@hot-updater/vercel 1.2.0-rc.2 → 1.2.0-rc.20
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/function/index.mjs +167 -127
- package/dist/index.cjs +28 -12
- package/dist/index.d.cts +6 -3
- package/dist/index.d.mts +6 -3
- package/dist/index.mjs +28 -12
- package/dist/init/index.cjs +18 -9
- package/dist/init/index.d.cts +3 -2
- package/dist/init/index.d.mts +3 -2
- package/dist/init/index.mjs +18 -9
- package/package.json +7 -7
package/dist/function/index.mjs
CHANGED
|
@@ -2470,6 +2470,10 @@ const nativeBuilds = defineTable({
|
|
|
2470
2470
|
type: "string",
|
|
2471
2471
|
maxLength: 255,
|
|
2472
2472
|
required: false
|
|
2473
|
+
},
|
|
2474
|
+
store_build: {
|
|
2475
|
+
type: "boolean",
|
|
2476
|
+
required: false
|
|
2473
2477
|
}
|
|
2474
2478
|
}, {
|
|
2475
2479
|
key: ["id"],
|
|
@@ -2482,6 +2486,11 @@ const nativeBuilds = defineTable({
|
|
|
2482
2486
|
eq: ["scope_key", "build_key"],
|
|
2483
2487
|
sort: ["id"]
|
|
2484
2488
|
},
|
|
2489
|
+
byStoreBuild: {
|
|
2490
|
+
eq: ["scope_key", "store_build"],
|
|
2491
|
+
sort: [],
|
|
2492
|
+
unique: true
|
|
2493
|
+
},
|
|
2485
2494
|
byChannel: {
|
|
2486
2495
|
eq: ["channel_id"],
|
|
2487
2496
|
sort: ["id"],
|
|
@@ -2677,10 +2686,7 @@ const LOG_TABLES = [
|
|
|
2677
2686
|
const LEASE_TABLE = "aggregate_lease";
|
|
2678
2687
|
const LEASE = { id: "compaction" };
|
|
2679
2688
|
const LEASE_MS = 3e4;
|
|
2680
|
-
const WINDOW_MS$1 =
|
|
2681
|
-
log: 6e4,
|
|
2682
|
-
memory: 15e3
|
|
2683
|
-
};
|
|
2689
|
+
const WINDOW_MS$1 = 6e4;
|
|
2684
2690
|
const LOG_PAGE = 200;
|
|
2685
2691
|
const GROUPS = {
|
|
2686
2692
|
commit: 1,
|
|
@@ -2688,7 +2694,6 @@ const GROUPS = {
|
|
|
2688
2694
|
flush: 256
|
|
2689
2695
|
};
|
|
2690
2696
|
const ATTEMPTS = 5;
|
|
2691
|
-
const MAX_BUFFERED = 1e4;
|
|
2692
2697
|
const log = defineTable({
|
|
2693
2698
|
id: {
|
|
2694
2699
|
type: "string",
|
|
@@ -2789,8 +2794,8 @@ const rewrite$1 = (change, key, current) => {
|
|
|
2789
2794
|
previous: current
|
|
2790
2795
|
};
|
|
2791
2796
|
};
|
|
2792
|
-
const compile = async (adapter, changes
|
|
2793
|
-
const keys = changes.map(({
|
|
2797
|
+
const compile = async (adapter, changes) => {
|
|
2798
|
+
const keys = changes.map(({ key }) => [...key.slice(0, -1), 0]);
|
|
2794
2799
|
const reads = /* @__PURE__ */ new Map();
|
|
2795
2800
|
changes.forEach((change, at) => {
|
|
2796
2801
|
if (rewrites(change)) reads.set(change.model, [...reads.get(change.model) ?? [], at]);
|
|
@@ -2836,7 +2841,7 @@ const encode = async (changes) => {
|
|
|
2836
2841
|
const zipped = await deflate(json);
|
|
2837
2842
|
return zipped !== void 0 && zipped.length < json.length ? `z${zipped}` : json;
|
|
2838
2843
|
};
|
|
2839
|
-
const createAggregateBatches = ({ engine, adapter, schema, batching: {
|
|
2844
|
+
const createAggregateBatches = ({ engine, adapter, schema, batching: { windowMs = WINDOW_MS$1 }, now }) => {
|
|
2840
2845
|
if (!schema.models.has(LEASE_TABLE)) throw new DatabaseTransactionError("An engine that batches aggregates needs aggregateBatchingModule in its schema.");
|
|
2841
2846
|
const holder = crypto.randomUUID().replaceAll("-", "");
|
|
2842
2847
|
const table = (name) => schema.models.get(name).table;
|
|
@@ -2863,61 +2868,6 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
2863
2868
|
}
|
|
2864
2869
|
return changes;
|
|
2865
2870
|
};
|
|
2866
|
-
const apply = async (changes, shard) => {
|
|
2867
|
-
let rest = changes;
|
|
2868
|
-
let ops = [];
|
|
2869
|
-
let read = true;
|
|
2870
|
-
for (let failures = 0; rest.length > 0 && failures < ATTEMPTS;) try {
|
|
2871
|
-
if (read) ops = await compile(adapter, rest, shard);
|
|
2872
|
-
let size = rest.length;
|
|
2873
|
-
const chunk = () => ops.slice(0, size).filter(isOp);
|
|
2874
|
-
while (size > 1 && !adapter.fits(chunk())) size = Math.ceil(size / 2);
|
|
2875
|
-
let result = { ok: true };
|
|
2876
|
-
if (chunk().length > 0) result = await adapter.write(chunk()).catch((error) => {
|
|
2877
|
-
warn("flush")(error);
|
|
2878
|
-
return { ok: true };
|
|
2879
|
-
});
|
|
2880
|
-
read = !result.ok && !("retry" in result);
|
|
2881
|
-
if (result.ok) {
|
|
2882
|
-
rest = rest.slice(size);
|
|
2883
|
-
ops = ops.slice(size);
|
|
2884
|
-
failures = 0;
|
|
2885
|
-
} else {
|
|
2886
|
-
failures += 1;
|
|
2887
|
-
if (!read) await sleep(failures);
|
|
2888
|
-
}
|
|
2889
|
-
} catch (error) {
|
|
2890
|
-
warn("flush")(error);
|
|
2891
|
-
return rest;
|
|
2892
|
-
}
|
|
2893
|
-
return rest;
|
|
2894
|
-
};
|
|
2895
|
-
let buffer = /* @__PURE__ */ new Map();
|
|
2896
|
-
let timer;
|
|
2897
|
-
let flushing;
|
|
2898
|
-
const shards = /* @__PURE__ */ new Map();
|
|
2899
|
-
const processShard = (model) => {
|
|
2900
|
-
if (!shards.has(model)) shards.set(model, Math.floor(Math.random() * shapeOf(model).shards));
|
|
2901
|
-
return shards.get(model);
|
|
2902
|
-
};
|
|
2903
|
-
const schedule = () => {
|
|
2904
|
-
if (timer !== void 0 || buffer.size === 0) return;
|
|
2905
|
-
timer = setTimeout(() => {
|
|
2906
|
-
timer = void 0;
|
|
2907
|
-
flushBuffer();
|
|
2908
|
-
}, windowMs);
|
|
2909
|
-
timer.unref?.();
|
|
2910
|
-
};
|
|
2911
|
-
const flushBuffer = () => flushing ??= (async () => {
|
|
2912
|
-
clearTimeout(timer);
|
|
2913
|
-
timer = void 0;
|
|
2914
|
-
const pending = [...buffer.values()];
|
|
2915
|
-
buffer = /* @__PURE__ */ new Map();
|
|
2916
|
-
mergeAll(buffer, await apply(pending, processShard));
|
|
2917
|
-
})().catch(warn("flush")).finally(() => {
|
|
2918
|
-
flushing = void 0;
|
|
2919
|
-
schedule();
|
|
2920
|
-
});
|
|
2921
2871
|
let nextDue = 0;
|
|
2922
2872
|
let compacting;
|
|
2923
2873
|
const known = /* @__PURE__ */ new Map();
|
|
@@ -3039,7 +2989,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
3039
2989
|
more
|
|
3040
2990
|
};
|
|
3041
2991
|
};
|
|
3042
|
-
const rowsFor = async (changes) => (await compile(adapter, changes
|
|
2992
|
+
const rowsFor = async (changes) => (await compile(adapter, changes)).filter(isOp);
|
|
3043
2993
|
const applyGroup = async (held, logs) => {
|
|
3044
2994
|
for (let count = logs.length; count > 0; count = Math.floor(count / 2)) {
|
|
3045
2995
|
const batch = logs.slice(0, count);
|
|
@@ -3119,19 +3069,6 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
3119
3069
|
}))).then((pages) => pages.some((page) => page.rows.length > 0)).finally(() => {
|
|
3120
3070
|
checking = void 0;
|
|
3121
3071
|
});
|
|
3122
|
-
const committed = async (changes) => {
|
|
3123
|
-
if (mode === "log") {
|
|
3124
|
-
if (now() >= nextDue) await compact(false, GROUPS.commit);
|
|
3125
|
-
return;
|
|
3126
|
-
}
|
|
3127
|
-
mergeAll(buffer, changes.values());
|
|
3128
|
-
schedule();
|
|
3129
|
-
if (buffer.size >= MAX_BUFFERED) await flushBuffer();
|
|
3130
|
-
};
|
|
3131
|
-
const flush = async () => {
|
|
3132
|
-
await flushBuffer();
|
|
3133
|
-
if (mode === "log" && await hasPending()) await compact(true, GROUPS.flush);
|
|
3134
|
-
};
|
|
3135
3072
|
return {
|
|
3136
3073
|
async transaction(fn) {
|
|
3137
3074
|
let changes = /* @__PURE__ */ new Map();
|
|
@@ -3157,7 +3094,7 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
3157
3094
|
aggregate
|
|
3158
3095
|
});
|
|
3159
3096
|
if (failure) throw failure.error;
|
|
3160
|
-
if (
|
|
3097
|
+
if (attempt.size > 0) {
|
|
3161
3098
|
const id = `${now().toString(36).padStart(9, "0")}${holder.slice(0, 8)}${crypto.randomUUID().slice(0, 8)}`;
|
|
3162
3099
|
const shard = Math.floor(Math.random() * LOG_TABLES.length);
|
|
3163
3100
|
const merged = mergeAll(/* @__PURE__ */ new Map(), attempt.values());
|
|
@@ -3171,24 +3108,18 @@ const createAggregateBatches = ({ engine, adapter, schema, batching: { mode = "l
|
|
|
3171
3108
|
open = false;
|
|
3172
3109
|
}
|
|
3173
3110
|
});
|
|
3174
|
-
if (changes.size > 0) await
|
|
3111
|
+
if (changes.size > 0 && now() >= nextDue) await compact(false, GROUPS.commit);
|
|
3175
3112
|
return result;
|
|
3176
3113
|
},
|
|
3177
3114
|
async beforeRead(name) {
|
|
3178
3115
|
if (!isBatched(schema.models.get(name))) return;
|
|
3179
|
-
if (
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
return false;
|
|
3184
|
-
})) await compact(true, GROUPS.read);
|
|
3185
|
-
}
|
|
3116
|
+
if (await hasPending().catch((error) => {
|
|
3117
|
+
warn("read")(error);
|
|
3118
|
+
return false;
|
|
3119
|
+
})) await compact(true, GROUPS.read);
|
|
3186
3120
|
},
|
|
3187
|
-
flush
|
|
3188
|
-
|
|
3189
|
-
clearTimeout(timer);
|
|
3190
|
-
timer = void 0;
|
|
3191
|
-
await flush();
|
|
3121
|
+
async flush() {
|
|
3122
|
+
if (await hasPending()) await compact(true, GROUPS.flush);
|
|
3192
3123
|
}
|
|
3193
3124
|
};
|
|
3194
3125
|
};
|
|
@@ -4147,9 +4078,6 @@ const createDatabaseEngine = ({ batching, now = Date.now, meter, ...options }) =
|
|
|
4147
4078
|
flush: async () => {
|
|
4148
4079
|
await batches?.flush();
|
|
4149
4080
|
},
|
|
4150
|
-
dispose: async () => {
|
|
4151
|
-
await batches?.dispose();
|
|
4152
|
-
},
|
|
4153
4081
|
database(module) {
|
|
4154
4082
|
const name = (model) => module.namespace ? `${module.namespace}_${model}` : model;
|
|
4155
4083
|
return {
|
|
@@ -4217,8 +4145,7 @@ const createEngine = (database, { plugins = [], now = Date.now } = {}) => {
|
|
|
4217
4145
|
if (module === void 0) throw new HotUpdaterConfigError(`Plugin "${plugin.id}" is not one of this engine's plugins.`);
|
|
4218
4146
|
return engine.database(module);
|
|
4219
4147
|
},
|
|
4220
|
-
flush: () => engine.flush()
|
|
4221
|
-
dispose: () => engine.dispose()
|
|
4148
|
+
flush: () => engine.flush()
|
|
4222
4149
|
};
|
|
4223
4150
|
};
|
|
4224
4151
|
//#endregion
|
|
@@ -17667,6 +17594,7 @@ var import_lib$1 = /* @__PURE__ */ __toESM(require_lib$2(), 1);
|
|
|
17667
17594
|
const { Pool } = import_lib$1.default;
|
|
17668
17595
|
const DATABASE_TARGET = Symbol.for("@hot-updater/database-target");
|
|
17669
17596
|
const targetOf = ({ connectionString, host, port, database }) => {
|
|
17597
|
+
if (typeof connectionString === "function") return void 0;
|
|
17670
17598
|
if (connectionString !== void 0) try {
|
|
17671
17599
|
const url = new URL(connectionString);
|
|
17672
17600
|
return `postgres/${url.hostname}:${url.port || "5432"}/${decodeURIComponent(url.pathname.slice(1))}`;
|
|
@@ -17678,7 +17606,14 @@ const targetOf = ({ connectionString, host, port, database }) => {
|
|
|
17678
17606
|
const postgres = (config) => {
|
|
17679
17607
|
const { dialect, ...poolConfig } = config;
|
|
17680
17608
|
const target = targetOf(poolConfig);
|
|
17681
|
-
const
|
|
17609
|
+
const { connectionString } = poolConfig;
|
|
17610
|
+
const db = new Kysely({ dialect: dialect ?? new PostgresDialect({ pool: typeof connectionString === "function" ? async () => new Pool({
|
|
17611
|
+
...poolConfig,
|
|
17612
|
+
connectionString: await connectionString()
|
|
17613
|
+
}) : new Pool({
|
|
17614
|
+
...poolConfig,
|
|
17615
|
+
connectionString
|
|
17616
|
+
}) }) });
|
|
17682
17617
|
return {
|
|
17683
17618
|
...createEngineDatabase({
|
|
17684
17619
|
name: "postgres",
|
|
@@ -17690,7 +17625,7 @@ const postgres = (config) => {
|
|
|
17690
17625
|
};
|
|
17691
17626
|
//#endregion
|
|
17692
17627
|
//#region ../../packages/server/dist/version.mjs
|
|
17693
|
-
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.
|
|
17628
|
+
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.20";
|
|
17694
17629
|
//#endregion
|
|
17695
17630
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
17696
17631
|
const createVersionRouteHandlers = (plugins = []) => {
|
|
@@ -18798,8 +18733,12 @@ const pick = (row) => ({
|
|
|
18798
18733
|
build_number: row.build_number ?? null,
|
|
18799
18734
|
submitted_to: row.submitted_to ?? null,
|
|
18800
18735
|
submitted_at_ms: row.submitted_at_ms ?? null,
|
|
18801
|
-
submitted_version: row.submitted_version ?? null
|
|
18736
|
+
submitted_version: row.submitted_version ?? null,
|
|
18737
|
+
store_build: row.store_build === true ? true : null
|
|
18802
18738
|
});
|
|
18739
|
+
const SANDBOX_CHANNEL_PREFIX = "sandbox-";
|
|
18740
|
+
const OLDER_BUILDS_PAGE = 20;
|
|
18741
|
+
const MARK_ATTEMPTS = 8;
|
|
18803
18742
|
const SUBMISSION_DESTINATIONS = {
|
|
18804
18743
|
android: "play-internal",
|
|
18805
18744
|
ios: "testflight"
|
|
@@ -18865,7 +18804,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
18865
18804
|
build_number: registration.buildNumber ?? null,
|
|
18866
18805
|
submitted_to: null,
|
|
18867
18806
|
submitted_at_ms: null,
|
|
18868
|
-
submitted_version: null
|
|
18807
|
+
submitted_version: null,
|
|
18808
|
+
store_build: null
|
|
18869
18809
|
};
|
|
18870
18810
|
for (let attempt = 1;; attempt += 1) {
|
|
18871
18811
|
await insertChannel(db, {
|
|
@@ -18903,21 +18843,45 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
18903
18843
|
const scopeKey = nativeBuildScopeKey(scope);
|
|
18904
18844
|
const buildKey = options?.buildKey;
|
|
18905
18845
|
if (buildKey !== void 0 && !BUILD_KEY.test(buildKey)) throw new NativeBuildInputError("Invalid native build key: it must be nbk1: and a SHA-256.");
|
|
18906
|
-
|
|
18907
|
-
|
|
18908
|
-
where: { scope_key: scopeKey },
|
|
18909
|
-
order: "desc",
|
|
18910
|
-
limit: 1
|
|
18911
|
-
}) : await db.findMany("native_builds", {
|
|
18912
|
-
index: "byBuildKey",
|
|
18913
|
-
where: {
|
|
18846
|
+
if (options?.storeBuild) {
|
|
18847
|
+
const marked = await db.findOne("native_builds", {
|
|
18914
18848
|
scope_key: scopeKey,
|
|
18915
|
-
|
|
18916
|
-
}
|
|
18917
|
-
|
|
18918
|
-
|
|
18919
|
-
|
|
18920
|
-
|
|
18849
|
+
store_build: true
|
|
18850
|
+
});
|
|
18851
|
+
return marked === null ? null : pick(marked);
|
|
18852
|
+
}
|
|
18853
|
+
const read = (limit, before) => {
|
|
18854
|
+
const page = {
|
|
18855
|
+
order: "desc",
|
|
18856
|
+
limit,
|
|
18857
|
+
...before === void 0 ? {} : { range: { lt: before } }
|
|
18858
|
+
};
|
|
18859
|
+
return buildKey === void 0 ? db.findMany("native_builds", {
|
|
18860
|
+
index: "byScope",
|
|
18861
|
+
where: { scope_key: scopeKey },
|
|
18862
|
+
...page
|
|
18863
|
+
}) : db.findMany("native_builds", {
|
|
18864
|
+
index: "byBuildKey",
|
|
18865
|
+
where: {
|
|
18866
|
+
scope_key: scopeKey,
|
|
18867
|
+
build_key: buildKey
|
|
18868
|
+
},
|
|
18869
|
+
...page
|
|
18870
|
+
});
|
|
18871
|
+
};
|
|
18872
|
+
const { rows } = await read(1);
|
|
18873
|
+
const newest = rows[0];
|
|
18874
|
+
if (newest === void 0) return null;
|
|
18875
|
+
const bundleId = options?.builtInOlderThan;
|
|
18876
|
+
if (bundleId === void 0 || newest.min_bundle_id < bundleId) return pick(newest);
|
|
18877
|
+
for (let before = newest.id;;) {
|
|
18878
|
+
const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
|
|
18879
|
+
const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
|
|
18880
|
+
if (usable !== void 0) return pick(usable);
|
|
18881
|
+
const last = older.at(-1);
|
|
18882
|
+
if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
|
|
18883
|
+
before = last.id;
|
|
18884
|
+
}
|
|
18921
18885
|
},
|
|
18922
18886
|
async recordNativeBuildSubmission(id, { destination, version }) {
|
|
18923
18887
|
if (version.trim().length === 0 || version.length > SUBMITTED_VERSION_MAX_LENGTH) throw new NativeBuildInputError(`Invalid native build submission: version must be the store's label of the build, up to ${SUBMITTED_VERSION_MAX_LENGTH} characters.`);
|
|
@@ -18938,6 +18902,49 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
18938
18902
|
};
|
|
18939
18903
|
});
|
|
18940
18904
|
},
|
|
18905
|
+
async markNativeBuild(id, { storeBuild }) {
|
|
18906
|
+
for (let attempt = 1;; attempt += 1) try {
|
|
18907
|
+
return await db.transaction(async (tx) => {
|
|
18908
|
+
const row = await tx.findOne("native_builds", { id });
|
|
18909
|
+
if (row === null) return null;
|
|
18910
|
+
const build = pick(row);
|
|
18911
|
+
if (!storeBuild) {
|
|
18912
|
+
if (build.store_build !== null) tx.update("native_builds", row, { store_build: null });
|
|
18913
|
+
return {
|
|
18914
|
+
nativeBuild: {
|
|
18915
|
+
...build,
|
|
18916
|
+
store_build: null
|
|
18917
|
+
},
|
|
18918
|
+
previous: null
|
|
18919
|
+
};
|
|
18920
|
+
}
|
|
18921
|
+
if (decodeChannelKey(build.channel_id.slice(8)).startsWith(SANDBOX_CHANNEL_PREFIX)) throw new NativeBuildInputError("A build on a sandbox channel can't be the store build.");
|
|
18922
|
+
if (build.store_build !== null) return {
|
|
18923
|
+
nativeBuild: build,
|
|
18924
|
+
previous: null
|
|
18925
|
+
};
|
|
18926
|
+
const holder = await tx.findOne("native_builds", {
|
|
18927
|
+
scope_key: build.scope_key,
|
|
18928
|
+
store_build: true
|
|
18929
|
+
});
|
|
18930
|
+
if (holder !== null) tx.update("native_builds", holder, { store_build: null });
|
|
18931
|
+
tx.update("native_builds", row, { store_build: true });
|
|
18932
|
+
return {
|
|
18933
|
+
nativeBuild: {
|
|
18934
|
+
...build,
|
|
18935
|
+
store_build: true
|
|
18936
|
+
},
|
|
18937
|
+
previous: holder === null ? null : {
|
|
18938
|
+
...pick(holder),
|
|
18939
|
+
store_build: null
|
|
18940
|
+
}
|
|
18941
|
+
};
|
|
18942
|
+
});
|
|
18943
|
+
} catch (error) {
|
|
18944
|
+
if (attempt < MARK_ATTEMPTS && error instanceof DatabaseConstraintError && error.reason === "unique") continue;
|
|
18945
|
+
throw error;
|
|
18946
|
+
}
|
|
18947
|
+
},
|
|
18941
18948
|
async deleteNativeBuild(id) {
|
|
18942
18949
|
return db.transaction(async (tx) => {
|
|
18943
18950
|
const row = await tx.findOne("native_builds", { id });
|
|
@@ -19964,7 +19971,13 @@ const createAdminRouteHandlers = () => ({
|
|
|
19964
19971
|
const url = new URL(request.url);
|
|
19965
19972
|
const scope = nativeBuildScopeOf(url);
|
|
19966
19973
|
const buildKey = url.searchParams.get("buildKey");
|
|
19967
|
-
|
|
19974
|
+
const builtInOlderThan = url.searchParams.get("builtInOlderThan");
|
|
19975
|
+
const options = {
|
|
19976
|
+
...buildKey === null ? {} : { buildKey },
|
|
19977
|
+
...url.searchParams.get("storeBuild") === "true" ? { storeBuild: true } : {},
|
|
19978
|
+
...builtInOlderThan === null ? {} : { builtInOlderThan }
|
|
19979
|
+
};
|
|
19980
|
+
return json$2({ data: await refusingInvalid(() => Object.keys(options).length === 0 ? core.findNativeBuild(scope) : core.findNativeBuild(scope, options)) });
|
|
19968
19981
|
}),
|
|
19969
19982
|
getNativeBuild: onCore(async (core, _request, params) => json$2({ data: await core.getNativeBuild(requireRouteParam(params, "id")) })),
|
|
19970
19983
|
listNativeBuilds: onCore(async (core, request) => {
|
|
@@ -19985,6 +19998,12 @@ const createAdminRouteHandlers = () => ({
|
|
|
19985
19998
|
};
|
|
19986
19999
|
return json$2({ data: await refusingInvalid(() => core.recordNativeBuildSubmission(requireRouteParam(params, "id"), submission)) });
|
|
19987
20000
|
}),
|
|
20001
|
+
markNativeBuild: onCore(async (core, request, params) => {
|
|
20002
|
+
const input = await body(request);
|
|
20003
|
+
if (!isRecord$5(input) || typeof input.storeBuild !== "boolean") throw new HandlerBadRequestError("A native build's store build mark needs storeBuild, true or false.");
|
|
20004
|
+
const mark = { storeBuild: input.storeBuild };
|
|
20005
|
+
return json$2({ data: await refusingInvalid(() => core.markNativeBuild(requireRouteParam(params, "id"), mark)) });
|
|
20006
|
+
}),
|
|
19988
20007
|
deleteNativeBuild: onCore(async (core, _request, params) => json$2({ data: await core.deleteNativeBuild(requireRouteParam(params, "id")) })),
|
|
19989
20008
|
deleteBundles: onCore(async (core, request) => {
|
|
19990
20009
|
const { ids } = await body(request);
|
|
@@ -20129,6 +20148,11 @@ const ADMIN_ROUTES = [
|
|
|
20129
20148
|
path: "/native-builds/:id/submission",
|
|
20130
20149
|
handler: "recordNativeBuildSubmission"
|
|
20131
20150
|
},
|
|
20151
|
+
{
|
|
20152
|
+
method: "POST",
|
|
20153
|
+
path: "/native-builds/:id/store-build",
|
|
20154
|
+
handler: "markNativeBuild"
|
|
20155
|
+
},
|
|
20132
20156
|
{
|
|
20133
20157
|
method: "DELETE",
|
|
20134
20158
|
path: "/native-builds/:id",
|
|
@@ -53985,9 +54009,17 @@ const storeIdOf = (token) => {
|
|
|
53985
54009
|
};
|
|
53986
54010
|
const access = "private";
|
|
53987
54011
|
const vercelBlobStorage = (config) => {
|
|
53988
|
-
|
|
53989
|
-
|
|
53990
|
-
|
|
54012
|
+
let resolved;
|
|
54013
|
+
const store = () => resolved ??= (async () => {
|
|
54014
|
+
const token = typeof config.token === "function" ? await config.token() : config.token;
|
|
54015
|
+
return {
|
|
54016
|
+
token,
|
|
54017
|
+
storeId: storeIdOf(token)
|
|
54018
|
+
};
|
|
54019
|
+
})().catch((error) => {
|
|
54020
|
+
resolved = void 0;
|
|
54021
|
+
throw error;
|
|
54022
|
+
});
|
|
53991
54023
|
const normalizedBasePath = config.basePath?.replace(/^\/+|\/+$/g, "") ?? "";
|
|
53992
54024
|
const getStorageKey = createStorageKeyBuilder(normalizedBasePath);
|
|
53993
54025
|
const expiresIn = config.signedUrlExpiresIn ?? 3600;
|
|
@@ -53997,6 +54029,7 @@ const vercelBlobStorage = (config) => {
|
|
|
53997
54029
|
const delegationUntil = async (validUntil) => {
|
|
53998
54030
|
const current = await delegation?.catch(() => void 0);
|
|
53999
54031
|
if (current !== void 0 && current.validUntil >= validUntil) return current;
|
|
54032
|
+
const { token } = await store();
|
|
54000
54033
|
const issued = issueSignedToken({
|
|
54001
54034
|
token,
|
|
54002
54035
|
operations: ["get"],
|
|
@@ -54005,10 +54038,14 @@ const vercelBlobStorage = (config) => {
|
|
|
54005
54038
|
delegation = issued;
|
|
54006
54039
|
return issued;
|
|
54007
54040
|
};
|
|
54008
|
-
const parseAndValidate = (storageUri) => {
|
|
54041
|
+
const parseAndValidate = async (storageUri) => {
|
|
54009
54042
|
const parsed = parseStorageUri(storageUri, PROTOCOL);
|
|
54010
|
-
|
|
54011
|
-
|
|
54043
|
+
const { token, storeId } = await store();
|
|
54044
|
+
if (parsed.bucket !== storeId) throw new Error(`Blob store mismatch: expected "${storeId}", but found "${parsed.bucket}".`);
|
|
54045
|
+
return {
|
|
54046
|
+
...parsed,
|
|
54047
|
+
token
|
|
54048
|
+
};
|
|
54012
54049
|
};
|
|
54013
54050
|
const getListPrefix = (prefix = "") => {
|
|
54014
54051
|
const value = [normalizedBasePath, prefix.replace(/^\/+|\/+$/g, "")].filter(Boolean).join("/");
|
|
@@ -54024,9 +54061,10 @@ const vercelBlobStorage = (config) => {
|
|
|
54024
54061
|
protocol: PROTOCOL,
|
|
54025
54062
|
async put({ key, body, contentLength, contentType }) {
|
|
54026
54063
|
const storageKey = getStorageKey(key);
|
|
54064
|
+
const { token, storeId } = await store();
|
|
54027
54065
|
const storageUri = createStorageUri({
|
|
54028
54066
|
protocol: PROTOCOL,
|
|
54029
|
-
bucket: storeId
|
|
54067
|
+
bucket: storeId,
|
|
54030
54068
|
key: storageKey
|
|
54031
54069
|
});
|
|
54032
54070
|
await put(toPathname(storageKey), body, {
|
|
@@ -54041,7 +54079,7 @@ const vercelBlobStorage = (config) => {
|
|
|
54041
54079
|
return { storageUri };
|
|
54042
54080
|
},
|
|
54043
54081
|
async get({ storageUri }) {
|
|
54044
|
-
const { key } = parseAndValidate(storageUri);
|
|
54082
|
+
const { key, token } = await parseAndValidate(storageUri);
|
|
54045
54083
|
const result = await get(toPathname(key), {
|
|
54046
54084
|
access,
|
|
54047
54085
|
token,
|
|
@@ -54055,7 +54093,7 @@ const vercelBlobStorage = (config) => {
|
|
|
54055
54093
|
} }) };
|
|
54056
54094
|
},
|
|
54057
54095
|
async getDownloadUrl({ storageUri }) {
|
|
54058
|
-
const { key } = parseAndValidate(storageUri);
|
|
54096
|
+
const { key } = await parseAndValidate(storageUri);
|
|
54059
54097
|
const pathname = toPathname(key);
|
|
54060
54098
|
const validUntil = Date.now() + expiresInMs;
|
|
54061
54099
|
const { presignedUrl } = await presignUrl(await delegationUntil(validUntil), {
|
|
@@ -54067,7 +54105,7 @@ const vercelBlobStorage = (config) => {
|
|
|
54067
54105
|
return { url: presignedUrl };
|
|
54068
54106
|
},
|
|
54069
54107
|
async exists({ storageUri }) {
|
|
54070
|
-
const { key } = parseAndValidate(storageUri);
|
|
54108
|
+
const { key, token } = await parseAndValidate(storageUri);
|
|
54071
54109
|
try {
|
|
54072
54110
|
await head(toPathname(key), { token });
|
|
54073
54111
|
return { exists: true };
|
|
@@ -54077,11 +54115,12 @@ const vercelBlobStorage = (config) => {
|
|
|
54077
54115
|
}
|
|
54078
54116
|
},
|
|
54079
54117
|
async delete({ storageUri }) {
|
|
54080
|
-
const { key } = parseAndValidate(storageUri);
|
|
54118
|
+
const { key, token } = await parseAndValidate(storageUri);
|
|
54081
54119
|
await del(toPathname(key), { token });
|
|
54082
54120
|
return { deleted: true };
|
|
54083
54121
|
},
|
|
54084
54122
|
async listObjects(prefix) {
|
|
54123
|
+
const { token, storeId } = await store();
|
|
54085
54124
|
const objects = [];
|
|
54086
54125
|
let cursor;
|
|
54087
54126
|
do {
|
|
@@ -54098,7 +54137,7 @@ const vercelBlobStorage = (config) => {
|
|
|
54098
54137
|
try {
|
|
54099
54138
|
storageUri = createStorageUri({
|
|
54100
54139
|
protocol: PROTOCOL,
|
|
54101
|
-
bucket: storeId
|
|
54140
|
+
bucket: storeId,
|
|
54102
54141
|
key
|
|
54103
54142
|
});
|
|
54104
54143
|
} catch {
|
|
@@ -54116,6 +54155,7 @@ const vercelBlobStorage = (config) => {
|
|
|
54116
54155
|
return objects;
|
|
54117
54156
|
},
|
|
54118
54157
|
async deleteObjects(relativeKeys) {
|
|
54158
|
+
const { token } = await store();
|
|
54119
54159
|
const pathnames = relativeKeys.map((key) => toPathname(getStorageKey(key)));
|
|
54120
54160
|
for (let offset = 0; offset < pathnames.length; offset += DELETE_BATCH_SIZE) await del(pathnames.slice(offset, offset + DELETE_BATCH_SIZE), { token });
|
|
54121
54161
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -69,9 +69,17 @@ const access = "private";
|
|
|
69
69
|
* that expire, so the store's objects never sit at a public address.
|
|
70
70
|
*/
|
|
71
71
|
const vercelBlobStorage = (config) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
let resolved;
|
|
73
|
+
const store = () => resolved ??= (async () => {
|
|
74
|
+
const token = typeof config.token === "function" ? await config.token() : config.token;
|
|
75
|
+
return {
|
|
76
|
+
token,
|
|
77
|
+
storeId: storeIdOf(token)
|
|
78
|
+
};
|
|
79
|
+
})().catch((error) => {
|
|
80
|
+
resolved = void 0;
|
|
81
|
+
throw error;
|
|
82
|
+
});
|
|
75
83
|
const normalizedBasePath = config.basePath?.replace(/^\/+|\/+$/g, "") ?? "";
|
|
76
84
|
const getStorageKey = (0, _hot_updater_plugin_core.createStorageKeyBuilder)(normalizedBasePath);
|
|
77
85
|
const expiresIn = config.signedUrlExpiresIn ?? 3600;
|
|
@@ -82,6 +90,7 @@ const vercelBlobStorage = (config) => {
|
|
|
82
90
|
const delegationUntil = async (validUntil) => {
|
|
83
91
|
const current = await delegation?.catch(() => void 0);
|
|
84
92
|
if (current !== void 0 && current.validUntil >= validUntil) return current;
|
|
93
|
+
const { token } = await store();
|
|
85
94
|
const issued = (0, _vercel_blob.issueSignedToken)({
|
|
86
95
|
token,
|
|
87
96
|
operations: ["get"],
|
|
@@ -90,10 +99,14 @@ const vercelBlobStorage = (config) => {
|
|
|
90
99
|
delegation = issued;
|
|
91
100
|
return issued;
|
|
92
101
|
};
|
|
93
|
-
const parseAndValidate = (storageUri) => {
|
|
102
|
+
const parseAndValidate = async (storageUri) => {
|
|
94
103
|
const parsed = (0, _hot_updater_plugin_core.parseStorageUri)(storageUri, PROTOCOL);
|
|
95
|
-
|
|
96
|
-
|
|
104
|
+
const { token, storeId } = await store();
|
|
105
|
+
if (parsed.bucket !== storeId) throw new Error(`Blob store mismatch: expected "${storeId}", but found "${parsed.bucket}".`);
|
|
106
|
+
return {
|
|
107
|
+
...parsed,
|
|
108
|
+
token
|
|
109
|
+
};
|
|
97
110
|
};
|
|
98
111
|
const getListPrefix = (prefix = "") => {
|
|
99
112
|
const value = [normalizedBasePath, prefix.replace(/^\/+|\/+$/g, "")].filter(Boolean).join("/");
|
|
@@ -109,9 +122,10 @@ const vercelBlobStorage = (config) => {
|
|
|
109
122
|
protocol: PROTOCOL,
|
|
110
123
|
async put({ key, body, contentLength, contentType }) {
|
|
111
124
|
const storageKey = getStorageKey(key);
|
|
125
|
+
const { token, storeId } = await store();
|
|
112
126
|
const storageUri = (0, _hot_updater_plugin_core.createStorageUri)({
|
|
113
127
|
protocol: PROTOCOL,
|
|
114
|
-
bucket: storeId
|
|
128
|
+
bucket: storeId,
|
|
115
129
|
key: storageKey
|
|
116
130
|
});
|
|
117
131
|
await (0, _vercel_blob.put)(toPathname(storageKey), body, {
|
|
@@ -126,7 +140,7 @@ const vercelBlobStorage = (config) => {
|
|
|
126
140
|
return { storageUri };
|
|
127
141
|
},
|
|
128
142
|
async get({ storageUri }) {
|
|
129
|
-
const { key } = parseAndValidate(storageUri);
|
|
143
|
+
const { key, token } = await parseAndValidate(storageUri);
|
|
130
144
|
const result = await (0, _vercel_blob.get)(toPathname(key), {
|
|
131
145
|
access,
|
|
132
146
|
token,
|
|
@@ -140,7 +154,7 @@ const vercelBlobStorage = (config) => {
|
|
|
140
154
|
} }) };
|
|
141
155
|
},
|
|
142
156
|
async getDownloadUrl({ storageUri }) {
|
|
143
|
-
const { key } = parseAndValidate(storageUri);
|
|
157
|
+
const { key } = await parseAndValidate(storageUri);
|
|
144
158
|
const pathname = toPathname(key);
|
|
145
159
|
const validUntil = Date.now() + expiresInMs;
|
|
146
160
|
const { presignedUrl } = await (0, _vercel_blob.presignUrl)(await delegationUntil(validUntil), {
|
|
@@ -152,7 +166,7 @@ const vercelBlobStorage = (config) => {
|
|
|
152
166
|
return { url: presignedUrl };
|
|
153
167
|
},
|
|
154
168
|
async exists({ storageUri }) {
|
|
155
|
-
const { key } = parseAndValidate(storageUri);
|
|
169
|
+
const { key, token } = await parseAndValidate(storageUri);
|
|
156
170
|
try {
|
|
157
171
|
await (0, _vercel_blob.head)(toPathname(key), { token });
|
|
158
172
|
return { exists: true };
|
|
@@ -162,11 +176,12 @@ const vercelBlobStorage = (config) => {
|
|
|
162
176
|
}
|
|
163
177
|
},
|
|
164
178
|
async delete({ storageUri }) {
|
|
165
|
-
const { key } = parseAndValidate(storageUri);
|
|
179
|
+
const { key, token } = await parseAndValidate(storageUri);
|
|
166
180
|
await (0, _vercel_blob.del)(toPathname(key), { token });
|
|
167
181
|
return { deleted: true };
|
|
168
182
|
},
|
|
169
183
|
async listObjects(prefix) {
|
|
184
|
+
const { token, storeId } = await store();
|
|
170
185
|
const objects = [];
|
|
171
186
|
let cursor;
|
|
172
187
|
do {
|
|
@@ -183,7 +198,7 @@ const vercelBlobStorage = (config) => {
|
|
|
183
198
|
try {
|
|
184
199
|
storageUri = (0, _hot_updater_plugin_core.createStorageUri)({
|
|
185
200
|
protocol: PROTOCOL,
|
|
186
|
-
bucket: storeId
|
|
201
|
+
bucket: storeId,
|
|
187
202
|
key
|
|
188
203
|
});
|
|
189
204
|
} catch {
|
|
@@ -201,6 +216,7 @@ const vercelBlobStorage = (config) => {
|
|
|
201
216
|
return objects;
|
|
202
217
|
},
|
|
203
218
|
async deleteObjects(relativeKeys) {
|
|
219
|
+
const { token } = await store();
|
|
204
220
|
const pathnames = relativeKeys.map((key) => toPathname(getStorageKey(key)));
|
|
205
221
|
for (let offset = 0; offset < pathnames.length; offset += DELETE_BATCH_SIZE) await (0, _vercel_blob.del)(pathnames.slice(offset, offset + DELETE_BATCH_SIZE), { token });
|
|
206
222
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { StorageAdapterWith } from "@hot-updater/plugin-core";
|
|
1
|
+
import { Lazy, StorageAdapterWith } from "@hot-updater/plugin-core";
|
|
2
2
|
import { PostgresConfig, postgres } from "@hot-updater/postgres";
|
|
3
3
|
//#region src/vercelBlobStorage.d.ts
|
|
4
4
|
interface VercelBlobStorageConfig {
|
|
5
5
|
/**
|
|
6
6
|
* The Blob store's read-write token, `vercel_blob_rw_<storeId>_<secret>`:
|
|
7
|
-
* the `BLOB_READ_WRITE_TOKEN` Vercel adds to a project the store connects
|
|
7
|
+
* the `BLOB_READ_WRITE_TOKEN` Vercel adds to a project the store connects
|
|
8
|
+
* to. Or a function that returns it, such as `secret("<name>")` in
|
|
9
|
+
* `hot-updater.config.ts`: called on first use, so a config loads without
|
|
10
|
+
* the token.
|
|
8
11
|
*/
|
|
9
|
-
token: string
|
|
12
|
+
token: Lazy<string>;
|
|
10
13
|
/** Base path where bundles will be stored in the store. */
|
|
11
14
|
basePath?: string;
|
|
12
15
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { StorageAdapterWith } from "@hot-updater/plugin-core";
|
|
1
|
+
import { Lazy, StorageAdapterWith } from "@hot-updater/plugin-core";
|
|
2
2
|
import { PostgresConfig, postgres } from "@hot-updater/postgres";
|
|
3
3
|
//#region src/vercelBlobStorage.d.ts
|
|
4
4
|
interface VercelBlobStorageConfig {
|
|
5
5
|
/**
|
|
6
6
|
* The Blob store's read-write token, `vercel_blob_rw_<storeId>_<secret>`:
|
|
7
|
-
* the `BLOB_READ_WRITE_TOKEN` Vercel adds to a project the store connects
|
|
7
|
+
* the `BLOB_READ_WRITE_TOKEN` Vercel adds to a project the store connects
|
|
8
|
+
* to. Or a function that returns it, such as `secret("<name>")` in
|
|
9
|
+
* `hot-updater.config.ts`: called on first use, so a config loads without
|
|
10
|
+
* the token.
|
|
8
11
|
*/
|
|
9
|
-
token: string
|
|
12
|
+
token: Lazy<string>;
|
|
10
13
|
/** Base path where bundles will be stored in the store. */
|
|
11
14
|
basePath?: string;
|
|
12
15
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -68,9 +68,17 @@ const access = "private";
|
|
|
68
68
|
* that expire, so the store's objects never sit at a public address.
|
|
69
69
|
*/
|
|
70
70
|
const vercelBlobStorage = (config) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
let resolved;
|
|
72
|
+
const store = () => resolved ??= (async () => {
|
|
73
|
+
const token = typeof config.token === "function" ? await config.token() : config.token;
|
|
74
|
+
return {
|
|
75
|
+
token,
|
|
76
|
+
storeId: storeIdOf(token)
|
|
77
|
+
};
|
|
78
|
+
})().catch((error) => {
|
|
79
|
+
resolved = void 0;
|
|
80
|
+
throw error;
|
|
81
|
+
});
|
|
74
82
|
const normalizedBasePath = config.basePath?.replace(/^\/+|\/+$/g, "") ?? "";
|
|
75
83
|
const getStorageKey = createStorageKeyBuilder(normalizedBasePath);
|
|
76
84
|
const expiresIn = config.signedUrlExpiresIn ?? 3600;
|
|
@@ -81,6 +89,7 @@ const vercelBlobStorage = (config) => {
|
|
|
81
89
|
const delegationUntil = async (validUntil) => {
|
|
82
90
|
const current = await delegation?.catch(() => void 0);
|
|
83
91
|
if (current !== void 0 && current.validUntil >= validUntil) return current;
|
|
92
|
+
const { token } = await store();
|
|
84
93
|
const issued = issueSignedToken({
|
|
85
94
|
token,
|
|
86
95
|
operations: ["get"],
|
|
@@ -89,10 +98,14 @@ const vercelBlobStorage = (config) => {
|
|
|
89
98
|
delegation = issued;
|
|
90
99
|
return issued;
|
|
91
100
|
};
|
|
92
|
-
const parseAndValidate = (storageUri) => {
|
|
101
|
+
const parseAndValidate = async (storageUri) => {
|
|
93
102
|
const parsed = parseStorageUri(storageUri, PROTOCOL);
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
const { token, storeId } = await store();
|
|
104
|
+
if (parsed.bucket !== storeId) throw new Error(`Blob store mismatch: expected "${storeId}", but found "${parsed.bucket}".`);
|
|
105
|
+
return {
|
|
106
|
+
...parsed,
|
|
107
|
+
token
|
|
108
|
+
};
|
|
96
109
|
};
|
|
97
110
|
const getListPrefix = (prefix = "") => {
|
|
98
111
|
const value = [normalizedBasePath, prefix.replace(/^\/+|\/+$/g, "")].filter(Boolean).join("/");
|
|
@@ -108,9 +121,10 @@ const vercelBlobStorage = (config) => {
|
|
|
108
121
|
protocol: PROTOCOL,
|
|
109
122
|
async put({ key, body, contentLength, contentType }) {
|
|
110
123
|
const storageKey = getStorageKey(key);
|
|
124
|
+
const { token, storeId } = await store();
|
|
111
125
|
const storageUri = createStorageUri({
|
|
112
126
|
protocol: PROTOCOL,
|
|
113
|
-
bucket: storeId
|
|
127
|
+
bucket: storeId,
|
|
114
128
|
key: storageKey
|
|
115
129
|
});
|
|
116
130
|
await put(toPathname(storageKey), body, {
|
|
@@ -125,7 +139,7 @@ const vercelBlobStorage = (config) => {
|
|
|
125
139
|
return { storageUri };
|
|
126
140
|
},
|
|
127
141
|
async get({ storageUri }) {
|
|
128
|
-
const { key } = parseAndValidate(storageUri);
|
|
142
|
+
const { key, token } = await parseAndValidate(storageUri);
|
|
129
143
|
const result = await get(toPathname(key), {
|
|
130
144
|
access,
|
|
131
145
|
token,
|
|
@@ -139,7 +153,7 @@ const vercelBlobStorage = (config) => {
|
|
|
139
153
|
} }) };
|
|
140
154
|
},
|
|
141
155
|
async getDownloadUrl({ storageUri }) {
|
|
142
|
-
const { key } = parseAndValidate(storageUri);
|
|
156
|
+
const { key } = await parseAndValidate(storageUri);
|
|
143
157
|
const pathname = toPathname(key);
|
|
144
158
|
const validUntil = Date.now() + expiresInMs;
|
|
145
159
|
const { presignedUrl } = await presignUrl(await delegationUntil(validUntil), {
|
|
@@ -151,7 +165,7 @@ const vercelBlobStorage = (config) => {
|
|
|
151
165
|
return { url: presignedUrl };
|
|
152
166
|
},
|
|
153
167
|
async exists({ storageUri }) {
|
|
154
|
-
const { key } = parseAndValidate(storageUri);
|
|
168
|
+
const { key, token } = await parseAndValidate(storageUri);
|
|
155
169
|
try {
|
|
156
170
|
await head(toPathname(key), { token });
|
|
157
171
|
return { exists: true };
|
|
@@ -161,11 +175,12 @@ const vercelBlobStorage = (config) => {
|
|
|
161
175
|
}
|
|
162
176
|
},
|
|
163
177
|
async delete({ storageUri }) {
|
|
164
|
-
const { key } = parseAndValidate(storageUri);
|
|
178
|
+
const { key, token } = await parseAndValidate(storageUri);
|
|
165
179
|
await del(toPathname(key), { token });
|
|
166
180
|
return { deleted: true };
|
|
167
181
|
},
|
|
168
182
|
async listObjects(prefix) {
|
|
183
|
+
const { token, storeId } = await store();
|
|
169
184
|
const objects = [];
|
|
170
185
|
let cursor;
|
|
171
186
|
do {
|
|
@@ -182,7 +197,7 @@ const vercelBlobStorage = (config) => {
|
|
|
182
197
|
try {
|
|
183
198
|
storageUri = createStorageUri({
|
|
184
199
|
protocol: PROTOCOL,
|
|
185
|
-
bucket: storeId
|
|
200
|
+
bucket: storeId,
|
|
186
201
|
key
|
|
187
202
|
});
|
|
188
203
|
} catch {
|
|
@@ -200,6 +215,7 @@ const vercelBlobStorage = (config) => {
|
|
|
200
215
|
return objects;
|
|
201
216
|
},
|
|
202
217
|
async deleteObjects(relativeKeys) {
|
|
218
|
+
const { token } = await store();
|
|
203
219
|
const pathnames = relativeKeys.map((key) => toPathname(getStorageKey(key)));
|
|
204
220
|
for (let offset = 0; offset < pathnames.length; offset += DELETE_BATCH_SIZE) await del(pathnames.slice(offset, offset + DELETE_BATCH_SIZE), { token });
|
|
205
221
|
}
|
package/dist/init/index.cjs
CHANGED
|
@@ -6268,14 +6268,19 @@ createExeca(mapScriptAsync, {}, deepScriptOptions, setScriptSync);
|
|
|
6268
6268
|
const { sendMessage, getOneMessage, getEachMessage, getCancelSignal } = getIpcExport();
|
|
6269
6269
|
//#endregion
|
|
6270
6270
|
//#region iac/configTemplate.ts
|
|
6271
|
+
/**
|
|
6272
|
+
* The config init and the agent scaffold write: the Blob token and the
|
|
6273
|
+
* database URL are read with `secret()`, from the environment and
|
|
6274
|
+
* `.env.hotupdater`, then the config's `secrets` adapter.
|
|
6275
|
+
*/
|
|
6271
6276
|
const getConfigScaffold = (build) => {
|
|
6272
|
-
|
|
6277
|
+
const builder = new _hot_updater_cli_tools.ConfigBuilder().setBuildType(build).setStorage({
|
|
6273
6278
|
imports: [{
|
|
6274
6279
|
pkg: "@hot-updater/vercel",
|
|
6275
6280
|
named: ["vercelBlobStorage"]
|
|
6276
6281
|
}],
|
|
6277
6282
|
configString: `vercelBlobStorage({
|
|
6278
|
-
token:
|
|
6283
|
+
token: secret("HOT_UPDATER_VERCEL_BLOB_READ_WRITE_TOKEN"),
|
|
6279
6284
|
})`
|
|
6280
6285
|
}).setDatabase({
|
|
6281
6286
|
imports: [{
|
|
@@ -6283,7 +6288,7 @@ const getConfigScaffold = (build) => {
|
|
|
6283
6288
|
named: ["postgres"]
|
|
6284
6289
|
}],
|
|
6285
6290
|
configString: `postgres({
|
|
6286
|
-
connectionString:
|
|
6291
|
+
connectionString: secret("HOT_UPDATER_VERCEL_DATABASE_URL"),
|
|
6287
6292
|
})`
|
|
6288
6293
|
}).setPlugins({
|
|
6289
6294
|
imports: [{
|
|
@@ -6295,7 +6300,11 @@ const getConfigScaffold = (build) => {
|
|
|
6295
6300
|
]
|
|
6296
6301
|
}],
|
|
6297
6302
|
configString: "[apiKeys(), insights(), remoteConfig()]"
|
|
6298
|
-
})
|
|
6303
|
+
}).addImport({
|
|
6304
|
+
pkg: "hot-updater",
|
|
6305
|
+
named: ["secret"]
|
|
6306
|
+
});
|
|
6307
|
+
return (0, _hot_updater_cli_tools.createHotUpdaterConfigScaffoldFromBuilder)(builder);
|
|
6299
6308
|
};
|
|
6300
6309
|
//#endregion
|
|
6301
6310
|
//#region iac/init/index.ts
|
|
@@ -6382,7 +6391,8 @@ const initProvider = {
|
|
|
6382
6391
|
persistence: "with-consent",
|
|
6383
6392
|
preflight: false
|
|
6384
6393
|
}
|
|
6385
|
-
}
|
|
6394
|
+
},
|
|
6395
|
+
secrets: ["HOT_UPDATER_VERCEL_BLOB_READ_WRITE_TOKEN", "HOT_UPDATER_VERCEL_DATABASE_URL"]
|
|
6386
6396
|
};
|
|
6387
6397
|
//#endregion
|
|
6388
6398
|
//#region iac/vercelApi.ts
|
|
@@ -7002,10 +7012,10 @@ const selectDatabaseUrl = async ({ api, cwd, project, savedUrl, scope, token })
|
|
|
7002
7012
|
validate: (value) => isPostgresUrl(value) ? void 0 : "Enter a postgres:// or postgresql:// URL."
|
|
7003
7013
|
}));
|
|
7004
7014
|
};
|
|
7005
|
-
const runInit = async ({ build, envFile }) => {
|
|
7015
|
+
const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
7006
7016
|
const cwd = (0, _hot_updater_cli_tools.getCwd)();
|
|
7007
7017
|
const nonInteractive = envFile !== void 0;
|
|
7008
|
-
const initEnvSources = await (0, _hot_updater_cli_tools.readHotUpdaterInitEnv)(cwd, envFile);
|
|
7018
|
+
const initEnvSources = await (0, _hot_updater_cli_tools.readHotUpdaterInitEnv)(cwd, envFile, secretsEnv);
|
|
7009
7019
|
const { managedEnv } = initEnvSources;
|
|
7010
7020
|
const initInputEnv = (0, _hot_updater_cli_tools.getHotUpdaterInitInputEnv)(initEnvSources, nonInteractive);
|
|
7011
7021
|
const saved = Object.fromEntries(Object.entries(inputs).map(([name, input]) => [name, initInputEnv[input.envKey]?.trim() || void 0]));
|
|
@@ -7142,8 +7152,7 @@ const runInit = async ({ build, envFile }) => {
|
|
|
7142
7152
|
...credential === void 0 ? {} : { credential },
|
|
7143
7153
|
clientPlugins: server.clientPlugins
|
|
7144
7154
|
});
|
|
7145
|
-
|
|
7146
|
-
_hot_updater_cli_tools.p.log.success("Done! 🎉");
|
|
7155
|
+
return { nextSteps: [(0, _hot_updater_cli_tools.link)("https://hot-updater.dev/docs/managed/vercel#step-3-add-hotupdater-to-your-project")] };
|
|
7147
7156
|
};
|
|
7148
7157
|
//#endregion
|
|
7149
7158
|
exports.VERCEL_FUNCTION_CONFIG = VERCEL_FUNCTION_CONFIG;
|
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/init/index.d.ts
|
|
3
3
|
declare const initProvider: {
|
|
4
4
|
readonly label: "Vercel Blob + Functions + Postgres";
|
|
@@ -68,6 +68,7 @@ declare const initProvider: {
|
|
|
68
68
|
readonly preflight: false;
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
|
+
readonly secrets: readonly ["HOT_UPDATER_VERCEL_BLOB_READ_WRITE_TOKEN", "HOT_UPDATER_VERCEL_DATABASE_URL"];
|
|
71
72
|
};
|
|
72
73
|
//#endregion
|
|
73
74
|
//#region iac/vercelFunction.d.ts
|
|
@@ -86,6 +87,6 @@ declare const VERCEL_FUNCTION_CONFIG: {
|
|
|
86
87
|
};
|
|
87
88
|
//#endregion
|
|
88
89
|
//#region iac/index.d.ts
|
|
89
|
-
declare const runInit: ({ build, envFile }: RunInitOptions) => Promise<
|
|
90
|
+
declare const runInit: ({ build, envFile, secretsEnv }: RunInitOptions) => Promise<RunInitResult>;
|
|
90
91
|
//#endregion
|
|
91
92
|
export { VERCEL_FUNCTION_CONFIG, initProvider, runInit };
|
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/init/index.d.ts
|
|
3
3
|
declare const initProvider: {
|
|
4
4
|
readonly label: "Vercel Blob + Functions + Postgres";
|
|
@@ -68,6 +68,7 @@ declare const initProvider: {
|
|
|
68
68
|
readonly preflight: false;
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
|
+
readonly secrets: readonly ["HOT_UPDATER_VERCEL_BLOB_READ_WRITE_TOKEN", "HOT_UPDATER_VERCEL_DATABASE_URL"];
|
|
71
72
|
};
|
|
72
73
|
//#endregion
|
|
73
74
|
//#region iac/vercelFunction.d.ts
|
|
@@ -86,6 +87,6 @@ declare const VERCEL_FUNCTION_CONFIG: {
|
|
|
86
87
|
};
|
|
87
88
|
//#endregion
|
|
88
89
|
//#region iac/index.d.ts
|
|
89
|
-
declare const runInit: ({ build, envFile }: RunInitOptions) => Promise<
|
|
90
|
+
declare const runInit: ({ build, envFile, secretsEnv }: RunInitOptions) => Promise<RunInitResult>;
|
|
90
91
|
//#endregion
|
|
91
92
|
export { VERCEL_FUNCTION_CONFIG, initProvider, runInit };
|
package/dist/init/index.mjs
CHANGED
|
@@ -6262,14 +6262,19 @@ createExeca(mapScriptAsync, {}, deepScriptOptions, setScriptSync);
|
|
|
6262
6262
|
const { sendMessage, getOneMessage, getEachMessage, getCancelSignal } = getIpcExport();
|
|
6263
6263
|
//#endregion
|
|
6264
6264
|
//#region iac/configTemplate.ts
|
|
6265
|
+
/**
|
|
6266
|
+
* The config init and the agent scaffold write: the Blob token and the
|
|
6267
|
+
* database URL are read with `secret()`, from the environment and
|
|
6268
|
+
* `.env.hotupdater`, then the config's `secrets` adapter.
|
|
6269
|
+
*/
|
|
6265
6270
|
const getConfigScaffold = (build) => {
|
|
6266
|
-
|
|
6271
|
+
const builder = new ConfigBuilder().setBuildType(build).setStorage({
|
|
6267
6272
|
imports: [{
|
|
6268
6273
|
pkg: "@hot-updater/vercel",
|
|
6269
6274
|
named: ["vercelBlobStorage"]
|
|
6270
6275
|
}],
|
|
6271
6276
|
configString: `vercelBlobStorage({
|
|
6272
|
-
token:
|
|
6277
|
+
token: secret("HOT_UPDATER_VERCEL_BLOB_READ_WRITE_TOKEN"),
|
|
6273
6278
|
})`
|
|
6274
6279
|
}).setDatabase({
|
|
6275
6280
|
imports: [{
|
|
@@ -6277,7 +6282,7 @@ const getConfigScaffold = (build) => {
|
|
|
6277
6282
|
named: ["postgres"]
|
|
6278
6283
|
}],
|
|
6279
6284
|
configString: `postgres({
|
|
6280
|
-
connectionString:
|
|
6285
|
+
connectionString: secret("HOT_UPDATER_VERCEL_DATABASE_URL"),
|
|
6281
6286
|
})`
|
|
6282
6287
|
}).setPlugins({
|
|
6283
6288
|
imports: [{
|
|
@@ -6289,7 +6294,11 @@ const getConfigScaffold = (build) => {
|
|
|
6289
6294
|
]
|
|
6290
6295
|
}],
|
|
6291
6296
|
configString: "[apiKeys(), insights(), remoteConfig()]"
|
|
6292
|
-
})
|
|
6297
|
+
}).addImport({
|
|
6298
|
+
pkg: "hot-updater",
|
|
6299
|
+
named: ["secret"]
|
|
6300
|
+
});
|
|
6301
|
+
return createHotUpdaterConfigScaffoldFromBuilder(builder);
|
|
6293
6302
|
};
|
|
6294
6303
|
//#endregion
|
|
6295
6304
|
//#region iac/init/index.ts
|
|
@@ -6376,7 +6385,8 @@ const initProvider = {
|
|
|
6376
6385
|
persistence: "with-consent",
|
|
6377
6386
|
preflight: false
|
|
6378
6387
|
}
|
|
6379
|
-
}
|
|
6388
|
+
},
|
|
6389
|
+
secrets: ["HOT_UPDATER_VERCEL_BLOB_READ_WRITE_TOKEN", "HOT_UPDATER_VERCEL_DATABASE_URL"]
|
|
6380
6390
|
};
|
|
6381
6391
|
//#endregion
|
|
6382
6392
|
//#region iac/vercelApi.ts
|
|
@@ -6996,10 +7006,10 @@ const selectDatabaseUrl = async ({ api, cwd, project, savedUrl, scope, token })
|
|
|
6996
7006
|
validate: (value) => isPostgresUrl(value) ? void 0 : "Enter a postgres:// or postgresql:// URL."
|
|
6997
7007
|
}));
|
|
6998
7008
|
};
|
|
6999
|
-
const runInit = async ({ build, envFile }) => {
|
|
7009
|
+
const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
7000
7010
|
const cwd = getCwd();
|
|
7001
7011
|
const nonInteractive = envFile !== void 0;
|
|
7002
|
-
const initEnvSources = await readHotUpdaterInitEnv(cwd, envFile);
|
|
7012
|
+
const initEnvSources = await readHotUpdaterInitEnv(cwd, envFile, secretsEnv);
|
|
7003
7013
|
const { managedEnv } = initEnvSources;
|
|
7004
7014
|
const initInputEnv = getHotUpdaterInitInputEnv(initEnvSources, nonInteractive);
|
|
7005
7015
|
const saved = Object.fromEntries(Object.entries(inputs).map(([name, input]) => [name, initInputEnv[input.envKey]?.trim() || void 0]));
|
|
@@ -7136,8 +7146,7 @@ const runInit = async ({ build, envFile }) => {
|
|
|
7136
7146
|
...credential === void 0 ? {} : { credential },
|
|
7137
7147
|
clientPlugins: server.clientPlugins
|
|
7138
7148
|
});
|
|
7139
|
-
|
|
7140
|
-
p.log.success("Done! 🎉");
|
|
7149
|
+
return { nextSteps: [link("https://hot-updater.dev/docs/managed/vercel#step-3-add-hotupdater-to-your-project")] };
|
|
7141
7150
|
};
|
|
7142
7151
|
//#endregion
|
|
7143
7152
|
export { VERCEL_FUNCTION_CONFIG, initProvider, runInit };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/vercel",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.0-rc.
|
|
4
|
+
"version": "1.2.0-rc.20",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
"@vercel/cli-auth": "0.3.10",
|
|
42
42
|
"@vercel/cli-config": "0.3.1",
|
|
43
43
|
"pg": "8.13.1",
|
|
44
|
-
"@hot-updater/
|
|
45
|
-
"@hot-updater/
|
|
46
|
-
"@hot-updater/
|
|
47
|
-
"@hot-updater/
|
|
48
|
-
"@hot-updater/
|
|
44
|
+
"@hot-updater/plugin-core": "1.2.0-rc.20",
|
|
45
|
+
"@hot-updater/cli-tools": "1.2.0-rc.20",
|
|
46
|
+
"@hot-updater/postgres": "1.2.0-rc.20",
|
|
47
|
+
"@hot-updater/protocol": "1.2.0-rc.20",
|
|
48
|
+
"@hot-updater/server": "1.2.0-rc.20"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^20",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"execa": "9.5.2",
|
|
55
55
|
"kysely": "0.28.17",
|
|
56
56
|
"vitest": "4.1.4",
|
|
57
|
-
"@hot-updater/test-utils": "1.2.0-rc.
|
|
57
|
+
"@hot-updater/test-utils": "1.2.0-rc.20"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "tsdown",
|