@usenadia/node 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -4
- package/dist/index.d.mts +1983 -361
- package/dist/index.d.ts +1983 -361
- package/dist/index.js +326 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +296 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
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,15 @@ __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,
|
|
56
74
|
getVideoHistory: () => getVideoHistory,
|
|
75
|
+
getViewsPerDay: () => getViewsPerDay,
|
|
57
76
|
getWebhook: () => getWebhook,
|
|
58
77
|
hideComment: () => hideComment,
|
|
59
|
-
importHooks: () => importHooks,
|
|
60
78
|
importMusic: () => importMusic,
|
|
61
79
|
linkContentPost: () => linkContentPost,
|
|
62
80
|
listAutomationFlowPoses: () => listAutomationFlowPoses,
|
|
@@ -79,13 +97,15 @@ __export(index_exports, {
|
|
|
79
97
|
listVideoPerformance: () => listVideoPerformance,
|
|
80
98
|
listWebhookEvents: () => listWebhookEvents,
|
|
81
99
|
listWebhooks: () => listWebhooks,
|
|
100
|
+
listWorkspaces: () => listWorkspaces,
|
|
82
101
|
moveContent: () => moveContent,
|
|
83
102
|
parseWebhook: () => parseWebhook,
|
|
84
103
|
pollAutomationPose: () => pollAutomationPose,
|
|
85
104
|
pollInbox: () => pollInbox,
|
|
86
105
|
poseAutomationFlow: () => poseAutomationFlow,
|
|
87
106
|
previewAutomationEmail: () => previewAutomationEmail,
|
|
88
|
-
|
|
107
|
+
previewAutomationPoseCatchUp: () => previewAutomationPoseCatchUp,
|
|
108
|
+
removePostAutomation: () => removePostAutomation,
|
|
89
109
|
replayAutomationPose: () => replayAutomationPose,
|
|
90
110
|
replyToComment: () => replyToComment,
|
|
91
111
|
runChannelTool: () => runChannelTool,
|
|
@@ -93,13 +113,19 @@ __export(index_exports, {
|
|
|
93
113
|
sendAutomationTestEmail: () => sendAutomationTestEmail,
|
|
94
114
|
sendDirectMessage: () => sendDirectMessage,
|
|
95
115
|
setAutomationFlowStatus: () => setAutomationFlowStatus,
|
|
116
|
+
setPostAutomation: () => setPostAutomation,
|
|
117
|
+
setPostCover: () => setPostCover,
|
|
118
|
+
setPostPublication: () => setPostPublication,
|
|
96
119
|
setPostReleaseId: () => setPostReleaseId,
|
|
120
|
+
setPostingTimes: () => setPostingTimes,
|
|
97
121
|
startChannelConnection: () => startChannelConnection,
|
|
98
122
|
subscribeInboxWebhook: () => subscribeInboxWebhook,
|
|
99
123
|
testWebhook: () => testWebhook,
|
|
100
124
|
updateAutomationFlow: () => updateAutomationFlow,
|
|
101
125
|
updateAutomationPose: () => updateAutomationPose,
|
|
102
126
|
updateContent: () => updateContent,
|
|
127
|
+
updateWorkspace: () => updateWorkspace,
|
|
128
|
+
uploadContentType: () => uploadContentType,
|
|
103
129
|
uploadFile: () => uploadFile,
|
|
104
130
|
uploadFromUrl: () => uploadFromUrl,
|
|
105
131
|
uploadMusicFile: () => uploadMusicFile,
|
|
@@ -942,11 +968,39 @@ var uploadFromUrl = (options) => (options.client ?? client).post({
|
|
|
942
968
|
...options.headers
|
|
943
969
|
}
|
|
944
970
|
});
|
|
971
|
+
var createUpload = (options) => (options.client ?? client).post({
|
|
972
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
973
|
+
url: "/public/v1/uploads",
|
|
974
|
+
...options,
|
|
975
|
+
headers: {
|
|
976
|
+
"Content-Type": "application/json",
|
|
977
|
+
...options.headers
|
|
978
|
+
}
|
|
979
|
+
});
|
|
980
|
+
var confirmUpload = (options) => (options.client ?? client).post({
|
|
981
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
982
|
+
url: "/public/v1/uploads/{uploadId}/confirm",
|
|
983
|
+
...options
|
|
984
|
+
});
|
|
945
985
|
var findSlot = (options) => (options.client ?? client).get({
|
|
946
986
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
947
987
|
url: "/public/v1/find-slot/{id}",
|
|
948
988
|
...options
|
|
949
989
|
});
|
|
990
|
+
var getPostingTimes = (options) => (options.client ?? client).get({
|
|
991
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
992
|
+
url: "/public/v1/integrations/{id}/posting-times",
|
|
993
|
+
...options
|
|
994
|
+
});
|
|
995
|
+
var setPostingTimes = (options) => (options.client ?? client).put({
|
|
996
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
997
|
+
url: "/public/v1/integrations/{id}/posting-times",
|
|
998
|
+
...options,
|
|
999
|
+
headers: {
|
|
1000
|
+
"Content-Type": "application/json",
|
|
1001
|
+
...options.headers
|
|
1002
|
+
}
|
|
1003
|
+
});
|
|
950
1004
|
var listPosts = (options) => (options.client ?? client).get({
|
|
951
1005
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
952
1006
|
url: "/public/v1/posts",
|
|
@@ -966,6 +1020,11 @@ var deletePost = (options) => (options.client ?? client).delete({
|
|
|
966
1020
|
url: "/public/v1/posts/{id}",
|
|
967
1021
|
...options
|
|
968
1022
|
});
|
|
1023
|
+
var getPost = (options) => (options.client ?? client).get({
|
|
1024
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1025
|
+
url: "/public/v1/posts/{id}",
|
|
1026
|
+
...options
|
|
1027
|
+
});
|
|
969
1028
|
var deletePostGroup = (options) => (options.client ?? client).delete({
|
|
970
1029
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
971
1030
|
url: "/public/v1/posts/group/{group}",
|
|
@@ -976,6 +1035,25 @@ var checkConnection = (options) => (options?.client ?? client).get({
|
|
|
976
1035
|
url: "/public/v1/is-connected",
|
|
977
1036
|
...options
|
|
978
1037
|
});
|
|
1038
|
+
var listWorkspaces = (options) => (options?.client ?? client).get({
|
|
1039
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1040
|
+
url: "/public/v1/workspaces",
|
|
1041
|
+
...options
|
|
1042
|
+
});
|
|
1043
|
+
var createWorkspace = (options) => (options.client ?? client).post({
|
|
1044
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1045
|
+
url: "/public/v1/workspaces",
|
|
1046
|
+
...options,
|
|
1047
|
+
headers: {
|
|
1048
|
+
"Content-Type": "application/json",
|
|
1049
|
+
...options.headers
|
|
1050
|
+
}
|
|
1051
|
+
});
|
|
1052
|
+
var getSubscription = (options) => (options?.client ?? client).get({
|
|
1053
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1054
|
+
url: "/public/v1/subscription",
|
|
1055
|
+
...options
|
|
1056
|
+
});
|
|
979
1057
|
var listGroups = (options) => (options?.client ?? client).get({
|
|
980
1058
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
981
1059
|
url: "/public/v1/groups",
|
|
@@ -996,24 +1074,6 @@ var listNotifications = (options) => (options?.client ?? client).get({
|
|
|
996
1074
|
url: "/public/v1/notifications",
|
|
997
1075
|
...options
|
|
998
1076
|
});
|
|
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
1077
|
var deleteChannel = (options) => (options.client ?? client).delete({
|
|
1018
1078
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1019
1079
|
url: "/public/v1/integrations/{id}",
|
|
@@ -1038,6 +1098,25 @@ var changePostStatus = (options) => (options.client ?? client).put({
|
|
|
1038
1098
|
...options.headers
|
|
1039
1099
|
}
|
|
1040
1100
|
});
|
|
1101
|
+
var removePostAutomation = (options) => (options.client ?? client).delete({
|
|
1102
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1103
|
+
url: "/public/v1/posts/{id}/automation",
|
|
1104
|
+
...options
|
|
1105
|
+
});
|
|
1106
|
+
var getPostAutomation = (options) => (options.client ?? client).get({
|
|
1107
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1108
|
+
url: "/public/v1/posts/{id}/automation",
|
|
1109
|
+
...options
|
|
1110
|
+
});
|
|
1111
|
+
var setPostAutomation = (options) => (options.client ?? client).put({
|
|
1112
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1113
|
+
url: "/public/v1/posts/{id}/automation",
|
|
1114
|
+
...options,
|
|
1115
|
+
headers: {
|
|
1116
|
+
"Content-Type": "application/json",
|
|
1117
|
+
...options.headers
|
|
1118
|
+
}
|
|
1119
|
+
});
|
|
1041
1120
|
var setPostReleaseId = (options) => (options.client ?? client).put({
|
|
1042
1121
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1043
1122
|
url: "/public/v1/posts/{id}/release-id",
|
|
@@ -1047,6 +1126,24 @@ var setPostReleaseId = (options) => (options.client ?? client).put({
|
|
|
1047
1126
|
...options.headers
|
|
1048
1127
|
}
|
|
1049
1128
|
});
|
|
1129
|
+
var setPostCover = (options) => (options.client ?? client).put({
|
|
1130
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1131
|
+
url: "/public/v1/posts/{id}/cover",
|
|
1132
|
+
...options,
|
|
1133
|
+
headers: {
|
|
1134
|
+
"Content-Type": "application/json",
|
|
1135
|
+
...options.headers
|
|
1136
|
+
}
|
|
1137
|
+
});
|
|
1138
|
+
var setPostPublication = (options) => (options.client ?? client).put({
|
|
1139
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1140
|
+
url: "/public/v1/posts/{id}/publication",
|
|
1141
|
+
...options,
|
|
1142
|
+
headers: {
|
|
1143
|
+
"Content-Type": "application/json",
|
|
1144
|
+
...options.headers
|
|
1145
|
+
}
|
|
1146
|
+
});
|
|
1050
1147
|
var getChannelAnalytics = (options) => (options.client ?? client).get({
|
|
1051
1148
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1052
1149
|
url: "/public/v1/analytics/{integration}",
|
|
@@ -1067,6 +1164,11 @@ var getVideoHistory = (options) => (options.client ?? client).get({
|
|
|
1067
1164
|
url: "/public/v1/video-history/{integrationId}",
|
|
1068
1165
|
...options
|
|
1069
1166
|
});
|
|
1167
|
+
var getViewsPerDay = (options) => (options.client ?? client).get({
|
|
1168
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1169
|
+
url: "/public/v1/views-per-day/{integrationId}",
|
|
1170
|
+
...options
|
|
1171
|
+
});
|
|
1070
1172
|
var getPostAnalytics = (options) => (options.client ?? client).get({
|
|
1071
1173
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1072
1174
|
url: "/public/v1/analytics/post/{postId}",
|
|
@@ -1222,7 +1324,7 @@ var poseAutomationFlow = (options) => (options.client ?? client).post({
|
|
|
1222
1324
|
...options.headers
|
|
1223
1325
|
}
|
|
1224
1326
|
});
|
|
1225
|
-
var listChannelAutomationPoses = (options) => (options
|
|
1327
|
+
var listChannelAutomationPoses = (options) => (options?.client ?? client).get({
|
|
1226
1328
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1227
1329
|
url: "/public/v1/automation-flow-poses",
|
|
1228
1330
|
...options
|
|
@@ -1265,6 +1367,16 @@ var replayAutomationPose = (options) => (options.client ?? client).post({
|
|
|
1265
1367
|
...options.headers
|
|
1266
1368
|
}
|
|
1267
1369
|
});
|
|
1370
|
+
var previewAutomationPoseCatchUp = (options) => (options.client ?? client).get({
|
|
1371
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1372
|
+
url: "/public/v1/automation-flow-poses/{id}/catch-up",
|
|
1373
|
+
...options
|
|
1374
|
+
});
|
|
1375
|
+
var catchUpAutomationPose = (options) => (options.client ?? client).post({
|
|
1376
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1377
|
+
url: "/public/v1/automation-flow-poses/{id}/catch-up",
|
|
1378
|
+
...options
|
|
1379
|
+
});
|
|
1268
1380
|
var listWebhookEvents = (options) => (options?.client ?? client).get({
|
|
1269
1381
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1270
1382
|
url: "/public/v1/webhooks/events",
|
|
@@ -1350,6 +1462,15 @@ var upsertContent = (options) => (options.client ?? client).post({
|
|
|
1350
1462
|
...options.headers
|
|
1351
1463
|
}
|
|
1352
1464
|
});
|
|
1465
|
+
var createContentFromLink = (options) => (options.client ?? client).post({
|
|
1466
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1467
|
+
url: "/public/v1/contents/from-link",
|
|
1468
|
+
...options,
|
|
1469
|
+
headers: {
|
|
1470
|
+
"Content-Type": "application/json",
|
|
1471
|
+
...options.headers
|
|
1472
|
+
}
|
|
1473
|
+
});
|
|
1353
1474
|
var moveContent = (options) => (options.client ?? client).put({
|
|
1354
1475
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1355
1476
|
url: "/public/v1/contents/{id}/move",
|
|
@@ -1383,24 +1504,6 @@ var listHookFamilies = (options) => (options?.client ?? client).get({
|
|
|
1383
1504
|
url: "/public/v1/hooks/families",
|
|
1384
1505
|
...options
|
|
1385
1506
|
});
|
|
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
1507
|
var listMusic = (options) => (options?.client ?? client).get({
|
|
1405
1508
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1406
1509
|
url: "/public/v1/music",
|
|
@@ -1435,6 +1538,20 @@ var uploadMusicFile = (options) => (options.client ?? client).put({
|
|
|
1435
1538
|
...options.headers
|
|
1436
1539
|
}
|
|
1437
1540
|
});
|
|
1541
|
+
var deleteWorkspace = (options) => (options.client ?? client).delete({
|
|
1542
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1543
|
+
url: "/public/v1/workspaces/{id}",
|
|
1544
|
+
...options
|
|
1545
|
+
});
|
|
1546
|
+
var updateWorkspace = (options) => (options.client ?? client).put({
|
|
1547
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1548
|
+
url: "/public/v1/workspaces/{id}",
|
|
1549
|
+
...options,
|
|
1550
|
+
headers: {
|
|
1551
|
+
"Content-Type": "application/json",
|
|
1552
|
+
...options.headers
|
|
1553
|
+
}
|
|
1554
|
+
});
|
|
1438
1555
|
|
|
1439
1556
|
// src/index.ts
|
|
1440
1557
|
var DEFAULT_BASE_URL = "https://app.usenadia.com/api";
|
|
@@ -1457,6 +1574,38 @@ var NadiaError = class _NadiaError extends Error {
|
|
|
1457
1574
|
}
|
|
1458
1575
|
};
|
|
1459
1576
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1577
|
+
var DIRECT_TYPES = {
|
|
1578
|
+
mp4: "video/mp4",
|
|
1579
|
+
jpg: "image/jpeg",
|
|
1580
|
+
jpeg: "image/jpeg",
|
|
1581
|
+
png: "image/png",
|
|
1582
|
+
webp: "image/webp",
|
|
1583
|
+
gif: "image/gif"
|
|
1584
|
+
};
|
|
1585
|
+
var PARALLEL_PARTS = 4;
|
|
1586
|
+
var PART_TRIES = 3;
|
|
1587
|
+
var UPLOAD_ROUNDS = 4;
|
|
1588
|
+
function directType(name, blobType) {
|
|
1589
|
+
const ext = /\.([a-z0-9]+)$/i.exec(name)?.[1]?.toLowerCase();
|
|
1590
|
+
if (ext && DIRECT_TYPES[ext]) return DIRECT_TYPES[ext];
|
|
1591
|
+
return Object.values(DIRECT_TYPES).includes(blobType) ? blobType : void 0;
|
|
1592
|
+
}
|
|
1593
|
+
var uploadContentType = (filename) => directType(filename, "");
|
|
1594
|
+
async function openSource(file, filename) {
|
|
1595
|
+
if (typeof file !== "string") {
|
|
1596
|
+
const own = file.name;
|
|
1597
|
+
return { blob: file, name: filename ?? (own || "upload") };
|
|
1598
|
+
}
|
|
1599
|
+
const fs = await import("fs");
|
|
1600
|
+
const { basename } = await import("path");
|
|
1601
|
+
const blob = typeof fs.openAsBlob === "function" ? await fs.openAsBlob(file) : new Blob([await fs.promises.readFile(file)]);
|
|
1602
|
+
return { blob, name: filename ?? basename(file) };
|
|
1603
|
+
}
|
|
1604
|
+
var range = (from, to) => Array.from({ length: to - from + 1 }, (_, i) => from + i);
|
|
1605
|
+
function missingParts(body) {
|
|
1606
|
+
const list = body?.missingParts;
|
|
1607
|
+
return Array.isArray(list) ? list.filter((n) => Number.isInteger(n) && n > 0) : [];
|
|
1608
|
+
}
|
|
1460
1609
|
var messageOf = (body) => {
|
|
1461
1610
|
if (!body || typeof body !== "object") return void 0;
|
|
1462
1611
|
const { msg, message } = body;
|
|
@@ -1470,12 +1619,15 @@ var messageOf = (body) => {
|
|
|
1470
1619
|
var Nadia = class {
|
|
1471
1620
|
client;
|
|
1472
1621
|
retries;
|
|
1622
|
+
/** For the bytes of an upload, which go to the upload host, not the API. */
|
|
1623
|
+
fetchImpl;
|
|
1473
1624
|
constructor(apiKey, options = {}) {
|
|
1474
1625
|
if (!apiKey) {
|
|
1475
1626
|
throw new Error("An API key is required.");
|
|
1476
1627
|
}
|
|
1477
1628
|
const opts = typeof options === "string" ? { baseUrl: options } : options;
|
|
1478
1629
|
this.retries = opts.retries ?? 2;
|
|
1630
|
+
this.fetchImpl = opts.fetch ?? ((input, init) => fetch(input, init));
|
|
1479
1631
|
this.client = client;
|
|
1480
1632
|
this.client.setConfig({
|
|
1481
1633
|
baseUrl: opts.baseUrl ?? DEFAULT_BASE_URL,
|
|
@@ -1521,10 +1673,68 @@ var Nadia = class {
|
|
|
1521
1673
|
(o) => listPosts({ ...o, query })
|
|
1522
1674
|
);
|
|
1523
1675
|
}
|
|
1524
|
-
/**
|
|
1525
|
-
|
|
1676
|
+
/**
|
|
1677
|
+
* Upload a file and get a URL usable in a post: a path on disk, or a
|
|
1678
|
+
* `Blob` / `File` with its name.
|
|
1679
|
+
*
|
|
1680
|
+
* An MP4, JPEG, PNG, WebP or GIF goes in parts of 20 MB straight to the
|
|
1681
|
+
* storage (`POST /public/v1/uploads`, then its confirm): four parts at a
|
|
1682
|
+
* time, a part cut by the network sent again, and the parts the confirm
|
|
1683
|
+
* says are missing sent again before confirming once more. A server that
|
|
1684
|
+
* does not take parts answers a single PUT, which is done instead; a
|
|
1685
|
+
* server without that route (older, or self-hosted on an older release)
|
|
1686
|
+
* and any other type (HEIC, MOV… which the server converts) go through
|
|
1687
|
+
* `POST /public/v1/upload`, the whole file in one request, as before.
|
|
1688
|
+
*
|
|
1689
|
+
* Resolves to the media: `id` and `path` always (what a post takes),
|
|
1690
|
+
* plus `size`, `duration`, `width`, `height`, `codec` when it went in
|
|
1691
|
+
* parts or in a single PUT.
|
|
1692
|
+
*/
|
|
1693
|
+
async upload(file, filename) {
|
|
1694
|
+
const source = await openSource(file, filename);
|
|
1695
|
+
const type = directType(source.name, source.blob.type);
|
|
1696
|
+
if (!type) return this.uploadWhole(source);
|
|
1697
|
+
let opened;
|
|
1698
|
+
try {
|
|
1699
|
+
opened = await this.call(
|
|
1700
|
+
(o) => createUpload({
|
|
1701
|
+
...o,
|
|
1702
|
+
body: { filename: source.name, contentType: type, size: source.blob.size }
|
|
1703
|
+
})
|
|
1704
|
+
);
|
|
1705
|
+
} catch (err) {
|
|
1706
|
+
if (err instanceof NadiaError && (err.status === 404 || err.status === 405)) {
|
|
1707
|
+
return this.uploadWhole(source);
|
|
1708
|
+
}
|
|
1709
|
+
throw err;
|
|
1710
|
+
}
|
|
1711
|
+
if (opened.parts) {
|
|
1712
|
+
await this.sendParts(opened, source.blob, range(1, opened.parts));
|
|
1713
|
+
} else {
|
|
1714
|
+
await this.sendWhole(opened, source.blob);
|
|
1715
|
+
}
|
|
1716
|
+
for (let round = 1; ; round++) {
|
|
1717
|
+
try {
|
|
1718
|
+
return await this.call(
|
|
1719
|
+
(o) => confirmUpload({ ...o, path: { uploadId: opened.uploadId } })
|
|
1720
|
+
);
|
|
1721
|
+
} catch (err) {
|
|
1722
|
+
if (!(err instanceof NadiaError) || err.status !== 409 || round >= UPLOAD_ROUNDS) throw err;
|
|
1723
|
+
const missing = missingParts(err.body);
|
|
1724
|
+
if (missing.length && opened.parts) {
|
|
1725
|
+
await this.sendParts(opened, source.blob, missing);
|
|
1726
|
+
} else if (/^CONFIRM_IN_PROGRESS/.test(err.message)) {
|
|
1727
|
+
await sleep(3e3);
|
|
1728
|
+
} else {
|
|
1729
|
+
throw err;
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
/** The whole file in one multipart request: `POST /public/v1/upload`. */
|
|
1735
|
+
uploadWhole(source) {
|
|
1526
1736
|
const form = new FormData();
|
|
1527
|
-
form.append("file",
|
|
1737
|
+
form.append("file", source.blob, source.name);
|
|
1528
1738
|
return this.call(
|
|
1529
1739
|
(o) => uploadFile({
|
|
1530
1740
|
...o,
|
|
@@ -1533,6 +1743,58 @@ var Nadia = class {
|
|
|
1533
1743
|
})
|
|
1534
1744
|
);
|
|
1535
1745
|
}
|
|
1746
|
+
/** Each part to `<uploadUrl>/<n>`, a few at a time, each retried. */
|
|
1747
|
+
async sendParts(opened, blob, numbers) {
|
|
1748
|
+
const queue = [...numbers];
|
|
1749
|
+
const size = opened.partSize;
|
|
1750
|
+
const worker = async () => {
|
|
1751
|
+
for (let n = queue.shift(); n !== void 0; n = queue.shift()) {
|
|
1752
|
+
const from = (n - 1) * size;
|
|
1753
|
+
await this.put(`${opened.uploadUrl}/${n}`, blob.slice(from, Math.min(from + size, blob.size)), {
|
|
1754
|
+
"Content-Type": "application/octet-stream"
|
|
1755
|
+
}, 200);
|
|
1756
|
+
}
|
|
1757
|
+
};
|
|
1758
|
+
await Promise.all(Array.from({ length: Math.min(PARALLEL_PARTS, queue.length) }, worker));
|
|
1759
|
+
}
|
|
1760
|
+
/** The single PUT of a server that takes no parts. */
|
|
1761
|
+
sendWhole(opened, blob) {
|
|
1762
|
+
const headers = Object.fromEntries(
|
|
1763
|
+
Object.entries(opened.headers ?? {}).filter(([k]) => k.toLowerCase() !== "content-length")
|
|
1764
|
+
);
|
|
1765
|
+
return this.put(opened.uploadUrl, blob, headers, 201);
|
|
1766
|
+
}
|
|
1767
|
+
/**
|
|
1768
|
+
* A PUT of raw bytes, without the API key (the URL is the credential):
|
|
1769
|
+
* three tries on a network error, a 5xx or a 429, none on anything else.
|
|
1770
|
+
*/
|
|
1771
|
+
async put(url, body, headers, ok) {
|
|
1772
|
+
let last;
|
|
1773
|
+
for (let attempt = 1; attempt <= PART_TRIES; attempt++) {
|
|
1774
|
+
let response;
|
|
1775
|
+
try {
|
|
1776
|
+
response = await this.fetchImpl(url, { method: "PUT", headers, body });
|
|
1777
|
+
} catch (err) {
|
|
1778
|
+
last = new NadiaError(0, err, `The upload of ${url.replace(/\/v2\/[^/]+/, "/v2/\u2026")} did not complete.`);
|
|
1779
|
+
}
|
|
1780
|
+
if (response) {
|
|
1781
|
+
if (response.status === ok || response.ok) {
|
|
1782
|
+
await response.body?.cancel();
|
|
1783
|
+
return;
|
|
1784
|
+
}
|
|
1785
|
+
const text = await response.text();
|
|
1786
|
+
let parsed = text;
|
|
1787
|
+
try {
|
|
1788
|
+
parsed = JSON.parse(text);
|
|
1789
|
+
} catch {
|
|
1790
|
+
}
|
|
1791
|
+
last = new NadiaError(response.status, parsed, messageOf(parsed) ?? `The upload answered ${response.status}`);
|
|
1792
|
+
if (!last.isTransient) throw last;
|
|
1793
|
+
}
|
|
1794
|
+
if (attempt < PART_TRIES) await sleep(attempt * 1e3);
|
|
1795
|
+
}
|
|
1796
|
+
throw last;
|
|
1797
|
+
}
|
|
1536
1798
|
/** List your connected channels. */
|
|
1537
1799
|
integrations() {
|
|
1538
1800
|
return this.call((o) => listChannels(o));
|
|
@@ -1725,13 +1987,17 @@ function parseWebhook(options) {
|
|
|
1725
1987
|
Nadia,
|
|
1726
1988
|
NadiaError,
|
|
1727
1989
|
NadiaWebhookError,
|
|
1728
|
-
|
|
1990
|
+
catchUpAutomationPose,
|
|
1729
1991
|
changePostStatus,
|
|
1730
1992
|
checkConnection,
|
|
1993
|
+
confirmUpload,
|
|
1731
1994
|
createAutomationFlow,
|
|
1732
1995
|
createContent,
|
|
1996
|
+
createContentFromLink,
|
|
1733
1997
|
createPost,
|
|
1998
|
+
createUpload,
|
|
1734
1999
|
createWebhook,
|
|
2000
|
+
createWorkspace,
|
|
1735
2001
|
deleteAutomationFlow,
|
|
1736
2002
|
deleteAutomationPose,
|
|
1737
2003
|
deleteChannel,
|
|
@@ -1740,8 +2006,8 @@ function parseWebhook(options) {
|
|
|
1740
2006
|
deletePost,
|
|
1741
2007
|
deletePostGroup,
|
|
1742
2008
|
deleteWebhook,
|
|
2009
|
+
deleteWorkspace,
|
|
1743
2010
|
findSlot,
|
|
1744
|
-
generateVideo,
|
|
1745
2011
|
getAccountHistory,
|
|
1746
2012
|
getAutomationFlow,
|
|
1747
2013
|
getAutomationPose,
|
|
@@ -1752,11 +2018,15 @@ function parseWebhook(options) {
|
|
|
1752
2018
|
getConversation,
|
|
1753
2019
|
getHookForms,
|
|
1754
2020
|
getMusicTrack,
|
|
2021
|
+
getPost,
|
|
1755
2022
|
getPostAnalytics,
|
|
2023
|
+
getPostAutomation,
|
|
2024
|
+
getPostingTimes,
|
|
2025
|
+
getSubscription,
|
|
1756
2026
|
getVideoHistory,
|
|
2027
|
+
getViewsPerDay,
|
|
1757
2028
|
getWebhook,
|
|
1758
2029
|
hideComment,
|
|
1759
|
-
importHooks,
|
|
1760
2030
|
importMusic,
|
|
1761
2031
|
linkContentPost,
|
|
1762
2032
|
listAutomationFlowPoses,
|
|
@@ -1779,13 +2049,15 @@ function parseWebhook(options) {
|
|
|
1779
2049
|
listVideoPerformance,
|
|
1780
2050
|
listWebhookEvents,
|
|
1781
2051
|
listWebhooks,
|
|
2052
|
+
listWorkspaces,
|
|
1782
2053
|
moveContent,
|
|
1783
2054
|
parseWebhook,
|
|
1784
2055
|
pollAutomationPose,
|
|
1785
2056
|
pollInbox,
|
|
1786
2057
|
poseAutomationFlow,
|
|
1787
2058
|
previewAutomationEmail,
|
|
1788
|
-
|
|
2059
|
+
previewAutomationPoseCatchUp,
|
|
2060
|
+
removePostAutomation,
|
|
1789
2061
|
replayAutomationPose,
|
|
1790
2062
|
replyToComment,
|
|
1791
2063
|
runChannelTool,
|
|
@@ -1793,13 +2065,19 @@ function parseWebhook(options) {
|
|
|
1793
2065
|
sendAutomationTestEmail,
|
|
1794
2066
|
sendDirectMessage,
|
|
1795
2067
|
setAutomationFlowStatus,
|
|
2068
|
+
setPostAutomation,
|
|
2069
|
+
setPostCover,
|
|
2070
|
+
setPostPublication,
|
|
1796
2071
|
setPostReleaseId,
|
|
2072
|
+
setPostingTimes,
|
|
1797
2073
|
startChannelConnection,
|
|
1798
2074
|
subscribeInboxWebhook,
|
|
1799
2075
|
testWebhook,
|
|
1800
2076
|
updateAutomationFlow,
|
|
1801
2077
|
updateAutomationPose,
|
|
1802
2078
|
updateContent,
|
|
2079
|
+
updateWorkspace,
|
|
2080
|
+
uploadContentType,
|
|
1803
2081
|
uploadFile,
|
|
1804
2082
|
uploadFromUrl,
|
|
1805
2083
|
uploadMusicFile,
|