naystack 1.8.15 → 1.8.17

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;
@@ -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 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
+ );
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 platform.createContainer(token, {
218
- ...item,
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) => {
@@ -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';
@@ -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 platform.createContainer(token, params);
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 platform.createContainer(token, {
175
- ...item,
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) => {