@cedarjs/api 6.0.0-canary.2789 → 6.0.0-canary.2793

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 (109) hide show
  1. package/dist/bins/cedar.js +14 -0
  2. package/dist/bins/cfw.js +14 -0
  3. package/dist/bins/redwood.js +14 -0
  4. package/dist/bins/tsc.js +8 -0
  5. package/dist/index.js +3 -3
  6. package/package.json +15 -39
  7. package/dist/cjs/auth/index.d.ts +0 -64
  8. package/dist/cjs/auth/index.d.ts.map +0 -1
  9. package/dist/cjs/auth/index.js +0 -143
  10. package/dist/cjs/auth/parseJWT.d.ts +0 -6
  11. package/dist/cjs/auth/parseJWT.d.ts.map +0 -1
  12. package/dist/cjs/auth/parseJWT.js +0 -57
  13. package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts +0 -18
  14. package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts.map +0 -1
  15. package/dist/cjs/auth/verifiers/base64Sha1Verifier.js +0 -77
  16. package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts +0 -18
  17. package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts.map +0 -1
  18. package/dist/cjs/auth/verifiers/base64Sha256Verifier.js +0 -77
  19. package/dist/cjs/auth/verifiers/common.d.ts +0 -112
  20. package/dist/cjs/auth/verifiers/common.d.ts.map +0 -1
  21. package/dist/cjs/auth/verifiers/common.js +0 -89
  22. package/dist/cjs/auth/verifiers/index.d.ts +0 -8
  23. package/dist/cjs/auth/verifiers/index.d.ts.map +0 -1
  24. package/dist/cjs/auth/verifiers/index.js +0 -39
  25. package/dist/cjs/auth/verifiers/jwtVerifier.d.ts +0 -18
  26. package/dist/cjs/auth/verifiers/jwtVerifier.d.ts.map +0 -1
  27. package/dist/cjs/auth/verifiers/jwtVerifier.js +0 -84
  28. package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts +0 -11
  29. package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts.map +0 -1
  30. package/dist/cjs/auth/verifiers/secretKeyVerifier.js +0 -43
  31. package/dist/cjs/auth/verifiers/sha1Verifier.d.ts +0 -17
  32. package/dist/cjs/auth/verifiers/sha1Verifier.d.ts.map +0 -1
  33. package/dist/cjs/auth/verifiers/sha1Verifier.js +0 -85
  34. package/dist/cjs/auth/verifiers/sha256Verifier.d.ts +0 -17
  35. package/dist/cjs/auth/verifiers/sha256Verifier.d.ts.map +0 -1
  36. package/dist/cjs/auth/verifiers/sha256Verifier.js +0 -85
  37. package/dist/cjs/auth/verifiers/skipVerifier.d.ts +0 -11
  38. package/dist/cjs/auth/verifiers/skipVerifier.d.ts.map +0 -1
  39. package/dist/cjs/auth/verifiers/skipVerifier.js +0 -40
  40. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts +0 -14
  41. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts.map +0 -1
  42. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.js +0 -86
  43. package/dist/cjs/bins/cedar.d.ts +0 -9
  44. package/dist/cjs/bins/cedar.d.ts.map +0 -1
  45. package/dist/cjs/bins/cedar.js +0 -36
  46. package/dist/cjs/bins/cfw.d.ts +0 -3
  47. package/dist/cjs/bins/cfw.d.ts.map +0 -1
  48. package/dist/cjs/bins/cfw.js +0 -36
  49. package/dist/cjs/bins/redwood.d.ts +0 -9
  50. package/dist/cjs/bins/redwood.d.ts.map +0 -1
  51. package/dist/cjs/bins/redwood.js +0 -36
  52. package/dist/cjs/bins/tsc.d.ts +0 -3
  53. package/dist/cjs/bins/tsc.d.ts.map +0 -1
  54. package/dist/cjs/bins/tsc.js +0 -30
  55. package/dist/cjs/cache/clients/BaseClient.d.ts +0 -11
  56. package/dist/cjs/cache/clients/BaseClient.d.ts.map +0 -1
  57. package/dist/cjs/cache/clients/BaseClient.js +0 -31
  58. package/dist/cjs/cache/clients/InMemoryClient.d.ts +0 -31
  59. package/dist/cjs/cache/clients/InMemoryClient.d.ts.map +0 -1
  60. package/dist/cjs/cache/clients/InMemoryClient.js +0 -94
  61. package/dist/cjs/cache/clients/MemcachedClient.d.ts +0 -16
  62. package/dist/cjs/cache/clients/MemcachedClient.d.ts.map +0 -1
  63. package/dist/cjs/cache/clients/MemcachedClient.js +0 -79
  64. package/dist/cjs/cache/clients/RedisClient.d.ts +0 -20
  65. package/dist/cjs/cache/clients/RedisClient.d.ts.map +0 -1
  66. package/dist/cjs/cache/clients/RedisClient.js +0 -83
  67. package/dist/cjs/cache/errors.d.ts +0 -4
  68. package/dist/cjs/cache/errors.d.ts.map +0 -1
  69. package/dist/cjs/cache/errors.js +0 -33
  70. package/dist/cjs/cache/index.d.ts +0 -35
  71. package/dist/cjs/cache/index.d.ts.map +0 -1
  72. package/dist/cjs/cache/index.js +0 -165
  73. package/dist/cjs/cors.d.ts +0 -16
  74. package/dist/cjs/cors.d.ts.map +0 -1
  75. package/dist/cjs/cors.js +0 -93
  76. package/dist/cjs/errors.d.ts +0 -5
  77. package/dist/cjs/errors.d.ts.map +0 -1
  78. package/dist/cjs/errors.js +0 -38
  79. package/dist/cjs/event.d.ts +0 -3
  80. package/dist/cjs/event.d.ts.map +0 -1
  81. package/dist/cjs/event.js +0 -34
  82. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts +0 -4
  83. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts.map +0 -1
  84. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.js +0 -72
  85. package/dist/cjs/index.d.ts +0 -15
  86. package/dist/cjs/index.d.ts.map +0 -1
  87. package/dist/cjs/index.js +0 -54
  88. package/dist/cjs/logger/index.d.ts +0 -179
  89. package/dist/cjs/logger/index.d.ts.map +0 -1
  90. package/dist/cjs/logger/index.js +0 -185
  91. package/dist/cjs/package.json +0 -1
  92. package/dist/cjs/runtime.d.ts +0 -42
  93. package/dist/cjs/runtime.d.ts.map +0 -1
  94. package/dist/cjs/runtime.js +0 -191
  95. package/dist/cjs/transforms.d.ts +0 -36
  96. package/dist/cjs/transforms.d.ts.map +0 -1
  97. package/dist/cjs/transforms.js +0 -176
  98. package/dist/cjs/types.d.ts +0 -25
  99. package/dist/cjs/types.d.ts.map +0 -1
  100. package/dist/cjs/types.js +0 -16
  101. package/dist/cjs/validations/errors.d.ts +0 -101
  102. package/dist/cjs/validations/errors.d.ts.map +0 -1
  103. package/dist/cjs/validations/errors.js +0 -298
  104. package/dist/cjs/validations/validations.d.ts +0 -235
  105. package/dist/cjs/validations/validations.d.ts.map +0 -1
  106. package/dist/cjs/validations/validations.js +0 -353
  107. package/dist/cjs/webhooks/index.d.ts +0 -77
  108. package/dist/cjs/webhooks/index.d.ts.map +0 -1
  109. package/dist/cjs/webhooks/index.js +0 -102
@@ -1,235 +0,0 @@
1
- type WithOptionalMessage<T = Record<string, unknown>> = T & {
2
- /**
3
- * A message to be shown if the validation fails.
4
- */
5
- message?: string;
6
- };
7
- type WithRequiredMessage<T = Record<string, unknown>> = Required<WithOptionalMessage> & T;
8
- interface AbsenceValidatorOptions extends WithOptionalMessage {
9
- /**
10
- * Will count an empty string as being absent (that is, null, undefined and "" will pass this validation)
11
- */
12
- allowEmptyString?: boolean;
13
- }
14
- interface AcceptanceValidatorOptions extends WithOptionalMessage {
15
- /**
16
- * An array of values that, if any match, will pass the validation.
17
- */
18
- in?: unknown[];
19
- }
20
- type EmailValidatorOptions = WithOptionalMessage;
21
- interface ExclusionValidatorOptions extends WithOptionalMessage {
22
- /**
23
- * The list of values that cannot be used.
24
- */
25
- in?: unknown[];
26
- caseSensitive?: boolean;
27
- }
28
- interface FormatValidatorOptions extends WithOptionalMessage {
29
- /**
30
- * The regular expression to use.
31
- */
32
- pattern?: RegExp;
33
- }
34
- interface InclusionValidatorOptions extends WithOptionalMessage {
35
- /**
36
- * The list of values that can be used.
37
- */
38
- in?: unknown[];
39
- caseSensitive?: boolean;
40
- }
41
- interface LengthValidatorOptions extends WithOptionalMessage {
42
- /**
43
- * Must be at least this number of characters long.
44
- */
45
- min?: number;
46
- /**
47
- * Must be no more than this number of characters long.
48
- */
49
- max?: number;
50
- /**
51
- * Must be exactly this number of characters long.
52
- */
53
- equal?: number;
54
- /**
55
- * Convenience syntax for defining min and max as an array
56
- *
57
- * @example
58
- * validate(input.title, 'Title', {
59
- * length: { between: [2, 255] }
60
- * })
61
- */
62
- between?: number[];
63
- }
64
- interface NumericalityValidatorOptions extends WithOptionalMessage {
65
- /**
66
- * The number must be an integer.
67
- */
68
- integer?: boolean;
69
- /**
70
- * The number must be less than the given value.
71
- */
72
- lessThan?: number;
73
- /**
74
- * The number must be less than or equal to the given value.
75
- */
76
- lessThanOrEqual?: number;
77
- /**
78
- * The number must be greater than the given value.
79
- */
80
- greaterThan?: number;
81
- /**
82
- * The number must be greater than or equal to the given number.
83
- */
84
- greaterThanOrEqual?: number;
85
- /**
86
- * The number must be equal to the given number.
87
- */
88
- equal?: number;
89
- /**
90
- * The number must not be equal to the given number.
91
- */
92
- otherThan?: number;
93
- /**
94
- * The number must be even.
95
- */
96
- even?: boolean;
97
- /**
98
- * The number must be odd.
99
- */
100
- odd?: boolean;
101
- /**
102
- * The number must be positive.
103
- */
104
- positive?: boolean;
105
- /**
106
- * The number must be negative.
107
- */
108
- negative?: boolean;
109
- }
110
- interface PresenceValidatorOptions extends WithOptionalMessage {
111
- /**
112
- * Whether or not to allow null to be considered present.
113
- *
114
- * @default false
115
- */
116
- allowNull?: boolean;
117
- /**
118
- * Whether or not to allow undefined to be considered present.
119
- *
120
- * @default false
121
- */
122
- allowUndefined?: boolean;
123
- /**
124
- * Whether or not to allow an empty string "" to be considered present.
125
- *
126
- * @default false
127
- */
128
- allowEmptyString?: boolean;
129
- }
130
- interface CustomValidatorOptions extends WithOptionalMessage {
131
- /**
132
- * A function which should either throw or return nothing
133
- */
134
- with: () => void;
135
- }
136
- interface UniquenessValidatorOptions<TDb extends UniquenessDb = UniquenessDb> extends WithOptionalMessage {
137
- db?: TDb;
138
- }
139
- type UniquenessWhere = Record<'AND' | 'NOT', Record<string, unknown>[]>;
140
- export type UniquenessTransactionClient = Record<string, {
141
- findFirst: (args: {
142
- where: UniquenessWhere;
143
- }) => Promise<unknown>;
144
- }>;
145
- interface UniquenessDb {
146
- $transaction: (...args: any[]) => Promise<any>;
147
- }
148
- type TxClientOf<TDb extends UniquenessDb> = TDb extends {
149
- $transaction: (callback: (tx: infer TTx) => any, ...args: any[]) => any;
150
- } ? TTx : never;
151
- interface ValidationRecipe {
152
- /**
153
- * Requires that a field NOT be present, meaning it must be `null` or `undefined`.
154
- *
155
- * Opposite of the [`presence`](https://cedarjs.com/docs/services.html#presence) validator.
156
- */
157
- absence?: boolean | AbsenceValidatorOptions;
158
- /**
159
- * Requires that the passed value be `true`, or within an array of allowed values that will be considered "true".
160
- */
161
- acceptance?: boolean | AcceptanceValidatorOptions;
162
- /**
163
- * Requires that the value be formatted like an email address by comparing against a regular expression.
164
- * The regex is extremely lax: `/^[^@\s]+@[^.\s]+\.[^\s]+$/`
165
- *
166
- * This says that the value:
167
- *
168
- * * Must start with one or more characters that aren't a whitespace or literal @
169
- * * Followed by a @
170
- * * Followed by one or more characters that aren't a whitespace or literal .
171
- * * Followed by a .
172
- * * Ending with one or more characters that aren't whitespace
173
- *
174
- * Since the official email regex is around 6,300 characters long, we though this one was good enough.
175
- * If you have a different, preferred email validation regular expression, use the format validation.
176
- */
177
- email?: boolean | EmailValidatorOptions;
178
- /**
179
- * Requires that the given value not equal to any in a list of given values.
180
- *
181
- * Opposite of the [inclusion](https://cedarjs.com/docs/services.html#inclusion) validation.
182
- */
183
- exclusion?: unknown[] | ExclusionValidatorOptions;
184
- /**
185
- * Requires that the value match a given regular expression.
186
- */
187
- format?: RegExp | FormatValidatorOptions;
188
- /**
189
- * Requires that the given value is equal to one in a list of given values.
190
- *
191
- * Opposite of the [exclusion](https://cedarjs.com/docs/services.html#exclusion) validation.
192
- */
193
- inclusion?: unknown[] | InclusionValidatorOptions;
194
- /**
195
- * Requires that the value meet one or more of a number of string length validations.
196
- */
197
- length?: LengthValidatorOptions;
198
- /**
199
- * The awesomely-named Numericality Validation requires that the value passed meet one or more criteria that are all number related.
200
- */
201
- numericality?: boolean | NumericalityValidatorOptions;
202
- /**
203
- * Requires that a field be present, meaning it must not be null or undefined.
204
- *
205
- * Opposite of the [absence](https://cedarjs.com/docs/services.html#absence) validator.
206
- */
207
- presence?: boolean | PresenceValidatorOptions;
208
- /**
209
- * Run a custom validation function which should either throw or return
210
- * nothing.
211
- * If the function throws an error, the error message will be used as the
212
- * validation error associated with the field.
213
- */
214
- custom?: CustomValidatorOptions;
215
- }
216
- interface ValidationWithMessagesRecipe extends ValidationRecipe {
217
- absence?: WithRequiredMessage<AbsenceValidatorOptions>;
218
- acceptance?: WithRequiredMessage<AcceptanceValidatorOptions>;
219
- email?: WithRequiredMessage<EmailValidatorOptions>;
220
- exclusion?: WithRequiredMessage<ExclusionValidatorOptions>;
221
- format?: WithRequiredMessage<FormatValidatorOptions>;
222
- inclusion?: WithRequiredMessage<InclusionValidatorOptions>;
223
- length?: WithRequiredMessage<LengthValidatorOptions>;
224
- numericality?: WithRequiredMessage<NumericalityValidatorOptions>;
225
- presence?: WithRequiredMessage<PresenceValidatorOptions>;
226
- custom?: CustomValidatorOptions;
227
- }
228
- export declare function validate(value: unknown, labelOrRecipe: ValidationWithMessagesRecipe, recipe?: never): void;
229
- export declare function validate(value: unknown, labelOrRecipe: string, recipe: ValidationRecipe): void;
230
- export declare const validateWithSync: (func: () => void) => void;
231
- export declare const validateWith: (func: () => Promise<any>) => Promise<void>;
232
- export declare function validateUniqueness<TDb extends UniquenessDb = UniquenessDb>(model: string, fields: Record<string, unknown>, optionsOrCallback: (tx: TxClientOf<TDb>) => Promise<any>, callback?: never): Promise<any>;
233
- export declare function validateUniqueness<TDb extends UniquenessDb = UniquenessDb>(model: string, fields: Record<string, unknown>, optionsOrCallback: UniquenessValidatorOptions<TDb>, callback?: (tx: TxClientOf<TDb>) => Promise<any>): Promise<any>;
234
- export {};
235
- //# sourceMappingURL=validations.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validations.d.ts","sourceRoot":"","sources":["../../../src/validations/validations.ts"],"names":[],"mappings":"AAMA,KAAK,mBAAmB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG;IAC1D;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,KAAK,mBAAmB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAClD,QAAQ,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAA;AAEnC,UAAU,uBAAwB,SAAQ,mBAAmB;IAC3D;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED,UAAU,0BAA2B,SAAQ,mBAAmB;IAC9D;;OAEG;IACH,EAAE,CAAC,EAAE,OAAO,EAAE,CAAA;CACf;AAED,KAAK,qBAAqB,GAAG,mBAAmB,CAAA;AAEhD,UAAU,yBAA0B,SAAQ,mBAAmB;IAC7D;;OAEG;IACH,EAAE,CAAC,EAAE,OAAO,EAAE,CAAA;IACd,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,UAAU,sBAAuB,SAAQ,mBAAmB;IAC1D;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,UAAU,yBAA0B,SAAQ,mBAAmB;IAC7D;;OAEG;IACH,EAAE,CAAC,EAAE,OAAO,EAAE,CAAA;IACd,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,UAAU,sBAAuB,SAAQ,mBAAmB;IAC1D;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAA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,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,iBAAiB,EAAE,0BAA0B,CAAC,GAAG,CAAC,EAClD,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,UAAU,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,GAC/C,OAAO,CAAC,GAAG,CAAC,CAAA"}
@@ -1,353 +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 validations_exports = {};
30
- __export(validations_exports, {
31
- validate: () => validate,
32
- validateUniqueness: () => validateUniqueness,
33
- validateWith: () => validateWith,
34
- validateWithSync: () => validateWithSync
35
- });
36
- module.exports = __toCommonJS(validations_exports);
37
- var import_pascalcase = __toESM(require("pascalcase"), 1);
38
- var ValidationErrors = __toESM(require("./errors.js"), 1);
39
- const VALIDATORS = {
40
- // Requires that the given value is `null` or `undefined`
41
- //
42
- // `allowEmptyString`: if true, counts "" as being absent (does not throw)
43
- //
44
- // { absence: true }
45
- // { absence: { allowEmptyString: true, message: '...' } }
46
- absence: (value, name, options) => {
47
- const absenceOptions = { allowEmptyString: false };
48
- Object.assign(absenceOptions, options);
49
- if (value === "") {
50
- if (!absenceOptions.allowEmptyString) {
51
- validationError("absence", name, options);
52
- }
53
- } else if (value != null) {
54
- validationError("absence", name, options);
55
- }
56
- },
57
- // Requires that the given field be `true` and nothing else, unless an array
58
- // of valid values is included with an `in` option
59
- //
60
- // { acceptance: true }
61
- // { acceptance: { in: ['true','1'], message: '...' } }
62
- acceptance: (value, name, options) => {
63
- let acceptedValues;
64
- if (typeof options === "object") {
65
- acceptedValues = options.in || [];
66
- } else {
67
- acceptedValues = [true];
68
- }
69
- if (!acceptedValues.includes(value)) {
70
- validationError("acceptance", name, options);
71
- }
72
- },
73
- // Requires that the given value be formatted like an email address. Uses a
74
- // very simple regex which checks for at least 1 character that is not an @,
75
- // then an @, then at least one character that isn't a period, then a period,
76
- // then any character. There cannot be any spaces present.
77
- //
78
- // { email: true }
79
- // { email: { message: '...' } }
80
- email: (value, name, options) => {
81
- const pattern = /^[^@\s]+@[^.\s]+\.[^\s]+$/;
82
- if (!pattern.test(String(value))) {
83
- validationError("email", name, options);
84
- }
85
- },
86
- // Requires that the given value NOT be in the list of possible values
87
- //
88
- // { exclusion: ['foo', 'bar'] }
89
- // { exclusion: { in: ['foo','bar'], message: '...' } }
90
- exclusion: (value, name, options) => {
91
- const [exclusionList, val] = prepareExclusionInclusion(value, options);
92
- if (exclusionList.includes(val)) {
93
- validationError("exclusion", name, options);
94
- }
95
- },
96
- // Requires that the given value match a regular expression
97
- //
98
- // { format: /^foobar$/ }
99
- // { format: { pattern: /^foobar$/, message: '...' } }
100
- format: (value, name, options) => {
101
- const pattern = options instanceof RegExp ? options : options.pattern;
102
- if (pattern == null) {
103
- throw new ValidationErrors.FormatValidationError(
104
- name,
105
- "No pattern for format validation"
106
- );
107
- }
108
- if (!pattern.test(String(value))) {
109
- validationError("format", name, options);
110
- }
111
- },
112
- // Requires that the given value be in the list of possible values
113
- //
114
- // { inclusion: ['foo', 'bar'] }
115
- // { inclusion: { in: ['foo','bar'], message: '...' } }
116
- inclusion: (value, name, options) => {
117
- const [inclusionList, val] = prepareExclusionInclusion(value, options);
118
- if (!inclusionList.includes(val)) {
119
- validationError("inclusion", name, options);
120
- }
121
- },
122
- // Requires that the given string be a certain length:
123
- //
124
- // `min`: must be at least `min` characters
125
- // `max`: must be no more than `max` characters
126
- // `equal`: must be exactly `equal` characters
127
- // `between`: an array consisting of the `min` and `max` length
128
- //
129
- // { length: { min: 4 } }
130
- // { length: { min: 2, max: 16 } }
131
- // { length: { between: [2, 16], message: '...' } }
132
- length: (value, name, options) => {
133
- const len = String(value).length;
134
- if (options.min && len < options.min) {
135
- validationError("minLength", name, options, { min: options.min });
136
- }
137
- if (options.max && len > options.max) {
138
- validationError("maxLength", name, options, { max: options.max });
139
- }
140
- if (options.equal && len !== options.equal) {
141
- validationError("equalLength", name, options, { equal: options.equal });
142
- }
143
- if (options.between && (len < options.between[0] || len > options.between[1])) {
144
- validationError("betweenLength", name, options, {
145
- min: options.between[0],
146
- max: options.between[1]
147
- });
148
- }
149
- },
150
- // Requires that number value meets some criteria:
151
- //
152
- // `integer`: value must be an integer
153
- // `lessThan`: value must be less than `lessThan`
154
- // `lessThanOrEqual`: value must be less than or equal to `lessThanOrEqual`
155
- // `greaterThan`: value must be greater than `greaterThan`
156
- // `greaterThanOrEqual`: value must be greater than or equal to `greaterThanOrEqual`
157
- // `equal`: value must equal `equal`
158
- // `otherThan`: value must be anything other than `otherThan`
159
- // `even`: value must be an even number
160
- // `odd`: value must be an odd number
161
- // `positive`: value must be a positive number
162
- // `negative`: value must be a negative number
163
- //
164
- // { numericality: true }
165
- // { numericality: { integer: true } }
166
- // { numericality: { greaterThan: 3.5, message: '...' } }
167
- numericality: (value, name, options) => {
168
- if (typeof value !== "number") {
169
- validationError("typeNumericality", name, options);
170
- }
171
- if (typeof options === "boolean") {
172
- return;
173
- } else {
174
- if (options.integer && !Number.isInteger(value)) {
175
- validationError("integerNumericality", name, options);
176
- }
177
- if (options.lessThan != null && value >= options.lessThan) {
178
- validationError("lessThanNumericality", name, options, {
179
- lessThan: options.lessThan
180
- });
181
- }
182
- if (options.lessThanOrEqual != null && value > options.lessThanOrEqual) {
183
- validationError("lessThanOrEqualNumericality", name, options, {
184
- lessThanOrEqual: options.lessThanOrEqual
185
- });
186
- }
187
- if (options.greaterThan != null && value <= options.greaterThan) {
188
- validationError("greaterThanNumericality", name, options, {
189
- greaterThan: options.greaterThan
190
- });
191
- }
192
- if (options.greaterThanOrEqual != null && value < options.greaterThanOrEqual) {
193
- validationError("greaterThanOrEqualNumericality", name, options, {
194
- greaterThanOrEqual: options.greaterThanOrEqual
195
- });
196
- }
197
- if (options.equal != null && value !== options.equal) {
198
- validationError("equalNumericality", name, options, {
199
- equal: options.equal
200
- });
201
- }
202
- if (options.otherThan != null && value === options.otherThan) {
203
- validationError("otherThanNumericality", name, options, {
204
- otherThan: options.otherThan
205
- });
206
- }
207
- if (options.even && value % 2 !== 0) {
208
- validationError("evenNumericality", name, options);
209
- }
210
- if (options.odd && value % 2 !== 1) {
211
- validationError("oddNumericality", name, options);
212
- }
213
- if (options.positive && value <= 0) {
214
- validationError("positiveNumericality", name, options);
215
- }
216
- if (options.negative && value >= 0) {
217
- validationError("negativeNumericality", name, options);
218
- }
219
- }
220
- },
221
- // Requires that the given value is not `null` or `undefined`. By default will
222
- // consider an empty string to pass
223
- //
224
- // `allowEmptyString`: if set to `false` will throw an error if value is ""
225
- // `allowNull`: if `true` will allow `null`
226
- // `allowUndefined`: if `true` will allow `undefined`
227
- //
228
- // Default behavior is equivalent to:
229
- // { allowNull: false, allowUndefined: false, allowEmptyString: true }
230
- //
231
- // { presence: true }
232
- // { presence: { allowEmptyString: false, message: '...' } }
233
- presence: (value, name, options) => {
234
- const presenceOptions = {
235
- allowNull: false,
236
- allowUndefined: false,
237
- allowEmptyString: true
238
- };
239
- Object.assign(presenceOptions, options);
240
- if (!presenceOptions.allowNull && value === null || !presenceOptions.allowUndefined && value === void 0 || !presenceOptions.allowEmptyString && value === "") {
241
- validationError("presence", name, options);
242
- }
243
- },
244
- custom: (_value, name, options) => {
245
- try {
246
- options.with();
247
- } catch (e) {
248
- const message = options.message || e.message || e;
249
- validationError("custom", name, { message });
250
- }
251
- }
252
- };
253
- const fieldsToString = (fields) => {
254
- const output = [];
255
- for (const [key, _value] of Object.entries(fields)) {
256
- output.push(key);
257
- }
258
- return output.join(", ");
259
- };
260
- const validationError = (type, name, options, substitutions = {}) => {
261
- const pascalType = (0, import_pascalcase.default)(type);
262
- const errorClassName = `${pascalType}ValidationError`;
263
- const ErrorClass = ValidationErrors[errorClassName];
264
- const errorMessage = typeof options === "object" ? options.message : void 0;
265
- throw new ErrorClass(name, errorMessage, substitutions);
266
- };
267
- const prepareExclusionInclusion = (value, options) => {
268
- const inputList = Array.isArray(options) && options || options.in || [];
269
- const caseSensitive = Array.isArray(options) ? true : options.caseSensitive ?? true;
270
- return caseSensitive ? [inputList, value] : [
271
- inputList.map((s) => s.toLowerCase()),
272
- value.toLowerCase()
273
- ];
274
- };
275
- function validate(value, labelOrRecipe, recipe) {
276
- let label, validationRecipe;
277
- if (typeof labelOrRecipe === "object") {
278
- label = "";
279
- validationRecipe = labelOrRecipe;
280
- } else if (recipe) {
281
- label = labelOrRecipe;
282
- validationRecipe = recipe;
283
- } else {
284
- throw new Error("invalid options");
285
- }
286
- for (const [validator, options] of Object.entries(validationRecipe)) {
287
- if (typeof options === "undefined") {
288
- continue;
289
- }
290
- VALIDATORS[validator](value, label, options);
291
- }
292
- }
293
- const validateWithSync = (func) => {
294
- try {
295
- func();
296
- } catch (e) {
297
- const message = e.message || e;
298
- throw new ValidationErrors.ServiceValidationError(message);
299
- }
300
- };
301
- const validateWith = async (func) => {
302
- try {
303
- await func();
304
- } catch (e) {
305
- const message = e.message || e;
306
- throw new ValidationErrors.ServiceValidationError(message);
307
- }
308
- };
309
- async function validateUniqueness(model, fields, optionsOrCallback, callback) {
310
- const { $self, $scope, ...rest } = fields;
311
- let options = {};
312
- let validCallback;
313
- if (typeof optionsOrCallback === "function") {
314
- validCallback = optionsOrCallback;
315
- } else if (callback) {
316
- options = optionsOrCallback;
317
- validCallback = callback;
318
- } else {
319
- throw new Error("validateUniqueness requires a callback function");
320
- }
321
- const { db: _db, ...restOptions } = options;
322
- const db = options.db;
323
- options = restOptions;
324
- if (!db) {
325
- throw new Error(
326
- "validateUniqueness could not resolve a Prisma `db` instance. Pass `{ db }` in options, or ensure `src/lib/db` exports `db`"
327
- );
328
- }
329
- const where = {
330
- AND: [rest],
331
- NOT: []
332
- };
333
- if ($scope) {
334
- where.AND.push($scope);
335
- }
336
- if ($self) {
337
- where.NOT.push($self);
338
- }
339
- return await db.$transaction(async (tx) => {
340
- const found = await tx[model].findFirst({ where });
341
- if (found) {
342
- validationError("uniqueness", fieldsToString(rest), options);
343
- }
344
- return validCallback(tx);
345
- });
346
- }
347
- // Annotate the CommonJS export names for ESM import in node:
348
- 0 && (module.exports = {
349
- validate,
350
- validateUniqueness,
351
- validateWith,
352
- validateWithSync
353
- });
@@ -1,77 +0,0 @@
1
- import type { APIGatewayProxyEvent } from 'aws-lambda';
2
- import type { VerifyOptions, SupportedVerifierTypes } from '../auth/verifiers/common.js';
3
- import { WebhookVerificationError, DEFAULT_WEBHOOK_SECRET } from '../auth/verifiers/index.js';
4
- export type { VerifyOptions, SupportedVerifierTypes };
5
- export { WebhookVerificationError, DEFAULT_WEBHOOK_SECRET };
6
- export declare const DEFAULT_WEBHOOK_SIGNATURE_HEADER = "RW-WEBHOOK-SIGNATURE";
7
- /**
8
- * Extracts signature from Lambda Event.
9
- *
10
- * @param {APIGatewayProxyEvent} event - The event that includes the request details, like headers
11
- * @param {string} signatureHeader - The name of header key that contains the signature; defaults to DEFAULT_WEBHOOK_SIGNATURE_HEADER
12
- * @return {string} - The signature found in the headers specified by signatureHeader
13
- *
14
- * @example
15
- *
16
- * signatureFromEvent({ event: event })
17
- */
18
- export declare const signatureFromEvent: ({ event, signatureHeader, }: {
19
- event: APIGatewayProxyEvent;
20
- signatureHeader: string;
21
- }) => string;
22
- /**
23
- * Verifies event payload is signed with a valid webhook signature.
24
- *
25
- * @param {APIGatewayProxyEvent} event - The event that includes the body for the verification payload and request details, like headers.
26
- * @param {string} payload - If provided, the payload will be used to verify the signature instead of the event body.
27
- * @param {string} secret - The secret that will verify the signature according to the verifier type
28
- * @param {VerifyOptions} options - Options to specify the verifier type the header key that contains the signature, timestamp leeway.
29
- * @return {boolean | WebhookVerificationError} - Returns true if the signature is verified, or raises WebhookVerificationError.
30
- *
31
- * @example
32
- *
33
- * verifyEvent({ event: event, options: {} })*
34
- */
35
- export declare const verifyEvent: (type: SupportedVerifierTypes, { event, payload, secret, options, }: {
36
- event: APIGatewayProxyEvent;
37
- payload?: string;
38
- secret?: string;
39
- options?: VerifyOptions | undefined;
40
- }) => boolean | WebhookVerificationError;
41
- /**
42
- * Standalone verification of webhook signature given a payload, secret, verifier type and options.
43
- *
44
- * @param {string} payload - Body content of the event
45
- * @param {string} secret - The secret that will verify the signature according to the verifier type
46
- * @param {string} signature - Signature that verifies that the event
47
- * @param {VerifyOptions} options - Options to specify the verifier type the header key that contains the signature, timestamp leeway.
48
- * @return {boolean | WebhookVerificationError} - Returns true if the signature is verified, or raises WebhookVerificationError.
49
- *
50
- * @example
51
- *
52
- * verifySignature({ payload, secret, signature, options: {} })*
53
- */
54
- export declare const verifySignature: (type: SupportedVerifierTypes, { payload, secret, signature, options, }: {
55
- payload: string | Record<string, unknown>;
56
- secret: string;
57
- signature: string;
58
- options?: VerifyOptions | undefined;
59
- }) => boolean | WebhookVerificationError;
60
- /**
61
- * Signs a payload with a secret and verifier type method
62
- *
63
- * @param {string} payload - Body content of the event to sign
64
- * @param {string} secret - The secret that will verify the signature according to the verifier type
65
- * @param {VerifyOptions} options - Options to specify the verifier type the header key that contains the signature, timestamp leeway.
66
- * @return {string} - Returns signature
67
- *
68
- * @example
69
- *
70
- * signPayload({ payload, secret, options: {} })*
71
- */
72
- export declare const signPayload: (type: SupportedVerifierTypes, { payload, secret, options, }: {
73
- payload: string;
74
- secret: string;
75
- options?: VerifyOptions | undefined;
76
- }) => string;
77
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/webhooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEtD,OAAO,KAAK,EACV,aAAa,EACb,sBAAsB,EACvB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAEL,wBAAwB,EACxB,sBAAsB,EAEvB,MAAM,4BAA4B,CAAA;AAEnC,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,CAAA;AACrD,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,CAAA;AAC3D,eAAO,MAAM,gCAAgC,yBAAyB,CAAA;AActE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,GAAI,6BAGhC;IACD,KAAK,EAAE,oBAAoB,CAAA;IAC3B,eAAe,EAAE,MAAM,CAAA;CACxB,KAAG,MAGH,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,GACtB,MAAM,sBAAsB,EAC5B,sCAKG;IACD,KAAK,EAAE,oBAAoB,CAAA;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAA;CACpC,KACA,OAAO,GAAG,wBAgCZ,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,GAC1B,MAAM,sB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