@echoppe/client 0.1.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/LICENSE ADDED
@@ -0,0 +1,31 @@
1
+ # Licence CeCILL v2.1
2
+
3
+ Ce logiciel est régi par la Licence CeCILL version 2.1 soumise au droit français et compatible avec la licence GNU GPL. Vous pouvez utiliser, modifier et redistribuer ce logiciel selon les termes de cette licence.
4
+
5
+ Le texte complet de la licence est disponible ici : [CeCILL v2.1 (français)](https://cecill.info/licences/Licence_CeCILL_V2.1-fr.html)
6
+
7
+ ## Résumé des droits et obligations
8
+
9
+ - **Utilisation** : vous pouvez utiliser ce logiciel pour tout usage, privé ou commercial.
10
+ - **Modification** : vous pouvez modifier le logiciel et redistribuer vos modifications.
11
+ - **Redistribution** : toute redistribution du logiciel original ou modifié doit se faire sous la même licence CeCILL v2.1.
12
+ - **Garantie** : ce logiciel est fourni "tel quel", sans garantie d'aucune sorte.
13
+
14
+ Pour plus de détails, consultez le texte complet de la licence via le lien ci-dessus.
15
+
16
+ ---
17
+
18
+ # CeCILL v2.1 License – Échoppe
19
+
20
+ This software, Échoppe, is governed by the CeCILL Version 2.1 License, under French law and compatible with the GNU GPL. You may use, modify, and redistribute this software under the terms of this license.
21
+
22
+ The full license text is available here: [CeCILL v2.1 (English)](https://cecill.info/licences/Licence_CeCILL_V2.1-en.html)
23
+
24
+ ## Summary of Rights and Obligations
25
+
26
+ - **Use**: You may use this software for any private or professional purpose.
27
+ - **Modification**: You may modify the software and redistribute your modifications.
28
+ - **Redistribution**: Any redistribution of the original or modified software must be under the same CeCILL v2.1 license.
29
+ - **Warranty**: This software is provided "as is", without any warranty of any kind.
30
+
31
+ For full details, please refer to the complete license text via the link above.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # @echoppe/client
2
+
3
+ SDK client **typé** pour l'API [Échoppe](https://github.com/) — généré depuis le
4
+ contrat OpenAPI de l'API. Runtime-agnostique (navigateur, Bun, Node, edge) : repose
5
+ uniquement sur `fetch`.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ bun add @echoppe/client
11
+ ```
12
+
13
+ ## Utilisation
14
+
15
+ ```ts
16
+ import { createEchoppeClient } from '@echoppe/client';
17
+
18
+ const echoppe = createEchoppeClient({
19
+ baseUrl: 'https://api.maboutique.fr',
20
+ });
21
+
22
+ const { data, error } = await echoppe.GET('/products/');
23
+ if (error) throw error;
24
+
25
+ // `data` est entièrement typé depuis le contrat de l'API
26
+ for (const product of data) {
27
+ console.log(product.name);
28
+ }
29
+ ```
30
+
31
+ Les méthodes suivent le contrat OpenAPI via [`openapi-fetch`](https://openapi-ts.dev/openapi-fetch/) :
32
+ `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, avec `params.path`, `params.query` et `body`
33
+ typés par route.
34
+
35
+ ```ts
36
+ const { data } = await echoppe.GET('/products/{id}', {
37
+ params: { path: { id: '…' } },
38
+ });
39
+ ```
40
+
41
+ ### Authentification
42
+
43
+ L'API utilise des **cookies de session HTTP-only**. Le client force
44
+ `credentials: 'include'` — dans un navigateur, les cookies de session sont donc
45
+ transmis automatiquement une fois l'utilisateur connecté via les routes d'auth.
46
+
47
+ ## Types
48
+
49
+ Le contrat complet est réexporté pour dériver ses propres types :
50
+
51
+ ```ts
52
+ import type { paths, components } from '@echoppe/client';
53
+
54
+ type Product = components['schemas']['...'];
55
+ ```
56
+
57
+ ## Régénérer depuis l'API
58
+
59
+ Le SDK est généré depuis l'OpenAPI d'une API en cours d'exécution :
60
+
61
+ ```bash
62
+ # API sur http://localhost:7532 par défaut
63
+ bun run generate
64
+ # ou une autre instance
65
+ ECHOPPE_API_URL=https://api.exemple.fr bun run generate
66
+ ```
67
+
68
+ Cela met à jour `openapi.json` (snapshot figé du contrat) puis `src/openapi.ts`.
@@ -0,0 +1,21 @@
1
+ import { type ClientOptions } from 'openapi-fetch';
2
+ import type { paths } from './openapi';
3
+ export interface EchoppeClientOptions {
4
+ /** URL de base de l'API Échoppe, ex. `https://api.maboutique.fr`. */
5
+ baseUrl: string;
6
+ /** En-têtes envoyés par défaut sur chaque requête (contexte SSR, etc.). */
7
+ headers?: Record<string, string>;
8
+ /**
9
+ * Implémentation de `fetch` à utiliser (SSR, tests). Défaut : `fetch` global.
10
+ */
11
+ fetch?: ClientOptions['fetch'];
12
+ }
13
+ /**
14
+ * Crée un client typé pour l'API Échoppe.
15
+ *
16
+ * L'authentification repose sur des cookies de session HTTP-only : le client
17
+ * force donc `credentials: 'include'` pour que les routes protégées fonctionnent.
18
+ */
19
+ export declare function createEchoppeClient(options: EchoppeClientOptions): import("openapi-fetch").Client<paths, `${string}/${string}`>;
20
+ export type EchoppeClient = ReturnType<typeof createEchoppeClient>;
21
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAA4B,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAEvC,MAAM,WAAW,oBAAoB;IACnC,qEAAqE;IACrE,OAAO,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC;;OAEG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CAChC;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,gEAOhE;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
package/dist/client.js ADDED
@@ -0,0 +1,16 @@
1
+ import createOpenApiClient, {} from 'openapi-fetch';
2
+ /**
3
+ * Crée un client typé pour l'API Échoppe.
4
+ *
5
+ * L'authentification repose sur des cookies de session HTTP-only : le client
6
+ * force donc `credentials: 'include'` pour que les routes protégées fonctionnent.
7
+ */
8
+ export function createEchoppeClient(options) {
9
+ return createOpenApiClient({
10
+ baseUrl: options.baseUrl.replace(/\/+$/, ''),
11
+ credentials: 'include',
12
+ headers: options.headers,
13
+ fetch: options.fetch,
14
+ });
15
+ }
16
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,EAAE,EAAsB,MAAM,eAAe,CAAC;AAcxE;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAA6B;IAC/D,OAAO,mBAAmB,CAAQ;QAChC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;QAC5C,WAAW,EAAE,SAAS;QACtB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,KAAK,EAAE,OAAO,CAAC,KAAK;KACrB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,4 @@
1
+ export type { EchoppeClient, EchoppeClientOptions } from './client';
2
+ export { createEchoppeClient } from './client';
3
+ export type { components, operations, paths } from './openapi';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { createEchoppeClient } from './client';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC"}