@terreno/api 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +170 -0
- package/biome.jsonc +22 -0
- package/bunfig.toml +4 -0
- package/dist/api.d.ts +227 -0
- package/dist/api.js +1024 -0
- package/dist/api.test.d.ts +1 -0
- package/dist/api.test.js +2143 -0
- package/dist/auth.d.ts +50 -0
- package/dist/auth.js +512 -0
- package/dist/auth.test.d.ts +1 -0
- package/dist/auth.test.js +778 -0
- package/dist/errors.d.ts +75 -0
- package/dist/errors.js +216 -0
- package/dist/example.d.ts +1 -0
- package/dist/example.js +118 -0
- package/dist/expressServer.d.ts +35 -0
- package/dist/expressServer.js +436 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +30 -0
- package/dist/logger.d.ts +23 -0
- package/dist/logger.js +249 -0
- package/dist/middleware.d.ts +10 -0
- package/dist/middleware.js +52 -0
- package/dist/notifiers/googleChatNotifier.d.ts +5 -0
- package/dist/notifiers/googleChatNotifier.js +130 -0
- package/dist/notifiers/googleChatNotifier.test.d.ts +1 -0
- package/dist/notifiers/googleChatNotifier.test.js +260 -0
- package/dist/notifiers/index.d.ts +3 -0
- package/dist/notifiers/index.js +19 -0
- package/dist/notifiers/slackNotifier.d.ts +5 -0
- package/dist/notifiers/slackNotifier.js +130 -0
- package/dist/notifiers/slackNotifier.test.d.ts +1 -0
- package/dist/notifiers/slackNotifier.test.js +259 -0
- package/dist/notifiers/zoomNotifier.d.ts +34 -0
- package/dist/notifiers/zoomNotifier.js +181 -0
- package/dist/notifiers/zoomNotifier.test.d.ts +1 -0
- package/dist/notifiers/zoomNotifier.test.js +370 -0
- package/dist/openApi.d.ts +60 -0
- package/dist/openApi.js +441 -0
- package/dist/openApi.test.d.ts +1 -0
- package/dist/openApi.test.js +445 -0
- package/dist/openApiBuilder.d.ts +419 -0
- package/dist/openApiBuilder.js +424 -0
- package/dist/openApiBuilder.test.d.ts +1 -0
- package/dist/openApiBuilder.test.js +509 -0
- package/dist/openApiEtag.d.ts +7 -0
- package/dist/openApiEtag.js +38 -0
- package/dist/permissions.d.ts +26 -0
- package/dist/permissions.js +331 -0
- package/dist/permissions.test.d.ts +1 -0
- package/dist/permissions.test.js +413 -0
- package/dist/plugins.d.ts +67 -0
- package/dist/plugins.js +315 -0
- package/dist/plugins.test.d.ts +1 -0
- package/dist/plugins.test.js +639 -0
- package/dist/populate.d.ts +14 -0
- package/dist/populate.js +315 -0
- package/dist/populate.test.d.ts +1 -0
- package/dist/populate.test.js +133 -0
- package/dist/response.d.ts +0 -0
- package/dist/response.js +1 -0
- package/dist/tests/bunSetup.d.ts +1 -0
- package/dist/tests/bunSetup.js +297 -0
- package/dist/tests/index.d.ts +1 -0
- package/dist/tests/index.js +17 -0
- package/dist/tests.d.ts +99 -0
- package/dist/tests.js +273 -0
- package/dist/transformers.d.ts +25 -0
- package/dist/transformers.js +217 -0
- package/dist/transformers.test.d.ts +1 -0
- package/dist/transformers.test.js +370 -0
- package/dist/utils.d.ts +11 -0
- package/dist/utils.js +143 -0
- package/dist/utils.test.d.ts +1 -0
- package/dist/utils.test.js +14 -0
- package/index.ts +1 -0
- package/package.json +88 -0
- package/src/__snapshots__/openApi.test.ts.snap +4814 -0
- package/src/__snapshots__/openApiBuilder.test.ts.snap +1485 -0
- package/src/api.test.ts +1661 -0
- package/src/api.ts +1036 -0
- package/src/auth.test.ts +550 -0
- package/src/auth.ts +408 -0
- package/src/errors.ts +225 -0
- package/src/example.ts +99 -0
- package/src/express.d.ts +5 -0
- package/src/expressServer.ts +387 -0
- package/src/index.ts +14 -0
- package/src/logger.ts +190 -0
- package/src/middleware.ts +18 -0
- package/src/notifiers/googleChatNotifier.test.ts +114 -0
- package/src/notifiers/googleChatNotifier.ts +47 -0
- package/src/notifiers/index.ts +3 -0
- package/src/notifiers/slackNotifier.test.ts +113 -0
- package/src/notifiers/slackNotifier.ts +55 -0
- package/src/notifiers/zoomNotifier.test.ts +207 -0
- package/src/notifiers/zoomNotifier.ts +111 -0
- package/src/openApi.test.ts +331 -0
- package/src/openApi.ts +494 -0
- package/src/openApiBuilder.test.ts +442 -0
- package/src/openApiBuilder.ts +636 -0
- package/src/openApiEtag.ts +40 -0
- package/src/permissions.test.ts +219 -0
- package/src/permissions.ts +228 -0
- package/src/plugins.test.ts +390 -0
- package/src/plugins.ts +289 -0
- package/src/populate.test.ts +65 -0
- package/src/populate.ts +258 -0
- package/src/response.ts +0 -0
- package/src/tests/bunSetup.ts +234 -0
- package/src/tests/index.ts +1 -0
- package/src/tests.ts +218 -0
- package/src/transformers.test.ts +202 -0
- package/src/transformers.ts +170 -0
- package/src/utils.test.ts +14 -0
- package/src/utils.ts +47 -0
- package/tsconfig.json +60 -0
- package/types.d.ts +17 -0
|
@@ -0,0 +1,370 @@
|
|
|
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/node"));
|
|
104
|
+
var axios_1 = __importDefault(require("axios"));
|
|
105
|
+
var zoomNotifier_1 = require("./zoomNotifier");
|
|
106
|
+
(0, bun_test_1.describe)("sendToZoom", function () {
|
|
107
|
+
var mockAxiosPost;
|
|
108
|
+
var ORIGINAL_ENV = process.env;
|
|
109
|
+
(0, bun_test_1.beforeEach)(function () {
|
|
110
|
+
mockAxiosPost = (0, bun_test_1.spyOn)(axios_1.default, "post").mockResolvedValue({ status: 200 });
|
|
111
|
+
process.env = __assign({}, ORIGINAL_ENV);
|
|
112
|
+
process.env.ZOOM_CHAT_WEBHOOKS = undefined;
|
|
113
|
+
Sentry.captureException.mockClear();
|
|
114
|
+
Sentry.captureMessage.mockClear();
|
|
115
|
+
});
|
|
116
|
+
(0, bun_test_1.afterEach)(function () {
|
|
117
|
+
mockAxiosPost.mockRestore();
|
|
118
|
+
});
|
|
119
|
+
(0, bun_test_1.afterAll)(function () {
|
|
120
|
+
process.env = ORIGINAL_ENV;
|
|
121
|
+
});
|
|
122
|
+
(0, bun_test_1.it)("returns early when ZOOM_CHAT_WEBHOOKS is missing", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
123
|
+
return __generator(this, function (_a) {
|
|
124
|
+
switch (_a.label) {
|
|
125
|
+
case 0: return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "world", header: "hello" }, { channel: "default" })];
|
|
126
|
+
case 1:
|
|
127
|
+
_a.sent();
|
|
128
|
+
(0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(0);
|
|
129
|
+
return [2 /*return*/];
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}); });
|
|
133
|
+
(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 () {
|
|
134
|
+
var callArgs, _a, url, payload, options;
|
|
135
|
+
return __generator(this, function (_b) {
|
|
136
|
+
switch (_b.label) {
|
|
137
|
+
case 0:
|
|
138
|
+
process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
|
|
139
|
+
default: {
|
|
140
|
+
channel: "https://zoom.example/webhook",
|
|
141
|
+
verificationToken: "test-token-123",
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
mockAxiosPost.mockResolvedValue({ status: 200 });
|
|
145
|
+
return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "world", header: "hello" }, { channel: "default" })];
|
|
146
|
+
case 1:
|
|
147
|
+
_b.sent();
|
|
148
|
+
(0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(1);
|
|
149
|
+
callArgs = mockAxiosPost.mock.calls[0];
|
|
150
|
+
(0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
|
|
151
|
+
_a = __read(callArgs, 3), url = _a[0], payload = _a[1], options = _a[2];
|
|
152
|
+
(0, bun_test_1.expect)(url).toBe("https://zoom.example/webhook?format=full");
|
|
153
|
+
(0, bun_test_1.expect)(payload).toEqual({
|
|
154
|
+
content: {
|
|
155
|
+
body: [{ text: "world", type: "message" }],
|
|
156
|
+
head: { text: "hello" },
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
(0, bun_test_1.expect)(options === null || options === void 0 ? void 0 : options.headers).toEqual({
|
|
160
|
+
Authorization: "test-token-123",
|
|
161
|
+
"Content-Type": "application/json",
|
|
162
|
+
});
|
|
163
|
+
return [2 /*return*/];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}); });
|
|
167
|
+
(0, bun_test_1.it)("posts to a specific channel when provided", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
168
|
+
var callArgs, _a, url, payload, options;
|
|
169
|
+
var _b;
|
|
170
|
+
return __generator(this, function (_c) {
|
|
171
|
+
switch (_c.label) {
|
|
172
|
+
case 0:
|
|
173
|
+
process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
|
|
174
|
+
default: {
|
|
175
|
+
channel: "https://zoom.example/default",
|
|
176
|
+
verificationToken: "default-token",
|
|
177
|
+
},
|
|
178
|
+
ops: {
|
|
179
|
+
channel: "https://zoom.example/ops",
|
|
180
|
+
verificationToken: "ops-token",
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
mockAxiosPost.mockResolvedValue({ status: 200 });
|
|
184
|
+
return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "ops msg", header: "ops msg" }, { channel: "ops" })];
|
|
185
|
+
case 1:
|
|
186
|
+
_c.sent();
|
|
187
|
+
callArgs = mockAxiosPost.mock.calls[0];
|
|
188
|
+
(0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
|
|
189
|
+
_a = __read(callArgs, 3), url = _a[0], payload = _a[1], options = _a[2];
|
|
190
|
+
(0, bun_test_1.expect)(url).toBe("https://zoom.example/ops?format=full");
|
|
191
|
+
(0, bun_test_1.expect)(payload).toEqual({
|
|
192
|
+
content: {
|
|
193
|
+
body: [{ text: "ops msg", type: "message" }],
|
|
194
|
+
head: { text: "ops msg" },
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
(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");
|
|
198
|
+
return [2 /*return*/];
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}); });
|
|
202
|
+
(0, bun_test_1.it)("falls back to default when channel not found", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
203
|
+
var callArgs, _a, url, payload;
|
|
204
|
+
return __generator(this, function (_b) {
|
|
205
|
+
switch (_b.label) {
|
|
206
|
+
case 0:
|
|
207
|
+
process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
|
|
208
|
+
default: {
|
|
209
|
+
channel: "https://zoom.example/default",
|
|
210
|
+
verificationToken: "default-token",
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
mockAxiosPost.mockResolvedValue({ status: 200 });
|
|
214
|
+
return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "missing channel", header: "missing channel" }, { channel: "unknown" })];
|
|
215
|
+
case 1:
|
|
216
|
+
_b.sent();
|
|
217
|
+
callArgs = mockAxiosPost.mock.calls[0];
|
|
218
|
+
(0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
|
|
219
|
+
_a = __read(callArgs, 2), url = _a[0], payload = _a[1];
|
|
220
|
+
(0, bun_test_1.expect)(url).toBe("https://zoom.example/default?format=full");
|
|
221
|
+
(0, bun_test_1.expect)(payload).toEqual({
|
|
222
|
+
content: {
|
|
223
|
+
body: [{ text: "missing channel", type: "message" }],
|
|
224
|
+
head: { text: "missing channel" },
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
return [2 /*return*/];
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}); });
|
|
231
|
+
(0, bun_test_1.it)("returns early when webhook url is missing for channel", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
232
|
+
return __generator(this, function (_a) {
|
|
233
|
+
switch (_a.label) {
|
|
234
|
+
case 0:
|
|
235
|
+
process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
|
|
236
|
+
default: {
|
|
237
|
+
verificationToken: "default-token",
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "no url", header: "no url" }, { channel: "default" })];
|
|
241
|
+
case 1:
|
|
242
|
+
_a.sent();
|
|
243
|
+
(0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(0);
|
|
244
|
+
return [2 /*return*/];
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}); });
|
|
248
|
+
(0, bun_test_1.it)("returns early when verification token is missing for channel", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
249
|
+
return __generator(this, function (_a) {
|
|
250
|
+
switch (_a.label) {
|
|
251
|
+
case 0:
|
|
252
|
+
process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
|
|
253
|
+
default: {
|
|
254
|
+
channel: "https://zoom.example/default",
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "no token", header: "no token" }, { channel: "default" })];
|
|
258
|
+
case 1:
|
|
259
|
+
_a.sent();
|
|
260
|
+
(0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(0);
|
|
261
|
+
return [2 /*return*/];
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}); });
|
|
265
|
+
(0, bun_test_1.it)("prefixes header with [ENV] when env provided", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
266
|
+
var callArgs, _a, payload;
|
|
267
|
+
return __generator(this, function (_b) {
|
|
268
|
+
switch (_b.label) {
|
|
269
|
+
case 0:
|
|
270
|
+
process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
|
|
271
|
+
default: {
|
|
272
|
+
channel: "https://zoom.example/default",
|
|
273
|
+
verificationToken: "token",
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
mockAxiosPost.mockResolvedValue({ status: 200 });
|
|
277
|
+
return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "status ok", header: "status ok" }, { channel: "default", env: "stg" })];
|
|
278
|
+
case 1:
|
|
279
|
+
_b.sent();
|
|
280
|
+
callArgs = mockAxiosPost.mock.calls[0];
|
|
281
|
+
(0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
|
|
282
|
+
_a = __read(callArgs, 2), payload = _a[1];
|
|
283
|
+
(0, bun_test_1.expect)(payload).toEqual({
|
|
284
|
+
content: {
|
|
285
|
+
body: [{ text: "status ok", type: "message" }],
|
|
286
|
+
head: { text: "[STG] status ok" },
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
return [2 /*return*/];
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}); });
|
|
293
|
+
(0, bun_test_1.it)("includes subheader when provided", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
294
|
+
var callArgs, _a, payload;
|
|
295
|
+
return __generator(this, function (_b) {
|
|
296
|
+
switch (_b.label) {
|
|
297
|
+
case 0:
|
|
298
|
+
process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
|
|
299
|
+
default: {
|
|
300
|
+
channel: "https://zoom.example/default",
|
|
301
|
+
verificationToken: "token",
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
mockAxiosPost.mockResolvedValue({ status: 200 });
|
|
305
|
+
return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "Body text", header: "Main Header", subheader: "Subheader text" }, { channel: "default" })];
|
|
306
|
+
case 1:
|
|
307
|
+
_b.sent();
|
|
308
|
+
callArgs = mockAxiosPost.mock.calls[0];
|
|
309
|
+
(0, bun_test_1.expect)(Array.isArray(callArgs)).toBe(true);
|
|
310
|
+
_a = __read(callArgs, 2), payload = _a[1];
|
|
311
|
+
(0, bun_test_1.expect)(payload).toEqual({
|
|
312
|
+
content: {
|
|
313
|
+
body: [{ text: "Body text", type: "message" }],
|
|
314
|
+
head: { sub_head: { text: "Subheader text" }, text: "Main Header" },
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
return [2 /*return*/];
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
}); });
|
|
321
|
+
(0, bun_test_1.it)("captures error and throws APIError when shouldThrow=true", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
322
|
+
var error_1;
|
|
323
|
+
return __generator(this, function (_a) {
|
|
324
|
+
switch (_a.label) {
|
|
325
|
+
case 0:
|
|
326
|
+
process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
|
|
327
|
+
default: {
|
|
328
|
+
channel: "https://zoom.example/default",
|
|
329
|
+
verificationToken: "token",
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
mockAxiosPost.mockRejectedValue(new Error("zoom down"));
|
|
333
|
+
_a.label = 1;
|
|
334
|
+
case 1:
|
|
335
|
+
_a.trys.push([1, 3, , 4]);
|
|
336
|
+
return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "err", header: "err" }, { channel: "default", shouldThrow: true })];
|
|
337
|
+
case 2:
|
|
338
|
+
_a.sent();
|
|
339
|
+
throw new Error("Expected sendToZoom to throw APIError");
|
|
340
|
+
case 3:
|
|
341
|
+
error_1 = _a.sent();
|
|
342
|
+
(0, bun_test_1.expect)(error_1.name).toBe("APIError");
|
|
343
|
+
(0, bun_test_1.expect)(error_1.title).toMatch(/Error posting to Zoom/i);
|
|
344
|
+
return [3 /*break*/, 4];
|
|
345
|
+
case 4:
|
|
346
|
+
(0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(1);
|
|
347
|
+
return [2 /*return*/];
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
}); });
|
|
351
|
+
(0, bun_test_1.it)("captures error and does not throw when shouldThrow=false", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
352
|
+
return __generator(this, function (_a) {
|
|
353
|
+
switch (_a.label) {
|
|
354
|
+
case 0:
|
|
355
|
+
process.env.ZOOM_CHAT_WEBHOOKS = JSON.stringify({
|
|
356
|
+
default: {
|
|
357
|
+
channel: "https://zoom.example/default",
|
|
358
|
+
verificationToken: "token",
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
mockAxiosPost.mockRejectedValue(new Error("zoom intermittent"));
|
|
362
|
+
return [4 /*yield*/, (0, zoomNotifier_1.sendToZoom)({ body: "err", header: "err" }, { channel: "default", shouldThrow: false })];
|
|
363
|
+
case 1:
|
|
364
|
+
_a.sent();
|
|
365
|
+
(0, bun_test_1.expect)(mockAxiosPost.mock.calls.length).toBe(1);
|
|
366
|
+
return [2 /*return*/];
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}); });
|
|
370
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Model } from "mongoose";
|
|
2
|
+
import type { modelRouterOptions } from "./api";
|
|
3
|
+
export declare const apiErrorContent: {
|
|
4
|
+
"application/json": {
|
|
5
|
+
schema: {
|
|
6
|
+
$ref: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare const defaultOpenApiErrorResponses: {
|
|
11
|
+
400: {
|
|
12
|
+
content: {
|
|
13
|
+
"application/json": {
|
|
14
|
+
schema: {
|
|
15
|
+
$ref: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
401: {
|
|
22
|
+
description: string;
|
|
23
|
+
};
|
|
24
|
+
403: {
|
|
25
|
+
content: {
|
|
26
|
+
"application/json": {
|
|
27
|
+
schema: {
|
|
28
|
+
$ref: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
description: string;
|
|
33
|
+
};
|
|
34
|
+
404: {
|
|
35
|
+
content: {
|
|
36
|
+
"application/json": {
|
|
37
|
+
schema: {
|
|
38
|
+
$ref: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
description: string;
|
|
43
|
+
};
|
|
44
|
+
405: {
|
|
45
|
+
content: {
|
|
46
|
+
"application/json": {
|
|
47
|
+
schema: {
|
|
48
|
+
$ref: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
description: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export declare function getOpenApiMiddleware<T>(model: Model<T>, options: Partial<modelRouterOptions<T>>): any;
|
|
56
|
+
export declare function listOpenApiMiddleware<T>(model: Model<T>, options: Partial<modelRouterOptions<T>>): any;
|
|
57
|
+
export declare function createOpenApiMiddleware<T>(model: Model<T>, options: Partial<modelRouterOptions<T>>): any;
|
|
58
|
+
export declare function patchOpenApiMiddleware<T>(model: Model<T>, options: Partial<modelRouterOptions<T>>): any;
|
|
59
|
+
export declare function deleteOpenApiMiddleware<T>(model: Model<T>, options: Partial<modelRouterOptions<T>>): any;
|
|
60
|
+
export declare function readOpenApiMiddleware<T>(options: Partial<modelRouterOptions<T>>, properties: any, required: string[], queryParameters: any): any;
|