@hot-updater/server 1.2.0-rc.27 → 1.2.0-rc.28
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 +24 -0
- package/dist/core/api.d.mts +24 -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/nativeBuilds.cjs +17 -4
- package/dist/core/nativeBuilds.mjs +17 -4
- package/dist/core/reads.cjs +9 -1
- package/dist/core/reads.mjs +9 -1
- package/dist/handlerAdminRoutes.cjs +126 -3
- package/dist/handlerAdminRoutes.mjs +126 -3
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/package.json +6 -6
package/dist/core/api.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_reads = require("./reads.cjs");
|
|
2
|
+
const require_iosDevices = require("./iosDevices.cjs");
|
|
2
3
|
const require_nativeBuilds = require("./nativeBuilds.cjs");
|
|
3
4
|
const require_operations = require("./operations.cjs");
|
|
4
5
|
//#region src/core/api.ts
|
|
@@ -43,6 +44,7 @@ const createCoreApi = (db, storage, options = {}) => {
|
|
|
43
44
|
...reads,
|
|
44
45
|
...require_operations.createCoreOperations(purgingCachedRoutes(db, options.onCachedRoutesChange), options),
|
|
45
46
|
...require_nativeBuilds.createNativeBuildApi(db, options),
|
|
47
|
+
...require_iosDevices.createIosDeviceApi(db, options),
|
|
46
48
|
/** One read, which checks the schema settings first. */
|
|
47
49
|
ready: async () => {
|
|
48
50
|
await reads.listReleaseCatalogs({ limit: 1 });
|
package/dist/core/api.d.cts
CHANGED
|
@@ -9,6 +9,30 @@ interface CoreApiOptions {
|
|
|
9
9
|
declare const createCoreApi: (db: CoreDatabase, storage: CoreStorage, options?: CoreApiOptions) => {
|
|
10
10
|
/** One read, which checks the schema settings first. */
|
|
11
11
|
ready: () => Promise<void>;
|
|
12
|
+
listIosDevices: (input: import("@hot-updater/plugin-core").KeysetInput & {
|
|
13
|
+
readonly status?: import("@hot-updater/plugin-core").IosDeviceStatus;
|
|
14
|
+
}) => Promise<import("@hot-updater/plugin-core").IosDeviceRow[]>;
|
|
15
|
+
findIosDevice: (udid: string) => Promise<import("@hot-updater/plugin-core").IosDeviceRow | null>;
|
|
16
|
+
requestIosDevice: (input: {
|
|
17
|
+
readonly udid: string;
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly requestedBy: string | null;
|
|
20
|
+
}) => Promise<import("@hot-updater/plugin-core").IosDeviceRequestResult>;
|
|
21
|
+
approveIosDevice: (id: string, input: {
|
|
22
|
+
readonly name?: string;
|
|
23
|
+
readonly approvedBy: string | null;
|
|
24
|
+
}) => Promise<import("@hot-updater/plugin-core").IosDeviceRow | null>;
|
|
25
|
+
renameIosDevice: (id: string, name: string) => Promise<import("@hot-updater/plugin-core").IosDeviceRow | null>;
|
|
26
|
+
recordIosDeviceOutcome: (input: import("@hot-updater/plugin-core").IosDeviceOutcomeInput) => Promise<import("@hot-updater/plugin-core").IosDeviceRow | null>;
|
|
27
|
+
markIosDevicesInBuild: (input: {
|
|
28
|
+
readonly buildId: string;
|
|
29
|
+
readonly ids: readonly string[];
|
|
30
|
+
}) => Promise<void>;
|
|
31
|
+
deleteIosDevice: (id: string, only?: {
|
|
32
|
+
readonly status?: import("@hot-updater/plugin-core").IosDeviceStatus;
|
|
33
|
+
readonly requestedBy?: string;
|
|
34
|
+
}) => Promise<import("@hot-updater/plugin-core").IosDeviceRow | null>;
|
|
35
|
+
claimIosDeviceAccount: (issuerId: string) => Promise<import("@hot-updater/plugin-core").IosDeviceAccountClaim>;
|
|
12
36
|
registerNativeBuild: (registration: import("@hot-updater/plugin-core").NativeBuildRegistration) => Promise<import("@hot-updater/plugin-core").NativeBuildRow>;
|
|
13
37
|
getNativeBuild: (id: string) => Promise<import("@hot-updater/plugin-core").NativeBuildRow | null>;
|
|
14
38
|
findNativeBuild: (scope: import("@hot-updater/plugin-core").NativeBuildScope, options?: {
|
package/dist/core/api.d.mts
CHANGED
|
@@ -9,6 +9,30 @@ interface CoreApiOptions {
|
|
|
9
9
|
declare const createCoreApi: (db: CoreDatabase, storage: CoreStorage, options?: CoreApiOptions) => {
|
|
10
10
|
/** One read, which checks the schema settings first. */
|
|
11
11
|
ready: () => Promise<void>;
|
|
12
|
+
listIosDevices: (input: import("@hot-updater/plugin-core").KeysetInput & {
|
|
13
|
+
readonly status?: import("@hot-updater/plugin-core").IosDeviceStatus;
|
|
14
|
+
}) => Promise<import("@hot-updater/plugin-core").IosDeviceRow[]>;
|
|
15
|
+
findIosDevice: (udid: string) => Promise<import("@hot-updater/plugin-core").IosDeviceRow | null>;
|
|
16
|
+
requestIosDevice: (input: {
|
|
17
|
+
readonly udid: string;
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly requestedBy: string | null;
|
|
20
|
+
}) => Promise<import("@hot-updater/plugin-core").IosDeviceRequestResult>;
|
|
21
|
+
approveIosDevice: (id: string, input: {
|
|
22
|
+
readonly name?: string;
|
|
23
|
+
readonly approvedBy: string | null;
|
|
24
|
+
}) => Promise<import("@hot-updater/plugin-core").IosDeviceRow | null>;
|
|
25
|
+
renameIosDevice: (id: string, name: string) => Promise<import("@hot-updater/plugin-core").IosDeviceRow | null>;
|
|
26
|
+
recordIosDeviceOutcome: (input: import("@hot-updater/plugin-core").IosDeviceOutcomeInput) => Promise<import("@hot-updater/plugin-core").IosDeviceRow | null>;
|
|
27
|
+
markIosDevicesInBuild: (input: {
|
|
28
|
+
readonly buildId: string;
|
|
29
|
+
readonly ids: readonly string[];
|
|
30
|
+
}) => Promise<void>;
|
|
31
|
+
deleteIosDevice: (id: string, only?: {
|
|
32
|
+
readonly status?: import("@hot-updater/plugin-core").IosDeviceStatus;
|
|
33
|
+
readonly requestedBy?: string;
|
|
34
|
+
}) => Promise<import("@hot-updater/plugin-core").IosDeviceRow | null>;
|
|
35
|
+
claimIosDeviceAccount: (issuerId: string) => Promise<import("@hot-updater/plugin-core").IosDeviceAccountClaim>;
|
|
12
36
|
registerNativeBuild: (registration: import("@hot-updater/plugin-core").NativeBuildRegistration) => Promise<import("@hot-updater/plugin-core").NativeBuildRow>;
|
|
13
37
|
getNativeBuild: (id: string) => Promise<import("@hot-updater/plugin-core").NativeBuildRow | null>;
|
|
14
38
|
findNativeBuild: (scope: import("@hot-updater/plugin-core").NativeBuildScope, options?: {
|
package/dist/core/api.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createCoreReads } from "./reads.mjs";
|
|
2
|
+
import { createIosDeviceApi } from "./iosDevices.mjs";
|
|
2
3
|
import { createNativeBuildApi } from "./nativeBuilds.mjs";
|
|
3
4
|
import { createCoreOperations } from "./operations.mjs";
|
|
4
5
|
//#region src/core/api.ts
|
|
@@ -43,6 +44,7 @@ const createCoreApi = (db, storage, options = {}) => {
|
|
|
43
44
|
...reads,
|
|
44
45
|
...createCoreOperations(purgingCachedRoutes(db, options.onCachedRoutesChange), options),
|
|
45
46
|
...createNativeBuildApi(db, options),
|
|
47
|
+
...createIosDeviceApi(db, options),
|
|
46
48
|
/** One read, which checks the schema settings first. */
|
|
47
49
|
ready: async () => {
|
|
48
50
|
await reads.listReleaseCatalogs({ limit: 1 });
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
const require_reads = require("./reads.cjs");
|
|
2
|
+
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
3
|
+
//#region src/core/iosDevices.ts
|
|
4
|
+
/**
|
|
5
|
+
* A device's UDID: 40 hex digits, or 8 and 16 joined by a hyphen. The same
|
|
6
|
+
* rule as `normalizeIosUdid` of `@hot-updater/protocol/native-artifact`,
|
|
7
|
+
* implemented here so the server's runtime never loads the artifact readers.
|
|
8
|
+
*/
|
|
9
|
+
const UDID = /^(?:[0-9a-f]{40}|[0-9a-f]{8}-[0-9a-f]{16})$/iu;
|
|
10
|
+
/** The form the registry stores and compares a UDID in, or null for text that isn't one. */
|
|
11
|
+
const normalizeIosUdid = (value) => {
|
|
12
|
+
const trimmed = value.trim();
|
|
13
|
+
return UDID.test(trimmed) ? trimmed.toLowerCase() : null;
|
|
14
|
+
};
|
|
15
|
+
/** `ios_devices.name`'s bound in core's schema. */
|
|
16
|
+
const NAME_MAX_LENGTH = 100;
|
|
17
|
+
/** `ios_devices.requested_by` and `approved_by`'s bound: an email address. */
|
|
18
|
+
const EMAIL_MAX_LENGTH = 320;
|
|
19
|
+
/** `ios_devices.apple_issuer_id`'s bound. */
|
|
20
|
+
const ISSUER_MAX_LENGTH = 64;
|
|
21
|
+
/** How many registry rows one read takes while finding its account. */
|
|
22
|
+
const ACCOUNT_SCAN_PAGE = 200;
|
|
23
|
+
/** The one row of `ios_device_account`. */
|
|
24
|
+
const ACCOUNT_ROW = "registry";
|
|
25
|
+
/** `ios_devices.apple_error`'s bound. */
|
|
26
|
+
const ERROR_MAX_LENGTH = 512;
|
|
27
|
+
const STATUSES = [
|
|
28
|
+
"pending",
|
|
29
|
+
"approved",
|
|
30
|
+
"registered"
|
|
31
|
+
];
|
|
32
|
+
const OUTCOMES = [
|
|
33
|
+
"registered",
|
|
34
|
+
"refused",
|
|
35
|
+
"disabled",
|
|
36
|
+
"missing"
|
|
37
|
+
];
|
|
38
|
+
/** The `apple_error` of a device Apple has disabled. */
|
|
39
|
+
const IOS_DEVICE_DISABLED_ERROR = "Disabled in the Apple account.";
|
|
40
|
+
/** The `apple_error` of a registered device Apple no longer lists. */
|
|
41
|
+
const IOS_DEVICE_MISSING_ERROR = "Gone from the Apple account. Approve it again to register it.";
|
|
42
|
+
/** A device or registry request core cannot store: the caller's input. */
|
|
43
|
+
var IosDeviceInputError = class extends TypeError {
|
|
44
|
+
name = "IosDeviceInputError";
|
|
45
|
+
};
|
|
46
|
+
const pick = (row) => ({
|
|
47
|
+
id: row.id,
|
|
48
|
+
udid: row.udid,
|
|
49
|
+
name: row.name,
|
|
50
|
+
status: row.status,
|
|
51
|
+
requested_by: row.requested_by ?? null,
|
|
52
|
+
created_at_ms: row.created_at_ms,
|
|
53
|
+
approved_by: row.approved_by ?? null,
|
|
54
|
+
approved_at_ms: row.approved_at_ms ?? null,
|
|
55
|
+
registered_at_ms: row.registered_at_ms ?? null,
|
|
56
|
+
apple_issuer_id: row.apple_issuer_id ?? null,
|
|
57
|
+
apple_error: row.apple_error ?? null,
|
|
58
|
+
build_id: row.build_id ?? null
|
|
59
|
+
});
|
|
60
|
+
const udidOf = (udid) => {
|
|
61
|
+
const key = typeof udid === "string" ? normalizeIosUdid(udid) : null;
|
|
62
|
+
if (key === null) throw new IosDeviceInputError("Invalid iOS device: udid must be 40 hex digits, or 8 and 16 joined by a hyphen.");
|
|
63
|
+
return key;
|
|
64
|
+
};
|
|
65
|
+
const nameOf = (name) => {
|
|
66
|
+
const trimmed = typeof name === "string" ? name.trim() : "";
|
|
67
|
+
if (trimmed.length === 0 || trimmed.length > NAME_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device: name must be 1 to ${NAME_MAX_LENGTH} characters.`);
|
|
68
|
+
return trimmed;
|
|
69
|
+
};
|
|
70
|
+
/** An email, lower-cased, or null for the CLI. */
|
|
71
|
+
const personOf = (value, field) => {
|
|
72
|
+
if (value === null) return null;
|
|
73
|
+
const email = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
74
|
+
if (email.length === 0 || email.length > EMAIL_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device: ${field} must be an email of at most ${EMAIL_MAX_LENGTH} characters, or null.`);
|
|
75
|
+
return email;
|
|
76
|
+
};
|
|
77
|
+
/** Apple's words, on one line and within the column's bound. */
|
|
78
|
+
const errorText = (text) => {
|
|
79
|
+
const line = text.replace(/\s+/gu, " ").trim();
|
|
80
|
+
return line.length > ERROR_MAX_LENGTH ? `${line.slice(0, 511)}…` : line;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* The iOS device registry: the iPhones and iPads a team asked to install ad hoc
|
|
84
|
+
* builds on. The Console writes requests and approvals, and the CLI what Apple
|
|
85
|
+
* said, each over the row it read.
|
|
86
|
+
*/
|
|
87
|
+
const createIosDeviceApi = (db, { now = Date.now } = {}) => {
|
|
88
|
+
const findIosDevice = async (udid) => {
|
|
89
|
+
const key = normalizeIosUdid(udid);
|
|
90
|
+
if (key === null) return null;
|
|
91
|
+
const row = await db.findOne("ios_devices", { udid: key });
|
|
92
|
+
return row === null ? null : pick(row);
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* The issuer of the registry's earliest registration among its rows, by
|
|
96
|
+
* when and then by ID, or null when no row names one: read only while the
|
|
97
|
+
* registry has no account yet, a page at a time.
|
|
98
|
+
*/
|
|
99
|
+
const accountOfRows = async () => {
|
|
100
|
+
let earliest = null;
|
|
101
|
+
for (let after;;) {
|
|
102
|
+
const { rows } = await db.findMany("ios_devices", {
|
|
103
|
+
index: "all",
|
|
104
|
+
where: {},
|
|
105
|
+
order: "asc",
|
|
106
|
+
limit: ACCOUNT_SCAN_PAGE,
|
|
107
|
+
...after === void 0 ? {} : { range: { gt: after } }
|
|
108
|
+
});
|
|
109
|
+
for (const row of rows.map(pick)) {
|
|
110
|
+
if (row.apple_issuer_id === null) continue;
|
|
111
|
+
if (earliest === null || (row.registered_at_ms ?? 0) < (earliest.registered_at_ms ?? 0)) earliest = row;
|
|
112
|
+
}
|
|
113
|
+
if (rows.length < ACCOUNT_SCAN_PAGE) return earliest?.apple_issuer_id ?? null;
|
|
114
|
+
after = rows.at(-1).id;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
async listIosDevices(input) {
|
|
119
|
+
if (input.status !== void 0 && !STATUSES.includes(input.status)) throw new IosDeviceInputError(`Invalid iOS device status: ${String(input.status)}. Expected ${STATUSES.join(", ")}.`);
|
|
120
|
+
const page = {
|
|
121
|
+
order: input.order ?? "asc",
|
|
122
|
+
limit: input.limit,
|
|
123
|
+
...require_reads.after(input)
|
|
124
|
+
};
|
|
125
|
+
const { rows } = input.status === void 0 ? await db.findMany("ios_devices", {
|
|
126
|
+
index: "all",
|
|
127
|
+
where: {},
|
|
128
|
+
...page
|
|
129
|
+
}) : await db.findMany("ios_devices", {
|
|
130
|
+
index: "byStatus",
|
|
131
|
+
where: { status: input.status },
|
|
132
|
+
...page
|
|
133
|
+
});
|
|
134
|
+
return rows.map(pick);
|
|
135
|
+
},
|
|
136
|
+
findIosDevice,
|
|
137
|
+
async requestIosDevice(input) {
|
|
138
|
+
const udid = udidOf(input.udid);
|
|
139
|
+
const name = nameOf(input.name);
|
|
140
|
+
const requestedBy = personOf(input.requestedBy, "requestedBy");
|
|
141
|
+
const existing = await db.findOne("ios_devices", { udid });
|
|
142
|
+
if (existing !== null) return {
|
|
143
|
+
device: pick(existing),
|
|
144
|
+
created: false
|
|
145
|
+
};
|
|
146
|
+
const device = {
|
|
147
|
+
id: (0, _hot_updater_plugin_core.createUUIDv7)(),
|
|
148
|
+
udid,
|
|
149
|
+
name,
|
|
150
|
+
status: "pending",
|
|
151
|
+
requested_by: requestedBy,
|
|
152
|
+
created_at_ms: now(),
|
|
153
|
+
approved_by: null,
|
|
154
|
+
approved_at_ms: null,
|
|
155
|
+
registered_at_ms: null,
|
|
156
|
+
apple_issuer_id: null,
|
|
157
|
+
apple_error: null,
|
|
158
|
+
build_id: null
|
|
159
|
+
};
|
|
160
|
+
try {
|
|
161
|
+
await db.transaction(async (tx) => {
|
|
162
|
+
tx.create("ios_devices", device);
|
|
163
|
+
});
|
|
164
|
+
} catch (error) {
|
|
165
|
+
if (error instanceof _hot_updater_plugin_core.DatabaseConstraintError && error.reason === "unique") {
|
|
166
|
+
const winner = await db.findOne("ios_devices", { udid });
|
|
167
|
+
if (winner !== null) return {
|
|
168
|
+
device: pick(winner),
|
|
169
|
+
created: false
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
device,
|
|
176
|
+
created: true
|
|
177
|
+
};
|
|
178
|
+
},
|
|
179
|
+
async approveIosDevice(id, input) {
|
|
180
|
+
const name = input.name === void 0 ? void 0 : nameOf(input.name);
|
|
181
|
+
const approvedBy = personOf(input.approvedBy, "approvedBy");
|
|
182
|
+
return db.transaction(async (tx) => {
|
|
183
|
+
const row = await tx.findOne("ios_devices", { id });
|
|
184
|
+
if (row === null) return null;
|
|
185
|
+
const device = pick(row);
|
|
186
|
+
const set = {
|
|
187
|
+
...name === void 0 || name === device.name ? {} : { name },
|
|
188
|
+
...device.status === "pending" ? {
|
|
189
|
+
status: "approved",
|
|
190
|
+
approved_by: approvedBy,
|
|
191
|
+
approved_at_ms: now()
|
|
192
|
+
} : {}
|
|
193
|
+
};
|
|
194
|
+
if (Object.keys(set).length === 0) return device;
|
|
195
|
+
tx.update("ios_devices", row, set);
|
|
196
|
+
return {
|
|
197
|
+
...device,
|
|
198
|
+
...set
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
async renameIosDevice(id, input) {
|
|
203
|
+
const name = nameOf(input);
|
|
204
|
+
return db.transaction(async (tx) => {
|
|
205
|
+
const row = await tx.findOne("ios_devices", { id });
|
|
206
|
+
if (row === null) return null;
|
|
207
|
+
const device = pick(row);
|
|
208
|
+
if (device.name === name) return device;
|
|
209
|
+
tx.update("ios_devices", row, { name });
|
|
210
|
+
return {
|
|
211
|
+
...device,
|
|
212
|
+
name
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
async recordIosDeviceOutcome({ id, seen, issuerId, outcome, reason }) {
|
|
217
|
+
if (!OUTCOMES.includes(outcome)) throw new IosDeviceInputError(`Invalid iOS device outcome: ${String(outcome)}. Expected ${OUTCOMES.join(", ")}.`);
|
|
218
|
+
if (typeof issuerId !== "string" || issuerId.trim().length === 0 || issuerId.length > ISSUER_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device outcome: issuerId must be an App Store Connect issuer of at most ${ISSUER_MAX_LENGTH} characters.`);
|
|
219
|
+
return db.transaction(async (tx) => {
|
|
220
|
+
const row = await tx.findOne("ios_devices", { id });
|
|
221
|
+
if (row === null) return null;
|
|
222
|
+
const device = pick(row);
|
|
223
|
+
if (device.status !== seen.status || device.approved_at_ms !== seen.approvedAtMs || device.apple_issuer_id !== null && device.apple_issuer_id !== issuerId) return null;
|
|
224
|
+
let set;
|
|
225
|
+
switch (outcome) {
|
|
226
|
+
case "registered":
|
|
227
|
+
if (device.status === "pending") return null;
|
|
228
|
+
set = {
|
|
229
|
+
status: "registered",
|
|
230
|
+
registered_at_ms: device.registered_at_ms ?? now(),
|
|
231
|
+
apple_issuer_id: issuerId,
|
|
232
|
+
apple_error: null
|
|
233
|
+
};
|
|
234
|
+
break;
|
|
235
|
+
case "refused":
|
|
236
|
+
if (device.status !== "approved") return null;
|
|
237
|
+
set = { apple_error: errorText(reason === void 0 || reason.trim() === "" ? "Apple refused it." : reason) };
|
|
238
|
+
break;
|
|
239
|
+
case "disabled":
|
|
240
|
+
if (device.status === "pending") return null;
|
|
241
|
+
set = { apple_error: IOS_DEVICE_DISABLED_ERROR };
|
|
242
|
+
break;
|
|
243
|
+
case "missing":
|
|
244
|
+
if (device.status !== "registered") return null;
|
|
245
|
+
set = {
|
|
246
|
+
status: "pending",
|
|
247
|
+
approved_by: null,
|
|
248
|
+
approved_at_ms: null,
|
|
249
|
+
apple_error: IOS_DEVICE_MISSING_ERROR
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
if (Object.entries(set).some(([column, value]) => device[column] !== (value ?? null))) tx.update("ios_devices", row, set);
|
|
253
|
+
return {
|
|
254
|
+
...device,
|
|
255
|
+
...set
|
|
256
|
+
};
|
|
257
|
+
});
|
|
258
|
+
},
|
|
259
|
+
async markIosDevicesInBuild({ buildId, ids }) {
|
|
260
|
+
for (const id of new Set(ids)) await db.transaction(async (tx) => {
|
|
261
|
+
const row = await tx.findOne("ios_devices", { id });
|
|
262
|
+
if (row === null || typeof row.build_id === "string" && row.build_id >= buildId) return;
|
|
263
|
+
tx.update("ios_devices", row, { build_id: buildId });
|
|
264
|
+
});
|
|
265
|
+
},
|
|
266
|
+
async claimIosDeviceAccount(issuerId) {
|
|
267
|
+
if (typeof issuerId !== "string" || issuerId.trim().length === 0 || issuerId.length > ISSUER_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device account: issuerId must be an App Store Connect issuer of at most ${ISSUER_MAX_LENGTH} characters.`);
|
|
268
|
+
const answer = (held) => ({
|
|
269
|
+
issuerId: held,
|
|
270
|
+
claimed: held === issuerId
|
|
271
|
+
});
|
|
272
|
+
const existing = await db.findOne("ios_device_account", { id: ACCOUNT_ROW });
|
|
273
|
+
if (existing !== null) return answer(existing.apple_issuer_id);
|
|
274
|
+
const holder = await accountOfRows() ?? issuerId;
|
|
275
|
+
try {
|
|
276
|
+
await db.transaction(async (tx) => {
|
|
277
|
+
tx.create("ios_device_account", {
|
|
278
|
+
id: ACCOUNT_ROW,
|
|
279
|
+
apple_issuer_id: holder,
|
|
280
|
+
claimed_at_ms: now()
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
return answer(holder);
|
|
284
|
+
} catch (error) {
|
|
285
|
+
if (error instanceof _hot_updater_plugin_core.DatabaseConstraintError && (error.reason === "exists" || error.reason === "unique")) {
|
|
286
|
+
const winner = await db.findOne("ios_device_account", { id: ACCOUNT_ROW });
|
|
287
|
+
if (winner !== null) return answer(winner.apple_issuer_id);
|
|
288
|
+
}
|
|
289
|
+
throw error;
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
async deleteIosDevice(id, only) {
|
|
293
|
+
const requestedBy = only?.requestedBy === void 0 ? void 0 : personOf(only.requestedBy, "requestedBy");
|
|
294
|
+
return db.transaction(async (tx) => {
|
|
295
|
+
const row = await tx.findOne("ios_devices", { id });
|
|
296
|
+
if (row === null) return null;
|
|
297
|
+
const device = pick(row);
|
|
298
|
+
if (only?.status !== void 0 && device.status !== only.status || requestedBy !== void 0 && device.requested_by !== requestedBy) return null;
|
|
299
|
+
await tx.delete("ios_devices", row);
|
|
300
|
+
return device;
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
//#endregion
|
|
306
|
+
exports.IOS_DEVICE_DISABLED_ERROR = IOS_DEVICE_DISABLED_ERROR;
|
|
307
|
+
exports.IOS_DEVICE_MISSING_ERROR = IOS_DEVICE_MISSING_ERROR;
|
|
308
|
+
exports.IosDeviceInputError = IosDeviceInputError;
|
|
309
|
+
exports.createIosDeviceApi = createIosDeviceApi;
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { after } from "./reads.mjs";
|
|
2
|
+
import { DatabaseConstraintError, createUUIDv7 } from "@hot-updater/plugin-core";
|
|
3
|
+
//#region src/core/iosDevices.ts
|
|
4
|
+
/**
|
|
5
|
+
* A device's UDID: 40 hex digits, or 8 and 16 joined by a hyphen. The same
|
|
6
|
+
* rule as `normalizeIosUdid` of `@hot-updater/protocol/native-artifact`,
|
|
7
|
+
* implemented here so the server's runtime never loads the artifact readers.
|
|
8
|
+
*/
|
|
9
|
+
const UDID = /^(?:[0-9a-f]{40}|[0-9a-f]{8}-[0-9a-f]{16})$/iu;
|
|
10
|
+
/** The form the registry stores and compares a UDID in, or null for text that isn't one. */
|
|
11
|
+
const normalizeIosUdid = (value) => {
|
|
12
|
+
const trimmed = value.trim();
|
|
13
|
+
return UDID.test(trimmed) ? trimmed.toLowerCase() : null;
|
|
14
|
+
};
|
|
15
|
+
/** `ios_devices.name`'s bound in core's schema. */
|
|
16
|
+
const NAME_MAX_LENGTH = 100;
|
|
17
|
+
/** `ios_devices.requested_by` and `approved_by`'s bound: an email address. */
|
|
18
|
+
const EMAIL_MAX_LENGTH = 320;
|
|
19
|
+
/** `ios_devices.apple_issuer_id`'s bound. */
|
|
20
|
+
const ISSUER_MAX_LENGTH = 64;
|
|
21
|
+
/** How many registry rows one read takes while finding its account. */
|
|
22
|
+
const ACCOUNT_SCAN_PAGE = 200;
|
|
23
|
+
/** The one row of `ios_device_account`. */
|
|
24
|
+
const ACCOUNT_ROW = "registry";
|
|
25
|
+
/** `ios_devices.apple_error`'s bound. */
|
|
26
|
+
const ERROR_MAX_LENGTH = 512;
|
|
27
|
+
const STATUSES = [
|
|
28
|
+
"pending",
|
|
29
|
+
"approved",
|
|
30
|
+
"registered"
|
|
31
|
+
];
|
|
32
|
+
const OUTCOMES = [
|
|
33
|
+
"registered",
|
|
34
|
+
"refused",
|
|
35
|
+
"disabled",
|
|
36
|
+
"missing"
|
|
37
|
+
];
|
|
38
|
+
/** The `apple_error` of a device Apple has disabled. */
|
|
39
|
+
const IOS_DEVICE_DISABLED_ERROR = "Disabled in the Apple account.";
|
|
40
|
+
/** The `apple_error` of a registered device Apple no longer lists. */
|
|
41
|
+
const IOS_DEVICE_MISSING_ERROR = "Gone from the Apple account. Approve it again to register it.";
|
|
42
|
+
/** A device or registry request core cannot store: the caller's input. */
|
|
43
|
+
var IosDeviceInputError = class extends TypeError {
|
|
44
|
+
name = "IosDeviceInputError";
|
|
45
|
+
};
|
|
46
|
+
const pick = (row) => ({
|
|
47
|
+
id: row.id,
|
|
48
|
+
udid: row.udid,
|
|
49
|
+
name: row.name,
|
|
50
|
+
status: row.status,
|
|
51
|
+
requested_by: row.requested_by ?? null,
|
|
52
|
+
created_at_ms: row.created_at_ms,
|
|
53
|
+
approved_by: row.approved_by ?? null,
|
|
54
|
+
approved_at_ms: row.approved_at_ms ?? null,
|
|
55
|
+
registered_at_ms: row.registered_at_ms ?? null,
|
|
56
|
+
apple_issuer_id: row.apple_issuer_id ?? null,
|
|
57
|
+
apple_error: row.apple_error ?? null,
|
|
58
|
+
build_id: row.build_id ?? null
|
|
59
|
+
});
|
|
60
|
+
const udidOf = (udid) => {
|
|
61
|
+
const key = typeof udid === "string" ? normalizeIosUdid(udid) : null;
|
|
62
|
+
if (key === null) throw new IosDeviceInputError("Invalid iOS device: udid must be 40 hex digits, or 8 and 16 joined by a hyphen.");
|
|
63
|
+
return key;
|
|
64
|
+
};
|
|
65
|
+
const nameOf = (name) => {
|
|
66
|
+
const trimmed = typeof name === "string" ? name.trim() : "";
|
|
67
|
+
if (trimmed.length === 0 || trimmed.length > NAME_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device: name must be 1 to ${NAME_MAX_LENGTH} characters.`);
|
|
68
|
+
return trimmed;
|
|
69
|
+
};
|
|
70
|
+
/** An email, lower-cased, or null for the CLI. */
|
|
71
|
+
const personOf = (value, field) => {
|
|
72
|
+
if (value === null) return null;
|
|
73
|
+
const email = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
74
|
+
if (email.length === 0 || email.length > EMAIL_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device: ${field} must be an email of at most ${EMAIL_MAX_LENGTH} characters, or null.`);
|
|
75
|
+
return email;
|
|
76
|
+
};
|
|
77
|
+
/** Apple's words, on one line and within the column's bound. */
|
|
78
|
+
const errorText = (text) => {
|
|
79
|
+
const line = text.replace(/\s+/gu, " ").trim();
|
|
80
|
+
return line.length > ERROR_MAX_LENGTH ? `${line.slice(0, 511)}…` : line;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* The iOS device registry: the iPhones and iPads a team asked to install ad hoc
|
|
84
|
+
* builds on. The Console writes requests and approvals, and the CLI what Apple
|
|
85
|
+
* said, each over the row it read.
|
|
86
|
+
*/
|
|
87
|
+
const createIosDeviceApi = (db, { now = Date.now } = {}) => {
|
|
88
|
+
const findIosDevice = async (udid) => {
|
|
89
|
+
const key = normalizeIosUdid(udid);
|
|
90
|
+
if (key === null) return null;
|
|
91
|
+
const row = await db.findOne("ios_devices", { udid: key });
|
|
92
|
+
return row === null ? null : pick(row);
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* The issuer of the registry's earliest registration among its rows, by
|
|
96
|
+
* when and then by ID, or null when no row names one: read only while the
|
|
97
|
+
* registry has no account yet, a page at a time.
|
|
98
|
+
*/
|
|
99
|
+
const accountOfRows = async () => {
|
|
100
|
+
let earliest = null;
|
|
101
|
+
for (let after;;) {
|
|
102
|
+
const { rows } = await db.findMany("ios_devices", {
|
|
103
|
+
index: "all",
|
|
104
|
+
where: {},
|
|
105
|
+
order: "asc",
|
|
106
|
+
limit: ACCOUNT_SCAN_PAGE,
|
|
107
|
+
...after === void 0 ? {} : { range: { gt: after } }
|
|
108
|
+
});
|
|
109
|
+
for (const row of rows.map(pick)) {
|
|
110
|
+
if (row.apple_issuer_id === null) continue;
|
|
111
|
+
if (earliest === null || (row.registered_at_ms ?? 0) < (earliest.registered_at_ms ?? 0)) earliest = row;
|
|
112
|
+
}
|
|
113
|
+
if (rows.length < ACCOUNT_SCAN_PAGE) return earliest?.apple_issuer_id ?? null;
|
|
114
|
+
after = rows.at(-1).id;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
async listIosDevices(input) {
|
|
119
|
+
if (input.status !== void 0 && !STATUSES.includes(input.status)) throw new IosDeviceInputError(`Invalid iOS device status: ${String(input.status)}. Expected ${STATUSES.join(", ")}.`);
|
|
120
|
+
const page = {
|
|
121
|
+
order: input.order ?? "asc",
|
|
122
|
+
limit: input.limit,
|
|
123
|
+
...after(input)
|
|
124
|
+
};
|
|
125
|
+
const { rows } = input.status === void 0 ? await db.findMany("ios_devices", {
|
|
126
|
+
index: "all",
|
|
127
|
+
where: {},
|
|
128
|
+
...page
|
|
129
|
+
}) : await db.findMany("ios_devices", {
|
|
130
|
+
index: "byStatus",
|
|
131
|
+
where: { status: input.status },
|
|
132
|
+
...page
|
|
133
|
+
});
|
|
134
|
+
return rows.map(pick);
|
|
135
|
+
},
|
|
136
|
+
findIosDevice,
|
|
137
|
+
async requestIosDevice(input) {
|
|
138
|
+
const udid = udidOf(input.udid);
|
|
139
|
+
const name = nameOf(input.name);
|
|
140
|
+
const requestedBy = personOf(input.requestedBy, "requestedBy");
|
|
141
|
+
const existing = await db.findOne("ios_devices", { udid });
|
|
142
|
+
if (existing !== null) return {
|
|
143
|
+
device: pick(existing),
|
|
144
|
+
created: false
|
|
145
|
+
};
|
|
146
|
+
const device = {
|
|
147
|
+
id: createUUIDv7(),
|
|
148
|
+
udid,
|
|
149
|
+
name,
|
|
150
|
+
status: "pending",
|
|
151
|
+
requested_by: requestedBy,
|
|
152
|
+
created_at_ms: now(),
|
|
153
|
+
approved_by: null,
|
|
154
|
+
approved_at_ms: null,
|
|
155
|
+
registered_at_ms: null,
|
|
156
|
+
apple_issuer_id: null,
|
|
157
|
+
apple_error: null,
|
|
158
|
+
build_id: null
|
|
159
|
+
};
|
|
160
|
+
try {
|
|
161
|
+
await db.transaction(async (tx) => {
|
|
162
|
+
tx.create("ios_devices", device);
|
|
163
|
+
});
|
|
164
|
+
} catch (error) {
|
|
165
|
+
if (error instanceof DatabaseConstraintError && error.reason === "unique") {
|
|
166
|
+
const winner = await db.findOne("ios_devices", { udid });
|
|
167
|
+
if (winner !== null) return {
|
|
168
|
+
device: pick(winner),
|
|
169
|
+
created: false
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
device,
|
|
176
|
+
created: true
|
|
177
|
+
};
|
|
178
|
+
},
|
|
179
|
+
async approveIosDevice(id, input) {
|
|
180
|
+
const name = input.name === void 0 ? void 0 : nameOf(input.name);
|
|
181
|
+
const approvedBy = personOf(input.approvedBy, "approvedBy");
|
|
182
|
+
return db.transaction(async (tx) => {
|
|
183
|
+
const row = await tx.findOne("ios_devices", { id });
|
|
184
|
+
if (row === null) return null;
|
|
185
|
+
const device = pick(row);
|
|
186
|
+
const set = {
|
|
187
|
+
...name === void 0 || name === device.name ? {} : { name },
|
|
188
|
+
...device.status === "pending" ? {
|
|
189
|
+
status: "approved",
|
|
190
|
+
approved_by: approvedBy,
|
|
191
|
+
approved_at_ms: now()
|
|
192
|
+
} : {}
|
|
193
|
+
};
|
|
194
|
+
if (Object.keys(set).length === 0) return device;
|
|
195
|
+
tx.update("ios_devices", row, set);
|
|
196
|
+
return {
|
|
197
|
+
...device,
|
|
198
|
+
...set
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
async renameIosDevice(id, input) {
|
|
203
|
+
const name = nameOf(input);
|
|
204
|
+
return db.transaction(async (tx) => {
|
|
205
|
+
const row = await tx.findOne("ios_devices", { id });
|
|
206
|
+
if (row === null) return null;
|
|
207
|
+
const device = pick(row);
|
|
208
|
+
if (device.name === name) return device;
|
|
209
|
+
tx.update("ios_devices", row, { name });
|
|
210
|
+
return {
|
|
211
|
+
...device,
|
|
212
|
+
name
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
async recordIosDeviceOutcome({ id, seen, issuerId, outcome, reason }) {
|
|
217
|
+
if (!OUTCOMES.includes(outcome)) throw new IosDeviceInputError(`Invalid iOS device outcome: ${String(outcome)}. Expected ${OUTCOMES.join(", ")}.`);
|
|
218
|
+
if (typeof issuerId !== "string" || issuerId.trim().length === 0 || issuerId.length > ISSUER_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device outcome: issuerId must be an App Store Connect issuer of at most ${ISSUER_MAX_LENGTH} characters.`);
|
|
219
|
+
return db.transaction(async (tx) => {
|
|
220
|
+
const row = await tx.findOne("ios_devices", { id });
|
|
221
|
+
if (row === null) return null;
|
|
222
|
+
const device = pick(row);
|
|
223
|
+
if (device.status !== seen.status || device.approved_at_ms !== seen.approvedAtMs || device.apple_issuer_id !== null && device.apple_issuer_id !== issuerId) return null;
|
|
224
|
+
let set;
|
|
225
|
+
switch (outcome) {
|
|
226
|
+
case "registered":
|
|
227
|
+
if (device.status === "pending") return null;
|
|
228
|
+
set = {
|
|
229
|
+
status: "registered",
|
|
230
|
+
registered_at_ms: device.registered_at_ms ?? now(),
|
|
231
|
+
apple_issuer_id: issuerId,
|
|
232
|
+
apple_error: null
|
|
233
|
+
};
|
|
234
|
+
break;
|
|
235
|
+
case "refused":
|
|
236
|
+
if (device.status !== "approved") return null;
|
|
237
|
+
set = { apple_error: errorText(reason === void 0 || reason.trim() === "" ? "Apple refused it." : reason) };
|
|
238
|
+
break;
|
|
239
|
+
case "disabled":
|
|
240
|
+
if (device.status === "pending") return null;
|
|
241
|
+
set = { apple_error: IOS_DEVICE_DISABLED_ERROR };
|
|
242
|
+
break;
|
|
243
|
+
case "missing":
|
|
244
|
+
if (device.status !== "registered") return null;
|
|
245
|
+
set = {
|
|
246
|
+
status: "pending",
|
|
247
|
+
approved_by: null,
|
|
248
|
+
approved_at_ms: null,
|
|
249
|
+
apple_error: IOS_DEVICE_MISSING_ERROR
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
if (Object.entries(set).some(([column, value]) => device[column] !== (value ?? null))) tx.update("ios_devices", row, set);
|
|
253
|
+
return {
|
|
254
|
+
...device,
|
|
255
|
+
...set
|
|
256
|
+
};
|
|
257
|
+
});
|
|
258
|
+
},
|
|
259
|
+
async markIosDevicesInBuild({ buildId, ids }) {
|
|
260
|
+
for (const id of new Set(ids)) await db.transaction(async (tx) => {
|
|
261
|
+
const row = await tx.findOne("ios_devices", { id });
|
|
262
|
+
if (row === null || typeof row.build_id === "string" && row.build_id >= buildId) return;
|
|
263
|
+
tx.update("ios_devices", row, { build_id: buildId });
|
|
264
|
+
});
|
|
265
|
+
},
|
|
266
|
+
async claimIosDeviceAccount(issuerId) {
|
|
267
|
+
if (typeof issuerId !== "string" || issuerId.trim().length === 0 || issuerId.length > ISSUER_MAX_LENGTH) throw new IosDeviceInputError(`Invalid iOS device account: issuerId must be an App Store Connect issuer of at most ${ISSUER_MAX_LENGTH} characters.`);
|
|
268
|
+
const answer = (held) => ({
|
|
269
|
+
issuerId: held,
|
|
270
|
+
claimed: held === issuerId
|
|
271
|
+
});
|
|
272
|
+
const existing = await db.findOne("ios_device_account", { id: ACCOUNT_ROW });
|
|
273
|
+
if (existing !== null) return answer(existing.apple_issuer_id);
|
|
274
|
+
const holder = await accountOfRows() ?? issuerId;
|
|
275
|
+
try {
|
|
276
|
+
await db.transaction(async (tx) => {
|
|
277
|
+
tx.create("ios_device_account", {
|
|
278
|
+
id: ACCOUNT_ROW,
|
|
279
|
+
apple_issuer_id: holder,
|
|
280
|
+
claimed_at_ms: now()
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
return answer(holder);
|
|
284
|
+
} catch (error) {
|
|
285
|
+
if (error instanceof DatabaseConstraintError && (error.reason === "exists" || error.reason === "unique")) {
|
|
286
|
+
const winner = await db.findOne("ios_device_account", { id: ACCOUNT_ROW });
|
|
287
|
+
if (winner !== null) return answer(winner.apple_issuer_id);
|
|
288
|
+
}
|
|
289
|
+
throw error;
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
async deleteIosDevice(id, only) {
|
|
293
|
+
const requestedBy = only?.requestedBy === void 0 ? void 0 : personOf(only.requestedBy, "requestedBy");
|
|
294
|
+
return db.transaction(async (tx) => {
|
|
295
|
+
const row = await tx.findOne("ios_devices", { id });
|
|
296
|
+
if (row === null) return null;
|
|
297
|
+
const device = pick(row);
|
|
298
|
+
if (only?.status !== void 0 && device.status !== only.status || requestedBy !== void 0 && device.requested_by !== requestedBy) return null;
|
|
299
|
+
await tx.delete("ios_devices", row);
|
|
300
|
+
return device;
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
//#endregion
|
|
306
|
+
export { IOS_DEVICE_DISABLED_ERROR, IOS_DEVICE_MISSING_ERROR, IosDeviceInputError, createIosDeviceApi };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_nativeBuildDestinations = require("./nativeBuildDestinations.cjs");
|
|
2
1
|
const require_reads = require("./reads.cjs");
|
|
2
|
+
const require_nativeBuildDestinations = require("./nativeBuildDestinations.cjs");
|
|
3
3
|
const require_writes = require("./writes.cjs");
|
|
4
4
|
let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
|
|
5
5
|
let _hot_updater_protocol = require("@hot-updater/protocol");
|
|
@@ -50,8 +50,16 @@ const pick = (row) => ({
|
|
|
50
50
|
submitted_version: row.submitted_version ?? null,
|
|
51
51
|
is_store_build: row.is_store_build === true,
|
|
52
52
|
is_sandbox: row.is_sandbox === true,
|
|
53
|
-
sandbox_url_scheme: row.sandbox_url_scheme ?? null
|
|
53
|
+
sandbox_url_scheme: row.sandbox_url_scheme ?? null,
|
|
54
|
+
export_method: row.export_method ?? null
|
|
54
55
|
});
|
|
56
|
+
/** The export methods an `.ipa` registers with. */
|
|
57
|
+
const EXPORT_METHODS = /* @__PURE__ */ new Set([
|
|
58
|
+
"app-store",
|
|
59
|
+
"ad-hoc",
|
|
60
|
+
"development",
|
|
61
|
+
"enterprise"
|
|
62
|
+
]);
|
|
55
63
|
/**
|
|
56
64
|
* The channels only sandbox builds register on: a registration's `sandbox`
|
|
57
65
|
* must agree with it. The registry's convention, as
|
|
@@ -97,7 +105,7 @@ const nativeBuildScopeKey = (scope) => {
|
|
|
97
105
|
};
|
|
98
106
|
/** Whether `bundleId` is a native build's built-in bundle: one unique read. */
|
|
99
107
|
const isBuiltInBundle = async (db, bundleId) => await db.findOne("native_builds", { min_bundle_id: bundleId }) !== null;
|
|
100
|
-
const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, artifact }) => {
|
|
108
|
+
const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, exportMethod, artifact }) => {
|
|
101
109
|
if (!(0, _hot_updater_plugin_core.isUUIDv7)(id)) return "id must be a UUIDv7";
|
|
102
110
|
if (!(0, _hot_updater_plugin_core.isUUIDv7)(minBundleId)) return "minBundleId must be the UUIDv7 a release build compiles in";
|
|
103
111
|
if (platform !== "ios" && platform !== "android") return "platform must be ios or android";
|
|
@@ -116,6 +124,10 @@ const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVer
|
|
|
116
124
|
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`;
|
|
117
125
|
const kinds = ARTIFACT_KINDS[platform];
|
|
118
126
|
if (!kinds.includes(artifact.kind)) return `artifact.kind of an ${platform} build must be ${kinds.join(" or ")}`;
|
|
127
|
+
if (exportMethod !== void 0 && exportMethod !== null) {
|
|
128
|
+
if (artifact.kind !== "ipa") return "exportMethod is an .ipa's, and this artifact isn't one";
|
|
129
|
+
if (!EXPORT_METHODS.has(exportMethod)) return `exportMethod must be ${[...EXPORT_METHODS].join(", ")}, or null`;
|
|
130
|
+
}
|
|
119
131
|
if (!Number.isSafeInteger(artifact.byteSize) || artifact.byteSize < 0) return "artifact.byteSize must be a byte count";
|
|
120
132
|
return null;
|
|
121
133
|
};
|
|
@@ -147,7 +159,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
147
159
|
submitted_version: null,
|
|
148
160
|
is_store_build: false,
|
|
149
161
|
is_sandbox: registration.isSandbox === true,
|
|
150
|
-
sandbox_url_scheme: registration.sandboxUrlScheme ?? null
|
|
162
|
+
sandbox_url_scheme: registration.sandboxUrlScheme ?? null,
|
|
163
|
+
export_method: registration.exportMethod ?? null
|
|
151
164
|
};
|
|
152
165
|
for (let attempt = 1;; attempt += 1) {
|
|
153
166
|
await require_writes.insertChannel(db, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NATIVE_BUILD_SUBMISSION_DESTINATIONS } from "./nativeBuildDestinations.mjs";
|
|
2
1
|
import { after } from "./reads.mjs";
|
|
2
|
+
import { NATIVE_BUILD_SUBMISSION_DESTINATIONS } from "./nativeBuildDestinations.mjs";
|
|
3
3
|
import { insertChannel } from "./writes.mjs";
|
|
4
4
|
import { DatabaseConstraintError, isUUIDv7 } from "@hot-updater/plugin-core";
|
|
5
5
|
import { createReleaseCatalogScopeKey, encodeChannelKey } from "@hot-updater/protocol";
|
|
@@ -50,8 +50,16 @@ const pick = (row) => ({
|
|
|
50
50
|
submitted_version: row.submitted_version ?? null,
|
|
51
51
|
is_store_build: row.is_store_build === true,
|
|
52
52
|
is_sandbox: row.is_sandbox === true,
|
|
53
|
-
sandbox_url_scheme: row.sandbox_url_scheme ?? null
|
|
53
|
+
sandbox_url_scheme: row.sandbox_url_scheme ?? null,
|
|
54
|
+
export_method: row.export_method ?? null
|
|
54
55
|
});
|
|
56
|
+
/** The export methods an `.ipa` registers with. */
|
|
57
|
+
const EXPORT_METHODS = /* @__PURE__ */ new Set([
|
|
58
|
+
"app-store",
|
|
59
|
+
"ad-hoc",
|
|
60
|
+
"development",
|
|
61
|
+
"enterprise"
|
|
62
|
+
]);
|
|
55
63
|
/**
|
|
56
64
|
* The channels only sandbox builds register on: a registration's `sandbox`
|
|
57
65
|
* must agree with it. The registry's convention, as
|
|
@@ -97,7 +105,7 @@ const nativeBuildScopeKey = (scope) => {
|
|
|
97
105
|
};
|
|
98
106
|
/** Whether `bundleId` is a native build's built-in bundle: one unique read. */
|
|
99
107
|
const isBuiltInBundle = async (db, bundleId) => await db.findOne("native_builds", { min_bundle_id: bundleId }) !== null;
|
|
100
|
-
const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, artifact }) => {
|
|
108
|
+
const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVersion, gitCommitHash, buildKey, buildNumber, isSandbox, sandboxUrlScheme, exportMethod, artifact }) => {
|
|
101
109
|
if (!isUUIDv7(id)) return "id must be a UUIDv7";
|
|
102
110
|
if (!isUUIDv7(minBundleId)) return "minBundleId must be the UUIDv7 a release build compiles in";
|
|
103
111
|
if (platform !== "ios" && platform !== "android") return "platform must be ios or android";
|
|
@@ -116,6 +124,10 @@ const problemOf = ({ id, minBundleId, platform, channel, fingerprintHash, appVer
|
|
|
116
124
|
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`;
|
|
117
125
|
const kinds = ARTIFACT_KINDS[platform];
|
|
118
126
|
if (!kinds.includes(artifact.kind)) return `artifact.kind of an ${platform} build must be ${kinds.join(" or ")}`;
|
|
127
|
+
if (exportMethod !== void 0 && exportMethod !== null) {
|
|
128
|
+
if (artifact.kind !== "ipa") return "exportMethod is an .ipa's, and this artifact isn't one";
|
|
129
|
+
if (!EXPORT_METHODS.has(exportMethod)) return `exportMethod must be ${[...EXPORT_METHODS].join(", ")}, or null`;
|
|
130
|
+
}
|
|
119
131
|
if (!Number.isSafeInteger(artifact.byteSize) || artifact.byteSize < 0) return "artifact.byteSize must be a byte count";
|
|
120
132
|
return null;
|
|
121
133
|
};
|
|
@@ -147,7 +159,8 @@ const createNativeBuildApi = (db, { now = Date.now } = {}) => ({
|
|
|
147
159
|
submitted_version: null,
|
|
148
160
|
is_store_build: false,
|
|
149
161
|
is_sandbox: registration.isSandbox === true,
|
|
150
|
-
sandbox_url_scheme: registration.sandboxUrlScheme ?? null
|
|
162
|
+
sandbox_url_scheme: registration.sandboxUrlScheme ?? null,
|
|
163
|
+
export_method: registration.exportMethod ?? null
|
|
151
164
|
};
|
|
152
165
|
for (let attempt = 1;; attempt += 1) {
|
|
153
166
|
await insertChannel(db, {
|
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. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_iosDevices = require("./core/iosDevices.cjs");
|
|
1
2
|
const require_nativeBuildDestinations = require("./core/nativeBuildDestinations.cjs");
|
|
2
3
|
const require_nativeBuilds = require("./core/nativeBuilds.cjs");
|
|
3
4
|
const require_handlerErrors = require("./handlerErrors.cjs");
|
|
@@ -48,10 +49,12 @@ const keyset = (url, maxValue = LIMITS.maxValue) => {
|
|
|
48
49
|
const limit = limitParam === null ? Math.min(LIMITS.defaultValue, maxValue) : Number(limitParam);
|
|
49
50
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > maxValue) throw new require_handlerErrors.HandlerBadRequestError(`limit must be between 1 and ${maxValue}.`);
|
|
50
51
|
const cursor = url.searchParams.get("cursor");
|
|
52
|
+
const through = url.searchParams.get("through");
|
|
51
53
|
return {
|
|
52
54
|
order,
|
|
53
55
|
limit,
|
|
54
|
-
...cursor === null ? {} : { after: cursor }
|
|
56
|
+
...cursor === null ? {} : { after: cursor },
|
|
57
|
+
...through === null ? {} : { through }
|
|
55
58
|
};
|
|
56
59
|
};
|
|
57
60
|
/** A page and the cursor of the next one, when the page is full. */
|
|
@@ -166,11 +169,11 @@ const refusingInvalid = async (operation) => {
|
|
|
166
169
|
try {
|
|
167
170
|
return await operation();
|
|
168
171
|
} catch (error) {
|
|
169
|
-
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);
|
|
170
173
|
throw error;
|
|
171
174
|
}
|
|
172
175
|
};
|
|
173
|
-
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)) && 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)) && 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));
|
|
174
177
|
const scopeKeyOf = (params) => require_handlerParameters.decodeMaybe(require_handlerParameters.requireRouteParam(params, "scopeKey")) ?? "";
|
|
175
178
|
/** Every admin route's handler, by the name `ADMIN_ROUTES` mounts it under. */
|
|
176
179
|
const createAdminRouteHandlers = () => ({
|
|
@@ -333,6 +336,81 @@ const createAdminRouteHandlers = () => ({
|
|
|
333
336
|
return json({ data: await refusingInvalid(() => core.markNativeBuild(require_handlerParameters.requireRouteParam(params, "id"), mark)) });
|
|
334
337
|
}),
|
|
335
338
|
deleteNativeBuild: onCore(async (core, _request, params) => json({ data: await core.deleteNativeBuild(require_handlerParameters.requireRouteParam(params, "id")) })),
|
|
339
|
+
listIosDevices: onCore(async (core, request) => {
|
|
340
|
+
const url = new URL(request.url);
|
|
341
|
+
const input = keyset(url);
|
|
342
|
+
const status = url.searchParams.get("status");
|
|
343
|
+
return page(await refusingInvalid(() => core.listIosDevices({
|
|
344
|
+
...input,
|
|
345
|
+
...status === null ? {} : { status }
|
|
346
|
+
})), input, ({ id }) => id);
|
|
347
|
+
}),
|
|
348
|
+
findIosDevice: onCore(async (core, _request, params) => json({ data: await core.findIosDevice(require_handlerParameters.requireRouteParam(params, "udid")) })),
|
|
349
|
+
requestIosDevice: onCore(async (core, request) => {
|
|
350
|
+
const input = await body(request);
|
|
351
|
+
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.");
|
|
352
|
+
const device = {
|
|
353
|
+
udid: input.udid,
|
|
354
|
+
name: input.name,
|
|
355
|
+
requestedBy: input.requestedBy
|
|
356
|
+
};
|
|
357
|
+
return json({ data: await refusingInvalid(() => core.requestIosDevice(device)) });
|
|
358
|
+
}),
|
|
359
|
+
approveIosDevice: onCore(async (core, request, params) => {
|
|
360
|
+
const input = await body(request);
|
|
361
|
+
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.");
|
|
362
|
+
const approval = {
|
|
363
|
+
approvedBy: input.approvedBy,
|
|
364
|
+
...input.name === void 0 ? {} : { name: input.name }
|
|
365
|
+
};
|
|
366
|
+
return json({ data: await refusingInvalid(() => core.approveIosDevice(require_handlerParameters.requireRouteParam(params, "id"), approval)) });
|
|
367
|
+
}),
|
|
368
|
+
renameIosDevice: onCore(async (core, request, params) => {
|
|
369
|
+
const input = await body(request);
|
|
370
|
+
if (!isText(input.name)) throw new require_handlerErrors.HandlerBadRequestError("An iOS device's new name is required.");
|
|
371
|
+
const name = input.name;
|
|
372
|
+
return json({ data: await refusingInvalid(() => core.renameIosDevice(require_handlerParameters.requireRouteParam(params, "id"), name)) });
|
|
373
|
+
}),
|
|
374
|
+
recordIosDeviceOutcome: onCore(async (core, request, params) => {
|
|
375
|
+
const input = await body(request);
|
|
376
|
+
const seen = input.seen;
|
|
377
|
+
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.");
|
|
378
|
+
const outcome = {
|
|
379
|
+
id: require_handlerParameters.requireRouteParam(params, "id"),
|
|
380
|
+
seen: {
|
|
381
|
+
status: seen.status,
|
|
382
|
+
approvedAtMs: seen.approvedAtMs
|
|
383
|
+
},
|
|
384
|
+
issuerId: input.issuerId,
|
|
385
|
+
outcome: input.outcome,
|
|
386
|
+
...input.reason === void 0 ? {} : { reason: input.reason }
|
|
387
|
+
};
|
|
388
|
+
return json({ data: await refusingInvalid(() => core.recordIosDeviceOutcome(outcome)) });
|
|
389
|
+
}),
|
|
390
|
+
claimIosDeviceAccount: onCore(async (core, request) => {
|
|
391
|
+
const { issuerId } = await body(request);
|
|
392
|
+
if (!isText(issuerId)) throw new require_handlerErrors.HandlerBadRequestError("Claiming the iOS device account needs issuerId.");
|
|
393
|
+
return json({ data: await refusingInvalid(() => core.claimIosDeviceAccount(issuerId)) });
|
|
394
|
+
}),
|
|
395
|
+
markIosDevicesInBuild: onCore(async (core, request) => {
|
|
396
|
+
const { buildId, ids } = await body(request);
|
|
397
|
+
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.");
|
|
398
|
+
await core.markIosDevicesInBuild({
|
|
399
|
+
buildId,
|
|
400
|
+
ids
|
|
401
|
+
});
|
|
402
|
+
return noContent();
|
|
403
|
+
}),
|
|
404
|
+
deleteIosDevice: onCore(async (core, request, params) => {
|
|
405
|
+
const url = new URL(request.url);
|
|
406
|
+
const status = url.searchParams.get("status");
|
|
407
|
+
const requestedBy = url.searchParams.get("requestedBy");
|
|
408
|
+
const only = {
|
|
409
|
+
...status === null ? {} : { status },
|
|
410
|
+
...requestedBy === null ? {} : { requestedBy }
|
|
411
|
+
};
|
|
412
|
+
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)) });
|
|
413
|
+
}),
|
|
336
414
|
deleteBundles: onCore(async (core, request) => {
|
|
337
415
|
const { ids } = await body(request);
|
|
338
416
|
if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id.length > 0)) throw new require_handlerErrors.HandlerBadRequestError("Bundle deletion needs ids");
|
|
@@ -486,6 +564,51 @@ const ADMIN_ROUTES = [
|
|
|
486
564
|
method: "DELETE",
|
|
487
565
|
path: "/native-builds/:id",
|
|
488
566
|
handler: "deleteNativeBuild"
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
method: "GET",
|
|
570
|
+
path: "/ios-devices",
|
|
571
|
+
handler: "listIosDevices"
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
method: "POST",
|
|
575
|
+
path: "/ios-devices",
|
|
576
|
+
handler: "requestIosDevice"
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
method: "GET",
|
|
580
|
+
path: "/ios-devices/udid/:udid",
|
|
581
|
+
handler: "findIosDevice"
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
method: "POST",
|
|
585
|
+
path: "/ios-devices/in-build",
|
|
586
|
+
handler: "markIosDevicesInBuild"
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
method: "POST",
|
|
590
|
+
path: "/ios-devices/account",
|
|
591
|
+
handler: "claimIosDeviceAccount"
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
method: "POST",
|
|
595
|
+
path: "/ios-devices/:id/approval",
|
|
596
|
+
handler: "approveIosDevice"
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
method: "POST",
|
|
600
|
+
path: "/ios-devices/:id/outcome",
|
|
601
|
+
handler: "recordIosDeviceOutcome"
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
method: "PATCH",
|
|
605
|
+
path: "/ios-devices/:id",
|
|
606
|
+
handler: "renameIosDevice"
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
method: "DELETE",
|
|
610
|
+
path: "/ios-devices/:id",
|
|
611
|
+
handler: "deleteIosDevice"
|
|
489
612
|
}
|
|
490
613
|
];
|
|
491
614
|
//#endregion
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IosDeviceInputError } from "./core/iosDevices.mjs";
|
|
1
2
|
import { NATIVE_BUILD_SUBMISSION_DESTINATIONS } from "./core/nativeBuildDestinations.mjs";
|
|
2
3
|
import { NativeBuildInputError } from "./core/nativeBuilds.mjs";
|
|
3
4
|
import { HandlerBadRequestError } from "./handlerErrors.mjs";
|
|
@@ -48,10 +49,12 @@ const keyset = (url, maxValue = LIMITS.maxValue) => {
|
|
|
48
49
|
const limit = limitParam === null ? Math.min(LIMITS.defaultValue, maxValue) : Number(limitParam);
|
|
49
50
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > maxValue) throw new HandlerBadRequestError(`limit must be between 1 and ${maxValue}.`);
|
|
50
51
|
const cursor = url.searchParams.get("cursor");
|
|
52
|
+
const through = url.searchParams.get("through");
|
|
51
53
|
return {
|
|
52
54
|
order,
|
|
53
55
|
limit,
|
|
54
|
-
...cursor === null ? {} : { after: cursor }
|
|
56
|
+
...cursor === null ? {} : { after: cursor },
|
|
57
|
+
...through === null ? {} : { through }
|
|
55
58
|
};
|
|
56
59
|
};
|
|
57
60
|
/** A page and the cursor of the next one, when the page is full. */
|
|
@@ -166,11 +169,11 @@ const refusingInvalid = async (operation) => {
|
|
|
166
169
|
try {
|
|
167
170
|
return await operation();
|
|
168
171
|
} catch (error) {
|
|
169
|
-
if (error instanceof NativeBuildInputError) throw new HandlerBadRequestError(error.message);
|
|
172
|
+
if (error instanceof NativeBuildInputError || error instanceof IosDeviceInputError) throw new HandlerBadRequestError(error.message);
|
|
170
173
|
throw error;
|
|
171
174
|
}
|
|
172
175
|
};
|
|
173
|
-
const isNativeBuildRegistration = (value) => isRecord(value) && isText(value.id) && isText(value.minBundleId) && typeof value.platform === "string" && 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)) && 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" && 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)) && 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));
|
|
174
177
|
const scopeKeyOf = (params) => decodeMaybe(requireRouteParam(params, "scopeKey")) ?? "";
|
|
175
178
|
/** Every admin route's handler, by the name `ADMIN_ROUTES` mounts it under. */
|
|
176
179
|
const createAdminRouteHandlers = () => ({
|
|
@@ -333,6 +336,81 @@ const createAdminRouteHandlers = () => ({
|
|
|
333
336
|
return json({ data: await refusingInvalid(() => core.markNativeBuild(requireRouteParam(params, "id"), mark)) });
|
|
334
337
|
}),
|
|
335
338
|
deleteNativeBuild: onCore(async (core, _request, params) => json({ data: await core.deleteNativeBuild(requireRouteParam(params, "id")) })),
|
|
339
|
+
listIosDevices: onCore(async (core, request) => {
|
|
340
|
+
const url = new URL(request.url);
|
|
341
|
+
const input = keyset(url);
|
|
342
|
+
const status = url.searchParams.get("status");
|
|
343
|
+
return page(await refusingInvalid(() => core.listIosDevices({
|
|
344
|
+
...input,
|
|
345
|
+
...status === null ? {} : { status }
|
|
346
|
+
})), input, ({ id }) => id);
|
|
347
|
+
}),
|
|
348
|
+
findIosDevice: onCore(async (core, _request, params) => json({ data: await core.findIosDevice(requireRouteParam(params, "udid")) })),
|
|
349
|
+
requestIosDevice: onCore(async (core, request) => {
|
|
350
|
+
const input = await body(request);
|
|
351
|
+
if (!isText(input.udid) || !isText(input.name) || !isTextOrNull(input.requestedBy)) throw new HandlerBadRequestError("An iOS device request needs udid, name, and requestedBy, an email or null.");
|
|
352
|
+
const device = {
|
|
353
|
+
udid: input.udid,
|
|
354
|
+
name: input.name,
|
|
355
|
+
requestedBy: input.requestedBy
|
|
356
|
+
};
|
|
357
|
+
return json({ data: await refusingInvalid(() => core.requestIosDevice(device)) });
|
|
358
|
+
}),
|
|
359
|
+
approveIosDevice: onCore(async (core, request, params) => {
|
|
360
|
+
const input = await body(request);
|
|
361
|
+
if (!isTextOrNull(input.approvedBy) || input.name !== void 0 && !isText(input.name)) throw new HandlerBadRequestError("An iOS device approval needs approvedBy, an email or null, and an optional name.");
|
|
362
|
+
const approval = {
|
|
363
|
+
approvedBy: input.approvedBy,
|
|
364
|
+
...input.name === void 0 ? {} : { name: input.name }
|
|
365
|
+
};
|
|
366
|
+
return json({ data: await refusingInvalid(() => core.approveIosDevice(requireRouteParam(params, "id"), approval)) });
|
|
367
|
+
}),
|
|
368
|
+
renameIosDevice: onCore(async (core, request, params) => {
|
|
369
|
+
const input = await body(request);
|
|
370
|
+
if (!isText(input.name)) throw new HandlerBadRequestError("An iOS device's new name is required.");
|
|
371
|
+
const name = input.name;
|
|
372
|
+
return json({ data: await refusingInvalid(() => core.renameIosDevice(requireRouteParam(params, "id"), name)) });
|
|
373
|
+
}),
|
|
374
|
+
recordIosDeviceOutcome: onCore(async (core, request, params) => {
|
|
375
|
+
const input = await body(request);
|
|
376
|
+
const seen = input.seen;
|
|
377
|
+
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 HandlerBadRequestError("An iOS device outcome needs seen { status, approvedAtMs }, issuerId, outcome, and an optional reason.");
|
|
378
|
+
const outcome = {
|
|
379
|
+
id: requireRouteParam(params, "id"),
|
|
380
|
+
seen: {
|
|
381
|
+
status: seen.status,
|
|
382
|
+
approvedAtMs: seen.approvedAtMs
|
|
383
|
+
},
|
|
384
|
+
issuerId: input.issuerId,
|
|
385
|
+
outcome: input.outcome,
|
|
386
|
+
...input.reason === void 0 ? {} : { reason: input.reason }
|
|
387
|
+
};
|
|
388
|
+
return json({ data: await refusingInvalid(() => core.recordIosDeviceOutcome(outcome)) });
|
|
389
|
+
}),
|
|
390
|
+
claimIosDeviceAccount: onCore(async (core, request) => {
|
|
391
|
+
const { issuerId } = await body(request);
|
|
392
|
+
if (!isText(issuerId)) throw new HandlerBadRequestError("Claiming the iOS device account needs issuerId.");
|
|
393
|
+
return json({ data: await refusingInvalid(() => core.claimIosDeviceAccount(issuerId)) });
|
|
394
|
+
}),
|
|
395
|
+
markIosDevicesInBuild: onCore(async (core, request) => {
|
|
396
|
+
const { buildId, ids } = await body(request);
|
|
397
|
+
if (!isText(buildId) || !Array.isArray(ids) || !ids.every((id) => isText(id))) throw new HandlerBadRequestError("Marking iOS devices in a build needs buildId and ids.");
|
|
398
|
+
await core.markIosDevicesInBuild({
|
|
399
|
+
buildId,
|
|
400
|
+
ids
|
|
401
|
+
});
|
|
402
|
+
return noContent();
|
|
403
|
+
}),
|
|
404
|
+
deleteIosDevice: onCore(async (core, request, params) => {
|
|
405
|
+
const url = new URL(request.url);
|
|
406
|
+
const status = url.searchParams.get("status");
|
|
407
|
+
const requestedBy = url.searchParams.get("requestedBy");
|
|
408
|
+
const only = {
|
|
409
|
+
...status === null ? {} : { status },
|
|
410
|
+
...requestedBy === null ? {} : { requestedBy }
|
|
411
|
+
};
|
|
412
|
+
return json({ data: await refusingInvalid(() => Object.keys(only).length === 0 ? core.deleteIosDevice(requireRouteParam(params, "id")) : core.deleteIosDevice(requireRouteParam(params, "id"), only)) });
|
|
413
|
+
}),
|
|
336
414
|
deleteBundles: onCore(async (core, request) => {
|
|
337
415
|
const { ids } = await body(request);
|
|
338
416
|
if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id.length > 0)) throw new HandlerBadRequestError("Bundle deletion needs ids");
|
|
@@ -486,6 +564,51 @@ const ADMIN_ROUTES = [
|
|
|
486
564
|
method: "DELETE",
|
|
487
565
|
path: "/native-builds/:id",
|
|
488
566
|
handler: "deleteNativeBuild"
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
method: "GET",
|
|
570
|
+
path: "/ios-devices",
|
|
571
|
+
handler: "listIosDevices"
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
method: "POST",
|
|
575
|
+
path: "/ios-devices",
|
|
576
|
+
handler: "requestIosDevice"
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
method: "GET",
|
|
580
|
+
path: "/ios-devices/udid/:udid",
|
|
581
|
+
handler: "findIosDevice"
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
method: "POST",
|
|
585
|
+
path: "/ios-devices/in-build",
|
|
586
|
+
handler: "markIosDevicesInBuild"
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
method: "POST",
|
|
590
|
+
path: "/ios-devices/account",
|
|
591
|
+
handler: "claimIosDeviceAccount"
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
method: "POST",
|
|
595
|
+
path: "/ios-devices/:id/approval",
|
|
596
|
+
handler: "approveIosDevice"
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
method: "POST",
|
|
600
|
+
path: "/ios-devices/:id/outcome",
|
|
601
|
+
handler: "recordIosDeviceOutcome"
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
method: "PATCH",
|
|
605
|
+
path: "/ios-devices/:id",
|
|
606
|
+
handler: "renameIosDevice"
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
method: "DELETE",
|
|
610
|
+
path: "/ios-devices/:id",
|
|
611
|
+
handler: "deleteIosDevice"
|
|
489
612
|
}
|
|
490
613
|
];
|
|
491
614
|
//#endregion
|
package/dist/package.cjs
CHANGED
package/dist/package.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/server",
|
|
3
|
-
"version": "1.2.0-rc.
|
|
3
|
+
"version": "1.2.0-rc.28",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -50,11 +50,11 @@
|
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"rou3": "0.7.9",
|
|
52
52
|
"verkit": "0.4.0",
|
|
53
|
-
"@hot-updater/protocol": "1.2.0-rc.
|
|
54
|
-
"@hot-updater/plugin-
|
|
55
|
-
"@hot-updater/plugin-insights": "1.2.0-rc.
|
|
56
|
-
"@hot-updater/plugin-
|
|
57
|
-
"@hot-updater/plugin-remote-config": "1.2.0-rc.
|
|
53
|
+
"@hot-updater/protocol": "1.2.0-rc.28",
|
|
54
|
+
"@hot-updater/plugin-api-keys": "1.2.0-rc.28",
|
|
55
|
+
"@hot-updater/plugin-insights": "1.2.0-rc.28",
|
|
56
|
+
"@hot-updater/plugin-core": "1.2.0-rc.28",
|
|
57
|
+
"@hot-updater/plugin-remote-config": "1.2.0-rc.28"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"@prisma/client": "*",
|