naystack 1.8.15 → 1.8.16
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/auth/index.cjs.js +32 -10
- package/dist/auth/index.esm.js +32 -10
- package/dist/auth/instagram/index.cjs.js +32 -10
- package/dist/auth/instagram/index.esm.js +32 -10
- package/dist/auth/instagram/route.cjs.js +32 -10
- package/dist/auth/instagram/route.esm.js +32 -10
- package/dist/socials/index.cjs.js +48 -18
- package/dist/socials/index.d.mts +1 -1
- package/dist/socials/index.d.ts +1 -1
- package/dist/socials/index.esm.js +48 -18
- package/dist/socials/instagram/setters.cjs.js +42 -15
- package/dist/socials/instagram/setters.esm.js +42 -15
- package/dist/socials/instagram/types.d.mts +3 -1
- package/dist/socials/instagram/types.d.ts +3 -1
- package/dist/socials/meta/container.cjs.js +32 -10
- package/dist/socials/meta/container.d.mts +21 -3
- package/dist/socials/meta/container.d.ts +21 -3
- package/dist/socials/meta/container.esm.js +32 -10
- package/dist/socials/threads/setters.cjs.js +38 -13
- package/dist/socials/threads/setters.esm.js +38 -13
- package/dist/socials/threads/types.d.mts +3 -1
- package/dist/socials/threads/types.d.ts +3 -1
- package/package.json +1 -1
package/dist/auth/index.cjs.js
CHANGED
|
@@ -698,25 +698,47 @@ function createPublisher(platform) {
|
|
|
698
698
|
}
|
|
699
699
|
return true;
|
|
700
700
|
};
|
|
701
|
+
const createReady = async (token, params, label, wait, retry) => {
|
|
702
|
+
const attempts = Math.max(1, retry?.attempts ?? 3);
|
|
703
|
+
const backoffMS = retry?.backoffMS ?? 2e3;
|
|
704
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
705
|
+
const id = await platform.createContainer(token, params);
|
|
706
|
+
if (id && await isReady(token, id, label, wait)) return id;
|
|
707
|
+
if (attempt < attempts) {
|
|
708
|
+
const delay = backoffMS * 2 ** (attempt - 1);
|
|
709
|
+
console.warn(
|
|
710
|
+
`[naystack] ${platform.name} ${label} attempt ${attempt}/${attempts} failed \u2014 retrying in ${delay}ms`
|
|
711
|
+
);
|
|
712
|
+
await sleep(delay);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
return null;
|
|
716
|
+
};
|
|
701
717
|
return {
|
|
702
718
|
/** Creates a container, waits for it to finish processing, then publishes it. */
|
|
703
|
-
publish: async (token, params, wait) => {
|
|
704
|
-
const containerID = await
|
|
719
|
+
publish: async (token, params, wait, retry) => {
|
|
720
|
+
const containerID = await createReady(
|
|
721
|
+
token,
|
|
722
|
+
params,
|
|
723
|
+
"container",
|
|
724
|
+
wait,
|
|
725
|
+
retry
|
|
726
|
+
);
|
|
705
727
|
if (!containerID) return null;
|
|
706
|
-
if (!await isReady(token, containerID, "container", wait)) return null;
|
|
707
728
|
return platform.publish(token, containerID);
|
|
708
729
|
},
|
|
709
730
|
/** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
|
|
710
|
-
createChildren: async (token, items, wait) => {
|
|
731
|
+
createChildren: async (token, items, wait, retry) => {
|
|
711
732
|
const children = [];
|
|
712
733
|
for (const item of items) {
|
|
713
|
-
const childID = await
|
|
714
|
-
|
|
715
|
-
is_carousel_item: true
|
|
716
|
-
|
|
734
|
+
const childID = await createReady(
|
|
735
|
+
token,
|
|
736
|
+
{ ...item, is_carousel_item: true },
|
|
737
|
+
"carousel item",
|
|
738
|
+
wait,
|
|
739
|
+
retry
|
|
740
|
+
);
|
|
717
741
|
if (!childID) return null;
|
|
718
|
-
if (!await isReady(token, childID, "carousel item", wait))
|
|
719
|
-
return null;
|
|
720
742
|
children.push(childID);
|
|
721
743
|
}
|
|
722
744
|
return children;
|
package/dist/auth/index.esm.js
CHANGED
|
@@ -656,25 +656,47 @@ function createPublisher(platform) {
|
|
|
656
656
|
}
|
|
657
657
|
return true;
|
|
658
658
|
};
|
|
659
|
+
const createReady = async (token, params, label, wait, retry) => {
|
|
660
|
+
const attempts = Math.max(1, retry?.attempts ?? 3);
|
|
661
|
+
const backoffMS = retry?.backoffMS ?? 2e3;
|
|
662
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
663
|
+
const id = await platform.createContainer(token, params);
|
|
664
|
+
if (id && await isReady(token, id, label, wait)) return id;
|
|
665
|
+
if (attempt < attempts) {
|
|
666
|
+
const delay = backoffMS * 2 ** (attempt - 1);
|
|
667
|
+
console.warn(
|
|
668
|
+
`[naystack] ${platform.name} ${label} attempt ${attempt}/${attempts} failed \u2014 retrying in ${delay}ms`
|
|
669
|
+
);
|
|
670
|
+
await sleep(delay);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
return null;
|
|
674
|
+
};
|
|
659
675
|
return {
|
|
660
676
|
/** Creates a container, waits for it to finish processing, then publishes it. */
|
|
661
|
-
publish: async (token, params, wait) => {
|
|
662
|
-
const containerID = await
|
|
677
|
+
publish: async (token, params, wait, retry) => {
|
|
678
|
+
const containerID = await createReady(
|
|
679
|
+
token,
|
|
680
|
+
params,
|
|
681
|
+
"container",
|
|
682
|
+
wait,
|
|
683
|
+
retry
|
|
684
|
+
);
|
|
663
685
|
if (!containerID) return null;
|
|
664
|
-
if (!await isReady(token, containerID, "container", wait)) return null;
|
|
665
686
|
return platform.publish(token, containerID);
|
|
666
687
|
},
|
|
667
688
|
/** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
|
|
668
|
-
createChildren: async (token, items, wait) => {
|
|
689
|
+
createChildren: async (token, items, wait, retry) => {
|
|
669
690
|
const children = [];
|
|
670
691
|
for (const item of items) {
|
|
671
|
-
const childID = await
|
|
672
|
-
|
|
673
|
-
is_carousel_item: true
|
|
674
|
-
|
|
692
|
+
const childID = await createReady(
|
|
693
|
+
token,
|
|
694
|
+
{ ...item, is_carousel_item: true },
|
|
695
|
+
"carousel item",
|
|
696
|
+
wait,
|
|
697
|
+
retry
|
|
698
|
+
);
|
|
675
699
|
if (!childID) return null;
|
|
676
|
-
if (!await isReady(token, childID, "carousel item", wait))
|
|
677
|
-
return null;
|
|
678
700
|
children.push(childID);
|
|
679
701
|
}
|
|
680
702
|
return children;
|
|
@@ -221,25 +221,47 @@ function createPublisher(platform) {
|
|
|
221
221
|
}
|
|
222
222
|
return true;
|
|
223
223
|
};
|
|
224
|
+
const createReady = async (token, params, label, wait, retry) => {
|
|
225
|
+
const attempts = Math.max(1, retry?.attempts ?? 3);
|
|
226
|
+
const backoffMS = retry?.backoffMS ?? 2e3;
|
|
227
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
228
|
+
const id = await platform.createContainer(token, params);
|
|
229
|
+
if (id && await isReady(token, id, label, wait)) return id;
|
|
230
|
+
if (attempt < attempts) {
|
|
231
|
+
const delay = backoffMS * 2 ** (attempt - 1);
|
|
232
|
+
console.warn(
|
|
233
|
+
`[naystack] ${platform.name} ${label} attempt ${attempt}/${attempts} failed \u2014 retrying in ${delay}ms`
|
|
234
|
+
);
|
|
235
|
+
await sleep(delay);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
239
|
+
};
|
|
224
240
|
return {
|
|
225
241
|
/** Creates a container, waits for it to finish processing, then publishes it. */
|
|
226
|
-
publish: async (token, params, wait) => {
|
|
227
|
-
const containerID = await
|
|
242
|
+
publish: async (token, params, wait, retry) => {
|
|
243
|
+
const containerID = await createReady(
|
|
244
|
+
token,
|
|
245
|
+
params,
|
|
246
|
+
"container",
|
|
247
|
+
wait,
|
|
248
|
+
retry
|
|
249
|
+
);
|
|
228
250
|
if (!containerID) return null;
|
|
229
|
-
if (!await isReady(token, containerID, "container", wait)) return null;
|
|
230
251
|
return platform.publish(token, containerID);
|
|
231
252
|
},
|
|
232
253
|
/** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
|
|
233
|
-
createChildren: async (token, items, wait) => {
|
|
254
|
+
createChildren: async (token, items, wait, retry) => {
|
|
234
255
|
const children = [];
|
|
235
256
|
for (const item of items) {
|
|
236
|
-
const childID = await
|
|
237
|
-
|
|
238
|
-
is_carousel_item: true
|
|
239
|
-
|
|
257
|
+
const childID = await createReady(
|
|
258
|
+
token,
|
|
259
|
+
{ ...item, is_carousel_item: true },
|
|
260
|
+
"carousel item",
|
|
261
|
+
wait,
|
|
262
|
+
retry
|
|
263
|
+
);
|
|
240
264
|
if (!childID) return null;
|
|
241
|
-
if (!await isReady(token, childID, "carousel item", wait))
|
|
242
|
-
return null;
|
|
243
265
|
children.push(childID);
|
|
244
266
|
}
|
|
245
267
|
return children;
|
|
@@ -193,25 +193,47 @@ function createPublisher(platform) {
|
|
|
193
193
|
}
|
|
194
194
|
return true;
|
|
195
195
|
};
|
|
196
|
+
const createReady = async (token, params, label, wait, retry) => {
|
|
197
|
+
const attempts = Math.max(1, retry?.attempts ?? 3);
|
|
198
|
+
const backoffMS = retry?.backoffMS ?? 2e3;
|
|
199
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
200
|
+
const id = await platform.createContainer(token, params);
|
|
201
|
+
if (id && await isReady(token, id, label, wait)) return id;
|
|
202
|
+
if (attempt < attempts) {
|
|
203
|
+
const delay = backoffMS * 2 ** (attempt - 1);
|
|
204
|
+
console.warn(
|
|
205
|
+
`[naystack] ${platform.name} ${label} attempt ${attempt}/${attempts} failed \u2014 retrying in ${delay}ms`
|
|
206
|
+
);
|
|
207
|
+
await sleep(delay);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
};
|
|
196
212
|
return {
|
|
197
213
|
/** Creates a container, waits for it to finish processing, then publishes it. */
|
|
198
|
-
publish: async (token, params, wait) => {
|
|
199
|
-
const containerID = await
|
|
214
|
+
publish: async (token, params, wait, retry) => {
|
|
215
|
+
const containerID = await createReady(
|
|
216
|
+
token,
|
|
217
|
+
params,
|
|
218
|
+
"container",
|
|
219
|
+
wait,
|
|
220
|
+
retry
|
|
221
|
+
);
|
|
200
222
|
if (!containerID) return null;
|
|
201
|
-
if (!await isReady(token, containerID, "container", wait)) return null;
|
|
202
223
|
return platform.publish(token, containerID);
|
|
203
224
|
},
|
|
204
225
|
/** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
|
|
205
|
-
createChildren: async (token, items, wait) => {
|
|
226
|
+
createChildren: async (token, items, wait, retry) => {
|
|
206
227
|
const children = [];
|
|
207
228
|
for (const item of items) {
|
|
208
|
-
const childID = await
|
|
209
|
-
|
|
210
|
-
is_carousel_item: true
|
|
211
|
-
|
|
229
|
+
const childID = await createReady(
|
|
230
|
+
token,
|
|
231
|
+
{ ...item, is_carousel_item: true },
|
|
232
|
+
"carousel item",
|
|
233
|
+
wait,
|
|
234
|
+
retry
|
|
235
|
+
);
|
|
212
236
|
if (!childID) return null;
|
|
213
|
-
if (!await isReady(token, childID, "carousel item", wait))
|
|
214
|
-
return null;
|
|
215
237
|
children.push(childID);
|
|
216
238
|
}
|
|
217
239
|
return children;
|
|
@@ -210,25 +210,47 @@ function createPublisher(platform) {
|
|
|
210
210
|
}
|
|
211
211
|
return true;
|
|
212
212
|
};
|
|
213
|
+
const createReady = async (token, params, label, wait, retry) => {
|
|
214
|
+
const attempts = Math.max(1, retry?.attempts ?? 3);
|
|
215
|
+
const backoffMS = retry?.backoffMS ?? 2e3;
|
|
216
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
217
|
+
const id = await platform.createContainer(token, params);
|
|
218
|
+
if (id && await isReady(token, id, label, wait)) return id;
|
|
219
|
+
if (attempt < attempts) {
|
|
220
|
+
const delay = backoffMS * 2 ** (attempt - 1);
|
|
221
|
+
console.warn(
|
|
222
|
+
`[naystack] ${platform.name} ${label} attempt ${attempt}/${attempts} failed \u2014 retrying in ${delay}ms`
|
|
223
|
+
);
|
|
224
|
+
await sleep(delay);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
};
|
|
213
229
|
return {
|
|
214
230
|
/** Creates a container, waits for it to finish processing, then publishes it. */
|
|
215
|
-
publish: async (token, params, wait) => {
|
|
216
|
-
const containerID = await
|
|
231
|
+
publish: async (token, params, wait, retry) => {
|
|
232
|
+
const containerID = await createReady(
|
|
233
|
+
token,
|
|
234
|
+
params,
|
|
235
|
+
"container",
|
|
236
|
+
wait,
|
|
237
|
+
retry
|
|
238
|
+
);
|
|
217
239
|
if (!containerID) return null;
|
|
218
|
-
if (!await isReady(token, containerID, "container", wait)) return null;
|
|
219
240
|
return platform.publish(token, containerID);
|
|
220
241
|
},
|
|
221
242
|
/** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
|
|
222
|
-
createChildren: async (token, items, wait) => {
|
|
243
|
+
createChildren: async (token, items, wait, retry) => {
|
|
223
244
|
const children = [];
|
|
224
245
|
for (const item of items) {
|
|
225
|
-
const childID = await
|
|
226
|
-
|
|
227
|
-
is_carousel_item: true
|
|
228
|
-
|
|
246
|
+
const childID = await createReady(
|
|
247
|
+
token,
|
|
248
|
+
{ ...item, is_carousel_item: true },
|
|
249
|
+
"carousel item",
|
|
250
|
+
wait,
|
|
251
|
+
retry
|
|
252
|
+
);
|
|
229
253
|
if (!childID) return null;
|
|
230
|
-
if (!await isReady(token, childID, "carousel item", wait))
|
|
231
|
-
return null;
|
|
232
254
|
children.push(childID);
|
|
233
255
|
}
|
|
234
256
|
return children;
|
|
@@ -186,25 +186,47 @@ function createPublisher(platform) {
|
|
|
186
186
|
}
|
|
187
187
|
return true;
|
|
188
188
|
};
|
|
189
|
+
const createReady = async (token, params, label, wait, retry) => {
|
|
190
|
+
const attempts = Math.max(1, retry?.attempts ?? 3);
|
|
191
|
+
const backoffMS = retry?.backoffMS ?? 2e3;
|
|
192
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
193
|
+
const id = await platform.createContainer(token, params);
|
|
194
|
+
if (id && await isReady(token, id, label, wait)) return id;
|
|
195
|
+
if (attempt < attempts) {
|
|
196
|
+
const delay = backoffMS * 2 ** (attempt - 1);
|
|
197
|
+
console.warn(
|
|
198
|
+
`[naystack] ${platform.name} ${label} attempt ${attempt}/${attempts} failed \u2014 retrying in ${delay}ms`
|
|
199
|
+
);
|
|
200
|
+
await sleep(delay);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return null;
|
|
204
|
+
};
|
|
189
205
|
return {
|
|
190
206
|
/** Creates a container, waits for it to finish processing, then publishes it. */
|
|
191
|
-
publish: async (token, params, wait) => {
|
|
192
|
-
const containerID = await
|
|
207
|
+
publish: async (token, params, wait, retry) => {
|
|
208
|
+
const containerID = await createReady(
|
|
209
|
+
token,
|
|
210
|
+
params,
|
|
211
|
+
"container",
|
|
212
|
+
wait,
|
|
213
|
+
retry
|
|
214
|
+
);
|
|
193
215
|
if (!containerID) return null;
|
|
194
|
-
if (!await isReady(token, containerID, "container", wait)) return null;
|
|
195
216
|
return platform.publish(token, containerID);
|
|
196
217
|
},
|
|
197
218
|
/** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
|
|
198
|
-
createChildren: async (token, items, wait) => {
|
|
219
|
+
createChildren: async (token, items, wait, retry) => {
|
|
199
220
|
const children = [];
|
|
200
221
|
for (const item of items) {
|
|
201
|
-
const childID = await
|
|
202
|
-
|
|
203
|
-
is_carousel_item: true
|
|
204
|
-
|
|
222
|
+
const childID = await createReady(
|
|
223
|
+
token,
|
|
224
|
+
{ ...item, is_carousel_item: true },
|
|
225
|
+
"carousel item",
|
|
226
|
+
wait,
|
|
227
|
+
retry
|
|
228
|
+
);
|
|
205
229
|
if (!childID) return null;
|
|
206
|
-
if (!await isReady(token, childID, "carousel item", wait))
|
|
207
|
-
return null;
|
|
208
230
|
children.push(childID);
|
|
209
231
|
}
|
|
210
232
|
return children;
|
|
@@ -202,25 +202,47 @@ function createPublisher(platform) {
|
|
|
202
202
|
}
|
|
203
203
|
return true;
|
|
204
204
|
};
|
|
205
|
+
const createReady = async (token, params, label, wait, retry) => {
|
|
206
|
+
const attempts = Math.max(1, retry?.attempts ?? 3);
|
|
207
|
+
const backoffMS = retry?.backoffMS ?? 2e3;
|
|
208
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
209
|
+
const id = await platform.createContainer(token, params);
|
|
210
|
+
if (id && await isReady(token, id, label, wait)) return id;
|
|
211
|
+
if (attempt < attempts) {
|
|
212
|
+
const delay = backoffMS * 2 ** (attempt - 1);
|
|
213
|
+
console.warn(
|
|
214
|
+
`[naystack] ${platform.name} ${label} attempt ${attempt}/${attempts} failed \u2014 retrying in ${delay}ms`
|
|
215
|
+
);
|
|
216
|
+
await sleep(delay);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return null;
|
|
220
|
+
};
|
|
205
221
|
return {
|
|
206
222
|
/** Creates a container, waits for it to finish processing, then publishes it. */
|
|
207
|
-
publish: async (token, params, wait) => {
|
|
208
|
-
const containerID = await
|
|
223
|
+
publish: async (token, params, wait, retry) => {
|
|
224
|
+
const containerID = await createReady(
|
|
225
|
+
token,
|
|
226
|
+
params,
|
|
227
|
+
"container",
|
|
228
|
+
wait,
|
|
229
|
+
retry
|
|
230
|
+
);
|
|
209
231
|
if (!containerID) return null;
|
|
210
|
-
if (!await isReady(token, containerID, "container", wait)) return null;
|
|
211
232
|
return platform.publish(token, containerID);
|
|
212
233
|
},
|
|
213
234
|
/** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
|
|
214
|
-
createChildren: async (token, items, wait) => {
|
|
235
|
+
createChildren: async (token, items, wait, retry) => {
|
|
215
236
|
const children = [];
|
|
216
237
|
for (const item of items) {
|
|
217
|
-
const childID = await
|
|
218
|
-
|
|
219
|
-
is_carousel_item: true
|
|
220
|
-
|
|
238
|
+
const childID = await createReady(
|
|
239
|
+
token,
|
|
240
|
+
{ ...item, is_carousel_item: true },
|
|
241
|
+
"carousel item",
|
|
242
|
+
wait,
|
|
243
|
+
retry
|
|
244
|
+
);
|
|
221
245
|
if (!childID) return null;
|
|
222
|
-
if (!await isReady(token, childID, "carousel item", wait))
|
|
223
|
-
return null;
|
|
224
246
|
children.push(childID);
|
|
225
247
|
}
|
|
226
248
|
return children;
|
|
@@ -278,14 +300,16 @@ var createInstagramPost = async (token, input) => {
|
|
|
278
300
|
media_type: "STORIES",
|
|
279
301
|
alt_text: void 0
|
|
280
302
|
},
|
|
281
|
-
input.wait
|
|
303
|
+
input.wait,
|
|
304
|
+
input.retry
|
|
282
305
|
);
|
|
283
306
|
}
|
|
284
307
|
if (media.length > 1) {
|
|
285
308
|
const children = await publisher.createChildren(
|
|
286
309
|
token,
|
|
287
310
|
media.map(mediaParams),
|
|
288
|
-
input.wait
|
|
311
|
+
input.wait,
|
|
312
|
+
input.retry
|
|
289
313
|
);
|
|
290
314
|
if (!children) return null;
|
|
291
315
|
return publisher.publish(
|
|
@@ -295,7 +319,8 @@ var createInstagramPost = async (token, input) => {
|
|
|
295
319
|
children: children.join(","),
|
|
296
320
|
caption: input.caption
|
|
297
321
|
},
|
|
298
|
-
input.wait
|
|
322
|
+
input.wait,
|
|
323
|
+
input.retry
|
|
299
324
|
);
|
|
300
325
|
}
|
|
301
326
|
if (first.type === "video" /* Video */) {
|
|
@@ -311,7 +336,8 @@ var createInstagramPost = async (token, input) => {
|
|
|
311
336
|
audio_name: input.audioName,
|
|
312
337
|
collaborators: input.collaborators && JSON.stringify(input.collaborators)
|
|
313
338
|
},
|
|
314
|
-
input.wait
|
|
339
|
+
input.wait,
|
|
340
|
+
input.retry
|
|
315
341
|
);
|
|
316
342
|
}
|
|
317
343
|
return publisher.publish(
|
|
@@ -322,7 +348,8 @@ var createInstagramPost = async (token, input) => {
|
|
|
322
348
|
alt_text: first.altText,
|
|
323
349
|
location_id: input.locationID
|
|
324
350
|
},
|
|
325
|
-
input.wait
|
|
351
|
+
input.wait,
|
|
352
|
+
input.retry
|
|
326
353
|
);
|
|
327
354
|
};
|
|
328
355
|
var sendInstagramMessage = (token, to, text) => {
|
|
@@ -427,13 +454,15 @@ var createThreadsPost = async (token, input, replyToID) => {
|
|
|
427
454
|
const children = await publisher2.createChildren(
|
|
428
455
|
token,
|
|
429
456
|
media.map((item) => mediaParams2(item)),
|
|
430
|
-
post.wait
|
|
457
|
+
post.wait,
|
|
458
|
+
post.retry
|
|
431
459
|
);
|
|
432
460
|
if (!children) return null;
|
|
433
461
|
return publisher2.publish(
|
|
434
462
|
token,
|
|
435
463
|
{ ...shared, media_type: "CAROUSEL", children: children.join(",") },
|
|
436
|
-
post.wait
|
|
464
|
+
post.wait,
|
|
465
|
+
post.retry
|
|
437
466
|
);
|
|
438
467
|
}
|
|
439
468
|
return publisher2.publish(
|
|
@@ -443,7 +472,8 @@ var createThreadsPost = async (token, input, replyToID) => {
|
|
|
443
472
|
...shared,
|
|
444
473
|
link_attachment: post.linkAttachment
|
|
445
474
|
},
|
|
446
|
-
post.wait
|
|
475
|
+
post.wait,
|
|
476
|
+
post.retry
|
|
447
477
|
);
|
|
448
478
|
};
|
|
449
479
|
var createThread = async (token, posts) => {
|
package/dist/socials/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ export { canPublishToInstagram, getInstagramConversation, getInstagramConversati
|
|
|
2
2
|
export { createInstagramPost, sendInstagramMessage } from './instagram/setters.mjs';
|
|
3
3
|
export { InstagramConversation, InstagramMedia, InstagramMessage, InstagramPostInput, InstagramPostMedia, InstagramUser } from './instagram/types.mjs';
|
|
4
4
|
export { setupInstagramWebhook } from './instagram/webhook.mjs';
|
|
5
|
-
export { WaitForContainerOptions } from './meta/container.mjs';
|
|
5
|
+
export { RetryOptions, WaitForContainerOptions } from './meta/container.mjs';
|
|
6
6
|
export { GraphError, MetaMediaType } from './meta/types.mjs';
|
|
7
7
|
export { getThread, getThreads, getThreadsReplies } from './threads/getters.mjs';
|
|
8
8
|
export { createThread, createThreadsPost } from './threads/setters.mjs';
|
package/dist/socials/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { canPublishToInstagram, getInstagramConversation, getInstagramConversati
|
|
|
2
2
|
export { createInstagramPost, sendInstagramMessage } from './instagram/setters.js';
|
|
3
3
|
export { InstagramConversation, InstagramMedia, InstagramMessage, InstagramPostInput, InstagramPostMedia, InstagramUser } from './instagram/types.js';
|
|
4
4
|
export { setupInstagramWebhook } from './instagram/webhook.js';
|
|
5
|
-
export { WaitForContainerOptions } from './meta/container.js';
|
|
5
|
+
export { RetryOptions, WaitForContainerOptions } from './meta/container.js';
|
|
6
6
|
export { GraphError, MetaMediaType } from './meta/types.js';
|
|
7
7
|
export { getThread, getThreads, getThreadsReplies } from './threads/getters.js';
|
|
8
8
|
export { createThread, createThreadsPost } from './threads/setters.js';
|
|
@@ -159,25 +159,47 @@ function createPublisher(platform) {
|
|
|
159
159
|
}
|
|
160
160
|
return true;
|
|
161
161
|
};
|
|
162
|
+
const createReady = async (token, params, label, wait, retry) => {
|
|
163
|
+
const attempts = Math.max(1, retry?.attempts ?? 3);
|
|
164
|
+
const backoffMS = retry?.backoffMS ?? 2e3;
|
|
165
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
166
|
+
const id = await platform.createContainer(token, params);
|
|
167
|
+
if (id && await isReady(token, id, label, wait)) return id;
|
|
168
|
+
if (attempt < attempts) {
|
|
169
|
+
const delay = backoffMS * 2 ** (attempt - 1);
|
|
170
|
+
console.warn(
|
|
171
|
+
`[naystack] ${platform.name} ${label} attempt ${attempt}/${attempts} failed \u2014 retrying in ${delay}ms`
|
|
172
|
+
);
|
|
173
|
+
await sleep(delay);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
};
|
|
162
178
|
return {
|
|
163
179
|
/** Creates a container, waits for it to finish processing, then publishes it. */
|
|
164
|
-
publish: async (token, params, wait) => {
|
|
165
|
-
const containerID = await
|
|
180
|
+
publish: async (token, params, wait, retry) => {
|
|
181
|
+
const containerID = await createReady(
|
|
182
|
+
token,
|
|
183
|
+
params,
|
|
184
|
+
"container",
|
|
185
|
+
wait,
|
|
186
|
+
retry
|
|
187
|
+
);
|
|
166
188
|
if (!containerID) return null;
|
|
167
|
-
if (!await isReady(token, containerID, "container", wait)) return null;
|
|
168
189
|
return platform.publish(token, containerID);
|
|
169
190
|
},
|
|
170
191
|
/** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
|
|
171
|
-
createChildren: async (token, items, wait) => {
|
|
192
|
+
createChildren: async (token, items, wait, retry) => {
|
|
172
193
|
const children = [];
|
|
173
194
|
for (const item of items) {
|
|
174
|
-
const childID = await
|
|
175
|
-
|
|
176
|
-
is_carousel_item: true
|
|
177
|
-
|
|
195
|
+
const childID = await createReady(
|
|
196
|
+
token,
|
|
197
|
+
{ ...item, is_carousel_item: true },
|
|
198
|
+
"carousel item",
|
|
199
|
+
wait,
|
|
200
|
+
retry
|
|
201
|
+
);
|
|
178
202
|
if (!childID) return null;
|
|
179
|
-
if (!await isReady(token, childID, "carousel item", wait))
|
|
180
|
-
return null;
|
|
181
203
|
children.push(childID);
|
|
182
204
|
}
|
|
183
205
|
return children;
|
|
@@ -235,14 +257,16 @@ var createInstagramPost = async (token, input) => {
|
|
|
235
257
|
media_type: "STORIES",
|
|
236
258
|
alt_text: void 0
|
|
237
259
|
},
|
|
238
|
-
input.wait
|
|
260
|
+
input.wait,
|
|
261
|
+
input.retry
|
|
239
262
|
);
|
|
240
263
|
}
|
|
241
264
|
if (media.length > 1) {
|
|
242
265
|
const children = await publisher.createChildren(
|
|
243
266
|
token,
|
|
244
267
|
media.map(mediaParams),
|
|
245
|
-
input.wait
|
|
268
|
+
input.wait,
|
|
269
|
+
input.retry
|
|
246
270
|
);
|
|
247
271
|
if (!children) return null;
|
|
248
272
|
return publisher.publish(
|
|
@@ -252,7 +276,8 @@ var createInstagramPost = async (token, input) => {
|
|
|
252
276
|
children: children.join(","),
|
|
253
277
|
caption: input.caption
|
|
254
278
|
},
|
|
255
|
-
input.wait
|
|
279
|
+
input.wait,
|
|
280
|
+
input.retry
|
|
256
281
|
);
|
|
257
282
|
}
|
|
258
283
|
if (first.type === "video" /* Video */) {
|
|
@@ -268,7 +293,8 @@ var createInstagramPost = async (token, input) => {
|
|
|
268
293
|
audio_name: input.audioName,
|
|
269
294
|
collaborators: input.collaborators && JSON.stringify(input.collaborators)
|
|
270
295
|
},
|
|
271
|
-
input.wait
|
|
296
|
+
input.wait,
|
|
297
|
+
input.retry
|
|
272
298
|
);
|
|
273
299
|
}
|
|
274
300
|
return publisher.publish(
|
|
@@ -279,7 +305,8 @@ var createInstagramPost = async (token, input) => {
|
|
|
279
305
|
alt_text: first.altText,
|
|
280
306
|
location_id: input.locationID
|
|
281
307
|
},
|
|
282
|
-
input.wait
|
|
308
|
+
input.wait,
|
|
309
|
+
input.retry
|
|
283
310
|
);
|
|
284
311
|
};
|
|
285
312
|
var sendInstagramMessage = (token, to, text) => {
|
|
@@ -384,13 +411,15 @@ var createThreadsPost = async (token, input, replyToID) => {
|
|
|
384
411
|
const children = await publisher2.createChildren(
|
|
385
412
|
token,
|
|
386
413
|
media.map((item) => mediaParams2(item)),
|
|
387
|
-
post.wait
|
|
414
|
+
post.wait,
|
|
415
|
+
post.retry
|
|
388
416
|
);
|
|
389
417
|
if (!children) return null;
|
|
390
418
|
return publisher2.publish(
|
|
391
419
|
token,
|
|
392
420
|
{ ...shared, media_type: "CAROUSEL", children: children.join(",") },
|
|
393
|
-
post.wait
|
|
421
|
+
post.wait,
|
|
422
|
+
post.retry
|
|
394
423
|
);
|
|
395
424
|
}
|
|
396
425
|
return publisher2.publish(
|
|
@@ -400,7 +429,8 @@ var createThreadsPost = async (token, input, replyToID) => {
|
|
|
400
429
|
...shared,
|
|
401
430
|
link_attachment: post.linkAttachment
|
|
402
431
|
},
|
|
403
|
-
post.wait
|
|
432
|
+
post.wait,
|
|
433
|
+
post.retry
|
|
404
434
|
);
|
|
405
435
|
};
|
|
406
436
|
var createThread = async (token, posts) => {
|
|
@@ -99,25 +99,47 @@ function createPublisher(platform) {
|
|
|
99
99
|
}
|
|
100
100
|
return true;
|
|
101
101
|
};
|
|
102
|
+
const createReady = async (token, params, label, wait, retry) => {
|
|
103
|
+
const attempts = Math.max(1, retry?.attempts ?? 3);
|
|
104
|
+
const backoffMS = retry?.backoffMS ?? 2e3;
|
|
105
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
106
|
+
const id = await platform.createContainer(token, params);
|
|
107
|
+
if (id && await isReady(token, id, label, wait)) return id;
|
|
108
|
+
if (attempt < attempts) {
|
|
109
|
+
const delay = backoffMS * 2 ** (attempt - 1);
|
|
110
|
+
console.warn(
|
|
111
|
+
`[naystack] ${platform.name} ${label} attempt ${attempt}/${attempts} failed \u2014 retrying in ${delay}ms`
|
|
112
|
+
);
|
|
113
|
+
await sleep(delay);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
};
|
|
102
118
|
return {
|
|
103
119
|
/** Creates a container, waits for it to finish processing, then publishes it. */
|
|
104
|
-
publish: async (token, params, wait) => {
|
|
105
|
-
const containerID = await
|
|
120
|
+
publish: async (token, params, wait, retry) => {
|
|
121
|
+
const containerID = await createReady(
|
|
122
|
+
token,
|
|
123
|
+
params,
|
|
124
|
+
"container",
|
|
125
|
+
wait,
|
|
126
|
+
retry
|
|
127
|
+
);
|
|
106
128
|
if (!containerID) return null;
|
|
107
|
-
if (!await isReady(token, containerID, "container", wait)) return null;
|
|
108
129
|
return platform.publish(token, containerID);
|
|
109
130
|
},
|
|
110
131
|
/** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
|
|
111
|
-
createChildren: async (token, items, wait) => {
|
|
132
|
+
createChildren: async (token, items, wait, retry) => {
|
|
112
133
|
const children = [];
|
|
113
134
|
for (const item of items) {
|
|
114
|
-
const childID = await
|
|
115
|
-
|
|
116
|
-
is_carousel_item: true
|
|
117
|
-
|
|
135
|
+
const childID = await createReady(
|
|
136
|
+
token,
|
|
137
|
+
{ ...item, is_carousel_item: true },
|
|
138
|
+
"carousel item",
|
|
139
|
+
wait,
|
|
140
|
+
retry
|
|
141
|
+
);
|
|
118
142
|
if (!childID) return null;
|
|
119
|
-
if (!await isReady(token, childID, "carousel item", wait))
|
|
120
|
-
return null;
|
|
121
143
|
children.push(childID);
|
|
122
144
|
}
|
|
123
145
|
return children;
|
|
@@ -168,14 +190,16 @@ var createInstagramPost = async (token, input) => {
|
|
|
168
190
|
media_type: "STORIES",
|
|
169
191
|
alt_text: void 0
|
|
170
192
|
},
|
|
171
|
-
input.wait
|
|
193
|
+
input.wait,
|
|
194
|
+
input.retry
|
|
172
195
|
);
|
|
173
196
|
}
|
|
174
197
|
if (media.length > 1) {
|
|
175
198
|
const children = await publisher.createChildren(
|
|
176
199
|
token,
|
|
177
200
|
media.map(mediaParams),
|
|
178
|
-
input.wait
|
|
201
|
+
input.wait,
|
|
202
|
+
input.retry
|
|
179
203
|
);
|
|
180
204
|
if (!children) return null;
|
|
181
205
|
return publisher.publish(
|
|
@@ -185,7 +209,8 @@ var createInstagramPost = async (token, input) => {
|
|
|
185
209
|
children: children.join(","),
|
|
186
210
|
caption: input.caption
|
|
187
211
|
},
|
|
188
|
-
input.wait
|
|
212
|
+
input.wait,
|
|
213
|
+
input.retry
|
|
189
214
|
);
|
|
190
215
|
}
|
|
191
216
|
if (first.type === "video" /* Video */) {
|
|
@@ -201,7 +226,8 @@ var createInstagramPost = async (token, input) => {
|
|
|
201
226
|
audio_name: input.audioName,
|
|
202
227
|
collaborators: input.collaborators && JSON.stringify(input.collaborators)
|
|
203
228
|
},
|
|
204
|
-
input.wait
|
|
229
|
+
input.wait,
|
|
230
|
+
input.retry
|
|
205
231
|
);
|
|
206
232
|
}
|
|
207
233
|
return publisher.publish(
|
|
@@ -212,7 +238,8 @@ var createInstagramPost = async (token, input) => {
|
|
|
212
238
|
alt_text: first.altText,
|
|
213
239
|
location_id: input.locationID
|
|
214
240
|
},
|
|
215
|
-
input.wait
|
|
241
|
+
input.wait,
|
|
242
|
+
input.retry
|
|
216
243
|
);
|
|
217
244
|
};
|
|
218
245
|
var sendInstagramMessage = (token, to, text) => {
|
|
@@ -72,25 +72,47 @@ function createPublisher(platform) {
|
|
|
72
72
|
}
|
|
73
73
|
return true;
|
|
74
74
|
};
|
|
75
|
+
const createReady = async (token, params, label, wait, retry) => {
|
|
76
|
+
const attempts = Math.max(1, retry?.attempts ?? 3);
|
|
77
|
+
const backoffMS = retry?.backoffMS ?? 2e3;
|
|
78
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
79
|
+
const id = await platform.createContainer(token, params);
|
|
80
|
+
if (id && await isReady(token, id, label, wait)) return id;
|
|
81
|
+
if (attempt < attempts) {
|
|
82
|
+
const delay = backoffMS * 2 ** (attempt - 1);
|
|
83
|
+
console.warn(
|
|
84
|
+
`[naystack] ${platform.name} ${label} attempt ${attempt}/${attempts} failed \u2014 retrying in ${delay}ms`
|
|
85
|
+
);
|
|
86
|
+
await sleep(delay);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
};
|
|
75
91
|
return {
|
|
76
92
|
/** Creates a container, waits for it to finish processing, then publishes it. */
|
|
77
|
-
publish: async (token, params, wait) => {
|
|
78
|
-
const containerID = await
|
|
93
|
+
publish: async (token, params, wait, retry) => {
|
|
94
|
+
const containerID = await createReady(
|
|
95
|
+
token,
|
|
96
|
+
params,
|
|
97
|
+
"container",
|
|
98
|
+
wait,
|
|
99
|
+
retry
|
|
100
|
+
);
|
|
79
101
|
if (!containerID) return null;
|
|
80
|
-
if (!await isReady(token, containerID, "container", wait)) return null;
|
|
81
102
|
return platform.publish(token, containerID);
|
|
82
103
|
},
|
|
83
104
|
/** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
|
|
84
|
-
createChildren: async (token, items, wait) => {
|
|
105
|
+
createChildren: async (token, items, wait, retry) => {
|
|
85
106
|
const children = [];
|
|
86
107
|
for (const item of items) {
|
|
87
|
-
const childID = await
|
|
88
|
-
|
|
89
|
-
is_carousel_item: true
|
|
90
|
-
|
|
108
|
+
const childID = await createReady(
|
|
109
|
+
token,
|
|
110
|
+
{ ...item, is_carousel_item: true },
|
|
111
|
+
"carousel item",
|
|
112
|
+
wait,
|
|
113
|
+
retry
|
|
114
|
+
);
|
|
91
115
|
if (!childID) return null;
|
|
92
|
-
if (!await isReady(token, childID, "carousel item", wait))
|
|
93
|
-
return null;
|
|
94
116
|
children.push(childID);
|
|
95
117
|
}
|
|
96
118
|
return children;
|
|
@@ -141,14 +163,16 @@ var createInstagramPost = async (token, input) => {
|
|
|
141
163
|
media_type: "STORIES",
|
|
142
164
|
alt_text: void 0
|
|
143
165
|
},
|
|
144
|
-
input.wait
|
|
166
|
+
input.wait,
|
|
167
|
+
input.retry
|
|
145
168
|
);
|
|
146
169
|
}
|
|
147
170
|
if (media.length > 1) {
|
|
148
171
|
const children = await publisher.createChildren(
|
|
149
172
|
token,
|
|
150
173
|
media.map(mediaParams),
|
|
151
|
-
input.wait
|
|
174
|
+
input.wait,
|
|
175
|
+
input.retry
|
|
152
176
|
);
|
|
153
177
|
if (!children) return null;
|
|
154
178
|
return publisher.publish(
|
|
@@ -158,7 +182,8 @@ var createInstagramPost = async (token, input) => {
|
|
|
158
182
|
children: children.join(","),
|
|
159
183
|
caption: input.caption
|
|
160
184
|
},
|
|
161
|
-
input.wait
|
|
185
|
+
input.wait,
|
|
186
|
+
input.retry
|
|
162
187
|
);
|
|
163
188
|
}
|
|
164
189
|
if (first.type === "video" /* Video */) {
|
|
@@ -174,7 +199,8 @@ var createInstagramPost = async (token, input) => {
|
|
|
174
199
|
audio_name: input.audioName,
|
|
175
200
|
collaborators: input.collaborators && JSON.stringify(input.collaborators)
|
|
176
201
|
},
|
|
177
|
-
input.wait
|
|
202
|
+
input.wait,
|
|
203
|
+
input.retry
|
|
178
204
|
);
|
|
179
205
|
}
|
|
180
206
|
return publisher.publish(
|
|
@@ -185,7 +211,8 @@ var createInstagramPost = async (token, input) => {
|
|
|
185
211
|
alt_text: first.altText,
|
|
186
212
|
location_id: input.locationID
|
|
187
213
|
},
|
|
188
|
-
input.wait
|
|
214
|
+
input.wait,
|
|
215
|
+
input.retry
|
|
189
216
|
);
|
|
190
217
|
};
|
|
191
218
|
var sendInstagramMessage = (token, to, text) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WaitForContainerOptions } from '../meta/container.mjs';
|
|
1
|
+
import { WaitForContainerOptions, RetryOptions } from '../meta/container.mjs';
|
|
2
2
|
import { MetaMediaType } from '../meta/types.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -121,6 +121,7 @@ type InstagramPostMedia = {
|
|
|
121
121
|
* @property audioName - Reels: name for the audio track. Can only be set once.
|
|
122
122
|
* @property collaborators - Reels: up to 3 public usernames to invite as collaborators.
|
|
123
123
|
* @property wait - Container polling settings.
|
|
124
|
+
* @property retry - Container-creation retry settings. See {@link RetryOptions}.
|
|
124
125
|
*
|
|
125
126
|
* @category Socials
|
|
126
127
|
*/
|
|
@@ -135,6 +136,7 @@ type InstagramPostInput = {
|
|
|
135
136
|
audioName?: string;
|
|
136
137
|
collaborators?: string[];
|
|
137
138
|
wait?: WaitForContainerOptions;
|
|
139
|
+
retry?: RetryOptions;
|
|
138
140
|
};
|
|
139
141
|
|
|
140
142
|
export type { InstagramConversation, InstagramMedia, InstagramMessage, InstagramPostInput, InstagramPostMedia, InstagramUser };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WaitForContainerOptions } from '../meta/container.js';
|
|
1
|
+
import { WaitForContainerOptions, RetryOptions } from '../meta/container.js';
|
|
2
2
|
import { MetaMediaType } from '../meta/types.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -121,6 +121,7 @@ type InstagramPostMedia = {
|
|
|
121
121
|
* @property audioName - Reels: name for the audio track. Can only be set once.
|
|
122
122
|
* @property collaborators - Reels: up to 3 public usernames to invite as collaborators.
|
|
123
123
|
* @property wait - Container polling settings.
|
|
124
|
+
* @property retry - Container-creation retry settings. See {@link RetryOptions}.
|
|
124
125
|
*
|
|
125
126
|
* @category Socials
|
|
126
127
|
*/
|
|
@@ -135,6 +136,7 @@ type InstagramPostInput = {
|
|
|
135
136
|
audioName?: string;
|
|
136
137
|
collaborators?: string[];
|
|
137
138
|
wait?: WaitForContainerOptions;
|
|
139
|
+
retry?: RetryOptions;
|
|
138
140
|
};
|
|
139
141
|
|
|
140
142
|
export type { InstagramConversation, InstagramMedia, InstagramMessage, InstagramPostInput, InstagramPostMedia, InstagramUser };
|
|
@@ -51,25 +51,47 @@ function createPublisher(platform) {
|
|
|
51
51
|
}
|
|
52
52
|
return true;
|
|
53
53
|
};
|
|
54
|
+
const createReady = async (token, params, label, wait, retry) => {
|
|
55
|
+
const attempts = Math.max(1, retry?.attempts ?? 3);
|
|
56
|
+
const backoffMS = retry?.backoffMS ?? 2e3;
|
|
57
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
58
|
+
const id = await platform.createContainer(token, params);
|
|
59
|
+
if (id && await isReady(token, id, label, wait)) return id;
|
|
60
|
+
if (attempt < attempts) {
|
|
61
|
+
const delay = backoffMS * 2 ** (attempt - 1);
|
|
62
|
+
console.warn(
|
|
63
|
+
`[naystack] ${platform.name} ${label} attempt ${attempt}/${attempts} failed \u2014 retrying in ${delay}ms`
|
|
64
|
+
);
|
|
65
|
+
await sleep(delay);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
};
|
|
54
70
|
return {
|
|
55
71
|
/** Creates a container, waits for it to finish processing, then publishes it. */
|
|
56
|
-
publish: async (token, params, wait) => {
|
|
57
|
-
const containerID = await
|
|
72
|
+
publish: async (token, params, wait, retry) => {
|
|
73
|
+
const containerID = await createReady(
|
|
74
|
+
token,
|
|
75
|
+
params,
|
|
76
|
+
"container",
|
|
77
|
+
wait,
|
|
78
|
+
retry
|
|
79
|
+
);
|
|
58
80
|
if (!containerID) return null;
|
|
59
|
-
if (!await isReady(token, containerID, "container", wait)) return null;
|
|
60
81
|
return platform.publish(token, containerID);
|
|
61
82
|
},
|
|
62
83
|
/** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
|
|
63
|
-
createChildren: async (token, items, wait) => {
|
|
84
|
+
createChildren: async (token, items, wait, retry) => {
|
|
64
85
|
const children = [];
|
|
65
86
|
for (const item of items) {
|
|
66
|
-
const childID = await
|
|
67
|
-
|
|
68
|
-
is_carousel_item: true
|
|
69
|
-
|
|
87
|
+
const childID = await createReady(
|
|
88
|
+
token,
|
|
89
|
+
{ ...item, is_carousel_item: true },
|
|
90
|
+
"carousel item",
|
|
91
|
+
wait,
|
|
92
|
+
retry
|
|
93
|
+
);
|
|
70
94
|
if (!childID) return null;
|
|
71
|
-
if (!await isReady(token, childID, "carousel item", wait))
|
|
72
|
-
return null;
|
|
73
95
|
children.push(childID);
|
|
74
96
|
}
|
|
75
97
|
return children;
|
|
@@ -12,6 +12,24 @@ type WaitForContainerOptions = {
|
|
|
12
12
|
intervalMS?: number;
|
|
13
13
|
timeoutMS?: number;
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Retry settings for creating a media container.
|
|
17
|
+
*
|
|
18
|
+
* Meta intermittently rejects a perfectly valid container — most visibly on
|
|
19
|
+
* carousels, where one arbitrary child fails with "Only photo or video can be
|
|
20
|
+
* accepted as media type." and the identical call succeeds moments later. The
|
|
21
|
+
* failure is transient and carries no distinguishing error code, so container
|
|
22
|
+
* creation is simply retried rather than pattern-matched against Meta's copy.
|
|
23
|
+
*
|
|
24
|
+
* @property attempts - Total tries, including the first. Default: `3`.
|
|
25
|
+
* @property backoffMS - Delay before the second try, doubled each time after. Default: `2000`.
|
|
26
|
+
*
|
|
27
|
+
* @category Socials
|
|
28
|
+
*/
|
|
29
|
+
type RetryOptions = {
|
|
30
|
+
attempts?: number;
|
|
31
|
+
backoffMS?: number;
|
|
32
|
+
};
|
|
15
33
|
/**
|
|
16
34
|
* Wires up the create → wait → publish flow Meta platforms share. Instagram and
|
|
17
35
|
* Threads differ only in their endpoints, so each builds one publisher and every
|
|
@@ -30,9 +48,9 @@ declare function createPublisher(platform: {
|
|
|
30
48
|
publish: (token: string, creationID: string) => Promise<string | null>;
|
|
31
49
|
}): {
|
|
32
50
|
/** Creates a container, waits for it to finish processing, then publishes it. */
|
|
33
|
-
publish: (token: string, params: GraphParams, wait?: WaitForContainerOptions) => Promise<string | null>;
|
|
51
|
+
publish: (token: string, params: GraphParams, wait?: WaitForContainerOptions, retry?: RetryOptions) => Promise<string | null>;
|
|
34
52
|
/** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
|
|
35
|
-
createChildren: (token: string, items: GraphParams[], wait?: WaitForContainerOptions) => Promise<string[] | null>;
|
|
53
|
+
createChildren: (token: string, items: GraphParams[], wait?: WaitForContainerOptions, retry?: RetryOptions) => Promise<string[] | null>;
|
|
36
54
|
};
|
|
37
55
|
|
|
38
|
-
export { type WaitForContainerOptions, createPublisher };
|
|
56
|
+
export { type RetryOptions, type WaitForContainerOptions, createPublisher };
|
|
@@ -12,6 +12,24 @@ type WaitForContainerOptions = {
|
|
|
12
12
|
intervalMS?: number;
|
|
13
13
|
timeoutMS?: number;
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Retry settings for creating a media container.
|
|
17
|
+
*
|
|
18
|
+
* Meta intermittently rejects a perfectly valid container — most visibly on
|
|
19
|
+
* carousels, where one arbitrary child fails with "Only photo or video can be
|
|
20
|
+
* accepted as media type." and the identical call succeeds moments later. The
|
|
21
|
+
* failure is transient and carries no distinguishing error code, so container
|
|
22
|
+
* creation is simply retried rather than pattern-matched against Meta's copy.
|
|
23
|
+
*
|
|
24
|
+
* @property attempts - Total tries, including the first. Default: `3`.
|
|
25
|
+
* @property backoffMS - Delay before the second try, doubled each time after. Default: `2000`.
|
|
26
|
+
*
|
|
27
|
+
* @category Socials
|
|
28
|
+
*/
|
|
29
|
+
type RetryOptions = {
|
|
30
|
+
attempts?: number;
|
|
31
|
+
backoffMS?: number;
|
|
32
|
+
};
|
|
15
33
|
/**
|
|
16
34
|
* Wires up the create → wait → publish flow Meta platforms share. Instagram and
|
|
17
35
|
* Threads differ only in their endpoints, so each builds one publisher and every
|
|
@@ -30,9 +48,9 @@ declare function createPublisher(platform: {
|
|
|
30
48
|
publish: (token: string, creationID: string) => Promise<string | null>;
|
|
31
49
|
}): {
|
|
32
50
|
/** Creates a container, waits for it to finish processing, then publishes it. */
|
|
33
|
-
publish: (token: string, params: GraphParams, wait?: WaitForContainerOptions) => Promise<string | null>;
|
|
51
|
+
publish: (token: string, params: GraphParams, wait?: WaitForContainerOptions, retry?: RetryOptions) => Promise<string | null>;
|
|
34
52
|
/** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
|
|
35
|
-
createChildren: (token: string, items: GraphParams[], wait?: WaitForContainerOptions) => Promise<string[] | null>;
|
|
53
|
+
createChildren: (token: string, items: GraphParams[], wait?: WaitForContainerOptions, retry?: RetryOptions) => Promise<string[] | null>;
|
|
36
54
|
};
|
|
37
55
|
|
|
38
|
-
export { type WaitForContainerOptions, createPublisher };
|
|
56
|
+
export { type RetryOptions, type WaitForContainerOptions, createPublisher };
|
|
@@ -27,25 +27,47 @@ function createPublisher(platform) {
|
|
|
27
27
|
}
|
|
28
28
|
return true;
|
|
29
29
|
};
|
|
30
|
+
const createReady = async (token, params, label, wait, retry) => {
|
|
31
|
+
const attempts = Math.max(1, retry?.attempts ?? 3);
|
|
32
|
+
const backoffMS = retry?.backoffMS ?? 2e3;
|
|
33
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
34
|
+
const id = await platform.createContainer(token, params);
|
|
35
|
+
if (id && await isReady(token, id, label, wait)) return id;
|
|
36
|
+
if (attempt < attempts) {
|
|
37
|
+
const delay = backoffMS * 2 ** (attempt - 1);
|
|
38
|
+
console.warn(
|
|
39
|
+
`[naystack] ${platform.name} ${label} attempt ${attempt}/${attempts} failed \u2014 retrying in ${delay}ms`
|
|
40
|
+
);
|
|
41
|
+
await sleep(delay);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
30
46
|
return {
|
|
31
47
|
/** Creates a container, waits for it to finish processing, then publishes it. */
|
|
32
|
-
publish: async (token, params, wait) => {
|
|
33
|
-
const containerID = await
|
|
48
|
+
publish: async (token, params, wait, retry) => {
|
|
49
|
+
const containerID = await createReady(
|
|
50
|
+
token,
|
|
51
|
+
params,
|
|
52
|
+
"container",
|
|
53
|
+
wait,
|
|
54
|
+
retry
|
|
55
|
+
);
|
|
34
56
|
if (!containerID) return null;
|
|
35
|
-
if (!await isReady(token, containerID, "container", wait)) return null;
|
|
36
57
|
return platform.publish(token, containerID);
|
|
37
58
|
},
|
|
38
59
|
/** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
|
|
39
|
-
createChildren: async (token, items, wait) => {
|
|
60
|
+
createChildren: async (token, items, wait, retry) => {
|
|
40
61
|
const children = [];
|
|
41
62
|
for (const item of items) {
|
|
42
|
-
const childID = await
|
|
43
|
-
|
|
44
|
-
is_carousel_item: true
|
|
45
|
-
|
|
63
|
+
const childID = await createReady(
|
|
64
|
+
token,
|
|
65
|
+
{ ...item, is_carousel_item: true },
|
|
66
|
+
"carousel item",
|
|
67
|
+
wait,
|
|
68
|
+
retry
|
|
69
|
+
);
|
|
46
70
|
if (!childID) return null;
|
|
47
|
-
if (!await isReady(token, childID, "carousel item", wait))
|
|
48
|
-
return null;
|
|
49
71
|
children.push(childID);
|
|
50
72
|
}
|
|
51
73
|
return children;
|
|
@@ -54,25 +54,47 @@ function createPublisher(platform) {
|
|
|
54
54
|
}
|
|
55
55
|
return true;
|
|
56
56
|
};
|
|
57
|
+
const createReady = async (token, params, label, wait, retry) => {
|
|
58
|
+
const attempts = Math.max(1, retry?.attempts ?? 3);
|
|
59
|
+
const backoffMS = retry?.backoffMS ?? 2e3;
|
|
60
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
61
|
+
const id = await platform.createContainer(token, params);
|
|
62
|
+
if (id && await isReady(token, id, label, wait)) return id;
|
|
63
|
+
if (attempt < attempts) {
|
|
64
|
+
const delay = backoffMS * 2 ** (attempt - 1);
|
|
65
|
+
console.warn(
|
|
66
|
+
`[naystack] ${platform.name} ${label} attempt ${attempt}/${attempts} failed \u2014 retrying in ${delay}ms`
|
|
67
|
+
);
|
|
68
|
+
await sleep(delay);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
};
|
|
57
73
|
return {
|
|
58
74
|
/** Creates a container, waits for it to finish processing, then publishes it. */
|
|
59
|
-
publish: async (token, params, wait) => {
|
|
60
|
-
const containerID = await
|
|
75
|
+
publish: async (token, params, wait, retry) => {
|
|
76
|
+
const containerID = await createReady(
|
|
77
|
+
token,
|
|
78
|
+
params,
|
|
79
|
+
"container",
|
|
80
|
+
wait,
|
|
81
|
+
retry
|
|
82
|
+
);
|
|
61
83
|
if (!containerID) return null;
|
|
62
|
-
if (!await isReady(token, containerID, "container", wait)) return null;
|
|
63
84
|
return platform.publish(token, containerID);
|
|
64
85
|
},
|
|
65
86
|
/** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
|
|
66
|
-
createChildren: async (token, items, wait) => {
|
|
87
|
+
createChildren: async (token, items, wait, retry) => {
|
|
67
88
|
const children = [];
|
|
68
89
|
for (const item of items) {
|
|
69
|
-
const childID = await
|
|
70
|
-
|
|
71
|
-
is_carousel_item: true
|
|
72
|
-
|
|
90
|
+
const childID = await createReady(
|
|
91
|
+
token,
|
|
92
|
+
{ ...item, is_carousel_item: true },
|
|
93
|
+
"carousel item",
|
|
94
|
+
wait,
|
|
95
|
+
retry
|
|
96
|
+
);
|
|
73
97
|
if (!childID) return null;
|
|
74
|
-
if (!await isReady(token, childID, "carousel item", wait))
|
|
75
|
-
return null;
|
|
76
98
|
children.push(childID);
|
|
77
99
|
}
|
|
78
100
|
return children;
|
|
@@ -159,13 +181,15 @@ var createThreadsPost = async (token, input, replyToID) => {
|
|
|
159
181
|
const children = await publisher.createChildren(
|
|
160
182
|
token,
|
|
161
183
|
media.map((item) => mediaParams(item)),
|
|
162
|
-
post.wait
|
|
184
|
+
post.wait,
|
|
185
|
+
post.retry
|
|
163
186
|
);
|
|
164
187
|
if (!children) return null;
|
|
165
188
|
return publisher.publish(
|
|
166
189
|
token,
|
|
167
190
|
{ ...shared, media_type: "CAROUSEL", children: children.join(",") },
|
|
168
|
-
post.wait
|
|
191
|
+
post.wait,
|
|
192
|
+
post.retry
|
|
169
193
|
);
|
|
170
194
|
}
|
|
171
195
|
return publisher.publish(
|
|
@@ -175,7 +199,8 @@ var createThreadsPost = async (token, input, replyToID) => {
|
|
|
175
199
|
...shared,
|
|
176
200
|
link_attachment: post.linkAttachment
|
|
177
201
|
},
|
|
178
|
-
post.wait
|
|
202
|
+
post.wait,
|
|
203
|
+
post.retry
|
|
179
204
|
);
|
|
180
205
|
};
|
|
181
206
|
var createThread = async (token, posts) => {
|
|
@@ -27,25 +27,47 @@ function createPublisher(platform) {
|
|
|
27
27
|
}
|
|
28
28
|
return true;
|
|
29
29
|
};
|
|
30
|
+
const createReady = async (token, params, label, wait, retry) => {
|
|
31
|
+
const attempts = Math.max(1, retry?.attempts ?? 3);
|
|
32
|
+
const backoffMS = retry?.backoffMS ?? 2e3;
|
|
33
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
34
|
+
const id = await platform.createContainer(token, params);
|
|
35
|
+
if (id && await isReady(token, id, label, wait)) return id;
|
|
36
|
+
if (attempt < attempts) {
|
|
37
|
+
const delay = backoffMS * 2 ** (attempt - 1);
|
|
38
|
+
console.warn(
|
|
39
|
+
`[naystack] ${platform.name} ${label} attempt ${attempt}/${attempts} failed \u2014 retrying in ${delay}ms`
|
|
40
|
+
);
|
|
41
|
+
await sleep(delay);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
30
46
|
return {
|
|
31
47
|
/** Creates a container, waits for it to finish processing, then publishes it. */
|
|
32
|
-
publish: async (token, params, wait) => {
|
|
33
|
-
const containerID = await
|
|
48
|
+
publish: async (token, params, wait, retry) => {
|
|
49
|
+
const containerID = await createReady(
|
|
50
|
+
token,
|
|
51
|
+
params,
|
|
52
|
+
"container",
|
|
53
|
+
wait,
|
|
54
|
+
retry
|
|
55
|
+
);
|
|
34
56
|
if (!containerID) return null;
|
|
35
|
-
if (!await isReady(token, containerID, "container", wait)) return null;
|
|
36
57
|
return platform.publish(token, containerID);
|
|
37
58
|
},
|
|
38
59
|
/** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
|
|
39
|
-
createChildren: async (token, items, wait) => {
|
|
60
|
+
createChildren: async (token, items, wait, retry) => {
|
|
40
61
|
const children = [];
|
|
41
62
|
for (const item of items) {
|
|
42
|
-
const childID = await
|
|
43
|
-
|
|
44
|
-
is_carousel_item: true
|
|
45
|
-
|
|
63
|
+
const childID = await createReady(
|
|
64
|
+
token,
|
|
65
|
+
{ ...item, is_carousel_item: true },
|
|
66
|
+
"carousel item",
|
|
67
|
+
wait,
|
|
68
|
+
retry
|
|
69
|
+
);
|
|
46
70
|
if (!childID) return null;
|
|
47
|
-
if (!await isReady(token, childID, "carousel item", wait))
|
|
48
|
-
return null;
|
|
49
71
|
children.push(childID);
|
|
50
72
|
}
|
|
51
73
|
return children;
|
|
@@ -132,13 +154,15 @@ var createThreadsPost = async (token, input, replyToID) => {
|
|
|
132
154
|
const children = await publisher.createChildren(
|
|
133
155
|
token,
|
|
134
156
|
media.map((item) => mediaParams(item)),
|
|
135
|
-
post.wait
|
|
157
|
+
post.wait,
|
|
158
|
+
post.retry
|
|
136
159
|
);
|
|
137
160
|
if (!children) return null;
|
|
138
161
|
return publisher.publish(
|
|
139
162
|
token,
|
|
140
163
|
{ ...shared, media_type: "CAROUSEL", children: children.join(",") },
|
|
141
|
-
post.wait
|
|
164
|
+
post.wait,
|
|
165
|
+
post.retry
|
|
142
166
|
);
|
|
143
167
|
}
|
|
144
168
|
return publisher.publish(
|
|
@@ -148,7 +172,8 @@ var createThreadsPost = async (token, input, replyToID) => {
|
|
|
148
172
|
...shared,
|
|
149
173
|
link_attachment: post.linkAttachment
|
|
150
174
|
},
|
|
151
|
-
post.wait
|
|
175
|
+
post.wait,
|
|
176
|
+
post.retry
|
|
152
177
|
);
|
|
153
178
|
};
|
|
154
179
|
var createThread = async (token, posts) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WaitForContainerOptions } from '../meta/container.mjs';
|
|
1
|
+
import { WaitForContainerOptions, RetryOptions } from '../meta/container.mjs';
|
|
2
2
|
import { MetaMediaType } from '../meta/types.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -40,6 +40,7 @@ type ThreadsPostMedia = {
|
|
|
40
40
|
* @property replyToID - Parent post id, to make this post a reply.
|
|
41
41
|
* @property replyControl - Who may reply.
|
|
42
42
|
* @property wait - Container polling settings.
|
|
43
|
+
* @property retry - Container-creation retry settings. See {@link RetryOptions}.
|
|
43
44
|
*
|
|
44
45
|
* @category Socials
|
|
45
46
|
*/
|
|
@@ -50,6 +51,7 @@ type ThreadsPostInput = {
|
|
|
50
51
|
replyToID?: string;
|
|
51
52
|
replyControl?: "everyone" | "accounts_you_follow" | "mentioned_only";
|
|
52
53
|
wait?: WaitForContainerOptions;
|
|
54
|
+
retry?: RetryOptions;
|
|
53
55
|
};
|
|
54
56
|
|
|
55
57
|
export type { ThreadsPost, ThreadsPostInput, ThreadsPostMedia };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WaitForContainerOptions } from '../meta/container.js';
|
|
1
|
+
import { WaitForContainerOptions, RetryOptions } from '../meta/container.js';
|
|
2
2
|
import { MetaMediaType } from '../meta/types.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -40,6 +40,7 @@ type ThreadsPostMedia = {
|
|
|
40
40
|
* @property replyToID - Parent post id, to make this post a reply.
|
|
41
41
|
* @property replyControl - Who may reply.
|
|
42
42
|
* @property wait - Container polling settings.
|
|
43
|
+
* @property retry - Container-creation retry settings. See {@link RetryOptions}.
|
|
43
44
|
*
|
|
44
45
|
* @category Socials
|
|
45
46
|
*/
|
|
@@ -50,6 +51,7 @@ type ThreadsPostInput = {
|
|
|
50
51
|
replyToID?: string;
|
|
51
52
|
replyControl?: "everyone" | "accounts_you_follow" | "mentioned_only";
|
|
52
53
|
wait?: WaitForContainerOptions;
|
|
54
|
+
retry?: RetryOptions;
|
|
53
55
|
};
|
|
54
56
|
|
|
55
57
|
export type { ThreadsPost, ThreadsPostInput, ThreadsPostMedia };
|