@waffo/pancake-ts 0.17.0 → 0.19.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 +35 -0
- package/README.md +14 -12
- package/dist/index.cjs +40 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -9
- package/dist/index.d.ts +87 -9
- package/dist/index.js +40 -9
- package/dist/index.js.map +1 -1
- package/docs/api-reference.md +15 -2
- package/docs/webhook-guide.md +20 -9
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -7,6 +7,21 @@ interface WaffoPancakeConfig {
|
|
|
7
7
|
baseUrl?: string;
|
|
8
8
|
/** Custom fetch implementation (default: global fetch) */
|
|
9
9
|
fetch?: typeof fetch;
|
|
10
|
+
/**
|
|
11
|
+
* Environment that customer sessions operate in (sent as the `X-Environment`
|
|
12
|
+
* header alongside the session token's Bearer credential).
|
|
13
|
+
*
|
|
14
|
+
* API Key requests do not need this — the gateway derives their environment
|
|
15
|
+
* from the key itself. Session tokens carry no environment, so the gateway
|
|
16
|
+
* requires the header and rejects the request with HTTP 400 without it.
|
|
17
|
+
*
|
|
18
|
+
* There is no default: a wrong guess would route the call to the other
|
|
19
|
+
* environment. Supply it here, or per session via
|
|
20
|
+
* {@link CustomerSessionOptions.environment}.
|
|
21
|
+
*
|
|
22
|
+
* @see {@link WaffoPancake.customer}
|
|
23
|
+
*/
|
|
24
|
+
environment?: `${Environment}`;
|
|
10
25
|
/**
|
|
11
26
|
* Custom RSA public key(s) for webhook signature verification.
|
|
12
27
|
*
|
|
@@ -18,6 +33,16 @@ interface WaffoPancakeConfig {
|
|
|
18
33
|
*/
|
|
19
34
|
webhookPublicKey?: WebhookPublicKeys;
|
|
20
35
|
}
|
|
36
|
+
/** Options for {@link WaffoPancake.customer}. */
|
|
37
|
+
interface CustomerSessionOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Environment this session operates in, overriding
|
|
40
|
+
* {@link WaffoPancakeConfig.environment} for a single session.
|
|
41
|
+
*
|
|
42
|
+
* Required when the client config omits `environment`.
|
|
43
|
+
*/
|
|
44
|
+
environment?: `${Environment}`;
|
|
45
|
+
}
|
|
21
46
|
/**
|
|
22
47
|
* Options for {@link HttpClient.post}.
|
|
23
48
|
* Not exported publicly — used by resource classes.
|
|
@@ -480,12 +505,18 @@ interface UpdateRoleResult {
|
|
|
480
505
|
* @example
|
|
481
506
|
* // JPY ¥1000
|
|
482
507
|
* { amount: "1000", taxCategory: "software" }
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* // USD $9.99 with a $1.00 trial period (subscription products only)
|
|
511
|
+
* { amount: "9.99", taxCategory: "saas", trialAmount: "1.00" }
|
|
483
512
|
*/
|
|
484
513
|
interface PriceInfo {
|
|
485
514
|
/** Price amount as display string (e.g., "9.99" for USD, "1000" for JPY) */
|
|
486
515
|
amount: string;
|
|
487
516
|
/** Tax category */
|
|
488
517
|
taxCategory: TaxCategory;
|
|
518
|
+
/** Trial period price as display string; requires `metadata.trialDays` and must be lower than `amount` */
|
|
519
|
+
trialAmount?: string;
|
|
489
520
|
}
|
|
490
521
|
/**
|
|
491
522
|
* Multi-currency prices (keyed by ISO 4217 currency code).
|
|
@@ -732,6 +763,17 @@ type CashierLanguage = "en" | "pt-BR" | "es-MX" | "id-ID" | "vi-VN" | "ru-RU" |
|
|
|
732
763
|
* Currencies outside this matrix cannot be charged at all — checkout session creation is rejected with a 400.
|
|
733
764
|
*/
|
|
734
765
|
type PaymentMethod = "card" | "applepay" | "googlepay" | "wechat";
|
|
766
|
+
/**
|
|
767
|
+
* Session-level price override, accepted with API Key authentication only.
|
|
768
|
+
* For subscription products it replaces the regular period price; the trial price comes from the locked product version.
|
|
769
|
+
* @see docs/api-reference/endpoints/orders/create-checkout-session.mdx
|
|
770
|
+
*/
|
|
771
|
+
interface PriceSnapshot {
|
|
772
|
+
/** Price amount as display string (e.g., "9.99" for USD, "1000" for JPY) */
|
|
773
|
+
amount: string;
|
|
774
|
+
/** Tax category */
|
|
775
|
+
taxCategory: TaxCategory;
|
|
776
|
+
}
|
|
735
777
|
/**
|
|
736
778
|
* Parameters for creating a checkout session.
|
|
737
779
|
* @see docs/api-reference/endpoints/orders/create-checkout-session.mdx
|
|
@@ -742,7 +784,7 @@ interface CreateCheckoutSessionParams {
|
|
|
742
784
|
/** Currency code (ISO 4217) */
|
|
743
785
|
currency: string;
|
|
744
786
|
/** Optional price snapshot override (reads from DB if omitted) */
|
|
745
|
-
priceSnapshot?:
|
|
787
|
+
priceSnapshot?: PriceSnapshot;
|
|
746
788
|
/** Trial toggle override (subscription only) */
|
|
747
789
|
withTrial?: boolean;
|
|
748
790
|
/** Pre-filled customer email */
|
|
@@ -1127,11 +1169,27 @@ interface VerifyWebhookOptions {
|
|
|
1127
1169
|
*/
|
|
1128
1170
|
environment?: `${Environment}`;
|
|
1129
1171
|
/**
|
|
1130
|
-
*
|
|
1131
|
-
* Set to 0 to skip timestamp checking
|
|
1132
|
-
* @
|
|
1172
|
+
* How far in the past a signature timestamp may be, in milliseconds.
|
|
1173
|
+
* Set to 0 to skip timestamp checking entirely (this also skips
|
|
1174
|
+
* {@link futureToleranceMs}).
|
|
1175
|
+
*
|
|
1176
|
+
* The default covers the full delivery retry schedule: the timestamp is
|
|
1177
|
+
* stamped before the first attempt and retries reuse it, so the last retry
|
|
1178
|
+
* arrives with a timestamp as old as the schedule itself.
|
|
1179
|
+
*
|
|
1180
|
+
* @default 2700000 (45 minutes)
|
|
1133
1181
|
*/
|
|
1134
1182
|
toleranceMs?: number;
|
|
1183
|
+
/**
|
|
1184
|
+
* How far in the future a signature timestamp may be, in milliseconds.
|
|
1185
|
+
* Only clock skew on the receiving server puts a timestamp ahead of now, so
|
|
1186
|
+
* this stays tight — it matches the gateway's API Key check.
|
|
1187
|
+
*
|
|
1188
|
+
* Ignored when `toleranceMs` is 0.
|
|
1189
|
+
*
|
|
1190
|
+
* @default 60000 (1 minute)
|
|
1191
|
+
*/
|
|
1192
|
+
futureToleranceMs?: number;
|
|
1135
1193
|
/**
|
|
1136
1194
|
* Per-call public key override (highest priority).
|
|
1137
1195
|
* When provided, skips all other key resolution (config, env vars, built-in).
|
|
@@ -1462,16 +1520,24 @@ declare class ContentSafetyResource {
|
|
|
1462
1520
|
* never sends an idempotency key (customer session actions are not protected by
|
|
1463
1521
|
* gateway idempotency in the current architecture).
|
|
1464
1522
|
*
|
|
1523
|
+
* Session tokens carry no environment of their own, so every request also sends
|
|
1524
|
+
* `X-Environment`. The gateway treats a Bearer credential without it as an
|
|
1525
|
+
* incomplete JWT header set and answers HTTP 400.
|
|
1526
|
+
*
|
|
1465
1527
|
* Not exported publicly — used internally by {@link CustomerSession}.
|
|
1466
1528
|
*/
|
|
1467
1529
|
declare class CustomerHttpClient {
|
|
1468
1530
|
private readonly token;
|
|
1531
|
+
private readonly environment;
|
|
1469
1532
|
private readonly baseUrl;
|
|
1470
1533
|
private readonly _fetch;
|
|
1471
|
-
constructor(token: string, config: Pick<WaffoPancakeConfig, "baseUrl" | "fetch">);
|
|
1534
|
+
constructor(token: string, environment: `${Environment}`, config: Pick<WaffoPancakeConfig, "baseUrl" | "fetch">);
|
|
1472
1535
|
/**
|
|
1473
1536
|
* Send a Bearer-authenticated POST and return the full envelope plus HTTP status.
|
|
1474
1537
|
*
|
|
1538
|
+
* Sends `Authorization: Bearer <token>` and `X-Environment` — the gateway
|
|
1539
|
+
* requires both to accept a session token.
|
|
1540
|
+
*
|
|
1475
1541
|
* Does NOT throw on `errors[]` or non-2xx status — caller inspects the result.
|
|
1476
1542
|
* Throws {@link WaffoPancakeError} only when the response body is not valid JSON.
|
|
1477
1543
|
*/
|
|
@@ -2174,22 +2240,34 @@ declare class WaffoPancake {
|
|
|
2174
2240
|
* methods for order cancellation, subscription management, refund tickets,
|
|
2175
2241
|
* and scoped GraphQL queries.
|
|
2176
2242
|
*
|
|
2243
|
+
* Session tokens expire 5 minutes after issuance, so issue one right before
|
|
2244
|
+
* use rather than caching it.
|
|
2245
|
+
*
|
|
2177
2246
|
* @param token - Session token from `client.auth.issueSessionToken()`
|
|
2247
|
+
* @param options - Per-session overrides
|
|
2178
2248
|
* @returns A customer session with self-service methods
|
|
2249
|
+
* @throws {WaffoPancakeError} When no environment is available from either
|
|
2250
|
+
* `options.environment` or `WaffoPancakeConfig.environment`
|
|
2179
2251
|
*
|
|
2180
2252
|
* @example
|
|
2181
2253
|
* const { token } = await client.auth.issueSessionToken({
|
|
2182
2254
|
* storeId: "STO_xxx",
|
|
2183
2255
|
* buyerIdentity: "customer@example.com",
|
|
2184
2256
|
* });
|
|
2185
|
-
* const customer = client.customer(token);
|
|
2257
|
+
* const customer = client.customer(token, { environment: "test" });
|
|
2186
2258
|
* await customer.cancelSubscription({ orderId: "ORD_xxx" });
|
|
2259
|
+
*
|
|
2260
|
+
* @example
|
|
2261
|
+
* // Set the environment once on the client instead
|
|
2262
|
+
* const client = new WaffoPancake({ merchantId, privateKey, environment: "test" });
|
|
2263
|
+
* const customer = client.customer(token);
|
|
2187
2264
|
*/
|
|
2188
|
-
customer(token: string): CustomerSession;
|
|
2265
|
+
customer(token: string, options?: CustomerSessionOptions): CustomerSession;
|
|
2189
2266
|
/**
|
|
2190
2267
|
* Create a customer session for self-service operations.
|
|
2191
2268
|
*
|
|
2192
2269
|
* @param token - Session token from `client.auth.issueSessionToken()`
|
|
2270
|
+
* @param options - Per-session overrides
|
|
2193
2271
|
* @returns A customer session with self-service methods
|
|
2194
2272
|
*
|
|
2195
2273
|
* @example
|
|
@@ -2199,7 +2277,7 @@ declare class WaffoPancake {
|
|
|
2199
2277
|
*
|
|
2200
2278
|
* @deprecated Use {@link WaffoPancake.customer} instead.
|
|
2201
2279
|
*/
|
|
2202
|
-
buyer(token: string): CustomerSession;
|
|
2280
|
+
buyer(token: string, options?: CustomerSessionOptions): CustomerSession;
|
|
2203
2281
|
}
|
|
2204
2282
|
|
|
2205
2283
|
/**
|
|
@@ -2278,4 +2356,4 @@ declare class WaffoPancakeError extends Error {
|
|
|
2278
2356
|
*/
|
|
2279
2357
|
declare function verifyWebhook<T = Record<string, unknown>>(payload: string, signatureHeader: string | undefined | null, options?: VerifyWebhookOptions): WebhookEvent<T>;
|
|
2280
2358
|
|
|
2281
|
-
export { type AddMerchantParams, type AddMerchantResult, type AddWebhookParams, type AnonymousCheckoutParams, type ApiError, type AuthenticatedCheckoutParams, type AuthenticatedCheckoutResult, type BillingDetail, BillingPeriod, type CancelOnetimeOrderParams, type CancelOnetimeOrderResult, type CancelSubscriptionParams, type CancelSubscriptionResult, type CashierLanguage, type CheckoutSessionResult, type CheckoutSettings, type CheckoutThemeSettings, type CreateCheckoutSessionParams, type CreateOnetimeProductParams, type CreateRefundTicketParams, type CreateStoreParams, type CreateSubscriptionProductGroupParams, type CreateSubscriptionProductParams, type DeleteStoreParams, type DeleteSubscriptionProductGroupParams, EntityStatus, type Envelope, Environment, ErrorLayer, type GraphQLParams, type GraphQLResponse, type GroupRules, type IssueSessionTokenParams, type MediaItem, MediaType, type MerchantWritableNotificationSettings, type Notice, type NotificationSettings, OnetimeOrderStatus, type OnetimeProductDetail, type PaymentMethod, PaymentStatus, type PostResult, type PriceInfo, type Prices, ProductVersionStatus, type PublishOnetimeProductParams, type PublishSubscriptionProductGroupParams, type PublishSubscriptionProductParams, type ReactivateSubscriptionParams, type ReactivateSubscriptionResult, RefundStatus, type RefundTicket, RefundTicketStatus, type RefundTicketVersionData, type RemoveMerchantParams, type RemoveMerchantResult, type RemoveWebhookParams, type RequestedAmount, type ResubmitRefundTicketParams, ScanAction, ScanPolicyCategory, type ScanPromptParams, ScanReasonCode, type ScanResult, ScanSemanticMode, ScanSemanticStatus, type SessionToken, type Store, StoreRole, type StoreWebhook, SubscriptionOrderStatus, type SubscriptionProductDetail, type SubscriptionProductGroup, TaxCategory, type UpdateOnetimeProductParams, type UpdateOnetimeStatusParams, type UpdateRoleParams, type UpdateRoleResult, type UpdateStoreParams, type UpdateSubscriptionProductGroupParams, type UpdateSubscriptionProductParams, type UpdateSubscriptionStatusParams, type UpdateWebhookParams, type VerifyWebhookOptions, WaffoPancake, type WaffoPancakeConfig, WaffoPancakeError, type WebhookChannel, type WebhookEvent, type WebhookEventData, WebhookEventType, type WebhookPublicKeys, verifyWebhook };
|
|
2359
|
+
export { type AddMerchantParams, type AddMerchantResult, type AddWebhookParams, type AnonymousCheckoutParams, type ApiError, type AuthenticatedCheckoutParams, type AuthenticatedCheckoutResult, type BillingDetail, BillingPeriod, type CancelOnetimeOrderParams, type CancelOnetimeOrderResult, type CancelSubscriptionParams, type CancelSubscriptionResult, type CashierLanguage, type CheckoutSessionResult, type CheckoutSettings, type CheckoutThemeSettings, type CreateCheckoutSessionParams, type CreateOnetimeProductParams, type CreateRefundTicketParams, type CreateStoreParams, type CreateSubscriptionProductGroupParams, type CreateSubscriptionProductParams, type CustomerSessionOptions, type DeleteStoreParams, type DeleteSubscriptionProductGroupParams, EntityStatus, type Envelope, Environment, ErrorLayer, type GraphQLParams, type GraphQLResponse, type GroupRules, type IssueSessionTokenParams, type MediaItem, MediaType, type MerchantWritableNotificationSettings, type Notice, type NotificationSettings, OnetimeOrderStatus, type OnetimeProductDetail, type PaymentMethod, PaymentStatus, type PostResult, type PriceInfo, type PriceSnapshot, type Prices, ProductVersionStatus, type PublishOnetimeProductParams, type PublishSubscriptionProductGroupParams, type PublishSubscriptionProductParams, type ReactivateSubscriptionParams, type ReactivateSubscriptionResult, RefundStatus, type RefundTicket, RefundTicketStatus, type RefundTicketVersionData, type RemoveMerchantParams, type RemoveMerchantResult, type RemoveWebhookParams, type RequestedAmount, type ResubmitRefundTicketParams, ScanAction, ScanPolicyCategory, type ScanPromptParams, ScanReasonCode, type ScanResult, ScanSemanticMode, ScanSemanticStatus, type SessionToken, type Store, StoreRole, type StoreWebhook, SubscriptionOrderStatus, type SubscriptionProductDetail, type SubscriptionProductGroup, TaxCategory, type UpdateOnetimeProductParams, type UpdateOnetimeStatusParams, type UpdateRoleParams, type UpdateRoleResult, type UpdateStoreParams, type UpdateSubscriptionProductGroupParams, type UpdateSubscriptionProductParams, type UpdateSubscriptionStatusParams, type UpdateWebhookParams, type VerifyWebhookOptions, WaffoPancake, type WaffoPancakeConfig, WaffoPancakeError, type WebhookChannel, type WebhookEvent, type WebhookEventData, WebhookEventType, type WebhookPublicKeys, verifyWebhook };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,21 @@ interface WaffoPancakeConfig {
|
|
|
7
7
|
baseUrl?: string;
|
|
8
8
|
/** Custom fetch implementation (default: global fetch) */
|
|
9
9
|
fetch?: typeof fetch;
|
|
10
|
+
/**
|
|
11
|
+
* Environment that customer sessions operate in (sent as the `X-Environment`
|
|
12
|
+
* header alongside the session token's Bearer credential).
|
|
13
|
+
*
|
|
14
|
+
* API Key requests do not need this — the gateway derives their environment
|
|
15
|
+
* from the key itself. Session tokens carry no environment, so the gateway
|
|
16
|
+
* requires the header and rejects the request with HTTP 400 without it.
|
|
17
|
+
*
|
|
18
|
+
* There is no default: a wrong guess would route the call to the other
|
|
19
|
+
* environment. Supply it here, or per session via
|
|
20
|
+
* {@link CustomerSessionOptions.environment}.
|
|
21
|
+
*
|
|
22
|
+
* @see {@link WaffoPancake.customer}
|
|
23
|
+
*/
|
|
24
|
+
environment?: `${Environment}`;
|
|
10
25
|
/**
|
|
11
26
|
* Custom RSA public key(s) for webhook signature verification.
|
|
12
27
|
*
|
|
@@ -18,6 +33,16 @@ interface WaffoPancakeConfig {
|
|
|
18
33
|
*/
|
|
19
34
|
webhookPublicKey?: WebhookPublicKeys;
|
|
20
35
|
}
|
|
36
|
+
/** Options for {@link WaffoPancake.customer}. */
|
|
37
|
+
interface CustomerSessionOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Environment this session operates in, overriding
|
|
40
|
+
* {@link WaffoPancakeConfig.environment} for a single session.
|
|
41
|
+
*
|
|
42
|
+
* Required when the client config omits `environment`.
|
|
43
|
+
*/
|
|
44
|
+
environment?: `${Environment}`;
|
|
45
|
+
}
|
|
21
46
|
/**
|
|
22
47
|
* Options for {@link HttpClient.post}.
|
|
23
48
|
* Not exported publicly — used by resource classes.
|
|
@@ -480,12 +505,18 @@ interface UpdateRoleResult {
|
|
|
480
505
|
* @example
|
|
481
506
|
* // JPY ¥1000
|
|
482
507
|
* { amount: "1000", taxCategory: "software" }
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* // USD $9.99 with a $1.00 trial period (subscription products only)
|
|
511
|
+
* { amount: "9.99", taxCategory: "saas", trialAmount: "1.00" }
|
|
483
512
|
*/
|
|
484
513
|
interface PriceInfo {
|
|
485
514
|
/** Price amount as display string (e.g., "9.99" for USD, "1000" for JPY) */
|
|
486
515
|
amount: string;
|
|
487
516
|
/** Tax category */
|
|
488
517
|
taxCategory: TaxCategory;
|
|
518
|
+
/** Trial period price as display string; requires `metadata.trialDays` and must be lower than `amount` */
|
|
519
|
+
trialAmount?: string;
|
|
489
520
|
}
|
|
490
521
|
/**
|
|
491
522
|
* Multi-currency prices (keyed by ISO 4217 currency code).
|
|
@@ -732,6 +763,17 @@ type CashierLanguage = "en" | "pt-BR" | "es-MX" | "id-ID" | "vi-VN" | "ru-RU" |
|
|
|
732
763
|
* Currencies outside this matrix cannot be charged at all — checkout session creation is rejected with a 400.
|
|
733
764
|
*/
|
|
734
765
|
type PaymentMethod = "card" | "applepay" | "googlepay" | "wechat";
|
|
766
|
+
/**
|
|
767
|
+
* Session-level price override, accepted with API Key authentication only.
|
|
768
|
+
* For subscription products it replaces the regular period price; the trial price comes from the locked product version.
|
|
769
|
+
* @see docs/api-reference/endpoints/orders/create-checkout-session.mdx
|
|
770
|
+
*/
|
|
771
|
+
interface PriceSnapshot {
|
|
772
|
+
/** Price amount as display string (e.g., "9.99" for USD, "1000" for JPY) */
|
|
773
|
+
amount: string;
|
|
774
|
+
/** Tax category */
|
|
775
|
+
taxCategory: TaxCategory;
|
|
776
|
+
}
|
|
735
777
|
/**
|
|
736
778
|
* Parameters for creating a checkout session.
|
|
737
779
|
* @see docs/api-reference/endpoints/orders/create-checkout-session.mdx
|
|
@@ -742,7 +784,7 @@ interface CreateCheckoutSessionParams {
|
|
|
742
784
|
/** Currency code (ISO 4217) */
|
|
743
785
|
currency: string;
|
|
744
786
|
/** Optional price snapshot override (reads from DB if omitted) */
|
|
745
|
-
priceSnapshot?:
|
|
787
|
+
priceSnapshot?: PriceSnapshot;
|
|
746
788
|
/** Trial toggle override (subscription only) */
|
|
747
789
|
withTrial?: boolean;
|
|
748
790
|
/** Pre-filled customer email */
|
|
@@ -1127,11 +1169,27 @@ interface VerifyWebhookOptions {
|
|
|
1127
1169
|
*/
|
|
1128
1170
|
environment?: `${Environment}`;
|
|
1129
1171
|
/**
|
|
1130
|
-
*
|
|
1131
|
-
* Set to 0 to skip timestamp checking
|
|
1132
|
-
* @
|
|
1172
|
+
* How far in the past a signature timestamp may be, in milliseconds.
|
|
1173
|
+
* Set to 0 to skip timestamp checking entirely (this also skips
|
|
1174
|
+
* {@link futureToleranceMs}).
|
|
1175
|
+
*
|
|
1176
|
+
* The default covers the full delivery retry schedule: the timestamp is
|
|
1177
|
+
* stamped before the first attempt and retries reuse it, so the last retry
|
|
1178
|
+
* arrives with a timestamp as old as the schedule itself.
|
|
1179
|
+
*
|
|
1180
|
+
* @default 2700000 (45 minutes)
|
|
1133
1181
|
*/
|
|
1134
1182
|
toleranceMs?: number;
|
|
1183
|
+
/**
|
|
1184
|
+
* How far in the future a signature timestamp may be, in milliseconds.
|
|
1185
|
+
* Only clock skew on the receiving server puts a timestamp ahead of now, so
|
|
1186
|
+
* this stays tight — it matches the gateway's API Key check.
|
|
1187
|
+
*
|
|
1188
|
+
* Ignored when `toleranceMs` is 0.
|
|
1189
|
+
*
|
|
1190
|
+
* @default 60000 (1 minute)
|
|
1191
|
+
*/
|
|
1192
|
+
futureToleranceMs?: number;
|
|
1135
1193
|
/**
|
|
1136
1194
|
* Per-call public key override (highest priority).
|
|
1137
1195
|
* When provided, skips all other key resolution (config, env vars, built-in).
|
|
@@ -1462,16 +1520,24 @@ declare class ContentSafetyResource {
|
|
|
1462
1520
|
* never sends an idempotency key (customer session actions are not protected by
|
|
1463
1521
|
* gateway idempotency in the current architecture).
|
|
1464
1522
|
*
|
|
1523
|
+
* Session tokens carry no environment of their own, so every request also sends
|
|
1524
|
+
* `X-Environment`. The gateway treats a Bearer credential without it as an
|
|
1525
|
+
* incomplete JWT header set and answers HTTP 400.
|
|
1526
|
+
*
|
|
1465
1527
|
* Not exported publicly — used internally by {@link CustomerSession}.
|
|
1466
1528
|
*/
|
|
1467
1529
|
declare class CustomerHttpClient {
|
|
1468
1530
|
private readonly token;
|
|
1531
|
+
private readonly environment;
|
|
1469
1532
|
private readonly baseUrl;
|
|
1470
1533
|
private readonly _fetch;
|
|
1471
|
-
constructor(token: string, config: Pick<WaffoPancakeConfig, "baseUrl" | "fetch">);
|
|
1534
|
+
constructor(token: string, environment: `${Environment}`, config: Pick<WaffoPancakeConfig, "baseUrl" | "fetch">);
|
|
1472
1535
|
/**
|
|
1473
1536
|
* Send a Bearer-authenticated POST and return the full envelope plus HTTP status.
|
|
1474
1537
|
*
|
|
1538
|
+
* Sends `Authorization: Bearer <token>` and `X-Environment` — the gateway
|
|
1539
|
+
* requires both to accept a session token.
|
|
1540
|
+
*
|
|
1475
1541
|
* Does NOT throw on `errors[]` or non-2xx status — caller inspects the result.
|
|
1476
1542
|
* Throws {@link WaffoPancakeError} only when the response body is not valid JSON.
|
|
1477
1543
|
*/
|
|
@@ -2174,22 +2240,34 @@ declare class WaffoPancake {
|
|
|
2174
2240
|
* methods for order cancellation, subscription management, refund tickets,
|
|
2175
2241
|
* and scoped GraphQL queries.
|
|
2176
2242
|
*
|
|
2243
|
+
* Session tokens expire 5 minutes after issuance, so issue one right before
|
|
2244
|
+
* use rather than caching it.
|
|
2245
|
+
*
|
|
2177
2246
|
* @param token - Session token from `client.auth.issueSessionToken()`
|
|
2247
|
+
* @param options - Per-session overrides
|
|
2178
2248
|
* @returns A customer session with self-service methods
|
|
2249
|
+
* @throws {WaffoPancakeError} When no environment is available from either
|
|
2250
|
+
* `options.environment` or `WaffoPancakeConfig.environment`
|
|
2179
2251
|
*
|
|
2180
2252
|
* @example
|
|
2181
2253
|
* const { token } = await client.auth.issueSessionToken({
|
|
2182
2254
|
* storeId: "STO_xxx",
|
|
2183
2255
|
* buyerIdentity: "customer@example.com",
|
|
2184
2256
|
* });
|
|
2185
|
-
* const customer = client.customer(token);
|
|
2257
|
+
* const customer = client.customer(token, { environment: "test" });
|
|
2186
2258
|
* await customer.cancelSubscription({ orderId: "ORD_xxx" });
|
|
2259
|
+
*
|
|
2260
|
+
* @example
|
|
2261
|
+
* // Set the environment once on the client instead
|
|
2262
|
+
* const client = new WaffoPancake({ merchantId, privateKey, environment: "test" });
|
|
2263
|
+
* const customer = client.customer(token);
|
|
2187
2264
|
*/
|
|
2188
|
-
customer(token: string): CustomerSession;
|
|
2265
|
+
customer(token: string, options?: CustomerSessionOptions): CustomerSession;
|
|
2189
2266
|
/**
|
|
2190
2267
|
* Create a customer session for self-service operations.
|
|
2191
2268
|
*
|
|
2192
2269
|
* @param token - Session token from `client.auth.issueSessionToken()`
|
|
2270
|
+
* @param options - Per-session overrides
|
|
2193
2271
|
* @returns A customer session with self-service methods
|
|
2194
2272
|
*
|
|
2195
2273
|
* @example
|
|
@@ -2199,7 +2277,7 @@ declare class WaffoPancake {
|
|
|
2199
2277
|
*
|
|
2200
2278
|
* @deprecated Use {@link WaffoPancake.customer} instead.
|
|
2201
2279
|
*/
|
|
2202
|
-
buyer(token: string): CustomerSession;
|
|
2280
|
+
buyer(token: string, options?: CustomerSessionOptions): CustomerSession;
|
|
2203
2281
|
}
|
|
2204
2282
|
|
|
2205
2283
|
/**
|
|
@@ -2278,4 +2356,4 @@ declare class WaffoPancakeError extends Error {
|
|
|
2278
2356
|
*/
|
|
2279
2357
|
declare function verifyWebhook<T = Record<string, unknown>>(payload: string, signatureHeader: string | undefined | null, options?: VerifyWebhookOptions): WebhookEvent<T>;
|
|
2280
2358
|
|
|
2281
|
-
export { type AddMerchantParams, type AddMerchantResult, type AddWebhookParams, type AnonymousCheckoutParams, type ApiError, type AuthenticatedCheckoutParams, type AuthenticatedCheckoutResult, type BillingDetail, BillingPeriod, type CancelOnetimeOrderParams, type CancelOnetimeOrderResult, type CancelSubscriptionParams, type CancelSubscriptionResult, type CashierLanguage, type CheckoutSessionResult, type CheckoutSettings, type CheckoutThemeSettings, type CreateCheckoutSessionParams, type CreateOnetimeProductParams, type CreateRefundTicketParams, type CreateStoreParams, type CreateSubscriptionProductGroupParams, type CreateSubscriptionProductParams, type DeleteStoreParams, type DeleteSubscriptionProductGroupParams, EntityStatus, type Envelope, Environment, ErrorLayer, type GraphQLParams, type GraphQLResponse, type GroupRules, type IssueSessionTokenParams, type MediaItem, MediaType, type MerchantWritableNotificationSettings, type Notice, type NotificationSettings, OnetimeOrderStatus, type OnetimeProductDetail, type PaymentMethod, PaymentStatus, type PostResult, type PriceInfo, type Prices, ProductVersionStatus, type PublishOnetimeProductParams, type PublishSubscriptionProductGroupParams, type PublishSubscriptionProductParams, type ReactivateSubscriptionParams, type ReactivateSubscriptionResult, RefundStatus, type RefundTicket, RefundTicketStatus, type RefundTicketVersionData, type RemoveMerchantParams, type RemoveMerchantResult, type RemoveWebhookParams, type RequestedAmount, type ResubmitRefundTicketParams, ScanAction, ScanPolicyCategory, type ScanPromptParams, ScanReasonCode, type ScanResult, ScanSemanticMode, ScanSemanticStatus, type SessionToken, type Store, StoreRole, type StoreWebhook, SubscriptionOrderStatus, type SubscriptionProductDetail, type SubscriptionProductGroup, TaxCategory, type UpdateOnetimeProductParams, type UpdateOnetimeStatusParams, type UpdateRoleParams, type UpdateRoleResult, type UpdateStoreParams, type UpdateSubscriptionProductGroupParams, type UpdateSubscriptionProductParams, type UpdateSubscriptionStatusParams, type UpdateWebhookParams, type VerifyWebhookOptions, WaffoPancake, type WaffoPancakeConfig, WaffoPancakeError, type WebhookChannel, type WebhookEvent, type WebhookEventData, WebhookEventType, type WebhookPublicKeys, verifyWebhook };
|
|
2359
|
+
export { type AddMerchantParams, type AddMerchantResult, type AddWebhookParams, type AnonymousCheckoutParams, type ApiError, type AuthenticatedCheckoutParams, type AuthenticatedCheckoutResult, type BillingDetail, BillingPeriod, type CancelOnetimeOrderParams, type CancelOnetimeOrderResult, type CancelSubscriptionParams, type CancelSubscriptionResult, type CashierLanguage, type CheckoutSessionResult, type CheckoutSettings, type CheckoutThemeSettings, type CreateCheckoutSessionParams, type CreateOnetimeProductParams, type CreateRefundTicketParams, type CreateStoreParams, type CreateSubscriptionProductGroupParams, type CreateSubscriptionProductParams, type CustomerSessionOptions, type DeleteStoreParams, type DeleteSubscriptionProductGroupParams, EntityStatus, type Envelope, Environment, ErrorLayer, type GraphQLParams, type GraphQLResponse, type GroupRules, type IssueSessionTokenParams, type MediaItem, MediaType, type MerchantWritableNotificationSettings, type Notice, type NotificationSettings, OnetimeOrderStatus, type OnetimeProductDetail, type PaymentMethod, PaymentStatus, type PostResult, type PriceInfo, type PriceSnapshot, type Prices, ProductVersionStatus, type PublishOnetimeProductParams, type PublishSubscriptionProductGroupParams, type PublishSubscriptionProductParams, type ReactivateSubscriptionParams, type ReactivateSubscriptionResult, RefundStatus, type RefundTicket, RefundTicketStatus, type RefundTicketVersionData, type RemoveMerchantParams, type RemoveMerchantResult, type RemoveWebhookParams, type RequestedAmount, type ResubmitRefundTicketParams, ScanAction, ScanPolicyCategory, type ScanPromptParams, ScanReasonCode, type ScanResult, ScanSemanticMode, ScanSemanticStatus, type SessionToken, type Store, StoreRole, type StoreWebhook, SubscriptionOrderStatus, type SubscriptionProductDetail, type SubscriptionProductGroup, TaxCategory, type UpdateOnetimeProductParams, type UpdateOnetimeStatusParams, type UpdateRoleParams, type UpdateRoleResult, type UpdateStoreParams, type UpdateSubscriptionProductGroupParams, type UpdateSubscriptionProductParams, type UpdateSubscriptionStatusParams, type UpdateWebhookParams, type VerifyWebhookOptions, WaffoPancake, type WaffoPancakeConfig, WaffoPancakeError, type WebhookChannel, type WebhookEvent, type WebhookEventData, WebhookEventType, type WebhookPublicKeys, verifyWebhook };
|
package/dist/index.js
CHANGED
|
@@ -15,16 +15,21 @@ var WaffoPancakeError = class extends Error {
|
|
|
15
15
|
var DEFAULT_BASE_URL = "https://api.waffo.ai";
|
|
16
16
|
var CustomerHttpClient = class {
|
|
17
17
|
token;
|
|
18
|
+
environment;
|
|
18
19
|
baseUrl;
|
|
19
20
|
_fetch;
|
|
20
|
-
constructor(token, config) {
|
|
21
|
+
constructor(token, environment, config) {
|
|
21
22
|
this.token = token;
|
|
23
|
+
this.environment = environment;
|
|
22
24
|
this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
23
25
|
this._fetch = config.fetch ?? globalThis.fetch.bind(globalThis);
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* Send a Bearer-authenticated POST and return the full envelope plus HTTP status.
|
|
27
29
|
*
|
|
30
|
+
* Sends `Authorization: Bearer <token>` and `X-Environment` — the gateway
|
|
31
|
+
* requires both to accept a session token.
|
|
32
|
+
*
|
|
28
33
|
* Does NOT throw on `errors[]` or non-2xx status — caller inspects the result.
|
|
29
34
|
* Throws {@link WaffoPancakeError} only when the response body is not valid JSON.
|
|
30
35
|
*/
|
|
@@ -33,7 +38,8 @@ var CustomerHttpClient = class {
|
|
|
33
38
|
method: "POST",
|
|
34
39
|
headers: {
|
|
35
40
|
"Content-Type": "application/json",
|
|
36
|
-
Authorization: `Bearer ${this.token}
|
|
41
|
+
Authorization: `Bearer ${this.token}`,
|
|
42
|
+
"X-Environment": this.environment
|
|
37
43
|
},
|
|
38
44
|
body: JSON.stringify(body)
|
|
39
45
|
});
|
|
@@ -1073,7 +1079,8 @@ var SubscriptionProductsResource = class {
|
|
|
1073
1079
|
|
|
1074
1080
|
// src/webhooks.ts
|
|
1075
1081
|
import { createVerify } from "crypto";
|
|
1076
|
-
var DEFAULT_TOLERANCE_MS =
|
|
1082
|
+
var DEFAULT_TOLERANCE_MS = 45 * 60 * 1e3;
|
|
1083
|
+
var DEFAULT_FUTURE_TOLERANCE_MS = 60 * 1e3;
|
|
1077
1084
|
var TEST_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
1078
1085
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxnmRY6yMMA3lVqmAU6ZG
|
|
1079
1086
|
b1sjL/+r/z6E+ZjkXaDAKiqOhk9rpazni0bNsGXwmftTPk9jy2wn+j6JHODD/WH/
|
|
@@ -1141,7 +1148,9 @@ function verifyWebhook(payload, signatureHeader, options) {
|
|
|
1141
1148
|
if (Number.isNaN(timestampMs)) {
|
|
1142
1149
|
throw new Error("Invalid timestamp in X-Waffo-Signature header");
|
|
1143
1150
|
}
|
|
1144
|
-
|
|
1151
|
+
const futureToleranceMs = options?.futureToleranceMs ?? DEFAULT_FUTURE_TOLERANCE_MS;
|
|
1152
|
+
const ageMs = Date.now() - timestampMs;
|
|
1153
|
+
if (ageMs > toleranceMs || ageMs < -futureToleranceMs) {
|
|
1145
1154
|
throw new Error("Webhook timestamp outside tolerance window (possible replay attack)");
|
|
1146
1155
|
}
|
|
1147
1156
|
}
|
|
@@ -1334,19 +1343,40 @@ var WaffoPancake = class {
|
|
|
1334
1343
|
* methods for order cancellation, subscription management, refund tickets,
|
|
1335
1344
|
* and scoped GraphQL queries.
|
|
1336
1345
|
*
|
|
1346
|
+
* Session tokens expire 5 minutes after issuance, so issue one right before
|
|
1347
|
+
* use rather than caching it.
|
|
1348
|
+
*
|
|
1337
1349
|
* @param token - Session token from `client.auth.issueSessionToken()`
|
|
1350
|
+
* @param options - Per-session overrides
|
|
1338
1351
|
* @returns A customer session with self-service methods
|
|
1352
|
+
* @throws {WaffoPancakeError} When no environment is available from either
|
|
1353
|
+
* `options.environment` or `WaffoPancakeConfig.environment`
|
|
1339
1354
|
*
|
|
1340
1355
|
* @example
|
|
1341
1356
|
* const { token } = await client.auth.issueSessionToken({
|
|
1342
1357
|
* storeId: "STO_xxx",
|
|
1343
1358
|
* buyerIdentity: "customer@example.com",
|
|
1344
1359
|
* });
|
|
1345
|
-
* const customer = client.customer(token);
|
|
1360
|
+
* const customer = client.customer(token, { environment: "test" });
|
|
1346
1361
|
* await customer.cancelSubscription({ orderId: "ORD_xxx" });
|
|
1362
|
+
*
|
|
1363
|
+
* @example
|
|
1364
|
+
* // Set the environment once on the client instead
|
|
1365
|
+
* const client = new WaffoPancake({ merchantId, privateKey, environment: "test" });
|
|
1366
|
+
* const customer = client.customer(token);
|
|
1347
1367
|
*/
|
|
1348
|
-
customer(token) {
|
|
1349
|
-
const
|
|
1368
|
+
customer(token, options) {
|
|
1369
|
+
const environment = options?.environment ?? this.config.environment;
|
|
1370
|
+
if (environment === void 0) {
|
|
1371
|
+
throw new WaffoPancakeError(400, [
|
|
1372
|
+
{
|
|
1373
|
+
message: "Missing required field: environment \u2014 set it on the client config or pass client.customer(token, { environment: 'test' | 'prod' })",
|
|
1374
|
+
layer: "sdk"
|
|
1375
|
+
}
|
|
1376
|
+
]);
|
|
1377
|
+
}
|
|
1378
|
+
validateEnum("environment", environment, ["test", "prod"]);
|
|
1379
|
+
const customerHttp = new CustomerHttpClient(token, environment, {
|
|
1350
1380
|
baseUrl: this.config.baseUrl,
|
|
1351
1381
|
fetch: this.config.fetch
|
|
1352
1382
|
});
|
|
@@ -1356,6 +1386,7 @@ var WaffoPancake = class {
|
|
|
1356
1386
|
* Create a customer session for self-service operations.
|
|
1357
1387
|
*
|
|
1358
1388
|
* @param token - Session token from `client.auth.issueSessionToken()`
|
|
1389
|
+
* @param options - Per-session overrides
|
|
1359
1390
|
* @returns A customer session with self-service methods
|
|
1360
1391
|
*
|
|
1361
1392
|
* @example
|
|
@@ -1365,8 +1396,8 @@ var WaffoPancake = class {
|
|
|
1365
1396
|
*
|
|
1366
1397
|
* @deprecated Use {@link WaffoPancake.customer} instead.
|
|
1367
1398
|
*/
|
|
1368
|
-
buyer(token) {
|
|
1369
|
-
return this.customer(token);
|
|
1399
|
+
buyer(token, options) {
|
|
1400
|
+
return this.customer(token, options);
|
|
1370
1401
|
}
|
|
1371
1402
|
};
|
|
1372
1403
|
|