codemie-sdk 0.1.461 → 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.d.cts CHANGED
@@ -2655,6 +2655,7 @@ interface CodeMieClientConfig {
2655
2655
  external_idp?: string;
2656
2656
  cookies?: Record<string, string>;
2657
2657
  verify_ssl?: boolean;
2658
+ jwt_token?: string;
2658
2659
  }
2659
2660
  declare class CodeMieClient {
2660
2661
  private auth;
@@ -2663,6 +2664,8 @@ declare class CodeMieClient {
2663
2664
  private apiDomain;
2664
2665
  private verifySSL;
2665
2666
  private useCookieAuth;
2667
+ private _isJwtAuth;
2668
+ private _jwtToken;
2666
2669
  private _analytics;
2667
2670
  private _assistants;
2668
2671
  private _conversations;
@@ -2727,7 +2730,7 @@ declare class CodeMieClient {
2727
2730
  /**
2728
2731
  * Initialize the client by obtaining the initial token.
2729
2732
  * This should be called after creating the client instance.
2730
- * When using cookie-based authentication, this is a no-op.
2733
+ * When using cookie-based or JWT token authentication, this is a no-op.
2731
2734
  */
2732
2735
  initialize(): Promise<void>;
2733
2736
  /**
@@ -2738,6 +2741,7 @@ declare class CodeMieClient {
2738
2741
  /**
2739
2742
  * Force token refresh and update all services with the new token.
2740
2743
  * Throws an error when using cookie-based authentication.
2744
+ * Returns the static token unchanged when using JWT authentication.
2741
2745
  */
2742
2746
  refreshToken(): Promise<string>;
2743
2747
  /**
package/dist/index.d.ts CHANGED
@@ -2655,6 +2655,7 @@ interface CodeMieClientConfig {
2655
2655
  external_idp?: string;
2656
2656
  cookies?: Record<string, string>;
2657
2657
  verify_ssl?: boolean;
2658
+ jwt_token?: string;
2658
2659
  }
2659
2660
  declare class CodeMieClient {
2660
2661
  private auth;
@@ -2663,6 +2664,8 @@ declare class CodeMieClient {
2663
2664
  private apiDomain;
2664
2665
  private verifySSL;
2665
2666
  private useCookieAuth;
2667
+ private _isJwtAuth;
2668
+ private _jwtToken;
2666
2669
  private _analytics;
2667
2670
  private _assistants;
2668
2671
  private _conversations;
@@ -2727,7 +2730,7 @@ declare class CodeMieClient {
2727
2730
  /**
2728
2731
  * Initialize the client by obtaining the initial token.
2729
2732
  * This should be called after creating the client instance.
2730
- * When using cookie-based authentication, this is a no-op.
2733
+ * When using cookie-based or JWT token authentication, this is a no-op.
2731
2734
  */
2732
2735
  initialize(): Promise<void>;
2733
2736
  /**
@@ -2738,6 +2741,7 @@ declare class CodeMieClient {
2738
2741
  /**
2739
2742
  * Force token refresh and update all services with the new token.
2740
2743
  * Throws an error when using cookie-based authentication.
2744
+ * Returns the static token unchanged when using JWT authentication.
2741
2745
  */
2742
2746
  refreshToken(): Promise<string>;
2743
2747
  /**
package/dist/index.js CHANGED
@@ -2117,6 +2117,8 @@ var CodeMieClient = class {
2117
2117
  constructor(config) {
2118
2118
  this.auth = null;
2119
2119
  this.token = null;
2120
+ this._isJwtAuth = false;
2121
+ this._jwtToken = null;
2120
2122
  const {
2121
2123
  auth_server_url,
2122
2124
  auth_realm_name,
@@ -2128,13 +2130,17 @@ var CodeMieClient = class {
2128
2130
  external_token,
2129
2131
  external_idp,
2130
2132
  cookies,
2131
- verify_ssl = true
2133
+ verify_ssl = true,
2134
+ jwt_token
2132
2135
  } = config;
2133
2136
  this.apiDomain = codemie_api_domain.replace(/\/$/, "");
2134
2137
  this.verifySSL = verify_ssl;
2135
2138
  this.cookies = cookies || {};
2136
2139
  this.useCookieAuth = !!cookies && Object.keys(cookies).length > 0;
2137
- if (!this.useCookieAuth) {
2140
+ this._isJwtAuth = !!jwt_token;
2141
+ if (this._isJwtAuth) {
2142
+ this._jwtToken = jwt_token ?? null;
2143
+ } else if (!this.useCookieAuth) {
2138
2144
  if (!auth_server_url || !auth_realm_name) {
2139
2145
  throw new Error(
2140
2146
  "auth_server_url and auth_realm_name are required when not using cookie authentication"
@@ -2153,13 +2159,21 @@ var CodeMieClient = class {
2153
2159
  });
2154
2160
  this.token = "";
2155
2161
  }
2162
+ let tokenGetter;
2163
+ if (this._isJwtAuth) {
2164
+ tokenGetter = () => {
2165
+ if (!this._jwtToken) throw new Error("JWT token not configured");
2166
+ return Promise.resolve(this._jwtToken);
2167
+ };
2168
+ } else {
2169
+ tokenGetter = this.auth ? () => this.auth.getToken() : null;
2170
+ }
2156
2171
  const authConfig = {
2157
2172
  apiDomain: this.apiDomain,
2158
2173
  token: this.token,
2159
2174
  verifySSL: this.verifySSL,
2160
2175
  cookies: this.cookies,
2161
- // biome-ignore lint/style/noNonNullAssertion: auth is non-null here, guarded by ternary
2162
- tokenGetter: this.auth ? () => this.auth.getToken() : null
2176
+ tokenGetter
2163
2177
  };
2164
2178
  this._analytics = new AnalyticsService(authConfig);
2165
2179
  this._assistants = new AssistantService(authConfig);
@@ -2249,10 +2263,10 @@ var CodeMieClient = class {
2249
2263
  /**
2250
2264
  * Initialize the client by obtaining the initial token.
2251
2265
  * This should be called after creating the client instance.
2252
- * When using cookie-based authentication, this is a no-op.
2266
+ * When using cookie-based or JWT token authentication, this is a no-op.
2253
2267
  */
2254
2268
  async initialize() {
2255
- if (this.useCookieAuth) {
2269
+ if (this.useCookieAuth || this._isJwtAuth) {
2256
2270
  return;
2257
2271
  }
2258
2272
  if (!this.auth) {
@@ -2269,6 +2283,9 @@ var CodeMieClient = class {
2269
2283
  if (this.useCookieAuth) {
2270
2284
  return null;
2271
2285
  }
2286
+ if (this._isJwtAuth) {
2287
+ return this._jwtToken;
2288
+ }
2272
2289
  if (!this.auth) {
2273
2290
  throw new Error("Authentication not configured");
2274
2291
  }
@@ -2281,11 +2298,16 @@ var CodeMieClient = class {
2281
2298
  /**
2282
2299
  * Force token refresh and update all services with the new token.
2283
2300
  * Throws an error when using cookie-based authentication.
2301
+ * Returns the static token unchanged when using JWT authentication.
2284
2302
  */
2285
2303
  async refreshToken() {
2286
2304
  if (this.useCookieAuth) {
2287
2305
  throw new Error("Token refresh is not supported with cookie-based authentication");
2288
2306
  }
2307
+ if (this._isJwtAuth) {
2308
+ if (!this._jwtToken) throw new Error("JWT token not configured");
2309
+ return this._jwtToken;
2310
+ }
2289
2311
  if (!this.auth) {
2290
2312
  throw new Error("Authentication not configured");
2291
2313
  }
@@ -2298,7 +2320,7 @@ var CodeMieClient = class {
2298
2320
  * Reinitialize all services with the current token or cookies.
2299
2321
  */
2300
2322
  async refreshServices() {
2301
- if (this.useCookieAuth) {
2323
+ if (this.useCookieAuth || this._isJwtAuth) {
2302
2324
  return;
2303
2325
  }
2304
2326
  if (!this.token) {