@zerodot/hootsuite 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/dist/index.cjs ADDED
@@ -0,0 +1,1325 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let zod = require("zod");
3
+ let _zerodot_node_sdk = require("@zerodot/node-sdk");
4
+ // src/api.ts
5
+ const HOOTSUITE_CREDENTIAL = "hootsuite.oauth2";
6
+ const HOOTSUITE_HOST = "https://platform.hootsuite.com";
7
+ /** The most items that "return all" collects. A node output has a size limit too. */
8
+ const MAX_ITEMS = 5e3;
9
+ /** The most that Hootsuite sends in one page of messages. */
10
+ const PAGE_SIZE = 100;
11
+ /** The `Authorization` value of a Hootsuite credential. It is a Bearer token. */
12
+ function hootsuiteAccess(credential) {
13
+ if (!credential || credential.type !== "hootsuite.oauth2") throw new Error("The node needs a Hootsuite credential");
14
+ const { accessToken } = credential.data;
15
+ if (typeof accessToken !== "string" || accessToken === "") throw new Error("The Hootsuite credential is not connected to an account yet");
16
+ return { authorization: `Bearer ${accessToken}` };
17
+ }
18
+ /** The full URL of a request, with the query. A value that is empty is not sent. */
19
+ function buildUrl(path, query = {}) {
20
+ const url = new URL(path, HOOTSUITE_HOST);
21
+ for (const [key, value] of Object.entries(query)) if (value !== void 0 && value !== "") url.searchParams.set(key, String(value));
22
+ return url.toString();
23
+ }
24
+ function describe(status, answer) {
25
+ const errors = answer?.errors;
26
+ const oauth = answer?.error_description ?? answer?.error;
27
+ return `Hootsuite request failed (${status}): ${errors?.map((error) => error.code ? `${error.message} (code ${error.code})` : error.message).filter(Boolean).join("; ") || (typeof oauth === "string" ? oauth : "") || (typeof answer?.detail === "string" ? answer.detail : "") || "no message"}.${status === 429 ? " The rate limit is reached. Try again later." : ""}`;
28
+ }
29
+ /** One call. Returns the JSON answer, or `null` when the answer has no body. */
30
+ async function callHootsuite(access, request, options) {
31
+ const hasBody = request.body !== void 0;
32
+ const response = await fetch(buildUrl(request.path, request.query), {
33
+ method: request.method,
34
+ headers: {
35
+ authorization: access.authorization,
36
+ accept: "application/json",
37
+ "user-agent": "zerodot",
38
+ ...hasBody && { "content-type": "application/json;charset=utf-8" }
39
+ },
40
+ ...hasBody && { body: JSON.stringify(request.body) },
41
+ redirect: "error",
42
+ signal: AbortSignal.any([options.signal, AbortSignal.timeout(options.timeoutMs)])
43
+ });
44
+ const text = await response.text();
45
+ let answer = null;
46
+ if (text !== "") try {
47
+ const parsed = JSON.parse(text);
48
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) answer = parsed;
49
+ } catch {
50
+ answer = null;
51
+ }
52
+ if (!response.ok) throw new Error(describe(response.status, answer));
53
+ return answer;
54
+ }
55
+ /**
56
+ * The result of one call. Hootsuite wraps a result in `data`. A call with no result gives
57
+ * `{ success: true }`. If some parts failed but others worked, the result is `{ data, errors }`.
58
+ * A SCIM answer has no `data` and is returned as it is.
59
+ */
60
+ function unwrap(answer) {
61
+ if (answer === null) return { success: true };
62
+ if (!("data" in answer) && !("errors" in answer)) return answer;
63
+ const { data, errors } = answer;
64
+ if (Array.isArray(errors) && errors.length > 0) {
65
+ if (data === void 0 || data === null || Array.isArray(data) && data.length === 0) throw new Error(describe(200, answer));
66
+ return {
67
+ data,
68
+ errors
69
+ };
70
+ }
71
+ if (data === void 0 || data === null) return { success: true };
72
+ return data;
73
+ }
74
+ /** A list. Follows the pages until it has `limit` items, or all items when `limit` is null. */
75
+ async function callHootsuiteList(access, request, limit, options) {
76
+ const wanted = Math.min(limit ?? 5e3, MAX_ITEMS);
77
+ const items = [];
78
+ let cursor;
79
+ let startIndex = 1;
80
+ while (items.length < wanted) {
81
+ const size = Math.min(PAGE_SIZE, wanted - items.length);
82
+ const query = request.list === "scim" ? {
83
+ ...request.query,
84
+ count: size,
85
+ startIndex
86
+ } : {
87
+ ...request.query,
88
+ limit: size,
89
+ cursor
90
+ };
91
+ const answer = await callHootsuite(access, {
92
+ ...request,
93
+ query
94
+ }, options);
95
+ if (request.list === "scim") {
96
+ const resources = answer?.Resources;
97
+ if (!Array.isArray(resources)) throw new Error("Hootsuite sent no list of resources");
98
+ items.push(...resources);
99
+ const total = typeof answer?.totalResults === "number" ? answer.totalResults : 0;
100
+ startIndex += resources.length;
101
+ if (resources.length === 0 || startIndex > total) break;
102
+ } else {
103
+ const page = answer?.data;
104
+ if (!Array.isArray(page)) throw new Error("Hootsuite sent no list");
105
+ items.push(...page);
106
+ const next = answer.metadata?.cursor?.next;
107
+ if (!next) break;
108
+ cursor = next;
109
+ }
110
+ }
111
+ return items.slice(0, wanted);
112
+ }
113
+ // src/icon.ts
114
+ const HOOTSUITE_ICON = (0, _zerodot_node_sdk.fileIcon)(require("url").pathToFileURL(__filename).href, "../hootsuite.svg");
115
+ // src/credential.ts
116
+ const TIMEOUT_MS = 1e4;
117
+ /** `offline` gives a refresh token. Add `analytics:read` for analytics access. */
118
+ const DEFAULT_SCOPES = ["offline"];
119
+ /** Fields that only the server writes, after the user connects the account. */
120
+ const OAUTH2_TOKEN_FIELDS = [
121
+ "accessToken",
122
+ "refreshToken",
123
+ "expiresAt",
124
+ "tokenType",
125
+ "grantedScope"
126
+ ];
127
+ /** Text fields for the token. The user cannot set them. */
128
+ const oauth2TokenShape = {
129
+ accessToken: zod.z.string().min(1).optional(),
130
+ refreshToken: zod.z.string().min(1).optional(),
131
+ /** ISO 8601 time. */
132
+ expiresAt: zod.z.iso.datetime().optional(),
133
+ tokenType: zod.z.string().min(1).optional(),
134
+ grantedScope: zod.z.string().optional()
135
+ };
136
+ const text = (value) => typeof value === "string" && value !== "" ? value : void 0;
137
+ function hootsuiteOAuth2(data) {
138
+ const scope = text(data.scope);
139
+ return {
140
+ authUrl: "https://platform.hootsuite.com/oauth2/auth",
141
+ tokenUrl: "https://platform.hootsuite.com/oauth2/token",
142
+ scopes: scope ? scope.split(/[\s,]+/).filter(Boolean) : DEFAULT_SCOPES,
143
+ authentication: "header"
144
+ };
145
+ }
146
+ async function check(credential) {
147
+ await callHootsuite(hootsuiteAccess(credential), {
148
+ method: "GET",
149
+ path: "/v1/me"
150
+ }, {
151
+ signal: AbortSignal.timeout(TIMEOUT_MS),
152
+ timeoutMs: TIMEOUT_MS
153
+ });
154
+ }
155
+ const hootsuiteOAuth2Credential = {
156
+ type: HOOTSUITE_CREDENTIAL,
157
+ label: "Hootsuite OAuth2",
158
+ fields: zod.z.object({
159
+ /** From your Hootsuite developer app (partner access). */
160
+ clientId: zod.z.string().min(1),
161
+ clientSecret: zod.z.string().min(1),
162
+ /** Scopes, separated by commas or spaces. Empty means `offline`. */
163
+ scope: zod.z.string().optional().meta({ placeholder: "offline" }),
164
+ ...oauth2TokenShape
165
+ }),
166
+ secretFields: [
167
+ "clientSecret",
168
+ "accessToken",
169
+ "refreshToken"
170
+ ],
171
+ serverFields: [...OAUTH2_TOKEN_FIELDS],
172
+ oauth2: hootsuiteOAuth2,
173
+ icon: "Key01Icon",
174
+ iconUrl: HOOTSUITE_ICON,
175
+ test: check
176
+ };
177
+ // src/config.ts
178
+ const RESOURCES = [
179
+ "me",
180
+ "message",
181
+ "comment",
182
+ "media",
183
+ "socialProfile",
184
+ "member",
185
+ "organization",
186
+ "team",
187
+ "scimUser",
188
+ "scimGroup",
189
+ "scimResourceType"
190
+ ];
191
+ const OPERATIONS_OF = {
192
+ me: [
193
+ "get",
194
+ "getOrganizations",
195
+ "getSocialProfiles",
196
+ "getAdAccounts"
197
+ ],
198
+ message: [
199
+ "schedule",
200
+ "get",
201
+ "getAll",
202
+ "delete",
203
+ "approve",
204
+ "reject",
205
+ "getHistory"
206
+ ],
207
+ comment: [
208
+ "get",
209
+ "approve",
210
+ "reject"
211
+ ],
212
+ media: [
213
+ "createUploadUrl",
214
+ "upload",
215
+ "get"
216
+ ],
217
+ socialProfile: [
218
+ "get",
219
+ "getAll",
220
+ "getTeams"
221
+ ],
222
+ member: [
223
+ "get",
224
+ "create",
225
+ "getOrganizations"
226
+ ],
227
+ organization: [
228
+ "getMembers",
229
+ "removeMember",
230
+ "getMemberPermissions",
231
+ "getMemberTeams",
232
+ "getMemberSocialProfiles",
233
+ "getMemberSocialProfilePermissions"
234
+ ],
235
+ team: [
236
+ "get",
237
+ "getAll",
238
+ "create",
239
+ "addMember",
240
+ "getMembers",
241
+ "getMemberPermissions",
242
+ "getSocialProfiles"
243
+ ],
244
+ scimUser: [
245
+ "create",
246
+ "get",
247
+ "getAll",
248
+ "replace",
249
+ "update"
250
+ ],
251
+ scimGroup: [
252
+ "create",
253
+ "get",
254
+ "getAll",
255
+ "replace",
256
+ "update"
257
+ ],
258
+ scimResourceType: ["getAll"]
259
+ };
260
+ const ALL_OPERATIONS = [...new Set(Object.values(OPERATIONS_OF).flat())];
261
+ /** Show a field only for these operations of a resource. */
262
+ const on = (resource, ...operations) => ({ showWhen: {
263
+ resource: [resource],
264
+ operation: operations
265
+ } });
266
+ /** The lists that follow pages. */
267
+ const LIST_SHOW = {
268
+ resource: [
269
+ "message",
270
+ "scimUser",
271
+ "scimGroup"
272
+ ],
273
+ operation: ["getAll"]
274
+ };
275
+ const REVIEWER_TYPES = ["MEMBER", "EXTERNAL"];
276
+ const LANGUAGES = [
277
+ "en",
278
+ "ja",
279
+ "fr",
280
+ "it",
281
+ "es",
282
+ "de",
283
+ "pt_BR",
284
+ "pl",
285
+ "id",
286
+ "zh_CN",
287
+ "zh_HK",
288
+ "zh_TW",
289
+ "nl",
290
+ "ko",
291
+ "ar",
292
+ "ru",
293
+ "th",
294
+ "tr"
295
+ ];
296
+ const VIDEO_CATEGORIES = [
297
+ "BEAUTY_FASHION",
298
+ "BUSINESS",
299
+ "CARS_TRUCKS",
300
+ "COMEDY",
301
+ "CUTE_ANIMALS",
302
+ "ENTERTAINMENT",
303
+ "FAMILY",
304
+ "FOOD_HEALTH",
305
+ "HOME",
306
+ "LIFESTYLE",
307
+ "MUSIC",
308
+ "NEWS",
309
+ "POLITICS",
310
+ "SCIENCE",
311
+ "SPORTS",
312
+ "TECHNOLOGY",
313
+ "VIDEO_GAMING",
314
+ "OTHER"
315
+ ];
316
+ const hootsuiteConfig = zod.z.object({
317
+ resource: zod.z.enum(RESOURCES).default("message").meta({
318
+ labels: {
319
+ me: "Me",
320
+ message: "Message",
321
+ comment: "Comment",
322
+ media: "Media",
323
+ socialProfile: "Social Profile",
324
+ member: "Member",
325
+ organization: "Organization",
326
+ team: "Team",
327
+ scimUser: "SCIM User",
328
+ scimGroup: "SCIM Group",
329
+ scimResourceType: "SCIM Resource Type"
330
+ },
331
+ hints: {
332
+ me: "Get the member that is signed in, and the organizations and profiles of this member",
333
+ message: "Schedule, get, list, delete, and review messages",
334
+ comment: "Get, approve, or reject a comment that needs review",
335
+ media: "Upload a file and get the status of an upload",
336
+ socialProfile: "Get social profiles and the teams of a profile",
337
+ member: "Get or create a member",
338
+ organization: "Members of an organization and what they can do",
339
+ team: "Get or create teams, and work with the members of a team",
340
+ scimUser: "Manage users with SCIM 2.0",
341
+ scimGroup: "Manage groups (teams) with SCIM 2.0",
342
+ scimResourceType: "Get the SCIM resource types"
343
+ }
344
+ }),
345
+ operation: zod.z.enum(ALL_OPERATIONS).default("getAll").meta({
346
+ labels: {
347
+ get: "Get",
348
+ getAll: "Get Many",
349
+ create: "Create",
350
+ replace: "Replace",
351
+ update: "Update",
352
+ delete: "Delete",
353
+ schedule: "Schedule",
354
+ approve: "Approve",
355
+ reject: "Reject",
356
+ getHistory: "Get Review History",
357
+ getOrganizations: "Get Organizations",
358
+ getSocialProfiles: "Get Social Profiles",
359
+ getAdAccounts: "Get Ad Accounts",
360
+ createUploadUrl: "Create Upload URL",
361
+ upload: "Upload",
362
+ getTeams: "Get Teams",
363
+ getMembers: "Get Members",
364
+ removeMember: "Remove Member",
365
+ getMemberPermissions: "Get Member Permissions",
366
+ getMemberTeams: "Get Member Teams",
367
+ getMemberSocialProfiles: "Get Member Social Profiles",
368
+ getMemberSocialProfilePermissions: "Get Member Social Profile Permissions",
369
+ addMember: "Add Member"
370
+ },
371
+ hints: {
372
+ get: "Get one item",
373
+ getAll: "Get many items",
374
+ create: "Create a new item",
375
+ replace: "Replace an item with the new data",
376
+ update: "Change some fields of an item",
377
+ delete: "Delete an item",
378
+ schedule: "Schedule a message on one or more social profiles",
379
+ approve: "Approve an item that waits for review",
380
+ reject: "Reject an item that waits for review",
381
+ getHistory: "Get the review history of a message",
382
+ getOrganizations: "Get organizations",
383
+ getSocialProfiles: "Get social profiles",
384
+ getAdAccounts: "Get ad accounts of the member in an organization",
385
+ createUploadUrl: "Get a URL to upload a file to. You upload the file yourself",
386
+ upload: "Upload binary data from the input, and wait until it is ready",
387
+ getTeams: "Get teams",
388
+ getMembers: "Get members",
389
+ removeMember: "Remove a member from an organization",
390
+ getMemberPermissions: "Get the permissions of a member",
391
+ getMemberTeams: "Get the teams of a member in an organization",
392
+ getMemberSocialProfiles: "Get the social profiles of a member in an organization",
393
+ getMemberSocialProfilePermissions: "Get what a member can do with one social profile in an organization",
394
+ addMember: "Add a member to a team"
395
+ }
396
+ }),
397
+ organizationId: zod.z.string().optional().meta({
398
+ showWhen: {
399
+ resource: [
400
+ "organization",
401
+ "team",
402
+ "me"
403
+ ],
404
+ operation: [
405
+ "getMembers",
406
+ "removeMember",
407
+ "getMemberPermissions",
408
+ "getMemberTeams",
409
+ "getMemberSocialProfiles",
410
+ "getMemberSocialProfilePermissions",
411
+ "getAll",
412
+ "create",
413
+ "addMember",
414
+ "getMemberPermissions",
415
+ "getSocialProfiles",
416
+ "getAdAccounts"
417
+ ]
418
+ },
419
+ title: "Organization ID",
420
+ description: "The ID of the organization"
421
+ }),
422
+ teamId: zod.z.string().optional().meta({
423
+ showWhen: {
424
+ resource: ["team"],
425
+ operation: [
426
+ "get",
427
+ "addMember",
428
+ "getMembers",
429
+ "getMemberPermissions",
430
+ "getSocialProfiles"
431
+ ]
432
+ },
433
+ title: "Team ID"
434
+ }),
435
+ memberId: zod.z.string().optional().meta({
436
+ showWhen: {
437
+ resource: [
438
+ "member",
439
+ "organization",
440
+ "team",
441
+ "scimUser"
442
+ ],
443
+ operation: [
444
+ "get",
445
+ "getOrganizations",
446
+ "removeMember",
447
+ "getMemberPermissions",
448
+ "getMemberTeams",
449
+ "getMemberSocialProfiles",
450
+ "getMemberSocialProfilePermissions",
451
+ "addMember",
452
+ "replace",
453
+ "update"
454
+ ]
455
+ },
456
+ title: "Member ID"
457
+ }),
458
+ socialProfileId: zod.z.string().optional().meta({
459
+ showWhen: {
460
+ resource: ["socialProfile", "organization"],
461
+ operation: [
462
+ "get",
463
+ "getTeams",
464
+ "getMemberSocialProfilePermissions"
465
+ ]
466
+ },
467
+ title: "Social Profile ID"
468
+ }),
469
+ messageId: zod.z.string().optional().meta({
470
+ ...on("message", "get", "delete", "approve", "reject", "getHistory"),
471
+ title: "Message ID"
472
+ }),
473
+ commentId: zod.z.string().optional().meta({
474
+ ...on("comment", "get", "approve", "reject"),
475
+ title: "Comment ID"
476
+ }),
477
+ mediaId: zod.z.string().optional().meta({
478
+ ...on("media", "get"),
479
+ title: "Media ID"
480
+ }),
481
+ groupId: zod.z.string().optional().meta({
482
+ ...on("scimGroup", "get", "replace", "update"),
483
+ title: "Group ID"
484
+ }),
485
+ text: zod.z.string().optional().meta({
486
+ ...on("message", "schedule"),
487
+ ui: "textarea",
488
+ description: "The text of the post"
489
+ }),
490
+ socialProfileIds: zod.z.string().optional().meta({
491
+ ...on("message", "schedule", "getAll"),
492
+ title: "Social Profile IDs",
493
+ description: "Social profile IDs with commas between. To schedule: needed. To list: empty means all"
494
+ }),
495
+ scheduledSendTime: zod.z.string().optional().meta({
496
+ ...on("message", "schedule"),
497
+ title: "Send Time",
498
+ description: "Time to send, in ISO 8601 format with a UTC offset, for example 2030-01-01T10:00:00Z. Empty means send now. A video must be at least 15 minutes in the future"
499
+ }),
500
+ mediaIds: zod.z.string().optional().meta({
501
+ ...on("message", "schedule"),
502
+ title: "Media IDs",
503
+ description: "IDs of media that you uploaded, with commas between. The media must be ready"
504
+ }),
505
+ mediaUrls: zod.z.string().optional().meta({
506
+ ...on("message", "schedule"),
507
+ title: "Media URLs",
508
+ description: "Public URLs of images, with commas between. Hootsuite only allows ow.ly URLs here"
509
+ }),
510
+ binaryPropertyName: zod.z.string().optional().meta({
511
+ showWhen: {
512
+ resource: ["message", "media"],
513
+ operation: ["schedule", "upload"]
514
+ },
515
+ title: "Binary Property",
516
+ description: "Name of the binary property in the input to upload. For a message: empty means no upload. For media: empty means data"
517
+ }),
518
+ webhookUrls: zod.z.string().optional().meta({
519
+ ...on("message", "schedule"),
520
+ title: "Webhook URLs",
521
+ description: "URLs with commas between. Hootsuite calls them when the message state changes"
522
+ }),
523
+ tags: zod.z.string().optional().meta({
524
+ ...on("message", "schedule"),
525
+ description: "Tags with commas between. The profiles must belong to your organization"
526
+ }),
527
+ emailNotification: zod.z.boolean().optional().meta({
528
+ ...on("message", "schedule"),
529
+ description: "Send an email to the author when the message is sent"
530
+ }),
531
+ latitude: zod.z.number().min(-90).max(90).optional().meta(on("message", "schedule")),
532
+ longitude: zod.z.number().min(-180).max(180).optional().meta(on("message", "schedule")),
533
+ facebookVideoTitle: zod.z.string().optional().meta({
534
+ ...on("message", "schedule"),
535
+ title: "Facebook Video Title",
536
+ description: "Title for each video in Media IDs, for Facebook"
537
+ }),
538
+ facebookVideoCategory: zod.z.enum(VIDEO_CATEGORIES).optional().meta({
539
+ ...on("message", "schedule"),
540
+ title: "Facebook Video Category",
541
+ description: "Category for each video in Media IDs, for Facebook"
542
+ }),
543
+ targeting: zod.z.string().optional().meta({
544
+ ...on("message", "schedule"),
545
+ ui: "code",
546
+ description: "JSON object for targeting, for example {\"facebookPage\":{\"ageMin\":18}}. Keys: facebookPage, linkedInCompany, linkedInV2Company"
547
+ }),
548
+ privacy: zod.z.string().optional().meta({
549
+ ...on("message", "schedule"),
550
+ ui: "code",
551
+ description: "JSON object for privacy, for example {\"facebook\":{\"visibility\":[\"everyone\"]}}. Keys: facebook, linkedIn"
552
+ }),
553
+ extendedInfo: zod.z.string().optional().meta({
554
+ ...on("message", "schedule"),
555
+ ui: "code",
556
+ description: "JSON array for extra network data. Pinterest needs it, for example [{\"socialProfileType\":\"PINTEREST\",\"socialProfileId\":\"1\",\"data\":{\"boardId\":\"2\",\"destinationUrl\":\"https://example.com\"}}]"
557
+ }),
558
+ startTime: zod.z.string().optional().meta({
559
+ ...on("message", "getAll"),
560
+ description: "Start of the time range, in ISO 8601 format"
561
+ }),
562
+ endTime: zod.z.string().optional().meta({
563
+ ...on("message", "getAll"),
564
+ description: "End of the time range, in ISO 8601 format. At most 4 weeks after the start"
565
+ }),
566
+ state: zod.z.enum([
567
+ "",
568
+ "PENDING_APPROVAL",
569
+ "REJECTED",
570
+ "SENT",
571
+ "SCHEDULED",
572
+ "SEND_FAILED_PERMANENTLY"
573
+ ]).optional().meta({
574
+ ...on("message", "getAll"),
575
+ labels: {
576
+ "": "Any",
577
+ PENDING_APPROVAL: "Pending Approval",
578
+ REJECTED: "Rejected",
579
+ SENT: "Sent",
580
+ SCHEDULED: "Scheduled",
581
+ SEND_FAILED_PERMANENTLY: "Send Failed"
582
+ },
583
+ description: "Show only messages in this state"
584
+ }),
585
+ includeUnscheduledReviewMsgs: zod.z.boolean().optional().meta({
586
+ ...on("message", "getAll"),
587
+ title: "Include Send-Now Review Messages",
588
+ description: "Also return messages for review that Hootsuite sends now"
589
+ }),
590
+ sequenceNumber: zod.z.number().int().optional().meta({
591
+ ...on("message", "approve", "reject"),
592
+ showWhen: {
593
+ resource: ["message", "comment"],
594
+ operation: ["approve", "reject"]
595
+ },
596
+ title: "Sequence Number",
597
+ description: "The sequence number of the review step. Get it from the review history"
598
+ }),
599
+ reviewerType: zod.z.enum(REVIEWER_TYPES).optional().meta({
600
+ showWhen: {
601
+ resource: ["message", "comment"],
602
+ operation: ["approve", "reject"]
603
+ },
604
+ labels: {
605
+ MEMBER: "Member",
606
+ EXTERNAL: "External"
607
+ },
608
+ description: "Type of reviewer. Empty means Hootsuite uses its default"
609
+ }),
610
+ reason: zod.z.string().optional().meta({
611
+ showWhen: {
612
+ resource: ["message", "comment"],
613
+ operation: ["reject"]
614
+ },
615
+ description: "The reason for the rejection"
616
+ }),
617
+ mimeType: zod.z.string().optional().meta({
618
+ ...on("media", "createUploadUrl", "upload"),
619
+ title: "MIME Type",
620
+ description: "For Create Upload URL: needed, for example video/mp4. For Upload: empty means the type of the binary data"
621
+ }),
622
+ sizeBytes: zod.z.number().int().min(1).optional().meta({
623
+ ...on("media", "createUploadUrl"),
624
+ title: "Size in Bytes",
625
+ description: "The size of the file. It must match the file that you upload"
626
+ }),
627
+ waitUntilReady: zod.z.boolean().default(true).meta({
628
+ ...on("media", "upload"),
629
+ description: "Check the status until Hootsuite has processed the file"
630
+ }),
631
+ pollIntervalMs: zod.z.number().int().min(0).max(6e4).default(2e3).meta({
632
+ showWhen: {
633
+ resource: ["media", "message"],
634
+ operation: ["upload", "schedule"]
635
+ },
636
+ title: "Poll Interval (ms)",
637
+ description: "Time between two status checks of an upload"
638
+ }),
639
+ readyTimeoutSeconds: zod.z.number().int().min(1).max(3600).default(120).meta({
640
+ showWhen: {
641
+ resource: ["media", "message"],
642
+ operation: ["upload", "schedule"]
643
+ },
644
+ title: "Ready Timeout (s)",
645
+ description: "Most time to wait until an upload is ready"
646
+ }),
647
+ organizationIds: zod.z.string().optional().meta({
648
+ ...on("member", "create"),
649
+ title: "Organization IDs",
650
+ description: "Organization IDs with commas between"
651
+ }),
652
+ email: zod.z.string().optional().meta({
653
+ ...on("member", "create"),
654
+ placeholder: "name@example.com"
655
+ }),
656
+ fullName: zod.z.string().optional().meta({
657
+ ...on("member", "create"),
658
+ title: "Full Name"
659
+ }),
660
+ companyName: zod.z.string().optional().meta({
661
+ ...on("member", "create"),
662
+ title: "Company Name"
663
+ }),
664
+ bio: zod.z.string().optional().meta(on("member", "create")),
665
+ timezone: zod.z.string().optional().meta({
666
+ showWhen: {
667
+ resource: ["member", "scimUser"],
668
+ operation: ["create", "replace"]
669
+ },
670
+ description: "Timezone name, for example America/Vancouver"
671
+ }),
672
+ language: zod.z.enum(LANGUAGES).optional().meta({
673
+ showWhen: {
674
+ resource: ["member", "scimUser"],
675
+ operation: ["create", "replace"]
676
+ },
677
+ description: "Language of the member. For SCIM it is the preferred language"
678
+ }),
679
+ teamName: zod.z.string().optional().meta({
680
+ ...on("team", "create"),
681
+ title: "Team Name",
682
+ description: "2 to 200 characters"
683
+ }),
684
+ userName: zod.z.string().optional().meta({
685
+ ...on("scimUser", "create", "replace"),
686
+ title: "User Name",
687
+ description: "The unique user name. Usually the email address"
688
+ }),
689
+ displayName: zod.z.string().optional().meta({
690
+ showWhen: {
691
+ resource: ["scimUser", "scimGroup"],
692
+ operation: ["create", "replace"]
693
+ },
694
+ title: "Display Name"
695
+ }),
696
+ givenName: zod.z.string().optional().meta({
697
+ ...on("scimUser", "create", "replace"),
698
+ title: "Given Name"
699
+ }),
700
+ familyName: zod.z.string().optional().meta({
701
+ ...on("scimUser", "create", "replace"),
702
+ title: "Family Name"
703
+ }),
704
+ scimEmail: zod.z.string().optional().meta({
705
+ ...on("scimUser", "create", "replace"),
706
+ title: "Email"
707
+ }),
708
+ scimTitle: zod.z.string().optional().meta({
709
+ ...on("scimUser", "create", "replace"),
710
+ title: "Job Title"
711
+ }),
712
+ active: zod.z.boolean().default(true).meta({
713
+ ...on("scimUser", "create", "replace"),
714
+ description: "If off, the user is inactive"
715
+ }),
716
+ groupIds: zod.z.string().optional().meta({
717
+ ...on("scimUser", "create", "replace"),
718
+ title: "Group IDs",
719
+ description: "Group IDs with commas between"
720
+ }),
721
+ memberIds: zod.z.string().optional().meta({
722
+ ...on("scimGroup", "create", "replace"),
723
+ title: "Member IDs",
724
+ description: "Member IDs with commas between"
725
+ }),
726
+ patchOperations: zod.z.string().optional().meta({
727
+ ...on("scimUser", "update"),
728
+ showWhen: {
729
+ resource: ["scimUser", "scimGroup"],
730
+ operation: ["update"]
731
+ },
732
+ ui: "code",
733
+ title: "Operations",
734
+ description: "JSON array of SCIM patch operations, for example [{\"op\":\"replace\",\"path\":\"active\",\"value\":false}]"
735
+ }),
736
+ scimFilter: zod.z.string().optional().meta({
737
+ showWhen: {
738
+ resource: ["scimUser", "scimGroup"],
739
+ operation: ["getAll"]
740
+ },
741
+ title: "Filter",
742
+ description: "SCIM filter, for example userName eq \"name@example.com\""
743
+ }),
744
+ returnAll: zod.z.boolean().default(false).meta({ showWhen: LIST_SHOW }),
745
+ limit: zod.z.number().int().min(1).max(5e3).default(50).meta({ showWhen: {
746
+ ...LIST_SHOW,
747
+ returnAll: [false]
748
+ } }),
749
+ timeoutMs: zod.z.number().int().min(1).max(3e5).default(3e4)
750
+ }).superRefine((config, context) => {
751
+ if (!OPERATIONS_OF[config.resource].includes(config.operation)) context.addIssue({
752
+ code: "custom",
753
+ path: ["operation"],
754
+ message: `"${config.operation}" is not an operation of "${config.resource}"`
755
+ });
756
+ });
757
+ // src/media.ts
758
+ const asInfo = (answer) => {
759
+ const data = answer?.data;
760
+ return typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
761
+ };
762
+ const sleep = (ms, signal) => new Promise((resolve, reject) => {
763
+ if (signal.aborted) return reject(signal.reason);
764
+ const timer = setTimeout(resolve, ms);
765
+ signal.addEventListener("abort", () => {
766
+ clearTimeout(timer);
767
+ reject(signal.reason);
768
+ }, { once: true });
769
+ });
770
+ /**
771
+ * The upload flow of Hootsuite: ask for an upload URL, `PUT` the bytes to it, and check the
772
+ * status until the media is `READY`. Returns the media ID and the last known state.
773
+ */
774
+ async function uploadMedia(access, input, settings, options) {
775
+ const binary = (0, _zerodot_node_sdk.readBinary)(input, settings.property);
776
+ const mimeType = settings.mimeType?.trim() || binary.mimeType || "application/octet-stream";
777
+ const bytes = new Uint8Array(Buffer.from(binary.data, "base64"));
778
+ if (bytes.byteLength === 0) throw new Error("The binary data is empty");
779
+ const created = asInfo(await callHootsuite(access, {
780
+ method: "POST",
781
+ path: "/v1/media",
782
+ body: {
783
+ sizeBytes: bytes.byteLength,
784
+ mimeType
785
+ }
786
+ }, options));
787
+ if (!created.id || !created.uploadUrl) throw new Error("Hootsuite sent no upload URL");
788
+ const put = await fetch(created.uploadUrl, {
789
+ method: "PUT",
790
+ headers: { "content-type": mimeType },
791
+ body: bytes,
792
+ redirect: "error",
793
+ signal: AbortSignal.any([options.signal, AbortSignal.timeout(options.timeoutMs)])
794
+ });
795
+ if (!put.ok) throw new Error(`The upload of the media failed (${put.status})`);
796
+ let state = created.state;
797
+ if (!settings.waitUntilReady) return {
798
+ id: created.id,
799
+ state
800
+ };
801
+ const deadline = Date.now() + settings.readyTimeoutSeconds * 1e3;
802
+ for (;;) {
803
+ state = asInfo(await callHootsuite(access, {
804
+ method: "GET",
805
+ path: `/v1/media/${encodeURIComponent(created.id)}`
806
+ }, options)).state;
807
+ if (state === "READY") return {
808
+ id: created.id,
809
+ state
810
+ };
811
+ if (state !== void 0 && state !== "QUEUED") throw new Error(`The media processing stopped with state "${state}"`);
812
+ if (Date.now() >= deadline) throw new Error(`The media is not ready after ${settings.readyTimeoutSeconds} seconds`);
813
+ await sleep(settings.pollIntervalMs, options.signal);
814
+ }
815
+ }
816
+ // src/request.ts
817
+ const list = (text) => {
818
+ const items = text?.split(",").map((item) => item.trim()).filter(Boolean);
819
+ return items && items.length > 0 ? items : void 0;
820
+ };
821
+ const need = (value, name, operation) => {
822
+ if (value === void 0 || value === "") throw new Error(`"${name}" is needed to ${operation}`);
823
+ return value;
824
+ };
825
+ const compact = (body) => Object.fromEntries(Object.entries(body).filter(([, value]) => value !== void 0));
826
+ function parseJson(text, name, kind) {
827
+ if (!text?.trim()) return void 0;
828
+ let value;
829
+ try {
830
+ value = JSON.parse(text);
831
+ } catch {
832
+ throw new Error(`"${name}" must be JSON`);
833
+ }
834
+ if (!(kind === "array" ? Array.isArray(value) : typeof value === "object" && value !== null && !Array.isArray(value))) throw new Error(`"${name}" must be a JSON ${kind}`);
835
+ return value;
836
+ }
837
+ const enc = encodeURIComponent;
838
+ const SCIM_USER_SCHEMA = "urn:ietf:params:scim:schemas:core:2.0:User";
839
+ const SCIM_GROUP_SCHEMA = "urn:ietf:params:scim:schemas:core:2.0:Group";
840
+ const SCIM_PATCH_SCHEMA = "urn:ietf:params:scim:api:messages:2.0:PatchOp";
841
+ /** The body of a message. `mediaIds` come from the config and from an upload of the node. */
842
+ function messageBody(c, uploadedMediaIds = []) {
843
+ const profiles = need(list(c.socialProfileIds), "socialProfileIds", "schedule a message");
844
+ const mediaIds = [...list(c.mediaIds) ?? [], ...uploadedMediaIds];
845
+ const videoOptions = c.facebookVideoTitle !== void 0 || c.facebookVideoCategory !== void 0 ? { facebook: compact({
846
+ title: c.facebookVideoTitle,
847
+ category: c.facebookVideoCategory
848
+ }) } : void 0;
849
+ const hasLocation = c.latitude !== void 0 || c.longitude !== void 0;
850
+ if (hasLocation && (c.latitude === void 0 || c.longitude === void 0)) throw new Error("\"latitude\" and \"longitude\" are both needed");
851
+ const urls = list(c.mediaUrls);
852
+ return compact({
853
+ text: c.text,
854
+ socialProfileIds: profiles,
855
+ scheduledSendTime: c.scheduledSendTime || void 0,
856
+ webhookUrls: list(c.webhookUrls),
857
+ tags: list(c.tags),
858
+ targeting: parseJson(c.targeting, "targeting", "object"),
859
+ privacy: parseJson(c.privacy, "privacy", "object"),
860
+ location: hasLocation ? {
861
+ latitude: c.latitude,
862
+ longitude: c.longitude
863
+ } : void 0,
864
+ emailNotification: c.emailNotification,
865
+ mediaUrls: urls?.map((url) => ({ url })),
866
+ media: mediaIds.length > 0 ? mediaIds.map((id) => compact({
867
+ id,
868
+ videoOptions
869
+ })) : void 0,
870
+ extendedInfo: parseJson(c.extendedInfo, "extendedInfo", "array")
871
+ });
872
+ }
873
+ function review(c, op, reject) {
874
+ return compact({
875
+ reason: reject ? need(c.reason, "reason", op) : void 0,
876
+ sequenceNumber: need(c.sequenceNumber, "sequenceNumber", op),
877
+ reviewerType: c.reviewerType
878
+ });
879
+ }
880
+ function scimUser(c, op) {
881
+ const name = compact({
882
+ givenName: c.givenName,
883
+ familyName: c.familyName
884
+ });
885
+ const groups = list(c.groupIds)?.map((value) => ({ value }));
886
+ return compact({
887
+ schemas: [SCIM_USER_SCHEMA],
888
+ userName: need(c.userName, "userName", op),
889
+ name: Object.keys(name).length > 0 ? name : void 0,
890
+ emails: c.scimEmail ? [{
891
+ primary: true,
892
+ value: c.scimEmail,
893
+ type: "work"
894
+ }] : void 0,
895
+ displayName: need(c.displayName, "displayName", op),
896
+ timezone: c.timezone,
897
+ preferredLanguage: c.language,
898
+ title: c.scimTitle,
899
+ groups,
900
+ active: c.active
901
+ });
902
+ }
903
+ function scimGroup(c, op) {
904
+ return compact({
905
+ schemas: [SCIM_GROUP_SCHEMA],
906
+ displayName: need(c.displayName, "displayName", op),
907
+ members: list(c.memberIds)?.map((value) => ({ value }))
908
+ });
909
+ }
910
+ function scimPatch(c, op) {
911
+ return {
912
+ schemas: [SCIM_PATCH_SCHEMA],
913
+ Operations: need(parseJson(c.patchOperations, "patchOperations", "array"), "patchOperations", op)
914
+ };
915
+ }
916
+ /** The API call for one operation, without the network. */
917
+ function buildRequest(c) {
918
+ const op = `${c.resource}.${c.operation}`;
919
+ const org = () => enc(need(c.organizationId, "organizationId", op));
920
+ const team = () => enc(need(c.teamId, "teamId", op));
921
+ const member = () => enc(need(c.memberId, "memberId", op));
922
+ const profile = () => enc(need(c.socialProfileId, "socialProfileId", op));
923
+ const message = () => enc(need(c.messageId, "messageId", op));
924
+ const comment = () => enc(need(c.commentId, "commentId", op));
925
+ const group = () => enc(need(c.groupId, "groupId", op));
926
+ const orgMember = () => `/v1/organizations/${org()}/members/${member()}`;
927
+ const orgTeam = () => `/v1/organizations/${org()}/teams/${team()}`;
928
+ switch (op) {
929
+ case "me.get": return {
930
+ method: "GET",
931
+ path: "/v1/me"
932
+ };
933
+ case "me.getOrganizations": return {
934
+ method: "GET",
935
+ path: "/v1/me/organizations"
936
+ };
937
+ case "me.getSocialProfiles": return {
938
+ method: "GET",
939
+ path: "/v1/me/socialProfiles"
940
+ };
941
+ case "me.getAdAccounts": return {
942
+ method: "GET",
943
+ path: "/v1/me/adAccounts",
944
+ query: { organization_id: need(c.organizationId, "organizationId", op) }
945
+ };
946
+ case "message.schedule": return {
947
+ method: "POST",
948
+ path: "/v1/messages",
949
+ body: messageBody(c)
950
+ };
951
+ case "message.get": return {
952
+ method: "GET",
953
+ path: `/v1/messages/${message()}`
954
+ };
955
+ case "message.getAll": return {
956
+ method: "GET",
957
+ path: "/v1/messages",
958
+ list: "cursor",
959
+ query: {
960
+ startTime: need(c.startTime, "startTime", op),
961
+ endTime: need(c.endTime, "endTime", op),
962
+ state: c.state || void 0,
963
+ socialProfileIds: list(c.socialProfileIds)?.join(","),
964
+ includeUnscheduledReviewMsgs: c.includeUnscheduledReviewMsgs
965
+ }
966
+ };
967
+ case "message.delete": return {
968
+ method: "DELETE",
969
+ path: `/v1/messages/${message()}`
970
+ };
971
+ case "message.approve": return {
972
+ method: "POST",
973
+ path: `/v1/messages/${message()}/approve`,
974
+ body: review(c, op, false)
975
+ };
976
+ case "message.reject": return {
977
+ method: "POST",
978
+ path: `/v1/messages/${message()}/reject`,
979
+ body: review(c, op, true)
980
+ };
981
+ case "message.getHistory": return {
982
+ method: "GET",
983
+ path: `/v1/messages/${message()}/history`
984
+ };
985
+ case "comment.get": return {
986
+ method: "GET",
987
+ path: `/v1/comments/${comment()}`
988
+ };
989
+ case "comment.approve": return {
990
+ method: "POST",
991
+ path: `/v1/comments/${comment()}/approve`,
992
+ body: review(c, op, false)
993
+ };
994
+ case "comment.reject": return {
995
+ method: "POST",
996
+ path: `/v1/comments/${comment()}/reject`,
997
+ body: review(c, op, true)
998
+ };
999
+ case "media.createUploadUrl": return {
1000
+ method: "POST",
1001
+ path: "/v1/media",
1002
+ body: {
1003
+ sizeBytes: need(c.sizeBytes, "sizeBytes", op),
1004
+ mimeType: need(c.mimeType, "mimeType", op)
1005
+ }
1006
+ };
1007
+ case "media.get": return {
1008
+ method: "GET",
1009
+ path: `/v1/media/${enc(need(c.mediaId, "mediaId", op))}`
1010
+ };
1011
+ case "socialProfile.get": return {
1012
+ method: "GET",
1013
+ path: `/v1/socialProfiles/${profile()}`
1014
+ };
1015
+ case "socialProfile.getAll": return {
1016
+ method: "GET",
1017
+ path: "/v1/socialProfiles"
1018
+ };
1019
+ case "socialProfile.getTeams": return {
1020
+ method: "GET",
1021
+ path: `/v1/socialProfiles/${profile()}/teams`
1022
+ };
1023
+ case "member.get": return {
1024
+ method: "GET",
1025
+ path: `/v1/members/${member()}`
1026
+ };
1027
+ case "member.create": {
1028
+ const ids = need(list(c.organizationIds), "organizationIds", op).map((id) => {
1029
+ const number = Number(id);
1030
+ if (!Number.isInteger(number)) throw new Error("\"organizationIds\" must be numbers");
1031
+ return number;
1032
+ });
1033
+ return {
1034
+ method: "POST",
1035
+ path: "/v1/members",
1036
+ body: compact({
1037
+ organizationIds: ids,
1038
+ email: need(c.email, "email", op),
1039
+ fullName: need(c.fullName, "fullName", op),
1040
+ companyName: c.companyName,
1041
+ bio: c.bio,
1042
+ timezone: c.timezone,
1043
+ language: c.language
1044
+ })
1045
+ };
1046
+ }
1047
+ case "member.getOrganizations": return {
1048
+ method: "GET",
1049
+ path: `/v1/members/${member()}/organizations`
1050
+ };
1051
+ case "organization.getMembers": return {
1052
+ method: "GET",
1053
+ path: `/v1/organizations/${org()}/members`
1054
+ };
1055
+ case "organization.removeMember": return {
1056
+ method: "DELETE",
1057
+ path: orgMember()
1058
+ };
1059
+ case "organization.getMemberPermissions": return {
1060
+ method: "GET",
1061
+ path: `${orgMember()}/permissions`
1062
+ };
1063
+ case "organization.getMemberTeams": return {
1064
+ method: "GET",
1065
+ path: `${orgMember()}/teams`
1066
+ };
1067
+ case "organization.getMemberSocialProfiles": return {
1068
+ method: "GET",
1069
+ path: `${orgMember()}/socialProfiles`
1070
+ };
1071
+ case "organization.getMemberSocialProfilePermissions": return {
1072
+ method: "GET",
1073
+ path: `${orgMember()}/socialProfiles/${profile()}/permissions`
1074
+ };
1075
+ case "team.get": return {
1076
+ method: "GET",
1077
+ path: `/v1/teams/${team()}`
1078
+ };
1079
+ case "team.getAll": return {
1080
+ method: "GET",
1081
+ path: `/v1/organizations/${org()}/teams`
1082
+ };
1083
+ case "team.create": return {
1084
+ method: "POST",
1085
+ path: `/v1/organizations/${org()}/teams`,
1086
+ body: { teamName: need(c.teamName, "teamName", op) }
1087
+ };
1088
+ case "team.addMember": return {
1089
+ method: "POST",
1090
+ path: `${orgTeam()}/members/${member()}`
1091
+ };
1092
+ case "team.getMembers": return {
1093
+ method: "GET",
1094
+ path: `${orgTeam()}/members`
1095
+ };
1096
+ case "team.getMemberPermissions": return {
1097
+ method: "GET",
1098
+ path: `${orgTeam()}/members/${member()}/permissions`
1099
+ };
1100
+ case "team.getSocialProfiles": return {
1101
+ method: "GET",
1102
+ path: `${orgTeam()}/socialProfiles`
1103
+ };
1104
+ case "scimUser.create": return {
1105
+ method: "POST",
1106
+ path: "/scim/v2/Users",
1107
+ body: scimUser(c, op)
1108
+ };
1109
+ case "scimUser.get": return {
1110
+ method: "GET",
1111
+ path: `/scim/v2/Users/${member()}`
1112
+ };
1113
+ case "scimUser.getAll": return {
1114
+ method: "GET",
1115
+ path: "/scim/v2/Users",
1116
+ list: "scim",
1117
+ query: { filter: c.scimFilter }
1118
+ };
1119
+ case "scimUser.replace": return {
1120
+ method: "PUT",
1121
+ path: `/scim/v2/Users/${member()}`,
1122
+ body: scimUser(c, op)
1123
+ };
1124
+ case "scimUser.update": return {
1125
+ method: "PATCH",
1126
+ path: `/scim/v2/Users/${member()}`,
1127
+ body: scimPatch(c, op)
1128
+ };
1129
+ case "scimGroup.create": return {
1130
+ method: "POST",
1131
+ path: "/scim/v2/Groups",
1132
+ body: scimGroup(c, op)
1133
+ };
1134
+ case "scimGroup.get": return {
1135
+ method: "GET",
1136
+ path: `/scim/v2/Groups/${group()}`
1137
+ };
1138
+ case "scimGroup.getAll": return {
1139
+ method: "GET",
1140
+ path: "/scim/v2/Groups",
1141
+ list: "scim",
1142
+ query: { filter: c.scimFilter }
1143
+ };
1144
+ case "scimGroup.replace": return {
1145
+ method: "PUT",
1146
+ path: `/scim/v2/Groups/${group()}`,
1147
+ body: scimGroup(c, op)
1148
+ };
1149
+ case "scimGroup.update": return {
1150
+ method: "PATCH",
1151
+ path: `/scim/v2/Groups/${group()}`,
1152
+ body: scimPatch(c, op)
1153
+ };
1154
+ case "scimResourceType.getAll": return {
1155
+ method: "GET",
1156
+ path: "/scim/v2/ResourceTypes"
1157
+ };
1158
+ }
1159
+ throw new Error(`Unknown Hootsuite operation "${op}" (media.upload runs in the node)`);
1160
+ }
1161
+ // src/index.ts
1162
+ const nodes = [(0, _zerodot_node_sdk.defineNode)({
1163
+ type: "hootsuite.api",
1164
+ label: "Hootsuite",
1165
+ description: "Schedule posts, upload media, and manage teams and members in Hootsuite",
1166
+ category: "integration",
1167
+ app: "Hootsuite",
1168
+ actions: [
1169
+ {
1170
+ label: "Schedule a message",
1171
+ config: {
1172
+ resource: "message",
1173
+ operation: "schedule"
1174
+ }
1175
+ },
1176
+ {
1177
+ label: "Get a message",
1178
+ config: {
1179
+ resource: "message",
1180
+ operation: "get"
1181
+ }
1182
+ },
1183
+ {
1184
+ label: "Get many messages",
1185
+ config: {
1186
+ resource: "message",
1187
+ operation: "getAll"
1188
+ }
1189
+ },
1190
+ {
1191
+ label: "Delete a message",
1192
+ config: {
1193
+ resource: "message",
1194
+ operation: "delete"
1195
+ }
1196
+ },
1197
+ {
1198
+ label: "Approve a message",
1199
+ config: {
1200
+ resource: "message",
1201
+ operation: "approve"
1202
+ }
1203
+ },
1204
+ {
1205
+ label: "Reject a message",
1206
+ config: {
1207
+ resource: "message",
1208
+ operation: "reject"
1209
+ }
1210
+ },
1211
+ {
1212
+ label: "Get the review history of a message",
1213
+ config: {
1214
+ resource: "message",
1215
+ operation: "getHistory"
1216
+ }
1217
+ },
1218
+ {
1219
+ label: "Upload media",
1220
+ config: {
1221
+ resource: "media",
1222
+ operation: "upload"
1223
+ }
1224
+ },
1225
+ {
1226
+ label: "Get the status of media",
1227
+ config: {
1228
+ resource: "media",
1229
+ operation: "get"
1230
+ }
1231
+ },
1232
+ {
1233
+ label: "Get many social profiles",
1234
+ config: {
1235
+ resource: "socialProfile",
1236
+ operation: "getAll"
1237
+ }
1238
+ },
1239
+ {
1240
+ label: "Get the signed-in member",
1241
+ config: {
1242
+ resource: "me",
1243
+ operation: "get"
1244
+ }
1245
+ },
1246
+ {
1247
+ label: "Get many teams of an organization",
1248
+ config: {
1249
+ resource: "team",
1250
+ operation: "getAll"
1251
+ }
1252
+ }
1253
+ ],
1254
+ icon: "Share2Icon",
1255
+ iconUrl: HOOTSUITE_ICON,
1256
+ config: hootsuiteConfig,
1257
+ defaultConfig: {
1258
+ resource: "message",
1259
+ operation: "getAll",
1260
+ returnAll: false,
1261
+ limit: 50,
1262
+ waitUntilReady: true,
1263
+ pollIntervalMs: 2e3,
1264
+ readyTimeoutSeconds: 120,
1265
+ active: true,
1266
+ timeoutMs: 3e4
1267
+ },
1268
+ credentialTypes: [HOOTSUITE_CREDENTIAL],
1269
+ ports: {
1270
+ in: ["in"],
1271
+ out: ["out"]
1272
+ },
1273
+ subtitle: (config) => typeof config.operation === "string" ? `${String(config.resource ?? "message")}: ${config.operation}` : void 0,
1274
+ async run({ config, credential, input, signal }) {
1275
+ const access = hootsuiteAccess(credential);
1276
+ const options = {
1277
+ signal,
1278
+ timeoutMs: config.timeoutMs
1279
+ };
1280
+ const upload = {
1281
+ waitUntilReady: config.waitUntilReady,
1282
+ pollIntervalMs: config.pollIntervalMs,
1283
+ readyTimeoutSeconds: config.readyTimeoutSeconds
1284
+ };
1285
+ if (config.resource === "media" && config.operation === "upload") return {
1286
+ port: "out",
1287
+ data: await uploadMedia(access, input, {
1288
+ ...upload,
1289
+ property: config.binaryPropertyName || "data",
1290
+ mimeType: config.mimeType
1291
+ }, options)
1292
+ };
1293
+ if (config.resource === "message" && config.operation === "schedule") {
1294
+ const uploaded = [];
1295
+ if (config.binaryPropertyName) {
1296
+ const media = await uploadMedia(access, input, {
1297
+ ...upload,
1298
+ waitUntilReady: true,
1299
+ property: config.binaryPropertyName
1300
+ }, options);
1301
+ uploaded.push(media.id);
1302
+ }
1303
+ return {
1304
+ port: "out",
1305
+ data: unwrap(await callHootsuite(access, {
1306
+ method: "POST",
1307
+ path: "/v1/messages",
1308
+ body: messageBody(config, uploaded)
1309
+ }, options))
1310
+ };
1311
+ }
1312
+ const request = buildRequest(config);
1313
+ if (request.list) return {
1314
+ port: "out",
1315
+ data: await callHootsuiteList(access, request, config.returnAll ? null : config.limit, options)
1316
+ };
1317
+ return {
1318
+ port: "out",
1319
+ data: unwrap(await callHootsuite(access, request, options))
1320
+ };
1321
+ }
1322
+ })];
1323
+ const credentialTypes = [hootsuiteOAuth2Credential];
1324
+ exports.credentialTypes = credentialTypes;
1325
+ exports.nodes = nodes;