naystack 1.8.14 → 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.
@@ -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 platform.createContainer(token, params);
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 platform.createContainer(token, {
714
- ...item,
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;
@@ -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 platform.createContainer(token, params);
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 platform.createContainer(token, {
672
- ...item,
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 platform.createContainer(token, params);
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 platform.createContainer(token, {
237
- ...item,
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 platform.createContainer(token, params);
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 platform.createContainer(token, {
209
- ...item,
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 platform.createContainer(token, params);
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 platform.createContainer(token, {
226
- ...item,
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 platform.createContainer(token, params);
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 platform.createContainer(token, {
202
- ...item,
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;
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/socials/index.ts
21
21
  var socials_exports = {};
22
22
  __export(socials_exports, {
23
+ MetaMediaType: () => MetaMediaType,
23
24
  canPublishToInstagram: () => canPublishToInstagram,
24
25
  createInstagramPost: () => createInstagramPost,
25
26
  createThread: () => createThread,
@@ -201,25 +202,47 @@ function createPublisher(platform) {
201
202
  }
202
203
  return true;
203
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
+ };
204
221
  return {
205
222
  /** Creates a container, waits for it to finish processing, then publishes it. */
206
- publish: async (token, params, wait) => {
207
- const containerID = await platform.createContainer(token, params);
223
+ publish: async (token, params, wait, retry) => {
224
+ const containerID = await createReady(
225
+ token,
226
+ params,
227
+ "container",
228
+ wait,
229
+ retry
230
+ );
208
231
  if (!containerID) return null;
209
- if (!await isReady(token, containerID, "container", wait)) return null;
210
232
  return platform.publish(token, containerID);
211
233
  },
212
234
  /** Creates and awaits every carousel child, resolving to their ids — or `null` if any failed. */
213
- createChildren: async (token, items, wait) => {
235
+ createChildren: async (token, items, wait, retry) => {
214
236
  const children = [];
215
237
  for (const item of items) {
216
- const childID = await platform.createContainer(token, {
217
- ...item,
218
- is_carousel_item: true
219
- });
238
+ const childID = await createReady(
239
+ token,
240
+ { ...item, is_carousel_item: true },
241
+ "carousel item",
242
+ wait,
243
+ retry
244
+ );
220
245
  if (!childID) return null;
221
- if (!await isReady(token, childID, "carousel item", wait))
222
- return null;
223
246
  children.push(childID);
224
247
  }
225
248
  return children;
@@ -227,6 +250,13 @@ function createPublisher(platform) {
227
250
  };
228
251
  }
229
252
 
253
+ // src/socials/meta/types.ts
254
+ var MetaMediaType = /* @__PURE__ */ ((MetaMediaType2) => {
255
+ MetaMediaType2["Photo"] = "photo";
256
+ MetaMediaType2["Video"] = "video";
257
+ return MetaMediaType2;
258
+ })(MetaMediaType || {});
259
+
230
260
  // src/socials/instagram/setters.ts
231
261
  var publisher = createPublisher({
232
262
  name: "Instagram",
@@ -270,14 +300,16 @@ var createInstagramPost = async (token, input) => {
270
300
  media_type: "STORIES",
271
301
  alt_text: void 0
272
302
  },
273
- input.wait
303
+ input.wait,
304
+ input.retry
274
305
  );
275
306
  }
276
307
  if (media.length > 1) {
277
308
  const children = await publisher.createChildren(
278
309
  token,
279
310
  media.map(mediaParams),
280
- input.wait
311
+ input.wait,
312
+ input.retry
281
313
  );
282
314
  if (!children) return null;
283
315
  return publisher.publish(
@@ -287,7 +319,8 @@ var createInstagramPost = async (token, input) => {
287
319
  children: children.join(","),
288
320
  caption: input.caption
289
321
  },
290
- input.wait
322
+ input.wait,
323
+ input.retry
291
324
  );
292
325
  }
293
326
  if (first.type === "video" /* Video */) {
@@ -303,7 +336,8 @@ var createInstagramPost = async (token, input) => {
303
336
  audio_name: input.audioName,
304
337
  collaborators: input.collaborators && JSON.stringify(input.collaborators)
305
338
  },
306
- input.wait
339
+ input.wait,
340
+ input.retry
307
341
  );
308
342
  }
309
343
  return publisher.publish(
@@ -314,7 +348,8 @@ var createInstagramPost = async (token, input) => {
314
348
  alt_text: first.altText,
315
349
  location_id: input.locationID
316
350
  },
317
- input.wait
351
+ input.wait,
352
+ input.retry
318
353
  );
319
354
  };
320
355
  var sendInstagramMessage = (token, to, text) => {
@@ -419,13 +454,15 @@ var createThreadsPost = async (token, input, replyToID) => {
419
454
  const children = await publisher2.createChildren(
420
455
  token,
421
456
  media.map((item) => mediaParams2(item)),
422
- post.wait
457
+ post.wait,
458
+ post.retry
423
459
  );
424
460
  if (!children) return null;
425
461
  return publisher2.publish(
426
462
  token,
427
463
  { ...shared, media_type: "CAROUSEL", children: children.join(",") },
428
- post.wait
464
+ post.wait,
465
+ post.retry
429
466
  );
430
467
  }
431
468
  return publisher2.publish(
@@ -435,7 +472,8 @@ var createThreadsPost = async (token, input, replyToID) => {
435
472
  ...shared,
436
473
  link_attachment: post.linkAttachment
437
474
  },
438
- post.wait
475
+ post.wait,
476
+ post.retry
439
477
  );
440
478
  };
441
479
  var createThread = async (token, posts) => {
@@ -464,6 +502,7 @@ var setupThreadsWebhook = (options) => {
464
502
  };
465
503
  // Annotate the CommonJS export names for ESM import in node:
466
504
  0 && (module.exports = {
505
+ MetaMediaType,
467
506
  canPublishToInstagram,
468
507
  createInstagramPost,
469
508
  createThread,
@@ -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';
@@ -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';