@hot-updater/firebase 1.2.0-rc.51 → 1.2.0-rc.52
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/firebase/functions/index.cjs +130 -21
- package/dist/index.cjs +17 -5
- package/dist/index.mjs +17 -5
- package/package.json +7 -7
|
@@ -4,6 +4,8 @@ let firebase_functions_v2_https = require("firebase-functions/v2/https");
|
|
|
4
4
|
let hono = require("hono");
|
|
5
5
|
let firebase_admin_firestore = require("firebase-admin/firestore");
|
|
6
6
|
let node_crypto = require("node:crypto");
|
|
7
|
+
let node_stream = require("node:stream");
|
|
8
|
+
let node_stream_promises = require("node:stream/promises");
|
|
7
9
|
let firebase_admin_storage = require("firebase-admin/storage");
|
|
8
10
|
//#region ../plugin-core/dist/contentAddressedAssets.mjs
|
|
9
11
|
const SHA256_FILE_HASH_RE = /^[0-9a-f]{64}$/;
|
|
@@ -1331,6 +1333,76 @@ function canonicalStringify(value) {
|
|
|
1331
1333
|
const record = value;
|
|
1332
1334
|
return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${canonicalStringify(record[key])}`).join(",")}}`;
|
|
1333
1335
|
}
|
|
1336
|
+
const BOUND_SHAPE = {
|
|
1337
|
+
inclusive: null,
|
|
1338
|
+
version: null
|
|
1339
|
+
};
|
|
1340
|
+
/**
|
|
1341
|
+
* Every key this release's compiler writes in a catalog payload, where it
|
|
1342
|
+
* writes it: the envelope's, a segment's and its bounds', and a release
|
|
1343
|
+
* descriptor's. A key outside it was written by a later release.
|
|
1344
|
+
*/
|
|
1345
|
+
const COMPILED_CATALOG_SHAPE = {
|
|
1346
|
+
fallbackPolicy: null,
|
|
1347
|
+
schemaVersion: null,
|
|
1348
|
+
strategy: null,
|
|
1349
|
+
releaseIndexes: null,
|
|
1350
|
+
rollbackReleaseIndexes: null,
|
|
1351
|
+
segments: {
|
|
1352
|
+
lower: BOUND_SHAPE,
|
|
1353
|
+
upper: BOUND_SHAPE,
|
|
1354
|
+
releaseIndexes: null,
|
|
1355
|
+
rollbackReleaseIndexes: null
|
|
1356
|
+
},
|
|
1357
|
+
releaseDescriptors: {
|
|
1358
|
+
releaseId: null,
|
|
1359
|
+
kind: null,
|
|
1360
|
+
bundleId: null,
|
|
1361
|
+
rolloutCohortCount: null,
|
|
1362
|
+
targetCohorts: null,
|
|
1363
|
+
shouldForceUpdate: null,
|
|
1364
|
+
message: null,
|
|
1365
|
+
label: null
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
/**
|
|
1369
|
+
* A stored catalog payload as this release reads it: canonical, with the
|
|
1370
|
+
* keys a later release added left out, and whether it had any, a later
|
|
1371
|
+
* schema version included. Server core compares a catalog by the fields
|
|
1372
|
+
* its compiler writes, and refuses to rewrite one a later release wrote,
|
|
1373
|
+
* which would drop what that release added.
|
|
1374
|
+
*/
|
|
1375
|
+
function readCompiledCatalogPayload(payload) {
|
|
1376
|
+
let fromLaterRelease = false;
|
|
1377
|
+
const known = (value, shape) => {
|
|
1378
|
+
if (Array.isArray(value)) return value.map((item) => known(item, shape));
|
|
1379
|
+
if (value === null || typeof value !== "object") return value;
|
|
1380
|
+
const entries = Object.entries(value).filter(([key]) => {
|
|
1381
|
+
if (Object.hasOwn(shape, key)) return true;
|
|
1382
|
+
fromLaterRelease = true;
|
|
1383
|
+
return false;
|
|
1384
|
+
});
|
|
1385
|
+
return Object.fromEntries(entries.map(([key, entry]) => {
|
|
1386
|
+
const inner = shape[key];
|
|
1387
|
+
return [key, inner === null ? entry : known(entry, inner)];
|
|
1388
|
+
}));
|
|
1389
|
+
};
|
|
1390
|
+
let parsed;
|
|
1391
|
+
try {
|
|
1392
|
+
parsed = JSON.parse(payload);
|
|
1393
|
+
} catch {
|
|
1394
|
+
parsed = null;
|
|
1395
|
+
}
|
|
1396
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return {
|
|
1397
|
+
canonicalPayload: payload,
|
|
1398
|
+
fromLaterRelease: false
|
|
1399
|
+
};
|
|
1400
|
+
if ("schemaVersion" in parsed && typeof parsed.schemaVersion === "number" && parsed.schemaVersion > 1) fromLaterRelease = true;
|
|
1401
|
+
return {
|
|
1402
|
+
canonicalPayload: canonicalStringify(known(parsed, COMPILED_CATALOG_SHAPE)),
|
|
1403
|
+
fromLaterRelease
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1334
1406
|
async function compileReleaseCatalog(input) {
|
|
1335
1407
|
const releases = validateReleases(input.releases, input.strategy);
|
|
1336
1408
|
const targetCohorts = new Set(releases.flatMap((release) => release.targetCohorts));
|
|
@@ -1914,6 +1986,23 @@ const SETTINGS_TABLE = {
|
|
|
1914
1986
|
/** The engine's storage-layout generation; it changes only with a migration. */
|
|
1915
1987
|
const ENGINE_SCHEMA_KEY = "schema.engine";
|
|
1916
1988
|
const CORE_SCHEMA_KEY = "schema.core";
|
|
1989
|
+
/** Compares dotted numeric versions, such as "1" and "1.2.0"; NaN when either is not one. */
|
|
1990
|
+
const compareVersions = (left, right) => {
|
|
1991
|
+
const parse = (version) => /^\d+(?:\.\d+)*$/u.test(version) ? version.split(".").map(Number) : [NaN];
|
|
1992
|
+
const [a, b] = [parse(left), parse(right)];
|
|
1993
|
+
if ([...a, ...b].some(Number.isNaN)) return NaN;
|
|
1994
|
+
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
1995
|
+
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
1996
|
+
if (difference !== 0) return difference;
|
|
1997
|
+
}
|
|
1998
|
+
return 0;
|
|
1999
|
+
};
|
|
2000
|
+
/**
|
|
2001
|
+
* The `schema.core` a newer release recorded, which `hot-updater db migrate`
|
|
2002
|
+
* never moves back: the fix is to upgrade, not to migrate.
|
|
2003
|
+
*/
|
|
2004
|
+
const newerCore = (settings) => settings.find(({ key, expected, found }) => key === CORE_SCHEMA_KEY && found !== null && compareVersions(found, expected) > 0);
|
|
2005
|
+
const newerMessage = (adapterName, { key, expected, found }) => `Hot Updater schema setting "${key}" for ${adapterName} is "${found}"; expected "${expected}". The database was migrated by Hot Updater ${found}: upgrade hot-updater and the @hot-updater packages to ${found} or later.`;
|
|
1917
2006
|
const stored = ({ key, expected, found }) => `"${key}" is ${found === null ? "missing" : `"${found}"`}; expected "${expected}"`;
|
|
1918
2007
|
/**
|
|
1919
2008
|
* How to migrate a database the fence refused: doctor names the command for
|
|
@@ -1927,7 +2016,10 @@ const pluginOf = ({ key }) => key.startsWith("schema.") && key !== "schema.engin
|
|
|
1927
2016
|
const listed = (items) => items.length < 2 ? items.join("") : `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
|
|
1928
2017
|
const settingsMessage = (adapterName, settings) => `Hot Updater schema settings for ${adapterName} are not migrated: ${settings.map(stored).join(", and ")}. ${MIGRATE_SCHEMA_FIX}`;
|
|
1929
2018
|
const pluginsMessage = (adapterName, plugins, settings, fix) => `The tables of ${plugins.length === 1 ? "plugin" : "plugins"} ${listed(plugins.map((id) => `"${id}"`))} are not migrated on ${adapterName}: schema ${settings.length === 1 ? "setting" : "settings"} ${settings.map(stored).join(", and ")}. ${fix}`;
|
|
1930
|
-
/**
|
|
2019
|
+
/**
|
|
2020
|
+
* The database needs `hot-updater db migrate`, a new database, or a newer
|
|
2021
|
+
* Hot Updater; the handler answers 503.
|
|
2022
|
+
*/
|
|
1931
2023
|
var HotUpdaterSchemaMigrationRequiredError = class extends Error {
|
|
1932
2024
|
adapterName;
|
|
1933
2025
|
currentVersion;
|
|
@@ -1942,7 +2034,8 @@ var HotUpdaterSchemaMigrationRequiredError = class extends Error {
|
|
|
1942
2034
|
constructor(adapterName, currentVersion, setting, options) {
|
|
1943
2035
|
const settings = options?.settings ?? (setting === void 0 ? [] : [setting]);
|
|
1944
2036
|
const plugins = settings.flatMap((mismatch) => pluginOf(mismatch) ?? []);
|
|
1945
|
-
|
|
2037
|
+
const newer = newerCore(settings);
|
|
2038
|
+
super(newer !== void 0 ? newerMessage(adapterName, newer) : setting === void 0 ? currentVersion === void 0 ? `Hot Updater database schema is not initialized for ${adapterName}. ${MIGRATE_SCHEMA_FIX}` : `Hot Updater v1 cannot migrate schema ${currentVersion} in place. Create a new empty database and run \`hot-updater db migrate\`.` : plugins.length > 0 && plugins.length === settings.length ? pluginsMessage(adapterName, plugins, settings, options?.fix ?? MIGRATE_SCHEMA_FIX) : settings.length > 1 && !(setting.key === "schema.engine" && setting.found === null) ? settingsMessage(adapterName, settings) : settingMessage(adapterName, setting), options?.cause === void 0 ? void 0 : { cause: options.cause });
|
|
1946
2039
|
this.adapterName = adapterName;
|
|
1947
2040
|
this.currentVersion = currentVersion;
|
|
1948
2041
|
this.setting = setting;
|
|
@@ -2729,17 +2822,6 @@ const refuseV0Database = (adapterName, stored) => {
|
|
|
2729
2822
|
if (typeof version !== "string" || stored.has("schema.engine")) return;
|
|
2730
2823
|
throw new HotUpdaterSchemaMigrationRequiredError(adapterName, version);
|
|
2731
2824
|
};
|
|
2732
|
-
/** Compares dotted numeric versions, such as "1" and "1.2.0"; NaN when either is not one. */
|
|
2733
|
-
const compareVersions = (left, right) => {
|
|
2734
|
-
const parse = (version) => /^\d+(?:\.\d+)*$/u.test(version) ? version.split(".").map(Number) : [NaN];
|
|
2735
|
-
const [a, b] = [parse(left), parse(right)];
|
|
2736
|
-
if ([...a, ...b].some(Number.isNaN)) return NaN;
|
|
2737
|
-
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
2738
|
-
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
2739
|
-
if (difference !== 0) return difference;
|
|
2740
|
-
}
|
|
2741
|
-
return 0;
|
|
2742
|
-
};
|
|
2743
2825
|
/**
|
|
2744
2826
|
* The settings whose versions only move forward when a `ToolingTarget` names
|
|
2745
2827
|
* none. `schema.engine` is a storage layout, not a release: a store refuses
|
|
@@ -5117,7 +5199,7 @@ const createKvAdapter = ({ store, tablePrefix = "" }) => {
|
|
|
5117
5199
|
};
|
|
5118
5200
|
//#endregion
|
|
5119
5201
|
//#region ../../packages/server/dist/version.mjs
|
|
5120
|
-
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.
|
|
5202
|
+
const HOT_UPDATER_SERVER_VERSION = "1.2.0-rc.52";
|
|
5121
5203
|
//#endregion
|
|
5122
5204
|
//#region ../../packages/server/dist/handlerVersionRoutes.mjs
|
|
5123
5205
|
/**
|
|
@@ -7584,6 +7666,13 @@ const readCatalog = async (tx, scopeKey) => {
|
|
|
7584
7666
|
catalog: row === null ? null : toCatalogRow(row)
|
|
7585
7667
|
};
|
|
7586
7668
|
};
|
|
7669
|
+
/**
|
|
7670
|
+
* Refuses to rewrite a catalog a later release compiled: this release's
|
|
7671
|
+
* compiler would drop the fields that release added.
|
|
7672
|
+
*/
|
|
7673
|
+
const refuseLaterCatalog = (scope, catalog) => {
|
|
7674
|
+
if (catalog !== null && readCompiledCatalogPayload(catalog.payload).fromLaterRelease) fail$1("CATALOG_FROM_LATER_RELEASE", `The ${scope.platform} release catalog of channel "${scope.channelName}" was written by a later Hot Updater.\nUpgrade hot-updater, then try again.`);
|
|
7675
|
+
};
|
|
7587
7676
|
/** A scope with releases and no compiled catalog lost its history. */
|
|
7588
7677
|
const assertHistory = (stored, hasReleases) => {
|
|
7589
7678
|
if (stored.catalog === null && hasReleases) fail$1("CATALOG_IDENTITY_MISSING", "Catalog history is missing. Restore its catalog row from backup before rebuilding or deploying.");
|
|
@@ -7597,6 +7686,7 @@ const assertHistory = (stored, hasReleases) => {
|
|
|
7597
7686
|
const changeRelease = async (tx, { scope, change, bundle, updatedAtMs }, labels) => {
|
|
7598
7687
|
checkScope(scope);
|
|
7599
7688
|
const stored = await readCatalog(tx, scope.scopeKey);
|
|
7689
|
+
refuseLaterCatalog(scope, stored.catalog);
|
|
7600
7690
|
let enabled = await enabledReleases(tx, scope.scopeKey);
|
|
7601
7691
|
if (bundle !== void 0) {
|
|
7602
7692
|
insertBundle(tx, bundle.row);
|
|
@@ -7669,8 +7759,16 @@ const changeReleases = (db, inputs) => {
|
|
|
7669
7759
|
return results;
|
|
7670
7760
|
});
|
|
7671
7761
|
};
|
|
7672
|
-
/**
|
|
7673
|
-
|
|
7762
|
+
/**
|
|
7763
|
+
* Whether `current` is what the scope's enabled releases compile to, in the
|
|
7764
|
+
* fields this release compiles: a later release's catalog may add others.
|
|
7765
|
+
*/
|
|
7766
|
+
const isCurrent = (scope, current, compilation) => {
|
|
7767
|
+
if (current.strategy !== scope.strategy || current.channel_id !== scope.channelId || current.channel_key !== encodeChannelKey(scope.channelName) || current.platform !== scope.platform || current.fingerprint_hash !== scope.fingerprintHash) return false;
|
|
7768
|
+
if (current.catalog_hash === compilation.catalogHash) return true;
|
|
7769
|
+
const read = readCompiledCatalogPayload(current.payload);
|
|
7770
|
+
return read.fromLaterRelease && read.canonicalPayload === compilation.canonicalPayload;
|
|
7771
|
+
};
|
|
7674
7772
|
/** A compiled payload with its descriptors' labels left out. */
|
|
7675
7773
|
const withoutLabels = (payload) => {
|
|
7676
7774
|
const parsed = JSON.parse(payload);
|
|
@@ -7732,6 +7830,7 @@ const rebuildScope = async (tx, scope, updatedAtMs) => {
|
|
|
7732
7830
|
changed: false,
|
|
7733
7831
|
diagnostics: compilation.diagnostics
|
|
7734
7832
|
};
|
|
7833
|
+
refuseLaterCatalog(scope, current);
|
|
7735
7834
|
const written = await writeCatalog(tx, scope, stored, enabled, updatedAtMs);
|
|
7736
7835
|
return {
|
|
7737
7836
|
catalog: written.catalog,
|
|
@@ -14089,11 +14188,21 @@ const firebaseStorage = (config) => {
|
|
|
14089
14188
|
protocol: "gs",
|
|
14090
14189
|
async put({ key, body, contentType }) {
|
|
14091
14190
|
const storageKey = getStorageKey(key);
|
|
14092
|
-
|
|
14093
|
-
|
|
14094
|
-
|
|
14095
|
-
|
|
14096
|
-
|
|
14191
|
+
try {
|
|
14192
|
+
await (0, node_stream_promises.pipeline)(node_stream.Readable.fromWeb(body), bucket().file(storageKey).createWriteStream({
|
|
14193
|
+
resumable: false,
|
|
14194
|
+
metadata: {
|
|
14195
|
+
contentType,
|
|
14196
|
+
cacheControl: "public, max-age=31536000, immutable"
|
|
14197
|
+
}
|
|
14198
|
+
}));
|
|
14199
|
+
} catch (error) {
|
|
14200
|
+
const status = Reflect.get(Object(error), "code");
|
|
14201
|
+
if (typeof status !== "number") throw error;
|
|
14202
|
+
const message = error.message;
|
|
14203
|
+
const detail = /<html|<!doctype/i.test(message) ? "" : `: ${message}`;
|
|
14204
|
+
throw new Error(`Firebase Storage answered HTTP ${status} while uploading ${storageKey}${detail}`, { cause: error });
|
|
14205
|
+
}
|
|
14097
14206
|
return { storageUri: createStorageUri({
|
|
14098
14207
|
bucket: config.storageBucket,
|
|
14099
14208
|
key: storageKey,
|
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,8 @@ let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
|
3
3
|
let firebase_admin_app = require("firebase-admin/app");
|
|
4
4
|
let firebase_admin_firestore = require("firebase-admin/firestore");
|
|
5
5
|
let node_crypto = require("node:crypto");
|
|
6
|
+
let node_stream = require("node:stream");
|
|
7
|
+
let node_stream_promises = require("node:stream/promises");
|
|
6
8
|
let firebase_admin_storage = require("firebase-admin/storage");
|
|
7
9
|
//#region src/firebaseInfrastructureNames.ts
|
|
8
10
|
/**
|
|
@@ -305,11 +307,21 @@ const firebaseStorage = (config) => {
|
|
|
305
307
|
protocol: "gs",
|
|
306
308
|
async put({ key, body, contentType }) {
|
|
307
309
|
const storageKey = getStorageKey(key);
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
310
|
+
try {
|
|
311
|
+
await (0, node_stream_promises.pipeline)(node_stream.Readable.fromWeb(body), bucket().file(storageKey).createWriteStream({
|
|
312
|
+
resumable: false,
|
|
313
|
+
metadata: {
|
|
314
|
+
contentType,
|
|
315
|
+
cacheControl: "public, max-age=31536000, immutable"
|
|
316
|
+
}
|
|
317
|
+
}));
|
|
318
|
+
} catch (error) {
|
|
319
|
+
const status = Reflect.get(Object(error), "code");
|
|
320
|
+
if (typeof status !== "number") throw error;
|
|
321
|
+
const message = error.message;
|
|
322
|
+
const detail = /<html|<!doctype/i.test(message) ? "" : `: ${message}`;
|
|
323
|
+
throw new Error(`Firebase Storage answered HTTP ${status} while uploading ${storageKey}${detail}`, { cause: error });
|
|
324
|
+
}
|
|
313
325
|
return { storageUri: (0, _hot_updater_plugin_core.createStorageUri)({
|
|
314
326
|
bucket: config.storageBucket,
|
|
315
327
|
key: storageKey,
|
package/dist/index.mjs
CHANGED
|
@@ -2,6 +2,8 @@ import { createEngineDatabase, createKvAdapter, createStorageAdapter, createStor
|
|
|
2
2
|
import { getApp, getApps, initializeApp } from "firebase-admin/app";
|
|
3
3
|
import { FieldPath, FieldValue, Timestamp, getFirestore } from "firebase-admin/firestore";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
|
+
import { Readable } from "node:stream";
|
|
6
|
+
import { pipeline } from "node:stream/promises";
|
|
5
7
|
import { getStorage } from "firebase-admin/storage";
|
|
6
8
|
//#region src/firebaseInfrastructureNames.ts
|
|
7
9
|
/**
|
|
@@ -304,11 +306,21 @@ const firebaseStorage = (config) => {
|
|
|
304
306
|
protocol: "gs",
|
|
305
307
|
async put({ key, body, contentType }) {
|
|
306
308
|
const storageKey = getStorageKey(key);
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
309
|
+
try {
|
|
310
|
+
await pipeline(Readable.fromWeb(body), bucket().file(storageKey).createWriteStream({
|
|
311
|
+
resumable: false,
|
|
312
|
+
metadata: {
|
|
313
|
+
contentType,
|
|
314
|
+
cacheControl: "public, max-age=31536000, immutable"
|
|
315
|
+
}
|
|
316
|
+
}));
|
|
317
|
+
} catch (error) {
|
|
318
|
+
const status = Reflect.get(Object(error), "code");
|
|
319
|
+
if (typeof status !== "number") throw error;
|
|
320
|
+
const message = error.message;
|
|
321
|
+
const detail = /<html|<!doctype/i.test(message) ? "" : `: ${message}`;
|
|
322
|
+
throw new Error(`Firebase Storage answered HTTP ${status} while uploading ${storageKey}${detail}`, { cause: error });
|
|
323
|
+
}
|
|
312
324
|
return { storageUri: createStorageUri({
|
|
313
325
|
bucket: config.storageBucket,
|
|
314
326
|
key: storageKey,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/firebase",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.0-rc.
|
|
4
|
+
"version": "1.2.0-rc.52",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"types": "dist/index.d.cts",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"hono": "4.12.34",
|
|
40
40
|
"google-auth-library": "10.7.0",
|
|
41
|
-
"@hot-updater/cli-tools": "1.2.0-rc.
|
|
42
|
-
"@hot-updater/
|
|
43
|
-
"@hot-updater/
|
|
44
|
-
"@hot-updater/
|
|
41
|
+
"@hot-updater/cli-tools": "1.2.0-rc.52",
|
|
42
|
+
"@hot-updater/plugin-core": "1.2.0-rc.52",
|
|
43
|
+
"@hot-updater/server": "1.2.0-rc.52",
|
|
44
|
+
"@hot-updater/protocol": "1.2.0-rc.52"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"firebase-tools": "15.29.0",
|
|
57
57
|
"fkill": "^9.0.0",
|
|
58
58
|
"mime": "^4.0.4",
|
|
59
|
-
"@hot-updater/
|
|
60
|
-
"@hot-updater/
|
|
59
|
+
"@hot-updater/test-utils": "1.2.0-rc.52",
|
|
60
|
+
"@hot-updater/mock": "1.2.0-rc.52"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"firebase-admin": ">=11.10.0",
|