@terreno/api 0.13.2 → 0.14.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/dist/__tests__/versionCheckPlugin.test.js +53 -3
- package/dist/api.arrayOperations.test.js +1 -0
- package/dist/api.asyncHandler.test.d.ts +1 -0
- package/dist/api.asyncHandler.test.js +236 -0
- package/dist/api.d.ts +15 -4
- package/dist/api.errors.test.js +1 -0
- package/dist/api.hooks.test.js +1 -0
- package/dist/api.js +153 -104
- package/dist/api.query.test.js +1 -0
- package/dist/api.test.js +174 -0
- package/dist/auth.d.ts +10 -5
- package/dist/auth.js +163 -90
- package/dist/auth.test.js +159 -0
- package/dist/betterAuthApp.test.js +1 -0
- package/dist/betterAuthSetup.d.ts +5 -6
- package/dist/betterAuthSetup.js +17 -14
- package/dist/betterAuthSetup.test.js +1 -0
- package/dist/config.d.ts +48 -0
- package/dist/config.js +248 -0
- package/dist/config.test.d.ts +1 -0
- package/dist/config.test.js +328 -0
- package/dist/configuration.test.js +1 -0
- package/dist/configurationApp.d.ts +1 -1
- package/dist/configurationApp.js +17 -13
- package/dist/configurationPlugin.test.js +1 -0
- package/dist/consentApp.test.js +1 -0
- package/dist/envConfigurationPlugin.d.ts +2 -0
- package/dist/envConfigurationPlugin.js +173 -0
- package/dist/envConfigurationPlugin.test.d.ts +1 -0
- package/dist/envConfigurationPlugin.test.js +322 -0
- package/dist/errors.d.ts +18 -7
- package/dist/errors.js +106 -10
- package/dist/errors.test.js +16 -1
- package/dist/example.js +16 -7
- package/dist/expressServer.d.ts +10 -9
- package/dist/expressServer.js +62 -53
- package/dist/expressServer.test.js +53 -2
- package/dist/githubAuth.d.ts +2 -1
- package/dist/githubAuth.js +41 -26
- package/dist/githubAuth.test.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +42 -20
- package/dist/models/versionConfig.d.ts +2 -0
- package/dist/models/versionConfig.js +8 -0
- package/dist/notifiers/googleChatNotifier.js +14 -16
- package/dist/notifiers/googleChatNotifier.test.js +1 -0
- package/dist/notifiers/slackNotifier.js +16 -14
- package/dist/notifiers/slackNotifier.test.js +41 -3
- package/dist/notifiers/zoomNotifier.js +7 -10
- package/dist/notifiers/zoomNotifier.test.js +1 -0
- package/dist/openApi.d.ts +1 -1
- package/dist/openApi.test.js +1 -0
- package/dist/openApiBuilder.d.ts +39 -6
- package/dist/openApiBuilder.js +1 -31
- package/dist/openApiBuilder.test.js +1 -0
- package/dist/openApiValidator.js +1 -0
- package/dist/openApiValidator.test.js +65 -0
- package/dist/permissions.d.ts +4 -4
- package/dist/permissions.js +67 -65
- package/dist/permissions.middleware.test.js +1 -0
- package/dist/permissions.test.js +1 -0
- package/dist/plugins.d.ts +5 -5
- package/dist/plugins.js +18 -9
- package/dist/plugins.test.js +1 -1
- package/dist/populate.d.ts +15 -8
- package/dist/populate.js +23 -24
- package/dist/populate.test.js +1 -0
- package/dist/realtime/changeStreamWatcher.d.ts +73 -0
- package/dist/realtime/changeStreamWatcher.js +720 -0
- package/dist/realtime/index.d.ts +6 -0
- package/dist/realtime/index.js +27 -0
- package/dist/realtime/queryMatcher.d.ts +14 -0
- package/dist/realtime/queryMatcher.js +250 -0
- package/dist/realtime/queryStore.d.ts +37 -0
- package/dist/realtime/queryStore.js +195 -0
- package/dist/realtime/realtime.test.d.ts +10 -0
- package/dist/realtime/realtime.test.js +2158 -0
- package/dist/realtime/realtimeApp.d.ts +93 -0
- package/dist/realtime/realtimeApp.js +560 -0
- package/dist/realtime/registry.d.ts +40 -0
- package/dist/realtime/registry.js +38 -0
- package/dist/realtime/socketUser.d.ts +10 -0
- package/dist/realtime/socketUser.js +17 -0
- package/dist/realtime/types.d.ts +100 -0
- package/dist/realtime/types.js +2 -0
- package/dist/requestContext.d.ts +37 -0
- package/dist/requestContext.js +344 -0
- package/dist/requestContext.test.d.ts +1 -0
- package/dist/requestContext.test.js +241 -0
- package/dist/terrenoApp.d.ts +8 -0
- package/dist/terrenoApp.js +50 -13
- package/dist/terrenoApp.test.js +194 -21
- package/dist/terrenoPlugin.d.ts +11 -0
- package/dist/tests/bunSetup.js +1 -0
- package/dist/tests.js +1 -1
- package/dist/transformers.d.ts +2 -2
- package/dist/transformers.js +5 -3
- package/dist/transformers.test.js +90 -0
- package/dist/types/consentResponse.d.ts +6 -3
- package/dist/versionCheckPlugin.d.ts +2 -0
- package/dist/versionCheckPlugin.js +18 -12
- package/package.json +4 -2
- package/src/__tests__/versionCheckPlugin.test.ts +37 -3
- package/src/api.arrayOperations.test.ts +1 -0
- package/src/api.asyncHandler.test.ts +177 -0
- package/src/api.errors.test.ts +1 -0
- package/src/api.hooks.test.ts +1 -0
- package/src/api.query.test.ts +1 -0
- package/src/api.test.ts +132 -0
- package/src/api.ts +199 -84
- package/src/auth.test.ts +160 -0
- package/src/auth.ts +120 -50
- package/src/betterAuthApp.test.ts +1 -0
- package/src/betterAuthSetup.test.ts +1 -0
- package/src/betterAuthSetup.ts +46 -19
- package/src/config.test.ts +255 -0
- package/src/config.ts +206 -0
- package/src/configuration.test.ts +1 -0
- package/src/configurationApp.ts +59 -24
- package/src/configurationPlugin.test.ts +1 -0
- package/src/consentApp.test.ts +1 -0
- package/src/envConfigurationPlugin.test.ts +143 -0
- package/src/envConfigurationPlugin.ts +100 -0
- package/src/errors.test.ts +19 -1
- package/src/errors.ts +94 -20
- package/src/example.ts +46 -21
- package/src/express.d.ts +18 -1
- package/src/expressServer.test.ts +50 -2
- package/src/expressServer.ts +80 -50
- package/src/githubAuth.test.ts +1 -0
- package/src/githubAuth.ts +59 -38
- package/src/index.ts +4 -0
- package/src/logger.ts +47 -17
- package/src/models/versionConfig.ts +13 -2
- package/src/notifiers/googleChatNotifier.test.ts +1 -0
- package/src/notifiers/googleChatNotifier.ts +7 -9
- package/src/notifiers/slackNotifier.test.ts +29 -3
- package/src/notifiers/slackNotifier.ts +9 -7
- package/src/notifiers/zoomNotifier.test.ts +1 -0
- package/src/notifiers/zoomNotifier.ts +8 -11
- package/src/openApi.test.ts +1 -0
- package/src/openApi.ts +4 -4
- package/src/openApiBuilder.test.ts +1 -0
- package/src/openApiBuilder.ts +14 -11
- package/src/openApiValidator.test.ts +59 -0
- package/src/openApiValidator.ts +3 -2
- package/src/permissions.middleware.test.ts +1 -0
- package/src/permissions.test.ts +1 -0
- package/src/permissions.ts +30 -25
- package/src/plugins.test.ts +1 -1
- package/src/plugins.ts +21 -14
- package/src/populate.test.ts +1 -0
- package/src/populate.ts +44 -36
- package/src/realtime/changeStreamWatcher.ts +568 -0
- package/src/realtime/index.ts +34 -0
- package/src/realtime/queryMatcher.ts +179 -0
- package/src/realtime/queryStore.ts +132 -0
- package/src/realtime/realtime.test.ts +1755 -0
- package/src/realtime/realtimeApp.ts +478 -0
- package/src/realtime/registry.ts +64 -0
- package/src/realtime/socketUser.ts +25 -0
- package/src/realtime/types.ts +112 -0
- package/src/requestContext.test.ts +196 -0
- package/src/requestContext.ts +368 -0
- package/src/terrenoApp.test.ts +137 -11
- package/src/terrenoApp.ts +64 -17
- package/src/terrenoPlugin.ts +12 -0
- package/src/tests/bunSetup.ts +1 -0
- package/src/tests.ts +7 -2
- package/src/transformers.test.ts +70 -2
- package/src/transformers.ts +15 -7
- package/src/types/consentResponse.ts +8 -10
- package/src/versionCheckPlugin.ts +15 -7
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
import type { Server } from "socket.io";
|
|
3
|
+
type ChangeStreamDocument = mongoose.mongo.ChangeStreamDocument;
|
|
4
|
+
import type { User } from "../auth";
|
|
5
|
+
import { type RealtimeRegistryEntry } from "./registry";
|
|
6
|
+
import type { ChangeStreamConfig, RealtimeEvent } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* Map MongoDB change stream operation types to our method names.
|
|
9
|
+
*
|
|
10
|
+
* Soft deletes (an `update` that sets `deleted: true`) are reclassified as
|
|
11
|
+
* `"delete"` only when the model has `"delete"` enabled in its realtime
|
|
12
|
+
* methods. Otherwise they fall back to `"update"` so models that subscribe
|
|
13
|
+
* to updates (but not deletes) still see the change — without this fallback,
|
|
14
|
+
* a model configured with `methods: ["create", "update"]` would silently
|
|
15
|
+
* drop soft-delete events.
|
|
16
|
+
*
|
|
17
|
+
* Exported for testing.
|
|
18
|
+
*/
|
|
19
|
+
export declare const mapOperationType: (operationType: string, change: ChangeStreamDocument, enabledMethods?: ReadonlyArray<"create" | "update" | "delete">) => "create" | "update" | "delete" | null;
|
|
20
|
+
/**
|
|
21
|
+
* Determine which Socket.io rooms to emit to based on the room strategy.
|
|
22
|
+
* Exported for testing.
|
|
23
|
+
*/
|
|
24
|
+
export declare const resolveRooms: (entry: RealtimeRegistryEntry, doc: any, method: string) => string[];
|
|
25
|
+
/**
|
|
26
|
+
* Ensure serialized documents include `id` to match REST API responses.
|
|
27
|
+
* Change stream fullDocument payloads are raw BSON objects with `_id` only.
|
|
28
|
+
*/
|
|
29
|
+
export declare const ensureApiId: (data: unknown) => unknown;
|
|
30
|
+
/**
|
|
31
|
+
* Serialize a document for emission.
|
|
32
|
+
*
|
|
33
|
+
* Precedence:
|
|
34
|
+
* 1. `realtimeResponseHandler` if provided (full control over what's emitted).
|
|
35
|
+
* 2. modelRouter `responseHandler` if provided — invoked with a synthetic request
|
|
36
|
+
* so the same stripping logic used for REST responses (e.g. removing `hash`/`salt`)
|
|
37
|
+
* applies to realtime events. This prevents accidental leaks when an app only
|
|
38
|
+
* configures sanitization in the REST `responseHandler`.
|
|
39
|
+
* 3. `toJSON()` fallback.
|
|
40
|
+
*
|
|
41
|
+
* If a user-supplied handler throws, we re-throw so the caller's outer try/catch
|
|
42
|
+
* records the failure and the event is dropped. Falling back to `toJSON()` here
|
|
43
|
+
* would risk leaking unsanitized fields (e.g. `hash`/`salt`) that the handler
|
|
44
|
+
* was supposed to strip.
|
|
45
|
+
*/
|
|
46
|
+
export declare const serializeDoc: (entry: RealtimeRegistryEntry, doc: any, method: "create" | "update" | "delete", user?: User) => Promise<any>;
|
|
47
|
+
export declare const emitToAuthorizedRoom: (io: Server, room: string, event: RealtimeEvent, entry: RealtimeRegistryEntry, fullDocument: any, logDebug: (msg: string) => void) => Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Emit a sync event to document-specific and query rooms.
|
|
50
|
+
*
|
|
51
|
+
* Document rooms: `document:{collection}:{docId}` — clients subscribed to a single document.
|
|
52
|
+
* Query rooms: `query:{queryId}` — clients subscribed to a query filter. The change stream
|
|
53
|
+
* watcher evaluates whether the document matches each active query for the collection.
|
|
54
|
+
*
|
|
55
|
+
* For deletes, we are careful not to leak cross-user activity:
|
|
56
|
+
* - Soft deletes (fullDocument present) are matched against each query like updates so
|
|
57
|
+
* query subscribers only see deletes for docs that matched their filter.
|
|
58
|
+
* - Hard deletes (fullDocument absent) on owner-strategy collections are NOT forwarded
|
|
59
|
+
* to query rooms — subscribers will reconcile on their next fetch. Other strategies
|
|
60
|
+
* forward the delete because the model/broadcast rooms are not user-scoped.
|
|
61
|
+
*
|
|
62
|
+
* Exported for testing.
|
|
63
|
+
*/
|
|
64
|
+
export declare const emitToDocumentAndQueryRooms: (io: Server, collection: string, event: RealtimeEvent, fullDocument: any, logDebug: (msg: string) => void, entry?: RealtimeRegistryEntry) => Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Start watching MongoDB change streams and emitting real-time events.
|
|
67
|
+
*/
|
|
68
|
+
export declare const startChangeStreamWatcher: (io: Server, config?: ChangeStreamConfig, debug?: boolean) => void;
|
|
69
|
+
/**
|
|
70
|
+
* Stop the change stream watcher.
|
|
71
|
+
*/
|
|
72
|
+
export declare const stopChangeStreamWatcher: () => Promise<void>;
|
|
73
|
+
export {};
|