@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/README.md +33 -4
- package/dist/index.d.mts +2191 -325
- package/dist/index.d.ts +2191 -325
- package/dist/index.js +403 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +370 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -834,11 +834,53 @@ var uploadFromUrl = (options) => (options.client ?? client).post({
|
|
|
834
834
|
...options.headers
|
|
835
835
|
}
|
|
836
836
|
});
|
|
837
|
+
var getUploadFromUrl = (options) => (options.client ?? client).get({
|
|
838
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
839
|
+
url: "/public/v1/upload-from-url/{importId}",
|
|
840
|
+
...options
|
|
841
|
+
});
|
|
842
|
+
var createUpload = (options) => (options.client ?? client).post({
|
|
843
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
844
|
+
url: "/public/v1/uploads",
|
|
845
|
+
...options,
|
|
846
|
+
headers: {
|
|
847
|
+
"Content-Type": "application/json",
|
|
848
|
+
...options.headers
|
|
849
|
+
}
|
|
850
|
+
});
|
|
851
|
+
var confirmUpload = (options) => (options.client ?? client).post({
|
|
852
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
853
|
+
url: "/public/v1/uploads/{uploadId}/confirm",
|
|
854
|
+
...options
|
|
855
|
+
});
|
|
856
|
+
var setMediaWorkspaces = (options) => (options.client ?? client).put({
|
|
857
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
858
|
+
url: "/public/v1/media/{id}/workspaces",
|
|
859
|
+
...options,
|
|
860
|
+
headers: {
|
|
861
|
+
"Content-Type": "application/json",
|
|
862
|
+
...options.headers
|
|
863
|
+
}
|
|
864
|
+
});
|
|
837
865
|
var findSlot = (options) => (options.client ?? client).get({
|
|
838
866
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
839
867
|
url: "/public/v1/find-slot/{id}",
|
|
840
868
|
...options
|
|
841
869
|
});
|
|
870
|
+
var getPostingTimes = (options) => (options.client ?? client).get({
|
|
871
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
872
|
+
url: "/public/v1/integrations/{id}/posting-times",
|
|
873
|
+
...options
|
|
874
|
+
});
|
|
875
|
+
var setPostingTimes = (options) => (options.client ?? client).put({
|
|
876
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
877
|
+
url: "/public/v1/integrations/{id}/posting-times",
|
|
878
|
+
...options,
|
|
879
|
+
headers: {
|
|
880
|
+
"Content-Type": "application/json",
|
|
881
|
+
...options.headers
|
|
882
|
+
}
|
|
883
|
+
});
|
|
842
884
|
var listPosts = (options) => (options.client ?? client).get({
|
|
843
885
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
844
886
|
url: "/public/v1/posts",
|
|
@@ -858,6 +900,11 @@ var deletePost = (options) => (options.client ?? client).delete({
|
|
|
858
900
|
url: "/public/v1/posts/{id}",
|
|
859
901
|
...options
|
|
860
902
|
});
|
|
903
|
+
var getPost = (options) => (options.client ?? client).get({
|
|
904
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
905
|
+
url: "/public/v1/posts/{id}",
|
|
906
|
+
...options
|
|
907
|
+
});
|
|
861
908
|
var deletePostGroup = (options) => (options.client ?? client).delete({
|
|
862
909
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
863
910
|
url: "/public/v1/posts/group/{group}",
|
|
@@ -868,6 +915,25 @@ var checkConnection = (options) => (options?.client ?? client).get({
|
|
|
868
915
|
url: "/public/v1/is-connected",
|
|
869
916
|
...options
|
|
870
917
|
});
|
|
918
|
+
var listWorkspaces = (options) => (options?.client ?? client).get({
|
|
919
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
920
|
+
url: "/public/v1/workspaces",
|
|
921
|
+
...options
|
|
922
|
+
});
|
|
923
|
+
var createWorkspace = (options) => (options.client ?? client).post({
|
|
924
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
925
|
+
url: "/public/v1/workspaces",
|
|
926
|
+
...options,
|
|
927
|
+
headers: {
|
|
928
|
+
"Content-Type": "application/json",
|
|
929
|
+
...options.headers
|
|
930
|
+
}
|
|
931
|
+
});
|
|
932
|
+
var getSubscription = (options) => (options?.client ?? client).get({
|
|
933
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
934
|
+
url: "/public/v1/subscription",
|
|
935
|
+
...options
|
|
936
|
+
});
|
|
871
937
|
var listGroups = (options) => (options?.client ?? client).get({
|
|
872
938
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
873
939
|
url: "/public/v1/groups",
|
|
@@ -888,24 +954,6 @@ var listNotifications = (options) => (options?.client ?? client).get({
|
|
|
888
954
|
url: "/public/v1/notifications",
|
|
889
955
|
...options
|
|
890
956
|
});
|
|
891
|
-
var generateVideo = (options) => (options.client ?? client).post({
|
|
892
|
-
security: [{ name: "Authorization", type: "apiKey" }],
|
|
893
|
-
url: "/public/v1/generate-video",
|
|
894
|
-
...options,
|
|
895
|
-
headers: {
|
|
896
|
-
"Content-Type": "application/json",
|
|
897
|
-
...options.headers
|
|
898
|
-
}
|
|
899
|
-
});
|
|
900
|
-
var callVideoFunction = (options) => (options.client ?? client).post({
|
|
901
|
-
security: [{ name: "Authorization", type: "apiKey" }],
|
|
902
|
-
url: "/public/v1/video/function",
|
|
903
|
-
...options,
|
|
904
|
-
headers: {
|
|
905
|
-
"Content-Type": "application/json",
|
|
906
|
-
...options.headers
|
|
907
|
-
}
|
|
908
|
-
});
|
|
909
957
|
var deleteChannel = (options) => (options.client ?? client).delete({
|
|
910
958
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
911
959
|
url: "/public/v1/integrations/{id}",
|
|
@@ -930,6 +978,25 @@ var changePostStatus = (options) => (options.client ?? client).put({
|
|
|
930
978
|
...options.headers
|
|
931
979
|
}
|
|
932
980
|
});
|
|
981
|
+
var removePostAutomation = (options) => (options.client ?? client).delete({
|
|
982
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
983
|
+
url: "/public/v1/posts/{id}/automation",
|
|
984
|
+
...options
|
|
985
|
+
});
|
|
986
|
+
var getPostAutomation = (options) => (options.client ?? client).get({
|
|
987
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
988
|
+
url: "/public/v1/posts/{id}/automation",
|
|
989
|
+
...options
|
|
990
|
+
});
|
|
991
|
+
var setPostAutomation = (options) => (options.client ?? client).put({
|
|
992
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
993
|
+
url: "/public/v1/posts/{id}/automation",
|
|
994
|
+
...options,
|
|
995
|
+
headers: {
|
|
996
|
+
"Content-Type": "application/json",
|
|
997
|
+
...options.headers
|
|
998
|
+
}
|
|
999
|
+
});
|
|
933
1000
|
var setPostReleaseId = (options) => (options.client ?? client).put({
|
|
934
1001
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
935
1002
|
url: "/public/v1/posts/{id}/release-id",
|
|
@@ -939,6 +1006,24 @@ var setPostReleaseId = (options) => (options.client ?? client).put({
|
|
|
939
1006
|
...options.headers
|
|
940
1007
|
}
|
|
941
1008
|
});
|
|
1009
|
+
var setPostCover = (options) => (options.client ?? client).put({
|
|
1010
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1011
|
+
url: "/public/v1/posts/{id}/cover",
|
|
1012
|
+
...options,
|
|
1013
|
+
headers: {
|
|
1014
|
+
"Content-Type": "application/json",
|
|
1015
|
+
...options.headers
|
|
1016
|
+
}
|
|
1017
|
+
});
|
|
1018
|
+
var setPostPublication = (options) => (options.client ?? client).put({
|
|
1019
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1020
|
+
url: "/public/v1/posts/{id}/publication",
|
|
1021
|
+
...options,
|
|
1022
|
+
headers: {
|
|
1023
|
+
"Content-Type": "application/json",
|
|
1024
|
+
...options.headers
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
942
1027
|
var getChannelAnalytics = (options) => (options.client ?? client).get({
|
|
943
1028
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
944
1029
|
url: "/public/v1/analytics/{integration}",
|
|
@@ -959,6 +1044,11 @@ var getVideoHistory = (options) => (options.client ?? client).get({
|
|
|
959
1044
|
url: "/public/v1/video-history/{integrationId}",
|
|
960
1045
|
...options
|
|
961
1046
|
});
|
|
1047
|
+
var getViewsPerDay = (options) => (options.client ?? client).get({
|
|
1048
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1049
|
+
url: "/public/v1/views-per-day/{integrationId}",
|
|
1050
|
+
...options
|
|
1051
|
+
});
|
|
962
1052
|
var getPostAnalytics = (options) => (options.client ?? client).get({
|
|
963
1053
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
964
1054
|
url: "/public/v1/analytics/post/{postId}",
|
|
@@ -1114,7 +1204,7 @@ var poseAutomationFlow = (options) => (options.client ?? client).post({
|
|
|
1114
1204
|
...options.headers
|
|
1115
1205
|
}
|
|
1116
1206
|
});
|
|
1117
|
-
var listChannelAutomationPoses = (options) => (options
|
|
1207
|
+
var listChannelAutomationPoses = (options) => (options?.client ?? client).get({
|
|
1118
1208
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1119
1209
|
url: "/public/v1/automation-flow-poses",
|
|
1120
1210
|
...options
|
|
@@ -1157,6 +1247,16 @@ var replayAutomationPose = (options) => (options.client ?? client).post({
|
|
|
1157
1247
|
...options.headers
|
|
1158
1248
|
}
|
|
1159
1249
|
});
|
|
1250
|
+
var previewAutomationPoseCatchUp = (options) => (options.client ?? client).get({
|
|
1251
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1252
|
+
url: "/public/v1/automation-flow-poses/{id}/catch-up",
|
|
1253
|
+
...options
|
|
1254
|
+
});
|
|
1255
|
+
var catchUpAutomationPose = (options) => (options.client ?? client).post({
|
|
1256
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1257
|
+
url: "/public/v1/automation-flow-poses/{id}/catch-up",
|
|
1258
|
+
...options
|
|
1259
|
+
});
|
|
1160
1260
|
var listWebhookEvents = (options) => (options?.client ?? client).get({
|
|
1161
1261
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1162
1262
|
url: "/public/v1/webhooks/events",
|
|
@@ -1242,6 +1342,15 @@ var upsertContent = (options) => (options.client ?? client).post({
|
|
|
1242
1342
|
...options.headers
|
|
1243
1343
|
}
|
|
1244
1344
|
});
|
|
1345
|
+
var createContentFromLink = (options) => (options.client ?? client).post({
|
|
1346
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1347
|
+
url: "/public/v1/contents/from-link",
|
|
1348
|
+
...options,
|
|
1349
|
+
headers: {
|
|
1350
|
+
"Content-Type": "application/json",
|
|
1351
|
+
...options.headers
|
|
1352
|
+
}
|
|
1353
|
+
});
|
|
1245
1354
|
var moveContent = (options) => (options.client ?? client).put({
|
|
1246
1355
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1247
1356
|
url: "/public/v1/contents/{id}/move",
|
|
@@ -1260,6 +1369,15 @@ var linkContentPost = (options) => (options.client ?? client).put({
|
|
|
1260
1369
|
...options.headers
|
|
1261
1370
|
}
|
|
1262
1371
|
});
|
|
1372
|
+
var setContentWorkspaces = (options) => (options.client ?? client).put({
|
|
1373
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1374
|
+
url: "/public/v1/contents/{id}/workspaces",
|
|
1375
|
+
...options,
|
|
1376
|
+
headers: {
|
|
1377
|
+
"Content-Type": "application/json",
|
|
1378
|
+
...options.headers
|
|
1379
|
+
}
|
|
1380
|
+
});
|
|
1263
1381
|
var searchHooks = (options) => (options?.client ?? client).get({
|
|
1264
1382
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1265
1383
|
url: "/public/v1/hooks",
|
|
@@ -1275,24 +1393,6 @@ var listHookFamilies = (options) => (options?.client ?? client).get({
|
|
|
1275
1393
|
url: "/public/v1/hooks/families",
|
|
1276
1394
|
...options
|
|
1277
1395
|
});
|
|
1278
|
-
var replaceHookFamilies = (options) => (options.client ?? client).put({
|
|
1279
|
-
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1280
|
-
url: "/public/v1/hooks/families",
|
|
1281
|
-
...options,
|
|
1282
|
-
headers: {
|
|
1283
|
-
"Content-Type": "application/json",
|
|
1284
|
-
...options.headers
|
|
1285
|
-
}
|
|
1286
|
-
});
|
|
1287
|
-
var importHooks = (options) => (options.client ?? client).post({
|
|
1288
|
-
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1289
|
-
url: "/public/v1/hooks/import",
|
|
1290
|
-
...options,
|
|
1291
|
-
headers: {
|
|
1292
|
-
"Content-Type": "application/json",
|
|
1293
|
-
...options.headers
|
|
1294
|
-
}
|
|
1295
|
-
});
|
|
1296
1396
|
var listMusic = (options) => (options?.client ?? client).get({
|
|
1297
1397
|
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1298
1398
|
url: "/public/v1/music",
|
|
@@ -1327,6 +1427,20 @@ var uploadMusicFile = (options) => (options.client ?? client).put({
|
|
|
1327
1427
|
...options.headers
|
|
1328
1428
|
}
|
|
1329
1429
|
});
|
|
1430
|
+
var deleteWorkspace = (options) => (options.client ?? client).delete({
|
|
1431
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1432
|
+
url: "/public/v1/workspaces/{id}",
|
|
1433
|
+
...options
|
|
1434
|
+
});
|
|
1435
|
+
var updateWorkspace = (options) => (options.client ?? client).put({
|
|
1436
|
+
security: [{ name: "Authorization", type: "apiKey" }],
|
|
1437
|
+
url: "/public/v1/workspaces/{id}",
|
|
1438
|
+
...options,
|
|
1439
|
+
headers: {
|
|
1440
|
+
"Content-Type": "application/json",
|
|
1441
|
+
...options.headers
|
|
1442
|
+
}
|
|
1443
|
+
});
|
|
1330
1444
|
|
|
1331
1445
|
// src/index.ts
|
|
1332
1446
|
var DEFAULT_BASE_URL = "https://app.usenadia.com/api";
|
|
@@ -1349,6 +1463,39 @@ var NadiaError = class _NadiaError extends Error {
|
|
|
1349
1463
|
}
|
|
1350
1464
|
};
|
|
1351
1465
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1466
|
+
var isUrlImport = (v) => !!v && typeof v === "object" && typeof v.id === "string" && typeof v.status === "string" && !("path" in v);
|
|
1467
|
+
var DIRECT_TYPES = {
|
|
1468
|
+
mp4: "video/mp4",
|
|
1469
|
+
jpg: "image/jpeg",
|
|
1470
|
+
jpeg: "image/jpeg",
|
|
1471
|
+
png: "image/png",
|
|
1472
|
+
webp: "image/webp",
|
|
1473
|
+
gif: "image/gif"
|
|
1474
|
+
};
|
|
1475
|
+
var PARALLEL_PARTS = 4;
|
|
1476
|
+
var PART_TRIES = 3;
|
|
1477
|
+
var UPLOAD_ROUNDS = 4;
|
|
1478
|
+
function directType(name, blobType) {
|
|
1479
|
+
const ext = /\.([a-z0-9]+)$/i.exec(name)?.[1]?.toLowerCase();
|
|
1480
|
+
if (ext && DIRECT_TYPES[ext]) return DIRECT_TYPES[ext];
|
|
1481
|
+
return Object.values(DIRECT_TYPES).includes(blobType) ? blobType : void 0;
|
|
1482
|
+
}
|
|
1483
|
+
var uploadContentType = (filename) => directType(filename, "");
|
|
1484
|
+
async function openSource(file, filename) {
|
|
1485
|
+
if (typeof file !== "string") {
|
|
1486
|
+
const own = file.name;
|
|
1487
|
+
return { blob: file, name: filename ?? (own || "upload") };
|
|
1488
|
+
}
|
|
1489
|
+
const fs = await import("fs");
|
|
1490
|
+
const { basename } = await import("path");
|
|
1491
|
+
const blob = typeof fs.openAsBlob === "function" ? await fs.openAsBlob(file) : new Blob([await fs.promises.readFile(file)]);
|
|
1492
|
+
return { blob, name: filename ?? basename(file) };
|
|
1493
|
+
}
|
|
1494
|
+
var range = (from, to) => Array.from({ length: to - from + 1 }, (_, i) => from + i);
|
|
1495
|
+
function missingParts(body) {
|
|
1496
|
+
const list = body?.missingParts;
|
|
1497
|
+
return Array.isArray(list) ? list.filter((n) => Number.isInteger(n) && n > 0) : [];
|
|
1498
|
+
}
|
|
1352
1499
|
var messageOf = (body) => {
|
|
1353
1500
|
if (!body || typeof body !== "object") return void 0;
|
|
1354
1501
|
const { msg, message } = body;
|
|
@@ -1362,12 +1509,20 @@ var messageOf = (body) => {
|
|
|
1362
1509
|
var Nadia = class {
|
|
1363
1510
|
client;
|
|
1364
1511
|
retries;
|
|
1512
|
+
/** For the bytes of an upload, which go to the upload host, not the API. */
|
|
1513
|
+
fetchImpl;
|
|
1514
|
+
importPoll;
|
|
1365
1515
|
constructor(apiKey, options = {}) {
|
|
1366
1516
|
if (!apiKey) {
|
|
1367
1517
|
throw new Error("An API key is required.");
|
|
1368
1518
|
}
|
|
1369
1519
|
const opts = typeof options === "string" ? { baseUrl: options } : options;
|
|
1370
1520
|
this.retries = opts.retries ?? 2;
|
|
1521
|
+
this.fetchImpl = opts.fetch ?? ((input, init) => fetch(input, init));
|
|
1522
|
+
this.importPoll = {
|
|
1523
|
+
intervalMs: opts.importPoll?.intervalMs ?? 3e3,
|
|
1524
|
+
timeoutMs: opts.importPoll?.timeoutMs ?? 15 * 60 * 1e3
|
|
1525
|
+
};
|
|
1371
1526
|
this.client = client;
|
|
1372
1527
|
this.client.setConfig({
|
|
1373
1528
|
baseUrl: opts.baseUrl ?? DEFAULT_BASE_URL,
|
|
@@ -1413,10 +1568,110 @@ var Nadia = class {
|
|
|
1413
1568
|
(o) => listPosts({ ...o, query })
|
|
1414
1569
|
);
|
|
1415
1570
|
}
|
|
1416
|
-
/**
|
|
1417
|
-
|
|
1571
|
+
/**
|
|
1572
|
+
* Upload a file and get a URL usable in a post: a path on disk, or a
|
|
1573
|
+
* `Blob` / `File` with its name.
|
|
1574
|
+
*
|
|
1575
|
+
* An MP4, JPEG, PNG, WebP or GIF goes in parts of 20 MB straight to the
|
|
1576
|
+
* storage (`POST /public/v1/uploads`, then its confirm): four parts at a
|
|
1577
|
+
* time, a part cut by the network sent again, and the parts the confirm
|
|
1578
|
+
* says are missing sent again before confirming once more. A server that
|
|
1579
|
+
* does not take parts answers a single PUT, which is done instead; a
|
|
1580
|
+
* server without that route (older, or self-hosted on an older release)
|
|
1581
|
+
* and any other type (HEIC… which the server converts to JPEG) go through
|
|
1582
|
+
* `POST /public/v1/upload`, the whole file in one request, as before. A
|
|
1583
|
+
* MOV or an M4V is refused there (`415`): convert it to MP4 first.
|
|
1584
|
+
*
|
|
1585
|
+
* Resolves to the media: `id` and `path` always (what a post takes),
|
|
1586
|
+
* plus `size`, `duration`, `width`, `height`, `codec` when it went in
|
|
1587
|
+
* parts or in a single PUT.
|
|
1588
|
+
*/
|
|
1589
|
+
async upload(file, filename) {
|
|
1590
|
+
const source = await openSource(file, filename);
|
|
1591
|
+
const type = directType(source.name, source.blob.type);
|
|
1592
|
+
if (!type) return this.uploadWhole(source);
|
|
1593
|
+
let opened;
|
|
1594
|
+
try {
|
|
1595
|
+
opened = await this.call(
|
|
1596
|
+
(o) => createUpload({
|
|
1597
|
+
...o,
|
|
1598
|
+
body: { filename: source.name, contentType: type, size: source.blob.size }
|
|
1599
|
+
})
|
|
1600
|
+
);
|
|
1601
|
+
} catch (err) {
|
|
1602
|
+
if (err instanceof NadiaError && (err.status === 404 || err.status === 405)) {
|
|
1603
|
+
return this.uploadWhole(source);
|
|
1604
|
+
}
|
|
1605
|
+
throw err;
|
|
1606
|
+
}
|
|
1607
|
+
if (opened.parts) {
|
|
1608
|
+
await this.sendParts(opened, source.blob, range(1, opened.parts));
|
|
1609
|
+
} else {
|
|
1610
|
+
await this.sendWhole(opened, source.blob);
|
|
1611
|
+
}
|
|
1612
|
+
for (let round = 1; ; round++) {
|
|
1613
|
+
try {
|
|
1614
|
+
return await this.call(
|
|
1615
|
+
(o) => confirmUpload({ ...o, path: { uploadId: opened.uploadId } })
|
|
1616
|
+
);
|
|
1617
|
+
} catch (err) {
|
|
1618
|
+
if (!(err instanceof NadiaError) || err.status !== 409 || round >= UPLOAD_ROUNDS) throw err;
|
|
1619
|
+
const missing = missingParts(err.body);
|
|
1620
|
+
if (missing.length && opened.parts) {
|
|
1621
|
+
await this.sendParts(opened, source.blob, missing);
|
|
1622
|
+
} else if (/^CONFIRM_IN_PROGRESS/.test(err.message)) {
|
|
1623
|
+
await sleep(3e3);
|
|
1624
|
+
} else {
|
|
1625
|
+
throw err;
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
/**
|
|
1631
|
+
* Import a file from a public HTTPS URL into the media library
|
|
1632
|
+
* (`POST /public/v1/upload-from-url`): the path of the URL ends in `.png`,
|
|
1633
|
+
* `.jpg`, `.jpeg`, `.gif`, `.webp` or `.mp4`.
|
|
1634
|
+
*
|
|
1635
|
+
* A long import (not done within 25 s) is answered `202` by the server and
|
|
1636
|
+
* goes on there; it is read again here (`GET
|
|
1637
|
+
* /public/v1/upload-from-url/{importId}`) until it ends. Resolves to the
|
|
1638
|
+
* media either way; a failed import throws the `NadiaError` the server
|
|
1639
|
+
* would have answered at once (its status and `msg`).
|
|
1640
|
+
*/
|
|
1641
|
+
async uploadFromUrl(url) {
|
|
1642
|
+
const first = await this.call((o) => uploadFromUrl({ ...o, body: { url } }));
|
|
1643
|
+
return this.importEnd(first);
|
|
1644
|
+
}
|
|
1645
|
+
/**
|
|
1646
|
+
* The end of an import from a URL: the media at once (`201`), or an import
|
|
1647
|
+
* (`202`) read again every few seconds until it is done or failed.
|
|
1648
|
+
*/
|
|
1649
|
+
async importEnd(answer) {
|
|
1650
|
+
if (!isUrlImport(answer)) return answer;
|
|
1651
|
+
const deadline = Date.now() + this.importPoll.timeoutMs;
|
|
1652
|
+
let current = answer;
|
|
1653
|
+
while (current.status === "running") {
|
|
1654
|
+
if (Date.now() >= deadline) {
|
|
1655
|
+
throw new NadiaError(
|
|
1656
|
+
504,
|
|
1657
|
+
current,
|
|
1658
|
+
`The import from a URL ${current.id} did not end within ${Math.round(this.importPoll.timeoutMs / 1e3)} s: read it again with getUploadFromUrl.`
|
|
1659
|
+
);
|
|
1660
|
+
}
|
|
1661
|
+
await sleep(this.importPoll.intervalMs);
|
|
1662
|
+
const id = current.id;
|
|
1663
|
+
current = await this.call(
|
|
1664
|
+
(o) => getUploadFromUrl({ ...o, path: { importId: id } })
|
|
1665
|
+
);
|
|
1666
|
+
}
|
|
1667
|
+
if (current.status === "done" && current.media) return current.media;
|
|
1668
|
+
const error = current.error ?? { statusCode: 500, msg: "The import from a URL failed." };
|
|
1669
|
+
throw new NadiaError(error.statusCode, { msg: error.msg }, error.msg);
|
|
1670
|
+
}
|
|
1671
|
+
/** The whole file in one multipart request: `POST /public/v1/upload`. */
|
|
1672
|
+
uploadWhole(source) {
|
|
1418
1673
|
const form = new FormData();
|
|
1419
|
-
form.append("file",
|
|
1674
|
+
form.append("file", source.blob, source.name);
|
|
1420
1675
|
return this.call(
|
|
1421
1676
|
(o) => uploadFile({
|
|
1422
1677
|
...o,
|
|
@@ -1425,6 +1680,58 @@ var Nadia = class {
|
|
|
1425
1680
|
})
|
|
1426
1681
|
);
|
|
1427
1682
|
}
|
|
1683
|
+
/** Each part to `<uploadUrl>/<n>`, a few at a time, each retried. */
|
|
1684
|
+
async sendParts(opened, blob, numbers) {
|
|
1685
|
+
const queue = [...numbers];
|
|
1686
|
+
const size = opened.partSize;
|
|
1687
|
+
const worker = async () => {
|
|
1688
|
+
for (let n = queue.shift(); n !== void 0; n = queue.shift()) {
|
|
1689
|
+
const from = (n - 1) * size;
|
|
1690
|
+
await this.put(`${opened.uploadUrl}/${n}`, blob.slice(from, Math.min(from + size, blob.size)), {
|
|
1691
|
+
"Content-Type": "application/octet-stream"
|
|
1692
|
+
}, 200);
|
|
1693
|
+
}
|
|
1694
|
+
};
|
|
1695
|
+
await Promise.all(Array.from({ length: Math.min(PARALLEL_PARTS, queue.length) }, worker));
|
|
1696
|
+
}
|
|
1697
|
+
/** The single PUT of a server that takes no parts. */
|
|
1698
|
+
sendWhole(opened, blob) {
|
|
1699
|
+
const headers = Object.fromEntries(
|
|
1700
|
+
Object.entries(opened.headers ?? {}).filter(([k]) => k.toLowerCase() !== "content-length")
|
|
1701
|
+
);
|
|
1702
|
+
return this.put(opened.uploadUrl, blob, headers, 201);
|
|
1703
|
+
}
|
|
1704
|
+
/**
|
|
1705
|
+
* A PUT of raw bytes, without the API key (the URL is the credential):
|
|
1706
|
+
* three tries on a network error, a 5xx or a 429, none on anything else.
|
|
1707
|
+
*/
|
|
1708
|
+
async put(url, body, headers, ok) {
|
|
1709
|
+
let last;
|
|
1710
|
+
for (let attempt = 1; attempt <= PART_TRIES; attempt++) {
|
|
1711
|
+
let response;
|
|
1712
|
+
try {
|
|
1713
|
+
response = await this.fetchImpl(url, { method: "PUT", headers, body });
|
|
1714
|
+
} catch (err) {
|
|
1715
|
+
last = new NadiaError(0, err, `The upload of ${url.replace(/\/v2\/[^/]+/, "/v2/\u2026")} did not complete.`);
|
|
1716
|
+
}
|
|
1717
|
+
if (response) {
|
|
1718
|
+
if (response.status === ok || response.ok) {
|
|
1719
|
+
await response.body?.cancel();
|
|
1720
|
+
return;
|
|
1721
|
+
}
|
|
1722
|
+
const text = await response.text();
|
|
1723
|
+
let parsed = text;
|
|
1724
|
+
try {
|
|
1725
|
+
parsed = JSON.parse(text);
|
|
1726
|
+
} catch {
|
|
1727
|
+
}
|
|
1728
|
+
last = new NadiaError(response.status, parsed, messageOf(parsed) ?? `The upload answered ${response.status}`);
|
|
1729
|
+
if (!last.isTransient) throw last;
|
|
1730
|
+
}
|
|
1731
|
+
if (attempt < PART_TRIES) await sleep(attempt * 1e3);
|
|
1732
|
+
}
|
|
1733
|
+
throw last;
|
|
1734
|
+
}
|
|
1428
1735
|
/** List your connected channels. */
|
|
1429
1736
|
integrations() {
|
|
1430
1737
|
return this.call((o) => listChannels(o));
|
|
@@ -1616,13 +1923,17 @@ export {
|
|
|
1616
1923
|
Nadia,
|
|
1617
1924
|
NadiaError,
|
|
1618
1925
|
NadiaWebhookError,
|
|
1619
|
-
|
|
1926
|
+
catchUpAutomationPose,
|
|
1620
1927
|
changePostStatus,
|
|
1621
1928
|
checkConnection,
|
|
1929
|
+
confirmUpload,
|
|
1622
1930
|
createAutomationFlow,
|
|
1623
1931
|
createContent,
|
|
1932
|
+
createContentFromLink,
|
|
1624
1933
|
createPost,
|
|
1934
|
+
createUpload,
|
|
1625
1935
|
createWebhook,
|
|
1936
|
+
createWorkspace,
|
|
1626
1937
|
index_default as default,
|
|
1627
1938
|
deleteAutomationFlow,
|
|
1628
1939
|
deleteAutomationPose,
|
|
@@ -1632,8 +1943,8 @@ export {
|
|
|
1632
1943
|
deletePost,
|
|
1633
1944
|
deletePostGroup,
|
|
1634
1945
|
deleteWebhook,
|
|
1946
|
+
deleteWorkspace,
|
|
1635
1947
|
findSlot,
|
|
1636
|
-
generateVideo,
|
|
1637
1948
|
getAccountHistory,
|
|
1638
1949
|
getAutomationFlow,
|
|
1639
1950
|
getAutomationPose,
|
|
@@ -1644,11 +1955,16 @@ export {
|
|
|
1644
1955
|
getConversation,
|
|
1645
1956
|
getHookForms,
|
|
1646
1957
|
getMusicTrack,
|
|
1958
|
+
getPost,
|
|
1647
1959
|
getPostAnalytics,
|
|
1960
|
+
getPostAutomation,
|
|
1961
|
+
getPostingTimes,
|
|
1962
|
+
getSubscription,
|
|
1963
|
+
getUploadFromUrl,
|
|
1648
1964
|
getVideoHistory,
|
|
1965
|
+
getViewsPerDay,
|
|
1649
1966
|
getWebhook,
|
|
1650
1967
|
hideComment,
|
|
1651
|
-
importHooks,
|
|
1652
1968
|
importMusic,
|
|
1653
1969
|
linkContentPost,
|
|
1654
1970
|
listAutomationFlowPoses,
|
|
@@ -1671,13 +1987,15 @@ export {
|
|
|
1671
1987
|
listVideoPerformance,
|
|
1672
1988
|
listWebhookEvents,
|
|
1673
1989
|
listWebhooks,
|
|
1990
|
+
listWorkspaces,
|
|
1674
1991
|
moveContent,
|
|
1675
1992
|
parseWebhook,
|
|
1676
1993
|
pollAutomationPose,
|
|
1677
1994
|
pollInbox,
|
|
1678
1995
|
poseAutomationFlow,
|
|
1679
1996
|
previewAutomationEmail,
|
|
1680
|
-
|
|
1997
|
+
previewAutomationPoseCatchUp,
|
|
1998
|
+
removePostAutomation,
|
|
1681
1999
|
replayAutomationPose,
|
|
1682
2000
|
replyToComment,
|
|
1683
2001
|
runChannelTool,
|
|
@@ -1685,13 +2003,21 @@ export {
|
|
|
1685
2003
|
sendAutomationTestEmail,
|
|
1686
2004
|
sendDirectMessage,
|
|
1687
2005
|
setAutomationFlowStatus,
|
|
2006
|
+
setContentWorkspaces,
|
|
2007
|
+
setMediaWorkspaces,
|
|
2008
|
+
setPostAutomation,
|
|
2009
|
+
setPostCover,
|
|
2010
|
+
setPostPublication,
|
|
1688
2011
|
setPostReleaseId,
|
|
2012
|
+
setPostingTimes,
|
|
1689
2013
|
startChannelConnection,
|
|
1690
2014
|
subscribeInboxWebhook,
|
|
1691
2015
|
testWebhook,
|
|
1692
2016
|
updateAutomationFlow,
|
|
1693
2017
|
updateAutomationPose,
|
|
1694
2018
|
updateContent,
|
|
2019
|
+
updateWorkspace,
|
|
2020
|
+
uploadContentType,
|
|
1695
2021
|
uploadFile,
|
|
1696
2022
|
uploadFromUrl,
|
|
1697
2023
|
uploadMusicFile,
|