astro-tokenkit 1.0.13 → 1.0.14

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.
@@ -15,7 +15,6 @@ import { getConfig, getTokenManager } from './config';
15
15
  */
16
16
  export function createMiddleware() {
17
17
  return (ctx, next) => __awaiter(this, void 0, void 0, function* () {
18
- var _a;
19
18
  const tokenManager = getTokenManager();
20
19
  const config = getConfig();
21
20
  const runLogic = () => __awaiter(this, void 0, void 0, function* () {
@@ -32,21 +31,18 @@ export function createMiddleware() {
32
31
  }
33
32
  return next();
34
33
  });
35
- // If getContextStore is defined, it means the context is managed externally (e.g., by a superior ALS)
36
- // We skip runWithContext to avoid nesting ALS.run() unnecessarily,
37
- // UNLESS a custom runWithContext is provided.
38
- if (config.getContextStore && !config.runWithContext) {
39
- let storage = config.getContextStore();
40
- if (storage)
41
- // Update existing reference
42
- storage.cookies = ctx.cookies;
43
- else if (config.setContextStore)
44
- config.setContextStore({ cookies: ctx.cookies });
45
- else
46
- console.error("[TokenKit] getContextStore returned null or undefined and no setter was found");
34
+ const setupAndRun = () => __awaiter(this, void 0, void 0, function* () {
35
+ if (config.setContextStore) {
36
+ config.setContextStore(ctx);
37
+ }
47
38
  return runLogic();
39
+ });
40
+ if (config.runWithContext) {
41
+ return config.runWithContext(ctx, setupAndRun);
42
+ }
43
+ if (config.setContextStore) {
44
+ return setupAndRun();
48
45
  }
49
- const runner = (_a = config.runWithContext) !== null && _a !== void 0 ? _a : defaultRunWithContext;
50
- return runner(ctx, runLogic);
46
+ return defaultRunWithContext(ctx, runLogic);
51
47
  });
52
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-tokenkit",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "A powerful API client for Astro with automatic token rotation, session management, and seamless context integration.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",