@agence-zef/sdk 0.14.1 → 0.15.0
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.ts +19 -1
- package/dist/index.js +22 -0
- package/dist/types.d.ts +115 -4
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ConfigCollections, CustomValuesOf, Registry, ZefConfig } from "@agence-zef/schema";
|
|
2
|
-
import type { ApiAccess, ApiAccount, ApiAccountSession, ApiAccountUpdate, ApiCart, ApiCheckout, ApiCheckoutInput, ApiGiftCardInput, ApiItem, ApiLayout, ApiLink, ApiList, ApiOrder, ApiPage, ApiPageEntry, ApiPlayback, ApiPreviewDocument, ApiRedirect, ApiRegisterInput, ApiSection, ApiServicePoint, ApiShippingOption, ApiSite, ApiSubscription, ApiSyncResult } from "./types.js";
|
|
2
|
+
import type { ApiAccess, ApiAccount, ApiAccountSession, ApiAccountUpdate, ApiCart, ApiCategoryItem, ApiCharacteristic, ApiCheckout, ApiCheckoutInput, ApiGiftCardInput, ApiItem, ApiLayout, ApiLink, ApiList, ApiOrder, ApiPage, ApiPageEntry, ApiPlayback, ApiPreviewDocument, ApiProductList, ApiProductSort, ApiRedirect, ApiRegisterInput, ApiSection, ApiServicePoint, ApiShippingOption, ApiSite, ApiSubscription, ApiSyncResult } from "./types.js";
|
|
3
3
|
export { businessJsonLd } from "./business.js";
|
|
4
4
|
export type * from "./types.js";
|
|
5
5
|
/** Erreur renvoyée par l'API (clé invalide, schéma refusé…). */
|
|
@@ -45,6 +45,22 @@ export declare function createClient<C extends ZefConfig = ZefConfig>(options: C
|
|
|
45
45
|
item: <K extends keyof Collections<C> & string>(name: K, slug: string, opts?: LocaleOption & {
|
|
46
46
|
visitor?: Visitor;
|
|
47
47
|
}) => Promise<Collections<C>[K] | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Produits de la boutique, filtrés et triés (M-13) : `category` (identifiant ou slug, avec ses
|
|
50
|
+
* sous-catégories sauf `direct`), `filters` (un paramètre par caractéristique :
|
|
51
|
+
* `{ couleur: ["noir"], contenance: "20-50", price: "0-30", inStock: "true" }`), `sort`. La
|
|
52
|
+
* réponse porte aussi les filtres à proposer avec leurs compteurs (`filters`).
|
|
53
|
+
*/
|
|
54
|
+
products: (opts?: LocaleOption & {
|
|
55
|
+
category?: string;
|
|
56
|
+
direct?: boolean;
|
|
57
|
+
filters?: Record<string, string | string[] | undefined>;
|
|
58
|
+
sort?: ApiProductSort;
|
|
59
|
+
limit?: number;
|
|
60
|
+
offset?: number;
|
|
61
|
+
}) => Promise<ApiProductList>;
|
|
62
|
+
/** Catégories de la boutique, dans l'ordre de l'arbre (M-12). */
|
|
63
|
+
categories: (opts?: LocaleOption) => Promise<ApiCategoryItem[]>;
|
|
48
64
|
/** Header et footer du site (sections partagées par toutes les pages). */
|
|
49
65
|
layout: (opts?: LocaleOption) => Promise<ApiLayout>;
|
|
50
66
|
/** Aperçu : header et footer en brouillon, champs marqués pour l'overlay. */
|
|
@@ -102,6 +118,8 @@ export declare function createClient<C extends ZefConfig = ZefConfig>(options: C
|
|
|
102
118
|
};
|
|
103
119
|
/** Boutique (module commerce) : panier, paiement et commandes du compte connecté. */
|
|
104
120
|
shop: {
|
|
121
|
+
/** Caractéristiques de la boutique (filtres et fiche produit), dans l'ordre (M-13). */
|
|
122
|
+
characteristics: (opts?: LocaleOption) => Promise<ApiCharacteristic[]>;
|
|
105
123
|
/**
|
|
106
124
|
* Panier ; avec `promoCode`, la remise ou la raison du refus (`promoError`) ; avec `giftCard`,
|
|
107
125
|
* le solde disponible de la carte (`giftCardError` sinon).
|
package/dist/index.js
CHANGED
|
@@ -74,6 +74,24 @@ export function createClient(options) {
|
|
|
74
74
|
query: opts,
|
|
75
75
|
}), `Collection « ${name} »`),
|
|
76
76
|
item: (name, slug, opts = {}) => request(`/collections/${encodeURIComponent(name)}/${encodeURIComponent(slug)}`, { query: { locale: opts.locale }, headers: visitorHeaders(opts.visitor) }),
|
|
77
|
+
/**
|
|
78
|
+
* Produits de la boutique, filtrés et triés (M-13) : `category` (identifiant ou slug, avec ses
|
|
79
|
+
* sous-catégories sauf `direct`), `filters` (un paramètre par caractéristique :
|
|
80
|
+
* `{ couleur: ["noir"], contenance: "20-50", price: "0-30", inStock: "true" }`), `sort`. La
|
|
81
|
+
* réponse porte aussi les filtres à proposer avec leurs compteurs (`filters`).
|
|
82
|
+
*/
|
|
83
|
+
products: async (opts = {}) => {
|
|
84
|
+
const { filters, ...rest } = opts;
|
|
85
|
+
const query = { ...rest };
|
|
86
|
+
for (const [key, value] of Object.entries(filters ?? {})) {
|
|
87
|
+
const text = Array.isArray(value) ? value.join(",") : value;
|
|
88
|
+
if (text)
|
|
89
|
+
query[key] = text;
|
|
90
|
+
}
|
|
91
|
+
return required(await request("/collections/products", { query }), "Produits");
|
|
92
|
+
},
|
|
93
|
+
/** Catégories de la boutique, dans l'ordre de l'arbre (M-12). */
|
|
94
|
+
categories: async (opts = {}) => required(await request("/collections/product-categories", { query: opts }), "Catégories").items,
|
|
77
95
|
/** Header et footer du site (sections partagées par toutes les pages). */
|
|
78
96
|
layout: async (opts = {}) => required(await request("/layout", { query: opts }), "Header et footer"),
|
|
79
97
|
/** Aperçu : header et footer en brouillon, champs marqués pour l'overlay. */
|
|
@@ -157,6 +175,10 @@ function shop(request, required) {
|
|
|
157
175
|
headers: visitorHeaders(visitor),
|
|
158
176
|
}), "Réponse");
|
|
159
177
|
return {
|
|
178
|
+
/** Caractéristiques de la boutique (filtres et fiche produit), dans l'ordre (M-13). */
|
|
179
|
+
characteristics: async (opts = {}) => required(await request("/shop/characteristics", {
|
|
180
|
+
query: opts,
|
|
181
|
+
}), "Caractéristiques").characteristics,
|
|
160
182
|
/**
|
|
161
183
|
* Panier ; avec `promoCode`, la remise ou la raison du refus (`promoError`) ; avec `giftCard`,
|
|
162
184
|
* le solde disponible de la carte (`giftCardError` sinon).
|
package/dist/types.d.ts
CHANGED
|
@@ -217,10 +217,17 @@ export type ApiProduct = {
|
|
|
217
217
|
/** Taux de TVA en points de base (2000 = 20 %). */
|
|
218
218
|
vatRate: number;
|
|
219
219
|
available: boolean;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
220
|
+
/** Catégories du produit (M-12), chacune avec ses parentes (`path`). */
|
|
221
|
+
categories: ApiProductCategory[];
|
|
222
|
+
/** Catégorie principale : fil d'Ariane et données structurées ; `null` sans catégorie. */
|
|
223
|
+
mainCategory: ApiProductCategory | null;
|
|
224
|
+
/** Caractéristiques « Fiche » renseignées, dans l'ordre de la boutique (M-13). */
|
|
225
|
+
characteristics: ApiProductCharacteristic[];
|
|
226
|
+
/**
|
|
227
|
+
* Variante qui remplit les filtres sur les variantes (couleur, contenance, prix, stock) ;
|
|
228
|
+
* le prix affiché (`price`) est alors le sien. Absent sans filtre de variante.
|
|
229
|
+
*/
|
|
230
|
+
matchedVariant?: string;
|
|
224
231
|
media: ApiProductMedia[];
|
|
225
232
|
thumbnail: ApiProductMedia | null;
|
|
226
233
|
options: {
|
|
@@ -263,6 +270,110 @@ export type ApiProduct = {
|
|
|
263
270
|
thumbnail: ApiProductMedia | null;
|
|
264
271
|
}[];
|
|
265
272
|
};
|
|
273
|
+
/** Types de caractéristiques (M-13). */
|
|
274
|
+
export type ApiCharacteristicType = "choice" | "multi" | "boolean" | "number" | "color" | "text";
|
|
275
|
+
/** Caractéristique de la boutique (`GET /shop/characteristics`). */
|
|
276
|
+
export type ApiCharacteristic = {
|
|
277
|
+
/** Nom technique, dans l'adresse des filtres (`couleur`). */
|
|
278
|
+
key: string;
|
|
279
|
+
label: string;
|
|
280
|
+
type: ApiCharacteristicType;
|
|
281
|
+
/** Où elle se remplit : sur le produit, ou sur chaque variante. */
|
|
282
|
+
appliesTo: "product" | "variants";
|
|
283
|
+
unit: string | null;
|
|
284
|
+
values: {
|
|
285
|
+
key: string;
|
|
286
|
+
label: string;
|
|
287
|
+
color?: string;
|
|
288
|
+
}[];
|
|
289
|
+
/** Catégories concernées (identifiants), vide : toutes. */
|
|
290
|
+
categories: string[];
|
|
291
|
+
/** Proposée comme filtre ; affichée sur la fiche produit. */
|
|
292
|
+
filter: boolean;
|
|
293
|
+
sheet: boolean;
|
|
294
|
+
};
|
|
295
|
+
/** Caractéristique renseignée d'un produit (tableau de la fiche). */
|
|
296
|
+
export type ApiProductCharacteristic = {
|
|
297
|
+
key: string;
|
|
298
|
+
label: string;
|
|
299
|
+
type: ApiCharacteristicType;
|
|
300
|
+
/** Clé de valeur (liste, couleur), clés (liste multiple), `true`, nombre ou texte. */
|
|
301
|
+
value: string | string[] | boolean | number;
|
|
302
|
+
/** Texte affiché : « Noir, Blanc », « 75 cl », « Oui ». */
|
|
303
|
+
display: string;
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* Filtre d'une liste de produits (`filters` de `GET /collections/products`), dans l'ordre de la
|
|
307
|
+
* boutique ; seulement ceux qu'au moins un produit de la liste renseigne. Les compteurs suivent les
|
|
308
|
+
* autres filtres choisis ; une valeur à 0 est grisée.
|
|
309
|
+
*/
|
|
310
|
+
export type ApiFilter = {
|
|
311
|
+
key: string;
|
|
312
|
+
label: string;
|
|
313
|
+
type: "choice" | "multi" | "color";
|
|
314
|
+
values: {
|
|
315
|
+
key: string;
|
|
316
|
+
label: string;
|
|
317
|
+
color?: string;
|
|
318
|
+
count: number;
|
|
319
|
+
selected: boolean;
|
|
320
|
+
}[];
|
|
321
|
+
} | {
|
|
322
|
+
key: string;
|
|
323
|
+
label: string;
|
|
324
|
+
type: "boolean" | "stock";
|
|
325
|
+
count: number;
|
|
326
|
+
selected: boolean;
|
|
327
|
+
} | {
|
|
328
|
+
key: string;
|
|
329
|
+
label: string;
|
|
330
|
+
type: "number" | "price";
|
|
331
|
+
unit: string | null;
|
|
332
|
+
/** Bornes de la liste (prix en centimes) ; `selected` : fourchette choisie. */
|
|
333
|
+
min: number;
|
|
334
|
+
max: number;
|
|
335
|
+
selected: {
|
|
336
|
+
min: number | null;
|
|
337
|
+
max: number | null;
|
|
338
|
+
} | null;
|
|
339
|
+
};
|
|
340
|
+
/** Tri d'une liste de produits. */
|
|
341
|
+
export type ApiProductSort = "position" | "price" | "-price" | "new";
|
|
342
|
+
/** Liste de produits filtrée (`GET /collections/products`). */
|
|
343
|
+
export type ApiProductList = ApiList<ApiItem & {
|
|
344
|
+
product: ApiProduct;
|
|
345
|
+
}> & {
|
|
346
|
+
filters: ApiFilter[];
|
|
347
|
+
};
|
|
348
|
+
/** Catégorie vue depuis une autre (parent, fil d'Ariane) ; `url` : `null` sans page en ligne. */
|
|
349
|
+
export type ApiCategoryRef = {
|
|
350
|
+
id: string;
|
|
351
|
+
slug: string;
|
|
352
|
+
title: string;
|
|
353
|
+
url: string | null;
|
|
354
|
+
};
|
|
355
|
+
/** Catégorie d'un produit : ses parentes du premier niveau au parent (`path`). */
|
|
356
|
+
export type ApiProductCategory = ApiCategoryRef & {
|
|
357
|
+
/** Même valeur que `title` (forme du lot 14e1). */
|
|
358
|
+
name: string;
|
|
359
|
+
path: ApiCategoryRef[];
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
* Élément de la collection `product-categories` (`GET /collections/product-categories`), servi
|
|
363
|
+
* dans l'ordre de l'arbre : ses champs, puis sa place dans l'arbre et son nombre de produits
|
|
364
|
+
* (sous-catégories comprises).
|
|
365
|
+
*/
|
|
366
|
+
export type ApiCategoryItem = ApiItem & {
|
|
367
|
+
/** Catégorie parente, `null` au premier niveau. */
|
|
368
|
+
parent: string | null;
|
|
369
|
+
/** Niveau : 0 au premier niveau. */
|
|
370
|
+
depth: number;
|
|
371
|
+
/** Catégories parentes, du premier niveau au parent. */
|
|
372
|
+
path: ApiCategoryRef[];
|
|
373
|
+
/** Sous-catégories servies, dans l'ordre. */
|
|
374
|
+
children: string[];
|
|
375
|
+
productCount: number;
|
|
376
|
+
};
|
|
266
377
|
/** Ligne du panier (montants TTC en centimes, recalculés par le CMS). */
|
|
267
378
|
export type ApiCartLine = {
|
|
268
379
|
/** Vide pour une carte cadeau (voir `giftCardLineId`). */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agence-zef/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Client typé de l'API d'un CMS ZEF (client.agence-zef.fr/api/v1).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@agence-zef/schema": "0.
|
|
20
|
+
"@agence-zef/schema": "0.20.0"
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://agence-zef.fr",
|
|
23
23
|
"scripts": {
|