@inwink-mcp/backoffice-extension-helpers 1.0.10 → 1.0.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inwink-mcp/backoffice-extension-helpers",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "author": "inwink",
5
5
  "license": "ISC",
6
6
  "description": "CLI pour bootstrapper, packager et vérifier les extensions backoffice inwink.",
@@ -100,6 +100,7 @@ Bonnes pratiques :
100
100
  - Le 429 (rate limiting) est géré automatiquement par les hooks : rejeu avec backoff exponentiel respectant l'en-tête `Retry-After` (cf. `useInwinkApi.ts`). Ne pas le ré-implémenter.
101
101
  - Au-delà de 429, une réponse non-OK lève une `InwinkApiError` (`status`, `body`) — à présenter via `ErrorState` ou un toast.
102
102
  - Pour propager l'annulation, passer le `signal` reçu de `useAsync` dans `init` : `eventApi.get(path, { signal })`.
103
+ - Verbes disponibles : `get`, `post`, `put`, `patch`, `del`, plus `request` pour le reste. Une réponse OK sans corps — un 204, ou un 200 comme en renvoient les écritures de template d'entité — résout sur `undefined`.
103
104
  - Ne déclarer dans `permissions.platform` que les scopes réellement utilisés.
104
105
  - Déclarer les hôtes externes dans `permissions.externalHosts` (HTTPS uniquement).
105
106
 
@@ -17,6 +17,7 @@ export interface InwinkApi {
17
17
  get: <T = unknown>(path: string, init?: RequestInit) => Promise<T>;
18
18
  post: <T = unknown>(path: string, body?: unknown, init?: RequestInit) => Promise<T>;
19
19
  put: <T = unknown>(path: string, body?: unknown, init?: RequestInit) => Promise<T>;
20
+ patch: <T = unknown>(path: string, body?: unknown, init?: RequestInit) => Promise<T>;
20
21
  del: <T = unknown>(path: string, init?: RequestInit) => Promise<T>;
21
22
  }
22
23
 
@@ -115,10 +116,11 @@ export function useInwinkApi(baseUrl: string): InwinkApi {
115
116
  throw new InwinkApiError(response.status, await safeBody(response));
116
117
  }
117
118
 
118
- if (response.status === 204) {
119
- return undefined as T;
120
- }
121
- return (await response.json()) as T;
119
+ // Une réponse OK peut ne porter aucun corps : un 204, mais aussi un 200 — les endpoints
120
+ // d'écriture du template d'entité répondent ainsi. `response.json()` lève sur un corps
121
+ // vide, d'où la lecture en texte avant de tenter le parse.
122
+ const text = await response.text();
123
+ return (text ? (JSON.parse(text) as T) : (undefined as T));
122
124
  }
123
125
 
124
126
  const withBody =
@@ -136,6 +138,7 @@ export function useInwinkApi(baseUrl: string): InwinkApi {
136
138
  request<T>(path, { ...init, method: 'GET' }),
137
139
  post: withBody('POST'),
138
140
  put: withBody('PUT'),
141
+ patch: withBody('PATCH'),
139
142
  del: <T = unknown>(path: string, init?: RequestInit) =>
140
143
  request<T>(path, { ...init, method: 'DELETE' }),
141
144
  };