astro-tokenkit 1.0.19 → 1.0.20

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
@@ -307,3 +307,17 @@ Run on a standard development machine using `npm run bench`:
307
307
  ## License
308
308
 
309
309
  MIT © [oamm](https://github.com/oamm)
310
+
311
+ ---
312
+
313
+ ## Playground
314
+
315
+ We've included a [playground](./playground) project to quickly test the integration.
316
+
317
+ To run the playground:
318
+
319
+ ```bash
320
+ npm run playground
321
+ ```
322
+
323
+ This will install the dependencies and start the Astro dev server for the playground.
@@ -143,6 +143,7 @@ export class APIClient {
143
143
  executeRequest(config, ctx, attempt) {
144
144
  return __awaiter(this, void 0, void 0, function* () {
145
145
  var _a, _b, _c, _d, _e;
146
+ const method = config.method.toUpperCase();
146
147
  // Ensure valid session (if auth is enabled)
147
148
  if (this.tokenManager && !config.skipAuth) {
148
149
  yield this.tokenManager.ensure(ctx, config.auth, config.headers);
@@ -153,13 +154,18 @@ export class APIClient {
153
154
  const headers = this.buildHeaders(config, ctx, fullURL);
154
155
  // Build request init
155
156
  const init = {
156
- method: config.method,
157
+ method,
157
158
  headers,
158
159
  signal: config.signal,
159
160
  };
160
- // Add body for non-GET requests
161
- if (config.data && config.method !== 'GET') {
161
+ // Add body for appropriate methods
162
+ const methodsWithNoBody = ['GET', 'HEAD', 'DELETE'];
163
+ if (config.data && !methodsWithNoBody.includes(method)) {
162
164
  init.body = JSON.stringify(config.data);
165
+ // Add Content-Type if not already present
166
+ if (!headers['Content-Type'] && !headers['content-type']) {
167
+ headers['Content-Type'] = 'application/json';
168
+ }
163
169
  }
164
170
  // Apply request interceptors
165
171
  let requestConfig = Object.assign({}, config);
@@ -271,7 +277,7 @@ export class APIClient {
271
277
  */
272
278
  buildHeaders(config, ctx, targetURL) {
273
279
  var _a, _b;
274
- const headers = Object.assign(Object.assign({ 'Content-Type': 'application/json' }, this.config.headers), config.headers);
280
+ const headers = Object.assign(Object.assign({}, this.config.headers), config.headers);
275
281
  // Add auth token if available (only for safe URLs)
276
282
  if (this.tokenManager && !config.skipAuth && this.isSafeURL(targetURL)) {
277
283
  const session = this.tokenManager.getSession(ctx);
package/dist/index.cjs CHANGED
@@ -1103,6 +1103,7 @@ class APIClient {
1103
1103
  executeRequest(config, ctx, attempt) {
1104
1104
  return __awaiter(this, void 0, void 0, function* () {
1105
1105
  var _a, _b, _c, _d, _e;
1106
+ const method = config.method.toUpperCase();
1106
1107
  // Ensure valid session (if auth is enabled)
1107
1108
  if (this.tokenManager && !config.skipAuth) {
1108
1109
  yield this.tokenManager.ensure(ctx, config.auth, config.headers);
@@ -1113,13 +1114,18 @@ class APIClient {
1113
1114
  const headers = this.buildHeaders(config, ctx, fullURL);
1114
1115
  // Build request init
1115
1116
  const init = {
1116
- method: config.method,
1117
+ method,
1117
1118
  headers,
1118
1119
  signal: config.signal,
1119
1120
  };
1120
- // Add body for non-GET requests
1121
- if (config.data && config.method !== 'GET') {
1121
+ // Add body for appropriate methods
1122
+ const methodsWithNoBody = ['GET', 'HEAD', 'DELETE'];
1123
+ if (config.data && !methodsWithNoBody.includes(method)) {
1122
1124
  init.body = JSON.stringify(config.data);
1125
+ // Add Content-Type if not already present
1126
+ if (!headers['Content-Type'] && !headers['content-type']) {
1127
+ headers['Content-Type'] = 'application/json';
1128
+ }
1123
1129
  }
1124
1130
  // Apply request interceptors
1125
1131
  let requestConfig = Object.assign({}, config);
@@ -1231,7 +1237,7 @@ class APIClient {
1231
1237
  */
1232
1238
  buildHeaders(config, ctx, targetURL) {
1233
1239
  var _a, _b;
1234
- const headers = Object.assign(Object.assign({ 'Content-Type': 'application/json' }, this.config.headers), config.headers);
1240
+ const headers = Object.assign(Object.assign({}, this.config.headers), config.headers);
1235
1241
  // Add auth token if available (only for safe URLs)
1236
1242
  if (this.tokenManager && !config.skipAuth && this.isSafeURL(targetURL)) {
1237
1243
  const session = this.tokenManager.getSession(ctx);