vidspotai-shared 1.0.82 → 1.0.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (442) hide show
  1. package/lib/globals/aiModels/enums.d.ts +11 -1
  2. package/lib/globals/aiModels/enums.d.ts.map +1 -1
  3. package/lib/globals/aiModels/enums.js +24 -1
  4. package/lib/globals/aiModels/index.d.ts.map +1 -1
  5. package/lib/globals/aiModels/index.js +2 -0
  6. package/lib/globals/aiModels/providers/anthropic.d.ts +12 -0
  7. package/lib/globals/aiModels/providers/anthropic.d.ts.map +1 -0
  8. package/lib/globals/aiModels/providers/anthropic.js +88 -0
  9. package/lib/globals/aiModels/providers/google.d.ts.map +1 -1
  10. package/lib/globals/aiModels/providers/google.js +82 -0
  11. package/lib/globals/aiModels/providers/openai.d.ts.map +1 -1
  12. package/lib/globals/aiModels/providers/openai.js +63 -4
  13. package/lib/globals/aiModels/tierHelpers.d.ts +12 -0
  14. package/lib/globals/aiModels/tierHelpers.d.ts.map +1 -1
  15. package/lib/globals/aiModels/tierHelpers.js +83 -0
  16. package/lib/globals/aiModels/types.d.ts +19 -0
  17. package/lib/globals/aiModels/types.d.ts.map +1 -1
  18. package/lib/globals/types.d.ts +120 -1
  19. package/lib/globals/types.d.ts.map +1 -1
  20. package/lib/globals/types.js +135 -1
  21. package/lib/models/agent.model.d.ts +41 -1
  22. package/lib/models/agent.model.d.ts.map +1 -1
  23. package/lib/models/index.d.ts +1 -0
  24. package/lib/models/index.d.ts.map +1 -1
  25. package/lib/models/index.js +1 -0
  26. package/lib/models/social.model.d.ts +180 -0
  27. package/lib/models/social.model.d.ts.map +1 -0
  28. package/lib/models/social.model.js +2 -0
  29. package/lib/models/user.model.d.ts +10 -0
  30. package/lib/models/user.model.d.ts.map +1 -1
  31. package/lib/models/video.model.d.ts +6 -0
  32. package/lib/models/video.model.d.ts.map +1 -1
  33. package/lib/schemas/brief.schema.d.ts +46 -0
  34. package/lib/schemas/brief.schema.d.ts.map +1 -1
  35. package/lib/schemas/brief.schema.js +72 -1
  36. package/lib/schemas/index.d.ts +1 -0
  37. package/lib/schemas/index.d.ts.map +1 -1
  38. package/lib/schemas/index.js +1 -0
  39. package/lib/schemas/project.schema.d.ts +67 -0
  40. package/lib/schemas/project.schema.d.ts.map +1 -1
  41. package/lib/schemas/project.schema.js +12 -0
  42. package/lib/schemas/social.schema.d.ts +91 -0
  43. package/lib/schemas/social.schema.d.ts.map +1 -0
  44. package/lib/schemas/social.schema.js +114 -0
  45. package/lib/schemas/videoPlan.schema.d.ts +114 -0
  46. package/lib/schemas/videoPlan.schema.d.ts.map +1 -1
  47. package/lib/schemas/videoPlan.schema.js +141 -1
  48. package/lib/services/agent/chatAgent.d.ts +25 -1
  49. package/lib/services/agent/chatAgent.d.ts.map +1 -1
  50. package/lib/services/agent/chatAgent.js +145 -9
  51. package/lib/services/agent/costPreflight.d.ts +11 -1
  52. package/lib/services/agent/costPreflight.d.ts.map +1 -1
  53. package/lib/services/agent/costPreflight.js +18 -1
  54. package/lib/services/agent/covers/coverPlanner.d.ts +41 -0
  55. package/lib/services/agent/covers/coverPlanner.d.ts.map +1 -0
  56. package/lib/services/agent/covers/coverPlanner.js +278 -0
  57. package/lib/services/agent/covers/covers.schema.d.ts +158 -0
  58. package/lib/services/agent/covers/covers.schema.d.ts.map +1 -0
  59. package/lib/services/agent/covers/covers.schema.js +166 -0
  60. package/lib/services/agent/covers/index.d.ts +3 -0
  61. package/lib/services/agent/covers/index.d.ts.map +1 -0
  62. package/lib/services/agent/covers/index.js +18 -0
  63. package/lib/services/agent/critic.d.ts +10 -0
  64. package/lib/services/agent/critic.d.ts.map +1 -1
  65. package/lib/services/agent/critic.js +37 -1
  66. package/lib/services/agent/editClassifier.d.ts +2 -2
  67. package/lib/services/agent/editClassifier.js +2 -2
  68. package/lib/services/agent/editExisting/editAssembler.d.ts +78 -0
  69. package/lib/services/agent/editExisting/editAssembler.d.ts.map +1 -0
  70. package/lib/services/agent/editExisting/editAssembler.js +172 -0
  71. package/lib/services/agent/editExisting/editExisting.schema.d.ts +119 -0
  72. package/lib/services/agent/editExisting/editExisting.schema.d.ts.map +1 -0
  73. package/lib/services/agent/editExisting/editExisting.schema.js +157 -0
  74. package/lib/services/agent/editExisting/highlightPicker.d.ts +48 -0
  75. package/lib/services/agent/editExisting/highlightPicker.d.ts.map +1 -0
  76. package/lib/services/agent/editExisting/highlightPicker.js +199 -0
  77. package/lib/services/agent/editExisting/index.d.ts +4 -0
  78. package/lib/services/agent/editExisting/index.d.ts.map +1 -0
  79. package/lib/services/agent/editExisting/index.js +19 -0
  80. package/lib/services/agent/eval/seedBriefs.d.ts +4 -3
  81. package/lib/services/agent/eval/seedBriefs.d.ts.map +1 -1
  82. package/lib/services/agent/eval/seedBriefs.js +283 -3
  83. package/lib/services/agent/eval/types.d.ts +10 -0
  84. package/lib/services/agent/eval/types.d.ts.map +1 -1
  85. package/lib/services/agent/executor/core.d.ts +70 -0
  86. package/lib/services/agent/executor/core.d.ts.map +1 -0
  87. package/lib/services/agent/executor/core.js +250 -0
  88. package/lib/services/agent/executor/duration.d.ts +20 -0
  89. package/lib/services/agent/executor/duration.d.ts.map +1 -0
  90. package/lib/services/agent/executor/duration.js +46 -0
  91. package/lib/services/agent/executor/index.d.ts +15 -0
  92. package/lib/services/agent/executor/index.d.ts.map +1 -0
  93. package/lib/services/agent/executor/index.js +32 -0
  94. package/lib/services/agent/executor/types.d.ts +183 -0
  95. package/lib/services/agent/executor/types.d.ts.map +1 -0
  96. package/lib/services/agent/executor/types.js +29 -0
  97. package/lib/services/agent/executor/visual.d.ts +32 -0
  98. package/lib/services/agent/executor/visual.d.ts.map +1 -0
  99. package/lib/services/agent/executor/visual.js +400 -0
  100. package/lib/services/agent/executor/voice.d.ts +17 -0
  101. package/lib/services/agent/executor/voice.d.ts.map +1 -0
  102. package/lib/services/agent/executor/voice.js +119 -0
  103. package/lib/services/agent/extendChain.d.ts +101 -0
  104. package/lib/services/agent/extendChain.d.ts.map +1 -0
  105. package/lib/services/agent/extendChain.js +177 -0
  106. package/lib/services/agent/index.d.ts +11 -1
  107. package/lib/services/agent/index.d.ts.map +1 -1
  108. package/lib/services/agent/index.js +11 -1
  109. package/lib/services/agent/llmCaller.d.ts +7 -8
  110. package/lib/services/agent/llmCaller.d.ts.map +1 -1
  111. package/lib/services/agent/llmCallerAnthropic.d.ts +44 -31
  112. package/lib/services/agent/llmCallerAnthropic.d.ts.map +1 -1
  113. package/lib/services/agent/llmCallerAnthropic.js +135 -60
  114. package/lib/services/agent/llmCallerFactory.d.ts +34 -0
  115. package/lib/services/agent/llmCallerFactory.d.ts.map +1 -0
  116. package/lib/services/agent/llmCallerFactory.js +31 -0
  117. package/lib/services/agent/llmCallerGemini.d.ts +62 -0
  118. package/lib/services/agent/llmCallerGemini.d.ts.map +1 -0
  119. package/lib/services/agent/llmCallerGemini.js +235 -0
  120. package/lib/services/agent/llmCallerOpenai.d.ts +56 -0
  121. package/lib/services/agent/llmCallerOpenai.d.ts.map +1 -0
  122. package/lib/services/agent/llmCallerOpenai.js +230 -0
  123. package/lib/services/agent/llmCallerRegistry.d.ts.map +1 -1
  124. package/lib/services/agent/llmCallerRegistry.js +7 -7
  125. package/lib/services/agent/llmCallerRouting.d.ts +63 -0
  126. package/lib/services/agent/llmCallerRouting.d.ts.map +1 -0
  127. package/lib/services/agent/llmCallerRouting.js +124 -0
  128. package/lib/services/agent/llmModelRegistry.d.ts +59 -0
  129. package/lib/services/agent/llmModelRegistry.d.ts.map +1 -0
  130. package/lib/services/agent/llmModelRegistry.js +168 -0
  131. package/lib/services/agent/llmRetry.d.ts +57 -0
  132. package/lib/services/agent/llmRetry.d.ts.map +1 -0
  133. package/lib/services/agent/llmRetry.js +102 -0
  134. package/lib/services/agent/modelRouter.d.ts +3 -3
  135. package/lib/services/agent/modelRouter.d.ts.map +1 -1
  136. package/lib/services/agent/modelRouter.js +27 -13
  137. package/lib/services/agent/planMutations.d.ts +54 -1
  138. package/lib/services/agent/planMutations.d.ts.map +1 -1
  139. package/lib/services/agent/planMutations.js +78 -0
  140. package/lib/services/agent/planner/Planner.d.ts +0 -17
  141. package/lib/services/agent/planner/Planner.d.ts.map +1 -1
  142. package/lib/services/agent/planner/Planner.js +67 -303
  143. package/lib/services/agent/planner/overlayRegen.d.ts +38 -0
  144. package/lib/services/agent/planner/overlayRegen.d.ts.map +1 -0
  145. package/lib/services/agent/planner/overlayRegen.js +145 -0
  146. package/lib/services/agent/planner/plannerMessages.d.ts +34 -0
  147. package/lib/services/agent/planner/plannerMessages.d.ts.map +1 -0
  148. package/lib/services/agent/planner/plannerMessages.js +185 -0
  149. package/lib/services/agent/planner/promptSections.d.ts +12 -0
  150. package/lib/services/agent/planner/promptSections.d.ts.map +1 -1
  151. package/lib/services/agent/planner/promptSections.js +57 -0
  152. package/lib/services/agent/planner/scriptFirstPlanner.d.ts +35 -0
  153. package/lib/services/agent/planner/scriptFirstPlanner.d.ts.map +1 -0
  154. package/lib/services/agent/planner/scriptFirstPlanner.js +140 -0
  155. package/lib/services/agent/planner/structuralRules.d.ts +10 -0
  156. package/lib/services/agent/planner/structuralRules.d.ts.map +1 -1
  157. package/lib/services/agent/planner/structuralRules.js +92 -9
  158. package/lib/services/agent/planner/validators.d.ts +18 -0
  159. package/lib/services/agent/planner/validators.d.ts.map +1 -1
  160. package/lib/services/agent/planner/validators.js +97 -0
  161. package/lib/services/agent/planner.d.ts +2 -1
  162. package/lib/services/agent/planner.d.ts.map +1 -1
  163. package/lib/services/agent/planner.js +5 -1
  164. package/lib/services/agent/priorProject.d.ts +26 -0
  165. package/lib/services/agent/priorProject.d.ts.map +1 -0
  166. package/lib/services/agent/priorProject.js +51 -0
  167. package/lib/services/agent/providerFallback/chains.d.ts.map +1 -1
  168. package/lib/services/agent/providerFallback/chains.js +27 -15
  169. package/lib/services/agent/repurpose/index.d.ts +3 -0
  170. package/lib/services/agent/repurpose/index.d.ts.map +1 -0
  171. package/lib/services/agent/repurpose/index.js +18 -0
  172. package/lib/services/agent/repurpose/repurpose.schema.d.ts +132 -0
  173. package/lib/services/agent/repurpose/repurpose.schema.d.ts.map +1 -0
  174. package/lib/services/agent/repurpose/repurpose.schema.js +144 -0
  175. package/lib/services/agent/repurpose/shortsPicker.d.ts +25 -0
  176. package/lib/services/agent/repurpose/shortsPicker.d.ts.map +1 -0
  177. package/lib/services/agent/repurpose/shortsPicker.js +218 -0
  178. package/lib/services/agent/runHelpers.d.ts +21 -2
  179. package/lib/services/agent/runHelpers.d.ts.map +1 -1
  180. package/lib/services/agent/runHelpers.js +71 -2
  181. package/lib/services/agent/tools/animateImage.tool.d.ts +1 -0
  182. package/lib/services/agent/tools/animateImage.tool.d.ts.map +1 -1
  183. package/lib/services/agent/tools/animateImage.tool.js +12 -0
  184. package/lib/services/agent/tools/chapterOutline.tool.d.ts +42 -0
  185. package/lib/services/agent/tools/chapterOutline.tool.d.ts.map +1 -0
  186. package/lib/services/agent/tools/chapterOutline.tool.js +115 -0
  187. package/lib/services/agent/tools/composeScene.tool.d.ts +63 -0
  188. package/lib/services/agent/tools/composeScene.tool.d.ts.map +1 -1
  189. package/lib/services/agent/tools/estimateCost.tool.d.ts +27 -0
  190. package/lib/services/agent/tools/estimateCost.tool.d.ts.map +1 -1
  191. package/lib/services/agent/tools/estimateCost.tool.js +55 -7
  192. package/lib/services/agent/tools/extendVideo.tool.d.ts +26 -0
  193. package/lib/services/agent/tools/extendVideo.tool.d.ts.map +1 -0
  194. package/lib/services/agent/tools/extendVideo.tool.js +149 -0
  195. package/lib/services/agent/tools/generateScript.tool.d.ts +184 -0
  196. package/lib/services/agent/tools/generateScript.tool.d.ts.map +1 -0
  197. package/lib/services/agent/tools/generateScript.tool.js +123 -0
  198. package/lib/services/agent/tools/generateVideo.tool.d.ts +1 -0
  199. package/lib/services/agent/tools/generateVideo.tool.d.ts.map +1 -1
  200. package/lib/services/agent/tools/generateVideo.tool.js +20 -1
  201. package/lib/services/agent/tools/index.d.ts +4 -0
  202. package/lib/services/agent/tools/index.d.ts.map +1 -1
  203. package/lib/services/agent/tools/index.js +4 -0
  204. package/lib/services/agent/tools/matchBrollToScript.tool.d.ts +50 -0
  205. package/lib/services/agent/tools/matchBrollToScript.tool.d.ts.map +1 -0
  206. package/lib/services/agent/tools/matchBrollToScript.tool.js +139 -0
  207. package/lib/services/agent/tools/planVideo.tool.d.ts +56 -0
  208. package/lib/services/agent/tools/planVideo.tool.d.ts.map +1 -1
  209. package/lib/services/agent/tools/planVideo.tool.js +3 -3
  210. package/lib/services/agent/tools/render.tool.d.ts +21 -0
  211. package/lib/services/agent/tools/render.tool.d.ts.map +1 -1
  212. package/lib/services/aiGen/aiGenFactory.service.d.ts.map +1 -1
  213. package/lib/services/aiGen/aiGenFactory.service.js +18 -3
  214. package/lib/services/aiGen/providers/anthropic/anthropic.service.d.ts +26 -0
  215. package/lib/services/aiGen/providers/anthropic/anthropic.service.d.ts.map +1 -0
  216. package/lib/services/aiGen/providers/anthropic/anthropic.service.js +95 -0
  217. package/lib/services/aiGen/providers/google/google.service.d.ts +24 -1
  218. package/lib/services/aiGen/providers/google/google.service.d.ts.map +1 -1
  219. package/lib/services/aiGen/providers/google/google.service.js +87 -243
  220. package/lib/services/aiGen/providers/google/googleErrors.d.ts +13 -0
  221. package/lib/services/aiGen/providers/google/googleErrors.d.ts.map +1 -0
  222. package/lib/services/aiGen/providers/google/googleErrors.js +102 -0
  223. package/lib/services/aiGen/providers/google/googleFetch.d.ts +8 -0
  224. package/lib/services/aiGen/providers/google/googleFetch.d.ts.map +1 -0
  225. package/lib/services/aiGen/providers/google/googleFetch.js +96 -0
  226. package/lib/services/aiGen/providers/google/googleMusic.d.ts +15 -0
  227. package/lib/services/aiGen/providers/google/googleMusic.d.ts.map +1 -0
  228. package/lib/services/aiGen/providers/google/googleMusic.js +77 -0
  229. package/lib/services/aiGen/providers/kling/kling.service.d.ts +7 -3
  230. package/lib/services/aiGen/providers/kling/kling.service.d.ts.map +1 -1
  231. package/lib/services/aiGen/providers/kling/kling.service.js +23 -367
  232. package/lib/services/aiGen/providers/kling/klingCredits.d.ts +9 -0
  233. package/lib/services/aiGen/providers/kling/klingCredits.d.ts.map +1 -0
  234. package/lib/services/aiGen/providers/kling/klingCredits.js +63 -0
  235. package/lib/services/aiGen/providers/kling/klingRequests.d.ts +32 -0
  236. package/lib/services/aiGen/providers/kling/klingRequests.d.ts.map +1 -0
  237. package/lib/services/aiGen/providers/kling/klingRequests.js +194 -0
  238. package/lib/services/aiGen/providers/kling/klingStatus.d.ts +16 -0
  239. package/lib/services/aiGen/providers/kling/klingStatus.d.ts.map +1 -0
  240. package/lib/services/aiGen/providers/kling/klingStatus.js +173 -0
  241. package/lib/services/bullmq.service.d.ts +61 -0
  242. package/lib/services/bullmq.service.d.ts.map +1 -1
  243. package/lib/services/bullmq.service.js +101 -1
  244. package/lib/services/crypto/index.d.ts +2 -0
  245. package/lib/services/crypto/index.d.ts.map +1 -0
  246. package/lib/services/crypto/index.js +17 -0
  247. package/lib/services/crypto/tokenVault.d.ts +47 -0
  248. package/lib/services/crypto/tokenVault.d.ts.map +1 -0
  249. package/lib/services/crypto/tokenVault.js +179 -0
  250. package/lib/services/editor/captionStyleHint.d.ts +3 -0
  251. package/lib/services/editor/captionStyleHint.d.ts.map +1 -0
  252. package/lib/services/editor/captionStyleHint.js +112 -0
  253. package/lib/services/editor/planToProject.d.ts +7 -66
  254. package/lib/services/editor/planToProject.d.ts.map +1 -1
  255. package/lib/services/editor/planToProject.helpers.d.ts +40 -0
  256. package/lib/services/editor/planToProject.helpers.d.ts.map +1 -0
  257. package/lib/services/editor/planToProject.helpers.js +177 -0
  258. package/lib/services/editor/planToProject.js +197 -180
  259. package/lib/services/editor/planToProject.types.d.ts +94 -0
  260. package/lib/services/editor/planToProject.types.d.ts.map +1 -0
  261. package/lib/services/editor/planToProject.types.js +2 -0
  262. package/lib/services/firestore.service.d.ts +5 -0
  263. package/lib/services/firestore.service.d.ts.map +1 -1
  264. package/lib/services/firestore.service.js +13 -0
  265. package/lib/services/index.d.ts +12 -0
  266. package/lib/services/index.d.ts.map +1 -1
  267. package/lib/services/index.js +12 -0
  268. package/lib/services/promptEnhancer/index.d.ts +18 -0
  269. package/lib/services/promptEnhancer/index.d.ts.map +1 -0
  270. package/lib/services/promptEnhancer/index.js +33 -0
  271. package/lib/services/promptEnhancer/models.d.ts +54 -0
  272. package/lib/services/promptEnhancer/models.d.ts.map +1 -0
  273. package/lib/services/promptEnhancer/models.js +37 -0
  274. package/lib/services/promptEnhancer/profiles/agent.profile.d.ts +14 -0
  275. package/lib/services/promptEnhancer/profiles/agent.profile.d.ts.map +1 -0
  276. package/lib/services/promptEnhancer/profiles/agent.profile.js +40 -0
  277. package/lib/services/promptEnhancer/profiles/avatar.profile.d.ts +13 -0
  278. package/lib/services/promptEnhancer/profiles/avatar.profile.d.ts.map +1 -0
  279. package/lib/services/promptEnhancer/profiles/avatar.profile.js +40 -0
  280. package/lib/services/promptEnhancer/profiles/base.d.ts +28 -0
  281. package/lib/services/promptEnhancer/profiles/base.d.ts.map +1 -0
  282. package/lib/services/promptEnhancer/profiles/base.js +35 -0
  283. package/lib/services/promptEnhancer/profiles/image.profile.d.ts +11 -0
  284. package/lib/services/promptEnhancer/profiles/image.profile.d.ts.map +1 -0
  285. package/lib/services/promptEnhancer/profiles/image.profile.js +42 -0
  286. package/lib/services/promptEnhancer/profiles/index.d.ts +12 -0
  287. package/lib/services/promptEnhancer/profiles/index.d.ts.map +1 -0
  288. package/lib/services/promptEnhancer/profiles/index.js +33 -0
  289. package/lib/services/promptEnhancer/profiles/video.profile.d.ts +15 -0
  290. package/lib/services/promptEnhancer/profiles/video.profile.d.ts.map +1 -0
  291. package/lib/services/promptEnhancer/profiles/video.profile.js +81 -0
  292. package/lib/services/promptEnhancer/promptEnhancer.service.d.ts +45 -0
  293. package/lib/services/promptEnhancer/promptEnhancer.service.d.ts.map +1 -0
  294. package/lib/services/promptEnhancer/promptEnhancer.service.js +157 -0
  295. package/lib/services/promptEnhancer/schema.d.ts +19 -0
  296. package/lib/services/promptEnhancer/schema.d.ts.map +1 -0
  297. package/lib/services/promptEnhancer/schema.js +43 -0
  298. package/lib/services/promptEnhancer/types.d.ts +112 -0
  299. package/lib/services/promptEnhancer/types.d.ts.map +1 -0
  300. package/lib/services/promptEnhancer/types.js +2 -0
  301. package/lib/services/socialAI/captionGen.d.ts +81 -0
  302. package/lib/services/socialAI/captionGen.d.ts.map +1 -0
  303. package/lib/services/socialAI/captionGen.js +206 -0
  304. package/lib/services/socialAI/hookScore.d.ts +85 -0
  305. package/lib/services/socialAI/hookScore.d.ts.map +1 -0
  306. package/lib/services/socialAI/hookScore.js +170 -0
  307. package/lib/services/socialAI/index.d.ts +3 -0
  308. package/lib/services/socialAI/index.d.ts.map +1 -0
  309. package/lib/services/socialAI/index.js +18 -0
  310. package/lib/services/socialAccounts/index.d.ts +2 -0
  311. package/lib/services/socialAccounts/index.d.ts.map +1 -0
  312. package/lib/services/socialAccounts/index.js +17 -0
  313. package/lib/services/socialAccounts/socialAccountService.d.ts +25 -0
  314. package/lib/services/socialAccounts/socialAccountService.d.ts.map +1 -0
  315. package/lib/services/socialAccounts/socialAccountService.js +105 -0
  316. package/lib/services/socialEngage/factory.d.ts +7 -0
  317. package/lib/services/socialEngage/factory.d.ts.map +1 -0
  318. package/lib/services/socialEngage/factory.js +25 -0
  319. package/lib/services/socialEngage/index.d.ts +6 -0
  320. package/lib/services/socialEngage/index.d.ts.map +1 -0
  321. package/lib/services/socialEngage/index.js +21 -0
  322. package/lib/services/socialEngage/meta.engage.d.ts +17 -0
  323. package/lib/services/socialEngage/meta.engage.d.ts.map +1 -0
  324. package/lib/services/socialEngage/meta.engage.js +128 -0
  325. package/lib/services/socialEngage/metaWebhook.d.ts +50 -0
  326. package/lib/services/socialEngage/metaWebhook.d.ts.map +1 -0
  327. package/lib/services/socialEngage/metaWebhook.js +93 -0
  328. package/lib/services/socialEngage/types.d.ts +72 -0
  329. package/lib/services/socialEngage/types.d.ts.map +1 -0
  330. package/lib/services/socialEngage/types.js +10 -0
  331. package/lib/services/socialEngage/youtube.engage.d.ts +9 -0
  332. package/lib/services/socialEngage/youtube.engage.d.ts.map +1 -0
  333. package/lib/services/socialEngage/youtube.engage.js +87 -0
  334. package/lib/services/socialFormat/aspectGeometry.d.ts +74 -0
  335. package/lib/services/socialFormat/aspectGeometry.d.ts.map +1 -0
  336. package/lib/services/socialFormat/aspectGeometry.js +135 -0
  337. package/lib/services/socialFormat/index.d.ts +2 -0
  338. package/lib/services/socialFormat/index.d.ts.map +1 -0
  339. package/lib/services/socialFormat/index.js +19 -0
  340. package/lib/services/socialInsights/index.d.ts +3 -0
  341. package/lib/services/socialInsights/index.d.ts.map +1 -0
  342. package/lib/services/socialInsights/index.js +18 -0
  343. package/lib/services/socialInsights/recommendations.d.ts +131 -0
  344. package/lib/services/socialInsights/recommendations.d.ts.map +1 -0
  345. package/lib/services/socialInsights/recommendations.js +277 -0
  346. package/lib/services/socialInsights/timeBuckets.d.ts +35 -0
  347. package/lib/services/socialInsights/timeBuckets.d.ts.map +1 -0
  348. package/lib/services/socialInsights/timeBuckets.js +78 -0
  349. package/lib/services/socialMetrics/factory.d.ts +5 -0
  350. package/lib/services/socialMetrics/factory.d.ts.map +1 -0
  351. package/lib/services/socialMetrics/factory.js +24 -0
  352. package/lib/services/socialMetrics/index.d.ts +6 -0
  353. package/lib/services/socialMetrics/index.d.ts.map +1 -0
  354. package/lib/services/socialMetrics/index.js +21 -0
  355. package/lib/services/socialMetrics/meta.metrics.d.ts +22 -0
  356. package/lib/services/socialMetrics/meta.metrics.d.ts.map +1 -0
  357. package/lib/services/socialMetrics/meta.metrics.js +137 -0
  358. package/lib/services/socialMetrics/tiktok.metrics.d.ts +8 -0
  359. package/lib/services/socialMetrics/tiktok.metrics.d.ts.map +1 -0
  360. package/lib/services/socialMetrics/tiktok.metrics.js +43 -0
  361. package/lib/services/socialMetrics/types.d.ts +54 -0
  362. package/lib/services/socialMetrics/types.d.ts.map +1 -0
  363. package/lib/services/socialMetrics/types.js +2 -0
  364. package/lib/services/socialMetrics/youtube.metrics.d.ts +8 -0
  365. package/lib/services/socialMetrics/youtube.metrics.d.ts.map +1 -0
  366. package/lib/services/socialMetrics/youtube.metrics.js +43 -0
  367. package/lib/services/socialOAuth/factory.d.ts +7 -0
  368. package/lib/services/socialOAuth/factory.d.ts.map +1 -0
  369. package/lib/services/socialOAuth/factory.js +42 -0
  370. package/lib/services/socialOAuth/index.d.ts +11 -0
  371. package/lib/services/socialOAuth/index.d.ts.map +1 -0
  372. package/lib/services/socialOAuth/index.js +26 -0
  373. package/lib/services/socialOAuth/linkedin.oauth.d.ts +14 -0
  374. package/lib/services/socialOAuth/linkedin.oauth.d.ts.map +1 -0
  375. package/lib/services/socialOAuth/linkedin.oauth.js +127 -0
  376. package/lib/services/socialOAuth/meta.oauth.d.ts +31 -0
  377. package/lib/services/socialOAuth/meta.oauth.d.ts.map +1 -0
  378. package/lib/services/socialOAuth/meta.oauth.js +214 -0
  379. package/lib/services/socialOAuth/oauthState.d.ts +14 -0
  380. package/lib/services/socialOAuth/oauthState.d.ts.map +1 -0
  381. package/lib/services/socialOAuth/oauthState.js +66 -0
  382. package/lib/services/socialOAuth/pinterest.oauth.d.ts +15 -0
  383. package/lib/services/socialOAuth/pinterest.oauth.d.ts.map +1 -0
  384. package/lib/services/socialOAuth/pinterest.oauth.js +126 -0
  385. package/lib/services/socialOAuth/threads.oauth.d.ts +14 -0
  386. package/lib/services/socialOAuth/threads.oauth.d.ts.map +1 -0
  387. package/lib/services/socialOAuth/threads.oauth.js +129 -0
  388. package/lib/services/socialOAuth/tiktok.oauth.d.ts +15 -0
  389. package/lib/services/socialOAuth/tiktok.oauth.d.ts.map +1 -0
  390. package/lib/services/socialOAuth/tiktok.oauth.js +151 -0
  391. package/lib/services/socialOAuth/types.d.ts +67 -0
  392. package/lib/services/socialOAuth/types.d.ts.map +1 -0
  393. package/lib/services/socialOAuth/types.js +2 -0
  394. package/lib/services/socialOAuth/x.oauth.d.ts +17 -0
  395. package/lib/services/socialOAuth/x.oauth.d.ts.map +1 -0
  396. package/lib/services/socialOAuth/x.oauth.js +134 -0
  397. package/lib/services/socialOAuth/youtube.oauth.d.ts +15 -0
  398. package/lib/services/socialOAuth/youtube.oauth.d.ts.map +1 -0
  399. package/lib/services/socialOAuth/youtube.oauth.js +156 -0
  400. package/lib/services/socialPublish/factory.d.ts +5 -0
  401. package/lib/services/socialPublish/factory.d.ts.map +1 -0
  402. package/lib/services/socialPublish/factory.js +32 -0
  403. package/lib/services/socialPublish/index.d.ts +10 -0
  404. package/lib/services/socialPublish/index.d.ts.map +1 -0
  405. package/lib/services/socialPublish/index.js +25 -0
  406. package/lib/services/socialPublish/linkedin.publish.d.ts +9 -0
  407. package/lib/services/socialPublish/linkedin.publish.d.ts.map +1 -0
  408. package/lib/services/socialPublish/linkedin.publish.js +143 -0
  409. package/lib/services/socialPublish/meta.publish.d.ts +28 -0
  410. package/lib/services/socialPublish/meta.publish.d.ts.map +1 -0
  411. package/lib/services/socialPublish/meta.publish.js +149 -0
  412. package/lib/services/socialPublish/pinterest.publish.d.ts +13 -0
  413. package/lib/services/socialPublish/pinterest.publish.d.ts.map +1 -0
  414. package/lib/services/socialPublish/pinterest.publish.js +130 -0
  415. package/lib/services/socialPublish/threads.publish.d.ts +12 -0
  416. package/lib/services/socialPublish/threads.publish.d.ts.map +1 -0
  417. package/lib/services/socialPublish/threads.publish.js +96 -0
  418. package/lib/services/socialPublish/tiktok.publish.d.ts +13 -0
  419. package/lib/services/socialPublish/tiktok.publish.d.ts.map +1 -0
  420. package/lib/services/socialPublish/tiktok.publish.js +118 -0
  421. package/lib/services/socialPublish/types.d.ts +47 -0
  422. package/lib/services/socialPublish/types.d.ts.map +1 -0
  423. package/lib/services/socialPublish/types.js +2 -0
  424. package/lib/services/socialPublish/x.publish.d.ts +12 -0
  425. package/lib/services/socialPublish/x.publish.d.ts.map +1 -0
  426. package/lib/services/socialPublish/x.publish.js +147 -0
  427. package/lib/services/socialPublish/youtube.publish.d.ts +9 -0
  428. package/lib/services/socialPublish/youtube.publish.d.ts.map +1 -0
  429. package/lib/services/socialPublish/youtube.publish.js +107 -0
  430. package/lib/services/stock/index.d.ts +2 -0
  431. package/lib/services/stock/index.d.ts.map +1 -0
  432. package/lib/services/stock/index.js +17 -0
  433. package/lib/services/stock/realPersonSafety.d.ts +99 -0
  434. package/lib/services/stock/realPersonSafety.d.ts.map +1 -0
  435. package/lib/services/stock/realPersonSafety.js +248 -0
  436. package/lib/utils/index.d.ts +1 -0
  437. package/lib/utils/index.d.ts.map +1 -1
  438. package/lib/utils/index.js +1 -0
  439. package/lib/utils/renderTier.d.ts +26 -0
  440. package/lib/utils/renderTier.d.ts.map +1 -0
  441. package/lib/utils/renderTier.js +34 -0
  442. package/package.json +1 -1
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LinkedInOAuthProvider = void 0;
4
+ const types_1 = require("../../globals/types");
5
+ const logger_1 = require("../../utils/logger");
6
+ /**
7
+ * LinkedIn OAuth provider. Phase 6 — fast-follow adapter.
8
+ *
9
+ * Config (env):
10
+ * LINKEDIN_CLIENT_ID
11
+ * LINKEDIN_CLIENT_SECRET
12
+ *
13
+ * Notes / gates (plan §G15-17):
14
+ * - Member posting uses `w_member_social` + OpenID (`openid profile`). Company-
15
+ * page posting + analytics is the Community Management API — vetted via a
16
+ * screencast review (business-tier G-features), requested via business scopes.
17
+ * - Refresh tokens are only issued to approved Marketing Developer Platform
18
+ * apps; standard apps get a 60-day access token and must re-consent. `refresh`
19
+ * still tries the refresh grant for approved apps.
20
+ */
21
+ const AUTH_ENDPOINT = "https://www.linkedin.com/oauth/v2/authorization";
22
+ const TOKEN_ENDPOINT = "https://www.linkedin.com/oauth/v2/accessToken";
23
+ const USERINFO_ENDPOINT = "https://api.linkedin.com/v2/userinfo";
24
+ const BASE_SCOPES = ["openid", "profile", "w_member_social"];
25
+ const BUSINESS_SCOPES = ["r_organization_social", "w_organization_social"];
26
+ class LinkedInOAuthProvider {
27
+ constructor() {
28
+ this.provider = types_1.ESocialProvider.LINKEDIN;
29
+ }
30
+ clientId() {
31
+ const v = process.env.LINKEDIN_CLIENT_ID;
32
+ if (!v)
33
+ throw new Error("LinkedInOAuth: LINKEDIN_CLIENT_ID not set");
34
+ return v;
35
+ }
36
+ clientSecret() {
37
+ const v = process.env.LINKEDIN_CLIENT_SECRET;
38
+ if (!v)
39
+ throw new Error("LinkedInOAuth: LINKEDIN_CLIENT_SECRET not set");
40
+ return v;
41
+ }
42
+ getAuthUrl({ state, redirectUri, requestBusinessScopes, }) {
43
+ const scopes = requestBusinessScopes
44
+ ? [...BASE_SCOPES, ...BUSINESS_SCOPES]
45
+ : BASE_SCOPES;
46
+ const params = new URLSearchParams({
47
+ response_type: "code",
48
+ client_id: this.clientId(),
49
+ redirect_uri: redirectUri,
50
+ state,
51
+ scope: scopes.join(" "),
52
+ });
53
+ return `${AUTH_ENDPOINT}?${params.toString()}`;
54
+ }
55
+ async exchangeCode({ code, redirectUri, }) {
56
+ const token = await this.postToken(new URLSearchParams({
57
+ grant_type: "authorization_code",
58
+ code,
59
+ redirect_uri: redirectUri,
60
+ client_id: this.clientId(),
61
+ client_secret: this.clientSecret(),
62
+ }));
63
+ if (!token.access_token) {
64
+ throw new Error("LinkedInOAuth: token exchange returned no access_token");
65
+ }
66
+ const tokens = this.toTokens(token);
67
+ const account = await this.resolveAccount(token.access_token);
68
+ return { account, tokens };
69
+ }
70
+ async refresh(refreshToken) {
71
+ const token = await this.postToken(new URLSearchParams({
72
+ grant_type: "refresh_token",
73
+ refresh_token: refreshToken,
74
+ client_id: this.clientId(),
75
+ client_secret: this.clientSecret(),
76
+ }));
77
+ if (!token.access_token) {
78
+ throw new Error("LinkedInOAuth: refresh returned no access_token");
79
+ }
80
+ const tokens = this.toTokens(token);
81
+ if (!tokens.refreshToken)
82
+ tokens.refreshToken = refreshToken;
83
+ return tokens;
84
+ }
85
+ async postToken(body) {
86
+ const resp = await fetch(TOKEN_ENDPOINT, {
87
+ method: "POST",
88
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
89
+ body: body.toString(),
90
+ });
91
+ const json = (await resp.json());
92
+ if (!resp.ok || json.error) {
93
+ throw new Error(`LinkedInOAuth: token endpoint ${resp.status} ${json.error ?? ""} ${json.error_description ?? ""}`.trim());
94
+ }
95
+ return json;
96
+ }
97
+ toTokens(token) {
98
+ const now = Date.now();
99
+ return {
100
+ accessToken: token.access_token,
101
+ refreshToken: token.refresh_token,
102
+ expiresAt: now + (token.expires_in ?? 60 * 24 * 3600) * 1000,
103
+ refreshExpiresAt: token.refresh_token_expires_in
104
+ ? now + token.refresh_token_expires_in * 1000
105
+ : undefined,
106
+ scopes: token.scope ? token.scope.split(" ").filter(Boolean) : [],
107
+ };
108
+ }
109
+ async resolveAccount(accessToken) {
110
+ const resp = await fetch(USERINFO_ENDPOINT, {
111
+ headers: { Authorization: `Bearer ${accessToken}` },
112
+ });
113
+ const json = (await resp.json());
114
+ if (!resp.ok || !json.sub) {
115
+ throw new Error(`LinkedInOAuth: userinfo ${resp.status}`);
116
+ }
117
+ logger_1.logger.info("LinkedInOAuth: connected", { sub: json.sub });
118
+ return {
119
+ // Store the bare member id; the publisher builds urn:li:person:{id}.
120
+ providerAccountId: json.sub,
121
+ displayName: json.name ?? "LinkedIn member",
122
+ avatarUrl: json.picture,
123
+ kind: types_1.ESocialAccountKind.PERSONAL,
124
+ };
125
+ }
126
+ }
127
+ exports.LinkedInOAuthProvider = LinkedInOAuthProvider;
@@ -0,0 +1,31 @@
1
+ import { ESocialProvider } from "../../globals/types";
2
+ import { AuthUrlParams, ConnectResult, ExchangeCodeParams, ISocialOAuthProvider, OAuthTokens } from "./types";
3
+ export declare class MetaOAuthProvider implements ISocialOAuthProvider {
4
+ readonly provider: ESocialProvider;
5
+ /** Which surface this instance resolves: FACEBOOK (Pages) or INSTAGRAM. */
6
+ private readonly target;
7
+ constructor(target: ESocialProvider);
8
+ private graphVersion;
9
+ private graph;
10
+ private appId;
11
+ private appSecret;
12
+ getAuthUrl({ state, redirectUri, requestBusinessScopes, }: AuthUrlParams): string;
13
+ /**
14
+ * Single-account path is unused for Meta (one grant → many accounts), but the
15
+ * interface requires it. We return the first resolved account so any caller
16
+ * that ignores `exchangeCodeMulti` still gets something sensible.
17
+ */
18
+ exchangeCode(params: ExchangeCodeParams): Promise<ConnectResult>;
19
+ exchangeCodeMulti(params: ExchangeCodeParams): Promise<ConnectResult[]>;
20
+ private resolveFacebookPages;
21
+ private resolveInstagramAccounts;
22
+ private pageTokens;
23
+ /**
24
+ * Meta Page tokens don't expire, so refresh should never be called by the
25
+ * daemon (far-future expiry). If it is, surface a reconnect rather than
26
+ * silently returning a possibly-revoked token.
27
+ */
28
+ refresh(): Promise<OAuthTokens>;
29
+ private getJson;
30
+ }
31
+ //# sourceMappingURL=meta.oauth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.oauth.d.ts","sourceRoot":"","sources":["../../../src/services/socialOAuth/meta.oauth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE1E,OAAO,EACL,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACZ,MAAM,SAAS,CAAC;AAiFjB,qBAAa,iBAAkB,YAAW,oBAAoB;IAC5D,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IAEnC,2EAA2E;IAC3E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;gBAE7B,MAAM,EAAE,eAAe;IAWnC,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,KAAK;IAMb,OAAO,CAAC,SAAS;IAMjB,UAAU,CAAC,EACT,KAAK,EACL,WAAW,EACX,qBAAqB,GACtB,EAAE,aAAa,GAAG,MAAM;IAczB;;;;OAIG;IACG,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC;IAahE,iBAAiB,CACrB,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,aAAa,EAAE,CAAC;YAgDb,oBAAoB;YA8BpB,wBAAwB;IAgCtC,OAAO,CAAC,UAAU;IASlB;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC;YAMvB,OAAO;CAYtB"}
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MetaOAuthProvider = void 0;
4
+ const types_1 = require("../../globals/types");
5
+ const logger_1 = require("../../utils/logger");
6
+ /**
7
+ * Meta (Facebook + Instagram) OAuth provider — Phase 3 of the Social Suite.
8
+ *
9
+ * One Facebook Login grant unlocks BOTH surfaces: every FB Page the user manages
10
+ * and each Page's linked IG Business/Creator account. We therefore key the OAuth
11
+ * factory with BOTH ESocialProvider.FACEBOOK and ESocialProvider.INSTAGRAM, each
12
+ * constructing a MetaOAuthProvider whose `target` decides which accounts the
13
+ * callback persists (Pages vs IG accounts). The auth dialog + token exchange are
14
+ * identical for both.
15
+ *
16
+ * Token model (important — differs from YouTube):
17
+ * - We exchange the short-lived user token for a LONG-LIVED user token
18
+ * (`fb_exchange_token`, ~60 days).
19
+ * - We then read `/me/accounts`, whose Page access tokens — when derived from a
20
+ * long-lived user token — DO NOT EXPIRE. We store the Page token per account
21
+ * and use it for both FB and the linked IG account (IG publishing/insights run
22
+ * through the managing Page token). So there is no refresh token and no
23
+ * proactive refresh; we set a far-future expiry and let a 401 on use trigger a
24
+ * reconnect. (Plan §3.)
25
+ *
26
+ * Config (env):
27
+ * META_APP_ID — Meta app id
28
+ * META_APP_SECRET — Meta app secret
29
+ * META_GRAPH_VERSION (optional, default v21.0)
30
+ */
31
+ const DEFAULT_GRAPH_VERSION = "v21.0";
32
+ /** Pages/IG publishing + insights. Business scopes add lead/ads management. */
33
+ const BASE_SCOPES = [
34
+ "pages_show_list",
35
+ "pages_read_engagement",
36
+ "pages_manage_posts",
37
+ "business_management",
38
+ "instagram_basic",
39
+ "instagram_content_publish",
40
+ "instagram_manage_insights",
41
+ "read_insights",
42
+ ];
43
+ const BUSINESS_SCOPES = [
44
+ "pages_manage_engagement", // comment moderation (G-features)
45
+ "instagram_manage_comments",
46
+ "leads_retrieval",
47
+ "ads_management",
48
+ ];
49
+ /** Page tokens from a long-lived user token don't expire; use a far horizon. */
50
+ const PAGE_TOKEN_HORIZON_MS = 1000 * 60 * 60 * 24 * 365 * 5;
51
+ class MetaOAuthProvider {
52
+ constructor(target) {
53
+ if (target !== types_1.ESocialProvider.FACEBOOK &&
54
+ target !== types_1.ESocialProvider.INSTAGRAM) {
55
+ throw new Error(`MetaOAuth: unsupported target '${target}'`);
56
+ }
57
+ this.provider = target;
58
+ this.target = target;
59
+ }
60
+ graphVersion() {
61
+ return process.env.META_GRAPH_VERSION || DEFAULT_GRAPH_VERSION;
62
+ }
63
+ graph(path) {
64
+ return `https://graph.facebook.com/${this.graphVersion()}${path}`;
65
+ }
66
+ appId() {
67
+ const id = process.env.META_APP_ID;
68
+ if (!id)
69
+ throw new Error("MetaOAuth: META_APP_ID not set");
70
+ return id;
71
+ }
72
+ appSecret() {
73
+ const secret = process.env.META_APP_SECRET;
74
+ if (!secret)
75
+ throw new Error("MetaOAuth: META_APP_SECRET not set");
76
+ return secret;
77
+ }
78
+ getAuthUrl({ state, redirectUri, requestBusinessScopes, }) {
79
+ const scopes = requestBusinessScopes
80
+ ? [...BASE_SCOPES, ...BUSINESS_SCOPES]
81
+ : BASE_SCOPES;
82
+ const params = new URLSearchParams({
83
+ client_id: this.appId(),
84
+ redirect_uri: redirectUri,
85
+ response_type: "code",
86
+ scope: scopes.join(","),
87
+ state,
88
+ });
89
+ return `https://www.facebook.com/${this.graphVersion()}/dialog/oauth?${params.toString()}`;
90
+ }
91
+ /**
92
+ * Single-account path is unused for Meta (one grant → many accounts), but the
93
+ * interface requires it. We return the first resolved account so any caller
94
+ * that ignores `exchangeCodeMulti` still gets something sensible.
95
+ */
96
+ async exchangeCode(params) {
97
+ const all = await this.exchangeCodeMulti(params);
98
+ const first = all[0];
99
+ if (!first) {
100
+ throw new Error(this.target === types_1.ESocialProvider.INSTAGRAM
101
+ ? "MetaOAuth: no IG Business account linked to any managed Page"
102
+ : "MetaOAuth: no Facebook Pages found on this account");
103
+ }
104
+ return first;
105
+ }
106
+ async exchangeCodeMulti(params) {
107
+ const { code, redirectUri } = params;
108
+ // 1. code → short-lived user token.
109
+ const short = await this.getJson(this.graph(`/oauth/access_token?${new URLSearchParams({
110
+ client_id: this.appId(),
111
+ client_secret: this.appSecret(),
112
+ redirect_uri: redirectUri,
113
+ code,
114
+ }).toString()}`));
115
+ if (!short.access_token) {
116
+ throw new Error(`MetaOAuth: code exchange returned no token ${short.error?.message ?? ""}`.trim());
117
+ }
118
+ // 2. short-lived → long-lived user token (~60d).
119
+ const longLived = await this.getJson(this.graph(`/oauth/access_token?${new URLSearchParams({
120
+ grant_type: "fb_exchange_token",
121
+ client_id: this.appId(),
122
+ client_secret: this.appSecret(),
123
+ fb_exchange_token: short.access_token,
124
+ }).toString()}`));
125
+ const userToken = longLived.access_token ?? short.access_token;
126
+ // 3. List managed Pages (each carries a Page access token).
127
+ const pages = await this.getJson(this.graph(`/me/accounts?fields=id,name,access_token,instagram_business_account&access_token=${encodeURIComponent(userToken)}`));
128
+ const list = pages.data ?? [];
129
+ if (!list.length) {
130
+ logger_1.logger.warn("MetaOAuth: user manages no Pages", { target: this.target });
131
+ return [];
132
+ }
133
+ return this.target === types_1.ESocialProvider.FACEBOOK
134
+ ? await this.resolveFacebookPages(list)
135
+ : await this.resolveInstagramAccounts(list);
136
+ }
137
+ async resolveFacebookPages(pages) {
138
+ const out = [];
139
+ for (const p of pages) {
140
+ if (!p.id || !p.access_token)
141
+ continue;
142
+ let avatarUrl;
143
+ try {
144
+ const pic = await this.getJson(this.graph(`/${p.id}/picture?type=large&redirect=false&access_token=${encodeURIComponent(p.access_token)}`));
145
+ avatarUrl = pic.data?.url;
146
+ }
147
+ catch {
148
+ // avatar is best-effort
149
+ }
150
+ out.push({
151
+ account: {
152
+ providerAccountId: p.id,
153
+ displayName: p.name ?? "Facebook Page",
154
+ avatarUrl,
155
+ kind: types_1.ESocialAccountKind.PAGE,
156
+ },
157
+ tokens: this.pageTokens(p.access_token),
158
+ });
159
+ }
160
+ return out;
161
+ }
162
+ async resolveInstagramAccounts(pages) {
163
+ const out = [];
164
+ for (const p of pages) {
165
+ const igId = p.instagram_business_account?.id;
166
+ if (!igId || !p.access_token)
167
+ continue;
168
+ let profile = {};
169
+ try {
170
+ profile = await this.getJson(this.graph(`/${igId}?fields=username,name,profile_picture_url&access_token=${encodeURIComponent(p.access_token)}`));
171
+ }
172
+ catch {
173
+ // profile lookup is best-effort
174
+ }
175
+ out.push({
176
+ account: {
177
+ providerAccountId: igId,
178
+ displayName: profile.name ?? profile.username ?? "Instagram account",
179
+ handle: profile.username,
180
+ avatarUrl: profile.profile_picture_url,
181
+ kind: types_1.ESocialAccountKind.BUSINESS,
182
+ },
183
+ // IG publishing/insights run through the managing Page's token.
184
+ tokens: this.pageTokens(p.access_token),
185
+ });
186
+ }
187
+ return out;
188
+ }
189
+ pageTokens(pageToken) {
190
+ return {
191
+ accessToken: pageToken,
192
+ // No refresh token: Page tokens from a long-lived user token don't expire.
193
+ expiresAt: Date.now() + PAGE_TOKEN_HORIZON_MS,
194
+ scopes: [],
195
+ };
196
+ }
197
+ /**
198
+ * Meta Page tokens don't expire, so refresh should never be called by the
199
+ * daemon (far-future expiry). If it is, surface a reconnect rather than
200
+ * silently returning a possibly-revoked token.
201
+ */
202
+ async refresh() {
203
+ throw new Error("MetaOAuth: page tokens are long-lived — reconnect required if revoked");
204
+ }
205
+ async getJson(url) {
206
+ const resp = await fetch(url);
207
+ const json = (await resp.json());
208
+ if (!resp.ok || json.error) {
209
+ throw new Error(`MetaOAuth: graph ${resp.status} ${json.error?.message ?? ""}`.trim());
210
+ }
211
+ return json;
212
+ }
213
+ }
214
+ exports.MetaOAuthProvider = MetaOAuthProvider;
@@ -0,0 +1,14 @@
1
+ import { ESocialProvider } from "../../globals/types";
2
+ export interface OAuthStatePayload {
3
+ userId: string;
4
+ provider: ESocialProvider;
5
+ /** App path to return to after connect (optional). */
6
+ returnTo?: string;
7
+ /** Whether business-tier scopes were requested. */
8
+ business?: boolean;
9
+ }
10
+ /** Produce a signed state string to hand to the provider's auth URL. */
11
+ export declare function signOAuthState(payload: OAuthStatePayload, nonce: string): string;
12
+ /** Verify + decode a state string. Returns null if invalid, forged, or expired. */
13
+ export declare function verifyOAuthState(state: string): OAuthStatePayload | null;
14
+ //# sourceMappingURL=oauthState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauthState.d.ts","sourceRoot":"","sources":["../../../src/services/socialOAuth/oauthState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAetD,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,eAAe,CAAC;IAC1B,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAgCD,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAIhF;AAED,mFAAmF;AACnF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAuBxE"}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.signOAuthState = signOAuthState;
4
+ exports.verifyOAuthState = verifyOAuthState;
5
+ const crypto_1 = require("crypto");
6
+ const tokenVault_1 = require("../crypto/tokenVault");
7
+ /**
8
+ * Stateless, signed OAuth `state` for the social connect flow. The OAuth
9
+ * callback (`/v1/social/oauth/callback/:provider`) is UNAUTHENTICATED — the
10
+ * provider redirects the browser there with no Firebase token — so we carry the
11
+ * initiating user's id inside a signed, time-boxed `state` rather than a server
12
+ * session. HMAC-SHA256 prevents forgery; the TTL bounds replay.
13
+ *
14
+ * Secret: `SOCIAL_OAUTH_STATE_SECRET`, falling back to `SOCIAL_TOKEN_ENC_KEY`.
15
+ */
16
+ const TTL_MS = 10 * 60 * 1000; // 10 minutes to complete consent
17
+ function secret() {
18
+ const s = process.env.SOCIAL_OAUTH_STATE_SECRET ?? process.env.SOCIAL_TOKEN_ENC_KEY;
19
+ if (!s) {
20
+ throw new Error("oauthState: set SOCIAL_OAUTH_STATE_SECRET (or SOCIAL_TOKEN_ENC_KEY)");
21
+ }
22
+ return s;
23
+ }
24
+ function b64url(buf) {
25
+ return buf
26
+ .toString("base64")
27
+ .replace(/\+/g, "-")
28
+ .replace(/\//g, "_")
29
+ .replace(/=+$/, "");
30
+ }
31
+ function sign(body) {
32
+ return b64url((0, crypto_1.createHmac)("sha256", secret()).update(body).digest());
33
+ }
34
+ /** Produce a signed state string to hand to the provider's auth URL. */
35
+ function signOAuthState(payload, nonce) {
36
+ const full = { ...payload, iat: Date.now(), n: nonce };
37
+ const body = b64url(Buffer.from(JSON.stringify(full), "utf8"));
38
+ return `${body}.${sign(body)}`;
39
+ }
40
+ /** Verify + decode a state string. Returns null if invalid, forged, or expired. */
41
+ function verifyOAuthState(state) {
42
+ const dot = state.lastIndexOf(".");
43
+ if (dot <= 0)
44
+ return null;
45
+ const body = state.slice(0, dot);
46
+ const sig = state.slice(dot + 1);
47
+ if (!(0, tokenVault_1.safeEqual)(sig, sign(body)))
48
+ return null;
49
+ try {
50
+ const json = Buffer.from(body.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8");
51
+ const parsed = JSON.parse(json);
52
+ if (!parsed.userId || !parsed.provider)
53
+ return null;
54
+ if (Date.now() - parsed.iat > TTL_MS)
55
+ return null;
56
+ return {
57
+ userId: parsed.userId,
58
+ provider: parsed.provider,
59
+ returnTo: parsed.returnTo,
60
+ business: parsed.business,
61
+ };
62
+ }
63
+ catch {
64
+ return null;
65
+ }
66
+ }
@@ -0,0 +1,15 @@
1
+ import { ESocialProvider } from "../../globals/types";
2
+ import { AuthUrlParams, ConnectResult, ExchangeCodeParams, ISocialOAuthProvider, OAuthTokens } from "./types";
3
+ export declare class PinterestOAuthProvider implements ISocialOAuthProvider {
4
+ readonly provider = ESocialProvider.PINTEREST;
5
+ private clientId;
6
+ private clientSecret;
7
+ private basicAuth;
8
+ getAuthUrl({ state, redirectUri, requestBusinessScopes, }: AuthUrlParams): string;
9
+ exchangeCode({ code, redirectUri, }: ExchangeCodeParams): Promise<ConnectResult>;
10
+ refresh(refreshToken: string): Promise<OAuthTokens>;
11
+ private postToken;
12
+ private toTokens;
13
+ private resolveAccount;
14
+ }
15
+ //# sourceMappingURL=pinterest.oauth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pinterest.oauth.d.ts","sourceRoot":"","sources":["../../../src/services/socialOAuth/pinterest.oauth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EACL,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACZ,MAAM,SAAS,CAAC;AAsCjB,qBAAa,sBAAuB,YAAW,oBAAoB;IACjE,QAAQ,CAAC,QAAQ,6BAA6B;IAE9C,OAAO,CAAC,QAAQ;IAKhB,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,SAAS;IAMjB,UAAU,CAAC,EACT,KAAK,EACL,WAAW,EACX,qBAAqB,GACtB,EAAE,aAAa,GAAG,MAAM;IAcnB,YAAY,CAAC,EACjB,IAAI,EACJ,WAAW,GACZ,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC;IAgBxC,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;YAe3C,SAAS;IAsBvB,OAAO,CAAC,QAAQ;YAaF,cAAc;CAoB7B"}
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PinterestOAuthProvider = void 0;
4
+ const types_1 = require("../../globals/types");
5
+ /**
6
+ * Pinterest OAuth provider (v5 API). Phase 6 — fast-follow adapter.
7
+ *
8
+ * Config (env):
9
+ * PINTEREST_CLIENT_ID
10
+ * PINTEREST_CLIENT_SECRET
11
+ *
12
+ * Token calls use HTTP Basic (client_id:client_secret). Access token ~30 days;
13
+ * refresh token ~1 year. A connected app starts in "trial" (sandbox) until
14
+ * Pinterest approves standard access. (Plan §G.)
15
+ */
16
+ const AUTH_ENDPOINT = "https://www.pinterest.com/oauth/";
17
+ const TOKEN_ENDPOINT = "https://api.pinterest.com/v5/oauth/token";
18
+ const ACCOUNT_ENDPOINT = "https://api.pinterest.com/v5/user_account";
19
+ const BASE_SCOPES = ["boards:read", "pins:read", "pins:write", "user_accounts:read"];
20
+ const BUSINESS_SCOPES = ["boards:read_secret", "pins:read_secret"];
21
+ class PinterestOAuthProvider {
22
+ constructor() {
23
+ this.provider = types_1.ESocialProvider.PINTEREST;
24
+ }
25
+ clientId() {
26
+ const v = process.env.PINTEREST_CLIENT_ID;
27
+ if (!v)
28
+ throw new Error("PinterestOAuth: PINTEREST_CLIENT_ID not set");
29
+ return v;
30
+ }
31
+ clientSecret() {
32
+ const v = process.env.PINTEREST_CLIENT_SECRET;
33
+ if (!v)
34
+ throw new Error("PinterestOAuth: PINTEREST_CLIENT_SECRET not set");
35
+ return v;
36
+ }
37
+ basicAuth() {
38
+ return Buffer.from(`${this.clientId()}:${this.clientSecret()}`).toString("base64");
39
+ }
40
+ getAuthUrl({ state, redirectUri, requestBusinessScopes, }) {
41
+ const scopes = requestBusinessScopes
42
+ ? [...BASE_SCOPES, ...BUSINESS_SCOPES]
43
+ : BASE_SCOPES;
44
+ const params = new URLSearchParams({
45
+ response_type: "code",
46
+ client_id: this.clientId(),
47
+ redirect_uri: redirectUri,
48
+ scope: scopes.join(","),
49
+ state,
50
+ });
51
+ return `${AUTH_ENDPOINT}?${params.toString()}`;
52
+ }
53
+ async exchangeCode({ code, redirectUri, }) {
54
+ const token = await this.postToken(new URLSearchParams({
55
+ grant_type: "authorization_code",
56
+ code,
57
+ redirect_uri: redirectUri,
58
+ }));
59
+ if (!token.access_token) {
60
+ throw new Error("PinterestOAuth: token exchange returned no access_token");
61
+ }
62
+ const tokens = this.toTokens(token);
63
+ const account = await this.resolveAccount(token.access_token);
64
+ return { account, tokens };
65
+ }
66
+ async refresh(refreshToken) {
67
+ const token = await this.postToken(new URLSearchParams({
68
+ grant_type: "refresh_token",
69
+ refresh_token: refreshToken,
70
+ }));
71
+ if (!token.access_token) {
72
+ throw new Error("PinterestOAuth: refresh returned no access_token");
73
+ }
74
+ const tokens = this.toTokens(token);
75
+ if (!tokens.refreshToken)
76
+ tokens.refreshToken = refreshToken;
77
+ return tokens;
78
+ }
79
+ async postToken(body) {
80
+ const resp = await fetch(TOKEN_ENDPOINT, {
81
+ method: "POST",
82
+ headers: {
83
+ "Content-Type": "application/x-www-form-urlencoded",
84
+ Authorization: `Basic ${this.basicAuth()}`,
85
+ },
86
+ body: body.toString(),
87
+ });
88
+ const json = (await resp.json());
89
+ if (!resp.ok || json.error) {
90
+ throw new Error(`PinterestOAuth: token endpoint ${resp.status} ${json.error ?? ""} ${json.error_description ?? json.message ?? ""}`.trim());
91
+ }
92
+ return json;
93
+ }
94
+ toTokens(token) {
95
+ const now = Date.now();
96
+ return {
97
+ accessToken: token.access_token,
98
+ refreshToken: token.refresh_token,
99
+ expiresAt: now + (token.expires_in ?? 30 * 24 * 3600) * 1000,
100
+ refreshExpiresAt: token.refresh_token_expires_in
101
+ ? now + token.refresh_token_expires_in * 1000
102
+ : undefined,
103
+ scopes: token.scope ? token.scope.split(/[ ,]/).filter(Boolean) : [],
104
+ };
105
+ }
106
+ async resolveAccount(accessToken) {
107
+ const resp = await fetch(ACCOUNT_ENDPOINT, {
108
+ headers: { Authorization: `Bearer ${accessToken}` },
109
+ });
110
+ const json = (await resp.json());
111
+ if (!resp.ok || !json.username) {
112
+ throw new Error(`PinterestOAuth: user_account ${resp.status}`);
113
+ }
114
+ return {
115
+ // Pinterest v5 keys the account by username (no separate stable id).
116
+ providerAccountId: json.username,
117
+ displayName: json.business_name ?? json.username,
118
+ handle: json.username,
119
+ avatarUrl: json.profile_image,
120
+ kind: json.account_type === "BUSINESS"
121
+ ? types_1.ESocialAccountKind.BUSINESS
122
+ : types_1.ESocialAccountKind.PERSONAL,
123
+ };
124
+ }
125
+ }
126
+ exports.PinterestOAuthProvider = PinterestOAuthProvider;
@@ -0,0 +1,14 @@
1
+ import { ESocialProvider } from "../../globals/types";
2
+ import { AuthUrlParams, ConnectResult, ExchangeCodeParams, ISocialOAuthProvider, OAuthTokens } from "./types";
3
+ export declare class ThreadsOAuthProvider implements ISocialOAuthProvider {
4
+ readonly provider = ESocialProvider.THREADS;
5
+ private appId;
6
+ private appSecret;
7
+ getAuthUrl({ state, redirectUri, requestBusinessScopes, }: AuthUrlParams): string;
8
+ exchangeCode({ code, redirectUri, }: ExchangeCodeParams): Promise<ConnectResult>;
9
+ refresh(refreshToken: string): Promise<OAuthTokens>;
10
+ private toLongLived;
11
+ private toTokens;
12
+ private resolveAccount;
13
+ }
14
+ //# sourceMappingURL=threads.oauth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"threads.oauth.d.ts","sourceRoot":"","sources":["../../../src/services/socialOAuth/threads.oauth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EACL,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACZ,MAAM,SAAS,CAAC;AA4CjB,qBAAa,oBAAqB,YAAW,oBAAoB;IAC/D,QAAQ,CAAC,QAAQ,2BAA2B;IAE5C,OAAO,CAAC,KAAK;IAKb,OAAO,CAAC,SAAS;IAMjB,UAAU,CAAC,EACT,KAAK,EACL,WAAW,EACX,qBAAqB,GACtB,EAAE,aAAa,GAAG,MAAM;IAcnB,YAAY,CAAC,EACjB,IAAI,EACJ,WAAW,GACZ,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC;IA2BxC,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;YAgB3C,WAAW;IAgBzB,OAAO,CAAC,QAAQ;YAYF,cAAc;CAkB7B"}