@redmix/api 0.0.1
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/LICENSE +21 -0
- package/README.md +51 -0
- package/dist/auth/index.d.ts +51 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +129 -0
- package/dist/auth/parseJWT.d.ts +6 -0
- package/dist/auth/parseJWT.d.ts.map +1 -0
- package/dist/auth/parseJWT.js +57 -0
- package/dist/auth/verifiers/base64Sha1Verifier.d.ts +19 -0
- package/dist/auth/verifiers/base64Sha1Verifier.d.ts.map +1 -0
- package/dist/auth/verifiers/base64Sha1Verifier.js +77 -0
- package/dist/auth/verifiers/base64Sha256Verifier.d.ts +19 -0
- package/dist/auth/verifiers/base64Sha256Verifier.d.ts.map +1 -0
- package/dist/auth/verifiers/base64Sha256Verifier.js +77 -0
- package/dist/auth/verifiers/common.d.ts +104 -0
- package/dist/auth/verifiers/common.d.ts.map +1 -0
- package/dist/auth/verifiers/common.js +99 -0
- package/dist/auth/verifiers/index.d.ts +8 -0
- package/dist/auth/verifiers/index.d.ts.map +1 -0
- package/dist/auth/verifiers/index.js +38 -0
- package/dist/auth/verifiers/jwtVerifier.d.ts +26 -0
- package/dist/auth/verifiers/jwtVerifier.d.ts.map +1 -0
- package/dist/auth/verifiers/jwtVerifier.js +86 -0
- package/dist/auth/verifiers/secretKeyVerifier.d.ts +14 -0
- package/dist/auth/verifiers/secretKeyVerifier.d.ts.map +1 -0
- package/dist/auth/verifiers/secretKeyVerifier.js +40 -0
- package/dist/auth/verifiers/sha1Verifier.d.ts +25 -0
- package/dist/auth/verifiers/sha1Verifier.d.ts.map +1 -0
- package/dist/auth/verifiers/sha1Verifier.js +85 -0
- package/dist/auth/verifiers/sha256Verifier.d.ts +25 -0
- package/dist/auth/verifiers/sha256Verifier.d.ts.map +1 -0
- package/dist/auth/verifiers/sha256Verifier.js +85 -0
- package/dist/auth/verifiers/skipVerifier.d.ts +13 -0
- package/dist/auth/verifiers/skipVerifier.d.ts.map +1 -0
- package/dist/auth/verifiers/skipVerifier.js +37 -0
- package/dist/auth/verifiers/timestampSchemeVerifier.d.ts +16 -0
- package/dist/auth/verifiers/timestampSchemeVerifier.d.ts.map +1 -0
- package/dist/auth/verifiers/timestampSchemeVerifier.js +81 -0
- package/dist/bins/redwood.d.ts +3 -0
- package/dist/bins/redwood.d.ts.map +1 -0
- package/dist/bins/redwood.js +33 -0
- package/dist/bins/rwfw.d.ts +3 -0
- package/dist/bins/rwfw.d.ts.map +1 -0
- package/dist/bins/rwfw.js +33 -0
- package/dist/bins/tsc.d.ts +3 -0
- package/dist/bins/tsc.d.ts.map +1 -0
- package/dist/bins/tsc.js +30 -0
- package/dist/cache/clients/BaseClient.d.ts +11 -0
- package/dist/cache/clients/BaseClient.d.ts.map +1 -0
- package/dist/cache/clients/BaseClient.js +27 -0
- package/dist/cache/clients/InMemoryClient.d.ts +31 -0
- package/dist/cache/clients/InMemoryClient.d.ts.map +1 -0
- package/dist/cache/clients/InMemoryClient.js +100 -0
- package/dist/cache/clients/MemcachedClient.d.ts +16 -0
- package/dist/cache/clients/MemcachedClient.d.ts.map +1 -0
- package/dist/cache/clients/MemcachedClient.js +75 -0
- package/dist/cache/clients/RedisClient.d.ts +20 -0
- package/dist/cache/clients/RedisClient.d.ts.map +1 -0
- package/dist/cache/clients/RedisClient.js +79 -0
- package/dist/cache/errors.d.ts +4 -0
- package/dist/cache/errors.d.ts.map +1 -0
- package/dist/cache/errors.js +33 -0
- package/dist/cache/index.d.ts +35 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +171 -0
- package/dist/cors.d.ts +16 -0
- package/dist/cors.d.ts.map +1 -0
- package/dist/cors.js +93 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +38 -0
- package/dist/event.d.ts +3 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +34 -0
- package/dist/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts +4 -0
- package/dist/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts.map +1 -0
- package/dist/functions/fixtures/apiGatewayProxyEvent.fixture.js +72 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/logger/index.d.ts +179 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +195 -0
- package/dist/transforms.d.ts +35 -0
- package/dist/transforms.d.ts.map +1 -0
- package/dist/transforms.js +98 -0
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +16 -0
- package/dist/validations/errors.d.ts +101 -0
- package/dist/validations/errors.d.ts.map +1 -0
- package/dist/validations/errors.js +298 -0
- package/dist/validations/validations.d.ts +222 -0
- package/dist/validations/validations.d.ts.map +1 -0
- package/dist/validations/validations.js +351 -0
- package/dist/webhooks/index.d.ts +76 -0
- package/dist/webhooks/index.d.ts.map +1 -0
- package/dist/webhooks/index.js +107 -0
- package/package.json +95 -0
@@ -0,0 +1,99 @@
|
|
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 common_exports = {};
|
30
|
+
__export(common_exports, {
|
31
|
+
DEFAULT_TOLERANCE: () => DEFAULT_TOLERANCE,
|
32
|
+
DEFAULT_WEBHOOK_SECRET: () => DEFAULT_WEBHOOK_SECRET,
|
33
|
+
VERIFICATION_ERROR_MESSAGE: () => VERIFICATION_ERROR_MESSAGE,
|
34
|
+
VERIFICATION_SIGN_MESSAGE: () => VERIFICATION_SIGN_MESSAGE,
|
35
|
+
WebhookSignError: () => WebhookSignError,
|
36
|
+
WebhookVerificationError: () => WebhookVerificationError,
|
37
|
+
verifierLookup: () => verifierLookup
|
38
|
+
});
|
39
|
+
module.exports = __toCommonJS(common_exports);
|
40
|
+
var import_base64Sha1Verifier = __toESM(require("./base64Sha1Verifier"));
|
41
|
+
var import_base64Sha256Verifier = __toESM(require("./base64Sha256Verifier"));
|
42
|
+
var import_jwtVerifier = __toESM(require("./jwtVerifier"));
|
43
|
+
var import_secretKeyVerifier = __toESM(require("./secretKeyVerifier"));
|
44
|
+
var import_sha1Verifier = __toESM(require("./sha1Verifier"));
|
45
|
+
var import_sha256Verifier = __toESM(require("./sha256Verifier"));
|
46
|
+
var import_skipVerifier = __toESM(require("./skipVerifier"));
|
47
|
+
var import_timestampSchemeVerifier = __toESM(require("./timestampSchemeVerifier"));
|
48
|
+
const verifierLookup = {
|
49
|
+
skipVerifier: import_skipVerifier.default,
|
50
|
+
secretKeyVerifier: import_secretKeyVerifier.default,
|
51
|
+
sha1Verifier: import_sha1Verifier.default,
|
52
|
+
sha256Verifier: import_sha256Verifier.default,
|
53
|
+
base64Sha1Verifier: import_base64Sha1Verifier.default,
|
54
|
+
base64Sha256Verifier: import_base64Sha256Verifier.default,
|
55
|
+
timestampSchemeVerifier: import_timestampSchemeVerifier.default,
|
56
|
+
jwtVerifier: import_jwtVerifier.default
|
57
|
+
};
|
58
|
+
const DEFAULT_WEBHOOK_SECRET = process.env.WEBHOOK_SECRET ?? "";
|
59
|
+
const VERIFICATION_ERROR_MESSAGE = "You don't have access to invoke this function.";
|
60
|
+
const VERIFICATION_SIGN_MESSAGE = "Unable to sign payload";
|
61
|
+
const FIVE_MINUTES = 5 * 6e4;
|
62
|
+
const DEFAULT_TOLERANCE = FIVE_MINUTES;
|
63
|
+
class WebhookError extends Error {
|
64
|
+
/**
|
65
|
+
* Create a WebhookError.
|
66
|
+
* @param {string} message - The error message
|
67
|
+
* */
|
68
|
+
constructor(message) {
|
69
|
+
super(message);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
class WebhookVerificationError extends WebhookError {
|
73
|
+
/**
|
74
|
+
* Create a WebhookVerificationError.
|
75
|
+
* @param {string} message - The error message
|
76
|
+
* */
|
77
|
+
constructor(message) {
|
78
|
+
super(message || VERIFICATION_ERROR_MESSAGE);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
class WebhookSignError extends WebhookError {
|
82
|
+
/**
|
83
|
+
* Create a WebhookSignError.
|
84
|
+
* @param {string} message - The error message
|
85
|
+
* */
|
86
|
+
constructor(message) {
|
87
|
+
super(message || VERIFICATION_SIGN_MESSAGE);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
91
|
+
0 && (module.exports = {
|
92
|
+
DEFAULT_TOLERANCE,
|
93
|
+
DEFAULT_WEBHOOK_SECRET,
|
94
|
+
VERIFICATION_ERROR_MESSAGE,
|
95
|
+
VERIFICATION_SIGN_MESSAGE,
|
96
|
+
WebhookSignError,
|
97
|
+
WebhookVerificationError,
|
98
|
+
verifierLookup
|
99
|
+
});
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { SupportedVerifierTypes, VerifyOptions, WebhookVerifier } from './common';
|
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';
|
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,UAAU,CAAA;AAEjB;;;GAGG;AACH,eAAO,MAAM,cAAc,SACnB,sBAAsB,YAClB,aAAa,KACtB,eAMF,CAAA;AAED,cAAc,UAAU,CAAA"}
|
@@ -0,0 +1,38 @@
|
|
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");
|
26
|
+
__reExport(verifiers_exports, require("./common"), module.exports);
|
27
|
+
const createVerifier = (type, options) => {
|
28
|
+
if (options) {
|
29
|
+
return import_common.verifierLookup[type](options);
|
30
|
+
} else {
|
31
|
+
return import_common.verifierLookup[type]();
|
32
|
+
}
|
33
|
+
};
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
35
|
+
0 && (module.exports = {
|
36
|
+
createVerifier,
|
37
|
+
...require("./common")
|
38
|
+
});
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import type { WebhookVerifier, VerifyOptions } from './common';
|
2
|
+
export interface JwtVerifier extends WebhookVerifier {
|
3
|
+
type: 'jwtVerifier';
|
4
|
+
}
|
5
|
+
/**
|
6
|
+
*
|
7
|
+
* verifySignature
|
8
|
+
*
|
9
|
+
*/
|
10
|
+
export declare const verifySignature: ({ payload, secret, signature, options, }: {
|
11
|
+
payload: string | Record<string, unknown>;
|
12
|
+
secret: string;
|
13
|
+
signature: string;
|
14
|
+
options: VerifyOptions | undefined;
|
15
|
+
}) => boolean;
|
16
|
+
/**
|
17
|
+
*
|
18
|
+
* JWT Payload Verifier
|
19
|
+
*
|
20
|
+
* Based on Netlify's webhook payload verification
|
21
|
+
* @see: https://docs.netlify.com/site-deploys/notifications/#payload-signature
|
22
|
+
*
|
23
|
+
*/
|
24
|
+
export declare const jwtVerifier: (options?: VerifyOptions) => JwtVerifier;
|
25
|
+
export default jwtVerifier;
|
26
|
+
//# 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,UAAU,CAAA;AAE9D,MAAM,WAAW,WAAY,SAAQ,eAAe;IAClD,IAAI,EAAE,aAAa,CAAA;CACpB;AA2BD;;;;GAIG;AACH,eAAO,MAAM,eAAe,6CAKzB;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;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,aAAc,aAAa,KAAG,WAUrD,CAAA;AAED,eAAe,WAAW,CAAA"}
|
@@ -0,0 +1,86 @@
|
|
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
|
+
default: () => jwtVerifier_default,
|
32
|
+
jwtVerifier: () => jwtVerifier,
|
33
|
+
verifySignature: () => verifySignature
|
34
|
+
});
|
35
|
+
module.exports = __toCommonJS(jwtVerifier_exports);
|
36
|
+
var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
|
37
|
+
var import_common = require("./common");
|
38
|
+
const createSignature = ({
|
39
|
+
payload,
|
40
|
+
secret = import_common.DEFAULT_WEBHOOK_SECRET,
|
41
|
+
options
|
42
|
+
}) => {
|
43
|
+
try {
|
44
|
+
const signOptions = options?.issuer ? { issuer: options?.issuer } : void 0;
|
45
|
+
return import_jsonwebtoken.default.sign(payload, secret, { ...signOptions });
|
46
|
+
} catch (error) {
|
47
|
+
throw new import_common.WebhookSignError(error.message);
|
48
|
+
}
|
49
|
+
};
|
50
|
+
const verifySignature = ({
|
51
|
+
payload,
|
52
|
+
secret = import_common.DEFAULT_WEBHOOK_SECRET,
|
53
|
+
signature,
|
54
|
+
options
|
55
|
+
}) => {
|
56
|
+
try {
|
57
|
+
if (payload === void 0 || payload?.length === 0) {
|
58
|
+
console.warn("Missing payload");
|
59
|
+
}
|
60
|
+
if (options?.issuer) {
|
61
|
+
import_jsonwebtoken.default.verify(signature, secret, { issuer: options?.issuer });
|
62
|
+
} else {
|
63
|
+
import_jsonwebtoken.default.verify(signature, secret);
|
64
|
+
}
|
65
|
+
return true;
|
66
|
+
} catch {
|
67
|
+
throw new import_common.WebhookVerificationError();
|
68
|
+
}
|
69
|
+
};
|
70
|
+
const jwtVerifier = (options) => {
|
71
|
+
return {
|
72
|
+
sign: ({ payload, secret }) => {
|
73
|
+
return createSignature({ payload, secret, options });
|
74
|
+
},
|
75
|
+
verify: ({ payload, secret, signature }) => {
|
76
|
+
return verifySignature({ payload, secret, signature, options });
|
77
|
+
},
|
78
|
+
type: "jwtVerifier"
|
79
|
+
};
|
80
|
+
};
|
81
|
+
var jwtVerifier_default = jwtVerifier;
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
83
|
+
0 && (module.exports = {
|
84
|
+
jwtVerifier,
|
85
|
+
verifySignature
|
86
|
+
});
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { WebhookVerifier, VerifyOptions } from './common';
|
2
|
+
export interface SecretKeyVerifier extends WebhookVerifier {
|
3
|
+
type: 'secretKeyVerifier';
|
4
|
+
}
|
5
|
+
/**
|
6
|
+
*
|
7
|
+
* Secret Key Verifier
|
8
|
+
*
|
9
|
+
* Use when the payload is not signed, but rather authorized via a known secret key
|
10
|
+
*
|
11
|
+
*/
|
12
|
+
declare const secretKeyVerifier: (_options?: VerifyOptions) => SecretKeyVerifier;
|
13
|
+
export default secretKeyVerifier;
|
14
|
+
//# 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,UAAU,CAAA;AAE9D,MAAM,WAAW,iBAAkB,SAAQ,eAAe;IACxD,IAAI,EAAE,mBAAmB,CAAA;CAC1B;AAED;;;;;;GAMG;AACH,QAAA,MAAM,iBAAiB,cAAe,aAAa,KAAG,iBAgBrD,CAAA;AAED,eAAe,iBAAiB,CAAA"}
|
@@ -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 secretKeyVerifier_exports = {};
|
20
|
+
__export(secretKeyVerifier_exports, {
|
21
|
+
default: () => secretKeyVerifier_default
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(secretKeyVerifier_exports);
|
24
|
+
var import_common = require("./common");
|
25
|
+
const 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
|
+
var secretKeyVerifier_default = secretKeyVerifier;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import type { WebhookVerifier, VerifyOptions } from './common';
|
2
|
+
export interface Sha1Verifier extends WebhookVerifier {
|
3
|
+
type: 'sha1Verifier';
|
4
|
+
}
|
5
|
+
/**
|
6
|
+
*
|
7
|
+
* verifySignature
|
8
|
+
*
|
9
|
+
*/
|
10
|
+
export declare const verifySignature: ({ payload, secret, signature, }: {
|
11
|
+
payload: string | Record<string, unknown>;
|
12
|
+
secret: string;
|
13
|
+
signature: string;
|
14
|
+
}) => boolean;
|
15
|
+
/**
|
16
|
+
*
|
17
|
+
* SHA1 HMAC Payload Verifier
|
18
|
+
*
|
19
|
+
* Based on Vercel's webhook payload verification
|
20
|
+
* @see https://vercel.com/docs/api#integrations/webhooks/securing-webhooks
|
21
|
+
*
|
22
|
+
*/
|
23
|
+
declare const sha1Verifier: (_options?: VerifyOptions) => Sha1Verifier;
|
24
|
+
export default sha1Verifier;
|
25
|
+
//# 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,UAAU,CAAA;AAE9D,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD,IAAI,EAAE,cAAc,CAAA;CACrB;AAkCD;;;;GAIG;AACH,eAAO,MAAM,eAAe,oCAIzB;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;;;;;;;GAOG;AACH,QAAA,MAAM,YAAY,cAAe,aAAa,KAAG,YAUhD,CAAA;AAED,eAAe,YAAY,CAAA"}
|
@@ -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
|
+
default: () => sha1Verifier_default,
|
22
|
+
verifySignature: () => verifySignature
|
23
|
+
});
|
24
|
+
module.exports = __toCommonJS(sha1Verifier_exports);
|
25
|
+
var import_crypto = require("crypto");
|
26
|
+
var import_common = require("./common");
|
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
|
+
const 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
|
+
var sha1Verifier_default = sha1Verifier;
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
83
|
+
0 && (module.exports = {
|
84
|
+
verifySignature
|
85
|
+
});
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import type { WebhookVerifier, VerifyOptions } from './common';
|
2
|
+
export interface Sha256Verifier extends WebhookVerifier {
|
3
|
+
type: 'sha256Verifier';
|
4
|
+
}
|
5
|
+
/**
|
6
|
+
*
|
7
|
+
* verifySignature
|
8
|
+
*
|
9
|
+
*/
|
10
|
+
export declare const verifySignature: ({ payload, secret, signature, }: {
|
11
|
+
payload: string | Record<string, unknown>;
|
12
|
+
secret: string;
|
13
|
+
signature: string;
|
14
|
+
}) => boolean;
|
15
|
+
/**
|
16
|
+
*
|
17
|
+
* SHA256 HMAC Payload Verifier
|
18
|
+
*
|
19
|
+
* Based on GitHub's webhook payload verification
|
20
|
+
* @see https://docs.github.com/en/developers/webhooks-and-events/securing-your-webhooks
|
21
|
+
*
|
22
|
+
*/
|
23
|
+
declare const sha256Verifier: (_options?: VerifyOptions) => Sha256Verifier;
|
24
|
+
export default sha256Verifier;
|
25
|
+
//# 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,UAAU,CAAA;AAE9D,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD,IAAI,EAAE,gBAAgB,CAAA;CACvB;AAkCD;;;;GAIG;AACH,eAAO,MAAM,eAAe,oCAIzB;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;;;;;;;GAOG;AACH,QAAA,MAAM,cAAc,cAAe,aAAa,KAAG,cAUlD,CAAA;AAED,eAAe,cAAc,CAAA"}
|
@@ -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
|
+
default: () => sha256Verifier_default,
|
22
|
+
verifySignature: () => verifySignature
|
23
|
+
});
|
24
|
+
module.exports = __toCommonJS(sha256Verifier_exports);
|
25
|
+
var import_crypto = require("crypto");
|
26
|
+
var import_common = require("./common");
|
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
|
+
const 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
|
+
var sha256Verifier_default = sha256Verifier;
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
83
|
+
0 && (module.exports = {
|
84
|
+
verifySignature
|
85
|
+
});
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import type { VerifyOptions, WebhookVerifier } from './common';
|
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
|
+
*/
|
11
|
+
declare const skipVerifier: (_options?: VerifyOptions) => SkipVerifier;
|
12
|
+
export default skipVerifier;
|
13
|
+
//# 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,UAAU,CAAA;AAE9D,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD,IAAI,EAAE,cAAc,CAAA;CACrB;AACD;;;;;GAKG;AACH,QAAA,MAAM,YAAY,cAAe,aAAa,KAAG,YAYhD,CAAA;AAED,eAAe,YAAY,CAAA"}
|
@@ -0,0 +1,37 @@
|
|
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
|
+
default: () => skipVerifier_default
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(skipVerifier_exports);
|
24
|
+
const 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
|
+
var skipVerifier_default = skipVerifier;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { WebhookVerifier, VerifyOptions } from './common';
|
2
|
+
export interface TimestampSchemeVerifier extends WebhookVerifier {
|
3
|
+
type: 'timestampSchemeVerifier';
|
4
|
+
}
|
5
|
+
/**
|
6
|
+
*
|
7
|
+
* Timestamp & Scheme Verifier
|
8
|
+
*
|
9
|
+
* Based on Stripe's secure webhook implementation
|
10
|
+
*
|
11
|
+
* @see https://stripe.com/docs/webhooks/signatures
|
12
|
+
*
|
13
|
+
*/
|
14
|
+
declare const timestampSchemeVerifier: (options?: VerifyOptions) => TimestampSchemeVerifier;
|
15
|
+
export default timestampSchemeVerifier;
|
16
|
+
//# 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,UAAU,CAAA;AAE9D,MAAM,WAAW,uBAAwB,SAAQ,eAAe;IAC9D,IAAI,EAAE,yBAAyB,CAAA;CAChC;AAwHD;;;;;;;;GAQG;AACH,QAAA,MAAM,uBAAuB,aACjB,aAAa,KACtB,uBAcF,CAAA;AAED,eAAe,uBAAuB,CAAA"}
|