nexabase-console 1.1.2 → 1.1.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.
Files changed (3) hide show
  1. package/README.md +12 -0
  2. package/dist/index.js +17 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -42,6 +42,13 @@ const app = initializeApp({
42
42
  const db = getFirestore(app);
43
43
  ```
44
44
 
45
+ #### 🛡️ Keamanan & Autentikasi Ganda (API Key & Sesi)
46
+ Untuk mendukung arsitektur server-side proxy atau direct API key yang sangat fleksibel, SDK secara otomatis mengirimkan token Anda dalam dua format header sekaligus:
47
+ - **`Authorization: Bearer <token>`**: Digunakan untuk validasi token JWT sesi user.
48
+ - **`x-api-key: <api_key>`**: Digunakan untuk otentikasi aman tanpa sesi menggunakan API Key proyek.
49
+
50
+ Hal ini mencegah kegagalan otentikasi (Error `403 Forbidden: Please login`) saat memanggil metode di server menggunakan API Key proyek.
51
+
45
52
  ---
46
53
 
47
54
  ### 2. Firestore-like Modular API (NoSQL)
@@ -242,6 +249,11 @@ const uploadImage = async (fileBlob) => {
242
249
  };
243
250
  ```
244
251
 
252
+ #### 📂 Penanganan Tipe Konten Dinamis (Form Data Boundary)
253
+ Unggahan file menggunakan format multipart standard yang dibungkus dalam objek `FormData`. SDK ini secara otomatis mendeteksi payload `FormData` dan membebaskan header `Content-Type` bawaan agar browser dapat secara dinamis menetapkan tipe konten yang menyertakan kode batas unik (*multipart boundary*).
254
+
255
+ Ini menghilangkan bug berkas kosong (`{}`) yang disebabkan oleh tumpang tindihnya header `application/json` di Axios.
256
+
245
257
  ---
246
258
 
247
259
  ### 5. Keamanan Tipe TypeScript (Generics) & Kueri Lanjutan
package/dist/index.js CHANGED
@@ -51,19 +51,29 @@ class NexaApp {
51
51
  defaultEndpoint = window.location.origin;
52
52
  }
53
53
  this.endpoint = config.endpoint || defaultEndpoint;
54
+ // Do not set default Content-Type globally to let Axios auto-detect FormData
54
55
  this.client = axios_1.default.create({
55
- baseURL: this.endpoint,
56
- headers: {
57
- 'Content-Type': 'application/json'
58
- }
56
+ baseURL: this.endpoint
59
57
  });
60
- // Request interceptor to attach bearer token and boundary fix
58
+ // Request interceptor to attach bearer/x-api-key token and boundary fix
61
59
  this.client.interceptors.request.use((req) => {
62
60
  if (this.token) {
61
+ // Send both Authorization Bearer and x-api-key for full server compatibility
63
62
  req.headers.Authorization = `Bearer ${this.token}`;
63
+ req.headers['x-api-key'] = this.token;
64
+ }
65
+ // If data is FormData, remove Content-Type so Axios/Browser can format multipart boundary dynamically
66
+ if (typeof FormData !== 'undefined' && req.data instanceof FormData) {
67
+ if (req.headers) {
68
+ delete req.headers['Content-Type'];
69
+ delete req.headers['content-type'];
70
+ }
64
71
  }
65
- if (req.headers && req.headers['Content-Type'] === 'multipart/form-data') {
66
- delete req.headers['Content-Type'];
72
+ else {
73
+ // Otherwise default to application/json for non-FormData payload requests
74
+ if (req.data && req.headers && !req.headers['Content-Type'] && !req.headers['content-type']) {
75
+ req.headers['Content-Type'] = 'application/json';
76
+ }
67
77
  }
68
78
  return req;
69
79
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexabase-console",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "SDK Client resmi untuk NexaBase: Platform Sinkronisasi NoSQL, Realtime, File Storage, & Autentikasi Offline-First.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",