@dodopayments/express 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -7508,6 +7508,32 @@ var buildCheckoutUrl = async ({
7508
7508
  }
7509
7509
  };
7510
7510
 
7511
+ var __create = Object.create;
7512
+ var __defProp = Object.defineProperty;
7513
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7514
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7515
+ var __getProtoOf = Object.getPrototypeOf;
7516
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7517
+ var __commonJS = (cb, mod) => function __require2() {
7518
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
7519
+ };
7520
+ var __copyProps = (to, from, except, desc) => {
7521
+ if (from && typeof from === "object" || typeof from === "function") {
7522
+ for (let key of __getOwnPropNames(from))
7523
+ if (!__hasOwnProp.call(to, key) && key !== except)
7524
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
7525
+ }
7526
+ return to;
7527
+ };
7528
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
7529
+ // If the importer is in node compatibility mode or this is not an ESM
7530
+ // file that has been converted to a CommonJS file using a Babel-
7531
+ // compatible transform (i.e. "__esModule" has not been set), then set
7532
+ // "default" to the CommonJS "module.exports" for node compatibility.
7533
+ __defProp(target, "default", { value: mod, enumerable: true }) ,
7534
+ mod
7535
+ ));
7536
+
7511
7537
  function checkoutHandler(config) {
7512
7538
  const getHandler = async (req, res) => {
7513
7539
  const queryParams = req.query;
@@ -7585,18 +7611,33 @@ function checkoutHandler(config) {
7585
7611
  };
7586
7612
  }
7587
7613
 
7614
+ // Helper to extract a string value from Express query params
7615
+ const getQueryString = (value) => {
7616
+ if (value === undefined)
7617
+ return undefined;
7618
+ if (typeof value === "string")
7619
+ return value;
7620
+ if (Array.isArray(value)) {
7621
+ const first = value[0];
7622
+ return typeof first === "string" ? first : undefined;
7623
+ }
7624
+ return undefined;
7625
+ };
7588
7626
  const CustomerPortal = ({ bearerToken, environment, }) => {
7589
7627
  const getHandler = async (req, res) => {
7590
7628
  // Extract customerId from query parameters
7591
7629
  const { customer_id: customerId, send_email } = req.query;
7592
- const params = {
7593
- send_email: false,
7594
- };
7595
- const sendEmail = Boolean(send_email);
7596
- if (sendEmail) {
7597
- params.send_email = sendEmail;
7598
- }
7599
- if (!customerId) {
7630
+ // Normalize customer_id to string
7631
+ const customerIdValue = getQueryString(customerId);
7632
+ const params = {};
7633
+ if (send_email !== undefined) {
7634
+ // Normalize to string
7635
+ const sendEmailValue = Array.isArray(send_email)
7636
+ ? send_email[0]
7637
+ : send_email;
7638
+ params.send_email = sendEmailValue === "true";
7639
+ }
7640
+ if (!customerIdValue) {
7600
7641
  return res.status(400).send("Missing customerId in query parameters");
7601
7642
  }
7602
7643
  const dodopayments = new DodoPayments({
@@ -7604,7 +7645,7 @@ const CustomerPortal = ({ bearerToken, environment, }) => {
7604
7645
  environment,
7605
7646
  });
7606
7647
  try {
7607
- const session = await dodopayments.customers.customerPortal.create(customerId, params);
7648
+ const session = await dodopayments.customers.customerPortal.create(customerIdValue, params);
7608
7649
  return res.redirect(session.link);
7609
7650
  }
7610
7651
  catch (error) {
@@ -7966,6 +8007,675 @@ var WebhookPayloadSchema = discriminatedUnionType("type", [
7966
8007
  LicenseKeyCreatedPayloadSchema
7967
8008
  ]);
7968
8009
 
8010
+ // ../../node_modules/@stablelib/base64/lib/base64.js
8011
+ var require_base64 = __commonJS({
8012
+ "../../node_modules/@stablelib/base64/lib/base64.js"(exports) {
8013
+ var __extends = exports && exports.__extends || /* @__PURE__ */ function() {
8014
+ var extendStatics = function(d, b) {
8015
+ extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
8016
+ d2.__proto__ = b2;
8017
+ } || function(d2, b2) {
8018
+ for (var p in b2) if (b2.hasOwnProperty(p)) d2[p] = b2[p];
8019
+ };
8020
+ return extendStatics(d, b);
8021
+ };
8022
+ return function(d, b) {
8023
+ extendStatics(d, b);
8024
+ function __() {
8025
+ this.constructor = d;
8026
+ }
8027
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
8028
+ };
8029
+ }();
8030
+ Object.defineProperty(exports, "__esModule", { value: true });
8031
+ var INVALID_BYTE = 256;
8032
+ var Coder = (
8033
+ /** @class */
8034
+ function() {
8035
+ function Coder2(_paddingCharacter) {
8036
+ if (_paddingCharacter === void 0) {
8037
+ _paddingCharacter = "=";
8038
+ }
8039
+ this._paddingCharacter = _paddingCharacter;
8040
+ }
8041
+ Coder2.prototype.encodedLength = function(length) {
8042
+ if (!this._paddingCharacter) {
8043
+ return (length * 8 + 5) / 6 | 0;
8044
+ }
8045
+ return (length + 2) / 3 * 4 | 0;
8046
+ };
8047
+ Coder2.prototype.encode = function(data) {
8048
+ var out = "";
8049
+ var i = 0;
8050
+ for (; i < data.length - 2; i += 3) {
8051
+ var c = data[i] << 16 | data[i + 1] << 8 | data[i + 2];
8052
+ out += this._encodeByte(c >>> 3 * 6 & 63);
8053
+ out += this._encodeByte(c >>> 2 * 6 & 63);
8054
+ out += this._encodeByte(c >>> 1 * 6 & 63);
8055
+ out += this._encodeByte(c >>> 0 * 6 & 63);
8056
+ }
8057
+ var left = data.length - i;
8058
+ if (left > 0) {
8059
+ var c = data[i] << 16 | (left === 2 ? data[i + 1] << 8 : 0);
8060
+ out += this._encodeByte(c >>> 3 * 6 & 63);
8061
+ out += this._encodeByte(c >>> 2 * 6 & 63);
8062
+ if (left === 2) {
8063
+ out += this._encodeByte(c >>> 1 * 6 & 63);
8064
+ } else {
8065
+ out += this._paddingCharacter || "";
8066
+ }
8067
+ out += this._paddingCharacter || "";
8068
+ }
8069
+ return out;
8070
+ };
8071
+ Coder2.prototype.maxDecodedLength = function(length) {
8072
+ if (!this._paddingCharacter) {
8073
+ return (length * 6 + 7) / 8 | 0;
8074
+ }
8075
+ return length / 4 * 3 | 0;
8076
+ };
8077
+ Coder2.prototype.decodedLength = function(s) {
8078
+ return this.maxDecodedLength(s.length - this._getPaddingLength(s));
8079
+ };
8080
+ Coder2.prototype.decode = function(s) {
8081
+ if (s.length === 0) {
8082
+ return new Uint8Array(0);
8083
+ }
8084
+ var paddingLength = this._getPaddingLength(s);
8085
+ var length = s.length - paddingLength;
8086
+ var out = new Uint8Array(this.maxDecodedLength(length));
8087
+ var op = 0;
8088
+ var i = 0;
8089
+ var haveBad = 0;
8090
+ var v0 = 0, v1 = 0, v2 = 0, v3 = 0;
8091
+ for (; i < length - 4; i += 4) {
8092
+ v0 = this._decodeChar(s.charCodeAt(i + 0));
8093
+ v1 = this._decodeChar(s.charCodeAt(i + 1));
8094
+ v2 = this._decodeChar(s.charCodeAt(i + 2));
8095
+ v3 = this._decodeChar(s.charCodeAt(i + 3));
8096
+ out[op++] = v0 << 2 | v1 >>> 4;
8097
+ out[op++] = v1 << 4 | v2 >>> 2;
8098
+ out[op++] = v2 << 6 | v3;
8099
+ haveBad |= v0 & INVALID_BYTE;
8100
+ haveBad |= v1 & INVALID_BYTE;
8101
+ haveBad |= v2 & INVALID_BYTE;
8102
+ haveBad |= v3 & INVALID_BYTE;
8103
+ }
8104
+ if (i < length - 1) {
8105
+ v0 = this._decodeChar(s.charCodeAt(i));
8106
+ v1 = this._decodeChar(s.charCodeAt(i + 1));
8107
+ out[op++] = v0 << 2 | v1 >>> 4;
8108
+ haveBad |= v0 & INVALID_BYTE;
8109
+ haveBad |= v1 & INVALID_BYTE;
8110
+ }
8111
+ if (i < length - 2) {
8112
+ v2 = this._decodeChar(s.charCodeAt(i + 2));
8113
+ out[op++] = v1 << 4 | v2 >>> 2;
8114
+ haveBad |= v2 & INVALID_BYTE;
8115
+ }
8116
+ if (i < length - 3) {
8117
+ v3 = this._decodeChar(s.charCodeAt(i + 3));
8118
+ out[op++] = v2 << 6 | v3;
8119
+ haveBad |= v3 & INVALID_BYTE;
8120
+ }
8121
+ if (haveBad !== 0) {
8122
+ throw new Error("Base64Coder: incorrect characters for decoding");
8123
+ }
8124
+ return out;
8125
+ };
8126
+ Coder2.prototype._encodeByte = function(b) {
8127
+ var result = b;
8128
+ result += 65;
8129
+ result += 25 - b >>> 8 & 0 - 65 - 26 + 97;
8130
+ result += 51 - b >>> 8 & 26 - 97 - 52 + 48;
8131
+ result += 61 - b >>> 8 & 52 - 48 - 62 + 43;
8132
+ result += 62 - b >>> 8 & 62 - 43 - 63 + 47;
8133
+ return String.fromCharCode(result);
8134
+ };
8135
+ Coder2.prototype._decodeChar = function(c) {
8136
+ var result = INVALID_BYTE;
8137
+ result += (42 - c & c - 44) >>> 8 & -INVALID_BYTE + c - 43 + 62;
8138
+ result += (46 - c & c - 48) >>> 8 & -INVALID_BYTE + c - 47 + 63;
8139
+ result += (47 - c & c - 58) >>> 8 & -INVALID_BYTE + c - 48 + 52;
8140
+ result += (64 - c & c - 91) >>> 8 & -INVALID_BYTE + c - 65 + 0;
8141
+ result += (96 - c & c - 123) >>> 8 & -INVALID_BYTE + c - 97 + 26;
8142
+ return result;
8143
+ };
8144
+ Coder2.prototype._getPaddingLength = function(s) {
8145
+ var paddingLength = 0;
8146
+ if (this._paddingCharacter) {
8147
+ for (var i = s.length - 1; i >= 0; i--) {
8148
+ if (s[i] !== this._paddingCharacter) {
8149
+ break;
8150
+ }
8151
+ paddingLength++;
8152
+ }
8153
+ if (s.length < 4 || paddingLength > 2) {
8154
+ throw new Error("Base64Coder: incorrect padding");
8155
+ }
8156
+ }
8157
+ return paddingLength;
8158
+ };
8159
+ return Coder2;
8160
+ }()
8161
+ );
8162
+ exports.Coder = Coder;
8163
+ var stdCoder = new Coder();
8164
+ function encode2(data) {
8165
+ return stdCoder.encode(data);
8166
+ }
8167
+ exports.encode = encode2;
8168
+ function decode2(s) {
8169
+ return stdCoder.decode(s);
8170
+ }
8171
+ exports.decode = decode2;
8172
+ var URLSafeCoder = (
8173
+ /** @class */
8174
+ function(_super) {
8175
+ __extends(URLSafeCoder2, _super);
8176
+ function URLSafeCoder2() {
8177
+ return _super !== null && _super.apply(this, arguments) || this;
8178
+ }
8179
+ URLSafeCoder2.prototype._encodeByte = function(b) {
8180
+ var result = b;
8181
+ result += 65;
8182
+ result += 25 - b >>> 8 & 0 - 65 - 26 + 97;
8183
+ result += 51 - b >>> 8 & 26 - 97 - 52 + 48;
8184
+ result += 61 - b >>> 8 & 52 - 48 - 62 + 45;
8185
+ result += 62 - b >>> 8 & 62 - 45 - 63 + 95;
8186
+ return String.fromCharCode(result);
8187
+ };
8188
+ URLSafeCoder2.prototype._decodeChar = function(c) {
8189
+ var result = INVALID_BYTE;
8190
+ result += (44 - c & c - 46) >>> 8 & -INVALID_BYTE + c - 45 + 62;
8191
+ result += (94 - c & c - 96) >>> 8 & -INVALID_BYTE + c - 95 + 63;
8192
+ result += (47 - c & c - 58) >>> 8 & -INVALID_BYTE + c - 48 + 52;
8193
+ result += (64 - c & c - 91) >>> 8 & -INVALID_BYTE + c - 65 + 0;
8194
+ result += (96 - c & c - 123) >>> 8 & -INVALID_BYTE + c - 97 + 26;
8195
+ return result;
8196
+ };
8197
+ return URLSafeCoder2;
8198
+ }(Coder)
8199
+ );
8200
+ exports.URLSafeCoder = URLSafeCoder;
8201
+ var urlSafeCoder = new URLSafeCoder();
8202
+ function encodeURLSafe(data) {
8203
+ return urlSafeCoder.encode(data);
8204
+ }
8205
+ exports.encodeURLSafe = encodeURLSafe;
8206
+ function decodeURLSafe(s) {
8207
+ return urlSafeCoder.decode(s);
8208
+ }
8209
+ exports.decodeURLSafe = decodeURLSafe;
8210
+ exports.encodedLength = function(length) {
8211
+ return stdCoder.encodedLength(length);
8212
+ };
8213
+ exports.maxDecodedLength = function(length) {
8214
+ return stdCoder.maxDecodedLength(length);
8215
+ };
8216
+ exports.decodedLength = function(s) {
8217
+ return stdCoder.decodedLength(s);
8218
+ };
8219
+ }
8220
+ });
8221
+
8222
+ // ../../node_modules/fast-sha256/sha256.js
8223
+ var require_sha256 = __commonJS({
8224
+ "../../node_modules/fast-sha256/sha256.js"(exports, module) {
8225
+ (function(root, factory) {
8226
+ var exports2 = {};
8227
+ factory(exports2);
8228
+ var sha2562 = exports2["default"];
8229
+ for (var k in exports2) {
8230
+ sha2562[k] = exports2[k];
8231
+ }
8232
+ if (typeof module === "object" && typeof module.exports === "object") {
8233
+ module.exports = sha2562;
8234
+ } else if (typeof define === "function" && define.amd) {
8235
+ define(function() {
8236
+ return sha2562;
8237
+ });
8238
+ } else {
8239
+ root.sha256 = sha2562;
8240
+ }
8241
+ })(exports, function(exports2) {
8242
+ exports2.__esModule = true;
8243
+ exports2.digestLength = 32;
8244
+ exports2.blockSize = 64;
8245
+ var K = new Uint32Array([
8246
+ 1116352408,
8247
+ 1899447441,
8248
+ 3049323471,
8249
+ 3921009573,
8250
+ 961987163,
8251
+ 1508970993,
8252
+ 2453635748,
8253
+ 2870763221,
8254
+ 3624381080,
8255
+ 310598401,
8256
+ 607225278,
8257
+ 1426881987,
8258
+ 1925078388,
8259
+ 2162078206,
8260
+ 2614888103,
8261
+ 3248222580,
8262
+ 3835390401,
8263
+ 4022224774,
8264
+ 264347078,
8265
+ 604807628,
8266
+ 770255983,
8267
+ 1249150122,
8268
+ 1555081692,
8269
+ 1996064986,
8270
+ 2554220882,
8271
+ 2821834349,
8272
+ 2952996808,
8273
+ 3210313671,
8274
+ 3336571891,
8275
+ 3584528711,
8276
+ 113926993,
8277
+ 338241895,
8278
+ 666307205,
8279
+ 773529912,
8280
+ 1294757372,
8281
+ 1396182291,
8282
+ 1695183700,
8283
+ 1986661051,
8284
+ 2177026350,
8285
+ 2456956037,
8286
+ 2730485921,
8287
+ 2820302411,
8288
+ 3259730800,
8289
+ 3345764771,
8290
+ 3516065817,
8291
+ 3600352804,
8292
+ 4094571909,
8293
+ 275423344,
8294
+ 430227734,
8295
+ 506948616,
8296
+ 659060556,
8297
+ 883997877,
8298
+ 958139571,
8299
+ 1322822218,
8300
+ 1537002063,
8301
+ 1747873779,
8302
+ 1955562222,
8303
+ 2024104815,
8304
+ 2227730452,
8305
+ 2361852424,
8306
+ 2428436474,
8307
+ 2756734187,
8308
+ 3204031479,
8309
+ 3329325298
8310
+ ]);
8311
+ function hashBlocks(w, v, p, pos, len) {
8312
+ var a, b, c, d, e, f, g, h, u, i, j, t1, t2;
8313
+ while (len >= 64) {
8314
+ a = v[0];
8315
+ b = v[1];
8316
+ c = v[2];
8317
+ d = v[3];
8318
+ e = v[4];
8319
+ f = v[5];
8320
+ g = v[6];
8321
+ h = v[7];
8322
+ for (i = 0; i < 16; i++) {
8323
+ j = pos + i * 4;
8324
+ w[i] = (p[j] & 255) << 24 | (p[j + 1] & 255) << 16 | (p[j + 2] & 255) << 8 | p[j + 3] & 255;
8325
+ }
8326
+ for (i = 16; i < 64; i++) {
8327
+ u = w[i - 2];
8328
+ t1 = (u >>> 17 | u << 32 - 17) ^ (u >>> 19 | u << 32 - 19) ^ u >>> 10;
8329
+ u = w[i - 15];
8330
+ t2 = (u >>> 7 | u << 32 - 7) ^ (u >>> 18 | u << 32 - 18) ^ u >>> 3;
8331
+ w[i] = (t1 + w[i - 7] | 0) + (t2 + w[i - 16] | 0);
8332
+ }
8333
+ for (i = 0; i < 64; i++) {
8334
+ t1 = (((e >>> 6 | e << 32 - 6) ^ (e >>> 11 | e << 32 - 11) ^ (e >>> 25 | e << 32 - 25)) + (e & f ^ ~e & g) | 0) + (h + (K[i] + w[i] | 0) | 0) | 0;
8335
+ t2 = ((a >>> 2 | a << 32 - 2) ^ (a >>> 13 | a << 32 - 13) ^ (a >>> 22 | a << 32 - 22)) + (a & b ^ a & c ^ b & c) | 0;
8336
+ h = g;
8337
+ g = f;
8338
+ f = e;
8339
+ e = d + t1 | 0;
8340
+ d = c;
8341
+ c = b;
8342
+ b = a;
8343
+ a = t1 + t2 | 0;
8344
+ }
8345
+ v[0] += a;
8346
+ v[1] += b;
8347
+ v[2] += c;
8348
+ v[3] += d;
8349
+ v[4] += e;
8350
+ v[5] += f;
8351
+ v[6] += g;
8352
+ v[7] += h;
8353
+ pos += 64;
8354
+ len -= 64;
8355
+ }
8356
+ return pos;
8357
+ }
8358
+ var Hash = (
8359
+ /** @class */
8360
+ function() {
8361
+ function Hash2() {
8362
+ this.digestLength = exports2.digestLength;
8363
+ this.blockSize = exports2.blockSize;
8364
+ this.state = new Int32Array(8);
8365
+ this.temp = new Int32Array(64);
8366
+ this.buffer = new Uint8Array(128);
8367
+ this.bufferLength = 0;
8368
+ this.bytesHashed = 0;
8369
+ this.finished = false;
8370
+ this.reset();
8371
+ }
8372
+ Hash2.prototype.reset = function() {
8373
+ this.state[0] = 1779033703;
8374
+ this.state[1] = 3144134277;
8375
+ this.state[2] = 1013904242;
8376
+ this.state[3] = 2773480762;
8377
+ this.state[4] = 1359893119;
8378
+ this.state[5] = 2600822924;
8379
+ this.state[6] = 528734635;
8380
+ this.state[7] = 1541459225;
8381
+ this.bufferLength = 0;
8382
+ this.bytesHashed = 0;
8383
+ this.finished = false;
8384
+ return this;
8385
+ };
8386
+ Hash2.prototype.clean = function() {
8387
+ for (var i = 0; i < this.buffer.length; i++) {
8388
+ this.buffer[i] = 0;
8389
+ }
8390
+ for (var i = 0; i < this.temp.length; i++) {
8391
+ this.temp[i] = 0;
8392
+ }
8393
+ this.reset();
8394
+ };
8395
+ Hash2.prototype.update = function(data, dataLength) {
8396
+ if (dataLength === void 0) {
8397
+ dataLength = data.length;
8398
+ }
8399
+ if (this.finished) {
8400
+ throw new Error("SHA256: can't update because hash was finished.");
8401
+ }
8402
+ var dataPos = 0;
8403
+ this.bytesHashed += dataLength;
8404
+ if (this.bufferLength > 0) {
8405
+ while (this.bufferLength < 64 && dataLength > 0) {
8406
+ this.buffer[this.bufferLength++] = data[dataPos++];
8407
+ dataLength--;
8408
+ }
8409
+ if (this.bufferLength === 64) {
8410
+ hashBlocks(this.temp, this.state, this.buffer, 0, 64);
8411
+ this.bufferLength = 0;
8412
+ }
8413
+ }
8414
+ if (dataLength >= 64) {
8415
+ dataPos = hashBlocks(this.temp, this.state, data, dataPos, dataLength);
8416
+ dataLength %= 64;
8417
+ }
8418
+ while (dataLength > 0) {
8419
+ this.buffer[this.bufferLength++] = data[dataPos++];
8420
+ dataLength--;
8421
+ }
8422
+ return this;
8423
+ };
8424
+ Hash2.prototype.finish = function(out) {
8425
+ if (!this.finished) {
8426
+ var bytesHashed = this.bytesHashed;
8427
+ var left = this.bufferLength;
8428
+ var bitLenHi = bytesHashed / 536870912 | 0;
8429
+ var bitLenLo = bytesHashed << 3;
8430
+ var padLength = bytesHashed % 64 < 56 ? 64 : 128;
8431
+ this.buffer[left] = 128;
8432
+ for (var i = left + 1; i < padLength - 8; i++) {
8433
+ this.buffer[i] = 0;
8434
+ }
8435
+ this.buffer[padLength - 8] = bitLenHi >>> 24 & 255;
8436
+ this.buffer[padLength - 7] = bitLenHi >>> 16 & 255;
8437
+ this.buffer[padLength - 6] = bitLenHi >>> 8 & 255;
8438
+ this.buffer[padLength - 5] = bitLenHi >>> 0 & 255;
8439
+ this.buffer[padLength - 4] = bitLenLo >>> 24 & 255;
8440
+ this.buffer[padLength - 3] = bitLenLo >>> 16 & 255;
8441
+ this.buffer[padLength - 2] = bitLenLo >>> 8 & 255;
8442
+ this.buffer[padLength - 1] = bitLenLo >>> 0 & 255;
8443
+ hashBlocks(this.temp, this.state, this.buffer, 0, padLength);
8444
+ this.finished = true;
8445
+ }
8446
+ for (var i = 0; i < 8; i++) {
8447
+ out[i * 4 + 0] = this.state[i] >>> 24 & 255;
8448
+ out[i * 4 + 1] = this.state[i] >>> 16 & 255;
8449
+ out[i * 4 + 2] = this.state[i] >>> 8 & 255;
8450
+ out[i * 4 + 3] = this.state[i] >>> 0 & 255;
8451
+ }
8452
+ return this;
8453
+ };
8454
+ Hash2.prototype.digest = function() {
8455
+ var out = new Uint8Array(this.digestLength);
8456
+ this.finish(out);
8457
+ return out;
8458
+ };
8459
+ Hash2.prototype._saveState = function(out) {
8460
+ for (var i = 0; i < this.state.length; i++) {
8461
+ out[i] = this.state[i];
8462
+ }
8463
+ };
8464
+ Hash2.prototype._restoreState = function(from, bytesHashed) {
8465
+ for (var i = 0; i < this.state.length; i++) {
8466
+ this.state[i] = from[i];
8467
+ }
8468
+ this.bytesHashed = bytesHashed;
8469
+ this.finished = false;
8470
+ this.bufferLength = 0;
8471
+ };
8472
+ return Hash2;
8473
+ }()
8474
+ );
8475
+ exports2.Hash = Hash;
8476
+ var HMAC = (
8477
+ /** @class */
8478
+ function() {
8479
+ function HMAC2(key) {
8480
+ this.inner = new Hash();
8481
+ this.outer = new Hash();
8482
+ this.blockSize = this.inner.blockSize;
8483
+ this.digestLength = this.inner.digestLength;
8484
+ var pad = new Uint8Array(this.blockSize);
8485
+ if (key.length > this.blockSize) {
8486
+ new Hash().update(key).finish(pad).clean();
8487
+ } else {
8488
+ for (var i = 0; i < key.length; i++) {
8489
+ pad[i] = key[i];
8490
+ }
8491
+ }
8492
+ for (var i = 0; i < pad.length; i++) {
8493
+ pad[i] ^= 54;
8494
+ }
8495
+ this.inner.update(pad);
8496
+ for (var i = 0; i < pad.length; i++) {
8497
+ pad[i] ^= 54 ^ 92;
8498
+ }
8499
+ this.outer.update(pad);
8500
+ this.istate = new Uint32Array(8);
8501
+ this.ostate = new Uint32Array(8);
8502
+ this.inner._saveState(this.istate);
8503
+ this.outer._saveState(this.ostate);
8504
+ for (var i = 0; i < pad.length; i++) {
8505
+ pad[i] = 0;
8506
+ }
8507
+ }
8508
+ HMAC2.prototype.reset = function() {
8509
+ this.inner._restoreState(this.istate, this.inner.blockSize);
8510
+ this.outer._restoreState(this.ostate, this.outer.blockSize);
8511
+ return this;
8512
+ };
8513
+ HMAC2.prototype.clean = function() {
8514
+ for (var i = 0; i < this.istate.length; i++) {
8515
+ this.ostate[i] = this.istate[i] = 0;
8516
+ }
8517
+ this.inner.clean();
8518
+ this.outer.clean();
8519
+ };
8520
+ HMAC2.prototype.update = function(data) {
8521
+ this.inner.update(data);
8522
+ return this;
8523
+ };
8524
+ HMAC2.prototype.finish = function(out) {
8525
+ if (this.outer.finished) {
8526
+ this.outer.finish(out);
8527
+ } else {
8528
+ this.inner.finish(out);
8529
+ this.outer.update(out, this.digestLength).finish(out);
8530
+ }
8531
+ return this;
8532
+ };
8533
+ HMAC2.prototype.digest = function() {
8534
+ var out = new Uint8Array(this.digestLength);
8535
+ this.finish(out);
8536
+ return out;
8537
+ };
8538
+ return HMAC2;
8539
+ }()
8540
+ );
8541
+ exports2.HMAC = HMAC;
8542
+ function hash(data) {
8543
+ var h = new Hash().update(data);
8544
+ var digest = h.digest();
8545
+ h.clean();
8546
+ return digest;
8547
+ }
8548
+ exports2.hash = hash;
8549
+ exports2["default"] = hash;
8550
+ function hmac2(key, data) {
8551
+ var h = new HMAC(key).update(data);
8552
+ var digest = h.digest();
8553
+ h.clean();
8554
+ return digest;
8555
+ }
8556
+ exports2.hmac = hmac2;
8557
+ function fillBuffer(buffer, hmac3, info, counter) {
8558
+ var num = counter[0];
8559
+ if (num === 0) {
8560
+ throw new Error("hkdf: cannot expand more");
8561
+ }
8562
+ hmac3.reset();
8563
+ if (num > 1) {
8564
+ hmac3.update(buffer);
8565
+ }
8566
+ if (info) {
8567
+ hmac3.update(info);
8568
+ }
8569
+ hmac3.update(counter);
8570
+ hmac3.finish(buffer);
8571
+ counter[0]++;
8572
+ }
8573
+ var hkdfSalt = new Uint8Array(exports2.digestLength);
8574
+ function hkdf(key, salt, info, length) {
8575
+ if (salt === void 0) {
8576
+ salt = hkdfSalt;
8577
+ }
8578
+ if (length === void 0) {
8579
+ length = 32;
8580
+ }
8581
+ var counter = new Uint8Array([1]);
8582
+ var okm = hmac2(salt, key);
8583
+ var hmac_ = new HMAC(okm);
8584
+ var buffer = new Uint8Array(hmac_.digestLength);
8585
+ var bufpos = buffer.length;
8586
+ var out = new Uint8Array(length);
8587
+ for (var i = 0; i < length; i++) {
8588
+ if (bufpos === buffer.length) {
8589
+ fillBuffer(buffer, hmac_, info, counter);
8590
+ bufpos = 0;
8591
+ }
8592
+ out[i] = buffer[bufpos++];
8593
+ }
8594
+ hmac_.clean();
8595
+ buffer.fill(0);
8596
+ counter.fill(0);
8597
+ return out;
8598
+ }
8599
+ exports2.hkdf = hkdf;
8600
+ function pbkdf2(password, salt, iterations, dkLen) {
8601
+ var prf = new HMAC(password);
8602
+ var len = prf.digestLength;
8603
+ var ctr = new Uint8Array(4);
8604
+ var t = new Uint8Array(len);
8605
+ var u = new Uint8Array(len);
8606
+ var dk = new Uint8Array(dkLen);
8607
+ for (var i = 0; i * len < dkLen; i++) {
8608
+ var c = i + 1;
8609
+ ctr[0] = c >>> 24 & 255;
8610
+ ctr[1] = c >>> 16 & 255;
8611
+ ctr[2] = c >>> 8 & 255;
8612
+ ctr[3] = c >>> 0 & 255;
8613
+ prf.reset();
8614
+ prf.update(salt);
8615
+ prf.update(ctr);
8616
+ prf.finish(u);
8617
+ for (var j = 0; j < len; j++) {
8618
+ t[j] = u[j];
8619
+ }
8620
+ for (var j = 2; j <= iterations; j++) {
8621
+ prf.reset();
8622
+ prf.update(u).finish(u);
8623
+ for (var k = 0; k < len; k++) {
8624
+ t[k] ^= u[k];
8625
+ }
8626
+ }
8627
+ for (var j = 0; j < len && i * len + j < dkLen; j++) {
8628
+ dk[i * len + j] = t[j];
8629
+ }
8630
+ }
8631
+ for (var i = 0; i < len; i++) {
8632
+ t[i] = u[i] = 0;
8633
+ }
8634
+ for (var i = 0; i < 4; i++) {
8635
+ ctr[i] = 0;
8636
+ }
8637
+ prf.clean();
8638
+ return dk;
8639
+ }
8640
+ exports2.pbkdf2 = pbkdf2;
8641
+ });
8642
+ }
8643
+ });
8644
+
8645
+ // src/webhook/vendor/standardwebhook.ts
8646
+ __toESM(require_base64());
8647
+ __toESM(require_sha256());
8648
+ /**
8649
+ * The MIT License
8650
+ *
8651
+ * Copyright (c) 2023 Svix (https://www.svix.com)
8652
+ *
8653
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8654
+ * of this software and associated documentation files (the "Software"), to deal
8655
+ * in the Software without restriction, including without limitation the rights
8656
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8657
+ * copies of the Software, and to permit persons to whom the Software is
8658
+ * furnished to do so, subject to the following conditions:
8659
+ *
8660
+ * The above copyright notice and this permission notice shall be included in
8661
+ * all copies or substantial portions of the Software.
8662
+ *
8663
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8664
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
8665
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
8666
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8667
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
8668
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
8669
+ * THE SOFTWARE.
8670
+ *
8671
+ * @fileoverview Server-only webhook verification implementation.
8672
+ * @description Vendored from standardwebhooks package to avoid bundling issues.
8673
+ * Uses Node.js crypto module - DO NOT import in client/browser code.
8674
+ * @license MIT
8675
+ * @internal
8676
+ */
8677
+
8678
+ // src/webhook/webhook.ts
7969
8679
  async function handleWebhookPayload(payload, config, context) {
7970
8680
  const callHandler = (handler, payload2) => {
7971
8681
  if (!handler) return;