@terreno/api 0.31.0 → 56.0.0-beta.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.
Files changed (250) hide show
  1. package/CHANGELOG.md +122 -2
  2. package/LICENSE +202 -21
  3. package/dist/api.d.ts +12 -3
  4. package/dist/api.js +110 -361
  5. package/dist/auth.d.ts +26 -0
  6. package/dist/auth.js +100 -1
  7. package/dist/betterAuth.d.ts +5 -0
  8. package/dist/betterAuthSetup.d.ts +1 -15
  9. package/dist/betterAuthSetup.js +29 -8
  10. package/dist/configurationPlugin.js +2 -2
  11. package/dist/docLoader.js +12 -9
  12. package/dist/errors.d.ts +13 -0
  13. package/dist/errors.js +29 -1
  14. package/dist/expressServer.js +5 -11
  15. package/dist/githubAuth.js +4 -1
  16. package/dist/index.d.ts +17 -1
  17. package/dist/index.js +29 -1
  18. package/dist/middleware.d.ts +7 -0
  19. package/dist/middleware.js +16 -1
  20. package/dist/openApiCompat.d.ts +10 -1
  21. package/dist/openApiCompat.js +115 -47
  22. package/dist/permissions.d.ts +27 -0
  23. package/dist/permissions.js +42 -1
  24. package/dist/plugins.d.ts +15 -3
  25. package/dist/plugins.js +36 -6
  26. package/dist/realtime/changeStreamWatcher.d.ts +100 -3
  27. package/dist/realtime/changeStreamWatcher.js +542 -137
  28. package/dist/realtime/realtimeApp.d.ts +3 -1
  29. package/dist/realtime/realtimeApp.js +75 -27
  30. package/dist/realtime/sessionRevalidation.d.ts +90 -0
  31. package/dist/realtime/sessionRevalidation.js +438 -0
  32. package/dist/realtime/socketAuth.d.ts +97 -0
  33. package/dist/realtime/socketAuth.js +272 -0
  34. package/dist/realtime/socketUser.d.ts +54 -0
  35. package/dist/realtime/socketUser.js +75 -5
  36. package/dist/realtime/types.d.ts +40 -0
  37. package/dist/secretProviders.d.ts +23 -0
  38. package/dist/secretProviders.js +9 -3
  39. package/dist/sync/executors.d.ts +198 -0
  40. package/dist/sync/executors.js +670 -0
  41. package/dist/sync/loadHarness.js +807 -0
  42. package/dist/sync/models.d.ts +216 -0
  43. package/dist/sync/models.js +644 -0
  44. package/dist/sync/mutationHandler.d.ts +97 -0
  45. package/dist/sync/mutationHandler.js +886 -0
  46. package/dist/sync/registry.d.ts +73 -0
  47. package/dist/sync/registry.js +223 -0
  48. package/dist/sync/routes.d.ts +62 -0
  49. package/dist/sync/routes.js +936 -0
  50. package/dist/sync/scripts/compactTombstones.d.ts +47 -0
  51. package/dist/sync/scripts/compactTombstones.js +270 -0
  52. package/dist/sync/serialize.d.ts +20 -0
  53. package/dist/{tests/bunSetup.js → sync/serialize.js} +35 -68
  54. package/dist/sync/socketHandlers.d.ts +54 -0
  55. package/dist/sync/socketHandlers.js +470 -0
  56. package/dist/sync/streams.d.ts +85 -0
  57. package/dist/sync/streams.js +221 -0
  58. package/dist/sync/syncApp.d.ts +29 -0
  59. package/dist/sync/syncApp.js +44 -0
  60. package/dist/sync/syncBatch.d.ts +71 -0
  61. package/dist/sync/syncBatch.js +252 -0
  62. package/dist/sync/syncSeqPlugin.d.ts +8 -0
  63. package/dist/sync/syncSeqPlugin.js +903 -0
  64. package/dist/sync/types.d.ts +254 -0
  65. package/dist/sync/types.js +9 -0
  66. package/dist/terrenoApp.js +90 -27
  67. package/dist/tests/models.d.ts +11 -27
  68. package/dist/tests/models.js +3 -5
  69. package/dist/tests/testHelper.d.ts +3 -9
  70. package/dist/vendor/wesleytodd-openapi/index.d.ts +1 -1
  71. package/dist/vendor/wesleytodd-openapi/lib/ui.d.ts +2 -1
  72. package/package.json +10 -8
  73. package/src/__tests__/openApiCompat.test.ts +20 -0
  74. package/src/actions.test.ts +12 -19
  75. package/src/actions.ts +2 -2
  76. package/src/api.coverage.test.ts +9 -7
  77. package/src/api.errorPaths.test.ts +1 -47
  78. package/src/api.test.ts +12 -0
  79. package/src/api.ts +98 -317
  80. package/src/auth.test.ts +128 -176
  81. package/src/auth.ts +109 -0
  82. package/src/betterAuth.ts +6 -0
  83. package/src/betterAuthSetup.test.ts +34 -0
  84. package/src/betterAuthSetup.ts +27 -8
  85. package/src/configurationPlugin.ts +2 -2
  86. package/src/consentApp.test.ts +12 -12
  87. package/src/docLoader.ts +3 -1
  88. package/src/errors.ts +33 -0
  89. package/src/expressServer.test.ts +7 -1
  90. package/src/expressServer.ts +5 -11
  91. package/src/githubAuth.ts +3 -1
  92. package/src/index.ts +42 -0
  93. package/src/middleware.test.ts +40 -1
  94. package/src/middleware.ts +15 -0
  95. package/src/models/versionConfig.ts +1 -1
  96. package/src/openApiBuilder.test.ts +9 -24
  97. package/src/openApiCompat.ts +99 -45
  98. package/src/openApiValidator.test.ts +0 -41
  99. package/src/permissions.test.ts +75 -1
  100. package/src/permissions.ts +49 -0
  101. package/src/plugins.test.ts +54 -14
  102. package/src/plugins.ts +47 -9
  103. package/src/populate.test.ts +16 -25
  104. package/src/realtime/changeStreamWatcher.ts +552 -114
  105. package/src/realtime/realtime.test.ts +157 -239
  106. package/src/realtime/realtimeApp.ts +80 -19
  107. package/src/realtime/sessionRevalidation.test.ts +423 -0
  108. package/src/realtime/sessionRevalidation.ts +273 -0
  109. package/src/realtime/socketAuth.test.ts +355 -0
  110. package/src/realtime/socketAuth.ts +228 -0
  111. package/src/realtime/socketUser.ts +69 -0
  112. package/src/realtime/types.ts +40 -0
  113. package/src/secretProviders.test.ts +7 -1
  114. package/src/secretProviders.ts +15 -3
  115. package/src/sync/ensureSyncIndexes.test.ts +144 -0
  116. package/src/sync/executors.test.ts +882 -0
  117. package/src/sync/executors.ts +703 -0
  118. package/src/sync/integration.test.ts +1160 -0
  119. package/src/sync/loadHarness.ts +618 -0
  120. package/src/sync/models.ts +640 -0
  121. package/src/sync/mutationHandler.test.ts +1252 -0
  122. package/src/sync/mutationHandler.ts +850 -0
  123. package/src/sync/registry.ts +232 -0
  124. package/src/sync/routes.ts +812 -0
  125. package/src/sync/scripts/compactTombstones.test.ts +249 -0
  126. package/src/sync/scripts/compactTombstones.ts +145 -0
  127. package/src/sync/serialize.ts +48 -0
  128. package/src/sync/sessionRevalidationIntegration.test.ts +281 -0
  129. package/src/sync/socketHandlers.ts +320 -0
  130. package/src/sync/streams.ts +188 -0
  131. package/src/sync/sync.test.ts +582 -0
  132. package/src/sync/syncApp.ts +44 -0
  133. package/src/sync/syncBatch.ts +219 -0
  134. package/src/sync/syncFrontier.test.ts +494 -0
  135. package/src/sync/syncPhaseC.test.ts +718 -0
  136. package/src/sync/syncRoutes.test.ts +865 -0
  137. package/src/sync/syncSeqPlugin.ts +738 -0
  138. package/src/sync/syncSocket.test.ts +1440 -0
  139. package/src/sync/types.ts +270 -0
  140. package/src/terrenoApp.ts +37 -17
  141. package/src/tests/bunSetup.ts +8 -0
  142. package/src/tests/models.ts +6 -8
  143. package/tsconfig.json +4 -4
  144. package/tsconfig.typedoc.json +7 -1
  145. package/dist/__tests__/openApiCompat.test.js +0 -317
  146. package/dist/__tests__/versionCheckPlugin.test.d.ts +0 -1
  147. package/dist/__tests__/versionCheckPlugin.test.js +0 -597
  148. package/dist/actions.openApi.test.d.ts +0 -1
  149. package/dist/actions.openApi.test.js +0 -253
  150. package/dist/actions.test.d.ts +0 -1
  151. package/dist/actions.test.js +0 -1087
  152. package/dist/api.arrayOperations.test.d.ts +0 -1
  153. package/dist/api.arrayOperations.test.js +0 -878
  154. package/dist/api.asyncHandler.test.d.ts +0 -1
  155. package/dist/api.asyncHandler.test.js +0 -236
  156. package/dist/api.coverage.test.d.ts +0 -1
  157. package/dist/api.coverage.test.js +0 -192
  158. package/dist/api.errorPaths.test.d.ts +0 -1
  159. package/dist/api.errorPaths.test.js +0 -887
  160. package/dist/api.errors.test.d.ts +0 -1
  161. package/dist/api.errors.test.js +0 -185
  162. package/dist/api.hooks.test.d.ts +0 -1
  163. package/dist/api.hooks.test.js +0 -950
  164. package/dist/api.query.test.d.ts +0 -1
  165. package/dist/api.query.test.js +0 -948
  166. package/dist/api.test.d.ts +0 -1
  167. package/dist/api.test.js +0 -2820
  168. package/dist/auth.compile.test.d.ts +0 -1
  169. package/dist/auth.compile.test.js +0 -201
  170. package/dist/auth.coverage.test.d.ts +0 -1
  171. package/dist/auth.coverage.test.js +0 -202
  172. package/dist/auth.test.d.ts +0 -1
  173. package/dist/auth.test.js +0 -2286
  174. package/dist/betterAuth.test.d.ts +0 -1
  175. package/dist/betterAuth.test.js +0 -181
  176. package/dist/betterAuthApp.test.d.ts +0 -1
  177. package/dist/betterAuthApp.test.js +0 -242
  178. package/dist/betterAuthSetup.test.d.ts +0 -1
  179. package/dist/betterAuthSetup.test.js +0 -762
  180. package/dist/config.test.d.ts +0 -1
  181. package/dist/config.test.js +0 -353
  182. package/dist/configuration.test.d.ts +0 -1
  183. package/dist/configuration.test.js +0 -980
  184. package/dist/configurationPlugin.test.d.ts +0 -1
  185. package/dist/configurationPlugin.test.js +0 -827
  186. package/dist/consentApp.test.d.ts +0 -1
  187. package/dist/consentApp.test.js +0 -1411
  188. package/dist/docLoader.test.d.ts +0 -1
  189. package/dist/docLoader.test.js +0 -137
  190. package/dist/envConfigurationPlugin.test.d.ts +0 -1
  191. package/dist/envConfigurationPlugin.test.js +0 -369
  192. package/dist/errors.test.d.ts +0 -1
  193. package/dist/errors.test.js +0 -607
  194. package/dist/expressServer.test.d.ts +0 -1
  195. package/dist/expressServer.test.js +0 -1249
  196. package/dist/githubAuth.test.d.ts +0 -1
  197. package/dist/githubAuth.test.js +0 -1142
  198. package/dist/httpClient.test.d.ts +0 -1
  199. package/dist/httpClient.test.js +0 -1471
  200. package/dist/logger.test.d.ts +0 -1
  201. package/dist/logger.test.js +0 -685
  202. package/dist/middleware.test.d.ts +0 -1
  203. package/dist/middleware.test.js +0 -241
  204. package/dist/notifiers/googleChatNotifier.test.d.ts +0 -1
  205. package/dist/notifiers/googleChatNotifier.test.js +0 -298
  206. package/dist/notifiers/slackNotifier.test.d.ts +0 -1
  207. package/dist/notifiers/slackNotifier.test.js +0 -297
  208. package/dist/notifiers/zoomNotifier.test.d.ts +0 -1
  209. package/dist/notifiers/zoomNotifier.test.js +0 -373
  210. package/dist/openApi.test.d.ts +0 -1
  211. package/dist/openApi.test.js +0 -620
  212. package/dist/openApiBuilder.test.d.ts +0 -1
  213. package/dist/openApiBuilder.test.js +0 -599
  214. package/dist/openApiEtag.test.d.ts +0 -1
  215. package/dist/openApiEtag.test.js +0 -86
  216. package/dist/openApiValidator.test.d.ts +0 -1
  217. package/dist/openApiValidator.test.js +0 -795
  218. package/dist/permissions.middleware.test.d.ts +0 -1
  219. package/dist/permissions.middleware.test.js +0 -308
  220. package/dist/permissions.test.d.ts +0 -1
  221. package/dist/permissions.test.js +0 -439
  222. package/dist/plugins.test.d.ts +0 -1
  223. package/dist/plugins.test.js +0 -902
  224. package/dist/populate.test.d.ts +0 -1
  225. package/dist/populate.test.js +0 -370
  226. package/dist/realtime/realtime.test.d.ts +0 -10
  227. package/dist/realtime/realtime.test.js +0 -4213
  228. package/dist/realtime/realtimeAppSetup.test.d.ts +0 -1
  229. package/dist/realtime/realtimeAppSetup.test.js +0 -213
  230. package/dist/requestContext.test.d.ts +0 -1
  231. package/dist/requestContext.test.js +0 -412
  232. package/dist/scriptRunner.test.d.ts +0 -1
  233. package/dist/scriptRunner.test.js +0 -386
  234. package/dist/secretProviders.test.d.ts +0 -1
  235. package/dist/secretProviders.test.js +0 -726
  236. package/dist/syncConsents.test.d.ts +0 -1
  237. package/dist/syncConsents.test.js +0 -522
  238. package/dist/terrenoApp.test.d.ts +0 -1
  239. package/dist/terrenoApp.test.js +0 -489
  240. package/dist/tests/bunSetup.d.ts +0 -1
  241. package/dist/tests/fixtures/compileAuthEntry.d.ts +0 -1
  242. package/dist/tests/fixtures/compileAuthEntry.js +0 -37
  243. package/dist/tests/testEnv.d.ts +0 -0
  244. package/dist/tests/testEnv.js +0 -6
  245. package/dist/transformers.test.d.ts +0 -1
  246. package/dist/transformers.test.js +0 -423
  247. package/dist/utils.test.d.ts +0 -1
  248. package/dist/utils.test.js +0 -242
  249. package/src/realtime/realtimeAppSetup.test.ts +0 -161
  250. /package/dist/{__tests__/openApiCompat.test.d.ts → sync/loadHarness.d.ts} +0 -0
@@ -1 +0,0 @@
1
- export {};
@@ -1,241 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __generator = (this && this.__generator) || function (thisArg, body) {
45
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
46
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
47
- function verb(n) { return function (v) { return step([n, v]); }; }
48
- function step(op) {
49
- if (f) throw new TypeError("Generator is already executing.");
50
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
51
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
52
- if (y = 0, t) op = [op[0] & 2, t.value];
53
- switch (op[0]) {
54
- case 0: case 1: t = op; break;
55
- case 4: _.label++; return { value: op[1], done: false };
56
- case 5: _.label++; y = op[1]; op = [0]; continue;
57
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
58
- default:
59
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
60
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
61
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
62
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
63
- if (t[2]) _.ops.pop();
64
- _.trys.pop(); continue;
65
- }
66
- op = body.call(thisArg, _);
67
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
68
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
69
- }
70
- };
71
- var __importDefault = (this && this.__importDefault) || function (mod) {
72
- return (mod && mod.__esModule) ? mod : { "default": mod };
73
- };
74
- Object.defineProperty(exports, "__esModule", { value: true });
75
- var bun_test_1 = require("bun:test");
76
- var Sentry = __importStar(require("@sentry/bun"));
77
- var express_1 = __importDefault(require("express"));
78
- var supertest_1 = __importDefault(require("supertest"));
79
- var middleware_1 = require("./middleware");
80
- var requestContext_1 = require("./requestContext");
81
- var buildReq = function (headers) {
82
- return {
83
- get: function (name) { return headers[name]; },
84
- };
85
- };
86
- var buildNext = function () { return (0, bun_test_1.mock)(function () { }); };
87
- (0, bun_test_1.describe)("sentryAppVersionMiddleware", function () {
88
- var setTagMock;
89
- (0, bun_test_1.beforeEach)(function () {
90
- // bunSetup.ts mocks @sentry/bun so that getCurrentScope() returns a scope
91
- // with a Bun mock setTag. Clear that mock between tests so each assertion
92
- // sees only its own calls.
93
- setTagMock = Sentry.getCurrentScope().setTag;
94
- setTagMock.mockClear();
95
- });
96
- (0, bun_test_1.it)("sets the app_version tag when the App-Version header is present", function () {
97
- var next = buildNext();
98
- var req = buildReq({ "App-Version": "1.2.3" });
99
- (0, middleware_1.sentryAppVersionMiddleware)(req, {}, next);
100
- (0, bun_test_1.expect)(setTagMock).toHaveBeenCalledTimes(1);
101
- (0, bun_test_1.expect)(setTagMock.mock.calls[0]).toEqual(["app_version", "1.2.3"]);
102
- (0, bun_test_1.expect)(next).toHaveBeenCalledTimes(1);
103
- });
104
- (0, bun_test_1.it)("does not set a tag when the App-Version header is missing", function () {
105
- var next = buildNext();
106
- var req = buildReq({});
107
- (0, middleware_1.sentryAppVersionMiddleware)(req, {}, next);
108
- (0, bun_test_1.expect)(setTagMock).not.toHaveBeenCalled();
109
- (0, bun_test_1.expect)(next).toHaveBeenCalledTimes(1);
110
- });
111
- (0, bun_test_1.it)("does not set a tag when the App-Version header is an empty string", function () {
112
- var next = buildNext();
113
- var req = buildReq({ "App-Version": "" });
114
- (0, middleware_1.sentryAppVersionMiddleware)(req, {}, next);
115
- (0, bun_test_1.expect)(setTagMock).not.toHaveBeenCalled();
116
- (0, bun_test_1.expect)(next).toHaveBeenCalledTimes(1);
117
- });
118
- (0, bun_test_1.it)("calls next exactly once with no arguments when the header is present", function () {
119
- var next = buildNext();
120
- (0, middleware_1.sentryAppVersionMiddleware)(buildReq({ "App-Version": "9.9.9" }), {}, next);
121
- (0, bun_test_1.expect)(next).toHaveBeenCalledTimes(1);
122
- (0, bun_test_1.expect)(next.mock.calls[0]).toHaveLength(0);
123
- });
124
- });
125
- (0, bun_test_1.describe)("jsonResponseRequestIdMiddleware", function () {
126
- var buildStackedApp = function () {
127
- var app = (0, express_1.default)();
128
- app.use(requestContext_1.requestContextMiddleware);
129
- app.use(middleware_1.jsonResponseRequestIdMiddleware);
130
- app.get("/object", function (_req, res) {
131
- return res.json({ hello: "world" });
132
- });
133
- app.get("/array", function (_req, res) {
134
- return res.json([1, 2]);
135
- });
136
- app.get("/openapi.json", function (_req, res) {
137
- return res.json({ openapi: "3.0.0", paths: {} });
138
- });
139
- app.get("/openapi/components/schemas/Food.json", function (_req, res) {
140
- return res.json({ description: "A food", type: "object" });
141
- });
142
- app.get("/openapi/validate", function (_req, res) {
143
- return res.json({ document: { openapi: "3.0.0" }, valid: true });
144
- });
145
- return app;
146
- };
147
- (0, bun_test_1.it)("adds requestId to object JSON bodies and matches X-Request-ID header", function () { return __awaiter(void 0, void 0, void 0, function () {
148
- var app, res;
149
- return __generator(this, function (_a) {
150
- switch (_a.label) {
151
- case 0:
152
- app = buildStackedApp();
153
- return [4 /*yield*/, (0, supertest_1.default)(app).get("/object").expect(200)];
154
- case 1:
155
- res = _a.sent();
156
- (0, bun_test_1.expect)(res.body.hello).toBe("world");
157
- (0, bun_test_1.expect)(res.body.requestId).toBeDefined();
158
- (0, bun_test_1.expect)(res.body.requestId).toBe(res.headers["x-request-id"]);
159
- return [2 /*return*/];
160
- }
161
- });
162
- }); });
163
- (0, bun_test_1.it)("does not wrap JSON array bodies", function () { return __awaiter(void 0, void 0, void 0, function () {
164
- var app, res;
165
- return __generator(this, function (_a) {
166
- switch (_a.label) {
167
- case 0:
168
- app = buildStackedApp();
169
- return [4 /*yield*/, (0, supertest_1.default)(app).get("/array").expect(200)];
170
- case 1:
171
- res = _a.sent();
172
- (0, bun_test_1.expect)(res.body).toEqual([1, 2]);
173
- (0, bun_test_1.expect)(res.headers["x-request-id"]).toBeDefined();
174
- return [2 /*return*/];
175
- }
176
- });
177
- }); });
178
- (0, bun_test_1.it)("does not inject requestId into GET /openapi.json bodies", function () { return __awaiter(void 0, void 0, void 0, function () {
179
- var app, res;
180
- return __generator(this, function (_a) {
181
- switch (_a.label) {
182
- case 0:
183
- app = buildStackedApp();
184
- return [4 /*yield*/, (0, supertest_1.default)(app).get("/openapi.json").expect(200)];
185
- case 1:
186
- res = _a.sent();
187
- (0, bun_test_1.expect)(res.body).toEqual({ openapi: "3.0.0", paths: {} });
188
- (0, bun_test_1.expect)(res.body.requestId).toBeUndefined();
189
- return [2 /*return*/];
190
- }
191
- });
192
- }); });
193
- (0, bun_test_1.it)("does not inject requestId into GET /openapi/components/...json bodies", function () { return __awaiter(void 0, void 0, void 0, function () {
194
- var app, res;
195
- return __generator(this, function (_a) {
196
- switch (_a.label) {
197
- case 0:
198
- app = buildStackedApp();
199
- return [4 /*yield*/, (0, supertest_1.default)(app).get("/openapi/components/schemas/Food.json").expect(200)];
200
- case 1:
201
- res = _a.sent();
202
- (0, bun_test_1.expect)(res.body).toEqual({ description: "A food", type: "object" });
203
- (0, bun_test_1.expect)(res.body.requestId).toBeUndefined();
204
- return [2 /*return*/];
205
- }
206
- });
207
- }); });
208
- (0, bun_test_1.it)("does not inject requestId into GET /openapi/validate bodies", function () { return __awaiter(void 0, void 0, void 0, function () {
209
- var app, res;
210
- return __generator(this, function (_a) {
211
- switch (_a.label) {
212
- case 0:
213
- app = buildStackedApp();
214
- return [4 /*yield*/, (0, supertest_1.default)(app).get("/openapi/validate").expect(200)];
215
- case 1:
216
- res = _a.sent();
217
- (0, bun_test_1.expect)(res.body).toEqual({ document: { openapi: "3.0.0" }, valid: true });
218
- (0, bun_test_1.expect)(res.body.requestId).toBeUndefined();
219
- return [2 /*return*/];
220
- }
221
- });
222
- }); });
223
- (0, bun_test_1.it)("uses incoming X-Request-ID on wrapped object responses", function () { return __awaiter(void 0, void 0, void 0, function () {
224
- var app, res;
225
- return __generator(this, function (_a) {
226
- switch (_a.label) {
227
- case 0:
228
- app = buildStackedApp();
229
- return [4 /*yield*/, (0, supertest_1.default)(app)
230
- .get("/object")
231
- .set("X-Request-ID", "client-rid-99")
232
- .expect(200)];
233
- case 1:
234
- res = _a.sent();
235
- (0, bun_test_1.expect)(res.body.requestId).toBe("client-rid-99");
236
- (0, bun_test_1.expect)(res.headers["x-request-id"]).toBe("client-rid-99");
237
- return [2 /*return*/];
238
- }
239
- });
240
- }); });
241
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,298 +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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
47
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
48
- return new (P || (P = Promise))(function (resolve, reject) {
49
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
50
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
51
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
52
- step((generator = generator.apply(thisArg, _arguments || [])).next());
53
- });
54
- };
55
- var __generator = (this && this.__generator) || function (thisArg, body) {
56
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
57
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
58
- function verb(n) { return function (v) { return step([n, v]); }; }
59
- function step(op) {
60
- if (f) throw new TypeError("Generator is already executing.");
61
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
62
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
63
- if (y = 0, t) op = [op[0] & 2, t.value];
64
- switch (op[0]) {
65
- case 0: case 1: t = op; break;
66
- case 4: _.label++; return { value: op[1], done: false };
67
- case 5: _.label++; y = op[1]; op = [0]; continue;
68
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
69
- default:
70
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
71
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
72
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
73
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
74
- if (t[2]) _.ops.pop();
75
- _.trys.pop(); continue;
76
- }
77
- op = body.call(thisArg, _);
78
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
79
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
80
- }
81
- };
82
- var __read = (this && this.__read) || function (o, n) {
83
- var m = typeof Symbol === "function" && o[Symbol.iterator];
84
- if (!m) return o;
85
- var i = m.call(o), r, ar = [], e;
86
- try {
87
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
88
- }
89
- catch (error) { e = { error: error }; }
90
- finally {
91
- try {
92
- if (r && !r.done && (m = i["return"])) m.call(i);
93
- }
94
- finally { if (e) throw e.error; }
95
- }
96
- return ar;
97
- };
98
- var __importDefault = (this && this.__importDefault) || function (mod) {
99
- return (mod && mod.__esModule) ? mod : { "default": mod };
100
- };
101
- Object.defineProperty(exports, "__esModule", { value: true });
102
- var bun_test_1 = require("bun:test");
103
- var Sentry = __importStar(require("@sentry/bun"));
104
- var axios_1 = __importDefault(require("axios"));
105
- var errors_1 = require("../errors");
106
- var googleChatNotifier_1 = require("./googleChatNotifier");
107
- (0, bun_test_1.describe)("sendToGoogleChat", function () {
108
- var mockAxiosPost;
109
- var ORIGINAL_ENV = process.env;
110
- (0, bun_test_1.beforeEach)(function () {
111
- mockAxiosPost = (0, bun_test_1.spyOn)(axios_1.default, "post").mockResolvedValue({ status: 200 });
112
- process.env = __assign({}, ORIGINAL_ENV);
113
- process.env.GOOGLE_CHAT_WEBHOOKS = undefined;
114
- Sentry.captureException.mockClear();
115
- Sentry.captureMessage.mockClear();
116
- });
117
- (0, bun_test_1.afterEach)(function () {
118
- mockAxiosPost.mockRestore();
119
- });
120
- (0, bun_test_1.afterAll)(function () {
121
- process.env = ORIGINAL_ENV;
122
- });
123
- (0, bun_test_1.it)("returns early when GOOGLE_CHAT_WEBHOOKS is missing", function () { return __awaiter(void 0, void 0, void 0, function () {
124
- return __generator(this, function (_a) {
125
- switch (_a.label) {
126
- case 0: return [4 /*yield*/, (0, googleChatNotifier_1.sendToGoogleChat)("hello")];
127
- case 1:
128
- _a.sent();
129
- (0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(0);
130
- return [2 /*return*/];
131
- }
132
- });
133
- }); });
134
- (0, bun_test_1.it)("posts to default webhook with plain text", function () { return __awaiter(void 0, void 0, void 0, function () {
135
- var callArgs, _a, url, payload;
136
- return __generator(this, function (_b) {
137
- switch (_b.label) {
138
- case 0:
139
- process.env.GOOGLE_CHAT_WEBHOOKS = JSON.stringify({
140
- default: "https://chat.example/webhook",
141
- });
142
- mockAxiosPost.mockResolvedValue({ status: 200 });
143
- return [4 /*yield*/, (0, googleChatNotifier_1.sendToGoogleChat)("hello world")];
144
- case 1:
145
- _b.sent();
146
- callArgs = mockAxiosPost.mock.calls[0];
147
- (0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
148
- _a = __read(callArgs, 2), url = _a[0], payload = _a[1];
149
- (0, bun_test_1.expect)(url).toBe("https://chat.example/webhook");
150
- (0, bun_test_1.expect)(payload).toEqual({ text: "hello world" });
151
- return [2 /*return*/];
152
- }
153
- });
154
- }); });
155
- (0, bun_test_1.it)("posts to a specific channel when provided", function () { return __awaiter(void 0, void 0, void 0, function () {
156
- var callArgs, _a, url, payload;
157
- return __generator(this, function (_b) {
158
- switch (_b.label) {
159
- case 0:
160
- process.env.GOOGLE_CHAT_WEBHOOKS = JSON.stringify({
161
- default: "https://chat.example/default",
162
- ops: "https://chat.example/ops",
163
- });
164
- mockAxiosPost.mockResolvedValue({ status: 200 });
165
- return [4 /*yield*/, (0, googleChatNotifier_1.sendToGoogleChat)("ops msg", { channel: "ops" })];
166
- case 1:
167
- _b.sent();
168
- callArgs = mockAxiosPost.mock.calls[0];
169
- (0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
170
- _a = __read(callArgs, 2), url = _a[0], payload = _a[1];
171
- (0, bun_test_1.expect)(url).toBe("https://chat.example/ops");
172
- (0, bun_test_1.expect)(payload).toEqual({ text: "ops msg" });
173
- return [2 /*return*/];
174
- }
175
- });
176
- }); });
177
- (0, bun_test_1.it)("falls back to default when channel not found", function () { return __awaiter(void 0, void 0, void 0, function () {
178
- var callArgs, _a, url, payload;
179
- return __generator(this, function (_b) {
180
- switch (_b.label) {
181
- case 0:
182
- process.env.GOOGLE_CHAT_WEBHOOKS = JSON.stringify({
183
- default: "https://chat.example/default",
184
- });
185
- mockAxiosPost.mockResolvedValue({ status: 200 });
186
- return [4 /*yield*/, (0, googleChatNotifier_1.sendToGoogleChat)("missing channel", { channel: "unknown" })];
187
- case 1:
188
- _b.sent();
189
- callArgs = mockAxiosPost.mock.calls[0];
190
- (0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
191
- _a = __read(callArgs, 2), url = _a[0], payload = _a[1];
192
- (0, bun_test_1.expect)(url).toBe("https://chat.example/default");
193
- (0, bun_test_1.expect)(payload).toEqual({ text: "missing channel" });
194
- return [2 /*return*/];
195
- }
196
- });
197
- }); });
198
- (0, bun_test_1.it)("prefixes message with [ENV] when env provided", function () { return __awaiter(void 0, void 0, void 0, function () {
199
- var callArgs, _a, payload;
200
- return __generator(this, function (_b) {
201
- switch (_b.label) {
202
- case 0:
203
- process.env.GOOGLE_CHAT_WEBHOOKS = JSON.stringify({
204
- default: "https://chat.example/default",
205
- });
206
- mockAxiosPost.mockResolvedValue({ status: 200 });
207
- return [4 /*yield*/, (0, googleChatNotifier_1.sendToGoogleChat)("status ok", { env: "prod" })];
208
- case 1:
209
- _b.sent();
210
- callArgs = mockAxiosPost.mock.calls[0];
211
- (0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
212
- _a = __read(callArgs, 2), payload = _a[1];
213
- (0, bun_test_1.expect)(payload).toEqual({ text: "[PROD] status ok" });
214
- return [2 /*return*/];
215
- }
216
- });
217
- }); });
218
- (0, bun_test_1.it)("captures error and throws APIError when shouldThrow=true", function () { return __awaiter(void 0, void 0, void 0, function () {
219
- var error_1;
220
- return __generator(this, function (_a) {
221
- switch (_a.label) {
222
- case 0:
223
- process.env.GOOGLE_CHAT_WEBHOOKS = JSON.stringify({
224
- default: "https://chat.example/default",
225
- });
226
- mockAxiosPost.mockRejectedValue(new Error("chat down"));
227
- _a.label = 1;
228
- case 1:
229
- _a.trys.push([1, 3, , 4]);
230
- return [4 /*yield*/, (0, googleChatNotifier_1.sendToGoogleChat)("err", { shouldThrow: true })];
231
- case 2:
232
- _a.sent();
233
- throw new Error("Expected sendToGoogleChat to throw APIError");
234
- case 3:
235
- error_1 = _a.sent();
236
- (0, bun_test_1.expect)((0, errors_1.isAPIError)(error_1)).toBe(true);
237
- (0, bun_test_1.expect)(error_1.title).toMatch(/Error posting to Google Chat/i);
238
- return [3 /*break*/, 4];
239
- case 4:
240
- (0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(1);
241
- return [2 /*return*/];
242
- }
243
- });
244
- }); });
245
- (0, bun_test_1.it)("captures error and does not throw when shouldThrow=false", function () { return __awaiter(void 0, void 0, void 0, function () {
246
- return __generator(this, function (_a) {
247
- switch (_a.label) {
248
- case 0:
249
- process.env.GOOGLE_CHAT_WEBHOOKS = JSON.stringify({
250
- default: "https://chat.example/default",
251
- });
252
- mockAxiosPost.mockRejectedValue(new Error("chat intermittent"));
253
- return [4 /*yield*/, (0, googleChatNotifier_1.sendToGoogleChat)("err", { shouldThrow: false })];
254
- case 1:
255
- _a.sent();
256
- (0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(1);
257
- return [2 /*return*/];
258
- }
259
- });
260
- }); });
261
- (0, bun_test_1.it)("returns early when webhook url is missing for channel and no default exists", function () { return __awaiter(void 0, void 0, void 0, function () {
262
- return __generator(this, function (_a) {
263
- switch (_a.label) {
264
- case 0:
265
- process.env.GOOGLE_CHAT_WEBHOOKS = JSON.stringify({
266
- ops: "https://chat.example/ops",
267
- });
268
- return [4 /*yield*/, (0, googleChatNotifier_1.sendToGoogleChat)("no default", { channel: "missing" })];
269
- case 1:
270
- _a.sent();
271
- (0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(0);
272
- (0, bun_test_1.expect)(Sentry.captureException).toHaveBeenCalled();
273
- return [2 /*return*/];
274
- }
275
- });
276
- }); });
277
- (0, bun_test_1.it)("prefixes message with [ENV] and posts when channel matches", function () { return __awaiter(void 0, void 0, void 0, function () {
278
- var callArgs, _a, url, payload;
279
- return __generator(this, function (_b) {
280
- switch (_b.label) {
281
- case 0:
282
- process.env.GOOGLE_CHAT_WEBHOOKS = JSON.stringify({
283
- default: "https://chat.example/default",
284
- ops: "https://chat.example/ops",
285
- });
286
- mockAxiosPost.mockResolvedValue({ status: 200 });
287
- return [4 /*yield*/, (0, googleChatNotifier_1.sendToGoogleChat)("deploy complete", { channel: "ops", env: "staging" })];
288
- case 1:
289
- _b.sent();
290
- callArgs = mockAxiosPost.mock.calls[0];
291
- _a = __read(callArgs, 2), url = _a[0], payload = _a[1];
292
- (0, bun_test_1.expect)(url).toBe("https://chat.example/ops");
293
- (0, bun_test_1.expect)(payload).toEqual({ text: "[STAGING] deploy complete" });
294
- return [2 /*return*/];
295
- }
296
- });
297
- }); });
298
- });
@@ -1 +0,0 @@
1
- export {};