@waffo/pancake-ts 0.2.1 → 0.3.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 +31 -0
- package/README.md +0 -12
- package/dist/index.cjs +36 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -40
- package/dist/index.d.ts +34 -40
- package/dist/index.js +36 -23
- package/dist/index.js.map +1 -1
- package/docs/api-reference.md +14 -20
- package/docs/graphql-guide.md +2 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -18,6 +18,18 @@ interface WaffoPancakeConfig {
|
|
|
18
18
|
*/
|
|
19
19
|
webhookPublicKey?: WebhookPublicKeys;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Options for {@link HttpClient.post}.
|
|
23
|
+
* Not exported publicly — used by resource classes.
|
|
24
|
+
*/
|
|
25
|
+
interface PostOptions {
|
|
26
|
+
/**
|
|
27
|
+
* Time window in seconds for idempotency key rotation.
|
|
28
|
+
* When set, a floored timestamp is mixed into the key so identical params
|
|
29
|
+
* produce a new key after the window elapses (e.g. 60 = per-minute dedup).
|
|
30
|
+
*/
|
|
31
|
+
idempotencyWindow?: number;
|
|
32
|
+
}
|
|
21
33
|
/**
|
|
22
34
|
* Single error object within the `errors` array.
|
|
23
35
|
*
|
|
@@ -175,14 +187,6 @@ declare enum MediaType {
|
|
|
175
187
|
Image = "image",
|
|
176
188
|
Video = "video"
|
|
177
189
|
}
|
|
178
|
-
/**
|
|
179
|
-
* Checkout session product type.
|
|
180
|
-
* @see waffo-pancake-order-service/app/lib/types.ts
|
|
181
|
-
*/
|
|
182
|
-
declare enum CheckoutSessionProductType {
|
|
183
|
-
Onetime = "onetime",
|
|
184
|
-
Subscription = "subscription"
|
|
185
|
-
}
|
|
186
190
|
/** Error layer identifier in the call stack. */
|
|
187
191
|
declare enum ErrorLayer {
|
|
188
192
|
Gateway = "gateway",
|
|
@@ -200,13 +204,19 @@ declare enum ErrorLayer {
|
|
|
200
204
|
}
|
|
201
205
|
/**
|
|
202
206
|
* Parameters for issuing a buyer session token.
|
|
207
|
+
*
|
|
208
|
+
* Provide either `storeId` or `productId` (at least one required).
|
|
209
|
+
* When `productId` is given without `storeId`, the server derives the store from the product.
|
|
210
|
+
*
|
|
203
211
|
* @see waffo-pancake-user-service/app/lib/utils/jwt.ts IssueSessionTokenRequest
|
|
204
212
|
*/
|
|
205
213
|
interface IssueSessionTokenParams {
|
|
206
214
|
/** Buyer identity (email or any merchant-provided identifier string) */
|
|
207
215
|
buyerIdentity: string;
|
|
208
|
-
/** Store ID */
|
|
209
|
-
storeId
|
|
216
|
+
/** Store ID (optional when `productId` is provided) */
|
|
217
|
+
storeId?: string;
|
|
218
|
+
/** Product ID — used to derive the store when `storeId` is omitted */
|
|
219
|
+
productId?: string;
|
|
210
220
|
}
|
|
211
221
|
/**
|
|
212
222
|
* Issued session token response.
|
|
@@ -613,12 +623,8 @@ interface BillingDetail {
|
|
|
613
623
|
* @see waffo-pancake-order-service/app/lib/types.ts CreateCheckoutSessionRequest
|
|
614
624
|
*/
|
|
615
625
|
interface CreateCheckoutSessionParams {
|
|
616
|
-
/** Store ID */
|
|
617
|
-
storeId: string;
|
|
618
626
|
/** Product ID */
|
|
619
627
|
productId: string;
|
|
620
|
-
/** Product type */
|
|
621
|
-
productType: `${CheckoutSessionProductType}`;
|
|
622
628
|
/** Currency code (ISO 4217) */
|
|
623
629
|
currency: string;
|
|
624
630
|
/** Optional price snapshot override (reads from DB if omitted) */
|
|
@@ -745,20 +751,14 @@ interface RefundTicket {
|
|
|
745
751
|
*
|
|
746
752
|
* @example
|
|
747
753
|
* const result = await client.checkout.anonymous.create({
|
|
748
|
-
* storeId: "STO_xxx",
|
|
749
754
|
* productId: "PROD_xxx",
|
|
750
|
-
* productType: "onetime",
|
|
751
755
|
* currency: "USD",
|
|
752
756
|
* });
|
|
753
757
|
* // Redirect to result.checkoutUrl
|
|
754
758
|
*/
|
|
755
759
|
interface AnonymousCheckoutParams {
|
|
756
|
-
/** Store ID */
|
|
757
|
-
storeId: string;
|
|
758
760
|
/** Product ID */
|
|
759
761
|
productId: string;
|
|
760
|
-
/** Product type */
|
|
761
|
-
productType: `${CheckoutSessionProductType}`;
|
|
762
762
|
/** Currency code (ISO 4217) */
|
|
763
763
|
currency: string;
|
|
764
764
|
/** Optional price snapshot override (reads from DB if omitted) */
|
|
@@ -782,21 +782,15 @@ interface AnonymousCheckoutParams {
|
|
|
782
782
|
*
|
|
783
783
|
* @example
|
|
784
784
|
* const result = await client.checkout.authenticated.create({
|
|
785
|
-
* storeId: "STO_xxx",
|
|
786
785
|
* productId: "PROD_xxx",
|
|
787
|
-
* productType: "onetime",
|
|
788
786
|
* currency: "USD",
|
|
789
787
|
* buyerIdentity: "customer@example.com",
|
|
790
788
|
* });
|
|
791
789
|
* // Redirect to result.checkoutUrl (includes #token=...)
|
|
792
790
|
*/
|
|
793
791
|
interface AuthenticatedCheckoutParams {
|
|
794
|
-
/** Store ID */
|
|
795
|
-
storeId: string;
|
|
796
792
|
/** Product ID */
|
|
797
793
|
productId: string;
|
|
798
|
-
/** Product type */
|
|
799
|
-
productType: `${CheckoutSessionProductType}`;
|
|
800
794
|
/** Currency code (ISO 4217) */
|
|
801
795
|
currency: string;
|
|
802
796
|
/** Buyer identity (email or merchant-provided identifier) */
|
|
@@ -989,15 +983,19 @@ declare class HttpClient {
|
|
|
989
983
|
*
|
|
990
984
|
* Behavior:
|
|
991
985
|
* - Generates a deterministic `X-Idempotency-Key` from `merchantId + path + body` (same request produces same key)
|
|
986
|
+
* - When `idempotencyWindow` is set, a floored timestamp is mixed into the key so identical params produce
|
|
987
|
+
* a new key after the window elapses (useful for checkout where repeated creation is intentional)
|
|
992
988
|
* - Auto-builds RSA-SHA256 signature (`X-Merchant-Id` / `X-Timestamp` / `X-Signature`)
|
|
993
989
|
* - Unwraps the response envelope: returns `data` on success, throws `WaffoPancakeError` on failure
|
|
994
990
|
*
|
|
995
991
|
* @param path - API path (e.g. `/v1/actions/store/create-store`)
|
|
996
992
|
* @param body - Request body object
|
|
993
|
+
* @param options - Optional settings
|
|
994
|
+
* @param options.idempotencyWindow - Time window in seconds for idempotency key rotation (e.g. 60 = per-minute dedup)
|
|
997
995
|
* @returns Parsed `data` field from the response
|
|
998
996
|
* @throws {WaffoPancakeError} When the API returns errors
|
|
999
997
|
*/
|
|
1000
|
-
post<T>(path: string, body: object): Promise<T>;
|
|
998
|
+
post<T>(path: string, body: object, options?: PostOptions): Promise<T>;
|
|
1001
999
|
}
|
|
1002
1000
|
|
|
1003
1001
|
/** Authentication resource — issue session tokens for buyers. */
|
|
@@ -1011,10 +1009,18 @@ declare class AuthResource {
|
|
|
1011
1009
|
* @returns Issued session token with expiration
|
|
1012
1010
|
*
|
|
1013
1011
|
* @example
|
|
1012
|
+
* // By store ID
|
|
1014
1013
|
* const { token, expiresAt } = await client.auth.issueSessionToken({
|
|
1015
1014
|
* storeId: "STO_xxx",
|
|
1016
1015
|
* buyerIdentity: "customer@example.com",
|
|
1017
1016
|
* });
|
|
1017
|
+
*
|
|
1018
|
+
* @example
|
|
1019
|
+
* // By product ID (store derived automatically)
|
|
1020
|
+
* const { token, expiresAt } = await client.auth.issueSessionToken({
|
|
1021
|
+
* productId: "PROD_xxx",
|
|
1022
|
+
* buyerIdentity: "customer@example.com",
|
|
1023
|
+
* });
|
|
1018
1024
|
*/
|
|
1019
1025
|
issueSessionToken(params: IssueSessionTokenParams): Promise<SessionToken>;
|
|
1020
1026
|
}
|
|
@@ -1165,9 +1171,7 @@ declare class CheckoutAnonymousResource {
|
|
|
1165
1171
|
*
|
|
1166
1172
|
* @example
|
|
1167
1173
|
* const result = await client.checkout.anonymous.create({
|
|
1168
|
-
* storeId: "STO_xxx",
|
|
1169
1174
|
* productId: "PROD_xxx",
|
|
1170
|
-
* productType: "onetime",
|
|
1171
1175
|
* currency: "USD",
|
|
1172
1176
|
* });
|
|
1173
1177
|
* // Redirect to result.checkoutUrl
|
|
@@ -1199,9 +1203,7 @@ declare class CheckoutAuthenticatedResource {
|
|
|
1199
1203
|
*
|
|
1200
1204
|
* @example
|
|
1201
1205
|
* const result = await client.checkout.authenticated.create({
|
|
1202
|
-
* storeId: "STO_xxx",
|
|
1203
1206
|
* productId: "PROD_xxx",
|
|
1204
|
-
* productType: "onetime",
|
|
1205
1207
|
* currency: "USD",
|
|
1206
1208
|
* buyerIdentity: "customer@example.com",
|
|
1207
1209
|
* });
|
|
@@ -1222,18 +1224,14 @@ declare class CheckoutAuthenticatedResource {
|
|
|
1222
1224
|
* @example
|
|
1223
1225
|
* // Anonymous checkout (no identity)
|
|
1224
1226
|
* const result = await client.checkout.anonymous.create({
|
|
1225
|
-
* storeId: "STO_xxx",
|
|
1226
1227
|
* productId: "PROD_xxx",
|
|
1227
|
-
* productType: "onetime",
|
|
1228
1228
|
* currency: "USD",
|
|
1229
1229
|
* });
|
|
1230
1230
|
*
|
|
1231
1231
|
* @example
|
|
1232
1232
|
* // Authenticated checkout (with buyer identity)
|
|
1233
1233
|
* const result = await client.checkout.authenticated.create({
|
|
1234
|
-
* storeId: "STO_xxx",
|
|
1235
1234
|
* productId: "PROD_xxx",
|
|
1236
|
-
* productType: "onetime",
|
|
1237
1235
|
* currency: "USD",
|
|
1238
1236
|
* buyerIdentity: "customer@example.com",
|
|
1239
1237
|
* });
|
|
@@ -1257,9 +1255,7 @@ declare class CheckoutResource {
|
|
|
1257
1255
|
*
|
|
1258
1256
|
* @example
|
|
1259
1257
|
* const session = await client.checkout.createSession({
|
|
1260
|
-
* storeId: "STO_xxx",
|
|
1261
1258
|
* productId: "PROD_xxx",
|
|
1262
|
-
* productType: "onetime",
|
|
1263
1259
|
* currency: "USD",
|
|
1264
1260
|
* buyerEmail: "customer@example.com",
|
|
1265
1261
|
* });
|
|
@@ -1669,9 +1665,7 @@ declare class WebhooksResource {
|
|
|
1669
1665
|
*
|
|
1670
1666
|
* // Create a checkout session
|
|
1671
1667
|
* const session = await client.checkout.createSession({
|
|
1672
|
-
* storeId: store.id,
|
|
1673
1668
|
* productId: product.id,
|
|
1674
|
-
* productType: "onetime",
|
|
1675
1669
|
* currency: "USD",
|
|
1676
1670
|
* });
|
|
1677
1671
|
* // => redirect customer to session.checkoutUrl
|
|
@@ -1804,4 +1798,4 @@ declare class WaffoPancakeError extends Error {
|
|
|
1804
1798
|
*/
|
|
1805
1799
|
declare function verifyWebhook<T = Record<string, unknown>>(payload: string, signatureHeader: string | undefined | null, options?: VerifyWebhookOptions): WebhookEvent<T>;
|
|
1806
1800
|
|
|
1807
|
-
export { type AddMerchantParams, type AddMerchantResult, type AnonymousCheckoutParams, type ApiError, type ApiErrorResponse, type ApiResponse, type ApiSuccessResponse, type AuthenticatedCheckoutParams, type AuthenticatedCheckoutResult, type BillingDetail, BillingPeriod, type CancelOnetimeOrderParams, type CancelOnetimeOrderResult, type CancelSubscriptionParams, type CancelSubscriptionResult,
|
|
1801
|
+
export { type AddMerchantParams, type AddMerchantResult, type AnonymousCheckoutParams, type ApiError, type ApiErrorResponse, type ApiResponse, type ApiSuccessResponse, type AuthenticatedCheckoutParams, type AuthenticatedCheckoutResult, type BillingDetail, BillingPeriod, type CancelOnetimeOrderParams, type CancelOnetimeOrderResult, type CancelSubscriptionParams, type CancelSubscriptionResult, type CheckoutSessionResult, type CheckoutSettings, type CheckoutThemeSettings, type CreateCheckoutSessionParams, type CreateOnetimeProductParams, type CreateRefundTicketParams, type CreateStoreParams, type CreateSubscriptionProductGroupParams, type CreateSubscriptionProductParams, type DeleteStoreParams, type DeleteSubscriptionProductGroupParams, EntityStatus, Environment, ErrorLayer, type GraphQLParams, type GraphQLResponse, type GroupRules, type IssueSessionTokenParams, type MediaItem, MediaType, type NotificationSettings, OnetimeOrderStatus, type OnetimeProductDetail, PaymentStatus, type PriceInfo, type Prices, ProductVersionStatus, type PublishOnetimeProductParams, type PublishSubscriptionProductGroupParams, type PublishSubscriptionProductParams, type ReactivateSubscriptionParams, type ReactivateSubscriptionResult, RefundStatus, type RefundTicket, RefundTicketStatus, type RemoveMerchantParams, type RemoveMerchantResult, type RequestedAmount, type ResubmitRefundTicketParams, type SessionToken, type Store, StoreRole, SubscriptionOrderStatus, type SubscriptionProductDetail, type SubscriptionProductGroup, TaxCategory, type UpdateOnetimeProductParams, type UpdateOnetimeStatusParams, type UpdateRoleParams, type UpdateRoleResult, type UpdateStoreParams, type UpdateSubscriptionProductGroupParams, type UpdateSubscriptionProductParams, type UpdateSubscriptionStatusParams, type VerifyWebhookOptions, WaffoPancake, type WaffoPancakeConfig, WaffoPancakeError, type WebhookEvent, type WebhookEventData, WebhookEventType, type WebhookPublicKeys, type WebhookSettings, verifyWebhook };
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,18 @@ interface WaffoPancakeConfig {
|
|
|
18
18
|
*/
|
|
19
19
|
webhookPublicKey?: WebhookPublicKeys;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Options for {@link HttpClient.post}.
|
|
23
|
+
* Not exported publicly — used by resource classes.
|
|
24
|
+
*/
|
|
25
|
+
interface PostOptions {
|
|
26
|
+
/**
|
|
27
|
+
* Time window in seconds for idempotency key rotation.
|
|
28
|
+
* When set, a floored timestamp is mixed into the key so identical params
|
|
29
|
+
* produce a new key after the window elapses (e.g. 60 = per-minute dedup).
|
|
30
|
+
*/
|
|
31
|
+
idempotencyWindow?: number;
|
|
32
|
+
}
|
|
21
33
|
/**
|
|
22
34
|
* Single error object within the `errors` array.
|
|
23
35
|
*
|
|
@@ -175,14 +187,6 @@ declare enum MediaType {
|
|
|
175
187
|
Image = "image",
|
|
176
188
|
Video = "video"
|
|
177
189
|
}
|
|
178
|
-
/**
|
|
179
|
-
* Checkout session product type.
|
|
180
|
-
* @see waffo-pancake-order-service/app/lib/types.ts
|
|
181
|
-
*/
|
|
182
|
-
declare enum CheckoutSessionProductType {
|
|
183
|
-
Onetime = "onetime",
|
|
184
|
-
Subscription = "subscription"
|
|
185
|
-
}
|
|
186
190
|
/** Error layer identifier in the call stack. */
|
|
187
191
|
declare enum ErrorLayer {
|
|
188
192
|
Gateway = "gateway",
|
|
@@ -200,13 +204,19 @@ declare enum ErrorLayer {
|
|
|
200
204
|
}
|
|
201
205
|
/**
|
|
202
206
|
* Parameters for issuing a buyer session token.
|
|
207
|
+
*
|
|
208
|
+
* Provide either `storeId` or `productId` (at least one required).
|
|
209
|
+
* When `productId` is given without `storeId`, the server derives the store from the product.
|
|
210
|
+
*
|
|
203
211
|
* @see waffo-pancake-user-service/app/lib/utils/jwt.ts IssueSessionTokenRequest
|
|
204
212
|
*/
|
|
205
213
|
interface IssueSessionTokenParams {
|
|
206
214
|
/** Buyer identity (email or any merchant-provided identifier string) */
|
|
207
215
|
buyerIdentity: string;
|
|
208
|
-
/** Store ID */
|
|
209
|
-
storeId
|
|
216
|
+
/** Store ID (optional when `productId` is provided) */
|
|
217
|
+
storeId?: string;
|
|
218
|
+
/** Product ID — used to derive the store when `storeId` is omitted */
|
|
219
|
+
productId?: string;
|
|
210
220
|
}
|
|
211
221
|
/**
|
|
212
222
|
* Issued session token response.
|
|
@@ -613,12 +623,8 @@ interface BillingDetail {
|
|
|
613
623
|
* @see waffo-pancake-order-service/app/lib/types.ts CreateCheckoutSessionRequest
|
|
614
624
|
*/
|
|
615
625
|
interface CreateCheckoutSessionParams {
|
|
616
|
-
/** Store ID */
|
|
617
|
-
storeId: string;
|
|
618
626
|
/** Product ID */
|
|
619
627
|
productId: string;
|
|
620
|
-
/** Product type */
|
|
621
|
-
productType: `${CheckoutSessionProductType}`;
|
|
622
628
|
/** Currency code (ISO 4217) */
|
|
623
629
|
currency: string;
|
|
624
630
|
/** Optional price snapshot override (reads from DB if omitted) */
|
|
@@ -745,20 +751,14 @@ interface RefundTicket {
|
|
|
745
751
|
*
|
|
746
752
|
* @example
|
|
747
753
|
* const result = await client.checkout.anonymous.create({
|
|
748
|
-
* storeId: "STO_xxx",
|
|
749
754
|
* productId: "PROD_xxx",
|
|
750
|
-
* productType: "onetime",
|
|
751
755
|
* currency: "USD",
|
|
752
756
|
* });
|
|
753
757
|
* // Redirect to result.checkoutUrl
|
|
754
758
|
*/
|
|
755
759
|
interface AnonymousCheckoutParams {
|
|
756
|
-
/** Store ID */
|
|
757
|
-
storeId: string;
|
|
758
760
|
/** Product ID */
|
|
759
761
|
productId: string;
|
|
760
|
-
/** Product type */
|
|
761
|
-
productType: `${CheckoutSessionProductType}`;
|
|
762
762
|
/** Currency code (ISO 4217) */
|
|
763
763
|
currency: string;
|
|
764
764
|
/** Optional price snapshot override (reads from DB if omitted) */
|
|
@@ -782,21 +782,15 @@ interface AnonymousCheckoutParams {
|
|
|
782
782
|
*
|
|
783
783
|
* @example
|
|
784
784
|
* const result = await client.checkout.authenticated.create({
|
|
785
|
-
* storeId: "STO_xxx",
|
|
786
785
|
* productId: "PROD_xxx",
|
|
787
|
-
* productType: "onetime",
|
|
788
786
|
* currency: "USD",
|
|
789
787
|
* buyerIdentity: "customer@example.com",
|
|
790
788
|
* });
|
|
791
789
|
* // Redirect to result.checkoutUrl (includes #token=...)
|
|
792
790
|
*/
|
|
793
791
|
interface AuthenticatedCheckoutParams {
|
|
794
|
-
/** Store ID */
|
|
795
|
-
storeId: string;
|
|
796
792
|
/** Product ID */
|
|
797
793
|
productId: string;
|
|
798
|
-
/** Product type */
|
|
799
|
-
productType: `${CheckoutSessionProductType}`;
|
|
800
794
|
/** Currency code (ISO 4217) */
|
|
801
795
|
currency: string;
|
|
802
796
|
/** Buyer identity (email or merchant-provided identifier) */
|
|
@@ -989,15 +983,19 @@ declare class HttpClient {
|
|
|
989
983
|
*
|
|
990
984
|
* Behavior:
|
|
991
985
|
* - Generates a deterministic `X-Idempotency-Key` from `merchantId + path + body` (same request produces same key)
|
|
986
|
+
* - When `idempotencyWindow` is set, a floored timestamp is mixed into the key so identical params produce
|
|
987
|
+
* a new key after the window elapses (useful for checkout where repeated creation is intentional)
|
|
992
988
|
* - Auto-builds RSA-SHA256 signature (`X-Merchant-Id` / `X-Timestamp` / `X-Signature`)
|
|
993
989
|
* - Unwraps the response envelope: returns `data` on success, throws `WaffoPancakeError` on failure
|
|
994
990
|
*
|
|
995
991
|
* @param path - API path (e.g. `/v1/actions/store/create-store`)
|
|
996
992
|
* @param body - Request body object
|
|
993
|
+
* @param options - Optional settings
|
|
994
|
+
* @param options.idempotencyWindow - Time window in seconds for idempotency key rotation (e.g. 60 = per-minute dedup)
|
|
997
995
|
* @returns Parsed `data` field from the response
|
|
998
996
|
* @throws {WaffoPancakeError} When the API returns errors
|
|
999
997
|
*/
|
|
1000
|
-
post<T>(path: string, body: object): Promise<T>;
|
|
998
|
+
post<T>(path: string, body: object, options?: PostOptions): Promise<T>;
|
|
1001
999
|
}
|
|
1002
1000
|
|
|
1003
1001
|
/** Authentication resource — issue session tokens for buyers. */
|
|
@@ -1011,10 +1009,18 @@ declare class AuthResource {
|
|
|
1011
1009
|
* @returns Issued session token with expiration
|
|
1012
1010
|
*
|
|
1013
1011
|
* @example
|
|
1012
|
+
* // By store ID
|
|
1014
1013
|
* const { token, expiresAt } = await client.auth.issueSessionToken({
|
|
1015
1014
|
* storeId: "STO_xxx",
|
|
1016
1015
|
* buyerIdentity: "customer@example.com",
|
|
1017
1016
|
* });
|
|
1017
|
+
*
|
|
1018
|
+
* @example
|
|
1019
|
+
* // By product ID (store derived automatically)
|
|
1020
|
+
* const { token, expiresAt } = await client.auth.issueSessionToken({
|
|
1021
|
+
* productId: "PROD_xxx",
|
|
1022
|
+
* buyerIdentity: "customer@example.com",
|
|
1023
|
+
* });
|
|
1018
1024
|
*/
|
|
1019
1025
|
issueSessionToken(params: IssueSessionTokenParams): Promise<SessionToken>;
|
|
1020
1026
|
}
|
|
@@ -1165,9 +1171,7 @@ declare class CheckoutAnonymousResource {
|
|
|
1165
1171
|
*
|
|
1166
1172
|
* @example
|
|
1167
1173
|
* const result = await client.checkout.anonymous.create({
|
|
1168
|
-
* storeId: "STO_xxx",
|
|
1169
1174
|
* productId: "PROD_xxx",
|
|
1170
|
-
* productType: "onetime",
|
|
1171
1175
|
* currency: "USD",
|
|
1172
1176
|
* });
|
|
1173
1177
|
* // Redirect to result.checkoutUrl
|
|
@@ -1199,9 +1203,7 @@ declare class CheckoutAuthenticatedResource {
|
|
|
1199
1203
|
*
|
|
1200
1204
|
* @example
|
|
1201
1205
|
* const result = await client.checkout.authenticated.create({
|
|
1202
|
-
* storeId: "STO_xxx",
|
|
1203
1206
|
* productId: "PROD_xxx",
|
|
1204
|
-
* productType: "onetime",
|
|
1205
1207
|
* currency: "USD",
|
|
1206
1208
|
* buyerIdentity: "customer@example.com",
|
|
1207
1209
|
* });
|
|
@@ -1222,18 +1224,14 @@ declare class CheckoutAuthenticatedResource {
|
|
|
1222
1224
|
* @example
|
|
1223
1225
|
* // Anonymous checkout (no identity)
|
|
1224
1226
|
* const result = await client.checkout.anonymous.create({
|
|
1225
|
-
* storeId: "STO_xxx",
|
|
1226
1227
|
* productId: "PROD_xxx",
|
|
1227
|
-
* productType: "onetime",
|
|
1228
1228
|
* currency: "USD",
|
|
1229
1229
|
* });
|
|
1230
1230
|
*
|
|
1231
1231
|
* @example
|
|
1232
1232
|
* // Authenticated checkout (with buyer identity)
|
|
1233
1233
|
* const result = await client.checkout.authenticated.create({
|
|
1234
|
-
* storeId: "STO_xxx",
|
|
1235
1234
|
* productId: "PROD_xxx",
|
|
1236
|
-
* productType: "onetime",
|
|
1237
1235
|
* currency: "USD",
|
|
1238
1236
|
* buyerIdentity: "customer@example.com",
|
|
1239
1237
|
* });
|
|
@@ -1257,9 +1255,7 @@ declare class CheckoutResource {
|
|
|
1257
1255
|
*
|
|
1258
1256
|
* @example
|
|
1259
1257
|
* const session = await client.checkout.createSession({
|
|
1260
|
-
* storeId: "STO_xxx",
|
|
1261
1258
|
* productId: "PROD_xxx",
|
|
1262
|
-
* productType: "onetime",
|
|
1263
1259
|
* currency: "USD",
|
|
1264
1260
|
* buyerEmail: "customer@example.com",
|
|
1265
1261
|
* });
|
|
@@ -1669,9 +1665,7 @@ declare class WebhooksResource {
|
|
|
1669
1665
|
*
|
|
1670
1666
|
* // Create a checkout session
|
|
1671
1667
|
* const session = await client.checkout.createSession({
|
|
1672
|
-
* storeId: store.id,
|
|
1673
1668
|
* productId: product.id,
|
|
1674
|
-
* productType: "onetime",
|
|
1675
1669
|
* currency: "USD",
|
|
1676
1670
|
* });
|
|
1677
1671
|
* // => redirect customer to session.checkoutUrl
|
|
@@ -1804,4 +1798,4 @@ declare class WaffoPancakeError extends Error {
|
|
|
1804
1798
|
*/
|
|
1805
1799
|
declare function verifyWebhook<T = Record<string, unknown>>(payload: string, signatureHeader: string | undefined | null, options?: VerifyWebhookOptions): WebhookEvent<T>;
|
|
1806
1800
|
|
|
1807
|
-
export { type AddMerchantParams, type AddMerchantResult, type AnonymousCheckoutParams, type ApiError, type ApiErrorResponse, type ApiResponse, type ApiSuccessResponse, type AuthenticatedCheckoutParams, type AuthenticatedCheckoutResult, type BillingDetail, BillingPeriod, type CancelOnetimeOrderParams, type CancelOnetimeOrderResult, type CancelSubscriptionParams, type CancelSubscriptionResult,
|
|
1801
|
+
export { type AddMerchantParams, type AddMerchantResult, type AnonymousCheckoutParams, type ApiError, type ApiErrorResponse, type ApiResponse, type ApiSuccessResponse, type AuthenticatedCheckoutParams, type AuthenticatedCheckoutResult, type BillingDetail, BillingPeriod, type CancelOnetimeOrderParams, type CancelOnetimeOrderResult, type CancelSubscriptionParams, type CancelSubscriptionResult, type CheckoutSessionResult, type CheckoutSettings, type CheckoutThemeSettings, type CreateCheckoutSessionParams, type CreateOnetimeProductParams, type CreateRefundTicketParams, type CreateStoreParams, type CreateSubscriptionProductGroupParams, type CreateSubscriptionProductParams, type DeleteStoreParams, type DeleteSubscriptionProductGroupParams, EntityStatus, Environment, ErrorLayer, type GraphQLParams, type GraphQLResponse, type GroupRules, type IssueSessionTokenParams, type MediaItem, MediaType, type NotificationSettings, OnetimeOrderStatus, type OnetimeProductDetail, PaymentStatus, type PriceInfo, type Prices, ProductVersionStatus, type PublishOnetimeProductParams, type PublishSubscriptionProductGroupParams, type PublishSubscriptionProductParams, type ReactivateSubscriptionParams, type ReactivateSubscriptionResult, RefundStatus, type RefundTicket, RefundTicketStatus, type RemoveMerchantParams, type RemoveMerchantResult, type RequestedAmount, type ResubmitRefundTicketParams, type SessionToken, type Store, StoreRole, SubscriptionOrderStatus, type SubscriptionProductDetail, type SubscriptionProductGroup, TaxCategory, type UpdateOnetimeProductParams, type UpdateOnetimeStatusParams, type UpdateRoleParams, type UpdateRoleResult, type UpdateStoreParams, type UpdateSubscriptionProductGroupParams, type UpdateSubscriptionProductParams, type UpdateSubscriptionStatusParams, type VerifyWebhookOptions, WaffoPancake, type WaffoPancakeConfig, WaffoPancakeError, type WebhookEvent, type WebhookEventData, WebhookEventType, type WebhookPublicKeys, type WebhookSettings, verifyWebhook };
|
package/dist/index.js
CHANGED
|
@@ -179,18 +179,26 @@ var HttpClient = class {
|
|
|
179
179
|
*
|
|
180
180
|
* Behavior:
|
|
181
181
|
* - Generates a deterministic `X-Idempotency-Key` from `merchantId + path + body` (same request produces same key)
|
|
182
|
+
* - When `idempotencyWindow` is set, a floored timestamp is mixed into the key so identical params produce
|
|
183
|
+
* a new key after the window elapses (useful for checkout where repeated creation is intentional)
|
|
182
184
|
* - Auto-builds RSA-SHA256 signature (`X-Merchant-Id` / `X-Timestamp` / `X-Signature`)
|
|
183
185
|
* - Unwraps the response envelope: returns `data` on success, throws `WaffoPancakeError` on failure
|
|
184
186
|
*
|
|
185
187
|
* @param path - API path (e.g. `/v1/actions/store/create-store`)
|
|
186
188
|
* @param body - Request body object
|
|
189
|
+
* @param options - Optional settings
|
|
190
|
+
* @param options.idempotencyWindow - Time window in seconds for idempotency key rotation (e.g. 60 = per-minute dedup)
|
|
187
191
|
* @returns Parsed `data` field from the response
|
|
188
192
|
* @throws {WaffoPancakeError} When the API returns errors
|
|
189
193
|
*/
|
|
190
|
-
async post(path, body) {
|
|
194
|
+
async post(path, body, options) {
|
|
191
195
|
const bodyStr = JSON.stringify(body);
|
|
192
|
-
const
|
|
196
|
+
const now = Date.now();
|
|
197
|
+
const timestampSec = Math.floor(now / 1e3);
|
|
198
|
+
const timestamp = timestampSec.toString();
|
|
193
199
|
const signature = signRequest("POST", path, timestamp, bodyStr, this.privateKey);
|
|
200
|
+
const idempotencyBase = `${this.merchantId}:${path}:${bodyStr}`;
|
|
201
|
+
const idempotencyInput = options?.idempotencyWindow ? `${idempotencyBase}:${Math.floor(timestampSec / options.idempotencyWindow)}` : idempotencyBase;
|
|
194
202
|
const response = await this._fetch(`${this.baseUrl}${path}`, {
|
|
195
203
|
method: "POST",
|
|
196
204
|
headers: {
|
|
@@ -198,7 +206,7 @@ var HttpClient = class {
|
|
|
198
206
|
"X-Merchant-Id": this.merchantId,
|
|
199
207
|
"X-Timestamp": timestamp,
|
|
200
208
|
"X-Signature": signature,
|
|
201
|
-
"X-Idempotency-Key": createHash2("sha256").update(
|
|
209
|
+
"X-Idempotency-Key": createHash2("sha256").update(idempotencyInput).digest("hex")
|
|
202
210
|
},
|
|
203
211
|
body: bodyStr
|
|
204
212
|
});
|
|
@@ -293,9 +301,7 @@ function validateBillingDetail(detail) {
|
|
|
293
301
|
}
|
|
294
302
|
}
|
|
295
303
|
function validateCheckoutCommon(params) {
|
|
296
|
-
validateShortId("storeId", params.storeId, "STO");
|
|
297
304
|
validateShortId("productId", params.productId, "PROD");
|
|
298
|
-
validateEnum("productType", params.productType, ["onetime", "subscription"]);
|
|
299
305
|
validateCurrencyCode("currency", params.currency);
|
|
300
306
|
if (params.priceSnapshot) {
|
|
301
307
|
validateAmountString("priceSnapshot.amount", params.priceSnapshot.amount);
|
|
@@ -321,13 +327,31 @@ var AuthResource = class {
|
|
|
321
327
|
* @returns Issued session token with expiration
|
|
322
328
|
*
|
|
323
329
|
* @example
|
|
330
|
+
* // By store ID
|
|
324
331
|
* const { token, expiresAt } = await client.auth.issueSessionToken({
|
|
325
332
|
* storeId: "STO_xxx",
|
|
326
333
|
* buyerIdentity: "customer@example.com",
|
|
327
334
|
* });
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* // By product ID (store derived automatically)
|
|
338
|
+
* const { token, expiresAt } = await client.auth.issueSessionToken({
|
|
339
|
+
* productId: "PROD_xxx",
|
|
340
|
+
* buyerIdentity: "customer@example.com",
|
|
341
|
+
* });
|
|
328
342
|
*/
|
|
329
343
|
async issueSessionToken(params) {
|
|
330
|
-
|
|
344
|
+
if (!params.storeId && !params.productId) {
|
|
345
|
+
throw new WaffoPancakeError(400, [
|
|
346
|
+
{ message: "Missing required field: provide storeId or productId", layer: "sdk" }
|
|
347
|
+
]);
|
|
348
|
+
}
|
|
349
|
+
if (params.storeId) {
|
|
350
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
351
|
+
}
|
|
352
|
+
if (params.productId) {
|
|
353
|
+
validateShortId("productId", params.productId, "PROD");
|
|
354
|
+
}
|
|
331
355
|
validateRequired("buyerIdentity", params.buyerIdentity);
|
|
332
356
|
return this.http.post("/v1/actions/auth/issue-session-token", params);
|
|
333
357
|
}
|
|
@@ -474,9 +498,7 @@ var CheckoutAnonymousResource = class {
|
|
|
474
498
|
*
|
|
475
499
|
* @example
|
|
476
500
|
* const result = await client.checkout.anonymous.create({
|
|
477
|
-
* storeId: "STO_xxx",
|
|
478
501
|
* productId: "PROD_xxx",
|
|
479
|
-
* productType: "onetime",
|
|
480
502
|
* currency: "USD",
|
|
481
503
|
* });
|
|
482
504
|
* // Redirect to result.checkoutUrl
|
|
@@ -485,7 +507,8 @@ var CheckoutAnonymousResource = class {
|
|
|
485
507
|
validateCheckoutCommon(params);
|
|
486
508
|
return this.http.post(
|
|
487
509
|
"/v1/actions/checkout/create-session",
|
|
488
|
-
params
|
|
510
|
+
params,
|
|
511
|
+
{ idempotencyWindow: 60 }
|
|
489
512
|
);
|
|
490
513
|
}
|
|
491
514
|
};
|
|
@@ -509,9 +532,7 @@ var CheckoutAuthenticatedResource = class {
|
|
|
509
532
|
*
|
|
510
533
|
* @example
|
|
511
534
|
* const result = await client.checkout.authenticated.create({
|
|
512
|
-
* storeId: "STO_xxx",
|
|
513
535
|
* productId: "PROD_xxx",
|
|
514
|
-
* productType: "onetime",
|
|
515
536
|
* currency: "USD",
|
|
516
537
|
* buyerIdentity: "customer@example.com",
|
|
517
538
|
* });
|
|
@@ -523,13 +544,13 @@ var CheckoutAuthenticatedResource = class {
|
|
|
523
544
|
const { buyerIdentity, buyerEmail, ...sessionFields } = params;
|
|
524
545
|
const [tokenResult, sessionResult] = await Promise.all([
|
|
525
546
|
this.http.post("/v1/actions/auth/issue-session-token", {
|
|
526
|
-
|
|
547
|
+
productId: params.productId,
|
|
527
548
|
buyerIdentity
|
|
528
|
-
}),
|
|
549
|
+
}, { idempotencyWindow: 60 }),
|
|
529
550
|
this.http.post("/v1/actions/checkout/create-session", {
|
|
530
551
|
...sessionFields,
|
|
531
552
|
buyerEmail: buyerEmail ?? buyerIdentity
|
|
532
|
-
})
|
|
553
|
+
}, { idempotencyWindow: 60 })
|
|
533
554
|
]);
|
|
534
555
|
return {
|
|
535
556
|
sessionId: sessionResult.sessionId,
|
|
@@ -563,16 +584,14 @@ var CheckoutResource = class {
|
|
|
563
584
|
*
|
|
564
585
|
* @example
|
|
565
586
|
* const session = await client.checkout.createSession({
|
|
566
|
-
* storeId: "STO_xxx",
|
|
567
587
|
* productId: "PROD_xxx",
|
|
568
|
-
* productType: "onetime",
|
|
569
588
|
* currency: "USD",
|
|
570
589
|
* buyerEmail: "customer@example.com",
|
|
571
590
|
* });
|
|
572
591
|
* // Redirect to session.checkoutUrl
|
|
573
592
|
*/
|
|
574
593
|
async createSession(params) {
|
|
575
|
-
return this.http.post("/v1/actions/checkout/create-session", params);
|
|
594
|
+
return this.http.post("/v1/actions/checkout/create-session", params, { idempotencyWindow: 60 });
|
|
576
595
|
}
|
|
577
596
|
};
|
|
578
597
|
|
|
@@ -1248,11 +1267,6 @@ var MediaType = /* @__PURE__ */ ((MediaType2) => {
|
|
|
1248
1267
|
MediaType2["Video"] = "video";
|
|
1249
1268
|
return MediaType2;
|
|
1250
1269
|
})(MediaType || {});
|
|
1251
|
-
var CheckoutSessionProductType = /* @__PURE__ */ ((CheckoutSessionProductType2) => {
|
|
1252
|
-
CheckoutSessionProductType2["Onetime"] = "onetime";
|
|
1253
|
-
CheckoutSessionProductType2["Subscription"] = "subscription";
|
|
1254
|
-
return CheckoutSessionProductType2;
|
|
1255
|
-
})(CheckoutSessionProductType || {});
|
|
1256
1270
|
var ErrorLayer = /* @__PURE__ */ ((ErrorLayer2) => {
|
|
1257
1271
|
ErrorLayer2["Gateway"] = "gateway";
|
|
1258
1272
|
ErrorLayer2["User"] = "user";
|
|
@@ -1281,7 +1295,6 @@ var WebhookEventType = /* @__PURE__ */ ((WebhookEventType2) => {
|
|
|
1281
1295
|
})(WebhookEventType || {});
|
|
1282
1296
|
export {
|
|
1283
1297
|
BillingPeriod,
|
|
1284
|
-
CheckoutSessionProductType,
|
|
1285
1298
|
EntityStatus,
|
|
1286
1299
|
Environment,
|
|
1287
1300
|
ErrorLayer,
|