@frenchbaas/js 0.2.4 → 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,6 +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 — valeur unique
53
+ const { data: pending } = await col.get({ filter: { status: 'pending' } })
54
+
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)
59
+ const { data: products } = await col.get({ filter: { category_ids: 'uuid-categorie' } })
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
+
52
69
  // Récupérer un document par ID
53
70
  const doc = await col.getById('doc-uuid')
54
71
  // doc → { id, data, created_at, updated_at }
@@ -200,6 +217,10 @@ const client = new FrenchBaas({
200
217
  Utilisez `localStorage` pour que la session survive au rechargement de page
201
218
  (applications web). Utilisez `memory` pour les environnements serveur (Node.js).
202
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
+
203
224
  ---
204
225
 
205
226
  ## Fonctionnalités automatiques
package/dist/index.cjs CHANGED
@@ -209,6 +209,18 @@ var CollectionClient = class {
209
209
  page: options.page,
210
210
  per_page: options.perPage
211
211
  };
212
+ if (options.filter) {
213
+ for (const [key, val] of Object.entries(options.filter)) {
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
+ }
222
+ }
223
+ }
212
224
  const res = await this._http.get(
213
225
  `/sdk/collections/${this._collectionId}/documents`,
214
226
  params
@@ -309,7 +321,12 @@ var HttpClient = class {
309
321
  const url = new URL(this._baseUrl + path);
310
322
  if (params) {
311
323
  for (const [k, v] of Object.entries(params)) {
312
- 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
+ }
313
330
  }
314
331
  }
315
332
  return this._request("GET", url.toString(), void 0, true);
package/dist/index.d.mts CHANGED
@@ -47,6 +47,22 @@ interface GetOptions {
47
47
  page?: number;
48
48
  /** Documents par page — max 100 (défaut: 50) */
49
49
  perPage?: number;
50
+ /**
51
+ * Filtres sur les champs du document.
52
+ *
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'] } }
62
+ */
63
+ filter?: Record<string, string | string[] | {
64
+ and: string[];
65
+ }>;
50
66
  }
51
67
  type FieldType = 'string' | 'integer' | 'number' | 'boolean' | 'array' | 'object' | 'datetime';
52
68
  interface SchemaField {
@@ -125,7 +141,7 @@ declare class HttpClient {
125
141
  constructor(_baseUrl: string, _apiKey: string, _tokenStore: TokenStore);
126
142
  /** Enregistre la fonction de refresh (injectée par AuthModule). */
127
143
  setRefreshFn(fn: RefreshFn): void;
128
- 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>;
129
145
  post<T>(path: string, body?: unknown): Promise<T>;
130
146
  patch<T>(path: string, body?: unknown): Promise<T>;
131
147
  delete<T>(path: string): Promise<T>;
package/dist/index.d.ts CHANGED
@@ -47,6 +47,22 @@ interface GetOptions {
47
47
  page?: number;
48
48
  /** Documents par page — max 100 (défaut: 50) */
49
49
  perPage?: number;
50
+ /**
51
+ * Filtres sur les champs du document.
52
+ *
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'] } }
62
+ */
63
+ filter?: Record<string, string | string[] | {
64
+ and: string[];
65
+ }>;
50
66
  }
51
67
  type FieldType = 'string' | 'integer' | 'number' | 'boolean' | 'array' | 'object' | 'datetime';
52
68
  interface SchemaField {
@@ -125,7 +141,7 @@ declare class HttpClient {
125
141
  constructor(_baseUrl: string, _apiKey: string, _tokenStore: TokenStore);
126
142
  /** Enregistre la fonction de refresh (injectée par AuthModule). */
127
143
  setRefreshFn(fn: RefreshFn): void;
128
- 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>;
129
145
  post<T>(path: string, body?: unknown): Promise<T>;
130
146
  patch<T>(path: string, body?: unknown): Promise<T>;
131
147
  delete<T>(path: string): Promise<T>;
package/dist/index.js CHANGED
@@ -175,6 +175,18 @@ var CollectionClient = class {
175
175
  page: options.page,
176
176
  per_page: options.perPage
177
177
  };
178
+ if (options.filter) {
179
+ for (const [key, val] of Object.entries(options.filter)) {
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
+ }
188
+ }
189
+ }
178
190
  const res = await this._http.get(
179
191
  `/sdk/collections/${this._collectionId}/documents`,
180
192
  params
@@ -275,7 +287,12 @@ var HttpClient = class {
275
287
  const url = new URL(this._baseUrl + path);
276
288
  if (params) {
277
289
  for (const [k, v] of Object.entries(params)) {
278
- 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
+ }
279
296
  }
280
297
  }
281
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.2.4",
3
+ "version": "0.3.1",
4
4
  "description": "SDK JavaScript officiel pour FrenchBaas",
5
5
  "author": "FrenchBaas",
6
6
  "license": "MIT",