@conloca/content-api-client 0.1.15 → 0.1.16

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.
@@ -0,0 +1,236 @@
1
+ /**
2
+ * Test helpers for mocking Content API Client
3
+ */
4
+ /**
5
+ * API route patterns used by the content API
6
+ * These match the routes defined in content-api/src/middleware.ts
7
+ */
8
+ export const API_ROUTES = {
9
+ SITES: '/sites',
10
+ ALL_CONTENT: '/content',
11
+ CONTENT_BY_ID: (id) => `/content/${id}`,
12
+ LOCALIZED_CONTENT: (id, locale) => `/content/${id}/${locale}`,
13
+ SITE_PAGES: (site) => `/${site}/pages`,
14
+ BLOCKS: '/blocks',
15
+ COLLECTIONS: '/content/collections',
16
+ BATCH_UPDATE: '/content/batch',
17
+ FIND_UNTRANSLATED: (locale) => `/untranslated/${locale}`,
18
+ DATA_CONTEXT: '/data-context',
19
+ };
20
+ /**
21
+ * Creates a mock fetch function for testing
22
+ * Note: This requires a mock function from your test framework (e.g., bun:test, jest, vitest)
23
+ */
24
+ export function createMockFetch(mockFn) {
25
+ return mockFn(() => Promise.resolve(new Response()));
26
+ }
27
+ /**
28
+ * Creates a Response object with JSON body
29
+ */
30
+ export function jsonResponse(body, options = {}) {
31
+ return new Response(JSON.stringify(body), {
32
+ status: options.status || 200,
33
+ headers: {
34
+ 'Content-Type': 'application/json',
35
+ ...options.headers,
36
+ },
37
+ });
38
+ }
39
+ /**
40
+ * Creates a mock ContentEntry
41
+ */
42
+ export function mockContentEntry(overrides) {
43
+ return {
44
+ id: 'test-id',
45
+ site: 'test-site',
46
+ collection: 'pages',
47
+ type: 'puck',
48
+ kind: 'page',
49
+ locales: {
50
+ en: {
51
+ locale: 'en',
52
+ etag: 'metaHash.contentHash',
53
+ created: '2024-01-01T00:00:00Z',
54
+ modified: '2024-01-01T00:00:00Z',
55
+ pathname: '/test',
56
+ meta: {
57
+ title: 'Test Page',
58
+ },
59
+ content: { puckData: {} },
60
+ },
61
+ },
62
+ ...overrides,
63
+ };
64
+ }
65
+ /**
66
+ * Creates a mock ContentManifest
67
+ */
68
+ export function mockContentManifest(overrides) {
69
+ return {
70
+ id: 'test-id',
71
+ site: 'test-site',
72
+ collection: 'pages',
73
+ type: 'puck',
74
+ kind: 'page',
75
+ locales: {
76
+ en: {
77
+ locale: 'en',
78
+ etag: 'metaHash.contentHash',
79
+ created: '2024-01-01T00:00:00Z',
80
+ modified: '2024-01-01T00:00:00Z',
81
+ pathname: '/test',
82
+ meta: {
83
+ title: 'Test Page',
84
+ },
85
+ },
86
+ },
87
+ ...overrides,
88
+ };
89
+ }
90
+ /**
91
+ * Creates a mock LocalizedEntry
92
+ */
93
+ export function mockLocalizedEntry(overrides) {
94
+ return {
95
+ id: 'test-id',
96
+ site: 'test-site',
97
+ collection: 'pages',
98
+ type: 'puck',
99
+ kind: 'page',
100
+ localized: {
101
+ locale: 'en',
102
+ etag: 'metaHash.contentHash',
103
+ created: '2024-01-01T00:00:00Z',
104
+ modified: '2024-01-01T00:00:00Z',
105
+ pathname: '/test',
106
+ meta: {
107
+ title: 'Test Page',
108
+ },
109
+ content: { puckData: {} },
110
+ },
111
+ ...overrides,
112
+ };
113
+ }
114
+ /**
115
+ * Creates a mock CreateResult
116
+ */
117
+ export function mockCreateResult(overrides) {
118
+ return {
119
+ success: true,
120
+ id: 'new-id',
121
+ etag: 'newMetaHash.newContentHash',
122
+ created: new Date('2024-01-01T00:00:00.000Z'),
123
+ ...overrides,
124
+ };
125
+ }
126
+ /**
127
+ * Creates a mock UpdateResult
128
+ */
129
+ export function mockUpdateResult(overrides) {
130
+ return {
131
+ success: true,
132
+ etag: 'updatedMetaHash.updatedContentHash',
133
+ modified: new Date('2024-01-01T00:00:00.000Z'),
134
+ ...overrides,
135
+ };
136
+ }
137
+ /**
138
+ * Creates a mock DeleteResult
139
+ */
140
+ export function mockDeleteResult(overrides) {
141
+ return {
142
+ success: true,
143
+ ...overrides,
144
+ };
145
+ }
146
+ /**
147
+ * Creates a mock BatchResult
148
+ */
149
+ export function mockBatchResult(overrides) {
150
+ return {
151
+ operations: [],
152
+ success: true,
153
+ updated: 0,
154
+ failed: 0,
155
+ ...overrides,
156
+ };
157
+ }
158
+ /**
159
+ * Mock helper for setting up common API responses
160
+ */
161
+ export class MockAPIResponses {
162
+ fetchMock;
163
+ constructor(fetchMock) {
164
+ this.fetchMock = fetchMock;
165
+ }
166
+ mockGetContent(content, status = 200) {
167
+ if (content) {
168
+ this.fetchMock.mockResolvedValueOnce(jsonResponse(content, { status }));
169
+ }
170
+ else {
171
+ this.fetchMock.mockResolvedValueOnce(new Response('Not found', { status: 404 }));
172
+ }
173
+ return this;
174
+ }
175
+ mockGetLocalized(entry, status = 200) {
176
+ if (entry) {
177
+ this.fetchMock.mockResolvedValueOnce(jsonResponse(entry, { status }));
178
+ }
179
+ else {
180
+ this.fetchMock.mockResolvedValueOnce(new Response('Not found', { status: 404 }));
181
+ }
182
+ return this;
183
+ }
184
+ mockListContent(items, status = 200) {
185
+ this.fetchMock.mockResolvedValueOnce(jsonResponse({ items }, { status }));
186
+ return this;
187
+ }
188
+ mockCreateContent(result, status = 200) {
189
+ this.fetchMock.mockResolvedValueOnce(jsonResponse({
190
+ ...result,
191
+ created: result.created?.toISOString(),
192
+ }, { status }));
193
+ return this;
194
+ }
195
+ mockUpdateContent(result, status = 200) {
196
+ this.fetchMock.mockResolvedValueOnce(jsonResponse({
197
+ ...result,
198
+ modified: result.modified?.toISOString(),
199
+ }, { status }));
200
+ return this;
201
+ }
202
+ mockDeleteContent(result, status = 200) {
203
+ this.fetchMock.mockResolvedValueOnce(jsonResponse(result, { status }));
204
+ return this;
205
+ }
206
+ mockStaleWrite(currentEtag) {
207
+ this.fetchMock.mockResolvedValueOnce(jsonResponse({
208
+ error: {
209
+ code: 'STALE_WRITE',
210
+ message: 'Content has been modified',
211
+ details: { currentEtag },
212
+ },
213
+ }, { status: 412 }));
214
+ return this;
215
+ }
216
+ mockError(message, status = 500) {
217
+ this.fetchMock.mockResolvedValueOnce(new Response(message, { status }));
218
+ return this;
219
+ }
220
+ mockNetworkError() {
221
+ this.fetchMock.mockRejectedValueOnce(new Error('Network error'));
222
+ return this;
223
+ }
224
+ }
225
+ /**
226
+ * Setup fetch mock with helper
227
+ * @param mockFn - Mock function from your test framework (e.g., mock from bun:test)
228
+ */
229
+ export function setupFetchMock(mockFn) {
230
+ const fetchMock = createMockFetch(mockFn);
231
+ global.fetch = fetchMock;
232
+ return {
233
+ fetchMock,
234
+ responses: new MockAPIResponses(fetchMock),
235
+ };
236
+ }
@@ -1,2 +1,2 @@
1
- import { a as jsonResponse, c as mockContentManifest, d as mockLocalizedEntry, f as mockUpdateResult, i as createMockFetch, l as mockCreateResult, n as MockAPIResponses, o as mockBatchResult, p as setupFetchMock, r as MockResponse, s as mockContentEntry, t as API_ROUTES, u as mockDeleteResult } from "./test-helpers-BJxZXOMi.mjs";
1
+ import { a as jsonResponse, c as mockContentManifest, d as mockLocalizedEntry, f as mockUpdateResult, i as createMockFetch, l as mockCreateResult, n as MockAPIResponses, o as mockBatchResult, p as setupFetchMock, r as MockResponse, s as mockContentEntry, t as API_ROUTES, u as mockDeleteResult } from "./test-helpers-B_YQhpE2.mjs";
2
2
  export { API_ROUTES, MockAPIResponses, MockResponse, createMockFetch, jsonResponse, mockBatchResult, mockContentEntry, mockContentManifest, mockCreateResult, mockDeleteResult, mockLocalizedEntry, mockUpdateResult, setupFetchMock };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Test helpers for @conloca/content-api-client
3
+ *
4
+ * Import from '@conloca/content-api-client/testing' to use these helpers in tests.
5
+ * This keeps test utilities separate from production code for better tree-shaking.
6
+ */
7
+ export * from './test-helpers';
8
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Test helpers for @conloca/content-api-client
3
+ *
4
+ * Import from '@conloca/content-api-client/testing' to use these helpers in tests.
5
+ * This keeps test utilities separate from production code for better tree-shaking.
6
+ */
7
+ export * from './test-helpers';
package/dist/testing.mjs CHANGED
@@ -1,3 +1,2 @@
1
- import { a as mockBatchResult, c as mockCreateResult, d as mockUpdateResult, f as setupFetchMock, i as jsonResponse, l as mockDeleteResult, n as MockAPIResponses, o as mockContentEntry, r as createMockFetch, s as mockContentManifest, t as API_ROUTES, u as mockLocalizedEntry } from "./test-helpers-CRvDHjs2.mjs";
2
-
3
- export { API_ROUTES, MockAPIResponses, createMockFetch, jsonResponse, mockBatchResult, mockContentEntry, mockContentManifest, mockCreateResult, mockDeleteResult, mockLocalizedEntry, mockUpdateResult, setupFetchMock };
1
+ import { a as mockBatchResult, c as mockCreateResult, d as mockUpdateResult, f as setupFetchMock, i as jsonResponse, l as mockDeleteResult, n as MockAPIResponses, o as mockContentEntry, r as createMockFetch, s as mockContentManifest, t as API_ROUTES, u as mockLocalizedEntry } from "./test-helpers-BFyjmKzv.mjs";
2
+ export { API_ROUTES, MockAPIResponses, createMockFetch, jsonResponse, mockBatchResult, mockContentEntry, mockContentManifest, mockCreateResult, mockDeleteResult, mockLocalizedEntry, mockUpdateResult, setupFetchMock };
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
1
  {
2
2
  "name": "@conloca/content-api-client",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/conloca/conloca.git",
10
- "directory": "content-api-client"
10
+ "directory": "packages/content-api-client"
11
11
  },
12
12
  "type": "module",
13
13
  "main": "./dist/index.mjs",
14
14
  "module": "./dist/index.mjs",
15
- "types": "./dist/index.d.ts",
15
+ "types": "./dist/index.d.mts",
16
16
  "exports": {
17
17
  "./package.json": "./package.json",
18
18
  ".": {
19
- "types": "./dist/index.d.ts",
19
+ "types": "./dist/index.d.mts",
20
20
  "import": "./dist/index.mjs",
21
21
  "default": "./dist/index.mjs"
22
22
  },
23
23
  "./testing": {
24
- "types": "./dist/testing.d.ts",
24
+ "types": "./dist/testing.d.mts",
25
25
  "import": "./dist/testing.mjs",
26
26
  "default": "./dist/testing.mjs"
27
27
  }
@@ -32,22 +32,67 @@
32
32
  "!dist/test"
33
33
  ],
34
34
  "scripts": {
35
- "build": "tsdown",
36
- "test": "tsc-bun-test"
35
+ "test": "nx run content-api-client:test --outputStyle=stream"
37
36
  },
38
37
  "dependencies": {
39
- "@conloca/content-api": "^0.1.15",
40
- "@tanstack/react-query": "^5.90.21",
38
+ "@conloca/content-api": "0.1.16",
39
+ "@tanstack/react-query": "^5.100.6",
41
40
  "tslib": "^2.8.1"
42
41
  },
43
42
  "peerDependencies": {
44
- "react": "^19.0.0",
45
- "react-dom": "^19.0.0"
43
+ "react": "^19.2.5",
44
+ "react-dom": "^19.2.5"
46
45
  },
47
46
  "devDependencies": {
48
47
  "@happy-dom/global-registrator": "20.6.1",
49
48
  "@testing-library/jest-dom": "^6.9.1",
50
49
  "@testing-library/react": "^16.3.2",
51
50
  "@types/react": "19.2.14"
52
- }
51
+ },
52
+ "nx": {
53
+ "targets": {
54
+ "clean": {},
55
+ "lint": {},
56
+ "tsdown-js": {
57
+ "executor": "nx:run-commands",
58
+ "cache": true,
59
+ "dependsOn": [
60
+ "^build"
61
+ ],
62
+ "inputs": [
63
+ "{projectRoot}/src/**/*",
64
+ "{projectRoot}/tsdown.config.ts",
65
+ "{projectRoot}/tsconfig.lib.json",
66
+ "{projectRoot}/package.json"
67
+ ],
68
+ "outputs": [
69
+ "{projectRoot}/dist/**/*.mjs",
70
+ "{projectRoot}/dist/**/*.js",
71
+ "{projectRoot}/dist/**/*.d.mts"
72
+ ],
73
+ "options": {
74
+ "command": "tsdown",
75
+ "cwd": "{projectRoot}"
76
+ }
77
+ },
78
+ "test": {
79
+ "executor": "@smoothbricks/nx-plugin:bounded-exec",
80
+ "dependsOn": [
81
+ "typecheck-tests",
82
+ "^build"
83
+ ],
84
+ "options": {
85
+ "command": "bun test --timeout=30000",
86
+ "cwd": "{projectRoot}",
87
+ "timeoutMs": 120000,
88
+ "killAfterMs": 1e4
89
+ }
90
+ }
91
+ },
92
+ "tags": [
93
+ "npm:public"
94
+ ],
95
+ "name": "content-api-client"
96
+ },
97
+ "license": "FSL-1.1-ALv2"
53
98
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-helpers-BJxZXOMi.d.mts","names":[],"sources":["../src/test-helpers.ts"],"mappings":";;;;;AAkBA;;;;;cAAa,UAAA;EAAA;;;2CAImB,MAAA;EAAA;;;;;;;UASf,YAAA;EACf,MAAA;EACA,OAAA,GAAU,MAAA;EACV,IAAA;AAAA;;;;;iBAOc,eAAA,CAAgB,MAAA,GAAS,IAAA;;;;iBAOzB,YAAA,CAAa,IAAA,OAAW,OAAA;EAAW,MAAA;EAAiB,OAAA,GAAU,MAAA;AAAA,IAAgC,QAAA;;;AAA9G;iBAagB,gBAAA,CAAiB,SAAA,GAAY,OAAA,CAAQ,YAAA,IAAgB,YAAA;;;;iBA2BrD,mBAAA,CAAoB,SAAA,GAAY,OAAA,CAAQ,eAAA,IAAmB,eAAA;;;;iBA0B3D,kBAAA,CAAmB,SAAA,GAAY,OAAA,CAAQ,cAAA,IAAkB,cAAA;;;AArDzE;iBA8EgB,gBAAA,CAAiB,SAAA,GAAY,OAAA,CAAQ,YAAA,IAAgB,YAAA;;;;iBAarD,gBAAA,CAAiB,SAAA,GAAY,OAAA,CAAQ,YAAA,IAAgB,YAAA;;;;iBAYrD,gBAAA,CAAiB,SAAA,GAAY,OAAA,CAAQ,YAAA,IAAgB,YAAA;;;;iBAUrD,eAAA,CAAgB,SAAA,GAAY,OAAA,CAAQ,WAAA,IAAe,WAAA;AAtFnE;;;AAAA,cAmGa,gBAAA;EAAA,QACS,SAAA;cAAA,SAAA;EAEpB,cAAA,CAAe,OAAA,EAAS,YAAA,SAAqB,MAAA;EAS7C,gBAAA,CAAiB,KAAA,EAAO,cAAA,SAAuB,MAAA;EAS/C,eAAA,CAAgB,KAAA,EAAO,eAAA,IAAmB,MAAA;EAK1C,iBAAA,CAAkB,MAAA,EAAQ,YAAA,EAAc,MAAA;EAaxC,iBAAA,CAAkB,MAAA,EAAQ,YAAA,EAAc,MAAA;EAaxC,iBAAA,CAAkB,MAAA,EAAQ,YAAA,EAAc,MAAA;EAKxC,cAAA,CAAe,WAAA;EAgBf,SAAA,CAAU,OAAA,UAAiB,MAAA;EAK3B,gBAAA,CAAA;AAAA;;;;;iBAUc,cAAA,CAAe,MAAA,GAAS,IAAA;;aAAV,gBAAA;AAAA"}