@terreno/api 0.30.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 (226) 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 +100 -1
  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 +35 -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 +73 -21
  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 +40 -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 +903 -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/actions.openApi.test.ts +7 -10
  66. package/src/api.test.ts +12 -0
  67. package/src/api.ts +87 -295
  68. package/src/auth.test.ts +128 -176
  69. package/src/auth.ts +109 -0
  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/docLoader.ts +3 -1
  74. package/src/errors.ts +33 -0
  75. package/src/expressServer.test.ts +7 -1
  76. package/src/index.ts +42 -0
  77. package/src/middleware.test.ts +40 -1
  78. package/src/middleware.ts +15 -0
  79. package/src/openApiCompat.ts +99 -45
  80. package/src/permissions.test.ts +75 -1
  81. package/src/permissions.ts +49 -0
  82. package/src/plugins.test.ts +54 -0
  83. package/src/plugins.ts +43 -0
  84. package/src/realtime/changeStreamWatcher.ts +552 -114
  85. package/src/realtime/realtime.test.ts +157 -0
  86. package/src/realtime/realtimeApp.ts +75 -11
  87. package/src/realtime/sessionRevalidation.test.ts +423 -0
  88. package/src/realtime/sessionRevalidation.ts +273 -0
  89. package/src/realtime/socketAuth.test.ts +355 -0
  90. package/src/realtime/socketAuth.ts +228 -0
  91. package/src/realtime/socketUser.ts +69 -0
  92. package/src/realtime/types.ts +40 -0
  93. package/src/secretProviders.test.ts +7 -1
  94. package/src/secretProviders.ts +15 -3
  95. package/src/sync/ensureSyncIndexes.test.ts +144 -0
  96. package/src/sync/executors.test.ts +882 -0
  97. package/src/sync/executors.ts +703 -0
  98. package/src/sync/integration.test.ts +1160 -0
  99. package/src/sync/loadHarness.ts +618 -0
  100. package/src/sync/models.ts +640 -0
  101. package/src/sync/mutationHandler.test.ts +1252 -0
  102. package/src/sync/mutationHandler.ts +850 -0
  103. package/src/sync/registry.ts +232 -0
  104. package/src/sync/routes.ts +812 -0
  105. package/src/sync/scripts/compactTombstones.test.ts +249 -0
  106. package/src/sync/scripts/compactTombstones.ts +145 -0
  107. package/src/sync/serialize.ts +48 -0
  108. package/src/sync/sessionRevalidationIntegration.test.ts +281 -0
  109. package/src/sync/socketHandlers.ts +320 -0
  110. package/src/sync/streams.ts +188 -0
  111. package/src/sync/sync.test.ts +582 -0
  112. package/src/sync/syncApp.ts +44 -0
  113. package/src/sync/syncBatch.ts +219 -0
  114. package/src/sync/syncFrontier.test.ts +494 -0
  115. package/src/sync/syncPhaseC.test.ts +718 -0
  116. package/src/sync/syncRoutes.test.ts +865 -0
  117. package/src/sync/syncSeqPlugin.ts +738 -0
  118. package/src/sync/syncSocket.test.ts +1440 -0
  119. package/src/sync/types.ts +270 -0
  120. package/src/terrenoApp.ts +37 -17
  121. package/src/tests/bunSetup.ts +8 -0
  122. package/tsconfig.json +4 -4
  123. package/tsconfig.typedoc.json +7 -1
  124. package/dist/__tests__/openApiCompat.test.js +0 -317
  125. package/dist/__tests__/versionCheckPlugin.test.d.ts +0 -1
  126. package/dist/__tests__/versionCheckPlugin.test.js +0 -597
  127. package/dist/actions.openApi.test.d.ts +0 -1
  128. package/dist/actions.openApi.test.js +0 -255
  129. package/dist/actions.test.d.ts +0 -1
  130. package/dist/actions.test.js +0 -1089
  131. package/dist/api.arrayOperations.test.d.ts +0 -1
  132. package/dist/api.arrayOperations.test.js +0 -878
  133. package/dist/api.asyncHandler.test.d.ts +0 -1
  134. package/dist/api.asyncHandler.test.js +0 -236
  135. package/dist/api.coverage.test.d.ts +0 -1
  136. package/dist/api.coverage.test.js +0 -194
  137. package/dist/api.errorPaths.test.d.ts +0 -1
  138. package/dist/api.errorPaths.test.js +0 -801
  139. package/dist/api.errors.test.d.ts +0 -1
  140. package/dist/api.errors.test.js +0 -185
  141. package/dist/api.hooks.test.d.ts +0 -1
  142. package/dist/api.hooks.test.js +0 -950
  143. package/dist/api.query.test.d.ts +0 -1
  144. package/dist/api.query.test.js +0 -948
  145. package/dist/api.test.d.ts +0 -1
  146. package/dist/api.test.js +0 -2820
  147. package/dist/auth.compile.test.d.ts +0 -1
  148. package/dist/auth.compile.test.js +0 -201
  149. package/dist/auth.coverage.test.d.ts +0 -1
  150. package/dist/auth.coverage.test.js +0 -202
  151. package/dist/auth.test.d.ts +0 -1
  152. package/dist/auth.test.js +0 -2286
  153. package/dist/betterAuth.test.d.ts +0 -1
  154. package/dist/betterAuth.test.js +0 -181
  155. package/dist/betterAuthApp.test.d.ts +0 -1
  156. package/dist/betterAuthApp.test.js +0 -242
  157. package/dist/betterAuthSetup.test.d.ts +0 -1
  158. package/dist/betterAuthSetup.test.js +0 -762
  159. package/dist/config.test.d.ts +0 -1
  160. package/dist/config.test.js +0 -353
  161. package/dist/configuration.test.d.ts +0 -1
  162. package/dist/configuration.test.js +0 -980
  163. package/dist/configurationPlugin.test.d.ts +0 -1
  164. package/dist/configurationPlugin.test.js +0 -827
  165. package/dist/consentApp.test.d.ts +0 -1
  166. package/dist/consentApp.test.js +0 -1415
  167. package/dist/docLoader.test.d.ts +0 -1
  168. package/dist/docLoader.test.js +0 -137
  169. package/dist/envConfigurationPlugin.test.d.ts +0 -1
  170. package/dist/envConfigurationPlugin.test.js +0 -369
  171. package/dist/errors.test.d.ts +0 -1
  172. package/dist/errors.test.js +0 -607
  173. package/dist/expressServer.test.d.ts +0 -1
  174. package/dist/expressServer.test.js +0 -1249
  175. package/dist/githubAuth.test.d.ts +0 -1
  176. package/dist/githubAuth.test.js +0 -1142
  177. package/dist/httpClient.test.d.ts +0 -1
  178. package/dist/httpClient.test.js +0 -1471
  179. package/dist/logger.test.d.ts +0 -1
  180. package/dist/logger.test.js +0 -685
  181. package/dist/middleware.test.d.ts +0 -1
  182. package/dist/middleware.test.js +0 -241
  183. package/dist/notifiers/googleChatNotifier.test.d.ts +0 -1
  184. package/dist/notifiers/googleChatNotifier.test.js +0 -298
  185. package/dist/notifiers/slackNotifier.test.d.ts +0 -1
  186. package/dist/notifiers/slackNotifier.test.js +0 -297
  187. package/dist/notifiers/zoomNotifier.test.d.ts +0 -1
  188. package/dist/notifiers/zoomNotifier.test.js +0 -373
  189. package/dist/openApi.test.d.ts +0 -1
  190. package/dist/openApi.test.js +0 -620
  191. package/dist/openApiBuilder.test.d.ts +0 -1
  192. package/dist/openApiBuilder.test.js +0 -601
  193. package/dist/openApiEtag.test.d.ts +0 -1
  194. package/dist/openApiEtag.test.js +0 -86
  195. package/dist/openApiValidator.test.d.ts +0 -1
  196. package/dist/openApiValidator.test.js +0 -761
  197. package/dist/permissions.middleware.test.d.ts +0 -1
  198. package/dist/permissions.middleware.test.js +0 -308
  199. package/dist/permissions.test.d.ts +0 -1
  200. package/dist/permissions.test.js +0 -439
  201. package/dist/plugins.test.d.ts +0 -1
  202. package/dist/plugins.test.js +0 -890
  203. package/dist/populate.test.d.ts +0 -1
  204. package/dist/populate.test.js +0 -373
  205. package/dist/realtime/realtime.test.d.ts +0 -10
  206. package/dist/realtime/realtime.test.js +0 -3982
  207. package/dist/requestContext.test.d.ts +0 -1
  208. package/dist/requestContext.test.js +0 -412
  209. package/dist/scriptRunner.test.d.ts +0 -1
  210. package/dist/scriptRunner.test.js +0 -386
  211. package/dist/secretProviders.test.d.ts +0 -1
  212. package/dist/secretProviders.test.js +0 -726
  213. package/dist/syncConsents.test.d.ts +0 -1
  214. package/dist/syncConsents.test.js +0 -522
  215. package/dist/terrenoApp.test.d.ts +0 -1
  216. package/dist/terrenoApp.test.js +0 -489
  217. package/dist/tests/bunSetup.d.ts +0 -1
  218. package/dist/tests/fixtures/compileAuthEntry.d.ts +0 -1
  219. package/dist/tests/fixtures/compileAuthEntry.js +0 -37
  220. package/dist/tests/testEnv.d.ts +0 -0
  221. package/dist/tests/testEnv.js +0 -6
  222. package/dist/transformers.test.d.ts +0 -1
  223. package/dist/transformers.test.js +0 -423
  224. package/dist/utils.test.d.ts +0 -1
  225. package/dist/utils.test.js +0 -242
  226. /package/dist/{__tests__/openApiCompat.test.d.ts → sync/loadHarness.d.ts} +0 -0
@@ -1,297 +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 slackNotifier_1 = require("./slackNotifier");
107
- (0, bun_test_1.describe)("sendToSlack", 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.SLACK_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 SLACK_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, slackNotifier_1.sendToSlack)("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.SLACK_WEBHOOKS = JSON.stringify({ default: "https://slack.example/webhook" });
140
- mockAxiosPost.mockResolvedValue({ status: 200 });
141
- return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)("hello world")];
142
- case 1:
143
- _b.sent();
144
- (0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(1);
145
- callArgs = mockAxiosPost.mock.calls[0];
146
- (0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
147
- _a = __read(callArgs, 2), url = _a[0], payload = _a[1];
148
- (0, bun_test_1.expect)(url).toBe("https://slack.example/webhook");
149
- (0, bun_test_1.expect)(payload).toEqual({ text: "hello world" });
150
- return [2 /*return*/];
151
- }
152
- });
153
- }); });
154
- (0, bun_test_1.it)("posts to a specific channel when provided", function () { return __awaiter(void 0, void 0, void 0, function () {
155
- var callArgs, _a, url, payload;
156
- return __generator(this, function (_b) {
157
- switch (_b.label) {
158
- case 0:
159
- process.env.SLACK_WEBHOOKS = JSON.stringify({
160
- default: "https://slack.example/default",
161
- ops: "https://slack.example/ops",
162
- });
163
- mockAxiosPost.mockResolvedValue({ status: 200 });
164
- return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)("ops msg", { slackChannel: "ops" })];
165
- case 1:
166
- _b.sent();
167
- callArgs = mockAxiosPost.mock.calls[0];
168
- (0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
169
- _a = __read(callArgs, 2), url = _a[0], payload = _a[1];
170
- (0, bun_test_1.expect)(url).toBe("https://slack.example/ops");
171
- (0, bun_test_1.expect)(payload).toEqual({ text: "ops msg" });
172
- return [2 /*return*/];
173
- }
174
- });
175
- }); });
176
- (0, bun_test_1.it)("falls back to default when channel not found", function () { return __awaiter(void 0, void 0, void 0, function () {
177
- var callArgs, _a, url, payload;
178
- return __generator(this, function (_b) {
179
- switch (_b.label) {
180
- case 0:
181
- process.env.SLACK_WEBHOOKS = JSON.stringify({
182
- default: "https://slack.example/default",
183
- });
184
- mockAxiosPost.mockResolvedValue({ status: 200 });
185
- return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)("missing channel", { slackChannel: "unknown" })];
186
- case 1:
187
- _b.sent();
188
- callArgs = mockAxiosPost.mock.calls[0];
189
- (0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
190
- _a = __read(callArgs, 2), url = _a[0], payload = _a[1];
191
- (0, bun_test_1.expect)(url).toBe("https://slack.example/default");
192
- (0, bun_test_1.expect)(payload).toEqual({ text: "missing channel" });
193
- return [2 /*return*/];
194
- }
195
- });
196
- }); });
197
- (0, bun_test_1.it)("prefixes message with [ENV] when env provided", function () { return __awaiter(void 0, void 0, void 0, function () {
198
- var callArgs, _a, payload;
199
- return __generator(this, function (_b) {
200
- switch (_b.label) {
201
- case 0:
202
- process.env.SLACK_WEBHOOKS = JSON.stringify({
203
- default: "https://slack.example/default",
204
- });
205
- mockAxiosPost.mockResolvedValue({ status: 200 });
206
- return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)("status ok", { env: "stg" })];
207
- case 1:
208
- _b.sent();
209
- callArgs = mockAxiosPost.mock.calls[0];
210
- (0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
211
- _a = __read(callArgs, 2), payload = _a[1];
212
- (0, bun_test_1.expect)(payload).toEqual({ text: "[STG] status ok" });
213
- return [2 /*return*/];
214
- }
215
- });
216
- }); });
217
- (0, bun_test_1.it)("reports to Sentry and returns early when channel has no webhook and no default", function () { return __awaiter(void 0, void 0, void 0, function () {
218
- var captured;
219
- return __generator(this, function (_a) {
220
- switch (_a.label) {
221
- case 0:
222
- process.env.SLACK_WEBHOOKS = JSON.stringify({ ops: "https://slack.example/ops" });
223
- return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)("orphan message", { slackChannel: "alerts" })];
224
- case 1:
225
- _a.sent();
226
- (0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(0);
227
- (0, bun_test_1.expect)(Sentry.captureException.mock.calls.length).toBe(1);
228
- captured = Sentry.captureException.mock
229
- .calls[0][0];
230
- (0, bun_test_1.expect)(captured).toBeInstanceOf(errors_1.APIError);
231
- (0, bun_test_1.expect)(captured.title).toContain("alerts");
232
- return [2 /*return*/];
233
- }
234
- });
235
- }); });
236
- (0, bun_test_1.it)("posts directly using the url parameter without env lookup", function () { return __awaiter(void 0, void 0, void 0, function () {
237
- var _a, url, payload;
238
- return __generator(this, function (_b) {
239
- switch (_b.label) {
240
- case 0:
241
- mockAxiosPost.mockResolvedValue({ status: 200 });
242
- return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)("direct msg", { url: "https://direct.example/hook" })];
243
- case 1:
244
- _b.sent();
245
- (0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(1);
246
- _a = __read(mockAxiosPost.mock.calls[0], 2), url = _a[0], payload = _a[1];
247
- (0, bun_test_1.expect)(url).toBe("https://direct.example/hook");
248
- (0, bun_test_1.expect)(payload).toEqual({ text: "direct msg" });
249
- return [2 /*return*/];
250
- }
251
- });
252
- }); });
253
- (0, bun_test_1.it)("captures error and throws APIError when shouldThrow=true", function () { return __awaiter(void 0, void 0, void 0, function () {
254
- var error_1, apiError;
255
- return __generator(this, function (_a) {
256
- switch (_a.label) {
257
- case 0:
258
- process.env.SLACK_WEBHOOKS = JSON.stringify({
259
- default: "https://slack.example/default",
260
- });
261
- mockAxiosPost.mockRejectedValue(new Error("slack down"));
262
- _a.label = 1;
263
- case 1:
264
- _a.trys.push([1, 3, , 4]);
265
- return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)("err", { shouldThrow: true })];
266
- case 2:
267
- _a.sent();
268
- throw new Error("Expected sendToSlack to throw APIError");
269
- case 3:
270
- error_1 = _a.sent();
271
- apiError = error_1;
272
- (0, bun_test_1.expect)((0, errors_1.isAPIError)(apiError)).toBe(true);
273
- (0, bun_test_1.expect)(apiError.title).toMatch(/Error posting to slack/i);
274
- return [3 /*break*/, 4];
275
- case 4:
276
- (0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(1);
277
- return [2 /*return*/];
278
- }
279
- });
280
- }); });
281
- (0, bun_test_1.it)("captures error and does not throw when shouldThrow=false", function () { return __awaiter(void 0, void 0, void 0, function () {
282
- return __generator(this, function (_a) {
283
- switch (_a.label) {
284
- case 0:
285
- process.env.SLACK_WEBHOOKS = JSON.stringify({
286
- default: "https://slack.example/default",
287
- });
288
- mockAxiosPost.mockRejectedValue(new Error("slack intermittent"));
289
- return [4 /*yield*/, (0, slackNotifier_1.sendToSlack)("err", { shouldThrow: false })];
290
- case 1:
291
- _a.sent();
292
- (0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(1);
293
- return [2 /*return*/];
294
- }
295
- });
296
- }); });
297
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,373 +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 zoomNotifier_1 = require("./zoomNotifier");
107
- (0, bun_test_1.describe)("sendToZoom", 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({
112
- status: 200,
113
- });
114
- process.env = __assign({}, ORIGINAL_ENV);
115
- process.env.ZOOM_CHAT_WEBHOOKS = undefined;
116
- Sentry.captureException.mockClear();
117
- Sentry.captureMessage.mockClear();
118
- });
119
- (0, bun_test_1.afterEach)(function () {
120
- mockAxiosPost.mockRestore();
121
- });
122
- (0, bun_test_1.afterAll)(function () {
123
- process.env = ORIGINAL_ENV;
124
- });
125
- (0, bun_test_1.it)("returns early when ZOOM_CHAT_WEBHOOKS is missing", function () { return __awaiter(void 0, void 0, void 0, function () {
126
- return __generator(this, function (_a) {
127
- switch (_a.label) {
128
- case 0: return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "world", header: "hello" }, { channel: "default" })];
129
- case 1:
130
- _a.sent();
131
- (0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(0);
132
- return [2 /*return*/];
133
- }
134
- });
135
- }); });
136
- (0, bun_test_1.it)("posts to default webhook with rich message format and authorization header", function () { return __awaiter(void 0, void 0, void 0, function () {
137
- var callArgs, _a, url, payload, options;
138
- return __generator(this, function (_b) {
139
- switch (_b.label) {
140
- case 0:
141
- process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
142
- default: {
143
- channel: "https://zoom.example/webhook",
144
- verificationToken: "test-token-123",
145
- },
146
- });
147
- mockAxiosPost.mockResolvedValue({ status: 200 });
148
- return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "world", header: "hello" }, { channel: "default" })];
149
- case 1:
150
- _b.sent();
151
- (0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(1);
152
- callArgs = mockAxiosPost.mock.calls[0];
153
- (0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
154
- _a = __read(callArgs, 3), url = _a[0], payload = _a[1], options = _a[2];
155
- (0, bun_test_1.expect)(url).toBe("https://zoom.example/webhook?format=full");
156
- (0, bun_test_1.expect)(payload).toEqual({
157
- content: {
158
- body: [{ text: "world", type: "message" }],
159
- head: { text: "hello" },
160
- },
161
- });
162
- (0, bun_test_1.expect)(options === null || options === void 0 ? void 0 : options.headers).toEqual({
163
- Authorization: "test-token-123",
164
- "Content-Type": "application/json",
165
- });
166
- return [2 /*return*/];
167
- }
168
- });
169
- }); });
170
- (0, bun_test_1.it)("posts to a specific channel when provided", function () { return __awaiter(void 0, void 0, void 0, function () {
171
- var callArgs, _a, url, payload, options;
172
- var _b;
173
- return __generator(this, function (_c) {
174
- switch (_c.label) {
175
- case 0:
176
- process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
177
- default: {
178
- channel: "https://zoom.example/default",
179
- verificationToken: "default-token",
180
- },
181
- ops: {
182
- channel: "https://zoom.example/ops",
183
- verificationToken: "ops-token",
184
- },
185
- });
186
- mockAxiosPost.mockResolvedValue({ status: 200 });
187
- return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "ops msg", header: "ops msg" }, { channel: "ops" })];
188
- case 1:
189
- _c.sent();
190
- callArgs = mockAxiosPost.mock.calls[0];
191
- (0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
192
- _a = __read(callArgs, 3), url = _a[0], payload = _a[1], options = _a[2];
193
- (0, bun_test_1.expect)(url).toBe("https://zoom.example/ops?format=full");
194
- (0, bun_test_1.expect)(payload).toEqual({
195
- content: {
196
- body: [{ text: "ops msg", type: "message" }],
197
- head: { text: "ops msg" },
198
- },
199
- });
200
- (0, bun_test_1.expect)((_b = options === null || options === void 0 ? void 0 : options.headers) === null || _b === void 0 ? void 0 : _b.Authorization).toBe("ops-token");
201
- return [2 /*return*/];
202
- }
203
- });
204
- }); });
205
- (0, bun_test_1.it)("falls back to default when channel not found", function () { return __awaiter(void 0, void 0, void 0, function () {
206
- var callArgs, _a, url, payload;
207
- return __generator(this, function (_b) {
208
- switch (_b.label) {
209
- case 0:
210
- process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
211
- default: {
212
- channel: "https://zoom.example/default",
213
- verificationToken: "default-token",
214
- },
215
- });
216
- mockAxiosPost.mockResolvedValue({ status: 200 });
217
- return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "missing channel", header: "missing channel" }, { channel: "unknown" })];
218
- case 1:
219
- _b.sent();
220
- callArgs = mockAxiosPost.mock.calls[0];
221
- (0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
222
- _a = __read(callArgs, 2), url = _a[0], payload = _a[1];
223
- (0, bun_test_1.expect)(url).toBe("https://zoom.example/default?format=full");
224
- (0, bun_test_1.expect)(payload).toEqual({
225
- content: {
226
- body: [{ text: "missing channel", type: "message" }],
227
- head: { text: "missing channel" },
228
- },
229
- });
230
- return [2 /*return*/];
231
- }
232
- });
233
- }); });
234
- (0, bun_test_1.it)("returns early when webhook url is missing for channel", function () { return __awaiter(void 0, void 0, void 0, function () {
235
- return __generator(this, function (_a) {
236
- switch (_a.label) {
237
- case 0:
238
- process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
239
- default: {
240
- verificationToken: "default-token",
241
- },
242
- });
243
- return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "no url", header: "no url" }, { channel: "default" })];
244
- case 1:
245
- _a.sent();
246
- (0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(0);
247
- return [2 /*return*/];
248
- }
249
- });
250
- }); });
251
- (0, bun_test_1.it)("returns early when verification token is missing for channel", function () { return __awaiter(void 0, void 0, void 0, function () {
252
- return __generator(this, function (_a) {
253
- switch (_a.label) {
254
- case 0:
255
- process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
256
- default: {
257
- channel: "https://zoom.example/default",
258
- },
259
- });
260
- return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "no token", header: "no token" }, { channel: "default" })];
261
- case 1:
262
- _a.sent();
263
- (0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(0);
264
- return [2 /*return*/];
265
- }
266
- });
267
- }); });
268
- (0, bun_test_1.it)("prefixes header with [ENV] when env provided", function () { return __awaiter(void 0, void 0, void 0, function () {
269
- var callArgs, _a, payload;
270
- return __generator(this, function (_b) {
271
- switch (_b.label) {
272
- case 0:
273
- process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
274
- default: {
275
- channel: "https://zoom.example/default",
276
- verificationToken: "token",
277
- },
278
- });
279
- mockAxiosPost.mockResolvedValue({ status: 200 });
280
- return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "status ok", header: "status ok" }, { channel: "default", env: "stg" })];
281
- case 1:
282
- _b.sent();
283
- callArgs = mockAxiosPost.mock.calls[0];
284
- (0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
285
- _a = __read(callArgs, 2), payload = _a[1];
286
- (0, bun_test_1.expect)(payload).toEqual({
287
- content: {
288
- body: [{ text: "status ok", type: "message" }],
289
- head: { text: "[STG] status ok" },
290
- },
291
- });
292
- return [2 /*return*/];
293
- }
294
- });
295
- }); });
296
- (0, bun_test_1.it)("includes subheader when provided", function () { return __awaiter(void 0, void 0, void 0, function () {
297
- var callArgs, _a, payload;
298
- return __generator(this, function (_b) {
299
- switch (_b.label) {
300
- case 0:
301
- process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
302
- default: {
303
- channel: "https://zoom.example/default",
304
- verificationToken: "token",
305
- },
306
- });
307
- mockAxiosPost.mockResolvedValue({ status: 200 });
308
- return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "Body text", header: "Main Header", subheader: "Subheader text" }, { channel: "default" })];
309
- case 1:
310
- _b.sent();
311
- callArgs = mockAxiosPost.mock.calls[0];
312
- (0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
313
- _a = __read(callArgs, 2), payload = _a[1];
314
- (0, bun_test_1.expect)(payload).toEqual({
315
- content: {
316
- body: [{ text: "Body text", type: "message" }],
317
- head: { sub_head: { text: "Subheader text" }, text: "Main Header" },
318
- },
319
- });
320
- return [2 /*return*/];
321
- }
322
- });
323
- }); });
324
- (0, bun_test_1.it)("captures error and throws APIError when shouldThrow=true", function () { return __awaiter(void 0, void 0, void 0, function () {
325
- var error_1;
326
- return __generator(this, function (_a) {
327
- switch (_a.label) {
328
- case 0:
329
- process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
330
- default: {
331
- channel: "https://zoom.example/default",
332
- verificationToken: "token",
333
- },
334
- });
335
- mockAxiosPost.mockRejectedValue(new Error("zoom down"));
336
- _a.label = 1;
337
- case 1:
338
- _a.trys.push([1, 3, , 4]);
339
- return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "err", header: "err" }, { channel: "default", shouldThrow: true })];
340
- case 2:
341
- _a.sent();
342
- throw new Error("Expected sendToZoom to throw APIError");
343
- case 3:
344
- error_1 = _a.sent();
345
- (0, bun_test_1.expect)((0, errors_1.isAPIError)(error_1)).toBe(true);
346
- (0, bun_test_1.expect)(error_1.title).toMatch(/Error posting to Zoom/i);
347
- return [3 /*break*/, 4];
348
- case 4:
349
- (0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(1);
350
- return [2 /*return*/];
351
- }
352
- });
353
- }); });
354
- (0, bun_test_1.it)("captures error and does not throw when shouldThrow=false", function () { return __awaiter(void 0, void 0, void 0, function () {
355
- return __generator(this, function (_a) {
356
- switch (_a.label) {
357
- case 0:
358
- process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
359
- default: {
360
- channel: "https://zoom.example/default",
361
- verificationToken: "token",
362
- },
363
- });
364
- mockAxiosPost.mockRejectedValue(new Error("zoom intermittent"));
365
- return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "err", header: "err" }, { channel: "default", shouldThrow: false })];
366
- case 1:
367
- _a.sent();
368
- (0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(1);
369
- return [2 /*return*/];
370
- }
371
- });
372
- }); });
373
- });
@@ -1 +0,0 @@
1
- export {};