svix 2.0.0 → 2.2.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svix",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Svix webhooks API client and webhook verification library",
5
5
  "author": "svix",
6
6
  "repository": "https://github.com/svix/svix-webhooks",
@@ -35,7 +35,7 @@
35
35
  "fmt": "biome format --write"
36
36
  },
37
37
  "dependencies": {
38
- "standardwebhooks": "1.0.0"
38
+ "standardwebhooks": "^1.1.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@biomejs/biome": "2.2.4",
@@ -1,5 +1,13 @@
1
1
  // this file is @generated
2
2
 
3
+ import {
4
+ type BulkExpungeContentsIn,
5
+ BulkExpungeContentsInSerializer,
6
+ } from "../models/bulkExpungeContentsIn";
7
+ import {
8
+ type BulkExpungeContentsOut,
9
+ BulkExpungeContentsOutSerializer,
10
+ } from "../models/bulkExpungeContentsOut";
3
11
  import {
4
12
  type ExpungeAllContentsOut,
5
13
  ExpungeAllContentsOutSerializer,
@@ -67,6 +75,10 @@ export interface MessageGetOptions {
67
75
  withContent?: boolean;
68
76
  }
69
77
 
78
+ export interface MessageBulkExpungeContentOptions {
79
+ idempotencyKey?: string;
80
+ }
81
+
70
82
  export interface MessageExpungeAllContentsOptions {
71
83
  idempotencyKey?: string;
72
84
  }
@@ -190,7 +202,8 @@ export class Message {
190
202
  * Delete the given message's payload.
191
203
  *
192
204
  * Useful in cases when a message was accidentally sent with sensitive content.
193
- * The message can't be replayed or resent once its payload has been deleted or expired.
205
+ * The message can't be replayed or resent once its payload has been deleted
206
+ * (or has expired).
194
207
  */
195
208
  public async expungeContent(appId: string, msgId: string): Promise<void> {
196
209
  const request = new SvixRequest(
@@ -204,6 +217,33 @@ export class Message {
204
217
  return await request.sendNoResponseBody(this.requestCtx);
205
218
  }
206
219
 
220
+ /**
221
+ * Delete the payloads from the given messages under the current application
222
+ *
223
+ * Useful in cases when a message was accidentally sent with sensitive content.
224
+ * A message can't be replayed or resent once its payload has been deleted
225
+ * (or has expired).
226
+ */
227
+ public async bulkExpungeContent(
228
+ appId: string,
229
+ bulkExpungeContentsIn: BulkExpungeContentsIn = {},
230
+ options?: MessageBulkExpungeContentOptions
231
+ ): Promise<BulkExpungeContentsOut> {
232
+ const request = new SvixRequest(
233
+ HttpMethod.POST,
234
+ "/api/v1/app/{app_id}/msg/bulk-expunge"
235
+ );
236
+
237
+ request.setPathParam("app_id", appId);
238
+ request.setHeaderParam("idempotency-key", options?.idempotencyKey);
239
+ request.setBody(BulkExpungeContentsInSerializer._toJsonObject(bulkExpungeContentsIn));
240
+
241
+ return await request.send(
242
+ this.requestCtx,
243
+ BulkExpungeContentsOutSerializer._fromJsonObject
244
+ );
245
+ }
246
+
207
247
  /**
208
248
  * Delete all message payloads for the application.
209
249
  *
@@ -0,0 +1,20 @@
1
+ // this file is @generated
2
+
3
+ export interface BulkExpungeContentsIn {
4
+ /** Message ID or UID to delete */
5
+ ids?: string[];
6
+ }
7
+
8
+ export const BulkExpungeContentsInSerializer = {
9
+ _fromJsonObject(object: any): BulkExpungeContentsIn {
10
+ return {
11
+ ids: object["ids"],
12
+ };
13
+ },
14
+
15
+ _toJsonObject(self: BulkExpungeContentsIn): any {
16
+ return {
17
+ ids: self.ids,
18
+ };
19
+ },
20
+ };
@@ -0,0 +1,33 @@
1
+ // this file is @generated
2
+ import { type BulkExpungeStatus, BulkExpungeStatusSerializer } from "./bulkExpungeStatus";
3
+
4
+ export interface BulkExpungeContentsOut {
5
+ /** Results of expunging (by ID) */
6
+ results: { [key: string]: BulkExpungeStatus };
7
+ }
8
+
9
+ export const BulkExpungeContentsOutSerializer = {
10
+ _fromJsonObject(object: any): BulkExpungeContentsOut {
11
+ return {
12
+ results: Object.fromEntries(
13
+ Object.entries<BulkExpungeStatus>(object["results"]).map(
14
+ (item: [string, BulkExpungeStatus]) => [
15
+ item[0],
16
+ BulkExpungeStatusSerializer._fromJsonObject(item[1]),
17
+ ]
18
+ )
19
+ ),
20
+ };
21
+ },
22
+
23
+ _toJsonObject(self: BulkExpungeContentsOut): any {
24
+ return {
25
+ results: Object.fromEntries(
26
+ Object.entries(self.results).map((item) => [
27
+ item[0],
28
+ BulkExpungeStatusSerializer._toJsonObject(item[1]),
29
+ ])
30
+ ),
31
+ };
32
+ },
33
+ };
@@ -0,0 +1,16 @@
1
+ // this file is @generated
2
+
3
+ export enum BulkExpungeStatus {
4
+ Expunged = "expunged",
5
+ NotFound = "not-found",
6
+ }
7
+
8
+ export const BulkExpungeStatusSerializer = {
9
+ _fromJsonObject(object: any): BulkExpungeStatus {
10
+ return object;
11
+ },
12
+
13
+ _toJsonObject(self: BulkExpungeStatus): any {
14
+ return self;
15
+ },
16
+ };
@@ -23,6 +23,9 @@ export { BackgroundTaskType } from "./backgroundTaskType";
23
23
  export { type BigQueryConfigIn } from "./bigQueryConfigIn";
24
24
  export { type BigQueryConfigOut } from "./bigQueryConfigOut";
25
25
  export { type BigQueryConfigPatch } from "./bigQueryConfigPatch";
26
+ export { type BulkExpungeContentsIn } from "./bulkExpungeContentsIn";
27
+ export { type BulkExpungeContentsOut } from "./bulkExpungeContentsOut";
28
+ export { BulkExpungeStatus } from "./bulkExpungeStatus";
26
29
  export { type BulkReplayIn } from "./bulkReplayIn";
27
30
  export { type CheckbookConfig } from "./checkbookConfig";
28
31
  export { type CheckbookConfigOut } from "./checkbookConfigOut";
package/src/request.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ApiException, type XOR } from "./util";
2
2
  import type { HttpErrorOut, HTTPValidationError } from "./HttpErrors";
3
3
 
4
- export const LIB_VERSION = "2.0.0";
4
+ export const LIB_VERSION = "2.2.0";
5
5
 
6
6
  function getUserAgent() {
7
7
  var fields = [`svix-libs/${LIB_VERSION}/javascript`];
@@ -124,7 +124,7 @@ test("partial signature throws error", () => {
124
124
  }, WebhookVerificationError);
125
125
  });
126
126
 
127
- test("valid signature is valid and returns valid json", () => {
127
+ test("valid signature is valid", () => {
128
128
  const wh = new Webhook("MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw");
129
129
 
130
130
  const testPayload = new TestPayload();
@@ -132,7 +132,7 @@ test("valid signature is valid and returns valid json", () => {
132
132
  wh.verify(testPayload.payload, testPayload.header);
133
133
  });
134
134
 
135
- test("valid unbranded signature is valid and returns valid json", () => {
135
+ test("valid unbranded signature is valid", () => {
136
136
  const wh = new Webhook("MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw");
137
137
 
138
138
  const testPayload = new TestPayload();
package/src/webhook.ts CHANGED
@@ -30,7 +30,7 @@ export class Webhook {
30
30
  | WebhookRequiredHeaders
31
31
  | WebhookUnbrandedRequiredHeaders
32
32
  | Record<string, string>
33
- ): unknown {
33
+ ): undefined {
34
34
  const headers: Record<string, string> = {};
35
35
  for (const key of Object.keys(headers_)) {
36
36
  headers[key.toLowerCase()] = (headers_ as Record<string, string>)[key];
@@ -42,7 +42,7 @@ export class Webhook {
42
42
  headers["webhook-timestamp"] =
43
43
  headers["svix-timestamp"] ?? headers["webhook-timestamp"] ?? "";
44
44
 
45
- return this.inner.verify(payload, headers);
45
+ this.inner.verify(payload, headers, { jsonParse: false });
46
46
  }
47
47
 
48
48
  public sign(msgId: string, timestamp: Date, payload: string | Buffer): string {