@waffo/pancake-nextjs 0.4.0 → 0.5.0
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 +16 -0
- package/README.md +8 -0
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +4 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,22 @@ All notable changes to `@waffo/pancake-nextjs` will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.5.0] - 2026-08-08
|
|
8
|
+
|
|
9
|
+
Picks up the `@waffo/pancake-ts` fix that makes customer sessions reach the API at all.
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- **`createCustomerSessionAction` reached the gateway but never the API.** Every action it dispatched — `cancelSubscription`, `cancelOnetimeOrder`, `reactivateSubscription`, `createRefundTicket`, `resubmitRefundTicket`, `query` — was rejected with HTTP 400 `Incomplete JWT authentication headers`, because the underlying session client omitted `X-Environment`. Fixed in `@waffo/pancake-ts` 0.18.0; no code change here beyond the dependency.
|
|
14
|
+
- **`createWebhookHandler` no longer rejects legitimate delivery retries.** The signature timestamp is stamped before the first attempt and retries reuse it, so late retries arrived outside the old 5-minute replay window. The default is now 45 minutes past / 1 minute future, inherited from `@waffo/pancake-ts` 0.18.0. `verifyOptions` passes through unchanged, including the new `futureToleranceMs`.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- **`createCustomerSessionAction(config)` requires `config.environment`** (`"test"` or `"prod"`), forwarded to the customer session. Without it the action throws `WaffoPancakeError` (400, `layer: "sdk"`) on the first call. `createCustomerTokenAction` is unaffected — token issuance authenticates with the API Key, whose environment the gateway derives from the key itself.
|
|
19
|
+
- `@waffo/pancake-ts` dependency range raised to `^0.18.0`.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
7
23
|
## [0.4.0] - 2026-07-28
|
|
8
24
|
|
|
9
25
|
Adds per-transaction payment method selection to checkout.
|
package/README.md
CHANGED
|
@@ -45,6 +45,8 @@ import {
|
|
|
45
45
|
const config = {
|
|
46
46
|
merchantId: process.env.WAFFO_MERCHANT_ID!,
|
|
47
47
|
privateKey: process.env.WAFFO_PRIVATE_KEY!,
|
|
48
|
+
// Required by createCustomerSessionAction — session tokens carry no environment
|
|
49
|
+
environment: "test" as const,
|
|
48
50
|
};
|
|
49
51
|
|
|
50
52
|
export const checkout = createCheckoutAction(config);
|
|
@@ -180,6 +182,12 @@ import { checkout } from "./lib/waffo";
|
|
|
180
182
|
For programmatic control — same props as `CheckoutButton`, returns `{ checkout, isLoading, error }`:
|
|
181
183
|
|
|
182
184
|
```tsx
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
> Passing `billingDetail` couples the cashier to the order's billing country: it then offers only that country's
|
|
188
|
+
> payment market and the customer cannot switch. The country that applies is the one on the finished order, not the
|
|
189
|
+
> one you sent; a country outside the payment markets we cover applies no restriction. Omit it to leave the cashier
|
|
190
|
+
> unrestricted.
|
|
183
191
|
import { useCheckout } from "@waffo/pancake-nextjs";
|
|
184
192
|
import { checkout as checkoutAction } from "./lib/waffo";
|
|
185
193
|
|
package/dist/server.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["/**\n * Server-side entry point for @waffo/pancake-nextjs.\n *\n * All functions in this module use the private key for RSA signing\n * and must only run on the server (Next.js Server Actions / Route Handlers).\n *\n * @example\n * ```ts\n * // app/lib/waffo.ts\n * \"use server\";\n * import { createCheckoutAction, createCustomerTokenAction, createMerchantQueryAction } from \"@waffo/pancake-nextjs/server\";\n *\n * const config = {\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * };\n *\n * export const checkout = createCheckoutAction(config);\n * export const issueCustomerToken = createCustomerTokenAction(config);\n * export const merchantQuery = createMerchantQueryAction(config);\n * ```\n */\nimport { WaffoPancake } from \"@waffo/pancake-ts\";\n\nimport type {\n WaffoPancakeConfig,\n AnonymousCheckoutParams,\n AuthenticatedCheckoutParams,\n CheckoutSessionResult,\n AuthenticatedCheckoutResult,\n IssueSessionTokenParams,\n SessionToken,\n GraphQLParams,\n GraphQLResponse,\n} from \"@waffo/pancake-ts\";\n\n// ============================================================\n// Checkout Action\n// ============================================================\n\n/** Parameters for the checkout server action */\nexport type CheckoutActionParams =\n | ({ type?: \"anonymous\" } & AnonymousCheckoutParams)\n | ({ type: \"authenticated\" } & AuthenticatedCheckoutParams);\n\n/** Result of the checkout server action */\nexport type CheckoutActionResult = CheckoutSessionResult | AuthenticatedCheckoutResult;\n\n/** Server action signature for checkout */\nexport type CheckoutAction = (params: CheckoutActionParams) => Promise<CheckoutActionResult>;\n\n/**\n * Create a server action that handles checkout session creation.\n *\n * The private key is captured in the closure and never sent to the client.\n *\n * @param config - WaffoPancake client configuration (merchantId + privateKey)\n * @returns A server action function\n *\n * @example\n * ```ts\n * \"use server\";\n * import { createCheckoutAction } from \"@waffo/pancake-nextjs/server\";\n *\n * export const checkout = createCheckoutAction({\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * });\n * ```\n */\nexport function createCheckoutAction(config: WaffoPancakeConfig): CheckoutAction {\n const client = new WaffoPancake(config);\n\n return async (params: CheckoutActionParams): Promise<CheckoutActionResult> => {\n if (params.type === \"authenticated\") {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- remove type field before passing to SDK\n const { type, ...sdkParams } = params;\n return client.checkout.authenticated.create(sdkParams);\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- remove type field before passing to SDK\n const { type, ...sdkParams } = params;\n return client.checkout.anonymous.create(sdkParams);\n };\n}\n\n// ============================================================\n// Customer Token Action\n// ============================================================\n\n/** Server action signature for issuing customer tokens */\nexport type CustomerTokenAction = (params: IssueSessionTokenParams) => Promise<SessionToken>;\n\n/**\n * Create a server action that issues customer session tokens.\n *\n * @param config - WaffoPancake client configuration\n * @returns A server action function\n *\n * @example\n * ```ts\n * \"use server\";\n * import { createCustomerTokenAction } from \"@waffo/pancake-nextjs/server\";\n *\n * export const issueCustomerToken = createCustomerTokenAction({\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * });\n * ```\n */\nexport function createCustomerTokenAction(config: WaffoPancakeConfig): CustomerTokenAction {\n const client = new WaffoPancake(config);\n\n return async (params: IssueSessionTokenParams): Promise<SessionToken> => {\n return client.auth.issueSessionToken(params);\n };\n}\n\n// ============================================================\n// Customer Session Action\n// ============================================================\n\n/** Customer action types */\nexport type CustomerSessionActionType =\n | \"cancelSubscription\"\n | \"cancelOnetimeOrder\"\n | \"reactivateSubscription\"\n | \"createRefundTicket\"\n | \"resubmitRefundTicket\"\n | \"query\";\n\n/** Server action signature for customer session operations */\nexport type CustomerSessionAction = (token: string, actionType: CustomerSessionActionType, params: unknown) => Promise<unknown>;\n\n/**\n * Create a server action that executes customer self-service operations.\n *\n * @param config - WaffoPancake client configuration\n * @returns A server action function\n *\n * @example\n * ```ts\n * \"use server\";\n * import { createCustomerSessionAction } from \"@waffo/pancake-nextjs/server\";\n *\n * export const customerAction = createCustomerSessionAction({\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * });\n * ```\n */\nexport function createCustomerSessionAction(config: WaffoPancakeConfig): CustomerSessionAction {\n const client = new WaffoPancake(config);\n\n return async (token: string, actionType: CustomerSessionActionType, params: unknown): Promise<unknown> => {\n const customer = client.buyer(token);\n switch (actionType) {\n case \"cancelSubscription\":\n return customer.cancelSubscription(params as Parameters<typeof customer.cancelSubscription>[0]);\n case \"cancelOnetimeOrder\":\n return customer.cancelOnetimeOrder(params as Parameters<typeof customer.cancelOnetimeOrder>[0]);\n case \"reactivateSubscription\":\n return customer.reactivateSubscription(params as Parameters<typeof customer.reactivateSubscription>[0]);\n case \"createRefundTicket\":\n return customer.createRefundTicket(params as Parameters<typeof customer.createRefundTicket>[0]);\n case \"resubmitRefundTicket\":\n return customer.resubmitRefundTicket(params as Parameters<typeof customer.resubmitRefundTicket>[0]);\n case \"query\":\n return customer.graphql.query(params as GraphQLParams);\n default:\n throw new Error(`Unknown customer action: ${actionType}`);\n }\n };\n}\n\n// ============================================================\n// Merchant Query Action\n// ============================================================\n\n/** Server action signature for merchant GraphQL queries */\nexport type MerchantQueryAction = (params: GraphQLParams) => Promise<GraphQLResponse>;\n\n/**\n * Create a server action that executes merchant GraphQL queries.\n *\n * @param config - WaffoPancake client configuration\n * @returns A server action function\n *\n * @example\n * ```ts\n * \"use server\";\n * import { createMerchantQueryAction } from \"@waffo/pancake-nextjs/server\";\n *\n * export const merchantQuery = createMerchantQueryAction({\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * });\n * ```\n */\nexport function createMerchantQueryAction(config: WaffoPancakeConfig): MerchantQueryAction {\n const client = new WaffoPancake(config);\n\n return async (params: GraphQLParams): Promise<GraphQLResponse> => {\n return client.graphql.query(params);\n };\n}\n\n// ============================================================\n// Deprecated Aliases\n// ============================================================\n\n/** @deprecated Use {@link CustomerTokenAction} instead. */\nexport type BuyerTokenAction = CustomerTokenAction;\n\n/** @deprecated Use {@link createCustomerTokenAction} instead. */\nexport const createBuyerTokenAction = createCustomerTokenAction;\n\n/** @deprecated Use {@link CustomerSessionActionType} instead. */\nexport type BuyerSessionActionType = CustomerSessionActionType;\n\n/** @deprecated Use {@link CustomerSessionAction} instead. */\nexport type BuyerSessionAction = CustomerSessionAction;\n\n/** @deprecated Use {@link createCustomerSessionAction} instead. */\nexport const createBuyerSessionAction = createCustomerSessionAction;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBA,wBAA6B;AAgDtB,SAAS,qBAAqB,QAA4C;AAC/E,QAAM,SAAS,IAAI,+BAAa,MAAM;AAEtC,SAAO,OAAO,WAAgE;AAC5E,QAAI,OAAO,SAAS,iBAAiB;AAEnC,YAAM,EAAE,MAAAA,OAAM,GAAGC,WAAU,IAAI;AAC/B,aAAO,OAAO,SAAS,cAAc,OAAOA,UAAS;AAAA,IACvD;AAEA,UAAM,EAAE,MAAM,GAAG,UAAU,IAAI;AAC/B,WAAO,OAAO,SAAS,UAAU,OAAO,SAAS;AAAA,EACnD;AACF;AA0BO,SAAS,0BAA0B,QAAiD;AACzF,QAAM,SAAS,IAAI,+BAAa,MAAM;AAEtC,SAAO,OAAO,WAA2D;AACvE,WAAO,OAAO,KAAK,kBAAkB,MAAM;AAAA,EAC7C;AACF;
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["/**\n * Server-side entry point for @waffo/pancake-nextjs.\n *\n * All functions in this module use the private key for RSA signing\n * and must only run on the server (Next.js Server Actions / Route Handlers).\n *\n * @example\n * ```ts\n * // app/lib/waffo.ts\n * \"use server\";\n * import { createCheckoutAction, createCustomerTokenAction, createMerchantQueryAction } from \"@waffo/pancake-nextjs/server\";\n *\n * const config = {\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * };\n *\n * export const checkout = createCheckoutAction(config);\n * export const issueCustomerToken = createCustomerTokenAction(config);\n * export const merchantQuery = createMerchantQueryAction(config);\n * ```\n */\nimport { WaffoPancake } from \"@waffo/pancake-ts\";\n\nimport type {\n WaffoPancakeConfig,\n AnonymousCheckoutParams,\n AuthenticatedCheckoutParams,\n CheckoutSessionResult,\n AuthenticatedCheckoutResult,\n IssueSessionTokenParams,\n SessionToken,\n GraphQLParams,\n GraphQLResponse,\n} from \"@waffo/pancake-ts\";\n\n// ============================================================\n// Checkout Action\n// ============================================================\n\n/** Parameters for the checkout server action */\nexport type CheckoutActionParams =\n | ({ type?: \"anonymous\" } & AnonymousCheckoutParams)\n | ({ type: \"authenticated\" } & AuthenticatedCheckoutParams);\n\n/** Result of the checkout server action */\nexport type CheckoutActionResult = CheckoutSessionResult | AuthenticatedCheckoutResult;\n\n/** Server action signature for checkout */\nexport type CheckoutAction = (params: CheckoutActionParams) => Promise<CheckoutActionResult>;\n\n/**\n * Create a server action that handles checkout session creation.\n *\n * The private key is captured in the closure and never sent to the client.\n *\n * @param config - WaffoPancake client configuration (merchantId + privateKey)\n * @returns A server action function\n *\n * @example\n * ```ts\n * \"use server\";\n * import { createCheckoutAction } from \"@waffo/pancake-nextjs/server\";\n *\n * export const checkout = createCheckoutAction({\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * });\n * ```\n */\nexport function createCheckoutAction(config: WaffoPancakeConfig): CheckoutAction {\n const client = new WaffoPancake(config);\n\n return async (params: CheckoutActionParams): Promise<CheckoutActionResult> => {\n if (params.type === \"authenticated\") {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- remove type field before passing to SDK\n const { type, ...sdkParams } = params;\n return client.checkout.authenticated.create(sdkParams);\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- remove type field before passing to SDK\n const { type, ...sdkParams } = params;\n return client.checkout.anonymous.create(sdkParams);\n };\n}\n\n// ============================================================\n// Customer Token Action\n// ============================================================\n\n/** Server action signature for issuing customer tokens */\nexport type CustomerTokenAction = (params: IssueSessionTokenParams) => Promise<SessionToken>;\n\n/**\n * Create a server action that issues customer session tokens.\n *\n * @param config - WaffoPancake client configuration\n * @returns A server action function\n *\n * @example\n * ```ts\n * \"use server\";\n * import { createCustomerTokenAction } from \"@waffo/pancake-nextjs/server\";\n *\n * export const issueCustomerToken = createCustomerTokenAction({\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * });\n * ```\n */\nexport function createCustomerTokenAction(config: WaffoPancakeConfig): CustomerTokenAction {\n const client = new WaffoPancake(config);\n\n return async (params: IssueSessionTokenParams): Promise<SessionToken> => {\n return client.auth.issueSessionToken(params);\n };\n}\n\n// ============================================================\n// Customer Session Action\n// ============================================================\n\n/** Customer action types */\nexport type CustomerSessionActionType =\n | \"cancelSubscription\"\n | \"cancelOnetimeOrder\"\n | \"reactivateSubscription\"\n | \"createRefundTicket\"\n | \"resubmitRefundTicket\"\n | \"query\";\n\n/** Server action signature for customer session operations */\nexport type CustomerSessionAction = (token: string, actionType: CustomerSessionActionType, params: unknown) => Promise<unknown>;\n\n/**\n * Create a server action that executes customer self-service operations.\n *\n * `config.environment` is required — session tokens carry no environment, and the\n * gateway rejects a session request without the matching header.\n *\n * @param config - WaffoPancake client configuration\n * @returns A server action function\n *\n * @example\n * ```ts\n * \"use server\";\n * import { createCustomerSessionAction } from \"@waffo/pancake-nextjs/server\";\n *\n * export const customerAction = createCustomerSessionAction({\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * environment: \"test\",\n * });\n * ```\n */\nexport function createCustomerSessionAction(config: WaffoPancakeConfig): CustomerSessionAction {\n const client = new WaffoPancake(config);\n\n return async (token: string, actionType: CustomerSessionActionType, params: unknown): Promise<unknown> => {\n const customer = client.buyer(token);\n switch (actionType) {\n case \"cancelSubscription\":\n return customer.cancelSubscription(params as Parameters<typeof customer.cancelSubscription>[0]);\n case \"cancelOnetimeOrder\":\n return customer.cancelOnetimeOrder(params as Parameters<typeof customer.cancelOnetimeOrder>[0]);\n case \"reactivateSubscription\":\n return customer.reactivateSubscription(params as Parameters<typeof customer.reactivateSubscription>[0]);\n case \"createRefundTicket\":\n return customer.createRefundTicket(params as Parameters<typeof customer.createRefundTicket>[0]);\n case \"resubmitRefundTicket\":\n return customer.resubmitRefundTicket(params as Parameters<typeof customer.resubmitRefundTicket>[0]);\n case \"query\":\n return customer.graphql.query(params as GraphQLParams);\n default:\n throw new Error(`Unknown customer action: ${actionType}`);\n }\n };\n}\n\n// ============================================================\n// Merchant Query Action\n// ============================================================\n\n/** Server action signature for merchant GraphQL queries */\nexport type MerchantQueryAction = (params: GraphQLParams) => Promise<GraphQLResponse>;\n\n/**\n * Create a server action that executes merchant GraphQL queries.\n *\n * @param config - WaffoPancake client configuration\n * @returns A server action function\n *\n * @example\n * ```ts\n * \"use server\";\n * import { createMerchantQueryAction } from \"@waffo/pancake-nextjs/server\";\n *\n * export const merchantQuery = createMerchantQueryAction({\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * });\n * ```\n */\nexport function createMerchantQueryAction(config: WaffoPancakeConfig): MerchantQueryAction {\n const client = new WaffoPancake(config);\n\n return async (params: GraphQLParams): Promise<GraphQLResponse> => {\n return client.graphql.query(params);\n };\n}\n\n// ============================================================\n// Deprecated Aliases\n// ============================================================\n\n/** @deprecated Use {@link CustomerTokenAction} instead. */\nexport type BuyerTokenAction = CustomerTokenAction;\n\n/** @deprecated Use {@link createCustomerTokenAction} instead. */\nexport const createBuyerTokenAction = createCustomerTokenAction;\n\n/** @deprecated Use {@link CustomerSessionActionType} instead. */\nexport type BuyerSessionActionType = CustomerSessionActionType;\n\n/** @deprecated Use {@link CustomerSessionAction} instead. */\nexport type BuyerSessionAction = CustomerSessionAction;\n\n/** @deprecated Use {@link createCustomerSessionAction} instead. */\nexport const createBuyerSessionAction = createCustomerSessionAction;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBA,wBAA6B;AAgDtB,SAAS,qBAAqB,QAA4C;AAC/E,QAAM,SAAS,IAAI,+BAAa,MAAM;AAEtC,SAAO,OAAO,WAAgE;AAC5E,QAAI,OAAO,SAAS,iBAAiB;AAEnC,YAAM,EAAE,MAAAA,OAAM,GAAGC,WAAU,IAAI;AAC/B,aAAO,OAAO,SAAS,cAAc,OAAOA,UAAS;AAAA,IACvD;AAEA,UAAM,EAAE,MAAM,GAAG,UAAU,IAAI;AAC/B,WAAO,OAAO,SAAS,UAAU,OAAO,SAAS;AAAA,EACnD;AACF;AA0BO,SAAS,0BAA0B,QAAiD;AACzF,QAAM,SAAS,IAAI,+BAAa,MAAM;AAEtC,SAAO,OAAO,WAA2D;AACvE,WAAO,OAAO,KAAK,kBAAkB,MAAM;AAAA,EAC7C;AACF;AAuCO,SAAS,4BAA4B,QAAmD;AAC7F,QAAM,SAAS,IAAI,+BAAa,MAAM;AAEtC,SAAO,OAAO,OAAe,YAAuC,WAAsC;AACxG,UAAM,WAAW,OAAO,MAAM,KAAK;AACnC,YAAQ,YAAY;AAAA,MAClB,KAAK;AACH,eAAO,SAAS,mBAAmB,MAA2D;AAAA,MAChG,KAAK;AACH,eAAO,SAAS,mBAAmB,MAA2D;AAAA,MAChG,KAAK;AACH,eAAO,SAAS,uBAAuB,MAA+D;AAAA,MACxG,KAAK;AACH,eAAO,SAAS,mBAAmB,MAA2D;AAAA,MAChG,KAAK;AACH,eAAO,SAAS,qBAAqB,MAA6D;AAAA,MACpG,KAAK;AACH,eAAO,SAAS,QAAQ,MAAM,MAAuB;AAAA,MACvD;AACE,cAAM,IAAI,MAAM,4BAA4B,UAAU,EAAE;AAAA,IAC5D;AAAA,EACF;AACF;AA0BO,SAAS,0BAA0B,QAAiD;AACzF,QAAM,SAAS,IAAI,+BAAa,MAAM;AAEtC,SAAO,OAAO,WAAoD;AAChE,WAAO,OAAO,QAAQ,MAAM,MAAM;AAAA,EACpC;AACF;AAUO,IAAM,yBAAyB;AAS/B,IAAM,2BAA2B;","names":["type","sdkParams"]}
|
package/dist/server.d.cts
CHANGED
|
@@ -57,6 +57,9 @@ type CustomerSessionAction = (token: string, actionType: CustomerSessionActionTy
|
|
|
57
57
|
/**
|
|
58
58
|
* Create a server action that executes customer self-service operations.
|
|
59
59
|
*
|
|
60
|
+
* `config.environment` is required — session tokens carry no environment, and the
|
|
61
|
+
* gateway rejects a session request without the matching header.
|
|
62
|
+
*
|
|
60
63
|
* @param config - WaffoPancake client configuration
|
|
61
64
|
* @returns A server action function
|
|
62
65
|
*
|
|
@@ -68,6 +71,7 @@ type CustomerSessionAction = (token: string, actionType: CustomerSessionActionTy
|
|
|
68
71
|
* export const customerAction = createCustomerSessionAction({
|
|
69
72
|
* merchantId: process.env.WAFFO_MERCHANT_ID!,
|
|
70
73
|
* privateKey: process.env.WAFFO_PRIVATE_KEY!,
|
|
74
|
+
* environment: "test",
|
|
71
75
|
* });
|
|
72
76
|
* ```
|
|
73
77
|
*/
|
package/dist/server.d.ts
CHANGED
|
@@ -57,6 +57,9 @@ type CustomerSessionAction = (token: string, actionType: CustomerSessionActionTy
|
|
|
57
57
|
/**
|
|
58
58
|
* Create a server action that executes customer self-service operations.
|
|
59
59
|
*
|
|
60
|
+
* `config.environment` is required — session tokens carry no environment, and the
|
|
61
|
+
* gateway rejects a session request without the matching header.
|
|
62
|
+
*
|
|
60
63
|
* @param config - WaffoPancake client configuration
|
|
61
64
|
* @returns A server action function
|
|
62
65
|
*
|
|
@@ -68,6 +71,7 @@ type CustomerSessionAction = (token: string, actionType: CustomerSessionActionTy
|
|
|
68
71
|
* export const customerAction = createCustomerSessionAction({
|
|
69
72
|
* merchantId: process.env.WAFFO_MERCHANT_ID!,
|
|
70
73
|
* privateKey: process.env.WAFFO_PRIVATE_KEY!,
|
|
74
|
+
* environment: "test",
|
|
71
75
|
* });
|
|
72
76
|
* ```
|
|
73
77
|
*/
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["/**\n * Server-side entry point for @waffo/pancake-nextjs.\n *\n * All functions in this module use the private key for RSA signing\n * and must only run on the server (Next.js Server Actions / Route Handlers).\n *\n * @example\n * ```ts\n * // app/lib/waffo.ts\n * \"use server\";\n * import { createCheckoutAction, createCustomerTokenAction, createMerchantQueryAction } from \"@waffo/pancake-nextjs/server\";\n *\n * const config = {\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * };\n *\n * export const checkout = createCheckoutAction(config);\n * export const issueCustomerToken = createCustomerTokenAction(config);\n * export const merchantQuery = createMerchantQueryAction(config);\n * ```\n */\nimport { WaffoPancake } from \"@waffo/pancake-ts\";\n\nimport type {\n WaffoPancakeConfig,\n AnonymousCheckoutParams,\n AuthenticatedCheckoutParams,\n CheckoutSessionResult,\n AuthenticatedCheckoutResult,\n IssueSessionTokenParams,\n SessionToken,\n GraphQLParams,\n GraphQLResponse,\n} from \"@waffo/pancake-ts\";\n\n// ============================================================\n// Checkout Action\n// ============================================================\n\n/** Parameters for the checkout server action */\nexport type CheckoutActionParams =\n | ({ type?: \"anonymous\" } & AnonymousCheckoutParams)\n | ({ type: \"authenticated\" } & AuthenticatedCheckoutParams);\n\n/** Result of the checkout server action */\nexport type CheckoutActionResult = CheckoutSessionResult | AuthenticatedCheckoutResult;\n\n/** Server action signature for checkout */\nexport type CheckoutAction = (params: CheckoutActionParams) => Promise<CheckoutActionResult>;\n\n/**\n * Create a server action that handles checkout session creation.\n *\n * The private key is captured in the closure and never sent to the client.\n *\n * @param config - WaffoPancake client configuration (merchantId + privateKey)\n * @returns A server action function\n *\n * @example\n * ```ts\n * \"use server\";\n * import { createCheckoutAction } from \"@waffo/pancake-nextjs/server\";\n *\n * export const checkout = createCheckoutAction({\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * });\n * ```\n */\nexport function createCheckoutAction(config: WaffoPancakeConfig): CheckoutAction {\n const client = new WaffoPancake(config);\n\n return async (params: CheckoutActionParams): Promise<CheckoutActionResult> => {\n if (params.type === \"authenticated\") {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- remove type field before passing to SDK\n const { type, ...sdkParams } = params;\n return client.checkout.authenticated.create(sdkParams);\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- remove type field before passing to SDK\n const { type, ...sdkParams } = params;\n return client.checkout.anonymous.create(sdkParams);\n };\n}\n\n// ============================================================\n// Customer Token Action\n// ============================================================\n\n/** Server action signature for issuing customer tokens */\nexport type CustomerTokenAction = (params: IssueSessionTokenParams) => Promise<SessionToken>;\n\n/**\n * Create a server action that issues customer session tokens.\n *\n * @param config - WaffoPancake client configuration\n * @returns A server action function\n *\n * @example\n * ```ts\n * \"use server\";\n * import { createCustomerTokenAction } from \"@waffo/pancake-nextjs/server\";\n *\n * export const issueCustomerToken = createCustomerTokenAction({\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * });\n * ```\n */\nexport function createCustomerTokenAction(config: WaffoPancakeConfig): CustomerTokenAction {\n const client = new WaffoPancake(config);\n\n return async (params: IssueSessionTokenParams): Promise<SessionToken> => {\n return client.auth.issueSessionToken(params);\n };\n}\n\n// ============================================================\n// Customer Session Action\n// ============================================================\n\n/** Customer action types */\nexport type CustomerSessionActionType =\n | \"cancelSubscription\"\n | \"cancelOnetimeOrder\"\n | \"reactivateSubscription\"\n | \"createRefundTicket\"\n | \"resubmitRefundTicket\"\n | \"query\";\n\n/** Server action signature for customer session operations */\nexport type CustomerSessionAction = (token: string, actionType: CustomerSessionActionType, params: unknown) => Promise<unknown>;\n\n/**\n * Create a server action that executes customer self-service operations.\n *\n * @param config - WaffoPancake client configuration\n * @returns A server action function\n *\n * @example\n * ```ts\n * \"use server\";\n * import { createCustomerSessionAction } from \"@waffo/pancake-nextjs/server\";\n *\n * export const customerAction = createCustomerSessionAction({\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * });\n * ```\n */\nexport function createCustomerSessionAction(config: WaffoPancakeConfig): CustomerSessionAction {\n const client = new WaffoPancake(config);\n\n return async (token: string, actionType: CustomerSessionActionType, params: unknown): Promise<unknown> => {\n const customer = client.buyer(token);\n switch (actionType) {\n case \"cancelSubscription\":\n return customer.cancelSubscription(params as Parameters<typeof customer.cancelSubscription>[0]);\n case \"cancelOnetimeOrder\":\n return customer.cancelOnetimeOrder(params as Parameters<typeof customer.cancelOnetimeOrder>[0]);\n case \"reactivateSubscription\":\n return customer.reactivateSubscription(params as Parameters<typeof customer.reactivateSubscription>[0]);\n case \"createRefundTicket\":\n return customer.createRefundTicket(params as Parameters<typeof customer.createRefundTicket>[0]);\n case \"resubmitRefundTicket\":\n return customer.resubmitRefundTicket(params as Parameters<typeof customer.resubmitRefundTicket>[0]);\n case \"query\":\n return customer.graphql.query(params as GraphQLParams);\n default:\n throw new Error(`Unknown customer action: ${actionType}`);\n }\n };\n}\n\n// ============================================================\n// Merchant Query Action\n// ============================================================\n\n/** Server action signature for merchant GraphQL queries */\nexport type MerchantQueryAction = (params: GraphQLParams) => Promise<GraphQLResponse>;\n\n/**\n * Create a server action that executes merchant GraphQL queries.\n *\n * @param config - WaffoPancake client configuration\n * @returns A server action function\n *\n * @example\n * ```ts\n * \"use server\";\n * import { createMerchantQueryAction } from \"@waffo/pancake-nextjs/server\";\n *\n * export const merchantQuery = createMerchantQueryAction({\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * });\n * ```\n */\nexport function createMerchantQueryAction(config: WaffoPancakeConfig): MerchantQueryAction {\n const client = new WaffoPancake(config);\n\n return async (params: GraphQLParams): Promise<GraphQLResponse> => {\n return client.graphql.query(params);\n };\n}\n\n// ============================================================\n// Deprecated Aliases\n// ============================================================\n\n/** @deprecated Use {@link CustomerTokenAction} instead. */\nexport type BuyerTokenAction = CustomerTokenAction;\n\n/** @deprecated Use {@link createCustomerTokenAction} instead. */\nexport const createBuyerTokenAction = createCustomerTokenAction;\n\n/** @deprecated Use {@link CustomerSessionActionType} instead. */\nexport type BuyerSessionActionType = CustomerSessionActionType;\n\n/** @deprecated Use {@link CustomerSessionAction} instead. */\nexport type BuyerSessionAction = CustomerSessionAction;\n\n/** @deprecated Use {@link createCustomerSessionAction} instead. */\nexport const createBuyerSessionAction = createCustomerSessionAction;\n"],"mappings":";AAsBA,SAAS,oBAAoB;AAgDtB,SAAS,qBAAqB,QAA4C;AAC/E,QAAM,SAAS,IAAI,aAAa,MAAM;AAEtC,SAAO,OAAO,WAAgE;AAC5E,QAAI,OAAO,SAAS,iBAAiB;AAEnC,YAAM,EAAE,MAAAA,OAAM,GAAGC,WAAU,IAAI;AAC/B,aAAO,OAAO,SAAS,cAAc,OAAOA,UAAS;AAAA,IACvD;AAEA,UAAM,EAAE,MAAM,GAAG,UAAU,IAAI;AAC/B,WAAO,OAAO,SAAS,UAAU,OAAO,SAAS;AAAA,EACnD;AACF;AA0BO,SAAS,0BAA0B,QAAiD;AACzF,QAAM,SAAS,IAAI,aAAa,MAAM;AAEtC,SAAO,OAAO,WAA2D;AACvE,WAAO,OAAO,KAAK,kBAAkB,MAAM;AAAA,EAC7C;AACF;
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["/**\n * Server-side entry point for @waffo/pancake-nextjs.\n *\n * All functions in this module use the private key for RSA signing\n * and must only run on the server (Next.js Server Actions / Route Handlers).\n *\n * @example\n * ```ts\n * // app/lib/waffo.ts\n * \"use server\";\n * import { createCheckoutAction, createCustomerTokenAction, createMerchantQueryAction } from \"@waffo/pancake-nextjs/server\";\n *\n * const config = {\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * };\n *\n * export const checkout = createCheckoutAction(config);\n * export const issueCustomerToken = createCustomerTokenAction(config);\n * export const merchantQuery = createMerchantQueryAction(config);\n * ```\n */\nimport { WaffoPancake } from \"@waffo/pancake-ts\";\n\nimport type {\n WaffoPancakeConfig,\n AnonymousCheckoutParams,\n AuthenticatedCheckoutParams,\n CheckoutSessionResult,\n AuthenticatedCheckoutResult,\n IssueSessionTokenParams,\n SessionToken,\n GraphQLParams,\n GraphQLResponse,\n} from \"@waffo/pancake-ts\";\n\n// ============================================================\n// Checkout Action\n// ============================================================\n\n/** Parameters for the checkout server action */\nexport type CheckoutActionParams =\n | ({ type?: \"anonymous\" } & AnonymousCheckoutParams)\n | ({ type: \"authenticated\" } & AuthenticatedCheckoutParams);\n\n/** Result of the checkout server action */\nexport type CheckoutActionResult = CheckoutSessionResult | AuthenticatedCheckoutResult;\n\n/** Server action signature for checkout */\nexport type CheckoutAction = (params: CheckoutActionParams) => Promise<CheckoutActionResult>;\n\n/**\n * Create a server action that handles checkout session creation.\n *\n * The private key is captured in the closure and never sent to the client.\n *\n * @param config - WaffoPancake client configuration (merchantId + privateKey)\n * @returns A server action function\n *\n * @example\n * ```ts\n * \"use server\";\n * import { createCheckoutAction } from \"@waffo/pancake-nextjs/server\";\n *\n * export const checkout = createCheckoutAction({\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * });\n * ```\n */\nexport function createCheckoutAction(config: WaffoPancakeConfig): CheckoutAction {\n const client = new WaffoPancake(config);\n\n return async (params: CheckoutActionParams): Promise<CheckoutActionResult> => {\n if (params.type === \"authenticated\") {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- remove type field before passing to SDK\n const { type, ...sdkParams } = params;\n return client.checkout.authenticated.create(sdkParams);\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- remove type field before passing to SDK\n const { type, ...sdkParams } = params;\n return client.checkout.anonymous.create(sdkParams);\n };\n}\n\n// ============================================================\n// Customer Token Action\n// ============================================================\n\n/** Server action signature for issuing customer tokens */\nexport type CustomerTokenAction = (params: IssueSessionTokenParams) => Promise<SessionToken>;\n\n/**\n * Create a server action that issues customer session tokens.\n *\n * @param config - WaffoPancake client configuration\n * @returns A server action function\n *\n * @example\n * ```ts\n * \"use server\";\n * import { createCustomerTokenAction } from \"@waffo/pancake-nextjs/server\";\n *\n * export const issueCustomerToken = createCustomerTokenAction({\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * });\n * ```\n */\nexport function createCustomerTokenAction(config: WaffoPancakeConfig): CustomerTokenAction {\n const client = new WaffoPancake(config);\n\n return async (params: IssueSessionTokenParams): Promise<SessionToken> => {\n return client.auth.issueSessionToken(params);\n };\n}\n\n// ============================================================\n// Customer Session Action\n// ============================================================\n\n/** Customer action types */\nexport type CustomerSessionActionType =\n | \"cancelSubscription\"\n | \"cancelOnetimeOrder\"\n | \"reactivateSubscription\"\n | \"createRefundTicket\"\n | \"resubmitRefundTicket\"\n | \"query\";\n\n/** Server action signature for customer session operations */\nexport type CustomerSessionAction = (token: string, actionType: CustomerSessionActionType, params: unknown) => Promise<unknown>;\n\n/**\n * Create a server action that executes customer self-service operations.\n *\n * `config.environment` is required — session tokens carry no environment, and the\n * gateway rejects a session request without the matching header.\n *\n * @param config - WaffoPancake client configuration\n * @returns A server action function\n *\n * @example\n * ```ts\n * \"use server\";\n * import { createCustomerSessionAction } from \"@waffo/pancake-nextjs/server\";\n *\n * export const customerAction = createCustomerSessionAction({\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * environment: \"test\",\n * });\n * ```\n */\nexport function createCustomerSessionAction(config: WaffoPancakeConfig): CustomerSessionAction {\n const client = new WaffoPancake(config);\n\n return async (token: string, actionType: CustomerSessionActionType, params: unknown): Promise<unknown> => {\n const customer = client.buyer(token);\n switch (actionType) {\n case \"cancelSubscription\":\n return customer.cancelSubscription(params as Parameters<typeof customer.cancelSubscription>[0]);\n case \"cancelOnetimeOrder\":\n return customer.cancelOnetimeOrder(params as Parameters<typeof customer.cancelOnetimeOrder>[0]);\n case \"reactivateSubscription\":\n return customer.reactivateSubscription(params as Parameters<typeof customer.reactivateSubscription>[0]);\n case \"createRefundTicket\":\n return customer.createRefundTicket(params as Parameters<typeof customer.createRefundTicket>[0]);\n case \"resubmitRefundTicket\":\n return customer.resubmitRefundTicket(params as Parameters<typeof customer.resubmitRefundTicket>[0]);\n case \"query\":\n return customer.graphql.query(params as GraphQLParams);\n default:\n throw new Error(`Unknown customer action: ${actionType}`);\n }\n };\n}\n\n// ============================================================\n// Merchant Query Action\n// ============================================================\n\n/** Server action signature for merchant GraphQL queries */\nexport type MerchantQueryAction = (params: GraphQLParams) => Promise<GraphQLResponse>;\n\n/**\n * Create a server action that executes merchant GraphQL queries.\n *\n * @param config - WaffoPancake client configuration\n * @returns A server action function\n *\n * @example\n * ```ts\n * \"use server\";\n * import { createMerchantQueryAction } from \"@waffo/pancake-nextjs/server\";\n *\n * export const merchantQuery = createMerchantQueryAction({\n * merchantId: process.env.WAFFO_MERCHANT_ID!,\n * privateKey: process.env.WAFFO_PRIVATE_KEY!,\n * });\n * ```\n */\nexport function createMerchantQueryAction(config: WaffoPancakeConfig): MerchantQueryAction {\n const client = new WaffoPancake(config);\n\n return async (params: GraphQLParams): Promise<GraphQLResponse> => {\n return client.graphql.query(params);\n };\n}\n\n// ============================================================\n// Deprecated Aliases\n// ============================================================\n\n/** @deprecated Use {@link CustomerTokenAction} instead. */\nexport type BuyerTokenAction = CustomerTokenAction;\n\n/** @deprecated Use {@link createCustomerTokenAction} instead. */\nexport const createBuyerTokenAction = createCustomerTokenAction;\n\n/** @deprecated Use {@link CustomerSessionActionType} instead. */\nexport type BuyerSessionActionType = CustomerSessionActionType;\n\n/** @deprecated Use {@link CustomerSessionAction} instead. */\nexport type BuyerSessionAction = CustomerSessionAction;\n\n/** @deprecated Use {@link createCustomerSessionAction} instead. */\nexport const createBuyerSessionAction = createCustomerSessionAction;\n"],"mappings":";AAsBA,SAAS,oBAAoB;AAgDtB,SAAS,qBAAqB,QAA4C;AAC/E,QAAM,SAAS,IAAI,aAAa,MAAM;AAEtC,SAAO,OAAO,WAAgE;AAC5E,QAAI,OAAO,SAAS,iBAAiB;AAEnC,YAAM,EAAE,MAAAA,OAAM,GAAGC,WAAU,IAAI;AAC/B,aAAO,OAAO,SAAS,cAAc,OAAOA,UAAS;AAAA,IACvD;AAEA,UAAM,EAAE,MAAM,GAAG,UAAU,IAAI;AAC/B,WAAO,OAAO,SAAS,UAAU,OAAO,SAAS;AAAA,EACnD;AACF;AA0BO,SAAS,0BAA0B,QAAiD;AACzF,QAAM,SAAS,IAAI,aAAa,MAAM;AAEtC,SAAO,OAAO,WAA2D;AACvE,WAAO,OAAO,KAAK,kBAAkB,MAAM;AAAA,EAC7C;AACF;AAuCO,SAAS,4BAA4B,QAAmD;AAC7F,QAAM,SAAS,IAAI,aAAa,MAAM;AAEtC,SAAO,OAAO,OAAe,YAAuC,WAAsC;AACxG,UAAM,WAAW,OAAO,MAAM,KAAK;AACnC,YAAQ,YAAY;AAAA,MAClB,KAAK;AACH,eAAO,SAAS,mBAAmB,MAA2D;AAAA,MAChG,KAAK;AACH,eAAO,SAAS,mBAAmB,MAA2D;AAAA,MAChG,KAAK;AACH,eAAO,SAAS,uBAAuB,MAA+D;AAAA,MACxG,KAAK;AACH,eAAO,SAAS,mBAAmB,MAA2D;AAAA,MAChG,KAAK;AACH,eAAO,SAAS,qBAAqB,MAA6D;AAAA,MACpG,KAAK;AACH,eAAO,SAAS,QAAQ,MAAM,MAAuB;AAAA,MACvD;AACE,cAAM,IAAI,MAAM,4BAA4B,UAAU,EAAE;AAAA,IAC5D;AAAA,EACF;AACF;AA0BO,SAAS,0BAA0B,QAAiD;AACzF,QAAM,SAAS,IAAI,aAAa,MAAM;AAEtC,SAAO,OAAO,WAAoD;AAChE,WAAO,OAAO,QAAQ,MAAM,MAAM;AAAA,EACpC;AACF;AAUO,IAAM,yBAAyB;AAS/B,IAAM,2BAA2B;","names":["type","sdkParams"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waffo/pancake-nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Next.js SDK for Waffo Pancake — checkout components and hooks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"license": "MIT",
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@waffo/pancake-ts": "^0.
|
|
51
|
+
"@waffo/pancake-ts": "^0.18.0",
|
|
52
52
|
"next": ">=14.0.0",
|
|
53
53
|
"react": ">=18.0.0",
|
|
54
54
|
"react-dom": ">=18.0.0"
|