{
  "openapi": "3.1.0",
  "info": {
    "title": "AllMyPeptides API",
    "version": "1.0.0",
    "description": "Public API for allmypeptides.com. Covers account management, loyalty state sync, payment checkout creation, and health. Authentication uses an HttpOnly session cookie (amp_sess) issued by the signup/login endpoints — OAuth/OIDC is not supported. A static machine-readable product catalog is available at https://allmypeptides.com/products.json. All peptides are for research use only.",
    "contact": {
      "email": "support@allmypeptides.com",
      "url": "https://allmypeptides.com/contact/"
    }
  },
  "servers": [
    {
      "url": "https://allmypeptides.com"
    }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "summary": "Service health check",
        "operationId": "getHealth",
        "responses": {
          "200": {
            "description": "Service is up",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "const": "ok"
                    },
                    "time": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/auth/signup": {
      "post": {
        "summary": "Create an account",
        "operationId": "signup",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "password",
                  "firstName",
                  "lastName"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "password": {
                    "type": "string",
                    "minLength": 6
                  },
                  "firstName": {
                    "type": "string"
                  },
                  "lastName": {
                    "type": "string"
                  },
                  "phone": {
                    "type": "string"
                  },
                  "referralCode": {
                    "type": "string",
                    "description": "Optional AMPXXXX referral code of an existing customer"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Account created; session cookie set",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthSuccess"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "description": "Email already registered",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/auth/login": {
      "post": {
        "summary": "Log in",
        "operationId": "login",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "password"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "password": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Logged in; session cookie set",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthSuccess"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/auth/logout": {
      "post": {
        "summary": "Log out (destroys the server session)",
        "operationId": "logout",
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Session destroyed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/auth/me": {
      "get": {
        "summary": "Current account profile and loyalty state",
        "operationId": "me",
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Profile and loyalty",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthSuccess"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/state/sync": {
      "post": {
        "summary": "Persist profile edits and loyalty state for the logged-in account",
        "description": "Only firstName, lastName and phone may be changed on the profile. Loyalty data is sanitised server-side; email, account id and referral code are immutable.",
        "operationId": "stateSync",
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "profile": {
                    "$ref": "#/components/schemas/Profile"
                  },
                  "loyalty": {
                    "$ref": "#/components/schemas/Loyalty"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "State stored",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/create-checkout": {
      "post": {
        "summary": "Create a SumUp hosted-checkout payment link for an order",
        "description": "Proxies checkout creation to SumUp and returns SumUp's checkout object including the hosted payment URL. Card payment itself is completed by a human on SumUp's hosted page.",
        "operationId": "createCheckout",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "checkout_reference",
                  "amount",
                  "currency",
                  "merchant_code"
                ],
                "properties": {
                  "checkout_reference": {
                    "type": "string",
                    "maxLength": 90
                  },
                  "amount": {
                    "type": "number",
                    "exclusiveMinimum": 0
                  },
                  "currency": {
                    "type": "string",
                    "example": "GBP"
                  },
                  "merchant_code": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "return_url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "redirect_url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "SumUp checkout created (response body is SumUp's checkout object)"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "502": {
            "description": "Payment provider unavailable"
          }
        }
      }
    },
    "/api/stock": {
      "get": {
        "summary": "Live stock levels for limited SKUs",
        "description": "Quantities for SKUs the shop tracks a limited stock count for. SKUs absent from the response are not stock-limited. Keys are of the form <product>-<size>, e.g. bpc-157-10mg.",
        "operationId": "getStock",
        "tags": [
          "Catalogue"
        ],
        "responses": {
          "200": {
            "description": "Map of SKU to remaining quantity",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "integer",
                    "minimum": 0
                  }
                },
                "example": {
                  "retatrutide-30mg": 4,
                  "mots-c-40mg": 2
                }
              }
            }
          }
        }
      }
    },
    "/api/validate-promo": {
      "get": {
        "summary": "Validate a discount code",
        "description": "Checks whether a promotional code is currently valid and returns its discount as a decimal fraction (0.10 = 10% off). Does not consume the code.",
        "operationId": "validatePromo",
        "tags": [
          "Checkout"
        ],
        "parameters": [
          {
            "name": "code",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "AMP10"
          }
        ],
        "responses": {
          "200": {
            "description": "Validation result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "valid": {
                      "type": "boolean"
                    },
                    "code": {
                      "type": "string"
                    },
                    "discount": {
                      "type": "number",
                      "description": "Decimal fraction, e.g. 0.1 for 10%"
                    }
                  },
                  "required": [
                    "valid"
                  ]
                },
                "example": {
                  "valid": true,
                  "code": "AMP10",
                  "discount": 0.1
                }
              }
            }
          }
        }
      }
    },
    "/api/version": {
      "get": {
        "summary": "Current deployment build identifier",
        "operationId": "getVersion",
        "tags": [
          "Meta"
        ],
        "responses": {
          "200": {
            "description": "Build identifier for the running deployment",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "build": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "build": "v286-000001-s615"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "cookieAuth": {
        "type": "apiKey",
        "in": "cookie",
        "name": "amp_sess",
        "description": "HttpOnly session cookie issued by /api/auth/signup or /api/auth/login. Valid 30 days."
      }
    },
    "responses": {
      "Error": {
        "description": "Error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "const": false
          },
          "error": {
            "type": "string"
          },
          "detail": {
            "type": "string"
          }
        }
      },
      "Profile": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "readOnly": true
          },
          "email": {
            "type": "string",
            "readOnly": true
          },
          "firstName": {
            "type": "string"
          },
          "lastName": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "readOnly": true
          },
          "referralCode": {
            "type": "string",
            "readOnly": true
          },
          "referredBy": {
            "type": "string",
            "readOnly": true
          }
        }
      },
      "Loyalty": {
        "type": "object",
        "properties": {
          "points": {
            "type": "integer",
            "minimum": 0
          },
          "lifetimePoints": {
            "type": "integer",
            "minimum": 0
          },
          "tier": {
            "type": "string",
            "enum": [
              "bronze",
              "silver",
              "gold",
              "platinum"
            ]
          },
          "pointsHistory": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "availableRewards": {
            "type": "array",
            "items": {}
          },
          "redeemedRewards": {
            "type": "array",
            "items": {}
          }
        }
      },
      "AuthSuccess": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "const": true
          },
          "user": {
            "type": "object",
            "properties": {
              "profile": {
                "$ref": "#/components/schemas/Profile"
              }
            }
          },
          "loyalty": {
            "$ref": "#/components/schemas/Loyalty"
          }
        }
      }
    }
  }
}