@stacksjs/payments 0.70.44 → 0.70.53

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.
@@ -17,6 +17,15 @@ export declare function registerWebhookHandlers(handlerMap: Record<WebhookEventT
17
17
  * silently ignored.
18
18
  */
19
19
  export declare function constructEvent(payload: string | Buffer, signature: string, secret: string, tolerance?: number): Stripe.Event;
20
+ /**
21
+ * Async variant of {@link constructEvent}. Some runtimes (notably Bun) resolve
22
+ * the Stripe SDK's crypto provider to WebCrypto's `SubtleCrypto`, which is
23
+ * async-only — the synchronous `constructEvent` then throws
24
+ * "SubtleCryptoProvider cannot be used in a synchronous context". Verifying via
25
+ * `constructEventAsync` works across Node and Bun, so webhook processing uses
26
+ * this path.
27
+ */
28
+ export declare function constructEventAsync(payload: string | Buffer, signature: string, secret: string, tolerance?: number): Promise<Stripe.Event>;
20
29
  /**
21
30
  * Handle an incoming webhook event
22
31
  */
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Build a deterministic Stripe idempotency key for an operation.
3
+ * The `scope` should be a stable string identifying the call site
4
+ * (e.g. `'customer.create'`, `'subscription.create'`); `parts` are
5
+ * any extra identifying values (user id, lookup key, etc.) that
6
+ * uniquely scope the operation within that user's lifetime.
7
+ *
8
+ * @param scope - stable operation name; never user input
9
+ * @param parts - identifying values appended after scope (coerced
10
+ * to string; nullish values are skipped)
11
+ */
12
+ export declare function stacksIdempotencyKey(scope: string, ...parts: Array<string | number | null | undefined>): string;
13
+ /**
14
+ * Build a one-shot idempotency key for operations that are NOT
15
+ * naturally retryable (a unique-per-attempt key that won't collide
16
+ * with anything). Used when the caller WANTS a fresh Stripe object
17
+ * each time but still wants the safety of a single network retry
18
+ * within a single attempt. The key includes a random suffix so
19
+ * sequential attempts produce different keys.
20
+ *
21
+ * Used for payment intents, checkout sessions — operations where
22
+ * "create another one" is the right semantic on a retry by the
23
+ * caller, but where a single network blip during a single attempt
24
+ * still benefits from in-flight idempotency.
25
+ */
26
+ export declare function freshIdempotencyKey(scope: string, ...parts: Array<string | number | null | undefined>): string;
@@ -11,3 +11,6 @@ export * from './billable/index';
11
11
  // Stripe driver and SDK
12
12
  export * from './drivers/stripe';
13
13
  export * as Stripe from 'stripe';
14
+ // Idempotency-key helpers — passed to every Stripe create/update so
15
+ // retries don't produce duplicate objects (stacksjs/stacks#1876 X-1).
16
+ export { freshIdempotencyKey, stacksIdempotencyKey } from './idempotency';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/payments",
3
3
  "type": "module",
4
- "version": "0.70.44",
4
+ "version": "0.70.53",
5
5
  "description": "The Stacks payments package. Currently supporting Stripe.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -50,9 +50,9 @@
50
50
  "prepublishOnly": "bun run build"
51
51
  },
52
52
  "devDependencies": {
53
- "@stacksjs/config": "^0.70.44",
53
+ "@stacksjs/config": "0.70.53",
54
54
  "better-dx": "^0.2.12",
55
- "@stacksjs/utils": "^0.70.44",
55
+ "@stacksjs/utils": "0.70.53",
56
56
  "@stripe/stripe-js": "^8.7.0",
57
57
  "stripe": "^21.0.1"
58
58
  }