@hot-updater/azure 1.2.0-rc.2 → 1.2.0-rc.21
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/functions/index.mjs +171 -140
- package/dist/index.cjs +260 -31
- package/dist/index.d.cts +65 -7
- package/dist/index.d.mts +65 -7
- package/dist/index.mjs +259 -31
- package/dist/init/index.cjs +46 -26
- package/dist/init/index.d.cts +3 -2
- package/dist/init/index.d.mts +3 -2
- package/dist/init/index.mjs +46 -26
- package/package.json +8 -6
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
|
import "@azure/storage-blob";
|
|
3
3
|
//#region iac/azureResources.d.ts
|
|
4
4
|
/** The `package.json` of the zip package: it points the Functions host at the bundled `index.mjs`. */
|
|
@@ -81,6 +81,7 @@ declare const initProvider: {
|
|
|
81
81
|
readonly preflight: false;
|
|
82
82
|
};
|
|
83
83
|
};
|
|
84
|
+
readonly secrets: readonly ["HOT_UPDATER_AZURE_STORAGE_CONNECTION_STRING", "HOT_UPDATER_AZURE_COSMOS_CONNECTION_STRING"];
|
|
84
85
|
};
|
|
85
86
|
//#endregion
|
|
86
87
|
//#region iac/index.d.ts
|
|
@@ -94,6 +95,6 @@ declare const defaultResourceNames: (subscriptionId: string, resourceGroup: stri
|
|
|
94
95
|
cosmosAccount: string;
|
|
95
96
|
functionApp: string;
|
|
96
97
|
};
|
|
97
|
-
declare const runInit: ({ build, envFile }: RunInitOptions) => Promise<
|
|
98
|
+
declare const runInit: ({ build, envFile, secretsEnv }: RunInitOptions) => Promise<RunInitResult>;
|
|
98
99
|
//#endregion
|
|
99
100
|
export { AZURE_FUNCTION_PACKAGE, defaultResourceNames, 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
|
import "@azure/storage-blob";
|
|
3
3
|
//#region iac/azureResources.d.ts
|
|
4
4
|
/** The `package.json` of the zip package: it points the Functions host at the bundled `index.mjs`. */
|
|
@@ -81,6 +81,7 @@ declare const initProvider: {
|
|
|
81
81
|
readonly preflight: false;
|
|
82
82
|
};
|
|
83
83
|
};
|
|
84
|
+
readonly secrets: readonly ["HOT_UPDATER_AZURE_STORAGE_CONNECTION_STRING", "HOT_UPDATER_AZURE_COSMOS_CONNECTION_STRING"];
|
|
84
85
|
};
|
|
85
86
|
//#endregion
|
|
86
87
|
//#region iac/index.d.ts
|
|
@@ -94,6 +95,6 @@ declare const defaultResourceNames: (subscriptionId: string, resourceGroup: stri
|
|
|
94
95
|
cosmosAccount: string;
|
|
95
96
|
functionApp: string;
|
|
96
97
|
};
|
|
97
|
-
declare const runInit: ({ build, envFile }: RunInitOptions) => Promise<
|
|
98
|
+
declare const runInit: ({ build, envFile, secretsEnv }: RunInitOptions) => Promise<RunInitResult>;
|
|
98
99
|
//#endregion
|
|
99
100
|
export { AZURE_FUNCTION_PACKAGE, defaultResourceNames, initProvider, runInit };
|
package/dist/init/index.mjs
CHANGED
|
@@ -262,14 +262,17 @@ const emulatorAborted = (error) => statusOf(error) === 500 && /PostgresError\(Sq
|
|
|
262
262
|
*/
|
|
263
263
|
const createCosmosStore = ({ client, databaseId, containerId, engine, nativePageSize }) => {
|
|
264
264
|
let opened;
|
|
265
|
-
const open = () => opened ??= (() => {
|
|
266
|
-
const account = typeof client === "function" ? client() : client;
|
|
265
|
+
const open = () => opened ??= (async () => {
|
|
266
|
+
const account = typeof client === "function" ? await client() : client;
|
|
267
267
|
return {
|
|
268
268
|
client: account,
|
|
269
269
|
container: account.database(databaseId).container(containerId)
|
|
270
270
|
};
|
|
271
|
-
})()
|
|
272
|
-
|
|
271
|
+
})().catch((error) => {
|
|
272
|
+
opened = void 0;
|
|
273
|
+
throw error;
|
|
274
|
+
});
|
|
275
|
+
const container = async () => (await open()).container;
|
|
273
276
|
/**
|
|
274
277
|
* The state of the items `ids` names, by id, with the rows of `rowIds`;
|
|
275
278
|
* a missing item has none.
|
|
@@ -277,7 +280,7 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
277
280
|
const readStates = async (ids, rowIds) => {
|
|
278
281
|
const states = /* @__PURE__ */ new Map();
|
|
279
282
|
for (const [group, projection] of [[ids.filter((id) => !rowIds.has(id)), ""], [ids.filter((id) => rowIds.has(id)), ", c.row"]]) for (let at = 0; at < group.length; at += GET_BATCH) {
|
|
280
|
-
const { resources } = await container().items.query(`SELECT c.id, c._etag AS etag, c.row._v AS v, c.expireAt${projection} FROM c WHERE c.id IN (${idList(group.slice(at, at + GET_BATCH))})`, { partitionKey: COSMOS_PARTITION }).fetchAll().catch(missingContainer);
|
|
283
|
+
const { resources } = await (await container()).items.query(`SELECT c.id, c._etag AS etag, c.row._v AS v, c.expireAt${projection} FROM c WHERE c.id IN (${idList(group.slice(at, at + GET_BATCH))})`, { partitionKey: COSMOS_PARTITION }).fetchAll().catch(missingContainer);
|
|
281
284
|
for (const { id, etag, v, expireAt, row } of resources) states.set(id, {
|
|
282
285
|
etag,
|
|
283
286
|
v,
|
|
@@ -415,7 +418,7 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
415
418
|
const found = /* @__PURE__ */ new Map();
|
|
416
419
|
const ids = [...new Set(keys.map(cosmosItemId))];
|
|
417
420
|
for (let at = 0; at < ids.length; at += GET_BATCH) {
|
|
418
|
-
const { resources } = await container().items.query(`SELECT c.id, c.row FROM c WHERE c.id IN (${idList(ids.slice(at, at + GET_BATCH))})`, { partitionKey: COSMOS_PARTITION }).fetchAll().catch(missingContainer);
|
|
421
|
+
const { resources } = await (await container()).items.query(`SELECT c.id, c.row FROM c WHERE c.id IN (${idList(ids.slice(at, at + GET_BATCH))})`, { partitionKey: COSMOS_PARTITION }).fetchAll().catch(missingContainer);
|
|
419
422
|
for (const resource of resources) found.set(resource.id, toRow(resource.row));
|
|
420
423
|
}
|
|
421
424
|
return keys.map((key) => found.get(cosmosItemId(key)) ?? null);
|
|
@@ -451,7 +454,7 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
451
454
|
value: after
|
|
452
455
|
});
|
|
453
456
|
}
|
|
454
|
-
const { resources } = await container().items.query({
|
|
457
|
+
const { resources } = await (await container()).items.query({
|
|
455
458
|
query: `SELECT TOP @size c.sk, c.row FROM c WHERE ${filters.join(" AND ")} ORDER BY c.pk ${order === "asc" ? "ASC" : "DESC"}, c.sk ${order === "asc" ? "ASC" : "DESC"}`,
|
|
456
459
|
parameters
|
|
457
460
|
}, {
|
|
@@ -501,7 +504,7 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
501
504
|
if (planned.length > BATCH_OPERATIONS) throw new Error(`A Cosmos DB batch takes ${BATCH_OPERATIONS} operations; this write needs ${planned.length}.`);
|
|
502
505
|
let results;
|
|
503
506
|
try {
|
|
504
|
-
const response = await container().items.batch(planned.map(({ operation }) => operation), COSMOS_PARTITION);
|
|
507
|
+
const response = await (await container()).items.batch(planned.map(({ operation }) => operation), COSMOS_PARTITION);
|
|
505
508
|
if (response.result === void 0) throw Object.assign(/* @__PURE__ */ new Error(`Cosmos DB refused the batch with status ${response.code}`), { code: response.code });
|
|
506
509
|
results = response.result;
|
|
507
510
|
} catch (error) {
|
|
@@ -535,7 +538,7 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
535
538
|
async deleteConsumed(keys) {
|
|
536
539
|
let remaining = [...new Set(keys.map(cosmosItemId))];
|
|
537
540
|
for (let attempt = 0; remaining.length > 0; attempt += 1) {
|
|
538
|
-
const failed = (await container().items.executeBulkOperations(remaining.map((id) => ({
|
|
541
|
+
const failed = (await (await container()).items.executeBulkOperations(remaining.map((id) => ({
|
|
539
542
|
operationType: "Delete",
|
|
540
543
|
id,
|
|
541
544
|
partitionKey: COSMOS_PARTITION
|
|
@@ -556,8 +559,8 @@ const createCosmosStore = ({ client, databaseId, containerId, engine, nativePage
|
|
|
556
559
|
migrations: {
|
|
557
560
|
/** Creates the database and the container when they are missing. */
|
|
558
561
|
async apply() {
|
|
559
|
-
if (engine !== void 0) await assertCosmosContainerReusable(container(), engine);
|
|
560
|
-
const { database } = await open().client.databases.createIfNotExists({ id: databaseId });
|
|
562
|
+
if (engine !== void 0) await assertCosmosContainerReusable(await container(), engine);
|
|
563
|
+
const { database } = await (await open()).client.databases.createIfNotExists({ id: databaseId });
|
|
561
564
|
const { resource } = await database.containers.createIfNotExists({
|
|
562
565
|
id: containerId,
|
|
563
566
|
partitionKey: { paths: [COSMOS_PARTITION_KEY_PATH] },
|
|
@@ -594,8 +597,12 @@ const adapterOf = (config) => {
|
|
|
594
597
|
const { databaseId = AZURE_COSMOS_V1_DATABASE, containerId = AZURE_COSMOS_V1_CONTAINER, aggregateBatching: _, ...connection } = config;
|
|
595
598
|
if (connection.consistencyLevel !== void 0 && connection.consistencyLevel !== "Strong") throw new Error(`cosmosDatabase reads with strong consistency; consistencyLevel "${String(connection.consistencyLevel)}" is weaker.`);
|
|
596
599
|
let client;
|
|
600
|
+
const { connectionString } = connection;
|
|
597
601
|
const store = createCosmosStore({
|
|
598
|
-
client: () => client ??= new CosmosClient(
|
|
602
|
+
client: async () => client ??= new CosmosClient({
|
|
603
|
+
...connection,
|
|
604
|
+
connectionString: typeof connectionString === "function" ? await connectionString() : connectionString
|
|
605
|
+
}),
|
|
599
606
|
databaseId,
|
|
600
607
|
containerId,
|
|
601
608
|
engine: currentCosmosEngine()
|
|
@@ -624,7 +631,7 @@ const migrateCosmosDatabase = (config, plugins = []) => {
|
|
|
624
631
|
const DATABASE_TARGET = Symbol.for("@hot-updater/database-target");
|
|
625
632
|
/** The account host a client reaches: its endpoint, or the connection string's. */
|
|
626
633
|
const accountHostOf = ({ endpoint, connectionString }) => {
|
|
627
|
-
const url = endpoint ?? connectionString
|
|
634
|
+
const url = endpoint ?? (typeof connectionString === "string" ? connectionString.match(/AccountEndpoint=([^;]+)/iu)?.[1] : void 0);
|
|
628
635
|
try {
|
|
629
636
|
return url === void 0 ? void 0 : new URL(url).hostname;
|
|
630
637
|
} catch {
|
|
@@ -7446,26 +7453,34 @@ const verifyFunction = async (baseURL, { attempts = 60, delayMs = 5e3 } = {}) =>
|
|
|
7446
7453
|
* import without its extension, so it names the container itself.
|
|
7447
7454
|
*/
|
|
7448
7455
|
const BLOB_CONTAINER = "hot-updater";
|
|
7449
|
-
|
|
7456
|
+
/**
|
|
7457
|
+
* The config init writes. With the `resources` init set up, it names the
|
|
7458
|
+
* Cosmos DB account. Either way it reads both connection strings with
|
|
7459
|
+
* `secret()`, from the environment and `.env.hotupdater`, then the config's
|
|
7460
|
+
* `secrets` adapter.
|
|
7461
|
+
*/
|
|
7462
|
+
const getConfigScaffold = (build, resources) => {
|
|
7450
7463
|
const storageConfig = {
|
|
7451
7464
|
imports: [{
|
|
7452
7465
|
pkg: "@hot-updater/azure",
|
|
7453
7466
|
named: ["azureBlobStorage"]
|
|
7454
7467
|
}],
|
|
7455
7468
|
configString: `azureBlobStorage({
|
|
7456
|
-
connectionString:
|
|
7469
|
+
connectionString: secret("HOT_UPDATER_AZURE_STORAGE_CONNECTION_STRING"),
|
|
7457
7470
|
containerName: "${BLOB_CONTAINER}",
|
|
7458
7471
|
})`
|
|
7459
7472
|
};
|
|
7460
|
-
|
|
7473
|
+
const databaseConfig = {
|
|
7461
7474
|
imports: [{
|
|
7462
7475
|
pkg: "@hot-updater/azure",
|
|
7463
7476
|
named: ["cosmosDatabase"]
|
|
7464
7477
|
}],
|
|
7465
|
-
configString: `cosmosDatabase({
|
|
7466
|
-
|
|
7478
|
+
configString: `cosmosDatabase({${resources?.cosmosEndpoint === void 0 ? "" : `
|
|
7479
|
+
endpoint: ${JSON.stringify(resources.cosmosEndpoint)},`}
|
|
7480
|
+
connectionString: secret("HOT_UPDATER_AZURE_COSMOS_CONNECTION_STRING"),
|
|
7467
7481
|
})`
|
|
7468
|
-
}
|
|
7482
|
+
};
|
|
7483
|
+
const builder = new ConfigBuilder().setBuildType(build).setStorage(storageConfig).setDatabase(databaseConfig).setPlugins({
|
|
7469
7484
|
imports: [{
|
|
7470
7485
|
pkg: "hot-updater/plugins",
|
|
7471
7486
|
named: [
|
|
@@ -7475,7 +7490,11 @@ const getConfigScaffold = (build) => {
|
|
|
7475
7490
|
]
|
|
7476
7491
|
}],
|
|
7477
7492
|
configString: "[apiKeys(), insights(), remoteConfig()]"
|
|
7478
|
-
})
|
|
7493
|
+
}).addImport({
|
|
7494
|
+
pkg: "hot-updater",
|
|
7495
|
+
named: ["secret"]
|
|
7496
|
+
});
|
|
7497
|
+
return createHotUpdaterConfigScaffoldFromBuilder(builder);
|
|
7479
7498
|
};
|
|
7480
7499
|
//#endregion
|
|
7481
7500
|
//#region iac/init/index.ts
|
|
@@ -7560,7 +7579,8 @@ const initProvider = {
|
|
|
7560
7579
|
optional: true,
|
|
7561
7580
|
preflight: false
|
|
7562
7581
|
}
|
|
7563
|
-
}
|
|
7582
|
+
},
|
|
7583
|
+
secrets: ["HOT_UPDATER_AZURE_STORAGE_CONNECTION_STRING", "HOT_UPDATER_AZURE_COSMOS_CONNECTION_STRING"]
|
|
7564
7584
|
};
|
|
7565
7585
|
//#endregion
|
|
7566
7586
|
//#region iac/index.ts
|
|
@@ -7620,10 +7640,10 @@ const resolveName = async ({ input, saved, fallback, nonInteractive, validate, h
|
|
|
7620
7640
|
validate: (value) => validate(value) ? void 0 : hint
|
|
7621
7641
|
}));
|
|
7622
7642
|
};
|
|
7623
|
-
const runInit = async ({ build, envFile }) => {
|
|
7643
|
+
const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
7624
7644
|
const cwd = getCwd();
|
|
7625
7645
|
const nonInteractive = envFile !== void 0;
|
|
7626
|
-
const initEnvSources = await readHotUpdaterInitEnv(cwd, envFile);
|
|
7646
|
+
const initEnvSources = await readHotUpdaterInitEnv(cwd, envFile, secretsEnv);
|
|
7627
7647
|
const initInputEnv = getHotUpdaterInitInputEnv(initEnvSources, nonInteractive);
|
|
7628
7648
|
const saved = Object.fromEntries(Object.entries(inputs).map(([name, input]) => [name, initInputEnv[input.envKey]?.trim() || void 0]));
|
|
7629
7649
|
const cliVersion = await azureCliVersion();
|
|
@@ -7830,7 +7850,8 @@ const runInit = async ({ build, envFile }) => {
|
|
|
7830
7850
|
await database.dispose?.();
|
|
7831
7851
|
}
|
|
7832
7852
|
p.log.success("Generated '.env.hotupdater' file with Azure settings.");
|
|
7833
|
-
|
|
7853
|
+
const cosmosEndpoint = /AccountEndpoint=([^;]+)/iu.exec(cosmosConnectionString)?.[1];
|
|
7854
|
+
await writeHotUpdaterFiles(getConfigScaffold(build, cosmosEndpoint === void 0 ? {} : { cosmosEndpoint }), {
|
|
7834
7855
|
cwd,
|
|
7835
7856
|
settings: "Azure"
|
|
7836
7857
|
});
|
|
@@ -7839,8 +7860,7 @@ const runInit = async ({ build, envFile }) => {
|
|
|
7839
7860
|
...credential === void 0 ? {} : { credential },
|
|
7840
7861
|
clientPlugins: server.clientPlugins
|
|
7841
7862
|
});
|
|
7842
|
-
|
|
7843
|
-
p.log.success("Done! 🎉");
|
|
7863
|
+
return { nextSteps: [link("https://hot-updater.dev/docs/managed/azure#step-3-add-hotupdater-to-your-project")] };
|
|
7844
7864
|
};
|
|
7845
7865
|
//#endregion
|
|
7846
7866
|
export { AZURE_FUNCTION_PACKAGE, defaultResourceNames, initProvider, runInit };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/azure",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.0-rc.
|
|
4
|
+
"version": "1.2.0-rc.21",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": "^22.23.4 || ^24.22.1 || >=26.12.1"
|
|
@@ -41,11 +41,13 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@azure/core-auth": "1.11.0",
|
|
43
43
|
"@azure/cosmos": "4.10.1",
|
|
44
|
+
"@azure/identity": "4.14.0",
|
|
45
|
+
"@azure/keyvault-secrets": "4.11.2",
|
|
44
46
|
"@azure/storage-blob": "12.34.0",
|
|
45
|
-
"@hot-updater/cli-tools": "1.2.0-rc.
|
|
46
|
-
"@hot-updater/
|
|
47
|
-
"@hot-updater/
|
|
48
|
-
"@hot-updater/
|
|
47
|
+
"@hot-updater/cli-tools": "1.2.0-rc.21",
|
|
48
|
+
"@hot-updater/protocol": "1.2.0-rc.21",
|
|
49
|
+
"@hot-updater/server": "1.2.0-rc.21",
|
|
50
|
+
"@hot-updater/plugin-core": "1.2.0-rc.21"
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
53
|
"@azure/functions": "4.16.5",
|
|
@@ -53,7 +55,7 @@
|
|
|
53
55
|
"execa": "9.5.2",
|
|
54
56
|
"jszip": "^3.10.1",
|
|
55
57
|
"vitest": "4.1.4",
|
|
56
|
-
"@hot-updater/test-utils": "1.2.0-rc.
|
|
58
|
+
"@hot-updater/test-utils": "1.2.0-rc.21"
|
|
57
59
|
},
|
|
58
60
|
"scripts": {
|
|
59
61
|
"build": "tsdown",
|