async-storage-sync 1.0.3 → 1.0.4

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.d.mts CHANGED
@@ -4,9 +4,7 @@ type DuplicateStrategy = 'append' | 'overwrite';
4
4
  interface InitConfig {
5
5
  driver: DriverName;
6
6
  serverUrl: string;
7
- credentials: {
8
- apiKey: string;
9
- };
7
+ credentials: Record<string, string>;
10
8
  /**
11
9
  * Optional transform applied to the stored record before it is sent to the server.
12
10
  * Use this to strip internal meta fields, rename keys, or reshape the payload
package/dist/index.d.ts CHANGED
@@ -4,9 +4,7 @@ type DuplicateStrategy = 'append' | 'overwrite';
4
4
  interface InitConfig {
5
5
  driver: DriverName;
6
6
  serverUrl: string;
7
- credentials: {
8
- apiKey: string;
9
- };
7
+ credentials: Record<string, string>;
10
8
  /**
11
9
  * Optional transform applied to the stored record before it is sent to the server.
12
10
  * Use this to strip internal meta fields, rename keys, or reshape the payload
package/dist/index.js CHANGED
@@ -155,6 +155,15 @@ var Queue = class {
155
155
  // src/core/sync-engine.ts
156
156
  var DEBOUNCE_MS = 500;
157
157
  var BACKOFF_BASE_MS = 1e3;
158
+ function buildAuthHeaders(credentials) {
159
+ const headers = { ...credentials };
160
+ const apiKey = headers.apiKey;
161
+ if (apiKey && !headers.Authorization && !headers.authorization) {
162
+ headers.Authorization = `Bearer ${apiKey}`;
163
+ }
164
+ delete headers.apiKey;
165
+ return headers;
166
+ }
158
167
  var SyncEngine = class {
159
168
  constructor(config, queue, driver) {
160
169
  this.config = config;
@@ -265,7 +274,7 @@ var SyncEngine = class {
265
274
  method: "POST",
266
275
  headers: {
267
276
  "Content-Type": "application/json",
268
- Authorization: `Bearer ${this.config.credentials.apiKey}`
277
+ ...buildAuthHeaders(this.config.credentials)
269
278
  },
270
279
  body: JSON.stringify(body)
271
280
  });
package/dist/index.mjs CHANGED
@@ -133,6 +133,15 @@ var Queue = class {
133
133
  // src/core/sync-engine.ts
134
134
  var DEBOUNCE_MS = 500;
135
135
  var BACKOFF_BASE_MS = 1e3;
136
+ function buildAuthHeaders(credentials) {
137
+ const headers = { ...credentials };
138
+ const apiKey = headers.apiKey;
139
+ if (apiKey && !headers.Authorization && !headers.authorization) {
140
+ headers.Authorization = `Bearer ${apiKey}`;
141
+ }
142
+ delete headers.apiKey;
143
+ return headers;
144
+ }
136
145
  var SyncEngine = class {
137
146
  constructor(config, queue, driver) {
138
147
  this.config = config;
@@ -243,7 +252,7 @@ var SyncEngine = class {
243
252
  method: "POST",
244
253
  headers: {
245
254
  "Content-Type": "application/json",
246
- Authorization: `Bearer ${this.config.credentials.apiKey}`
255
+ ...buildAuthHeaders(this.config.credentials)
247
256
  },
248
257
  body: JSON.stringify(body)
249
258
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "async-storage-sync",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Offline-first data layer for React Native with local-first storage and automatic sync",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",