deepspace 0.5.7 → 0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # deepspace
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - `deepspace collaborators add <email>` can now invite someone who isn't a DeepSpace user yet: it sends them an email invitation (billed to the app owner) and they become a collaborator when they sign in and accept it. The new `deepspace collaborators cancel <email>` rescinds a pending invite, and `collaborators list` now shows outstanding invites alongside active collaborators.
8
+
9
+ ### Patch Changes
10
+
11
+ - `deepspace deploy` on a repo without `DEEPSPACE_APP_ID` no longer silently mints a fresh id destined for a route-claim collision when the name belongs to an existing app. Adoption now also recognizes legacy name-as-id apps the caller deploys on-behalf (collaborator or admin): adopting an app you own stays automatic; adopting one you _don't_ own asks for confirmation (or `--adopt` for non-interactive runs); a name owned by an app you can't deploy fails up front with the real reason.
12
+
3
13
  ## 0.5.7
4
14
 
5
15
  ### Patch Changes
package/dist/cli.js CHANGED
@@ -13,7 +13,9 @@ var API_ERROR_HINTS = {
13
13
  app_not_found: "App not found. Check the app id \u2014 the DEEPSPACE_APP_ID value in wrangler.toml, usually `app_\u2026` (a legacy app's id is its name). List your apps with `deepspace apps`. (`domain` commands take the deployed app *name* instead.)",
14
14
  not_app_owner_or_collaborator: "You must be the app owner or a collaborator to do this.",
15
15
  test_account_cannot_be_collaborator: "Test accounts cannot be added as collaborators. Use a real DeepSpace account.",
16
- user_not_found: "No DeepSpace user with that email. They need to log in to DeepSpace at least once (`deepspace login`, or sign in to any app) before they can be referenced by email."
16
+ user_not_found: "No DeepSpace user with that email. They need to log in to DeepSpace at least once (`deepspace login`, or sign in to any app) before they can be referenced by email.",
17
+ insufficient_credits: "Out of credits. Inviting a new collaborator by email sends them a transactional email billed to your account \u2014 top up your credits and try again.",
18
+ invite_email_failed: "The invite email could not be sent. You were not charged \u2014 please try again in a moment."
17
19
  };
18
20
  function formatCliError(err) {
19
21
  const message = err instanceof Error ? err.message : String(err);
@@ -555,18 +557,27 @@ function mintAppId(now = Date.now()) {
555
557
  }
556
558
  return `app_${ts}${rs}`.slice(0, 30);
557
559
  }
558
- async function resolveOwnedAppId(deployUrl, token, appName) {
560
+ async function resolveExistingAppId(deployUrl, token, appName) {
561
+ const headers = { Authorization: `Bearer ${token}` };
559
562
  try {
560
- const res = await fetch(`${deployUrl}/api/apps`, {
561
- headers: { Authorization: `Bearer ${token}` }
562
- });
563
- if (!res.ok) return null;
564
- const body = await res.json();
565
- const match = body.apps?.find((a) => a.name === appName);
566
- return match?.appId ?? null;
563
+ const res = await fetch(`${deployUrl}/api/apps`, { headers });
564
+ if (res.ok) {
565
+ const body = await res.json();
566
+ const match = body.apps?.find((a) => a.name === appName);
567
+ if (match?.appId) return { kind: "adopted", appId: match.appId, owned: true };
568
+ }
569
+ } catch {
570
+ }
571
+ try {
572
+ const res = await fetch(
573
+ `${deployUrl}/api/apps/${encodeURIComponent(appName)}/analytics?period=1h`,
574
+ { headers }
575
+ );
576
+ if (res.ok) return { kind: "adopted", appId: appName, owned: false };
577
+ if (res.status === 403) return { kind: "taken" };
567
578
  } catch {
568
- return null;
569
579
  }
580
+ return { kind: "none" };
570
581
  }
571
582
  function readAppId(cwd = process.cwd(), wranglerEnv) {
572
583
  const wranglerPath = join(resolve(cwd), "wrangler.toml");
@@ -2893,6 +2904,11 @@ var deploy_default = defineCommand8({
2893
2904
  type: "boolean",
2894
2905
  description: "Deploy even though hand-edited .dev.vars secrets are absent from the store (they will NOT be deployed, and any a previous deploy set are dropped).",
2895
2906
  default: false
2907
+ },
2908
+ adopt: {
2909
+ type: "boolean",
2910
+ description: "Confirm adopting an existing app you can deploy but do not own (collaborator/admin on-behalf) when wrangler.toml has no DEEPSPACE_APP_ID. Without this flag an interactive prompt asks.",
2911
+ default: false
2896
2912
  }
2897
2913
  },
2898
2914
  async run({ args }) {
@@ -2932,11 +2948,32 @@ var deploy_default = defineCommand8({
2932
2948
  process.exit(1);
2933
2949
  }
2934
2950
  if (!appId) {
2935
- const adopted = await resolveOwnedAppId(DEPLOY_URL3, token, appName);
2936
- appId = adopted ?? mintAppId();
2951
+ const existing = await resolveExistingAppId(DEPLOY_URL3, token, appName);
2952
+ if (existing.kind === "taken") {
2953
+ p4.cancel(
2954
+ `"${appName}" is taken by an app you don't have deploy access to. Ask the owner to add you as a collaborator (\`deepspace collaborators add\`), or pick a different \`name\` in wrangler.toml.`
2955
+ );
2956
+ process.exit(1);
2957
+ }
2958
+ if (existing.kind === "adopted" && !existing.owned && !args.adopt) {
2959
+ if (!process.stdin.isTTY) {
2960
+ p4.cancel(
2961
+ `"${appName}" is an existing app owned by another account that you can deploy on-behalf (collaborator/admin). Confirmation needs an interactive terminal \u2014 re-run with --adopt to deploy it, or pick a different \`name\` in wrangler.toml if you meant a new app.`
2962
+ );
2963
+ process.exit(1);
2964
+ }
2965
+ const yes = await p4.confirm({
2966
+ message: `"${appName}" is an existing app owned by another account that you can deploy on-behalf (you are a collaborator or admin). Deploy it? (Meant a new app? Pick a different \`name\` in wrangler.toml.)`
2967
+ });
2968
+ if (p4.isCancel(yes) || !yes) {
2969
+ p4.cancel("Deploy cancelled.");
2970
+ process.exit(1);
2971
+ }
2972
+ }
2973
+ appId = existing.kind === "adopted" ? existing.appId : mintAppId();
2937
2974
  writeAppId(appDir, appId, { wranglerEnv: envName });
2938
2975
  p4.log.info(
2939
- adopted ? `Adopted existing app id ${appId} for ${appName} \u2014 commit wrangler.toml.` : `Minted app id ${appId} \u2014 commit wrangler.toml.`
2976
+ existing.kind === "adopted" ? `Adopted existing app id ${appId} for ${appName} \u2014 commit wrangler.toml.` : `Minted app id ${appId} \u2014 commit wrangler.toml.`
2940
2977
  );
2941
2978
  }
2942
2979
  p4.log.info(`Id: ${appId}`);
@@ -4131,30 +4168,35 @@ var list3 = defineCommand14({
4131
4168
  async run({ args }) {
4132
4169
  const token = await ensureToken();
4133
4170
  const app = await resolveAppTarget(DEPLOY_URL6, token, args.app);
4134
- const { collaborators } = await api2(
4135
- token,
4136
- `/api/app-collaborators/${encodeURIComponent(app)}`
4137
- );
4171
+ const { collaborators, pending = [] } = await api2(token, `/api/app-collaborators/${encodeURIComponent(app)}`);
4138
4172
  if (args.json) {
4139
- process.stdout.write(JSON.stringify(collaborators, null, 2) + "\n");
4173
+ process.stdout.write(JSON.stringify({ collaborators, pending }, null, 2) + "\n");
4140
4174
  return;
4141
4175
  }
4142
- if (!collaborators.length) {
4176
+ if (!collaborators.length && !pending.length) {
4143
4177
  console.log(`No collaborators on ${app}. Add one with \`deepspace collaborators add <email>\`.`);
4144
4178
  return;
4145
4179
  }
4146
- console.log(`COLLABORATORS ON ${app}`);
4147
- for (const c of collaborators) {
4148
- console.log(` ${c.emailDisplay}`);
4180
+ if (collaborators.length) {
4181
+ console.log(`COLLABORATORS ON ${app}`);
4182
+ for (const c of collaborators) {
4183
+ console.log(` ${c.emailDisplay}`);
4184
+ }
4185
+ }
4186
+ if (pending.length) {
4187
+ console.log(`PENDING INVITES ON ${app}`);
4188
+ for (const p10 of pending) {
4189
+ console.log(` ${p10.email} (expires ${new Date(p10.expiresAt).toLocaleDateString()})`);
4190
+ }
4149
4191
  }
4150
4192
  }
4151
4193
  });
4152
4194
  var add = defineCommand14({
4153
- meta: { name: "add", description: "Authorize a DeepSpace user to deploy your app" },
4195
+ meta: { name: "add", description: "Authorize someone to deploy your app" },
4154
4196
  args: {
4155
4197
  email: {
4156
4198
  type: "positional",
4157
- description: "Collaborator email (must already be a DeepSpace user)",
4199
+ description: "Collaborator email",
4158
4200
  required: true
4159
4201
  },
4160
4202
  app: { type: "string", alias: "a", description: "App id or name (defaults to ./wrangler.toml)" },
@@ -4169,16 +4211,29 @@ var add = defineCommand14({
4169
4211
  );
4170
4212
  process.exit(1);
4171
4213
  }
4172
- const { collaborator } = await api2(
4214
+ const res = await api2(
4173
4215
  token,
4174
4216
  `/api/app-collaborators/${encodeURIComponent(app)}`,
4175
4217
  { method: "POST", body: JSON.stringify({ email: args.email }) }
4176
4218
  );
4177
4219
  if (args.json) {
4178
- process.stdout.write(JSON.stringify(collaborator, null, 2) + "\n");
4220
+ process.stdout.write(JSON.stringify(res, null, 2) + "\n");
4221
+ return;
4222
+ }
4223
+ if (res.status === "invited" || res.status === "already_invited") {
4224
+ const expires = new Date(res.expiresAt).toLocaleDateString();
4225
+ if (res.status === "already_invited") {
4226
+ console.log(
4227
+ `\u2022 ${res.email} already has a pending invite (expires ${expires}). No new email was sent. Cancel it with \`deepspace collaborators cancel ${res.email}\` to reset.`
4228
+ );
4229
+ return;
4230
+ }
4231
+ console.log(
4232
+ `\u2713 Invite sent to ${res.email} (expires ${expires}). They become a collaborator when they sign in.`
4233
+ );
4179
4234
  return;
4180
4235
  }
4181
- console.log(`\u2713 ${collaborator.emailDisplay} can now deploy ${app}`);
4236
+ console.log(`\u2713 ${res.collaborator.emailDisplay} can now deploy ${app}`);
4182
4237
  }
4183
4238
  });
4184
4239
  var remove = defineCommand14({
@@ -4213,9 +4268,41 @@ var remove = defineCommand14({
4213
4268
  console.log(`\u2713 ${found.emailDisplay} can no longer deploy ${app}`);
4214
4269
  }
4215
4270
  });
4271
+ var cancel4 = defineCommand14({
4272
+ meta: { name: "cancel", description: "Cancel a pending (un-accepted) email invite" },
4273
+ args: {
4274
+ email: { type: "positional", description: "Invited email", required: true },
4275
+ app: { type: "string", alias: "a", description: "App id or name (defaults to ./wrangler.toml)" },
4276
+ json: { type: "boolean", description: "Emit JSON" }
4277
+ },
4278
+ async run({ args }) {
4279
+ const token = await ensureToken();
4280
+ const app = await resolveAppTarget(DEPLOY_URL6, token, args.app);
4281
+ const { pending = [] } = await api2(
4282
+ token,
4283
+ `/api/app-collaborators/${encodeURIComponent(app)}`
4284
+ );
4285
+ const target = args.email.trim().toLowerCase();
4286
+ const found = pending.find((p10) => p10.email.toLowerCase() === target);
4287
+ if (!found) {
4288
+ console.error(`${args.email} has no pending invite on ${app}`);
4289
+ process.exit(1);
4290
+ }
4291
+ await api2(
4292
+ token,
4293
+ `/api/app-collaborators/${encodeURIComponent(app)}/pending/${encodeURIComponent(found.email)}`,
4294
+ { method: "DELETE" }
4295
+ );
4296
+ if (args.json) {
4297
+ process.stdout.write(JSON.stringify({ cancelled: found }, null, 2) + "\n");
4298
+ return;
4299
+ }
4300
+ console.log(`\u2713 Cancelled the pending invite to ${found.email} on ${app}`);
4301
+ }
4302
+ });
4216
4303
  var collaborators_default = defineCommand14({
4217
4304
  meta: { name: "collaborators", description: "Manage who can deploy your app" },
4218
- subCommands: { list: list3, add, remove }
4305
+ subCommands: { list: list3, add, remove, cancel: cancel4 }
4219
4306
  });
4220
4307
 
4221
4308
  // src/cli/commands/transfer.ts
@@ -4304,7 +4391,7 @@ var accept = defineCommand15({
4304
4391
  );
4305
4392
  }
4306
4393
  });
4307
- var cancel4 = defineCommand15({
4394
+ var cancel5 = defineCommand15({
4308
4395
  meta: { name: "cancel", description: "Cancel/decline the pending offer (either party)" },
4309
4396
  args: {
4310
4397
  app: { type: "string", alias: "a", description: "App id or name (defaults to ./wrangler.toml)" }
@@ -4318,7 +4405,7 @@ var cancel4 = defineCommand15({
4318
4405
  });
4319
4406
  var transfer_default = defineCommand15({
4320
4407
  meta: { name: "transfer", description: "Transfer app ownership to another user" },
4321
- subCommands: { offer, status: status2, accept, cancel: cancel4 }
4408
+ subCommands: { offer, status: status2, accept, cancel: cancel5 }
4322
4409
  });
4323
4410
 
4324
4411
  // src/cli/commands/integrations.ts