@siteping/adapter-drizzle 0.1.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/README.md +40 -0
- package/dist/chunk-6G6UAERF.js +814 -0
- package/dist/chunk-6G6UAERF.js.map +1 -0
- package/dist/chunk-ICY2AW6S.js +11 -0
- package/dist/chunk-ICY2AW6S.js.map +1 -0
- package/dist/concurrency.d.cts +14 -0
- package/dist/concurrency.d.ts +14 -0
- package/dist/deep-link.d.cts +14 -0
- package/dist/deep-link.d.ts +14 -0
- package/dist/email.d.cts +22 -0
- package/dist/email.d.ts +22 -0
- package/dist/errors.d.cts +55 -0
- package/dist/errors.d.ts +55 -0
- package/dist/filters.d.cts +82 -0
- package/dist/filters.d.ts +82 -0
- package/dist/i18n.d.cts +85 -0
- package/dist/i18n.d.ts +85 -0
- package/dist/index.cjs +33 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +45 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/libsql.cjs +1045 -0
- package/dist/libsql.cjs.map +1 -0
- package/dist/libsql.d.cts +1015 -0
- package/dist/libsql.d.ts +1015 -0
- package/dist/libsql.js +254 -0
- package/dist/libsql.js.map +1 -0
- package/dist/pg.cjs +1079 -0
- package/dist/pg.cjs.map +1 -0
- package/dist/pg.d.cts +968 -0
- package/dist/pg.d.ts +968 -0
- package/dist/pg.js +298 -0
- package/dist/pg.js.map +1 -0
- package/dist/schema.d.cts +317 -0
- package/dist/schema.d.ts +317 -0
- package/dist/screenshot-storage.d.cts +103 -0
- package/dist/screenshot-storage.d.ts +103 -0
- package/dist/siteping-core.d.cts +20 -0
- package/dist/siteping-core.d.ts +20 -0
- package/dist/store-helpers.d.cts +140 -0
- package/dist/store-helpers.d.ts +140 -0
- package/dist/type-utils.d.cts +66 -0
- package/dist/type-utils.d.ts +66 -0
- package/dist/types.d.cts +1206 -0
- package/dist/types.d.ts +1206 -0
- package/dist/wire.d.cts +68 -0
- package/dist/wire.d.ts +68 -0
- package/package.json +89 -0
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Siteping database models — single source of truth.
|
|
3
|
+
*
|
|
4
|
+
* Used by:
|
|
5
|
+
* - CLI to generate Prisma schema (via prisma-ast)
|
|
6
|
+
* - Adapter for Zod validation
|
|
7
|
+
* - Type exports
|
|
8
|
+
*
|
|
9
|
+
* This is a TS representation, NOT a .prisma file.
|
|
10
|
+
* The CLI generates the actual Prisma schema from this definition.
|
|
11
|
+
*/
|
|
12
|
+
/** Prisma scalar types supported by Siteping field definitions. */
|
|
13
|
+
export type PrismaScalarType = "String" | "Boolean" | "Int" | "BigInt" | "Float" | "Decimal" | "DateTime" | "Json" | "Bytes";
|
|
14
|
+
/** Prisma native column hints applied via `@db.<NativeType>`. */
|
|
15
|
+
export type PrismaNativeType = "Text" | "VarChar" | "Char" | "MediumText" | "LongText" | (string & {});
|
|
16
|
+
/** Relation cardinality between two Siteping models. */
|
|
17
|
+
export type RelationKind = "1-to-many" | "many-to-1";
|
|
18
|
+
/** Prisma `onDelete` referential action. */
|
|
19
|
+
export type RelationOnDelete = "Cascade" | "Restrict" | "NoAction" | "SetNull" | "SetDefault";
|
|
20
|
+
/**
|
|
21
|
+
* Relation metadata attached to a {@link FieldDef}.
|
|
22
|
+
*
|
|
23
|
+
* - `1-to-many` fields point at the related model and require no inverse
|
|
24
|
+
* column on this side (`fields`/`references` are inferred by Prisma).
|
|
25
|
+
* - `many-to-1` fields own the foreign key — Prisma needs `fields` and
|
|
26
|
+
* `references` to wire it up.
|
|
27
|
+
*/
|
|
28
|
+
export interface RelationDef {
|
|
29
|
+
kind: RelationKind;
|
|
30
|
+
model: string;
|
|
31
|
+
fields?: readonly string[];
|
|
32
|
+
references?: readonly string[];
|
|
33
|
+
onDelete?: RelationOnDelete;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Definition of a single field in a Siteping database model.
|
|
37
|
+
*
|
|
38
|
+
* The interface intentionally keeps a wide structural shape so it stays
|
|
39
|
+
* easy to extend, but consumers can narrow via {@link isRelationField} /
|
|
40
|
+
* {@link isScalarField} when relation vs. scalar logic diverges.
|
|
41
|
+
*/
|
|
42
|
+
export interface FieldDef {
|
|
43
|
+
/** Prisma type (e.g. "String", "Int") for scalars, model name for relations. */
|
|
44
|
+
type: PrismaScalarType | (string & {});
|
|
45
|
+
/** Default literal (`"open"`) or function call (`now()`, `cuid()`). */
|
|
46
|
+
default?: string;
|
|
47
|
+
/** Whether the column is nullable. */
|
|
48
|
+
optional?: boolean;
|
|
49
|
+
/** Set on relation fields — absent on scalars. */
|
|
50
|
+
relation?: RelationDef;
|
|
51
|
+
isId?: boolean;
|
|
52
|
+
isUnique?: boolean;
|
|
53
|
+
/** Prisma native type attribute (e.g. "Text" for @db.Text) — used for MySQL compatibility on long strings */
|
|
54
|
+
nativeType?: PrismaNativeType;
|
|
55
|
+
/** Prisma @updatedAt attribute */
|
|
56
|
+
isUpdatedAt?: boolean;
|
|
57
|
+
}
|
|
58
|
+
/** Narrowing predicate: returns `true` when `field` declares a Prisma relation. */
|
|
59
|
+
export declare function isRelationField(field: FieldDef): field is FieldDef & {
|
|
60
|
+
relation: RelationDef;
|
|
61
|
+
};
|
|
62
|
+
/** Narrowing predicate: returns `true` when `field` is a Prisma scalar (no relation metadata). */
|
|
63
|
+
export declare function isScalarField(field: FieldDef): field is FieldDef & {
|
|
64
|
+
relation?: undefined;
|
|
65
|
+
};
|
|
66
|
+
/** Definition of a composite index on a Siteping database model. */
|
|
67
|
+
export interface IndexDef {
|
|
68
|
+
fields: readonly string[];
|
|
69
|
+
}
|
|
70
|
+
/** Definition of a single Siteping database model (fields + indexes). */
|
|
71
|
+
export interface ModelDef {
|
|
72
|
+
fields: Record<string, FieldDef>;
|
|
73
|
+
indexes?: readonly IndexDef[];
|
|
74
|
+
}
|
|
75
|
+
declare const _SITEPING_MODELS: {
|
|
76
|
+
readonly SitepingFeedback: {
|
|
77
|
+
readonly fields: {
|
|
78
|
+
readonly id: {
|
|
79
|
+
readonly type: "String";
|
|
80
|
+
readonly isId: true;
|
|
81
|
+
readonly default: "cuid()";
|
|
82
|
+
};
|
|
83
|
+
readonly projectName: {
|
|
84
|
+
readonly type: "String";
|
|
85
|
+
};
|
|
86
|
+
readonly type: {
|
|
87
|
+
readonly type: "String";
|
|
88
|
+
};
|
|
89
|
+
readonly message: {
|
|
90
|
+
readonly type: "String";
|
|
91
|
+
readonly nativeType: "Text";
|
|
92
|
+
};
|
|
93
|
+
readonly status: {
|
|
94
|
+
readonly type: "String";
|
|
95
|
+
readonly default: "\"open\"";
|
|
96
|
+
};
|
|
97
|
+
readonly url: {
|
|
98
|
+
readonly type: "String";
|
|
99
|
+
};
|
|
100
|
+
readonly urlPattern: {
|
|
101
|
+
readonly type: "String";
|
|
102
|
+
readonly optional: true;
|
|
103
|
+
};
|
|
104
|
+
readonly screenshotUrl: {
|
|
105
|
+
readonly type: "String";
|
|
106
|
+
readonly optional: true;
|
|
107
|
+
readonly nativeType: "Text";
|
|
108
|
+
};
|
|
109
|
+
readonly screenshotRegion: {
|
|
110
|
+
readonly type: "Json";
|
|
111
|
+
readonly optional: true;
|
|
112
|
+
};
|
|
113
|
+
readonly diagnostics: {
|
|
114
|
+
readonly type: "Json";
|
|
115
|
+
readonly optional: true;
|
|
116
|
+
};
|
|
117
|
+
readonly viewport: {
|
|
118
|
+
readonly type: "String";
|
|
119
|
+
};
|
|
120
|
+
readonly userAgent: {
|
|
121
|
+
readonly type: "String";
|
|
122
|
+
};
|
|
123
|
+
readonly authorName: {
|
|
124
|
+
readonly type: "String";
|
|
125
|
+
};
|
|
126
|
+
readonly authorEmail: {
|
|
127
|
+
readonly type: "String";
|
|
128
|
+
};
|
|
129
|
+
readonly clientId: {
|
|
130
|
+
readonly type: "String";
|
|
131
|
+
readonly isUnique: true;
|
|
132
|
+
};
|
|
133
|
+
readonly resolvedAt: {
|
|
134
|
+
readonly type: "DateTime";
|
|
135
|
+
readonly optional: true;
|
|
136
|
+
};
|
|
137
|
+
readonly createdAt: {
|
|
138
|
+
readonly type: "DateTime";
|
|
139
|
+
readonly default: "now()";
|
|
140
|
+
};
|
|
141
|
+
readonly updatedAt: {
|
|
142
|
+
readonly type: "DateTime";
|
|
143
|
+
readonly isUpdatedAt: true;
|
|
144
|
+
};
|
|
145
|
+
readonly annotations: {
|
|
146
|
+
readonly type: "SitepingAnnotation";
|
|
147
|
+
readonly relation: {
|
|
148
|
+
readonly kind: "1-to-many";
|
|
149
|
+
readonly model: "SitepingAnnotation";
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
readonly comments: {
|
|
153
|
+
readonly type: "SitepingComment";
|
|
154
|
+
readonly relation: {
|
|
155
|
+
readonly kind: "1-to-many";
|
|
156
|
+
readonly model: "SitepingComment";
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
readonly indexes: readonly [{
|
|
161
|
+
readonly fields: readonly ["projectName"];
|
|
162
|
+
}, {
|
|
163
|
+
readonly fields: readonly ["projectName", "status", "createdAt"];
|
|
164
|
+
}, {
|
|
165
|
+
readonly fields: readonly ["projectName", "url"];
|
|
166
|
+
}];
|
|
167
|
+
};
|
|
168
|
+
readonly SitepingAnnotation: {
|
|
169
|
+
readonly fields: {
|
|
170
|
+
readonly id: {
|
|
171
|
+
readonly type: "String";
|
|
172
|
+
readonly isId: true;
|
|
173
|
+
readonly default: "cuid()";
|
|
174
|
+
};
|
|
175
|
+
readonly feedbackId: {
|
|
176
|
+
readonly type: "String";
|
|
177
|
+
};
|
|
178
|
+
readonly feedback: {
|
|
179
|
+
readonly type: "SitepingFeedback";
|
|
180
|
+
readonly relation: {
|
|
181
|
+
readonly kind: "many-to-1";
|
|
182
|
+
readonly model: "SitepingFeedback";
|
|
183
|
+
readonly fields: readonly ["feedbackId"];
|
|
184
|
+
readonly references: readonly ["id"];
|
|
185
|
+
readonly onDelete: "Cascade";
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
readonly cssSelector: {
|
|
189
|
+
readonly type: "String";
|
|
190
|
+
readonly nativeType: "Text";
|
|
191
|
+
};
|
|
192
|
+
readonly xpath: {
|
|
193
|
+
readonly type: "String";
|
|
194
|
+
readonly nativeType: "Text";
|
|
195
|
+
};
|
|
196
|
+
readonly textSnippet: {
|
|
197
|
+
readonly type: "String";
|
|
198
|
+
readonly nativeType: "Text";
|
|
199
|
+
};
|
|
200
|
+
readonly elementTag: {
|
|
201
|
+
readonly type: "String";
|
|
202
|
+
};
|
|
203
|
+
readonly elementId: {
|
|
204
|
+
readonly type: "String";
|
|
205
|
+
readonly optional: true;
|
|
206
|
+
};
|
|
207
|
+
readonly textPrefix: {
|
|
208
|
+
readonly type: "String";
|
|
209
|
+
readonly nativeType: "Text";
|
|
210
|
+
};
|
|
211
|
+
readonly textSuffix: {
|
|
212
|
+
readonly type: "String";
|
|
213
|
+
readonly nativeType: "Text";
|
|
214
|
+
};
|
|
215
|
+
readonly fingerprint: {
|
|
216
|
+
readonly type: "String";
|
|
217
|
+
};
|
|
218
|
+
readonly neighborText: {
|
|
219
|
+
readonly type: "String";
|
|
220
|
+
readonly nativeType: "Text";
|
|
221
|
+
};
|
|
222
|
+
readonly anchorKey: {
|
|
223
|
+
readonly type: "String";
|
|
224
|
+
readonly optional: true;
|
|
225
|
+
};
|
|
226
|
+
readonly xPct: {
|
|
227
|
+
readonly type: "Float";
|
|
228
|
+
};
|
|
229
|
+
readonly yPct: {
|
|
230
|
+
readonly type: "Float";
|
|
231
|
+
};
|
|
232
|
+
readonly wPct: {
|
|
233
|
+
readonly type: "Float";
|
|
234
|
+
};
|
|
235
|
+
readonly hPct: {
|
|
236
|
+
readonly type: "Float";
|
|
237
|
+
};
|
|
238
|
+
readonly scrollX: {
|
|
239
|
+
readonly type: "Float";
|
|
240
|
+
};
|
|
241
|
+
readonly scrollY: {
|
|
242
|
+
readonly type: "Float";
|
|
243
|
+
};
|
|
244
|
+
readonly viewportW: {
|
|
245
|
+
readonly type: "Int";
|
|
246
|
+
};
|
|
247
|
+
readonly viewportH: {
|
|
248
|
+
readonly type: "Int";
|
|
249
|
+
};
|
|
250
|
+
readonly devicePixelRatio: {
|
|
251
|
+
readonly type: "Float";
|
|
252
|
+
readonly default: "1";
|
|
253
|
+
};
|
|
254
|
+
readonly createdAt: {
|
|
255
|
+
readonly type: "DateTime";
|
|
256
|
+
readonly default: "now()";
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
readonly indexes: readonly [{
|
|
260
|
+
readonly fields: readonly ["feedbackId"];
|
|
261
|
+
}];
|
|
262
|
+
};
|
|
263
|
+
readonly SitepingComment: {
|
|
264
|
+
readonly fields: {
|
|
265
|
+
readonly id: {
|
|
266
|
+
readonly type: "String";
|
|
267
|
+
readonly isId: true;
|
|
268
|
+
readonly default: "cuid()";
|
|
269
|
+
};
|
|
270
|
+
readonly feedbackId: {
|
|
271
|
+
readonly type: "String";
|
|
272
|
+
};
|
|
273
|
+
readonly feedback: {
|
|
274
|
+
readonly type: "SitepingFeedback";
|
|
275
|
+
readonly relation: {
|
|
276
|
+
readonly kind: "many-to-1";
|
|
277
|
+
readonly model: "SitepingFeedback";
|
|
278
|
+
readonly fields: readonly ["feedbackId"];
|
|
279
|
+
readonly references: readonly ["id"];
|
|
280
|
+
readonly onDelete: "Cascade";
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
readonly body: {
|
|
284
|
+
readonly type: "String";
|
|
285
|
+
readonly nativeType: "Text";
|
|
286
|
+
};
|
|
287
|
+
readonly authorName: {
|
|
288
|
+
readonly type: "String";
|
|
289
|
+
};
|
|
290
|
+
readonly authorEmail: {
|
|
291
|
+
readonly type: "String";
|
|
292
|
+
};
|
|
293
|
+
readonly authorRole: {
|
|
294
|
+
readonly type: "String";
|
|
295
|
+
readonly default: "\"client\"";
|
|
296
|
+
};
|
|
297
|
+
readonly clientId: {
|
|
298
|
+
readonly type: "String";
|
|
299
|
+
readonly isUnique: true;
|
|
300
|
+
};
|
|
301
|
+
readonly createdAt: {
|
|
302
|
+
readonly type: "DateTime";
|
|
303
|
+
readonly default: "now()";
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
readonly indexes: readonly [{
|
|
307
|
+
readonly fields: readonly ["feedbackId", "createdAt"];
|
|
308
|
+
}];
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
/** Map of Siteping models keyed by model name — frozen at runtime. */
|
|
312
|
+
export declare const SITEPING_MODELS: typeof _SITEPING_MODELS;
|
|
313
|
+
/** Union of every Siteping model name as a string literal. */
|
|
314
|
+
export type SitepingModelName = keyof typeof SITEPING_MODELS;
|
|
315
|
+
/** Field names declared on a specific Siteping model. */
|
|
316
|
+
export type SitepingModelFieldName<M extends SitepingModelName> = keyof (typeof SITEPING_MODELS)[M]["fields"];
|
|
317
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pluggable storage for feedback screenshots.
|
|
3
|
+
*
|
|
4
|
+
* `adapter-prisma` and `adapter-drizzle` accept an optional
|
|
5
|
+
* `screenshotStorage` config. When provided, the adapter forwards the
|
|
6
|
+
* widget-supplied data URL to `upload()` and persists the returned URL on
|
|
7
|
+
* `Feedback.screenshotUrl`. When not provided, the adapter falls back to
|
|
8
|
+
* inline base64 (with a one-time warn) — fine for dev and small
|
|
9
|
+
* deployments, a footgun for production Postgres.
|
|
10
|
+
*
|
|
11
|
+
* `@siteping/screenshot-storage` implements it over any S3-compatible
|
|
12
|
+
* bucket (AWS S3, Cloudflare R2, Backblaze B2, MinIO…), Cloudflare Images,
|
|
13
|
+
* a database table, the local filesystem or memory. Implement it yourself
|
|
14
|
+
* for anything else.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* // Minimal S3 implementation
|
|
19
|
+
* import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
|
|
20
|
+
*
|
|
21
|
+
* const s3 = new S3Client({ region: "eu-west-3" });
|
|
22
|
+
* const screenshotStorage: ScreenshotStorage = {
|
|
23
|
+
* async upload(dataUrl, { mimeType }) {
|
|
24
|
+
* const body = Buffer.from(dataUrl.slice(dataUrl.indexOf(",") + 1), "base64");
|
|
25
|
+
* const key = `siteping/${crypto.randomUUID()}`; // fresh per upload, see URL ownership
|
|
26
|
+
* await s3.send(new PutObjectCommand({
|
|
27
|
+
* Bucket: "my-bucket", Key: key, Body: body, ContentType: mimeType,
|
|
28
|
+
* }));
|
|
29
|
+
* return { url: `https://cdn.example.com/${key}` };
|
|
30
|
+
* },
|
|
31
|
+
* };
|
|
32
|
+
*
|
|
33
|
+
* createSitepingHandler({ prisma, screenshotStorage });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export interface ScreenshotStorage {
|
|
37
|
+
/**
|
|
38
|
+
* Persist a base64 data URL and return the URL the widget will use as
|
|
39
|
+
* `<img src>`. Implementations decide the underlying storage and any
|
|
40
|
+
* post-processing (resize, virus scan, content-type sniff).
|
|
41
|
+
*
|
|
42
|
+
* Adapters call this synchronously inside `createFeedback` — keep it
|
|
43
|
+
* fast or move to a queue if needed.
|
|
44
|
+
*
|
|
45
|
+
* `ctx.feedbackId` identifies the upload. Adapters that upload before the
|
|
46
|
+
* record exists pass the *client-generated* `clientId` (Prisma); the
|
|
47
|
+
* Drizzle adapter passes the server-generated id the create attempt will
|
|
48
|
+
* insert the record under.
|
|
49
|
+
*
|
|
50
|
+
* **URL ownership:** every call must return a URL no other call returns —
|
|
51
|
+
* key the object by a fresh random value (`crypto.randomUUID()`, as the
|
|
52
|
+
* example does), never by `ctx.feedbackId` alone nor by a content hash.
|
|
53
|
+
* Adapters treat each URL as the property of the one record that stores it
|
|
54
|
+
* and may pass it to `delete` once that record is deleted, or once its
|
|
55
|
+
* create lost a race: two submissions of one `clientId` both upload, and
|
|
56
|
+
* the object of the one that is not stored is deleted. Under Prisma,
|
|
57
|
+
* `ctx.feedbackId` is that client-supplied `clientId`, so an object keyed
|
|
58
|
+
* by it is rewritten by every replay — a retry, or anyone who learns the
|
|
59
|
+
* id — and a URL shared by several records lets deleting one remove the
|
|
60
|
+
* object another still points at.
|
|
61
|
+
*
|
|
62
|
+
* **Security note:** treat `ctx.feedbackId` as attacker-controlled:
|
|
63
|
+
* sanitize before using it in filesystem paths or object keys, even though
|
|
64
|
+
* server adapters validate its shape upstream.
|
|
65
|
+
*/
|
|
66
|
+
upload(dataUrl: string, ctx: {
|
|
67
|
+
feedbackId: string;
|
|
68
|
+
mimeType: string;
|
|
69
|
+
}): Promise<{
|
|
70
|
+
url: string;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Optional cleanup hook called when the feedback is deleted, and for an
|
|
74
|
+
* object uploaded by a create whose record was not stored: one rejected
|
|
75
|
+
* because its `clientId` is already stored, or — in adapters that key
|
|
76
|
+
* uploads per attempt, like Drizzle — one whose insert failed. An object a
|
|
77
|
+
* stored row still references (a deterministic key reused by the replay)
|
|
78
|
+
* is kept. Receives only URLs returned by {@link ScreenshotStorage.upload}.
|
|
79
|
+
* Adapters call this best-effort and swallow errors — orphaned objects are
|
|
80
|
+
* preferred over failed deletes.
|
|
81
|
+
*/
|
|
82
|
+
delete?: (url: string) => Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Most `ScreenshotStorage.delete` calls one cleanup keeps in flight — a
|
|
86
|
+
* project delete may free thousands of objects, and firing them all at once
|
|
87
|
+
* can exhaust sockets (one per request with `fetch`) or memory and trip
|
|
88
|
+
* object-store rate limits. It stays under the 50 sockets the AWS SDK opens
|
|
89
|
+
* per client by default, yet a project delete, which waits for its cleanup,
|
|
90
|
+
* is not serialised: 1,000 objects take 32 rounds. Adapters run their
|
|
91
|
+
* deletes through `settleWithConcurrencyLimit` with this bound.
|
|
92
|
+
*/
|
|
93
|
+
export declare const SCREENSHOT_DELETE_CONCURRENCY = 32;
|
|
94
|
+
/**
|
|
95
|
+
* MIME type an adapter reports to {@link ScreenshotStorage.upload}: the one
|
|
96
|
+
* an image data URL declares (`data:image/png;base64,…` → `image/png`),
|
|
97
|
+
* limited to the JPEG, PNG and WebP the HTTP schema accepts. Stores are
|
|
98
|
+
* public and may be fed unvalidated data URLs, and an `image/svg+xml` label
|
|
99
|
+
* would make the stored object script-capable when served inline. Anything
|
|
100
|
+
* else — including a data URL that declares no type — reports JPEG, the
|
|
101
|
+
* widget's capture format.
|
|
102
|
+
*/
|
|
103
|
+
export declare function screenshotMimeType(dataUrl: string): string;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pluggable storage for feedback screenshots.
|
|
3
|
+
*
|
|
4
|
+
* `adapter-prisma` and `adapter-drizzle` accept an optional
|
|
5
|
+
* `screenshotStorage` config. When provided, the adapter forwards the
|
|
6
|
+
* widget-supplied data URL to `upload()` and persists the returned URL on
|
|
7
|
+
* `Feedback.screenshotUrl`. When not provided, the adapter falls back to
|
|
8
|
+
* inline base64 (with a one-time warn) — fine for dev and small
|
|
9
|
+
* deployments, a footgun for production Postgres.
|
|
10
|
+
*
|
|
11
|
+
* `@siteping/screenshot-storage` implements it over any S3-compatible
|
|
12
|
+
* bucket (AWS S3, Cloudflare R2, Backblaze B2, MinIO…), Cloudflare Images,
|
|
13
|
+
* a database table, the local filesystem or memory. Implement it yourself
|
|
14
|
+
* for anything else.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* // Minimal S3 implementation
|
|
19
|
+
* import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
|
|
20
|
+
*
|
|
21
|
+
* const s3 = new S3Client({ region: "eu-west-3" });
|
|
22
|
+
* const screenshotStorage: ScreenshotStorage = {
|
|
23
|
+
* async upload(dataUrl, { mimeType }) {
|
|
24
|
+
* const body = Buffer.from(dataUrl.slice(dataUrl.indexOf(",") + 1), "base64");
|
|
25
|
+
* const key = `siteping/${crypto.randomUUID()}`; // fresh per upload, see URL ownership
|
|
26
|
+
* await s3.send(new PutObjectCommand({
|
|
27
|
+
* Bucket: "my-bucket", Key: key, Body: body, ContentType: mimeType,
|
|
28
|
+
* }));
|
|
29
|
+
* return { url: `https://cdn.example.com/${key}` };
|
|
30
|
+
* },
|
|
31
|
+
* };
|
|
32
|
+
*
|
|
33
|
+
* createSitepingHandler({ prisma, screenshotStorage });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export interface ScreenshotStorage {
|
|
37
|
+
/**
|
|
38
|
+
* Persist a base64 data URL and return the URL the widget will use as
|
|
39
|
+
* `<img src>`. Implementations decide the underlying storage and any
|
|
40
|
+
* post-processing (resize, virus scan, content-type sniff).
|
|
41
|
+
*
|
|
42
|
+
* Adapters call this synchronously inside `createFeedback` — keep it
|
|
43
|
+
* fast or move to a queue if needed.
|
|
44
|
+
*
|
|
45
|
+
* `ctx.feedbackId` identifies the upload. Adapters that upload before the
|
|
46
|
+
* record exists pass the *client-generated* `clientId` (Prisma); the
|
|
47
|
+
* Drizzle adapter passes the server-generated id the create attempt will
|
|
48
|
+
* insert the record under.
|
|
49
|
+
*
|
|
50
|
+
* **URL ownership:** every call must return a URL no other call returns —
|
|
51
|
+
* key the object by a fresh random value (`crypto.randomUUID()`, as the
|
|
52
|
+
* example does), never by `ctx.feedbackId` alone nor by a content hash.
|
|
53
|
+
* Adapters treat each URL as the property of the one record that stores it
|
|
54
|
+
* and may pass it to `delete` once that record is deleted, or once its
|
|
55
|
+
* create lost a race: two submissions of one `clientId` both upload, and
|
|
56
|
+
* the object of the one that is not stored is deleted. Under Prisma,
|
|
57
|
+
* `ctx.feedbackId` is that client-supplied `clientId`, so an object keyed
|
|
58
|
+
* by it is rewritten by every replay — a retry, or anyone who learns the
|
|
59
|
+
* id — and a URL shared by several records lets deleting one remove the
|
|
60
|
+
* object another still points at.
|
|
61
|
+
*
|
|
62
|
+
* **Security note:** treat `ctx.feedbackId` as attacker-controlled:
|
|
63
|
+
* sanitize before using it in filesystem paths or object keys, even though
|
|
64
|
+
* server adapters validate its shape upstream.
|
|
65
|
+
*/
|
|
66
|
+
upload(dataUrl: string, ctx: {
|
|
67
|
+
feedbackId: string;
|
|
68
|
+
mimeType: string;
|
|
69
|
+
}): Promise<{
|
|
70
|
+
url: string;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Optional cleanup hook called when the feedback is deleted, and for an
|
|
74
|
+
* object uploaded by a create whose record was not stored: one rejected
|
|
75
|
+
* because its `clientId` is already stored, or — in adapters that key
|
|
76
|
+
* uploads per attempt, like Drizzle — one whose insert failed. An object a
|
|
77
|
+
* stored row still references (a deterministic key reused by the replay)
|
|
78
|
+
* is kept. Receives only URLs returned by {@link ScreenshotStorage.upload}.
|
|
79
|
+
* Adapters call this best-effort and swallow errors — orphaned objects are
|
|
80
|
+
* preferred over failed deletes.
|
|
81
|
+
*/
|
|
82
|
+
delete?: (url: string) => Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Most `ScreenshotStorage.delete` calls one cleanup keeps in flight — a
|
|
86
|
+
* project delete may free thousands of objects, and firing them all at once
|
|
87
|
+
* can exhaust sockets (one per request with `fetch`) or memory and trip
|
|
88
|
+
* object-store rate limits. It stays under the 50 sockets the AWS SDK opens
|
|
89
|
+
* per client by default, yet a project delete, which waits for its cleanup,
|
|
90
|
+
* is not serialised: 1,000 objects take 32 rounds. Adapters run their
|
|
91
|
+
* deletes through `settleWithConcurrencyLimit` with this bound.
|
|
92
|
+
*/
|
|
93
|
+
export declare const SCREENSHOT_DELETE_CONCURRENCY = 32;
|
|
94
|
+
/**
|
|
95
|
+
* MIME type an adapter reports to {@link ScreenshotStorage.upload}: the one
|
|
96
|
+
* an image data URL declares (`data:image/png;base64,…` → `image/png`),
|
|
97
|
+
* limited to the JPEG, PNG and WebP the HTTP schema accepts. Stores are
|
|
98
|
+
* public and may be fed unvalidated data URLs, and an `image/svg+xml` label
|
|
99
|
+
* would make the stored object script-capable when served inline. Anything
|
|
100
|
+
* else — including a data URL that declares no type — reports JPEG, the
|
|
101
|
+
* widget's capture format.
|
|
102
|
+
*/
|
|
103
|
+
export declare function screenshotMimeType(dataUrl: string): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { settleWithConcurrencyLimit } from "./concurrency.cjs";
|
|
2
|
+
export { buildDeepLink, parseHttpUrl } from "./deep-link.cjs";
|
|
3
|
+
export { EMAIL_PATTERN, isValidEmail } from "./email.cjs";
|
|
4
|
+
export type { SitepingErrorCode } from "./errors.cjs";
|
|
5
|
+
export { SitepingAuthError, SitepingError, SitepingNetworkError, SitepingValidationError } from "./errors.cjs";
|
|
6
|
+
export type { FilterResult, Pagination } from "./filters.cjs";
|
|
7
|
+
export { applyFeedbackFilters, clampPagination, DEFAULT_PAGE_LIMIT, isUnreachableOffset, MAX_PAGE_LIMIT, matchesFeedbackQuery, } from "./filters.cjs";
|
|
8
|
+
export type { I18n, LocaleLoaders, TranslateFunction } from "./i18n.cjs";
|
|
9
|
+
export { canonicalizeLocale, createI18n, interpolate, intlLocale, tWithParams } from "./i18n.cjs";
|
|
10
|
+
export type { FieldDef, IndexDef, ModelDef, PrismaNativeType, PrismaScalarType, RelationDef, RelationKind, RelationOnDelete, SitepingModelFieldName, SitepingModelName, } from "./schema.cjs";
|
|
11
|
+
export { isRelationField, isScalarField, SITEPING_MODELS } from "./schema.cjs";
|
|
12
|
+
export type { ScreenshotStorage } from "./screenshot-storage.cjs";
|
|
13
|
+
export { SCREENSHOT_DELETE_CONCURRENCY, screenshotMimeType } from "./screenshot-storage.cjs";
|
|
14
|
+
export type { CollectionStore, CollectionStoreBackend } from "./store-helpers.cjs";
|
|
15
|
+
export { buildAnnotationRecord, buildCommentRecord, buildFeedbackRecord, createCollectionStore, } from "./store-helpers.cjs";
|
|
16
|
+
export type { AssertEqual, IfEquals, Prettify, Serialized } from "./type-utils.cjs";
|
|
17
|
+
export { hasOwn, isRecord } from "./type-utils.cjs";
|
|
18
|
+
export type { AnchorData, AnnotationCreateInput, AnnotationPayload, AnnotationRecord, AnnotationResponse, BuiltinLocale, ClosedFeedbackStatus, CommentAuthorRole, CommentCreateInput, CommentDeletePayload, CommentPayload, CommentRecord, CommentResponse, ConsoleDiagnosticEntry, ConsoleDiagnosticLevel, DiagnosticsCaptureOptions, DiagnosticsSnapshot, FeedbackCreateInput, FeedbackCreateOutcome, FeedbackListPermissions, FeedbackPage, FeedbackPayload, FeedbackPermissions, FeedbackQuery, FeedbackRecord, FeedbackResponse, FeedbackResponseList, FeedbackStatus, FeedbackType, FeedbackUpdateInput, NetworkDiagnosticEntry, OpenFeedbackStatus, PageScope, RectData, ScreenshotRegion, SitepingBaseConfig, SitepingCapabilities, SitepingConfig, SitepingDeepLinkOptions, SitepingHeadersOption, SitepingHttpConfig, SitepingIdentity, SitepingInstance, SitepingLocale, SitepingPanelAction, SitepingPanelActionContext, SitepingPanelActionFeedback, SitepingPanelButtonAction, SitepingPanelLinkAction, SitepingPosition, SitepingPublicEventListener, SitepingPublicEvents, SitepingSkipReason, SitepingStore, SitepingStoreConfig, SitepingTheme, SitepingUnsubscribe, } from "./types.cjs";
|
|
19
|
+
export { ANCHOR_ELEMENT_ID_MAX, ANCHOR_ELEMENT_TAG_MAX, BUILTIN_LOCALES, CLOSED_FEEDBACK_STATUSES, COMMENT_AUTHOR_ROLES, COMMENT_BODY_MAX_LENGTH, CONSOLE_DIAGNOSTIC_LEVELS, FEEDBACK_STATUSES, FEEDBACK_TYPES, flattenAnnotation, IDENTITY_FIELD_MAX_LENGTH, isClosedStatus, isStoreDuplicate, isStoreLimit, isStoreNotFound, isStorePersistence, isStoreValueTooLong, MAX_COMMENTS_PER_FEEDBACK, OPEN_FEEDBACK_STATUSES, StoreDuplicateError, StoreLimitError, StoreNotFoundError, StorePersistenceError, StoreValueTooLongError, toFeedbackUpdate, } from "./types.cjs";
|
|
20
|
+
export { errorFromResponse, feedbackQueryToSearchParams, isCommentGone, isThreadFull, mergeRequestHeaders, networkErrorFromException, newClientId, withSearchParams, } from "./wire.cjs";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { settleWithConcurrencyLimit } from "./concurrency.js";
|
|
2
|
+
export { buildDeepLink, parseHttpUrl } from "./deep-link.js";
|
|
3
|
+
export { EMAIL_PATTERN, isValidEmail } from "./email.js";
|
|
4
|
+
export type { SitepingErrorCode } from "./errors.js";
|
|
5
|
+
export { SitepingAuthError, SitepingError, SitepingNetworkError, SitepingValidationError } from "./errors.js";
|
|
6
|
+
export type { FilterResult, Pagination } from "./filters.js";
|
|
7
|
+
export { applyFeedbackFilters, clampPagination, DEFAULT_PAGE_LIMIT, isUnreachableOffset, MAX_PAGE_LIMIT, matchesFeedbackQuery, } from "./filters.js";
|
|
8
|
+
export type { I18n, LocaleLoaders, TranslateFunction } from "./i18n.js";
|
|
9
|
+
export { canonicalizeLocale, createI18n, interpolate, intlLocale, tWithParams } from "./i18n.js";
|
|
10
|
+
export type { FieldDef, IndexDef, ModelDef, PrismaNativeType, PrismaScalarType, RelationDef, RelationKind, RelationOnDelete, SitepingModelFieldName, SitepingModelName, } from "./schema.js";
|
|
11
|
+
export { isRelationField, isScalarField, SITEPING_MODELS } from "./schema.js";
|
|
12
|
+
export type { ScreenshotStorage } from "./screenshot-storage.js";
|
|
13
|
+
export { SCREENSHOT_DELETE_CONCURRENCY, screenshotMimeType } from "./screenshot-storage.js";
|
|
14
|
+
export type { CollectionStore, CollectionStoreBackend } from "./store-helpers.js";
|
|
15
|
+
export { buildAnnotationRecord, buildCommentRecord, buildFeedbackRecord, createCollectionStore, } from "./store-helpers.js";
|
|
16
|
+
export type { AssertEqual, IfEquals, Prettify, Serialized } from "./type-utils.js";
|
|
17
|
+
export { hasOwn, isRecord } from "./type-utils.js";
|
|
18
|
+
export type { AnchorData, AnnotationCreateInput, AnnotationPayload, AnnotationRecord, AnnotationResponse, BuiltinLocale, ClosedFeedbackStatus, CommentAuthorRole, CommentCreateInput, CommentDeletePayload, CommentPayload, CommentRecord, CommentResponse, ConsoleDiagnosticEntry, ConsoleDiagnosticLevel, DiagnosticsCaptureOptions, DiagnosticsSnapshot, FeedbackCreateInput, FeedbackCreateOutcome, FeedbackListPermissions, FeedbackPage, FeedbackPayload, FeedbackPermissions, FeedbackQuery, FeedbackRecord, FeedbackResponse, FeedbackResponseList, FeedbackStatus, FeedbackType, FeedbackUpdateInput, NetworkDiagnosticEntry, OpenFeedbackStatus, PageScope, RectData, ScreenshotRegion, SitepingBaseConfig, SitepingCapabilities, SitepingConfig, SitepingDeepLinkOptions, SitepingHeadersOption, SitepingHttpConfig, SitepingIdentity, SitepingInstance, SitepingLocale, SitepingPanelAction, SitepingPanelActionContext, SitepingPanelActionFeedback, SitepingPanelButtonAction, SitepingPanelLinkAction, SitepingPosition, SitepingPublicEventListener, SitepingPublicEvents, SitepingSkipReason, SitepingStore, SitepingStoreConfig, SitepingTheme, SitepingUnsubscribe, } from "./types.js";
|
|
19
|
+
export { ANCHOR_ELEMENT_ID_MAX, ANCHOR_ELEMENT_TAG_MAX, BUILTIN_LOCALES, CLOSED_FEEDBACK_STATUSES, COMMENT_AUTHOR_ROLES, COMMENT_BODY_MAX_LENGTH, CONSOLE_DIAGNOSTIC_LEVELS, FEEDBACK_STATUSES, FEEDBACK_TYPES, flattenAnnotation, IDENTITY_FIELD_MAX_LENGTH, isClosedStatus, isStoreDuplicate, isStoreLimit, isStoreNotFound, isStorePersistence, isStoreValueTooLong, MAX_COMMENTS_PER_FEEDBACK, OPEN_FEEDBACK_STATUSES, StoreDuplicateError, StoreLimitError, StoreNotFoundError, StorePersistenceError, StoreValueTooLongError, toFeedbackUpdate, } from "./types.js";
|
|
20
|
+
export { errorFromResponse, feedbackQueryToSearchParams, isCommentGone, isThreadFull, mergeRequestHeaders, networkErrorFromException, newClientId, withSearchParams, } from "./wire.js";
|