ampost 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +198 -2
- package/dist/cjs/client.d.ts +62 -0
- package/dist/cjs/client.js +206 -0
- package/dist/cjs/core.d.ts +45 -0
- package/dist/cjs/core.js +9 -0
- package/dist/cjs/errors.d.ts +68 -0
- package/dist/cjs/errors.js +153 -0
- package/dist/cjs/generated/resources.d.ts +854 -0
- package/dist/cjs/generated/resources.js +668 -0
- package/dist/cjs/generated/schema.d.ts +5674 -0
- package/dist/cjs/generated/schema.js +3 -0
- package/dist/cjs/generated/types.d.ts +199 -0
- package/dist/cjs/generated/types.js +3 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.js +29 -0
- package/dist/cjs/media.d.ts +42 -0
- package/dist/cjs/media.js +114 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/pagination.d.ts +27 -0
- package/dist/cjs/pagination.js +58 -0
- package/dist/cjs/version.d.ts +2 -0
- package/dist/cjs/version.js +5 -0
- package/dist/esm/client.d.ts +62 -0
- package/dist/esm/client.js +199 -0
- package/dist/esm/core.d.ts +45 -0
- package/dist/esm/core.js +6 -0
- package/dist/esm/errors.d.ts +68 -0
- package/dist/esm/errors.js +135 -0
- package/dist/esm/generated/resources.d.ts +854 -0
- package/dist/esm/generated/resources.js +655 -0
- package/dist/esm/generated/schema.d.ts +5674 -0
- package/dist/esm/generated/schema.js +2 -0
- package/dist/esm/generated/types.d.ts +199 -0
- package/dist/esm/generated/types.js +2 -0
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/media.d.ts +42 -0
- package/dist/esm/media.js +109 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/pagination.d.ts +27 -0
- package/dist/esm/pagination.js +54 -0
- package/dist/esm/version.d.ts +2 -0
- package/dist/esm/version.js +2 -0
- package/package.json +70 -4
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import type { components, operations } from "./schema.js";
|
|
2
|
+
export type Pagination = components["schemas"]["Pagination"];
|
|
3
|
+
export type Error = components["schemas"]["Error"];
|
|
4
|
+
/**
|
|
5
|
+
* A media item at a public URL. Platforms may require metadata: see `media.requiredFields` in GET /api/platforms.
|
|
6
|
+
*/
|
|
7
|
+
export type MediaInput = components["schemas"]["MediaInput"];
|
|
8
|
+
export type ThreadItemInput = components["schemas"]["ThreadItemInput"];
|
|
9
|
+
/**
|
|
10
|
+
* Needs a title, description, image or fields; all embeds together at most 6000 characters.
|
|
11
|
+
*/
|
|
12
|
+
export type DiscordEmbed = components["schemas"]["DiscordEmbed"];
|
|
13
|
+
/**
|
|
14
|
+
* A poll; it cannot be edited later.
|
|
15
|
+
*/
|
|
16
|
+
export type DiscordPoll = components["schemas"]["DiscordPoll"];
|
|
17
|
+
/**
|
|
18
|
+
* Per-platform options keyed by platform. Every platform accepts `text`, the platforms that take a first comment accept `firstComment` and the ones that take a thread (X, Bluesky, Threads) accept `thread`; see GET /api/platforms for the rest.
|
|
19
|
+
*/
|
|
20
|
+
export type PostOptions = components["schemas"]["PostOptions"];
|
|
21
|
+
/**
|
|
22
|
+
* Per-platform options to change. Each platform key you send replaces that platform's options as a whole (send every field you want to keep, e.g. both `text` and `placement`); `null` removes them. Platforms you leave out keep their options.
|
|
23
|
+
*/
|
|
24
|
+
export type PostOptionsUpdate = components["schemas"]["PostOptionsUpdate"];
|
|
25
|
+
export type Platform = components["schemas"]["Platform"];
|
|
26
|
+
/**
|
|
27
|
+
* Public details captured at connect time; each platform fills only its own fields.
|
|
28
|
+
*/
|
|
29
|
+
export type PlatformMetadata = components["schemas"]["PlatformMetadata"];
|
|
30
|
+
export type AccountHealthIssue = components["schemas"]["AccountHealthIssue"];
|
|
31
|
+
/**
|
|
32
|
+
* Whether the account can publish, and why not. Derived from the status, token expiry and granted scopes.
|
|
33
|
+
*/
|
|
34
|
+
export type AccountHealth = components["schemas"]["AccountHealth"];
|
|
35
|
+
/**
|
|
36
|
+
* Whether Ampost collects analytics for the account.
|
|
37
|
+
*/
|
|
38
|
+
export type AccountAnalytics = components["schemas"]["AccountAnalytics"];
|
|
39
|
+
export type Account = components["schemas"]["Account"];
|
|
40
|
+
export type SetAccountAnalyticsRequest = components["schemas"]["SetAccountAnalyticsRequest"];
|
|
41
|
+
export type PinterestBoard = components["schemas"]["PinterestBoard"];
|
|
42
|
+
export type PinterestBoardList = components["schemas"]["PinterestBoardList"];
|
|
43
|
+
export type SetPinterestBoardRequest = components["schemas"]["SetPinterestBoardRequest"];
|
|
44
|
+
export type DisconnectedAccount = components["schemas"]["DisconnectedAccount"];
|
|
45
|
+
export type AccountList = components["schemas"]["AccountList"];
|
|
46
|
+
export type PlatformSet = components["schemas"]["PlatformSet"];
|
|
47
|
+
export type PlatformSetList = components["schemas"]["PlatformSetList"];
|
|
48
|
+
export type PlatformSetRequest = components["schemas"]["PlatformSetRequest"];
|
|
49
|
+
export type Deleted = components["schemas"]["Deleted"];
|
|
50
|
+
export type ConnectAccountRequest = components["schemas"]["ConnectAccountRequest"];
|
|
51
|
+
export type ConnectRequestCreated = components["schemas"]["ConnectRequestCreated"];
|
|
52
|
+
export type ConnectRequest = components["schemas"]["ConnectRequest"];
|
|
53
|
+
/**
|
|
54
|
+
* A file uploaded in the same multipart request (the whole request max 4 MB; larger files go through POST /api/media/uploads). Type, MIME type and size come from the file.
|
|
55
|
+
*/
|
|
56
|
+
export type MediaFileInput = components["schemas"]["MediaFileInput"];
|
|
57
|
+
export type Media = components["schemas"]["Media"];
|
|
58
|
+
export type PlatformFirstComment = components["schemas"]["PlatformFirstComment"];
|
|
59
|
+
/**
|
|
60
|
+
* How media outside a platform's aspect ratio is fitted (`media.conversion` in GET /api/platforms), e.g. Instagram feed 4:5 to 1.91:1, Reels, Stories and TikTok 9:16, and on Pinterest a carousel's later images to the first one's ratio. pad: bars around the whole frame (white on images, black on video); crop: the centre fills the frame; none: the ratio stays as uploaded (a platform that requires one may refuse it). Default: pad.
|
|
61
|
+
*/
|
|
62
|
+
export type MediaFit = components["schemas"]["MediaFit"];
|
|
63
|
+
export type MediaTransform = components["schemas"]["MediaTransform"];
|
|
64
|
+
export type PlatformThreadItem = components["schemas"]["PlatformThreadItem"];
|
|
65
|
+
export type ThreadItem = components["schemas"]["ThreadItem"];
|
|
66
|
+
export type PlatformPost = components["schemas"]["PlatformPost"];
|
|
67
|
+
export type PostTarget = components["schemas"]["PostTarget"];
|
|
68
|
+
export type Post = components["schemas"]["Post"];
|
|
69
|
+
export type PostList = components["schemas"]["PostList"];
|
|
70
|
+
export type ValidationIssue = components["schemas"]["ValidationIssue"];
|
|
71
|
+
export type MediaConversionPreview = components["schemas"]["MediaConversionPreview"];
|
|
72
|
+
export type PostValidationTarget = components["schemas"]["PostValidationTarget"];
|
|
73
|
+
export type PostValidation = components["schemas"]["PostValidation"];
|
|
74
|
+
/**
|
|
75
|
+
* Platforms of one platform set. Each goes to the set's account for that platform.
|
|
76
|
+
*/
|
|
77
|
+
export type PostTargetInput = components["schemas"]["PostTargetInput"];
|
|
78
|
+
export type CreatePostRequest = components["schemas"]["CreatePostRequest"];
|
|
79
|
+
export type CreatePostMultipartData = components["schemas"]["CreatePostMultipartData"];
|
|
80
|
+
/**
|
|
81
|
+
* Fields to change. Omitted fields keep their value. Only draft and scheduled posts can change.
|
|
82
|
+
*/
|
|
83
|
+
export type UpdatePostRequest = components["schemas"]["UpdatePostRequest"];
|
|
84
|
+
export type UnpublishPostRequest = components["schemas"]["UnpublishPostRequest"];
|
|
85
|
+
export type EditPublishedPostRequest = components["schemas"]["EditPublishedPostRequest"];
|
|
86
|
+
export type RetryPostRequest = components["schemas"]["RetryPostRequest"];
|
|
87
|
+
export type AnalyticsMetrics = components["schemas"]["AnalyticsMetrics"];
|
|
88
|
+
export type AnalyticsUnavailableAccount = components["schemas"]["AnalyticsUnavailableAccount"];
|
|
89
|
+
export type AnalyticsPlatformPost = components["schemas"]["AnalyticsPlatformPost"];
|
|
90
|
+
export type AnalyticsPost = components["schemas"]["AnalyticsPost"];
|
|
91
|
+
export type AnalyticsPostList = components["schemas"]["AnalyticsPostList"];
|
|
92
|
+
export type AnalyticsAccountSummary = components["schemas"]["AnalyticsAccountSummary"];
|
|
93
|
+
export type AnalyticsOverview = components["schemas"]["AnalyticsOverview"];
|
|
94
|
+
export type AnalyticsFollowerPoint = components["schemas"]["AnalyticsFollowerPoint"];
|
|
95
|
+
export type AnalyticsFollowers = components["schemas"]["AnalyticsFollowers"];
|
|
96
|
+
export type AnalyticsFollowersList = components["schemas"]["AnalyticsFollowersList"];
|
|
97
|
+
export type DocsSearchResult = components["schemas"]["DocsSearchResult"];
|
|
98
|
+
export type DocsSearchResults = components["schemas"]["DocsSearchResults"];
|
|
99
|
+
export type FeedbackReceipt = components["schemas"]["FeedbackReceipt"];
|
|
100
|
+
export type CreateMediaUploadRequest = components["schemas"]["CreateMediaUploadRequest"];
|
|
101
|
+
export type MediaUploadLimits = components["schemas"]["MediaUploadLimits"];
|
|
102
|
+
export type MediaUploadCreated = components["schemas"]["MediaUploadCreated"];
|
|
103
|
+
/**
|
|
104
|
+
* An uploaded file in the `media[]` item shape: pass it to posts_create as is (add `altText` if you like). Type, size, width, height and duration are read from the file itself; images are re-saved without metadata (EXIF, GPS), so the URL is not the one the file was uploaded to. A video duration the container does not state is null.
|
|
105
|
+
*/
|
|
106
|
+
export type UploadedMedia = components["schemas"]["UploadedMedia"];
|
|
107
|
+
export type MediaUpload = components["schemas"]["MediaUpload"];
|
|
108
|
+
export type PlatformList = components["schemas"]["PlatformList"];
|
|
109
|
+
export type Webhook = components["schemas"]["Webhook"];
|
|
110
|
+
export type WebhookList = components["schemas"]["WebhookList"];
|
|
111
|
+
export type CreateWebhookRequest = components["schemas"]["CreateWebhookRequest"];
|
|
112
|
+
/**
|
|
113
|
+
* Fields to change. Omitted fields keep their value.
|
|
114
|
+
*/
|
|
115
|
+
export type UpdateWebhookRequest = components["schemas"]["UpdateWebhookRequest"];
|
|
116
|
+
export type WebhookDelivery = components["schemas"]["WebhookDelivery"];
|
|
117
|
+
export type WebhookDeliveryList = components["schemas"]["WebhookDeliveryList"];
|
|
118
|
+
export type WebhookEvent = components["schemas"]["WebhookEvent"];
|
|
119
|
+
export type QueueSlot = components["schemas"]["QueueSlot"];
|
|
120
|
+
export type Queue = components["schemas"]["Queue"];
|
|
121
|
+
/**
|
|
122
|
+
* Fields to change. Omitted fields keep their value; a new queue starts in UTC with no slots.
|
|
123
|
+
*/
|
|
124
|
+
export type UpdateQueueRequest = components["schemas"]["UpdateQueueRequest"];
|
|
125
|
+
export type QueuePreview = components["schemas"]["QueuePreview"];
|
|
126
|
+
export type ImportPostsCsvRequest = components["schemas"]["ImportPostsCsvRequest"];
|
|
127
|
+
export type ImportRowResult = components["schemas"]["ImportRowResult"];
|
|
128
|
+
export type ImportPostsCsvResult = components["schemas"]["ImportPostsCsvResult"];
|
|
129
|
+
export type PlatformsListQuery = NonNullable<operations["platforms_list"]["parameters"]["query"]>;
|
|
130
|
+
export type PlatformsListResponse = operations["platforms_list"]["responses"][200]["content"]["application/json"];
|
|
131
|
+
export type PostsListQuery = NonNullable<operations["posts_list"]["parameters"]["query"]>;
|
|
132
|
+
export type PostsListResponse = operations["posts_list"]["responses"][200]["content"]["application/json"];
|
|
133
|
+
export type PostsCreateBody = NonNullable<operations["posts_create"]["requestBody"]>["content"]["application/json"];
|
|
134
|
+
export type PostsCreateResponse = operations["posts_create"]["responses"][201]["content"]["application/json"];
|
|
135
|
+
export type PostsValidateBody = NonNullable<operations["posts_validate"]["requestBody"]>["content"]["application/json"];
|
|
136
|
+
export type PostsValidateResponse = operations["posts_validate"]["responses"][200]["content"]["application/json"];
|
|
137
|
+
export type PostsImportCsvBody = NonNullable<operations["posts_import_csv"]["requestBody"]>["content"]["application/json"];
|
|
138
|
+
export type PostsImportCsvResponse = operations["posts_import_csv"]["responses"][200]["content"]["application/json"];
|
|
139
|
+
export type PostsGetResponse = operations["posts_get"]["responses"][200]["content"]["application/json"];
|
|
140
|
+
export type PostsUpdateBody = NonNullable<operations["posts_update"]["requestBody"]>["content"]["application/json"];
|
|
141
|
+
export type PostsUpdateResponse = operations["posts_update"]["responses"][200]["content"]["application/json"];
|
|
142
|
+
export type PostsDeleteResponse = operations["posts_delete"]["responses"][200]["content"]["application/json"];
|
|
143
|
+
export type PostsPublishResponse = operations["posts_publish"]["responses"][200]["content"]["application/json"];
|
|
144
|
+
export type PostsUnpublishBody = NonNullable<operations["posts_unpublish"]["requestBody"]>["content"]["application/json"];
|
|
145
|
+
export type PostsUnpublishResponse = operations["posts_unpublish"]["responses"][200]["content"]["application/json"];
|
|
146
|
+
export type PostsEditPublishedBody = NonNullable<operations["posts_edit_published"]["requestBody"]>["content"]["application/json"];
|
|
147
|
+
export type PostsEditPublishedResponse = operations["posts_edit_published"]["responses"][200]["content"]["application/json"];
|
|
148
|
+
export type PostsRetryBody = NonNullable<operations["posts_retry"]["requestBody"]>["content"]["application/json"];
|
|
149
|
+
export type PostsRetryResponse = operations["posts_retry"]["responses"][200]["content"]["application/json"];
|
|
150
|
+
export type MediaUploadCreateBody = NonNullable<operations["media_upload_create"]["requestBody"]>["content"]["application/json"];
|
|
151
|
+
export type MediaUploadCreateResponse = operations["media_upload_create"]["responses"][201]["content"]["application/json"];
|
|
152
|
+
export type MediaUploadStatusResponse = operations["media_upload_status"]["responses"][200]["content"]["application/json"];
|
|
153
|
+
export type AccountsListQuery = NonNullable<operations["accounts_list"]["parameters"]["query"]>;
|
|
154
|
+
export type AccountsListResponse = operations["accounts_list"]["responses"][200]["content"]["application/json"];
|
|
155
|
+
export type AccountsGetResponse = operations["accounts_get"]["responses"][200]["content"]["application/json"];
|
|
156
|
+
export type AccountsDisconnectResponse = operations["accounts_disconnect"]["responses"][200]["content"]["application/json"];
|
|
157
|
+
export type AccountsSetAnalyticsBody = NonNullable<operations["accounts_set_analytics"]["requestBody"]>["content"]["application/json"];
|
|
158
|
+
export type AccountsSetAnalyticsResponse = operations["accounts_set_analytics"]["responses"][200]["content"]["application/json"];
|
|
159
|
+
export type AccountsListBoardsResponse = operations["accounts_list_boards"]["responses"][200]["content"]["application/json"];
|
|
160
|
+
export type AccountsSetBoardBody = NonNullable<operations["accounts_set_board"]["requestBody"]>["content"]["application/json"];
|
|
161
|
+
export type AccountsSetBoardResponse = operations["accounts_set_board"]["responses"][200]["content"]["application/json"];
|
|
162
|
+
export type AccountsConnectBody = NonNullable<operations["accounts_connect"]["requestBody"]>["content"]["application/json"];
|
|
163
|
+
export type AccountsConnectResponse = operations["accounts_connect"]["responses"][201]["content"]["application/json"];
|
|
164
|
+
export type AccountsConnectStatusResponse = operations["accounts_connect_status"]["responses"][200]["content"]["application/json"];
|
|
165
|
+
export type PlatformSetsListQuery = NonNullable<operations["platform_sets_list"]["parameters"]["query"]>;
|
|
166
|
+
export type PlatformSetsListResponse = operations["platform_sets_list"]["responses"][200]["content"]["application/json"];
|
|
167
|
+
export type PlatformSetsCreateBody = NonNullable<operations["platform_sets_create"]["requestBody"]>["content"]["application/json"];
|
|
168
|
+
export type PlatformSetsCreateResponse = operations["platform_sets_create"]["responses"][201]["content"]["application/json"];
|
|
169
|
+
export type PlatformSetsGetResponse = operations["platform_sets_get"]["responses"][200]["content"]["application/json"];
|
|
170
|
+
export type PlatformSetsUpdateBody = NonNullable<operations["platform_sets_update"]["requestBody"]>["content"]["application/json"];
|
|
171
|
+
export type PlatformSetsUpdateResponse = operations["platform_sets_update"]["responses"][200]["content"]["application/json"];
|
|
172
|
+
export type PlatformSetsDeleteResponse = operations["platform_sets_delete"]["responses"][200]["content"]["application/json"];
|
|
173
|
+
export type QueueGetResponse = operations["queue_get"]["responses"][200]["content"]["application/json"];
|
|
174
|
+
export type QueueUpdateBody = NonNullable<operations["queue_update"]["requestBody"]>["content"]["application/json"];
|
|
175
|
+
export type QueueUpdateResponse = operations["queue_update"]["responses"][200]["content"]["application/json"];
|
|
176
|
+
export type QueueSlotsQuery = NonNullable<operations["queue_slots"]["parameters"]["query"]>;
|
|
177
|
+
export type QueueSlotsResponse = operations["queue_slots"]["responses"][200]["content"]["application/json"];
|
|
178
|
+
export type AnalyticsPostsQuery = NonNullable<operations["analytics_posts"]["parameters"]["query"]>;
|
|
179
|
+
export type AnalyticsPostsResponse = operations["analytics_posts"]["responses"][200]["content"]["application/json"];
|
|
180
|
+
export type AnalyticsOverviewQuery = NonNullable<operations["analytics_overview"]["parameters"]["query"]>;
|
|
181
|
+
export type AnalyticsOverviewResponse = operations["analytics_overview"]["responses"][200]["content"]["application/json"];
|
|
182
|
+
export type AnalyticsFollowersQuery = NonNullable<operations["analytics_followers"]["parameters"]["query"]>;
|
|
183
|
+
export type AnalyticsFollowersResponse = operations["analytics_followers"]["responses"][200]["content"]["application/json"];
|
|
184
|
+
export type WebhooksListQuery = NonNullable<operations["webhooks_list"]["parameters"]["query"]>;
|
|
185
|
+
export type WebhooksListResponse = operations["webhooks_list"]["responses"][200]["content"]["application/json"];
|
|
186
|
+
export type WebhooksCreateBody = NonNullable<operations["webhooks_create"]["requestBody"]>["content"]["application/json"];
|
|
187
|
+
export type WebhooksCreateResponse = operations["webhooks_create"]["responses"][201]["content"]["application/json"];
|
|
188
|
+
export type WebhooksGetResponse = operations["webhooks_get"]["responses"][200]["content"]["application/json"];
|
|
189
|
+
export type WebhooksUpdateBody = NonNullable<operations["webhooks_update"]["requestBody"]>["content"]["application/json"];
|
|
190
|
+
export type WebhooksUpdateResponse = operations["webhooks_update"]["responses"][200]["content"]["application/json"];
|
|
191
|
+
export type WebhooksDeleteResponse = operations["webhooks_delete"]["responses"][200]["content"]["application/json"];
|
|
192
|
+
export type WebhooksTestResponse = operations["webhooks_test"]["responses"][200]["content"]["application/json"];
|
|
193
|
+
export type WebhooksDeliveriesListQuery = NonNullable<operations["webhooks_deliveries_list"]["parameters"]["query"]>;
|
|
194
|
+
export type WebhooksDeliveriesListResponse = operations["webhooks_deliveries_list"]["responses"][200]["content"]["application/json"];
|
|
195
|
+
export type WebhooksRedeliverResponse = operations["webhooks_redeliver"]["responses"][200]["content"]["application/json"];
|
|
196
|
+
export type DocsSearchQuery = NonNullable<operations["docs_search"]["parameters"]["query"]>;
|
|
197
|
+
export type DocsSearchResponse = operations["docs_search"]["responses"][200]["content"]["application/json"];
|
|
198
|
+
export type FeedbackSubmitBody = NonNullable<operations["feedback_submit"]["requestBody"]>["content"]["application/json"];
|
|
199
|
+
export type FeedbackSubmitResponse = operations["feedback_submit"]["responses"][201]["content"]["application/json"];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { Ampost, DEFAULT_BASE_URL } from "./client.js";
|
|
2
|
+
export type { ClientOptions } from "./client.js";
|
|
3
|
+
export type { IdempotentRequestOptions, RequestOptions, RequestSpec, ListResponse } from "./core.js";
|
|
4
|
+
export { AmpostError, APIError, BadRequestError, AuthenticationError, PermissionDeniedError, NotFoundError, ConflictError, PayloadTooLargeError, UnprocessableEntityError, RateLimitError, InternalServerError, APIConnectionError, APITimeoutError, MediaUploadError, } from "./errors.js";
|
|
5
|
+
export { PagePromise } from "./pagination.js";
|
|
6
|
+
export { MediaResource } from "./media.js";
|
|
7
|
+
export type { UploadOptions, UploadSource, WaitOptions } from "./media.js";
|
|
8
|
+
export { OPERATIONS } from "./generated/resources.js";
|
|
9
|
+
export type * from "./generated/types.js";
|
|
10
|
+
export type { components, operations, paths } from "./generated/schema.js";
|
|
11
|
+
export { VERSION } from "./version.js";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VERSION = exports.OPERATIONS = exports.MediaResource = exports.PagePromise = exports.MediaUploadError = exports.APITimeoutError = exports.APIConnectionError = exports.InternalServerError = exports.RateLimitError = exports.UnprocessableEntityError = exports.PayloadTooLargeError = exports.ConflictError = exports.NotFoundError = exports.PermissionDeniedError = exports.AuthenticationError = exports.BadRequestError = exports.APIError = exports.AmpostError = exports.DEFAULT_BASE_URL = exports.Ampost = void 0;
|
|
4
|
+
var client_js_1 = require("./client.js");
|
|
5
|
+
Object.defineProperty(exports, "Ampost", { enumerable: true, get: function () { return client_js_1.Ampost; } });
|
|
6
|
+
Object.defineProperty(exports, "DEFAULT_BASE_URL", { enumerable: true, get: function () { return client_js_1.DEFAULT_BASE_URL; } });
|
|
7
|
+
var errors_js_1 = require("./errors.js");
|
|
8
|
+
Object.defineProperty(exports, "AmpostError", { enumerable: true, get: function () { return errors_js_1.AmpostError; } });
|
|
9
|
+
Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return errors_js_1.APIError; } });
|
|
10
|
+
Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return errors_js_1.BadRequestError; } });
|
|
11
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_js_1.AuthenticationError; } });
|
|
12
|
+
Object.defineProperty(exports, "PermissionDeniedError", { enumerable: true, get: function () { return errors_js_1.PermissionDeniedError; } });
|
|
13
|
+
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_js_1.NotFoundError; } });
|
|
14
|
+
Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return errors_js_1.ConflictError; } });
|
|
15
|
+
Object.defineProperty(exports, "PayloadTooLargeError", { enumerable: true, get: function () { return errors_js_1.PayloadTooLargeError; } });
|
|
16
|
+
Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, get: function () { return errors_js_1.UnprocessableEntityError; } });
|
|
17
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_js_1.RateLimitError; } });
|
|
18
|
+
Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return errors_js_1.InternalServerError; } });
|
|
19
|
+
Object.defineProperty(exports, "APIConnectionError", { enumerable: true, get: function () { return errors_js_1.APIConnectionError; } });
|
|
20
|
+
Object.defineProperty(exports, "APITimeoutError", { enumerable: true, get: function () { return errors_js_1.APITimeoutError; } });
|
|
21
|
+
Object.defineProperty(exports, "MediaUploadError", { enumerable: true, get: function () { return errors_js_1.MediaUploadError; } });
|
|
22
|
+
var pagination_js_1 = require("./pagination.js");
|
|
23
|
+
Object.defineProperty(exports, "PagePromise", { enumerable: true, get: function () { return pagination_js_1.PagePromise; } });
|
|
24
|
+
var media_js_1 = require("./media.js");
|
|
25
|
+
Object.defineProperty(exports, "MediaResource", { enumerable: true, get: function () { return media_js_1.MediaResource; } });
|
|
26
|
+
var resources_js_1 = require("./generated/resources.js");
|
|
27
|
+
Object.defineProperty(exports, "OPERATIONS", { enumerable: true, get: function () { return resources_js_1.OPERATIONS; } });
|
|
28
|
+
var version_js_1 = require("./version.js");
|
|
29
|
+
Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_js_1.VERSION; } });
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { RawResponse } from "./client.js";
|
|
2
|
+
import type { RequestOptions, Transport } from "./core.js";
|
|
3
|
+
import { Media } from "./generated/resources.js";
|
|
4
|
+
import type { MediaUpload, UploadedMedia } from "./generated/types.js";
|
|
5
|
+
/** A file to upload: a path (Node), a `Blob`/`File`, or raw bytes. */
|
|
6
|
+
export type UploadSource = string | Blob | ArrayBuffer | ArrayBufferView;
|
|
7
|
+
export interface UploadOptions extends RequestOptions {
|
|
8
|
+
/** Name at the end of the file URL. Default: the path's or File's name, else `file`. */
|
|
9
|
+
fileName?: string;
|
|
10
|
+
/** MIME type, e.g. `video/mp4`. Default: the Blob's type, else guessed from the file name. */
|
|
11
|
+
contentType?: string;
|
|
12
|
+
/** How often to check whether Ampost has processed the file. Default 2000 ms. */
|
|
13
|
+
pollIntervalMs?: number;
|
|
14
|
+
/** How long to wait for processing before giving up. Default 120 000 ms. */
|
|
15
|
+
waitTimeoutMs?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface WaitOptions extends RequestOptions {
|
|
18
|
+
pollIntervalMs?: number;
|
|
19
|
+
waitTimeoutMs?: number;
|
|
20
|
+
}
|
|
21
|
+
type Send = (url: string, init: RequestInit, options?: RequestOptions) => Promise<RawResponse>;
|
|
22
|
+
export declare class MediaResource extends Media {
|
|
23
|
+
private readonly send;
|
|
24
|
+
constructor(transport: Transport, send: Send);
|
|
25
|
+
/**
|
|
26
|
+
* Uploads one image or video and returns it as a `media[]` item for `posts.create`:
|
|
27
|
+
*
|
|
28
|
+
* const video = await client.media.upload("./launch.mp4");
|
|
29
|
+
* await client.posts.create({ text: "We launched", media: [video], targets: [{ platforms: ["tiktok"] }] });
|
|
30
|
+
*
|
|
31
|
+
* Steps: `createUpload`, a PUT of the bytes to the returned `uploadUrl` (straight to storage; your API
|
|
32
|
+
* key is not sent there), then `getUpload` until Ampost has checked the file.
|
|
33
|
+
*/
|
|
34
|
+
upload(source: UploadSource, options?: UploadOptions): Promise<UploadedMedia>;
|
|
35
|
+
/**
|
|
36
|
+
* Polls an upload until it is `completed` and returns it; throws `MediaUploadError` when it `failed` or
|
|
37
|
+
* `expired`, or is still pending after `waitTimeoutMs`. Use it after showing `uploadPageUrl` to a user.
|
|
38
|
+
*/
|
|
39
|
+
waitForUpload(uploadId: string, options?: WaitOptions): Promise<MediaUpload>;
|
|
40
|
+
}
|
|
41
|
+
export declare function guessContentType(fileName: string): string | undefined;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MediaResource = void 0;
|
|
4
|
+
exports.guessContentType = guessContentType;
|
|
5
|
+
const errors_js_1 = require("./errors.js");
|
|
6
|
+
const resources_js_1 = require("./generated/resources.js");
|
|
7
|
+
const MIME_TYPES = {
|
|
8
|
+
jpg: "image/jpeg",
|
|
9
|
+
jpeg: "image/jpeg",
|
|
10
|
+
png: "image/png",
|
|
11
|
+
webp: "image/webp",
|
|
12
|
+
gif: "image/gif",
|
|
13
|
+
mp4: "video/mp4",
|
|
14
|
+
m4v: "video/mp4",
|
|
15
|
+
mov: "video/quicktime",
|
|
16
|
+
webm: "video/webm",
|
|
17
|
+
};
|
|
18
|
+
/** Large videos take a while to send; the API's per-request timeout would be too short. */
|
|
19
|
+
const UPLOAD_TIMEOUT_MS = 15 * 60_000;
|
|
20
|
+
class MediaResource extends resources_js_1.Media {
|
|
21
|
+
send;
|
|
22
|
+
constructor(transport, send) {
|
|
23
|
+
super(transport);
|
|
24
|
+
this.send = send;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Uploads one image or video and returns it as a `media[]` item for `posts.create`:
|
|
28
|
+
*
|
|
29
|
+
* const video = await client.media.upload("./launch.mp4");
|
|
30
|
+
* await client.posts.create({ text: "We launched", media: [video], targets: [{ platforms: ["tiktok"] }] });
|
|
31
|
+
*
|
|
32
|
+
* Steps: `createUpload`, a PUT of the bytes to the returned `uploadUrl` (straight to storage; your API
|
|
33
|
+
* key is not sent there), then `getUpload` until Ampost has checked the file.
|
|
34
|
+
*/
|
|
35
|
+
async upload(source, options = {}) {
|
|
36
|
+
const file = await readSource(source, options);
|
|
37
|
+
const created = await this.createUpload({ fileName: file.fileName }, options);
|
|
38
|
+
const response = await this.send(created.uploadUrl, {
|
|
39
|
+
method: created.method,
|
|
40
|
+
headers: { ...created.headers, "x-content-type": file.contentType },
|
|
41
|
+
body: file.body,
|
|
42
|
+
}, { ...options, timeoutMs: options.timeoutMs ?? UPLOAD_TIMEOUT_MS });
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
throw new errors_js_1.MediaUploadError(`Storage refused the file: HTTP ${response.status} ${response.text.slice(0, 300)}`.trim(), "upload_rejected", created.id);
|
|
45
|
+
}
|
|
46
|
+
const upload = await this.waitForUpload(created.id, options);
|
|
47
|
+
const [uploaded] = upload.files;
|
|
48
|
+
if (!uploaded)
|
|
49
|
+
throw new errors_js_1.MediaUploadError("The upload completed without a file", "failed", created.id);
|
|
50
|
+
return uploaded;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Polls an upload until it is `completed` and returns it; throws `MediaUploadError` when it `failed` or
|
|
54
|
+
* `expired`, or is still pending after `waitTimeoutMs`. Use it after showing `uploadPageUrl` to a user.
|
|
55
|
+
*/
|
|
56
|
+
async waitForUpload(uploadId, options = {}) {
|
|
57
|
+
const interval = options.pollIntervalMs ?? 2_000;
|
|
58
|
+
const deadline = Date.now() + (options.waitTimeoutMs ?? 120_000);
|
|
59
|
+
for (;;) {
|
|
60
|
+
const upload = await this.getUpload(uploadId, options);
|
|
61
|
+
if (upload.status === "completed")
|
|
62
|
+
return upload;
|
|
63
|
+
if (upload.status === "failed") {
|
|
64
|
+
throw new errors_js_1.MediaUploadError(`The upload failed: ${upload.error ?? "the file was refused"}`, "failed", uploadId);
|
|
65
|
+
}
|
|
66
|
+
if (upload.status === "expired") {
|
|
67
|
+
throw new errors_js_1.MediaUploadError("The upload expired before a file arrived; create a new one", "expired", uploadId);
|
|
68
|
+
}
|
|
69
|
+
if (Date.now() + interval > deadline) {
|
|
70
|
+
throw new errors_js_1.MediaUploadError("The upload is still being processed; check it later with getUpload", "timeout", uploadId);
|
|
71
|
+
}
|
|
72
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.MediaResource = MediaResource;
|
|
77
|
+
async function readSource(source, options) {
|
|
78
|
+
let body;
|
|
79
|
+
let name;
|
|
80
|
+
let type;
|
|
81
|
+
if (typeof source === "string") {
|
|
82
|
+
const fs = await Promise.resolve().then(() => require("node:fs"));
|
|
83
|
+
const path = await Promise.resolve().then(() => require("node:path"));
|
|
84
|
+
// openAsBlob (Node 20+) streams the file; Node 18 reads it into memory.
|
|
85
|
+
const openAsBlob = fs.openAsBlob;
|
|
86
|
+
body = openAsBlob ? await openAsBlob(source) : new Uint8Array(await fs.promises.readFile(source));
|
|
87
|
+
name = path.basename(source);
|
|
88
|
+
}
|
|
89
|
+
else if (typeof Blob !== "undefined" && source instanceof Blob) {
|
|
90
|
+
body = source;
|
|
91
|
+
name = source.name || undefined;
|
|
92
|
+
type = source.type || undefined;
|
|
93
|
+
}
|
|
94
|
+
else if (source instanceof ArrayBuffer) {
|
|
95
|
+
body = source;
|
|
96
|
+
}
|
|
97
|
+
else if (ArrayBuffer.isView(source)) {
|
|
98
|
+
// A copy: fetch takes no SharedArrayBuffer-backed views.
|
|
99
|
+
body = new Uint8Array(source.buffer, source.byteOffset, source.byteLength).slice();
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
throw new TypeError("upload() takes a file path, a Blob/File, an ArrayBuffer or a Uint8Array/Buffer");
|
|
103
|
+
}
|
|
104
|
+
const fileName = options.fileName ?? name ?? "file";
|
|
105
|
+
const contentType = options.contentType ?? type ?? guessContentType(fileName);
|
|
106
|
+
if (!contentType) {
|
|
107
|
+
throw new errors_js_1.AmpostError(`Cannot tell the MIME type of ${JSON.stringify(fileName)}: pass { contentType }`);
|
|
108
|
+
}
|
|
109
|
+
return { body, fileName, contentType };
|
|
110
|
+
}
|
|
111
|
+
function guessContentType(fileName) {
|
|
112
|
+
const extension = /\.([a-z0-9]+)$/i.exec(fileName)?.[1]?.toLowerCase();
|
|
113
|
+
return extension ? MIME_TYPES[extension] : undefined;
|
|
114
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ListResponse } from "./core.js";
|
|
2
|
+
/**
|
|
3
|
+
* What every list method returns. Await it for one page:
|
|
4
|
+
*
|
|
5
|
+
* const { data, pagination } = await client.posts.list({ limit: 50 });
|
|
6
|
+
*
|
|
7
|
+
* or iterate it to walk every item, fetching the next page as needed:
|
|
8
|
+
*
|
|
9
|
+
* for await (const post of client.posts.list({ status: "failed" })) { ... }
|
|
10
|
+
*
|
|
11
|
+
* The first page is requested once, on first use.
|
|
12
|
+
*/
|
|
13
|
+
export declare class PagePromise<T extends ListResponse> implements Promise<T>, AsyncIterable<T["data"][number]> {
|
|
14
|
+
private readonly fetchPage;
|
|
15
|
+
readonly [Symbol.toStringTag] = "PagePromise";
|
|
16
|
+
private first;
|
|
17
|
+
constructor(fetchPage: (offset: number | undefined) => Promise<T>);
|
|
18
|
+
private firstPage;
|
|
19
|
+
then<R1 = T, R2 = never>(onFulfilled?: ((value: T) => R1 | PromiseLike<R1>) | null, onRejected?: ((reason: unknown) => R2 | PromiseLike<R2>) | null): Promise<R1 | R2>;
|
|
20
|
+
catch<R = never>(onRejected?: ((reason: unknown) => R | PromiseLike<R>) | null): Promise<T | R>;
|
|
21
|
+
finally(onFinally?: (() => void) | null): Promise<T>;
|
|
22
|
+
/** Every page, starting with the first. */
|
|
23
|
+
pages(): AsyncGenerator<T, void, undefined>;
|
|
24
|
+
[Symbol.asyncIterator](): AsyncGenerator<T["data"][number], void, undefined>;
|
|
25
|
+
/** Collects every item into an array. Mind large accounts: prefer `for await`. */
|
|
26
|
+
toArray(): Promise<T["data"][number][]>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PagePromise = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* What every list method returns. Await it for one page:
|
|
6
|
+
*
|
|
7
|
+
* const { data, pagination } = await client.posts.list({ limit: 50 });
|
|
8
|
+
*
|
|
9
|
+
* or iterate it to walk every item, fetching the next page as needed:
|
|
10
|
+
*
|
|
11
|
+
* for await (const post of client.posts.list({ status: "failed" })) { ... }
|
|
12
|
+
*
|
|
13
|
+
* The first page is requested once, on first use.
|
|
14
|
+
*/
|
|
15
|
+
class PagePromise {
|
|
16
|
+
fetchPage;
|
|
17
|
+
[Symbol.toStringTag] = "PagePromise";
|
|
18
|
+
first;
|
|
19
|
+
constructor(fetchPage) {
|
|
20
|
+
this.fetchPage = fetchPage;
|
|
21
|
+
}
|
|
22
|
+
firstPage() {
|
|
23
|
+
this.first ??= this.fetchPage(undefined);
|
|
24
|
+
return this.first;
|
|
25
|
+
}
|
|
26
|
+
then(onFulfilled, onRejected) {
|
|
27
|
+
return this.firstPage().then(onFulfilled, onRejected);
|
|
28
|
+
}
|
|
29
|
+
catch(onRejected) {
|
|
30
|
+
return this.firstPage().catch(onRejected);
|
|
31
|
+
}
|
|
32
|
+
finally(onFinally) {
|
|
33
|
+
return this.firstPage().finally(onFinally);
|
|
34
|
+
}
|
|
35
|
+
/** Every page, starting with the first. */
|
|
36
|
+
async *pages() {
|
|
37
|
+
let page = await this.firstPage();
|
|
38
|
+
for (;;) {
|
|
39
|
+
yield page;
|
|
40
|
+
const { offset, hasMore } = page.pagination;
|
|
41
|
+
if (!hasMore || page.data.length === 0)
|
|
42
|
+
return;
|
|
43
|
+
page = await this.fetchPage(offset + page.data.length);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async *[Symbol.asyncIterator]() {
|
|
47
|
+
for await (const page of this.pages())
|
|
48
|
+
yield* page.data;
|
|
49
|
+
}
|
|
50
|
+
/** Collects every item into an array. Mind large accounts: prefer `for await`. */
|
|
51
|
+
async toArray() {
|
|
52
|
+
const items = [];
|
|
53
|
+
for await (const item of this)
|
|
54
|
+
items.push(item);
|
|
55
|
+
return items;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.PagePromise = PagePromise;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { IdempotentRequestOptions, ListResponse, RequestOptions, RequestSpec } from "./core.js";
|
|
2
|
+
import { AmpostResources } from "./generated/resources.js";
|
|
3
|
+
import { MediaResource } from "./media.js";
|
|
4
|
+
import { PagePromise } from "./pagination.js";
|
|
5
|
+
export declare const DEFAULT_BASE_URL = "https://api.ampost.io";
|
|
6
|
+
export interface ClientOptions {
|
|
7
|
+
/** An API key from https://ampost.io/app/settings/api-keys. Default: `process.env.AMPOST_API_KEY`. */
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
/** Default: `process.env.AMPOST_BASE_URL`, else `https://api.ampost.io`. */
|
|
10
|
+
baseUrl?: string;
|
|
11
|
+
/** Retries after a 429, a 5xx or a network error (see README, "Retries"). Default 2. */
|
|
12
|
+
maxRetries?: number;
|
|
13
|
+
/** Per-attempt timeout in milliseconds. Default 60 000. */
|
|
14
|
+
timeoutMs?: number;
|
|
15
|
+
/** A `Retry-After` longer than this is not waited for: the error is thrown. Default 60 000. */
|
|
16
|
+
maxRetryDelayMs?: number;
|
|
17
|
+
/** Headers sent with every request. */
|
|
18
|
+
defaultHeaders?: Record<string, string>;
|
|
19
|
+
/** Custom fetch, for proxies or tests. Default: the global `fetch` (Node 18+). */
|
|
20
|
+
fetch?: typeof fetch;
|
|
21
|
+
}
|
|
22
|
+
/** A finished HTTP exchange with the body already read. */
|
|
23
|
+
export interface RawResponse {
|
|
24
|
+
status: number;
|
|
25
|
+
statusText: string;
|
|
26
|
+
ok: boolean;
|
|
27
|
+
headers: Headers;
|
|
28
|
+
text: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The Ampost API client.
|
|
32
|
+
*
|
|
33
|
+
* import { Ampost } from "ampost";
|
|
34
|
+
* const client = new Ampost(); // reads AMPOST_API_KEY
|
|
35
|
+
* const post = await client.posts.create({ text: "Hello", targets: [{ platforms: ["bluesky"] }], publishNow: true });
|
|
36
|
+
*/
|
|
37
|
+
export declare class Ampost extends AmpostResources {
|
|
38
|
+
#private;
|
|
39
|
+
/** Media uploads, with `upload()` on top of the generated methods. */
|
|
40
|
+
readonly media: MediaResource;
|
|
41
|
+
readonly baseUrl: string;
|
|
42
|
+
readonly maxRetries: number;
|
|
43
|
+
readonly timeoutMs: number;
|
|
44
|
+
readonly maxRetryDelayMs: number;
|
|
45
|
+
constructor(options?: ClientOptions);
|
|
46
|
+
/**
|
|
47
|
+
* Sends one API call with auth, the idempotency key and retries. The generated methods call this;
|
|
48
|
+
* use it directly only for an endpoint this SDK version does not know yet.
|
|
49
|
+
*/
|
|
50
|
+
request<T>(spec: RequestSpec, options?: IdempotentRequestOptions): Promise<T>;
|
|
51
|
+
/** Like `request`, for list operations: returns a page that also iterates every item. */
|
|
52
|
+
paginate<T extends ListResponse>(spec: RequestSpec, options?: RequestOptions): PagePromise<T>;
|
|
53
|
+
/** Milliseconds to wait before retrying, or undefined to give up. */
|
|
54
|
+
private retryDelay;
|
|
55
|
+
/** @internal One HTTP exchange with the timeout; reads the body. Throws APIConnectionError without a response. */
|
|
56
|
+
send(url: string, init: RequestInit, options?: RequestOptions): Promise<RawResponse>;
|
|
57
|
+
}
|
|
58
|
+
export declare function buildUrl(baseUrl: string, path: string, query?: object): string;
|
|
59
|
+
/** Exponential backoff with jitter: about 0.5 s, 1 s, 2 s, ... up to 8 s. */
|
|
60
|
+
export declare function backoff(attempt: number): number;
|
|
61
|
+
/** A UUID v4 for `Idempotency-Key`; Node 18 has no global `crypto` without a flag, hence the fallback. */
|
|
62
|
+
export declare function randomKey(): string;
|