@terreno/api 0.31.0 → 56.0.0-beta.2

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 (232) hide show
  1. package/dist/api.d.ts +10 -0
  2. package/dist/api.js +110 -361
  3. package/dist/auth.d.ts +26 -0
  4. package/dist/auth.js +121 -26
  5. package/dist/betterAuth.d.ts +5 -0
  6. package/dist/betterAuthSetup.js +23 -4
  7. package/dist/docLoader.js +12 -9
  8. package/dist/errors.d.ts +13 -0
  9. package/dist/errors.js +29 -1
  10. package/dist/index.d.ts +17 -1
  11. package/dist/index.js +29 -1
  12. package/dist/middleware.d.ts +7 -0
  13. package/dist/middleware.js +16 -1
  14. package/dist/openApiCompat.d.ts +10 -1
  15. package/dist/openApiCompat.js +115 -47
  16. package/dist/permissions.d.ts +27 -0
  17. package/dist/permissions.js +42 -1
  18. package/dist/plugins.d.ts +13 -0
  19. package/dist/plugins.js +47 -1
  20. package/dist/realtime/changeStreamWatcher.d.ts +100 -3
  21. package/dist/realtime/changeStreamWatcher.js +542 -137
  22. package/dist/realtime/realtimeApp.d.ts +2 -0
  23. package/dist/realtime/realtimeApp.js +83 -27
  24. package/dist/realtime/sessionRevalidation.d.ts +90 -0
  25. package/dist/realtime/sessionRevalidation.js +438 -0
  26. package/dist/realtime/socketAuth.d.ts +97 -0
  27. package/dist/realtime/socketAuth.js +272 -0
  28. package/dist/realtime/socketUser.d.ts +54 -0
  29. package/dist/realtime/socketUser.js +75 -5
  30. package/dist/realtime/types.d.ts +54 -0
  31. package/dist/secretProviders.d.ts +23 -0
  32. package/dist/secretProviders.js +9 -3
  33. package/dist/sync/executors.d.ts +198 -0
  34. package/dist/sync/executors.js +670 -0
  35. package/dist/sync/loadHarness.js +807 -0
  36. package/dist/sync/models.d.ts +216 -0
  37. package/dist/sync/models.js +644 -0
  38. package/dist/sync/mutationHandler.d.ts +97 -0
  39. package/dist/sync/mutationHandler.js +886 -0
  40. package/dist/sync/registry.d.ts +73 -0
  41. package/dist/sync/registry.js +223 -0
  42. package/dist/sync/routes.d.ts +62 -0
  43. package/dist/sync/routes.js +936 -0
  44. package/dist/sync/scripts/compactTombstones.d.ts +47 -0
  45. package/dist/sync/scripts/compactTombstones.js +270 -0
  46. package/dist/sync/serialize.d.ts +20 -0
  47. package/dist/{tests/bunSetup.js → sync/serialize.js} +35 -68
  48. package/dist/sync/socketHandlers.d.ts +54 -0
  49. package/dist/sync/socketHandlers.js +470 -0
  50. package/dist/sync/streams.d.ts +85 -0
  51. package/dist/sync/streams.js +221 -0
  52. package/dist/sync/syncApp.d.ts +29 -0
  53. package/dist/sync/syncApp.js +44 -0
  54. package/dist/sync/syncBatch.d.ts +71 -0
  55. package/dist/sync/syncBatch.js +252 -0
  56. package/dist/sync/syncSeqPlugin.d.ts +8 -0
  57. package/dist/sync/syncSeqPlugin.js +899 -0
  58. package/dist/sync/types.d.ts +254 -0
  59. package/dist/sync/types.js +9 -0
  60. package/dist/terrenoApp.js +90 -27
  61. package/dist/vendor/wesleytodd-openapi/index.d.ts +1 -1
  62. package/dist/vendor/wesleytodd-openapi/lib/ui.d.ts +2 -1
  63. package/package.json +7 -6
  64. package/src/__tests__/openApiCompat.test.ts +20 -0
  65. package/src/api.errors.test.ts +32 -23
  66. package/src/api.test.ts +12 -0
  67. package/src/api.ts +87 -296
  68. package/src/auth.test.ts +202 -0
  69. package/src/auth.ts +134 -23
  70. package/src/betterAuth.ts +6 -0
  71. package/src/betterAuthSetup.test.ts +34 -0
  72. package/src/betterAuthSetup.ts +20 -1
  73. package/src/configuration.test.ts +59 -38
  74. package/src/configurationPlugin.test.ts +72 -42
  75. package/src/docLoader.ts +3 -1
  76. package/src/errors.ts +33 -0
  77. package/src/expressServer.test.ts +7 -1
  78. package/src/index.ts +42 -0
  79. package/src/middleware.test.ts +56 -1
  80. package/src/middleware.ts +15 -0
  81. package/src/openApiCompat.ts +99 -45
  82. package/src/permissions.test.ts +101 -17
  83. package/src/permissions.ts +49 -0
  84. package/src/plugins.test.ts +64 -0
  85. package/src/plugins.ts +56 -0
  86. package/src/realtime/changeStreamWatcher.ts +552 -114
  87. package/src/realtime/realtime.test.ts +157 -0
  88. package/src/realtime/realtimeApp.ts +82 -14
  89. package/src/realtime/realtimeAppSetup.test.ts +25 -27
  90. package/src/realtime/sessionRevalidation.test.ts +423 -0
  91. package/src/realtime/sessionRevalidation.ts +273 -0
  92. package/src/realtime/socketAuth.test.ts +355 -0
  93. package/src/realtime/socketAuth.ts +228 -0
  94. package/src/realtime/socketUser.ts +69 -0
  95. package/src/realtime/types.ts +54 -0
  96. package/src/secretProviders.test.ts +7 -1
  97. package/src/secretProviders.ts +15 -3
  98. package/src/secretProvidersGcpClient.test.ts +66 -0
  99. package/src/sync/ensureSyncIndexes.test.ts +144 -0
  100. package/src/sync/executors.test.ts +882 -0
  101. package/src/sync/executors.ts +705 -0
  102. package/src/sync/integration.test.ts +1160 -0
  103. package/src/sync/loadHarness.ts +618 -0
  104. package/src/sync/models.ts +641 -0
  105. package/src/sync/mutationHandler.test.ts +1252 -0
  106. package/src/sync/mutationHandler.ts +850 -0
  107. package/src/sync/registry.ts +232 -0
  108. package/src/sync/routes.ts +812 -0
  109. package/src/sync/scripts/compactTombstones.test.ts +249 -0
  110. package/src/sync/scripts/compactTombstones.ts +145 -0
  111. package/src/sync/serialize.ts +48 -0
  112. package/src/sync/sessionRevalidationIntegration.test.ts +281 -0
  113. package/src/sync/socketHandlers.ts +320 -0
  114. package/src/sync/streams.ts +188 -0
  115. package/src/sync/sync.test.ts +582 -0
  116. package/src/sync/syncApp.ts +44 -0
  117. package/src/sync/syncBatch.ts +219 -0
  118. package/src/sync/syncFrontier.test.ts +494 -0
  119. package/src/sync/syncPhaseC.test.ts +718 -0
  120. package/src/sync/syncRoutes.test.ts +865 -0
  121. package/src/sync/syncSeqPlugin.ts +730 -0
  122. package/src/sync/syncSocket.test.ts +1440 -0
  123. package/src/sync/types.ts +270 -0
  124. package/src/terrenoApp.ts +37 -17
  125. package/src/tests/bunSetup.ts +8 -0
  126. package/tsconfig.json +4 -4
  127. package/tsconfig.typedoc.json +7 -1
  128. package/dist/__tests__/openApiCompat.test.js +0 -317
  129. package/dist/__tests__/versionCheckPlugin.test.d.ts +0 -1
  130. package/dist/__tests__/versionCheckPlugin.test.js +0 -597
  131. package/dist/actions.openApi.test.d.ts +0 -1
  132. package/dist/actions.openApi.test.js +0 -253
  133. package/dist/actions.test.d.ts +0 -1
  134. package/dist/actions.test.js +0 -1087
  135. package/dist/api.arrayOperations.test.d.ts +0 -1
  136. package/dist/api.arrayOperations.test.js +0 -878
  137. package/dist/api.asyncHandler.test.d.ts +0 -1
  138. package/dist/api.asyncHandler.test.js +0 -236
  139. package/dist/api.coverage.test.d.ts +0 -1
  140. package/dist/api.coverage.test.js +0 -192
  141. package/dist/api.errorPaths.test.d.ts +0 -1
  142. package/dist/api.errorPaths.test.js +0 -887
  143. package/dist/api.errors.test.d.ts +0 -1
  144. package/dist/api.errors.test.js +0 -185
  145. package/dist/api.hooks.test.d.ts +0 -1
  146. package/dist/api.hooks.test.js +0 -950
  147. package/dist/api.query.test.d.ts +0 -1
  148. package/dist/api.query.test.js +0 -948
  149. package/dist/api.test.d.ts +0 -1
  150. package/dist/api.test.js +0 -2820
  151. package/dist/auth.compile.test.d.ts +0 -1
  152. package/dist/auth.compile.test.js +0 -201
  153. package/dist/auth.coverage.test.d.ts +0 -1
  154. package/dist/auth.coverage.test.js +0 -202
  155. package/dist/auth.test.d.ts +0 -1
  156. package/dist/auth.test.js +0 -2286
  157. package/dist/betterAuth.test.d.ts +0 -1
  158. package/dist/betterAuth.test.js +0 -181
  159. package/dist/betterAuthApp.test.d.ts +0 -1
  160. package/dist/betterAuthApp.test.js +0 -242
  161. package/dist/betterAuthSetup.test.d.ts +0 -1
  162. package/dist/betterAuthSetup.test.js +0 -762
  163. package/dist/config.test.d.ts +0 -1
  164. package/dist/config.test.js +0 -353
  165. package/dist/configuration.test.d.ts +0 -1
  166. package/dist/configuration.test.js +0 -980
  167. package/dist/configurationPlugin.test.d.ts +0 -1
  168. package/dist/configurationPlugin.test.js +0 -827
  169. package/dist/consentApp.test.d.ts +0 -1
  170. package/dist/consentApp.test.js +0 -1411
  171. package/dist/docLoader.test.d.ts +0 -1
  172. package/dist/docLoader.test.js +0 -137
  173. package/dist/envConfigurationPlugin.test.d.ts +0 -1
  174. package/dist/envConfigurationPlugin.test.js +0 -369
  175. package/dist/errors.test.d.ts +0 -1
  176. package/dist/errors.test.js +0 -607
  177. package/dist/expressServer.test.d.ts +0 -1
  178. package/dist/expressServer.test.js +0 -1249
  179. package/dist/githubAuth.test.d.ts +0 -1
  180. package/dist/githubAuth.test.js +0 -1142
  181. package/dist/httpClient.test.d.ts +0 -1
  182. package/dist/httpClient.test.js +0 -1471
  183. package/dist/logger.test.d.ts +0 -1
  184. package/dist/logger.test.js +0 -685
  185. package/dist/middleware.test.d.ts +0 -1
  186. package/dist/middleware.test.js +0 -241
  187. package/dist/notifiers/googleChatNotifier.test.d.ts +0 -1
  188. package/dist/notifiers/googleChatNotifier.test.js +0 -298
  189. package/dist/notifiers/slackNotifier.test.d.ts +0 -1
  190. package/dist/notifiers/slackNotifier.test.js +0 -297
  191. package/dist/notifiers/zoomNotifier.test.d.ts +0 -1
  192. package/dist/notifiers/zoomNotifier.test.js +0 -373
  193. package/dist/openApi.test.d.ts +0 -1
  194. package/dist/openApi.test.js +0 -620
  195. package/dist/openApiBuilder.test.d.ts +0 -1
  196. package/dist/openApiBuilder.test.js +0 -599
  197. package/dist/openApiEtag.test.d.ts +0 -1
  198. package/dist/openApiEtag.test.js +0 -86
  199. package/dist/openApiValidator.test.d.ts +0 -1
  200. package/dist/openApiValidator.test.js +0 -795
  201. package/dist/permissions.middleware.test.d.ts +0 -1
  202. package/dist/permissions.middleware.test.js +0 -308
  203. package/dist/permissions.test.d.ts +0 -1
  204. package/dist/permissions.test.js +0 -439
  205. package/dist/plugins.test.d.ts +0 -1
  206. package/dist/plugins.test.js +0 -902
  207. package/dist/populate.test.d.ts +0 -1
  208. package/dist/populate.test.js +0 -370
  209. package/dist/realtime/realtime.test.d.ts +0 -10
  210. package/dist/realtime/realtime.test.js +0 -4213
  211. package/dist/realtime/realtimeAppSetup.test.d.ts +0 -1
  212. package/dist/realtime/realtimeAppSetup.test.js +0 -213
  213. package/dist/requestContext.test.d.ts +0 -1
  214. package/dist/requestContext.test.js +0 -412
  215. package/dist/scriptRunner.test.d.ts +0 -1
  216. package/dist/scriptRunner.test.js +0 -386
  217. package/dist/secretProviders.test.d.ts +0 -1
  218. package/dist/secretProviders.test.js +0 -726
  219. package/dist/syncConsents.test.d.ts +0 -1
  220. package/dist/syncConsents.test.js +0 -522
  221. package/dist/terrenoApp.test.d.ts +0 -1
  222. package/dist/terrenoApp.test.js +0 -489
  223. package/dist/tests/bunSetup.d.ts +0 -1
  224. package/dist/tests/fixtures/compileAuthEntry.d.ts +0 -1
  225. package/dist/tests/fixtures/compileAuthEntry.js +0 -37
  226. package/dist/tests/testEnv.d.ts +0 -0
  227. package/dist/tests/testEnv.js +0 -6
  228. package/dist/transformers.test.d.ts +0 -1
  229. package/dist/transformers.test.js +0 -423
  230. package/dist/utils.test.d.ts +0 -1
  231. package/dist/utils.test.js +0 -242
  232. /package/dist/{__tests__/openApiCompat.test.d.ts → sync/loadHarness.d.ts} +0 -0
@@ -1 +0,0 @@
1
- export {};
@@ -1,685 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- var desc = Object.getOwnPropertyDescriptor(m, k);
16
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
- desc = { enumerable: true, get: function() { return m[k]; } };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26
- }) : function(o, v) {
27
- o["default"] = v;
28
- });
29
- var __importStar = (this && this.__importStar) || (function () {
30
- var ownKeys = function(o) {
31
- ownKeys = Object.getOwnPropertyNames || function (o) {
32
- var ar = [];
33
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
- return ar;
35
- };
36
- return ownKeys(o);
37
- };
38
- return function (mod) {
39
- if (mod && mod.__esModule) return mod;
40
- var result = {};
41
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
- __setModuleDefault(result, mod);
43
- return result;
44
- };
45
- })();
46
- var __importDefault = (this && this.__importDefault) || function (mod) {
47
- return (mod && mod.__esModule) ? mod : { "default": mod };
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- var bun_test_1 = require("bun:test");
51
- var node_fs_1 = __importDefault(require("node:fs"));
52
- var node_os_1 = __importDefault(require("node:os"));
53
- var node_path_1 = __importDefault(require("node:path"));
54
- var node_stream_1 = require("node:stream");
55
- var Sentry = __importStar(require("@sentry/bun"));
56
- var winston_1 = __importDefault(require("winston"));
57
- var logger_1 = require("./logger");
58
- var requestContext_1 = require("./requestContext");
59
- (0, bun_test_1.describe)("logger", function () {
60
- var OLD_ENV = process.env;
61
- (0, bun_test_1.beforeEach)(function () {
62
- process.env = __assign({}, OLD_ENV);
63
- });
64
- (0, bun_test_1.afterEach)(function () {
65
- process.env = OLD_ENV;
66
- });
67
- (0, bun_test_1.it)("logger.info writes a log entry", function () {
68
- (0, bun_test_1.expect)(function () { return logger_1.logger.info("test info message"); }).not.toThrow();
69
- });
70
- (0, bun_test_1.it)("logger.warn writes a log entry", function () {
71
- (0, bun_test_1.expect)(function () { return logger_1.logger.warn("test warn message"); }).not.toThrow();
72
- });
73
- (0, bun_test_1.it)("logger.error writes a log entry", function () {
74
- (0, bun_test_1.expect)(function () { return logger_1.logger.error("test error message"); }).not.toThrow();
75
- });
76
- (0, bun_test_1.it)("logger.debug writes a log entry", function () {
77
- (0, bun_test_1.expect)(function () { return logger_1.logger.debug("test debug message"); }).not.toThrow();
78
- });
79
- (0, bun_test_1.it)("logger.catch handles Error instance", function () {
80
- (0, bun_test_1.expect)(function () { return logger_1.logger.catch(new Error("caught error")); }).not.toThrow();
81
- });
82
- (0, bun_test_1.it)("logger.catch handles non-Error value", function () {
83
- (0, bun_test_1.expect)(function () { return logger_1.logger.catch("string error"); }).not.toThrow();
84
- });
85
- (0, bun_test_1.it)("logger.catch with Sentry logging enabled and Error", function () {
86
- process.env.USE_SENTRY_LOGGING = "true";
87
- (0, bun_test_1.expect)(function () { return logger_1.logger.catch(new Error("captured")); }).not.toThrow();
88
- });
89
- });
90
- (0, bun_test_1.describe)("logger Sentry structured logging", function () {
91
- (0, bun_test_1.afterEach)(function () {
92
- Reflect.deleteProperty(process.env, "USE_SENTRY_LOGGING");
93
- });
94
- (0, bun_test_1.it)("forwards every level to Sentry.logger when USE_SENTRY_LOGGING is true", function () {
95
- var _a, _b, _c, _d;
96
- process.env.USE_SENTRY_LOGGING = "true";
97
- logger_1.logger.debug("sentry-debug-message");
98
- logger_1.logger.info("sentry-info-message");
99
- logger_1.logger.warn("sentry-warn-message");
100
- logger_1.logger.error("sentry-error-message");
101
- (0, bun_test_1.expect)((_a = Sentry.logger) === null || _a === void 0 ? void 0 : _a.debug).toHaveBeenCalledWith("sentry-debug-message", bun_test_1.expect.anything());
102
- (0, bun_test_1.expect)((_b = Sentry.logger) === null || _b === void 0 ? void 0 : _b.info).toHaveBeenCalledWith("sentry-info-message", bun_test_1.expect.anything());
103
- (0, bun_test_1.expect)((_c = Sentry.logger) === null || _c === void 0 ? void 0 : _c.warn).toHaveBeenCalledWith("sentry-warn-message", bun_test_1.expect.anything());
104
- (0, bun_test_1.expect)((_d = Sentry.logger) === null || _d === void 0 ? void 0 : _d.error).toHaveBeenCalledWith("sentry-error-message", bun_test_1.expect.anything());
105
- });
106
- (0, bun_test_1.it)("does not forward to Sentry.logger when USE_SENTRY_LOGGING is unset", function () {
107
- var _a;
108
- Reflect.deleteProperty(process.env, "USE_SENTRY_LOGGING");
109
- (0, bun_test_1.expect)(function () { return logger_1.logger.info("no-sentry-message"); }).not.toThrow();
110
- (0, bun_test_1.expect)((_a = Sentry.logger) === null || _a === void 0 ? void 0 : _a.info).not.toHaveBeenCalledWith("no-sentry-message", bun_test_1.expect.anything());
111
- });
112
- (0, bun_test_1.it)("attaches terrenoRequestLog to Sentry attributes inside a request scope", function () {
113
- var _a;
114
- process.env.USE_SENTRY_LOGGING = "true";
115
- (0, requestContext_1.runWithRequestContext)({ requestId: "sentry-req-1", userId: "sentry-user-1" }, function () {
116
- logger_1.logger.info("sentry-request-scoped-message");
117
- });
118
- (0, bun_test_1.expect)((_a = Sentry.logger) === null || _a === void 0 ? void 0 : _a.info).toHaveBeenCalledWith("sentry-request-scoped-message", bun_test_1.expect.objectContaining({
119
- terrenoRequestLog: bun_test_1.expect.objectContaining({
120
- requestId: "sentry-req-1",
121
- userId: "sentry-user-1",
122
- }),
123
- }));
124
- });
125
- (0, bun_test_1.it)("logs a caught non-Error value via Sentry.logger.error when enabled", function () {
126
- var _a;
127
- process.env.USE_SENTRY_LOGGING = "true";
128
- (0, bun_test_1.expect)(function () { return logger_1.logger.catch("plain-string-failure"); }).not.toThrow();
129
- (0, bun_test_1.expect)((_a = Sentry.logger) === null || _a === void 0 ? void 0 : _a.error).toHaveBeenCalled();
130
- });
131
- (0, bun_test_1.it)("scoped logger catch logs a non-Error value via Sentry.logger.error when enabled", function () {
132
- var _a;
133
- process.env.USE_SENTRY_LOGGING = "true";
134
- var scoped = (0, logger_1.createScopedLogger)({ labels: { jobId: "j1" }, prefix: "[SentryScoped]" });
135
- (0, bun_test_1.expect)(function () { return scoped.catch("scoped-plain-failure"); }).not.toThrow();
136
- (0, bun_test_1.expect)((_a = Sentry.logger) === null || _a === void 0 ? void 0 : _a.error).toHaveBeenCalled();
137
- });
138
- });
139
- (0, bun_test_1.describe)("formatLogContextSuffix", function () {
140
- (0, bun_test_1.it)("includes request ids and sorts terrenoLabels for stable output", function () {
141
- var suffix = (0, logger_1.formatLogContextSuffix)({
142
- requestId: "r1",
143
- terrenoLabels: { alpha: "a", zebra: "z" },
144
- });
145
- (0, bun_test_1.expect)(suffix).toContain("requestId=r1");
146
- (0, bun_test_1.expect)(suffix.indexOf("alpha=a")).toBeLessThan(suffix.indexOf("zebra=z"));
147
- });
148
- (0, bun_test_1.it)("returns empty string when no fields are set", function () {
149
- (0, bun_test_1.expect)((0, logger_1.formatLogContextSuffix)({})).toBe("");
150
- });
151
- (0, bun_test_1.it)("includes terrenoLogPrefix in suffix", function () {
152
- var suffix = (0, logger_1.formatLogContextSuffix)({
153
- requestId: "r1",
154
- terrenoLogPrefix: "[Job]",
155
- });
156
- (0, bun_test_1.expect)(suffix).toContain("logPrefix=[Job]");
157
- (0, bun_test_1.expect)(suffix).toContain("requestId=r1");
158
- });
159
- });
160
- (0, bun_test_1.describe)("createScopedLogger", function () {
161
- (0, bun_test_1.afterEach)(function () {
162
- (0, logger_1.setupLogging)({ disableFileLogging: true });
163
- });
164
- (0, bun_test_1.it)("returns the global logger when prefix and labels are empty", function () {
165
- (0, bun_test_1.expect)((0, logger_1.createScopedLogger)({})).toBe(logger_1.logger);
166
- (0, bun_test_1.expect)((0, logger_1.createScopedLogger)({ labels: { skipped: undefined } })).toBe(logger_1.logger);
167
- });
168
- (0, bun_test_1.it)("prefixes messages when only prefix is set", function () {
169
- var lines = [];
170
- var snapshots = [];
171
- var captureTransport = new winston_1.default.transports.Stream({
172
- format: winston_1.default.format.combine(winston_1.default.format(function (info) {
173
- snapshots.push({
174
- terrenoLogPrefix: info.terrenoLogPrefix,
175
- });
176
- return info;
177
- })(), winston_1.default.format.printf(function (info) {
178
- var msg = typeof info.message === "string" ? info.message : String(info.message);
179
- return "".concat(info.level, ": ").concat(msg);
180
- })),
181
- stream: new node_stream_1.Writable({
182
- write: function (chunk, _encoding, callback) {
183
- lines.push(chunk.toString().trim());
184
- callback();
185
- },
186
- }),
187
- });
188
- logger_1.winstonLogger.add(captureTransport);
189
- try {
190
- (0, logger_1.createScopedLogger)({ prefix: "[ScopedTest]" }).info("hello");
191
- }
192
- finally {
193
- logger_1.winstonLogger.remove(captureTransport);
194
- }
195
- (0, bun_test_1.expect)(lines.some(function (l) { return l.includes("[ScopedTest]") && l.includes("hello"); })).toBe(true);
196
- (0, bun_test_1.expect)(snapshots.some(function (s) { return s.terrenoLogPrefix === "[ScopedTest]"; })).toBe(true);
197
- });
198
- (0, bun_test_1.it)("attaches terrenoLabels to winston metadata for structured transports", function () {
199
- var snapshots = [];
200
- var captureTransport = new winston_1.default.transports.Stream({
201
- format: winston_1.default.format(function (info) {
202
- snapshots.push({
203
- level: info.level,
204
- message: info.message,
205
- terrenoLabels: info.terrenoLabels,
206
- });
207
- return info;
208
- })(),
209
- stream: new node_stream_1.Writable({
210
- write: function (_chunk, _encoding, callback) {
211
- callback();
212
- },
213
- }),
214
- });
215
- logger_1.winstonLogger.add(captureTransport);
216
- try {
217
- (0, logger_1.createScopedLogger)({ labels: { billingId: "b1" } }).warn("charged");
218
- }
219
- finally {
220
- logger_1.winstonLogger.remove(captureTransport);
221
- }
222
- (0, bun_test_1.expect)(snapshots.some(function (s) { var _a; return ((_a = s.terrenoLabels) === null || _a === void 0 ? void 0 : _a.billingId) === "b1"; })).toBe(true);
223
- });
224
- (0, bun_test_1.it)("includes terrenoLogPrefix alongside terrenoLabels in metadata", function () {
225
- var snapshots = [];
226
- var captureTransport = new winston_1.default.transports.Stream({
227
- format: winston_1.default.format(function (info) {
228
- snapshots.push({
229
- terrenoLabels: info.terrenoLabels,
230
- terrenoLogPrefix: info.terrenoLogPrefix,
231
- });
232
- return info;
233
- })(),
234
- stream: new node_stream_1.Writable({
235
- write: function (_chunk, _encoding, callback) {
236
- callback();
237
- },
238
- }),
239
- });
240
- logger_1.winstonLogger.add(captureTransport);
241
- try {
242
- (0, logger_1.createScopedLogger)({ labels: { x: "1" }, prefix: "[Both]" }).info("m");
243
- }
244
- finally {
245
- logger_1.winstonLogger.remove(captureTransport);
246
- }
247
- (0, bun_test_1.expect)(snapshots.some(function (s) {
248
- var _a;
249
- return ((_a = s.terrenoLabels) === null || _a === void 0 ? void 0 : _a.x) === "1" &&
250
- s.terrenoLogPrefix === "[Both]";
251
- })).toBe(true);
252
- });
253
- (0, bun_test_1.it)("merges all request context fields including jobId, sessionId, spanId, traceId, traceSampled", function () {
254
- var snapshots = [];
255
- var captureTransport = new winston_1.default.transports.Stream({
256
- format: winston_1.default.format(function (info) {
257
- snapshots.push({
258
- jobId: info.jobId,
259
- requestId: info.requestId,
260
- sessionId: info.sessionId,
261
- spanId: info.spanId,
262
- traceId: info.traceId,
263
- traceSampled: info.traceSampled,
264
- userId: info.userId,
265
- });
266
- return info;
267
- })(),
268
- stream: new node_stream_1.Writable({
269
- write: function (_chunk, _encoding, callback) {
270
- callback();
271
- },
272
- }),
273
- });
274
- logger_1.winstonLogger.add(captureTransport);
275
- try {
276
- (0, requestContext_1.runWithRequestContext)({
277
- jobId: "job-42",
278
- requestId: "req-full",
279
- sessionId: "sess-7",
280
- spanId: "span-abc",
281
- traceId: "trace-xyz",
282
- traceSampled: true,
283
- userId: "user-1",
284
- }, function () {
285
- logger_1.logger.info("full context");
286
- });
287
- }
288
- finally {
289
- logger_1.winstonLogger.remove(captureTransport);
290
- }
291
- var entry = snapshots.find(function (s) { return s.requestId === "req-full"; });
292
- (0, bun_test_1.expect)(entry).toBeDefined();
293
- (0, bun_test_1.expect)(entry === null || entry === void 0 ? void 0 : entry.jobId).toBe("job-42");
294
- (0, bun_test_1.expect)(entry === null || entry === void 0 ? void 0 : entry.sessionId).toBe("sess-7");
295
- (0, bun_test_1.expect)(entry === null || entry === void 0 ? void 0 : entry.spanId).toBe("span-abc");
296
- (0, bun_test_1.expect)(entry === null || entry === void 0 ? void 0 : entry.traceId).toBe("trace-xyz");
297
- (0, bun_test_1.expect)(entry === null || entry === void 0 ? void 0 : entry.traceSampled).toBe(true);
298
- (0, bun_test_1.expect)(entry === null || entry === void 0 ? void 0 : entry.userId).toBe("user-1");
299
- });
300
- (0, bun_test_1.it)("exercises all scoped logger methods (debug, error, catch)", function () {
301
- var lines = [];
302
- var captureTransport = new winston_1.default.transports.Stream({
303
- format: winston_1.default.format.printf(function (info) {
304
- var msg = typeof info.message === "string" ? info.message : String(info.message);
305
- return "".concat(info.level, ": ").concat(msg);
306
- }),
307
- stream: new node_stream_1.Writable({
308
- write: function (chunk, _encoding, callback) {
309
- lines.push(chunk.toString().trim());
310
- callback();
311
- },
312
- }),
313
- });
314
- logger_1.winstonLogger.add(captureTransport);
315
- try {
316
- var scoped = (0, logger_1.createScopedLogger)({ prefix: "[Methods]" });
317
- scoped.debug("d-msg");
318
- scoped.error("e-msg");
319
- scoped.catch(new Error("caught-msg"));
320
- }
321
- finally {
322
- logger_1.winstonLogger.remove(captureTransport);
323
- }
324
- (0, bun_test_1.expect)(lines.some(function (l) { return l.includes("[Methods]") && l.includes("d-msg"); })).toBe(true);
325
- (0, bun_test_1.expect)(lines.some(function (l) { return l.includes("[Methods]") && l.includes("e-msg"); })).toBe(true);
326
- (0, bun_test_1.expect)(lines.some(function (l) { return l.includes("[Methods]") && l.includes("caught-msg"); })).toBe(true);
327
- });
328
- (0, bun_test_1.it)("scoped logger catch with Sentry enabled and Error instance", function () {
329
- var OLD_ENV = process.env;
330
- process.env = __assign(__assign({}, OLD_ENV), { USE_SENTRY_LOGGING: "true" });
331
- try {
332
- var scoped_1 = (0, logger_1.createScopedLogger)({ prefix: "[Sentry]" });
333
- (0, bun_test_1.expect)(function () { return scoped_1.catch(new Error("sentry scoped error")); }).not.toThrow();
334
- }
335
- finally {
336
- process.env = OLD_ENV;
337
- }
338
- });
339
- (0, bun_test_1.it)("attaches terrenoRequestLog while request ALS scope is active", function () {
340
- var _a, _b;
341
- var snapshots = [];
342
- var captureTransport = new winston_1.default.transports.Stream({
343
- format: winston_1.default.format(function (info) {
344
- snapshots.push({
345
- terrenoRequestLog: info
346
- .terrenoRequestLog,
347
- });
348
- return info;
349
- })(),
350
- stream: new node_stream_1.Writable({
351
- write: function (_chunk, _encoding, callback) {
352
- callback();
353
- },
354
- }),
355
- });
356
- logger_1.winstonLogger.add(captureTransport);
357
- try {
358
- (0, requestContext_1.runWithRequestContext)({ requestId: "req-als-1", userId: "user-99" }, function () {
359
- logger_1.logger.info("in scope");
360
- });
361
- (0, requestContext_1.runWithRequestContext)({ requestId: "req-als-2" }, function () {
362
- logger_1.logger.info("anon");
363
- });
364
- }
365
- finally {
366
- logger_1.winstonLogger.remove(captureTransport);
367
- }
368
- var withUser = snapshots.find(function (s) { var _a; return ((_a = s.terrenoRequestLog) === null || _a === void 0 ? void 0 : _a.requestId) === "req-als-1"; });
369
- (0, bun_test_1.expect)((_a = withUser === null || withUser === void 0 ? void 0 : withUser.terrenoRequestLog) === null || _a === void 0 ? void 0 : _a.userId).toBe("user-99");
370
- var anon = snapshots.find(function (s) { var _a; return ((_a = s.terrenoRequestLog) === null || _a === void 0 ? void 0 : _a.requestId) === "req-als-2"; });
371
- (0, bun_test_1.expect)((_b = anon === null || anon === void 0 ? void 0 : anon.terrenoRequestLog) === null || _b === void 0 ? void 0 : _b.userId).toBeNull();
372
- });
373
- });
374
- (0, bun_test_1.describe)("createFeatureFlaggedLogger", function () {
375
- (0, bun_test_1.afterEach)(function () {
376
- (0, logger_1.setupLogging)({ disableFileLogging: true });
377
- });
378
- (0, bun_test_1.it)("drops info lines while disabled", function () {
379
- var hits = 0;
380
- var captureTransport = new winston_1.default.transports.Stream({
381
- format: winston_1.default.format.printf(function () {
382
- hits += 1;
383
- return "";
384
- }),
385
- stream: new node_stream_1.Writable({
386
- write: function (_chunk, _encoding, callback) {
387
- callback();
388
- },
389
- }),
390
- });
391
- logger_1.winstonLogger.add(captureTransport);
392
- try {
393
- var log = (0, logger_1.createFeatureFlaggedLogger)({ isEnabled: function () { return false; }, target: logger_1.logger });
394
- log.info("hidden");
395
- }
396
- finally {
397
- logger_1.winstonLogger.remove(captureTransport);
398
- }
399
- (0, bun_test_1.expect)(hits).toBe(0);
400
- });
401
- (0, bun_test_1.it)("forwards lines when enabled", function () {
402
- var hits = 0;
403
- var captureTransport = new winston_1.default.transports.Stream({
404
- format: winston_1.default.format.printf(function () {
405
- hits += 1;
406
- return "";
407
- }),
408
- stream: new node_stream_1.Writable({
409
- write: function (_chunk, _encoding, callback) {
410
- callback();
411
- },
412
- }),
413
- });
414
- logger_1.winstonLogger.add(captureTransport);
415
- try {
416
- var log = (0, logger_1.createFeatureFlaggedLogger)({ isEnabled: function () { return true; }, target: logger_1.logger });
417
- log.info("visible");
418
- }
419
- finally {
420
- logger_1.winstonLogger.remove(captureTransport);
421
- }
422
- (0, bun_test_1.expect)(hits).toBeGreaterThan(0);
423
- });
424
- (0, bun_test_1.it)("forwards catch while disabled when gateCatch is false", function () {
425
- var hits = 0;
426
- var captureTransport = new winston_1.default.transports.Stream({
427
- format: winston_1.default.format.printf(function () {
428
- hits += 1;
429
- return "";
430
- }),
431
- stream: new node_stream_1.Writable({
432
- write: function (_chunk, _encoding, callback) {
433
- callback();
434
- },
435
- }),
436
- });
437
- logger_1.winstonLogger.add(captureTransport);
438
- try {
439
- var log = (0, logger_1.createFeatureFlaggedLogger)({
440
- gateCatch: false,
441
- isEnabled: function () { return false; },
442
- target: logger_1.logger,
443
- });
444
- log.catch(new Error("still-logged"));
445
- }
446
- finally {
447
- logger_1.winstonLogger.remove(captureTransport);
448
- }
449
- (0, bun_test_1.expect)(hits).toBeGreaterThan(0);
450
- });
451
- (0, bun_test_1.it)("forwards all methods when enabled (debug, warn, error)", function () {
452
- var levels = [];
453
- var captureTransport = new winston_1.default.transports.Stream({
454
- format: winston_1.default.format(function (info) {
455
- levels.push(info.level);
456
- return info;
457
- })(),
458
- stream: new node_stream_1.Writable({
459
- write: function (_chunk, _encoding, callback) {
460
- callback();
461
- },
462
- }),
463
- });
464
- logger_1.winstonLogger.add(captureTransport);
465
- try {
466
- var log = (0, logger_1.createFeatureFlaggedLogger)({ isEnabled: function () { return true; }, target: logger_1.logger });
467
- log.debug("d");
468
- log.warn("w");
469
- log.error("e");
470
- }
471
- finally {
472
- logger_1.winstonLogger.remove(captureTransport);
473
- }
474
- (0, bun_test_1.expect)(levels.some(function (l) { return l === "debug"; })).toBe(true);
475
- (0, bun_test_1.expect)(levels.some(function (l) { return l === "warn"; })).toBe(true);
476
- (0, bun_test_1.expect)(levels.some(function (l) { return l === "error"; })).toBe(true);
477
- });
478
- (0, bun_test_1.it)("drops debug, warn, error lines when disabled", function () {
479
- var hits = 0;
480
- var captureTransport = new winston_1.default.transports.Stream({
481
- format: winston_1.default.format.printf(function () {
482
- hits += 1;
483
- return "";
484
- }),
485
- stream: new node_stream_1.Writable({
486
- write: function (_chunk, _encoding, callback) {
487
- callback();
488
- },
489
- }),
490
- });
491
- logger_1.winstonLogger.add(captureTransport);
492
- try {
493
- var log = (0, logger_1.createFeatureFlaggedLogger)({ isEnabled: function () { return false; }, target: logger_1.logger });
494
- log.debug("hidden-d");
495
- log.warn("hidden-w");
496
- log.error("hidden-e");
497
- }
498
- finally {
499
- logger_1.winstonLogger.remove(captureTransport);
500
- }
501
- (0, bun_test_1.expect)(hits).toBe(0);
502
- });
503
- (0, bun_test_1.it)("uses the global logger as default target when target is not provided", function () {
504
- var log = (0, logger_1.createFeatureFlaggedLogger)({ isEnabled: function () { return true; } });
505
- (0, bun_test_1.expect)(function () { return log.info("default target"); }).not.toThrow();
506
- });
507
- (0, bun_test_1.it)("drops catch while disabled when gateCatch is true", function () {
508
- var hits = 0;
509
- var captureTransport = new winston_1.default.transports.Stream({
510
- format: winston_1.default.format.printf(function () {
511
- hits += 1;
512
- return "";
513
- }),
514
- stream: new node_stream_1.Writable({
515
- write: function (_chunk, _encoding, callback) {
516
- callback();
517
- },
518
- }),
519
- });
520
- logger_1.winstonLogger.add(captureTransport);
521
- try {
522
- var log = (0, logger_1.createFeatureFlaggedLogger)({
523
- gateCatch: true,
524
- isEnabled: function () { return false; },
525
- target: logger_1.logger,
526
- });
527
- log.catch(new Error("suppressed"));
528
- }
529
- finally {
530
- logger_1.winstonLogger.remove(captureTransport);
531
- }
532
- (0, bun_test_1.expect)(hits).toBe(0);
533
- });
534
- });
535
- (0, bun_test_1.describe)("setupLogging", function () {
536
- var tempDir;
537
- (0, bun_test_1.beforeEach)(function () {
538
- tempDir = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "logger-test-"));
539
- });
540
- (0, bun_test_1.afterEach)(function () {
541
- try {
542
- node_fs_1.default.rmSync(tempDir, { force: true, recursive: true });
543
- }
544
- catch (_a) { }
545
- // Restore a default logger config
546
- (0, logger_1.setupLogging)({ disableFileLogging: true });
547
- });
548
- (0, bun_test_1.it)("disables console logging when disableConsoleLogging is true", function () {
549
- (0, bun_test_1.expect)(function () {
550
- return (0, logger_1.setupLogging)({
551
- disableConsoleLogging: true,
552
- disableFileLogging: true,
553
- });
554
- }).not.toThrow();
555
- });
556
- (0, bun_test_1.it)("disables console colors when disableConsoleColors is true", function () {
557
- (0, bun_test_1.expect)(function () {
558
- return (0, logger_1.setupLogging)({
559
- disableConsoleColors: true,
560
- disableFileLogging: true,
561
- });
562
- }).not.toThrow();
563
- });
564
- (0, bun_test_1.it)("adds timestamps when showConsoleTimestamps is true", function () {
565
- (0, bun_test_1.expect)(function () {
566
- return (0, logger_1.setupLogging)({
567
- disableFileLogging: true,
568
- showConsoleTimestamps: true,
569
- });
570
- }).not.toThrow();
571
- });
572
- (0, bun_test_1.it)("respects logLevel option", function () {
573
- (0, bun_test_1.expect)(function () {
574
- return (0, logger_1.setupLogging)({
575
- disableFileLogging: true,
576
- level: "info",
577
- });
578
- }).not.toThrow();
579
- });
580
- (0, bun_test_1.it)("creates log directory if it does not exist", function () {
581
- var nonExistentDir = node_path_1.default.join(tempDir, "nested", "logs");
582
- (0, logger_1.setupLogging)({
583
- disableConsoleLogging: true,
584
- logDirectory: nonExistentDir,
585
- });
586
- (0, bun_test_1.expect)(node_fs_1.default.existsSync(nonExistentDir)).toBe(true);
587
- });
588
- (0, bun_test_1.it)("uses existing log directory if it exists", function () {
589
- var existingDir = node_path_1.default.join(tempDir, "existing");
590
- node_fs_1.default.mkdirSync(existingDir);
591
- (0, bun_test_1.expect)(function () {
592
- return (0, logger_1.setupLogging)({
593
- disableConsoleLogging: true,
594
- logDirectory: existingDir,
595
- });
596
- }).not.toThrow();
597
- });
598
- (0, bun_test_1.it)("adds custom transports when provided", function () {
599
- var customTransport = new winston_1.default.transports.Console({ level: "error" });
600
- (0, bun_test_1.expect)(function () {
601
- return (0, logger_1.setupLogging)({
602
- disableConsoleLogging: true,
603
- disableFileLogging: true,
604
- transports: [customTransport],
605
- });
606
- }).not.toThrow();
607
- });
608
- (0, bun_test_1.it)("uses file logging at info level when level is info (no debug file)", function () {
609
- (0, logger_1.setupLogging)({
610
- disableConsoleLogging: true,
611
- level: "info",
612
- logDirectory: tempDir,
613
- });
614
- // No assertion needed - just verifying branch coverage with level=info
615
- (0, bun_test_1.expect)(true).toBe(true);
616
- });
617
- (0, bun_test_1.it)("uses file logging at debug level by default (with debug file)", function () {
618
- (0, logger_1.setupLogging)({
619
- disableConsoleLogging: true,
620
- logDirectory: tempDir,
621
- });
622
- (0, bun_test_1.expect)(true).toBe(true);
623
- });
624
- (0, bun_test_1.it)("console format includes timestamps when showConsoleTimestamps is true", function () {
625
- var lines = [];
626
- (0, logger_1.setupLogging)({
627
- disableFileLogging: true,
628
- showConsoleTimestamps: true,
629
- });
630
- var captureTransport = new winston_1.default.transports.Stream({
631
- format: winston_1.default.format.combine(winston_1.default.format.timestamp(), winston_1.default.format.printf(function (info) {
632
- if (info.timestamp) {
633
- return "".concat(info.timestamp, " - ").concat(info.level, ": ").concat(info.message);
634
- }
635
- return "".concat(info.level, ": ").concat(info.message);
636
- })),
637
- stream: new node_stream_1.Writable({
638
- write: function (chunk, _encoding, callback) {
639
- lines.push(chunk.toString().trim());
640
- callback();
641
- },
642
- }),
643
- });
644
- logger_1.winstonLogger.add(captureTransport);
645
- try {
646
- logger_1.logger.info("timestamp-test");
647
- }
648
- finally {
649
- logger_1.winstonLogger.remove(captureTransport);
650
- }
651
- (0, bun_test_1.expect)(lines.some(function (l) { return l.includes("timestamp-test"); })).toBe(true);
652
- });
653
- (0, bun_test_1.it)("disableTerrenoDevJsonlLog skips the dev JSONL transport", function () {
654
- (0, bun_test_1.expect)(function () {
655
- return (0, logger_1.setupLogging)({
656
- disableFileLogging: true,
657
- disableTerrenoDevJsonlLog: true,
658
- });
659
- }).not.toThrow();
660
- });
661
- (0, bun_test_1.it)("attaches the dev JSONL transport when TERRENO_LOG_FILE forces it on", function () {
662
- var originalCwd = process.cwd();
663
- process.env.TERRENO_LOG_FILE = "true";
664
- try {
665
- process.chdir(tempDir);
666
- (0, logger_1.setupLogging)({ disableConsoleLogging: true, disableFileLogging: true });
667
- (0, bun_test_1.expect)(node_fs_1.default.existsSync(node_path_1.default.join(tempDir, ".terreno", "logs"))).toBe(true);
668
- }
669
- finally {
670
- process.chdir(originalCwd);
671
- Reflect.deleteProperty(process.env, "TERRENO_LOG_FILE");
672
- }
673
- });
674
- (0, bun_test_1.it)("skips the dev JSONL transport when TERRENO_LOG_FILE forces it off", function () {
675
- process.env.TERRENO_LOG_FILE = "false";
676
- try {
677
- (0, bun_test_1.expect)(function () {
678
- return (0, logger_1.setupLogging)({ disableConsoleLogging: true, disableFileLogging: true });
679
- }).not.toThrow();
680
- }
681
- finally {
682
- Reflect.deleteProperty(process.env, "TERRENO_LOG_FILE");
683
- }
684
- });
685
- });