@happyvertical/smrt-social 0.61.4 → 0.61.6
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/AGENTS.md +1 -1
- package/README.md +43 -0
- package/dist/chunks/social-account-collection-B4PZKbUC.js +432 -0
- package/dist/chunks/social-account-collection-B4PZKbUC.js.map +1 -0
- package/dist/connect/flow.d.ts +62 -0
- package/dist/connect/flow.d.ts.map +1 -0
- package/dist/connect/index.d.ts +5 -0
- package/dist/connect/index.d.ts.map +1 -0
- package/dist/connect/registry.d.ts +6 -0
- package/dist/connect/registry.d.ts.map +1 -0
- package/dist/connect/types.d.ts +79 -0
- package/dist/connect/types.d.ts.map +1 -0
- package/dist/connect/x.d.ts +11 -0
- package/dist/connect/x.d.ts.map +1 -0
- package/dist/connect.d.ts +2 -0
- package/dist/connect.d.ts.map +1 -0
- package/dist/connect.js +250 -0
- package/dist/connect.js.map +1 -0
- package/dist/index.js +4 -425
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +21 -6
- package/dist/oauth-state.d.ts +5 -0
- package/dist/oauth-state.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +12 -5
- package/dist/smrt-knowledge.okf.md +3 -2
- package/package.json +13 -9
package/dist/index.js
CHANGED
|
@@ -1,429 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ObjectRegistry,
|
|
3
|
-
import { TenantScoped,
|
|
4
|
-
import { randomUUID } from "node:crypto";
|
|
5
|
-
import { SecretService } from "@happyvertical/smrt-secrets";
|
|
1
|
+
import { i as OAuthState, n as SocialAccount, r as OAuthStateCollection, t as SocialAccountCollection } from "./chunks/social-account-collection-B4PZKbUC.js";
|
|
2
|
+
import { ObjectRegistry, SmrtCollection, SmrtObject, SmrtRecipe, crossPackageRef, field, foreignKey, smrt } from "@happyvertical/smrt-core";
|
|
3
|
+
import { TenantScoped, tenantId } from "@happyvertical/smrt-tenancy";
|
|
6
4
|
//#region src/__smrt-register__.ts
|
|
7
|
-
ObjectRegistry.registerPackageManifest(JSON.parse(`{"version":"1.0.0","timestamp":0,"packageName":"@happyvertical/smrt-social","packageVersion":"0.61.4","objects":{"@happyvertical/smrt-social:OAuthStateCollection":{"name":"oauthstatecollection","className":"OAuthStateCollection","qualifiedName":"@happyvertical/smrt-social:OAuthStateCollection","collection":"oauthstates","filePath":"src/collections/oauth-state-collection.ts","packageName":"@happyvertical/smrt-social","fields":{},"methods":{"findByState":{"name":"findByState","async":true,"parameters":[{"name":"state","type":"string","optional":false}],"returnType":"Promise<OAuthState | null>","isStatic":false,"isPublic":true},"consume":{"name":"consume","async":true,"parameters":[{"name":"state","type":"OAuthState","optional":false}],"returnType":"Promise<boolean>","isStatic":false,"isPublic":true},"findExpired":{"name":"findExpired","async":true,"parameters":[{"name":"now","type":"Date","optional":true}],"returnType":"Promise<OAuthState[]>","isStatic":false,"isPublic":true},"deleteExpired":{"name":"deleteExpired","async":true,"parameters":[{"name":"now","type":"Date","optional":true}],"returnType":"Promise<number>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","delete"]},"mcp":false},"extends":"SmrtCollection","extendsTypeArg":"OAuthState","exportName":"OAuthStateCollection","collectionExportName":"OAuthStateCollectionCollection","collectionOf":"@happyvertical/smrt-social:OAuthState","inheritedExposure":["api","mcp"],"schema":{"tableName":"oauth_states","ddl":"CREATE TABLE IF NOT EXISTS \\"oauth_states\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"platform\\" TEXT DEFAULT 'youtube',\\n \\"state\\" TEXT DEFAULT '',\\n \\"code_verifier\\" TEXT,\\n \\"redirect_uri\\" TEXT DEFAULT '',\\n \\"scopes\\" JSON DEFAULT '[]',\\n \\"expires_at\\" TIMESTAMP,\\n \\"created_by_user_id\\" UUID,\\n \\"return_to\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"platform":{"type":"TEXT","notNull":false,"default":"youtube"},"state":{"type":"TEXT","notNull":false,"default":""},"code_verifier":{"type":"TEXT","notNull":false},"redirect_uri":{"type":"TEXT","notNull":false,"default":""},"scopes":{"type":"JSON","notNull":false,"default":[]},"expires_at":{"type":"TIMESTAMP","notNull":false},"created_by_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"return_to":{"type":"TEXT","notNull":false}},"indexes":[{"name":"oauth_states_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"oauth_states_meta_type_idx","columns":["_meta_type"]},{"name":"oauth_states_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"oauth_states_created_by_user_id_idx","columns":["created_by_user_id"]}],"version":"46b1e275"},"importPath":"@happyvertical/smrt-social"},"@happyvertical/smrt-social:SocialAccountCollection":{"name":"socialaccountcollection","className":"SocialAccountCollection","qualifiedName":"@happyvertical/smrt-social:SocialAccountCollection","collection":"socialaccounts","filePath":"src/collections/social-account-collection.ts","packageName":"@happyvertical/smrt-social","fields":{},"methods":{"findActive":{"name":"findActive","async":true,"parameters":[{"name":"platform","type":"SocialPlatformType","optional":true}],"returnType":"Promise<SocialAccount[]>","isStatic":false,"isPublic":true},"findReady":{"name":"findReady","async":true,"parameters":[{"name":"platform","type":"SocialPlatformType","optional":true}],"returnType":"Promise<SocialAccount[]>","isStatic":false,"isPublic":true},"findNeedsAttention":{"name":"findNeedsAttention","async":true,"parameters":[],"returnType":"Promise<SocialAccount[]>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","update","delete"]},"mcp":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"SocialAccount","exportName":"SocialAccountCollection","collectionExportName":"SocialAccountCollectionCollection","collectionOf":"@happyvertical/smrt-social:SocialAccount","inheritedExposure":["api","mcp"],"schema":{"tableName":"social_accounts","ddl":"CREATE TABLE IF NOT EXISTS \\"social_accounts\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"name\\" TEXT DEFAULT '',\\n \\"platform\\" TEXT DEFAULT 'youtube',\\n \\"platform_user_id\\" TEXT,\\n \\"platform_username\\" TEXT,\\n \\"platform_url\\" TEXT,\\n \\"access_token\\" TEXT,\\n \\"refresh_token\\" TEXT,\\n \\"credential_secret_id\\" TEXT,\\n \\"access_token_secret_name\\" TEXT,\\n \\"refresh_token_secret_name\\" TEXT,\\n \\"token_expires_at\\" TIMESTAMP,\\n \\"is_active\\" BOOLEAN DEFAULT TRUE,\\n \\"default_hashtags\\" JSON DEFAULT '[]',\\n \\"scopes\\" JSON DEFAULT '[]',\\n \\"missing_permissions\\" JSON DEFAULT '[]',\\n \\"link_behavior\\" TEXT DEFAULT 'description',\\n \\"publish_mode\\" TEXT DEFAULT 'dry_run',\\n \\"public_publishing_allowed\\" BOOLEAN DEFAULT FALSE,\\n \\"status\\" TEXT DEFAULT 'connected',\\n \\"error_message\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"name":{"type":"TEXT","notNull":false,"default":""},"platform":{"type":"TEXT","notNull":false,"default":"youtube"},"platform_user_id":{"type":"TEXT","notNull":false},"platform_username":{"type":"TEXT","notNull":false},"platform_url":{"type":"TEXT","notNull":false},"access_token":{"type":"TEXT","notNull":false},"refresh_token":{"type":"TEXT","notNull":false},"credential_secret_id":{"type":"TEXT","notNull":false},"access_token_secret_name":{"type":"TEXT","notNull":false},"refresh_token_secret_name":{"type":"TEXT","notNull":false},"token_expires_at":{"type":"TIMESTAMP","notNull":false},"is_active":{"type":"BOOLEAN","notNull":false,"default":true},"default_hashtags":{"type":"JSON","notNull":false,"default":[]},"scopes":{"type":"JSON","notNull":false,"default":[]},"missing_permissions":{"type":"JSON","notNull":false,"default":[]},"link_behavior":{"type":"TEXT","notNull":false,"default":"description"},"publish_mode":{"type":"TEXT","notNull":false,"default":"dry_run"},"public_publishing_allowed":{"type":"BOOLEAN","notNull":false,"default":false},"status":{"type":"TEXT","notNull":false,"default":"connected"},"error_message":{"type":"TEXT","notNull":false}},"indexes":[{"name":"social_accounts_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"social_accounts_meta_type_idx","columns":["_meta_type"]},{"name":"social_accounts_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"973c4ad8"},"importPath":"@happyvertical/smrt-social"},"@happyvertical/smrt-social:SocialPostAnalyticsSnapshotCollection":{"name":"socialpostanalyticssnapshotcollection","className":"SocialPostAnalyticsSnapshotCollection","qualifiedName":"@happyvertical/smrt-social:SocialPostAnalyticsSnapshotCollection","collection":"socialpostanalyticssnapshots","filePath":"src/collections/social-post-analytics-snapshot-collection.ts","packageName":"@happyvertical/smrt-social","fields":{},"methods":{"recordSnapshot":{"name":"recordSnapshot","async":true,"parameters":[{"name":"options","type":"object","optional":false,"memberTypes":["string","SocialPlatformType","PostAnalytics","RawAnalyticsPayload","Date","string | null"]}],"returnType":"Promise<SocialPostAnalyticsSnapshot>","isStatic":false,"isPublic":true},"findForPost":{"name":"findForPost","async":true,"parameters":[{"name":"socialPostId","type":"string","optional":false}],"returnType":"Promise<SocialPostAnalyticsSnapshot[]>","isStatic":false,"isPublic":true},"findLatestForPost":{"name":"findLatestForPost","async":true,"parameters":[{"name":"socialPostId","type":"string","optional":false}],"returnType":"Promise<SocialPostAnalyticsSnapshot | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","delete"]},"mcp":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"SocialPostAnalyticsSnapshot","exportName":"SocialPostAnalyticsSnapshotCollection","collectionExportName":"SocialPostAnalyticsSnapshotCollectionCollection","collectionOf":"@happyvertical/smrt-social:SocialPostAnalyticsSnapshot","inheritedExposure":["api","mcp"],"schema":{"tableName":"social_post_analytics_snapshots","ddl":"CREATE TABLE IF NOT EXISTS \\"social_post_analytics_snapshots\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"social_post_id\\" UUID,\\n \\"platform\\" TEXT,\\n \\"analytics\\" JSON,\\n \\"raw\\" JSON,\\n \\"captured_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"social_post_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"social_posts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"platform":{"type":"TEXT","notNull":false},"analytics":{"type":"JSON","notNull":false},"raw":{"type":"JSON","notNull":false},"captured_at":{"type":"TIMESTAMP","notNull":false}},"indexes":[{"name":"social_post_analytics_snapshots_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"social_post_analytics_snapshots_meta_type_idx","columns":["_meta_type"]},{"name":"social_post_analytics_snapshots_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"social_post_analytics_snapshots_social_post_id_idx","columns":["social_post_id"]}],"version":"0f4b8270"},"importPath":"@happyvertical/smrt-social"},"@happyvertical/smrt-social:SocialPostCollection":{"name":"socialpostcollection","className":"SocialPostCollection","qualifiedName":"@happyvertical/smrt-social:SocialPostCollection","collection":"socialposts","filePath":"src/collections/social-post-collection.ts","packageName":"@happyvertical/smrt-social","fields":{},"methods":{"createDraft":{"name":"createDraft","async":true,"parameters":[{"name":"options","type":"CreateSocialPostDraftOptions","optional":false}],"returnType":"Promise<SocialPost>","isStatic":false,"isPublic":true},"findByStatus":{"name":"findByStatus","async":true,"parameters":[{"name":"status","type":"PostStatus","optional":false}],"returnType":"Promise<SocialPost[]>","isStatic":false,"isPublic":true},"findForAccount":{"name":"findForAccount","async":true,"parameters":[{"name":"socialAccountId","type":"string","optional":false}],"returnType":"Promise<SocialPost[]>","isStatic":false,"isPublic":true},"findDueForPublish":{"name":"findDueForPublish","async":true,"parameters":[{"name":"now","type":"Date","optional":true}],"returnType":"Promise<SocialPost[]>","isStatic":false,"isPublic":true},"recordPublishSuccess":{"name":"recordPublishSuccess","async":true,"parameters":[{"name":"post","type":"SocialPost","optional":false},{"name":"data","type":"PublishSuccessData","optional":false}],"returnType":"Promise<SocialPost>","isStatic":false,"isPublic":true},"recordPublishFailure":{"name":"recordPublishFailure","async":true,"parameters":[{"name":"post","type":"SocialPost","optional":false},{"name":"error","type":"Error | string","optional":false,"unionBranches":[{"type":"Error"},{"type":"string"}]}],"returnType":"Promise<SocialPost>","isStatic":false,"isPublic":true},"updateLatestAnalytics":{"name":"updateLatestAnalytics","async":true,"parameters":[{"name":"post","type":"SocialPost","optional":false},{"name":"analytics","type":"PostAnalytics","optional":false},{"name":"syncedAt","type":"Date","optional":true}],"returnType":"Promise<SocialPost>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","update","delete"]},"mcp":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"SocialPost","exportName":"SocialPostCollection","collectionExportName":"SocialPostCollectionCollection","collectionOf":"@happyvertical/smrt-social:SocialPost","inheritedExposure":["api","mcp"],"schema":{"tableName":"social_posts","ddl":"CREATE TABLE IF NOT EXISTS \\"social_posts\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"social_account_id\\" UUID,\\n \\"created_by_user_id\\" UUID,\\n \\"video_content_id\\" UUID,\\n \\"content_id\\" UUID,\\n \\"post_type\\" TEXT DEFAULT 'text',\\n \\"media_url\\" TEXT,\\n \\"title\\" TEXT,\\n \\"description\\" TEXT DEFAULT '',\\n \\"hashtags\\" JSON DEFAULT '[]',\\n \\"link_url\\" TEXT,\\n \\"platform_post_id\\" TEXT,\\n \\"platform_url\\" TEXT,\\n \\"scheduled_at\\" TIMESTAMP,\\n \\"published_at\\" TIMESTAMP,\\n \\"status\\" TEXT DEFAULT 'draft',\\n \\"error_message\\" TEXT,\\n \\"analytics\\" JSON,\\n \\"analytics_last_synced_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"social_account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"social_accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"created_by_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"video_content_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"content_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"post_type":{"type":"TEXT","notNull":false,"default":"text"},"media_url":{"type":"TEXT","notNull":false},"title":{"type":"TEXT","notNull":false},"description":{"type":"TEXT","notNull":false,"default":""},"hashtags":{"type":"JSON","notNull":false,"default":[]},"link_url":{"type":"TEXT","notNull":false},"platform_post_id":{"type":"TEXT","notNull":false},"platform_url":{"type":"TEXT","notNull":false},"scheduled_at":{"type":"TIMESTAMP","notNull":false},"published_at":{"type":"TIMESTAMP","notNull":false},"status":{"type":"TEXT","notNull":false,"default":"draft"},"error_message":{"type":"TEXT","notNull":false},"analytics":{"type":"JSON","notNull":false},"analytics_last_synced_at":{"type":"TIMESTAMP","notNull":false}},"indexes":[{"name":"social_posts_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"social_posts_meta_type_idx","columns":["_meta_type"]},{"name":"social_posts_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"social_posts_social_account_id_idx","columns":["social_account_id"]},{"name":"social_posts_created_by_user_id_idx","columns":["created_by_user_id"]},{"name":"social_posts_video_content_id_idx","columns":["video_content_id"]},{"name":"social_posts_content_id_idx","columns":["content_id"]}],"version":"1006bafa"},"importPath":"@happyvertical/smrt-social"},"@happyvertical/smrt-social:OAuthState":{"name":"oauthstate","className":"OAuthState","qualifiedName":"@happyvertical/smrt-social:OAuthState","collection":"oauthstates","description":"Temporary OAuth state for social account connection","filePath":"src/oauth-state.ts","packageName":"@happyvertical/smrt-social","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","nullable","__tenancy","required"],"sqlType":"UUID","nullable":true,"required":false},"required":false},"platform":{"type":"text","_meta":{"__statedOptions":["default","enum"]},"required":false,"default":"youtube","enum":["youtube","threads","x","bluesky","facebook"]},"state":{"type":"text","_meta":{"__statedOptions":["default"]},"required":false,"default":""},"codeVerifier":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"redirectUri":{"type":"text","_meta":{"__statedOptions":["default"]},"required":false,"default":""},"scopes":{"type":"json","_meta":{"__statedOptions":["default"]},"required":false,"default":[]},"expiresAt":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"createdByUserId":{"type":"crossPackageRef","_meta":{"__statedOptions":["related"]},"required":false,"related":"@happyvertical/smrt-users:User"},"returnTo":{"type":"text","_meta":{"__statedOptions":[]},"required":false}},"methods":{"verifyState":{"name":"verifyState","async":false,"parameters":[{"name":"callbackState","type":"string","optional":false}],"returnType":"boolean","isStatic":false,"isPublic":true},"generateState":{"name":"generateState","async":false,"parameters":[],"returnType":"string","isStatic":true,"isPublic":true},"generateCodeVerifier":{"name":"generateCodeVerifier","async":false,"parameters":[],"returnType":"string","isStatic":true,"isPublic":true},"generateCodeChallenge":{"name":"generateCodeChallenge","async":true,"parameters":[{"name":"verifier","type":"string","optional":false}],"returnType":"Promise<string>","isStatic":true,"isPublic":true}},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get","create","delete"]},"mcp":false,"cli":{"skipApiCheck":true},"tenantScoped":{"mode":"optional"},"conflictColumns":["tenant_id","slug","context","_meta_type"]},"extends":"SmrtObject","exportName":"OAuthState","collectionExportName":"OAuthStateCollection","schema":{"tableName":"oauth_states","ddl":"CREATE TABLE IF NOT EXISTS \\"oauth_states\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"platform\\" TEXT DEFAULT 'youtube',\\n \\"state\\" TEXT DEFAULT '',\\n \\"code_verifier\\" TEXT,\\n \\"redirect_uri\\" TEXT DEFAULT '',\\n \\"scopes\\" JSON DEFAULT '[]',\\n \\"expires_at\\" TIMESTAMP,\\n \\"created_by_user_id\\" UUID,\\n \\"return_to\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"platform":{"type":"TEXT","notNull":false,"default":"youtube"},"state":{"type":"TEXT","notNull":false,"default":""},"code_verifier":{"type":"TEXT","notNull":false},"redirect_uri":{"type":"TEXT","notNull":false,"default":""},"scopes":{"type":"JSON","notNull":false,"default":[]},"expires_at":{"type":"TIMESTAMP","notNull":false},"created_by_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"return_to":{"type":"TEXT","notNull":false}},"indexes":[{"name":"oauth_states_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"oauth_states_meta_type_idx","columns":["_meta_type"]},{"name":"oauth_states_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"oauth_states_created_by_user_id_idx","columns":["created_by_user_id"]}],"version":"46b1e275"},"importPath":"@happyvertical/smrt-social"},"@happyvertical/smrt-social:SocialAccount":{"name":"socialaccount","className":"SocialAccount","qualifiedName":"@happyvertical/smrt-social:SocialAccount","collection":"socialaccounts","description":"Connected social media account for publishing","filePath":"src/social-account.ts","packageName":"@happyvertical/smrt-social","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","nullable","__tenancy","required"],"sqlType":"UUID","nullable":true,"required":false},"required":false},"name":{"type":"text","_meta":{"__statedOptions":["description","default"],"description":"A name you will recognise this account by."},"required":false,"default":"","description":"A name you will recognise this account by."},"platform":{"type":"text","_meta":{"__statedOptions":["description","default","enum"],"description":"Which platform it is on: YouTube, X, Threads or Bluesky."},"required":false,"default":"youtube","description":"Which platform it is on: YouTube, X, Threads or Bluesky.","enum":["youtube","threads","x","bluesky","facebook"]},"platformUserId":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"platformUsername":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The username or handle you post under."},"required":false,"description":"The username or handle you post under."},"platformUrl":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The web address of your profile on the platform."},"required":false,"description":"The web address of your profile on the platform."},"accessToken":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"refreshToken":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"credentialSecretId":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"accessTokenSecretName":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"refreshTokenSecretName":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"tokenExpiresAt":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"isActive":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether posts can still go out from this account."},"required":false,"default":true,"description":"Whether posts can still go out from this account."},"defaultHashtags":{"type":"json","_meta":{"__statedOptions":["description","default"],"description":"Hashtags added to every post from this account."},"required":false,"default":[],"description":"Hashtags added to every post from this account."},"scopes":{"type":"json","_meta":{"__statedOptions":["default"]},"required":false,"default":[]},"missingPermissions":{"type":"json","_meta":{"__statedOptions":["default"]},"required":false,"default":[]},"linkBehavior":{"type":"text","_meta":{"__statedOptions":["description","default","enum"],"description":"Where a shared link goes: in the text, as a reply, or left out."},"required":false,"default":"description","description":"Where a shared link goes: in the text, as a reply, or left out.","enum":["description","inline","attachment","reply","none"]},"publishMode":{"type":"text","_meta":{"__statedOptions":["default","enum"]},"required":false,"default":"dry_run","enum":["dry_run","stage_remote","private_or_scheduled","public"]},"publicPublishingAllowed":{"type":"boolean","_meta":{"__statedOptions":["default"]},"required":false,"default":false},"status":{"type":"text","_meta":{"__statedOptions":["description","default","enum"],"description":"Whether the account is connected, or needs signing in again."},"required":false,"default":"connected","description":"Whether the account is connected, or needs signing in again.","enum":["connected","disconnected","expired","missing_permissions","error"]},"errorMessage":{"type":"text","_meta":{"__statedOptions":[]},"required":false}},"methods":{"getSlug":{"name":"getSlug","async":true,"parameters":[],"returnType":"Promise<string | null | undefined>","isStatic":false,"isPublic":true},"setCredentials":{"name":"setCredentials","async":true,"parameters":[{"name":"credentials","type":"Record<string, unknown>","optional":false},{"name":"options","type":"object","optional":true,"memberTypes":["string"]}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"getCredentials":{"name":"getCredentials","async":true,"parameters":[],"returnType":"Promise<Record<string, unknown> | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get","create","update","delete"]},"mcp":{"include":["list","get"]},"cli":{"skipApiCheck":true},"tenantScoped":{"mode":"optional"},"conflictColumns":["tenant_id","slug","context","_meta_type"]},"extends":"SmrtObject","exportName":"SocialAccount","collectionExportName":"SocialAccountCollection","displayLabelField":"name","schema":{"tableName":"social_accounts","ddl":"CREATE TABLE IF NOT EXISTS \\"social_accounts\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"name\\" TEXT DEFAULT '',\\n \\"platform\\" TEXT DEFAULT 'youtube',\\n \\"platform_user_id\\" TEXT,\\n \\"platform_username\\" TEXT,\\n \\"platform_url\\" TEXT,\\n \\"access_token\\" TEXT,\\n \\"refresh_token\\" TEXT,\\n \\"credential_secret_id\\" TEXT,\\n \\"access_token_secret_name\\" TEXT,\\n \\"refresh_token_secret_name\\" TEXT,\\n \\"token_expires_at\\" TIMESTAMP,\\n \\"is_active\\" BOOLEAN DEFAULT TRUE,\\n \\"default_hashtags\\" JSON DEFAULT '[]',\\n \\"scopes\\" JSON DEFAULT '[]',\\n \\"missing_permissions\\" JSON DEFAULT '[]',\\n \\"link_behavior\\" TEXT DEFAULT 'description',\\n \\"publish_mode\\" TEXT DEFAULT 'dry_run',\\n \\"public_publishing_allowed\\" BOOLEAN DEFAULT FALSE,\\n \\"status\\" TEXT DEFAULT 'connected',\\n \\"error_message\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"name":{"type":"TEXT","notNull":false,"default":""},"platform":{"type":"TEXT","notNull":false,"default":"youtube"},"platform_user_id":{"type":"TEXT","notNull":false},"platform_username":{"type":"TEXT","notNull":false},"platform_url":{"type":"TEXT","notNull":false},"access_token":{"type":"TEXT","notNull":false},"refresh_token":{"type":"TEXT","notNull":false},"credential_secret_id":{"type":"TEXT","notNull":false},"access_token_secret_name":{"type":"TEXT","notNull":false},"refresh_token_secret_name":{"type":"TEXT","notNull":false},"token_expires_at":{"type":"TIMESTAMP","notNull":false},"is_active":{"type":"BOOLEAN","notNull":false,"default":true},"default_hashtags":{"type":"JSON","notNull":false,"default":[]},"scopes":{"type":"JSON","notNull":false,"default":[]},"missing_permissions":{"type":"JSON","notNull":false,"default":[]},"link_behavior":{"type":"TEXT","notNull":false,"default":"description"},"publish_mode":{"type":"TEXT","notNull":false,"default":"dry_run"},"public_publishing_allowed":{"type":"BOOLEAN","notNull":false,"default":false},"status":{"type":"TEXT","notNull":false,"default":"connected"},"error_message":{"type":"TEXT","notNull":false}},"indexes":[{"name":"social_accounts_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"social_accounts_meta_type_idx","columns":["_meta_type"]},{"name":"social_accounts_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"973c4ad8"},"importPath":"@happyvertical/smrt-social"},"@happyvertical/smrt-social:SocialPostAnalyticsSnapshot":{"name":"socialpostanalyticssnapshot","className":"SocialPostAnalyticsSnapshot","qualifiedName":"@happyvertical/smrt-social:SocialPostAnalyticsSnapshot","collection":"socialpostanalyticssnapshots","filePath":"src/social-post-analytics-snapshot.ts","packageName":"@happyvertical/smrt-social","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","nullable","__tenancy","required"],"sqlType":"UUID","nullable":true,"required":false},"required":false},"socialPostId":{"type":"foreignKey","_meta":{"__statedOptions":["description","related"],"description":"The post these numbers are for."},"required":false,"related":"SocialPost","description":"The post these numbers are for."},"platform":{"type":"text","_meta":{"__statedOptions":["description","enum"],"description":"The platform that reported the numbers."},"required":false,"description":"The platform that reported the numbers.","enum":["youtube","threads","x","bluesky","facebook"]},"analytics":{"type":"json","_meta":{"__typeUnresolved":true,"__statedOptions":["description"],"description":"The views, likes, comments, shares and clicks the platform reported."},"required":false,"description":"The views, likes, comments, shares and clicks the platform reported."},"raw":{"type":"json","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false},"capturedAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When these numbers were taken from the platform."},"required":false,"description":"When these numbers were taken from the platform."}},"methods":{},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get","create","delete"]},"mcp":{"include":["list","get"]},"cli":true,"tenantScoped":{"mode":"optional"},"conflictColumns":["tenant_id","slug","context","_meta_type"]},"extends":"SmrtObject","exportName":"SocialPostAnalyticsSnapshot","collectionExportName":"SocialPostAnalyticsSnapshotCollection","schema":{"tableName":"social_post_analytics_snapshots","ddl":"CREATE TABLE IF NOT EXISTS \\"social_post_analytics_snapshots\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"social_post_id\\" UUID,\\n \\"platform\\" TEXT,\\n \\"analytics\\" JSON,\\n \\"raw\\" JSON,\\n \\"captured_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"social_post_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"social_posts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"platform":{"type":"TEXT","notNull":false},"analytics":{"type":"JSON","notNull":false},"raw":{"type":"JSON","notNull":false},"captured_at":{"type":"TIMESTAMP","notNull":false}},"indexes":[{"name":"social_post_analytics_snapshots_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"social_post_analytics_snapshots_meta_type_idx","columns":["_meta_type"]},{"name":"social_post_analytics_snapshots_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"social_post_analytics_snapshots_social_post_id_idx","columns":["social_post_id"]}],"version":"0f4b8270"},"importPath":"@happyvertical/smrt-social"},"@happyvertical/smrt-social:SocialPost":{"name":"socialpost","className":"SocialPost","qualifiedName":"@happyvertical/smrt-social:SocialPost","collection":"socialposts","description":"Social media post for multi-platform publishing","filePath":"src/social-post.ts","packageName":"@happyvertical/smrt-social","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","nullable","__tenancy","required"],"sqlType":"UUID","nullable":true,"required":false},"required":false},"socialAccountId":{"type":"foreignKey","_meta":{"__statedOptions":["description","related"],"description":"The connected account this post goes out from."},"required":false,"related":"SocialAccount","description":"The connected account this post goes out from."},"createdByUserId":{"type":"crossPackageRef","_meta":{"__statedOptions":["related"]},"required":false,"related":"@happyvertical/smrt-users:User"},"videoContentId":{"type":"crossPackageRef","_meta":{"__statedOptions":["related"]},"required":false,"related":"@happyvertical/smrt-video:VideoShot"},"contentId":{"type":"crossPackageRef","_meta":{"__statedOptions":["related"]},"required":false,"related":"@happyvertical/smrt-content:Content"},"postType":{"type":"text","_meta":{"__statedOptions":["description","default","enum"],"description":"What kind of post it is: text, link, image or video."},"required":false,"default":"text","description":"What kind of post it is: text, link, image or video.","enum":["text","link","image","video"]},"mediaUrl":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"title":{"type":"text","_meta":{"__statedOptions":["description"],"description":"A title, for platforms that show one."},"required":false,"description":"A title, for platforms that show one."},"description":{"type":"text","_meta":{"__statedOptions":["description","default"],"description":"The words of the post."},"required":false,"default":"","description":"The words of the post."},"hashtags":{"type":"json","_meta":{"__statedOptions":["description","default"],"description":"Hashtags added to the end of the post."},"required":false,"default":[],"description":"Hashtags added to the end of the post."},"linkUrl":{"type":"text","_meta":{"__statedOptions":["description"],"description":"A web address to share with the post."},"required":false,"description":"A web address to share with the post."},"platformPostId":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"platformUrl":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Where the post can be seen on the platform, once it is out."},"required":false,"description":"Where the post can be seen on the platform, once it is out."},"scheduledAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"The date and time you have in mind for putting the post out. Only a note of the plan: publishing is a separate step your application has to run."},"required":false,"description":"The date and time you have in mind for putting the post out. Only a note of the plan: publishing is a separate step your application has to run."},"publishedAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When the post actually went out."},"required":false,"description":"When the post actually went out."},"status":{"type":"text","_meta":{"__statedOptions":["description","default","enum"],"description":"Where the post stands: draft, waiting to go out, published or failed."},"required":false,"default":"draft","description":"Where the post stands: draft, waiting to go out, published or failed.","enum":["draft","pending_approval","approved","scheduled","publishing","dry_run","staged","published","failed","cancelled"]},"errorMessage":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"analytics":{"type":"json","_meta":{"__typeUnresolved":true,"__statedOptions":[]},"required":false},"analyticsLastSyncedAt":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false}},"methods":{},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get","create","update","delete"]},"mcp":{"include":["list","get"]},"cli":true,"tenantScoped":{"mode":"optional"},"conflictColumns":["tenant_id","slug","context","_meta_type"]},"extends":"SmrtObject","exportName":"SocialPost","collectionExportName":"SocialPostCollection","displayLabelField":"title","schema":{"tableName":"social_posts","ddl":"CREATE TABLE IF NOT EXISTS \\"social_posts\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"social_account_id\\" UUID,\\n \\"created_by_user_id\\" UUID,\\n \\"video_content_id\\" UUID,\\n \\"content_id\\" UUID,\\n \\"post_type\\" TEXT DEFAULT 'text',\\n \\"media_url\\" TEXT,\\n \\"title\\" TEXT,\\n \\"description\\" TEXT DEFAULT '',\\n \\"hashtags\\" JSON DEFAULT '[]',\\n \\"link_url\\" TEXT,\\n \\"platform_post_id\\" TEXT,\\n \\"platform_url\\" TEXT,\\n \\"scheduled_at\\" TIMESTAMP,\\n \\"published_at\\" TIMESTAMP,\\n \\"status\\" TEXT DEFAULT 'draft',\\n \\"error_message\\" TEXT,\\n \\"analytics\\" JSON,\\n \\"analytics_last_synced_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"social_account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"social_accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"created_by_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"video_content_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"content_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"post_type":{"type":"TEXT","notNull":false,"default":"text"},"media_url":{"type":"TEXT","notNull":false},"title":{"type":"TEXT","notNull":false},"description":{"type":"TEXT","notNull":false,"default":""},"hashtags":{"type":"JSON","notNull":false,"default":[]},"link_url":{"type":"TEXT","notNull":false},"platform_post_id":{"type":"TEXT","notNull":false},"platform_url":{"type":"TEXT","notNull":false},"scheduled_at":{"type":"TIMESTAMP","notNull":false},"published_at":{"type":"TIMESTAMP","notNull":false},"status":{"type":"TEXT","notNull":false,"default":"draft"},"error_message":{"type":"TEXT","notNull":false},"analytics":{"type":"JSON","notNull":false},"analytics_last_synced_at":{"type":"TIMESTAMP","notNull":false}},"indexes":[{"name":"social_posts_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"social_posts_meta_type_idx","columns":["_meta_type"]},{"name":"social_posts_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"social_posts_social_account_id_idx","columns":["social_account_id"]},{"name":"social_posts_created_by_user_id_idx","columns":["created_by_user_id"]},{"name":"social_posts_video_content_id_idx","columns":["video_content_id"]},{"name":"social_posts_content_id_idx","columns":["content_id"]}],"version":"1006bafa"},"importPath":"@happyvertical/smrt-social"}},"moduleType":"smrt","recipes":[{"id":"social.posts","className":"SocialPostsRecipe","label":"Social","summary":"Write posts for your YouTube, X, Threads and Bluesky accounts, plan when they go out and see how each one did.","synonyms":["social media","social posts","social accounts","youtube","bluesky","threads","tweets","post results"],"models":["@happyvertical/smrt-social:SocialPost","@happyvertical/smrt-social:SocialAccount","@happyvertical/smrt-social:SocialPostAnalyticsSnapshot"],"nav":[{"label":"Posts","model":"@happyvertical/smrt-social:SocialPost","icon":"fileText","description":"What you have written for each account and where it stands.","noun":"post"},{"label":"Connected accounts","model":"@happyvertical/smrt-social:SocialAccount","icon":"users","description":"The social accounts you can post to, and their settings.","noun":"account"}],"requires":[],"section":{"id":"publish","label":"Publish","icon":"fileText","description":"What you write, record and put out."},"options":{"@happyvertical/smrt-social:SocialPost":{"fields":{"socialAccountId":{"label":"Account","order":1},"title":{"order":2},"description":{"label":"Text","order":3},"hashtags":{"order":4},"linkUrl":{"label":"Link","order":5},"postType":{"label":"Kind of post","order":6},"scheduledAt":{"label":"Planned for","order":7},"status":{"locked":true,"order":8},"publishedAt":{"label":"Published on","locked":true,"order":9},"platformUrl":{"label":"Link to the post","locked":true,"order":10},"videoContentId":{"label":"Video","visibility":"advanced"},"contentId":{"label":"Content","visibility":"advanced"},"mediaUrl":{"label":"Media link","visibility":"advanced"},"errorMessage":{"label":"What went wrong","visibility":"advanced"},"analyticsLastSyncedAt":{"label":"Results last updated","visibility":"advanced"},"tenantId":{"visibility":"hidden"},"createdByUserId":{"visibility":"hidden"},"platformPostId":{"visibility":"hidden"},"analytics":{"visibility":"hidden"}}},"@happyvertical/smrt-social:SocialAccount":{"fields":{"name":{"order":1},"platform":{"order":2},"platformUsername":{"label":"Username","order":3},"platformUrl":{"label":"Profile link","order":4},"status":{"locked":true,"order":5},"isActive":{"label":"In use","order":6},"defaultHashtags":{"order":7},"linkBehavior":{"label":"Where links go","order":8},"publishMode":{"label":"Publishing mode","visibility":"advanced"},"publicPublishingAllowed":{"label":"Allow public posts","visibility":"advanced"},"platformUserId":{"visibility":"advanced"},"tokenExpiresAt":{"label":"Connection expires","visibility":"advanced"},"scopes":{"label":"Permissions granted","visibility":"advanced"},"missingPermissions":{"visibility":"advanced"},"errorMessage":{"label":"What went wrong","visibility":"advanced"},"tenantId":{"visibility":"hidden"},"accessToken":{"visibility":"hidden"},"refreshToken":{"visibility":"hidden"},"credentialSecretId":{"visibility":"hidden"},"accessTokenSecretName":{"visibility":"hidden"},"refreshTokenSecretName":{"visibility":"hidden"}}},"@happyvertical/smrt-social:SocialPostAnalyticsSnapshot":{"fields":{"socialPostId":{"label":"Post","order":1},"platform":{"order":2},"capturedAt":{"label":"Measured on","order":3},"analytics":{"label":"Numbers","order":4},"tenantId":{"visibility":"hidden"},"raw":{"visibility":"hidden"}}}},"help":{"markdown":"## Overview\\n\\nSocial is where you write what you want to put out on YouTube, X, Threads and\\nBluesky. Each post is written for one connected account, with its text,\\nhashtags and an optional link, and can carry the date you plan to put it out.\\nYour app does the publishing; once a post is out, the platform's numbers for it\\narrive here as post results.\\n\\n## Tasks\\n\\n### Connect an account\\n\\n1. Open the connected accounts and choose **New**.\\n2. Give it a **{field:SocialAccount.name}** you will recognise, such as \\"Acme Corp on Bluesky\\".\\n3. Pick the **{field:SocialAccount.platform}** and type the **{field:SocialAccount.platformUsername}** you post under.\\n4. Add any **{field:SocialAccount.defaultHashtags}** you want on every post from this account.\\n5. Save. Signing in to the platform itself happens from your app, not in this form; the **{field:SocialAccount.status}** shows whether the account is connected.\\n\\n### Write a post\\n\\n1. Open the posts and choose **New**.\\n2. Pick the **{field:SocialPost.socialAccountId}** it is for.\\n3. Write the **{field:SocialPost.description}** and add any **{field:SocialPost.hashtags}**.\\n4. Give it a **{field:SocialPost.title}** if the platform shows one, and a **{field:SocialPost.linkUrl}** if you are sharing a page.\\n5. Save. It stays a draft until your app puts it out.\\n\\n### Note when a post should go out\\n\\n1. Open the post and set **{field:SocialPost.scheduledAt}** to the date and time you have in mind.\\n2. Save. This only records the plan on the post. Nothing here publishes it: a post goes out only when your application's own publishing step approves it and sends it at that time, so check with whoever set up your app that this step is in place.\\n\\n### See where a post stands\\n\\nOpen the post. Its **{field:SocialPost.status}** shows whether it is a draft,\\nwaiting to go out, published or failed. Once it is out, **{field:SocialPost.publishedAt}**\\nand the **{field:SocialPost.platformUrl}** are filled in.\\n\\n### Change or remove a post\\n\\n1. Open the post and change what you need, then save.\\n2. To remove it, open the post and choose **Delete**.\\n\\n### See how a post did\\n\\nPost results are written by the platform sync, not by hand; you can only read\\nthem here.\\n\\n1. Open the post and look at its results, listed under the post.\\n2. Each result names the **{field:SocialPostAnalyticsSnapshot.socialPostId}** it belongs to and the **{field:SocialPostAnalyticsSnapshot.platform}** it ran on.\\n3. Each result shows the **{field:SocialPostAnalyticsSnapshot.analytics}** the platform reported and when they were **{field:SocialPostAnalyticsSnapshot.capturedAt}**, so the newest one is the latest count.\\n\\n### Stop using an account\\n\\n1. Open the account and untick **{field:SocialAccount.isActive}**, then save. Its posts stay, but nothing new goes out from it.\\n2. To remove it entirely, open the account and choose **Delete**.\\n","fieldRefs":["SocialAccount.defaultHashtags","SocialAccount.isActive","SocialAccount.name","SocialAccount.platform","SocialAccount.platformUsername","SocialAccount.status","SocialPost.description","SocialPost.hashtags","SocialPost.linkUrl","SocialPost.platformUrl","SocialPost.publishedAt","SocialPost.scheduledAt","SocialPost.socialAccountId","SocialPost.status","SocialPost.title","SocialPostAnalyticsSnapshot.analytics","SocialPostAnalyticsSnapshot.capturedAt","SocialPostAnalyticsSnapshot.platform","SocialPostAnalyticsSnapshot.socialPostId"]},"demo":{"mode":"server","reasons":["Needs a server because its package does not build for a browser: node:crypto; and its package depends on @happyvertical/smrt-agents, @happyvertical/smrt-chat, @happyvertical/smrt-content, @happyvertical/smrt-images, @happyvertical/smrt-jobs, @happyvertical/smrt-profiles, @happyvertical/smrt-reports, @happyvertical/smrt-secrets, @happyvertical/smrt-tenancy, @happyvertical/smrt-users, which do not build for a browser (#3615, #3617, #3624, #3625, #3626, #3627, #3628)."]}}],"smrtDependencies":["@happyvertical/smrt-content","@happyvertical/smrt-core","@happyvertical/smrt-secrets","@happyvertical/smrt-tenancy","@happyvertical/smrt-video"],"browser":{"status":"server-only","issues":["#3615","#3617","#3624","#3625","#3626","#3627","#3628"],"reason":"node:crypto","via":["@happyvertical/smrt-agents","@happyvertical/smrt-chat","@happyvertical/smrt-content","@happyvertical/smrt-images","@happyvertical/smrt-jobs","@happyvertical/smrt-profiles","@happyvertical/smrt-reports","@happyvertical/smrt-secrets","@happyvertical/smrt-tenancy","@happyvertical/smrt-users"]},"stampsConstructors":true}`));
|
|
8
|
-
//#endregion
|
|
9
|
-
//#region src/oauth-state.ts
|
|
10
|
-
var __defProp$3 = Object.defineProperty;
|
|
11
|
-
var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
|
|
12
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true,
|
|
16
|
-
value
|
|
17
|
-
}) : obj[key] = value;
|
|
18
|
-
var __decorateClass$3 = (decorators, target, key, kind) => {
|
|
19
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
|
|
20
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
21
|
-
if (kind && result) __defProp$3(target, key, result);
|
|
22
|
-
return result;
|
|
23
|
-
};
|
|
24
|
-
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
25
|
-
var OAuthState = class extends SmrtObject {
|
|
26
|
-
tenantId = null;
|
|
27
|
-
/**
|
|
28
|
-
* Platform being connected
|
|
29
|
-
*/
|
|
30
|
-
platform = "youtube";
|
|
31
|
-
/**
|
|
32
|
-
* CSRF state token
|
|
33
|
-
* This is sent to the OAuth provider and verified on callback
|
|
34
|
-
*/
|
|
35
|
-
state = "";
|
|
36
|
-
/**
|
|
37
|
-
* PKCE code verifier
|
|
38
|
-
* Required for platforms using PKCE (YouTube, etc.)
|
|
39
|
-
*/
|
|
40
|
-
codeVerifier = null;
|
|
41
|
-
/**
|
|
42
|
-
* Redirect URI used in the OAuth request
|
|
43
|
-
* Must match on callback for verification
|
|
44
|
-
*/
|
|
45
|
-
redirectUri = "";
|
|
46
|
-
/**
|
|
47
|
-
* Requested OAuth scopes
|
|
48
|
-
*/
|
|
49
|
-
scopes = [];
|
|
50
|
-
/**
|
|
51
|
-
* When this state expires
|
|
52
|
-
* States should be short-lived (10 minutes typical)
|
|
53
|
-
*/
|
|
54
|
-
expiresAt = new Date(Date.now() + 600 * 1e3);
|
|
55
|
-
createdByUserId = null;
|
|
56
|
-
/**
|
|
57
|
-
* Application-defined path to return to after the callback, for example the
|
|
58
|
-
* settings page that started the flow. Opaque to the framework: the host
|
|
59
|
-
* that reads it must validate it as a same-origin path before redirecting.
|
|
60
|
-
*/
|
|
61
|
-
returnTo = null;
|
|
62
|
-
constructor(options = {}) {
|
|
63
|
-
super(options);
|
|
64
|
-
if (options.platform !== void 0) this.platform = options.platform;
|
|
65
|
-
if (options.state !== void 0) this.state = options.state;
|
|
66
|
-
if (options.codeVerifier !== void 0) this.codeVerifier = options.codeVerifier;
|
|
67
|
-
if (options.redirectUri !== void 0) this.redirectUri = options.redirectUri;
|
|
68
|
-
if (options.scopes !== void 0) this.scopes = options.scopes;
|
|
69
|
-
if (options.expiresAt !== void 0) this.expiresAt = options.expiresAt;
|
|
70
|
-
if (options.tenantId !== void 0) this.tenantId = options.tenantId;
|
|
71
|
-
if (options.createdByUserId !== void 0) this.createdByUserId = options.createdByUserId;
|
|
72
|
-
if (options.returnTo !== void 0) this.returnTo = options.returnTo;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Check if the state has expired
|
|
76
|
-
*/
|
|
77
|
-
get isExpired() {
|
|
78
|
-
return Date.now() >= this.expiresAt.getTime();
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Check if the state is still valid
|
|
82
|
-
*/
|
|
83
|
-
get isValid() {
|
|
84
|
-
return !this.isExpired && this.state.length > 0;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Verify a callback state matches this record
|
|
88
|
-
*/
|
|
89
|
-
verifyState(callbackState) {
|
|
90
|
-
return this.isValid && this.state === callbackState;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Generate a new random state token
|
|
94
|
-
*/
|
|
95
|
-
static generateState() {
|
|
96
|
-
return crypto.randomUUID();
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Generate a PKCE code verifier
|
|
100
|
-
* Returns a 43-128 character random string
|
|
101
|
-
*/
|
|
102
|
-
static generateCodeVerifier() {
|
|
103
|
-
const array = /* @__PURE__ */ new Uint8Array(32);
|
|
104
|
-
crypto.getRandomValues(array);
|
|
105
|
-
return Array.from(array, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Generate PKCE code challenge from verifier (S256 method)
|
|
109
|
-
* Note: This requires async crypto operations
|
|
110
|
-
*/
|
|
111
|
-
static async generateCodeChallenge(verifier) {
|
|
112
|
-
const data = new TextEncoder().encode(verifier);
|
|
113
|
-
const digest = await crypto.subtle.digest("SHA-256", data);
|
|
114
|
-
return btoa(String.fromCharCode(...new Uint8Array(digest))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
__publicField$3(OAuthState, "__smrtPackage__", "@happyvertical/smrt-social");
|
|
118
|
-
__decorateClass$3([tenantId({ nullable: true })], OAuthState.prototype, "tenantId", 2);
|
|
119
|
-
__decorateClass$3([crossPackageRef("@happyvertical/smrt-users:User")], OAuthState.prototype, "createdByUserId", 2);
|
|
120
|
-
OAuthState = __decorateClass$3([TenantScoped({ mode: "optional" }), smrt({
|
|
121
|
-
tableStrategy: "sti",
|
|
122
|
-
api: { include: [
|
|
123
|
-
"list",
|
|
124
|
-
"get",
|
|
125
|
-
"create",
|
|
126
|
-
"delete"
|
|
127
|
-
] },
|
|
128
|
-
mcp: false,
|
|
129
|
-
cli: { skipApiCheck: true }
|
|
130
|
-
})], OAuthState);
|
|
131
|
-
//#endregion
|
|
132
|
-
//#region src/collections/oauth-state-collection.ts
|
|
133
|
-
var OAuthStateCollection = class extends SmrtCollection {
|
|
134
|
-
static _itemClass = OAuthState;
|
|
135
|
-
async findByState(state) {
|
|
136
|
-
return this.get({ state });
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Consume a loaded state exactly once.
|
|
140
|
-
*
|
|
141
|
-
* Deletes the record with a revision-guarded delete, so when two callbacks
|
|
142
|
-
* race on the same state only one delete removes the row. Returns `true`
|
|
143
|
-
* for that caller and `false` for every caller whose row was already gone
|
|
144
|
-
* or changed; any other failure propagates. Call it before acting on the
|
|
145
|
-
* state (exchanging the code), and stop when it returns `false`.
|
|
146
|
-
*/
|
|
147
|
-
async consume(state) {
|
|
148
|
-
if (!state.id || !state.updated_at) return false;
|
|
149
|
-
try {
|
|
150
|
-
await state.delete({ expectedUpdatedAt: state.updated_at });
|
|
151
|
-
return true;
|
|
152
|
-
} catch (error) {
|
|
153
|
-
if (error instanceof RuntimeError && error.code === "RUNTIME_REVISION_CONFLICT") return false;
|
|
154
|
-
throw error;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
async findExpired(now = /* @__PURE__ */ new Date()) {
|
|
158
|
-
return this.list({
|
|
159
|
-
where: { "expiresAt <=": now },
|
|
160
|
-
orderBy: "expiresAt ASC"
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
async deleteExpired(now = /* @__PURE__ */ new Date()) {
|
|
164
|
-
const expired = await this.findExpired(now);
|
|
165
|
-
await Promise.all(expired.map((state) => state.delete()));
|
|
166
|
-
return expired.length;
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
//#endregion
|
|
170
|
-
//#region src/social-account.ts
|
|
171
|
-
var __defProp$2 = Object.defineProperty;
|
|
172
|
-
var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
|
|
173
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, {
|
|
174
|
-
enumerable: true,
|
|
175
|
-
configurable: true,
|
|
176
|
-
writable: true,
|
|
177
|
-
value
|
|
178
|
-
}) : obj[key] = value;
|
|
179
|
-
var __decorateClass$2 = (decorators, target, key, kind) => {
|
|
180
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
|
|
181
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
182
|
-
if (kind && result) __defProp$2(target, key, result);
|
|
183
|
-
return result;
|
|
184
|
-
};
|
|
185
|
-
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
186
|
-
var SocialAccount = class extends SmrtObject {
|
|
187
|
-
tenantId = null;
|
|
188
|
-
name = "";
|
|
189
|
-
platform = "youtube";
|
|
190
|
-
/**
|
|
191
|
-
* Platform-specific user ID
|
|
192
|
-
*/
|
|
193
|
-
platformUserId = null;
|
|
194
|
-
platformUsername = null;
|
|
195
|
-
platformUrl = null;
|
|
196
|
-
/**
|
|
197
|
-
* Deprecated raw OAuth access token.
|
|
198
|
-
* Prefer credentialSecretId/accessTokenSecretName.
|
|
199
|
-
*/
|
|
200
|
-
accessToken = null;
|
|
201
|
-
/**
|
|
202
|
-
* Deprecated raw OAuth refresh token.
|
|
203
|
-
* Prefer credentialSecretId/refreshTokenSecretName.
|
|
204
|
-
*/
|
|
205
|
-
refreshToken = null;
|
|
206
|
-
/**
|
|
207
|
-
* Secret name containing the complete platform credential payload.
|
|
208
|
-
*/
|
|
209
|
-
credentialSecretId = null;
|
|
210
|
-
/**
|
|
211
|
-
* Secret name containing only the access token.
|
|
212
|
-
*/
|
|
213
|
-
accessTokenSecretName = null;
|
|
214
|
-
/**
|
|
215
|
-
* Secret name containing only the refresh token.
|
|
216
|
-
*/
|
|
217
|
-
refreshTokenSecretName = null;
|
|
218
|
-
/**
|
|
219
|
-
* Token expiration time
|
|
220
|
-
*/
|
|
221
|
-
tokenExpiresAt = null;
|
|
222
|
-
isActive = true;
|
|
223
|
-
defaultHashtags = [];
|
|
224
|
-
/**
|
|
225
|
-
* Granted OAuth scopes or platform permissions.
|
|
226
|
-
*/
|
|
227
|
-
scopes = [];
|
|
228
|
-
/**
|
|
229
|
-
* Required permissions that still need app review or user grant.
|
|
230
|
-
*/
|
|
231
|
-
missingPermissions = [];
|
|
232
|
-
linkBehavior = "description";
|
|
233
|
-
/**
|
|
234
|
-
* Safety mode for publish operations.
|
|
235
|
-
*/
|
|
236
|
-
publishMode = "dry_run";
|
|
237
|
-
/**
|
|
238
|
-
* Separate latch required before public publishing is allowed.
|
|
239
|
-
*/
|
|
240
|
-
publicPublishingAllowed = false;
|
|
241
|
-
status = "connected";
|
|
242
|
-
/**
|
|
243
|
-
* Error message if status is 'error'
|
|
244
|
-
*/
|
|
245
|
-
errorMessage = null;
|
|
246
|
-
constructor(options = {}) {
|
|
247
|
-
super(options);
|
|
248
|
-
if (options.name !== void 0) this.name = options.name;
|
|
249
|
-
if (options.platform !== void 0) this.platform = options.platform;
|
|
250
|
-
if (options.platformUserId !== void 0) this.platformUserId = options.platformUserId;
|
|
251
|
-
if (options.platformUsername !== void 0) this.platformUsername = options.platformUsername;
|
|
252
|
-
if (options.platformUrl !== void 0) this.platformUrl = options.platformUrl;
|
|
253
|
-
if (options.accessToken !== void 0) this.accessToken = options.accessToken;
|
|
254
|
-
if (options.refreshToken !== void 0) this.refreshToken = options.refreshToken;
|
|
255
|
-
if (options.credentialSecretId !== void 0) this.credentialSecretId = options.credentialSecretId;
|
|
256
|
-
if (options.accessTokenSecretName !== void 0) this.accessTokenSecretName = options.accessTokenSecretName;
|
|
257
|
-
if (options.refreshTokenSecretName !== void 0) this.refreshTokenSecretName = options.refreshTokenSecretName;
|
|
258
|
-
if (options.tokenExpiresAt !== void 0) this.tokenExpiresAt = options.tokenExpiresAt;
|
|
259
|
-
if (options.isActive !== void 0) this.isActive = options.isActive;
|
|
260
|
-
if (options.defaultHashtags !== void 0) this.defaultHashtags = options.defaultHashtags;
|
|
261
|
-
if (options.scopes !== void 0) this.scopes = options.scopes;
|
|
262
|
-
if (options.missingPermissions !== void 0) this.missingPermissions = options.missingPermissions;
|
|
263
|
-
if (options.linkBehavior !== void 0) this.linkBehavior = options.linkBehavior;
|
|
264
|
-
if (options.publishMode !== void 0) this.publishMode = options.publishMode;
|
|
265
|
-
if (options.publicPublishingAllowed !== void 0) this.publicPublishingAllowed = options.publicPublishingAllowed;
|
|
266
|
-
if (options.status !== void 0) this.status = options.status;
|
|
267
|
-
if (options.errorMessage !== void 0) this.errorMessage = options.errorMessage;
|
|
268
|
-
if (options.tenantId !== void 0) this.tenantId = options.tenantId;
|
|
269
|
-
if (options.platform !== void 0) {
|
|
270
|
-
const setup = getSocialPlatformSetup(this.platform);
|
|
271
|
-
if (options.linkBehavior === void 0) this.linkBehavior = setup.defaultLinkBehavior;
|
|
272
|
-
if (options.publishMode === void 0) this.publishMode = setup.defaultPublishMode;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Social accounts need a slug identity that is scoped by tenant and platform.
|
|
277
|
-
* A newsroom may connect `@localnews` on X, YouTube, Threads, and Facebook;
|
|
278
|
-
* the generic name-derived slug would make those accounts overwrite each
|
|
279
|
-
* other through SMRT's slug/context upsert identity.
|
|
280
|
-
*/
|
|
281
|
-
async getSlug() {
|
|
282
|
-
if (!this.slug) {
|
|
283
|
-
const identity = this.platformUserId || this.platformUsername || this.name || this.id;
|
|
284
|
-
if (!identity) return this.slug;
|
|
285
|
-
const source = [
|
|
286
|
-
this.tenantId ? `tenant-${this.tenantId}` : "no-tenant",
|
|
287
|
-
this.platform,
|
|
288
|
-
identity
|
|
289
|
-
].filter(Boolean).join("-");
|
|
290
|
-
this.slug = source.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
|
|
291
|
-
}
|
|
292
|
-
return this.slug;
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Check if the token is expired or will expire soon
|
|
296
|
-
*/
|
|
297
|
-
get isTokenExpired() {
|
|
298
|
-
if (!this.tokenExpiresAt) return false;
|
|
299
|
-
return Date.now() >= this.tokenExpiresAt.getTime() - 300 * 1e3;
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Check if the account needs attention (expired or error)
|
|
303
|
-
*/
|
|
304
|
-
get needsAttention() {
|
|
305
|
-
return this.status !== "connected" || this.isTokenExpired || this.missingPermissions.length > 0 || this.publishMode === "public" && !this.publicPublishingAllowed;
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Check if the account is ready for publishing
|
|
309
|
-
*/
|
|
310
|
-
get isReady() {
|
|
311
|
-
return this.isActive && this.status === "connected" && this.hasCredentials && this.missingPermissions.length === 0 && !this.isTokenExpired && (this.publishMode !== "public" || this.publicPublishingAllowed);
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Effective publish mode after applying the public-publishing latch.
|
|
315
|
-
*/
|
|
316
|
-
get effectivePublishMode() {
|
|
317
|
-
if (this.publishMode === "public" && !this.publicPublishingAllowed) return "dry_run";
|
|
318
|
-
return this.publishMode;
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Check whether any usable credential reference exists.
|
|
322
|
-
*/
|
|
323
|
-
get hasCredentials() {
|
|
324
|
-
return Boolean(this.credentialSecretId || this.accessTokenSecretName || this.accessToken);
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Store all platform credentials in smrt-secrets as a single JSON payload.
|
|
328
|
-
*/
|
|
329
|
-
async setCredentials(credentials, options = {}) {
|
|
330
|
-
if (!this.id) this.id = randomUUID();
|
|
331
|
-
const secretName = this.credentialSecretId ?? `social-account-${this.id}`;
|
|
332
|
-
const tenantId2 = this.requireCredentialTenantId("store social account credentials");
|
|
333
|
-
await (await SecretService.create({ db: this.db })).storeForTenant(tenantId2, secretName, JSON.stringify(credentials), {
|
|
334
|
-
description: options.description ?? `Credentials for ${this.name}`,
|
|
335
|
-
category: options.category ?? "social"
|
|
336
|
-
});
|
|
337
|
-
this.credentialSecretId = secretName;
|
|
338
|
-
await this.withCredentialTenantContext(async () => {
|
|
339
|
-
await this.save();
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Retrieve platform credentials from smrt-secrets, falling back to deprecated fields.
|
|
344
|
-
*/
|
|
345
|
-
async getCredentials() {
|
|
346
|
-
if (!this.credentialSecretId) {
|
|
347
|
-
if (this.accessTokenSecretName || this.refreshTokenSecretName) {
|
|
348
|
-
const tenantId3 = this.requireCredentialTenantId("retrieve social account credentials");
|
|
349
|
-
const secretService2 = await SecretService.create({ db: this.db });
|
|
350
|
-
const credentials = {};
|
|
351
|
-
if (this.accessTokenSecretName) credentials.accessToken = (await secretService2.retrieveForTenant(tenantId3, this.accessTokenSecretName)).value;
|
|
352
|
-
if (this.refreshTokenSecretName) credentials.refreshToken = (await secretService2.retrieveForTenant(tenantId3, this.refreshTokenSecretName)).value;
|
|
353
|
-
return credentials;
|
|
354
|
-
}
|
|
355
|
-
if (!this.accessToken && !this.refreshToken) return null;
|
|
356
|
-
return {
|
|
357
|
-
accessToken: this.accessToken,
|
|
358
|
-
refreshToken: this.refreshToken
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
const credentialSecretId = this.credentialSecretId;
|
|
362
|
-
const tenantId2 = this.requireCredentialTenantId("retrieve social account credentials");
|
|
363
|
-
const secret = await (await SecretService.create({ db: this.db })).retrieveForTenant(tenantId2, credentialSecretId);
|
|
364
|
-
return JSON.parse(secret.value);
|
|
365
|
-
}
|
|
366
|
-
async withCredentialTenantContext(fn) {
|
|
367
|
-
const tenantId2 = this.getCredentialTenantId();
|
|
368
|
-
const currentTenantId = getCurrentTenant()?.tenantId;
|
|
369
|
-
if (!tenantId2 || currentTenantId === tenantId2) return fn();
|
|
370
|
-
return withTenant({ tenantId: tenantId2 }, fn);
|
|
371
|
-
}
|
|
372
|
-
getCredentialTenantId() {
|
|
373
|
-
if (this.tenantId) return this.tenantId;
|
|
374
|
-
return getCurrentTenant()?.tenantId ?? null;
|
|
375
|
-
}
|
|
376
|
-
requireCredentialTenantId(action) {
|
|
377
|
-
const tenantId2 = this.getCredentialTenantId();
|
|
378
|
-
if (!tenantId2) throw new Error(`Tenant context required to ${action}.`);
|
|
379
|
-
return tenantId2;
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
__publicField$2(SocialAccount, "__smrtPackage__", "@happyvertical/smrt-social");
|
|
383
|
-
__decorateClass$2([tenantId({ nullable: true })], SocialAccount.prototype, "tenantId", 2);
|
|
384
|
-
__decorateClass$2([field({ description: "A name you will recognise this account by." })], SocialAccount.prototype, "name", 2);
|
|
385
|
-
__decorateClass$2([field({ description: "Which platform it is on: YouTube, X, Threads or Bluesky." })], SocialAccount.prototype, "platform", 2);
|
|
386
|
-
__decorateClass$2([field({ description: "The username or handle you post under." })], SocialAccount.prototype, "platformUsername", 2);
|
|
387
|
-
__decorateClass$2([field({ description: "The web address of your profile on the platform." })], SocialAccount.prototype, "platformUrl", 2);
|
|
388
|
-
__decorateClass$2([field({ description: "Whether posts can still go out from this account." })], SocialAccount.prototype, "isActive", 2);
|
|
389
|
-
__decorateClass$2([field({ description: "Hashtags added to every post from this account." })], SocialAccount.prototype, "defaultHashtags", 2);
|
|
390
|
-
__decorateClass$2([field({ description: "Where a shared link goes: in the text, as a reply, or left out." })], SocialAccount.prototype, "linkBehavior", 2);
|
|
391
|
-
__decorateClass$2([field({ description: "Whether the account is connected, or needs signing in again." })], SocialAccount.prototype, "status", 2);
|
|
392
|
-
SocialAccount = __decorateClass$2([TenantScoped({ mode: "optional" }), smrt({
|
|
393
|
-
tableStrategy: "sti",
|
|
394
|
-
api: { include: [
|
|
395
|
-
"list",
|
|
396
|
-
"get",
|
|
397
|
-
"create",
|
|
398
|
-
"update",
|
|
399
|
-
"delete"
|
|
400
|
-
] },
|
|
401
|
-
mcp: { include: ["list", "get"] },
|
|
402
|
-
cli: { skipApiCheck: true }
|
|
403
|
-
})], SocialAccount);
|
|
404
|
-
//#endregion
|
|
405
|
-
//#region src/collections/social-account-collection.ts
|
|
406
|
-
var SocialAccountCollection = class extends SmrtCollection {
|
|
407
|
-
static _itemClass = SocialAccount;
|
|
408
|
-
async findActive(platform) {
|
|
409
|
-
return await this.list({
|
|
410
|
-
where: {
|
|
411
|
-
isActive: true,
|
|
412
|
-
...platform ? { platform } : {}
|
|
413
|
-
},
|
|
414
|
-
orderBy: "name ASC"
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
async findReady(platform) {
|
|
418
|
-
return (await this.findActive(platform)).filter((account) => account.isReady);
|
|
419
|
-
}
|
|
420
|
-
async findNeedsAttention() {
|
|
421
|
-
return (await this.list({
|
|
422
|
-
where: { isActive: true },
|
|
423
|
-
orderBy: "name ASC"
|
|
424
|
-
})).filter((account) => account.needsAttention);
|
|
425
|
-
}
|
|
426
|
-
};
|
|
5
|
+
ObjectRegistry.registerPackageManifest(JSON.parse(`{"version":"1.0.0","timestamp":0,"packageName":"@happyvertical/smrt-social","packageVersion":"0.61.6","objects":{"@happyvertical/smrt-social:OAuthStateCollection":{"name":"oauthstatecollection","className":"OAuthStateCollection","qualifiedName":"@happyvertical/smrt-social:OAuthStateCollection","collection":"oauthstates","filePath":"src/collections/oauth-state-collection.ts","packageName":"@happyvertical/smrt-social","fields":{},"methods":{"findByState":{"name":"findByState","async":true,"parameters":[{"name":"state","type":"string","optional":false}],"returnType":"Promise<OAuthState | null>","isStatic":false,"isPublic":true},"consume":{"name":"consume","async":true,"parameters":[{"name":"state","type":"OAuthState","optional":false}],"returnType":"Promise<boolean>","isStatic":false,"isPublic":true},"findExpired":{"name":"findExpired","async":true,"parameters":[{"name":"now","type":"Date","optional":true}],"returnType":"Promise<OAuthState[]>","isStatic":false,"isPublic":true},"deleteExpired":{"name":"deleteExpired","async":true,"parameters":[{"name":"now","type":"Date","optional":true}],"returnType":"Promise<number>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","delete"]},"mcp":false},"extends":"SmrtCollection","extendsTypeArg":"OAuthState","exportName":"OAuthStateCollection","collectionExportName":"OAuthStateCollectionCollection","collectionOf":"@happyvertical/smrt-social:OAuthState","inheritedExposure":["api","mcp"],"schema":{"tableName":"oauth_states","ddl":"CREATE TABLE IF NOT EXISTS \\"oauth_states\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"initiated_by_user_id\\" TEXT,\\n \\"platform\\" TEXT DEFAULT 'youtube',\\n \\"state\\" TEXT DEFAULT '',\\n \\"code_verifier\\" TEXT,\\n \\"redirect_uri\\" TEXT DEFAULT '',\\n \\"scopes\\" JSON DEFAULT '[]',\\n \\"expires_at\\" TIMESTAMP,\\n \\"created_by_user_id\\" UUID,\\n \\"return_to\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"initiated_by_user_id":{"type":"TEXT","notNull":false},"platform":{"type":"TEXT","notNull":false,"default":"youtube"},"state":{"type":"TEXT","notNull":false,"default":""},"code_verifier":{"type":"TEXT","notNull":false},"redirect_uri":{"type":"TEXT","notNull":false,"default":""},"scopes":{"type":"JSON","notNull":false,"default":[]},"expires_at":{"type":"TIMESTAMP","notNull":false},"created_by_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"return_to":{"type":"TEXT","notNull":false}},"indexes":[{"name":"oauth_states_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"oauth_states_meta_type_idx","columns":["_meta_type"]},{"name":"oauth_states_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"oauth_states_created_by_user_id_idx","columns":["created_by_user_id"]}],"version":"5ab2b26a"},"importPath":"@happyvertical/smrt-social"},"@happyvertical/smrt-social:SocialAccountCollection":{"name":"socialaccountcollection","className":"SocialAccountCollection","qualifiedName":"@happyvertical/smrt-social:SocialAccountCollection","collection":"socialaccounts","filePath":"src/collections/social-account-collection.ts","packageName":"@happyvertical/smrt-social","fields":{},"methods":{"findActive":{"name":"findActive","async":true,"parameters":[{"name":"platform","type":"SocialPlatformType","optional":true}],"returnType":"Promise<SocialAccount[]>","isStatic":false,"isPublic":true},"findReady":{"name":"findReady","async":true,"parameters":[{"name":"platform","type":"SocialPlatformType","optional":true}],"returnType":"Promise<SocialAccount[]>","isStatic":false,"isPublic":true},"findNeedsAttention":{"name":"findNeedsAttention","async":true,"parameters":[],"returnType":"Promise<SocialAccount[]>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","update","delete"]},"mcp":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"SocialAccount","exportName":"SocialAccountCollection","collectionExportName":"SocialAccountCollectionCollection","collectionOf":"@happyvertical/smrt-social:SocialAccount","inheritedExposure":["api","mcp"],"schema":{"tableName":"social_accounts","ddl":"CREATE TABLE IF NOT EXISTS \\"social_accounts\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"name\\" TEXT DEFAULT '',\\n \\"platform\\" TEXT DEFAULT 'youtube',\\n \\"platform_user_id\\" TEXT,\\n \\"platform_username\\" TEXT,\\n \\"platform_url\\" TEXT,\\n \\"access_token\\" TEXT,\\n \\"refresh_token\\" TEXT,\\n \\"credential_secret_id\\" TEXT,\\n \\"access_token_secret_name\\" TEXT,\\n \\"refresh_token_secret_name\\" TEXT,\\n \\"token_expires_at\\" TIMESTAMP,\\n \\"is_active\\" BOOLEAN DEFAULT TRUE,\\n \\"default_hashtags\\" JSON DEFAULT '[]',\\n \\"scopes\\" JSON DEFAULT '[]',\\n \\"missing_permissions\\" JSON DEFAULT '[]',\\n \\"link_behavior\\" TEXT DEFAULT 'description',\\n \\"publish_mode\\" TEXT DEFAULT 'dry_run',\\n \\"public_publishing_allowed\\" BOOLEAN DEFAULT FALSE,\\n \\"status\\" TEXT DEFAULT 'connected',\\n \\"error_message\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"name":{"type":"TEXT","notNull":false,"default":""},"platform":{"type":"TEXT","notNull":false,"default":"youtube"},"platform_user_id":{"type":"TEXT","notNull":false},"platform_username":{"type":"TEXT","notNull":false},"platform_url":{"type":"TEXT","notNull":false},"access_token":{"type":"TEXT","notNull":false},"refresh_token":{"type":"TEXT","notNull":false},"credential_secret_id":{"type":"TEXT","notNull":false},"access_token_secret_name":{"type":"TEXT","notNull":false},"refresh_token_secret_name":{"type":"TEXT","notNull":false},"token_expires_at":{"type":"TIMESTAMP","notNull":false},"is_active":{"type":"BOOLEAN","notNull":false,"default":true},"default_hashtags":{"type":"JSON","notNull":false,"default":[]},"scopes":{"type":"JSON","notNull":false,"default":[]},"missing_permissions":{"type":"JSON","notNull":false,"default":[]},"link_behavior":{"type":"TEXT","notNull":false,"default":"description"},"publish_mode":{"type":"TEXT","notNull":false,"default":"dry_run"},"public_publishing_allowed":{"type":"BOOLEAN","notNull":false,"default":false},"status":{"type":"TEXT","notNull":false,"default":"connected"},"error_message":{"type":"TEXT","notNull":false}},"indexes":[{"name":"social_accounts_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"social_accounts_meta_type_idx","columns":["_meta_type"]},{"name":"social_accounts_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"973c4ad8"},"importPath":"@happyvertical/smrt-social"},"@happyvertical/smrt-social:SocialPostAnalyticsSnapshotCollection":{"name":"socialpostanalyticssnapshotcollection","className":"SocialPostAnalyticsSnapshotCollection","qualifiedName":"@happyvertical/smrt-social:SocialPostAnalyticsSnapshotCollection","collection":"socialpostanalyticssnapshots","filePath":"src/collections/social-post-analytics-snapshot-collection.ts","packageName":"@happyvertical/smrt-social","fields":{},"methods":{"recordSnapshot":{"name":"recordSnapshot","async":true,"parameters":[{"name":"options","type":"object","optional":false,"memberTypes":["string","SocialPlatformType","PostAnalytics","RawAnalyticsPayload","Date","string | null"]}],"returnType":"Promise<SocialPostAnalyticsSnapshot>","isStatic":false,"isPublic":true},"findForPost":{"name":"findForPost","async":true,"parameters":[{"name":"socialPostId","type":"string","optional":false}],"returnType":"Promise<SocialPostAnalyticsSnapshot[]>","isStatic":false,"isPublic":true},"findLatestForPost":{"name":"findLatestForPost","async":true,"parameters":[{"name":"socialPostId","type":"string","optional":false}],"returnType":"Promise<SocialPostAnalyticsSnapshot | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","delete"]},"mcp":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"SocialPostAnalyticsSnapshot","exportName":"SocialPostAnalyticsSnapshotCollection","collectionExportName":"SocialPostAnalyticsSnapshotCollectionCollection","collectionOf":"@happyvertical/smrt-social:SocialPostAnalyticsSnapshot","inheritedExposure":["api","mcp"],"schema":{"tableName":"social_post_analytics_snapshots","ddl":"CREATE TABLE IF NOT EXISTS \\"social_post_analytics_snapshots\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"social_post_id\\" UUID,\\n \\"platform\\" TEXT,\\n \\"analytics\\" JSON,\\n \\"raw\\" JSON,\\n \\"captured_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"social_post_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"social_posts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"platform":{"type":"TEXT","notNull":false},"analytics":{"type":"JSON","notNull":false},"raw":{"type":"JSON","notNull":false},"captured_at":{"type":"TIMESTAMP","notNull":false}},"indexes":[{"name":"social_post_analytics_snapshots_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"social_post_analytics_snapshots_meta_type_idx","columns":["_meta_type"]},{"name":"social_post_analytics_snapshots_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"social_post_analytics_snapshots_social_post_id_idx","columns":["social_post_id"]}],"version":"0f4b8270"},"importPath":"@happyvertical/smrt-social"},"@happyvertical/smrt-social:SocialPostCollection":{"name":"socialpostcollection","className":"SocialPostCollection","qualifiedName":"@happyvertical/smrt-social:SocialPostCollection","collection":"socialposts","filePath":"src/collections/social-post-collection.ts","packageName":"@happyvertical/smrt-social","fields":{},"methods":{"createDraft":{"name":"createDraft","async":true,"parameters":[{"name":"options","type":"CreateSocialPostDraftOptions","optional":false}],"returnType":"Promise<SocialPost>","isStatic":false,"isPublic":true},"findByStatus":{"name":"findByStatus","async":true,"parameters":[{"name":"status","type":"PostStatus","optional":false}],"returnType":"Promise<SocialPost[]>","isStatic":false,"isPublic":true},"findForAccount":{"name":"findForAccount","async":true,"parameters":[{"name":"socialAccountId","type":"string","optional":false}],"returnType":"Promise<SocialPost[]>","isStatic":false,"isPublic":true},"findDueForPublish":{"name":"findDueForPublish","async":true,"parameters":[{"name":"now","type":"Date","optional":true}],"returnType":"Promise<SocialPost[]>","isStatic":false,"isPublic":true},"recordPublishSuccess":{"name":"recordPublishSuccess","async":true,"parameters":[{"name":"post","type":"SocialPost","optional":false},{"name":"data","type":"PublishSuccessData","optional":false}],"returnType":"Promise<SocialPost>","isStatic":false,"isPublic":true},"recordPublishFailure":{"name":"recordPublishFailure","async":true,"parameters":[{"name":"post","type":"SocialPost","optional":false},{"name":"error","type":"Error | string","optional":false,"unionBranches":[{"type":"Error"},{"type":"string"}]}],"returnType":"Promise<SocialPost>","isStatic":false,"isPublic":true},"updateLatestAnalytics":{"name":"updateLatestAnalytics","async":true,"parameters":[{"name":"post","type":"SocialPost","optional":false},{"name":"analytics","type":"PostAnalytics","optional":false},{"name":"syncedAt","type":"Date","optional":true}],"returnType":"Promise<SocialPost>","isStatic":false,"isPublic":true}},"decoratorConfig":{"api":{"include":["list","get","create","update","delete"]},"mcp":{"include":["list","get"]}},"extends":"SmrtCollection","extendsTypeArg":"SocialPost","exportName":"SocialPostCollection","collectionExportName":"SocialPostCollectionCollection","collectionOf":"@happyvertical/smrt-social:SocialPost","inheritedExposure":["api","mcp"],"schema":{"tableName":"social_posts","ddl":"CREATE TABLE IF NOT EXISTS \\"social_posts\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"social_account_id\\" UUID,\\n \\"created_by_user_id\\" UUID,\\n \\"video_content_id\\" UUID,\\n \\"content_id\\" UUID,\\n \\"post_type\\" TEXT DEFAULT 'text',\\n \\"media_url\\" TEXT,\\n \\"title\\" TEXT,\\n \\"description\\" TEXT DEFAULT '',\\n \\"hashtags\\" JSON DEFAULT '[]',\\n \\"link_url\\" TEXT,\\n \\"platform_post_id\\" TEXT,\\n \\"platform_url\\" TEXT,\\n \\"scheduled_at\\" TIMESTAMP,\\n \\"published_at\\" TIMESTAMP,\\n \\"status\\" TEXT DEFAULT 'draft',\\n \\"error_message\\" TEXT,\\n \\"analytics\\" JSON,\\n \\"analytics_last_synced_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"social_account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"social_accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"created_by_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"video_content_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"content_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"post_type":{"type":"TEXT","notNull":false,"default":"text"},"media_url":{"type":"TEXT","notNull":false},"title":{"type":"TEXT","notNull":false},"description":{"type":"TEXT","notNull":false,"default":""},"hashtags":{"type":"JSON","notNull":false,"default":[]},"link_url":{"type":"TEXT","notNull":false},"platform_post_id":{"type":"TEXT","notNull":false},"platform_url":{"type":"TEXT","notNull":false},"scheduled_at":{"type":"TIMESTAMP","notNull":false},"published_at":{"type":"TIMESTAMP","notNull":false},"status":{"type":"TEXT","notNull":false,"default":"draft"},"error_message":{"type":"TEXT","notNull":false},"analytics":{"type":"JSON","notNull":false},"analytics_last_synced_at":{"type":"TIMESTAMP","notNull":false}},"indexes":[{"name":"social_posts_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"social_posts_meta_type_idx","columns":["_meta_type"]},{"name":"social_posts_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"social_posts_social_account_id_idx","columns":["social_account_id"]},{"name":"social_posts_created_by_user_id_idx","columns":["created_by_user_id"]},{"name":"social_posts_video_content_id_idx","columns":["video_content_id"]},{"name":"social_posts_content_id_idx","columns":["content_id"]}],"version":"1006bafa"},"importPath":"@happyvertical/smrt-social"},"@happyvertical/smrt-social:OAuthState":{"name":"oauthstate","className":"OAuthState","qualifiedName":"@happyvertical/smrt-social:OAuthState","collection":"oauthstates","description":"Temporary OAuth state for social account connection","filePath":"src/oauth-state.ts","packageName":"@happyvertical/smrt-social","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","nullable","__tenancy","required"],"sqlType":"UUID","nullable":true,"required":false},"required":false},"initiatedByUserId":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"platform":{"type":"text","_meta":{"__statedOptions":["default","enum"]},"required":false,"default":"youtube","enum":["youtube","threads","x","bluesky","facebook"]},"state":{"type":"text","_meta":{"__statedOptions":["default"]},"required":false,"default":""},"codeVerifier":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"redirectUri":{"type":"text","_meta":{"__statedOptions":["default"]},"required":false,"default":""},"scopes":{"type":"json","_meta":{"__statedOptions":["default"]},"required":false,"default":[]},"expiresAt":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"createdByUserId":{"type":"crossPackageRef","_meta":{"__statedOptions":["related"]},"required":false,"related":"@happyvertical/smrt-users:User"},"returnTo":{"type":"text","_meta":{"__statedOptions":[]},"required":false}},"methods":{"verifyState":{"name":"verifyState","async":false,"parameters":[{"name":"callbackState","type":"string","optional":false}],"returnType":"boolean","isStatic":false,"isPublic":true},"generateState":{"name":"generateState","async":false,"parameters":[],"returnType":"string","isStatic":true,"isPublic":true},"generateCodeVerifier":{"name":"generateCodeVerifier","async":false,"parameters":[],"returnType":"string","isStatic":true,"isPublic":true},"generateCodeChallenge":{"name":"generateCodeChallenge","async":true,"parameters":[{"name":"verifier","type":"string","optional":false}],"returnType":"Promise<string>","isStatic":true,"isPublic":true}},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get","create","delete"]},"mcp":false,"cli":{"skipApiCheck":true},"tenantScoped":{"mode":"optional"},"conflictColumns":["tenant_id","slug","context","_meta_type"]},"extends":"SmrtObject","exportName":"OAuthState","collectionExportName":"OAuthStateCollection","schema":{"tableName":"oauth_states","ddl":"CREATE TABLE IF NOT EXISTS \\"oauth_states\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"initiated_by_user_id\\" TEXT,\\n \\"platform\\" TEXT DEFAULT 'youtube',\\n \\"state\\" TEXT DEFAULT '',\\n \\"code_verifier\\" TEXT,\\n \\"redirect_uri\\" TEXT DEFAULT '',\\n \\"scopes\\" JSON DEFAULT '[]',\\n \\"expires_at\\" TIMESTAMP,\\n \\"created_by_user_id\\" UUID,\\n \\"return_to\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"initiated_by_user_id":{"type":"TEXT","notNull":false},"platform":{"type":"TEXT","notNull":false,"default":"youtube"},"state":{"type":"TEXT","notNull":false,"default":""},"code_verifier":{"type":"TEXT","notNull":false},"redirect_uri":{"type":"TEXT","notNull":false,"default":""},"scopes":{"type":"JSON","notNull":false,"default":[]},"expires_at":{"type":"TIMESTAMP","notNull":false},"created_by_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"return_to":{"type":"TEXT","notNull":false}},"indexes":[{"name":"oauth_states_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"oauth_states_meta_type_idx","columns":["_meta_type"]},{"name":"oauth_states_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"oauth_states_created_by_user_id_idx","columns":["created_by_user_id"]}],"version":"5ab2b26a"},"importPath":"@happyvertical/smrt-social"},"@happyvertical/smrt-social:SocialAccount":{"name":"socialaccount","className":"SocialAccount","qualifiedName":"@happyvertical/smrt-social:SocialAccount","collection":"socialaccounts","description":"Connected social media account for publishing","filePath":"src/social-account.ts","packageName":"@happyvertical/smrt-social","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","nullable","__tenancy","required"],"sqlType":"UUID","nullable":true,"required":false},"required":false},"name":{"type":"text","_meta":{"__statedOptions":["description","default"],"description":"A name you will recognise this account by."},"required":false,"default":"","description":"A name you will recognise this account by."},"platform":{"type":"text","_meta":{"__statedOptions":["description","default","enum"],"description":"Which platform it is on: YouTube, X, Threads or Bluesky."},"required":false,"default":"youtube","description":"Which platform it is on: YouTube, X, Threads or Bluesky.","enum":["youtube","threads","x","bluesky","facebook"]},"platformUserId":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"platformUsername":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The username or handle you post under."},"required":false,"description":"The username or handle you post under."},"platformUrl":{"type":"text","_meta":{"__statedOptions":["description"],"description":"The web address of your profile on the platform."},"required":false,"description":"The web address of your profile on the platform."},"accessToken":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"refreshToken":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"credentialSecretId":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"accessTokenSecretName":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"refreshTokenSecretName":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"tokenExpiresAt":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"isActive":{"type":"boolean","_meta":{"__statedOptions":["description","default"],"description":"Whether posts can still go out from this account."},"required":false,"default":true,"description":"Whether posts can still go out from this account."},"defaultHashtags":{"type":"json","_meta":{"__statedOptions":["description","default"],"description":"Hashtags added to every post from this account."},"required":false,"default":[],"description":"Hashtags added to every post from this account."},"scopes":{"type":"json","_meta":{"__statedOptions":["default"]},"required":false,"default":[]},"missingPermissions":{"type":"json","_meta":{"__statedOptions":["default"]},"required":false,"default":[]},"linkBehavior":{"type":"text","_meta":{"__statedOptions":["description","default","enum"],"description":"Where a shared link goes: in the text, as a reply, or left out."},"required":false,"default":"description","description":"Where a shared link goes: in the text, as a reply, or left out.","enum":["description","inline","attachment","reply","none"]},"publishMode":{"type":"text","_meta":{"__statedOptions":["default","enum"]},"required":false,"default":"dry_run","enum":["dry_run","stage_remote","private_or_scheduled","public"]},"publicPublishingAllowed":{"type":"boolean","_meta":{"__statedOptions":["default"]},"required":false,"default":false},"status":{"type":"text","_meta":{"__statedOptions":["description","default","enum"],"description":"Whether the account is connected, or needs signing in again."},"required":false,"default":"connected","description":"Whether the account is connected, or needs signing in again.","enum":["connected","disconnected","expired","missing_permissions","error"]},"errorMessage":{"type":"text","_meta":{"__statedOptions":[]},"required":false}},"methods":{"getSlug":{"name":"getSlug","async":true,"parameters":[],"returnType":"Promise<string | null | undefined>","isStatic":false,"isPublic":true},"setCredentials":{"name":"setCredentials","async":true,"parameters":[{"name":"credentials","type":"Record<string, unknown>","optional":false},{"name":"options","type":"object","optional":true,"memberTypes":["string"]}],"returnType":"Promise<void>","isStatic":false,"isPublic":true},"getCredentials":{"name":"getCredentials","async":true,"parameters":[],"returnType":"Promise<Record<string, unknown> | null>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get","create","update","delete"]},"mcp":{"include":["list","get"]},"cli":{"skipApiCheck":true},"tenantScoped":{"mode":"optional"},"conflictColumns":["tenant_id","slug","context","_meta_type"]},"extends":"SmrtObject","exportName":"SocialAccount","collectionExportName":"SocialAccountCollection","displayLabelField":"name","schema":{"tableName":"social_accounts","ddl":"CREATE TABLE IF NOT EXISTS \\"social_accounts\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"name\\" TEXT DEFAULT '',\\n \\"platform\\" TEXT DEFAULT 'youtube',\\n \\"platform_user_id\\" TEXT,\\n \\"platform_username\\" TEXT,\\n \\"platform_url\\" TEXT,\\n \\"access_token\\" TEXT,\\n \\"refresh_token\\" TEXT,\\n \\"credential_secret_id\\" TEXT,\\n \\"access_token_secret_name\\" TEXT,\\n \\"refresh_token_secret_name\\" TEXT,\\n \\"token_expires_at\\" TIMESTAMP,\\n \\"is_active\\" BOOLEAN DEFAULT TRUE,\\n \\"default_hashtags\\" JSON DEFAULT '[]',\\n \\"scopes\\" JSON DEFAULT '[]',\\n \\"missing_permissions\\" JSON DEFAULT '[]',\\n \\"link_behavior\\" TEXT DEFAULT 'description',\\n \\"publish_mode\\" TEXT DEFAULT 'dry_run',\\n \\"public_publishing_allowed\\" BOOLEAN DEFAULT FALSE,\\n \\"status\\" TEXT DEFAULT 'connected',\\n \\"error_message\\" TEXT\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"name":{"type":"TEXT","notNull":false,"default":""},"platform":{"type":"TEXT","notNull":false,"default":"youtube"},"platform_user_id":{"type":"TEXT","notNull":false},"platform_username":{"type":"TEXT","notNull":false},"platform_url":{"type":"TEXT","notNull":false},"access_token":{"type":"TEXT","notNull":false},"refresh_token":{"type":"TEXT","notNull":false},"credential_secret_id":{"type":"TEXT","notNull":false},"access_token_secret_name":{"type":"TEXT","notNull":false},"refresh_token_secret_name":{"type":"TEXT","notNull":false},"token_expires_at":{"type":"TIMESTAMP","notNull":false},"is_active":{"type":"BOOLEAN","notNull":false,"default":true},"default_hashtags":{"type":"JSON","notNull":false,"default":[]},"scopes":{"type":"JSON","notNull":false,"default":[]},"missing_permissions":{"type":"JSON","notNull":false,"default":[]},"link_behavior":{"type":"TEXT","notNull":false,"default":"description"},"publish_mode":{"type":"TEXT","notNull":false,"default":"dry_run"},"public_publishing_allowed":{"type":"BOOLEAN","notNull":false,"default":false},"status":{"type":"TEXT","notNull":false,"default":"connected"},"error_message":{"type":"TEXT","notNull":false}},"indexes":[{"name":"social_accounts_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"social_accounts_meta_type_idx","columns":["_meta_type"]},{"name":"social_accounts_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"973c4ad8"},"importPath":"@happyvertical/smrt-social"},"@happyvertical/smrt-social:SocialPostAnalyticsSnapshot":{"name":"socialpostanalyticssnapshot","className":"SocialPostAnalyticsSnapshot","qualifiedName":"@happyvertical/smrt-social:SocialPostAnalyticsSnapshot","collection":"socialpostanalyticssnapshots","filePath":"src/social-post-analytics-snapshot.ts","packageName":"@happyvertical/smrt-social","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","nullable","__tenancy","required"],"sqlType":"UUID","nullable":true,"required":false},"required":false},"socialPostId":{"type":"foreignKey","_meta":{"__statedOptions":["description","related"],"description":"The post these numbers are for."},"required":false,"related":"SocialPost","description":"The post these numbers are for."},"platform":{"type":"text","_meta":{"__statedOptions":["description","enum"],"description":"The platform that reported the numbers."},"required":false,"description":"The platform that reported the numbers.","enum":["youtube","threads","x","bluesky","facebook"]},"analytics":{"type":"json","_meta":{"__typeUnresolved":true,"__statedOptions":["description"],"description":"The views, likes, comments, shares and clicks the platform reported."},"required":false,"description":"The views, likes, comments, shares and clicks the platform reported."},"raw":{"type":"json","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false},"capturedAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When these numbers were taken from the platform."},"required":false,"description":"When these numbers were taken from the platform."}},"methods":{},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get","create","delete"]},"mcp":{"include":["list","get"]},"cli":true,"tenantScoped":{"mode":"optional"},"conflictColumns":["tenant_id","slug","context","_meta_type"]},"extends":"SmrtObject","exportName":"SocialPostAnalyticsSnapshot","collectionExportName":"SocialPostAnalyticsSnapshotCollection","schema":{"tableName":"social_post_analytics_snapshots","ddl":"CREATE TABLE IF NOT EXISTS \\"social_post_analytics_snapshots\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"social_post_id\\" UUID,\\n \\"platform\\" TEXT,\\n \\"analytics\\" JSON,\\n \\"raw\\" JSON,\\n \\"captured_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"social_post_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"social_posts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"platform":{"type":"TEXT","notNull":false},"analytics":{"type":"JSON","notNull":false},"raw":{"type":"JSON","notNull":false},"captured_at":{"type":"TIMESTAMP","notNull":false}},"indexes":[{"name":"social_post_analytics_snapshots_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"social_post_analytics_snapshots_meta_type_idx","columns":["_meta_type"]},{"name":"social_post_analytics_snapshots_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"social_post_analytics_snapshots_social_post_id_idx","columns":["social_post_id"]}],"version":"0f4b8270"},"importPath":"@happyvertical/smrt-social"},"@happyvertical/smrt-social:SocialPost":{"name":"socialpost","className":"SocialPost","qualifiedName":"@happyvertical/smrt-social:SocialPost","collection":"socialposts","description":"Social media post for multi-platform publishing","filePath":"src/social-post.ts","packageName":"@happyvertical/smrt-social","fields":{"created_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"updated_at":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false},"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":false,"autoPopulate":true,"nullable":true,"mode":"optional","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","nullable","__tenancy","required"],"sqlType":"UUID","nullable":true,"required":false},"required":false},"socialAccountId":{"type":"foreignKey","_meta":{"__statedOptions":["description","related"],"description":"The connected account this post goes out from."},"required":false,"related":"SocialAccount","description":"The connected account this post goes out from."},"createdByUserId":{"type":"crossPackageRef","_meta":{"__statedOptions":["related"]},"required":false,"related":"@happyvertical/smrt-users:User"},"videoContentId":{"type":"crossPackageRef","_meta":{"__statedOptions":["related"]},"required":false,"related":"@happyvertical/smrt-video:VideoShot"},"contentId":{"type":"crossPackageRef","_meta":{"__statedOptions":["related"]},"required":false,"related":"@happyvertical/smrt-content:Content"},"postType":{"type":"text","_meta":{"__statedOptions":["description","default","enum"],"description":"What kind of post it is: text, link, image or video."},"required":false,"default":"text","description":"What kind of post it is: text, link, image or video.","enum":["text","link","image","video"]},"mediaUrl":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"title":{"type":"text","_meta":{"__statedOptions":["description"],"description":"A title, for platforms that show one."},"required":false,"description":"A title, for platforms that show one."},"description":{"type":"text","_meta":{"__statedOptions":["description","default"],"description":"The words of the post."},"required":false,"default":"","description":"The words of the post."},"hashtags":{"type":"json","_meta":{"__statedOptions":["description","default"],"description":"Hashtags added to the end of the post."},"required":false,"default":[],"description":"Hashtags added to the end of the post."},"linkUrl":{"type":"text","_meta":{"__statedOptions":["description"],"description":"A web address to share with the post."},"required":false,"description":"A web address to share with the post."},"platformPostId":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"platformUrl":{"type":"text","_meta":{"__statedOptions":["description"],"description":"Where the post can be seen on the platform, once it is out."},"required":false,"description":"Where the post can be seen on the platform, once it is out."},"scheduledAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"The date and time you have in mind for putting the post out. Only a note of the plan: publishing is a separate step your application has to run."},"required":false,"description":"The date and time you have in mind for putting the post out. Only a note of the plan: publishing is a separate step your application has to run."},"publishedAt":{"type":"datetime","_meta":{"__statedOptions":["description"],"description":"When the post actually went out."},"required":false,"description":"When the post actually went out."},"status":{"type":"text","_meta":{"__statedOptions":["description","default","enum"],"description":"Where the post stands: draft, waiting to go out, published or failed."},"required":false,"default":"draft","description":"Where the post stands: draft, waiting to go out, published or failed.","enum":["draft","pending_approval","approved","scheduled","publishing","dry_run","staged","published","failed","cancelled"]},"errorMessage":{"type":"text","_meta":{"__statedOptions":[]},"required":false},"analytics":{"type":"json","_meta":{"__typeUnresolved":true,"__statedOptions":[]},"required":false},"analyticsLastSyncedAt":{"type":"datetime","_meta":{"__statedOptions":[]},"required":false}},"methods":{},"decoratorConfig":{"tableStrategy":"sti","api":{"include":["list","get","create","update","delete"]},"mcp":{"include":["list","get"]},"cli":true,"tenantScoped":{"mode":"optional"},"conflictColumns":["tenant_id","slug","context","_meta_type"]},"extends":"SmrtObject","exportName":"SocialPost","collectionExportName":"SocialPostCollection","displayLabelField":"title","schema":{"tableName":"social_posts","ddl":"CREATE TABLE IF NOT EXISTS \\"social_posts\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"_meta_type\\" TEXT NOT NULL,\\n \\"_meta_data\\" JSON,\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID,\\n \\"social_account_id\\" UUID,\\n \\"created_by_user_id\\" UUID,\\n \\"video_content_id\\" UUID,\\n \\"content_id\\" UUID,\\n \\"post_type\\" TEXT DEFAULT 'text',\\n \\"media_url\\" TEXT,\\n \\"title\\" TEXT,\\n \\"description\\" TEXT DEFAULT '',\\n \\"hashtags\\" JSON DEFAULT '[]',\\n \\"link_url\\" TEXT,\\n \\"platform_post_id\\" TEXT,\\n \\"platform_url\\" TEXT,\\n \\"scheduled_at\\" TIMESTAMP,\\n \\"published_at\\" TIMESTAMP,\\n \\"status\\" TEXT DEFAULT 'draft',\\n \\"error_message\\" TEXT,\\n \\"analytics\\" JSON,\\n \\"analytics_last_synced_at\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"_meta_type":{"type":"TEXT","notNull":true},"_meta_data":{"type":"JSON","notNull":false},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":false},"social_account_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"foreignKey":{"table":"social_accounts","column":"id","onDelete":"NO ACTION","onUpdate":"CASCADE"}},"created_by_user_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"video_content_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"content_id":{"type":"UUID","referenceKind":"crossPackageRef","notNull":false},"post_type":{"type":"TEXT","notNull":false,"default":"text"},"media_url":{"type":"TEXT","notNull":false},"title":{"type":"TEXT","notNull":false},"description":{"type":"TEXT","notNull":false,"default":""},"hashtags":{"type":"JSON","notNull":false,"default":[]},"link_url":{"type":"TEXT","notNull":false},"platform_post_id":{"type":"TEXT","notNull":false},"platform_url":{"type":"TEXT","notNull":false},"scheduled_at":{"type":"TIMESTAMP","notNull":false},"published_at":{"type":"TIMESTAMP","notNull":false},"status":{"type":"TEXT","notNull":false,"default":"draft"},"error_message":{"type":"TEXT","notNull":false},"analytics":{"type":"JSON","notNull":false},"analytics_last_synced_at":{"type":"TIMESTAMP","notNull":false}},"indexes":[{"name":"social_posts_slug_context_meta_type_idx","columns":["tenant_id","slug","context","_meta_type"],"unique":true,"nullsNotDistinct":true},{"name":"social_posts_meta_type_idx","columns":["_meta_type"]},{"name":"social_posts_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"social_posts_social_account_id_idx","columns":["social_account_id"]},{"name":"social_posts_created_by_user_id_idx","columns":["created_by_user_id"]},{"name":"social_posts_video_content_id_idx","columns":["video_content_id"]},{"name":"social_posts_content_id_idx","columns":["content_id"]}],"version":"1006bafa"},"importPath":"@happyvertical/smrt-social"}},"moduleType":"smrt","recipes":[{"id":"social.posts","className":"SocialPostsRecipe","label":"Social","summary":"Write posts for your YouTube, X, Threads and Bluesky accounts, plan when they go out and see how each one did.","synonyms":["social media","social posts","social accounts","youtube","bluesky","threads","tweets","post results"],"models":["@happyvertical/smrt-social:SocialPost","@happyvertical/smrt-social:SocialAccount","@happyvertical/smrt-social:SocialPostAnalyticsSnapshot"],"nav":[{"label":"Posts","model":"@happyvertical/smrt-social:SocialPost","icon":"fileText","description":"What you have written for each account and where it stands.","noun":"post"},{"label":"Connected accounts","model":"@happyvertical/smrt-social:SocialAccount","icon":"users","description":"The social accounts you can post to, and their settings.","noun":"account"}],"requires":[],"section":{"id":"publish","label":"Publish","icon":"fileText","description":"What you write, record and put out."},"options":{"@happyvertical/smrt-social:SocialPost":{"fields":{"socialAccountId":{"label":"Account","order":1},"title":{"order":2},"description":{"label":"Text","order":3},"hashtags":{"order":4},"linkUrl":{"label":"Link","order":5},"postType":{"label":"Kind of post","order":6},"scheduledAt":{"label":"Planned for","order":7},"status":{"locked":true,"order":8},"publishedAt":{"label":"Published on","locked":true,"order":9},"platformUrl":{"label":"Link to the post","locked":true,"order":10},"videoContentId":{"label":"Video","visibility":"advanced"},"contentId":{"label":"Content","visibility":"advanced"},"mediaUrl":{"label":"Media link","visibility":"advanced"},"errorMessage":{"label":"What went wrong","visibility":"advanced"},"analyticsLastSyncedAt":{"label":"Results last updated","visibility":"advanced"},"tenantId":{"visibility":"hidden"},"createdByUserId":{"visibility":"hidden"},"platformPostId":{"visibility":"hidden"},"analytics":{"visibility":"hidden"}}},"@happyvertical/smrt-social:SocialAccount":{"fields":{"name":{"order":1},"platform":{"order":2},"platformUsername":{"label":"Username","order":3},"platformUrl":{"label":"Profile link","order":4},"status":{"locked":true,"order":5},"isActive":{"label":"In use","order":6},"defaultHashtags":{"order":7},"linkBehavior":{"label":"Where links go","order":8},"publishMode":{"label":"Publishing mode","visibility":"advanced"},"publicPublishingAllowed":{"label":"Allow public posts","visibility":"advanced"},"platformUserId":{"visibility":"advanced"},"tokenExpiresAt":{"label":"Connection expires","visibility":"advanced"},"scopes":{"label":"Permissions granted","visibility":"advanced"},"missingPermissions":{"visibility":"advanced"},"errorMessage":{"label":"What went wrong","visibility":"advanced"},"tenantId":{"visibility":"hidden"},"accessToken":{"visibility":"hidden"},"refreshToken":{"visibility":"hidden"},"credentialSecretId":{"visibility":"hidden"},"accessTokenSecretName":{"visibility":"hidden"},"refreshTokenSecretName":{"visibility":"hidden"}}},"@happyvertical/smrt-social:SocialPostAnalyticsSnapshot":{"fields":{"socialPostId":{"label":"Post","order":1},"platform":{"order":2},"capturedAt":{"label":"Measured on","order":3},"analytics":{"label":"Numbers","order":4},"tenantId":{"visibility":"hidden"},"raw":{"visibility":"hidden"}}}},"help":{"markdown":"## Overview\\n\\nSocial is where you write what you want to put out on YouTube, X, Threads and\\nBluesky. Each post is written for one connected account, with its text,\\nhashtags and an optional link, and can carry the date you plan to put it out.\\nYour app does the publishing; once a post is out, the platform's numbers for it\\narrive here as post results.\\n\\n## Tasks\\n\\n### Connect an account\\n\\n1. Open the connected accounts and choose **New**.\\n2. Give it a **{field:SocialAccount.name}** you will recognise, such as \\"Acme Corp on Bluesky\\".\\n3. Pick the **{field:SocialAccount.platform}** and type the **{field:SocialAccount.platformUsername}** you post under.\\n4. Add any **{field:SocialAccount.defaultHashtags}** you want on every post from this account.\\n5. Save. Signing in to the platform itself happens from your app, not in this form; the **{field:SocialAccount.status}** shows whether the account is connected.\\n\\n### Write a post\\n\\n1. Open the posts and choose **New**.\\n2. Pick the **{field:SocialPost.socialAccountId}** it is for.\\n3. Write the **{field:SocialPost.description}** and add any **{field:SocialPost.hashtags}**.\\n4. Give it a **{field:SocialPost.title}** if the platform shows one, and a **{field:SocialPost.linkUrl}** if you are sharing a page.\\n5. Save. It stays a draft until your app puts it out.\\n\\n### Note when a post should go out\\n\\n1. Open the post and set **{field:SocialPost.scheduledAt}** to the date and time you have in mind.\\n2. Save. This only records the plan on the post. Nothing here publishes it: a post goes out only when your application's own publishing step approves it and sends it at that time, so check with whoever set up your app that this step is in place.\\n\\n### See where a post stands\\n\\nOpen the post. Its **{field:SocialPost.status}** shows whether it is a draft,\\nwaiting to go out, published or failed. Once it is out, **{field:SocialPost.publishedAt}**\\nand the **{field:SocialPost.platformUrl}** are filled in.\\n\\n### Change or remove a post\\n\\n1. Open the post and change what you need, then save.\\n2. To remove it, open the post and choose **Delete**.\\n\\n### See how a post did\\n\\nPost results are written by the platform sync, not by hand; you can only read\\nthem here.\\n\\n1. Open the post and look at its results, listed under the post.\\n2. Each result names the **{field:SocialPostAnalyticsSnapshot.socialPostId}** it belongs to and the **{field:SocialPostAnalyticsSnapshot.platform}** it ran on.\\n3. Each result shows the **{field:SocialPostAnalyticsSnapshot.analytics}** the platform reported and when they were **{field:SocialPostAnalyticsSnapshot.capturedAt}**, so the newest one is the latest count.\\n\\n### Stop using an account\\n\\n1. Open the account and untick **{field:SocialAccount.isActive}**, then save. Its posts stay, but nothing new goes out from it.\\n2. To remove it entirely, open the account and choose **Delete**.\\n","fieldRefs":["SocialAccount.defaultHashtags","SocialAccount.isActive","SocialAccount.name","SocialAccount.platform","SocialAccount.platformUsername","SocialAccount.status","SocialPost.description","SocialPost.hashtags","SocialPost.linkUrl","SocialPost.platformUrl","SocialPost.publishedAt","SocialPost.scheduledAt","SocialPost.socialAccountId","SocialPost.status","SocialPost.title","SocialPostAnalyticsSnapshot.analytics","SocialPostAnalyticsSnapshot.capturedAt","SocialPostAnalyticsSnapshot.platform","SocialPostAnalyticsSnapshot.socialPostId"]},"demo":{"mode":"server","reasons":["Needs a server because its package does not build for a browser: node:crypto; and its package depends on @happyvertical/smrt-agents, @happyvertical/smrt-chat, @happyvertical/smrt-content, @happyvertical/smrt-images, @happyvertical/smrt-jobs, @happyvertical/smrt-profiles, @happyvertical/smrt-reports, @happyvertical/smrt-secrets, @happyvertical/smrt-tenancy, @happyvertical/smrt-users, which do not build for a browser (#3615, #3617, #3624, #3625, #3626, #3627, #3628)."]}}],"smrtDependencies":["@happyvertical/smrt-content","@happyvertical/smrt-core","@happyvertical/smrt-secrets","@happyvertical/smrt-tenancy","@happyvertical/smrt-video"],"browser":{"status":"server-only","issues":["#3615","#3617","#3624","#3625","#3626","#3627","#3628"],"reason":"node:crypto","via":["@happyvertical/smrt-agents","@happyvertical/smrt-chat","@happyvertical/smrt-content","@happyvertical/smrt-images","@happyvertical/smrt-jobs","@happyvertical/smrt-profiles","@happyvertical/smrt-reports","@happyvertical/smrt-secrets","@happyvertical/smrt-tenancy","@happyvertical/smrt-users"]},"stampsConstructors":true}`));
|
|
427
6
|
//#endregion
|
|
428
7
|
//#region src/social-post.ts
|
|
429
8
|
var __defProp$1 = Object.defineProperty;
|