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.
- 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 +57 -18
- package/dist/socials/index.d.mts +1 -1
- package/dist/socials/index.d.ts +1 -1
- package/dist/socials/index.esm.js +56 -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
|
@@ -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 };
|