@thisux/dunsocial-sdk 0.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.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +168 -0
  3. package/dist/client.d.ts +39 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +188 -0
  6. package/dist/errors.d.ts +21 -0
  7. package/dist/errors.d.ts.map +1 -0
  8. package/dist/errors.js +72 -0
  9. package/dist/index.d.ts +28 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +32 -0
  12. package/dist/media-limits.d.ts +16 -0
  13. package/dist/media-limits.d.ts.map +1 -0
  14. package/dist/media-limits.js +49 -0
  15. package/dist/pagination.d.ts +4 -0
  16. package/dist/pagination.d.ts.map +1 -0
  17. package/dist/pagination.js +35 -0
  18. package/dist/resources/accounts.d.ts +22 -0
  19. package/dist/resources/accounts.d.ts.map +1 -0
  20. package/dist/resources/accounts.js +27 -0
  21. package/dist/resources/drafts.d.ts +16 -0
  22. package/dist/resources/drafts.d.ts.map +1 -0
  23. package/dist/resources/drafts.js +46 -0
  24. package/dist/resources/media.d.ts +15 -0
  25. package/dist/resources/media.d.ts.map +1 -0
  26. package/dist/resources/media.js +41 -0
  27. package/dist/resources/memory.d.ts +25 -0
  28. package/dist/resources/memory.d.ts.map +1 -0
  29. package/dist/resources/memory.js +40 -0
  30. package/dist/resources/personalization.d.ts +11 -0
  31. package/dist/resources/personalization.d.ts.map +1 -0
  32. package/dist/resources/personalization.js +22 -0
  33. package/dist/resources/posts.d.ts +27 -0
  34. package/dist/resources/posts.d.ts.map +1 -0
  35. package/dist/resources/posts.js +114 -0
  36. package/dist/resources/workspaces.d.ts +9 -0
  37. package/dist/resources/workspaces.d.ts.map +1 -0
  38. package/dist/resources/workspaces.js +13 -0
  39. package/dist/types.d.ts +205 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/types.js +1 -0
  42. package/dist/version.d.ts +2 -0
  43. package/dist/version.d.ts.map +1 -0
  44. package/dist/version.js +1 -0
  45. package/dist/webhooks.d.ts +3 -0
  46. package/dist/webhooks.d.ts.map +1 -0
  47. package/dist/webhooks.js +62 -0
  48. package/package.json +53 -0
@@ -0,0 +1,35 @@
1
+ export function asPage(data) {
2
+ if (Array.isArray(data)) {
3
+ return {
4
+ items: data,
5
+ total: data.length,
6
+ limit: data.length,
7
+ offset: 0,
8
+ hasMore: false
9
+ };
10
+ }
11
+ const record = data && typeof data === 'object' ? data : {};
12
+ const items = Array.isArray(record.items)
13
+ ? record.items
14
+ : Array.isArray(record.data)
15
+ ? record.data
16
+ : [];
17
+ return {
18
+ items,
19
+ total: typeof record.total === 'number' ? record.total : items.length,
20
+ limit: typeof record.limit === 'number' ? record.limit : items.length,
21
+ offset: typeof record.offset === 'number' ? record.offset : 0,
22
+ hasMore: Boolean(record.hasMore)
23
+ };
24
+ }
25
+ export async function* iteratePages(fetchPage, pageSize = 50) {
26
+ let offset = 0;
27
+ for (;;) {
28
+ const page = await fetchPage(offset, pageSize);
29
+ for (const item of page.items)
30
+ yield item;
31
+ if (!page.hasMore || page.items.length === 0)
32
+ break;
33
+ offset = page.offset + page.items.length;
34
+ }
35
+ }
@@ -0,0 +1,22 @@
1
+ import type { HttpClient } from '../client';
2
+ import type { SocialAccount } from '../types';
3
+ export declare class Accounts {
4
+ private readonly http;
5
+ constructor(http: HttpClient);
6
+ list(query?: {
7
+ platform?: string;
8
+ }): Promise<SocialAccount[]>;
9
+ redditFlairs(subreddit: string): Promise<{
10
+ choices: Array<{
11
+ id: string;
12
+ text: string;
13
+ textEditable?: boolean;
14
+ }>;
15
+ }>;
16
+ redditRequirements(subreddit: string): Promise<{
17
+ is_flair_required?: boolean;
18
+ title_text_max_length?: number;
19
+ title_text_min_length?: number;
20
+ }>;
21
+ }
22
+ //# sourceMappingURL=accounts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/resources/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,qBAAa,QAAQ;IACR,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEvC,IAAI,CAAC,KAAK,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAWnE,YAAY,CAAC,SAAS,EAAE,MAAM;iBAEnB,KAAK,CAAC;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,YAAY,CAAC,EAAE,OAAO,CAAA;SAAE,CAAC;;IAOtE,kBAAkB,CAAC,SAAS,EAAE,MAAM;4BAEd,OAAO;gCACH,MAAM;gCACN,MAAM;;CAMhC"}
@@ -0,0 +1,27 @@
1
+ export class Accounts {
2
+ http;
3
+ constructor(http) {
4
+ this.http = http;
5
+ }
6
+ async list(query) {
7
+ const accounts = await this.http.get('/api/social-accounts', {
8
+ workspace: true
9
+ });
10
+ if (!query?.platform)
11
+ return accounts;
12
+ const needle = query.platform.toLowerCase();
13
+ return accounts.filter((account) => (account.providerName ?? '').toLowerCase().includes(needle));
14
+ }
15
+ redditFlairs(subreddit) {
16
+ return this.http.get('/api/social-accounts/reddit/flair-options', {
17
+ workspace: true,
18
+ query: { subreddit }
19
+ });
20
+ }
21
+ redditRequirements(subreddit) {
22
+ return this.http.get('/api/social-accounts/reddit/post-requirements', {
23
+ workspace: true,
24
+ query: { subreddit }
25
+ });
26
+ }
27
+ }
@@ -0,0 +1,16 @@
1
+ import type { HttpClient } from '../client';
2
+ import type { CreateDraftInput, Paginated } from '../types';
3
+ export declare class Drafts {
4
+ private readonly http;
5
+ constructor(http: HttpClient);
6
+ list(query?: {
7
+ limit?: number;
8
+ offset?: number;
9
+ }): Promise<Paginated<unknown>>;
10
+ iterate(pageSize?: number): AsyncGenerator<unknown, void, undefined>;
11
+ get(id: string): Promise<unknown>;
12
+ create(input: CreateDraftInput): Promise<unknown>;
13
+ update(id: string, input: Partial<CreateDraftInput>): Promise<unknown>;
14
+ delete(id: string): Promise<unknown>;
15
+ }
16
+ //# sourceMappingURL=drafts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drafts.d.ts","sourceRoot":"","sources":["../../src/resources/drafts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE5D,qBAAa,MAAM;IACN,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEvC,IAAI,CAAC,KAAK,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAQpF,OAAO,CAAC,QAAQ,SAAK;IAIrB,GAAG,CAAC,EAAE,EAAE,MAAM;IAId,MAAM,CAAC,KAAK,EAAE,gBAAgB;IAgB9B,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,gBAAgB,CAAC;IAiBnD,MAAM,CAAC,EAAE,EAAE,MAAM;CAGjB"}
@@ -0,0 +1,46 @@
1
+ import { asPage, iteratePages } from '../pagination';
2
+ export class Drafts {
3
+ http;
4
+ constructor(http) {
5
+ this.http = http;
6
+ }
7
+ async list(query) {
8
+ const data = await this.http.get('/api/drafts', {
9
+ workspace: true,
10
+ query: { limit: query?.limit ?? 50, offset: query?.offset ?? 0 }
11
+ });
12
+ return asPage(data);
13
+ }
14
+ iterate(pageSize = 50) {
15
+ return iteratePages((offset, limit) => this.list({ offset, limit }), pageSize);
16
+ }
17
+ get(id) {
18
+ return this.http.get(`/api/drafts/${id}`, { workspace: true });
19
+ }
20
+ create(input) {
21
+ return this.http.post('/api/drafts', {
22
+ content: input.content,
23
+ name: input.name,
24
+ socialAccountIds: input.socialAccountIds ?? [],
25
+ selectedPlatforms: input.selectedPlatforms ?? [],
26
+ mediaUrls: input.mediaIds ?? [],
27
+ platformContent: input.platformContent,
28
+ platformMedia: input.platformMedia
29
+ }, { workspace: true });
30
+ }
31
+ update(id, input) {
32
+ return this.http.patch(`/api/drafts/${id}`, {
33
+ id,
34
+ content: input.content,
35
+ name: input.name,
36
+ socialAccountIds: input.socialAccountIds,
37
+ selectedPlatforms: input.selectedPlatforms,
38
+ mediaUrls: input.mediaIds,
39
+ platformContent: input.platformContent,
40
+ platformMedia: input.platformMedia
41
+ }, { workspace: true });
42
+ }
43
+ delete(id) {
44
+ return this.http.delete(`/api/drafts/${id}`, undefined, { workspace: true });
45
+ }
46
+ }
@@ -0,0 +1,15 @@
1
+ import type { HttpClient } from '../client';
2
+ import type { MediaAsset, Paginated, UploadInput } from '../types';
3
+ export declare class Media {
4
+ private readonly http;
5
+ constructor(http: HttpClient);
6
+ list(query?: {
7
+ limit?: number;
8
+ offset?: number;
9
+ }): Promise<Paginated<MediaAsset>>;
10
+ iterate(pageSize?: number): AsyncGenerator<MediaAsset, void, undefined>;
11
+ get(id: string): Promise<MediaAsset>;
12
+ upload(input: UploadInput): Promise<MediaAsset>;
13
+ delete(id: string): Promise<unknown>;
14
+ }
15
+ //# sourceMappingURL=media.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../src/resources/media.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAI5C,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEnE,qBAAa,KAAK;IACL,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEvC,IAAI,CAAC,KAAK,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IAQvF,OAAO,CAAC,QAAQ,SAAK;IAIrB,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAI9B,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAgCrD,MAAM,CAAC,EAAE,EAAE,MAAM;CAGjB"}
@@ -0,0 +1,41 @@
1
+ import { DunSocialError } from '../errors';
2
+ import { byteLength, preflightMediaUpload } from '../media-limits';
3
+ import { asPage, iteratePages } from '../pagination';
4
+ export class Media {
5
+ http;
6
+ constructor(http) {
7
+ this.http = http;
8
+ }
9
+ async list(query) {
10
+ const data = await this.http.get('/api/media', {
11
+ workspace: true,
12
+ query: { limit: query?.limit ?? 50, offset: query?.offset ?? 0 }
13
+ });
14
+ return asPage(data);
15
+ }
16
+ iterate(pageSize = 50) {
17
+ return iteratePages((offset, limit) => this.list({ offset, limit }), pageSize);
18
+ }
19
+ get(id) {
20
+ return this.http.get(`/api/media/${id}`, { workspace: true });
21
+ }
22
+ async upload(input) {
23
+ const fileSize = byteLength(input.file);
24
+ const preflight = preflightMediaUpload({ mimeType: input.mimeType, fileSize });
25
+ if (!preflight.ok) {
26
+ throw new DunSocialError(preflight.message, { code: 'validation' });
27
+ }
28
+ const upload = await this.http.post('/api/media/upload-url', { filename: input.filename, mimeType: input.mimeType, fileSize }, { workspace: true });
29
+ await this.http.putBytes(upload.uploadUrl, input.file, input.mimeType);
30
+ return this.http.post('/api/media/complete', {
31
+ storageKey: upload.storageKey,
32
+ originalFilename: input.filename,
33
+ mimeType: input.mimeType,
34
+ fileSize,
35
+ altText: input.altText
36
+ }, { workspace: true });
37
+ }
38
+ delete(id) {
39
+ return this.http.delete(`/api/media/${id}`, undefined, { workspace: true });
40
+ }
41
+ }
@@ -0,0 +1,25 @@
1
+ import type { HttpClient } from '../client';
2
+ import type { CreateCollectionInput } from '../types';
3
+ export declare class Memory {
4
+ private readonly http;
5
+ constructor(http: HttpClient);
6
+ listCollections(): Promise<unknown>;
7
+ createCollection(input: CreateCollectionInput): Promise<unknown>;
8
+ getCollection(id: string): Promise<unknown>;
9
+ updateCollection(id: string, input: Partial<CreateCollectionInput>): Promise<unknown>;
10
+ deleteCollection(id: string): Promise<unknown>;
11
+ list(collectionId: string, query?: {
12
+ limit?: number;
13
+ }): Promise<unknown>;
14
+ save(input: {
15
+ collectionId: string;
16
+ text: string;
17
+ }): Promise<unknown>;
18
+ search(input: {
19
+ prompt: string;
20
+ collectionIds: string[];
21
+ topK?: number;
22
+ }): Promise<unknown>;
23
+ delete(id: string, collectionId: string): Promise<unknown>;
24
+ }
25
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/resources/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEtD,qBAAa,MAAM;IACN,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C,eAAe;IAIf,gBAAgB,CAAC,KAAK,EAAE,qBAAqB;IAY7C,aAAa,CAAC,EAAE,EAAE,MAAM;IAIxB,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,qBAAqB,CAAC;IAIlE,gBAAgB,CAAC,EAAE,EAAE,MAAM;IAI3B,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAOrD,IAAI,CAAC,KAAK,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;IAIlD,MAAM,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,EAAE,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE;IAQxE,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;CAGvC"}
@@ -0,0 +1,40 @@
1
+ export class Memory {
2
+ http;
3
+ constructor(http) {
4
+ this.http = http;
5
+ }
6
+ listCollections() {
7
+ return this.http.get('/api/memory/collections', { workspace: true });
8
+ }
9
+ createCollection(input) {
10
+ return this.http.post('/api/memory/collections', {
11
+ name: input.name,
12
+ color: input.color ?? 'blue',
13
+ isPrivate: input.isPrivate ?? false
14
+ }, { workspace: true });
15
+ }
16
+ getCollection(id) {
17
+ return this.http.get(`/api/memory/collections/${id}`, { workspace: true });
18
+ }
19
+ updateCollection(id, input) {
20
+ return this.http.patch(`/api/memory/collections/${id}`, input, { workspace: true });
21
+ }
22
+ deleteCollection(id) {
23
+ return this.http.delete(`/api/memory/collections/${id}`, undefined, { workspace: true });
24
+ }
25
+ list(collectionId, query) {
26
+ return this.http.get('/api/memory', {
27
+ workspace: true,
28
+ query: { collectionId, limit: query?.limit ?? 100 }
29
+ });
30
+ }
31
+ save(input) {
32
+ return this.http.post('/api/memory', input, { workspace: true });
33
+ }
34
+ search(input) {
35
+ return this.http.post('/api/memory/search', { prompt: input.prompt, collectionIds: input.collectionIds, topK: input.topK ?? 5 }, { workspace: true });
36
+ }
37
+ delete(id, collectionId) {
38
+ return this.http.delete(`/api/memory/${id}`, { collectionId, memoryId: id }, { workspace: true });
39
+ }
40
+ }
@@ -0,0 +1,11 @@
1
+ import type { HttpClient } from '../client';
2
+ import type { Personalization } from '../types';
3
+ export declare class PersonalizationResource {
4
+ private readonly http;
5
+ constructor(http: HttpClient);
6
+ private path;
7
+ get(workspaceId?: string): Promise<Personalization | null>;
8
+ set(input: Personalization, workspaceId?: string): Promise<Personalization | null>;
9
+ clear(workspaceId?: string): Promise<Personalization | null>;
10
+ }
11
+ //# sourceMappingURL=personalization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"personalization.d.ts","sourceRoot":"","sources":["../../src/resources/personalization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD,qBAAa,uBAAuB;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C,OAAO,CAAC,IAAI;IAIZ,GAAG,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAI1D,GAAG,CAAC,KAAK,EAAE,eAAe,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAMlF,KAAK,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;CAK5D"}
@@ -0,0 +1,22 @@
1
+ export class PersonalizationResource {
2
+ http;
3
+ constructor(http) {
4
+ this.http = http;
5
+ }
6
+ path(id) {
7
+ return `/api/workspaces/${id ?? this.http.requireWorkspace()}/ai-voice-settings`;
8
+ }
9
+ get(workspaceId) {
10
+ return this.http.get(this.path(workspaceId), { workspace: true });
11
+ }
12
+ set(input, workspaceId) {
13
+ return this.http.patch(this.path(workspaceId), input, {
14
+ workspace: true
15
+ });
16
+ }
17
+ clear(workspaceId) {
18
+ return this.http.patch(this.path(workspaceId), null, {
19
+ workspace: true
20
+ });
21
+ }
22
+ }
@@ -0,0 +1,27 @@
1
+ import type { HttpClient } from '../client';
2
+ import type { ListPostsQuery, Paginated, Post, PublishPostInput, PublishThreadInput, SchedulePostInput, ScheduleThreadInput, ValidatePostInput, ValidatePostResult } from '../types';
3
+ export declare class Posts {
4
+ private readonly http;
5
+ constructor(http: HttpClient);
6
+ list(query?: ListPostsQuery): Promise<Paginated<Post>>;
7
+ iterate(query?: Omit<ListPostsQuery, 'offset'>): AsyncGenerator<Post, void, undefined>;
8
+ get(id: string): Promise<Post>;
9
+ validate(input: ValidatePostInput): Promise<ValidatePostResult>;
10
+ schedule(input: SchedulePostInput): Promise<Post[]>;
11
+ publish(input: PublishPostInput): Promise<Post[]>;
12
+ reschedule(id: string, input: {
13
+ scheduledAt: Date | string;
14
+ content?: string;
15
+ mediaIds?: string[];
16
+ }): Promise<Post>;
17
+ cancel(id: string): Promise<Post>;
18
+ delete(id: string): Promise<unknown>;
19
+ scheduleThread(input: ScheduleThreadInput): Promise<unknown>;
20
+ publishThread(input: PublishThreadInput): Promise<unknown>;
21
+ xCapUsage(): Promise<unknown>;
22
+ wait(id: string, options?: {
23
+ timeoutMs?: number;
24
+ pollMs?: number;
25
+ }): Promise<Post>;
26
+ }
27
+ //# sourceMappingURL=posts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"posts.d.ts","sourceRoot":"","sources":["../../src/resources/posts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAG5C,OAAO,KAAK,EACX,cAAc,EACd,SAAS,EACT,IAAI,EACJ,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,MAAM,UAAU,CAAC;AAIlB,qBAAa,KAAK;IACL,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEvC,IAAI,CAAC,KAAK,GAAE,cAAmB,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAchE,OAAO,CAAC,KAAK,GAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAM,GAAG,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC;IAO1F,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxB,QAAQ,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAerE,QAAQ,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAQnD,OAAO,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAQjD,UAAU,CACT,EAAE,EAAE,MAAM,EACV,KAAK,EAAE;QAAE,WAAW,EAAE,IAAI,GAAG,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAC1E,OAAO,CAAC,IAAI,CAAC;IAYhB,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIpC,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;IAgB5D,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;IAe1D,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAIvB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAyBxF"}
@@ -0,0 +1,114 @@
1
+ import { DunSocialError } from '../errors';
2
+ import { asPage, iteratePages } from '../pagination';
3
+ const TERMINAL = new Set(['published', 'failed', 'cancelled']);
4
+ export class Posts {
5
+ http;
6
+ constructor(http) {
7
+ this.http = http;
8
+ }
9
+ async list(query = {}) {
10
+ const data = await this.http.get('/api/posts', {
11
+ workspace: true,
12
+ query: {
13
+ status: query.status,
14
+ socialAccountId: query.socialAccountId,
15
+ groupId: query.groupId,
16
+ limit: query.limit ?? 50,
17
+ offset: query.offset ?? 0
18
+ }
19
+ });
20
+ return asPage(data);
21
+ }
22
+ iterate(query = {}) {
23
+ return iteratePages((offset, limit) => this.list({ ...query, offset, limit }), query.limit ?? 50);
24
+ }
25
+ get(id) {
26
+ return this.http.get(`/api/posts/${id}`, { workspace: true });
27
+ }
28
+ async validate(input) {
29
+ const result = await this.http.post('/api/posts/validate', toPostBody(input), { workspace: true });
30
+ if (input.throwOnInvalid && !result.valid) {
31
+ throw new DunSocialError(result.issues.map((issue) => issue.message).join('; ') || 'Post validation failed', { code: 'validation', details: result });
32
+ }
33
+ return result;
34
+ }
35
+ schedule(input) {
36
+ return this.http.post('/api/posts/schedule', { ...toPostBody(input), scheduledAt: toIso(input.scheduledAt) }, { workspace: true });
37
+ }
38
+ publish(input) {
39
+ return this.http.post('/api/posts/publish-now', { ...toPostBody(input), naturalPosting: input.naturalPosting ?? false }, { workspace: true });
40
+ }
41
+ reschedule(id, input) {
42
+ return this.http.post(`/api/posts/${id}/reschedule`, {
43
+ scheduledAt: toIso(input.scheduledAt),
44
+ content: input.content,
45
+ mediaUrls: input.mediaIds
46
+ }, { workspace: true });
47
+ }
48
+ cancel(id) {
49
+ return this.http.post(`/api/posts/${id}/cancel`, undefined, { workspace: true });
50
+ }
51
+ delete(id) {
52
+ return this.http.delete(`/api/posts/${id}`, undefined, { workspace: true });
53
+ }
54
+ scheduleThread(input) {
55
+ return this.http.post('/api/posts/schedule-thread', {
56
+ socialAccountId: input.socialAccountId,
57
+ scheduledAt: toIso(input.scheduledAt),
58
+ metadata: input.metadata ?? {},
59
+ tweets: input.tweets.map((tweet) => ({
60
+ content: tweet.content,
61
+ mediaUrls: tweet.mediaIds ?? []
62
+ }))
63
+ }, { workspace: true });
64
+ }
65
+ publishThread(input) {
66
+ return this.http.post('/api/posts/publish-thread-now', {
67
+ socialAccountId: input.socialAccountId,
68
+ metadata: input.metadata ?? {},
69
+ tweets: input.tweets.map((tweet) => ({
70
+ content: tweet.content,
71
+ mediaUrls: tweet.mediaIds ?? []
72
+ }))
73
+ }, { workspace: true });
74
+ }
75
+ xCapUsage() {
76
+ return this.http.get('/api/posts/x-cap-usage', { workspace: true });
77
+ }
78
+ async wait(id, options) {
79
+ const timeoutMs = options?.timeoutMs ?? 120_000;
80
+ const deadline = Date.now() + timeoutMs;
81
+ let delay = options?.pollMs ?? 1500;
82
+ for (;;) {
83
+ if (Date.now() > deadline) {
84
+ throw new DunSocialError(`Timed out waiting for publish after ${timeoutMs}ms. Still pending: ${id}`, { code: 'timeout', details: { pending: [id] } });
85
+ }
86
+ const current = await this.get(id);
87
+ if (current.status && TERMINAL.has(current.status)) {
88
+ if (current.status === 'failed') {
89
+ throw new DunSocialError(current.error || 'publish failed', {
90
+ code: 'validation',
91
+ details: { posts: [current] }
92
+ });
93
+ }
94
+ return current;
95
+ }
96
+ await sleep(delay);
97
+ delay = Math.min(delay * 1.4, 8000);
98
+ }
99
+ }
100
+ }
101
+ function toPostBody(input) {
102
+ return {
103
+ content: input.content,
104
+ socialAccountIds: input.socialAccountIds,
105
+ mediaUrls: input.mediaIds ?? [],
106
+ metadata: input.metadata ?? {}
107
+ };
108
+ }
109
+ function toIso(value) {
110
+ return value instanceof Date ? value.toISOString() : value;
111
+ }
112
+ function sleep(ms) {
113
+ return new Promise((resolve) => setTimeout(resolve, ms));
114
+ }
@@ -0,0 +1,9 @@
1
+ import type { HttpClient } from '../client';
2
+ import type { Workspace } from '../types';
3
+ export declare class Workspaces {
4
+ private readonly http;
5
+ constructor(http: HttpClient);
6
+ list(): Promise<Workspace[]>;
7
+ get(id?: string): Promise<Workspace>;
8
+ }
9
+ //# sourceMappingURL=workspaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspaces.d.ts","sourceRoot":"","sources":["../../src/resources/workspaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,qBAAa,UAAU;IACV,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C,IAAI,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAI5B,GAAG,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;CAIpC"}
@@ -0,0 +1,13 @@
1
+ export class Workspaces {
2
+ http;
3
+ constructor(http) {
4
+ this.http = http;
5
+ }
6
+ list() {
7
+ return this.http.get('/api/workspaces');
8
+ }
9
+ get(id) {
10
+ const workspaceId = id ?? this.http.requireWorkspace();
11
+ return this.http.get(`/api/workspaces/${workspaceId}`, { workspace: true });
12
+ }
13
+ }