@posty5/social-publisher-workspace 5.0.0 → 5.1.0
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/README.md +21 -0
- package/dist/index.d.mts +149 -1
- package/dist/index.d.ts +149 -1
- package/dist/index.js +88 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -129,6 +129,27 @@ try {
|
|
|
129
129
|
}
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
+
## 💬 Default comments (5.1.0)
|
|
133
|
+
|
|
134
|
+
A workspace keeps up to 10 default comments. Every new post to it starts with the active ones whose `postTypes`
|
|
135
|
+
match the post (empty means every type), aimed at the platforms flagged on each that the workspace has an account on.
|
|
136
|
+
Account defaults marked `applyToWorkspacePosts` are added after them. **Each added comment is charged like any other
|
|
137
|
+
comment**; a create request turns them off with `allowPostDefaultComments: false`.
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
const ws = await workspaces.get("workspace-id");
|
|
141
|
+
|
|
142
|
+
await workspaces.setDefaultComments("workspace-id", [
|
|
143
|
+
{ text: "Full video on our channel 👉 https://example.com", postTypes: ["shortVideo"], postToInstagram: false },
|
|
144
|
+
{ text: "Thanks for watching!", delayMinutes: 60 },
|
|
145
|
+
], ws.__v);
|
|
146
|
+
|
|
147
|
+
// What a new image post would get right now:
|
|
148
|
+
const { comments, warnings } = await workspaces.resolveDefaultComments("workspace-id", "image");
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
A post copies its defaults when it is created: editing a default later never changes an existing or scheduled post.
|
|
152
|
+
|
|
132
153
|
## 📚 API Reference & Examples
|
|
133
154
|
|
|
134
155
|
### create()
|
package/dist/index.d.mts
CHANGED
|
@@ -33,6 +33,98 @@ interface IListParams {
|
|
|
33
33
|
refId?: string;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/** A post type that takes comments. Stories take none. */
|
|
37
|
+
type CommentPostType = "shortVideo" | "longVideo" | "image" | "text";
|
|
38
|
+
/**
|
|
39
|
+
* One default comment on a workspace.
|
|
40
|
+
*
|
|
41
|
+
* Every new post to the workspace whose type is in `postTypes` (or any type,
|
|
42
|
+
* when it is empty) starts with it, aimed at the platforms flagged here that the
|
|
43
|
+
* workspace has an account on. Posts copy it when they are created, so editing
|
|
44
|
+
* a default never changes a post that already exists. Each comment that is
|
|
45
|
+
* posted is charged like any other comment.
|
|
46
|
+
*/
|
|
47
|
+
interface IWorkspaceDefaultComment {
|
|
48
|
+
/** Send it back to edit this default; omit it to add a new one. */
|
|
49
|
+
_id?: string;
|
|
50
|
+
/** 1–2200 characters. */
|
|
51
|
+
text: string;
|
|
52
|
+
/** Only Facebook and Threads render an image on a comment; elsewhere the text posts without it. */
|
|
53
|
+
imageUrl?: string;
|
|
54
|
+
/** `bucketFilePath` from {@link IDefaultCommentUploadSlot}. Only a key under this workspace is accepted. */
|
|
55
|
+
imageStorageKey?: string;
|
|
56
|
+
/** Minutes after the post publishes, 0–1440. Default 0. */
|
|
57
|
+
delayMinutes?: number;
|
|
58
|
+
/** An inactive default is kept but never added. Default true. */
|
|
59
|
+
isActive?: boolean;
|
|
60
|
+
/** The post types this default is added to. Empty means all of them. */
|
|
61
|
+
postTypes?: CommentPostType[];
|
|
62
|
+
/** Default true. */
|
|
63
|
+
postToFacebook?: boolean;
|
|
64
|
+
/** Default true. */
|
|
65
|
+
postToInstagram?: boolean;
|
|
66
|
+
/** Default true. */
|
|
67
|
+
postToYoutube?: boolean;
|
|
68
|
+
/** Default false: TikTok has no comment API, so it is never attempted or charged. */
|
|
69
|
+
postToTiktok?: boolean;
|
|
70
|
+
/** Default true. */
|
|
71
|
+
postToThreads?: boolean;
|
|
72
|
+
/** Default true. */
|
|
73
|
+
postToTwitter?: boolean;
|
|
74
|
+
/** Set by the server: the position in the list. */
|
|
75
|
+
order?: number;
|
|
76
|
+
createdAt?: string;
|
|
77
|
+
updatedAt?: string;
|
|
78
|
+
}
|
|
79
|
+
/** What `setDefaultComments` answers. */
|
|
80
|
+
interface ISetDefaultCommentsResult {
|
|
81
|
+
/** The saved list, in order. */
|
|
82
|
+
comments: IWorkspaceDefaultComment[];
|
|
83
|
+
/** The workspace's new version: pass it to the next versioned write. */
|
|
84
|
+
__v: number;
|
|
85
|
+
}
|
|
86
|
+
/** One signed slot for a default-comment image. */
|
|
87
|
+
interface IDefaultCommentUploadSlot {
|
|
88
|
+
/** Send it as the default's `imageStorageKey`. */
|
|
89
|
+
bucketFilePath: string;
|
|
90
|
+
/** The image's public URL once uploaded: send it as the default's `imageUrl`. */
|
|
91
|
+
fileURL: string;
|
|
92
|
+
/** Where to PUT the bytes. */
|
|
93
|
+
uploadFileURL: string;
|
|
94
|
+
}
|
|
95
|
+
/** An uploaded default-comment image, ready to put on a default. */
|
|
96
|
+
interface IUploadedDefaultCommentImage {
|
|
97
|
+
imageUrl: string;
|
|
98
|
+
imageStorageKey: string;
|
|
99
|
+
}
|
|
100
|
+
/** Why some defaults would not be added: a platform (or the post) was already at its comment ceiling. */
|
|
101
|
+
interface IDefaultCommentWarning {
|
|
102
|
+
code: "DEFAULT_COMMENTS_TRUNCATED" | string;
|
|
103
|
+
/** The platform whose ceiling was hit, or `all` for the post's total ceiling. */
|
|
104
|
+
platform: string;
|
|
105
|
+
dropped: number;
|
|
106
|
+
}
|
|
107
|
+
/** One comment a new post would get, in the shape a create request's `comments[]` takes. */
|
|
108
|
+
interface IResolvedDefaultComment {
|
|
109
|
+
text: string;
|
|
110
|
+
imageUrl?: string;
|
|
111
|
+
imageStorageKey?: string;
|
|
112
|
+
delayMinutes?: number;
|
|
113
|
+
defaultCommentId: string;
|
|
114
|
+
defaultCommentSource: "workspace" | "account";
|
|
115
|
+
postToFacebook?: boolean;
|
|
116
|
+
postToInstagram?: boolean;
|
|
117
|
+
postToYoutube?: boolean;
|
|
118
|
+
postToTiktok?: boolean;
|
|
119
|
+
postToThreads?: boolean;
|
|
120
|
+
postToTwitter?: boolean;
|
|
121
|
+
}
|
|
122
|
+
/** What `resolveDefaultComments` answers. */
|
|
123
|
+
interface IResolvedDefaultCommentsResponse {
|
|
124
|
+
comments: IResolvedDefaultComment[];
|
|
125
|
+
warnings: IDefaultCommentWarning[];
|
|
126
|
+
}
|
|
127
|
+
|
|
36
128
|
type SocialPublisherAccountStatusType = "active" | "inactive" | "authenticationExpired";
|
|
37
129
|
interface IAccountSampleDetails {
|
|
38
130
|
link: string;
|
|
@@ -55,6 +147,8 @@ interface IWorkspaceResponse {
|
|
|
55
147
|
description: string;
|
|
56
148
|
imageUrl?: string;
|
|
57
149
|
account: IWorkspaceAccount;
|
|
150
|
+
/** The comments every new post to this workspace starts with. */
|
|
151
|
+
defaultComments?: IWorkspaceDefaultComment[];
|
|
58
152
|
}
|
|
59
153
|
interface IWorkspaceSampleDetails {
|
|
60
154
|
_id: string;
|
|
@@ -226,6 +320,60 @@ declare class SocialPublisherWorkspaceClient {
|
|
|
226
320
|
* @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.
|
|
227
321
|
*/
|
|
228
322
|
delete(id: string, version: number): Promise<void>;
|
|
323
|
+
/**
|
|
324
|
+
* The workspace's default comments, in order.
|
|
325
|
+
* @param id - Workspace ID
|
|
326
|
+
*/
|
|
327
|
+
getDefaultComments(id: string): Promise<IWorkspaceDefaultComment[]>;
|
|
328
|
+
/**
|
|
329
|
+
* Replace the workspace's default comments (at most 10).
|
|
330
|
+
*
|
|
331
|
+
* Send the whole list the workspace should have; an empty list clears it.
|
|
332
|
+
* Every new post to the workspace then starts with the active defaults for
|
|
333
|
+
* its post type, unless the create request sends
|
|
334
|
+
* `allowPostDefaultComments: false`. **Each added comment is charged like any
|
|
335
|
+
* other comment.**
|
|
336
|
+
*
|
|
337
|
+
* @param id - Workspace ID
|
|
338
|
+
* @param comments - The full list
|
|
339
|
+
* @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```typescript
|
|
343
|
+
* const ws = await client.get('workspace-id');
|
|
344
|
+
* await client.setDefaultComments('workspace-id', [
|
|
345
|
+
* { text: 'Full video on our channel 👉', postTypes: ['shortVideo'] },
|
|
346
|
+
* { text: 'Thanks for watching!', delayMinutes: 60 },
|
|
347
|
+
* ], ws.__v);
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
setDefaultComments(id: string, comments: IWorkspaceDefaultComment[], version: number): Promise<ISetDefaultCommentsResult>;
|
|
351
|
+
/**
|
|
352
|
+
* Signed upload slots for default-comment images, one per file type.
|
|
353
|
+
* Uploading is a paid-plan feature; on a lower plan give the default an `imageUrl` instead.
|
|
354
|
+
* @param id - Workspace ID
|
|
355
|
+
* @param fileTypes - MIME types: image/jpeg, image/png, image/gif or image/webp
|
|
356
|
+
*/
|
|
357
|
+
generateDefaultCommentUploadUrls(id: string, fileTypes: string[]): Promise<IDefaultCommentUploadSlot[]>;
|
|
358
|
+
/**
|
|
359
|
+
* Upload one image for a default comment: a slot, then the bytes.
|
|
360
|
+
* Put the result on a default and save it with {@link setDefaultComments}.
|
|
361
|
+
* @param id - Workspace ID
|
|
362
|
+
* @param image - The image (File or Blob)
|
|
363
|
+
*/
|
|
364
|
+
uploadDefaultCommentImage(id: string, image: File | Blob): Promise<IUploadedDefaultCommentImage>;
|
|
365
|
+
/**
|
|
366
|
+
* The default comments a new post of `postType` to this workspace would get
|
|
367
|
+
* right now: the workspace's own for that type, then the account defaults
|
|
368
|
+
* marked `applyToWorkspacePosts`. The same rule the create endpoints run.
|
|
369
|
+
*
|
|
370
|
+
* To show them to a user and let them edit the list, send the edited list as
|
|
371
|
+
* the post's `comments` with `allowPostDefaultComments: false`.
|
|
372
|
+
*
|
|
373
|
+
* @param id - Workspace ID
|
|
374
|
+
* @param postType - shortVideo, longVideo, image or text
|
|
375
|
+
*/
|
|
376
|
+
resolveDefaultComments(id: string, postType: CommentPostType): Promise<IResolvedDefaultCommentsResponse>;
|
|
229
377
|
}
|
|
230
378
|
|
|
231
379
|
/**
|
|
@@ -251,4 +399,4 @@ declare class SocialPublisherAccountClient {
|
|
|
251
399
|
get(id: string): Promise<ISocialAccountDetails>;
|
|
252
400
|
}
|
|
253
401
|
|
|
254
|
-
export { type IAccountSampleDetails, type ICreateWorkspaceRequest, type ICreateWorkspaceResponse, type IDeleteWorkspaceResponse, type IListParams, type ISearchWorkspaceResponse, type ISocialAccountDetails, type ISocialAccountListParams, type ISocialAccountLookupItem, type ISocialAccountSummary, type IUpdateWorkspaceRequest, type IUpdateWorkspaceResponse, type IUpdateWorkspaceResult, type IUploadImageConfig, type IWorkspaceAccount, type IWorkspaceForNewPostResponse, type IWorkspaceRequest, type IWorkspaceResponse, type IWorkspaceSampleDetails, type IWorkspaceWithUploadConfig, type SocialAccountPlatform, type SocialAccountStatus, SocialPublisherAccountClient, type SocialPublisherAccountStatusType, SocialPublisherWorkspaceClient };
|
|
402
|
+
export { type CommentPostType, type IAccountSampleDetails, type ICreateWorkspaceRequest, type ICreateWorkspaceResponse, type IDefaultCommentUploadSlot, type IDefaultCommentWarning, type IDeleteWorkspaceResponse, type IListParams, type IResolvedDefaultComment, type IResolvedDefaultCommentsResponse, type ISearchWorkspaceResponse, type ISetDefaultCommentsResult, type ISocialAccountDetails, type ISocialAccountListParams, type ISocialAccountLookupItem, type ISocialAccountSummary, type IUpdateWorkspaceRequest, type IUpdateWorkspaceResponse, type IUpdateWorkspaceResult, type IUploadImageConfig, type IUploadedDefaultCommentImage, type IWorkspaceAccount, type IWorkspaceDefaultComment, type IWorkspaceForNewPostResponse, type IWorkspaceRequest, type IWorkspaceResponse, type IWorkspaceSampleDetails, type IWorkspaceWithUploadConfig, type SocialAccountPlatform, type SocialAccountStatus, SocialPublisherAccountClient, type SocialPublisherAccountStatusType, SocialPublisherWorkspaceClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,98 @@ interface IListParams {
|
|
|
33
33
|
refId?: string;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/** A post type that takes comments. Stories take none. */
|
|
37
|
+
type CommentPostType = "shortVideo" | "longVideo" | "image" | "text";
|
|
38
|
+
/**
|
|
39
|
+
* One default comment on a workspace.
|
|
40
|
+
*
|
|
41
|
+
* Every new post to the workspace whose type is in `postTypes` (or any type,
|
|
42
|
+
* when it is empty) starts with it, aimed at the platforms flagged here that the
|
|
43
|
+
* workspace has an account on. Posts copy it when they are created, so editing
|
|
44
|
+
* a default never changes a post that already exists. Each comment that is
|
|
45
|
+
* posted is charged like any other comment.
|
|
46
|
+
*/
|
|
47
|
+
interface IWorkspaceDefaultComment {
|
|
48
|
+
/** Send it back to edit this default; omit it to add a new one. */
|
|
49
|
+
_id?: string;
|
|
50
|
+
/** 1–2200 characters. */
|
|
51
|
+
text: string;
|
|
52
|
+
/** Only Facebook and Threads render an image on a comment; elsewhere the text posts without it. */
|
|
53
|
+
imageUrl?: string;
|
|
54
|
+
/** `bucketFilePath` from {@link IDefaultCommentUploadSlot}. Only a key under this workspace is accepted. */
|
|
55
|
+
imageStorageKey?: string;
|
|
56
|
+
/** Minutes after the post publishes, 0–1440. Default 0. */
|
|
57
|
+
delayMinutes?: number;
|
|
58
|
+
/** An inactive default is kept but never added. Default true. */
|
|
59
|
+
isActive?: boolean;
|
|
60
|
+
/** The post types this default is added to. Empty means all of them. */
|
|
61
|
+
postTypes?: CommentPostType[];
|
|
62
|
+
/** Default true. */
|
|
63
|
+
postToFacebook?: boolean;
|
|
64
|
+
/** Default true. */
|
|
65
|
+
postToInstagram?: boolean;
|
|
66
|
+
/** Default true. */
|
|
67
|
+
postToYoutube?: boolean;
|
|
68
|
+
/** Default false: TikTok has no comment API, so it is never attempted or charged. */
|
|
69
|
+
postToTiktok?: boolean;
|
|
70
|
+
/** Default true. */
|
|
71
|
+
postToThreads?: boolean;
|
|
72
|
+
/** Default true. */
|
|
73
|
+
postToTwitter?: boolean;
|
|
74
|
+
/** Set by the server: the position in the list. */
|
|
75
|
+
order?: number;
|
|
76
|
+
createdAt?: string;
|
|
77
|
+
updatedAt?: string;
|
|
78
|
+
}
|
|
79
|
+
/** What `setDefaultComments` answers. */
|
|
80
|
+
interface ISetDefaultCommentsResult {
|
|
81
|
+
/** The saved list, in order. */
|
|
82
|
+
comments: IWorkspaceDefaultComment[];
|
|
83
|
+
/** The workspace's new version: pass it to the next versioned write. */
|
|
84
|
+
__v: number;
|
|
85
|
+
}
|
|
86
|
+
/** One signed slot for a default-comment image. */
|
|
87
|
+
interface IDefaultCommentUploadSlot {
|
|
88
|
+
/** Send it as the default's `imageStorageKey`. */
|
|
89
|
+
bucketFilePath: string;
|
|
90
|
+
/** The image's public URL once uploaded: send it as the default's `imageUrl`. */
|
|
91
|
+
fileURL: string;
|
|
92
|
+
/** Where to PUT the bytes. */
|
|
93
|
+
uploadFileURL: string;
|
|
94
|
+
}
|
|
95
|
+
/** An uploaded default-comment image, ready to put on a default. */
|
|
96
|
+
interface IUploadedDefaultCommentImage {
|
|
97
|
+
imageUrl: string;
|
|
98
|
+
imageStorageKey: string;
|
|
99
|
+
}
|
|
100
|
+
/** Why some defaults would not be added: a platform (or the post) was already at its comment ceiling. */
|
|
101
|
+
interface IDefaultCommentWarning {
|
|
102
|
+
code: "DEFAULT_COMMENTS_TRUNCATED" | string;
|
|
103
|
+
/** The platform whose ceiling was hit, or `all` for the post's total ceiling. */
|
|
104
|
+
platform: string;
|
|
105
|
+
dropped: number;
|
|
106
|
+
}
|
|
107
|
+
/** One comment a new post would get, in the shape a create request's `comments[]` takes. */
|
|
108
|
+
interface IResolvedDefaultComment {
|
|
109
|
+
text: string;
|
|
110
|
+
imageUrl?: string;
|
|
111
|
+
imageStorageKey?: string;
|
|
112
|
+
delayMinutes?: number;
|
|
113
|
+
defaultCommentId: string;
|
|
114
|
+
defaultCommentSource: "workspace" | "account";
|
|
115
|
+
postToFacebook?: boolean;
|
|
116
|
+
postToInstagram?: boolean;
|
|
117
|
+
postToYoutube?: boolean;
|
|
118
|
+
postToTiktok?: boolean;
|
|
119
|
+
postToThreads?: boolean;
|
|
120
|
+
postToTwitter?: boolean;
|
|
121
|
+
}
|
|
122
|
+
/** What `resolveDefaultComments` answers. */
|
|
123
|
+
interface IResolvedDefaultCommentsResponse {
|
|
124
|
+
comments: IResolvedDefaultComment[];
|
|
125
|
+
warnings: IDefaultCommentWarning[];
|
|
126
|
+
}
|
|
127
|
+
|
|
36
128
|
type SocialPublisherAccountStatusType = "active" | "inactive" | "authenticationExpired";
|
|
37
129
|
interface IAccountSampleDetails {
|
|
38
130
|
link: string;
|
|
@@ -55,6 +147,8 @@ interface IWorkspaceResponse {
|
|
|
55
147
|
description: string;
|
|
56
148
|
imageUrl?: string;
|
|
57
149
|
account: IWorkspaceAccount;
|
|
150
|
+
/** The comments every new post to this workspace starts with. */
|
|
151
|
+
defaultComments?: IWorkspaceDefaultComment[];
|
|
58
152
|
}
|
|
59
153
|
interface IWorkspaceSampleDetails {
|
|
60
154
|
_id: string;
|
|
@@ -226,6 +320,60 @@ declare class SocialPublisherWorkspaceClient {
|
|
|
226
320
|
* @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.
|
|
227
321
|
*/
|
|
228
322
|
delete(id: string, version: number): Promise<void>;
|
|
323
|
+
/**
|
|
324
|
+
* The workspace's default comments, in order.
|
|
325
|
+
* @param id - Workspace ID
|
|
326
|
+
*/
|
|
327
|
+
getDefaultComments(id: string): Promise<IWorkspaceDefaultComment[]>;
|
|
328
|
+
/**
|
|
329
|
+
* Replace the workspace's default comments (at most 10).
|
|
330
|
+
*
|
|
331
|
+
* Send the whole list the workspace should have; an empty list clears it.
|
|
332
|
+
* Every new post to the workspace then starts with the active defaults for
|
|
333
|
+
* its post type, unless the create request sends
|
|
334
|
+
* `allowPostDefaultComments: false`. **Each added comment is charged like any
|
|
335
|
+
* other comment.**
|
|
336
|
+
*
|
|
337
|
+
* @param id - Workspace ID
|
|
338
|
+
* @param comments - The full list
|
|
339
|
+
* @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```typescript
|
|
343
|
+
* const ws = await client.get('workspace-id');
|
|
344
|
+
* await client.setDefaultComments('workspace-id', [
|
|
345
|
+
* { text: 'Full video on our channel 👉', postTypes: ['shortVideo'] },
|
|
346
|
+
* { text: 'Thanks for watching!', delayMinutes: 60 },
|
|
347
|
+
* ], ws.__v);
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
setDefaultComments(id: string, comments: IWorkspaceDefaultComment[], version: number): Promise<ISetDefaultCommentsResult>;
|
|
351
|
+
/**
|
|
352
|
+
* Signed upload slots for default-comment images, one per file type.
|
|
353
|
+
* Uploading is a paid-plan feature; on a lower plan give the default an `imageUrl` instead.
|
|
354
|
+
* @param id - Workspace ID
|
|
355
|
+
* @param fileTypes - MIME types: image/jpeg, image/png, image/gif or image/webp
|
|
356
|
+
*/
|
|
357
|
+
generateDefaultCommentUploadUrls(id: string, fileTypes: string[]): Promise<IDefaultCommentUploadSlot[]>;
|
|
358
|
+
/**
|
|
359
|
+
* Upload one image for a default comment: a slot, then the bytes.
|
|
360
|
+
* Put the result on a default and save it with {@link setDefaultComments}.
|
|
361
|
+
* @param id - Workspace ID
|
|
362
|
+
* @param image - The image (File or Blob)
|
|
363
|
+
*/
|
|
364
|
+
uploadDefaultCommentImage(id: string, image: File | Blob): Promise<IUploadedDefaultCommentImage>;
|
|
365
|
+
/**
|
|
366
|
+
* The default comments a new post of `postType` to this workspace would get
|
|
367
|
+
* right now: the workspace's own for that type, then the account defaults
|
|
368
|
+
* marked `applyToWorkspacePosts`. The same rule the create endpoints run.
|
|
369
|
+
*
|
|
370
|
+
* To show them to a user and let them edit the list, send the edited list as
|
|
371
|
+
* the post's `comments` with `allowPostDefaultComments: false`.
|
|
372
|
+
*
|
|
373
|
+
* @param id - Workspace ID
|
|
374
|
+
* @param postType - shortVideo, longVideo, image or text
|
|
375
|
+
*/
|
|
376
|
+
resolveDefaultComments(id: string, postType: CommentPostType): Promise<IResolvedDefaultCommentsResponse>;
|
|
229
377
|
}
|
|
230
378
|
|
|
231
379
|
/**
|
|
@@ -251,4 +399,4 @@ declare class SocialPublisherAccountClient {
|
|
|
251
399
|
get(id: string): Promise<ISocialAccountDetails>;
|
|
252
400
|
}
|
|
253
401
|
|
|
254
|
-
export { type IAccountSampleDetails, type ICreateWorkspaceRequest, type ICreateWorkspaceResponse, type IDeleteWorkspaceResponse, type IListParams, type ISearchWorkspaceResponse, type ISocialAccountDetails, type ISocialAccountListParams, type ISocialAccountLookupItem, type ISocialAccountSummary, type IUpdateWorkspaceRequest, type IUpdateWorkspaceResponse, type IUpdateWorkspaceResult, type IUploadImageConfig, type IWorkspaceAccount, type IWorkspaceForNewPostResponse, type IWorkspaceRequest, type IWorkspaceResponse, type IWorkspaceSampleDetails, type IWorkspaceWithUploadConfig, type SocialAccountPlatform, type SocialAccountStatus, SocialPublisherAccountClient, type SocialPublisherAccountStatusType, SocialPublisherWorkspaceClient };
|
|
402
|
+
export { type CommentPostType, type IAccountSampleDetails, type ICreateWorkspaceRequest, type ICreateWorkspaceResponse, type IDefaultCommentUploadSlot, type IDefaultCommentWarning, type IDeleteWorkspaceResponse, type IListParams, type IResolvedDefaultComment, type IResolvedDefaultCommentsResponse, type ISearchWorkspaceResponse, type ISetDefaultCommentsResult, type ISocialAccountDetails, type ISocialAccountListParams, type ISocialAccountLookupItem, type ISocialAccountSummary, type IUpdateWorkspaceRequest, type IUpdateWorkspaceResponse, type IUpdateWorkspaceResult, type IUploadImageConfig, type IUploadedDefaultCommentImage, type IWorkspaceAccount, type IWorkspaceDefaultComment, type IWorkspaceForNewPostResponse, type IWorkspaceRequest, type IWorkspaceResponse, type IWorkspaceSampleDetails, type IWorkspaceWithUploadConfig, type SocialAccountPlatform, type SocialAccountStatus, SocialPublisherAccountClient, type SocialPublisherAccountStatusType, SocialPublisherWorkspaceClient };
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var SocialPublisherWorkspaceClient = class {
|
|
|
31
31
|
* @param id - Workspace ID
|
|
32
32
|
*/
|
|
33
33
|
async get(id) {
|
|
34
|
-
const response = await this.http.get(`${this.basePath}/${id}`);
|
|
34
|
+
const response = await this.http.get(`${this.basePath}/${encodeURIComponent(id)}`);
|
|
35
35
|
return response.result;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
@@ -47,7 +47,7 @@ var SocialPublisherWorkspaceClient = class {
|
|
|
47
47
|
* ```
|
|
48
48
|
*/
|
|
49
49
|
async getForNewPost(id) {
|
|
50
|
-
const response = await this.http.get(`${this.basePath}/${id}/for-new-post`);
|
|
50
|
+
const response = await this.http.get(`${this.basePath}/${encodeURIComponent(id)}/for-new-post`);
|
|
51
51
|
return response.result;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
@@ -106,7 +106,7 @@ var SocialPublisherWorkspaceClient = class {
|
|
|
106
106
|
async update(id, data, version, logo) {
|
|
107
107
|
core.assertVersion(version);
|
|
108
108
|
const response = await this.http.put(
|
|
109
|
-
`${this.basePath}/${id}`,
|
|
109
|
+
`${this.basePath}/${encodeURIComponent(id)}`,
|
|
110
110
|
{
|
|
111
111
|
...data,
|
|
112
112
|
hasImage: !!logo
|
|
@@ -127,7 +127,90 @@ var SocialPublisherWorkspaceClient = class {
|
|
|
127
127
|
*/
|
|
128
128
|
async delete(id, version) {
|
|
129
129
|
core.assertVersion(version);
|
|
130
|
-
await this.http.delete(`${this.basePath}/${id}`, { version });
|
|
130
|
+
await this.http.delete(`${this.basePath}/${encodeURIComponent(id)}`, { version });
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The workspace's default comments, in order.
|
|
134
|
+
* @param id - Workspace ID
|
|
135
|
+
*/
|
|
136
|
+
async getDefaultComments(id) {
|
|
137
|
+
const workspace = await this.get(id);
|
|
138
|
+
return workspace.defaultComments ?? [];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Replace the workspace's default comments (at most 10).
|
|
142
|
+
*
|
|
143
|
+
* Send the whole list the workspace should have; an empty list clears it.
|
|
144
|
+
* Every new post to the workspace then starts with the active defaults for
|
|
145
|
+
* its post type, unless the create request sends
|
|
146
|
+
* `allowPostDefaultComments: false`. **Each added comment is charged like any
|
|
147
|
+
* other comment.**
|
|
148
|
+
*
|
|
149
|
+
* @param id - Workspace ID
|
|
150
|
+
* @param comments - The full list
|
|
151
|
+
* @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* const ws = await client.get('workspace-id');
|
|
156
|
+
* await client.setDefaultComments('workspace-id', [
|
|
157
|
+
* { text: 'Full video on our channel 👉', postTypes: ['shortVideo'] },
|
|
158
|
+
* { text: 'Thanks for watching!', delayMinutes: 60 },
|
|
159
|
+
* ], ws.__v);
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
async setDefaultComments(id, comments, version) {
|
|
163
|
+
core.assertVersion(version);
|
|
164
|
+
const response = await this.http.put(
|
|
165
|
+
`${this.basePath}/${encodeURIComponent(id)}/default-comments`,
|
|
166
|
+
{ comments },
|
|
167
|
+
{ version }
|
|
168
|
+
);
|
|
169
|
+
return { comments: response.result ?? [], __v: response.version };
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Signed upload slots for default-comment images, one per file type.
|
|
173
|
+
* Uploading is a paid-plan feature; on a lower plan give the default an `imageUrl` instead.
|
|
174
|
+
* @param id - Workspace ID
|
|
175
|
+
* @param fileTypes - MIME types: image/jpeg, image/png, image/gif or image/webp
|
|
176
|
+
*/
|
|
177
|
+
async generateDefaultCommentUploadUrls(id, fileTypes) {
|
|
178
|
+
const response = await this.http.post(
|
|
179
|
+
`${this.basePath}/${encodeURIComponent(id)}/default-comments/upload-urls`,
|
|
180
|
+
{ fileTypes }
|
|
181
|
+
);
|
|
182
|
+
return response.result ?? [];
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Upload one image for a default comment: a slot, then the bytes.
|
|
186
|
+
* Put the result on a default and save it with {@link setDefaultComments}.
|
|
187
|
+
* @param id - Workspace ID
|
|
188
|
+
* @param image - The image (File or Blob)
|
|
189
|
+
*/
|
|
190
|
+
async uploadDefaultCommentImage(id, image) {
|
|
191
|
+
const contentType = image.type || "image/png";
|
|
192
|
+
const [slot] = await this.generateDefaultCommentUploadUrls(id, [contentType]);
|
|
193
|
+
if (!slot?.uploadFileURL) throw new Error("The API did not return an upload slot.");
|
|
194
|
+
await core.uploadToR2(slot.uploadFileURL, image, { contentType });
|
|
195
|
+
return { imageUrl: slot.fileURL, imageStorageKey: slot.bucketFilePath };
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The default comments a new post of `postType` to this workspace would get
|
|
199
|
+
* right now: the workspace's own for that type, then the account defaults
|
|
200
|
+
* marked `applyToWorkspacePosts`. The same rule the create endpoints run.
|
|
201
|
+
*
|
|
202
|
+
* To show them to a user and let them edit the list, send the edited list as
|
|
203
|
+
* the post's `comments` with `allowPostDefaultComments: false`.
|
|
204
|
+
*
|
|
205
|
+
* @param id - Workspace ID
|
|
206
|
+
* @param postType - shortVideo, longVideo, image or text
|
|
207
|
+
*/
|
|
208
|
+
async resolveDefaultComments(id, postType) {
|
|
209
|
+
const response = await this.http.get(
|
|
210
|
+
`${this.basePath}/${encodeURIComponent(id)}/default-comments/resolved`,
|
|
211
|
+
{ params: { postType } }
|
|
212
|
+
);
|
|
213
|
+
return response.result ?? { comments: [], warnings: [] };
|
|
131
214
|
}
|
|
132
215
|
};
|
|
133
216
|
|
|
@@ -155,7 +238,7 @@ var SocialPublisherAccountClient = class {
|
|
|
155
238
|
}
|
|
156
239
|
/** One account's details. */
|
|
157
240
|
async get(id) {
|
|
158
|
-
const response = await this.http.get(`${this.basePath}/${id}`);
|
|
241
|
+
const response = await this.http.get(`${this.basePath}/${encodeURIComponent(id)}`);
|
|
159
242
|
return response.result;
|
|
160
243
|
}
|
|
161
244
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/social-publisher-workspace.client.ts","../src/social-publisher-account.client.ts"],"names":["uploadToR2","assertVersion"],"mappings":";;;;;AAiBO,IAAM,iCAAN,MAAqC;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ1C,YAAY,IAAA,EAAkB;AAN9B,IAAA,IAAA,CAAQ,QAAA,GAAW,iCAAA;AAOjB,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,IAAA,CAAK,MAAA,EAAsB,UAAA,EAAmE;AAClG,IAAA,MAAM,WAAW,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAA8B,KAAK,QAAA,EAAU;AAAA,MAC5E,MAAA,EAAQ;AAAA,QACN,GAAG,MAAA;AAAA,QACH,GAAG;AAAA;AACL,KACD,CAAA;AACD,IAAA,OAAO,QAAA,CAAS,MAAA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,IAAI,EAAA,EAAyC;AACjD,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAAwB,GAAG,IAAA,CAAK,QAAQ,CAAA,CAAA,EAAI,EAAE,CAAA,CAAE,CAAA;AACjF,IAAA,OAAO,QAAA,CAAS,MAAA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,MAAM,cAAc,EAAA,EAAmD;AACrE,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAAkC,GAAG,IAAA,CAAK,QAAQ,CAAA,CAAA,EAAI,EAAE,CAAA,aAAA,CAAe,CAAA;AACxG,IAAA,OAAO,QAAA,CAAS,MAAA;AAAA,EAClB;AAAA;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,QAAA;AAChC,IAAA,IAAI,QAAA,SAAiB,QAAA,GAAW,QAAA;AAChC,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAAgC,CAAA,EAAG,IAAA,CAAK,QAAQ,CAAA,OAAA,CAAA,EAAW,EAAE,MAAA,EAAQ,CAAA;AACtG,IAAA,OAAO,QAAA,CAAS,UAAU,EAAC;AAAA,EAC7B;AAAA;AAAA,EAGA,MAAM,IAAI,EAAA,EAA4C;AACpD,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAA2B,GAAG,IAAA,CAAK,QAAQ,CAAA,CAAA,EAAI,EAAE,CAAA,CAAE,CAAA;AACpF,IAAA,OAAO,QAAA,CAAS,MAAA;AAAA,EAClB;AACF","file":"index.js","sourcesContent":["import { HttpClient, IPaginationParams, assertVersion, uploadToR2 } from \"@posty5/core\";\nimport {\n ICreateWorkspaceRequest,\n IUpdateWorkspaceRequest,\n IListParams,\n ISearchWorkspaceResponse,\n ICreateWorkspaceResponse,\n IUpdateWorkspaceResponse,\n IDeleteWorkspaceResponse,\n IWorkspaceResponse,\n IWorkspaceForNewPostResponse,\n IUpdateWorkspaceResult,\n} from \"./interfaces\";\n\n/**\n * Social Publisher Workspace Client\n */\nexport class SocialPublisherWorkspaceClient {\n private http: HttpClient;\n private basePath = \"/api/social-publisher-workspace\";\n\n /**\n * Create client\n * @param http - HttpClient instance\n */\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Search workspaces\n * @param params - Search filters\n * @param pagination - Pagination options\n */\n async list(params?: IListParams, pagination?: IPaginationParams): Promise<ISearchWorkspaceResponse> {\n const response = await this.http.get<ISearchWorkspaceResponse>(this.basePath, {\n params: {\n ...params,\n ...pagination,\n },\n });\n return response.result!;\n }\n\n /**\n * Get workspace by ID\n * @param id - Workspace ID\n */\n async get(id: string): Promise<IWorkspaceResponse> {\n const response = await this.http.get<IWorkspaceResponse>(`${this.basePath}/${id}`);\n return response.result!;\n }\n\n /**\n * Get workspace details for creating new post\n * @param id - Workspace ID\n * @returns Workspace details with populated account information\n *\n * @example\n * ```typescript\n * const workspace = await client.getForNewPost('workspace-id');\n * console.log(workspace.account.youtube); // YouTube account details\n * console.log(workspace.account.facebook?.status); // Facebook account status\n * ```\n */\n async getForNewPost(id: string): Promise<IWorkspaceForNewPostResponse> {\n const response = await this.http.get<IWorkspaceForNewPostResponse>(`${this.basePath}/${id}/for-new-post`);\n return response.result!;\n }\n\n /**\n * Create workspace with optional image upload\n * @param data - Workspace data\n * @param logo - Optional image file (File or Blob)\n * @returns Workspace details\n *\n * @example\n * ```typescript\n * // Create without image\n * const workspace = await client.create({ name: 'My Workspace', description: 'Description' });\n *\n * // Create with image\n * const file = new File([imageBlob], 'logo.png', { type: 'image/png' });\n * const workspace = await client.create(\n * { name: 'My Workspace', description: 'Description' },\n * file\n * );\n */\n async create(data: ICreateWorkspaceRequest, logo?: File | Blob): Promise<string> {\n // Step 1: Create workspace and get upload config\n const response = await this.http.post<ICreateWorkspaceResponse>(this.basePath, {\n ...data,\n hasImage: !!logo,\n createdFrom: this.http.createdFrom,\n });\n\n // Step 2: Upload image if provided\n if (logo && response.result?.uploadImageConfig) {\n await uploadToR2(response.result.uploadImageConfig.uploadUrl, logo, {\n contentType: /*logo instanceof File ? logo.type : 'image/png'*/ \"image/png\",\n });\n }\n\n return response.result?.workspaceId!;\n }\n\n /**\n * Update workspace with optional image upload\n * @param id - Workspace ID\n * @param data - Workspace data\n * @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.\n * @param logo - Optional new image file (File or Blob)\n * @returns `{ _id, __v }`, `__v` being the new version\n *\n * @example\n * ```typescript\n * // Update without changing image\n * const ws = await client.get('workspace-id');\n * await client.update('workspace-id', { name: 'New Name', description: 'New Description' }, ws.__v);\n *\n * // Update with new image\n * const file = new File([imageBlob], 'new-logo.png', { type: 'image/png' });\n * await client.update(\n * 'workspace-id',\n */\n async update(id: string, data: IUpdateWorkspaceRequest, version: number, logo?: File | Blob): Promise<IUpdateWorkspaceResult> {\n assertVersion(version);\n // Step 1: Update workspace and get upload config\n const response = await this.http.put<IUpdateWorkspaceResponse>(\n `${this.basePath}/${id}`,\n {\n ...data,\n hasImage: !!logo,\n },\n { version },\n );\n\n // Step 2: Upload image if provided\n if (logo && response.result?.uploadImageConfig) {\n await uploadToR2(response.result.uploadImageConfig.uploadUrl, logo, {\n contentType: logo instanceof File ? logo.type : \"image/png\",\n });\n }\n\n return { _id: response.result?.workspaceId ?? id, __v: response.version as number };\n }\n\n /**\n * Delete workspace\n * @param id - Workspace ID\n * @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.\n */\n async delete(id: string, version: number): Promise<void> {\n assertVersion(version);\n await this.http.delete<IDeleteWorkspaceResponse>(`${this.basePath}/${id}`, { version });\n }\n}\n","import { HttpClient, IPaginationParams, IPaginationResponse } from \"@posty5/core\";\nimport { ISocialAccountDetails, ISocialAccountListParams, ISocialAccountLookupItem, ISocialAccountSummary, SocialAccountPlatform } from \"./interfaces\";\n\n/**\n * Connected social accounts, read-only — `/api/social-publisher-account`.\n *\n * Where an `accountId` for the account-targeted post methods\n * (`createImagePostToAccount`, `publishShortVideoToAccount`, …) comes from.\n * Connecting an account is an OAuth flow done in the Posty5 dashboard, not\n * through the API. No response carries a platform token.\n *\n * With an API key whose record scope is `key`, only accounts connected with\n * that key are listed; with `account`, every account of its owner.\n */\nexport class SocialPublisherAccountClient {\n private http: HttpClient;\n private readonly basePath = \"/api/social-publisher-account\";\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /** List connected accounts, filtered by platform, status or name. */\n async list(params?: ISocialAccountListParams, pagination?: IPaginationParams): Promise<IPaginationResponse<ISocialAccountSummary>> {\n const response = await this.http.get<IPaginationResponse<ISocialAccountSummary>>(this.basePath, {\n params: { ...params, ...pagination },\n });\n return response.result!;\n }\n\n /** Look accounts up by name, optionally on one platform. One page, no cursor (`pageSize` defaults to 10). */\n async lookup(term?: string, platform?: SocialAccountPlatform, pageSize?: number): Promise<ISocialAccountLookupItem[]> {\n const params: Record<string, string | number> = {};\n if (term) params.term = term;\n if (platform) params.platform = platform;\n if (pageSize) params.pageSize = pageSize;\n const response = await this.http.get<ISocialAccountLookupItem[]>(`${this.basePath}/lookup`, { params });\n return response.result || [];\n }\n\n /** One account's details. */\n async get(id: string): Promise<ISocialAccountDetails> {\n const response = await this.http.get<ISocialAccountDetails>(`${this.basePath}/${id}`);\n return response.result!;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/social-publisher-workspace.client.ts","../src/social-publisher-account.client.ts"],"names":["uploadToR2","assertVersion"],"mappings":";;;;;AAuBO,IAAM,iCAAN,MAAqC;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ1C,YAAY,IAAA,EAAkB;AAN9B,IAAA,IAAA,CAAQ,QAAA,GAAW,iCAAA;AAOjB,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,IAAA,CAAK,MAAA,EAAsB,UAAA,EAAmE;AAClG,IAAA,MAAM,WAAW,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAA8B,KAAK,QAAA,EAAU;AAAA,MAC5E,MAAA,EAAQ;AAAA,QACN,GAAG,MAAA;AAAA,QACH,GAAG;AAAA;AACL,KACD,CAAA;AACD,IAAA,OAAO,QAAA,CAAS,MAAA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,IAAI,EAAA,EAAyC;AACjD,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAAwB,CAAA,EAAG,IAAA,CAAK,QAAQ,CAAA,CAAA,EAAI,kBAAA,CAAmB,EAAE,CAAC,CAAA,CAAE,CAAA;AACrG,IAAA,OAAO,QAAA,CAAS,MAAA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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A,IAAI,QAAA,SAAiB,QAAA,GAAW,QAAA;AAChC,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAAgC,CAAA,EAAG,IAAA,CAAK,QAAQ,CAAA,OAAA,CAAA,EAAW,EAAE,MAAA,EAAQ,CAAA;AACtG,IAAA,OAAO,QAAA,CAAS,UAAU,EAAC;AAAA,EAC7B;AAAA;AAAA,EAGA,MAAM,IAAI,EAAA,EAA4C;AACpD,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAA2B,CAAA,EAAG,IAAA,CAAK,QAAQ,CAAA,CAAA,EAAI,kBAAA,CAAmB,EAAE,CAAC,CAAA,CAAE,CAAA;AACxG,IAAA,OAAO,QAAA,CAAS,MAAA;AAAA,EAClB;AACF","file":"index.js","sourcesContent":["import { HttpClient, IPaginationParams, assertVersion, uploadToR2 } from \"@posty5/core\";\nimport {\n ICreateWorkspaceRequest,\n IUpdateWorkspaceRequest,\n IListParams,\n ISearchWorkspaceResponse,\n ICreateWorkspaceResponse,\n IUpdateWorkspaceResponse,\n IDeleteWorkspaceResponse,\n IWorkspaceResponse,\n IWorkspaceForNewPostResponse,\n IUpdateWorkspaceResult,\n CommentPostType,\n IDefaultCommentUploadSlot,\n IResolvedDefaultCommentsResponse,\n ISetDefaultCommentsResult,\n IUploadedDefaultCommentImage,\n IWorkspaceDefaultComment,\n} from \"./interfaces\";\n\n/**\n * Social Publisher Workspace Client\n */\nexport class SocialPublisherWorkspaceClient {\n private http: HttpClient;\n private basePath = \"/api/social-publisher-workspace\";\n\n /**\n * Create client\n * @param http - HttpClient instance\n */\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Search workspaces\n * @param params - Search filters\n * @param pagination - Pagination options\n */\n async list(params?: IListParams, pagination?: IPaginationParams): Promise<ISearchWorkspaceResponse> {\n const response = await this.http.get<ISearchWorkspaceResponse>(this.basePath, {\n params: {\n ...params,\n ...pagination,\n },\n });\n return response.result!;\n }\n\n /**\n * Get workspace by ID\n * @param id - Workspace ID\n */\n async get(id: string): Promise<IWorkspaceResponse> {\n const response = await this.http.get<IWorkspaceResponse>(`${this.basePath}/${encodeURIComponent(id)}`);\n return response.result!;\n }\n\n /**\n * Get workspace details for creating new post\n * @param id - Workspace ID\n * @returns Workspace details with populated account information\n *\n * @example\n * ```typescript\n * const workspace = await client.getForNewPost('workspace-id');\n * console.log(workspace.account.youtube); // YouTube account details\n * console.log(workspace.account.facebook?.status); // Facebook account status\n * ```\n */\n async getForNewPost(id: string): Promise<IWorkspaceForNewPostResponse> {\n const response = await this.http.get<IWorkspaceForNewPostResponse>(`${this.basePath}/${encodeURIComponent(id)}/for-new-post`);\n return response.result!;\n }\n\n /**\n * Create workspace with optional image upload\n * @param data - Workspace data\n * @param logo - Optional image file (File or Blob)\n * @returns Workspace details\n *\n * @example\n * ```typescript\n * // Create without image\n * const workspace = await client.create({ name: 'My Workspace', description: 'Description' });\n *\n * // Create with image\n * const file = new File([imageBlob], 'logo.png', { type: 'image/png' });\n * const workspace = await client.create(\n * { name: 'My Workspace', description: 'Description' },\n * file\n * );\n */\n async create(data: ICreateWorkspaceRequest, logo?: File | Blob): Promise<string> {\n // Step 1: Create workspace and get upload config\n const response = await this.http.post<ICreateWorkspaceResponse>(this.basePath, {\n ...data,\n hasImage: !!logo,\n createdFrom: this.http.createdFrom,\n });\n\n // Step 2: Upload image if provided\n if (logo && response.result?.uploadImageConfig) {\n await uploadToR2(response.result.uploadImageConfig.uploadUrl, logo, {\n contentType: /*logo instanceof File ? logo.type : 'image/png'*/ \"image/png\",\n });\n }\n\n return response.result?.workspaceId!;\n }\n\n /**\n * Update workspace with optional image upload\n * @param id - Workspace ID\n * @param data - Workspace data\n * @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.\n * @param logo - Optional new image file (File or Blob)\n * @returns `{ _id, __v }`, `__v` being the new version\n *\n * @example\n * ```typescript\n * // Update without changing image\n * const ws = await client.get('workspace-id');\n * await client.update('workspace-id', { name: 'New Name', description: 'New Description' }, ws.__v);\n *\n * // Update with new image\n * const file = new File([imageBlob], 'new-logo.png', { type: 'image/png' });\n * await client.update(\n * 'workspace-id',\n */\n async update(id: string, data: IUpdateWorkspaceRequest, version: number, logo?: File | Blob): Promise<IUpdateWorkspaceResult> {\n assertVersion(version);\n // Step 1: Update workspace and get upload config\n const response = await this.http.put<IUpdateWorkspaceResponse>(\n `${this.basePath}/${encodeURIComponent(id)}`,\n {\n ...data,\n hasImage: !!logo,\n },\n { version },\n );\n\n // Step 2: Upload image if provided\n if (logo && response.result?.uploadImageConfig) {\n await uploadToR2(response.result.uploadImageConfig.uploadUrl, logo, {\n contentType: logo instanceof File ? logo.type : \"image/png\",\n });\n }\n\n return { _id: response.result?.workspaceId ?? id, __v: response.version as number };\n }\n\n /**\n * Delete workspace\n * @param id - Workspace ID\n * @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.\n */\n async delete(id: string, version: number): Promise<void> {\n assertVersion(version);\n await this.http.delete<IDeleteWorkspaceResponse>(`${this.basePath}/${encodeURIComponent(id)}`, { version });\n }\n\n /**\n * The workspace's default comments, in order.\n * @param id - Workspace ID\n */\n async getDefaultComments(id: string): Promise<IWorkspaceDefaultComment[]> {\n const workspace = await this.get(id);\n return workspace.defaultComments ?? [];\n }\n\n /**\n * Replace the workspace's default comments (at most 10).\n *\n * Send the whole list the workspace should have; an empty list clears it.\n * Every new post to the workspace then starts with the active defaults for\n * its post type, unless the create request sends\n * `allowPostDefaultComments: false`. **Each added comment is charged like any\n * other comment.**\n *\n * @param id - Workspace ID\n * @param comments - The full list\n * @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.\n *\n * @example\n * ```typescript\n * const ws = await client.get('workspace-id');\n * await client.setDefaultComments('workspace-id', [\n * { text: 'Full video on our channel 👉', postTypes: ['shortVideo'] },\n * { text: 'Thanks for watching!', delayMinutes: 60 },\n * ], ws.__v);\n * ```\n */\n async setDefaultComments(id: string, comments: IWorkspaceDefaultComment[], version: number): Promise<ISetDefaultCommentsResult> {\n assertVersion(version);\n const response = await this.http.put<IWorkspaceDefaultComment[]>(\n `${this.basePath}/${encodeURIComponent(id)}/default-comments`,\n { comments },\n { version },\n );\n return { comments: response.result ?? [], __v: response.version as number };\n }\n\n /**\n * Signed upload slots for default-comment images, one per file type.\n * Uploading is a paid-plan feature; on a lower plan give the default an `imageUrl` instead.\n * @param id - Workspace ID\n * @param fileTypes - MIME types: image/jpeg, image/png, image/gif or image/webp\n */\n async generateDefaultCommentUploadUrls(id: string, fileTypes: string[]): Promise<IDefaultCommentUploadSlot[]> {\n const response = await this.http.post<IDefaultCommentUploadSlot[]>(\n `${this.basePath}/${encodeURIComponent(id)}/default-comments/upload-urls`,\n { fileTypes },\n );\n return response.result ?? [];\n }\n\n /**\n * Upload one image for a default comment: a slot, then the bytes.\n * Put the result on a default and save it with {@link setDefaultComments}.\n * @param id - Workspace ID\n * @param image - The image (File or Blob)\n */\n async uploadDefaultCommentImage(id: string, image: File | Blob): Promise<IUploadedDefaultCommentImage> {\n const contentType = image.type || \"image/png\";\n const [slot] = await this.generateDefaultCommentUploadUrls(id, [contentType]);\n if (!slot?.uploadFileURL) throw new Error(\"The API did not return an upload slot.\");\n await uploadToR2(slot.uploadFileURL, image, { contentType });\n return { imageUrl: slot.fileURL, imageStorageKey: slot.bucketFilePath };\n }\n\n /**\n * The default comments a new post of `postType` to this workspace would get\n * right now: the workspace's own for that type, then the account defaults\n * marked `applyToWorkspacePosts`. The same rule the create endpoints run.\n *\n * To show them to a user and let them edit the list, send the edited list as\n * the post's `comments` with `allowPostDefaultComments: false`.\n *\n * @param id - Workspace ID\n * @param postType - shortVideo, longVideo, image or text\n */\n async resolveDefaultComments(id: string, postType: CommentPostType): Promise<IResolvedDefaultCommentsResponse> {\n const response = await this.http.get<IResolvedDefaultCommentsResponse>(\n `${this.basePath}/${encodeURIComponent(id)}/default-comments/resolved`,\n { params: { postType } },\n );\n return response.result ?? { comments: [], warnings: [] };\n }\n}\n","import { HttpClient, IPaginationParams, IPaginationResponse } from \"@posty5/core\";\nimport { ISocialAccountDetails, ISocialAccountListParams, ISocialAccountLookupItem, ISocialAccountSummary, SocialAccountPlatform } from \"./interfaces\";\n\n/**\n * Connected social accounts, read-only — `/api/social-publisher-account`.\n *\n * Where an `accountId` for the account-targeted post methods\n * (`createImagePostToAccount`, `publishShortVideoToAccount`, …) comes from.\n * Connecting an account is an OAuth flow done in the Posty5 dashboard, not\n * through the API. No response carries a platform token.\n *\n * With an API key whose record scope is `key`, only accounts connected with\n * that key are listed; with `account`, every account of its owner.\n */\nexport class SocialPublisherAccountClient {\n private http: HttpClient;\n private readonly basePath = \"/api/social-publisher-account\";\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /** List connected accounts, filtered by platform, status or name. */\n async list(params?: ISocialAccountListParams, pagination?: IPaginationParams): Promise<IPaginationResponse<ISocialAccountSummary>> {\n const response = await this.http.get<IPaginationResponse<ISocialAccountSummary>>(this.basePath, {\n params: { ...params, ...pagination },\n });\n return response.result!;\n }\n\n /** Look accounts up by name, optionally on one platform. One page, no cursor (`pageSize` defaults to 10). */\n async lookup(term?: string, platform?: SocialAccountPlatform, pageSize?: number): Promise<ISocialAccountLookupItem[]> {\n const params: Record<string, string | number> = {};\n if (term) params.term = term;\n if (platform) params.platform = platform;\n if (pageSize) params.pageSize = pageSize;\n const response = await this.http.get<ISocialAccountLookupItem[]>(`${this.basePath}/lookup`, { params });\n return response.result || [];\n }\n\n /** One account's details. */\n async get(id: string): Promise<ISocialAccountDetails> {\n const response = await this.http.get<ISocialAccountDetails>(`${this.basePath}/${encodeURIComponent(id)}`);\n return response.result!;\n }\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -29,7 +29,7 @@ var SocialPublisherWorkspaceClient = class {
|
|
|
29
29
|
* @param id - Workspace ID
|
|
30
30
|
*/
|
|
31
31
|
async get(id) {
|
|
32
|
-
const response = await this.http.get(`${this.basePath}/${id}`);
|
|
32
|
+
const response = await this.http.get(`${this.basePath}/${encodeURIComponent(id)}`);
|
|
33
33
|
return response.result;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
@@ -45,7 +45,7 @@ var SocialPublisherWorkspaceClient = class {
|
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
47
|
async getForNewPost(id) {
|
|
48
|
-
const response = await this.http.get(`${this.basePath}/${id}/for-new-post`);
|
|
48
|
+
const response = await this.http.get(`${this.basePath}/${encodeURIComponent(id)}/for-new-post`);
|
|
49
49
|
return response.result;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
@@ -104,7 +104,7 @@ var SocialPublisherWorkspaceClient = class {
|
|
|
104
104
|
async update(id, data, version, logo) {
|
|
105
105
|
assertVersion(version);
|
|
106
106
|
const response = await this.http.put(
|
|
107
|
-
`${this.basePath}/${id}`,
|
|
107
|
+
`${this.basePath}/${encodeURIComponent(id)}`,
|
|
108
108
|
{
|
|
109
109
|
...data,
|
|
110
110
|
hasImage: !!logo
|
|
@@ -125,7 +125,90 @@ var SocialPublisherWorkspaceClient = class {
|
|
|
125
125
|
*/
|
|
126
126
|
async delete(id, version) {
|
|
127
127
|
assertVersion(version);
|
|
128
|
-
await this.http.delete(`${this.basePath}/${id}`, { version });
|
|
128
|
+
await this.http.delete(`${this.basePath}/${encodeURIComponent(id)}`, { version });
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The workspace's default comments, in order.
|
|
132
|
+
* @param id - Workspace ID
|
|
133
|
+
*/
|
|
134
|
+
async getDefaultComments(id) {
|
|
135
|
+
const workspace = await this.get(id);
|
|
136
|
+
return workspace.defaultComments ?? [];
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Replace the workspace's default comments (at most 10).
|
|
140
|
+
*
|
|
141
|
+
* Send the whole list the workspace should have; an empty list clears it.
|
|
142
|
+
* Every new post to the workspace then starts with the active defaults for
|
|
143
|
+
* its post type, unless the create request sends
|
|
144
|
+
* `allowPostDefaultComments: false`. **Each added comment is charged like any
|
|
145
|
+
* other comment.**
|
|
146
|
+
*
|
|
147
|
+
* @param id - Workspace ID
|
|
148
|
+
* @param comments - The full list
|
|
149
|
+
* @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const ws = await client.get('workspace-id');
|
|
154
|
+
* await client.setDefaultComments('workspace-id', [
|
|
155
|
+
* { text: 'Full video on our channel 👉', postTypes: ['shortVideo'] },
|
|
156
|
+
* { text: 'Thanks for watching!', delayMinutes: 60 },
|
|
157
|
+
* ], ws.__v);
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
async setDefaultComments(id, comments, version) {
|
|
161
|
+
assertVersion(version);
|
|
162
|
+
const response = await this.http.put(
|
|
163
|
+
`${this.basePath}/${encodeURIComponent(id)}/default-comments`,
|
|
164
|
+
{ comments },
|
|
165
|
+
{ version }
|
|
166
|
+
);
|
|
167
|
+
return { comments: response.result ?? [], __v: response.version };
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Signed upload slots for default-comment images, one per file type.
|
|
171
|
+
* Uploading is a paid-plan feature; on a lower plan give the default an `imageUrl` instead.
|
|
172
|
+
* @param id - Workspace ID
|
|
173
|
+
* @param fileTypes - MIME types: image/jpeg, image/png, image/gif or image/webp
|
|
174
|
+
*/
|
|
175
|
+
async generateDefaultCommentUploadUrls(id, fileTypes) {
|
|
176
|
+
const response = await this.http.post(
|
|
177
|
+
`${this.basePath}/${encodeURIComponent(id)}/default-comments/upload-urls`,
|
|
178
|
+
{ fileTypes }
|
|
179
|
+
);
|
|
180
|
+
return response.result ?? [];
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Upload one image for a default comment: a slot, then the bytes.
|
|
184
|
+
* Put the result on a default and save it with {@link setDefaultComments}.
|
|
185
|
+
* @param id - Workspace ID
|
|
186
|
+
* @param image - The image (File or Blob)
|
|
187
|
+
*/
|
|
188
|
+
async uploadDefaultCommentImage(id, image) {
|
|
189
|
+
const contentType = image.type || "image/png";
|
|
190
|
+
const [slot] = await this.generateDefaultCommentUploadUrls(id, [contentType]);
|
|
191
|
+
if (!slot?.uploadFileURL) throw new Error("The API did not return an upload slot.");
|
|
192
|
+
await uploadToR2(slot.uploadFileURL, image, { contentType });
|
|
193
|
+
return { imageUrl: slot.fileURL, imageStorageKey: slot.bucketFilePath };
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The default comments a new post of `postType` to this workspace would get
|
|
197
|
+
* right now: the workspace's own for that type, then the account defaults
|
|
198
|
+
* marked `applyToWorkspacePosts`. The same rule the create endpoints run.
|
|
199
|
+
*
|
|
200
|
+
* To show them to a user and let them edit the list, send the edited list as
|
|
201
|
+
* the post's `comments` with `allowPostDefaultComments: false`.
|
|
202
|
+
*
|
|
203
|
+
* @param id - Workspace ID
|
|
204
|
+
* @param postType - shortVideo, longVideo, image or text
|
|
205
|
+
*/
|
|
206
|
+
async resolveDefaultComments(id, postType) {
|
|
207
|
+
const response = await this.http.get(
|
|
208
|
+
`${this.basePath}/${encodeURIComponent(id)}/default-comments/resolved`,
|
|
209
|
+
{ params: { postType } }
|
|
210
|
+
);
|
|
211
|
+
return response.result ?? { comments: [], warnings: [] };
|
|
129
212
|
}
|
|
130
213
|
};
|
|
131
214
|
|
|
@@ -153,7 +236,7 @@ var SocialPublisherAccountClient = class {
|
|
|
153
236
|
}
|
|
154
237
|
/** One account's details. */
|
|
155
238
|
async get(id) {
|
|
156
|
-
const response = await this.http.get(`${this.basePath}/${id}`);
|
|
239
|
+
const response = await this.http.get(`${this.basePath}/${encodeURIComponent(id)}`);
|
|
157
240
|
return response.result;
|
|
158
241
|
}
|
|
159
242
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/social-publisher-workspace.client.ts","../src/social-publisher-account.client.ts"],"names":[],"mapp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AAW,EAAE,MAAA,EAAQ,CAAA;AACtG,IAAA,OAAO,QAAA,CAAS,UAAU,EAAC;AAAA,EAC7B;AAAA;AAAA,EAGA,MAAM,IAAI,EAAA,EAA4C;AACpD,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAA2B,GAAG,IAAA,CAAK,QAAQ,CAAA,CAAA,EAAI,EAAE,CAAA,CAAE,CAAA;AACpF,IAAA,OAAO,QAAA,CAAS,MAAA;AAAA,EAClB;AACF","file":"index.mjs","sourcesContent":["import { HttpClient, IPaginationParams, assertVersion, uploadToR2 } from \"@posty5/core\";\nimport {\n ICreateWorkspaceRequest,\n IUpdateWorkspaceRequest,\n IListParams,\n ISearchWorkspaceResponse,\n ICreateWorkspaceResponse,\n IUpdateWorkspaceResponse,\n IDeleteWorkspaceResponse,\n IWorkspaceResponse,\n IWorkspaceForNewPostResponse,\n IUpdateWorkspaceResult,\n} from \"./interfaces\";\n\n/**\n * Social Publisher Workspace Client\n */\nexport class SocialPublisherWorkspaceClient {\n private http: HttpClient;\n private basePath = \"/api/social-publisher-workspace\";\n\n /**\n * Create client\n * @param http - HttpClient instance\n */\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Search workspaces\n * @param params - Search filters\n * @param pagination - Pagination options\n */\n async list(params?: IListParams, pagination?: IPaginationParams): Promise<ISearchWorkspaceResponse> {\n const response = await this.http.get<ISearchWorkspaceResponse>(this.basePath, {\n params: {\n ...params,\n ...pagination,\n },\n });\n return response.result!;\n }\n\n /**\n * Get workspace by ID\n * @param id - Workspace ID\n */\n async get(id: string): Promise<IWorkspaceResponse> {\n const response = await this.http.get<IWorkspaceResponse>(`${this.basePath}/${id}`);\n return response.result!;\n }\n\n /**\n * Get workspace details for creating new post\n * @param id - Workspace ID\n * @returns Workspace details with populated account information\n *\n * @example\n * ```typescript\n * const workspace = await client.getForNewPost('workspace-id');\n * console.log(workspace.account.youtube); // YouTube account details\n * console.log(workspace.account.facebook?.status); // Facebook account status\n * ```\n */\n async getForNewPost(id: string): Promise<IWorkspaceForNewPostResponse> {\n const response = await this.http.get<IWorkspaceForNewPostResponse>(`${this.basePath}/${id}/for-new-post`);\n return response.result!;\n }\n\n /**\n * Create workspace with optional image upload\n * @param data - Workspace data\n * @param logo - Optional image file (File or Blob)\n * @returns Workspace details\n *\n * @example\n * ```typescript\n * // Create without image\n * const workspace = await client.create({ name: 'My Workspace', description: 'Description' });\n *\n * // Create with image\n * const file = new File([imageBlob], 'logo.png', { type: 'image/png' });\n * const workspace = await client.create(\n * { name: 'My Workspace', description: 'Description' },\n * file\n * );\n */\n async create(data: ICreateWorkspaceRequest, logo?: File | Blob): Promise<string> {\n // Step 1: Create workspace and get upload config\n const response = await this.http.post<ICreateWorkspaceResponse>(this.basePath, {\n ...data,\n hasImage: !!logo,\n createdFrom: this.http.createdFrom,\n });\n\n // Step 2: Upload image if provided\n if (logo && response.result?.uploadImageConfig) {\n await uploadToR2(response.result.uploadImageConfig.uploadUrl, logo, {\n contentType: /*logo instanceof File ? logo.type : 'image/png'*/ \"image/png\",\n });\n }\n\n return response.result?.workspaceId!;\n }\n\n /**\n * Update workspace with optional image upload\n * @param id - Workspace ID\n * @param data - Workspace data\n * @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.\n * @param logo - Optional new image file (File or Blob)\n * @returns `{ _id, __v }`, `__v` being the new version\n *\n * @example\n * ```typescript\n * // Update without changing image\n * const ws = await client.get('workspace-id');\n * await client.update('workspace-id', { name: 'New Name', description: 'New Description' }, ws.__v);\n *\n * // Update with new image\n * const file = new File([imageBlob], 'new-logo.png', { type: 'image/png' });\n * await client.update(\n * 'workspace-id',\n */\n async update(id: string, data: IUpdateWorkspaceRequest, version: number, logo?: File | Blob): Promise<IUpdateWorkspaceResult> {\n assertVersion(version);\n // Step 1: Update workspace and get upload config\n const response = await this.http.put<IUpdateWorkspaceResponse>(\n `${this.basePath}/${id}`,\n {\n ...data,\n hasImage: !!logo,\n },\n { version },\n );\n\n // Step 2: Upload image if provided\n if (logo && response.result?.uploadImageConfig) {\n await uploadToR2(response.result.uploadImageConfig.uploadUrl, logo, {\n contentType: logo instanceof File ? logo.type : \"image/png\",\n });\n }\n\n return { _id: response.result?.workspaceId ?? id, __v: response.version as number };\n }\n\n /**\n * Delete workspace\n * @param id - Workspace ID\n * @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.\n */\n async delete(id: string, version: number): Promise<void> {\n assertVersion(version);\n await this.http.delete<IDeleteWorkspaceResponse>(`${this.basePath}/${id}`, { version });\n }\n}\n","import { HttpClient, IPaginationParams, IPaginationResponse } from \"@posty5/core\";\nimport { ISocialAccountDetails, ISocialAccountListParams, ISocialAccountLookupItem, ISocialAccountSummary, SocialAccountPlatform } from \"./interfaces\";\n\n/**\n * Connected social accounts, read-only — `/api/social-publisher-account`.\n *\n * Where an `accountId` for the account-targeted post methods\n * (`createImagePostToAccount`, `publishShortVideoToAccount`, …) comes from.\n * Connecting an account is an OAuth flow done in the Posty5 dashboard, not\n * through the API. No response carries a platform token.\n *\n * With an API key whose record scope is `key`, only accounts connected with\n * that key are listed; with `account`, every account of its owner.\n */\nexport class SocialPublisherAccountClient {\n private http: HttpClient;\n private readonly basePath = \"/api/social-publisher-account\";\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /** List connected accounts, filtered by platform, status or name. */\n async list(params?: ISocialAccountListParams, pagination?: IPaginationParams): Promise<IPaginationResponse<ISocialAccountSummary>> {\n const response = await this.http.get<IPaginationResponse<ISocialAccountSummary>>(this.basePath, {\n params: { ...params, ...pagination },\n });\n return response.result!;\n }\n\n /** Look accounts up by name, optionally on one platform. One page, no cursor (`pageSize` defaults to 10). */\n async lookup(term?: string, platform?: SocialAccountPlatform, pageSize?: number): Promise<ISocialAccountLookupItem[]> {\n const params: Record<string, string | number> = {};\n if (term) params.term = term;\n if (platform) params.platform = platform;\n if (pageSize) params.pageSize = pageSize;\n const response = await this.http.get<ISocialAccountLookupItem[]>(`${this.basePath}/lookup`, { params });\n return response.result || [];\n }\n\n /** One account's details. */\n async get(id: string): Promise<ISocialAccountDetails> {\n const response = await this.http.get<ISocialAccountDetails>(`${this.basePath}/${id}`);\n return response.result!;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/social-publisher-workspace.client.ts","../src/social-publisher-account.client.ts"],"names":[],"mappings":";;;AAuBO,IAAM,iCAAN,MAAqC;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ1C,YAAY,IAAA,EAAkB;AAN9B,IAAA,IAAA,CAAQ,QAAA,GAAW,iCAAA;AAOjB,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,IAAA,CAAK,MAAA,EAAsB,UAAA,EAAmE;AAClG,IAAA,MAAM,WAAW,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAA8B,KAAK,QAAA,EAAU;AAAA,MAC5E,MAAA,EAAQ;AAAA,QACN,GAAG,MAAA;AAAA,QACH,GAAG;AAAA;AACL,KACD,CAAA;AACD,IAAA,OAAO,QAAA,CAAS,MAAA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,IAAI,EAAA,EAAyC;AACjD,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAAwB,CAAA,EAAG,IAAA,CAAK,QAAQ,CAAA,CAAA,EAAI,kBAAA,CAAmB,EAAE,CAAC,CAAA,CAAE,CAAA;AACrG,IAAA,OAAO,QAAA,CAAS,MAAA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,MAAM,cAAc,EAAA,EAAmD;AACrE,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAAkC,CAAA,EAAG,IAAA,CAAK,QAAQ,CAAA,CAAA,EAAI,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AO,QAAA,CAAS,UAAU,EAAC;AAAA,EAC7B;AAAA;AAAA,EAGA,MAAM,IAAI,EAAA,EAA4C;AACpD,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAA2B,CAAA,EAAG,IAAA,CAAK,QAAQ,CAAA,CAAA,EAAI,kBAAA,CAAmB,EAAE,CAAC,CAAA,CAAE,CAAA;AACxG,IAAA,OAAO,QAAA,CAAS,MAAA;AAAA,EAClB;AACF","file":"index.mjs","sourcesContent":["import { HttpClient, IPaginationParams, assertVersion, uploadToR2 } from \"@posty5/core\";\nimport {\n ICreateWorkspaceRequest,\n IUpdateWorkspaceRequest,\n IListParams,\n ISearchWorkspaceResponse,\n ICreateWorkspaceResponse,\n IUpdateWorkspaceResponse,\n IDeleteWorkspaceResponse,\n IWorkspaceResponse,\n IWorkspaceForNewPostResponse,\n IUpdateWorkspaceResult,\n CommentPostType,\n IDefaultCommentUploadSlot,\n IResolvedDefaultCommentsResponse,\n ISetDefaultCommentsResult,\n IUploadedDefaultCommentImage,\n IWorkspaceDefaultComment,\n} from \"./interfaces\";\n\n/**\n * Social Publisher Workspace Client\n */\nexport class SocialPublisherWorkspaceClient {\n private http: HttpClient;\n private basePath = \"/api/social-publisher-workspace\";\n\n /**\n * Create client\n * @param http - HttpClient instance\n */\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Search workspaces\n * @param params - Search filters\n * @param pagination - Pagination options\n */\n async list(params?: IListParams, pagination?: IPaginationParams): Promise<ISearchWorkspaceResponse> {\n const response = await this.http.get<ISearchWorkspaceResponse>(this.basePath, {\n params: {\n ...params,\n ...pagination,\n },\n });\n return response.result!;\n }\n\n /**\n * Get workspace by ID\n * @param id - Workspace ID\n */\n async get(id: string): Promise<IWorkspaceResponse> {\n const response = await this.http.get<IWorkspaceResponse>(`${this.basePath}/${encodeURIComponent(id)}`);\n return response.result!;\n }\n\n /**\n * Get workspace details for creating new post\n * @param id - Workspace ID\n * @returns Workspace details with populated account information\n *\n * @example\n * ```typescript\n * const workspace = await client.getForNewPost('workspace-id');\n * console.log(workspace.account.youtube); // YouTube account details\n * console.log(workspace.account.facebook?.status); // Facebook account status\n * ```\n */\n async getForNewPost(id: string): Promise<IWorkspaceForNewPostResponse> {\n const response = await this.http.get<IWorkspaceForNewPostResponse>(`${this.basePath}/${encodeURIComponent(id)}/for-new-post`);\n return response.result!;\n }\n\n /**\n * Create workspace with optional image upload\n * @param data - Workspace data\n * @param logo - Optional image file (File or Blob)\n * @returns Workspace details\n *\n * @example\n * ```typescript\n * // Create without image\n * const workspace = await client.create({ name: 'My Workspace', description: 'Description' });\n *\n * // Create with image\n * const file = new File([imageBlob], 'logo.png', { type: 'image/png' });\n * const workspace = await client.create(\n * { name: 'My Workspace', description: 'Description' },\n * file\n * );\n */\n async create(data: ICreateWorkspaceRequest, logo?: File | Blob): Promise<string> {\n // Step 1: Create workspace and get upload config\n const response = await this.http.post<ICreateWorkspaceResponse>(this.basePath, {\n ...data,\n hasImage: !!logo,\n createdFrom: this.http.createdFrom,\n });\n\n // Step 2: Upload image if provided\n if (logo && response.result?.uploadImageConfig) {\n await uploadToR2(response.result.uploadImageConfig.uploadUrl, logo, {\n contentType: /*logo instanceof File ? logo.type : 'image/png'*/ \"image/png\",\n });\n }\n\n return response.result?.workspaceId!;\n }\n\n /**\n * Update workspace with optional image upload\n * @param id - Workspace ID\n * @param data - Workspace data\n * @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.\n * @param logo - Optional new image file (File or Blob)\n * @returns `{ _id, __v }`, `__v` being the new version\n *\n * @example\n * ```typescript\n * // Update without changing image\n * const ws = await client.get('workspace-id');\n * await client.update('workspace-id', { name: 'New Name', description: 'New Description' }, ws.__v);\n *\n * // Update with new image\n * const file = new File([imageBlob], 'new-logo.png', { type: 'image/png' });\n * await client.update(\n * 'workspace-id',\n */\n async update(id: string, data: IUpdateWorkspaceRequest, version: number, logo?: File | Blob): Promise<IUpdateWorkspaceResult> {\n assertVersion(version);\n // Step 1: Update workspace and get upload config\n const response = await this.http.put<IUpdateWorkspaceResponse>(\n `${this.basePath}/${encodeURIComponent(id)}`,\n {\n ...data,\n hasImage: !!logo,\n },\n { version },\n );\n\n // Step 2: Upload image if provided\n if (logo && response.result?.uploadImageConfig) {\n await uploadToR2(response.result.uploadImageConfig.uploadUrl, logo, {\n contentType: logo instanceof File ? logo.type : \"image/png\",\n });\n }\n\n return { _id: response.result?.workspaceId ?? id, __v: response.version as number };\n }\n\n /**\n * Delete workspace\n * @param id - Workspace ID\n * @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.\n */\n async delete(id: string, version: number): Promise<void> {\n assertVersion(version);\n await this.http.delete<IDeleteWorkspaceResponse>(`${this.basePath}/${encodeURIComponent(id)}`, { version });\n }\n\n /**\n * The workspace's default comments, in order.\n * @param id - Workspace ID\n */\n async getDefaultComments(id: string): Promise<IWorkspaceDefaultComment[]> {\n const workspace = await this.get(id);\n return workspace.defaultComments ?? [];\n }\n\n /**\n * Replace the workspace's default comments (at most 10).\n *\n * Send the whole list the workspace should have; an empty list clears it.\n * Every new post to the workspace then starts with the active defaults for\n * its post type, unless the create request sends\n * `allowPostDefaultComments: false`. **Each added comment is charged like any\n * other comment.**\n *\n * @param id - Workspace ID\n * @param comments - The full list\n * @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.\n *\n * @example\n * ```typescript\n * const ws = await client.get('workspace-id');\n * await client.setDefaultComments('workspace-id', [\n * { text: 'Full video on our channel 👉', postTypes: ['shortVideo'] },\n * { text: 'Thanks for watching!', delayMinutes: 60 },\n * ], ws.__v);\n * ```\n */\n async setDefaultComments(id: string, comments: IWorkspaceDefaultComment[], version: number): Promise<ISetDefaultCommentsResult> {\n assertVersion(version);\n const response = await this.http.put<IWorkspaceDefaultComment[]>(\n `${this.basePath}/${encodeURIComponent(id)}/default-comments`,\n { comments },\n { version },\n );\n return { comments: response.result ?? [], __v: response.version as number };\n }\n\n /**\n * Signed upload slots for default-comment images, one per file type.\n * Uploading is a paid-plan feature; on a lower plan give the default an `imageUrl` instead.\n * @param id - Workspace ID\n * @param fileTypes - MIME types: image/jpeg, image/png, image/gif or image/webp\n */\n async generateDefaultCommentUploadUrls(id: string, fileTypes: string[]): Promise<IDefaultCommentUploadSlot[]> {\n const response = await this.http.post<IDefaultCommentUploadSlot[]>(\n `${this.basePath}/${encodeURIComponent(id)}/default-comments/upload-urls`,\n { fileTypes },\n );\n return response.result ?? [];\n }\n\n /**\n * Upload one image for a default comment: a slot, then the bytes.\n * Put the result on a default and save it with {@link setDefaultComments}.\n * @param id - Workspace ID\n * @param image - The image (File or Blob)\n */\n async uploadDefaultCommentImage(id: string, image: File | Blob): Promise<IUploadedDefaultCommentImage> {\n const contentType = image.type || \"image/png\";\n const [slot] = await this.generateDefaultCommentUploadUrls(id, [contentType]);\n if (!slot?.uploadFileURL) throw new Error(\"The API did not return an upload slot.\");\n await uploadToR2(slot.uploadFileURL, image, { contentType });\n return { imageUrl: slot.fileURL, imageStorageKey: slot.bucketFilePath };\n }\n\n /**\n * The default comments a new post of `postType` to this workspace would get\n * right now: the workspace's own for that type, then the account defaults\n * marked `applyToWorkspacePosts`. The same rule the create endpoints run.\n *\n * To show them to a user and let them edit the list, send the edited list as\n * the post's `comments` with `allowPostDefaultComments: false`.\n *\n * @param id - Workspace ID\n * @param postType - shortVideo, longVideo, image or text\n */\n async resolveDefaultComments(id: string, postType: CommentPostType): Promise<IResolvedDefaultCommentsResponse> {\n const response = await this.http.get<IResolvedDefaultCommentsResponse>(\n `${this.basePath}/${encodeURIComponent(id)}/default-comments/resolved`,\n { params: { postType } },\n );\n return response.result ?? { comments: [], warnings: [] };\n }\n}\n","import { HttpClient, IPaginationParams, IPaginationResponse } from \"@posty5/core\";\nimport { ISocialAccountDetails, ISocialAccountListParams, ISocialAccountLookupItem, ISocialAccountSummary, SocialAccountPlatform } from \"./interfaces\";\n\n/**\n * Connected social accounts, read-only — `/api/social-publisher-account`.\n *\n * Where an `accountId` for the account-targeted post methods\n * (`createImagePostToAccount`, `publishShortVideoToAccount`, …) comes from.\n * Connecting an account is an OAuth flow done in the Posty5 dashboard, not\n * through the API. No response carries a platform token.\n *\n * With an API key whose record scope is `key`, only accounts connected with\n * that key are listed; with `account`, every account of its owner.\n */\nexport class SocialPublisherAccountClient {\n private http: HttpClient;\n private readonly basePath = \"/api/social-publisher-account\";\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /** List connected accounts, filtered by platform, status or name. */\n async list(params?: ISocialAccountListParams, pagination?: IPaginationParams): Promise<IPaginationResponse<ISocialAccountSummary>> {\n const response = await this.http.get<IPaginationResponse<ISocialAccountSummary>>(this.basePath, {\n params: { ...params, ...pagination },\n });\n return response.result!;\n }\n\n /** Look accounts up by name, optionally on one platform. One page, no cursor (`pageSize` defaults to 10). */\n async lookup(term?: string, platform?: SocialAccountPlatform, pageSize?: number): Promise<ISocialAccountLookupItem[]> {\n const params: Record<string, string | number> = {};\n if (term) params.term = term;\n if (platform) params.platform = platform;\n if (pageSize) params.pageSize = pageSize;\n const response = await this.http.get<ISocialAccountLookupItem[]>(`${this.basePath}/lookup`, { params });\n return response.result || [];\n }\n\n /** One account's details. */\n async get(id: string): Promise<ISocialAccountDetails> {\n const response = await this.http.get<ISocialAccountDetails>(`${this.basePath}/${encodeURIComponent(id)}`);\n return response.result!;\n }\n}\n"]}
|