@hot-updater/protocol 1.1.4 → 1.2.0-rc.1

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.
@@ -0,0 +1,299 @@
1
+ //#region ../../node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/comparison-DenM3wCn.js
2
+ const LETTER_DASH_NUMBER = "[a-zA-Z0-9-]";
3
+ const NUMERIC_IDENTIFIER = String.raw`0|[1-9]\d*`;
4
+ const NUMERIC_IDENTIFIER_LOOSE = String.raw`\d+`;
5
+ const NON_NUMERIC_IDENTIFIER = String.raw`\d*[a-zA-Z-]${LETTER_DASH_NUMBER}*`;
6
+ const MAIN_VERSION = String.raw`(${NUMERIC_IDENTIFIER})\.(${NUMERIC_IDENTIFIER})\.(${NUMERIC_IDENTIFIER})`;
7
+ const MAIN_VERSION_LOOSE = String.raw`(${NUMERIC_IDENTIFIER_LOOSE})\.(${NUMERIC_IDENTIFIER_LOOSE})\.(${NUMERIC_IDENTIFIER_LOOSE})`;
8
+ const PRERELEASE_IDENTIFIER = `(?:${NON_NUMERIC_IDENTIFIER}|${NUMERIC_IDENTIFIER})`;
9
+ const PRERELEASE_IDENTIFIER_LOOSE = `(?:${NON_NUMERIC_IDENTIFIER}|${NUMERIC_IDENTIFIER_LOOSE})`;
10
+ const PRERELEASE = String.raw`(?:-(${PRERELEASE_IDENTIFIER}(?:\.${PRERELEASE_IDENTIFIER})*))`;
11
+ const PRERELEASE_LOOSE = String.raw`(?:-?(${PRERELEASE_IDENTIFIER_LOOSE}(?:\.${PRERELEASE_IDENTIFIER_LOOSE})*))`;
12
+ const BUILD_IDENTIFIER = `${LETTER_DASH_NUMBER}+`;
13
+ const BUILD = String.raw`(?:\+(${BUILD_IDENTIFIER}(?:\.${BUILD_IDENTIFIER})*))`;
14
+ const FULL_PLAIN = `v?${MAIN_VERSION}${PRERELEASE}?${BUILD}?`;
15
+ const LOOSE_PLAIN = String.raw`[v=\s]*${MAIN_VERSION_LOOSE}${PRERELEASE_LOOSE}?${BUILD}?`;
16
+ const XRANGE_IDENTIFIER = String.raw`${NUMERIC_IDENTIFIER}|x|X|\*`;
17
+ const XRANGE_IDENTIFIER_LOOSE = String.raw`${NUMERIC_IDENTIFIER_LOOSE}|x|X|\*`;
18
+ String.raw`[v=\s]*(${XRANGE_IDENTIFIER})(?:\.(${XRANGE_IDENTIFIER})(?:\.(${XRANGE_IDENTIFIER})(?:${PRERELEASE})?${BUILD}?)?)?`;
19
+ String.raw`[v=\s]*(${XRANGE_IDENTIFIER_LOOSE})(?:\.(${XRANGE_IDENTIFIER_LOOSE})(?:\.(${XRANGE_IDENTIFIER_LOOSE})(?:${PRERELEASE_LOOSE})?${BUILD}?)?)?`;
20
+ String.raw`(?:\^)`;
21
+ const COERCE_PLAIN = String.raw`(^|[^\d])(\d{1,${16}})(?:\.(\d{1,${16}}))?(?:\.(\d{1,${16}}))?`;
22
+ const COERCE = String.raw`${COERCE_PLAIN}(?:$|[^\d])`;
23
+ const COERCE_FULL = String.raw`${COERCE_PLAIN}(?:${PRERELEASE})?(?:${BUILD})?(?:$|[^\d])`;
24
+ function makeSafeRegexSource(source) {
25
+ const replacements = [
26
+ [String.raw`\s`, 1],
27
+ [String.raw`\d`, 256],
28
+ [LETTER_DASH_NUMBER, 250]
29
+ ];
30
+ for (const [token, maximum] of replacements) source = source.split(`${token}*`).join(`${token}{0,${maximum}}`).split(`${token}+`).join(`${token}{1,${maximum}}`);
31
+ return source;
32
+ }
33
+ function safeRegex(source, flags) {
34
+ return new RegExp(makeSafeRegexSource(source), flags);
35
+ }
36
+ const FULL = safeRegex(`^${FULL_PLAIN}$`);
37
+ const LOOSE = safeRegex(`^${LOOSE_PLAIN}$`);
38
+ const NUMERIC$1 = /^\d+$/;
39
+ function formatComparableVersion(version) {
40
+ const base = `${version.major}.${version.minor}.${version.patch}`;
41
+ return version.prerelease?.length ? `${base}-${version.prerelease.join(".")}` : base;
42
+ }
43
+ function formatFullVersion(version) {
44
+ const comparable = formatComparableVersion(version);
45
+ return version.build?.length ? `${comparable}+${version.build.join(".")}` : comparable;
46
+ }
47
+ function parse(version, options = {}) {
48
+ if (typeof version !== "string") return version;
49
+ if (version.length > 256) throw new TypeError(`Version exceeds the maximum length of 256 characters`);
50
+ const match = version.trim().match(options.loose ? LOOSE : FULL);
51
+ if (!match) throw new TypeError(`Invalid version syntax: ${version}`);
52
+ const major = Number(match[1]);
53
+ const minor = Number(match[2]);
54
+ const patch = Number(match[3]);
55
+ if (major > Number.MAX_SAFE_INTEGER || major < 0) throw new TypeError(`Invalid major version: ${match[1]}`);
56
+ if (minor > Number.MAX_SAFE_INTEGER || minor < 0) throw new TypeError(`Invalid minor version: ${match[2]}`);
57
+ if (patch > Number.MAX_SAFE_INTEGER || patch < 0) throw new TypeError(`Invalid patch version: ${match[3]}`);
58
+ const prerelease = match[4] ? match[4].split(".").map((identifier) => {
59
+ if (NUMERIC$1.test(identifier)) {
60
+ const numeric = Number(identifier);
61
+ if (numeric >= 0 && numeric < Number.MAX_SAFE_INTEGER) return numeric;
62
+ }
63
+ return identifier;
64
+ }) : void 0;
65
+ return {
66
+ build: match[5]?.split("."),
67
+ major,
68
+ minor,
69
+ patch,
70
+ prerelease
71
+ };
72
+ }
73
+ function tryParse(version, options = {}) {
74
+ try {
75
+ return parse(version, options);
76
+ } catch {
77
+ return null;
78
+ }
79
+ }
80
+ //#endregion
81
+ //#region ../../node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/version-CQ98ZBpL.js
82
+ const COERCE_EXACT = safeRegex(COERCE);
83
+ const COERCE_FULL_EXACT = safeRegex(COERCE_FULL);
84
+ safeRegex(`^${PRERELEASE}$`);
85
+ safeRegex(`^${PRERELEASE_LOOSE}$`);
86
+ function normalizeFull(version, options = {}) {
87
+ const parsed = tryParse(version, options);
88
+ return parsed ? formatFullVersion(parsed) : null;
89
+ }
90
+ function coerce(value, options = {}) {
91
+ if (typeof value === "object") return value;
92
+ const input = typeof value === "number" ? String(value) : value;
93
+ let match = null;
94
+ if (options.rtl) {
95
+ const expression = safeRegex(options.includePrerelease ? COERCE_FULL : COERCE, "g");
96
+ let next;
97
+ while ((next = expression.exec(input)) && (!match || match.index + match[0].length !== input.length)) {
98
+ if (!match || next.index + next[0].length !== match.index + match[0].length) match = next;
99
+ expression.lastIndex = next.index + next[1].length + next[2].length;
100
+ }
101
+ } else match = (options.includePrerelease ? COERCE_FULL_EXACT : COERCE_EXACT).exec(input);
102
+ if (!match) return null;
103
+ const major = match[2];
104
+ return tryParse(`${major}.${match[3] || "0"}.${match[4] || "0"}${options.includePrerelease && match[5] ? `-${match[5]}` : ""}${options.includePrerelease && match[6] ? `+${match[6]}` : ""}`, options);
105
+ }
106
+ //#endregion
107
+ //#region src/appVersion.ts
108
+ /**
109
+ * The form of an app version that the device and the server compare:
110
+ * `major.minor.patch` of the first version in `appVersion`, such as `1.4.0`
111
+ * for `v1.4`, or null when it holds none. Prerelease and build parts are
112
+ * dropped.
113
+ */
114
+ function canonicalizeAppVersion(appVersion) {
115
+ const version = coerce(appVersion);
116
+ return version ? normalizeFull(version) : null;
117
+ }
118
+ //#endregion
119
+ //#region src/releaseCatalogScope.ts
120
+ const BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
121
+ const MAX_CATALOG_SEGMENT_LENGTH = 255;
122
+ function assertCatalogSegment(value, name) {
123
+ if (value.length === 0 || value.length > MAX_CATALOG_SEGMENT_LENGTH || !/^[A-Za-z0-9._~-]+$/.test(value)) throw new Error(`${name} must be 1-${MAX_CATALOG_SEGMENT_LENGTH} URL-safe ASCII characters`);
124
+ }
125
+ function encodeUtf8(value) {
126
+ const bytes = [];
127
+ for (const codePointText of value) {
128
+ const codePoint = codePointText.codePointAt(0);
129
+ if (codePoint <= 127) bytes.push(codePoint);
130
+ else if (codePoint <= 2047) bytes.push(192 | codePoint >> 6, 128 | codePoint & 63);
131
+ else if (codePoint <= 65535) bytes.push(224 | codePoint >> 12, 128 | codePoint >> 6 & 63, 128 | codePoint & 63);
132
+ else bytes.push(240 | codePoint >> 18, 128 | codePoint >> 12 & 63, 128 | codePoint >> 6 & 63, 128 | codePoint & 63);
133
+ }
134
+ return bytes;
135
+ }
136
+ function decodeUtf8(bytes) {
137
+ let result = "";
138
+ for (let index = 0; index < bytes.length;) {
139
+ const first = bytes[index++];
140
+ let codePoint;
141
+ let continuationCount;
142
+ if (first <= 127) {
143
+ codePoint = first;
144
+ continuationCount = 0;
145
+ } else if ((first & 224) === 192) {
146
+ codePoint = first & 31;
147
+ continuationCount = 1;
148
+ } else if ((first & 240) === 224) {
149
+ codePoint = first & 15;
150
+ continuationCount = 2;
151
+ } else if ((first & 248) === 240) {
152
+ codePoint = first & 7;
153
+ continuationCount = 3;
154
+ } else throw new Error("Invalid UTF-8 channel key");
155
+ for (let offset = 0; offset < continuationCount; offset += 1) {
156
+ const continuation = bytes[index++];
157
+ if (continuation === void 0 || (continuation & 192) !== 128) throw new Error("Invalid UTF-8 channel key");
158
+ codePoint = codePoint << 6 | continuation & 63;
159
+ }
160
+ if (codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343 || continuationCount === 1 && codePoint < 128 || continuationCount === 2 && codePoint < 2048 || continuationCount === 3 && codePoint < 65536) throw new Error("Invalid UTF-8 channel key");
161
+ result += String.fromCodePoint(codePoint);
162
+ }
163
+ return result;
164
+ }
165
+ function base64UrlEncode(bytes) {
166
+ let result = "";
167
+ for (let index = 0; index < bytes.length; index += 3) {
168
+ const first = bytes[index];
169
+ const second = bytes[index + 1];
170
+ const third = bytes[index + 2];
171
+ const value = first << 16 | (second ?? 0) << 8 | (third ?? 0);
172
+ result += BASE64URL_ALPHABET[value >> 18 & 63];
173
+ result += BASE64URL_ALPHABET[value >> 12 & 63];
174
+ if (second !== void 0) result += BASE64URL_ALPHABET[value >> 6 & 63];
175
+ if (third !== void 0) result += BASE64URL_ALPHABET[value & 63];
176
+ }
177
+ return result;
178
+ }
179
+ function base64UrlDecode(value) {
180
+ if (!/^[A-Za-z0-9_-]*$/.test(value) || value.length % 4 === 1) throw new Error("Invalid channel key");
181
+ const bytes = [];
182
+ for (let index = 0; index < value.length; index += 4) {
183
+ const chunk = value.slice(index, index + 4);
184
+ const encoded = [...chunk].map((character) => BASE64URL_ALPHABET.indexOf(character));
185
+ if (encoded.some((part) => part < 0)) throw new Error("Invalid channel key");
186
+ const bits = encoded[0] << 18 | encoded[1] << 12 | (encoded[2] ?? 0) << 6 | (encoded[3] ?? 0);
187
+ bytes.push(bits >> 16 & 255);
188
+ if (chunk.length >= 3) bytes.push(bits >> 8 & 255);
189
+ if (chunk.length === 4) bytes.push(bits & 255);
190
+ }
191
+ return bytes;
192
+ }
193
+ function normalizeChannelName(channel) {
194
+ return channel.trim().normalize("NFC");
195
+ }
196
+ function assertCanonicalChannelName(channel) {
197
+ const normalized = normalizeChannelName(channel);
198
+ if (normalized.length === 0 || normalized !== channel) throw new Error("Channel name must be non-empty, trimmed, and NFC-normalized");
199
+ let codePointCount = 0;
200
+ for (const _codePoint of normalized) {
201
+ codePointCount += 1;
202
+ if (codePointCount > 255) throw new Error("Channel name must not exceed 255 characters");
203
+ }
204
+ }
205
+ function encodeChannelKey(channel) {
206
+ assertCanonicalChannelName(channel);
207
+ return base64UrlEncode(encodeUtf8(channel));
208
+ }
209
+ function decodeChannelKey(channelKey) {
210
+ const channel = decodeUtf8(base64UrlDecode(channelKey));
211
+ assertCanonicalChannelName(channel);
212
+ if (encodeChannelKey(channel) !== channelKey) throw new Error("Channel key is not canonically encoded");
213
+ return channel;
214
+ }
215
+ function createReleaseCatalogScopeKey(input) {
216
+ decodeChannelKey(input.channelKey);
217
+ if (input.strategy === "APP_VERSION") return `v1:app-version:${input.platform}:${input.channelKey}`;
218
+ assertCatalogSegment(input.fingerprintHash, "Fingerprint hash");
219
+ return `v1:fingerprint:${input.platform}:${input.channelKey}:${input.fingerprintHash}`;
220
+ }
221
+ function parseReleaseCatalogScopeKey(scopeKey) {
222
+ const segments = scopeKey.split(":");
223
+ const [version, strategy, platform, channelKey] = segments;
224
+ if (version !== "v1" || platform !== "ios" && platform !== "android" || channelKey === void 0) throw new Error("Invalid release catalog scope key");
225
+ const input = strategy === "app-version" && segments.length === 4 ? {
226
+ channelKey,
227
+ platform,
228
+ strategy: "APP_VERSION"
229
+ } : strategy === "fingerprint" && segments.length === 5 && segments[4] !== void 0 ? {
230
+ channelKey,
231
+ fingerprintHash: segments[4],
232
+ platform,
233
+ strategy: "FINGERPRINT"
234
+ } : (() => {
235
+ throw new Error("Invalid release catalog scope key");
236
+ })();
237
+ if (createReleaseCatalogScopeKey(input) !== scopeKey) throw new Error("Release catalog scope key is not canonical");
238
+ return input;
239
+ }
240
+ //#endregion
241
+ //#region src/uuid.ts
242
+ const NIL_UUID = "00000000-0000-0000-0000-000000000000";
243
+ const UUID_V7_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
244
+ const isUUIDv7 = (value) => typeof value === "string" && UUID_V7_PATTERN.test(value);
245
+ //#endregion
246
+ Object.defineProperty(exports, "NIL_UUID", {
247
+ enumerable: true,
248
+ get: function() {
249
+ return NIL_UUID;
250
+ }
251
+ });
252
+ Object.defineProperty(exports, "assertCanonicalChannelName", {
253
+ enumerable: true,
254
+ get: function() {
255
+ return assertCanonicalChannelName;
256
+ }
257
+ });
258
+ Object.defineProperty(exports, "canonicalizeAppVersion", {
259
+ enumerable: true,
260
+ get: function() {
261
+ return canonicalizeAppVersion;
262
+ }
263
+ });
264
+ Object.defineProperty(exports, "createReleaseCatalogScopeKey", {
265
+ enumerable: true,
266
+ get: function() {
267
+ return createReleaseCatalogScopeKey;
268
+ }
269
+ });
270
+ Object.defineProperty(exports, "decodeChannelKey", {
271
+ enumerable: true,
272
+ get: function() {
273
+ return decodeChannelKey;
274
+ }
275
+ });
276
+ Object.defineProperty(exports, "encodeChannelKey", {
277
+ enumerable: true,
278
+ get: function() {
279
+ return encodeChannelKey;
280
+ }
281
+ });
282
+ Object.defineProperty(exports, "isUUIDv7", {
283
+ enumerable: true,
284
+ get: function() {
285
+ return isUUIDv7;
286
+ }
287
+ });
288
+ Object.defineProperty(exports, "normalizeChannelName", {
289
+ enumerable: true,
290
+ get: function() {
291
+ return normalizeChannelName;
292
+ }
293
+ });
294
+ Object.defineProperty(exports, "parseReleaseCatalogScopeKey", {
295
+ enumerable: true,
296
+ get: function() {
297
+ return parseReleaseCatalogScopeKey;
298
+ }
299
+ });
@@ -0,0 +1,246 @@
1
+ //#region ../../node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/comparison-DenM3wCn.js
2
+ const LETTER_DASH_NUMBER = "[a-zA-Z0-9-]";
3
+ const NUMERIC_IDENTIFIER = String.raw`0|[1-9]\d*`;
4
+ const NUMERIC_IDENTIFIER_LOOSE = String.raw`\d+`;
5
+ const NON_NUMERIC_IDENTIFIER = String.raw`\d*[a-zA-Z-]${LETTER_DASH_NUMBER}*`;
6
+ const MAIN_VERSION = String.raw`(${NUMERIC_IDENTIFIER})\.(${NUMERIC_IDENTIFIER})\.(${NUMERIC_IDENTIFIER})`;
7
+ const MAIN_VERSION_LOOSE = String.raw`(${NUMERIC_IDENTIFIER_LOOSE})\.(${NUMERIC_IDENTIFIER_LOOSE})\.(${NUMERIC_IDENTIFIER_LOOSE})`;
8
+ const PRERELEASE_IDENTIFIER = `(?:${NON_NUMERIC_IDENTIFIER}|${NUMERIC_IDENTIFIER})`;
9
+ const PRERELEASE_IDENTIFIER_LOOSE = `(?:${NON_NUMERIC_IDENTIFIER}|${NUMERIC_IDENTIFIER_LOOSE})`;
10
+ const PRERELEASE = String.raw`(?:-(${PRERELEASE_IDENTIFIER}(?:\.${PRERELEASE_IDENTIFIER})*))`;
11
+ const PRERELEASE_LOOSE = String.raw`(?:-?(${PRERELEASE_IDENTIFIER_LOOSE}(?:\.${PRERELEASE_IDENTIFIER_LOOSE})*))`;
12
+ const BUILD_IDENTIFIER = `${LETTER_DASH_NUMBER}+`;
13
+ const BUILD = String.raw`(?:\+(${BUILD_IDENTIFIER}(?:\.${BUILD_IDENTIFIER})*))`;
14
+ const FULL_PLAIN = `v?${MAIN_VERSION}${PRERELEASE}?${BUILD}?`;
15
+ const LOOSE_PLAIN = String.raw`[v=\s]*${MAIN_VERSION_LOOSE}${PRERELEASE_LOOSE}?${BUILD}?`;
16
+ const XRANGE_IDENTIFIER = String.raw`${NUMERIC_IDENTIFIER}|x|X|\*`;
17
+ const XRANGE_IDENTIFIER_LOOSE = String.raw`${NUMERIC_IDENTIFIER_LOOSE}|x|X|\*`;
18
+ String.raw`[v=\s]*(${XRANGE_IDENTIFIER})(?:\.(${XRANGE_IDENTIFIER})(?:\.(${XRANGE_IDENTIFIER})(?:${PRERELEASE})?${BUILD}?)?)?`;
19
+ String.raw`[v=\s]*(${XRANGE_IDENTIFIER_LOOSE})(?:\.(${XRANGE_IDENTIFIER_LOOSE})(?:\.(${XRANGE_IDENTIFIER_LOOSE})(?:${PRERELEASE_LOOSE})?${BUILD}?)?)?`;
20
+ String.raw`(?:\^)`;
21
+ const COERCE_PLAIN = String.raw`(^|[^\d])(\d{1,${16}})(?:\.(\d{1,${16}}))?(?:\.(\d{1,${16}}))?`;
22
+ const COERCE = String.raw`${COERCE_PLAIN}(?:$|[^\d])`;
23
+ const COERCE_FULL = String.raw`${COERCE_PLAIN}(?:${PRERELEASE})?(?:${BUILD})?(?:$|[^\d])`;
24
+ function makeSafeRegexSource(source) {
25
+ const replacements = [
26
+ [String.raw`\s`, 1],
27
+ [String.raw`\d`, 256],
28
+ [LETTER_DASH_NUMBER, 250]
29
+ ];
30
+ for (const [token, maximum] of replacements) source = source.split(`${token}*`).join(`${token}{0,${maximum}}`).split(`${token}+`).join(`${token}{1,${maximum}}`);
31
+ return source;
32
+ }
33
+ function safeRegex(source, flags) {
34
+ return new RegExp(makeSafeRegexSource(source), flags);
35
+ }
36
+ const FULL = safeRegex(`^${FULL_PLAIN}$`);
37
+ const LOOSE = safeRegex(`^${LOOSE_PLAIN}$`);
38
+ const NUMERIC$1 = /^\d+$/;
39
+ function formatComparableVersion(version) {
40
+ const base = `${version.major}.${version.minor}.${version.patch}`;
41
+ return version.prerelease?.length ? `${base}-${version.prerelease.join(".")}` : base;
42
+ }
43
+ function formatFullVersion(version) {
44
+ const comparable = formatComparableVersion(version);
45
+ return version.build?.length ? `${comparable}+${version.build.join(".")}` : comparable;
46
+ }
47
+ function parse(version, options = {}) {
48
+ if (typeof version !== "string") return version;
49
+ if (version.length > 256) throw new TypeError(`Version exceeds the maximum length of 256 characters`);
50
+ const match = version.trim().match(options.loose ? LOOSE : FULL);
51
+ if (!match) throw new TypeError(`Invalid version syntax: ${version}`);
52
+ const major = Number(match[1]);
53
+ const minor = Number(match[2]);
54
+ const patch = Number(match[3]);
55
+ if (major > Number.MAX_SAFE_INTEGER || major < 0) throw new TypeError(`Invalid major version: ${match[1]}`);
56
+ if (minor > Number.MAX_SAFE_INTEGER || minor < 0) throw new TypeError(`Invalid minor version: ${match[2]}`);
57
+ if (patch > Number.MAX_SAFE_INTEGER || patch < 0) throw new TypeError(`Invalid patch version: ${match[3]}`);
58
+ const prerelease = match[4] ? match[4].split(".").map((identifier) => {
59
+ if (NUMERIC$1.test(identifier)) {
60
+ const numeric = Number(identifier);
61
+ if (numeric >= 0 && numeric < Number.MAX_SAFE_INTEGER) return numeric;
62
+ }
63
+ return identifier;
64
+ }) : void 0;
65
+ return {
66
+ build: match[5]?.split("."),
67
+ major,
68
+ minor,
69
+ patch,
70
+ prerelease
71
+ };
72
+ }
73
+ function tryParse(version, options = {}) {
74
+ try {
75
+ return parse(version, options);
76
+ } catch {
77
+ return null;
78
+ }
79
+ }
80
+ //#endregion
81
+ //#region ../../node_modules/.pnpm/verkit@0.4.0/node_modules/verkit/dist/version-CQ98ZBpL.js
82
+ const COERCE_EXACT = safeRegex(COERCE);
83
+ const COERCE_FULL_EXACT = safeRegex(COERCE_FULL);
84
+ safeRegex(`^${PRERELEASE}$`);
85
+ safeRegex(`^${PRERELEASE_LOOSE}$`);
86
+ function normalizeFull(version, options = {}) {
87
+ const parsed = tryParse(version, options);
88
+ return parsed ? formatFullVersion(parsed) : null;
89
+ }
90
+ function coerce(value, options = {}) {
91
+ if (typeof value === "object") return value;
92
+ const input = typeof value === "number" ? String(value) : value;
93
+ let match = null;
94
+ if (options.rtl) {
95
+ const expression = safeRegex(options.includePrerelease ? COERCE_FULL : COERCE, "g");
96
+ let next;
97
+ while ((next = expression.exec(input)) && (!match || match.index + match[0].length !== input.length)) {
98
+ if (!match || next.index + next[0].length !== match.index + match[0].length) match = next;
99
+ expression.lastIndex = next.index + next[1].length + next[2].length;
100
+ }
101
+ } else match = (options.includePrerelease ? COERCE_FULL_EXACT : COERCE_EXACT).exec(input);
102
+ if (!match) return null;
103
+ const major = match[2];
104
+ return tryParse(`${major}.${match[3] || "0"}.${match[4] || "0"}${options.includePrerelease && match[5] ? `-${match[5]}` : ""}${options.includePrerelease && match[6] ? `+${match[6]}` : ""}`, options);
105
+ }
106
+ //#endregion
107
+ //#region src/appVersion.ts
108
+ /**
109
+ * The form of an app version that the device and the server compare:
110
+ * `major.minor.patch` of the first version in `appVersion`, such as `1.4.0`
111
+ * for `v1.4`, or null when it holds none. Prerelease and build parts are
112
+ * dropped.
113
+ */
114
+ function canonicalizeAppVersion(appVersion) {
115
+ const version = coerce(appVersion);
116
+ return version ? normalizeFull(version) : null;
117
+ }
118
+ //#endregion
119
+ //#region src/releaseCatalogScope.ts
120
+ const BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
121
+ const MAX_CATALOG_SEGMENT_LENGTH = 255;
122
+ function assertCatalogSegment(value, name) {
123
+ if (value.length === 0 || value.length > MAX_CATALOG_SEGMENT_LENGTH || !/^[A-Za-z0-9._~-]+$/.test(value)) throw new Error(`${name} must be 1-${MAX_CATALOG_SEGMENT_LENGTH} URL-safe ASCII characters`);
124
+ }
125
+ function encodeUtf8(value) {
126
+ const bytes = [];
127
+ for (const codePointText of value) {
128
+ const codePoint = codePointText.codePointAt(0);
129
+ if (codePoint <= 127) bytes.push(codePoint);
130
+ else if (codePoint <= 2047) bytes.push(192 | codePoint >> 6, 128 | codePoint & 63);
131
+ else if (codePoint <= 65535) bytes.push(224 | codePoint >> 12, 128 | codePoint >> 6 & 63, 128 | codePoint & 63);
132
+ else bytes.push(240 | codePoint >> 18, 128 | codePoint >> 12 & 63, 128 | codePoint >> 6 & 63, 128 | codePoint & 63);
133
+ }
134
+ return bytes;
135
+ }
136
+ function decodeUtf8(bytes) {
137
+ let result = "";
138
+ for (let index = 0; index < bytes.length;) {
139
+ const first = bytes[index++];
140
+ let codePoint;
141
+ let continuationCount;
142
+ if (first <= 127) {
143
+ codePoint = first;
144
+ continuationCount = 0;
145
+ } else if ((first & 224) === 192) {
146
+ codePoint = first & 31;
147
+ continuationCount = 1;
148
+ } else if ((first & 240) === 224) {
149
+ codePoint = first & 15;
150
+ continuationCount = 2;
151
+ } else if ((first & 248) === 240) {
152
+ codePoint = first & 7;
153
+ continuationCount = 3;
154
+ } else throw new Error("Invalid UTF-8 channel key");
155
+ for (let offset = 0; offset < continuationCount; offset += 1) {
156
+ const continuation = bytes[index++];
157
+ if (continuation === void 0 || (continuation & 192) !== 128) throw new Error("Invalid UTF-8 channel key");
158
+ codePoint = codePoint << 6 | continuation & 63;
159
+ }
160
+ if (codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343 || continuationCount === 1 && codePoint < 128 || continuationCount === 2 && codePoint < 2048 || continuationCount === 3 && codePoint < 65536) throw new Error("Invalid UTF-8 channel key");
161
+ result += String.fromCodePoint(codePoint);
162
+ }
163
+ return result;
164
+ }
165
+ function base64UrlEncode(bytes) {
166
+ let result = "";
167
+ for (let index = 0; index < bytes.length; index += 3) {
168
+ const first = bytes[index];
169
+ const second = bytes[index + 1];
170
+ const third = bytes[index + 2];
171
+ const value = first << 16 | (second ?? 0) << 8 | (third ?? 0);
172
+ result += BASE64URL_ALPHABET[value >> 18 & 63];
173
+ result += BASE64URL_ALPHABET[value >> 12 & 63];
174
+ if (second !== void 0) result += BASE64URL_ALPHABET[value >> 6 & 63];
175
+ if (third !== void 0) result += BASE64URL_ALPHABET[value & 63];
176
+ }
177
+ return result;
178
+ }
179
+ function base64UrlDecode(value) {
180
+ if (!/^[A-Za-z0-9_-]*$/.test(value) || value.length % 4 === 1) throw new Error("Invalid channel key");
181
+ const bytes = [];
182
+ for (let index = 0; index < value.length; index += 4) {
183
+ const chunk = value.slice(index, index + 4);
184
+ const encoded = [...chunk].map((character) => BASE64URL_ALPHABET.indexOf(character));
185
+ if (encoded.some((part) => part < 0)) throw new Error("Invalid channel key");
186
+ const bits = encoded[0] << 18 | encoded[1] << 12 | (encoded[2] ?? 0) << 6 | (encoded[3] ?? 0);
187
+ bytes.push(bits >> 16 & 255);
188
+ if (chunk.length >= 3) bytes.push(bits >> 8 & 255);
189
+ if (chunk.length === 4) bytes.push(bits & 255);
190
+ }
191
+ return bytes;
192
+ }
193
+ function normalizeChannelName(channel) {
194
+ return channel.trim().normalize("NFC");
195
+ }
196
+ function assertCanonicalChannelName(channel) {
197
+ const normalized = normalizeChannelName(channel);
198
+ if (normalized.length === 0 || normalized !== channel) throw new Error("Channel name must be non-empty, trimmed, and NFC-normalized");
199
+ let codePointCount = 0;
200
+ for (const _codePoint of normalized) {
201
+ codePointCount += 1;
202
+ if (codePointCount > 255) throw new Error("Channel name must not exceed 255 characters");
203
+ }
204
+ }
205
+ function encodeChannelKey(channel) {
206
+ assertCanonicalChannelName(channel);
207
+ return base64UrlEncode(encodeUtf8(channel));
208
+ }
209
+ function decodeChannelKey(channelKey) {
210
+ const channel = decodeUtf8(base64UrlDecode(channelKey));
211
+ assertCanonicalChannelName(channel);
212
+ if (encodeChannelKey(channel) !== channelKey) throw new Error("Channel key is not canonically encoded");
213
+ return channel;
214
+ }
215
+ function createReleaseCatalogScopeKey(input) {
216
+ decodeChannelKey(input.channelKey);
217
+ if (input.strategy === "APP_VERSION") return `v1:app-version:${input.platform}:${input.channelKey}`;
218
+ assertCatalogSegment(input.fingerprintHash, "Fingerprint hash");
219
+ return `v1:fingerprint:${input.platform}:${input.channelKey}:${input.fingerprintHash}`;
220
+ }
221
+ function parseReleaseCatalogScopeKey(scopeKey) {
222
+ const segments = scopeKey.split(":");
223
+ const [version, strategy, platform, channelKey] = segments;
224
+ if (version !== "v1" || platform !== "ios" && platform !== "android" || channelKey === void 0) throw new Error("Invalid release catalog scope key");
225
+ const input = strategy === "app-version" && segments.length === 4 ? {
226
+ channelKey,
227
+ platform,
228
+ strategy: "APP_VERSION"
229
+ } : strategy === "fingerprint" && segments.length === 5 && segments[4] !== void 0 ? {
230
+ channelKey,
231
+ fingerprintHash: segments[4],
232
+ platform,
233
+ strategy: "FINGERPRINT"
234
+ } : (() => {
235
+ throw new Error("Invalid release catalog scope key");
236
+ })();
237
+ if (createReleaseCatalogScopeKey(input) !== scopeKey) throw new Error("Release catalog scope key is not canonical");
238
+ return input;
239
+ }
240
+ //#endregion
241
+ //#region src/uuid.ts
242
+ const NIL_UUID = "00000000-0000-0000-0000-000000000000";
243
+ const UUID_V7_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
244
+ const isUUIDv7 = (value) => typeof value === "string" && UUID_V7_PATTERN.test(value);
245
+ //#endregion
246
+ export { decodeChannelKey as a, parseReleaseCatalogScopeKey as c, createReleaseCatalogScopeKey as i, canonicalizeAppVersion as l, isUUIDv7 as n, encodeChannelKey as o, assertCanonicalChannelName as r, normalizeChannelName as s, NIL_UUID as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/protocol",
3
- "version": "1.1.4",
3
+ "version": "1.2.0-rc.1",
4
4
  "type": "module",
5
5
  "description": "The data formats and pure computations that Hot Updater's app and server share",
6
6
  "sideEffects": false,
@@ -12,6 +12,10 @@
12
12
  "import": "./dist/index.mjs",
13
13
  "require": "./dist/index.cjs"
14
14
  },
15
+ "./native-artifact": {
16
+ "import": "./dist/native-artifact.mjs",
17
+ "require": "./dist/native-artifact.cjs"
18
+ },
15
19
  "./package.json": "./package.json"
16
20
  },
17
21
  "files": [
@@ -43,6 +47,7 @@
43
47
  },
44
48
  "devDependencies": {
45
49
  "@types/node": "^20",
50
+ "jszip": "^3.10.1",
46
51
  "verkit": "0.4.0"
47
52
  },
48
53
  "inlinedDependencies": {