@waffo/pancake-ts 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js.map +1 -1
- package/docs/webhook-guide.md +1 -0
- package/package.json +1 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/buyer-http-client.ts","../src/http-client.ts","../src/signing.ts","../src/validation.ts","../src/resources/auth.ts","../src/resources/buyer.ts","../src/resources/checkout-anonymous.ts","../src/resources/checkout-authenticated.ts","../src/resources/checkout.ts","../src/resources/graphql.ts","../src/resources/onetime-products.ts","../src/resources/orders.ts","../src/resources/store-merchants.ts","../src/resources/stores.ts","../src/resources/subscription-product-groups.ts","../src/resources/subscription-products.ts","../src/webhooks.ts","../src/resources/webhooks.ts","../src/client.ts","../src/types.ts"],"sourcesContent":["// Client\nexport { WaffoPancake } from \"./client.js\";\n\n// Errors\nexport { WaffoPancakeError } from \"./errors.js\";\n\n// Webhooks\nexport { verifyWebhook } from \"./webhooks.js\";\n\n// Enums (runtime values)\nexport {\n BillingPeriod,\n EntityStatus,\n Environment,\n ErrorLayer,\n MediaType,\n OnetimeOrderStatus,\n PaymentStatus,\n ProductVersionStatus,\n RefundStatus,\n RefundTicketStatus,\n StoreRole,\n SubscriptionOrderStatus,\n TaxCategory,\n WebhookEventType,\n} from \"./types.js\";\n\n// Types (interfaces & type aliases)\nexport type {\n // Config\n WaffoPancakeConfig,\n\n // Response envelope\n ApiError,\n ApiErrorResponse,\n ApiResponse,\n ApiSuccessResponse,\n\n // Auth\n IssueSessionTokenParams,\n SessionToken,\n\n // Store\n CheckoutSettings,\n CheckoutThemeSettings,\n CreateStoreParams,\n DeleteStoreParams,\n NotificationSettings,\n Store,\n UpdateStoreParams,\n WebhookSettings,\n\n // Store Merchant\n AddMerchantParams,\n AddMerchantResult,\n RemoveMerchantParams,\n RemoveMerchantResult,\n UpdateRoleParams,\n UpdateRoleResult,\n\n // Product shared\n MediaItem,\n PriceInfo,\n Prices,\n\n // Onetime Product\n CreateOnetimeProductParams,\n OnetimeProductDetail,\n PublishOnetimeProductParams,\n UpdateOnetimeProductParams,\n UpdateOnetimeStatusParams,\n\n // Subscription Product\n CreateSubscriptionProductParams,\n PublishSubscriptionProductParams,\n SubscriptionProductDetail,\n UpdateSubscriptionProductParams,\n UpdateSubscriptionStatusParams,\n\n // Subscription Product Group\n CreateSubscriptionProductGroupParams,\n DeleteSubscriptionProductGroupParams,\n GroupRules,\n PublishSubscriptionProductGroupParams,\n SubscriptionProductGroup,\n UpdateSubscriptionProductGroupParams,\n\n // Buyer self-service\n CancelOnetimeOrderParams,\n CancelOnetimeOrderResult,\n CreateRefundTicketParams,\n ReactivateSubscriptionParams,\n ReactivateSubscriptionResult,\n RefundTicket,\n RefundTicketVersionData,\n RequestedAmount,\n ResubmitRefundTicketParams,\n\n // Checkout convenience\n AnonymousCheckoutParams,\n AuthenticatedCheckoutParams,\n AuthenticatedCheckoutResult,\n\n // Order\n BillingDetail,\n CancelSubscriptionParams,\n CancelSubscriptionResult,\n CheckoutSessionResult,\n CreateCheckoutSessionParams,\n\n // GraphQL\n GraphQLParams,\n GraphQLResponse,\n\n // Webhook\n VerifyWebhookOptions,\n WebhookEvent,\n WebhookEventData,\n WebhookPublicKeys,\n} from \"./types.js\";\n","import type { ApiError } from \"./types.js\";\n\n/**\n * Error thrown when the API returns a non-success response.\n *\n * @example\n * try {\n * await client.stores.create({ name: \"My Store\" });\n * } catch (err) {\n * if (err instanceof WaffoPancakeError) {\n * console.log(err.status); // 400\n * console.log(err.errors[0]); // { message: \"...\", layer: \"store\" }\n * }\n * }\n */\nexport class WaffoPancakeError extends Error {\n readonly status: number;\n readonly errors: ApiError[];\n\n constructor(status: number, errors: ApiError[]) {\n const rootCause = errors[0]?.message ?? \"Unknown error\";\n super(rootCause);\n this.name = \"WaffoPancakeError\";\n this.status = status;\n this.errors = errors;\n }\n}\n","import { WaffoPancakeError } from \"./errors.js\";\n\nimport type { ApiResponse, WaffoPancakeConfig } from \"./types.js\";\n\nconst DEFAULT_BASE_URL = \"https://api.waffo.ai\";\n\n/**\n * Internal HTTP client for buyer-side requests using Bearer token authentication.\n *\n * Unlike {@link HttpClient} which signs requests with RSA-SHA256 (API Key auth),\n * this client attaches a session token as `Authorization: Bearer <token>`.\n *\n * Not exported publicly — used internally by {@link BuyerSession}.\n */\nexport class BuyerHttpClient {\n private readonly token: string;\n private readonly baseUrl: string;\n private readonly _fetch: typeof fetch;\n\n constructor(token: string, config: Pick<WaffoPancakeConfig, \"baseUrl\" | \"fetch\">) {\n this.token = token;\n this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this._fetch = config.fetch ?? globalThis.fetch.bind(globalThis);\n }\n\n /**\n * Send a Bearer-authenticated POST request and return the parsed `data` field.\n *\n * @param path - API path\n * @param body - Request body object\n * @returns Parsed `data` field from the response\n * @throws {WaffoPancakeError} When the API returns errors\n */\n async post<T>(path: string, body: object): Promise<T> {\n const response = await this._fetch(`${this.baseUrl}${path}`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.token}`,\n },\n body: JSON.stringify(body),\n });\n\n const result = (await response.json()) as ApiResponse<T>;\n\n if (\"errors\" in result && result.errors) {\n throw new WaffoPancakeError(response.status, result.errors);\n }\n\n return result.data as T;\n }\n}\n","import { createHash } from \"node:crypto\";\n\nimport { WaffoPancakeError } from \"./errors.js\";\nimport { normalizePrivateKey, signRequest } from \"./signing.js\";\n\nimport type { ApiResponse, PostOptions, WaffoPancakeConfig } from \"./types.js\";\n\nconst DEFAULT_BASE_URL = \"https://api.waffo.ai\";\n\n/**\n * Internal HTTP client that auto-signs requests and attaches idempotency keys.\n *\n * The `X-Merchant-Id` header is sent in `MER_{base62}` format as provided by the user.\n * The gateway decodes it to a raw UUID before forwarding to downstream services.\n *\n * Not exported publicly — used by resource classes via {@link WaffoPancake}.\n */\nexport class HttpClient {\n private readonly merchantId: string;\n private readonly privateKey: string;\n private readonly baseUrl: string;\n private readonly _fetch: typeof fetch;\n\n constructor(config: WaffoPancakeConfig) {\n this.merchantId = config.merchantId;\n this.privateKey = normalizePrivateKey(config.privateKey);\n this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this._fetch = config.fetch ?? globalThis.fetch.bind(globalThis);\n }\n\n /**\n * Send a signed POST request and return the parsed `data` field.\n *\n * Behavior:\n * - Generates a deterministic `X-Idempotency-Key` from `merchantId + path + body` (same request produces same key)\n * - When `idempotencyWindow` is set, a floored timestamp is mixed into the key so identical params produce\n * a new key after the window elapses (useful for checkout where repeated creation is intentional)\n * - Auto-builds RSA-SHA256 signature (`X-Merchant-Id` / `X-Timestamp` / `X-Signature`)\n * - Unwraps the response envelope: returns `data` on success, throws `WaffoPancakeError` on failure\n *\n * @param path - API path (e.g. `/v1/actions/store/create-store`)\n * @param body - Request body object\n * @param options - Optional settings\n * @param options.idempotencyWindow - Time window in seconds for idempotency key rotation (e.g. 60 = per-minute dedup)\n * @returns Parsed `data` field from the response\n * @throws {WaffoPancakeError} When the API returns errors\n */\n async post<T>(path: string, body: object, options?: PostOptions): Promise<T> {\n const bodyStr = JSON.stringify(body);\n const now = Date.now();\n const timestampSec = Math.floor(now / 1000);\n const timestamp = timestampSec.toString();\n const signature = signRequest(\"POST\", path, timestamp, bodyStr, this.privateKey);\n\n const idempotencyBase = `${this.merchantId}:${path}:${bodyStr}`;\n const idempotencyInput = options?.idempotencyWindow\n ? `${idempotencyBase}:${Math.floor(timestampSec / options.idempotencyWindow)}`\n : idempotencyBase;\n\n const response = await this._fetch(`${this.baseUrl}${path}`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-Merchant-Id\": this.merchantId,\n \"X-Timestamp\": timestamp,\n \"X-Signature\": signature,\n \"X-Idempotency-Key\": createHash(\"sha256\").update(idempotencyInput).digest(\"hex\"),\n },\n body: bodyStr,\n });\n\n const result = (await response.json()) as ApiResponse<T>;\n\n if (\"errors\" in result && result.errors) {\n throw new WaffoPancakeError(response.status, result.errors);\n }\n\n return result.data as T;\n }\n}\n","import { createHash, createPrivateKey, createPublicKey, createSign } from \"node:crypto\";\n\nconst PKCS8_HEADER = \"-----BEGIN PRIVATE KEY-----\";\nconst PKCS8_FOOTER = \"-----END PRIVATE KEY-----\";\nconst PKCS1_HEADER = \"-----BEGIN RSA PRIVATE KEY-----\";\nconst PKCS1_FOOTER = \"-----END RSA PRIVATE KEY-----\";\n\nconst SPKI_HEADER = \"-----BEGIN PUBLIC KEY-----\";\nconst SPKI_FOOTER = \"-----END PUBLIC KEY-----\";\nconst PKCS1_PUB_HEADER = \"-----BEGIN RSA PUBLIC KEY-----\";\nconst PKCS1_PUB_FOOTER = \"-----END RSA PUBLIC KEY-----\";\n\n/**\n * Normalize a PEM private key string into a valid PEM format.\n *\n * Handles common issues:\n * - Literal `\\n` from environment variables (e.g. `PRIVATE_KEY=\"-----BEGIN...\\\\n...\"`)\n * - Windows-style `\\r\\n` line endings\n * - Leading/trailing whitespace and blank lines\n * - Missing PEM header/footer (raw base64 input, assumed PKCS#8)\n * - Base64 content on a single line (re-wrapped to 64-char lines)\n * - PKCS#1 (`BEGIN RSA PRIVATE KEY`) accepted as-is\n *\n * @param raw - Private key string in any of the above formats\n * @returns A well-formed PEM string\n * @throws {Error} If the input is empty or contains no base64 content\n *\n * @example\n * // Env var with literal \\n\n * normalizePrivateKey(\"-----BEGIN PRIVATE KEY-----\\\\nMIIE...\\\\n-----END PRIVATE KEY-----\")\n *\n * @example\n * // Raw base64 without PEM wrapper\n * normalizePrivateKey(\"MIIEvQIBADANBgkqhki...\")\n */\nexport function normalizePrivateKey(raw: string): string {\n if (!raw || !raw.trim()) {\n throw new Error(\"Private key is empty. Provide an RSA private key in PEM format.\");\n }\n\n // 1. Replace literal \\n / \\r\\n with real newlines\n let pem = raw.replace(/\\\\n/g, \"\\n\").replace(/\\r\\n/g, \"\\n\");\n\n // 2. Trim leading/trailing whitespace\n pem = pem.trim();\n\n // 3. Detect whether PEM headers are present\n const hasPkcs8Header = pem.includes(PKCS8_HEADER);\n const hasPkcs1Header = pem.includes(PKCS1_HEADER);\n const hasHeader = hasPkcs8Header || hasPkcs1Header;\n\n if (hasHeader) {\n // Strip headers/footers, extract pure base64\n const base64 = pem\n .replace(/-----BEGIN (?:RSA )?PRIVATE KEY-----/g, \"\")\n .replace(/-----END (?:RSA )?PRIVATE KEY-----/g, \"\")\n .replace(/\\s+/g, \"\");\n\n if (!base64) {\n throw new Error(\"Private key contains PEM headers but no key data. Check the key content.\");\n }\n\n // Re-wrap to 64-char lines with the original header type\n const header = hasPkcs1Header ? PKCS1_HEADER : PKCS8_HEADER;\n const footer = hasPkcs1Header ? PKCS1_FOOTER : PKCS8_FOOTER;\n const wrapped = base64.match(/.{1,64}/g)!.join(\"\\n\");\n pem = `${header}\\n${wrapped}\\n${footer}`;\n } else {\n // No PEM header — treat as raw base64, wrap with PKCS#8 headers\n const base64 = pem.replace(/\\s+/g, \"\");\n\n if (!/^[A-Za-z0-9+/]+=*$/.test(base64)) {\n throw new Error(\"Private key is not valid PEM or base64. Expected an RSA private key in PEM format or raw base64.\");\n }\n\n const wrapped = base64.match(/.{1,64}/g)!.join(\"\\n\");\n pem = `${PKCS8_HEADER}\\n${wrapped}\\n${PKCS8_FOOTER}`;\n }\n\n // 4. Validate the key is actually parseable by Node.js crypto\n try {\n createPrivateKey(pem);\n } catch {\n throw new Error(\"Private key could not be parsed. Ensure it is a valid RSA private key in PKCS#8 or PKCS#1 (PEM) format.\");\n }\n\n return pem;\n}\n\n/**\n * Normalize a PEM public key string into a valid PEM format.\n *\n * Handles common issues:\n * - Literal `\\n` from environment variables\n * - Windows-style `\\r\\n` line endings\n * - Leading/trailing whitespace and blank lines\n * - Missing PEM header/footer (raw base64 input, assumed SPKI)\n * - Base64 content on a single line (re-wrapped to 64-char lines)\n * - PKCS#1 (`BEGIN RSA PUBLIC KEY`) accepted as-is\n *\n * @param raw - Public key string in any of the above formats\n * @returns A well-formed PEM string\n * @throws {Error} If the input is empty or contains no base64 content\n *\n * @example\n * // Env var with literal \\n\n * normalizePublicKey(\"-----BEGIN PUBLIC KEY-----\\\\nMIIB...\\\\n-----END PUBLIC KEY-----\")\n *\n * @example\n * // Raw base64 without PEM wrapper\n * normalizePublicKey(\"MIIBIjANBgkqhki...\")\n */\nexport function normalizePublicKey(raw: string): string {\n if (!raw || !raw.trim()) {\n throw new Error(\"Public key is empty. Provide an RSA public key in PEM format.\");\n }\n\n // 1. Replace literal \\n / \\r\\n with real newlines\n let pem = raw.replace(/\\\\n/g, \"\\n\").replace(/\\r\\n/g, \"\\n\");\n\n // 2. Trim leading/trailing whitespace\n pem = pem.trim();\n\n // 3. Detect whether PEM headers are present\n const hasSpkiHeader = pem.includes(SPKI_HEADER);\n const hasPkcs1PubHeader = pem.includes(PKCS1_PUB_HEADER);\n const hasHeader = hasSpkiHeader || hasPkcs1PubHeader;\n\n if (hasHeader) {\n // Strip headers/footers, extract pure base64\n const base64 = pem\n .replace(/-----BEGIN (?:RSA )?PUBLIC KEY-----/g, \"\")\n .replace(/-----END (?:RSA )?PUBLIC KEY-----/g, \"\")\n .replace(/\\s+/g, \"\");\n\n if (!base64) {\n throw new Error(\"Public key contains PEM headers but no key data. Check the key content.\");\n }\n\n // Re-wrap to 64-char lines with the original header type\n const header = hasPkcs1PubHeader ? PKCS1_PUB_HEADER : SPKI_HEADER;\n const footer = hasPkcs1PubHeader ? PKCS1_PUB_FOOTER : SPKI_FOOTER;\n const wrapped = base64.match(/.{1,64}/g)!.join(\"\\n\");\n pem = `${header}\\n${wrapped}\\n${footer}`;\n } else {\n // No PEM header — treat as raw base64, wrap with SPKI headers\n const base64 = pem.replace(/\\s+/g, \"\");\n\n if (!/^[A-Za-z0-9+/]+=*$/.test(base64)) {\n throw new Error(\"Public key is not valid PEM or base64. Expected an RSA public key in PEM format or raw base64.\");\n }\n\n const wrapped = base64.match(/.{1,64}/g)!.join(\"\\n\");\n pem = `${SPKI_HEADER}\\n${wrapped}\\n${SPKI_FOOTER}`;\n }\n\n // 4. Validate the key is actually parseable by Node.js crypto\n try {\n createPublicKey(pem);\n } catch {\n throw new Error(\"Public key could not be parsed. Ensure it is a valid RSA public key in SPKI or PKCS#1 (PEM) format.\");\n }\n\n return pem;\n}\n\n/**\n * Build canonical request string and sign with RSA-SHA256.\n *\n * Canonical request format:\n * METHOD\\nPATH\\nTIMESTAMP\\nSHA256(BODY)\n *\n * @param method - HTTP method (e.g. \"POST\")\n * @param path - Request path (e.g. \"/v1/actions/store/create-store\")\n * @param timestamp - Unix epoch seconds string\n * @param body - Serialized JSON body\n * @param privateKey - RSA private key in PEM format\n * @returns Base64-encoded RSA-SHA256 signature\n */\nexport function signRequest(method: string, path: string, timestamp: string, body: string, privateKey: string): string {\n const bodyHash = createHash(\"sha256\").update(body).digest(\"base64\");\n const canonicalRequest = `${method}\\n${path}\\n${timestamp}\\n${bodyHash}`;\n\n const sign = createSign(\"sha256\");\n sign.update(canonicalRequest);\n return sign.sign(privateKey, \"base64\");\n}\n","/**\n * Client-side input validation.\n *\n * These checks catch obviously invalid inputs before making a network request.\n * They do NOT validate data existence (e.g., whether a store/product actually exists).\n *\n * All validation errors throw `WaffoPancakeError` with `status: 400` and `layer: \"sdk\"`,\n * so developers can catch them uniformly with API errors.\n *\n * Not exported publicly — used internally by resource classes.\n */\n\nimport { WaffoPancakeError } from \"./errors.js\";\n\nconst SHORT_ID_REGEX = /^[A-Z]{2,5}_[0-9A-Za-z]{22}$/;\nconst CURRENCY_CODE_REGEX = /^[A-Z]{3}$/;\nconst COUNTRY_CODE_REGEX = /^[A-Z]{2}$/;\nconst AMOUNT_STRING_REGEX = /^\\d+(\\.\\d+)?$/;\n\nconst SHORT_ID_LABELS: Record<string, string> = {\n STO: \"Store\",\n PROD: \"Product\",\n ORD: \"Order\",\n PAY: \"Payment\",\n REF: \"Refund\",\n TKT: \"Ticket\",\n MER: \"Merchant\",\n};\n\nfunction fail(message: string): never {\n throw new WaffoPancakeError(400, [{ message, layer: \"sdk\" }]);\n}\n\n/**\n * Validate that a required field is present and non-empty.\n */\nexport function validateRequired(field: string, value: unknown): void {\n if (value === undefined || value === null) {\n fail(`Missing required field: ${field}`);\n }\n if (typeof value === \"string\" && value.trim() === \"\") {\n fail(`${field} cannot be empty`);\n }\n}\n\n/**\n * Validate Short ID format (`{PREFIX}_{base62}`).\n */\nexport function validateShortId(field: string, value: string, prefix: string): void {\n validateRequired(field, value);\n const label = SHORT_ID_LABELS[prefix] ?? prefix;\n if (!SHORT_ID_REGEX.test(value)) {\n fail(`Invalid ${field}: expected ${label} Short ID format (${prefix}_xxx), got \"${value}\"`);\n }\n if (!value.startsWith(`${prefix}_`)) {\n fail(`Invalid ${field}: expected ${prefix}_ prefix (${label}), got \"${value.split(\"_\")[0]}_\"`);\n }\n}\n\n/**\n * Validate ISO 4217 currency code format (3 uppercase letters).\n */\nexport function validateCurrencyCode(field: string, value: string): void {\n validateRequired(field, value);\n if (!CURRENCY_CODE_REGEX.test(value)) {\n fail(`Invalid ${field}: expected 3-letter ISO 4217 currency code (e.g., \"USD\"), got \"${value}\"`);\n }\n}\n\n/**\n * Validate that amount is a valid numeric string in display format.\n */\nexport function validateAmountString(field: string, value: string): void {\n validateRequired(field, value);\n if (!AMOUNT_STRING_REGEX.test(value)) {\n fail(`Invalid ${field}: expected numeric string in display format (e.g., \"9.99\", \"1000\"), got \"${value}\"`);\n }\n}\n\n/**\n * Validate that a value is one of the allowed enum values.\n */\nexport function validateEnum(field: string, value: string, allowed: string[]): void {\n validateRequired(field, value);\n if (!allowed.includes(value)) {\n fail(`Invalid ${field}: expected one of [${allowed.join(\", \")}], got \"${value}\"`);\n }\n}\n\n/**\n * Validate that a value is a positive integer.\n */\nexport function validatePositiveInteger(field: string, value: number): void {\n if (!Number.isInteger(value) || value <= 0) {\n fail(`Invalid ${field}: expected positive integer, got ${value}`);\n }\n}\n\n/**\n * Validate ISO 3166-1 alpha-2 country code (2 uppercase letters).\n */\nexport function validateCountryCode(field: string, value: string): void {\n validateRequired(field, value);\n if (!COUNTRY_CODE_REGEX.test(value)) {\n fail(`Invalid ${field}: expected 2-letter ISO 3166-1 country code (e.g., \"US\"), got \"${value}\"`);\n }\n}\n\n/**\n * Validate Prices object — each currency key and price amount.\n */\nexport function validatePrices(field: string, prices: Record<string, { amount: string; taxCategory: string }>): void {\n validateRequired(field, prices);\n const entries = Object.entries(prices);\n if (entries.length === 0) {\n fail(`${field} must contain at least one currency`);\n }\n for (const [currency, info] of entries) {\n validateCurrencyCode(`${field}.${currency} (key)`, currency);\n validateAmountString(`${field}.${currency}.amount`, info.amount);\n validateRequired(`${field}.${currency}.taxCategory`, info.taxCategory);\n }\n}\n\n/**\n * Validate BillingDetail fields (when present).\n */\nexport function validateBillingDetail(detail: { country: string; isBusiness: boolean }): void {\n validateCountryCode(\"billingDetail.country\", detail.country);\n if (typeof detail.isBusiness !== \"boolean\") {\n fail(`Invalid billingDetail.isBusiness: expected boolean, got ${typeof detail.isBusiness}`);\n }\n}\n\n/**\n * Validate checkout session common fields.\n */\nexport function validateCheckoutCommon(params: {\n productId: string;\n currency: string;\n priceSnapshot?: { amount: string; taxCategory: string };\n billingDetail?: { country: string; isBusiness: boolean };\n expiresInSeconds?: number;\n}): void {\n validateShortId(\"productId\", params.productId, \"PROD\");\n validateCurrencyCode(\"currency\", params.currency);\n if (params.priceSnapshot) {\n validateAmountString(\"priceSnapshot.amount\", params.priceSnapshot.amount);\n validateRequired(\"priceSnapshot.taxCategory\", params.priceSnapshot.taxCategory);\n }\n if (params.billingDetail) {\n validateBillingDetail(params.billingDetail);\n }\n if (params.expiresInSeconds !== undefined) {\n validatePositiveInteger(\"expiresInSeconds\", params.expiresInSeconds);\n }\n}\n","import { WaffoPancakeError } from \"../errors.js\";\nimport { validateRequired, validateShortId } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type { IssueSessionTokenParams, SessionToken } from \"../types.js\";\n\n/** Authentication resource — issue session tokens for buyers. */\nexport class AuthResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Issue a session token for a buyer.\n *\n * @param params - Token issuance parameters\n * @returns Issued session token with expiration\n *\n * @example\n * // By store ID\n * const { token, expiresAt } = await client.auth.issueSessionToken({\n * storeId: \"STO_xxx\",\n * buyerIdentity: \"customer@example.com\",\n * });\n *\n * @example\n * // By product ID (store derived automatically)\n * const { token, expiresAt } = await client.auth.issueSessionToken({\n * productId: \"PROD_xxx\",\n * buyerIdentity: \"customer@example.com\",\n * });\n */\n async issueSessionToken(params: IssueSessionTokenParams): Promise<SessionToken> {\n if (!params.storeId && !params.productId) {\n throw new WaffoPancakeError(400, [{ message: \"Missing required field: provide storeId or productId\", layer: \"sdk\" }]);\n }\n if (params.storeId) {\n validateShortId(\"storeId\", params.storeId, \"STO\");\n }\n if (params.productId) {\n validateShortId(\"productId\", params.productId, \"PROD\");\n }\n validateRequired(\"buyerIdentity\", params.buyerIdentity);\n return this.http.post<SessionToken>(\"/v1/actions/auth/issue-session-token\", params);\n }\n}\n","import { validateAmountString, validateCurrencyCode, validateRequired, validateShortId } from \"../validation.js\";\n\nimport type { BuyerHttpClient } from \"../buyer-http-client.js\";\nimport type {\n CancelOnetimeOrderParams,\n CancelOnetimeOrderResult,\n CancelSubscriptionParams,\n CancelSubscriptionResult,\n CreateRefundTicketParams,\n GraphQLParams,\n GraphQLResponse,\n ReactivateSubscriptionParams,\n ReactivateSubscriptionResult,\n RefundTicket,\n ResubmitRefundTicketParams,\n} from \"../types.js\";\n\n/**\n * Buyer session — lets authenticated buyers manage their own orders and subscriptions.\n *\n * Created via `client.buyer(token)` using a session token issued by\n * `client.auth.issueSessionToken()`. All requests use Bearer token authentication.\n *\n * @example\n * const { token } = await client.auth.issueSessionToken({\n * storeId: \"STO_xxx\",\n * buyerIdentity: \"customer@example.com\",\n * });\n * const buyer = client.buyer(token);\n * await buyer.cancelSubscription({ orderId: \"ORD_xxx\" });\n */\nexport class BuyerSession {\n /** GraphQL query access scoped to the buyer's data. */\n readonly graphql: BuyerGraphQL;\n\n constructor(private readonly http: BuyerHttpClient) {\n this.graphql = new BuyerGraphQL(http);\n }\n\n /**\n * Cancel a subscription order.\n *\n * @param params - Order to cancel\n * @returns Order ID and resulting status\n *\n * @example\n * const { orderId, status } = await buyer.cancelSubscription({ orderId: \"ORD_xxx\" });\n * // status: \"canceled\" (was pending) or \"canceling\" (was active)\n */\n async cancelSubscription(params: CancelSubscriptionParams): Promise<CancelSubscriptionResult> {\n validateShortId(\"orderId\", params.orderId, \"ORD\");\n return this.http.post<CancelSubscriptionResult>(\"/v1/actions/subscription-order/cancel-order\", params);\n }\n\n /**\n * Cancel a one-time order (only while payment is still pending).\n *\n * @param params - Order to cancel\n * @returns Order ID and resulting status\n *\n * @example\n * const { orderId, status } = await buyer.cancelOnetimeOrder({ orderId: \"ORD_xxx\" });\n */\n async cancelOnetimeOrder(params: CancelOnetimeOrderParams): Promise<CancelOnetimeOrderResult> {\n validateShortId(\"orderId\", params.orderId, \"ORD\");\n return this.http.post<CancelOnetimeOrderResult>(\"/v1/actions/onetime-order/cancel-order\", params);\n }\n\n /**\n * Reactivate a subscription that is in `canceling` status.\n *\n * @param params - Order to reactivate\n * @returns Order ID and resulting status\n *\n * @example\n * const { orderId, status } = await buyer.reactivateSubscription({ orderId: \"ORD_xxx\" });\n * // status: \"active\"\n */\n async reactivateSubscription(params: ReactivateSubscriptionParams): Promise<ReactivateSubscriptionResult> {\n validateShortId(\"orderId\", params.orderId, \"ORD\");\n return this.http.post<ReactivateSubscriptionResult>(\"/v1/actions/subscription-order/reactivate-order\", params);\n }\n\n /**\n * Submit a refund request for a payment.\n *\n * @param params - Refund ticket details\n * @returns Created refund ticket\n *\n * @example\n * const { ticket } = await buyer.createRefundTicket({\n * paymentId: \"PAY_xxx\",\n * reason: \"Product not as described\",\n * requestedAmount: { amount: \"29.00\", currency: \"USD\" },\n * });\n */\n async createRefundTicket(params: CreateRefundTicketParams): Promise<{ ticket: RefundTicket }> {\n validateShortId(\"paymentId\", params.paymentId, \"PAY\");\n validateRequired(\"reason\", params.reason);\n validateAmountString(\"requestedAmount.amount\", params.requestedAmount.amount);\n validateCurrencyCode(\"requestedAmount.currency\", params.requestedAmount.currency);\n return this.http.post<{ ticket: RefundTicket }>(\"/v1/actions/refund-ticket/create-ticket\", params);\n }\n\n /**\n * Resubmit a previously rejected refund ticket with updated details.\n *\n * @param params - Updated ticket details\n * @returns Updated refund ticket\n *\n * @example\n * const { ticket } = await buyer.resubmitRefundTicket({\n * ticketId: \"TKT_xxx\",\n * paymentId: \"PAY_xxx\",\n * reason: \"Updated reason with more detail\",\n * requestedAmount: { amount: \"29.00\", currency: \"USD\" },\n * });\n */\n async resubmitRefundTicket(params: ResubmitRefundTicketParams): Promise<{ ticket: RefundTicket }> {\n validateShortId(\"ticketId\", params.ticketId, \"TKT\");\n validateShortId(\"paymentId\", params.paymentId, \"PAY\");\n validateRequired(\"reason\", params.reason);\n validateAmountString(\"requestedAmount.amount\", params.requestedAmount.amount);\n validateCurrencyCode(\"requestedAmount.currency\", params.requestedAmount.currency);\n return this.http.post<{ ticket: RefundTicket }>(\"/v1/actions/refund-ticket/resubmit-ticket\", params);\n }\n}\n\n/**\n * GraphQL access scoped to the buyer's session token.\n */\nclass BuyerGraphQL {\n constructor(private readonly http: BuyerHttpClient) {}\n\n /**\n * Execute a GraphQL query scoped to the buyer's data.\n *\n * @param params - GraphQL query and variables\n * @returns GraphQL response\n *\n * @example\n * const result = await buyer.graphql.query({\n * query: `query { orders { id status } }`,\n * });\n */\n async query<T = Record<string, unknown>>(params: GraphQLParams): Promise<GraphQLResponse<T>> {\n validateRequired(\"query\", params.query);\n return this.http.post<GraphQLResponse<T>>(\"/v1/graphql\", params);\n }\n}\n","import { validateCheckoutCommon } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type { AnonymousCheckoutParams, CheckoutSessionResult } from \"../types.js\";\n\n/**\n * Anonymous checkout — no buyer identity provided.\n *\n * The buyer reaches the checkout page without a session token. Merchants may still\n * pre-fill `buyerEmail` and `billingDetail` on the page by passing them here.\n * Internally creates a checkout session and returns the redirect URL.\n */\nexport class CheckoutAnonymousResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Create an anonymous checkout session.\n *\n * @param params - Checkout parameters (no buyer identity required)\n * @returns Session ID, checkout URL, and expiration\n *\n * @example\n * // Minimal — buyer fills everything on the page\n * const result = await client.checkout.anonymous.create({\n * productId: \"PROD_xxx\",\n * currency: \"USD\",\n * });\n *\n * @example\n * // Pre-fill email and billing without issuing a session token\n * const result = await client.checkout.anonymous.create({\n * productId: \"PROD_xxx\",\n * currency: \"USD\",\n * buyerEmail: \"customer@example.com\",\n * billingDetail: { country: \"US\", isBusiness: false, postcode: \"10001\" },\n * });\n */\n async create(params: AnonymousCheckoutParams): Promise<CheckoutSessionResult> {\n validateCheckoutCommon(params);\n return this.http.post<CheckoutSessionResult>(\"/v1/actions/checkout/create-session\", params, { idempotencyWindow: 60 });\n }\n}\n","import { validateCheckoutCommon, validateRequired } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type { AuthenticatedCheckoutParams, AuthenticatedCheckoutResult, CheckoutSessionResult, SessionToken } from \"../types.js\";\n\n/**\n * Authenticated checkout — merchant provides buyer identity.\n *\n * Issues a session token, creates a checkout session, and returns a\n * checkout URL with the token appended as a URL fragment (`#token=...`).\n * The checkout page reads the fragment to pre-fill buyer information.\n */\nexport class CheckoutAuthenticatedResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Create an authenticated checkout session.\n *\n * Behavior:\n * - Issues a session token via `issue-session-token` (receives `buyerIdentity` + `productId` only)\n * - Creates a checkout session via `create-session` (receives every other field unchanged)\n * - Appends the token to the checkout URL as a URL fragment (`#token=...`)\n *\n * `buyerIdentity` and `buyerEmail` are independent inputs: identity is for the JWT,\n * email is for pre-filling the checkout page. The SDK forwards each to its own endpoint.\n *\n * @param params - Checkout parameters including buyer identity\n * @returns Session details with token-appended checkout URL\n *\n * @example\n * const result = await client.checkout.authenticated.create({\n * productId: \"PROD_xxx\",\n * currency: \"USD\",\n * buyerIdentity: \"user-123\",\n * buyerEmail: \"customer@example.com\",\n * });\n * // Redirect to result.checkoutUrl (includes #token=...)\n */\n async create(params: AuthenticatedCheckoutParams): Promise<AuthenticatedCheckoutResult> {\n validateCheckoutCommon(params);\n validateRequired(\"buyerIdentity\", params.buyerIdentity);\n const { buyerIdentity, ...sessionParams } = params;\n\n const [tokenResult, sessionResult] = await Promise.all([\n this.http.post<SessionToken>(\n \"/v1/actions/auth/issue-session-token\",\n {\n productId: params.productId,\n buyerIdentity,\n },\n { idempotencyWindow: 60 },\n ),\n this.http.post<CheckoutSessionResult>(\"/v1/actions/checkout/create-session\", sessionParams, { idempotencyWindow: 60 }),\n ]);\n\n return {\n sessionId: sessionResult.sessionId,\n checkoutUrl: `${sessionResult.checkoutUrl}#token=${tokenResult.token}`,\n expiresAt: sessionResult.expiresAt,\n token: tokenResult.token,\n tokenExpiresAt: tokenResult.expiresAt,\n };\n }\n}\n","import { CheckoutAnonymousResource } from \"./checkout-anonymous.js\";\nimport { CheckoutAuthenticatedResource } from \"./checkout-authenticated.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type { CheckoutSessionResult, CreateCheckoutSessionParams } from \"../types.js\";\n\n/**\n * Checkout resource — create checkout sessions for payments.\n *\n * Provides two convenience sub-resources for the common checkout flows:\n * - `anonymous` — no buyer identity, empty form\n * - `authenticated` — merchant provides buyer identity, pre-filled form + token\n *\n * The low-level `createSession()` method is still available for full control.\n *\n * @example\n * // Anonymous checkout (no identity)\n * const result = await client.checkout.anonymous.create({\n * productId: \"PROD_xxx\",\n * currency: \"USD\",\n * });\n *\n * @example\n * // Authenticated checkout (with buyer identity)\n * const result = await client.checkout.authenticated.create({\n * productId: \"PROD_xxx\",\n * currency: \"USD\",\n * buyerIdentity: \"userIdInYourSystem\",\n * buyerEmail: \"customer@example.com\",\n * });\n * // result.checkoutUrl includes #token=...\n */\nexport class CheckoutResource {\n /** Anonymous checkout — no buyer identity, empty form. */\n readonly anonymous: CheckoutAnonymousResource;\n /** Authenticated checkout — merchant provides buyer identity. */\n readonly authenticated: CheckoutAuthenticatedResource;\n\n constructor(private readonly http: HttpClient) {\n this.anonymous = new CheckoutAnonymousResource(http);\n this.authenticated = new CheckoutAuthenticatedResource(http);\n }\n\n /**\n * Create a checkout session (low-level). Returns a URL to redirect the customer to.\n *\n * For most use cases, prefer `checkout.anonymous.create()` or\n * `checkout.authenticated.create()` which handle the full flow automatically.\n *\n * @param params - Checkout session parameters\n * @returns Session ID, checkout URL, and expiration\n *\n * @example\n * const session = await client.checkout.createSession({\n * productId: \"PROD_xxx\",\n * currency: \"USD\",\n * buyerEmail: \"customer@example.com\",\n * });\n * // Redirect to session.checkoutUrl\n */\n async createSession(params: CreateCheckoutSessionParams): Promise<CheckoutSessionResult> {\n return this.http.post<CheckoutSessionResult>(\"/v1/actions/checkout/create-session\", params, { idempotencyWindow: 60 });\n }\n}\n","import { validateRequired } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type { GraphQLParams, GraphQLResponse } from \"../types.js\";\n\n/** GraphQL query resource (Query only, no Mutations). */\nexport class GraphQLResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Execute a GraphQL query (Query only, no Mutations).\n *\n * @param params - GraphQL query and optional variables\n * @returns GraphQL response with data and optional errors\n *\n * @example\n * const result = await client.graphql.query<{ stores: Array<{ id: string; name: string }> }>({\n * query: `query { stores { id name status } }`,\n * });\n * console.log(result.data?.stores);\n *\n * @example\n * const result = await client.graphql.query({\n * query: `query ($id: ID!) { onetimeProduct(id: $id) { id name prices } }`,\n * variables: { id: \"PROD_xxx\" },\n * });\n */\n async query<T = Record<string, unknown>>(params: GraphQLParams): Promise<GraphQLResponse<T>> {\n validateRequired(\"query\", params.query);\n return this.http.post<GraphQLResponse<T>>(\"/v1/graphql\", params);\n }\n}\n","import { validateEnum, validatePrices, validateRequired, validateShortId } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type {\n CreateOnetimeProductParams,\n OnetimeProductDetail,\n PublishOnetimeProductParams,\n UpdateOnetimeProductParams,\n UpdateOnetimeStatusParams,\n} from \"../types.js\";\n\n/** One-time product management resource. */\nexport class OnetimeProductsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Create a one-time product with multi-currency pricing.\n *\n * @param params - Product creation parameters\n * @returns Created product detail\n *\n * @example\n * const { product } = await client.onetimeProducts.create({\n * storeId: \"STO_xxx\",\n * name: \"E-Book\",\n * prices: { USD: { amount: \"29.00\", taxCategory: \"digital_goods\" } },\n * });\n */\n async create(params: CreateOnetimeProductParams): Promise<{ product: OnetimeProductDetail }> {\n validateShortId(\"storeId\", params.storeId, \"STO\");\n validateRequired(\"name\", params.name);\n validatePrices(\"prices\", params.prices);\n return this.http.post<{ product: OnetimeProductDetail }>(\"/v1/actions/onetime-product/create-product\", params);\n }\n\n /**\n * Update a one-time product. Creates a new version; skips if unchanged.\n *\n * @param params - Product update parameters (only `id` is required)\n * @returns Updated product detail\n *\n * @example\n * // Update only the name\n * const { product } = await client.onetimeProducts.update({\n * id: \"PROD_xxx\",\n * name: \"E-Book v2\",\n * });\n *\n * @example\n * // Update prices while preserving other fields\n * const { product } = await client.onetimeProducts.update({\n * id: \"PROD_xxx\",\n * prices: { USD: { amount: \"39.00\", taxCategory: \"digital_goods\" } },\n * });\n */\n async update(params: UpdateOnetimeProductParams): Promise<{ product: OnetimeProductDetail }> {\n validateShortId(\"id\", params.id, \"PROD\");\n if (params.name !== undefined) validateRequired(\"name\", params.name);\n if (params.prices) validatePrices(\"prices\", params.prices);\n return this.http.post<{ product: OnetimeProductDetail }>(\"/v1/actions/onetime-product/update-product\", params);\n }\n\n /**\n * Publish a one-time product's test version to production.\n *\n * @param params - Product to publish\n * @returns Published product detail\n *\n * @example\n * const { product } = await client.onetimeProducts.publish({ id: \"PROD_xxx\" });\n */\n async publish(params: PublishOnetimeProductParams): Promise<{ product: OnetimeProductDetail }> {\n validateShortId(\"id\", params.id, \"PROD\");\n return this.http.post<{ product: OnetimeProductDetail }>(\"/v1/actions/onetime-product/publish-product\", params);\n }\n\n /**\n * Update a one-time product's status (active/inactive).\n *\n * @param params - Status update parameters\n * @returns Updated product detail\n *\n * @example\n * const { product } = await client.onetimeProducts.updateStatus({\n * id: \"PROD_xxx\",\n * status: ProductVersionStatus.Inactive,\n * });\n */\n async updateStatus(params: UpdateOnetimeStatusParams): Promise<{ product: OnetimeProductDetail }> {\n validateShortId(\"id\", params.id, \"PROD\");\n validateEnum(\"status\", params.status, [\"active\", \"inactive\"]);\n return this.http.post<{ product: OnetimeProductDetail }>(\"/v1/actions/onetime-product/update-status\", params);\n }\n}\n","import { validateShortId } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type { CancelSubscriptionParams, CancelSubscriptionResult } from \"../types.js\";\n\n/** Order management resource. */\nexport class OrdersResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Cancel a subscription order.\n *\n * - pending -> canceled (immediate)\n * - active/trialing -> canceling (PSP cancel, webhook updates later)\n *\n * @param params - Order to cancel\n * @returns Order ID and resulting status\n *\n * @example\n * const { orderId, status } = await client.orders.cancelSubscription({\n * orderId: \"ORD_xxx\",\n * });\n * // status: \"canceled\" or \"canceling\"\n */\n async cancelSubscription(params: CancelSubscriptionParams): Promise<CancelSubscriptionResult> {\n validateShortId(\"orderId\", params.orderId, \"ORD\");\n return this.http.post<CancelSubscriptionResult>(\"/v1/actions/subscription-order/cancel-order\", params);\n }\n}\n","import { validateEnum, validateRequired, validateShortId } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type {\n AddMerchantParams,\n AddMerchantResult,\n RemoveMerchantParams,\n RemoveMerchantResult,\n UpdateRoleParams,\n UpdateRoleResult,\n} from \"../types.js\";\n\n/** Store merchant management resource (coming soon — endpoints return 501). */\nexport class StoreMerchantsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Add a merchant to a store.\n *\n * @param params - Merchant addition parameters\n * @returns Added merchant details\n *\n * @example\n * const result = await client.storeMerchants.add({\n * storeId: \"STO_xxx\",\n * email: \"member@example.com\",\n * role: \"admin\",\n * });\n */\n async add(params: AddMerchantParams): Promise<AddMerchantResult> {\n validateShortId(\"storeId\", params.storeId, \"STO\");\n validateRequired(\"email\", params.email);\n validateEnum(\"role\", params.role, [\"admin\", \"member\"]);\n return this.http.post<AddMerchantResult>(\"/v1/actions/store-merchant/add-merchant\", params);\n }\n\n /**\n * Remove a merchant from a store.\n *\n * @param params - Merchant removal parameters\n * @returns Removal confirmation\n *\n * @example\n * const result = await client.storeMerchants.remove({\n * storeId: \"STO_xxx\",\n * merchantId: \"MER_xxx\",\n * });\n */\n async remove(params: RemoveMerchantParams): Promise<RemoveMerchantResult> {\n validateShortId(\"storeId\", params.storeId, \"STO\");\n validateShortId(\"merchantId\", params.merchantId, \"MER\");\n return this.http.post<RemoveMerchantResult>(\"/v1/actions/store-merchant/remove-merchant\", params);\n }\n\n /**\n * Update a merchant's role in a store.\n *\n * @param params - Role update parameters\n * @returns Updated role details\n *\n * @example\n * const result = await client.storeMerchants.updateRole({\n * storeId: \"STO_xxx\",\n * merchantId: \"MER_xxx\",\n * role: \"member\",\n * });\n */\n async updateRole(params: UpdateRoleParams): Promise<UpdateRoleResult> {\n validateShortId(\"storeId\", params.storeId, \"STO\");\n validateShortId(\"merchantId\", params.merchantId, \"MER\");\n validateEnum(\"role\", params.role, [\"admin\", \"member\"]);\n return this.http.post<UpdateRoleResult>(\"/v1/actions/store-merchant/update-role\", params);\n }\n}\n","import { validateRequired, validateShortId } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type { CreateStoreParams, DeleteStoreParams, Store, UpdateStoreParams } from \"../types.js\";\n\n/** Store management resource — create, update, and delete stores. */\nexport class StoresResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Create a new store. Slug is auto-generated from the name.\n *\n * @param params - Store creation parameters\n * @returns Created store entity\n *\n * @example\n * const { store } = await client.stores.create({ name: \"My Store\" });\n */\n async create(params: CreateStoreParams): Promise<{ store: Store }> {\n validateRequired(\"name\", params.name);\n return this.http.post<{ store: Store }>(\"/v1/actions/store/create-store\", params);\n }\n\n /**\n * Update an existing store's settings.\n *\n * Settings objects (`webhookSettings`, `notificationSettings`, `checkoutSettings`)\n * support partial updates: omitted sub-fields keep existing values, `null` clears\n * a field. Pass the entire settings object as `null` to clear all fields.\n *\n * @param params - Fields to update (only provided fields are changed)\n * @returns Updated store entity\n *\n * @example\n * // Update name\n * const { store } = await client.stores.update({\n * id: \"STO_xxx\",\n * name: \"Updated Name\",\n * });\n *\n * @example\n * // Clear test webhook URL while keeping other webhook settings\n * const { store } = await client.stores.update({\n * id: \"STO_xxx\",\n * webhookSettings: { testWebhookUrl: null },\n * });\n */\n async update(params: UpdateStoreParams): Promise<{ store: Store }> {\n validateShortId(\"id\", params.id, \"STO\");\n return this.http.post<{ store: Store }>(\"/v1/actions/store/update-store\", params);\n }\n\n /**\n * Soft-delete a store. Only the owner can delete.\n *\n * @param params - Store to delete\n * @returns Deleted store entity (with `deletedAt` set)\n *\n * @example\n * const { store } = await client.stores.delete({ id: \"STO_xxx\" });\n */\n async delete(params: DeleteStoreParams): Promise<{ store: Store }> {\n validateShortId(\"id\", params.id, \"STO\");\n return this.http.post<{ store: Store }>(\"/v1/actions/store/delete-store\", params);\n }\n}\n","import { validateRequired, validateShortId } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type {\n CreateSubscriptionProductGroupParams,\n DeleteSubscriptionProductGroupParams,\n PublishSubscriptionProductGroupParams,\n SubscriptionProductGroup,\n UpdateSubscriptionProductGroupParams,\n} from \"../types.js\";\n\n/** Subscription product group management resource (shared trial, plan switching). */\nexport class SubscriptionProductGroupsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Create a subscription product group for shared-trial or plan switching.\n *\n * @param params - Group creation parameters\n * @returns Created group entity\n *\n * @example\n * const { group } = await client.subscriptionProductGroups.create({\n * storeId: \"STO_xxx\",\n * name: \"Pro Plans\",\n * rules: { sharedTrial: true },\n * productIds: [\"PROD_aaa\", \"PROD_bbb\"],\n * });\n */\n async create(params: CreateSubscriptionProductGroupParams): Promise<{ group: SubscriptionProductGroup }> {\n validateShortId(\"storeId\", params.storeId, \"STO\");\n validateRequired(\"name\", params.name);\n return this.http.post<{ group: SubscriptionProductGroup }>(\"/v1/actions/subscription-product-group/create-group\", params);\n }\n\n /**\n * Update a subscription product group. `productIds` is a full replacement.\n *\n * @param params - Group update parameters\n * @returns Updated group entity\n *\n * @example\n * const { group } = await client.subscriptionProductGroups.update({\n * id: \"GRP_xxx\",\n * productIds: [\"PROD_aaa\", \"PROD_bbb\", \"PROD_ccc\"],\n * });\n */\n async update(params: UpdateSubscriptionProductGroupParams): Promise<{ group: SubscriptionProductGroup }> {\n validateRequired(\"id\", params.id);\n return this.http.post<{ group: SubscriptionProductGroup }>(\"/v1/actions/subscription-product-group/update-group\", params);\n }\n\n /**\n * Hard-delete a subscription product group.\n *\n * @param params - Group to delete\n * @returns Deleted group entity\n *\n * @example\n * const { group } = await client.subscriptionProductGroups.delete({ id: \"GRP_xxx\" });\n */\n async delete(params: DeleteSubscriptionProductGroupParams): Promise<{ group: SubscriptionProductGroup }> {\n validateRequired(\"id\", params.id);\n return this.http.post<{ group: SubscriptionProductGroup }>(\"/v1/actions/subscription-product-group/delete-group\", params);\n }\n\n /**\n * Publish a test-environment group to production (upsert).\n *\n * @param params - Group to publish\n * @returns Published group entity\n *\n * @example\n * const { group } = await client.subscriptionProductGroups.publish({ id: \"GRP_xxx\" });\n */\n async publish(params: PublishSubscriptionProductGroupParams): Promise<{ group: SubscriptionProductGroup }> {\n validateRequired(\"id\", params.id);\n return this.http.post<{ group: SubscriptionProductGroup }>(\"/v1/actions/subscription-product-group/publish-group\", params);\n }\n}\n","import { validateEnum, validatePrices, validateRequired, validateShortId } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type {\n CreateSubscriptionProductParams,\n PublishSubscriptionProductParams,\n SubscriptionProductDetail,\n UpdateSubscriptionProductParams,\n UpdateSubscriptionStatusParams,\n} from \"../types.js\";\n\n/** Subscription product management resource. */\nexport class SubscriptionProductsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Create a subscription product with billing period and multi-currency pricing.\n *\n * @param params - Product creation parameters\n * @returns Created product detail\n *\n * @example\n * const { product } = await client.subscriptionProducts.create({\n * storeId: \"STO_xxx\",\n * name: \"Pro Plan\",\n * billingPeriod: \"monthly\",\n * prices: { USD: { amount: \"9.99\", taxCategory: \"saas\" } },\n * });\n */\n async create(params: CreateSubscriptionProductParams): Promise<{ product: SubscriptionProductDetail }> {\n validateShortId(\"storeId\", params.storeId, \"STO\");\n validateRequired(\"name\", params.name);\n validateEnum(\"billingPeriod\", params.billingPeriod, [\"weekly\", \"monthly\", \"quarterly\", \"yearly\"]);\n validatePrices(\"prices\", params.prices);\n return this.http.post<{ product: SubscriptionProductDetail }>(\"/v1/actions/subscription-product/create-product\", params);\n }\n\n /**\n * Update a subscription product. Creates a new version; skips if unchanged.\n *\n * @param params - Product update parameters (only `id` is required)\n * @returns Updated product detail\n *\n * @example\n * // Update only the name\n * const { product } = await client.subscriptionProducts.update({\n * id: \"PROD_xxx\",\n * name: \"Pro Plan v2\",\n * });\n *\n * @example\n * // Update prices and billing period\n * const { product } = await client.subscriptionProducts.update({\n * id: \"PROD_xxx\",\n * billingPeriod: \"yearly\",\n * prices: { USD: { amount: \"99.00\", taxCategory: \"saas\" } },\n * });\n */\n async update(params: UpdateSubscriptionProductParams): Promise<{ product: SubscriptionProductDetail }> {\n validateShortId(\"id\", params.id, \"PROD\");\n if (params.name !== undefined) validateRequired(\"name\", params.name);\n if (params.billingPeriod !== undefined)\n validateEnum(\"billingPeriod\", params.billingPeriod, [\"weekly\", \"monthly\", \"quarterly\", \"yearly\"]);\n if (params.prices) validatePrices(\"prices\", params.prices);\n return this.http.post<{ product: SubscriptionProductDetail }>(\"/v1/actions/subscription-product/update-product\", params);\n }\n\n /**\n * Publish a subscription product's test version to production.\n *\n * @param params - Product to publish\n * @returns Published product detail\n *\n * @example\n * const { product } = await client.subscriptionProducts.publish({ id: \"PROD_xxx\" });\n */\n async publish(params: PublishSubscriptionProductParams): Promise<{ product: SubscriptionProductDetail }> {\n validateShortId(\"id\", params.id, \"PROD\");\n return this.http.post<{ product: SubscriptionProductDetail }>(\"/v1/actions/subscription-product/publish-product\", params);\n }\n\n /**\n * Update a subscription product's status (active/inactive).\n *\n * @param params - Status update parameters\n * @returns Updated product detail\n *\n * @example\n * const { product } = await client.subscriptionProducts.updateStatus({\n * id: \"PROD_xxx\",\n * status: ProductVersionStatus.Active,\n * });\n */\n async updateStatus(params: UpdateSubscriptionStatusParams): Promise<{ product: SubscriptionProductDetail }> {\n validateShortId(\"id\", params.id, \"PROD\");\n validateEnum(\"status\", params.status, [\"active\", \"inactive\"]);\n return this.http.post<{ product: SubscriptionProductDetail }>(\"/v1/actions/subscription-product/update-status\", params);\n }\n}\n","import { createVerify } from \"node:crypto\";\n\nimport { normalizePublicKey } from \"./signing.js\";\n\nimport type { VerifyWebhookOptions, WebhookEvent, WebhookPublicKeys } from \"./types.js\";\n\n/** Default tolerance: 5 minutes */\nconst DEFAULT_TOLERANCE_MS = 5 * 60 * 1000;\n\n/** Waffo Pancake test environment webhook verification public key. */\nconst TEST_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxnmRY6yMMA3lVqmAU6ZG\nb1sjL/+r/z6E+ZjkXaDAKiqOhk9rpazni0bNsGXwmftTPk9jy2wn+j6JHODD/WH/\nSCnSfvKkLIjy4Hk7BuCgB174C0ydan7J+KgXLkOwgCAxxB68t2tezldwo74ZpXgn\nF49opzMvQ9prEwIAWOE+kV9iK6gx/AckSMtHIHpUesoPDkldpmFHlB2qpf1vsFTZ\n5kD6DmGl+2GIVK01aChy2lk8pLv0yUMu18v44sLkO5M44TkGPJD9qG09wrvVG2wp\nOTVCn1n5pP8P+HRLcgzbUB3OlZVfdFurn6EZwtyL4ZD9kdkQ4EZE/9inKcp3c1h4\nxwIDAQAB\n-----END PUBLIC KEY-----`;\n\n/** Waffo Pancake production environment webhook verification public key. */\nconst PROD_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz+xApdTIb4ua+DgZKQ54\niBsD82ybyhGCLRETONW4Jgbb3A8DUM1LqBk6r/CmTOCHqLalTQHNigvP3R5zkDNX\niRJz6gA4MJ/+8K0+mnEE2RISQzN+Qu65TNd6svb+INm/kMaftY4uIXr6y6kchtTJ\ndwnQhcKdAL2v7h7IFnkVelQsKxDdb2PqX8xX/qwd01iXvMcpCCaXovUwZsxH2QN5\nZKBTseJivbhUeyJCco4fdUyxOMHe2ybCVhyvim2uxAl1nkvL5L8RCWMCAV55LLo0\n9OhmLahz/DYNu13YLVP6dvIT09ZFBYU6Owj1NxdinTynlJCFS9VYwBgmftosSE1U\ndwIDAQAB\n-----END PUBLIC KEY-----`;\n\n/**\n * Parse `X-Waffo-Signature` header.\n *\n * Format: `t=<timestamp>,v1=<base64signature>`\n *\n * @returns Parsed `t` (timestamp string) and `v1` (base64 signature)\n */\nfunction parseSignatureHeader(header: string): { t: string; v1: string } {\n let t = \"\";\n let v1 = \"\";\n for (const pair of header.split(\",\")) {\n const eqIdx = pair.indexOf(\"=\");\n if (eqIdx === -1) continue;\n const key = pair.slice(0, eqIdx).trim();\n const value = pair.slice(eqIdx + 1).trim();\n if (key === \"t\") t = value;\n else if (key === \"v1\") v1 = value;\n }\n return { t, v1 };\n}\n\n/**\n * Verify RSA-SHA256 signature against a public key.\n *\n * @param signatureInput - The string to verify (`${t}.${rawBody}`)\n * @param v1 - Base64-encoded signature\n * @param publicKey - PEM public key\n * @returns Whether the signature is valid\n */\nfunction rsaVerify(signatureInput: string, v1: string, publicKey: string): boolean {\n const verifier = createVerify(\"RSA-SHA256\");\n verifier.update(signatureInput);\n return verifier.verify(publicKey, v1, \"base64\");\n}\n\n/**\n * Resolve the public key for a given environment using the multi-level fallback chain.\n *\n * Resolution order:\n * 1. `configKeys[env]` or `configKeys` (if string) — from WaffoPancakeConfig\n * 2. `WAFFO_WEBHOOK_TEST_PUBLIC_KEY` / `WAFFO_WEBHOOK_PROD_PUBLIC_KEY` — env var per-env\n * 3. `WAFFO_WEBHOOK_PUBLIC_KEY` — env var shared\n * 4. Built-in hardcoded key\n *\n * @param env - Target environment\n * @param configKeys - Config-level public key(s)\n * @returns Resolved and normalized PEM public key\n */\nfunction resolveKeyForEnv(env: \"test\" | \"prod\", configKeys?: WebhookPublicKeys): string {\n // 1. Config-level key\n if (typeof configKeys === \"string\") {\n return normalizePublicKey(configKeys);\n }\n if (configKeys?.[env]) {\n return normalizePublicKey(configKeys[env]);\n }\n\n // 2. Environment variable (per-env)\n const envSpecific = env === \"test\" ? process.env.WAFFO_WEBHOOK_TEST_PUBLIC_KEY : process.env.WAFFO_WEBHOOK_PROD_PUBLIC_KEY;\n if (envSpecific) {\n return normalizePublicKey(envSpecific);\n }\n\n // 3. Environment variable (shared)\n const generic = process.env.WAFFO_WEBHOOK_PUBLIC_KEY;\n if (generic) {\n return normalizePublicKey(generic);\n }\n\n // 4. Built-in hardcoded key\n return env === \"test\" ? TEST_PUBLIC_KEY : PROD_PUBLIC_KEY;\n}\n\n/**\n * Verify and parse an incoming Waffo Pancake webhook event.\n *\n * Public key resolution (per environment):\n * 1. `options.publicKey` — per-call override (highest priority, skips all other resolution)\n * 2. `options.publicKeys[env]` or `options.publicKeys` (string) — config-level\n * 3. `WAFFO_WEBHOOK_{TEST|PROD}_PUBLIC_KEY` environment variable\n * 4. `WAFFO_WEBHOOK_PUBLIC_KEY` environment variable\n * 5. Built-in hardcoded key\n *\n * Behavior:\n * - Parses the `X-Waffo-Signature` header (`t=<timestamp>,v1=<base64sig>`)\n * - Builds signature input `${t}.${rawBody}` and verifies with RSA-SHA256\n * - When `environment` is not specified, tries prod key first, then test key\n * - Optional: checks timestamp to prevent replay attacks (default 5-minute tolerance)\n *\n * @param payload - Raw request body string (must be unparsed)\n * @param signatureHeader - Value of the `X-Waffo-Signature` header\n * @param options - Verification options\n * @returns Parsed webhook event\n * @throws Error if header is missing/malformed, signature is invalid, or timestamp is stale\n *\n * @example\n * // Express (use raw body!)\n * app.post(\"/webhooks\", express.raw({ type: \"application/json\" }), (req, res) => {\n * try {\n * const event = verifyWebhook(\n * req.body.toString(\"utf-8\"),\n * req.headers[\"x-waffo-signature\"] as string,\n * );\n * res.status(200).send(\"OK\");\n * handleEventAsync(event).catch(console.error);\n * } catch {\n * res.status(401).send(\"Invalid signature\");\n * }\n * });\n *\n * @example\n * // Next.js App Router\n * export async function POST(request: Request) {\n * const body = await request.text();\n * const sig = request.headers.get(\"x-waffo-signature\");\n * const event = verifyWebhook(body, sig);\n * // handle event ...\n * return new Response(\"OK\");\n * }\n *\n * @example\n * // Specify environment explicitly\n * const event = verifyWebhook(body, sig, { environment: \"prod\" });\n *\n * @example\n * // Disable replay protection\n * const event = verifyWebhook(body, sig, { toleranceMs: 0 });\n */\nexport function verifyWebhook<T = Record<string, unknown>>(\n payload: string,\n signatureHeader: string | undefined | null,\n options?: VerifyWebhookOptions,\n): WebhookEvent<T> {\n if (!signatureHeader) {\n throw new Error(\"Missing X-Waffo-Signature header\");\n }\n\n const { t, v1 } = parseSignatureHeader(signatureHeader);\n if (!t || !v1) {\n throw new Error(\"Malformed X-Waffo-Signature header: missing t or v1\");\n }\n\n // Replay protection\n const toleranceMs = options?.toleranceMs ?? DEFAULT_TOLERANCE_MS;\n if (toleranceMs > 0) {\n const timestampMs = Number(t);\n if (Number.isNaN(timestampMs)) {\n throw new Error(\"Invalid timestamp in X-Waffo-Signature header\");\n }\n if (Math.abs(Date.now() - timestampMs) > toleranceMs) {\n throw new Error(\"Webhook timestamp outside tolerance window (possible replay attack)\");\n }\n }\n\n // RSA-SHA256 verification\n const signatureInput = `${t}.${payload}`;\n const directKey = options?.publicKey;\n\n if (directKey) {\n // Per-call override — highest priority, skip all resolution\n const normalizedKey = normalizePublicKey(directKey);\n if (!rsaVerify(signatureInput, v1, normalizedKey)) {\n throw new Error(\"Invalid webhook signature (custom key)\");\n }\n } else {\n const configKeys = options?.publicKeys;\n const env = options?.environment;\n\n if (env === \"test\" || env === \"prod\") {\n const key = resolveKeyForEnv(env, configKeys);\n if (!rsaVerify(signatureInput, v1, key)) {\n throw new Error(`Invalid webhook signature (${env} key)`);\n }\n } else {\n // Auto-detect: try prod first, then test\n const prodKey = resolveKeyForEnv(\"prod\", configKeys);\n if (!rsaVerify(signatureInput, v1, prodKey)) {\n const testKey = resolveKeyForEnv(\"test\", configKeys);\n if (!rsaVerify(signatureInput, v1, testKey)) {\n throw new Error(\"Invalid webhook signature (tried both prod and test keys)\");\n }\n }\n }\n }\n\n return JSON.parse(payload) as WebhookEvent<T>;\n}\n","import { verifyWebhook } from \"../webhooks.js\";\n\nimport type { VerifyWebhookOptions, WebhookEvent, WebhookPublicKeys } from \"../types.js\";\n\n/**\n * Webhook signature verification resource.\n *\n * Unlike other resources, this does not use HttpClient — webhook verification\n * is a local cryptographic operation that does not require API calls.\n */\nexport class WebhooksResource {\n /** @param publicKeys - Optional config-level public key(s) from WaffoPancakeConfig */\n constructor(private readonly publicKeys: WebhookPublicKeys | undefined) {}\n\n /**\n * Verify and parse an incoming webhook event.\n *\n * Key resolution order:\n * 1. `options.publicKey` — per-call override (highest priority)\n * 2. `config.webhookPublicKey[env]` or `config.webhookPublicKey` (string)\n * 3. `WAFFO_WEBHOOK_{TEST|PROD}_PUBLIC_KEY` environment variable\n * 4. `WAFFO_WEBHOOK_PUBLIC_KEY` environment variable\n * 5. Built-in hardcoded key\n *\n * @param payload - Raw request body string (must be unparsed)\n * @param signatureHeader - Value of the `X-Waffo-Signature` header\n * @param options - Verification options (optional)\n * @returns Parsed webhook event\n * @throws Error if signature is invalid, header is malformed, or timestamp is stale\n *\n * @example\n * const event = client.webhooks.verify(rawBody, signatureHeader);\n *\n * @example\n * // Specify environment\n * const event = client.webhooks.verify(rawBody, sig, { environment: \"test\" });\n *\n * @example\n * // Per-call key override\n * const event = client.webhooks.verify(rawBody, sig, { publicKey: oneOffKey });\n */\n verify<T = Record<string, unknown>>(\n payload: string,\n signatureHeader: string | undefined | null,\n options?: VerifyWebhookOptions,\n ): WebhookEvent<T> {\n const mergedOptions: VerifyWebhookOptions = {\n ...options,\n publicKeys: options?.publicKeys ?? this.publicKeys,\n };\n return verifyWebhook<T>(payload, signatureHeader, mergedOptions);\n }\n}\n","import { BuyerHttpClient } from \"./buyer-http-client.js\";\nimport { HttpClient } from \"./http-client.js\";\nimport { AuthResource } from \"./resources/auth.js\";\nimport { BuyerSession } from \"./resources/buyer.js\";\nimport { CheckoutResource } from \"./resources/checkout.js\";\nimport { GraphQLResource } from \"./resources/graphql.js\";\nimport { OnetimeProductsResource } from \"./resources/onetime-products.js\";\nimport { OrdersResource } from \"./resources/orders.js\";\nimport { StoreMerchantsResource } from \"./resources/store-merchants.js\";\nimport { StoresResource } from \"./resources/stores.js\";\nimport { SubscriptionProductGroupsResource } from \"./resources/subscription-product-groups.js\";\nimport { SubscriptionProductsResource } from \"./resources/subscription-products.js\";\nimport { WebhooksResource } from \"./resources/webhooks.js\";\nimport { validateShortId } from \"./validation.js\";\n\nimport type { WaffoPancakeConfig } from \"./types.js\";\n\n/**\n * Waffo Pancake TypeScript SDK client.\n *\n * Uses Merchant API Key (RSA-SHA256) authentication. All requests are\n * automatically signed — no manual header construction needed.\n *\n * @example\n * import { WaffoPancake } from \"@waffo/pancake-ts\";\n *\n * const client = new WaffoPancake({\n * merchantId: \"MER_2D5F8G3H1K4M6N9P0Q7R8S\", // MER_{base62} format\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * });\n *\n * // Create a store — IDs are returned in {prefix}_{base62} format\n * const { store } = await client.stores.create({ name: \"My Store\" });\n * // => store.id = \"STO_...\"\n *\n * // Create a product\n * const { product } = await client.onetimeProducts.create({\n * storeId: store.id, // \"STO_...\"\n * name: \"E-Book\",\n * prices: { USD: { amount: \"29.00\", taxCategory: \"digital_goods\" } },\n * });\n * // => product.id = \"PROD_...\"\n *\n * // Create a checkout session\n * const session = await client.checkout.createSession({\n * productId: product.id,\n * currency: \"USD\",\n * });\n * // => redirect customer to session.checkoutUrl\n *\n * // Query data via GraphQL\n * const result = await client.graphql.query({\n * query: `query { stores { id name status } }`,\n * });\n *\n * @example\n * // Per-environment webhook public keys\n * const client = new WaffoPancake({\n * merchantId: \"...\",\n * privateKey: \"...\",\n * webhookPublicKey: {\n * test: process.env.WAFFO_TEST_PUB_KEY!,\n * prod: process.env.WAFFO_PROD_PUB_KEY!,\n * },\n * });\n * const event = client.webhooks.verify(rawBody, signatureHeader);\n */\nexport class WaffoPancake {\n private readonly http: HttpClient;\n private readonly config: WaffoPancakeConfig;\n\n readonly auth: AuthResource;\n readonly stores: StoresResource;\n readonly storeMerchants: StoreMerchantsResource;\n readonly onetimeProducts: OnetimeProductsResource;\n readonly subscriptionProducts: SubscriptionProductsResource;\n readonly subscriptionProductGroups: SubscriptionProductGroupsResource;\n readonly orders: OrdersResource;\n readonly checkout: CheckoutResource;\n readonly graphql: GraphQLResource;\n readonly webhooks: WebhooksResource;\n\n constructor(config: WaffoPancakeConfig) {\n validateShortId(\"merchantId\", config.merchantId, \"MER\");\n this.config = config;\n this.http = new HttpClient(config);\n\n this.auth = new AuthResource(this.http);\n this.stores = new StoresResource(this.http);\n this.storeMerchants = new StoreMerchantsResource(this.http);\n this.onetimeProducts = new OnetimeProductsResource(this.http);\n this.subscriptionProducts = new SubscriptionProductsResource(this.http);\n this.subscriptionProductGroups = new SubscriptionProductGroupsResource(this.http);\n this.orders = new OrdersResource(this.http);\n this.checkout = new CheckoutResource(this.http);\n this.graphql = new GraphQLResource(this.http);\n this.webhooks = new WebhooksResource(config.webhookPublicKey);\n }\n\n /**\n * Create a buyer session for self-service operations.\n *\n * The returned session uses Bearer token authentication and provides\n * methods for order cancellation, subscription management, refund tickets,\n * and scoped GraphQL queries.\n *\n * @param token - Session token from `client.auth.issueSessionToken()`\n * @returns A buyer session with self-service methods\n *\n * @example\n * const { token } = await client.auth.issueSessionToken({\n * storeId: \"STO_xxx\",\n * buyerIdentity: \"customer@example.com\",\n * });\n * const buyer = client.buyer(token);\n * await buyer.cancelSubscription({ orderId: \"ORD_xxx\" });\n */\n buyer(token: string): BuyerSession {\n const buyerHttp = new BuyerHttpClient(token, {\n baseUrl: this.config.baseUrl,\n fetch: this.config.fetch,\n });\n return new BuyerSession(buyerHttp);\n }\n}\n","// ---------------------------------------------------------------------------\n// Client config\n// ---------------------------------------------------------------------------\n\nexport interface WaffoPancakeConfig {\n /** Merchant ID in `MER_{base62}` format (sent as X-Merchant-Id header) */\n merchantId: string;\n /** RSA private key in PEM format for request signing */\n privateKey: string;\n /** Base URL override (default: https://api.waffo.ai) */\n baseUrl?: string;\n /** Custom fetch implementation (default: global fetch) */\n fetch?: typeof fetch;\n /**\n * Custom RSA public key(s) for webhook signature verification.\n *\n * - `string` — single key used for both test and prod environments\n * - `{ test?, prod? }` — per-environment keys\n *\n * Resolution order per environment: config key → env var → built-in key.\n * @see {@link VerifyWebhookOptions} for per-call overrides\n */\n webhookPublicKey?: WebhookPublicKeys;\n}\n\n// ---------------------------------------------------------------------------\n// Internal HTTP options\n// ---------------------------------------------------------------------------\n\n/**\n * Options for {@link HttpClient.post}.\n * Not exported publicly — used by resource classes.\n */\nexport interface PostOptions {\n /**\n * Time window in seconds for idempotency key rotation.\n * When set, a floored timestamp is mixed into the key so identical params\n * produce a new key after the window elapses (e.g. 60 = per-minute dedup).\n */\n idempotencyWindow?: number;\n}\n\n// ---------------------------------------------------------------------------\n// API response envelope\n// ---------------------------------------------------------------------------\n\n/**\n * Single error object within the `errors` array.\n *\n * @example\n * { message: \"Store slug already exists\", layer: \"store\" }\n */\nexport interface ApiError {\n /** Error message */\n message: string;\n /** Layer where the error originated */\n layer: `${ErrorLayer}`;\n}\n\n/** Successful API response envelope. */\nexport interface ApiSuccessResponse<T> {\n data: T;\n}\n\n/**\n * Error API response envelope.\n *\n * `errors` are ordered by call stack: `[0]` is the deepest layer, `[n]` is the outermost.\n */\nexport interface ApiErrorResponse {\n data: null;\n errors: ApiError[];\n}\n\n/** Union type of success and error API responses. */\nexport type ApiResponse<T> = ApiSuccessResponse<T> | ApiErrorResponse;\n\n// ---------------------------------------------------------------------------\n// Enums (runtime-accessible values)\n// ---------------------------------------------------------------------------\n\n/**\n * Environment type.\n * @see waffo-pancake-order-service/app/lib/types.ts\n */\nexport enum Environment {\n Test = \"test\",\n Prod = \"prod\",\n}\n\n/**\n * Tax category for products.\n * @see waffo-pancake-product-service/app/lib/resources/types.ts\n */\nexport enum TaxCategory {\n DigitalGoods = \"digital_goods\",\n SaaS = \"saas\",\n Software = \"software\",\n Ebook = \"ebook\",\n OnlineCourse = \"online_course\",\n Consulting = \"consulting\",\n ProfessionalService = \"professional_service\",\n}\n\n/**\n * Subscription billing period.\n * @see waffo-pancake-product-service/app/lib/resources/types.ts\n */\nexport enum BillingPeriod {\n Weekly = \"weekly\",\n Monthly = \"monthly\",\n Quarterly = \"quarterly\",\n Yearly = \"yearly\",\n}\n\n/**\n * Product version status.\n * @see waffo-pancake-product-service/app/lib/resources/types.ts\n */\nexport enum ProductVersionStatus {\n Active = \"active\",\n Inactive = \"inactive\",\n}\n\n/**\n * Store entity status.\n * @see waffo-pancake-store-service/app/lib/resources/store.ts\n */\nexport enum EntityStatus {\n Active = \"active\",\n Inactive = \"inactive\",\n Suspended = \"suspended\",\n}\n\n/**\n * Store member role.\n * @see waffo-pancake-store-service/app/lib/resources/store.ts\n */\nexport enum StoreRole {\n Owner = \"owner\",\n Admin = \"admin\",\n Member = \"member\",\n}\n\n/**\n * One-time order status.\n * @see waffo-pancake-order-service/app/lib/resources/onetime-order.ts\n */\nexport enum OnetimeOrderStatus {\n Pending = \"pending\",\n Completed = \"completed\",\n Canceled = \"canceled\",\n}\n\n/**\n * Subscription order status.\n *\n * State machine:\n * - pending -> active, canceled, closed (PSP CLOSE from never-activated)\n * - active -> canceling, past_due, canceled, expired\n * - canceling -> active, canceled\n * - past_due -> active, canceled\n * - closed -> terminal (never-activated subscription closed by PSP)\n * - canceled -> terminal\n * - expired -> terminal\n *\n * @see waffo-pancake-order-service/app/lib/resources/subscription-order.ts\n */\nexport enum SubscriptionOrderStatus {\n Pending = \"pending\",\n Active = \"active\",\n Canceling = \"canceling\",\n PastDue = \"past_due\",\n Closed = \"closed\",\n Canceled = \"canceled\",\n Expired = \"expired\",\n}\n\n/**\n * Payment status.\n * @see waffo-pancake-order-service/app/lib/resources/payment.ts\n */\nexport enum PaymentStatus {\n Pending = \"pending\",\n Succeeded = \"succeeded\",\n Failed = \"failed\",\n Canceled = \"canceled\",\n}\n\n/**\n * Refund ticket status.\n * @see waffo-pancake-order-service/app/lib/resources/refund-ticket.ts\n */\nexport enum RefundTicketStatus {\n Pending = \"pending\",\n UnderReview = \"under_review\",\n Approved = \"approved\",\n Rejected = \"rejected\",\n Returned = \"returned\",\n Processing = \"processing\",\n Succeeded = \"succeeded\",\n Failed = \"failed\",\n Cancelled = \"cancelled\",\n}\n\n/**\n * Refund status.\n * @see waffo-pancake-order-service/app/lib/resources/refund.ts\n */\nexport enum RefundStatus {\n Succeeded = \"succeeded\",\n Failed = \"failed\",\n}\n\n/**\n * Media asset type.\n * @see waffo-pancake-product-service/app/lib/resources/types.ts\n */\nexport enum MediaType {\n Image = \"image\",\n Video = \"video\",\n}\n\n/** Error layer identifier in the call stack. */\nexport enum ErrorLayer {\n Gateway = \"gateway\",\n User = \"user\",\n Store = \"store\",\n Product = \"product\",\n Order = \"order\",\n Ticket = \"ticket\",\n GraphQL = \"graphql\",\n Resource = \"resource\",\n /** SDK-specific layer for email delivery errors (not part of the service-side error layers). */\n Email = \"email\",\n /** SDK-side input validation (caught before network request). */\n Sdk = \"sdk\",\n}\n\n// ---------------------------------------------------------------------------\n// Auth\n// ---------------------------------------------------------------------------\n\n/**\n * Parameters for issuing a buyer session token.\n *\n * Provide either `storeId` or `productId` (at least one required).\n * When `productId` is given without `storeId`, the server derives the store from the product.\n *\n * @see waffo-pancake-user-service/app/lib/utils/jwt.ts IssueSessionTokenRequest\n */\nexport interface IssueSessionTokenParams {\n /**\n * Buyer identity — encoded into the JWT payload for merchant-side buyer\n * identification. Accepts an email or any merchant-provided identifier string.\n * To pre-fill the checkout page's email field, use `buyerEmail` on\n * `checkout.authenticated.create`.\n */\n buyerIdentity: string;\n /** Store ID (optional when `productId` is provided) */\n storeId?: string;\n /** Product ID — used to derive the store when `storeId` is omitted */\n productId?: string;\n}\n\n/**\n * Issued session token response.\n *\n * @example\n * { token: \"eyJhbGciOi...\", expiresAt: \"2026-03-10T09:00:00.000Z\" }\n */\nexport interface SessionToken {\n /** JWT token string */\n token: string;\n /** Expiration time (ISO 8601 UTC) */\n expiresAt: string;\n}\n\n// ---------------------------------------------------------------------------\n// Store — from waffo-pancake-store-service\n// ---------------------------------------------------------------------------\n\n/**\n * Webhook configuration for test and production environments.\n * @see waffo-pancake-store-service/app/lib/types.ts\n */\nexport interface WebhookSettings {\n /** Test environment webhook URL */\n testWebhookUrl: string | null;\n /** Production environment webhook URL */\n prodWebhookUrl: string | null;\n /** Event types subscribed in test environment */\n testEvents: string[];\n /** Event types subscribed in production environment */\n prodEvents: string[];\n}\n\n/**\n * Notification settings (all default to true).\n * @see waffo-pancake-store-service/app/lib/types.ts\n */\nexport interface NotificationSettings {\n emailOrderConfirmation: boolean;\n emailSubscriptionConfirmation: boolean;\n emailSubscriptionCycled: boolean;\n emailSubscriptionCanceled: boolean;\n emailSubscriptionRevoked: boolean;\n emailSubscriptionPastDue: boolean;\n notifyNewOrders: boolean;\n notifyNewSubscriptions: boolean;\n}\n\n/**\n * Single-theme checkout page styling.\n * @see waffo-pancake-store-service/app/lib/types.ts\n */\nexport interface CheckoutThemeSettings {\n checkoutLogo: string | null;\n checkoutColorPrimary: string;\n checkoutColorBackground: string;\n checkoutColorCard: string;\n checkoutColorText: string;\n checkoutBorderRadius: string;\n}\n\n/**\n * Checkout page configuration (light and dark themes).\n * @see waffo-pancake-store-service/app/lib/types.ts\n */\nexport interface CheckoutSettings {\n defaultDarkMode: boolean;\n light: CheckoutThemeSettings;\n dark: CheckoutThemeSettings;\n}\n\n/**\n * Store entity.\n * @see waffo-pancake-store-service/app/lib/resources/store.ts\n */\nexport interface Store {\n id: string;\n name: string;\n status: EntityStatus;\n logo: string | null;\n supportEmail: string | null;\n website: string | null;\n slug: string | null;\n prodEnabled: boolean;\n webhookSettings: WebhookSettings | null;\n notificationSettings: NotificationSettings | null;\n checkoutSettings: CheckoutSettings | null;\n deletedAt: string | null;\n createdAt: string;\n updatedAt: string;\n}\n\n/** Parameters for creating a store. */\nexport interface CreateStoreParams {\n /** Store name (slug is auto-generated) */\n name: string;\n}\n\n/**\n * Parameters for updating a store.\n *\n * Settings objects support partial updates — omitted sub-fields keep their\n * existing values, `null` clears a field, and a concrete value sets it.\n * Pass the entire settings object as `null` to clear all fields in the group.\n */\nexport interface UpdateStoreParams {\n /** Store ID */\n id: string;\n /** Store display name */\n name?: string;\n /** Store status */\n status?: EntityStatus;\n /** Store logo URL (set to `null` to remove) */\n logo?: string | null;\n /** Support email address (set to `null` to remove) */\n supportEmail?: string | null;\n /** Store website URL (set to `null` to remove) */\n website?: string | null;\n /** Webhook configuration (partial update — omitted fields keep existing values, set to `null` to clear all) */\n webhookSettings?: Partial<WebhookSettings> | null;\n /** Notification preferences (partial update — omitted fields keep existing values, set to `null` to clear all) */\n notificationSettings?: Partial<NotificationSettings> | null;\n /** Checkout page theme configuration (partial update — omitted fields keep existing values, set to `null` to clear all) */\n checkoutSettings?: Partial<CheckoutSettings> | null;\n}\n\n/** Parameters for deleting (soft-delete) a store. */\nexport interface DeleteStoreParams {\n /** Store ID */\n id: string;\n}\n\n// ---------------------------------------------------------------------------\n// Store Merchant (coming soon — endpoints return 501)\n// ---------------------------------------------------------------------------\n\n/** Parameters for adding a merchant to a store. */\nexport interface AddMerchantParams {\n storeId: string;\n email: string;\n role: \"admin\" | \"member\";\n}\n\n/** Result of adding a merchant to a store. */\nexport interface AddMerchantResult {\n storeId: string;\n merchantId: string;\n email: string;\n role: string;\n status: string;\n addedAt: string;\n}\n\n/** Parameters for removing a merchant from a store. */\nexport interface RemoveMerchantParams {\n storeId: string;\n merchantId: string;\n}\n\n/** Result of removing a merchant from a store. */\nexport interface RemoveMerchantResult {\n message: string;\n removedAt: string;\n}\n\n/** Parameters for updating a merchant's role. */\nexport interface UpdateRoleParams {\n storeId: string;\n merchantId: string;\n role: \"admin\" | \"member\";\n}\n\n/** Result of updating a merchant's role. */\nexport interface UpdateRoleResult {\n storeId: string;\n merchantId: string;\n role: string;\n updatedAt: string;\n}\n\n// ---------------------------------------------------------------------------\n// Product — shared types from waffo-pancake-product-service\n// ---------------------------------------------------------------------------\n\n/**\n * Price for a single currency.\n *\n * Amounts are represented as display strings (e.g., \"9.99\" for USD, \"1000\" for JPY).\n * The server handles conversion to/from smallest currency units internally.\n *\n * @see waffo-pancake-product-service/app/lib/resources/types.ts\n *\n * @example\n * // USD $9.99\n * { amount: \"9.99\", taxCategory: \"saas\" }\n *\n * @example\n * // JPY ¥1000\n * { amount: \"1000\", taxCategory: \"software\" }\n */\nexport interface PriceInfo {\n /** Price amount as display string (e.g., \"9.99\" for USD, \"1000\" for JPY) */\n amount: string;\n /** Tax category */\n taxCategory: TaxCategory;\n}\n\n/**\n * Multi-currency prices (keyed by ISO 4217 currency code).\n *\n * @see waffo-pancake-product-service/app/lib/resources/types.ts\n *\n * @example\n * {\n * \"USD\": { amount: \"9.99\", taxCategory: \"saas\" },\n * \"EUR\": { amount: \"8.99\", taxCategory: \"saas\" }\n * }\n */\nexport type Prices = Record<string, PriceInfo>;\n\n/**\n * Media asset (image or video).\n * @see waffo-pancake-product-service/app/lib/resources/types.ts\n */\nexport interface MediaItem {\n /** Media type */\n type: `${MediaType}`;\n /** Asset URL */\n url: string;\n /** Alt text */\n alt?: string;\n /** Thumbnail URL */\n thumbnail?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Onetime Product — from waffo-pancake-product-service\n// ---------------------------------------------------------------------------\n\n/**\n * One-time product detail (public API shape).\n * @see waffo-pancake-product-service/app/lib/resources/onetime-product.ts OnetimeProductDetail\n */\nexport interface OnetimeProductDetail {\n id: string;\n storeId: string;\n name: string;\n description: string | null;\n prices: Prices;\n media: MediaItem[];\n successUrl: string | null;\n metadata: Record<string, unknown>;\n status: ProductVersionStatus;\n createdAt: string;\n updatedAt: string;\n}\n\n/**\n * Parameters for creating a one-time product.\n * @see waffo-pancake-product-service/app/lib/resources/onetime-product.ts CreateOnetimeProductRequestBody\n */\nexport interface CreateOnetimeProductParams {\n storeId: string;\n name: string;\n prices: Prices;\n description?: string;\n media?: MediaItem[];\n successUrl?: string;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Parameters for updating a one-time product (creates a new version; skips if unchanged).\n * @see waffo-pancake-product-service/app/lib/resources/onetime-product.ts UpdateOnetimeProductContentRequestBody\n */\nexport interface UpdateOnetimeProductParams {\n id: string;\n name?: string;\n prices?: Prices;\n description?: string;\n media?: MediaItem[];\n successUrl?: string;\n metadata?: Record<string, unknown>;\n}\n\n/** Parameters for publishing a one-time product's test version to production. */\nexport interface PublishOnetimeProductParams {\n /** Product ID */\n id: string;\n}\n\n/**\n * Parameters for updating a one-time product's status.\n * @see waffo-pancake-product-service/app/lib/resources/onetime-product.ts UpdateOnetimeStatusRequestBody\n */\nexport interface UpdateOnetimeStatusParams {\n id: string;\n status: ProductVersionStatus;\n}\n\n// ---------------------------------------------------------------------------\n// Subscription Product — from waffo-pancake-product-service\n// ---------------------------------------------------------------------------\n\n/**\n * Subscription product detail (public API shape).\n * @see waffo-pancake-product-service/app/lib/resources/subscription-product.ts SubscriptionProductDetail\n */\nexport interface SubscriptionProductDetail {\n id: string;\n storeId: string;\n name: string;\n description: string | null;\n billingPeriod: BillingPeriod;\n prices: Prices;\n media: MediaItem[];\n successUrl: string | null;\n metadata: Record<string, unknown>;\n status: ProductVersionStatus;\n createdAt: string;\n updatedAt: string;\n}\n\n/**\n * Parameters for creating a subscription product.\n * @see waffo-pancake-product-service/app/lib/resources/subscription-product.ts CreateSubscriptionProductRequestBody\n */\nexport interface CreateSubscriptionProductParams {\n storeId: string;\n name: string;\n billingPeriod: BillingPeriod;\n prices: Prices;\n description?: string;\n media?: MediaItem[];\n successUrl?: string;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Parameters for updating a subscription product (creates a new version; skips if unchanged).\n * @see waffo-pancake-product-service/app/lib/resources/subscription-product.ts UpdateSubscriptionProductContentRequestBody\n */\nexport interface UpdateSubscriptionProductParams {\n id: string;\n name?: string;\n billingPeriod?: BillingPeriod;\n prices?: Prices;\n description?: string;\n media?: MediaItem[];\n successUrl?: string;\n metadata?: Record<string, unknown>;\n}\n\n/** Parameters for publishing a subscription product's test version to production. */\nexport interface PublishSubscriptionProductParams {\n /** Product ID */\n id: string;\n}\n\n/**\n * Parameters for updating a subscription product's status.\n * @see waffo-pancake-product-service/app/lib/resources/subscription-product.ts UpdateSubscriptionStatusRequestBody\n */\nexport interface UpdateSubscriptionStatusParams {\n id: string;\n status: ProductVersionStatus;\n}\n\n// ---------------------------------------------------------------------------\n// Subscription Product Group — from waffo-pancake-product-service\n// ---------------------------------------------------------------------------\n\n/**\n * Group rules for subscription product groups.\n * @see waffo-pancake-product-service/app/lib/resources/subscription-product-group.ts\n */\nexport interface GroupRules {\n /** Whether trial period is shared across products in the group */\n sharedTrial: boolean;\n}\n\n/**\n * Subscription product group entity.\n * @see waffo-pancake-product-service/app/lib/resources/subscription-product-group.ts\n */\nexport interface SubscriptionProductGroup {\n id: string;\n storeId: string;\n name: string;\n description: string | null;\n rules: GroupRules;\n productIds: string[];\n environment: Environment;\n createdAt: string;\n updatedAt: string;\n}\n\n/**\n * Parameters for creating a subscription product group.\n * @see waffo-pancake-product-service/app/lib/resources/subscription-product-group.ts CreateGroupRequestBody\n */\nexport interface CreateSubscriptionProductGroupParams {\n storeId: string;\n name: string;\n description?: string;\n rules?: GroupRules;\n productIds?: string[];\n}\n\n/**\n * Parameters for updating a subscription product group (`productIds` is a full replacement).\n * @see waffo-pancake-product-service/app/lib/resources/subscription-product-group.ts UpdateGroupRequestBody\n */\nexport interface UpdateSubscriptionProductGroupParams {\n id: string;\n name?: string;\n description?: string;\n rules?: GroupRules;\n productIds?: string[];\n}\n\n/** Parameters for hard-deleting a subscription product group. */\nexport interface DeleteSubscriptionProductGroupParams {\n /** Group ID */\n id: string;\n}\n\n/** Parameters for publishing a test-environment group to production (upsert). */\nexport interface PublishSubscriptionProductGroupParams {\n /** Group ID */\n id: string;\n}\n\n// ---------------------------------------------------------------------------\n// Order — from waffo-pancake-order-service\n// ---------------------------------------------------------------------------\n\n/** Parameters for canceling a subscription order. */\nexport interface CancelSubscriptionParams {\n /** Order ID */\n orderId: string;\n}\n\n/**\n * Result of canceling a subscription order.\n * @see waffo-pancake-order-service cancel-order route.ts\n */\nexport interface CancelSubscriptionResult {\n orderId: string;\n /** Status after cancellation (`\"canceled\"` or `\"canceling\"`) */\n status: `${SubscriptionOrderStatus}`;\n}\n\n/**\n * Buyer billing details for checkout.\n * @see waffo-pancake-order-service/app/lib/types.ts\n */\nexport interface BillingDetail {\n /** Country code (ISO 3166-1 alpha-2) */\n country: string;\n /** Whether this is a business purchase */\n isBusiness: boolean;\n /** Postal / ZIP code (required for US, at least one of postcode/state for CA) */\n postcode?: string;\n /** State / province code (at least one of state/postcode for CA) */\n state?: string;\n /** Business name (recommended for invoicing, does not affect tax calculation) */\n businessName?: string;\n /** Tax ID / VAT number (EU businesses: triggers reverse charge 0% when provided) */\n taxId?: string;\n}\n\n/**\n * Parameters for creating a checkout session.\n * @see waffo-pancake-order-service/app/lib/types.ts CreateCheckoutSessionRequest\n */\nexport interface CreateCheckoutSessionParams {\n /** Product ID */\n productId: string;\n /** Currency code (ISO 4217) */\n currency: string;\n /** Optional price snapshot override (reads from DB if omitted) */\n priceSnapshot?: PriceInfo;\n /** Trial toggle override (subscription only) */\n withTrial?: boolean;\n /** Pre-filled buyer email */\n buyerEmail?: string;\n /** Pre-filled billing details */\n billingDetail?: BillingDetail;\n /** Redirect URL after successful payment */\n successUrl?: string;\n /** Session expiration in seconds (default: 45 minutes) */\n expiresInSeconds?: number;\n /** Dark mode override (true=dark, false=light, omit=use store default) */\n darkMode?: boolean;\n /** Custom metadata */\n metadata?: Record<string, string>;\n}\n\n/** Result of creating a checkout session. */\nexport interface CheckoutSessionResult {\n /** Session ID */\n sessionId: string;\n /** URL to redirect the customer to */\n checkoutUrl: string;\n /** Session expiration time (ISO 8601 UTC) */\n expiresAt: string;\n}\n\n// ---------------------------------------------------------------------------\n// Buyer self-service\n// ---------------------------------------------------------------------------\n\n/** Parameters for canceling a one-time order (buyer-side). */\nexport interface CancelOnetimeOrderParams {\n /** Order ID */\n orderId: string;\n}\n\n/** Result of canceling a one-time order. */\nexport interface CancelOnetimeOrderResult {\n /** Order ID */\n orderId: string;\n /** Resulting status (`\"canceled\"`) */\n status: string;\n}\n\n/** Parameters for reactivating a subscription (buyer-side). */\nexport interface ReactivateSubscriptionParams {\n /** Subscription order ID */\n orderId: string;\n}\n\n/** Result of reactivating a subscription. */\nexport interface ReactivateSubscriptionResult {\n /** Order ID */\n orderId: string;\n /** Resulting status (`\"active\"`) */\n status: string;\n}\n\n/** Requested refund amount. */\nexport interface RequestedAmount {\n /** Refund amount in display format (e.g., `\"29.00\"`) */\n amount: string;\n /** Currency code (ISO 4217) */\n currency: string;\n}\n\n/**\n * Per-version data for a refund ticket. Each ticket can be submitted/resubmitted\n * multiple times; this is the shape of a single submission.\n */\nexport interface RefundTicketVersionData {\n /** Refund reason supplied by the buyer */\n reason: string;\n /** Requested refund amount; `null` if the version has no amount recorded */\n requestedAmount: RequestedAmount | null;\n}\n\n/** Parameters for creating a refund ticket (buyer-side). */\nexport interface CreateRefundTicketParams {\n /** Payment ID to refund */\n paymentId: string;\n /** Reason for the refund request */\n reason: string;\n /** Requested refund amount */\n requestedAmount: RequestedAmount;\n /** Custom metadata */\n metadata?: Record<string, unknown>;\n}\n\n/** Parameters for resubmitting a rejected refund ticket (buyer-side). */\nexport interface ResubmitRefundTicketParams {\n /** Existing ticket ID */\n ticketId: string;\n /** Payment ID */\n paymentId: string;\n /** Updated reason */\n reason: string;\n /** Updated requested amount */\n requestedAmount: RequestedAmount;\n}\n\n/** Refund ticket entity returned from create/resubmit operations. */\nexport interface RefundTicket {\n /** Ticket ID */\n id: string;\n /** Ticket type (e.g., `\"refund\"`) */\n type: string;\n /** Ticket status (e.g., `\"pending\"`, `\"approved\"`, `\"rejected\"`) */\n status: string;\n /** Associated payment ID */\n subjectId: string;\n /** Submitter identifier (email or merchant ID) */\n submitterId: string;\n /** Submitter type (e.g., `\"customer\"`, `\"merchant\"`) */\n submitterType: string;\n /** Current version ID */\n currentVersionId: string | null;\n /** Reviewer ID (null if not yet reviewed) */\n reviewerId: string | null;\n /** Review timestamp (ISO 8601, null if not yet reviewed) */\n reviewedAt: string | null;\n /** Reviewer's note */\n reviewNote: string | null;\n /** Rejection reason (null if approved or pending) */\n rejectReason: string | null;\n /** Execution timestamp (ISO 8601, null if not yet executed) */\n executedAt: string | null;\n /** Custom metadata */\n metadata: Record<string, unknown>;\n /** Current version number */\n versionNumber: number | null;\n /** Current (latest) version data */\n versionData: RefundTicketVersionData | null;\n /** Creation timestamp (ISO 8601) */\n createdAt: string;\n /** Last update timestamp (ISO 8601) */\n updatedAt: string;\n}\n\n// ---------------------------------------------------------------------------\n// Checkout — convenience wrappers\n// ---------------------------------------------------------------------------\n\n/**\n * Parameters for anonymous checkout.\n *\n * The buyer reaches the checkout page without a session token. Merchants may still\n * pre-fill `buyerEmail` and `billingDetail`; omitting them leaves the form blank.\n *\n * Accepts every field of {@link CreateCheckoutSessionParams} — this wrapper simply\n * forwards the params unchanged to `/v1/actions/checkout/create-session`.\n *\n * @example\n * const result = await client.checkout.anonymous.create({\n * productId: \"PROD_xxx\",\n * currency: \"USD\",\n * });\n * // Redirect to result.checkoutUrl\n */\nexport type AnonymousCheckoutParams = CreateCheckoutSessionParams;\n\n/**\n * Parameters for authenticated checkout.\n *\n * Merges the checkout-session fields ({@link CreateCheckoutSessionParams}) with the\n * extra `buyerIdentity` required by `issue-session-token`. The wrapper splits the\n * input: `buyerIdentity` goes to the token call; everything else (including\n * `buyerEmail`) goes to the create-session call. The two fields are independent.\n *\n * @example\n * const result = await client.checkout.authenticated.create({\n * productId: \"PROD_xxx\",\n * currency: \"USD\",\n * buyerIdentity: \"user-123\", // merchant-side buyer id (goes into JWT)\n * buyerEmail: \"customer@example.com\", // pre-filled on the checkout page\n * });\n * // Redirect to result.checkoutUrl (includes #token=...)\n */\nexport interface AuthenticatedCheckoutParams extends CreateCheckoutSessionParams {\n /**\n * Buyer identity — sent to `issue-session-token` and encoded into the JWT\n * payload for merchant-side buyer identification. Accepts an email or any\n * merchant-provided identifier string. Use `buyerEmail` to pre-fill the\n * checkout page's email input.\n */\n buyerIdentity: string;\n}\n\n/**\n * Result of an authenticated checkout creation.\n *\n * Extends the base session result with the issued token details.\n */\nexport interface AuthenticatedCheckoutResult {\n /** Session ID */\n sessionId: string;\n /** Checkout URL with session token appended as URL fragment (`#token=...`) */\n checkoutUrl: string;\n /** Session expiration time (ISO 8601 UTC) */\n expiresAt: string;\n /** Issued JWT token */\n token: string;\n /** Token expiration time (ISO 8601 UTC) */\n tokenExpiresAt: string;\n}\n\n// ---------------------------------------------------------------------------\n// GraphQL\n// ---------------------------------------------------------------------------\n\n/** Parameters for a GraphQL query. */\nexport interface GraphQLParams {\n /** GraphQL query string */\n query: string;\n /** Query variables */\n variables?: Record<string, unknown>;\n}\n\n/** GraphQL response envelope. */\nexport interface GraphQLResponse<T = Record<string, unknown>> {\n data: T | null;\n errors?: Array<{\n message: string;\n locations?: Array<{ line: number; column: number }>;\n path?: string[];\n }>;\n}\n\n// ---------------------------------------------------------------------------\n// Webhook\n// ---------------------------------------------------------------------------\n\n/**\n * Webhook event types.\n * @see docs/api-reference/webhooks.mdx\n */\nexport enum WebhookEventType {\n /** One-time order first payment succeeded */\n OrderCompleted = \"order.completed\",\n /** Subscription first payment succeeded (newly activated) */\n SubscriptionActivated = \"subscription.activated\",\n /** Subscription renewal payment succeeded */\n SubscriptionPaymentSucceeded = \"subscription.payment_succeeded\",\n /** Buyer initiated cancellation (expires at end of current period) */\n SubscriptionCanceling = \"subscription.canceling\",\n /** Buyer withdrew cancellation (subscription restored) */\n SubscriptionUncanceled = \"subscription.uncanceled\",\n /** Subscription product changed (upgrade/downgrade) */\n SubscriptionUpdated = \"subscription.updated\",\n /** Subscription fully terminated */\n SubscriptionCanceled = \"subscription.canceled\",\n /** Renewal payment failed (past due) */\n SubscriptionPastDue = \"subscription.past_due\",\n /** Refund succeeded */\n RefundSucceeded = \"refund.succeeded\",\n /** Refund failed */\n RefundFailed = \"refund.failed\",\n}\n\n/**\n * Common data fields in a webhook event payload.\n * @see docs/api-reference/webhooks.mdx\n */\nexport interface WebhookEventData {\n // Order\n orderId: string;\n /** Order status (e.g., \"completed\", \"active\", \"canceling\") */\n orderStatus?: string;\n buyerEmail: string;\n /** Merchant-provided buyer identity from checkout session */\n merchantProvidedBuyerIdentity?: string;\n currency: string;\n /** Billing/shipping address (structured object) */\n billingDetail?: Record<string, unknown>;\n /** Order-level metadata from checkout session (flat key-value pairs) */\n orderMetadata?: Record<string, string>;\n\n // Amount\n /** Amount as display string (e.g., \"9.99\" for USD, \"1000\" for JPY) */\n amount: string;\n /** Tax amount as display string (e.g., \"0.91\" for USD) */\n taxAmount: string;\n /** Tax rate as decimal (e.g., 0.1 for 10%) */\n taxRate?: number;\n /** Tax name (e.g., \"Consumption Tax\") */\n taxName?: string;\n /** Subtotal as display string (before tax) */\n subtotal?: string;\n /** Total as display string (after tax) */\n total?: string;\n\n // Product\n productName: string;\n /** Product description */\n productDescription?: string;\n /** Product-level metadata set when creating/updating the product */\n productMetadata?: Record<string, string>;\n\n // Payment (present for payment events: order.completed, subscription.payment_succeeded)\n /** Payment ID */\n paymentId?: string;\n /** Payment status (e.g., \"succeeded\", \"failed\") */\n paymentStatus?: string;\n /** Payment method type (e.g., \"card\") */\n paymentMethod?: string;\n /** Last 4 digits of payment instrument */\n paymentLast4?: string;\n /** Payment failure reason (present when payment failed) */\n paymentFailureReason?: string;\n /** Payment date (ISO 8601 date, e.g., \"2026-04-18\") */\n paymentDate?: string;\n\n // Subscription (present for subscription events)\n /** Billing period: \"weekly\", \"monthly\", \"quarterly\", \"yearly\" */\n billingPeriod?: string;\n /** Current billing period start date (ISO 8601, e.g., \"2026-04-01\") */\n currentPeriodStart?: string;\n /** Current billing period end date (ISO 8601, e.g., \"2026-05-01\") */\n currentPeriodEnd?: string;\n /** Subscription cancellation timestamp (ISO 8601, present when canceled) */\n canceledAt?: string;\n\n // Refund (present for refund events: refund.succeeded, refund.failed)\n /** Refund status (e.g., \"succeeded\", \"failed\") */\n refundStatus?: string;\n /** Refund reason */\n refundReason?: string;\n /** Refund creation timestamp (ISO 8601) */\n refundCreatedAt?: string;\n}\n\n/**\n * Webhook event payload.\n *\n * @see docs/api-reference/webhooks.mdx\n *\n * @example\n * {\n * id: \"550e8400-...\",\n * timestamp: \"2026-03-10T08:30:00.000Z\",\n * eventType: \"order.completed\",\n * eventId: \"PAY_5xK9mRtYvWnPqLsJ3hBfDe\",\n * storeId: \"STO_2aUyqjCzEIiEcYMKj7TZtw\",\n * mode: \"prod\",\n * data: { orderId: \"...\", buyerEmail: \"...\", currency: \"USD\", amount: \"29.00\", taxAmount: \"2.90\", productName: \"Pro Plan\", orderMetadata: { planId: \"pro\" } }\n * }\n */\nexport interface WebhookEvent<T = WebhookEventData> {\n /** Delivery record unique ID (UUID), usable for idempotent deduplication */\n id: string;\n /** Event timestamp (ISO 8601 UTC) */\n timestamp: string;\n /** Event type */\n eventType: `${WebhookEventType}` | (string & {});\n /** Business event ID (e.g. payment ID, order ID) */\n eventId: string;\n /** Store ID the event belongs to */\n storeId: string;\n /** Environment identifier */\n mode: `${Environment}`;\n /** Event data */\n data: T;\n}\n\n/**\n * Webhook public key configuration.\n *\n * - `string` — single key used for both test and prod environments\n * - `{ test?, prod? }` — per-environment keys\n */\nexport type WebhookPublicKeys = string | { test?: string; prod?: string };\n\n/** Options for {@link verifyWebhook}. */\nexport interface VerifyWebhookOptions {\n /**\n * Specify which environment's public key to use for verification.\n * When omitted, both keys are tried automatically (prod first).\n * Ignored when `publicKey` is provided.\n */\n environment?: `${Environment}`;\n /**\n * Timestamp tolerance window in milliseconds for replay protection.\n * Set to 0 to skip timestamp checking.\n * @default 300000 (5 minutes)\n */\n toleranceMs?: number;\n /**\n * Per-call public key override (highest priority).\n * When provided, skips all other key resolution (config, env vars, built-in).\n */\n publicKey?: string;\n /**\n * Config-level public key(s) for the resolution chain.\n * When using `client.webhooks.verify()`, this is set automatically from `WaffoPancakeConfig.webhookPublicKey`.\n * When using the standalone `verifyWebhook()`, you can pass this directly for config-level key injection.\n *\n * Resolution order per environment:\n * 1. `publicKey` (per-call override)\n * 2. `publicKeys[env]` or `publicKeys` (config)\n * 3. `WAFFO_WEBHOOK_{TEST|PROD}_PUBLIC_KEY` (env var)\n * 4. `WAFFO_WEBHOOK_PUBLIC_KEY` (env var)\n * 5. Built-in hardcoded key\n */\n publicKeys?: WebhookPublicKeys;\n}\n"],"mappings":";;;;;;;;;;;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T,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,cAAW;AAEX,EAAAA,YAAA,WAAQ;AAER,EAAAA,YAAA,SAAM;AAZI,SAAAA;AAAA,GAAA;AAuvBL,IAAK,mBAAL,kBAAKC,sBAAL;AAEL,EAAAA,kBAAA,oBAAiB;AAEjB,EAAAA,kBAAA,2BAAwB;AAExB,EAAAA,kBAAA,kCAA+B;AAE/B,EAAAA,kBAAA,2BAAwB;AAExB,EAAAA,kBAAA,4BAAyB;AAEzB,EAAAA,kBAAA,yBAAsB;AAEtB,EAAAA,kBAAA,0BAAuB;AAEvB,EAAAA,kBAAA,yBAAsB;AAEtB,EAAAA,kBAAA,qBAAkB;AAElB,EAAAA,kBAAA,kBAAe;AApBL,SAAAA;AAAA,GAAA;","names":["import_node_crypto","DEFAULT_BASE_URL","import_node_crypto","Environment","TaxCategory","BillingPeriod","ProductVersionStatus","EntityStatus","StoreRole","OnetimeOrderStatus","SubscriptionOrderStatus","PaymentStatus","RefundTicketStatus","RefundStatus","MediaType","ErrorLayer","WebhookEventType"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/buyer-http-client.ts","../src/http-client.ts","../src/signing.ts","../src/validation.ts","../src/resources/auth.ts","../src/resources/buyer.ts","../src/resources/checkout-anonymous.ts","../src/resources/checkout-authenticated.ts","../src/resources/checkout.ts","../src/resources/graphql.ts","../src/resources/onetime-products.ts","../src/resources/orders.ts","../src/resources/store-merchants.ts","../src/resources/stores.ts","../src/resources/subscription-product-groups.ts","../src/resources/subscription-products.ts","../src/webhooks.ts","../src/resources/webhooks.ts","../src/client.ts","../src/types.ts"],"sourcesContent":["// Client\nexport { WaffoPancake } from \"./client.js\";\n\n// Errors\nexport { WaffoPancakeError } from \"./errors.js\";\n\n// Webhooks\nexport { verifyWebhook } from \"./webhooks.js\";\n\n// Enums (runtime values)\nexport {\n BillingPeriod,\n EntityStatus,\n Environment,\n ErrorLayer,\n MediaType,\n OnetimeOrderStatus,\n PaymentStatus,\n ProductVersionStatus,\n RefundStatus,\n RefundTicketStatus,\n StoreRole,\n SubscriptionOrderStatus,\n TaxCategory,\n WebhookEventType,\n} from \"./types.js\";\n\n// Types (interfaces & type aliases)\nexport type {\n // Config\n WaffoPancakeConfig,\n\n // Response envelope\n ApiError,\n ApiErrorResponse,\n ApiResponse,\n ApiSuccessResponse,\n\n // Auth\n IssueSessionTokenParams,\n SessionToken,\n\n // Store\n CheckoutSettings,\n CheckoutThemeSettings,\n CreateStoreParams,\n DeleteStoreParams,\n NotificationSettings,\n Store,\n UpdateStoreParams,\n WebhookSettings,\n\n // Store Merchant\n AddMerchantParams,\n AddMerchantResult,\n RemoveMerchantParams,\n RemoveMerchantResult,\n UpdateRoleParams,\n UpdateRoleResult,\n\n // Product shared\n MediaItem,\n PriceInfo,\n Prices,\n\n // Onetime Product\n CreateOnetimeProductParams,\n OnetimeProductDetail,\n PublishOnetimeProductParams,\n UpdateOnetimeProductParams,\n UpdateOnetimeStatusParams,\n\n // Subscription Product\n CreateSubscriptionProductParams,\n PublishSubscriptionProductParams,\n SubscriptionProductDetail,\n UpdateSubscriptionProductParams,\n UpdateSubscriptionStatusParams,\n\n // Subscription Product Group\n CreateSubscriptionProductGroupParams,\n DeleteSubscriptionProductGroupParams,\n GroupRules,\n PublishSubscriptionProductGroupParams,\n SubscriptionProductGroup,\n UpdateSubscriptionProductGroupParams,\n\n // Buyer self-service\n CancelOnetimeOrderParams,\n CancelOnetimeOrderResult,\n CreateRefundTicketParams,\n ReactivateSubscriptionParams,\n ReactivateSubscriptionResult,\n RefundTicket,\n RefundTicketVersionData,\n RequestedAmount,\n ResubmitRefundTicketParams,\n\n // Checkout convenience\n AnonymousCheckoutParams,\n AuthenticatedCheckoutParams,\n AuthenticatedCheckoutResult,\n\n // Order\n BillingDetail,\n CancelSubscriptionParams,\n CancelSubscriptionResult,\n CheckoutSessionResult,\n CreateCheckoutSessionParams,\n\n // GraphQL\n GraphQLParams,\n GraphQLResponse,\n\n // Webhook\n VerifyWebhookOptions,\n WebhookEvent,\n WebhookEventData,\n WebhookPublicKeys,\n} from \"./types.js\";\n","import type { ApiError } from \"./types.js\";\n\n/**\n * Error thrown when the API returns a non-success response.\n *\n * @example\n * try {\n * await client.stores.create({ name: \"My Store\" });\n * } catch (err) {\n * if (err instanceof WaffoPancakeError) {\n * console.log(err.status); // 400\n * console.log(err.errors[0]); // { message: \"...\", layer: \"store\" }\n * }\n * }\n */\nexport class WaffoPancakeError extends Error {\n readonly status: number;\n readonly errors: ApiError[];\n\n constructor(status: number, errors: ApiError[]) {\n const rootCause = errors[0]?.message ?? \"Unknown error\";\n super(rootCause);\n this.name = \"WaffoPancakeError\";\n this.status = status;\n this.errors = errors;\n }\n}\n","import { WaffoPancakeError } from \"./errors.js\";\n\nimport type { ApiResponse, WaffoPancakeConfig } from \"./types.js\";\n\nconst DEFAULT_BASE_URL = \"https://api.waffo.ai\";\n\n/**\n * Internal HTTP client for buyer-side requests using Bearer token authentication.\n *\n * Unlike {@link HttpClient} which signs requests with RSA-SHA256 (API Key auth),\n * this client attaches a session token as `Authorization: Bearer <token>`.\n *\n * Not exported publicly — used internally by {@link BuyerSession}.\n */\nexport class BuyerHttpClient {\n private readonly token: string;\n private readonly baseUrl: string;\n private readonly _fetch: typeof fetch;\n\n constructor(token: string, config: Pick<WaffoPancakeConfig, \"baseUrl\" | \"fetch\">) {\n this.token = token;\n this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this._fetch = config.fetch ?? globalThis.fetch.bind(globalThis);\n }\n\n /**\n * Send a Bearer-authenticated POST request and return the parsed `data` field.\n *\n * @param path - API path\n * @param body - Request body object\n * @returns Parsed `data` field from the response\n * @throws {WaffoPancakeError} When the API returns errors\n */\n async post<T>(path: string, body: object): Promise<T> {\n const response = await this._fetch(`${this.baseUrl}${path}`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.token}`,\n },\n body: JSON.stringify(body),\n });\n\n const result = (await response.json()) as ApiResponse<T>;\n\n if (\"errors\" in result && result.errors) {\n throw new WaffoPancakeError(response.status, result.errors);\n }\n\n return result.data as T;\n }\n}\n","import { createHash } from \"node:crypto\";\n\nimport { WaffoPancakeError } from \"./errors.js\";\nimport { normalizePrivateKey, signRequest } from \"./signing.js\";\n\nimport type { ApiResponse, PostOptions, WaffoPancakeConfig } from \"./types.js\";\n\nconst DEFAULT_BASE_URL = \"https://api.waffo.ai\";\n\n/**\n * Internal HTTP client that auto-signs requests and attaches idempotency keys.\n *\n * The `X-Merchant-Id` header is sent in `MER_{base62}` format as provided by the user.\n * The gateway decodes it to a raw UUID before forwarding to downstream services.\n *\n * Not exported publicly — used by resource classes via {@link WaffoPancake}.\n */\nexport class HttpClient {\n private readonly merchantId: string;\n private readonly privateKey: string;\n private readonly baseUrl: string;\n private readonly _fetch: typeof fetch;\n\n constructor(config: WaffoPancakeConfig) {\n this.merchantId = config.merchantId;\n this.privateKey = normalizePrivateKey(config.privateKey);\n this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this._fetch = config.fetch ?? globalThis.fetch.bind(globalThis);\n }\n\n /**\n * Send a signed POST request and return the parsed `data` field.\n *\n * Behavior:\n * - Generates a deterministic `X-Idempotency-Key` from `merchantId + path + body` (same request produces same key)\n * - When `idempotencyWindow` is set, a floored timestamp is mixed into the key so identical params produce\n * a new key after the window elapses (useful for checkout where repeated creation is intentional)\n * - Auto-builds RSA-SHA256 signature (`X-Merchant-Id` / `X-Timestamp` / `X-Signature`)\n * - Unwraps the response envelope: returns `data` on success, throws `WaffoPancakeError` on failure\n *\n * @param path - API path (e.g. `/v1/actions/store/create-store`)\n * @param body - Request body object\n * @param options - Optional settings\n * @param options.idempotencyWindow - Time window in seconds for idempotency key rotation (e.g. 60 = per-minute dedup)\n * @returns Parsed `data` field from the response\n * @throws {WaffoPancakeError} When the API returns errors\n */\n async post<T>(path: string, body: object, options?: PostOptions): Promise<T> {\n const bodyStr = JSON.stringify(body);\n const now = Date.now();\n const timestampSec = Math.floor(now / 1000);\n const timestamp = timestampSec.toString();\n const signature = signRequest(\"POST\", path, timestamp, bodyStr, this.privateKey);\n\n const idempotencyBase = `${this.merchantId}:${path}:${bodyStr}`;\n const idempotencyInput = options?.idempotencyWindow\n ? `${idempotencyBase}:${Math.floor(timestampSec / options.idempotencyWindow)}`\n : idempotencyBase;\n\n const response = await this._fetch(`${this.baseUrl}${path}`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-Merchant-Id\": this.merchantId,\n \"X-Timestamp\": timestamp,\n \"X-Signature\": signature,\n \"X-Idempotency-Key\": createHash(\"sha256\").update(idempotencyInput).digest(\"hex\"),\n },\n body: bodyStr,\n });\n\n const result = (await response.json()) as ApiResponse<T>;\n\n if (\"errors\" in result && result.errors) {\n throw new WaffoPancakeError(response.status, result.errors);\n }\n\n return result.data as T;\n }\n}\n","import { createHash, createPrivateKey, createPublicKey, createSign } from \"node:crypto\";\n\nconst PKCS8_HEADER = \"-----BEGIN PRIVATE KEY-----\";\nconst PKCS8_FOOTER = \"-----END PRIVATE KEY-----\";\nconst PKCS1_HEADER = \"-----BEGIN RSA PRIVATE KEY-----\";\nconst PKCS1_FOOTER = \"-----END RSA PRIVATE KEY-----\";\n\nconst SPKI_HEADER = \"-----BEGIN PUBLIC KEY-----\";\nconst SPKI_FOOTER = \"-----END PUBLIC KEY-----\";\nconst PKCS1_PUB_HEADER = \"-----BEGIN RSA PUBLIC KEY-----\";\nconst PKCS1_PUB_FOOTER = \"-----END RSA PUBLIC KEY-----\";\n\n/**\n * Normalize a PEM private key string into a valid PEM format.\n *\n * Handles common issues:\n * - Literal `\\n` from environment variables (e.g. `PRIVATE_KEY=\"-----BEGIN...\\\\n...\"`)\n * - Windows-style `\\r\\n` line endings\n * - Leading/trailing whitespace and blank lines\n * - Missing PEM header/footer (raw base64 input, assumed PKCS#8)\n * - Base64 content on a single line (re-wrapped to 64-char lines)\n * - PKCS#1 (`BEGIN RSA PRIVATE KEY`) accepted as-is\n *\n * @param raw - Private key string in any of the above formats\n * @returns A well-formed PEM string\n * @throws {Error} If the input is empty or contains no base64 content\n *\n * @example\n * // Env var with literal \\n\n * normalizePrivateKey(\"-----BEGIN PRIVATE KEY-----\\\\nMIIE...\\\\n-----END PRIVATE KEY-----\")\n *\n * @example\n * // Raw base64 without PEM wrapper\n * normalizePrivateKey(\"MIIEvQIBADANBgkqhki...\")\n */\nexport function normalizePrivateKey(raw: string): string {\n if (!raw || !raw.trim()) {\n throw new Error(\"Private key is empty. Provide an RSA private key in PEM format.\");\n }\n\n // 1. Replace literal \\n / \\r\\n with real newlines\n let pem = raw.replace(/\\\\n/g, \"\\n\").replace(/\\r\\n/g, \"\\n\");\n\n // 2. Trim leading/trailing whitespace\n pem = pem.trim();\n\n // 3. Detect whether PEM headers are present\n const hasPkcs8Header = pem.includes(PKCS8_HEADER);\n const hasPkcs1Header = pem.includes(PKCS1_HEADER);\n const hasHeader = hasPkcs8Header || hasPkcs1Header;\n\n if (hasHeader) {\n // Strip headers/footers, extract pure base64\n const base64 = pem\n .replace(/-----BEGIN (?:RSA )?PRIVATE KEY-----/g, \"\")\n .replace(/-----END (?:RSA )?PRIVATE KEY-----/g, \"\")\n .replace(/\\s+/g, \"\");\n\n if (!base64) {\n throw new Error(\"Private key contains PEM headers but no key data. Check the key content.\");\n }\n\n // Re-wrap to 64-char lines with the original header type\n const header = hasPkcs1Header ? PKCS1_HEADER : PKCS8_HEADER;\n const footer = hasPkcs1Header ? PKCS1_FOOTER : PKCS8_FOOTER;\n const wrapped = base64.match(/.{1,64}/g)!.join(\"\\n\");\n pem = `${header}\\n${wrapped}\\n${footer}`;\n } else {\n // No PEM header — treat as raw base64, wrap with PKCS#8 headers\n const base64 = pem.replace(/\\s+/g, \"\");\n\n if (!/^[A-Za-z0-9+/]+=*$/.test(base64)) {\n throw new Error(\"Private key is not valid PEM or base64. Expected an RSA private key in PEM format or raw base64.\");\n }\n\n const wrapped = base64.match(/.{1,64}/g)!.join(\"\\n\");\n pem = `${PKCS8_HEADER}\\n${wrapped}\\n${PKCS8_FOOTER}`;\n }\n\n // 4. Validate the key is actually parseable by Node.js crypto\n try {\n createPrivateKey(pem);\n } catch {\n throw new Error(\"Private key could not be parsed. Ensure it is a valid RSA private key in PKCS#8 or PKCS#1 (PEM) format.\");\n }\n\n return pem;\n}\n\n/**\n * Normalize a PEM public key string into a valid PEM format.\n *\n * Handles common issues:\n * - Literal `\\n` from environment variables\n * - Windows-style `\\r\\n` line endings\n * - Leading/trailing whitespace and blank lines\n * - Missing PEM header/footer (raw base64 input, assumed SPKI)\n * - Base64 content on a single line (re-wrapped to 64-char lines)\n * - PKCS#1 (`BEGIN RSA PUBLIC KEY`) accepted as-is\n *\n * @param raw - Public key string in any of the above formats\n * @returns A well-formed PEM string\n * @throws {Error} If the input is empty or contains no base64 content\n *\n * @example\n * // Env var with literal \\n\n * normalizePublicKey(\"-----BEGIN PUBLIC KEY-----\\\\nMIIB...\\\\n-----END PUBLIC KEY-----\")\n *\n * @example\n * // Raw base64 without PEM wrapper\n * normalizePublicKey(\"MIIBIjANBgkqhki...\")\n */\nexport function normalizePublicKey(raw: string): string {\n if (!raw || !raw.trim()) {\n throw new Error(\"Public key is empty. Provide an RSA public key in PEM format.\");\n }\n\n // 1. Replace literal \\n / \\r\\n with real newlines\n let pem = raw.replace(/\\\\n/g, \"\\n\").replace(/\\r\\n/g, \"\\n\");\n\n // 2. Trim leading/trailing whitespace\n pem = pem.trim();\n\n // 3. Detect whether PEM headers are present\n const hasSpkiHeader = pem.includes(SPKI_HEADER);\n const hasPkcs1PubHeader = pem.includes(PKCS1_PUB_HEADER);\n const hasHeader = hasSpkiHeader || hasPkcs1PubHeader;\n\n if (hasHeader) {\n // Strip headers/footers, extract pure base64\n const base64 = pem\n .replace(/-----BEGIN (?:RSA )?PUBLIC KEY-----/g, \"\")\n .replace(/-----END (?:RSA )?PUBLIC KEY-----/g, \"\")\n .replace(/\\s+/g, \"\");\n\n if (!base64) {\n throw new Error(\"Public key contains PEM headers but no key data. Check the key content.\");\n }\n\n // Re-wrap to 64-char lines with the original header type\n const header = hasPkcs1PubHeader ? PKCS1_PUB_HEADER : SPKI_HEADER;\n const footer = hasPkcs1PubHeader ? PKCS1_PUB_FOOTER : SPKI_FOOTER;\n const wrapped = base64.match(/.{1,64}/g)!.join(\"\\n\");\n pem = `${header}\\n${wrapped}\\n${footer}`;\n } else {\n // No PEM header — treat as raw base64, wrap with SPKI headers\n const base64 = pem.replace(/\\s+/g, \"\");\n\n if (!/^[A-Za-z0-9+/]+=*$/.test(base64)) {\n throw new Error(\"Public key is not valid PEM or base64. Expected an RSA public key in PEM format or raw base64.\");\n }\n\n const wrapped = base64.match(/.{1,64}/g)!.join(\"\\n\");\n pem = `${SPKI_HEADER}\\n${wrapped}\\n${SPKI_FOOTER}`;\n }\n\n // 4. Validate the key is actually parseable by Node.js crypto\n try {\n createPublicKey(pem);\n } catch {\n throw new Error(\"Public key could not be parsed. Ensure it is a valid RSA public key in SPKI or PKCS#1 (PEM) format.\");\n }\n\n return pem;\n}\n\n/**\n * Build canonical request string and sign with RSA-SHA256.\n *\n * Canonical request format:\n * METHOD\\nPATH\\nTIMESTAMP\\nSHA256(BODY)\n *\n * @param method - HTTP method (e.g. \"POST\")\n * @param path - Request path (e.g. \"/v1/actions/store/create-store\")\n * @param timestamp - Unix epoch seconds string\n * @param body - Serialized JSON body\n * @param privateKey - RSA private key in PEM format\n * @returns Base64-encoded RSA-SHA256 signature\n */\nexport function signRequest(method: string, path: string, timestamp: string, body: string, privateKey: string): string {\n const bodyHash = createHash(\"sha256\").update(body).digest(\"base64\");\n const canonicalRequest = `${method}\\n${path}\\n${timestamp}\\n${bodyHash}`;\n\n const sign = createSign(\"sha256\");\n sign.update(canonicalRequest);\n return sign.sign(privateKey, \"base64\");\n}\n","/**\n * Client-side input validation.\n *\n * These checks catch obviously invalid inputs before making a network request.\n * They do NOT validate data existence (e.g., whether a store/product actually exists).\n *\n * All validation errors throw `WaffoPancakeError` with `status: 400` and `layer: \"sdk\"`,\n * so developers can catch them uniformly with API errors.\n *\n * Not exported publicly — used internally by resource classes.\n */\n\nimport { WaffoPancakeError } from \"./errors.js\";\n\nconst SHORT_ID_REGEX = /^[A-Z]{2,5}_[0-9A-Za-z]{22}$/;\nconst CURRENCY_CODE_REGEX = /^[A-Z]{3}$/;\nconst COUNTRY_CODE_REGEX = /^[A-Z]{2}$/;\nconst AMOUNT_STRING_REGEX = /^\\d+(\\.\\d+)?$/;\n\nconst SHORT_ID_LABELS: Record<string, string> = {\n STO: \"Store\",\n PROD: \"Product\",\n ORD: \"Order\",\n PAY: \"Payment\",\n REF: \"Refund\",\n TKT: \"Ticket\",\n MER: \"Merchant\",\n};\n\nfunction fail(message: string): never {\n throw new WaffoPancakeError(400, [{ message, layer: \"sdk\" }]);\n}\n\n/**\n * Validate that a required field is present and non-empty.\n */\nexport function validateRequired(field: string, value: unknown): void {\n if (value === undefined || value === null) {\n fail(`Missing required field: ${field}`);\n }\n if (typeof value === \"string\" && value.trim() === \"\") {\n fail(`${field} cannot be empty`);\n }\n}\n\n/**\n * Validate Short ID format (`{PREFIX}_{base62}`).\n */\nexport function validateShortId(field: string, value: string, prefix: string): void {\n validateRequired(field, value);\n const label = SHORT_ID_LABELS[prefix] ?? prefix;\n if (!SHORT_ID_REGEX.test(value)) {\n fail(`Invalid ${field}: expected ${label} Short ID format (${prefix}_xxx), got \"${value}\"`);\n }\n if (!value.startsWith(`${prefix}_`)) {\n fail(`Invalid ${field}: expected ${prefix}_ prefix (${label}), got \"${value.split(\"_\")[0]}_\"`);\n }\n}\n\n/**\n * Validate ISO 4217 currency code format (3 uppercase letters).\n */\nexport function validateCurrencyCode(field: string, value: string): void {\n validateRequired(field, value);\n if (!CURRENCY_CODE_REGEX.test(value)) {\n fail(`Invalid ${field}: expected 3-letter ISO 4217 currency code (e.g., \"USD\"), got \"${value}\"`);\n }\n}\n\n/**\n * Validate that amount is a valid numeric string in display format.\n */\nexport function validateAmountString(field: string, value: string): void {\n validateRequired(field, value);\n if (!AMOUNT_STRING_REGEX.test(value)) {\n fail(`Invalid ${field}: expected numeric string in display format (e.g., \"9.99\", \"1000\"), got \"${value}\"`);\n }\n}\n\n/**\n * Validate that a value is one of the allowed enum values.\n */\nexport function validateEnum(field: string, value: string, allowed: string[]): void {\n validateRequired(field, value);\n if (!allowed.includes(value)) {\n fail(`Invalid ${field}: expected one of [${allowed.join(\", \")}], got \"${value}\"`);\n }\n}\n\n/**\n * Validate that a value is a positive integer.\n */\nexport function validatePositiveInteger(field: string, value: number): void {\n if (!Number.isInteger(value) || value <= 0) {\n fail(`Invalid ${field}: expected positive integer, got ${value}`);\n }\n}\n\n/**\n * Validate ISO 3166-1 alpha-2 country code (2 uppercase letters).\n */\nexport function validateCountryCode(field: string, value: string): void {\n validateRequired(field, value);\n if (!COUNTRY_CODE_REGEX.test(value)) {\n fail(`Invalid ${field}: expected 2-letter ISO 3166-1 country code (e.g., \"US\"), got \"${value}\"`);\n }\n}\n\n/**\n * Validate Prices object — each currency key and price amount.\n */\nexport function validatePrices(field: string, prices: Record<string, { amount: string; taxCategory: string }>): void {\n validateRequired(field, prices);\n const entries = Object.entries(prices);\n if (entries.length === 0) {\n fail(`${field} must contain at least one currency`);\n }\n for (const [currency, info] of entries) {\n validateCurrencyCode(`${field}.${currency} (key)`, currency);\n validateAmountString(`${field}.${currency}.amount`, info.amount);\n validateRequired(`${field}.${currency}.taxCategory`, info.taxCategory);\n }\n}\n\n/**\n * Validate BillingDetail fields (when present).\n */\nexport function validateBillingDetail(detail: { country: string; isBusiness: boolean }): void {\n validateCountryCode(\"billingDetail.country\", detail.country);\n if (typeof detail.isBusiness !== \"boolean\") {\n fail(`Invalid billingDetail.isBusiness: expected boolean, got ${typeof detail.isBusiness}`);\n }\n}\n\n/**\n * Validate checkout session common fields.\n */\nexport function validateCheckoutCommon(params: {\n productId: string;\n currency: string;\n priceSnapshot?: { amount: string; taxCategory: string };\n billingDetail?: { country: string; isBusiness: boolean };\n expiresInSeconds?: number;\n}): void {\n validateShortId(\"productId\", params.productId, \"PROD\");\n validateCurrencyCode(\"currency\", params.currency);\n if (params.priceSnapshot) {\n validateAmountString(\"priceSnapshot.amount\", params.priceSnapshot.amount);\n validateRequired(\"priceSnapshot.taxCategory\", params.priceSnapshot.taxCategory);\n }\n if (params.billingDetail) {\n validateBillingDetail(params.billingDetail);\n }\n if (params.expiresInSeconds !== undefined) {\n validatePositiveInteger(\"expiresInSeconds\", params.expiresInSeconds);\n }\n}\n","import { WaffoPancakeError } from \"../errors.js\";\nimport { validateRequired, validateShortId } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type { IssueSessionTokenParams, SessionToken } from \"../types.js\";\n\n/** Authentication resource — issue session tokens for buyers. */\nexport class AuthResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Issue a session token for a buyer.\n *\n * @param params - Token issuance parameters\n * @returns Issued session token with expiration\n *\n * @example\n * // By store ID\n * const { token, expiresAt } = await client.auth.issueSessionToken({\n * storeId: \"STO_xxx\",\n * buyerIdentity: \"customer@example.com\",\n * });\n *\n * @example\n * // By product ID (store derived automatically)\n * const { token, expiresAt } = await client.auth.issueSessionToken({\n * productId: \"PROD_xxx\",\n * buyerIdentity: \"customer@example.com\",\n * });\n */\n async issueSessionToken(params: IssueSessionTokenParams): Promise<SessionToken> {\n if (!params.storeId && !params.productId) {\n throw new WaffoPancakeError(400, [{ message: \"Missing required field: provide storeId or productId\", layer: \"sdk\" }]);\n }\n if (params.storeId) {\n validateShortId(\"storeId\", params.storeId, \"STO\");\n }\n if (params.productId) {\n validateShortId(\"productId\", params.productId, \"PROD\");\n }\n validateRequired(\"buyerIdentity\", params.buyerIdentity);\n return this.http.post<SessionToken>(\"/v1/actions/auth/issue-session-token\", params);\n }\n}\n","import { validateAmountString, validateCurrencyCode, validateRequired, validateShortId } from \"../validation.js\";\n\nimport type { BuyerHttpClient } from \"../buyer-http-client.js\";\nimport type {\n CancelOnetimeOrderParams,\n CancelOnetimeOrderResult,\n CancelSubscriptionParams,\n CancelSubscriptionResult,\n CreateRefundTicketParams,\n GraphQLParams,\n GraphQLResponse,\n ReactivateSubscriptionParams,\n ReactivateSubscriptionResult,\n RefundTicket,\n ResubmitRefundTicketParams,\n} from \"../types.js\";\n\n/**\n * Buyer session — lets authenticated buyers manage their own orders and subscriptions.\n *\n * Created via `client.buyer(token)` using a session token issued by\n * `client.auth.issueSessionToken()`. All requests use Bearer token authentication.\n *\n * @example\n * const { token } = await client.auth.issueSessionToken({\n * storeId: \"STO_xxx\",\n * buyerIdentity: \"customer@example.com\",\n * });\n * const buyer = client.buyer(token);\n * await buyer.cancelSubscription({ orderId: \"ORD_xxx\" });\n */\nexport class BuyerSession {\n /** GraphQL query access scoped to the buyer's data. */\n readonly graphql: BuyerGraphQL;\n\n constructor(private readonly http: BuyerHttpClient) {\n this.graphql = new BuyerGraphQL(http);\n }\n\n /**\n * Cancel a subscription order.\n *\n * @param params - Order to cancel\n * @returns Order ID and resulting status\n *\n * @example\n * const { orderId, status } = await buyer.cancelSubscription({ orderId: \"ORD_xxx\" });\n * // status: \"canceled\" (was pending) or \"canceling\" (was active)\n */\n async cancelSubscription(params: CancelSubscriptionParams): Promise<CancelSubscriptionResult> {\n validateShortId(\"orderId\", params.orderId, \"ORD\");\n return this.http.post<CancelSubscriptionResult>(\"/v1/actions/subscription-order/cancel-order\", params);\n }\n\n /**\n * Cancel a one-time order (only while payment is still pending).\n *\n * @param params - Order to cancel\n * @returns Order ID and resulting status\n *\n * @example\n * const { orderId, status } = await buyer.cancelOnetimeOrder({ orderId: \"ORD_xxx\" });\n */\n async cancelOnetimeOrder(params: CancelOnetimeOrderParams): Promise<CancelOnetimeOrderResult> {\n validateShortId(\"orderId\", params.orderId, \"ORD\");\n return this.http.post<CancelOnetimeOrderResult>(\"/v1/actions/onetime-order/cancel-order\", params);\n }\n\n /**\n * Reactivate a subscription that is in `canceling` status.\n *\n * @param params - Order to reactivate\n * @returns Order ID and resulting status\n *\n * @example\n * const { orderId, status } = await buyer.reactivateSubscription({ orderId: \"ORD_xxx\" });\n * // status: \"active\"\n */\n async reactivateSubscription(params: ReactivateSubscriptionParams): Promise<ReactivateSubscriptionResult> {\n validateShortId(\"orderId\", params.orderId, \"ORD\");\n return this.http.post<ReactivateSubscriptionResult>(\"/v1/actions/subscription-order/reactivate-order\", params);\n }\n\n /**\n * Submit a refund request for a payment.\n *\n * @param params - Refund ticket details\n * @returns Created refund ticket\n *\n * @example\n * const { ticket } = await buyer.createRefundTicket({\n * paymentId: \"PAY_xxx\",\n * reason: \"Product not as described\",\n * requestedAmount: { amount: \"29.00\", currency: \"USD\" },\n * });\n */\n async createRefundTicket(params: CreateRefundTicketParams): Promise<{ ticket: RefundTicket }> {\n validateShortId(\"paymentId\", params.paymentId, \"PAY\");\n validateRequired(\"reason\", params.reason);\n validateAmountString(\"requestedAmount.amount\", params.requestedAmount.amount);\n validateCurrencyCode(\"requestedAmount.currency\", params.requestedAmount.currency);\n return this.http.post<{ ticket: RefundTicket }>(\"/v1/actions/refund-ticket/create-ticket\", params);\n }\n\n /**\n * Resubmit a previously rejected refund ticket with updated details.\n *\n * @param params - Updated ticket details\n * @returns Updated refund ticket\n *\n * @example\n * const { ticket } = await buyer.resubmitRefundTicket({\n * ticketId: \"TKT_xxx\",\n * paymentId: \"PAY_xxx\",\n * reason: \"Updated reason with more detail\",\n * requestedAmount: { amount: \"29.00\", currency: \"USD\" },\n * });\n */\n async resubmitRefundTicket(params: ResubmitRefundTicketParams): Promise<{ ticket: RefundTicket }> {\n validateShortId(\"ticketId\", params.ticketId, \"TKT\");\n validateShortId(\"paymentId\", params.paymentId, \"PAY\");\n validateRequired(\"reason\", params.reason);\n validateAmountString(\"requestedAmount.amount\", params.requestedAmount.amount);\n validateCurrencyCode(\"requestedAmount.currency\", params.requestedAmount.currency);\n return this.http.post<{ ticket: RefundTicket }>(\"/v1/actions/refund-ticket/resubmit-ticket\", params);\n }\n}\n\n/**\n * GraphQL access scoped to the buyer's session token.\n */\nclass BuyerGraphQL {\n constructor(private readonly http: BuyerHttpClient) {}\n\n /**\n * Execute a GraphQL query scoped to the buyer's data.\n *\n * @param params - GraphQL query and variables\n * @returns GraphQL response\n *\n * @example\n * const result = await buyer.graphql.query({\n * query: `query { orders { id status } }`,\n * });\n */\n async query<T = Record<string, unknown>>(params: GraphQLParams): Promise<GraphQLResponse<T>> {\n validateRequired(\"query\", params.query);\n return this.http.post<GraphQLResponse<T>>(\"/v1/graphql\", params);\n }\n}\n","import { validateCheckoutCommon } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type { AnonymousCheckoutParams, CheckoutSessionResult } from \"../types.js\";\n\n/**\n * Anonymous checkout — no buyer identity provided.\n *\n * The buyer reaches the checkout page without a session token. Merchants may still\n * pre-fill `buyerEmail` and `billingDetail` on the page by passing them here.\n * Internally creates a checkout session and returns the redirect URL.\n */\nexport class CheckoutAnonymousResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Create an anonymous checkout session.\n *\n * @param params - Checkout parameters (no buyer identity required)\n * @returns Session ID, checkout URL, and expiration\n *\n * @example\n * // Minimal — buyer fills everything on the page\n * const result = await client.checkout.anonymous.create({\n * productId: \"PROD_xxx\",\n * currency: \"USD\",\n * });\n *\n * @example\n * // Pre-fill email and billing without issuing a session token\n * const result = await client.checkout.anonymous.create({\n * productId: \"PROD_xxx\",\n * currency: \"USD\",\n * buyerEmail: \"customer@example.com\",\n * billingDetail: { country: \"US\", isBusiness: false, postcode: \"10001\" },\n * });\n */\n async create(params: AnonymousCheckoutParams): Promise<CheckoutSessionResult> {\n validateCheckoutCommon(params);\n return this.http.post<CheckoutSessionResult>(\"/v1/actions/checkout/create-session\", params, { idempotencyWindow: 60 });\n }\n}\n","import { validateCheckoutCommon, validateRequired } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type { AuthenticatedCheckoutParams, AuthenticatedCheckoutResult, CheckoutSessionResult, SessionToken } from \"../types.js\";\n\n/**\n * Authenticated checkout — merchant provides buyer identity.\n *\n * Issues a session token, creates a checkout session, and returns a\n * checkout URL with the token appended as a URL fragment (`#token=...`).\n * The checkout page reads the fragment to pre-fill buyer information.\n */\nexport class CheckoutAuthenticatedResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Create an authenticated checkout session.\n *\n * Behavior:\n * - Issues a session token via `issue-session-token` (receives `buyerIdentity` + `productId` only)\n * - Creates a checkout session via `create-session` (receives every other field unchanged)\n * - Appends the token to the checkout URL as a URL fragment (`#token=...`)\n *\n * `buyerIdentity` and `buyerEmail` are independent inputs: identity is for the JWT,\n * email is for pre-filling the checkout page. The SDK forwards each to its own endpoint.\n *\n * @param params - Checkout parameters including buyer identity\n * @returns Session details with token-appended checkout URL\n *\n * @example\n * const result = await client.checkout.authenticated.create({\n * productId: \"PROD_xxx\",\n * currency: \"USD\",\n * buyerIdentity: \"user-123\",\n * buyerEmail: \"customer@example.com\",\n * });\n * // Redirect to result.checkoutUrl (includes #token=...)\n */\n async create(params: AuthenticatedCheckoutParams): Promise<AuthenticatedCheckoutResult> {\n validateCheckoutCommon(params);\n validateRequired(\"buyerIdentity\", params.buyerIdentity);\n const { buyerIdentity, ...sessionParams } = params;\n\n const [tokenResult, sessionResult] = await Promise.all([\n this.http.post<SessionToken>(\n \"/v1/actions/auth/issue-session-token\",\n {\n productId: params.productId,\n buyerIdentity,\n },\n { idempotencyWindow: 60 },\n ),\n this.http.post<CheckoutSessionResult>(\"/v1/actions/checkout/create-session\", sessionParams, { idempotencyWindow: 60 }),\n ]);\n\n return {\n sessionId: sessionResult.sessionId,\n checkoutUrl: `${sessionResult.checkoutUrl}#token=${tokenResult.token}`,\n expiresAt: sessionResult.expiresAt,\n token: tokenResult.token,\n tokenExpiresAt: tokenResult.expiresAt,\n };\n }\n}\n","import { CheckoutAnonymousResource } from \"./checkout-anonymous.js\";\nimport { CheckoutAuthenticatedResource } from \"./checkout-authenticated.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type { CheckoutSessionResult, CreateCheckoutSessionParams } from \"../types.js\";\n\n/**\n * Checkout resource — create checkout sessions for payments.\n *\n * Provides two convenience sub-resources for the common checkout flows:\n * - `anonymous` — no buyer identity, empty form\n * - `authenticated` — merchant provides buyer identity, pre-filled form + token\n *\n * The low-level `createSession()` method is still available for full control.\n *\n * @example\n * // Anonymous checkout (no identity)\n * const result = await client.checkout.anonymous.create({\n * productId: \"PROD_xxx\",\n * currency: \"USD\",\n * });\n *\n * @example\n * // Authenticated checkout (with buyer identity)\n * const result = await client.checkout.authenticated.create({\n * productId: \"PROD_xxx\",\n * currency: \"USD\",\n * buyerIdentity: \"userIdInYourSystem\",\n * buyerEmail: \"customer@example.com\",\n * });\n * // result.checkoutUrl includes #token=...\n */\nexport class CheckoutResource {\n /** Anonymous checkout — no buyer identity, empty form. */\n readonly anonymous: CheckoutAnonymousResource;\n /** Authenticated checkout — merchant provides buyer identity. */\n readonly authenticated: CheckoutAuthenticatedResource;\n\n constructor(private readonly http: HttpClient) {\n this.anonymous = new CheckoutAnonymousResource(http);\n this.authenticated = new CheckoutAuthenticatedResource(http);\n }\n\n /**\n * Create a checkout session (low-level). Returns a URL to redirect the customer to.\n *\n * For most use cases, prefer `checkout.anonymous.create()` or\n * `checkout.authenticated.create()` which handle the full flow automatically.\n *\n * @param params - Checkout session parameters\n * @returns Session ID, checkout URL, and expiration\n *\n * @example\n * const session = await client.checkout.createSession({\n * productId: \"PROD_xxx\",\n * currency: \"USD\",\n * buyerEmail: \"customer@example.com\",\n * });\n * // Redirect to session.checkoutUrl\n */\n async createSession(params: CreateCheckoutSessionParams): Promise<CheckoutSessionResult> {\n return this.http.post<CheckoutSessionResult>(\"/v1/actions/checkout/create-session\", params, { idempotencyWindow: 60 });\n }\n}\n","import { validateRequired } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type { GraphQLParams, GraphQLResponse } from \"../types.js\";\n\n/** GraphQL query resource (Query only, no Mutations). */\nexport class GraphQLResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Execute a GraphQL query (Query only, no Mutations).\n *\n * @param params - GraphQL query and optional variables\n * @returns GraphQL response with data and optional errors\n *\n * @example\n * const result = await client.graphql.query<{ stores: Array<{ id: string; name: string }> }>({\n * query: `query { stores { id name status } }`,\n * });\n * console.log(result.data?.stores);\n *\n * @example\n * const result = await client.graphql.query({\n * query: `query ($id: ID!) { onetimeProduct(id: $id) { id name prices } }`,\n * variables: { id: \"PROD_xxx\" },\n * });\n */\n async query<T = Record<string, unknown>>(params: GraphQLParams): Promise<GraphQLResponse<T>> {\n validateRequired(\"query\", params.query);\n return this.http.post<GraphQLResponse<T>>(\"/v1/graphql\", params);\n }\n}\n","import { validateEnum, validatePrices, validateRequired, validateShortId } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type {\n CreateOnetimeProductParams,\n OnetimeProductDetail,\n PublishOnetimeProductParams,\n UpdateOnetimeProductParams,\n UpdateOnetimeStatusParams,\n} from \"../types.js\";\n\n/** One-time product management resource. */\nexport class OnetimeProductsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Create a one-time product with multi-currency pricing.\n *\n * @param params - Product creation parameters\n * @returns Created product detail\n *\n * @example\n * const { product } = await client.onetimeProducts.create({\n * storeId: \"STO_xxx\",\n * name: \"E-Book\",\n * prices: { USD: { amount: \"29.00\", taxCategory: \"digital_goods\" } },\n * });\n */\n async create(params: CreateOnetimeProductParams): Promise<{ product: OnetimeProductDetail }> {\n validateShortId(\"storeId\", params.storeId, \"STO\");\n validateRequired(\"name\", params.name);\n validatePrices(\"prices\", params.prices);\n return this.http.post<{ product: OnetimeProductDetail }>(\"/v1/actions/onetime-product/create-product\", params);\n }\n\n /**\n * Update a one-time product. Creates a new version; skips if unchanged.\n *\n * @param params - Product update parameters (only `id` is required)\n * @returns Updated product detail\n *\n * @example\n * // Update only the name\n * const { product } = await client.onetimeProducts.update({\n * id: \"PROD_xxx\",\n * name: \"E-Book v2\",\n * });\n *\n * @example\n * // Update prices while preserving other fields\n * const { product } = await client.onetimeProducts.update({\n * id: \"PROD_xxx\",\n * prices: { USD: { amount: \"39.00\", taxCategory: \"digital_goods\" } },\n * });\n */\n async update(params: UpdateOnetimeProductParams): Promise<{ product: OnetimeProductDetail }> {\n validateShortId(\"id\", params.id, \"PROD\");\n if (params.name !== undefined) validateRequired(\"name\", params.name);\n if (params.prices) validatePrices(\"prices\", params.prices);\n return this.http.post<{ product: OnetimeProductDetail }>(\"/v1/actions/onetime-product/update-product\", params);\n }\n\n /**\n * Publish a one-time product's test version to production.\n *\n * @param params - Product to publish\n * @returns Published product detail\n *\n * @example\n * const { product } = await client.onetimeProducts.publish({ id: \"PROD_xxx\" });\n */\n async publish(params: PublishOnetimeProductParams): Promise<{ product: OnetimeProductDetail }> {\n validateShortId(\"id\", params.id, \"PROD\");\n return this.http.post<{ product: OnetimeProductDetail }>(\"/v1/actions/onetime-product/publish-product\", params);\n }\n\n /**\n * Update a one-time product's status (active/inactive).\n *\n * @param params - Status update parameters\n * @returns Updated product detail\n *\n * @example\n * const { product } = await client.onetimeProducts.updateStatus({\n * id: \"PROD_xxx\",\n * status: ProductVersionStatus.Inactive,\n * });\n */\n async updateStatus(params: UpdateOnetimeStatusParams): Promise<{ product: OnetimeProductDetail }> {\n validateShortId(\"id\", params.id, \"PROD\");\n validateEnum(\"status\", params.status, [\"active\", \"inactive\"]);\n return this.http.post<{ product: OnetimeProductDetail }>(\"/v1/actions/onetime-product/update-status\", params);\n }\n}\n","import { validateShortId } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type { CancelSubscriptionParams, CancelSubscriptionResult } from \"../types.js\";\n\n/** Order management resource. */\nexport class OrdersResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Cancel a subscription order.\n *\n * - pending -> canceled (immediate)\n * - active/trialing -> canceling (PSP cancel, webhook updates later)\n *\n * @param params - Order to cancel\n * @returns Order ID and resulting status\n *\n * @example\n * const { orderId, status } = await client.orders.cancelSubscription({\n * orderId: \"ORD_xxx\",\n * });\n * // status: \"canceled\" or \"canceling\"\n */\n async cancelSubscription(params: CancelSubscriptionParams): Promise<CancelSubscriptionResult> {\n validateShortId(\"orderId\", params.orderId, \"ORD\");\n return this.http.post<CancelSubscriptionResult>(\"/v1/actions/subscription-order/cancel-order\", params);\n }\n}\n","import { validateEnum, validateRequired, validateShortId } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type {\n AddMerchantParams,\n AddMerchantResult,\n RemoveMerchantParams,\n RemoveMerchantResult,\n UpdateRoleParams,\n UpdateRoleResult,\n} from \"../types.js\";\n\n/** Store merchant management resource (coming soon — endpoints return 501). */\nexport class StoreMerchantsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Add a merchant to a store.\n *\n * @param params - Merchant addition parameters\n * @returns Added merchant details\n *\n * @example\n * const result = await client.storeMerchants.add({\n * storeId: \"STO_xxx\",\n * email: \"member@example.com\",\n * role: \"admin\",\n * });\n */\n async add(params: AddMerchantParams): Promise<AddMerchantResult> {\n validateShortId(\"storeId\", params.storeId, \"STO\");\n validateRequired(\"email\", params.email);\n validateEnum(\"role\", params.role, [\"admin\", \"member\"]);\n return this.http.post<AddMerchantResult>(\"/v1/actions/store-merchant/add-merchant\", params);\n }\n\n /**\n * Remove a merchant from a store.\n *\n * @param params - Merchant removal parameters\n * @returns Removal confirmation\n *\n * @example\n * const result = await client.storeMerchants.remove({\n * storeId: \"STO_xxx\",\n * merchantId: \"MER_xxx\",\n * });\n */\n async remove(params: RemoveMerchantParams): Promise<RemoveMerchantResult> {\n validateShortId(\"storeId\", params.storeId, \"STO\");\n validateShortId(\"merchantId\", params.merchantId, \"MER\");\n return this.http.post<RemoveMerchantResult>(\"/v1/actions/store-merchant/remove-merchant\", params);\n }\n\n /**\n * Update a merchant's role in a store.\n *\n * @param params - Role update parameters\n * @returns Updated role details\n *\n * @example\n * const result = await client.storeMerchants.updateRole({\n * storeId: \"STO_xxx\",\n * merchantId: \"MER_xxx\",\n * role: \"member\",\n * });\n */\n async updateRole(params: UpdateRoleParams): Promise<UpdateRoleResult> {\n validateShortId(\"storeId\", params.storeId, \"STO\");\n validateShortId(\"merchantId\", params.merchantId, \"MER\");\n validateEnum(\"role\", params.role, [\"admin\", \"member\"]);\n return this.http.post<UpdateRoleResult>(\"/v1/actions/store-merchant/update-role\", params);\n }\n}\n","import { validateRequired, validateShortId } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type { CreateStoreParams, DeleteStoreParams, Store, UpdateStoreParams } from \"../types.js\";\n\n/** Store management resource — create, update, and delete stores. */\nexport class StoresResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Create a new store. Slug is auto-generated from the name.\n *\n * @param params - Store creation parameters\n * @returns Created store entity\n *\n * @example\n * const { store } = await client.stores.create({ name: \"My Store\" });\n */\n async create(params: CreateStoreParams): Promise<{ store: Store }> {\n validateRequired(\"name\", params.name);\n return this.http.post<{ store: Store }>(\"/v1/actions/store/create-store\", params);\n }\n\n /**\n * Update an existing store's settings.\n *\n * Settings objects (`webhookSettings`, `notificationSettings`, `checkoutSettings`)\n * support partial updates: omitted sub-fields keep existing values, `null` clears\n * a field. Pass the entire settings object as `null` to clear all fields.\n *\n * @param params - Fields to update (only provided fields are changed)\n * @returns Updated store entity\n *\n * @example\n * // Update name\n * const { store } = await client.stores.update({\n * id: \"STO_xxx\",\n * name: \"Updated Name\",\n * });\n *\n * @example\n * // Clear test webhook URL while keeping other webhook settings\n * const { store } = await client.stores.update({\n * id: \"STO_xxx\",\n * webhookSettings: { testWebhookUrl: null },\n * });\n */\n async update(params: UpdateStoreParams): Promise<{ store: Store }> {\n validateShortId(\"id\", params.id, \"STO\");\n return this.http.post<{ store: Store }>(\"/v1/actions/store/update-store\", params);\n }\n\n /**\n * Soft-delete a store. Only the owner can delete.\n *\n * @param params - Store to delete\n * @returns Deleted store entity (with `deletedAt` set)\n *\n * @example\n * const { store } = await client.stores.delete({ id: \"STO_xxx\" });\n */\n async delete(params: DeleteStoreParams): Promise<{ store: Store }> {\n validateShortId(\"id\", params.id, \"STO\");\n return this.http.post<{ store: Store }>(\"/v1/actions/store/delete-store\", params);\n }\n}\n","import { validateRequired, validateShortId } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type {\n CreateSubscriptionProductGroupParams,\n DeleteSubscriptionProductGroupParams,\n PublishSubscriptionProductGroupParams,\n SubscriptionProductGroup,\n UpdateSubscriptionProductGroupParams,\n} from \"../types.js\";\n\n/** Subscription product group management resource (shared trial, plan switching). */\nexport class SubscriptionProductGroupsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Create a subscription product group for shared-trial or plan switching.\n *\n * @param params - Group creation parameters\n * @returns Created group entity\n *\n * @example\n * const { group } = await client.subscriptionProductGroups.create({\n * storeId: \"STO_xxx\",\n * name: \"Pro Plans\",\n * rules: { sharedTrial: true },\n * productIds: [\"PROD_aaa\", \"PROD_bbb\"],\n * });\n */\n async create(params: CreateSubscriptionProductGroupParams): Promise<{ group: SubscriptionProductGroup }> {\n validateShortId(\"storeId\", params.storeId, \"STO\");\n validateRequired(\"name\", params.name);\n return this.http.post<{ group: SubscriptionProductGroup }>(\"/v1/actions/subscription-product-group/create-group\", params);\n }\n\n /**\n * Update a subscription product group. `productIds` is a full replacement.\n *\n * @param params - Group update parameters\n * @returns Updated group entity\n *\n * @example\n * const { group } = await client.subscriptionProductGroups.update({\n * id: \"GRP_xxx\",\n * productIds: [\"PROD_aaa\", \"PROD_bbb\", \"PROD_ccc\"],\n * });\n */\n async update(params: UpdateSubscriptionProductGroupParams): Promise<{ group: SubscriptionProductGroup }> {\n validateRequired(\"id\", params.id);\n return this.http.post<{ group: SubscriptionProductGroup }>(\"/v1/actions/subscription-product-group/update-group\", params);\n }\n\n /**\n * Hard-delete a subscription product group.\n *\n * @param params - Group to delete\n * @returns Deleted group entity\n *\n * @example\n * const { group } = await client.subscriptionProductGroups.delete({ id: \"GRP_xxx\" });\n */\n async delete(params: DeleteSubscriptionProductGroupParams): Promise<{ group: SubscriptionProductGroup }> {\n validateRequired(\"id\", params.id);\n return this.http.post<{ group: SubscriptionProductGroup }>(\"/v1/actions/subscription-product-group/delete-group\", params);\n }\n\n /**\n * Publish a test-environment group to production (upsert).\n *\n * @param params - Group to publish\n * @returns Published group entity\n *\n * @example\n * const { group } = await client.subscriptionProductGroups.publish({ id: \"GRP_xxx\" });\n */\n async publish(params: PublishSubscriptionProductGroupParams): Promise<{ group: SubscriptionProductGroup }> {\n validateRequired(\"id\", params.id);\n return this.http.post<{ group: SubscriptionProductGroup }>(\"/v1/actions/subscription-product-group/publish-group\", params);\n }\n}\n","import { validateEnum, validatePrices, validateRequired, validateShortId } from \"../validation.js\";\n\nimport type { HttpClient } from \"../http-client.js\";\nimport type {\n CreateSubscriptionProductParams,\n PublishSubscriptionProductParams,\n SubscriptionProductDetail,\n UpdateSubscriptionProductParams,\n UpdateSubscriptionStatusParams,\n} from \"../types.js\";\n\n/** Subscription product management resource. */\nexport class SubscriptionProductsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Create a subscription product with billing period and multi-currency pricing.\n *\n * @param params - Product creation parameters\n * @returns Created product detail\n *\n * @example\n * const { product } = await client.subscriptionProducts.create({\n * storeId: \"STO_xxx\",\n * name: \"Pro Plan\",\n * billingPeriod: \"monthly\",\n * prices: { USD: { amount: \"9.99\", taxCategory: \"saas\" } },\n * });\n */\n async create(params: CreateSubscriptionProductParams): Promise<{ product: SubscriptionProductDetail }> {\n validateShortId(\"storeId\", params.storeId, \"STO\");\n validateRequired(\"name\", params.name);\n validateEnum(\"billingPeriod\", params.billingPeriod, [\"weekly\", \"monthly\", \"quarterly\", \"yearly\"]);\n validatePrices(\"prices\", params.prices);\n return this.http.post<{ product: SubscriptionProductDetail }>(\"/v1/actions/subscription-product/create-product\", params);\n }\n\n /**\n * Update a subscription product. Creates a new version; skips if unchanged.\n *\n * @param params - Product update parameters (only `id` is required)\n * @returns Updated product detail\n *\n * @example\n * // Update only the name\n * const { product } = await client.subscriptionProducts.update({\n * id: \"PROD_xxx\",\n * name: \"Pro Plan v2\",\n * });\n *\n * @example\n * // Update prices and billing period\n * const { product } = await client.subscriptionProducts.update({\n * id: \"PROD_xxx\",\n * billingPeriod: \"yearly\",\n * prices: { USD: { amount: \"99.00\", taxCategory: \"saas\" } },\n * });\n */\n async update(params: UpdateSubscriptionProductParams): Promise<{ product: SubscriptionProductDetail }> {\n validateShortId(\"id\", params.id, \"PROD\");\n if (params.name !== undefined) validateRequired(\"name\", params.name);\n if (params.billingPeriod !== undefined)\n validateEnum(\"billingPeriod\", params.billingPeriod, [\"weekly\", \"monthly\", \"quarterly\", \"yearly\"]);\n if (params.prices) validatePrices(\"prices\", params.prices);\n return this.http.post<{ product: SubscriptionProductDetail }>(\"/v1/actions/subscription-product/update-product\", params);\n }\n\n /**\n * Publish a subscription product's test version to production.\n *\n * @param params - Product to publish\n * @returns Published product detail\n *\n * @example\n * const { product } = await client.subscriptionProducts.publish({ id: \"PROD_xxx\" });\n */\n async publish(params: PublishSubscriptionProductParams): Promise<{ product: SubscriptionProductDetail }> {\n validateShortId(\"id\", params.id, \"PROD\");\n return this.http.post<{ product: SubscriptionProductDetail }>(\"/v1/actions/subscription-product/publish-product\", params);\n }\n\n /**\n * Update a subscription product's status (active/inactive).\n *\n * @param params - Status update parameters\n * @returns Updated product detail\n *\n * @example\n * const { product } = await client.subscriptionProducts.updateStatus({\n * id: \"PROD_xxx\",\n * status: ProductVersionStatus.Active,\n * });\n */\n async updateStatus(params: UpdateSubscriptionStatusParams): Promise<{ product: SubscriptionProductDetail }> {\n validateShortId(\"id\", params.id, \"PROD\");\n validateEnum(\"status\", params.status, [\"active\", \"inactive\"]);\n return this.http.post<{ product: SubscriptionProductDetail }>(\"/v1/actions/subscription-product/update-status\", params);\n }\n}\n","import { createVerify } from \"node:crypto\";\n\nimport { normalizePublicKey } from \"./signing.js\";\n\nimport type { VerifyWebhookOptions, WebhookEvent, WebhookPublicKeys } from \"./types.js\";\n\n/** Default tolerance: 5 minutes */\nconst DEFAULT_TOLERANCE_MS = 5 * 60 * 1000;\n\n/** Waffo Pancake test environment webhook verification public key. */\nconst TEST_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxnmRY6yMMA3lVqmAU6ZG\nb1sjL/+r/z6E+ZjkXaDAKiqOhk9rpazni0bNsGXwmftTPk9jy2wn+j6JHODD/WH/\nSCnSfvKkLIjy4Hk7BuCgB174C0ydan7J+KgXLkOwgCAxxB68t2tezldwo74ZpXgn\nF49opzMvQ9prEwIAWOE+kV9iK6gx/AckSMtHIHpUesoPDkldpmFHlB2qpf1vsFTZ\n5kD6DmGl+2GIVK01aChy2lk8pLv0yUMu18v44sLkO5M44TkGPJD9qG09wrvVG2wp\nOTVCn1n5pP8P+HRLcgzbUB3OlZVfdFurn6EZwtyL4ZD9kdkQ4EZE/9inKcp3c1h4\nxwIDAQAB\n-----END PUBLIC KEY-----`;\n\n/** Waffo Pancake production environment webhook verification public key. */\nconst PROD_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz+xApdTIb4ua+DgZKQ54\niBsD82ybyhGCLRETONW4Jgbb3A8DUM1LqBk6r/CmTOCHqLalTQHNigvP3R5zkDNX\niRJz6gA4MJ/+8K0+mnEE2RISQzN+Qu65TNd6svb+INm/kMaftY4uIXr6y6kchtTJ\ndwnQhcKdAL2v7h7IFnkVelQsKxDdb2PqX8xX/qwd01iXvMcpCCaXovUwZsxH2QN5\nZKBTseJivbhUeyJCco4fdUyxOMHe2ybCVhyvim2uxAl1nkvL5L8RCWMCAV55LLo0\n9OhmLahz/DYNu13YLVP6dvIT09ZFBYU6Owj1NxdinTynlJCFS9VYwBgmftosSE1U\ndwIDAQAB\n-----END PUBLIC KEY-----`;\n\n/**\n * Parse `X-Waffo-Signature` header.\n *\n * Format: `t=<timestamp>,v1=<base64signature>`\n *\n * @returns Parsed `t` (timestamp string) and `v1` (base64 signature)\n */\nfunction parseSignatureHeader(header: string): { t: string; v1: string } {\n let t = \"\";\n let v1 = \"\";\n for (const pair of header.split(\",\")) {\n const eqIdx = pair.indexOf(\"=\");\n if (eqIdx === -1) continue;\n const key = pair.slice(0, eqIdx).trim();\n const value = pair.slice(eqIdx + 1).trim();\n if (key === \"t\") t = value;\n else if (key === \"v1\") v1 = value;\n }\n return { t, v1 };\n}\n\n/**\n * Verify RSA-SHA256 signature against a public key.\n *\n * @param signatureInput - The string to verify (`${t}.${rawBody}`)\n * @param v1 - Base64-encoded signature\n * @param publicKey - PEM public key\n * @returns Whether the signature is valid\n */\nfunction rsaVerify(signatureInput: string, v1: string, publicKey: string): boolean {\n const verifier = createVerify(\"RSA-SHA256\");\n verifier.update(signatureInput);\n return verifier.verify(publicKey, v1, \"base64\");\n}\n\n/**\n * Resolve the public key for a given environment using the multi-level fallback chain.\n *\n * Resolution order:\n * 1. `configKeys[env]` or `configKeys` (if string) — from WaffoPancakeConfig\n * 2. `WAFFO_WEBHOOK_TEST_PUBLIC_KEY` / `WAFFO_WEBHOOK_PROD_PUBLIC_KEY` — env var per-env\n * 3. `WAFFO_WEBHOOK_PUBLIC_KEY` — env var shared\n * 4. Built-in hardcoded key\n *\n * @param env - Target environment\n * @param configKeys - Config-level public key(s)\n * @returns Resolved and normalized PEM public key\n */\nfunction resolveKeyForEnv(env: \"test\" | \"prod\", configKeys?: WebhookPublicKeys): string {\n // 1. Config-level key\n if (typeof configKeys === \"string\") {\n return normalizePublicKey(configKeys);\n }\n if (configKeys?.[env]) {\n return normalizePublicKey(configKeys[env]);\n }\n\n // 2. Environment variable (per-env)\n const envSpecific = env === \"test\" ? process.env.WAFFO_WEBHOOK_TEST_PUBLIC_KEY : process.env.WAFFO_WEBHOOK_PROD_PUBLIC_KEY;\n if (envSpecific) {\n return normalizePublicKey(envSpecific);\n }\n\n // 3. Environment variable (shared)\n const generic = process.env.WAFFO_WEBHOOK_PUBLIC_KEY;\n if (generic) {\n return normalizePublicKey(generic);\n }\n\n // 4. Built-in hardcoded key\n return env === \"test\" ? TEST_PUBLIC_KEY : PROD_PUBLIC_KEY;\n}\n\n/**\n * Verify and parse an incoming Waffo Pancake webhook event.\n *\n * Public key resolution (per environment):\n * 1. `options.publicKey` — per-call override (highest priority, skips all other resolution)\n * 2. `options.publicKeys[env]` or `options.publicKeys` (string) — config-level\n * 3. `WAFFO_WEBHOOK_{TEST|PROD}_PUBLIC_KEY` environment variable\n * 4. `WAFFO_WEBHOOK_PUBLIC_KEY` environment variable\n * 5. Built-in hardcoded key\n *\n * Behavior:\n * - Parses the `X-Waffo-Signature` header (`t=<timestamp>,v1=<base64sig>`)\n * - Builds signature input `${t}.${rawBody}` and verifies with RSA-SHA256\n * - When `environment` is not specified, tries prod key first, then test key\n * - Optional: checks timestamp to prevent replay attacks (default 5-minute tolerance)\n *\n * @param payload - Raw request body string (must be unparsed)\n * @param signatureHeader - Value of the `X-Waffo-Signature` header\n * @param options - Verification options\n * @returns Parsed webhook event\n * @throws Error if header is missing/malformed, signature is invalid, or timestamp is stale\n *\n * @example\n * // Express (use raw body!)\n * app.post(\"/webhooks\", express.raw({ type: \"application/json\" }), (req, res) => {\n * try {\n * const event = verifyWebhook(\n * req.body.toString(\"utf-8\"),\n * req.headers[\"x-waffo-signature\"] as string,\n * );\n * res.status(200).send(\"OK\");\n * handleEventAsync(event).catch(console.error);\n * } catch {\n * res.status(401).send(\"Invalid signature\");\n * }\n * });\n *\n * @example\n * // Next.js App Router\n * export async function POST(request: Request) {\n * const body = await request.text();\n * const sig = request.headers.get(\"x-waffo-signature\");\n * const event = verifyWebhook(body, sig);\n * // handle event ...\n * return new Response(\"OK\");\n * }\n *\n * @example\n * // Specify environment explicitly\n * const event = verifyWebhook(body, sig, { environment: \"prod\" });\n *\n * @example\n * // Disable replay protection\n * const event = verifyWebhook(body, sig, { toleranceMs: 0 });\n */\nexport function verifyWebhook<T = Record<string, unknown>>(\n payload: string,\n signatureHeader: string | undefined | null,\n options?: VerifyWebhookOptions,\n): WebhookEvent<T> {\n if (!signatureHeader) {\n throw new Error(\"Missing X-Waffo-Signature header\");\n }\n\n const { t, v1 } = parseSignatureHeader(signatureHeader);\n if (!t || !v1) {\n throw new Error(\"Malformed X-Waffo-Signature header: missing t or v1\");\n }\n\n // Replay protection\n const toleranceMs = options?.toleranceMs ?? DEFAULT_TOLERANCE_MS;\n if (toleranceMs > 0) {\n const timestampMs = Number(t);\n if (Number.isNaN(timestampMs)) {\n throw new Error(\"Invalid timestamp in X-Waffo-Signature header\");\n }\n if (Math.abs(Date.now() - timestampMs) > toleranceMs) {\n throw new Error(\"Webhook timestamp outside tolerance window (possible replay attack)\");\n }\n }\n\n // RSA-SHA256 verification\n const signatureInput = `${t}.${payload}`;\n const directKey = options?.publicKey;\n\n if (directKey) {\n // Per-call override — highest priority, skip all resolution\n const normalizedKey = normalizePublicKey(directKey);\n if (!rsaVerify(signatureInput, v1, normalizedKey)) {\n throw new Error(\"Invalid webhook signature (custom key)\");\n }\n } else {\n const configKeys = options?.publicKeys;\n const env = options?.environment;\n\n if (env === \"test\" || env === \"prod\") {\n const key = resolveKeyForEnv(env, configKeys);\n if (!rsaVerify(signatureInput, v1, key)) {\n throw new Error(`Invalid webhook signature (${env} key)`);\n }\n } else {\n // Auto-detect: try prod first, then test\n const prodKey = resolveKeyForEnv(\"prod\", configKeys);\n if (!rsaVerify(signatureInput, v1, prodKey)) {\n const testKey = resolveKeyForEnv(\"test\", configKeys);\n if (!rsaVerify(signatureInput, v1, testKey)) {\n throw new Error(\"Invalid webhook signature (tried both prod and test keys)\");\n }\n }\n }\n }\n\n return JSON.parse(payload) as WebhookEvent<T>;\n}\n","import { verifyWebhook } from \"../webhooks.js\";\n\nimport type { VerifyWebhookOptions, WebhookEvent, WebhookPublicKeys } from \"../types.js\";\n\n/**\n * Webhook signature verification resource.\n *\n * Unlike other resources, this does not use HttpClient — webhook verification\n * is a local cryptographic operation that does not require API calls.\n */\nexport class WebhooksResource {\n /** @param publicKeys - Optional config-level public key(s) from WaffoPancakeConfig */\n constructor(private readonly publicKeys: WebhookPublicKeys | undefined) {}\n\n /**\n * Verify and parse an incoming webhook event.\n *\n * Key resolution order:\n * 1. `options.publicKey` — per-call override (highest priority)\n * 2. `config.webhookPublicKey[env]` or `config.webhookPublicKey` (string)\n * 3. `WAFFO_WEBHOOK_{TEST|PROD}_PUBLIC_KEY` environment variable\n * 4. `WAFFO_WEBHOOK_PUBLIC_KEY` environment variable\n * 5. Built-in hardcoded key\n *\n * @param payload - Raw request body string (must be unparsed)\n * @param signatureHeader - Value of the `X-Waffo-Signature` header\n * @param options - Verification options (optional)\n * @returns Parsed webhook event\n * @throws Error if signature is invalid, header is malformed, or timestamp is stale\n *\n * @example\n * const event = client.webhooks.verify(rawBody, signatureHeader);\n *\n * @example\n * // Specify environment\n * const event = client.webhooks.verify(rawBody, sig, { environment: \"test\" });\n *\n * @example\n * // Per-call key override\n * const event = client.webhooks.verify(rawBody, sig, { publicKey: oneOffKey });\n */\n verify<T = Record<string, unknown>>(\n payload: string,\n signatureHeader: string | undefined | null,\n options?: VerifyWebhookOptions,\n ): WebhookEvent<T> {\n const mergedOptions: VerifyWebhookOptions = {\n ...options,\n publicKeys: options?.publicKeys ?? this.publicKeys,\n };\n return verifyWebhook<T>(payload, signatureHeader, mergedOptions);\n }\n}\n","import { BuyerHttpClient } from \"./buyer-http-client.js\";\nimport { HttpClient } from \"./http-client.js\";\nimport { AuthResource } from \"./resources/auth.js\";\nimport { BuyerSession } from \"./resources/buyer.js\";\nimport { CheckoutResource } from \"./resources/checkout.js\";\nimport { GraphQLResource } from \"./resources/graphql.js\";\nimport { OnetimeProductsResource } from \"./resources/onetime-products.js\";\nimport { OrdersResource } from \"./resources/orders.js\";\nimport { StoreMerchantsResource } from \"./resources/store-merchants.js\";\nimport { StoresResource } from \"./resources/stores.js\";\nimport { SubscriptionProductGroupsResource } from \"./resources/subscription-product-groups.js\";\nimport { SubscriptionProductsResource } from \"./resources/subscription-products.js\";\nimport { WebhooksResource } from \"./resources/webhooks.js\";\nimport { validateShortId } from \"./validation.js\";\n\nimport type { WaffoPancakeConfig } from \"./types.js\";\n\n/**\n * Waffo Pancake TypeScript SDK client.\n *\n * Uses Merchant API Key (RSA-SHA256) authentication. All requests are\n * automatically signed — no manual header construction needed.\n *\n * @example\n * import { WaffoPancake } from \"@waffo/pancake-ts\";\n *\n * const client = new WaffoPancake({\n * merchantId: \"MER_2D5F8G3H1K4M6N9P0Q7R8S\", // MER_{base62} format\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * });\n *\n * // Create a store — IDs are returned in {prefix}_{base62} format\n * const { store } = await client.stores.create({ name: \"My Store\" });\n * // => store.id = \"STO_...\"\n *\n * // Create a product\n * const { product } = await client.onetimeProducts.create({\n * storeId: store.id, // \"STO_...\"\n * name: \"E-Book\",\n * prices: { USD: { amount: \"29.00\", taxCategory: \"digital_goods\" } },\n * });\n * // => product.id = \"PROD_...\"\n *\n * // Create a checkout session\n * const session = await client.checkout.createSession({\n * productId: product.id,\n * currency: \"USD\",\n * });\n * // => redirect customer to session.checkoutUrl\n *\n * // Query data via GraphQL\n * const result = await client.graphql.query({\n * query: `query { stores { id name status } }`,\n * });\n *\n * @example\n * // Per-environment webhook public keys\n * const client = new WaffoPancake({\n * merchantId: \"...\",\n * privateKey: \"...\",\n * webhookPublicKey: {\n * test: process.env.WAFFO_TEST_PUB_KEY!,\n * prod: process.env.WAFFO_PROD_PUB_KEY!,\n * },\n * });\n * const event = client.webhooks.verify(rawBody, signatureHeader);\n */\nexport class WaffoPancake {\n private readonly http: HttpClient;\n private readonly config: WaffoPancakeConfig;\n\n readonly auth: AuthResource;\n readonly stores: StoresResource;\n readonly storeMerchants: StoreMerchantsResource;\n readonly onetimeProducts: OnetimeProductsResource;\n readonly subscriptionProducts: SubscriptionProductsResource;\n readonly subscriptionProductGroups: SubscriptionProductGroupsResource;\n readonly orders: OrdersResource;\n readonly checkout: CheckoutResource;\n readonly graphql: GraphQLResource;\n readonly webhooks: WebhooksResource;\n\n constructor(config: WaffoPancakeConfig) {\n validateShortId(\"merchantId\", config.merchantId, \"MER\");\n this.config = config;\n this.http = new HttpClient(config);\n\n this.auth = new AuthResource(this.http);\n this.stores = new StoresResource(this.http);\n this.storeMerchants = new StoreMerchantsResource(this.http);\n this.onetimeProducts = new OnetimeProductsResource(this.http);\n this.subscriptionProducts = new SubscriptionProductsResource(this.http);\n this.subscriptionProductGroups = new SubscriptionProductGroupsResource(this.http);\n this.orders = new OrdersResource(this.http);\n this.checkout = new CheckoutResource(this.http);\n this.graphql = new GraphQLResource(this.http);\n this.webhooks = new WebhooksResource(config.webhookPublicKey);\n }\n\n /**\n * Create a buyer session for self-service operations.\n *\n * The returned session uses Bearer token authentication and provides\n * methods for order cancellation, subscription management, refund tickets,\n * and scoped GraphQL queries.\n *\n * @param token - Session token from `client.auth.issueSessionToken()`\n * @returns A buyer session with self-service methods\n *\n * @example\n * const { token } = await client.auth.issueSessionToken({\n * storeId: \"STO_xxx\",\n * buyerIdentity: \"customer@example.com\",\n * });\n * const buyer = client.buyer(token);\n * await buyer.cancelSubscription({ orderId: \"ORD_xxx\" });\n */\n buyer(token: string): BuyerSession {\n const buyerHttp = new BuyerHttpClient(token, {\n baseUrl: this.config.baseUrl,\n fetch: this.config.fetch,\n });\n return new BuyerSession(buyerHttp);\n }\n}\n","// ---------------------------------------------------------------------------\n// Client config\n// ---------------------------------------------------------------------------\n\nexport interface WaffoPancakeConfig {\n /** Merchant ID in `MER_{base62}` format (sent as X-Merchant-Id header) */\n merchantId: string;\n /** RSA private key in PEM format for request signing */\n privateKey: string;\n /** Base URL override (default: https://api.waffo.ai) */\n baseUrl?: string;\n /** Custom fetch implementation (default: global fetch) */\n fetch?: typeof fetch;\n /**\n * Custom RSA public key(s) for webhook signature verification.\n *\n * - `string` — single key used for both test and prod environments\n * - `{ test?, prod? }` — per-environment keys\n *\n * Resolution order per environment: config key → env var → built-in key.\n * @see {@link VerifyWebhookOptions} for per-call overrides\n */\n webhookPublicKey?: WebhookPublicKeys;\n}\n\n// ---------------------------------------------------------------------------\n// Internal HTTP options\n// ---------------------------------------------------------------------------\n\n/**\n * Options for {@link HttpClient.post}.\n * Not exported publicly — used by resource classes.\n */\nexport interface PostOptions {\n /**\n * Time window in seconds for idempotency key rotation.\n * When set, a floored timestamp is mixed into the key so identical params\n * produce a new key after the window elapses (e.g. 60 = per-minute dedup).\n */\n idempotencyWindow?: number;\n}\n\n// ---------------------------------------------------------------------------\n// API response envelope\n// ---------------------------------------------------------------------------\n\n/**\n * Single error object within the `errors` array.\n *\n * @example\n * { message: \"Store slug already exists\", layer: \"store\" }\n */\nexport interface ApiError {\n /** Error message */\n message: string;\n /** Layer where the error originated */\n layer: `${ErrorLayer}`;\n}\n\n/** Successful API response envelope. */\nexport interface ApiSuccessResponse<T> {\n data: T;\n}\n\n/**\n * Error API response envelope.\n *\n * `errors` are ordered by call stack: `[0]` is the deepest layer, `[n]` is the outermost.\n */\nexport interface ApiErrorResponse {\n data: null;\n errors: ApiError[];\n}\n\n/** Union type of success and error API responses. */\nexport type ApiResponse<T> = ApiSuccessResponse<T> | ApiErrorResponse;\n\n// ---------------------------------------------------------------------------\n// Enums (runtime-accessible values)\n// ---------------------------------------------------------------------------\n\n/**\n * Environment type.\n * @see waffo-pancake-order-service/app/lib/types.ts\n */\nexport enum Environment {\n Test = \"test\",\n Prod = \"prod\",\n}\n\n/**\n * Tax category for products.\n * @see waffo-pancake-product-service/app/lib/resources/types.ts\n */\nexport enum TaxCategory {\n DigitalGoods = \"digital_goods\",\n SaaS = \"saas\",\n Software = \"software\",\n Ebook = \"ebook\",\n OnlineCourse = \"online_course\",\n Consulting = \"consulting\",\n ProfessionalService = \"professional_service\",\n}\n\n/**\n * Subscription billing period.\n * @see waffo-pancake-product-service/app/lib/resources/types.ts\n */\nexport enum BillingPeriod {\n Weekly = \"weekly\",\n Monthly = \"monthly\",\n Quarterly = \"quarterly\",\n Yearly = \"yearly\",\n}\n\n/**\n * Product version status.\n * @see waffo-pancake-product-service/app/lib/resources/types.ts\n */\nexport enum ProductVersionStatus {\n Active = \"active\",\n Inactive = \"inactive\",\n}\n\n/**\n * Store entity status.\n * @see waffo-pancake-store-service/app/lib/resources/store.ts\n */\nexport enum EntityStatus {\n Active = \"active\",\n Inactive = \"inactive\",\n Suspended = \"suspended\",\n}\n\n/**\n * Store member role.\n * @see waffo-pancake-store-service/app/lib/resources/store.ts\n */\nexport enum StoreRole {\n Owner = \"owner\",\n Admin = \"admin\",\n Member = \"member\",\n}\n\n/**\n * One-time order status.\n * @see waffo-pancake-order-service/app/lib/resources/onetime-order.ts\n */\nexport enum OnetimeOrderStatus {\n Pending = \"pending\",\n Completed = \"completed\",\n Canceled = \"canceled\",\n}\n\n/**\n * Subscription order status.\n *\n * State machine:\n * - pending -> active, canceled, closed (PSP CLOSE from never-activated)\n * - active -> canceling, past_due, canceled, expired\n * - canceling -> active, canceled\n * - past_due -> active, canceled\n * - closed -> terminal (never-activated subscription closed by PSP)\n * - canceled -> terminal\n * - expired -> terminal\n *\n * @see waffo-pancake-order-service/app/lib/resources/subscription-order.ts\n */\nexport enum SubscriptionOrderStatus {\n Pending = \"pending\",\n Active = \"active\",\n Canceling = \"canceling\",\n PastDue = \"past_due\",\n Closed = \"closed\",\n Canceled = \"canceled\",\n Expired = \"expired\",\n}\n\n/**\n * Payment status.\n * @see waffo-pancake-order-service/app/lib/resources/payment.ts\n */\nexport enum PaymentStatus {\n Pending = \"pending\",\n Succeeded = \"succeeded\",\n Failed = \"failed\",\n Canceled = \"canceled\",\n}\n\n/**\n * Refund ticket status.\n * @see waffo-pancake-order-service/app/lib/resources/refund-ticket.ts\n */\nexport enum RefundTicketStatus {\n Pending = \"pending\",\n UnderReview = \"under_review\",\n Approved = \"approved\",\n Rejected = \"rejected\",\n Returned = \"returned\",\n Processing = \"processing\",\n Succeeded = \"succeeded\",\n Failed = \"failed\",\n Cancelled = \"cancelled\",\n}\n\n/**\n * Refund status.\n * @see waffo-pancake-order-service/app/lib/resources/refund.ts\n */\nexport enum RefundStatus {\n Succeeded = \"succeeded\",\n Failed = \"failed\",\n}\n\n/**\n * Media asset type.\n * @see waffo-pancake-product-service/app/lib/resources/types.ts\n */\nexport enum MediaType {\n Image = \"image\",\n Video = \"video\",\n}\n\n/** Error layer identifier in the call stack. */\nexport enum ErrorLayer {\n Gateway = \"gateway\",\n User = \"user\",\n Store = \"store\",\n Product = \"product\",\n Order = \"order\",\n Ticket = \"ticket\",\n GraphQL = \"graphql\",\n Resource = \"resource\",\n /** SDK-specific layer for email delivery errors (not part of the service-side error layers). */\n Email = \"email\",\n /** SDK-side input validation (caught before network request). */\n Sdk = \"sdk\",\n}\n\n// ---------------------------------------------------------------------------\n// Auth\n// ---------------------------------------------------------------------------\n\n/**\n * Parameters for issuing a buyer session token.\n *\n * Provide either `storeId` or `productId` (at least one required).\n * When `productId` is given without `storeId`, the server derives the store from the product.\n *\n * @see waffo-pancake-user-service/app/lib/utils/jwt.ts IssueSessionTokenRequest\n */\nexport interface IssueSessionTokenParams {\n /**\n * Buyer identity — encoded into the JWT payload for merchant-side buyer\n * identification. Accepts an email or any merchant-provided identifier string.\n * To pre-fill the checkout page's email field, use `buyerEmail` on\n * `checkout.authenticated.create`.\n */\n buyerIdentity: string;\n /** Store ID (optional when `productId` is provided) */\n storeId?: string;\n /** Product ID — used to derive the store when `storeId` is omitted */\n productId?: string;\n}\n\n/**\n * Issued session token response.\n *\n * @example\n * { token: \"eyJhbGciOi...\", expiresAt: \"2026-03-10T09:00:00.000Z\" }\n */\nexport interface SessionToken {\n /** JWT token string */\n token: string;\n /** Expiration time (ISO 8601 UTC) */\n expiresAt: string;\n}\n\n// ---------------------------------------------------------------------------\n// Store — from waffo-pancake-store-service\n// ---------------------------------------------------------------------------\n\n/**\n * Webhook configuration for test and production environments.\n * @see waffo-pancake-store-service/app/lib/types.ts\n */\nexport interface WebhookSettings {\n /** Test environment webhook URL */\n testWebhookUrl: string | null;\n /** Production environment webhook URL */\n prodWebhookUrl: string | null;\n /** Event types subscribed in test environment */\n testEvents: string[];\n /** Event types subscribed in production environment */\n prodEvents: string[];\n}\n\n/**\n * Notification settings (all default to true).\n * @see waffo-pancake-store-service/app/lib/types.ts\n */\nexport interface NotificationSettings {\n emailOrderConfirmation: boolean;\n emailSubscriptionConfirmation: boolean;\n emailSubscriptionCycled: boolean;\n emailSubscriptionCanceled: boolean;\n emailSubscriptionRevoked: boolean;\n emailSubscriptionPastDue: boolean;\n notifyNewOrders: boolean;\n notifyNewSubscriptions: boolean;\n}\n\n/**\n * Single-theme checkout page styling.\n * @see waffo-pancake-store-service/app/lib/types.ts\n */\nexport interface CheckoutThemeSettings {\n checkoutLogo: string | null;\n checkoutColorPrimary: string;\n checkoutColorBackground: string;\n checkoutColorCard: string;\n checkoutColorText: string;\n checkoutBorderRadius: string;\n}\n\n/**\n * Checkout page configuration (light and dark themes).\n * @see waffo-pancake-store-service/app/lib/types.ts\n */\nexport interface CheckoutSettings {\n defaultDarkMode: boolean;\n light: CheckoutThemeSettings;\n dark: CheckoutThemeSettings;\n}\n\n/**\n * Store entity.\n * @see waffo-pancake-store-service/app/lib/resources/store.ts\n */\nexport interface Store {\n id: string;\n name: string;\n status: EntityStatus;\n logo: string | null;\n supportEmail: string | null;\n website: string | null;\n slug: string | null;\n prodEnabled: boolean;\n webhookSettings: WebhookSettings | null;\n notificationSettings: NotificationSettings | null;\n checkoutSettings: CheckoutSettings | null;\n deletedAt: string | null;\n createdAt: string;\n updatedAt: string;\n}\n\n/** Parameters for creating a store. */\nexport interface CreateStoreParams {\n /** Store name (slug is auto-generated) */\n name: string;\n}\n\n/**\n * Parameters for updating a store.\n *\n * Settings objects support partial updates — omitted sub-fields keep their\n * existing values, `null` clears a field, and a concrete value sets it.\n * Pass the entire settings object as `null` to clear all fields in the group.\n */\nexport interface UpdateStoreParams {\n /** Store ID */\n id: string;\n /** Store display name */\n name?: string;\n /** Store status */\n status?: EntityStatus;\n /** Store logo URL (set to `null` to remove) */\n logo?: string | null;\n /** Support email address (set to `null` to remove) */\n supportEmail?: string | null;\n /** Store website URL (set to `null` to remove) */\n website?: string | null;\n /** Webhook configuration (partial update — omitted fields keep existing values, set to `null` to clear all) */\n webhookSettings?: Partial<WebhookSettings> | null;\n /** Notification preferences (partial update — omitted fields keep existing values, set to `null` to clear all) */\n notificationSettings?: Partial<NotificationSettings> | null;\n /** Checkout page theme configuration (partial update — omitted fields keep existing values, set to `null` to clear all) */\n checkoutSettings?: Partial<CheckoutSettings> | null;\n}\n\n/** Parameters for deleting (soft-delete) a store. */\nexport interface DeleteStoreParams {\n /** Store ID */\n id: string;\n}\n\n// ---------------------------------------------------------------------------\n// Store Merchant (coming soon — endpoints return 501)\n// ---------------------------------------------------------------------------\n\n/** Parameters for adding a merchant to a store. */\nexport interface AddMerchantParams {\n storeId: string;\n email: string;\n role: \"admin\" | \"member\";\n}\n\n/** Result of adding a merchant to a store. */\nexport interface AddMerchantResult {\n storeId: string;\n merchantId: string;\n email: string;\n role: string;\n status: string;\n addedAt: string;\n}\n\n/** Parameters for removing a merchant from a store. */\nexport interface RemoveMerchantParams {\n storeId: string;\n merchantId: string;\n}\n\n/** Result of removing a merchant from a store. */\nexport interface RemoveMerchantResult {\n message: string;\n removedAt: string;\n}\n\n/** Parameters for updating a merchant's role. */\nexport interface UpdateRoleParams {\n storeId: string;\n merchantId: string;\n role: \"admin\" | \"member\";\n}\n\n/** Result of updating a merchant's role. */\nexport interface UpdateRoleResult {\n storeId: string;\n merchantId: string;\n role: string;\n updatedAt: string;\n}\n\n// ---------------------------------------------------------------------------\n// Product — shared types from waffo-pancake-product-service\n// ---------------------------------------------------------------------------\n\n/**\n * Price for a single currency.\n *\n * Amounts are represented as display strings (e.g., \"9.99\" for USD, \"1000\" for JPY).\n * The server handles conversion to/from smallest currency units internally.\n *\n * @see waffo-pancake-product-service/app/lib/resources/types.ts\n *\n * @example\n * // USD $9.99\n * { amount: \"9.99\", taxCategory: \"saas\" }\n *\n * @example\n * // JPY ¥1000\n * { amount: \"1000\", taxCategory: \"software\" }\n */\nexport interface PriceInfo {\n /** Price amount as display string (e.g., \"9.99\" for USD, \"1000\" for JPY) */\n amount: string;\n /** Tax category */\n taxCategory: TaxCategory;\n}\n\n/**\n * Multi-currency prices (keyed by ISO 4217 currency code).\n *\n * @see waffo-pancake-product-service/app/lib/resources/types.ts\n *\n * @example\n * {\n * \"USD\": { amount: \"9.99\", taxCategory: \"saas\" },\n * \"EUR\": { amount: \"8.99\", taxCategory: \"saas\" }\n * }\n */\nexport type Prices = Record<string, PriceInfo>;\n\n/**\n * Media asset (image or video).\n * @see waffo-pancake-product-service/app/lib/resources/types.ts\n */\nexport interface MediaItem {\n /** Media type */\n type: `${MediaType}`;\n /** Asset URL */\n url: string;\n /** Alt text */\n alt?: string;\n /** Thumbnail URL */\n thumbnail?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Onetime Product — from waffo-pancake-product-service\n// ---------------------------------------------------------------------------\n\n/**\n * One-time product detail (public API shape).\n * @see waffo-pancake-product-service/app/lib/resources/onetime-product.ts OnetimeProductDetail\n */\nexport interface OnetimeProductDetail {\n id: string;\n storeId: string;\n name: string;\n description: string | null;\n prices: Prices;\n media: MediaItem[];\n successUrl: string | null;\n metadata: Record<string, unknown>;\n status: ProductVersionStatus;\n createdAt: string;\n updatedAt: string;\n}\n\n/**\n * Parameters for creating a one-time product.\n * @see waffo-pancake-product-service/app/lib/resources/onetime-product.ts CreateOnetimeProductRequestBody\n */\nexport interface CreateOnetimeProductParams {\n storeId: string;\n name: string;\n prices: Prices;\n description?: string;\n media?: MediaItem[];\n successUrl?: string;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Parameters for updating a one-time product (creates a new version; skips if unchanged).\n * @see waffo-pancake-product-service/app/lib/resources/onetime-product.ts UpdateOnetimeProductContentRequestBody\n */\nexport interface UpdateOnetimeProductParams {\n id: string;\n name?: string;\n prices?: Prices;\n description?: string;\n media?: MediaItem[];\n successUrl?: string;\n metadata?: Record<string, unknown>;\n}\n\n/** Parameters for publishing a one-time product's test version to production. */\nexport interface PublishOnetimeProductParams {\n /** Product ID */\n id: string;\n}\n\n/**\n * Parameters for updating a one-time product's status.\n * @see waffo-pancake-product-service/app/lib/resources/onetime-product.ts UpdateOnetimeStatusRequestBody\n */\nexport interface UpdateOnetimeStatusParams {\n id: string;\n status: ProductVersionStatus;\n}\n\n// ---------------------------------------------------------------------------\n// Subscription Product — from waffo-pancake-product-service\n// ---------------------------------------------------------------------------\n\n/**\n * Subscription product detail (public API shape).\n * @see waffo-pancake-product-service/app/lib/resources/subscription-product.ts SubscriptionProductDetail\n */\nexport interface SubscriptionProductDetail {\n id: string;\n storeId: string;\n name: string;\n description: string | null;\n billingPeriod: BillingPeriod;\n prices: Prices;\n media: MediaItem[];\n successUrl: string | null;\n metadata: Record<string, unknown>;\n status: ProductVersionStatus;\n createdAt: string;\n updatedAt: string;\n}\n\n/**\n * Parameters for creating a subscription product.\n * @see waffo-pancake-product-service/app/lib/resources/subscription-product.ts CreateSubscriptionProductRequestBody\n */\nexport interface CreateSubscriptionProductParams {\n storeId: string;\n name: string;\n billingPeriod: BillingPeriod;\n prices: Prices;\n description?: string;\n media?: MediaItem[];\n successUrl?: string;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Parameters for updating a subscription product (creates a new version; skips if unchanged).\n * @see waffo-pancake-product-service/app/lib/resources/subscription-product.ts UpdateSubscriptionProductContentRequestBody\n */\nexport interface UpdateSubscriptionProductParams {\n id: string;\n name?: string;\n billingPeriod?: BillingPeriod;\n prices?: Prices;\n description?: string;\n media?: MediaItem[];\n successUrl?: string;\n metadata?: Record<string, unknown>;\n}\n\n/** Parameters for publishing a subscription product's test version to production. */\nexport interface PublishSubscriptionProductParams {\n /** Product ID */\n id: string;\n}\n\n/**\n * Parameters for updating a subscription product's status.\n * @see waffo-pancake-product-service/app/lib/resources/subscription-product.ts UpdateSubscriptionStatusRequestBody\n */\nexport interface UpdateSubscriptionStatusParams {\n id: string;\n status: ProductVersionStatus;\n}\n\n// ---------------------------------------------------------------------------\n// Subscription Product Group — from waffo-pancake-product-service\n// ---------------------------------------------------------------------------\n\n/**\n * Group rules for subscription product groups.\n * @see waffo-pancake-product-service/app/lib/resources/subscription-product-group.ts\n */\nexport interface GroupRules {\n /** Whether trial period is shared across products in the group */\n sharedTrial: boolean;\n}\n\n/**\n * Subscription product group entity.\n * @see waffo-pancake-product-service/app/lib/resources/subscription-product-group.ts\n */\nexport interface SubscriptionProductGroup {\n id: string;\n storeId: string;\n name: string;\n description: string | null;\n rules: GroupRules;\n productIds: string[];\n environment: Environment;\n createdAt: string;\n updatedAt: string;\n}\n\n/**\n * Parameters for creating a subscription product group.\n * @see waffo-pancake-product-service/app/lib/resources/subscription-product-group.ts CreateGroupRequestBody\n */\nexport interface CreateSubscriptionProductGroupParams {\n storeId: string;\n name: string;\n description?: string;\n rules?: GroupRules;\n productIds?: string[];\n}\n\n/**\n * Parameters for updating a subscription product group (`productIds` is a full replacement).\n * @see waffo-pancake-product-service/app/lib/resources/subscription-product-group.ts UpdateGroupRequestBody\n */\nexport interface UpdateSubscriptionProductGroupParams {\n id: string;\n name?: string;\n description?: string;\n rules?: GroupRules;\n productIds?: string[];\n}\n\n/** Parameters for hard-deleting a subscription product group. */\nexport interface DeleteSubscriptionProductGroupParams {\n /** Group ID */\n id: string;\n}\n\n/** Parameters for publishing a test-environment group to production (upsert). */\nexport interface PublishSubscriptionProductGroupParams {\n /** Group ID */\n id: string;\n}\n\n// ---------------------------------------------------------------------------\n// Order — from waffo-pancake-order-service\n// ---------------------------------------------------------------------------\n\n/** Parameters for canceling a subscription order. */\nexport interface CancelSubscriptionParams {\n /** Order ID */\n orderId: string;\n}\n\n/**\n * Result of canceling a subscription order.\n * @see waffo-pancake-order-service cancel-order route.ts\n */\nexport interface CancelSubscriptionResult {\n orderId: string;\n /** Status after cancellation (`\"canceled\"` or `\"canceling\"`) */\n status: `${SubscriptionOrderStatus}`;\n}\n\n/**\n * Buyer billing details for checkout.\n * @see waffo-pancake-order-service/app/lib/types.ts\n */\nexport interface BillingDetail {\n /** Country code (ISO 3166-1 alpha-2) */\n country: string;\n /** Whether this is a business purchase */\n isBusiness: boolean;\n /** Postal / ZIP code (required for US, at least one of postcode/state for CA) */\n postcode?: string;\n /** State / province code (at least one of state/postcode for CA) */\n state?: string;\n /** Business name (recommended for invoicing, does not affect tax calculation) */\n businessName?: string;\n /** Tax ID / VAT number (EU businesses: triggers reverse charge 0% when provided) */\n taxId?: string;\n}\n\n/**\n * Parameters for creating a checkout session.\n * @see waffo-pancake-order-service/app/lib/types.ts CreateCheckoutSessionRequest\n */\nexport interface CreateCheckoutSessionParams {\n /** Product ID */\n productId: string;\n /** Currency code (ISO 4217) */\n currency: string;\n /** Optional price snapshot override (reads from DB if omitted) */\n priceSnapshot?: PriceInfo;\n /** Trial toggle override (subscription only) */\n withTrial?: boolean;\n /** Pre-filled buyer email */\n buyerEmail?: string;\n /** Pre-filled billing details */\n billingDetail?: BillingDetail;\n /** Redirect URL after successful payment */\n successUrl?: string;\n /** Session expiration in seconds (default: 45 minutes) */\n expiresInSeconds?: number;\n /** Dark mode override (true=dark, false=light, omit=use store default) */\n darkMode?: boolean;\n /** Custom metadata */\n metadata?: Record<string, string>;\n}\n\n/** Result of creating a checkout session. */\nexport interface CheckoutSessionResult {\n /** Session ID */\n sessionId: string;\n /** URL to redirect the customer to */\n checkoutUrl: string;\n /** Session expiration time (ISO 8601 UTC) */\n expiresAt: string;\n}\n\n// ---------------------------------------------------------------------------\n// Buyer self-service\n// ---------------------------------------------------------------------------\n\n/** Parameters for canceling a one-time order (buyer-side). */\nexport interface CancelOnetimeOrderParams {\n /** Order ID */\n orderId: string;\n}\n\n/** Result of canceling a one-time order. */\nexport interface CancelOnetimeOrderResult {\n /** Order ID */\n orderId: string;\n /** Resulting status (`\"canceled\"`) */\n status: string;\n}\n\n/** Parameters for reactivating a subscription (buyer-side). */\nexport interface ReactivateSubscriptionParams {\n /** Subscription order ID */\n orderId: string;\n}\n\n/** Result of reactivating a subscription. */\nexport interface ReactivateSubscriptionResult {\n /** Order ID */\n orderId: string;\n /** Resulting status (`\"active\"`) */\n status: string;\n}\n\n/** Requested refund amount. */\nexport interface RequestedAmount {\n /** Refund amount in display format (e.g., `\"29.00\"`) */\n amount: string;\n /** Currency code (ISO 4217) */\n currency: string;\n}\n\n/**\n * Per-version data for a refund ticket. Each ticket can be submitted/resubmitted\n * multiple times; this is the shape of a single submission.\n */\nexport interface RefundTicketVersionData {\n /** Refund reason supplied by the buyer */\n reason: string;\n /** Requested refund amount; `null` if the version has no amount recorded */\n requestedAmount: RequestedAmount | null;\n}\n\n/** Parameters for creating a refund ticket (buyer-side). */\nexport interface CreateRefundTicketParams {\n /** Payment ID to refund */\n paymentId: string;\n /** Reason for the refund request */\n reason: string;\n /** Requested refund amount */\n requestedAmount: RequestedAmount;\n /** Custom metadata */\n metadata?: Record<string, unknown>;\n}\n\n/** Parameters for resubmitting a rejected refund ticket (buyer-side). */\nexport interface ResubmitRefundTicketParams {\n /** Existing ticket ID */\n ticketId: string;\n /** Payment ID */\n paymentId: string;\n /** Updated reason */\n reason: string;\n /** Updated requested amount */\n requestedAmount: RequestedAmount;\n}\n\n/** Refund ticket entity returned from create/resubmit operations. */\nexport interface RefundTicket {\n /** Ticket ID */\n id: string;\n /** Ticket type (e.g., `\"refund\"`) */\n type: string;\n /** Ticket status (e.g., `\"pending\"`, `\"approved\"`, `\"rejected\"`) */\n status: string;\n /** Associated payment ID */\n subjectId: string;\n /** Submitter identifier (email or merchant ID) */\n submitterId: string;\n /** Submitter type (e.g., `\"customer\"`, `\"merchant\"`) */\n submitterType: string;\n /** Current version ID */\n currentVersionId: string | null;\n /** Reviewer ID (null if not yet reviewed) */\n reviewerId: string | null;\n /** Review timestamp (ISO 8601, null if not yet reviewed) */\n reviewedAt: string | null;\n /** Reviewer's note */\n reviewNote: string | null;\n /** Rejection reason (null if approved or pending) */\n rejectReason: string | null;\n /** Execution timestamp (ISO 8601, null if not yet executed) */\n executedAt: string | null;\n /** Custom metadata */\n metadata: Record<string, unknown>;\n /** Current version number */\n versionNumber: number | null;\n /** Current (latest) version data */\n versionData: RefundTicketVersionData | null;\n /** Creation timestamp (ISO 8601) */\n createdAt: string;\n /** Last update timestamp (ISO 8601) */\n updatedAt: string;\n}\n\n// ---------------------------------------------------------------------------\n// Checkout — convenience wrappers\n// ---------------------------------------------------------------------------\n\n/**\n * Parameters for anonymous checkout.\n *\n * The buyer reaches the checkout page without a session token. Merchants may still\n * pre-fill `buyerEmail` and `billingDetail`; omitting them leaves the form blank.\n *\n * Accepts every field of {@link CreateCheckoutSessionParams} — this wrapper simply\n * forwards the params unchanged to `/v1/actions/checkout/create-session`.\n *\n * @example\n * const result = await client.checkout.anonymous.create({\n * productId: \"PROD_xxx\",\n * currency: \"USD\",\n * });\n * // Redirect to result.checkoutUrl\n */\nexport type AnonymousCheckoutParams = CreateCheckoutSessionParams;\n\n/**\n * Parameters for authenticated checkout.\n *\n * Merges the checkout-session fields ({@link CreateCheckoutSessionParams}) with the\n * extra `buyerIdentity` required by `issue-session-token`. The wrapper splits the\n * input: `buyerIdentity` goes to the token call; everything else (including\n * `buyerEmail`) goes to the create-session call. The two fields are independent.\n *\n * @example\n * const result = await client.checkout.authenticated.create({\n * productId: \"PROD_xxx\",\n * currency: \"USD\",\n * buyerIdentity: \"user-123\", // merchant-side buyer id (goes into JWT)\n * buyerEmail: \"customer@example.com\", // pre-filled on the checkout page\n * });\n * // Redirect to result.checkoutUrl (includes #token=...)\n */\nexport interface AuthenticatedCheckoutParams extends CreateCheckoutSessionParams {\n /**\n * Buyer identity — sent to `issue-session-token` and encoded into the JWT\n * payload for merchant-side buyer identification. Accepts an email or any\n * merchant-provided identifier string. Use `buyerEmail` to pre-fill the\n * checkout page's email input.\n */\n buyerIdentity: string;\n}\n\n/**\n * Result of an authenticated checkout creation.\n *\n * Extends the base session result with the issued token details.\n */\nexport interface AuthenticatedCheckoutResult {\n /** Session ID */\n sessionId: string;\n /** Checkout URL with session token appended as URL fragment (`#token=...`) */\n checkoutUrl: string;\n /** Session expiration time (ISO 8601 UTC) */\n expiresAt: string;\n /** Issued JWT token */\n token: string;\n /** Token expiration time (ISO 8601 UTC) */\n tokenExpiresAt: string;\n}\n\n// ---------------------------------------------------------------------------\n// GraphQL\n// ---------------------------------------------------------------------------\n\n/** Parameters for a GraphQL query. */\nexport interface GraphQLParams {\n /** GraphQL query string */\n query: string;\n /** Query variables */\n variables?: Record<string, unknown>;\n}\n\n/** GraphQL response envelope. */\nexport interface GraphQLResponse<T = Record<string, unknown>> {\n data: T | null;\n errors?: Array<{\n message: string;\n locations?: Array<{ line: number; column: number }>;\n path?: string[];\n }>;\n}\n\n// ---------------------------------------------------------------------------\n// Webhook\n// ---------------------------------------------------------------------------\n\n/**\n * Webhook event types.\n * @see docs/api-reference/webhooks.mdx\n */\nexport enum WebhookEventType {\n /** One-time order first payment succeeded */\n OrderCompleted = \"order.completed\",\n /** Subscription first payment succeeded (newly activated) */\n SubscriptionActivated = \"subscription.activated\",\n /** Subscription renewal payment succeeded */\n SubscriptionPaymentSucceeded = \"subscription.payment_succeeded\",\n /** Buyer initiated cancellation (expires at end of current period) */\n SubscriptionCanceling = \"subscription.canceling\",\n /** Buyer withdrew cancellation (subscription restored) */\n SubscriptionUncanceled = \"subscription.uncanceled\",\n /** Subscription product changed (upgrade/downgrade) */\n SubscriptionUpdated = \"subscription.updated\",\n /** Subscription fully terminated */\n SubscriptionCanceled = \"subscription.canceled\",\n /** Renewal payment failed (past due) */\n SubscriptionPastDue = \"subscription.past_due\",\n /** Refund succeeded */\n RefundSucceeded = \"refund.succeeded\",\n /** Refund failed */\n RefundFailed = \"refund.failed\",\n}\n\n/**\n * Common data fields in a webhook event payload.\n * @see docs/api-reference/webhooks.mdx\n */\nexport interface WebhookEventData {\n // Order\n orderId: string;\n /** Order status (e.g., \"completed\", \"active\", \"canceling\") */\n orderStatus?: string;\n buyerEmail: string;\n /** Merchant-provided buyer identity from checkout session */\n merchantProvidedBuyerIdentity?: string;\n currency: string;\n /** Billing/shipping address (structured object) */\n billingDetail?: Record<string, unknown>;\n /** Order-level metadata from checkout session (flat key-value pairs) */\n orderMetadata?: Record<string, string>;\n\n // Amount\n /** Amount as display string (e.g., \"9.99\" for USD, \"1000\" for JPY) */\n amount: string;\n /** Tax amount as display string (e.g., \"0.91\" for USD) */\n taxAmount: string;\n /** Tax rate as decimal (e.g., 0.1 for 10%) */\n taxRate?: number;\n /** Tax name (e.g., \"Consumption Tax\") */\n taxName?: string;\n /** Subtotal as display string (before tax) */\n subtotal?: string;\n /** Total as display string (after tax) */\n total?: string;\n\n // Product\n productName: string;\n /** Product description */\n productDescription?: string;\n /** Product-level metadata set when creating/updating the product */\n productMetadata?: Record<string, string>;\n\n // Payment (present for payment events: order.completed, subscription.payment_succeeded)\n /** Payment ID */\n paymentId?: string;\n /** Payment status (e.g., \"succeeded\", \"failed\") */\n paymentStatus?: string;\n /** Payment method type (e.g., \"card\") */\n paymentMethod?: string;\n /** Last 4 digits of payment instrument */\n paymentLast4?: string;\n /** Payment failure reason (present when payment failed) */\n paymentFailureReason?: string;\n /** Payment date (ISO 8601 date, e.g., \"2026-04-18\") */\n paymentDate?: string;\n\n // Subscription (present for subscription events)\n /** Billing period: \"weekly\", \"monthly\", \"quarterly\", \"yearly\" */\n billingPeriod?: string;\n /** Current billing period start date (ISO 8601, e.g., \"2026-04-01\") */\n currentPeriodStart?: string;\n /** Current billing period end date (ISO 8601, e.g., \"2026-05-01\") */\n currentPeriodEnd?: string;\n /** Subscription cancellation timestamp (ISO 8601, present when canceled) */\n canceledAt?: string;\n\n // Refund (present for refund events: refund.succeeded, refund.failed)\n /** Refund status (e.g., \"succeeded\", \"failed\") */\n refundStatus?: string;\n /** Refund reason */\n refundReason?: string;\n /** Refund creation timestamp (ISO 8601) */\n refundCreatedAt?: string;\n}\n\n/**\n * Webhook event payload.\n *\n * @see docs/api-reference/webhooks.mdx\n *\n * @example\n * {\n * id: \"550e8400-...\",\n * timestamp: \"2026-03-10T08:30:00.000Z\",\n * eventType: \"order.completed\",\n * eventId: \"PAY_5xK9mRtYvWnPqLsJ3hBfDe\",\n * storeId: \"STO_2aUyqjCzEIiEcYMKj7TZtw\",\n * storeName: \"My Store\",\n * mode: \"prod\",\n * data: { orderId: \"...\", buyerEmail: \"...\", currency: \"USD\", amount: \"29.00\", taxAmount: \"2.90\", productName: \"Pro Plan\", orderMetadata: { planId: \"pro\" } }\n * }\n */\nexport interface WebhookEvent<T = WebhookEventData> {\n /** Delivery record unique ID (UUID), usable for idempotent deduplication */\n id: string;\n /** Event timestamp (ISO 8601 UTC) */\n timestamp: string;\n /** Event type */\n eventType: `${WebhookEventType}` | (string & {});\n /** Business event ID (e.g. payment ID, order ID) */\n eventId: string;\n /** Store ID the event belongs to */\n storeId: string;\n /** Store name */\n storeName: string;\n /** Environment identifier */\n mode: `${Environment}`;\n /** Event data */\n data: T;\n}\n\n/**\n * Webhook public key configuration.\n *\n * - `string` — single key used for both test and prod environments\n * - `{ test?, prod? }` — per-environment keys\n */\nexport type WebhookPublicKeys = string | { test?: string; prod?: string };\n\n/** Options for {@link verifyWebhook}. */\nexport interface VerifyWebhookOptions {\n /**\n * Specify which environment's public key to use for verification.\n * When omitted, both keys are tried automatically (prod first).\n * Ignored when `publicKey` is provided.\n */\n environment?: `${Environment}`;\n /**\n * Timestamp tolerance window in milliseconds for replay protection.\n * Set to 0 to skip timestamp checking.\n * @default 300000 (5 minutes)\n */\n toleranceMs?: number;\n /**\n * Per-call public key override (highest priority).\n * When provided, skips all other key resolution (config, env vars, built-in).\n */\n publicKey?: string;\n /**\n * Config-level public key(s) for the resolution chain.\n * When using `client.webhooks.verify()`, this is set automatically from `WaffoPancakeConfig.webhookPublicKey`.\n * When using the standalone `verifyWebhook()`, you can pass this directly for config-level key injection.\n *\n * Resolution order per environment:\n * 1. `publicKey` (per-call override)\n * 2. `publicKeys[env]` or `publicKeys` (config)\n * 3. `WAFFO_WEBHOOK_{TEST|PROD}_PUBLIC_KEY` (env var)\n * 4. `WAFFO_WEBHOOK_PUBLIC_KEY` (env var)\n * 5. Built-in hardcoded key\n */\n publicKeys?: WebhookPublicKeys;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACeO,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAClC;AAAA,EACA;AAAA,EAET,YAAY,QAAgB,QAAoB;AAC9C,UAAM,YAAY,OAAO,CAAC,GAAG,WAAW;AACxC,UAAM,SAAS;AACf,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,SAAS;AAAA,EAChB;AACF;;;ACtBA,IAAM,mBAAmB;AAUlB,IAAM,kBAAN,MAAsB;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EAEjB,YAAY,OAAe,QAAuD;AAChF,SAAK,QAAQ;AACb,SAAK,WAAW,OAAO,WAAW,kBAAkB,QAAQ,QAAQ,EAAE;AACtE,SAAK,SAAS,OAAO,SAAS,WAAW,MAAM,KAAK,UAAU;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,KAAQ,MAAc,MAA0B;AACpD,UAAM,WAAW,MAAM,KAAK,OAAO,GAAG,KAAK,OAAO,GAAG,IAAI,IAAI;AAAA,MAC3D,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,QA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,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,eAAY;AACZ,EAAAA,cAAA,YAAS;AAFC,SAAAA;AAAA,GAAA;AASL,IAAK,YAAL,kBAAKC,eAAL;AACL,EAAAA,WAAA,WAAQ;AACR,EAAAA,WAAA,WAAQ;AAFE,SAAAA;AAAA,GAAA;AAML,IAAK,aAAL,kBAAKC,gBAAL;AACL,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,WAAQ;AACR,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,WAAQ;AACR,EAAAA,YAAA,YAAS;AACT,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,cAAW;AAEX,EAAAA,YAAA,WAAQ;AAER,EAAAA,YAAA,SAAM;AAZI,SAAAA;AAAA,GAAA;AAuvBL,IAAK,mBAAL,kBAAKC,sBAAL;AAEL,EAAAA,kBAAA,oBAAiB;AAEjB,EAAAA,kBAAA,2BAAwB;AAExB,EAAAA,kBAAA,kCAA+B;AAE/B,EAAAA,kBAAA,2BAAwB;AAExB,EAAAA,kBAAA,4BAAyB;AAEzB,EAAAA,kBAAA,yBAAsB;AAEtB,EAAAA,kBAAA,0BAAuB;AAEvB,EAAAA,kBAAA,yBAAsB;AAEtB,EAAAA,kBAAA,qBAAkB;AAElB,EAAAA,kBAAA,kBAAe;AApBL,SAAAA;AAAA,GAAA;","names":["import_node_crypto","DEFAULT_BASE_URL","import_node_crypto","Environment","TaxCategory","BillingPeriod","ProductVersionStatus","EntityStatus","StoreRole","OnetimeOrderStatus","SubscriptionOrderStatus","PaymentStatus","RefundTicketStatus","RefundStatus","MediaType","ErrorLayer","WebhookEventType"]}
|