better-auth-streampay 1.1.5 → 1.1.6

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/README.md CHANGED
@@ -23,6 +23,15 @@ pnpm add better-auth-streampay @streamsdk/typescript better-auth zod
23
23
 
24
24
  Peers: `better-auth ^1.4`, `@streamsdk/typescript ^1.0.6`, `zod ^3.24 || ^4`.
25
25
 
26
+ ### Preview releases
27
+
28
+ Every push to `main` and every PR is published as an installable tarball
29
+ via [pkg.pr.new](https://github.com/stackblitz-labs/pkg.pr.new):
30
+
31
+ ```bash
32
+ pnpm add https://pkg.pr.new/better-auth-streampay@<sha-or-pr-number>
33
+ ```
34
+
26
35
  ## Env
27
36
 
28
37
  ```bash
package/dist/index.cjs CHANGED
@@ -530,6 +530,21 @@ async function claimWebhookEvent(ctx, payload) {
530
530
  throw err;
531
531
  }
532
532
  }
533
+ async function releaseWebhookEvent(ctx, payload) {
534
+ const eventId = extractEventId(payload);
535
+ if (!eventId) return;
536
+ try {
537
+ await ctx.context.adapter.delete({
538
+ model: WEBHOOK_EVENT_MODEL,
539
+ where: [{ field: "eventId", value: eventId }]
540
+ });
541
+ } catch (err) {
542
+ const msg = err instanceof Error ? err.message : String(err);
543
+ ctx.context.logger.error(
544
+ `StreamPay webhook ${payload.event_type} (${eventId}): failed to release dedupe claim after sync error \u2014 retry will be skipped: ${msg}`
545
+ );
546
+ }
547
+ }
533
548
  function extractEventId(payload) {
534
549
  if (!payload.timestamp || !payload.entity_id) return null;
535
550
  return `${payload.event_type}:${payload.entity_id}:${payload.timestamp}`;
@@ -720,24 +735,30 @@ async function syncWebhookPayload(ctx, payload, client, plans, callbacks, option
720
735
  if (payload.entity_type !== "SUBSCRIPTION" && payload.event_type !== "INVOICE_COMPLETED") {
721
736
  return;
722
737
  }
723
- if (options.dedupe !== false) {
738
+ const dedupe = options.dedupe !== false;
739
+ if (dedupe) {
724
740
  const claimed = await claimWebhookEvent(ctx, payload);
725
741
  if (!claimed) return;
726
742
  }
727
- if (payload.event_type === "INVOICE_COMPLETED") {
728
- await handleInvoiceCompleted(ctx, payload, client, plans, callbacks);
729
- return;
743
+ try {
744
+ if (payload.event_type === "INVOICE_COMPLETED") {
745
+ await handleInvoiceCompleted(ctx, payload, client, plans, callbacks);
746
+ return;
747
+ }
748
+ const { row, stream } = await reconcileFromStreamPay(ctx, payload, client, plans);
749
+ if (!row) return;
750
+ const user = await resolveRowUser(ctx, row);
751
+ const data = {
752
+ subscription: row,
753
+ streampaySubscription: stream,
754
+ user,
755
+ event: payload
756
+ };
757
+ await dispatchSubscriptionCallback(ctx, payload, data, callbacks);
758
+ } catch (err) {
759
+ if (dedupe) await releaseWebhookEvent(ctx, payload);
760
+ throw err;
730
761
  }
731
- const { row, stream } = await reconcileFromStreamPay(ctx, payload, client, plans);
732
- if (!row) return;
733
- const user = await resolveRowUser(ctx, row);
734
- const data = {
735
- subscription: row,
736
- streampaySubscription: stream,
737
- user,
738
- event: payload
739
- };
740
- await dispatchSubscriptionCallback(ctx, payload, data, callbacks);
741
762
  }
742
763
  async function handleInvoiceCompleted(ctx, payload, client, _plans, callbacks) {
743
764
  const invoiceId = payload.data?.invoice?.id ?? payload.entity_id;
@@ -3278,7 +3299,7 @@ var onUserDelete = (options) => async (user, context) => {
3278
3299
 
3279
3300
  // package.json
3280
3301
  var package_default = {
3281
- version: "1.1.5"};
3302
+ version: "1.1.6"};
3282
3303
 
3283
3304
  // src/version.ts
3284
3305
  var version = package_default.version;