@financial-times/content-curation-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/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # Content Curation API Client
2
+
3
+ A TypeScript client library for interacting with the Content Curation API.
4
+
5
+ ## Features
6
+
7
+ - Fully typed API using Zod schemas for validation
8
+ - Simple promise-based API for fetching and updating homepage and page structures
9
+ - Comprehensive error handling
10
+ - TypeScript-friendly with exported types
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install @financial-times/content-curation-client
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ### Initialize the client
21
+
22
+ ```typescript
23
+ import { ApiClient } from "@financial-times/content-curation-client";
24
+
25
+ const client = new ApiClient({
26
+ baseUrl: "https://content-curation.eu-west-1.edtech-test.ftweb.tech/api",
27
+ apiToken: "your-api-token",
28
+ });
29
+ ```
30
+
31
+ ### Get homepage structure
32
+
33
+ ```typescript
34
+ // Fetch a homepage structure by pageId
35
+ const pageId = "123e4567-e89b-12d3-a456-426614174000";
36
+ const homepage = await client.homepage.getStructure(pageId);
37
+
38
+ // Fetch available homepage structures by homepageListId
39
+ const homepageListId = "123e4567-e89b-12d3-a456-426614174000";
40
+ const structures = await client.homepage.getStructuresByHomepageListId(homepageListId);
41
+
42
+ console.log(homepage.data.properties.title);
43
+ ```
44
+
45
+ ### Get page structure
46
+
47
+ ```typescript
48
+ // Fetch a page structure by pageId
49
+ const pageId = "123e4567-e89b-12d3-a456-426614174999";
50
+ const page = await client.page.getStructure(pageId);
51
+
52
+ console.log(page.data.properties.title);
53
+ ```
54
+
55
+ ### Update homepage structure
56
+
57
+ ```typescript
58
+ import { HomepageDataApi } from "@financial-times/content-curation-client";
59
+
60
+ // Create or update homepage structure
61
+ const homepageStructure: Omit<HomepageDataApi, "type"> = {
62
+ properties: {
63
+ pageId: "58de2dc7-980b-4d51-8e45-9798f0c6b6bf",
64
+ homepageListId: "123e4567-e89b-12d3-a456-426614174000",
65
+ title: "My Updated Homepage",
66
+ },
67
+ children: [
68
+ {
69
+ type: "HomepageSlice",
70
+ properties: {
71
+ heading: {
72
+ text: "Featured Section",
73
+ },
74
+ },
75
+ },
76
+ {
77
+ type: "FlourishGraphic",
78
+ properties: {
79
+ heading: {
80
+ text: "Interactive Chart",
81
+ },
82
+ flourishId: "visualisation-123",
83
+ displayBehaviour: "standalone",
84
+ },
85
+ },
86
+ ],
87
+ };
88
+
89
+ const result = await client.homepage.upsertStructure(pageId, homepageStructure);
90
+ ```
91
+
92
+ ### Update page structure
93
+
94
+ ```typescript
95
+ import { PageStructureInput } from "@financial-times/content-curation-client";
96
+
97
+ // Create or update page structure
98
+ const pageStructure: Omit<PageStructureInput, "type"> = {
99
+ properties: {
100
+ pageId: "123e4567-e89b-12d3-a456-426614174999",
101
+ title: "My Updated Page",
102
+ },
103
+ children: [
104
+ {
105
+ type: "HomepageSlice",
106
+ properties: {
107
+ heading: {
108
+ text: "Featured Section",
109
+ },
110
+ },
111
+ },
112
+ ],
113
+ };
114
+
115
+ const result = await client.page.upsertStructure(pageId, pageStructure);
116
+ ```
117
+
118
+ ### Error handling
119
+
120
+ ```typescript
121
+ import { ApiError } from "@financial-times/content-curation-client";
122
+
123
+ try {
124
+ const homepageStructure = await client.homepage.getStructure("invalid-id");
125
+ } catch (error) {
126
+ if (error instanceof ApiError) {
127
+ console.error(`API Error (${error.status}): ${error.message}`);
128
+
129
+ if (error.errors) {
130
+ console.error("Validation errors:", error.errors);
131
+ }
132
+ } else {
133
+ console.error("Unknown error:", error);
134
+ }
135
+ }
136
+ ```
137
+
138
+ ## Advanced usage
139
+
140
+ ### Custom fetch implementation
141
+
142
+ You can provide your own fetch implementation, which is useful for caching, testing, and adding other custom behavior:
143
+
144
+ ```typescript
145
+ import { ApiClient } from "@financial-times/content-curation-client";
146
+
147
+ const client = new ApiClient({
148
+ baseUrl: "https://your-api-url.com/api",
149
+ apiToken: "your-api-token",
150
+ fetch: customFetchFunction,
151
+ });
152
+ ```
153
+
154
+ ## Types
155
+
156
+ ```typescript
157
+ import {
158
+ HomepageDataApi,
159
+ HomepageStructureApiResponse,
160
+ HomepageSliceApiResponse,
161
+ PageStructureInput,
162
+ PageStructureOutput,
163
+ } from "@financial-times/content-curation-client";
164
+
165
+ // Use types in your code
166
+ const myPageStructureResponse: PageStructureOutput = {
167
+ /* ... */
168
+ };
169
+ ```