@hot-updater/server 1.2.0-rc.5 → 1.2.0-rc.50
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/adapters/drizzle.cjs +8 -4
- package/dist/adapters/drizzle.d.cts +3 -2
- package/dist/adapters/drizzle.d.mts +3 -2
- package/dist/adapters/drizzle.mjs +8 -4
- package/dist/adapters/drizzleExecutor.cjs +4 -2
- package/dist/adapters/drizzleExecutor.mjs +4 -2
- package/dist/adapters/kysely.cjs +3 -2
- package/dist/adapters/kysely.mjs +3 -2
- package/dist/adapters/mongodb.cjs +1 -1
- package/dist/adapters/mongodb.mjs +1 -1
- package/dist/adapters/mongodbAdapter.cjs +15 -3
- package/dist/adapters/mongodbAdapter.mjs +15 -3
- package/dist/adapters/prisma.cjs +9 -13
- package/dist/adapters/prisma.mjs +10 -14
- package/dist/adapters/prismaExecutor.cjs +25 -20
- package/dist/adapters/prismaExecutor.mjs +25 -20
- package/dist/core/api.cjs +2 -0
- package/dist/core/api.d.cts +39 -1
- package/dist/core/api.d.mts +39 -1
- package/dist/core/api.mjs +2 -0
- package/dist/core/iosDevices.cjs +306 -0
- package/dist/core/iosDevices.mjs +303 -0
- package/dist/core/nativeBuildDestinations.cjs +13 -0
- package/dist/core/nativeBuildDestinations.mjs +13 -0
- package/dist/core/nativeBuilds.cjs +291 -22
- package/dist/core/nativeBuilds.mjs +291 -23
- package/dist/core/operations.cjs +8 -22
- package/dist/core/operations.mjs +11 -25
- package/dist/core/reads.cjs +44 -4
- package/dist/core/reads.mjs +44 -4
- package/dist/core/releases.cjs +78 -26
- package/dist/core/releases.mjs +79 -29
- 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/db/engineDrizzleSchema.cjs +21 -5
- package/dist/db/engineDrizzleSchema.mjs +21 -6
- package/dist/db/enginePrismaSchema.cjs +6 -14
- package/dist/db/enginePrismaSchema.mjs +7 -15
- package/dist/db/releaseCatalog.cjs +13 -4
- package/dist/db/releaseCatalog.mjs +12 -5
- package/dist/handlerAdminRoutes.cjs +254 -16
- package/dist/handlerAdminRoutes.mjs +255 -17
- package/dist/handlerReleaseCatalogRoutes.cjs +43 -27
- package/dist/handlerReleaseCatalogRoutes.mjs +43 -27
- 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,27 @@ 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}$`);
|
|
29
|
+
/**
|
|
30
|
+
* A bundle identifier or application ID, as an artifact reports it: letters,
|
|
31
|
+
* digits, dots, dashes and underscores, which a scope key holds as they are.
|
|
32
|
+
*/
|
|
33
|
+
const APP_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,254}$/;
|
|
34
|
+
/** A fingerprint hash as a Release Catalog scope key holds it. */
|
|
35
|
+
const FINGERPRINT_HASH = /^[A-Za-z0-9._~-]{1,255}$/;
|
|
36
|
+
/** How each kind of artifact can install. */
|
|
37
|
+
const DISTRIBUTIONS = {
|
|
38
|
+
apk: ["direct"],
|
|
39
|
+
app: ["direct"],
|
|
40
|
+
aab: ["store"],
|
|
41
|
+
ipa: ["direct", "store"]
|
|
42
|
+
};
|
|
21
43
|
/** A native build or scope core cannot store or look up: the caller's input. */
|
|
22
44
|
var NativeBuildInputError = class extends TypeError {
|
|
23
45
|
name = "NativeBuildInputError";
|
|
@@ -39,24 +61,73 @@ const pick = (row) => ({
|
|
|
39
61
|
build_number: row.build_number ?? null,
|
|
40
62
|
submitted_to: row.submitted_to ?? null,
|
|
41
63
|
submitted_at_ms: row.submitted_at_ms ?? null,
|
|
42
|
-
submitted_version: row.submitted_version ?? null
|
|
64
|
+
submitted_version: row.submitted_version ?? null,
|
|
65
|
+
is_store_build: row.is_store_build === true,
|
|
66
|
+
is_sandbox: row.is_sandbox === true,
|
|
67
|
+
sandbox_url_scheme: row.sandbox_url_scheme ?? null,
|
|
68
|
+
export_method: row.export_method ?? null,
|
|
69
|
+
native_app_version: row.native_app_version ?? null
|
|
43
70
|
});
|
|
44
|
-
/** The
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
71
|
+
/** The export methods an `.ipa` registers with. */
|
|
72
|
+
const EXPORT_METHODS = /* @__PURE__ */ new Set([
|
|
73
|
+
"app-store",
|
|
74
|
+
"ad-hoc",
|
|
75
|
+
"development",
|
|
76
|
+
"enterprise"
|
|
77
|
+
]);
|
|
78
|
+
/**
|
|
79
|
+
* How many older builds of a scope one read takes, looking for one older than
|
|
80
|
+
* a bundle when a build made after the bundle is the newest.
|
|
81
|
+
*/
|
|
82
|
+
const OLDER_BUILDS_PAGE = 20;
|
|
83
|
+
/**
|
|
84
|
+
* How many pages of older builds that look reads before it answers null: 100
|
|
85
|
+
* builds made after the bundle in one scope, where a deploy's new bundle has
|
|
86
|
+
* none or a few registered while it deploys.
|
|
87
|
+
*/
|
|
88
|
+
const OLDER_BUILDS_PAGES = 5;
|
|
89
|
+
/** How many times a mark runs again after losing its scope's mark to another. */
|
|
90
|
+
const MARK_ATTEMPTS = 8;
|
|
49
91
|
/** `native_builds.build_number`'s bound in core's schema. */
|
|
50
92
|
const BUILD_NUMBER_MAX_LENGTH = 64;
|
|
51
93
|
/** `native_builds.submitted_version`'s bound in core's schema. */
|
|
52
94
|
const SUBMITTED_VERSION_MAX_LENGTH = 255;
|
|
95
|
+
const checkedScopeKey = (scopeKey) => {
|
|
96
|
+
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.`);
|
|
97
|
+
return scopeKey;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* How a registered artifact installs: an `.ipa` by its export method, and
|
|
101
|
+
* `unknown` for one whose export no profile confirmed, which no lookup asks
|
|
102
|
+
* for, so it is never reused as either.
|
|
103
|
+
*/
|
|
104
|
+
const registeredDistribution = (kind, exportMethod) => kind !== "ipa" ? DISTRIBUTIONS[kind][0] : exportMethod === void 0 || exportMethod === null ? "unknown" : exportMethod === "app-store" ? "store" : "direct";
|
|
105
|
+
/**
|
|
106
|
+
* A sandbox build scope's key, which names no channel: the app ID, URL
|
|
107
|
+
* scheme, artifact kind and distribution in its place, then the fingerprint,
|
|
108
|
+
* or the app-version strategy and the exact app version. `v1:sandbox:` is no
|
|
109
|
+
* Release Catalog strategy, so it never meets a normal build's key.
|
|
110
|
+
*/
|
|
111
|
+
const sandboxScopeKey = (scope, sandbox) => {
|
|
112
|
+
const { appId, urlScheme, artifactKind, distribution } = sandbox;
|
|
113
|
+
const problem = typeof appId !== "string" || !APP_ID.test(appId) ? "its app ID must be a bundle identifier or application ID, up to 255 characters" : typeof urlScheme !== "string" || !URL_SCHEME.test(urlScheme) ? `its URL scheme must be a URL scheme in lower case, up to ${SANDBOX_URL_SCHEME_MAX_LENGTH} characters` : !ARTIFACT_KINDS[scope.platform]?.includes(artifactKind) ? `its artifact kind must be one an ${scope.platform} build makes` : distribution !== "unknown" && !DISTRIBUTIONS[artifactKind].includes(distribution) ? `an .${artifactKind} doesn't install as ${String(distribution)}` : scope.fingerprintHash !== null && !FINGERPRINT_HASH.test(scope.fingerprintHash) ? "its fingerprint hash must be 1-255 URL-safe ASCII characters" : null;
|
|
114
|
+
if (problem !== null) throw new NativeBuildInputError(`Invalid sandbox build scope: ${problem}.`);
|
|
115
|
+
const target = scope.fingerprintHash === null ? `app-version:${encodeURIComponent(scope.appVersion)}` : `fingerprint:${scope.fingerprintHash}`;
|
|
116
|
+
return checkedScopeKey(`v1:sandbox:${scope.platform}:${appId}:${urlScheme}:${artifactKind}:${distribution}:${target}`);
|
|
117
|
+
};
|
|
53
118
|
/**
|
|
54
119
|
* A native build scope's key: the Release Catalog scope key of a
|
|
55
120
|
* fingerprint, or of the app-version strategy followed by the exact app
|
|
56
121
|
* version the build compiled in. One key serves both strategies, so one
|
|
57
|
-
* index finds the newest build of either.
|
|
122
|
+
* index finds the newest build of either. A sandbox scope's key names no
|
|
123
|
+
* channel, so pull requests find a sandbox build on any.
|
|
58
124
|
*/
|
|
59
125
|
const nativeBuildScopeKey = (scope) => {
|
|
126
|
+
const { sandbox } = scope;
|
|
127
|
+
if (sandbox !== void 0 && sandbox !== null) {
|
|
128
|
+
if (sandbox.distribution !== "direct" && sandbox.distribution !== "store") throw new NativeBuildInputError("Invalid sandbox build scope: its distribution must be direct or store.");
|
|
129
|
+
return sandboxScopeKey(scope, sandbox);
|
|
130
|
+
}
|
|
60
131
|
let scopeKey;
|
|
61
132
|
try {
|
|
62
133
|
const channelKey = encodeChannelKey(scope.channel);
|
|
@@ -73,32 +144,126 @@ const nativeBuildScopeKey = (scope) => {
|
|
|
73
144
|
} catch (error) {
|
|
74
145
|
throw new NativeBuildInputError(`Invalid native build scope: ${error instanceof Error ? error.message : String(error)}.`);
|
|
75
146
|
}
|
|
76
|
-
|
|
77
|
-
|
|
147
|
+
return checkedScopeKey(scopeKey);
|
|
148
|
+
};
|
|
149
|
+
/** The channel row a registration names, or the refusal of its channel. */
|
|
150
|
+
const channelIdOf = (channel) => {
|
|
151
|
+
try {
|
|
152
|
+
return `channel:${encodeChannelKey(channel)}`;
|
|
153
|
+
} catch (error) {
|
|
154
|
+
throw new NativeBuildInputError(`Invalid native build scope: ${error instanceof Error ? error.message : String(error)}.`);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* A registration's scope key, from the registration's own facts: a sandbox
|
|
159
|
+
* build's from what its artifact says, whatever `sandbox` it names.
|
|
160
|
+
*/
|
|
161
|
+
const registrationScopeKey = (registration) => {
|
|
162
|
+
channelIdOf(registration.channel);
|
|
163
|
+
return registration.isSandbox === true ? sandboxScopeKey(registration, {
|
|
164
|
+
appId: registration.sandboxAppId,
|
|
165
|
+
urlScheme: registration.sandboxUrlScheme,
|
|
166
|
+
artifactKind: registration.artifact.kind,
|
|
167
|
+
distribution: registeredDistribution(registration.artifact.kind, registration.exportMethod)
|
|
168
|
+
}) : nativeBuildScopeKey({
|
|
169
|
+
...registration,
|
|
170
|
+
sandbox: null
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Refuses a patch from a sandbox build's built-in bundle: no deploy patches
|
|
175
|
+
* from one, so no store or test install of the app gets a patch made for a
|
|
176
|
+
* sandbox build. One unique read of the base.
|
|
177
|
+
*/
|
|
178
|
+
const refuseSandboxPatchBase = async (db, baseBundleId) => {
|
|
179
|
+
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.");
|
|
78
180
|
};
|
|
79
181
|
/** Whether `bundleId` is a native build's built-in bundle: one unique read. */
|
|
80
182
|
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 }) => {
|
|
183
|
+
const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, sandboxAppId, exportMethod, nativeAppVersion, artifact }) => {
|
|
82
184
|
if (!isUUIDv7(id)) return "id must be a UUIDv7";
|
|
83
185
|
if (!isUUIDv7(minBundleId)) return "minBundleId must be the UUIDv7 a release build compiles in";
|
|
84
186
|
if (platform !== "ios" && platform !== "android") return "platform must be ios or android";
|
|
85
187
|
if (channel.trim().length === 0) return "channel is required";
|
|
188
|
+
if (isSandbox !== void 0 && typeof isSandbox !== "boolean") return "isSandbox must be true or false";
|
|
189
|
+
if (sandboxUrlScheme !== void 0 && sandboxUrlScheme !== null) {
|
|
190
|
+
if (isSandbox !== true) return "sandboxUrlScheme is a sandbox build's, and this isn't one";
|
|
191
|
+
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`;
|
|
192
|
+
}
|
|
193
|
+
if (sandboxAppId !== void 0 && sandboxAppId !== null) {
|
|
194
|
+
if (isSandbox !== true) return "sandboxAppId is a sandbox build's, and this isn't one";
|
|
195
|
+
if (typeof sandboxAppId !== "string" || !APP_ID.test(sandboxAppId)) return "sandboxAppId must be the artifact's bundle identifier or application ID, up to 255 characters";
|
|
196
|
+
}
|
|
197
|
+
if (isSandbox === true) {
|
|
198
|
+
if (sandboxUrlScheme === void 0 || sandboxUrlScheme === null) return "a sandbox build needs the sandboxUrlScheme its artifact registers";
|
|
199
|
+
if (sandboxAppId === void 0 || sandboxAppId === null) return "a sandbox build needs the sandboxAppId its artifact reports, which an older hot-updater CLI doesn't send. Upgrade the hot-updater CLI to the version that matches this server, and build again";
|
|
200
|
+
}
|
|
86
201
|
if (gitCommitHash !== null && gitCommitHash.length > GIT_COMMIT_HASH_MAX_LENGTH) return `gitCommitHash must be at most ${GIT_COMMIT_HASH_MAX_LENGTH} characters`;
|
|
87
202
|
if (fingerprintHash === null === (appVersion === null)) return "exactly one of fingerprintHash and appVersion is required";
|
|
88
203
|
if (buildKey !== null && !BUILD_KEY.test(buildKey)) return "buildKey must be nbk1: and a SHA-256, or null";
|
|
89
204
|
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`;
|
|
205
|
+
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
206
|
const kinds = ARTIFACT_KINDS[platform];
|
|
91
207
|
if (!kinds.includes(artifact.kind)) return `artifact.kind of an ${platform} build must be ${kinds.join(" or ")}`;
|
|
208
|
+
if (exportMethod !== void 0 && exportMethod !== null) {
|
|
209
|
+
if (artifact.kind !== "ipa") return "exportMethod is an .ipa's, and this artifact isn't one";
|
|
210
|
+
if (!EXPORT_METHODS.has(exportMethod)) return `exportMethod must be ${[...EXPORT_METHODS].join(", ")}, or null`;
|
|
211
|
+
}
|
|
92
212
|
if (!Number.isSafeInteger(artifact.byteSize) || artifact.byteSize < 0) return "artifact.byteSize must be a byte count";
|
|
93
213
|
return null;
|
|
94
214
|
};
|
|
215
|
+
/** The other install target of an iOS sandbox build's native code. */
|
|
216
|
+
const SIBLING_KINDS = {
|
|
217
|
+
app: "ipa",
|
|
218
|
+
ipa: "app"
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* Whether a build is one a person installs from its file: a Simulator `.app`,
|
|
222
|
+
* or an `.ipa` exported for direct install, that no store took and that isn't
|
|
223
|
+
* the store build. One rule for a sibling and the build it is found from, so
|
|
224
|
+
* a build that shows its sibling is shown by it.
|
|
225
|
+
*/
|
|
226
|
+
const isInstallTarget = (build) => !build.is_store_build && build.submitted_to === null && (build.artifact_kind === "app" || build.artifact_kind === "ipa" && build.export_method !== null && build.export_method !== "app-store");
|
|
227
|
+
/**
|
|
228
|
+
* The scope key of the other install target of a sandbox build, from its own
|
|
229
|
+
* key's app ID and URL scheme, which hold no colon, and its row's fingerprint
|
|
230
|
+
* or app version, through `sandboxScopeKey`; null for a key it didn't make.
|
|
231
|
+
*/
|
|
232
|
+
const siblingSandboxScopeKey = (build, artifactKind) => {
|
|
233
|
+
const [version, sandbox, platform, appId, urlScheme] = build.scope_key.split(":");
|
|
234
|
+
if (version !== "v1" || sandbox !== "sandbox" || platform !== build.platform || appId === void 0 || urlScheme === void 0) return null;
|
|
235
|
+
const target = build.fingerprint_hash === null ? {
|
|
236
|
+
platform: build.platform,
|
|
237
|
+
fingerprintHash: null,
|
|
238
|
+
appVersion: build.app_version ?? ""
|
|
239
|
+
} : {
|
|
240
|
+
platform: build.platform,
|
|
241
|
+
fingerprintHash: build.fingerprint_hash,
|
|
242
|
+
appVersion: null
|
|
243
|
+
};
|
|
244
|
+
try {
|
|
245
|
+
return sandboxScopeKey(target, {
|
|
246
|
+
appId,
|
|
247
|
+
urlScheme,
|
|
248
|
+
artifactKind: build.artifact_kind,
|
|
249
|
+
distribution: registeredDistribution(build.artifact_kind, build.export_method)
|
|
250
|
+
}) === build.scope_key ? sandboxScopeKey(target, {
|
|
251
|
+
appId,
|
|
252
|
+
urlScheme,
|
|
253
|
+
artifactKind,
|
|
254
|
+
distribution: "direct"
|
|
255
|
+
}) : null;
|
|
256
|
+
} catch {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
95
260
|
/** The native build registry: core's `native_builds` and the built-in bundle rows. */
|
|
96
261
|
const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
97
262
|
async registerNativeBuild(registration) {
|
|
98
263
|
const problem = problemOf(registration);
|
|
99
264
|
if (problem !== null) throw new NativeBuildInputError(`Invalid native build: ${problem}.`);
|
|
100
|
-
const scopeKey =
|
|
101
|
-
const channelId =
|
|
265
|
+
const scopeKey = registrationScopeKey(registration);
|
|
266
|
+
const channelId = channelIdOf(registration.channel);
|
|
102
267
|
const { embeddedBundle } = registration;
|
|
103
268
|
const row = {
|
|
104
269
|
id: registration.id,
|
|
@@ -117,7 +282,12 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
117
282
|
build_number: registration.buildNumber ?? null,
|
|
118
283
|
submitted_to: null,
|
|
119
284
|
submitted_at_ms: null,
|
|
120
|
-
submitted_version: null
|
|
285
|
+
submitted_version: null,
|
|
286
|
+
is_store_build: false,
|
|
287
|
+
is_sandbox: registration.isSandbox === true,
|
|
288
|
+
sandbox_url_scheme: registration.sandboxUrlScheme ?? null,
|
|
289
|
+
export_method: registration.exportMethod ?? null,
|
|
290
|
+
native_app_version: registration.nativeAppVersion ?? null
|
|
121
291
|
};
|
|
122
292
|
for (let attempt = 1;; attempt += 1) {
|
|
123
293
|
await insertChannel(db, {
|
|
@@ -151,25 +321,82 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
151
321
|
const row = await db.findOne("native_builds", { id });
|
|
152
322
|
return row === null ? null : pick(row);
|
|
153
323
|
},
|
|
324
|
+
async findNativeBuildByBuiltInBundle(bundleId) {
|
|
325
|
+
const row = await db.findOne("native_builds", { min_bundle_id: bundleId });
|
|
326
|
+
return row === null ? null : pick(row);
|
|
327
|
+
},
|
|
154
328
|
async findNativeBuild(scope, options) {
|
|
155
329
|
const scopeKey = nativeBuildScopeKey(scope);
|
|
156
330
|
const buildKey = options?.buildKey;
|
|
157
331
|
if (buildKey !== void 0 && !BUILD_KEY.test(buildKey)) throw new NativeBuildInputError("Invalid native build key: it must be nbk1: and a SHA-256.");
|
|
158
|
-
const
|
|
332
|
+
const artifactKind = options?.artifactKind;
|
|
333
|
+
if (artifactKind !== void 0 && !ARTIFACT_KINDS[scope.platform].includes(artifactKind)) throw new NativeBuildInputError(`Invalid native build kind: an ${scope.platform} build is ${ARTIFACT_KINDS[scope.platform].join(" or ")}.`);
|
|
334
|
+
const ofKind = (row) => artifactKind === void 0 || row.artifact_kind === artifactKind;
|
|
335
|
+
if (options?.storeBuild) {
|
|
336
|
+
const marked = await db.findOne("native_builds", { store_build_scope_key: scopeKey });
|
|
337
|
+
return marked === null || !ofKind(marked) ? null : pick(marked);
|
|
338
|
+
}
|
|
339
|
+
const read = (limit, before) => {
|
|
340
|
+
const page = {
|
|
341
|
+
order: "desc",
|
|
342
|
+
limit,
|
|
343
|
+
...before === void 0 ? {} : { range: { lt: before } }
|
|
344
|
+
};
|
|
345
|
+
return buildKey !== void 0 ? db.findMany("native_builds", {
|
|
346
|
+
index: "byBuildKey",
|
|
347
|
+
where: {
|
|
348
|
+
scope_key: scopeKey,
|
|
349
|
+
build_key: buildKey
|
|
350
|
+
},
|
|
351
|
+
...page
|
|
352
|
+
}) : artifactKind !== void 0 ? db.findMany("native_builds", {
|
|
353
|
+
index: "byScopeKind",
|
|
354
|
+
where: {
|
|
355
|
+
scope_key: scopeKey,
|
|
356
|
+
artifact_kind: artifactKind
|
|
357
|
+
},
|
|
358
|
+
...page
|
|
359
|
+
}) : db.findMany("native_builds", {
|
|
360
|
+
index: "byScope",
|
|
361
|
+
where: { scope_key: scopeKey },
|
|
362
|
+
...page
|
|
363
|
+
});
|
|
364
|
+
};
|
|
365
|
+
const bundleId = options?.builtInOlderThan;
|
|
366
|
+
if (bundleId !== void 0 && scope.sandbox !== void 0 && scope.sandbox !== null) return null;
|
|
367
|
+
const { rows } = await read(1);
|
|
368
|
+
const newest = (rows[0] === void 0 ? void 0 : pick(rows[0])) ?? (artifactKind !== void 0 && buildKey === void 0 ? await db.findMany("native_builds", {
|
|
159
369
|
index: "byScope",
|
|
160
370
|
where: { scope_key: scopeKey },
|
|
161
371
|
order: "desc",
|
|
162
372
|
limit: 1
|
|
163
|
-
}) :
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
},
|
|
373
|
+
}).then(({ rows: [row] }) => row?.artifact_kind === artifactKind ? pick(row) : void 0) : void 0);
|
|
374
|
+
if (newest === void 0 || !ofKind(newest)) return null;
|
|
375
|
+
if (bundleId === void 0 || newest.min_bundle_id < bundleId) return newest;
|
|
376
|
+
let before = newest.id;
|
|
377
|
+
for (let page = 0; page < OLDER_BUILDS_PAGES; page += 1) {
|
|
378
|
+
const { rows: older } = await read(OLDER_BUILDS_PAGE, before);
|
|
379
|
+
const usable = older.find(({ min_bundle_id }) => min_bundle_id < bundleId);
|
|
380
|
+
if (usable !== void 0) return ofKind(usable) ? pick(usable) : null;
|
|
381
|
+
const last = older.at(-1);
|
|
382
|
+
if (older.length < OLDER_BUILDS_PAGE || last === void 0) return null;
|
|
383
|
+
before = last.id;
|
|
384
|
+
}
|
|
385
|
+
return null;
|
|
386
|
+
},
|
|
387
|
+
async findNativeBuildSibling(build) {
|
|
388
|
+
const artifactKind = SIBLING_KINDS[build.artifact_kind];
|
|
389
|
+
if (build.platform !== "ios" || !build.is_sandbox || artifactKind === void 0 || !isInstallTarget(build)) return null;
|
|
390
|
+
const scopeKey = siblingSandboxScopeKey(build, artifactKind);
|
|
391
|
+
if (scopeKey === null) return null;
|
|
392
|
+
const { rows } = await db.findMany("native_builds", {
|
|
393
|
+
index: "byScope",
|
|
394
|
+
where: { scope_key: scopeKey },
|
|
169
395
|
order: "desc",
|
|
170
396
|
limit: 1
|
|
171
397
|
});
|
|
172
|
-
|
|
398
|
+
const sibling = rows[0] === void 0 ? null : pick(rows[0]);
|
|
399
|
+
return sibling !== null && isInstallTarget(sibling) ? sibling : null;
|
|
173
400
|
},
|
|
174
401
|
async recordNativeBuildSubmission(id, { destination, version }) {
|
|
175
402
|
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 +404,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
177
404
|
const row = await tx.findOne("native_builds", { id });
|
|
178
405
|
if (row === null) return null;
|
|
179
406
|
const build = pick(row);
|
|
180
|
-
if (
|
|
407
|
+
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}.`);
|
|
408
|
+
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
409
|
const set = {
|
|
182
410
|
submitted_to: destination,
|
|
183
411
|
submitted_at_ms: now(),
|
|
@@ -190,6 +418,46 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
190
418
|
};
|
|
191
419
|
});
|
|
192
420
|
},
|
|
421
|
+
async markNativeBuild(id, { storeBuild }) {
|
|
422
|
+
for (let attempt = 1;; attempt += 1) try {
|
|
423
|
+
return await db.transaction(async (tx) => {
|
|
424
|
+
const row = await tx.findOne("native_builds", { id });
|
|
425
|
+
if (row === null) return null;
|
|
426
|
+
const build = pick(row);
|
|
427
|
+
if (!storeBuild) {
|
|
428
|
+
if (build.is_store_build) tx.update("native_builds", row, { is_store_build: false });
|
|
429
|
+
return {
|
|
430
|
+
nativeBuild: {
|
|
431
|
+
...build,
|
|
432
|
+
is_store_build: false
|
|
433
|
+
},
|
|
434
|
+
previous: null
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
if (build.is_sandbox) throw new NativeBuildInputError("A sandbox build can't be the store build.");
|
|
438
|
+
if (build.is_store_build) return {
|
|
439
|
+
nativeBuild: build,
|
|
440
|
+
previous: null
|
|
441
|
+
};
|
|
442
|
+
const holder = await tx.findOne("native_builds", { store_build_scope_key: build.scope_key });
|
|
443
|
+
if (holder !== null) tx.update("native_builds", holder, { is_store_build: false });
|
|
444
|
+
tx.update("native_builds", row, { is_store_build: true });
|
|
445
|
+
return {
|
|
446
|
+
nativeBuild: {
|
|
447
|
+
...build,
|
|
448
|
+
is_store_build: true
|
|
449
|
+
},
|
|
450
|
+
previous: holder === null ? null : {
|
|
451
|
+
...pick(holder),
|
|
452
|
+
is_store_build: false
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
});
|
|
456
|
+
} catch (error) {
|
|
457
|
+
if (attempt < MARK_ATTEMPTS && error instanceof DatabaseConstraintError && error.reason === "unique") continue;
|
|
458
|
+
throw error;
|
|
459
|
+
}
|
|
460
|
+
},
|
|
193
461
|
async deleteNativeBuild(id) {
|
|
194
462
|
return db.transaction(async (tx) => {
|
|
195
463
|
const row = await tx.findOne("native_builds", { id });
|
|
@@ -226,4 +494,4 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
226
494
|
}
|
|
227
495
|
});
|
|
228
496
|
//#endregion
|
|
229
|
-
export { NativeBuildInputError, createNativeBuildApi, isBuiltInBundle, nativeBuildScopeKey };
|
|
497
|
+
export { NativeBuildInputError, createNativeBuildApi, isBuiltInBundle, nativeBuildScopeKey, refuseSandboxPatchBase };
|
package/dist/core/operations.cjs
CHANGED
|
@@ -93,14 +93,7 @@ const mutationResult = ({ catalog, release }) => ({
|
|
|
93
93
|
const catalogScope = async (tx, scopeKey) => {
|
|
94
94
|
const row = await tx.findOne("release_catalogs", { scope_key: scopeKey });
|
|
95
95
|
if (row === null) throw new Error(`Release catalog "${scopeKey}" was not found.`);
|
|
96
|
-
return
|
|
97
|
-
channelId: row.channel_id,
|
|
98
|
-
channelName: (0, _hot_updater_protocol.decodeChannelKey)(row.channel_key),
|
|
99
|
-
fingerprintHash: row.fingerprint_hash,
|
|
100
|
-
platform: row.platform,
|
|
101
|
-
scopeKey: row.scope_key,
|
|
102
|
-
strategy: row.strategy
|
|
103
|
-
};
|
|
96
|
+
return require_releases.catalogRowScope(require_reads.toCatalogRow(row));
|
|
104
97
|
};
|
|
105
98
|
/**
|
|
106
99
|
* Core's typed writes: each runs in one engine transaction rooted at the
|
|
@@ -129,7 +122,11 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
129
122
|
for (const { release } of deployments) if (!channels.has(release.channel)) channels.set(release.channel, await ensureChannel(release.channel));
|
|
130
123
|
const platforms = /* @__PURE__ */ new Map();
|
|
131
124
|
for (const deployment of deployments) {
|
|
132
|
-
if (!("bundleId" in deployment)
|
|
125
|
+
if (!("bundleId" in deployment)) {
|
|
126
|
+
for (const { baseBundleId } of deployment.bundle.patches ?? []) await require_nativeBuilds.refuseSandboxPatchBase(db, baseBundleId);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (platforms.has(deployment.bundleId)) continue;
|
|
133
130
|
const row = await db.findOne("bundles", { id: deployment.bundleId });
|
|
134
131
|
if (row === null) throw new _hot_updater_plugin_core.DatabaseBundleNotFoundError(deployment.bundleId);
|
|
135
132
|
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.`);
|
|
@@ -304,18 +301,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
304
301
|
};
|
|
305
302
|
});
|
|
306
303
|
},
|
|
307
|
-
preflightReleaseCatalogRebuild: (scopeKey) =>
|
|
308
|
-
const updatedAtMs = now();
|
|
309
|
-
return dryRun(db, async (tx) => {
|
|
310
|
-
const rebuilt = await require_releases.rebuildScope(tx, await catalogScope(tx, scopeKey), updatedAtMs);
|
|
311
|
-
return {
|
|
312
|
-
changed: rebuilt.changed,
|
|
313
|
-
currentCatalog: rebuilt.current,
|
|
314
|
-
diagnostics: rebuilt.diagnostics,
|
|
315
|
-
projectedCatalog: rebuilt.catalog
|
|
316
|
-
};
|
|
317
|
-
});
|
|
318
|
-
},
|
|
304
|
+
preflightReleaseCatalogRebuild: (scopeKey) => require_releases.preflightRebuild(db, scopeKey, now()),
|
|
319
305
|
ensureChannel,
|
|
320
306
|
deleteChannel: (id) => require_writes.deleteChannel(db, id),
|
|
321
307
|
updateBundle: (id, update) => db.transaction(async (tx) => {
|
|
@@ -333,7 +319,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
333
319
|
if (patches !== void 0) await require_writes.replaceBundlePatches(tx, current, (0, _hot_updater_plugin_core.bundleToPatchRows)({
|
|
334
320
|
...next,
|
|
335
321
|
patches
|
|
336
|
-
}));
|
|
322
|
+
}), (row) => require_nativeBuilds.refuseSandboxPatchBase(tx, row.base_bundle_id));
|
|
337
323
|
}),
|
|
338
324
|
deleteBundles: async (ids) => {
|
|
339
325
|
try {
|
package/dist/core/operations.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { toBundleRow, toReleaseRow } from "./reads.mjs";
|
|
1
|
+
import { toBundleRow, toCatalogRow, toReleaseRow } from "./reads.mjs";
|
|
2
2
|
import { deleteBundle, deleteChannel, insertChannel, replaceBundlePatches, updateBundle } from "./writes.mjs";
|
|
3
|
-
import { isBuiltInBundle } from "./nativeBuilds.mjs";
|
|
4
|
-
import { changeRelease, changeReleases, readCatalog, rebuildScope } from "./releases.mjs";
|
|
3
|
+
import { isBuiltInBundle, refuseSandboxPatchBase } from "./nativeBuilds.mjs";
|
|
4
|
+
import { catalogRowScope, changeRelease, changeReleases, preflightRebuild, 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";
|
|
7
7
|
//#region src/core/operations.ts
|
|
@@ -93,14 +93,7 @@ const mutationResult = ({ catalog, release }) => ({
|
|
|
93
93
|
const catalogScope = async (tx, scopeKey) => {
|
|
94
94
|
const row = await tx.findOne("release_catalogs", { scope_key: scopeKey });
|
|
95
95
|
if (row === null) throw new Error(`Release catalog "${scopeKey}" was not found.`);
|
|
96
|
-
return
|
|
97
|
-
channelId: row.channel_id,
|
|
98
|
-
channelName: decodeChannelKey(row.channel_key),
|
|
99
|
-
fingerprintHash: row.fingerprint_hash,
|
|
100
|
-
platform: row.platform,
|
|
101
|
-
scopeKey: row.scope_key,
|
|
102
|
-
strategy: row.strategy
|
|
103
|
-
};
|
|
96
|
+
return catalogRowScope(toCatalogRow(row));
|
|
104
97
|
};
|
|
105
98
|
/**
|
|
106
99
|
* Core's typed writes: each runs in one engine transaction rooted at the
|
|
@@ -129,7 +122,11 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
129
122
|
for (const { release } of deployments) if (!channels.has(release.channel)) channels.set(release.channel, await ensureChannel(release.channel));
|
|
130
123
|
const platforms = /* @__PURE__ */ new Map();
|
|
131
124
|
for (const deployment of deployments) {
|
|
132
|
-
if (!("bundleId" in deployment)
|
|
125
|
+
if (!("bundleId" in deployment)) {
|
|
126
|
+
for (const { baseBundleId } of deployment.bundle.patches ?? []) await refuseSandboxPatchBase(db, baseBundleId);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (platforms.has(deployment.bundleId)) continue;
|
|
133
130
|
const row = await db.findOne("bundles", { id: deployment.bundleId });
|
|
134
131
|
if (row === null) throw new DatabaseBundleNotFoundError(deployment.bundleId);
|
|
135
132
|
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.`);
|
|
@@ -304,18 +301,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
304
301
|
};
|
|
305
302
|
});
|
|
306
303
|
},
|
|
307
|
-
preflightReleaseCatalogRebuild: (scopeKey) =>
|
|
308
|
-
const updatedAtMs = now();
|
|
309
|
-
return dryRun(db, async (tx) => {
|
|
310
|
-
const rebuilt = await rebuildScope(tx, await catalogScope(tx, scopeKey), updatedAtMs);
|
|
311
|
-
return {
|
|
312
|
-
changed: rebuilt.changed,
|
|
313
|
-
currentCatalog: rebuilt.current,
|
|
314
|
-
diagnostics: rebuilt.diagnostics,
|
|
315
|
-
projectedCatalog: rebuilt.catalog
|
|
316
|
-
};
|
|
317
|
-
});
|
|
318
|
-
},
|
|
304
|
+
preflightReleaseCatalogRebuild: (scopeKey) => preflightRebuild(db, scopeKey, now()),
|
|
319
305
|
ensureChannel,
|
|
320
306
|
deleteChannel: (id) => deleteChannel(db, id),
|
|
321
307
|
updateBundle: (id, update) => db.transaction(async (tx) => {
|
|
@@ -333,7 +319,7 @@ const createCoreOperations = (db, { now = Date.now } = {}) => {
|
|
|
333
319
|
if (patches !== void 0) await replaceBundlePatches(tx, current, bundleToPatchRows({
|
|
334
320
|
...next,
|
|
335
321
|
patches
|
|
336
|
-
}));
|
|
322
|
+
}), (row) => refuseSandboxPatchBase(tx, row.base_bundle_id));
|
|
337
323
|
}),
|
|
338
324
|
deleteBundles: async (ids) => {
|
|
339
325
|
try {
|
package/dist/core/reads.cjs
CHANGED
|
@@ -74,8 +74,16 @@ 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
|
-
|
|
78
|
-
|
|
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
|
+
};
|
|
86
|
+
/** Core's reads, each through one declared index or key; plugins get `CoreReads`. */
|
|
79
87
|
const createCoreReads = (db, storage) => {
|
|
80
88
|
/** A bundle row's patches, exactly as many as its reference counter holds. */
|
|
81
89
|
const detail = async (row) => {
|
|
@@ -263,8 +271,35 @@ const createCoreReads = (db, storage) => {
|
|
|
263
271
|
...after(input)
|
|
264
272
|
})).rows.map(toCatalogRow);
|
|
265
273
|
},
|
|
266
|
-
/**
|
|
267
|
-
|
|
274
|
+
/**
|
|
275
|
+
* Up to `limit` scope keys that have releases, ascending after `after`:
|
|
276
|
+
* one limit-1 seek of the `scopes` index past each scope, so the reads
|
|
277
|
+
* grow with the scopes, not with their releases.
|
|
278
|
+
*/
|
|
279
|
+
async listReleaseScopeKeys(input) {
|
|
280
|
+
const scopeKeys = [];
|
|
281
|
+
for (let last = input.after ?? ""; scopeKeys.length < input.limit;) {
|
|
282
|
+
const { rows } = await db.findMany("releases", {
|
|
283
|
+
index: "scopes",
|
|
284
|
+
where: {},
|
|
285
|
+
limit: 1,
|
|
286
|
+
range: { gt: last }
|
|
287
|
+
});
|
|
288
|
+
if (rows[0] === void 0) break;
|
|
289
|
+
last = rows[0].scope_key;
|
|
290
|
+
scopeKeys.push(last);
|
|
291
|
+
}
|
|
292
|
+
return scopeKeys;
|
|
293
|
+
},
|
|
294
|
+
/** Every channel by name; with `input`, one keyset page of them. */
|
|
295
|
+
async listChannels(input) {
|
|
296
|
+
if (input !== void 0) return (await db.findMany("channels", {
|
|
297
|
+
index: "all",
|
|
298
|
+
where: {},
|
|
299
|
+
order: input.order ?? "asc",
|
|
300
|
+
limit: input.limit,
|
|
301
|
+
...after(input)
|
|
302
|
+
})).rows.map(toChannelRow);
|
|
268
303
|
return (await drain((page) => db.findMany("channels", {
|
|
269
304
|
index: "all",
|
|
270
305
|
where: {},
|
|
@@ -272,6 +307,11 @@ const createCoreReads = (db, storage) => {
|
|
|
272
307
|
...page
|
|
273
308
|
}))).map(toChannelRow);
|
|
274
309
|
},
|
|
310
|
+
async getChannels(ids) {
|
|
311
|
+
const unique = [...new Set(ids)];
|
|
312
|
+
if (unique.length === 0) return [];
|
|
313
|
+
return (await db.findByKeys("channels", unique.map((id) => ({ id })))).flatMap((row) => row ? [toChannelRow(row)] : []);
|
|
314
|
+
},
|
|
275
315
|
async findChannelByName(name) {
|
|
276
316
|
const row = await db.findOne("channels", { name });
|
|
277
317
|
return row === null ? null : toChannelRow(row);
|