@cedarjs/api 5.0.4-next.167 → 5.0.4

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.
Files changed (109) hide show
  1. package/dist/cjs/auth/index.d.ts +64 -0
  2. package/dist/cjs/auth/index.d.ts.map +1 -0
  3. package/dist/cjs/auth/index.js +143 -0
  4. package/dist/cjs/auth/parseJWT.d.ts +6 -0
  5. package/dist/cjs/auth/parseJWT.d.ts.map +1 -0
  6. package/dist/cjs/auth/parseJWT.js +57 -0
  7. package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts +18 -0
  8. package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts.map +1 -0
  9. package/dist/cjs/auth/verifiers/base64Sha1Verifier.js +77 -0
  10. package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts +18 -0
  11. package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts.map +1 -0
  12. package/dist/cjs/auth/verifiers/base64Sha256Verifier.js +77 -0
  13. package/dist/cjs/auth/verifiers/common.d.ts +112 -0
  14. package/dist/cjs/auth/verifiers/common.d.ts.map +1 -0
  15. package/dist/cjs/auth/verifiers/common.js +89 -0
  16. package/dist/cjs/auth/verifiers/index.d.ts +8 -0
  17. package/dist/cjs/auth/verifiers/index.d.ts.map +1 -0
  18. package/dist/cjs/auth/verifiers/index.js +39 -0
  19. package/dist/cjs/auth/verifiers/jwtVerifier.d.ts +18 -0
  20. package/dist/cjs/auth/verifiers/jwtVerifier.d.ts.map +1 -0
  21. package/dist/cjs/auth/verifiers/jwtVerifier.js +84 -0
  22. package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts +11 -0
  23. package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts.map +1 -0
  24. package/dist/cjs/auth/verifiers/secretKeyVerifier.js +43 -0
  25. package/dist/cjs/auth/verifiers/sha1Verifier.d.ts +17 -0
  26. package/dist/cjs/auth/verifiers/sha1Verifier.d.ts.map +1 -0
  27. package/dist/cjs/auth/verifiers/sha1Verifier.js +85 -0
  28. package/dist/cjs/auth/verifiers/sha256Verifier.d.ts +17 -0
  29. package/dist/cjs/auth/verifiers/sha256Verifier.d.ts.map +1 -0
  30. package/dist/cjs/auth/verifiers/sha256Verifier.js +85 -0
  31. package/dist/cjs/auth/verifiers/skipVerifier.d.ts +11 -0
  32. package/dist/cjs/auth/verifiers/skipVerifier.d.ts.map +1 -0
  33. package/dist/cjs/auth/verifiers/skipVerifier.js +40 -0
  34. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts +14 -0
  35. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts.map +1 -0
  36. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.js +86 -0
  37. package/dist/cjs/bins/cedar.d.ts +9 -0
  38. package/dist/cjs/bins/cedar.d.ts.map +1 -0
  39. package/dist/cjs/bins/cedar.js +36 -0
  40. package/dist/cjs/bins/cfw.d.ts +3 -0
  41. package/dist/cjs/bins/cfw.d.ts.map +1 -0
  42. package/dist/cjs/bins/cfw.js +36 -0
  43. package/dist/cjs/bins/redwood.d.ts +9 -0
  44. package/dist/cjs/bins/redwood.d.ts.map +1 -0
  45. package/dist/cjs/bins/redwood.js +36 -0
  46. package/dist/cjs/bins/tsc.d.ts +3 -0
  47. package/dist/cjs/bins/tsc.d.ts.map +1 -0
  48. package/dist/cjs/bins/tsc.js +30 -0
  49. package/dist/cjs/cache/clients/BaseClient.d.ts +11 -0
  50. package/dist/cjs/cache/clients/BaseClient.d.ts.map +1 -0
  51. package/dist/cjs/cache/clients/BaseClient.js +31 -0
  52. package/dist/cjs/cache/clients/InMemoryClient.d.ts +31 -0
  53. package/dist/cjs/cache/clients/InMemoryClient.d.ts.map +1 -0
  54. package/dist/cjs/cache/clients/InMemoryClient.js +94 -0
  55. package/dist/cjs/cache/clients/MemcachedClient.d.ts +16 -0
  56. package/dist/cjs/cache/clients/MemcachedClient.d.ts.map +1 -0
  57. package/dist/cjs/cache/clients/MemcachedClient.js +79 -0
  58. package/dist/cjs/cache/clients/RedisClient.d.ts +20 -0
  59. package/dist/cjs/cache/clients/RedisClient.d.ts.map +1 -0
  60. package/dist/cjs/cache/clients/RedisClient.js +83 -0
  61. package/dist/cjs/cache/errors.d.ts +4 -0
  62. package/dist/cjs/cache/errors.d.ts.map +1 -0
  63. package/dist/cjs/cache/errors.js +33 -0
  64. package/dist/cjs/cache/index.d.ts +35 -0
  65. package/dist/cjs/cache/index.d.ts.map +1 -0
  66. package/dist/cjs/cache/index.js +165 -0
  67. package/dist/cjs/cors.d.ts +16 -0
  68. package/dist/cjs/cors.d.ts.map +1 -0
  69. package/dist/cjs/cors.js +93 -0
  70. package/dist/cjs/errors.d.ts +5 -0
  71. package/dist/cjs/errors.d.ts.map +1 -0
  72. package/dist/cjs/errors.js +38 -0
  73. package/dist/cjs/event.d.ts +3 -0
  74. package/dist/cjs/event.d.ts.map +1 -0
  75. package/dist/cjs/event.js +34 -0
  76. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts +4 -0
  77. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts.map +1 -0
  78. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.js +72 -0
  79. package/dist/cjs/index.d.ts +15 -0
  80. package/dist/cjs/index.d.ts.map +1 -0
  81. package/dist/cjs/index.js +54 -0
  82. package/dist/cjs/logger/index.d.ts +179 -0
  83. package/dist/cjs/logger/index.d.ts.map +1 -0
  84. package/dist/cjs/logger/index.js +185 -0
  85. package/dist/cjs/package.json +1 -0
  86. package/dist/cjs/runtime.d.ts +42 -0
  87. package/dist/cjs/runtime.d.ts.map +1 -0
  88. package/dist/cjs/runtime.js +191 -0
  89. package/dist/cjs/transforms.d.ts +36 -0
  90. package/dist/cjs/transforms.d.ts.map +1 -0
  91. package/dist/cjs/transforms.js +176 -0
  92. package/dist/cjs/types.d.ts +25 -0
  93. package/dist/cjs/types.d.ts.map +1 -0
  94. package/dist/cjs/types.js +16 -0
  95. package/dist/cjs/validations/errors.d.ts +101 -0
  96. package/dist/cjs/validations/errors.d.ts.map +1 -0
  97. package/dist/cjs/validations/errors.js +298 -0
  98. package/dist/cjs/validations/validations.d.ts +235 -0
  99. package/dist/cjs/validations/validations.d.ts.map +1 -0
  100. package/dist/cjs/validations/validations.js +353 -0
  101. package/dist/cjs/webhooks/index.d.ts +77 -0
  102. package/dist/cjs/webhooks/index.d.ts.map +1 -0
  103. package/dist/cjs/webhooks/index.js +102 -0
  104. package/dist/index.js +3 -3
  105. package/package.json +41 -17
  106. package/dist/bins/cedar.js +0 -14
  107. package/dist/bins/cfw.js +0 -14
  108. package/dist/bins/redwood.js +0 -14
  109. package/dist/bins/tsc.js +0 -8
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var common_exports = {};
20
+ __export(common_exports, {
21
+ DEFAULT_TOLERANCE: () => DEFAULT_TOLERANCE,
22
+ DEFAULT_WEBHOOK_SECRET: () => DEFAULT_WEBHOOK_SECRET,
23
+ VERIFICATION_ERROR_MESSAGE: () => VERIFICATION_ERROR_MESSAGE,
24
+ VERIFICATION_SIGN_MESSAGE: () => VERIFICATION_SIGN_MESSAGE,
25
+ WebhookSignError: () => WebhookSignError,
26
+ WebhookVerificationError: () => WebhookVerificationError,
27
+ verifierLookup: () => verifierLookup
28
+ });
29
+ module.exports = __toCommonJS(common_exports);
30
+ var import_base64Sha1Verifier = require("./base64Sha1Verifier.js");
31
+ var import_base64Sha256Verifier = require("./base64Sha256Verifier.js");
32
+ var import_jwtVerifier = require("./jwtVerifier.js");
33
+ var import_secretKeyVerifier = require("./secretKeyVerifier.js");
34
+ var import_sha1Verifier = require("./sha1Verifier.js");
35
+ var import_sha256Verifier = require("./sha256Verifier.js");
36
+ var import_skipVerifier = require("./skipVerifier.js");
37
+ var import_timestampSchemeVerifier = require("./timestampSchemeVerifier.js");
38
+ const verifierLookup = {
39
+ skipVerifier: import_skipVerifier.skipVerifier,
40
+ secretKeyVerifier: import_secretKeyVerifier.secretKeyVerifier,
41
+ sha1Verifier: import_sha1Verifier.sha1Verifier,
42
+ sha256Verifier: import_sha256Verifier.sha256Verifier,
43
+ base64Sha1Verifier: import_base64Sha1Verifier.base64Sha1Verifier,
44
+ base64Sha256Verifier: import_base64Sha256Verifier.base64Sha256Verifier,
45
+ timestampSchemeVerifier: import_timestampSchemeVerifier.timestampSchemeVerifier,
46
+ jwtVerifier: import_jwtVerifier.jwtVerifier
47
+ };
48
+ const DEFAULT_WEBHOOK_SECRET = process.env.WEBHOOK_SECRET ?? "";
49
+ const VERIFICATION_ERROR_MESSAGE = "You don't have access to invoke this function.";
50
+ const VERIFICATION_SIGN_MESSAGE = "Unable to sign payload";
51
+ const FIVE_MINUTES = 5 * 6e4;
52
+ const DEFAULT_TOLERANCE = FIVE_MINUTES;
53
+ class WebhookError extends Error {
54
+ /**
55
+ * Create a WebhookError.
56
+ * @param {string} message - The error message
57
+ * */
58
+ constructor(message) {
59
+ super(message);
60
+ }
61
+ }
62
+ class WebhookVerificationError extends WebhookError {
63
+ /**
64
+ * Create a WebhookVerificationError.
65
+ * @param {string} message - The error message
66
+ * */
67
+ constructor(message) {
68
+ super(message || VERIFICATION_ERROR_MESSAGE);
69
+ }
70
+ }
71
+ class WebhookSignError extends WebhookError {
72
+ /**
73
+ * Create a WebhookSignError.
74
+ * @param {string} message - The error message
75
+ * */
76
+ constructor(message) {
77
+ super(message || VERIFICATION_SIGN_MESSAGE);
78
+ }
79
+ }
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ DEFAULT_TOLERANCE,
83
+ DEFAULT_WEBHOOK_SECRET,
84
+ VERIFICATION_ERROR_MESSAGE,
85
+ VERIFICATION_SIGN_MESSAGE,
86
+ WebhookSignError,
87
+ WebhookVerificationError,
88
+ verifierLookup
89
+ });
@@ -0,0 +1,8 @@
1
+ import type { SupportedVerifierTypes, VerifyOptions, WebhookVerifier } from './common.js';
2
+ /**
3
+ * @param {SupportedVerifierTypes} type - What verification type methods used to sign and verify signatures
4
+ * @param {VerifyOptions} options - Options used to verify the signature based on verifiers requirements
5
+ */
6
+ export declare const createVerifier: (type: SupportedVerifierTypes, options?: VerifyOptions) => WebhookVerifier;
7
+ export * from './common.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/auth/verifiers/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,sBAAsB,EACtB,aAAa,EACb,eAAe,EAChB,MAAM,aAAa,CAAA;AAEpB;;;GAGG;AACH,eAAO,MAAM,cAAc,GACzB,MAAM,sBAAsB,EAC5B,UAAU,aAAa,KACtB,eAQF,CAAA;AAED,cAAc,aAAa,CAAA"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var verifiers_exports = {};
21
+ __export(verifiers_exports, {
22
+ createVerifier: () => createVerifier
23
+ });
24
+ module.exports = __toCommonJS(verifiers_exports);
25
+ var import_common = require("./common.js");
26
+ __reExport(verifiers_exports, require("./common.js"), module.exports);
27
+ const createVerifier = (type, options) => {
28
+ const verifierFactory = import_common.verifierLookup[type];
29
+ if (options) {
30
+ return verifierFactory(options);
31
+ } else {
32
+ return verifierFactory();
33
+ }
34
+ };
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ createVerifier,
38
+ ...require("./common.js")
39
+ });
@@ -0,0 +1,18 @@
1
+ import type { WebhookVerifier, VerifyOptions } from './common.js';
2
+ export interface JwtVerifier extends WebhookVerifier {
3
+ type: 'jwtVerifier';
4
+ }
5
+ export declare const verifySignature: ({ payload, secret, signature, options, }: {
6
+ payload: string | Record<string, unknown>;
7
+ secret: string;
8
+ signature: string;
9
+ options: VerifyOptions | undefined;
10
+ }) => boolean;
11
+ /**
12
+ * JWT Payload Verifier
13
+ *
14
+ * Based on Netlify's webhook payload verification
15
+ * @see: https://docs.netlify.com/site-deploys/notifications/#payload-signature
16
+ */
17
+ export declare function jwtVerifier(options?: VerifyOptions): JwtVerifier;
18
+ //# sourceMappingURL=jwtVerifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwtVerifier.d.ts","sourceRoot":"","sources":["../../../../src/auth/verifiers/jwtVerifier.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEjE,MAAM,WAAW,WAAY,SAAQ,eAAe;IAClD,IAAI,EAAE,aAAa,CAAA;CACpB;AAsBD,eAAO,MAAM,eAAe,GAAI,0CAK7B;IACD,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,aAAa,GAAG,SAAS,CAAA;CACnC,KAAG,OAmBH,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,WAAW,CAUhE"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var jwtVerifier_exports = {};
30
+ __export(jwtVerifier_exports, {
31
+ jwtVerifier: () => jwtVerifier,
32
+ verifySignature: () => verifySignature
33
+ });
34
+ module.exports = __toCommonJS(jwtVerifier_exports);
35
+ var import_jsonwebtoken = __toESM(require("jsonwebtoken"), 1);
36
+ var import_common = require("./common.js");
37
+ const createSignature = ({
38
+ payload,
39
+ secret = import_common.DEFAULT_WEBHOOK_SECRET,
40
+ options
41
+ }) => {
42
+ try {
43
+ const signOptions = options?.issuer ? { issuer: options?.issuer } : void 0;
44
+ return import_jsonwebtoken.default.sign(payload, secret, { ...signOptions });
45
+ } catch (error) {
46
+ throw new import_common.WebhookSignError(error.message);
47
+ }
48
+ };
49
+ const verifySignature = ({
50
+ payload,
51
+ secret = import_common.DEFAULT_WEBHOOK_SECRET,
52
+ signature,
53
+ options
54
+ }) => {
55
+ try {
56
+ if (payload === void 0 || payload?.length === 0) {
57
+ console.warn("Missing payload");
58
+ }
59
+ if (options?.issuer) {
60
+ import_jsonwebtoken.default.verify(signature, secret, { issuer: options?.issuer });
61
+ } else {
62
+ import_jsonwebtoken.default.verify(signature, secret);
63
+ }
64
+ return true;
65
+ } catch {
66
+ throw new import_common.WebhookVerificationError();
67
+ }
68
+ };
69
+ function jwtVerifier(options) {
70
+ return {
71
+ sign: ({ payload, secret }) => {
72
+ return createSignature({ payload, secret, options });
73
+ },
74
+ verify: ({ payload, secret, signature }) => {
75
+ return verifySignature({ payload, secret, signature, options });
76
+ },
77
+ type: "jwtVerifier"
78
+ };
79
+ }
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ jwtVerifier,
83
+ verifySignature
84
+ });
@@ -0,0 +1,11 @@
1
+ import type { WebhookVerifier, VerifyOptions } from './common.js';
2
+ export interface SecretKeyVerifier extends WebhookVerifier {
3
+ type: 'secretKeyVerifier';
4
+ }
5
+ /**
6
+ * Secret Key Verifier
7
+ *
8
+ * Use when the payload is not signed, but rather authorized via a known secret key
9
+ */
10
+ export declare function secretKeyVerifier(_options?: VerifyOptions): SecretKeyVerifier;
11
+ //# sourceMappingURL=secretKeyVerifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secretKeyVerifier.d.ts","sourceRoot":"","sources":["../../../../src/auth/verifiers/secretKeyVerifier.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEjE,MAAM,WAAW,iBAAkB,SAAQ,eAAe;IACxD,IAAI,EAAE,mBAAmB,CAAA;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,iBAAiB,CAgB7E"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var secretKeyVerifier_exports = {};
20
+ __export(secretKeyVerifier_exports, {
21
+ secretKeyVerifier: () => secretKeyVerifier
22
+ });
23
+ module.exports = __toCommonJS(secretKeyVerifier_exports);
24
+ var import_common = require("./common.js");
25
+ function secretKeyVerifier(_options) {
26
+ return {
27
+ sign: ({ secret }) => {
28
+ return secret;
29
+ },
30
+ verify: ({ signature, secret = import_common.DEFAULT_WEBHOOK_SECRET }) => {
31
+ const verified = signature === secret;
32
+ if (!verified) {
33
+ throw new import_common.WebhookVerificationError();
34
+ }
35
+ return verified;
36
+ },
37
+ type: "secretKeyVerifier"
38
+ };
39
+ }
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ secretKeyVerifier
43
+ });
@@ -0,0 +1,17 @@
1
+ import type { WebhookVerifier, VerifyOptions } from './common.js';
2
+ export interface Sha1Verifier extends WebhookVerifier {
3
+ type: 'sha1Verifier';
4
+ }
5
+ export declare const verifySignature: ({ payload, secret, signature, }: {
6
+ payload: string | Record<string, unknown>;
7
+ secret: string;
8
+ signature: string;
9
+ }) => boolean;
10
+ /**
11
+ * SHA1 HMAC Payload Verifier
12
+ *
13
+ * Based on Vercel's webhook payload verification
14
+ * @see https://vercel.com/docs/api#integrations/webhooks/securing-webhooks
15
+ */
16
+ export declare function sha1Verifier(_options?: VerifyOptions): Sha1Verifier;
17
+ //# sourceMappingURL=sha1Verifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha1Verifier.d.ts","sourceRoot":"","sources":["../../../../src/auth/verifiers/sha1Verifier.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEjE,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD,IAAI,EAAE,cAAc,CAAA;CACrB;AA6BD,eAAO,MAAM,eAAe,GAAI,iCAI7B;IACD,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG,OA+BH,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,YAAY,CAUnE"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var sha1Verifier_exports = {};
20
+ __export(sha1Verifier_exports, {
21
+ sha1Verifier: () => sha1Verifier,
22
+ verifySignature: () => verifySignature
23
+ });
24
+ module.exports = __toCommonJS(sha1Verifier_exports);
25
+ var import_crypto = require("crypto");
26
+ var import_common = require("./common.js");
27
+ function toNormalizedJsonString(payload) {
28
+ return JSON.stringify(payload).replace(/[^\\]\\u[\da-f]{4}/g, (s) => {
29
+ return s.substr(0, 3) + s.substr(3).toUpperCase();
30
+ });
31
+ }
32
+ const createSignature = ({
33
+ payload,
34
+ secret = import_common.DEFAULT_WEBHOOK_SECRET
35
+ }) => {
36
+ const algorithm = "sha1";
37
+ const hmac = (0, import_crypto.createHmac)(algorithm, secret);
38
+ payload = typeof payload === "string" ? payload : toNormalizedJsonString(payload);
39
+ const digest = Buffer.from(
40
+ algorithm + "=" + hmac.update(payload).digest("hex"),
41
+ "utf8"
42
+ );
43
+ return digest.toString();
44
+ };
45
+ const verifySignature = ({
46
+ payload,
47
+ secret = import_common.DEFAULT_WEBHOOK_SECRET,
48
+ signature
49
+ }) => {
50
+ try {
51
+ const algorithm = signature.split("=")[0];
52
+ const webhookSignature = Buffer.from(signature || "", "utf8");
53
+ const hmac = (0, import_crypto.createHmac)(algorithm, secret);
54
+ payload = typeof payload === "string" ? payload : toNormalizedJsonString(payload);
55
+ const digest = Buffer.from(
56
+ algorithm + "=" + hmac.update(payload).digest("hex"),
57
+ "utf8"
58
+ );
59
+ const verified = webhookSignature.length === digest.length && (0, import_crypto.timingSafeEqual)(digest, webhookSignature);
60
+ if (verified) {
61
+ return verified;
62
+ }
63
+ throw new import_common.WebhookVerificationError();
64
+ } catch (error) {
65
+ throw new import_common.WebhookVerificationError(
66
+ `${import_common.VERIFICATION_ERROR_MESSAGE}: ${error.message}`
67
+ );
68
+ }
69
+ };
70
+ function sha1Verifier(_options) {
71
+ return {
72
+ sign: ({ payload, secret }) => {
73
+ return createSignature({ payload, secret });
74
+ },
75
+ verify: ({ payload, secret, signature }) => {
76
+ return verifySignature({ payload, secret, signature });
77
+ },
78
+ type: "sha1Verifier"
79
+ };
80
+ }
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ sha1Verifier,
84
+ verifySignature
85
+ });
@@ -0,0 +1,17 @@
1
+ import type { WebhookVerifier, VerifyOptions } from './common.js';
2
+ export interface Sha256Verifier extends WebhookVerifier {
3
+ type: 'sha256Verifier';
4
+ }
5
+ export declare const verifySignature: ({ payload, secret, signature, }: {
6
+ payload: string | Record<string, unknown>;
7
+ secret: string;
8
+ signature: string;
9
+ }) => boolean;
10
+ /**
11
+ * SHA256 HMAC Payload Verifier
12
+ *
13
+ * Based on GitHub's webhook payload verification
14
+ * @see https://docs.github.com/en/developers/webhooks-and-events/securing-your-webhooks
15
+ */
16
+ export declare function sha256Verifier(_options?: VerifyOptions): Sha256Verifier;
17
+ //# sourceMappingURL=sha256Verifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256Verifier.d.ts","sourceRoot":"","sources":["../../../../src/auth/verifiers/sha256Verifier.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEjE,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD,IAAI,EAAE,gBAAgB,CAAA;CACvB;AA6BD,eAAO,MAAM,eAAe,GAAI,iCAI7B;IACD,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG,OA+BH,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,cAAc,CAUvE"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var sha256Verifier_exports = {};
20
+ __export(sha256Verifier_exports, {
21
+ sha256Verifier: () => sha256Verifier,
22
+ verifySignature: () => verifySignature
23
+ });
24
+ module.exports = __toCommonJS(sha256Verifier_exports);
25
+ var import_crypto = require("crypto");
26
+ var import_common = require("./common.js");
27
+ function toNormalizedJsonString(payload) {
28
+ return JSON.stringify(payload).replace(/[^\\]\\u[\da-f]{4}/g, (s) => {
29
+ return s.substr(0, 3) + s.substr(3).toUpperCase();
30
+ });
31
+ }
32
+ const createSignature = ({
33
+ payload,
34
+ secret = import_common.DEFAULT_WEBHOOK_SECRET
35
+ }) => {
36
+ const algorithm = "sha256";
37
+ const hmac = (0, import_crypto.createHmac)(algorithm, secret);
38
+ payload = typeof payload === "string" ? payload : toNormalizedJsonString(payload);
39
+ const digest = Buffer.from(
40
+ algorithm + "=" + hmac.update(payload).digest("hex"),
41
+ "utf8"
42
+ );
43
+ return digest.toString();
44
+ };
45
+ const verifySignature = ({
46
+ payload,
47
+ secret = import_common.DEFAULT_WEBHOOK_SECRET,
48
+ signature
49
+ }) => {
50
+ try {
51
+ const algorithm = signature.split("=")[0];
52
+ const webhookSignature = Buffer.from(signature || "", "utf8");
53
+ const hmac = (0, import_crypto.createHmac)(algorithm, secret);
54
+ payload = typeof payload === "string" ? payload : toNormalizedJsonString(payload);
55
+ const digest = Buffer.from(
56
+ algorithm + "=" + hmac.update(payload).digest("hex"),
57
+ "utf8"
58
+ );
59
+ const verified = webhookSignature.length === digest.length && (0, import_crypto.timingSafeEqual)(digest, webhookSignature);
60
+ if (verified) {
61
+ return verified;
62
+ }
63
+ throw new import_common.WebhookVerificationError();
64
+ } catch (error) {
65
+ throw new import_common.WebhookVerificationError(
66
+ `${import_common.VERIFICATION_ERROR_MESSAGE}: ${error.message}`
67
+ );
68
+ }
69
+ };
70
+ function sha256Verifier(_options) {
71
+ return {
72
+ sign: ({ payload, secret }) => {
73
+ return createSignature({ payload, secret });
74
+ },
75
+ verify: ({ payload, secret, signature }) => {
76
+ return verifySignature({ payload, secret, signature });
77
+ },
78
+ type: "sha256Verifier"
79
+ };
80
+ }
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ sha256Verifier,
84
+ verifySignature
85
+ });
@@ -0,0 +1,11 @@
1
+ import type { VerifyOptions, WebhookVerifier } from './common.js';
2
+ export interface SkipVerifier extends WebhookVerifier {
3
+ type: 'skipVerifier';
4
+ }
5
+ /**
6
+ * skipVerifier skips webhook signature verification.
7
+ * Use when there is no signature provided or the webhook is
8
+ * entirely public.
9
+ */
10
+ export declare function skipVerifier(_options?: VerifyOptions): SkipVerifier;
11
+ //# sourceMappingURL=skipVerifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skipVerifier.d.ts","sourceRoot":"","sources":["../../../../src/auth/verifiers/skipVerifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAEjE,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD,IAAI,EAAE,cAAc,CAAA;CACrB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,YAAY,CAYnE"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var skipVerifier_exports = {};
20
+ __export(skipVerifier_exports, {
21
+ skipVerifier: () => skipVerifier
22
+ });
23
+ module.exports = __toCommonJS(skipVerifier_exports);
24
+ function skipVerifier(_options) {
25
+ return {
26
+ sign: () => {
27
+ console.warn(`No signature is created for the skipVerifier verifier`);
28
+ return "";
29
+ },
30
+ verify: () => {
31
+ console.warn(`The skipVerifier verifier considers all signatures valid`);
32
+ return true;
33
+ },
34
+ type: "skipVerifier"
35
+ };
36
+ }
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ skipVerifier
40
+ });
@@ -0,0 +1,14 @@
1
+ import type { WebhookVerifier, VerifyOptions } from './common.js';
2
+ export interface TimestampSchemeVerifier extends WebhookVerifier {
3
+ type: 'timestampSchemeVerifier';
4
+ }
5
+ /**
6
+ * Timestamp & Scheme Verifier
7
+ *
8
+ * Based on Stripe's secure webhook implementation
9
+ *
10
+ * @see https://stripe.com/docs/webhooks/signatures
11
+ */
12
+ export declare function timestampSchemeVerifier(options?: VerifyOptions): TimestampSchemeVerifier;
13
+ export default timestampSchemeVerifier;
14
+ //# sourceMappingURL=timestampSchemeVerifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timestampSchemeVerifier.d.ts","sourceRoot":"","sources":["../../../../src/auth/verifiers/timestampSchemeVerifier.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEjE,MAAM,WAAW,uBAAwB,SAAQ,eAAe;IAC9D,IAAI,EAAE,yBAAyB,CAAA;CAChC;AAwHD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,CAAC,EAAE,aAAa,GACtB,uBAAuB,CAczB;AAED,eAAe,uBAAuB,CAAA"}