@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,35 @@
|
|
1
|
+
import type { Logger } from '../logger';
|
2
|
+
import type BaseClient from './clients/BaseClient';
|
3
|
+
export { default as MemcachedClient } from './clients/MemcachedClient';
|
4
|
+
export { default as RedisClient } from './clients/RedisClient';
|
5
|
+
export { default as InMemoryClient } from './clients/InMemoryClient';
|
6
|
+
export interface CreateCacheOptions {
|
7
|
+
logger?: Logger;
|
8
|
+
timeout?: number;
|
9
|
+
prefix?: string;
|
10
|
+
fields?: {
|
11
|
+
id: string;
|
12
|
+
updatedAt: string;
|
13
|
+
};
|
14
|
+
}
|
15
|
+
export interface CacheOptions {
|
16
|
+
expires?: number;
|
17
|
+
}
|
18
|
+
export interface CacheFindManyOptions<TFindManyArgs extends Record<string, unknown>> extends CacheOptions {
|
19
|
+
conditions?: TFindManyArgs;
|
20
|
+
}
|
21
|
+
export type CacheKey = string | string[];
|
22
|
+
export type LatestQuery = Record<string, unknown>;
|
23
|
+
type GenericDelegate = {
|
24
|
+
findMany: (...args: any) => any;
|
25
|
+
findFirst: (...args: any) => any;
|
26
|
+
};
|
27
|
+
export declare const cacheKeySeparator = "-";
|
28
|
+
export declare const formatCacheKey: (key: CacheKey, prefix?: string) => string;
|
29
|
+
export declare const createCache: (cacheClient: BaseClient, options?: CreateCacheOptions) => {
|
30
|
+
cache: <TResult>(key: CacheKey, input: () => TResult | Promise<TResult>, options?: CacheOptions) => Promise<any>;
|
31
|
+
cacheFindMany: <TDelegate extends GenericDelegate>(key: CacheKey, model: TDelegate, options?: CacheFindManyOptions<Parameters<TDelegate["findMany"]>[0]>) => Promise<any>;
|
32
|
+
cacheClient: BaseClient;
|
33
|
+
deleteCacheKey: (key: CacheKey) => Promise<any>;
|
34
|
+
};
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cache/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAEvC,OAAO,KAAK,UAAU,MAAM,sBAAsB,CAAA;AAGlD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,2BAA2B,CAAA;AACtE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAC9D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAEpE,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE;QACP,EAAE,EAAE,MAAM,CAAA;QACV,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,oBAAoB,CACnC,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC7C,SAAQ,YAAY;IACpB,UAAU,CAAC,EAAE,aAAa,CAAA;CAC3B;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;AACxC,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEjD,KAAK,eAAe,GAAG;IACrB,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,CAAA;IAC/B,SAAS,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,CAAA;CACjC,CAAA;AAQD,eAAO,MAAM,iBAAiB,MAAM,CAAA;AAEpC,eAAO,MAAM,cAAc,QAAS,QAAQ,WAAW,MAAM,WAkB5D,CAAA;AAMD,eAAO,MAAM,WAAW,gBACT,UAAU,YACb,kBAAkB;YAQP,OAAO,OACrB,QAAQ,SACN,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,YAC7B,YAAY,KACrB,OAAO,CAAC,GAAG,CAAC;oBAqDc,SAAS,SAAS,eAAe,OACvD,QAAQ,SACN,SAAS,YACP,oBAAoB,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;0BAgDlC,QAAQ;CA0B5C,CAAA"}
|
@@ -0,0 +1,171 @@
|
|
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 cache_exports = {};
|
30
|
+
__export(cache_exports, {
|
31
|
+
InMemoryClient: () => import_InMemoryClient.default,
|
32
|
+
MemcachedClient: () => import_MemcachedClient.default,
|
33
|
+
RedisClient: () => import_RedisClient.default,
|
34
|
+
cacheKeySeparator: () => cacheKeySeparator,
|
35
|
+
createCache: () => createCache,
|
36
|
+
formatCacheKey: () => formatCacheKey
|
37
|
+
});
|
38
|
+
module.exports = __toCommonJS(cache_exports);
|
39
|
+
var import_errors = require("./errors");
|
40
|
+
var import_MemcachedClient = __toESM(require("./clients/MemcachedClient"));
|
41
|
+
var import_RedisClient = __toESM(require("./clients/RedisClient"));
|
42
|
+
var import_InMemoryClient = __toESM(require("./clients/InMemoryClient"));
|
43
|
+
const DEFAULT_LATEST_FIELDS = { id: "id", updatedAt: "updatedAt" };
|
44
|
+
const wait = (ms) => {
|
45
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
46
|
+
};
|
47
|
+
const cacheKeySeparator = "-";
|
48
|
+
const formatCacheKey = (key, prefix) => {
|
49
|
+
let output;
|
50
|
+
if (Array.isArray(key)) {
|
51
|
+
output = key.join(cacheKeySeparator);
|
52
|
+
} else {
|
53
|
+
output = key;
|
54
|
+
}
|
55
|
+
if (prefix && !output.toString().match(new RegExp("^" + prefix + cacheKeySeparator))) {
|
56
|
+
output = `${prefix}${cacheKeySeparator}${output}`;
|
57
|
+
}
|
58
|
+
return output;
|
59
|
+
};
|
60
|
+
const serialize = (input) => {
|
61
|
+
return JSON.parse(JSON.stringify(input));
|
62
|
+
};
|
63
|
+
const createCache = (cacheClient, options) => {
|
64
|
+
const client = cacheClient;
|
65
|
+
const logger = options?.logger;
|
66
|
+
const timeout = options?.timeout || 1e3;
|
67
|
+
const prefix = options?.prefix;
|
68
|
+
const fields = options?.fields || DEFAULT_LATEST_FIELDS;
|
69
|
+
const cache = async (key, input, options2) => {
|
70
|
+
const cacheKey = formatCacheKey(key, prefix);
|
71
|
+
try {
|
72
|
+
const result = await Promise.race([
|
73
|
+
client.get(cacheKey),
|
74
|
+
wait(timeout).then(() => {
|
75
|
+
throw new import_errors.CacheTimeoutError();
|
76
|
+
})
|
77
|
+
]);
|
78
|
+
if (result) {
|
79
|
+
logger?.debug(`[Cache] HIT key '${cacheKey}'`);
|
80
|
+
return result;
|
81
|
+
}
|
82
|
+
} catch (e) {
|
83
|
+
logger?.error(`[Cache] Error GET '${cacheKey}': ${e.message}`);
|
84
|
+
if (e instanceof import_errors.CacheTimeoutError && client.disconnect) {
|
85
|
+
logger?.error(`[Cache] Disconnecting current instance...`);
|
86
|
+
await client.disconnect();
|
87
|
+
}
|
88
|
+
return serialize(await input());
|
89
|
+
}
|
90
|
+
let data;
|
91
|
+
try {
|
92
|
+
data = await input();
|
93
|
+
await Promise.race([
|
94
|
+
client.set(cacheKey, data, options2 || {}),
|
95
|
+
wait(timeout).then(() => {
|
96
|
+
throw new import_errors.CacheTimeoutError();
|
97
|
+
})
|
98
|
+
]);
|
99
|
+
logger?.debug(
|
100
|
+
`[Cache] MISS '${cacheKey}', SET ${JSON.stringify(data).length} bytes`
|
101
|
+
);
|
102
|
+
return serialize(data);
|
103
|
+
} catch (e) {
|
104
|
+
logger?.error(`[Cache] Error SET '${cacheKey}': ${e.message}`);
|
105
|
+
return serialize(data || await input());
|
106
|
+
}
|
107
|
+
};
|
108
|
+
const cacheFindMany = async (key, model, options2 = {}) => {
|
109
|
+
const { conditions, ...rest } = options2;
|
110
|
+
const cacheKey = formatCacheKey(key, prefix);
|
111
|
+
let latest, latestCacheKey;
|
112
|
+
const { PrismaClientValidationError } = await import("@prisma/client");
|
113
|
+
try {
|
114
|
+
latest = await model.findFirst({
|
115
|
+
...conditions,
|
116
|
+
orderBy: { [fields.updatedAt]: "desc" },
|
117
|
+
select: { [fields.id]: true, [fields.updatedAt]: true }
|
118
|
+
});
|
119
|
+
} catch (e) {
|
120
|
+
if (e instanceof PrismaClientValidationError) {
|
121
|
+
logger?.error(
|
122
|
+
`[Cache] cacheFindMany error: model does not contain \`${fields.id}\` or \`${fields.updatedAt}\` fields`
|
123
|
+
);
|
124
|
+
} else {
|
125
|
+
logger?.error(`[Cache] cacheFindMany error: ${e.message}`);
|
126
|
+
}
|
127
|
+
return serialize(await model.findMany(conditions));
|
128
|
+
}
|
129
|
+
if (latest) {
|
130
|
+
latestCacheKey = `${cacheKey}${cacheKeySeparator}${latest.id}${cacheKeySeparator}${latest[fields.updatedAt].getTime()}`;
|
131
|
+
} else {
|
132
|
+
logger?.debug(
|
133
|
+
`[Cache] cacheFindMany: No data to cache for key \`${key}\`, skipping`
|
134
|
+
);
|
135
|
+
return serialize(await model.findMany(conditions));
|
136
|
+
}
|
137
|
+
return cache(latestCacheKey, () => model.findMany(conditions), rest);
|
138
|
+
};
|
139
|
+
const deleteCacheKey = async (key) => {
|
140
|
+
let result;
|
141
|
+
const cacheKey = formatCacheKey(key, prefix);
|
142
|
+
try {
|
143
|
+
await Promise.race([
|
144
|
+
result = client.del(cacheKey),
|
145
|
+
wait(timeout).then(() => {
|
146
|
+
throw new import_errors.CacheTimeoutError();
|
147
|
+
})
|
148
|
+
]);
|
149
|
+
logger?.debug(`[Cache] DEL '${cacheKey}'`);
|
150
|
+
return result;
|
151
|
+
} catch (e) {
|
152
|
+
logger?.error(`[Cache] Error DEL '${cacheKey}': ${e.message}`);
|
153
|
+
return false;
|
154
|
+
}
|
155
|
+
};
|
156
|
+
return {
|
157
|
+
cache,
|
158
|
+
cacheFindMany,
|
159
|
+
cacheClient: client,
|
160
|
+
deleteCacheKey
|
161
|
+
};
|
162
|
+
};
|
163
|
+
// Annotate the CommonJS export names for ESM import in node:
|
164
|
+
0 && (module.exports = {
|
165
|
+
InMemoryClient,
|
166
|
+
MemcachedClient,
|
167
|
+
RedisClient,
|
168
|
+
cacheKeySeparator,
|
169
|
+
createCache,
|
170
|
+
formatCacheKey
|
171
|
+
});
|
package/dist/cors.d.ts
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { PartialRequest } from './transforms';
|
2
|
+
export type CorsConfig = {
|
3
|
+
origin?: boolean | string | string[];
|
4
|
+
methods?: string | string[];
|
5
|
+
allowedHeaders?: string | string[];
|
6
|
+
exposedHeaders?: string | string[];
|
7
|
+
credentials?: boolean;
|
8
|
+
maxAge?: number;
|
9
|
+
};
|
10
|
+
export type CorsHeaders = Record<string, string>;
|
11
|
+
export type CorsContext = ReturnType<typeof createCorsContext>;
|
12
|
+
export declare function createCorsContext(cors: CorsConfig | undefined): {
|
13
|
+
shouldHandleCors(request: PartialRequest): boolean;
|
14
|
+
getRequestHeaders(request: PartialRequest): CorsHeaders;
|
15
|
+
};
|
16
|
+
//# sourceMappingURL=cors.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../src/cors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAElD,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;IACpC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC3B,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAClC,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAClC,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAChD,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAE9D,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS;8BA6ChC,cAAc;+BAGb,cAAc,GAAG,WAAW;EAgC1D"}
|
package/dist/cors.js
ADDED
@@ -0,0 +1,93 @@
|
|
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 cors_exports = {};
|
20
|
+
__export(cors_exports, {
|
21
|
+
createCorsContext: () => createCorsContext
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(cors_exports);
|
24
|
+
var import_fetch = require("@whatwg-node/fetch");
|
25
|
+
function createCorsContext(cors) {
|
26
|
+
const corsHeaders = new import_fetch.Headers();
|
27
|
+
if (cors) {
|
28
|
+
if (cors.methods) {
|
29
|
+
if (typeof cors.methods === "string") {
|
30
|
+
corsHeaders.set("access-control-allow-methods", cors.methods);
|
31
|
+
} else if (Array.isArray(cors.methods)) {
|
32
|
+
corsHeaders.set("access-control-allow-methods", cors.methods.join(","));
|
33
|
+
}
|
34
|
+
}
|
35
|
+
if (cors.allowedHeaders) {
|
36
|
+
if (typeof cors.allowedHeaders === "string") {
|
37
|
+
corsHeaders.set("access-control-allow-headers", cors.allowedHeaders);
|
38
|
+
} else if (Array.isArray(cors.allowedHeaders)) {
|
39
|
+
corsHeaders.set(
|
40
|
+
"access-control-allow-headers",
|
41
|
+
cors.allowedHeaders.join(",")
|
42
|
+
);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
if (cors.exposedHeaders) {
|
46
|
+
if (typeof cors.exposedHeaders === "string") {
|
47
|
+
corsHeaders.set("access-control-expose-headers", cors.exposedHeaders);
|
48
|
+
} else if (Array.isArray(cors.exposedHeaders)) {
|
49
|
+
corsHeaders.set(
|
50
|
+
"access-control-expose-headers",
|
51
|
+
cors.exposedHeaders.join(",")
|
52
|
+
);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
if (cors.credentials) {
|
56
|
+
corsHeaders.set("access-control-allow-credentials", "true");
|
57
|
+
}
|
58
|
+
if (typeof cors.maxAge === "number") {
|
59
|
+
corsHeaders.set("access-control-max-age", cors.maxAge.toString());
|
60
|
+
}
|
61
|
+
}
|
62
|
+
return {
|
63
|
+
shouldHandleCors(request) {
|
64
|
+
return request.method === "OPTIONS";
|
65
|
+
},
|
66
|
+
getRequestHeaders(request) {
|
67
|
+
const eventHeaders = new import_fetch.Headers(request.headers);
|
68
|
+
const requestCorsHeaders = new import_fetch.Headers(corsHeaders);
|
69
|
+
if (cors?.origin) {
|
70
|
+
const requestOrigin = eventHeaders.get("origin");
|
71
|
+
if (typeof cors.origin === "string") {
|
72
|
+
requestCorsHeaders.set("access-control-allow-origin", cors.origin);
|
73
|
+
} else if (requestOrigin && (typeof cors.origin === "boolean" || Array.isArray(cors.origin) && requestOrigin && cors.origin.includes(requestOrigin))) {
|
74
|
+
requestCorsHeaders.set("access-control-allow-origin", requestOrigin);
|
75
|
+
}
|
76
|
+
const requestAccessControlRequestHeaders = eventHeaders.get(
|
77
|
+
"access-control-request-headers"
|
78
|
+
);
|
79
|
+
if (!cors.allowedHeaders && requestAccessControlRequestHeaders) {
|
80
|
+
requestCorsHeaders.set(
|
81
|
+
"access-control-allow-headers",
|
82
|
+
requestAccessControlRequestHeaders
|
83
|
+
);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
return Object.fromEntries(requestCorsHeaders.entries());
|
87
|
+
}
|
88
|
+
};
|
89
|
+
}
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
91
|
+
0 && (module.exports = {
|
92
|
+
createCorsContext
|
93
|
+
});
|
package/dist/errors.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IACrC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAA;gBAC/B,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAQ9D"}
|
package/dist/errors.js
ADDED
@@ -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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var errors_exports = {};
|
20
|
+
__export(errors_exports, {
|
21
|
+
RedwoodError: () => RedwoodError
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(errors_exports);
|
24
|
+
class RedwoodError extends Error {
|
25
|
+
extensions;
|
26
|
+
constructor(message, extensions) {
|
27
|
+
super(message);
|
28
|
+
this.name = "RedwoodError";
|
29
|
+
this.extensions = {
|
30
|
+
...extensions,
|
31
|
+
code: extensions?.code || "REDWOODJS_ERROR"
|
32
|
+
};
|
33
|
+
}
|
34
|
+
}
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
36
|
+
0 && (module.exports = {
|
37
|
+
RedwoodError
|
38
|
+
});
|
package/dist/event.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAKtD,eAAO,MAAM,cAAc,UAClB,oBAAoB,GAAG,OAAO,cACzB,MAAM,8BAOnB,CAAA"}
|
package/dist/event.js
ADDED
@@ -0,0 +1,34 @@
|
|
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 event_exports = {};
|
20
|
+
__export(event_exports, {
|
21
|
+
getEventHeader: () => getEventHeader
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(event_exports);
|
24
|
+
var import_transforms = require("./transforms");
|
25
|
+
const getEventHeader = (event, headerName) => {
|
26
|
+
if ((0, import_transforms.isFetchApiRequest)(event)) {
|
27
|
+
return event.headers.get(headerName);
|
28
|
+
}
|
29
|
+
return event.headers[headerName] || event.headers[headerName.toLowerCase()];
|
30
|
+
};
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
32
|
+
0 && (module.exports = {
|
33
|
+
getEventHeader
|
34
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"apiGatewayProxyEvent.fixture.d.ts","sourceRoot":"","sources":["../../../src/functions/fixtures/apiGatewayProxyEvent.fixture.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEtD,eAAO,MAAM,0BAA0B,EAAE,oBA0CxC,CAAA;AAED,eAAe,0BAA0B,CAAA"}
|
@@ -0,0 +1,72 @@
|
|
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 apiGatewayProxyEvent_fixture_exports = {};
|
20
|
+
__export(apiGatewayProxyEvent_fixture_exports, {
|
21
|
+
default: () => apiGatewayProxyEvent_fixture_default,
|
22
|
+
mockedAPIGatewayProxyEvent: () => mockedAPIGatewayProxyEvent
|
23
|
+
});
|
24
|
+
module.exports = __toCommonJS(apiGatewayProxyEvent_fixture_exports);
|
25
|
+
const mockedAPIGatewayProxyEvent = {
|
26
|
+
body: "MOCKED_BODY",
|
27
|
+
headers: {},
|
28
|
+
multiValueHeaders: {},
|
29
|
+
httpMethod: "POST",
|
30
|
+
isBase64Encoded: false,
|
31
|
+
path: "/MOCK_PATH",
|
32
|
+
pathParameters: null,
|
33
|
+
queryStringParameters: null,
|
34
|
+
multiValueQueryStringParameters: null,
|
35
|
+
stageVariables: null,
|
36
|
+
requestContext: {
|
37
|
+
accountId: "MOCKED_ACCOUNT",
|
38
|
+
apiId: "MOCKED_API_ID",
|
39
|
+
authorizer: { name: "MOCKED_AUTHORIZER" },
|
40
|
+
protocol: "HTTP",
|
41
|
+
identity: {
|
42
|
+
accessKey: null,
|
43
|
+
accountId: null,
|
44
|
+
apiKey: null,
|
45
|
+
apiKeyId: null,
|
46
|
+
caller: null,
|
47
|
+
clientCert: null,
|
48
|
+
cognitoAuthenticationProvider: null,
|
49
|
+
cognitoAuthenticationType: null,
|
50
|
+
cognitoIdentityId: null,
|
51
|
+
cognitoIdentityPoolId: null,
|
52
|
+
principalOrgId: null,
|
53
|
+
sourceIp: "123.123.123.123",
|
54
|
+
user: null,
|
55
|
+
userAgent: null,
|
56
|
+
userArn: null
|
57
|
+
},
|
58
|
+
httpMethod: "POST",
|
59
|
+
path: "/MOCK_PATH",
|
60
|
+
stage: "MOCK_STAGE",
|
61
|
+
requestId: "MOCKED_REQUEST_ID",
|
62
|
+
requestTimeEpoch: 1,
|
63
|
+
resourceId: "MOCKED_RESOURCE_ID",
|
64
|
+
resourcePath: "MOCKED_RESOURCE_PATH"
|
65
|
+
},
|
66
|
+
resource: "MOCKED_RESOURCE"
|
67
|
+
};
|
68
|
+
var apiGatewayProxyEvent_fixture_default = mockedAPIGatewayProxyEvent;
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
70
|
+
0 && (module.exports = {
|
71
|
+
mockedAPIGatewayProxyEvent
|
72
|
+
});
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
export * from './auth';
|
2
|
+
export * from './errors';
|
3
|
+
export * from './validations/validations';
|
4
|
+
export * from './validations/errors';
|
5
|
+
export * from './types';
|
6
|
+
export * from './transforms';
|
7
|
+
export * from './cors';
|
8
|
+
export * from './event';
|
9
|
+
export declare const prismaVersion: any;
|
10
|
+
export declare const redwoodVersion: any;
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,2BAA2B,CAAA;AACzC,cAAc,sBAAsB,CAAA;AAEpC,cAAc,SAAS,CAAA;AAEvB,cAAc,cAAc,CAAA;AAC5B,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AAIvB,eAAO,MAAM,aAAa,KAA8C,CAAA;AACxE,eAAO,MAAM,cAAc,KAAuB,CAAA"}
|
package/dist/index.js
ADDED
@@ -0,0 +1,49 @@
|
|
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 index_exports = {};
|
21
|
+
__export(index_exports, {
|
22
|
+
prismaVersion: () => prismaVersion,
|
23
|
+
redwoodVersion: () => redwoodVersion
|
24
|
+
});
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
26
|
+
__reExport(index_exports, require("./auth"), module.exports);
|
27
|
+
__reExport(index_exports, require("./errors"), module.exports);
|
28
|
+
__reExport(index_exports, require("./validations/validations"), module.exports);
|
29
|
+
__reExport(index_exports, require("./validations/errors"), module.exports);
|
30
|
+
__reExport(index_exports, require("./types"), module.exports);
|
31
|
+
__reExport(index_exports, require("./transforms"), module.exports);
|
32
|
+
__reExport(index_exports, require("./cors"), module.exports);
|
33
|
+
__reExport(index_exports, require("./event"), module.exports);
|
34
|
+
const packageJson = require("../package.json");
|
35
|
+
const prismaVersion = packageJson?.dependencies["@prisma/client"];
|
36
|
+
const redwoodVersion = packageJson?.version;
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
38
|
+
0 && (module.exports = {
|
39
|
+
prismaVersion,
|
40
|
+
redwoodVersion,
|
41
|
+
...require("./auth"),
|
42
|
+
...require("./errors"),
|
43
|
+
...require("./validations/validations"),
|
44
|
+
...require("./validations/errors"),
|
45
|
+
...require("./types"),
|
46
|
+
...require("./transforms"),
|
47
|
+
...require("./cors"),
|
48
|
+
...require("./event")
|
49
|
+
});
|