@qelos/global-types 3.11.11 → 4.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/index.ts +2 -1
- package/package.json +1 -1
- package/qelos-integrator.ts +124 -0
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared contracts every Qelos framework integrator (`@qelos/integrator-*`)
|
|
3
|
+
* builds upon. Defined here — rather than in each integrator — so the
|
|
4
|
+
* per-request shape and configuration surface are guaranteed identical across
|
|
5
|
+
* frameworks.
|
|
6
|
+
*
|
|
7
|
+
* `@qelos/sdk` depends on `@qelos/global-types`, so this file deliberately
|
|
8
|
+
* avoids importing from the SDK; instead, {@link QelosContext} is generic over
|
|
9
|
+
* the SDK instance type and integrators specialize it with the concrete
|
|
10
|
+
* `QelosSDK` / `IUser` / `IWorkspace` types from `@qelos/sdk`.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Tokens read from an inbound request. Integrators mutate this object in place
|
|
15
|
+
* when a refresh occurs so later code can read the current pair.
|
|
16
|
+
*/
|
|
17
|
+
export interface QelosTokenPair {
|
|
18
|
+
accessToken?: string;
|
|
19
|
+
refreshToken?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Result of a successful token refresh.
|
|
24
|
+
*/
|
|
25
|
+
export interface ResolvedTokens {
|
|
26
|
+
accessToken: string;
|
|
27
|
+
refreshToken?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Minimal user contract shared by all integrators. The SDK's `IUser` (rich,
|
|
32
|
+
* with first/last name, metadata, etc.) is assignable to this and is what
|
|
33
|
+
* integrators actually plug in via the `TUser` parameter on
|
|
34
|
+
* {@link QelosContext}.
|
|
35
|
+
*/
|
|
36
|
+
export interface IQelosUser {
|
|
37
|
+
_id: string;
|
|
38
|
+
username: string;
|
|
39
|
+
email: string;
|
|
40
|
+
roles: string[];
|
|
41
|
+
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Minimal workspace contract shared by all integrators. The SDK's `IWorkspace`
|
|
47
|
+
* is assignable to this.
|
|
48
|
+
*/
|
|
49
|
+
export interface IQelosWorkspace {
|
|
50
|
+
name: string;
|
|
51
|
+
|
|
52
|
+
[key: string]: any;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Base configuration contract every framework integrator builds upon.
|
|
57
|
+
* Framework-specific configs (e.g. `QelosExpressConfig`, `QelosNextConfig`)
|
|
58
|
+
* extend this with transport-specific options such as `sdkOptions`.
|
|
59
|
+
*/
|
|
60
|
+
export interface QelosConfig {
|
|
61
|
+
/**
|
|
62
|
+
* Base URL of the Qelos backend (e.g. https://yourdomain.com).
|
|
63
|
+
*/
|
|
64
|
+
appUrl: string;
|
|
65
|
+
/**
|
|
66
|
+
* Static API token used for service-to-service calls. When provided, no
|
|
67
|
+
* cookie/refresh-token handling is performed.
|
|
68
|
+
*/
|
|
69
|
+
apiToken?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Cookie name carrying the Qelos access token. Defaults to `q_access_token`.
|
|
72
|
+
*/
|
|
73
|
+
accessTokenCookie?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Cookie name carrying the Qelos refresh token. Defaults to `q_refresh_token`.
|
|
76
|
+
*/
|
|
77
|
+
refreshTokenCookie?: string;
|
|
78
|
+
/**
|
|
79
|
+
* If true, the integrator rejects requests (401) when the user cannot be
|
|
80
|
+
* resolved. Defaults to `false` — anonymous requests pass through with
|
|
81
|
+
* `qelos.user = null`.
|
|
82
|
+
*/
|
|
83
|
+
requireAuth?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Skip the integrator entirely for requests whose path starts with any of
|
|
86
|
+
* these prefixes. Useful for `/health`, `/_next`, `/api/_auth`, etc.
|
|
87
|
+
*/
|
|
88
|
+
skipPaths?: string[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Per-request Qelos context every integrator produces. Generic over the SDK
|
|
93
|
+
* instance type and the user/workspace shape so framework integrators narrow
|
|
94
|
+
* these to the SDK's concrete types (`QelosSDK`, `IUser`, `IWorkspace`)
|
|
95
|
+
* without dragging the SDK into `@qelos/global-types`.
|
|
96
|
+
*/
|
|
97
|
+
export interface QelosContext<
|
|
98
|
+
TSdk = unknown,
|
|
99
|
+
TUser extends IQelosUser = IQelosUser,
|
|
100
|
+
TWorkspace extends IQelosWorkspace = IQelosWorkspace,
|
|
101
|
+
> {
|
|
102
|
+
/**
|
|
103
|
+
* The authenticated user, or `null` when anonymous.
|
|
104
|
+
*/
|
|
105
|
+
user: TUser | null;
|
|
106
|
+
/**
|
|
107
|
+
* The active workspace for the request, or `null` when none is active /
|
|
108
|
+
* the user is anonymous.
|
|
109
|
+
*/
|
|
110
|
+
workspace: TWorkspace | null;
|
|
111
|
+
/**
|
|
112
|
+
* The full list of workspaces the user has access to.
|
|
113
|
+
*/
|
|
114
|
+
workspaces: TWorkspace[];
|
|
115
|
+
/**
|
|
116
|
+
* SDK instance bound to the current request's tokens.
|
|
117
|
+
*/
|
|
118
|
+
sdk: TSdk;
|
|
119
|
+
/**
|
|
120
|
+
* Tokens read from the request. Mutated in place when a refresh occurs so
|
|
121
|
+
* later code can read the current pair.
|
|
122
|
+
*/
|
|
123
|
+
tokens: QelosTokenPair;
|
|
124
|
+
}
|