@vercel/sandbox 2.0.0-beta.2 → 2.0.0-beta.20

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 (208) hide show
  1. package/README.md +48 -1
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  3. package/dist/api-client/api-client.cjs +445 -0
  4. package/dist/api-client/api-client.cjs.map +1 -0
  5. package/dist/api-client/api-client.d.cts +6235 -0
  6. package/dist/api-client/api-client.d.ts +6229 -706
  7. package/dist/api-client/api-client.js +436 -472
  8. package/dist/api-client/api-client.js.map +1 -1
  9. package/dist/api-client/api-error.cjs +32 -0
  10. package/dist/api-client/api-error.cjs.map +1 -0
  11. package/dist/api-client/api-error.d.cts +29 -0
  12. package/dist/api-client/api-error.d.ts +21 -16
  13. package/dist/api-client/api-error.js +28 -32
  14. package/dist/api-client/api-error.js.map +1 -1
  15. package/dist/api-client/base-client.cjs +126 -0
  16. package/dist/api-client/base-client.cjs.map +1 -0
  17. package/dist/api-client/base-client.d.cts +38 -0
  18. package/dist/api-client/base-client.d.ts +31 -36
  19. package/dist/api-client/base-client.js +114 -118
  20. package/dist/api-client/base-client.js.map +1 -1
  21. package/dist/api-client/file-writer.cjs +62 -0
  22. package/dist/api-client/file-writer.cjs.map +1 -0
  23. package/dist/api-client/file-writer.d.cts +66 -0
  24. package/dist/api-client/file-writer.d.ts +56 -42
  25. package/dist/api-client/file-writer.js +57 -61
  26. package/dist/api-client/file-writer.js.map +1 -1
  27. package/dist/api-client/index.cjs +2 -0
  28. package/dist/api-client/index.d.ts +2 -2
  29. package/dist/api-client/index.js +4 -21
  30. package/dist/api-client/validators.cjs +229 -0
  31. package/dist/api-client/validators.cjs.map +1 -0
  32. package/dist/api-client/validators.d.cts +26885 -0
  33. package/dist/api-client/validators.d.ts +26732 -3706
  34. package/dist/api-client/validators.js +198 -191
  35. package/dist/api-client/validators.js.map +1 -1
  36. package/dist/api-client/with-retry.cjs +89 -0
  37. package/dist/api-client/with-retry.cjs.map +1 -0
  38. package/dist/api-client/with-retry.d.cts +10 -0
  39. package/dist/api-client/with-retry.d.ts +9 -13
  40. package/dist/api-client/with-retry.js +81 -102
  41. package/dist/api-client/with-retry.js.map +1 -1
  42. package/dist/auth/api.cjs +29 -0
  43. package/dist/auth/api.cjs.map +1 -0
  44. package/dist/auth/api.js +26 -25
  45. package/dist/auth/api.js.map +1 -1
  46. package/dist/auth/error.cjs +13 -0
  47. package/dist/auth/error.cjs.map +1 -0
  48. package/dist/auth/error.js +11 -11
  49. package/dist/auth/error.js.map +1 -1
  50. package/dist/auth/file.cjs +64 -0
  51. package/dist/auth/file.cjs.map +1 -0
  52. package/dist/auth/file.d.cts +26 -0
  53. package/dist/auth/file.d.ts +19 -15
  54. package/dist/auth/file.js +49 -64
  55. package/dist/auth/file.js.map +1 -1
  56. package/dist/auth/index.cjs +11 -0
  57. package/dist/auth/index.d.cts +5 -0
  58. package/dist/auth/index.d.ts +5 -6
  59. package/dist/auth/index.js +6 -27
  60. package/dist/auth/linked-project.cjs +38 -0
  61. package/dist/auth/linked-project.cjs.map +1 -0
  62. package/dist/auth/linked-project.js +30 -64
  63. package/dist/auth/linked-project.js.map +1 -1
  64. package/dist/auth/oauth.cjs +205 -0
  65. package/dist/auth/oauth.cjs.map +1 -0
  66. package/dist/auth/oauth.d.cts +135 -0
  67. package/dist/auth/oauth.d.ts +113 -109
  68. package/dist/auth/oauth.js +185 -252
  69. package/dist/auth/oauth.js.map +1 -1
  70. package/dist/auth/poll-for-token.cjs +82 -0
  71. package/dist/auth/poll-for-token.cjs.map +1 -0
  72. package/dist/auth/poll-for-token.d.cts +28 -0
  73. package/dist/auth/poll-for-token.d.ts +23 -15
  74. package/dist/auth/poll-for-token.js +79 -64
  75. package/dist/auth/poll-for-token.js.map +1 -1
  76. package/dist/auth/project.cjs +178 -0
  77. package/dist/auth/project.cjs.map +1 -0
  78. package/dist/auth/project.d.cts +40 -0
  79. package/dist/auth/project.d.ts +19 -19
  80. package/dist/auth/project.js +169 -72
  81. package/dist/auth/project.js.map +1 -1
  82. package/dist/auth/zod.cjs +22 -0
  83. package/dist/auth/zod.cjs.map +1 -0
  84. package/dist/auth/zod.js +18 -17
  85. package/dist/auth/zod.js.map +1 -1
  86. package/dist/command.cjs +328 -0
  87. package/dist/command.cjs.map +1 -0
  88. package/dist/command.d.cts +289 -0
  89. package/dist/command.d.ts +265 -171
  90. package/dist/command.js +323 -226
  91. package/dist/command.js.map +1 -1
  92. package/dist/constants.d.cts +5 -0
  93. package/dist/constants.d.ts +5 -1
  94. package/dist/filesystem.cjs +499 -0
  95. package/dist/filesystem.cjs.map +1 -0
  96. package/dist/filesystem.d.cts +258 -0
  97. package/dist/filesystem.d.ts +258 -0
  98. package/dist/filesystem.js +497 -0
  99. package/dist/filesystem.js.map +1 -0
  100. package/dist/index.cjs +15 -0
  101. package/dist/index.d.cts +8 -0
  102. package/dist/index.d.ts +8 -6
  103. package/dist/index.js +8 -17
  104. package/dist/network-policy.d.cts +156 -0
  105. package/dist/network-policy.d.ts +88 -28
  106. package/dist/sandbox.cjs +816 -0
  107. package/dist/sandbox.cjs.map +1 -0
  108. package/dist/sandbox.d.cts +2847 -0
  109. package/dist/sandbox.d.ts +2834 -628
  110. package/dist/sandbox.js +808 -557
  111. package/dist/sandbox.js.map +1 -1
  112. package/dist/session.cjs +527 -0
  113. package/dist/session.cjs.map +1 -0
  114. package/dist/session.d.cts +410 -0
  115. package/dist/session.d.ts +403 -368
  116. package/dist/session.js +524 -489
  117. package/dist/session.js.map +1 -1
  118. package/dist/snapshot.cjs +204 -0
  119. package/dist/snapshot.cjs.map +1 -0
  120. package/dist/snapshot.d.cts +161 -0
  121. package/dist/snapshot.d.ts +152 -92
  122. package/dist/snapshot.js +201 -114
  123. package/dist/snapshot.js.map +1 -1
  124. package/dist/utils/array.cjs +17 -0
  125. package/dist/utils/array.cjs.map +1 -0
  126. package/dist/utils/array.js +12 -15
  127. package/dist/utils/array.js.map +1 -1
  128. package/dist/utils/consume-readable.cjs +18 -0
  129. package/dist/utils/consume-readable.cjs.map +1 -0
  130. package/dist/utils/consume-readable.js +13 -12
  131. package/dist/utils/consume-readable.js.map +1 -1
  132. package/dist/utils/decode-base64-url.cjs +15 -0
  133. package/dist/utils/decode-base64-url.cjs.map +1 -0
  134. package/dist/utils/decode-base64-url.js +10 -9
  135. package/dist/utils/decode-base64-url.js.map +1 -1
  136. package/dist/utils/dev-credentials.cjs +142 -0
  137. package/dist/utils/dev-credentials.cjs.map +1 -0
  138. package/dist/utils/dev-credentials.js +126 -184
  139. package/dist/utils/dev-credentials.js.map +1 -1
  140. package/dist/utils/get-credentials.cjs +123 -0
  141. package/dist/utils/get-credentials.cjs.map +1 -0
  142. package/dist/utils/get-credentials.d.cts +21 -0
  143. package/dist/utils/get-credentials.d.ts +19 -61
  144. package/dist/utils/get-credentials.js +106 -140
  145. package/dist/utils/get-credentials.js.map +1 -1
  146. package/dist/utils/log.cjs +25 -0
  147. package/dist/utils/log.cjs.map +1 -0
  148. package/dist/utils/log.js +15 -17
  149. package/dist/utils/log.js.map +1 -1
  150. package/dist/utils/network-policy.cjs +49 -0
  151. package/dist/utils/network-policy.cjs.map +1 -0
  152. package/dist/utils/network-policy.js +42 -77
  153. package/dist/utils/network-policy.js.map +1 -1
  154. package/dist/utils/normalizePath.cjs +27 -0
  155. package/dist/utils/normalizePath.cjs.map +1 -0
  156. package/dist/utils/normalizePath.js +21 -28
  157. package/dist/utils/normalizePath.js.map +1 -1
  158. package/dist/utils/paginator.cjs +41 -0
  159. package/dist/utils/paginator.cjs.map +1 -0
  160. package/dist/utils/paginator.d.cts +16 -0
  161. package/dist/utils/paginator.d.ts +16 -0
  162. package/dist/utils/paginator.js +40 -0
  163. package/dist/utils/paginator.js.map +1 -0
  164. package/dist/utils/resolveSignal.cjs +20 -0
  165. package/dist/utils/resolveSignal.cjs.map +1 -0
  166. package/dist/utils/resolveSignal.d.cts +15 -0
  167. package/dist/utils/resolveSignal.d.ts +12 -10
  168. package/dist/utils/resolveSignal.js +14 -17
  169. package/dist/utils/resolveSignal.js.map +1 -1
  170. package/dist/utils/sandbox-snapshot.cjs +14 -0
  171. package/dist/utils/sandbox-snapshot.cjs.map +1 -0
  172. package/dist/utils/sandbox-snapshot.d.cts +10 -0
  173. package/dist/utils/sandbox-snapshot.d.ts +11 -0
  174. package/dist/utils/sandbox-snapshot.js +14 -0
  175. package/dist/utils/sandbox-snapshot.js.map +1 -0
  176. package/dist/utils/types.cjs +13 -0
  177. package/dist/utils/types.cjs.map +1 -0
  178. package/dist/utils/types.d.cts +11 -0
  179. package/dist/utils/types.d.ts +5 -7
  180. package/dist/utils/types.js +8 -8
  181. package/dist/utils/types.js.map +1 -1
  182. package/dist/version.cjs +7 -0
  183. package/dist/version.cjs.map +1 -0
  184. package/dist/version.js +5 -5
  185. package/dist/version.js.map +1 -1
  186. package/package.json +23 -3
  187. package/dist/api-client/index.js.map +0 -1
  188. package/dist/auth/api.d.ts +0 -6
  189. package/dist/auth/error.d.ts +0 -11
  190. package/dist/auth/index.js.map +0 -1
  191. package/dist/auth/linked-project.d.ts +0 -10
  192. package/dist/auth/zod.d.ts +0 -5
  193. package/dist/constants.js +0 -3
  194. package/dist/constants.js.map +0 -1
  195. package/dist/index.js.map +0 -1
  196. package/dist/network-policy.js +0 -3
  197. package/dist/network-policy.js.map +0 -1
  198. package/dist/utils/array.d.ts +0 -9
  199. package/dist/utils/consume-readable.d.ts +0 -5
  200. package/dist/utils/convert-sandbox.d.ts +0 -6
  201. package/dist/utils/convert-sandbox.js +0 -14
  202. package/dist/utils/convert-sandbox.js.map +0 -1
  203. package/dist/utils/decode-base64-url.d.ts +0 -7
  204. package/dist/utils/dev-credentials.d.ts +0 -37
  205. package/dist/utils/log.d.ts +0 -2
  206. package/dist/utils/network-policy.d.ts +0 -7
  207. package/dist/utils/normalizePath.d.ts +0 -17
  208. package/dist/version.d.ts +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","source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AAM,CAAC,aAAa;gBACnC,MAAM,EAAE,IAAI,EAAE,MAAM;aACrB,CAAC,CAAC;YAEH,mEAAmE;YACnE,IAAI,CAAC,OAAO,GAAG,IAAA,gCAAc,EAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,aAAa,CACjB,QAAgB,EAChB,IAA+B;QAE/B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;YAC/C,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE;YAC1B,QAAQ;YACR,MAAM,EAAE,IAAI,EAAE,MAAM;SACrB,CAAC,CAAC;QAEH,kEAAkE;QAClE,IAAI,CAAC,OAAO,GAAG,IAAA,gCAAc,EAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,QAAQ,CAAC,IAGd;QACC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;YAChD,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE;YAC1B,UAAU,EAAE,IAAI,EAAE,UAAU;YAC5B,MAAM,EAAE,IAAI,EAAE,MAAM;SACrB,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,GAAG,IAAA,gCAAc,EAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAErD,OAAO,IAAI,mBAAQ,CAAC;YAClB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ;SACjC,CAAC,CAAC;IACL,CAAC;CACF;AA/lBD,0BA+lBC"}
1
+ {"version":3,"file":"session.js","names":["params: RunCommandParams","command","path"],"sources":["../src/session.ts"],"sourcesContent":["import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from \"@workflow/serde\";\nimport { type SessionMetaData, type SandboxRouteData, type SandboxMetaData, type SnapshotMetadata, APIClient } from \"./api-client/index.js\";\nimport type { Writable } from \"stream\";\nimport { pipeline } from \"stream/promises\";\nimport { createWriteStream } from \"fs\";\nimport { mkdir } from \"fs/promises\";\nimport { dirname, resolve } from \"path\";\nimport { Command, CommandFinished } from \"./command.js\";\nimport { Snapshot } from \"./snapshot.js\";\nimport { consumeReadable } from \"./utils/consume-readable.js\";\nimport type {\n NetworkPolicy,\n NetworkPolicyRule,\n NetworkTransformer,\n} from \"./network-policy.js\";\nimport { toSandboxSnapshot, type SandboxSnapshot } from \"./utils/sandbox-snapshot.js\";\nimport { getCredentials } from \"./utils/get-credentials.js\";\n\nexport type { NetworkPolicy, NetworkPolicyRule, NetworkTransformer };\n\n/**\n * Serialized representation of a Session for @workflow/serde.\n */\nexport interface SerializedSession {\n session: SandboxSnapshot;\n routes: SandboxRouteData[];\n}\n\n/** @inline */\nexport interface RunCommandParams {\n /**\n * The command to execute\n */\n cmd: string;\n /**\n * Arguments to pass to the command\n */\n args?: string[];\n /**\n * Working directory to execute the command in\n */\n cwd?: string;\n /**\n * Environment variables to set for this command\n */\n env?: Record<string, string>;\n /**\n * If true, execute this command with root privileges. Defaults to false.\n */\n sudo?: boolean;\n /**\n * If true, the command will return without waiting for `exitCode`\n */\n detached?: boolean;\n /**\n * A `Writable` stream where `stdout` from the command will be piped\n */\n stdout?: Writable;\n /**\n * A `Writable` stream where `stderr` from the command will be piped\n */\n stderr?: Writable;\n /**\n * An AbortSignal to cancel the command execution\n */\n signal?: AbortSignal;\n}\n\n/**\n * A Session represents a running VM instance within a {@link Sandbox}.\n *\n * Obtain a session via {@link Sandbox.currentSession}.\n */\nexport class Session {\n private _client: APIClient | null = null;\n\n /**\n * Lazily resolve credentials and construct an API client.\n * This is used in step contexts where the Sandbox was deserialized\n * without a client (e.g. when crossing workflow/step boundaries).\n * Uses getCredentials() which resolves from OIDC or env vars.\n * @internal\n */\n private async ensureClient(): Promise<APIClient> {\n \"use step\";\n if (this._client) return this._client;\n const credentials = await getCredentials();\n this._client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n });\n return this._client;\n }\n\n /**\n * Routes from ports to subdomains.\n * @hidden\n */\n public readonly routes: SandboxRouteData[];\n\n /**\n * Internal metadata about the current session.\n */\n private session: SandboxSnapshot;\n\n private get client(): APIClient {\n if (!this._client) throw new Error(\"API client not initialized\");\n return this._client;\n }\n\n /** @internal */\n get _sessionSnapshot(): SandboxSnapshot {\n return this.session;\n }\n\n /**\n * Unique ID of this session.\n */\n public get sessionId(): string {\n return this.session.id;\n }\n\n public get interactivePort(): number | undefined {\n return this.session.interactivePort ?? undefined;\n }\n\n /**\n * The status of this session.\n */\n public get status(): SessionMetaData[\"status\"] {\n return this.session.status;\n }\n\n /**\n * The creation date of this session.\n */\n public get createdAt(): Date {\n return new Date(this.session.createdAt);\n }\n\n /**\n * The timeout of this session in milliseconds.\n */\n public get timeout(): number {\n return this.session.timeout;\n }\n\n /**\n * The network policy of this session.\n */\n public get networkPolicy(): NetworkPolicy | undefined {\n return this.session.networkPolicy;\n }\n\n /**\n * If the session was created from a snapshot, the ID of that snapshot.\n */\n public get sourceSnapshotId(): string | undefined {\n return this.session.sourceSnapshotId;\n }\n\n /**\n * Memory allocated to this session in MB.\n */\n public get memory(): number {\n return this.session.memory;\n }\n\n /**\n * Number of vCPUs allocated to this session.\n */\n public get vcpus(): number {\n return this.session.vcpus;\n }\n\n /**\n * The region where this session is hosted.\n */\n public get region(): string {\n return this.session.region;\n }\n\n /**\n * Runtime identifier (e.g. \"node24\", \"python3.13\").\n */\n public get runtime(): string {\n return this.session.runtime;\n }\n\n /**\n * The working directory of this session.\n */\n public get cwd(): string {\n return this.session.cwd;\n }\n\n /**\n * When this session was requested.\n */\n public get requestedAt(): Date {\n return new Date(this.session.requestedAt);\n }\n\n /**\n * When this session started running.\n */\n public get startedAt(): Date | undefined {\n return this.session.startedAt != null\n ? new Date(this.session.startedAt)\n : undefined;\n }\n\n /**\n * When this session was requested to stop.\n */\n public get requestedStopAt(): Date | undefined {\n return this.session.requestedStopAt != null\n ? new Date(this.session.requestedStopAt)\n : undefined;\n }\n\n /**\n * When this session was stopped.\n */\n public get stoppedAt(): Date | undefined {\n return this.session.stoppedAt != null\n ? new Date(this.session.stoppedAt)\n : undefined;\n }\n\n /**\n * When this session was aborted.\n */\n public get abortedAt(): Date | undefined {\n return this.session.abortedAt != null\n ? new Date(this.session.abortedAt)\n : undefined;\n }\n\n /**\n * The wall-clock duration of this session in milliseconds.\n */\n public get duration(): number | undefined {\n return this.session.duration;\n }\n\n /**\n * When a snapshot was requested for this session.\n */\n public get snapshottedAt(): Date | undefined {\n return this.session.snapshottedAt != null\n ? new Date(this.session.snapshottedAt)\n : undefined;\n }\n\n /**\n * When this session was last updated.\n */\n public get updatedAt(): Date {\n return new Date(this.session.updatedAt);\n }\n\n /**\n * The amount of active CPU used by the session. Only reported once the VM is\n * stopped.\n */\n public get activeCpuUsageMs(): number | undefined {\n return this.session.activeCpuDurationMs;\n }\n\n /**\n * The amount of network data used by the session. Only reported once the VM\n * is stopped.\n */\n public get networkTransfer():\n | { ingress: number; egress: number }\n | undefined {\n return this.session.networkTransfer;\n }\n\n /**\n * Serialize a Session instance to plain data for @workflow/serde.\n *\n * Although Sandbox handles top-level serialization, Session needs these\n * methods so the Workflow SWC compiler can resolve the class by name.\n * The `new Session(...)` self-reference in WORKFLOW_DESERIALIZE forces\n * rolldown to preserve the class name in the compiled output.\n */\n static [WORKFLOW_SERIALIZE](instance: Session): SerializedSession {\n return {\n session: instance.session,\n routes: instance.routes,\n };\n }\n\n static [WORKFLOW_DESERIALIZE](data: SerializedSession): Session {\n return new Session({ routes: data.routes, snapshot: data.session });\n }\n\n constructor(params: {\n client: APIClient;\n routes: SandboxRouteData[];\n session: SessionMetaData;\n } | {\n /** @internal – used during deserialization with an already-converted snapshot */\n routes: SandboxRouteData[];\n snapshot: SandboxSnapshot;\n }) {\n this.routes = params.routes;\n if (\"snapshot\" in params) {\n this.session = params.snapshot;\n } else {\n this._client = params.client;\n this.session = toSandboxSnapshot(params.session);\n }\n }\n\n /** @internal */\n updateRoutes(routes: SandboxRouteData[]): void {\n (this as { routes: SandboxRouteData[] }).routes = routes;\n }\n\n /**\n * Get a previously run command by its ID.\n *\n * @param cmdId - ID of the command to retrieve\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A {@link Command} instance representing the command\n */\n async getCommand(\n cmdId: string,\n opts?: { signal?: AbortSignal },\n ): Promise<Command> {\n \"use step\";\n const client = await this.ensureClient();\n const command = await client.getCommand({\n sessionId: this.session.id,\n cmdId,\n signal: opts?.signal,\n });\n\n return new Command({\n client,\n sessionId: this.session.id,\n cmd: command.json.command,\n });\n }\n\n /**\n * Start executing a command in this session.\n *\n * @param command - The command to execute.\n * @param args - Arguments to pass to the command.\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the command execution.\n * @returns A {@link CommandFinished} result once execution is done.\n */\n async runCommand(\n command: string,\n args?: string[],\n opts?: { signal?: AbortSignal },\n ): Promise<CommandFinished>;\n\n /**\n * Start executing a command in detached mode.\n *\n * @param params - The command parameters.\n * @returns A {@link Command} instance for the running command.\n */\n async runCommand(\n params: RunCommandParams & { detached: true },\n ): Promise<Command>;\n\n /**\n * Start executing a command in this session.\n *\n * @param params - The command parameters.\n * @returns A {@link CommandFinished} result once execution is done.\n */\n async runCommand(params: RunCommandParams): Promise<CommandFinished>;\n\n async runCommand(\n commandOrParams: string | RunCommandParams,\n args?: string[],\n opts?: { signal?: AbortSignal },\n ): Promise<Command | CommandFinished> {\n \"use step\";\n const client = await this.ensureClient();\n const params: RunCommandParams =\n typeof commandOrParams === \"string\"\n ? { cmd: commandOrParams, args, signal: opts?.signal }\n : commandOrParams;\n const wait = params.detached ? false : true;\n const pipeLogs = async (command: Command): Promise<void> => {\n if (!params.stdout && !params.stderr) {\n return;\n }\n\n try {\n for await (const log of command.logs({ signal: params.signal })) {\n if (log.stream === \"stdout\") {\n params.stdout?.write(log.data);\n } else if (log.stream === \"stderr\") {\n params.stderr?.write(log.data);\n }\n }\n } catch (err) {\n if (params.signal?.aborted) {\n return;\n }\n throw err;\n }\n };\n\n if (wait) {\n const commandStream = await client.runCommand({\n sessionId: this.session.id,\n command: params.cmd,\n args: params.args ?? [],\n cwd: params.cwd,\n env: params.env ?? {},\n sudo: params.sudo ?? false,\n wait: true,\n signal: params.signal,\n });\n\n const command = new Command({\n client,\n sessionId: this.session.id,\n cmd: commandStream.command,\n });\n\n const [finished] = await Promise.all([\n commandStream.finished,\n pipeLogs(command),\n ]);\n return new CommandFinished({\n client,\n sessionId: this.session.id,\n cmd: finished,\n exitCode: finished.exitCode ?? 0,\n });\n }\n\n const commandResponse = await client.runCommand({\n sessionId: this.session.id,\n command: params.cmd,\n args: params.args ?? [],\n cwd: params.cwd,\n env: params.env ?? {},\n sudo: params.sudo ?? false,\n signal: params.signal,\n });\n\n const command = new Command({\n client,\n sessionId: this.session.id,\n cmd: commandResponse.json.command,\n });\n\n void pipeLogs(command).catch((err) => {\n if (params.signal?.aborted) {\n return;\n }\n (params.stderr ?? params.stdout)?.emit(\"error\", err);\n });\n\n return command;\n }\n\n /**\n * Create a directory in the filesystem of this session.\n *\n * @param path - Path of the directory to create\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n */\n async mkDir(path: string, opts?: { signal?: AbortSignal }): Promise<void> {\n \"use step\";\n const client = await this.ensureClient();\n await client.mkDir({\n sessionId: this.session.id,\n path: path,\n signal: opts?.signal,\n });\n }\n\n /**\n * Read a file from the filesystem of this session as a stream.\n *\n * @param file - File to read, with path and optional cwd\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves to a ReadableStream containing the file contents, or null if file not found\n */\n async readFile(\n file: { path: string; cwd?: string },\n opts?: { signal?: AbortSignal },\n ): Promise<NodeJS.ReadableStream | null> {\n \"use step\";\n const client = await this.ensureClient();\n return client.readFile({\n sessionId: this.session.id,\n path: file.path,\n cwd: file.cwd,\n signal: opts?.signal,\n });\n }\n\n /**\n * Read a file from the filesystem of this session as a Buffer.\n *\n * @param file - File to read, with path and optional cwd\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves to the file contents as a Buffer, or null if file not found\n */\n async readFileToBuffer(\n file: { path: string; cwd?: string },\n opts?: { signal?: AbortSignal },\n ): Promise<Buffer | null> {\n \"use step\";\n const client = await this.ensureClient();\n const stream = await client.readFile({\n sessionId: this.session.id,\n path: file.path,\n cwd: file.cwd,\n signal: opts?.signal,\n });\n\n if (stream === null) {\n return null;\n }\n\n return consumeReadable(stream);\n }\n\n /**\n * Download a file from the session to the local filesystem.\n *\n * @param src - Source file on the session, with path and optional cwd\n * @param dst - Destination file on the local machine, with path and optional cwd\n * @param opts - Optional parameters.\n * @param opts.mkdirRecursive - If true, create parent directories for the destination if they don't exist.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns The absolute path to the written file, or null if the source file was not found\n */\n async downloadFile(\n src: { path: string; cwd?: string },\n dst: { path: string; cwd?: string },\n opts?: { mkdirRecursive?: boolean; signal?: AbortSignal },\n ): Promise<string | null> {\n \"use step\";\n const client = await this.ensureClient();\n if (!src?.path) {\n throw new Error(\"downloadFile: source path is required\");\n }\n\n if (!dst?.path) {\n throw new Error(\"downloadFile: destination path is required\");\n }\n\n const stream = await client.readFile({\n sessionId: this.session.id,\n path: src.path,\n cwd: src.cwd,\n signal: opts?.signal,\n });\n\n if (stream === null) {\n return null;\n }\n\n try {\n const dstPath = resolve(dst.cwd ?? \"\", dst.path);\n if (opts?.mkdirRecursive) {\n await mkdir(dirname(dstPath), { recursive: true });\n }\n await pipeline(stream, createWriteStream(dstPath), {\n signal: opts?.signal,\n });\n return dstPath;\n } finally {\n stream.destroy();\n }\n }\n\n /**\n * Write files to the filesystem of this session.\n * Defaults to writing to /vercel/sandbox unless an absolute path is specified.\n * Writes files using the `vercel-sandbox` user.\n *\n * @param files - Array of files with path and stream/buffer contents\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves when the files are written\n */\n async writeFiles(\n files: { path: string; content: string | Uint8Array; mode?: number }[],\n opts?: { signal?: AbortSignal },\n ) {\n \"use step\";\n const client = await this.ensureClient();\n return client.writeFiles({\n sessionId: this.session.id,\n cwd: this.session.cwd,\n extractDir: \"/\",\n files: files,\n signal: opts?.signal,\n });\n }\n\n /**\n * Get the public domain of a port of this session.\n *\n * @param p - Port number to resolve\n * @returns A full domain (e.g. `https://subdomain.vercel.run`)\n * @throws If the port has no associated route\n */\n domain(p: number): string {\n const route = this.routes.find(({ port }) => port == p);\n if (route) {\n return `https://${route.subdomain}.vercel.run`;\n } else {\n throw new Error(`No route for port ${p}`);\n }\n }\n\n /**\n * Stop this session.\n *\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns The final session state and optional sandbox metadata.\n */\n async stop(opts?: {\n signal?: AbortSignal;\n }): Promise<{ session: SandboxSnapshot; sandbox?: SandboxMetaData; snapshot?: SnapshotMetadata }> {\n \"use step\";\n const client = await this.ensureClient();\n const response = await client.stopSession({\n sessionId: this.session.id,\n signal: opts?.signal,\n });\n this.session = toSandboxSnapshot(response.json.session);\n return { session: this.session, sandbox: response.json.sandbox, snapshot: response.json.snapshot };\n }\n\n /**\n * Update the current session's settings.\n *\n * @param params - Fields to update.\n * @param params.networkPolicy - The new network policy to apply.\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n *\n * @example\n * // Restrict to specific domains\n * await session.update({\n * networkPolicy: {\n * allow: [\"*.npmjs.org\", \"github.com\"],\n * }\n * });\n *\n * @example\n * // Inject credentials with per-domain transformers\n * await session.update({\n * networkPolicy: {\n * allow: {\n * \"ai-gateway.vercel.sh\": [{\n * transform: [{\n * headers: { authorization: \"Bearer ...\" }\n * }]\n * }],\n * \"*\": []\n * }\n * }\n * });\n *\n * @example\n * // Deny all network access\n * await session.update({ networkPolicy: \"deny-all\" });\n */\n async update(\n params: {\n networkPolicy?: NetworkPolicy;\n },\n opts?: { signal?: AbortSignal },\n ): Promise<void> {\n \"use step\";\n if (params.networkPolicy !== undefined) {\n const client = await this.ensureClient();\n const response = await client.updateNetworkPolicy({\n sessionId: this.session.id,\n networkPolicy: params.networkPolicy,\n signal: opts?.signal,\n });\n\n // Update the internal session with the new network policy\n this.session = toSandboxSnapshot(response.json.session);\n }\n }\n\n /**\n * Extend the timeout of the session by the specified duration.\n *\n * This allows you to extend the lifetime of a session up until the maximum\n * execution timeout for your plan.\n *\n * @param duration - The duration in milliseconds to extend the timeout by\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves when the timeout is extended\n *\n * @example\n * const sandbox = await Sandbox.create({ timeout: ms('10m') });\n * const session = sandbox.currentSession();\n * // Extends timeout by 5 minutes, to a total of 15 minutes.\n * await session.extendTimeout(ms('5m'));\n */\n async extendTimeout(\n duration: number,\n opts?: { signal?: AbortSignal },\n ): Promise<void> {\n \"use step\";\n const client = await this.ensureClient();\n const response = await client.extendTimeout({\n sessionId: this.session.id,\n duration,\n signal: opts?.signal,\n });\n\n // Update the internal sandbox metadata with the new timeout value\n this.session = toSandboxSnapshot(response.json.session);\n }\n\n /**\n * Create a snapshot from this currently running session. New sandboxes can\n * then be created from this snapshot using {@link Sandbox.create}.\n *\n * Note: this session will be stopped as part of the snapshot creation process.\n *\n * @param opts - Optional parameters.\n * @param opts.expiration - Optional expiration time in milliseconds. Use 0 for no expiration at all.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves to the Snapshot instance\n */\n async snapshot(opts?: {\n expiration?: number;\n signal?: AbortSignal;\n }): Promise<Snapshot> {\n \"use step\";\n const client = await this.ensureClient();\n const response = await client.createSnapshot({\n sessionId: this.session.id,\n expiration: opts?.expiration,\n signal: opts?.signal,\n });\n\n this.session = toSandboxSnapshot(response.json.session);\n\n return new Snapshot({\n client,\n snapshot: response.json.snapshot,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyEA,IAAa,UAAb,MAAa,QAAQ;;;;;;;;CAUnB,MAAc,eAAmC;AAC/C;AACA,MAAI,KAAK,QAAS,QAAO,KAAK;EAC9B,MAAM,cAAc,MAAM,gBAAgB;AAC1C,OAAK,UAAU,IAAI,UAAU;GAC3B,QAAQ,YAAY;GACpB,OAAO,YAAY;GACpB,CAAC;AACF,SAAO,KAAK;;CAcd,IAAY,SAAoB;AAC9B,MAAI,CAAC,KAAK,QAAS,OAAM,IAAI,MAAM,6BAA6B;AAChE,SAAO,KAAK;;;CAId,IAAI,mBAAoC;AACtC,SAAO,KAAK;;;;;CAMd,IAAW,YAAoB;AAC7B,SAAO,KAAK,QAAQ;;CAGtB,IAAW,kBAAsC;AAC/C,SAAO,KAAK,QAAQ,mBAAmB;;;;;CAMzC,IAAW,SAAoC;AAC7C,SAAO,KAAK,QAAQ;;;;;CAMtB,IAAW,YAAkB;AAC3B,SAAO,IAAI,KAAK,KAAK,QAAQ,UAAU;;;;;CAMzC,IAAW,UAAkB;AAC3B,SAAO,KAAK,QAAQ;;;;;CAMtB,IAAW,gBAA2C;AACpD,SAAO,KAAK,QAAQ;;;;;CAMtB,IAAW,mBAAuC;AAChD,SAAO,KAAK,QAAQ;;;;;CAMtB,IAAW,SAAiB;AAC1B,SAAO,KAAK,QAAQ;;;;;CAMtB,IAAW,QAAgB;AACzB,SAAO,KAAK,QAAQ;;;;;CAMtB,IAAW,SAAiB;AAC1B,SAAO,KAAK,QAAQ;;;;;CAMtB,IAAW,UAAkB;AAC3B,SAAO,KAAK,QAAQ;;;;;CAMtB,IAAW,MAAc;AACvB,SAAO,KAAK,QAAQ;;;;;CAMtB,IAAW,cAAoB;AAC7B,SAAO,IAAI,KAAK,KAAK,QAAQ,YAAY;;;;;CA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OADF,MAAM,KAAK,cAAc,EACV,oBAAoB;GAChD,WAAW,KAAK,QAAQ;GACxB,eAAe,OAAO;GACtB,QAAQ,MAAM;GACf,CAAC,EAGwC,KAAK,QAAQ;;;;;;;;;;;;;;;;;;;CAqB3D,MAAM,cACJ,UACA,MACe;AACf;AASA,OAAK,UAAU,mBAPE,OADF,MAAM,KAAK,cAAc,EACV,cAAc;GAC1C,WAAW,KAAK,QAAQ;GACxB;GACA,QAAQ,MAAM;GACf,CAAC,EAGwC,KAAK,QAAQ;;;;;;;;;;;;;CAczD,MAAM,SAAS,MAGO;AACpB;EACA,MAAM,SAAS,MAAM,KAAK,cAAc;EACxC,MAAM,WAAW,MAAM,OAAO,eAAe;GAC3C,WAAW,KAAK,QAAQ;GACxB,YAAY,MAAM;GAClB,QAAQ,MAAM;GACf,CAAC;AAEF,OAAK,UAAU,kBAAkB,SAAS,KAAK,QAAQ;AAEvD,SAAO,IAAI,SAAS;GAClB;GACA,UAAU,SAAS,KAAK;GACzB,CAAC"}
@@ -0,0 +1,204 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_api_client = require('./api-client/api-client.cjs');
3
+ require('./api-client/index.cjs');
4
+ const require_get_credentials = require('./utils/get-credentials.cjs');
5
+ const require_paginator = require('./utils/paginator.cjs');
6
+ let __workflow_serde = require("@workflow/serde");
7
+
8
+ //#region src/snapshot.ts
9
+ /**
10
+ * A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes
11
+ *
12
+ * Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.
13
+ * @hideconstructor
14
+ */
15
+ var Snapshot = class Snapshot {
16
+ /**
17
+ * Lazily resolve credentials and construct an API client.
18
+ * This is used in step contexts where the Snapshot was deserialized
19
+ * without a client (e.g. when crossing workflow/step boundaries).
20
+ * @internal
21
+ */
22
+ async ensureClient() {
23
+ "use step";
24
+ if (this._client) return this._client;
25
+ const credentials = await require_get_credentials.getCredentials();
26
+ this._client = new require_api_client.APIClient({
27
+ teamId: credentials.teamId,
28
+ token: credentials.token
29
+ });
30
+ return this._client;
31
+ }
32
+ /**
33
+ * Unique ID of this snapshot.
34
+ */
35
+ get snapshotId() {
36
+ return this.snapshot.id;
37
+ }
38
+ /**
39
+ * The ID of the session from which this snapshot was created.
40
+ */
41
+ get sourceSessionId() {
42
+ return this.snapshot.sourceSessionId;
43
+ }
44
+ /**
45
+ * The status of the snapshot.
46
+ */
47
+ get status() {
48
+ return this.snapshot.status;
49
+ }
50
+ /**
51
+ * The size of the snapshot in bytes, or null if not available.
52
+ */
53
+ get sizeBytes() {
54
+ return this.snapshot.sizeBytes;
55
+ }
56
+ /**
57
+ * The creation date of this snapshot.
58
+ */
59
+ get createdAt() {
60
+ return new Date(this.snapshot.createdAt);
61
+ }
62
+ /**
63
+ * The expiration date of this snapshot, or undefined if it does not expire.
64
+ */
65
+ get expiresAt() {
66
+ if (this.snapshot.expiresAt === void 0) return;
67
+ return new Date(this.snapshot.expiresAt);
68
+ }
69
+ /**
70
+ * Serialize a Snapshot instance to plain data for @workflow/serde.
71
+ *
72
+ * @param instance - The Snapshot instance to serialize
73
+ * @returns A plain object containing snapshot metadata
74
+ */
75
+ static [__workflow_serde.WORKFLOW_SERIALIZE](instance) {
76
+ return { snapshot: instance.snapshot };
77
+ }
78
+ /**
79
+ * Deserialize a Snapshot from serialized data.
80
+ *
81
+ * The deserialized instance uses the serialized metadata synchronously and
82
+ * lazily creates an API client only when methods perform API requests.
83
+ *
84
+ * @param data - The serialized snapshot data
85
+ * @returns The reconstructed Snapshot instance
86
+ */
87
+ static [__workflow_serde.WORKFLOW_DESERIALIZE](data) {
88
+ return new Snapshot({ snapshot: data.snapshot });
89
+ }
90
+ constructor({ client, snapshot }) {
91
+ this._client = null;
92
+ this._client = client ?? null;
93
+ this.snapshot = snapshot;
94
+ }
95
+ /**
96
+ * Allow to get a list of snapshots for a team narrowed to the given params.
97
+ * It returns both the snapshots and the pagination metadata to allow getting
98
+ * the next page of results.
99
+ *
100
+ * The returned object is async-iterable to auto-paginate through all pages:
101
+ *
102
+ * ```ts
103
+ * const result = await Snapshot.list({ name: "my-sandbox" });
104
+ * for await (const snapshot of result) { ... }
105
+ * // or: await result.toArray();
106
+ * // or: for await (const page of result.pages()) { ... }
107
+ * ```
108
+ */
109
+ static async list(params) {
110
+ "use step";
111
+ const credentials = await require_get_credentials.getCredentials(params);
112
+ const client = new require_api_client.APIClient({
113
+ teamId: credentials.teamId,
114
+ token: credentials.token,
115
+ fetch: params?.fetch
116
+ });
117
+ const fetchPage = async (cursor) => {
118
+ return (await client.listSnapshots({
119
+ ...credentials,
120
+ ...params,
121
+ ...cursor !== void 0 && { cursor }
122
+ })).json;
123
+ };
124
+ return require_paginator.attachPaginator(await fetchPage(params?.cursor), {
125
+ itemsKey: "snapshots",
126
+ fetchNext: fetchPage,
127
+ signal: params?.signal
128
+ });
129
+ }
130
+ /**
131
+ * Resolve the current snapshot ID of an existing sandbox by name.
132
+ *
133
+ * Useful to feed into {@link Sandbox.create} as `source.snapshotId` without
134
+ * having to first look up the sandbox yourself.
135
+ *
136
+ * @param name - The name of the source sandbox.
137
+ * @param opts - Optional credentials, fetch override, and abort signal.
138
+ * @returns The current snapshot ID of the named sandbox.
139
+ * @throws If the sandbox has no current snapshot.
140
+ *
141
+ * @example
142
+ * const sandbox = await Sandbox.create({
143
+ * source: {
144
+ * type: "snapshot",
145
+ * snapshotId: await Snapshot.fromSandbox("my-sandbox"),
146
+ * },
147
+ * });
148
+ */
149
+ static async fromSandbox(name, opts) {
150
+ "use step";
151
+ const credentials = await require_get_credentials.getCredentials(opts);
152
+ const snapshotId = (await new require_api_client.APIClient({
153
+ teamId: credentials.teamId,
154
+ token: credentials.token,
155
+ fetch: opts?.fetch
156
+ }).getSandbox({
157
+ name,
158
+ projectId: credentials.projectId,
159
+ resume: false,
160
+ signal: opts?.signal
161
+ })).json.sandbox.currentSnapshotId;
162
+ if (!snapshotId) throw new Error(`Sandbox "${name}" has no current snapshot.`);
163
+ return snapshotId;
164
+ }
165
+ /**
166
+ * Retrieve an existing snapshot.
167
+ *
168
+ * @param params - Get parameters and optional credentials.
169
+ * @returns A promise resolving to the {@link Sandbox}.
170
+ */
171
+ static async get(params) {
172
+ "use step";
173
+ const credentials = await require_get_credentials.getCredentials(params);
174
+ const client = new require_api_client.APIClient({
175
+ teamId: credentials.teamId,
176
+ token: credentials.token
177
+ });
178
+ return new Snapshot({
179
+ client,
180
+ snapshot: (await client.getSnapshot({
181
+ snapshotId: params.snapshotId,
182
+ signal: params.signal
183
+ })).json.snapshot
184
+ });
185
+ }
186
+ /**
187
+ * Delete this snapshot.
188
+ *
189
+ * @param opts - Optional parameters.
190
+ * @param opts.signal - An AbortSignal to cancel the operation.
191
+ * @returns A promise that resolves once the snapshot has been deleted.
192
+ */
193
+ async delete(opts) {
194
+ "use step";
195
+ this.snapshot = (await (await this.ensureClient()).deleteSnapshot({
196
+ snapshotId: this.snapshot.id,
197
+ signal: opts?.signal
198
+ })).json.snapshot;
199
+ }
200
+ };
201
+
202
+ //#endregion
203
+ exports.Snapshot = Snapshot;
204
+ //# sourceMappingURL=snapshot.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.cjs","names":["getCredentials","APIClient","WORKFLOW_SERIALIZE","WORKFLOW_DESERIALIZE","attachPaginator"],"sources":["../src/snapshot.ts"],"sourcesContent":["import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from \"@workflow/serde\";\nimport type { WithFetchOptions } from \"./api-client/api-client.js\";\nimport type { SnapshotMetadata } from \"./api-client/index.js\";\nimport { APIClient } from \"./api-client/index.js\";\nimport { type Credentials, getCredentials } from \"./utils/get-credentials.js\";\nimport { attachPaginator } from \"./utils/paginator.js\";\n\nexport interface SerializedSnapshot {\n snapshot: SnapshotMetadata;\n}\n\n/** @inline */\ninterface GetSnapshotParams {\n /**\n * Unique identifier of the snapshot.\n */\n snapshotId: string;\n /**\n * An AbortSignal to cancel the operation.\n */\n signal?: AbortSignal;\n}\n\n/**\n * A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes\n *\n * Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.\n * @hideconstructor\n */\nexport class Snapshot {\n private _client: APIClient | null = null;\n\n /**\n * Lazily resolve credentials and construct an API client.\n * This is used in step contexts where the Snapshot was deserialized\n * without a client (e.g. when crossing workflow/step boundaries).\n * @internal\n */\n private async ensureClient(): Promise<APIClient> {\n \"use step\";\n if (this._client) return this._client;\n const credentials = await getCredentials();\n this._client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n });\n return this._client;\n }\n\n /**\n * Unique ID of this snapshot.\n */\n public get snapshotId(): string {\n return this.snapshot.id;\n }\n\n /**\n * The ID of the session from which this snapshot was created.\n */\n public get sourceSessionId(): string {\n return this.snapshot.sourceSessionId;\n }\n\n /**\n * The status of the snapshot.\n */\n public get status(): SnapshotMetadata[\"status\"] {\n return this.snapshot.status;\n }\n\n /**\n * The size of the snapshot in bytes, or null if not available.\n */\n public get sizeBytes(): number {\n return this.snapshot.sizeBytes;\n }\n\n /**\n * The creation date of this snapshot.\n */\n public get createdAt(): Date {\n return new Date(this.snapshot.createdAt);\n }\n\n /**\n * The expiration date of this snapshot, or undefined if it does not expire.\n */\n public get expiresAt(): Date | undefined {\n if (this.snapshot.expiresAt === undefined) {\n return undefined;\n }\n\n return new Date(this.snapshot.expiresAt);\n }\n\n /**\n * Internal metadata about this snapshot.\n */\n private snapshot: SnapshotMetadata;\n\n /**\n * Serialize a Snapshot instance to plain data for @workflow/serde.\n *\n * @param instance - The Snapshot instance to serialize\n * @returns A plain object containing snapshot metadata\n */\n static [WORKFLOW_SERIALIZE](instance: Snapshot): SerializedSnapshot {\n return {\n snapshot: instance.snapshot,\n };\n }\n\n /**\n * Deserialize a Snapshot from serialized data.\n *\n * The deserialized instance uses the serialized metadata synchronously and\n * lazily creates an API client only when methods perform API requests.\n *\n * @param data - The serialized snapshot data\n * @returns The reconstructed Snapshot instance\n */\n static [WORKFLOW_DESERIALIZE](data: SerializedSnapshot): Snapshot {\n return new Snapshot({\n snapshot: data.snapshot,\n });\n }\n\n constructor({\n client,\n snapshot,\n }: {\n client?: APIClient;\n snapshot: SnapshotMetadata;\n }) {\n this._client = client ?? null;\n this.snapshot = snapshot;\n }\n\n /**\n * Allow to get a list of snapshots for a team narrowed to the given params.\n * It returns both the snapshots and the pagination metadata to allow getting\n * the next page of results.\n *\n * The returned object is async-iterable to auto-paginate through all pages:\n *\n * ```ts\n * const result = await Snapshot.list({ name: \"my-sandbox\" });\n * for await (const snapshot of result) { ... }\n * // or: await result.toArray();\n * // or: for await (const page of result.pages()) { ... }\n * ```\n */\n static async list(\n params?: Partial<Parameters<APIClient[\"listSnapshots\"]>[0]> &\n Partial<Credentials> &\n WithFetchOptions,\n ) {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: params?.fetch,\n });\n const fetchPage = async (cursor?: string) => {\n const response = await client.listSnapshots({\n ...credentials,\n ...params,\n ...(cursor !== undefined && { cursor }),\n });\n return response.json;\n };\n const firstPage = await fetchPage(params?.cursor);\n return attachPaginator(firstPage, {\n itemsKey: \"snapshots\",\n fetchNext: fetchPage,\n signal: params?.signal,\n });\n }\n\n /**\n * Resolve the current snapshot ID of an existing sandbox by name.\n *\n * Useful to feed into {@link Sandbox.create} as `source.snapshotId` without\n * having to first look up the sandbox yourself.\n *\n * @param name - The name of the source sandbox.\n * @param opts - Optional credentials, fetch override, and abort signal.\n * @returns The current snapshot ID of the named sandbox.\n * @throws If the sandbox has no current snapshot.\n *\n * @example\n * const sandbox = await Sandbox.create({\n * source: {\n * type: \"snapshot\",\n * snapshotId: await Snapshot.fromSandbox(\"my-sandbox\"),\n * },\n * });\n */\n static async fromSandbox(\n name: string,\n opts?: Partial<Credentials> & WithFetchOptions & { signal?: AbortSignal },\n ): Promise<string> {\n \"use step\";\n const credentials = await getCredentials(opts);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: opts?.fetch,\n });\n\n const response = await client.getSandbox({\n name,\n projectId: credentials.projectId,\n resume: false,\n signal: opts?.signal,\n });\n\n const snapshotId = response.json.sandbox.currentSnapshotId;\n if (!snapshotId) {\n throw new Error(`Sandbox \"${name}\" has no current snapshot.`);\n }\n return snapshotId;\n }\n\n /**\n * Retrieve an existing snapshot.\n *\n * @param params - Get parameters and optional credentials.\n * @returns A promise resolving to the {@link Sandbox}.\n */\n static async get(\n params: GetSnapshotParams | (GetSnapshotParams & Credentials),\n ): Promise<Snapshot> {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n });\n\n const sandbox = await client.getSnapshot({\n snapshotId: params.snapshotId,\n signal: params.signal,\n });\n\n return new Snapshot({\n client,\n snapshot: sandbox.json.snapshot,\n });\n }\n\n /**\n * Delete this snapshot.\n *\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves once the snapshot has been deleted.\n */\n async delete(opts?: { signal?: AbortSignal }): Promise<void> {\n \"use step\";\n const client = await this.ensureClient();\n const response = await client.deleteSnapshot({\n snapshotId: this.snapshot.id,\n signal: opts?.signal,\n });\n\n this.snapshot = response.json.snapshot;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA6BA,IAAa,WAAb,MAAa,SAAS;;;;;;;CASpB,MAAc,eAAmC;AAC/C;AACA,MAAI,KAAK,QAAS,QAAO,KAAK;EAC9B,MAAM,cAAc,MAAMA,wCAAgB;AAC1C,OAAK,UAAU,IAAIC,6BAAU;GAC3B,QAAQ,YAAY;GACpB,OAAO,YAAY;GACpB,CAAC;AACF,SAAO,KAAK;;;;;CAMd,IAAW,aAAqB;AAC9B,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,kBAA0B;AACnC,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,SAAqC;AAC9C,SAAO,KAAK,SAAS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AC,WACH,OAAM,IAAI,MAAM,YAAY,KAAK,4BAA4B;AAE/D,SAAO;;;;;;;;CAST,aAAa,IACX,QACmB;AACnB;EACA,MAAM,cAAc,MAAMD,uCAAe,OAAO;EAChD,MAAM,SAAS,IAAIC,6BAAU;GAC3B,QAAQ,YAAY;GACpB,OAAO,YAAY;GACpB,CAAC;AAOF,SAAO,IAAI,SAAS;GAClB;GACA,WAPc,MAAM,OAAO,YAAY;IACvC,YAAY,OAAO;IACnB,QAAQ,OAAO;IAChB,CAAC,EAIkB,KAAK;GACxB,CAAC;;;;;;;;;CAUJ,MAAM,OAAO,MAAgD;AAC3D;AAOA,OAAK,YALY,OADF,MAAM,KAAK,cAAc,EACV,eAAe;GAC3C,YAAY,KAAK,SAAS;GAC1B,QAAQ,MAAM;GACf,CAAC,EAEuB,KAAK"}
@@ -0,0 +1,161 @@
1
+ import { Paginator } from "./utils/paginator.cjs";
2
+ import { SnapshotMetadata } from "./api-client/validators.cjs";
3
+ import { APIClient, WithFetchOptions } from "./api-client/api-client.cjs";
4
+ import { Credentials } from "./utils/get-credentials.cjs";
5
+ import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@workflow/serde";
6
+
7
+ //#region src/snapshot.d.ts
8
+ interface SerializedSnapshot {
9
+ snapshot: SnapshotMetadata;
10
+ }
11
+ /** @inline */
12
+ interface GetSnapshotParams {
13
+ /**
14
+ * Unique identifier of the snapshot.
15
+ */
16
+ snapshotId: string;
17
+ /**
18
+ * An AbortSignal to cancel the operation.
19
+ */
20
+ signal?: AbortSignal;
21
+ }
22
+ /**
23
+ * A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes
24
+ *
25
+ * Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.
26
+ * @hideconstructor
27
+ */
28
+ declare class Snapshot {
29
+ private _client;
30
+ /**
31
+ * Lazily resolve credentials and construct an API client.
32
+ * This is used in step contexts where the Snapshot was deserialized
33
+ * without a client (e.g. when crossing workflow/step boundaries).
34
+ * @internal
35
+ */
36
+ private ensureClient;
37
+ /**
38
+ * Unique ID of this snapshot.
39
+ */
40
+ get snapshotId(): string;
41
+ /**
42
+ * The ID of the session from which this snapshot was created.
43
+ */
44
+ get sourceSessionId(): string;
45
+ /**
46
+ * The status of the snapshot.
47
+ */
48
+ get status(): SnapshotMetadata["status"];
49
+ /**
50
+ * The size of the snapshot in bytes, or null if not available.
51
+ */
52
+ get sizeBytes(): number;
53
+ /**
54
+ * The creation date of this snapshot.
55
+ */
56
+ get createdAt(): Date;
57
+ /**
58
+ * The expiration date of this snapshot, or undefined if it does not expire.
59
+ */
60
+ get expiresAt(): Date | undefined;
61
+ /**
62
+ * Internal metadata about this snapshot.
63
+ */
64
+ private snapshot;
65
+ /**
66
+ * Serialize a Snapshot instance to plain data for @workflow/serde.
67
+ *
68
+ * @param instance - The Snapshot instance to serialize
69
+ * @returns A plain object containing snapshot metadata
70
+ */
71
+ static [WORKFLOW_SERIALIZE](instance: Snapshot): SerializedSnapshot;
72
+ /**
73
+ * Deserialize a Snapshot from serialized data.
74
+ *
75
+ * The deserialized instance uses the serialized metadata synchronously and
76
+ * lazily creates an API client only when methods perform API requests.
77
+ *
78
+ * @param data - The serialized snapshot data
79
+ * @returns The reconstructed Snapshot instance
80
+ */
81
+ static [WORKFLOW_DESERIALIZE](data: SerializedSnapshot): Snapshot;
82
+ constructor({
83
+ client,
84
+ snapshot
85
+ }: {
86
+ client?: APIClient;
87
+ snapshot: SnapshotMetadata;
88
+ });
89
+ /**
90
+ * Allow to get a list of snapshots for a team narrowed to the given params.
91
+ * It returns both the snapshots and the pagination metadata to allow getting
92
+ * the next page of results.
93
+ *
94
+ * The returned object is async-iterable to auto-paginate through all pages:
95
+ *
96
+ * ```ts
97
+ * const result = await Snapshot.list({ name: "my-sandbox" });
98
+ * for await (const snapshot of result) { ... }
99
+ * // or: await result.toArray();
100
+ * // or: for await (const page of result.pages()) { ... }
101
+ * ```
102
+ */
103
+ static list(params?: Partial<Parameters<APIClient["listSnapshots"]>[0]> & Partial<Credentials> & WithFetchOptions): Promise<Paginator<{
104
+ pagination: {
105
+ count: number;
106
+ next: string | null;
107
+ };
108
+ snapshots: {
109
+ status: "failed" | "created" | "deleted";
110
+ region: string;
111
+ createdAt: number;
112
+ updatedAt: number;
113
+ id: string;
114
+ sourceSessionId: string;
115
+ sizeBytes: number;
116
+ expiresAt?: number | undefined;
117
+ }[];
118
+ }, "snapshots">>;
119
+ /**
120
+ * Resolve the current snapshot ID of an existing sandbox by name.
121
+ *
122
+ * Useful to feed into {@link Sandbox.create} as `source.snapshotId` without
123
+ * having to first look up the sandbox yourself.
124
+ *
125
+ * @param name - The name of the source sandbox.
126
+ * @param opts - Optional credentials, fetch override, and abort signal.
127
+ * @returns The current snapshot ID of the named sandbox.
128
+ * @throws If the sandbox has no current snapshot.
129
+ *
130
+ * @example
131
+ * const sandbox = await Sandbox.create({
132
+ * source: {
133
+ * type: "snapshot",
134
+ * snapshotId: await Snapshot.fromSandbox("my-sandbox"),
135
+ * },
136
+ * });
137
+ */
138
+ static fromSandbox(name: string, opts?: Partial<Credentials> & WithFetchOptions & {
139
+ signal?: AbortSignal;
140
+ }): Promise<string>;
141
+ /**
142
+ * Retrieve an existing snapshot.
143
+ *
144
+ * @param params - Get parameters and optional credentials.
145
+ * @returns A promise resolving to the {@link Sandbox}.
146
+ */
147
+ static get(params: GetSnapshotParams | (GetSnapshotParams & Credentials)): Promise<Snapshot>;
148
+ /**
149
+ * Delete this snapshot.
150
+ *
151
+ * @param opts - Optional parameters.
152
+ * @param opts.signal - An AbortSignal to cancel the operation.
153
+ * @returns A promise that resolves once the snapshot has been deleted.
154
+ */
155
+ delete(opts?: {
156
+ signal?: AbortSignal;
157
+ }): Promise<void>;
158
+ }
159
+ //#endregion
160
+ export { SerializedSnapshot, Snapshot };
161
+ //# sourceMappingURL=snapshot.d.cts.map