@hot-updater/supabase 1.2.0-rc.5 → 1.2.0-rc.51

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/edge.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_supabaseStorage = require("./supabaseStorage-BV6GuUz_.cjs");
2
+ const require_supabaseStorage = require("./supabaseStorage-DUa49vGh.cjs");
3
3
  exports.supabaseDatabase = require_supabaseStorage.supabaseDatabase;
4
4
  exports.supabaseStorage = require_supabaseStorage.supabaseStorage;
package/dist/edge.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { i as supabaseDatabase, n as supabaseStorage, r as SupabaseDatabaseConfig, t as SupabaseStorageConfig } from "./supabaseStorage-B131_auF.cjs";
1
+ import { i as supabaseDatabase, n as supabaseStorage, r as SupabaseDatabaseConfig, t as SupabaseStorageConfig } from "./supabaseStorage-C9W-69OP.cjs";
2
2
  export { type SupabaseDatabaseConfig, type SupabaseStorageConfig, supabaseDatabase, supabaseStorage };
package/dist/edge.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { i as supabaseDatabase, n as supabaseStorage, r as SupabaseDatabaseConfig, t as SupabaseStorageConfig } from "./supabaseStorage-B131_auF.mjs";
1
+ import { i as supabaseDatabase, n as supabaseStorage, r as SupabaseDatabaseConfig, t as SupabaseStorageConfig } from "./supabaseStorage-C9W-69OP.mjs";
2
2
  export { type SupabaseDatabaseConfig, type SupabaseStorageConfig, supabaseDatabase, supabaseStorage };
package/dist/edge.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as supabaseDatabase, t as supabaseStorage } from "./supabaseStorage-8VAuNYHy.mjs";
1
+ import { n as supabaseDatabase, t as supabaseStorage } from "./supabaseStorage-B6IM8UX2.mjs";
2
2
  export { supabaseDatabase, supabaseStorage };
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_supabaseStorage = require("./supabaseStorage-BV6GuUz_.cjs");
2
+ const require_supabaseStorage = require("./supabaseStorage-DUa49vGh.cjs");
3
3
  let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
4
4
  //#region src/supabaseSchema.ts
5
5
  /** Every table the apply RPC may name: models, index tables, settings, and the write guard. */
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as supabaseStorage, r as SupabaseDatabaseConfig, t as SupabaseStorageConfig } from "./supabaseStorage-B131_auF.cjs";
1
+ import { n as supabaseStorage, r as SupabaseDatabaseConfig, t as SupabaseStorageConfig } from "./supabaseStorage-C9W-69OP.cjs";
2
2
  import { ToolingDatabase } from "@hot-updater/plugin-core";
3
3
  //#region src/supabaseMigration.d.ts
4
4
  /**
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as supabaseStorage, r as SupabaseDatabaseConfig, t as SupabaseStorageConfig } from "./supabaseStorage-B131_auF.mjs";
1
+ import { n as supabaseStorage, r as SupabaseDatabaseConfig, t as SupabaseStorageConfig } from "./supabaseStorage-C9W-69OP.mjs";
2
2
  import { ToolingDatabase } from "@hot-updater/plugin-core";
3
3
  //#region src/supabaseMigration.d.ts
4
4
  /**
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as SUPABASE_TABLE_PREFIX, n as supabaseDatabase$1, r as SUPABASE_APPLY_FUNCTION, t as supabaseStorage } from "./supabaseStorage-8VAuNYHy.mjs";
1
+ import { i as SUPABASE_TABLE_PREFIX, n as supabaseDatabase$1, r as SUPABASE_APPLY_FUNCTION, t as supabaseStorage } from "./supabaseStorage-B6IM8UX2.mjs";
2
2
  import { SETTINGS_TABLE, WRITE_GUARD_TABLE, coreSettings, coreTarget, createTableStatements, generateEngineSql, isMultiIndex } from "@hot-updater/plugin-core";
3
3
  //#region src/supabaseSchema.ts
4
4
  /** Every table the apply RPC may name: models, index tables, settings, and the write guard. */
@@ -6421,14 +6421,15 @@ const supabaseDatabase = (config) => {
6421
6421
  //#region iac/configTemplate.ts
6422
6422
  /**
6423
6423
  * The config init writes. With the `resources` init set up, it names them,
6424
- * and reads the service role key with `secretEnv`, from the environment and
6424
+ * and reads the service role key with `secret()`, from the environment and
6425
6425
  * `.env.hotupdater`, then the config's `secrets` adapter. Without them, as
6426
- * the agent scaffold writes it, it reads every value from the environment.
6426
+ * the agent scaffold writes it before the agent creates the project, it
6427
+ * reads the URL and bucket from the environment, where the agent records
6428
+ * them, and the key with `secret()` alike.
6427
6429
  */
6428
6430
  const getConfigScaffold = (build, resources) => {
6429
6431
  const supabaseUrl = resources === void 0 ? "process.env.HOT_UPDATER_SUPABASE_URL!" : JSON.stringify(resources.supabaseUrl);
6430
- const serviceRoleKey = resources === void 0 ? "process.env.HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY!" : `async () =>
6431
- (await deploySecrets()).HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY`;
6432
+ const serviceRoleKey = "secret(\"HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY\")";
6432
6433
  const storageConfig = {
6433
6434
  imports: [{
6434
6435
  pkg: "@hot-updater/supabase",
@@ -6450,7 +6451,6 @@ const getConfigScaffold = (build, resources) => {
6450
6451
  supabaseServiceRoleKey: ${serviceRoleKey},
6451
6452
  })`
6452
6453
  };
6453
- const helperStatements = resources === void 0 ? [] : [(0, _hot_updater_cli_tools.secretEnvHelper)("deploySecrets", ["HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY"])];
6454
6454
  const builder = new _hot_updater_cli_tools.ConfigBuilder().setBuildType(build).setStorage(storageConfig).setDatabase(databaseConfig).setPlugins({
6455
6455
  imports: [{
6456
6456
  pkg: "hot-updater/plugins",
@@ -6462,11 +6462,11 @@ const getConfigScaffold = (build, resources) => {
6462
6462
  }],
6463
6463
  configString: "[apiKeys(), insights(), remoteConfig()]"
6464
6464
  });
6465
- if (resources !== void 0) builder.addImport({
6465
+ builder.addImport({
6466
6466
  pkg: "hot-updater",
6467
- named: ["secretEnv"]
6468
- }).setIntermediateCode(helperStatements.map(({ code }) => code).join("\n\n"));
6469
- return (0, _hot_updater_cli_tools.createHotUpdaterConfigScaffoldFromBuilder)(builder, { helperStatements });
6467
+ named: ["secret"]
6468
+ });
6469
+ return (0, _hot_updater_cli_tools.createHotUpdaterConfigScaffoldFromBuilder)(builder);
6470
6470
  };
6471
6471
  //#endregion
6472
6472
  //#region iac/init/index.ts
@@ -6605,6 +6605,17 @@ const supabaseApi = (supabaseUrl, supabaseServiceRoleKey) => {
6605
6605
  };
6606
6606
  };
6607
6607
  //#endregion
6608
+ //#region iac/supabaseCliPackage.ts
6609
+ /**
6610
+ * The Supabase CLI init runs, as `npx -y <SUPABASE_CLI>`, so whichever CLI
6611
+ * the project installs or npx resolves can't change what its commands do.
6612
+ * Its commands use Supabase CLI 3's forms: `--remote` targets the linked
6613
+ * project or `--remote=<ref>` another one, and every hosted change passes
6614
+ * `--yes`, because CLI 3 fails one without a terminal unless it does. Move
6615
+ * to a new major only after checking each command against its release notes.
6616
+ */
6617
+ const SUPABASE_CLI = "supabase@3.0.0";
6618
+ //#endregion
6608
6619
  //#region iac/supabaseAuthentication.ts
6609
6620
  const SUPABASE_AUTH_METHOD = {
6610
6621
  accessToken: "access-token",
@@ -6625,7 +6636,7 @@ const openBrowser = async (url) => {
6625
6636
  const hasValidSupabaseCliLogin = async () => {
6626
6637
  return (await execa("npx", [
6627
6638
  "-y",
6628
- "supabase",
6639
+ SUPABASE_CLI,
6629
6640
  "projects",
6630
6641
  "list",
6631
6642
  "--output",
@@ -6652,7 +6663,7 @@ const inputSupabaseAccessToken = async (accessToken) => {
6652
6663
  if (await hasValidSupabaseCliLogin()) return;
6653
6664
  const loginProcess = execa("npx", [
6654
6665
  "-y",
6655
- "supabase",
6666
+ SUPABASE_CLI,
6656
6667
  "login",
6657
6668
  "--no-browser",
6658
6669
  "--agent",
@@ -6724,7 +6735,7 @@ const supabaseDatabaseCommandErrorMessage = (err, { dbPassword, stderrInherited
6724
6735
  };
6725
6736
  const handleSupabaseDatabaseCommandError = (err, options) => {
6726
6737
  if (err instanceof ExecaError) _hot_updater_cli_tools.p.log.error(supabaseDatabaseCommandErrorMessage(err, options));
6727
- else console.error(err);
6738
+ else _hot_updater_cli_tools.p.log.error(err instanceof Error ? err.message : String(err));
6728
6739
  process.exit(1);
6729
6740
  };
6730
6741
  const confirmSupabaseDatabaseMigrations = async ({ nonInteractive }) => {
@@ -6737,9 +6748,9 @@ const confirmSupabaseDatabaseMigrations = async ({ nonInteractive }) => {
6737
6748
  const runSupabaseLink = async (workdir, { accessToken, projectId, dbPassword }) => {
6738
6749
  await fs_promises.default.writeFile(path.default.join(workdir, "supabase", "config.toml"), (0, _hot_updater_cli_tools.transformTemplate)(SUPABASE_CONFIG_TEMPLATE, { projectId }));
6739
6750
  await execa("npx", [
6740
- "supabase",
6751
+ "-y",
6752
+ SUPABASE_CLI,
6741
6753
  "link",
6742
- "--project-ref",
6743
6754
  projectId,
6744
6755
  "--workdir",
6745
6756
  workdir
@@ -6768,10 +6779,11 @@ const linkSupabase = async (workdir, options) => {
6768
6779
  /** Pushes the workdir's migrations the linked project has not run, after its own history. */
6769
6780
  const runSupabasePush = async (workdir, { accessToken, dbPassword, quiet = false }) => {
6770
6781
  await execa("npx", [
6771
- "supabase",
6782
+ "-y",
6783
+ SUPABASE_CLI,
6772
6784
  "migration",
6773
6785
  "fetch",
6774
- "--linked",
6786
+ "--remote",
6775
6787
  "--yes",
6776
6788
  "--workdir",
6777
6789
  workdir
@@ -6783,10 +6795,12 @@ const runSupabasePush = async (workdir, { accessToken, dbPassword, quiet = false
6783
6795
  throw error;
6784
6796
  });
6785
6797
  return execa("npx", [
6786
- "supabase",
6798
+ "-y",
6799
+ SUPABASE_CLI,
6787
6800
  "db",
6788
6801
  "push",
6789
6802
  "--include-all",
6803
+ "--remote",
6790
6804
  "--yes",
6791
6805
  "--workdir",
6792
6806
  workdir
@@ -6949,7 +6963,7 @@ const isRecord$1 = (value) => typeof value === "object" && value !== null;
6949
6963
  const runSupabaseCli = async (args) => {
6950
6964
  const result = await execa("npx", [
6951
6965
  "-y",
6952
- "supabase",
6966
+ SUPABASE_CLI,
6953
6967
  ...args
6954
6968
  ], { env: void 0 });
6955
6969
  return JSON.parse(result.stdout);
@@ -6972,15 +6986,14 @@ const supabaseCliManagementApi = () => ({
6972
6986
  listFunctions: async (projectId) => parseSupabaseFunctionSlugs(await runSupabaseCli([
6973
6987
  "functions",
6974
6988
  "list",
6975
- "--project-ref",
6976
- projectId,
6989
+ `--remote=${projectId}`,
6977
6990
  "--output",
6978
6991
  "json"
6979
6992
  ])),
6980
6993
  createProject: async ({ name, organizationSlug, region }) => {
6981
6994
  await execa("npx", [
6982
6995
  "-y",
6983
- "supabase",
6996
+ SUPABASE_CLI,
6984
6997
  "projects",
6985
6998
  "create",
6986
6999
  name,
@@ -6988,6 +7001,7 @@ const supabaseCliManagementApi = () => ({
6988
7001
  organizationSlug,
6989
7002
  "--region",
6990
7003
  region,
7004
+ "--yes",
6991
7005
  "--agent",
6992
7006
  "no"
6993
7007
  ], { stdio: "inherit" });
@@ -7276,7 +7290,7 @@ const selectProject = async (preferredProjectId, nonInteractive = false, accessT
7276
7290
  try {
7277
7291
  const listProjects = await execa("npx", [
7278
7292
  "-y",
7279
- "supabase",
7293
+ SUPABASE_CLI,
7280
7294
  "projects",
7281
7295
  "list",
7282
7296
  "--output",
@@ -7286,7 +7300,7 @@ const selectProject = async (preferredProjectId, nonInteractive = false, accessT
7286
7300
  } catch (err) {
7287
7301
  spinner.stop();
7288
7302
  const message = err instanceof Error ? err.message : String(err);
7289
- console.error(`Failed to fetch Supabase projects: ${message}`);
7303
+ _hot_updater_cli_tools.p.log.error(`Failed to fetch Supabase projects: ${message}`);
7290
7304
  process.exit(1);
7291
7305
  }
7292
7306
  spinner.stop();
@@ -7437,13 +7451,14 @@ const deployEdgeFunction = async (accessToken, workdir, projectId, functionName)
7437
7451
  task: async () => {
7438
7452
  try {
7439
7453
  return (await execa("npx", [
7440
- "supabase",
7454
+ "-y",
7455
+ SUPABASE_CLI,
7441
7456
  "functions",
7442
7457
  "deploy",
7443
7458
  functionName,
7444
- "--project-ref",
7445
- projectId,
7459
+ `--remote=${projectId}`,
7446
7460
  "--no-verify-jwt",
7461
+ "--yes",
7447
7462
  "--workdir",
7448
7463
  workdir
7449
7464
  ], {
@@ -7482,11 +7497,10 @@ const getSupabaseProjectAccess = async ({ accessToken, managementApi, project, w
7482
7497
  const getServiceRoleApiKey = async () => {
7483
7498
  const keysProcess = await execa("npx", [
7484
7499
  "-y",
7485
- "supabase",
7500
+ SUPABASE_CLI,
7486
7501
  "projects",
7487
7502
  "api-keys",
7488
- "--project-ref",
7489
- project.id,
7503
+ `--remote=${project.id}`,
7490
7504
  "--output",
7491
7505
  "json"
7492
7506
  ], { env: getSupabaseCliEnv(accessToken) });
@@ -7693,6 +7707,7 @@ const runInitWithoutCliMetadata = async ({ build, envFile, secretsEnv }) => {
7693
7707
  });
7694
7708
  ({clientPlugins} = managedServer);
7695
7709
  try {
7710
+ await (0, _hot_updater_cli_tools.fillReleaseLabels)(managedServer);
7696
7711
  credential = await (0, _hot_updater_cli_tools.provisionClientCredential)(managedServer, {
7697
7712
  env: initInputEnv,
7698
7713
  name: "Supabase init"
@@ -7719,8 +7734,7 @@ const runInitWithoutCliMetadata = async ({ build, envFile, secretsEnv }) => {
7719
7734
  clientPlugins
7720
7735
  });
7721
7736
  reportSupabaseOriginCatalogReady();
7722
- _hot_updater_cli_tools.p.log.message(`Next step: ${(0, _hot_updater_cli_tools.link)("https://hot-updater.dev/docs/managed/supabase#step-3-add-hotupdater-to-your-project")}`);
7723
- _hot_updater_cli_tools.p.log.success("Done! 🎉");
7737
+ return { nextSteps: [(0, _hot_updater_cli_tools.link)("https://hot-updater.dev/docs/managed/supabase#step-3-add-hotupdater-to-your-project")] };
7724
7738
  };
7725
7739
  const runInit = (options) => withSupabaseCliMetadataCleanup(process.cwd(), () => runInitWithoutCliMetadata(options));
7726
7740
  //#endregion
@@ -1,4 +1,4 @@
1
- import { RunInitOptions } from "@hot-updater/cli-tools";
1
+ import { RunInitOptions, RunInitResult } from "@hot-updater/cli-tools";
2
2
  //#region iac/supabaseApi.d.ts
3
3
  type SupabaseInfrastructureState = "fresh" | "incompatible" | "v1";
4
4
  interface SupabaseApi {
@@ -177,6 +177,6 @@ declare const getSupabaseProjectAccess: ({ accessToken, managementApi, project,
177
177
  readonly serviceRoleApiKey: string;
178
178
  }>;
179
179
  declare const withSupabaseCliMetadataCleanup: <Result>(cwd: string, operation: () => Promise<Result>) => Promise<Result>;
180
- declare const runInit: (options: RunInitOptions) => Promise<void>;
180
+ declare const runInit: (options: RunInitOptions) => Promise<RunInitResult>;
181
181
  //#endregion
182
182
  export { SupabaseBucketSelection, SupabaseProjectSelection, createSelectedBucket, getSupabaseFunctionUrl, getSupabaseProjectAccess, initProvider, reportSupabaseOriginCatalogReady, resolveEdgeFunctionDenoConfig, runInit, selectBucket, selectProject, waitForSupabaseProjectReady, waitForSupabaseSchemaReady, withSupabaseCliMetadataCleanup };
@@ -1,4 +1,4 @@
1
- import { RunInitOptions } from "@hot-updater/cli-tools";
1
+ import { RunInitOptions, RunInitResult } from "@hot-updater/cli-tools";
2
2
  //#region iac/supabaseApi.d.ts
3
3
  type SupabaseInfrastructureState = "fresh" | "incompatible" | "v1";
4
4
  interface SupabaseApi {
@@ -177,6 +177,6 @@ declare const getSupabaseProjectAccess: ({ accessToken, managementApi, project,
177
177
  readonly serviceRoleApiKey: string;
178
178
  }>;
179
179
  declare const withSupabaseCliMetadataCleanup: <Result>(cwd: string, operation: () => Promise<Result>) => Promise<Result>;
180
- declare const runInit: (options: RunInitOptions) => Promise<void>;
180
+ declare const runInit: (options: RunInitOptions) => Promise<RunInitResult>;
181
181
  //#endregion
182
182
  export { SupabaseBucketSelection, SupabaseProjectSelection, createSelectedBucket, getSupabaseFunctionUrl, getSupabaseProjectAccess, initProvider, reportSupabaseOriginCatalogReady, resolveEdgeFunctionDenoConfig, runInit, selectBucket, selectProject, waitForSupabaseProjectReady, waitForSupabaseSchemaReady, withSupabaseCliMetadataCleanup };
@@ -1,7 +1,7 @@
1
1
  import { createRequire } from "node:module";
2
2
  import fs from "fs/promises";
3
3
  import path from "path";
4
- import { ConfigBuilder, InitError, MissingInitInputsError, assembleServer, assertInfrastructureGenerationAtUrl, assertInitInputs, assertInitProviderInputs, confirmInitInputPersistence, copyDirToTmp, createHotUpdaterConfigScaffoldFromBuilder, getHotUpdaterEnvValue, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, moduleSpecifiersOf, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInput, resolvePackageVersion, secretEnvHelper, transformEnv, transformTemplate, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
4
+ import { ConfigBuilder, InitError, MissingInitInputsError, assembleServer, assertInfrastructureGenerationAtUrl, assertInitInputs, assertInitProviderInputs, confirmInitInputPersistence, copyDirToTmp, createHotUpdaterConfigScaffoldFromBuilder, fillReleaseLabels, getHotUpdaterEnvValue, getHotUpdaterInitInputEnv, getInitProviderEnvVars, getInitProviderTextPromptValues, link, makeEnv, moduleSpecifiersOf, p, printAppSetup, provisionClientCredential, readHotUpdaterInitEnv, resolveInitProviderInput, resolvePackageVersion, transformEnv, transformTemplate, writeHotUpdaterFiles } from "@hot-updater/cli-tools";
5
5
  import { apiKeys, insights, remoteConfig } from "@hot-updater/server/plugins";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import { ChildProcess, execFile, spawn, spawnSync } from "node:child_process";
@@ -6416,14 +6416,15 @@ const supabaseDatabase = (config) => {
6416
6416
  //#region iac/configTemplate.ts
6417
6417
  /**
6418
6418
  * The config init writes. With the `resources` init set up, it names them,
6419
- * and reads the service role key with `secretEnv`, from the environment and
6419
+ * and reads the service role key with `secret()`, from the environment and
6420
6420
  * `.env.hotupdater`, then the config's `secrets` adapter. Without them, as
6421
- * the agent scaffold writes it, it reads every value from the environment.
6421
+ * the agent scaffold writes it before the agent creates the project, it
6422
+ * reads the URL and bucket from the environment, where the agent records
6423
+ * them, and the key with `secret()` alike.
6422
6424
  */
6423
6425
  const getConfigScaffold = (build, resources) => {
6424
6426
  const supabaseUrl = resources === void 0 ? "process.env.HOT_UPDATER_SUPABASE_URL!" : JSON.stringify(resources.supabaseUrl);
6425
- const serviceRoleKey = resources === void 0 ? "process.env.HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY!" : `async () =>
6426
- (await deploySecrets()).HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY`;
6427
+ const serviceRoleKey = "secret(\"HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY\")";
6427
6428
  const storageConfig = {
6428
6429
  imports: [{
6429
6430
  pkg: "@hot-updater/supabase",
@@ -6445,7 +6446,6 @@ const getConfigScaffold = (build, resources) => {
6445
6446
  supabaseServiceRoleKey: ${serviceRoleKey},
6446
6447
  })`
6447
6448
  };
6448
- const helperStatements = resources === void 0 ? [] : [secretEnvHelper("deploySecrets", ["HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY"])];
6449
6449
  const builder = new ConfigBuilder().setBuildType(build).setStorage(storageConfig).setDatabase(databaseConfig).setPlugins({
6450
6450
  imports: [{
6451
6451
  pkg: "hot-updater/plugins",
@@ -6457,11 +6457,11 @@ const getConfigScaffold = (build, resources) => {
6457
6457
  }],
6458
6458
  configString: "[apiKeys(), insights(), remoteConfig()]"
6459
6459
  });
6460
- if (resources !== void 0) builder.addImport({
6460
+ builder.addImport({
6461
6461
  pkg: "hot-updater",
6462
- named: ["secretEnv"]
6463
- }).setIntermediateCode(helperStatements.map(({ code }) => code).join("\n\n"));
6464
- return createHotUpdaterConfigScaffoldFromBuilder(builder, { helperStatements });
6462
+ named: ["secret"]
6463
+ });
6464
+ return createHotUpdaterConfigScaffoldFromBuilder(builder);
6465
6465
  };
6466
6466
  //#endregion
6467
6467
  //#region iac/init/index.ts
@@ -6600,6 +6600,17 @@ const supabaseApi = (supabaseUrl, supabaseServiceRoleKey) => {
6600
6600
  };
6601
6601
  };
6602
6602
  //#endregion
6603
+ //#region iac/supabaseCliPackage.ts
6604
+ /**
6605
+ * The Supabase CLI init runs, as `npx -y <SUPABASE_CLI>`, so whichever CLI
6606
+ * the project installs or npx resolves can't change what its commands do.
6607
+ * Its commands use Supabase CLI 3's forms: `--remote` targets the linked
6608
+ * project or `--remote=<ref>` another one, and every hosted change passes
6609
+ * `--yes`, because CLI 3 fails one without a terminal unless it does. Move
6610
+ * to a new major only after checking each command against its release notes.
6611
+ */
6612
+ const SUPABASE_CLI = "supabase@3.0.0";
6613
+ //#endregion
6603
6614
  //#region iac/supabaseAuthentication.ts
6604
6615
  const SUPABASE_AUTH_METHOD = {
6605
6616
  accessToken: "access-token",
@@ -6620,7 +6631,7 @@ const openBrowser = async (url) => {
6620
6631
  const hasValidSupabaseCliLogin = async () => {
6621
6632
  return (await execa("npx", [
6622
6633
  "-y",
6623
- "supabase",
6634
+ SUPABASE_CLI,
6624
6635
  "projects",
6625
6636
  "list",
6626
6637
  "--output",
@@ -6647,7 +6658,7 @@ const inputSupabaseAccessToken = async (accessToken) => {
6647
6658
  if (await hasValidSupabaseCliLogin()) return;
6648
6659
  const loginProcess = execa("npx", [
6649
6660
  "-y",
6650
- "supabase",
6661
+ SUPABASE_CLI,
6651
6662
  "login",
6652
6663
  "--no-browser",
6653
6664
  "--agent",
@@ -6719,7 +6730,7 @@ const supabaseDatabaseCommandErrorMessage = (err, { dbPassword, stderrInherited
6719
6730
  };
6720
6731
  const handleSupabaseDatabaseCommandError = (err, options) => {
6721
6732
  if (err instanceof ExecaError) p.log.error(supabaseDatabaseCommandErrorMessage(err, options));
6722
- else console.error(err);
6733
+ else p.log.error(err instanceof Error ? err.message : String(err));
6723
6734
  process.exit(1);
6724
6735
  };
6725
6736
  const confirmSupabaseDatabaseMigrations = async ({ nonInteractive }) => {
@@ -6732,9 +6743,9 @@ const confirmSupabaseDatabaseMigrations = async ({ nonInteractive }) => {
6732
6743
  const runSupabaseLink = async (workdir, { accessToken, projectId, dbPassword }) => {
6733
6744
  await fs.writeFile(path.join(workdir, "supabase", "config.toml"), transformTemplate(SUPABASE_CONFIG_TEMPLATE, { projectId }));
6734
6745
  await execa("npx", [
6735
- "supabase",
6746
+ "-y",
6747
+ SUPABASE_CLI,
6736
6748
  "link",
6737
- "--project-ref",
6738
6749
  projectId,
6739
6750
  "--workdir",
6740
6751
  workdir
@@ -6763,10 +6774,11 @@ const linkSupabase = async (workdir, options) => {
6763
6774
  /** Pushes the workdir's migrations the linked project has not run, after its own history. */
6764
6775
  const runSupabasePush = async (workdir, { accessToken, dbPassword, quiet = false }) => {
6765
6776
  await execa("npx", [
6766
- "supabase",
6777
+ "-y",
6778
+ SUPABASE_CLI,
6767
6779
  "migration",
6768
6780
  "fetch",
6769
- "--linked",
6781
+ "--remote",
6770
6782
  "--yes",
6771
6783
  "--workdir",
6772
6784
  workdir
@@ -6778,10 +6790,12 @@ const runSupabasePush = async (workdir, { accessToken, dbPassword, quiet = false
6778
6790
  throw error;
6779
6791
  });
6780
6792
  return execa("npx", [
6781
- "supabase",
6793
+ "-y",
6794
+ SUPABASE_CLI,
6782
6795
  "db",
6783
6796
  "push",
6784
6797
  "--include-all",
6798
+ "--remote",
6785
6799
  "--yes",
6786
6800
  "--workdir",
6787
6801
  workdir
@@ -6944,7 +6958,7 @@ const isRecord$1 = (value) => typeof value === "object" && value !== null;
6944
6958
  const runSupabaseCli = async (args) => {
6945
6959
  const result = await execa("npx", [
6946
6960
  "-y",
6947
- "supabase",
6961
+ SUPABASE_CLI,
6948
6962
  ...args
6949
6963
  ], { env: void 0 });
6950
6964
  return JSON.parse(result.stdout);
@@ -6967,15 +6981,14 @@ const supabaseCliManagementApi = () => ({
6967
6981
  listFunctions: async (projectId) => parseSupabaseFunctionSlugs(await runSupabaseCli([
6968
6982
  "functions",
6969
6983
  "list",
6970
- "--project-ref",
6971
- projectId,
6984
+ `--remote=${projectId}`,
6972
6985
  "--output",
6973
6986
  "json"
6974
6987
  ])),
6975
6988
  createProject: async ({ name, organizationSlug, region }) => {
6976
6989
  await execa("npx", [
6977
6990
  "-y",
6978
- "supabase",
6991
+ SUPABASE_CLI,
6979
6992
  "projects",
6980
6993
  "create",
6981
6994
  name,
@@ -6983,6 +6996,7 @@ const supabaseCliManagementApi = () => ({
6983
6996
  organizationSlug,
6984
6997
  "--region",
6985
6998
  region,
6999
+ "--yes",
6986
7000
  "--agent",
6987
7001
  "no"
6988
7002
  ], { stdio: "inherit" });
@@ -7271,7 +7285,7 @@ const selectProject = async (preferredProjectId, nonInteractive = false, accessT
7271
7285
  try {
7272
7286
  const listProjects = await execa("npx", [
7273
7287
  "-y",
7274
- "supabase",
7288
+ SUPABASE_CLI,
7275
7289
  "projects",
7276
7290
  "list",
7277
7291
  "--output",
@@ -7281,7 +7295,7 @@ const selectProject = async (preferredProjectId, nonInteractive = false, accessT
7281
7295
  } catch (err) {
7282
7296
  spinner.stop();
7283
7297
  const message = err instanceof Error ? err.message : String(err);
7284
- console.error(`Failed to fetch Supabase projects: ${message}`);
7298
+ p.log.error(`Failed to fetch Supabase projects: ${message}`);
7285
7299
  process.exit(1);
7286
7300
  }
7287
7301
  spinner.stop();
@@ -7432,13 +7446,14 @@ const deployEdgeFunction = async (accessToken, workdir, projectId, functionName)
7432
7446
  task: async () => {
7433
7447
  try {
7434
7448
  return (await execa("npx", [
7435
- "supabase",
7449
+ "-y",
7450
+ SUPABASE_CLI,
7436
7451
  "functions",
7437
7452
  "deploy",
7438
7453
  functionName,
7439
- "--project-ref",
7440
- projectId,
7454
+ `--remote=${projectId}`,
7441
7455
  "--no-verify-jwt",
7456
+ "--yes",
7442
7457
  "--workdir",
7443
7458
  workdir
7444
7459
  ], {
@@ -7477,11 +7492,10 @@ const getSupabaseProjectAccess = async ({ accessToken, managementApi, project, w
7477
7492
  const getServiceRoleApiKey = async () => {
7478
7493
  const keysProcess = await execa("npx", [
7479
7494
  "-y",
7480
- "supabase",
7495
+ SUPABASE_CLI,
7481
7496
  "projects",
7482
7497
  "api-keys",
7483
- "--project-ref",
7484
- project.id,
7498
+ `--remote=${project.id}`,
7485
7499
  "--output",
7486
7500
  "json"
7487
7501
  ], { env: getSupabaseCliEnv(accessToken) });
@@ -7688,6 +7702,7 @@ const runInitWithoutCliMetadata = async ({ build, envFile, secretsEnv }) => {
7688
7702
  });
7689
7703
  ({clientPlugins} = managedServer);
7690
7704
  try {
7705
+ await fillReleaseLabels(managedServer);
7691
7706
  credential = await provisionClientCredential(managedServer, {
7692
7707
  env: initInputEnv,
7693
7708
  name: "Supabase init"
@@ -7714,8 +7729,7 @@ const runInitWithoutCliMetadata = async ({ build, envFile, secretsEnv }) => {
7714
7729
  clientPlugins
7715
7730
  });
7716
7731
  reportSupabaseOriginCatalogReady();
7717
- p.log.message(`Next step: ${link("https://hot-updater.dev/docs/managed/supabase#step-3-add-hotupdater-to-your-project")}`);
7718
- p.log.success("Done! 🎉");
7732
+ return { nextSteps: [link("https://hot-updater.dev/docs/managed/supabase#step-3-add-hotupdater-to-your-project")] };
7719
7733
  };
7720
7734
  const runInit = (options) => withSupabaseCliMetadataCleanup(process.cwd(), () => runInitWithoutCliMetadata(options));
7721
7735
  //#endregion
@@ -166,7 +166,15 @@ const isMissingObjectError = async (error) => {
166
166
  };
167
167
  /** A character Storage rejects in an object name, `?`, or `!`. */
168
168
  const ESCAPED_CHARACTER = /[^A-Za-z0-9_/.*'() &$=@;:+,-]/gu;
169
+ const ESCAPE_SEQUENCE = /!([0-9A-F]{2})/gu;
169
170
  const utf8 = new TextEncoder();
171
+ const utf8Decoder = new TextDecoder("utf-8", { fatal: true });
172
+ /** Objects Storage lists a page at a time. */
173
+ const LIST_PAGE_SIZE = 1e3;
174
+ /** Names Storage removes in one request. */
175
+ const DELETE_BATCH_SIZE = 1e3;
176
+ /** The object the Supabase dashboard keeps in a folder it creates. */
177
+ const EMPTY_FOLDER_PLACEHOLDER = ".emptyFolderPlaceholder";
170
178
  /**
171
179
  * The object name Storage keeps a key under. Storage accepts names of ASCII
172
180
  * letters, digits and `_/!.*'() &$=@;:+,?-` only, and supabase-js puts a name
@@ -177,6 +185,34 @@ const utf8 = new TextEncoder();
177
185
  * Deploy's keys, such as `<bundleId>/manifest.json`, are stored as they are.
178
186
  */
179
187
  const toObjectName = (key) => key.replace(ESCAPED_CHARACTER, (character) => Array.from(utf8.encode(character), (byte) => `!${byte.toString(16).toUpperCase().padStart(2, "0")}`).join(""));
188
+ /** The key `toObjectName` stored under `name`, or null for a name it never makes. */
189
+ const fromObjectName = (name) => {
190
+ const bytes = [];
191
+ const parts = [];
192
+ const flush = () => {
193
+ if (bytes.length === 0) return true;
194
+ try {
195
+ parts.push(utf8Decoder.decode(new Uint8Array(bytes)));
196
+ } catch {
197
+ return false;
198
+ }
199
+ bytes.length = 0;
200
+ return true;
201
+ };
202
+ let index = 0;
203
+ for (const match of name.matchAll(ESCAPE_SEQUENCE)) {
204
+ if (match.index !== index) {
205
+ if (!flush()) return null;
206
+ parts.push(name.slice(index, match.index));
207
+ }
208
+ bytes.push(Number.parseInt(match[1], 16));
209
+ index = match.index + match[0].length;
210
+ }
211
+ if (!flush()) return null;
212
+ parts.push(name.slice(index));
213
+ const key = parts.join("");
214
+ return toObjectName(key) === name ? key : null;
215
+ };
180
216
  const supabaseStorage = (config) => {
181
217
  let client;
182
218
  const bucket = async () => (await (client ??= resolveSupabaseServiceRoleKey(config).then((key) => createClient(config.supabaseUrl, key), (error) => {
@@ -184,6 +220,7 @@ const supabaseStorage = (config) => {
184
220
  throw error;
185
221
  }))).storage.from(config.bucketName);
186
222
  const getStorageKey = createStorageKeyBuilder(config.basePath);
223
+ const basePrefix = getStorageKey() ? `${getStorageKey()}/` : "";
187
224
  const resolveSignedUrl = createSupabaseSignedUrlBatcher({
188
225
  createSignedUrls: async (_bucketName, keys, expiresIn) => (await bucket()).createSignedUrls(keys, expiresIn),
189
226
  expiresIn: config.signedUrlExpiresIn ?? 3600,
@@ -240,6 +277,51 @@ const supabaseStorage = (config) => {
240
277
  const { error } = await (await bucket()).remove([toObjectName(key)]);
241
278
  if (error && !isNotFoundError(error)) throw new Error(`Failed to delete storage object: ${error.message}`);
242
279
  return { deleted: true };
280
+ },
281
+ async listObjects(prefix) {
282
+ const objects = [];
283
+ const folder = toObjectName(getStorageKey(prefix ?? ""));
284
+ let cursor;
285
+ do {
286
+ const { data, error } = await (await bucket()).listV2({
287
+ prefix: folder ? `${folder}/` : "",
288
+ limit: LIST_PAGE_SIZE,
289
+ ...cursor === void 0 ? {} : { cursor }
290
+ });
291
+ if (error) throw new Error(`Failed to list storage objects: ${error.message}`);
292
+ for (const entry of data.objects) {
293
+ const name = entry.key ?? entry.name;
294
+ if (name.split("/").at(-1) === EMPTY_FOLDER_PLACEHOLDER) continue;
295
+ const key = fromObjectName(name);
296
+ if (key === null || !key.startsWith(basePrefix)) continue;
297
+ let storageUri;
298
+ try {
299
+ storageUri = createStorageUri({
300
+ protocol: "supabase-storage",
301
+ bucket: config.bucketName,
302
+ key
303
+ });
304
+ } catch {
305
+ continue;
306
+ }
307
+ const updatedAt = entry.updated_at ?? entry.created_at;
308
+ objects.push({
309
+ key: key.slice(basePrefix.length),
310
+ ...updatedAt ? { lastModifiedAt: new Date(updatedAt) } : {},
311
+ size: Number(entry.metadata?.size ?? 0),
312
+ storageUri
313
+ });
314
+ }
315
+ cursor = data.hasNext ? data.nextCursor : void 0;
316
+ } while (cursor !== void 0);
317
+ return objects;
318
+ },
319
+ async deleteObjects(relativeKeys) {
320
+ const names = relativeKeys.map((key) => toObjectName(getStorageKey(key)));
321
+ for (let offset = 0; offset < names.length; offset += DELETE_BATCH_SIZE) {
322
+ const { error } = await (await bucket()).remove(names.slice(offset, offset + DELETE_BATCH_SIZE));
323
+ if (error && !isNotFoundError(error)) throw new Error(`Failed to delete storage objects: ${error.message}`);
324
+ }
243
325
  }
244
326
  });
245
327
  };
@@ -1,13 +1,13 @@
1
- import { EngineDatabase, StorageAdapterWith } from "@hot-updater/plugin-core";
1
+ import { EngineDatabase, Lazy, StorageAdapterWith } from "@hot-updater/plugin-core";
2
2
  //#region src/supabaseConfig.d.ts
3
3
  type SupabaseServiceRoleConfig = {
4
4
  supabaseUrl: string;
5
5
  /**
6
6
  * The project's service role key, or a function that returns it, such as
7
- * one that reads it with `secretEnv`: called on the first request, so a
8
- * config loads without the key.
7
+ * `secret("<name>")` in `hot-updater.config.ts`: called on the first
8
+ * request, so a config loads without the key.
9
9
  */
10
- supabaseServiceRoleKey: string | (() => string | Promise<string>);
10
+ supabaseServiceRoleKey: Lazy<string>;
11
11
  };
12
12
  //#endregion
13
13
  //#region src/supabaseDatabase.d.ts
@@ -28,6 +28,6 @@ type SupabaseStorageConfig = SupabaseServiceRoleConfig & {
28
28
  /** Signed download URL lifetime in seconds. @default 3600 */
29
29
  signedUrlExpiresIn?: number;
30
30
  };
31
- declare const supabaseStorage: (config: SupabaseStorageConfig) => StorageAdapterWith<"put" | "get" | "getDownloadUrl" | "exists" | "delete">;
31
+ declare const supabaseStorage: (config: SupabaseStorageConfig) => StorageAdapterWith<"put" | "get" | "getDownloadUrl" | "exists" | "delete" | "listObjects" | "deleteObjects">;
32
32
  //#endregion
33
33
  export { supabaseDatabase as i, supabaseStorage as n, SupabaseDatabaseConfig as r, SupabaseStorageConfig as t };
@@ -1,13 +1,13 @@
1
- import { EngineDatabase, StorageAdapterWith } from "@hot-updater/plugin-core";
1
+ import { EngineDatabase, Lazy, StorageAdapterWith } from "@hot-updater/plugin-core";
2
2
  //#region src/supabaseConfig.d.ts
3
3
  type SupabaseServiceRoleConfig = {
4
4
  supabaseUrl: string;
5
5
  /**
6
6
  * The project's service role key, or a function that returns it, such as
7
- * one that reads it with `secretEnv`: called on the first request, so a
8
- * config loads without the key.
7
+ * `secret("<name>")` in `hot-updater.config.ts`: called on the first
8
+ * request, so a config loads without the key.
9
9
  */
10
- supabaseServiceRoleKey: string | (() => string | Promise<string>);
10
+ supabaseServiceRoleKey: Lazy<string>;
11
11
  };
12
12
  //#endregion
13
13
  //#region src/supabaseDatabase.d.ts
@@ -28,6 +28,6 @@ type SupabaseStorageConfig = SupabaseServiceRoleConfig & {
28
28
  /** Signed download URL lifetime in seconds. @default 3600 */
29
29
  signedUrlExpiresIn?: number;
30
30
  };
31
- declare const supabaseStorage: (config: SupabaseStorageConfig) => StorageAdapterWith<"put" | "get" | "getDownloadUrl" | "exists" | "delete">;
31
+ declare const supabaseStorage: (config: SupabaseStorageConfig) => StorageAdapterWith<"put" | "get" | "getDownloadUrl" | "exists" | "delete" | "listObjects" | "deleteObjects">;
32
32
  //#endregion
33
33
  export { supabaseDatabase as i, supabaseStorage as n, SupabaseDatabaseConfig as r, SupabaseStorageConfig as t };
@@ -166,7 +166,15 @@ const isMissingObjectError = async (error) => {
166
166
  };
167
167
  /** A character Storage rejects in an object name, `?`, or `!`. */
168
168
  const ESCAPED_CHARACTER = /[^A-Za-z0-9_/.*'() &$=@;:+,-]/gu;
169
+ const ESCAPE_SEQUENCE = /!([0-9A-F]{2})/gu;
169
170
  const utf8 = new TextEncoder();
171
+ const utf8Decoder = new TextDecoder("utf-8", { fatal: true });
172
+ /** Objects Storage lists a page at a time. */
173
+ const LIST_PAGE_SIZE = 1e3;
174
+ /** Names Storage removes in one request. */
175
+ const DELETE_BATCH_SIZE = 1e3;
176
+ /** The object the Supabase dashboard keeps in a folder it creates. */
177
+ const EMPTY_FOLDER_PLACEHOLDER = ".emptyFolderPlaceholder";
170
178
  /**
171
179
  * The object name Storage keeps a key under. Storage accepts names of ASCII
172
180
  * letters, digits and `_/!.*'() &$=@;:+,?-` only, and supabase-js puts a name
@@ -177,6 +185,34 @@ const utf8 = new TextEncoder();
177
185
  * Deploy's keys, such as `<bundleId>/manifest.json`, are stored as they are.
178
186
  */
179
187
  const toObjectName = (key) => key.replace(ESCAPED_CHARACTER, (character) => Array.from(utf8.encode(character), (byte) => `!${byte.toString(16).toUpperCase().padStart(2, "0")}`).join(""));
188
+ /** The key `toObjectName` stored under `name`, or null for a name it never makes. */
189
+ const fromObjectName = (name) => {
190
+ const bytes = [];
191
+ const parts = [];
192
+ const flush = () => {
193
+ if (bytes.length === 0) return true;
194
+ try {
195
+ parts.push(utf8Decoder.decode(new Uint8Array(bytes)));
196
+ } catch {
197
+ return false;
198
+ }
199
+ bytes.length = 0;
200
+ return true;
201
+ };
202
+ let index = 0;
203
+ for (const match of name.matchAll(ESCAPE_SEQUENCE)) {
204
+ if (match.index !== index) {
205
+ if (!flush()) return null;
206
+ parts.push(name.slice(index, match.index));
207
+ }
208
+ bytes.push(Number.parseInt(match[1], 16));
209
+ index = match.index + match[0].length;
210
+ }
211
+ if (!flush()) return null;
212
+ parts.push(name.slice(index));
213
+ const key = parts.join("");
214
+ return toObjectName(key) === name ? key : null;
215
+ };
180
216
  const supabaseStorage = (config) => {
181
217
  let client;
182
218
  const bucket = async () => (await (client ??= resolveSupabaseServiceRoleKey(config).then((key) => (0, _supabase_supabase_js.createClient)(config.supabaseUrl, key), (error) => {
@@ -184,6 +220,7 @@ const supabaseStorage = (config) => {
184
220
  throw error;
185
221
  }))).storage.from(config.bucketName);
186
222
  const getStorageKey = (0, _hot_updater_plugin_core.createStorageKeyBuilder)(config.basePath);
223
+ const basePrefix = getStorageKey() ? `${getStorageKey()}/` : "";
187
224
  const resolveSignedUrl = createSupabaseSignedUrlBatcher({
188
225
  createSignedUrls: async (_bucketName, keys, expiresIn) => (await bucket()).createSignedUrls(keys, expiresIn),
189
226
  expiresIn: config.signedUrlExpiresIn ?? 3600,
@@ -240,6 +277,51 @@ const supabaseStorage = (config) => {
240
277
  const { error } = await (await bucket()).remove([toObjectName(key)]);
241
278
  if (error && !isNotFoundError(error)) throw new Error(`Failed to delete storage object: ${error.message}`);
242
279
  return { deleted: true };
280
+ },
281
+ async listObjects(prefix) {
282
+ const objects = [];
283
+ const folder = toObjectName(getStorageKey(prefix ?? ""));
284
+ let cursor;
285
+ do {
286
+ const { data, error } = await (await bucket()).listV2({
287
+ prefix: folder ? `${folder}/` : "",
288
+ limit: LIST_PAGE_SIZE,
289
+ ...cursor === void 0 ? {} : { cursor }
290
+ });
291
+ if (error) throw new Error(`Failed to list storage objects: ${error.message}`);
292
+ for (const entry of data.objects) {
293
+ const name = entry.key ?? entry.name;
294
+ if (name.split("/").at(-1) === EMPTY_FOLDER_PLACEHOLDER) continue;
295
+ const key = fromObjectName(name);
296
+ if (key === null || !key.startsWith(basePrefix)) continue;
297
+ let storageUri;
298
+ try {
299
+ storageUri = (0, _hot_updater_plugin_core.createStorageUri)({
300
+ protocol: "supabase-storage",
301
+ bucket: config.bucketName,
302
+ key
303
+ });
304
+ } catch {
305
+ continue;
306
+ }
307
+ const updatedAt = entry.updated_at ?? entry.created_at;
308
+ objects.push({
309
+ key: key.slice(basePrefix.length),
310
+ ...updatedAt ? { lastModifiedAt: new Date(updatedAt) } : {},
311
+ size: Number(entry.metadata?.size ?? 0),
312
+ storageUri
313
+ });
314
+ }
315
+ cursor = data.hasNext ? data.nextCursor : void 0;
316
+ } while (cursor !== void 0);
317
+ return objects;
318
+ },
319
+ async deleteObjects(relativeKeys) {
320
+ const names = relativeKeys.map((key) => toObjectName(getStorageKey(key)));
321
+ for (let offset = 0; offset < names.length; offset += DELETE_BATCH_SIZE) {
322
+ const { error } = await (await bucket()).remove(names.slice(offset, offset + DELETE_BATCH_SIZE));
323
+ if (error && !isNotFoundError(error)) throw new Error(`Failed to delete storage objects: ${error.message}`);
324
+ }
243
325
  }
244
326
  });
245
327
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/supabase",
3
3
  "type": "module",
4
- "version": "1.2.0-rc.5",
4
+ "version": "1.2.0-rc.51",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.mjs",
@@ -51,10 +51,10 @@
51
51
  "@supabase/supabase-js": "2.76.1",
52
52
  "hono": "4.12.34",
53
53
  "uuidv7": "^1.0.2",
54
- "@hot-updater/protocol": "1.2.0-rc.5",
55
- "@hot-updater/cli-tools": "1.2.0-rc.5",
56
- "@hot-updater/plugin-core": "1.2.0-rc.5",
57
- "@hot-updater/server": "1.2.0-rc.5"
54
+ "@hot-updater/plugin-core": "1.2.0-rc.51",
55
+ "@hot-updater/protocol": "1.2.0-rc.51",
56
+ "@hot-updater/cli-tools": "1.2.0-rc.51",
57
+ "@hot-updater/server": "1.2.0-rc.51"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@electric-sql/pglite": "0.4.1",
@@ -64,9 +64,9 @@
64
64
  "execa": "9.5.2",
65
65
  "@types/node": "^20",
66
66
  "mime": "^4.0.4",
67
- "@hot-updater/mock": "1.2.0-rc.5",
68
- "@hot-updater/test-utils": "1.2.0-rc.5",
69
- "@hot-updater/postgres": "1.2.0-rc.5"
67
+ "@hot-updater/mock": "1.2.0-rc.51",
68
+ "@hot-updater/test-utils": "1.2.0-rc.51",
69
+ "@hot-updater/postgres": "1.2.0-rc.51"
70
70
  },
71
71
  "scripts": {
72
72
  "build": "tsdown",
@@ -1,17 +1,45 @@
1
1
  -- HotUpdater.schema
2
2
 
3
- CREATE TABLE IF NOT EXISTS "hot_updater_v1_native_builds" ("id" varchar(36) COLLATE "C" NOT NULL, "scope_key" varchar(2048) COLLATE "C" NOT NULL, "platform" varchar(16) COLLATE "C" NOT NULL, "channel_id" varchar(1408) COLLATE "C" NOT NULL, "fingerprint_hash" varchar(255) COLLATE "C", "app_version" text COLLATE "C", "min_bundle_id" varchar(36) COLLATE "C" NOT NULL, "artifact_kind" varchar(16) COLLATE "C" NOT NULL, "artifact_storage_uri" text COLLATE "C" NOT NULL, "byte_size" bigint NOT NULL, "git_commit_hash" varchar(255) COLLATE "C", "created_at_ms" bigint NOT NULL, "build_key" varchar(69) COLLATE "C", "build_number" varchar(64) COLLATE "C", "submitted_to" varchar(16) COLLATE "C", "submitted_at_ms" bigint, "submitted_version" varchar(255) COLLATE "C", "_v" bigint NOT NULL DEFAULT 0, PRIMARY KEY ("id"));
3
+ ALTER TABLE "hot_updater_v1_releases" ADD COLUMN IF NOT EXISTS "label" bigint;
4
+
5
+ CREATE UNIQUE INDEX IF NOT EXISTS "hot_updater_v1_releases_byLabel" ON "hot_updater_v1_releases" ("channel_id", "platform", "label");
6
+
7
+ CREATE TABLE IF NOT EXISTS "hot_updater_v1_native_builds" ("id" varchar(36) COLLATE "C" NOT NULL, "scope_key" varchar(2048) COLLATE "C" NOT NULL, "platform" varchar(16) COLLATE "C" NOT NULL, "channel_id" varchar(1408) COLLATE "C" NOT NULL, "fingerprint_hash" varchar(255) COLLATE "C", "app_version" text COLLATE "C", "min_bundle_id" varchar(36) COLLATE "C" NOT NULL, "artifact_kind" varchar(16) COLLATE "C" NOT NULL, "artifact_storage_uri" text COLLATE "C" NOT NULL, "byte_size" bigint NOT NULL, "git_commit_hash" varchar(255) COLLATE "C", "created_at_ms" bigint NOT NULL, "build_key" varchar(69) COLLATE "C", "build_number" varchar(64) COLLATE "C", "submitted_to" varchar(16) COLLATE "C", "submitted_at_ms" bigint, "submitted_version" varchar(255) COLLATE "C", "is_store_build" boolean NOT NULL, "is_sandbox" boolean NOT NULL, "sandbox_url_scheme" varchar(255) COLLATE "C", "export_method" varchar(16) COLLATE "C", "native_app_version" text COLLATE "C", "store_build_scope_key" varchar(2048) COLLATE "C", "_v" bigint NOT NULL DEFAULT 0, PRIMARY KEY ("id"));
4
8
 
5
9
  CREATE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_byScope" ON "hot_updater_v1_native_builds" ("scope_key", "id");
6
10
 
7
11
  CREATE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_byBuildKey" ON "hot_updater_v1_native_builds" ("scope_key", "build_key", "id");
8
12
 
13
+ CREATE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_byScopeKind" ON "hot_updater_v1_native_builds" ("scope_key", "artifact_kind", "id");
14
+
15
+ CREATE UNIQUE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_byStoreBuild" ON "hot_updater_v1_native_builds" ("store_build_scope_key");
16
+
9
17
  CREATE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_byChannel" ON "hot_updater_v1_native_builds" ("channel_id", "id");
10
18
 
11
19
  CREATE UNIQUE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_min_bundle_id" ON "hot_updater_v1_native_builds" ("min_bundle_id");
12
20
 
21
+ CREATE TABLE IF NOT EXISTS "hot_updater_v1_ios_devices" ("id" varchar(36) COLLATE "C" NOT NULL, "udid" varchar(40) COLLATE "C" NOT NULL, "name" varchar(100) COLLATE "C" NOT NULL, "status" varchar(16) COLLATE "C" NOT NULL, "requested_by" varchar(320) COLLATE "C", "created_at_ms" bigint NOT NULL, "approved_by" varchar(320) COLLATE "C", "approved_at_ms" bigint, "registered_at_ms" bigint, "apple_issuer_id" varchar(64) COLLATE "C", "apple_error" varchar(512) COLLATE "C", "build_id" varchar(36) COLLATE "C", "_v" bigint NOT NULL DEFAULT 0, PRIMARY KEY ("id"));
22
+
23
+ CREATE INDEX IF NOT EXISTS "hot_updater_v1_ios_devices_byStatus" ON "hot_updater_v1_ios_devices" ("status", "id");
24
+
25
+ CREATE INDEX IF NOT EXISTS "hot_updater_v1_ios_devices_byRegistration" ON "hot_updater_v1_ios_devices" ("registered_at_ms", "id");
26
+
27
+ CREATE UNIQUE INDEX IF NOT EXISTS "hot_updater_v1_ios_devices_udid" ON "hot_updater_v1_ios_devices" ("udid");
28
+
29
+ CREATE TABLE IF NOT EXISTS "hot_updater_v1_ios_device_account" ("id" varchar(16) COLLATE "C" NOT NULL, "apple_issuer_id" varchar(64) COLLATE "C" NOT NULL, "claimed_at_ms" bigint NOT NULL, "_v" bigint NOT NULL DEFAULT 0, PRIMARY KEY ("id"));
30
+
31
+ CREATE TABLE IF NOT EXISTS "hot_updater_v1_label_sequences" ("id" varchar(1440) COLLATE "C" NOT NULL, "last_label" bigint NOT NULL, "is_filled" boolean NOT NULL, "_v" bigint NOT NULL DEFAULT 0, PRIMARY KEY ("id"));
32
+
33
+ CREATE INDEX IF NOT EXISTS "hot_updater_v1_bundle_events__byBundle__key" ON "hot_updater_v1_bundle_events__byBundle" ("id");
34
+
13
35
  ALTER TABLE "hot_updater_v1_native_builds" ENABLE ROW LEVEL SECURITY;
14
36
 
37
+ ALTER TABLE "hot_updater_v1_ios_devices" ENABLE ROW LEVEL SECURITY;
38
+
39
+ ALTER TABLE "hot_updater_v1_ios_device_account" ENABLE ROW LEVEL SECURITY;
40
+
41
+ ALTER TABLE "hot_updater_v1_label_sequences" ENABLE ROW LEVEL SECURITY;
42
+
15
43
  CREATE OR REPLACE FUNCTION public.hot_updater_v1_apply(p_statements jsonb)
16
44
  RETURNS jsonb
17
45
  LANGUAGE plpgsql
@@ -31,7 +59,7 @@ BEGIN
31
59
  FOR item IN SELECT value FROM jsonb_array_elements(p_statements) LOOP
32
60
  statement := item->>'sql';
33
61
  FOR target IN SELECT (regexp_matches(statement, '(?:FROM|INTO|UPDATE|JOIN) "([^"]+)"', 'g'))[1] LOOP
34
- IF NOT target = ANY (ARRAY['hot_updater_v1_bundles', 'hot_updater_v1_bundle_patches', 'hot_updater_v1_releases', 'hot_updater_v1_release_catalogs', 'hot_updater_v1_channels', 'hot_updater_v1_bundle_totals', 'hot_updater_v1_native_builds', 'hot_updater_v1_bundle_events', 'hot_updater_v1_bundle_events__byBundle', 'hot_updater_v1_bundle_event_heads', 'hot_updater_v1_insights_overview', 'hot_updater_v1_insights_sketches', 'hot_updater_v1_insights_overview_daily', 'hot_updater_v1_insights_sketches_daily', 'hot_updater_v1_insights_overview_lifetime', 'hot_updater_v1_insights_sketches_lifetime', 'hot_updater_v1_insights_distribution', 'hot_updater_v1_insights_builtin_distribution', 'hot_updater_v1_insights_latest_by_bundle', 'hot_updater_v1_insights_outcomes', 'hot_updater_v1_insights_failures', 'hot_updater_v1_api_keys', 'hot_updater_v1_remote_config_active', 'hot_updater_v1_remote_config_versions', 'hot_updater_v1_private_hot_updater_settings', 'hot_updater_v1__hu_write']) THEN
62
+ IF NOT target = ANY (ARRAY['hot_updater_v1_bundles', 'hot_updater_v1_bundle_patches', 'hot_updater_v1_releases', 'hot_updater_v1_release_catalogs', 'hot_updater_v1_channels', 'hot_updater_v1_bundle_totals', 'hot_updater_v1_native_builds', 'hot_updater_v1_ios_devices', 'hot_updater_v1_ios_device_account', 'hot_updater_v1_label_sequences', 'hot_updater_v1_bundle_events', 'hot_updater_v1_bundle_events__byBundle', 'hot_updater_v1_bundle_event_heads', 'hot_updater_v1_insights_overview', 'hot_updater_v1_insights_sketches', 'hot_updater_v1_insights_overview_daily', 'hot_updater_v1_insights_sketches_daily', 'hot_updater_v1_insights_overview_lifetime', 'hot_updater_v1_insights_sketches_lifetime', 'hot_updater_v1_insights_distribution', 'hot_updater_v1_insights_builtin_distribution', 'hot_updater_v1_insights_latest_by_bundle', 'hot_updater_v1_insights_outcomes', 'hot_updater_v1_insights_failures', 'hot_updater_v1_api_keys', 'hot_updater_v1_remote_config_active', 'hot_updater_v1_remote_config_versions', 'hot_updater_v1_private_hot_updater_settings', 'hot_updater_v1__hu_write']) THEN
35
63
  RAISE EXCEPTION 'hot_updater_v1_apply: % is not a Hot Updater table', target USING ERRCODE = '42501';
36
64
  END IF;
37
65
  END LOOP;