@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,81 @@
|
|
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 timestampSchemeVerifier_exports = {};
|
20
|
+
__export(timestampSchemeVerifier_exports, {
|
21
|
+
default: () => timestampSchemeVerifier_default
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(timestampSchemeVerifier_exports);
|
24
|
+
var import_crypto = require("crypto");
|
25
|
+
var import_common = require("./common");
|
26
|
+
const getHmac = ({ secret }) => {
|
27
|
+
if (typeof secret === "undefined" || secret === "") {
|
28
|
+
throw new import_common.WebhookVerificationError();
|
29
|
+
}
|
30
|
+
return (0, import_crypto.createHmac)("sha256", secret);
|
31
|
+
};
|
32
|
+
const createSignature = ({
|
33
|
+
payload,
|
34
|
+
secret = import_common.DEFAULT_WEBHOOK_SECRET,
|
35
|
+
timestamp = Date.now()
|
36
|
+
}) => {
|
37
|
+
const hmac = getHmac({ secret });
|
38
|
+
hmac.update(timestamp + "." + payload);
|
39
|
+
return `t=${timestamp},v1=${hmac.digest("hex")}`;
|
40
|
+
};
|
41
|
+
const verifySignature = ({
|
42
|
+
payload,
|
43
|
+
secret = import_common.DEFAULT_WEBHOOK_SECRET,
|
44
|
+
signature,
|
45
|
+
options
|
46
|
+
}) => {
|
47
|
+
const match = /t=(\d+),v1=([\da-f]+)/.exec(signature);
|
48
|
+
if (!match) {
|
49
|
+
throw new import_common.WebhookVerificationError();
|
50
|
+
}
|
51
|
+
const signedStamp = Number(match[1]);
|
52
|
+
const signedPayload = match[2];
|
53
|
+
const timestamp = options?.currentTimestampOverride ?? Date.now();
|
54
|
+
const tolerance = options?.tolerance ?? import_common.DEFAULT_TOLERANCE;
|
55
|
+
const difference = Math.abs(timestamp - signedStamp);
|
56
|
+
if (difference > tolerance) {
|
57
|
+
throw new import_common.WebhookVerificationError();
|
58
|
+
}
|
59
|
+
const hmac = getHmac({ secret });
|
60
|
+
hmac.update(signedStamp + "." + payload);
|
61
|
+
if (hmac.digest("hex") === signedPayload) {
|
62
|
+
return true;
|
63
|
+
}
|
64
|
+
throw new import_common.WebhookVerificationError();
|
65
|
+
};
|
66
|
+
const timestampSchemeVerifier = (options) => {
|
67
|
+
return {
|
68
|
+
sign: ({ payload, secret }) => {
|
69
|
+
return createSignature({
|
70
|
+
payload,
|
71
|
+
secret,
|
72
|
+
timestamp: options?.currentTimestampOverride
|
73
|
+
});
|
74
|
+
},
|
75
|
+
verify: ({ payload, secret, signature }) => {
|
76
|
+
return verifySignature({ payload, secret, signature, options });
|
77
|
+
},
|
78
|
+
type: "timestampSchemeVerifier"
|
79
|
+
};
|
80
|
+
};
|
81
|
+
var timestampSchemeVerifier_default = timestampSchemeVerifier;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"redwood.d.ts","sourceRoot":"","sources":["../../src/bins/redwood.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
"use strict";
|
3
|
+
var __create = Object.create;
|
4
|
+
var __defProp = Object.defineProperty;
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
+
for (let key of __getOwnPropNames(from))
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
+
}
|
15
|
+
return to;
|
16
|
+
};
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
23
|
+
mod
|
24
|
+
));
|
25
|
+
var import_module = require("module");
|
26
|
+
const requireFromCli = (0, import_module.createRequire)(
|
27
|
+
require.resolve("@redmix/cli/package.json")
|
28
|
+
);
|
29
|
+
const bins = requireFromCli("./package.json")["bin"];
|
30
|
+
if (process.env.PROJECT_CWD) {
|
31
|
+
process.chdir(process.env.PROJECT_CWD);
|
32
|
+
}
|
33
|
+
requireFromCli(bins["redwood"]);
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"rwfw.d.ts","sourceRoot":"","sources":["../../src/bins/rwfw.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
"use strict";
|
3
|
+
var __create = Object.create;
|
4
|
+
var __defProp = Object.defineProperty;
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
+
for (let key of __getOwnPropNames(from))
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
+
}
|
15
|
+
return to;
|
16
|
+
};
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
23
|
+
mod
|
24
|
+
));
|
25
|
+
var import_module = require("module");
|
26
|
+
const requireFromCli = (0, import_module.createRequire)(
|
27
|
+
require.resolve("@redmix/cli/package.json")
|
28
|
+
);
|
29
|
+
const bins = requireFromCli("./package.json")["bin"];
|
30
|
+
if (process.env.PROJECT_CWD) {
|
31
|
+
process.chdir(process.env.PROJECT_CWD);
|
32
|
+
}
|
33
|
+
requireFromCli(bins["rwfw"]);
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"tsc.d.ts","sourceRoot":"","sources":["../../src/bins/tsc.ts"],"names":[],"mappings":""}
|
package/dist/bins/tsc.js
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
"use strict";
|
3
|
+
var __create = Object.create;
|
4
|
+
var __defProp = Object.defineProperty;
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
+
for (let key of __getOwnPropNames(from))
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
+
}
|
15
|
+
return to;
|
16
|
+
};
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
23
|
+
mod
|
24
|
+
));
|
25
|
+
var import_module = require("module");
|
26
|
+
const requireFromTypeScript = (0, import_module.createRequire)(
|
27
|
+
require.resolve("typescript/package.json")
|
28
|
+
);
|
29
|
+
const bins = requireFromTypeScript("./package.json")["bin"];
|
30
|
+
requireFromTypeScript(bins["tsc"]);
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export default abstract class BaseClient {
|
2
|
+
constructor();
|
3
|
+
disconnect?(): void | Promise<void>;
|
4
|
+
abstract connect(): void | Promise<void>;
|
5
|
+
abstract get(key: string): any;
|
6
|
+
abstract set(key: string, value: unknown, options: {
|
7
|
+
expires?: number;
|
8
|
+
}): Promise<any> | any;
|
9
|
+
abstract del(key: string): Promise<boolean> | any;
|
10
|
+
}
|
11
|
+
//# sourceMappingURL=BaseClient.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"BaseClient.d.ts","sourceRoot":"","sources":["../../../src/cache/clients/BaseClient.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,UAAU;;IAKtC,UAAU,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAEnC,QAAQ,CAAC,OAAO,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAGxC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG;IAG9B,QAAQ,CAAC,GAAG,CACV,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,EACd,OAAO,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAC5B,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG;IAGrB,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,GAAG;CAClD"}
|
@@ -0,0 +1,27 @@
|
|
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 BaseClient_exports = {};
|
20
|
+
__export(BaseClient_exports, {
|
21
|
+
default: () => BaseClient
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(BaseClient_exports);
|
24
|
+
class BaseClient {
|
25
|
+
constructor() {
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import BaseClient from './BaseClient';
|
2
|
+
type CacheOptions = {
|
3
|
+
expires?: number;
|
4
|
+
};
|
5
|
+
export default class InMemoryClient extends BaseClient {
|
6
|
+
storage: Record<string, {
|
7
|
+
expires: number;
|
8
|
+
value: string;
|
9
|
+
}>;
|
10
|
+
constructor(data?: {});
|
11
|
+
/**
|
12
|
+
* Special function for testing, only available in InMemoryClient
|
13
|
+
*
|
14
|
+
* Returns deserialized content of cache as an array of values (without cache keys)
|
15
|
+
*
|
16
|
+
*/
|
17
|
+
get contents(): any[];
|
18
|
+
disconnect(): Promise<void>;
|
19
|
+
connect(): Promise<void>;
|
20
|
+
get(key: string): Promise<any>;
|
21
|
+
set(key: string, value: unknown, options?: CacheOptions): Promise<boolean>;
|
22
|
+
del(key: string): Promise<boolean>;
|
23
|
+
/**
|
24
|
+
* Special functions for testing, only available in InMemoryClient
|
25
|
+
*/
|
26
|
+
clear(): Promise<void>;
|
27
|
+
cacheKeyForValue(value: any): string | null;
|
28
|
+
isCached(value: any): boolean;
|
29
|
+
}
|
30
|
+
export {};
|
31
|
+
//# sourceMappingURL=InMemoryClient.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"InMemoryClient.d.ts","sourceRoot":"","sources":["../../../src/cache/clients/InMemoryClient.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,cAAc,CAAA;AAErC,KAAK,YAAY,GAAG;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,UAAU;IACpD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;gBAG/C,IAAI,KAAK;IAKrB;;;;;OAKG;IACH,IAAI,QAAQ,UAIX;IAGK,UAAU;IACV,OAAO;IAEP,GAAG,CAAC,GAAG,EAAE,MAAM;IAWf,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,YAAiB;IAU3D,GAAG,CAAC,GAAG,EAAE,MAAM;IASrB;;OAEG;IACG,KAAK;IAIX,gBAAgB,CAAC,KAAK,EAAE,GAAG;IAU3B,QAAQ,CAAC,KAAK,EAAE,GAAG;CAGpB"}
|
@@ -0,0 +1,100 @@
|
|
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 InMemoryClient_exports = {};
|
30
|
+
__export(InMemoryClient_exports, {
|
31
|
+
default: () => InMemoryClient
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(InMemoryClient_exports);
|
34
|
+
var import_BaseClient = __toESM(require("./BaseClient"));
|
35
|
+
class InMemoryClient extends import_BaseClient.default {
|
36
|
+
storage;
|
37
|
+
// initialize with pre-cached data if needed
|
38
|
+
constructor(data = {}) {
|
39
|
+
super();
|
40
|
+
this.storage = data;
|
41
|
+
}
|
42
|
+
/**
|
43
|
+
* Special function for testing, only available in InMemoryClient
|
44
|
+
*
|
45
|
+
* Returns deserialized content of cache as an array of values (without cache keys)
|
46
|
+
*
|
47
|
+
*/
|
48
|
+
get contents() {
|
49
|
+
return Object.values(this.storage).map(
|
50
|
+
(cacheObj) => JSON.parse(cacheObj.value)
|
51
|
+
);
|
52
|
+
}
|
53
|
+
// Not needed for InMemoryClient
|
54
|
+
async disconnect() {
|
55
|
+
}
|
56
|
+
async connect() {
|
57
|
+
}
|
58
|
+
async get(key) {
|
59
|
+
const now = /* @__PURE__ */ new Date();
|
60
|
+
if (this.storage[key] && this.storage[key].expires > now.getTime()) {
|
61
|
+
return JSON.parse(this.storage[key].value);
|
62
|
+
} else {
|
63
|
+
delete this.storage[key];
|
64
|
+
return null;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
// stores expiration dates as epoch
|
68
|
+
async set(key, value, options = {}) {
|
69
|
+
const now = /* @__PURE__ */ new Date();
|
70
|
+
now.setSeconds(now.getSeconds() + (options?.expires || 31536e4));
|
71
|
+
const data = { expires: now.getTime(), value: JSON.stringify(value) };
|
72
|
+
this.storage[key] = data;
|
73
|
+
return true;
|
74
|
+
}
|
75
|
+
async del(key) {
|
76
|
+
if (this.storage[key]) {
|
77
|
+
delete this.storage[key];
|
78
|
+
return true;
|
79
|
+
} else {
|
80
|
+
return false;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
/**
|
84
|
+
* Special functions for testing, only available in InMemoryClient
|
85
|
+
*/
|
86
|
+
async clear() {
|
87
|
+
this.storage = {};
|
88
|
+
}
|
89
|
+
cacheKeyForValue(value) {
|
90
|
+
for (const [cacheKey, cacheObj] of Object.entries(this.storage)) {
|
91
|
+
if (cacheObj.value === JSON.stringify(value)) {
|
92
|
+
return cacheKey;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
return null;
|
96
|
+
}
|
97
|
+
isCached(value) {
|
98
|
+
return !!this.cacheKeyForValue(value);
|
99
|
+
}
|
100
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { Client as ClientType, ClientOptions, ServerOptions } from 'memjs';
|
2
|
+
import BaseClient from './BaseClient';
|
3
|
+
export default class MemcachedClient extends BaseClient {
|
4
|
+
client?: ClientType | null;
|
5
|
+
servers: string;
|
6
|
+
options: (ClientOptions<string | Buffer, Buffer | null> & ServerOptions) | undefined;
|
7
|
+
constructor(servers: string, options?: ClientOptions & ServerOptions);
|
8
|
+
connect(): Promise<void>;
|
9
|
+
disconnect(): Promise<void>;
|
10
|
+
get(key: string): Promise<any>;
|
11
|
+
set(key: string, value: unknown, options: {
|
12
|
+
expires?: number;
|
13
|
+
}): Promise<boolean | undefined>;
|
14
|
+
del(key: string): Promise<boolean | undefined>;
|
15
|
+
}
|
16
|
+
//# sourceMappingURL=MemcachedClient.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"MemcachedClient.d.ts","sourceRoot":"","sources":["../../../src/cache/clients/MemcachedClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAE/E,OAAO,UAAU,MAAM,cAAc,CAAA;AAErC,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU;IACrD,MAAM,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;IAC1B,OAAO,SAAA;IACP,OAAO,8EAAA;gBAEK,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,aAAa;IAM9D,OAAO;IAKP,UAAU;IAKV,GAAG,CAAC,GAAG,EAAE,MAAM;IAcf,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAQ9D,GAAG,CAAC,GAAG,EAAE,MAAM;CAQtB"}
|
@@ -0,0 +1,75 @@
|
|
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 MemcachedClient_exports = {};
|
30
|
+
__export(MemcachedClient_exports, {
|
31
|
+
default: () => MemcachedClient
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(MemcachedClient_exports);
|
34
|
+
var import_BaseClient = __toESM(require("./BaseClient"));
|
35
|
+
class MemcachedClient extends import_BaseClient.default {
|
36
|
+
client;
|
37
|
+
servers;
|
38
|
+
options;
|
39
|
+
constructor(servers, options) {
|
40
|
+
super();
|
41
|
+
this.servers = servers;
|
42
|
+
this.options = options;
|
43
|
+
}
|
44
|
+
async connect() {
|
45
|
+
const { Client: MemCachedClient } = await import("memjs");
|
46
|
+
this.client = MemCachedClient.create(this.servers, this.options);
|
47
|
+
}
|
48
|
+
async disconnect() {
|
49
|
+
this.client?.close();
|
50
|
+
this.client = null;
|
51
|
+
}
|
52
|
+
async get(key) {
|
53
|
+
if (!this.client) {
|
54
|
+
await this.connect();
|
55
|
+
}
|
56
|
+
const result = await this.client?.get(key);
|
57
|
+
if (result?.value) {
|
58
|
+
return JSON.parse(result.value.toString());
|
59
|
+
} else {
|
60
|
+
return result?.value;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
async set(key, value, options) {
|
64
|
+
if (!this.client) {
|
65
|
+
await this.connect();
|
66
|
+
}
|
67
|
+
return this.client?.set(key, JSON.stringify(value), options);
|
68
|
+
}
|
69
|
+
async del(key) {
|
70
|
+
if (!this.client) {
|
71
|
+
await this.connect();
|
72
|
+
}
|
73
|
+
return this.client?.delete(key);
|
74
|
+
}
|
75
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import type { RedisClientType, RedisClientOptions } from 'redis';
|
2
|
+
import type { Logger } from '../../logger';
|
3
|
+
import BaseClient from './BaseClient';
|
4
|
+
type LoggerOptions = {
|
5
|
+
logger?: Logger;
|
6
|
+
};
|
7
|
+
export default class RedisClient extends BaseClient {
|
8
|
+
client?: RedisClientType | null;
|
9
|
+
logger?: Logger;
|
10
|
+
redisOptions?: RedisClientOptions;
|
11
|
+
constructor(options: RedisClientOptions & LoggerOptions);
|
12
|
+
connect(): Promise<void>;
|
13
|
+
get(key: string): Promise<any>;
|
14
|
+
set(key: string, value: unknown, options: {
|
15
|
+
expires?: number;
|
16
|
+
}): Promise<string | null | undefined>;
|
17
|
+
del(key: string): Promise<boolean>;
|
18
|
+
}
|
19
|
+
export {};
|
20
|
+
//# sourceMappingURL=RedisClient.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"RedisClient.d.ts","sourceRoot":"","sources":["../../../src/cache/clients/RedisClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAEhE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C,OAAO,UAAU,MAAM,cAAc,CAAA;AAMrC,KAAK,aAAa,GAAG;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,UAAU;IACjD,MAAM,CAAC,EAAE,eAAe,GAAG,IAAI,CAAA;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,kBAAkB,CAAA;gBAErB,OAAO,EAAE,kBAAkB,GAAG,aAAa;IAQjD,OAAO;IAiBP,GAAG,CAAC,GAAG,EAAE,MAAM;IAUf,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAc9D,GAAG,CAAC,GAAG,EAAE,MAAM;CAQtB"}
|
@@ -0,0 +1,79 @@
|
|
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 RedisClient_exports = {};
|
30
|
+
__export(RedisClient_exports, {
|
31
|
+
default: () => RedisClient
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(RedisClient_exports);
|
34
|
+
var import_BaseClient = __toESM(require("./BaseClient"));
|
35
|
+
class RedisClient extends import_BaseClient.default {
|
36
|
+
client;
|
37
|
+
logger;
|
38
|
+
redisOptions;
|
39
|
+
constructor(options) {
|
40
|
+
const { logger, ...redisOptions } = options;
|
41
|
+
super();
|
42
|
+
this.logger = logger;
|
43
|
+
this.redisOptions = redisOptions;
|
44
|
+
}
|
45
|
+
async connect() {
|
46
|
+
const { createClient } = await import("redis");
|
47
|
+
this.client = createClient(this.redisOptions);
|
48
|
+
this.client.on(
|
49
|
+
"error",
|
50
|
+
(err) => this.logger?.error(err) || console.error(err)
|
51
|
+
);
|
52
|
+
await this.client.connect();
|
53
|
+
}
|
54
|
+
// @NOTE: disconnect intentionally not implemented for Redis
|
55
|
+
// Because node-redis recovers gracefully from connection loss
|
56
|
+
async get(key) {
|
57
|
+
if (!this.client) {
|
58
|
+
await this.connect();
|
59
|
+
}
|
60
|
+
const result = await this.client?.get(key);
|
61
|
+
return result ? JSON.parse(result) : null;
|
62
|
+
}
|
63
|
+
async set(key, value, options) {
|
64
|
+
const setOptions = {};
|
65
|
+
if (!this.client) {
|
66
|
+
await this.connect();
|
67
|
+
}
|
68
|
+
if (options.expires) {
|
69
|
+
setOptions.EX = options.expires;
|
70
|
+
}
|
71
|
+
return this.client?.set(key, JSON.stringify(value), setOptions);
|
72
|
+
}
|
73
|
+
async del(key) {
|
74
|
+
if (!this.client) {
|
75
|
+
await this.connect();
|
76
|
+
}
|
77
|
+
return !!await this.client?.del([key]);
|
78
|
+
}
|
79
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/cache/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,iBAAkB,SAAQ,KAAK;;CAK3C"}
|
@@ -0,0 +1,33 @@
|
|
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 errors_exports = {};
|
20
|
+
__export(errors_exports, {
|
21
|
+
CacheTimeoutError: () => CacheTimeoutError
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(errors_exports);
|
24
|
+
class CacheTimeoutError extends Error {
|
25
|
+
constructor() {
|
26
|
+
super("Timed out waiting for response from the cache server");
|
27
|
+
this.name = "CacheTimeoutError";
|
28
|
+
}
|
29
|
+
}
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
31
|
+
0 && (module.exports = {
|
32
|
+
CacheTimeoutError
|
33
|
+
});
|