@kadoa/node-sdk 0.22.0 → 0.23.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/dist/browser/index.global.js +6 -6
- package/dist/browser/index.global.js.map +1 -1
- package/dist/index.d.mts +46 -3
- package/dist/index.d.ts +46 -3
- package/dist/index.js +69 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6201,7 +6201,7 @@ process.env.KADOA_WSS_NEO_API_URI ?? "wss://events.kadoa.com/events/ws";
|
|
|
6201
6201
|
var REALTIME_API_URI = process.env.KADOA_REALTIME_API_URI ?? "https://realtime.kadoa.com";
|
|
6202
6202
|
|
|
6203
6203
|
// src/version.ts
|
|
6204
|
-
var SDK_VERSION = "0.
|
|
6204
|
+
var SDK_VERSION = "0.23.0";
|
|
6205
6205
|
var SDK_NAME = "kadoa-node-sdk";
|
|
6206
6206
|
var SDK_LANGUAGE = "node";
|
|
6207
6207
|
|
|
@@ -7176,11 +7176,27 @@ function createNotificationDomain(params) {
|
|
|
7176
7176
|
// src/client/kadoa-client.ts
|
|
7177
7177
|
var KadoaClient = class {
|
|
7178
7178
|
constructor(config) {
|
|
7179
|
+
if (!config.apiKey && !config.bearerToken) {
|
|
7180
|
+
throw new KadoaSdkException(
|
|
7181
|
+
"Either apiKey or bearerToken must be provided",
|
|
7182
|
+
{ code: "VALIDATION_ERROR" }
|
|
7183
|
+
);
|
|
7184
|
+
}
|
|
7179
7185
|
this._baseUrl = config.baseUrl ?? PUBLIC_API_URI;
|
|
7180
|
-
this._apiKey = config.apiKey;
|
|
7186
|
+
this._apiKey = config.apiKey ?? "";
|
|
7187
|
+
this._bearerToken = config.bearerToken;
|
|
7181
7188
|
const timeout = config.timeout ?? 3e4;
|
|
7182
7189
|
const headers = createSdkHeaders();
|
|
7183
7190
|
this._axiosInstance = createAxiosInstance({ timeout, headers });
|
|
7191
|
+
this._axiosInstance.interceptors.request.use((reqConfig) => {
|
|
7192
|
+
if (this._bearerToken) {
|
|
7193
|
+
if (!reqConfig.headers["Authorization"]) {
|
|
7194
|
+
reqConfig.headers["Authorization"] = `Bearer ${this._bearerToken}`;
|
|
7195
|
+
}
|
|
7196
|
+
delete reqConfig.headers["x-api-key"];
|
|
7197
|
+
}
|
|
7198
|
+
return reqConfig;
|
|
7199
|
+
});
|
|
7184
7200
|
this.apis = new ApiRegistry(
|
|
7185
7201
|
this._apiKey,
|
|
7186
7202
|
this._baseUrl,
|
|
@@ -7218,11 +7234,19 @@ var KadoaClient = class {
|
|
|
7218
7234
|
/**
|
|
7219
7235
|
* Get the API key
|
|
7220
7236
|
*
|
|
7221
|
-
* @returns The API key
|
|
7237
|
+
* @returns The API key (empty string when using Bearer auth)
|
|
7222
7238
|
*/
|
|
7223
7239
|
get apiKey() {
|
|
7224
7240
|
return this._apiKey;
|
|
7225
7241
|
}
|
|
7242
|
+
/**
|
|
7243
|
+
* Update the Bearer token used for authentication.
|
|
7244
|
+
* Call this after a Supabase JWT refresh so that subsequent requests
|
|
7245
|
+
* use the new token.
|
|
7246
|
+
*/
|
|
7247
|
+
setBearerToken(token) {
|
|
7248
|
+
this._bearerToken = token;
|
|
7249
|
+
}
|
|
7226
7250
|
/**
|
|
7227
7251
|
* Get the realtime connection (if enabled)
|
|
7228
7252
|
*/
|
|
@@ -7246,6 +7270,12 @@ var KadoaClient = class {
|
|
|
7246
7270
|
* @returns The Realtime instance
|
|
7247
7271
|
*/
|
|
7248
7272
|
async connectRealtime(options) {
|
|
7273
|
+
if (!this._apiKey) {
|
|
7274
|
+
throw new KadoaSdkException(
|
|
7275
|
+
"Realtime requires an API key. Bearer-only auth is not supported for WebSocket connections.",
|
|
7276
|
+
{ code: "VALIDATION_ERROR" }
|
|
7277
|
+
);
|
|
7278
|
+
}
|
|
7249
7279
|
if (!this._realtime) {
|
|
7250
7280
|
this._realtime = new Realtime({ apiKey: this._apiKey, ...options });
|
|
7251
7281
|
await this._realtime.connect();
|
|
@@ -7281,6 +7311,42 @@ var KadoaClient = class {
|
|
|
7281
7311
|
realtimeConnected: this.isRealtimeConnected()
|
|
7282
7312
|
};
|
|
7283
7313
|
}
|
|
7314
|
+
/**
|
|
7315
|
+
* List all teams accessible to the authenticated user.
|
|
7316
|
+
*
|
|
7317
|
+
* When called with a Bearer token (Supabase JWT), returns all teams the
|
|
7318
|
+
* human user belongs to. Without it, falls back to x-api-key auth which
|
|
7319
|
+
* only returns teams the service account (API key) belongs to.
|
|
7320
|
+
*/
|
|
7321
|
+
async listTeams(opts) {
|
|
7322
|
+
const headers = opts?.bearerToken ? { Authorization: `Bearer ${opts.bearerToken}` } : void 0;
|
|
7323
|
+
const response = await this._axiosInstance.get("/v5/user", {
|
|
7324
|
+
baseURL: this._baseUrl,
|
|
7325
|
+
...headers && { headers }
|
|
7326
|
+
});
|
|
7327
|
+
return response.data?.teams ?? [];
|
|
7328
|
+
}
|
|
7329
|
+
/**
|
|
7330
|
+
* Switch the active team for this session.
|
|
7331
|
+
*
|
|
7332
|
+
* Calls `POST /v5/auth/active-team` which updates the server-side
|
|
7333
|
+
* session→team mapping. Subsequent requests with the same JWT are
|
|
7334
|
+
* automatically scoped to the new team — no token refresh needed.
|
|
7335
|
+
*
|
|
7336
|
+
* @param teamId - The team ID to switch to (must be a team the user belongs to)
|
|
7337
|
+
*/
|
|
7338
|
+
async setActiveTeam(teamId) {
|
|
7339
|
+
if (!teamId?.trim()) {
|
|
7340
|
+
throw new KadoaSdkException("teamId is required", {
|
|
7341
|
+
code: "VALIDATION_ERROR"
|
|
7342
|
+
});
|
|
7343
|
+
}
|
|
7344
|
+
await this._axiosInstance.post(
|
|
7345
|
+
"/v5/auth/active-team",
|
|
7346
|
+
{ teamId },
|
|
7347
|
+
{ baseURL: this._baseUrl }
|
|
7348
|
+
);
|
|
7349
|
+
}
|
|
7284
7350
|
/**
|
|
7285
7351
|
* Dispose of the client and clean up resources
|
|
7286
7352
|
*/
|