codemie-sdk 0.1.460 → 0.1.462
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/index.cjs +29 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +29 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2220,6 +2220,8 @@ var CodeMieClient = class {
|
|
|
2220
2220
|
constructor(config) {
|
|
2221
2221
|
this.auth = null;
|
|
2222
2222
|
this.token = null;
|
|
2223
|
+
this._isJwtAuth = false;
|
|
2224
|
+
this._jwtToken = null;
|
|
2223
2225
|
const {
|
|
2224
2226
|
auth_server_url,
|
|
2225
2227
|
auth_realm_name,
|
|
@@ -2231,13 +2233,17 @@ var CodeMieClient = class {
|
|
|
2231
2233
|
external_token,
|
|
2232
2234
|
external_idp,
|
|
2233
2235
|
cookies,
|
|
2234
|
-
verify_ssl = true
|
|
2236
|
+
verify_ssl = true,
|
|
2237
|
+
jwt_token
|
|
2235
2238
|
} = config;
|
|
2236
2239
|
this.apiDomain = codemie_api_domain.replace(/\/$/, "");
|
|
2237
2240
|
this.verifySSL = verify_ssl;
|
|
2238
2241
|
this.cookies = cookies || {};
|
|
2239
2242
|
this.useCookieAuth = !!cookies && Object.keys(cookies).length > 0;
|
|
2240
|
-
|
|
2243
|
+
this._isJwtAuth = !!jwt_token;
|
|
2244
|
+
if (this._isJwtAuth) {
|
|
2245
|
+
this._jwtToken = jwt_token ?? null;
|
|
2246
|
+
} else if (!this.useCookieAuth) {
|
|
2241
2247
|
if (!auth_server_url || !auth_realm_name) {
|
|
2242
2248
|
throw new Error(
|
|
2243
2249
|
"auth_server_url and auth_realm_name are required when not using cookie authentication"
|
|
@@ -2256,13 +2262,21 @@ var CodeMieClient = class {
|
|
|
2256
2262
|
});
|
|
2257
2263
|
this.token = "";
|
|
2258
2264
|
}
|
|
2265
|
+
let tokenGetter;
|
|
2266
|
+
if (this._isJwtAuth) {
|
|
2267
|
+
tokenGetter = () => {
|
|
2268
|
+
if (!this._jwtToken) throw new Error("JWT token not configured");
|
|
2269
|
+
return Promise.resolve(this._jwtToken);
|
|
2270
|
+
};
|
|
2271
|
+
} else {
|
|
2272
|
+
tokenGetter = this.auth ? () => this.auth.getToken() : null;
|
|
2273
|
+
}
|
|
2259
2274
|
const authConfig = {
|
|
2260
2275
|
apiDomain: this.apiDomain,
|
|
2261
2276
|
token: this.token,
|
|
2262
2277
|
verifySSL: this.verifySSL,
|
|
2263
2278
|
cookies: this.cookies,
|
|
2264
|
-
|
|
2265
|
-
tokenGetter: this.auth ? () => this.auth.getToken() : null
|
|
2279
|
+
tokenGetter
|
|
2266
2280
|
};
|
|
2267
2281
|
this._analytics = new AnalyticsService(authConfig);
|
|
2268
2282
|
this._assistants = new AssistantService(authConfig);
|
|
@@ -2352,10 +2366,10 @@ var CodeMieClient = class {
|
|
|
2352
2366
|
/**
|
|
2353
2367
|
* Initialize the client by obtaining the initial token.
|
|
2354
2368
|
* This should be called after creating the client instance.
|
|
2355
|
-
* When using cookie-based authentication, this is a no-op.
|
|
2369
|
+
* When using cookie-based or JWT token authentication, this is a no-op.
|
|
2356
2370
|
*/
|
|
2357
2371
|
async initialize() {
|
|
2358
|
-
if (this.useCookieAuth) {
|
|
2372
|
+
if (this.useCookieAuth || this._isJwtAuth) {
|
|
2359
2373
|
return;
|
|
2360
2374
|
}
|
|
2361
2375
|
if (!this.auth) {
|
|
@@ -2372,6 +2386,9 @@ var CodeMieClient = class {
|
|
|
2372
2386
|
if (this.useCookieAuth) {
|
|
2373
2387
|
return null;
|
|
2374
2388
|
}
|
|
2389
|
+
if (this._isJwtAuth) {
|
|
2390
|
+
return this._jwtToken;
|
|
2391
|
+
}
|
|
2375
2392
|
if (!this.auth) {
|
|
2376
2393
|
throw new Error("Authentication not configured");
|
|
2377
2394
|
}
|
|
@@ -2384,11 +2401,16 @@ var CodeMieClient = class {
|
|
|
2384
2401
|
/**
|
|
2385
2402
|
* Force token refresh and update all services with the new token.
|
|
2386
2403
|
* Throws an error when using cookie-based authentication.
|
|
2404
|
+
* Returns the static token unchanged when using JWT authentication.
|
|
2387
2405
|
*/
|
|
2388
2406
|
async refreshToken() {
|
|
2389
2407
|
if (this.useCookieAuth) {
|
|
2390
2408
|
throw new Error("Token refresh is not supported with cookie-based authentication");
|
|
2391
2409
|
}
|
|
2410
|
+
if (this._isJwtAuth) {
|
|
2411
|
+
if (!this._jwtToken) throw new Error("JWT token not configured");
|
|
2412
|
+
return this._jwtToken;
|
|
2413
|
+
}
|
|
2392
2414
|
if (!this.auth) {
|
|
2393
2415
|
throw new Error("Authentication not configured");
|
|
2394
2416
|
}
|
|
@@ -2401,7 +2423,7 @@ var CodeMieClient = class {
|
|
|
2401
2423
|
* Reinitialize all services with the current token or cookies.
|
|
2402
2424
|
*/
|
|
2403
2425
|
async refreshServices() {
|
|
2404
|
-
if (this.useCookieAuth) {
|
|
2426
|
+
if (this.useCookieAuth || this._isJwtAuth) {
|
|
2405
2427
|
return;
|
|
2406
2428
|
}
|
|
2407
2429
|
if (!this.token) {
|