@sandbox-kit/modal 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,101 @@
1
+ // Code generated by protoc-gen-kit-typescript. DO NOT EDIT.
2
+ // source: kit/providers/modal/v1/provider.proto + specs/providers/modal.yaml
3
+ import { durationMs } from "@bufbuild/protobuf/wkt";
4
+ import { ErrorKind, PolicyMode, sandboxError } from "@sandbox-kit/sandbox";
5
+ export function validateProviderCreate(request) {
6
+ const value0_0 = request.resources;
7
+ if (value0_0 !== undefined) {
8
+ const value0 = value0_0.cpuCores;
9
+ if (value0 !== undefined) {
10
+ if (value0 < 0.125)
11
+ fail(ErrorKind.InvalidArgument, "resources.cpuCores", "resources.cpu_cores is outside supported values");
12
+ }
13
+ }
14
+ const value1_0 = request.resources;
15
+ if (value1_0 !== undefined) {
16
+ const value1 = value1_0.memoryMib;
17
+ if (value1 !== undefined) {
18
+ if (value1 < BigInt("128"))
19
+ fail(ErrorKind.InvalidArgument, "resources.memoryMib", "resources.memory_mib is outside supported values");
20
+ }
21
+ }
22
+ const value2_0 = request.runtime;
23
+ if (value2_0 !== undefined) {
24
+ const value2 = value2_0.workingDirectory;
25
+ if (value2 !== undefined) {
26
+ if (!validAbsolutePath(value2))
27
+ fail(ErrorKind.InvalidArgument, "runtime.workingDirectory", "runtime.working_directory is outside supported values");
28
+ }
29
+ }
30
+ const value3_0 = request.placement;
31
+ if (value3_0 !== undefined) {
32
+ const value3 = value3_0.cloud;
33
+ if (value3 !== undefined) {
34
+ if (value3 !== "aws" && value3 !== "gcp" && value3 !== "oci" && value3 !== "auto")
35
+ fail(ErrorKind.Unsupported, "placement.cloud", "placement.cloud is outside supported values");
36
+ }
37
+ }
38
+ const value4_0 = request.network;
39
+ if (value4_0 !== undefined) {
40
+ const value4_1 = value4_0.outboundCidrs;
41
+ if (value4_1 !== undefined) {
42
+ for (const value4 of value4_1.entries ?? []) {
43
+ if (value4 !== "" && !validCidr(value4))
44
+ fail(ErrorKind.InvalidArgument, "network.outboundCidrs.entries", "network.outbound_cidrs.entries is outside supported values");
45
+ }
46
+ }
47
+ }
48
+ const value5_0 = request.network;
49
+ if (value5_0 !== undefined) {
50
+ const value5_1 = value5_0.inboundCidrs;
51
+ if (value5_1 !== undefined) {
52
+ for (const value5 of value5_1.entries ?? []) {
53
+ if (!validCidr(value5))
54
+ fail(ErrorKind.InvalidArgument, "network.inboundCidrs.entries", "network.inbound_cidrs.entries is outside supported values");
55
+ }
56
+ }
57
+ }
58
+ const value6_0 = request.network;
59
+ if (value6_0 !== undefined) {
60
+ const value6_1 = value6_0.outboundDomains;
61
+ if (value6_1 !== undefined) {
62
+ for (const value6 of value6_1.entries ?? []) {
63
+ if (value6 !== "" && !validDomain(value6))
64
+ fail(ErrorKind.InvalidArgument, "network.outboundDomains.entries", "network.outbound_domains.entries is outside supported values");
65
+ }
66
+ }
67
+ }
68
+ for (const value7 of Object.keys(request.environment ?? {})) {
69
+ if (!validEnvName(value7))
70
+ fail(ErrorKind.InvalidArgument, "environment", "environment is outside supported values");
71
+ }
72
+ }
73
+ function delayed(policy) { return (policy?.mode ?? PolicyMode.Default) === PolicyMode.After && policy?.after !== undefined && durationMs(policy.after) > 0; }
74
+ function immediate(policy) { return (policy?.mode ?? PolicyMode.Default) === PolicyMode.After && policy?.after !== undefined && durationMs(policy.after) === 0; }
75
+ function validEnvName(value) { return /^[A-Za-z_][A-Za-z0-9_]*$/.test(value); }
76
+ function validAbsolutePath(value) { return value.startsWith("/"); }
77
+ function validHttpUrl(value) { try {
78
+ const parsed = new URL(value);
79
+ return parsed.hostname !== "" && (parsed.protocol === "http:" || parsed.protocol === "https:");
80
+ }
81
+ catch {
82
+ return false;
83
+ } }
84
+ function validDomain(value) { const domain = value.startsWith("*.") ? value.slice(2) : value; return domain.length <= 253 && /^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.?$/i.test(domain); }
85
+ function validCidr(value) { const separator = value.lastIndexOf("/"); if (separator <= 0)
86
+ return false; const address = value.slice(0, separator); const prefix = Number(value.slice(separator + 1)); if (!Number.isInteger(prefix))
87
+ return false; return address.includes(":") ? prefix >= 0 && prefix <= 128 && validIpv6(address) : prefix >= 0 && prefix <= 32 && validIpv4(address); }
88
+ function validIpv4(value) { const parts = value.split("."); return parts.length === 4 && parts.every((part) => /^(0|[1-9][0-9]{0,2})$/.test(part) && Number(part) <= 255); }
89
+ function validIpv6(value) { if ((value.match(/::/g)?.length ?? 0) > 1)
90
+ return false; const halves = value.split("::"); if (halves.length > 2)
91
+ return false; const count = (part) => { if (part === "")
92
+ return 0; const groups = part.split(":"); let total = 0; for (const group of groups) {
93
+ if (/^[0-9a-f]{1,4}$/i.test(group))
94
+ total++;
95
+ else if (validIpv4(group))
96
+ total += 2;
97
+ else
98
+ return undefined;
99
+ } return total; }; const left = count(halves[0] ?? ""); const right = count(halves[1] ?? ""); return left !== undefined && right !== undefined && (halves.length === 2 ? left + right < 8 : left === 8); }
100
+ function invalid(field, message) { fail(ErrorKind.InvalidArgument, field, message); }
101
+ function fail(kind, field, message) { throw sandboxError({ kind, provider: "modal", operation: "create", field, message: "sandbox-kit modal: " + message }); }
@@ -0,0 +1,9 @@
1
+ import type { ModalClientParams as NativeClientConfig } from "modal";
2
+ import { type ConfigWire, type ConfigWire, type Scope } from "@sandbox-kit/sandbox";
3
+ export declare function mapGeneratedClientConfig(config: ConfigWire): NativeClientConfig;
4
+ export interface ProviderState {
5
+ readonly scope?: ConfigWire["scope"] | Scope;
6
+ readonly region?: string;
7
+ }
8
+ export declare function captureProviderState(config: ConfigWire | ConfigWire): ProviderState;
9
+ //# sourceMappingURL=provider.config.gen.d.ts.map
@@ -0,0 +1,40 @@
1
+ // Code generated by protoc-gen-kit-typescript. DO NOT EDIT.
2
+ // source: kit/providers/modal/v1/provider.proto + specs/providers/modal.yaml
3
+ import { ErrorKind, materializeClientConfig, sandboxError, validateConfig, } from "@sandbox-kit/sandbox";
4
+ import { mapClientScope, mapOAuthAuth, mapTokenPairCredentials } from "./provider.mappings.gen.js";
5
+ export function mapGeneratedClientConfig(config) {
6
+ let source = config;
7
+ validateConfig(source, "modal", "initialize");
8
+ const target = {};
9
+ if (source.endpoint !== undefined)
10
+ unsupported("endpoint", "Endpoint cannot be configured through this SDK's public client constructor");
11
+ if (source.scope !== undefined) {
12
+ const mapped = mapClientScope(source.scope, "initialize");
13
+ Object.assign(target, mapped);
14
+ if (source.scope.organizationId !== undefined)
15
+ unsupported("scope.organizationId", "unsupported client configuration field");
16
+ if (source.scope.projectId !== undefined)
17
+ unsupported("scope.projectId", "unsupported client configuration field");
18
+ }
19
+ const credentials = source.auth?.credentials;
20
+ if (credentials?.case === "tokenPair") {
21
+ const mapped = mapTokenPairCredentials(credentials.value, "initialize");
22
+ Object.assign(target, mapped);
23
+ }
24
+ else if (credentials?.case === "oauthRefresh") {
25
+ const mapped = mapOAuthAuth(credentials.value, "initialize");
26
+ Object.assign(target, mapped);
27
+ }
28
+ else if (credentials?.case !== undefined) {
29
+ unsupported("auth", "unsupported authentication mode");
30
+ }
31
+ return target;
32
+ }
33
+ export function captureProviderState(config) {
34
+ const source = materializeClientConfig(config);
35
+ return {
36
+ ...(source.scope === undefined ? {} : { scope: structuredClone(source.scope) }),
37
+ ...(source.region === undefined ? {} : { region: source.region }),
38
+ };
39
+ }
40
+ function unsupported(field, message) { throw sandboxError({ kind: ErrorKind.Unsupported, provider: "modal", operation: "initialize", field, message: "sandbox-kit modal: " + message }); }
@@ -0,0 +1,13 @@
1
+ import type { Backend, Config, CreateOptions, CreateResult, OperationOptions, Provider } from "@sandbox-kit/sandbox";
2
+ export declare const providerName: "modal";
3
+ /** @internal Shared provider identity wiring. */
4
+ export declare abstract class ProviderBase implements Provider {
5
+ readonly name: "modal";
6
+ abstract initialize(config: Config): Backend;
7
+ }
8
+ /** @internal Shared backend identity and required create/close surface. */
9
+ export declare abstract class BackendBase implements Backend {
10
+ readonly name: "modal";
11
+ abstract create(request: CreateOptions, options: OperationOptions): Promise<CreateResult>;
12
+ abstract close(options: OperationOptions): Promise<void>;
13
+ }
@@ -0,0 +1,3 @@
1
+ import { SandboxError } from "@sandbox-kit/sandbox";
2
+ export declare function mapModalError(error: unknown, operation: string): SandboxError;
3
+ //# sourceMappingURL=provider.errors.gen.d.ts.map
@@ -0,0 +1,36 @@
1
+ // Code generated by protoc-gen-kit-typescript. DO NOT EDIT.
2
+ // source: kit/providers/modal/v1/provider.proto + specs/providers/modal.yaml
3
+ import { AlreadyExistsError, ClientClosedError, ConflictError, InvalidError, NotFoundError, ResourceExhaustedError, SandboxTimeoutError, TimeoutError } from "modal";
4
+ import { ErrorKind, SandboxError, sandboxError } from "@sandbox-kit/sandbox";
5
+ export function mapModalError(error, operation) {
6
+ if (error instanceof SandboxError)
7
+ return error;
8
+ if (error instanceof DOMException && error.name === "AbortError")
9
+ return create(ErrorKind.Canceled, error, operation);
10
+ if (error instanceof DOMException && error.name === "TimeoutError")
11
+ return create(ErrorKind.Timeout, error, operation);
12
+ let kind = ErrorKind.Unknown;
13
+ if (kind === ErrorKind.Unknown && error instanceof InvalidError)
14
+ kind = ErrorKind.InvalidArgument;
15
+ if (kind === ErrorKind.Unknown && error instanceof NotFoundError)
16
+ kind = ErrorKind.NotFound;
17
+ if (kind === ErrorKind.Unknown && error instanceof AlreadyExistsError)
18
+ kind = ErrorKind.AlreadyExists;
19
+ if (kind === ErrorKind.Unknown && error instanceof ConflictError)
20
+ kind = ErrorKind.Conflict;
21
+ if (kind === ErrorKind.Unknown && error instanceof ResourceExhaustedError)
22
+ kind = ErrorKind.ResourceExhausted;
23
+ if (kind === ErrorKind.Unknown && error instanceof TimeoutError)
24
+ kind = ErrorKind.Timeout;
25
+ if (kind === ErrorKind.Unknown && error instanceof SandboxTimeoutError)
26
+ kind = ErrorKind.Timeout;
27
+ if (kind === ErrorKind.Unknown && error instanceof ClientClosedError)
28
+ kind = ErrorKind.FailedPrecondition;
29
+ let statusCode;
30
+ let providerCode;
31
+ let providerSource;
32
+ return create(kind, error, operation, statusCode, providerCode, providerSource);
33
+ }
34
+ function create(kind, error, operation, statusCode, providerCode, providerSource) {
35
+ return sandboxError({ kind, provider: "modal", operation, field: "", message: error instanceof Error ? error.message : "sandbox-kit modal: provider operation failed", ...(statusCode === undefined ? {} : { statusCode }), ...(providerCode === undefined ? {} : { providerCode }), ...(providerSource === undefined ? {} : { providerSource }) }, error);
36
+ }
@@ -0,0 +1,14 @@
1
+ import type { Backend, ConfigWire, CreateOptionsWire, CreateResult, OperationOptions, Provider } from "@sandbox-kit/sandbox";
2
+ export declare const providerName: "modal";
3
+ /** @internal Shared generated provider identity wiring. */
4
+ export declare abstract class ProviderBase implements Provider {
5
+ readonly name: "modal";
6
+ abstract initialize(config: ConfigWire): Backend;
7
+ }
8
+ /** @internal Shared generated backend identity and required operation surface. */
9
+ export declare abstract class BackendBase implements Backend {
10
+ readonly name: "modal";
11
+ abstract create(request: CreateOptionsWire, options: OperationOptions): Promise<CreateResult>;
12
+ abstract close(options: OperationOptions): Promise<void>;
13
+ }
14
+ //# sourceMappingURL=provider.gen.d.ts.map
@@ -0,0 +1,11 @@
1
+ // Code generated by protoc-gen-kit-typescript. DO NOT EDIT.
2
+ // source: kit/providers/modal/v1/provider.proto + specs/providers/modal.yaml
3
+ export const providerName = "modal";
4
+ /** @internal Shared generated provider identity wiring. */
5
+ export class ProviderBase {
6
+ name = providerName;
7
+ }
8
+ /** @internal Shared generated backend identity and required operation surface. */
9
+ export class BackendBase {
10
+ name = providerName;
11
+ }
@@ -0,0 +1,10 @@
1
+ // Modal provider construction and native SDK orchestration are handwritten.
2
+ export const providerName = "modal";
3
+ /** @internal Shared provider identity wiring. */
4
+ export class ProviderBase {
5
+ name = providerName;
6
+ }
7
+ /** @internal Shared backend identity and required create/close surface. */
8
+ export class BackendBase {
9
+ name = providerName;
10
+ }
@@ -0,0 +1,11 @@
1
+ import { type AutomaticAction, type CreateOptionsWire, type LifetimePolicy, type OAuthCredentials, type Resources, type SandboxInfo, type Scope, type TokenPairCredentials } from "@sandbox-kit/sandbox";
2
+ import type { ModalClientParams as NativeModalClientParams, Sandbox as NativeSandbox, SandboxCreateParams as NativeSandboxCreateParams } from "modal";
3
+ export declare function mapSandboxIdentity(source: NativeSandbox | undefined, operation?: string): Partial<SandboxInfo>;
4
+ export declare function mapClientScope(source: Scope | undefined, operation?: string): NativeModalClientParams;
5
+ export declare function mapCommonCreateFields(source: CreateOptionsWire | undefined, operation?: string): NativeSandboxCreateParams;
6
+ export declare function mapResources(source: Resources | undefined, operation?: string): NativeSandboxCreateParams;
7
+ export declare function mapLifetimeDuration(source: LifetimePolicy | undefined, operation?: string): NativeSandboxCreateParams;
8
+ export declare function mapIdleDuration(source: AutomaticAction | undefined, operation?: string): NativeSandboxCreateParams;
9
+ export declare function mapTokenPairCredentials(source: TokenPairCredentials | undefined, operation?: string): NativeModalClientParams;
10
+ export declare function mapOAuthAuth(source: OAuthCredentials | undefined, operation?: string): NativeModalClientParams;
11
+ //# sourceMappingURL=provider.mappings.gen.d.ts.map
@@ -0,0 +1,161 @@
1
+ // Code generated by protoc-gen-kit-typescript. DO NOT EDIT.
2
+ // source: kit/providers/modal/v1/provider.proto + specs/providers/modal.yaml
3
+ import { durationMs } from "@bufbuild/protobuf/wkt";
4
+ import { ErrorKind, PolicyMode, ValueOrigin, sandboxError } from "@sandbox-kit/sandbox";
5
+ export function mapSandboxIdentity(source, operation = "create") {
6
+ const target = {};
7
+ if (source === undefined)
8
+ return target;
9
+ const origins = {};
10
+ target.origins = origins;
11
+ {
12
+ if (source.sandboxId !== undefined) {
13
+ const value = source.sandboxId;
14
+ target.id = value;
15
+ origins["id"] = ValueOrigin.Provider;
16
+ }
17
+ }
18
+ target.provider = "modal";
19
+ return target;
20
+ }
21
+ export function mapClientScope(source, operation = "initialize") {
22
+ const target = {};
23
+ if (source === undefined)
24
+ return target;
25
+ {
26
+ if (source.environment !== undefined) {
27
+ const value = source.environment;
28
+ target.environment = value;
29
+ }
30
+ }
31
+ return target;
32
+ }
33
+ export function mapCommonCreateFields(source, operation = "create") {
34
+ const target = {};
35
+ if (source === undefined)
36
+ return target;
37
+ {
38
+ if (source.name !== undefined) {
39
+ const value = source.name;
40
+ target.name = value;
41
+ }
42
+ }
43
+ {
44
+ if (source.environment !== undefined) {
45
+ const value = source.environment;
46
+ target.env = { ...value };
47
+ }
48
+ }
49
+ {
50
+ if (source.labels !== undefined) {
51
+ const value = source.labels;
52
+ target.tags = { ...value };
53
+ }
54
+ }
55
+ return target;
56
+ }
57
+ export function mapResources(source, operation = "create") {
58
+ const target = {};
59
+ if (source === undefined)
60
+ return target;
61
+ {
62
+ if (source.cpuCores !== undefined) {
63
+ const value = source.cpuCores;
64
+ target.cpu = value;
65
+ }
66
+ }
67
+ {
68
+ if (source.cpuLimitCores !== undefined) {
69
+ const value = source.cpuLimitCores;
70
+ target.cpuLimit = value;
71
+ }
72
+ }
73
+ {
74
+ if (source.memoryMib !== undefined) {
75
+ const value = source.memoryMib;
76
+ if (value > 2147483647n)
77
+ mappingError(ErrorKind.InvalidArgument, "resources.memory_mib", "memory_mib cannot be represented", operation);
78
+ target.memoryMiB = Number(value);
79
+ }
80
+ }
81
+ {
82
+ if (source.memoryLimitMib !== undefined) {
83
+ const value = source.memoryLimitMib;
84
+ if (value > 2147483647n)
85
+ mappingError(ErrorKind.InvalidArgument, "resources.memory_limit_mib", "memory_limit_mib cannot be represented", operation);
86
+ target.memoryLimitMiB = Number(value);
87
+ }
88
+ }
89
+ return target;
90
+ }
91
+ export function mapLifetimeDuration(source, operation = "create") {
92
+ const target = {};
93
+ if (source === undefined)
94
+ return target;
95
+ {
96
+ if (source.maximumLifetime !== undefined) {
97
+ const value = durationMs(source.maximumLifetime);
98
+ if (value > 86400000)
99
+ mappingError(ErrorKind.InvalidArgument, "lifetime.maximum_lifetime", "maximum_lifetime cannot be represented", operation);
100
+ target.timeoutMs = value;
101
+ }
102
+ }
103
+ return target;
104
+ }
105
+ export function mapIdleDuration(source, operation = "create") {
106
+ const target = {};
107
+ if (source === undefined)
108
+ return target;
109
+ {
110
+ if (source.after !== undefined) {
111
+ const value = durationMs(source.after);
112
+ if (value > 4294967295000)
113
+ mappingError(ErrorKind.InvalidArgument, "lifetime.idle_terminate.after", "after cannot be represented", operation);
114
+ target.idleTimeoutMs = value;
115
+ }
116
+ }
117
+ return target;
118
+ }
119
+ export function mapTokenPairCredentials(source, operation = "initialize") {
120
+ const target = {};
121
+ if (source === undefined)
122
+ return target;
123
+ {
124
+ const value = source.id;
125
+ target.tokenId = value;
126
+ }
127
+ {
128
+ const value = source.secret;
129
+ target.tokenSecret = value;
130
+ }
131
+ return target;
132
+ }
133
+ export function mapOAuthAuth(source, operation = "create") {
134
+ const target = {};
135
+ if (source === undefined)
136
+ return target;
137
+ {
138
+ const value = source.refreshToken;
139
+ target.oauthRefreshToken = value;
140
+ }
141
+ {
142
+ const value = source.clientId;
143
+ target.oauthClientId = value;
144
+ }
145
+ {
146
+ if (source.clientSecret !== undefined) {
147
+ const value = source.clientSecret;
148
+ target.oauthClientSecret = value;
149
+ }
150
+ }
151
+ {
152
+ if (source.jwtKey !== undefined) {
153
+ const value = source.jwtKey;
154
+ target.oauthJwtKey = value;
155
+ }
156
+ }
157
+ return target;
158
+ }
159
+ function mappingError(kind, field, message, operation) {
160
+ throw sandboxError({ kind, provider: "modal", operation, field, message: "sandbox-kit modal: " + message });
161
+ }
@@ -0,0 +1,3 @@
1
+ import type { CreateOptions } from "@sandbox-kit/sandbox";
2
+ export declare function validateProviderCreate(request: CreateOptions): void;
3
+ //# sourceMappingURL=provider_checks.d.ts.map
@@ -0,0 +1,106 @@
1
+ import { ErrorKind, sandboxError } from "@sandbox-kit/sandbox";
2
+ // validateProviderCreate rejects creation settings this provider cannot honor.
3
+ // Rules are inventoried in specs/providers/modal.yaml checks.
4
+ export function validateProviderCreate(request) {
5
+ const cpuCores = request.resources?.cpuCores;
6
+ if (cpuCores !== undefined && cpuCores < 0.125) {
7
+ fail(ErrorKind.InvalidArgument, "resources.cpuCores", "resources.cpu_cores is outside supported values");
8
+ }
9
+ const memoryMib = request.resources?.memoryMib;
10
+ if (memoryMib !== undefined && memoryMib < BigInt("128")) {
11
+ fail(ErrorKind.InvalidArgument, "resources.memoryMib", "resources.memory_mib is outside supported values");
12
+ }
13
+ const workingDirectory = request.runtime?.workingDirectory;
14
+ if (workingDirectory !== undefined && !workingDirectory.startsWith("/")) {
15
+ fail(ErrorKind.InvalidArgument, "runtime.workingDirectory", "runtime.working_directory is outside supported values");
16
+ }
17
+ const cloud = request.placement?.cloud;
18
+ if (cloud !== undefined &&
19
+ cloud !== "aws" &&
20
+ cloud !== "gcp" &&
21
+ cloud !== "oci" &&
22
+ cloud !== "auto") {
23
+ fail(ErrorKind.Unsupported, "placement.cloud", "placement.cloud is outside supported values");
24
+ }
25
+ for (const value of request.network?.outboundCidrs ?? []) {
26
+ if (value !== "" && !validCidr(value)) {
27
+ fail(ErrorKind.InvalidArgument, "network.outboundCidrs.entries", "network.outbound_cidrs.entries is outside supported values");
28
+ }
29
+ }
30
+ for (const value of request.network?.inboundCidrs ?? []) {
31
+ if (!validCidr(value)) {
32
+ fail(ErrorKind.InvalidArgument, "network.inboundCidrs.entries", "network.inbound_cidrs.entries is outside supported values");
33
+ }
34
+ }
35
+ for (const value of request.network?.outboundDomains ?? []) {
36
+ if (value !== "" && !validDomain(value)) {
37
+ fail(ErrorKind.InvalidArgument, "network.outboundDomains.entries", "network.outbound_domains.entries is outside supported values");
38
+ }
39
+ }
40
+ for (const value of Object.keys(request.environment ?? {})) {
41
+ if (!validEnvName(value)) {
42
+ fail(ErrorKind.InvalidArgument, "environment", "environment is outside supported values");
43
+ }
44
+ }
45
+ }
46
+ function validEnvName(value) {
47
+ return /^[A-Za-z_][A-Za-z0-9_]*$/.test(value);
48
+ }
49
+ function validDomain(value) {
50
+ const domain = value.startsWith("*.") ? value.slice(2) : value;
51
+ return (domain.length <= 253 &&
52
+ /^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.?$/i.test(domain));
53
+ }
54
+ function validCidr(value) {
55
+ const separator = value.lastIndexOf("/");
56
+ if (separator <= 0)
57
+ return false;
58
+ const address = value.slice(0, separator);
59
+ const prefix = Number(value.slice(separator + 1));
60
+ if (!Number.isInteger(prefix))
61
+ return false;
62
+ return address.includes(":")
63
+ ? prefix >= 0 && prefix <= 128 && validIpv6(address)
64
+ : prefix >= 0 && prefix <= 32 && validIpv4(address);
65
+ }
66
+ function validIpv4(value) {
67
+ const parts = value.split(".");
68
+ return (parts.length === 4 &&
69
+ parts.every((part) => /^(0|[1-9][0-9]{0,2})$/.test(part) && Number(part) <= 255));
70
+ }
71
+ function validIpv6(value) {
72
+ if ((value.match(/::/g)?.length ?? 0) > 1)
73
+ return false;
74
+ const halves = value.split("::");
75
+ if (halves.length > 2)
76
+ return false;
77
+ const count = (part) => {
78
+ if (part === "")
79
+ return 0;
80
+ const groups = part.split(":");
81
+ let total = 0;
82
+ for (const group of groups) {
83
+ if (/^[0-9a-f]{1,4}$/i.test(group))
84
+ total++;
85
+ else if (validIpv4(group))
86
+ total += 2;
87
+ else
88
+ return undefined;
89
+ }
90
+ return total;
91
+ };
92
+ const left = count(halves[0] ?? "");
93
+ const right = count(halves[1] ?? "");
94
+ return (left !== undefined &&
95
+ right !== undefined &&
96
+ (halves.length === 2 ? left + right < 8 : left === 8));
97
+ }
98
+ function fail(kind, field, message) {
99
+ throw sandboxError({
100
+ kind,
101
+ provider: "modal",
102
+ operation: "create",
103
+ field,
104
+ message: "sandbox-kit modal: " + message,
105
+ });
106
+ }
@@ -0,0 +1,9 @@
1
+ import type { ModalClientParams as NativeClientConfig } from "modal";
2
+ import { type Config, type Scope } from "@sandbox-kit/sandbox";
3
+ export declare function mapGeneratedClientConfig(config: Config): NativeClientConfig;
4
+ export interface ProviderState {
5
+ readonly scope?: Scope;
6
+ readonly region?: string;
7
+ }
8
+ export declare function captureProviderState(config: Config): ProviderState;
9
+ //# sourceMappingURL=provider_config.d.ts.map
@@ -0,0 +1,46 @@
1
+ // Client configuration composition for the native SDK constructor.
2
+ // Kept in sync with specs/providers/modal.yaml client: rules (not emitted).
3
+ import { ErrorKind, sandboxError, validateConfig, } from "@sandbox-kit/sandbox";
4
+ import { mapClientScope, mapOAuthAuth, mapTokenPairCredentials, } from "./provider_mappings.js";
5
+ export function mapGeneratedClientConfig(config) {
6
+ const source = config;
7
+ validateConfig(source, "modal", "initialize");
8
+ const target = {};
9
+ if (source.endpoint !== undefined)
10
+ unsupported("endpoint", "Endpoint cannot be configured through this SDK's public client constructor");
11
+ if (source.scope !== undefined) {
12
+ const mapped = mapClientScope(source.scope, "initialize");
13
+ Object.assign(target, mapped);
14
+ if (source.scope.organizationId !== undefined)
15
+ unsupported("scope.organizationId", "unsupported client configuration field");
16
+ if (source.scope.projectId !== undefined)
17
+ unsupported("scope.projectId", "unsupported client configuration field");
18
+ }
19
+ if (source.auth?.tokenPair !== undefined) {
20
+ Object.assign(target, mapTokenPairCredentials(source.auth.tokenPair, "initialize"));
21
+ }
22
+ else if (source.auth?.oauthRefresh !== undefined) {
23
+ Object.assign(target, mapOAuthAuth(source.auth.oauthRefresh, "initialize"));
24
+ }
25
+ else if (source.auth !== undefined) {
26
+ unsupported("auth", "unsupported authentication mode");
27
+ }
28
+ return target;
29
+ }
30
+ export function captureProviderState(config) {
31
+ return {
32
+ ...(config.scope === undefined
33
+ ? {}
34
+ : { scope: structuredClone(config.scope) }),
35
+ ...(config.region === undefined ? {} : { region: config.region }),
36
+ };
37
+ }
38
+ function unsupported(field, message) {
39
+ throw sandboxError({
40
+ kind: ErrorKind.Unsupported,
41
+ provider: "modal",
42
+ operation: "initialize",
43
+ field,
44
+ message: "sandbox-kit modal: " + message,
45
+ });
46
+ }
@@ -0,0 +1,15 @@
1
+ import { type SandboxInfo, type Scope } from "@sandbox-kit/sandbox";
2
+ import type { CreateOptions, OAuthCredentials, Resources, TokenPairCredentials } from "@sandbox-kit/sandbox";
3
+ import type { ModalClientParams as NativeModalClientParams, Sandbox as NativeSandbox, SandboxCreateParams as NativeSandboxCreateParams } from "modal";
4
+ type PublicLifetime = NonNullable<CreateOptions["lifetime"]>;
5
+ type PublicIdleTerminate = NonNullable<PublicLifetime["idleTerminate"]>;
6
+ export declare function mapSandboxIdentity(source: NativeSandbox | undefined, operation?: string): Partial<SandboxInfo>;
7
+ export declare function mapClientScope(source: Scope | undefined, operation?: string): NativeModalClientParams;
8
+ export declare function mapCommonCreateFields(source: CreateOptions | undefined, operation?: string): NativeSandboxCreateParams;
9
+ export declare function mapResources(source: Resources | undefined, operation?: string): NativeSandboxCreateParams;
10
+ export declare function mapLifetimeDuration(source: PublicLifetime | undefined, operation?: string): NativeSandboxCreateParams;
11
+ export declare function mapIdleDuration(source: PublicIdleTerminate | undefined, operation?: string): NativeSandboxCreateParams;
12
+ export declare function mapTokenPairCredentials(source: TokenPairCredentials | undefined, operation?: string): NativeModalClientParams;
13
+ export declare function mapOAuthAuth(source: OAuthCredentials | undefined, operation?: string): NativeModalClientParams;
14
+ export {};
15
+ //# sourceMappingURL=provider_mappings.d.ts.map