@limrun/api 0.79.6 → 0.80.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.
- package/CHANGELOG.md +41 -0
- package/client.d.mts +4 -1
- package/client.d.mts.map +1 -1
- package/client.d.ts +4 -1
- package/client.d.ts.map +1 -1
- package/client.js +1 -1
- package/client.js.map +1 -1
- package/client.mjs +1 -1
- package/client.mjs.map +1 -1
- package/exec-client.d.mts +64 -15
- package/exec-client.d.mts.map +1 -1
- package/exec-client.d.ts +64 -15
- package/exec-client.d.ts.map +1 -1
- package/exec-client.js.map +1 -1
- package/exec-client.mjs.map +1 -1
- package/folder-sync.d.mts +2 -0
- package/folder-sync.d.mts.map +1 -1
- package/folder-sync.d.ts +2 -0
- package/folder-sync.d.ts.map +1 -1
- package/folder-sync.js +1 -1
- package/folder-sync.js.map +1 -1
- package/folder-sync.mjs +1 -1
- package/folder-sync.mjs.map +1 -1
- package/index.d.mts +2 -2
- package/index.d.mts.map +1 -1
- package/index.d.ts +2 -2
- package/index.d.ts.map +1 -1
- package/index.js.map +1 -1
- package/index.mjs.map +1 -1
- package/instance-client.d.mts +43 -3
- package/instance-client.d.mts.map +1 -1
- package/instance-client.d.ts +43 -3
- package/instance-client.d.ts.map +1 -1
- package/instance-client.js +44 -55
- package/instance-client.js.map +1 -1
- package/instance-client.mjs +43 -55
- package/instance-client.mjs.map +1 -1
- package/internal/asset-source.d.mts +11 -0
- package/internal/asset-source.d.mts.map +1 -0
- package/internal/asset-source.d.ts +11 -0
- package/internal/asset-source.d.ts.map +1 -0
- package/internal/asset-source.js +15 -0
- package/internal/asset-source.js.map +1 -0
- package/internal/asset-source.mjs +12 -0
- package/internal/asset-source.mjs.map +1 -0
- package/internal/file-transfer.d.mts +43 -0
- package/internal/file-transfer.d.mts.map +1 -0
- package/internal/file-transfer.d.ts +43 -0
- package/internal/file-transfer.d.ts.map +1 -0
- package/internal/file-transfer.js +270 -0
- package/internal/file-transfer.js.map +1 -0
- package/internal/file-transfer.mjs +261 -0
- package/internal/file-transfer.mjs.map +1 -0
- package/ios-client.d.mts +23 -4
- package/ios-client.d.mts.map +1 -1
- package/ios-client.d.ts +23 -4
- package/ios-client.d.ts.map +1 -1
- package/ios-client.js +11 -2
- package/ios-client.js.map +1 -1
- package/ios-client.mjs +11 -2
- package/ios-client.mjs.map +1 -1
- package/lib/workload-credentials.d.mts +2 -1
- package/lib/workload-credentials.d.mts.map +1 -1
- package/lib/workload-credentials.d.ts +2 -1
- package/lib/workload-credentials.d.ts.map +1 -1
- package/lib/workload-credentials.js +3 -0
- package/lib/workload-credentials.js.map +1 -1
- package/lib/workload-credentials.mjs +3 -0
- package/lib/workload-credentials.mjs.map +1 -1
- package/package.json +2 -1
- package/resources/access-tokens.d.mts +17 -0
- package/resources/access-tokens.d.mts.map +1 -1
- package/resources/access-tokens.d.ts +17 -0
- package/resources/access-tokens.d.ts.map +1 -1
- package/resources/access-tokens.js +39 -3
- package/resources/access-tokens.js.map +1 -1
- package/resources/access-tokens.mjs +36 -2
- package/resources/access-tokens.mjs.map +1 -1
- package/resources/assets.d.mts +6 -0
- package/resources/assets.d.mts.map +1 -1
- package/resources/assets.d.ts +6 -0
- package/resources/assets.d.ts.map +1 -1
- package/resources/index.d.mts +1 -1
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +1 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/macos-instances-helpers.d.mts +112 -0
- package/resources/macos-instances-helpers.d.mts.map +1 -1
- package/resources/macos-instances-helpers.d.ts +112 -0
- package/resources/macos-instances-helpers.d.ts.map +1 -1
- package/resources/macos-instances-helpers.js +105 -0
- package/resources/macos-instances-helpers.js.map +1 -1
- package/resources/macos-instances-helpers.mjs +104 -0
- package/resources/macos-instances-helpers.mjs.map +1 -1
- package/resources/scoped-tokens.d.mts +2 -2
- package/resources/scoped-tokens.d.mts.map +1 -1
- package/resources/scoped-tokens.d.ts +2 -2
- package/resources/scoped-tokens.d.ts.map +1 -1
- package/resources/scoped-tokens.js +9 -2
- package/resources/scoped-tokens.js.map +1 -1
- package/resources/scoped-tokens.mjs +9 -2
- package/resources/scoped-tokens.mjs.map +1 -1
- package/resources/session-artifacts.d.mts +7 -4
- package/resources/session-artifacts.d.mts.map +1 -1
- package/resources/session-artifacts.d.ts +7 -4
- package/resources/session-artifacts.d.ts.map +1 -1
- package/resources/xcode-instances-helpers.d.mts +33 -18
- package/resources/xcode-instances-helpers.d.mts.map +1 -1
- package/resources/xcode-instances-helpers.d.ts +33 -18
- package/resources/xcode-instances-helpers.d.ts.map +1 -1
- package/resources/xcode-instances-helpers.js +5 -2
- package/resources/xcode-instances-helpers.js.map +1 -1
- package/resources/xcode-instances-helpers.mjs +5 -2
- package/resources/xcode-instances-helpers.mjs.map +1 -1
- package/src/client.ts +5 -2
- package/src/exec-client.ts +77 -22
- package/src/folder-sync.ts +3 -1
- package/src/index.ts +9 -0
- package/src/instance-client.ts +87 -60
- package/src/internal/asset-source.ts +13 -0
- package/src/internal/file-transfer.ts +284 -0
- package/src/ios-client.ts +43 -6
- package/src/lib/workload-credentials.ts +6 -1
- package/src/resources/access-tokens.ts +39 -2
- package/src/resources/assets.ts +7 -0
- package/src/resources/index.ts +4 -0
- package/src/resources/macos-instances-helpers.ts +257 -0
- package/src/resources/scoped-tokens.ts +14 -3
- package/src/resources/session-artifacts.ts +7 -4
- package/src/resources/xcode-instances-helpers.ts +49 -19
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { Readable } from 'stream';
|
|
4
|
+
import * as zlib from 'zlib';
|
|
5
|
+
import * as tarStream from 'tar-stream';
|
|
6
|
+
|
|
7
|
+
import { nodeProxyTransport } from './proxy-transport';
|
|
8
|
+
|
|
9
|
+
/** The Content-Type of a folder an instance sends as a tar. */
|
|
10
|
+
export const TAR_CONTENT_TYPE = 'application/x-tar';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The header saying a pull's body is zstd-compressed. A pull asks for it with `compression=zstd`;
|
|
14
|
+
* a server that predates it sends neither. It is not Content-Encoding, so fetch never decodes the
|
|
15
|
+
* body on its own.
|
|
16
|
+
*/
|
|
17
|
+
export const COMPRESSION_HEADER = 'x-limrun-compression';
|
|
18
|
+
|
|
19
|
+
// Node has zstd from 22.15; an older Node pulls and pushes uncompressed.
|
|
20
|
+
const zstdCompress = (zlib as any).createZstdCompress as
|
|
21
|
+
| ((options?: object) => NodeJS.ReadWriteStream)
|
|
22
|
+
| undefined;
|
|
23
|
+
const zstdDecompress = (zlib as any).createZstdDecompress as (() => NodeJS.ReadWriteStream) | undefined;
|
|
24
|
+
|
|
25
|
+
/** pullQuery is the query a pull adds to its URL: a folder as a tar, compressed when Node can read it. */
|
|
26
|
+
export function pullQuery(): string {
|
|
27
|
+
return zstdDecompress ? 'archive=tar&compression=zstd' : 'archive=tar';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* pushFile PUTs a local file to `url`, compressed with zstd as it is read when `compress` is set
|
|
32
|
+
* and Node has zstd, and returns the `path` the instance answers with.
|
|
33
|
+
*/
|
|
34
|
+
export async function pushFile(
|
|
35
|
+
url: string,
|
|
36
|
+
token: string,
|
|
37
|
+
localPath: string,
|
|
38
|
+
compress: boolean,
|
|
39
|
+
): Promise<string> {
|
|
40
|
+
const size = (await fs.promises.stat(localPath)).size;
|
|
41
|
+
const file = fs.createReadStream(localPath);
|
|
42
|
+
const zstd =
|
|
43
|
+
compress && zstdCompress ?
|
|
44
|
+
zstdCompress({ params: { [(zlib as any).constants.ZSTD_c_compressionLevel]: 3 } })
|
|
45
|
+
: undefined;
|
|
46
|
+
const headers: Record<string, string> = {
|
|
47
|
+
'Content-Type': 'application/octet-stream',
|
|
48
|
+
Authorization: `Bearer ${token}`,
|
|
49
|
+
};
|
|
50
|
+
let body: Readable = file;
|
|
51
|
+
if (zstd) {
|
|
52
|
+
headers['Content-Encoding'] = 'zstd';
|
|
53
|
+
file.on('error', (err) => (zstd as any).destroy(err));
|
|
54
|
+
body = file.pipe(zstd) as unknown as Readable;
|
|
55
|
+
} else {
|
|
56
|
+
headers['Content-Length'] = String(size);
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const response = await nodeProxyTransport.fetch(url, {
|
|
60
|
+
method: 'PUT',
|
|
61
|
+
headers,
|
|
62
|
+
body: body as any,
|
|
63
|
+
duplex: 'half',
|
|
64
|
+
} as any);
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
const errorBody = await response.text();
|
|
67
|
+
throw new Error(`Upload of '${localPath}' failed: ${response.status} ${errorBody}`);
|
|
68
|
+
}
|
|
69
|
+
return ((await response.json()) as { path: string }).path;
|
|
70
|
+
} finally {
|
|
71
|
+
file.destroy();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** What a pull wrote. */
|
|
76
|
+
export type PullResult = {
|
|
77
|
+
/** The absolute local path of the file or folder written. */
|
|
78
|
+
path: string;
|
|
79
|
+
/** True when the remote was a folder, unpacked into `path`. */
|
|
80
|
+
isDirectory: boolean;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* pullTarget is where a pull of `remote` into `local` writes: `local`, or `remote`'s base name
|
|
85
|
+
* inside it when `local` is an existing folder. Without `local`, the base name in the current
|
|
86
|
+
* directory.
|
|
87
|
+
*/
|
|
88
|
+
export async function pullTarget(remote: string, local?: string): Promise<string> {
|
|
89
|
+
const name = path.posix.basename(remote.replace(/\/+$/, ''));
|
|
90
|
+
const nameless = name === '' || name === '.' || name === '..' || name === '~';
|
|
91
|
+
if (local === undefined || local === '') {
|
|
92
|
+
if (nameless)
|
|
93
|
+
throw new Error(`"${remote}" has no name to save it under; pass the local path to write to`);
|
|
94
|
+
return path.resolve(name);
|
|
95
|
+
}
|
|
96
|
+
const target = path.resolve(local);
|
|
97
|
+
const stat = await fs.promises.stat(target).catch(() => null);
|
|
98
|
+
if (!stat?.isDirectory()) return target;
|
|
99
|
+
if (nameless) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`${target} is a folder and "${remote}" has no name to put inside it; pass the local path to write to`,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
return path.join(target, name);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* pullToLocalPath GETs `url`, whose query ends with {@link pullQuery}, and writes the answer to `target`: a
|
|
109
|
+
* tar is unpacked into the folder `target`, anything else is written to the file `target` through
|
|
110
|
+
* a temporary file renamed into place.
|
|
111
|
+
*/
|
|
112
|
+
export async function pullToLocalPath(
|
|
113
|
+
url: string,
|
|
114
|
+
token: string,
|
|
115
|
+
remote: string,
|
|
116
|
+
target: string,
|
|
117
|
+
): Promise<PullResult> {
|
|
118
|
+
const response = await nodeProxyTransport.fetch(url, {
|
|
119
|
+
method: 'GET',
|
|
120
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
121
|
+
});
|
|
122
|
+
if (!response.ok) {
|
|
123
|
+
const errorBody = await response.text();
|
|
124
|
+
throw new Error(`Pull of '${remote}' failed: ${response.status} ${errorBody}`);
|
|
125
|
+
}
|
|
126
|
+
if (!response.body) throw new Error(`Pull of '${remote}' failed: the response has no body`);
|
|
127
|
+
let source: AsyncIterable<Buffer> = Readable.fromWeb(response.body as any);
|
|
128
|
+
const compression = response.headers.get(COMPRESSION_HEADER);
|
|
129
|
+
if (compression) {
|
|
130
|
+
if (compression !== 'zstd' || !zstdDecompress) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`Pull of '${remote}' failed: the body is compressed with ${compression}, which this Node cannot read`,
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
const raw = source as Readable;
|
|
136
|
+
const decompress = zstdDecompress();
|
|
137
|
+
raw.on('error', (err) => (decompress as any).destroy(err));
|
|
138
|
+
source = raw.pipe(decompress) as unknown as AsyncIterable<Buffer>;
|
|
139
|
+
}
|
|
140
|
+
const mediaType = (response.headers.get('content-type') ?? '').split(';')[0]!.trim().toLowerCase();
|
|
141
|
+
if (mediaType === TAR_CONTENT_TYPE) {
|
|
142
|
+
await fs.promises.mkdir(target, { recursive: true });
|
|
143
|
+
await unpackTar(source, target);
|
|
144
|
+
return { path: target, isDirectory: true };
|
|
145
|
+
}
|
|
146
|
+
await writeFileAtomically(source, target);
|
|
147
|
+
return { path: target, isDirectory: false };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function writeFileAtomically(source: AsyncIterable<Buffer>, target: string): Promise<void> {
|
|
151
|
+
const dir = path.dirname(target);
|
|
152
|
+
await fs.promises.mkdir(dir, { recursive: true });
|
|
153
|
+
const temporary = path.join(
|
|
154
|
+
dir,
|
|
155
|
+
`.lim-pull-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
156
|
+
);
|
|
157
|
+
const handle = await fs.promises.open(temporary, 'wx', 0o644);
|
|
158
|
+
try {
|
|
159
|
+
try {
|
|
160
|
+
for await (const chunk of source) await handle.write(chunk);
|
|
161
|
+
} finally {
|
|
162
|
+
await handle.close();
|
|
163
|
+
}
|
|
164
|
+
await fs.promises.rename(temporary, target);
|
|
165
|
+
} catch (err) {
|
|
166
|
+
await fs.promises.rm(temporary, { force: true });
|
|
167
|
+
throw err;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* unpackTar extracts a tar into `dir`, an existing folder. Entries are relative to `dir`: an
|
|
173
|
+
* absolute name or one with a `..` component fails the unpack. Symlinks keep their targets, as tar
|
|
174
|
+
* keeps them, wherever they point: they are created after every file and folder, and nothing is
|
|
175
|
+
* written through a symlink, so a target outside `dir` is never written to. Entries other than
|
|
176
|
+
* files, folders and symlinks are skipped.
|
|
177
|
+
*/
|
|
178
|
+
export async function unpackTar(source: AsyncIterable<Buffer>, dir: string): Promise<void> {
|
|
179
|
+
const extract = tarStream.extract();
|
|
180
|
+
const input = Readable.from(source);
|
|
181
|
+
input.on('error', (err) => extract.destroy(err));
|
|
182
|
+
input.pipe(extract);
|
|
183
|
+
const links: { name: string; target: string }[] = [];
|
|
184
|
+
const folders: { path: string; mode: number; mtime: Date | undefined }[] = [];
|
|
185
|
+
try {
|
|
186
|
+
for await (const entry of extract) {
|
|
187
|
+
const header = entry.header;
|
|
188
|
+
const name = entryName(header.name);
|
|
189
|
+
const dst = name === '' ? dir : path.join(dir, ...name.split('/'));
|
|
190
|
+
const mode = (header.mode ?? 0o644) & 0o7777;
|
|
191
|
+
if (header.type === 'file' || header.type === 'contiguous-file') {
|
|
192
|
+
if (name === '') throw new Error('the tar has a file entry for its own folder');
|
|
193
|
+
await makeDirs(dir, path.posix.dirname(name));
|
|
194
|
+
await writeEntry(dst, entry as unknown as AsyncIterable<Buffer>, mode, header.mtime);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
entry.resume();
|
|
198
|
+
if (name === '') continue;
|
|
199
|
+
if (header.type === 'directory') {
|
|
200
|
+
await makeDirs(dir, name);
|
|
201
|
+
folders.push({ path: dst, mode, mtime: header.mtime });
|
|
202
|
+
} else if (header.type === 'symlink') {
|
|
203
|
+
if (!header.linkname) throw new Error(`the tar has a symlink "${name}" without a target`);
|
|
204
|
+
links.push({ name, target: header.linkname });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
} finally {
|
|
208
|
+
input.unpipe(extract);
|
|
209
|
+
input.destroy();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
for (const link of links) {
|
|
213
|
+
await makeDirs(dir, path.posix.dirname(link.name));
|
|
214
|
+
const dst = path.join(dir, ...link.name.split('/'));
|
|
215
|
+
await removeEntry(dst);
|
|
216
|
+
await fs.promises.symlink(link.target, dst);
|
|
217
|
+
}
|
|
218
|
+
// Folders get their modes and times last: writing into them changes their times, and a
|
|
219
|
+
// read-only folder could not be written into.
|
|
220
|
+
for (const folder of folders.reverse()) {
|
|
221
|
+
await fs.promises.chmod(folder.path, folder.mode | 0o700);
|
|
222
|
+
if (folder.mtime) await fs.promises.utimes(folder.path, folder.mtime, folder.mtime).catch(() => {});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** entryName returns an entry's name as a clean relative slash path, '' for the folder itself. */
|
|
227
|
+
function entryName(raw: string): string {
|
|
228
|
+
if (raw.startsWith('/') || path.isAbsolute(raw) || /^[A-Za-z]:/.test(raw)) {
|
|
229
|
+
throw new Error(`the tar has an absolute entry "${raw}"`);
|
|
230
|
+
}
|
|
231
|
+
const parts = raw.split('/');
|
|
232
|
+
if (parts.includes('..') || raw.includes('\\'))
|
|
233
|
+
throw new Error(`the tar has an entry outside its folder: "${raw}"`);
|
|
234
|
+
return parts.filter((part) => part !== '' && part !== '.').join('/');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** makeDirs creates the folders of `rel` under `root` one at a time, refusing links and files. */
|
|
238
|
+
async function makeDirs(root: string, rel: string): Promise<void> {
|
|
239
|
+
if (rel === '' || rel === '.') return;
|
|
240
|
+
let current = root;
|
|
241
|
+
for (const part of rel.split('/')) {
|
|
242
|
+
current = path.join(current, part);
|
|
243
|
+
const stat = await fs.promises.lstat(current).catch((err: NodeJS.ErrnoException) => {
|
|
244
|
+
if (err.code === 'ENOENT') return null;
|
|
245
|
+
throw err;
|
|
246
|
+
});
|
|
247
|
+
if (!stat) {
|
|
248
|
+
await fs.promises.mkdir(current, 0o755);
|
|
249
|
+
} else if (stat.isSymbolicLink()) {
|
|
250
|
+
throw new Error(`refusing to write through the symlink ${current}`);
|
|
251
|
+
} else if (!stat.isDirectory()) {
|
|
252
|
+
throw new Error(`${current} is a file, not a folder`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** removeEntry removes a file or symlink so a new entry replaces it rather than writing through it. */
|
|
258
|
+
async function removeEntry(dst: string): Promise<void> {
|
|
259
|
+
const stat = await fs.promises.lstat(dst).catch((err: NodeJS.ErrnoException) => {
|
|
260
|
+
if (err.code === 'ENOENT') return null;
|
|
261
|
+
throw err;
|
|
262
|
+
});
|
|
263
|
+
if (!stat) return;
|
|
264
|
+
if (stat.isDirectory()) throw new Error(`${dst} is a folder, not a file`);
|
|
265
|
+
await fs.promises.rm(dst);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async function writeEntry(
|
|
269
|
+
dst: string,
|
|
270
|
+
chunks: AsyncIterable<Buffer>,
|
|
271
|
+
mode: number,
|
|
272
|
+
mtime: Date | undefined,
|
|
273
|
+
): Promise<void> {
|
|
274
|
+
await removeEntry(dst);
|
|
275
|
+
// 'wx' fails rather than follow a symlink that appeared at dst.
|
|
276
|
+
const handle = await fs.promises.open(dst, 'wx', mode | 0o200);
|
|
277
|
+
try {
|
|
278
|
+
for await (const chunk of chunks) await handle.write(chunk);
|
|
279
|
+
} finally {
|
|
280
|
+
await handle.close();
|
|
281
|
+
}
|
|
282
|
+
if ((mode & 0o200) === 0) await fs.promises.chmod(dst, mode);
|
|
283
|
+
if (mtime) await fs.promises.utimes(dst, mtime, mtime).catch(() => {});
|
|
284
|
+
}
|
package/src/ios-client.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { assetSourceFields, type AssetSource } from './internal/asset-source';
|
|
2
|
+
export type { AssetSource } from './internal/asset-source';
|
|
1
3
|
import os from 'os';
|
|
2
4
|
import crypto from 'crypto';
|
|
3
5
|
import path from 'path';
|
|
@@ -16,6 +18,8 @@ import { prepareAppBundlePath, watchAppArchive } from './app-archive';
|
|
|
16
18
|
import { downloadFileToLocalPath } from './internal/download-file';
|
|
17
19
|
import { sleep } from './internal/utils/sleep';
|
|
18
20
|
import { nodeProxyTransport } from './internal/proxy-transport';
|
|
21
|
+
import { pullQuery, pullTarget, pullToLocalPath, type PullResult } from './internal/file-transfer';
|
|
22
|
+
export type { PullResult } from './internal/file-transfer';
|
|
19
23
|
import { requestBlockedDomains } from './internal/blocked-domains';
|
|
20
24
|
import { postTrustedCaCertificate } from './internal/trusted-ca';
|
|
21
25
|
import {
|
|
@@ -431,7 +435,9 @@ export type DeviceInfo = {
|
|
|
431
435
|
};
|
|
432
436
|
|
|
433
437
|
export type AppInstallationResult = {
|
|
434
|
-
/** The
|
|
438
|
+
/** The asset name supplied to installApp, when used. */
|
|
439
|
+
assetName?: string;
|
|
440
|
+
/** The supplied URL, or an empty string for a named asset. */
|
|
435
441
|
url: string;
|
|
436
442
|
/** Bundle ID of the installed app */
|
|
437
443
|
bundleId: string;
|
|
@@ -1104,13 +1110,16 @@ export type InstanceClient = {
|
|
|
1104
1110
|
openUrl: (url: string) => Promise<void>;
|
|
1105
1111
|
|
|
1106
1112
|
/**
|
|
1107
|
-
* Install an app from a URL (supports .ipa or .app files, optionally zipped)
|
|
1108
|
-
* @param
|
|
1113
|
+
* Install an app from a URL or asset name (supports .ipa or .app files, optionally zipped)
|
|
1114
|
+
* @param source A URL, or { assetName } resolved using the instance role's asset read permission
|
|
1109
1115
|
* @param options Optional installation options (md5 for caching, launchMode)
|
|
1110
1116
|
* @returns The installation result with bundle ID on success
|
|
1111
1117
|
* @throws Error if installation fails (e.g., invalid app, download failure)
|
|
1112
1118
|
*/
|
|
1113
|
-
installApp: (
|
|
1119
|
+
installApp: (source: AssetSource, options?: AppInstallationOptions) => Promise<AppInstallationResult>;
|
|
1120
|
+
|
|
1121
|
+
/** Install an app by exact asset name using the instance role. */
|
|
1122
|
+
installAppByName: (assetName: string, options?: AppInstallationOptions) => Promise<AppInstallationResult>;
|
|
1114
1123
|
|
|
1115
1124
|
/**
|
|
1116
1125
|
* Save the simulator keychain as an unencrypted tar.gz archive at a presigned asset-storage URL.
|
|
@@ -1602,6 +1611,18 @@ export type InstanceClient = {
|
|
|
1602
1611
|
*/
|
|
1603
1612
|
pullFile: (name: string, opts?: ContainerTargetOptions) => Promise<Buffer>;
|
|
1604
1613
|
|
|
1614
|
+
/**
|
|
1615
|
+
* Download a file or folder from the simulator to `localPath`; a folder arrives as a tar,
|
|
1616
|
+
* compressed with zstd, and is unpacked there, merging with what is already there. When
|
|
1617
|
+
* `localPath` is an existing folder, the file or folder lands inside it under the remote's
|
|
1618
|
+
* name. Defaults to the remote's name in the current directory.
|
|
1619
|
+
*
|
|
1620
|
+
* `name` addresses what {@link pullFile} does: the sandbox staging folder, or a relative path
|
|
1621
|
+
* inside the app container when `opts.bundleId` is set. An instance that predates folder pulls
|
|
1622
|
+
* refuses a folder.
|
|
1623
|
+
*/
|
|
1624
|
+
pull: (name: string, localPath?: string, opts?: ContainerTargetOptions) => Promise<PullResult>;
|
|
1625
|
+
|
|
1605
1626
|
/**
|
|
1606
1627
|
* List a directory in the simulator staging folder or an app container.
|
|
1607
1628
|
*
|
|
@@ -1877,6 +1898,7 @@ type ServerResponse = {
|
|
|
1877
1898
|
elementType?: string;
|
|
1878
1899
|
apps?: string;
|
|
1879
1900
|
url?: string;
|
|
1901
|
+
assetName?: string;
|
|
1880
1902
|
filename?: string;
|
|
1881
1903
|
bundleId?: string;
|
|
1882
1904
|
files?: LsofEntry[];
|
|
@@ -2414,6 +2436,7 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
|
|
|
2414
2436
|
}),
|
|
2415
2437
|
openUrlResult: () => undefined,
|
|
2416
2438
|
appInstallationResult: (msg) => ({
|
|
2439
|
+
...(msg.assetName !== undefined && { assetName: msg.assetName }),
|
|
2417
2440
|
url: msg.url || '',
|
|
2418
2441
|
bundleId: msg.bundleId || '',
|
|
2419
2442
|
}),
|
|
@@ -2848,11 +2871,14 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
|
|
|
2848
2871
|
return sendRequest<void>('openUrl', { url });
|
|
2849
2872
|
};
|
|
2850
2873
|
|
|
2851
|
-
const installApp = (
|
|
2874
|
+
const installApp = (
|
|
2875
|
+
source: AssetSource,
|
|
2876
|
+
options?: AppInstallationOptions,
|
|
2877
|
+
): Promise<AppInstallationResult> => {
|
|
2852
2878
|
return sendRequest<AppInstallationResult>(
|
|
2853
2879
|
'appInstallation',
|
|
2854
2880
|
{
|
|
2855
|
-
|
|
2881
|
+
...assetSourceFields(source),
|
|
2856
2882
|
md5: options?.md5,
|
|
2857
2883
|
launchMode: options?.launchMode,
|
|
2858
2884
|
},
|
|
@@ -3398,6 +3424,15 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
|
|
|
3398
3424
|
return Buffer.from(await response.arrayBuffer());
|
|
3399
3425
|
};
|
|
3400
3426
|
|
|
3427
|
+
const pull = async (
|
|
3428
|
+
name: string,
|
|
3429
|
+
localPath?: string,
|
|
3430
|
+
opts?: ContainerTargetOptions,
|
|
3431
|
+
): Promise<PullResult> => {
|
|
3432
|
+
const target = await pullTarget(name, localPath);
|
|
3433
|
+
return pullToLocalPath(`${buildFilesUrl(name, opts)}&${pullQuery()}`, options.token, name, target);
|
|
3434
|
+
};
|
|
3435
|
+
|
|
3401
3436
|
const listFiles = async (path = '.', opts?: ContainerTargetOptions): Promise<IosFileEntry[]> => {
|
|
3402
3437
|
const params = new URLSearchParams();
|
|
3403
3438
|
if (path && path !== '.') {
|
|
@@ -3747,6 +3782,7 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
|
|
|
3747
3782
|
listApps,
|
|
3748
3783
|
openUrl,
|
|
3749
3784
|
installApp,
|
|
3785
|
+
installAppByName: (assetName, options) => installApp({ assetName }, options),
|
|
3750
3786
|
saveKeychain,
|
|
3751
3787
|
restoreKeychain,
|
|
3752
3788
|
resetKeychain,
|
|
@@ -3805,6 +3841,7 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
|
|
|
3805
3841
|
xcodebuild,
|
|
3806
3842
|
pushFile,
|
|
3807
3843
|
pullFile,
|
|
3844
|
+
pull,
|
|
3808
3845
|
listFiles,
|
|
3809
3846
|
deleteFile,
|
|
3810
3847
|
setCameraVideo,
|
|
@@ -27,8 +27,9 @@ export class WorkloadCredentials {
|
|
|
27
27
|
private cached?: { token: string; expires: number; refreshAt: number };
|
|
28
28
|
private pending: Promise<string> | undefined;
|
|
29
29
|
|
|
30
|
+
/** endpoint is the token service. Without one, every exchange fails rather than go elsewhere. */
|
|
30
31
|
constructor(
|
|
31
|
-
private endpoint: string,
|
|
32
|
+
private endpoint: string | undefined,
|
|
32
33
|
private readIdentity: WorkloadIdentityReader,
|
|
33
34
|
private fetcher: typeof fetch,
|
|
34
35
|
private fetchOptions?: MergedRequestInit,
|
|
@@ -45,6 +46,10 @@ export class WorkloadCredentials {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
private async exchange(): Promise<string> {
|
|
49
|
+
if (!this.endpoint)
|
|
50
|
+
throw new Error(
|
|
51
|
+
"A Limrun workload identity is exchanged at the region's token service; set STS_URL or LIMRUN_STS_BASE_URL",
|
|
52
|
+
);
|
|
48
53
|
const identity = await this.readIdentity();
|
|
49
54
|
const jwt =
|
|
50
55
|
identity === null ? undefined
|
|
@@ -1,17 +1,54 @@
|
|
|
1
1
|
import { APIResource } from '../core/resource';
|
|
2
2
|
import { APIPromise } from '../core/api-promise';
|
|
3
|
+
import { LimrunError } from '../core/error';
|
|
3
4
|
import { RequestOptions } from '../internal/request-options';
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* The Limrun token service mints and revokes access tokens. A client with its own `baseURL`
|
|
8
|
+
* sends these requests to that URL instead.
|
|
9
|
+
*/
|
|
10
|
+
export const TOKEN_SERVICE_URL = 'https://sts.limrun.com';
|
|
11
|
+
|
|
5
12
|
export class AccessTokens extends APIResource {
|
|
6
13
|
/** Mint a temporary credential whose permissions are covered by the caller. */
|
|
7
14
|
create(body: AccessTokenCreateParams, options?: RequestOptions): APIPromise<AccessToken> {
|
|
8
|
-
return this._client
|
|
15
|
+
return this._client
|
|
16
|
+
.post<AccessToken>('/v1/access_tokens', {
|
|
17
|
+
body: tokenServiceBody(body),
|
|
18
|
+
defaultBaseURL: TOKEN_SERVICE_URL,
|
|
19
|
+
...options,
|
|
20
|
+
})
|
|
21
|
+
._thenUnwrap(withScopes);
|
|
9
22
|
}
|
|
10
23
|
|
|
11
24
|
/** Revoke a credential by the ID returned when it was minted. */
|
|
12
25
|
revoke(id: string, options?: RequestOptions): APIPromise<AccessTokenRevokeResponse> {
|
|
13
|
-
return this._client.delete(`/v1/access_tokens/${encodeURIComponent(id)}`,
|
|
26
|
+
return this._client.delete(`/v1/access_tokens/${encodeURIComponent(id)}`, {
|
|
27
|
+
defaultBaseURL: TOKEN_SERVICE_URL,
|
|
28
|
+
...options,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The token service accepts only `permissions`, so the deprecated `scopes` alias is
|
|
35
|
+
* resolved here, with the same rule the API applied: both must name the same set.
|
|
36
|
+
*/
|
|
37
|
+
export function tokenServiceBody({ scopes, ...body }: AccessTokenCreateParams): AccessTokenCreateParams {
|
|
38
|
+
if (!scopes) return body;
|
|
39
|
+
if (!body.permissions) return { ...body, permissions: scopes };
|
|
40
|
+
const permissions = new Set(body.permissions);
|
|
41
|
+
if (new Set(scopes).size !== permissions.size || scopes.some((scope) => !permissions.has(scope))) {
|
|
42
|
+
throw new LimrunError('permissions and the deprecated scopes must name the same permissions');
|
|
14
43
|
}
|
|
44
|
+
return body;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Fills the deprecated `scopes` field, which the token service no longer returns. */
|
|
48
|
+
export function withScopes<T extends { permissions: Array<string>; scopes?: Array<string> }>(
|
|
49
|
+
token: T,
|
|
50
|
+
): T & { scopes: Array<string> } {
|
|
51
|
+
return { ...token, scopes: token.scopes ?? token.permissions };
|
|
15
52
|
}
|
|
16
53
|
|
|
17
54
|
export interface AccessToken {
|
package/src/resources/assets.ts
CHANGED
|
@@ -99,6 +99,13 @@ export interface Asset {
|
|
|
99
99
|
*/
|
|
100
100
|
platform?: 'ios' | 'android' | 'xcode';
|
|
101
101
|
|
|
102
|
+
/**
|
|
103
|
+
* The xcodebuild SDK the artifact was built against, e.g. "iphonesimulator" or
|
|
104
|
+
* "macosx", recorded at build time. Empty for hand-uploaded assets. Only a "macosx"
|
|
105
|
+
* build installs on a macOS instance.
|
|
106
|
+
*/
|
|
107
|
+
targetSdk?: string;
|
|
108
|
+
|
|
102
109
|
signedDownloadUrl?: string;
|
|
103
110
|
|
|
104
111
|
signedUploadUrl?: string;
|
package/src/resources/index.ts
CHANGED
|
@@ -136,6 +136,10 @@ export {
|
|
|
136
136
|
type MacosSshAccess,
|
|
137
137
|
type MacosSnapshotRestoreOptions,
|
|
138
138
|
type MacosSnapshotProgress,
|
|
139
|
+
type MacosSyncOptions,
|
|
140
|
+
type MacosSyncResult,
|
|
141
|
+
type MacosFileEntry,
|
|
142
|
+
type PullResult,
|
|
139
143
|
} from './macos-instances-helpers';
|
|
140
144
|
|
|
141
145
|
export {
|