@techinject/sveltekit-server 0.0.0-stage → 0.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +10 -2
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SignalKit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @techinject/sveltekit-server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Unpublished alpha Node adapter for SvelteKit 3. createSvelteKitHooks(getConfig) returns handle and handleFetch for hooks.server.ts. Supply a config factory using the actual request's host policy/consent. Return fresh observers/providers per request: the adapter flushes bounded work and disposes them when resolve completes. Do not return a shared disposable collector or mutate global consent.
|
|
4
|
+
|
|
5
|
+
handle uses event.route.id for route templates, preserves resolve responses/errors, and isolates request context with AsyncLocalStorage. handleFetch wraps SvelteKit's supplied fetch instead of substituting global fetch, retaining its cookie/internal-route semantics and correlating outgoing records. When invoked outside an active handle scope, it passes through. Compose authentication first using SvelteKit sequence; compose any other handleFetch hook inside the supplied transport.
|
|
6
|
+
|
|
7
|
+
Node only. Prerender/static assets and platform requests outside SvelteKit's handle pipeline are not incoming API coverage. Supply a denied policy during prerender/build if appropriate. Unknown routes use existing safeRoute heuristics; avoid sensitive slugs and use exclusions. Flush adds bounded telemetry wait to the response; set timeoutMs and maxPending for your host budget. Streaming/background work after resolve is outside this request's lifecycle. No durable retry or automatic purchase verification.
|
|
8
|
+
|
|
9
|
+
See [integration reference](../INTEGRATION.md) and [SvelteKit lab](../../../../examples/sveltekit/README.md). Peer framework: SvelteKit >=3 <4. Browser package remains separate; no server import belongs in a client component.
|
|
10
|
+
|
|
11
|
+
A throwing/rejected config factory disables telemetry for that resolve scope and passes through to the host. Authenticate/authorize in a separate earlier hook; never use the telemetry config callback as an access-control gate.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RequestEvent } from '@sveltejs/kit';
|
|
2
|
+
import type { Handle, HandleFetch } from '@sveltejs/kit/hooks';
|
|
3
|
+
import { type ServerConfig } from '@techinject/server';
|
|
4
|
+
/** Node runtime only. Return fresh observer/provider instances for each request. */
|
|
5
|
+
export declare function createSvelteKitHooks(getConfig: (event: RequestEvent) => ServerConfig | Promise<ServerConfig>): {
|
|
6
|
+
handle: Handle;
|
|
7
|
+
handleFetch: HandleFetch;
|
|
8
|
+
};
|
|
9
|
+
export { createOTLPObserver } from '@techinject/server';
|
|
10
|
+
export type { ServerConfig } from '@techinject/server';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAuB,KAAK,YAAY,EAAsB,MAAM,oBAAoB,CAAC;AAEhG,oFAAoF;AACpF,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,GACvE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,WAAW,CAAA;CAAE,CA6C9C;AACD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { createServerSignals } from '@techinject/server';
|
|
3
|
+
/** Node runtime only. Return fresh observer/provider instances for each request. */
|
|
4
|
+
export function createSvelteKitHooks(getConfig) {
|
|
5
|
+
const active = new AsyncLocalStorage();
|
|
6
|
+
const handle = async ({ event, resolve }) => {
|
|
7
|
+
let config;
|
|
8
|
+
let signals;
|
|
9
|
+
try {
|
|
10
|
+
config = await getConfig(event);
|
|
11
|
+
signals = createServerSignals(config);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
// Fail closed for telemetry, without inheriting a parent request's policy.
|
|
15
|
+
return active.exit(() => resolve(event));
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
return await active.run(signals, () => signals.handle(event.request, () => resolve(event), {
|
|
19
|
+
route: event.route.id ?? undefined,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
// A host observer flush can hang; never let it hold a response forever.
|
|
24
|
+
const timeout = Number.isFinite(config.timeoutMs)
|
|
25
|
+
? Math.max(1, Math.min(30000, config.timeoutMs))
|
|
26
|
+
: 2000;
|
|
27
|
+
let timer;
|
|
28
|
+
try {
|
|
29
|
+
await Promise.race([
|
|
30
|
+
signals.flush(),
|
|
31
|
+
new Promise((resolve) => {
|
|
32
|
+
timer = setTimeout(resolve, timeout);
|
|
33
|
+
}),
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
/* telemetry must not replace a host response/error */
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
if (timer)
|
|
41
|
+
clearTimeout(timer);
|
|
42
|
+
signals.dispose();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const handleFetch = ({ request, fetch }) => {
|
|
47
|
+
const signals = active.getStore();
|
|
48
|
+
// Preserve SvelteKit's fetch (cookies, internal routes, SSR response handling).
|
|
49
|
+
return signals ? signals.wrapFetch(fetch)(request) : fetch(request);
|
|
50
|
+
};
|
|
51
|
+
return { handle, handleFetch };
|
|
52
|
+
}
|
|
53
|
+
export { createOTLPObserver } from '@techinject/server';
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAAE,mBAAmB,EAAyC,MAAM,oBAAoB,CAAC;AAEhG,oFAAoF;AACpF,MAAM,UAAU,oBAAoB,CAClC,SAAwE;IAExE,MAAM,MAAM,GAAG,IAAI,iBAAiB,EAAiB,CAAC;IACtD,MAAM,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C;oBAAS,CAAC;gBACT,IAAI,KAAK;oBAAE,YAAY,CAAC,KAAK,CAAC,CAAC;gBAC/B,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IACF,MAAM,WAAW,GAAgB,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE;QACtD,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QAClC,gFAAgF;QAChF,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACtE,CAAC,CAAC;IACF,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;AACjC,CAAC;AACD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@techinject/sveltekit-server",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-alpha.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"LICENSE",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@techinject/server": "0.1.0-alpha.2"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/TechInjectIndia/signal-kit.git",
|
|
23
|
+
"directory": "packages/features/signals/sveltekit-server"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22"
|
|
30
|
+
},
|
|
31
|
+
"description": "SignalKit SvelteKit Node request hooks adapter",
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@sveltejs/kit": ">=3 <4"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@sveltejs/kit": "3.0.1",
|
|
37
|
+
"svelte": "5.57.2",
|
|
38
|
+
"vite": "8.3.4",
|
|
39
|
+
"@sveltejs/vite-plugin-svelte": "7.3.1",
|
|
40
|
+
"typescript": "6.0.3"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc -p tsconfig.json",
|
|
44
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"lint": "tsc -p tsconfig.json --noEmit"
|
|
47
|
+
}
|
|
6
48
|
}
|