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