@usenadia/node 0.1.1 → 0.3.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.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -24,13 +34,17 @@ __export(index_exports, {
24
34
  Nadia: () => Nadia,
25
35
  NadiaError: () => NadiaError,
26
36
  NadiaWebhookError: () => NadiaWebhookError,
27
- callVideoFunction: () => callVideoFunction,
37
+ catchUpAutomationPose: () => catchUpAutomationPose,
28
38
  changePostStatus: () => changePostStatus,
29
39
  checkConnection: () => checkConnection,
40
+ confirmUpload: () => confirmUpload,
30
41
  createAutomationFlow: () => createAutomationFlow,
31
42
  createContent: () => createContent,
43
+ createContentFromLink: () => createContentFromLink,
32
44
  createPost: () => createPost,
45
+ createUpload: () => createUpload,
33
46
  createWebhook: () => createWebhook,
47
+ createWorkspace: () => createWorkspace,
34
48
  default: () => index_default,
35
49
  deleteAutomationFlow: () => deleteAutomationFlow,
36
50
  deleteAutomationPose: () => deleteAutomationPose,
@@ -40,8 +54,8 @@ __export(index_exports, {
40
54
  deletePost: () => deletePost,
41
55
  deletePostGroup: () => deletePostGroup,
42
56
  deleteWebhook: () => deleteWebhook,
57
+ deleteWorkspace: () => deleteWorkspace,
43
58
  findSlot: () => findSlot,
44
- generateVideo: () => generateVideo,
45
59
  getAccountHistory: () => getAccountHistory,
46
60
  getAutomationFlow: () => getAutomationFlow,
47
61
  getAutomationPose: () => getAutomationPose,
@@ -52,11 +66,16 @@ __export(index_exports, {
52
66
  getConversation: () => getConversation,
53
67
  getHookForms: () => getHookForms,
54
68
  getMusicTrack: () => getMusicTrack,
69
+ getPost: () => getPost,
55
70
  getPostAnalytics: () => getPostAnalytics,
71
+ getPostAutomation: () => getPostAutomation,
72
+ getPostingTimes: () => getPostingTimes,
73
+ getSubscription: () => getSubscription,
74
+ getUploadFromUrl: () => getUploadFromUrl,
56
75
  getVideoHistory: () => getVideoHistory,
76
+ getViewsPerDay: () => getViewsPerDay,
57
77
  getWebhook: () => getWebhook,
58
78
  hideComment: () => hideComment,
59
- importHooks: () => importHooks,
60
79
  importMusic: () => importMusic,
61
80
  linkContentPost: () => linkContentPost,
62
81
  listAutomationFlowPoses: () => listAutomationFlowPoses,
@@ -79,13 +98,15 @@ __export(index_exports, {
79
98
  listVideoPerformance: () => listVideoPerformance,
80
99
  listWebhookEvents: () => listWebhookEvents,
81
100
  listWebhooks: () => listWebhooks,
101
+ listWorkspaces: () => listWorkspaces,
82
102
  moveContent: () => moveContent,
83
103
  parseWebhook: () => parseWebhook,
84
104
  pollAutomationPose: () => pollAutomationPose,
85
105
  pollInbox: () => pollInbox,
86
106
  poseAutomationFlow: () => poseAutomationFlow,
87
107
  previewAutomationEmail: () => previewAutomationEmail,
88
- replaceHookFamilies: () => replaceHookFamilies,
108
+ previewAutomationPoseCatchUp: () => previewAutomationPoseCatchUp,
109
+ removePostAutomation: () => removePostAutomation,
89
110
  replayAutomationPose: () => replayAutomationPose,
90
111
  replyToComment: () => replyToComment,
91
112
  runChannelTool: () => runChannelTool,
@@ -93,13 +114,21 @@ __export(index_exports, {
93
114
  sendAutomationTestEmail: () => sendAutomationTestEmail,
94
115
  sendDirectMessage: () => sendDirectMessage,
95
116
  setAutomationFlowStatus: () => setAutomationFlowStatus,
117
+ setContentWorkspaces: () => setContentWorkspaces,
118
+ setMediaWorkspaces: () => setMediaWorkspaces,
119
+ setPostAutomation: () => setPostAutomation,
120
+ setPostCover: () => setPostCover,
121
+ setPostPublication: () => setPostPublication,
96
122
  setPostReleaseId: () => setPostReleaseId,
123
+ setPostingTimes: () => setPostingTimes,
97
124
  startChannelConnection: () => startChannelConnection,
98
125
  subscribeInboxWebhook: () => subscribeInboxWebhook,
99
126
  testWebhook: () => testWebhook,
100
127
  updateAutomationFlow: () => updateAutomationFlow,
101
128
  updateAutomationPose: () => updateAutomationPose,
102
129
  updateContent: () => updateContent,
130
+ updateWorkspace: () => updateWorkspace,
131
+ uploadContentType: () => uploadContentType,
103
132
  uploadFile: () => uploadFile,
104
133
  uploadFromUrl: () => uploadFromUrl,
105
134
  uploadMusicFile: () => uploadMusicFile,
@@ -942,11 +971,53 @@ var uploadFromUrl = (options) => (options.client ?? client).post({
942
971
  ...options.headers
943
972
  }
944
973
  });
974
+ var getUploadFromUrl = (options) => (options.client ?? client).get({
975
+ security: [{ name: "Authorization", type: "apiKey" }],
976
+ url: "/public/v1/upload-from-url/{importId}",
977
+ ...options
978
+ });
979
+ var createUpload = (options) => (options.client ?? client).post({
980
+ security: [{ name: "Authorization", type: "apiKey" }],
981
+ url: "/public/v1/uploads",
982
+ ...options,
983
+ headers: {
984
+ "Content-Type": "application/json",
985
+ ...options.headers
986
+ }
987
+ });
988
+ var confirmUpload = (options) => (options.client ?? client).post({
989
+ security: [{ name: "Authorization", type: "apiKey" }],
990
+ url: "/public/v1/uploads/{uploadId}/confirm",
991
+ ...options
992
+ });
993
+ var setMediaWorkspaces = (options) => (options.client ?? client).put({
994
+ security: [{ name: "Authorization", type: "apiKey" }],
995
+ url: "/public/v1/media/{id}/workspaces",
996
+ ...options,
997
+ headers: {
998
+ "Content-Type": "application/json",
999
+ ...options.headers
1000
+ }
1001
+ });
945
1002
  var findSlot = (options) => (options.client ?? client).get({
946
1003
  security: [{ name: "Authorization", type: "apiKey" }],
947
1004
  url: "/public/v1/find-slot/{id}",
948
1005
  ...options
949
1006
  });
1007
+ var getPostingTimes = (options) => (options.client ?? client).get({
1008
+ security: [{ name: "Authorization", type: "apiKey" }],
1009
+ url: "/public/v1/integrations/{id}/posting-times",
1010
+ ...options
1011
+ });
1012
+ var setPostingTimes = (options) => (options.client ?? client).put({
1013
+ security: [{ name: "Authorization", type: "apiKey" }],
1014
+ url: "/public/v1/integrations/{id}/posting-times",
1015
+ ...options,
1016
+ headers: {
1017
+ "Content-Type": "application/json",
1018
+ ...options.headers
1019
+ }
1020
+ });
950
1021
  var listPosts = (options) => (options.client ?? client).get({
951
1022
  security: [{ name: "Authorization", type: "apiKey" }],
952
1023
  url: "/public/v1/posts",
@@ -966,6 +1037,11 @@ var deletePost = (options) => (options.client ?? client).delete({
966
1037
  url: "/public/v1/posts/{id}",
967
1038
  ...options
968
1039
  });
1040
+ var getPost = (options) => (options.client ?? client).get({
1041
+ security: [{ name: "Authorization", type: "apiKey" }],
1042
+ url: "/public/v1/posts/{id}",
1043
+ ...options
1044
+ });
969
1045
  var deletePostGroup = (options) => (options.client ?? client).delete({
970
1046
  security: [{ name: "Authorization", type: "apiKey" }],
971
1047
  url: "/public/v1/posts/group/{group}",
@@ -976,6 +1052,25 @@ var checkConnection = (options) => (options?.client ?? client).get({
976
1052
  url: "/public/v1/is-connected",
977
1053
  ...options
978
1054
  });
1055
+ var listWorkspaces = (options) => (options?.client ?? client).get({
1056
+ security: [{ name: "Authorization", type: "apiKey" }],
1057
+ url: "/public/v1/workspaces",
1058
+ ...options
1059
+ });
1060
+ var createWorkspace = (options) => (options.client ?? client).post({
1061
+ security: [{ name: "Authorization", type: "apiKey" }],
1062
+ url: "/public/v1/workspaces",
1063
+ ...options,
1064
+ headers: {
1065
+ "Content-Type": "application/json",
1066
+ ...options.headers
1067
+ }
1068
+ });
1069
+ var getSubscription = (options) => (options?.client ?? client).get({
1070
+ security: [{ name: "Authorization", type: "apiKey" }],
1071
+ url: "/public/v1/subscription",
1072
+ ...options
1073
+ });
979
1074
  var listGroups = (options) => (options?.client ?? client).get({
980
1075
  security: [{ name: "Authorization", type: "apiKey" }],
981
1076
  url: "/public/v1/groups",
@@ -996,24 +1091,6 @@ var listNotifications = (options) => (options?.client ?? client).get({
996
1091
  url: "/public/v1/notifications",
997
1092
  ...options
998
1093
  });
999
- var generateVideo = (options) => (options.client ?? client).post({
1000
- security: [{ name: "Authorization", type: "apiKey" }],
1001
- url: "/public/v1/generate-video",
1002
- ...options,
1003
- headers: {
1004
- "Content-Type": "application/json",
1005
- ...options.headers
1006
- }
1007
- });
1008
- var callVideoFunction = (options) => (options.client ?? client).post({
1009
- security: [{ name: "Authorization", type: "apiKey" }],
1010
- url: "/public/v1/video/function",
1011
- ...options,
1012
- headers: {
1013
- "Content-Type": "application/json",
1014
- ...options.headers
1015
- }
1016
- });
1017
1094
  var deleteChannel = (options) => (options.client ?? client).delete({
1018
1095
  security: [{ name: "Authorization", type: "apiKey" }],
1019
1096
  url: "/public/v1/integrations/{id}",
@@ -1038,6 +1115,25 @@ var changePostStatus = (options) => (options.client ?? client).put({
1038
1115
  ...options.headers
1039
1116
  }
1040
1117
  });
1118
+ var removePostAutomation = (options) => (options.client ?? client).delete({
1119
+ security: [{ name: "Authorization", type: "apiKey" }],
1120
+ url: "/public/v1/posts/{id}/automation",
1121
+ ...options
1122
+ });
1123
+ var getPostAutomation = (options) => (options.client ?? client).get({
1124
+ security: [{ name: "Authorization", type: "apiKey" }],
1125
+ url: "/public/v1/posts/{id}/automation",
1126
+ ...options
1127
+ });
1128
+ var setPostAutomation = (options) => (options.client ?? client).put({
1129
+ security: [{ name: "Authorization", type: "apiKey" }],
1130
+ url: "/public/v1/posts/{id}/automation",
1131
+ ...options,
1132
+ headers: {
1133
+ "Content-Type": "application/json",
1134
+ ...options.headers
1135
+ }
1136
+ });
1041
1137
  var setPostReleaseId = (options) => (options.client ?? client).put({
1042
1138
  security: [{ name: "Authorization", type: "apiKey" }],
1043
1139
  url: "/public/v1/posts/{id}/release-id",
@@ -1047,6 +1143,24 @@ var setPostReleaseId = (options) => (options.client ?? client).put({
1047
1143
  ...options.headers
1048
1144
  }
1049
1145
  });
1146
+ var setPostCover = (options) => (options.client ?? client).put({
1147
+ security: [{ name: "Authorization", type: "apiKey" }],
1148
+ url: "/public/v1/posts/{id}/cover",
1149
+ ...options,
1150
+ headers: {
1151
+ "Content-Type": "application/json",
1152
+ ...options.headers
1153
+ }
1154
+ });
1155
+ var setPostPublication = (options) => (options.client ?? client).put({
1156
+ security: [{ name: "Authorization", type: "apiKey" }],
1157
+ url: "/public/v1/posts/{id}/publication",
1158
+ ...options,
1159
+ headers: {
1160
+ "Content-Type": "application/json",
1161
+ ...options.headers
1162
+ }
1163
+ });
1050
1164
  var getChannelAnalytics = (options) => (options.client ?? client).get({
1051
1165
  security: [{ name: "Authorization", type: "apiKey" }],
1052
1166
  url: "/public/v1/analytics/{integration}",
@@ -1067,6 +1181,11 @@ var getVideoHistory = (options) => (options.client ?? client).get({
1067
1181
  url: "/public/v1/video-history/{integrationId}",
1068
1182
  ...options
1069
1183
  });
1184
+ var getViewsPerDay = (options) => (options.client ?? client).get({
1185
+ security: [{ name: "Authorization", type: "apiKey" }],
1186
+ url: "/public/v1/views-per-day/{integrationId}",
1187
+ ...options
1188
+ });
1070
1189
  var getPostAnalytics = (options) => (options.client ?? client).get({
1071
1190
  security: [{ name: "Authorization", type: "apiKey" }],
1072
1191
  url: "/public/v1/analytics/post/{postId}",
@@ -1222,7 +1341,7 @@ var poseAutomationFlow = (options) => (options.client ?? client).post({
1222
1341
  ...options.headers
1223
1342
  }
1224
1343
  });
1225
- var listChannelAutomationPoses = (options) => (options.client ?? client).get({
1344
+ var listChannelAutomationPoses = (options) => (options?.client ?? client).get({
1226
1345
  security: [{ name: "Authorization", type: "apiKey" }],
1227
1346
  url: "/public/v1/automation-flow-poses",
1228
1347
  ...options
@@ -1265,6 +1384,16 @@ var replayAutomationPose = (options) => (options.client ?? client).post({
1265
1384
  ...options.headers
1266
1385
  }
1267
1386
  });
1387
+ var previewAutomationPoseCatchUp = (options) => (options.client ?? client).get({
1388
+ security: [{ name: "Authorization", type: "apiKey" }],
1389
+ url: "/public/v1/automation-flow-poses/{id}/catch-up",
1390
+ ...options
1391
+ });
1392
+ var catchUpAutomationPose = (options) => (options.client ?? client).post({
1393
+ security: [{ name: "Authorization", type: "apiKey" }],
1394
+ url: "/public/v1/automation-flow-poses/{id}/catch-up",
1395
+ ...options
1396
+ });
1268
1397
  var listWebhookEvents = (options) => (options?.client ?? client).get({
1269
1398
  security: [{ name: "Authorization", type: "apiKey" }],
1270
1399
  url: "/public/v1/webhooks/events",
@@ -1350,6 +1479,15 @@ var upsertContent = (options) => (options.client ?? client).post({
1350
1479
  ...options.headers
1351
1480
  }
1352
1481
  });
1482
+ var createContentFromLink = (options) => (options.client ?? client).post({
1483
+ security: [{ name: "Authorization", type: "apiKey" }],
1484
+ url: "/public/v1/contents/from-link",
1485
+ ...options,
1486
+ headers: {
1487
+ "Content-Type": "application/json",
1488
+ ...options.headers
1489
+ }
1490
+ });
1353
1491
  var moveContent = (options) => (options.client ?? client).put({
1354
1492
  security: [{ name: "Authorization", type: "apiKey" }],
1355
1493
  url: "/public/v1/contents/{id}/move",
@@ -1368,6 +1506,15 @@ var linkContentPost = (options) => (options.client ?? client).put({
1368
1506
  ...options.headers
1369
1507
  }
1370
1508
  });
1509
+ var setContentWorkspaces = (options) => (options.client ?? client).put({
1510
+ security: [{ name: "Authorization", type: "apiKey" }],
1511
+ url: "/public/v1/contents/{id}/workspaces",
1512
+ ...options,
1513
+ headers: {
1514
+ "Content-Type": "application/json",
1515
+ ...options.headers
1516
+ }
1517
+ });
1371
1518
  var searchHooks = (options) => (options?.client ?? client).get({
1372
1519
  security: [{ name: "Authorization", type: "apiKey" }],
1373
1520
  url: "/public/v1/hooks",
@@ -1383,24 +1530,6 @@ var listHookFamilies = (options) => (options?.client ?? client).get({
1383
1530
  url: "/public/v1/hooks/families",
1384
1531
  ...options
1385
1532
  });
1386
- var replaceHookFamilies = (options) => (options.client ?? client).put({
1387
- security: [{ name: "Authorization", type: "apiKey" }],
1388
- url: "/public/v1/hooks/families",
1389
- ...options,
1390
- headers: {
1391
- "Content-Type": "application/json",
1392
- ...options.headers
1393
- }
1394
- });
1395
- var importHooks = (options) => (options.client ?? client).post({
1396
- security: [{ name: "Authorization", type: "apiKey" }],
1397
- url: "/public/v1/hooks/import",
1398
- ...options,
1399
- headers: {
1400
- "Content-Type": "application/json",
1401
- ...options.headers
1402
- }
1403
- });
1404
1533
  var listMusic = (options) => (options?.client ?? client).get({
1405
1534
  security: [{ name: "Authorization", type: "apiKey" }],
1406
1535
  url: "/public/v1/music",
@@ -1435,6 +1564,20 @@ var uploadMusicFile = (options) => (options.client ?? client).put({
1435
1564
  ...options.headers
1436
1565
  }
1437
1566
  });
1567
+ var deleteWorkspace = (options) => (options.client ?? client).delete({
1568
+ security: [{ name: "Authorization", type: "apiKey" }],
1569
+ url: "/public/v1/workspaces/{id}",
1570
+ ...options
1571
+ });
1572
+ var updateWorkspace = (options) => (options.client ?? client).put({
1573
+ security: [{ name: "Authorization", type: "apiKey" }],
1574
+ url: "/public/v1/workspaces/{id}",
1575
+ ...options,
1576
+ headers: {
1577
+ "Content-Type": "application/json",
1578
+ ...options.headers
1579
+ }
1580
+ });
1438
1581
 
1439
1582
  // src/index.ts
1440
1583
  var DEFAULT_BASE_URL = "https://app.usenadia.com/api";
@@ -1457,6 +1600,39 @@ var NadiaError = class _NadiaError extends Error {
1457
1600
  }
1458
1601
  };
1459
1602
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
1603
+ var isUrlImport = (v) => !!v && typeof v === "object" && typeof v.id === "string" && typeof v.status === "string" && !("path" in v);
1604
+ var DIRECT_TYPES = {
1605
+ mp4: "video/mp4",
1606
+ jpg: "image/jpeg",
1607
+ jpeg: "image/jpeg",
1608
+ png: "image/png",
1609
+ webp: "image/webp",
1610
+ gif: "image/gif"
1611
+ };
1612
+ var PARALLEL_PARTS = 4;
1613
+ var PART_TRIES = 3;
1614
+ var UPLOAD_ROUNDS = 4;
1615
+ function directType(name, blobType) {
1616
+ const ext = /\.([a-z0-9]+)$/i.exec(name)?.[1]?.toLowerCase();
1617
+ if (ext && DIRECT_TYPES[ext]) return DIRECT_TYPES[ext];
1618
+ return Object.values(DIRECT_TYPES).includes(blobType) ? blobType : void 0;
1619
+ }
1620
+ var uploadContentType = (filename) => directType(filename, "");
1621
+ async function openSource(file, filename) {
1622
+ if (typeof file !== "string") {
1623
+ const own = file.name;
1624
+ return { blob: file, name: filename ?? (own || "upload") };
1625
+ }
1626
+ const fs = await import("fs");
1627
+ const { basename } = await import("path");
1628
+ const blob = typeof fs.openAsBlob === "function" ? await fs.openAsBlob(file) : new Blob([await fs.promises.readFile(file)]);
1629
+ return { blob, name: filename ?? basename(file) };
1630
+ }
1631
+ var range = (from, to) => Array.from({ length: to - from + 1 }, (_, i) => from + i);
1632
+ function missingParts(body) {
1633
+ const list = body?.missingParts;
1634
+ return Array.isArray(list) ? list.filter((n) => Number.isInteger(n) && n > 0) : [];
1635
+ }
1460
1636
  var messageOf = (body) => {
1461
1637
  if (!body || typeof body !== "object") return void 0;
1462
1638
  const { msg, message } = body;
@@ -1470,12 +1646,20 @@ var messageOf = (body) => {
1470
1646
  var Nadia = class {
1471
1647
  client;
1472
1648
  retries;
1649
+ /** For the bytes of an upload, which go to the upload host, not the API. */
1650
+ fetchImpl;
1651
+ importPoll;
1473
1652
  constructor(apiKey, options = {}) {
1474
1653
  if (!apiKey) {
1475
1654
  throw new Error("An API key is required.");
1476
1655
  }
1477
1656
  const opts = typeof options === "string" ? { baseUrl: options } : options;
1478
1657
  this.retries = opts.retries ?? 2;
1658
+ this.fetchImpl = opts.fetch ?? ((input, init) => fetch(input, init));
1659
+ this.importPoll = {
1660
+ intervalMs: opts.importPoll?.intervalMs ?? 3e3,
1661
+ timeoutMs: opts.importPoll?.timeoutMs ?? 15 * 60 * 1e3
1662
+ };
1479
1663
  this.client = client;
1480
1664
  this.client.setConfig({
1481
1665
  baseUrl: opts.baseUrl ?? DEFAULT_BASE_URL,
@@ -1521,10 +1705,110 @@ var Nadia = class {
1521
1705
  (o) => listPosts({ ...o, query })
1522
1706
  );
1523
1707
  }
1524
- /** Upload a file and get a URL usable in a post. */
1525
- upload(file, filename = "upload") {
1708
+ /**
1709
+ * Upload a file and get a URL usable in a post: a path on disk, or a
1710
+ * `Blob` / `File` with its name.
1711
+ *
1712
+ * An MP4, JPEG, PNG, WebP or GIF goes in parts of 20 MB straight to the
1713
+ * storage (`POST /public/v1/uploads`, then its confirm): four parts at a
1714
+ * time, a part cut by the network sent again, and the parts the confirm
1715
+ * says are missing sent again before confirming once more. A server that
1716
+ * does not take parts answers a single PUT, which is done instead; a
1717
+ * server without that route (older, or self-hosted on an older release)
1718
+ * and any other type (HEIC… which the server converts to JPEG) go through
1719
+ * `POST /public/v1/upload`, the whole file in one request, as before. A
1720
+ * MOV or an M4V is refused there (`415`): convert it to MP4 first.
1721
+ *
1722
+ * Resolves to the media: `id` and `path` always (what a post takes),
1723
+ * plus `size`, `duration`, `width`, `height`, `codec` when it went in
1724
+ * parts or in a single PUT.
1725
+ */
1726
+ async upload(file, filename) {
1727
+ const source = await openSource(file, filename);
1728
+ const type = directType(source.name, source.blob.type);
1729
+ if (!type) return this.uploadWhole(source);
1730
+ let opened;
1731
+ try {
1732
+ opened = await this.call(
1733
+ (o) => createUpload({
1734
+ ...o,
1735
+ body: { filename: source.name, contentType: type, size: source.blob.size }
1736
+ })
1737
+ );
1738
+ } catch (err) {
1739
+ if (err instanceof NadiaError && (err.status === 404 || err.status === 405)) {
1740
+ return this.uploadWhole(source);
1741
+ }
1742
+ throw err;
1743
+ }
1744
+ if (opened.parts) {
1745
+ await this.sendParts(opened, source.blob, range(1, opened.parts));
1746
+ } else {
1747
+ await this.sendWhole(opened, source.blob);
1748
+ }
1749
+ for (let round = 1; ; round++) {
1750
+ try {
1751
+ return await this.call(
1752
+ (o) => confirmUpload({ ...o, path: { uploadId: opened.uploadId } })
1753
+ );
1754
+ } catch (err) {
1755
+ if (!(err instanceof NadiaError) || err.status !== 409 || round >= UPLOAD_ROUNDS) throw err;
1756
+ const missing = missingParts(err.body);
1757
+ if (missing.length && opened.parts) {
1758
+ await this.sendParts(opened, source.blob, missing);
1759
+ } else if (/^CONFIRM_IN_PROGRESS/.test(err.message)) {
1760
+ await sleep(3e3);
1761
+ } else {
1762
+ throw err;
1763
+ }
1764
+ }
1765
+ }
1766
+ }
1767
+ /**
1768
+ * Import a file from a public HTTPS URL into the media library
1769
+ * (`POST /public/v1/upload-from-url`): the path of the URL ends in `.png`,
1770
+ * `.jpg`, `.jpeg`, `.gif`, `.webp` or `.mp4`.
1771
+ *
1772
+ * A long import (not done within 25 s) is answered `202` by the server and
1773
+ * goes on there; it is read again here (`GET
1774
+ * /public/v1/upload-from-url/{importId}`) until it ends. Resolves to the
1775
+ * media either way; a failed import throws the `NadiaError` the server
1776
+ * would have answered at once (its status and `msg`).
1777
+ */
1778
+ async uploadFromUrl(url) {
1779
+ const first = await this.call((o) => uploadFromUrl({ ...o, body: { url } }));
1780
+ return this.importEnd(first);
1781
+ }
1782
+ /**
1783
+ * The end of an import from a URL: the media at once (`201`), or an import
1784
+ * (`202`) read again every few seconds until it is done or failed.
1785
+ */
1786
+ async importEnd(answer) {
1787
+ if (!isUrlImport(answer)) return answer;
1788
+ const deadline = Date.now() + this.importPoll.timeoutMs;
1789
+ let current = answer;
1790
+ while (current.status === "running") {
1791
+ if (Date.now() >= deadline) {
1792
+ throw new NadiaError(
1793
+ 504,
1794
+ current,
1795
+ `The import from a URL ${current.id} did not end within ${Math.round(this.importPoll.timeoutMs / 1e3)} s: read it again with getUploadFromUrl.`
1796
+ );
1797
+ }
1798
+ await sleep(this.importPoll.intervalMs);
1799
+ const id = current.id;
1800
+ current = await this.call(
1801
+ (o) => getUploadFromUrl({ ...o, path: { importId: id } })
1802
+ );
1803
+ }
1804
+ if (current.status === "done" && current.media) return current.media;
1805
+ const error = current.error ?? { statusCode: 500, msg: "The import from a URL failed." };
1806
+ throw new NadiaError(error.statusCode, { msg: error.msg }, error.msg);
1807
+ }
1808
+ /** The whole file in one multipart request: `POST /public/v1/upload`. */
1809
+ uploadWhole(source) {
1526
1810
  const form = new FormData();
1527
- form.append("file", file, filename);
1811
+ form.append("file", source.blob, source.name);
1528
1812
  return this.call(
1529
1813
  (o) => uploadFile({
1530
1814
  ...o,
@@ -1533,6 +1817,58 @@ var Nadia = class {
1533
1817
  })
1534
1818
  );
1535
1819
  }
1820
+ /** Each part to `<uploadUrl>/<n>`, a few at a time, each retried. */
1821
+ async sendParts(opened, blob, numbers) {
1822
+ const queue = [...numbers];
1823
+ const size = opened.partSize;
1824
+ const worker = async () => {
1825
+ for (let n = queue.shift(); n !== void 0; n = queue.shift()) {
1826
+ const from = (n - 1) * size;
1827
+ await this.put(`${opened.uploadUrl}/${n}`, blob.slice(from, Math.min(from + size, blob.size)), {
1828
+ "Content-Type": "application/octet-stream"
1829
+ }, 200);
1830
+ }
1831
+ };
1832
+ await Promise.all(Array.from({ length: Math.min(PARALLEL_PARTS, queue.length) }, worker));
1833
+ }
1834
+ /** The single PUT of a server that takes no parts. */
1835
+ sendWhole(opened, blob) {
1836
+ const headers = Object.fromEntries(
1837
+ Object.entries(opened.headers ?? {}).filter(([k]) => k.toLowerCase() !== "content-length")
1838
+ );
1839
+ return this.put(opened.uploadUrl, blob, headers, 201);
1840
+ }
1841
+ /**
1842
+ * A PUT of raw bytes, without the API key (the URL is the credential):
1843
+ * three tries on a network error, a 5xx or a 429, none on anything else.
1844
+ */
1845
+ async put(url, body, headers, ok) {
1846
+ let last;
1847
+ for (let attempt = 1; attempt <= PART_TRIES; attempt++) {
1848
+ let response;
1849
+ try {
1850
+ response = await this.fetchImpl(url, { method: "PUT", headers, body });
1851
+ } catch (err) {
1852
+ last = new NadiaError(0, err, `The upload of ${url.replace(/\/v2\/[^/]+/, "/v2/\u2026")} did not complete.`);
1853
+ }
1854
+ if (response) {
1855
+ if (response.status === ok || response.ok) {
1856
+ await response.body?.cancel();
1857
+ return;
1858
+ }
1859
+ const text = await response.text();
1860
+ let parsed = text;
1861
+ try {
1862
+ parsed = JSON.parse(text);
1863
+ } catch {
1864
+ }
1865
+ last = new NadiaError(response.status, parsed, messageOf(parsed) ?? `The upload answered ${response.status}`);
1866
+ if (!last.isTransient) throw last;
1867
+ }
1868
+ if (attempt < PART_TRIES) await sleep(attempt * 1e3);
1869
+ }
1870
+ throw last;
1871
+ }
1536
1872
  /** List your connected channels. */
1537
1873
  integrations() {
1538
1874
  return this.call((o) => listChannels(o));
@@ -1725,13 +2061,17 @@ function parseWebhook(options) {
1725
2061
  Nadia,
1726
2062
  NadiaError,
1727
2063
  NadiaWebhookError,
1728
- callVideoFunction,
2064
+ catchUpAutomationPose,
1729
2065
  changePostStatus,
1730
2066
  checkConnection,
2067
+ confirmUpload,
1731
2068
  createAutomationFlow,
1732
2069
  createContent,
2070
+ createContentFromLink,
1733
2071
  createPost,
2072
+ createUpload,
1734
2073
  createWebhook,
2074
+ createWorkspace,
1735
2075
  deleteAutomationFlow,
1736
2076
  deleteAutomationPose,
1737
2077
  deleteChannel,
@@ -1740,8 +2080,8 @@ function parseWebhook(options) {
1740
2080
  deletePost,
1741
2081
  deletePostGroup,
1742
2082
  deleteWebhook,
2083
+ deleteWorkspace,
1743
2084
  findSlot,
1744
- generateVideo,
1745
2085
  getAccountHistory,
1746
2086
  getAutomationFlow,
1747
2087
  getAutomationPose,
@@ -1752,11 +2092,16 @@ function parseWebhook(options) {
1752
2092
  getConversation,
1753
2093
  getHookForms,
1754
2094
  getMusicTrack,
2095
+ getPost,
1755
2096
  getPostAnalytics,
2097
+ getPostAutomation,
2098
+ getPostingTimes,
2099
+ getSubscription,
2100
+ getUploadFromUrl,
1756
2101
  getVideoHistory,
2102
+ getViewsPerDay,
1757
2103
  getWebhook,
1758
2104
  hideComment,
1759
- importHooks,
1760
2105
  importMusic,
1761
2106
  linkContentPost,
1762
2107
  listAutomationFlowPoses,
@@ -1779,13 +2124,15 @@ function parseWebhook(options) {
1779
2124
  listVideoPerformance,
1780
2125
  listWebhookEvents,
1781
2126
  listWebhooks,
2127
+ listWorkspaces,
1782
2128
  moveContent,
1783
2129
  parseWebhook,
1784
2130
  pollAutomationPose,
1785
2131
  pollInbox,
1786
2132
  poseAutomationFlow,
1787
2133
  previewAutomationEmail,
1788
- replaceHookFamilies,
2134
+ previewAutomationPoseCatchUp,
2135
+ removePostAutomation,
1789
2136
  replayAutomationPose,
1790
2137
  replyToComment,
1791
2138
  runChannelTool,
@@ -1793,13 +2140,21 @@ function parseWebhook(options) {
1793
2140
  sendAutomationTestEmail,
1794
2141
  sendDirectMessage,
1795
2142
  setAutomationFlowStatus,
2143
+ setContentWorkspaces,
2144
+ setMediaWorkspaces,
2145
+ setPostAutomation,
2146
+ setPostCover,
2147
+ setPostPublication,
1796
2148
  setPostReleaseId,
2149
+ setPostingTimes,
1797
2150
  startChannelConnection,
1798
2151
  subscribeInboxWebhook,
1799
2152
  testWebhook,
1800
2153
  updateAutomationFlow,
1801
2154
  updateAutomationPose,
1802
2155
  updateContent,
2156
+ updateWorkspace,
2157
+ uploadContentType,
1803
2158
  uploadFile,
1804
2159
  uploadFromUrl,
1805
2160
  uploadMusicFile,