@vercel/slack-bolt 1.3.1 → 1.4.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/README.md +84 -8
- package/dist/cli.d.mts +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +357 -507
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +385 -497
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +181 -90
- package/dist/index.d.ts +181 -90
- package/dist/index.js +491 -367
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +489 -365
- package/dist/index.mjs.map +1 -1
- package/dist/preview-DAWKwXt1.mjs +689 -0
- package/dist/preview-DAWKwXt1.mjs.map +1 -0
- package/dist/preview-DeqpNNn_.js +794 -0
- package/dist/preview-DeqpNNn_.js.map +1 -0
- package/dist/preview.d.mts +47 -44
- package/dist/preview.d.ts +47 -44
- package/dist/preview.js +3 -13
- package/dist/preview.mjs +2 -6
- package/package.json +9 -8
- package/dist/chunk-B5E7QPZP.mjs +0 -11
- package/dist/chunk-B5E7QPZP.mjs.map +0 -1
- package/dist/chunk-F7WJK2MS.mjs +0 -980
- package/dist/chunk-F7WJK2MS.mjs.map +0 -1
- package/dist/chunk-QHMZVK6J.js +0 -14
- package/dist/chunk-QHMZVK6J.js.map +0 -1
- package/dist/chunk-VI33CCYY.js +0 -1003
- package/dist/chunk-VI33CCYY.js.map +0 -1
- package/dist/preview.js.map +0 -1
- package/dist/preview.mjs.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,525 +1,375 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
|
|
13
|
-
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
14
|
-
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
15
|
-
|
|
2
|
+
const require_preview = require("./preview-DeqpNNn_.js");
|
|
3
|
+
let node_fs = require("node:fs");
|
|
4
|
+
node_fs = require_preview.__toESM(node_fs);
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
node_path = require_preview.__toESM(node_path);
|
|
7
|
+
let commander = require("commander");
|
|
8
|
+
let zod = require("zod");
|
|
9
|
+
//#region src/internal/schemas.ts
|
|
16
10
|
function formatMissingKeys(error) {
|
|
17
|
-
|
|
11
|
+
return error.issues.map((i) => i.path.join(".")).join(", ");
|
|
18
12
|
}
|
|
13
|
+
const systemEnvSchema = zod.z.object({
|
|
14
|
+
VERCEL_ENV: zod.z.enum([
|
|
15
|
+
"production",
|
|
16
|
+
"preview",
|
|
17
|
+
"development"
|
|
18
|
+
]),
|
|
19
|
+
VERCEL_GIT_COMMIT_REF: zod.z.string(),
|
|
20
|
+
VERCEL_PROJECT_ID: zod.z.string(),
|
|
21
|
+
VERCEL_URL: zod.z.string(),
|
|
22
|
+
VERCEL_BRANCH_URL: zod.z.string().optional(),
|
|
23
|
+
VERCEL_TEAM_ID: zod.z.string().optional(),
|
|
24
|
+
VERCEL_GIT_COMMIT_SHA: zod.z.string().optional(),
|
|
25
|
+
VERCEL_GIT_COMMIT_MESSAGE: zod.z.string().optional(),
|
|
26
|
+
VERCEL_GIT_COMMIT_AUTHOR_LOGIN: zod.z.string().optional(),
|
|
27
|
+
VERCEL_DEPLOYMENT_ID: zod.z.string().optional(),
|
|
28
|
+
VERCEL_AUTOMATION_BYPASS_SECRET: zod.z.string().optional()
|
|
29
|
+
});
|
|
30
|
+
const slackEnvSchema = zod.z.object({
|
|
31
|
+
SLACK_APP_ID: zod.z.string().optional(),
|
|
32
|
+
SLACK_CONFIGURATION_TOKEN: zod.z.string(),
|
|
33
|
+
SLACK_SERVICE_TOKEN: zod.z.string().optional(),
|
|
34
|
+
SLACK_CONFIG_REFRESH_TOKEN: zod.z.string().optional(),
|
|
35
|
+
MANIFEST_PATH: zod.z.string().default("manifest.json")
|
|
36
|
+
});
|
|
37
|
+
const vercelEnvSchema = zod.z.object({ VERCEL_API_TOKEN: zod.z.string() });
|
|
19
38
|
function validateAndBuildParams(env) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
commitMessage: systemResult.data.VERCEL_GIT_COMMIT_MESSAGE,
|
|
54
|
-
commitAuthor: systemResult.data.VERCEL_GIT_COMMIT_AUTHOR_LOGIN,
|
|
55
|
-
deploymentId: systemResult.data.VERCEL_DEPLOYMENT_ID,
|
|
56
|
-
automationBypassSecret: systemResult.data.VERCEL_AUTOMATION_BYPASS_SECRET,
|
|
57
|
-
slackAppId: slackResult.data.SLACK_APP_ID,
|
|
58
|
-
slackConfigurationToken: slackResult.data.SLACK_CONFIGURATION_TOKEN,
|
|
59
|
-
slackConfigRefreshToken: slackResult.data.SLACK_CONFIG_REFRESH_TOKEN,
|
|
60
|
-
slackServiceToken: slackResult.data.SLACK_SERVICE_TOKEN,
|
|
61
|
-
manifestPath: slackResult.data.MANIFEST_PATH,
|
|
62
|
-
vercelApiToken: vercelResult.data.VERCEL_API_TOKEN
|
|
63
|
-
};
|
|
39
|
+
const systemResult = systemEnvSchema.safeParse(env);
|
|
40
|
+
if (!systemResult.success) {
|
|
41
|
+
const missing = formatMissingKeys(systemResult.error);
|
|
42
|
+
throw new Error(`Missing Vercel system environment variables: ${missing}\nEnable 'Automatically expose System Environment Variables' in your Vercel project settings:\nhttps://vercel.com/docs/projects/environment-variables/system-environment-variables`);
|
|
43
|
+
}
|
|
44
|
+
const slackResult = slackEnvSchema.safeParse(env);
|
|
45
|
+
if (!slackResult.success) {
|
|
46
|
+
const missing = formatMissingKeys(slackResult.error);
|
|
47
|
+
throw new Error(`Missing Slack environment variables: ${missing}\nAdd them as environment variables in your Vercel project.`);
|
|
48
|
+
}
|
|
49
|
+
const vercelResult = vercelEnvSchema.safeParse(env);
|
|
50
|
+
if (!vercelResult.success) {
|
|
51
|
+
const missing = formatMissingKeys(vercelResult.error);
|
|
52
|
+
throw new Error(`Missing Vercel environment variables: ${missing}\nCreate a new token and add it as VERCEL_API_TOKEN in your Vercel project:\nhttps://vercel.com/account/settings/tokens`);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
branch: systemResult.data.VERCEL_GIT_COMMIT_REF,
|
|
56
|
+
projectId: systemResult.data.VERCEL_PROJECT_ID,
|
|
57
|
+
deploymentUrl: systemResult.data.VERCEL_URL,
|
|
58
|
+
branchUrl: systemResult.data.VERCEL_BRANCH_URL,
|
|
59
|
+
teamId: systemResult.data.VERCEL_TEAM_ID,
|
|
60
|
+
commitSha: systemResult.data.VERCEL_GIT_COMMIT_SHA,
|
|
61
|
+
commitMessage: systemResult.data.VERCEL_GIT_COMMIT_MESSAGE,
|
|
62
|
+
commitAuthor: systemResult.data.VERCEL_GIT_COMMIT_AUTHOR_LOGIN,
|
|
63
|
+
deploymentId: systemResult.data.VERCEL_DEPLOYMENT_ID,
|
|
64
|
+
automationBypassSecret: systemResult.data.VERCEL_AUTOMATION_BYPASS_SECRET,
|
|
65
|
+
slackAppId: slackResult.data.SLACK_APP_ID,
|
|
66
|
+
slackConfigurationToken: slackResult.data.SLACK_CONFIGURATION_TOKEN,
|
|
67
|
+
slackConfigRefreshToken: slackResult.data.SLACK_CONFIG_REFRESH_TOKEN,
|
|
68
|
+
slackServiceToken: slackResult.data.SLACK_SERVICE_TOKEN,
|
|
69
|
+
manifestPath: slackResult.data.MANIFEST_PATH,
|
|
70
|
+
vercelApiToken: vercelResult.data.VERCEL_API_TOKEN
|
|
71
|
+
};
|
|
64
72
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
try {
|
|
128
|
-
appId = await chunkVI33CCYY_js.getEnvironmentVariable({
|
|
129
|
-
projectId,
|
|
130
|
-
envId,
|
|
131
|
-
token: vercelApiToken,
|
|
132
|
-
teamId
|
|
133
|
-
});
|
|
134
|
-
} catch {
|
|
135
|
-
chunkVI33CCYY_js.log.warning(`Failed to decrypt SLACK_APP_ID for branch ${branch}`);
|
|
136
|
-
}
|
|
137
|
-
if (appId) {
|
|
138
|
-
try {
|
|
139
|
-
await chunkVI33CCYY_js.deleteSlackApp({
|
|
140
|
-
token: slackConfigurationToken,
|
|
141
|
-
appId
|
|
142
|
-
});
|
|
143
|
-
chunkVI33CCYY_js.log.info(`${appId} deleted (branch: ${branch})`);
|
|
144
|
-
} catch (error) {
|
|
145
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
146
|
-
if (msg.includes("app_not_found")) {
|
|
147
|
-
chunkVI33CCYY_js.log.info(`${appId} already deleted (branch: ${branch})`);
|
|
148
|
-
} else {
|
|
149
|
-
chunkVI33CCYY_js.log.warning(`Failed to delete app ${appId}: ${msg}`);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
for (const env of envs) {
|
|
154
|
-
if (env.id && env.gitBranch === branch && SLACK_ENV_VAR_KEYS.includes(env.key)) {
|
|
155
|
-
try {
|
|
156
|
-
await chunkVI33CCYY_js.deleteEnvironmentVariable({
|
|
157
|
-
projectId,
|
|
158
|
-
envId: env.id,
|
|
159
|
-
token: vercelApiToken,
|
|
160
|
-
teamId
|
|
161
|
-
});
|
|
162
|
-
} catch (error) {
|
|
163
|
-
chunkVI33CCYY_js.log.warning(
|
|
164
|
-
`Failed to delete env var ${env.key} for branch ${branch}: ${error instanceof Error ? error.message : error}`
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
chunkVI33CCYY_js.log.success("Orphan cleanup completed");
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/cleanup.ts
|
|
75
|
+
const SLACK_ENV_VAR_KEYS = [
|
|
76
|
+
"SLACK_APP_ID",
|
|
77
|
+
"SLACK_CLIENT_ID",
|
|
78
|
+
"SLACK_CLIENT_SECRET",
|
|
79
|
+
"SLACK_SIGNING_SECRET",
|
|
80
|
+
"SLACK_BOT_TOKEN"
|
|
81
|
+
];
|
|
82
|
+
async function cleanupOrphanedApps({ projectId, currentBranch, vercelApiToken, teamId, slackConfigurationToken }) {
|
|
83
|
+
const activeBranches = await require_preview.getActiveBranches({
|
|
84
|
+
projectId,
|
|
85
|
+
token: vercelApiToken,
|
|
86
|
+
teamId
|
|
87
|
+
});
|
|
88
|
+
const envs = await require_preview.getEnvironmentVariables({
|
|
89
|
+
projectId,
|
|
90
|
+
token: vercelApiToken,
|
|
91
|
+
teamId
|
|
92
|
+
});
|
|
93
|
+
const staleBranches = /* @__PURE__ */ new Map();
|
|
94
|
+
for (const env of envs) if (env.key === "SLACK_APP_ID" && env.gitBranch && env.gitBranch !== currentBranch && !activeBranches.has(env.gitBranch)) staleBranches.set(env.gitBranch, env.id);
|
|
95
|
+
if (staleBranches.size === 0) {
|
|
96
|
+
require_preview.log.info("No orphaned preview apps found");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
require_preview.log.step(`Found ${staleBranches.size} orphaned ${staleBranches.size === 1 ? "branch" : "branches"}`);
|
|
100
|
+
for (const [branch, envId] of staleBranches) {
|
|
101
|
+
let appId = null;
|
|
102
|
+
try {
|
|
103
|
+
appId = await require_preview.getEnvironmentVariable({
|
|
104
|
+
projectId,
|
|
105
|
+
envId,
|
|
106
|
+
token: vercelApiToken,
|
|
107
|
+
teamId
|
|
108
|
+
});
|
|
109
|
+
} catch {
|
|
110
|
+
require_preview.log.warning(`Failed to decrypt SLACK_APP_ID for branch ${branch}`);
|
|
111
|
+
}
|
|
112
|
+
if (appId) try {
|
|
113
|
+
await require_preview.deleteSlackApp({
|
|
114
|
+
token: slackConfigurationToken,
|
|
115
|
+
appId
|
|
116
|
+
});
|
|
117
|
+
require_preview.log.info(`${appId} deleted (branch: ${branch})`);
|
|
118
|
+
} catch (error) {
|
|
119
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
120
|
+
if (msg.includes("app_not_found")) require_preview.log.info(`${appId} already deleted (branch: ${branch})`);
|
|
121
|
+
else require_preview.log.warning(`Failed to delete app ${appId}: ${msg}`);
|
|
122
|
+
}
|
|
123
|
+
for (const env of envs) if (env.id && env.gitBranch === branch && SLACK_ENV_VAR_KEYS.includes(env.key)) try {
|
|
124
|
+
await require_preview.deleteEnvironmentVariable({
|
|
125
|
+
projectId,
|
|
126
|
+
envId: env.id,
|
|
127
|
+
token: vercelApiToken,
|
|
128
|
+
teamId
|
|
129
|
+
});
|
|
130
|
+
} catch (error) {
|
|
131
|
+
require_preview.log.warning(`Failed to delete env var ${env.key} for branch ${branch}: ${error instanceof Error ? error.message : error}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
require_preview.log.success("Orphan cleanup completed");
|
|
171
135
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
"src/cleanup.ts"() {
|
|
175
|
-
chunkVI33CCYY_js.init_slack();
|
|
176
|
-
chunkVI33CCYY_js.init_vercel();
|
|
177
|
-
chunkVI33CCYY_js.init_logger();
|
|
178
|
-
SLACK_ENV_VAR_KEYS = [
|
|
179
|
-
"SLACK_APP_ID",
|
|
180
|
-
"SLACK_CLIENT_ID",
|
|
181
|
-
"SLACK_CLIENT_SECRET",
|
|
182
|
-
"SLACK_SIGNING_SECRET",
|
|
183
|
-
"SLACK_BOT_TOKEN"
|
|
184
|
-
];
|
|
185
|
-
}
|
|
186
|
-
});
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/cli/build.ts
|
|
187
138
|
async function executeBuild(params, options) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
currentBranch: params.branch,
|
|
277
|
-
vercelApiToken: params.vercelApiToken,
|
|
278
|
-
teamId: params.teamId,
|
|
279
|
-
slackConfigurationToken: params.slackConfigurationToken
|
|
280
|
-
});
|
|
281
|
-
} catch (error) {
|
|
282
|
-
chunkVI33CCYY_js.log.warning(
|
|
283
|
-
`Orphan cleanup failed: ${error instanceof Error ? error.message : error}`
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
const result = await chunkVI33CCYY_js.preview(params, "cli");
|
|
288
|
-
if (result.isNew && params.deploymentId) {
|
|
289
|
-
chunkVI33CCYY_js.log.step("Creating new deployment to pick up new environment variables");
|
|
290
|
-
const { id, url } = await chunkVI33CCYY_js.createDeployment({
|
|
291
|
-
deploymentId: params.deploymentId,
|
|
292
|
-
projectId: params.projectId,
|
|
293
|
-
token: params.vercelApiToken,
|
|
294
|
-
teamId: params.teamId
|
|
295
|
-
});
|
|
296
|
-
chunkVI33CCYY_js.log.success(`New deployment created: ${url} (${id})`);
|
|
297
|
-
chunkVI33CCYY_js.log.step("Cancelling current deployment");
|
|
298
|
-
await chunkVI33CCYY_js.cancelDeployment({
|
|
299
|
-
deploymentId: params.deploymentId,
|
|
300
|
-
token: params.vercelApiToken,
|
|
301
|
-
teamId: params.teamId
|
|
302
|
-
});
|
|
303
|
-
}
|
|
139
|
+
if (!params.slackConfigurationToken) throw new Error("Slack Configuration Token is not set. Generate a configuration token and add it as SLACK_CONFIGURATION_TOKEN in your Vercel project:\nhttps://api.slack.com/apps");
|
|
140
|
+
try {
|
|
141
|
+
await require_preview.authTest({ token: params.slackConfigurationToken });
|
|
142
|
+
} catch (error) {
|
|
143
|
+
if (!params.slackConfigRefreshToken) throw new Error("Slack configuration token is invalid or expired. Provide SLACK_CONFIG_REFRESH_TOKEN for automatic rotation, or generate a new token:\nhttps://api.slack.com/apps", { cause: error });
|
|
144
|
+
require_preview.log.step("Refreshing SLACK_CONFIGURATION_TOKEN");
|
|
145
|
+
try {
|
|
146
|
+
const rotated = await require_preview.rotateConfigToken({ refreshToken: params.slackConfigRefreshToken });
|
|
147
|
+
params.slackConfigurationToken = rotated.token;
|
|
148
|
+
params.slackConfigRefreshToken = rotated.refreshToken;
|
|
149
|
+
await require_preview.addEnvironmentVariables({
|
|
150
|
+
projectId: params.projectId,
|
|
151
|
+
token: params.vercelApiToken,
|
|
152
|
+
teamId: params.teamId,
|
|
153
|
+
envs: [{
|
|
154
|
+
key: "SLACK_CONFIGURATION_TOKEN",
|
|
155
|
+
value: rotated.token,
|
|
156
|
+
type: "encrypted",
|
|
157
|
+
target: [
|
|
158
|
+
"production",
|
|
159
|
+
"preview",
|
|
160
|
+
"development"
|
|
161
|
+
]
|
|
162
|
+
}, {
|
|
163
|
+
key: "SLACK_CONFIG_REFRESH_TOKEN",
|
|
164
|
+
value: rotated.refreshToken,
|
|
165
|
+
type: "encrypted",
|
|
166
|
+
target: [
|
|
167
|
+
"production",
|
|
168
|
+
"preview",
|
|
169
|
+
"development"
|
|
170
|
+
]
|
|
171
|
+
}]
|
|
172
|
+
});
|
|
173
|
+
require_preview.log.success("Configuration token rotated and persisted");
|
|
174
|
+
} catch (rotateError) {
|
|
175
|
+
throw new Error("Failed to rotate configuration token — refresh token may be invalid. Generate new tokens:\nhttps://api.slack.com/apps", { cause: rotateError });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (params.slackServiceToken) try {
|
|
179
|
+
await require_preview.authTest({ token: params.slackServiceToken });
|
|
180
|
+
} catch (error) {
|
|
181
|
+
require_preview.log.warning("SLACK_SERVICE_TOKEN is invalid — app must be installed manually");
|
|
182
|
+
require_preview.log.info("https://docs.slack.dev/authentication/tokens/#service");
|
|
183
|
+
require_preview.log.debug(error);
|
|
184
|
+
}
|
|
185
|
+
if (!params.branch) throw new Error("VERCEL_GIT_COMMIT_REF is not set — connect your Git repository in your Vercel project settings.\nhttps://vercel.com/docs/git");
|
|
186
|
+
try {
|
|
187
|
+
await require_preview.getProject({
|
|
188
|
+
projectId: params.projectId,
|
|
189
|
+
token: params.vercelApiToken,
|
|
190
|
+
teamId: params.teamId
|
|
191
|
+
});
|
|
192
|
+
} catch (error) {
|
|
193
|
+
throw new Error("Vercel API token cannot access this project. Ensure VERCEL_API_TOKEN is valid and has access to this team:\nhttps://vercel.com/account/settings/tokens", { cause: error });
|
|
194
|
+
}
|
|
195
|
+
const manifestFullPath = node_path.default.join(process.cwd(), params.manifestPath);
|
|
196
|
+
if (!node_fs.default.existsSync(manifestFullPath)) throw new Error(`No manifest found at ${params.manifestPath}. Create a manifest.json (or manifest.yaml) file with your Slack app configuration:\nhttps://docs.slack.dev/reference/manifests`);
|
|
197
|
+
if (options?.cleanup) {
|
|
198
|
+
require_preview.log.step("Cleaning up orphaned preview apps");
|
|
199
|
+
try {
|
|
200
|
+
await cleanupOrphanedApps({
|
|
201
|
+
projectId: params.projectId,
|
|
202
|
+
currentBranch: params.branch,
|
|
203
|
+
vercelApiToken: params.vercelApiToken,
|
|
204
|
+
teamId: params.teamId,
|
|
205
|
+
slackConfigurationToken: params.slackConfigurationToken
|
|
206
|
+
});
|
|
207
|
+
} catch (error) {
|
|
208
|
+
require_preview.log.warning(`Orphan cleanup failed: ${error instanceof Error ? error.message : error}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if ((await require_preview.preview(params, "cli")).isNew && params.deploymentId) {
|
|
212
|
+
require_preview.log.step("Creating new deployment to pick up new environment variables");
|
|
213
|
+
const { id, url } = await require_preview.createDeployment({
|
|
214
|
+
deploymentId: params.deploymentId,
|
|
215
|
+
projectId: params.projectId,
|
|
216
|
+
token: params.vercelApiToken,
|
|
217
|
+
teamId: params.teamId
|
|
218
|
+
});
|
|
219
|
+
require_preview.log.success(`New deployment created: ${url} (${id})`);
|
|
220
|
+
require_preview.log.step("Cancelling current deployment");
|
|
221
|
+
await require_preview.cancelDeployment({
|
|
222
|
+
deploymentId: params.deploymentId,
|
|
223
|
+
token: params.vercelApiToken,
|
|
224
|
+
teamId: params.teamId
|
|
225
|
+
});
|
|
226
|
+
}
|
|
304
227
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
228
|
+
//#endregion
|
|
229
|
+
//#region src/cli/env.ts
|
|
230
|
+
const ENV_KEYS = [
|
|
231
|
+
"VERCEL_ENV",
|
|
232
|
+
"VERCEL_GIT_COMMIT_REF",
|
|
233
|
+
"VERCEL_PROJECT_ID",
|
|
234
|
+
"VERCEL_URL",
|
|
235
|
+
"VERCEL_BRANCH_URL",
|
|
236
|
+
"VERCEL_TEAM_ID",
|
|
237
|
+
"VERCEL_GIT_COMMIT_SHA",
|
|
238
|
+
"VERCEL_GIT_COMMIT_MESSAGE",
|
|
239
|
+
"VERCEL_GIT_COMMIT_AUTHOR_LOGIN",
|
|
240
|
+
"VERCEL_DEPLOYMENT_ID",
|
|
241
|
+
"VERCEL_AUTOMATION_BYPASS_SECRET",
|
|
242
|
+
"SLACK_APP_ID",
|
|
243
|
+
"SLACK_CONFIGURATION_TOKEN",
|
|
244
|
+
"SLACK_SERVICE_TOKEN",
|
|
245
|
+
"SLACK_CONFIG_REFRESH_TOKEN",
|
|
246
|
+
"MANIFEST_PATH",
|
|
247
|
+
"VERCEL_API_TOKEN"
|
|
248
|
+
];
|
|
316
249
|
function envKeyToFlag(key) {
|
|
317
|
-
|
|
250
|
+
return key.toLowerCase().replace(/_/g, "-");
|
|
318
251
|
}
|
|
319
252
|
function flagToCamelCase(flag) {
|
|
320
|
-
|
|
253
|
+
return flag.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
321
254
|
}
|
|
322
255
|
function resolveEnv(options) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
256
|
+
const overrides = {};
|
|
257
|
+
for (const key of ENV_KEYS) {
|
|
258
|
+
const value = options[flagToCamelCase(envKeyToFlag(key))];
|
|
259
|
+
if (typeof value === "string") overrides[key] = value;
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
...process.env,
|
|
263
|
+
...overrides
|
|
264
|
+
};
|
|
332
265
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
"src/cli/env.ts"() {
|
|
336
|
-
ENV_KEYS = [
|
|
337
|
-
"VERCEL_ENV",
|
|
338
|
-
"VERCEL_GIT_COMMIT_REF",
|
|
339
|
-
"VERCEL_PROJECT_ID",
|
|
340
|
-
"VERCEL_URL",
|
|
341
|
-
"VERCEL_BRANCH_URL",
|
|
342
|
-
"VERCEL_TEAM_ID",
|
|
343
|
-
"VERCEL_GIT_COMMIT_SHA",
|
|
344
|
-
"VERCEL_GIT_COMMIT_MESSAGE",
|
|
345
|
-
"VERCEL_GIT_COMMIT_AUTHOR_LOGIN",
|
|
346
|
-
"VERCEL_DEPLOYMENT_ID",
|
|
347
|
-
"VERCEL_AUTOMATION_BYPASS_SECRET",
|
|
348
|
-
"SLACK_APP_ID",
|
|
349
|
-
"SLACK_CONFIGURATION_TOKEN",
|
|
350
|
-
"SLACK_SERVICE_TOKEN",
|
|
351
|
-
"SLACK_CONFIG_REFRESH_TOKEN",
|
|
352
|
-
"MANIFEST_PATH",
|
|
353
|
-
"VERCEL_API_TOKEN"
|
|
354
|
-
];
|
|
355
|
-
}
|
|
356
|
-
});
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/cli/index.ts
|
|
357
268
|
function run(version) {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
env.SLACK_APP_ID
|
|
385
|
-
)
|
|
386
|
-
);
|
|
387
|
-
const isLocal = !env.VERCEL_ENV;
|
|
388
|
-
const isDev = env.VERCEL_ENV === "development" || env.NODE_ENV === "development";
|
|
389
|
-
const isProd = env.VERCEL_ENV === "production";
|
|
390
|
-
if (isLocal || isDev || isProd) {
|
|
391
|
-
const reason = isLocal ? "local" : isDev ? "development" : "production";
|
|
392
|
-
chunkVI33CCYY_js.log.info(`Environment: ${reason} (skipped)
|
|
393
|
-
`);
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
const params = validateAndBuildParams(env);
|
|
397
|
-
await executeBuild(params, { cleanup });
|
|
398
|
-
});
|
|
399
|
-
program.parseAsync().catch((error) => {
|
|
400
|
-
chunkVI33CCYY_js.log.error(error instanceof Error ? error.message : String(error));
|
|
401
|
-
console.log();
|
|
402
|
-
});
|
|
269
|
+
const program = new commander.Command().name("vercel-slack").description("Build and configure Slack apps for Vercel preview deployments").version(version).option("--debug", "Enable verbose debug logging for all HTTP requests");
|
|
270
|
+
const cmd = program.command("build").description("Build and configure the Slack app for a Vercel preview deployment");
|
|
271
|
+
for (const key of ENV_KEYS) cmd.option(`--${envKeyToFlag(key)} <value>`, `Override ${key}`);
|
|
272
|
+
cmd.option("--cleanup", "Clean up Slack apps and env vars for inactive preview branches");
|
|
273
|
+
cmd.action(async (options) => {
|
|
274
|
+
if (program.opts().debug === true || process.env.VERCEL_SLACK_DEBUG === "1" || process.env.VERCEL_SLACK_DEBUG === "true") {
|
|
275
|
+
process.env.VERCEL_SLACK_DEBUG = "1";
|
|
276
|
+
require_preview.enableFetchDebugLogging();
|
|
277
|
+
}
|
|
278
|
+
const cleanup = options.cleanup === true;
|
|
279
|
+
const env = resolveEnv(options);
|
|
280
|
+
console.log(require_preview.startMessage(version, env.VERCEL_GIT_COMMIT_REF, env.VERCEL_GIT_COMMIT_SHA, env.SLACK_APP_ID));
|
|
281
|
+
const isLocal = !env.VERCEL_ENV;
|
|
282
|
+
const isDev = env.VERCEL_ENV === "development" || env.NODE_ENV === "development";
|
|
283
|
+
const isProd = env.VERCEL_ENV === "production";
|
|
284
|
+
if (isLocal || isDev || isProd) {
|
|
285
|
+
const reason = isLocal ? "local" : isDev ? "development" : "production";
|
|
286
|
+
require_preview.log.info(`Environment: ${reason} (skipped)\n`);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
await executeBuild(validateAndBuildParams(env), { cleanup });
|
|
290
|
+
});
|
|
291
|
+
program.parseAsync().catch((error) => {
|
|
292
|
+
require_preview.log.error(error instanceof Error ? error.message : String(error));
|
|
293
|
+
console.log();
|
|
294
|
+
});
|
|
403
295
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
yaml: "^2.8.2",
|
|
483
|
-
zod: "^4.3.6"
|
|
484
|
-
},
|
|
485
|
-
devDependencies: {
|
|
486
|
-
"@arethetypeswrong/cli": "^0.18.2",
|
|
487
|
-
"@biomejs/biome": "2.2.2",
|
|
488
|
-
"@types/node": "^20.19.35",
|
|
489
|
-
"@vitest/coverage-v8": "4.0.18",
|
|
490
|
-
tsup: "^8.5.1",
|
|
491
|
-
tsx: "^4.21.0",
|
|
492
|
-
typescript: "^5.9.3",
|
|
493
|
-
vitest: "^4.0.18"
|
|
494
|
-
},
|
|
495
|
-
peerDependencies: {
|
|
496
|
-
"@slack/bolt": "^4.4.0"
|
|
497
|
-
},
|
|
498
|
-
peerDependenciesMeta: {
|
|
499
|
-
"@slack/bolt": {
|
|
500
|
-
optional: false
|
|
501
|
-
}
|
|
502
|
-
},
|
|
503
|
-
engines: {
|
|
504
|
-
node: ">=20.0.0"
|
|
505
|
-
},
|
|
506
|
-
publishConfig: {
|
|
507
|
-
access: "public"
|
|
508
|
-
}
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
// src/cli.ts
|
|
514
|
-
var require_cli = chunkQHMZVK6J_js.__commonJS({
|
|
515
|
-
"src/cli.ts"() {
|
|
516
|
-
init_cli();
|
|
517
|
-
var { version } = require_package();
|
|
518
|
-
run(version);
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
var cli = require_cli();
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/cli.ts
|
|
298
|
+
const { version } = (/* @__PURE__ */ require_preview.__commonJSMin(((exports, module) => {
|
|
299
|
+
module.exports = {
|
|
300
|
+
"name": "@vercel/slack-bolt",
|
|
301
|
+
"version": "1.4.1",
|
|
302
|
+
"description": "A Vercel receiver for building Slack apps with Bolt and deploying them to Vercel",
|
|
303
|
+
"main": "./dist/index.js",
|
|
304
|
+
"types": "./dist/index.d.ts",
|
|
305
|
+
"type": "commonjs",
|
|
306
|
+
"bin": { "vercel-slack": "./bin/vercel-slack.js" },
|
|
307
|
+
"exports": {
|
|
308
|
+
".": {
|
|
309
|
+
"types": {
|
|
310
|
+
"import": "./dist/index.d.mts",
|
|
311
|
+
"require": "./dist/index.d.ts"
|
|
312
|
+
},
|
|
313
|
+
"import": "./dist/index.mjs",
|
|
314
|
+
"require": "./dist/index.js"
|
|
315
|
+
},
|
|
316
|
+
"./preview": {
|
|
317
|
+
"types": {
|
|
318
|
+
"import": "./dist/preview.d.mts",
|
|
319
|
+
"require": "./dist/preview.d.ts"
|
|
320
|
+
},
|
|
321
|
+
"import": "./dist/preview.mjs",
|
|
322
|
+
"require": "./dist/preview.js"
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
"typesVersions": { "*": { "preview": ["./dist/preview.d.ts"] } },
|
|
326
|
+
"files": ["bin", "dist"],
|
|
327
|
+
"repository": {
|
|
328
|
+
"type": "git",
|
|
329
|
+
"url": "https://github.com/vercel-labs/slack-bolt"
|
|
330
|
+
},
|
|
331
|
+
"bugs": { "url": "https://github.com/vercel-labs/slack-bolt/issues" },
|
|
332
|
+
"scripts": {
|
|
333
|
+
"build": "tsdown",
|
|
334
|
+
"dev": "tsdown --watch",
|
|
335
|
+
"test": "vitest run",
|
|
336
|
+
"test:watch": "vitest watch",
|
|
337
|
+
"lint": "biome check .",
|
|
338
|
+
"lint:fix": "biome check . --write",
|
|
339
|
+
"attw": "attw --pack ."
|
|
340
|
+
},
|
|
341
|
+
"keywords": [
|
|
342
|
+
"vercel",
|
|
343
|
+
"bolt",
|
|
344
|
+
"slack"
|
|
345
|
+
],
|
|
346
|
+
"author": "Vercel",
|
|
347
|
+
"license": "MIT",
|
|
348
|
+
"dependencies": {
|
|
349
|
+
"@slack/logger": "^4.0.1",
|
|
350
|
+
"@slack/oauth": "3.0.5",
|
|
351
|
+
"@vercel/functions": "^3.4.3",
|
|
352
|
+
"commander": "^14.0.3",
|
|
353
|
+
"yaml": "^2.8.3",
|
|
354
|
+
"zod": "^4.3.6"
|
|
355
|
+
},
|
|
356
|
+
"devDependencies": {
|
|
357
|
+
"@arethetypeswrong/cli": "^0.18.2",
|
|
358
|
+
"@biomejs/biome": "2.2.2",
|
|
359
|
+
"@types/node": "^20.19.35",
|
|
360
|
+
"@vitest/coverage-v8": "4.1.2",
|
|
361
|
+
"tsdown": "^0.21.7",
|
|
362
|
+
"tsx": "^4.21.0",
|
|
363
|
+
"typescript": "^5.9.3",
|
|
364
|
+
"vitest": "^4.1.2"
|
|
365
|
+
},
|
|
366
|
+
"peerDependencies": { "@slack/bolt": "^4.4.0" },
|
|
367
|
+
"peerDependenciesMeta": { "@slack/bolt": { "optional": false } },
|
|
368
|
+
"engines": { "node": ">=20.0.0" },
|
|
369
|
+
"publishConfig": { "access": "public" }
|
|
370
|
+
};
|
|
371
|
+
})))();
|
|
372
|
+
run(version);
|
|
373
|
+
//#endregion
|
|
522
374
|
|
|
523
|
-
module.exports = cli;
|
|
524
|
-
//# sourceMappingURL=cli.js.map
|
|
525
375
|
//# sourceMappingURL=cli.js.map
|