@01.software/sdk 0.1.1 → 0.1.2
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/dist/{auth-BipHkgbu.d.cts → auth-AVOXtnYN.d.cts} +1 -1
- package/dist/{auth-Brdn6voY.d.ts → auth-c2UWJjPa.d.ts} +1 -1
- package/dist/auth.d.cts +2 -2
- package/dist/auth.d.ts +2 -2
- package/dist/index.cjs +27 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +27 -9
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-BE-5_Y2d.d.cts → payload-types-DFzDtXGO.d.cts} +247 -18
- package/dist/{payload-types-BE-5_Y2d.d.ts → payload-types-DFzDtXGO.d.ts} +247 -18
- package/dist/{webhook-D13_sbzU.d.ts → webhook-CGpSMkNA.d.ts} +1 -1
- package/dist/{webhook-Dg4AkcDQ.d.cts → webhook-DJCQSO6S.d.cts} +1 -1
- package/dist/webhook.cjs +6 -1
- package/dist/webhook.cjs.map +1 -1
- package/dist/webhook.d.cts +2 -2
- package/dist/webhook.d.ts +2 -2
- package/dist/webhook.js +6 -1
- package/dist/webhook.js.map +1 -1
- package/package.json +1 -1
|
@@ -17,10 +17,13 @@ interface Config {
|
|
|
17
17
|
blocks: {
|
|
18
18
|
Player: PlayerBlock;
|
|
19
19
|
Iframe: IframeBlock;
|
|
20
|
+
Code: CodeBlock;
|
|
20
21
|
};
|
|
21
22
|
collections: {
|
|
22
23
|
users: User;
|
|
23
24
|
media: Media;
|
|
25
|
+
audiences: Audience;
|
|
26
|
+
'email-logs': EmailLog;
|
|
24
27
|
tenants: Tenant;
|
|
25
28
|
'tenant-metadata': TenantMetadatum;
|
|
26
29
|
'tenant-logos': TenantLogo;
|
|
@@ -85,6 +88,8 @@ interface Config {
|
|
|
85
88
|
collectionsSelect: {
|
|
86
89
|
users: UsersSelect<false> | UsersSelect<true>;
|
|
87
90
|
media: MediaSelect<false> | MediaSelect<true>;
|
|
91
|
+
audiences: AudiencesSelect<false> | AudiencesSelect<true>;
|
|
92
|
+
'email-logs': EmailLogsSelect<false> | EmailLogsSelect<true>;
|
|
88
93
|
tenants: TenantsSelect<false> | TenantsSelect<true>;
|
|
89
94
|
'tenant-metadata': TenantMetadataSelect<false> | TenantMetadataSelect<true>;
|
|
90
95
|
'tenant-logos': TenantLogosSelect<false> | TenantLogosSelect<true>;
|
|
@@ -180,6 +185,17 @@ interface IframeBlock {
|
|
|
180
185
|
blockName?: string | null;
|
|
181
186
|
blockType: 'Iframe';
|
|
182
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* This interface was referenced by `Config`'s JSON-Schema
|
|
190
|
+
* via the `definition` "CodeBlock".
|
|
191
|
+
*/
|
|
192
|
+
interface CodeBlock {
|
|
193
|
+
language?: ('typescript' | 'javascript' | 'tsx' | 'python' | 'html' | 'css' | 'json' | 'bash' | 'sql' | 'graphql' | 'yaml' | 'markdown' | 'go' | 'rust' | 'java' | 'plaintext') | null;
|
|
194
|
+
code: string;
|
|
195
|
+
id?: string | null;
|
|
196
|
+
blockName?: string | null;
|
|
197
|
+
blockType: 'Code';
|
|
198
|
+
}
|
|
183
199
|
/**
|
|
184
200
|
* This interface was referenced by `Config`'s JSON-Schema
|
|
185
201
|
* via the `definition` "users".
|
|
@@ -192,6 +208,9 @@ interface User {
|
|
|
192
208
|
roles: ('tenant-admin' | 'tenant-viewer')[];
|
|
193
209
|
id?: string | null;
|
|
194
210
|
}[] | null;
|
|
211
|
+
emailPreferences?: {
|
|
212
|
+
usageAlerts?: boolean | null;
|
|
213
|
+
};
|
|
195
214
|
updatedAt: string;
|
|
196
215
|
createdAt: string;
|
|
197
216
|
email: string;
|
|
@@ -199,6 +218,8 @@ interface User {
|
|
|
199
218
|
resetPasswordExpiration?: string | null;
|
|
200
219
|
salt?: string | null;
|
|
201
220
|
hash?: string | null;
|
|
221
|
+
_verified?: boolean | null;
|
|
222
|
+
_verificationToken?: string | null;
|
|
202
223
|
loginAttempts?: number | null;
|
|
203
224
|
lockUntil?: string | null;
|
|
204
225
|
sessions?: {
|
|
@@ -217,7 +238,7 @@ interface Tenant {
|
|
|
217
238
|
name: string;
|
|
218
239
|
domain?: string | null;
|
|
219
240
|
features?: ('ecommerce' | 'playlists' | 'links' | 'forms' | 'galleries' | 'posts' | 'documents')[] | null;
|
|
220
|
-
plan: 'free' | 'basic' | 'pro' | 'enterprise';
|
|
241
|
+
plan: 'free' | 'starter' | 'basic' | 'pro' | 'enterprise';
|
|
221
242
|
clientKey: string;
|
|
222
243
|
secretKeys?: {
|
|
223
244
|
name: string;
|
|
@@ -257,6 +278,42 @@ interface Media {
|
|
|
257
278
|
focalX?: number | null;
|
|
258
279
|
focalY?: number | null;
|
|
259
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* This interface was referenced by `Config`'s JSON-Schema
|
|
283
|
+
* via the `definition` "audiences".
|
|
284
|
+
*/
|
|
285
|
+
interface Audience {
|
|
286
|
+
id: number;
|
|
287
|
+
email: string;
|
|
288
|
+
firstName?: string | null;
|
|
289
|
+
lastName?: string | null;
|
|
290
|
+
status: 'subscribed' | 'unsubscribed';
|
|
291
|
+
source: 'newsletter' | 'manual';
|
|
292
|
+
subscribedAt?: string | null;
|
|
293
|
+
unsubscribedAt?: string | null;
|
|
294
|
+
/**
|
|
295
|
+
* Resend Contact ID (auto-synced)
|
|
296
|
+
*/
|
|
297
|
+
resendContactId?: string | null;
|
|
298
|
+
updatedAt: string;
|
|
299
|
+
createdAt: string;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* This interface was referenced by `Config`'s JSON-Schema
|
|
303
|
+
* via the `definition` "email-logs".
|
|
304
|
+
*/
|
|
305
|
+
interface EmailLog {
|
|
306
|
+
id: number;
|
|
307
|
+
to: string;
|
|
308
|
+
from?: string | null;
|
|
309
|
+
subject: string;
|
|
310
|
+
type: 'usage-alert' | 'verification' | 'password-reset' | 'newsletter' | 'other';
|
|
311
|
+
status: 'sent' | 'failed';
|
|
312
|
+
sentAt: string;
|
|
313
|
+
error?: string | null;
|
|
314
|
+
updatedAt: string;
|
|
315
|
+
createdAt: string;
|
|
316
|
+
}
|
|
260
317
|
/**
|
|
261
318
|
* This interface was referenced by `Config`'s JSON-Schema
|
|
262
319
|
* via the `definition` "tenant-metadata".
|
|
@@ -442,6 +499,64 @@ interface BrandLogo {
|
|
|
442
499
|
height?: number | null;
|
|
443
500
|
focalX?: number | null;
|
|
444
501
|
focalY?: number | null;
|
|
502
|
+
sizes?: {
|
|
503
|
+
'16'?: {
|
|
504
|
+
url?: string | null;
|
|
505
|
+
width?: number | null;
|
|
506
|
+
height?: number | null;
|
|
507
|
+
mimeType?: string | null;
|
|
508
|
+
filesize?: number | null;
|
|
509
|
+
filename?: string | null;
|
|
510
|
+
};
|
|
511
|
+
'32'?: {
|
|
512
|
+
url?: string | null;
|
|
513
|
+
width?: number | null;
|
|
514
|
+
height?: number | null;
|
|
515
|
+
mimeType?: string | null;
|
|
516
|
+
filesize?: number | null;
|
|
517
|
+
filename?: string | null;
|
|
518
|
+
};
|
|
519
|
+
'64'?: {
|
|
520
|
+
url?: string | null;
|
|
521
|
+
width?: number | null;
|
|
522
|
+
height?: number | null;
|
|
523
|
+
mimeType?: string | null;
|
|
524
|
+
filesize?: number | null;
|
|
525
|
+
filename?: string | null;
|
|
526
|
+
};
|
|
527
|
+
'128'?: {
|
|
528
|
+
url?: string | null;
|
|
529
|
+
width?: number | null;
|
|
530
|
+
height?: number | null;
|
|
531
|
+
mimeType?: string | null;
|
|
532
|
+
filesize?: number | null;
|
|
533
|
+
filename?: string | null;
|
|
534
|
+
};
|
|
535
|
+
'180'?: {
|
|
536
|
+
url?: string | null;
|
|
537
|
+
width?: number | null;
|
|
538
|
+
height?: number | null;
|
|
539
|
+
mimeType?: string | null;
|
|
540
|
+
filesize?: number | null;
|
|
541
|
+
filename?: string | null;
|
|
542
|
+
};
|
|
543
|
+
'192'?: {
|
|
544
|
+
url?: string | null;
|
|
545
|
+
width?: number | null;
|
|
546
|
+
height?: number | null;
|
|
547
|
+
mimeType?: string | null;
|
|
548
|
+
filesize?: number | null;
|
|
549
|
+
filename?: string | null;
|
|
550
|
+
};
|
|
551
|
+
'512'?: {
|
|
552
|
+
url?: string | null;
|
|
553
|
+
width?: number | null;
|
|
554
|
+
height?: number | null;
|
|
555
|
+
mimeType?: string | null;
|
|
556
|
+
filesize?: number | null;
|
|
557
|
+
filename?: string | null;
|
|
558
|
+
};
|
|
559
|
+
};
|
|
445
560
|
}
|
|
446
561
|
/**
|
|
447
562
|
* This interface was referenced by `Config`'s JSON-Schema
|
|
@@ -515,11 +630,23 @@ interface ApiUsage {
|
|
|
515
630
|
*/
|
|
516
631
|
month: string;
|
|
517
632
|
count: number;
|
|
518
|
-
plan: 'free' | 'basic' | 'pro' | 'enterprise';
|
|
633
|
+
plan: 'free' | 'starter' | 'basic' | 'pro' | 'enterprise';
|
|
519
634
|
/**
|
|
520
635
|
* -1 means unlimited
|
|
521
636
|
*/
|
|
522
637
|
limit: number;
|
|
638
|
+
/**
|
|
639
|
+
* Storage usage in bytes
|
|
640
|
+
*/
|
|
641
|
+
storageUsed?: number | null;
|
|
642
|
+
/**
|
|
643
|
+
* Storage limit in bytes (-1 means unlimited)
|
|
644
|
+
*/
|
|
645
|
+
storageLimit?: number | null;
|
|
646
|
+
/**
|
|
647
|
+
* Total document count across all tenant-scoped collections
|
|
648
|
+
*/
|
|
649
|
+
totalDocuments?: number | null;
|
|
523
650
|
updatedAt: string;
|
|
524
651
|
createdAt: string;
|
|
525
652
|
}
|
|
@@ -1336,22 +1463,15 @@ interface GalleryImage {
|
|
|
1336
1463
|
*/
|
|
1337
1464
|
interface Form {
|
|
1338
1465
|
id: number;
|
|
1466
|
+
tenant?: (number | null) | Tenant;
|
|
1339
1467
|
title: string;
|
|
1340
|
-
description?:
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
}[];
|
|
1348
|
-
direction: ('ltr' | 'rtl') | null;
|
|
1349
|
-
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
|
|
1350
|
-
indent: number;
|
|
1351
|
-
version: number;
|
|
1352
|
-
};
|
|
1353
|
-
[k: string]: unknown;
|
|
1354
|
-
} | null;
|
|
1468
|
+
description?: string | null;
|
|
1469
|
+
status: 'active' | 'inactive';
|
|
1470
|
+
/**
|
|
1471
|
+
* When enabled, the slug will auto-generate from the title field on save and autosave.
|
|
1472
|
+
*/
|
|
1473
|
+
generateSlug?: boolean | null;
|
|
1474
|
+
slug?: string | null;
|
|
1355
1475
|
fields?: ({
|
|
1356
1476
|
name: string;
|
|
1357
1477
|
label?: string | null;
|
|
@@ -1510,6 +1630,7 @@ interface Form {
|
|
|
1510
1630
|
*/
|
|
1511
1631
|
interface FormSubmission {
|
|
1512
1632
|
id: number;
|
|
1633
|
+
tenant?: (number | null) | Tenant;
|
|
1513
1634
|
form: number | Form;
|
|
1514
1635
|
submissionData?: {
|
|
1515
1636
|
field: string;
|
|
@@ -1542,6 +1663,12 @@ interface PayloadLockedDocument {
|
|
|
1542
1663
|
} | null) | ({
|
|
1543
1664
|
relationTo: 'media';
|
|
1544
1665
|
value: number | Media;
|
|
1666
|
+
} | null) | ({
|
|
1667
|
+
relationTo: 'audiences';
|
|
1668
|
+
value: number | Audience;
|
|
1669
|
+
} | null) | ({
|
|
1670
|
+
relationTo: 'email-logs';
|
|
1671
|
+
value: number | EmailLog;
|
|
1545
1672
|
} | null) | ({
|
|
1546
1673
|
relationTo: 'tenants';
|
|
1547
1674
|
value: number | Tenant;
|
|
@@ -1689,6 +1816,9 @@ interface UsersSelect<T extends boolean = true> {
|
|
|
1689
1816
|
roles?: T;
|
|
1690
1817
|
id?: T;
|
|
1691
1818
|
};
|
|
1819
|
+
emailPreferences?: T | {
|
|
1820
|
+
usageAlerts?: T;
|
|
1821
|
+
};
|
|
1692
1822
|
updatedAt?: T;
|
|
1693
1823
|
createdAt?: T;
|
|
1694
1824
|
email?: T;
|
|
@@ -1696,6 +1826,8 @@ interface UsersSelect<T extends boolean = true> {
|
|
|
1696
1826
|
resetPasswordExpiration?: T;
|
|
1697
1827
|
salt?: T;
|
|
1698
1828
|
hash?: T;
|
|
1829
|
+
_verified?: T;
|
|
1830
|
+
_verificationToken?: T;
|
|
1699
1831
|
loginAttempts?: T;
|
|
1700
1832
|
lockUntil?: T;
|
|
1701
1833
|
sessions?: T | {
|
|
@@ -1726,6 +1858,37 @@ interface MediaSelect<T extends boolean = true> {
|
|
|
1726
1858
|
focalX?: T;
|
|
1727
1859
|
focalY?: T;
|
|
1728
1860
|
}
|
|
1861
|
+
/**
|
|
1862
|
+
* This interface was referenced by `Config`'s JSON-Schema
|
|
1863
|
+
* via the `definition` "audiences_select".
|
|
1864
|
+
*/
|
|
1865
|
+
interface AudiencesSelect<T extends boolean = true> {
|
|
1866
|
+
email?: T;
|
|
1867
|
+
firstName?: T;
|
|
1868
|
+
lastName?: T;
|
|
1869
|
+
status?: T;
|
|
1870
|
+
source?: T;
|
|
1871
|
+
subscribedAt?: T;
|
|
1872
|
+
unsubscribedAt?: T;
|
|
1873
|
+
resendContactId?: T;
|
|
1874
|
+
updatedAt?: T;
|
|
1875
|
+
createdAt?: T;
|
|
1876
|
+
}
|
|
1877
|
+
/**
|
|
1878
|
+
* This interface was referenced by `Config`'s JSON-Schema
|
|
1879
|
+
* via the `definition` "email-logs_select".
|
|
1880
|
+
*/
|
|
1881
|
+
interface EmailLogsSelect<T extends boolean = true> {
|
|
1882
|
+
to?: T;
|
|
1883
|
+
from?: T;
|
|
1884
|
+
subject?: T;
|
|
1885
|
+
type?: T;
|
|
1886
|
+
status?: T;
|
|
1887
|
+
sentAt?: T;
|
|
1888
|
+
error?: T;
|
|
1889
|
+
updatedAt?: T;
|
|
1890
|
+
createdAt?: T;
|
|
1891
|
+
}
|
|
1729
1892
|
/**
|
|
1730
1893
|
* This interface was referenced by `Config`'s JSON-Schema
|
|
1731
1894
|
* via the `definition` "tenants_select".
|
|
@@ -1869,6 +2032,9 @@ interface ApiUsageSelect<T extends boolean = true> {
|
|
|
1869
2032
|
count?: T;
|
|
1870
2033
|
plan?: T;
|
|
1871
2034
|
limit?: T;
|
|
2035
|
+
storageUsed?: T;
|
|
2036
|
+
storageLimit?: T;
|
|
2037
|
+
totalDocuments?: T;
|
|
1872
2038
|
updatedAt?: T;
|
|
1873
2039
|
createdAt?: T;
|
|
1874
2040
|
}
|
|
@@ -2057,6 +2223,64 @@ interface BrandLogosSelect<T extends boolean = true> {
|
|
|
2057
2223
|
height?: T;
|
|
2058
2224
|
focalX?: T;
|
|
2059
2225
|
focalY?: T;
|
|
2226
|
+
sizes?: T | {
|
|
2227
|
+
'16'?: T | {
|
|
2228
|
+
url?: T;
|
|
2229
|
+
width?: T;
|
|
2230
|
+
height?: T;
|
|
2231
|
+
mimeType?: T;
|
|
2232
|
+
filesize?: T;
|
|
2233
|
+
filename?: T;
|
|
2234
|
+
};
|
|
2235
|
+
'32'?: T | {
|
|
2236
|
+
url?: T;
|
|
2237
|
+
width?: T;
|
|
2238
|
+
height?: T;
|
|
2239
|
+
mimeType?: T;
|
|
2240
|
+
filesize?: T;
|
|
2241
|
+
filename?: T;
|
|
2242
|
+
};
|
|
2243
|
+
'64'?: T | {
|
|
2244
|
+
url?: T;
|
|
2245
|
+
width?: T;
|
|
2246
|
+
height?: T;
|
|
2247
|
+
mimeType?: T;
|
|
2248
|
+
filesize?: T;
|
|
2249
|
+
filename?: T;
|
|
2250
|
+
};
|
|
2251
|
+
'128'?: T | {
|
|
2252
|
+
url?: T;
|
|
2253
|
+
width?: T;
|
|
2254
|
+
height?: T;
|
|
2255
|
+
mimeType?: T;
|
|
2256
|
+
filesize?: T;
|
|
2257
|
+
filename?: T;
|
|
2258
|
+
};
|
|
2259
|
+
'180'?: T | {
|
|
2260
|
+
url?: T;
|
|
2261
|
+
width?: T;
|
|
2262
|
+
height?: T;
|
|
2263
|
+
mimeType?: T;
|
|
2264
|
+
filesize?: T;
|
|
2265
|
+
filename?: T;
|
|
2266
|
+
};
|
|
2267
|
+
'192'?: T | {
|
|
2268
|
+
url?: T;
|
|
2269
|
+
width?: T;
|
|
2270
|
+
height?: T;
|
|
2271
|
+
mimeType?: T;
|
|
2272
|
+
filesize?: T;
|
|
2273
|
+
filename?: T;
|
|
2274
|
+
};
|
|
2275
|
+
'512'?: T | {
|
|
2276
|
+
url?: T;
|
|
2277
|
+
width?: T;
|
|
2278
|
+
height?: T;
|
|
2279
|
+
mimeType?: T;
|
|
2280
|
+
filesize?: T;
|
|
2281
|
+
filename?: T;
|
|
2282
|
+
};
|
|
2283
|
+
};
|
|
2060
2284
|
}
|
|
2061
2285
|
/**
|
|
2062
2286
|
* This interface was referenced by `Config`'s JSON-Schema
|
|
@@ -2502,8 +2726,12 @@ interface GalleryImagesSelect<T extends boolean = true> {
|
|
|
2502
2726
|
* via the `definition` "forms_select".
|
|
2503
2727
|
*/
|
|
2504
2728
|
interface FormsSelect<T extends boolean = true> {
|
|
2729
|
+
tenant?: T;
|
|
2505
2730
|
title?: T;
|
|
2506
2731
|
description?: T;
|
|
2732
|
+
status?: T;
|
|
2733
|
+
generateSlug?: T;
|
|
2734
|
+
slug?: T;
|
|
2507
2735
|
fields?: T | {
|
|
2508
2736
|
checkbox?: T | {
|
|
2509
2737
|
name?: T;
|
|
@@ -2611,6 +2839,7 @@ interface FormsSelect<T extends boolean = true> {
|
|
|
2611
2839
|
* via the `definition` "form-submissions_select".
|
|
2612
2840
|
*/
|
|
2613
2841
|
interface FormSubmissionsSelect<T extends boolean = true> {
|
|
2842
|
+
tenant?: T;
|
|
2614
2843
|
form?: T;
|
|
2615
2844
|
submissionData?: T | {
|
|
2616
2845
|
field?: T;
|
|
@@ -2672,4 +2901,4 @@ declare module 'payload' {
|
|
|
2672
2901
|
}
|
|
2673
2902
|
}
|
|
2674
2903
|
|
|
2675
|
-
export type {
|
|
2904
|
+
export type { TenantLogosSelect as $, Audience as A, BrandLogo as B, Config as C, Document as D, EmailLog as E, GalleryImage as F, Gallery as G, Form as H, IframeBlock as I, FormSubmission as J, PayloadKv as K, PayloadLockedDocument as L, Media as M, PayloadPreference as N, Order as O, ProductOption as P, PayloadMigration as Q, Return as R, SupportedTimezones as S, Transaction as T, UserAuthOperations as U, UsersSelect as V, MediaSelect as W, AudiencesSelect as X, EmailLogsSelect as Y, TenantsSelect as Z, TenantMetadataSelect as _, OrderProduct as a, TenantOgImagesSelect as a0, ApiUsageSelect as a1, ProductsSelect as a2, ProductVariantsSelect as a3, ProductOptionsSelect as a4, ProductCategoriesSelect as a5, ProductTagsSelect as a6, ProductImagesSelect as a7, BrandsSelect as a8, BrandLogosSelect as a9, OrdersSelect as aa, OrderProductsSelect as ab, ReturnsSelect as ac, ReturnProductsSelect as ad, TransactionsSelect as ae, PostsSelect as af, PostCategoriesSelect as ag, PostTagsSelect as ah, PostImagesSelect as ai, AuthorsSelect as aj, DocumentsSelect as ak, DocumentCategoriesSelect as al, DocumentImagesSelect as am, PlaylistsSelect as an, PlaylistImagesSelect as ao, MusicsSelect as ap, GalleriesSelect as aq, GalleryImagesSelect as ar, FormsSelect as as, FormSubmissionsSelect as at, PayloadKvSelect as au, PayloadLockedDocumentsSelect as av, PayloadPreferencesSelect as aw, PayloadMigrationsSelect as ax, Auth as ay, PlayerBlock as b, CodeBlock as c, User as d, Tenant as e, TenantMetadatum as f, TenantOgImage as g, TenantLogo as h, ApiUsage as i, Product as j, ProductImage as k, ProductCategory as l, ProductTag as m, Brand as n, ProductVariant as o, ReturnProduct as p, Post as q, PostImage as r, Author as s, PostCategory as t, PostTag as u, DocumentCategory as v, DocumentImage as w, Playlist as x, PlaylistImage as y, Music as z };
|
package/dist/webhook.cjs
CHANGED
|
@@ -64,7 +64,12 @@ function verifySignature(payload, secret, signature) {
|
|
|
64
64
|
);
|
|
65
65
|
const sig = yield crypto.subtle.sign("HMAC", key, encoder.encode(payload));
|
|
66
66
|
const expected = Array.from(new Uint8Array(sig)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
67
|
-
|
|
67
|
+
if (expected.length !== signature.length) return false;
|
|
68
|
+
let result = 0;
|
|
69
|
+
for (let i = 0; i < expected.length; i++) {
|
|
70
|
+
result |= expected.charCodeAt(i) ^ signature.charCodeAt(i);
|
|
71
|
+
}
|
|
72
|
+
return result === 0;
|
|
68
73
|
});
|
|
69
74
|
}
|
|
70
75
|
function handleWebhook(request, handler, options) {
|
package/dist/webhook.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/webhook.ts","../src/core/webhook/index.tsx"],"sourcesContent":["export {\n handleWebhook,\n createTypedWebhookHandler,\n isValidWebhookEvent,\n} from './core/webhook'\nexport type {\n WebhookEvent,\n WebhookHandler,\n WebhookOperation,\n WebhookOptions,\n} from './core/webhook'\n","import type { Collection } from '../client/types'\nimport type { CollectionType } from '../collection/types'\n\nexport type WebhookOperation = 'create' | 'update'\n\nexport interface WebhookEvent<T extends Collection = Collection> {\n collection: T\n operation: WebhookOperation\n data: CollectionType<T>\n}\n\nexport type WebhookHandler<T extends Collection = Collection> = (\n event: WebhookEvent<T>,\n) => Promise<void> | void\n\nexport interface WebhookOptions {\n secret?: string\n}\n\nexport function isValidWebhookEvent(data: unknown): data is WebhookEvent {\n if (typeof data !== 'object' || data === null) return false\n const obj = data as Record<string, unknown>\n return (\n typeof obj.collection === 'string' &&\n (obj.operation === 'create' || obj.operation === 'update') &&\n typeof obj.data === 'object' &&\n obj.data !== null\n )\n}\n\nasync function verifySignature(\n payload: string,\n secret: string,\n signature: string,\n): Promise<boolean> {\n const encoder = new TextEncoder()\n const key = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n { name: 'HMAC', hash: 'SHA-256' },\n false,\n ['sign'],\n )\n const sig = await crypto.subtle.sign('HMAC', key, encoder.encode(payload))\n const expected = Array.from(new Uint8Array(sig))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n return expected
|
|
1
|
+
{"version":3,"sources":["../src/webhook.ts","../src/core/webhook/index.tsx"],"sourcesContent":["export {\n handleWebhook,\n createTypedWebhookHandler,\n isValidWebhookEvent,\n} from './core/webhook'\nexport type {\n WebhookEvent,\n WebhookHandler,\n WebhookOperation,\n WebhookOptions,\n} from './core/webhook'\n","import type { Collection } from '../client/types'\nimport type { CollectionType } from '../collection/types'\n\nexport type WebhookOperation = 'create' | 'update'\n\nexport interface WebhookEvent<T extends Collection = Collection> {\n collection: T\n operation: WebhookOperation\n data: CollectionType<T>\n}\n\nexport type WebhookHandler<T extends Collection = Collection> = (\n event: WebhookEvent<T>,\n) => Promise<void> | void\n\nexport interface WebhookOptions {\n secret?: string\n}\n\nexport function isValidWebhookEvent(data: unknown): data is WebhookEvent {\n if (typeof data !== 'object' || data === null) return false\n const obj = data as Record<string, unknown>\n return (\n typeof obj.collection === 'string' &&\n (obj.operation === 'create' || obj.operation === 'update') &&\n typeof obj.data === 'object' &&\n obj.data !== null\n )\n}\n\nasync function verifySignature(\n payload: string,\n secret: string,\n signature: string,\n): Promise<boolean> {\n const encoder = new TextEncoder()\n const key = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n { name: 'HMAC', hash: 'SHA-256' },\n false,\n ['sign'],\n )\n const sig = await crypto.subtle.sign('HMAC', key, encoder.encode(payload))\n const expected = Array.from(new Uint8Array(sig))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n // Constant-time comparison to prevent timing attacks\n if (expected.length !== signature.length) return false\n let result = 0\n for (let i = 0; i < expected.length; i++) {\n result |= expected.charCodeAt(i) ^ signature.charCodeAt(i)\n }\n return result === 0\n}\n\nexport async function handleWebhook<T extends Collection = Collection>(\n request: Request,\n handler: WebhookHandler<T>,\n options?: WebhookOptions,\n): Promise<Response> {\n try {\n const rawBody = await request.text()\n\n if (options?.secret) {\n const signature = request.headers.get('x-webhook-signature') || ''\n const valid = await verifySignature(rawBody, options.secret, signature)\n if (!valid) {\n return new Response(\n JSON.stringify({ error: 'Invalid webhook signature' }),\n { status: 401, headers: { 'Content-Type': 'application/json' } },\n )\n }\n }\n\n const body = JSON.parse(rawBody)\n\n if (!isValidWebhookEvent(body)) {\n return new Response(\n JSON.stringify({ error: 'Invalid webhook event format' }),\n { status: 400, headers: { 'Content-Type': 'application/json' } },\n )\n }\n\n await handler(body as WebhookEvent<T>)\n\n return new Response(\n JSON.stringify({ success: true, message: 'Webhook processed' }),\n { status: 200, headers: { 'Content-Type': 'application/json' } },\n )\n } catch (error) {\n console.error('Webhook processing error:', error)\n\n return new Response(\n JSON.stringify({\n error: 'Internal server error',\n message: error instanceof Error ? error.message : 'Unknown error',\n }),\n { status: 500, headers: { 'Content-Type': 'application/json' } },\n )\n }\n}\n\nexport function createTypedWebhookHandler<T extends Collection>(\n collection: T,\n handler: (event: WebhookEvent<T>) => Promise<void> | void,\n): WebhookHandler<T> {\n return async (event: WebhookEvent<T>) => {\n if (event.collection !== collection) {\n throw new Error(`Expected collection \"${collection}\", got \"${event.collection}\"`)\n }\n return handler(event)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmBO,SAAS,oBAAoB,MAAqC;AACvE,MAAI,OAAO,SAAS,YAAY,SAAS,KAAM,QAAO;AACtD,QAAM,MAAM;AACZ,SACE,OAAO,IAAI,eAAe,aACzB,IAAI,cAAc,YAAY,IAAI,cAAc,aACjD,OAAO,IAAI,SAAS,YACpB,IAAI,SAAS;AAEjB;AAEA,SAAe,gBACb,SACA,QACA,WACkB;AAAA;AAClB,UAAM,UAAU,IAAI,YAAY;AAChC,UAAM,MAAM,MAAM,OAAO,OAAO;AAAA,MAC9B;AAAA,MACA,QAAQ,OAAO,MAAM;AAAA,MACrB,EAAE,MAAM,QAAQ,MAAM,UAAU;AAAA,MAChC;AAAA,MACA,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9D,EAAE,QAAQ,KAAK,SAAS,EAAE,gBAAgB,mBAAmB,EAAE;AAAA,MACjE;AAAA,IACF,SAAS,OAAO;AACd,cAAQ,MAAM,6BAA6B,KAAK;AAEhD,aAAO,IAAI;AAAA,QACT,KAAK,UAAU;AAAA,UACb,OAAO;AAAA,UACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU;AAAA,QACpD,CAAC;AAAA,QACD,EAAE,QAAQ,KAAK,SAAS,EAAE,gBAAgB,mBAAmB,EAAE;AAAA,MACjE;AAAA,IACF;AAAA,EACF;AAAA;AAEO,SAAS,0BACd,YACA,SACmB;AACnB,SAAO,CAAO,UAA2B;AACvC,QAAI,MAAM,eAAe,YAAY;AACnC,YAAM,IAAI,MAAM,wBAAwB,UAAU,WAAW,MAAM,UAAU,GAAG;AAAA,IAClF;AACA,WAAO,QAAQ,KAAK;AAAA,EACtB;AACF;","names":[]}
|
package/dist/webhook.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { c as WebhookEvent, d as WebhookHandler, W as WebhookOperation, e as WebhookOptions, f as createTypedWebhookHandler, h as handleWebhook, i as isValidWebhookEvent } from './webhook-
|
|
2
|
-
import './payload-types-
|
|
1
|
+
export { c as WebhookEvent, d as WebhookHandler, W as WebhookOperation, e as WebhookOptions, f as createTypedWebhookHandler, h as handleWebhook, i as isValidWebhookEvent } from './webhook-DJCQSO6S.cjs';
|
|
2
|
+
import './payload-types-DFzDtXGO.cjs';
|
package/dist/webhook.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { c as WebhookEvent, d as WebhookHandler, W as WebhookOperation, e as WebhookOptions, f as createTypedWebhookHandler, h as handleWebhook, i as isValidWebhookEvent } from './webhook-
|
|
2
|
-
import './payload-types-
|
|
1
|
+
export { c as WebhookEvent, d as WebhookHandler, W as WebhookOperation, e as WebhookOptions, f as createTypedWebhookHandler, h as handleWebhook, i as isValidWebhookEvent } from './webhook-CGpSMkNA.js';
|
|
2
|
+
import './payload-types-DFzDtXGO.js';
|
package/dist/webhook.js
CHANGED
|
@@ -37,7 +37,12 @@ function verifySignature(payload, secret, signature) {
|
|
|
37
37
|
);
|
|
38
38
|
const sig = yield crypto.subtle.sign("HMAC", key, encoder.encode(payload));
|
|
39
39
|
const expected = Array.from(new Uint8Array(sig)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
40
|
-
|
|
40
|
+
if (expected.length !== signature.length) return false;
|
|
41
|
+
let result = 0;
|
|
42
|
+
for (let i = 0; i < expected.length; i++) {
|
|
43
|
+
result |= expected.charCodeAt(i) ^ signature.charCodeAt(i);
|
|
44
|
+
}
|
|
45
|
+
return result === 0;
|
|
41
46
|
});
|
|
42
47
|
}
|
|
43
48
|
function handleWebhook(request, handler, options) {
|
package/dist/webhook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/webhook/index.tsx"],"sourcesContent":["import type { Collection } from '../client/types'\nimport type { CollectionType } from '../collection/types'\n\nexport type WebhookOperation = 'create' | 'update'\n\nexport interface WebhookEvent<T extends Collection = Collection> {\n collection: T\n operation: WebhookOperation\n data: CollectionType<T>\n}\n\nexport type WebhookHandler<T extends Collection = Collection> = (\n event: WebhookEvent<T>,\n) => Promise<void> | void\n\nexport interface WebhookOptions {\n secret?: string\n}\n\nexport function isValidWebhookEvent(data: unknown): data is WebhookEvent {\n if (typeof data !== 'object' || data === null) return false\n const obj = data as Record<string, unknown>\n return (\n typeof obj.collection === 'string' &&\n (obj.operation === 'create' || obj.operation === 'update') &&\n typeof obj.data === 'object' &&\n obj.data !== null\n )\n}\n\nasync function verifySignature(\n payload: string,\n secret: string,\n signature: string,\n): Promise<boolean> {\n const encoder = new TextEncoder()\n const key = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n { name: 'HMAC', hash: 'SHA-256' },\n false,\n ['sign'],\n )\n const sig = await crypto.subtle.sign('HMAC', key, encoder.encode(payload))\n const expected = Array.from(new Uint8Array(sig))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n return expected
|
|
1
|
+
{"version":3,"sources":["../src/core/webhook/index.tsx"],"sourcesContent":["import type { Collection } from '../client/types'\nimport type { CollectionType } from '../collection/types'\n\nexport type WebhookOperation = 'create' | 'update'\n\nexport interface WebhookEvent<T extends Collection = Collection> {\n collection: T\n operation: WebhookOperation\n data: CollectionType<T>\n}\n\nexport type WebhookHandler<T extends Collection = Collection> = (\n event: WebhookEvent<T>,\n) => Promise<void> | void\n\nexport interface WebhookOptions {\n secret?: string\n}\n\nexport function isValidWebhookEvent(data: unknown): data is WebhookEvent {\n if (typeof data !== 'object' || data === null) return false\n const obj = data as Record<string, unknown>\n return (\n typeof obj.collection === 'string' &&\n (obj.operation === 'create' || obj.operation === 'update') &&\n typeof obj.data === 'object' &&\n obj.data !== null\n )\n}\n\nasync function verifySignature(\n payload: string,\n secret: string,\n signature: string,\n): Promise<boolean> {\n const encoder = new TextEncoder()\n const key = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n { name: 'HMAC', hash: 'SHA-256' },\n false,\n ['sign'],\n )\n const sig = await crypto.subtle.sign('HMAC', key, encoder.encode(payload))\n const expected = Array.from(new Uint8Array(sig))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n // Constant-time comparison to prevent timing attacks\n if (expected.length !== signature.length) return false\n let result = 0\n for (let i = 0; i < expected.length; i++) {\n result |= expected.charCodeAt(i) ^ signature.charCodeAt(i)\n }\n return result === 0\n}\n\nexport async function handleWebhook<T extends Collection = Collection>(\n request: Request,\n handler: WebhookHandler<T>,\n options?: WebhookOptions,\n): Promise<Response> {\n try {\n const rawBody = await request.text()\n\n if (options?.secret) {\n const signature = request.headers.get('x-webhook-signature') || ''\n const valid = await verifySignature(rawBody, options.secret, signature)\n if (!valid) {\n return new Response(\n JSON.stringify({ error: 'Invalid webhook signature' }),\n { status: 401, headers: { 'Content-Type': 'application/json' } },\n )\n }\n }\n\n const body = JSON.parse(rawBody)\n\n if (!isValidWebhookEvent(body)) {\n return new Response(\n JSON.stringify({ error: 'Invalid webhook event format' }),\n { status: 400, headers: { 'Content-Type': 'application/json' } },\n )\n }\n\n await handler(body as WebhookEvent<T>)\n\n return new Response(\n JSON.stringify({ success: true, message: 'Webhook processed' }),\n { status: 200, headers: { 'Content-Type': 'application/json' } },\n )\n } catch (error) {\n console.error('Webhook processing error:', error)\n\n return new Response(\n JSON.stringify({\n error: 'Internal server error',\n message: error instanceof Error ? error.message : 'Unknown error',\n }),\n { status: 500, headers: { 'Content-Type': 'application/json' } },\n )\n }\n}\n\nexport function createTypedWebhookHandler<T extends Collection>(\n collection: T,\n handler: (event: WebhookEvent<T>) => Promise<void> | void,\n): WebhookHandler<T> {\n return async (event: WebhookEvent<T>) => {\n if (event.collection !== collection) {\n throw new Error(`Expected collection \"${collection}\", got \"${event.collection}\"`)\n }\n return handler(event)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmBO,SAAS,oBAAoB,MAAqC;AACvE,MAAI,OAAO,SAAS,YAAY,SAAS,KAAM,QAAO;AACtD,QAAM,MAAM;AACZ,SACE,OAAO,IAAI,eAAe,aACzB,IAAI,cAAc,YAAY,IAAI,cAAc,aACjD,OAAO,IAAI,SAAS,YACpB,IAAI,SAAS;AAEjB;AAEA,SAAe,gBACb,SACA,QACA,WACkB;AAAA;AAClB,UAAM,UAAU,IAAI,YAAY;AAChC,UAAM,MAAM,MAAM,OAAO,OAAO;AAAA,MAC9B;AAAA,MACA,QAAQ,OAAO,MAAM;AAAA,MACrB,EAAE,MAAM,QAAQ,MAAM,UAAU;AAAA,MAChC;AAAA,MACA,CAAC,MAAM;AAAA,IACT;AACA,UAAM,MAAM,MAAM,OAAO,OAAO,KAAK,QAAQ,KAAK,QAAQ,OAAO,OAAO,CAAC;AACzE,UAAM,WAAW,MAAM,KAAK,IAAI,WAAW,GAAG,CAAC,EAC5C,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SA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