@sandbox-kit/daytona 0.1.1 → 0.1.2

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.
@@ -1,275 +0,0 @@
1
- // Code generated by protoc-gen-kit-typescript. DO NOT EDIT.
2
- // source: kit/providers/daytona/v1/provider.proto + specs/providers/daytona.yaml
3
- import { durationMs } from "@bufbuild/protobuf/wkt";
4
- import { ErrorKind, PolicyMode, ValueOrigin, sandboxError } from "@sandbox-kit/sandbox";
5
- export function mapLifetimePolicies(source, operation = "create") {
6
- const target = {};
7
- if (source === undefined)
8
- return target;
9
- if (source.idleStop !== undefined) {
10
- const policy = source.idleStop;
11
- const mode = policy.mode ?? PolicyMode.Default;
12
- if (mode === PolicyMode.Disabled) {
13
- target.autoStopInterval = 0;
14
- }
15
- else if (mode === PolicyMode.After) {
16
- if (policy.after === undefined)
17
- mappingError(ErrorKind.InvalidArgument, "lifetime.idle_stop", "duration is required", operation);
18
- const afterMs = durationMs(policy.after);
19
- if (afterMs === 0)
20
- mappingError(ErrorKind.Unsupported, "lifetime.idle_stop", "immediate action is not representable", operation);
21
- if (!Number.isFinite(afterMs) || afterMs < 0 || afterMs % 60_000 !== 0)
22
- mappingError(ErrorKind.InvalidArgument, "lifetime.idle_stop", "delay cannot be represented in whole minutes", operation);
23
- const minutes = afterMs / 60_000;
24
- target.autoStopInterval = minutes;
25
- }
26
- else if (mode !== PolicyMode.Default) {
27
- mappingError(ErrorKind.InvalidArgument, "lifetime.idle_stop", "unknown policy mode", operation);
28
- }
29
- }
30
- if (source.idlePause !== undefined) {
31
- const policy = source.idlePause;
32
- const mode = policy.mode ?? PolicyMode.Default;
33
- if (mode === PolicyMode.Disabled) {
34
- target.autoPauseInterval = 0;
35
- }
36
- else if (mode === PolicyMode.After) {
37
- if (policy.after === undefined)
38
- mappingError(ErrorKind.InvalidArgument, "lifetime.idle_pause", "duration is required", operation);
39
- const afterMs = durationMs(policy.after);
40
- if (afterMs === 0)
41
- mappingError(ErrorKind.Unsupported, "lifetime.idle_pause", "immediate action is not representable", operation);
42
- if (!Number.isFinite(afterMs) || afterMs < 0 || afterMs % 60_000 !== 0)
43
- mappingError(ErrorKind.InvalidArgument, "lifetime.idle_pause", "delay cannot be represented in whole minutes", operation);
44
- const minutes = afterMs / 60_000;
45
- target.autoPauseInterval = minutes;
46
- }
47
- else if (mode !== PolicyMode.Default) {
48
- mappingError(ErrorKind.InvalidArgument, "lifetime.idle_pause", "unknown policy mode", operation);
49
- }
50
- }
51
- if (source.stoppedArchive !== undefined) {
52
- const policy = source.stoppedArchive;
53
- const mode = policy.mode ?? PolicyMode.Default;
54
- if (mode === PolicyMode.Disabled) {
55
- mappingError(ErrorKind.Unsupported, "lifetime.stopped_archive", "explicit disabling is not representable", operation);
56
- }
57
- else if (mode === PolicyMode.After) {
58
- if (policy.after === undefined)
59
- mappingError(ErrorKind.InvalidArgument, "lifetime.stopped_archive", "duration is required", operation);
60
- const afterMs = durationMs(policy.after);
61
- if (afterMs === 0)
62
- mappingError(ErrorKind.Unsupported, "lifetime.stopped_archive", "immediate action is not representable", operation);
63
- if (!Number.isFinite(afterMs) || afterMs < 0 || afterMs % 60_000 !== 0)
64
- mappingError(ErrorKind.InvalidArgument, "lifetime.stopped_archive", "delay cannot be represented in whole minutes", operation);
65
- const minutes = afterMs / 60_000;
66
- if (minutes > 43200)
67
- mappingError(ErrorKind.InvalidArgument, "lifetime.stopped_archive", "delay exceeds documented maximum", operation);
68
- target.autoArchiveInterval = minutes;
69
- }
70
- else if (mode !== PolicyMode.Default) {
71
- mappingError(ErrorKind.InvalidArgument, "lifetime.stopped_archive", "unknown policy mode", operation);
72
- }
73
- }
74
- if (source.stoppedDelete !== undefined) {
75
- const policy = source.stoppedDelete;
76
- const mode = policy.mode ?? PolicyMode.Default;
77
- if (mode === PolicyMode.Disabled) {
78
- mappingError(ErrorKind.Unsupported, "lifetime.stopped_delete", "explicit disabling is not representable", operation);
79
- }
80
- else if (mode === PolicyMode.After) {
81
- if (policy.after === undefined)
82
- mappingError(ErrorKind.InvalidArgument, "lifetime.stopped_delete", "duration is required", operation);
83
- const afterMs = durationMs(policy.after);
84
- if (!Number.isFinite(afterMs) || afterMs < 0 || afterMs % 60_000 !== 0)
85
- mappingError(ErrorKind.InvalidArgument, "lifetime.stopped_delete", "delay cannot be represented in whole minutes", operation);
86
- const minutes = afterMs / 60_000;
87
- target.autoDeleteInterval = minutes;
88
- }
89
- else if (mode !== PolicyMode.Default) {
90
- mappingError(ErrorKind.InvalidArgument, "lifetime.stopped_delete", "unknown policy mode", operation);
91
- }
92
- }
93
- return target;
94
- }
95
- export function mapCommonCreateFields(source, operation = "create") {
96
- const target = {};
97
- if (source === undefined)
98
- return target;
99
- {
100
- if (source.name !== undefined) {
101
- const value = source.name;
102
- target.name = value;
103
- }
104
- }
105
- {
106
- if (source.environment !== undefined) {
107
- const value = source.environment;
108
- target.envVars = { ...value };
109
- }
110
- }
111
- {
112
- if (source.labels !== undefined) {
113
- const value = source.labels;
114
- target.labels = { ...value };
115
- }
116
- }
117
- return target;
118
- }
119
- export function mapResources(source, operation = "create") {
120
- const target = {};
121
- if (source === undefined)
122
- return target;
123
- {
124
- if (source.cpuCores !== undefined) {
125
- const value = source.cpuCores;
126
- if (!Number.isInteger(value) || value > 2147483647)
127
- mappingError(ErrorKind.InvalidArgument, "resources.cpu_cores", "cpu_cores cannot be represented", operation);
128
- target.cpu = Number(value);
129
- }
130
- }
131
- {
132
- if (source.memoryMib !== undefined) {
133
- const value = source.memoryMib;
134
- if (value % 1024n !== 0n || value / 1024n > 2147483647n)
135
- mappingError(ErrorKind.InvalidArgument, "resources.memory_mib", "memory_mib cannot be represented", operation);
136
- target.memory = Number(value / 1024n);
137
- }
138
- }
139
- {
140
- if (source.diskMib !== undefined) {
141
- const value = source.diskMib;
142
- if (value % 1024n !== 0n || value / 1024n > 2147483647n)
143
- mappingError(ErrorKind.InvalidArgument, "resources.disk_mib", "disk_mib cannot be represented", operation);
144
- target.disk = Number(value / 1024n);
145
- }
146
- }
147
- return target;
148
- }
149
- export function mapSandboxInfo(source, operation = "create") {
150
- const target = {};
151
- if (source === undefined)
152
- return target;
153
- const origins = {};
154
- target.origins = origins;
155
- {
156
- if (source.id !== undefined) {
157
- const value = source.id;
158
- target.id = value;
159
- origins["id"] = ValueOrigin.Provider;
160
- }
161
- }
162
- {
163
- if (source.name !== undefined) {
164
- const value = source.name;
165
- target.name = value;
166
- origins["name"] = ValueOrigin.Provider;
167
- }
168
- }
169
- {
170
- if (source.state !== undefined) {
171
- const value = source.state;
172
- target.providerState = String(value);
173
- origins["provider_state"] = ValueOrigin.Provider;
174
- }
175
- }
176
- {
177
- if (source.target !== undefined) {
178
- const value = source.target;
179
- target.region = value;
180
- origins["region"] = ValueOrigin.Provider;
181
- }
182
- }
183
- {
184
- if (source.labels !== undefined) {
185
- const value = source.labels;
186
- target.labels = { ...value };
187
- origins["labels"] = ValueOrigin.Provider;
188
- }
189
- }
190
- target.provider = "daytona";
191
- return target;
192
- }
193
- export function mapAllocatedResources(source, operation = "create") {
194
- const target = {};
195
- if (source === undefined)
196
- return target;
197
- if (!((source.cpu ?? 0) > 0 && (source.memory ?? 0) > 0 && (source.disk ?? 0) > 0))
198
- return target;
199
- {
200
- if (source.cpu !== undefined) {
201
- const value = source.cpu;
202
- target.cpuCores = Number(value);
203
- }
204
- }
205
- {
206
- if (source.memory !== undefined) {
207
- const value = source.memory;
208
- if (!Number.isSafeInteger(value) || value < 0)
209
- mappingError(ErrorKind.InvalidResponse, "memory", "memory cannot be represented", operation);
210
- target.memoryMib = BigInt(value) * 1024n;
211
- }
212
- }
213
- {
214
- if (source.disk !== undefined) {
215
- const value = source.disk;
216
- if (!Number.isSafeInteger(value) || value < 0)
217
- mappingError(ErrorKind.InvalidResponse, "disk", "disk cannot be represented", operation);
218
- target.diskMib = BigInt(value) * 1024n;
219
- }
220
- }
221
- return target;
222
- }
223
- export function mapClientSettings(source, operation = "initialize") {
224
- const target = {};
225
- if (source === undefined)
226
- return target;
227
- {
228
- if (source.endpoint !== undefined) {
229
- const value = source.endpoint;
230
- target.apiUrl = value;
231
- }
232
- }
233
- {
234
- if (source.region !== undefined) {
235
- const value = source.region;
236
- target.target = value;
237
- }
238
- }
239
- return target;
240
- }
241
- export function mapAPIKeyCredentials(source, operation = "initialize") {
242
- const target = {};
243
- if (source === undefined)
244
- return target;
245
- {
246
- const value = source.key;
247
- target.apiKey = value;
248
- }
249
- return target;
250
- }
251
- export function mapBearerAuth(source, operation = "initialize") {
252
- const target = {};
253
- if (source === undefined)
254
- return target;
255
- {
256
- const value = source.token;
257
- target.jwtToken = value;
258
- }
259
- return target;
260
- }
261
- export function mapScope(source, operation = "initialize") {
262
- const target = {};
263
- if (source === undefined)
264
- return target;
265
- {
266
- if (source.organizationId !== undefined) {
267
- const value = source.organizationId;
268
- target.organizationId = value;
269
- }
270
- }
271
- return target;
272
- }
273
- function mappingError(kind, field, message, operation) {
274
- throw sandboxError({ kind, provider: "daytona", operation, field, message: "sandbox-kit daytona: " + message });
275
- }
@@ -1,3 +0,0 @@
1
- import type { CreateOptions } from "@sandbox-kit/sandbox";
2
- export declare function validateProviderCreate(request: CreateOptions): void;
3
- //# sourceMappingURL=provider_checks.d.ts.map
@@ -1,137 +0,0 @@
1
- import { ErrorKind, PolicyMode, sandboxError } from "@sandbox-kit/sandbox";
2
- // validateProviderCreate rejects creation settings this provider cannot honor.
3
- // Rules are inventoried in specs/providers/daytona.yaml checks.
4
- export function validateProviderCreate(request) {
5
- const language = request.runtime?.language;
6
- if (language !== undefined &&
7
- language !== "python" &&
8
- language !== "javascript" &&
9
- language !== "typescript") {
10
- fail(ErrorKind.Unsupported, "runtime.language", "runtime.language is outside supported values");
11
- }
12
- const outboundProxyUrl = request.network?.outboundProxyUrl;
13
- if (outboundProxyUrl !== undefined && !validHttpUrl(outboundProxyUrl)) {
14
- fail(ErrorKind.InvalidArgument, "network.outboundProxyUrl", "network.outbound_proxy_url is outside supported values");
15
- }
16
- for (const value of request.network?.outboundCidrs ?? []) {
17
- if (!validCidr(value)) {
18
- fail(ErrorKind.InvalidArgument, "network.outboundCidrs.entries", "network.outbound_cidrs.entries is outside supported values");
19
- }
20
- }
21
- for (const value of request.network?.outboundDomains ?? []) {
22
- if (!validDomain(value)) {
23
- fail(ErrorKind.InvalidArgument, "network.outboundDomains.entries", "network.outbound_domains.entries is outside supported values");
24
- }
25
- }
26
- for (const item of request.security?.secrets ?? []) {
27
- const environmentVariable = item.environmentVariable;
28
- if (environmentVariable !== undefined &&
29
- !validEnvName(environmentVariable)) {
30
- fail(ErrorKind.InvalidArgument, "security.secrets.environmentVariable", "security.secrets.environment_variable is outside supported values");
31
- }
32
- }
33
- if (delayed(request.lifetime?.idleStop) &&
34
- delayed(request.lifetime?.idlePause)) {
35
- invalid("lifetime", "incompatible lifetime policies");
36
- }
37
- if (delayed(request.lifetime?.idlePause) &&
38
- request.lifetime?.ephemeral === true) {
39
- invalid("lifetime", "incompatible lifetime policies");
40
- }
41
- if (delayed(request.lifetime?.idlePause) &&
42
- immediate(request.lifetime?.stoppedDelete)) {
43
- invalid("lifetime", "incompatible lifetime policies");
44
- }
45
- if (delayed(request.lifetime?.stoppedDelete) &&
46
- request.lifetime?.ephemeral === true) {
47
- invalid("lifetime", "incompatible lifetime policies");
48
- }
49
- if (delayed(request.lifetime?.stoppedArchive) &&
50
- request.lifetime?.ephemeral === true) {
51
- invalid("lifetime", "incompatible lifetime policies");
52
- }
53
- }
54
- function delayed(policy) {
55
- return ((policy?.mode ?? PolicyMode.Default) === PolicyMode.After &&
56
- policy?.after !== undefined &&
57
- policy.after > 0);
58
- }
59
- function immediate(policy) {
60
- return ((policy?.mode ?? PolicyMode.Default) === PolicyMode.After &&
61
- policy?.after !== undefined &&
62
- policy.after === 0);
63
- }
64
- function validEnvName(value) {
65
- return /^[A-Za-z_][A-Za-z0-9_]*$/.test(value);
66
- }
67
- function validHttpUrl(value) {
68
- try {
69
- const parsed = new URL(value);
70
- return (parsed.hostname !== "" &&
71
- (parsed.protocol === "http:" || parsed.protocol === "https:"));
72
- }
73
- catch {
74
- return false;
75
- }
76
- }
77
- function validDomain(value) {
78
- const domain = value.startsWith("*.") ? value.slice(2) : value;
79
- return (domain.length <= 253 &&
80
- /^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.?$/i.test(domain));
81
- }
82
- function validCidr(value) {
83
- const separator = value.lastIndexOf("/");
84
- if (separator <= 0)
85
- return false;
86
- const address = value.slice(0, separator);
87
- const prefix = Number(value.slice(separator + 1));
88
- if (!Number.isInteger(prefix))
89
- return false;
90
- return address.includes(":")
91
- ? prefix >= 0 && prefix <= 128 && validIpv6(address)
92
- : prefix >= 0 && prefix <= 32 && validIpv4(address);
93
- }
94
- function validIpv4(value) {
95
- const parts = value.split(".");
96
- return (parts.length === 4 &&
97
- parts.every((part) => /^(0|[1-9][0-9]{0,2})$/.test(part) && Number(part) <= 255));
98
- }
99
- function validIpv6(value) {
100
- if ((value.match(/::/g)?.length ?? 0) > 1)
101
- return false;
102
- const halves = value.split("::");
103
- if (halves.length > 2)
104
- return false;
105
- const count = (part) => {
106
- if (part === "")
107
- return 0;
108
- const groups = part.split(":");
109
- let total = 0;
110
- for (const group of groups) {
111
- if (/^[0-9a-f]{1,4}$/i.test(group))
112
- total++;
113
- else if (validIpv4(group))
114
- total += 2;
115
- else
116
- return undefined;
117
- }
118
- return total;
119
- };
120
- const left = count(halves[0] ?? "");
121
- const right = count(halves[1] ?? "");
122
- return (left !== undefined &&
123
- right !== undefined &&
124
- (halves.length === 2 ? left + right < 8 : left === 8));
125
- }
126
- function invalid(field, message) {
127
- fail(ErrorKind.InvalidArgument, field, message);
128
- }
129
- function fail(kind, field, message) {
130
- throw sandboxError({
131
- kind,
132
- provider: "daytona",
133
- operation: "create",
134
- field,
135
- message: "sandbox-kit daytona: " + message,
136
- });
137
- }
@@ -1,5 +0,0 @@
1
- import type { DaytonaConfig as NativeClientConfig } from "@daytona/sdk";
2
- import { type Config } from "@sandbox-kit/sandbox";
3
- export type Environment = Readonly<Record<string, string | undefined>>;
4
- export declare function mapGeneratedClientConfig(config: Config, environment?: Environment): NativeClientConfig;
5
- //# sourceMappingURL=provider_config.d.ts.map
@@ -1,49 +0,0 @@
1
- // Client configuration composition for the native SDK constructor.
2
- // Kept in sync with specs/providers/daytona.yaml client: rules (not emitted).
3
- import { ErrorKind, sandboxError, validateConfig, } from "@sandbox-kit/sandbox";
4
- import { mapAPIKeyCredentials, mapBearerAuth, mapClientSettings, mapScope, } from "./provider_mappings.js";
5
- export function mapGeneratedClientConfig(config, environment = environmentVariables()) {
6
- let source = config;
7
- if (source.endpoint === undefined)
8
- source = {
9
- ...source,
10
- endpoint: environment.DAYTONA_API_URL ??
11
- environment.DAYTONA_SERVER_URL ??
12
- "https://app.daytona.io/api",
13
- };
14
- validateConfig(source, "daytona", "initialize");
15
- const target = mapClientSettings(source, "initialize");
16
- if (source.scope !== undefined) {
17
- const mapped = mapScope(source.scope, "initialize");
18
- Object.assign(target, mapped);
19
- if (source.scope.appName !== undefined)
20
- unsupported("scope.appName", "unsupported client configuration field");
21
- if (source.scope.environment !== undefined)
22
- unsupported("scope.environment", "unsupported client configuration field");
23
- if (source.scope.projectId !== undefined)
24
- unsupported("scope.projectId", "unsupported client configuration field");
25
- }
26
- if (source.auth?.apiKey !== undefined) {
27
- Object.assign(target, mapAPIKeyCredentials(source.auth.apiKey, "initialize"));
28
- }
29
- else if (source.auth?.bearerToken !== undefined) {
30
- Object.assign(target, mapBearerAuth(source.auth.bearerToken, "initialize"));
31
- }
32
- else if (source.auth !== undefined) {
33
- unsupported("auth", "unsupported authentication mode");
34
- }
35
- return target;
36
- }
37
- function environmentVariables() {
38
- return (globalThis
39
- .process?.env ?? {});
40
- }
41
- function unsupported(field, message) {
42
- throw sandboxError({
43
- kind: ErrorKind.Unsupported,
44
- provider: "daytona",
45
- operation: "initialize",
46
- field,
47
- message: "sandbox-kit daytona: " + message,
48
- });
49
- }
@@ -1,15 +0,0 @@
1
- import { type SandboxInfo, type Scope } from "@sandbox-kit/sandbox";
2
- import type { APIKeyCredentials, BearerTokenCredentials, Config, CreateOptions, Resources } from "@sandbox-kit/sandbox";
3
- import type { CreateSandboxBaseParams as NativeCreateSandboxBaseParams, DaytonaConfig as NativeDaytonaConfig, Resources as NativeResources, Sandbox as NativeSandbox } from "@daytona/sdk";
4
- type PublicLifetime = NonNullable<CreateOptions["lifetime"]>;
5
- export declare function mapLifetimePolicies(source: PublicLifetime | undefined, operation?: string): NativeCreateSandboxBaseParams;
6
- export declare function mapCommonCreateFields(source: CreateOptions | undefined, operation?: string): NativeCreateSandboxBaseParams;
7
- export declare function mapResources(source: Resources | undefined, operation?: string): NativeResources;
8
- export declare function mapSandboxInfo(source: NativeSandbox | undefined, operation?: string): Partial<SandboxInfo>;
9
- export declare function mapAllocatedResources(source: NativeSandbox | undefined, operation?: string): Partial<Resources>;
10
- export declare function mapClientSettings(source: Config | undefined, operation?: string): NativeDaytonaConfig;
11
- export declare function mapAPIKeyCredentials(source: APIKeyCredentials | undefined, operation?: string): NativeDaytonaConfig;
12
- export declare function mapBearerAuth(source: BearerTokenCredentials | undefined, operation?: string): NativeDaytonaConfig;
13
- export declare function mapScope(source: Scope | undefined, operation?: string): NativeDaytonaConfig;
14
- export {};
15
- //# sourceMappingURL=provider_mappings.d.ts.map