@hot-updater/supabase 0.28.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/edge.cjs +4 -0
- package/dist/edge.d.cts +2 -0
- package/dist/edge.d.mts +2 -0
- package/dist/edge.mjs +2 -0
- package/dist/iac/index.cjs +457 -499
- package/dist/iac/index.d.cts +4 -1
- package/dist/iac/{index.d.ts → index.d.mts} +4 -1
- package/dist/iac/{index.js → index.mjs} +420 -451
- package/dist/index.cjs +15 -109
- package/dist/index.d.cts +5 -4
- package/dist/index.d.mts +23 -0
- package/dist/index.mjs +50 -0
- package/dist/supabaseEdgeFunctionStorage-B-gM2rZx.cjs +192 -0
- package/dist/supabaseEdgeFunctionStorage-ByPGforO.d.mts +19 -0
- package/dist/supabaseEdgeFunctionStorage-CSPi2UB8.d.cts +19 -0
- package/dist/supabaseEdgeFunctionStorage-CVEY5QJO.mjs +174 -0
- package/package.json +22 -10
- package/supabase/edge-functions/index.ts +29 -317
- package/supabase/edge-functions/runtime.docker.integration.spec.ts +779 -0
- package/supabase/migrations/20260401000000_hot-updater_0.29.0.sql +503 -0
- package/dist/index.d.ts +0 -22
- package/dist/index.js +0 -145
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -19,121 +20,24 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
19
20
|
value: mod,
|
|
20
21
|
enumerable: true
|
|
21
22
|
}) : target, mod));
|
|
22
|
-
|
|
23
23
|
//#endregion
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
let
|
|
27
|
-
__supabase_supabase_js = __toESM(__supabase_supabase_js);
|
|
24
|
+
const require_supabaseEdgeFunctionStorage = require("./supabaseEdgeFunctionStorage-B-gM2rZx.cjs");
|
|
25
|
+
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
26
|
+
let _supabase_supabase_js = require("@supabase/supabase-js");
|
|
28
27
|
let fs_promises = require("fs/promises");
|
|
29
28
|
fs_promises = __toESM(fs_promises);
|
|
30
29
|
let path = require("path");
|
|
31
30
|
path = __toESM(path);
|
|
32
|
-
|
|
33
|
-
//#region src/supabaseDatabase.ts
|
|
34
|
-
const supabaseDatabase = (0, __hot_updater_plugin_core.createDatabasePlugin)({
|
|
35
|
-
name: "supabaseDatabase",
|
|
36
|
-
factory: (config) => {
|
|
37
|
-
const supabase = (0, __supabase_supabase_js.createClient)(config.supabaseUrl, config.supabaseAnonKey);
|
|
38
|
-
return {
|
|
39
|
-
async getBundleById(bundleId) {
|
|
40
|
-
const { data, error } = await supabase.from("bundles").select("channel, enabled, should_force_update, file_hash, git_commit_hash, id, message, platform, target_app_version, fingerprint_hash, storage_uri, metadata").eq("id", bundleId).single();
|
|
41
|
-
if (!data || error) return null;
|
|
42
|
-
return {
|
|
43
|
-
channel: data.channel,
|
|
44
|
-
enabled: data.enabled,
|
|
45
|
-
shouldForceUpdate: data.should_force_update,
|
|
46
|
-
fileHash: data.file_hash,
|
|
47
|
-
gitCommitHash: data.git_commit_hash,
|
|
48
|
-
id: data.id,
|
|
49
|
-
message: data.message,
|
|
50
|
-
platform: data.platform,
|
|
51
|
-
targetAppVersion: data.target_app_version,
|
|
52
|
-
fingerprintHash: data.fingerprint_hash,
|
|
53
|
-
storageUri: data.storage_uri,
|
|
54
|
-
metadata: data.metadata ?? {}
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
async getBundles(options) {
|
|
58
|
-
const { where, limit, offset } = options ?? {};
|
|
59
|
-
let countQuery = supabase.from("bundles").select("*", {
|
|
60
|
-
count: "exact",
|
|
61
|
-
head: true
|
|
62
|
-
});
|
|
63
|
-
if (where?.channel) countQuery = countQuery.eq("channel", where.channel);
|
|
64
|
-
if (where?.platform) countQuery = countQuery.eq("platform", where.platform);
|
|
65
|
-
const { count: total = 0 } = await countQuery;
|
|
66
|
-
let query = supabase.from("bundles").select("id, channel, enabled, platform, should_force_update, file_hash, git_commit_hash, message, fingerprint_hash, target_app_version, storage_uri, metadata").order("id", { ascending: false });
|
|
67
|
-
if (where?.channel) query = query.eq("channel", where.channel);
|
|
68
|
-
if (where?.platform) query = query.eq("platform", where.platform);
|
|
69
|
-
if (limit) query = query.limit(limit);
|
|
70
|
-
if (offset) query = query.range(offset, offset + (limit || 20) - 1);
|
|
71
|
-
const { data } = await query;
|
|
72
|
-
return {
|
|
73
|
-
data: data ? data.map((bundle) => ({
|
|
74
|
-
channel: bundle.channel,
|
|
75
|
-
enabled: bundle.enabled,
|
|
76
|
-
shouldForceUpdate: bundle.should_force_update,
|
|
77
|
-
fileHash: bundle.file_hash,
|
|
78
|
-
gitCommitHash: bundle.git_commit_hash,
|
|
79
|
-
id: bundle.id,
|
|
80
|
-
message: bundle.message,
|
|
81
|
-
platform: bundle.platform,
|
|
82
|
-
targetAppVersion: bundle.target_app_version,
|
|
83
|
-
fingerprintHash: bundle.fingerprint_hash,
|
|
84
|
-
storageUri: bundle.storage_uri,
|
|
85
|
-
metadata: bundle.metadata ?? {}
|
|
86
|
-
})) : [],
|
|
87
|
-
pagination: (0, __hot_updater_plugin_core.calculatePagination)(total ?? 0, {
|
|
88
|
-
limit,
|
|
89
|
-
offset
|
|
90
|
-
})
|
|
91
|
-
};
|
|
92
|
-
},
|
|
93
|
-
async getChannels() {
|
|
94
|
-
const { data, error } = await supabase.rpc("get_channels");
|
|
95
|
-
if (error) throw error;
|
|
96
|
-
return data.map((bundle) => bundle.channel);
|
|
97
|
-
},
|
|
98
|
-
async commitBundle({ changedSets }) {
|
|
99
|
-
if (changedSets.length === 0) return;
|
|
100
|
-
for (const op of changedSets) if (op.operation === "delete") {
|
|
101
|
-
const { error } = await supabase.from("bundles").delete().eq("id", op.data.id);
|
|
102
|
-
if (error) throw new Error(`Failed to delete bundle: ${error.message}`);
|
|
103
|
-
} else if (op.operation === "insert" || op.operation === "update") {
|
|
104
|
-
const bundle = op.data;
|
|
105
|
-
const { error } = await supabase.from("bundles").upsert({
|
|
106
|
-
id: bundle.id,
|
|
107
|
-
channel: bundle.channel,
|
|
108
|
-
enabled: bundle.enabled,
|
|
109
|
-
should_force_update: bundle.shouldForceUpdate,
|
|
110
|
-
file_hash: bundle.fileHash,
|
|
111
|
-
git_commit_hash: bundle.gitCommitHash,
|
|
112
|
-
message: bundle.message,
|
|
113
|
-
platform: bundle.platform,
|
|
114
|
-
target_app_version: bundle.targetAppVersion,
|
|
115
|
-
fingerprint_hash: bundle.fingerprintHash,
|
|
116
|
-
storage_uri: bundle.storageUri,
|
|
117
|
-
metadata: bundle.metadata
|
|
118
|
-
}, { onConflict: "id" });
|
|
119
|
-
if (error) throw error;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
//#endregion
|
|
127
31
|
//#region src/supabaseStorage.ts
|
|
128
|
-
const supabaseStorage = (0,
|
|
32
|
+
const supabaseStorage = (0, _hot_updater_plugin_core.createStoragePlugin)({
|
|
129
33
|
name: "supabaseStorage",
|
|
130
34
|
supportedProtocol: "supabase-storage",
|
|
131
35
|
factory: (config) => {
|
|
132
|
-
const bucket = (0,
|
|
133
|
-
const getStorageKey = (0,
|
|
36
|
+
const bucket = (0, _supabase_supabase_js.createClient)(config.supabaseUrl, config.supabaseAnonKey).storage.from(config.bucketName);
|
|
37
|
+
const getStorageKey = (0, _hot_updater_plugin_core.createStorageKeyBuilder)(config.basePath);
|
|
134
38
|
return {
|
|
135
39
|
async delete(storageUri) {
|
|
136
|
-
const { key, bucket: bucketName } = (0,
|
|
40
|
+
const { key, bucket: bucketName } = (0, _hot_updater_plugin_core.parseStorageUri)(storageUri, "supabase-storage");
|
|
137
41
|
if (bucketName !== config.bucketName) throw new Error(`Bucket name mismatch: expected "${config.bucketName}", but found "${bucketName}".`);
|
|
138
42
|
const { error } = await bucket.remove([key]);
|
|
139
43
|
if (error) {
|
|
@@ -143,7 +47,7 @@ const supabaseStorage = (0, __hot_updater_plugin_core.createStoragePlugin)({
|
|
|
143
47
|
},
|
|
144
48
|
async upload(key, filePath) {
|
|
145
49
|
const Body = await fs_promises.default.readFile(filePath);
|
|
146
|
-
const ContentType = (0,
|
|
50
|
+
const ContentType = (0, _hot_updater_plugin_core.getContentType)(filePath);
|
|
147
51
|
const Key = getStorageKey(key, path.default.basename(filePath));
|
|
148
52
|
const upload = await bucket.upload(Key, Body, {
|
|
149
53
|
contentType: ContentType,
|
|
@@ -167,7 +71,9 @@ const supabaseStorage = (0, __hot_updater_plugin_core.createStoragePlugin)({
|
|
|
167
71
|
};
|
|
168
72
|
}
|
|
169
73
|
});
|
|
170
|
-
|
|
171
74
|
//#endregion
|
|
172
|
-
exports.
|
|
173
|
-
exports.
|
|
75
|
+
exports.__toESM = __toESM;
|
|
76
|
+
exports.supabaseDatabase = require_supabaseEdgeFunctionStorage.supabaseDatabase;
|
|
77
|
+
exports.supabaseEdgeFunctionDatabase = require_supabaseEdgeFunctionStorage.supabaseEdgeFunctionDatabase;
|
|
78
|
+
exports.supabaseEdgeFunctionStorage = require_supabaseEdgeFunctionStorage.supabaseEdgeFunctionStorage;
|
|
79
|
+
exports.supabaseStorage = supabaseStorage;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { i as supabaseEdgeFunctionDatabase, n as supabaseEdgeFunctionStorage, r as SupabaseEdgeFunctionDatabaseConfig, t as SupabaseEdgeFunctionStorageConfig } from "./supabaseEdgeFunctionStorage-CSPi2UB8.cjs";
|
|
2
|
+
import * as _$_hot_updater_plugin_core0 from "@hot-updater/plugin-core";
|
|
2
3
|
|
|
3
4
|
//#region src/supabaseDatabase.d.ts
|
|
4
5
|
interface SupabaseDatabaseConfig {
|
|
5
6
|
supabaseUrl: string;
|
|
6
7
|
supabaseAnonKey: string;
|
|
7
8
|
}
|
|
8
|
-
declare const supabaseDatabase: (config: SupabaseDatabaseConfig, hooks?:
|
|
9
|
+
declare const supabaseDatabase: (config: SupabaseDatabaseConfig, hooks?: _$_hot_updater_plugin_core0.DatabasePluginHooks) => () => _$_hot_updater_plugin_core0.DatabasePlugin<unknown>;
|
|
9
10
|
//#endregion
|
|
10
11
|
//#region src/supabaseStorage.d.ts
|
|
11
12
|
interface SupabaseStorageConfig {
|
|
@@ -17,6 +18,6 @@ interface SupabaseStorageConfig {
|
|
|
17
18
|
*/
|
|
18
19
|
basePath?: string;
|
|
19
20
|
}
|
|
20
|
-
declare const supabaseStorage: (config: SupabaseStorageConfig, hooks?:
|
|
21
|
+
declare const supabaseStorage: (config: SupabaseStorageConfig, hooks?: _$_hot_updater_plugin_core0.StoragePluginHooks) => () => _$_hot_updater_plugin_core0.StoragePlugin<unknown>;
|
|
21
22
|
//#endregion
|
|
22
|
-
export { SupabaseDatabaseConfig, SupabaseStorageConfig, supabaseDatabase, supabaseStorage };
|
|
23
|
+
export { SupabaseDatabaseConfig, SupabaseEdgeFunctionDatabaseConfig, SupabaseEdgeFunctionStorageConfig, SupabaseStorageConfig, supabaseDatabase, supabaseEdgeFunctionDatabase, supabaseEdgeFunctionStorage, supabaseStorage };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { i as supabaseEdgeFunctionDatabase, n as supabaseEdgeFunctionStorage, r as SupabaseEdgeFunctionDatabaseConfig, t as SupabaseEdgeFunctionStorageConfig } from "./supabaseEdgeFunctionStorage-ByPGforO.mjs";
|
|
2
|
+
import * as _$_hot_updater_plugin_core0 from "@hot-updater/plugin-core";
|
|
3
|
+
|
|
4
|
+
//#region src/supabaseDatabase.d.ts
|
|
5
|
+
interface SupabaseDatabaseConfig {
|
|
6
|
+
supabaseUrl: string;
|
|
7
|
+
supabaseAnonKey: string;
|
|
8
|
+
}
|
|
9
|
+
declare const supabaseDatabase: (config: SupabaseDatabaseConfig, hooks?: _$_hot_updater_plugin_core0.DatabasePluginHooks) => () => _$_hot_updater_plugin_core0.DatabasePlugin<unknown>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/supabaseStorage.d.ts
|
|
12
|
+
interface SupabaseStorageConfig {
|
|
13
|
+
supabaseUrl: string;
|
|
14
|
+
supabaseAnonKey: string;
|
|
15
|
+
bucketName: string;
|
|
16
|
+
/**
|
|
17
|
+
* Base path where bundles will be stored in the bucket
|
|
18
|
+
*/
|
|
19
|
+
basePath?: string;
|
|
20
|
+
}
|
|
21
|
+
declare const supabaseStorage: (config: SupabaseStorageConfig, hooks?: _$_hot_updater_plugin_core0.StoragePluginHooks) => () => _$_hot_updater_plugin_core0.StoragePlugin<unknown>;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { SupabaseDatabaseConfig, SupabaseEdgeFunctionDatabaseConfig, SupabaseEdgeFunctionStorageConfig, SupabaseStorageConfig, supabaseDatabase, supabaseEdgeFunctionDatabase, supabaseEdgeFunctionStorage, supabaseStorage };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { n as supabaseEdgeFunctionDatabase, r as supabaseDatabase, t as supabaseEdgeFunctionStorage } from "./supabaseEdgeFunctionStorage-CVEY5QJO.mjs";
|
|
2
|
+
import { createStorageKeyBuilder, createStoragePlugin, getContentType, parseStorageUri } from "@hot-updater/plugin-core";
|
|
3
|
+
import { createClient } from "@supabase/supabase-js";
|
|
4
|
+
import fs from "fs/promises";
|
|
5
|
+
import path from "path";
|
|
6
|
+
//#region src/supabaseStorage.ts
|
|
7
|
+
const supabaseStorage = createStoragePlugin({
|
|
8
|
+
name: "supabaseStorage",
|
|
9
|
+
supportedProtocol: "supabase-storage",
|
|
10
|
+
factory: (config) => {
|
|
11
|
+
const bucket = createClient(config.supabaseUrl, config.supabaseAnonKey).storage.from(config.bucketName);
|
|
12
|
+
const getStorageKey = createStorageKeyBuilder(config.basePath);
|
|
13
|
+
return {
|
|
14
|
+
async delete(storageUri) {
|
|
15
|
+
const { key, bucket: bucketName } = parseStorageUri(storageUri, "supabase-storage");
|
|
16
|
+
if (bucketName !== config.bucketName) throw new Error(`Bucket name mismatch: expected "${config.bucketName}", but found "${bucketName}".`);
|
|
17
|
+
const { error } = await bucket.remove([key]);
|
|
18
|
+
if (error) {
|
|
19
|
+
if (error.message?.includes("not found")) throw new Error(`Bundle not found`);
|
|
20
|
+
throw new Error(`Failed to delete bundle: ${error.message}`);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
async upload(key, filePath) {
|
|
24
|
+
const Body = await fs.readFile(filePath);
|
|
25
|
+
const ContentType = getContentType(filePath);
|
|
26
|
+
const Key = getStorageKey(key, path.basename(filePath));
|
|
27
|
+
const upload = await bucket.upload(Key, Body, {
|
|
28
|
+
contentType: ContentType,
|
|
29
|
+
cacheControl: "max-age=31536000",
|
|
30
|
+
headers: {}
|
|
31
|
+
});
|
|
32
|
+
if (upload.error) throw upload.error;
|
|
33
|
+
return { storageUri: `supabase-storage://${upload.data.fullPath}` };
|
|
34
|
+
},
|
|
35
|
+
async getDownloadUrl(storageUri) {
|
|
36
|
+
const u = new URL(storageUri);
|
|
37
|
+
if (u.protocol.replace(":", "") !== "supabase-storage") throw new Error("Invalid Supabase storage URI protocol");
|
|
38
|
+
let key = `${u.host}${u.pathname}`.replace(/^\//, "");
|
|
39
|
+
if (!key) throw new Error("Invalid Supabase storage URI: missing key");
|
|
40
|
+
if (key.startsWith(`${config.bucketName}/`)) key = key.substring(`${config.bucketName}/`.length);
|
|
41
|
+
const { data, error } = await bucket.createSignedUrl(key, 3600);
|
|
42
|
+
if (error) throw new Error(`Failed to generate download URL: ${error.message}`);
|
|
43
|
+
if (!data?.signedUrl) throw new Error("Failed to generate download URL");
|
|
44
|
+
return { fileUrl: data.signedUrl };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
//#endregion
|
|
50
|
+
export { supabaseDatabase, supabaseEdgeFunctionDatabase, supabaseEdgeFunctionStorage, supabaseStorage };
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
require("./index.cjs");
|
|
2
|
+
let _hot_updater_core = require("@hot-updater/core");
|
|
3
|
+
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
4
|
+
let _supabase_supabase_js = require("@supabase/supabase-js");
|
|
5
|
+
//#region src/supabaseDatabase.ts
|
|
6
|
+
const supabaseDatabase = (0, _hot_updater_plugin_core.createDatabasePlugin)({
|
|
7
|
+
name: "supabaseDatabase",
|
|
8
|
+
factory: (config) => {
|
|
9
|
+
const supabase = (0, _supabase_supabase_js.createClient)(config.supabaseUrl, config.supabaseAnonKey);
|
|
10
|
+
return {
|
|
11
|
+
async getBundleById(bundleId) {
|
|
12
|
+
const { data, error } = await supabase.from("bundles").select("channel, enabled, should_force_update, file_hash, git_commit_hash, id, message, platform, target_app_version, fingerprint_hash, storage_uri, metadata, rollout_cohort_count, target_cohorts").eq("id", bundleId).single();
|
|
13
|
+
if (!data || error) return null;
|
|
14
|
+
return {
|
|
15
|
+
channel: data.channel,
|
|
16
|
+
enabled: data.enabled,
|
|
17
|
+
shouldForceUpdate: data.should_force_update,
|
|
18
|
+
fileHash: data.file_hash,
|
|
19
|
+
gitCommitHash: data.git_commit_hash,
|
|
20
|
+
id: data.id,
|
|
21
|
+
message: data.message,
|
|
22
|
+
platform: data.platform,
|
|
23
|
+
targetAppVersion: data.target_app_version,
|
|
24
|
+
fingerprintHash: data.fingerprint_hash,
|
|
25
|
+
storageUri: data.storage_uri,
|
|
26
|
+
metadata: data.metadata ?? {},
|
|
27
|
+
rolloutCohortCount: data.rollout_cohort_count ?? _hot_updater_core.DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
28
|
+
targetCohorts: data.target_cohorts ?? null
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
async getBundles(options) {
|
|
32
|
+
const { where, limit, offset, orderBy } = options ?? {};
|
|
33
|
+
if (where?.targetAppVersionIn && where.targetAppVersionIn.length === 0 || where?.id?.in && where.id.in.length === 0) return {
|
|
34
|
+
data: [],
|
|
35
|
+
pagination: (0, _hot_updater_plugin_core.calculatePagination)(0, {
|
|
36
|
+
limit,
|
|
37
|
+
offset
|
|
38
|
+
})
|
|
39
|
+
};
|
|
40
|
+
let countQuery = supabase.from("bundles").select("*", {
|
|
41
|
+
count: "exact",
|
|
42
|
+
head: true
|
|
43
|
+
});
|
|
44
|
+
if (where?.channel) countQuery = countQuery.eq("channel", where.channel);
|
|
45
|
+
if (where?.platform) countQuery = countQuery.eq("platform", where.platform);
|
|
46
|
+
if (where?.enabled !== void 0) countQuery = countQuery.eq("enabled", where.enabled);
|
|
47
|
+
if (where?.fingerprintHash !== void 0) countQuery = where.fingerprintHash === null ? countQuery.is("fingerprint_hash", null) : countQuery.eq("fingerprint_hash", where.fingerprintHash);
|
|
48
|
+
if (where?.targetAppVersion !== void 0) countQuery = where.targetAppVersion === null ? countQuery.is("target_app_version", null) : countQuery.eq("target_app_version", where.targetAppVersion);
|
|
49
|
+
if (where?.targetAppVersionIn) countQuery = countQuery.in("target_app_version", where.targetAppVersionIn);
|
|
50
|
+
if (where?.targetAppVersionNotNull) countQuery = countQuery.not("target_app_version", "is", null);
|
|
51
|
+
if (where?.id?.eq) countQuery = countQuery.eq("id", where.id.eq);
|
|
52
|
+
if (where?.id?.gt) countQuery = countQuery.gt("id", where.id.gt);
|
|
53
|
+
if (where?.id?.gte) countQuery = countQuery.gte("id", where.id.gte);
|
|
54
|
+
if (where?.id?.lt) countQuery = countQuery.lt("id", where.id.lt);
|
|
55
|
+
if (where?.id?.lte) countQuery = countQuery.lte("id", where.id.lte);
|
|
56
|
+
if (where?.id?.in) countQuery = countQuery.in("id", where.id.in);
|
|
57
|
+
const { count: total = 0 } = await countQuery;
|
|
58
|
+
let query = supabase.from("bundles").select("id, channel, enabled, platform, should_force_update, file_hash, git_commit_hash, message, fingerprint_hash, target_app_version, storage_uri, metadata, rollout_cohort_count, target_cohorts").order("id", { ascending: orderBy?.direction === "asc" });
|
|
59
|
+
if (where?.channel) query = query.eq("channel", where.channel);
|
|
60
|
+
if (where?.platform) query = query.eq("platform", where.platform);
|
|
61
|
+
if (where?.enabled !== void 0) query = query.eq("enabled", where.enabled);
|
|
62
|
+
if (where?.fingerprintHash !== void 0) query = where.fingerprintHash === null ? query.is("fingerprint_hash", null) : query.eq("fingerprint_hash", where.fingerprintHash);
|
|
63
|
+
if (where?.targetAppVersion !== void 0) query = where.targetAppVersion === null ? query.is("target_app_version", null) : query.eq("target_app_version", where.targetAppVersion);
|
|
64
|
+
if (where?.targetAppVersionIn) query = query.in("target_app_version", where.targetAppVersionIn);
|
|
65
|
+
if (where?.targetAppVersionNotNull) query = query.not("target_app_version", "is", null);
|
|
66
|
+
if (where?.id?.eq) query = query.eq("id", where.id.eq);
|
|
67
|
+
if (where?.id?.gt) query = query.gt("id", where.id.gt);
|
|
68
|
+
if (where?.id?.gte) query = query.gte("id", where.id.gte);
|
|
69
|
+
if (where?.id?.lt) query = query.lt("id", where.id.lt);
|
|
70
|
+
if (where?.id?.lte) query = query.lte("id", where.id.lte);
|
|
71
|
+
if (where?.id?.in) query = query.in("id", where.id.in);
|
|
72
|
+
if (limit) query = query.limit(limit);
|
|
73
|
+
if (offset) query = query.range(offset, offset + (limit || 20) - 1);
|
|
74
|
+
const { data } = await query;
|
|
75
|
+
return {
|
|
76
|
+
data: data ? data.map((bundle) => ({
|
|
77
|
+
channel: bundle.channel,
|
|
78
|
+
enabled: bundle.enabled,
|
|
79
|
+
shouldForceUpdate: bundle.should_force_update,
|
|
80
|
+
fileHash: bundle.file_hash,
|
|
81
|
+
gitCommitHash: bundle.git_commit_hash,
|
|
82
|
+
id: bundle.id,
|
|
83
|
+
message: bundle.message,
|
|
84
|
+
platform: bundle.platform,
|
|
85
|
+
targetAppVersion: bundle.target_app_version,
|
|
86
|
+
fingerprintHash: bundle.fingerprint_hash,
|
|
87
|
+
storageUri: bundle.storage_uri,
|
|
88
|
+
metadata: bundle.metadata ?? {},
|
|
89
|
+
rolloutCohortCount: bundle.rollout_cohort_count ?? _hot_updater_core.DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
90
|
+
targetCohorts: bundle.target_cohorts ?? null
|
|
91
|
+
})) : [],
|
|
92
|
+
pagination: (0, _hot_updater_plugin_core.calculatePagination)(total ?? 0, {
|
|
93
|
+
limit,
|
|
94
|
+
offset
|
|
95
|
+
})
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
async getChannels() {
|
|
99
|
+
const { data, error } = await supabase.rpc("get_channels");
|
|
100
|
+
if (error) throw error;
|
|
101
|
+
return data.map((bundle) => bundle.channel);
|
|
102
|
+
},
|
|
103
|
+
async commitBundle({ changedSets }) {
|
|
104
|
+
if (changedSets.length === 0) return;
|
|
105
|
+
for (const op of changedSets) if (op.operation === "delete") {
|
|
106
|
+
const { error } = await supabase.from("bundles").delete().eq("id", op.data.id);
|
|
107
|
+
if (error) throw new Error(`Failed to delete bundle: ${error.message}`);
|
|
108
|
+
} else if (op.operation === "insert" || op.operation === "update") {
|
|
109
|
+
const bundle = op.data;
|
|
110
|
+
const { error } = await supabase.from("bundles").upsert({
|
|
111
|
+
id: bundle.id,
|
|
112
|
+
channel: bundle.channel,
|
|
113
|
+
enabled: bundle.enabled,
|
|
114
|
+
should_force_update: bundle.shouldForceUpdate,
|
|
115
|
+
file_hash: bundle.fileHash,
|
|
116
|
+
git_commit_hash: bundle.gitCommitHash,
|
|
117
|
+
message: bundle.message,
|
|
118
|
+
platform: bundle.platform,
|
|
119
|
+
target_app_version: bundle.targetAppVersion,
|
|
120
|
+
fingerprint_hash: bundle.fingerprintHash,
|
|
121
|
+
storage_uri: bundle.storageUri,
|
|
122
|
+
metadata: bundle.metadata,
|
|
123
|
+
rollout_cohort_count: bundle.rolloutCohortCount ?? _hot_updater_core.DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
124
|
+
target_cohorts: bundle.targetCohorts ?? null
|
|
125
|
+
}, { onConflict: "id" });
|
|
126
|
+
if (error) throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/supabaseEdgeFunctionDatabase.ts
|
|
134
|
+
const supabaseEdgeFunctionDatabase = (config, hooks) => {
|
|
135
|
+
return supabaseDatabase({
|
|
136
|
+
supabaseUrl: config.supabaseUrl,
|
|
137
|
+
supabaseAnonKey: config.supabaseServiceRoleKey
|
|
138
|
+
}, hooks);
|
|
139
|
+
};
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/supabaseEdgeFunctionStorage.ts
|
|
142
|
+
const supabaseEdgeFunctionStorage = (config) => {
|
|
143
|
+
const supabase = (0, _supabase_supabase_js.createClient)(config.supabaseUrl, config.supabaseServiceRoleKey);
|
|
144
|
+
return () => {
|
|
145
|
+
return {
|
|
146
|
+
name: "supabaseEdgeFunctionStorage",
|
|
147
|
+
supportedProtocol: "supabase-storage",
|
|
148
|
+
async upload() {
|
|
149
|
+
throw new Error("supabaseEdgeFunctionStorage does not support upload() in the edge runtime.");
|
|
150
|
+
},
|
|
151
|
+
async delete(storageUri) {
|
|
152
|
+
const storageUrl = new URL(storageUri);
|
|
153
|
+
if (storageUrl.protocol !== "supabase-storage:") throw new Error("Invalid Supabase storage URI protocol");
|
|
154
|
+
const bucketName = storageUrl.host;
|
|
155
|
+
const key = storageUrl.pathname.replace(/^\/+/, "");
|
|
156
|
+
if (!bucketName || !key) throw new Error("Invalid Supabase storage URI");
|
|
157
|
+
const { error } = await supabase.storage.from(bucketName).remove([key]);
|
|
158
|
+
if (error) throw new Error(`Failed to delete bundle: ${error.message}`);
|
|
159
|
+
},
|
|
160
|
+
async getDownloadUrl(storageUri) {
|
|
161
|
+
const storageUrl = new URL(storageUri);
|
|
162
|
+
if (storageUrl.protocol !== "supabase-storage:") throw new Error("Invalid Supabase storage URI protocol");
|
|
163
|
+
const bucketName = storageUrl.host;
|
|
164
|
+
const key = storageUrl.pathname.replace(/^\/+/, "");
|
|
165
|
+
if (!bucketName || !key) throw new Error("Invalid Supabase storage URI");
|
|
166
|
+
const { data, error } = await supabase.storage.from(bucketName).createSignedUrl(key, config.signedUrlExpiresIn ?? 3600);
|
|
167
|
+
if (error) throw new Error(`Failed to generate download URL: ${error.message}`);
|
|
168
|
+
if (!data?.signedUrl) throw new Error("Failed to generate download URL");
|
|
169
|
+
return { fileUrl: data.signedUrl };
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
//#endregion
|
|
175
|
+
Object.defineProperty(exports, "supabaseDatabase", {
|
|
176
|
+
enumerable: true,
|
|
177
|
+
get: function() {
|
|
178
|
+
return supabaseDatabase;
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
Object.defineProperty(exports, "supabaseEdgeFunctionDatabase", {
|
|
182
|
+
enumerable: true,
|
|
183
|
+
get: function() {
|
|
184
|
+
return supabaseEdgeFunctionDatabase;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
Object.defineProperty(exports, "supabaseEdgeFunctionStorage", {
|
|
188
|
+
enumerable: true,
|
|
189
|
+
get: function() {
|
|
190
|
+
return supabaseEdgeFunctionStorage;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as _$_hot_updater_plugin_core0 from "@hot-updater/plugin-core";
|
|
2
|
+
import { DatabasePluginHooks, StoragePlugin } from "@hot-updater/plugin-core";
|
|
3
|
+
|
|
4
|
+
//#region src/supabaseEdgeFunctionDatabase.d.ts
|
|
5
|
+
interface SupabaseEdgeFunctionDatabaseConfig {
|
|
6
|
+
supabaseUrl: string;
|
|
7
|
+
supabaseServiceRoleKey: string;
|
|
8
|
+
}
|
|
9
|
+
declare const supabaseEdgeFunctionDatabase: (config: SupabaseEdgeFunctionDatabaseConfig, hooks?: DatabasePluginHooks) => () => _$_hot_updater_plugin_core0.DatabasePlugin<unknown>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/supabaseEdgeFunctionStorage.d.ts
|
|
12
|
+
interface SupabaseEdgeFunctionStorageConfig {
|
|
13
|
+
supabaseUrl: string;
|
|
14
|
+
supabaseServiceRoleKey: string;
|
|
15
|
+
signedUrlExpiresIn?: number;
|
|
16
|
+
}
|
|
17
|
+
declare const supabaseEdgeFunctionStorage: (config: SupabaseEdgeFunctionStorageConfig) => () => StoragePlugin;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { supabaseEdgeFunctionDatabase as i, supabaseEdgeFunctionStorage as n, SupabaseEdgeFunctionDatabaseConfig as r, SupabaseEdgeFunctionStorageConfig as t };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as _$_hot_updater_plugin_core0 from "@hot-updater/plugin-core";
|
|
2
|
+
import { DatabasePluginHooks, StoragePlugin } from "@hot-updater/plugin-core";
|
|
3
|
+
|
|
4
|
+
//#region src/supabaseEdgeFunctionDatabase.d.ts
|
|
5
|
+
interface SupabaseEdgeFunctionDatabaseConfig {
|
|
6
|
+
supabaseUrl: string;
|
|
7
|
+
supabaseServiceRoleKey: string;
|
|
8
|
+
}
|
|
9
|
+
declare const supabaseEdgeFunctionDatabase: (config: SupabaseEdgeFunctionDatabaseConfig, hooks?: DatabasePluginHooks) => () => _$_hot_updater_plugin_core0.DatabasePlugin<unknown>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/supabaseEdgeFunctionStorage.d.ts
|
|
12
|
+
interface SupabaseEdgeFunctionStorageConfig {
|
|
13
|
+
supabaseUrl: string;
|
|
14
|
+
supabaseServiceRoleKey: string;
|
|
15
|
+
signedUrlExpiresIn?: number;
|
|
16
|
+
}
|
|
17
|
+
declare const supabaseEdgeFunctionStorage: (config: SupabaseEdgeFunctionStorageConfig) => () => StoragePlugin;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { supabaseEdgeFunctionDatabase as i, supabaseEdgeFunctionStorage as n, SupabaseEdgeFunctionDatabaseConfig as r, SupabaseEdgeFunctionStorageConfig as t };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { DEFAULT_ROLLOUT_COHORT_COUNT } from "@hot-updater/core";
|
|
2
|
+
import { calculatePagination, createDatabasePlugin } from "@hot-updater/plugin-core";
|
|
3
|
+
import { createClient } from "@supabase/supabase-js";
|
|
4
|
+
//#region src/supabaseDatabase.ts
|
|
5
|
+
const supabaseDatabase = createDatabasePlugin({
|
|
6
|
+
name: "supabaseDatabase",
|
|
7
|
+
factory: (config) => {
|
|
8
|
+
const supabase = createClient(config.supabaseUrl, config.supabaseAnonKey);
|
|
9
|
+
return {
|
|
10
|
+
async getBundleById(bundleId) {
|
|
11
|
+
const { data, error } = await supabase.from("bundles").select("channel, enabled, should_force_update, file_hash, git_commit_hash, id, message, platform, target_app_version, fingerprint_hash, storage_uri, metadata, rollout_cohort_count, target_cohorts").eq("id", bundleId).single();
|
|
12
|
+
if (!data || error) return null;
|
|
13
|
+
return {
|
|
14
|
+
channel: data.channel,
|
|
15
|
+
enabled: data.enabled,
|
|
16
|
+
shouldForceUpdate: data.should_force_update,
|
|
17
|
+
fileHash: data.file_hash,
|
|
18
|
+
gitCommitHash: data.git_commit_hash,
|
|
19
|
+
id: data.id,
|
|
20
|
+
message: data.message,
|
|
21
|
+
platform: data.platform,
|
|
22
|
+
targetAppVersion: data.target_app_version,
|
|
23
|
+
fingerprintHash: data.fingerprint_hash,
|
|
24
|
+
storageUri: data.storage_uri,
|
|
25
|
+
metadata: data.metadata ?? {},
|
|
26
|
+
rolloutCohortCount: data.rollout_cohort_count ?? DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
27
|
+
targetCohorts: data.target_cohorts ?? null
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
async getBundles(options) {
|
|
31
|
+
const { where, limit, offset, orderBy } = options ?? {};
|
|
32
|
+
if (where?.targetAppVersionIn && where.targetAppVersionIn.length === 0 || where?.id?.in && where.id.in.length === 0) return {
|
|
33
|
+
data: [],
|
|
34
|
+
pagination: calculatePagination(0, {
|
|
35
|
+
limit,
|
|
36
|
+
offset
|
|
37
|
+
})
|
|
38
|
+
};
|
|
39
|
+
let countQuery = supabase.from("bundles").select("*", {
|
|
40
|
+
count: "exact",
|
|
41
|
+
head: true
|
|
42
|
+
});
|
|
43
|
+
if (where?.channel) countQuery = countQuery.eq("channel", where.channel);
|
|
44
|
+
if (where?.platform) countQuery = countQuery.eq("platform", where.platform);
|
|
45
|
+
if (where?.enabled !== void 0) countQuery = countQuery.eq("enabled", where.enabled);
|
|
46
|
+
if (where?.fingerprintHash !== void 0) countQuery = where.fingerprintHash === null ? countQuery.is("fingerprint_hash", null) : countQuery.eq("fingerprint_hash", where.fingerprintHash);
|
|
47
|
+
if (where?.targetAppVersion !== void 0) countQuery = where.targetAppVersion === null ? countQuery.is("target_app_version", null) : countQuery.eq("target_app_version", where.targetAppVersion);
|
|
48
|
+
if (where?.targetAppVersionIn) countQuery = countQuery.in("target_app_version", where.targetAppVersionIn);
|
|
49
|
+
if (where?.targetAppVersionNotNull) countQuery = countQuery.not("target_app_version", "is", null);
|
|
50
|
+
if (where?.id?.eq) countQuery = countQuery.eq("id", where.id.eq);
|
|
51
|
+
if (where?.id?.gt) countQuery = countQuery.gt("id", where.id.gt);
|
|
52
|
+
if (where?.id?.gte) countQuery = countQuery.gte("id", where.id.gte);
|
|
53
|
+
if (where?.id?.lt) countQuery = countQuery.lt("id", where.id.lt);
|
|
54
|
+
if (where?.id?.lte) countQuery = countQuery.lte("id", where.id.lte);
|
|
55
|
+
if (where?.id?.in) countQuery = countQuery.in("id", where.id.in);
|
|
56
|
+
const { count: total = 0 } = await countQuery;
|
|
57
|
+
let query = supabase.from("bundles").select("id, channel, enabled, platform, should_force_update, file_hash, git_commit_hash, message, fingerprint_hash, target_app_version, storage_uri, metadata, rollout_cohort_count, target_cohorts").order("id", { ascending: orderBy?.direction === "asc" });
|
|
58
|
+
if (where?.channel) query = query.eq("channel", where.channel);
|
|
59
|
+
if (where?.platform) query = query.eq("platform", where.platform);
|
|
60
|
+
if (where?.enabled !== void 0) query = query.eq("enabled", where.enabled);
|
|
61
|
+
if (where?.fingerprintHash !== void 0) query = where.fingerprintHash === null ? query.is("fingerprint_hash", null) : query.eq("fingerprint_hash", where.fingerprintHash);
|
|
62
|
+
if (where?.targetAppVersion !== void 0) query = where.targetAppVersion === null ? query.is("target_app_version", null) : query.eq("target_app_version", where.targetAppVersion);
|
|
63
|
+
if (where?.targetAppVersionIn) query = query.in("target_app_version", where.targetAppVersionIn);
|
|
64
|
+
if (where?.targetAppVersionNotNull) query = query.not("target_app_version", "is", null);
|
|
65
|
+
if (where?.id?.eq) query = query.eq("id", where.id.eq);
|
|
66
|
+
if (where?.id?.gt) query = query.gt("id", where.id.gt);
|
|
67
|
+
if (where?.id?.gte) query = query.gte("id", where.id.gte);
|
|
68
|
+
if (where?.id?.lt) query = query.lt("id", where.id.lt);
|
|
69
|
+
if (where?.id?.lte) query = query.lte("id", where.id.lte);
|
|
70
|
+
if (where?.id?.in) query = query.in("id", where.id.in);
|
|
71
|
+
if (limit) query = query.limit(limit);
|
|
72
|
+
if (offset) query = query.range(offset, offset + (limit || 20) - 1);
|
|
73
|
+
const { data } = await query;
|
|
74
|
+
return {
|
|
75
|
+
data: data ? data.map((bundle) => ({
|
|
76
|
+
channel: bundle.channel,
|
|
77
|
+
enabled: bundle.enabled,
|
|
78
|
+
shouldForceUpdate: bundle.should_force_update,
|
|
79
|
+
fileHash: bundle.file_hash,
|
|
80
|
+
gitCommitHash: bundle.git_commit_hash,
|
|
81
|
+
id: bundle.id,
|
|
82
|
+
message: bundle.message,
|
|
83
|
+
platform: bundle.platform,
|
|
84
|
+
targetAppVersion: bundle.target_app_version,
|
|
85
|
+
fingerprintHash: bundle.fingerprint_hash,
|
|
86
|
+
storageUri: bundle.storage_uri,
|
|
87
|
+
metadata: bundle.metadata ?? {},
|
|
88
|
+
rolloutCohortCount: bundle.rollout_cohort_count ?? DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
89
|
+
targetCohorts: bundle.target_cohorts ?? null
|
|
90
|
+
})) : [],
|
|
91
|
+
pagination: calculatePagination(total ?? 0, {
|
|
92
|
+
limit,
|
|
93
|
+
offset
|
|
94
|
+
})
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
async getChannels() {
|
|
98
|
+
const { data, error } = await supabase.rpc("get_channels");
|
|
99
|
+
if (error) throw error;
|
|
100
|
+
return data.map((bundle) => bundle.channel);
|
|
101
|
+
},
|
|
102
|
+
async commitBundle({ changedSets }) {
|
|
103
|
+
if (changedSets.length === 0) return;
|
|
104
|
+
for (const op of changedSets) if (op.operation === "delete") {
|
|
105
|
+
const { error } = await supabase.from("bundles").delete().eq("id", op.data.id);
|
|
106
|
+
if (error) throw new Error(`Failed to delete bundle: ${error.message}`);
|
|
107
|
+
} else if (op.operation === "insert" || op.operation === "update") {
|
|
108
|
+
const bundle = op.data;
|
|
109
|
+
const { error } = await supabase.from("bundles").upsert({
|
|
110
|
+
id: bundle.id,
|
|
111
|
+
channel: bundle.channel,
|
|
112
|
+
enabled: bundle.enabled,
|
|
113
|
+
should_force_update: bundle.shouldForceUpdate,
|
|
114
|
+
file_hash: bundle.fileHash,
|
|
115
|
+
git_commit_hash: bundle.gitCommitHash,
|
|
116
|
+
message: bundle.message,
|
|
117
|
+
platform: bundle.platform,
|
|
118
|
+
target_app_version: bundle.targetAppVersion,
|
|
119
|
+
fingerprint_hash: bundle.fingerprintHash,
|
|
120
|
+
storage_uri: bundle.storageUri,
|
|
121
|
+
metadata: bundle.metadata,
|
|
122
|
+
rollout_cohort_count: bundle.rolloutCohortCount ?? DEFAULT_ROLLOUT_COHORT_COUNT,
|
|
123
|
+
target_cohorts: bundle.targetCohorts ?? null
|
|
124
|
+
}, { onConflict: "id" });
|
|
125
|
+
if (error) throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/supabaseEdgeFunctionDatabase.ts
|
|
133
|
+
const supabaseEdgeFunctionDatabase = (config, hooks) => {
|
|
134
|
+
return supabaseDatabase({
|
|
135
|
+
supabaseUrl: config.supabaseUrl,
|
|
136
|
+
supabaseAnonKey: config.supabaseServiceRoleKey
|
|
137
|
+
}, hooks);
|
|
138
|
+
};
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/supabaseEdgeFunctionStorage.ts
|
|
141
|
+
const supabaseEdgeFunctionStorage = (config) => {
|
|
142
|
+
const supabase = createClient(config.supabaseUrl, config.supabaseServiceRoleKey);
|
|
143
|
+
return () => {
|
|
144
|
+
return {
|
|
145
|
+
name: "supabaseEdgeFunctionStorage",
|
|
146
|
+
supportedProtocol: "supabase-storage",
|
|
147
|
+
async upload() {
|
|
148
|
+
throw new Error("supabaseEdgeFunctionStorage does not support upload() in the edge runtime.");
|
|
149
|
+
},
|
|
150
|
+
async delete(storageUri) {
|
|
151
|
+
const storageUrl = new URL(storageUri);
|
|
152
|
+
if (storageUrl.protocol !== "supabase-storage:") throw new Error("Invalid Supabase storage URI protocol");
|
|
153
|
+
const bucketName = storageUrl.host;
|
|
154
|
+
const key = storageUrl.pathname.replace(/^\/+/, "");
|
|
155
|
+
if (!bucketName || !key) throw new Error("Invalid Supabase storage URI");
|
|
156
|
+
const { error } = await supabase.storage.from(bucketName).remove([key]);
|
|
157
|
+
if (error) throw new Error(`Failed to delete bundle: ${error.message}`);
|
|
158
|
+
},
|
|
159
|
+
async getDownloadUrl(storageUri) {
|
|
160
|
+
const storageUrl = new URL(storageUri);
|
|
161
|
+
if (storageUrl.protocol !== "supabase-storage:") throw new Error("Invalid Supabase storage URI protocol");
|
|
162
|
+
const bucketName = storageUrl.host;
|
|
163
|
+
const key = storageUrl.pathname.replace(/^\/+/, "");
|
|
164
|
+
if (!bucketName || !key) throw new Error("Invalid Supabase storage URI");
|
|
165
|
+
const { data, error } = await supabase.storage.from(bucketName).createSignedUrl(key, config.signedUrlExpiresIn ?? 3600);
|
|
166
|
+
if (error) throw new Error(`Failed to generate download URL: ${error.message}`);
|
|
167
|
+
if (!data?.signedUrl) throw new Error("Failed to generate download URL");
|
|
168
|
+
return { fileUrl: data.signedUrl };
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
//#endregion
|
|
174
|
+
export { supabaseEdgeFunctionDatabase as n, supabaseDatabase as r, supabaseEdgeFunctionStorage as t };
|