@cedarjs/api 5.0.6 → 5.0.7-next.219

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/dist/auth/index.d.ts +9 -0
  2. package/dist/auth/index.d.ts.map +1 -1
  3. package/dist/auth/index.js +7 -0
  4. package/dist/bins/cedar.js +14 -0
  5. package/dist/bins/cfw.js +14 -0
  6. package/dist/bins/redwood.js +14 -0
  7. package/dist/bins/tsc.js +8 -0
  8. package/dist/errors.d.ts +9 -1
  9. package/dist/errors.d.ts.map +1 -1
  10. package/dist/errors.js +9 -2
  11. package/dist/index.js +3 -3
  12. package/dist/logger/index.d.ts +7 -5
  13. package/dist/logger/index.d.ts.map +1 -1
  14. package/dist/runtime.d.ts +0 -26
  15. package/dist/runtime.d.ts.map +1 -1
  16. package/dist/runtime.js +1 -22
  17. package/package.json +17 -41
  18. package/dist/cjs/auth/index.d.ts +0 -64
  19. package/dist/cjs/auth/index.d.ts.map +0 -1
  20. package/dist/cjs/auth/index.js +0 -143
  21. package/dist/cjs/auth/parseJWT.d.ts +0 -6
  22. package/dist/cjs/auth/parseJWT.d.ts.map +0 -1
  23. package/dist/cjs/auth/parseJWT.js +0 -57
  24. package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts +0 -18
  25. package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts.map +0 -1
  26. package/dist/cjs/auth/verifiers/base64Sha1Verifier.js +0 -77
  27. package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts +0 -18
  28. package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts.map +0 -1
  29. package/dist/cjs/auth/verifiers/base64Sha256Verifier.js +0 -77
  30. package/dist/cjs/auth/verifiers/common.d.ts +0 -112
  31. package/dist/cjs/auth/verifiers/common.d.ts.map +0 -1
  32. package/dist/cjs/auth/verifiers/common.js +0 -89
  33. package/dist/cjs/auth/verifiers/index.d.ts +0 -8
  34. package/dist/cjs/auth/verifiers/index.d.ts.map +0 -1
  35. package/dist/cjs/auth/verifiers/index.js +0 -39
  36. package/dist/cjs/auth/verifiers/jwtVerifier.d.ts +0 -18
  37. package/dist/cjs/auth/verifiers/jwtVerifier.d.ts.map +0 -1
  38. package/dist/cjs/auth/verifiers/jwtVerifier.js +0 -84
  39. package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts +0 -11
  40. package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts.map +0 -1
  41. package/dist/cjs/auth/verifiers/secretKeyVerifier.js +0 -43
  42. package/dist/cjs/auth/verifiers/sha1Verifier.d.ts +0 -17
  43. package/dist/cjs/auth/verifiers/sha1Verifier.d.ts.map +0 -1
  44. package/dist/cjs/auth/verifiers/sha1Verifier.js +0 -85
  45. package/dist/cjs/auth/verifiers/sha256Verifier.d.ts +0 -17
  46. package/dist/cjs/auth/verifiers/sha256Verifier.d.ts.map +0 -1
  47. package/dist/cjs/auth/verifiers/sha256Verifier.js +0 -85
  48. package/dist/cjs/auth/verifiers/skipVerifier.d.ts +0 -11
  49. package/dist/cjs/auth/verifiers/skipVerifier.d.ts.map +0 -1
  50. package/dist/cjs/auth/verifiers/skipVerifier.js +0 -40
  51. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts +0 -14
  52. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts.map +0 -1
  53. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.js +0 -86
  54. package/dist/cjs/bins/cedar.d.ts +0 -9
  55. package/dist/cjs/bins/cedar.d.ts.map +0 -1
  56. package/dist/cjs/bins/cedar.js +0 -36
  57. package/dist/cjs/bins/cfw.d.ts +0 -3
  58. package/dist/cjs/bins/cfw.d.ts.map +0 -1
  59. package/dist/cjs/bins/cfw.js +0 -36
  60. package/dist/cjs/bins/redwood.d.ts +0 -9
  61. package/dist/cjs/bins/redwood.d.ts.map +0 -1
  62. package/dist/cjs/bins/redwood.js +0 -36
  63. package/dist/cjs/bins/tsc.d.ts +0 -3
  64. package/dist/cjs/bins/tsc.d.ts.map +0 -1
  65. package/dist/cjs/bins/tsc.js +0 -30
  66. package/dist/cjs/cache/clients/BaseClient.d.ts +0 -11
  67. package/dist/cjs/cache/clients/BaseClient.d.ts.map +0 -1
  68. package/dist/cjs/cache/clients/BaseClient.js +0 -31
  69. package/dist/cjs/cache/clients/InMemoryClient.d.ts +0 -31
  70. package/dist/cjs/cache/clients/InMemoryClient.d.ts.map +0 -1
  71. package/dist/cjs/cache/clients/InMemoryClient.js +0 -94
  72. package/dist/cjs/cache/clients/MemcachedClient.d.ts +0 -16
  73. package/dist/cjs/cache/clients/MemcachedClient.d.ts.map +0 -1
  74. package/dist/cjs/cache/clients/MemcachedClient.js +0 -79
  75. package/dist/cjs/cache/clients/RedisClient.d.ts +0 -20
  76. package/dist/cjs/cache/clients/RedisClient.d.ts.map +0 -1
  77. package/dist/cjs/cache/clients/RedisClient.js +0 -83
  78. package/dist/cjs/cache/errors.d.ts +0 -4
  79. package/dist/cjs/cache/errors.d.ts.map +0 -1
  80. package/dist/cjs/cache/errors.js +0 -33
  81. package/dist/cjs/cache/index.d.ts +0 -35
  82. package/dist/cjs/cache/index.d.ts.map +0 -1
  83. package/dist/cjs/cache/index.js +0 -165
  84. package/dist/cjs/cors.d.ts +0 -16
  85. package/dist/cjs/cors.d.ts.map +0 -1
  86. package/dist/cjs/cors.js +0 -93
  87. package/dist/cjs/errors.d.ts +0 -5
  88. package/dist/cjs/errors.d.ts.map +0 -1
  89. package/dist/cjs/errors.js +0 -38
  90. package/dist/cjs/event.d.ts +0 -3
  91. package/dist/cjs/event.d.ts.map +0 -1
  92. package/dist/cjs/event.js +0 -34
  93. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts +0 -4
  94. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts.map +0 -1
  95. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.js +0 -72
  96. package/dist/cjs/index.d.ts +0 -15
  97. package/dist/cjs/index.d.ts.map +0 -1
  98. package/dist/cjs/index.js +0 -54
  99. package/dist/cjs/logger/index.d.ts +0 -179
  100. package/dist/cjs/logger/index.d.ts.map +0 -1
  101. package/dist/cjs/logger/index.js +0 -185
  102. package/dist/cjs/package.json +0 -1
  103. package/dist/cjs/runtime.d.ts +0 -68
  104. package/dist/cjs/runtime.d.ts.map +0 -1
  105. package/dist/cjs/runtime.js +0 -200
  106. package/dist/cjs/transforms.d.ts +0 -36
  107. package/dist/cjs/transforms.d.ts.map +0 -1
  108. package/dist/cjs/transforms.js +0 -176
  109. package/dist/cjs/types.d.ts +0 -25
  110. package/dist/cjs/types.d.ts.map +0 -1
  111. package/dist/cjs/types.js +0 -16
  112. package/dist/cjs/validations/errors.d.ts +0 -101
  113. package/dist/cjs/validations/errors.d.ts.map +0 -1
  114. package/dist/cjs/validations/errors.js +0 -298
  115. package/dist/cjs/validations/validations.d.ts +0 -235
  116. package/dist/cjs/validations/validations.d.ts.map +0 -1
  117. package/dist/cjs/validations/validations.js +0 -353
  118. package/dist/cjs/webhooks/index.d.ts +0 -77
  119. package/dist/cjs/webhooks/index.d.ts.map +0 -1
  120. package/dist/cjs/webhooks/index.js +0 -102
@@ -1,185 +0,0 @@
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 logger_exports = {};
20
- __export(logger_exports, {
21
- createLogger: () => createLogger,
22
- defaultLogLevels: () => defaultLogLevels,
23
- defaultLoggerOptions: () => defaultLoggerOptions,
24
- emitLogLevels: () => emitLogLevels,
25
- handlePrismaLogging: () => handlePrismaLogging,
26
- isDevelopment: () => isDevelopment,
27
- isProduction: () => isProduction,
28
- isTest: () => isTest,
29
- logLevel: () => logLevel,
30
- redactionsList: () => redactionsList
31
- });
32
- module.exports = __toCommonJS(logger_exports);
33
- var import_pino = require("pino");
34
- const isDevelopment = process.env.NODE_ENV === "development";
35
- const isTest = process.env.NODE_ENV === "test";
36
- const isProduction = !isDevelopment && !isTest;
37
- const redactionsList = [
38
- "access_token",
39
- "data.access_token",
40
- "data.*.access_token",
41
- "data.*.accessToken",
42
- "accessToken",
43
- "data.accessToken",
44
- "DATABASE_URL",
45
- "data.*.email",
46
- "data.email",
47
- "email",
48
- "event.headers.authorization",
49
- "data.hashedPassword",
50
- "data.*.hashedPassword",
51
- "hashedPassword",
52
- "host",
53
- "jwt",
54
- "data.jwt",
55
- "data.*.jwt",
56
- "JWT",
57
- "data.JWT",
58
- "data.*.JWT",
59
- "password",
60
- "data.password",
61
- "data.*.password",
62
- "params",
63
- "data.salt",
64
- "data.*.salt",
65
- "salt",
66
- "secret",
67
- "data.secret",
68
- "data.*.secret"
69
- ];
70
- const logLevel = (() => {
71
- if (typeof process.env.LOG_LEVEL !== "undefined") {
72
- return process.env.LOG_LEVEL;
73
- } else if (isProduction) {
74
- return "warn";
75
- } else if (isTest) {
76
- return "silent";
77
- } else {
78
- return "trace";
79
- }
80
- })();
81
- const defaultLoggerOptions = {
82
- level: logLevel,
83
- redact: redactionsList
84
- };
85
- const createLogger = ({
86
- options,
87
- destination,
88
- showConfig = false
89
- }) => {
90
- const hasDestination = typeof destination !== "undefined";
91
- const isFile = hasDestination && typeof destination === "string";
92
- const isStream = hasDestination && !isFile;
93
- const stream = destination;
94
- options = { ...defaultLoggerOptions, ...options };
95
- if (showConfig) {
96
- console.log("Logger Configuration");
97
- console.log(`isProduction: ${isProduction}`);
98
- console.log(`isDevelopment: ${isDevelopment}`);
99
- console.log(`isTest: ${isTest}`);
100
- console.log(`isFile: ${isFile}`);
101
- console.log(`isStream: ${isStream}`);
102
- console.log(`logLevel: ${logLevel}`);
103
- console.log(`options: ${JSON.stringify(options, null, 2)}`);
104
- console.log(`destination: ${destination}`);
105
- }
106
- if (isFile) {
107
- if (isProduction) {
108
- console.warn(
109
- "Please make certain that file system access is available when logging to a file in a production environment."
110
- );
111
- }
112
- return (0, import_pino.pino)(options, stream);
113
- } else {
114
- if (isStream && isDevelopment && !isTest) {
115
- console.warn(
116
- "Logs will be sent to the transport stream in the current development environment."
117
- );
118
- }
119
- return (0, import_pino.pino)(options, stream);
120
- }
121
- };
122
- const DEFAULT_SLOW_QUERY_THRESHOLD = 2e3;
123
- const defaultLogLevels = ["info", "warn", "error"];
124
- const emitLogLevels = (setLogLevels) => {
125
- return setLogLevels?.map((level) => {
126
- return { emit: "event", level };
127
- });
128
- };
129
- const handlePrismaLogging = (config) => {
130
- const logger = config.logger.child({
131
- // @TODO Change this once this issue is resolved
132
- // See https://github.com/prisma/prisma/issues/8290
133
- prisma: { clientVersion: config.db["_clientVersion"] }
134
- });
135
- const slowQueryThreshold = config.slowQueryThreshold ?? DEFAULT_SLOW_QUERY_THRESHOLD;
136
- config.logLevels?.forEach((level) => {
137
- if (level === "query") {
138
- config.db.$on(level, (event) => {
139
- const queryEvent = event;
140
- if (queryEvent.duration >= slowQueryThreshold) {
141
- logger.warn(
142
- { ...queryEvent },
143
- `Slow Query performed in ${queryEvent.duration} msec`
144
- );
145
- } else {
146
- logger.debug(
147
- { ...queryEvent },
148
- `Query performed in ${queryEvent.duration} msec`
149
- );
150
- }
151
- });
152
- } else {
153
- config.db.$on(level, (event) => {
154
- const logEvent = event;
155
- switch (level) {
156
- case "info":
157
- logger.info({ ...logEvent }, logEvent.message);
158
- break;
159
- case "warn":
160
- logger.warn({ ...logEvent }, logEvent.message);
161
- break;
162
- case "error":
163
- logger.error({ ...logEvent }, logEvent.message);
164
- break;
165
- default:
166
- logger.info({ ...logEvent }, logEvent.message);
167
- }
168
- });
169
- }
170
- });
171
- return;
172
- };
173
- // Annotate the CommonJS export names for ESM import in node:
174
- 0 && (module.exports = {
175
- createLogger,
176
- defaultLogLevels,
177
- defaultLoggerOptions,
178
- emitLogLevels,
179
- handlePrismaLogging,
180
- isDevelopment,
181
- isProduction,
182
- isTest,
183
- logLevel,
184
- redactionsList
185
- });
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1,68 +0,0 @@
1
- import type { APIGatewayProxyEvent, APIGatewayProxyResult, Context as LambdaContext } from 'aws-lambda';
2
- import { getAuthenticationContext } from './auth/index.js';
3
- import type { Decoder } from './auth/index.js';
4
- /**
5
- * A decoder that decodes nothing.
6
- *
7
- * Resolving `serverAuthState` has to happen before the GraphQL server reads
8
- * the request body:
9
- *
10
- * 1. Resolving it materialises the request body — `getAuthenticationContext`
11
- * builds a Lambda-style event via `requestToBaseEvent`, which does
12
- * `request.clone().text()`
13
- * 2. `clone()` only works while the body is untouched
14
- * 3. So once the GraphQL server has read the body, resolving throws
15
- * `TypeError: unusable`
16
- *
17
- * `buildCedarContext` only resolves auth state when it's given a decoder, so
18
- * GraphQL call sites pass this one for projects that have no auth set up, to
19
- * keep the resolve eager. Resolving with it produces the same payload as
20
- * resolving with no decoders at all.
21
- *
22
- * (When it isn't resolved eagerly, `useRedwoodAuthContext` resolves it during
23
- * context building instead — too late. That's how this surfaces.)
24
- *
25
- * TODO: Remove this once the request body is captured at the entry point rather
26
- * than read lazily from the auth path, which drops the ordering constraint.
27
- */
28
- export declare const noopAuthDecoder: Decoder;
29
- export interface CedarRequestContext {
30
- params: Record<string, string>;
31
- query: URLSearchParams;
32
- cookies: ReadonlyMap<string, string>;
33
- serverAuthState?: Awaited<ReturnType<typeof getAuthenticationContext>>;
34
- }
35
- export type CedarHandler = (request: Request, ctx: CedarRequestContext) => Promise<Response> | Response;
36
- export type CedarMiddleware = (request: Request, ctx: CedarRequestContext, next: () => Promise<Response>) => Promise<Response>;
37
- export interface CedarRouteRecord {
38
- /**
39
- * Unique identifier for this route, typically the URL path (e.g. `/graphql`).
40
- * Used to derive the UD `EntryMeta.id`.
41
- */
42
- id: string;
43
- path: string;
44
- methods: string[];
45
- type: 'graphql' | 'auth' | 'function' | 'health';
46
- entry: string;
47
- }
48
- export interface BuildCedarContextOptions {
49
- params?: Record<string, string>;
50
- authDecoder?: Parameters<typeof getAuthenticationContext>[0]['authDecoder'];
51
- lambdaContext?: LambdaContext;
52
- }
53
- export interface LegacyHandlerContext {
54
- event: APIGatewayProxyEvent;
55
- context: LambdaContext;
56
- request: Request;
57
- cedarContext: CedarRequestContext;
58
- }
59
- export type LegacyHandlerResult = APIGatewayProxyResult | Response;
60
- export type LegacyHandler = (event: APIGatewayProxyEvent, context: LambdaContext) => Promise<LegacyHandlerResult> | LegacyHandlerResult;
61
- export declare function buildCedarContext(request: Request, options?: BuildCedarContextOptions): Promise<CedarRequestContext>;
62
- export declare function composeCedarMiddleware(handler: CedarHandler, middleware: CedarMiddleware[]): CedarHandler;
63
- export declare function createRouteManifest(routes: CedarRouteRecord[]): CedarRouteRecord[];
64
- export declare function routeManifestToJSON(routes: CedarRouteRecord[]): string;
65
- export declare function wrapLegacyHandler(legacyHandler: LegacyHandler, options?: BuildCedarContextOptions): CedarHandler;
66
- export declare function requestToLegacyEvent(request: Request, ctx: CedarRequestContext): Promise<APIGatewayProxyEvent>;
67
- export declare function legacyResultToResponse(result: LegacyHandlerResult): Response;
68
- //# sourceMappingURL=runtime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EAEpB,qBAAqB,EACrB,OAAO,IAAI,aAAa,EACzB,MAAM,YAAY,CAAA;AAInB,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAG9C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,eAAe,EAAE,OAA0B,CAAA;AAExD,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9B,KAAK,EAAE,eAAe,CAAA;IACtB,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC,eAAe,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAA;CACvE;AAED,MAAM,MAAM,YAAY,GAAG,CACzB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,mBAAmB,KACrB,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAA;AAEjC,MAAM,MAAM,eAAe,GAAG,CAC5B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,mBAAmB,EACxB,IAAI,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,KAC1B,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEtB,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,CAAA;IAChD,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,WAAW,CAAC,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAA;IAC3E,aAAa,CAAC,EAAE,aAAa,CAAA;CAC9B;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,oBAAoB,CAAA;IAC3B,OAAO,EAAE,aAAa,CAAA;IACtB,OAAO,EAAE,OAAO,CAAA;IAChB,YAAY,EAAE,mBAAmB,CAAA;CAClC;AAED,MAAM,MAAM,mBAAmB,GAAG,qBAAqB,GAAG,QAAQ,CAAA;AAElE,MAAM,MAAM,aAAa,GAAG,CAC1B,KAAK,EAAE,oBAAoB,EAC3B,OAAO,EAAE,aAAa,KACnB,OAAO,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,CAAA;AAmCvD,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,mBAAmB,CAAC,CAiC9B;AAED,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,eAAe,EAAE,GAC5B,YAAY,CAMd;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,gBAAgB,EAAE,GACzB,gBAAgB,EAAE,CAOpB;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAEtE;AAED,wBAAgB,iBAAiB,CAC/B,aAAa,EAAE,aAAa,EAC5B,OAAO,GAAE,wBAA6B,GACrC,YAAY,CAQd;AAED,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,oBAAoB,CAAC,CAqB/B;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,mBAAmB,GAAG,QAAQ,CAsD5E"}
@@ -1,200 +0,0 @@
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 runtime_exports = {};
30
- __export(runtime_exports, {
31
- buildCedarContext: () => buildCedarContext,
32
- composeCedarMiddleware: () => composeCedarMiddleware,
33
- createRouteManifest: () => createRouteManifest,
34
- legacyResultToResponse: () => legacyResultToResponse,
35
- noopAuthDecoder: () => noopAuthDecoder,
36
- requestToLegacyEvent: () => requestToLegacyEvent,
37
- routeManifestToJSON: () => routeManifestToJSON,
38
- wrapLegacyHandler: () => wrapLegacyHandler
39
- });
40
- module.exports = __toCommonJS(runtime_exports);
41
- var cookie = __toESM(require("cookie"), 1);
42
- var import_picoquery = require("picoquery");
43
- var import_auth = require("./auth/index.js");
44
- var import_transforms = require("./transforms.js");
45
- const noopAuthDecoder = async () => null;
46
- const DEFAULT_LAMBDA_CONTEXT = {
47
- callbackWaitsForEmptyEventLoop: false,
48
- functionName: "cedar",
49
- functionVersion: "$LATEST",
50
- invokedFunctionArn: "cedar",
51
- memoryLimitInMB: "0",
52
- awsRequestId: "cedar-request",
53
- logGroupName: "cedar",
54
- logStreamName: "cedar",
55
- getRemainingTimeInMillis() {
56
- return 0;
57
- },
58
- done() {
59
- return void 0;
60
- },
61
- fail() {
62
- return void 0;
63
- },
64
- succeed() {
65
- return void 0;
66
- }
67
- };
68
- function hasAuthDecoder(authDecoder) {
69
- if (Array.isArray(authDecoder)) {
70
- return authDecoder.length > 0;
71
- }
72
- return !!authDecoder;
73
- }
74
- async function buildCedarContext(request, options = {}) {
75
- const url = new URL(request.url);
76
- const query = url.searchParams;
77
- const cookies = new Map(
78
- Object.entries(cookie.parse(request.headers.get("cookie") ?? "")).filter(
79
- (entry) => {
80
- return entry[1] !== void 0;
81
- }
82
- )
83
- );
84
- const params = options.params ?? {};
85
- const serverAuthState = hasAuthDecoder(options.authDecoder) ? await (0, import_auth.getAuthenticationContext)({
86
- authDecoder: options.authDecoder,
87
- event: request,
88
- context: options.lambdaContext
89
- }) : void 0;
90
- return {
91
- params,
92
- query,
93
- cookies,
94
- serverAuthState
95
- };
96
- }
97
- function composeCedarMiddleware(handler, middleware) {
98
- return middleware.reduceRight((next, current) => {
99
- return (request, ctx) => {
100
- return current(request, ctx, async () => next(request, ctx));
101
- };
102
- }, handler);
103
- }
104
- function createRouteManifest(routes) {
105
- return routes.map((route) => {
106
- return {
107
- ...route,
108
- methods: [...route.methods]
109
- };
110
- });
111
- }
112
- function routeManifestToJSON(routes) {
113
- return JSON.stringify(createRouteManifest(routes), null, 2);
114
- }
115
- function wrapLegacyHandler(legacyHandler, options = {}) {
116
- return async (request, ctx) => {
117
- const lambdaContext = options.lambdaContext ?? DEFAULT_LAMBDA_CONTEXT;
118
- const event = await requestToLegacyEvent(request, ctx);
119
- const result = await legacyHandler(event, lambdaContext);
120
- return legacyResultToResponse(result);
121
- };
122
- }
123
- async function requestToLegacyEvent(request, ctx) {
124
- const url = new URL(request.url);
125
- const base = await (0, import_transforms.requestToBaseEvent)(request);
126
- const queryStringParameters = (0, import_picoquery.parse)(url.search ? url.search.slice(1) : "", {
127
- nestingSyntax: "index",
128
- arrayRepeat: true,
129
- arrayRepeatSyntax: "bracket"
130
- });
131
- return {
132
- ...base,
133
- queryStringParameters,
134
- multiValueQueryStringParameters: toMultiValueQueryStringParameters(url),
135
- pathParameters: Object.keys(ctx.params).length > 0 ? ctx.params : base.pathParameters
136
- };
137
- }
138
- function legacyResultToResponse(result) {
139
- if (result instanceof Response) {
140
- return result;
141
- }
142
- const headers = new Headers();
143
- if (result.headers) {
144
- for (const [name, value] of Object.entries(result.headers)) {
145
- if (Array.isArray(value)) {
146
- for (const item of value) {
147
- headers.append(name, item);
148
- }
149
- } else if (value !== void 0) {
150
- headers.set(name, String(value));
151
- }
152
- }
153
- }
154
- if (result.multiValueHeaders) {
155
- for (const [name, values] of Object.entries(result.multiValueHeaders)) {
156
- if (!values) {
157
- continue;
158
- }
159
- for (const value of values) {
160
- headers.append(name, String(value));
161
- }
162
- }
163
- }
164
- const status = result.statusCode ?? 200;
165
- const isNoBodyStatus = status === 204 || status === 205 || status === 304;
166
- const body = isNoBodyStatus ? null : result.body ?? "";
167
- if (result.isBase64Encoded && !isNoBodyStatus) {
168
- return new Response(Buffer.from(body || "", "base64"), {
169
- status,
170
- headers
171
- });
172
- }
173
- return new Response(body, {
174
- status,
175
- headers
176
- });
177
- }
178
- function toMultiValueQueryStringParameters(url) {
179
- const values = /* @__PURE__ */ new Map();
180
- for (const [name, value] of url.searchParams.entries()) {
181
- const existing = values.get(name) ?? [];
182
- existing.push(value);
183
- values.set(name, existing);
184
- }
185
- if (values.size === 0) {
186
- return null;
187
- }
188
- return Object.fromEntries(values.entries());
189
- }
190
- // Annotate the CommonJS export names for ESM import in node:
191
- 0 && (module.exports = {
192
- buildCedarContext,
193
- composeCedarMiddleware,
194
- createRouteManifest,
195
- legacyResultToResponse,
196
- noopAuthDecoder,
197
- requestToLegacyEvent,
198
- routeManifestToJSON,
199
- wrapLegacyHandler
200
- });
@@ -1,36 +0,0 @@
1
- import type { APIGatewayProxyEvent } from 'aws-lambda';
2
- export interface PartialRequest<TBody = Record<string, any>> {
3
- jsonBody: TBody;
4
- headers: Headers;
5
- method: string;
6
- query: any;
7
- }
8
- /**
9
- * Extracts and parses body payload from event with base64 encoding check
10
- */
11
- export declare const parseLambdaEventBody: (event: APIGatewayProxyEvent) => any;
12
- /**
13
- * Extracts and parses body payload from Fetch Request
14
- * with check for empty body
15
- *
16
- * NOTE: whatwg/server expects that you will decode the base64 body yourself
17
- * see readme here: https://github.com/ardatan/whatwg-node/tree/master/packages/server#aws-lambda
18
- */
19
- export declare const parseFetchEventBody: (event: Request) => Promise<any>;
20
- export declare const requestToBaseEvent: (request: Request) => Promise<APIGatewayProxyEvent>;
21
- export declare const isFetchApiRequest: (event: Request | APIGatewayProxyEvent) => event is Request;
22
- /**
23
- *
24
- * This function returns a an object that lets you access _some_ of the request properties in a consistent way
25
- * You can give it either a LambdaEvent or a Fetch API Request
26
- *
27
- * NOTE: It does NOT return a full Request object!
28
- */
29
- export declare function normalizeRequest(event: APIGatewayProxyEvent | Request): Promise<PartialRequest>;
30
- /**
31
- * Useful for removing nulls from an object, such as an input from a GraphQL mutation used directly in a Prisma query
32
- * @param input - Object to remove nulls from
33
- * See {@link https://www.prisma.io/docs/concepts/components/prisma-client/null-and-undefined Prisma docs: null vs undefined}
34
- */
35
- export declare const removeNulls: (input: Record<number | symbol | string, any>) => Record<string | number | symbol, any>;
36
- //# sourceMappingURL=transforms.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transforms.d.ts","sourceRoot":"","sources":["../../src/transforms.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAKtD,MAAM,WAAW,cAAc,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IACzD,QAAQ,EAAE,KAAK,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,GAAG,CAAA;CACX;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,oBAAoB,QAU/D,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAU,OAAO,OAAO,iBAQvD,CAAA;AAED,eAAO,MAAM,kBAAkB,GAC7B,SAAS,OAAO,KACf,OAAO,CAAC,oBAAoB,CAsD9B,CAAA;AAoCD,eAAO,MAAM,iBAAiB,GAC5B,OAAO,OAAO,GAAG,oBAAoB,KACpC,KAAK,IAAI,OAcX,CAAA;AAaD;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,oBAAoB,GAAG,OAAO,GACpC,OAAO,CAAC,cAAc,CAAC,CAkBzB;AAID;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,0CAcvE,CAAA"}
@@ -1,176 +0,0 @@
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 transforms_exports = {};
20
- __export(transforms_exports, {
21
- isFetchApiRequest: () => isFetchApiRequest,
22
- normalizeRequest: () => normalizeRequest,
23
- parseFetchEventBody: () => parseFetchEventBody,
24
- parseLambdaEventBody: () => parseLambdaEventBody,
25
- removeNulls: () => removeNulls,
26
- requestToBaseEvent: () => requestToBaseEvent
27
- });
28
- module.exports = __toCommonJS(transforms_exports);
29
- var import_fetch = require("@whatwg-node/fetch");
30
- const parseLambdaEventBody = (event) => {
31
- if (!event.body) {
32
- return {};
33
- }
34
- if (event.isBase64Encoded) {
35
- return JSON.parse(Buffer.from(event.body, "base64").toString("utf-8"));
36
- } else {
37
- return JSON.parse(event.body);
38
- }
39
- };
40
- const parseFetchEventBody = async (event) => {
41
- if (!event.body) {
42
- return {};
43
- }
44
- const body = await event.text();
45
- return body ? JSON.parse(body) : {};
46
- };
47
- const requestToBaseEvent = async (request) => {
48
- const url = new URL(request.url);
49
- const bodyText = await request.clone().text();
50
- const queryStringParameters = {};
51
- url.searchParams.forEach((value, key) => {
52
- queryStringParameters[key] = value;
53
- });
54
- const event = {
55
- headers: Object.fromEntries(request.headers.entries()),
56
- body: bodyText || null,
57
- httpMethod: request.method,
58
- path: url.pathname,
59
- queryStringParameters,
60
- isBase64Encoded: false,
61
- multiValueHeaders: toMultiValueHeaders(request.headers),
62
- multiValueQueryStringParameters: toMultiValueQueryStringParameters(url),
63
- pathParameters: null,
64
- stageVariables: null,
65
- resource: url.pathname,
66
- requestContext: {
67
- accountId: "cedar",
68
- apiId: "cedar",
69
- authorizer: void 0,
70
- protocol: "HTTP/1.1",
71
- identity: {
72
- accessKey: null,
73
- accountId: null,
74
- apiKey: null,
75
- apiKeyId: null,
76
- caller: null,
77
- clientCert: null,
78
- cognitoAuthenticationProvider: null,
79
- cognitoAuthenticationType: null,
80
- cognitoIdentityId: null,
81
- cognitoIdentityPoolId: null,
82
- principalOrgId: null,
83
- sourceIp: "",
84
- user: null,
85
- userAgent: request.headers.get("user-agent"),
86
- userArn: null
87
- },
88
- path: url.pathname,
89
- stage: "",
90
- requestId: "cedar-request",
91
- requestTimeEpoch: Date.now(),
92
- resourceId: "cedar",
93
- resourcePath: url.pathname,
94
- httpMethod: request.method
95
- }
96
- };
97
- return event;
98
- };
99
- function toMultiValueHeaders(headers) {
100
- const values = /* @__PURE__ */ new Map();
101
- for (const [name, value] of headers.entries()) {
102
- const existing = values.get(name) ?? [];
103
- existing.push(value);
104
- values.set(name, existing);
105
- }
106
- if (values.size === 0) {
107
- return {};
108
- }
109
- return Object.fromEntries(values.entries());
110
- }
111
- function toMultiValueQueryStringParameters(url) {
112
- const values = /* @__PURE__ */ new Map();
113
- for (const [name, value] of url.searchParams.entries()) {
114
- const existing = values.get(name) ?? [];
115
- existing.push(value);
116
- values.set(name, existing);
117
- }
118
- if (values.size === 0) {
119
- return null;
120
- }
121
- return Object.fromEntries(values.entries());
122
- }
123
- const isFetchApiRequest = (event) => {
124
- if (event.constructor.name === "Request" || event.constructor.name === import_fetch.Request.name) {
125
- return true;
126
- }
127
- if (Symbol.iterator in Object(event.headers)) {
128
- return true;
129
- }
130
- return false;
131
- };
132
- function getQueryStringParams(reqUrl) {
133
- const url = new URL(reqUrl);
134
- const params = new URLSearchParams(url.search);
135
- const paramObject = {};
136
- for (const entry of params.entries()) {
137
- paramObject[entry[0]] = entry[1];
138
- }
139
- return paramObject;
140
- }
141
- async function normalizeRequest(event) {
142
- if (isFetchApiRequest(event)) {
143
- return {
144
- headers: event.headers,
145
- method: event.method,
146
- query: getQueryStringParams(event.url),
147
- jsonBody: await parseFetchEventBody(event)
148
- };
149
- }
150
- const jsonBody = parseLambdaEventBody(event);
151
- return {
152
- headers: new import_fetch.Headers(event.headers),
153
- method: event.httpMethod,
154
- query: event.queryStringParameters,
155
- jsonBody
156
- };
157
- }
158
- const removeNulls = (input) => {
159
- for (const key in input) {
160
- if (input[key] === null) {
161
- input[key] = void 0;
162
- } else if (typeof input[key] === "object" && !(input[key] instanceof Date)) {
163
- input[key] = removeNulls(input[key]);
164
- }
165
- }
166
- return input;
167
- };
168
- // Annotate the CommonJS export names for ESM import in node:
169
- 0 && (module.exports = {
170
- isFetchApiRequest,
171
- normalizeRequest,
172
- parseFetchEventBody,
173
- parseLambdaEventBody,
174
- removeNulls,
175
- requestToBaseEvent
176
- });