@norbix.ai/ts 1.0.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 +628 -0
- package/dist/api/index.cjs +1104 -0
- package/dist/api/index.cjs.map +1 -0
- package/dist/api/index.d.cts +3 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +1102 -0
- package/dist/api/index.js.map +1 -0
- package/dist/hub/index.cjs +5854 -0
- package/dist/hub/index.cjs.map +1 -0
- package/dist/hub/index.d.cts +2174 -0
- package/dist/hub/index.d.ts +2174 -0
- package/dist/hub/index.js +5852 -0
- package/dist/hub/index.js.map +1 -0
- package/dist/index-BARFtiR-.d.cts +459 -0
- package/dist/index-t6pXnReB.d.ts +459 -0
- package/dist/index.cjs +7628 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +225 -0
- package/dist/index.d.ts +225 -0
- package/dist/index.js +7619 -0
- package/dist/index.js.map +1 -0
- package/dist/transport-c4_dsqN0.d.cts +269 -0
- package/dist/transport-c4_dsqN0.d.ts +269 -0
- package/dist/types/api2.dtos.cjs +3802 -0
- package/dist/types/api2.dtos.cjs.map +1 -0
- package/dist/types/api2.dtos.d.cts +2055 -0
- package/dist/types/api2.dtos.d.ts +2055 -0
- package/dist/types/api2.dtos.js +3802 -0
- package/dist/types/api2.dtos.js.map +1 -0
- package/dist/types/hub2.dtos.cjs +19537 -0
- package/dist/types/hub2.dtos.cjs.map +1 -0
- package/dist/types/hub2.dtos.d.cts +10399 -0
- package/dist/types/hub2.dtos.d.ts +10399 -0
- package/dist/types/hub2.dtos.js +19537 -0
- package/dist/types/hub2.dtos.js.map +1 -0
- package/package.json +112 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the Norbix client.
|
|
3
|
+
*
|
|
4
|
+
* Auth modes:
|
|
5
|
+
* - **API key** — long-lived, server-side. Set `apiKey` in code or
|
|
6
|
+
* `NORBIX_API_KEY` in the environment. Acts as a service identity.
|
|
7
|
+
* - **JWT bearer** — short-lived, on behalf of a user. Set `bearerToken`
|
|
8
|
+
* directly, or call `norbix.login(...)` to exchange credentials for one.
|
|
9
|
+
*
|
|
10
|
+
* If both are configured, the bearer token wins (most specific wins). If
|
|
11
|
+
* neither is set at construction, you must call `login()` before making any
|
|
12
|
+
* other call — otherwise the first request throws.
|
|
13
|
+
*
|
|
14
|
+
* Scoping rule:
|
|
15
|
+
* - `projectId` is required (or `NORBIX_PROJECT_ID` env var).
|
|
16
|
+
* - `accountId` is optional. When set, account-scoped Hub endpoints
|
|
17
|
+
* (team invite, billing portal, account verify, ...) become callable.
|
|
18
|
+
*
|
|
19
|
+
* Env vars (Node only — silently ignored in the browser):
|
|
20
|
+
* NORBIX_API_KEY
|
|
21
|
+
* NORBIX_BEARER_TOKEN
|
|
22
|
+
* NORBIX_PROJECT_ID
|
|
23
|
+
* NORBIX_ACCOUNT_ID
|
|
24
|
+
* NORBIX_REGION
|
|
25
|
+
* NORBIX_API_URL
|
|
26
|
+
* NORBIX_HUB_URL
|
|
27
|
+
* NORBIX_API_VERSION
|
|
28
|
+
* NORBIX_HUB_VERSION
|
|
29
|
+
* NORBIX_TIMEOUT_MS
|
|
30
|
+
*/
|
|
31
|
+
interface NorbixConfig {
|
|
32
|
+
/**
|
|
33
|
+
* Long-lived API key, typically used for service-to-service calls. The SDK
|
|
34
|
+
* sends it as `Authorization: Bearer <apiKey>` until a JWT bearer token
|
|
35
|
+
* takes over (set explicitly or via `login`). Falls back to `NORBIX_API_KEY`.
|
|
36
|
+
*/
|
|
37
|
+
apiKey?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Short-lived JWT bearer token, typically obtained from a login flow.
|
|
40
|
+
* Takes precedence over `apiKey` when both are set. Falls back to
|
|
41
|
+
* `NORBIX_BEARER_TOKEN`.
|
|
42
|
+
*/
|
|
43
|
+
bearerToken?: string;
|
|
44
|
+
/** Project the SDK operates against. Falls back to `NORBIX_PROJECT_ID`. */
|
|
45
|
+
projectId?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Optional account ID. Required for Hub account-scoped endpoints
|
|
48
|
+
* (team, billing, account profile). Falls back to `NORBIX_ACCOUNT_ID`.
|
|
49
|
+
*/
|
|
50
|
+
accountId?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Project environment every request targets, sent as the `norbix-env`
|
|
53
|
+
* header. Each project owns a set of named environments; `PROD` always
|
|
54
|
+
* exists and is the default. A non-PROD env (e.g. `TEST`, `STAGING`) scopes
|
|
55
|
+
* every read and write to that environment's integrations — there is no
|
|
56
|
+
* cross-env fallback. Defaults to `PROD`. Falls back to `NORBIX_ENV`.
|
|
57
|
+
*
|
|
58
|
+
* Override per call via the `env` option on any request, or switch the
|
|
59
|
+
* client default at runtime with `setEnv(...)`.
|
|
60
|
+
*/
|
|
61
|
+
env?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Norbix region every request targets, sent as the `nb-region` header
|
|
64
|
+
* (a region code, e.g. `nb-eu-germany`). Unlike `env`, there is no default
|
|
65
|
+
* region — when unset, no header is sent and the backend picks the project's
|
|
66
|
+
* primary region. Falls back to `NORBIX_REGION`.
|
|
67
|
+
*
|
|
68
|
+
* When the client uses the SDK's default base URLs, setting a region also
|
|
69
|
+
* composes the regional URL (`https://nb-eu-germany.api.norbix.dev`); a
|
|
70
|
+
* user-supplied custom `baseUrl` is never rewritten.
|
|
71
|
+
*
|
|
72
|
+
* Override per call via the `region` option on any request (header only —
|
|
73
|
+
* never changes the URL), or switch the client default at runtime with
|
|
74
|
+
* `setRegion(...)`.
|
|
75
|
+
*/
|
|
76
|
+
region?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Override default base URLs. Useful for self-hosted deployments,
|
|
79
|
+
* staging environments, or pointing the SDK at localhost in tests.
|
|
80
|
+
* Each URL falls back to its env var (`NORBIX_API_URL`, `NORBIX_HUB_URL`).
|
|
81
|
+
*/
|
|
82
|
+
baseUrl?: {
|
|
83
|
+
api?: string;
|
|
84
|
+
hub?: string;
|
|
85
|
+
};
|
|
86
|
+
/** API version segment used in `{version}` route tokens. Defaults to `v2`. */
|
|
87
|
+
apiVersion?: string;
|
|
88
|
+
hubVersion?: string;
|
|
89
|
+
/** Request timeout in milliseconds. Defaults to 30_000. */
|
|
90
|
+
timeoutMs?: number;
|
|
91
|
+
/**
|
|
92
|
+
* Optional fetch implementation. Useful for testing (`vi.fn()`) or for
|
|
93
|
+
* environments where global `fetch` is unavailable.
|
|
94
|
+
*/
|
|
95
|
+
fetch?: typeof globalThis.fetch;
|
|
96
|
+
/** Extra headers attached to every request. */
|
|
97
|
+
defaultHeaders?: Record<string, string>;
|
|
98
|
+
/** Hook called once per request before it is sent. */
|
|
99
|
+
onRequest?: (info: {
|
|
100
|
+
url: string;
|
|
101
|
+
method: string;
|
|
102
|
+
headers: Headers;
|
|
103
|
+
}) => void;
|
|
104
|
+
/** Hook called once per response, regardless of success/failure. */
|
|
105
|
+
onResponse?: (info: {
|
|
106
|
+
url: string;
|
|
107
|
+
status: number;
|
|
108
|
+
durationMs: number;
|
|
109
|
+
}) => void;
|
|
110
|
+
/**
|
|
111
|
+
* Transport retry policy for transient failures (429/5xx/network/timeout).
|
|
112
|
+
* Defaults are conservative; set to 0 to disable.
|
|
113
|
+
*/
|
|
114
|
+
retry?: {
|
|
115
|
+
/** Number of retries after the initial attempt. Default: 2 */
|
|
116
|
+
maxRetries?: number;
|
|
117
|
+
/** Base delay for exponential backoff. Default: 250 */
|
|
118
|
+
baseDelayMs?: number;
|
|
119
|
+
/** Maximum delay cap. Default: 5_000 */
|
|
120
|
+
maxDelayMs?: number;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Optional token refresh callback. If provided and a request fails with 401,
|
|
124
|
+
* the transport will call this to obtain a new bearer token and retry once.
|
|
125
|
+
*
|
|
126
|
+
* The callback should return the new JWT bearer token string (without "Bearer ").
|
|
127
|
+
*/
|
|
128
|
+
refreshBearerToken?: (info: {
|
|
129
|
+
url: string;
|
|
130
|
+
status: 401;
|
|
131
|
+
}) => Promise<string | undefined>;
|
|
132
|
+
/**
|
|
133
|
+
* Transport middleware chain. Each middleware can observe or mutate the
|
|
134
|
+
* request and response, and can choose to retry/short-circuit if desired.
|
|
135
|
+
*/
|
|
136
|
+
middleware?: Array<(ctx: {
|
|
137
|
+
url: string;
|
|
138
|
+
init: RequestInit;
|
|
139
|
+
attempt: number;
|
|
140
|
+
next: () => Promise<Response>;
|
|
141
|
+
}) => Promise<Response>>;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Internal resolved config. The Norbix class fills required fields from
|
|
145
|
+
* NorbixConfig + env vars + defaults before constructing the transport.
|
|
146
|
+
*/
|
|
147
|
+
interface ResolvedNorbixConfig {
|
|
148
|
+
apiKey?: string;
|
|
149
|
+
bearerToken?: string;
|
|
150
|
+
projectId: string;
|
|
151
|
+
accountId?: string;
|
|
152
|
+
/** Resolved project environment. Defaults to `PROD`. */
|
|
153
|
+
env: string;
|
|
154
|
+
/** Resolved Norbix region (e.g. `nb-eu-germany`). No default — may be unset. */
|
|
155
|
+
region?: string;
|
|
156
|
+
baseUrl: {
|
|
157
|
+
api: string;
|
|
158
|
+
hub: string;
|
|
159
|
+
};
|
|
160
|
+
apiVersion: string;
|
|
161
|
+
hubVersion: string;
|
|
162
|
+
timeoutMs: number;
|
|
163
|
+
fetch: typeof globalThis.fetch;
|
|
164
|
+
defaultHeaders: Record<string, string>;
|
|
165
|
+
onRequest?: NorbixConfig['onRequest'];
|
|
166
|
+
onResponse?: NorbixConfig['onResponse'];
|
|
167
|
+
retry: Required<NonNullable<NorbixConfig['retry']>>;
|
|
168
|
+
refreshBearerToken?: NorbixConfig['refreshBearerToken'];
|
|
169
|
+
middleware: NonNullable<NorbixConfig['middleware']>;
|
|
170
|
+
}
|
|
171
|
+
/** Credentials for `norbix.login(...)`. Mirrors the /auth Authenticate DTO. */
|
|
172
|
+
interface LoginCredentials {
|
|
173
|
+
/** AuthProvider, e.g. 'credentials'. Defaults to 'credentials' if omitted. */
|
|
174
|
+
provider?: string;
|
|
175
|
+
userName?: string;
|
|
176
|
+
password?: string;
|
|
177
|
+
rememberMe?: boolean;
|
|
178
|
+
/** OAuth-style access token + secret, used for federated providers. */
|
|
179
|
+
accessToken?: string;
|
|
180
|
+
accessTokenSecret?: string;
|
|
181
|
+
meta?: Record<string, string>;
|
|
182
|
+
}
|
|
183
|
+
/** Shape of a successful /auth response. Just the fields the SDK uses. */
|
|
184
|
+
interface LoginResponse {
|
|
185
|
+
bearerToken?: string;
|
|
186
|
+
refreshToken?: string;
|
|
187
|
+
userId?: string;
|
|
188
|
+
userName?: string;
|
|
189
|
+
displayName?: string;
|
|
190
|
+
sessionId?: string;
|
|
191
|
+
[key: string]: unknown;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
type HttpVerb = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
195
|
+
/**
|
|
196
|
+
* Marks endpoints that require an `accountId` on the client. The auto-mapped
|
|
197
|
+
* code passes `'account'` for any DTO implementing `IHasAccountId`. The
|
|
198
|
+
* special `'unauthenticated'` scope bypasses the auth header check, used by
|
|
199
|
+
* the login flow which has no token yet.
|
|
200
|
+
*/
|
|
201
|
+
type Scope = 'project' | 'account' | 'public' | 'unauthenticated';
|
|
202
|
+
interface RequestOptions<TBody = unknown> {
|
|
203
|
+
/** Which gateway (api2 or hub) the call targets. */
|
|
204
|
+
target: 'api' | 'hub';
|
|
205
|
+
/** Path template with `{version}` and any `{paramName}` placeholders. */
|
|
206
|
+
path: string;
|
|
207
|
+
/** HTTP verb. If multiple verbs were declared, the codegen picks the most idiomatic one. */
|
|
208
|
+
method: HttpVerb;
|
|
209
|
+
/** Whole request DTO. Path tokens, query string, and body are extracted from it. */
|
|
210
|
+
request?: TBody;
|
|
211
|
+
/** Names of properties on the request that should fill `{path}` tokens. */
|
|
212
|
+
pathParams?: string[];
|
|
213
|
+
/** Scoping requirement. `account` throws if `accountId` is not configured. */
|
|
214
|
+
scope?: Scope;
|
|
215
|
+
/** Per-call timeout override. */
|
|
216
|
+
timeoutMs?: number;
|
|
217
|
+
/** Per-call bearer token override, useful for SSR and multi-tenant request scopes. */
|
|
218
|
+
bearerToken?: string;
|
|
219
|
+
/**
|
|
220
|
+
* Per-call environment override. Sent as the `norbix-env` header, selecting
|
|
221
|
+
* which project environment the request targets. Falls back to the client's
|
|
222
|
+
* configured `env`. `PROD` (the default) sends no header.
|
|
223
|
+
*/
|
|
224
|
+
env?: string;
|
|
225
|
+
/**
|
|
226
|
+
* Per-call region override. Sent as the `nb-region` header (a region code,
|
|
227
|
+
* e.g. `nb-eu-germany`). Falls back to the client's configured `region`.
|
|
228
|
+
* There is no default region — when neither is set, no header is sent.
|
|
229
|
+
* Affects the header only; it never changes the request URL.
|
|
230
|
+
*/
|
|
231
|
+
region?: string;
|
|
232
|
+
}
|
|
233
|
+
interface RequestOverrideOptions {
|
|
234
|
+
/** Per-call bearer token override, useful for SSR and multi-tenant request scopes. */
|
|
235
|
+
bearerToken?: string;
|
|
236
|
+
/** Per-call timeout override. */
|
|
237
|
+
timeoutMs?: number;
|
|
238
|
+
/**
|
|
239
|
+
* Per-call environment override. Sent as the `norbix-env` header, overriding
|
|
240
|
+
* the client's configured `env` for this single call. `PROD` sends no header.
|
|
241
|
+
*/
|
|
242
|
+
env?: string;
|
|
243
|
+
/**
|
|
244
|
+
* Per-call region override. Sent as the `nb-region` header, overriding the
|
|
245
|
+
* client's configured `region` for this single call. Affects the header
|
|
246
|
+
* only — the request URL is never rewritten per call.
|
|
247
|
+
*/
|
|
248
|
+
region?: string;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Tiny fetch-based transport. Handles:
|
|
252
|
+
* - bearer auth (JWT preferred, falls back to API key)
|
|
253
|
+
* - project + account headers
|
|
254
|
+
* - path token interpolation
|
|
255
|
+
* - query-string vs body based on verb
|
|
256
|
+
* - timeout via AbortController
|
|
257
|
+
* - structured error parsing into NorbixError
|
|
258
|
+
*
|
|
259
|
+
* Keeps a reference to the resolved config object — the Norbix client
|
|
260
|
+
* mutates fields on this object (bearerToken, projectId, accountId) so the
|
|
261
|
+
* transport always sees the current state without rebuilding.
|
|
262
|
+
*/
|
|
263
|
+
declare class Transport {
|
|
264
|
+
private readonly cfg;
|
|
265
|
+
constructor(cfg: ResolvedNorbixConfig);
|
|
266
|
+
send<TResponse>(opts: RequestOptions): Promise<TResponse>;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export { type LoginCredentials as L, type NorbixConfig as N, type RequestOverrideOptions as R, Transport as T, type LoginResponse as a, type ResolvedNorbixConfig as b };
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the Norbix client.
|
|
3
|
+
*
|
|
4
|
+
* Auth modes:
|
|
5
|
+
* - **API key** — long-lived, server-side. Set `apiKey` in code or
|
|
6
|
+
* `NORBIX_API_KEY` in the environment. Acts as a service identity.
|
|
7
|
+
* - **JWT bearer** — short-lived, on behalf of a user. Set `bearerToken`
|
|
8
|
+
* directly, or call `norbix.login(...)` to exchange credentials for one.
|
|
9
|
+
*
|
|
10
|
+
* If both are configured, the bearer token wins (most specific wins). If
|
|
11
|
+
* neither is set at construction, you must call `login()` before making any
|
|
12
|
+
* other call — otherwise the first request throws.
|
|
13
|
+
*
|
|
14
|
+
* Scoping rule:
|
|
15
|
+
* - `projectId` is required (or `NORBIX_PROJECT_ID` env var).
|
|
16
|
+
* - `accountId` is optional. When set, account-scoped Hub endpoints
|
|
17
|
+
* (team invite, billing portal, account verify, ...) become callable.
|
|
18
|
+
*
|
|
19
|
+
* Env vars (Node only — silently ignored in the browser):
|
|
20
|
+
* NORBIX_API_KEY
|
|
21
|
+
* NORBIX_BEARER_TOKEN
|
|
22
|
+
* NORBIX_PROJECT_ID
|
|
23
|
+
* NORBIX_ACCOUNT_ID
|
|
24
|
+
* NORBIX_REGION
|
|
25
|
+
* NORBIX_API_URL
|
|
26
|
+
* NORBIX_HUB_URL
|
|
27
|
+
* NORBIX_API_VERSION
|
|
28
|
+
* NORBIX_HUB_VERSION
|
|
29
|
+
* NORBIX_TIMEOUT_MS
|
|
30
|
+
*/
|
|
31
|
+
interface NorbixConfig {
|
|
32
|
+
/**
|
|
33
|
+
* Long-lived API key, typically used for service-to-service calls. The SDK
|
|
34
|
+
* sends it as `Authorization: Bearer <apiKey>` until a JWT bearer token
|
|
35
|
+
* takes over (set explicitly or via `login`). Falls back to `NORBIX_API_KEY`.
|
|
36
|
+
*/
|
|
37
|
+
apiKey?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Short-lived JWT bearer token, typically obtained from a login flow.
|
|
40
|
+
* Takes precedence over `apiKey` when both are set. Falls back to
|
|
41
|
+
* `NORBIX_BEARER_TOKEN`.
|
|
42
|
+
*/
|
|
43
|
+
bearerToken?: string;
|
|
44
|
+
/** Project the SDK operates against. Falls back to `NORBIX_PROJECT_ID`. */
|
|
45
|
+
projectId?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Optional account ID. Required for Hub account-scoped endpoints
|
|
48
|
+
* (team, billing, account profile). Falls back to `NORBIX_ACCOUNT_ID`.
|
|
49
|
+
*/
|
|
50
|
+
accountId?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Project environment every request targets, sent as the `norbix-env`
|
|
53
|
+
* header. Each project owns a set of named environments; `PROD` always
|
|
54
|
+
* exists and is the default. A non-PROD env (e.g. `TEST`, `STAGING`) scopes
|
|
55
|
+
* every read and write to that environment's integrations — there is no
|
|
56
|
+
* cross-env fallback. Defaults to `PROD`. Falls back to `NORBIX_ENV`.
|
|
57
|
+
*
|
|
58
|
+
* Override per call via the `env` option on any request, or switch the
|
|
59
|
+
* client default at runtime with `setEnv(...)`.
|
|
60
|
+
*/
|
|
61
|
+
env?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Norbix region every request targets, sent as the `nb-region` header
|
|
64
|
+
* (a region code, e.g. `nb-eu-germany`). Unlike `env`, there is no default
|
|
65
|
+
* region — when unset, no header is sent and the backend picks the project's
|
|
66
|
+
* primary region. Falls back to `NORBIX_REGION`.
|
|
67
|
+
*
|
|
68
|
+
* When the client uses the SDK's default base URLs, setting a region also
|
|
69
|
+
* composes the regional URL (`https://nb-eu-germany.api.norbix.dev`); a
|
|
70
|
+
* user-supplied custom `baseUrl` is never rewritten.
|
|
71
|
+
*
|
|
72
|
+
* Override per call via the `region` option on any request (header only —
|
|
73
|
+
* never changes the URL), or switch the client default at runtime with
|
|
74
|
+
* `setRegion(...)`.
|
|
75
|
+
*/
|
|
76
|
+
region?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Override default base URLs. Useful for self-hosted deployments,
|
|
79
|
+
* staging environments, or pointing the SDK at localhost in tests.
|
|
80
|
+
* Each URL falls back to its env var (`NORBIX_API_URL`, `NORBIX_HUB_URL`).
|
|
81
|
+
*/
|
|
82
|
+
baseUrl?: {
|
|
83
|
+
api?: string;
|
|
84
|
+
hub?: string;
|
|
85
|
+
};
|
|
86
|
+
/** API version segment used in `{version}` route tokens. Defaults to `v2`. */
|
|
87
|
+
apiVersion?: string;
|
|
88
|
+
hubVersion?: string;
|
|
89
|
+
/** Request timeout in milliseconds. Defaults to 30_000. */
|
|
90
|
+
timeoutMs?: number;
|
|
91
|
+
/**
|
|
92
|
+
* Optional fetch implementation. Useful for testing (`vi.fn()`) or for
|
|
93
|
+
* environments where global `fetch` is unavailable.
|
|
94
|
+
*/
|
|
95
|
+
fetch?: typeof globalThis.fetch;
|
|
96
|
+
/** Extra headers attached to every request. */
|
|
97
|
+
defaultHeaders?: Record<string, string>;
|
|
98
|
+
/** Hook called once per request before it is sent. */
|
|
99
|
+
onRequest?: (info: {
|
|
100
|
+
url: string;
|
|
101
|
+
method: string;
|
|
102
|
+
headers: Headers;
|
|
103
|
+
}) => void;
|
|
104
|
+
/** Hook called once per response, regardless of success/failure. */
|
|
105
|
+
onResponse?: (info: {
|
|
106
|
+
url: string;
|
|
107
|
+
status: number;
|
|
108
|
+
durationMs: number;
|
|
109
|
+
}) => void;
|
|
110
|
+
/**
|
|
111
|
+
* Transport retry policy for transient failures (429/5xx/network/timeout).
|
|
112
|
+
* Defaults are conservative; set to 0 to disable.
|
|
113
|
+
*/
|
|
114
|
+
retry?: {
|
|
115
|
+
/** Number of retries after the initial attempt. Default: 2 */
|
|
116
|
+
maxRetries?: number;
|
|
117
|
+
/** Base delay for exponential backoff. Default: 250 */
|
|
118
|
+
baseDelayMs?: number;
|
|
119
|
+
/** Maximum delay cap. Default: 5_000 */
|
|
120
|
+
maxDelayMs?: number;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Optional token refresh callback. If provided and a request fails with 401,
|
|
124
|
+
* the transport will call this to obtain a new bearer token and retry once.
|
|
125
|
+
*
|
|
126
|
+
* The callback should return the new JWT bearer token string (without "Bearer ").
|
|
127
|
+
*/
|
|
128
|
+
refreshBearerToken?: (info: {
|
|
129
|
+
url: string;
|
|
130
|
+
status: 401;
|
|
131
|
+
}) => Promise<string | undefined>;
|
|
132
|
+
/**
|
|
133
|
+
* Transport middleware chain. Each middleware can observe or mutate the
|
|
134
|
+
* request and response, and can choose to retry/short-circuit if desired.
|
|
135
|
+
*/
|
|
136
|
+
middleware?: Array<(ctx: {
|
|
137
|
+
url: string;
|
|
138
|
+
init: RequestInit;
|
|
139
|
+
attempt: number;
|
|
140
|
+
next: () => Promise<Response>;
|
|
141
|
+
}) => Promise<Response>>;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Internal resolved config. The Norbix class fills required fields from
|
|
145
|
+
* NorbixConfig + env vars + defaults before constructing the transport.
|
|
146
|
+
*/
|
|
147
|
+
interface ResolvedNorbixConfig {
|
|
148
|
+
apiKey?: string;
|
|
149
|
+
bearerToken?: string;
|
|
150
|
+
projectId: string;
|
|
151
|
+
accountId?: string;
|
|
152
|
+
/** Resolved project environment. Defaults to `PROD`. */
|
|
153
|
+
env: string;
|
|
154
|
+
/** Resolved Norbix region (e.g. `nb-eu-germany`). No default — may be unset. */
|
|
155
|
+
region?: string;
|
|
156
|
+
baseUrl: {
|
|
157
|
+
api: string;
|
|
158
|
+
hub: string;
|
|
159
|
+
};
|
|
160
|
+
apiVersion: string;
|
|
161
|
+
hubVersion: string;
|
|
162
|
+
timeoutMs: number;
|
|
163
|
+
fetch: typeof globalThis.fetch;
|
|
164
|
+
defaultHeaders: Record<string, string>;
|
|
165
|
+
onRequest?: NorbixConfig['onRequest'];
|
|
166
|
+
onResponse?: NorbixConfig['onResponse'];
|
|
167
|
+
retry: Required<NonNullable<NorbixConfig['retry']>>;
|
|
168
|
+
refreshBearerToken?: NorbixConfig['refreshBearerToken'];
|
|
169
|
+
middleware: NonNullable<NorbixConfig['middleware']>;
|
|
170
|
+
}
|
|
171
|
+
/** Credentials for `norbix.login(...)`. Mirrors the /auth Authenticate DTO. */
|
|
172
|
+
interface LoginCredentials {
|
|
173
|
+
/** AuthProvider, e.g. 'credentials'. Defaults to 'credentials' if omitted. */
|
|
174
|
+
provider?: string;
|
|
175
|
+
userName?: string;
|
|
176
|
+
password?: string;
|
|
177
|
+
rememberMe?: boolean;
|
|
178
|
+
/** OAuth-style access token + secret, used for federated providers. */
|
|
179
|
+
accessToken?: string;
|
|
180
|
+
accessTokenSecret?: string;
|
|
181
|
+
meta?: Record<string, string>;
|
|
182
|
+
}
|
|
183
|
+
/** Shape of a successful /auth response. Just the fields the SDK uses. */
|
|
184
|
+
interface LoginResponse {
|
|
185
|
+
bearerToken?: string;
|
|
186
|
+
refreshToken?: string;
|
|
187
|
+
userId?: string;
|
|
188
|
+
userName?: string;
|
|
189
|
+
displayName?: string;
|
|
190
|
+
sessionId?: string;
|
|
191
|
+
[key: string]: unknown;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
type HttpVerb = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
195
|
+
/**
|
|
196
|
+
* Marks endpoints that require an `accountId` on the client. The auto-mapped
|
|
197
|
+
* code passes `'account'` for any DTO implementing `IHasAccountId`. The
|
|
198
|
+
* special `'unauthenticated'` scope bypasses the auth header check, used by
|
|
199
|
+
* the login flow which has no token yet.
|
|
200
|
+
*/
|
|
201
|
+
type Scope = 'project' | 'account' | 'public' | 'unauthenticated';
|
|
202
|
+
interface RequestOptions<TBody = unknown> {
|
|
203
|
+
/** Which gateway (api2 or hub) the call targets. */
|
|
204
|
+
target: 'api' | 'hub';
|
|
205
|
+
/** Path template with `{version}` and any `{paramName}` placeholders. */
|
|
206
|
+
path: string;
|
|
207
|
+
/** HTTP verb. If multiple verbs were declared, the codegen picks the most idiomatic one. */
|
|
208
|
+
method: HttpVerb;
|
|
209
|
+
/** Whole request DTO. Path tokens, query string, and body are extracted from it. */
|
|
210
|
+
request?: TBody;
|
|
211
|
+
/** Names of properties on the request that should fill `{path}` tokens. */
|
|
212
|
+
pathParams?: string[];
|
|
213
|
+
/** Scoping requirement. `account` throws if `accountId` is not configured. */
|
|
214
|
+
scope?: Scope;
|
|
215
|
+
/** Per-call timeout override. */
|
|
216
|
+
timeoutMs?: number;
|
|
217
|
+
/** Per-call bearer token override, useful for SSR and multi-tenant request scopes. */
|
|
218
|
+
bearerToken?: string;
|
|
219
|
+
/**
|
|
220
|
+
* Per-call environment override. Sent as the `norbix-env` header, selecting
|
|
221
|
+
* which project environment the request targets. Falls back to the client's
|
|
222
|
+
* configured `env`. `PROD` (the default) sends no header.
|
|
223
|
+
*/
|
|
224
|
+
env?: string;
|
|
225
|
+
/**
|
|
226
|
+
* Per-call region override. Sent as the `nb-region` header (a region code,
|
|
227
|
+
* e.g. `nb-eu-germany`). Falls back to the client's configured `region`.
|
|
228
|
+
* There is no default region — when neither is set, no header is sent.
|
|
229
|
+
* Affects the header only; it never changes the request URL.
|
|
230
|
+
*/
|
|
231
|
+
region?: string;
|
|
232
|
+
}
|
|
233
|
+
interface RequestOverrideOptions {
|
|
234
|
+
/** Per-call bearer token override, useful for SSR and multi-tenant request scopes. */
|
|
235
|
+
bearerToken?: string;
|
|
236
|
+
/** Per-call timeout override. */
|
|
237
|
+
timeoutMs?: number;
|
|
238
|
+
/**
|
|
239
|
+
* Per-call environment override. Sent as the `norbix-env` header, overriding
|
|
240
|
+
* the client's configured `env` for this single call. `PROD` sends no header.
|
|
241
|
+
*/
|
|
242
|
+
env?: string;
|
|
243
|
+
/**
|
|
244
|
+
* Per-call region override. Sent as the `nb-region` header, overriding the
|
|
245
|
+
* client's configured `region` for this single call. Affects the header
|
|
246
|
+
* only — the request URL is never rewritten per call.
|
|
247
|
+
*/
|
|
248
|
+
region?: string;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Tiny fetch-based transport. Handles:
|
|
252
|
+
* - bearer auth (JWT preferred, falls back to API key)
|
|
253
|
+
* - project + account headers
|
|
254
|
+
* - path token interpolation
|
|
255
|
+
* - query-string vs body based on verb
|
|
256
|
+
* - timeout via AbortController
|
|
257
|
+
* - structured error parsing into NorbixError
|
|
258
|
+
*
|
|
259
|
+
* Keeps a reference to the resolved config object — the Norbix client
|
|
260
|
+
* mutates fields on this object (bearerToken, projectId, accountId) so the
|
|
261
|
+
* transport always sees the current state without rebuilding.
|
|
262
|
+
*/
|
|
263
|
+
declare class Transport {
|
|
264
|
+
private readonly cfg;
|
|
265
|
+
constructor(cfg: ResolvedNorbixConfig);
|
|
266
|
+
send<TResponse>(opts: RequestOptions): Promise<TResponse>;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export { type LoginCredentials as L, type NorbixConfig as N, type RequestOverrideOptions as R, Transport as T, type LoginResponse as a, type ResolvedNorbixConfig as b };
|