@renbostudios/edge-ota 0.2.5 → 0.2.7
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/manifest.js +25 -3
- package/dist/index.js +5 -18
- package/package.json +1 -1
package/dist/core/manifest.js
CHANGED
|
@@ -12,18 +12,39 @@
|
|
|
12
12
|
* The client SDK deserialises this from the `manifest` part of the
|
|
13
13
|
* multipart response (or directly from the response body in non-multipart mode).
|
|
14
14
|
*/
|
|
15
|
+
function hexToBase64Url(hex) {
|
|
16
|
+
if (hex.length !== 64 || !/^[0-9a-fA-F]+$/.test(hex)) {
|
|
17
|
+
return hex;
|
|
18
|
+
}
|
|
19
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
20
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
21
|
+
bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
22
|
+
}
|
|
23
|
+
let binString = "";
|
|
24
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
25
|
+
binString += String.fromCharCode(bytes[i]);
|
|
26
|
+
}
|
|
27
|
+
const base64 = btoa(binString);
|
|
28
|
+
return base64
|
|
29
|
+
.replace(/\+/g, '-')
|
|
30
|
+
.replace(/\//g, '_')
|
|
31
|
+
.replace(/=+$/, '');
|
|
32
|
+
}
|
|
15
33
|
export function generateExpoManifest(params) {
|
|
16
34
|
return {
|
|
17
35
|
id: params.updateId,
|
|
18
36
|
createdAt: params.createdAt,
|
|
19
37
|
runtimeVersion: params.runtimeVersion,
|
|
20
38
|
launchAsset: {
|
|
21
|
-
hash: params.bundleHash,
|
|
39
|
+
hash: hexToBase64Url(params.bundleHash),
|
|
22
40
|
key: "bundle",
|
|
23
41
|
contentType: "application/javascript",
|
|
24
42
|
url: params.bundleUrl
|
|
25
43
|
},
|
|
26
|
-
assets: params.assets
|
|
44
|
+
assets: params.assets.map(asset => ({
|
|
45
|
+
...asset,
|
|
46
|
+
hash: hexToBase64Url(asset.hash)
|
|
47
|
+
})),
|
|
27
48
|
metadata: params.metadata ?? {},
|
|
28
49
|
extra: params.extra ?? {}
|
|
29
50
|
};
|
|
@@ -66,7 +87,8 @@ export function createExpoHeaders(signature) {
|
|
|
66
87
|
export function buildMultipartManifestBody(manifest, signature) {
|
|
67
88
|
const boundary = "expo-update-boundary-" + Math.random().toString(36).slice(2, 10);
|
|
68
89
|
const manifestJson = JSON.stringify(manifest);
|
|
69
|
-
let partHeaders = "Content-
|
|
90
|
+
let partHeaders = "Content-Disposition: inline; name=\"manifest\"\r\n";
|
|
91
|
+
partHeaders += "Content-Type: application/json\r\n";
|
|
70
92
|
if (signature) {
|
|
71
93
|
partHeaders += `expo-signature: sig="${signature}", keyid="root", alg="ecdsa-p256-sha256"\r\n`;
|
|
72
94
|
}
|
package/dist/index.js
CHANGED
|
@@ -228,18 +228,8 @@ program
|
|
|
228
228
|
let projectId = options.project;
|
|
229
229
|
if (!serverUrl) {
|
|
230
230
|
console.log(` ${colors.dim}no --server flag provided${colors.reset}`);
|
|
231
|
-
const answer = await askQuestion(` server url [
|
|
232
|
-
|
|
233
|
-
serverUrl = "http://localhost:3000";
|
|
234
|
-
}
|
|
235
|
-
else if (answer.toLowerCase().includes("host")) {
|
|
236
|
-
console.log(` ${colors.yellow}hint${colors.reset} use your hosted EdgeOTA instance (e.g. https://api.edge-ota.renbo.site)`);
|
|
237
|
-
const hostedAnswer = await askQuestion(` hosted server url: `);
|
|
238
|
-
serverUrl = hostedAnswer.trim() || "http://localhost:3000";
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
serverUrl = answer;
|
|
242
|
-
}
|
|
231
|
+
const answer = await askQuestion(` server url [https://api.edge-ota.renbo.site]: `);
|
|
232
|
+
serverUrl = answer.trim() || "https://api.edge-ota.renbo.site";
|
|
243
233
|
}
|
|
244
234
|
if (!projectId && !options.server) {
|
|
245
235
|
const pAnswer = await askQuestion(` project id (optional, press Enter to skip): `);
|
|
@@ -363,12 +353,10 @@ program
|
|
|
363
353
|
console.log(" payload ", payloadObj);
|
|
364
354
|
continue;
|
|
365
355
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
await zipDirectory(distDir, zipPath);
|
|
369
|
-
const zipBuffer = fs.readFileSync(zipPath);
|
|
356
|
+
console.log(` packing bundle`);
|
|
357
|
+
const bundleBuffer = fs.readFileSync(bundlePath);
|
|
370
358
|
const form = new FormData();
|
|
371
|
-
form.append("bundle", new Blob([
|
|
359
|
+
form.append("bundle", new Blob([bundleBuffer], { type: "application/javascript" }), `bundle-${platform}.hbc`);
|
|
372
360
|
form.append("payload", payloadStr);
|
|
373
361
|
form.append("signature", signature);
|
|
374
362
|
form.append("platform", platform);
|
|
@@ -381,7 +369,6 @@ program
|
|
|
381
369
|
},
|
|
382
370
|
body: form
|
|
383
371
|
});
|
|
384
|
-
fs.unlinkSync(zipPath);
|
|
385
372
|
if (response.ok) {
|
|
386
373
|
const body = await response.json().catch(() => ({}));
|
|
387
374
|
const updateId = body.updateId || "unknown";
|
package/package.json
CHANGED