@waffo/pancake-ts 0.17.0 → 0.18.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.
@@ -545,7 +545,7 @@ const { orderId, status } = await client.orders.cancelSubscription({
545
545
 
546
546
  Issue a session token and create a customer session to let customers manage their own orders.
547
547
 
548
- ### `client.customer(token)`
548
+ ### `client.customer(token, options?)`
549
549
 
550
550
  Create a customer session from a session token issued by `client.auth.issueSessionToken()`.
551
551
 
@@ -554,9 +554,22 @@ const { token } = await client.auth.issueSessionToken({
554
554
  storeId: "STO_xxx",
555
555
  buyerIdentity: "customer@example.com",
556
556
  });
557
- const customer = client.customer(token);
557
+ const customer = client.customer(token, { environment: "test" });
558
558
  ```
559
559
 
560
+ | Option | Type | Required | Description |
561
+ | ------------- | ------------------ | ------------------------------- | ------------------------------------------------ |
562
+ | `environment` | `"test" \| "prod"` | Unless set on the client config | Sent as `X-Environment` on every session request |
563
+
564
+ An environment must come from either `options.environment` or
565
+ `WaffoPancakeConfig.environment` — the session token carries none of its own, and
566
+ the gateway rejects a Bearer credential without the header. There is no default:
567
+ guessing would route the call to the other environment. When neither supplies
568
+ one, this throws `WaffoPancakeError` (400, `layer: "sdk"`).
569
+
570
+ Session tokens expire 5 minutes after issuance — issue one right before use
571
+ rather than caching it.
572
+
560
573
  ### `customer.cancelSubscription(params)`
561
574
 
562
575
  | Field | Type | Required | Description |
@@ -7,7 +7,7 @@ Waffo Pancake sends webhook events to your configured endpoint when payment, sub
7
7
  - **Algorithm**: RSA-SHA256 with environment-specific key pairs
8
8
  - **Dual environment**: Test and production use separate key pairs; the SDK resolves the correct key automatically
9
9
  - **Multi-level key loading**: Config parameter → environment variable → built-in hardcoded key
10
- - **Replay protection**: 5-minute timestamp tolerance by default
10
+ - **Replay protection**: 45-minute past / 1-minute future timestamp tolerance by default
11
11
  - **Environment auto-detection**: Tries the production key first, falls back to test
12
12
 
13
13
  ## Signature Verification
@@ -16,9 +16,16 @@ Waffo Pancake sends webhook events to your configured endpoint when payment, sub
16
16
  1. Parse X-Waffo-Signature header → t (timestamp) + v1 (Base64 signature)
17
17
  2. Build signature input: `${t}.${rawBody}`
18
18
  3. Verify v1 with RSA-SHA256 using the Waffo public key
19
- 4. Check timestamp (default 5-minute tolerance to prevent replay attacks)
19
+ 4. Check timestamp (default: up to 45 minutes old, up to 1 minute ahead)
20
20
  ```
21
21
 
22
+ The timestamp is stamped once, before the first delivery attempt. Retries reuse
23
+ the original header, so the final retry of a schedule arrives with a timestamp as
24
+ old as the schedule itself — the past-facing window has to cover it. Treat the
25
+ window as a bound on how long a captured request stays replayable, not as your
26
+ primary defense: every event carries a stable `id`, and your handler should be
27
+ idempotent on it.
28
+
22
29
  ## Usage
23
30
 
24
31
  ### Express
@@ -83,8 +90,11 @@ const event = verifyWebhook(body, sig, { environment: "prod" });
83
90
  // Disable replay protection (useful for testing)
84
91
  const event = verifyWebhook(body, sig, { toleranceMs: 0 });
85
92
 
86
- // Custom tolerance window (10 minutes)
93
+ // Custom past-facing tolerance window (10 minutes)
87
94
  const event = verifyWebhook(body, sig, { toleranceMs: 600000 });
95
+
96
+ // Loosen the future-facing window for a server with known clock skew
97
+ const event = verifyWebhook(body, sig, { futureToleranceMs: 300000 });
88
98
  ```
89
99
 
90
100
  ## Parameters
@@ -97,12 +107,13 @@ const event = verifyWebhook(body, sig, { toleranceMs: 600000 });
97
107
 
98
108
  ### `VerifyWebhookOptions`
99
109
 
100
- | Field | Type | Default | Description |
101
- | ------------- | ---------------------------- | ---------------- | --------------------------------------------------------------------------------------------------------------- |
102
- | `environment` | `"test" \| "prod"` | auto-detect | Which environment's key to resolve. When omitted, tries prod first, then test. Ignored when `publicKey` is set. |
103
- | `toleranceMs` | `number` | `300000` (5 min) | Timestamp tolerance in ms. Set to `0` to skip timestamp check |
104
- | `publicKey` | `string` | | Per-call public key override (highest priority, skips all resolution) |
105
- | `publicKeys` | `string \| { test?, prod? }` | — | Config-level key(s) for the resolution chain. Typically injected automatically by `client.webhooks.verify()` |
110
+ | Field | Type | Default | Description |
111
+ | ------------------- | ---------------------------- | ------------------ | --------------------------------------------------------------------------------------------------------------- |
112
+ | `environment` | `"test" \| "prod"` | auto-detect | Which environment's key to resolve. When omitted, tries prod first, then test. Ignored when `publicKey` is set. |
113
+ | `toleranceMs` | `number` | `2700000` (45 min) | How far in the past a timestamp may be, in ms. Set to `0` to skip the timestamp check entirely |
114
+ | `futureToleranceMs` | `number` | `60000` (1 min) | How far in the future a timestamp may be, in ms. Ignored when `toleranceMs` is `0` |
115
+ | `publicKey` | `string` | — | Per-call public key override (highest priority, skips all resolution) |
116
+ | `publicKeys` | `string \| { test?, prod? }` | — | Config-level key(s) for the resolution chain. Typically injected automatically by `client.webhooks.verify()` |
106
117
 
107
118
  ## Dual-Environment Public Key Architecture
108
119
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waffo/pancake-ts",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "TypeScript SDK for Waffo Pancake MoR platform — RSA-SHA256 signing, zero runtime dependencies",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",