create-disposabl-app 0.6.4 → 0.6.6

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.
Files changed (20) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/templates/default/.github/scripts/android-build.sh +14 -5
  3. package/dist/templates/default/.github/scripts/disposabl.mjs +1 -1
  4. package/dist/templates/default/.github/scripts/expo-env.sh +17 -0
  5. package/dist/templates/default/.github/scripts/expo-fingerprint.sh +6 -3
  6. package/dist/templates/default/.github/scripts/expo-update.sh +4 -2
  7. package/dist/templates/default/.github/scripts/verify-artifacts.sh +1 -1
  8. package/dist/templates/default/apps/mobile/README.md +2 -0
  9. package/dist/templates/default/packages/backend/convex/_generated/api.d.ts +4 -0
  10. package/dist/templates/default/packages/backend/convex/_generated/server.d.ts +1 -0
  11. package/dist/templates/default/packages/backend/convex/apps/actions/create.ts +16 -3
  12. package/dist/templates/default/packages/backend/convex/apps/actions/setup.ts +34 -0
  13. package/dist/templates/default/packages/backend/convex/apps/internal.ts +20 -0
  14. package/dist/templates/default/packages/backend/convex/convex.config.ts +1 -0
  15. package/dist/templates/default/packages/backend/convex/github/actions/secrets.ts +101 -0
  16. package/dist/templates/default/packages/backend/convex/github/actions/tokens.ts +7 -2
  17. package/dist/templates/default/packages/backend/convex/previews/internal.ts +0 -13
  18. package/dist/templates/default/packages/backend/convex/previews/token/actions/create.ts +5 -21
  19. package/dist/templates/default/packages/backend/convex/previews/token/actions/management.ts +33 -0
  20. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import { fileURLToPath as fileURLToPath2 } from "node:url";
8
8
  import { Command, CommanderError } from "commander";
9
9
  import * as p2 from "@clack/prompts";
10
10
  // package.json
11
- var version = "0.6.4";
11
+ var version = "0.6.6";
12
12
 
13
13
  // ../disposabl-kit/platforms.ts
14
14
  var platforms = [
@@ -9,10 +9,19 @@ if [[ "$CHANNEL" == production ]]; then
9
9
  fi
10
10
  bun x --no-install expo prebuild --platform android --no-install
11
11
  test "$(bun x --no-install expo-updates runtimeversion:resolve --platform android --workflow managed | jq -er .runtimeVersion)" = "$RUNTIME"
12
- (cd android && ./gradlew :app:assembleRelease --no-daemon --build-cache)
13
- apk=android/app/build/outputs/apk/release/app-release.apk
14
- test "$(unzip -p "$apk" assets/fingerprint)" = "$RUNTIME"
12
+ task=assembleRelease
13
+ artifact=android.apk
14
+ binary=android/app/build/outputs/apk/release/app-release.apk
15
+ fingerprint=assets/fingerprint
16
+ if [[ "$CHANNEL" == production ]]; then
17
+ task=bundleRelease
18
+ artifact=android.aab
19
+ binary=android/app/build/outputs/bundle/release/app-release.aab
20
+ fingerprint=base/assets/fingerprint
21
+ fi
22
+ (cd android && ./gradlew ":app:$task" --no-daemon --build-cache)
23
+ test "$(unzip -p "$binary" "$fingerprint")" = "$RUNTIME"
15
24
  test "$(bun x --no-install expo-updates runtimeversion:resolve --platform android --workflow managed | jq -er .runtimeVersion)" = "$RUNTIME"
16
25
  mkdir -p ../../dist/release
17
- cp "$apk" ../../dist/release/android.apk
18
- jq --arg sha "$(sha256sum "$apk" | cut -d' ' -f1)" '. + {sha256: $sha, action: "build"}' <<< "$MANIFEST" > ../../dist/release/android.json
26
+ cp "$binary" "../../dist/release/$artifact"
27
+ jq --arg sha "$(sha256sum "$binary" | cut -d' ' -f1)" '. + {sha256: $sha, action: "build"}' <<< "$MANIFEST" > ../../dist/release/android.json
@@ -74,7 +74,7 @@ if (config.appId) {
74
74
  process.exit(0);
75
75
  }
76
76
  const suffix = {
77
- android: ".apk",
77
+ android: process.env.CHANNEL === "production" ? ".aab" : ".apk",
78
78
  ios: ".ipa",
79
79
  macos: ".dmg",
80
80
  windows: ".exe",
@@ -1,5 +1,22 @@
1
1
  #!/usr/bin/env bash
2
2
  set -euo pipefail
3
+ if [[ -z "$EXPO_PROJECT_ID" ]]; then
4
+ # Initialize with static config; app.config.js reads the resulting environment.
5
+ mkdir -p "$RUNNER_TEMP/expo-project"
6
+ jq --slurpfile app ../../disposabl.json --arg owner "${EXPO_OWNER:-}" '
7
+ {expo: {name: .expo.name, slug: (if $app[0].appId then "app-" + $app[0].appId else .expo.slug end)}}
8
+ | if $owner != "" then .expo.owner = $owner else . end
9
+ ' app.json > "$RUNNER_TEMP/expo-project/app.json"
10
+ printf '{"name":"expo-project","private":true}\n' > "$RUNNER_TEMP/expo-project/package.json"
11
+ account=()
12
+ [[ -z "${EXPO_OWNER:-}" ]] || account=(--account "$EXPO_OWNER")
13
+ (cd "$RUNNER_TEMP/expo-project" && bun x "$EAS_CLI" init --force --non-interactive --json --no-icon "${account[@]}") > "$RUNNER_TEMP/expo-project.json"
14
+ EXPO_PROJECT_ID=$(jq -er .projectId "$RUNNER_TEMP/expo-project.json")
15
+ EXPO_OWNER=$(jq -er .owner "$RUNNER_TEMP/expo-project.json")
16
+ EXPO_SLUG=$(jq -er .slug "$RUNNER_TEMP/expo-project.json")
17
+ export EXPO_PROJECT_ID EXPO_OWNER EXPO_SLUG
18
+ printf 'EXPO_PROJECT_ID=%s\nEXPO_OWNER=%s\nEXPO_SLUG=%s\n' "$EXPO_PROJECT_ID" "$EXPO_OWNER" "$EXPO_SLUG" >> "$GITHUB_ENV"
19
+ fi
3
20
  jq --arg channel "$CHANNEL" '.build["ios-" + env.EAS_ENVIRONMENT].channel = $channel' eas.json > "$RUNNER_TEMP/eas.json"
4
21
  mv "$RUNNER_TEMP/eas.json" eas.json
5
22
  bun x "$EAS_CLI" env:pull --environment "$EAS_ENVIRONMENT" --path "$RUNNER_TEMP/expo.env" --non-interactive
@@ -1,8 +1,11 @@
1
1
  #!/usr/bin/env bash
2
2
  set -euo pipefail
3
+ artifact=android.apk
4
+ [[ "$CHANNEL" != production ]] || artifact=android.aab
5
+ export artifact
3
6
  for ((page=1; ; page++)); do
4
7
  gh api "repos/$GH_REPO/releases?per_page=100&page=$page" > "$RUNNER_TEMP/releases.json"
5
- jq --arg tag "$RELEASE_PREFIX-$CHANNEL-android" --arg legacy "$RELEASE_PREFIX-$CHANNEL" '[.[] | select(.draft | not) | select(.tag_name == $tag or .tag_name == $legacy or (.tag_name | startswith($legacy + "-"))) | select(any(.assets[]; .name == "android.apk"))] | sort_by(.tag_name != $tag, .tag_name != $legacy) | .[0] // {}' "$RUNNER_TEMP/releases.json" > "$RUNNER_TEMP/release.json"
8
+ jq --arg artifact "$artifact" --arg tag "$RELEASE_PREFIX-$CHANNEL-android" --arg legacy "$RELEASE_PREFIX-$CHANNEL" '[.[] | select(.draft | not) | select(.tag_name == $tag or .tag_name == $legacy or (.tag_name | startswith($legacy + "-"))) | select(any(.assets[]; .name == $artifact))] | sort_by(.tag_name != $tag, .tag_name != $legacy) | .[0] // {}' "$RUNNER_TEMP/releases.json" > "$RUNNER_TEMP/release.json"
6
9
  if jq -e '.id' "$RUNNER_TEMP/release.json" > /dev/null || [[ $(jq length "$RUNNER_TEMP/releases.json") -lt 100 ]]; then break; fi
7
10
  done
8
11
  bun x --no-install expo config --json > "$RUNNER_TEMP/mobile.json"
@@ -14,10 +17,10 @@ bun -e '
14
17
  const wanted = {channel: process.env.CHANNEL, projectId: config.extra.eas.projectId, applicationId: config.android.package, runtimeVersion: process.env.RUNTIME};
15
18
  const release = await Bun.file(`${process.env.RUNNER_TEMP}/release.json`).json();
16
19
  const prior = JSON.parse(/<!-- android (\{[^\n]+\}) -->/.exec(release.body || "")?.[1] || "null");
17
- const reusable = prior && Object.keys(wanted).every(k => prior[k] === wanted[k]) && /^[a-f0-9]{64}$/.test(prior.sha256 || "") && release.assets.some(a => a.name === "android.apk" && a.state === "uploaded" && a.size > 0 && a.digest === `sha256:${prior.sha256}`);
20
+ const reusable = prior && Object.keys(wanted).every(k => prior[k] === wanted[k]) && /^[a-f0-9]{64}$/.test(prior.sha256 || "") && release.assets.some(a => a.name === process.env.artifact && a.state === "uploaded" && a.size > 0 && a.digest === `sha256:${prior.sha256}`);
18
21
  const blocked = !reusable && process.env.CHANNEL === "production" && process.env.ANDROID_SIGNING_READY !== "true";
19
22
  if (blocked) {
20
- const reason = "Configure Android production signing credentials before building an APK.";
23
+ const reason = "Configure Android production signing credentials before building an AAB.";
21
24
  console.error(`::notice::${reason}`);
22
25
  const report = Bun.spawnSync(["node", ".github/scripts/disposabl.mjs", "report", "android", "blocked", reason], {
23
26
  cwd: process.env.GITHUB_WORKSPACE, stdout: "inherit", stderr: "inherit",
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env bash
2
2
  set -euo pipefail
3
+ artifact=android.apk
4
+ [[ "$CHANNEL" != production ]] || artifact=android.aab
3
5
  mkdir -p dist/release
4
- gh release download "$TAG" --pattern android.apk --dir dist/release
5
- echo "$SHA dist/release/android.apk" | sha256sum --check
6
+ gh release download "$TAG" --pattern "$artifact" --dir dist/release
7
+ echo "$SHA dist/release/$artifact" | sha256sum --check
6
8
  cd apps/mobile
7
9
  bun x --no-install expo export --platform android --output-dir dist/update
8
10
  test "$(bun x --no-install expo-updates runtimeversion:resolve --platform android --workflow managed | jq -er .runtimeVersion)" = "$RUNTIME"
@@ -4,7 +4,7 @@ check_source() { test "$(gh api "repos/$GH_REPO/$SOURCE_PATH" --jq 'if has("head
4
4
  check_source
5
5
  for file in dist/release/*; do test -f "$file"; test -s "$file"; done
6
6
  case "$PLATFORM" in
7
- android) test -s dist/release/android.apk; test -s dist/release/android.json ;;
7
+ android) artifact=android.apk; [[ "$CHANNEL" != production ]] || artifact=android.aab; test -s "dist/release/$artifact"; test -s dist/release/android.json ;;
8
8
  ios) test -s dist/release/ios.ipa; test -s dist/release/ios.json ;;
9
9
  linux) compgen -G 'dist/release/*.deb' > /dev/null; compgen -G 'dist/release/*.rpm' > /dev/null ;;
10
10
  windows) compgen -G 'dist/release/*.exe' > /dev/null; compgen -G 'dist/release/*.nupkg' > /dev/null; test -s dist/release/RELEASES ;;
@@ -185,3 +185,5 @@ CI uses the project's EAS ad hoc credentials automatically. Missing or invalid
185
185
  credentials fail the iOS build instead of silently skipping it.
186
186
  It does not require TestFlight or an App Store Connect app record. TestFlight is
187
187
  a separate distribution option. The pipeline never submits to the App Store.
188
+
189
+ Android preview builds produce an installable APK. Production builds produce an AAB for Google Play. GitHub Actions builds and publishes these files; Expo hosts compatible EAS Updates.
@@ -9,12 +9,14 @@
9
9
  */
10
10
 
11
11
  import type * as apps_actions_create from "../apps/actions/create.js";
12
+ import type * as apps_actions_setup from "../apps/actions/setup.js";
12
13
  import type * as apps_internal from "../apps/internal.js";
13
14
  import type * as auth from "../auth.js";
14
15
  import type * as github_actions_http from "../github/actions/http.js";
15
16
  import type * as github_actions_internal from "../github/actions/internal.js";
16
17
  import type * as github_actions_oidc from "../github/actions/oidc.js";
17
18
  import type * as github_actions_provision from "../github/actions/provision.js";
19
+ import type * as github_actions_secrets from "../github/actions/secrets.js";
18
20
  import type * as github_actions_tokens from "../github/actions/tokens.js";
19
21
  import type * as github_internal from "../github/internal.js";
20
22
  import type * as http from "../http.js";
@@ -36,12 +38,14 @@ import type {
36
38
 
37
39
  declare const fullApi: ApiFromModules<{
38
40
  "apps/actions/create": typeof apps_actions_create;
41
+ "apps/actions/setup": typeof apps_actions_setup;
39
42
  "apps/internal": typeof apps_internal;
40
43
  auth: typeof auth;
41
44
  "github/actions/http": typeof github_actions_http;
42
45
  "github/actions/internal": typeof github_actions_internal;
43
46
  "github/actions/oidc": typeof github_actions_oidc;
44
47
  "github/actions/provision": typeof github_actions_provision;
48
+ "github/actions/secrets": typeof github_actions_secrets;
45
49
  "github/actions/tokens": typeof github_actions_tokens;
46
50
  "github/internal": typeof github_internal;
47
51
  http: typeof http;
@@ -34,6 +34,7 @@ type Env = {
34
34
  readonly AUTH_PRIVATE_KEY: string;
35
35
  readonly CONVEX_TEAM_ID: string | undefined;
36
36
  readonly CONVEX_TEAM_TOKEN: string | undefined;
37
+ readonly EXPO_TOKEN: string | undefined;
37
38
  readonly GITHUB_CONNECTOR: string | undefined;
38
39
  readonly GITHUB_INSTALLATION_ID: string | undefined;
39
40
  readonly GITHUB_OWNER: string | undefined;
@@ -4,6 +4,7 @@ import {
4
4
  } from "@disposabl/disposabl-kit/server/lib/functions";
5
5
  import { internal } from "../../_generated/api";
6
6
  import { appArgs, appResult } from "../../validator";
7
+ import { env } from "../../_generated/server";
7
8
  import type { Infer } from "convex/values";
8
9
  type AppResult = Infer<typeof appResult>;
9
10
 
@@ -11,9 +12,21 @@ export const create = internalAction({
11
12
  platforms: true,
12
13
  args: { ...identityFields, ...appArgs },
13
14
  returns: appResult,
14
- handler: async (ctx, args): Promise<AppResult> =>
15
- ctx.runMutation(internal.apps.internal.insert, {
15
+ handler: async (ctx, args): Promise<AppResult> => {
16
+ const app = await ctx.runMutation(internal.apps.internal.insert, {
16
17
  ...args,
17
18
  appId: crypto.randomUUID(),
18
- }),
19
+ });
20
+ if (env.CONVEX_TEAM_TOKEN) {
21
+ await ctx.runAction(internal.apps.actions.setup.setup, {
22
+ userId: args.userId,
23
+ appId: app.appId,
24
+ });
25
+ return ctx.runQuery(internal.apps.internal.get, {
26
+ userId: args.userId,
27
+ appId: app.appId,
28
+ });
29
+ }
30
+ return app;
31
+ },
19
32
  });
@@ -0,0 +1,34 @@
1
+ import {
2
+ identityFields,
3
+ internalAction,
4
+ } from "@disposabl/disposabl-kit/server/lib/functions";
5
+ import { v } from "convex/values";
6
+ import { internal } from "../../_generated/api";
7
+ import { env } from "../../_generated/server";
8
+ import { ensureProject } from "../../previews/token/actions/management";
9
+
10
+ export const setup = internalAction({
11
+ args: { ...identityFields, appId: v.string() },
12
+ returns: v.number(),
13
+ handler: async (ctx, args): Promise<number> => {
14
+ const saved = await ctx.runQuery(internal.apps.internal.project, args);
15
+ const token = env.CONVEX_TEAM_TOKEN;
16
+ const teamId = env.CONVEX_TEAM_ID;
17
+ if (!token || !teamId || !/^\d+$/.test(teamId))
18
+ throw new Error(
19
+ "Managed setup requires CONVEX_TEAM_ID and CONVEX_TEAM_TOKEN on the service backend.",
20
+ );
21
+ const projectId = saved ?? (await ensureProject(token, teamId, args.appId));
22
+ if (saved === null)
23
+ await ctx.runMutation(internal.apps.internal.saveProject, {
24
+ ...args,
25
+ projectId,
26
+ });
27
+ await ctx.runAction(internal.github.actions.provision.run, args);
28
+ await ctx.runAction(internal.github.actions.secrets.configure, {
29
+ ...args,
30
+ projectId,
31
+ });
32
+ return projectId;
33
+ },
34
+ });
@@ -195,3 +195,23 @@ export const githubSetup = internalQuery({
195
195
  };
196
196
  },
197
197
  });
198
+
199
+ export const project = internalQuery({
200
+ args: { ...identityFields, appId: v.string() },
201
+ returns: v.union(v.number(), v.null()),
202
+ handler: async (ctx, { userId, appId }) =>
203
+ (await ownedApp(ctx, userId, appId)).convexProjectId ?? null,
204
+ });
205
+ export const saveProject = internalMutation({
206
+ args: {
207
+ ...identityFields,
208
+ appId: v.string(),
209
+ projectId: v.number(),
210
+ },
211
+ returns: v.null(),
212
+ handler: async (ctx, args) => {
213
+ const app = await ownedApp(ctx, args.userId, args.appId);
214
+ await ctx.db.patch("apps", app._id, { convexProjectId: args.projectId });
215
+ return null;
216
+ },
217
+ });
@@ -18,6 +18,7 @@ const app = defineApp({
18
18
  VERCEL_TEAM_ID: v.optional(v.string()),
19
19
  GITHUB_CONNECTOR: v.optional(v.string()),
20
20
  GITHUB_OWNER: v.optional(v.string()),
21
+ EXPO_TOKEN: v.optional(v.string()),
21
22
  GITHUB_INSTALLATION_ID: v.optional(v.string()),
22
23
  },
23
24
  });
@@ -0,0 +1,101 @@
1
+ "use node";
2
+
3
+ import sodium from "libsodium-wrappers";
4
+ import {
5
+ identityFields,
6
+ internalAction,
7
+ } from "@disposabl/disposabl-kit/server/lib/functions";
8
+ import { v } from "convex/values";
9
+ import { internal } from "../../_generated/api";
10
+ import { env } from "../../_generated/server";
11
+ import {
12
+ management,
13
+ ensureProduction,
14
+ } from "../../previews/token/actions/management";
15
+ import { githubRequest, githubToken } from "./tokens";
16
+
17
+ export const configure = internalAction({
18
+ args: { ...identityFields, appId: v.string(), projectId: v.number() },
19
+ returns: v.null(),
20
+ handler: async (ctx, args) => {
21
+ await ctx.runQuery(internal.apps.internal.get, {
22
+ userId: args.userId,
23
+ appId: args.appId,
24
+ });
25
+ const app = await ctx.runQuery(internal.apps.internal.githubApp, {
26
+ appId: args.appId,
27
+ });
28
+ if (!app) return null;
29
+ const repository = `${app.githubOwner}/${app.githubRepo}`;
30
+ const token = await githubToken(
31
+ app.installationId,
32
+ ["secrets:write"],
33
+ repository,
34
+ );
35
+ const path = `/repos/${repository}/actions/secrets`;
36
+ const existing = await githubRequest<{ secrets: { name: string }[] }>(
37
+ token,
38
+ `${path}?per_page=100`,
39
+ );
40
+ const names = new Set(existing.secrets.map((secret) => secret.name));
41
+ const publicKey = await githubRequest<{ key_id: string; key: string }>(
42
+ token,
43
+ `${path}/public-key`,
44
+ );
45
+ await sodium.ready;
46
+ const save = async (name: string, value: string) => {
47
+ const encrypted = sodium.crypto_box_seal(
48
+ value,
49
+ sodium.from_base64(publicKey.key, sodium.base64_variants.ORIGINAL),
50
+ );
51
+ await githubRequest(
52
+ token,
53
+ `${path}/${name}`,
54
+ {
55
+ key_id: publicKey.key_id,
56
+ encrypted_value: sodium.to_base64(
57
+ encrypted,
58
+ sodium.base64_variants.ORIGINAL,
59
+ ),
60
+ },
61
+ "PUT",
62
+ );
63
+ };
64
+ const managementToken = env.CONVEX_TEAM_TOKEN;
65
+ if (!managementToken)
66
+ throw new Error("Convex team access is not configured.");
67
+ if (!names.has("CONVEX_DEPLOY_KEY")) {
68
+ const deployment = await ensureProduction(
69
+ managementToken,
70
+ args.projectId,
71
+ );
72
+ const { deployKey } = await management<{ deployKey: string }>(
73
+ managementToken,
74
+ `/deployments/${deployment}/create_deploy_key`,
75
+ { name: "github-actions-production" },
76
+ );
77
+ if (!deployKey.startsWith(`prod:${deployment}|`))
78
+ throw new Error("Expected a production deploy key.");
79
+ await save("CONVEX_DEPLOY_KEY", deployKey);
80
+ }
81
+ if (!names.has("CONVEX_DEPLOY_KEY_PREVIEW")) {
82
+ const { previewDeployKey } = await management<{
83
+ previewDeployKey: string;
84
+ }>(
85
+ managementToken,
86
+ `/projects/${args.projectId}/create_preview_deploy_key`,
87
+ { name: "github-actions-preview" },
88
+ );
89
+ if (!previewDeployKey.startsWith("preview:"))
90
+ throw new Error("Expected a preview deploy key.");
91
+ await save("CONVEX_DEPLOY_KEY_PREVIEW", previewDeployKey);
92
+ }
93
+ if (
94
+ app.githubOwner === env.GITHUB_OWNER?.toLowerCase() &&
95
+ env.EXPO_TOKEN &&
96
+ !names.has("EXPO_TOKEN")
97
+ )
98
+ await save("EXPO_TOKEN", env.EXPO_TOKEN);
99
+ return null;
100
+ },
101
+ });
@@ -47,9 +47,10 @@ export async function githubRequest<T>(
47
47
  token: string,
48
48
  path: string,
49
49
  body?: unknown,
50
+ method = body === undefined ? "GET" : "POST",
50
51
  ): Promise<T> {
51
52
  const response = await fetch(`https://api.github.com${path}`, {
52
- method: body === undefined ? "GET" : "POST",
53
+ method,
53
54
  redirect: "error",
54
55
  signal: AbortSignal.timeout(30_000),
55
56
  headers: {
@@ -62,5 +63,9 @@ export async function githubRequest<T>(
62
63
  });
63
64
  if (!response.ok)
64
65
  throw new Error(`GitHub request failed (${response.status}).`);
65
- return response.json() as Promise<T>;
66
+ return (
67
+ response.status === 204 || response.headers.get("content-length") === "0"
68
+ ? undefined
69
+ : await response.json()
70
+ ) as T;
66
71
  }
@@ -156,19 +156,6 @@ export const create = internalMutation({
156
156
  return app.convexProjectId ?? null;
157
157
  },
158
158
  });
159
- export const saveProject = internalMutation({
160
- args: {
161
- ...identityFields,
162
- appId: v.string(),
163
- projectId: v.number(),
164
- },
165
- returns: v.null(),
166
- handler: async (ctx, args) => {
167
- const app = await ownedApp(ctx, args.userId, args.appId);
168
- await ctx.db.patch("apps", app._id, { convexProjectId: args.projectId });
169
- return null;
170
- },
171
- });
172
159
  export const finish = internalMutation({
173
160
  args: { ...identityFields, ...previewIdentity, deployment },
174
161
  returns: v.null(),
@@ -2,12 +2,12 @@ import {
2
2
  identityFields,
3
3
  internalAction,
4
4
  } from "@disposabl/disposabl-kit/server/lib/functions";
5
- import { ConvexError, v } from "convex/values";
5
+ import { v } from "convex/values";
6
6
  import { internal } from "../../../_generated/api";
7
7
  import { env } from "../../../_generated/server";
8
8
  import { previewIdentity, deployment } from "../../../validator";
9
9
  import { validateReference } from "../../internal";
10
- import { ensureDevelopment, ensureProject } from "./management";
10
+ import { ensureDevelopment } from "./management";
11
11
 
12
12
  export const create = internalAction({
13
13
  platforms: true,
@@ -34,29 +34,13 @@ export const create = internalAction({
34
34
  userId: args.userId,
35
35
  appId: args.appId,
36
36
  });
37
- const token = env.CONVEX_TEAM_TOKEN;
38
- const teamId = env.CONVEX_TEAM_ID;
39
- if (!token || !teamId || !/^\d+$/.test(teamId))
40
- throw new ConvexError(
41
- "Managed setup requires CONVEX_TEAM_ID and CONVEX_TEAM_TOKEN on the service backend.",
42
- );
43
- const saved = await ctx.runMutation(
44
- internal.previews.internal.create,
45
- args,
46
- );
47
- await ctx.runAction(internal.github.actions.provision.run, {
37
+ await ctx.runMutation(internal.previews.internal.create, args);
38
+ const projectId = await ctx.runAction(internal.apps.actions.setup.setup, {
48
39
  userId: args.userId,
49
40
  appId: args.appId,
50
41
  });
51
- const projectId = saved ?? (await ensureProject(token, teamId, args.appId));
52
- if (saved === null)
53
- await ctx.runMutation(internal.previews.internal.saveProject, {
54
- userId: args.userId,
55
- appId: args.appId,
56
- projectId,
57
- });
58
42
  const { deployKey, ...deployment } = await ensureDevelopment(
59
- token,
43
+ env.CONVEX_TEAM_TOKEN!,
60
44
  projectId,
61
45
  args.reference,
62
46
  );
@@ -131,3 +131,36 @@ export async function ensureDevelopment(
131
131
  deployKey,
132
132
  };
133
133
  }
134
+
135
+ export async function ensureProduction(token: string, projectId: number) {
136
+ const path = `/projects/${projectId}`;
137
+ const lookup = () =>
138
+ management<Deployment>(token, `${path}/deployment?defaultProd=true`);
139
+ let deployment: Deployment;
140
+ try {
141
+ deployment = await lookup();
142
+ } catch (error) {
143
+ if (!(error instanceof ManagementError) || error.status !== 404)
144
+ throw error;
145
+ try {
146
+ deployment = await management<Deployment>(
147
+ token,
148
+ `${path}/create_deployment`,
149
+ { type: "prod" },
150
+ );
151
+ } catch (error) {
152
+ try {
153
+ deployment = await lookup();
154
+ } catch {
155
+ throw error;
156
+ }
157
+ }
158
+ }
159
+ if (
160
+ deployment.kind !== "cloud" ||
161
+ deployment.deploymentType !== "prod" ||
162
+ deployment.projectId !== projectId
163
+ )
164
+ throw new Error("Expected this app's production deployment.");
165
+ return deployment.name;
166
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-disposabl-app",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "Create a Disposabl app",
5
5
  "type": "module",
6
6
  "license": "MIT",