@terreno/api 57.4.0 → 57.6.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.
- package/README.md +5 -5
- package/bunfig.toml +1 -1
- package/dist/actions.js +197 -368
- package/dist/adminModelRouter.js +88 -173
- package/dist/api.js +598 -852
- package/dist/audit/auditApp.js +48 -89
- package/dist/audit/auditEventModel.js +15 -16
- package/dist/audit/cloudTasksEnqueue.js +56 -149
- package/dist/audit/diff.js +70 -160
- package/dist/audit/processQueue.js +25 -70
- package/dist/audit/rbacSink.js +25 -66
- package/dist/audit/record.js +129 -251
- package/dist/auth.js +432 -681
- package/dist/authRecovery.js +155 -269
- package/dist/authTokens.js +43 -118
- package/dist/betterAuthApp.js +25 -26
- package/dist/betterAuthSetup.js +258 -413
- package/dist/browserLogsRoute.d.ts +6 -0
- package/dist/browserLogsRoute.js +97 -0
- package/dist/collectionRegistry.js +32 -47
- package/dist/config.js +53 -122
- package/dist/configurationApp.js +180 -361
- package/dist/configurationPlugin.js +130 -302
- package/dist/consentApp.js +276 -421
- package/dist/docLoader.js +78 -126
- package/dist/envConfigurationPlugin.js +25 -147
- package/dist/errors.js +151 -247
- package/dist/example.js +28 -34
- package/dist/expressServer.d.ts +10 -0
- package/dist/expressServer.js +109 -255
- package/dist/frameworkModelNames.d.ts +24 -0
- package/dist/frameworkModelNames.js +31 -0
- package/dist/githubAuth.js +152 -216
- package/dist/httpClient.js +176 -264
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -2
- package/dist/logger.js +145 -278
- package/dist/mcp/auth.js +76 -128
- package/dist/mcp/createMCPRequest.js +4 -5
- package/dist/mcp/handlers.js +268 -480
- package/dist/mcp/query.js +56 -150
- package/dist/mcp/registry.js +17 -30
- package/dist/mcp/schemaGenerator.js +95 -181
- package/dist/mcp/server.js +28 -100
- package/dist/mcp/serviceTokens.js +102 -191
- package/dist/mcp/toolGenerator.js +78 -191
- package/dist/middleware.js +15 -27
- package/dist/migrations/fixtures/all-down/20260910120000-one.js +2 -42
- package/dist/migrations/fixtures/all-down/20260910120001-two.js +2 -42
- package/dist/migrations/fixtures/bad-id/20260910120000-mismatch.js +1 -39
- package/dist/migrations/fixtures/bad-name/not-a-migration.js +1 -39
- package/dist/migrations/fixtures/valid/20260910120000-alpha.js +1 -39
- package/dist/migrations/fixtures/valid/20260910120001-beta.js +2 -42
- package/dist/migrations/generate.js +107 -229
- package/dist/migrations/load.js +75 -201
- package/dist/migrations/lock.js +54 -126
- package/dist/migrations/runner.js +192 -446
- package/dist/migrations/schemaCatalog.js +122 -263
- package/dist/models/consentForm.js +6 -6
- package/dist/models/consentResponse.js +5 -5
- package/dist/models/mcpServiceToken.js +66 -156
- package/dist/models/notification.js +6 -6
- package/dist/models/notificationPreference.js +6 -6
- package/dist/models/versionConfig.js +5 -5
- package/dist/notifications/notificationService.js +133 -273
- package/dist/notifications/notificationsApp.js +85 -179
- package/dist/notifications/notificationsBeforeSend.js +19 -64
- package/dist/notifiers/googleChatNotifier.js +36 -117
- package/dist/notifiers/slackNotifier.d.ts +31 -2
- package/dist/notifiers/slackNotifier.js +170 -119
- package/dist/notifiers/zoomNotifier.js +60 -111
- package/dist/openApi.js +107 -122
- package/dist/openApiBuilder.js +117 -159
- package/dist/openApiCompat.js +81 -148
- package/dist/openApiEtag.js +7 -7
- package/dist/openApiValidator.js +177 -286
- package/dist/orgs/orgContext.js +87 -157
- package/dist/orgs/orgPermissions.js +29 -68
- package/dist/orgs/orgPlugin.js +9 -27
- package/dist/orgs/organizationModel.js +65 -166
- package/dist/orgs/organizationSettings.js +29 -36
- package/dist/orgs/orgsApp.js +346 -608
- package/dist/permissions.js +88 -181
- package/dist/plugins.js +125 -218
- package/dist/populate.js +130 -240
- package/dist/rateLimit/applyTrustProxy.js +1 -1
- package/dist/rateLimit/createStore.js +7 -8
- package/dist/rateLimit/memoryStore.js +22 -100
- package/dist/rateLimit/middleware.js +48 -99
- package/dist/rateLimit/mongoStore.js +54 -112
- package/dist/rateLimit/policies.js +41 -75
- package/dist/rateLimit/redisStore.js +39 -133
- package/dist/rbac/access.js +119 -267
- package/dist/rbac/assertAllowed.js +95 -171
- package/dist/rbac/auditModel.js +14 -58
- package/dist/rbac/backfillAdmins.js +24 -130
- package/dist/rbac/fieldViews.js +46 -141
- package/dist/rbac/membershipOrgAdminSource.js +28 -99
- package/dist/rbac/middleware.js +30 -96
- package/dist/rbac/modelRouterAccess.js +130 -307
- package/dist/rbac/permissionUtils.js +40 -179
- package/dist/rbac/realtimeAccess.js +81 -147
- package/dist/rbac/resolve.d.ts +1 -1
- package/dist/rbac/resolve.js +148 -342
- package/dist/rbac/roleManager.js +318 -700
- package/dist/rbac/roleModel.js +44 -171
- package/dist/rbac/routes.js +93 -196
- package/dist/rbac/scopes.js +39 -133
- package/dist/rbac/statements.js +23 -91
- package/dist/rbac/userPlugin.js +3 -29
- package/dist/realtime/changeStreamWatcher.js +489 -800
- package/dist/realtime/deprecation.js +8 -10
- package/dist/realtime/queryMatcher.js +110 -191
- package/dist/realtime/queryStore.js +35 -118
- package/dist/realtime/realtimeApp.js +247 -401
- package/dist/realtime/registry.js +19 -30
- package/dist/realtime/sessionRevalidation.js +132 -358
- package/dist/realtime/socketAuth.js +89 -208
- package/dist/realtime/socketUser.js +10 -56
- package/dist/requestContext.js +93 -139
- package/dist/schemaMetadata.js +179 -274
- package/dist/scriptRunner.js +96 -266
- package/dist/scrubAdminFields.js +36 -108
- package/dist/secretProviders.js +130 -299
- package/dist/seedRunner.js +221 -514
- package/dist/sync/adminBroadcastScope.js +58 -170
- package/dist/sync/adminWindowAccess.js +15 -86
- package/dist/sync/adminWindowMutation.js +110 -181
- package/dist/sync/executors.js +425 -629
- package/dist/sync/loadHarness.js +392 -689
- package/dist/sync/models.js +181 -341
- package/dist/sync/mutationHandler.js +533 -801
- package/dist/sync/registrationSideEffects.js +41 -95
- package/dist/sync/registry.js +29 -49
- package/dist/sync/routes.js +484 -817
- package/dist/sync/scripts/compactTombstones.js +83 -228
- package/dist/sync/serialize.js +18 -58
- package/dist/sync/socketHandlers.js +253 -478
- package/dist/sync/streams.js +49 -117
- package/dist/sync/syncApp.js +12 -15
- package/dist/sync/syncBatch.js +63 -168
- package/dist/sync/syncSeqPlugin.js +430 -702
- package/dist/syncConsents.js +113 -253
- package/dist/terrenoApp.js +166 -276
- package/dist/tests/createTestData.js +146 -256
- package/dist/tests/models.js +14 -54
- package/dist/tests/mongoTestSetup.js +42 -103
- package/dist/tests/testHelper.js +31 -93
- package/dist/tests.js +12 -51
- package/dist/transformers.js +61 -164
- package/dist/utils.js +31 -93
- package/dist/vendor/wesleytodd-openapi/index.js +37 -51
- package/dist/vendor/wesleytodd-openapi/lib/generate-doc.js +32 -40
- package/dist/vendor/wesleytodd-openapi/lib/layer-schema.js +3 -3
- package/dist/vendor/wesleytodd-openapi/lib/ui.js +50 -19
- package/dist/vendor/wesleytodd-openapi/lib/validate.js +19 -47
- package/dist/versionCheckPlugin.js +52 -100
- package/dist/webhooks/headerValue.js +2 -2
- package/dist/webhooks/idempotency/memoryStore.js +16 -59
- package/dist/webhooks/idempotency/mongoStore.js +55 -130
- package/dist/webhooks/idempotency/webhookReceipt.js +9 -9
- package/dist/webhooks/rawBody.js +1 -1
- package/dist/webhooks/timingSafeEqual.js +4 -5
- package/dist/webhooks/verifiers/hmac.js +17 -18
- package/dist/webhooks/verifiers/sendgrid.js +20 -22
- package/dist/webhooks/verifiers/stripe.js +31 -65
- package/dist/webhooks/verifiers/twilio.js +23 -73
- package/dist/webhooks/webhooksApp.js +78 -177
- package/dist/zodOpenApi.js +2 -2
- package/package.json +6 -6
- package/src/__tests__/browserLogsRoute.test.ts +165 -0
- package/src/audit/auditApp.test.ts +5 -5
- package/src/audit/auditEventModel.ts +7 -3
- package/src/audit/auditRouter.test.ts +5 -5
- package/src/audit/rbacSink.test.ts +2 -2
- package/src/audit/record.test.ts +2 -2
- package/src/audit/record.ts +3 -2
- package/src/auth.ts +1 -1
- package/src/authRecovery.test.ts +43 -0
- package/src/authRecovery.ts +16 -10
- package/src/authTokens.ts +6 -2
- package/src/authVerification.test.ts +22 -0
- package/src/browserLogsRoute.ts +110 -0
- package/src/configurationPlugin.test.ts +1 -11
- package/src/expressServer.ts +10 -0
- package/src/frameworkModelNames.test.ts +62 -0
- package/src/frameworkModelNames.ts +33 -0
- package/src/index.ts +7 -0
- package/src/isolated/migrateCliConnect.isolated.ts +51 -0
- package/src/mcp/auth.test.ts +34 -1
- package/src/migrations/cli.test.ts +0 -23
- package/src/models/mcpServiceToken.ts +4 -3
- package/src/models/notification.ts +3 -2
- package/src/models/notificationPreference.ts +1 -1
- package/src/notifications/notificationsApp.test.ts +24 -1
- package/src/notifiers/slackNotifier.test.ts +186 -1
- package/src/notifiers/slackNotifier.ts +167 -8
- package/src/orgs/orgPlugin.ts +1 -1
- package/src/orgs/organizationModel.ts +11 -6
- package/src/plugins.test.ts +5 -0
- package/src/plugins.ts +3 -0
- package/src/realtime/realtimeApp.ts +1 -1
- package/src/sync/integration.test.ts +2 -2
- package/src/terrenoApp.ts +3 -0
- package/src/types.d.ts +1 -0
- package/src/webhooks/idempotency/webhookReceipt.ts +4 -3
- package/tsconfig.json +13 -54
- package/tsconfig.typedoc.json +2 -0
|
@@ -32,139 +32,190 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var
|
|
36
|
-
|
|
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
|
-
});
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
37
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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 };
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.sendToSlack = exports.lookupSlackUserIdByEmail = exports.formatSlackUserMention = exports.normalizeSlackUserId = void 0;
|
|
40
|
+
const Sentry = __importStar(require("@sentry/bun"));
|
|
41
|
+
const axios_1 = __importDefault(require("axios"));
|
|
42
|
+
const errors_1 = require("../errors");
|
|
43
|
+
const logger_1 = require("../logger");
|
|
44
|
+
/** Slack member IDs are `U…` (users) or `W…` (Enterprise Grid). */
|
|
45
|
+
const SLACK_USER_ID_PATTERN = /^[UW][A-Z0-9]{8,}$/i;
|
|
46
|
+
const SLACK_LOOKUP_BY_EMAIL_URL = "https://slack.com/api/users.lookupByEmail";
|
|
47
|
+
/**
|
|
48
|
+
* Normalize a Slack member ID. Accepts a bare id (`U012ABCDEF`) or a mention
|
|
49
|
+
* token (`<@U012ABCDEF>`). Returns undefined when the value is not a Slack
|
|
50
|
+
* member ID — names and emails cannot be used for mentions.
|
|
51
|
+
*/
|
|
52
|
+
const normalizeSlackUserId = (value) => {
|
|
53
|
+
const trimmed = value.trim();
|
|
54
|
+
if (!trimmed) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const unwrapped = trimmed.startsWith("<@") && trimmed.endsWith(">") ? trimmed.slice(2, -1) : trimmed;
|
|
58
|
+
if (!SLACK_USER_ID_PATTERN.test(unwrapped)) {
|
|
59
|
+
return undefined;
|
|
69
60
|
}
|
|
61
|
+
return unwrapped.toUpperCase();
|
|
70
62
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
exports.normalizeSlackUserId = normalizeSlackUserId;
|
|
64
|
+
/** Format a Slack member ID as an incoming-webhook mention token. */
|
|
65
|
+
const formatSlackUserMention = (slackUserId) => {
|
|
66
|
+
const id = (0, exports.normalizeSlackUserId)(slackUserId);
|
|
67
|
+
if (!id) {
|
|
68
|
+
throw new errors_1.APIError({
|
|
69
|
+
detail: slackUserId,
|
|
70
|
+
status: 400,
|
|
71
|
+
title: "Invalid Slack user id",
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return `<@${id}>`;
|
|
75
|
+
};
|
|
76
|
+
exports.formatSlackUserMention = formatSlackUserMention;
|
|
77
|
+
const uniqueMentionTokens = (mentionUserIds) => {
|
|
78
|
+
if (!mentionUserIds?.length) {
|
|
79
|
+
return [];
|
|
77
80
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
const seen = new Set();
|
|
82
|
+
const tokens = [];
|
|
83
|
+
for (const rawId of mentionUserIds) {
|
|
84
|
+
const id = (0, exports.normalizeSlackUserId)(rawId);
|
|
85
|
+
if (!id) {
|
|
86
|
+
logger_1.logger.warn("Skipping Slack mention; value is not a Slack member id", { value: rawId });
|
|
87
|
+
continue;
|
|
82
88
|
}
|
|
83
|
-
|
|
89
|
+
if (seen.has(id)) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
seen.add(id);
|
|
93
|
+
tokens.push(`<@${id}>`);
|
|
84
94
|
}
|
|
85
|
-
return
|
|
95
|
+
return tokens;
|
|
86
96
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
const applyMentions = (text, mentionUserIds) => {
|
|
98
|
+
const tokens = uniqueMentionTokens(mentionUserIds);
|
|
99
|
+
if (tokens.length === 0) {
|
|
100
|
+
return text;
|
|
101
|
+
}
|
|
102
|
+
if (!text) {
|
|
103
|
+
return tokens.join(" ");
|
|
93
104
|
}
|
|
94
|
-
return
|
|
105
|
+
return `${tokens.join(" ")} ${text}`;
|
|
95
106
|
};
|
|
96
|
-
|
|
97
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Resolve a workspace member's Slack user id from their email.
|
|
109
|
+
*
|
|
110
|
+
* Incoming webhooks cannot look users up. This calls `users.lookupByEmail` and
|
|
111
|
+
* needs a bot token with the `users:read.email` scope. Store the returned id on
|
|
112
|
+
* the staff/user record and pass it to `sendToSlack({mentionUserIds})`.
|
|
113
|
+
*/
|
|
114
|
+
const lookupSlackUserIdByEmail = async ({ email, token, shouldThrow = false, }) => {
|
|
115
|
+
const trimmedEmail = email.trim();
|
|
116
|
+
if (!trimmedEmail) {
|
|
117
|
+
if (shouldThrow) {
|
|
118
|
+
throw new errors_1.APIError({ status: 400, title: "Email is required to look up a Slack user" });
|
|
119
|
+
}
|
|
120
|
+
logger_1.logger.debug("lookupSlackUserIdByEmail skipped: empty email");
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
const botToken = token ?? process.env.SLACK_BOT_TOKEN;
|
|
124
|
+
if (!botToken) {
|
|
125
|
+
if (shouldThrow) {
|
|
126
|
+
throw new errors_1.APIError({
|
|
127
|
+
status: 500,
|
|
128
|
+
title: "SLACK_BOT_TOKEN is not set; cannot look up Slack user ids",
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
logger_1.logger.debug("lookupSlackUserIdByEmail skipped: no Slack bot token");
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const response = await axios_1.default.get(SLACK_LOOKUP_BY_EMAIL_URL, {
|
|
136
|
+
headers: { Authorization: `Bearer ${botToken}` },
|
|
137
|
+
params: { email: trimmedEmail },
|
|
138
|
+
});
|
|
139
|
+
const payload = response.data;
|
|
140
|
+
if (!payload?.ok || !payload.user?.id) {
|
|
141
|
+
const slackError = payload?.error ?? "unknown_error";
|
|
142
|
+
logger_1.logger.warn("Slack users.lookupByEmail did not return a user id", {
|
|
143
|
+
email: trimmedEmail,
|
|
144
|
+
slackError,
|
|
145
|
+
});
|
|
146
|
+
if (shouldThrow) {
|
|
147
|
+
throw new errors_1.APIError({
|
|
148
|
+
detail: slackError,
|
|
149
|
+
status: 502,
|
|
150
|
+
title: "Slack user lookup failed",
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
return (0, exports.normalizeSlackUserId)(payload.user.id);
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (error instanceof errors_1.APIError) {
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
const message = (0, errors_1.errorMessage)(error);
|
|
162
|
+
logger_1.logger.error(`Error looking up Slack user by email: ${message}`);
|
|
163
|
+
Sentry.captureException(error);
|
|
164
|
+
if (shouldThrow) {
|
|
165
|
+
throw new errors_1.APIError({
|
|
166
|
+
status: 500,
|
|
167
|
+
title: `Error looking up Slack user by email: ${message}`,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
98
172
|
};
|
|
99
|
-
|
|
100
|
-
exports.sendToSlack = void 0;
|
|
101
|
-
var Sentry = __importStar(require("@sentry/bun"));
|
|
102
|
-
var axios_1 = __importDefault(require("axios"));
|
|
103
|
-
var errors_1 = require("../errors");
|
|
104
|
-
var logger_1 = require("../logger");
|
|
173
|
+
exports.lookupSlackUserIdByEmail = lookupSlackUserIdByEmail;
|
|
105
174
|
// Convenience method to send data to a Slack webhook.
|
|
106
175
|
// If `url` is provided, it will be used directly instead of looking up from environment.
|
|
107
176
|
// DEPRECATED: Looking up webhook URLs from the SLACK_WEBHOOKS environment variable by channel name
|
|
108
177
|
// is deprecated and will be removed in a future version. Please pass the `url` parameter directly.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
formattedText = text;
|
|
141
|
-
if (env) {
|
|
142
|
-
formattedText = "[".concat(env.toUpperCase(), "] ").concat(text);
|
|
143
|
-
}
|
|
144
|
-
_e.label = 1;
|
|
145
|
-
case 1:
|
|
146
|
-
_e.trys.push([1, 3, , 4]);
|
|
147
|
-
return [4 /*yield*/, axios_1.default.post(slackWebhookUrl, {
|
|
148
|
-
text: formattedText,
|
|
149
|
-
})];
|
|
150
|
-
case 2:
|
|
151
|
-
_e.sent();
|
|
152
|
-
return [3 /*break*/, 4];
|
|
153
|
-
case 3:
|
|
154
|
-
error_1 = _e.sent();
|
|
155
|
-
message = (0, errors_1.errorMessage)(error_1);
|
|
156
|
-
logger_1.logger.error("Error posting to slack: ".concat(message));
|
|
157
|
-
Sentry.captureException(error_1);
|
|
158
|
-
if (shouldThrow) {
|
|
159
|
-
throw new errors_1.APIError({
|
|
160
|
-
status: 500,
|
|
161
|
-
title: "Error posting to slack: ".concat(message),
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
return [3 /*break*/, 4];
|
|
165
|
-
case 4: return [2 /*return*/];
|
|
166
|
-
}
|
|
178
|
+
const sendToSlack = async (text, { slackChannel, shouldThrow = false, env, url, mentionUserIds } = {}) => {
|
|
179
|
+
let slackWebhookUrl = url;
|
|
180
|
+
if (!slackWebhookUrl) {
|
|
181
|
+
logger_1.logger.debug("DEPRECATED: Looking up webhook URLs from SLACK_WEBHOOKS environment variable is deprecated and will be removed in a future version. Please pass the url parameter directly.");
|
|
182
|
+
// since Slack now requires a webhook for each channel, we need to store them in the environment
|
|
183
|
+
// as an object, so we can look them up by channel name.
|
|
184
|
+
const slackWebhooksString = process.env.SLACK_WEBHOOKS;
|
|
185
|
+
if (!slackWebhooksString) {
|
|
186
|
+
logger_1.logger.debug("You must set SLACK_WEBHOOKS in the environment to use sendToSlack.");
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const slackWebhooks = JSON.parse(slackWebhooksString ?? "{}");
|
|
190
|
+
const channel = slackChannel ?? "default";
|
|
191
|
+
slackWebhookUrl = slackWebhooks[channel] ?? slackWebhooks.default;
|
|
192
|
+
if (!slackWebhookUrl) {
|
|
193
|
+
Sentry.captureException(new errors_1.APIError({
|
|
194
|
+
status: 500,
|
|
195
|
+
title: `No webhook url set in env for ${channel}. Slack message not sent`,
|
|
196
|
+
}));
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
let formattedText = applyMentions(text, mentionUserIds);
|
|
201
|
+
if (env) {
|
|
202
|
+
formattedText = `[${env.toUpperCase()}] ${formattedText}`;
|
|
203
|
+
}
|
|
204
|
+
try {
|
|
205
|
+
await axios_1.default.post(slackWebhookUrl, {
|
|
206
|
+
text: formattedText,
|
|
167
207
|
});
|
|
168
|
-
}
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
const message = (0, errors_1.errorMessage)(error);
|
|
211
|
+
logger_1.logger.error(`Error posting to slack: ${message}`);
|
|
212
|
+
Sentry.captureException(error);
|
|
213
|
+
if (shouldThrow) {
|
|
214
|
+
throw new errors_1.APIError({
|
|
215
|
+
status: 500,
|
|
216
|
+
title: `Error posting to slack: ${message}`,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
169
220
|
};
|
|
170
221
|
exports.sendToSlack = sendToSlack;
|
|
@@ -32,51 +32,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
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
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
72
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
73
37
|
};
|
|
74
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
75
39
|
exports.sendToZoom = void 0;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
40
|
+
const Sentry = __importStar(require("@sentry/bun"));
|
|
41
|
+
const axios_1 = __importDefault(require("axios"));
|
|
42
|
+
const errors_1 = require("../errors");
|
|
43
|
+
const logger_1 = require("../logger");
|
|
80
44
|
/**
|
|
81
45
|
* Sends a rich formatted message to a Zoom chat channel via webhook.
|
|
82
46
|
*
|
|
@@ -102,76 +66,61 @@ var logger_1 = require("../logger");
|
|
|
102
66
|
* Logs errors to Sentry and logger when webhook is missing or request fails.
|
|
103
67
|
* Uses Zoom's rich message format (format=full) with structured header and body.
|
|
104
68
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
_m.sent();
|
|
160
|
-
return [3 /*break*/, 4];
|
|
161
|
-
case 3:
|
|
162
|
-
error_1 = _m.sent();
|
|
163
|
-
message = (0, errors_1.errorMessage)(error_1);
|
|
164
|
-
logger_1.logger.error("Error posting to Zoom: ".concat(message));
|
|
165
|
-
Sentry.captureException(error_1);
|
|
166
|
-
if (shouldThrow) {
|
|
167
|
-
throw new errors_1.APIError({
|
|
168
|
-
status: 500,
|
|
169
|
-
title: "Error posting to Zoom: ".concat(message),
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
return [3 /*break*/, 4];
|
|
173
|
-
case 4: return [2 /*return*/];
|
|
69
|
+
const sendToZoom = async ({ header, body, subheader }, { channel, shouldThrow = false, env }) => {
|
|
70
|
+
const zoomWebhooksString = process.env.ZOOM_CHAT_WEBHOOKS;
|
|
71
|
+
if (!zoomWebhooksString) {
|
|
72
|
+
const msg = "ZOOM_CHAT_WEBHOOKS not set. Zoom message not sent";
|
|
73
|
+
Sentry.captureException(new errors_1.APIError({ status: 500, title: msg }));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const zoomWebhooks = JSON.parse(zoomWebhooksString ?? "{}");
|
|
77
|
+
const zoomChannel = channel ?? "default";
|
|
78
|
+
const zoomWebhookUrl = zoomWebhooks[zoomChannel]?.channel ?? zoomWebhooks.default?.channel;
|
|
79
|
+
if (!zoomWebhookUrl) {
|
|
80
|
+
const msg = `No webhook url set in env for ${zoomChannel}. Zoom message not sent`;
|
|
81
|
+
Sentry.captureException(new errors_1.APIError({ status: 500, title: msg }));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const zoomToken = zoomWebhooks[zoomChannel]?.verificationToken ?? zoomWebhooks.default?.verificationToken;
|
|
85
|
+
if (!zoomToken) {
|
|
86
|
+
const msg = `No verification token set in env for ${zoomChannel}. Zoom message not sent`;
|
|
87
|
+
Sentry.captureException(new errors_1.APIError({ status: 500, title: msg }));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const messageBody = {
|
|
91
|
+
body: [
|
|
92
|
+
{
|
|
93
|
+
text: body,
|
|
94
|
+
type: "message",
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
head: {
|
|
98
|
+
text: env ? `[${env.toUpperCase()}] ${header}` : header,
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
if (subheader) {
|
|
102
|
+
messageBody.head.sub_head = {
|
|
103
|
+
text: subheader,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
await axios_1.default.post(`${zoomWebhookUrl}?format=full`, { content: messageBody }, {
|
|
108
|
+
headers: {
|
|
109
|
+
Authorization: zoomToken,
|
|
110
|
+
"Content-Type": "application/json",
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
const message = (0, errors_1.errorMessage)(error);
|
|
116
|
+
logger_1.logger.error(`Error posting to Zoom: ${message}`);
|
|
117
|
+
Sentry.captureException(error);
|
|
118
|
+
if (shouldThrow) {
|
|
119
|
+
throw new errors_1.APIError({
|
|
120
|
+
status: 500,
|
|
121
|
+
title: `Error posting to Zoom: ${message}`,
|
|
122
|
+
});
|
|
174
123
|
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
177
126
|
exports.sendToZoom = sendToZoom;
|