@computesdk/railway 1.1.12 → 1.1.14
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/dist/index.d.mts +37 -21
- package/dist/index.d.ts +37 -21
- package/dist/index.js +2 -189
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -188
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,33 +1,49 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as computesdk from 'computesdk';
|
|
2
|
+
import { ComputeConfig } from '@computesdk/provider';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
* Railway
|
|
5
|
+
* Railway provider configuration
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
-
* Railway sandbox interface
|
|
8
|
-
*/
|
|
9
|
-
interface RailwaySandbox {
|
|
10
|
-
serviceId: string;
|
|
11
|
-
projectId: string;
|
|
12
|
-
environmentId: string;
|
|
13
|
-
}
|
|
14
|
-
interface RailwayConfig {
|
|
7
|
+
interface RailwayConfig extends ComputeConfig {
|
|
15
8
|
/** Railway API key - if not provided, will fallback to RAILWAY_API_KEY environment variable */
|
|
16
9
|
apiKey?: string;
|
|
17
|
-
/** Railway Project ID */
|
|
10
|
+
/** Railway Project ID - if not provided, will fallback to RAILWAY_PROJECT_ID environment variable */
|
|
18
11
|
projectId?: string;
|
|
19
12
|
/** Railway Environment ID - if not provided, will fallback to RAILWAY_ENVIRONMENT_ID environment variable */
|
|
20
13
|
environmentId?: string;
|
|
21
14
|
}
|
|
22
|
-
declare const getAndValidateCredentials: (config: RailwayConfig) => {
|
|
23
|
-
apiKey: string;
|
|
24
|
-
projectId: string;
|
|
25
|
-
environmentId: string;
|
|
26
|
-
};
|
|
27
|
-
declare const fetchRailway: (apiKey: string, mutation: any) => Promise<any>;
|
|
28
15
|
/**
|
|
29
|
-
*
|
|
16
|
+
* Railway compute factory - creates configured compute instances
|
|
17
|
+
*
|
|
18
|
+
* Railway is an infrastructure provider that becomes a full sandbox provider
|
|
19
|
+
* via the ComputeSDK gateway. The gateway provisions Railway services with the
|
|
20
|
+
* daemon pre-installed, enabling full sandbox capabilities.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { railway } from '@computesdk/railway';
|
|
25
|
+
*
|
|
26
|
+
* const compute = railway({
|
|
27
|
+
* apiKey: 'railway_xxx',
|
|
28
|
+
* projectId: 'project_xxx',
|
|
29
|
+
* environmentId: 'env_xxx'
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Full compute API available (routes through gateway)
|
|
33
|
+
* const sandbox = await compute.sandbox.create();
|
|
34
|
+
*
|
|
35
|
+
* // Execute code
|
|
36
|
+
* const result = await sandbox.runCode('console.log("Hello from Railway!")');
|
|
37
|
+
* console.log(result.stdout);
|
|
38
|
+
*
|
|
39
|
+
* // Filesystem operations
|
|
40
|
+
* await sandbox.filesystem.writeFile('/tmp/test.txt', 'Hello!');
|
|
41
|
+
* const content = await sandbox.filesystem.readFile('/tmp/test.txt');
|
|
42
|
+
*
|
|
43
|
+
* // Cleanup
|
|
44
|
+
* await sandbox.destroy();
|
|
45
|
+
* ```
|
|
30
46
|
*/
|
|
31
|
-
declare const railway: (config: RailwayConfig
|
|
47
|
+
declare const railway: (config: RailwayConfig) => computesdk.CallableCompute;
|
|
32
48
|
|
|
33
|
-
export { type RailwayConfig,
|
|
49
|
+
export { type RailwayConfig, railway };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,33 +1,49 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as computesdk from 'computesdk';
|
|
2
|
+
import { ComputeConfig } from '@computesdk/provider';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
* Railway
|
|
5
|
+
* Railway provider configuration
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
-
* Railway sandbox interface
|
|
8
|
-
*/
|
|
9
|
-
interface RailwaySandbox {
|
|
10
|
-
serviceId: string;
|
|
11
|
-
projectId: string;
|
|
12
|
-
environmentId: string;
|
|
13
|
-
}
|
|
14
|
-
interface RailwayConfig {
|
|
7
|
+
interface RailwayConfig extends ComputeConfig {
|
|
15
8
|
/** Railway API key - if not provided, will fallback to RAILWAY_API_KEY environment variable */
|
|
16
9
|
apiKey?: string;
|
|
17
|
-
/** Railway Project ID */
|
|
10
|
+
/** Railway Project ID - if not provided, will fallback to RAILWAY_PROJECT_ID environment variable */
|
|
18
11
|
projectId?: string;
|
|
19
12
|
/** Railway Environment ID - if not provided, will fallback to RAILWAY_ENVIRONMENT_ID environment variable */
|
|
20
13
|
environmentId?: string;
|
|
21
14
|
}
|
|
22
|
-
declare const getAndValidateCredentials: (config: RailwayConfig) => {
|
|
23
|
-
apiKey: string;
|
|
24
|
-
projectId: string;
|
|
25
|
-
environmentId: string;
|
|
26
|
-
};
|
|
27
|
-
declare const fetchRailway: (apiKey: string, mutation: any) => Promise<any>;
|
|
28
15
|
/**
|
|
29
|
-
*
|
|
16
|
+
* Railway compute factory - creates configured compute instances
|
|
17
|
+
*
|
|
18
|
+
* Railway is an infrastructure provider that becomes a full sandbox provider
|
|
19
|
+
* via the ComputeSDK gateway. The gateway provisions Railway services with the
|
|
20
|
+
* daemon pre-installed, enabling full sandbox capabilities.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { railway } from '@computesdk/railway';
|
|
25
|
+
*
|
|
26
|
+
* const compute = railway({
|
|
27
|
+
* apiKey: 'railway_xxx',
|
|
28
|
+
* projectId: 'project_xxx',
|
|
29
|
+
* environmentId: 'env_xxx'
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Full compute API available (routes through gateway)
|
|
33
|
+
* const sandbox = await compute.sandbox.create();
|
|
34
|
+
*
|
|
35
|
+
* // Execute code
|
|
36
|
+
* const result = await sandbox.runCode('console.log("Hello from Railway!")');
|
|
37
|
+
* console.log(result.stdout);
|
|
38
|
+
*
|
|
39
|
+
* // Filesystem operations
|
|
40
|
+
* await sandbox.filesystem.writeFile('/tmp/test.txt', 'Hello!');
|
|
41
|
+
* const content = await sandbox.filesystem.readFile('/tmp/test.txt');
|
|
42
|
+
*
|
|
43
|
+
* // Cleanup
|
|
44
|
+
* await sandbox.destroy();
|
|
45
|
+
* ```
|
|
30
46
|
*/
|
|
31
|
-
declare const railway: (config: RailwayConfig
|
|
47
|
+
declare const railway: (config: RailwayConfig) => computesdk.CallableCompute;
|
|
32
48
|
|
|
33
|
-
export { type RailwayConfig,
|
|
49
|
+
export { type RailwayConfig, railway };
|
package/dist/index.js
CHANGED
|
@@ -20,202 +20,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
fetchRailway: () => fetchRailway,
|
|
24
|
-
getAndValidateCredentials: () => getAndValidateCredentials,
|
|
25
23
|
railway: () => railway
|
|
26
24
|
});
|
|
27
25
|
module.exports = __toCommonJS(index_exports);
|
|
28
26
|
var import_provider = require("@computesdk/provider");
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
const projectId = config.projectId || typeof process !== "undefined" && process.env?.RAILWAY_PROJECT_ID || "";
|
|
32
|
-
const environmentId = config.environmentId || typeof process !== "undefined" && process.env?.RAILWAY_ENVIRONMENT_ID || "";
|
|
33
|
-
if (!apiKey) {
|
|
34
|
-
throw new Error(
|
|
35
|
-
"Missing Railway API key. Provide apiKey in config or set RAILWAY_API_KEY environment variable."
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
if (!projectId) {
|
|
39
|
-
throw new Error(
|
|
40
|
-
"Missing Railway Project ID. Provide projectId in config or set RAILWAY_PROJECT_ID environment variable."
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
if (!environmentId) {
|
|
44
|
-
throw new Error(
|
|
45
|
-
"Missing Railway Environment ID. Provide environmentId in config or set RAILWAY_ENVIRONMENT_ID environment variable."
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
return { apiKey, projectId, environmentId };
|
|
49
|
-
};
|
|
50
|
-
var GRAPHQL_QUERIES = {
|
|
51
|
-
CREATE_SERVICE: `mutation ServiceCreate($input: ServiceCreateInput!) { serviceCreate(input: $input) { id name } }`,
|
|
52
|
-
GET_SERVICE: `query Service($serviceId: String!) { service(id: $serviceId) { id name createdAt } }`,
|
|
53
|
-
LIST_SERVICES: `query Project($projectId: String!) { project(id: $projectId) { services { edges { node { id name createdAt updatedAt } } } } }`,
|
|
54
|
-
DELETE_SERVICE: `mutation ServiceDelete($id: String!) { serviceDelete(id: $id) }`
|
|
55
|
-
};
|
|
56
|
-
var handleGraphQLErrors = (data) => {
|
|
57
|
-
if (data.errors) {
|
|
58
|
-
throw new Error(`Railway GraphQL error: ${data.errors.map((e) => e.message).join(", ")}`);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
var fetchRailway = async (apiKey, mutation) => {
|
|
62
|
-
const response = await fetch("https://backboard.railway.com/graphql/v2", {
|
|
63
|
-
method: "POST",
|
|
64
|
-
headers: {
|
|
65
|
-
"Content-Type": "application/json",
|
|
66
|
-
"Authorization": `Bearer ${apiKey}`
|
|
67
|
-
},
|
|
68
|
-
body: JSON.stringify(mutation)
|
|
69
|
-
});
|
|
70
|
-
if (!response.ok) {
|
|
71
|
-
throw new Error(`Railway API error: ${response.status} ${response.statusText}`);
|
|
72
|
-
}
|
|
73
|
-
const data = await response.json();
|
|
74
|
-
handleGraphQLErrors(data);
|
|
75
|
-
return data.data;
|
|
76
|
-
};
|
|
77
|
-
var railway = (0, import_provider.defineProvider)({
|
|
78
|
-
name: "railway",
|
|
79
|
-
methods: {
|
|
80
|
-
sandbox: {
|
|
81
|
-
// Collection operations (compute.sandbox.*)
|
|
82
|
-
create: async (config, options) => {
|
|
83
|
-
const { apiKey, projectId, environmentId } = getAndValidateCredentials(config);
|
|
84
|
-
try {
|
|
85
|
-
const mutation = {
|
|
86
|
-
query: GRAPHQL_QUERIES.CREATE_SERVICE,
|
|
87
|
-
variables: {
|
|
88
|
-
input: {
|
|
89
|
-
projectId,
|
|
90
|
-
environmentId,
|
|
91
|
-
source: {
|
|
92
|
-
image: options?.runtime === "node" ? "node:alpine" : "python:alpine"
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
const responseData = await fetchRailway(apiKey, mutation);
|
|
98
|
-
const service = responseData?.serviceCreate;
|
|
99
|
-
if (!service) {
|
|
100
|
-
throw new Error("No service returned from Railway API - responseData.serviceCreate is undefined");
|
|
101
|
-
}
|
|
102
|
-
if (!service.id) {
|
|
103
|
-
throw new Error(`Service ID is undefined. Full service object: ${JSON.stringify(service, null, 2)}`);
|
|
104
|
-
}
|
|
105
|
-
const railwaySandbox = {
|
|
106
|
-
serviceId: service.id,
|
|
107
|
-
projectId,
|
|
108
|
-
environmentId
|
|
109
|
-
};
|
|
110
|
-
return {
|
|
111
|
-
sandbox: railwaySandbox,
|
|
112
|
-
sandboxId: service.id
|
|
113
|
-
};
|
|
114
|
-
} catch (error) {
|
|
115
|
-
throw new Error(
|
|
116
|
-
`Failed to create Railway sandbox: ${error instanceof Error ? error.message : String(error)}`
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
getById: async (config, sandboxId) => {
|
|
121
|
-
const { apiKey, projectId, environmentId } = getAndValidateCredentials(config);
|
|
122
|
-
try {
|
|
123
|
-
const mutation = {
|
|
124
|
-
query: GRAPHQL_QUERIES.GET_SERVICE,
|
|
125
|
-
variables: {
|
|
126
|
-
serviceId: sandboxId
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
const responseData = await fetchRailway(apiKey, mutation);
|
|
130
|
-
if (responseData === null) {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
const service = responseData?.service;
|
|
134
|
-
if (!service) {
|
|
135
|
-
throw new Error("Service data is missing from Railway response");
|
|
136
|
-
}
|
|
137
|
-
const railwaySandbox = {
|
|
138
|
-
serviceId: service.id,
|
|
139
|
-
projectId,
|
|
140
|
-
environmentId
|
|
141
|
-
};
|
|
142
|
-
return {
|
|
143
|
-
sandbox: railwaySandbox,
|
|
144
|
-
sandboxId: service.id
|
|
145
|
-
};
|
|
146
|
-
} catch (error) {
|
|
147
|
-
throw new Error(
|
|
148
|
-
`Failed to get Railway sandbox: ${error instanceof Error ? error.message : String(error)}`
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
list: async (config) => {
|
|
153
|
-
const { apiKey, projectId, environmentId } = getAndValidateCredentials(config);
|
|
154
|
-
try {
|
|
155
|
-
const mutation = {
|
|
156
|
-
query: GRAPHQL_QUERIES.LIST_SERVICES,
|
|
157
|
-
variables: {
|
|
158
|
-
projectId
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
const responseData = await fetchRailway(apiKey, mutation);
|
|
162
|
-
const services = responseData?.project?.services?.edges || [];
|
|
163
|
-
const sandboxes = services.map((edge) => {
|
|
164
|
-
const service = edge.node;
|
|
165
|
-
const railwaySandbox = {
|
|
166
|
-
serviceId: service.id,
|
|
167
|
-
projectId,
|
|
168
|
-
environmentId
|
|
169
|
-
};
|
|
170
|
-
return {
|
|
171
|
-
sandbox: railwaySandbox,
|
|
172
|
-
sandboxId: service.id
|
|
173
|
-
};
|
|
174
|
-
});
|
|
175
|
-
return sandboxes;
|
|
176
|
-
} catch (error) {
|
|
177
|
-
throw new Error(
|
|
178
|
-
`Failed to list Railway sandboxes: ${error instanceof Error ? error.message : String(error)}`
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
destroy: async (config, sandboxId) => {
|
|
183
|
-
const { apiKey } = getAndValidateCredentials(config);
|
|
184
|
-
try {
|
|
185
|
-
const mutation = {
|
|
186
|
-
query: GRAPHQL_QUERIES.DELETE_SERVICE,
|
|
187
|
-
variables: {
|
|
188
|
-
id: sandboxId
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
const data = await fetchRailway(apiKey, mutation);
|
|
192
|
-
if (data.errors) {
|
|
193
|
-
console.warn(`Railway delete warning: ${data.errors.map((e) => e.message).join(", ")}`);
|
|
194
|
-
}
|
|
195
|
-
} catch (error) {
|
|
196
|
-
console.warn(`Railway destroy warning: ${error instanceof Error ? error.message : String(error)}`);
|
|
197
|
-
}
|
|
198
|
-
},
|
|
199
|
-
// Instance operations (minimal stubs - not implemented yet)
|
|
200
|
-
runCode: async (_sandbox, _code, _runtime) => {
|
|
201
|
-
throw new Error("Railway runCode method not implemented yet");
|
|
202
|
-
},
|
|
203
|
-
runCommand: async (_sandbox, _command, _options) => {
|
|
204
|
-
throw new Error("Railway runCommand method not implemented yet");
|
|
205
|
-
},
|
|
206
|
-
getInfo: async (_sandbox) => {
|
|
207
|
-
throw new Error("Railway getInfo method not implemented yet");
|
|
208
|
-
},
|
|
209
|
-
getUrl: async (_sandbox, _options) => {
|
|
210
|
-
throw new Error("Railway getUrl method not implemented yet");
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
27
|
+
var railway = (0, import_provider.defineCompute)({
|
|
28
|
+
provider: "railway"
|
|
214
29
|
});
|
|
215
30
|
// Annotate the CommonJS export names for ESM import in node:
|
|
216
31
|
0 && (module.exports = {
|
|
217
|
-
fetchRailway,
|
|
218
|
-
getAndValidateCredentials,
|
|
219
32
|
railway
|
|
220
33
|
});
|
|
221
34
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Railway Provider - Factory-based Implementation\n */\n\nimport { defineProvider } from '@computesdk/provider';\n\nimport type { Runtime, CodeResult, CommandResult, SandboxInfo, CreateSandboxOptions, FileEntry, RunCommandOptions } from '@computesdk/provider';\n\n/**\n * Railway sandbox interface\n */\ninterface RailwaySandbox {\n serviceId: string;\n projectId: string;\n environmentId: string;\n}\n\nexport interface RailwayConfig {\n /** Railway API key - if not provided, will fallback to RAILWAY_API_KEY environment variable */\n apiKey?: string;\n /** Railway Project ID */\n projectId?: string;\n /** Railway Environment ID - if not provided, will fallback to RAILWAY_ENVIRONMENT_ID environment variable */\n environmentId?: string;\n}\n\nexport const getAndValidateCredentials = (config: RailwayConfig) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.RAILWAY_API_KEY) || '';\n const projectId = config.projectId || (typeof process !== 'undefined' && process.env?.RAILWAY_PROJECT_ID) || '';\n const environmentId = config.environmentId || (typeof process !== 'undefined' && process.env?.RAILWAY_ENVIRONMENT_ID) || '';\n\n if (!apiKey) {\n throw new Error(\n 'Missing Railway API key. Provide apiKey in config or set RAILWAY_API_KEY environment variable.'\n );\n }\n\n if (!projectId) {\n throw new Error(\n 'Missing Railway Project ID. Provide projectId in config or set RAILWAY_PROJECT_ID environment variable.'\n );\n }\n\n if (!environmentId) {\n throw new Error(\n 'Missing Railway Environment ID. Provide environmentId in config or set RAILWAY_ENVIRONMENT_ID environment variable.'\n );\n }\n\n return { apiKey, projectId, environmentId };\n};\n\nconst GRAPHQL_QUERIES = {\n CREATE_SERVICE: `mutation ServiceCreate($input: ServiceCreateInput!) { serviceCreate(input: $input) { id name } }`,\n GET_SERVICE: `query Service($serviceId: String!) { service(id: $serviceId) { id name createdAt } }`,\n LIST_SERVICES: `query Project($projectId: String!) { project(id: $projectId) { services { edges { node { id name createdAt updatedAt } } } } }`,\n DELETE_SERVICE: `mutation ServiceDelete($id: String!) { serviceDelete(id: $id) }`\n};\n\nconst handleGraphQLErrors = (data: any) => {\n if (data.errors) {\n throw new Error(`Railway GraphQL error: ${data.errors.map((e: any) => e.message).join(', ')}`);\n }\n};\n\n\nexport const fetchRailway = async (\n apiKey: string, \n mutation: any,\n) => {\n \n const response = await fetch('https://backboard.railway.com/graphql/v2', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${apiKey}`\n },\n body: JSON.stringify(mutation)\n });\n\n if (!response.ok) {\n throw new Error(`Railway API error: ${response.status} ${response.statusText}`);\n }\n\n const data = await response.json();\n\n // Standard error handling for all operations\n handleGraphQLErrors(data);\n\n return data.data;\n};\n\n\n\n/**\n * Create a Railway provider instance using the factory pattern\n */\nexport const railway = defineProvider<RailwaySandbox, RailwayConfig>({\n name: 'railway',\n methods: {\n sandbox: {\n // Collection operations (compute.sandbox.*)\n create: async (config: RailwayConfig, options?: CreateSandboxOptions) => {\n const { apiKey, projectId, environmentId } = getAndValidateCredentials(config);\n\n try {\n const mutation = {\n query: GRAPHQL_QUERIES.CREATE_SERVICE,\n variables: {\n input: {\n projectId,\n environmentId,\n source: {\n image: options?.runtime === 'node' ? 'node:alpine' : 'python:alpine'\n }\n }\n }\n };\n\n const responseData = await fetchRailway(apiKey, mutation);\n \n // Extract service from the expected serviceCreate response\n const service = responseData?.serviceCreate;\n \n if (!service) {\n throw new Error('No service returned from Railway API - responseData.serviceCreate is undefined');\n }\n \n if (!service.id) {\n throw new Error(`Service ID is undefined. Full service object: ${JSON.stringify(service, null, 2)}`);\n }\n\n const railwaySandbox: RailwaySandbox = {\n serviceId: service.id,\n projectId,\n environmentId,\n };\n\n return {\n sandbox: railwaySandbox,\n sandboxId: service.id\n };\n } catch (error) {\n throw new Error(\n `Failed to create Railway sandbox: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getById: async (config: RailwayConfig, sandboxId: string) => {\n const { apiKey, projectId, environmentId } = getAndValidateCredentials(config);\n\n try {\n const mutation = {\n query: GRAPHQL_QUERIES.GET_SERVICE,\n variables: {\n serviceId: sandboxId\n }\n };\n\n const responseData = await fetchRailway(apiKey, mutation);\n \n // If service doesn't exist, fetchRailway returns null when useGetByIdErrorHandling=true\n if (responseData === null) {\n return null;\n }\n \n const service = responseData?.service;\n \n // Service should be defined if we get here (non-existent services return null above)\n if (!service) {\n throw new Error('Service data is missing from Railway response');\n }\n const railwaySandbox: RailwaySandbox = {\n serviceId: service.id,\n projectId,\n environmentId,\n };\n\n return {\n sandbox: railwaySandbox,\n sandboxId: service.id\n };\n } catch (error) {\n throw new Error(\n `Failed to get Railway sandbox: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n \n list: async (config: RailwayConfig) => {\n const { apiKey, projectId, environmentId } = getAndValidateCredentials(config);\n\n try {\n const mutation = {\n query: GRAPHQL_QUERIES.LIST_SERVICES,\n variables: {\n projectId\n }\n };\n\n const responseData = await fetchRailway(apiKey, mutation);\n \n // Extract services from the project.services.edges structure\n const services = responseData?.project?.services?.edges || [];\n \n // Transform each service into the expected format\n const sandboxes = services.map((edge: any) => {\n const service = edge.node;\n const railwaySandbox: RailwaySandbox = {\n serviceId: service.id,\n projectId,\n environmentId,\n };\n\n return {\n sandbox: railwaySandbox,\n sandboxId: service.id\n };\n });\n\n return sandboxes;\n } catch (error) {\n throw new Error(\n `Failed to list Railway sandboxes: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n destroy: async (config: RailwayConfig, sandboxId: string) => {\n const { apiKey } = getAndValidateCredentials(config);\n\n try {\n const mutation = {\n query: GRAPHQL_QUERIES.DELETE_SERVICE,\n variables: {\n id: sandboxId\n }\n };\n\n const data = await fetchRailway(apiKey, mutation);\n \n if (data.errors) {\n // Log errors but don't throw for destroy operations\n console.warn(`Railway delete warning: ${data.errors.map((e: any) => e.message).join(', ')}`);\n }\n } catch (error) {\n // For destroy operations, we typically don't throw if the service is already gone\n console.warn(`Railway destroy warning: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n // Instance operations (minimal stubs - not implemented yet)\n runCode: async (_sandbox: RailwaySandbox, _code: string, _runtime?: Runtime) => {\n throw new Error('Railway runCode method not implemented yet');\n },\n\n runCommand: async (_sandbox: RailwaySandbox, _command: string, _options?: RunCommandOptions) => {\n throw new Error('Railway runCommand method not implemented yet');\n },\n\n getInfo: async (_sandbox: RailwaySandbox) => {\n throw new Error('Railway getInfo method not implemented yet');\n },\n\n getUrl: async (_sandbox: RailwaySandbox, _options: { port: number; protocol?: string }) => {\n throw new Error('Railway getUrl method not implemented yet');\n },\n\n },\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAA+B;AAsBxB,IAAM,4BAA4B,CAAC,WAA0B;AAClE,QAAM,SAAS,OAAO,UAAW,OAAO,YAAY,eAAe,QAAQ,KAAK,mBAAoB;AACpG,QAAM,YAAY,OAAO,aAAc,OAAO,YAAY,eAAe,QAAQ,KAAK,sBAAuB;AAC7G,QAAM,gBAAgB,OAAO,iBAAkB,OAAO,YAAY,eAAe,QAAQ,KAAK,0BAA2B;AAEzH,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,MAAI,CAAC,WAAW;AACd,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,QAAQ,WAAW,cAAc;AAC5C;AAEA,IAAM,kBAAkB;AAAA,EACtB,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,eAAe;AAAA,EACf,gBAAgB;AAClB;AAEA,IAAM,sBAAsB,CAAC,SAAc;AACzC,MAAI,KAAK,QAAQ;AACf,UAAM,IAAI,MAAM,0BAA0B,KAAK,OAAO,IAAI,CAAC,MAAW,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC,EAAE;AAAA,EAC/F;AACF;AAGO,IAAM,eAAe,OAC1B,QACA,aACG;AAEH,QAAM,WAAW,MAAM,MAAM,4CAA4C;AAAA,IACvE,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,iBAAiB,UAAU,MAAM;AAAA,IACnC;AAAA,IACA,MAAM,K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qCAAqC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,UAC7F;AAAA,QACF;AAAA,MACF;AAAA,MAEA,SAAS,OAAO,QAAuB,cAAsB;AAC3D,cAAM,EAAE,OAAO,IAAI,0BAA0B,MAAM;AAEnD,YAAI;AACF,gBAAM,WAAW;AAAA,YACf,OAAO,gBAAgB;AAAA,YACvB,WAAW;AAAA,cACT,IAAI;AAAA,YACN;AAAA,UACF;AAEA,gBAAM,OAAO,MAAM,aAAa,QAAQ,QAAQ;AAEhD,cAAI,KAAK,QAAQ;AAEf,oBAAQ,KAAK,2BAA2B,KAAK,OAAO,IAAI,CAAC,MAAW,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC,EAAE;AAAA,UAC7F;AAAA,QACF,SAAS,OAAO;AAEd,kBAAQ,KAAK,4BAA4B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AAAA,QACnG;AAAA,MACF;AAAA;AAAA,MAGA,SAAS,OAAO,UAA0B,OAAe,aAAuB;AAC9E,cAAM,IAAI,MAAM,4CAA4C;AAAA,MAC9D;AAAA,MAEA,YAAY,OAAO,UAA0B,UAAkB,aAAiC;AAC9F,cAAM,IAAI,MAAM,+CAA+C;AAAA,MACjE;AAAA,MAEA,SAAS,OAAO,aAA6B;AAC3C,cAAM,IAAI,MAAM,4CAA4C;AAAA,MAC9D;AAAA,MAEA,QAAQ,OAAO,UAA0B,aAAkD;AACzF,cAAM,IAAI,MAAM,2CAA2C;AAAA,MAC7D;AAAA,IAEF;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Railway Provider - Compute Factory\n * \n * Provides a first-class Railway provider experience by routing all operations\n * through the ComputeSDK gateway. The gateway handles infrastructure provisioning\n * via @computesdk/gateway and installs the daemon for full sandbox capabilities.\n */\n\nimport { defineCompute, type ComputeConfig } from '@computesdk/provider';\n\n/**\n * Railway provider configuration\n */\nexport interface RailwayConfig extends ComputeConfig {\n /** Railway API key - if not provided, will fallback to RAILWAY_API_KEY environment variable */\n apiKey?: string;\n /** Railway Project ID - if not provided, will fallback to RAILWAY_PROJECT_ID environment variable */\n projectId?: string;\n /** Railway Environment ID - if not provided, will fallback to RAILWAY_ENVIRONMENT_ID environment variable */\n environmentId?: string;\n}\n\n/**\n * Railway compute factory - creates configured compute instances\n * \n * Railway is an infrastructure provider that becomes a full sandbox provider\n * via the ComputeSDK gateway. The gateway provisions Railway services with the\n * daemon pre-installed, enabling full sandbox capabilities.\n * \n * @example\n * ```typescript\n * import { railway } from '@computesdk/railway';\n * \n * const compute = railway({\n * apiKey: 'railway_xxx',\n * projectId: 'project_xxx',\n * environmentId: 'env_xxx'\n * });\n * \n * // Full compute API available (routes through gateway)\n * const sandbox = await compute.sandbox.create();\n * \n * // Execute code\n * const result = await sandbox.runCode('console.log(\"Hello from Railway!\")');\n * console.log(result.stdout);\n * \n * // Filesystem operations\n * await sandbox.filesystem.writeFile('/tmp/test.txt', 'Hello!');\n * const content = await sandbox.filesystem.readFile('/tmp/test.txt');\n * \n * // Cleanup\n * await sandbox.destroy();\n * ```\n */\nexport const railway = defineCompute<RailwayConfig>({\n provider: 'railway'\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,sBAAkD;AA8C3C,IAAM,cAAU,+BAA6B;AAAA,EAClD,UAAU;AACZ,CAAC;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,194 +1,9 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import {
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
const projectId = config.projectId || typeof process !== "undefined" && process.env?.RAILWAY_PROJECT_ID || "";
|
|
6
|
-
const environmentId = config.environmentId || typeof process !== "undefined" && process.env?.RAILWAY_ENVIRONMENT_ID || "";
|
|
7
|
-
if (!apiKey) {
|
|
8
|
-
throw new Error(
|
|
9
|
-
"Missing Railway API key. Provide apiKey in config or set RAILWAY_API_KEY environment variable."
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
if (!projectId) {
|
|
13
|
-
throw new Error(
|
|
14
|
-
"Missing Railway Project ID. Provide projectId in config or set RAILWAY_PROJECT_ID environment variable."
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
if (!environmentId) {
|
|
18
|
-
throw new Error(
|
|
19
|
-
"Missing Railway Environment ID. Provide environmentId in config or set RAILWAY_ENVIRONMENT_ID environment variable."
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
return { apiKey, projectId, environmentId };
|
|
23
|
-
};
|
|
24
|
-
var GRAPHQL_QUERIES = {
|
|
25
|
-
CREATE_SERVICE: `mutation ServiceCreate($input: ServiceCreateInput!) { serviceCreate(input: $input) { id name } }`,
|
|
26
|
-
GET_SERVICE: `query Service($serviceId: String!) { service(id: $serviceId) { id name createdAt } }`,
|
|
27
|
-
LIST_SERVICES: `query Project($projectId: String!) { project(id: $projectId) { services { edges { node { id name createdAt updatedAt } } } } }`,
|
|
28
|
-
DELETE_SERVICE: `mutation ServiceDelete($id: String!) { serviceDelete(id: $id) }`
|
|
29
|
-
};
|
|
30
|
-
var handleGraphQLErrors = (data) => {
|
|
31
|
-
if (data.errors) {
|
|
32
|
-
throw new Error(`Railway GraphQL error: ${data.errors.map((e) => e.message).join(", ")}`);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var fetchRailway = async (apiKey, mutation) => {
|
|
36
|
-
const response = await fetch("https://backboard.railway.com/graphql/v2", {
|
|
37
|
-
method: "POST",
|
|
38
|
-
headers: {
|
|
39
|
-
"Content-Type": "application/json",
|
|
40
|
-
"Authorization": `Bearer ${apiKey}`
|
|
41
|
-
},
|
|
42
|
-
body: JSON.stringify(mutation)
|
|
43
|
-
});
|
|
44
|
-
if (!response.ok) {
|
|
45
|
-
throw new Error(`Railway API error: ${response.status} ${response.statusText}`);
|
|
46
|
-
}
|
|
47
|
-
const data = await response.json();
|
|
48
|
-
handleGraphQLErrors(data);
|
|
49
|
-
return data.data;
|
|
50
|
-
};
|
|
51
|
-
var railway = defineProvider({
|
|
52
|
-
name: "railway",
|
|
53
|
-
methods: {
|
|
54
|
-
sandbox: {
|
|
55
|
-
// Collection operations (compute.sandbox.*)
|
|
56
|
-
create: async (config, options) => {
|
|
57
|
-
const { apiKey, projectId, environmentId } = getAndValidateCredentials(config);
|
|
58
|
-
try {
|
|
59
|
-
const mutation = {
|
|
60
|
-
query: GRAPHQL_QUERIES.CREATE_SERVICE,
|
|
61
|
-
variables: {
|
|
62
|
-
input: {
|
|
63
|
-
projectId,
|
|
64
|
-
environmentId,
|
|
65
|
-
source: {
|
|
66
|
-
image: options?.runtime === "node" ? "node:alpine" : "python:alpine"
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
const responseData = await fetchRailway(apiKey, mutation);
|
|
72
|
-
const service = responseData?.serviceCreate;
|
|
73
|
-
if (!service) {
|
|
74
|
-
throw new Error("No service returned from Railway API - responseData.serviceCreate is undefined");
|
|
75
|
-
}
|
|
76
|
-
if (!service.id) {
|
|
77
|
-
throw new Error(`Service ID is undefined. Full service object: ${JSON.stringify(service, null, 2)}`);
|
|
78
|
-
}
|
|
79
|
-
const railwaySandbox = {
|
|
80
|
-
serviceId: service.id,
|
|
81
|
-
projectId,
|
|
82
|
-
environmentId
|
|
83
|
-
};
|
|
84
|
-
return {
|
|
85
|
-
sandbox: railwaySandbox,
|
|
86
|
-
sandboxId: service.id
|
|
87
|
-
};
|
|
88
|
-
} catch (error) {
|
|
89
|
-
throw new Error(
|
|
90
|
-
`Failed to create Railway sandbox: ${error instanceof Error ? error.message : String(error)}`
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
getById: async (config, sandboxId) => {
|
|
95
|
-
const { apiKey, projectId, environmentId } = getAndValidateCredentials(config);
|
|
96
|
-
try {
|
|
97
|
-
const mutation = {
|
|
98
|
-
query: GRAPHQL_QUERIES.GET_SERVICE,
|
|
99
|
-
variables: {
|
|
100
|
-
serviceId: sandboxId
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
const responseData = await fetchRailway(apiKey, mutation);
|
|
104
|
-
if (responseData === null) {
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
const service = responseData?.service;
|
|
108
|
-
if (!service) {
|
|
109
|
-
throw new Error("Service data is missing from Railway response");
|
|
110
|
-
}
|
|
111
|
-
const railwaySandbox = {
|
|
112
|
-
serviceId: service.id,
|
|
113
|
-
projectId,
|
|
114
|
-
environmentId
|
|
115
|
-
};
|
|
116
|
-
return {
|
|
117
|
-
sandbox: railwaySandbox,
|
|
118
|
-
sandboxId: service.id
|
|
119
|
-
};
|
|
120
|
-
} catch (error) {
|
|
121
|
-
throw new Error(
|
|
122
|
-
`Failed to get Railway sandbox: ${error instanceof Error ? error.message : String(error)}`
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
list: async (config) => {
|
|
127
|
-
const { apiKey, projectId, environmentId } = getAndValidateCredentials(config);
|
|
128
|
-
try {
|
|
129
|
-
const mutation = {
|
|
130
|
-
query: GRAPHQL_QUERIES.LIST_SERVICES,
|
|
131
|
-
variables: {
|
|
132
|
-
projectId
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
const responseData = await fetchRailway(apiKey, mutation);
|
|
136
|
-
const services = responseData?.project?.services?.edges || [];
|
|
137
|
-
const sandboxes = services.map((edge) => {
|
|
138
|
-
const service = edge.node;
|
|
139
|
-
const railwaySandbox = {
|
|
140
|
-
serviceId: service.id,
|
|
141
|
-
projectId,
|
|
142
|
-
environmentId
|
|
143
|
-
};
|
|
144
|
-
return {
|
|
145
|
-
sandbox: railwaySandbox,
|
|
146
|
-
sandboxId: service.id
|
|
147
|
-
};
|
|
148
|
-
});
|
|
149
|
-
return sandboxes;
|
|
150
|
-
} catch (error) {
|
|
151
|
-
throw new Error(
|
|
152
|
-
`Failed to list Railway sandboxes: ${error instanceof Error ? error.message : String(error)}`
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
destroy: async (config, sandboxId) => {
|
|
157
|
-
const { apiKey } = getAndValidateCredentials(config);
|
|
158
|
-
try {
|
|
159
|
-
const mutation = {
|
|
160
|
-
query: GRAPHQL_QUERIES.DELETE_SERVICE,
|
|
161
|
-
variables: {
|
|
162
|
-
id: sandboxId
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
const data = await fetchRailway(apiKey, mutation);
|
|
166
|
-
if (data.errors) {
|
|
167
|
-
console.warn(`Railway delete warning: ${data.errors.map((e) => e.message).join(", ")}`);
|
|
168
|
-
}
|
|
169
|
-
} catch (error) {
|
|
170
|
-
console.warn(`Railway destroy warning: ${error instanceof Error ? error.message : String(error)}`);
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
// Instance operations (minimal stubs - not implemented yet)
|
|
174
|
-
runCode: async (_sandbox, _code, _runtime) => {
|
|
175
|
-
throw new Error("Railway runCode method not implemented yet");
|
|
176
|
-
},
|
|
177
|
-
runCommand: async (_sandbox, _command, _options) => {
|
|
178
|
-
throw new Error("Railway runCommand method not implemented yet");
|
|
179
|
-
},
|
|
180
|
-
getInfo: async (_sandbox) => {
|
|
181
|
-
throw new Error("Railway getInfo method not implemented yet");
|
|
182
|
-
},
|
|
183
|
-
getUrl: async (_sandbox, _options) => {
|
|
184
|
-
throw new Error("Railway getUrl method not implemented yet");
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
2
|
+
import { defineCompute } from "@computesdk/provider";
|
|
3
|
+
var railway = defineCompute({
|
|
4
|
+
provider: "railway"
|
|
188
5
|
});
|
|
189
6
|
export {
|
|
190
|
-
fetchRailway,
|
|
191
|
-
getAndValidateCredentials,
|
|
192
7
|
railway
|
|
193
8
|
};
|
|
194
9
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Railway Provider - Factory-based Implementation\n */\n\nimport { defineProvider } from '@computesdk/provider';\n\nimport type { Runtime, CodeResult, CommandResult, SandboxInfo, CreateSandboxOptions, FileEntry, RunCommandOptions } from '@computesdk/provider';\n\n/**\n * Railway sandbox interface\n */\ninterface RailwaySandbox {\n serviceId: string;\n projectId: string;\n environmentId: string;\n}\n\nexport interface RailwayConfig {\n /** Railway API key - if not provided, will fallback to RAILWAY_API_KEY environment variable */\n apiKey?: string;\n /** Railway Project ID */\n projectId?: string;\n /** Railway Environment ID - if not provided, will fallback to RAILWAY_ENVIRONMENT_ID environment variable */\n environmentId?: string;\n}\n\nexport const getAndValidateCredentials = (config: RailwayConfig) => {\n const apiKey = config.apiKey || (typeof process !== 'undefined' && process.env?.RAILWAY_API_KEY) || '';\n const projectId = config.projectId || (typeof process !== 'undefined' && process.env?.RAILWAY_PROJECT_ID) || '';\n const environmentId = config.environmentId || (typeof process !== 'undefined' && process.env?.RAILWAY_ENVIRONMENT_ID) || '';\n\n if (!apiKey) {\n throw new Error(\n 'Missing Railway API key. Provide apiKey in config or set RAILWAY_API_KEY environment variable.'\n );\n }\n\n if (!projectId) {\n throw new Error(\n 'Missing Railway Project ID. Provide projectId in config or set RAILWAY_PROJECT_ID environment variable.'\n );\n }\n\n if (!environmentId) {\n throw new Error(\n 'Missing Railway Environment ID. Provide environmentId in config or set RAILWAY_ENVIRONMENT_ID environment variable.'\n );\n }\n\n return { apiKey, projectId, environmentId };\n};\n\nconst GRAPHQL_QUERIES = {\n CREATE_SERVICE: `mutation ServiceCreate($input: ServiceCreateInput!) { serviceCreate(input: $input) { id name } }`,\n GET_SERVICE: `query Service($serviceId: String!) { service(id: $serviceId) { id name createdAt } }`,\n LIST_SERVICES: `query Project($projectId: String!) { project(id: $projectId) { services { edges { node { id name createdAt updatedAt } } } } }`,\n DELETE_SERVICE: `mutation ServiceDelete($id: String!) { serviceDelete(id: $id) }`\n};\n\nconst handleGraphQLErrors = (data: any) => {\n if (data.errors) {\n throw new Error(`Railway GraphQL error: ${data.errors.map((e: any) => e.message).join(', ')}`);\n }\n};\n\n\nexport const fetchRailway = async (\n apiKey: string, \n mutation: any,\n) => {\n \n const response = await fetch('https://backboard.railway.com/graphql/v2', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${apiKey}`\n },\n body: JSON.stringify(mutation)\n });\n\n if (!response.ok) {\n throw new Error(`Railway API error: ${response.status} ${response.statusText}`);\n }\n\n const data = await response.json();\n\n // Standard error handling for all operations\n handleGraphQLErrors(data);\n\n return data.data;\n};\n\n\n\n/**\n * Create a Railway provider instance using the factory pattern\n */\nexport const railway = defineProvider<RailwaySandbox, RailwayConfig>({\n name: 'railway',\n methods: {\n sandbox: {\n // Collection operations (compute.sandbox.*)\n create: async (config: RailwayConfig, options?: CreateSandboxOptions) => {\n const { apiKey, projectId, environmentId } = getAndValidateCredentials(config);\n\n try {\n const mutation = {\n query: GRAPHQL_QUERIES.CREATE_SERVICE,\n variables: {\n input: {\n projectId,\n environmentId,\n source: {\n image: options?.runtime === 'node' ? 'node:alpine' : 'python:alpine'\n }\n }\n }\n };\n\n const responseData = await fetchRailway(apiKey, mutation);\n \n // Extract service from the expected serviceCreate response\n const service = responseData?.serviceCreate;\n \n if (!service) {\n throw new Error('No service returned from Railway API - responseData.serviceCreate is undefined');\n }\n \n if (!service.id) {\n throw new Error(`Service ID is undefined. Full service object: ${JSON.stringify(service, null, 2)}`);\n }\n\n const railwaySandbox: RailwaySandbox = {\n serviceId: service.id,\n projectId,\n environmentId,\n };\n\n return {\n sandbox: railwaySandbox,\n sandboxId: service.id\n };\n } catch (error) {\n throw new Error(\n `Failed to create Railway sandbox: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getById: async (config: RailwayConfig, sandboxId: string) => {\n const { apiKey, projectId, environmentId } = getAndValidateCredentials(config);\n\n try {\n const mutation = {\n query: GRAPHQL_QUERIES.GET_SERVICE,\n variables: {\n serviceId: sandboxId\n }\n };\n\n const responseData = await fetchRailway(apiKey, mutation);\n \n // If service doesn't exist, fetchRailway returns null when useGetByIdErrorHandling=true\n if (responseData === null) {\n return null;\n }\n \n const service = responseData?.service;\n \n // Service should be defined if we get here (non-existent services return null above)\n if (!service) {\n throw new Error('Service data is missing from Railway response');\n }\n const railwaySandbox: RailwaySandbox = {\n serviceId: service.id,\n projectId,\n environmentId,\n };\n\n return {\n sandbox: railwaySandbox,\n sandboxId: service.id\n };\n } catch (error) {\n throw new Error(\n `Failed to get Railway sandbox: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n \n list: async (config: RailwayConfig) => {\n const { apiKey, projectId, environmentId } = getAndValidateCredentials(config);\n\n try {\n const mutation = {\n query: GRAPHQL_QUERIES.LIST_SERVICES,\n variables: {\n projectId\n }\n };\n\n const responseData = await fetchRailway(apiKey, mutation);\n \n // Extract services from the project.services.edges structure\n const services = responseData?.project?.services?.edges || [];\n \n // Transform each service into the expected format\n const sandboxes = services.map((edge: any) => {\n const service = edge.node;\n const railwaySandbox: RailwaySandbox = {\n serviceId: service.id,\n projectId,\n environmentId,\n };\n\n return {\n sandbox: railwaySandbox,\n sandboxId: service.id\n };\n });\n\n return sandboxes;\n } catch (error) {\n throw new Error(\n `Failed to list Railway sandboxes: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n destroy: async (config: RailwayConfig, sandboxId: string) => {\n const { apiKey } = getAndValidateCredentials(config);\n\n try {\n const mutation = {\n query: GRAPHQL_QUERIES.DELETE_SERVICE,\n variables: {\n id: sandboxId\n }\n };\n\n const data = await fetchRailway(apiKey, mutation);\n \n if (data.errors) {\n // Log errors but don't throw for destroy operations\n console.warn(`Railway delete warning: ${data.errors.map((e: any) => e.message).join(', ')}`);\n }\n } catch (error) {\n // For destroy operations, we typically don't throw if the service is already gone\n console.warn(`Railway destroy warning: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n // Instance operations (minimal stubs - not implemented yet)\n runCode: async (_sandbox: RailwaySandbox, _code: string, _runtime?: Runtime) => {\n throw new Error('Railway runCode method not implemented yet');\n },\n\n runCommand: async (_sandbox: RailwaySandbox, _command: string, _options?: RunCommandOptions) => {\n throw new Error('Railway runCommand method not implemented yet');\n },\n\n getInfo: async (_sandbox: RailwaySandbox) => {\n throw new Error('Railway getInfo method not implemented yet');\n },\n\n getUrl: async (_sandbox: RailwaySandbox, _options: { port: number; protocol?: string }) => {\n throw new Error('Railway getUrl method not implemented yet');\n },\n\n },\n },\n});\n"],"mappings":";AAIA,SAAS,sBAAsB;AAsBxB,IAAM,4BAA4B,CAAC,WAA0B;AAClE,QAAM,SAAS,OAAO,UAAW,OAAO,YAAY,eAAe,QAAQ,KAAK,mBAAoB;AACpG,QAAM,YAAY,OAAO,aAAc,OAAO,YAAY,eAAe,QAAQ,KAAK,sBAAuB;AAC7G,QAAM,gBAAgB,OAAO,iBAAkB,OAAO,YAAY,eAAe,QAAQ,KAAK,0BAA2B;AAEzH,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,MAAI,CAAC,WAAW;AACd,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,QAAQ,WAAW,cAAc;AAC5C;AAEA,IAAM,kBAAkB;AAAA,EACtB,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,eAAe;AAAA,EACf,gBAAgB;AAClB;AAEA,IAAM,sBAAsB,CAAC,SAAc;AACzC,MAAI,KAAK,QAAQ;AACf,UAAM,IAAI,MAAM,0BAA0B,KAAK,OAAO,IAAI,CAAC,MAAW,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC,EAAE;AAAA,EAC/F;AACF;AAGO,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railway Provider - Compute Factory\n * \n * Provides a first-class Railway provider experience by routing all operations\n * through the ComputeSDK gateway. The gateway handles infrastructure provisioning\n * via @computesdk/gateway and installs the daemon for full sandbox capabilities.\n */\n\nimport { defineCompute, type ComputeConfig } from '@computesdk/provider';\n\n/**\n * Railway provider configuration\n */\nexport interface RailwayConfig extends ComputeConfig {\n /** Railway API key - if not provided, will fallback to RAILWAY_API_KEY environment variable */\n apiKey?: string;\n /** Railway Project ID - if not provided, will fallback to RAILWAY_PROJECT_ID environment variable */\n projectId?: string;\n /** Railway Environment ID - if not provided, will fallback to RAILWAY_ENVIRONMENT_ID environment variable */\n environmentId?: string;\n}\n\n/**\n * Railway compute factory - creates configured compute instances\n * \n * Railway is an infrastructure provider that becomes a full sandbox provider\n * via the ComputeSDK gateway. The gateway provisions Railway services with the\n * daemon pre-installed, enabling full sandbox capabilities.\n * \n * @example\n * ```typescript\n * import { railway } from '@computesdk/railway';\n * \n * const compute = railway({\n * apiKey: 'railway_xxx',\n * projectId: 'project_xxx',\n * environmentId: 'env_xxx'\n * });\n * \n * // Full compute API available (routes through gateway)\n * const sandbox = await compute.sandbox.create();\n * \n * // Execute code\n * const result = await sandbox.runCode('console.log(\"Hello from Railway!\")');\n * console.log(result.stdout);\n * \n * // Filesystem operations\n * await sandbox.filesystem.writeFile('/tmp/test.txt', 'Hello!');\n * const content = await sandbox.filesystem.readFile('/tmp/test.txt');\n * \n * // Cleanup\n * await sandbox.destroy();\n * ```\n */\nexport const railway = defineCompute<RailwayConfig>({\n provider: 'railway'\n});\n"],"mappings":";AAQA,SAAS,qBAAyC;AA8C3C,IAAM,UAAU,cAA6B;AAAA,EAClD,UAAU;AACZ,CAAC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@computesdk/railway",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.14",
|
|
4
4
|
"description": "Railway provider for ComputeSDK - simple cloud deployment for containerized sandboxes",
|
|
5
5
|
"author": "ComputeSDK Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@computesdk/provider": "1.0.
|
|
22
|
-
"computesdk": "1.
|
|
21
|
+
"@computesdk/provider": "1.0.8",
|
|
22
|
+
"computesdk": "1.12.1"
|
|
23
23
|
},
|
|
24
24
|
"keywords": [
|
|
25
25
|
"computesdk",
|