@frenchbaas/js 0.3.0 → 0.3.1

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
@@ -24,11 +24,11 @@ const client = new FrenchBaas({
24
24
  ## Auth
25
25
 
26
26
  ```js
27
- // Inscription
28
- const { user, access_token } = await client.auth.signUp({ email: 'a@b.com', password: 'secret' })
27
+ // Inscription (mot de passe : 8 caractères minimum)
28
+ const { user, access_token } = await client.auth.signUp({ email: 'a@b.com', password: 'monMotDePasse' })
29
29
 
30
30
  // Connexion
31
- const { user, access_token } = await client.auth.login({ email: 'a@b.com', password: 'secret' })
31
+ const { user, access_token } = await client.auth.login({ email: 'a@b.com', password: 'monMotDePasse' })
32
32
 
33
33
  // Déconnexion
34
34
  await client.auth.logout()
@@ -49,12 +49,23 @@ const col = client.collection('uuid-de-la-collection')
49
49
  const { data, meta } = await col.get({ page: 1, perPage: 20 })
50
50
  // meta → { total, page, per_page, total_pages }
51
51
 
52
- // Filtrer par champ (string, number, boolean)
52
+ // Filtrer par champ valeur unique
53
53
  const { data: pending } = await col.get({ filter: { status: 'pending' } })
54
54
 
55
- // Filtrer par champ references (tableau d'UUIDs contient l'UUID)
55
+ // Filtrer OR plusieurs valeurs (status pending OU delivered)
56
+ const { data: multi } = await col.get({ filter: { status: ['pending', 'delivered'] } })
57
+
58
+ // Filtrer par references — valeur unique (contient l'UUID)
56
59
  const { data: products } = await col.get({ filter: { category_ids: 'uuid-categorie' } })
57
60
 
61
+ // Filtrer references OR — catégorie A OU B
62
+ const { data: orProducts } = await col.get({ filter: { category_ids: ['uuid-cat-a', 'uuid-cat-b'] } })
63
+
64
+ // Filtrer references AND — dans catégorie A ET B (uniquement pour references/array)
65
+ const { data: andProducts } = await col.get({ filter: { category_ids: { and: ['uuid-cat-a', 'uuid-cat-b'] } } })
66
+
67
+ // ⚠ Maximum 20 valeurs par filtre (OR ou AND)
68
+
58
69
  // Récupérer un document par ID
59
70
  const doc = await col.getById('doc-uuid')
60
71
  // doc → { id, data, created_at, updated_at }
@@ -206,6 +217,10 @@ const client = new FrenchBaas({
206
217
  Utilisez `localStorage` pour que la session survive au rechargement de page
207
218
  (applications web). Utilisez `memory` pour les environnements serveur (Node.js).
208
219
 
220
+ > **Sécurité** : l'option `localStorage` expose les tokens à toute attaque XSS sur votre page.
221
+ > Assurez-vous que votre application ne charge pas de scripts tiers non maîtrisés
222
+ > et qu'elle applique une politique CSP stricte si vous utilisez ce mode.
223
+
209
224
  ---
210
225
 
211
226
  ## Fonctionnalités automatiques
package/dist/index.cjs CHANGED
@@ -211,7 +211,14 @@ var CollectionClient = class {
211
211
  };
212
212
  if (options.filter) {
213
213
  for (const [key, val] of Object.entries(options.filter)) {
214
- if (val !== void 0) params[`filter[${key}]`] = val;
214
+ if (val === void 0) continue;
215
+ if (typeof val === "string") {
216
+ params[`filter[${key}]`] = val;
217
+ } else if (Array.isArray(val)) {
218
+ params[`filter[${key}][]`] = val;
219
+ } else {
220
+ params[`filter[${key}][and][]`] = val.and;
221
+ }
215
222
  }
216
223
  }
217
224
  const res = await this._http.get(
@@ -314,7 +321,12 @@ var HttpClient = class {
314
321
  const url = new URL(this._baseUrl + path);
315
322
  if (params) {
316
323
  for (const [k, v] of Object.entries(params)) {
317
- if (v !== void 0) url.searchParams.set(k, String(v));
324
+ if (v === void 0) continue;
325
+ if (Array.isArray(v)) {
326
+ for (const item of v) url.searchParams.append(k, item);
327
+ } else {
328
+ url.searchParams.set(k, String(v));
329
+ }
318
330
  }
319
331
  }
320
332
  return this._request("GET", url.toString(), void 0, true);
package/dist/index.d.mts CHANGED
@@ -49,13 +49,20 @@ interface GetOptions {
49
49
  perPage?: number;
50
50
  /**
51
51
  * Filtres sur les champs du document.
52
- * - Champ string/number/boolean : égalité exacte
53
- * - Champ references : l'UUID doit être présent dans le tableau
54
52
  *
55
- * @example { status: 'pending' }
56
- * @example { category_ids: '3e0a5843-...' }
53
+ * - Valeur unique (string) → égalité exacte ou contient (references/array)
54
+ * - Tableau string[] → OR : field = v1 OU v2 / contient v1 OU v2
55
+ * - { and: string[] } → AND : uniquement pour references/array — contient tous les éléments
56
+ *
57
+ * @example { status: 'active' }
58
+ * @example { status: ['active', 'pending'] }
59
+ * @example { category_ids: 'uuid1' }
60
+ * @example { category_ids: ['uuid1', 'uuid2'] }
61
+ * @example { category_ids: { and: ['uuid1', 'uuid2'] } }
57
62
  */
58
- filter?: Record<string, string>;
63
+ filter?: Record<string, string | string[] | {
64
+ and: string[];
65
+ }>;
59
66
  }
60
67
  type FieldType = 'string' | 'integer' | 'number' | 'boolean' | 'array' | 'object' | 'datetime';
61
68
  interface SchemaField {
@@ -134,7 +141,7 @@ declare class HttpClient {
134
141
  constructor(_baseUrl: string, _apiKey: string, _tokenStore: TokenStore);
135
142
  /** Enregistre la fonction de refresh (injectée par AuthModule). */
136
143
  setRefreshFn(fn: RefreshFn): void;
137
- get<T>(path: string, params?: Record<string, string | number | undefined>): Promise<T>;
144
+ get<T>(path: string, params?: Record<string, string | number | string[] | undefined>): Promise<T>;
138
145
  post<T>(path: string, body?: unknown): Promise<T>;
139
146
  patch<T>(path: string, body?: unknown): Promise<T>;
140
147
  delete<T>(path: string): Promise<T>;
package/dist/index.d.ts CHANGED
@@ -49,13 +49,20 @@ interface GetOptions {
49
49
  perPage?: number;
50
50
  /**
51
51
  * Filtres sur les champs du document.
52
- * - Champ string/number/boolean : égalité exacte
53
- * - Champ references : l'UUID doit être présent dans le tableau
54
52
  *
55
- * @example { status: 'pending' }
56
- * @example { category_ids: '3e0a5843-...' }
53
+ * - Valeur unique (string) → égalité exacte ou contient (references/array)
54
+ * - Tableau string[] → OR : field = v1 OU v2 / contient v1 OU v2
55
+ * - { and: string[] } → AND : uniquement pour references/array — contient tous les éléments
56
+ *
57
+ * @example { status: 'active' }
58
+ * @example { status: ['active', 'pending'] }
59
+ * @example { category_ids: 'uuid1' }
60
+ * @example { category_ids: ['uuid1', 'uuid2'] }
61
+ * @example { category_ids: { and: ['uuid1', 'uuid2'] } }
57
62
  */
58
- filter?: Record<string, string>;
63
+ filter?: Record<string, string | string[] | {
64
+ and: string[];
65
+ }>;
59
66
  }
60
67
  type FieldType = 'string' | 'integer' | 'number' | 'boolean' | 'array' | 'object' | 'datetime';
61
68
  interface SchemaField {
@@ -134,7 +141,7 @@ declare class HttpClient {
134
141
  constructor(_baseUrl: string, _apiKey: string, _tokenStore: TokenStore);
135
142
  /** Enregistre la fonction de refresh (injectée par AuthModule). */
136
143
  setRefreshFn(fn: RefreshFn): void;
137
- get<T>(path: string, params?: Record<string, string | number | undefined>): Promise<T>;
144
+ get<T>(path: string, params?: Record<string, string | number | string[] | undefined>): Promise<T>;
138
145
  post<T>(path: string, body?: unknown): Promise<T>;
139
146
  patch<T>(path: string, body?: unknown): Promise<T>;
140
147
  delete<T>(path: string): Promise<T>;
package/dist/index.js CHANGED
@@ -177,7 +177,14 @@ var CollectionClient = class {
177
177
  };
178
178
  if (options.filter) {
179
179
  for (const [key, val] of Object.entries(options.filter)) {
180
- if (val !== void 0) params[`filter[${key}]`] = val;
180
+ if (val === void 0) continue;
181
+ if (typeof val === "string") {
182
+ params[`filter[${key}]`] = val;
183
+ } else if (Array.isArray(val)) {
184
+ params[`filter[${key}][]`] = val;
185
+ } else {
186
+ params[`filter[${key}][and][]`] = val.and;
187
+ }
181
188
  }
182
189
  }
183
190
  const res = await this._http.get(
@@ -280,7 +287,12 @@ var HttpClient = class {
280
287
  const url = new URL(this._baseUrl + path);
281
288
  if (params) {
282
289
  for (const [k, v] of Object.entries(params)) {
283
- if (v !== void 0) url.searchParams.set(k, String(v));
290
+ if (v === void 0) continue;
291
+ if (Array.isArray(v)) {
292
+ for (const item of v) url.searchParams.append(k, item);
293
+ } else {
294
+ url.searchParams.set(k, String(v));
295
+ }
284
296
  }
285
297
  }
286
298
  return this._request("GET", url.toString(), void 0, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frenchbaas/js",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "SDK JavaScript officiel pour FrenchBaas",
5
5
  "author": "FrenchBaas",
6
6
  "license": "MIT",