@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,179 @@
1
+ // Provider field mappings between shared CreateOptions/Config and the native SDK.
2
+ // Inventoried in specs/providers/modal.yaml groups; kept in sync by hand (not emitted).
3
+ import { ErrorKind, ValueOrigin, sandboxError } from "@sandbox-kit/sandbox";
4
+ export function mapSandboxIdentity(source, operation = "create") {
5
+ const target = {};
6
+ if (source === undefined)
7
+ return target;
8
+ const origins = {};
9
+ target.origins = origins;
10
+ {
11
+ if (source.sandboxId !== undefined) {
12
+ const value = source.sandboxId;
13
+ target.id = value;
14
+ origins["id"] = ValueOrigin.Provider;
15
+ }
16
+ }
17
+ target.provider = "modal";
18
+ return target;
19
+ }
20
+ export function mapClientScope(source, operation = "initialize") {
21
+ const target = {};
22
+ if (source === undefined)
23
+ return target;
24
+ {
25
+ if (source.environment !== undefined) {
26
+ const value = source.environment;
27
+ target.environment = value;
28
+ }
29
+ }
30
+ return target;
31
+ }
32
+ export function mapCommonCreateFields(source, operation = "create") {
33
+ const target = {};
34
+ if (source === undefined)
35
+ return target;
36
+ {
37
+ if (source.name !== undefined) {
38
+ const value = source.name;
39
+ target.name = value;
40
+ }
41
+ }
42
+ {
43
+ if (source.environment !== undefined) {
44
+ const value = source.environment;
45
+ target.env = { ...value };
46
+ }
47
+ }
48
+ {
49
+ if (source.labels !== undefined) {
50
+ const value = source.labels;
51
+ target.tags = { ...value };
52
+ }
53
+ }
54
+ return target;
55
+ }
56
+ export function mapResources(source, operation = "create") {
57
+ const target = {};
58
+ if (source === undefined)
59
+ return target;
60
+ {
61
+ if (source.cpuCores !== undefined) {
62
+ target.cpu = scaledCpuCores(source.cpuCores, "resources.cpu_cores", operation);
63
+ }
64
+ }
65
+ {
66
+ if (source.cpuLimitCores !== undefined) {
67
+ target.cpuLimit = scaledCpuCores(source.cpuLimitCores, "resources.cpu_limit_cores", operation);
68
+ }
69
+ }
70
+ {
71
+ if (source.memoryMib !== undefined) {
72
+ const value = source.memoryMib;
73
+ if (value > 2147483647n)
74
+ mappingError(ErrorKind.InvalidArgument, "resources.memory_mib", "memory_mib cannot be represented", operation);
75
+ target.memoryMiB = Number(value);
76
+ }
77
+ }
78
+ {
79
+ if (source.memoryLimitMib !== undefined) {
80
+ const value = source.memoryLimitMib;
81
+ if (value > 2147483647n)
82
+ mappingError(ErrorKind.InvalidArgument, "resources.memory_limit_mib", "memory_limit_mib cannot be represented", operation);
83
+ target.memoryLimitMiB = Number(value);
84
+ }
85
+ }
86
+ return target;
87
+ }
88
+ export function mapLifetimeDuration(source, operation = "create") {
89
+ const target = {};
90
+ if (source === undefined)
91
+ return target;
92
+ {
93
+ if (source.maximumLifetime !== undefined) {
94
+ target.timeoutMs = durationSecondsMs(source.maximumLifetime, "lifetime.maximum_lifetime", 86_400, operation);
95
+ }
96
+ }
97
+ return target;
98
+ }
99
+ export function mapIdleDuration(source, operation = "create") {
100
+ const target = {};
101
+ if (source === undefined)
102
+ return target;
103
+ {
104
+ if (source.after !== undefined) {
105
+ target.idleTimeoutMs = durationSecondsMs(source.after, "lifetime.idle_terminate.after", 4_294_967_295, operation);
106
+ }
107
+ }
108
+ return target;
109
+ }
110
+ /** Modal CPU fields are millis-scaled: value must equal round(value*1000)/1000. */
111
+ function scaledCpuCores(value, field, operation) {
112
+ const scaled = Math.round(value * 1000);
113
+ if (!Number.isFinite(value) ||
114
+ value < 0 ||
115
+ value !== scaled / 1000 ||
116
+ scaled > 4_294_967_295) {
117
+ mappingError(ErrorKind.InvalidArgument, field, field.slice(field.lastIndexOf(".") + 1) + " cannot be represented", operation);
118
+ }
119
+ return value * 1000 < scaled ? scaled / 1000 : value;
120
+ }
121
+ /** Modal lifetime/idle timeouts are whole seconds expressed as milliseconds. */
122
+ function durationSecondsMs(value, field, maximumSeconds, operation) {
123
+ if (!Number.isFinite(value) ||
124
+ value <= 0 ||
125
+ value % 1000 !== 0 ||
126
+ value / 1000 > maximumSeconds) {
127
+ mappingError(ErrorKind.InvalidArgument, field, field.slice(field.lastIndexOf(".") + 1) + " cannot be represented", operation);
128
+ }
129
+ return value;
130
+ }
131
+ export function mapTokenPairCredentials(source, operation = "initialize") {
132
+ const target = {};
133
+ if (source === undefined)
134
+ return target;
135
+ {
136
+ const value = source.id;
137
+ target.tokenId = value;
138
+ }
139
+ {
140
+ const value = source.secret;
141
+ target.tokenSecret = value;
142
+ }
143
+ return target;
144
+ }
145
+ export function mapOAuthAuth(source, operation = "create") {
146
+ const target = {};
147
+ if (source === undefined)
148
+ return target;
149
+ {
150
+ const value = source.refreshToken;
151
+ target.oauthRefreshToken = value;
152
+ }
153
+ {
154
+ const value = source.clientId;
155
+ target.oauthClientId = value;
156
+ }
157
+ {
158
+ if (source.clientSecret !== undefined) {
159
+ const value = source.clientSecret;
160
+ target.oauthClientSecret = value;
161
+ }
162
+ }
163
+ {
164
+ if (source.jwtKey !== undefined) {
165
+ const value = source.jwtKey;
166
+ target.oauthJwtKey = value;
167
+ }
168
+ }
169
+ return target;
170
+ }
171
+ function mappingError(kind, field, message, operation) {
172
+ throw sandboxError({
173
+ kind,
174
+ provider: "modal",
175
+ operation,
176
+ field,
177
+ message: "sandbox-kit modal: " + message,
178
+ });
179
+ }
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@sandbox-kit/modal",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "modal provider for sandbox kit",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "packageManager": "npm@11.19.0",
8
+ "engines": {
9
+ "node": "^20.0.0 || ^22.0.0 || >=24.15.0"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/sandbox-kit/kit.git",
14
+ "directory": "sdks/typescript/providers/modal"
15
+ },
16
+ "homepage": "https://github.com/sandbox-kit/kit/tree/main/sdks/typescript/providers/modal",
17
+ "bugs": {
18
+ "url": "https://github.com/sandbox-kit/kit/issues"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
28
+ "main": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js"
34
+ }
35
+ },
36
+ "imports": {
37
+ "#mappings/*.js": {
38
+ "@sandbox-kit/source": "./src/mappings/*.ts",
39
+ "default": "./dist/mappings/*.js"
40
+ },
41
+ "#checks/*.js": {
42
+ "@sandbox-kit/source": "./src/checks/*.ts",
43
+ "default": "./dist/checks/*.js"
44
+ },
45
+ "#config/*.js": {
46
+ "@sandbox-kit/source": "./src/config/*.ts",
47
+ "default": "./dist/config/*.js"
48
+ }
49
+ },
50
+ "scripts": {
51
+ "build": "tsc -p tsconfig.build.json",
52
+ "prepublishOnly": "npm run build",
53
+ "test": "tsc -p tsconfig.test.json && vitest run"
54
+ },
55
+ "dependencies": {
56
+ "@bufbuild/protobuf": "2.16.0",
57
+ "@sandbox-kit/sandbox": "0.1.0",
58
+ "modal": "0.11.1"
59
+ },
60
+ "devDependencies": {
61
+ "@types/node": "24.10.1",
62
+ "typescript": "5.9.3",
63
+ "vitest": "4.1.11"
64
+ }
65
+ }