@cedarjs/api 5.0.7-next.336 → 5.0.7-rc.3

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 +0 -9
  2. package/dist/auth/index.d.ts.map +1 -1
  3. package/dist/auth/index.js +0 -7
  4. package/dist/cjs/auth/index.d.ts +64 -0
  5. package/dist/cjs/auth/index.d.ts.map +1 -0
  6. package/dist/cjs/auth/index.js +143 -0
  7. package/dist/cjs/auth/parseJWT.d.ts +6 -0
  8. package/dist/cjs/auth/parseJWT.d.ts.map +1 -0
  9. package/dist/cjs/auth/parseJWT.js +57 -0
  10. package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts +18 -0
  11. package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts.map +1 -0
  12. package/dist/cjs/auth/verifiers/base64Sha1Verifier.js +77 -0
  13. package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts +18 -0
  14. package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts.map +1 -0
  15. package/dist/cjs/auth/verifiers/base64Sha256Verifier.js +77 -0
  16. package/dist/cjs/auth/verifiers/common.d.ts +112 -0
  17. package/dist/cjs/auth/verifiers/common.d.ts.map +1 -0
  18. package/dist/cjs/auth/verifiers/common.js +89 -0
  19. package/dist/cjs/auth/verifiers/index.d.ts +8 -0
  20. package/dist/cjs/auth/verifiers/index.d.ts.map +1 -0
  21. package/dist/cjs/auth/verifiers/index.js +39 -0
  22. package/dist/cjs/auth/verifiers/jwtVerifier.d.ts +18 -0
  23. package/dist/cjs/auth/verifiers/jwtVerifier.d.ts.map +1 -0
  24. package/dist/cjs/auth/verifiers/jwtVerifier.js +84 -0
  25. package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts +11 -0
  26. package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts.map +1 -0
  27. package/dist/cjs/auth/verifiers/secretKeyVerifier.js +43 -0
  28. package/dist/cjs/auth/verifiers/sha1Verifier.d.ts +17 -0
  29. package/dist/cjs/auth/verifiers/sha1Verifier.d.ts.map +1 -0
  30. package/dist/cjs/auth/verifiers/sha1Verifier.js +85 -0
  31. package/dist/cjs/auth/verifiers/sha256Verifier.d.ts +17 -0
  32. package/dist/cjs/auth/verifiers/sha256Verifier.d.ts.map +1 -0
  33. package/dist/cjs/auth/verifiers/sha256Verifier.js +85 -0
  34. package/dist/cjs/auth/verifiers/skipVerifier.d.ts +11 -0
  35. package/dist/cjs/auth/verifiers/skipVerifier.d.ts.map +1 -0
  36. package/dist/cjs/auth/verifiers/skipVerifier.js +40 -0
  37. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts +14 -0
  38. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts.map +1 -0
  39. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.js +86 -0
  40. package/dist/cjs/bins/cedar.d.ts +9 -0
  41. package/dist/cjs/bins/cedar.d.ts.map +1 -0
  42. package/dist/cjs/bins/cedar.js +36 -0
  43. package/dist/cjs/bins/cfw.d.ts +3 -0
  44. package/dist/cjs/bins/cfw.d.ts.map +1 -0
  45. package/dist/cjs/bins/cfw.js +36 -0
  46. package/dist/cjs/bins/redwood.d.ts +9 -0
  47. package/dist/cjs/bins/redwood.d.ts.map +1 -0
  48. package/dist/cjs/bins/redwood.js +36 -0
  49. package/dist/cjs/bins/tsc.d.ts +3 -0
  50. package/dist/cjs/bins/tsc.d.ts.map +1 -0
  51. package/dist/cjs/bins/tsc.js +30 -0
  52. package/dist/cjs/cache/clients/BaseClient.d.ts +11 -0
  53. package/dist/cjs/cache/clients/BaseClient.d.ts.map +1 -0
  54. package/dist/cjs/cache/clients/BaseClient.js +31 -0
  55. package/dist/cjs/cache/clients/InMemoryClient.d.ts +31 -0
  56. package/dist/cjs/cache/clients/InMemoryClient.d.ts.map +1 -0
  57. package/dist/cjs/cache/clients/InMemoryClient.js +94 -0
  58. package/dist/cjs/cache/clients/MemcachedClient.d.ts +16 -0
  59. package/dist/cjs/cache/clients/MemcachedClient.d.ts.map +1 -0
  60. package/dist/cjs/cache/clients/MemcachedClient.js +79 -0
  61. package/dist/cjs/cache/clients/RedisClient.d.ts +20 -0
  62. package/dist/cjs/cache/clients/RedisClient.d.ts.map +1 -0
  63. package/dist/cjs/cache/clients/RedisClient.js +83 -0
  64. package/dist/cjs/cache/errors.d.ts +4 -0
  65. package/dist/cjs/cache/errors.d.ts.map +1 -0
  66. package/dist/cjs/cache/errors.js +33 -0
  67. package/dist/cjs/cache/index.d.ts +35 -0
  68. package/dist/cjs/cache/index.d.ts.map +1 -0
  69. package/dist/cjs/cache/index.js +165 -0
  70. package/dist/cjs/cors.d.ts +16 -0
  71. package/dist/cjs/cors.d.ts.map +1 -0
  72. package/dist/cjs/cors.js +93 -0
  73. package/dist/cjs/errors.d.ts +5 -0
  74. package/dist/cjs/errors.d.ts.map +1 -0
  75. package/dist/cjs/errors.js +38 -0
  76. package/dist/cjs/event.d.ts +3 -0
  77. package/dist/cjs/event.d.ts.map +1 -0
  78. package/dist/cjs/event.js +34 -0
  79. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts +4 -0
  80. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts.map +1 -0
  81. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.js +72 -0
  82. package/dist/cjs/index.d.ts +15 -0
  83. package/dist/cjs/index.d.ts.map +1 -0
  84. package/dist/cjs/index.js +54 -0
  85. package/dist/cjs/logger/index.d.ts +179 -0
  86. package/dist/cjs/logger/index.d.ts.map +1 -0
  87. package/dist/cjs/logger/index.js +185 -0
  88. package/dist/cjs/package.json +1 -0
  89. package/dist/cjs/runtime.d.ts +68 -0
  90. package/dist/cjs/runtime.d.ts.map +1 -0
  91. package/dist/cjs/runtime.js +200 -0
  92. package/dist/cjs/transforms.d.ts +36 -0
  93. package/dist/cjs/transforms.d.ts.map +1 -0
  94. package/dist/cjs/transforms.js +176 -0
  95. package/dist/cjs/types.d.ts +25 -0
  96. package/dist/cjs/types.d.ts.map +1 -0
  97. package/dist/cjs/types.js +16 -0
  98. package/dist/cjs/validations/errors.d.ts +101 -0
  99. package/dist/cjs/validations/errors.d.ts.map +1 -0
  100. package/dist/cjs/validations/errors.js +298 -0
  101. package/dist/cjs/validations/validations.d.ts +235 -0
  102. package/dist/cjs/validations/validations.d.ts.map +1 -0
  103. package/dist/cjs/validations/validations.js +353 -0
  104. package/dist/cjs/webhooks/index.d.ts +77 -0
  105. package/dist/cjs/webhooks/index.d.ts.map +1 -0
  106. package/dist/cjs/webhooks/index.js +102 -0
  107. package/dist/errors.d.ts +1 -9
  108. package/dist/errors.d.ts.map +1 -1
  109. package/dist/errors.js +2 -9
  110. package/dist/index.js +3 -3
  111. package/dist/logger/index.d.ts +5 -7
  112. package/dist/logger/index.d.ts.map +1 -1
  113. package/dist/runtime.d.ts +26 -0
  114. package/dist/runtime.d.ts.map +1 -1
  115. package/dist/runtime.js +22 -1
  116. package/package.json +41 -17
  117. package/dist/bins/cedar.js +0 -14
  118. package/dist/bins/cfw.js +0 -14
  119. package/dist/bins/redwood.js +0 -14
  120. package/dist/bins/tsc.js +0 -8
@@ -0,0 +1,179 @@
1
+ import type P from 'pino';
2
+ /**
3
+ * Types from Pino
4
+ * @see https://github.com/pinojs/pino/blob/master/pino.d.ts
5
+ */
6
+ export type Logger = P.Logger;
7
+ export type BaseLogger = P.BaseLogger;
8
+ export type DestinationStream = P.DestinationStream;
9
+ export type LevelWithSilent = P.LevelWithSilent;
10
+ export type LoggerOptions = P.LoggerOptions;
11
+ export type LogLevel = 'info' | 'query' | 'warn' | 'error';
12
+ type PrismaClient = any;
13
+ type LogDefinition = {
14
+ level: LogLevel;
15
+ emit: 'stdout' | 'event';
16
+ };
17
+ /**
18
+ * Determines if log environment is development
19
+ *
20
+ * @type {boolean}
21
+ *
22
+ */
23
+ export declare const isDevelopment: boolean;
24
+ /**
25
+ * Determines if log environment is test
26
+ *
27
+ * @type {boolean}
28
+ *
29
+ */
30
+ export declare const isTest: boolean;
31
+ /**
32
+ * Determines if log environment is production by checking if not development
33
+ *
34
+ * @type {boolean}
35
+ *
36
+ */
37
+ export declare const isProduction: boolean;
38
+ export declare const redactionsList: string[];
39
+ /**
40
+ * Determines if log level based on environment variables and
41
+ * development or deployment environment defaults
42
+ *
43
+ * Set `LOG_LEVEL` env to the desired logging level. In order of priority, available levels are:
44
+ *
45
+ * - 'fatal'
46
+ * - 'error'
47
+ * - 'warn'
48
+ * - 'info'
49
+ * - 'debug'
50
+ * - 'trace'
51
+ *
52
+ * The logging level is a __minimum__ level. For instance if `logger.level` is `'info'` then all `'fatal'`, `'error'`, `'warn'`,
53
+ * and `'info'` logs will be enabled.
54
+ *
55
+ * You can pass `'silent'` to disable logging.
56
+ *
57
+ * @default 'warn' in Production
58
+ * @default 'trace' in Development
59
+ * @default 'silent' in Test
60
+ *
61
+ */
62
+ export declare const logLevel: LevelWithSilent | string;
63
+ /**
64
+ * Defines an opinionated base logger configuration that defines
65
+ * how to log and what to ignore.
66
+ *
67
+ * @default logger options are:
68
+ *
69
+ * - Ignore certain event attributes like hostname and pid for cleaner log statements
70
+ * - Prefix the log output with log level
71
+ * - Use a shorted log message that omits server name
72
+ * - Humanize time in GMT
73
+ * - Set the default log level in test to silent, development to trace
74
+ * and warn in prod
75
+ * Or set via LOG_LEVEL environment variable
76
+ * - Redact the host and other keys via a set redactionList
77
+ *
78
+ * Each path must be a string using a syntax which corresponds to JavaScript dot and bracket notation.
79
+ *
80
+ * If an object is supplied, three options can be specified:
81
+ *
82
+ * paths (String[]): Required. An array of paths
83
+ * censor (String): Optional. A value to overwrite key which are to be redacted. Default: '[Redacted]'
84
+ * remove (Boolean): Optional. Instead of censoring the value, remove both the key and the value. Default: false
85
+ *
86
+ * @see {@link https://github.com/pinojs/pino/blob/master/docs/api.md}
87
+ */
88
+ export declare const defaultLoggerOptions: {
89
+ level: string;
90
+ redact: string[];
91
+ };
92
+ /**
93
+ * RedwoodLoggerOptions defines custom logger options that extend those available in LoggerOptions
94
+ * and can define a destination like a file or other supported pin log transport stream
95
+ *
96
+ * @typedef {Object} RedwoodLoggerOptions
97
+ * @extends LoggerOptions
98
+ * @property {options} LoggerOptions - options define how to log
99
+ * @property {string | DestinationStream} destination - destination defines where to log
100
+ * @property {boolean} showConfig - Display logger configuration on initialization
101
+ */
102
+ export interface RedwoodLoggerOptions {
103
+ options?: LoggerOptions;
104
+ destination?: string | DestinationStream;
105
+ showConfig?: boolean;
106
+ }
107
+ /**
108
+ * Creates the logger
109
+ *
110
+ * @param options {RedwoodLoggerOptions} - Override the default logger configuration
111
+ * @param destination {DestinationStream} - An optional destination stream
112
+ * @param showConfig {Boolean} - Show the logger configuration. This is off by default.
113
+ *
114
+ * @example
115
+ * // Create the logger to log just at the error level
116
+ * createLogger({ options: { level: 'error' } })
117
+ *
118
+ * @example
119
+ * // Create the logger to log to a file
120
+ * createLogger({ destination: { 'var/logs/redwood-api.log' } })
121
+ *
122
+ * @return {Logger} - The configured logger
123
+ */
124
+ export declare const createLogger: ({ options, destination, showConfig, }: RedwoodLoggerOptions) => Logger;
125
+ /**
126
+ * Determines the type and level of logging.
127
+ *
128
+ * @see {@link https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#log}
129
+ */
130
+ export declare const defaultLogLevels: LogLevel[];
131
+ /**
132
+ * Generates the Prisma Log Definitions for the Prisma Client to emit
133
+ *
134
+ * @return Prisma.LogDefinition[]
135
+ */
136
+ export declare const emitLogLevels: (setLogLevels: LogLevel[]) => LogDefinition[];
137
+ /**
138
+ * Defines what is needed to setup Prisma Client logging used in handlePrismaLogging
139
+ *
140
+ *
141
+ * @param db {PrismaClient} - The Prisma Client instance
142
+ * @param logger {BaseLogger} - The Redwood logger instance
143
+ * @param logLevels {LogLevel[]} - The log levels . Should match those set with emitLogLevels
144
+ * @param slowQueryThreshold {number} - The threshold for slow queries. Default: 2 seconds
145
+ *
146
+ * @see emitLogLevels
147
+ *
148
+ */
149
+ interface PrismaLoggingConfig {
150
+ db: PrismaClient;
151
+ logger: Logger;
152
+ logLevels: LogLevel[];
153
+ slowQueryThreshold?: number;
154
+ }
155
+ /**
156
+ * Sets up event-based logging on the Prisma client
157
+ *
158
+ * Sets emit to event for a specific log level, such as query
159
+ * using the $on() method to subscribe to the event
160
+ *
161
+ * @see {@link https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/logging}
162
+ *
163
+ * @param PrismaLoggingConfig
164
+ *
165
+ * @example
166
+ *
167
+ * handlePrismaLogging({
168
+ * db,
169
+ * logger,
170
+ * logLevels: ['info', 'warn', 'error'],
171
+ * slowQueryThreshold: 2000,
172
+ * })
173
+ *
174
+ * @return {void}
175
+ *
176
+ */
177
+ export declare const handlePrismaLogging: (config: PrismaLoggingConfig) => void;
178
+ export {};
179
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/logger/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,MAAM,CAAA;AAGzB;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAA;AAC7B,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,UAAU,CAAA;AACrC,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,iBAAiB,CAAA;AACnD,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,eAAe,CAAA;AAC/C,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,aAAa,CAAA;AAC3C,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAA;AAI1D,KAAK,YAAY,GAAG,GAAG,CAAA;AAEvB,KAAK,aAAa,GAAG;IACnB,KAAK,EAAE,QAAQ,CAAA;IACf,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAA;CACzB,CAAA;AAgBD;;;;;GAKG;AACH,eAAO,MAAM,aAAa,SAAyC,CAAA;AAEnE;;;;;GAKG;AACH,eAAO,MAAM,MAAM,SAAkC,CAAA;AAErD;;;;;GAKG;AACH,eAAO,MAAM,YAAY,SAA4B,CAAA;AAQrD,eAAO,MAAM,cAAc,EAAE,MAAM,EAgClC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,QAAQ,EAAE,eAAe,GAAG,MAUrC,CAAA;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,oBAAoB;;;CAGR,CAAA;AAEzB;;;;;;;;;GASG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAAA;IACxC,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,YAAY,GAAI,uCAI1B,oBAAoB,KAAG,MAuCzB,CAAA;AAQD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,QAAQ,EAA8B,CAAA;AAErE;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,cAAc,QAAQ,EAAE,KAAG,aAAa,EAIrE,CAAA;AAED;;;;;;;;;;;GAWG;AACH,UAAU,mBAAmB;IAC3B,EAAE,EAAE,YAAY,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,QAAQ,EAAE,CAAA;IACrB,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,mBAAmB,GAAI,QAAQ,mBAAmB,KAAG,IA8CjE,CAAA"}
@@ -0,0 +1,185 @@
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
+ });
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,68 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,200 @@
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
+ });
@@ -0,0 +1,36 @@
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
@@ -0,0 +1 @@
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"}