@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
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { D as DatabaseModule, A as ApiNamespace } from './index-BARFtiR-.cjs';
|
|
2
|
+
import { HubNamespace } from './hub/index.cjs';
|
|
3
|
+
import { R as RequestOverrideOptions, N as NorbixConfig, L as LoginCredentials, a as LoginResponse, b as ResolvedNorbixConfig } from './transport-c4_dsqN0.cjs';
|
|
4
|
+
import { CodeMashApi2 } from './types/api2.dtos.cjs';
|
|
5
|
+
import './types/hub2.dtos.cjs';
|
|
6
|
+
|
|
7
|
+
declare class CollectionResource<TItem = unknown> {
|
|
8
|
+
private readonly database;
|
|
9
|
+
private readonly collectionName;
|
|
10
|
+
constructor(database: DatabaseModule, collectionName: string);
|
|
11
|
+
find(request?: Omit<Partial<CodeMashApi2.FindRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.FindResponse>;
|
|
12
|
+
findItems(request?: Omit<Partial<CodeMashApi2.FindRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<TItem[]>;
|
|
13
|
+
findOne(request: Omit<Partial<CodeMashApi2.FindOneRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.FindOneResponse>;
|
|
14
|
+
count(request?: Omit<Partial<CodeMashApi2.CountRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.CountResponse>;
|
|
15
|
+
distinct(request: Omit<Partial<CodeMashApi2.DistinctRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.DistinctResponse>;
|
|
16
|
+
insertOne(request: Omit<Partial<CodeMashApi2.InsertOneRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.IdResponse>;
|
|
17
|
+
insertMany(request: Omit<Partial<CodeMashApi2.InsertManyRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.EmptyResponse>;
|
|
18
|
+
updateOne(request: Omit<Partial<CodeMashApi2.UpdateOneRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.EmptyResponse>;
|
|
19
|
+
updateMany(request: Omit<Partial<CodeMashApi2.UpdateManyRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.EmptyResponse>;
|
|
20
|
+
replaceOne(request: Omit<Partial<CodeMashApi2.ReplaceOneRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.EmptyResponse>;
|
|
21
|
+
deleteOne(request: Omit<Partial<CodeMashApi2.DeleteOneRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.EmptyResponse>;
|
|
22
|
+
deleteMany(request: Omit<Partial<CodeMashApi2.DeleteManyRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.EmptyResponse>;
|
|
23
|
+
aggregate(request: Omit<Partial<CodeMashApi2.AggregateRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.AggregateResponse>;
|
|
24
|
+
executeAggregate(request: Omit<Partial<CodeMashApi2.ExecuteAggregateRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.ExecuteAggregateResponse>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Single entry point for the Norbix SDK.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* // Service-to-service: long-lived API key
|
|
32
|
+
* const norbix = new Norbix({ apiKey: '...', projectId: '...' });
|
|
33
|
+
*
|
|
34
|
+
* // User-on-behalf-of: log in, then act as the user
|
|
35
|
+
* const norbix = new Norbix({ projectId: '...' });
|
|
36
|
+
* await norbix.login({ userName: 'alice', password: '...' });
|
|
37
|
+
* await norbix.api.database.find({ collectionName: 'orders' });
|
|
38
|
+
*
|
|
39
|
+
* // Zero-config: read everything from NORBIX_* env vars
|
|
40
|
+
* const norbix = new Norbix();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
declare class Norbix {
|
|
44
|
+
readonly api: ApiNamespace;
|
|
45
|
+
readonly hub: HubNamespace;
|
|
46
|
+
private cfg;
|
|
47
|
+
private transport;
|
|
48
|
+
/**
|
|
49
|
+
* Whether each base URL is the SDK default (not user/env supplied). Only
|
|
50
|
+
* default base URLs are ever rewritten when a region is set; a custom
|
|
51
|
+
* `baseUrl` is never touched.
|
|
52
|
+
*/
|
|
53
|
+
private readonly usesDefaultBaseUrl;
|
|
54
|
+
/** Create a client using explicit configuration (readable alternative to `new Norbix(...)`). */
|
|
55
|
+
static create(config?: NorbixConfig, opts?: {
|
|
56
|
+
envSource?: Record<string, string | undefined>;
|
|
57
|
+
}): Norbix;
|
|
58
|
+
/**
|
|
59
|
+
* Create a client from environment variables only (still allows injecting envSource for tests).
|
|
60
|
+
* Equivalent to `new Norbix({}, opts)`.
|
|
61
|
+
*/
|
|
62
|
+
static fromEnv(opts?: {
|
|
63
|
+
envSource?: Record<string, string | undefined>;
|
|
64
|
+
}): Norbix;
|
|
65
|
+
constructor(config?: NorbixConfig, opts?: {
|
|
66
|
+
envSource?: Record<string, string | undefined>;
|
|
67
|
+
});
|
|
68
|
+
/**
|
|
69
|
+
* (Re)compose the base URLs for the configured region. Only the SDK's
|
|
70
|
+
* default URLs are ever rewritten — `https://api.norbix.dev` becomes
|
|
71
|
+
* `https://nb-eu-germany.api.norbix.dev` — and clearing the region restores
|
|
72
|
+
* the defaults. A user-supplied custom base URL is never touched.
|
|
73
|
+
*/
|
|
74
|
+
private applyRegionToBaseUrls;
|
|
75
|
+
/**
|
|
76
|
+
* Exchange credentials for a JWT bearer token. On success, the token is
|
|
77
|
+
* stored on the client and used for every subsequent call (it takes
|
|
78
|
+
* precedence over any configured `apiKey`). The full /auth response is
|
|
79
|
+
* returned so the caller can also access refreshToken, userId, etc.
|
|
80
|
+
*
|
|
81
|
+
* The login call itself runs unauthenticated — no Authorization header is
|
|
82
|
+
* sent for /auth even if a token is already configured.
|
|
83
|
+
*/
|
|
84
|
+
login(credentials: LoginCredentials): Promise<LoginResponse>;
|
|
85
|
+
/**
|
|
86
|
+
* Clear the JWT bearer token. If an `apiKey` was configured, the client
|
|
87
|
+
* falls back to it; otherwise subsequent calls throw NORBIX_NOT_AUTHENTICATED.
|
|
88
|
+
*/
|
|
89
|
+
logout(): void;
|
|
90
|
+
/** Replace the bearer token without rebuilding the client. */
|
|
91
|
+
setBearerToken(token: string | undefined): void;
|
|
92
|
+
/** Replace the API key without rebuilding the client. */
|
|
93
|
+
setApiKey(apiKey: string | undefined): void;
|
|
94
|
+
/** Switch the client to a different project (and optionally account) at runtime. */
|
|
95
|
+
setScope(scope: {
|
|
96
|
+
projectId: string;
|
|
97
|
+
accountId?: string;
|
|
98
|
+
}): void;
|
|
99
|
+
/**
|
|
100
|
+
* Switch the project environment all subsequent requests target (sent as the
|
|
101
|
+
* `norbix-env` header). Pass `'PROD'` or `undefined` to return to production.
|
|
102
|
+
* Per-call `env` overrides still take precedence for individual requests.
|
|
103
|
+
*/
|
|
104
|
+
setEnv(env: string | undefined): void;
|
|
105
|
+
/** Current project environment the client targets (defaults to `PROD`). */
|
|
106
|
+
getEnv(): string;
|
|
107
|
+
/**
|
|
108
|
+
* Switch the Norbix region all subsequent requests target (sent as the
|
|
109
|
+
* `nb-region` header). Pass `undefined` to clear the region — no header is
|
|
110
|
+
* sent when no region is set. When the client uses the SDK's default base
|
|
111
|
+
* URLs, the regional URL is recomposed under the same rule as construction;
|
|
112
|
+
* a custom `baseUrl` is never rewritten. Per-call `region` overrides still
|
|
113
|
+
* take precedence for individual requests (header only — never the URL).
|
|
114
|
+
*/
|
|
115
|
+
setRegion(region: string | undefined): void;
|
|
116
|
+
/** Current Norbix region the client targets (e.g. `nb-eu-germany`), if any. */
|
|
117
|
+
getRegion(): string | undefined;
|
|
118
|
+
/** True when the client has either a JWT bearer token or an API key. */
|
|
119
|
+
isAuthenticated(): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Ergonomic database access wrapper over `norbix.api.database.*`.
|
|
122
|
+
* Keeps the generated API available, but gives a resource-first call style.
|
|
123
|
+
*/
|
|
124
|
+
collection<TItem = unknown>(collectionName: string): CollectionResource<TItem>;
|
|
125
|
+
/** Read-only snapshot of the current config (useful for tests/diagnostics). */
|
|
126
|
+
getConfig(): Readonly<ResolvedNorbixConfig>;
|
|
127
|
+
/**
|
|
128
|
+
* Snapshot suitable for logs/telemetry. Sensitive fields are redacted.
|
|
129
|
+
* Use `getConfig()` only in tests or trusted diagnostics.
|
|
130
|
+
*/
|
|
131
|
+
getRedactedConfig(): Readonly<Omit<ResolvedNorbixConfig, 'fetch'>>;
|
|
132
|
+
/**
|
|
133
|
+
* Create a new client for per-request scoping (SSR/multi-tenant safe).
|
|
134
|
+
* The new instance does not share mutable auth or scope with the original.
|
|
135
|
+
*/
|
|
136
|
+
with(overrides: Pick<NorbixConfig, 'apiKey' | 'bearerToken' | 'projectId' | 'accountId' | 'env' | 'region'>): Norbix;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Shape of a ServiceStack ResponseStatus block returned by the Norbix gateways
|
|
141
|
+
* on failure. Modelled after the `ResponseStatus` DTO so error envelopes are
|
|
142
|
+
* consumer-friendly without forcing them to import generated DTO types.
|
|
143
|
+
*/
|
|
144
|
+
interface NorbixErrorPayload {
|
|
145
|
+
errorCode?: string;
|
|
146
|
+
message?: string;
|
|
147
|
+
stackTrace?: string;
|
|
148
|
+
errors?: Array<{
|
|
149
|
+
errorCode?: string;
|
|
150
|
+
fieldName?: string;
|
|
151
|
+
message?: string;
|
|
152
|
+
meta?: Record<string, string>;
|
|
153
|
+
}>;
|
|
154
|
+
meta?: Record<string, string>;
|
|
155
|
+
}
|
|
156
|
+
declare class NorbixError extends Error {
|
|
157
|
+
readonly status: number;
|
|
158
|
+
readonly code?: string;
|
|
159
|
+
readonly fieldErrors: NonNullable<NorbixErrorPayload['errors']>;
|
|
160
|
+
readonly raw?: unknown;
|
|
161
|
+
readonly url?: string;
|
|
162
|
+
constructor(opts: {
|
|
163
|
+
message: string;
|
|
164
|
+
status: number;
|
|
165
|
+
code?: string;
|
|
166
|
+
fieldErrors?: NonNullable<NorbixErrorPayload['errors']>;
|
|
167
|
+
raw?: unknown;
|
|
168
|
+
url?: string;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
declare class NorbixNetworkError extends NorbixError {
|
|
172
|
+
constructor(opts: {
|
|
173
|
+
message: string;
|
|
174
|
+
url?: string;
|
|
175
|
+
raw?: unknown;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
declare class NorbixTimeoutError extends NorbixError {
|
|
179
|
+
constructor(opts: {
|
|
180
|
+
message: string;
|
|
181
|
+
url?: string;
|
|
182
|
+
raw?: unknown;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
declare class NorbixAuthError extends NorbixError {
|
|
186
|
+
constructor(opts: {
|
|
187
|
+
message: string;
|
|
188
|
+
status: number;
|
|
189
|
+
code?: string;
|
|
190
|
+
fieldErrors?: NorbixErrorPayload['errors'];
|
|
191
|
+
url?: string;
|
|
192
|
+
raw?: unknown;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
declare class NorbixValidationError extends NorbixError {
|
|
196
|
+
constructor(opts: {
|
|
197
|
+
message: string;
|
|
198
|
+
status: number;
|
|
199
|
+
code?: string;
|
|
200
|
+
fieldErrors?: NorbixErrorPayload['errors'];
|
|
201
|
+
url?: string;
|
|
202
|
+
raw?: unknown;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Resolve all NORBIX_* env vars into a typed snapshot. Returns an object with
|
|
208
|
+
* only the keys that were set, so callers can spread it as a partial config.
|
|
209
|
+
*/
|
|
210
|
+
interface EnvConfig {
|
|
211
|
+
apiKey?: string;
|
|
212
|
+
bearerToken?: string;
|
|
213
|
+
projectId?: string;
|
|
214
|
+
accountId?: string;
|
|
215
|
+
env?: string;
|
|
216
|
+
region?: string;
|
|
217
|
+
apiUrl?: string;
|
|
218
|
+
hubUrl?: string;
|
|
219
|
+
apiVersion?: string;
|
|
220
|
+
hubVersion?: string;
|
|
221
|
+
timeoutMs?: number;
|
|
222
|
+
}
|
|
223
|
+
declare function loadEnvConfig(source?: Record<string, string | undefined>): EnvConfig;
|
|
224
|
+
|
|
225
|
+
export { CollectionResource, type EnvConfig, LoginCredentials, LoginResponse, Norbix, NorbixAuthError, NorbixConfig, NorbixError, type NorbixErrorPayload, NorbixNetworkError, NorbixTimeoutError, NorbixValidationError, loadEnvConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { D as DatabaseModule, A as ApiNamespace } from './index-t6pXnReB.js';
|
|
2
|
+
import { HubNamespace } from './hub/index.js';
|
|
3
|
+
import { R as RequestOverrideOptions, N as NorbixConfig, L as LoginCredentials, a as LoginResponse, b as ResolvedNorbixConfig } from './transport-c4_dsqN0.js';
|
|
4
|
+
import { CodeMashApi2 } from './types/api2.dtos.js';
|
|
5
|
+
import './types/hub2.dtos.js';
|
|
6
|
+
|
|
7
|
+
declare class CollectionResource<TItem = unknown> {
|
|
8
|
+
private readonly database;
|
|
9
|
+
private readonly collectionName;
|
|
10
|
+
constructor(database: DatabaseModule, collectionName: string);
|
|
11
|
+
find(request?: Omit<Partial<CodeMashApi2.FindRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.FindResponse>;
|
|
12
|
+
findItems(request?: Omit<Partial<CodeMashApi2.FindRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<TItem[]>;
|
|
13
|
+
findOne(request: Omit<Partial<CodeMashApi2.FindOneRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.FindOneResponse>;
|
|
14
|
+
count(request?: Omit<Partial<CodeMashApi2.CountRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.CountResponse>;
|
|
15
|
+
distinct(request: Omit<Partial<CodeMashApi2.DistinctRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.DistinctResponse>;
|
|
16
|
+
insertOne(request: Omit<Partial<CodeMashApi2.InsertOneRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.IdResponse>;
|
|
17
|
+
insertMany(request: Omit<Partial<CodeMashApi2.InsertManyRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.EmptyResponse>;
|
|
18
|
+
updateOne(request: Omit<Partial<CodeMashApi2.UpdateOneRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.EmptyResponse>;
|
|
19
|
+
updateMany(request: Omit<Partial<CodeMashApi2.UpdateManyRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.EmptyResponse>;
|
|
20
|
+
replaceOne(request: Omit<Partial<CodeMashApi2.ReplaceOneRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.EmptyResponse>;
|
|
21
|
+
deleteOne(request: Omit<Partial<CodeMashApi2.DeleteOneRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.EmptyResponse>;
|
|
22
|
+
deleteMany(request: Omit<Partial<CodeMashApi2.DeleteManyRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.EmptyResponse>;
|
|
23
|
+
aggregate(request: Omit<Partial<CodeMashApi2.AggregateRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.AggregateResponse>;
|
|
24
|
+
executeAggregate(request: Omit<Partial<CodeMashApi2.ExecuteAggregateRequest>, 'collectionName'>, options?: RequestOverrideOptions): Promise<CodeMashApi2.ExecuteAggregateResponse>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Single entry point for the Norbix SDK.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* // Service-to-service: long-lived API key
|
|
32
|
+
* const norbix = new Norbix({ apiKey: '...', projectId: '...' });
|
|
33
|
+
*
|
|
34
|
+
* // User-on-behalf-of: log in, then act as the user
|
|
35
|
+
* const norbix = new Norbix({ projectId: '...' });
|
|
36
|
+
* await norbix.login({ userName: 'alice', password: '...' });
|
|
37
|
+
* await norbix.api.database.find({ collectionName: 'orders' });
|
|
38
|
+
*
|
|
39
|
+
* // Zero-config: read everything from NORBIX_* env vars
|
|
40
|
+
* const norbix = new Norbix();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
declare class Norbix {
|
|
44
|
+
readonly api: ApiNamespace;
|
|
45
|
+
readonly hub: HubNamespace;
|
|
46
|
+
private cfg;
|
|
47
|
+
private transport;
|
|
48
|
+
/**
|
|
49
|
+
* Whether each base URL is the SDK default (not user/env supplied). Only
|
|
50
|
+
* default base URLs are ever rewritten when a region is set; a custom
|
|
51
|
+
* `baseUrl` is never touched.
|
|
52
|
+
*/
|
|
53
|
+
private readonly usesDefaultBaseUrl;
|
|
54
|
+
/** Create a client using explicit configuration (readable alternative to `new Norbix(...)`). */
|
|
55
|
+
static create(config?: NorbixConfig, opts?: {
|
|
56
|
+
envSource?: Record<string, string | undefined>;
|
|
57
|
+
}): Norbix;
|
|
58
|
+
/**
|
|
59
|
+
* Create a client from environment variables only (still allows injecting envSource for tests).
|
|
60
|
+
* Equivalent to `new Norbix({}, opts)`.
|
|
61
|
+
*/
|
|
62
|
+
static fromEnv(opts?: {
|
|
63
|
+
envSource?: Record<string, string | undefined>;
|
|
64
|
+
}): Norbix;
|
|
65
|
+
constructor(config?: NorbixConfig, opts?: {
|
|
66
|
+
envSource?: Record<string, string | undefined>;
|
|
67
|
+
});
|
|
68
|
+
/**
|
|
69
|
+
* (Re)compose the base URLs for the configured region. Only the SDK's
|
|
70
|
+
* default URLs are ever rewritten — `https://api.norbix.dev` becomes
|
|
71
|
+
* `https://nb-eu-germany.api.norbix.dev` — and clearing the region restores
|
|
72
|
+
* the defaults. A user-supplied custom base URL is never touched.
|
|
73
|
+
*/
|
|
74
|
+
private applyRegionToBaseUrls;
|
|
75
|
+
/**
|
|
76
|
+
* Exchange credentials for a JWT bearer token. On success, the token is
|
|
77
|
+
* stored on the client and used for every subsequent call (it takes
|
|
78
|
+
* precedence over any configured `apiKey`). The full /auth response is
|
|
79
|
+
* returned so the caller can also access refreshToken, userId, etc.
|
|
80
|
+
*
|
|
81
|
+
* The login call itself runs unauthenticated — no Authorization header is
|
|
82
|
+
* sent for /auth even if a token is already configured.
|
|
83
|
+
*/
|
|
84
|
+
login(credentials: LoginCredentials): Promise<LoginResponse>;
|
|
85
|
+
/**
|
|
86
|
+
* Clear the JWT bearer token. If an `apiKey` was configured, the client
|
|
87
|
+
* falls back to it; otherwise subsequent calls throw NORBIX_NOT_AUTHENTICATED.
|
|
88
|
+
*/
|
|
89
|
+
logout(): void;
|
|
90
|
+
/** Replace the bearer token without rebuilding the client. */
|
|
91
|
+
setBearerToken(token: string | undefined): void;
|
|
92
|
+
/** Replace the API key without rebuilding the client. */
|
|
93
|
+
setApiKey(apiKey: string | undefined): void;
|
|
94
|
+
/** Switch the client to a different project (and optionally account) at runtime. */
|
|
95
|
+
setScope(scope: {
|
|
96
|
+
projectId: string;
|
|
97
|
+
accountId?: string;
|
|
98
|
+
}): void;
|
|
99
|
+
/**
|
|
100
|
+
* Switch the project environment all subsequent requests target (sent as the
|
|
101
|
+
* `norbix-env` header). Pass `'PROD'` or `undefined` to return to production.
|
|
102
|
+
* Per-call `env` overrides still take precedence for individual requests.
|
|
103
|
+
*/
|
|
104
|
+
setEnv(env: string | undefined): void;
|
|
105
|
+
/** Current project environment the client targets (defaults to `PROD`). */
|
|
106
|
+
getEnv(): string;
|
|
107
|
+
/**
|
|
108
|
+
* Switch the Norbix region all subsequent requests target (sent as the
|
|
109
|
+
* `nb-region` header). Pass `undefined` to clear the region — no header is
|
|
110
|
+
* sent when no region is set. When the client uses the SDK's default base
|
|
111
|
+
* URLs, the regional URL is recomposed under the same rule as construction;
|
|
112
|
+
* a custom `baseUrl` is never rewritten. Per-call `region` overrides still
|
|
113
|
+
* take precedence for individual requests (header only — never the URL).
|
|
114
|
+
*/
|
|
115
|
+
setRegion(region: string | undefined): void;
|
|
116
|
+
/** Current Norbix region the client targets (e.g. `nb-eu-germany`), if any. */
|
|
117
|
+
getRegion(): string | undefined;
|
|
118
|
+
/** True when the client has either a JWT bearer token or an API key. */
|
|
119
|
+
isAuthenticated(): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Ergonomic database access wrapper over `norbix.api.database.*`.
|
|
122
|
+
* Keeps the generated API available, but gives a resource-first call style.
|
|
123
|
+
*/
|
|
124
|
+
collection<TItem = unknown>(collectionName: string): CollectionResource<TItem>;
|
|
125
|
+
/** Read-only snapshot of the current config (useful for tests/diagnostics). */
|
|
126
|
+
getConfig(): Readonly<ResolvedNorbixConfig>;
|
|
127
|
+
/**
|
|
128
|
+
* Snapshot suitable for logs/telemetry. Sensitive fields are redacted.
|
|
129
|
+
* Use `getConfig()` only in tests or trusted diagnostics.
|
|
130
|
+
*/
|
|
131
|
+
getRedactedConfig(): Readonly<Omit<ResolvedNorbixConfig, 'fetch'>>;
|
|
132
|
+
/**
|
|
133
|
+
* Create a new client for per-request scoping (SSR/multi-tenant safe).
|
|
134
|
+
* The new instance does not share mutable auth or scope with the original.
|
|
135
|
+
*/
|
|
136
|
+
with(overrides: Pick<NorbixConfig, 'apiKey' | 'bearerToken' | 'projectId' | 'accountId' | 'env' | 'region'>): Norbix;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Shape of a ServiceStack ResponseStatus block returned by the Norbix gateways
|
|
141
|
+
* on failure. Modelled after the `ResponseStatus` DTO so error envelopes are
|
|
142
|
+
* consumer-friendly without forcing them to import generated DTO types.
|
|
143
|
+
*/
|
|
144
|
+
interface NorbixErrorPayload {
|
|
145
|
+
errorCode?: string;
|
|
146
|
+
message?: string;
|
|
147
|
+
stackTrace?: string;
|
|
148
|
+
errors?: Array<{
|
|
149
|
+
errorCode?: string;
|
|
150
|
+
fieldName?: string;
|
|
151
|
+
message?: string;
|
|
152
|
+
meta?: Record<string, string>;
|
|
153
|
+
}>;
|
|
154
|
+
meta?: Record<string, string>;
|
|
155
|
+
}
|
|
156
|
+
declare class NorbixError extends Error {
|
|
157
|
+
readonly status: number;
|
|
158
|
+
readonly code?: string;
|
|
159
|
+
readonly fieldErrors: NonNullable<NorbixErrorPayload['errors']>;
|
|
160
|
+
readonly raw?: unknown;
|
|
161
|
+
readonly url?: string;
|
|
162
|
+
constructor(opts: {
|
|
163
|
+
message: string;
|
|
164
|
+
status: number;
|
|
165
|
+
code?: string;
|
|
166
|
+
fieldErrors?: NonNullable<NorbixErrorPayload['errors']>;
|
|
167
|
+
raw?: unknown;
|
|
168
|
+
url?: string;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
declare class NorbixNetworkError extends NorbixError {
|
|
172
|
+
constructor(opts: {
|
|
173
|
+
message: string;
|
|
174
|
+
url?: string;
|
|
175
|
+
raw?: unknown;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
declare class NorbixTimeoutError extends NorbixError {
|
|
179
|
+
constructor(opts: {
|
|
180
|
+
message: string;
|
|
181
|
+
url?: string;
|
|
182
|
+
raw?: unknown;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
declare class NorbixAuthError extends NorbixError {
|
|
186
|
+
constructor(opts: {
|
|
187
|
+
message: string;
|
|
188
|
+
status: number;
|
|
189
|
+
code?: string;
|
|
190
|
+
fieldErrors?: NorbixErrorPayload['errors'];
|
|
191
|
+
url?: string;
|
|
192
|
+
raw?: unknown;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
declare class NorbixValidationError extends NorbixError {
|
|
196
|
+
constructor(opts: {
|
|
197
|
+
message: string;
|
|
198
|
+
status: number;
|
|
199
|
+
code?: string;
|
|
200
|
+
fieldErrors?: NorbixErrorPayload['errors'];
|
|
201
|
+
url?: string;
|
|
202
|
+
raw?: unknown;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Resolve all NORBIX_* env vars into a typed snapshot. Returns an object with
|
|
208
|
+
* only the keys that were set, so callers can spread it as a partial config.
|
|
209
|
+
*/
|
|
210
|
+
interface EnvConfig {
|
|
211
|
+
apiKey?: string;
|
|
212
|
+
bearerToken?: string;
|
|
213
|
+
projectId?: string;
|
|
214
|
+
accountId?: string;
|
|
215
|
+
env?: string;
|
|
216
|
+
region?: string;
|
|
217
|
+
apiUrl?: string;
|
|
218
|
+
hubUrl?: string;
|
|
219
|
+
apiVersion?: string;
|
|
220
|
+
hubVersion?: string;
|
|
221
|
+
timeoutMs?: number;
|
|
222
|
+
}
|
|
223
|
+
declare function loadEnvConfig(source?: Record<string, string | undefined>): EnvConfig;
|
|
224
|
+
|
|
225
|
+
export { CollectionResource, type EnvConfig, LoginCredentials, LoginResponse, Norbix, NorbixAuthError, NorbixConfig, NorbixError, type NorbixErrorPayload, NorbixNetworkError, NorbixTimeoutError, NorbixValidationError, loadEnvConfig };
|