@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/dist/index.js ADDED
@@ -0,0 +1,319 @@
1
+ // src/errors.ts
2
+ var FlexaError = class extends Error {
3
+ constructor(message, status, errors = {}, body = null) {
4
+ super(message);
5
+ this.status = status;
6
+ this.errors = errors;
7
+ this.body = body;
8
+ }
9
+ status;
10
+ errors;
11
+ body;
12
+ name = "FlexaError";
13
+ get isNotFound() {
14
+ return this.status === 404;
15
+ }
16
+ get isUnauthorized() {
17
+ return this.status === 401;
18
+ }
19
+ get isForbidden() {
20
+ return this.status === 403;
21
+ }
22
+ get isValidationError() {
23
+ return this.status === 422;
24
+ }
25
+ get isRateLimited() {
26
+ return this.status === 429;
27
+ }
28
+ };
29
+ function isFlexaError(error) {
30
+ return error instanceof FlexaError;
31
+ }
32
+
33
+ // src/client.ts
34
+ var RETRYABLE_STATUSES = /* @__PURE__ */ new Set([429, 502, 503, 504]);
35
+ function sleep(milliseconds) {
36
+ return new Promise((resolve) => setTimeout(resolve, milliseconds));
37
+ }
38
+ var FlexaClient = class {
39
+ baseUrl;
40
+ options;
41
+ constructor(options) {
42
+ if (!options.url) {
43
+ throw new TypeError('Flexa: the "url" option is required.');
44
+ }
45
+ if (!options.apiKey) {
46
+ throw new TypeError('Flexa: the "apiKey" option is required.');
47
+ }
48
+ const apiPath = `/${(options.apiPath ?? "/api/v1").replace(/^\/+|\/+$/g, "")}`;
49
+ this.baseUrl = `${options.url.replace(/\/+$/, "")}${apiPath}`;
50
+ this.options = { timeout: 3e4, retries: 2, ...options };
51
+ }
52
+ /** Entities (content models) the API key can read. */
53
+ async entities(options) {
54
+ const response = await this.request(
55
+ "GET",
56
+ "/entities",
57
+ void 0,
58
+ options
59
+ );
60
+ return response.data;
61
+ }
62
+ /** Typed access to the entries of one entity. */
63
+ entity(slug) {
64
+ return new EntityClient(this, slug);
65
+ }
66
+ /**
67
+ * Send a request to the content API. Exposed for endpoints the typed helpers
68
+ * do not cover yet; `path` is relative to the API base (e.g. `/posts`).
69
+ */
70
+ async request(method, path, body, options = {}) {
71
+ const fetchImplementation = this.options.fetch ?? globalThis.fetch;
72
+ if (typeof fetchImplementation !== "function") {
73
+ throw new TypeError(
74
+ 'Flexa: no fetch implementation available. Pass one with the "fetch" option.'
75
+ );
76
+ }
77
+ const attempts = method === "GET" ? this.options.retries + 1 : 1;
78
+ let lastError;
79
+ for (let attempt = 1; attempt <= attempts; attempt++) {
80
+ const signals = [
81
+ AbortSignal.timeout(this.options.timeout),
82
+ options.signal
83
+ ].filter((signal) => signal !== void 0);
84
+ let response;
85
+ try {
86
+ response = await fetchImplementation(`${this.baseUrl}${path}`, {
87
+ ...options.init,
88
+ method,
89
+ signal: signals.length > 1 ? AbortSignal.any(signals) : signals[0],
90
+ headers: {
91
+ Accept: "application/json",
92
+ ...body === void 0 ? {} : { "Content-Type": "application/json" },
93
+ ...this.options.headers,
94
+ ...options.init?.headers,
95
+ Authorization: `Bearer ${this.options.apiKey}`
96
+ },
97
+ body: body === void 0 ? void 0 : JSON.stringify(body)
98
+ });
99
+ } catch (error) {
100
+ if (options.signal?.aborted || attempt === attempts) {
101
+ throw new FlexaError(
102
+ error instanceof Error ? `Flexa request failed: ${error.message}` : "Flexa request failed.",
103
+ 0
104
+ );
105
+ }
106
+ lastError = error;
107
+ await sleep(this.backoff(attempt));
108
+ continue;
109
+ }
110
+ if (response.ok) {
111
+ return response.status === 204 ? void 0 : await response.json();
112
+ }
113
+ if (attempt < attempts && RETRYABLE_STATUSES.has(response.status)) {
114
+ await sleep(
115
+ this.backoff(attempt, response.headers.get("Retry-After"))
116
+ );
117
+ continue;
118
+ }
119
+ throw await this.toError(response);
120
+ }
121
+ throw lastError;
122
+ }
123
+ backoff(attempt, retryAfter) {
124
+ const seconds = Number(retryAfter);
125
+ if (retryAfter && Number.isFinite(seconds)) {
126
+ return Math.min(seconds * 1e3, 3e4);
127
+ }
128
+ return 250 * 2 ** (attempt - 1);
129
+ }
130
+ async toError(response) {
131
+ let body = null;
132
+ try {
133
+ body = await response.json();
134
+ } catch {
135
+ }
136
+ const payload = body ?? {};
137
+ const message = typeof payload.message === "string" && payload.message !== "" ? payload.message : `Flexa request failed with status ${response.status}.`;
138
+ return new FlexaError(
139
+ message,
140
+ response.status,
141
+ payload.errors && typeof payload.errors === "object" ? payload.errors : {},
142
+ body
143
+ );
144
+ }
145
+ };
146
+ var EntityClient = class {
147
+ constructor(client, slug) {
148
+ this.client = client;
149
+ this.slug = slug;
150
+ }
151
+ client;
152
+ slug;
153
+ get path() {
154
+ return `/${encodeURIComponent(this.slug)}`;
155
+ }
156
+ /** Fields, groups, categories and locales of the entity. */
157
+ async schema(options) {
158
+ const response = await this.client.request(
159
+ "GET",
160
+ `${this.path}/schema`,
161
+ void 0,
162
+ options
163
+ );
164
+ return response.data;
165
+ }
166
+ /** One page of entries. */
167
+ list(params = {}, options) {
168
+ const query = new URLSearchParams();
169
+ for (const [key, value] of Object.entries({
170
+ status: params.status,
171
+ search: params.search,
172
+ category: params.category,
173
+ page: params.page,
174
+ per_page: params.perPage,
175
+ trashed: params.trashed,
176
+ include: params.includeRelations ? "relations" : void 0
177
+ })) {
178
+ if (value !== void 0 && value !== null && value !== "") {
179
+ query.set(key, String(value));
180
+ }
181
+ }
182
+ const search = query.toString();
183
+ return this.client.request(
184
+ "GET",
185
+ `${this.path}${search ? `?${search}` : ""}`,
186
+ void 0,
187
+ options
188
+ );
189
+ }
190
+ /** Iterate over every matching entry, fetching pages as needed. */
191
+ async *iterate(params = {}, options) {
192
+ let page = 1;
193
+ let lastPage = 1;
194
+ do {
195
+ const result = await this.list(
196
+ { perPage: 100, ...params, page },
197
+ options
198
+ );
199
+ yield* result.data;
200
+ lastPage = result.meta.last_page;
201
+ page++;
202
+ } while (page <= lastPage);
203
+ }
204
+ /** Every matching entry, across all pages. */
205
+ async all(params = {}, options) {
206
+ const entries = [];
207
+ for await (const entry of this.iterate(params, options)) {
208
+ entries.push(entry);
209
+ }
210
+ return entries;
211
+ }
212
+ /** An entry by id or slug. Throws a 404 `FlexaError` when it does not exist. */
213
+ async get(idOrSlug, params = {}, options) {
214
+ const query = params.includeRelations ? "?include=relations" : "";
215
+ const response = await this.client.request(
216
+ "GET",
217
+ `${this.path}/${encodeURIComponent(String(idOrSlug))}${query}`,
218
+ void 0,
219
+ options
220
+ );
221
+ return response.data;
222
+ }
223
+ /** Like `get()`, but resolves to `null` when the entry does not exist. */
224
+ async find(idOrSlug, params = {}, options) {
225
+ try {
226
+ return await this.get(idOrSlug, params, options);
227
+ } catch (error) {
228
+ if (error instanceof FlexaError && error.isNotFound) {
229
+ return null;
230
+ }
231
+ throw error;
232
+ }
233
+ }
234
+ /** Create an entry. Needs the Write ability. */
235
+ async create(input, options) {
236
+ const response = await this.client.request(
237
+ "POST",
238
+ this.path,
239
+ input,
240
+ options
241
+ );
242
+ return response.data;
243
+ }
244
+ /** Partially update an entry. Needs the Write ability. */
245
+ async update(idOrSlug, input, options) {
246
+ const response = await this.client.request(
247
+ "PATCH",
248
+ `${this.path}/${encodeURIComponent(String(idOrSlug))}`,
249
+ input,
250
+ options
251
+ );
252
+ return response.data;
253
+ }
254
+ /** Move an entry to the trash, or delete it for good with `force`. Needs the Delete ability. */
255
+ async delete(idOrSlug, params = {}, options) {
256
+ await this.client.request(
257
+ "DELETE",
258
+ `${this.path}/${encodeURIComponent(String(idOrSlug))}${params.force ? "?force=1" : ""}`,
259
+ void 0,
260
+ options
261
+ );
262
+ }
263
+ /** Restore a trashed entry. Needs the Write ability. */
264
+ async restore(idOrSlug, options) {
265
+ const response = await this.client.request(
266
+ "POST",
267
+ `${this.path}/${encodeURIComponent(String(idOrSlug))}/restore`,
268
+ void 0,
269
+ options
270
+ );
271
+ return response.data;
272
+ }
273
+ };
274
+ function createClient(options) {
275
+ return new FlexaClient(options);
276
+ }
277
+
278
+ // src/localize.ts
279
+ function isLocalized(value, locales) {
280
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
281
+ return false;
282
+ }
283
+ const keys = Object.keys(value);
284
+ if (keys.length === 0) {
285
+ return false;
286
+ }
287
+ return locales ? keys.every((key) => locales.includes(key)) : keys.every((key) => /^[a-z]{2,3}([_-][A-Za-z]{2,4})?$/.test(key));
288
+ }
289
+ function localize(value, locale, fallbacks = []) {
290
+ if (value === null || value === void 0) {
291
+ return null;
292
+ }
293
+ if (!isLocalized(value)) {
294
+ return value;
295
+ }
296
+ const translations = value;
297
+ for (const candidate of [locale, ...fallbacks]) {
298
+ const translation = translations[candidate];
299
+ if (translation !== null && translation !== void 0 && translation !== "") {
300
+ return translation;
301
+ }
302
+ }
303
+ for (const translation of Object.values(translations)) {
304
+ if (translation !== null && translation !== void 0 && translation !== "") {
305
+ return translation;
306
+ }
307
+ }
308
+ return null;
309
+ }
310
+ export {
311
+ EntityClient,
312
+ FlexaClient,
313
+ FlexaError,
314
+ createClient,
315
+ isFlexaError,
316
+ isLocalized,
317
+ localize
318
+ };
319
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/client.ts","../src/localize.ts"],"sourcesContent":["/**\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 (\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X;AAAA,EACJ;AAEA,SAAO;AACX;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
- "name": "@flexacms/client",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@flexacms/client",
3
+ "version": "0.1.0",
4
+ "description": "Typed, dependency-free client for the Flexa headless CMS content API.",
5
+ "keywords": [
6
+ "api-client",
7
+ "cms",
8
+ "flexa",
9
+ "headless",
10
+ "sdk"
11
+ ],
12
+ "homepage": "https://github.com/flexacms/sdk/tree/main/packages/client#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/flexacms/sdk/issues"
15
+ },
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/flexacms/sdk.git",
20
+ "directory": "packages/client"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md",
25
+ "LICENSE"
26
+ ],
27
+ "type": "module",
28
+ "sideEffects": false,
29
+ "main": "./dist/index.cjs",
30
+ "module": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "import": {
35
+ "types": "./dist/index.d.ts",
36
+ "default": "./dist/index.js"
37
+ },
38
+ "require": {
39
+ "types": "./dist/index.d.cts",
40
+ "default": "./dist/index.cjs"
41
+ }
42
+ }
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "scripts": {
48
+ "build": "tsup",
49
+ "typecheck": "tsc -p tsconfig.json"
50
+ },
51
+ "engines": {
52
+ "node": ">=20"
53
+ }
54
+ }