@cedarjs/api 0.0.4

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 (194) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +51 -0
  3. package/dist/auth/index.d.ts +51 -0
  4. package/dist/auth/index.d.ts.map +1 -0
  5. package/dist/auth/index.js +89 -0
  6. package/dist/auth/parseJWT.d.ts +6 -0
  7. package/dist/auth/parseJWT.d.ts.map +1 -0
  8. package/dist/auth/parseJWT.js +33 -0
  9. package/dist/auth/verifiers/base64Sha1Verifier.d.ts +19 -0
  10. package/dist/auth/verifiers/base64Sha1Verifier.d.ts.map +1 -0
  11. package/dist/auth/verifiers/base64Sha1Verifier.js +57 -0
  12. package/dist/auth/verifiers/base64Sha256Verifier.d.ts +19 -0
  13. package/dist/auth/verifiers/base64Sha256Verifier.d.ts.map +1 -0
  14. package/dist/auth/verifiers/base64Sha256Verifier.js +57 -0
  15. package/dist/auth/verifiers/common.d.ts +104 -0
  16. package/dist/auth/verifiers/common.d.ts.map +1 -0
  17. package/dist/auth/verifiers/common.js +59 -0
  18. package/dist/auth/verifiers/index.d.ts +8 -0
  19. package/dist/auth/verifiers/index.d.ts.map +1 -0
  20. package/dist/auth/verifiers/index.js +12 -0
  21. package/dist/auth/verifiers/jwtVerifier.d.ts +26 -0
  22. package/dist/auth/verifiers/jwtVerifier.d.ts.map +1 -0
  23. package/dist/auth/verifiers/jwtVerifier.js +55 -0
  24. package/dist/auth/verifiers/secretKeyVerifier.d.ts +14 -0
  25. package/dist/auth/verifiers/secretKeyVerifier.d.ts.map +1 -0
  26. package/dist/auth/verifiers/secretKeyVerifier.js +20 -0
  27. package/dist/auth/verifiers/sha1Verifier.d.ts +25 -0
  28. package/dist/auth/verifiers/sha1Verifier.d.ts.map +1 -0
  29. package/dist/auth/verifiers/sha1Verifier.js +65 -0
  30. package/dist/auth/verifiers/sha256Verifier.d.ts +25 -0
  31. package/dist/auth/verifiers/sha256Verifier.d.ts.map +1 -0
  32. package/dist/auth/verifiers/sha256Verifier.js +65 -0
  33. package/dist/auth/verifiers/skipVerifier.d.ts +13 -0
  34. package/dist/auth/verifiers/skipVerifier.d.ts.map +1 -0
  35. package/dist/auth/verifiers/skipVerifier.js +17 -0
  36. package/dist/auth/verifiers/timestampSchemeVerifier.d.ts +16 -0
  37. package/dist/auth/verifiers/timestampSchemeVerifier.d.ts.map +1 -0
  38. package/dist/auth/verifiers/timestampSchemeVerifier.js +65 -0
  39. package/dist/bins/redwood.d.ts +9 -0
  40. package/dist/bins/redwood.d.ts.map +1 -0
  41. package/dist/bins/rwfw.d.ts +3 -0
  42. package/dist/bins/rwfw.d.ts.map +1 -0
  43. package/dist/bins/tsc.d.ts +3 -0
  44. package/dist/bins/tsc.d.ts.map +1 -0
  45. package/dist/cache/clients/BaseClient.d.ts +11 -0
  46. package/dist/cache/clients/BaseClient.d.ts.map +1 -0
  47. package/dist/cache/clients/BaseClient.js +7 -0
  48. package/dist/cache/clients/InMemoryClient.d.ts +31 -0
  49. package/dist/cache/clients/InMemoryClient.d.ts.map +1 -0
  50. package/dist/cache/clients/InMemoryClient.js +70 -0
  51. package/dist/cache/clients/MemcachedClient.d.ts +16 -0
  52. package/dist/cache/clients/MemcachedClient.d.ts.map +1 -0
  53. package/dist/cache/clients/MemcachedClient.js +45 -0
  54. package/dist/cache/clients/RedisClient.d.ts +20 -0
  55. package/dist/cache/clients/RedisClient.d.ts.map +1 -0
  56. package/dist/cache/clients/RedisClient.js +49 -0
  57. package/dist/cache/errors.d.ts +4 -0
  58. package/dist/cache/errors.d.ts.map +1 -0
  59. package/dist/cache/errors.js +9 -0
  60. package/dist/cache/index.d.ts +35 -0
  61. package/dist/cache/index.d.ts.map +1 -0
  62. package/dist/cache/index.js +132 -0
  63. package/dist/cjs/auth/index.d.ts +51 -0
  64. package/dist/cjs/auth/index.d.ts.map +1 -0
  65. package/dist/cjs/auth/index.js +129 -0
  66. package/dist/cjs/auth/parseJWT.d.ts +6 -0
  67. package/dist/cjs/auth/parseJWT.d.ts.map +1 -0
  68. package/dist/cjs/auth/parseJWT.js +57 -0
  69. package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts +19 -0
  70. package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts.map +1 -0
  71. package/dist/cjs/auth/verifiers/base64Sha1Verifier.js +77 -0
  72. package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts +19 -0
  73. package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts.map +1 -0
  74. package/dist/cjs/auth/verifiers/base64Sha256Verifier.js +77 -0
  75. package/dist/cjs/auth/verifiers/common.d.ts +104 -0
  76. package/dist/cjs/auth/verifiers/common.d.ts.map +1 -0
  77. package/dist/cjs/auth/verifiers/common.js +99 -0
  78. package/dist/cjs/auth/verifiers/index.d.ts +8 -0
  79. package/dist/cjs/auth/verifiers/index.d.ts.map +1 -0
  80. package/dist/cjs/auth/verifiers/index.js +38 -0
  81. package/dist/cjs/auth/verifiers/jwtVerifier.d.ts +26 -0
  82. package/dist/cjs/auth/verifiers/jwtVerifier.d.ts.map +1 -0
  83. package/dist/cjs/auth/verifiers/jwtVerifier.js +86 -0
  84. package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts +14 -0
  85. package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts.map +1 -0
  86. package/dist/cjs/auth/verifiers/secretKeyVerifier.js +40 -0
  87. package/dist/cjs/auth/verifiers/sha1Verifier.d.ts +25 -0
  88. package/dist/cjs/auth/verifiers/sha1Verifier.d.ts.map +1 -0
  89. package/dist/cjs/auth/verifiers/sha1Verifier.js +85 -0
  90. package/dist/cjs/auth/verifiers/sha256Verifier.d.ts +25 -0
  91. package/dist/cjs/auth/verifiers/sha256Verifier.d.ts.map +1 -0
  92. package/dist/cjs/auth/verifiers/sha256Verifier.js +85 -0
  93. package/dist/cjs/auth/verifiers/skipVerifier.d.ts +13 -0
  94. package/dist/cjs/auth/verifiers/skipVerifier.d.ts.map +1 -0
  95. package/dist/cjs/auth/verifiers/skipVerifier.js +37 -0
  96. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts +16 -0
  97. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts.map +1 -0
  98. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.js +81 -0
  99. package/dist/cjs/bins/redwood.d.ts +9 -0
  100. package/dist/cjs/bins/redwood.d.ts.map +1 -0
  101. package/dist/cjs/bins/redwood.js +36 -0
  102. package/dist/cjs/bins/rwfw.d.ts +3 -0
  103. package/dist/cjs/bins/rwfw.d.ts.map +1 -0
  104. package/dist/cjs/bins/rwfw.js +36 -0
  105. package/dist/cjs/bins/tsc.d.ts +3 -0
  106. package/dist/cjs/bins/tsc.d.ts.map +1 -0
  107. package/dist/cjs/bins/tsc.js +30 -0
  108. package/dist/cjs/cache/clients/BaseClient.d.ts +11 -0
  109. package/dist/cjs/cache/clients/BaseClient.d.ts.map +1 -0
  110. package/dist/cjs/cache/clients/BaseClient.js +27 -0
  111. package/dist/cjs/cache/clients/InMemoryClient.d.ts +31 -0
  112. package/dist/cjs/cache/clients/InMemoryClient.d.ts.map +1 -0
  113. package/dist/cjs/cache/clients/InMemoryClient.js +100 -0
  114. package/dist/cjs/cache/clients/MemcachedClient.d.ts +16 -0
  115. package/dist/cjs/cache/clients/MemcachedClient.d.ts.map +1 -0
  116. package/dist/cjs/cache/clients/MemcachedClient.js +75 -0
  117. package/dist/cjs/cache/clients/RedisClient.d.ts +20 -0
  118. package/dist/cjs/cache/clients/RedisClient.d.ts.map +1 -0
  119. package/dist/cjs/cache/clients/RedisClient.js +79 -0
  120. package/dist/cjs/cache/errors.d.ts +4 -0
  121. package/dist/cjs/cache/errors.d.ts.map +1 -0
  122. package/dist/cjs/cache/errors.js +33 -0
  123. package/dist/cjs/cache/index.d.ts +35 -0
  124. package/dist/cjs/cache/index.d.ts.map +1 -0
  125. package/dist/cjs/cache/index.js +171 -0
  126. package/dist/cjs/cors.d.ts +16 -0
  127. package/dist/cjs/cors.d.ts.map +1 -0
  128. package/dist/cjs/cors.js +93 -0
  129. package/dist/cjs/errors.d.ts +5 -0
  130. package/dist/cjs/errors.d.ts.map +1 -0
  131. package/dist/cjs/errors.js +38 -0
  132. package/dist/cjs/event.d.ts +3 -0
  133. package/dist/cjs/event.d.ts.map +1 -0
  134. package/dist/cjs/event.js +34 -0
  135. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts +4 -0
  136. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts.map +1 -0
  137. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.js +72 -0
  138. package/dist/cjs/index.d.ts +11 -0
  139. package/dist/cjs/index.d.ts.map +1 -0
  140. package/dist/cjs/index.js +82 -0
  141. package/dist/cjs/logger/index.d.ts +179 -0
  142. package/dist/cjs/logger/index.d.ts.map +1 -0
  143. package/dist/cjs/logger/index.js +195 -0
  144. package/dist/cjs/package.json +1 -0
  145. package/dist/cjs/transforms.d.ts +35 -0
  146. package/dist/cjs/transforms.d.ts.map +1 -0
  147. package/dist/cjs/transforms.js +98 -0
  148. package/dist/cjs/types.d.ts +25 -0
  149. package/dist/cjs/types.d.ts.map +1 -0
  150. package/dist/cjs/types.js +16 -0
  151. package/dist/cjs/validations/errors.d.ts +101 -0
  152. package/dist/cjs/validations/errors.d.ts.map +1 -0
  153. package/dist/cjs/validations/errors.js +298 -0
  154. package/dist/cjs/validations/validations.d.ts +222 -0
  155. package/dist/cjs/validations/validations.d.ts.map +1 -0
  156. package/dist/cjs/validations/validations.js +351 -0
  157. package/dist/cjs/webhooks/index.d.ts +76 -0
  158. package/dist/cjs/webhooks/index.d.ts.map +1 -0
  159. package/dist/cjs/webhooks/index.js +107 -0
  160. package/dist/cors.d.ts +16 -0
  161. package/dist/cors.d.ts.map +1 -0
  162. package/dist/cors.js +69 -0
  163. package/dist/errors.d.ts +5 -0
  164. package/dist/errors.d.ts.map +1 -0
  165. package/dist/errors.js +14 -0
  166. package/dist/event.d.ts +3 -0
  167. package/dist/event.d.ts.map +1 -0
  168. package/dist/event.js +10 -0
  169. package/dist/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts +4 -0
  170. package/dist/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts.map +1 -0
  171. package/dist/functions/fixtures/apiGatewayProxyEvent.fixture.js +48 -0
  172. package/dist/index.d.ts +11 -0
  173. package/dist/index.d.ts.map +1 -0
  174. package/dist/index.js +38 -0
  175. package/dist/logger/index.d.ts +179 -0
  176. package/dist/logger/index.d.ts.map +1 -0
  177. package/dist/logger/index.js +152 -0
  178. package/dist/package.json +1 -0
  179. package/dist/transforms.d.ts +35 -0
  180. package/dist/transforms.d.ts.map +1 -0
  181. package/dist/transforms.js +70 -0
  182. package/dist/types.d.ts +25 -0
  183. package/dist/types.d.ts.map +1 -0
  184. package/dist/types.js +0 -0
  185. package/dist/validations/errors.d.ts +101 -0
  186. package/dist/validations/errors.d.ts.map +1 -0
  187. package/dist/validations/errors.js +239 -0
  188. package/dist/validations/validations.d.ts +222 -0
  189. package/dist/validations/validations.d.ts.map +1 -0
  190. package/dist/validations/validations.js +314 -0
  191. package/dist/webhooks/index.d.ts +76 -0
  192. package/dist/webhooks/index.d.ts.map +1 -0
  193. package/dist/webhooks/index.js +85 -0
  194. package/package.json +130 -0
@@ -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,48 @@
1
+ const mockedAPIGatewayProxyEvent = {
2
+ body: "MOCKED_BODY",
3
+ headers: {},
4
+ multiValueHeaders: {},
5
+ httpMethod: "POST",
6
+ isBase64Encoded: false,
7
+ path: "/MOCK_PATH",
8
+ pathParameters: null,
9
+ queryStringParameters: null,
10
+ multiValueQueryStringParameters: null,
11
+ stageVariables: null,
12
+ requestContext: {
13
+ accountId: "MOCKED_ACCOUNT",
14
+ apiId: "MOCKED_API_ID",
15
+ authorizer: { name: "MOCKED_AUTHORIZER" },
16
+ protocol: "HTTP",
17
+ identity: {
18
+ accessKey: null,
19
+ accountId: null,
20
+ apiKey: null,
21
+ apiKeyId: null,
22
+ caller: null,
23
+ clientCert: null,
24
+ cognitoAuthenticationProvider: null,
25
+ cognitoAuthenticationType: null,
26
+ cognitoIdentityId: null,
27
+ cognitoIdentityPoolId: null,
28
+ principalOrgId: null,
29
+ sourceIp: "123.123.123.123",
30
+ user: null,
31
+ userAgent: null,
32
+ userArn: null
33
+ },
34
+ httpMethod: "POST",
35
+ path: "/MOCK_PATH",
36
+ stage: "MOCK_STAGE",
37
+ requestId: "MOCKED_REQUEST_ID",
38
+ requestTimeEpoch: 1,
39
+ resourceId: "MOCKED_RESOURCE_ID",
40
+ resourcePath: "MOCKED_RESOURCE_PATH"
41
+ },
42
+ resource: "MOCKED_RESOURCE"
43
+ };
44
+ var apiGatewayProxyEvent_fixture_default = mockedAPIGatewayProxyEvent;
45
+ export {
46
+ apiGatewayProxyEvent_fixture_default as default,
47
+ mockedAPIGatewayProxyEvent
48
+ };
@@ -0,0 +1,11 @@
1
+ export * from './auth/index.js';
2
+ export * from './errors.js';
3
+ export * from './validations/validations.js';
4
+ export * from './validations/errors.js';
5
+ export * from './types.js';
6
+ export * from './transforms.js';
7
+ export * from './cors.js';
8
+ export * from './event.js';
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":"AAGA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,yBAAyB,CAAA;AACvC,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AA8B1B,eAAO,MAAM,aAAa,KAA8C,CAAA;AACxE,eAAO,MAAM,cAAc,KAAuB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ import { createRequire } from "node:module";
2
+ import path from "node:path";
3
+ export * from "./auth/index.js";
4
+ export * from "./errors.js";
5
+ export * from "./validations/validations.js";
6
+ export * from "./validations/errors.js";
7
+ export * from "./types.js";
8
+ export * from "./transforms.js";
9
+ export * from "./cors.js";
10
+ export * from "./event.js";
11
+ const customRequire = (
12
+ // Look out for a stubbed require function
13
+ // @ts-expect-error - Using `0, ` to work around bundler magic
14
+ typeof require === "function" && !(0, require).toString().includes("@rollup") ? require : (
15
+ // The argument to `createRequire` should be a file and node will strip
16
+ // the last segment (the file name) to get to a base path. By appending a
17
+ // fake "foo" file we get the base path we want.
18
+ // If I knew this was only going to be run as an ESM I'd use
19
+ // `import.meta.url`, but for dual bundling I can't do that (without a
20
+ // bunch of warnings at build time at least)
21
+ createRequire(path.join(process.env.RWJS_CWD || process.cwd(), "foo"))
22
+ )
23
+ );
24
+ const rxApiPath = customRequire.resolve("@cedarjs/api");
25
+ const rxApiRequire = createRequire(rxApiPath);
26
+ let packageJson = rxApiRequire("./package.json");
27
+ if (packageJson?.name !== "@cedarjs/api") {
28
+ packageJson = rxApiRequire("../package.json");
29
+ }
30
+ if (packageJson?.name !== "@cedarjs/api") {
31
+ packageJson = rxApiRequire("../../package.json");
32
+ }
33
+ const prismaVersion = packageJson?.dependencies["@prisma/client"];
34
+ const redwoodVersion = packageJson?.version;
35
+ export {
36
+ prismaVersion,
37
+ redwoodVersion
38
+ };
@@ -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,GAA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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,WAAY,mBAAmB,KAAG,IA8CjE,CAAA"}
@@ -0,0 +1,152 @@
1
+ import pino from "pino";
2
+ const isDevelopment = process.env.NODE_ENV === "development";
3
+ const isTest = process.env.NODE_ENV === "test";
4
+ const isProduction = !isDevelopment && !isTest;
5
+ const redactionsList = [
6
+ "access_token",
7
+ "data.access_token",
8
+ "data.*.access_token",
9
+ "data.*.accessToken",
10
+ "accessToken",
11
+ "data.accessToken",
12
+ "DATABASE_URL",
13
+ "data.*.email",
14
+ "data.email",
15
+ "email",
16
+ "event.headers.authorization",
17
+ "data.hashedPassword",
18
+ "data.*.hashedPassword",
19
+ "hashedPassword",
20
+ "host",
21
+ "jwt",
22
+ "data.jwt",
23
+ "data.*.jwt",
24
+ "JWT",
25
+ "data.JWT",
26
+ "data.*.JWT",
27
+ "password",
28
+ "data.password",
29
+ "data.*.password",
30
+ "params",
31
+ "data.salt",
32
+ "data.*.salt",
33
+ "salt",
34
+ "secret",
35
+ "data.secret",
36
+ "data.*.secret"
37
+ ];
38
+ const logLevel = (() => {
39
+ if (typeof process.env.LOG_LEVEL !== "undefined") {
40
+ return process.env.LOG_LEVEL;
41
+ } else if (isProduction) {
42
+ return "warn";
43
+ } else if (isTest) {
44
+ return "silent";
45
+ } else {
46
+ return "trace";
47
+ }
48
+ })();
49
+ const defaultLoggerOptions = {
50
+ level: logLevel,
51
+ redact: redactionsList
52
+ };
53
+ const createLogger = ({
54
+ options,
55
+ destination,
56
+ showConfig = false
57
+ }) => {
58
+ const hasDestination = typeof destination !== "undefined";
59
+ const isFile = hasDestination && typeof destination === "string";
60
+ const isStream = hasDestination && !isFile;
61
+ const stream = destination;
62
+ options = { ...defaultLoggerOptions, ...options };
63
+ if (showConfig) {
64
+ console.log("Logger Configuration");
65
+ console.log(`isProduction: ${isProduction}`);
66
+ console.log(`isDevelopment: ${isDevelopment}`);
67
+ console.log(`isTest: ${isTest}`);
68
+ console.log(`isFile: ${isFile}`);
69
+ console.log(`isStream: ${isStream}`);
70
+ console.log(`logLevel: ${logLevel}`);
71
+ console.log(`options: ${JSON.stringify(options, null, 2)}`);
72
+ console.log(`destination: ${destination}`);
73
+ }
74
+ if (isFile) {
75
+ if (isProduction) {
76
+ console.warn(
77
+ "Please make certain that file system access is available when logging to a file in a production environment."
78
+ );
79
+ }
80
+ return pino(options, stream);
81
+ } else {
82
+ if (isStream && isDevelopment && !isTest) {
83
+ console.warn(
84
+ "Logs will be sent to the transport stream in the current development environment."
85
+ );
86
+ }
87
+ return pino(options, stream);
88
+ }
89
+ };
90
+ const DEFAULT_SLOW_QUERY_THRESHOLD = 2e3;
91
+ const defaultLogLevels = ["info", "warn", "error"];
92
+ const emitLogLevels = (setLogLevels) => {
93
+ return setLogLevels?.map((level) => {
94
+ return { emit: "event", level };
95
+ });
96
+ };
97
+ const handlePrismaLogging = (config) => {
98
+ const logger = config.logger.child({
99
+ // @TODO Change this once this issue is resolved
100
+ // See https://github.com/prisma/prisma/issues/8290
101
+ prisma: { clientVersion: config.db["_clientVersion"] }
102
+ });
103
+ const slowQueryThreshold = config.slowQueryThreshold ?? DEFAULT_SLOW_QUERY_THRESHOLD;
104
+ config.logLevels?.forEach((level) => {
105
+ if (level === "query") {
106
+ config.db.$on(level, (event) => {
107
+ const queryEvent = event;
108
+ if (queryEvent.duration >= slowQueryThreshold) {
109
+ logger.warn(
110
+ { ...queryEvent },
111
+ `Slow Query performed in ${queryEvent.duration} msec`
112
+ );
113
+ } else {
114
+ logger.debug(
115
+ { ...queryEvent },
116
+ `Query performed in ${queryEvent.duration} msec`
117
+ );
118
+ }
119
+ });
120
+ } else {
121
+ config.db.$on(level, (event) => {
122
+ const logEvent = event;
123
+ switch (level) {
124
+ case "info":
125
+ logger.info({ ...logEvent }, logEvent.message);
126
+ break;
127
+ case "warn":
128
+ logger.warn({ ...logEvent }, logEvent.message);
129
+ break;
130
+ case "error":
131
+ logger.error({ ...logEvent }, logEvent.message);
132
+ break;
133
+ default:
134
+ logger.info({ ...logEvent }, logEvent.message);
135
+ }
136
+ });
137
+ }
138
+ });
139
+ return;
140
+ };
141
+ export {
142
+ createLogger,
143
+ defaultLogLevels,
144
+ defaultLoggerOptions,
145
+ emitLogLevels,
146
+ handlePrismaLogging,
147
+ isDevelopment,
148
+ isProduction,
149
+ isTest,
150
+ logLevel,
151
+ redactionsList
152
+ };
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,35 @@
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 isFetchApiRequest: (event: Request | APIGatewayProxyEvent) => event is Request;
21
+ /**
22
+ *
23
+ * This function returns a an object that lets you access _some_ of the request properties in a consistent way
24
+ * You can give it either a LambdaEvent or a Fetch API Request
25
+ *
26
+ * NOTE: It does NOT return a full Request object!
27
+ */
28
+ export declare function normalizeRequest(event: APIGatewayProxyEvent | Request): Promise<PartialRequest>;
29
+ /**
30
+ * Useful for removing nulls from an object, such as an input from a GraphQL mutation used directly in a Prisma query
31
+ * @param input - Object to remove nulls from
32
+ * See {@link https://www.prisma.io/docs/concepts/components/prisma-client/null-and-undefined Prisma docs: null vs undefined}
33
+ */
34
+ export declare const removeNulls: (input: Record<number | symbol | string, any>) => Record<string | number | symbol, any>;
35
+ //# 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,UAAW,oBAAoB,QAU/D,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,UAAiB,OAAO,iBAQvD,CAAA;AAED,eAAO,MAAM,iBAAiB,UACrB,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,UAAW,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,0CAcvE,CAAA"}
@@ -0,0 +1,70 @@
1
+ import { Headers, Request as PonyfillRequest } from "@whatwg-node/fetch";
2
+ const parseLambdaEventBody = (event) => {
3
+ if (!event.body) {
4
+ return {};
5
+ }
6
+ if (event.isBase64Encoded) {
7
+ return JSON.parse(Buffer.from(event.body, "base64").toString("utf-8"));
8
+ } else {
9
+ return JSON.parse(event.body);
10
+ }
11
+ };
12
+ const parseFetchEventBody = async (event) => {
13
+ if (!event.body) {
14
+ return {};
15
+ }
16
+ const body = await event.text();
17
+ return body ? JSON.parse(body) : {};
18
+ };
19
+ const isFetchApiRequest = (event) => {
20
+ if (event.constructor.name === "Request" || event.constructor.name === PonyfillRequest.name) {
21
+ return true;
22
+ }
23
+ if (Symbol.iterator in Object(event.headers)) {
24
+ return true;
25
+ }
26
+ return false;
27
+ };
28
+ function getQueryStringParams(reqUrl) {
29
+ const url = new URL(reqUrl);
30
+ const params = new URLSearchParams(url.search);
31
+ const paramObject = {};
32
+ for (const entry of params.entries()) {
33
+ paramObject[entry[0]] = entry[1];
34
+ }
35
+ return paramObject;
36
+ }
37
+ async function normalizeRequest(event) {
38
+ if (isFetchApiRequest(event)) {
39
+ return {
40
+ headers: event.headers,
41
+ method: event.method,
42
+ query: getQueryStringParams(event.url),
43
+ jsonBody: await parseFetchEventBody(event)
44
+ };
45
+ }
46
+ const jsonBody = parseLambdaEventBody(event);
47
+ return {
48
+ headers: new Headers(event.headers),
49
+ method: event.httpMethod,
50
+ query: event.queryStringParameters,
51
+ jsonBody
52
+ };
53
+ }
54
+ const removeNulls = (input) => {
55
+ for (const key in input) {
56
+ if (input[key] === null) {
57
+ input[key] = void 0;
58
+ } else if (typeof input[key] === "object" && !(input[key] instanceof Date)) {
59
+ input[key] = removeNulls(input[key]);
60
+ }
61
+ }
62
+ return input;
63
+ };
64
+ export {
65
+ isFetchApiRequest,
66
+ normalizeRequest,
67
+ parseFetchEventBody,
68
+ parseLambdaEventBody,
69
+ removeNulls
70
+ };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Houses utility types commonly used on the api side
3
+ */
4
+ import type { O, A } from 'ts-toolbelt';
5
+ /**
6
+ * ---- Prisma SDL Type Merge ----
7
+ * SDL is source of truth for KEYS
8
+ * Prisma types is source of truth for VALUES (unless SDL-only field)
9
+ */
10
+ type AnyObject = Record<string | symbol | number, unknown>;
11
+ type SdlOnlyFields<TPrisma, TSdl> = Omit<TSdl, keyof TPrisma>;
12
+ type PrismaTypeWithOptionalKeysFromSdl<TPrisma extends AnyObject, TSdl extends AnyObject> = Pick<TPrisma, O.OptionalKeys<TSdl>>;
13
+ type PrismaTypeWithOptionalKeysAndNullableValues<TPrisma extends AnyObject, TSdl extends AnyObject> = {
14
+ [k in keyof PrismaTypeWithOptionalKeysFromSdl<TPrisma, TSdl>]?: PrismaTypeWithOptionalKeysFromSdl<TPrisma, TSdl>[k] | null;
15
+ };
16
+ type PrismaTypeWithRequiredKeysFromSdl<TPrisma extends AnyObject, TSdl extends AnyObject> = Pick<TPrisma, O.RequiredKeys<TSdl>>;
17
+ type OptionalsAndSdlOnly<TPrisma extends AnyObject, TSdl extends AnyObject> = PrismaTypeWithOptionalKeysAndNullableValues<TPrisma, TSdl> & SdlOnlyFields<TPrisma, TSdl>;
18
+ export type MakeRelationsOptional<T, TAllMappedModels> = {
19
+ [key in keyof T as T[key] extends TAllMappedModels ? key : never]?: MakeRelationsOptional<T[key], TAllMappedModels>;
20
+ } & {
21
+ [key in keyof T as T[key] extends TAllMappedModels ? never : key]: T[key];
22
+ };
23
+ export type MergePrismaWithSdlTypes<TPrisma extends AnyObject, TSdl extends AnyObject, TAllMappedModels> = A.Compute<OptionalsAndSdlOnly<TPrisma, MakeRelationsOptional<TSdl, TAllMappedModels>> & PrismaTypeWithRequiredKeysFromSdl<TPrisma, MakeRelationsOptional<TSdl, TAllMappedModels>>>;
24
+ export {};
25
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,aAAa,CAAA;AAEvC;;;;GAIG;AAEH,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAA;AAE1D,KAAK,aAAa,CAAC,OAAO,EAAE,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,CAAA;AAG7D,KAAK,iC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