@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/dist/cli.js CHANGED
@@ -1,525 +1,375 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
3
-
4
- var chunkVI33CCYY_js = require('./chunk-VI33CCYY.js');
5
- var chunkQHMZVK6J_js = require('./chunk-QHMZVK6J.js');
6
- var zod = require('zod');
7
- var fs = require('fs');
8
- var path = require('path');
9
- var commander = require('commander');
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
- return error.issues.map((i) => i.path.join(".")).join(", ");
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
- const systemResult = systemEnvSchema.safeParse(env);
21
- if (!systemResult.success) {
22
- const missing = formatMissingKeys(systemResult.error);
23
- throw new Error(
24
- `Missing Vercel system environment variables: ${missing}
25
- Enable 'Automatically expose System Environment Variables' in your Vercel project settings:
26
- https://vercel.com/docs/projects/environment-variables/system-environment-variables`
27
- );
28
- }
29
- const slackResult = slackEnvSchema.safeParse(env);
30
- if (!slackResult.success) {
31
- const missing = formatMissingKeys(slackResult.error);
32
- throw new Error(
33
- `Missing Slack environment variables: ${missing}
34
- Add them as environment variables in your Vercel project.`
35
- );
36
- }
37
- const vercelResult = vercelEnvSchema.safeParse(env);
38
- if (!vercelResult.success) {
39
- const missing = formatMissingKeys(vercelResult.error);
40
- throw new Error(
41
- `Missing Vercel environment variables: ${missing}
42
- Create a new token and add it as VERCEL_API_TOKEN in your Vercel project:
43
- https://vercel.com/account/settings/tokens`
44
- );
45
- }
46
- return {
47
- branch: systemResult.data.VERCEL_GIT_COMMIT_REF,
48
- projectId: systemResult.data.VERCEL_PROJECT_ID,
49
- deploymentUrl: systemResult.data.VERCEL_URL,
50
- branchUrl: systemResult.data.VERCEL_BRANCH_URL,
51
- teamId: systemResult.data.VERCEL_TEAM_ID,
52
- commitSha: systemResult.data.VERCEL_GIT_COMMIT_SHA,
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
- var systemEnvSchema, slackEnvSchema, vercelEnvSchema;
66
- var init_schemas = chunkQHMZVK6J_js.__esm({
67
- "src/internal/schemas.ts"() {
68
- systemEnvSchema = zod.z.object({
69
- VERCEL_ENV: zod.z.enum(["production", "preview", "development"]),
70
- VERCEL_GIT_COMMIT_REF: zod.z.string(),
71
- VERCEL_PROJECT_ID: zod.z.string(),
72
- VERCEL_URL: zod.z.string(),
73
- VERCEL_BRANCH_URL: zod.z.string().optional(),
74
- VERCEL_TEAM_ID: zod.z.string().optional(),
75
- VERCEL_GIT_COMMIT_SHA: zod.z.string().optional(),
76
- VERCEL_GIT_COMMIT_MESSAGE: zod.z.string().optional(),
77
- VERCEL_GIT_COMMIT_AUTHOR_LOGIN: zod.z.string().optional(),
78
- VERCEL_DEPLOYMENT_ID: zod.z.string().optional(),
79
- VERCEL_AUTOMATION_BYPASS_SECRET: zod.z.string().optional()
80
- });
81
- slackEnvSchema = zod.z.object({
82
- SLACK_APP_ID: zod.z.string().optional(),
83
- SLACK_CONFIGURATION_TOKEN: zod.z.string(),
84
- SLACK_SERVICE_TOKEN: zod.z.string().optional(),
85
- SLACK_CONFIG_REFRESH_TOKEN: zod.z.string().optional(),
86
- MANIFEST_PATH: zod.z.string().default("manifest.json")
87
- });
88
- vercelEnvSchema = zod.z.object({
89
- VERCEL_API_TOKEN: zod.z.string()
90
- });
91
- }
92
- });
93
-
94
- // src/cleanup.ts
95
- async function cleanupOrphanedApps({
96
- projectId,
97
- currentBranch,
98
- vercelApiToken,
99
- teamId,
100
- slackConfigurationToken
101
- }) {
102
- const activeBranches = await chunkVI33CCYY_js.getActiveBranches({
103
- projectId,
104
- token: vercelApiToken,
105
- teamId
106
- });
107
- const envs = await chunkVI33CCYY_js.getEnvironmentVariables({
108
- projectId,
109
- token: vercelApiToken,
110
- teamId
111
- });
112
- const staleBranches = /* @__PURE__ */ new Map();
113
- for (const env of envs) {
114
- if (env.key === "SLACK_APP_ID" && env.gitBranch && env.gitBranch !== currentBranch && !activeBranches.has(env.gitBranch)) {
115
- staleBranches.set(env.gitBranch, env.id);
116
- }
117
- }
118
- if (staleBranches.size === 0) {
119
- chunkVI33CCYY_js.log.info("No orphaned preview apps found");
120
- return;
121
- }
122
- chunkVI33CCYY_js.log.step(
123
- `Found ${staleBranches.size} orphaned ${staleBranches.size === 1 ? "branch" : "branches"}`
124
- );
125
- for (const [branch, envId] of staleBranches) {
126
- let appId = null;
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
- var SLACK_ENV_VAR_KEYS;
173
- var init_cleanup = chunkQHMZVK6J_js.__esm({
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
- if (!params.slackConfigurationToken) {
189
- throw new Error(
190
- "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"
191
- );
192
- }
193
- try {
194
- await chunkVI33CCYY_js.authTest({ token: params.slackConfigurationToken });
195
- } catch (error) {
196
- if (!params.slackConfigRefreshToken) {
197
- throw new Error(
198
- "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",
199
- { cause: error }
200
- );
201
- }
202
- chunkVI33CCYY_js.log.step("Refreshing SLACK_CONFIGURATION_TOKEN");
203
- try {
204
- const rotated = await chunkVI33CCYY_js.rotateConfigToken({
205
- refreshToken: params.slackConfigRefreshToken
206
- });
207
- params.slackConfigurationToken = rotated.token;
208
- params.slackConfigRefreshToken = rotated.refreshToken;
209
- await chunkVI33CCYY_js.addEnvironmentVariables({
210
- projectId: params.projectId,
211
- token: params.vercelApiToken,
212
- teamId: params.teamId,
213
- envs: [
214
- {
215
- key: "SLACK_CONFIGURATION_TOKEN",
216
- value: rotated.token,
217
- type: "encrypted",
218
- target: ["production", "preview", "development"]
219
- },
220
- {
221
- key: "SLACK_CONFIG_REFRESH_TOKEN",
222
- value: rotated.refreshToken,
223
- type: "encrypted",
224
- target: ["production", "preview", "development"]
225
- }
226
- ]
227
- });
228
- chunkVI33CCYY_js.log.success("Configuration token rotated and persisted");
229
- } catch (rotateError) {
230
- throw new Error(
231
- "Failed to rotate configuration token \u2014 refresh token may be invalid. Generate new tokens:\nhttps://api.slack.com/apps",
232
- { cause: rotateError }
233
- );
234
- }
235
- }
236
- if (params.slackServiceToken) {
237
- try {
238
- await chunkVI33CCYY_js.authTest({ token: params.slackServiceToken });
239
- } catch (error) {
240
- chunkVI33CCYY_js.log.warning(
241
- "SLACK_SERVICE_TOKEN is invalid \u2014 app must be installed manually"
242
- );
243
- chunkVI33CCYY_js.log.info("https://docs.slack.dev/authentication/tokens/#service");
244
- chunkVI33CCYY_js.log.debug(error);
245
- }
246
- }
247
- if (!params.branch) {
248
- throw new Error(
249
- "VERCEL_GIT_COMMIT_REF is not set \u2014 connect your Git repository in your Vercel project settings.\nhttps://vercel.com/docs/git"
250
- );
251
- }
252
- try {
253
- await chunkVI33CCYY_js.getProject({
254
- projectId: params.projectId,
255
- token: params.vercelApiToken,
256
- teamId: params.teamId
257
- });
258
- } catch (error) {
259
- throw new Error(
260
- "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",
261
- { cause: error }
262
- );
263
- }
264
- const manifestFullPath = path__default.default.join(process.cwd(), params.manifestPath);
265
- if (!fs__default.default.existsSync(manifestFullPath)) {
266
- throw new Error(
267
- `No manifest found at ${params.manifestPath}. Create a manifest.json (or manifest.yaml) file with your Slack app configuration:
268
- https://docs.slack.dev/reference/manifests`
269
- );
270
- }
271
- if (options?.cleanup) {
272
- chunkVI33CCYY_js.log.step("Cleaning up orphaned preview apps");
273
- try {
274
- await cleanupOrphanedApps({
275
- projectId: params.projectId,
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
- var init_build = chunkQHMZVK6J_js.__esm({
306
- "src/cli/build.ts"() {
307
- init_cleanup();
308
- chunkVI33CCYY_js.init_slack();
309
- chunkVI33CCYY_js.init_vercel();
310
- chunkVI33CCYY_js.init_logger();
311
- chunkVI33CCYY_js.init_preview();
312
- }
313
- });
314
-
315
- // src/cli/env.ts
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
- return key.toLowerCase().replace(/_/g, "-");
250
+ return key.toLowerCase().replace(/_/g, "-");
318
251
  }
319
252
  function flagToCamelCase(flag) {
320
- return flag.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
253
+ return flag.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
321
254
  }
322
255
  function resolveEnv(options) {
323
- const overrides = {};
324
- for (const key of ENV_KEYS) {
325
- const camelKey = flagToCamelCase(envKeyToFlag(key));
326
- const value = options[camelKey];
327
- if (typeof value === "string") {
328
- overrides[key] = value;
329
- }
330
- }
331
- return { ...process.env, ...overrides };
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
- var ENV_KEYS;
334
- var init_env = chunkQHMZVK6J_js.__esm({
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
- const program = new commander.Command().name("vercel-slack").description(
359
- "Build and configure Slack apps for Vercel preview deployments"
360
- ).version(version).option("--debug", "Enable verbose debug logging for all HTTP requests");
361
- const cmd = program.command("build").description(
362
- "Build and configure the Slack app for a Vercel preview deployment"
363
- );
364
- for (const key of ENV_KEYS) {
365
- cmd.option(`--${envKeyToFlag(key)} <value>`, `Override ${key}`);
366
- }
367
- cmd.option(
368
- "--cleanup",
369
- "Clean up Slack apps and env vars for inactive preview branches"
370
- );
371
- cmd.action(async (options) => {
372
- const debug = program.opts().debug === true || process.env.VERCEL_SLACK_DEBUG === "1" || process.env.VERCEL_SLACK_DEBUG === "true";
373
- if (debug) {
374
- process.env.VERCEL_SLACK_DEBUG = "1";
375
- chunkVI33CCYY_js.enableFetchDebugLogging();
376
- }
377
- const cleanup = options.cleanup === true;
378
- const env = resolveEnv(options);
379
- console.log(
380
- chunkVI33CCYY_js.startMessage(
381
- version,
382
- env.VERCEL_GIT_COMMIT_REF,
383
- env.VERCEL_GIT_COMMIT_SHA,
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
- var init_cli = chunkQHMZVK6J_js.__esm({
405
- "src/cli/index.ts"() {
406
- init_schemas();
407
- chunkVI33CCYY_js.init_logger();
408
- init_build();
409
- init_env();
410
- }
411
- });
412
-
413
- // package.json
414
- var require_package = chunkQHMZVK6J_js.__commonJS({
415
- "package.json"(exports$1, module) {
416
- module.exports = {
417
- name: "@vercel/slack-bolt",
418
- version: "1.3.1",
419
- description: "A Vercel receiver for building Slack apps with Bolt and deploying them to Vercel",
420
- main: "./dist/index.js",
421
- types: "./dist/index.d.ts",
422
- type: "commonjs",
423
- bin: {
424
- "vercel-slack": "./bin/vercel-slack.js"
425
- },
426
- exports: {
427
- ".": {
428
- types: {
429
- import: "./dist/index.d.mts",
430
- require: "./dist/index.d.ts"
431
- },
432
- import: "./dist/index.mjs",
433
- require: "./dist/index.js"
434
- },
435
- "./preview": {
436
- types: {
437
- import: "./dist/preview.d.mts",
438
- require: "./dist/preview.d.ts"
439
- },
440
- import: "./dist/preview.mjs",
441
- require: "./dist/preview.js"
442
- }
443
- },
444
- typesVersions: {
445
- "*": {
446
- preview: [
447
- "./dist/preview.d.ts"
448
- ]
449
- }
450
- },
451
- files: [
452
- "bin",
453
- "dist"
454
- ],
455
- repository: {
456
- type: "git",
457
- url: "https://github.com/vercel-labs/slack-bolt"
458
- },
459
- bugs: {
460
- url: "https://github.com/vercel-labs/slack-bolt/issues"
461
- },
462
- scripts: {
463
- build: "tsup",
464
- dev: "tsup --watch",
465
- test: "vitest run",
466
- "test:watch": "vitest watch",
467
- lint: "biome check .",
468
- "lint:fix": "biome check . --write",
469
- attw: "attw --pack ."
470
- },
471
- keywords: [
472
- "vercel",
473
- "bolt",
474
- "slack"
475
- ],
476
- author: "Vercel",
477
- license: "MIT",
478
- dependencies: {
479
- "@slack/logger": "^4.0.0",
480
- "@vercel/functions": "^3.4.3",
481
- commander: "^14.0.3",
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