@maravilla-labs/adapter-sveltekit 0.8.3 → 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ Proprietary License
2
+
3
+ Copyright (c) 2025 SOLUTAS GmbH, Switzerland. All rights reserved.
4
+
5
+ This software and associated documentation (the "Software") are the confidential and proprietary information of SOLUTAS GmbH ("SOLUTAS"). By using, copying, or accessing the Software, you agree that:
6
+
7
+ - No rights are granted except as expressly set forth in a separate written agreement with SOLUTAS.
8
+ - You may not copy, modify, distribute, sublicense, reverse engineer, or create derivative works of the Software except as permitted in such agreement.
9
+ - The Software is provided "as is" without warranty of any kind; SOLUTAS disclaims all implied warranties to the maximum extent permitted by law.
10
+ - In no event shall SOLUTAS be liable for any damages arising from use of the Software except as expressly provided in an applicable agreement.
11
+
12
+ For licensing inquiries, contact: legal@solutas.ch
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAW,MAAM,eAAe,CAAC;AACtD,OAAO,EAUL,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AAKtC,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAoIrE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAW,MAAM,eAAe,CAAC;AACtD,OAAO,EAWL,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AAKtC,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAuIrE"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { writeFileSync } from 'node:fs';
2
- import { bundleServerEntry, analyzeBundle, generateManifest, writeManifest, collectAssets, buildAndIntegrateFunctions, buildAndIntegrateEvents, buildAndIntegrateWorkflows, loadMaravillaConfig, } from '@maravilla-labs/adapter-core';
2
+ import { bundleServerEntry, analyzeBundle, generateManifest, writeManifest, collectAssets, buildAndIntegrateFunctions, buildAndIntegrateEvents, buildAndIntegrateWorkflows, buildAndIntegrateMcp, loadMaravillaConfig, } from '@maravilla-labs/adapter-core';
3
3
  // Import the worker template from separate file for maintainability
4
4
  import { WORKER_TEMPLATE } from './worker-template.js';
5
5
  export default function adapter(options = {}) {
@@ -91,6 +91,8 @@ export default function adapter(options = {}) {
91
91
  });
92
92
  // Build and integrate workflows (workflows.ts / workflows/**/*.ts)
93
93
  await buildAndIntegrateWorkflows(process.cwd(), out, builder.log);
94
+ // Build and integrate MCP tools (mcp.ts / mcp/**/*.ts)
95
+ await buildAndIntegrateMcp(process.cwd(), out, builder.log);
94
96
  builder.log.minor(`Build complete. Output written to ${out}`);
95
97
  builder.log.minor('');
96
98
  builder.log.minor('Deploy: push to a branch listed in .maravilla/pipeline/*.yml');
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,0BAA0B,EAC1B,uBAAuB,EACvB,0BAA0B,EAC1B,mBAAmB,GAEpB,MAAM,8BAA8B,CAAC;AAEtC,oEAAoE;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,UAA0B,EAAE;IAC1D,MAAM,EACJ,GAAG,GAAG,OAAO,EACb,WAAW,GAAG,KAAK,EACnB,SAAS,GAAG,SAAS,EACrB,QAAQ,GAAG,IAAI,EACf,OAAO,GAAG,EAAE,EACZ,OAAO,GAAG,EAAE,EACZ,Q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C,MAAM,0BAA0B,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;YAElE,kEAAkE;YAClE,6DAA6D;YAC7D,kEAAkE;YAClE,8DAA8D;YAC9D,yDAAyD;YACzD,MAAM,uBAAuB,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;gBAC7D,UAAU,EAAE,eAAe,CAAC,UAAU;aACvC,CAAC,CAAC;YAEH,mEAAmE;YACnE,MAAM,0BAA0B,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;YAElE,uDAAuD;YACvD,MAAM,oBAAoB,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;YAE5D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,qCAAqC,GAAG,EAAE,CAAC,CAAC;YAC9D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,8DAA8D,CAAC,CAAC;YAClF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC3C,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAAC;QAClD,CAAC;QAED,QAAQ,EAAE;YACR,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI;SACjB;KACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maravilla-labs/adapter-sveltekit",
3
- "version": "0.8.3",
3
+ "version": "1.0.0",
4
4
  "description": "SvelteKit adapter for Maravilla Runtime",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -15,12 +15,6 @@
15
15
  "dist/worker.js",
16
16
  "worker-template.js"
17
17
  ],
18
- "scripts": {
19
- "build": "tsc",
20
- "dev": "tsc --watch",
21
- "test": "vitest",
22
- "prepublishOnly": "npm run build"
23
- },
24
18
  "keywords": [
25
19
  "sveltekit",
26
20
  "adapter",
@@ -40,7 +34,7 @@
40
34
  },
41
35
  "peerDependencies": {
42
36
  "@sveltejs/kit": "^2.0.0",
43
- "@maravilla-labs/functions": "^0.8.3"
37
+ "@maravilla-labs/functions": "^0.9.0"
44
38
  },
45
39
  "peerDependenciesMeta": {
46
40
  "@maravilla-labs/functions": {
@@ -54,8 +48,13 @@
54
48
  "vitest": "^1.0.0"
55
49
  },
56
50
  "dependencies": {
57
- "@maravilla-labs/adapter-core": "^0.8.3",
58
51
  "esbuild": "^0.25.0",
59
- "set-cookie-parser": "^2.6.0"
52
+ "set-cookie-parser": "^2.6.0",
53
+ "@maravilla-labs/adapter-core": "^1.0.0"
54
+ },
55
+ "scripts": {
56
+ "build": "tsc",
57
+ "dev": "tsc --watch",
58
+ "test": "vitest"
60
59
  }
61
- }
60
+ }
@@ -1,290 +0,0 @@
1
- // This file contains the worker template as a proper TypeScript file for easier editing
2
- // It will be inlined into index.ts during the build
3
- export const WORKER_TEMPLATE = `// Maravilla Runtime Worker for SvelteKit
4
- // This runs inside the Deno isolate with access to platform APIs
5
-
6
- // Store the original fetch and Request for internal use
7
- const originalFetch = globalThis.fetch;
8
- const OriginalRequest = globalThis.Request;
9
-
10
- // Create an enhanced Request that properly handles SvelteKit's usage patterns
11
- class EnhancedRequest extends OriginalRequest {
12
- constructor(input, init) {
13
- // Handle the case where SvelteKit passes a string URL
14
- if (typeof input === 'string') {
15
- try {
16
- super(input, init);
17
- } catch (e) {
18
- // If it fails, it might be a relative URL - try to resolve it
19
- if (globalThis.location && e.message && e.message.includes('relative')) {
20
- try {
21
- const absoluteUrl = new URL(input, globalThis.location.href);
22
- super(absoluteUrl.href, init);
23
- } catch (e2) {
24
- // If that also fails, throw the original error
25
- throw e;
26
- }
27
- } else {
28
- throw e;
29
- }
30
- }
31
- return;
32
- }
33
-
34
- // Handle plain objects with url property (SvelteKit sometimes does this)
35
- if (input && typeof input === 'object' && !(input instanceof OriginalRequest)) {
36
- // Extract URL from the object
37
- const url = input.url || input.href || input.toString();
38
- if (!url) {
39
- throw new TypeError('Request must have a URL');
40
- }
41
-
42
- // Build init options from the object
43
- const newInit = {
44
- method: input.method || init?.method || 'GET',
45
- headers: input.headers || init?.headers,
46
- body: input.body || init?.body,
47
- mode: input.mode || init?.mode,
48
- credentials: input.credentials || init?.credentials,
49
- cache: input.cache || init?.cache,
50
- redirect: input.redirect || init?.redirect,
51
- referrer: input.referrer || init?.referrer,
52
- referrerPolicy: input.referrerPolicy || init?.referrerPolicy,
53
- integrity: input.integrity || init?.integrity,
54
- keepalive: input.keepalive || init?.keepalive,
55
- signal: input.signal || init?.signal,
56
- ...init
57
- };
58
-
59
- // Create the Request with the extracted URL
60
- super(url, newInit);
61
- return;
62
- }
63
-
64
- // Otherwise use the original constructor normally
65
- super(input, init);
66
- }
67
- }
68
-
69
- // Replace global Request with our enhanced version
70
- globalThis.Request = EnhancedRequest;
71
-
72
- // Create an enhanced fetch that handles relative URLs and special cases
73
- globalThis.fetch = function enhancedFetch(input, init) {
74
- // Convert input to a Request if needed
75
- let request;
76
-
77
- if (input instanceof Request) {
78
- request = input;
79
- } else if (typeof input === 'string') {
80
- // Check if it's already absolute
81
- if (input.startsWith('http://') || input.startsWith('https://')) {
82
- request = new Request(input, init);
83
- } else if (globalThis.location) {
84
- // It's relative - resolve it
85
- try {
86
- const absoluteUrl = new URL(input, globalThis.location.href);
87
- request = new Request(absoluteUrl.href, init);
88
- } catch (e) {
89
- console.error('Failed to resolve relative URL:', input, 'against', globalThis.location.href);
90
- throw e;
91
- }
92
- } else {
93
- console.error('Cannot resolve relative URL without globalThis.location:', input);
94
- throw new Error('Cannot resolve relative URL without a base URL');
95
- }
96
- } else if (input && typeof input === 'object') {
97
- // Handle plain objects by converting to Request
98
- request = new Request(input, init);
99
- } else {
100
- throw new TypeError('First argument must be a string, Request, or URL');
101
- }
102
-
103
- // Call the original fetch with the normalized request
104
- return originalFetch(request);
105
- };
106
-
107
- // Import SvelteKit server - these will be replaced by esbuild
108
- import { Server } from '__SERVER__';
109
- import { manifest, prerendered, base } from '__MANIFEST__';
110
-
111
- // Initialize the SvelteKit server
112
- const server = new Server(manifest);
113
-
114
- // Initialize server with platform-specific read function
115
- const initialized = server.init({
116
- env: globalThis.platform?.env || {},
117
- read: async (file) => {
118
- // For now, return empty stream for any file read attempts
119
- // This is a placeholder until we implement proper static file serving
120
- // console.log('Read function called for file:', file);
121
-
122
- // Return an empty ReadableStream to prevent errors
123
- return new ReadableStream({
124
- start(controller) {
125
- // Just close the stream immediately
126
- controller.close();
127
- }
128
- });
129
- }
130
- });
131
-
132
- /**
133
- * Main request handler for the Maravilla runtime
134
- * This function is called by the runtime for each incoming request
135
- */
136
- async function handleRequest(request) {
137
- // Apply our fetch/Request overrides when first called
138
- if (globalThis.Request !== EnhancedRequest) {
139
- // console.log('Applying EnhancedRequest override');
140
- globalThis.Request = EnhancedRequest;
141
- globalThis.fetch = enhancedFetch;
142
- }
143
- // Ensure server is initialized
144
- await initialized;
145
-
146
- // The runtime should have already set globalThis.location by now
147
- // Log it for debugging
148
- if (globalThis.location) {
149
- // console.log('globalThis.location is available:', globalThis.location.origin);
150
- } else {
151
- console.warn('WARNING: globalThis.location not set by runtime - this may cause URL resolution issues');
152
- }
153
-
154
- // Check if request is already a Web API Request object
155
- let webRequest;
156
- if (request instanceof Request) {
157
- // It's already a proper Request object from the runtime
158
- // console.log('Request is already a Web API Request object');
159
- webRequest = request;
160
- } else {
161
- // It's a plain object, convert it to a Request (fallback for older runtime)
162
- // console.log('Converting plain object to Request');
163
- const url = new URL(request.url, 'http://localhost');
164
-
165
- // Prepare the body - handle different types
166
- let requestBody = undefined;
167
- if (request.body !== null && request.body !== undefined) {
168
- // If body is already a string, use it directly
169
- if (typeof request.body === 'string') {
170
- requestBody = request.body;
171
- } else {
172
- // Otherwise stringify it
173
- requestBody = JSON.stringify(request.body);
174
- }
175
- }
176
-
177
- // Create a standard Request object
178
- webRequest = new Request(url.toString(), {
179
- method: request.method,
180
- headers: request.headers || {},
181
- body: requestBody
182
- });
183
- }
184
-
185
- // Check if this is a static asset request
186
- // Use a base URL to avoid "relative URL without a base" errors
187
- const requestUrl = new URL(webRequest.url, webRequest.url.startsWith('http') ? undefined : 'http://localhost');
188
- const pathname = requestUrl.pathname;
189
- const stripped_pathname = pathname.replace(/\\/$/, '');
190
-
191
- // Debug: verify URL.pathname setter works for data requests
192
- if (pathname.endsWith('/__data.json') || pathname.endsWith('.html__data.json')) {
193
- try {
194
- const test = new URL(webRequest.url, webRequest.url.startsWith('http') ? undefined : 'http://localhost');
195
- const before = test.pathname;
196
- const candidate = pathname.endsWith('/__data.json')
197
- ? pathname.slice(0, -'/__data.json'.length)
198
- : pathname.slice(0, -'.html__data.json'.length) + '.html';
199
- test.pathname = candidate;
200
- // console.log('Data URL normalization test', { before, candidate, after: test.pathname, href: test.href });
201
- } catch (e) {
202
- console.error('Data URL normalization error', e);
203
- }
204
- }
205
-
206
- // Check if path is prerendered
207
- if (prerendered.has(pathname)) {
208
- // For prerendered pages, we could serve from static storage
209
- // but for now, let SvelteKit handle it
210
- }
211
-
212
- // Handle trailing slash redirects for prerendered pages
213
- const location = pathname.at(-1) === '/' ? stripped_pathname : pathname + '/';
214
- if (location && prerendered.has(location)) {
215
- const urlObj = new URL(webRequest.url, webRequest.url.startsWith('http') ? undefined : 'http://localhost');
216
- return new Response('', {
217
- status: 308,
218
- headers: {
219
- location: location + urlObj.search
220
- }
221
- });
222
- }
223
-
224
- // Let SvelteKit handle the request
225
- try {
226
- // console.log('SvelteKit server.respond called with:', {
227
- // url: webRequest.url,
228
- // method: webRequest.method,
229
- // hasBody: webRequest.body !== null,
230
- // platform: {
231
- // hasEnv: !!globalThis.platform?.env,
232
- // hasKv: !!globalThis.platform?.kv,
233
- // hasDb: !!globalThis.platform?.db
234
- // }
235
- // });
236
-
237
- const response = await server.respond(webRequest, {
238
- platform: {
239
- // Expose Maravilla platform APIs to SvelteKit
240
- env: globalThis.platform?.env || {},
241
- context: {
242
- waitUntil: (promise) => {
243
- // In Maravilla, we can queue background work
244
- if (globalThis.platform?.queue) {
245
- globalThis.platform.queue.send({ type: 'background', promise });
246
- }
247
- },
248
- passThroughOnException: () => {
249
- // Not applicable in Maravilla runtime
250
- }
251
- },
252
- // Expose platform services
253
- kv: globalThis.platform?.kv,
254
- db: globalThis.platform?.db,
255
- storage: globalThis.platform?.storage,
256
- queue: globalThis.platform?.queue
257
- },
258
- getClientAddress: () => {
259
- // Get client IP from request headers
260
- const forwarded = webRequest.headers.get('x-forwarded-for');
261
- if (forwarded) {
262
- return forwarded.split(',')[0].trim();
263
- }
264
- // Fallback for plain object format (shouldn't happen with proper Request)
265
- return request.headers?.['x-real-ip'] || '127.0.0.1';
266
- }
267
- });
268
-
269
- // Log response details
270
- if (response.status >= 400) {
271
- console.error('SvelteKit returned error:', {
272
- status: response.status,
273
- statusText: response.statusText,
274
- url: webRequest.url
275
- });
276
- }
277
-
278
- // Return the response in a format the runtime expects
279
- return response;
280
- } catch (error) {
281
- console.error('Error in server.respond:', error);
282
- console.error('Error stack:', error.stack);
283
- throw error;
284
- }
285
- }
286
-
287
- // Export for the Maravilla runtime
288
- globalThis.handleRequest = handleRequest;
289
- `;
290
- //# sourceMappingURL=worker-template.js.map