@limrun/api 0.82.0 → 0.83.0

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.
Files changed (282) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +4 -6
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts.map +1 -1
  5. package/client.js.map +1 -1
  6. package/client.mjs.map +1 -1
  7. package/core/api-promise.d.mts.map +1 -1
  8. package/core/api-promise.d.ts.map +1 -1
  9. package/core/api-promise.js +0 -1
  10. package/core/api-promise.js.map +1 -1
  11. package/core/api-promise.mjs +0 -1
  12. package/core/api-promise.mjs.map +1 -1
  13. package/core/error.d.mts.map +1 -1
  14. package/core/error.d.ts.map +1 -1
  15. package/core/error.js +0 -1
  16. package/core/error.js.map +1 -1
  17. package/core/error.mjs +0 -1
  18. package/core/error.mjs.map +1 -1
  19. package/core/pagination.d.mts.map +1 -1
  20. package/core/pagination.d.ts.map +1 -1
  21. package/core/pagination.js +0 -1
  22. package/core/pagination.js.map +1 -1
  23. package/core/pagination.mjs +0 -1
  24. package/core/pagination.mjs.map +1 -1
  25. package/core/resource.d.mts.map +1 -1
  26. package/core/resource.d.ts.map +1 -1
  27. package/core/resource.js +0 -1
  28. package/core/resource.js.map +1 -1
  29. package/core/resource.mjs +0 -1
  30. package/core/resource.mjs.map +1 -1
  31. package/exec-client.d.mts +3 -3
  32. package/exec-client.d.ts +3 -3
  33. package/gradle-snapshot.d.mts +9 -1
  34. package/gradle-snapshot.d.mts.map +1 -1
  35. package/gradle-snapshot.d.ts +9 -1
  36. package/gradle-snapshot.d.ts.map +1 -1
  37. package/gradle-snapshot.js.map +1 -1
  38. package/gradle-snapshot.mjs.map +1 -1
  39. package/index.d.mts +1 -1
  40. package/index.d.mts.map +1 -1
  41. package/index.d.ts +1 -1
  42. package/index.d.ts.map +1 -1
  43. package/index.js +4 -3
  44. package/index.js.map +1 -1
  45. package/index.mjs +1 -1
  46. package/index.mjs.map +1 -1
  47. package/internal/builtin-types.d.mts.map +1 -1
  48. package/internal/builtin-types.d.ts.map +1 -1
  49. package/internal/builtin-types.js +0 -1
  50. package/internal/builtin-types.js.map +1 -1
  51. package/internal/builtin-types.mjs +0 -1
  52. package/internal/builtin-types.mjs.map +1 -1
  53. package/internal/daemon-snapshot.d.mts +29 -0
  54. package/internal/daemon-snapshot.d.mts.map +1 -0
  55. package/internal/daemon-snapshot.d.ts +29 -0
  56. package/internal/daemon-snapshot.d.ts.map +1 -0
  57. package/internal/daemon-snapshot.js +137 -0
  58. package/internal/daemon-snapshot.js.map +1 -0
  59. package/internal/daemon-snapshot.mjs +134 -0
  60. package/internal/daemon-snapshot.mjs.map +1 -0
  61. package/internal/detect-platform.d.mts.map +1 -1
  62. package/internal/detect-platform.d.ts.map +1 -1
  63. package/internal/detect-platform.js +0 -1
  64. package/internal/detect-platform.js.map +1 -1
  65. package/internal/detect-platform.mjs +0 -1
  66. package/internal/detect-platform.mjs.map +1 -1
  67. package/internal/errors.d.mts.map +1 -1
  68. package/internal/errors.d.ts.map +1 -1
  69. package/internal/errors.js +0 -1
  70. package/internal/errors.js.map +1 -1
  71. package/internal/errors.mjs +0 -1
  72. package/internal/errors.mjs.map +1 -1
  73. package/internal/headers.d.mts.map +1 -1
  74. package/internal/headers.d.ts.map +1 -1
  75. package/internal/headers.js +0 -1
  76. package/internal/headers.js.map +1 -1
  77. package/internal/headers.mjs +0 -1
  78. package/internal/headers.mjs.map +1 -1
  79. package/internal/parse.d.mts.map +1 -1
  80. package/internal/parse.d.ts.map +1 -1
  81. package/internal/parse.js +0 -1
  82. package/internal/parse.js.map +1 -1
  83. package/internal/parse.mjs +0 -1
  84. package/internal/parse.mjs.map +1 -1
  85. package/internal/request-options.d.mts.map +1 -1
  86. package/internal/request-options.d.ts.map +1 -1
  87. package/internal/request-options.js +0 -1
  88. package/internal/request-options.js.map +1 -1
  89. package/internal/request-options.mjs +0 -1
  90. package/internal/request-options.mjs.map +1 -1
  91. package/internal/shim-types.d.mts.map +1 -1
  92. package/internal/shim-types.d.ts.map +1 -1
  93. package/internal/shim-types.js +6 -1
  94. package/internal/shim-types.js.map +1 -1
  95. package/internal/shim-types.mjs +6 -1
  96. package/internal/shim-types.mjs.map +1 -1
  97. package/internal/shims.d.mts.map +1 -1
  98. package/internal/shims.d.ts.map +1 -1
  99. package/internal/shims.js +6 -1
  100. package/internal/shims.js.map +1 -1
  101. package/internal/shims.mjs +6 -1
  102. package/internal/shims.mjs.map +1 -1
  103. package/internal/types.d.mts.map +1 -1
  104. package/internal/types.d.ts.map +1 -1
  105. package/internal/types.js +0 -1
  106. package/internal/types.js.map +1 -1
  107. package/internal/types.mjs +0 -1
  108. package/internal/types.mjs.map +1 -1
  109. package/internal/utils/base64.d.mts.map +1 -1
  110. package/internal/utils/base64.d.ts.map +1 -1
  111. package/internal/utils/base64.js +0 -1
  112. package/internal/utils/base64.js.map +1 -1
  113. package/internal/utils/base64.mjs +0 -1
  114. package/internal/utils/base64.mjs.map +1 -1
  115. package/internal/utils/env.d.mts.map +1 -1
  116. package/internal/utils/env.d.ts.map +1 -1
  117. package/internal/utils/env.js +0 -1
  118. package/internal/utils/env.js.map +1 -1
  119. package/internal/utils/env.mjs +0 -1
  120. package/internal/utils/env.mjs.map +1 -1
  121. package/internal/utils/log.d.mts.map +1 -1
  122. package/internal/utils/log.d.ts.map +1 -1
  123. package/internal/utils/log.js +0 -1
  124. package/internal/utils/log.js.map +1 -1
  125. package/internal/utils/log.mjs +0 -1
  126. package/internal/utils/log.mjs.map +1 -1
  127. package/internal/utils/query.d.mts.map +1 -1
  128. package/internal/utils/query.d.ts.map +1 -1
  129. package/internal/utils/query.js +0 -1
  130. package/internal/utils/query.js.map +1 -1
  131. package/internal/utils/query.mjs +0 -1
  132. package/internal/utils/query.mjs.map +1 -1
  133. package/internal/utils/sleep.d.mts.map +1 -1
  134. package/internal/utils/sleep.d.ts.map +1 -1
  135. package/internal/utils/sleep.js +0 -1
  136. package/internal/utils/sleep.js.map +1 -1
  137. package/internal/utils/sleep.mjs +0 -1
  138. package/internal/utils/sleep.mjs.map +1 -1
  139. package/internal/utils/uuid.d.mts.map +1 -1
  140. package/internal/utils/uuid.d.ts.map +1 -1
  141. package/internal/utils/uuid.js +0 -1
  142. package/internal/utils/uuid.js.map +1 -1
  143. package/internal/utils/uuid.mjs +0 -1
  144. package/internal/utils/uuid.mjs.map +1 -1
  145. package/internal/utils/values.d.mts.map +1 -1
  146. package/internal/utils/values.d.ts.map +1 -1
  147. package/internal/utils/values.js +0 -1
  148. package/internal/utils/values.js.map +1 -1
  149. package/internal/utils/values.mjs +0 -1
  150. package/internal/utils/values.mjs.map +1 -1
  151. package/internal/utils.d.mts.map +1 -1
  152. package/internal/utils.d.ts.map +1 -1
  153. package/internal/utils.js +0 -1
  154. package/internal/utils.js.map +1 -1
  155. package/internal/utils.mjs +0 -1
  156. package/internal/utils.mjs.map +1 -1
  157. package/package.json +2 -2
  158. package/resources/analytics.d.mts.map +1 -1
  159. package/resources/analytics.d.ts.map +1 -1
  160. package/resources/analytics.js +0 -1
  161. package/resources/analytics.js.map +1 -1
  162. package/resources/analytics.mjs +0 -1
  163. package/resources/analytics.mjs.map +1 -1
  164. package/resources/android-instances.d.mts.map +1 -1
  165. package/resources/android-instances.d.ts.map +1 -1
  166. package/resources/android-instances.js +0 -1
  167. package/resources/android-instances.js.map +1 -1
  168. package/resources/android-instances.mjs +0 -1
  169. package/resources/android-instances.mjs.map +1 -1
  170. package/resources/assets.d.mts.map +1 -1
  171. package/resources/assets.d.ts.map +1 -1
  172. package/resources/assets.js +0 -1
  173. package/resources/assets.js.map +1 -1
  174. package/resources/assets.mjs +0 -1
  175. package/resources/assets.mjs.map +1 -1
  176. package/resources/daemon-client-shared.d.mts.map +1 -1
  177. package/resources/daemon-client-shared.d.ts.map +1 -1
  178. package/resources/daemon-client-shared.js.map +1 -1
  179. package/resources/daemon-client-shared.mjs.map +1 -1
  180. package/resources/gradle-instances-helpers.d.mts.map +1 -1
  181. package/resources/gradle-instances-helpers.d.ts.map +1 -1
  182. package/resources/gradle-instances-helpers.js +25 -37
  183. package/resources/gradle-instances-helpers.js.map +1 -1
  184. package/resources/gradle-instances-helpers.mjs +25 -37
  185. package/resources/gradle-instances-helpers.mjs.map +1 -1
  186. package/resources/gradle-instances.d.mts.map +1 -1
  187. package/resources/gradle-instances.d.ts.map +1 -1
  188. package/resources/gradle-instances.js +0 -2
  189. package/resources/gradle-instances.js.map +1 -1
  190. package/resources/gradle-instances.mjs +0 -2
  191. package/resources/gradle-instances.mjs.map +1 -1
  192. package/resources/index.d.mts +1 -1
  193. package/resources/index.d.mts.map +1 -1
  194. package/resources/index.d.ts +1 -1
  195. package/resources/index.d.ts.map +1 -1
  196. package/resources/index.js +3 -2
  197. package/resources/index.js.map +1 -1
  198. package/resources/index.mjs +1 -1
  199. package/resources/index.mjs.map +1 -1
  200. package/resources/ios-instances.d.mts.map +1 -1
  201. package/resources/ios-instances.d.ts.map +1 -1
  202. package/resources/ios-instances.js +0 -1
  203. package/resources/ios-instances.js.map +1 -1
  204. package/resources/ios-instances.mjs +0 -1
  205. package/resources/ios-instances.mjs.map +1 -1
  206. package/resources/macos-instances-helpers.d.mts +27 -3
  207. package/resources/macos-instances-helpers.d.mts.map +1 -1
  208. package/resources/macos-instances-helpers.d.ts +27 -3
  209. package/resources/macos-instances-helpers.d.ts.map +1 -1
  210. package/resources/macos-instances-helpers.js +111 -25
  211. package/resources/macos-instances-helpers.js.map +1 -1
  212. package/resources/macos-instances-helpers.mjs +109 -25
  213. package/resources/macos-instances-helpers.mjs.map +1 -1
  214. package/resources/macos-instances.d.mts.map +1 -1
  215. package/resources/macos-instances.d.ts.map +1 -1
  216. package/resources/macos-instances.js +0 -2
  217. package/resources/macos-instances.js.map +1 -1
  218. package/resources/macos-instances.mjs +0 -2
  219. package/resources/macos-instances.mjs.map +1 -1
  220. package/resources/scoped-tokens.d.mts.map +1 -1
  221. package/resources/scoped-tokens.d.ts.map +1 -1
  222. package/resources/scoped-tokens.js +0 -1
  223. package/resources/scoped-tokens.js.map +1 -1
  224. package/resources/scoped-tokens.mjs +0 -1
  225. package/resources/scoped-tokens.mjs.map +1 -1
  226. package/resources/xcode-instances-helpers.d.mts +3 -4
  227. package/resources/xcode-instances-helpers.d.mts.map +1 -1
  228. package/resources/xcode-instances-helpers.d.ts +3 -4
  229. package/resources/xcode-instances-helpers.d.ts.map +1 -1
  230. package/resources/xcode-instances-helpers.js.map +1 -1
  231. package/resources/xcode-instances-helpers.mjs.map +1 -1
  232. package/resources/xcode-instances.d.mts.map +1 -1
  233. package/resources/xcode-instances.d.ts.map +1 -1
  234. package/resources/xcode-instances.js +0 -1
  235. package/resources/xcode-instances.js.map +1 -1
  236. package/resources/xcode-instances.mjs +0 -1
  237. package/resources/xcode-instances.mjs.map +1 -1
  238. package/src/client.ts +0 -2
  239. package/src/core/api-promise.ts +0 -2
  240. package/src/core/error.ts +0 -2
  241. package/src/core/pagination.ts +0 -2
  242. package/src/core/resource.ts +0 -2
  243. package/src/exec-client.ts +3 -3
  244. package/src/gradle-snapshot.ts +9 -1
  245. package/src/index.ts +1 -2
  246. package/src/internal/builtin-types.ts +0 -2
  247. package/src/internal/daemon-snapshot.ts +144 -0
  248. package/src/internal/detect-platform.ts +0 -2
  249. package/src/internal/errors.ts +0 -2
  250. package/src/internal/headers.ts +0 -2
  251. package/src/internal/parse.ts +0 -2
  252. package/src/internal/request-options.ts +0 -2
  253. package/src/internal/shim-types.ts +0 -2
  254. package/src/internal/shims.ts +0 -2
  255. package/src/internal/types.ts +0 -2
  256. package/src/internal/utils/base64.ts +0 -2
  257. package/src/internal/utils/env.ts +0 -2
  258. package/src/internal/utils/log.ts +0 -2
  259. package/src/internal/utils/query.ts +0 -2
  260. package/src/internal/utils/sleep.ts +0 -2
  261. package/src/internal/utils/uuid.ts +0 -2
  262. package/src/internal/utils/values.ts +0 -2
  263. package/src/internal/utils.ts +0 -2
  264. package/src/resources/analytics.ts +0 -2
  265. package/src/resources/android-instances.ts +0 -2
  266. package/src/resources/assets.ts +0 -2
  267. package/src/resources/daemon-client-shared.ts +2 -4
  268. package/src/resources/gradle-instances-helpers.ts +27 -41
  269. package/src/resources/gradle-instances.ts +0 -3
  270. package/src/resources/index.ts +1 -2
  271. package/src/resources/ios-instances.ts +0 -2
  272. package/src/resources/macos-instances-helpers.ts +160 -29
  273. package/src/resources/macos-instances.ts +0 -3
  274. package/src/resources/scoped-tokens.ts +0 -2
  275. package/src/resources/xcode-instances-helpers.ts +3 -4
  276. package/src/resources/xcode-instances.ts +0 -2
  277. package/src/version.ts +1 -1
  278. package/version.d.mts +1 -1
  279. package/version.d.ts +1 -1
  280. package/version.js +1 -1
  281. package/version.mjs +1 -1
  282. package/src/lib/.keep +0 -4
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  /**
4
2
  * Shims for types that we can't always rely on being available globally.
5
3
  *
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  /**
4
2
  * This module provides internal shims and utility functions for environments where certain Node.js or global types may not be available.
5
3
  *
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  export type PromiseOrValue<T> = T | Promise<T>;
4
2
  export type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
5
3
 
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { LimrunError } from '../../core/error';
4
2
  import { encodeUTF8 } from './bytes';
5
3
 
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  /**
4
2
  * Read an environment variable.
5
3
  *
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { hasOwn } from './values';
4
2
  import { type Limrun } from '../../client';
5
3
  import { RequestOptions } from '../request-options';
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { LimrunError } from '../../core/error';
4
2
 
5
3
  /**
@@ -1,3 +1 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  export const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  /**
4
2
  * https://stackoverflow.com/a/2117523
5
3
  */
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { LimrunError } from '../../core/error';
4
2
 
5
3
  // https://url.spec.whatwg.org/#url-scheme-string
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  export * from './utils/values';
4
2
  export * from './utils/base64';
5
3
  export * from './utils/env';
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { APIResource } from '../core/resource';
4
2
  import { APIPromise } from '../core/api-promise';
5
3
  import { RequestOptions } from '../internal/request-options';
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { APIResource } from '../core/resource';
4
2
  import { APIPromise } from '../core/api-promise';
5
3
  import { Items, type ItemsParams, PagePromise } from '../core/pagination';
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { APIResource } from '../core/resource';
4
2
  import { APIPromise } from '../core/api-promise';
5
3
  import { buildHeaders } from '../internal/headers';
@@ -13,10 +13,8 @@ export type LogLevel = 'none' | 'error' | 'warn' | 'info' | 'debug';
13
13
  // gradle responses share this exact shape (their OpenAPI schemas are
14
14
  // structurally identical), so it is defined once here and aliased per
15
15
  // resource; a platform gaining a field of its own is the signal to split the
16
- // aliases back into real interfaces. Hand-written against
17
- // api/public/director/openapiv3.yaml; if a Stainless regeneration ever picks
18
- // those paths up, reconcile with the generated surface instead of
19
- // duplicating it.
16
+ // aliases back into real interfaces. Written against
17
+ // api/public/director/openapiv3.yaml.
20
18
  export interface BuildLog {
21
19
  /** Exec ID assigned by the build daemon, e.g. build-1776140344112378000. */
22
20
  id: string;
@@ -1,15 +1,13 @@
1
1
  import { DeviceDetachUnavailableError } from '../device-detach';
2
- import { directInstanceHttpError } from '../internal/direct-instance-errors';
2
+ import { followDaemonSnapshot } from '../internal/daemon-snapshot';
3
3
  import { nodeProxyTransport } from '../internal/proxy-transport';
4
4
  import {
5
5
  GradleSnapshotRequestUnavailableError,
6
6
  GradleSnapshotTimeoutError,
7
7
  isGradleRestoreTerminal,
8
8
  type GradleInstanceSnapshot,
9
- type GradleSnapshotRequest,
10
9
  type GradleSnapshotRestoreOptions,
11
10
  } from '../gradle-snapshot';
12
- import { sleep } from '../internal/utils/sleep';
13
11
  import type { AndroidInstance } from './android-instances';
14
12
  import { pullBuildFile } from '../internal/build-pull-file';
15
13
  import { normalizeAssetUpload, type BuildUpload } from '../lib/asset-permissions';
@@ -315,45 +313,33 @@ class GradleInstancesHelpers extends GradleInstances {
315
313
  },
316
314
 
317
315
  async restoreSnapshot({ onUpdate, timeoutMs = RESTORE_TIMEOUT_MS, key, restoreKeys, encryptionKey }) {
318
- const snapshotRequest = async (body?: GradleSnapshotRequest): Promise<GradleInstanceSnapshot> => {
319
- const response = await nodeProxyTransport.fetch(`${apiUrl}/snapshot`, {
320
- method: body ? 'POST' : 'GET',
321
- headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
322
- ...(body ? { body: JSON.stringify(body) } : {}),
323
- });
324
- if (response.status === 404) {
325
- await response.text().catch(() => undefined);
326
- throw new GradleSnapshotRequestUnavailableError();
327
- }
328
- if (!response.ok) {
329
- // The body is the daemon's reason, which never repeats the encryption key.
330
- throw directInstanceHttpError(
331
- 'Disk snapshot request',
332
- response.status,
333
- (await response.text()).trim(),
334
- response.headers,
335
- );
336
- }
337
- return instanceSnapshot((await response.json()) as InstanceSnapshotReport);
338
- };
339
- const deadline = Date.now() + timeoutMs;
340
- let state = await snapshotRequest({
341
- ...(key !== undefined && { key }),
342
- ...(restoreKeys !== undefined && { restoreKeys }),
343
- ...(encryptionKey !== undefined && { encryptionKey }),
344
- });
345
316
  let reported = '';
346
- for (;;) {
347
- const seen = `${state.restore.phase}/${state.restore.reason ?? ''}`;
348
- if (seen !== reported) {
349
- reported = seen;
350
- onUpdate?.(state);
351
- }
352
- if (isGradleRestoreTerminal(state.restore.phase)) return state;
353
- if (Date.now() >= deadline) throw new GradleSnapshotTimeoutError('restore', timeoutMs, state);
354
- await sleep(1000);
355
- state = await snapshotRequest();
356
- }
317
+ let state: GradleInstanceSnapshot | undefined;
318
+ await followDaemonSnapshot<InstanceSnapshotReport>({
319
+ apiUrl,
320
+ token,
321
+ request: {
322
+ ...(key !== undefined && { key }),
323
+ ...(restoreKeys !== undefined && { restoreKeys }),
324
+ ...(encryptionKey !== undefined && { encryptionKey }),
325
+ },
326
+ timeoutMs,
327
+ onStatus: (report) => {
328
+ const current = instanceSnapshot(report);
329
+ state = current;
330
+ const seen = `${current.restore.phase}/${current.restore.reason ?? ''}/${
331
+ current.restore.doneBytes ?? ''
332
+ }`;
333
+ if (seen !== reported) {
334
+ reported = seen;
335
+ onUpdate?.(current);
336
+ }
337
+ return isGradleRestoreTerminal(current.restore.phase);
338
+ },
339
+ unavailableError: () => new GradleSnapshotRequestUnavailableError(),
340
+ timeoutError: () => new GradleSnapshotTimeoutError('restore', timeoutMs, state),
341
+ });
342
+ return state!;
357
343
  },
358
344
  };
359
345
  }
@@ -1,6 +1,3 @@
1
- // Hand-written following the Stainless resource pattern; a future generation
2
- // from the OpenAPI spec reconciles with this file.
3
-
4
1
  import { APIResource } from '../core/resource';
5
2
  import { APIPromise } from '../core/api-promise';
6
3
  import { Items, type ItemsParams, PagePromise } from '../core/pagination';
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  export {
4
2
  XcodeSnapshots,
5
3
  IOSSnapshots,
@@ -140,6 +138,7 @@ export {
140
138
  type MacosSyncResult,
141
139
  type MacosFileEntry,
142
140
  type PullResult,
141
+ MacosSnapshotEncryptionUnsupportedError,
143
142
  } from './macos-instances-helpers';
144
143
 
145
144
  export {
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { APIResource } from '../core/resource';
4
2
  import { APIPromise } from '../core/api-promise';
5
3
  import { Items, type ItemsParams, PagePromise } from '../core/pagination';
@@ -52,6 +52,8 @@ import {
52
52
  pushFile as pushLocalFile,
53
53
  type PullResult,
54
54
  } from '../internal/file-transfer';
55
+ import { LimrunError } from '../core/error';
56
+ import { followDaemonSnapshot } from '../internal/daemon-snapshot';
55
57
  import { nodeProxyTransport } from '../internal/proxy-transport';
56
58
  import nodePath from 'path';
57
59
  import { createHash } from 'crypto';
@@ -318,9 +320,10 @@ export interface MacosClient {
318
320
  *
319
321
  * Each restore key is tried in order: its exact name first, then the newest asset whose name
320
322
  * starts with it, skipping snapshots saved on another macOS build. Without `restoreKeys`,
321
- * `key` is restored. Without either, nothing is restored. Call it once the instance is ready
322
- * and before using the guest; asking again joins the restore already running. Resolves with the
323
- * final progress event; `onProgress` sees every event, with byte counts while downloading.
323
+ * `key` is restored. Without either, nothing is restored and it resolves with the save's state.
324
+ * Call it once the instance is ready and before using the guest; asking again joins the restore
325
+ * already running. Resolves with the final progress event; `onProgress` sees every event, with
326
+ * byte counts while downloading.
324
327
  */
325
328
  restoreSnapshot(options: MacosSnapshotRestoreOptions): Promise<MacosSnapshotProgress>;
326
329
 
@@ -460,11 +463,26 @@ export interface MacosSnapshotRestoreOptions {
460
463
  key?: string;
461
464
  /** Asset names, or name prefixes, to restore from, in order. Defaults to `key`. */
462
465
  restoreKeys?: string[];
466
+ /**
467
+ * A base64 AES-256 key, 32 random bytes, that encrypts the save and decrypts the restore. Limrun
468
+ * stores no copy, so a lost key makes the snapshot unreadable. Generate one with
469
+ * `openssl rand -base64 32`. An instance from before encrypted snapshots rejects it with
470
+ * `MacosSnapshotEncryptionUnsupportedError` and restores nothing.
471
+ */
472
+ encryptionKey?: string;
473
+ /** Called once per distinct state, and again as the download progresses. */
463
474
  onProgress?: (progress: MacosSnapshotProgress) => void;
475
+ /** How long to wait for the restore to end. Defaults to twenty minutes. */
476
+ timeoutMs?: number;
464
477
  }
465
478
 
466
479
  /** A restore's progress, as the instance reports it. */
467
480
  export interface MacosSnapshotProgress {
481
+ /**
482
+ * The restore's phase. A request with neither `key` nor `restoreKeys` restores nothing and
483
+ * reports the save the instance runs when it terminates instead: the phase is then the save's,
484
+ * such as `idle`.
485
+ */
468
486
  phase: 'resolving' | 'downloading' | 'extracting' | 'restored' | 'skipped' | 'failed' | string;
469
487
  /** The asset name the restore matched. */
470
488
  key?: string;
@@ -547,6 +565,42 @@ class MacosInstancesHelpers extends MacosInstances {
547
565
  return true;
548
566
  },
549
567
  });
568
+ // limacvm's restoreSnapshot over signaling, which every limacvm takes. Progress arrives as
569
+ // restoreSnapshotProgress before the result.
570
+ const restoreOverSignaling = async (
571
+ request: Record<string, unknown>,
572
+ onProgress: MacosSnapshotRestoreOptions['onProgress'],
573
+ ): Promise<MacosSnapshotProgress> => {
574
+ const id = transport.nextId();
575
+ let last: MacosSnapshotProgress | undefined;
576
+ restoreProgress.set(id, (progress) => {
577
+ last = progress;
578
+ onProgress?.(progress);
579
+ });
580
+ try {
581
+ // A restore downloads the whole disk, so it waits as long as the connection lasts.
582
+ let final: MacosSnapshotProgress | undefined;
583
+ try {
584
+ final = await transport.request<MacosSnapshotProgress | undefined>(
585
+ 'restoreSnapshot',
586
+ request,
587
+ (msg) => msg['progress'] as MacosSnapshotProgress | undefined,
588
+ 0,
589
+ id,
590
+ );
591
+ } catch (error) {
592
+ // A failed restore is an outcome, as it was reported in its progress, not an error.
593
+ if (last?.phase === 'failed') return last;
594
+ throw error;
595
+ }
596
+ if (final && final !== last) onProgress?.(final);
597
+ const result = final ?? last;
598
+ if (!result) throw new Error('the instance finished the restore without reporting its progress');
599
+ return result;
600
+ } finally {
601
+ restoreProgress.delete(id);
602
+ }
603
+ };
550
604
  const send = <T = void>(
551
605
  type: string,
552
606
  params: Record<string, unknown> = {},
@@ -882,36 +936,51 @@ class MacosInstancesHelpers extends MacosInstances {
882
936
  onProgress,
883
937
  key,
884
938
  restoreKeys,
939
+ encryptionKey,
940
+ timeoutMs = MACOS_RESTORE_TIMEOUT_MS,
885
941
  }: MacosSnapshotRestoreOptions): Promise<MacosSnapshotProgress> {
886
- const id = transport.nextId();
942
+ const request = {
943
+ ...(key !== undefined && { key }),
944
+ ...(restoreKeys !== undefined && { restoreKeys }),
945
+ ...(encryptionKey !== undefined && { encryptionKey }),
946
+ };
947
+ // A request for no restore reports the save, as signaling does.
948
+ const restores = (restoreKeys ?? (key !== undefined ? [key] : [])).length > 0;
887
949
  let last: MacosSnapshotProgress | undefined;
888
- restoreProgress.set(id, (progress) => {
889
- last = progress;
890
- onProgress?.(progress);
891
- });
950
+ let reported = '';
892
951
  try {
893
- // A restore downloads the whole disk, so it waits as long as the connection lasts.
894
- let final: MacosSnapshotProgress | undefined;
895
- try {
896
- final = await transport.request<MacosSnapshotProgress | undefined>(
897
- 'restoreSnapshot',
898
- { ...(key !== undefined && { key }), ...(restoreKeys !== undefined && { restoreKeys }) },
899
- (msg) => msg['progress'] as MacosSnapshotProgress | undefined,
900
- 0,
901
- id,
902
- );
903
- } catch (error) {
904
- // A failed restore is an outcome, as it was reported in its progress, not an error.
905
- if (last?.phase === 'failed') return last;
906
- throw error;
907
- }
908
- if (final && final !== last) onProgress?.(final);
909
- const result = final ?? last;
910
- if (!result) throw new Error('the instance finished the restore without reporting its progress');
911
- return result;
912
- } finally {
913
- restoreProgress.delete(id);
952
+ await followDaemonSnapshot<MacosSnapshotReport>({
953
+ apiUrl,
954
+ token,
955
+ request,
956
+ timeoutMs,
957
+ onStatus: (report) => {
958
+ last = macosSnapshotProgress(report, restores);
959
+ const seen = `${last.phase}/${last.reason ?? ''}/${last.doneBytes ?? ''}`;
960
+ if (seen !== reported) {
961
+ reported = seen;
962
+ onProgress?.(last);
963
+ }
964
+ return !restores || MACOS_RESTORE_TERMINAL.has(report.restore.phase);
965
+ },
966
+ unavailableError: () => new MacosSnapshotRequestUnavailableError(),
967
+ timeoutError: () =>
968
+ new Error(
969
+ `Timed out after ${Math.round(
970
+ timeoutMs / 1000,
971
+ )}s waiting for the disk snapshot restore to finish` +
972
+ (last ? ` (last phase: ${last.phase})` : ''),
973
+ ),
974
+ });
975
+ return last!;
976
+ } catch (error) {
977
+ // An instance from before POST /snapshot takes the request over signaling only.
978
+ if (!(error instanceof MacosSnapshotRequestUnavailableError)) throw error;
914
979
  }
980
+ // Every instance that encrypts snapshots takes POST /snapshot. An older one would ignore
981
+ // the key and save the guest unencrypted, so it gets no request at all.
982
+ if (encryptionKey !== undefined) throw new MacosSnapshotEncryptionUnsupportedError();
983
+ return restoreOverSignaling(request, onProgress);
915
984
  },
916
985
 
917
986
  async drag(from, to, options) {
@@ -966,3 +1035,65 @@ function validateRecordingId(recordingId: string): void {
966
1035
  throw new Error('recordingId must match ^[a-z0-9][a-z0-9_-]{0,63}$');
967
1036
  }
968
1037
  }
1038
+
1039
+ /** Waits past the instance's own fifteen-minute bound on a restore before giving up on it. */
1040
+ const MACOS_RESTORE_TIMEOUT_MS = 20 * 60 * 1000;
1041
+
1042
+ const MACOS_RESTORE_TERMINAL = new Set(['disabled', 'restored', 'skipped', 'failed']);
1043
+
1044
+ /** POST /snapshot answered 404, so the instance predates it or keeps no snapshots. */
1045
+ class MacosSnapshotRequestUnavailableError extends Error {}
1046
+
1047
+ /**
1048
+ * `restoreSnapshot` was given an `encryptionKey` and the instance predates encrypted snapshots.
1049
+ * Nothing was restored, and the instance saves nothing. A new instance takes the key.
1050
+ */
1051
+ export class MacosSnapshotEncryptionUnsupportedError extends LimrunError {
1052
+ constructor() {
1053
+ super(
1054
+ 'This instance predates encrypted disk snapshots, so it cannot take an encryption key; create a new instance.',
1055
+ );
1056
+ this.name = 'MacosSnapshotEncryptionUnsupportedError';
1057
+ }
1058
+ }
1059
+
1060
+ /** The status limacvm answers POST and GET /snapshot with. */
1061
+ type MacosSnapshotReport = {
1062
+ restore: {
1063
+ phase: string;
1064
+ key?: string;
1065
+ matchKind?: string;
1066
+ source?: string;
1067
+ bytes?: number;
1068
+ doneBytes?: number;
1069
+ reason?: string;
1070
+ message?: string;
1071
+ };
1072
+ save: { phase: string; key?: string; reason?: string; message?: string };
1073
+ };
1074
+
1075
+ /** The report in the shape signaling's progress events have, which `restoreSnapshot` returns. */
1076
+ function macosSnapshotProgress(
1077
+ { restore, save }: MacosSnapshotReport,
1078
+ restores: boolean,
1079
+ ): MacosSnapshotProgress {
1080
+ if (!restores) {
1081
+ return {
1082
+ phase: save.phase,
1083
+ ...(save.key && { key: save.key }),
1084
+ ...(save.reason && { reason: save.reason }),
1085
+ ...(save.message && { message: save.message }),
1086
+ };
1087
+ }
1088
+ return {
1089
+ phase: restore.phase,
1090
+ ...(restore.key && { key: restore.key }),
1091
+ ...(restore.matchKind && { matchKind: restore.matchKind }),
1092
+ ...(restore.source && { source: restore.source }),
1093
+ ...(restore.bytes && { totalBytes: restore.bytes, doneBytes: restore.doneBytes ?? 0 }),
1094
+ // A download that has not learned its total yet still reports its progress.
1095
+ ...(!restore.bytes && restore.doneBytes && { doneBytes: restore.doneBytes }),
1096
+ ...(restore.reason && { reason: restore.reason }),
1097
+ ...(restore.message && { message: restore.message }),
1098
+ };
1099
+ }
@@ -1,6 +1,3 @@
1
- // Hand-written following the Stainless resource pattern; a future generation
2
- // from the OpenAPI spec reconciles with this file.
3
-
4
1
  import { APIResource } from '../core/resource';
5
2
  import { APIPromise } from '../core/api-promise';
6
3
  import { Items, type ItemsParams, PagePromise } from '../core/pagination';
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import {
4
2
  type AccessTokenCreateParams,
5
3
  TOKEN_SERVICE_URL,
@@ -181,10 +181,9 @@ export type XcodeProjectConfig = {
181
181
  */
182
182
  runTests?: boolean;
183
183
  /**
184
- * Run the tests through Apple's xcodebuild on the attached simulator and
185
- * keep their result bundle, reported as ExecResult.xctest.resultBundle;
186
- * fetch it with XcodeClient.pullResultBundle. Needs a testing action and a
187
- * test run.
184
+ * Keep the test run's result bundle, reported as
185
+ * ExecResult.xctest.resultBundle; fetch it with XcodeClient.pullResultBundle.
186
+ * Needs a testing action and a test run.
188
187
  */
189
188
  resultBundle?: boolean;
190
189
  /**
@@ -1,5 +1,3 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
1
  import { APIResource } from '../core/resource';
4
2
  import { APIPromise } from '../core/api-promise';
5
3
  import { Items, type ItemsParams, PagePromise } from '../core/pagination';
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.82.0'; // x-release-please-version
1
+ export const VERSION = '0.83.0'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.82.0";
1
+ export declare const VERSION = "0.83.0";
2
2
  //# sourceMappingURL=version.d.mts.map
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.82.0";
1
+ export declare const VERSION = "0.83.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '0.82.0'; // x-release-please-version
4
+ exports.VERSION = '0.83.0'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.82.0'; // x-release-please-version
1
+ export const VERSION = '0.83.0'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map
package/src/lib/.keep DELETED
@@ -1,4 +0,0 @@
1
- File generated from our OpenAPI spec by Stainless.
2
-
3
- This directory can be used to store custom files to expand the SDK.
4
- It is ignored by Stainless code generation and its content (other than this keep file) won't be touched.