tenneo-auth-plugin 0.1.9 → 0.1.10

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/README.md CHANGED
@@ -138,6 +138,7 @@ function App() {
138
138
 
139
139
  | Prop | Type | Required | Default | Description |
140
140
  |------|------|----------|---------|-------------|
141
+ | `config` | `SDKConfig` | No | - | Pass all configuration as a single object (alternative to individual props) |
141
142
  | `tenantCode` | `string` | No | - | Tenant code for configuration resolution |
142
143
  | `apiBaseUrl` | `string` | Yes | - | Tenant resolution service base URL |
143
144
  | `authServerUrl` | `string` | Yes | - | Authorization server base URL (OIDC authorize) |
package/dist/index.d.mts CHANGED
@@ -206,6 +206,80 @@ declare function isAccessTokenExpired(): boolean;
206
206
 
207
207
  declare function useAuthContext(): AuthContextValue;
208
208
 
209
+ /**
210
+ * Configuration types.
211
+ *
212
+ * There is no "internal vs runtime" config anymore.
213
+ * Everything is provided by the host app via `AuthProvider` props / `setConfig()`.
214
+ */
215
+ interface SDKConfig {
216
+ /** Tenant resolution service base URL. */
217
+ apiBaseUrl?: string;
218
+ /** Auth API base URL (token exchange/refresh/logout). */
219
+ apiAuthBaseUrl?: string;
220
+ /** Authorization server base URL (OIDC authorize endpoint). */
221
+ authServerUrl?: string;
222
+ /** Callback/redirect URL (full URL). */
223
+ callbackUrl?: string;
224
+ /** Optional tenant code/key (used for tenant resolution). */
225
+ tenantCode?: string;
226
+ /** Optional runtime identifiers (may be returned from tenant API). */
227
+ clientId?: string;
228
+ tenantId?: string;
229
+ clientCode?: string;
230
+ /** Optional UI/runtime overrides. */
231
+ basePath?: string;
232
+ }
233
+ type HostConfigOverride = SDKConfig;
234
+ interface ResolvedConfig {
235
+ apiBaseUrl: string;
236
+ authServerUrl: string;
237
+ callbackUrl: string;
238
+ clientCode: string;
239
+ }
240
+ type ResolvedHostConfig = ResolvedConfig;
241
+
242
+ /**
243
+ * OAuth constants and storage keys. No config resolution — pure constants.
244
+ */
245
+ declare const OAUTH_CONSTANTS: {
246
+ readonly SCOPES: "openid profile email";
247
+ readonly RESPONSE_TYPE: "code";
248
+ readonly CODE_CHALLENGE_METHOD: "S256";
249
+ readonly TOKEN_GRANT_TYPE: "authorization_code";
250
+ readonly REFRESH_GRANT_TYPE: "refresh_token";
251
+ };
252
+ declare const STORAGE_KEY_PREFIX = "tenneo_auth_";
253
+ declare const STORAGE_KEYS: {
254
+ readonly authServerUrl: "tenneo_auth_auth_server_url";
255
+ readonly clientId: "tenneo_auth_client_id";
256
+ readonly redirectUri: "tenneo_auth_redirect_uri";
257
+ readonly tenantId: "tenneo_auth_tenant_id";
258
+ readonly codeVerifier: "tenneo_auth_code_verifier";
259
+ readonly state: "tenneo_auth_state";
260
+ readonly accessToken: "tenneo_auth_access_token";
261
+ readonly refreshToken: "tenneo_auth_refresh_token";
262
+ readonly expiresAt: "tenneo_auth_expires_at";
263
+ };
264
+
265
+ /**
266
+ * Config: minimal host-driven config store + facade.
267
+ *
268
+ * No "internal" or "runtime" config separation.
269
+ * Everything comes from the host app via `setConfig()` / `AuthProvider` props.
270
+ */
271
+
272
+ declare function resolveConfig(overrides?: HostConfigOverride): ResolvedConfig;
273
+ declare function getConfig(): ResolvedConfig;
274
+ declare function setConfig(overrides: HostConfigOverride): void;
275
+ declare const Config: {
276
+ readonly getApiBaseUrl: () => string;
277
+ readonly getAuthServerUrl: () => string;
278
+ readonly getClientCode: () => string;
279
+ readonly getRedirectUri: () => string;
280
+ readonly getAll: () => ResolvedHostConfig;
281
+ };
282
+
209
283
  /**
210
284
  * React Context Provider for authentication state (FINAL)
211
285
  */
@@ -213,6 +287,8 @@ declare function useAuthContext(): AuthContextValue;
213
287
  interface AuthProviderProps {
214
288
  children: React.ReactNode;
215
289
  autoInit?: boolean;
290
+ /** Optional config object from host app (alternative to passing individual props). */
291
+ config?: SDKConfig;
216
292
  /** Tenant code from host app (used to resolve tenant via GET /api/tenant/v1/public/tenants/by-code/{tenantCode}). */
217
293
  tenantCode?: string;
218
294
  /** Tenant resolution base URL (host app). */
@@ -229,7 +305,7 @@ interface AuthProviderProps {
229
305
  /**
230
306
  * AuthProvider – UI-facing auth state only
231
307
  */
232
- declare function AuthProvider({ children, autoInit, tenantCode, apiBaseUrl, authServerUrl, callbackUrl, appId, storageAdapter, }: AuthProviderProps): React.JSX.Element;
308
+ declare function AuthProvider({ children, autoInit, config, tenantCode, apiBaseUrl, authServerUrl, callbackUrl, appId, storageAdapter, }: AuthProviderProps): React.JSX.Element;
233
309
 
234
310
  interface AuthCallbackProps {
235
311
  loginPath?: string;
@@ -415,80 +491,6 @@ declare function isCallbackUrl(): boolean;
415
491
 
416
492
  declare function resolveTenant(tenantKey: string): Promise<TenantConfig | null>;
417
493
 
418
- /**
419
- * Configuration types.
420
- *
421
- * There is no "internal vs runtime" config anymore.
422
- * Everything is provided by the host app via `AuthProvider` props / `setConfig()`.
423
- */
424
- interface SDKConfig {
425
- /** Tenant resolution service base URL. */
426
- apiBaseUrl?: string;
427
- /** Auth API base URL (token exchange/refresh/logout). */
428
- apiAuthBaseUrl?: string;
429
- /** Authorization server base URL (OIDC authorize endpoint). */
430
- authServerUrl?: string;
431
- /** Callback/redirect URL (full URL). */
432
- callbackUrl?: string;
433
- /** Optional tenant code/key (used for tenant resolution). */
434
- tenantCode?: string;
435
- /** Optional runtime identifiers (may be returned from tenant API). */
436
- clientId?: string;
437
- tenantId?: string;
438
- clientCode?: string;
439
- /** Optional UI/runtime overrides. */
440
- basePath?: string;
441
- }
442
- type HostConfigOverride = SDKConfig;
443
- interface ResolvedConfig {
444
- apiBaseUrl: string;
445
- authServerUrl: string;
446
- callbackUrl: string;
447
- clientCode: string;
448
- }
449
- type ResolvedHostConfig = ResolvedConfig;
450
-
451
- /**
452
- * OAuth constants and storage keys. No config resolution — pure constants.
453
- */
454
- declare const OAUTH_CONSTANTS: {
455
- readonly SCOPES: "openid profile email";
456
- readonly RESPONSE_TYPE: "code";
457
- readonly CODE_CHALLENGE_METHOD: "S256";
458
- readonly TOKEN_GRANT_TYPE: "authorization_code";
459
- readonly REFRESH_GRANT_TYPE: "refresh_token";
460
- };
461
- declare const STORAGE_KEY_PREFIX = "tenneo_auth_";
462
- declare const STORAGE_KEYS: {
463
- readonly authServerUrl: "tenneo_auth_auth_server_url";
464
- readonly clientId: "tenneo_auth_client_id";
465
- readonly redirectUri: "tenneo_auth_redirect_uri";
466
- readonly tenantId: "tenneo_auth_tenant_id";
467
- readonly codeVerifier: "tenneo_auth_code_verifier";
468
- readonly state: "tenneo_auth_state";
469
- readonly accessToken: "tenneo_auth_access_token";
470
- readonly refreshToken: "tenneo_auth_refresh_token";
471
- readonly expiresAt: "tenneo_auth_expires_at";
472
- };
473
-
474
- /**
475
- * Config: minimal host-driven config store + facade.
476
- *
477
- * No "internal" or "runtime" config separation.
478
- * Everything comes from the host app via `setConfig()` / `AuthProvider` props.
479
- */
480
-
481
- declare function resolveConfig(overrides?: HostConfigOverride): ResolvedConfig;
482
- declare function getConfig(): ResolvedConfig;
483
- declare function setConfig(overrides: HostConfigOverride): void;
484
- declare const Config: {
485
- readonly getApiBaseUrl: () => string;
486
- readonly getAuthServerUrl: () => string;
487
- readonly getClientCode: () => string;
488
- readonly getRedirectUri: () => string;
489
- readonly getAll: () => ResolvedHostConfig;
490
- };
491
-
492
494
  /**
493
495
  * Security and error utilities for authentication.
494
496
  * Domain layer: sanitized errors and HTTPS enforcement.
package/dist/index.d.ts CHANGED
@@ -206,6 +206,80 @@ declare function isAccessTokenExpired(): boolean;
206
206
 
207
207
  declare function useAuthContext(): AuthContextValue;
208
208
 
209
+ /**
210
+ * Configuration types.
211
+ *
212
+ * There is no "internal vs runtime" config anymore.
213
+ * Everything is provided by the host app via `AuthProvider` props / `setConfig()`.
214
+ */
215
+ interface SDKConfig {
216
+ /** Tenant resolution service base URL. */
217
+ apiBaseUrl?: string;
218
+ /** Auth API base URL (token exchange/refresh/logout). */
219
+ apiAuthBaseUrl?: string;
220
+ /** Authorization server base URL (OIDC authorize endpoint). */
221
+ authServerUrl?: string;
222
+ /** Callback/redirect URL (full URL). */
223
+ callbackUrl?: string;
224
+ /** Optional tenant code/key (used for tenant resolution). */
225
+ tenantCode?: string;
226
+ /** Optional runtime identifiers (may be returned from tenant API). */
227
+ clientId?: string;
228
+ tenantId?: string;
229
+ clientCode?: string;
230
+ /** Optional UI/runtime overrides. */
231
+ basePath?: string;
232
+ }
233
+ type HostConfigOverride = SDKConfig;
234
+ interface ResolvedConfig {
235
+ apiBaseUrl: string;
236
+ authServerUrl: string;
237
+ callbackUrl: string;
238
+ clientCode: string;
239
+ }
240
+ type ResolvedHostConfig = ResolvedConfig;
241
+
242
+ /**
243
+ * OAuth constants and storage keys. No config resolution — pure constants.
244
+ */
245
+ declare const OAUTH_CONSTANTS: {
246
+ readonly SCOPES: "openid profile email";
247
+ readonly RESPONSE_TYPE: "code";
248
+ readonly CODE_CHALLENGE_METHOD: "S256";
249
+ readonly TOKEN_GRANT_TYPE: "authorization_code";
250
+ readonly REFRESH_GRANT_TYPE: "refresh_token";
251
+ };
252
+ declare const STORAGE_KEY_PREFIX = "tenneo_auth_";
253
+ declare const STORAGE_KEYS: {
254
+ readonly authServerUrl: "tenneo_auth_auth_server_url";
255
+ readonly clientId: "tenneo_auth_client_id";
256
+ readonly redirectUri: "tenneo_auth_redirect_uri";
257
+ readonly tenantId: "tenneo_auth_tenant_id";
258
+ readonly codeVerifier: "tenneo_auth_code_verifier";
259
+ readonly state: "tenneo_auth_state";
260
+ readonly accessToken: "tenneo_auth_access_token";
261
+ readonly refreshToken: "tenneo_auth_refresh_token";
262
+ readonly expiresAt: "tenneo_auth_expires_at";
263
+ };
264
+
265
+ /**
266
+ * Config: minimal host-driven config store + facade.
267
+ *
268
+ * No "internal" or "runtime" config separation.
269
+ * Everything comes from the host app via `setConfig()` / `AuthProvider` props.
270
+ */
271
+
272
+ declare function resolveConfig(overrides?: HostConfigOverride): ResolvedConfig;
273
+ declare function getConfig(): ResolvedConfig;
274
+ declare function setConfig(overrides: HostConfigOverride): void;
275
+ declare const Config: {
276
+ readonly getApiBaseUrl: () => string;
277
+ readonly getAuthServerUrl: () => string;
278
+ readonly getClientCode: () => string;
279
+ readonly getRedirectUri: () => string;
280
+ readonly getAll: () => ResolvedHostConfig;
281
+ };
282
+
209
283
  /**
210
284
  * React Context Provider for authentication state (FINAL)
211
285
  */
@@ -213,6 +287,8 @@ declare function useAuthContext(): AuthContextValue;
213
287
  interface AuthProviderProps {
214
288
  children: React.ReactNode;
215
289
  autoInit?: boolean;
290
+ /** Optional config object from host app (alternative to passing individual props). */
291
+ config?: SDKConfig;
216
292
  /** Tenant code from host app (used to resolve tenant via GET /api/tenant/v1/public/tenants/by-code/{tenantCode}). */
217
293
  tenantCode?: string;
218
294
  /** Tenant resolution base URL (host app). */
@@ -229,7 +305,7 @@ interface AuthProviderProps {
229
305
  /**
230
306
  * AuthProvider – UI-facing auth state only
231
307
  */
232
- declare function AuthProvider({ children, autoInit, tenantCode, apiBaseUrl, authServerUrl, callbackUrl, appId, storageAdapter, }: AuthProviderProps): React.JSX.Element;
308
+ declare function AuthProvider({ children, autoInit, config, tenantCode, apiBaseUrl, authServerUrl, callbackUrl, appId, storageAdapter, }: AuthProviderProps): React.JSX.Element;
233
309
 
234
310
  interface AuthCallbackProps {
235
311
  loginPath?: string;
@@ -415,80 +491,6 @@ declare function isCallbackUrl(): boolean;
415
491
 
416
492
  declare function resolveTenant(tenantKey: string): Promise<TenantConfig | null>;
417
493
 
418
- /**
419
- * Configuration types.
420
- *
421
- * There is no "internal vs runtime" config anymore.
422
- * Everything is provided by the host app via `AuthProvider` props / `setConfig()`.
423
- */
424
- interface SDKConfig {
425
- /** Tenant resolution service base URL. */
426
- apiBaseUrl?: string;
427
- /** Auth API base URL (token exchange/refresh/logout). */
428
- apiAuthBaseUrl?: string;
429
- /** Authorization server base URL (OIDC authorize endpoint). */
430
- authServerUrl?: string;
431
- /** Callback/redirect URL (full URL). */
432
- callbackUrl?: string;
433
- /** Optional tenant code/key (used for tenant resolution). */
434
- tenantCode?: string;
435
- /** Optional runtime identifiers (may be returned from tenant API). */
436
- clientId?: string;
437
- tenantId?: string;
438
- clientCode?: string;
439
- /** Optional UI/runtime overrides. */
440
- basePath?: string;
441
- }
442
- type HostConfigOverride = SDKConfig;
443
- interface ResolvedConfig {
444
- apiBaseUrl: string;
445
- authServerUrl: string;
446
- callbackUrl: string;
447
- clientCode: string;
448
- }
449
- type ResolvedHostConfig = ResolvedConfig;
450
-
451
- /**
452
- * OAuth constants and storage keys. No config resolution — pure constants.
453
- */
454
- declare const OAUTH_CONSTANTS: {
455
- readonly SCOPES: "openid profile email";
456
- readonly RESPONSE_TYPE: "code";
457
- readonly CODE_CHALLENGE_METHOD: "S256";
458
- readonly TOKEN_GRANT_TYPE: "authorization_code";
459
- readonly REFRESH_GRANT_TYPE: "refresh_token";
460
- };
461
- declare const STORAGE_KEY_PREFIX = "tenneo_auth_";
462
- declare const STORAGE_KEYS: {
463
- readonly authServerUrl: "tenneo_auth_auth_server_url";
464
- readonly clientId: "tenneo_auth_client_id";
465
- readonly redirectUri: "tenneo_auth_redirect_uri";
466
- readonly tenantId: "tenneo_auth_tenant_id";
467
- readonly codeVerifier: "tenneo_auth_code_verifier";
468
- readonly state: "tenneo_auth_state";
469
- readonly accessToken: "tenneo_auth_access_token";
470
- readonly refreshToken: "tenneo_auth_refresh_token";
471
- readonly expiresAt: "tenneo_auth_expires_at";
472
- };
473
-
474
- /**
475
- * Config: minimal host-driven config store + facade.
476
- *
477
- * No "internal" or "runtime" config separation.
478
- * Everything comes from the host app via `setConfig()` / `AuthProvider` props.
479
- */
480
-
481
- declare function resolveConfig(overrides?: HostConfigOverride): ResolvedConfig;
482
- declare function getConfig(): ResolvedConfig;
483
- declare function setConfig(overrides: HostConfigOverride): void;
484
- declare const Config: {
485
- readonly getApiBaseUrl: () => string;
486
- readonly getAuthServerUrl: () => string;
487
- readonly getClientCode: () => string;
488
- readonly getRedirectUri: () => string;
489
- readonly getAll: () => ResolvedHostConfig;
490
- };
491
-
492
494
  /**
493
495
  * Security and error utilities for authentication.
494
496
  * Domain layer: sanitized errors and HTTPS enforcement.
package/dist/index.js CHANGED
@@ -2882,6 +2882,7 @@ function createAuthEngine(config) {
2882
2882
  function AuthProvider({
2883
2883
  children,
2884
2884
  autoInit = true,
2885
+ config,
2885
2886
  tenantCode,
2886
2887
  apiBaseUrl,
2887
2888
  authServerUrl,
@@ -2889,7 +2890,11 @@ function AuthProvider({
2889
2890
  appId = "",
2890
2891
  storageAdapter
2891
2892
  }) {
2892
- const resolvedTenantKey = tenantCode ?? Config.getClientCode();
2893
+ const mergedTenantCode = tenantCode ?? config?.tenantCode;
2894
+ const mergedApiBaseUrl = apiBaseUrl ?? config?.apiBaseUrl;
2895
+ const mergedAuthServerUrl = authServerUrl ?? config?.authServerUrl;
2896
+ const mergedCallbackUrl = callbackUrl ?? config?.callbackUrl;
2897
+ const resolvedTenantKey = mergedTenantCode ?? Config.getClientCode();
2893
2898
  const namespace = react.useMemo(
2894
2899
  () => ({ tenantId: resolvedTenantKey ?? "", appId: appId ?? "" }),
2895
2900
  [resolvedTenantKey, appId]
@@ -2898,39 +2903,39 @@ function AuthProvider({
2898
2903
  const engineRef = react.useRef(null);
2899
2904
  react.useLayoutEffect(() => {
2900
2905
  logger.debug("[AuthProvider] Host config props", {
2901
- tenantCode: tenantCode ?? "(not provided)",
2902
- apiBaseUrl: apiBaseUrl ? apiBaseUrl : "(empty)",
2903
- authServerUrl: authServerUrl ? authServerUrl : "(empty)",
2904
- callbackUrl: callbackUrl ? callbackUrl : "(empty)"
2906
+ tenantCode: mergedTenantCode ?? "(not provided)",
2907
+ apiBaseUrl: mergedApiBaseUrl ? mergedApiBaseUrl : "(empty)",
2908
+ authServerUrl: mergedAuthServerUrl ? mergedAuthServerUrl : "(empty)",
2909
+ callbackUrl: mergedCallbackUrl ? mergedCallbackUrl : "(empty)"
2905
2910
  });
2906
- if (!authServerUrl || !authServerUrl.trim()) {
2911
+ if (!mergedAuthServerUrl || !mergedAuthServerUrl.trim()) {
2907
2912
  logger.warn("[AuthProvider] authServerUrl missing from host props");
2908
2913
  }
2909
- if (!callbackUrl || !callbackUrl.trim()) {
2914
+ if (!mergedCallbackUrl || !mergedCallbackUrl.trim()) {
2910
2915
  logger.warn("[AuthProvider] callbackUrl missing from host props");
2911
2916
  }
2912
2917
  setConfig({
2913
- ...tenantCode ? { tenantCode } : {},
2914
- ...apiBaseUrl ? { apiBaseUrl } : {},
2915
- ...authServerUrl ? { authServerUrl } : {},
2916
- ...callbackUrl ? { callbackUrl } : {}
2918
+ ...mergedTenantCode ? { tenantCode: mergedTenantCode } : {},
2919
+ ...mergedApiBaseUrl ? { apiBaseUrl: mergedApiBaseUrl } : {},
2920
+ ...mergedAuthServerUrl ? { authServerUrl: mergedAuthServerUrl } : {},
2921
+ ...mergedCallbackUrl ? { callbackUrl: mergedCallbackUrl } : {}
2917
2922
  });
2918
2923
  return () => {
2919
2924
  clearConfigOverrides();
2920
2925
  };
2921
- }, [tenantCode, apiBaseUrl, authServerUrl, callbackUrl]);
2926
+ }, [mergedTenantCode, mergedApiBaseUrl, mergedAuthServerUrl, mergedCallbackUrl]);
2922
2927
  react.useEffect(() => {
2923
2928
  try {
2924
2929
  const payload = {
2925
- tenantCode: tenantCode ?? "",
2926
- apiBaseUrl: apiBaseUrl ?? "",
2927
- authServerUrl: authServerUrl ?? "",
2928
- callbackUrl: callbackUrl ?? ""
2930
+ tenantCode: mergedTenantCode ?? "",
2931
+ apiBaseUrl: mergedApiBaseUrl ?? "",
2932
+ authServerUrl: mergedAuthServerUrl ?? "",
2933
+ callbackUrl: mergedCallbackUrl ?? ""
2929
2934
  };
2930
2935
  setStorage(getStorageKey("host_config"), JSON.stringify(payload));
2931
2936
  } catch {
2932
2937
  }
2933
- }, [tenantCode, apiBaseUrl, authServerUrl, callbackUrl]);
2938
+ }, [mergedTenantCode, mergedApiBaseUrl, mergedAuthServerUrl, mergedCallbackUrl]);
2934
2939
  react.useLayoutEffect(() => {
2935
2940
  setStorageKeyPrefix(resolvedTenantKey ?? "");
2936
2941
  const adapter = storageAdapter !== void 0 && storageAdapter !== null ? storageAdapter : createSecureSessionStorageAdapter(namespace);