@cedarjs/api 5.0.3 → 5.0.4-next.167

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 +17 -41
  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,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,sBAAsB,EAC5B,0CAKG;IACD,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAA;CACpC,KACA,OAAO,GAAG,wBAIZ,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,GACtB,MAAM,sBAAsB,EAC5B,+BAIG;IACD,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAA;CACpC,KACA,MAIF,CAAA"}
@@ -1,102 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var webhooks_exports = {};
20
- __export(webhooks_exports, {
21
- DEFAULT_WEBHOOK_SECRET: () => import_verifiers.DEFAULT_WEBHOOK_SECRET,
22
- DEFAULT_WEBHOOK_SIGNATURE_HEADER: () => DEFAULT_WEBHOOK_SIGNATURE_HEADER,
23
- WebhookVerificationError: () => import_verifiers.WebhookVerificationError,
24
- signPayload: () => signPayload,
25
- signatureFromEvent: () => signatureFromEvent,
26
- verifyEvent: () => verifyEvent,
27
- verifySignature: () => verifySignature
28
- });
29
- module.exports = __toCommonJS(webhooks_exports);
30
- var import_verifiers = require("../auth/verifiers/index.js");
31
- const DEFAULT_WEBHOOK_SIGNATURE_HEADER = "RW-WEBHOOK-SIGNATURE";
32
- const eventBody = (event) => {
33
- if (event.isBase64Encoded) {
34
- return Buffer.from(event.body || "", "base64").toString("utf-8");
35
- } else {
36
- return event.body || "";
37
- }
38
- };
39
- const signatureFromEvent = ({
40
- event,
41
- signatureHeader = DEFAULT_WEBHOOK_SIGNATURE_HEADER
42
- }) => {
43
- const header = signatureHeader.toLocaleLowerCase();
44
- return event.headers[header];
45
- };
46
- const verifyEvent = (type, {
47
- event,
48
- payload,
49
- secret = import_verifiers.DEFAULT_WEBHOOK_SECRET,
50
- options
51
- }) => {
52
- let body = "";
53
- if (payload) {
54
- body = payload;
55
- } else {
56
- body = eventBody(event);
57
- }
58
- let signature = signatureFromEvent({
59
- event,
60
- signatureHeader: options?.signatureHeader || DEFAULT_WEBHOOK_SIGNATURE_HEADER
61
- });
62
- if (options?.signatureTransformer) {
63
- signature = options.signatureTransformer(signature);
64
- }
65
- if (options?.eventTimestamp) {
66
- const timestamp = options?.currentTimestampOverride ?? Date.now();
67
- const difference = Math.abs(timestamp - options?.eventTimestamp);
68
- const tolerance = options?.tolerance ?? import_verifiers.DEFAULT_TOLERANCE;
69
- if (difference > tolerance) {
70
- throw new import_verifiers.WebhookVerificationError();
71
- }
72
- }
73
- const { verify } = (0, import_verifiers.createVerifier)(type, options);
74
- return verify({ payload: body, secret, signature });
75
- };
76
- const verifySignature = (type, {
77
- payload,
78
- secret = import_verifiers.DEFAULT_WEBHOOK_SECRET,
79
- signature,
80
- options
81
- }) => {
82
- const { verify } = (0, import_verifiers.createVerifier)(type, options);
83
- return verify({ payload, secret, signature });
84
- };
85
- const signPayload = (type, {
86
- payload,
87
- secret = import_verifiers.DEFAULT_WEBHOOK_SECRET,
88
- options
89
- }) => {
90
- const { sign } = (0, import_verifiers.createVerifier)(type, options);
91
- return sign({ payload, secret });
92
- };
93
- // Annotate the CommonJS export names for ESM import in node:
94
- 0 && (module.exports = {
95
- DEFAULT_WEBHOOK_SECRET,
96
- DEFAULT_WEBHOOK_SIGNATURE_HEADER,
97
- WebhookVerificationError,
98
- signPayload,
99
- signatureFromEvent,
100
- verifyEvent,
101
- verifySignature
102
- });