@hookflo/tern 3.0.7-beta → 3.0.11-beta

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.
@@ -1,11 +1,117 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.resolveQueueConfig = resolveQueueConfig;
4
37
  exports.handleReceive = handleReceive;
5
38
  exports.handleProcess = handleProcess;
6
39
  exports.handleQueuedRequest = handleQueuedRequest;
7
- const qstash_1 = require("@upstash/qstash");
40
+ const QStash = __importStar(require("@upstash/qstash"));
8
41
  const index_1 = require("../index");
42
+ async function dynamicImport(modulePath) {
43
+ return new Function('modulePath', 'return import(modulePath);')(modulePath);
44
+ }
45
+ async function loadQStashModules() {
46
+ const optionalImports = await Promise.allSettled([
47
+ dynamicImport('@upstash/qstash'),
48
+ dynamicImport('@upstash/qstash/nextjs'),
49
+ dynamicImport('@upstash/qstash/nuxt'),
50
+ dynamicImport('@upstash/qstash/sveltekit'),
51
+ dynamicImport('@upstash/qstash/cloudflare'),
52
+ ]);
53
+ return [
54
+ QStash,
55
+ ...optionalImports.flatMap((result) => (result.status === 'fulfilled' ? [result.value] : [])),
56
+ ];
57
+ }
58
+ function resolveModuleExport(modules, key) {
59
+ for (const moduleRef of modules) {
60
+ const directExport = moduleRef[key];
61
+ if (typeof directExport === 'function') {
62
+ return directExport;
63
+ }
64
+ const defaultExport = moduleRef.default?.[key];
65
+ if (typeof defaultExport === 'function') {
66
+ return defaultExport;
67
+ }
68
+ }
69
+ return undefined;
70
+ }
71
+ function resolveNestedConstructor(modules, key) {
72
+ const seen = new Set();
73
+ const queue = [...modules];
74
+ while (queue.length) {
75
+ const current = queue.shift();
76
+ if (!current || typeof current !== 'object' || seen.has(current)) {
77
+ continue;
78
+ }
79
+ seen.add(current);
80
+ const record = current;
81
+ const candidate = record[key];
82
+ if (typeof candidate === 'function') {
83
+ return candidate;
84
+ }
85
+ for (const value of Object.values(record)) {
86
+ if (value && typeof value === 'object') {
87
+ queue.push(value);
88
+ }
89
+ }
90
+ }
91
+ return undefined;
92
+ }
93
+ async function createQStashReceiver(queueConfig) {
94
+ const modules = await loadQStashModules();
95
+ const receiverExport = resolveModuleExport(modules, 'Receiver')
96
+ ?? resolveNestedConstructor(modules, 'Receiver');
97
+ if (typeof receiverExport !== 'function') {
98
+ throw new Error('[tern] Incompatible @upstash/qstash version: Receiver export not found. Ensure @upstash/qstash is installed and up-to-date.');
99
+ }
100
+ return new receiverExport({
101
+ currentSigningKey: queueConfig.signingKey,
102
+ nextSigningKey: queueConfig.nextSigningKey,
103
+ });
104
+ }
105
+ async function createQStashClient(queueConfig) {
106
+ const modules = await loadQStashModules();
107
+ const clientExport = resolveModuleExport(modules, 'Client');
108
+ const resolvedClientExport = clientExport
109
+ ?? resolveNestedConstructor(modules, 'Client');
110
+ if (typeof resolvedClientExport !== 'function') {
111
+ throw new Error('[tern] Incompatible @upstash/qstash version: Client export not found. Ensure @upstash/qstash is installed and up-to-date.');
112
+ }
113
+ return new resolvedClientExport({ token: queueConfig.token });
114
+ }
9
115
  function nonRetryableResponse(message, status = 489) {
10
116
  return new Response(JSON.stringify({ error: message }), {
11
117
  status,
@@ -32,7 +138,7 @@ async function handleReceive(request, platform, secret, queueConfig, toleranceIn
32
138
  if (!verificationResult.isValid) {
33
139
  return nonRetryableResponse(verificationResult.error || 'Webhook signature verification failed');
34
140
  }
35
- const client = new qstash_1.Client({ token: queueConfig.token });
141
+ const client = await createQStashClient(queueConfig);
36
142
  const queuedMessage = {
37
143
  platform,
38
144
  payload: verificationResult.payload,
@@ -61,10 +167,7 @@ async function handleProcess(request, handler, queueConfig) {
61
167
  return new Response(JSON.stringify({ error: 'Missing Upstash-Signature header' }), { status: 401, headers: { 'Content-Type': 'application/json' } });
62
168
  }
63
169
  const rawBody = await request.text();
64
- const receiver = new qstash_1.Receiver({
65
- currentSigningKey: queueConfig.signingKey,
66
- nextSigningKey: queueConfig.nextSigningKey,
67
- });
170
+ const receiver = await createQStashReceiver(queueConfig);
68
171
  try {
69
172
  const verification = await receiver.verify({
70
173
  signature,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hookflo/tern",
3
- "version": "3.0.7-beta",
3
+ "version": "3.0.11-beta",
4
4
  "description": "A robust, scalable webhook verification framework supporting multiple platforms and signature algorithms",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -125,7 +125,7 @@
125
125
  }
126
126
  },
127
127
  "peerDependencies": {
128
- "@upstash/qstash": ">=2.0.0"
128
+ "@upstash/qstash": ">=2.9.0"
129
129
  },
130
130
  "peerDependenciesMeta": {
131
131
  "@upstash/qstash": {