@redmix/api 9.0.0-canary.581 → 9.0.0-canary.582
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/auth/index.js +10 -49
- package/dist/auth/parseJWT.js +3 -26
- package/dist/auth/verifiers/base64Sha1Verifier.js +18 -37
- package/dist/auth/verifiers/base64Sha256Verifier.js +18 -37
- package/dist/auth/verifiers/common.js +19 -58
- package/dist/auth/verifiers/index.js +8 -33
- package/dist/auth/verifiers/jwtVerifier.js +17 -47
- package/dist/auth/verifiers/secretKeyVerifier.js +7 -26
- package/dist/auth/verifiers/sha1Verifier.js +18 -37
- package/dist/auth/verifiers/sha256Verifier.js +18 -37
- package/dist/auth/verifiers/skipVerifier.js +4 -23
- package/dist/auth/verifiers/timestampSchemeVerifier.js +18 -33
- package/dist/cache/clients/BaseClient.js +4 -23
- package/dist/cache/clients/InMemoryClient.js +6 -35
- package/dist/cache/clients/MemcachedClient.js +6 -35
- package/dist/cache/clients/RedisClient.js +6 -35
- package/dist/cache/errors.js +3 -26
- package/dist/cache/index.js +14 -52
- package/dist/cjs/auth/index.d.ts +51 -0
- package/dist/cjs/auth/index.d.ts.map +1 -0
- package/dist/cjs/auth/index.js +129 -0
- package/dist/cjs/auth/parseJWT.d.ts +6 -0
- package/dist/cjs/auth/parseJWT.d.ts.map +1 -0
- package/dist/cjs/auth/parseJWT.js +57 -0
- package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts +19 -0
- package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/base64Sha1Verifier.js +77 -0
- package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts +19 -0
- package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/base64Sha256Verifier.js +77 -0
- package/dist/cjs/auth/verifiers/common.d.ts +104 -0
- package/dist/cjs/auth/verifiers/common.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/common.js +99 -0
- package/dist/cjs/auth/verifiers/index.d.ts +8 -0
- package/dist/cjs/auth/verifiers/index.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/index.js +38 -0
- package/dist/cjs/auth/verifiers/jwtVerifier.d.ts +26 -0
- package/dist/cjs/auth/verifiers/jwtVerifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/jwtVerifier.js +86 -0
- package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts +14 -0
- package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/secretKeyVerifier.js +40 -0
- package/dist/cjs/auth/verifiers/sha1Verifier.d.ts +25 -0
- package/dist/cjs/auth/verifiers/sha1Verifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/sha1Verifier.js +85 -0
- package/dist/cjs/auth/verifiers/sha256Verifier.d.ts +25 -0
- package/dist/cjs/auth/verifiers/sha256Verifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/sha256Verifier.js +85 -0
- package/dist/cjs/auth/verifiers/skipVerifier.d.ts +13 -0
- package/dist/cjs/auth/verifiers/skipVerifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/skipVerifier.js +37 -0
- package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts +16 -0
- package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts.map +1 -0
- package/dist/cjs/auth/verifiers/timestampSchemeVerifier.js +81 -0
- package/dist/cjs/bins/redwood.d.ts +9 -0
- package/dist/cjs/bins/redwood.d.ts.map +1 -0
- package/dist/cjs/bins/rwfw.d.ts +3 -0
- package/dist/cjs/bins/rwfw.d.ts.map +1 -0
- package/dist/cjs/bins/tsc.d.ts +3 -0
- package/dist/cjs/bins/tsc.d.ts.map +1 -0
- package/dist/{bins → cjs/bins}/tsc.js +2 -2
- package/dist/cjs/cache/clients/BaseClient.d.ts +11 -0
- package/dist/cjs/cache/clients/BaseClient.d.ts.map +1 -0
- package/dist/cjs/cache/clients/BaseClient.js +27 -0
- package/dist/cjs/cache/clients/InMemoryClient.d.ts +31 -0
- package/dist/cjs/cache/clients/InMemoryClient.d.ts.map +1 -0
- package/dist/cjs/cache/clients/InMemoryClient.js +100 -0
- package/dist/cjs/cache/clients/MemcachedClient.d.ts +16 -0
- package/dist/cjs/cache/clients/MemcachedClient.d.ts.map +1 -0
- package/dist/cjs/cache/clients/MemcachedClient.js +75 -0
- package/dist/cjs/cache/clients/RedisClient.d.ts +20 -0
- package/dist/cjs/cache/clients/RedisClient.d.ts.map +1 -0
- package/dist/cjs/cache/clients/RedisClient.js +79 -0
- package/dist/cjs/cache/errors.d.ts +4 -0
- package/dist/cjs/cache/errors.d.ts.map +1 -0
- package/dist/cjs/cache/errors.js +33 -0
- package/dist/cjs/cache/index.d.ts +35 -0
- package/dist/cjs/cache/index.d.ts.map +1 -0
- package/dist/cjs/cache/index.js +171 -0
- package/dist/cjs/cors.d.ts +16 -0
- package/dist/cjs/cors.d.ts.map +1 -0
- package/dist/cjs/cors.js +93 -0
- package/dist/cjs/errors.d.ts +5 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +38 -0
- package/dist/cjs/event.d.ts +3 -0
- package/dist/cjs/event.d.ts.map +1 -0
- package/dist/cjs/event.js +34 -0
- package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts +4 -0
- package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts.map +1 -0
- package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.js +72 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +63 -0
- package/dist/cjs/logger/index.d.ts +179 -0
- package/dist/cjs/logger/index.d.ts.map +1 -0
- package/dist/cjs/logger/index.js +195 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/transforms.d.ts +35 -0
- package/dist/cjs/transforms.d.ts.map +1 -0
- package/dist/cjs/transforms.js +98 -0
- package/dist/cjs/types.d.ts +25 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +16 -0
- package/dist/cjs/validations/errors.d.ts +101 -0
- package/dist/cjs/validations/errors.d.ts.map +1 -0
- package/dist/cjs/validations/errors.js +298 -0
- package/dist/cjs/validations/validations.d.ts +222 -0
- package/dist/cjs/validations/validations.d.ts.map +1 -0
- package/dist/cjs/validations/validations.js +351 -0
- package/dist/cjs/webhooks/index.d.ts +76 -0
- package/dist/cjs/webhooks/index.d.ts.map +1 -0
- package/dist/cjs/webhooks/index.js +107 -0
- package/dist/cors.js +7 -30
- package/dist/errors.js +3 -26
- package/dist/event.js +5 -28
- package/dist/functions/fixtures/apiGatewayProxyEvent.fixture.js +4 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -46
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/logger/index.js +6 -48
- package/dist/package.json +1 -0
- package/dist/transforms.js +6 -33
- package/dist/types.js +1 -16
- package/dist/validations/errors.js +8 -66
- package/dist/validations/validations.js +8 -44
- package/dist/webhooks/index.js +25 -46
- package/package.json +53 -18
- /package/dist/{bins → cjs/bins}/redwood.js +0 -0
- /package/dist/{bins → cjs/bins}/rwfw.js +0 -0
package/dist/auth/index.js
CHANGED
@@ -1,56 +1,19 @@
|
|
1
|
-
"
|
2
|
-
|
3
|
-
|
4
|
-
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
27
|
-
mod
|
28
|
-
));
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
30
|
-
var auth_exports = {};
|
31
|
-
__export(auth_exports, {
|
32
|
-
AUTH_PROVIDER_HEADER: () => AUTH_PROVIDER_HEADER,
|
33
|
-
getAuthProviderHeader: () => getAuthProviderHeader,
|
34
|
-
getAuthenticationContext: () => getAuthenticationContext,
|
35
|
-
parseAuthorizationCookie: () => parseAuthorizationCookie,
|
36
|
-
parseAuthorizationHeader: () => parseAuthorizationHeader
|
37
|
-
});
|
38
|
-
module.exports = __toCommonJS(auth_exports);
|
39
|
-
__reExport(auth_exports, require("./parseJWT.js"), module.exports);
|
40
|
-
var cookie = __toESM(require("cookie"));
|
41
|
-
var import_event = require("../event.js");
|
1
|
+
import bannerPath from "node:path"; import bannerUrl from "node:url"; const __filename = bannerUrl.fileURLToPath(import.meta.url); const __dirname = bannerPath.dirname(__filename);
|
2
|
+
export * from "./parseJWT.js";
|
3
|
+
import * as cookie from "cookie";
|
4
|
+
import { getEventHeader } from "../event.js";
|
42
5
|
const AUTH_PROVIDER_HEADER = "auth-provider";
|
43
6
|
const getAuthProviderHeader = (event) => {
|
44
7
|
const authProviderKey = Object.keys(event?.headers ?? {}).find(
|
45
8
|
(key) => key.toLowerCase() === AUTH_PROVIDER_HEADER
|
46
9
|
);
|
47
10
|
if (authProviderKey) {
|
48
|
-
return
|
11
|
+
return getEventHeader(event, authProviderKey);
|
49
12
|
}
|
50
13
|
return void 0;
|
51
14
|
};
|
52
15
|
const parseAuthorizationCookie = (event) => {
|
53
|
-
const cookieHeader =
|
16
|
+
const cookieHeader = getEventHeader(event, "Cookie");
|
54
17
|
if (!cookieHeader) {
|
55
18
|
return null;
|
56
19
|
}
|
@@ -64,7 +27,7 @@ const parseAuthorizationCookie = (event) => {
|
|
64
27
|
};
|
65
28
|
};
|
66
29
|
const parseAuthorizationHeader = (event) => {
|
67
|
-
const parts =
|
30
|
+
const parts = getEventHeader(event, "Authorization")?.split(" ");
|
68
31
|
if (parts?.length !== 2) {
|
69
32
|
throw new Error("The `Authorization` header is not valid.");
|
70
33
|
}
|
@@ -118,12 +81,10 @@ const getAuthenticationContext = async ({
|
|
118
81
|
}
|
119
82
|
return [decoded, { type, schema, token }, { event, context }];
|
120
83
|
};
|
121
|
-
|
122
|
-
0 && (module.exports = {
|
84
|
+
export {
|
123
85
|
AUTH_PROVIDER_HEADER,
|
124
86
|
getAuthProviderHeader,
|
125
87
|
getAuthenticationContext,
|
126
88
|
parseAuthorizationCookie,
|
127
|
-
parseAuthorizationHeader
|
128
|
-
|
129
|
-
});
|
89
|
+
parseAuthorizationHeader
|
90
|
+
};
|
package/dist/auth/parseJWT.js
CHANGED
@@ -1,26 +1,4 @@
|
|
1
|
-
"
|
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 parseJWT_exports = {};
|
20
|
-
__export(parseJWT_exports, {
|
21
|
-
parseJWT: () => parseJWT
|
22
|
-
});
|
23
|
-
module.exports = __toCommonJS(parseJWT_exports);
|
1
|
+
import bannerPath from "node:path"; import bannerUrl from "node:url"; const __filename = bannerUrl.fileURLToPath(import.meta.url); const __dirname = bannerPath.dirname(__filename);
|
24
2
|
function isTokenWithRoles(token) {
|
25
3
|
return !!token.decoded?.roles;
|
26
4
|
}
|
@@ -51,7 +29,6 @@ const parseJWT = (token) => {
|
|
51
29
|
roles: roles(token)
|
52
30
|
};
|
53
31
|
};
|
54
|
-
|
55
|
-
0 && (module.exports = {
|
32
|
+
export {
|
56
33
|
parseJWT
|
57
|
-
}
|
34
|
+
};
|
@@ -1,29 +1,10 @@
|
|
1
|
-
"
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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 base64Sha1Verifier_exports = {};
|
20
|
-
__export(base64Sha1Verifier_exports, {
|
21
|
-
default: () => base64Sha1Verifier_default,
|
22
|
-
verifySignature: () => verifySignature
|
23
|
-
});
|
24
|
-
module.exports = __toCommonJS(base64Sha1Verifier_exports);
|
25
|
-
var import_crypto = require("crypto");
|
26
|
-
var import_common = require("./common.js");
|
1
|
+
import bannerPath from "node:path"; import bannerUrl from "node:url"; const __filename = bannerUrl.fileURLToPath(import.meta.url); const __dirname = bannerPath.dirname(__filename);
|
2
|
+
import { createHmac, timingSafeEqual } from "crypto";
|
3
|
+
import {
|
4
|
+
WebhookVerificationError,
|
5
|
+
VERIFICATION_ERROR_MESSAGE,
|
6
|
+
DEFAULT_WEBHOOK_SECRET
|
7
|
+
} from "./common.js";
|
27
8
|
function toNormalizedJsonString(payload) {
|
28
9
|
return JSON.stringify(payload).replace(/[^\\]\\u[\da-f]{4}/g, (s) => {
|
29
10
|
return s.slice(0, 3) + s.slice(3).toUpperCase();
|
@@ -31,31 +12,31 @@ function toNormalizedJsonString(payload) {
|
|
31
12
|
}
|
32
13
|
const createSignature = ({
|
33
14
|
payload,
|
34
|
-
secret =
|
15
|
+
secret = DEFAULT_WEBHOOK_SECRET
|
35
16
|
}) => {
|
36
17
|
const algorithm = "sha1";
|
37
|
-
const hmac =
|
18
|
+
const hmac = createHmac(algorithm, Buffer.from(secret, "base64"));
|
38
19
|
payload = typeof payload === "string" ? payload : toNormalizedJsonString(payload);
|
39
20
|
const digest = hmac.update(payload).digest();
|
40
21
|
return digest.toString("base64");
|
41
22
|
};
|
42
23
|
const verifySignature = ({
|
43
24
|
payload,
|
44
|
-
secret =
|
25
|
+
secret = DEFAULT_WEBHOOK_SECRET,
|
45
26
|
signature
|
46
27
|
}) => {
|
47
28
|
try {
|
48
29
|
const webhookSignature = Buffer.from(signature || "", "base64");
|
49
|
-
const hmac =
|
30
|
+
const hmac = createHmac("sha1", Buffer.from(secret, "base64"));
|
50
31
|
payload = typeof payload === "string" ? payload : toNormalizedJsonString(payload);
|
51
32
|
const digest = hmac.update(payload).digest();
|
52
|
-
if (webhookSignature.length === digest.length &&
|
33
|
+
if (webhookSignature.length === digest.length && timingSafeEqual(digest, webhookSignature)) {
|
53
34
|
return true;
|
54
35
|
}
|
55
|
-
throw new
|
36
|
+
throw new WebhookVerificationError();
|
56
37
|
} catch (error) {
|
57
|
-
throw new
|
58
|
-
`${
|
38
|
+
throw new WebhookVerificationError(
|
39
|
+
`${VERIFICATION_ERROR_MESSAGE}: ${error.message}`
|
59
40
|
);
|
60
41
|
}
|
61
42
|
};
|
@@ -71,7 +52,7 @@ const base64Sha1Verifier = (_options) => {
|
|
71
52
|
};
|
72
53
|
};
|
73
54
|
var base64Sha1Verifier_default = base64Sha1Verifier;
|
74
|
-
|
75
|
-
|
55
|
+
export {
|
56
|
+
base64Sha1Verifier_default as default,
|
76
57
|
verifySignature
|
77
|
-
}
|
58
|
+
};
|
@@ -1,29 +1,10 @@
|
|
1
|
-
"
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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 base64Sha256Verifier_exports = {};
|
20
|
-
__export(base64Sha256Verifier_exports, {
|
21
|
-
default: () => base64Sha256Verifier_default,
|
22
|
-
verifySignature: () => verifySignature
|
23
|
-
});
|
24
|
-
module.exports = __toCommonJS(base64Sha256Verifier_exports);
|
25
|
-
var import_crypto = require("crypto");
|
26
|
-
var import_common = require("./common.js");
|
1
|
+
import bannerPath from "node:path"; import bannerUrl from "node:url"; const __filename = bannerUrl.fileURLToPath(import.meta.url); const __dirname = bannerPath.dirname(__filename);
|
2
|
+
import { createHmac, timingSafeEqual } from "crypto";
|
3
|
+
import {
|
4
|
+
WebhookVerificationError,
|
5
|
+
VERIFICATION_ERROR_MESSAGE,
|
6
|
+
DEFAULT_WEBHOOK_SECRET
|
7
|
+
} from "./common.js";
|
27
8
|
function toNormalizedJsonString(payload) {
|
28
9
|
return JSON.stringify(payload).replace(/[^\\]\\u[\da-f]{4}/g, (s) => {
|
29
10
|
return s.slice(0, 3) + s.slice(3).toUpperCase();
|
@@ -31,31 +12,31 @@ function toNormalizedJsonString(payload) {
|
|
31
12
|
}
|
32
13
|
const createSignature = ({
|
33
14
|
payload,
|
34
|
-
secret =
|
15
|
+
secret = DEFAULT_WEBHOOK_SECRET
|
35
16
|
}) => {
|
36
17
|
const algorithm = "sha256";
|
37
|
-
const hmac =
|
18
|
+
const hmac = createHmac(algorithm, Buffer.from(secret, "base64"));
|
38
19
|
payload = typeof payload === "string" ? payload : toNormalizedJsonString(payload);
|
39
20
|
const digest = hmac.update(payload).digest();
|
40
21
|
return digest.toString("base64");
|
41
22
|
};
|
42
23
|
const verifySignature = ({
|
43
24
|
payload,
|
44
|
-
secret =
|
25
|
+
secret = DEFAULT_WEBHOOK_SECRET,
|
45
26
|
signature
|
46
27
|
}) => {
|
47
28
|
try {
|
48
29
|
const webhookSignature = Buffer.from(signature || "", "base64");
|
49
|
-
const hmac =
|
30
|
+
const hmac = createHmac("sha256", Buffer.from(secret, "base64"));
|
50
31
|
payload = typeof payload === "string" ? payload : toNormalizedJsonString(payload);
|
51
32
|
const digest = hmac.update(payload).digest();
|
52
|
-
if (webhookSignature.length === digest.length &&
|
33
|
+
if (webhookSignature.length === digest.length && timingSafeEqual(digest, webhookSignature)) {
|
53
34
|
return true;
|
54
35
|
}
|
55
|
-
throw new
|
36
|
+
throw new WebhookVerificationError();
|
56
37
|
} catch (error) {
|
57
|
-
throw new
|
58
|
-
`${
|
38
|
+
throw new WebhookVerificationError(
|
39
|
+
`${VERIFICATION_ERROR_MESSAGE}: ${error.message}`
|
59
40
|
);
|
60
41
|
}
|
61
42
|
};
|
@@ -71,7 +52,7 @@ const base64Sha256Verifier = (_options) => {
|
|
71
52
|
};
|
72
53
|
};
|
73
54
|
var base64Sha256Verifier_default = base64Sha256Verifier;
|
74
|
-
|
75
|
-
|
55
|
+
export {
|
56
|
+
base64Sha256Verifier_default as default,
|
76
57
|
verifySignature
|
77
|
-
}
|
58
|
+
};
|
@@ -1,59 +1,21 @@
|
|
1
|
-
"
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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.js"));
|
41
|
-
var import_base64Sha256Verifier = __toESM(require("./base64Sha256Verifier.js"));
|
42
|
-
var import_jwtVerifier = __toESM(require("./jwtVerifier.js"));
|
43
|
-
var import_secretKeyVerifier = __toESM(require("./secretKeyVerifier.js"));
|
44
|
-
var import_sha1Verifier = __toESM(require("./sha1Verifier.js"));
|
45
|
-
var import_sha256Verifier = __toESM(require("./sha256Verifier.js"));
|
46
|
-
var import_skipVerifier = __toESM(require("./skipVerifier.js"));
|
47
|
-
var import_timestampSchemeVerifier = __toESM(require("./timestampSchemeVerifier.js"));
|
1
|
+
import bannerPath from "node:path"; import bannerUrl from "node:url"; const __filename = bannerUrl.fileURLToPath(import.meta.url); const __dirname = bannerPath.dirname(__filename);
|
2
|
+
import base64Sha1Verifier from "./base64Sha1Verifier.js";
|
3
|
+
import base64Sha256Verifier from "./base64Sha256Verifier.js";
|
4
|
+
import jwtVerifier from "./jwtVerifier.js";
|
5
|
+
import secretKeyVerifier from "./secretKeyVerifier.js";
|
6
|
+
import sha1Verifier from "./sha1Verifier.js";
|
7
|
+
import sha256Verifier from "./sha256Verifier.js";
|
8
|
+
import skipVerifier from "./skipVerifier.js";
|
9
|
+
import timestampSchemeVerifier from "./timestampSchemeVerifier.js";
|
48
10
|
const verifierLookup = {
|
49
|
-
skipVerifier
|
50
|
-
secretKeyVerifier
|
51
|
-
sha1Verifier
|
52
|
-
sha256Verifier
|
53
|
-
base64Sha1Verifier
|
54
|
-
base64Sha256Verifier
|
55
|
-
timestampSchemeVerifier
|
56
|
-
jwtVerifier
|
11
|
+
skipVerifier,
|
12
|
+
secretKeyVerifier,
|
13
|
+
sha1Verifier,
|
14
|
+
sha256Verifier,
|
15
|
+
base64Sha1Verifier,
|
16
|
+
base64Sha256Verifier,
|
17
|
+
timestampSchemeVerifier,
|
18
|
+
jwtVerifier
|
57
19
|
};
|
58
20
|
const DEFAULT_WEBHOOK_SECRET = process.env.WEBHOOK_SECRET ?? "";
|
59
21
|
const VERIFICATION_ERROR_MESSAGE = "You don't have access to invoke this function.";
|
@@ -87,8 +49,7 @@ class WebhookSignError extends WebhookError {
|
|
87
49
|
super(message || VERIFICATION_SIGN_MESSAGE);
|
88
50
|
}
|
89
51
|
}
|
90
|
-
|
91
|
-
0 && (module.exports = {
|
52
|
+
export {
|
92
53
|
DEFAULT_TOLERANCE,
|
93
54
|
DEFAULT_WEBHOOK_SECRET,
|
94
55
|
VERIFICATION_ERROR_MESSAGE,
|
@@ -96,4 +57,4 @@ class WebhookSignError extends WebhookError {
|
|
96
57
|
WebhookSignError,
|
97
58
|
WebhookVerificationError,
|
98
59
|
verifierLookup
|
99
|
-
}
|
60
|
+
};
|
@@ -1,38 +1,13 @@
|
|
1
|
-
"
|
2
|
-
|
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);
|
1
|
+
import bannerPath from "node:path"; import bannerUrl from "node:url"; const __filename = bannerUrl.fileURLToPath(import.meta.url); const __dirname = bannerPath.dirname(__filename);
|
2
|
+
import { verifierLookup } from "./common.js";
|
27
3
|
const createVerifier = (type, options) => {
|
28
4
|
if (options) {
|
29
|
-
return
|
5
|
+
return verifierLookup[type](options);
|
30
6
|
} else {
|
31
|
-
return
|
7
|
+
return verifierLookup[type]();
|
32
8
|
}
|
33
9
|
};
|
34
|
-
|
35
|
-
|
36
|
-
createVerifier
|
37
|
-
|
38
|
-
});
|
10
|
+
export * from "./common.js";
|
11
|
+
export {
|
12
|
+
createVerifier
|
13
|
+
};
|
@@ -1,55 +1,25 @@
|
|
1
|
-
"
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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.js");
|
1
|
+
import bannerPath from "node:path"; import bannerUrl from "node:url"; const __filename = bannerUrl.fileURLToPath(import.meta.url); const __dirname = bannerPath.dirname(__filename);
|
2
|
+
import jwt from "jsonwebtoken";
|
3
|
+
import {
|
4
|
+
WebhookSignError,
|
5
|
+
WebhookVerificationError,
|
6
|
+
DEFAULT_WEBHOOK_SECRET
|
7
|
+
} from "./common.js";
|
38
8
|
const createSignature = ({
|
39
9
|
payload,
|
40
|
-
secret =
|
10
|
+
secret = DEFAULT_WEBHOOK_SECRET,
|
41
11
|
options
|
42
12
|
}) => {
|
43
13
|
try {
|
44
14
|
const signOptions = options?.issuer ? { issuer: options?.issuer } : void 0;
|
45
|
-
return
|
15
|
+
return jwt.sign(payload, secret, { ...signOptions });
|
46
16
|
} catch (error) {
|
47
|
-
throw new
|
17
|
+
throw new WebhookSignError(error.message);
|
48
18
|
}
|
49
19
|
};
|
50
20
|
const verifySignature = ({
|
51
21
|
payload,
|
52
|
-
secret =
|
22
|
+
secret = DEFAULT_WEBHOOK_SECRET,
|
53
23
|
signature,
|
54
24
|
options
|
55
25
|
}) => {
|
@@ -58,13 +28,13 @@ const verifySignature = ({
|
|
58
28
|
console.warn("Missing payload");
|
59
29
|
}
|
60
30
|
if (options?.issuer) {
|
61
|
-
|
31
|
+
jwt.verify(signature, secret, { issuer: options?.issuer });
|
62
32
|
} else {
|
63
|
-
|
33
|
+
jwt.verify(signature, secret);
|
64
34
|
}
|
65
35
|
return true;
|
66
36
|
} catch {
|
67
|
-
throw new
|
37
|
+
throw new WebhookVerificationError();
|
68
38
|
}
|
69
39
|
};
|
70
40
|
const jwtVerifier = (options) => {
|
@@ -79,8 +49,8 @@ const jwtVerifier = (options) => {
|
|
79
49
|
};
|
80
50
|
};
|
81
51
|
var jwtVerifier_default = jwtVerifier;
|
82
|
-
|
83
|
-
|
52
|
+
export {
|
53
|
+
jwtVerifier_default as default,
|
84
54
|
jwtVerifier,
|
85
55
|
verifySignature
|
86
|
-
}
|
56
|
+
};
|
@@ -1,36 +1,14 @@
|
|
1
|
-
"
|
2
|
-
|
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.js");
|
1
|
+
import bannerPath from "node:path"; import bannerUrl from "node:url"; const __filename = bannerUrl.fileURLToPath(import.meta.url); const __dirname = bannerPath.dirname(__filename);
|
2
|
+
import { WebhookVerificationError, DEFAULT_WEBHOOK_SECRET } from "./common.js";
|
25
3
|
const secretKeyVerifier = (_options) => {
|
26
4
|
return {
|
27
5
|
sign: ({ secret }) => {
|
28
6
|
return secret;
|
29
7
|
},
|
30
|
-
verify: ({ signature, secret =
|
8
|
+
verify: ({ signature, secret = DEFAULT_WEBHOOK_SECRET }) => {
|
31
9
|
const verified = signature === secret;
|
32
10
|
if (!verified) {
|
33
|
-
throw new
|
11
|
+
throw new WebhookVerificationError();
|
34
12
|
}
|
35
13
|
return verified;
|
36
14
|
},
|
@@ -38,3 +16,6 @@ const secretKeyVerifier = (_options) => {
|
|
38
16
|
};
|
39
17
|
};
|
40
18
|
var secretKeyVerifier_default = secretKeyVerifier;
|
19
|
+
export {
|
20
|
+
secretKeyVerifier_default as default
|
21
|
+
};
|