@dodopayments/convex 0.1.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/README.md +443 -0
- package/dist/client/index.d.ts +42 -0
- package/dist/component/_generated/server.js +28 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +2 -0
- package/dist/component/convex.config.js +6 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/lib.d.ts +54 -0
- package/dist/component/lib.js +88 -0
- package/dist/component/lib.js.map +1 -0
- package/dist/component/schema.d.ts +2 -0
- package/dist/component/schema.js +6 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/core/dist/checkout/checkout.js +543 -0
- package/dist/core/dist/checkout/checkout.js.map +1 -0
- package/dist/index.cjs +2445 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.js +2441 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2441 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// This is the public-facing client that developers will use.
|
|
4
|
+
class DodoPayments {
|
|
5
|
+
constructor(component, config) {
|
|
6
|
+
this.component = component;
|
|
7
|
+
this.config = config;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Returns the public API methods for the Dodo Payments client.
|
|
11
|
+
*/
|
|
12
|
+
api() {
|
|
13
|
+
return {
|
|
14
|
+
/**
|
|
15
|
+
* Creates a Dodo Payments checkout session.
|
|
16
|
+
* Uses session checkout with full feature support.
|
|
17
|
+
*/
|
|
18
|
+
checkout: async (ctx, args) => {
|
|
19
|
+
return await ctx.runAction(this.component.lib.checkout, {
|
|
20
|
+
...args,
|
|
21
|
+
apiKey: this.config.apiKey,
|
|
22
|
+
environment: this.config.environment,
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves a URL for the customer portal.
|
|
27
|
+
* This function is designed to be called from a public Convex query in your app.
|
|
28
|
+
*/
|
|
29
|
+
customerPortal: async (ctx, args) => {
|
|
30
|
+
const identity = await this.config.identify(ctx);
|
|
31
|
+
if (!identity) {
|
|
32
|
+
throw new Error("User is not authenticated.");
|
|
33
|
+
}
|
|
34
|
+
return await ctx.runAction(this.component.lib.customerPortal, {
|
|
35
|
+
dodoCustomerId: identity.dodoCustomerId,
|
|
36
|
+
send_email: args?.send_email,
|
|
37
|
+
apiKey: this.config.apiKey,
|
|
38
|
+
environment: this.config.environment,
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
var lookup = [];
|
|
46
|
+
var revLookup = [];
|
|
47
|
+
var Arr = Uint8Array;
|
|
48
|
+
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
49
|
+
for (var i = 0, len = code.length; i < len; ++i) {
|
|
50
|
+
lookup[i] = code[i];
|
|
51
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
52
|
+
}
|
|
53
|
+
revLookup["-".charCodeAt(0)] = 62;
|
|
54
|
+
revLookup["_".charCodeAt(0)] = 63;
|
|
55
|
+
function getLens(b64) {
|
|
56
|
+
var len = b64.length;
|
|
57
|
+
if (len % 4 > 0) {
|
|
58
|
+
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
59
|
+
}
|
|
60
|
+
var validLen = b64.indexOf("=");
|
|
61
|
+
if (validLen === -1) validLen = len;
|
|
62
|
+
var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
|
|
63
|
+
return [validLen, placeHoldersLen];
|
|
64
|
+
}
|
|
65
|
+
function _byteLength(_b64, validLen, placeHoldersLen) {
|
|
66
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
67
|
+
}
|
|
68
|
+
function toByteArray(b64) {
|
|
69
|
+
var tmp;
|
|
70
|
+
var lens = getLens(b64);
|
|
71
|
+
var validLen = lens[0];
|
|
72
|
+
var placeHoldersLen = lens[1];
|
|
73
|
+
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
74
|
+
var curByte = 0;
|
|
75
|
+
var len = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
76
|
+
var i;
|
|
77
|
+
for (i = 0; i < len; i += 4) {
|
|
78
|
+
tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
|
|
79
|
+
arr[curByte++] = tmp >> 16 & 255;
|
|
80
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
81
|
+
arr[curByte++] = tmp & 255;
|
|
82
|
+
}
|
|
83
|
+
if (placeHoldersLen === 2) {
|
|
84
|
+
tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
|
|
85
|
+
arr[curByte++] = tmp & 255;
|
|
86
|
+
}
|
|
87
|
+
if (placeHoldersLen === 1) {
|
|
88
|
+
tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
|
|
89
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
90
|
+
arr[curByte++] = tmp & 255;
|
|
91
|
+
}
|
|
92
|
+
return arr;
|
|
93
|
+
}
|
|
94
|
+
function tripletToBase64(num) {
|
|
95
|
+
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
96
|
+
}
|
|
97
|
+
function encodeChunk(uint8, start, end) {
|
|
98
|
+
var tmp;
|
|
99
|
+
var output = [];
|
|
100
|
+
for (var i = start; i < end; i += 3) {
|
|
101
|
+
tmp = (uint8[i] << 16 & 16711680) + (uint8[i + 1] << 8 & 65280) + (uint8[i + 2] & 255);
|
|
102
|
+
output.push(tripletToBase64(tmp));
|
|
103
|
+
}
|
|
104
|
+
return output.join("");
|
|
105
|
+
}
|
|
106
|
+
function fromByteArray(uint8) {
|
|
107
|
+
var tmp;
|
|
108
|
+
var len = uint8.length;
|
|
109
|
+
var extraBytes = len % 3;
|
|
110
|
+
var parts = [];
|
|
111
|
+
var maxChunkLength = 16383;
|
|
112
|
+
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
|
113
|
+
parts.push(
|
|
114
|
+
encodeChunk(
|
|
115
|
+
uint8,
|
|
116
|
+
i,
|
|
117
|
+
i + maxChunkLength > len2 ? len2 : i + maxChunkLength
|
|
118
|
+
)
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (extraBytes === 1) {
|
|
122
|
+
tmp = uint8[len - 1];
|
|
123
|
+
parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "==");
|
|
124
|
+
} else if (extraBytes === 2) {
|
|
125
|
+
tmp = (uint8[len - 2] << 8) + uint8[len - 1];
|
|
126
|
+
parts.push(
|
|
127
|
+
lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "="
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
return parts.join("");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function parseArgs(args) {
|
|
134
|
+
if (args === void 0) {
|
|
135
|
+
return {};
|
|
136
|
+
}
|
|
137
|
+
if (!isSimpleObject(args)) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
`The arguments to a Convex function must be an object. Received: ${args}`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return args;
|
|
143
|
+
}
|
|
144
|
+
function isSimpleObject(value) {
|
|
145
|
+
const isObject = typeof value === "object";
|
|
146
|
+
const prototype = Object.getPrototypeOf(value);
|
|
147
|
+
const isSimple = prototype === null || prototype === Object.prototype || // Objects generated from other contexts (e.g. across Node.js `vm` modules) will not satisfy the previous
|
|
148
|
+
// conditions but are still simple objects.
|
|
149
|
+
prototype?.constructor?.name === "Object";
|
|
150
|
+
return isObject && isSimple;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const LITTLE_ENDIAN = true;
|
|
154
|
+
const MIN_INT64 = BigInt("-9223372036854775808");
|
|
155
|
+
const MAX_INT64 = BigInt("9223372036854775807");
|
|
156
|
+
const ZERO = BigInt("0");
|
|
157
|
+
const EIGHT = BigInt("8");
|
|
158
|
+
const TWOFIFTYSIX = BigInt("256");
|
|
159
|
+
function isSpecial(n) {
|
|
160
|
+
return Number.isNaN(n) || !Number.isFinite(n) || Object.is(n, -0);
|
|
161
|
+
}
|
|
162
|
+
function slowBigIntToBase64(value) {
|
|
163
|
+
if (value < ZERO) {
|
|
164
|
+
value -= MIN_INT64 + MIN_INT64;
|
|
165
|
+
}
|
|
166
|
+
let hex = value.toString(16);
|
|
167
|
+
if (hex.length % 2 === 1) hex = "0" + hex;
|
|
168
|
+
const bytes = new Uint8Array(new ArrayBuffer(8));
|
|
169
|
+
let i = 0;
|
|
170
|
+
for (const hexByte of hex.match(/.{2}/g).reverse()) {
|
|
171
|
+
bytes.set([parseInt(hexByte, 16)], i++);
|
|
172
|
+
value >>= EIGHT;
|
|
173
|
+
}
|
|
174
|
+
return fromByteArray(bytes);
|
|
175
|
+
}
|
|
176
|
+
function slowBase64ToBigInt(encoded) {
|
|
177
|
+
const integerBytes = toByteArray(encoded);
|
|
178
|
+
if (integerBytes.byteLength !== 8) {
|
|
179
|
+
throw new Error(
|
|
180
|
+
`Received ${integerBytes.byteLength} bytes, expected 8 for $integer`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
let value = ZERO;
|
|
184
|
+
let power = ZERO;
|
|
185
|
+
for (const byte of integerBytes) {
|
|
186
|
+
value += BigInt(byte) * TWOFIFTYSIX ** power;
|
|
187
|
+
power++;
|
|
188
|
+
}
|
|
189
|
+
if (value > MAX_INT64) {
|
|
190
|
+
value += MIN_INT64 + MIN_INT64;
|
|
191
|
+
}
|
|
192
|
+
return value;
|
|
193
|
+
}
|
|
194
|
+
function modernBigIntToBase64(value) {
|
|
195
|
+
if (value < MIN_INT64 || MAX_INT64 < value) {
|
|
196
|
+
throw new Error(
|
|
197
|
+
`BigInt ${value} does not fit into a 64-bit signed integer.`
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
const buffer = new ArrayBuffer(8);
|
|
201
|
+
new DataView(buffer).setBigInt64(0, value, true);
|
|
202
|
+
return fromByteArray(new Uint8Array(buffer));
|
|
203
|
+
}
|
|
204
|
+
function modernBase64ToBigInt(encoded) {
|
|
205
|
+
const integerBytes = toByteArray(encoded);
|
|
206
|
+
if (integerBytes.byteLength !== 8) {
|
|
207
|
+
throw new Error(
|
|
208
|
+
`Received ${integerBytes.byteLength} bytes, expected 8 for $integer`
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
const intBytesView = new DataView(integerBytes.buffer);
|
|
212
|
+
return intBytesView.getBigInt64(0, true);
|
|
213
|
+
}
|
|
214
|
+
const bigIntToBase64 = DataView.prototype.setBigInt64 ? modernBigIntToBase64 : slowBigIntToBase64;
|
|
215
|
+
const base64ToBigInt = DataView.prototype.getBigInt64 ? modernBase64ToBigInt : slowBase64ToBigInt;
|
|
216
|
+
const MAX_IDENTIFIER_LEN = 1024;
|
|
217
|
+
function validateObjectField(k) {
|
|
218
|
+
if (k.length > MAX_IDENTIFIER_LEN) {
|
|
219
|
+
throw new Error(
|
|
220
|
+
`Field name ${k} exceeds maximum field name length ${MAX_IDENTIFIER_LEN}.`
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
if (k.startsWith("$")) {
|
|
224
|
+
throw new Error(`Field name ${k} starts with a '$', which is reserved.`);
|
|
225
|
+
}
|
|
226
|
+
for (let i = 0; i < k.length; i += 1) {
|
|
227
|
+
const charCode = k.charCodeAt(i);
|
|
228
|
+
if (charCode < 32 || charCode >= 127) {
|
|
229
|
+
throw new Error(
|
|
230
|
+
`Field name ${k} has invalid character '${k[i]}': Field names can only contain non-control ASCII characters`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function jsonToConvex(value) {
|
|
236
|
+
if (value === null) {
|
|
237
|
+
return value;
|
|
238
|
+
}
|
|
239
|
+
if (typeof value === "boolean") {
|
|
240
|
+
return value;
|
|
241
|
+
}
|
|
242
|
+
if (typeof value === "number") {
|
|
243
|
+
return value;
|
|
244
|
+
}
|
|
245
|
+
if (typeof value === "string") {
|
|
246
|
+
return value;
|
|
247
|
+
}
|
|
248
|
+
if (Array.isArray(value)) {
|
|
249
|
+
return value.map((value2) => jsonToConvex(value2));
|
|
250
|
+
}
|
|
251
|
+
if (typeof value !== "object") {
|
|
252
|
+
throw new Error(`Unexpected type of ${value}`);
|
|
253
|
+
}
|
|
254
|
+
const entries = Object.entries(value);
|
|
255
|
+
if (entries.length === 1) {
|
|
256
|
+
const key = entries[0][0];
|
|
257
|
+
if (key === "$bytes") {
|
|
258
|
+
if (typeof value.$bytes !== "string") {
|
|
259
|
+
throw new Error(`Malformed $bytes field on ${value}`);
|
|
260
|
+
}
|
|
261
|
+
return toByteArray(value.$bytes).buffer;
|
|
262
|
+
}
|
|
263
|
+
if (key === "$integer") {
|
|
264
|
+
if (typeof value.$integer !== "string") {
|
|
265
|
+
throw new Error(`Malformed $integer field on ${value}`);
|
|
266
|
+
}
|
|
267
|
+
return base64ToBigInt(value.$integer);
|
|
268
|
+
}
|
|
269
|
+
if (key === "$float") {
|
|
270
|
+
if (typeof value.$float !== "string") {
|
|
271
|
+
throw new Error(`Malformed $float field on ${value}`);
|
|
272
|
+
}
|
|
273
|
+
const floatBytes = toByteArray(value.$float);
|
|
274
|
+
if (floatBytes.byteLength !== 8) {
|
|
275
|
+
throw new Error(
|
|
276
|
+
`Received ${floatBytes.byteLength} bytes, expected 8 for $float`
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
const floatBytesView = new DataView(floatBytes.buffer);
|
|
280
|
+
const float = floatBytesView.getFloat64(0, LITTLE_ENDIAN);
|
|
281
|
+
if (!isSpecial(float)) {
|
|
282
|
+
throw new Error(`Float ${float} should be encoded as a number`);
|
|
283
|
+
}
|
|
284
|
+
return float;
|
|
285
|
+
}
|
|
286
|
+
if (key === "$set") {
|
|
287
|
+
throw new Error(
|
|
288
|
+
`Received a Set which is no longer supported as a Convex type.`
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
if (key === "$map") {
|
|
292
|
+
throw new Error(
|
|
293
|
+
`Received a Map which is no longer supported as a Convex type.`
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
const out = {};
|
|
298
|
+
for (const [k, v] of Object.entries(value)) {
|
|
299
|
+
validateObjectField(k);
|
|
300
|
+
out[k] = jsonToConvex(v);
|
|
301
|
+
}
|
|
302
|
+
return out;
|
|
303
|
+
}
|
|
304
|
+
function stringifyValueForError(value) {
|
|
305
|
+
return JSON.stringify(value, (_key, value2) => {
|
|
306
|
+
if (value2 === void 0) {
|
|
307
|
+
return "undefined";
|
|
308
|
+
}
|
|
309
|
+
if (typeof value2 === "bigint") {
|
|
310
|
+
return `${value2.toString()}n`;
|
|
311
|
+
}
|
|
312
|
+
return value2;
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
function convexToJsonInternal(value, originalValue, context, includeTopLevelUndefined) {
|
|
316
|
+
if (value === void 0) {
|
|
317
|
+
const contextText = context && ` (present at path ${context} in original object ${stringifyValueForError(
|
|
318
|
+
originalValue
|
|
319
|
+
)})`;
|
|
320
|
+
throw new Error(
|
|
321
|
+
`undefined is not a valid Convex value${contextText}. To learn about Convex's supported types, see https://docs.convex.dev/using/types.`
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
if (value === null) {
|
|
325
|
+
return value;
|
|
326
|
+
}
|
|
327
|
+
if (typeof value === "bigint") {
|
|
328
|
+
if (value < MIN_INT64 || MAX_INT64 < value) {
|
|
329
|
+
throw new Error(
|
|
330
|
+
`BigInt ${value} does not fit into a 64-bit signed integer.`
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
return { $integer: bigIntToBase64(value) };
|
|
334
|
+
}
|
|
335
|
+
if (typeof value === "number") {
|
|
336
|
+
if (isSpecial(value)) {
|
|
337
|
+
const buffer = new ArrayBuffer(8);
|
|
338
|
+
new DataView(buffer).setFloat64(0, value, LITTLE_ENDIAN);
|
|
339
|
+
return { $float: fromByteArray(new Uint8Array(buffer)) };
|
|
340
|
+
} else {
|
|
341
|
+
return value;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (typeof value === "boolean") {
|
|
345
|
+
return value;
|
|
346
|
+
}
|
|
347
|
+
if (typeof value === "string") {
|
|
348
|
+
return value;
|
|
349
|
+
}
|
|
350
|
+
if (value instanceof ArrayBuffer) {
|
|
351
|
+
return { $bytes: fromByteArray(new Uint8Array(value)) };
|
|
352
|
+
}
|
|
353
|
+
if (Array.isArray(value)) {
|
|
354
|
+
return value.map(
|
|
355
|
+
(value2, i) => convexToJsonInternal(value2, originalValue, context + `[${i}]`)
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
if (value instanceof Set) {
|
|
359
|
+
throw new Error(
|
|
360
|
+
errorMessageForUnsupportedType(context, "Set", [...value], originalValue)
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
if (value instanceof Map) {
|
|
364
|
+
throw new Error(
|
|
365
|
+
errorMessageForUnsupportedType(context, "Map", [...value], originalValue)
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
if (!isSimpleObject(value)) {
|
|
369
|
+
const theType = value?.constructor?.name;
|
|
370
|
+
const typeName = theType ? `${theType} ` : "";
|
|
371
|
+
throw new Error(
|
|
372
|
+
errorMessageForUnsupportedType(context, typeName, value, originalValue)
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
const out = {};
|
|
376
|
+
const entries = Object.entries(value);
|
|
377
|
+
entries.sort(([k1, _v1], [k2, _v2]) => k1 === k2 ? 0 : k1 < k2 ? -1 : 1);
|
|
378
|
+
for (const [k, v] of entries) {
|
|
379
|
+
if (v !== void 0) {
|
|
380
|
+
validateObjectField(k);
|
|
381
|
+
out[k] = convexToJsonInternal(v, originalValue, context + `.${k}`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return out;
|
|
385
|
+
}
|
|
386
|
+
function errorMessageForUnsupportedType(context, typeName, value, originalValue) {
|
|
387
|
+
if (context) {
|
|
388
|
+
return `${typeName}${stringifyValueForError(
|
|
389
|
+
value
|
|
390
|
+
)} is not a supported Convex type (present at path ${context} in original object ${stringifyValueForError(
|
|
391
|
+
originalValue
|
|
392
|
+
)}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.`;
|
|
393
|
+
} else {
|
|
394
|
+
return `${typeName}${stringifyValueForError(
|
|
395
|
+
value
|
|
396
|
+
)} is not a supported Convex type.`;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function convexOrUndefinedToJsonInternal(value, originalValue, context) {
|
|
400
|
+
if (value === void 0) {
|
|
401
|
+
return { $undefined: null };
|
|
402
|
+
} else {
|
|
403
|
+
if (originalValue === void 0) {
|
|
404
|
+
throw new Error(
|
|
405
|
+
`Programming error. Current value is ${stringifyValueForError(
|
|
406
|
+
value
|
|
407
|
+
)} but original value is undefined`
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
return convexToJsonInternal(value, originalValue, context);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function convexToJson(value) {
|
|
414
|
+
return convexToJsonInternal(value, value, "");
|
|
415
|
+
}
|
|
416
|
+
function convexOrUndefinedToJson(value) {
|
|
417
|
+
return convexOrUndefinedToJsonInternal(value, value, "");
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
var __defProp$3 = Object.defineProperty;
|
|
421
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
422
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
423
|
+
var _a, _b;
|
|
424
|
+
const IDENTIFYING_FIELD = Symbol.for("ConvexError");
|
|
425
|
+
class ConvexError extends (_b = Error, _a = IDENTIFYING_FIELD, _b) {
|
|
426
|
+
constructor(data) {
|
|
427
|
+
super(typeof data === "string" ? data : stringifyValueForError(data));
|
|
428
|
+
__publicField$3(this, "name", "ConvexError");
|
|
429
|
+
__publicField$3(this, "data");
|
|
430
|
+
__publicField$3(this, _a, true);
|
|
431
|
+
this.data = data;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const arr = () => Array.from({ length: 4 }, () => 0);
|
|
436
|
+
arr();
|
|
437
|
+
arr();
|
|
438
|
+
|
|
439
|
+
const version = "1.27.0";
|
|
440
|
+
|
|
441
|
+
async function performAsyncSyscall(op, arg) {
|
|
442
|
+
if (typeof Convex === "undefined" || Convex.asyncSyscall === void 0) {
|
|
443
|
+
throw new Error(
|
|
444
|
+
"The Convex database and auth objects are being used outside of a Convex backend. Did you mean to use `useQuery` or `useMutation` to call a Convex function?"
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
let resultStr;
|
|
448
|
+
try {
|
|
449
|
+
resultStr = await Convex.asyncSyscall(op, JSON.stringify(arg));
|
|
450
|
+
} catch (e) {
|
|
451
|
+
if (e.data !== void 0) {
|
|
452
|
+
const rethrown = new ConvexError(e.message);
|
|
453
|
+
rethrown.data = jsonToConvex(e.data);
|
|
454
|
+
throw rethrown;
|
|
455
|
+
}
|
|
456
|
+
throw new Error(e.message);
|
|
457
|
+
}
|
|
458
|
+
return JSON.parse(resultStr);
|
|
459
|
+
}
|
|
460
|
+
function performJsSyscall(op, arg) {
|
|
461
|
+
if (typeof Convex === "undefined" || Convex.jsSyscall === void 0) {
|
|
462
|
+
throw new Error(
|
|
463
|
+
"The Convex database and auth objects are being used outside of a Convex backend. Did you mean to use `useQuery` or `useMutation` to call a Convex function?"
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
return Convex.jsSyscall(op, arg);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const functionName = Symbol.for("functionName");
|
|
470
|
+
|
|
471
|
+
const toReferencePath = Symbol.for("toReferencePath");
|
|
472
|
+
function setReferencePath(obj, value) {
|
|
473
|
+
obj[toReferencePath] = value;
|
|
474
|
+
}
|
|
475
|
+
function extractReferencePath(reference) {
|
|
476
|
+
return reference[toReferencePath] ?? null;
|
|
477
|
+
}
|
|
478
|
+
function isFunctionHandle(s) {
|
|
479
|
+
return s.startsWith("function://");
|
|
480
|
+
}
|
|
481
|
+
function getFunctionAddress(functionReference) {
|
|
482
|
+
let functionAddress;
|
|
483
|
+
if (typeof functionReference === "string") {
|
|
484
|
+
if (isFunctionHandle(functionReference)) {
|
|
485
|
+
functionAddress = { functionHandle: functionReference };
|
|
486
|
+
} else {
|
|
487
|
+
functionAddress = { name: functionReference };
|
|
488
|
+
}
|
|
489
|
+
} else if (functionReference[functionName]) {
|
|
490
|
+
functionAddress = { name: functionReference[functionName] };
|
|
491
|
+
} else {
|
|
492
|
+
const referencePath = extractReferencePath(functionReference);
|
|
493
|
+
if (!referencePath) {
|
|
494
|
+
throw new Error(`${functionReference} is not a functionReference`);
|
|
495
|
+
}
|
|
496
|
+
functionAddress = { reference: referencePath };
|
|
497
|
+
}
|
|
498
|
+
return functionAddress;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function syscallArgs(requestId, functionReference, args) {
|
|
502
|
+
const address = getFunctionAddress(functionReference);
|
|
503
|
+
return {
|
|
504
|
+
...address,
|
|
505
|
+
args: convexToJson(parseArgs(args)),
|
|
506
|
+
version,
|
|
507
|
+
requestId
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
function setupActionCalls(requestId) {
|
|
511
|
+
return {
|
|
512
|
+
runQuery: async (query, args) => {
|
|
513
|
+
const result = await performAsyncSyscall(
|
|
514
|
+
"1.0/actions/query",
|
|
515
|
+
syscallArgs(requestId, query, args)
|
|
516
|
+
);
|
|
517
|
+
return jsonToConvex(result);
|
|
518
|
+
},
|
|
519
|
+
runMutation: async (mutation, args) => {
|
|
520
|
+
const result = await performAsyncSyscall(
|
|
521
|
+
"1.0/actions/mutation",
|
|
522
|
+
syscallArgs(requestId, mutation, args)
|
|
523
|
+
);
|
|
524
|
+
return jsonToConvex(result);
|
|
525
|
+
},
|
|
526
|
+
runAction: async (action, args) => {
|
|
527
|
+
const result = await performAsyncSyscall(
|
|
528
|
+
"1.0/actions/action",
|
|
529
|
+
syscallArgs(requestId, action, args)
|
|
530
|
+
);
|
|
531
|
+
return jsonToConvex(result);
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
var __defProp$2 = Object.defineProperty;
|
|
537
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
538
|
+
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
539
|
+
class FilterExpression {
|
|
540
|
+
/**
|
|
541
|
+
* @internal
|
|
542
|
+
*/
|
|
543
|
+
constructor() {
|
|
544
|
+
// Property for nominal type support.
|
|
545
|
+
__publicField$2(this, "_isExpression");
|
|
546
|
+
// Property to distinguish expressions by the type they resolve to.
|
|
547
|
+
__publicField$2(this, "_value");
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function validateArg(arg, idx, method, argName) {
|
|
552
|
+
if (arg === void 0) {
|
|
553
|
+
throw new TypeError(
|
|
554
|
+
`Must provide arg ${idx} \`${argName}\` to \`${method}\``
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
var __defProp$1 = Object.defineProperty;
|
|
560
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
561
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
562
|
+
function setupActionVectorSearch(requestId) {
|
|
563
|
+
return async (tableName, indexName, query) => {
|
|
564
|
+
validateArg(tableName, 1, "vectorSearch", "tableName");
|
|
565
|
+
validateArg(indexName, 2, "vectorSearch", "indexName");
|
|
566
|
+
validateArg(query, 3, "vectorSearch", "query");
|
|
567
|
+
if (!query.vector || !Array.isArray(query.vector) || query.vector.length === 0) {
|
|
568
|
+
throw Error("`vector` must be a non-empty Array in vectorSearch");
|
|
569
|
+
}
|
|
570
|
+
return await new VectorQueryImpl(
|
|
571
|
+
requestId,
|
|
572
|
+
tableName + "." + indexName,
|
|
573
|
+
query
|
|
574
|
+
).collect();
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
class VectorQueryImpl {
|
|
578
|
+
constructor(requestId, indexName, query) {
|
|
579
|
+
__publicField$1(this, "requestId");
|
|
580
|
+
__publicField$1(this, "state");
|
|
581
|
+
this.requestId = requestId;
|
|
582
|
+
const filters = query.filter ? serializeExpression(query.filter(filterBuilderImpl)) : null;
|
|
583
|
+
this.state = {
|
|
584
|
+
type: "preparing",
|
|
585
|
+
query: {
|
|
586
|
+
indexName,
|
|
587
|
+
limit: query.limit,
|
|
588
|
+
vector: query.vector,
|
|
589
|
+
expressions: filters
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
async collect() {
|
|
594
|
+
if (this.state.type === "consumed") {
|
|
595
|
+
throw new Error("This query is closed and can't emit any more values.");
|
|
596
|
+
}
|
|
597
|
+
const query = this.state.query;
|
|
598
|
+
this.state = { type: "consumed" };
|
|
599
|
+
const { results } = await performAsyncSyscall("1.0/actions/vectorSearch", {
|
|
600
|
+
requestId: this.requestId,
|
|
601
|
+
version,
|
|
602
|
+
query
|
|
603
|
+
});
|
|
604
|
+
return results;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
class ExpressionImpl extends FilterExpression {
|
|
608
|
+
constructor(inner) {
|
|
609
|
+
super();
|
|
610
|
+
__publicField$1(this, "inner");
|
|
611
|
+
this.inner = inner;
|
|
612
|
+
}
|
|
613
|
+
serialize() {
|
|
614
|
+
return this.inner;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
function serializeExpression(expr) {
|
|
618
|
+
if (expr instanceof ExpressionImpl) {
|
|
619
|
+
return expr.serialize();
|
|
620
|
+
} else {
|
|
621
|
+
return { $literal: convexOrUndefinedToJson(expr) };
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
const filterBuilderImpl = {
|
|
625
|
+
// Comparisons /////////////////////////////////////////////////////////////
|
|
626
|
+
eq(fieldName, value) {
|
|
627
|
+
if (typeof fieldName !== "string") {
|
|
628
|
+
throw new Error("The first argument to `q.eq` must be a field name.");
|
|
629
|
+
}
|
|
630
|
+
return new ExpressionImpl({
|
|
631
|
+
$eq: [
|
|
632
|
+
serializeExpression(new ExpressionImpl({ $field: fieldName })),
|
|
633
|
+
serializeExpression(value)
|
|
634
|
+
]
|
|
635
|
+
});
|
|
636
|
+
},
|
|
637
|
+
// Logic ///////////////////////////////////////////////////////////////////
|
|
638
|
+
or(...exprs) {
|
|
639
|
+
return new ExpressionImpl({ $or: exprs.map(serializeExpression) });
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
function setupAuth(requestId) {
|
|
644
|
+
return {
|
|
645
|
+
getUserIdentity: async () => {
|
|
646
|
+
return await performAsyncSyscall("1.0/getUserIdentity", {
|
|
647
|
+
requestId
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
function setupActionScheduler(requestId) {
|
|
654
|
+
return {
|
|
655
|
+
runAfter: async (delayMs, functionReference, args) => {
|
|
656
|
+
const syscallArgs = {
|
|
657
|
+
requestId,
|
|
658
|
+
...runAfterSyscallArgs(delayMs, functionReference, args)
|
|
659
|
+
};
|
|
660
|
+
return await performAsyncSyscall("1.0/actions/schedule", syscallArgs);
|
|
661
|
+
},
|
|
662
|
+
runAt: async (ms_since_epoch_or_date, functionReference, args) => {
|
|
663
|
+
const syscallArgs = {
|
|
664
|
+
requestId,
|
|
665
|
+
...runAtSyscallArgs(ms_since_epoch_or_date, functionReference, args)
|
|
666
|
+
};
|
|
667
|
+
return await performAsyncSyscall("1.0/actions/schedule", syscallArgs);
|
|
668
|
+
},
|
|
669
|
+
cancel: async (id) => {
|
|
670
|
+
validateArg(id, 1, "cancel", "id");
|
|
671
|
+
const syscallArgs = { id: convexToJson(id) };
|
|
672
|
+
return await performAsyncSyscall("1.0/actions/cancel_job", syscallArgs);
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
function runAfterSyscallArgs(delayMs, functionReference, args) {
|
|
677
|
+
if (typeof delayMs !== "number") {
|
|
678
|
+
throw new Error("`delayMs` must be a number");
|
|
679
|
+
}
|
|
680
|
+
if (!isFinite(delayMs)) {
|
|
681
|
+
throw new Error("`delayMs` must be a finite number");
|
|
682
|
+
}
|
|
683
|
+
if (delayMs < 0) {
|
|
684
|
+
throw new Error("`delayMs` must be non-negative");
|
|
685
|
+
}
|
|
686
|
+
const functionArgs = parseArgs(args);
|
|
687
|
+
const address = getFunctionAddress(functionReference);
|
|
688
|
+
const ts = (Date.now() + delayMs) / 1e3;
|
|
689
|
+
return {
|
|
690
|
+
...address,
|
|
691
|
+
ts,
|
|
692
|
+
args: convexToJson(functionArgs),
|
|
693
|
+
version
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
function runAtSyscallArgs(ms_since_epoch_or_date, functionReference, args) {
|
|
697
|
+
let ts;
|
|
698
|
+
if (ms_since_epoch_or_date instanceof Date) {
|
|
699
|
+
ts = ms_since_epoch_or_date.valueOf() / 1e3;
|
|
700
|
+
} else if (typeof ms_since_epoch_or_date === "number") {
|
|
701
|
+
ts = ms_since_epoch_or_date / 1e3;
|
|
702
|
+
} else {
|
|
703
|
+
throw new Error("The invoke time must a Date or a timestamp");
|
|
704
|
+
}
|
|
705
|
+
const address = getFunctionAddress(functionReference);
|
|
706
|
+
const functionArgs = parseArgs(args);
|
|
707
|
+
return {
|
|
708
|
+
...address,
|
|
709
|
+
ts,
|
|
710
|
+
args: convexToJson(functionArgs),
|
|
711
|
+
version
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
function setupStorageReader(requestId) {
|
|
716
|
+
return {
|
|
717
|
+
getUrl: async (storageId) => {
|
|
718
|
+
validateArg(storageId, 1, "getUrl", "storageId");
|
|
719
|
+
return await performAsyncSyscall("1.0/storageGetUrl", {
|
|
720
|
+
requestId,
|
|
721
|
+
version,
|
|
722
|
+
storageId
|
|
723
|
+
});
|
|
724
|
+
},
|
|
725
|
+
getMetadata: async (storageId) => {
|
|
726
|
+
return await performAsyncSyscall("1.0/storageGetMetadata", {
|
|
727
|
+
requestId,
|
|
728
|
+
version,
|
|
729
|
+
storageId
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
function setupStorageWriter(requestId) {
|
|
735
|
+
const reader = setupStorageReader(requestId);
|
|
736
|
+
return {
|
|
737
|
+
generateUploadUrl: async () => {
|
|
738
|
+
return await performAsyncSyscall("1.0/storageGenerateUploadUrl", {
|
|
739
|
+
requestId,
|
|
740
|
+
version
|
|
741
|
+
});
|
|
742
|
+
},
|
|
743
|
+
delete: async (storageId) => {
|
|
744
|
+
await performAsyncSyscall("1.0/storageDelete", {
|
|
745
|
+
requestId,
|
|
746
|
+
version,
|
|
747
|
+
storageId
|
|
748
|
+
});
|
|
749
|
+
},
|
|
750
|
+
getUrl: reader.getUrl,
|
|
751
|
+
getMetadata: reader.getMetadata
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
function setupStorageActionWriter(requestId) {
|
|
755
|
+
const writer = setupStorageWriter(requestId);
|
|
756
|
+
return {
|
|
757
|
+
...writer,
|
|
758
|
+
store: async (blob, options) => {
|
|
759
|
+
return await performJsSyscall("storage/storeBlob", {
|
|
760
|
+
requestId,
|
|
761
|
+
version,
|
|
762
|
+
blob,
|
|
763
|
+
options
|
|
764
|
+
});
|
|
765
|
+
},
|
|
766
|
+
get: async (storageId) => {
|
|
767
|
+
return await performJsSyscall("storage/getBlob", {
|
|
768
|
+
requestId,
|
|
769
|
+
version,
|
|
770
|
+
storageId
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
async function invokeFunction(func, ctx, args) {
|
|
777
|
+
let result;
|
|
778
|
+
try {
|
|
779
|
+
result = await Promise.resolve(func(ctx, ...args));
|
|
780
|
+
} catch (thrown) {
|
|
781
|
+
throw serializeConvexErrorData(thrown);
|
|
782
|
+
}
|
|
783
|
+
return result;
|
|
784
|
+
}
|
|
785
|
+
function dontCallDirectly(funcType, handler) {
|
|
786
|
+
return (ctx, args) => {
|
|
787
|
+
globalThis.console.warn(
|
|
788
|
+
`Convex functions should not directly call other Convex functions. Consider calling a helper function instead. e.g. \`export const foo = ${funcType}(...); await foo(ctx);\` is not supported. See https://docs.convex.dev/production/best-practices/#use-helper-functions-to-write-shared-code`
|
|
789
|
+
);
|
|
790
|
+
return handler(ctx, args);
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
function serializeConvexErrorData(thrown) {
|
|
794
|
+
if (typeof thrown === "object" && thrown !== null && Symbol.for("ConvexError") in thrown) {
|
|
795
|
+
const error = thrown;
|
|
796
|
+
error.data = JSON.stringify(
|
|
797
|
+
convexToJson(error.data === void 0 ? null : error.data)
|
|
798
|
+
);
|
|
799
|
+
error.ConvexErrorSymbol = Symbol.for("ConvexError");
|
|
800
|
+
return error;
|
|
801
|
+
} else {
|
|
802
|
+
return thrown;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
function assertNotBrowser() {
|
|
806
|
+
if (typeof window === "undefined" || window.__convexAllowFunctionsInBrowser) {
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
const isRealBrowser = Object.getOwnPropertyDescriptor(globalThis, "window")?.get?.toString().includes("[native code]") ?? false;
|
|
810
|
+
if (isRealBrowser) {
|
|
811
|
+
console.error(
|
|
812
|
+
"Convex functions should not be imported in the browser. This will throw an error in future versions of `convex`. If this is a false negative, please report it to Convex support."
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
async function invokeHttpAction(func, request) {
|
|
817
|
+
const requestId = "";
|
|
818
|
+
const calls = setupActionCalls(requestId);
|
|
819
|
+
const ctx = {
|
|
820
|
+
...calls,
|
|
821
|
+
auth: setupAuth(requestId),
|
|
822
|
+
storage: setupStorageActionWriter(requestId),
|
|
823
|
+
scheduler: setupActionScheduler(requestId),
|
|
824
|
+
vectorSearch: setupActionVectorSearch(requestId)
|
|
825
|
+
};
|
|
826
|
+
return await invokeFunction(func, ctx, [request]);
|
|
827
|
+
}
|
|
828
|
+
const httpActionGeneric = (func) => {
|
|
829
|
+
const q = dontCallDirectly("httpAction", func);
|
|
830
|
+
assertNotBrowser();
|
|
831
|
+
q.isHttp = true;
|
|
832
|
+
q.invokeHttpAction = (request) => invokeHttpAction(func, request);
|
|
833
|
+
q._handler = func;
|
|
834
|
+
return q;
|
|
835
|
+
};
|
|
836
|
+
|
|
837
|
+
var __defProp = Object.defineProperty;
|
|
838
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
839
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
840
|
+
class InstalledComponent {
|
|
841
|
+
constructor(definition, name) {
|
|
842
|
+
/**
|
|
843
|
+
* @internal
|
|
844
|
+
*/
|
|
845
|
+
__publicField(this, "_definition");
|
|
846
|
+
/**
|
|
847
|
+
* @internal
|
|
848
|
+
*/
|
|
849
|
+
__publicField(this, "_name");
|
|
850
|
+
this._definition = definition;
|
|
851
|
+
this._name = name;
|
|
852
|
+
setReferencePath(this, `_reference/childComponent/${name}`);
|
|
853
|
+
}
|
|
854
|
+
get exports() {
|
|
855
|
+
return createExports(this._name, []);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
function createExports(name, pathParts) {
|
|
859
|
+
const handler = {
|
|
860
|
+
get(_, prop) {
|
|
861
|
+
if (typeof prop === "string") {
|
|
862
|
+
const newParts = [...pathParts, prop];
|
|
863
|
+
return createExports(name, newParts);
|
|
864
|
+
} else if (prop === toReferencePath) {
|
|
865
|
+
let reference = `_reference/childComponent/${name}`;
|
|
866
|
+
for (const part of pathParts) {
|
|
867
|
+
reference += `/${part}`;
|
|
868
|
+
}
|
|
869
|
+
return reference;
|
|
870
|
+
} else {
|
|
871
|
+
return void 0;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
return new Proxy({}, handler);
|
|
876
|
+
}
|
|
877
|
+
function use(definition, options) {
|
|
878
|
+
const importedComponentDefinition = definition;
|
|
879
|
+
if (typeof importedComponentDefinition.componentDefinitionPath !== "string") {
|
|
880
|
+
throw new Error(
|
|
881
|
+
"Component definition does not have the required componentDefinitionPath property. This code only works in Convex runtime."
|
|
882
|
+
);
|
|
883
|
+
}
|
|
884
|
+
const name = options?.name || // added recently
|
|
885
|
+
importedComponentDefinition.defaultName || // can be removed once backend is out
|
|
886
|
+
importedComponentDefinition.componentDefinitionPath.split("/").pop();
|
|
887
|
+
this._childComponents.push([name, importedComponentDefinition, {}]);
|
|
888
|
+
return new InstalledComponent(definition, name);
|
|
889
|
+
}
|
|
890
|
+
function serializeExportTree(tree) {
|
|
891
|
+
const branch = [];
|
|
892
|
+
for (const [key, child] of Object.entries(tree)) {
|
|
893
|
+
let node;
|
|
894
|
+
if (typeof child === "string") {
|
|
895
|
+
node = { type: "leaf", leaf: child };
|
|
896
|
+
} else {
|
|
897
|
+
node = serializeExportTree(child);
|
|
898
|
+
}
|
|
899
|
+
branch.push([key, node]);
|
|
900
|
+
}
|
|
901
|
+
return { type: "branch", branch };
|
|
902
|
+
}
|
|
903
|
+
function serializeChildComponents(childComponents) {
|
|
904
|
+
return childComponents.map(([name, definition, p]) => {
|
|
905
|
+
let args = null;
|
|
906
|
+
if (p !== null) {
|
|
907
|
+
args = [];
|
|
908
|
+
for (const [name2, value] of Object.entries(p)) {
|
|
909
|
+
if (value !== void 0) {
|
|
910
|
+
args.push([
|
|
911
|
+
name2,
|
|
912
|
+
{ type: "value", value: JSON.stringify(convexToJson(value)) }
|
|
913
|
+
]);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
const path = definition.componentDefinitionPath;
|
|
918
|
+
if (!path)
|
|
919
|
+
throw new Error(
|
|
920
|
+
"no .componentPath for component definition " + JSON.stringify(definition, null, 2)
|
|
921
|
+
);
|
|
922
|
+
return {
|
|
923
|
+
name,
|
|
924
|
+
path,
|
|
925
|
+
args
|
|
926
|
+
};
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
function exportComponentForAnalysis() {
|
|
930
|
+
const args = Object.entries(
|
|
931
|
+
this._args
|
|
932
|
+
).map(([name, validator]) => [
|
|
933
|
+
name,
|
|
934
|
+
{
|
|
935
|
+
type: "value",
|
|
936
|
+
value: JSON.stringify(validator.json)
|
|
937
|
+
}
|
|
938
|
+
]);
|
|
939
|
+
const definitionType = {
|
|
940
|
+
type: "childComponent",
|
|
941
|
+
name: this._name,
|
|
942
|
+
args
|
|
943
|
+
};
|
|
944
|
+
const childComponents = serializeChildComponents(this._childComponents);
|
|
945
|
+
return {
|
|
946
|
+
name: this._name,
|
|
947
|
+
definitionType,
|
|
948
|
+
childComponents,
|
|
949
|
+
httpMounts: {},
|
|
950
|
+
exports: serializeExportTree(this._exportTree)
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
function defineComponent(name) {
|
|
954
|
+
const ret = {
|
|
955
|
+
_isRoot: false,
|
|
956
|
+
_name: name,
|
|
957
|
+
_args: {},
|
|
958
|
+
_childComponents: [],
|
|
959
|
+
_exportTree: {},
|
|
960
|
+
_onInitCallbacks: {},
|
|
961
|
+
export: exportComponentForAnalysis,
|
|
962
|
+
use,
|
|
963
|
+
// pretend to conform to ComponentDefinition, which temporarily expects __args
|
|
964
|
+
...{}
|
|
965
|
+
};
|
|
966
|
+
return ret;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
var convex_config = defineComponent("dodopayments");
|
|
970
|
+
|
|
971
|
+
/* eslint-disable */
|
|
972
|
+
/**
|
|
973
|
+
* Generated utilities for implementing server-side Convex query and mutation functions.
|
|
974
|
+
*
|
|
975
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
976
|
+
*
|
|
977
|
+
* To regenerate, run `npx convex dev`.
|
|
978
|
+
* @module
|
|
979
|
+
*/
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
/**
|
|
983
|
+
* Define a Convex HTTP action.
|
|
984
|
+
*
|
|
985
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument, and a `Request` object
|
|
986
|
+
* as its second.
|
|
987
|
+
* @returns The wrapped endpoint function. Route a URL path to this function in `convex/http.js`.
|
|
988
|
+
*/
|
|
989
|
+
const httpAction = httpActionGeneric;
|
|
990
|
+
|
|
991
|
+
var PaymentSchema = z.object({
|
|
992
|
+
payload_type: z.literal("Payment"),
|
|
993
|
+
billing: z.object({
|
|
994
|
+
city: z.string().nullable(),
|
|
995
|
+
country: z.string().nullable(),
|
|
996
|
+
state: z.string().nullable(),
|
|
997
|
+
street: z.string().nullable(),
|
|
998
|
+
zipcode: z.string().nullable(),
|
|
999
|
+
}),
|
|
1000
|
+
brand_id: z.string(),
|
|
1001
|
+
business_id: z.string(),
|
|
1002
|
+
card_issuing_country: z.string().nullable(),
|
|
1003
|
+
card_last_four: z.string().nullable(),
|
|
1004
|
+
card_network: z.string().nullable(),
|
|
1005
|
+
card_type: z.string().nullable(),
|
|
1006
|
+
created_at: z.string().transform(function (d) { return new Date(d); }),
|
|
1007
|
+
currency: z.string(),
|
|
1008
|
+
customer: z.object({
|
|
1009
|
+
customer_id: z.string(),
|
|
1010
|
+
email: z.string(),
|
|
1011
|
+
name: z.string().nullable(),
|
|
1012
|
+
}),
|
|
1013
|
+
digital_products_delivered: z.boolean(),
|
|
1014
|
+
discount_id: z.string().nullable(),
|
|
1015
|
+
disputes: z
|
|
1016
|
+
.array(z.object({
|
|
1017
|
+
amount: z.string(),
|
|
1018
|
+
business_id: z.string(),
|
|
1019
|
+
created_at: z.string().transform(function (d) { return new Date(d); }),
|
|
1020
|
+
currency: z.string(),
|
|
1021
|
+
dispute_id: z.string(),
|
|
1022
|
+
dispute_stage: z.enum([
|
|
1023
|
+
"pre_dispute",
|
|
1024
|
+
"dispute_opened",
|
|
1025
|
+
"dispute_won",
|
|
1026
|
+
"dispute_lost",
|
|
1027
|
+
]),
|
|
1028
|
+
dispute_status: z.enum([
|
|
1029
|
+
"dispute_opened",
|
|
1030
|
+
"dispute_won",
|
|
1031
|
+
"dispute_lost",
|
|
1032
|
+
"dispute_accepted",
|
|
1033
|
+
"dispute_cancelled",
|
|
1034
|
+
"dispute_challenged",
|
|
1035
|
+
]),
|
|
1036
|
+
payment_id: z.string(),
|
|
1037
|
+
remarks: z.string().nullable(),
|
|
1038
|
+
}))
|
|
1039
|
+
.nullable(),
|
|
1040
|
+
error_code: z.string().nullable(),
|
|
1041
|
+
error_message: z.string().nullable(),
|
|
1042
|
+
metadata: z.record(z.any()).nullable(),
|
|
1043
|
+
payment_id: z.string(),
|
|
1044
|
+
payment_link: z.string().nullable(),
|
|
1045
|
+
payment_method: z.string().nullable(),
|
|
1046
|
+
payment_method_type: z.string().nullable(),
|
|
1047
|
+
product_cart: z
|
|
1048
|
+
.array(z.object({
|
|
1049
|
+
product_id: z.string(),
|
|
1050
|
+
quantity: z.number(),
|
|
1051
|
+
}))
|
|
1052
|
+
.nullable(),
|
|
1053
|
+
refunds: z
|
|
1054
|
+
.array(z.object({
|
|
1055
|
+
amount: z.number(),
|
|
1056
|
+
business_id: z.string(),
|
|
1057
|
+
created_at: z.string().transform(function (d) { return new Date(d); }),
|
|
1058
|
+
currency: z.string(),
|
|
1059
|
+
is_partial: z.boolean(),
|
|
1060
|
+
payment_id: z.string(),
|
|
1061
|
+
reason: z.string().nullable(),
|
|
1062
|
+
refund_id: z.string(),
|
|
1063
|
+
status: z.enum(["succeeded", "failed", "pending"]),
|
|
1064
|
+
}))
|
|
1065
|
+
.nullable(),
|
|
1066
|
+
settlement_amount: z.number(),
|
|
1067
|
+
settlement_currency: z.string(),
|
|
1068
|
+
settlement_tax: z.number().nullable(),
|
|
1069
|
+
status: z.enum(["succeeded", "failed", "pending", "processing", "cancelled"]),
|
|
1070
|
+
subscription_id: z.string().nullable(),
|
|
1071
|
+
tax: z.number().nullable(),
|
|
1072
|
+
total_amount: z.number(),
|
|
1073
|
+
updated_at: z
|
|
1074
|
+
.string()
|
|
1075
|
+
.transform(function (d) { return new Date(d); })
|
|
1076
|
+
.nullable(),
|
|
1077
|
+
});
|
|
1078
|
+
var SubscriptionSchema = z.object({
|
|
1079
|
+
payload_type: z.literal("Subscription"),
|
|
1080
|
+
addons: z
|
|
1081
|
+
.array(z.object({
|
|
1082
|
+
addon_id: z.string(),
|
|
1083
|
+
quantity: z.number(),
|
|
1084
|
+
}))
|
|
1085
|
+
.nullable(),
|
|
1086
|
+
billing: z.object({
|
|
1087
|
+
city: z.string().nullable(),
|
|
1088
|
+
country: z.string().nullable(),
|
|
1089
|
+
state: z.string().nullable(),
|
|
1090
|
+
street: z.string().nullable(),
|
|
1091
|
+
zipcode: z.string().nullable(),
|
|
1092
|
+
}),
|
|
1093
|
+
cancel_at_next_billing_date: z.boolean(),
|
|
1094
|
+
cancelled_at: z
|
|
1095
|
+
.string()
|
|
1096
|
+
.transform(function (d) { return new Date(d); })
|
|
1097
|
+
.nullable(),
|
|
1098
|
+
created_at: z.string().transform(function (d) { return new Date(d); }),
|
|
1099
|
+
currency: z.string(),
|
|
1100
|
+
customer: z.object({
|
|
1101
|
+
customer_id: z.string(),
|
|
1102
|
+
email: z.string(),
|
|
1103
|
+
name: z.string().nullable(),
|
|
1104
|
+
}),
|
|
1105
|
+
discount_id: z.string().nullable(),
|
|
1106
|
+
metadata: z.record(z.any()).nullable(),
|
|
1107
|
+
next_billing_date: z
|
|
1108
|
+
.string()
|
|
1109
|
+
.transform(function (d) { return new Date(d); })
|
|
1110
|
+
.nullable(),
|
|
1111
|
+
on_demand: z.boolean(),
|
|
1112
|
+
payment_frequency_count: z.number(),
|
|
1113
|
+
payment_frequency_interval: z.enum(["Day", "Week", "Month", "Year"]),
|
|
1114
|
+
previous_billing_date: z
|
|
1115
|
+
.string()
|
|
1116
|
+
.transform(function (d) { return new Date(d); })
|
|
1117
|
+
.nullable(),
|
|
1118
|
+
product_id: z.string(),
|
|
1119
|
+
quantity: z.number(),
|
|
1120
|
+
recurring_pre_tax_amount: z.number(),
|
|
1121
|
+
status: z.enum([
|
|
1122
|
+
"pending",
|
|
1123
|
+
"active",
|
|
1124
|
+
"on_hold",
|
|
1125
|
+
"paused",
|
|
1126
|
+
"cancelled",
|
|
1127
|
+
"expired",
|
|
1128
|
+
"failed",
|
|
1129
|
+
]),
|
|
1130
|
+
subscription_id: z.string(),
|
|
1131
|
+
subscription_period_count: z.number(),
|
|
1132
|
+
subscription_period_interval: z.enum(["Day", "Week", "Month", "Year"]),
|
|
1133
|
+
tax_inclusive: z.boolean(),
|
|
1134
|
+
trial_period_days: z.number(),
|
|
1135
|
+
});
|
|
1136
|
+
var RefundSchema = z.object({
|
|
1137
|
+
payload_type: z.literal("Refund"),
|
|
1138
|
+
amount: z.number(),
|
|
1139
|
+
business_id: z.string(),
|
|
1140
|
+
created_at: z.string().transform(function (d) { return new Date(d); }),
|
|
1141
|
+
currency: z.string(),
|
|
1142
|
+
is_partial: z.boolean(),
|
|
1143
|
+
payment_id: z.string(),
|
|
1144
|
+
reason: z.string().nullable(),
|
|
1145
|
+
refund_id: z.string(),
|
|
1146
|
+
status: z.enum(["succeeded", "failed", "pending"]),
|
|
1147
|
+
});
|
|
1148
|
+
var DisputeSchema = z.object({
|
|
1149
|
+
payload_type: z.literal("Dispute"),
|
|
1150
|
+
amount: z.string(),
|
|
1151
|
+
business_id: z.string(),
|
|
1152
|
+
created_at: z.string().transform(function (d) { return new Date(d); }),
|
|
1153
|
+
currency: z.string(),
|
|
1154
|
+
dispute_id: z.string(),
|
|
1155
|
+
dispute_stage: z.enum([
|
|
1156
|
+
"pre_dispute",
|
|
1157
|
+
"dispute_opened",
|
|
1158
|
+
"dispute_won",
|
|
1159
|
+
"dispute_lost",
|
|
1160
|
+
]),
|
|
1161
|
+
dispute_status: z.enum([
|
|
1162
|
+
"dispute_opened",
|
|
1163
|
+
"dispute_won",
|
|
1164
|
+
"dispute_lost",
|
|
1165
|
+
"dispute_accepted",
|
|
1166
|
+
"dispute_cancelled",
|
|
1167
|
+
"dispute_challenged",
|
|
1168
|
+
]),
|
|
1169
|
+
payment_id: z.string(),
|
|
1170
|
+
remarks: z.string().nullable(),
|
|
1171
|
+
});
|
|
1172
|
+
var LicenseKeySchema = z.object({
|
|
1173
|
+
payload_type: z.literal("LicenseKey"),
|
|
1174
|
+
activations_limit: z.number(),
|
|
1175
|
+
business_id: z.string(),
|
|
1176
|
+
created_at: z.string().transform(function (d) { return new Date(d); }),
|
|
1177
|
+
customer_id: z.string(),
|
|
1178
|
+
expires_at: z
|
|
1179
|
+
.string()
|
|
1180
|
+
.transform(function (d) { return new Date(d); })
|
|
1181
|
+
.nullable(),
|
|
1182
|
+
id: z.string(),
|
|
1183
|
+
instances_count: z.number(),
|
|
1184
|
+
key: z.string(),
|
|
1185
|
+
payment_id: z.string(),
|
|
1186
|
+
product_id: z.string(),
|
|
1187
|
+
status: z.enum(["active", "inactive", "expired"]),
|
|
1188
|
+
subscription_id: z.string().nullable(),
|
|
1189
|
+
});
|
|
1190
|
+
var PaymentSucceededPayloadSchema = z.object({
|
|
1191
|
+
business_id: z.string(),
|
|
1192
|
+
type: z.literal("payment.succeeded"),
|
|
1193
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1194
|
+
data: PaymentSchema,
|
|
1195
|
+
});
|
|
1196
|
+
var PaymentFailedPayloadSchema = z.object({
|
|
1197
|
+
business_id: z.string(),
|
|
1198
|
+
type: z.literal("payment.failed"),
|
|
1199
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1200
|
+
data: PaymentSchema,
|
|
1201
|
+
});
|
|
1202
|
+
var PaymentProcessingPayloadSchema = z.object({
|
|
1203
|
+
business_id: z.string(),
|
|
1204
|
+
type: z.literal("payment.processing"),
|
|
1205
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1206
|
+
data: PaymentSchema,
|
|
1207
|
+
});
|
|
1208
|
+
var PaymentCancelledPayloadSchema = z.object({
|
|
1209
|
+
business_id: z.string(),
|
|
1210
|
+
type: z.literal("payment.cancelled"),
|
|
1211
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1212
|
+
data: PaymentSchema,
|
|
1213
|
+
});
|
|
1214
|
+
var RefundSucceededPayloadSchema = z.object({
|
|
1215
|
+
business_id: z.string(),
|
|
1216
|
+
type: z.literal("refund.succeeded"),
|
|
1217
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1218
|
+
data: RefundSchema,
|
|
1219
|
+
});
|
|
1220
|
+
var RefundFailedPayloadSchema = z.object({
|
|
1221
|
+
business_id: z.string(),
|
|
1222
|
+
type: z.literal("refund.failed"),
|
|
1223
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1224
|
+
data: RefundSchema,
|
|
1225
|
+
});
|
|
1226
|
+
var DisputeOpenedPayloadSchema = z.object({
|
|
1227
|
+
business_id: z.string(),
|
|
1228
|
+
type: z.literal("dispute.opened"),
|
|
1229
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1230
|
+
data: DisputeSchema,
|
|
1231
|
+
});
|
|
1232
|
+
var DisputeExpiredPayloadSchema = z.object({
|
|
1233
|
+
business_id: z.string(),
|
|
1234
|
+
type: z.literal("dispute.expired"),
|
|
1235
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1236
|
+
data: DisputeSchema,
|
|
1237
|
+
});
|
|
1238
|
+
var DisputeAcceptedPayloadSchema = z.object({
|
|
1239
|
+
business_id: z.string(),
|
|
1240
|
+
type: z.literal("dispute.accepted"),
|
|
1241
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1242
|
+
data: DisputeSchema,
|
|
1243
|
+
});
|
|
1244
|
+
var DisputeCancelledPayloadSchema = z.object({
|
|
1245
|
+
business_id: z.string(),
|
|
1246
|
+
type: z.literal("dispute.cancelled"),
|
|
1247
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1248
|
+
data: DisputeSchema,
|
|
1249
|
+
});
|
|
1250
|
+
var DisputeChallengedPayloadSchema = z.object({
|
|
1251
|
+
business_id: z.string(),
|
|
1252
|
+
type: z.literal("dispute.challenged"),
|
|
1253
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1254
|
+
data: DisputeSchema,
|
|
1255
|
+
});
|
|
1256
|
+
var DisputeWonPayloadSchema = z.object({
|
|
1257
|
+
business_id: z.string(),
|
|
1258
|
+
type: z.literal("dispute.won"),
|
|
1259
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1260
|
+
data: DisputeSchema,
|
|
1261
|
+
});
|
|
1262
|
+
var DisputeLostPayloadSchema = z.object({
|
|
1263
|
+
business_id: z.string(),
|
|
1264
|
+
type: z.literal("dispute.lost"),
|
|
1265
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1266
|
+
data: DisputeSchema,
|
|
1267
|
+
});
|
|
1268
|
+
var SubscriptionActivePayloadSchema = z.object({
|
|
1269
|
+
business_id: z.string(),
|
|
1270
|
+
type: z.literal("subscription.active"),
|
|
1271
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1272
|
+
data: SubscriptionSchema,
|
|
1273
|
+
});
|
|
1274
|
+
var SubscriptionOnHoldPayloadSchema = z.object({
|
|
1275
|
+
business_id: z.string(),
|
|
1276
|
+
type: z.literal("subscription.on_hold"),
|
|
1277
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1278
|
+
data: SubscriptionSchema,
|
|
1279
|
+
});
|
|
1280
|
+
var SubscriptionRenewedPayloadSchema = z.object({
|
|
1281
|
+
business_id: z.string(),
|
|
1282
|
+
type: z.literal("subscription.renewed"),
|
|
1283
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1284
|
+
data: SubscriptionSchema,
|
|
1285
|
+
});
|
|
1286
|
+
var SubscriptionPausedPayloadSchema = z.object({
|
|
1287
|
+
business_id: z.string(),
|
|
1288
|
+
type: z.literal("subscription.paused"),
|
|
1289
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1290
|
+
data: SubscriptionSchema,
|
|
1291
|
+
});
|
|
1292
|
+
var SubscriptionPlanChangedPayloadSchema = z.object({
|
|
1293
|
+
business_id: z.string(),
|
|
1294
|
+
type: z.literal("subscription.plan_changed"),
|
|
1295
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1296
|
+
data: SubscriptionSchema,
|
|
1297
|
+
});
|
|
1298
|
+
var SubscriptionCancelledPayloadSchema = z.object({
|
|
1299
|
+
business_id: z.string(),
|
|
1300
|
+
type: z.literal("subscription.cancelled"),
|
|
1301
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1302
|
+
data: SubscriptionSchema,
|
|
1303
|
+
});
|
|
1304
|
+
var SubscriptionFailedPayloadSchema = z.object({
|
|
1305
|
+
business_id: z.string(),
|
|
1306
|
+
type: z.literal("subscription.failed"),
|
|
1307
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1308
|
+
data: SubscriptionSchema,
|
|
1309
|
+
});
|
|
1310
|
+
var SubscriptionExpiredPayloadSchema = z.object({
|
|
1311
|
+
business_id: z.string(),
|
|
1312
|
+
type: z.literal("subscription.expired"),
|
|
1313
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1314
|
+
data: SubscriptionSchema,
|
|
1315
|
+
});
|
|
1316
|
+
var LicenseKeyCreatedPayloadSchema = z.object({
|
|
1317
|
+
business_id: z.string(),
|
|
1318
|
+
type: z.literal("license_key.created"),
|
|
1319
|
+
timestamp: z.string().transform(function (d) { return new Date(d); }),
|
|
1320
|
+
data: LicenseKeySchema,
|
|
1321
|
+
});
|
|
1322
|
+
var WebhookPayloadSchema = z.discriminatedUnion("type", [
|
|
1323
|
+
PaymentSucceededPayloadSchema,
|
|
1324
|
+
PaymentFailedPayloadSchema,
|
|
1325
|
+
PaymentProcessingPayloadSchema,
|
|
1326
|
+
PaymentCancelledPayloadSchema,
|
|
1327
|
+
RefundSucceededPayloadSchema,
|
|
1328
|
+
RefundFailedPayloadSchema,
|
|
1329
|
+
DisputeOpenedPayloadSchema,
|
|
1330
|
+
DisputeExpiredPayloadSchema,
|
|
1331
|
+
DisputeAcceptedPayloadSchema,
|
|
1332
|
+
DisputeCancelledPayloadSchema,
|
|
1333
|
+
DisputeChallengedPayloadSchema,
|
|
1334
|
+
DisputeWonPayloadSchema,
|
|
1335
|
+
DisputeLostPayloadSchema,
|
|
1336
|
+
SubscriptionActivePayloadSchema,
|
|
1337
|
+
SubscriptionOnHoldPayloadSchema,
|
|
1338
|
+
SubscriptionRenewedPayloadSchema,
|
|
1339
|
+
SubscriptionPausedPayloadSchema,
|
|
1340
|
+
SubscriptionPlanChangedPayloadSchema,
|
|
1341
|
+
SubscriptionCancelledPayloadSchema,
|
|
1342
|
+
SubscriptionFailedPayloadSchema,
|
|
1343
|
+
SubscriptionExpiredPayloadSchema,
|
|
1344
|
+
LicenseKeyCreatedPayloadSchema,
|
|
1345
|
+
]);
|
|
1346
|
+
|
|
1347
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
1348
|
+
|
|
1349
|
+
var dist = {};
|
|
1350
|
+
|
|
1351
|
+
var timing_safe_equal = {};
|
|
1352
|
+
|
|
1353
|
+
Object.defineProperty(timing_safe_equal, "__esModule", { value: true });
|
|
1354
|
+
timing_safe_equal.timingSafeEqual = void 0;
|
|
1355
|
+
function assert(expr, msg = "") {
|
|
1356
|
+
if (!expr) {
|
|
1357
|
+
throw new Error(msg);
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
function timingSafeEqual(a, b) {
|
|
1361
|
+
if (a.byteLength !== b.byteLength) {
|
|
1362
|
+
return false;
|
|
1363
|
+
}
|
|
1364
|
+
if (!(a instanceof DataView)) {
|
|
1365
|
+
a = new DataView(ArrayBuffer.isView(a) ? a.buffer : a);
|
|
1366
|
+
}
|
|
1367
|
+
if (!(b instanceof DataView)) {
|
|
1368
|
+
b = new DataView(ArrayBuffer.isView(b) ? b.buffer : b);
|
|
1369
|
+
}
|
|
1370
|
+
assert(a instanceof DataView);
|
|
1371
|
+
assert(b instanceof DataView);
|
|
1372
|
+
const length = a.byteLength;
|
|
1373
|
+
let out = 0;
|
|
1374
|
+
let i = -1;
|
|
1375
|
+
while (++i < length) {
|
|
1376
|
+
out |= a.getUint8(i) ^ b.getUint8(i);
|
|
1377
|
+
}
|
|
1378
|
+
return out === 0;
|
|
1379
|
+
}
|
|
1380
|
+
timing_safe_equal.timingSafeEqual = timingSafeEqual;
|
|
1381
|
+
|
|
1382
|
+
var base64$1 = {};
|
|
1383
|
+
|
|
1384
|
+
// Copyright (C) 2016 Dmitry Chestnykh
|
|
1385
|
+
// MIT License. See LICENSE file for details.
|
|
1386
|
+
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
1387
|
+
var extendStatics = function (d, b) {
|
|
1388
|
+
extendStatics = Object.setPrototypeOf ||
|
|
1389
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
1390
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
1391
|
+
return extendStatics(d, b);
|
|
1392
|
+
};
|
|
1393
|
+
return function (d, b) {
|
|
1394
|
+
extendStatics(d, b);
|
|
1395
|
+
function __() { this.constructor = d; }
|
|
1396
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
1397
|
+
};
|
|
1398
|
+
})();
|
|
1399
|
+
Object.defineProperty(base64$1, "__esModule", { value: true });
|
|
1400
|
+
/**
|
|
1401
|
+
* Package base64 implements Base64 encoding and decoding.
|
|
1402
|
+
*/
|
|
1403
|
+
// Invalid character used in decoding to indicate
|
|
1404
|
+
// that the character to decode is out of range of
|
|
1405
|
+
// alphabet and cannot be decoded.
|
|
1406
|
+
var INVALID_BYTE = 256;
|
|
1407
|
+
/**
|
|
1408
|
+
* Implements standard Base64 encoding.
|
|
1409
|
+
*
|
|
1410
|
+
* Operates in constant time.
|
|
1411
|
+
*/
|
|
1412
|
+
var Coder = /** @class */ (function () {
|
|
1413
|
+
// TODO(dchest): methods to encode chunk-by-chunk.
|
|
1414
|
+
function Coder(_paddingCharacter) {
|
|
1415
|
+
if (_paddingCharacter === void 0) { _paddingCharacter = "="; }
|
|
1416
|
+
this._paddingCharacter = _paddingCharacter;
|
|
1417
|
+
}
|
|
1418
|
+
Coder.prototype.encodedLength = function (length) {
|
|
1419
|
+
if (!this._paddingCharacter) {
|
|
1420
|
+
return (length * 8 + 5) / 6 | 0;
|
|
1421
|
+
}
|
|
1422
|
+
return (length + 2) / 3 * 4 | 0;
|
|
1423
|
+
};
|
|
1424
|
+
Coder.prototype.encode = function (data) {
|
|
1425
|
+
var out = "";
|
|
1426
|
+
var i = 0;
|
|
1427
|
+
for (; i < data.length - 2; i += 3) {
|
|
1428
|
+
var c = (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2]);
|
|
1429
|
+
out += this._encodeByte((c >>> 3 * 6) & 63);
|
|
1430
|
+
out += this._encodeByte((c >>> 2 * 6) & 63);
|
|
1431
|
+
out += this._encodeByte((c >>> 1 * 6) & 63);
|
|
1432
|
+
out += this._encodeByte((c >>> 0 * 6) & 63);
|
|
1433
|
+
}
|
|
1434
|
+
var left = data.length - i;
|
|
1435
|
+
if (left > 0) {
|
|
1436
|
+
var c = (data[i] << 16) | (left === 2 ? data[i + 1] << 8 : 0);
|
|
1437
|
+
out += this._encodeByte((c >>> 3 * 6) & 63);
|
|
1438
|
+
out += this._encodeByte((c >>> 2 * 6) & 63);
|
|
1439
|
+
if (left === 2) {
|
|
1440
|
+
out += this._encodeByte((c >>> 1 * 6) & 63);
|
|
1441
|
+
}
|
|
1442
|
+
else {
|
|
1443
|
+
out += this._paddingCharacter || "";
|
|
1444
|
+
}
|
|
1445
|
+
out += this._paddingCharacter || "";
|
|
1446
|
+
}
|
|
1447
|
+
return out;
|
|
1448
|
+
};
|
|
1449
|
+
Coder.prototype.maxDecodedLength = function (length) {
|
|
1450
|
+
if (!this._paddingCharacter) {
|
|
1451
|
+
return (length * 6 + 7) / 8 | 0;
|
|
1452
|
+
}
|
|
1453
|
+
return length / 4 * 3 | 0;
|
|
1454
|
+
};
|
|
1455
|
+
Coder.prototype.decodedLength = function (s) {
|
|
1456
|
+
return this.maxDecodedLength(s.length - this._getPaddingLength(s));
|
|
1457
|
+
};
|
|
1458
|
+
Coder.prototype.decode = function (s) {
|
|
1459
|
+
if (s.length === 0) {
|
|
1460
|
+
return new Uint8Array(0);
|
|
1461
|
+
}
|
|
1462
|
+
var paddingLength = this._getPaddingLength(s);
|
|
1463
|
+
var length = s.length - paddingLength;
|
|
1464
|
+
var out = new Uint8Array(this.maxDecodedLength(length));
|
|
1465
|
+
var op = 0;
|
|
1466
|
+
var i = 0;
|
|
1467
|
+
var haveBad = 0;
|
|
1468
|
+
var v0 = 0, v1 = 0, v2 = 0, v3 = 0;
|
|
1469
|
+
for (; i < length - 4; i += 4) {
|
|
1470
|
+
v0 = this._decodeChar(s.charCodeAt(i + 0));
|
|
1471
|
+
v1 = this._decodeChar(s.charCodeAt(i + 1));
|
|
1472
|
+
v2 = this._decodeChar(s.charCodeAt(i + 2));
|
|
1473
|
+
v3 = this._decodeChar(s.charCodeAt(i + 3));
|
|
1474
|
+
out[op++] = (v0 << 2) | (v1 >>> 4);
|
|
1475
|
+
out[op++] = (v1 << 4) | (v2 >>> 2);
|
|
1476
|
+
out[op++] = (v2 << 6) | v3;
|
|
1477
|
+
haveBad |= v0 & INVALID_BYTE;
|
|
1478
|
+
haveBad |= v1 & INVALID_BYTE;
|
|
1479
|
+
haveBad |= v2 & INVALID_BYTE;
|
|
1480
|
+
haveBad |= v3 & INVALID_BYTE;
|
|
1481
|
+
}
|
|
1482
|
+
if (i < length - 1) {
|
|
1483
|
+
v0 = this._decodeChar(s.charCodeAt(i));
|
|
1484
|
+
v1 = this._decodeChar(s.charCodeAt(i + 1));
|
|
1485
|
+
out[op++] = (v0 << 2) | (v1 >>> 4);
|
|
1486
|
+
haveBad |= v0 & INVALID_BYTE;
|
|
1487
|
+
haveBad |= v1 & INVALID_BYTE;
|
|
1488
|
+
}
|
|
1489
|
+
if (i < length - 2) {
|
|
1490
|
+
v2 = this._decodeChar(s.charCodeAt(i + 2));
|
|
1491
|
+
out[op++] = (v1 << 4) | (v2 >>> 2);
|
|
1492
|
+
haveBad |= v2 & INVALID_BYTE;
|
|
1493
|
+
}
|
|
1494
|
+
if (i < length - 3) {
|
|
1495
|
+
v3 = this._decodeChar(s.charCodeAt(i + 3));
|
|
1496
|
+
out[op++] = (v2 << 6) | v3;
|
|
1497
|
+
haveBad |= v3 & INVALID_BYTE;
|
|
1498
|
+
}
|
|
1499
|
+
if (haveBad !== 0) {
|
|
1500
|
+
throw new Error("Base64Coder: incorrect characters for decoding");
|
|
1501
|
+
}
|
|
1502
|
+
return out;
|
|
1503
|
+
};
|
|
1504
|
+
// Standard encoding have the following encoded/decoded ranges,
|
|
1505
|
+
// which we need to convert between.
|
|
1506
|
+
//
|
|
1507
|
+
// ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 + /
|
|
1508
|
+
// Index: 0 - 25 26 - 51 52 - 61 62 63
|
|
1509
|
+
// ASCII: 65 - 90 97 - 122 48 - 57 43 47
|
|
1510
|
+
//
|
|
1511
|
+
// Encode 6 bits in b into a new character.
|
|
1512
|
+
Coder.prototype._encodeByte = function (b) {
|
|
1513
|
+
// Encoding uses constant time operations as follows:
|
|
1514
|
+
//
|
|
1515
|
+
// 1. Define comparison of A with B using (A - B) >>> 8:
|
|
1516
|
+
// if A > B, then result is positive integer
|
|
1517
|
+
// if A <= B, then result is 0
|
|
1518
|
+
//
|
|
1519
|
+
// 2. Define selection of C or 0 using bitwise AND: X & C:
|
|
1520
|
+
// if X == 0, then result is 0
|
|
1521
|
+
// if X != 0, then result is C
|
|
1522
|
+
//
|
|
1523
|
+
// 3. Start with the smallest comparison (b >= 0), which is always
|
|
1524
|
+
// true, so set the result to the starting ASCII value (65).
|
|
1525
|
+
//
|
|
1526
|
+
// 4. Continue comparing b to higher ASCII values, and selecting
|
|
1527
|
+
// zero if comparison isn't true, otherwise selecting a value
|
|
1528
|
+
// to add to result, which:
|
|
1529
|
+
//
|
|
1530
|
+
// a) undoes the previous addition
|
|
1531
|
+
// b) provides new value to add
|
|
1532
|
+
//
|
|
1533
|
+
var result = b;
|
|
1534
|
+
// b >= 0
|
|
1535
|
+
result += 65;
|
|
1536
|
+
// b > 25
|
|
1537
|
+
result += ((25 - b) >>> 8) & ((0 - 65) - 26 + 97);
|
|
1538
|
+
// b > 51
|
|
1539
|
+
result += ((51 - b) >>> 8) & ((26 - 97) - 52 + 48);
|
|
1540
|
+
// b > 61
|
|
1541
|
+
result += ((61 - b) >>> 8) & ((52 - 48) - 62 + 43);
|
|
1542
|
+
// b > 62
|
|
1543
|
+
result += ((62 - b) >>> 8) & ((62 - 43) - 63 + 47);
|
|
1544
|
+
return String.fromCharCode(result);
|
|
1545
|
+
};
|
|
1546
|
+
// Decode a character code into a byte.
|
|
1547
|
+
// Must return 256 if character is out of alphabet range.
|
|
1548
|
+
Coder.prototype._decodeChar = function (c) {
|
|
1549
|
+
// Decoding works similar to encoding: using the same comparison
|
|
1550
|
+
// function, but now it works on ranges: result is always incremented
|
|
1551
|
+
// by value, but this value becomes zero if the range is not
|
|
1552
|
+
// satisfied.
|
|
1553
|
+
//
|
|
1554
|
+
// Decoding starts with invalid value, 256, which is then
|
|
1555
|
+
// subtracted when the range is satisfied. If none of the ranges
|
|
1556
|
+
// apply, the function returns 256, which is then checked by
|
|
1557
|
+
// the caller to throw error.
|
|
1558
|
+
var result = INVALID_BYTE; // start with invalid character
|
|
1559
|
+
// c == 43 (c > 42 and c < 44)
|
|
1560
|
+
result += (((42 - c) & (c - 44)) >>> 8) & (-INVALID_BYTE + c - 43 + 62);
|
|
1561
|
+
// c == 47 (c > 46 and c < 48)
|
|
1562
|
+
result += (((46 - c) & (c - 48)) >>> 8) & (-INVALID_BYTE + c - 47 + 63);
|
|
1563
|
+
// c > 47 and c < 58
|
|
1564
|
+
result += (((47 - c) & (c - 58)) >>> 8) & (-INVALID_BYTE + c - 48 + 52);
|
|
1565
|
+
// c > 64 and c < 91
|
|
1566
|
+
result += (((64 - c) & (c - 91)) >>> 8) & (-INVALID_BYTE + c - 65 + 0);
|
|
1567
|
+
// c > 96 and c < 123
|
|
1568
|
+
result += (((96 - c) & (c - 123)) >>> 8) & (-INVALID_BYTE + c - 97 + 26);
|
|
1569
|
+
return result;
|
|
1570
|
+
};
|
|
1571
|
+
Coder.prototype._getPaddingLength = function (s) {
|
|
1572
|
+
var paddingLength = 0;
|
|
1573
|
+
if (this._paddingCharacter) {
|
|
1574
|
+
for (var i = s.length - 1; i >= 0; i--) {
|
|
1575
|
+
if (s[i] !== this._paddingCharacter) {
|
|
1576
|
+
break;
|
|
1577
|
+
}
|
|
1578
|
+
paddingLength++;
|
|
1579
|
+
}
|
|
1580
|
+
if (s.length < 4 || paddingLength > 2) {
|
|
1581
|
+
throw new Error("Base64Coder: incorrect padding");
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
return paddingLength;
|
|
1585
|
+
};
|
|
1586
|
+
return Coder;
|
|
1587
|
+
}());
|
|
1588
|
+
base64$1.Coder = Coder;
|
|
1589
|
+
var stdCoder = new Coder();
|
|
1590
|
+
function encode(data) {
|
|
1591
|
+
return stdCoder.encode(data);
|
|
1592
|
+
}
|
|
1593
|
+
base64$1.encode = encode;
|
|
1594
|
+
function decode(s) {
|
|
1595
|
+
return stdCoder.decode(s);
|
|
1596
|
+
}
|
|
1597
|
+
base64$1.decode = decode;
|
|
1598
|
+
/**
|
|
1599
|
+
* Implements URL-safe Base64 encoding.
|
|
1600
|
+
* (Same as Base64, but '+' is replaced with '-', and '/' with '_').
|
|
1601
|
+
*
|
|
1602
|
+
* Operates in constant time.
|
|
1603
|
+
*/
|
|
1604
|
+
var URLSafeCoder = /** @class */ (function (_super) {
|
|
1605
|
+
__extends(URLSafeCoder, _super);
|
|
1606
|
+
function URLSafeCoder() {
|
|
1607
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1608
|
+
}
|
|
1609
|
+
// URL-safe encoding have the following encoded/decoded ranges:
|
|
1610
|
+
//
|
|
1611
|
+
// ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 - _
|
|
1612
|
+
// Index: 0 - 25 26 - 51 52 - 61 62 63
|
|
1613
|
+
// ASCII: 65 - 90 97 - 122 48 - 57 45 95
|
|
1614
|
+
//
|
|
1615
|
+
URLSafeCoder.prototype._encodeByte = function (b) {
|
|
1616
|
+
var result = b;
|
|
1617
|
+
// b >= 0
|
|
1618
|
+
result += 65;
|
|
1619
|
+
// b > 25
|
|
1620
|
+
result += ((25 - b) >>> 8) & ((0 - 65) - 26 + 97);
|
|
1621
|
+
// b > 51
|
|
1622
|
+
result += ((51 - b) >>> 8) & ((26 - 97) - 52 + 48);
|
|
1623
|
+
// b > 61
|
|
1624
|
+
result += ((61 - b) >>> 8) & ((52 - 48) - 62 + 45);
|
|
1625
|
+
// b > 62
|
|
1626
|
+
result += ((62 - b) >>> 8) & ((62 - 45) - 63 + 95);
|
|
1627
|
+
return String.fromCharCode(result);
|
|
1628
|
+
};
|
|
1629
|
+
URLSafeCoder.prototype._decodeChar = function (c) {
|
|
1630
|
+
var result = INVALID_BYTE;
|
|
1631
|
+
// c == 45 (c > 44 and c < 46)
|
|
1632
|
+
result += (((44 - c) & (c - 46)) >>> 8) & (-INVALID_BYTE + c - 45 + 62);
|
|
1633
|
+
// c == 95 (c > 94 and c < 96)
|
|
1634
|
+
result += (((94 - c) & (c - 96)) >>> 8) & (-INVALID_BYTE + c - 95 + 63);
|
|
1635
|
+
// c > 47 and c < 58
|
|
1636
|
+
result += (((47 - c) & (c - 58)) >>> 8) & (-INVALID_BYTE + c - 48 + 52);
|
|
1637
|
+
// c > 64 and c < 91
|
|
1638
|
+
result += (((64 - c) & (c - 91)) >>> 8) & (-INVALID_BYTE + c - 65 + 0);
|
|
1639
|
+
// c > 96 and c < 123
|
|
1640
|
+
result += (((96 - c) & (c - 123)) >>> 8) & (-INVALID_BYTE + c - 97 + 26);
|
|
1641
|
+
return result;
|
|
1642
|
+
};
|
|
1643
|
+
return URLSafeCoder;
|
|
1644
|
+
}(Coder));
|
|
1645
|
+
base64$1.URLSafeCoder = URLSafeCoder;
|
|
1646
|
+
var urlSafeCoder = new URLSafeCoder();
|
|
1647
|
+
function encodeURLSafe(data) {
|
|
1648
|
+
return urlSafeCoder.encode(data);
|
|
1649
|
+
}
|
|
1650
|
+
base64$1.encodeURLSafe = encodeURLSafe;
|
|
1651
|
+
function decodeURLSafe(s) {
|
|
1652
|
+
return urlSafeCoder.decode(s);
|
|
1653
|
+
}
|
|
1654
|
+
base64$1.decodeURLSafe = decodeURLSafe;
|
|
1655
|
+
base64$1.encodedLength = function (length) {
|
|
1656
|
+
return stdCoder.encodedLength(length);
|
|
1657
|
+
};
|
|
1658
|
+
base64$1.maxDecodedLength = function (length) {
|
|
1659
|
+
return stdCoder.maxDecodedLength(length);
|
|
1660
|
+
};
|
|
1661
|
+
base64$1.decodedLength = function (s) {
|
|
1662
|
+
return stdCoder.decodedLength(s);
|
|
1663
|
+
};
|
|
1664
|
+
|
|
1665
|
+
var sha256$1 = {exports: {}};
|
|
1666
|
+
|
|
1667
|
+
(function (module) {
|
|
1668
|
+
(function (root, factory) {
|
|
1669
|
+
// Hack to make all exports of this module sha256 function object properties.
|
|
1670
|
+
var exports = {};
|
|
1671
|
+
factory(exports);
|
|
1672
|
+
var sha256 = exports["default"];
|
|
1673
|
+
for (var k in exports) {
|
|
1674
|
+
sha256[k] = exports[k];
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
{
|
|
1678
|
+
module.exports = sha256;
|
|
1679
|
+
}
|
|
1680
|
+
})(commonjsGlobal, function(exports) {
|
|
1681
|
+
exports.__esModule = true;
|
|
1682
|
+
// SHA-256 (+ HMAC and PBKDF2) for JavaScript.
|
|
1683
|
+
//
|
|
1684
|
+
// Written in 2014-2016 by Dmitry Chestnykh.
|
|
1685
|
+
// Public domain, no warranty.
|
|
1686
|
+
//
|
|
1687
|
+
// Functions (accept and return Uint8Arrays):
|
|
1688
|
+
//
|
|
1689
|
+
// sha256(message) -> hash
|
|
1690
|
+
// sha256.hmac(key, message) -> mac
|
|
1691
|
+
// sha256.pbkdf2(password, salt, rounds, dkLen) -> dk
|
|
1692
|
+
//
|
|
1693
|
+
// Classes:
|
|
1694
|
+
//
|
|
1695
|
+
// new sha256.Hash()
|
|
1696
|
+
// new sha256.HMAC(key)
|
|
1697
|
+
//
|
|
1698
|
+
exports.digestLength = 32;
|
|
1699
|
+
exports.blockSize = 64;
|
|
1700
|
+
// SHA-256 constants
|
|
1701
|
+
var K = new Uint32Array([
|
|
1702
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b,
|
|
1703
|
+
0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01,
|
|
1704
|
+
0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7,
|
|
1705
|
+
0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
|
1706
|
+
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152,
|
|
1707
|
+
0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
|
|
1708
|
+
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc,
|
|
1709
|
+
0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
1710
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819,
|
|
1711
|
+
0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08,
|
|
1712
|
+
0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f,
|
|
1713
|
+
0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
|
1714
|
+
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
1715
|
+
]);
|
|
1716
|
+
function hashBlocks(w, v, p, pos, len) {
|
|
1717
|
+
var a, b, c, d, e, f, g, h, u, i, j, t1, t2;
|
|
1718
|
+
while (len >= 64) {
|
|
1719
|
+
a = v[0];
|
|
1720
|
+
b = v[1];
|
|
1721
|
+
c = v[2];
|
|
1722
|
+
d = v[3];
|
|
1723
|
+
e = v[4];
|
|
1724
|
+
f = v[5];
|
|
1725
|
+
g = v[6];
|
|
1726
|
+
h = v[7];
|
|
1727
|
+
for (i = 0; i < 16; i++) {
|
|
1728
|
+
j = pos + i * 4;
|
|
1729
|
+
w[i] = (((p[j] & 0xff) << 24) | ((p[j + 1] & 0xff) << 16) |
|
|
1730
|
+
((p[j + 2] & 0xff) << 8) | (p[j + 3] & 0xff));
|
|
1731
|
+
}
|
|
1732
|
+
for (i = 16; i < 64; i++) {
|
|
1733
|
+
u = w[i - 2];
|
|
1734
|
+
t1 = (u >>> 17 | u << (32 - 17)) ^ (u >>> 19 | u << (32 - 19)) ^ (u >>> 10);
|
|
1735
|
+
u = w[i - 15];
|
|
1736
|
+
t2 = (u >>> 7 | u << (32 - 7)) ^ (u >>> 18 | u << (32 - 18)) ^ (u >>> 3);
|
|
1737
|
+
w[i] = (t1 + w[i - 7] | 0) + (t2 + w[i - 16] | 0);
|
|
1738
|
+
}
|
|
1739
|
+
for (i = 0; i < 64; i++) {
|
|
1740
|
+
t1 = (((((e >>> 6 | e << (32 - 6)) ^ (e >>> 11 | e << (32 - 11)) ^
|
|
1741
|
+
(e >>> 25 | e << (32 - 25))) + ((e & f) ^ (~e & g))) | 0) +
|
|
1742
|
+
((h + ((K[i] + w[i]) | 0)) | 0)) | 0;
|
|
1743
|
+
t2 = (((a >>> 2 | a << (32 - 2)) ^ (a >>> 13 | a << (32 - 13)) ^
|
|
1744
|
+
(a >>> 22 | a << (32 - 22))) + ((a & b) ^ (a & c) ^ (b & c))) | 0;
|
|
1745
|
+
h = g;
|
|
1746
|
+
g = f;
|
|
1747
|
+
f = e;
|
|
1748
|
+
e = (d + t1) | 0;
|
|
1749
|
+
d = c;
|
|
1750
|
+
c = b;
|
|
1751
|
+
b = a;
|
|
1752
|
+
a = (t1 + t2) | 0;
|
|
1753
|
+
}
|
|
1754
|
+
v[0] += a;
|
|
1755
|
+
v[1] += b;
|
|
1756
|
+
v[2] += c;
|
|
1757
|
+
v[3] += d;
|
|
1758
|
+
v[4] += e;
|
|
1759
|
+
v[5] += f;
|
|
1760
|
+
v[6] += g;
|
|
1761
|
+
v[7] += h;
|
|
1762
|
+
pos += 64;
|
|
1763
|
+
len -= 64;
|
|
1764
|
+
}
|
|
1765
|
+
return pos;
|
|
1766
|
+
}
|
|
1767
|
+
// Hash implements SHA256 hash algorithm.
|
|
1768
|
+
var Hash = /** @class */ (function () {
|
|
1769
|
+
function Hash() {
|
|
1770
|
+
this.digestLength = exports.digestLength;
|
|
1771
|
+
this.blockSize = exports.blockSize;
|
|
1772
|
+
// Note: Int32Array is used instead of Uint32Array for performance reasons.
|
|
1773
|
+
this.state = new Int32Array(8); // hash state
|
|
1774
|
+
this.temp = new Int32Array(64); // temporary state
|
|
1775
|
+
this.buffer = new Uint8Array(128); // buffer for data to hash
|
|
1776
|
+
this.bufferLength = 0; // number of bytes in buffer
|
|
1777
|
+
this.bytesHashed = 0; // number of total bytes hashed
|
|
1778
|
+
this.finished = false; // indicates whether the hash was finalized
|
|
1779
|
+
this.reset();
|
|
1780
|
+
}
|
|
1781
|
+
// Resets hash state making it possible
|
|
1782
|
+
// to re-use this instance to hash other data.
|
|
1783
|
+
Hash.prototype.reset = function () {
|
|
1784
|
+
this.state[0] = 0x6a09e667;
|
|
1785
|
+
this.state[1] = 0xbb67ae85;
|
|
1786
|
+
this.state[2] = 0x3c6ef372;
|
|
1787
|
+
this.state[3] = 0xa54ff53a;
|
|
1788
|
+
this.state[4] = 0x510e527f;
|
|
1789
|
+
this.state[5] = 0x9b05688c;
|
|
1790
|
+
this.state[6] = 0x1f83d9ab;
|
|
1791
|
+
this.state[7] = 0x5be0cd19;
|
|
1792
|
+
this.bufferLength = 0;
|
|
1793
|
+
this.bytesHashed = 0;
|
|
1794
|
+
this.finished = false;
|
|
1795
|
+
return this;
|
|
1796
|
+
};
|
|
1797
|
+
// Cleans internal buffers and re-initializes hash state.
|
|
1798
|
+
Hash.prototype.clean = function () {
|
|
1799
|
+
for (var i = 0; i < this.buffer.length; i++) {
|
|
1800
|
+
this.buffer[i] = 0;
|
|
1801
|
+
}
|
|
1802
|
+
for (var i = 0; i < this.temp.length; i++) {
|
|
1803
|
+
this.temp[i] = 0;
|
|
1804
|
+
}
|
|
1805
|
+
this.reset();
|
|
1806
|
+
};
|
|
1807
|
+
// Updates hash state with the given data.
|
|
1808
|
+
//
|
|
1809
|
+
// Optionally, length of the data can be specified to hash
|
|
1810
|
+
// fewer bytes than data.length.
|
|
1811
|
+
//
|
|
1812
|
+
// Throws error when trying to update already finalized hash:
|
|
1813
|
+
// instance must be reset to use it again.
|
|
1814
|
+
Hash.prototype.update = function (data, dataLength) {
|
|
1815
|
+
if (dataLength === void 0) { dataLength = data.length; }
|
|
1816
|
+
if (this.finished) {
|
|
1817
|
+
throw new Error("SHA256: can't update because hash was finished.");
|
|
1818
|
+
}
|
|
1819
|
+
var dataPos = 0;
|
|
1820
|
+
this.bytesHashed += dataLength;
|
|
1821
|
+
if (this.bufferLength > 0) {
|
|
1822
|
+
while (this.bufferLength < 64 && dataLength > 0) {
|
|
1823
|
+
this.buffer[this.bufferLength++] = data[dataPos++];
|
|
1824
|
+
dataLength--;
|
|
1825
|
+
}
|
|
1826
|
+
if (this.bufferLength === 64) {
|
|
1827
|
+
hashBlocks(this.temp, this.state, this.buffer, 0, 64);
|
|
1828
|
+
this.bufferLength = 0;
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
if (dataLength >= 64) {
|
|
1832
|
+
dataPos = hashBlocks(this.temp, this.state, data, dataPos, dataLength);
|
|
1833
|
+
dataLength %= 64;
|
|
1834
|
+
}
|
|
1835
|
+
while (dataLength > 0) {
|
|
1836
|
+
this.buffer[this.bufferLength++] = data[dataPos++];
|
|
1837
|
+
dataLength--;
|
|
1838
|
+
}
|
|
1839
|
+
return this;
|
|
1840
|
+
};
|
|
1841
|
+
// Finalizes hash state and puts hash into out.
|
|
1842
|
+
//
|
|
1843
|
+
// If hash was already finalized, puts the same value.
|
|
1844
|
+
Hash.prototype.finish = function (out) {
|
|
1845
|
+
if (!this.finished) {
|
|
1846
|
+
var bytesHashed = this.bytesHashed;
|
|
1847
|
+
var left = this.bufferLength;
|
|
1848
|
+
var bitLenHi = (bytesHashed / 0x20000000) | 0;
|
|
1849
|
+
var bitLenLo = bytesHashed << 3;
|
|
1850
|
+
var padLength = (bytesHashed % 64 < 56) ? 64 : 128;
|
|
1851
|
+
this.buffer[left] = 0x80;
|
|
1852
|
+
for (var i = left + 1; i < padLength - 8; i++) {
|
|
1853
|
+
this.buffer[i] = 0;
|
|
1854
|
+
}
|
|
1855
|
+
this.buffer[padLength - 8] = (bitLenHi >>> 24) & 0xff;
|
|
1856
|
+
this.buffer[padLength - 7] = (bitLenHi >>> 16) & 0xff;
|
|
1857
|
+
this.buffer[padLength - 6] = (bitLenHi >>> 8) & 0xff;
|
|
1858
|
+
this.buffer[padLength - 5] = (bitLenHi >>> 0) & 0xff;
|
|
1859
|
+
this.buffer[padLength - 4] = (bitLenLo >>> 24) & 0xff;
|
|
1860
|
+
this.buffer[padLength - 3] = (bitLenLo >>> 16) & 0xff;
|
|
1861
|
+
this.buffer[padLength - 2] = (bitLenLo >>> 8) & 0xff;
|
|
1862
|
+
this.buffer[padLength - 1] = (bitLenLo >>> 0) & 0xff;
|
|
1863
|
+
hashBlocks(this.temp, this.state, this.buffer, 0, padLength);
|
|
1864
|
+
this.finished = true;
|
|
1865
|
+
}
|
|
1866
|
+
for (var i = 0; i < 8; i++) {
|
|
1867
|
+
out[i * 4 + 0] = (this.state[i] >>> 24) & 0xff;
|
|
1868
|
+
out[i * 4 + 1] = (this.state[i] >>> 16) & 0xff;
|
|
1869
|
+
out[i * 4 + 2] = (this.state[i] >>> 8) & 0xff;
|
|
1870
|
+
out[i * 4 + 3] = (this.state[i] >>> 0) & 0xff;
|
|
1871
|
+
}
|
|
1872
|
+
return this;
|
|
1873
|
+
};
|
|
1874
|
+
// Returns the final hash digest.
|
|
1875
|
+
Hash.prototype.digest = function () {
|
|
1876
|
+
var out = new Uint8Array(this.digestLength);
|
|
1877
|
+
this.finish(out);
|
|
1878
|
+
return out;
|
|
1879
|
+
};
|
|
1880
|
+
// Internal function for use in HMAC for optimization.
|
|
1881
|
+
Hash.prototype._saveState = function (out) {
|
|
1882
|
+
for (var i = 0; i < this.state.length; i++) {
|
|
1883
|
+
out[i] = this.state[i];
|
|
1884
|
+
}
|
|
1885
|
+
};
|
|
1886
|
+
// Internal function for use in HMAC for optimization.
|
|
1887
|
+
Hash.prototype._restoreState = function (from, bytesHashed) {
|
|
1888
|
+
for (var i = 0; i < this.state.length; i++) {
|
|
1889
|
+
this.state[i] = from[i];
|
|
1890
|
+
}
|
|
1891
|
+
this.bytesHashed = bytesHashed;
|
|
1892
|
+
this.finished = false;
|
|
1893
|
+
this.bufferLength = 0;
|
|
1894
|
+
};
|
|
1895
|
+
return Hash;
|
|
1896
|
+
}());
|
|
1897
|
+
exports.Hash = Hash;
|
|
1898
|
+
// HMAC implements HMAC-SHA256 message authentication algorithm.
|
|
1899
|
+
var HMAC = /** @class */ (function () {
|
|
1900
|
+
function HMAC(key) {
|
|
1901
|
+
this.inner = new Hash();
|
|
1902
|
+
this.outer = new Hash();
|
|
1903
|
+
this.blockSize = this.inner.blockSize;
|
|
1904
|
+
this.digestLength = this.inner.digestLength;
|
|
1905
|
+
var pad = new Uint8Array(this.blockSize);
|
|
1906
|
+
if (key.length > this.blockSize) {
|
|
1907
|
+
(new Hash()).update(key).finish(pad).clean();
|
|
1908
|
+
}
|
|
1909
|
+
else {
|
|
1910
|
+
for (var i = 0; i < key.length; i++) {
|
|
1911
|
+
pad[i] = key[i];
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
for (var i = 0; i < pad.length; i++) {
|
|
1915
|
+
pad[i] ^= 0x36;
|
|
1916
|
+
}
|
|
1917
|
+
this.inner.update(pad);
|
|
1918
|
+
for (var i = 0; i < pad.length; i++) {
|
|
1919
|
+
pad[i] ^= 0x36 ^ 0x5c;
|
|
1920
|
+
}
|
|
1921
|
+
this.outer.update(pad);
|
|
1922
|
+
this.istate = new Uint32Array(8);
|
|
1923
|
+
this.ostate = new Uint32Array(8);
|
|
1924
|
+
this.inner._saveState(this.istate);
|
|
1925
|
+
this.outer._saveState(this.ostate);
|
|
1926
|
+
for (var i = 0; i < pad.length; i++) {
|
|
1927
|
+
pad[i] = 0;
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
// Returns HMAC state to the state initialized with key
|
|
1931
|
+
// to make it possible to run HMAC over the other data with the same
|
|
1932
|
+
// key without creating a new instance.
|
|
1933
|
+
HMAC.prototype.reset = function () {
|
|
1934
|
+
this.inner._restoreState(this.istate, this.inner.blockSize);
|
|
1935
|
+
this.outer._restoreState(this.ostate, this.outer.blockSize);
|
|
1936
|
+
return this;
|
|
1937
|
+
};
|
|
1938
|
+
// Cleans HMAC state.
|
|
1939
|
+
HMAC.prototype.clean = function () {
|
|
1940
|
+
for (var i = 0; i < this.istate.length; i++) {
|
|
1941
|
+
this.ostate[i] = this.istate[i] = 0;
|
|
1942
|
+
}
|
|
1943
|
+
this.inner.clean();
|
|
1944
|
+
this.outer.clean();
|
|
1945
|
+
};
|
|
1946
|
+
// Updates state with provided data.
|
|
1947
|
+
HMAC.prototype.update = function (data) {
|
|
1948
|
+
this.inner.update(data);
|
|
1949
|
+
return this;
|
|
1950
|
+
};
|
|
1951
|
+
// Finalizes HMAC and puts the result in out.
|
|
1952
|
+
HMAC.prototype.finish = function (out) {
|
|
1953
|
+
if (this.outer.finished) {
|
|
1954
|
+
this.outer.finish(out);
|
|
1955
|
+
}
|
|
1956
|
+
else {
|
|
1957
|
+
this.inner.finish(out);
|
|
1958
|
+
this.outer.update(out, this.digestLength).finish(out);
|
|
1959
|
+
}
|
|
1960
|
+
return this;
|
|
1961
|
+
};
|
|
1962
|
+
// Returns message authentication code.
|
|
1963
|
+
HMAC.prototype.digest = function () {
|
|
1964
|
+
var out = new Uint8Array(this.digestLength);
|
|
1965
|
+
this.finish(out);
|
|
1966
|
+
return out;
|
|
1967
|
+
};
|
|
1968
|
+
return HMAC;
|
|
1969
|
+
}());
|
|
1970
|
+
exports.HMAC = HMAC;
|
|
1971
|
+
// Returns SHA256 hash of data.
|
|
1972
|
+
function hash(data) {
|
|
1973
|
+
var h = (new Hash()).update(data);
|
|
1974
|
+
var digest = h.digest();
|
|
1975
|
+
h.clean();
|
|
1976
|
+
return digest;
|
|
1977
|
+
}
|
|
1978
|
+
exports.hash = hash;
|
|
1979
|
+
// Function hash is both available as module.hash and as default export.
|
|
1980
|
+
exports["default"] = hash;
|
|
1981
|
+
// Returns HMAC-SHA256 of data under the key.
|
|
1982
|
+
function hmac(key, data) {
|
|
1983
|
+
var h = (new HMAC(key)).update(data);
|
|
1984
|
+
var digest = h.digest();
|
|
1985
|
+
h.clean();
|
|
1986
|
+
return digest;
|
|
1987
|
+
}
|
|
1988
|
+
exports.hmac = hmac;
|
|
1989
|
+
// Fills hkdf buffer like this:
|
|
1990
|
+
// T(1) = HMAC-Hash(PRK, T(0) | info | 0x01)
|
|
1991
|
+
function fillBuffer(buffer, hmac, info, counter) {
|
|
1992
|
+
// Counter is a byte value: check if it overflowed.
|
|
1993
|
+
var num = counter[0];
|
|
1994
|
+
if (num === 0) {
|
|
1995
|
+
throw new Error("hkdf: cannot expand more");
|
|
1996
|
+
}
|
|
1997
|
+
// Prepare HMAC instance for new data with old key.
|
|
1998
|
+
hmac.reset();
|
|
1999
|
+
// Hash in previous output if it was generated
|
|
2000
|
+
// (i.e. counter is greater than 1).
|
|
2001
|
+
if (num > 1) {
|
|
2002
|
+
hmac.update(buffer);
|
|
2003
|
+
}
|
|
2004
|
+
// Hash in info if it exists.
|
|
2005
|
+
if (info) {
|
|
2006
|
+
hmac.update(info);
|
|
2007
|
+
}
|
|
2008
|
+
// Hash in the counter.
|
|
2009
|
+
hmac.update(counter);
|
|
2010
|
+
// Output result to buffer and clean HMAC instance.
|
|
2011
|
+
hmac.finish(buffer);
|
|
2012
|
+
// Increment counter inside typed array, this works properly.
|
|
2013
|
+
counter[0]++;
|
|
2014
|
+
}
|
|
2015
|
+
var hkdfSalt = new Uint8Array(exports.digestLength); // Filled with zeroes.
|
|
2016
|
+
function hkdf(key, salt, info, length) {
|
|
2017
|
+
if (salt === void 0) { salt = hkdfSalt; }
|
|
2018
|
+
if (length === void 0) { length = 32; }
|
|
2019
|
+
var counter = new Uint8Array([1]);
|
|
2020
|
+
// HKDF-Extract uses salt as HMAC key, and key as data.
|
|
2021
|
+
var okm = hmac(salt, key);
|
|
2022
|
+
// Initialize HMAC for expanding with extracted key.
|
|
2023
|
+
// Ensure no collisions with `hmac` function.
|
|
2024
|
+
var hmac_ = new HMAC(okm);
|
|
2025
|
+
// Allocate buffer.
|
|
2026
|
+
var buffer = new Uint8Array(hmac_.digestLength);
|
|
2027
|
+
var bufpos = buffer.length;
|
|
2028
|
+
var out = new Uint8Array(length);
|
|
2029
|
+
for (var i = 0; i < length; i++) {
|
|
2030
|
+
if (bufpos === buffer.length) {
|
|
2031
|
+
fillBuffer(buffer, hmac_, info, counter);
|
|
2032
|
+
bufpos = 0;
|
|
2033
|
+
}
|
|
2034
|
+
out[i] = buffer[bufpos++];
|
|
2035
|
+
}
|
|
2036
|
+
hmac_.clean();
|
|
2037
|
+
buffer.fill(0);
|
|
2038
|
+
counter.fill(0);
|
|
2039
|
+
return out;
|
|
2040
|
+
}
|
|
2041
|
+
exports.hkdf = hkdf;
|
|
2042
|
+
// Derives a key from password and salt using PBKDF2-HMAC-SHA256
|
|
2043
|
+
// with the given number of iterations.
|
|
2044
|
+
//
|
|
2045
|
+
// The number of bytes returned is equal to dkLen.
|
|
2046
|
+
//
|
|
2047
|
+
// (For better security, avoid dkLen greater than hash length - 32 bytes).
|
|
2048
|
+
function pbkdf2(password, salt, iterations, dkLen) {
|
|
2049
|
+
var prf = new HMAC(password);
|
|
2050
|
+
var len = prf.digestLength;
|
|
2051
|
+
var ctr = new Uint8Array(4);
|
|
2052
|
+
var t = new Uint8Array(len);
|
|
2053
|
+
var u = new Uint8Array(len);
|
|
2054
|
+
var dk = new Uint8Array(dkLen);
|
|
2055
|
+
for (var i = 0; i * len < dkLen; i++) {
|
|
2056
|
+
var c = i + 1;
|
|
2057
|
+
ctr[0] = (c >>> 24) & 0xff;
|
|
2058
|
+
ctr[1] = (c >>> 16) & 0xff;
|
|
2059
|
+
ctr[2] = (c >>> 8) & 0xff;
|
|
2060
|
+
ctr[3] = (c >>> 0) & 0xff;
|
|
2061
|
+
prf.reset();
|
|
2062
|
+
prf.update(salt);
|
|
2063
|
+
prf.update(ctr);
|
|
2064
|
+
prf.finish(u);
|
|
2065
|
+
for (var j = 0; j < len; j++) {
|
|
2066
|
+
t[j] = u[j];
|
|
2067
|
+
}
|
|
2068
|
+
for (var j = 2; j <= iterations; j++) {
|
|
2069
|
+
prf.reset();
|
|
2070
|
+
prf.update(u).finish(u);
|
|
2071
|
+
for (var k = 0; k < len; k++) {
|
|
2072
|
+
t[k] ^= u[k];
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
for (var j = 0; j < len && i * len + j < dkLen; j++) {
|
|
2076
|
+
dk[i * len + j] = t[j];
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
for (var i = 0; i < len; i++) {
|
|
2080
|
+
t[i] = u[i] = 0;
|
|
2081
|
+
}
|
|
2082
|
+
for (var i = 0; i < 4; i++) {
|
|
2083
|
+
ctr[i] = 0;
|
|
2084
|
+
}
|
|
2085
|
+
prf.clean();
|
|
2086
|
+
return dk;
|
|
2087
|
+
}
|
|
2088
|
+
exports.pbkdf2 = pbkdf2;
|
|
2089
|
+
});
|
|
2090
|
+
} (sha256$1));
|
|
2091
|
+
|
|
2092
|
+
var sha256Exports = sha256$1.exports;
|
|
2093
|
+
|
|
2094
|
+
Object.defineProperty(dist, "__esModule", { value: true });
|
|
2095
|
+
var Webhook_1 = dist.Webhook = WebhookVerificationError_1 = dist.WebhookVerificationError = void 0;
|
|
2096
|
+
const timing_safe_equal_1 = timing_safe_equal;
|
|
2097
|
+
const base64 = base64$1;
|
|
2098
|
+
const sha256 = sha256Exports;
|
|
2099
|
+
const WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60;
|
|
2100
|
+
class ExtendableError extends Error {
|
|
2101
|
+
constructor(message) {
|
|
2102
|
+
super(message);
|
|
2103
|
+
Object.setPrototypeOf(this, ExtendableError.prototype);
|
|
2104
|
+
this.name = "ExtendableError";
|
|
2105
|
+
this.stack = new Error(message).stack;
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
class WebhookVerificationError extends ExtendableError {
|
|
2109
|
+
constructor(message) {
|
|
2110
|
+
super(message);
|
|
2111
|
+
Object.setPrototypeOf(this, WebhookVerificationError.prototype);
|
|
2112
|
+
this.name = "WebhookVerificationError";
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
var WebhookVerificationError_1 = dist.WebhookVerificationError = WebhookVerificationError;
|
|
2116
|
+
class Webhook {
|
|
2117
|
+
constructor(secret, options) {
|
|
2118
|
+
if (!secret) {
|
|
2119
|
+
throw new Error("Secret can't be empty.");
|
|
2120
|
+
}
|
|
2121
|
+
if ((options === null || options === void 0 ? void 0 : options.format) === "raw") {
|
|
2122
|
+
if (secret instanceof Uint8Array) {
|
|
2123
|
+
this.key = secret;
|
|
2124
|
+
}
|
|
2125
|
+
else {
|
|
2126
|
+
this.key = Uint8Array.from(secret, (c) => c.charCodeAt(0));
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
else {
|
|
2130
|
+
if (typeof secret !== "string") {
|
|
2131
|
+
throw new Error("Expected secret to be of type string");
|
|
2132
|
+
}
|
|
2133
|
+
if (secret.startsWith(Webhook.prefix)) {
|
|
2134
|
+
secret = secret.substring(Webhook.prefix.length);
|
|
2135
|
+
}
|
|
2136
|
+
this.key = base64.decode(secret);
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
verify(payload, headers_) {
|
|
2140
|
+
const headers = {};
|
|
2141
|
+
for (const key of Object.keys(headers_)) {
|
|
2142
|
+
headers[key.toLowerCase()] = headers_[key];
|
|
2143
|
+
}
|
|
2144
|
+
const msgId = headers["webhook-id"];
|
|
2145
|
+
const msgSignature = headers["webhook-signature"];
|
|
2146
|
+
const msgTimestamp = headers["webhook-timestamp"];
|
|
2147
|
+
if (!msgSignature || !msgId || !msgTimestamp) {
|
|
2148
|
+
throw new WebhookVerificationError("Missing required headers");
|
|
2149
|
+
}
|
|
2150
|
+
const timestamp = this.verifyTimestamp(msgTimestamp);
|
|
2151
|
+
const computedSignature = this.sign(msgId, timestamp, payload);
|
|
2152
|
+
const expectedSignature = computedSignature.split(",")[1];
|
|
2153
|
+
const passedSignatures = msgSignature.split(" ");
|
|
2154
|
+
const encoder = new globalThis.TextEncoder();
|
|
2155
|
+
for (const versionedSignature of passedSignatures) {
|
|
2156
|
+
const [version, signature] = versionedSignature.split(",");
|
|
2157
|
+
if (version !== "v1") {
|
|
2158
|
+
continue;
|
|
2159
|
+
}
|
|
2160
|
+
if ((0, timing_safe_equal_1.timingSafeEqual)(encoder.encode(signature), encoder.encode(expectedSignature))) {
|
|
2161
|
+
return JSON.parse(payload.toString());
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
throw new WebhookVerificationError("No matching signature found");
|
|
2165
|
+
}
|
|
2166
|
+
sign(msgId, timestamp, payload) {
|
|
2167
|
+
if (typeof payload === "string") ;
|
|
2168
|
+
else if (payload.constructor.name === "Buffer") {
|
|
2169
|
+
payload = payload.toString();
|
|
2170
|
+
}
|
|
2171
|
+
else {
|
|
2172
|
+
throw new Error("Expected payload to be of type string or Buffer.");
|
|
2173
|
+
}
|
|
2174
|
+
const encoder = new TextEncoder();
|
|
2175
|
+
const timestampNumber = Math.floor(timestamp.getTime() / 1000);
|
|
2176
|
+
const toSign = encoder.encode(`${msgId}.${timestampNumber}.${payload}`);
|
|
2177
|
+
const expectedSignature = base64.encode(sha256.hmac(this.key, toSign));
|
|
2178
|
+
return `v1,${expectedSignature}`;
|
|
2179
|
+
}
|
|
2180
|
+
verifyTimestamp(timestampHeader) {
|
|
2181
|
+
const now = Math.floor(Date.now() / 1000);
|
|
2182
|
+
const timestamp = parseInt(timestampHeader, 10);
|
|
2183
|
+
if (isNaN(timestamp)) {
|
|
2184
|
+
throw new WebhookVerificationError("Invalid Signature Headers");
|
|
2185
|
+
}
|
|
2186
|
+
if (now - timestamp > WEBHOOK_TOLERANCE_IN_SECONDS) {
|
|
2187
|
+
throw new WebhookVerificationError("Message timestamp too old");
|
|
2188
|
+
}
|
|
2189
|
+
if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) {
|
|
2190
|
+
throw new WebhookVerificationError("Message timestamp too new");
|
|
2191
|
+
}
|
|
2192
|
+
return new Date(timestamp * 1000);
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
Webhook_1 = dist.Webhook = Webhook;
|
|
2196
|
+
Webhook.prefix = "whsec_";
|
|
2197
|
+
|
|
2198
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2199
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
2200
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
2201
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
2202
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
2203
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
2204
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2205
|
+
});
|
|
2206
|
+
};
|
|
2207
|
+
var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
|
|
2208
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
2209
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
2210
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
2211
|
+
function step(op) {
|
|
2212
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
2213
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
2214
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
2215
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
2216
|
+
switch (op[0]) {
|
|
2217
|
+
case 0: case 1: t = op; break;
|
|
2218
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
2219
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
2220
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
2221
|
+
default:
|
|
2222
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
2223
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
2224
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
2225
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
2226
|
+
if (t[2]) _.ops.pop();
|
|
2227
|
+
_.trys.pop(); continue;
|
|
2228
|
+
}
|
|
2229
|
+
op = body.call(thisArg, _);
|
|
2230
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
2231
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
2232
|
+
}
|
|
2233
|
+
};
|
|
2234
|
+
var handleWebhookPayload = function (payload, config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2235
|
+
return __generator(this, function (_a) {
|
|
2236
|
+
switch (_a.label) {
|
|
2237
|
+
case 0:
|
|
2238
|
+
if (!config.onPayload) return [3 /*break*/, 2];
|
|
2239
|
+
return [4 /*yield*/, config.onPayload(payload)];
|
|
2240
|
+
case 1:
|
|
2241
|
+
_a.sent();
|
|
2242
|
+
_a.label = 2;
|
|
2243
|
+
case 2:
|
|
2244
|
+
if (!(payload.type === "payment.succeeded" && config.onPaymentSucceeded)) return [3 /*break*/, 4];
|
|
2245
|
+
return [4 /*yield*/, config.onPaymentSucceeded(payload)];
|
|
2246
|
+
case 3:
|
|
2247
|
+
_a.sent();
|
|
2248
|
+
_a.label = 4;
|
|
2249
|
+
case 4:
|
|
2250
|
+
if (!(payload.type === "payment.failed" && config.onPaymentFailed)) return [3 /*break*/, 6];
|
|
2251
|
+
return [4 /*yield*/, config.onPaymentFailed(payload)];
|
|
2252
|
+
case 5:
|
|
2253
|
+
_a.sent();
|
|
2254
|
+
_a.label = 6;
|
|
2255
|
+
case 6:
|
|
2256
|
+
if (!(payload.type === "payment.processing" && config.onPaymentProcessing)) return [3 /*break*/, 8];
|
|
2257
|
+
return [4 /*yield*/, config.onPaymentProcessing(payload)];
|
|
2258
|
+
case 7:
|
|
2259
|
+
_a.sent();
|
|
2260
|
+
_a.label = 8;
|
|
2261
|
+
case 8:
|
|
2262
|
+
if (!(payload.type === "payment.cancelled" && config.onPaymentCancelled)) return [3 /*break*/, 10];
|
|
2263
|
+
return [4 /*yield*/, config.onPaymentCancelled(payload)];
|
|
2264
|
+
case 9:
|
|
2265
|
+
_a.sent();
|
|
2266
|
+
_a.label = 10;
|
|
2267
|
+
case 10:
|
|
2268
|
+
if (!(payload.type === "refund.succeeded" && config.onRefundSucceeded)) return [3 /*break*/, 12];
|
|
2269
|
+
return [4 /*yield*/, config.onRefundSucceeded(payload)];
|
|
2270
|
+
case 11:
|
|
2271
|
+
_a.sent();
|
|
2272
|
+
_a.label = 12;
|
|
2273
|
+
case 12:
|
|
2274
|
+
if (!(payload.type === "refund.failed" && config.onRefundFailed)) return [3 /*break*/, 14];
|
|
2275
|
+
return [4 /*yield*/, config.onRefundFailed(payload)];
|
|
2276
|
+
case 13:
|
|
2277
|
+
_a.sent();
|
|
2278
|
+
_a.label = 14;
|
|
2279
|
+
case 14:
|
|
2280
|
+
if (!(payload.type === "dispute.opened" && config.onDisputeOpened)) return [3 /*break*/, 16];
|
|
2281
|
+
return [4 /*yield*/, config.onDisputeOpened(payload)];
|
|
2282
|
+
case 15:
|
|
2283
|
+
_a.sent();
|
|
2284
|
+
_a.label = 16;
|
|
2285
|
+
case 16:
|
|
2286
|
+
if (!(payload.type === "dispute.expired" && config.onDisputeExpired)) return [3 /*break*/, 18];
|
|
2287
|
+
return [4 /*yield*/, config.onDisputeExpired(payload)];
|
|
2288
|
+
case 17:
|
|
2289
|
+
_a.sent();
|
|
2290
|
+
_a.label = 18;
|
|
2291
|
+
case 18:
|
|
2292
|
+
if (!(payload.type === "dispute.accepted" && config.onDisputeAccepted)) return [3 /*break*/, 20];
|
|
2293
|
+
return [4 /*yield*/, config.onDisputeAccepted(payload)];
|
|
2294
|
+
case 19:
|
|
2295
|
+
_a.sent();
|
|
2296
|
+
_a.label = 20;
|
|
2297
|
+
case 20:
|
|
2298
|
+
if (!(payload.type === "dispute.cancelled" && config.onDisputeCancelled)) return [3 /*break*/, 22];
|
|
2299
|
+
return [4 /*yield*/, config.onDisputeCancelled(payload)];
|
|
2300
|
+
case 21:
|
|
2301
|
+
_a.sent();
|
|
2302
|
+
_a.label = 22;
|
|
2303
|
+
case 22:
|
|
2304
|
+
if (!(payload.type === "dispute.challenged" && config.onDisputeChallenged)) return [3 /*break*/, 24];
|
|
2305
|
+
return [4 /*yield*/, config.onDisputeChallenged(payload)];
|
|
2306
|
+
case 23:
|
|
2307
|
+
_a.sent();
|
|
2308
|
+
_a.label = 24;
|
|
2309
|
+
case 24:
|
|
2310
|
+
if (!(payload.type === "dispute.won" && config.onDisputeWon)) return [3 /*break*/, 26];
|
|
2311
|
+
return [4 /*yield*/, config.onDisputeWon(payload)];
|
|
2312
|
+
case 25:
|
|
2313
|
+
_a.sent();
|
|
2314
|
+
_a.label = 26;
|
|
2315
|
+
case 26:
|
|
2316
|
+
if (!(payload.type === "dispute.lost" && config.onDisputeLost)) return [3 /*break*/, 28];
|
|
2317
|
+
return [4 /*yield*/, config.onDisputeLost(payload)];
|
|
2318
|
+
case 27:
|
|
2319
|
+
_a.sent();
|
|
2320
|
+
_a.label = 28;
|
|
2321
|
+
case 28:
|
|
2322
|
+
if (!(payload.type === "subscription.active" && config.onSubscriptionActive)) return [3 /*break*/, 30];
|
|
2323
|
+
return [4 /*yield*/, config.onSubscriptionActive(payload)];
|
|
2324
|
+
case 29:
|
|
2325
|
+
_a.sent();
|
|
2326
|
+
_a.label = 30;
|
|
2327
|
+
case 30:
|
|
2328
|
+
if (!(payload.type === "subscription.on_hold" && config.onSubscriptionOnHold)) return [3 /*break*/, 32];
|
|
2329
|
+
return [4 /*yield*/, config.onSubscriptionOnHold(payload)];
|
|
2330
|
+
case 31:
|
|
2331
|
+
_a.sent();
|
|
2332
|
+
_a.label = 32;
|
|
2333
|
+
case 32:
|
|
2334
|
+
if (!(payload.type === "subscription.renewed" && config.onSubscriptionRenewed)) return [3 /*break*/, 34];
|
|
2335
|
+
return [4 /*yield*/, config.onSubscriptionRenewed(payload)];
|
|
2336
|
+
case 33:
|
|
2337
|
+
_a.sent();
|
|
2338
|
+
_a.label = 34;
|
|
2339
|
+
case 34:
|
|
2340
|
+
if (!(payload.type === "subscription.paused" && config.onSubscriptionPaused)) return [3 /*break*/, 36];
|
|
2341
|
+
return [4 /*yield*/, config.onSubscriptionPaused(payload)];
|
|
2342
|
+
case 35:
|
|
2343
|
+
_a.sent();
|
|
2344
|
+
_a.label = 36;
|
|
2345
|
+
case 36:
|
|
2346
|
+
if (!(payload.type === "subscription.plan_changed" &&
|
|
2347
|
+
config.onSubscriptionPlanChanged)) return [3 /*break*/, 38];
|
|
2348
|
+
return [4 /*yield*/, config.onSubscriptionPlanChanged(payload)];
|
|
2349
|
+
case 37:
|
|
2350
|
+
_a.sent();
|
|
2351
|
+
_a.label = 38;
|
|
2352
|
+
case 38:
|
|
2353
|
+
if (!(payload.type === "subscription.cancelled" &&
|
|
2354
|
+
config.onSubscriptionCancelled)) return [3 /*break*/, 40];
|
|
2355
|
+
return [4 /*yield*/, config.onSubscriptionCancelled(payload)];
|
|
2356
|
+
case 39:
|
|
2357
|
+
_a.sent();
|
|
2358
|
+
_a.label = 40;
|
|
2359
|
+
case 40:
|
|
2360
|
+
if (!(payload.type === "subscription.failed" && config.onSubscriptionFailed)) return [3 /*break*/, 42];
|
|
2361
|
+
return [4 /*yield*/, config.onSubscriptionFailed(payload)];
|
|
2362
|
+
case 41:
|
|
2363
|
+
_a.sent();
|
|
2364
|
+
_a.label = 42;
|
|
2365
|
+
case 42:
|
|
2366
|
+
if (!(payload.type === "subscription.expired" && config.onSubscriptionExpired)) return [3 /*break*/, 44];
|
|
2367
|
+
return [4 /*yield*/, config.onSubscriptionExpired(payload)];
|
|
2368
|
+
case 43:
|
|
2369
|
+
_a.sent();
|
|
2370
|
+
_a.label = 44;
|
|
2371
|
+
case 44:
|
|
2372
|
+
if (!(payload.type === "license_key.created" && config.onLicenseKeyCreated)) return [3 /*break*/, 46];
|
|
2373
|
+
return [4 /*yield*/, config.onLicenseKeyCreated(payload)];
|
|
2374
|
+
case 45:
|
|
2375
|
+
_a.sent();
|
|
2376
|
+
_a.label = 46;
|
|
2377
|
+
case 46: return [2 /*return*/];
|
|
2378
|
+
}
|
|
2379
|
+
});
|
|
2380
|
+
}); };
|
|
2381
|
+
var verifyWebhookPayload = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
2382
|
+
var standardWebhook, _c, success, payload, error;
|
|
2383
|
+
var webhookKey = _b.webhookKey, headers = _b.headers, body = _b.body;
|
|
2384
|
+
return __generator(this, function (_d) {
|
|
2385
|
+
standardWebhook = new Webhook_1(webhookKey);
|
|
2386
|
+
try {
|
|
2387
|
+
standardWebhook.verify(body, headers);
|
|
2388
|
+
}
|
|
2389
|
+
catch (e) {
|
|
2390
|
+
if (e instanceof WebhookVerificationError_1) {
|
|
2391
|
+
throw new Error(e.message);
|
|
2392
|
+
}
|
|
2393
|
+
throw e;
|
|
2394
|
+
}
|
|
2395
|
+
_c = WebhookPayloadSchema.safeParse(JSON.parse(body)), success = _c.success, payload = _c.data, error = _c.error;
|
|
2396
|
+
if (!success) {
|
|
2397
|
+
throw new Error(error.message);
|
|
2398
|
+
}
|
|
2399
|
+
return [2 /*return*/, payload];
|
|
2400
|
+
});
|
|
2401
|
+
}); };
|
|
2402
|
+
|
|
2403
|
+
/**
|
|
2404
|
+
* Creates a Convex HTTP action to securely handle Dodo Payments webhooks.
|
|
2405
|
+
*
|
|
2406
|
+
* @param handlers - An object containing your webhook event handlers (e.g., onPaymentSucceeded).
|
|
2407
|
+
* @returns A Convex HTTP action.
|
|
2408
|
+
*/
|
|
2409
|
+
const createDodoWebhookHandler = (handlers) => {
|
|
2410
|
+
return httpAction(async (_, request) => {
|
|
2411
|
+
const webhookSecret = process.env.DODO_PAYMENTS_WEBHOOK_SECRET;
|
|
2412
|
+
if (!webhookSecret) {
|
|
2413
|
+
throw new Error("DODO_PAYMENTS_WEBHOOK_SECRET environment variable is not set.");
|
|
2414
|
+
}
|
|
2415
|
+
const body = await request.text();
|
|
2416
|
+
const headers = {};
|
|
2417
|
+
request.headers.forEach((value, key) => {
|
|
2418
|
+
headers[key] = value;
|
|
2419
|
+
});
|
|
2420
|
+
try {
|
|
2421
|
+
const payload = await verifyWebhookPayload({
|
|
2422
|
+
webhookKey: webhookSecret,
|
|
2423
|
+
headers,
|
|
2424
|
+
body,
|
|
2425
|
+
});
|
|
2426
|
+
await handleWebhookPayload(payload, {
|
|
2427
|
+
webhookKey: webhookSecret,
|
|
2428
|
+
...handlers,
|
|
2429
|
+
});
|
|
2430
|
+
return new Response(null, { status: 200 });
|
|
2431
|
+
}
|
|
2432
|
+
catch (error) {
|
|
2433
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
2434
|
+
console.error("Dodo Payments Webhook Error:", errorMessage);
|
|
2435
|
+
return new Response("Error while processing webhook", { status: 400 });
|
|
2436
|
+
}
|
|
2437
|
+
});
|
|
2438
|
+
};
|
|
2439
|
+
|
|
2440
|
+
export { DodoPayments, convex_config as component, createDodoWebhookHandler };
|
|
2441
|
+
//# sourceMappingURL=index.js.map
|