@plyaz/types 1.15.20 → 1.16.1
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/api/aws/index.d.ts +5 -0
- package/dist/api/aws/signature.d.ts +42 -0
- package/dist/api/endpoints/cdn/endpoints.d.ts +57 -0
- package/dist/api/endpoints/cdn/index.d.ts +6 -0
- package/dist/api/endpoints/cdn/types.d.ts +151 -0
- package/dist/api/endpoints/index.d.ts +2 -0
- package/dist/api/endpoints/types.d.ts +3 -1
- package/dist/api/endpoints/virustotal/endpoints.d.ts +37 -0
- package/dist/api/endpoints/virustotal/index.d.ts +6 -0
- package/dist/api/endpoints/virustotal/types.d.ts +202 -0
- package/dist/api/index.cjs +1317 -1
- package/dist/api/index.cjs.map +1 -1
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +1317 -1
- package/dist/api/index.js.map +1 -1
- package/dist/core/idempotency.d.ts +48 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/errors/codes.d.ts +296 -0
- package/dist/errors/enums.d.ts +10 -0
- package/dist/errors/index.cjs +1482 -1
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1482 -2
- package/dist/errors/index.js.map +1 -1
- package/dist/errors/validation.d.ts +71 -0
- package/dist/index.cjs +2268 -132
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.js +2227 -133
- package/dist/index.js.map +1 -1
- package/dist/logger/enums.d.ts +10 -0
- package/dist/notifications/types.d.ts +1 -2
- package/dist/storage/compliance.d.ts +247 -0
- package/dist/storage/enums.d.ts +527 -0
- package/dist/storage/event-handler-mapping.d.ts +69 -0
- package/dist/storage/index.d.ts +13 -0
- package/dist/storage/interfaces.d.ts +2242 -0
- package/dist/storage/plugins.d.ts +1056 -0
- package/dist/storage/schemas.d.ts +224 -0
- package/dist/storage/webhooks.d.ts +340 -0
- package/package.json +6 -1
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage Package Zod Schemas
|
|
3
|
+
* @module @plyaz/types/storage/schemas
|
|
4
|
+
*
|
|
5
|
+
* Validation schemas for storage webhooks and other features
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
/**
|
|
9
|
+
* Storage media processing job status
|
|
10
|
+
*/
|
|
11
|
+
export declare enum STORAGE_PROCESSING_STATUS {
|
|
12
|
+
Queued = "queued",
|
|
13
|
+
Processing = "processing",
|
|
14
|
+
Completed = "completed",
|
|
15
|
+
Failed = "failed"
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Storage media processing output schema
|
|
19
|
+
*/
|
|
20
|
+
export declare const StorageProcessingOutputSchema: z.ZodObject<{
|
|
21
|
+
url: z.ZodString;
|
|
22
|
+
format: z.ZodString;
|
|
23
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
24
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
25
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
26
|
+
size: z.ZodNumber;
|
|
27
|
+
bitrate: z.ZodOptional<z.ZodNumber>;
|
|
28
|
+
codec: z.ZodOptional<z.ZodString>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export type StorageProcessingOutput = z.infer<typeof StorageProcessingOutputSchema>;
|
|
31
|
+
/**
|
|
32
|
+
* Storage media processing webhook payload schema
|
|
33
|
+
*/
|
|
34
|
+
export declare const StorageMediaProcessingPayloadSchema: z.ZodObject<{
|
|
35
|
+
jobId: z.ZodString;
|
|
36
|
+
status: z.ZodEnum<typeof STORAGE_PROCESSING_STATUS>;
|
|
37
|
+
input: z.ZodObject<{
|
|
38
|
+
url: z.ZodString;
|
|
39
|
+
objectKey: z.ZodString;
|
|
40
|
+
bucket: z.ZodOptional<z.ZodString>;
|
|
41
|
+
}, z.core.$strip>;
|
|
42
|
+
output: z.ZodOptional<z.ZodObject<{
|
|
43
|
+
primary: z.ZodOptional<z.ZodObject<{
|
|
44
|
+
url: z.ZodString;
|
|
45
|
+
format: z.ZodString;
|
|
46
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
47
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
48
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
size: z.ZodNumber;
|
|
50
|
+
bitrate: z.ZodOptional<z.ZodNumber>;
|
|
51
|
+
codec: z.ZodOptional<z.ZodString>;
|
|
52
|
+
}, z.core.$strip>>;
|
|
53
|
+
thumbnail: z.ZodOptional<z.ZodObject<{
|
|
54
|
+
url: z.ZodString;
|
|
55
|
+
format: z.ZodString;
|
|
56
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
57
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
58
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
59
|
+
size: z.ZodNumber;
|
|
60
|
+
bitrate: z.ZodOptional<z.ZodNumber>;
|
|
61
|
+
codec: z.ZodOptional<z.ZodString>;
|
|
62
|
+
}, z.core.$strip>>;
|
|
63
|
+
variants: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
64
|
+
url: z.ZodString;
|
|
65
|
+
format: z.ZodString;
|
|
66
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
67
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
68
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
69
|
+
size: z.ZodNumber;
|
|
70
|
+
bitrate: z.ZodOptional<z.ZodNumber>;
|
|
71
|
+
codec: z.ZodOptional<z.ZodString>;
|
|
72
|
+
}, z.core.$strip>>>;
|
|
73
|
+
}, z.core.$strip>>;
|
|
74
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
75
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
76
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
77
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
78
|
+
format: z.ZodOptional<z.ZodString>;
|
|
79
|
+
codec: z.ZodOptional<z.ZodString>;
|
|
80
|
+
}, z.core.$strip>>;
|
|
81
|
+
progress: z.ZodOptional<z.ZodNumber>;
|
|
82
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
83
|
+
code: z.ZodString;
|
|
84
|
+
message: z.ZodString;
|
|
85
|
+
details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
86
|
+
}, z.core.$strip>>;
|
|
87
|
+
timestamp: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
88
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
89
|
+
}, z.core.$strip>;
|
|
90
|
+
export type StorageMediaProcessingPayload = z.infer<typeof StorageMediaProcessingPayloadSchema>;
|
|
91
|
+
/**
|
|
92
|
+
* ============================================================================
|
|
93
|
+
* Cloudflare R2 Webhook Schemas
|
|
94
|
+
* ============================================================================
|
|
95
|
+
* S3-compatible event notifications
|
|
96
|
+
* https://docs.aws.amazon.com/AmazonS3/latest/userguide/notification-content-structure.html
|
|
97
|
+
*/
|
|
98
|
+
export declare const R2EventRecordSchema: z.ZodObject<{
|
|
99
|
+
eventVersion: z.ZodString;
|
|
100
|
+
eventSource: z.ZodString;
|
|
101
|
+
awsRegion: z.ZodOptional<z.ZodString>;
|
|
102
|
+
eventTime: z.ZodString;
|
|
103
|
+
eventName: z.ZodString;
|
|
104
|
+
userIdentity: z.ZodOptional<z.ZodObject<{
|
|
105
|
+
principalId: z.ZodString;
|
|
106
|
+
}, z.core.$strip>>;
|
|
107
|
+
requestParameters: z.ZodOptional<z.ZodObject<{
|
|
108
|
+
sourceIPAddress: z.ZodString;
|
|
109
|
+
}, z.core.$strip>>;
|
|
110
|
+
responseElements: z.ZodOptional<z.ZodObject<{
|
|
111
|
+
'x-amz-request-id': z.ZodOptional<z.ZodString>;
|
|
112
|
+
'x-amz-id-2': z.ZodOptional<z.ZodString>;
|
|
113
|
+
}, z.core.$strip>>;
|
|
114
|
+
s3: z.ZodObject<{
|
|
115
|
+
s3SchemaVersion: z.ZodString;
|
|
116
|
+
configurationId: z.ZodOptional<z.ZodString>;
|
|
117
|
+
bucket: z.ZodObject<{
|
|
118
|
+
name: z.ZodString;
|
|
119
|
+
ownerIdentity: z.ZodOptional<z.ZodObject<{
|
|
120
|
+
principalId: z.ZodString;
|
|
121
|
+
}, z.core.$strip>>;
|
|
122
|
+
arn: z.ZodOptional<z.ZodString>;
|
|
123
|
+
}, z.core.$strip>;
|
|
124
|
+
object: z.ZodObject<{
|
|
125
|
+
key: z.ZodString;
|
|
126
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
127
|
+
eTag: z.ZodOptional<z.ZodString>;
|
|
128
|
+
versionId: z.ZodOptional<z.ZodString>;
|
|
129
|
+
sequencer: z.ZodOptional<z.ZodString>;
|
|
130
|
+
}, z.core.$strip>;
|
|
131
|
+
}, z.core.$strip>;
|
|
132
|
+
}, z.core.$strip>;
|
|
133
|
+
export declare const R2WebhookPayloadSchema: z.ZodObject<{
|
|
134
|
+
Records: z.ZodArray<z.ZodObject<{
|
|
135
|
+
eventVersion: z.ZodString;
|
|
136
|
+
eventSource: z.ZodString;
|
|
137
|
+
awsRegion: z.ZodOptional<z.ZodString>;
|
|
138
|
+
eventTime: z.ZodString;
|
|
139
|
+
eventName: z.ZodString;
|
|
140
|
+
userIdentity: z.ZodOptional<z.ZodObject<{
|
|
141
|
+
principalId: z.ZodString;
|
|
142
|
+
}, z.core.$strip>>;
|
|
143
|
+
requestParameters: z.ZodOptional<z.ZodObject<{
|
|
144
|
+
sourceIPAddress: z.ZodString;
|
|
145
|
+
}, z.core.$strip>>;
|
|
146
|
+
responseElements: z.ZodOptional<z.ZodObject<{
|
|
147
|
+
'x-amz-request-id': z.ZodOptional<z.ZodString>;
|
|
148
|
+
'x-amz-id-2': z.ZodOptional<z.ZodString>;
|
|
149
|
+
}, z.core.$strip>>;
|
|
150
|
+
s3: z.ZodObject<{
|
|
151
|
+
s3SchemaVersion: z.ZodString;
|
|
152
|
+
configurationId: z.ZodOptional<z.ZodString>;
|
|
153
|
+
bucket: z.ZodObject<{
|
|
154
|
+
name: z.ZodString;
|
|
155
|
+
ownerIdentity: z.ZodOptional<z.ZodObject<{
|
|
156
|
+
principalId: z.ZodString;
|
|
157
|
+
}, z.core.$strip>>;
|
|
158
|
+
arn: z.ZodOptional<z.ZodString>;
|
|
159
|
+
}, z.core.$strip>;
|
|
160
|
+
object: z.ZodObject<{
|
|
161
|
+
key: z.ZodString;
|
|
162
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
163
|
+
eTag: z.ZodOptional<z.ZodString>;
|
|
164
|
+
versionId: z.ZodOptional<z.ZodString>;
|
|
165
|
+
sequencer: z.ZodOptional<z.ZodString>;
|
|
166
|
+
}, z.core.$strip>;
|
|
167
|
+
}, z.core.$strip>;
|
|
168
|
+
}, z.core.$strip>>;
|
|
169
|
+
}, z.core.$strip>;
|
|
170
|
+
export type R2WebhookPayload = z.infer<typeof R2WebhookPayloadSchema>;
|
|
171
|
+
export type R2EventRecord = z.infer<typeof R2EventRecordSchema>;
|
|
172
|
+
/**
|
|
173
|
+
* ============================================================================
|
|
174
|
+
* Supabase Storage Webhook Schemas
|
|
175
|
+
* ============================================================================
|
|
176
|
+
* Database webhook events from storage.objects table
|
|
177
|
+
*/
|
|
178
|
+
export declare const SupabaseStorageObjectSchema: z.ZodObject<{
|
|
179
|
+
id: z.ZodUUID;
|
|
180
|
+
bucket_id: z.ZodString;
|
|
181
|
+
name: z.ZodString;
|
|
182
|
+
owner: z.ZodNullable<z.ZodOptional<z.ZodUUID>>;
|
|
183
|
+
created_at: z.ZodString;
|
|
184
|
+
updated_at: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
185
|
+
last_accessed_at: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
186
|
+
metadata: z.ZodNullable<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
187
|
+
version: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
188
|
+
owner_id: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
189
|
+
}, z.core.$strip>;
|
|
190
|
+
export declare const SupabaseWebhookPayloadSchema: z.ZodObject<{
|
|
191
|
+
type: z.ZodEnum<{
|
|
192
|
+
DELETE: "DELETE";
|
|
193
|
+
UPDATE: "UPDATE";
|
|
194
|
+
INSERT: "INSERT";
|
|
195
|
+
}>;
|
|
196
|
+
table: z.ZodLiteral<"objects">;
|
|
197
|
+
schema: z.ZodLiteral<"storage">;
|
|
198
|
+
record: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
199
|
+
id: z.ZodUUID;
|
|
200
|
+
bucket_id: z.ZodString;
|
|
201
|
+
name: z.ZodString;
|
|
202
|
+
owner: z.ZodNullable<z.ZodOptional<z.ZodUUID>>;
|
|
203
|
+
created_at: z.ZodString;
|
|
204
|
+
updated_at: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
205
|
+
last_accessed_at: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
206
|
+
metadata: z.ZodNullable<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
207
|
+
version: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
208
|
+
owner_id: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
209
|
+
}, z.core.$strip>>>;
|
|
210
|
+
old_record: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
211
|
+
id: z.ZodUUID;
|
|
212
|
+
bucket_id: z.ZodString;
|
|
213
|
+
name: z.ZodString;
|
|
214
|
+
owner: z.ZodNullable<z.ZodOptional<z.ZodUUID>>;
|
|
215
|
+
created_at: z.ZodString;
|
|
216
|
+
updated_at: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
217
|
+
last_accessed_at: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
218
|
+
metadata: z.ZodNullable<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
219
|
+
version: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
220
|
+
owner_id: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
221
|
+
}, z.core.$strip>>>;
|
|
222
|
+
}, z.core.$strip>;
|
|
223
|
+
export type SupabaseWebhookPayload = z.infer<typeof SupabaseWebhookPayloadSchema>;
|
|
224
|
+
export type SupabaseStorageObject = z.infer<typeof SupabaseStorageObjectSchema>;
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { type STORAGE_OPERATION, type STORAGE_SIGNATURE_METHOD, type STORAGE_WEBHOOK_EVENT_TYPE, type RETRY_STRATEGY } from './enums';
|
|
2
|
+
import type { CoreIdempotencyStoreConfig } from '../core';
|
|
3
|
+
/**
|
|
4
|
+
* Base webhook payload structure
|
|
5
|
+
*/
|
|
6
|
+
export interface StorageWebhookPayload<T = unknown> {
|
|
7
|
+
/** HTTP method */
|
|
8
|
+
method: string;
|
|
9
|
+
/** Request URL */
|
|
10
|
+
url: string;
|
|
11
|
+
/** HTTP headers */
|
|
12
|
+
headers: Record<string, string | string[]>;
|
|
13
|
+
/** Parsed body */
|
|
14
|
+
body: T;
|
|
15
|
+
/** Raw body (for signature verification) */
|
|
16
|
+
rawBody?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Processed webhook event
|
|
20
|
+
* This is what gets emitted after webhook processing
|
|
21
|
+
*/
|
|
22
|
+
export interface ProcessedStorageWebhookEvent {
|
|
23
|
+
/** Event type */
|
|
24
|
+
eventType: STORAGE_WEBHOOK_EVENT_TYPE;
|
|
25
|
+
/** File ID (if applicable) */
|
|
26
|
+
fileId?: string;
|
|
27
|
+
/** Bucket name */
|
|
28
|
+
bucketName?: string;
|
|
29
|
+
/** Bucket name (alias) */
|
|
30
|
+
bucket?: string;
|
|
31
|
+
/** Object key/path */
|
|
32
|
+
objectKey: string;
|
|
33
|
+
/** Storage operation */
|
|
34
|
+
operation: STORAGE_OPERATION;
|
|
35
|
+
/** Event timestamp */
|
|
36
|
+
timestamp: Date;
|
|
37
|
+
/** Provider name (r2, supabase, mediaconvert, etc.) */
|
|
38
|
+
provider: string;
|
|
39
|
+
/** File size in bytes */
|
|
40
|
+
fileSize?: number;
|
|
41
|
+
/** Content type */
|
|
42
|
+
contentType?: string;
|
|
43
|
+
/** ETag */
|
|
44
|
+
etag?: string;
|
|
45
|
+
/** Version ID */
|
|
46
|
+
versionId?: string;
|
|
47
|
+
/** Additional metadata */
|
|
48
|
+
metadata?: Record<string, unknown>;
|
|
49
|
+
/** Error message (if failed) */
|
|
50
|
+
error?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Webhook verification result
|
|
54
|
+
*/
|
|
55
|
+
export interface StorageWebhookVerificationResult {
|
|
56
|
+
/** Whether signature is valid */
|
|
57
|
+
valid: boolean;
|
|
58
|
+
/** Error message if invalid */
|
|
59
|
+
error?: string;
|
|
60
|
+
/** Additional verification details */
|
|
61
|
+
details?: Record<string, unknown>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Webhook processing result
|
|
65
|
+
*/
|
|
66
|
+
export interface StorageWebhookProcessingResult {
|
|
67
|
+
/** Whether processing succeeded */
|
|
68
|
+
success: boolean;
|
|
69
|
+
/** Processed events */
|
|
70
|
+
events: ProcessedStorageWebhookEvent[];
|
|
71
|
+
/** Whether this was a duplicate request (idempotency) */
|
|
72
|
+
duplicate?: boolean;
|
|
73
|
+
/** Error if processing failed */
|
|
74
|
+
error?: Error;
|
|
75
|
+
/** Processing metadata */
|
|
76
|
+
metadata?: {
|
|
77
|
+
/** Processing time in milliseconds */
|
|
78
|
+
processingTime?: number;
|
|
79
|
+
/** Number of events processed */
|
|
80
|
+
eventCount?: number;
|
|
81
|
+
/** Number of retry attempts made */
|
|
82
|
+
retryAttempts?: number;
|
|
83
|
+
/** Whether max retries were exceeded */
|
|
84
|
+
maxRetriesExceeded?: boolean;
|
|
85
|
+
/** Retry errors encountered */
|
|
86
|
+
retryErrors?: Array<{
|
|
87
|
+
attempt: number;
|
|
88
|
+
error: string;
|
|
89
|
+
timestamp: number;
|
|
90
|
+
}>;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Base webhook adapter configuration
|
|
95
|
+
*/
|
|
96
|
+
export interface StorageBaseWebhookAdapterConfig {
|
|
97
|
+
/** Webhook secret for signature verification */
|
|
98
|
+
secret: string;
|
|
99
|
+
/** Signature verification method */
|
|
100
|
+
signatureMethod?: STORAGE_SIGNATURE_METHOD;
|
|
101
|
+
/** Header containing signature */
|
|
102
|
+
signatureHeader?: string;
|
|
103
|
+
/** Header containing timestamp (for replay attack prevention) */
|
|
104
|
+
timestampHeader?: string;
|
|
105
|
+
/** Timestamp tolerance in milliseconds */
|
|
106
|
+
timestampTolerance?: number;
|
|
107
|
+
/** Allowed source IPs (CIDR notation) */
|
|
108
|
+
allowedIPs?: string[];
|
|
109
|
+
/** Logger instance */
|
|
110
|
+
logger?: unknown;
|
|
111
|
+
/** Security configuration (alternative to individual properties) */
|
|
112
|
+
security?: StorageWebhookSecurityConfig;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Security configuration for webhooks
|
|
116
|
+
*/
|
|
117
|
+
export interface StorageWebhookSecurityConfig {
|
|
118
|
+
/** Allowed source IPs (CIDR notation) */
|
|
119
|
+
allowedIPs?: string[];
|
|
120
|
+
/** Require IP whitelist check */
|
|
121
|
+
requireIPWhitelist?: boolean;
|
|
122
|
+
/** Maximum timestamp age in milliseconds (replay attack prevention) */
|
|
123
|
+
maxTimestampAge?: number;
|
|
124
|
+
/** Require timestamp validation */
|
|
125
|
+
requireTimestamp?: boolean;
|
|
126
|
+
/** Rate limit configuration */
|
|
127
|
+
rateLimit?: {
|
|
128
|
+
/** Maximum requests per window */
|
|
129
|
+
maxRequests: number;
|
|
130
|
+
/** Time window in milliseconds */
|
|
131
|
+
windowMs: number;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Webhook adapter interface
|
|
136
|
+
* Note: TSchema is the validation schema type (implementation detail is hidden)
|
|
137
|
+
*/
|
|
138
|
+
export interface StorageWebhookAdapter<TPayload = unknown, TSchema = unknown> {
|
|
139
|
+
/** Provider name (r2, supabase, mediaconvert, etc.) */
|
|
140
|
+
readonly providerName: string;
|
|
141
|
+
/** Event type this adapter handles */
|
|
142
|
+
readonly eventType: STORAGE_WEBHOOK_EVENT_TYPE | string;
|
|
143
|
+
/** Validation schema for payload (implementation agnostic) */
|
|
144
|
+
readonly schema: TSchema;
|
|
145
|
+
/** Priority (lower = higher priority, default: 100) */
|
|
146
|
+
readonly priority?: number;
|
|
147
|
+
/**
|
|
148
|
+
* Verify webhook signature
|
|
149
|
+
*/
|
|
150
|
+
verify(payload: StorageWebhookPayload<unknown>): StorageWebhookVerificationResult | Promise<StorageWebhookVerificationResult>;
|
|
151
|
+
/**
|
|
152
|
+
* Process webhook payload
|
|
153
|
+
*/
|
|
154
|
+
process(payload: StorageWebhookPayload<TPayload>): ProcessedStorageWebhookEvent[] | Promise<ProcessedStorageWebhookEvent[]>;
|
|
155
|
+
/**
|
|
156
|
+
* Generate idempotency key from payload
|
|
157
|
+
*/
|
|
158
|
+
getIdempotencyKey?(payload: StorageWebhookPayload<TPayload>): string;
|
|
159
|
+
/**
|
|
160
|
+
* Check if this adapter should process the webhook
|
|
161
|
+
* Useful when multiple adapters handle same provider/event
|
|
162
|
+
*/
|
|
163
|
+
shouldProcess?(payload: StorageWebhookPayload<unknown>): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Handle errors during processing
|
|
166
|
+
*/
|
|
167
|
+
handleError?(error: Error, payload: StorageWebhookPayload<unknown>): void | Promise<void>;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Webhook manager configuration
|
|
171
|
+
*/
|
|
172
|
+
export interface StorageWebhookManagerConfig {
|
|
173
|
+
/** Enable/disable webhook processing */
|
|
174
|
+
enabled?: boolean;
|
|
175
|
+
/** Webhook processing timeout in milliseconds */
|
|
176
|
+
timeout?: number;
|
|
177
|
+
/** Idempotency store configuration */
|
|
178
|
+
idempotency?: CoreIdempotencyStoreConfig;
|
|
179
|
+
/** Retry configuration */
|
|
180
|
+
retry?: StorageWebhookRetryConfig;
|
|
181
|
+
/** Security configuration */
|
|
182
|
+
security?: StorageWebhookSecurityConfig;
|
|
183
|
+
/** Webhook scope (service or adapter level) */
|
|
184
|
+
scope?: 'service' | 'adapter';
|
|
185
|
+
/** Adapter name (for adapter-level webhooks) */
|
|
186
|
+
adapterName?: string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Webhook retry configuration
|
|
190
|
+
*/
|
|
191
|
+
export interface StorageWebhookRetryConfig {
|
|
192
|
+
/** Enable/disable retry */
|
|
193
|
+
enabled?: boolean;
|
|
194
|
+
/** Retry strategy */
|
|
195
|
+
strategy?: RETRY_STRATEGY;
|
|
196
|
+
/** Maximum retry attempts */
|
|
197
|
+
maxAttempts?: number;
|
|
198
|
+
/** Initial delay in milliseconds */
|
|
199
|
+
initialDelay?: number;
|
|
200
|
+
/** Maximum delay in milliseconds */
|
|
201
|
+
maxDelay?: number;
|
|
202
|
+
/** Backoff multiplier for exponential strategy */
|
|
203
|
+
backoffMultiplier?: number;
|
|
204
|
+
/** Error codes that should NOT be retried (permanent failures) */
|
|
205
|
+
nonRetryableErrorCodes?: string[];
|
|
206
|
+
/** Callback on retry attempt */
|
|
207
|
+
onRetry?: (attempt: number, error: Error, payload: StorageWebhookPayload) => void;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* External idempotency store interface
|
|
211
|
+
*/
|
|
212
|
+
export interface StorageExternalIdempotencyStore {
|
|
213
|
+
/**
|
|
214
|
+
* Check if key exists
|
|
215
|
+
*/
|
|
216
|
+
has(key: string): Promise<boolean>;
|
|
217
|
+
/**
|
|
218
|
+
* Set key with TTL
|
|
219
|
+
*/
|
|
220
|
+
set(key: string, ttl: number, metadata?: Record<string, unknown>): Promise<void>;
|
|
221
|
+
/**
|
|
222
|
+
* Delete key
|
|
223
|
+
*/
|
|
224
|
+
delete(key: string): Promise<void>;
|
|
225
|
+
/**
|
|
226
|
+
* Clear all keys (optional)
|
|
227
|
+
*/
|
|
228
|
+
clear?(): Promise<void>;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Idempotency record
|
|
232
|
+
*/
|
|
233
|
+
export interface StorageIdempotencyRecord {
|
|
234
|
+
/** Unique key */
|
|
235
|
+
key: string;
|
|
236
|
+
/** When processed */
|
|
237
|
+
processedAt: Date;
|
|
238
|
+
/** When expires */
|
|
239
|
+
expiresAt: Date;
|
|
240
|
+
/** Additional metadata */
|
|
241
|
+
metadata?: Record<string, unknown>;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Webhook middleware
|
|
245
|
+
*/
|
|
246
|
+
export interface StorageWebhookMiddleware {
|
|
247
|
+
/** Middleware name */
|
|
248
|
+
name: string;
|
|
249
|
+
/** Priority (lower = runs earlier) */
|
|
250
|
+
priority?: number;
|
|
251
|
+
/**
|
|
252
|
+
* Run before webhook processing
|
|
253
|
+
* Can modify payload
|
|
254
|
+
*/
|
|
255
|
+
before?(payload: StorageWebhookPayload): Promise<StorageWebhookPayload | void>;
|
|
256
|
+
/**
|
|
257
|
+
* Run after webhook processing
|
|
258
|
+
* Can modify result
|
|
259
|
+
*/
|
|
260
|
+
after?(result: StorageWebhookProcessingResult, payload: StorageWebhookPayload): Promise<StorageWebhookProcessingResult | void>;
|
|
261
|
+
/**
|
|
262
|
+
* Handle errors
|
|
263
|
+
*/
|
|
264
|
+
onError?(error: Error, payload: StorageWebhookPayload): Promise<void>;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Webhook audit log entry
|
|
268
|
+
*/
|
|
269
|
+
export interface WebhookAuditLogEntry {
|
|
270
|
+
/** Unique audit ID */
|
|
271
|
+
id: string;
|
|
272
|
+
/** Event timestamp */
|
|
273
|
+
timestamp: Date;
|
|
274
|
+
/** Event type */
|
|
275
|
+
eventType: STORAGE_WEBHOOK_EVENT_TYPE | string;
|
|
276
|
+
/** Storage operation */
|
|
277
|
+
operation: STORAGE_OPERATION;
|
|
278
|
+
/** File ID */
|
|
279
|
+
fileId?: string;
|
|
280
|
+
/** Bucket name */
|
|
281
|
+
bucketName?: string;
|
|
282
|
+
/** Object key */
|
|
283
|
+
objectKey: string;
|
|
284
|
+
/** Provider name */
|
|
285
|
+
provider: string;
|
|
286
|
+
/** Source IP address */
|
|
287
|
+
sourceIP: string;
|
|
288
|
+
/** Whether signature was valid */
|
|
289
|
+
signatureValid: boolean;
|
|
290
|
+
/** Compliance checks results */
|
|
291
|
+
complianceChecks?: {
|
|
292
|
+
retentionPolicyRespected: boolean;
|
|
293
|
+
immutabilityRespected: boolean;
|
|
294
|
+
jurisdictionCompliant?: boolean;
|
|
295
|
+
};
|
|
296
|
+
/** Processing result */
|
|
297
|
+
result: 'success' | 'failed' | 'blocked' | 'duplicate';
|
|
298
|
+
/** Error message */
|
|
299
|
+
error?: string;
|
|
300
|
+
/** Additional metadata */
|
|
301
|
+
metadata?: Record<string, unknown>;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Storage service webhook configuration
|
|
305
|
+
* Can be configured at service level or adapter level
|
|
306
|
+
*/
|
|
307
|
+
export interface StorageWebhookConfig {
|
|
308
|
+
/** Enable/disable webhooks */
|
|
309
|
+
enabled?: boolean;
|
|
310
|
+
/** Webhook adapters to register */
|
|
311
|
+
adapters?: StorageWebhookAdapter[];
|
|
312
|
+
/** Webhook middleware */
|
|
313
|
+
middleware?: StorageWebhookMiddleware[];
|
|
314
|
+
/** Webhook manager configuration */
|
|
315
|
+
config?: StorageWebhookManagerConfig;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* ============================================================================
|
|
319
|
+
* Provider-Specific Webhook Config Interfaces
|
|
320
|
+
* ============================================================================
|
|
321
|
+
* Note: Schemas and types are in schemas.ts
|
|
322
|
+
*/
|
|
323
|
+
/**
|
|
324
|
+
* Cloudflare R2 Webhook Configuration
|
|
325
|
+
*/
|
|
326
|
+
export interface CloudflareR2WebhookConfig extends StorageBaseWebhookAdapterConfig {
|
|
327
|
+
/**
|
|
328
|
+
* Provider name (default: 'cloudflare-r2')
|
|
329
|
+
*/
|
|
330
|
+
providerName?: string;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Supabase Storage Webhook Configuration
|
|
334
|
+
*/
|
|
335
|
+
export interface SupabaseStorageWebhookConfig extends StorageBaseWebhookAdapterConfig {
|
|
336
|
+
/**
|
|
337
|
+
* Provider name (default: 'supabase-storage')
|
|
338
|
+
*/
|
|
339
|
+
providerName?: string;
|
|
340
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plyaz/types",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.1",
|
|
4
4
|
"author": "Redeemer Pace",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"description": "Provides shared TypeScript types and schema utilities for validation and parsing in the @playz ecosystem.",
|
|
@@ -185,6 +185,11 @@
|
|
|
185
185
|
"import": "./dist/payments/index.js",
|
|
186
186
|
"require": "./dist/payments/index.cjs"
|
|
187
187
|
},
|
|
188
|
+
"./storage": {
|
|
189
|
+
"types": "./dist/storage/index.d.ts",
|
|
190
|
+
"import": "./dist/storage/index.js",
|
|
191
|
+
"require": "./dist/storage/index.cjs"
|
|
192
|
+
},
|
|
188
193
|
"./db": {
|
|
189
194
|
"types": "./dist/db/index.d.ts",
|
|
190
195
|
"import": "./dist/db/index.js",
|