@cedarjs/api 9.0.0-canary.1784 → 9.0.0-canary.3124

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 (137) hide show
  1. package/dist/auth/index.d.ts +14 -1
  2. package/dist/auth/index.d.ts.map +1 -1
  3. package/dist/auth/index.js +19 -5
  4. package/dist/bins/cedar.js +14 -0
  5. package/dist/bins/cfw.js +14 -0
  6. package/dist/bins/redwood.js +14 -0
  7. package/dist/bins/tsc.js +8 -0
  8. package/dist/cache/clients/RedisClient.d.ts.map +1 -1
  9. package/dist/cache/index.d.ts.map +1 -1
  10. package/dist/cache/index.js +8 -4
  11. package/dist/errors.d.ts +9 -1
  12. package/dist/errors.d.ts.map +1 -1
  13. package/dist/errors.js +9 -2
  14. package/dist/index.d.ts +5 -4
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +5 -19
  17. package/dist/logger/index.d.ts +7 -5
  18. package/dist/logger/index.d.ts.map +1 -1
  19. package/dist/logger/index.js +1 -1
  20. package/dist/runtime.d.ts +48 -0
  21. package/dist/runtime.d.ts.map +1 -0
  22. package/dist/runtime.js +131 -0
  23. package/dist/signedTokens/index.d.ts +2 -0
  24. package/dist/signedTokens/index.d.ts.map +1 -0
  25. package/dist/signedTokens/index.js +1 -0
  26. package/dist/signedTokens/signedTokens.d.ts +99 -0
  27. package/dist/signedTokens/signedTokens.d.ts.map +1 -0
  28. package/dist/signedTokens/signedTokens.js +100 -0
  29. package/dist/transforms.d.ts +1 -0
  30. package/dist/transforms.d.ts.map +1 -1
  31. package/dist/transforms.js +82 -1
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/validations/validations.d.ts +21 -8
  34. package/dist/validations/validations.d.ts.map +1 -1
  35. package/dist/validations/validations.js +16 -14
  36. package/package.json +35 -46
  37. package/LICENSE +0 -21
  38. package/dist/cjs/auth/index.d.ts +0 -51
  39. package/dist/cjs/auth/index.d.ts.map +0 -1
  40. package/dist/cjs/auth/index.js +0 -129
  41. package/dist/cjs/auth/parseJWT.d.ts +0 -6
  42. package/dist/cjs/auth/parseJWT.d.ts.map +0 -1
  43. package/dist/cjs/auth/parseJWT.js +0 -57
  44. package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts +0 -18
  45. package/dist/cjs/auth/verifiers/base64Sha1Verifier.d.ts.map +0 -1
  46. package/dist/cjs/auth/verifiers/base64Sha1Verifier.js +0 -77
  47. package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts +0 -18
  48. package/dist/cjs/auth/verifiers/base64Sha256Verifier.d.ts.map +0 -1
  49. package/dist/cjs/auth/verifiers/base64Sha256Verifier.js +0 -77
  50. package/dist/cjs/auth/verifiers/common.d.ts +0 -112
  51. package/dist/cjs/auth/verifiers/common.d.ts.map +0 -1
  52. package/dist/cjs/auth/verifiers/common.js +0 -89
  53. package/dist/cjs/auth/verifiers/index.d.ts +0 -8
  54. package/dist/cjs/auth/verifiers/index.d.ts.map +0 -1
  55. package/dist/cjs/auth/verifiers/index.js +0 -39
  56. package/dist/cjs/auth/verifiers/jwtVerifier.d.ts +0 -18
  57. package/dist/cjs/auth/verifiers/jwtVerifier.d.ts.map +0 -1
  58. package/dist/cjs/auth/verifiers/jwtVerifier.js +0 -84
  59. package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts +0 -11
  60. package/dist/cjs/auth/verifiers/secretKeyVerifier.d.ts.map +0 -1
  61. package/dist/cjs/auth/verifiers/secretKeyVerifier.js +0 -43
  62. package/dist/cjs/auth/verifiers/sha1Verifier.d.ts +0 -17
  63. package/dist/cjs/auth/verifiers/sha1Verifier.d.ts.map +0 -1
  64. package/dist/cjs/auth/verifiers/sha1Verifier.js +0 -85
  65. package/dist/cjs/auth/verifiers/sha256Verifier.d.ts +0 -17
  66. package/dist/cjs/auth/verifiers/sha256Verifier.d.ts.map +0 -1
  67. package/dist/cjs/auth/verifiers/sha256Verifier.js +0 -85
  68. package/dist/cjs/auth/verifiers/skipVerifier.d.ts +0 -11
  69. package/dist/cjs/auth/verifiers/skipVerifier.d.ts.map +0 -1
  70. package/dist/cjs/auth/verifiers/skipVerifier.js +0 -40
  71. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts +0 -14
  72. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.d.ts.map +0 -1
  73. package/dist/cjs/auth/verifiers/timestampSchemeVerifier.js +0 -86
  74. package/dist/cjs/bins/cedar.d.ts +0 -9
  75. package/dist/cjs/bins/cedar.d.ts.map +0 -1
  76. package/dist/cjs/bins/cedar.js +0 -36
  77. package/dist/cjs/bins/cfw.d.ts +0 -3
  78. package/dist/cjs/bins/cfw.d.ts.map +0 -1
  79. package/dist/cjs/bins/cfw.js +0 -36
  80. package/dist/cjs/bins/redwood.d.ts +0 -9
  81. package/dist/cjs/bins/redwood.d.ts.map +0 -1
  82. package/dist/cjs/bins/redwood.js +0 -36
  83. package/dist/cjs/bins/tsc.d.ts +0 -3
  84. package/dist/cjs/bins/tsc.d.ts.map +0 -1
  85. package/dist/cjs/bins/tsc.js +0 -30
  86. package/dist/cjs/cache/clients/BaseClient.d.ts +0 -11
  87. package/dist/cjs/cache/clients/BaseClient.d.ts.map +0 -1
  88. package/dist/cjs/cache/clients/BaseClient.js +0 -31
  89. package/dist/cjs/cache/clients/InMemoryClient.d.ts +0 -31
  90. package/dist/cjs/cache/clients/InMemoryClient.d.ts.map +0 -1
  91. package/dist/cjs/cache/clients/InMemoryClient.js +0 -94
  92. package/dist/cjs/cache/clients/MemcachedClient.d.ts +0 -16
  93. package/dist/cjs/cache/clients/MemcachedClient.d.ts.map +0 -1
  94. package/dist/cjs/cache/clients/MemcachedClient.js +0 -79
  95. package/dist/cjs/cache/clients/RedisClient.d.ts +0 -20
  96. package/dist/cjs/cache/clients/RedisClient.d.ts.map +0 -1
  97. package/dist/cjs/cache/clients/RedisClient.js +0 -83
  98. package/dist/cjs/cache/errors.d.ts +0 -4
  99. package/dist/cjs/cache/errors.d.ts.map +0 -1
  100. package/dist/cjs/cache/errors.js +0 -33
  101. package/dist/cjs/cache/index.d.ts +0 -35
  102. package/dist/cjs/cache/index.d.ts.map +0 -1
  103. package/dist/cjs/cache/index.js +0 -171
  104. package/dist/cjs/cors.d.ts +0 -16
  105. package/dist/cjs/cors.d.ts.map +0 -1
  106. package/dist/cjs/cors.js +0 -93
  107. package/dist/cjs/errors.d.ts +0 -5
  108. package/dist/cjs/errors.d.ts.map +0 -1
  109. package/dist/cjs/errors.js +0 -38
  110. package/dist/cjs/event.d.ts +0 -3
  111. package/dist/cjs/event.d.ts.map +0 -1
  112. package/dist/cjs/event.js +0 -34
  113. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts +0 -4
  114. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts.map +0 -1
  115. package/dist/cjs/functions/fixtures/apiGatewayProxyEvent.fixture.js +0 -72
  116. package/dist/cjs/index.d.ts +0 -15
  117. package/dist/cjs/index.d.ts.map +0 -1
  118. package/dist/cjs/index.js +0 -70
  119. package/dist/cjs/logger/index.d.ts +0 -179
  120. package/dist/cjs/logger/index.d.ts.map +0 -1
  121. package/dist/cjs/logger/index.js +0 -195
  122. package/dist/cjs/package.json +0 -1
  123. package/dist/cjs/transforms.d.ts +0 -35
  124. package/dist/cjs/transforms.d.ts.map +0 -1
  125. package/dist/cjs/transforms.js +0 -98
  126. package/dist/cjs/types.d.ts +0 -25
  127. package/dist/cjs/types.d.ts.map +0 -1
  128. package/dist/cjs/types.js +0 -16
  129. package/dist/cjs/validations/errors.d.ts +0 -101
  130. package/dist/cjs/validations/errors.d.ts.map +0 -1
  131. package/dist/cjs/validations/errors.js +0 -298
  132. package/dist/cjs/validations/validations.d.ts +0 -222
  133. package/dist/cjs/validations/validations.d.ts.map +0 -1
  134. package/dist/cjs/validations/validations.js +0 -351
  135. package/dist/cjs/webhooks/index.d.ts +0 -77
  136. package/dist/cjs/webhooks/index.d.ts.map +0 -1
  137. package/dist/cjs/webhooks/index.js +0 -102
@@ -1,351 +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_client = require("@prisma/client");
38
- var import_pascalcase = __toESM(require("pascalcase"), 1);
39
- var ValidationErrors = __toESM(require("./errors.js"), 1);
40
- const VALIDATORS = {
41
- // Requires that the given value is `null` or `undefined`
42
- //
43
- // `allowEmptyString`: if true, counts "" as being absent (does not throw)
44
- //
45
- // { absence: true }
46
- // { absence: { allowEmptyString: true, message: '...' } }
47
- absence: (value, name, options) => {
48
- const absenceOptions = { allowEmptyString: false };
49
- Object.assign(absenceOptions, options);
50
- if (value === "") {
51
- if (!absenceOptions.allowEmptyString) {
52
- validationError("absence", name, options);
53
- }
54
- } else if (value != null) {
55
- validationError("absence", name, options);
56
- }
57
- },
58
- // Requires that the given field be `true` and nothing else, unless an array
59
- // of valid values is included with an `in` option
60
- //
61
- // { acceptance: true }
62
- // { acceptance: { in: ['true','1'], message: '...' } }
63
- acceptance: (value, name, options) => {
64
- let acceptedValues;
65
- if (typeof options === "object") {
66
- acceptedValues = options.in || [];
67
- } else {
68
- acceptedValues = [true];
69
- }
70
- if (!acceptedValues.includes(value)) {
71
- validationError("acceptance", name, options);
72
- }
73
- },
74
- // Requires that the given value be formatted like an email address. Uses a
75
- // very simple regex which checks for at least 1 character that is not an @,
76
- // then an @, then at least one character that isn't a period, then a period,
77
- // then any character. There cannot be any spaces present.
78
- //
79
- // { email: true }
80
- // { email: { message: '...' } }
81
- email: (value, name, options) => {
82
- const pattern = /^[^@\s]+@[^.\s]+\.[^\s]+$/;
83
- if (!pattern.test(String(value))) {
84
- validationError("email", name, options);
85
- }
86
- },
87
- // Requires that the given value NOT be in the list of possible values
88
- //
89
- // { exclusion: ['foo', 'bar'] }
90
- // { exclusion: { in: ['foo','bar'], message: '...' } }
91
- exclusion: (value, name, options) => {
92
- const [exclusionList, val] = prepareExclusionInclusion(value, options);
93
- if (exclusionList.includes(val)) {
94
- validationError("exclusion", name, options);
95
- }
96
- },
97
- // Requires that the given value match a regular expression
98
- //
99
- // { format: /^foobar$/ }
100
- // { format: { pattern: /^foobar$/, message: '...' } }
101
- format: (value, name, options) => {
102
- const pattern = options instanceof RegExp ? options : options.pattern;
103
- if (pattern == null) {
104
- throw new ValidationErrors.FormatValidationError(
105
- name,
106
- "No pattern for format validation"
107
- );
108
- }
109
- if (!pattern.test(String(value))) {
110
- validationError("format", name, options);
111
- }
112
- },
113
- // Requires that the given value be in the list of possible values
114
- //
115
- // { inclusion: ['foo', 'bar'] }
116
- // { inclusion: { in: ['foo','bar'], message: '...' } }
117
- inclusion: (value, name, options) => {
118
- const [inclusionList, val] = prepareExclusionInclusion(value, options);
119
- if (!inclusionList.includes(val)) {
120
- validationError("inclusion", name, options);
121
- }
122
- },
123
- // Requires that the given string be a certain length:
124
- //
125
- // `min`: must be at least `min` characters
126
- // `max`: must be no more than `max` characters
127
- // `equal`: must be exactly `equal` characters
128
- // `between`: an array consisting of the `min` and `max` length
129
- //
130
- // { length: { min: 4 } }
131
- // { length: { min: 2, max: 16 } }
132
- // { length: { between: [2, 16], message: '...' } }
133
- length: (value, name, options) => {
134
- const len = String(value).length;
135
- if (options.min && len < options.min) {
136
- validationError("minLength", name, options, { min: options.min });
137
- }
138
- if (options.max && len > options.max) {
139
- validationError("maxLength", name, options, { max: options.max });
140
- }
141
- if (options.equal && len !== options.equal) {
142
- validationError("equalLength", name, options, { equal: options.equal });
143
- }
144
- if (options.between && (len < options.between[0] || len > options.between[1])) {
145
- validationError("betweenLength", name, options, {
146
- min: options.between[0],
147
- max: options.between[1]
148
- });
149
- }
150
- },
151
- // Requires that number value meets some criteria:
152
- //
153
- // `integer`: value must be an integer
154
- // `lessThan`: value must be less than `lessThan`
155
- // `lessThanOrEqual`: value must be less than or equal to `lessThanOrEqual`
156
- // `greaterThan`: value must be greater than `greaterThan`
157
- // `greaterThanOrEqual`: value must be greater than or equal to `greaterThanOrEqual`
158
- // `equal`: value must equal `equal`
159
- // `otherThan`: value must be anything other than `otherThan`
160
- // `even`: value must be an even number
161
- // `odd`: value must be an odd number
162
- // `positive`: value must be a positive number
163
- // `negative`: value must be a negative number
164
- //
165
- // { numericality: true }
166
- // { numericality: { integer: true } }
167
- // { numericality: { greaterThan: 3.5, message: '...' } }
168
- numericality: (value, name, options) => {
169
- if (typeof value !== "number") {
170
- validationError("typeNumericality", name, options);
171
- }
172
- if (typeof options === "boolean") {
173
- return;
174
- } else {
175
- if (options.integer && !Number.isInteger(value)) {
176
- validationError("integerNumericality", name, options);
177
- }
178
- if (options.lessThan != null && value >= options.lessThan) {
179
- validationError("lessThanNumericality", name, options, {
180
- lessThan: options.lessThan
181
- });
182
- }
183
- if (options.lessThanOrEqual != null && value > options.lessThanOrEqual) {
184
- validationError("lessThanOrEqualNumericality", name, options, {
185
- lessThanOrEqual: options.lessThanOrEqual
186
- });
187
- }
188
- if (options.greaterThan != null && value <= options.greaterThan) {
189
- validationError("greaterThanNumericality", name, options, {
190
- greaterThan: options.greaterThan
191
- });
192
- }
193
- if (options.greaterThanOrEqual != null && value < options.greaterThanOrEqual) {
194
- validationError("greaterThanOrEqualNumericality", name, options, {
195
- greaterThanOrEqual: options.greaterThanOrEqual
196
- });
197
- }
198
- if (options.equal != null && value !== options.equal) {
199
- validationError("equalNumericality", name, options, {
200
- equal: options.equal
201
- });
202
- }
203
- if (options.otherThan != null && value === options.otherThan) {
204
- validationError("otherThanNumericality", name, options, {
205
- otherThan: options.otherThan
206
- });
207
- }
208
- if (options.even && value % 2 !== 0) {
209
- validationError("evenNumericality", name, options);
210
- }
211
- if (options.odd && value % 2 !== 1) {
212
- validationError("oddNumericality", name, options);
213
- }
214
- if (options.positive && value <= 0) {
215
- validationError("positiveNumericality", name, options);
216
- }
217
- if (options.negative && value >= 0) {
218
- validationError("negativeNumericality", name, options);
219
- }
220
- }
221
- },
222
- // Requires that the given value is not `null` or `undefined`. By default will
223
- // consider an empty string to pass
224
- //
225
- // `allowEmptyString`: if set to `false` will throw an error if value is ""
226
- // `allowNull`: if `true` will allow `null`
227
- // `allowUndefined`: if `true` will allow `undefined`
228
- //
229
- // Default behavior is equivalent to:
230
- // { allowNull: false, allowUndefined: false, allowEmptyString: true }
231
- //
232
- // { presence: true }
233
- // { presence: { allowEmptyString: false, message: '...' } }
234
- presence: (value, name, options) => {
235
- const presenceOptions = {
236
- allowNull: false,
237
- allowUndefined: false,
238
- allowEmptyString: true
239
- };
240
- Object.assign(presenceOptions, options);
241
- if (!presenceOptions.allowNull && value === null || !presenceOptions.allowUndefined && value === void 0 || !presenceOptions.allowEmptyString && value === "") {
242
- validationError("presence", name, options);
243
- }
244
- },
245
- custom: (_value, name, options) => {
246
- try {
247
- options.with();
248
- } catch (e) {
249
- const message = options.message || e.message || e;
250
- validationError("custom", name, { message });
251
- }
252
- }
253
- };
254
- const fieldsToString = (fields) => {
255
- const output = [];
256
- for (const [key, _value] of Object.entries(fields)) {
257
- output.push(key);
258
- }
259
- return output.join(", ");
260
- };
261
- const validationError = (type, name, options, substitutions = {}) => {
262
- const errorClassName = `${(0, import_pascalcase.default)(
263
- type
264
- )}ValidationError`;
265
- const ErrorClass = ValidationErrors[errorClassName];
266
- const errorMessage = typeof options === "object" ? options.message : void 0;
267
- throw new ErrorClass(name, errorMessage, substitutions);
268
- };
269
- const prepareExclusionInclusion = (value, options) => {
270
- const inputList = Array.isArray(options) && options || options.in || [];
271
- const caseSensitive = Array.isArray(options) ? true : options.caseSensitive ?? true;
272
- return caseSensitive ? [inputList, value] : [
273
- inputList.map((s) => s.toLowerCase()),
274
- value.toLowerCase()
275
- ];
276
- };
277
- function validate(value, labelOrRecipe, recipe) {
278
- let label, validationRecipe;
279
- if (typeof labelOrRecipe === "object") {
280
- label = "";
281
- validationRecipe = labelOrRecipe;
282
- } else {
283
- label = labelOrRecipe;
284
- validationRecipe = recipe;
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
- let db = null;
314
- if (typeof optionsOrCallback === "function") {
315
- validCallback = optionsOrCallback;
316
- } else {
317
- options = optionsOrCallback;
318
- validCallback = callback;
319
- }
320
- if (options.db) {
321
- const { db: customDb, ...restOptions } = options;
322
- options = restOptions;
323
- db = customDb;
324
- } else {
325
- db = new import_client.PrismaClient();
326
- }
327
- const where = {
328
- AND: [rest],
329
- NOT: []
330
- };
331
- if ($scope) {
332
- where.AND.push($scope);
333
- }
334
- if ($self) {
335
- where.NOT.push($self);
336
- }
337
- return await db.$transaction(async (tx) => {
338
- const found = await tx[model].findFirst({ where });
339
- if (found) {
340
- validationError("uniqueness", fieldsToString(fields), options);
341
- }
342
- return validCallback(tx);
343
- });
344
- }
345
- // Annotate the CommonJS export names for ESM import in node:
346
- 0 && (module.exports = {
347
- validate,
348
- validateUniqueness,
349
- validateWith,
350
- validateWithSync
351
- });
@@ -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
- });