@posty5/social-publisher-workspace 4.2.0 → 5.0.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/README.md +48 -0
- package/dist/index.d.mts +82 -5
- package/dist/index.d.ts +82 -5
- package/dist/index.js +53 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -102,6 +102,33 @@ console.log(`Found ${workspaces.pagination.totalCount} workspaces`);
|
|
|
102
102
|
|
|
103
103
|
---
|
|
104
104
|
|
|
105
|
+
## 🔒 Versioned writes (5.0.0)
|
|
106
|
+
|
|
107
|
+
Every write to an existing document carries the version you read, so two
|
|
108
|
+
people (or two scripts) can never silently overwrite each other.
|
|
109
|
+
|
|
110
|
+
- **Where `__v` comes from:** every entity this SDK returns (`get`, `list`,
|
|
111
|
+
and every write) has `__v`. Keep the `__v` a write returns for your next write.
|
|
112
|
+
- **A stale version** throws `ConflictError` (409). It carries
|
|
113
|
+
`currentVersion`, the document's version now.
|
|
114
|
+
- **Merging deliberately:** reload, re-apply your change, and resend with the
|
|
115
|
+
fresh version (`currentVersion`). There is no "overwrite anyway" flag;
|
|
116
|
+
resending blindly is exactly the lost update this prevents.
|
|
117
|
+
- Versioned writes are never retried automatically.
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { ConflictError } from "@posty5/core";
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
const ws = await client.get(id);
|
|
124
|
+
await client.update(id, { name, description }, ws.__v);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (error instanceof ConflictError) {
|
|
127
|
+
// error.currentVersion: reload, merge, and resend with the fresh __v
|
|
128
|
+
} else throw error;
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
105
132
|
## 📚 API Reference & Examples
|
|
106
133
|
|
|
107
134
|
### create()
|
|
@@ -598,6 +625,27 @@ We're here to help you succeed with Posty5!
|
|
|
598
625
|
|
|
599
626
|
---
|
|
600
627
|
|
|
628
|
+
## 👤 Connected social accounts (4.3.0)
|
|
629
|
+
|
|
630
|
+
```ts
|
|
631
|
+
import { SocialPublisherAccountClient } from "@posty5/social-publisher-workspace";
|
|
632
|
+
|
|
633
|
+
const accounts = new SocialPublisherAccountClient(http);
|
|
634
|
+
const { items } = await accounts.list({ platform: "instagram" });
|
|
635
|
+
// items[0]._id is the accountId the account-targeted post methods take
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
| Method | Route |
|
|
639
|
+
| --- | --- |
|
|
640
|
+
| `list(params?, pagination?)` | `GET /api/social-publisher-account` |
|
|
641
|
+
| `lookup(term?, platform?)` | `GET /api/social-publisher-account/lookup` |
|
|
642
|
+
| `get(id)` | `GET /api/social-publisher-account/{id}` |
|
|
643
|
+
|
|
644
|
+
Read-only: connecting an account is an OAuth flow done in the Posty5 dashboard.
|
|
645
|
+
No response carries a platform token.
|
|
646
|
+
|
|
647
|
+
---
|
|
648
|
+
|
|
601
649
|
## 📄 License
|
|
602
650
|
|
|
603
651
|
MIT License - see [LICENSE](./LICENSE) file for details.
|
package/dist/index.d.mts
CHANGED
|
@@ -49,6 +49,8 @@ interface IWorkspaceAccount {
|
|
|
49
49
|
}
|
|
50
50
|
interface IWorkspaceResponse {
|
|
51
51
|
_id: string;
|
|
52
|
+
/** Document version: pass it to versioned writes (`update`, `delete`, ...). */
|
|
53
|
+
__v: number;
|
|
52
54
|
name: string;
|
|
53
55
|
description: string;
|
|
54
56
|
imageUrl?: string;
|
|
@@ -56,6 +58,8 @@ interface IWorkspaceResponse {
|
|
|
56
58
|
}
|
|
57
59
|
interface IWorkspaceSampleDetails {
|
|
58
60
|
_id: string;
|
|
61
|
+
/** Document version: pass it to versioned writes (`update`, `delete`, ...). */
|
|
62
|
+
__v: number;
|
|
59
63
|
name: string;
|
|
60
64
|
description: string;
|
|
61
65
|
imageUrl?: string;
|
|
@@ -81,6 +85,12 @@ interface IWorkspaceWithUploadConfig {
|
|
|
81
85
|
type ISearchWorkspaceResponse = IPaginationResponse<IWorkspaceSampleDetails>;
|
|
82
86
|
type ICreateWorkspaceResponse = IWorkspaceWithUploadConfig;
|
|
83
87
|
type IUpdateWorkspaceResponse = IWorkspaceWithUploadConfig;
|
|
88
|
+
/** What a versioned workspace update answers. */
|
|
89
|
+
interface IUpdateWorkspaceResult {
|
|
90
|
+
_id: string;
|
|
91
|
+
/** The workspace's new version */
|
|
92
|
+
__v: number;
|
|
93
|
+
}
|
|
84
94
|
interface IDeleteWorkspaceResponse {
|
|
85
95
|
message?: string;
|
|
86
96
|
}
|
|
@@ -89,12 +99,53 @@ interface IDeleteWorkspaceResponse {
|
|
|
89
99
|
*/
|
|
90
100
|
interface IWorkspaceForNewPostResponse {
|
|
91
101
|
_id: string;
|
|
102
|
+
/** Document version: pass it to versioned writes (`update`, `delete`, ...). */
|
|
103
|
+
__v: number;
|
|
92
104
|
name: string;
|
|
93
105
|
description: string;
|
|
94
106
|
imageUrl?: string;
|
|
95
107
|
account: IWorkspaceAccount;
|
|
96
108
|
}
|
|
97
109
|
|
|
110
|
+
/** A platform a social account can be connected on. */
|
|
111
|
+
type SocialAccountPlatform = "youtube" | "tiktok" | "facebook" | "instagram" | "threads" | "twitter";
|
|
112
|
+
/** `authenticationExpired`: reconnect the account in the Posty5 dashboard before publishing to it. */
|
|
113
|
+
type SocialAccountStatus = "active" | "inactive" | "authenticationExpired";
|
|
114
|
+
/** Filters for `SocialPublisherAccountClient.list`. */
|
|
115
|
+
interface ISocialAccountListParams {
|
|
116
|
+
platform?: SocialAccountPlatform;
|
|
117
|
+
status?: SocialAccountStatus;
|
|
118
|
+
/** Contains, case-insensitive. */
|
|
119
|
+
name?: string;
|
|
120
|
+
}
|
|
121
|
+
/** A connected social account as lists return it. Never carries a platform token. */
|
|
122
|
+
interface ISocialAccountSummary {
|
|
123
|
+
/** The `accountId` the account-targeted post methods take. */
|
|
124
|
+
_id: string;
|
|
125
|
+
platform: SocialAccountPlatform;
|
|
126
|
+
status: SocialAccountStatus;
|
|
127
|
+
/** Instagram only: how the account was connected. */
|
|
128
|
+
authSource?: "facebook_page" | "instagram_login";
|
|
129
|
+
name: string;
|
|
130
|
+
thumbnail?: string;
|
|
131
|
+
link?: string;
|
|
132
|
+
createdAt: string;
|
|
133
|
+
}
|
|
134
|
+
/** One account's details: its platform profile and publishing defaults. */
|
|
135
|
+
interface ISocialAccountDetails extends ISocialAccountSummary {
|
|
136
|
+
defaultPostSettings?: Record<string, unknown>;
|
|
137
|
+
defaultComments?: Record<string, unknown>[];
|
|
138
|
+
[platformBlock: string]: unknown;
|
|
139
|
+
}
|
|
140
|
+
/** One row of `SocialPublisherAccountClient.lookup`. */
|
|
141
|
+
interface ISocialAccountLookupItem {
|
|
142
|
+
_id: string;
|
|
143
|
+
name: string;
|
|
144
|
+
data?: {
|
|
145
|
+
img?: string;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
98
149
|
/**
|
|
99
150
|
* Social Publisher Workspace Client
|
|
100
151
|
*/
|
|
@@ -153,25 +204,51 @@ declare class SocialPublisherWorkspaceClient {
|
|
|
153
204
|
* Update workspace with optional image upload
|
|
154
205
|
* @param id - Workspace ID
|
|
155
206
|
* @param data - Workspace data
|
|
207
|
+
* @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.
|
|
156
208
|
* @param logo - Optional new image file (File or Blob)
|
|
157
|
-
* @returns
|
|
209
|
+
* @returns `{ _id, __v }`, `__v` being the new version
|
|
158
210
|
*
|
|
159
211
|
* @example
|
|
160
212
|
* ```typescript
|
|
161
213
|
* // Update without changing image
|
|
162
|
-
* await client.
|
|
214
|
+
* const ws = await client.get('workspace-id');
|
|
215
|
+
* await client.update('workspace-id', { name: 'New Name', description: 'New Description' }, ws.__v);
|
|
163
216
|
*
|
|
164
217
|
* // Update with new image
|
|
165
218
|
* const file = new File([imageBlob], 'new-logo.png', { type: 'image/png' });
|
|
166
219
|
* await client.update(
|
|
167
220
|
* 'workspace-id',
|
|
168
221
|
*/
|
|
169
|
-
update(id: string, data: IUpdateWorkspaceRequest, logo?: File | Blob): Promise<
|
|
222
|
+
update(id: string, data: IUpdateWorkspaceRequest, version: number, logo?: File | Blob): Promise<IUpdateWorkspaceResult>;
|
|
170
223
|
/**
|
|
171
224
|
* Delete workspace
|
|
172
225
|
* @param id - Workspace ID
|
|
226
|
+
* @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.
|
|
173
227
|
*/
|
|
174
|
-
delete(id: string): Promise<void>;
|
|
228
|
+
delete(id: string, version: number): Promise<void>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Connected social accounts, read-only — `/api/social-publisher-account`.
|
|
233
|
+
*
|
|
234
|
+
* Where an `accountId` for the account-targeted post methods
|
|
235
|
+
* (`createImagePostToAccount`, `publishShortVideoToAccount`, …) comes from.
|
|
236
|
+
* Connecting an account is an OAuth flow done in the Posty5 dashboard, not
|
|
237
|
+
* through the API. No response carries a platform token.
|
|
238
|
+
*
|
|
239
|
+
* With an API key whose record scope is `key`, only accounts connected with
|
|
240
|
+
* that key are listed; with `account`, every account of its owner.
|
|
241
|
+
*/
|
|
242
|
+
declare class SocialPublisherAccountClient {
|
|
243
|
+
private http;
|
|
244
|
+
private readonly basePath;
|
|
245
|
+
constructor(http: HttpClient);
|
|
246
|
+
/** List connected accounts, filtered by platform, status or name. */
|
|
247
|
+
list(params?: ISocialAccountListParams, pagination?: IPaginationParams): Promise<IPaginationResponse<ISocialAccountSummary>>;
|
|
248
|
+
/** Look accounts up by name, optionally on one platform. One page, no cursor (`pageSize` defaults to 10). */
|
|
249
|
+
lookup(term?: string, platform?: SocialAccountPlatform, pageSize?: number): Promise<ISocialAccountLookupItem[]>;
|
|
250
|
+
/** One account's details. */
|
|
251
|
+
get(id: string): Promise<ISocialAccountDetails>;
|
|
175
252
|
}
|
|
176
253
|
|
|
177
|
-
export { type IAccountSampleDetails, type ICreateWorkspaceRequest, type ICreateWorkspaceResponse, type IDeleteWorkspaceResponse, type IListParams, type ISearchWorkspaceResponse, type IUpdateWorkspaceRequest, type IUpdateWorkspaceResponse, type IUploadImageConfig, type IWorkspaceAccount, type IWorkspaceForNewPostResponse, type IWorkspaceRequest, type IWorkspaceResponse, type IWorkspaceSampleDetails, type IWorkspaceWithUploadConfig, type SocialPublisherAccountStatusType, SocialPublisherWorkspaceClient };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -49,6 +49,8 @@ interface IWorkspaceAccount {
|
|
|
49
49
|
}
|
|
50
50
|
interface IWorkspaceResponse {
|
|
51
51
|
_id: string;
|
|
52
|
+
/** Document version: pass it to versioned writes (`update`, `delete`, ...). */
|
|
53
|
+
__v: number;
|
|
52
54
|
name: string;
|
|
53
55
|
description: string;
|
|
54
56
|
imageUrl?: string;
|
|
@@ -56,6 +58,8 @@ interface IWorkspaceResponse {
|
|
|
56
58
|
}
|
|
57
59
|
interface IWorkspaceSampleDetails {
|
|
58
60
|
_id: string;
|
|
61
|
+
/** Document version: pass it to versioned writes (`update`, `delete`, ...). */
|
|
62
|
+
__v: number;
|
|
59
63
|
name: string;
|
|
60
64
|
description: string;
|
|
61
65
|
imageUrl?: string;
|
|
@@ -81,6 +85,12 @@ interface IWorkspaceWithUploadConfig {
|
|
|
81
85
|
type ISearchWorkspaceResponse = IPaginationResponse<IWorkspaceSampleDetails>;
|
|
82
86
|
type ICreateWorkspaceResponse = IWorkspaceWithUploadConfig;
|
|
83
87
|
type IUpdateWorkspaceResponse = IWorkspaceWithUploadConfig;
|
|
88
|
+
/** What a versioned workspace update answers. */
|
|
89
|
+
interface IUpdateWorkspaceResult {
|
|
90
|
+
_id: string;
|
|
91
|
+
/** The workspace's new version */
|
|
92
|
+
__v: number;
|
|
93
|
+
}
|
|
84
94
|
interface IDeleteWorkspaceResponse {
|
|
85
95
|
message?: string;
|
|
86
96
|
}
|
|
@@ -89,12 +99,53 @@ interface IDeleteWorkspaceResponse {
|
|
|
89
99
|
*/
|
|
90
100
|
interface IWorkspaceForNewPostResponse {
|
|
91
101
|
_id: string;
|
|
102
|
+
/** Document version: pass it to versioned writes (`update`, `delete`, ...). */
|
|
103
|
+
__v: number;
|
|
92
104
|
name: string;
|
|
93
105
|
description: string;
|
|
94
106
|
imageUrl?: string;
|
|
95
107
|
account: IWorkspaceAccount;
|
|
96
108
|
}
|
|
97
109
|
|
|
110
|
+
/** A platform a social account can be connected on. */
|
|
111
|
+
type SocialAccountPlatform = "youtube" | "tiktok" | "facebook" | "instagram" | "threads" | "twitter";
|
|
112
|
+
/** `authenticationExpired`: reconnect the account in the Posty5 dashboard before publishing to it. */
|
|
113
|
+
type SocialAccountStatus = "active" | "inactive" | "authenticationExpired";
|
|
114
|
+
/** Filters for `SocialPublisherAccountClient.list`. */
|
|
115
|
+
interface ISocialAccountListParams {
|
|
116
|
+
platform?: SocialAccountPlatform;
|
|
117
|
+
status?: SocialAccountStatus;
|
|
118
|
+
/** Contains, case-insensitive. */
|
|
119
|
+
name?: string;
|
|
120
|
+
}
|
|
121
|
+
/** A connected social account as lists return it. Never carries a platform token. */
|
|
122
|
+
interface ISocialAccountSummary {
|
|
123
|
+
/** The `accountId` the account-targeted post methods take. */
|
|
124
|
+
_id: string;
|
|
125
|
+
platform: SocialAccountPlatform;
|
|
126
|
+
status: SocialAccountStatus;
|
|
127
|
+
/** Instagram only: how the account was connected. */
|
|
128
|
+
authSource?: "facebook_page" | "instagram_login";
|
|
129
|
+
name: string;
|
|
130
|
+
thumbnail?: string;
|
|
131
|
+
link?: string;
|
|
132
|
+
createdAt: string;
|
|
133
|
+
}
|
|
134
|
+
/** One account's details: its platform profile and publishing defaults. */
|
|
135
|
+
interface ISocialAccountDetails extends ISocialAccountSummary {
|
|
136
|
+
defaultPostSettings?: Record<string, unknown>;
|
|
137
|
+
defaultComments?: Record<string, unknown>[];
|
|
138
|
+
[platformBlock: string]: unknown;
|
|
139
|
+
}
|
|
140
|
+
/** One row of `SocialPublisherAccountClient.lookup`. */
|
|
141
|
+
interface ISocialAccountLookupItem {
|
|
142
|
+
_id: string;
|
|
143
|
+
name: string;
|
|
144
|
+
data?: {
|
|
145
|
+
img?: string;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
98
149
|
/**
|
|
99
150
|
* Social Publisher Workspace Client
|
|
100
151
|
*/
|
|
@@ -153,25 +204,51 @@ declare class SocialPublisherWorkspaceClient {
|
|
|
153
204
|
* Update workspace with optional image upload
|
|
154
205
|
* @param id - Workspace ID
|
|
155
206
|
* @param data - Workspace data
|
|
207
|
+
* @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.
|
|
156
208
|
* @param logo - Optional new image file (File or Blob)
|
|
157
|
-
* @returns
|
|
209
|
+
* @returns `{ _id, __v }`, `__v` being the new version
|
|
158
210
|
*
|
|
159
211
|
* @example
|
|
160
212
|
* ```typescript
|
|
161
213
|
* // Update without changing image
|
|
162
|
-
* await client.
|
|
214
|
+
* const ws = await client.get('workspace-id');
|
|
215
|
+
* await client.update('workspace-id', { name: 'New Name', description: 'New Description' }, ws.__v);
|
|
163
216
|
*
|
|
164
217
|
* // Update with new image
|
|
165
218
|
* const file = new File([imageBlob], 'new-logo.png', { type: 'image/png' });
|
|
166
219
|
* await client.update(
|
|
167
220
|
* 'workspace-id',
|
|
168
221
|
*/
|
|
169
|
-
update(id: string, data: IUpdateWorkspaceRequest, logo?: File | Blob): Promise<
|
|
222
|
+
update(id: string, data: IUpdateWorkspaceRequest, version: number, logo?: File | Blob): Promise<IUpdateWorkspaceResult>;
|
|
170
223
|
/**
|
|
171
224
|
* Delete workspace
|
|
172
225
|
* @param id - Workspace ID
|
|
226
|
+
* @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.
|
|
173
227
|
*/
|
|
174
|
-
delete(id: string): Promise<void>;
|
|
228
|
+
delete(id: string, version: number): Promise<void>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Connected social accounts, read-only — `/api/social-publisher-account`.
|
|
233
|
+
*
|
|
234
|
+
* Where an `accountId` for the account-targeted post methods
|
|
235
|
+
* (`createImagePostToAccount`, `publishShortVideoToAccount`, …) comes from.
|
|
236
|
+
* Connecting an account is an OAuth flow done in the Posty5 dashboard, not
|
|
237
|
+
* through the API. No response carries a platform token.
|
|
238
|
+
*
|
|
239
|
+
* With an API key whose record scope is `key`, only accounts connected with
|
|
240
|
+
* that key are listed; with `account`, every account of its owner.
|
|
241
|
+
*/
|
|
242
|
+
declare class SocialPublisherAccountClient {
|
|
243
|
+
private http;
|
|
244
|
+
private readonly basePath;
|
|
245
|
+
constructor(http: HttpClient);
|
|
246
|
+
/** List connected accounts, filtered by platform, status or name. */
|
|
247
|
+
list(params?: ISocialAccountListParams, pagination?: IPaginationParams): Promise<IPaginationResponse<ISocialAccountSummary>>;
|
|
248
|
+
/** Look accounts up by name, optionally on one platform. One page, no cursor (`pageSize` defaults to 10). */
|
|
249
|
+
lookup(term?: string, platform?: SocialAccountPlatform, pageSize?: number): Promise<ISocialAccountLookupItem[]>;
|
|
250
|
+
/** One account's details. */
|
|
251
|
+
get(id: string): Promise<ISocialAccountDetails>;
|
|
175
252
|
}
|
|
176
253
|
|
|
177
|
-
export { type IAccountSampleDetails, type ICreateWorkspaceRequest, type ICreateWorkspaceResponse, type IDeleteWorkspaceResponse, type IListParams, type ISearchWorkspaceResponse, type IUpdateWorkspaceRequest, type IUpdateWorkspaceResponse, type IUploadImageConfig, type IWorkspaceAccount, type IWorkspaceForNewPostResponse, type IWorkspaceRequest, type IWorkspaceResponse, type IWorkspaceSampleDetails, type IWorkspaceWithUploadConfig, type SocialPublisherAccountStatusType, SocialPublisherWorkspaceClient };
|
|
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 };
|
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
|
/**
|
|
@@ -72,16 +72,15 @@ var SocialPublisherWorkspaceClient = class {
|
|
|
72
72
|
const response = await this.http.post(this.basePath, {
|
|
73
73
|
...data,
|
|
74
74
|
hasImage: !!logo,
|
|
75
|
-
createdFrom:
|
|
75
|
+
createdFrom: this.http.createdFrom
|
|
76
76
|
});
|
|
77
77
|
if (logo && response.result?.uploadImageConfig) {
|
|
78
|
-
|
|
78
|
+
await core.uploadToR2(response.result.uploadImageConfig.uploadUrl, logo, {
|
|
79
79
|
contentType: (
|
|
80
80
|
/*logo instanceof File ? logo.type : 'image/png'*/
|
|
81
81
|
"image/png"
|
|
82
82
|
)
|
|
83
83
|
});
|
|
84
|
-
console.log(res);
|
|
85
84
|
}
|
|
86
85
|
return response.result?.workspaceId;
|
|
87
86
|
}
|
|
@@ -89,39 +88,79 @@ var SocialPublisherWorkspaceClient = class {
|
|
|
89
88
|
* Update workspace with optional image upload
|
|
90
89
|
* @param id - Workspace ID
|
|
91
90
|
* @param data - Workspace data
|
|
91
|
+
* @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.
|
|
92
92
|
* @param logo - Optional new image file (File or Blob)
|
|
93
|
-
* @returns
|
|
93
|
+
* @returns `{ _id, __v }`, `__v` being the new version
|
|
94
94
|
*
|
|
95
95
|
* @example
|
|
96
96
|
* ```typescript
|
|
97
97
|
* // Update without changing image
|
|
98
|
-
* await client.
|
|
98
|
+
* const ws = await client.get('workspace-id');
|
|
99
|
+
* await client.update('workspace-id', { name: 'New Name', description: 'New Description' }, ws.__v);
|
|
99
100
|
*
|
|
100
101
|
* // Update with new image
|
|
101
102
|
* const file = new File([imageBlob], 'new-logo.png', { type: 'image/png' });
|
|
102
103
|
* await client.update(
|
|
103
104
|
* 'workspace-id',
|
|
104
105
|
*/
|
|
105
|
-
async update(id, data, logo) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
async update(id, data, version, logo) {
|
|
107
|
+
core.assertVersion(version);
|
|
108
|
+
const response = await this.http.put(
|
|
109
|
+
`${this.basePath}/${encodeURIComponent(id)}`,
|
|
110
|
+
{
|
|
111
|
+
...data,
|
|
112
|
+
hasImage: !!logo
|
|
113
|
+
},
|
|
114
|
+
{ version }
|
|
115
|
+
);
|
|
110
116
|
if (logo && response.result?.uploadImageConfig) {
|
|
111
117
|
await core.uploadToR2(response.result.uploadImageConfig.uploadUrl, logo, {
|
|
112
118
|
contentType: logo instanceof File ? logo.type : "image/png"
|
|
113
119
|
});
|
|
114
120
|
}
|
|
121
|
+
return { _id: response.result?.workspaceId ?? id, __v: response.version };
|
|
115
122
|
}
|
|
116
123
|
/**
|
|
117
124
|
* Delete workspace
|
|
118
125
|
* @param id - Workspace ID
|
|
126
|
+
* @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.
|
|
119
127
|
*/
|
|
120
|
-
async delete(id) {
|
|
121
|
-
|
|
128
|
+
async delete(id, version) {
|
|
129
|
+
core.assertVersion(version);
|
|
130
|
+
await this.http.delete(`${this.basePath}/${encodeURIComponent(id)}`, { version });
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// src/social-publisher-account.client.ts
|
|
135
|
+
var SocialPublisherAccountClient = class {
|
|
136
|
+
constructor(http) {
|
|
137
|
+
this.basePath = "/api/social-publisher-account";
|
|
138
|
+
this.http = http;
|
|
139
|
+
}
|
|
140
|
+
/** List connected accounts, filtered by platform, status or name. */
|
|
141
|
+
async list(params, pagination) {
|
|
142
|
+
const response = await this.http.get(this.basePath, {
|
|
143
|
+
params: { ...params, ...pagination }
|
|
144
|
+
});
|
|
145
|
+
return response.result;
|
|
146
|
+
}
|
|
147
|
+
/** Look accounts up by name, optionally on one platform. One page, no cursor (`pageSize` defaults to 10). */
|
|
148
|
+
async lookup(term, platform, pageSize) {
|
|
149
|
+
const params = {};
|
|
150
|
+
if (term) params.term = term;
|
|
151
|
+
if (platform) params.platform = platform;
|
|
152
|
+
if (pageSize) params.pageSize = pageSize;
|
|
153
|
+
const response = await this.http.get(`${this.basePath}/lookup`, { params });
|
|
154
|
+
return response.result || [];
|
|
155
|
+
}
|
|
156
|
+
/** One account's details. */
|
|
157
|
+
async get(id) {
|
|
158
|
+
const response = await this.http.get(`${this.basePath}/${encodeURIComponent(id)}`);
|
|
159
|
+
return response.result;
|
|
122
160
|
}
|
|
123
161
|
};
|
|
124
162
|
|
|
163
|
+
exports.SocialPublisherAccountClient = SocialPublisherAccountClient;
|
|
125
164
|
exports.SocialPublisherWorkspaceClient = SocialPublisherWorkspaceClient;
|
|
126
165
|
//# sourceMappingURL=index.js.map
|
|
127
166
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/social-publisher-workspace.client.ts"],"names":["uploadToR2"],"mappings":";;;;;AAgBO,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,QA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W,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAA8B,GAAG,IAAA,CAAK,QAAQ,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA,EAAI;AAAA,MACvF,GAAG,IAAA;AAAA,MACH,QAAA,EAAU,CAAC,CAAC;AAAA,KACb,CAAA;AAGD,IAAA,IAAI,IAAA,IAAQ,QAAA,CAAS,MAAA,EAAQ,iBAAA,EAAmB;AAC9C,MAAA,MAAMA,eAAA,CAAW,QAAA,CAAS,MAAA,CAAO,iBAAA,CAAkB,WAAW,IAAA,EAAM;AAAA,QAClE,WAAA,EAAa,IAAA,YAAgB,IAAA,GAAO,IAAA,CAAK,IAAA,GAAO;AAAA,OACjD,CAAA;AAAA,IACH;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,OAAO,EAAA,EAA2B;AACtC,IAAA,MAAM,IAAA,CAAK,KAAK,MAAA,CAAiC,CAAA,EAAG,KAAK,QAAQ,CAAA,CAAA,EAAI,EAAE,CAAA,CAAE,CAAA;AAAA,EAC3E;AACF","file":"index.js","sourcesContent":["import { HttpClient, IPaginationParams, uploadToR2 } from \"@posty5/core\";\nimport {\n ICreateWorkspaceRequest,\n IUpdateWorkspaceRequest,\n IListParams,\n ISearchWorkspaceResponse,\n ICreateWorkspaceResponse,\n IUpdateWorkspaceResponse,\n IDeleteWorkspaceResponse,\n IWorkspaceResponse,\n IWorkspaceForNewPostResponse,\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: \"npmPackage\",\n });\n\n // Step 2: Upload image if provided\n if (logo && response.result?.uploadImageConfig) {\n var res = await uploadToR2(response.result.uploadImageConfig.uploadUrl, logo, {\n contentType: /*logo instanceof File ? logo.type : 'image/png'*/ \"image/png\",\n });\n console.log(res);\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 logo - Optional new image file (File or Blob)\n * @returns Workspace details\n *\n * @example\n * ```typescript\n * // Update without changing image\n * await client.update('workspace-id', { name: 'New Name', description: 'New Description' });\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, logo?: File | Blob): Promise<void> {\n // Step 1: Update workspace and get upload config\n const response = await this.http.put<IUpdateWorkspaceResponse>(`${this.basePath}/${id}`, {\n ...data,\n hasImage: !!logo,\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\n /**\n * Delete workspace\n * @param id - Workspace ID\n */\n async delete(id: string): Promise<void> {\n await this.http.delete<IDeleteWorkspaceResponse>(`${this.basePath}/${id}`);\n }\n}\n"]}
|
|
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,CAAA,EAAG,IAAA,CAAK,QAAQ,CAAA,CAAA,EAAI,kBAAA,CAAmB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IAAA,CAAK,MAAA,EAAmC,UAAA,EAAqF;AACjI,IAAA,MAAM,WAAW,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAAgD,KAAK,QAAA,EAAU;AAAA,MAC9F,MAAA,EAAQ,EAAE,GAAG,MAAA,EAAQ,GAAG,UAAA;AAAW,KACpC,CAAA;AACD,IAAA,OAAO,QAAA,CAAS,MAAA;AAAA,EAClB;AAAA;AAAA,EAGA,MAAM,MAAA,CAAO,IAAA,EAAe,QAAA,EAAkC,QAAA,EAAwD;AACpH,IAAA,MAAM,SAA0C,EAAC;AACjD,IAAA,IAAI,IAAA,SAAa,IAAA,GAAO,IAAA;AACxB,IAAA,IAAI,QAAA,SAAiB,QAAA,GAAW,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,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} 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","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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { uploadToR2 } from '@posty5/core';
|
|
1
|
+
import { uploadToR2, assertVersion } from '@posty5/core';
|
|
2
2
|
|
|
3
3
|
// src/social-publisher-workspace.client.ts
|
|
4
4
|
var SocialPublisherWorkspaceClient = class {
|
|
@@ -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
|
/**
|
|
@@ -70,16 +70,15 @@ var SocialPublisherWorkspaceClient = class {
|
|
|
70
70
|
const response = await this.http.post(this.basePath, {
|
|
71
71
|
...data,
|
|
72
72
|
hasImage: !!logo,
|
|
73
|
-
createdFrom:
|
|
73
|
+
createdFrom: this.http.createdFrom
|
|
74
74
|
});
|
|
75
75
|
if (logo && response.result?.uploadImageConfig) {
|
|
76
|
-
|
|
76
|
+
await uploadToR2(response.result.uploadImageConfig.uploadUrl, logo, {
|
|
77
77
|
contentType: (
|
|
78
78
|
/*logo instanceof File ? logo.type : 'image/png'*/
|
|
79
79
|
"image/png"
|
|
80
80
|
)
|
|
81
81
|
});
|
|
82
|
-
console.log(res);
|
|
83
82
|
}
|
|
84
83
|
return response.result?.workspaceId;
|
|
85
84
|
}
|
|
@@ -87,39 +86,78 @@ var SocialPublisherWorkspaceClient = class {
|
|
|
87
86
|
* Update workspace with optional image upload
|
|
88
87
|
* @param id - Workspace ID
|
|
89
88
|
* @param data - Workspace data
|
|
89
|
+
* @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.
|
|
90
90
|
* @param logo - Optional new image file (File or Blob)
|
|
91
|
-
* @returns
|
|
91
|
+
* @returns `{ _id, __v }`, `__v` being the new version
|
|
92
92
|
*
|
|
93
93
|
* @example
|
|
94
94
|
* ```typescript
|
|
95
95
|
* // Update without changing image
|
|
96
|
-
* await client.
|
|
96
|
+
* const ws = await client.get('workspace-id');
|
|
97
|
+
* await client.update('workspace-id', { name: 'New Name', description: 'New Description' }, ws.__v);
|
|
97
98
|
*
|
|
98
99
|
* // Update with new image
|
|
99
100
|
* const file = new File([imageBlob], 'new-logo.png', { type: 'image/png' });
|
|
100
101
|
* await client.update(
|
|
101
102
|
* 'workspace-id',
|
|
102
103
|
*/
|
|
103
|
-
async update(id, data, logo) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
async update(id, data, version, logo) {
|
|
105
|
+
assertVersion(version);
|
|
106
|
+
const response = await this.http.put(
|
|
107
|
+
`${this.basePath}/${encodeURIComponent(id)}`,
|
|
108
|
+
{
|
|
109
|
+
...data,
|
|
110
|
+
hasImage: !!logo
|
|
111
|
+
},
|
|
112
|
+
{ version }
|
|
113
|
+
);
|
|
108
114
|
if (logo && response.result?.uploadImageConfig) {
|
|
109
115
|
await uploadToR2(response.result.uploadImageConfig.uploadUrl, logo, {
|
|
110
116
|
contentType: logo instanceof File ? logo.type : "image/png"
|
|
111
117
|
});
|
|
112
118
|
}
|
|
119
|
+
return { _id: response.result?.workspaceId ?? id, __v: response.version };
|
|
113
120
|
}
|
|
114
121
|
/**
|
|
115
122
|
* Delete workspace
|
|
116
123
|
* @param id - Workspace ID
|
|
124
|
+
* @param version - The workspace's `__v` as you read it. A stale one throws `ConflictError`.
|
|
117
125
|
*/
|
|
118
|
-
async delete(id) {
|
|
119
|
-
|
|
126
|
+
async delete(id, version) {
|
|
127
|
+
assertVersion(version);
|
|
128
|
+
await this.http.delete(`${this.basePath}/${encodeURIComponent(id)}`, { version });
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// src/social-publisher-account.client.ts
|
|
133
|
+
var SocialPublisherAccountClient = class {
|
|
134
|
+
constructor(http) {
|
|
135
|
+
this.basePath = "/api/social-publisher-account";
|
|
136
|
+
this.http = http;
|
|
137
|
+
}
|
|
138
|
+
/** List connected accounts, filtered by platform, status or name. */
|
|
139
|
+
async list(params, pagination) {
|
|
140
|
+
const response = await this.http.get(this.basePath, {
|
|
141
|
+
params: { ...params, ...pagination }
|
|
142
|
+
});
|
|
143
|
+
return response.result;
|
|
144
|
+
}
|
|
145
|
+
/** Look accounts up by name, optionally on one platform. One page, no cursor (`pageSize` defaults to 10). */
|
|
146
|
+
async lookup(term, platform, pageSize) {
|
|
147
|
+
const params = {};
|
|
148
|
+
if (term) params.term = term;
|
|
149
|
+
if (platform) params.platform = platform;
|
|
150
|
+
if (pageSize) params.pageSize = pageSize;
|
|
151
|
+
const response = await this.http.get(`${this.basePath}/lookup`, { params });
|
|
152
|
+
return response.result || [];
|
|
153
|
+
}
|
|
154
|
+
/** One account's details. */
|
|
155
|
+
async get(id) {
|
|
156
|
+
const response = await this.http.get(`${this.basePath}/${encodeURIComponent(id)}`);
|
|
157
|
+
return response.result;
|
|
120
158
|
}
|
|
121
159
|
};
|
|
122
160
|
|
|
123
|
-
export { SocialPublisherWorkspaceClient };
|
|
161
|
+
export { SocialPublisherAccountClient, SocialPublisherWorkspaceClient };
|
|
124
162
|
//# sourceMappingURL=index.mjs.map
|
|
125
163
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/social-publisher-workspace.client.ts"],"names":[],"mappings":";;;AAgBO,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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A;AAAA,OACjE,CAAA;AACD,MAAA,OAAA,CAAQ,IAAI,GAAG,CAAA;AAAA,IACjB;AAEA,IAAA,OAAO,SAAS,MAAA,EAAQ,WAAA;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBA,MAAM,MAAA,CAAO,EAAA,EAAY,IAAA,EAA+B,IAAA,EAAmC;AAEzF,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,GAAA,CAA8B,GAAG,IAAA,CAAK,QAAQ,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA,EAAI;AAAA,MACvF,GAAG,IAAA;AAAA,MACH,QAAA,EAAU,CAAC,CAAC;AAAA,KACb,CAAA;AAGD,IAAA,IAAI,IAAA,IAAQ,QAAA,CAAS,MAAA,EAAQ,iBAAA,EAAmB;AAC9C,MAAA,MAAM,UAAA,CAAW,QAAA,CAAS,MAAA,CAAO,iBAAA,CAAkB,WAAW,IAAA,EAAM;AAAA,QAClE,WAAA,EAAa,IAAA,YAAgB,IAAA,GAAO,IAAA,CAAK,IAAA,GAAO;AAAA,OACjD,CAAA;AAAA,IACH;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,OAAO,EAAA,EAA2B;AACtC,IAAA,MAAM,IAAA,CAAK,KAAK,MAAA,CAAiC,CAAA,EAAG,KAAK,QAAQ,CAAA,CAAA,EAAI,EAAE,CAAA,CAAE,CAAA;AAAA,EAC3E;AACF","file":"index.mjs","sourcesContent":["import { HttpClient, IPaginationParams, uploadToR2 } from \"@posty5/core\";\nimport {\n ICreateWorkspaceRequest,\n IUpdateWorkspaceRequest,\n IListParams,\n ISearchWorkspaceResponse,\n ICreateWorkspaceResponse,\n IUpdateWorkspaceResponse,\n IDeleteWorkspaceResponse,\n IWorkspaceResponse,\n IWorkspaceForNewPostResponse,\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: \"npmPackage\",\n });\n\n // Step 2: Upload image if provided\n if (logo && response.result?.uploadImageConfig) {\n var res = await uploadToR2(response.result.uploadImageConfig.uploadUrl, logo, {\n contentType: /*logo instanceof File ? logo.type : 'image/png'*/ \"image/png\",\n });\n console.log(res);\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 logo - Optional new image file (File or Blob)\n * @returns Workspace details\n *\n * @example\n * ```typescript\n * // Update without changing image\n * await client.update('workspace-id', { name: 'New Name', description: 'New Description' });\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, logo?: File | Blob): Promise<void> {\n // Step 1: Update workspace and get upload config\n const response = await this.http.put<IUpdateWorkspaceResponse>(`${this.basePath}/${id}`, {\n ...data,\n hasImage: !!logo,\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\n /**\n * Delete workspace\n * @param id - Workspace ID\n */\n async delete(id: string): Promise<void> {\n await this.http.delete<IDeleteWorkspaceResponse>(`${this.basePath}/${id}`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/social-publisher-workspace.client.ts","../src/social-publisher-account.client.ts"],"names":[],"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,MAA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;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} 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","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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posty5/social-publisher-workspace",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Social Publisher Organization management SDK for Posty5 API",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"author": "Posty5",
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@posty5/core": "^
|
|
48
|
+
"@posty5/core": "^5.0.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@posty5/core": "file:../posty5-core",
|