@vercel/sandbox 1.8.1 → 1.9.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/README.md +8 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/api-client/api-client.cjs +375 -0
- package/dist/api-client/api-client.cjs.map +1 -0
- package/dist/api-client/api-client.d.cts +403 -0
- package/dist/api-client/api-client.d.ts +397 -391
- package/dist/api-client/api-client.js +365 -404
- package/dist/api-client/api-client.js.map +1 -1
- package/dist/api-client/api-error.cjs +31 -0
- package/dist/api-client/api-error.cjs.map +1 -0
- package/dist/api-client/api-error.d.cts +27 -0
- package/dist/api-client/api-error.d.ts +19 -16
- package/dist/api-client/api-error.js +27 -32
- package/dist/api-client/api-error.js.map +1 -1
- package/dist/api-client/base-client.cjs +113 -0
- package/dist/api-client/base-client.cjs.map +1 -0
- package/dist/api-client/base-client.d.cts +38 -0
- package/dist/api-client/base-client.d.ts +31 -36
- package/dist/api-client/base-client.js +101 -118
- package/dist/api-client/base-client.js.map +1 -1
- package/dist/api-client/file-writer.cjs +62 -0
- package/dist/api-client/file-writer.cjs.map +1 -0
- package/dist/api-client/file-writer.d.cts +66 -0
- package/dist/api-client/file-writer.d.ts +56 -42
- package/dist/api-client/file-writer.js +57 -61
- package/dist/api-client/file-writer.js.map +1 -1
- package/dist/api-client/index.cjs +2 -0
- package/dist/api-client/index.d.ts +2 -2
- package/dist/api-client/index.js +4 -21
- package/dist/api-client/validators.cjs +149 -0
- package/dist/api-client/validators.cjs.map +1 -0
- package/dist/api-client/validators.d.cts +1677 -0
- package/dist/api-client/validators.d.ts +1501 -2412
- package/dist/api-client/validators.js +124 -154
- package/dist/api-client/validators.js.map +1 -1
- package/dist/api-client/with-retry.cjs +89 -0
- package/dist/api-client/with-retry.cjs.map +1 -0
- package/dist/api-client/with-retry.d.cts +10 -0
- package/dist/api-client/with-retry.d.ts +9 -13
- package/dist/api-client/with-retry.js +81 -102
- package/dist/api-client/with-retry.js.map +1 -1
- package/dist/auth/api.cjs +29 -0
- package/dist/auth/api.cjs.map +1 -0
- package/dist/auth/api.js +26 -25
- package/dist/auth/api.js.map +1 -1
- package/dist/auth/error.cjs +13 -0
- package/dist/auth/error.cjs.map +1 -0
- package/dist/auth/error.js +11 -11
- package/dist/auth/error.js.map +1 -1
- package/dist/auth/file.cjs +64 -0
- package/dist/auth/file.cjs.map +1 -0
- package/dist/auth/file.d.cts +26 -0
- package/dist/auth/file.d.ts +19 -15
- package/dist/auth/file.js +49 -64
- package/dist/auth/file.js.map +1 -1
- package/dist/auth/index.cjs +12 -0
- package/dist/auth/index.d.cts +5 -0
- package/dist/auth/index.d.ts +5 -6
- package/dist/auth/index.js +6 -27
- package/dist/auth/linked-project.cjs +38 -0
- package/dist/auth/linked-project.cjs.map +1 -0
- package/dist/auth/linked-project.js +30 -64
- package/dist/auth/linked-project.js.map +1 -1
- package/dist/auth/oauth.cjs +205 -0
- package/dist/auth/oauth.cjs.map +1 -0
- package/dist/auth/oauth.d.cts +135 -0
- package/dist/auth/oauth.d.ts +113 -109
- package/dist/auth/oauth.js +185 -252
- package/dist/auth/oauth.js.map +1 -1
- package/dist/auth/poll-for-token.cjs +82 -0
- package/dist/auth/poll-for-token.cjs.map +1 -0
- package/dist/auth/poll-for-token.d.cts +28 -0
- package/dist/auth/poll-for-token.d.ts +23 -15
- package/dist/auth/poll-for-token.js +79 -64
- package/dist/auth/poll-for-token.js.map +1 -1
- package/dist/auth/project.cjs +80 -0
- package/dist/auth/project.cjs.map +1 -0
- package/dist/auth/project.d.cts +44 -0
- package/dist/auth/project.d.ts +12 -8
- package/dist/auth/project.js +70 -72
- package/dist/auth/project.js.map +1 -1
- package/dist/auth/zod.cjs +22 -0
- package/dist/auth/zod.cjs.map +1 -0
- package/dist/auth/zod.js +18 -17
- package/dist/auth/zod.js.map +1 -1
- package/dist/command.cjs +326 -0
- package/dist/command.cjs.map +1 -0
- package/dist/command.d.cts +289 -0
- package/dist/command.d.ts +265 -171
- package/dist/command.js +321 -226
- package/dist/command.js.map +1 -1
- package/dist/constants.d.cts +5 -0
- package/dist/constants.d.ts +5 -1
- package/dist/index.cjs +11 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +6 -15
- package/dist/network-policy.d.cts +100 -0
- package/dist/network-policy.d.ts +32 -28
- package/dist/sandbox.cjs +543 -0
- package/dist/sandbox.cjs.map +1 -0
- package/dist/sandbox.d.cts +538 -0
- package/dist/sandbox.d.ts +521 -472
- package/dist/sandbox.js +539 -506
- package/dist/sandbox.js.map +1 -1
- package/dist/snapshot.cjs +116 -0
- package/dist/snapshot.cjs.map +1 -0
- package/dist/snapshot.d.cts +109 -0
- package/dist/snapshot.d.ts +100 -92
- package/dist/snapshot.js +114 -114
- package/dist/snapshot.js.map +1 -1
- package/dist/utils/array.cjs +17 -0
- package/dist/utils/array.cjs.map +1 -0
- package/dist/utils/array.js +12 -15
- package/dist/utils/array.js.map +1 -1
- package/dist/utils/consume-readable.cjs +18 -0
- package/dist/utils/consume-readable.cjs.map +1 -0
- package/dist/utils/consume-readable.js +13 -12
- package/dist/utils/consume-readable.js.map +1 -1
- package/dist/utils/decode-base64-url.cjs +15 -0
- package/dist/utils/decode-base64-url.cjs.map +1 -0
- package/dist/utils/decode-base64-url.js +10 -9
- package/dist/utils/decode-base64-url.js.map +1 -1
- package/dist/utils/dev-credentials.cjs +142 -0
- package/dist/utils/dev-credentials.cjs.map +1 -0
- package/dist/utils/dev-credentials.js +126 -184
- package/dist/utils/dev-credentials.js.map +1 -1
- package/dist/utils/get-credentials.cjs +123 -0
- package/dist/utils/get-credentials.cjs.map +1 -0
- package/dist/utils/get-credentials.d.cts +21 -0
- package/dist/utils/get-credentials.d.ts +19 -61
- package/dist/utils/get-credentials.js +106 -140
- package/dist/utils/get-credentials.js.map +1 -1
- package/dist/utils/log.cjs +25 -0
- package/dist/utils/log.cjs.map +1 -0
- package/dist/utils/log.js +15 -17
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/network-policy.cjs +65 -0
- package/dist/utils/network-policy.cjs.map +1 -0
- package/dist/utils/network-policy.js +58 -77
- package/dist/utils/network-policy.js.map +1 -1
- package/dist/utils/normalizePath.cjs +27 -0
- package/dist/utils/normalizePath.cjs.map +1 -0
- package/dist/utils/normalizePath.js +21 -28
- package/dist/utils/normalizePath.js.map +1 -1
- package/dist/utils/resolveSignal.cjs +20 -0
- package/dist/utils/resolveSignal.cjs.map +1 -0
- package/dist/utils/resolveSignal.d.cts +15 -0
- package/dist/utils/resolveSignal.d.ts +12 -10
- package/dist/utils/resolveSignal.js +14 -17
- package/dist/utils/resolveSignal.js.map +1 -1
- package/dist/utils/sandbox-snapshot.cjs +14 -0
- package/dist/utils/sandbox-snapshot.cjs.map +1 -0
- package/dist/utils/sandbox-snapshot.d.cts +10 -0
- package/dist/utils/sandbox-snapshot.d.ts +11 -0
- package/dist/utils/sandbox-snapshot.js +14 -0
- package/dist/utils/sandbox-snapshot.js.map +1 -0
- package/dist/utils/types.cjs +13 -0
- package/dist/utils/types.cjs.map +1 -0
- package/dist/utils/types.d.cts +11 -0
- package/dist/utils/types.d.ts +5 -7
- package/dist/utils/types.js +8 -8
- package/dist/utils/types.js.map +1 -1
- package/dist/version.cjs +7 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.js +5 -5
- package/dist/version.js.map +1 -1
- package/package.json +23 -3
- package/dist/api-client/index.js.map +0 -1
- package/dist/auth/api.d.ts +0 -6
- package/dist/auth/error.d.ts +0 -11
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/linked-project.d.ts +0 -10
- package/dist/auth/zod.d.ts +0 -5
- package/dist/constants.js +0 -3
- package/dist/constants.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/network-policy.js +0 -3
- package/dist/network-policy.js.map +0 -1
- package/dist/utils/array.d.ts +0 -9
- package/dist/utils/consume-readable.d.ts +0 -5
- package/dist/utils/convert-sandbox.d.ts +0 -6
- package/dist/utils/convert-sandbox.js +0 -14
- package/dist/utils/convert-sandbox.js.map +0 -1
- package/dist/utils/decode-base64-url.d.ts +0 -7
- package/dist/utils/dev-credentials.d.ts +0 -37
- package/dist/utils/log.d.ts +0 -2
- package/dist/utils/network-policy.d.ts +0 -7
- package/dist/utils/normalizePath.d.ts +0 -17
- package/dist/version.d.ts +0 -1
|
@@ -1,157 +1,127 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
allowedCIDRs: zod_1.z.array(zod_1.z.string()).optional(),
|
|
20
|
-
deniedCIDRs: zod_1.z.array(zod_1.z.string()).optional(),
|
|
21
|
-
injectionRules: zod_1.z.array(exports.InjectionRuleValidator).optional(),
|
|
22
|
-
})
|
|
23
|
-
.passthrough(),
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/api-client/validators.ts
|
|
4
|
+
const InjectionRuleValidator = z.object({
|
|
5
|
+
domain: z.string(),
|
|
6
|
+
headers: z.record(z.string()).optional(),
|
|
7
|
+
headerNames: z.array(z.string()).optional()
|
|
8
|
+
});
|
|
9
|
+
const NetworkPolicyValidator = z.union([
|
|
10
|
+
z.object({ mode: z.literal("allow-all") }).passthrough(),
|
|
11
|
+
z.object({ mode: z.literal("deny-all") }).passthrough(),
|
|
12
|
+
z.object({
|
|
13
|
+
mode: z.literal("custom"),
|
|
14
|
+
allowedDomains: z.array(z.string()).optional(),
|
|
15
|
+
allowedCIDRs: z.array(z.string()).optional(),
|
|
16
|
+
deniedCIDRs: z.array(z.string()).optional(),
|
|
17
|
+
injectionRules: z.array(InjectionRuleValidator).optional()
|
|
18
|
+
}).passthrough()
|
|
24
19
|
]);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
exports.CommandFinishedResponse = zod_1.z.object({
|
|
114
|
-
command: CommandFinished,
|
|
115
|
-
});
|
|
116
|
-
exports.EmptyResponse = zod_1.z.object({});
|
|
117
|
-
const LogLineBase = zod_1.z.object({ data: zod_1.z.string() });
|
|
118
|
-
exports.LogLineStdout = LogLineBase.extend({
|
|
119
|
-
stream: zod_1.z.literal("stdout"),
|
|
120
|
-
});
|
|
121
|
-
exports.LogLineStderr = LogLineBase.extend({
|
|
122
|
-
stream: zod_1.z.literal("stderr"),
|
|
123
|
-
});
|
|
124
|
-
exports.LogError = zod_1.z.object({
|
|
125
|
-
stream: zod_1.z.literal("error"),
|
|
126
|
-
data: zod_1.z.object({
|
|
127
|
-
code: zod_1.z.string(),
|
|
128
|
-
message: zod_1.z.string(),
|
|
129
|
-
}),
|
|
130
|
-
});
|
|
131
|
-
exports.LogLine = zod_1.z.discriminatedUnion("stream", [
|
|
132
|
-
exports.LogLineStdout,
|
|
133
|
-
exports.LogLineStderr,
|
|
134
|
-
exports.LogError,
|
|
20
|
+
const Sandbox = z.object({
|
|
21
|
+
id: z.string(),
|
|
22
|
+
memory: z.number(),
|
|
23
|
+
vcpus: z.number(),
|
|
24
|
+
region: z.string(),
|
|
25
|
+
runtime: z.string(),
|
|
26
|
+
timeout: z.number(),
|
|
27
|
+
status: z.enum([
|
|
28
|
+
"pending",
|
|
29
|
+
"running",
|
|
30
|
+
"stopping",
|
|
31
|
+
"stopped",
|
|
32
|
+
"failed",
|
|
33
|
+
"aborted",
|
|
34
|
+
"snapshotting"
|
|
35
|
+
]),
|
|
36
|
+
requestedAt: z.number(),
|
|
37
|
+
startedAt: z.number().optional(),
|
|
38
|
+
requestedStopAt: z.number().optional(),
|
|
39
|
+
stoppedAt: z.number().optional(),
|
|
40
|
+
abortedAt: z.number().optional(),
|
|
41
|
+
duration: z.number().optional(),
|
|
42
|
+
sourceSnapshotId: z.string().optional(),
|
|
43
|
+
snapshottedAt: z.number().optional(),
|
|
44
|
+
createdAt: z.number(),
|
|
45
|
+
cwd: z.string(),
|
|
46
|
+
updatedAt: z.number(),
|
|
47
|
+
interactivePort: z.number().optional(),
|
|
48
|
+
networkPolicy: NetworkPolicyValidator.optional(),
|
|
49
|
+
activeCpuDurationMs: z.number().optional(),
|
|
50
|
+
networkTransfer: z.object({
|
|
51
|
+
ingress: z.number(),
|
|
52
|
+
egress: z.number()
|
|
53
|
+
}).optional()
|
|
54
|
+
});
|
|
55
|
+
const SandboxRoute = z.object({
|
|
56
|
+
url: z.string(),
|
|
57
|
+
subdomain: z.string(),
|
|
58
|
+
port: z.number()
|
|
59
|
+
});
|
|
60
|
+
const Snapshot = z.object({
|
|
61
|
+
id: z.string(),
|
|
62
|
+
sourceSandboxId: z.string(),
|
|
63
|
+
region: z.string(),
|
|
64
|
+
status: z.enum([
|
|
65
|
+
"created",
|
|
66
|
+
"deleted",
|
|
67
|
+
"failed"
|
|
68
|
+
]),
|
|
69
|
+
sizeBytes: z.number(),
|
|
70
|
+
expiresAt: z.number().optional(),
|
|
71
|
+
createdAt: z.number(),
|
|
72
|
+
updatedAt: z.number()
|
|
73
|
+
});
|
|
74
|
+
const Pagination = z.object({
|
|
75
|
+
count: z.number(),
|
|
76
|
+
next: z.number().nullable(),
|
|
77
|
+
prev: z.number().nullable()
|
|
78
|
+
});
|
|
79
|
+
const Command = z.object({
|
|
80
|
+
id: z.string(),
|
|
81
|
+
name: z.string(),
|
|
82
|
+
args: z.array(z.string()),
|
|
83
|
+
cwd: z.string(),
|
|
84
|
+
sandboxId: z.string(),
|
|
85
|
+
exitCode: z.number().nullable(),
|
|
86
|
+
startedAt: z.number()
|
|
87
|
+
});
|
|
88
|
+
const CommandFinished = Command.extend({ exitCode: z.number() });
|
|
89
|
+
const SandboxResponse = z.object({ sandbox: Sandbox });
|
|
90
|
+
const SandboxAndRoutesResponse = SandboxResponse.extend({ routes: z.array(SandboxRoute) });
|
|
91
|
+
const CommandResponse = z.object({ command: Command });
|
|
92
|
+
const CommandFinishedResponse = z.object({ command: CommandFinished });
|
|
93
|
+
const EmptyResponse = z.object({});
|
|
94
|
+
const LogLineBase = z.object({ data: z.string() });
|
|
95
|
+
const LogLineStdout = LogLineBase.extend({ stream: z.literal("stdout") });
|
|
96
|
+
const LogLineStderr = LogLineBase.extend({ stream: z.literal("stderr") });
|
|
97
|
+
const LogError = z.object({
|
|
98
|
+
stream: z.literal("error"),
|
|
99
|
+
data: z.object({
|
|
100
|
+
code: z.string(),
|
|
101
|
+
message: z.string()
|
|
102
|
+
})
|
|
103
|
+
});
|
|
104
|
+
const LogLine = z.discriminatedUnion("stream", [
|
|
105
|
+
LogLineStdout,
|
|
106
|
+
LogLineStderr,
|
|
107
|
+
LogError
|
|
135
108
|
]);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
exports.SnapshotResponse = zod_1.z.object({
|
|
155
|
-
snapshot: exports.Snapshot,
|
|
156
|
-
});
|
|
109
|
+
const SandboxesResponse = z.object({
|
|
110
|
+
sandboxes: z.array(Sandbox),
|
|
111
|
+
pagination: Pagination
|
|
112
|
+
});
|
|
113
|
+
const SnapshotsResponse = z.object({
|
|
114
|
+
snapshots: z.array(Snapshot),
|
|
115
|
+
pagination: Pagination
|
|
116
|
+
});
|
|
117
|
+
const ExtendTimeoutResponse = z.object({ sandbox: Sandbox });
|
|
118
|
+
const UpdateNetworkPolicyResponse = z.object({ sandbox: Sandbox });
|
|
119
|
+
const CreateSnapshotResponse = z.object({
|
|
120
|
+
snapshot: Snapshot,
|
|
121
|
+
sandbox: Sandbox
|
|
122
|
+
});
|
|
123
|
+
const SnapshotResponse = z.object({ snapshot: Snapshot });
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
export { Command, CommandFinishedResponse, CommandResponse, CreateSnapshotResponse, EmptyResponse, ExtendTimeoutResponse, InjectionRuleValidator, LogError, LogLine, LogLineStderr, LogLineStdout, NetworkPolicyValidator, Pagination, Sandbox, SandboxAndRoutesResponse, SandboxResponse, SandboxRoute, SandboxesResponse, Snapshot, SnapshotResponse, SnapshotsResponse, UpdateNetworkPolicyResponse };
|
|
157
127
|
//# sourceMappingURL=validators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","
|
|
1
|
+
{"version":3,"file":"validators.js","names":[],"sources":["../../src/api-client/validators.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport type SandboxMetaData = z.infer<typeof Sandbox>;\n\nexport const InjectionRuleValidator = z.object({\n domain: z.string(),\n // headers are only sent in requests\n headers: z.record(z.string()).optional(),\n // headerNames are returned in responses\n headerNames: z.array(z.string()).optional(),\n});\n\nexport const NetworkPolicyValidator = z.union([\n z.object({ mode: z.literal(\"allow-all\") }).passthrough(),\n z.object({ mode: z.literal(\"deny-all\") }).passthrough(),\n z\n .object({\n mode: z.literal(\"custom\"),\n allowedDomains: z.array(z.string()).optional(),\n allowedCIDRs: z.array(z.string()).optional(),\n deniedCIDRs: z.array(z.string()).optional(),\n injectionRules: z.array(InjectionRuleValidator).optional(),\n })\n .passthrough(),\n]);\n\nexport const Sandbox = z.object({\n id: z.string(),\n memory: z.number(),\n vcpus: z.number(),\n region: z.string(),\n runtime: z.string(),\n timeout: z.number(),\n status: z.enum([\n \"pending\",\n \"running\",\n \"stopping\",\n \"stopped\",\n \"failed\",\n \"aborted\",\n \"snapshotting\",\n ]),\n requestedAt: z.number(),\n startedAt: z.number().optional(),\n requestedStopAt: z.number().optional(),\n stoppedAt: z.number().optional(),\n abortedAt: z.number().optional(),\n duration: z.number().optional(),\n sourceSnapshotId: z.string().optional(),\n snapshottedAt: z.number().optional(),\n createdAt: z.number(),\n cwd: z.string(),\n updatedAt: z.number(),\n interactivePort: z.number().optional(),\n networkPolicy: NetworkPolicyValidator.optional(),\n activeCpuDurationMs: z.number().optional(),\n networkTransfer: z.object({\n ingress: z.number(),\n egress: z.number(),\n }).optional(),\n});\n\nexport type SandboxRouteData = z.infer<typeof SandboxRoute>;\n\nexport const SandboxRoute = z.object({\n url: z.string(),\n subdomain: z.string(),\n port: z.number(),\n});\n\nexport type SnapshotMetadata = z.infer<typeof Snapshot>;\n\nexport const Snapshot = z.object({\n id: z.string(),\n sourceSandboxId: z.string(),\n region: z.string(),\n status: z.enum([\"created\", \"deleted\", \"failed\"]),\n sizeBytes: z.number(),\n expiresAt: z.number().optional(),\n createdAt: z.number(),\n updatedAt: z.number(),\n});\n\nexport const Pagination = z.object({\n /**\n * Amount of items in the current page.\n * @example 20\n */\n count: z.number(),\n /**\n * Timestamp that must be used to request the next page.\n * @example 1540095775951\n */\n next: z.number().nullable(),\n /**\n * Timestamp that must be used to request the previous page.\n * @example 1540095775951\n */\n prev: z.number().nullable(),\n});\n\nexport type CommandData = z.infer<typeof Command>;\n\nexport const Command = z.object({\n id: z.string(),\n name: z.string(),\n args: z.array(z.string()),\n cwd: z.string(),\n sandboxId: z.string(),\n exitCode: z.number().nullable(),\n startedAt: z.number(),\n});\n\nconst CommandFinished = Command.extend({\n exitCode: z.number(),\n});\n\nexport const SandboxResponse = z.object({\n sandbox: Sandbox,\n});\n\nexport const SandboxAndRoutesResponse = SandboxResponse.extend({\n routes: z.array(SandboxRoute),\n});\n\nexport const CommandResponse = z.object({\n command: Command,\n});\n\nexport type CommandFinishedData = z.infer<typeof CommandFinishedResponse>[\"command\"];\n\nexport const CommandFinishedResponse = z.object({\n command: CommandFinished,\n});\n\nexport const EmptyResponse = z.object({});\n\nconst LogLineBase = z.object({ data: z.string() });\nexport const LogLineStdout = LogLineBase.extend({\n stream: z.literal(\"stdout\"),\n});\nexport const LogLineStderr = LogLineBase.extend({\n stream: z.literal(\"stderr\"),\n});\n\nexport const LogError = z.object({\n stream: z.literal(\"error\"),\n data: z.object({\n code: z.string(),\n message: z.string(),\n }),\n});\n\nexport const LogLine = z.discriminatedUnion(\"stream\", [\n LogLineStdout,\n LogLineStderr,\n LogError,\n]);\n\nexport const SandboxesResponse = z.object({\n sandboxes: z.array(Sandbox),\n pagination: Pagination,\n});\n\nexport const SnapshotsResponse = z.object({\n snapshots: z.array(Snapshot),\n pagination: Pagination,\n});\n\nexport const ExtendTimeoutResponse = z.object({\n sandbox: Sandbox,\n});\n\nexport const UpdateNetworkPolicyResponse = z.object({\n sandbox: Sandbox,\n});\n\nexport const CreateSnapshotResponse = z.object({\n snapshot: Snapshot,\n sandbox: Sandbox,\n});\n\nexport const SnapshotResponse = z.object({\n snapshot: Snapshot,\n});\n"],"mappings":";;;AAIA,MAAa,yBAAyB,EAAE,OAAO;CAC7C,QAAQ,EAAE,QAAQ;CAElB,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,UAAU;CAExC,aAAa,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;CAC5C,CAAC;AAEF,MAAa,yBAAyB,EAAE,MAAM;CAC5C,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,YAAY,EAAE,CAAC,CAAC,aAAa;CACxD,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,WAAW,EAAE,CAAC,CAAC,aAAa;CACvD,EACG,OAAO;EACN,MAAM,EAAE,QAAQ,SAAS;EACzB,gBAAgB,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;EAC9C,cAAc,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;EAC5C,aAAa,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;EAC3C,gBAAgB,EAAE,MAAM,uBAAuB,CAAC,UAAU;EAC3D,CAAC,CACD,aAAa;CACjB,CAAC;AAEF,MAAa,UAAU,EAAE,OAAO;CAC9B,IAAI,EAAE,QAAQ;CACd,QAAQ,EAAE,QAAQ;CAClB,OAAO,EAAE,QAAQ;CACjB,QAAQ,EAAE,QAAQ;CAClB,SAAS,EAAE,QAAQ;CACnB,SAAS,EAAE,QAAQ;CACnB,QAAQ,EAAE,KAAK;EACb;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC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E,OAAO,EAClD,SAAS,SACV,CAAC;AAEF,MAAa,yBAAyB,EAAE,OAAO;CAC7C,UAAU;CACV,SAAS;CACV,CAAC;AAEF,MAAa,mBAAmB,EAAE,OAAO,EACvC,UAAU,UACX,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_api_error = require('./api-error.cjs');
|
|
3
|
+
let node_timers_promises = require("node:timers/promises");
|
|
4
|
+
let async_retry = require("async-retry");
|
|
5
|
+
async_retry = require_rolldown_runtime.__toESM(async_retry);
|
|
6
|
+
|
|
7
|
+
//#region src/api-client/with-retry.ts
|
|
8
|
+
/**
|
|
9
|
+
* Wraps a fetch function with retry logic. The retry logic will retry
|
|
10
|
+
* on network errors, 429 responses and 5xx responses. The retry logic
|
|
11
|
+
* will not retry on 4xx responses.
|
|
12
|
+
*
|
|
13
|
+
* @param rawFetch The fetch function to wrap.
|
|
14
|
+
* @returns The wrapped fetch function.
|
|
15
|
+
*/
|
|
16
|
+
function withRetry(rawFetch) {
|
|
17
|
+
return async (url, opts = {}) => {
|
|
18
|
+
/**
|
|
19
|
+
* Timeouts by default will be [10, 60, 360, 2160, 12960]
|
|
20
|
+
* before randomization is added.
|
|
21
|
+
*/
|
|
22
|
+
const retryOpts = Object.assign({
|
|
23
|
+
minTimeout: 10,
|
|
24
|
+
retries: 5,
|
|
25
|
+
factor: 6,
|
|
26
|
+
maxRetryAfter: 20
|
|
27
|
+
}, opts.retry);
|
|
28
|
+
if (opts.onRetry) retryOpts.onRetry = (error, attempts) => {
|
|
29
|
+
opts.onRetry(error, opts);
|
|
30
|
+
if (opts.retry && opts.retry.onRetry) opts.retry.onRetry(error, attempts);
|
|
31
|
+
};
|
|
32
|
+
try {
|
|
33
|
+
return await (0, async_retry.default)(async (bail) => {
|
|
34
|
+
try {
|
|
35
|
+
if (opts.signal?.aborted) return bail(opts.signal.reason || /* @__PURE__ */ new Error("Request aborted"));
|
|
36
|
+
const response = await rawFetch(url, opts);
|
|
37
|
+
/**
|
|
38
|
+
* When the response is 429 we will try to parse the Retry-After
|
|
39
|
+
* header. If the header exists we will try to parse it and, if
|
|
40
|
+
* the wait time is higher than the maximum defined, we respond.
|
|
41
|
+
* Otherwise we wait for the time given in the header and throw
|
|
42
|
+
* to retry.
|
|
43
|
+
*/
|
|
44
|
+
if (response.status === 429) {
|
|
45
|
+
const retryAfter = parseInt(response.headers.get("retry-after") || "", 10);
|
|
46
|
+
if (retryAfter && !isNaN(retryAfter)) {
|
|
47
|
+
if (retryAfter > retryOpts.maxRetryAfter) return response;
|
|
48
|
+
await (0, node_timers_promises.setTimeout)(retryAfter * 1e3);
|
|
49
|
+
}
|
|
50
|
+
throw new require_api_error.APIError(response);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* If the response is a a retryable error, we throw in
|
|
54
|
+
* order to retry.
|
|
55
|
+
*/
|
|
56
|
+
if (response.status >= 500 && response.status < 600) throw new require_api_error.APIError(response);
|
|
57
|
+
return response;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
/**
|
|
60
|
+
* If the request was aborted using the AbortController
|
|
61
|
+
* we bail from retrying throwing the original error.
|
|
62
|
+
*/
|
|
63
|
+
if (isAbortError(error)) return bail(error);
|
|
64
|
+
/**
|
|
65
|
+
* If the signal was aborted meanwhile we were
|
|
66
|
+
* waiting, we bail from retrying.
|
|
67
|
+
*/
|
|
68
|
+
if (opts.signal?.aborted) return bail(opts.signal.reason || /* @__PURE__ */ new Error("Request aborted"));
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}, retryOpts);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
/**
|
|
74
|
+
* The ResponseError is only intended for retries so in case we
|
|
75
|
+
* ran out of attempts we will respond with the last response
|
|
76
|
+
* we obtained.
|
|
77
|
+
*/
|
|
78
|
+
if (error instanceof require_api_error.APIError) return error.response;
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function isAbortError(error) {
|
|
84
|
+
return error !== void 0 && error !== null && error.name === "AbortError";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
exports.withRetry = withRetry;
|
|
89
|
+
//# sourceMappingURL=with-retry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-retry.cjs","names":["APIError"],"sources":["../../src/api-client/with-retry.ts"],"sourcesContent":["import type { Options as RetryOptions } from \"async-retry\";\nimport { APIError } from \"./api-error.js\";\nimport { setTimeout } from \"node:timers/promises\";\nimport retry from \"async-retry\";\n\nexport interface RequestOptions {\n onRetry?(error: any, options: RequestOptions): void;\n retry?: Partial<RetryOptions>;\n}\n\n/**\n * Wraps a fetch function with retry logic. The retry logic will retry\n * on network errors, 429 responses and 5xx responses. The retry logic\n * will not retry on 4xx responses.\n *\n * @param rawFetch The fetch function to wrap.\n * @returns The wrapped fetch function.\n */\nexport function withRetry<T extends RequestInit>(\n rawFetch: (url: URL | string, init?: T) => Promise<Response>,\n) {\n return async (\n url: URL | string,\n opts: T & RequestOptions = <T & RequestOptions>{},\n ) => {\n /**\n * Timeouts by default will be [10, 60, 360, 2160, 12960]\n * before randomization is added.\n */\n const retryOpts = Object.assign(\n {\n minTimeout: 10,\n retries: 5,\n factor: 6,\n maxRetryAfter: 20,\n },\n opts.retry,\n );\n\n if (opts.onRetry) {\n retryOpts.onRetry = (error, attempts) => {\n opts.onRetry!(error, opts);\n if (opts.retry && opts.retry.onRetry) {\n opts.retry.onRetry(error, attempts);\n }\n };\n }\n\n try {\n return (await retry(async (bail) => {\n try {\n if (opts.signal?.aborted) {\n return bail(opts.signal.reason || new Error(\"Request aborted\"));\n }\n const response = await rawFetch(url, opts);\n\n /**\n * When the response is 429 we will try to parse the Retry-After\n * header. If the header exists we will try to parse it and, if\n * the wait time is higher than the maximum defined, we respond.\n * Otherwise we wait for the time given in the header and throw\n * to retry.\n */\n if (response.status === 429) {\n const retryAfter = parseInt(\n response.headers.get(\"retry-after\") || \"\",\n 10,\n );\n\n if (retryAfter && !isNaN(retryAfter)) {\n if (retryAfter > retryOpts.maxRetryAfter) {\n return response;\n }\n\n await setTimeout(retryAfter * 1e3);\n }\n\n throw new APIError(response);\n }\n\n /**\n * If the response is a a retryable error, we throw in\n * order to retry.\n */\n if (response.status >= 500 && response.status < 600) {\n throw new APIError(response);\n }\n\n return response;\n } catch (error) {\n /**\n * If the request was aborted using the AbortController\n * we bail from retrying throwing the original error.\n */\n if (isAbortError(error)) {\n return bail(error);\n }\n\n /**\n * If the signal was aborted meanwhile we were\n * waiting, we bail from retrying.\n */\n if (opts.signal?.aborted) {\n return bail(opts.signal.reason || new Error(\"Request aborted\"));\n }\n\n throw error;\n }\n }, retryOpts)) as Response;\n } catch (error) {\n /**\n * The ResponseError is only intended for retries so in case we\n * ran out of attempts we will respond with the last response\n * we obtained.\n */\n if (error instanceof APIError) {\n return error.response;\n }\n\n throw error;\n }\n };\n}\n\nfunction isAbortError(error: unknown): error is Error {\n return (\n error !== undefined &&\n error !== null &&\n (error as Error).name === \"AbortError\"\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,SAAgB,UACd,UACA;AACA,QAAO,OACL,KACA,OAA+C,EAAE,KAC9C;;;;;EAKH,MAAM,YAAY,OAAO,OACvB;GACE,YAAY;GACZ,SAAS;GACT,QAAQ;GACR,eAAe;GAChB,EACD,KAAK,MACN;AAED,MAAI,KAAK,QACP,WAAU,WAAW,OAAO,aAAa;AACvC,QAAK,QAAS,OAAO,KAAK;AAC1B,OAAI,KAAK,SAAS,KAAK,MAAM,QAC3B,MAAK,MAAM,QAAQ,OAAO,SAAS;;AAKzC,MAAI;AACF,UAAQ,+BAAY,OAAO,SAAS;AAClC,QAAI;AACF,SAAI,KAAK,QAAQ,QACf,QAAO,KAAK,KAAK,OAAO,0BAAU,IAAI,MAAM,kBAAkB,CAAC;KAEjE,MAAM,WAAW,MAAM,SAAS,KAAK,KAAK;;;;;;;;AAS1C,SAAI,SAAS,WAAW,KAAK;MAC3B,MAAM,aAAa,SACjB,SAAS,QAAQ,IAAI,cAAc,IAAI,IACvC,GACD;AAED,UAAI,cAAc,CAAC,MAAM,WAAW,EAAE;AACpC,WAAI,aAAa,UAAU,cACzB,QAAO;AAGT,kDAAiB,aAAa,IAAI;;AAGpC,YAAM,IAAIA,2BAAS,SAAS;;;;;;AAO9B,SAAI,SAAS,UAAU,OAAO,SAAS,SAAS,IAC9C,OAAM,IAAIA,2BAAS,SAAS;AAG9B,YAAO;aACA,OAAO;;;;;AAKd,SAAI,aAAa,MAAM,CACrB,QAAO,KAAK,MAAM;;;;;AAOpB,SAAI,KAAK,QAAQ,QACf,QAAO,KAAK,KAAK,OAAO,0BAAU,IAAI,MAAM,kBAAkB,CAAC;AAGjE,WAAM;;MAEP,UAAU;WACN,OAAO;;;;;;AAMd,OAAI,iBAAiBA,2BACnB,QAAO,MAAM;AAGf,SAAM;;;;AAKZ,SAAS,aAAa,OAAgC;AACpD,QACE,UAAU,UACV,UAAU,QACT,MAAgB,SAAS"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Options } from "async-retry";
|
|
2
|
+
|
|
3
|
+
//#region src/api-client/with-retry.d.ts
|
|
4
|
+
interface RequestOptions {
|
|
5
|
+
onRetry?(error: any, options: RequestOptions): void;
|
|
6
|
+
retry?: Partial<Options>;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { RequestOptions };
|
|
10
|
+
//# sourceMappingURL=with-retry.d.cts.map
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Options } from "async-retry";
|
|
2
|
+
|
|
3
|
+
//#region src/api-client/with-retry.d.ts
|
|
4
|
+
interface RequestOptions {
|
|
5
|
+
onRetry?(error: any, options: RequestOptions): void;
|
|
6
|
+
retry?: Partial<Options>;
|
|
5
7
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* will not retry on 4xx responses.
|
|
10
|
-
*
|
|
11
|
-
* @param rawFetch The fetch function to wrap.
|
|
12
|
-
* @returns The wrapped fetch function.
|
|
13
|
-
*/
|
|
14
|
-
export declare function withRetry<T extends RequestInit>(rawFetch: (url: URL | string, init?: T) => Promise<Response>): (url: URL | string, opts?: T & RequestOptions) => Promise<Response>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { RequestOptions };
|
|
10
|
+
//# sourceMappingURL=with-retry.d.ts.map
|