@flexacms/client 0.0.0-stage → 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 +21 -0
- package/README.md +61 -2
- package/dist/index.cjs +352 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +290 -0
- package/dist/index.d.ts +290 -0
- package/dist/index.js +319 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ivan Mercedes
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,62 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @flexacms/client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Typed, dependency-free client for the [Flexa](https://github.com/flexacms) headless CMS content API. Works in Node 20+, Bun, Deno, edge runtimes and browsers.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @flexacms/client
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createClient, localize } from '@flexacms/client';
|
|
11
|
+
|
|
12
|
+
const flexa = createClient({
|
|
13
|
+
url: process.env.FLEXA_URL!, // https://cms.example.com
|
|
14
|
+
apiKey: process.env.FLEXA_API_KEY!,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const { data: posts, meta } = await flexa
|
|
18
|
+
.entity('posts')
|
|
19
|
+
.list({ status: 'published', perPage: 12 });
|
|
20
|
+
const post = await flexa.entity('posts').find('hello-world'); // null when missing
|
|
21
|
+
const headline = localize(post?.values.headline, 'es', ['en']);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
> Keep the API key on the server. Anyone with it can do what its abilities allow; use a **Read** key limited to the entities a public site needs.
|
|
25
|
+
|
|
26
|
+
## Typed content
|
|
27
|
+
|
|
28
|
+
Generate types for your workspace with [`@flexacms/cli`](../cli) and pass them to the client:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import type { FlexaSchema } from './flexa';
|
|
32
|
+
|
|
33
|
+
const flexa = createClient<FlexaSchema>({ url, apiKey });
|
|
34
|
+
const page = await flexa.entity('pages').get('home');
|
|
35
|
+
page.values.headline.en; // string | null | undefined, typed from your content model
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## API
|
|
39
|
+
|
|
40
|
+
| Method | Description |
|
|
41
|
+
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
42
|
+
| `entities()` | Content models the key can read |
|
|
43
|
+
| `entity(slug).schema()` | Fields, groups, categories and locales |
|
|
44
|
+
| `entity(slug).list(params)` | One page: `status`, `search`, `category`, `page`, `perPage`, `trashed`, `includeRelations` |
|
|
45
|
+
| `entity(slug).all(params)` / `iterate(params)` | Every matching entry, page by page |
|
|
46
|
+
| `entity(slug).get(idOrSlug)` / `find(idOrSlug)` | One entry (`find` resolves to `null` on 404) |
|
|
47
|
+
| `entity(slug).create(input)` / `update(id, input)` | Write entries (Write ability) |
|
|
48
|
+
| `entity(slug).delete(id, { force })` / `restore(id)` | Trash, delete for good or restore |
|
|
49
|
+
|
|
50
|
+
Every method accepts a last `{ signal, init }` argument; `init` is merged into the `fetch` call.
|
|
51
|
+
|
|
52
|
+
## Errors and retries
|
|
53
|
+
|
|
54
|
+
Failed requests throw a `FlexaError` with `status`, `message`, `errors` (validation errors keyed by field) and helpers such as `isNotFound` or `isValidationError`. Reads are retried after `429`, `502`, `503`, `504` and network failures (honouring `Retry-After`); writes are never retried.
|
|
55
|
+
|
|
56
|
+
| Option | Default | |
|
|
57
|
+
| --------- | -------------- | ---------------------------------------- |
|
|
58
|
+
| `apiPath` | `/api/v1` | Path of the content API |
|
|
59
|
+
| `timeout` | `30000` | Milliseconds before a request is aborted |
|
|
60
|
+
| `retries` | `2` | Retries for reads |
|
|
61
|
+
| `headers` | — | Extra headers on every request |
|
|
62
|
+
| `fetch` | global `fetch` | Custom fetch implementation |
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
EntityClient: () => EntityClient,
|
|
24
|
+
FlexaClient: () => FlexaClient,
|
|
25
|
+
FlexaError: () => FlexaError,
|
|
26
|
+
createClient: () => createClient,
|
|
27
|
+
isFlexaError: () => isFlexaError,
|
|
28
|
+
isLocalized: () => isLocalized,
|
|
29
|
+
localize: () => localize
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
|
|
33
|
+
// src/errors.ts
|
|
34
|
+
var FlexaError = class extends Error {
|
|
35
|
+
constructor(message, status, errors = {}, body = null) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.status = status;
|
|
38
|
+
this.errors = errors;
|
|
39
|
+
this.body = body;
|
|
40
|
+
}
|
|
41
|
+
status;
|
|
42
|
+
errors;
|
|
43
|
+
body;
|
|
44
|
+
name = "FlexaError";
|
|
45
|
+
get isNotFound() {
|
|
46
|
+
return this.status === 404;
|
|
47
|
+
}
|
|
48
|
+
get isUnauthorized() {
|
|
49
|
+
return this.status === 401;
|
|
50
|
+
}
|
|
51
|
+
get isForbidden() {
|
|
52
|
+
return this.status === 403;
|
|
53
|
+
}
|
|
54
|
+
get isValidationError() {
|
|
55
|
+
return this.status === 422;
|
|
56
|
+
}
|
|
57
|
+
get isRateLimited() {
|
|
58
|
+
return this.status === 429;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
function isFlexaError(error) {
|
|
62
|
+
return error instanceof FlexaError;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/client.ts
|
|
66
|
+
var RETRYABLE_STATUSES = /* @__PURE__ */ new Set([429, 502, 503, 504]);
|
|
67
|
+
function sleep(milliseconds) {
|
|
68
|
+
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
69
|
+
}
|
|
70
|
+
var FlexaClient = class {
|
|
71
|
+
baseUrl;
|
|
72
|
+
options;
|
|
73
|
+
constructor(options) {
|
|
74
|
+
if (!options.url) {
|
|
75
|
+
throw new TypeError('Flexa: the "url" option is required.');
|
|
76
|
+
}
|
|
77
|
+
if (!options.apiKey) {
|
|
78
|
+
throw new TypeError('Flexa: the "apiKey" option is required.');
|
|
79
|
+
}
|
|
80
|
+
const apiPath = `/${(options.apiPath ?? "/api/v1").replace(/^\/+|\/+$/g, "")}`;
|
|
81
|
+
this.baseUrl = `${options.url.replace(/\/+$/, "")}${apiPath}`;
|
|
82
|
+
this.options = { timeout: 3e4, retries: 2, ...options };
|
|
83
|
+
}
|
|
84
|
+
/** Entities (content models) the API key can read. */
|
|
85
|
+
async entities(options) {
|
|
86
|
+
const response = await this.request(
|
|
87
|
+
"GET",
|
|
88
|
+
"/entities",
|
|
89
|
+
void 0,
|
|
90
|
+
options
|
|
91
|
+
);
|
|
92
|
+
return response.data;
|
|
93
|
+
}
|
|
94
|
+
/** Typed access to the entries of one entity. */
|
|
95
|
+
entity(slug) {
|
|
96
|
+
return new EntityClient(this, slug);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Send a request to the content API. Exposed for endpoints the typed helpers
|
|
100
|
+
* do not cover yet; `path` is relative to the API base (e.g. `/posts`).
|
|
101
|
+
*/
|
|
102
|
+
async request(method, path, body, options = {}) {
|
|
103
|
+
const fetchImplementation = this.options.fetch ?? globalThis.fetch;
|
|
104
|
+
if (typeof fetchImplementation !== "function") {
|
|
105
|
+
throw new TypeError(
|
|
106
|
+
'Flexa: no fetch implementation available. Pass one with the "fetch" option.'
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
const attempts = method === "GET" ? this.options.retries + 1 : 1;
|
|
110
|
+
let lastError;
|
|
111
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
112
|
+
const signals = [
|
|
113
|
+
AbortSignal.timeout(this.options.timeout),
|
|
114
|
+
options.signal
|
|
115
|
+
].filter((signal) => signal !== void 0);
|
|
116
|
+
let response;
|
|
117
|
+
try {
|
|
118
|
+
response = await fetchImplementation(`${this.baseUrl}${path}`, {
|
|
119
|
+
...options.init,
|
|
120
|
+
method,
|
|
121
|
+
signal: signals.length > 1 ? AbortSignal.any(signals) : signals[0],
|
|
122
|
+
headers: {
|
|
123
|
+
Accept: "application/json",
|
|
124
|
+
...body === void 0 ? {} : { "Content-Type": "application/json" },
|
|
125
|
+
...this.options.headers,
|
|
126
|
+
...options.init?.headers,
|
|
127
|
+
Authorization: `Bearer ${this.options.apiKey}`
|
|
128
|
+
},
|
|
129
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
130
|
+
});
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (options.signal?.aborted || attempt === attempts) {
|
|
133
|
+
throw new FlexaError(
|
|
134
|
+
error instanceof Error ? `Flexa request failed: ${error.message}` : "Flexa request failed.",
|
|
135
|
+
0
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
lastError = error;
|
|
139
|
+
await sleep(this.backoff(attempt));
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (response.ok) {
|
|
143
|
+
return response.status === 204 ? void 0 : await response.json();
|
|
144
|
+
}
|
|
145
|
+
if (attempt < attempts && RETRYABLE_STATUSES.has(response.status)) {
|
|
146
|
+
await sleep(
|
|
147
|
+
this.backoff(attempt, response.headers.get("Retry-After"))
|
|
148
|
+
);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
throw await this.toError(response);
|
|
152
|
+
}
|
|
153
|
+
throw lastError;
|
|
154
|
+
}
|
|
155
|
+
backoff(attempt, retryAfter) {
|
|
156
|
+
const seconds = Number(retryAfter);
|
|
157
|
+
if (retryAfter && Number.isFinite(seconds)) {
|
|
158
|
+
return Math.min(seconds * 1e3, 3e4);
|
|
159
|
+
}
|
|
160
|
+
return 250 * 2 ** (attempt - 1);
|
|
161
|
+
}
|
|
162
|
+
async toError(response) {
|
|
163
|
+
let body = null;
|
|
164
|
+
try {
|
|
165
|
+
body = await response.json();
|
|
166
|
+
} catch {
|
|
167
|
+
}
|
|
168
|
+
const payload = body ?? {};
|
|
169
|
+
const message = typeof payload.message === "string" && payload.message !== "" ? payload.message : `Flexa request failed with status ${response.status}.`;
|
|
170
|
+
return new FlexaError(
|
|
171
|
+
message,
|
|
172
|
+
response.status,
|
|
173
|
+
payload.errors && typeof payload.errors === "object" ? payload.errors : {},
|
|
174
|
+
body
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
var EntityClient = class {
|
|
179
|
+
constructor(client, slug) {
|
|
180
|
+
this.client = client;
|
|
181
|
+
this.slug = slug;
|
|
182
|
+
}
|
|
183
|
+
client;
|
|
184
|
+
slug;
|
|
185
|
+
get path() {
|
|
186
|
+
return `/${encodeURIComponent(this.slug)}`;
|
|
187
|
+
}
|
|
188
|
+
/** Fields, groups, categories and locales of the entity. */
|
|
189
|
+
async schema(options) {
|
|
190
|
+
const response = await this.client.request(
|
|
191
|
+
"GET",
|
|
192
|
+
`${this.path}/schema`,
|
|
193
|
+
void 0,
|
|
194
|
+
options
|
|
195
|
+
);
|
|
196
|
+
return response.data;
|
|
197
|
+
}
|
|
198
|
+
/** One page of entries. */
|
|
199
|
+
list(params = {}, options) {
|
|
200
|
+
const query = new URLSearchParams();
|
|
201
|
+
for (const [key, value] of Object.entries({
|
|
202
|
+
status: params.status,
|
|
203
|
+
search: params.search,
|
|
204
|
+
category: params.category,
|
|
205
|
+
page: params.page,
|
|
206
|
+
per_page: params.perPage,
|
|
207
|
+
trashed: params.trashed,
|
|
208
|
+
include: params.includeRelations ? "relations" : void 0
|
|
209
|
+
})) {
|
|
210
|
+
if (value !== void 0 && value !== null && value !== "") {
|
|
211
|
+
query.set(key, String(value));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const search = query.toString();
|
|
215
|
+
return this.client.request(
|
|
216
|
+
"GET",
|
|
217
|
+
`${this.path}${search ? `?${search}` : ""}`,
|
|
218
|
+
void 0,
|
|
219
|
+
options
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
/** Iterate over every matching entry, fetching pages as needed. */
|
|
223
|
+
async *iterate(params = {}, options) {
|
|
224
|
+
let page = 1;
|
|
225
|
+
let lastPage = 1;
|
|
226
|
+
do {
|
|
227
|
+
const result = await this.list(
|
|
228
|
+
{ perPage: 100, ...params, page },
|
|
229
|
+
options
|
|
230
|
+
);
|
|
231
|
+
yield* result.data;
|
|
232
|
+
lastPage = result.meta.last_page;
|
|
233
|
+
page++;
|
|
234
|
+
} while (page <= lastPage);
|
|
235
|
+
}
|
|
236
|
+
/** Every matching entry, across all pages. */
|
|
237
|
+
async all(params = {}, options) {
|
|
238
|
+
const entries = [];
|
|
239
|
+
for await (const entry of this.iterate(params, options)) {
|
|
240
|
+
entries.push(entry);
|
|
241
|
+
}
|
|
242
|
+
return entries;
|
|
243
|
+
}
|
|
244
|
+
/** An entry by id or slug. Throws a 404 `FlexaError` when it does not exist. */
|
|
245
|
+
async get(idOrSlug, params = {}, options) {
|
|
246
|
+
const query = params.includeRelations ? "?include=relations" : "";
|
|
247
|
+
const response = await this.client.request(
|
|
248
|
+
"GET",
|
|
249
|
+
`${this.path}/${encodeURIComponent(String(idOrSlug))}${query}`,
|
|
250
|
+
void 0,
|
|
251
|
+
options
|
|
252
|
+
);
|
|
253
|
+
return response.data;
|
|
254
|
+
}
|
|
255
|
+
/** Like `get()`, but resolves to `null` when the entry does not exist. */
|
|
256
|
+
async find(idOrSlug, params = {}, options) {
|
|
257
|
+
try {
|
|
258
|
+
return await this.get(idOrSlug, params, options);
|
|
259
|
+
} catch (error) {
|
|
260
|
+
if (error instanceof FlexaError && error.isNotFound) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
throw error;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/** Create an entry. Needs the Write ability. */
|
|
267
|
+
async create(input, options) {
|
|
268
|
+
const response = await this.client.request(
|
|
269
|
+
"POST",
|
|
270
|
+
this.path,
|
|
271
|
+
input,
|
|
272
|
+
options
|
|
273
|
+
);
|
|
274
|
+
return response.data;
|
|
275
|
+
}
|
|
276
|
+
/** Partially update an entry. Needs the Write ability. */
|
|
277
|
+
async update(idOrSlug, input, options) {
|
|
278
|
+
const response = await this.client.request(
|
|
279
|
+
"PATCH",
|
|
280
|
+
`${this.path}/${encodeURIComponent(String(idOrSlug))}`,
|
|
281
|
+
input,
|
|
282
|
+
options
|
|
283
|
+
);
|
|
284
|
+
return response.data;
|
|
285
|
+
}
|
|
286
|
+
/** Move an entry to the trash, or delete it for good with `force`. Needs the Delete ability. */
|
|
287
|
+
async delete(idOrSlug, params = {}, options) {
|
|
288
|
+
await this.client.request(
|
|
289
|
+
"DELETE",
|
|
290
|
+
`${this.path}/${encodeURIComponent(String(idOrSlug))}${params.force ? "?force=1" : ""}`,
|
|
291
|
+
void 0,
|
|
292
|
+
options
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
/** Restore a trashed entry. Needs the Write ability. */
|
|
296
|
+
async restore(idOrSlug, options) {
|
|
297
|
+
const response = await this.client.request(
|
|
298
|
+
"POST",
|
|
299
|
+
`${this.path}/${encodeURIComponent(String(idOrSlug))}/restore`,
|
|
300
|
+
void 0,
|
|
301
|
+
options
|
|
302
|
+
);
|
|
303
|
+
return response.data;
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
function createClient(options) {
|
|
307
|
+
return new FlexaClient(options);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// src/localize.ts
|
|
311
|
+
function isLocalized(value, locales) {
|
|
312
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
const keys = Object.keys(value);
|
|
316
|
+
if (keys.length === 0) {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
return locales ? keys.every((key) => locales.includes(key)) : keys.every((key) => /^[a-z]{2,3}([_-][A-Za-z]{2,4})?$/.test(key));
|
|
320
|
+
}
|
|
321
|
+
function localize(value, locale, fallbacks = []) {
|
|
322
|
+
if (value === null || value === void 0) {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
if (!isLocalized(value)) {
|
|
326
|
+
return value;
|
|
327
|
+
}
|
|
328
|
+
const translations = value;
|
|
329
|
+
for (const candidate of [locale, ...fallbacks]) {
|
|
330
|
+
const translation = translations[candidate];
|
|
331
|
+
if (translation !== null && translation !== void 0 && translation !== "") {
|
|
332
|
+
return translation;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
for (const translation of Object.values(translations)) {
|
|
336
|
+
if (translation !== null && translation !== void 0 && translation !== "") {
|
|
337
|
+
return translation;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
343
|
+
0 && (module.exports = {
|
|
344
|
+
EntityClient,
|
|
345
|
+
FlexaClient,
|
|
346
|
+
FlexaError,
|
|
347
|
+
createClient,
|
|
348
|
+
isFlexaError,
|
|
349
|
+
isLocalized,
|
|
350
|
+
localize
|
|
351
|
+
});
|
|
352
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/client.ts","../src/localize.ts"],"sourcesContent":["export { createClient, EntityClient, FlexaClient } from './client';\nexport type { FlexaClientOptions } from './client';\nexport { FlexaError, isFlexaError } from './errors';\nexport { isLocalized, localize } from './localize';\nexport type * from './types';\n","/**\n * Error thrown for every non-2xx response from the content API.\n */\nexport class FlexaError extends Error {\n override readonly name = 'FlexaError';\n\n constructor(\n message: string,\n /** HTTP status, or 0 when the request never reached the server. */\n readonly status: number,\n /** Validation errors keyed by field (422 responses). */\n readonly errors: Record<string, string[]> = {},\n /** Parsed response body, when there was one. */\n readonly body: unknown = null,\n ) {\n super(message);\n }\n\n get isNotFound(): boolean {\n return this.status === 404;\n }\n\n get isUnauthorized(): boolean {\n return this.status === 401;\n }\n\n get isForbidden(): boolean {\n return this.status === 403;\n }\n\n get isValidationError(): boolean {\n return this.status === 422;\n }\n\n get isRateLimited(): boolean {\n return this.status === 429;\n }\n}\n\nexport function isFlexaError(error: unknown): error is FlexaError {\n return error instanceof FlexaError;\n}\n","import { FlexaError } from './errors';\nimport type {\n ContentSchema,\n EntitySchema,\n EntitySummary,\n Entry,\n EntryInput,\n EntryValues,\n GetParams,\n ListParams,\n Paginated,\n RequestOptions,\n} from './types';\n\nexport interface FlexaClientOptions {\n /** Base URL of your Flexa installation, e.g. `https://cms.example.com`. */\n url: string;\n /**\n * Workspace API key. Keep it on the server: anyone with the key can do what\n * its abilities allow. Use a Read-only key for public websites.\n */\n apiKey: string;\n /** Path of the content API. Defaults to `/api/v1`. */\n apiPath?: string;\n /** Custom fetch implementation (defaults to the global `fetch`). */\n fetch?: typeof fetch;\n /** Extra headers sent with every request. */\n headers?: Record<string, string>;\n /** Abort requests that take longer than this, in milliseconds. Defaults to 30s. */\n timeout?: number;\n /**\n * How many times to retry reads after a rate limit (429), a gateway error\n * (502/503/504) or a network failure. Writes are never retried. Defaults to 2.\n */\n retries?: number;\n}\n\ntype ValuesOf<\n TSchema extends object,\n TEntity extends string,\n> = TEntity extends keyof TSchema\n ? TSchema[TEntity] extends object\n ? TSchema[TEntity]\n : EntryValues\n : EntryValues;\n\n/** The part of the client entity helpers need: sending requests. */\ntype RequestSender = Pick<FlexaClient, 'request'>;\n\nconst RETRYABLE_STATUSES = new Set([429, 502, 503, 504]);\n\nfunction sleep(milliseconds: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, milliseconds));\n}\n\n/**\n * Content API client for one Flexa workspace (the workspace is set by the API key).\n */\nexport class FlexaClient<TSchema extends object = ContentSchema> {\n readonly baseUrl: string;\n\n private readonly options: Required<\n Pick<FlexaClientOptions, 'timeout' | 'retries'>\n > &\n FlexaClientOptions;\n\n constructor(options: FlexaClientOptions) {\n if (!options.url) {\n throw new TypeError('Flexa: the \"url\" option is required.');\n }\n\n if (!options.apiKey) {\n throw new TypeError('Flexa: the \"apiKey\" option is required.');\n }\n\n const apiPath = `/${(options.apiPath ?? '/api/v1').replace(/^\\/+|\\/+$/g, '')}`;\n\n this.baseUrl = `${options.url.replace(/\\/+$/, '')}${apiPath}`;\n this.options = { timeout: 30_000, retries: 2, ...options };\n }\n\n /** Entities (content models) the API key can read. */\n async entities(options?: RequestOptions): Promise<EntitySummary[]> {\n const response = await this.request<{ data: EntitySummary[] }>(\n 'GET',\n '/entities',\n undefined,\n options,\n );\n\n return response.data;\n }\n\n /** Typed access to the entries of one entity. */\n entity<TEntity extends Extract<keyof TSchema, string> | (string & {})>(\n slug: TEntity,\n ): EntityClient<ValuesOf<TSchema, TEntity>> {\n return new EntityClient(this, slug);\n }\n\n /**\n * Send a request to the content API. Exposed for endpoints the typed helpers\n * do not cover yet; `path` is relative to the API base (e.g. `/posts`).\n */\n async request<T>(\n method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE',\n path: string,\n body?: unknown,\n options: RequestOptions = {},\n ): Promise<T> {\n const fetchImplementation = this.options.fetch ?? globalThis.fetch;\n\n if (typeof fetchImplementation !== 'function') {\n throw new TypeError(\n 'Flexa: no fetch implementation available. Pass one with the \"fetch\" option.',\n );\n }\n\n const attempts = method === 'GET' ? this.options.retries + 1 : 1;\n let lastError: unknown;\n\n for (let attempt = 1; attempt <= attempts; attempt++) {\n const signals = [\n AbortSignal.timeout(this.options.timeout),\n options.signal,\n ].filter((signal): signal is AbortSignal => signal !== undefined);\n\n let response: Response;\n\n try {\n response = await fetchImplementation(`${this.baseUrl}${path}`, {\n ...options.init,\n method,\n signal:\n signals.length > 1\n ? AbortSignal.any(signals)\n : signals[0],\n headers: {\n Accept: 'application/json',\n ...(body === undefined\n ? {}\n : { 'Content-Type': 'application/json' }),\n ...this.options.headers,\n ...(options.init?.headers as\n | Record<string, string>\n | undefined),\n Authorization: `Bearer ${this.options.apiKey}`,\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n });\n } catch (error) {\n if (options.signal?.aborted || attempt === attempts) {\n throw new FlexaError(\n error instanceof Error\n ? `Flexa request failed: ${error.message}`\n : 'Flexa request failed.',\n 0,\n );\n }\n\n lastError = error;\n await sleep(this.backoff(attempt));\n continue;\n }\n\n if (response.ok) {\n return (\n response.status === 204 ? undefined : await response.json()\n ) as T;\n }\n\n if (attempt < attempts && RETRYABLE_STATUSES.has(response.status)) {\n await sleep(\n this.backoff(attempt, response.headers.get('Retry-After')),\n );\n continue;\n }\n\n throw await this.toError(response);\n }\n\n throw lastError;\n }\n\n private backoff(attempt: number, retryAfter?: string | null): number {\n const seconds = Number(retryAfter);\n\n if (retryAfter && Number.isFinite(seconds)) {\n return Math.min(seconds * 1000, 30_000);\n }\n\n return 250 * 2 ** (attempt - 1);\n }\n\n private async toError(response: Response): Promise<FlexaError> {\n let body: unknown = null;\n\n try {\n body = await response.json();\n } catch {\n // Not a JSON body.\n }\n\n const payload = (body ?? {}) as { message?: unknown; errors?: unknown };\n const message =\n typeof payload.message === 'string' && payload.message !== ''\n ? payload.message\n : `Flexa request failed with status ${response.status}.`;\n\n return new FlexaError(\n message,\n response.status,\n (payload.errors && typeof payload.errors === 'object'\n ? payload.errors\n : {}) as Record<string, string[]>,\n body,\n );\n }\n}\n\n/**\n * Entries of one entity: list, read, create, update, delete and restore.\n */\nexport class EntityClient<TValues extends object = EntryValues> {\n constructor(\n private readonly client: RequestSender,\n readonly slug: string,\n ) {}\n\n private get path(): string {\n return `/${encodeURIComponent(this.slug)}`;\n }\n\n /** Fields, groups, categories and locales of the entity. */\n async schema(options?: RequestOptions): Promise<EntitySchema> {\n const response = await this.client.request<{ data: EntitySchema }>(\n 'GET',\n `${this.path}/schema`,\n undefined,\n options,\n );\n\n return response.data;\n }\n\n /** One page of entries. */\n list(\n params: ListParams = {},\n options?: RequestOptions,\n ): Promise<Paginated<Entry<TValues>>> {\n const query = new URLSearchParams();\n\n for (const [key, value] of Object.entries({\n status: params.status,\n search: params.search,\n category: params.category,\n page: params.page,\n per_page: params.perPage,\n trashed: params.trashed,\n include: params.includeRelations ? 'relations' : undefined,\n })) {\n if (value !== undefined && value !== null && value !== '') {\n query.set(key, String(value));\n }\n }\n\n const search = query.toString();\n\n return this.client.request(\n 'GET',\n `${this.path}${search ? `?${search}` : ''}`,\n undefined,\n options,\n );\n }\n\n /** Iterate over every matching entry, fetching pages as needed. */\n async *iterate(\n params: Omit<ListParams, 'page'> = {},\n options?: RequestOptions,\n ): AsyncGenerator<Entry<TValues>> {\n let page = 1;\n let lastPage = 1;\n\n do {\n const result = await this.list(\n { perPage: 100, ...params, page },\n options,\n );\n\n yield* result.data;\n lastPage = result.meta.last_page;\n page++;\n } while (page <= lastPage);\n }\n\n /** Every matching entry, across all pages. */\n async all(\n params: Omit<ListParams, 'page'> = {},\n options?: RequestOptions,\n ): Promise<Entry<TValues>[]> {\n const entries: Entry<TValues>[] = [];\n\n for await (const entry of this.iterate(params, options)) {\n entries.push(entry);\n }\n\n return entries;\n }\n\n /** An entry by id or slug. Throws a 404 `FlexaError` when it does not exist. */\n async get(\n idOrSlug: number | string,\n params: GetParams = {},\n options?: RequestOptions,\n ): Promise<Entry<TValues>> {\n const query = params.includeRelations ? '?include=relations' : '';\n const response = await this.client.request<{ data: Entry<TValues> }>(\n 'GET',\n `${this.path}/${encodeURIComponent(String(idOrSlug))}${query}`,\n undefined,\n options,\n );\n\n return response.data;\n }\n\n /** Like `get()`, but resolves to `null` when the entry does not exist. */\n async find(\n idOrSlug: number | string,\n params: GetParams = {},\n options?: RequestOptions,\n ): Promise<Entry<TValues> | null> {\n try {\n return await this.get(idOrSlug, params, options);\n } catch (error) {\n if (error instanceof FlexaError && error.isNotFound) {\n return null;\n }\n\n throw error;\n }\n }\n\n /** Create an entry. Needs the Write ability. */\n async create(\n input: EntryInput<TValues>,\n options?: RequestOptions,\n ): Promise<Entry<TValues>> {\n const response = await this.client.request<{ data: Entry<TValues> }>(\n 'POST',\n this.path,\n input,\n options,\n );\n\n return response.data;\n }\n\n /** Partially update an entry. Needs the Write ability. */\n async update(\n idOrSlug: number | string,\n input: EntryInput<TValues>,\n options?: RequestOptions,\n ): Promise<Entry<TValues>> {\n const response = await this.client.request<{ data: Entry<TValues> }>(\n 'PATCH',\n `${this.path}/${encodeURIComponent(String(idOrSlug))}`,\n input,\n options,\n );\n\n return response.data;\n }\n\n /** Move an entry to the trash, or delete it for good with `force`. Needs the Delete ability. */\n async delete(\n idOrSlug: number | string,\n params: { force?: boolean } = {},\n options?: RequestOptions,\n ): Promise<void> {\n await this.client.request(\n 'DELETE',\n `${this.path}/${encodeURIComponent(String(idOrSlug))}${params.force ? '?force=1' : ''}`,\n undefined,\n options,\n );\n }\n\n /** Restore a trashed entry. Needs the Write ability. */\n async restore(\n idOrSlug: number | string,\n options?: RequestOptions,\n ): Promise<Entry<TValues>> {\n const response = await this.client.request<{ data: Entry<TValues> }>(\n 'POST',\n `${this.path}/${encodeURIComponent(String(idOrSlug))}/restore`,\n undefined,\n options,\n );\n\n return response.data;\n }\n}\n\nexport function createClient<TSchema extends object = ContentSchema>(\n options: FlexaClientOptions,\n): FlexaClient<TSchema> {\n return new FlexaClient<TSchema>(options);\n}\n","import type { Localized } from './types';\n\n/**\n * Whether a field value is a translatable value ({ \"en\": \"...\", \"es\": \"...\" }).\n */\nexport function isLocalized(\n value: unknown,\n locales?: readonly string[],\n): value is Localized<unknown> {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return false;\n }\n\n const keys = Object.keys(value);\n\n if (keys.length === 0) {\n return false;\n }\n\n return locales\n ? keys.every((key) => locales.includes(key))\n : keys.every((key) => /^[a-z]{2,3}([_-][A-Za-z]{2,4})?$/.test(key));\n}\n\n/**\n * Pick one locale of a translatable value, falling back to the given locales\n * (and then to the first non-empty translation). Plain values pass through.\n */\nexport function localize<T>(\n value: Localized<T> | T | null | undefined,\n locale: string,\n fallbacks: readonly string[] = [],\n): T | null {\n if (value === null || value === undefined) {\n return null;\n }\n\n if (!isLocalized(value)) {\n return value as T;\n }\n\n const translations = value as Localized<T>;\n\n for (const candidate of [locale, ...fallbacks]) {\n const translation = translations[candidate];\n\n if (\n translation !== null &&\n translation !== undefined &&\n translation !== ''\n ) {\n return translation;\n }\n }\n\n for (const translation of Object.values(translations)) {\n if (\n translation !== null &&\n translation !== undefined &&\n translation !== ''\n ) {\n return translation;\n }\n }\n\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,aAAN,cAAyB,MAAM;AAAA,EAGlC,YACI,SAES,QAEA,SAAmC,CAAC,GAEpC,OAAgB,MAC3B;AACE,UAAM,OAAO;AANJ;AAEA;AAEA;AAAA,EAGb;AAAA,EAPa;AAAA,EAEA;AAAA,EAEA;AAAA,EATK,OAAO;AAAA,EAczB,IAAI,aAAsB;AACtB,WAAO,KAAK,WAAW;AAAA,EAC3B;AAAA,EAEA,IAAI,iBAA0B;AAC1B,WAAO,KAAK,WAAW;AAAA,EAC3B;AAAA,EAEA,IAAI,cAAuB;AACvB,WAAO,KAAK,WAAW;AAAA,EAC3B;AAAA,EAEA,IAAI,oBAA6B;AAC7B,WAAO,KAAK,WAAW;AAAA,EAC3B;AAAA,EAEA,IAAI,gBAAyB;AACzB,WAAO,KAAK,WAAW;AAAA,EAC3B;AACJ;AAEO,SAAS,aAAa,OAAqC;AAC9D,SAAO,iBAAiB;AAC5B;;;ACQA,IAAM,qBAAqB,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