@flink-app/contentone-plugin 0.12.1-alpha.4 → 0.12.1-alpha.40
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 +4 -4
- package/readme.md +392 -138
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flink-app/contentone-plugin",
|
|
3
|
-
"version": "0.12.1-alpha.
|
|
3
|
+
"version": "0.12.1-alpha.40",
|
|
4
4
|
"description": "Flink plugin that enables easy to use communication with content one",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\"",
|
|
7
|
-
"
|
|
7
|
+
"prepare": "tsc"
|
|
8
8
|
},
|
|
9
9
|
"author": "johan@frost.se",
|
|
10
10
|
"publishConfig": {
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"got": "^9.6.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@flink-app/flink": "^0.12.1-alpha.
|
|
21
|
+
"@flink-app/flink": "^0.12.1-alpha.40",
|
|
22
22
|
"@types/got": "^9.6.0",
|
|
23
23
|
"@types/node": "22.13.10",
|
|
24
24
|
"ts-node": "^9.1.1",
|
|
25
25
|
"typescript": "5.4.5"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "456502f273fe9473df05b71a803f3eda1a2f8931"
|
|
28
28
|
}
|
package/readme.md
CHANGED
|
@@ -1,244 +1,498 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @flink-app/contentone-plugin
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A Flink plugin for integrating with Content One CMS (Aquro). This plugin provides a simple and type-safe way to consume content from Content One collections, execute management actions, and upload files to the Content One CDN.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- Retrieve documents from Content One collections
|
|
8
|
+
- List and query collection documents with filtering and pagination
|
|
9
|
+
- Execute Content One management actions
|
|
10
|
+
- Upload files to Content One CDN with image processing options
|
|
11
|
+
- Support for multiple collections and CDN configurations
|
|
12
|
+
- Environment switching (Production/Staging)
|
|
13
|
+
- Document relation resolution
|
|
14
|
+
- Language-specific content retrieval
|
|
15
|
+
- Full TypeScript support with generic types
|
|
16
|
+
- Direct API calls without pre-configuration
|
|
8
17
|
|
|
9
|
-
|
|
18
|
+
## Installation
|
|
10
19
|
|
|
11
|
-
```
|
|
12
|
-
npm
|
|
20
|
+
```bash
|
|
21
|
+
npm install @flink-app/contentone-plugin
|
|
13
22
|
```
|
|
14
23
|
|
|
15
|
-
|
|
24
|
+
## Usage
|
|
16
25
|
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
### Basic Setup
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { FlinkApp } from "@flink-app/flink";
|
|
30
|
+
import {
|
|
31
|
+
contentOnePlugin,
|
|
32
|
+
ContentOneClient,
|
|
33
|
+
ContentOneManagementAction,
|
|
34
|
+
ContentOneCDN,
|
|
35
|
+
} from "@flink-app/contentone-plugin";
|
|
19
36
|
|
|
20
37
|
function start() {
|
|
21
38
|
new FlinkApp<AppContext>({
|
|
22
39
|
name: "My app",
|
|
23
40
|
plugins: [
|
|
24
|
-
// Register plugin
|
|
25
41
|
contentOnePlugin({
|
|
26
|
-
collections
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
42
|
+
collections: {
|
|
43
|
+
NewsItems: new ContentOneClient({
|
|
44
|
+
collection: "collection_id_here",
|
|
45
|
+
token: "your_token_here",
|
|
46
|
+
}),
|
|
47
|
+
Products: new ContentOneClient({
|
|
48
|
+
collection: "another_collection_id",
|
|
49
|
+
token: "your_token_here",
|
|
30
50
|
}),
|
|
31
|
-
"Collection2" : new ContentOneClient({
|
|
32
|
-
collection : "collectionid",
|
|
33
|
-
token : "token.."
|
|
34
|
-
})
|
|
35
51
|
},
|
|
36
|
-
actions
|
|
37
|
-
|
|
38
|
-
actionId
|
|
39
|
-
apiKey
|
|
40
|
-
})
|
|
52
|
+
actions: {
|
|
53
|
+
SendEmail: new ContentOneManagementAction({
|
|
54
|
+
actionId: "send_email_action_id",
|
|
55
|
+
apiKey: "your_api_key_here",
|
|
56
|
+
}),
|
|
41
57
|
},
|
|
42
|
-
cdns
|
|
43
|
-
|
|
44
|
-
token
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
58
|
+
cdns: {
|
|
59
|
+
photos: new ContentOneCDN({
|
|
60
|
+
token: "file_archive_token",
|
|
61
|
+
}),
|
|
62
|
+
},
|
|
63
|
+
baseUrl: "https://cdb.aquro.com", // optional
|
|
64
|
+
managementBaseUrl: "https://api-cm.aquro.com", // optional
|
|
65
|
+
}),
|
|
49
66
|
],
|
|
50
67
|
}).start();
|
|
51
68
|
}
|
|
52
|
-
|
|
53
69
|
```
|
|
54
70
|
|
|
55
|
-
|
|
71
|
+
### Add Plugin Context to Your Application
|
|
56
72
|
|
|
57
|
-
```
|
|
73
|
+
```typescript
|
|
58
74
|
import { contentOnePluginContext } from "@flink-app/contentone-plugin";
|
|
59
75
|
|
|
60
|
-
export interface
|
|
61
|
-
repos: {
|
|
76
|
+
export interface AppContext extends FlinkContext<contentOnePluginContext> {
|
|
77
|
+
repos: {
|
|
78
|
+
// your repos
|
|
79
|
+
};
|
|
62
80
|
}
|
|
63
|
-
|
|
64
81
|
```
|
|
65
82
|
|
|
66
|
-
##
|
|
83
|
+
## Configuration Options
|
|
67
84
|
|
|
68
|
-
|
|
85
|
+
- `collections` (optional): Object mapping collection names to `ContentOneClient` instances
|
|
86
|
+
- `actions` (optional): Object mapping action names to `ContentOneManagementAction` instances
|
|
87
|
+
- `cdns` (optional): Object mapping CDN names to `ContentOneCDN` instances
|
|
88
|
+
- `baseUrl` (optional): Content One API base URL (defaults to `https://cdb.aquro.com`)
|
|
89
|
+
- `managementBaseUrl` (optional): Content One Management API base URL (defaults to `https://api-cm.aquro.com`)
|
|
69
90
|
|
|
70
|
-
|
|
91
|
+
## Working with Collections
|
|
71
92
|
|
|
72
|
-
|
|
73
|
-
const document = (await ctx.plugins.contentOne.collections.NewsItems.get("documentid")).document
|
|
74
|
-
```
|
|
93
|
+
### Get a Single Document
|
|
75
94
|
|
|
76
|
-
|
|
95
|
+
```typescript
|
|
96
|
+
const document = (await ctx.plugins.contentOne.collections.NewsItems.get("document_id")).document;
|
|
97
|
+
```
|
|
77
98
|
|
|
78
|
-
|
|
79
|
-
| ----------- | ------------------------------------------------- | ---------------------------------- |
|
|
80
|
-
| language | Language code (ISO 639-1) to get the documents in |
|
|
81
|
-
| environment | "Production" | "Staging", |
|
|
82
|
-
| resolve | "yes" | "no" - Resolving related documents |
|
|
99
|
+
With options:
|
|
83
100
|
|
|
84
|
-
```
|
|
85
|
-
const document
|
|
101
|
+
```typescript
|
|
102
|
+
const document = (
|
|
103
|
+
await ctx.plugins.contentOne.collections.NewsItems.get("document_id", {
|
|
104
|
+
language: "en",
|
|
105
|
+
environment: "Production",
|
|
106
|
+
resolve: "yes",
|
|
107
|
+
})
|
|
108
|
+
).document;
|
|
86
109
|
```
|
|
87
110
|
|
|
88
|
-
###
|
|
111
|
+
### List Documents
|
|
89
112
|
|
|
113
|
+
```typescript
|
|
114
|
+
const documents = (await ctx.plugins.contentOne.collections.NewsItems.list()).documents;
|
|
90
115
|
```
|
|
91
|
-
|
|
116
|
+
|
|
117
|
+
With pagination and sorting:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
const documents = (
|
|
121
|
+
await ctx.plugins.contentOne.collections.NewsItems.list({
|
|
122
|
+
skip: 0,
|
|
123
|
+
limit: 50,
|
|
124
|
+
sort: "createdDate",
|
|
125
|
+
sort_direction: "desc",
|
|
126
|
+
language: "en",
|
|
127
|
+
environment: "Production",
|
|
128
|
+
resolve: "yes",
|
|
129
|
+
})
|
|
130
|
+
).documents;
|
|
92
131
|
```
|
|
93
132
|
|
|
94
|
-
|
|
133
|
+
### Query Documents
|
|
95
134
|
|
|
96
|
-
|
|
97
|
-
| -------------- | ------------------------------------------------- | ---------------------------------- |
|
|
98
|
-
| language | Language code (ISO 639-1) to get the documents in |
|
|
99
|
-
| environment | "Production" | "Staging", |
|
|
100
|
-
| resolve | "yes" | "no" - Resolving related documents |
|
|
101
|
-
| skip | Skip a number of documents, defaults to 0 |
|
|
102
|
-
| limit | Maximum of documents returned, defaults to 10 000 |
|
|
103
|
-
| sort | Field to sort the documents by |
|
|
104
|
-
| sort_direction | "asc" | "desc" |
|
|
135
|
+
Execute a named query with arguments:
|
|
105
136
|
|
|
106
|
-
```
|
|
107
|
-
const
|
|
137
|
+
```typescript
|
|
138
|
+
const documents = (
|
|
139
|
+
await ctx.plugins.contentOne.collections.NewsItems.query("GetNewsByCategory", {
|
|
140
|
+
category: "Technology",
|
|
141
|
+
})
|
|
142
|
+
).documents;
|
|
108
143
|
```
|
|
109
144
|
|
|
110
|
-
|
|
145
|
+
With options:
|
|
111
146
|
|
|
112
|
-
```
|
|
113
|
-
const documents
|
|
147
|
+
```typescript
|
|
148
|
+
const documents = (
|
|
149
|
+
await ctx.plugins.contentOne.collections.NewsItems.query(
|
|
150
|
+
"GetNewsByCategory",
|
|
151
|
+
{
|
|
152
|
+
category: "Technology",
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
limit: 20,
|
|
156
|
+
sort: "publishDate",
|
|
157
|
+
sort_direction: "desc",
|
|
158
|
+
}
|
|
159
|
+
)
|
|
160
|
+
).documents;
|
|
114
161
|
```
|
|
115
162
|
|
|
116
|
-
|
|
163
|
+
## Request Options
|
|
117
164
|
|
|
118
|
-
|
|
119
|
-
| -------------- | ------------------------------------------------- | ---------------------------------- |
|
|
120
|
-
| language | Language code (ISO 639-1) to get the documents in |
|
|
121
|
-
| environment | "Production" | "Staging", |
|
|
122
|
-
| resolve | "yes" | "no" - Resolving related documents |
|
|
123
|
-
| skip | Skip a number of documents, defaults to 0 |
|
|
124
|
-
| limit | Maximum of documents returned, defaults to 10 000 |
|
|
125
|
-
| sort | Field to sort the documents by |
|
|
126
|
-
| sort_direction | "asc" | "desc" |
|
|
165
|
+
### Common Options
|
|
127
166
|
|
|
128
|
-
|
|
129
|
-
const documents = (await ctx.plugins.contentOne.collections.NewsItems.query("QueryName", { Arg : "Hello" }, { limit : 1000 })).documents
|
|
130
|
-
```
|
|
167
|
+
Available for `get`, `list`, and `query`:
|
|
131
168
|
|
|
132
|
-
|
|
169
|
+
- `language` (string): Language code (ISO 639-1) to retrieve documents in (e.g., "en", "sv")
|
|
170
|
+
- `environment` ("Production" | "Staging"): Which environment to fetch from
|
|
171
|
+
- `resolve` ("yes" | "no"): Whether to resolve related documents
|
|
133
172
|
|
|
134
|
-
|
|
173
|
+
### List and Query Options
|
|
135
174
|
|
|
136
|
-
|
|
137
|
-
const resp = ctx.plugins.contentOne.actions.ActionName.execute({ Arg : "Hello" });
|
|
138
|
-
```
|
|
175
|
+
Additional options for `list` and `query`:
|
|
139
176
|
|
|
140
|
-
|
|
177
|
+
- `skip` (number): Number of documents to skip (default: 0)
|
|
178
|
+
- `limit` (number): Maximum documents to return (default: 10,000)
|
|
179
|
+
- `sort` (string): Field name to sort by
|
|
180
|
+
- `sort_direction` ("asc" | "desc"): Sort direction
|
|
141
181
|
|
|
142
|
-
|
|
182
|
+
## TypeScript Type Safety
|
|
143
183
|
|
|
144
|
-
|
|
184
|
+
Use generic types to get typed document responses:
|
|
145
185
|
|
|
146
|
-
```
|
|
147
|
-
|
|
186
|
+
```typescript
|
|
187
|
+
interface NewsItem {
|
|
188
|
+
_id: string;
|
|
189
|
+
title: string;
|
|
190
|
+
content: string;
|
|
191
|
+
publishDate: string;
|
|
192
|
+
category: string;
|
|
193
|
+
}
|
|
148
194
|
|
|
195
|
+
// Single document
|
|
196
|
+
const document = (
|
|
197
|
+
await ctx.plugins.contentOne.collections.NewsItems.get<NewsItem>("document_id")
|
|
198
|
+
).document;
|
|
199
|
+
// document is typed as NewsItem
|
|
200
|
+
|
|
201
|
+
// Multiple documents
|
|
202
|
+
const documents = (
|
|
203
|
+
await ctx.plugins.contentOne.collections.NewsItems.list<NewsItem>()
|
|
204
|
+
).documents;
|
|
205
|
+
// documents is typed as NewsItem[]
|
|
149
206
|
```
|
|
150
207
|
|
|
151
|
-
|
|
208
|
+
## Management Actions
|
|
152
209
|
|
|
153
|
-
|
|
210
|
+
### Execute Pre-configured Actions
|
|
154
211
|
|
|
155
|
-
|
|
212
|
+
```typescript
|
|
213
|
+
const response = await ctx.plugins.contentOne.actions.SendEmail.execute({
|
|
214
|
+
to: "user@example.com",
|
|
215
|
+
subject: "Hello",
|
|
216
|
+
body: "Welcome to our service",
|
|
217
|
+
});
|
|
156
218
|
|
|
157
|
-
|
|
219
|
+
if (response.status === "success") {
|
|
220
|
+
console.log("Email sent:", response.data);
|
|
221
|
+
}
|
|
222
|
+
```
|
|
158
223
|
|
|
159
|
-
|
|
224
|
+
### Execute Actions Directly
|
|
160
225
|
|
|
161
|
-
|
|
226
|
+
Without pre-configuration:
|
|
162
227
|
|
|
163
|
-
|
|
228
|
+
```typescript
|
|
229
|
+
const response = await ctx.plugins.contentOne.management.action(
|
|
230
|
+
"action_id",
|
|
231
|
+
"api_key",
|
|
232
|
+
{
|
|
233
|
+
arg1: "value1",
|
|
234
|
+
arg2: "value2",
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
```
|
|
164
238
|
|
|
165
|
-
|
|
239
|
+
### Typed Action Responses
|
|
166
240
|
|
|
167
|
-
|
|
241
|
+
```typescript
|
|
242
|
+
interface EmailResponse {
|
|
243
|
+
messageId: string;
|
|
244
|
+
status: string;
|
|
245
|
+
}
|
|
168
246
|
|
|
169
|
-
|
|
247
|
+
const response = await ctx.plugins.contentOne.actions.SendEmail.execute<EmailResponse>({
|
|
248
|
+
to: "user@example.com",
|
|
249
|
+
subject: "Hello",
|
|
250
|
+
});
|
|
170
251
|
|
|
171
|
-
|
|
252
|
+
if (response.status === "success") {
|
|
253
|
+
console.log("Message ID:", response.data.messageId);
|
|
254
|
+
}
|
|
255
|
+
```
|
|
172
256
|
|
|
173
|
-
|
|
257
|
+
## File Upload (CDN)
|
|
174
258
|
|
|
175
|
-
|
|
259
|
+
### Upload Files with Pre-configured CDN
|
|
176
260
|
|
|
177
|
-
|
|
261
|
+
```typescript
|
|
262
|
+
const result = await ctx.plugins.contentOne.cdns.photos.upload("/tmp/photo.jpg", {
|
|
263
|
+
image_rotate: "auto",
|
|
264
|
+
image_resize_width: 1200,
|
|
265
|
+
image_resize_max: "yes",
|
|
266
|
+
image_thumb: "yes",
|
|
267
|
+
image_thumb_width: 200,
|
|
268
|
+
image_thumb_height: 200,
|
|
269
|
+
});
|
|
178
270
|
|
|
179
|
-
|
|
271
|
+
if (result.status === "success") {
|
|
272
|
+
console.log("File URL:", result.file.Url);
|
|
273
|
+
console.log("Thumbnail URL:", result.file.Thumbnail);
|
|
274
|
+
}
|
|
275
|
+
```
|
|
180
276
|
|
|
181
|
-
|
|
277
|
+
### Upload Files Directly
|
|
182
278
|
|
|
183
|
-
|
|
279
|
+
Without pre-configuration:
|
|
184
280
|
|
|
185
|
-
|
|
281
|
+
```typescript
|
|
282
|
+
const result = await ctx.plugins.contentOne.cdnClient.upload("/tmp/photo.jpg", "file_archive_token", {
|
|
283
|
+
image_rotate: "auto",
|
|
284
|
+
image_resize_width: 1200,
|
|
285
|
+
});
|
|
286
|
+
```
|
|
186
287
|
|
|
187
|
-
|
|
288
|
+
### Upload Options
|
|
188
289
|
|
|
189
|
-
|
|
290
|
+
- `folderId` (string): Folder to save the file to
|
|
291
|
+
- `image_rotate` ("90" | "180" | "270" | "auto"): Rotate image (auto uses EXIF data)
|
|
292
|
+
- `image_resize_width` (number): Resize to specific width
|
|
293
|
+
- `image_resize_height` (number): Resize to specific height
|
|
294
|
+
- `image_resize_max` ("yes" | "no"): Keep aspect ratio, fit within dimensions
|
|
295
|
+
- `image_resize_crop` ("center" | "attention"): Crop strategy for exact dimensions
|
|
296
|
+
- `image_thumb` ("yes" | "no"): Generate thumbnail
|
|
297
|
+
- `image_thumb_width` (number): Thumbnail width
|
|
298
|
+
- `image_thumb_height` (number): Thumbnail height
|
|
190
299
|
|
|
191
|
-
|
|
300
|
+
### Upload Response
|
|
192
301
|
|
|
193
|
-
```
|
|
302
|
+
```typescript
|
|
194
303
|
{
|
|
195
|
-
status:
|
|
304
|
+
status: "success" | "fail",
|
|
196
305
|
file: {
|
|
197
|
-
_id:
|
|
198
|
-
ProjectID:
|
|
199
|
-
Local_FileName:
|
|
200
|
-
CDN_FileName:
|
|
201
|
-
Url:
|
|
202
|
-
Type:
|
|
203
|
-
Size:
|
|
204
|
-
CreatedDate:
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
306
|
+
_id: string;
|
|
307
|
+
ProjectID: string;
|
|
308
|
+
Local_FileName: string;
|
|
309
|
+
CDN_FileName: string;
|
|
310
|
+
Url: string;
|
|
311
|
+
Type: string;
|
|
312
|
+
Size: number;
|
|
313
|
+
CreatedDate: string;
|
|
314
|
+
FolderID: string;
|
|
315
|
+
Thumbnail?: string;
|
|
316
|
+
ThumbnailCDN_Filename?: string;
|
|
208
317
|
}
|
|
209
318
|
}
|
|
210
319
|
```
|
|
211
320
|
|
|
212
|
-
## Direct
|
|
321
|
+
## Direct API Calls
|
|
213
322
|
|
|
214
|
-
|
|
323
|
+
The plugin supports direct API calls without pre-configuration:
|
|
215
324
|
|
|
325
|
+
### Direct Collection Access
|
|
326
|
+
|
|
327
|
+
```typescript
|
|
328
|
+
const document = (
|
|
329
|
+
await ctx.plugins.contentOne.getClient({
|
|
330
|
+
token: "token",
|
|
331
|
+
collection: "collection_id",
|
|
332
|
+
}).get("document_id")
|
|
333
|
+
).document;
|
|
216
334
|
```
|
|
217
|
-
const document = (await ctx.plugins.contentOne.getClient({ token : "token", "collection" : "collectionid"}).get("documentid")).document
|
|
218
|
-
```
|
|
219
335
|
|
|
220
|
-
|
|
336
|
+
### Direct Action Execution
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
const response = await ctx.plugins.contentOne.management.action(
|
|
340
|
+
"action_id",
|
|
341
|
+
"api_key",
|
|
342
|
+
{
|
|
343
|
+
argument: "value",
|
|
344
|
+
}
|
|
345
|
+
);
|
|
346
|
+
```
|
|
221
347
|
|
|
222
|
-
Direct
|
|
348
|
+
### Direct CDN Upload
|
|
223
349
|
|
|
350
|
+
```typescript
|
|
351
|
+
const result = await ctx.plugins.contentOne.cdnClient.upload(
|
|
352
|
+
"./file.txt",
|
|
353
|
+
"token",
|
|
354
|
+
{}
|
|
355
|
+
);
|
|
224
356
|
```
|
|
225
|
-
|
|
357
|
+
|
|
358
|
+
## Complete Example
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
import { FlinkApp } from "@flink-app/flink";
|
|
362
|
+
import {
|
|
363
|
+
contentOnePlugin,
|
|
364
|
+
ContentOneClient,
|
|
365
|
+
ContentOneManagementAction,
|
|
366
|
+
ContentOneCDN,
|
|
367
|
+
} from "@flink-app/contentone-plugin";
|
|
368
|
+
|
|
369
|
+
interface Article {
|
|
370
|
+
_id: string;
|
|
371
|
+
title: string;
|
|
372
|
+
content: string;
|
|
373
|
+
author: string;
|
|
374
|
+
publishedAt: string;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const plugin = contentOnePlugin({
|
|
378
|
+
collections: {
|
|
379
|
+
Articles: new ContentOneClient({
|
|
380
|
+
collection: "articles_collection_id",
|
|
381
|
+
token: process.env.CONTENTONE_TOKEN!,
|
|
382
|
+
debug: true, // Enable logging
|
|
383
|
+
}),
|
|
384
|
+
},
|
|
385
|
+
actions: {
|
|
386
|
+
PublishArticle: new ContentOneManagementAction({
|
|
387
|
+
actionId: "publish_article",
|
|
388
|
+
apiKey: process.env.CONTENTONE_API_KEY!,
|
|
389
|
+
}),
|
|
390
|
+
},
|
|
391
|
+
cdns: {
|
|
392
|
+
images: new ContentOneCDN({
|
|
393
|
+
token: process.env.CONTENTONE_CDN_TOKEN!,
|
|
394
|
+
}),
|
|
395
|
+
},
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
// Later in your handler or job:
|
|
399
|
+
async function publishArticle(ctx: AppContext, articleId: string) {
|
|
400
|
+
// Get the article
|
|
401
|
+
const article = (
|
|
402
|
+
await ctx.plugins.contentOne.collections.Articles.get<Article>(articleId, {
|
|
403
|
+
language: "en",
|
|
404
|
+
environment: "Production",
|
|
405
|
+
})
|
|
406
|
+
).document;
|
|
407
|
+
|
|
408
|
+
// Execute publish action
|
|
409
|
+
const result = await ctx.plugins.contentOne.actions.PublishArticle.execute({
|
|
410
|
+
articleId: article._id,
|
|
411
|
+
publishDate: new Date().toISOString(),
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
return result;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
async function uploadArticleImage(ctx: AppContext, imagePath: string) {
|
|
418
|
+
const upload = await ctx.plugins.contentOne.cdns.images.upload(imagePath, {
|
|
419
|
+
image_rotate: "auto",
|
|
420
|
+
image_resize_width: 1200,
|
|
421
|
+
image_resize_max: "yes",
|
|
422
|
+
image_thumb: "yes",
|
|
423
|
+
image_thumb_width: 300,
|
|
424
|
+
image_thumb_height: 200,
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
if (upload.status === "success") {
|
|
428
|
+
return {
|
|
429
|
+
imageUrl: upload.file.Url,
|
|
430
|
+
thumbnailUrl: upload.file.Thumbnail,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
throw new Error("Upload failed");
|
|
435
|
+
}
|
|
226
436
|
```
|
|
227
437
|
|
|
228
|
-
##
|
|
438
|
+
## Error Handling
|
|
229
439
|
|
|
230
|
-
|
|
440
|
+
Always wrap API calls in try-catch blocks:
|
|
231
441
|
|
|
442
|
+
```typescript
|
|
443
|
+
try {
|
|
444
|
+
const document = (
|
|
445
|
+
await ctx.plugins.contentOne.collections.NewsItems.get("document_id")
|
|
446
|
+
).document;
|
|
447
|
+
} catch (error) {
|
|
448
|
+
console.error("Failed to fetch document:", error);
|
|
449
|
+
// Handle error appropriately
|
|
450
|
+
}
|
|
232
451
|
```
|
|
233
|
-
|
|
452
|
+
|
|
453
|
+
## Debug Mode
|
|
454
|
+
|
|
455
|
+
Enable debug mode for a collection to log all API requests and responses:
|
|
456
|
+
|
|
457
|
+
```typescript
|
|
458
|
+
new ContentOneClient({
|
|
459
|
+
collection: "collection_id",
|
|
460
|
+
token: "token",
|
|
461
|
+
debug: true, // Logs all requests and responses
|
|
462
|
+
});
|
|
234
463
|
```
|
|
235
464
|
|
|
236
|
-
##
|
|
465
|
+
## API Response Types
|
|
237
466
|
|
|
238
|
-
|
|
467
|
+
### Document Response
|
|
239
468
|
|
|
469
|
+
```typescript
|
|
470
|
+
{
|
|
471
|
+
status: "success" | "error",
|
|
472
|
+
document: T,
|
|
473
|
+
message?: string
|
|
474
|
+
}
|
|
240
475
|
```
|
|
241
|
-
const document = (await ctx.plugins.contentOne.collections.NewsItems.get<Type>("documentid")).document
|
|
242
476
|
|
|
477
|
+
### Document List Response
|
|
243
478
|
|
|
479
|
+
```typescript
|
|
480
|
+
{
|
|
481
|
+
status: "success" | "error",
|
|
482
|
+
documents: T[],
|
|
483
|
+
message?: string
|
|
484
|
+
}
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
### Action Response
|
|
488
|
+
|
|
489
|
+
```typescript
|
|
490
|
+
{
|
|
491
|
+
status: "success" | "error",
|
|
492
|
+
data: T
|
|
493
|
+
}
|
|
244
494
|
```
|
|
495
|
+
|
|
496
|
+
## License
|
|
497
|
+
|
|
498
|
+
MIT
|