@zerodot/postiz 0.0.0-stage → 1.0.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 +661 -0
- package/README.md +64 -2
- package/dist/index.cjs +1174 -0
- package/package.json +46 -3
- package/postiz.svg +1 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1174 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _zerodot_node_sdk = require("@zerodot/node-sdk");
|
|
3
|
+
let zod = require("zod");
|
|
4
|
+
// src/api.ts
|
|
5
|
+
const POSTIZ_CREDENTIAL = "postiz.api";
|
|
6
|
+
/** The API address of Postiz Cloud. A self-hosted server uses `https://your-domain/api/public/v1`. */
|
|
7
|
+
const POSTIZ_API = "https://api.postiz.com/public/v1";
|
|
8
|
+
const API_SUFFIX = "/public/v1";
|
|
9
|
+
const text = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
10
|
+
/**
|
|
11
|
+
* The API address from the credential. An empty value means Postiz Cloud. The address can end with
|
|
12
|
+
* `/public/v1` or not. This adds `/public/v1` when it is not there.
|
|
13
|
+
*/
|
|
14
|
+
function normalizeBaseUrl(raw) {
|
|
15
|
+
const value = text(raw);
|
|
16
|
+
if (!value) return POSTIZ_API;
|
|
17
|
+
let parsed;
|
|
18
|
+
try {
|
|
19
|
+
parsed = new URL(value);
|
|
20
|
+
} catch {
|
|
21
|
+
throw new Error("The Postiz credential \"baseUrl\" is not a valid URL");
|
|
22
|
+
}
|
|
23
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("The Postiz credential \"baseUrl\" must use http or https");
|
|
24
|
+
const path = parsed.pathname.replace(/\/+$/, "");
|
|
25
|
+
const full = path.endsWith(API_SUFFIX) ? path : `${path}${API_SUFFIX}`;
|
|
26
|
+
return `${parsed.origin}${full}`;
|
|
27
|
+
}
|
|
28
|
+
/** The API key and the API address of a Postiz credential. */
|
|
29
|
+
function postizAccess(credential) {
|
|
30
|
+
if (!credential || credential.type !== "postiz.api") throw new Error("The node needs a Postiz credential");
|
|
31
|
+
const apiKey = text(credential.data.apiKey);
|
|
32
|
+
if (!apiKey) throw new Error("The credential has no \"apiKey\"");
|
|
33
|
+
return {
|
|
34
|
+
apiKey,
|
|
35
|
+
baseUrl: normalizeBaseUrl(credential.data.baseUrl)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** An error from Postiz. `status` is the HTTP status code. */
|
|
39
|
+
var PostizError = class extends Error {
|
|
40
|
+
status;
|
|
41
|
+
retryAfter;
|
|
42
|
+
constructor(message, status, retryAfter) {
|
|
43
|
+
super(message);
|
|
44
|
+
this.name = "PostizError";
|
|
45
|
+
this.status = status;
|
|
46
|
+
this.retryAfter = retryAfter;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const HINTS = {
|
|
50
|
+
400: "Postiz did not accept the request. Check the fields",
|
|
51
|
+
401: "Postiz did not accept the API key",
|
|
52
|
+
402: "The plan of this account does not allow this call",
|
|
53
|
+
403: "The API key does not own this resource",
|
|
54
|
+
404: "Postiz did not find the endpoint or the item",
|
|
55
|
+
413: "The request is too large. Upload the media first and use its path",
|
|
56
|
+
429: "The Postiz rate limit is reached. Try again later",
|
|
57
|
+
500: "Postiz had a server error. Try again later"
|
|
58
|
+
};
|
|
59
|
+
function detailOf(answer) {
|
|
60
|
+
if (!(0, _zerodot_node_sdk.isRecord)(answer)) return void 0;
|
|
61
|
+
const message = answer.message;
|
|
62
|
+
if (typeof message === "string" && message.trim() !== "") return message.trim();
|
|
63
|
+
if (Array.isArray(message)) {
|
|
64
|
+
const parts = message.filter((entry) => typeof entry === "string");
|
|
65
|
+
if (parts.length > 0) return parts.join("; ");
|
|
66
|
+
}
|
|
67
|
+
const error = answer.error;
|
|
68
|
+
return typeof error === "string" && error.trim() !== "" ? error.trim() : void 0;
|
|
69
|
+
}
|
|
70
|
+
/** The error for a failed response. It never has the API key. */
|
|
71
|
+
function postizErrorOf(label, status, answer, retryAfter) {
|
|
72
|
+
const parts = [`Postiz ${label} failed (${status})`];
|
|
73
|
+
const detail = detailOf(answer);
|
|
74
|
+
if (detail) parts.push(detail);
|
|
75
|
+
const hint = HINTS[status];
|
|
76
|
+
if (hint) parts.push(hint);
|
|
77
|
+
if (retryAfter !== void 0) parts.push(`Try again in ${retryAfter} seconds`);
|
|
78
|
+
return new PostizError(parts.join(". "), status, retryAfter);
|
|
79
|
+
}
|
|
80
|
+
function urlFor(access, request) {
|
|
81
|
+
const url = new URL(`${access.baseUrl}${request.path}`);
|
|
82
|
+
for (const [key, value] of Object.entries(request.query ?? {})) if (value !== void 0 && value !== "") url.searchParams.set(key, String(value));
|
|
83
|
+
return url;
|
|
84
|
+
}
|
|
85
|
+
function bodyOf(request) {
|
|
86
|
+
if (request.upload) {
|
|
87
|
+
const form = new FormData();
|
|
88
|
+
const { file, fields } = request.upload;
|
|
89
|
+
form.set("file", new Blob([Buffer.from(file.data, "base64")], { type: file.mimeType }), file.name);
|
|
90
|
+
for (const [key, value] of Object.entries(fields)) form.set(key, value);
|
|
91
|
+
return {
|
|
92
|
+
body: form,
|
|
93
|
+
json: false
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (request.body) return {
|
|
97
|
+
body: JSON.stringify(request.body),
|
|
98
|
+
json: true
|
|
99
|
+
};
|
|
100
|
+
return { json: false };
|
|
101
|
+
}
|
|
102
|
+
const retryAfterOf = (header) => {
|
|
103
|
+
const seconds = Number(header);
|
|
104
|
+
return header !== null && Number.isFinite(seconds) && seconds >= 0 ? seconds : void 0;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* One call to the Postiz Public API. The API key goes in the `Authorization` header with no prefix.
|
|
108
|
+
* An empty answer gives `null`.
|
|
109
|
+
*/
|
|
110
|
+
async function callPostiz(access, request, options) {
|
|
111
|
+
const { body, json } = bodyOf(request);
|
|
112
|
+
const response = await fetch(urlFor(access, request), {
|
|
113
|
+
method: request.method,
|
|
114
|
+
headers: {
|
|
115
|
+
accept: "application/json",
|
|
116
|
+
authorization: access.apiKey,
|
|
117
|
+
"user-agent": "zerodot",
|
|
118
|
+
...json ? { "content-type": "application/json" } : {}
|
|
119
|
+
},
|
|
120
|
+
body,
|
|
121
|
+
redirect: "error",
|
|
122
|
+
signal: AbortSignal.any([options.signal, AbortSignal.timeout(options.timeoutMs)])
|
|
123
|
+
});
|
|
124
|
+
const raw = await response.text();
|
|
125
|
+
let answer = null;
|
|
126
|
+
if (raw !== "") try {
|
|
127
|
+
answer = JSON.parse(raw);
|
|
128
|
+
} catch {
|
|
129
|
+
answer = raw;
|
|
130
|
+
}
|
|
131
|
+
if (!response.ok) throw postizErrorOf(`${request.method} ${request.path}`, response.status, answer, retryAfterOf(response.headers.get("retry-after")));
|
|
132
|
+
return answer;
|
|
133
|
+
}
|
|
134
|
+
// src/icon.ts
|
|
135
|
+
const POSTIZ_ICON = (0, _zerodot_node_sdk.fileIcon)(require("url").pathToFileURL(__filename).href, "../postiz.svg");
|
|
136
|
+
// src/credential.ts
|
|
137
|
+
const TIMEOUT_MS = 1e4;
|
|
138
|
+
const postizCredential = {
|
|
139
|
+
type: POSTIZ_CREDENTIAL,
|
|
140
|
+
label: "Postiz API",
|
|
141
|
+
fields: zod.z.object({
|
|
142
|
+
apiKey: zod.z.string().min(1).meta({
|
|
143
|
+
title: "API Key",
|
|
144
|
+
description: "Get it in Postiz under Settings. An OAuth app token (starts with pos_) also works"
|
|
145
|
+
}),
|
|
146
|
+
baseUrl: zod.z.string().optional().meta({
|
|
147
|
+
title: "Base URL",
|
|
148
|
+
placeholder: POSTIZ_API,
|
|
149
|
+
description: "Empty means Postiz Cloud. For a self-hosted server, use https://your-domain/api"
|
|
150
|
+
})
|
|
151
|
+
}),
|
|
152
|
+
secretFields: ["apiKey"],
|
|
153
|
+
icon: "Key01Icon",
|
|
154
|
+
iconUrl: POSTIZ_ICON,
|
|
155
|
+
async test(credential) {
|
|
156
|
+
const answer = await callPostiz(postizAccess(credential), {
|
|
157
|
+
method: "GET",
|
|
158
|
+
path: "/is-connected"
|
|
159
|
+
}, {
|
|
160
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
161
|
+
timeoutMs: TIMEOUT_MS
|
|
162
|
+
});
|
|
163
|
+
if ((0, _zerodot_node_sdk.isRecord)(answer) && answer.connected === false) throw new Error("Postiz says that the API key is not connected");
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
// src/config.ts
|
|
167
|
+
const RESOURCES = [
|
|
168
|
+
"post",
|
|
169
|
+
"channel",
|
|
170
|
+
"group",
|
|
171
|
+
"analytics",
|
|
172
|
+
"notification",
|
|
173
|
+
"media",
|
|
174
|
+
"video",
|
|
175
|
+
"clipping"
|
|
176
|
+
];
|
|
177
|
+
const OPERATIONS_OF = {
|
|
178
|
+
post: [
|
|
179
|
+
"create",
|
|
180
|
+
"getAll",
|
|
181
|
+
"delete",
|
|
182
|
+
"deleteByGroup",
|
|
183
|
+
"getMissingContent",
|
|
184
|
+
"updateReleaseId",
|
|
185
|
+
"changeStatus",
|
|
186
|
+
"updateSettings",
|
|
187
|
+
"updateAttachments"
|
|
188
|
+
],
|
|
189
|
+
channel: [
|
|
190
|
+
"getAll",
|
|
191
|
+
"delete",
|
|
192
|
+
"getOAuthUrl",
|
|
193
|
+
"createConnectLink",
|
|
194
|
+
"getSettings",
|
|
195
|
+
"triggerTool",
|
|
196
|
+
"checkConnection",
|
|
197
|
+
"getAccount",
|
|
198
|
+
"findSlot"
|
|
199
|
+
],
|
|
200
|
+
group: ["getAll"],
|
|
201
|
+
analytics: ["getPlatform", "getPost"],
|
|
202
|
+
notification: ["getAll"],
|
|
203
|
+
media: [
|
|
204
|
+
"uploadFile",
|
|
205
|
+
"uploadFromUrl",
|
|
206
|
+
"getStatus",
|
|
207
|
+
"getAll"
|
|
208
|
+
],
|
|
209
|
+
video: ["generate", "runFunction"],
|
|
210
|
+
clipping: [
|
|
211
|
+
"create",
|
|
212
|
+
"get",
|
|
213
|
+
"getAll"
|
|
214
|
+
]
|
|
215
|
+
};
|
|
216
|
+
const ALL_OPERATIONS = [...new Set(Object.values(OPERATIONS_OF).flat())];
|
|
217
|
+
const POST_TYPES = [
|
|
218
|
+
"draft",
|
|
219
|
+
"schedule",
|
|
220
|
+
"now"
|
|
221
|
+
];
|
|
222
|
+
const STATUSES = ["draft", "schedule"];
|
|
223
|
+
const VALUE_TYPES = [
|
|
224
|
+
"string",
|
|
225
|
+
"number",
|
|
226
|
+
"boolean",
|
|
227
|
+
"json"
|
|
228
|
+
];
|
|
229
|
+
const VIDEO_OUTPUTS = ["vertical", "horizontal"];
|
|
230
|
+
const CLIP_FITS = ["blur", "crop"];
|
|
231
|
+
/** Show a field for these operations of these resources. */
|
|
232
|
+
const on = (operations) => ({ showWhen: Object.entries(operations).map(([resource, ops]) => ({
|
|
233
|
+
resource: [resource],
|
|
234
|
+
operation: [...ops ?? []]
|
|
235
|
+
})) });
|
|
236
|
+
const imageItem = zod.z.object({
|
|
237
|
+
id: zod.z.string().meta({ description: "ID of the file. Get it from Upload" }),
|
|
238
|
+
path: zod.z.string().meta({ description: "URL of the file. Get it from Upload" }),
|
|
239
|
+
alt: zod.z.string().optional().meta({ description: "Text for screen readers" }),
|
|
240
|
+
thumbnailTimestamp: zod.z.number().optional().meta({ description: "Video only. The millisecond of the frame for the cover" })
|
|
241
|
+
});
|
|
242
|
+
const imageList = zod.z.object({ imageItem: zod.z.array(imageItem).default([]) });
|
|
243
|
+
const contentItem = zod.z.object({
|
|
244
|
+
content: zod.z.string().meta({ description: "The text of the post" }),
|
|
245
|
+
id: zod.z.string().optional().meta({ description: "ID of an existing post, to update it" }),
|
|
246
|
+
image: imageList.optional()
|
|
247
|
+
});
|
|
248
|
+
const setting = zod.z.object({
|
|
249
|
+
key: zod.z.string().meta({ description: "The name of the setting, such as \"__type\"" }),
|
|
250
|
+
valueType: zod.z.enum(VALUE_TYPES).default("string"),
|
|
251
|
+
stringValue: zod.z.string().optional(),
|
|
252
|
+
numberValue: zod.z.number().optional(),
|
|
253
|
+
booleanValue: zod.z.boolean().optional(),
|
|
254
|
+
jsonValue: zod.z.string().optional().meta({ description: "A JSON object or array" })
|
|
255
|
+
});
|
|
256
|
+
const postItem = zod.z.object({
|
|
257
|
+
integrationId: zod.z.string().meta({
|
|
258
|
+
title: "Channel ID",
|
|
259
|
+
description: "Get the ID with Channel > Get Many, or from the Postiz app"
|
|
260
|
+
}),
|
|
261
|
+
group: zod.z.string().optional().meta({ description: "A group ID for related posts" }),
|
|
262
|
+
settings: zod.z.object({ setting: zod.z.array(setting).default([]) }).optional(),
|
|
263
|
+
value: zod.z.object({ contentItem: zod.z.array(contentItem).default([]) }).optional()
|
|
264
|
+
});
|
|
265
|
+
const tagItem = zod.z.object({
|
|
266
|
+
value: zod.z.string(),
|
|
267
|
+
label: zod.z.string()
|
|
268
|
+
});
|
|
269
|
+
const keyValue = zod.z.object({
|
|
270
|
+
key: zod.z.string(),
|
|
271
|
+
value: zod.z.string()
|
|
272
|
+
});
|
|
273
|
+
const keyValueList = zod.z.object({ parameter: zod.z.array(keyValue).default([]) });
|
|
274
|
+
const postizConfig = zod.z.object({
|
|
275
|
+
resource: zod.z.enum(RESOURCES).default("post").meta({
|
|
276
|
+
labels: {
|
|
277
|
+
post: "Post",
|
|
278
|
+
channel: "Channel",
|
|
279
|
+
group: "Group",
|
|
280
|
+
analytics: "Analytics",
|
|
281
|
+
notification: "Notification",
|
|
282
|
+
media: "Media",
|
|
283
|
+
video: "Video",
|
|
284
|
+
clipping: "Clipping"
|
|
285
|
+
},
|
|
286
|
+
hints: {
|
|
287
|
+
post: "Create, find, change, and delete posts",
|
|
288
|
+
channel: "Connected social media accounts, their settings, and tools",
|
|
289
|
+
group: "Customer groups of channels",
|
|
290
|
+
analytics: "Numbers of a channel or of a published post",
|
|
291
|
+
notification: "Notifications of the organization",
|
|
292
|
+
media: "Upload files and list the media library",
|
|
293
|
+
video: "Make a video with AI",
|
|
294
|
+
clipping: "Cut short clips from a YouTube video"
|
|
295
|
+
}
|
|
296
|
+
}),
|
|
297
|
+
operation: zod.z.enum(ALL_OPERATIONS).default("getAll").meta({
|
|
298
|
+
labels: {
|
|
299
|
+
create: "Create",
|
|
300
|
+
getAll: "Get Many",
|
|
301
|
+
get: "Get",
|
|
302
|
+
delete: "Delete",
|
|
303
|
+
deleteByGroup: "Delete by Group",
|
|
304
|
+
getMissingContent: "Get Missing Content",
|
|
305
|
+
updateReleaseId: "Update Release ID",
|
|
306
|
+
changeStatus: "Change Status",
|
|
307
|
+
updateSettings: "Update Settings",
|
|
308
|
+
updateAttachments: "Update Attachments",
|
|
309
|
+
getOAuthUrl: "Get OAuth URL",
|
|
310
|
+
createConnectLink: "Create Connect Link",
|
|
311
|
+
getSettings: "Get Settings and Tools",
|
|
312
|
+
triggerTool: "Trigger a Tool",
|
|
313
|
+
checkConnection: "Check Connection",
|
|
314
|
+
getAccount: "Get Connected Account",
|
|
315
|
+
findSlot: "Find Free Slot",
|
|
316
|
+
getPlatform: "Get Channel Analytics",
|
|
317
|
+
getPost: "Get Post Analytics",
|
|
318
|
+
uploadFile: "Upload File",
|
|
319
|
+
uploadFromUrl: "Upload From URL",
|
|
320
|
+
getStatus: "Get Status",
|
|
321
|
+
generate: "Generate Video",
|
|
322
|
+
runFunction: "Run Video Function"
|
|
323
|
+
},
|
|
324
|
+
hints: {
|
|
325
|
+
create: "Create, schedule, or publish a post. For clipping: start a new clipping",
|
|
326
|
+
getAll: "Get all items, or use filters",
|
|
327
|
+
get: "Get one item",
|
|
328
|
+
delete: "Delete one item",
|
|
329
|
+
deleteByGroup: "Delete all posts of a group",
|
|
330
|
+
getMissingContent: "Get recent content from the platform for a post with a missing release ID",
|
|
331
|
+
updateReleaseId: "Link a post with a missing release ID to its published content",
|
|
332
|
+
changeStatus: "Move a post between draft and schedule",
|
|
333
|
+
updateSettings: "Merge new keys into the settings of a post that is not published",
|
|
334
|
+
updateAttachments: "Replace the media of a post that is not published",
|
|
335
|
+
getOAuthUrl: "Get the OAuth URL to connect a new channel",
|
|
336
|
+
createConnectLink: "Make a link that lets a person connect a channel. It works 1 hour",
|
|
337
|
+
getSettings: "Get the rules, the settings schema, and the tools of a channel",
|
|
338
|
+
triggerTool: "Run a tool of a channel, such as a list of Reddit flairs",
|
|
339
|
+
checkConnection: "Check that the API key is valid",
|
|
340
|
+
getAccount: "Get the workspace that the API key acts for",
|
|
341
|
+
findSlot: "Get the next free time slot of a channel",
|
|
342
|
+
getPlatform: "Followers, impressions, and other numbers of a channel",
|
|
343
|
+
getPost: "Likes, comments, and other numbers of a published post",
|
|
344
|
+
uploadFile: "Upload a file of the input",
|
|
345
|
+
uploadFromUrl: "Upload a file from a URL",
|
|
346
|
+
getStatus: "Check if an upload with Adjust is ready",
|
|
347
|
+
generate: "Make a video with AI",
|
|
348
|
+
runFunction: "Run a function of a video type, such as loading the voices"
|
|
349
|
+
}
|
|
350
|
+
}),
|
|
351
|
+
postId: zod.z.string().optional().meta({
|
|
352
|
+
title: "Post ID",
|
|
353
|
+
...on({
|
|
354
|
+
post: [
|
|
355
|
+
"delete",
|
|
356
|
+
"getMissingContent",
|
|
357
|
+
"updateReleaseId",
|
|
358
|
+
"changeStatus",
|
|
359
|
+
"updateSettings",
|
|
360
|
+
"updateAttachments"
|
|
361
|
+
],
|
|
362
|
+
analytics: ["getPost"]
|
|
363
|
+
}),
|
|
364
|
+
description: "Delete: all posts of the same group go away too"
|
|
365
|
+
}),
|
|
366
|
+
group: zod.z.string().optional().meta({
|
|
367
|
+
title: "Group",
|
|
368
|
+
...on({ post: ["deleteByGroup"] }),
|
|
369
|
+
description: "The group ID of the posts"
|
|
370
|
+
}),
|
|
371
|
+
integrationId: zod.z.string().optional().meta({
|
|
372
|
+
title: "Channel ID",
|
|
373
|
+
...on({
|
|
374
|
+
channel: [
|
|
375
|
+
"delete",
|
|
376
|
+
"getSettings",
|
|
377
|
+
"triggerTool",
|
|
378
|
+
"findSlot"
|
|
379
|
+
],
|
|
380
|
+
analytics: ["getPlatform"]
|
|
381
|
+
}),
|
|
382
|
+
description: "Get the ID with Channel > Get Many, or from the Postiz app"
|
|
383
|
+
}),
|
|
384
|
+
mediaId: zod.z.string().optional().meta({
|
|
385
|
+
title: "Media ID",
|
|
386
|
+
...on({ media: ["getStatus"] }),
|
|
387
|
+
description: "The ID that the upload gave"
|
|
388
|
+
}),
|
|
389
|
+
clippingId: zod.z.string().optional().meta({
|
|
390
|
+
title: "Clipping ID",
|
|
391
|
+
...on({ clipping: ["get"] })
|
|
392
|
+
}),
|
|
393
|
+
type: zod.z.enum(POST_TYPES).default("now").meta({
|
|
394
|
+
title: "Type",
|
|
395
|
+
...on({ post: ["create"] }),
|
|
396
|
+
labels: {
|
|
397
|
+
draft: "Draft",
|
|
398
|
+
schedule: "Schedule",
|
|
399
|
+
now: "Now"
|
|
400
|
+
},
|
|
401
|
+
hints: {
|
|
402
|
+
draft: "Save the post. Do not publish it",
|
|
403
|
+
schedule: "Publish the post at the date",
|
|
404
|
+
now: "Publish the post now"
|
|
405
|
+
}
|
|
406
|
+
}),
|
|
407
|
+
shortLink: zod.z.boolean().default(false).meta({
|
|
408
|
+
title: "Short Link",
|
|
409
|
+
...on({ post: ["create"] }),
|
|
410
|
+
description: "Whether to use short links"
|
|
411
|
+
}),
|
|
412
|
+
date: zod.z.string().optional().meta({
|
|
413
|
+
title: "Date",
|
|
414
|
+
...on({ post: ["create"] }),
|
|
415
|
+
description: "Date and time of the post, in UTC ISO format. Empty means now"
|
|
416
|
+
}),
|
|
417
|
+
order: zod.z.string().optional().meta({
|
|
418
|
+
title: "Order",
|
|
419
|
+
...on({ post: ["create"] }),
|
|
420
|
+
description: "Order of the posts"
|
|
421
|
+
}),
|
|
422
|
+
interval: zod.z.number().optional().meta({
|
|
423
|
+
title: "Interval",
|
|
424
|
+
...on({ post: ["create"] }),
|
|
425
|
+
description: "Interval between the posts"
|
|
426
|
+
}),
|
|
427
|
+
tags: zod.z.object({ tag: zod.z.array(tagItem).default([]) }).optional().meta({
|
|
428
|
+
title: "Tags",
|
|
429
|
+
...on({ post: ["create"] }),
|
|
430
|
+
description: "Tags for the post"
|
|
431
|
+
}),
|
|
432
|
+
posts: zod.z.object({ post: zod.z.array(postItem).default([]) }).optional().meta({
|
|
433
|
+
title: "Posts",
|
|
434
|
+
...on({ post: ["create"] }),
|
|
435
|
+
description: "One entry for each channel. A draft needs no entry"
|
|
436
|
+
}),
|
|
437
|
+
startDate: zod.z.string().optional().meta({
|
|
438
|
+
title: "Start Date (UTC)",
|
|
439
|
+
...on({ post: ["getAll"] }),
|
|
440
|
+
description: "Start of the range, in UTC ISO format"
|
|
441
|
+
}),
|
|
442
|
+
endDate: zod.z.string().optional().meta({
|
|
443
|
+
title: "End Date (UTC)",
|
|
444
|
+
...on({ post: ["getAll"] }),
|
|
445
|
+
description: "End of the range, in UTC ISO format"
|
|
446
|
+
}),
|
|
447
|
+
customer: zod.z.string().optional().meta({
|
|
448
|
+
title: "Customer",
|
|
449
|
+
...on({
|
|
450
|
+
post: ["getAll"],
|
|
451
|
+
channel: ["getAll"]
|
|
452
|
+
}),
|
|
453
|
+
description: "Only items of this customer (group) ID. Optional"
|
|
454
|
+
}),
|
|
455
|
+
releaseId: zod.z.string().optional().meta({
|
|
456
|
+
title: "Release ID",
|
|
457
|
+
...on({ post: ["updateReleaseId"] }),
|
|
458
|
+
description: "The ID of the content on the platform. Get it from Get Missing Content"
|
|
459
|
+
}),
|
|
460
|
+
status: zod.z.enum(STATUSES).default("schedule").meta({
|
|
461
|
+
title: "Status",
|
|
462
|
+
...on({ post: ["changeStatus"] }),
|
|
463
|
+
labels: {
|
|
464
|
+
draft: "Draft",
|
|
465
|
+
schedule: "Schedule"
|
|
466
|
+
},
|
|
467
|
+
hints: {
|
|
468
|
+
draft: "Stop the publishing of the post",
|
|
469
|
+
schedule: "Publish the post at its date"
|
|
470
|
+
}
|
|
471
|
+
}),
|
|
472
|
+
postSettings: zod.z.string().optional().meta({
|
|
473
|
+
title: "Settings (JSON)",
|
|
474
|
+
ui: "code",
|
|
475
|
+
...on({ post: ["updateSettings"] }),
|
|
476
|
+
placeholder: "{\"who_can_reply_post\":\"everyone\"}",
|
|
477
|
+
description: "A JSON object. Only these keys change"
|
|
478
|
+
}),
|
|
479
|
+
attachments: imageList.optional().meta({
|
|
480
|
+
title: "Attachments",
|
|
481
|
+
...on({ post: ["updateAttachments"] }),
|
|
482
|
+
description: "The full new list. An empty list removes all media"
|
|
483
|
+
}),
|
|
484
|
+
integration: zod.z.string().optional().meta({
|
|
485
|
+
title: "Platform",
|
|
486
|
+
...on({ channel: ["getOAuthUrl", "createConnectLink"] }),
|
|
487
|
+
placeholder: "x",
|
|
488
|
+
description: "The platform name, such as x, linkedin, facebook, instagram, or youtube"
|
|
489
|
+
}),
|
|
490
|
+
refresh: zod.z.string().optional().meta({
|
|
491
|
+
title: "Refresh Channel ID",
|
|
492
|
+
...on({ channel: ["getOAuthUrl"] }),
|
|
493
|
+
description: "A channel ID. Postiz then refreshes the token of this channel"
|
|
494
|
+
}),
|
|
495
|
+
redirectUrl: zod.z.string().optional().meta({
|
|
496
|
+
title: "Redirect URL",
|
|
497
|
+
...on({ channel: ["createConnectLink"] }),
|
|
498
|
+
description: "Where the person goes after the connect. Empty means they stay on Postiz"
|
|
499
|
+
}),
|
|
500
|
+
methodName: zod.z.string().optional().meta({
|
|
501
|
+
title: "Method Name",
|
|
502
|
+
...on({ channel: ["triggerTool"] }),
|
|
503
|
+
description: "The name of the tool. Get it with Get Settings and Tools"
|
|
504
|
+
}),
|
|
505
|
+
triggerData: zod.z.string().optional().meta({
|
|
506
|
+
title: "Data (JSON)",
|
|
507
|
+
ui: "code",
|
|
508
|
+
...on({ channel: ["triggerTool"] }),
|
|
509
|
+
placeholder: "{\"query\":\"summer\"}",
|
|
510
|
+
description: "A JSON object with the inputs of the tool"
|
|
511
|
+
}),
|
|
512
|
+
lookbackDays: zod.z.number().int().min(1).default(7).meta({
|
|
513
|
+
title: "Days",
|
|
514
|
+
...on({ analytics: ["getPlatform", "getPost"] }),
|
|
515
|
+
description: "How many days to look back, such as 7, 30, or 90"
|
|
516
|
+
}),
|
|
517
|
+
page: zod.z.number().int().min(1).default(1).meta({
|
|
518
|
+
title: "Page",
|
|
519
|
+
...on({
|
|
520
|
+
notification: ["getAll"],
|
|
521
|
+
media: ["getAll"],
|
|
522
|
+
clipping: ["getAll"]
|
|
523
|
+
}),
|
|
524
|
+
description: "The page number, from 1. A page has 100 notifications, 18 media files, or 20 clippings"
|
|
525
|
+
}),
|
|
526
|
+
search: zod.z.string().optional().meta({
|
|
527
|
+
title: "Search",
|
|
528
|
+
...on({ media: ["getAll"] }),
|
|
529
|
+
description: "Only files with this text in the original name"
|
|
530
|
+
}),
|
|
531
|
+
binaryProperty: zod.z.string().default("data").meta({
|
|
532
|
+
title: "Binary Property",
|
|
533
|
+
...on({ media: ["uploadFile"] }),
|
|
534
|
+
description: "The name of the binary property with the file data"
|
|
535
|
+
}),
|
|
536
|
+
url: zod.z.string().optional().meta({
|
|
537
|
+
title: "URL",
|
|
538
|
+
...on({
|
|
539
|
+
media: ["uploadFromUrl"],
|
|
540
|
+
clipping: ["create"]
|
|
541
|
+
}),
|
|
542
|
+
description: "Upload: the URL of the file. Clipping: the URL of a YouTube video"
|
|
543
|
+
}),
|
|
544
|
+
adjust: zod.z.boolean().default(false).meta({
|
|
545
|
+
title: "Adjust",
|
|
546
|
+
...on({ media: ["uploadFile", "uploadFromUrl"] }),
|
|
547
|
+
description: "Scale the file to the limits of the platforms. This runs in the background. Use Get Status to see when it is done"
|
|
548
|
+
}),
|
|
549
|
+
videoType: zod.z.string().default("image-text-slides").meta({
|
|
550
|
+
title: "Video Type",
|
|
551
|
+
...on({ video: ["generate"] }),
|
|
552
|
+
description: "The type of video: image-text-slides or veo3"
|
|
553
|
+
}),
|
|
554
|
+
output: zod.z.enum(VIDEO_OUTPUTS).default("vertical").meta({
|
|
555
|
+
title: "Output Format",
|
|
556
|
+
...on({ video: ["generate"] }),
|
|
557
|
+
labels: {
|
|
558
|
+
vertical: "Vertical",
|
|
559
|
+
horizontal: "Horizontal"
|
|
560
|
+
}
|
|
561
|
+
}),
|
|
562
|
+
customParameters: keyValueList.optional().meta({
|
|
563
|
+
title: "Custom Parameters",
|
|
564
|
+
...on({ video: ["generate"] }),
|
|
565
|
+
description: "Parameters of the video, such as prompt, voice, or images. A value can be JSON, such as [{\"id\":\"...\",\"path\":\"...\"}]"
|
|
566
|
+
}),
|
|
567
|
+
functionName: zod.z.string().optional().meta({
|
|
568
|
+
title: "Function Name",
|
|
569
|
+
...on({ video: ["runFunction"] }),
|
|
570
|
+
placeholder: "loadVoices",
|
|
571
|
+
description: "The function to run, such as loadVoices"
|
|
572
|
+
}),
|
|
573
|
+
identifier: zod.z.string().optional().meta({
|
|
574
|
+
title: "Identifier",
|
|
575
|
+
...on({ video: ["runFunction"] }),
|
|
576
|
+
placeholder: "image-text-slides",
|
|
577
|
+
description: "The video type of the function"
|
|
578
|
+
}),
|
|
579
|
+
additionalParameters: keyValueList.optional().meta({
|
|
580
|
+
title: "Additional Parameters",
|
|
581
|
+
...on({ video: ["runFunction"] }),
|
|
582
|
+
description: "Parameters for the function"
|
|
583
|
+
}),
|
|
584
|
+
clipIntegrations: zod.z.string().optional().meta({
|
|
585
|
+
title: "Channel IDs",
|
|
586
|
+
...on({ clipping: ["create"] }),
|
|
587
|
+
description: "Channel IDs with commas between (at most 20). Postiz makes a draft for each clip on each channel. Empty means the clips go only to the media library"
|
|
588
|
+
}),
|
|
589
|
+
clipCount: zod.z.number().int().min(1).max(10).default(5).meta({
|
|
590
|
+
title: "Clips",
|
|
591
|
+
...on({ clipping: ["create"] }),
|
|
592
|
+
description: "The most clips to make"
|
|
593
|
+
}),
|
|
594
|
+
clipFit: zod.z.enum(CLIP_FITS).default("blur").meta({
|
|
595
|
+
title: "Fit",
|
|
596
|
+
...on({ clipping: ["create"] }),
|
|
597
|
+
labels: {
|
|
598
|
+
blur: "Blur",
|
|
599
|
+
crop: "Crop"
|
|
600
|
+
},
|
|
601
|
+
hints: {
|
|
602
|
+
blur: "Keep the whole picture over a blurred copy of itself",
|
|
603
|
+
crop: "Fill the clip with the middle of the picture"
|
|
604
|
+
}
|
|
605
|
+
}),
|
|
606
|
+
timeoutMs: zod.z.number().int().min(1e3).max(6e5).default(3e4).meta({ title: "Timeout (ms)" })
|
|
607
|
+
}).superRefine((config, context) => {
|
|
608
|
+
if (!OPERATIONS_OF[config.resource].includes(config.operation)) context.addIssue({
|
|
609
|
+
code: "custom",
|
|
610
|
+
path: ["operation"],
|
|
611
|
+
message: `"${config.operation}" is not an operation of "${config.resource}"`
|
|
612
|
+
});
|
|
613
|
+
});
|
|
614
|
+
// src/request.ts
|
|
615
|
+
const seg = encodeURIComponent;
|
|
616
|
+
const need = (value, name, operation) => {
|
|
617
|
+
if (value === void 0 || typeof value === "string" && value.trim() === "") throw new Error(`"${name}" is needed to ${operation}`);
|
|
618
|
+
return typeof value === "string" ? value.trim() : value;
|
|
619
|
+
};
|
|
620
|
+
const compact = (body) => Object.fromEntries(Object.entries(body).filter(([, value]) => value !== void 0 && value !== ""));
|
|
621
|
+
/** A JSON value from text. Text that is not JSON stays text. */
|
|
622
|
+
const looseJson = (value) => {
|
|
623
|
+
try {
|
|
624
|
+
return JSON.parse(value);
|
|
625
|
+
} catch {
|
|
626
|
+
return value;
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
/** A JSON object from a field. Empty text gives `undefined`. */
|
|
630
|
+
function jsonObjectOf(raw, field) {
|
|
631
|
+
const trimmed = raw?.trim();
|
|
632
|
+
if (!trimmed) return void 0;
|
|
633
|
+
let parsed;
|
|
634
|
+
try {
|
|
635
|
+
parsed = JSON.parse(trimmed);
|
|
636
|
+
} catch {
|
|
637
|
+
throw new Error(`"${field}" must be valid JSON`);
|
|
638
|
+
}
|
|
639
|
+
if (!(0, _zerodot_node_sdk.isRecord)(parsed)) throw new Error(`"${field}" must be a JSON object`);
|
|
640
|
+
return parsed;
|
|
641
|
+
}
|
|
642
|
+
/** The media of a post. Empty optional fields do not go to the API. */
|
|
643
|
+
function mediaOf(list) {
|
|
644
|
+
return (list?.imageItem ?? []).map((item) => compact({
|
|
645
|
+
id: item.id,
|
|
646
|
+
path: item.path,
|
|
647
|
+
alt: item.alt,
|
|
648
|
+
thumbnailTimestamp: item.thumbnailTimestamp
|
|
649
|
+
}));
|
|
650
|
+
}
|
|
651
|
+
function settingValue(setting) {
|
|
652
|
+
switch (setting.valueType) {
|
|
653
|
+
case "number": return setting.numberValue ?? 0;
|
|
654
|
+
case "boolean": return setting.booleanValue ?? false;
|
|
655
|
+
case "json": return looseJson(setting.jsonValue ?? "");
|
|
656
|
+
default: return setting.stringValue ?? "";
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
/** The `settings` object of a post, from the list of keys and values. */
|
|
660
|
+
function settingsOf(entry) {
|
|
661
|
+
const settings = {};
|
|
662
|
+
for (const setting of entry.settings?.setting ?? []) {
|
|
663
|
+
const key = setting.key.trim();
|
|
664
|
+
if (key) settings[key] = settingValue(setting);
|
|
665
|
+
}
|
|
666
|
+
return settings;
|
|
667
|
+
}
|
|
668
|
+
/** The list `posts` of the create call. */
|
|
669
|
+
function postsOf(c) {
|
|
670
|
+
return (c.posts?.post ?? []).map((entry) => ({
|
|
671
|
+
integration: { id: need(entry.integrationId, "integrationId", "create a post") },
|
|
672
|
+
value: (entry.value?.contentItem ?? []).map((item) => ({
|
|
673
|
+
content: item.content,
|
|
674
|
+
...item.id?.trim() ? { id: item.id.trim() } : {},
|
|
675
|
+
image: mediaOf(item.image)
|
|
676
|
+
})),
|
|
677
|
+
...entry.group?.trim() ? { group: entry.group.trim() } : {},
|
|
678
|
+
settings: settingsOf(entry)
|
|
679
|
+
}));
|
|
680
|
+
}
|
|
681
|
+
/** Text with commas between, as a list. */
|
|
682
|
+
const listOf = (text) => (text ?? "").split(",").map((item) => item.trim()).filter(Boolean);
|
|
683
|
+
/** Pairs of key and value as an object. With `parse` a JSON value becomes JSON. */
|
|
684
|
+
function pairsOf(list, parse) {
|
|
685
|
+
const result = {};
|
|
686
|
+
for (const { key, value } of list?.parameter ?? []) if (key.trim()) result[key.trim()] = parse ? looseJson(value) : value;
|
|
687
|
+
return result;
|
|
688
|
+
}
|
|
689
|
+
/** The `data` of a tool call. The API wants text values. */
|
|
690
|
+
function toolDataOf(raw) {
|
|
691
|
+
const object = jsonObjectOf(raw, "triggerData");
|
|
692
|
+
if (!object) return void 0;
|
|
693
|
+
return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, typeof value === "string" ? value : JSON.stringify(value)]));
|
|
694
|
+
}
|
|
695
|
+
/** The API call for one operation, without the network. The input has the binary data. */
|
|
696
|
+
function buildRequest(c, input) {
|
|
697
|
+
const op = `${c.resource}.${c.operation}`;
|
|
698
|
+
const post = () => `/posts/${seg(need(c.postId, "postId", op))}`;
|
|
699
|
+
const channel = () => seg(need(c.integrationId, "integrationId", op));
|
|
700
|
+
switch (op) {
|
|
701
|
+
case "post.create": {
|
|
702
|
+
const posts = postsOf(c);
|
|
703
|
+
if (c.type !== "draft" && posts.length === 0) throw new Error("\"posts\" needs at least one post, unless the type is Draft");
|
|
704
|
+
return {
|
|
705
|
+
method: "POST",
|
|
706
|
+
path: "/posts",
|
|
707
|
+
body: {
|
|
708
|
+
type: c.type,
|
|
709
|
+
shortLink: c.shortLink,
|
|
710
|
+
date: c.date?.trim() || (/* @__PURE__ */ new Date()).toISOString(),
|
|
711
|
+
tags: (c.tags?.tag ?? []).map(({ value, label }) => ({
|
|
712
|
+
value,
|
|
713
|
+
label
|
|
714
|
+
})),
|
|
715
|
+
...c.order?.trim() ? { order: c.order.trim() } : {},
|
|
716
|
+
...c.interval === void 0 ? {} : { inter: c.interval },
|
|
717
|
+
posts
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
case "post.getAll": return {
|
|
722
|
+
method: "GET",
|
|
723
|
+
path: "/posts",
|
|
724
|
+
query: {
|
|
725
|
+
startDate: need(c.startDate, "startDate", op),
|
|
726
|
+
endDate: need(c.endDate, "endDate", op),
|
|
727
|
+
customer: c.customer?.trim()
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
case "post.delete": return {
|
|
731
|
+
method: "DELETE",
|
|
732
|
+
path: post()
|
|
733
|
+
};
|
|
734
|
+
case "post.deleteByGroup": return {
|
|
735
|
+
method: "DELETE",
|
|
736
|
+
path: `/posts/group/${seg(need(c.group, "group", op))}`
|
|
737
|
+
};
|
|
738
|
+
case "post.getMissingContent": return {
|
|
739
|
+
method: "GET",
|
|
740
|
+
path: `${post()}/missing`
|
|
741
|
+
};
|
|
742
|
+
case "post.updateReleaseId": return {
|
|
743
|
+
method: "PUT",
|
|
744
|
+
path: `${post()}/release-id`,
|
|
745
|
+
body: { releaseId: need(c.releaseId, "releaseId", op) }
|
|
746
|
+
};
|
|
747
|
+
case "post.changeStatus": return {
|
|
748
|
+
method: "PUT",
|
|
749
|
+
path: `${post()}/status`,
|
|
750
|
+
body: { status: c.status }
|
|
751
|
+
};
|
|
752
|
+
case "post.updateSettings": return {
|
|
753
|
+
method: "PUT",
|
|
754
|
+
path: `${post()}/settings`,
|
|
755
|
+
body: { settings: need(jsonObjectOf(c.postSettings, "postSettings"), "postSettings", op) }
|
|
756
|
+
};
|
|
757
|
+
case "post.updateAttachments": return {
|
|
758
|
+
method: "PUT",
|
|
759
|
+
path: `${post()}/attachments`,
|
|
760
|
+
body: { attachments: mediaOf(c.attachments) }
|
|
761
|
+
};
|
|
762
|
+
case "channel.getAll": return {
|
|
763
|
+
method: "GET",
|
|
764
|
+
path: "/integrations",
|
|
765
|
+
query: { group: c.customer?.trim() }
|
|
766
|
+
};
|
|
767
|
+
case "channel.delete": return {
|
|
768
|
+
method: "DELETE",
|
|
769
|
+
path: `/integrations/${channel()}`
|
|
770
|
+
};
|
|
771
|
+
case "channel.getOAuthUrl": return {
|
|
772
|
+
method: "GET",
|
|
773
|
+
path: `/social/${seg(need(c.integration, "integration", op))}`,
|
|
774
|
+
query: { refresh: c.refresh?.trim() }
|
|
775
|
+
};
|
|
776
|
+
case "channel.createConnectLink": return {
|
|
777
|
+
method: "POST",
|
|
778
|
+
path: "/integrations/connect",
|
|
779
|
+
body: compact({
|
|
780
|
+
integration: need(c.integration, "integration", op),
|
|
781
|
+
redirectUrl: c.redirectUrl?.trim()
|
|
782
|
+
})
|
|
783
|
+
};
|
|
784
|
+
case "channel.getSettings": return {
|
|
785
|
+
method: "GET",
|
|
786
|
+
path: `/integration-settings/${channel()}`
|
|
787
|
+
};
|
|
788
|
+
case "channel.triggerTool": {
|
|
789
|
+
const data = toolDataOf(c.triggerData);
|
|
790
|
+
return {
|
|
791
|
+
method: "POST",
|
|
792
|
+
path: `/integration-trigger/${channel()}`,
|
|
793
|
+
body: {
|
|
794
|
+
methodName: need(c.methodName, "methodName", op),
|
|
795
|
+
...data ? { data } : {}
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
case "channel.checkConnection": return {
|
|
800
|
+
method: "GET",
|
|
801
|
+
path: "/is-connected"
|
|
802
|
+
};
|
|
803
|
+
case "channel.getAccount": return {
|
|
804
|
+
method: "GET",
|
|
805
|
+
path: "/me"
|
|
806
|
+
};
|
|
807
|
+
case "channel.findSlot": return {
|
|
808
|
+
method: "GET",
|
|
809
|
+
path: `/find-slot/${channel()}`
|
|
810
|
+
};
|
|
811
|
+
case "group.getAll": return {
|
|
812
|
+
method: "GET",
|
|
813
|
+
path: "/groups"
|
|
814
|
+
};
|
|
815
|
+
case "analytics.getPlatform": return {
|
|
816
|
+
method: "GET",
|
|
817
|
+
path: `/analytics/${channel()}`,
|
|
818
|
+
query: { date: c.lookbackDays }
|
|
819
|
+
};
|
|
820
|
+
case "analytics.getPost": return {
|
|
821
|
+
method: "GET",
|
|
822
|
+
path: `/analytics/post/${seg(need(c.postId, "postId", op))}`,
|
|
823
|
+
query: { date: c.lookbackDays }
|
|
824
|
+
};
|
|
825
|
+
case "notification.getAll": return {
|
|
826
|
+
method: "GET",
|
|
827
|
+
path: "/notifications",
|
|
828
|
+
query: { page: c.page - 1 }
|
|
829
|
+
};
|
|
830
|
+
case "media.uploadFile": {
|
|
831
|
+
const file = (0, _zerodot_node_sdk.readBinary)(input, need(c.binaryProperty, "binaryProperty", op));
|
|
832
|
+
return {
|
|
833
|
+
method: "POST",
|
|
834
|
+
path: "/upload",
|
|
835
|
+
upload: {
|
|
836
|
+
file: {
|
|
837
|
+
name: file.fileName || "file",
|
|
838
|
+
mimeType: file.mimeType || "application/octet-stream",
|
|
839
|
+
data: file.data
|
|
840
|
+
},
|
|
841
|
+
fields: { adjust: String(c.adjust) }
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
case "media.uploadFromUrl": return {
|
|
846
|
+
method: "POST",
|
|
847
|
+
path: "/upload-from-url",
|
|
848
|
+
body: {
|
|
849
|
+
url: need(c.url, "url", op),
|
|
850
|
+
adjust: c.adjust
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
case "media.getStatus": return {
|
|
854
|
+
method: "GET",
|
|
855
|
+
path: `/media/${seg(need(c.mediaId, "mediaId", op))}/status`
|
|
856
|
+
};
|
|
857
|
+
case "media.getAll": return {
|
|
858
|
+
method: "GET",
|
|
859
|
+
path: "/media",
|
|
860
|
+
query: {
|
|
861
|
+
page: c.page,
|
|
862
|
+
search: c.search?.trim()
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
case "video.generate": return {
|
|
866
|
+
method: "POST",
|
|
867
|
+
path: "/generate-video",
|
|
868
|
+
body: {
|
|
869
|
+
type: need(c.videoType, "videoType", op),
|
|
870
|
+
output: c.output,
|
|
871
|
+
customParams: pairsOf(c.customParameters, true)
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
case "video.runFunction": {
|
|
875
|
+
const params = pairsOf(c.additionalParameters, false);
|
|
876
|
+
return {
|
|
877
|
+
method: "POST",
|
|
878
|
+
path: "/video/function",
|
|
879
|
+
body: {
|
|
880
|
+
functionName: need(c.functionName, "functionName", op),
|
|
881
|
+
identifier: need(c.identifier, "identifier", op),
|
|
882
|
+
...Object.keys(params).length > 0 ? { params } : {}
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
case "clipping.create": {
|
|
887
|
+
const integrations = listOf(c.clipIntegrations);
|
|
888
|
+
return {
|
|
889
|
+
method: "POST",
|
|
890
|
+
path: "/clipping",
|
|
891
|
+
body: {
|
|
892
|
+
url: need(c.url, "url", op),
|
|
893
|
+
...integrations.length > 0 ? { integrations } : {},
|
|
894
|
+
clips: c.clipCount,
|
|
895
|
+
fit: c.clipFit
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
case "clipping.get": return {
|
|
900
|
+
method: "GET",
|
|
901
|
+
path: `/clipping/${seg(need(c.clippingId, "clippingId", op))}`
|
|
902
|
+
};
|
|
903
|
+
case "clipping.getAll": return {
|
|
904
|
+
method: "GET",
|
|
905
|
+
path: "/clipping",
|
|
906
|
+
query: { page: c.page }
|
|
907
|
+
};
|
|
908
|
+
default: throw new Error(`"${c.operation}" is not an operation of "${c.resource}"`);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
// src/index.ts
|
|
912
|
+
const nodes = [(0, _zerodot_node_sdk.defineNode)({
|
|
913
|
+
type: "postiz.api",
|
|
914
|
+
label: "Postiz",
|
|
915
|
+
description: "Create, schedule, and delete social media posts, manage channels, upload media, and read analytics with Postiz",
|
|
916
|
+
category: "integration",
|
|
917
|
+
app: "Postiz",
|
|
918
|
+
actions: [
|
|
919
|
+
{
|
|
920
|
+
label: "Create a post",
|
|
921
|
+
config: {
|
|
922
|
+
resource: "post",
|
|
923
|
+
operation: "create"
|
|
924
|
+
}
|
|
925
|
+
},
|
|
926
|
+
{
|
|
927
|
+
label: "Get many posts",
|
|
928
|
+
config: {
|
|
929
|
+
resource: "post",
|
|
930
|
+
operation: "getAll"
|
|
931
|
+
}
|
|
932
|
+
},
|
|
933
|
+
{
|
|
934
|
+
label: "Delete a post",
|
|
935
|
+
config: {
|
|
936
|
+
resource: "post",
|
|
937
|
+
operation: "delete"
|
|
938
|
+
}
|
|
939
|
+
},
|
|
940
|
+
{
|
|
941
|
+
label: "Delete the posts of a group",
|
|
942
|
+
config: {
|
|
943
|
+
resource: "post",
|
|
944
|
+
operation: "deleteByGroup"
|
|
945
|
+
}
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
label: "Get missing content of a post",
|
|
949
|
+
config: {
|
|
950
|
+
resource: "post",
|
|
951
|
+
operation: "getMissingContent"
|
|
952
|
+
}
|
|
953
|
+
},
|
|
954
|
+
{
|
|
955
|
+
label: "Update the release ID of a post",
|
|
956
|
+
config: {
|
|
957
|
+
resource: "post",
|
|
958
|
+
operation: "updateReleaseId"
|
|
959
|
+
}
|
|
960
|
+
},
|
|
961
|
+
{
|
|
962
|
+
label: "Change the status of a post",
|
|
963
|
+
config: {
|
|
964
|
+
resource: "post",
|
|
965
|
+
operation: "changeStatus"
|
|
966
|
+
}
|
|
967
|
+
},
|
|
968
|
+
{
|
|
969
|
+
label: "Update the settings of a post",
|
|
970
|
+
config: {
|
|
971
|
+
resource: "post",
|
|
972
|
+
operation: "updateSettings"
|
|
973
|
+
}
|
|
974
|
+
},
|
|
975
|
+
{
|
|
976
|
+
label: "Update the attachments of a post",
|
|
977
|
+
config: {
|
|
978
|
+
resource: "post",
|
|
979
|
+
operation: "updateAttachments"
|
|
980
|
+
}
|
|
981
|
+
},
|
|
982
|
+
{
|
|
983
|
+
label: "Get many channels",
|
|
984
|
+
config: {
|
|
985
|
+
resource: "channel",
|
|
986
|
+
operation: "getAll"
|
|
987
|
+
}
|
|
988
|
+
},
|
|
989
|
+
{
|
|
990
|
+
label: "Delete a channel",
|
|
991
|
+
config: {
|
|
992
|
+
resource: "channel",
|
|
993
|
+
operation: "delete"
|
|
994
|
+
}
|
|
995
|
+
},
|
|
996
|
+
{
|
|
997
|
+
label: "Get the OAuth URL of a channel",
|
|
998
|
+
config: {
|
|
999
|
+
resource: "channel",
|
|
1000
|
+
operation: "getOAuthUrl"
|
|
1001
|
+
}
|
|
1002
|
+
},
|
|
1003
|
+
{
|
|
1004
|
+
label: "Create a connect link for a channel",
|
|
1005
|
+
config: {
|
|
1006
|
+
resource: "channel",
|
|
1007
|
+
operation: "createConnectLink"
|
|
1008
|
+
}
|
|
1009
|
+
},
|
|
1010
|
+
{
|
|
1011
|
+
label: "Get the settings and tools of a channel",
|
|
1012
|
+
config: {
|
|
1013
|
+
resource: "channel",
|
|
1014
|
+
operation: "getSettings"
|
|
1015
|
+
}
|
|
1016
|
+
},
|
|
1017
|
+
{
|
|
1018
|
+
label: "Trigger a tool of a channel",
|
|
1019
|
+
config: {
|
|
1020
|
+
resource: "channel",
|
|
1021
|
+
operation: "triggerTool"
|
|
1022
|
+
}
|
|
1023
|
+
},
|
|
1024
|
+
{
|
|
1025
|
+
label: "Check the connection",
|
|
1026
|
+
config: {
|
|
1027
|
+
resource: "channel",
|
|
1028
|
+
operation: "checkConnection"
|
|
1029
|
+
}
|
|
1030
|
+
},
|
|
1031
|
+
{
|
|
1032
|
+
label: "Get the connected account",
|
|
1033
|
+
config: {
|
|
1034
|
+
resource: "channel",
|
|
1035
|
+
operation: "getAccount"
|
|
1036
|
+
}
|
|
1037
|
+
},
|
|
1038
|
+
{
|
|
1039
|
+
label: "Find a free slot of a channel",
|
|
1040
|
+
config: {
|
|
1041
|
+
resource: "channel",
|
|
1042
|
+
operation: "findSlot"
|
|
1043
|
+
}
|
|
1044
|
+
},
|
|
1045
|
+
{
|
|
1046
|
+
label: "Get many groups",
|
|
1047
|
+
config: {
|
|
1048
|
+
resource: "group",
|
|
1049
|
+
operation: "getAll"
|
|
1050
|
+
}
|
|
1051
|
+
},
|
|
1052
|
+
{
|
|
1053
|
+
label: "Get the analytics of a channel",
|
|
1054
|
+
config: {
|
|
1055
|
+
resource: "analytics",
|
|
1056
|
+
operation: "getPlatform"
|
|
1057
|
+
}
|
|
1058
|
+
},
|
|
1059
|
+
{
|
|
1060
|
+
label: "Get the analytics of a post",
|
|
1061
|
+
config: {
|
|
1062
|
+
resource: "analytics",
|
|
1063
|
+
operation: "getPost"
|
|
1064
|
+
}
|
|
1065
|
+
},
|
|
1066
|
+
{
|
|
1067
|
+
label: "Get many notifications",
|
|
1068
|
+
config: {
|
|
1069
|
+
resource: "notification",
|
|
1070
|
+
operation: "getAll"
|
|
1071
|
+
}
|
|
1072
|
+
},
|
|
1073
|
+
{
|
|
1074
|
+
label: "Upload a file",
|
|
1075
|
+
config: {
|
|
1076
|
+
resource: "media",
|
|
1077
|
+
operation: "uploadFile"
|
|
1078
|
+
}
|
|
1079
|
+
},
|
|
1080
|
+
{
|
|
1081
|
+
label: "Upload a file from a URL",
|
|
1082
|
+
config: {
|
|
1083
|
+
resource: "media",
|
|
1084
|
+
operation: "uploadFromUrl"
|
|
1085
|
+
}
|
|
1086
|
+
},
|
|
1087
|
+
{
|
|
1088
|
+
label: "Get the status of a media file",
|
|
1089
|
+
config: {
|
|
1090
|
+
resource: "media",
|
|
1091
|
+
operation: "getStatus"
|
|
1092
|
+
}
|
|
1093
|
+
},
|
|
1094
|
+
{
|
|
1095
|
+
label: "Get many media files",
|
|
1096
|
+
config: {
|
|
1097
|
+
resource: "media",
|
|
1098
|
+
operation: "getAll"
|
|
1099
|
+
}
|
|
1100
|
+
},
|
|
1101
|
+
{
|
|
1102
|
+
label: "Generate a video",
|
|
1103
|
+
config: {
|
|
1104
|
+
resource: "video",
|
|
1105
|
+
operation: "generate"
|
|
1106
|
+
}
|
|
1107
|
+
},
|
|
1108
|
+
{
|
|
1109
|
+
label: "Run a video function",
|
|
1110
|
+
config: {
|
|
1111
|
+
resource: "video",
|
|
1112
|
+
operation: "runFunction"
|
|
1113
|
+
}
|
|
1114
|
+
},
|
|
1115
|
+
{
|
|
1116
|
+
label: "Start a clipping",
|
|
1117
|
+
config: {
|
|
1118
|
+
resource: "clipping",
|
|
1119
|
+
operation: "create"
|
|
1120
|
+
}
|
|
1121
|
+
},
|
|
1122
|
+
{
|
|
1123
|
+
label: "Get a clipping",
|
|
1124
|
+
config: {
|
|
1125
|
+
resource: "clipping",
|
|
1126
|
+
operation: "get"
|
|
1127
|
+
}
|
|
1128
|
+
},
|
|
1129
|
+
{
|
|
1130
|
+
label: "Get many clippings",
|
|
1131
|
+
config: {
|
|
1132
|
+
resource: "clipping",
|
|
1133
|
+
operation: "getAll"
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
],
|
|
1137
|
+
icon: "Share2Icon",
|
|
1138
|
+
iconUrl: POSTIZ_ICON,
|
|
1139
|
+
config: postizConfig,
|
|
1140
|
+
defaultConfig: {
|
|
1141
|
+
resource: "post",
|
|
1142
|
+
operation: "create",
|
|
1143
|
+
type: "now",
|
|
1144
|
+
shortLink: false,
|
|
1145
|
+
status: "schedule",
|
|
1146
|
+
lookbackDays: 7,
|
|
1147
|
+
page: 1,
|
|
1148
|
+
binaryProperty: "data",
|
|
1149
|
+
adjust: false,
|
|
1150
|
+
videoType: "image-text-slides",
|
|
1151
|
+
output: "vertical",
|
|
1152
|
+
clipCount: 5,
|
|
1153
|
+
clipFit: "blur",
|
|
1154
|
+
timeoutMs: 3e4
|
|
1155
|
+
},
|
|
1156
|
+
credentialTypes: [POSTIZ_CREDENTIAL],
|
|
1157
|
+
ports: {
|
|
1158
|
+
in: ["in"],
|
|
1159
|
+
out: ["out"]
|
|
1160
|
+
},
|
|
1161
|
+
subtitle: (config) => typeof config.operation === "string" ? `${String(config.resource ?? "post")}: ${config.operation}` : void 0,
|
|
1162
|
+
async run({ config, input, credential, signal }) {
|
|
1163
|
+
return {
|
|
1164
|
+
port: "out",
|
|
1165
|
+
data: await callPostiz(postizAccess(credential), buildRequest(config, input), {
|
|
1166
|
+
signal,
|
|
1167
|
+
timeoutMs: config.timeoutMs
|
|
1168
|
+
}) ?? { success: true }
|
|
1169
|
+
};
|
|
1170
|
+
}
|
|
1171
|
+
})];
|
|
1172
|
+
const credentialTypes = [postizCredential];
|
|
1173
|
+
exports.credentialTypes = credentialTypes;
|
|
1174
|
+
exports.nodes = nodes;
|