astro-tokenkit 1.0.14 → 1.0.16
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 +25 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +25 -1
- package/dist/index.js.map +1 -1
- package/dist/integration.js +8 -1
- package/dist/middleware.cjs +796 -0
- package/dist/middleware.cjs.map +1 -0
- package/dist/middleware.d.ts +9 -2
- package/dist/middleware.js +758 -13
- package/dist/middleware.js.map +1 -0
- package/dist/types.d.ts +5 -0
- package/package.json +6 -1
package/dist/index.d.ts
CHANGED
|
@@ -221,6 +221,11 @@ interface ClientConfig {
|
|
|
221
221
|
* TokenKit Global Configuration
|
|
222
222
|
*/
|
|
223
223
|
interface TokenKitConfig extends Partial<ClientConfig> {
|
|
224
|
+
/**
|
|
225
|
+
* Whether to automatically inject the middleware (default: true).
|
|
226
|
+
* If false, you must manually export onRequest = api.middleware() in src/middleware.ts
|
|
227
|
+
*/
|
|
228
|
+
autoMiddleware?: boolean;
|
|
224
229
|
}
|
|
225
230
|
/**
|
|
226
231
|
* API Error
|
package/dist/index.js
CHANGED
|
@@ -824,6 +824,7 @@ function sleep(ms) {
|
|
|
824
824
|
}
|
|
825
825
|
|
|
826
826
|
// packages/astro-tokenkit/src/middleware.ts
|
|
827
|
+
const LOGGED_KEY = Symbol.for('astro-tokenkit.middleware.logged');
|
|
827
828
|
/**
|
|
828
829
|
* Create middleware for context binding and automatic token rotation
|
|
829
830
|
*/
|
|
@@ -831,6 +832,22 @@ function createMiddleware() {
|
|
|
831
832
|
return (ctx, next) => __awaiter(this, void 0, void 0, function* () {
|
|
832
833
|
const tokenManager = getTokenManager();
|
|
833
834
|
const config = getConfig();
|
|
835
|
+
const globalStorage = globalThis;
|
|
836
|
+
if (!globalStorage[LOGGED_KEY]) {
|
|
837
|
+
const authStatus = tokenManager ? 'enabled' : 'disabled';
|
|
838
|
+
let contextStrategy = 'default';
|
|
839
|
+
if (config.runWithContext) {
|
|
840
|
+
contextStrategy = 'custom (runWithContext)';
|
|
841
|
+
}
|
|
842
|
+
else if (config.setContextStore) {
|
|
843
|
+
contextStrategy = 'custom (getter/setter)';
|
|
844
|
+
}
|
|
845
|
+
else if (config.context) {
|
|
846
|
+
contextStrategy = 'custom (external AsyncLocalStorage)';
|
|
847
|
+
}
|
|
848
|
+
console.log(`[TokenKit] Middleware initialized (auth: ${authStatus}, context: ${contextStrategy})`);
|
|
849
|
+
globalStorage[LOGGED_KEY] = true;
|
|
850
|
+
}
|
|
834
851
|
const runLogic = () => __awaiter(this, void 0, void 0, function* () {
|
|
835
852
|
// Proactively ensure a valid session if auth is configured
|
|
836
853
|
if (tokenManager) {
|
|
@@ -1236,7 +1253,7 @@ function tokenKit(config) {
|
|
|
1236
1253
|
return {
|
|
1237
1254
|
name: 'astro-tokenkit',
|
|
1238
1255
|
hooks: {
|
|
1239
|
-
'astro:config:setup': ({ updateConfig }) => {
|
|
1256
|
+
'astro:config:setup': ({ updateConfig, addMiddleware }) => {
|
|
1240
1257
|
updateConfig({
|
|
1241
1258
|
vite: {
|
|
1242
1259
|
define: {
|
|
@@ -1244,6 +1261,13 @@ function tokenKit(config) {
|
|
|
1244
1261
|
}
|
|
1245
1262
|
}
|
|
1246
1263
|
});
|
|
1264
|
+
// Autoinject the middleware
|
|
1265
|
+
if (config.autoMiddleware !== false) {
|
|
1266
|
+
addMiddleware({
|
|
1267
|
+
entrypoint: 'astro-tokenkit/middleware',
|
|
1268
|
+
order: 'pre'
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1247
1271
|
console.log('[TokenKit] Integration initialized');
|
|
1248
1272
|
},
|
|
1249
1273
|
},
|