@drakkar.software/starfish-events 3.0.0-alpha.40

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.
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Starfish server plugin: intercepts JSON event-batch pushes and encodes them
3
+ * as Parquet files written directly to the object store (typically S3).
4
+ *
5
+ * ## How it works
6
+ *
7
+ * 1. Register a JSON-typed collection (allowedMimeTypes: ["application/json"])
8
+ * with public write access.
9
+ * 2. Attach this plugin to the sync router.
10
+ * 3. Each push to that collection is intercepted here; the JSON event batch is
11
+ * encoded as Parquet and stored via `store.putBytes`, short-circuiting the
12
+ * default JSON document write so no JSON is persisted alongside the Parquet.
13
+ *
14
+ * ## Collection requirement
15
+ *
16
+ * The intercepted collection **must** be JSON-typed — `interceptPush` only
17
+ * receives a populated `rawBody` for JSON collections. A binary (parquet-typed)
18
+ * collection would yield an empty body.
19
+ *
20
+ * ## One file per batch
21
+ *
22
+ * Parquet's column-footer format makes in-place append impractical. Each
23
+ * `send()` call from the SunGlasses adapter writes a unique path (batchId in
24
+ * the storagePath template). DuckDB's `read_parquet('s3://…/**‌/*.parquet')`
25
+ * glob treats all files under the prefix as one logical dataset.
26
+ *
27
+ * ## Privacy
28
+ *
29
+ * Never log `distinct_id`, `properties`, or `context`. Log counts only.
30
+ * These values ride as opaque strings into Parquet.
31
+ */
32
+ import type { ServerPlugin } from "@drakkar.software/starfish-protocol";
33
+ import type { ObjectStore } from "@drakkar.software/starfish-server";
34
+ /** Options for {@link createEventsServerPlugin}. */
35
+ export interface EventsPluginOptions {
36
+ /**
37
+ * Object store the plugin writes Parquet files to.
38
+ * Must implement `putBytes` (e.g. `S3ObjectStore` from `starfish-server/s3`).
39
+ * Pass the **same** store instance that you pass to `createSyncRouter`.
40
+ */
41
+ store: ObjectStore;
42
+ /**
43
+ * Name of the collection to intercept.
44
+ * Must match the `name` field in the `SyncConfig.collections` entry.
45
+ * Example: `"events"`
46
+ */
47
+ collection: string;
48
+ /**
49
+ * Storage-path template for the output Parquet key.
50
+ * Supports `{param}` placeholders resolved from the push URL's path params.
51
+ * Example: `"events/{app}/{batchId}"` → `"events/myapp/<uuid>"`
52
+ *
53
+ * The plugin appends `.parquet` when the resolved key doesn't already end
54
+ * with it, so you can omit the extension from the template.
55
+ */
56
+ storagePath: string;
57
+ }
58
+ /**
59
+ * Create a Starfish server plugin that encodes SunGlasses event batches as
60
+ * Parquet and writes them to the object store.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * import { S3ObjectStore } from "@drakkar.software/starfish-server/s3"
65
+ * import { createEventsServerPlugin } from "@drakkar.software/starfish-events"
66
+ *
67
+ * const store = new S3ObjectStore({ bucket: "my-bucket", ... })
68
+ * const eventsPlugin = createEventsServerPlugin({
69
+ * store,
70
+ * collection: "events",
71
+ * storagePath: "events/{app}/{batchId}",
72
+ * })
73
+ *
74
+ * const sync = createSyncRouter({
75
+ * store,
76
+ * config: {
77
+ * version: 1,
78
+ * collections: [{
79
+ * name: "events",
80
+ * storagePath: "events/{app}/{batchId}",
81
+ * readRoles: ["public"],
82
+ * writeRoles: ["public"],
83
+ * encryption: "none",
84
+ * allowedMimeTypes: ["application/json"], // ← JSON-typed, not parquet
85
+ * maxBodyBytes: 8_000_000,
86
+ * }],
87
+ * },
88
+ * plugins: [eventsPlugin],
89
+ * })
90
+ * ```
91
+ */
92
+ export declare function createEventsServerPlugin(opts: EventsPluginOptions): ServerPlugin;
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@drakkar.software/starfish-events",
3
+ "version": "3.0.0-alpha.40",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/Drakkar-Software/starfish.git",
7
+ "directory": "packages/ts/events"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "description": "Starfish server plugin that accepts JSON event batches and encodes them as Parquet on S3",
13
+ "type": "module",
14
+ "sideEffects": false,
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ }
22
+ },
23
+ "dependencies": {
24
+ "hyparquet-writer": "^0.16.1",
25
+ "@drakkar.software/starfish-protocol": "3.0.0-alpha.40",
26
+ "@drakkar.software/starfish-server": "3.0.0-alpha.40"
27
+ },
28
+ "devDependencies": {
29
+ "esbuild": "^0.27.4",
30
+ "hyparquet": "1.26.1",
31
+ "typescript": "^5.5.0",
32
+ "vitest": "^3.0.0"
33
+ },
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "scripts": {
38
+ "build": "node build.mjs && tsc -p tsconfig.build.json",
39
+ "typecheck": "tsc --noEmit",
40
+ "test": "vitest run"
41
+ }
42
+ }