@hot-updater/supabase 1.2.0-rc.3 → 1.2.0-rc.31
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 +1 -1
- package/dist/edge.d.cts +1 -1
- package/dist/edge.d.mts +1 -1
- package/dist/edge.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/init/index.cjs +87 -42
- package/dist/init/index.d.cts +3 -2
- package/dist/init/index.d.mts +3 -2
- package/dist/init/index.mjs +87 -42
- package/dist/{supabaseStorage-D4jcGa-l.mjs → supabaseStorage-B6IM8UX2.mjs} +106 -12
- package/dist/{supabaseStorage-BryXQ72m.d.cts → supabaseStorage-C9W-69OP.d.cts} +8 -3
- package/dist/{supabaseStorage-BryXQ72m.d.mts → supabaseStorage-C9W-69OP.d.mts} +8 -3
- package/dist/{supabaseStorage-MqoRcaii.cjs → supabaseStorage-DUa49vGh.cjs} +106 -12
- package/package.json +8 -8
- package/supabase/migrations/0002_hot-updater_1.2.0.sql +16 -2
package/dist/edge.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_supabaseStorage = require("./supabaseStorage-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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. */
|
package/dist/init/index.cjs
CHANGED
|
@@ -6333,9 +6333,11 @@ createExeca(mapScriptAsync, {}, deepScriptOptions, setScriptSync);
|
|
|
6333
6333
|
const { sendMessage, getOneMessage, getEachMessage, getCancelSignal } = getIpcExport();
|
|
6334
6334
|
//#endregion
|
|
6335
6335
|
//#region src/supabaseConfig.ts
|
|
6336
|
-
const resolveSupabaseServiceRoleKey = (config) => {
|
|
6337
|
-
|
|
6338
|
-
|
|
6336
|
+
const resolveSupabaseServiceRoleKey = async (config) => {
|
|
6337
|
+
const { supabaseServiceRoleKey } = config;
|
|
6338
|
+
const key = typeof supabaseServiceRoleKey === "function" ? await supabaseServiceRoleKey() : supabaseServiceRoleKey;
|
|
6339
|
+
if (!key) throw new Error("Supabase service role key is required. Set supabaseServiceRoleKey.");
|
|
6340
|
+
return key;
|
|
6339
6341
|
};
|
|
6340
6342
|
//#endregion
|
|
6341
6343
|
//#region src/supabaseInfrastructureNames.ts
|
|
@@ -6375,9 +6377,16 @@ const withCode = (error) => Object.assign(new Error(error.message, { cause: erro
|
|
|
6375
6377
|
*/
|
|
6376
6378
|
const supabaseExecutor = (client) => {
|
|
6377
6379
|
let created;
|
|
6378
|
-
const clientOf = () =>
|
|
6380
|
+
const clientOf = async () => {
|
|
6381
|
+
if (typeof client !== "function") return client;
|
|
6382
|
+
created ??= Promise.resolve().then(client).catch((error) => {
|
|
6383
|
+
created = void 0;
|
|
6384
|
+
throw error;
|
|
6385
|
+
});
|
|
6386
|
+
return created;
|
|
6387
|
+
};
|
|
6379
6388
|
const apply = async (statements) => {
|
|
6380
|
-
const { data, error } = await clientOf().rpc(SUPABASE_APPLY_FUNCTION, { p_statements: statements.map(toApplyStatement) });
|
|
6389
|
+
const { data, error } = await (await clientOf()).rpc(SUPABASE_APPLY_FUNCTION, { p_statements: statements.map(toApplyStatement) });
|
|
6381
6390
|
if (error) throw withCode(error);
|
|
6382
6391
|
return data;
|
|
6383
6392
|
};
|
|
@@ -6400,7 +6409,7 @@ const supabaseExecutor = (client) => {
|
|
|
6400
6409
|
*/
|
|
6401
6410
|
const supabaseDatabase = (config) => {
|
|
6402
6411
|
const { migrations: _migrations, ...adapter } = (0, _hot_updater_plugin_core.createSqlAdapter)({
|
|
6403
|
-
executor: supabaseExecutor(() => (0, _supabase_supabase_js.createClient)(config.supabaseUrl, resolveSupabaseServiceRoleKey(config))),
|
|
6412
|
+
executor: supabaseExecutor(async () => (0, _supabase_supabase_js.createClient)(config.supabaseUrl, await resolveSupabaseServiceRoleKey(config))),
|
|
6404
6413
|
tablePrefix: SUPABASE_TABLE_PREFIX
|
|
6405
6414
|
});
|
|
6406
6415
|
return (0, _hot_updater_plugin_core.createEngineDatabase)({
|
|
@@ -6410,27 +6419,39 @@ const supabaseDatabase = (config) => {
|
|
|
6410
6419
|
};
|
|
6411
6420
|
//#endregion
|
|
6412
6421
|
//#region iac/configTemplate.ts
|
|
6413
|
-
|
|
6414
|
-
|
|
6422
|
+
/**
|
|
6423
|
+
* The config init writes. With the `resources` init set up, it names them,
|
|
6424
|
+
* and reads the service role key with `secret()`, from the environment and
|
|
6425
|
+
* `.env.hotupdater`, then the config's `secrets` adapter. Without them, as
|
|
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.
|
|
6429
|
+
*/
|
|
6430
|
+
const getConfigScaffold = (build, resources) => {
|
|
6431
|
+
const supabaseUrl = resources === void 0 ? "process.env.HOT_UPDATER_SUPABASE_URL!" : JSON.stringify(resources.supabaseUrl);
|
|
6432
|
+
const serviceRoleKey = "secret(\"HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY\")";
|
|
6433
|
+
const storageConfig = {
|
|
6415
6434
|
imports: [{
|
|
6416
6435
|
pkg: "@hot-updater/supabase",
|
|
6417
6436
|
named: ["supabaseStorage"]
|
|
6418
6437
|
}],
|
|
6419
6438
|
configString: `supabaseStorage({
|
|
6420
|
-
supabaseUrl:
|
|
6421
|
-
supabaseServiceRoleKey:
|
|
6422
|
-
bucketName: process.env.HOT_UPDATER_SUPABASE_BUCKET_NAME
|
|
6439
|
+
supabaseUrl: ${supabaseUrl},
|
|
6440
|
+
supabaseServiceRoleKey: ${serviceRoleKey},
|
|
6441
|
+
bucketName: ${resources === void 0 ? "process.env.HOT_UPDATER_SUPABASE_BUCKET_NAME!" : JSON.stringify(resources.bucketName)},
|
|
6423
6442
|
})`
|
|
6424
|
-
}
|
|
6443
|
+
};
|
|
6444
|
+
const databaseConfig = {
|
|
6425
6445
|
imports: [{
|
|
6426
6446
|
pkg: "@hot-updater/supabase",
|
|
6427
6447
|
named: ["supabaseDatabase"]
|
|
6428
6448
|
}],
|
|
6429
6449
|
configString: `supabaseDatabase({
|
|
6430
|
-
supabaseUrl:
|
|
6431
|
-
supabaseServiceRoleKey:
|
|
6450
|
+
supabaseUrl: ${supabaseUrl},
|
|
6451
|
+
supabaseServiceRoleKey: ${serviceRoleKey},
|
|
6432
6452
|
})`
|
|
6433
|
-
}
|
|
6453
|
+
};
|
|
6454
|
+
const builder = new _hot_updater_cli_tools.ConfigBuilder().setBuildType(build).setStorage(storageConfig).setDatabase(databaseConfig).setPlugins({
|
|
6434
6455
|
imports: [{
|
|
6435
6456
|
pkg: "hot-updater/plugins",
|
|
6436
6457
|
named: [
|
|
@@ -6440,7 +6461,12 @@ const getConfigScaffold = (build) => {
|
|
|
6440
6461
|
]
|
|
6441
6462
|
}],
|
|
6442
6463
|
configString: "[apiKeys(), insights(), remoteConfig()]"
|
|
6443
|
-
})
|
|
6464
|
+
});
|
|
6465
|
+
builder.addImport({
|
|
6466
|
+
pkg: "hot-updater",
|
|
6467
|
+
named: ["secret"]
|
|
6468
|
+
});
|
|
6469
|
+
return (0, _hot_updater_cli_tools.createHotUpdaterConfigScaffoldFromBuilder)(builder);
|
|
6444
6470
|
};
|
|
6445
6471
|
//#endregion
|
|
6446
6472
|
//#region iac/init/index.ts
|
|
@@ -6546,7 +6572,8 @@ const initProvider = {
|
|
|
6546
6572
|
type: "password"
|
|
6547
6573
|
}
|
|
6548
6574
|
}
|
|
6549
|
-
}
|
|
6575
|
+
},
|
|
6576
|
+
secrets: ["HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY"]
|
|
6550
6577
|
};
|
|
6551
6578
|
//#endregion
|
|
6552
6579
|
//#region iac/supabaseApi.ts
|
|
@@ -6578,6 +6605,17 @@ const supabaseApi = (supabaseUrl, supabaseServiceRoleKey) => {
|
|
|
6578
6605
|
};
|
|
6579
6606
|
};
|
|
6580
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
|
|
6581
6619
|
//#region iac/supabaseAuthentication.ts
|
|
6582
6620
|
const SUPABASE_AUTH_METHOD = {
|
|
6583
6621
|
accessToken: "access-token",
|
|
@@ -6598,7 +6636,7 @@ const openBrowser = async (url) => {
|
|
|
6598
6636
|
const hasValidSupabaseCliLogin = async () => {
|
|
6599
6637
|
return (await execa("npx", [
|
|
6600
6638
|
"-y",
|
|
6601
|
-
|
|
6639
|
+
SUPABASE_CLI,
|
|
6602
6640
|
"projects",
|
|
6603
6641
|
"list",
|
|
6604
6642
|
"--output",
|
|
@@ -6625,7 +6663,7 @@ const inputSupabaseAccessToken = async (accessToken) => {
|
|
|
6625
6663
|
if (await hasValidSupabaseCliLogin()) return;
|
|
6626
6664
|
const loginProcess = execa("npx", [
|
|
6627
6665
|
"-y",
|
|
6628
|
-
|
|
6666
|
+
SUPABASE_CLI,
|
|
6629
6667
|
"login",
|
|
6630
6668
|
"--no-browser",
|
|
6631
6669
|
"--agent",
|
|
@@ -6697,7 +6735,7 @@ const supabaseDatabaseCommandErrorMessage = (err, { dbPassword, stderrInherited
|
|
|
6697
6735
|
};
|
|
6698
6736
|
const handleSupabaseDatabaseCommandError = (err, options) => {
|
|
6699
6737
|
if (err instanceof ExecaError) _hot_updater_cli_tools.p.log.error(supabaseDatabaseCommandErrorMessage(err, options));
|
|
6700
|
-
else
|
|
6738
|
+
else _hot_updater_cli_tools.p.log.error(err instanceof Error ? err.message : String(err));
|
|
6701
6739
|
process.exit(1);
|
|
6702
6740
|
};
|
|
6703
6741
|
const confirmSupabaseDatabaseMigrations = async ({ nonInteractive }) => {
|
|
@@ -6710,9 +6748,9 @@ const confirmSupabaseDatabaseMigrations = async ({ nonInteractive }) => {
|
|
|
6710
6748
|
const runSupabaseLink = async (workdir, { accessToken, projectId, dbPassword }) => {
|
|
6711
6749
|
await fs_promises.default.writeFile(path.default.join(workdir, "supabase", "config.toml"), (0, _hot_updater_cli_tools.transformTemplate)(SUPABASE_CONFIG_TEMPLATE, { projectId }));
|
|
6712
6750
|
await execa("npx", [
|
|
6713
|
-
"
|
|
6751
|
+
"-y",
|
|
6752
|
+
SUPABASE_CLI,
|
|
6714
6753
|
"link",
|
|
6715
|
-
"--project-ref",
|
|
6716
6754
|
projectId,
|
|
6717
6755
|
"--workdir",
|
|
6718
6756
|
workdir
|
|
@@ -6741,10 +6779,11 @@ const linkSupabase = async (workdir, options) => {
|
|
|
6741
6779
|
/** Pushes the workdir's migrations the linked project has not run, after its own history. */
|
|
6742
6780
|
const runSupabasePush = async (workdir, { accessToken, dbPassword, quiet = false }) => {
|
|
6743
6781
|
await execa("npx", [
|
|
6744
|
-
"
|
|
6782
|
+
"-y",
|
|
6783
|
+
SUPABASE_CLI,
|
|
6745
6784
|
"migration",
|
|
6746
6785
|
"fetch",
|
|
6747
|
-
"--
|
|
6786
|
+
"--remote",
|
|
6748
6787
|
"--yes",
|
|
6749
6788
|
"--workdir",
|
|
6750
6789
|
workdir
|
|
@@ -6756,10 +6795,12 @@ const runSupabasePush = async (workdir, { accessToken, dbPassword, quiet = false
|
|
|
6756
6795
|
throw error;
|
|
6757
6796
|
});
|
|
6758
6797
|
return execa("npx", [
|
|
6759
|
-
"
|
|
6798
|
+
"-y",
|
|
6799
|
+
SUPABASE_CLI,
|
|
6760
6800
|
"db",
|
|
6761
6801
|
"push",
|
|
6762
6802
|
"--include-all",
|
|
6803
|
+
"--remote",
|
|
6763
6804
|
"--yes",
|
|
6764
6805
|
"--workdir",
|
|
6765
6806
|
workdir
|
|
@@ -6922,7 +6963,7 @@ const isRecord$1 = (value) => typeof value === "object" && value !== null;
|
|
|
6922
6963
|
const runSupabaseCli = async (args) => {
|
|
6923
6964
|
const result = await execa("npx", [
|
|
6924
6965
|
"-y",
|
|
6925
|
-
|
|
6966
|
+
SUPABASE_CLI,
|
|
6926
6967
|
...args
|
|
6927
6968
|
], { env: void 0 });
|
|
6928
6969
|
return JSON.parse(result.stdout);
|
|
@@ -6945,15 +6986,14 @@ const supabaseCliManagementApi = () => ({
|
|
|
6945
6986
|
listFunctions: async (projectId) => parseSupabaseFunctionSlugs(await runSupabaseCli([
|
|
6946
6987
|
"functions",
|
|
6947
6988
|
"list",
|
|
6948
|
-
|
|
6949
|
-
projectId,
|
|
6989
|
+
`--remote=${projectId}`,
|
|
6950
6990
|
"--output",
|
|
6951
6991
|
"json"
|
|
6952
6992
|
])),
|
|
6953
6993
|
createProject: async ({ name, organizationSlug, region }) => {
|
|
6954
6994
|
await execa("npx", [
|
|
6955
6995
|
"-y",
|
|
6956
|
-
|
|
6996
|
+
SUPABASE_CLI,
|
|
6957
6997
|
"projects",
|
|
6958
6998
|
"create",
|
|
6959
6999
|
name,
|
|
@@ -6961,6 +7001,7 @@ const supabaseCliManagementApi = () => ({
|
|
|
6961
7001
|
organizationSlug,
|
|
6962
7002
|
"--region",
|
|
6963
7003
|
region,
|
|
7004
|
+
"--yes",
|
|
6964
7005
|
"--agent",
|
|
6965
7006
|
"no"
|
|
6966
7007
|
], { stdio: "inherit" });
|
|
@@ -7249,7 +7290,7 @@ const selectProject = async (preferredProjectId, nonInteractive = false, accessT
|
|
|
7249
7290
|
try {
|
|
7250
7291
|
const listProjects = await execa("npx", [
|
|
7251
7292
|
"-y",
|
|
7252
|
-
|
|
7293
|
+
SUPABASE_CLI,
|
|
7253
7294
|
"projects",
|
|
7254
7295
|
"list",
|
|
7255
7296
|
"--output",
|
|
@@ -7259,7 +7300,7 @@ const selectProject = async (preferredProjectId, nonInteractive = false, accessT
|
|
|
7259
7300
|
} catch (err) {
|
|
7260
7301
|
spinner.stop();
|
|
7261
7302
|
const message = err instanceof Error ? err.message : String(err);
|
|
7262
|
-
|
|
7303
|
+
_hot_updater_cli_tools.p.log.error(`Failed to fetch Supabase projects: ${message}`);
|
|
7263
7304
|
process.exit(1);
|
|
7264
7305
|
}
|
|
7265
7306
|
spinner.stop();
|
|
@@ -7410,13 +7451,14 @@ const deployEdgeFunction = async (accessToken, workdir, projectId, functionName)
|
|
|
7410
7451
|
task: async () => {
|
|
7411
7452
|
try {
|
|
7412
7453
|
return (await execa("npx", [
|
|
7413
|
-
"
|
|
7454
|
+
"-y",
|
|
7455
|
+
SUPABASE_CLI,
|
|
7414
7456
|
"functions",
|
|
7415
7457
|
"deploy",
|
|
7416
7458
|
functionName,
|
|
7417
|
-
|
|
7418
|
-
projectId,
|
|
7459
|
+
`--remote=${projectId}`,
|
|
7419
7460
|
"--no-verify-jwt",
|
|
7461
|
+
"--yes",
|
|
7420
7462
|
"--workdir",
|
|
7421
7463
|
workdir
|
|
7422
7464
|
], {
|
|
@@ -7455,11 +7497,10 @@ const getSupabaseProjectAccess = async ({ accessToken, managementApi, project, w
|
|
|
7455
7497
|
const getServiceRoleApiKey = async () => {
|
|
7456
7498
|
const keysProcess = await execa("npx", [
|
|
7457
7499
|
"-y",
|
|
7458
|
-
|
|
7500
|
+
SUPABASE_CLI,
|
|
7459
7501
|
"projects",
|
|
7460
7502
|
"api-keys",
|
|
7461
|
-
|
|
7462
|
-
project.id,
|
|
7503
|
+
`--remote=${project.id}`,
|
|
7463
7504
|
"--output",
|
|
7464
7505
|
"json"
|
|
7465
7506
|
], { env: getSupabaseCliEnv(accessToken) });
|
|
@@ -7515,9 +7556,9 @@ const withSupabaseCliMetadataCleanup = async (cwd, operation) => {
|
|
|
7515
7556
|
});
|
|
7516
7557
|
}
|
|
7517
7558
|
};
|
|
7518
|
-
const runInitWithoutCliMetadata = async ({ build, envFile }) => {
|
|
7559
|
+
const runInitWithoutCliMetadata = async ({ build, envFile, secretsEnv }) => {
|
|
7519
7560
|
const nonInteractive = envFile !== void 0;
|
|
7520
|
-
const initEnvSources = await (0, _hot_updater_cli_tools.readHotUpdaterInitEnv)(process.cwd(), envFile);
|
|
7561
|
+
const initEnvSources = await (0, _hot_updater_cli_tools.readHotUpdaterInitEnv)(process.cwd(), envFile, secretsEnv);
|
|
7521
7562
|
const { inputEnv, managedEnv } = initEnvSources;
|
|
7522
7563
|
const initInputEnv = (0, _hot_updater_cli_tools.getHotUpdaterInitInputEnv)(initEnvSources, nonInteractive);
|
|
7523
7564
|
const savedInputs = resolveSupabaseInitInputs(initInputEnv, {
|
|
@@ -7596,6 +7637,7 @@ const runInitWithoutCliMetadata = async ({ build, envFile }) => {
|
|
|
7596
7637
|
const { tmpDir, removeTmpDir } = await (0, _hot_updater_cli_tools.copyDirToTmp)(scaffoldLibPath, "supabase");
|
|
7597
7638
|
let credential;
|
|
7598
7639
|
let clientPlugins = [];
|
|
7640
|
+
let resources;
|
|
7599
7641
|
try {
|
|
7600
7642
|
await stageEdgeFunction({
|
|
7601
7643
|
bucketName: bucketSelection.name,
|
|
@@ -7637,6 +7679,10 @@ const runInitWithoutCliMetadata = async ({ build, envFile }) => {
|
|
|
7637
7679
|
[initProvider.inputs.bucketName.envKey]: bucket.name,
|
|
7638
7680
|
HOT_UPDATER_SUPABASE_URL: `https://${project.id}.supabase.co`
|
|
7639
7681
|
});
|
|
7682
|
+
resources = {
|
|
7683
|
+
supabaseUrl: `https://${project.id}.supabase.co`,
|
|
7684
|
+
bucketName: bucket.name
|
|
7685
|
+
};
|
|
7640
7686
|
await linkSupabase(tmpDir, {
|
|
7641
7687
|
accessToken,
|
|
7642
7688
|
projectId: project.id,
|
|
@@ -7674,7 +7720,7 @@ const runInitWithoutCliMetadata = async ({ build, envFile }) => {
|
|
|
7674
7720
|
await removeTmpDir();
|
|
7675
7721
|
}
|
|
7676
7722
|
_hot_updater_cli_tools.p.log.success("Generated '.env.hotupdater' file with Supabase settings.");
|
|
7677
|
-
await (0, _hot_updater_cli_tools.writeHotUpdaterFiles)(getConfigScaffold(build), {
|
|
7723
|
+
await (0, _hot_updater_cli_tools.writeHotUpdaterFiles)(getConfigScaffold(build, resources), {
|
|
7678
7724
|
cwd: process.cwd(),
|
|
7679
7725
|
settings: "Supabase"
|
|
7680
7726
|
});
|
|
@@ -7687,8 +7733,7 @@ const runInitWithoutCliMetadata = async ({ build, envFile }) => {
|
|
|
7687
7733
|
clientPlugins
|
|
7688
7734
|
});
|
|
7689
7735
|
reportSupabaseOriginCatalogReady();
|
|
7690
|
-
|
|
7691
|
-
_hot_updater_cli_tools.p.log.success("Done! 🎉");
|
|
7736
|
+
return { nextSteps: [(0, _hot_updater_cli_tools.link)("https://hot-updater.dev/docs/managed/supabase#step-3-add-hotupdater-to-your-project")] };
|
|
7692
7737
|
};
|
|
7693
7738
|
const runInit = (options) => withSupabaseCliMetadataCleanup(process.cwd(), () => runInitWithoutCliMetadata(options));
|
|
7694
7739
|
//#endregion
|
package/dist/init/index.d.cts
CHANGED
|
@@ -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 {
|
|
@@ -99,6 +99,7 @@ declare const initProvider: {
|
|
|
99
99
|
};
|
|
100
100
|
};
|
|
101
101
|
};
|
|
102
|
+
readonly secrets: readonly ["HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY"];
|
|
102
103
|
};
|
|
103
104
|
//#endregion
|
|
104
105
|
//#region iac/supabaseManagementApi.d.ts
|
|
@@ -176,6 +177,6 @@ declare const getSupabaseProjectAccess: ({ accessToken, managementApi, project,
|
|
|
176
177
|
readonly serviceRoleApiKey: string;
|
|
177
178
|
}>;
|
|
178
179
|
declare const withSupabaseCliMetadataCleanup: <Result>(cwd: string, operation: () => Promise<Result>) => Promise<Result>;
|
|
179
|
-
declare const runInit: (options: RunInitOptions) => Promise<
|
|
180
|
+
declare const runInit: (options: RunInitOptions) => Promise<RunInitResult>;
|
|
180
181
|
//#endregion
|
|
181
182
|
export { SupabaseBucketSelection, SupabaseProjectSelection, createSelectedBucket, getSupabaseFunctionUrl, getSupabaseProjectAccess, initProvider, reportSupabaseOriginCatalogReady, resolveEdgeFunctionDenoConfig, runInit, selectBucket, selectProject, waitForSupabaseProjectReady, waitForSupabaseSchemaReady, withSupabaseCliMetadataCleanup };
|
package/dist/init/index.d.mts
CHANGED
|
@@ -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 {
|
|
@@ -99,6 +99,7 @@ declare const initProvider: {
|
|
|
99
99
|
};
|
|
100
100
|
};
|
|
101
101
|
};
|
|
102
|
+
readonly secrets: readonly ["HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY"];
|
|
102
103
|
};
|
|
103
104
|
//#endregion
|
|
104
105
|
//#region iac/supabaseManagementApi.d.ts
|
|
@@ -176,6 +177,6 @@ declare const getSupabaseProjectAccess: ({ accessToken, managementApi, project,
|
|
|
176
177
|
readonly serviceRoleApiKey: string;
|
|
177
178
|
}>;
|
|
178
179
|
declare const withSupabaseCliMetadataCleanup: <Result>(cwd: string, operation: () => Promise<Result>) => Promise<Result>;
|
|
179
|
-
declare const runInit: (options: RunInitOptions) => Promise<
|
|
180
|
+
declare const runInit: (options: RunInitOptions) => Promise<RunInitResult>;
|
|
180
181
|
//#endregion
|
|
181
182
|
export { SupabaseBucketSelection, SupabaseProjectSelection, createSelectedBucket, getSupabaseFunctionUrl, getSupabaseProjectAccess, initProvider, reportSupabaseOriginCatalogReady, resolveEdgeFunctionDenoConfig, runInit, selectBucket, selectProject, waitForSupabaseProjectReady, waitForSupabaseSchemaReady, withSupabaseCliMetadataCleanup };
|
package/dist/init/index.mjs
CHANGED
|
@@ -6328,9 +6328,11 @@ createExeca(mapScriptAsync, {}, deepScriptOptions, setScriptSync);
|
|
|
6328
6328
|
const { sendMessage, getOneMessage, getEachMessage, getCancelSignal } = getIpcExport();
|
|
6329
6329
|
//#endregion
|
|
6330
6330
|
//#region src/supabaseConfig.ts
|
|
6331
|
-
const resolveSupabaseServiceRoleKey = (config) => {
|
|
6332
|
-
|
|
6333
|
-
|
|
6331
|
+
const resolveSupabaseServiceRoleKey = async (config) => {
|
|
6332
|
+
const { supabaseServiceRoleKey } = config;
|
|
6333
|
+
const key = typeof supabaseServiceRoleKey === "function" ? await supabaseServiceRoleKey() : supabaseServiceRoleKey;
|
|
6334
|
+
if (!key) throw new Error("Supabase service role key is required. Set supabaseServiceRoleKey.");
|
|
6335
|
+
return key;
|
|
6334
6336
|
};
|
|
6335
6337
|
//#endregion
|
|
6336
6338
|
//#region src/supabaseInfrastructureNames.ts
|
|
@@ -6370,9 +6372,16 @@ const withCode = (error) => Object.assign(new Error(error.message, { cause: erro
|
|
|
6370
6372
|
*/
|
|
6371
6373
|
const supabaseExecutor = (client) => {
|
|
6372
6374
|
let created;
|
|
6373
|
-
const clientOf = () =>
|
|
6375
|
+
const clientOf = async () => {
|
|
6376
|
+
if (typeof client !== "function") return client;
|
|
6377
|
+
created ??= Promise.resolve().then(client).catch((error) => {
|
|
6378
|
+
created = void 0;
|
|
6379
|
+
throw error;
|
|
6380
|
+
});
|
|
6381
|
+
return created;
|
|
6382
|
+
};
|
|
6374
6383
|
const apply = async (statements) => {
|
|
6375
|
-
const { data, error } = await clientOf().rpc(SUPABASE_APPLY_FUNCTION, { p_statements: statements.map(toApplyStatement) });
|
|
6384
|
+
const { data, error } = await (await clientOf()).rpc(SUPABASE_APPLY_FUNCTION, { p_statements: statements.map(toApplyStatement) });
|
|
6376
6385
|
if (error) throw withCode(error);
|
|
6377
6386
|
return data;
|
|
6378
6387
|
};
|
|
@@ -6395,7 +6404,7 @@ const supabaseExecutor = (client) => {
|
|
|
6395
6404
|
*/
|
|
6396
6405
|
const supabaseDatabase = (config) => {
|
|
6397
6406
|
const { migrations: _migrations, ...adapter } = createSqlAdapter({
|
|
6398
|
-
executor: supabaseExecutor(() => createClient(config.supabaseUrl, resolveSupabaseServiceRoleKey(config))),
|
|
6407
|
+
executor: supabaseExecutor(async () => createClient(config.supabaseUrl, await resolveSupabaseServiceRoleKey(config))),
|
|
6399
6408
|
tablePrefix: SUPABASE_TABLE_PREFIX
|
|
6400
6409
|
});
|
|
6401
6410
|
return createEngineDatabase({
|
|
@@ -6405,27 +6414,39 @@ const supabaseDatabase = (config) => {
|
|
|
6405
6414
|
};
|
|
6406
6415
|
//#endregion
|
|
6407
6416
|
//#region iac/configTemplate.ts
|
|
6408
|
-
|
|
6409
|
-
|
|
6417
|
+
/**
|
|
6418
|
+
* The config init writes. With the `resources` init set up, it names them,
|
|
6419
|
+
* and reads the service role key with `secret()`, from the environment and
|
|
6420
|
+
* `.env.hotupdater`, then the config's `secrets` adapter. Without them, as
|
|
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.
|
|
6424
|
+
*/
|
|
6425
|
+
const getConfigScaffold = (build, resources) => {
|
|
6426
|
+
const supabaseUrl = resources === void 0 ? "process.env.HOT_UPDATER_SUPABASE_URL!" : JSON.stringify(resources.supabaseUrl);
|
|
6427
|
+
const serviceRoleKey = "secret(\"HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY\")";
|
|
6428
|
+
const storageConfig = {
|
|
6410
6429
|
imports: [{
|
|
6411
6430
|
pkg: "@hot-updater/supabase",
|
|
6412
6431
|
named: ["supabaseStorage"]
|
|
6413
6432
|
}],
|
|
6414
6433
|
configString: `supabaseStorage({
|
|
6415
|
-
supabaseUrl:
|
|
6416
|
-
supabaseServiceRoleKey:
|
|
6417
|
-
bucketName: process.env.HOT_UPDATER_SUPABASE_BUCKET_NAME
|
|
6434
|
+
supabaseUrl: ${supabaseUrl},
|
|
6435
|
+
supabaseServiceRoleKey: ${serviceRoleKey},
|
|
6436
|
+
bucketName: ${resources === void 0 ? "process.env.HOT_UPDATER_SUPABASE_BUCKET_NAME!" : JSON.stringify(resources.bucketName)},
|
|
6418
6437
|
})`
|
|
6419
|
-
}
|
|
6438
|
+
};
|
|
6439
|
+
const databaseConfig = {
|
|
6420
6440
|
imports: [{
|
|
6421
6441
|
pkg: "@hot-updater/supabase",
|
|
6422
6442
|
named: ["supabaseDatabase"]
|
|
6423
6443
|
}],
|
|
6424
6444
|
configString: `supabaseDatabase({
|
|
6425
|
-
supabaseUrl:
|
|
6426
|
-
supabaseServiceRoleKey:
|
|
6445
|
+
supabaseUrl: ${supabaseUrl},
|
|
6446
|
+
supabaseServiceRoleKey: ${serviceRoleKey},
|
|
6427
6447
|
})`
|
|
6428
|
-
}
|
|
6448
|
+
};
|
|
6449
|
+
const builder = new ConfigBuilder().setBuildType(build).setStorage(storageConfig).setDatabase(databaseConfig).setPlugins({
|
|
6429
6450
|
imports: [{
|
|
6430
6451
|
pkg: "hot-updater/plugins",
|
|
6431
6452
|
named: [
|
|
@@ -6435,7 +6456,12 @@ const getConfigScaffold = (build) => {
|
|
|
6435
6456
|
]
|
|
6436
6457
|
}],
|
|
6437
6458
|
configString: "[apiKeys(), insights(), remoteConfig()]"
|
|
6438
|
-
})
|
|
6459
|
+
});
|
|
6460
|
+
builder.addImport({
|
|
6461
|
+
pkg: "hot-updater",
|
|
6462
|
+
named: ["secret"]
|
|
6463
|
+
});
|
|
6464
|
+
return createHotUpdaterConfigScaffoldFromBuilder(builder);
|
|
6439
6465
|
};
|
|
6440
6466
|
//#endregion
|
|
6441
6467
|
//#region iac/init/index.ts
|
|
@@ -6541,7 +6567,8 @@ const initProvider = {
|
|
|
6541
6567
|
type: "password"
|
|
6542
6568
|
}
|
|
6543
6569
|
}
|
|
6544
|
-
}
|
|
6570
|
+
},
|
|
6571
|
+
secrets: ["HOT_UPDATER_SUPABASE_SERVICE_ROLE_KEY"]
|
|
6545
6572
|
};
|
|
6546
6573
|
//#endregion
|
|
6547
6574
|
//#region iac/supabaseApi.ts
|
|
@@ -6573,6 +6600,17 @@ const supabaseApi = (supabaseUrl, supabaseServiceRoleKey) => {
|
|
|
6573
6600
|
};
|
|
6574
6601
|
};
|
|
6575
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
|
|
6576
6614
|
//#region iac/supabaseAuthentication.ts
|
|
6577
6615
|
const SUPABASE_AUTH_METHOD = {
|
|
6578
6616
|
accessToken: "access-token",
|
|
@@ -6593,7 +6631,7 @@ const openBrowser = async (url) => {
|
|
|
6593
6631
|
const hasValidSupabaseCliLogin = async () => {
|
|
6594
6632
|
return (await execa("npx", [
|
|
6595
6633
|
"-y",
|
|
6596
|
-
|
|
6634
|
+
SUPABASE_CLI,
|
|
6597
6635
|
"projects",
|
|
6598
6636
|
"list",
|
|
6599
6637
|
"--output",
|
|
@@ -6620,7 +6658,7 @@ const inputSupabaseAccessToken = async (accessToken) => {
|
|
|
6620
6658
|
if (await hasValidSupabaseCliLogin()) return;
|
|
6621
6659
|
const loginProcess = execa("npx", [
|
|
6622
6660
|
"-y",
|
|
6623
|
-
|
|
6661
|
+
SUPABASE_CLI,
|
|
6624
6662
|
"login",
|
|
6625
6663
|
"--no-browser",
|
|
6626
6664
|
"--agent",
|
|
@@ -6692,7 +6730,7 @@ const supabaseDatabaseCommandErrorMessage = (err, { dbPassword, stderrInherited
|
|
|
6692
6730
|
};
|
|
6693
6731
|
const handleSupabaseDatabaseCommandError = (err, options) => {
|
|
6694
6732
|
if (err instanceof ExecaError) p.log.error(supabaseDatabaseCommandErrorMessage(err, options));
|
|
6695
|
-
else
|
|
6733
|
+
else p.log.error(err instanceof Error ? err.message : String(err));
|
|
6696
6734
|
process.exit(1);
|
|
6697
6735
|
};
|
|
6698
6736
|
const confirmSupabaseDatabaseMigrations = async ({ nonInteractive }) => {
|
|
@@ -6705,9 +6743,9 @@ const confirmSupabaseDatabaseMigrations = async ({ nonInteractive }) => {
|
|
|
6705
6743
|
const runSupabaseLink = async (workdir, { accessToken, projectId, dbPassword }) => {
|
|
6706
6744
|
await fs.writeFile(path.join(workdir, "supabase", "config.toml"), transformTemplate(SUPABASE_CONFIG_TEMPLATE, { projectId }));
|
|
6707
6745
|
await execa("npx", [
|
|
6708
|
-
"
|
|
6746
|
+
"-y",
|
|
6747
|
+
SUPABASE_CLI,
|
|
6709
6748
|
"link",
|
|
6710
|
-
"--project-ref",
|
|
6711
6749
|
projectId,
|
|
6712
6750
|
"--workdir",
|
|
6713
6751
|
workdir
|
|
@@ -6736,10 +6774,11 @@ const linkSupabase = async (workdir, options) => {
|
|
|
6736
6774
|
/** Pushes the workdir's migrations the linked project has not run, after its own history. */
|
|
6737
6775
|
const runSupabasePush = async (workdir, { accessToken, dbPassword, quiet = false }) => {
|
|
6738
6776
|
await execa("npx", [
|
|
6739
|
-
"
|
|
6777
|
+
"-y",
|
|
6778
|
+
SUPABASE_CLI,
|
|
6740
6779
|
"migration",
|
|
6741
6780
|
"fetch",
|
|
6742
|
-
"--
|
|
6781
|
+
"--remote",
|
|
6743
6782
|
"--yes",
|
|
6744
6783
|
"--workdir",
|
|
6745
6784
|
workdir
|
|
@@ -6751,10 +6790,12 @@ const runSupabasePush = async (workdir, { accessToken, dbPassword, quiet = false
|
|
|
6751
6790
|
throw error;
|
|
6752
6791
|
});
|
|
6753
6792
|
return execa("npx", [
|
|
6754
|
-
"
|
|
6793
|
+
"-y",
|
|
6794
|
+
SUPABASE_CLI,
|
|
6755
6795
|
"db",
|
|
6756
6796
|
"push",
|
|
6757
6797
|
"--include-all",
|
|
6798
|
+
"--remote",
|
|
6758
6799
|
"--yes",
|
|
6759
6800
|
"--workdir",
|
|
6760
6801
|
workdir
|
|
@@ -6917,7 +6958,7 @@ const isRecord$1 = (value) => typeof value === "object" && value !== null;
|
|
|
6917
6958
|
const runSupabaseCli = async (args) => {
|
|
6918
6959
|
const result = await execa("npx", [
|
|
6919
6960
|
"-y",
|
|
6920
|
-
|
|
6961
|
+
SUPABASE_CLI,
|
|
6921
6962
|
...args
|
|
6922
6963
|
], { env: void 0 });
|
|
6923
6964
|
return JSON.parse(result.stdout);
|
|
@@ -6940,15 +6981,14 @@ const supabaseCliManagementApi = () => ({
|
|
|
6940
6981
|
listFunctions: async (projectId) => parseSupabaseFunctionSlugs(await runSupabaseCli([
|
|
6941
6982
|
"functions",
|
|
6942
6983
|
"list",
|
|
6943
|
-
|
|
6944
|
-
projectId,
|
|
6984
|
+
`--remote=${projectId}`,
|
|
6945
6985
|
"--output",
|
|
6946
6986
|
"json"
|
|
6947
6987
|
])),
|
|
6948
6988
|
createProject: async ({ name, organizationSlug, region }) => {
|
|
6949
6989
|
await execa("npx", [
|
|
6950
6990
|
"-y",
|
|
6951
|
-
|
|
6991
|
+
SUPABASE_CLI,
|
|
6952
6992
|
"projects",
|
|
6953
6993
|
"create",
|
|
6954
6994
|
name,
|
|
@@ -6956,6 +6996,7 @@ const supabaseCliManagementApi = () => ({
|
|
|
6956
6996
|
organizationSlug,
|
|
6957
6997
|
"--region",
|
|
6958
6998
|
region,
|
|
6999
|
+
"--yes",
|
|
6959
7000
|
"--agent",
|
|
6960
7001
|
"no"
|
|
6961
7002
|
], { stdio: "inherit" });
|
|
@@ -7244,7 +7285,7 @@ const selectProject = async (preferredProjectId, nonInteractive = false, accessT
|
|
|
7244
7285
|
try {
|
|
7245
7286
|
const listProjects = await execa("npx", [
|
|
7246
7287
|
"-y",
|
|
7247
|
-
|
|
7288
|
+
SUPABASE_CLI,
|
|
7248
7289
|
"projects",
|
|
7249
7290
|
"list",
|
|
7250
7291
|
"--output",
|
|
@@ -7254,7 +7295,7 @@ const selectProject = async (preferredProjectId, nonInteractive = false, accessT
|
|
|
7254
7295
|
} catch (err) {
|
|
7255
7296
|
spinner.stop();
|
|
7256
7297
|
const message = err instanceof Error ? err.message : String(err);
|
|
7257
|
-
|
|
7298
|
+
p.log.error(`Failed to fetch Supabase projects: ${message}`);
|
|
7258
7299
|
process.exit(1);
|
|
7259
7300
|
}
|
|
7260
7301
|
spinner.stop();
|
|
@@ -7405,13 +7446,14 @@ const deployEdgeFunction = async (accessToken, workdir, projectId, functionName)
|
|
|
7405
7446
|
task: async () => {
|
|
7406
7447
|
try {
|
|
7407
7448
|
return (await execa("npx", [
|
|
7408
|
-
"
|
|
7449
|
+
"-y",
|
|
7450
|
+
SUPABASE_CLI,
|
|
7409
7451
|
"functions",
|
|
7410
7452
|
"deploy",
|
|
7411
7453
|
functionName,
|
|
7412
|
-
|
|
7413
|
-
projectId,
|
|
7454
|
+
`--remote=${projectId}`,
|
|
7414
7455
|
"--no-verify-jwt",
|
|
7456
|
+
"--yes",
|
|
7415
7457
|
"--workdir",
|
|
7416
7458
|
workdir
|
|
7417
7459
|
], {
|
|
@@ -7450,11 +7492,10 @@ const getSupabaseProjectAccess = async ({ accessToken, managementApi, project, w
|
|
|
7450
7492
|
const getServiceRoleApiKey = async () => {
|
|
7451
7493
|
const keysProcess = await execa("npx", [
|
|
7452
7494
|
"-y",
|
|
7453
|
-
|
|
7495
|
+
SUPABASE_CLI,
|
|
7454
7496
|
"projects",
|
|
7455
7497
|
"api-keys",
|
|
7456
|
-
|
|
7457
|
-
project.id,
|
|
7498
|
+
`--remote=${project.id}`,
|
|
7458
7499
|
"--output",
|
|
7459
7500
|
"json"
|
|
7460
7501
|
], { env: getSupabaseCliEnv(accessToken) });
|
|
@@ -7510,9 +7551,9 @@ const withSupabaseCliMetadataCleanup = async (cwd, operation) => {
|
|
|
7510
7551
|
});
|
|
7511
7552
|
}
|
|
7512
7553
|
};
|
|
7513
|
-
const runInitWithoutCliMetadata = async ({ build, envFile }) => {
|
|
7554
|
+
const runInitWithoutCliMetadata = async ({ build, envFile, secretsEnv }) => {
|
|
7514
7555
|
const nonInteractive = envFile !== void 0;
|
|
7515
|
-
const initEnvSources = await readHotUpdaterInitEnv(process.cwd(), envFile);
|
|
7556
|
+
const initEnvSources = await readHotUpdaterInitEnv(process.cwd(), envFile, secretsEnv);
|
|
7516
7557
|
const { inputEnv, managedEnv } = initEnvSources;
|
|
7517
7558
|
const initInputEnv = getHotUpdaterInitInputEnv(initEnvSources, nonInteractive);
|
|
7518
7559
|
const savedInputs = resolveSupabaseInitInputs(initInputEnv, {
|
|
@@ -7591,6 +7632,7 @@ const runInitWithoutCliMetadata = async ({ build, envFile }) => {
|
|
|
7591
7632
|
const { tmpDir, removeTmpDir } = await copyDirToTmp(scaffoldLibPath, "supabase");
|
|
7592
7633
|
let credential;
|
|
7593
7634
|
let clientPlugins = [];
|
|
7635
|
+
let resources;
|
|
7594
7636
|
try {
|
|
7595
7637
|
await stageEdgeFunction({
|
|
7596
7638
|
bucketName: bucketSelection.name,
|
|
@@ -7632,6 +7674,10 @@ const runInitWithoutCliMetadata = async ({ build, envFile }) => {
|
|
|
7632
7674
|
[initProvider.inputs.bucketName.envKey]: bucket.name,
|
|
7633
7675
|
HOT_UPDATER_SUPABASE_URL: `https://${project.id}.supabase.co`
|
|
7634
7676
|
});
|
|
7677
|
+
resources = {
|
|
7678
|
+
supabaseUrl: `https://${project.id}.supabase.co`,
|
|
7679
|
+
bucketName: bucket.name
|
|
7680
|
+
};
|
|
7635
7681
|
await linkSupabase(tmpDir, {
|
|
7636
7682
|
accessToken,
|
|
7637
7683
|
projectId: project.id,
|
|
@@ -7669,7 +7715,7 @@ const runInitWithoutCliMetadata = async ({ build, envFile }) => {
|
|
|
7669
7715
|
await removeTmpDir();
|
|
7670
7716
|
}
|
|
7671
7717
|
p.log.success("Generated '.env.hotupdater' file with Supabase settings.");
|
|
7672
|
-
await writeHotUpdaterFiles(getConfigScaffold(build), {
|
|
7718
|
+
await writeHotUpdaterFiles(getConfigScaffold(build, resources), {
|
|
7673
7719
|
cwd: process.cwd(),
|
|
7674
7720
|
settings: "Supabase"
|
|
7675
7721
|
});
|
|
@@ -7682,8 +7728,7 @@ const runInitWithoutCliMetadata = async ({ build, envFile }) => {
|
|
|
7682
7728
|
clientPlugins
|
|
7683
7729
|
});
|
|
7684
7730
|
reportSupabaseOriginCatalogReady();
|
|
7685
|
-
|
|
7686
|
-
p.log.success("Done! 🎉");
|
|
7731
|
+
return { nextSteps: [link("https://hot-updater.dev/docs/managed/supabase#step-3-add-hotupdater-to-your-project")] };
|
|
7687
7732
|
};
|
|
7688
7733
|
const runInit = (options) => withSupabaseCliMetadataCleanup(process.cwd(), () => runInitWithoutCliMetadata(options));
|
|
7689
7734
|
//#endregion
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { SETTINGS_TABLE, createEngineDatabase, createSqlAdapter, createStorageAdapter, createStorageKeyBuilder, createStorageUri, parseStorageUri } from "@hot-updater/plugin-core";
|
|
2
2
|
import { createClient } from "@supabase/supabase-js";
|
|
3
3
|
//#region src/supabaseConfig.ts
|
|
4
|
-
const resolveSupabaseServiceRoleKey = (config) => {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const resolveSupabaseServiceRoleKey = async (config) => {
|
|
5
|
+
const { supabaseServiceRoleKey } = config;
|
|
6
|
+
const key = typeof supabaseServiceRoleKey === "function" ? await supabaseServiceRoleKey() : supabaseServiceRoleKey;
|
|
7
|
+
if (!key) throw new Error("Supabase service role key is required. Set supabaseServiceRoleKey.");
|
|
8
|
+
return key;
|
|
7
9
|
};
|
|
8
10
|
//#endregion
|
|
9
11
|
//#region src/supabaseInfrastructureNames.ts
|
|
@@ -42,9 +44,16 @@ const withCode = (error) => Object.assign(new Error(error.message, { cause: erro
|
|
|
42
44
|
*/
|
|
43
45
|
const supabaseExecutor = (client) => {
|
|
44
46
|
let created;
|
|
45
|
-
const clientOf = () =>
|
|
47
|
+
const clientOf = async () => {
|
|
48
|
+
if (typeof client !== "function") return client;
|
|
49
|
+
created ??= Promise.resolve().then(client).catch((error) => {
|
|
50
|
+
created = void 0;
|
|
51
|
+
throw error;
|
|
52
|
+
});
|
|
53
|
+
return created;
|
|
54
|
+
};
|
|
46
55
|
const apply = async (statements) => {
|
|
47
|
-
const { data, error } = await clientOf().rpc(SUPABASE_APPLY_FUNCTION, { p_statements: statements.map(toApplyStatement) });
|
|
56
|
+
const { data, error } = await (await clientOf()).rpc(SUPABASE_APPLY_FUNCTION, { p_statements: statements.map(toApplyStatement) });
|
|
48
57
|
if (error) throw withCode(error);
|
|
49
58
|
return data;
|
|
50
59
|
};
|
|
@@ -67,7 +76,7 @@ const supabaseExecutor = (client) => {
|
|
|
67
76
|
*/
|
|
68
77
|
const supabaseDatabase = (config) => {
|
|
69
78
|
const { migrations: _migrations, ...adapter } = createSqlAdapter({
|
|
70
|
-
executor: supabaseExecutor(() => createClient(config.supabaseUrl, resolveSupabaseServiceRoleKey(config))),
|
|
79
|
+
executor: supabaseExecutor(async () => createClient(config.supabaseUrl, await resolveSupabaseServiceRoleKey(config))),
|
|
71
80
|
tablePrefix: SUPABASE_TABLE_PREFIX
|
|
72
81
|
});
|
|
73
82
|
return createEngineDatabase({
|
|
@@ -157,7 +166,15 @@ const isMissingObjectError = async (error) => {
|
|
|
157
166
|
};
|
|
158
167
|
/** A character Storage rejects in an object name, `?`, or `!`. */
|
|
159
168
|
const ESCAPED_CHARACTER = /[^A-Za-z0-9_/.*'() &$=@;:+,-]/gu;
|
|
169
|
+
const ESCAPE_SEQUENCE = /!([0-9A-F]{2})/gu;
|
|
160
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";
|
|
161
178
|
/**
|
|
162
179
|
* The object name Storage keeps a key under. Storage accepts names of ASCII
|
|
163
180
|
* letters, digits and `_/!.*'() &$=@;:+,?-` only, and supabase-js puts a name
|
|
@@ -168,12 +185,44 @@ const utf8 = new TextEncoder();
|
|
|
168
185
|
* Deploy's keys, such as `<bundleId>/manifest.json`, are stored as they are.
|
|
169
186
|
*/
|
|
170
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
|
+
};
|
|
171
216
|
const supabaseStorage = (config) => {
|
|
172
217
|
let client;
|
|
173
|
-
const bucket = () => (client ??= createClient(config.supabaseUrl,
|
|
218
|
+
const bucket = async () => (await (client ??= resolveSupabaseServiceRoleKey(config).then((key) => createClient(config.supabaseUrl, key), (error) => {
|
|
219
|
+
client = void 0;
|
|
220
|
+
throw error;
|
|
221
|
+
}))).storage.from(config.bucketName);
|
|
174
222
|
const getStorageKey = createStorageKeyBuilder(config.basePath);
|
|
223
|
+
const basePrefix = getStorageKey() ? `${getStorageKey()}/` : "";
|
|
175
224
|
const resolveSignedUrl = createSupabaseSignedUrlBatcher({
|
|
176
|
-
createSignedUrls: (_bucketName, keys, expiresIn) => bucket().createSignedUrls(keys, expiresIn),
|
|
225
|
+
createSignedUrls: async (_bucketName, keys, expiresIn) => (await bucket()).createSignedUrls(keys, expiresIn),
|
|
177
226
|
expiresIn: config.signedUrlExpiresIn ?? 3600,
|
|
178
227
|
formatObjectPath: (_bucketName, key) => key
|
|
179
228
|
});
|
|
@@ -187,7 +236,7 @@ const supabaseStorage = (config) => {
|
|
|
187
236
|
protocol: "supabase-storage",
|
|
188
237
|
async put({ key, body, contentLength, contentType }) {
|
|
189
238
|
const storageKey = getStorageKey(key);
|
|
190
|
-
const { error } = await bucket().upload(toObjectName(storageKey), body, {
|
|
239
|
+
const { error } = await (await bucket()).upload(toObjectName(storageKey), body, {
|
|
191
240
|
contentType,
|
|
192
241
|
cacheControl: "max-age=31536000",
|
|
193
242
|
upsert: true,
|
|
@@ -203,7 +252,7 @@ const supabaseStorage = (config) => {
|
|
|
203
252
|
},
|
|
204
253
|
async get({ storageUri }) {
|
|
205
254
|
const { key } = parseAndValidate(storageUri);
|
|
206
|
-
const { data, error } = await bucket().download(toObjectName(key));
|
|
255
|
+
const { data, error } = await (await bucket()).download(toObjectName(key));
|
|
207
256
|
if (error) {
|
|
208
257
|
if (await isMissingObjectError(error)) return { response: null };
|
|
209
258
|
throw new Error(`Failed to download storage object: ${error.message}`);
|
|
@@ -216,7 +265,7 @@ const supabaseStorage = (config) => {
|
|
|
216
265
|
},
|
|
217
266
|
async exists({ storageUri }) {
|
|
218
267
|
const { key } = parseAndValidate(storageUri);
|
|
219
|
-
const { data, error } = await bucket().exists(toObjectName(key));
|
|
268
|
+
const { data, error } = await (await bucket()).exists(toObjectName(key));
|
|
220
269
|
if (error) {
|
|
221
270
|
if (isMissingExistsError(error)) return { exists: false };
|
|
222
271
|
throw error;
|
|
@@ -225,9 +274,54 @@ const supabaseStorage = (config) => {
|
|
|
225
274
|
},
|
|
226
275
|
async delete({ storageUri }) {
|
|
227
276
|
const { key } = parseAndValidate(storageUri);
|
|
228
|
-
const { error } = await bucket().remove([toObjectName(key)]);
|
|
277
|
+
const { error } = await (await bucket()).remove([toObjectName(key)]);
|
|
229
278
|
if (error && !isNotFoundError(error)) throw new Error(`Failed to delete storage object: ${error.message}`);
|
|
230
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
|
+
}
|
|
231
325
|
}
|
|
232
326
|
});
|
|
233
327
|
};
|
|
@@ -1,8 +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
|
+
* The project's service role key, or a function that returns it, such as
|
|
7
|
+
* `secret("<name>")` in `hot-updater.config.ts`: called on the first
|
|
8
|
+
* request, so a config loads without the key.
|
|
9
|
+
*/
|
|
10
|
+
supabaseServiceRoleKey: Lazy<string>;
|
|
6
11
|
};
|
|
7
12
|
//#endregion
|
|
8
13
|
//#region src/supabaseDatabase.d.ts
|
|
@@ -23,6 +28,6 @@ type SupabaseStorageConfig = SupabaseServiceRoleConfig & {
|
|
|
23
28
|
/** Signed download URL lifetime in seconds. @default 3600 */
|
|
24
29
|
signedUrlExpiresIn?: number;
|
|
25
30
|
};
|
|
26
|
-
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">;
|
|
27
32
|
//#endregion
|
|
28
33
|
export { supabaseDatabase as i, supabaseStorage as n, SupabaseDatabaseConfig as r, SupabaseStorageConfig as t };
|
|
@@ -1,8 +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
|
+
* The project's service role key, or a function that returns it, such as
|
|
7
|
+
* `secret("<name>")` in `hot-updater.config.ts`: called on the first
|
|
8
|
+
* request, so a config loads without the key.
|
|
9
|
+
*/
|
|
10
|
+
supabaseServiceRoleKey: Lazy<string>;
|
|
6
11
|
};
|
|
7
12
|
//#endregion
|
|
8
13
|
//#region src/supabaseDatabase.d.ts
|
|
@@ -23,6 +28,6 @@ type SupabaseStorageConfig = SupabaseServiceRoleConfig & {
|
|
|
23
28
|
/** Signed download URL lifetime in seconds. @default 3600 */
|
|
24
29
|
signedUrlExpiresIn?: number;
|
|
25
30
|
};
|
|
26
|
-
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">;
|
|
27
32
|
//#endregion
|
|
28
33
|
export { supabaseDatabase as i, supabaseStorage as n, SupabaseDatabaseConfig as r, SupabaseStorageConfig as t };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
2
2
|
let _supabase_supabase_js = require("@supabase/supabase-js");
|
|
3
3
|
//#region src/supabaseConfig.ts
|
|
4
|
-
const resolveSupabaseServiceRoleKey = (config) => {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const resolveSupabaseServiceRoleKey = async (config) => {
|
|
5
|
+
const { supabaseServiceRoleKey } = config;
|
|
6
|
+
const key = typeof supabaseServiceRoleKey === "function" ? await supabaseServiceRoleKey() : supabaseServiceRoleKey;
|
|
7
|
+
if (!key) throw new Error("Supabase service role key is required. Set supabaseServiceRoleKey.");
|
|
8
|
+
return key;
|
|
7
9
|
};
|
|
8
10
|
//#endregion
|
|
9
11
|
//#region src/supabaseInfrastructureNames.ts
|
|
@@ -42,9 +44,16 @@ const withCode = (error) => Object.assign(new Error(error.message, { cause: erro
|
|
|
42
44
|
*/
|
|
43
45
|
const supabaseExecutor = (client) => {
|
|
44
46
|
let created;
|
|
45
|
-
const clientOf = () =>
|
|
47
|
+
const clientOf = async () => {
|
|
48
|
+
if (typeof client !== "function") return client;
|
|
49
|
+
created ??= Promise.resolve().then(client).catch((error) => {
|
|
50
|
+
created = void 0;
|
|
51
|
+
throw error;
|
|
52
|
+
});
|
|
53
|
+
return created;
|
|
54
|
+
};
|
|
46
55
|
const apply = async (statements) => {
|
|
47
|
-
const { data, error } = await clientOf().rpc(SUPABASE_APPLY_FUNCTION, { p_statements: statements.map(toApplyStatement) });
|
|
56
|
+
const { data, error } = await (await clientOf()).rpc(SUPABASE_APPLY_FUNCTION, { p_statements: statements.map(toApplyStatement) });
|
|
48
57
|
if (error) throw withCode(error);
|
|
49
58
|
return data;
|
|
50
59
|
};
|
|
@@ -67,7 +76,7 @@ const supabaseExecutor = (client) => {
|
|
|
67
76
|
*/
|
|
68
77
|
const supabaseDatabase = (config) => {
|
|
69
78
|
const { migrations: _migrations, ...adapter } = (0, _hot_updater_plugin_core.createSqlAdapter)({
|
|
70
|
-
executor: supabaseExecutor(() => (0, _supabase_supabase_js.createClient)(config.supabaseUrl, resolveSupabaseServiceRoleKey(config))),
|
|
79
|
+
executor: supabaseExecutor(async () => (0, _supabase_supabase_js.createClient)(config.supabaseUrl, await resolveSupabaseServiceRoleKey(config))),
|
|
71
80
|
tablePrefix: SUPABASE_TABLE_PREFIX
|
|
72
81
|
});
|
|
73
82
|
return (0, _hot_updater_plugin_core.createEngineDatabase)({
|
|
@@ -157,7 +166,15 @@ const isMissingObjectError = async (error) => {
|
|
|
157
166
|
};
|
|
158
167
|
/** A character Storage rejects in an object name, `?`, or `!`. */
|
|
159
168
|
const ESCAPED_CHARACTER = /[^A-Za-z0-9_/.*'() &$=@;:+,-]/gu;
|
|
169
|
+
const ESCAPE_SEQUENCE = /!([0-9A-F]{2})/gu;
|
|
160
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";
|
|
161
178
|
/**
|
|
162
179
|
* The object name Storage keeps a key under. Storage accepts names of ASCII
|
|
163
180
|
* letters, digits and `_/!.*'() &$=@;:+,?-` only, and supabase-js puts a name
|
|
@@ -168,12 +185,44 @@ const utf8 = new TextEncoder();
|
|
|
168
185
|
* Deploy's keys, such as `<bundleId>/manifest.json`, are stored as they are.
|
|
169
186
|
*/
|
|
170
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
|
+
};
|
|
171
216
|
const supabaseStorage = (config) => {
|
|
172
217
|
let client;
|
|
173
|
-
const bucket = () => (client ??= (0, _supabase_supabase_js.createClient)(config.supabaseUrl,
|
|
218
|
+
const bucket = async () => (await (client ??= resolveSupabaseServiceRoleKey(config).then((key) => (0, _supabase_supabase_js.createClient)(config.supabaseUrl, key), (error) => {
|
|
219
|
+
client = void 0;
|
|
220
|
+
throw error;
|
|
221
|
+
}))).storage.from(config.bucketName);
|
|
174
222
|
const getStorageKey = (0, _hot_updater_plugin_core.createStorageKeyBuilder)(config.basePath);
|
|
223
|
+
const basePrefix = getStorageKey() ? `${getStorageKey()}/` : "";
|
|
175
224
|
const resolveSignedUrl = createSupabaseSignedUrlBatcher({
|
|
176
|
-
createSignedUrls: (_bucketName, keys, expiresIn) => bucket().createSignedUrls(keys, expiresIn),
|
|
225
|
+
createSignedUrls: async (_bucketName, keys, expiresIn) => (await bucket()).createSignedUrls(keys, expiresIn),
|
|
177
226
|
expiresIn: config.signedUrlExpiresIn ?? 3600,
|
|
178
227
|
formatObjectPath: (_bucketName, key) => key
|
|
179
228
|
});
|
|
@@ -187,7 +236,7 @@ const supabaseStorage = (config) => {
|
|
|
187
236
|
protocol: "supabase-storage",
|
|
188
237
|
async put({ key, body, contentLength, contentType }) {
|
|
189
238
|
const storageKey = getStorageKey(key);
|
|
190
|
-
const { error } = await bucket().upload(toObjectName(storageKey), body, {
|
|
239
|
+
const { error } = await (await bucket()).upload(toObjectName(storageKey), body, {
|
|
191
240
|
contentType,
|
|
192
241
|
cacheControl: "max-age=31536000",
|
|
193
242
|
upsert: true,
|
|
@@ -203,7 +252,7 @@ const supabaseStorage = (config) => {
|
|
|
203
252
|
},
|
|
204
253
|
async get({ storageUri }) {
|
|
205
254
|
const { key } = parseAndValidate(storageUri);
|
|
206
|
-
const { data, error } = await bucket().download(toObjectName(key));
|
|
255
|
+
const { data, error } = await (await bucket()).download(toObjectName(key));
|
|
207
256
|
if (error) {
|
|
208
257
|
if (await isMissingObjectError(error)) return { response: null };
|
|
209
258
|
throw new Error(`Failed to download storage object: ${error.message}`);
|
|
@@ -216,7 +265,7 @@ const supabaseStorage = (config) => {
|
|
|
216
265
|
},
|
|
217
266
|
async exists({ storageUri }) {
|
|
218
267
|
const { key } = parseAndValidate(storageUri);
|
|
219
|
-
const { data, error } = await bucket().exists(toObjectName(key));
|
|
268
|
+
const { data, error } = await (await bucket()).exists(toObjectName(key));
|
|
220
269
|
if (error) {
|
|
221
270
|
if (isMissingExistsError(error)) return { exists: false };
|
|
222
271
|
throw error;
|
|
@@ -225,9 +274,54 @@ const supabaseStorage = (config) => {
|
|
|
225
274
|
},
|
|
226
275
|
async delete({ storageUri }) {
|
|
227
276
|
const { key } = parseAndValidate(storageUri);
|
|
228
|
-
const { error } = await bucket().remove([toObjectName(key)]);
|
|
277
|
+
const { error } = await (await bucket()).remove([toObjectName(key)]);
|
|
229
278
|
if (error && !isNotFoundError(error)) throw new Error(`Failed to delete storage object: ${error.message}`);
|
|
230
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
|
+
}
|
|
231
325
|
}
|
|
232
326
|
});
|
|
233
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.
|
|
4
|
+
"version": "1.2.0-rc.31",
|
|
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.
|
|
55
|
-
"@hot-updater/plugin-core": "1.2.0-rc.
|
|
56
|
-
"@hot-updater/
|
|
57
|
-
"@hot-updater/
|
|
54
|
+
"@hot-updater/protocol": "1.2.0-rc.31",
|
|
55
|
+
"@hot-updater/plugin-core": "1.2.0-rc.31",
|
|
56
|
+
"@hot-updater/server": "1.2.0-rc.31",
|
|
57
|
+
"@hot-updater/cli-tools": "1.2.0-rc.31"
|
|
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.
|
|
68
|
-
"@hot-updater/test-utils": "1.2.0-rc.
|
|
69
|
-
"@hot-updater/postgres": "1.2.0-rc.
|
|
67
|
+
"@hot-updater/mock": "1.2.0-rc.31",
|
|
68
|
+
"@hot-updater/test-utils": "1.2.0-rc.31",
|
|
69
|
+
"@hot-updater/postgres": "1.2.0-rc.31"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"build": "tsdown",
|
|
@@ -1,17 +1,31 @@
|
|
|
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
|
+
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
4
|
|
|
5
5
|
CREATE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_byScope" ON "hot_updater_v1_native_builds" ("scope_key", "id");
|
|
6
6
|
|
|
7
7
|
CREATE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_byBuildKey" ON "hot_updater_v1_native_builds" ("scope_key", "build_key", "id");
|
|
8
8
|
|
|
9
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_byStoreBuild" ON "hot_updater_v1_native_builds" ("store_build_scope_key");
|
|
10
|
+
|
|
9
11
|
CREATE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_byChannel" ON "hot_updater_v1_native_builds" ("channel_id", "id");
|
|
10
12
|
|
|
11
13
|
CREATE UNIQUE INDEX IF NOT EXISTS "hot_updater_v1_native_builds_min_bundle_id" ON "hot_updater_v1_native_builds" ("min_bundle_id");
|
|
12
14
|
|
|
15
|
+
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"));
|
|
16
|
+
|
|
17
|
+
CREATE INDEX IF NOT EXISTS "hot_updater_v1_ios_devices_byStatus" ON "hot_updater_v1_ios_devices" ("status", "id");
|
|
18
|
+
|
|
19
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "hot_updater_v1_ios_devices_udid" ON "hot_updater_v1_ios_devices" ("udid");
|
|
20
|
+
|
|
21
|
+
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"));
|
|
22
|
+
|
|
13
23
|
ALTER TABLE "hot_updater_v1_native_builds" ENABLE ROW LEVEL SECURITY;
|
|
14
24
|
|
|
25
|
+
ALTER TABLE "hot_updater_v1_ios_devices" ENABLE ROW LEVEL SECURITY;
|
|
26
|
+
|
|
27
|
+
ALTER TABLE "hot_updater_v1_ios_device_account" ENABLE ROW LEVEL SECURITY;
|
|
28
|
+
|
|
15
29
|
CREATE OR REPLACE FUNCTION public.hot_updater_v1_apply(p_statements jsonb)
|
|
16
30
|
RETURNS jsonb
|
|
17
31
|
LANGUAGE plpgsql
|
|
@@ -31,7 +45,7 @@ BEGIN
|
|
|
31
45
|
FOR item IN SELECT value FROM jsonb_array_elements(p_statements) LOOP
|
|
32
46
|
statement := item->>'sql';
|
|
33
47
|
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
|
|
48
|
+
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_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
49
|
RAISE EXCEPTION 'hot_updater_v1_apply: % is not a Hot Updater table', target USING ERRCODE = '42501';
|
|
36
50
|
END IF;
|
|
37
51
|
END LOOP;
|