astro-tokenkit 1.0.12 → 1.0.13

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.js CHANGED
@@ -687,46 +687,66 @@ class TokenManager {
687
687
  }
688
688
 
689
689
  // packages/astro-tokenkit/src/config.ts
690
- let config = {
691
- runWithContext: undefined,
692
- getContextStore: undefined,
693
- setContextStore: undefined,
694
- baseURL: "",
695
- };
696
- let tokenManager;
690
+ const CONFIG_KEY = Symbol.for('astro-tokenkit.config');
691
+ const MANAGER_KEY = Symbol.for('astro-tokenkit.manager');
692
+ const globalStorage = globalThis;
693
+ // Initialize global storage if not present
694
+ if (!globalStorage[CONFIG_KEY]) {
695
+ globalStorage[CONFIG_KEY] = {
696
+ runWithContext: undefined,
697
+ getContextStore: undefined,
698
+ setContextStore: undefined,
699
+ baseURL: "",
700
+ };
701
+ }
697
702
  /**
698
703
  * Set configuration
699
704
  */
700
705
  function setConfig(userConfig) {
701
- const finalConfig = Object.assign(Object.assign({}, config), userConfig);
706
+ const currentConfig = globalStorage[CONFIG_KEY];
707
+ const finalConfig = Object.assign(Object.assign({}, currentConfig), userConfig);
702
708
  // Validate that getter and setter are defined together
703
709
  if ((finalConfig.getContextStore && !finalConfig.setContextStore) ||
704
710
  (!finalConfig.getContextStore && finalConfig.setContextStore)) {
705
711
  throw new Error("[TokenKit] getContextStore and setContextStore must be defined together.");
706
712
  }
707
- config = finalConfig;
713
+ globalStorage[CONFIG_KEY] = finalConfig;
708
714
  // Re-initialize global token manager if auth changed
709
- if (config.auth) {
710
- tokenManager = new TokenManager(config.auth, config.baseURL);
715
+ if (finalConfig.auth) {
716
+ globalStorage[MANAGER_KEY] = new TokenManager(finalConfig.auth, finalConfig.baseURL);
717
+ }
718
+ else {
719
+ globalStorage[MANAGER_KEY] = undefined;
711
720
  }
712
721
  }
713
722
  /**
714
723
  * Get current configuration
715
724
  */
716
725
  function getConfig() {
717
- return config;
726
+ return globalStorage[CONFIG_KEY];
718
727
  }
719
728
  /**
720
729
  * Get global token manager
721
730
  */
722
731
  function getTokenManager() {
723
- return tokenManager;
732
+ return globalStorage[MANAGER_KEY];
724
733
  }
725
734
  /**
726
735
  * Set global token manager (mainly for testing)
727
736
  */
728
737
  function setTokenManager(manager) {
729
- tokenManager = manager;
738
+ globalStorage[MANAGER_KEY] = manager;
739
+ }
740
+ // Handle injected configuration from Astro integration
741
+ try {
742
+ // @ts-ignore
743
+ const injectedConfig = typeof __TOKENKIT_CONFIG__ !== 'undefined' ? __TOKENKIT_CONFIG__ : undefined;
744
+ if (injectedConfig) {
745
+ setConfig(injectedConfig);
746
+ }
747
+ }
748
+ catch (e) {
749
+ // Ignore errors in environments where __TOKENKIT_CONFIG__ might be restricted
730
750
  }
731
751
 
732
752
  // packages/astro-tokenkit/src/client/context.ts
@@ -1211,11 +1231,23 @@ function createClient(config) {
1211
1231
  */
1212
1232
  function tokenKit(config) {
1213
1233
  setConfig(config);
1234
+ // Create a serializable version of the config for the runtime
1235
+ const serializableConfig = JSON.parse(JSON.stringify(config, (key, value) => {
1236
+ if (typeof value === 'function')
1237
+ return undefined;
1238
+ return value;
1239
+ }));
1214
1240
  return {
1215
1241
  name: 'astro-tokenkit',
1216
1242
  hooks: {
1217
- 'astro:config:setup': () => {
1218
- // Future-proofing: could add vite aliases or other setup here
1243
+ 'astro:config:setup': ({ updateConfig }) => {
1244
+ updateConfig({
1245
+ vite: {
1246
+ define: {
1247
+ '__TOKENKIT_CONFIG__': JSON.stringify(serializableConfig)
1248
+ }
1249
+ }
1250
+ });
1219
1251
  console.log('[TokenKit] Integration initialized');
1220
1252
  },
1221
1253
  },