@hot-updater/server 1.2.0-rc.4 → 1.2.0-rc.40
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/core/api.cjs +2 -0
- package/dist/core/api.d.cts +29 -0
- package/dist/core/api.d.mts +29 -0
- package/dist/core/api.mjs +2 -0
- package/dist/core/iosDevices.cjs +309 -0
- package/dist/core/iosDevices.mjs +306 -0
- package/dist/core/nativeBuildDestinations.cjs +13 -0
- package/dist/core/nativeBuildDestinations.mjs +13 -0
- package/dist/core/nativeBuilds.cjs +142 -24
- package/dist/core/nativeBuilds.mjs +142 -25
- package/dist/core/operations.cjs +6 -2
- package/dist/core/operations.mjs +7 -3
- package/dist/core/reads.cjs +9 -1
- package/dist/core/reads.mjs +9 -1
- package/dist/core/writes.cjs +4 -1
- package/dist/core/writes.mjs +4 -1
- package/dist/createHotUpdaterCore.d.cts +2 -4
- package/dist/createHotUpdaterCore.d.mts +2 -4
- package/dist/handlerAdminRoutes.cjs +149 -7
- package/dist/handlerAdminRoutes.mjs +149 -7
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/package.json +7 -14
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { after } from "./reads.mjs";
|
|
2
|
+
import { NATIVE_BUILD_SUBMISSION_DESTINATIONS } from "./nativeBuildDestinations.mjs";
|
|
2
3
|
import { insertChannel } from "./writes.mjs";
|
|
3
4
|
import { DatabaseConstraintError, isUUIDv7 } from "@hot-updater/plugin-core";
|
|
4
5
|
import { createReleaseCatalogScopeKey, encodeChannelKey } from "@hot-updater/protocol";
|
|
@@ -18,6 +19,13 @@ const GIT_COMMIT_HASH_MAX_LENGTH = 255;
|
|
|
18
19
|
* and looks up nothing else.
|
|
19
20
|
*/
|
|
20
21
|
const BUILD_KEY = /^nbk1:[0-9a-f]{64}$/;
|
|
22
|
+
/** `native_builds.sandbox_url_scheme`'s bound in core's schema. */
|
|
23
|
+
const SANDBOX_URL_SCHEME_MAX_LENGTH = 255;
|
|
24
|
+
/**
|
|
25
|
+
* A URL scheme as RFC 3986 spells it, in lower case: what a sandbox build's
|
|
26
|
+
* artifact registers, as `@hot-updater/protocol/native-artifact` reads it.
|
|
27
|
+
*/
|
|
28
|
+
const URL_SCHEME = new RegExp(`^[a-z][a-z0-9+.-]{0,254}$`);
|
|
21
29
|
/** A native build or scope core cannot store or look up: the caller's input. */
|
|
22
30
|
var NativeBuildInputError = class extends TypeError {
|
|
23
31
|
name = "NativeBuildInputError";
|
|
@@ -39,13 +47,33 @@ const pick = (row) => ({
|
|
|
39
47
|
build_number: row.build_number ?? null,
|
|
40
48
|
submitted_to: row.submitted_to ?? null,
|
|
41
49
|
submitted_at_ms: row.submitted_at_ms ?? null,
|
|
42
|
-
submitted_version: row.submitted_version ?? null
|
|
50
|
+
submitted_version: row.submitted_version ?? null,
|
|
51
|
+
is_store_build: row.is_store_build === true,
|
|
52
|
+
is_sandbox: row.is_sandbox === true,
|
|
53
|
+
sandbox_url_scheme: row.sandbox_url_scheme ?? null,
|
|
54
|
+
export_method: row.export_method ?? null,
|
|
55
|
+
native_app_version: row.native_app_version ?? null
|
|
43
56
|
});
|
|
44
|
-
/** The
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
/** The export methods an `.ipa` registers with. */
|
|
58
|
+
const EXPORT_METHODS = /* @__PURE__ */ new Set([
|
|
59
|
+
"app-store",
|
|
60
|
+
"ad-hoc",
|
|
61
|
+
"development",
|
|
62
|
+
"enterprise"
|
|
63
|
+
]);
|
|
64
|
+
/**
|
|
65
|
+
* The channels only sandbox builds register on: a registration's `sandbox`
|
|
66
|
+
* must agree with it. The registry's convention, as
|
|
67
|
+
* `@hot-updater/protocol/native-artifact` checks it for a build's artifact.
|
|
68
|
+
*/
|
|
69
|
+
const SANDBOX_CHANNEL_PREFIX = "sandbox-";
|
|
70
|
+
/**
|
|
71
|
+
* How many older builds of a scope one read takes, looking for one older than
|
|
72
|
+
* a bundle when a build made after the bundle is the newest.
|
|
73
|
+
*/
|
|
74
|
+
const OLDER_BUILDS_PAGE = 20;
|
|
75
|
+
/** How many times a mark runs again after losing its scope's mark to another. */
|
|
76
|
+
const MARK_ATTEMPTS = 8;
|
|
49
77
|
/** `native_builds.build_number`'s bound in core's schema. */
|
|
50
78
|
const BUILD_NUMBER_MAX_LENGTH = 64;
|
|
51
79
|
/** `native_builds.submitted_version`'s bound in core's schema. */
|
|
@@ -76,19 +104,40 @@ const nativeBuildScopeKey = (scope) => {
|
|
|
76
104
|
if (scopeKey.length > SCOPE_KEY_MAX_LENGTH) throw new NativeBuildInputError(`Invalid native build scope: its key is longer than ${SCOPE_KEY_MAX_LENGTH} characters; shorten the channel or app version.`);
|
|
77
105
|
return scopeKey;
|
|
78
106
|
};
|
|
107
|
+
/**
|
|
108
|
+
* Refuses a patch from a sandbox build's built-in bundle: no deploy patches
|
|
109
|
+
* from one, so no store or test install of the app gets a patch made for a
|
|
110
|
+
* sandbox build. One unique read of the base.
|
|
111
|
+
*/
|
|
112
|
+
const refuseSandboxPatchBase = async (db, baseBundleId) => {
|
|
113
|
+
if ((await db.findOne("native_builds", { min_bundle_id: baseBundleId }))?.is_sandbox === true) throw new NativeBuildInputError("A sandbox build's built-in bundle is no patch base.");
|
|
114
|
+
};
|
|
79
115
|
/** Whether `bundleId` is a native build's built-in bundle: one unique read. */
|
|
80
116
|
const isBuiltInBundle = async (db, bundleId) => await db.findOne("native_builds", { min_bundle_id: bundleId }) !== null;
|
|
81
|
-
const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, artifact }) => {
|
|
117
|
+
const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, exportMethod, nativeAppVersion, artifact }) => {
|
|
82
118
|
if (!isUUIDv7(id)) return "id must be a UUIDv7";
|
|
83
119
|
if (!isUUIDv7(minBundleId)) return "minBundleId must be the UUIDv7 a release build compiles in";
|
|
84
120
|
if (platform !== "ios" && platform !== "android") return "platform must be ios or android";
|
|
85
121
|
if (channel.trim().length === 0) return "channel is required";
|
|
122
|
+
if (isSandbox !== void 0 && typeof isSandbox !== "boolean") return "isSandbox must be true or false";
|
|
123
|
+
const reserved = channel.startsWith(SANDBOX_CHANNEL_PREFIX);
|
|
124
|
+
if (isSandbox === true && !reserved) return `a sandbox build registers on a ${SANDBOX_CHANNEL_PREFIX}* channel, not ${channel}`;
|
|
125
|
+
if (isSandbox !== true && reserved) return `channel ${channel} is reserved for sandbox builds`;
|
|
126
|
+
if (sandboxUrlScheme !== void 0 && sandboxUrlScheme !== null) {
|
|
127
|
+
if (isSandbox !== true) return "sandboxUrlScheme is a sandbox build's, and this isn't one";
|
|
128
|
+
if (typeof sandboxUrlScheme !== "string" || !URL_SCHEME.test(sandboxUrlScheme)) return `sandboxUrlScheme must be a URL scheme in lower case, up to ${SANDBOX_URL_SCHEME_MAX_LENGTH} characters, or null`;
|
|
129
|
+
}
|
|
86
130
|
if (gitCommitHash !== null && gitCommitHash.length > GIT_COMMIT_HASH_MAX_LENGTH) return `gitCommitHash must be at most ${GIT_COMMIT_HASH_MAX_LENGTH} characters`;
|
|
87
131
|
if (fingerprintHash === null === (appVersion === null)) return "exactly one of fingerprintHash and appVersion is required";
|
|
88
132
|
if (buildKey !== null && !BUILD_KEY.test(buildKey)) return "buildKey must be nbk1: and a SHA-256, or null";
|
|
89
133
|
if (buildNumber !== void 0 && buildNumber !== null && (buildNumber.trim().length === 0 || buildNumber.length > BUILD_NUMBER_MAX_LENGTH)) return `buildNumber must be the artifact's build number, up to ${BUILD_NUMBER_MAX_LENGTH} characters, or null`;
|
|
134
|
+
if (nativeAppVersion !== void 0 && nativeAppVersion !== null && (typeof nativeAppVersion !== "string" || nativeAppVersion.trim().length === 0)) return "nativeAppVersion must be the artifact's app version, or null";
|
|
90
135
|
const kinds = ARTIFACT_KINDS[platform];
|
|
91
136
|
if (!kinds.includes(artifact.kind)) return `artifact.kind of an ${platform} build must be ${kinds.join(" or ")}`;
|
|
137
|
+
if (exportMethod !== void 0 && exportMethod !== null) {
|
|
138
|
+
if (artifact.kind !== "ipa") return "exportMethod is an .ipa's, and this artifact isn't one";
|
|
139
|
+
if (!EXPORT_METHODS.has(exportMethod)) return `exportMethod must be ${[...EXPORT_METHODS].join(", ")}, or null`;
|
|
140
|
+
}
|
|
92
141
|
if (!Number.isSafeInteger(artifact.byteSize) || artifact.byteSize < 0) return "artifact.byteSize must be a byte count";
|
|
93
142
|
return null;
|
|
94
143
|
};
|
|
@@ -117,7 +166,12 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
117
166
|
build_number: registration.buildNumber ?? null,
|
|
118
167
|
submitted_to: null,
|
|
119
168
|
submitted_at_ms: null,
|
|
120
|
-
submitted_version: null
|
|
169
|
+
submitted_version: null,
|
|
170
|
+
is_store_build: false,
|
|
171
|
+
is_sandbox: registration.isSandbox === true,
|
|
172
|
+
sandbox_url_scheme: registration.sandboxUrlScheme ?? null,
|
|
173
|
+
export_method: registration.exportMethod ?? null,
|
|
174
|
+
native_app_version: registration.nativeAppVersion ?? null
|
|
121
175
|
};
|
|
122
176
|
for (let attempt = 1;; attempt += 1) {
|
|
123
177
|
await insertChannel(db, {
|
|
@@ -155,21 +209,43 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
155
209
|
const scopeKey = nativeBuildScopeKey(scope);
|
|
156
210
|
const buildKey = options?.buildKey;
|
|
157
211
|
if (buildKey !== void 0 && !BUILD_KEY.test(buildKey)) throw new NativeBuildInputError("Invalid native build key: it must be nbk1: and a SHA-256.");
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
212
|
+
if (options?.storeBuild) {
|
|
213
|
+
const marked = await db.findOne("native_builds", { store_build_scope_key: scopeKey });
|
|
214
|
+
return marked === null ? null : pick(marked);
|
|
215
|
+
}
|
|
216
|
+
const read = (limit, before) => {
|
|
217
|
+
const page = {
|
|
218
|
+
order: "desc",
|
|
219
|
+
limit,
|
|
220
|
+
...before === void 0 ? {} : { range: { lt: before } }
|
|
221
|
+
};
|
|
222
|
+
return buildKey === void 0 ? db.findMany("native_builds", {
|
|
223
|
+
index: "byScope",
|
|
224
|
+
where: { scope_key: scopeKey },
|
|
225
|
+
...page
|
|
226
|
+
}) : db.findMany("native_builds", {
|
|
227
|
+
index: "byBuildKey",
|
|
228
|
+
where: {
|
|
229
|
+
scope_key: scopeKey,
|
|
230
|
+
build_key: buildKey
|
|
231
|
+
},
|
|
232
|
+
...page
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
const bundleId = options?.builtInOlderThan;
|
|
236
|
+
if (bundleId !== void 0 && scope.channel.startsWith(SANDBOX_CHANNEL_PREFIX)) return null;
|
|
237
|
+
const { rows } = await read(1);
|
|
238
|
+
const newest = rows[0];
|
|
239
|
+
if (newest === void 0) return null;
|
|
240
|
+
if (bundleId === void 0 || newest.min_bundle_id < bundleId) return pick(newest);
|
|
241
|
+
for (let before = newest.id;;) {
|
|
242
|
+
const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
|
|
243
|
+
const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
|
|
244
|
+
if (usable !== void 0) return pick(usable);
|
|
245
|
+
const last = older.at(-1);
|
|
246
|
+
if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
|
|
247
|
+
before = last.id;
|
|
248
|
+
}
|
|
173
249
|
},
|
|
174
250
|
async recordNativeBuildSubmission(id, { destination, version }) {
|
|
175
251
|
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.`);
|
|
@@ -177,7 +253,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
177
253
|
const row = await tx.findOne("native_builds", { id });
|
|
178
254
|
if (row === null) return null;
|
|
179
255
|
const build = pick(row);
|
|
180
|
-
if (
|
|
256
|
+
if (!NATIVE_BUILD_SUBMISSION_DESTINATIONS[build.platform].includes(destination)) throw new NativeBuildInputError(`Invalid native build submission: an ${build.platform} build is submitted to ${NATIVE_BUILD_SUBMISSION_DESTINATIONS[build.platform].join(" or ")}, not ${destination}.`);
|
|
257
|
+
if (build.is_sandbox && destination !== "testflight" && destination !== "play-internal") throw new NativeBuildInputError("A sandbox build can submit only to TestFlight or Play internal testing.");
|
|
181
258
|
const set = {
|
|
182
259
|
submitted_to: destination,
|
|
183
260
|
submitted_at_ms: now(),
|
|
@@ -190,6 +267,46 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
190
267
|
};
|
|
191
268
|
});
|
|
192
269
|
},
|
|
270
|
+
async markNativeBuild(id, { storeBuild }) {
|
|
271
|
+
for (let attempt = 1;; attempt += 1) try {
|
|
272
|
+
return await db.transaction(async (tx) => {
|
|
273
|
+
const row = await tx.findOne("native_builds", { id });
|
|
274
|
+
if (row === null) return null;
|
|
275
|
+
const build = pick(row);
|
|
276
|
+
if (!storeBuild) {
|
|
277
|
+
if (build.is_store_build) tx.update("native_builds", row, { is_store_build: false });
|
|
278
|
+
return {
|
|
279
|
+
nativeBuild: {
|
|
280
|
+
...build,
|
|
281
|
+
is_store_build: false
|
|
282
|
+
},
|
|
283
|
+
previous: null
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
if (build.is_sandbox) throw new NativeBuildInputError("A sandbox build can't be the store build.");
|
|
287
|
+
if (build.is_store_build) return {
|
|
288
|
+
nativeBuild: build,
|
|
289
|
+
previous: null
|
|
290
|
+
};
|
|
291
|
+
const holder = await tx.findOne("native_builds", { store_build_scope_key: build.scope_key });
|
|
292
|
+
if (holder !== null) tx.update("native_builds", holder, { is_store_build: false });
|
|
293
|
+
tx.update("native_builds", row, { is_store_build: true });
|
|
294
|
+
return {
|
|
295
|
+
nativeBuild: {
|
|
296
|
+
...build,
|
|
297
|
+
is_store_build: true
|
|
298
|
+
},
|
|
299
|
+
previous: holder === null ? null : {
|
|
300
|
+
...pick(holder),
|
|
301
|
+
is_store_build: false
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
});
|
|
305
|
+
} catch (error) {
|
|
306
|
+
if (attempt < MARK_ATTEMPTS && error instanceof DatabaseConstraintError && error.reason === "unique") continue;
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
309
|
+
},
|
|
193
310
|
async deleteNativeBuild(id) {
|
|
194
311
|
return db.transaction(async (tx) => {
|
|
195
312
|
const row = await tx.findOne("native_builds", { id });
|
|
@@ -226,4 +343,4 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
226
343
|
}
|
|
227
344
|
});
|
|
228
345
|
//#endregion
|
|
229
|
-
export { NativeBuildInputError, createNativeBuildApi, isBuiltInBundle, nativeBuildScopeKey };
|
|
346
|
+
export { NativeBuildInputError, createNativeBuildApi, isBuiltInBundle, nativeBuildScopeKey, refuseSandboxPatchBase };
|
package/dist/core/operations.cjs
CHANGED
|
@@ -129,7 +129,11 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
129
129
|
for (const { release } of deployments) if (!channels.has(release.channel)) channels.set(release.channel, await ensureChannel(release.channel));
|
|
130
130
|
const platforms = /* @__PURE__ */ new Map();
|
|
131
131
|
for (const deployment of deployments) {
|
|
132
|
-
if (!("bundleId" in deployment)
|
|
132
|
+
if (!("bundleId" in deployment)) {
|
|
133
|
+
for (const { baseBundleId } of deployment.bundle.patches ?? []) await require_nativeBuilds.refuseSandboxPatchBase(db, baseBundleId);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (platforms.has(deployment.bundleId)) continue;
|
|
133
137
|
const row = await db.findOne("bundles", { id: deployment.bundleId });
|
|
134
138
|
if (row === null) throw new _hot_updater_plugin_core.DatabaseBundleNotFoundError(deployment.bundleId);
|
|
135
139
|
if (await require_nativeBuilds.isBuiltInBundle(db, deployment.bundleId)) throw new _hot_updater_plugin_core.ReleaseManagementError("TARGET_RELEASE_INVALID", `Bundle "${deployment.bundleId}" is a native build's built-in bundle, which no release publishes.`);
|
|
@@ -333,7 +337,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
333
337
|
if (patches !== void 0) await require_writes.replaceBundlePatches(tx, current, (0, _hot_updater_plugin_core.bundleToPatchRows)({
|
|
334
338
|
...next,
|
|
335
339
|
patches
|
|
336
|
-
}));
|
|
340
|
+
}), (row) => require_nativeBuilds.refuseSandboxPatchBase(tx, row.base_bundle_id));
|
|
337
341
|
}),
|
|
338
342
|
deleteBundles: async (ids) => {
|
|
339
343
|
try {
|
package/dist/core/operations.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { toBundleRow, toReleaseRow } from "./reads.mjs";
|
|
2
2
|
import { deleteBundle, deleteChannel, insertChannel, replaceBundlePatches, updateBundle } from "./writes.mjs";
|
|
3
|
-
import { isBuiltInBundle } from "./nativeBuilds.mjs";
|
|
3
|
+
import { isBuiltInBundle, refuseSandboxPatchBase } from "./nativeBuilds.mjs";
|
|
4
4
|
import { changeRelease, changeReleases, readCatalog, rebuildScope } from "./releases.mjs";
|
|
5
5
|
import { DatabaseBundleNotFoundError, DatabaseConstraintError, DatabaseRowReferencedError, ReleaseCatalogMutationError, ReleaseManagementError, bundleToPatchRows, bundleToRow, createUUIDv7After, isUUIDv7, rowToBundle } from "@hot-updater/plugin-core";
|
|
6
6
|
import { createReleaseCatalogScopeKey, decodeChannelKey, encodeChannelKey } from "@hot-updater/protocol";
|
|
@@ -129,7 +129,11 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
129
129
|
for (const { release } of deployments) if (!channels.has(release.channel)) channels.set(release.channel, await ensureChannel(release.channel));
|
|
130
130
|
const platforms = /* @__PURE__ */ new Map();
|
|
131
131
|
for (const deployment of deployments) {
|
|
132
|
-
if (!("bundleId" in deployment)
|
|
132
|
+
if (!("bundleId" in deployment)) {
|
|
133
|
+
for (const { baseBundleId } of deployment.bundle.patches ?? []) await refuseSandboxPatchBase(db, baseBundleId);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (platforms.has(deployment.bundleId)) continue;
|
|
133
137
|
const row = await db.findOne("bundles", { id: deployment.bundleId });
|
|
134
138
|
if (row === null) throw new DatabaseBundleNotFoundError(deployment.bundleId);
|
|
135
139
|
if (await isBuiltInBundle(db, deployment.bundleId)) throw new ReleaseManagementError("TARGET_RELEASE_INVALID", `Bundle "${deployment.bundleId}" is a native build's built-in bundle, which no release publishes.`);
|
|
@@ -333,7 +337,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
333
337
|
if (patches !== void 0) await replaceBundlePatches(tx, current, bundleToPatchRows({
|
|
334
338
|
...next,
|
|
335
339
|
patches
|
|
336
|
-
}));
|
|
340
|
+
}), (row) => refuseSandboxPatchBase(tx, row.base_bundle_id));
|
|
337
341
|
}),
|
|
338
342
|
deleteBundles: async (ids) => {
|
|
339
343
|
try {
|
package/dist/core/reads.cjs
CHANGED
|
@@ -74,7 +74,15 @@ const drain = async (read) => {
|
|
|
74
74
|
return rows;
|
|
75
75
|
};
|
|
76
76
|
/** A keyset page's range: the keys strictly after `after`, in `order`. */
|
|
77
|
-
|
|
77
|
+
/** A keyset read's range on its index's order: past `after`, up to `through`. */
|
|
78
|
+
const after = (input) => {
|
|
79
|
+
const asc = (input.order ?? "asc") === "asc";
|
|
80
|
+
const range = {
|
|
81
|
+
...input.after === void 0 ? {} : asc ? { gt: input.after } : { lt: input.after },
|
|
82
|
+
...input.through === void 0 ? {} : asc ? { lte: input.through } : { gte: input.through }
|
|
83
|
+
};
|
|
84
|
+
return Object.keys(range).length === 0 ? {} : { range };
|
|
85
|
+
};
|
|
78
86
|
/** Core's reads, each through one declared index or key. */
|
|
79
87
|
const createCoreReads = (db, storage) => {
|
|
80
88
|
/** A bundle row's patches, exactly as many as its reference counter holds. */
|
package/dist/core/reads.mjs
CHANGED
|
@@ -74,7 +74,15 @@ const drain = async (read) => {
|
|
|
74
74
|
return rows;
|
|
75
75
|
};
|
|
76
76
|
/** A keyset page's range: the keys strictly after `after`, in `order`. */
|
|
77
|
-
|
|
77
|
+
/** A keyset read's range on its index's order: past `after`, up to `through`. */
|
|
78
|
+
const after = (input) => {
|
|
79
|
+
const asc = (input.order ?? "asc") === "asc";
|
|
80
|
+
const range = {
|
|
81
|
+
...input.after === void 0 ? {} : asc ? { gt: input.after } : { lt: input.after },
|
|
82
|
+
...input.through === void 0 ? {} : asc ? { lte: input.through } : { gte: input.through }
|
|
83
|
+
};
|
|
84
|
+
return Object.keys(range).length === 0 ? {} : { range };
|
|
85
|
+
};
|
|
78
86
|
/** Core's reads, each through one declared index or key. */
|
|
79
87
|
const createCoreReads = (db, storage) => {
|
|
80
88
|
/** A bundle row's patches, exactly as many as its reference counter holds. */
|
package/dist/core/writes.cjs
CHANGED
|
@@ -29,8 +29,10 @@ const deleteBundle = async (tx, current) => {
|
|
|
29
29
|
/**
|
|
30
30
|
* Replaces a bundle's patches with `rows`: kept patches are updated where
|
|
31
31
|
* they changed, others deleted or created, so no key is written twice.
|
|
32
|
+
* `checkNew` sees each patch it is about to create, and refuses one by
|
|
33
|
+
* throwing, which leaves the transaction's writes undone.
|
|
32
34
|
*/
|
|
33
|
-
const replaceBundlePatches = async (tx, bundle, rows) => {
|
|
35
|
+
const replaceBundlePatches = async (tx, bundle, rows, checkNew) => {
|
|
34
36
|
const wanted = new Map(rows.map((row) => [row.id, row]));
|
|
35
37
|
const count = bundle._refs_bundle_patches_bundle_id ?? 0;
|
|
36
38
|
let cursor;
|
|
@@ -55,6 +57,7 @@ const replaceBundlePatches = async (tx, bundle, rows) => {
|
|
|
55
57
|
if (page.next === void 0) break;
|
|
56
58
|
cursor = page.next;
|
|
57
59
|
}
|
|
60
|
+
if (checkNew !== void 0) for (const row of wanted.values()) await checkNew(row);
|
|
58
61
|
for (const row of wanted.values()) tx.create("bundle_patches", row);
|
|
59
62
|
};
|
|
60
63
|
/** A channel by name, created when missing; a concurrent creator's row is returned instead. */
|
package/dist/core/writes.mjs
CHANGED
|
@@ -29,8 +29,10 @@ const deleteBundle = async (tx, current) => {
|
|
|
29
29
|
/**
|
|
30
30
|
* Replaces a bundle's patches with `rows`: kept patches are updated where
|
|
31
31
|
* they changed, others deleted or created, so no key is written twice.
|
|
32
|
+
* `checkNew` sees each patch it is about to create, and refuses one by
|
|
33
|
+
* throwing, which leaves the transaction's writes undone.
|
|
32
34
|
*/
|
|
33
|
-
const replaceBundlePatches = async (tx, bundle, rows) => {
|
|
35
|
+
const replaceBundlePatches = async (tx, bundle, rows, checkNew) => {
|
|
34
36
|
const wanted = new Map(rows.map((row) => [row.id, row]));
|
|
35
37
|
const count = bundle._refs_bundle_patches_bundle_id ?? 0;
|
|
36
38
|
let cursor;
|
|
@@ -55,6 +57,7 @@ const replaceBundlePatches = async (tx, bundle, rows) => {
|
|
|
55
57
|
if (page.next === void 0) break;
|
|
56
58
|
cursor = page.next;
|
|
57
59
|
}
|
|
60
|
+
if (checkNew !== void 0) for (const row of wanted.values()) await checkNew(row);
|
|
58
61
|
for (const row of wanted.values()) tx.create("bundle_patches", row);
|
|
59
62
|
};
|
|
60
63
|
/** A channel by name, created when missing; a concurrent creator's row is returned instead. */
|
|
@@ -42,10 +42,8 @@ type RuntimeHotUpdaterAPI<TPlugins extends readonly AnyHotUpdaterPlugin[] = read
|
|
|
42
42
|
/** The database's name, which `hot-updater db` commands read. */
|
|
43
43
|
readonly adapterName: string;
|
|
44
44
|
/**
|
|
45
|
-
* Applies
|
|
46
|
-
*
|
|
47
|
-
* A long-lived server with `aggregateBatching: { mode: "memory" }` calls
|
|
48
|
-
* it before it exits.
|
|
45
|
+
* Applies the log rows of batched aggregates that no compaction has merged
|
|
46
|
+
* yet. Nothing waits on it: they are durable, and a read compacts first.
|
|
49
47
|
*/
|
|
50
48
|
readonly flush: () => Promise<void>;
|
|
51
49
|
/**
|
|
@@ -42,10 +42,8 @@ type RuntimeHotUpdaterAPI<TPlugins extends readonly AnyHotUpdaterPlugin[] = read
|
|
|
42
42
|
/** The database's name, which `hot-updater db` commands read. */
|
|
43
43
|
readonly adapterName: string;
|
|
44
44
|
/**
|
|
45
|
-
* Applies
|
|
46
|
-
*
|
|
47
|
-
* A long-lived server with `aggregateBatching: { mode: "memory" }` calls
|
|
48
|
-
* it before it exits.
|
|
45
|
+
* Applies the log rows of batched aggregates that no compaction has merged
|
|
46
|
+
* yet. Nothing waits on it: they are durable, and a read compacts first.
|
|
49
47
|
*/
|
|
50
48
|
readonly flush: () => Promise<void>;
|
|
51
49
|
/**
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const require_iosDevices = require("./core/iosDevices.cjs");
|
|
2
|
+
const require_nativeBuildDestinations = require("./core/nativeBuildDestinations.cjs");
|
|
1
3
|
const require_nativeBuilds = require("./core/nativeBuilds.cjs");
|
|
2
4
|
const require_handlerErrors = require("./handlerErrors.cjs");
|
|
3
5
|
const require_handlerParameters = require("./handlerParameters.cjs");
|
|
@@ -47,10 +49,12 @@ const keyset = (url, maxValue = LIMITS.maxValue) => {
|
|
|
47
49
|
const limit = limitParam === null ? Math.min(LIMITS.defaultValue, maxValue) : Number(limitParam);
|
|
48
50
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > maxValue) throw new require_handlerErrors.HandlerBadRequestError(`limit must be between 1 and ${maxValue}.`);
|
|
49
51
|
const cursor = url.searchParams.get("cursor");
|
|
52
|
+
const through = url.searchParams.get("through");
|
|
50
53
|
return {
|
|
51
54
|
order,
|
|
52
55
|
limit,
|
|
53
|
-
...cursor === null ? {} : { after: cursor }
|
|
56
|
+
...cursor === null ? {} : { after: cursor },
|
|
57
|
+
...through === null ? {} : { through }
|
|
54
58
|
};
|
|
55
59
|
};
|
|
56
60
|
/** A page and the cursor of the next one, when the page is full. */
|
|
@@ -165,11 +169,11 @@ const refusingInvalid = async (operation) => {
|
|
|
165
169
|
try {
|
|
166
170
|
return await operation();
|
|
167
171
|
} catch (error) {
|
|
168
|
-
if (error instanceof require_nativeBuilds.NativeBuildInputError) throw new require_handlerErrors.HandlerBadRequestError(error.message);
|
|
172
|
+
if (error instanceof require_nativeBuilds.NativeBuildInputError || error instanceof require_iosDevices.IosDeviceInputError) throw new require_handlerErrors.HandlerBadRequestError(error.message);
|
|
169
173
|
throw error;
|
|
170
174
|
}
|
|
171
175
|
};
|
|
172
|
-
const isNativeBuildRegistration = (value) => isRecord(value) && isText(value.id) && isText(value.minBundleId) && typeof value.platform === "string" && require_handlerParameters.isPlatform(value.platform) && isText(value.channel) && isTextOrNull(value.fingerprintHash) && isTextOrNull(value.appVersion) && value.fingerprintHash === null !== (value.appVersion === null) && isTextOrNull(value.gitCommitHash) && isTextOrNull(value.buildKey) && (value.buildNumber === void 0 || isTextOrNull(value.buildNumber)) && isRecord(value.artifact) && typeof value.artifact.kind === "string" && NATIVE_BUILD_ARTIFACT_KINDS.has(value.artifact.kind) && isText(value.artifact.storageUri) && Number.isSafeInteger(value.artifact.byteSize) && value.artifact.byteSize >= 0 && isRecord(value.embeddedBundle) && isText(value.embeddedBundle.manifestStorageUri) && isText(value.embeddedBundle.manifestFileHash) && isText(value.embeddedBundle.assetBaseStorageUri) && (value.embeddedBundle.metadata === void 0 || isRecord(value.embeddedBundle.metadata));
|
|
176
|
+
const isNativeBuildRegistration = (value) => isRecord(value) && isText(value.id) && isText(value.minBundleId) && typeof value.platform === "string" && require_handlerParameters.isPlatform(value.platform) && isText(value.channel) && isTextOrNull(value.fingerprintHash) && isTextOrNull(value.appVersion) && value.fingerprintHash === null !== (value.appVersion === null) && isTextOrNull(value.gitCommitHash) && isTextOrNull(value.buildKey) && (value.buildNumber === void 0 || isTextOrNull(value.buildNumber)) && (value.isSandbox === void 0 || typeof value.isSandbox === "boolean") && (value.sandboxUrlScheme === void 0 || isTextOrNull(value.sandboxUrlScheme)) && (value.exportMethod === void 0 || isTextOrNull(value.exportMethod)) && (value.nativeAppVersion === void 0 || isTextOrNull(value.nativeAppVersion)) && isRecord(value.artifact) && typeof value.artifact.kind === "string" && NATIVE_BUILD_ARTIFACT_KINDS.has(value.artifact.kind) && isText(value.artifact.storageUri) && Number.isSafeInteger(value.artifact.byteSize) && value.artifact.byteSize >= 0 && isRecord(value.embeddedBundle) && isText(value.embeddedBundle.manifestStorageUri) && isText(value.embeddedBundle.manifestFileHash) && isText(value.embeddedBundle.assetBaseStorageUri) && (value.embeddedBundle.metadata === void 0 || isRecord(value.embeddedBundle.metadata));
|
|
173
177
|
const scopeKeyOf = (params) => require_handlerParameters.decodeMaybe(require_handlerParameters.requireRouteParam(params, "scopeKey")) ?? "";
|
|
174
178
|
/** Every admin route's handler, by the name `ADMIN_ROUTES` mounts it under. */
|
|
175
179
|
const createAdminRouteHandlers = () => ({
|
|
@@ -251,7 +255,8 @@ const createAdminRouteHandlers = () => ({
|
|
|
251
255
|
rebuildReleaseCatalog: onCore(async (core, _request, params) => json({ data: await core.rebuildReleaseCatalog(scopeKeyOf(params)) })),
|
|
252
256
|
updateBundle: onCore(async (core, request, params) => {
|
|
253
257
|
const bundleId = require_handlerParameters.requireRouteParam(params, "id");
|
|
254
|
-
|
|
258
|
+
const update = bundleUpdateOf(await request.json(), bundleId);
|
|
259
|
+
await refusingInvalid(() => core.updateBundle(bundleId, update));
|
|
255
260
|
return noContent();
|
|
256
261
|
}),
|
|
257
262
|
countBundles: onCore(async (core, request) => json({ data: await core.countBundles(platformOf(new URL(request.url))) })),
|
|
@@ -275,7 +280,7 @@ const createAdminRouteHandlers = () => ({
|
|
|
275
280
|
deployReleases: onCore(async (core, request) => {
|
|
276
281
|
const { deployments } = await body(request);
|
|
277
282
|
if (!Array.isArray(deployments) || deployments.length === 0 || !deployments.every(isDeployment)) throw new require_handlerErrors.HandlerBadRequestError("Deploy needs deployments, each a bundle and its release policy.");
|
|
278
|
-
return json({ data: await core.deploy(deployments) }, 201);
|
|
283
|
+
return json({ data: await refusingInvalid(() => core.deploy(deployments)) }, 201);
|
|
279
284
|
}),
|
|
280
285
|
promoteRelease: onCore(async (core, request, params) => {
|
|
281
286
|
const input = await body(request);
|
|
@@ -298,7 +303,13 @@ const createAdminRouteHandlers = () => ({
|
|
|
298
303
|
const url = new URL(request.url);
|
|
299
304
|
const scope = nativeBuildScopeOf(url);
|
|
300
305
|
const buildKey = url.searchParams.get("buildKey");
|
|
301
|
-
|
|
306
|
+
const builtInOlderThan = url.searchParams.get("builtInOlderThan");
|
|
307
|
+
const options = {
|
|
308
|
+
...buildKey === null ? {} : { buildKey },
|
|
309
|
+
...url.searchParams.get("storeBuild") === "true" ? { storeBuild: true } : {},
|
|
310
|
+
...builtInOlderThan === null ? {} : { builtInOlderThan }
|
|
311
|
+
};
|
|
312
|
+
return json({ data: await refusingInvalid(() => Object.keys(options).length === 0 ? core.findNativeBuild(scope) : core.findNativeBuild(scope, options)) });
|
|
302
313
|
}),
|
|
303
314
|
getNativeBuild: onCore(async (core, _request, params) => json({ data: await core.getNativeBuild(require_handlerParameters.requireRouteParam(params, "id")) })),
|
|
304
315
|
listNativeBuilds: onCore(async (core, request) => {
|
|
@@ -312,14 +323,95 @@ const createAdminRouteHandlers = () => ({
|
|
|
312
323
|
}),
|
|
313
324
|
recordNativeBuildSubmission: onCore(async (core, request, params) => {
|
|
314
325
|
const input = await body(request);
|
|
315
|
-
if (!isRecord(input) ||
|
|
326
|
+
if (!isRecord(input) || !Object.values(require_nativeBuildDestinations.NATIVE_BUILD_SUBMISSION_DESTINATIONS).flat().includes(input.destination) || !isText(input.version)) throw new require_handlerErrors.HandlerBadRequestError("A native build submission needs a valid store destination and version.");
|
|
316
327
|
const submission = {
|
|
317
328
|
destination: input.destination,
|
|
318
329
|
version: input.version
|
|
319
330
|
};
|
|
320
331
|
return json({ data: await refusingInvalid(() => core.recordNativeBuildSubmission(require_handlerParameters.requireRouteParam(params, "id"), submission)) });
|
|
321
332
|
}),
|
|
333
|
+
markNativeBuild: onCore(async (core, request, params) => {
|
|
334
|
+
const input = await body(request);
|
|
335
|
+
if (!isRecord(input) || typeof input.storeBuild !== "boolean") throw new require_handlerErrors.HandlerBadRequestError("A native build's store build mark needs storeBuild, true or false.");
|
|
336
|
+
const mark = { storeBuild: input.storeBuild };
|
|
337
|
+
return json({ data: await refusingInvalid(() => core.markNativeBuild(require_handlerParameters.requireRouteParam(params, "id"), mark)) });
|
|
338
|
+
}),
|
|
322
339
|
deleteNativeBuild: onCore(async (core, _request, params) => json({ data: await core.deleteNativeBuild(require_handlerParameters.requireRouteParam(params, "id")) })),
|
|
340
|
+
listIosDevices: onCore(async (core, request) => {
|
|
341
|
+
const url = new URL(request.url);
|
|
342
|
+
const input = keyset(url);
|
|
343
|
+
const status = url.searchParams.get("status");
|
|
344
|
+
return page(await refusingInvalid(() => core.listIosDevices({
|
|
345
|
+
...input,
|
|
346
|
+
...status === null ? {} : { status }
|
|
347
|
+
})), input, ({ id }) => id);
|
|
348
|
+
}),
|
|
349
|
+
findIosDevice: onCore(async (core, _request, params) => json({ data: await core.findIosDevice(require_handlerParameters.requireRouteParam(params, "udid")) })),
|
|
350
|
+
requestIosDevice: onCore(async (core, request) => {
|
|
351
|
+
const input = await body(request);
|
|
352
|
+
if (!isText(input.udid) || !isText(input.name) || !isTextOrNull(input.requestedBy)) throw new require_handlerErrors.HandlerBadRequestError("An iOS device request needs udid, name, and requestedBy, an email or null.");
|
|
353
|
+
const device = {
|
|
354
|
+
udid: input.udid,
|
|
355
|
+
name: input.name,
|
|
356
|
+
requestedBy: input.requestedBy
|
|
357
|
+
};
|
|
358
|
+
return json({ data: await refusingInvalid(() => core.requestIosDevice(device)) });
|
|
359
|
+
}),
|
|
360
|
+
approveIosDevice: onCore(async (core, request, params) => {
|
|
361
|
+
const input = await body(request);
|
|
362
|
+
if (!isTextOrNull(input.approvedBy) || input.name !== void 0 && !isText(input.name)) throw new require_handlerErrors.HandlerBadRequestError("An iOS device approval needs approvedBy, an email or null, and an optional name.");
|
|
363
|
+
const approval = {
|
|
364
|
+
approvedBy: input.approvedBy,
|
|
365
|
+
...input.name === void 0 ? {} : { name: input.name }
|
|
366
|
+
};
|
|
367
|
+
return json({ data: await refusingInvalid(() => core.approveIosDevice(require_handlerParameters.requireRouteParam(params, "id"), approval)) });
|
|
368
|
+
}),
|
|
369
|
+
renameIosDevice: onCore(async (core, request, params) => {
|
|
370
|
+
const input = await body(request);
|
|
371
|
+
if (!isText(input.name)) throw new require_handlerErrors.HandlerBadRequestError("An iOS device's new name is required.");
|
|
372
|
+
const name = input.name;
|
|
373
|
+
return json({ data: await refusingInvalid(() => core.renameIosDevice(require_handlerParameters.requireRouteParam(params, "id"), name)) });
|
|
374
|
+
}),
|
|
375
|
+
recordIosDeviceOutcome: onCore(async (core, request, params) => {
|
|
376
|
+
const input = await body(request);
|
|
377
|
+
const seen = input.seen;
|
|
378
|
+
if (!isRecord(seen) || typeof seen.status !== "string" || !(seen.approvedAtMs === null || Number.isSafeInteger(seen.approvedAtMs)) || !isText(input.issuerId) || typeof input.outcome !== "string" || input.reason !== void 0 && typeof input.reason !== "string") throw new require_handlerErrors.HandlerBadRequestError("An iOS device outcome needs seen { status, approvedAtMs }, issuerId, outcome, and an optional reason.");
|
|
379
|
+
const outcome = {
|
|
380
|
+
id: require_handlerParameters.requireRouteParam(params, "id"),
|
|
381
|
+
seen: {
|
|
382
|
+
status: seen.status,
|
|
383
|
+
approvedAtMs: seen.approvedAtMs
|
|
384
|
+
},
|
|
385
|
+
issuerId: input.issuerId,
|
|
386
|
+
outcome: input.outcome,
|
|
387
|
+
...input.reason === void 0 ? {} : { reason: input.reason }
|
|
388
|
+
};
|
|
389
|
+
return json({ data: await refusingInvalid(() => core.recordIosDeviceOutcome(outcome)) });
|
|
390
|
+
}),
|
|
391
|
+
claimIosDeviceAccount: onCore(async (core, request) => {
|
|
392
|
+
const { issuerId } = await body(request);
|
|
393
|
+
if (!isText(issuerId)) throw new require_handlerErrors.HandlerBadRequestError("Claiming the iOS device account needs issuerId.");
|
|
394
|
+
return json({ data: await refusingInvalid(() => core.claimIosDeviceAccount(issuerId)) });
|
|
395
|
+
}),
|
|
396
|
+
markIosDevicesInBuild: onCore(async (core, request) => {
|
|
397
|
+
const { buildId, ids } = await body(request);
|
|
398
|
+
if (!isText(buildId) || !Array.isArray(ids) || !ids.every((id) => isText(id))) throw new require_handlerErrors.HandlerBadRequestError("Marking iOS devices in a build needs buildId and ids.");
|
|
399
|
+
await core.markIosDevicesInBuild({
|
|
400
|
+
buildId,
|
|
401
|
+
ids
|
|
402
|
+
});
|
|
403
|
+
return noContent();
|
|
404
|
+
}),
|
|
405
|
+
deleteIosDevice: onCore(async (core, request, params) => {
|
|
406
|
+
const url = new URL(request.url);
|
|
407
|
+
const status = url.searchParams.get("status");
|
|
408
|
+
const requestedBy = url.searchParams.get("requestedBy");
|
|
409
|
+
const only = {
|
|
410
|
+
...status === null ? {} : { status },
|
|
411
|
+
...requestedBy === null ? {} : { requestedBy }
|
|
412
|
+
};
|
|
413
|
+
return json({ data: await refusingInvalid(() => Object.keys(only).length === 0 ? core.deleteIosDevice(require_handlerParameters.requireRouteParam(params, "id")) : core.deleteIosDevice(require_handlerParameters.requireRouteParam(params, "id"), only)) });
|
|
414
|
+
}),
|
|
323
415
|
deleteBundles: onCore(async (core, request) => {
|
|
324
416
|
const { ids } = await body(request);
|
|
325
417
|
if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id.length > 0)) throw new require_handlerErrors.HandlerBadRequestError("Bundle deletion needs ids");
|
|
@@ -464,10 +556,60 @@ const ADMIN_ROUTES = [
|
|
|
464
556
|
path: "/native-builds/:id/submission",
|
|
465
557
|
handler: "recordNativeBuildSubmission"
|
|
466
558
|
},
|
|
559
|
+
{
|
|
560
|
+
method: "POST",
|
|
561
|
+
path: "/native-builds/:id/store-build",
|
|
562
|
+
handler: "markNativeBuild"
|
|
563
|
+
},
|
|
467
564
|
{
|
|
468
565
|
method: "DELETE",
|
|
469
566
|
path: "/native-builds/:id",
|
|
470
567
|
handler: "deleteNativeBuild"
|
|
568
|
+
},
|
|
569
|
+
{
|
|
570
|
+
method: "GET",
|
|
571
|
+
path: "/ios-devices",
|
|
572
|
+
handler: "listIosDevices"
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
method: "POST",
|
|
576
|
+
path: "/ios-devices",
|
|
577
|
+
handler: "requestIosDevice"
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
method: "GET",
|
|
581
|
+
path: "/ios-devices/udid/:udid",
|
|
582
|
+
handler: "findIosDevice"
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
method: "POST",
|
|
586
|
+
path: "/ios-devices/in-build",
|
|
587
|
+
handler: "markIosDevicesInBuild"
|
|
588
|
+
},
|
|
589
|
+
{
|
|
590
|
+
method: "POST",
|
|
591
|
+
path: "/ios-devices/account",
|
|
592
|
+
handler: "claimIosDeviceAccount"
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
method: "POST",
|
|
596
|
+
path: "/ios-devices/:id/approval",
|
|
597
|
+
handler: "approveIosDevice"
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
method: "POST",
|
|
601
|
+
path: "/ios-devices/:id/outcome",
|
|
602
|
+
handler: "recordIosDeviceOutcome"
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
method: "PATCH",
|
|
606
|
+
path: "/ios-devices/:id",
|
|
607
|
+
handler: "renameIosDevice"
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
method: "DELETE",
|
|
611
|
+
path: "/ios-devices/:id",
|
|
612
|
+
handler: "deleteIosDevice"
|
|
471
613
|
}
|
|
472
614
|
];
|
|
473
615
|
//#endregion
|