@vibiz/app 0.3.20 → 0.3.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@
9
9
  * const { url } = await vibiz.files.upload(bytes, { name: 'avatar.png' });
10
10
  * await vibiz.contacts.upsert({ email, first_name, lists: ['Users'] }); // newsletters, onboarding
11
11
  * await vibiz.contacts.track(email, 'upgraded', { plan: 'pro' }); // starts automations
12
+ * const { url } = await vibiz.user(userId).social.connect({ platform: 'threads', return_url });
12
13
  *
13
14
  * The key (`VIBIZ_APP_KEY`, `vz_app_…`) belongs to one project and one
14
15
  * environment. It is a server secret: this client refuses to run in a
@@ -394,6 +395,86 @@ export interface PhoneCall {
394
395
  price_usd: number;
395
396
  created_at: string;
396
397
  }
398
+ /** A platform a user can connect (docs: social). */
399
+ export type SocialPlatform = 'instagram' | 'facebook' | 'tiktok' | 'linkedin' | 'x' | 'youtube' | 'pinterest' | 'threads' | 'bluesky' | 'reddit' | 'google_business' | 'telegram';
400
+ /** One of your user's own social accounts (`vibiz.user(id).social`). */
401
+ export interface SocialUserAccount {
402
+ object: 'social_account';
403
+ id: string;
404
+ project_id: string;
405
+ environment: 'production' | 'development';
406
+ platform: SocialPlatform;
407
+ kind: 'social';
408
+ status: 'connected' | 'needs_reconnect' | 'disconnected';
409
+ username: string | null;
410
+ display_name: string | null;
411
+ avatar_url: string | null;
412
+ profile_url: string | null;
413
+ details: Record<string, unknown>;
414
+ connected_at: string;
415
+ /** Your user's id, as you sent it. */
416
+ user_id: string;
417
+ }
418
+ /** Where to send your user to connect an account (`social.connect`). */
419
+ export interface SocialConnectLink {
420
+ object: 'social_connect_link';
421
+ platform: SocialPlatform;
422
+ environment: 'production' | 'development';
423
+ /**
424
+ * Production: a thelastapi link (one hour, single use) that goes straight to the
425
+ * platform's sign-in, then back to your `return_url` with `?account_id=…&status=connected`
426
+ * (or `status=failed&error=…`). Development: your `return_url` with the test account already.
427
+ */
428
+ url: string;
429
+ expires_at: string;
430
+ /** Development only: the test account, made at once. */
431
+ account?: SocialUserAccount;
432
+ }
433
+ export interface SocialUserPostInput {
434
+ text?: string;
435
+ /** Your user's own account ids (`sacc_…`), 1–20. */
436
+ account_ids: string[];
437
+ /** Any public https URL, or one from `social.upload`. */
438
+ media?: Array<{
439
+ url: string;
440
+ type?: 'image' | 'video' | 'gif' | 'document';
441
+ }>;
442
+ /** Per-platform options, keyed by platform (`youtube: { title }`) or by account id. */
443
+ options?: Record<string, Record<string, unknown>>;
444
+ /** ISO time, at least a minute and at most a year ahead; leave out to publish now. */
445
+ schedule_at?: string | null;
446
+ timezone?: string | null;
447
+ draft?: boolean;
448
+ }
449
+ export interface SocialUserPost {
450
+ object: 'social_post';
451
+ id: string;
452
+ project_id: string;
453
+ environment: 'production' | 'development';
454
+ status: 'draft' | 'scheduled' | 'publishing' | 'published' | 'partial' | 'failed' | 'cancelled';
455
+ text: string;
456
+ media: Array<{
457
+ type: 'image' | 'video' | 'gif' | 'document';
458
+ url: string;
459
+ }>;
460
+ targets: Array<{
461
+ account_id: string;
462
+ platform: SocialPlatform;
463
+ username: string | null;
464
+ status: 'pending' | 'publishing' | 'published' | 'failed' | 'cancelled';
465
+ url: string | null;
466
+ error: string | null;
467
+ published_at: string | null;
468
+ options: Record<string, unknown>;
469
+ }>;
470
+ scheduled_for: string | null;
471
+ timezone: string | null;
472
+ published_at: string | null;
473
+ approval: null;
474
+ created_at: string;
475
+ updated_at: string;
476
+ user_id: string;
477
+ }
397
478
  export declare class VibizApp {
398
479
  private readonly options;
399
480
  private loaded;
@@ -641,6 +722,65 @@ export declare class VibizApp {
641
722
  deleted: true;
642
723
  }>;
643
724
  };
725
+ /**
726
+ * Your users' own social accounts (docs: social ▸ "Social for your app's
727
+ * users"), on `vibiz.user(id)`: they connect Threads, Bluesky, Instagram…
728
+ * with no thelastapi sign-in, and post or schedule to them with no owner
729
+ * approval. Each user sees only their own accounts and posts. A development
730
+ * key connects test accounts at once and posts nowhere.
731
+ */
732
+ get social(): {
733
+ /** A link for your user to connect an account; `return_url` must be on your app's own address. */
734
+ connect: (input: {
735
+ platform: SocialPlatform;
736
+ return_url: string;
737
+ }) => Promise<SocialConnectLink>;
738
+ accounts: () => Promise<{
739
+ object: "list";
740
+ data: SocialUserAccount[];
741
+ has_more: boolean;
742
+ }>;
743
+ disconnect: (accountId: string) => Promise<SocialUserAccount>;
744
+ /** `post(input)` publishes, schedules or drafts; `post(id)` reads one back. */
745
+ post: {
746
+ (input: SocialUserPostInput): Promise<SocialUserPost>;
747
+ (id: string): Promise<SocialUserPost>;
748
+ };
749
+ get: (id: string) => Promise<SocialUserPost>;
750
+ posts: (opts?: {
751
+ status?: SocialUserPost["status"] | SocialUserPost["status"][];
752
+ account?: string;
753
+ platform?: SocialPlatform;
754
+ from?: string;
755
+ to?: string;
756
+ cursor?: string;
757
+ limit?: number;
758
+ }) => Promise<{
759
+ object: "list";
760
+ data: SocialUserPost[];
761
+ has_more: boolean;
762
+ next_cursor: string | null;
763
+ }>;
764
+ /** Publish a draft now, or at `schedule_at`. */
765
+ publish: (id: string, opts?: {
766
+ schedule_at?: string | null;
767
+ timezone?: string | null;
768
+ }) => Promise<SocialUserPost>;
769
+ /** Cancel a draft or a scheduled post (a published one stays on the platforms). */
770
+ cancel: (id: string) => Promise<SocialUserPost>;
771
+ /** Upload an image or video (at most 512 MB) → `{url}` to put in `media`. */
772
+ upload: (file: Uint8Array | Blob, opts: {
773
+ name: string;
774
+ contentType?: string;
775
+ }) => Promise<{
776
+ object: "social_media";
777
+ url: string;
778
+ type: "image" | "video" | "gif" | "document";
779
+ content_type: string;
780
+ size: number;
781
+ environment: "production" | "development";
782
+ }>;
783
+ };
644
784
  /**
645
785
  * The project's contacts (docs: email ▸ Contacts): who gets its newsletters and
646
786
  * automations. Add users at signup, keep their properties current, and track
package/dist/index.js CHANGED
@@ -465,6 +465,64 @@ var VibizApp = class _VibizApp {
465
465
  { method: "DELETE" }
466
466
  )
467
467
  };
468
+ /**
469
+ * Your users' own social accounts (docs: social ▸ "Social for your app's
470
+ * users"), on `vibiz.user(id)`: they connect Threads, Bluesky, Instagram…
471
+ * with no thelastapi sign-in, and post or schedule to them with no owner
472
+ * approval. Each user sees only their own accounts and posts. A development
473
+ * key connects test accounts at once and posts nowhere.
474
+ */
475
+ get social() {
476
+ const user = this.options.user;
477
+ const base = () => {
478
+ if (!user) {
479
+ throw new VibizAppError(
480
+ 400,
481
+ "invalid_request",
482
+ "Social acts for one of your users: call it on vibiz.user(userId).social."
483
+ );
484
+ }
485
+ return `/app/social/users/${encodeURIComponent(user)}`;
486
+ };
487
+ const getPost = (id) => this.request(`${base()}/posts/${encodeURIComponent(id)}`);
488
+ const createPost = (input) => this.request(`${base()}/posts`, { body: input });
489
+ function post(arg) {
490
+ return typeof arg === "string" ? getPost(arg) : createPost(arg);
491
+ }
492
+ return {
493
+ /** A link for your user to connect an account; `return_url` must be on your app's own address. */
494
+ connect: (input) => this.request(`${base()}/connect`, { body: input }),
495
+ accounts: () => this.request(
496
+ `${base()}/accounts`
497
+ ),
498
+ disconnect: (accountId) => this.request(`${base()}/accounts/${encodeURIComponent(accountId)}`, {
499
+ method: "DELETE"
500
+ }),
501
+ /** `post(input)` publishes, schedules or drafts; `post(id)` reads one back. */
502
+ post,
503
+ get: getPost,
504
+ posts: (opts = {}) => this.request(
505
+ `${base()}/posts${query({ ...opts, status: Array.isArray(opts.status) ? opts.status.join(",") : opts.status })}`
506
+ ),
507
+ /** Publish a draft now, or at `schedule_at`. */
508
+ publish: (id, opts = {}) => this.request(`${base()}/posts/${encodeURIComponent(id)}/publish`, {
509
+ body: opts
510
+ }),
511
+ /** Cancel a draft or a scheduled post (a published one stays on the platforms). */
512
+ cancel: (id) => this.request(`${base()}/posts/${encodeURIComponent(id)}/cancel`, {
513
+ body: {}
514
+ }),
515
+ /** Upload an image or video (at most 512 MB) → `{url}` to put in `media`. */
516
+ upload: async (file, opts) => {
517
+ const raw = file instanceof Uint8Array ? file : new Uint8Array(await file.arrayBuffer());
518
+ const contentType = opts.contentType ?? (file instanceof Blob && file.type ? file.type : void 0);
519
+ return this.request(`${base()}/media${query({ filename: opts.name })}`, {
520
+ raw,
521
+ ...contentType ? { contentType } : {}
522
+ });
523
+ }
524
+ };
525
+ }
468
526
  /**
469
527
  * The project's contacts (docs: email ▸ Contacts): who gets its newsletters and
470
528
  * automations. Add users at signup, keep their properties current, and track
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibiz/app",
3
- "version": "0.3.20",
3
+ "version": "0.3.22",
4
4
  "description": "One key for your app: env, AI, email, actions and events from thelastapi.",
5
5
  "keywords": [
6
6
  "vibiz",