@terreno/api 0.13.3 → 0.14.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.
Files changed (172) hide show
  1. package/dist/__tests__/versionCheckPlugin.test.js +136 -3
  2. package/dist/api.arrayOperations.test.js +1 -0
  3. package/dist/api.d.ts +15 -4
  4. package/dist/api.errors.test.js +1 -0
  5. package/dist/api.hooks.test.js +1 -0
  6. package/dist/api.js +153 -104
  7. package/dist/api.query.test.js +1 -0
  8. package/dist/api.test.js +174 -0
  9. package/dist/auth.d.ts +10 -5
  10. package/dist/auth.js +163 -90
  11. package/dist/auth.test.js +159 -0
  12. package/dist/betterAuthApp.test.js +1 -0
  13. package/dist/betterAuthSetup.d.ts +5 -6
  14. package/dist/betterAuthSetup.js +30 -17
  15. package/dist/betterAuthSetup.test.js +1 -0
  16. package/dist/config.d.ts +48 -0
  17. package/dist/config.js +257 -0
  18. package/dist/config.test.d.ts +1 -0
  19. package/dist/config.test.js +328 -0
  20. package/dist/configuration.test.js +1 -0
  21. package/dist/configurationApp.d.ts +1 -1
  22. package/dist/configurationApp.js +17 -13
  23. package/dist/configurationPlugin.test.js +1 -0
  24. package/dist/consentApp.test.js +1 -0
  25. package/dist/envConfigurationPlugin.d.ts +2 -0
  26. package/dist/envConfigurationPlugin.js +173 -0
  27. package/dist/envConfigurationPlugin.test.d.ts +1 -0
  28. package/dist/envConfigurationPlugin.test.js +322 -0
  29. package/dist/errors.d.ts +18 -7
  30. package/dist/errors.js +111 -12
  31. package/dist/errors.test.js +16 -1
  32. package/dist/example.js +19 -7
  33. package/dist/expressServer.d.ts +10 -9
  34. package/dist/expressServer.js +62 -53
  35. package/dist/expressServer.test.js +165 -2
  36. package/dist/githubAuth.d.ts +2 -1
  37. package/dist/githubAuth.js +41 -26
  38. package/dist/githubAuth.test.js +1 -0
  39. package/dist/index.d.ts +4 -0
  40. package/dist/index.js +4 -0
  41. package/dist/logger.d.ts +1 -1
  42. package/dist/logger.js +42 -20
  43. package/dist/models/versionConfig.d.ts +2 -0
  44. package/dist/models/versionConfig.js +8 -0
  45. package/dist/notifiers/googleChatNotifier.js +14 -16
  46. package/dist/notifiers/googleChatNotifier.test.js +1 -0
  47. package/dist/notifiers/slackNotifier.js +16 -14
  48. package/dist/notifiers/slackNotifier.test.js +41 -3
  49. package/dist/notifiers/zoomNotifier.js +7 -10
  50. package/dist/notifiers/zoomNotifier.test.js +1 -0
  51. package/dist/openApi.d.ts +1 -1
  52. package/dist/openApi.test.js +1 -0
  53. package/dist/openApiBuilder.d.ts +39 -6
  54. package/dist/openApiBuilder.js +1 -31
  55. package/dist/openApiBuilder.test.js +1 -0
  56. package/dist/openApiValidator.js +1 -0
  57. package/dist/openApiValidator.test.js +1 -0
  58. package/dist/permissions.d.ts +4 -4
  59. package/dist/permissions.js +67 -65
  60. package/dist/permissions.middleware.test.js +1 -0
  61. package/dist/permissions.test.js +1 -0
  62. package/dist/plugins.d.ts +5 -5
  63. package/dist/plugins.js +18 -9
  64. package/dist/plugins.test.js +1 -1
  65. package/dist/populate.d.ts +15 -8
  66. package/dist/populate.js +23 -24
  67. package/dist/populate.test.js +1 -0
  68. package/dist/realtime/changeStreamWatcher.d.ts +73 -0
  69. package/dist/realtime/changeStreamWatcher.js +724 -0
  70. package/dist/realtime/index.d.ts +6 -0
  71. package/dist/realtime/index.js +27 -0
  72. package/dist/realtime/queryMatcher.d.ts +14 -0
  73. package/dist/realtime/queryMatcher.js +250 -0
  74. package/dist/realtime/queryStore.d.ts +37 -0
  75. package/dist/realtime/queryStore.js +195 -0
  76. package/dist/realtime/realtime.test.d.ts +10 -0
  77. package/dist/realtime/realtime.test.js +3066 -0
  78. package/dist/realtime/realtimeApp.d.ts +93 -0
  79. package/dist/realtime/realtimeApp.js +560 -0
  80. package/dist/realtime/registry.d.ts +40 -0
  81. package/dist/realtime/registry.js +38 -0
  82. package/dist/realtime/socketUser.d.ts +10 -0
  83. package/dist/realtime/socketUser.js +17 -0
  84. package/dist/realtime/types.d.ts +100 -0
  85. package/dist/realtime/types.js +2 -0
  86. package/dist/requestContext.d.ts +37 -0
  87. package/dist/requestContext.js +344 -0
  88. package/dist/requestContext.test.d.ts +1 -0
  89. package/dist/requestContext.test.js +384 -0
  90. package/dist/terrenoApp.d.ts +8 -0
  91. package/dist/terrenoApp.js +50 -13
  92. package/dist/terrenoApp.test.js +194 -21
  93. package/dist/terrenoPlugin.d.ts +11 -0
  94. package/dist/tests/bunSetup.js +1 -0
  95. package/dist/tests.js +1 -1
  96. package/dist/transformers.d.ts +2 -2
  97. package/dist/transformers.js +5 -3
  98. package/dist/transformers.test.js +90 -0
  99. package/dist/types/consentResponse.d.ts +6 -3
  100. package/dist/versionCheckPlugin.d.ts +2 -0
  101. package/dist/versionCheckPlugin.js +18 -12
  102. package/package.json +4 -2
  103. package/src/__tests__/versionCheckPlugin.test.ts +94 -3
  104. package/src/api.arrayOperations.test.ts +1 -0
  105. package/src/api.errors.test.ts +1 -0
  106. package/src/api.hooks.test.ts +1 -0
  107. package/src/api.query.test.ts +1 -0
  108. package/src/api.test.ts +132 -0
  109. package/src/api.ts +199 -84
  110. package/src/auth.test.ts +160 -0
  111. package/src/auth.ts +120 -50
  112. package/src/betterAuthApp.test.ts +1 -0
  113. package/src/betterAuthSetup.test.ts +1 -0
  114. package/src/betterAuthSetup.ts +59 -22
  115. package/src/config.test.ts +255 -0
  116. package/src/config.ts +216 -0
  117. package/src/configuration.test.ts +1 -0
  118. package/src/configurationApp.ts +59 -24
  119. package/src/configurationPlugin.test.ts +1 -0
  120. package/src/consentApp.test.ts +1 -0
  121. package/src/envConfigurationPlugin.test.ts +143 -0
  122. package/src/envConfigurationPlugin.ts +100 -0
  123. package/src/errors.test.ts +19 -1
  124. package/src/errors.ts +118 -38
  125. package/src/example.ts +49 -21
  126. package/src/express.d.ts +18 -1
  127. package/src/expressServer.test.ts +147 -2
  128. package/src/expressServer.ts +80 -50
  129. package/src/githubAuth.test.ts +1 -0
  130. package/src/githubAuth.ts +59 -38
  131. package/src/index.ts +4 -0
  132. package/src/logger.ts +47 -17
  133. package/src/models/versionConfig.ts +13 -2
  134. package/src/notifiers/googleChatNotifier.test.ts +1 -0
  135. package/src/notifiers/googleChatNotifier.ts +7 -9
  136. package/src/notifiers/slackNotifier.test.ts +29 -3
  137. package/src/notifiers/slackNotifier.ts +9 -7
  138. package/src/notifiers/zoomNotifier.test.ts +1 -0
  139. package/src/notifiers/zoomNotifier.ts +8 -11
  140. package/src/openApi.test.ts +1 -0
  141. package/src/openApi.ts +4 -4
  142. package/src/openApiBuilder.test.ts +1 -0
  143. package/src/openApiBuilder.ts +14 -11
  144. package/src/openApiValidator.test.ts +1 -0
  145. package/src/openApiValidator.ts +3 -2
  146. package/src/permissions.middleware.test.ts +1 -0
  147. package/src/permissions.test.ts +1 -0
  148. package/src/permissions.ts +30 -25
  149. package/src/plugins.test.ts +1 -1
  150. package/src/plugins.ts +21 -14
  151. package/src/populate.test.ts +1 -0
  152. package/src/populate.ts +44 -36
  153. package/src/realtime/changeStreamWatcher.ts +572 -0
  154. package/src/realtime/index.ts +34 -0
  155. package/src/realtime/queryMatcher.ts +179 -0
  156. package/src/realtime/queryStore.ts +132 -0
  157. package/src/realtime/realtime.test.ts +2465 -0
  158. package/src/realtime/realtimeApp.ts +478 -0
  159. package/src/realtime/registry.ts +64 -0
  160. package/src/realtime/socketUser.ts +25 -0
  161. package/src/realtime/types.ts +112 -0
  162. package/src/requestContext.test.ts +321 -0
  163. package/src/requestContext.ts +368 -0
  164. package/src/terrenoApp.test.ts +137 -11
  165. package/src/terrenoApp.ts +64 -17
  166. package/src/terrenoPlugin.ts +12 -0
  167. package/src/tests/bunSetup.ts +1 -0
  168. package/src/tests.ts +7 -2
  169. package/src/transformers.test.ts +70 -2
  170. package/src/transformers.ts +15 -7
  171. package/src/types/consentResponse.ts +8 -10
  172. package/src/versionCheckPlugin.ts +15 -7
@@ -39,6 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
+ // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
42
43
  var bun_test_1 = require("bun:test");
43
44
  var supertest_1 = __importDefault(require("supertest"));
44
45
  var versionConfig_1 = require("../models/versionConfig");
@@ -86,7 +87,7 @@ var versionCheckPlugin_1 = require("../versionCheckPlugin");
86
87
  case 1:
87
88
  res = _a.sent();
88
89
  (0, bun_test_1.expect)(res.status).toBe(200);
89
- (0, bun_test_1.expect)(res.body).toEqual({ status: "ok" });
90
+ (0, bun_test_1.expect)(res.body).toEqual({ pollingIntervalMs: 86400000, status: "ok" });
90
91
  return [2 /*return*/];
91
92
  }
92
93
  });
@@ -131,7 +132,12 @@ var versionCheckPlugin_1 = require("../versionCheckPlugin");
131
132
  case 2:
132
133
  res = _a.sent();
133
134
  (0, bun_test_1.expect)(res.status).toBe(200);
134
- (0, bun_test_1.expect)(res.body).toEqual({ requiredVersion: 50, status: "ok", warningVersion: 100 });
135
+ (0, bun_test_1.expect)(res.body).toEqual({
136
+ pollingIntervalMs: 86400000,
137
+ requiredVersion: 50,
138
+ status: "ok",
139
+ warningVersion: 100,
140
+ });
135
141
  return [2 /*return*/];
136
142
  }
137
143
  });
@@ -236,7 +242,110 @@ var versionCheckPlugin_1 = require("../versionCheckPlugin");
236
242
  case 2:
237
243
  res = _a.sent();
238
244
  (0, bun_test_1.expect)(res.status).toBe(200);
239
- (0, bun_test_1.expect)(res.body).toEqual({ requiredVersion: 50, status: "ok", warningVersion: 100 });
245
+ (0, bun_test_1.expect)(res.body).toEqual({
246
+ pollingIntervalMs: 86400000,
247
+ requiredVersion: 50,
248
+ status: "ok",
249
+ warningVersion: 100,
250
+ });
251
+ return [2 /*return*/];
252
+ }
253
+ });
254
+ }); });
255
+ (0, bun_test_1.it)("returns pollingIntervalMs from config pollingIntervalMinutes", function () { return __awaiter(void 0, void 0, void 0, function () {
256
+ var res;
257
+ return __generator(this, function (_a) {
258
+ switch (_a.label) {
259
+ case 0: return [4 /*yield*/, versionConfig_1.VersionConfig.create({
260
+ pollingIntervalMinutes: 60,
261
+ webRequiredVersion: 0,
262
+ webWarningVersion: 0,
263
+ })];
264
+ case 1:
265
+ _a.sent();
266
+ return [4 /*yield*/, app.get("/version-check").query({ platform: "web", version: 100 })];
267
+ case 2:
268
+ res = _a.sent();
269
+ (0, bun_test_1.expect)(res.status).toBe(200);
270
+ (0, bun_test_1.expect)(res.body.pollingIntervalMs).toBe(3600000);
271
+ return [2 /*return*/];
272
+ }
273
+ });
274
+ }); });
275
+ (0, bun_test_1.it)("returns default pollingIntervalMs (86400000) when pollingIntervalMinutes not set", function () { return __awaiter(void 0, void 0, void 0, function () {
276
+ var res;
277
+ return __generator(this, function (_a) {
278
+ switch (_a.label) {
279
+ case 0: return [4 /*yield*/, versionConfig_1.VersionConfig.create({
280
+ webRequiredVersion: 0,
281
+ webWarningVersion: 0,
282
+ })];
283
+ case 1:
284
+ _a.sent();
285
+ return [4 /*yield*/, app.get("/version-check").query({ platform: "web", version: 100 })];
286
+ case 2:
287
+ res = _a.sent();
288
+ (0, bun_test_1.expect)(res.status).toBe(200);
289
+ (0, bun_test_1.expect)(res.body.pollingIntervalMs).toBe(86400000);
290
+ return [2 /*return*/];
291
+ }
292
+ });
293
+ }); });
294
+ (0, bun_test_1.it)("handles numeric version parameter directly", function () { return __awaiter(void 0, void 0, void 0, function () {
295
+ var res;
296
+ return __generator(this, function (_a) {
297
+ switch (_a.label) {
298
+ case 0: return [4 /*yield*/, versionConfig_1.VersionConfig.create({
299
+ webRequiredVersion: 100,
300
+ webWarningVersion: 150,
301
+ })];
302
+ case 1:
303
+ _a.sent();
304
+ return [4 /*yield*/, app.get("/version-check?version=50&platform=web")];
305
+ case 2:
306
+ res = _a.sent();
307
+ (0, bun_test_1.expect)(res.status).toBe(200);
308
+ (0, bun_test_1.expect)(res.body.status).toBe("required");
309
+ return [2 /*return*/];
310
+ }
311
+ });
312
+ }); });
313
+ (0, bun_test_1.it)("returns default warning message when warningMessage not set", function () { return __awaiter(void 0, void 0, void 0, function () {
314
+ var res;
315
+ return __generator(this, function (_a) {
316
+ switch (_a.label) {
317
+ case 0: return [4 /*yield*/, versionConfig_1.VersionConfig.create({
318
+ webRequiredVersion: 0,
319
+ webWarningVersion: 100,
320
+ })];
321
+ case 1:
322
+ _a.sent();
323
+ return [4 /*yield*/, app.get("/version-check").query({ platform: "web", version: 50 })];
324
+ case 2:
325
+ res = _a.sent();
326
+ (0, bun_test_1.expect)(res.status).toBe(200);
327
+ (0, bun_test_1.expect)(res.body.status).toBe("warning");
328
+ (0, bun_test_1.expect)(res.body.message).toBe("A new version is available. Please update for the best experience.");
329
+ return [2 /*return*/];
330
+ }
331
+ });
332
+ }); });
333
+ (0, bun_test_1.it)("returns default required message when requiredMessage not set", function () { return __awaiter(void 0, void 0, void 0, function () {
334
+ var res;
335
+ return __generator(this, function (_a) {
336
+ switch (_a.label) {
337
+ case 0: return [4 /*yield*/, versionConfig_1.VersionConfig.create({
338
+ webRequiredVersion: 100,
339
+ webWarningVersion: 150,
340
+ })];
341
+ case 1:
342
+ _a.sent();
343
+ return [4 /*yield*/, app.get("/version-check").query({ platform: "web", version: 50 })];
344
+ case 2:
345
+ res = _a.sent();
346
+ (0, bun_test_1.expect)(res.status).toBe(200);
347
+ (0, bun_test_1.expect)(res.body.status).toBe("required");
348
+ (0, bun_test_1.expect)(res.body.message).toBe("This version is no longer supported. Please update to continue.");
240
349
  return [2 /*return*/];
241
350
  }
242
351
  });
@@ -261,3 +370,27 @@ var versionCheckPlugin_1 = require("../versionCheckPlugin");
261
370
  });
262
371
  }); });
263
372
  });
373
+ (0, bun_test_1.describe)("VersionCheckPlugin direct usage", function () {
374
+ (0, bun_test_1.it)("can be instantiated and register called directly on an express app", function () { return __awaiter(void 0, void 0, void 0, function () {
375
+ var express, plugin, expressApp, testApp, res;
376
+ return __generator(this, function (_a) {
377
+ switch (_a.label) {
378
+ case 0:
379
+ express = require("express");
380
+ plugin = new versionCheckPlugin_1.VersionCheckPlugin();
381
+ (0, bun_test_1.expect)(plugin).toBeDefined();
382
+ (0, bun_test_1.expect)(plugin).toBeInstanceOf(versionCheckPlugin_1.VersionCheckPlugin);
383
+ (0, bun_test_1.expect)(typeof plugin.register).toBe("function");
384
+ expressApp = express();
385
+ plugin.register(expressApp);
386
+ testApp = (0, supertest_1.default)(expressApp);
387
+ return [4 /*yield*/, testApp.get("/version-check")];
388
+ case 1:
389
+ res = _a.sent();
390
+ (0, bun_test_1.expect)(res.status).toBe(200);
391
+ (0, bun_test_1.expect)(res.body.status).toBe("ok");
392
+ return [2 /*return*/];
393
+ }
394
+ });
395
+ }); });
396
+ });
@@ -55,6 +55,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
55
55
  return (mod && mod.__esModule) ? mod : { "default": mod };
56
56
  };
57
57
  Object.defineProperty(exports, "__esModule", { value: true });
58
+ // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
58
59
  var bun_test_1 = require("bun:test");
59
60
  var supertest_1 = __importDefault(require("supertest"));
60
61
  var api_1 = require("./api");
package/dist/api.d.ts CHANGED
@@ -4,6 +4,7 @@ import { type User } from "./auth";
4
4
  import { type ModelRouterValidationOptions } from "./openApiValidator";
5
5
  import { type RESTPermissions } from "./permissions";
6
6
  import type { PopulatePath } from "./populate";
7
+ import type { RealtimeConfig } from "./realtime/types";
7
8
  import { type TerrenoTransformer } from "./transformers";
8
9
  export type JSONPrimitive = string | number | boolean | null;
9
10
  export interface JSONArray extends Array<JSONValue> {
@@ -193,13 +194,13 @@ export interface ModelRouterOptions<T> {
193
194
  * Throw an APIError to return a 400 with an error message.
194
195
  * @deprecated: Use responseHandler instead.
195
196
  */
196
- postList?: (value: (Document<any, any, any> & T)[], request: express.Request) => Promise<(Document<any, any, any> & T)[]>;
197
+ postList?: (value: (Document<unknown, unknown, unknown> & T)[], request: express.Request) => Promise<(Document<unknown, unknown, unknown> & T)[]>;
197
198
  /**
198
199
  * Serialize an object or list of objects before returning to the client.
199
200
  * This is a good spot to remove sensitive information from the object, such as passwords or API
200
201
  * keys. Throw an APIError to return a 400 with an error message.
201
202
  */
202
- responseHandler?: (value: (Document<any, any, any> & T) | (Document<any, any, any> & T)[], method: "list" | "create" | "read" | "update" | "delete", request: express.Request, options: ModelRouterOptions<T>) => Promise<JSONValue>;
203
+ responseHandler?: (value: (Document<unknown, unknown, unknown> & T) | (Document<unknown, unknown, unknown> & T)[], method: "list" | "create" | "read" | "update" | "delete", request: express.Request, options: ModelRouterOptions<T>) => Promise<JSONValue>;
203
204
  /**
204
205
  * The OpenAPI generator for this server. This is used to generate the OpenAPI documentation.
205
206
  */
@@ -235,6 +236,14 @@ export interface ModelRouterOptions<T> {
235
236
  * This option overrides the global setting for this specific router.
236
237
  */
237
238
  validation?: boolean | ModelRouterValidationOptions;
239
+ /**
240
+ * Enable real-time sync for this model via WebSocket events.
241
+ * When configured, CRUD operations will emit events to connected clients
242
+ * through the RealtimeApp plugin's change stream watcher.
243
+ *
244
+ * Requires the RealtimeApp plugin to be registered with TerrenoApp.
245
+ */
246
+ realtime?: RealtimeConfig;
238
247
  }
239
248
  /**
240
249
  * Registration object returned by modelRouter when called with a path.
@@ -253,7 +262,7 @@ export interface ModelRouterRegistration {
253
262
  /** The Express router containing CRUD endpoints */
254
263
  router: express.Router;
255
264
  /** @internal Rebuilds the router with the openApi instance injected into options */
256
- _buildWithOpenApi: (openApi: any) => express.Router;
265
+ _buildWithOpenApi: (openApi: OpenApiMiddleware) => express.Router;
257
266
  }
258
267
  /**
259
268
  * Create a set of CRUD routes given a Mongoose model and configuration options.
@@ -324,6 +333,8 @@ export interface AsyncHandlerOptions {
324
333
  * }));
325
334
  * ```
326
335
  */
327
- export declare const asyncHandler: (fn: any, options?: AsyncHandlerOptions) => (req: Request, res: Response, next: NextFunction) => void;
336
+ type AsyncHandlerFn = (req: any, res: Response, next: NextFunction) => Promise<unknown> | unknown;
337
+ export declare const asyncHandler: (fn: AsyncHandlerFn, options?: AsyncHandlerOptions) => (req: Request, res: Response, next: NextFunction) => void;
328
338
  export declare const gooseRestRouter: typeof modelRouter;
329
339
  export type GooseRESTOptions<T> = ModelRouterOptions<T>;
340
+ export {};
@@ -39,6 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
+ // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
42
43
  var bun_test_1 = require("bun:test");
43
44
  var mongoose_1 = __importDefault(require("mongoose"));
44
45
  var errors_1 = require("./errors");
@@ -55,6 +55,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
55
55
  return (mod && mod.__esModule) ? mod : { "default": mod };
56
56
  };
57
57
  Object.defineProperty(exports, "__esModule", { value: true });
58
+ // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
58
59
  var bun_test_1 = require("bun:test");
59
60
  var supertest_1 = __importDefault(require("supertest"));
60
61
  var api_1 = require("./api");