@kurdel/common 0.1.0-beta.1
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 +24 -0
- package/lib/auth-user.d.ts +34 -0
- package/lib/auth-user.js +2 -0
- package/lib/auth-user.js.map +1 -0
- package/lib/http-response-extended.d.ts +13 -0
- package/lib/http-response-extended.js +2 -0
- package/lib/http-response-extended.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -0
- package/lib/interfaces.d.ts +28 -0
- package/lib/interfaces.js +2 -0
- package/lib/interfaces.js.map +1 -0
- package/lib/json-loader.d.ts +3 -0
- package/lib/json-loader.js +15 -0
- package/lib/json-loader.js.map +1 -0
- package/lib/types.d.ts +1 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/lib/url.d.ts +11 -0
- package/lib/url.js +27 -0
- package/lib/url.js.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Andrii Sorokin
|
|
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
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @kurdel/common
|
|
2
|
+
|
|
3
|
+
Shared TypeScript types, interfaces, and utilities used by Kurdel packages.
|
|
4
|
+
Application code normally receives this package transitively through the
|
|
5
|
+
framework packages that depend on it.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @kurdel/common@beta
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Exports
|
|
14
|
+
|
|
15
|
+
The package exposes common HTTP types, authentication user contracts, JSON
|
|
16
|
+
loading helpers, and URL utilities from its main entry point.
|
|
17
|
+
|
|
18
|
+
## Requirements
|
|
19
|
+
|
|
20
|
+
Node.js 20.19+, 22.12+, or 24+.
|
|
21
|
+
|
|
22
|
+
## License
|
|
23
|
+
|
|
24
|
+
MIT © Andrii Sorokin
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## AuthUser
|
|
3
|
+
*
|
|
4
|
+
* Unified representation of an authenticated identity within the Kurdel runtime.
|
|
5
|
+
*
|
|
6
|
+
* Produced exclusively by authentication strategies.
|
|
7
|
+
* Used later by authorization middleware to determine access rights.
|
|
8
|
+
*
|
|
9
|
+
* Properties:
|
|
10
|
+
* - `id` — public stable identity of the user (string or number).
|
|
11
|
+
* - `roles` — zero or more logical roles (e.g., `"admin"`, `"user"`, `"system"`).
|
|
12
|
+
* - Additional fields may be attached by strategies (JWT payload, profile data, etc.).
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* The runtime never interprets extra properties — they are passed through
|
|
16
|
+
* transparently and may be used by controllers or custom middleware.
|
|
17
|
+
*/
|
|
18
|
+
export interface AuthUser {
|
|
19
|
+
id: string | number;
|
|
20
|
+
roles: string[];
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** Metadata about the credential used for the current authentication. */
|
|
24
|
+
export interface AuthCredential {
|
|
25
|
+
type: string;
|
|
26
|
+
id?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Authentication state attached to a request after a strategy succeeds. */
|
|
29
|
+
export interface AuthContext<TUser extends AuthUser = AuthUser> {
|
|
30
|
+
user: TUser;
|
|
31
|
+
strategy: string;
|
|
32
|
+
credential?: AuthCredential;
|
|
33
|
+
claims?: Record<string, unknown>;
|
|
34
|
+
}
|
package/lib/auth-user.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-user.js","sourceRoot":"","sources":["../src/auth-user.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HttpResponse } from './interfaces.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extended interface for platform adapters (Node, Express, etc.)
|
|
4
|
+
* that expose header manipulation methods.
|
|
5
|
+
*/
|
|
6
|
+
export interface HttpResponseWithHeaders extends HttpResponse {
|
|
7
|
+
/** Set a response header (platform-specific) */
|
|
8
|
+
setHeader(name: string, value: string): void;
|
|
9
|
+
/** Retrieve a response header */
|
|
10
|
+
getHeader(name: string): string | undefined;
|
|
11
|
+
/** Optional shorthand for MIME type */
|
|
12
|
+
type?(mime: string): this;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-response-extended.js","sourceRoot":"","sources":["../src/http-response-extended.ts"],"names":[],"mappings":""}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** A minimal, platform-independent HTTP request abstraction. */
|
|
2
|
+
export interface HttpRequest {
|
|
3
|
+
method: string;
|
|
4
|
+
url: string;
|
|
5
|
+
headers?: Record<string, string | string[]>;
|
|
6
|
+
body?: unknown;
|
|
7
|
+
query: Record<string, string | string[]>;
|
|
8
|
+
params?: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
/** A minimal, platform-independent HTTP response abstraction. */
|
|
11
|
+
export interface HttpResponse {
|
|
12
|
+
/** Sends a complete response body (string, Buffer, or object). */
|
|
13
|
+
send(body?: any): void;
|
|
14
|
+
/** Sends a JSON response with correct content type. */
|
|
15
|
+
json(body: unknown): void;
|
|
16
|
+
/** Sets the HTTP status code. */
|
|
17
|
+
status(code: number): this;
|
|
18
|
+
/** Optional shorthand for redirection. */
|
|
19
|
+
redirect(status: number, location: string): void;
|
|
20
|
+
/** Write a data chunk to the response stream. */
|
|
21
|
+
write?(chunk: any): void;
|
|
22
|
+
/** End the response stream (optional final data chunk). */
|
|
23
|
+
end?(chunk?: any): void;
|
|
24
|
+
/** Marks the response as already sent. */
|
|
25
|
+
sent: boolean;
|
|
26
|
+
/** Underlying native platform response (optional). */
|
|
27
|
+
raw?: unknown;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
export class JSONLoader {
|
|
3
|
+
load(filePath) {
|
|
4
|
+
try {
|
|
5
|
+
const rawData = fs.readFileSync(filePath, 'utf8');
|
|
6
|
+
const config = JSON.parse(rawData);
|
|
7
|
+
return config;
|
|
8
|
+
}
|
|
9
|
+
catch (err) {
|
|
10
|
+
console.error(`Error reading config file: ${err}`);
|
|
11
|
+
throw new Error(`Failed to read config file: ${filePath}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=json-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-loader.js","sourceRoot":"","sources":["../src/json-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,OAAO,UAAU;IACrB,IAAI,CAAC,QAAgB;QACnB,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAClD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACnC,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,8BAA8B,GAAG,EAAE,CAAC,CAAC;YACnD,MAAM,IAAI,KAAK,CAAC,+BAA+B,QAAQ,EAAE,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;CACF"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Newable<T> = new (...args: any[]) => T;
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/lib/url.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Default base used when constructing internal URLs. */
|
|
2
|
+
export declare const DEFAULT_INTERNAL_BASE = "http://internal";
|
|
3
|
+
/** Key → string or array of strings (for repeated query params). */
|
|
4
|
+
export type QueryMap = Record<string, string | string[]>;
|
|
5
|
+
/**
|
|
6
|
+
* Build a URL from a string path or an existing URL.
|
|
7
|
+
* Never reads Node.js request types; pure and platform-agnostic.
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildURL(input: string | URL, base?: string): URL;
|
|
10
|
+
/** Convert URLSearchParams into a multi-value map. */
|
|
11
|
+
export declare function toQuery(u: URL): QueryMap;
|
package/lib/url.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Default base used when constructing internal URLs. */
|
|
2
|
+
export const DEFAULT_INTERNAL_BASE = 'http://internal';
|
|
3
|
+
/**
|
|
4
|
+
* Build a URL from a string path or an existing URL.
|
|
5
|
+
* Never reads Node.js request types; pure and platform-agnostic.
|
|
6
|
+
*/
|
|
7
|
+
export function buildURL(input, base = DEFAULT_INTERNAL_BASE) {
|
|
8
|
+
if (input instanceof URL)
|
|
9
|
+
return input;
|
|
10
|
+
const path = input || '/';
|
|
11
|
+
return new URL(path, base);
|
|
12
|
+
}
|
|
13
|
+
/** Convert URLSearchParams into a multi-value map. */
|
|
14
|
+
export function toQuery(u) {
|
|
15
|
+
const out = {};
|
|
16
|
+
u.searchParams.forEach((value, key) => {
|
|
17
|
+
if (key in out) {
|
|
18
|
+
const prev = out[key];
|
|
19
|
+
out[key] = Array.isArray(prev) ? [...prev, value] : [prev, value];
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
out[key] = value;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=url.js.map
|
package/lib/url.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.js","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAC;AAKvD;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAmB,EAAE,OAAe,qBAAqB;IAChF,IAAI,KAAK,YAAY,GAAG;QAAE,OAAO,KAAK,CAAC;IACvC,MAAM,IAAI,GAAG,KAAK,IAAI,GAAG,CAAC;IAC1B,OAAO,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,OAAO,CAAC,CAAM;IAC5B,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACpC,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;YACf,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;YACtB,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAc,EAAE,KAAK,CAAC,CAAC;QAC9E,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kurdel/common",
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"description": "Shared types and utilities for Kurdel packages",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./lib/index.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "./lib/index.js",
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"lib"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"prepack": "npm run build",
|
|
16
|
+
"test": "echo \"No tests yet\"",
|
|
17
|
+
"clean": "rimraf lib ../../.cache/tsconfig.common.build.tsbuildinfo",
|
|
18
|
+
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
19
|
+
"build:force": "npm run clean && tsc -p tsconfig.build.json --force && tsc-alias -p tsconfig.build.json"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"kurdel",
|
|
23
|
+
"framework",
|
|
24
|
+
"utilities",
|
|
25
|
+
"typescript"
|
|
26
|
+
],
|
|
27
|
+
"author": "Andrii Sorokin",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/ignorantic/kurdel.git",
|
|
35
|
+
"directory": "packages/common"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/ignorantic/kurdel/tree/main/packages/common#readme",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/ignorantic/kurdel/issues"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public",
|
|
43
|
+
"tag": "beta"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^20.9.0",
|
|
47
|
+
"rimraf": "^3.0.2",
|
|
48
|
+
"tsc-alias": "^1.8.16"
|
|
49
|
+
}
|
|
50
|
+
}
|