@lobu/runtime-server 24.11.0 → 24.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (275) hide show
  1. package/dist/catalogs/connectors.json +1113 -107
  2. package/dist/catalogs/skills.json +2 -2
  3. package/dist/component.json +1 -1
  4. package/dist/connectors/README.md +2 -2
  5. package/dist/connectors/chat-transport-actions.ts +50 -0
  6. package/dist/connectors/discord.ts +2 -0
  7. package/dist/connectors/gchat.ts +2 -0
  8. package/dist/connectors/github.ts +4 -4
  9. package/dist/connectors/google_drive.ts +20 -0
  10. package/dist/connectors/google_gmail.ts +49 -8
  11. package/dist/connectors/herdr.ts +1 -1
  12. package/dist/connectors/imessage.ts +1 -0
  13. package/dist/connectors/linkedin-browser-script.ts +11 -0
  14. package/dist/connectors/linkedin-draft-page.js +24 -8
  15. package/dist/connectors/linkedin-inbox-adapter.js +209 -19
  16. package/dist/connectors/linkedin-inbox.ts +152 -4
  17. package/dist/connectors/linkedin-network.ts +788 -0
  18. package/dist/connectors/linkedin-search.ts +1284 -0
  19. package/dist/connectors/linkedin.ts +892 -27
  20. package/dist/connectors/microsoft_outlook.ts +57 -19
  21. package/dist/connectors/rss.ts +179 -33
  22. package/dist/connectors/slack.ts +2 -0
  23. package/dist/connectors/source-file-attachment.ts +46 -0
  24. package/dist/connectors/teams.ts +2 -0
  25. package/dist/connectors/telegram.ts +2 -0
  26. package/dist/connectors/tiktok_web.ts +1 -1
  27. package/dist/connectors/whatsapp.ts +2 -0
  28. package/dist/connectors/whatsapp_web.ts +3 -3
  29. package/dist/connectors/x-dm-adapter.js +8 -10
  30. package/dist/connectors/x.ts +8 -9
  31. package/dist/db/migrations/20261115040000_account_two_factor.sql +20 -0
  32. package/dist/db/migrations/20261115120000_events_unbound_tool_audit_without_bridge.sql +40 -0
  33. package/dist/db/migrations/20261115120001_events_unbound_tool_audit_validate.sql +19 -0
  34. package/dist/db/migrations/20261115120002_drop_events_linked_org_ids.sql +119 -0
  35. package/dist/db/migrations/20261115130000_entities_retired_type_idx.sql +34 -0
  36. package/dist/db/migrations/20261115140000_entity_identities_personal_owner_idx.sql +34 -0
  37. package/dist/db/migrations/20261117090000_write_policy_kind_note.sql +65 -0
  38. package/dist/db/migrations/20261117120000_app_policy_principal.sql +48 -0
  39. package/dist/db/migrations/20261117170000_personal_org_connector_auto_policy_backfill.sql +57 -0
  40. package/dist/db/migrations/20261117190000_org_slug_reserved_paths.sql +29 -0
  41. package/dist/db/migrations/20261118120000_workspace_view_top_level_paths.sql +69 -0
  42. package/dist/db/migrations/preconditions/20261117190000_org_slug_reserved_paths.sql +14 -0
  43. package/dist/db/migrations/preconditions/20261118120000_workspace_view_top_level_paths.sql +21 -0
  44. package/dist/dependencies.bun.lock +51 -46
  45. package/dist/guest.bundle.js +11 -2
  46. package/dist/owletto/dist/assets/_-BC9j6MkU.js +2 -0
  47. package/dist/owletto/dist/assets/_-Z1u1cIe6.js +3 -0
  48. package/dist/owletto/dist/assets/_agentId-B-TFq9TP.js +2 -0
  49. package/dist/owletto/dist/assets/{_agentId-CGScf8z_.js → _agentId-BGatZWsd.js} +2 -2
  50. package/dist/owletto/dist/assets/_automationId-CMUrWPvr.js +2 -0
  51. package/dist/owletto/dist/assets/_connectorKey._connectionId-CUoAoP0_.js +2 -0
  52. package/dist/owletto/dist/assets/_connectorKey.index-Bs49QGGH.js +2 -0
  53. package/dist/owletto/dist/assets/_conversationId-CszP1den.js +2 -0
  54. package/dist/owletto/dist/assets/_eventId-C0AZUBnD.js +2 -0
  55. package/dist/owletto/dist/assets/_owner-B4ydA75k.js +3 -0
  56. package/dist/owletto/dist/assets/_shape-C4-ikE70.js +2 -0
  57. package/dist/owletto/dist/assets/_slug-DE5J3KVu.js +2 -0
  58. package/dist/owletto/dist/assets/_viewKey-Dkcd8JQC.js +2 -0
  59. package/dist/owletto/dist/assets/{accept-invitation-BKeIzZXE.js → accept-invitation-DmrQQu_W.js} +2 -2
  60. package/dist/owletto/dist/assets/{activity-route-location-sLvKaSCa.js → activity-route-location-Bec6fW-t.js} +2 -2
  61. package/dist/owletto/dist/assets/activity-route-view-DCSNBKZU.js +2 -0
  62. package/dist/owletto/dist/assets/agent-client-connections-xvabPpi6.js +4 -0
  63. package/dist/owletto/dist/assets/agent-connect-pages-DDPtkcmq.js +6 -0
  64. package/dist/owletto/dist/assets/{agent-editor-form-DVFyyMyd.js → agent-editor-form-BrhQbHZg.js} +2 -2
  65. package/dist/owletto/dist/assets/{agent-loading-shells-BLNHIy-r.js → agent-loading-shells-D3y98xuO.js} +2 -2
  66. package/dist/owletto/dist/assets/{agent-permissions-matrix-UBKRR5vs.js → agent-permissions-matrix-jQJjSa9i.js} +2 -2
  67. package/dist/owletto/dist/assets/{agent-skill-context-fqedKd0D.js → agent-skill-context-CCcknBYE.js} +2 -2
  68. package/dist/owletto/dist/assets/{agent-subpage-shell-BUCoY2Nf.js → agent-subpage-shell-6f_53cSf.js} +2 -2
  69. package/dist/owletto/dist/assets/agent-thread-v_lSSnJi.js +6 -0
  70. package/dist/owletto/dist/assets/{app._appId-ByIypCL9.js → app._appId-CKWzZ2ic.js} +2 -2
  71. package/dist/owletto/dist/assets/assist-composer-Q9ZJjAta.js +2 -0
  72. package/dist/owletto/dist/assets/automation-run-now-Dl0MKx3N.js +2 -0
  73. package/dist/owletto/dist/assets/{callback-Pz5uS-k7.js → callback-Bentv78L.js} +2 -2
  74. package/dist/owletto/dist/assets/{card-CAPpY9P5.js → card-C4oPCVh6.js} +2 -2
  75. package/dist/owletto/dist/assets/{claim-DgWWK0KI.js → claim-B3C4qIi2.js} +2 -2
  76. package/dist/owletto/dist/assets/client-activity-scopes-DqaFEyir.js +2 -0
  77. package/dist/owletto/dist/assets/{client-rows-Dd5YV8vn.js → client-rows-rse9thnk.js} +2 -2
  78. package/dist/owletto/dist/assets/{clients-Bf7ZgGro.js → clients-BhPMbxHi.js} +2 -2
  79. package/dist/owletto/dist/assets/{code-editor-z1Sy_hiX.js → code-editor-CTdKUDPY.js} +2 -2
  80. package/dist/owletto/dist/assets/connect-D8o7HBlo.js +2 -0
  81. package/dist/owletto/dist/assets/connect-menu-D5EZvSHb.js +2 -0
  82. package/dist/owletto/dist/assets/connect._clientId-Dbagcg9L.js +2 -0
  83. package/dist/owletto/dist/assets/connected._clientId-DALW9S2K.js +2 -0
  84. package/dist/owletto/dist/assets/connection-DyxzSqVE.js +2 -0
  85. package/dist/owletto/dist/assets/connection-feed-detail-LqpxUCdy.js +2 -0
  86. package/dist/owletto/dist/assets/{connector-page-shell-an3SYLim.js → connector-page-shell-DZjKv9zQ.js} +2 -2
  87. package/dist/owletto/dist/assets/{connector-provenance-mSZCOud-.js → connector-provenance-DtTJn1Nk.js} +2 -2
  88. package/dist/owletto/dist/assets/connectors-BVl-AR33.js +2 -0
  89. package/dist/owletto/dist/assets/{consent-1ulwyJ3k.js → consent-XCqsHLxS.js} +2 -2
  90. package/dist/owletto/dist/assets/{core.esm-Ctg_pXLe.js → core.esm-B1du4Zwy.js} +3 -3
  91. package/dist/owletto/dist/assets/create-BYKCtGL4.js +2 -0
  92. package/dist/owletto/dist/assets/create-D6Mmuxcq.js +2 -0
  93. package/dist/owletto/dist/assets/{create-CGuoqPh8.js → create-GHTb6wKX.js} +2 -2
  94. package/dist/owletto/dist/assets/{create-automation-form-CD6jSlWL.js → create-automation-form-CTiy_S9G.js} +3 -3
  95. package/dist/owletto/dist/assets/create._connectorKey-DMH97KkK.js +2 -0
  96. package/dist/owletto/dist/assets/custom-guardrail-edits-DZy66ucV.js +2 -0
  97. package/dist/owletto/dist/assets/definition-comparison-C2mPfIMD.js +2 -0
  98. package/dist/owletto/dist/assets/detail-page-skeleton-DNBL7nyk.js +2 -0
  99. package/dist/owletto/dist/assets/device-CwP1PY8q.js +2 -0
  100. package/dist/owletto/dist/assets/{device-pin-tombstone-Dkj7hrBE.js → device-pin-tombstone-DYTt7kU5.js} +2 -2
  101. package/dist/owletto/dist/assets/device._deviceId-DZ2kqI4Y.js +2 -0
  102. package/dist/owletto/dist/assets/{entity-options-D4t-NAcg.js → entity-options-D9K_5Lcs.js} +2 -2
  103. package/dist/owletto/dist/assets/entity-page-DggKXrcE.js +2 -0
  104. package/dist/owletto/dist/assets/entity-pages-C6M6yKFf.js +2 -0
  105. package/dist/owletto/dist/assets/{entity-schema-graph-Cq96SJ3c.js → entity-schema-graph-B255NKjF.js} +2 -2
  106. package/dist/owletto/dist/assets/entity-type-page-CGBAP2wt.js +2 -0
  107. package/dist/owletto/dist/assets/event-attachments-D8Z8uwv9.js +2 -0
  108. package/dist/owletto/dist/assets/event-detail-CgG3pDLA.js +2 -0
  109. package/dist/owletto/dist/assets/events-feed-ClhEywwV.js +2 -0
  110. package/dist/owletto/dist/assets/{filter-editors-DGVl9U4D.js → filter-editors-D_Sfn0dv.js} +3 -3
  111. package/dist/owletto/dist/assets/{full-page-spinner-CtVlF8GQ.js → full-page-spinner-C1clibUY.js} +2 -2
  112. package/dist/owletto/dist/assets/{index-CK5GDX4B.js → index-04B26s6E.js} +2 -2
  113. package/dist/owletto/dist/assets/index-2HrEO-nl.js +2 -0
  114. package/dist/owletto/dist/assets/index-BU3k9wpw.js +2 -0
  115. package/dist/owletto/dist/assets/{index-DvuJ_S_o.js → index-BXHqp23o.js} +2 -2
  116. package/dist/owletto/dist/assets/index-BdLRUDIR.js +2 -0
  117. package/dist/owletto/dist/assets/index-C2FrGwYN.js +2 -0
  118. package/dist/owletto/dist/assets/index-CB9wGfUm.js +2 -0
  119. package/dist/owletto/dist/assets/index-Caihaftb.js +2 -0
  120. package/dist/owletto/dist/assets/index-CwH59DJV.js +2 -0
  121. package/dist/owletto/dist/assets/index-DB2lVKuV.js +7908 -0
  122. package/dist/owletto/dist/assets/{index-DbjbHlDe.js → index-DTvJRjrM.js} +2 -2
  123. package/dist/owletto/dist/assets/index-SF2ni1Rs.css +1 -0
  124. package/dist/owletto/dist/assets/{index-BifR-LE9.js → index-mSrdbx3C.js} +9 -9
  125. package/dist/owletto/dist/assets/index-uFn-Ilrx.js +2 -0
  126. package/dist/owletto/dist/assets/{json-diff-OjtREegr.js → json-diff-Ce6YAXzY.js} +2 -2
  127. package/dist/owletto/dist/assets/{list-skeleton-CH0qQBYk.js → list-skeleton-DLPBTnbR.js} +2 -2
  128. package/dist/owletto/dist/assets/login-DeWlvogD.js +2 -0
  129. package/dist/owletto/dist/assets/{logout-DfdgOLoM.js → logout-CJY0ceN9.js} +2 -2
  130. package/dist/owletto/dist/assets/{member-scope-gate-Cxg2zGQT.js → member-scope-gate-CBPMprXu.js} +2 -2
  131. package/dist/owletto/dist/assets/memory-browse-page-D5kj1RaR.js +74 -0
  132. package/dist/owletto/dist/assets/{model-selector-D2OpDkwH.js → model-selector-CjkBPpjN.js} +2 -2
  133. package/dist/owletto/dist/assets/new-BKrNkOQD.js +2 -0
  134. package/dist/owletto/dist/assets/new-BetiMuDq.js +2 -0
  135. package/dist/owletto/dist/assets/new-dk_-eXqU.js +2 -0
  136. package/dist/owletto/dist/assets/new-efN--4Wx.js +2 -0
  137. package/dist/owletto/dist/assets/organization-C3rpwx_d.js +2 -0
  138. package/dist/owletto/dist/assets/pdf-document--AN-oCKj.css +1 -0
  139. package/dist/owletto/dist/assets/pdf-document-2W1q0sRA.js +56 -0
  140. package/dist/owletto/dist/assets/pdf.worker.min-CIqJB0yW.mjs +28 -0
  141. package/dist/owletto/dist/assets/peek-pane-content-ChsBWO0P.js +3 -0
  142. package/dist/owletto/dist/assets/{pending-seed-BBACroge.js → pending-seed-CTKYdA4X.js} +2 -2
  143. package/dist/owletto/dist/assets/proposal-review-shell-EyGWEYwQ.js +2 -0
  144. package/dist/owletto/dist/assets/public-shell-ready-_KWdfzEM.js +2 -0
  145. package/dist/owletto/dist/assets/record-session-D27VNxP_.js +2 -0
  146. package/dist/owletto/dist/assets/{renderer-CTKNMcXP.js → renderer-B8yZ5lql.js} +34 -33
  147. package/dist/owletto/dist/assets/{reset-password-DKBEneyR.js → reset-password-BGVJIh2I.js} +2 -2
  148. package/dist/owletto/dist/assets/run-initiator-C0sur8lU.js +2 -0
  149. package/dist/owletto/dist/assets/runs-list-CJOFMgpk.js +2 -0
  150. package/dist/owletto/dist/assets/schema-value-DDNHANGs.js +3 -0
  151. package/dist/owletto/dist/assets/{scoped-feed-bar-DNFL0sYX.js → scoped-feed-bar-BTv9mPcR.js} +2 -2
  152. package/dist/owletto/dist/assets/settings-Ponr5XbS.js +3 -0
  153. package/dist/owletto/dist/assets/{status-variants-SzXYYedJ.js → status-variants-mLqVhg5O.js} +2 -2
  154. package/dist/owletto/dist/assets/subDays-BGA_fkig.js +2 -0
  155. package/dist/owletto/dist/assets/two-factor-pqoxGSgL.js +2 -0
  156. package/dist/owletto/dist/assets/{use-automations-DfBtVzGa.js → use-automations-DcdlmVuX.js} +2 -2
  157. package/dist/owletto/dist/assets/{use-login-redirect-BDiS3eyl.js → use-login-redirect-D7HW5Ed6.js} +2 -2
  158. package/dist/owletto/dist/assets/{use-mention-search-khySpz_V.js → use-mention-search-BniE-K2d.js} +3 -3
  159. package/dist/owletto/dist/assets/view-card-Cg6PeEiV.js +2 -0
  160. package/dist/owletto/dist/assets/view-param-filters-CvrKw0mZ.js +2 -0
  161. package/dist/owletto/dist/index.html +2 -2
  162. package/dist/server-main.bundle.mjs +5766 -2999
  163. package/npm-shrinkwrap.json +195 -172
  164. package/package.json +2 -1
  165. package/vendor/connector-sdk/dist/connector-types.d.ts +20 -0
  166. package/vendor/connector-sdk/dist/define-connector.js +2 -0
  167. package/vendor/connector-sdk/dist/extension-dom-scrape.d.ts +2 -0
  168. package/vendor/connector-sdk/dist/extension-dom-scrape.js +5 -0
  169. package/vendor/connector-sdk/dist/reaction-client-types.d.ts +20 -0
  170. package/vendor/connector-sdk/package.json +1 -1
  171. package/vendor/core/dist/contracts/entity-reference.d.ts +2 -0
  172. package/vendor/core/dist/contracts/entity-reference.js +4 -3
  173. package/vendor/core/dist/contracts/tools/entity-list-sort.d.ts +18 -0
  174. package/vendor/core/dist/contracts/tools/entity-list-sort.js +64 -0
  175. package/vendor/core/dist/contracts/tools/manage-agents.d.ts +1 -1
  176. package/vendor/core/dist/contracts/tools/manage-agents.js +3 -3
  177. package/vendor/core/dist/contracts/tools/manage-entity-schema.d.ts +4 -0
  178. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +4 -0
  179. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +4 -0
  180. package/vendor/core/dist/contracts/tools/manage-entity.js +11 -1
  181. package/vendor/core/dist/contracts/tools/manage-operations.d.ts +29 -3
  182. package/vendor/core/dist/contracts/tools/manage-operations.js +24 -2
  183. package/vendor/core/dist/contracts/tools/manage-views.d.ts +36 -0
  184. package/vendor/core/dist/contracts/tools/manage-views.js +15 -2
  185. package/vendor/core/dist/contracts/tools/view-definition.js +7 -2
  186. package/vendor/core/dist/contracts/tools/view-host.js +5 -0
  187. package/vendor/core/dist/contracts/tools/view-path.d.ts +8 -1
  188. package/vendor/core/dist/contracts/tools/view-path.js +11 -1
  189. package/vendor/core/dist/reserved.d.ts +7 -1
  190. package/vendor/core/dist/reserved.js +17 -0
  191. package/vendor/core/package.json +6 -1
  192. package/vendor/views/dist/api.d.ts +19 -3
  193. package/vendor/views/dist/api.js +53 -5
  194. package/vendor/views/dist/components.d.ts +7 -0
  195. package/vendor/views/dist/components.js +223 -2
  196. package/vendor/views/dist/embed.js +13 -2
  197. package/vendor/views/dist/live-gate.d.ts +34 -0
  198. package/vendor/views/dist/live-gate.js +100 -0
  199. package/vendor/views/dist/native.d.ts +43 -1
  200. package/vendor/views/dist/native.js +1 -0
  201. package/vendor/views/package.json +1 -1
  202. package/dist/owletto/dist/assets/_-BDMUN9XZ.js +0 -2
  203. package/dist/owletto/dist/assets/_-CF5X4ANe.js +0 -3
  204. package/dist/owletto/dist/assets/_agentId-EQU2aUP0.js +0 -2
  205. package/dist/owletto/dist/assets/_automationId-PXZ33jsF.js +0 -2
  206. package/dist/owletto/dist/assets/_connectorKey._connectionId-DcI29kGy.js +0 -2
  207. package/dist/owletto/dist/assets/_connectorKey.index-Cr2NDJWX.js +0 -2
  208. package/dist/owletto/dist/assets/_conversationId-CnmLYlVS.js +0 -2
  209. package/dist/owletto/dist/assets/_eventId-w5sDz5oa.js +0 -2
  210. package/dist/owletto/dist/assets/_owner-CkOZR4n0.js +0 -3
  211. package/dist/owletto/dist/assets/_shape-C_FmSf9G.js +0 -2
  212. package/dist/owletto/dist/assets/_slug-COPpRXLt.js +0 -2
  213. package/dist/owletto/dist/assets/_viewKey-BVdJiilV.js +0 -2
  214. package/dist/owletto/dist/assets/_viewKey-mxxpqjtC.js +0 -2
  215. package/dist/owletto/dist/assets/activity-route-view-msesKUwn.js +0 -2
  216. package/dist/owletto/dist/assets/agent-connect-pages-DVq9nAR7.js +0 -4
  217. package/dist/owletto/dist/assets/agent-thread-Cqf9ITrT.js +0 -6
  218. package/dist/owletto/dist/assets/assist-composer-kG_heHXo.js +0 -2
  219. package/dist/owletto/dist/assets/automation-run-now-C5XTS00o.js +0 -2
  220. package/dist/owletto/dist/assets/client-activity-scopes-Aqdo6Pdr.js +0 -2
  221. package/dist/owletto/dist/assets/connect-BFNp1y_s.js +0 -2
  222. package/dist/owletto/dist/assets/connect-menu-BWrAhMqO.js +0 -2
  223. package/dist/owletto/dist/assets/connect._clientId-CSPfwYIN.js +0 -2
  224. package/dist/owletto/dist/assets/connected._clientId-CuOeHafK.js +0 -2
  225. package/dist/owletto/dist/assets/connection-CVeHmDLs.js +0 -2
  226. package/dist/owletto/dist/assets/connection-feed-detail-BYo7zdVD.js +0 -2
  227. package/dist/owletto/dist/assets/connectors-DBEM9QQz.js +0 -2
  228. package/dist/owletto/dist/assets/copy-button-Xhh7ZnjO.js +0 -2
  229. package/dist/owletto/dist/assets/create-Ccb5R-S4.js +0 -2
  230. package/dist/owletto/dist/assets/create-DmhbacIa.js +0 -2
  231. package/dist/owletto/dist/assets/create._connectorKey-CZsAqj1p.js +0 -2
  232. package/dist/owletto/dist/assets/custom-guardrail-edits-Ce_BwiwD.js +0 -2
  233. package/dist/owletto/dist/assets/definition-comparison-D_qP25jR.js +0 -2
  234. package/dist/owletto/dist/assets/detail-page-skeleton-CPAfZLG0.js +0 -2
  235. package/dist/owletto/dist/assets/device-DDl5XKvt.js +0 -2
  236. package/dist/owletto/dist/assets/device._deviceId-bNhTcops.js +0 -2
  237. package/dist/owletto/dist/assets/dynamic-schema-form-CRyUchXo.js +0 -2
  238. package/dist/owletto/dist/assets/entity-page-BOOL_vy3.js +0 -2
  239. package/dist/owletto/dist/assets/entity-pages-_nuesgnp.js +0 -2
  240. package/dist/owletto/dist/assets/entity-type-page-CkCSbkBx.js +0 -2
  241. package/dist/owletto/dist/assets/event-detail-DUvlqn9b.js +0 -2
  242. package/dist/owletto/dist/assets/events-feed-DcKTkJVe.js +0 -2
  243. package/dist/owletto/dist/assets/index-BUlkNJzX.js +0 -2
  244. package/dist/owletto/dist/assets/index-BoqrvLHQ.js +0 -7906
  245. package/dist/owletto/dist/assets/index-CA9mW_ZM.js +0 -2
  246. package/dist/owletto/dist/assets/index-CH0GzG4i.js +0 -2
  247. package/dist/owletto/dist/assets/index-CtI5Eomq.js +0 -2
  248. package/dist/owletto/dist/assets/index-DmtQ0bds.js +0 -2
  249. package/dist/owletto/dist/assets/index-Du_J8hnx.js +0 -2
  250. package/dist/owletto/dist/assets/index-Pae_f9LM.css +0 -1
  251. package/dist/owletto/dist/assets/index-XETZnN7L.js +0 -2
  252. package/dist/owletto/dist/assets/login-DG0b9uSC.js +0 -2
  253. package/dist/owletto/dist/assets/memory-browse-page-qEDQ9Z18.js +0 -74
  254. package/dist/owletto/dist/assets/missing-view-xT0B-f5z.js +0 -2
  255. package/dist/owletto/dist/assets/needs-you-list-3uMsWcDv.js +0 -2
  256. package/dist/owletto/dist/assets/new-AdGV6a8R.js +0 -2
  257. package/dist/owletto/dist/assets/new-BdtIhBpo.js +0 -2
  258. package/dist/owletto/dist/assets/new-BjGwX6s6.js +0 -2
  259. package/dist/owletto/dist/assets/new-D-iMjV74.js +0 -2
  260. package/dist/owletto/dist/assets/organization-qaIpEiQg.js +0 -2
  261. package/dist/owletto/dist/assets/peek-pane-content-CEsDVScl.js +0 -2
  262. package/dist/owletto/dist/assets/proposal-review-shell-C8ZfIAYn.js +0 -2
  263. package/dist/owletto/dist/assets/public-shell-ready-K2R8iXSI.js +0 -2
  264. package/dist/owletto/dist/assets/record-session-BrM9cdXu.js +0 -2
  265. package/dist/owletto/dist/assets/run-initiator-BKSgI1o0.js +0 -2
  266. package/dist/owletto/dist/assets/runs-k2NpbZm8.js +0 -2
  267. package/dist/owletto/dist/assets/runs-list-DUXRMkWN.js +0 -2
  268. package/dist/owletto/dist/assets/schema-value-wjqGxXhv.js +0 -3
  269. package/dist/owletto/dist/assets/settings-V0m5Om5j.js +0 -2
  270. package/dist/owletto/dist/assets/source-record-panels-BMut9YIA.js +0 -2
  271. package/dist/owletto/dist/assets/subDays-9s9OEl5t.js +0 -2
  272. package/dist/owletto/dist/assets/table-ZuYMOjVR.js +0 -2
  273. package/dist/owletto/dist/assets/view-card-DiHWlypr.js +0 -2
  274. package/dist/owletto/dist/assets/view-param-filters-DGKxSr7r.js +0 -2
  275. package/dist/owletto/dist/assets/views-access-required-HA-PiOwA.js +0 -2
@@ -0,0 +1,1284 @@
1
+ /**
2
+ * Read-only LinkedIn lookups: people search, profile read, company search and
3
+ * company read. Each is one content-script scrape of the page LinkedIn itself
4
+ * renders in the paired Chrome, so nothing is clicked and nothing is stored.
5
+ * Selectors follow the current SDUI markup (obfuscated classes, `componentkey`
6
+ * attributes, `role="listitem"` result rows); row text is parsed here.
7
+ */
8
+
9
+ import {
10
+ type ActionContext,
11
+ type ActionResult,
12
+ type ChromeActionDispatcher,
13
+ type ExtensionScrapeConfig,
14
+ extensionDomScrape,
15
+ requireBrowser,
16
+ } from "@lobu/connector-sdk";
17
+ import {
18
+ LINKEDIN_ALLOWED_ORIGINS,
19
+ LINKEDIN_LOGGED_OUT_ERROR,
20
+ LINKEDIN_LOGGED_OUT_WHEN,
21
+ } from "./linkedin-browser-script.js";
22
+
23
+ type Row = Record<string, unknown>;
24
+
25
+ const MAX_TEXT_INPUT = 200;
26
+ const MAX_PAGE = 10;
27
+ const MAX_POSITIONS = 15;
28
+ const MAX_EDUCATION = 10;
29
+ const MAX_ABOUT_CHARS = 4000;
30
+ const MAX_DESCRIPTION_CHARS = 2000;
31
+ const MAX_SKILLS = 50;
32
+
33
+ /** LinkedIn's people-search connection-degree facet values. */
34
+ const NETWORK_FACETS = { "1st": "F", "2nd": "S", "3rd": "O" } as const;
35
+
36
+ class InputError extends Error {}
37
+
38
+ function optionalText(input: Row, name: string): string | undefined {
39
+ const value = input[name];
40
+ if (value === undefined || value === null) return undefined;
41
+ if (typeof value !== "string")
42
+ throw new InputError(`${name} must be a string`);
43
+ const trimmed = value.trim();
44
+ if (trimmed.length > MAX_TEXT_INPUT)
45
+ throw new InputError(
46
+ `${name} must be at most ${MAX_TEXT_INPUT} characters`
47
+ );
48
+ return trimmed || undefined;
49
+ }
50
+
51
+ function requiredText(input: Row, name: string): string {
52
+ const value = optionalText(input, name);
53
+ if (!value) throw new InputError(`${name} is required`);
54
+ return value;
55
+ }
56
+
57
+ /** Search pages are 1-based; one call reads one page. */
58
+ export function readSearchPage(input: Row): number {
59
+ const value = input.page ?? 1;
60
+ if (
61
+ typeof value !== "number" ||
62
+ !Number.isInteger(value) ||
63
+ value < 1 ||
64
+ value > MAX_PAGE
65
+ ) {
66
+ throw new InputError(`page must be an integer from 1 to ${MAX_PAGE}`);
67
+ }
68
+ return value;
69
+ }
70
+
71
+ function readNetwork(input: Row): Array<keyof typeof NETWORK_FACETS> {
72
+ const value = input.network;
73
+ if (value === undefined || value === null) return [];
74
+ if (
75
+ !Array.isArray(value) ||
76
+ value.some((item) => !Object.hasOwn(NETWORK_FACETS, String(item)))
77
+ ) {
78
+ throw new InputError('network must be an array of "1st", "2nd" or "3rd"');
79
+ }
80
+ return [...new Set(value as Array<keyof typeof NETWORK_FACETS>)];
81
+ }
82
+
83
+ function linkedInUrl(raw: string, name: string): URL {
84
+ let url: URL;
85
+ try {
86
+ url = new URL(raw.includes("://") ? raw : `https://${raw}`);
87
+ } catch {
88
+ throw new InputError(`${name} must be a LinkedIn URL`);
89
+ }
90
+ const host = url.hostname.toLowerCase();
91
+ if (
92
+ (url.protocol !== "https:" && url.protocol !== "http:") ||
93
+ (host !== "linkedin.com" && !host.endsWith(".linkedin.com"))
94
+ ) {
95
+ throw new InputError(`${name} must be a LinkedIn URL`);
96
+ }
97
+ return url;
98
+ }
99
+
100
+ function decodedSegment(segment: string): string {
101
+ try {
102
+ return decodeURIComponent(segment);
103
+ } catch {
104
+ return segment;
105
+ }
106
+ }
107
+
108
+ /** `https://www.linkedin.com/in/<slug>/` for a member profile URL, else null. */
109
+ export function canonicalProfileUrl(raw: string | undefined): string | null {
110
+ if (!raw) return null;
111
+ let url: URL;
112
+ try {
113
+ url = linkedInUrl(raw, "profile_url");
114
+ } catch {
115
+ return null;
116
+ }
117
+ const slug = url.pathname.match(/^\/in\/([^/]+)/i)?.[1];
118
+ if (!slug) return null;
119
+ return `https://www.linkedin.com/in/${encodeURIComponent(decodedSegment(slug))}/`;
120
+ }
121
+
122
+ /** `https://www.linkedin.com/company/<slug-or-id>/` for a company URL, else null. */
123
+ export function canonicalCompanyUrl(raw: string | undefined): string | null {
124
+ if (!raw) return null;
125
+ let url: URL;
126
+ try {
127
+ url = linkedInUrl(raw, "company_url");
128
+ } catch {
129
+ return null;
130
+ }
131
+ const slug = url.pathname.match(/^\/(?:company|showcase|school)\/([^/]+)/i);
132
+ if (!slug?.[1]) return null;
133
+ const kind = url.pathname.split("/")[1]?.toLowerCase() ?? "company";
134
+ return `https://www.linkedin.com/${kind}/${encodeURIComponent(decodedSegment(slug[1]))}/`;
135
+ }
136
+
137
+ const DEGREE_RE = /^[·•]?\s*(1st|2nd|3rd)\b/i;
138
+
139
+ function degreeOf(text: string | undefined): string | null {
140
+ const match = text?.match(/[·•]\s*(1st|2nd|3rd)\b/i) ?? null;
141
+ return match ? match[1].toLowerCase() : null;
142
+ }
143
+
144
+ function cleanText(value: unknown): string {
145
+ return typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "";
146
+ }
147
+
148
+ function lineTexts(value: unknown): string[] {
149
+ if (!Array.isArray(value)) return [];
150
+ return value
151
+ .map((part) => cleanText((part as Row | null)?.t))
152
+ .filter((line) => line.length > 0);
153
+ }
154
+
155
+ function nonEmpty(value: string | undefined | null): string | null {
156
+ return value ? value : null;
157
+ }
158
+
159
+ /** LinkedIn's "… more" expander text, rendered inside clamped paragraphs. */
160
+ function stripMore(text: string): string {
161
+ return text.replace(/\s*…\s*(?:see\s+)?more$/i, "").trim();
162
+ }
163
+
164
+ // innerHTML escapes only these in text; `&quot;` appears in attributes alone.
165
+ const HTML_TEXT_ENTITIES: Record<string, string> = {
166
+ amp: "&",
167
+ lt: "<",
168
+ gt: ">",
169
+ nbsp: " ",
170
+ };
171
+
172
+ /**
173
+ * The first paragraph with a line break. The scraper's `text` read collapses
174
+ * every newline to a space; its `html` read keeps the `<br>`s.
175
+ */
176
+ const MULTILINE_HTML = { selector: "p:has(br)", take: "html" } as const;
177
+
178
+ /**
179
+ * `text` with the line breaks of `html` restored. The html only supplies the
180
+ * formatting: when it is a different element (its text differs), `text` is
181
+ * returned unchanged.
182
+ */
183
+ export function withLineBreaks(text: string, html: unknown): string {
184
+ if (typeof html !== "string" || !text) return text;
185
+ // Drop tags until none remain, so one tag split by another cannot reassemble.
186
+ // A tag skips a ">" inside a double-quoted attribute value.
187
+ let plain = html.replace(/<br\s*\/?>/gi, "\n");
188
+ for (let previous = ""; plain !== previous; ) {
189
+ previous = plain;
190
+ plain = plain.replace(/<(?:[^>"]|"[^"]*")*>/g, "");
191
+ }
192
+ const multiline = stripMore(
193
+ plain
194
+ .replace(
195
+ /&(amp|lt|gt|nbsp);/g,
196
+ (_entity, name: string) => HTML_TEXT_ENTITIES[name]
197
+ )
198
+ .split("\n")
199
+ .map(cleanText)
200
+ .join("\n")
201
+ .replace(/\n{3,}/g, "\n\n")
202
+ .trim()
203
+ );
204
+ return cleanText(multiline) === cleanText(text) ? multiline : text;
205
+ }
206
+
207
+ /** Outbound links render as `linkedin.com/safety/go/?url=<target>`. */
208
+ function isLinkedInRedirect(href: string): boolean {
209
+ try {
210
+ return new URL(href, "https://www.linkedin.com").pathname.startsWith("/safety/go");
211
+ } catch {
212
+ return false;
213
+ }
214
+ }
215
+
216
+ export function decodeLinkedInRedirect(href: string): string | null {
217
+ let url: URL;
218
+ try {
219
+ url = new URL(href, "https://www.linkedin.com");
220
+ } catch {
221
+ return null;
222
+ }
223
+ if (url.pathname.startsWith("/safety/go")) {
224
+ const target = url.searchParams.get("url");
225
+ return target && /^https?:\/\//i.test(target) ? target : null;
226
+ }
227
+ return url.protocol === "https:" || url.protocol === "http:"
228
+ ? url.href
229
+ : null;
230
+ }
231
+
232
+ function linkList(value: unknown): Array<{ href: string; text: string }> {
233
+ if (!Array.isArray(value)) return [];
234
+ return value
235
+ .map((part) => ({
236
+ href: cleanText((part as Row | null)?.h),
237
+ text: cleanText((part as Row | null)?.t),
238
+ }))
239
+ .filter((link) => link.href.length > 0);
240
+ }
241
+
242
+ function parseCount(text: string): number {
243
+ return Number.parseInt(text.replace(/[,.]/g, ""), 10);
244
+ }
245
+
246
+ /**
247
+ * "A, B & 5 other mutual connections" / "A is a mutual connection" /
248
+ * "Alex & 12 other connections work here": the named people plus "N other".
249
+ */
250
+ function countNamedConnections(text: string, named: number): number {
251
+ const others = text.match(/(\d[\d,]*)\s+others?\b/i)?.[1];
252
+ return named + (others ? parseCount(others) : 0);
253
+ }
254
+
255
+ const WORKPLACE_TYPES = new Set(["hybrid", "remote", "on-site"]);
256
+
257
+ /** "London, UK · Hybrid" → location + workplace type; "Remote" alone too. */
258
+ function splitWorkplace(line: string | undefined): {
259
+ location: string | null;
260
+ workplace_type: string | null;
261
+ } {
262
+ if (!line) return { location: null, workplace_type: null };
263
+ const parts = line.split(/\s+·\s+/);
264
+ const last = parts.at(-1) ?? "";
265
+ if (WORKPLACE_TYPES.has(last.toLowerCase())) {
266
+ return {
267
+ location: nonEmpty(parts.slice(0, -1).join(" · ")),
268
+ workplace_type: last,
269
+ };
270
+ }
271
+ return { location: line, workplace_type: null };
272
+ }
273
+
274
+ const DURATION_RE = /^\d+\s+(?:yrs?|mos?)\b/i;
275
+
276
+ /** LinkedIn's "30M followers" / "1,234 followers" → 30000000 / 1234. */
277
+ function parseFollowerCount(text: string): number | null {
278
+ const match = text.match(/([\d.,]+)\s*([KMB])?\+?\s+followers?\b/i);
279
+ if (!match?.[1]) return null;
280
+ const unit = match[2]?.toUpperCase();
281
+ const base = unit
282
+ ? Number.parseFloat(match[1].replace(/,/g, ""))
283
+ : Number.parseInt(match[1].replace(/[.,]/g, ""), 10);
284
+ if (!Number.isFinite(base)) return null;
285
+ const scale =
286
+ unit === "K" ? 1e3 : unit === "M" ? 1e6 : unit === "B" ? 1e9 : 1;
287
+ return Math.round(base * scale);
288
+ }
289
+
290
+ async function scrape(
291
+ dispatcher: ChromeActionDispatcher,
292
+ url: string,
293
+ config: ExtensionScrapeConfig
294
+ ): Promise<{ rows: Row[]; loggedIn: boolean; landedUrl?: string }> {
295
+ const result = await extensionDomScrape<Row>({
296
+ dispatcher,
297
+ url,
298
+ config: { loggedOutWhen: LINKEDIN_LOGGED_OUT_WHEN, ...config },
299
+ parseRows: (rows) => rows,
300
+ allowedOrigins: LINKEDIN_ALLOWED_ORIGINS,
301
+ persistent: false,
302
+ });
303
+ return {
304
+ rows: result.items,
305
+ loggedIn: result.loggedIn,
306
+ landedUrl: result.landedUrl,
307
+ };
308
+ }
309
+
310
+ type Run = (dispatcher: ChromeActionDispatcher) => Promise<Row | null>;
311
+
312
+ /** Validate every input first, then dispatch; a null run result means the
313
+ * paired Chrome is signed out of LinkedIn. */
314
+ async function runAction(
315
+ ctx: ActionContext,
316
+ prepare: (input: Row) => Run
317
+ ): Promise<ActionResult> {
318
+ let run: Run;
319
+ try {
320
+ run = prepare(ctx.input);
321
+ } catch (error) {
322
+ if (error instanceof InputError)
323
+ return { success: false, error: error.message };
324
+ throw error;
325
+ }
326
+ const output = await run(requireBrowser(ctx));
327
+ if (!output) return { success: false, error: LINKEDIN_LOGGED_OUT_ERROR };
328
+ return { success: true, output };
329
+ }
330
+
331
+ // ── search_people ──────────────────────────────────────────────
332
+
333
+ /** Public jobs typeahead: the only location lookup that returns geo ids as JSON. */
334
+ function geoTypeaheadUrl(query: string): string {
335
+ const params = new URLSearchParams({
336
+ origin: "jserp",
337
+ typeaheadType: "GEO",
338
+ geoTypes: "POPULATED_PLACE,ADMIN_DIVISION_2,MARKET_AREA,COUNTRY_REGION",
339
+ query,
340
+ });
341
+ return `https://www.linkedin.com/jobs-guest/api/typeaheadHits?${params}`;
342
+ }
343
+
344
+ /** First geo hit from the typeahead body. Chrome's JSON viewer can prefix
345
+ * the raw text with its own "Raw/Parsed" toggle label, so parse from `[`. */
346
+ function parseGeoTypeahead(
347
+ text: string | undefined
348
+ ): { geo_id: string; display_name: string } | null {
349
+ if (!text) return null;
350
+ const start = text.indexOf("[");
351
+ if (start < 0) return null;
352
+ let hits: unknown;
353
+ try {
354
+ hits = JSON.parse(text.slice(start));
355
+ } catch {
356
+ return null;
357
+ }
358
+ if (!Array.isArray(hits)) return null;
359
+ for (const hit of hits) {
360
+ const id = String((hit as Row | null)?.id ?? "");
361
+ const name = cleanText((hit as Row | null)?.displayName);
362
+ if (/^\d+$/.test(id)) return { geo_id: id, display_name: name };
363
+ }
364
+ return null;
365
+ }
366
+
367
+ const PEOPLE_SEARCH_CONFIG = {
368
+ scroll: { max: 1, stall: 1, waitMs: 2000 },
369
+ // The first result sits inside its own SearchResults_FirstResult wrapper,
370
+ // so match list items anywhere under <main> rather than direct children.
371
+ rowSelector: 'main [role="listitem"]',
372
+ requireFields: ["profile_url"],
373
+ id: { source: "field", field: "profile_url" },
374
+ fields: {
375
+ profile_url: { selector: 'a[href*="/in/"]', take: "attr", attr: "href" },
376
+ name: { selector: 'p > a[href*="/in/"]', take: "text" },
377
+ name_line: { selector: 'p:has(> a[href*="/in/"])', take: "text" },
378
+ verified: {
379
+ selector: 'p > a[href*="/in/"] [role="img"][aria-label]',
380
+ take: "attr",
381
+ attr: "aria-label",
382
+ },
383
+ headline: { selector: 'p:has(> a[href*="/in/"]) + div', take: "text" },
384
+ location: {
385
+ selector: 'p:has(> a[href*="/in/"]) + div + div',
386
+ take: "text",
387
+ },
388
+ snippet: {
389
+ selector: '[componentkey^="SearchResultssnippet_"]',
390
+ take: "text",
391
+ },
392
+ // The shared-connections line links each named mutual connection and,
393
+ // past two, a canned search for the rest.
394
+ mutual_line: {
395
+ selector:
396
+ 'p:has(> span > a[href*="/in/"]), p:has(> span > a[href*="connectionOf"])',
397
+ take: "text",
398
+ },
399
+ mutual_people: {
400
+ selector: 'p > span > a[href*="/in/"]',
401
+ take: "objectAll",
402
+ parts: { h: { take: "attr", attr: "href" }, t: { take: "text" } },
403
+ },
404
+ mutual_search: {
405
+ selector: 'a[href*="connectionOf"]',
406
+ take: "attr",
407
+ attr: "href",
408
+ },
409
+ },
410
+ };
411
+
412
+ function mutualConnections(
413
+ line: string,
414
+ people: Array<{ name: string; profile_url: string | null }>,
415
+ searchUrl: string
416
+ ): Row | null {
417
+ if (!/\bmutual connections?\b/i.test(line)) return null;
418
+ return {
419
+ count: countNamedConnections(line, people.length),
420
+ people,
421
+ search_url: searchUrl ? decodeLinkedInRedirect(searchUrl) : null,
422
+ };
423
+ }
424
+
425
+ function parsePeopleRows(rows: Row[]): Row[] {
426
+ const seen = new Set<string>();
427
+ const people: Row[] = [];
428
+ for (const row of rows) {
429
+ const profileUrl = canonicalProfileUrl(cleanText(row.profile_url));
430
+ if (!profileUrl || seen.has(profileUrl)) continue;
431
+ seen.add(profileUrl);
432
+ const nameLine = cleanText(row.name_line);
433
+ const name =
434
+ cleanText(row.name) || nameLine.replace(/\s*[·•].*$/, "").trim();
435
+ const snippet = cleanText(row.snippet);
436
+ const [, label, value] = snippet.match(/^(Current|Past):\s*(.+)$/i) ?? [];
437
+ const mutual = mutualConnections(
438
+ cleanText(row.mutual_line),
439
+ linkList(row.mutual_people).map((link) => ({
440
+ name: link.text,
441
+ profile_url: canonicalProfileUrl(link.href),
442
+ })),
443
+ cleanText(row.mutual_search)
444
+ );
445
+ people.push({
446
+ name: nonEmpty(name),
447
+ headline: nonEmpty(cleanText(row.headline)),
448
+ location: nonEmpty(cleanText(row.location)),
449
+ profile_url: profileUrl,
450
+ degree: degreeOf(nameLine),
451
+ verified: cleanText(row.verified).toLowerCase() === "verified",
452
+ current_position:
453
+ label?.toLowerCase() === "current" ? nonEmpty(value) : null,
454
+ past_position: label?.toLowerCase() === "past" ? nonEmpty(value) : null,
455
+ snippet: label ? null : nonEmpty(snippet),
456
+ mutual_connections: mutual,
457
+ });
458
+ }
459
+ return people;
460
+ }
461
+
462
+ export async function searchLinkedInPeople(
463
+ ctx: ActionContext
464
+ ): Promise<ActionResult> {
465
+ return runAction(ctx, (input) => {
466
+ const searchKeywords = requiredText(input, "keywords");
467
+ const title = optionalText(input, "title");
468
+ const company = optionalText(input, "company");
469
+ const location = optionalText(input, "location");
470
+ const network = readNetwork(input);
471
+ const page = readSearchPage(input);
472
+ return async (dispatcher) => {
473
+ let keywords = searchKeywords;
474
+
475
+ let locationFilter: Row | undefined;
476
+ let geoId: string | undefined;
477
+ if (location) {
478
+ const { rows } = await scrape(dispatcher, geoTypeaheadUrl(location), {
479
+ scroll: { max: 0, stall: 0, waitMs: 300 },
480
+ rowSelector: "body",
481
+ fields: { json: { selector: "pre", take: "text" } },
482
+ });
483
+ const hit = parseGeoTypeahead(cleanText(rows[0]?.json));
484
+ if (hit) {
485
+ geoId = hit.geo_id;
486
+ locationFilter = { query: location, applied: "geo_filter", ...hit };
487
+ } else {
488
+ keywords = `${keywords} ${location}`;
489
+ locationFilter = { query: location, applied: "keywords" };
490
+ }
491
+ }
492
+
493
+ const params = new URLSearchParams({
494
+ keywords,
495
+ origin: "FACETED_SEARCH",
496
+ });
497
+ if (title) params.set("title", title);
498
+ if (company) params.set("company", company);
499
+ if (network.length)
500
+ params.set(
501
+ "network",
502
+ JSON.stringify(network.map((degree) => NETWORK_FACETS[degree]))
503
+ );
504
+ if (geoId) params.set("geoUrn", JSON.stringify([geoId]));
505
+ if (page > 1) params.set("page", String(page));
506
+ const url = `https://www.linkedin.com/search/results/people/?${params}`;
507
+
508
+ const { rows, loggedIn } = await scrape(
509
+ dispatcher,
510
+ url,
511
+ PEOPLE_SEARCH_CONFIG
512
+ );
513
+ if (!loggedIn) return null;
514
+ const people = parsePeopleRows(rows);
515
+ return {
516
+ page,
517
+ search_url: url,
518
+ ...(locationFilter ? { location_filter: locationFilter } : {}),
519
+ count: people.length,
520
+ people,
521
+ };
522
+ };
523
+ });
524
+ }
525
+
526
+ // ── read_profile ───────────────────────────────────────────────
527
+
528
+ // Scrape payloads can reach the extension with their keys re-ordered, so
529
+ // every config names its merge key instead of relying on the first field.
530
+ const PROFILE_CONFIG = {
531
+ // The page scrolls inside <main>; the top card and About render first.
532
+ scroll: { max: 2, stall: 1, waitMs: 2000, deep: true },
533
+ rowSelector: "main section",
534
+ id: { source: "field", field: "text" },
535
+ fields: {
536
+ text: { take: "text" },
537
+ heading: { selector: "h2", take: "text" },
538
+ lines: { selector: "p", take: "objectAll", parts: { t: { take: "text" } } },
539
+ // The top card renders a hidden alternate degree badge as the only child
540
+ // of a display:none wrapper; the visible badge has siblings.
541
+ visible_lines: {
542
+ selector: "p:not(:only-child)",
543
+ take: "objectAll",
544
+ parts: { t: { take: "text" } },
545
+ },
546
+ links: {
547
+ selector: "a[href]",
548
+ take: "objectAll",
549
+ parts: { h: { take: "attr", attr: "href" }, t: { take: "text" } },
550
+ },
551
+ mutual_names: {
552
+ selector: 'a[href*="connectionOf"] strong',
553
+ take: "objectAll",
554
+ parts: { t: { take: "text" } },
555
+ },
556
+ multiline_html: MULTILINE_HTML,
557
+ },
558
+ };
559
+
560
+ // The main profile only renders Experience and Education when their lazy
561
+ // anchors scroll into a visible viewport, so read the details pages instead.
562
+ const DETAIL_LINES = {
563
+ lines: { selector: "p", take: "objectAll", parts: { t: { take: "text" } } },
564
+ // Long descriptions are the only paragraphs that wrap their text in a span.
565
+ spans: {
566
+ selector: "p > span",
567
+ take: "objectAll",
568
+ parts: { t: { take: "text" } },
569
+ },
570
+ org_url: {
571
+ selector: 'a[href*="/company/"], a[href*="/school/"]',
572
+ take: "attr",
573
+ attr: "href",
574
+ },
575
+ multiline_html: MULTILINE_HTML,
576
+ } as const;
577
+
578
+ const EDUCATION_CONFIG = {
579
+ scroll: { max: 2, stall: 1, waitMs: 2500, deep: true },
580
+ rowSelector: 'main [componentkey*="EducationDetailsSection"] [componentkey]',
581
+ requireFields: ["lines"],
582
+ id: { source: "field", field: "text" },
583
+ fields: { text: { take: "text" }, ...DETAIL_LINES },
584
+ };
585
+
586
+ const EXPERIENCE_CONFIG = {
587
+ scroll: { max: 2, stall: 1, waitMs: 2500, deep: true },
588
+ id: { source: "field", field: "text" },
589
+ // A company with several roles renders one header entry with each role as
590
+ // an <li>; single-role entries have no list. Rows arrive in document order,
591
+ // so each role list follows its company header.
592
+ rowSelector: [
593
+ 'main [componentkey^="entity-collection-item"]',
594
+ 'main [componentkey^="entity-collection-item"] li',
595
+ ].join(", "),
596
+ fields: {
597
+ text: { take: "text" },
598
+ ...DETAIL_LINES,
599
+ // Paragraphs inside role items; on a header row they are its roles' lines.
600
+ role_lines: {
601
+ selector: "li p",
602
+ take: "objectAll",
603
+ parts: { t: { take: "text" } },
604
+ },
605
+ group_company: {
606
+ closestSelector: '[componentkey^="entity-collection-item"]',
607
+ firstLine: true,
608
+ },
609
+ },
610
+ };
611
+
612
+ const SKILLS_CONFIG = {
613
+ scroll: { max: 3, stall: 1, waitMs: 2500, deep: true },
614
+ // The escaped "(" is the same selector to Chrome; JSDOM needs the escape.
615
+ rowSelector: 'main [componentkey^="com.linkedin.sdui.profile.skill\\("]',
616
+ requireFields: ["name"],
617
+ id: { source: "field", field: "name" },
618
+ fields: {
619
+ name: { selector: "p", take: "text" },
620
+ lines: { selector: "p", take: "objectAll", parts: { t: { take: "text" } } },
621
+ },
622
+ };
623
+
624
+ // Only rendered for 1st-degree connections and the viewer's own profile;
625
+ // anyone else's overlay URL redirects back to the profile.
626
+ const CONTACT_CONFIG = {
627
+ scroll: { max: 0, stall: 0, waitMs: 2000 },
628
+ rowSelector: '[componentkey*="ContactInfoDetailSection"] [componentkey]',
629
+ requireFields: ["label"],
630
+ id: { source: "field", field: "text" },
631
+ fields: {
632
+ text: { take: "text" },
633
+ label: { selector: "p", take: "text" },
634
+ lines: { selector: "p", take: "objectAll", parts: { t: { take: "text" } } },
635
+ links: {
636
+ selector: "a[href]",
637
+ take: "objectAll",
638
+ parts: { h: { take: "attr", attr: "href" }, t: { take: "text" } },
639
+ },
640
+ },
641
+ };
642
+
643
+ const DATE_RANGE_RE =
644
+ /^(?:[A-Z][a-z]{2,8}\.? )?\d{4}\s*[-–]\s*(?:(?:[A-Z][a-z]{2,8}\.? )?\d{4}|Present)\b/;
645
+ const YEAR_RANGE_RE =
646
+ /^(?:[A-Z][a-z]{2,8}\.? )?\d{4}(?:\s*[-–]\s*(?:(?:[A-Z][a-z]{2,8}\.? )?\d{4}|Present))?$/;
647
+
648
+ /** The joined long-text spans, minus the role's "Present" badge. */
649
+ function descriptionOf(row: Row): string | null {
650
+ const text = lineTexts(row.spans)
651
+ .filter((line) => line !== "Present")
652
+ .map(stripMore)
653
+ .join(" ")
654
+ .trim();
655
+ return nonEmpty(
656
+ withLineBreaks(text, row.multiline_html).slice(0, MAX_DESCRIPTION_CHARS)
657
+ );
658
+ }
659
+
660
+ type GroupHeader = {
661
+ company: string;
662
+ employment_type: string | null;
663
+ location: string | null;
664
+ workplace_type: string | null;
665
+ company_url: string | null;
666
+ };
667
+
668
+ /** A multi-role company header: name, "Full-time · 6 yrs", location. */
669
+ function parseGroupHeader(row: Row): GroupHeader | null {
670
+ const lines = lineTexts(row.lines);
671
+ const header = lines.slice(0, lines.length - lineTexts(row.role_lines).length);
672
+ if (!header[0]) return null;
673
+ const facts = (header[1] ?? "").split(/\s+·\s+/).filter(Boolean);
674
+ const type = facts.find((fact) => !DURATION_RE.test(fact));
675
+ return {
676
+ company: header[0],
677
+ employment_type: type ?? null,
678
+ ...splitWorkplace(header[2]),
679
+ company_url: canonicalCompanyUrl(cleanText(row.org_url)),
680
+ };
681
+ }
682
+
683
+ /** One role: title, company, dates, location, description. */
684
+ function parseExperienceRow(
685
+ row: Row,
686
+ group: GroupHeader | undefined
687
+ ): Row | null {
688
+ const lines = lineTexts(row.lines);
689
+ const title = lines[0];
690
+ if (!title) return null;
691
+ const description = descriptionOf(row);
692
+ const dateIndex = lines.findIndex((line) => DATE_RANGE_RE.test(line));
693
+ let company = group?.company ?? null;
694
+ let employmentType = group?.employment_type ?? null;
695
+ if (!group && dateIndex !== 1 && lines[1]) {
696
+ const [name, type] = lines[1].split(/\s+·\s+/);
697
+ company = nonEmpty(name);
698
+ employmentType = nonEmpty(type);
699
+ }
700
+ const [dates, duration] =
701
+ dateIndex >= 0 ? lines[dateIndex].split(/\s+·\s+/) : [];
702
+ // The location, when listed, is the first plain line after the dates.
703
+ const spans = new Set(lineTexts(row.spans));
704
+ const locationLine =
705
+ dateIndex >= 0
706
+ ? lines
707
+ .slice(dateIndex + 1)
708
+ .find(
709
+ (line) =>
710
+ line !== "Present" && !spans.has(line) && !/^Skills:/i.test(line)
711
+ )
712
+ : undefined;
713
+ const skillsLine = lines.find((line) => /^Skills:/i.test(line));
714
+ const place = locationLine
715
+ ? splitWorkplace(locationLine)
716
+ : {
717
+ location: group?.location ?? null,
718
+ workplace_type: group?.workplace_type ?? null,
719
+ };
720
+ return {
721
+ title,
722
+ company,
723
+ employment_type: employmentType,
724
+ dates: nonEmpty(dates ?? null),
725
+ duration: nonEmpty(duration ?? null),
726
+ is_current: /present/i.test(dates ?? ""),
727
+ ...place,
728
+ description,
729
+ skills: skillsLine
730
+ ? skillsLine
731
+ .replace(/^Skills:\s*/i, "")
732
+ .split(/\s+·\s+/)
733
+ .filter(Boolean)
734
+ : [],
735
+ company_url:
736
+ canonicalCompanyUrl(cleanText(row.org_url)) ?? group?.company_url ?? null,
737
+ };
738
+ }
739
+
740
+ function parseExperienceRows(rows: Row[]): Row[] {
741
+ const groups = new Map<string, GroupHeader>();
742
+ const positions: Row[] = [];
743
+ for (const row of rows) {
744
+ const groupName = cleanText(row.group_company);
745
+ if (!groupName && lineTexts(row.role_lines).length > 0) {
746
+ const header = parseGroupHeader(row);
747
+ if (header) groups.set(header.company, header);
748
+ continue;
749
+ }
750
+ const position = parseExperienceRow(
751
+ row,
752
+ groupName
753
+ ? (groups.get(groupName) ?? {
754
+ company: groupName,
755
+ employment_type: null,
756
+ location: null,
757
+ workplace_type: null,
758
+ company_url: null,
759
+ })
760
+ : undefined
761
+ );
762
+ if (position) positions.push(position);
763
+ }
764
+ return positions;
765
+ }
766
+
767
+ function parseEducationRow(row: Row): Row | null {
768
+ const lines = lineTexts(row.lines);
769
+ const school = lines[0];
770
+ if (!school) return null;
771
+ const spans = new Set(lineTexts(row.spans));
772
+ const dateIndex = lines.findIndex((line) => YEAR_RANGE_RE.test(line));
773
+ const labelled = (label: string) =>
774
+ nonEmpty(
775
+ lines
776
+ .find((line) => line.startsWith(`${label}:`))
777
+ ?.slice(label.length + 1)
778
+ .trim() ?? null
779
+ );
780
+ const degreeLine =
781
+ lines[1] &&
782
+ dateIndex !== 1 &&
783
+ !spans.has(lines[1]) &&
784
+ !/^[A-Z][a-z ]+:/.test(lines[1])
785
+ ? lines[1]
786
+ : undefined;
787
+ // LinkedIn joins the degree and the field of study with a comma.
788
+ const comma = degreeLine?.indexOf(", ") ?? -1;
789
+ return {
790
+ school,
791
+ degree: nonEmpty(comma > 0 ? degreeLine?.slice(0, comma) : degreeLine),
792
+ field_of_study: comma > 0 ? nonEmpty(degreeLine?.slice(comma + 2)) : null,
793
+ dates: dateIndex >= 0 ? lines[dateIndex] : null,
794
+ grade: labelled("Grade"),
795
+ activities: labelled("Activities and societies"),
796
+ description: descriptionOf(row),
797
+ school_url: canonicalCompanyUrl(cleanText(row.org_url)),
798
+ };
799
+ }
800
+
801
+ function parseSkills(rows: Row[]): Row[] {
802
+ const seen = new Set<string>();
803
+ const skills: Row[] = [];
804
+ for (const row of rows) {
805
+ const name = cleanText(row.name);
806
+ if (!name || seen.has(name)) continue;
807
+ seen.add(name);
808
+ const endorsements = lineTexts(row.lines)
809
+ .map((line) => line.match(/^(\d[\d,]*)\s+endorsements?$/i)?.[1])
810
+ .find(Boolean);
811
+ skills.push({
812
+ name,
813
+ endorsements: endorsements ? parseCount(endorsements) : 0,
814
+ });
815
+ }
816
+ return skills.slice(0, MAX_SKILLS);
817
+ }
818
+
819
+ /** Contact overlay entries: a label paragraph followed by its value(s). */
820
+ function parseContactInfo(rows: Row[]): Row {
821
+ const info: Row = {
822
+ email: null,
823
+ phone: null,
824
+ websites: [],
825
+ birthday: null,
826
+ connected_since: null,
827
+ address: null,
828
+ };
829
+ for (const row of rows) {
830
+ const label = cleanText(row.label).toLowerCase();
831
+ const values = lineTexts(row.lines).slice(1);
832
+ const links = linkList(row.links);
833
+ if (label === "website" || label === "websites") {
834
+ info.websites = links.flatMap((link) => {
835
+ const url = decodeLinkedInRedirect(link.href);
836
+ if (!url) return [];
837
+ const kind = values
838
+ .find((value) => value.includes(link.text))
839
+ ?.slice(link.text.length)
840
+ .match(/^\s*\(([^)]+)\)/)?.[1];
841
+ return [{ url, type: kind ?? null }];
842
+ });
843
+ } else if (label === "email") {
844
+ const mail = links.find((link) => link.href.startsWith("mailto:"));
845
+ info.email = mail ? mail.href.slice("mailto:".length) : nonEmpty(values[0]);
846
+ } else if (label === "phone") {
847
+ info.phone = nonEmpty(values.join(", "));
848
+ } else if (label === "birthday") {
849
+ info.birthday = nonEmpty(values[0]);
850
+ } else if (label === "connected") {
851
+ info.connected_since = nonEmpty(values[0]);
852
+ } else if (label === "address") {
853
+ info.address = nonEmpty(values.join(", "));
854
+ }
855
+ }
856
+ return info;
857
+ }
858
+
859
+ /** Top card + About from the main profile page's `section` rows. */
860
+ function parseProfileSections(rows: Row[]): Row {
861
+ const top = rows.find((row) => cleanText(row.heading)) ?? rows[0];
862
+ const name = cleanText(top?.heading);
863
+ const lines = lineTexts(top?.lines);
864
+ const degreeLine = lineTexts(top?.visible_lines).find((line) =>
865
+ DEGREE_RE.test(line.replace(/^[·•]\s*/, ""))
866
+ );
867
+ const pronouns = lines.find((line) => /^[A-Za-z]+\/[A-Za-z]+$/.test(line));
868
+ // Drop the degree badges and the optional pronoun line ("She/Her") that
869
+ // LinkedIn renders between the name and the headline.
870
+ const content = lines.filter(
871
+ (line) => !/^[·•]\s*(1st|2nd|3rd\+?|You)$/i.test(line) && line !== pronouns
872
+ );
873
+ // The location is the line before the "· Contact info" separator.
874
+ const separator = content.findIndex((line) => line === "·");
875
+ const about = rows.find(
876
+ (row) => cleanText(row.heading).toLowerCase() === "about"
877
+ );
878
+ const aboutText = lineTexts(about?.lines).reduce(
879
+ (longest, line) => (line.length > longest.length ? line : longest),
880
+ ""
881
+ );
882
+ // "500+" / "connections" render as two paragraphs.
883
+ const connectionsIndex = lines.findIndex((line) =>
884
+ /^connections?$/i.test(line)
885
+ );
886
+ const connections =
887
+ connectionsIndex > 0 && /^[\d,]+\+?$/.test(lines[connectionsIndex - 1])
888
+ ? lines[connectionsIndex - 1]
889
+ : null;
890
+ // Creators show followers on the top card, everyone else in Activity.
891
+ const followersLine = rows
892
+ .flatMap((row) => lineTexts(row.lines))
893
+ .find((line) => /^[\d,.]+[KMB]?\+?\s+followers?$/i.test(line));
894
+ const links = linkList(top?.links);
895
+ const mutualLink = links.find((link) => link.href.includes("connectionOf"));
896
+ const mutualNames = lineTexts(top?.mutual_names).flatMap((names) =>
897
+ names.split(/,\s*|\s+and\s+/).filter(Boolean)
898
+ );
899
+ const website = links
900
+ .filter((link) => isLinkedInRedirect(link.href))
901
+ .map((link) => decodeLinkedInRedirect(link.href))
902
+ .find(Boolean);
903
+ return {
904
+ name: nonEmpty(name),
905
+ pronouns: nonEmpty(pronouns),
906
+ headline: nonEmpty(content[0] ?? null),
907
+ location: separator > 0 ? content[separator - 1] : null,
908
+ degree: degreeOf(degreeLine),
909
+ followers: followersLine ? parseFollowerCount(followersLine) : null,
910
+ connections,
911
+ mutual_connections: mutualLink
912
+ ? {
913
+ count: countNamedConnections(mutualLink.text, mutualNames.length),
914
+ people: mutualNames.map((mutual) => ({
915
+ name: mutual,
916
+ profile_url: null,
917
+ })),
918
+ search_url: decodeLinkedInRedirect(mutualLink.href),
919
+ }
920
+ : null,
921
+ website: website ?? null,
922
+ about: nonEmpty(
923
+ withLineBreaks(stripMore(aboutText), about?.multiline_html).slice(
924
+ 0,
925
+ MAX_ABOUT_CHARS
926
+ )
927
+ ),
928
+ };
929
+ }
930
+
931
+ export async function readLinkedInProfile(
932
+ ctx: ActionContext
933
+ ): Promise<ActionResult> {
934
+ return runAction(ctx, (input) => {
935
+ const profileUrl = canonicalProfileUrl(requiredText(input, "profile_url"));
936
+ if (!profileUrl)
937
+ throw new InputError(
938
+ "profile_url must be a LinkedIn member profile URL (linkedin.com/in/<slug>)"
939
+ );
940
+ return async (dispatcher) => {
941
+ const main = await scrape(dispatcher, profileUrl, PROFILE_CONFIG);
942
+ if (!main.loggedIn) return null;
943
+ const landed = canonicalProfileUrl(main.landedUrl) ?? profileUrl;
944
+ const top = parseProfileSections(main.rows);
945
+ // A missing degree badge means the viewer's own profile.
946
+ const readContact = top.degree === "1st" || top.degree === null;
947
+ const [experience, schools, skills, contact] = await Promise.all([
948
+ scrape(dispatcher, `${landed}details/experience/`, EXPERIENCE_CONFIG),
949
+ scrape(dispatcher, `${landed}details/education/`, EDUCATION_CONFIG),
950
+ scrape(dispatcher, `${landed}details/skills/`, SKILLS_CONFIG),
951
+ readContact
952
+ ? scrape(dispatcher, `${landed}overlay/contact-info/`, CONTACT_CONFIG)
953
+ : null,
954
+ ]);
955
+ if (
956
+ !experience.loggedIn ||
957
+ !schools.loggedIn ||
958
+ !skills.loggedIn ||
959
+ contact?.loggedIn === false
960
+ )
961
+ return null;
962
+ const positions = parseExperienceRows(experience.rows);
963
+ const education = schools.rows
964
+ .map(parseEducationRow)
965
+ .filter((row): row is Row => row !== null);
966
+ return {
967
+ profile_url: landed,
968
+ ...top,
969
+ contact_info: contact?.rows.length
970
+ ? parseContactInfo(contact.rows)
971
+ : null,
972
+ current_positions: positions
973
+ .filter((row) => row.is_current)
974
+ .slice(0, MAX_POSITIONS),
975
+ past_positions: positions
976
+ .filter((row) => !row.is_current)
977
+ .slice(0, MAX_POSITIONS),
978
+ education: education.slice(0, MAX_EDUCATION),
979
+ skills: parseSkills(skills.rows),
980
+ };
981
+ };
982
+ });
983
+ }
984
+
985
+ // ── search_companies ───────────────────────────────────────────
986
+
987
+ /**
988
+ * "Sam & 1 other connection work here" / "Jordan Lee follows this page":
989
+ * the viewer's connections at (or following) a company.
990
+ */
991
+ function networkConnections(
992
+ link: { href: string; text: string } | undefined
993
+ ): Row | null {
994
+ if (!link?.text) return null;
995
+ const names = link.text
996
+ .replace(/\s+(?:works?|follows?)\b.*$/i, "")
997
+ .split(/\s+&\s+\d/)[0];
998
+ return {
999
+ count: countNamedConnections(
1000
+ link.text,
1001
+ names.split(/,\s*|\s+and\s+/).filter(Boolean).length
1002
+ ),
1003
+ search_url: decodeLinkedInRedirect(link.href),
1004
+ };
1005
+ }
1006
+
1007
+ // A card's header is the name <p> (holding the company link) followed by one
1008
+ // sibling <div><p> per fact: industry, then location when the company lists one.
1009
+ // The summary and follower line live in a separate subtree, so reading facts by
1010
+ // position over every <p> would take the summary as a missing location.
1011
+ const COMPANY_NAME = 'p:has(> a[href*="/company/"]), p:has(> a[href*="/showcase/"])';
1012
+ const COMPANY_SEARCH_CONFIG = {
1013
+ scroll: { max: 1, stall: 1, waitMs: 2500 },
1014
+ rowSelector: 'main [role="listitem"]',
1015
+ requireFields: ["company_url"],
1016
+ id: { source: "field", field: "company_url" },
1017
+ fields: {
1018
+ company_url: {
1019
+ selector: 'a[href*="/company/"], a[href*="/showcase/"]',
1020
+ take: "attr",
1021
+ attr: "href",
1022
+ },
1023
+ name: { selector: COMPANY_NAME },
1024
+ verified: {
1025
+ selector: '[role="img"][aria-label="Verified organization"]',
1026
+ take: "attr",
1027
+ attr: "aria-label",
1028
+ },
1029
+ facts: {
1030
+ selector: 'p:has(> a[href*="/company/"]) ~ div > p, p:has(> a[href*="/showcase/"]) ~ div > p',
1031
+ take: "objectAll",
1032
+ parts: { t: { take: "text" } },
1033
+ },
1034
+ // Paragraphs without links: the facts and the company summary.
1035
+ plain_lines: {
1036
+ selector: "p:not(:has(a))",
1037
+ take: "objectAll",
1038
+ parts: { t: { take: "text" } },
1039
+ },
1040
+ network: {
1041
+ selector:
1042
+ 'a[href*="SHARED_CONNECTIONS"], a[href*="showInNetworkFollowers"]',
1043
+ take: "objectAll",
1044
+ parts: { h: { take: "attr", attr: "href" }, t: { take: "text" } },
1045
+ },
1046
+ follow_state: {
1047
+ selector: 'button[aria-label^="Follow"]',
1048
+ take: "attr",
1049
+ attr: "aria-label",
1050
+ },
1051
+ lines: { selector: "p", take: "objectAll", parts: { t: { take: "text" } } },
1052
+ },
1053
+ };
1054
+
1055
+ function parseCompanyRows(rows: Row[]): Row[] {
1056
+ const seen = new Set<string>();
1057
+ const companies: Row[] = [];
1058
+ for (const row of rows) {
1059
+ const companyUrl = canonicalCompanyUrl(cleanText(row.company_url));
1060
+ if (!companyUrl || seen.has(companyUrl)) continue;
1061
+ seen.add(companyUrl);
1062
+ const facts = lineTexts(row.facts);
1063
+ const followersLine = lineTexts(row.lines).find((line) =>
1064
+ /\bfollowers?$/i.test(line)
1065
+ );
1066
+ const summary = lineTexts(row.plain_lines).find(
1067
+ (line) => !facts.includes(line) && !/\bfollowers?$/i.test(line)
1068
+ );
1069
+ const network = linkList(row.network)[0];
1070
+ const connections = networkConnections(network);
1071
+ const working = /\bwork(?:s)? here\b/i.test(network?.text ?? "");
1072
+ companies.push({
1073
+ name: nonEmpty(cleanText(row.name)),
1074
+ industry: nonEmpty(facts[0] ?? null),
1075
+ location: nonEmpty(facts[1] ?? null),
1076
+ summary: nonEmpty(stripMore(summary ?? "").replace(/\.\.\.$/, "…")),
1077
+ followers: followersLine ? parseFollowerCount(followersLine) : null,
1078
+ verified: cleanText(row.verified) !== "",
1079
+ following: /^Following\b/i.test(cleanText(row.follow_state)),
1080
+ connections_working_here: working ? connections : null,
1081
+ connections_following: working ? null : connections,
1082
+ company_url: companyUrl,
1083
+ });
1084
+ }
1085
+ return companies;
1086
+ }
1087
+
1088
+ export async function searchLinkedInCompanies(
1089
+ ctx: ActionContext
1090
+ ): Promise<ActionResult> {
1091
+ return runAction(ctx, (input) => {
1092
+ const keywords = requiredText(input, "keywords");
1093
+ const page = readSearchPage(input);
1094
+ return async (dispatcher) => {
1095
+ const params = new URLSearchParams({ keywords });
1096
+ if (page > 1) params.set("page", String(page));
1097
+ const url = `https://www.linkedin.com/search/results/companies/?${params}`;
1098
+ const { rows, loggedIn } = await scrape(
1099
+ dispatcher,
1100
+ url,
1101
+ COMPANY_SEARCH_CONFIG
1102
+ );
1103
+ if (!loggedIn) return null;
1104
+ const companies = parseCompanyRows(rows);
1105
+ return { page, search_url: url, count: companies.length, companies };
1106
+ };
1107
+ });
1108
+ }
1109
+
1110
+ // ── read_company ───────────────────────────────────────────────
1111
+
1112
+ const TOP_CARD = '[componentkey^="pages.topCard."]';
1113
+
1114
+ // One row: the whole page. The top card carries the tagline, the follower and
1115
+ // employee counts and the viewer's network; the About tab's Overview section
1116
+ // lists the description followed by labelled facts.
1117
+ const COMPANY_ABOUT_CONFIG = {
1118
+ scroll: { max: 1, stall: 1, waitMs: 2500 },
1119
+ rowSelector: "main",
1120
+ requireFields: ["name"],
1121
+ id: { source: "field", field: "name" },
1122
+ fields: {
1123
+ name: { selector: `${TOP_CARD} h2, h1`, take: "text" },
1124
+ top_card: { selector: TOP_CARD, take: "attr", attr: "componentkey" },
1125
+ tagline: { selector: `${TOP_CARD} div:has(> h2) + p`, take: "text" },
1126
+ // The facts row follows the heading's wrapper when the company has a
1127
+ // tagline, and sits beside the heading itself when it has none.
1128
+ top_facts: {
1129
+ selector: `${TOP_CARD} div:has(> h2) ~ div > p, ${TOP_CARD} h2 ~ div > p`,
1130
+ take: "objectAll",
1131
+ parts: { t: { take: "text" } },
1132
+ },
1133
+ top_lines: {
1134
+ selector: `${TOP_CARD} p`,
1135
+ take: "objectAll",
1136
+ parts: { t: { take: "text" } },
1137
+ },
1138
+ network: {
1139
+ selector: `${TOP_CARD} a[href*="network="]`,
1140
+ take: "objectAll",
1141
+ parts: { h: { take: "attr", attr: "href" }, t: { take: "text" } },
1142
+ },
1143
+ follow_state: {
1144
+ selector: `${TOP_CARD} button[aria-label^="Follow"]`,
1145
+ take: "attr",
1146
+ attr: "aria-label",
1147
+ },
1148
+ top_website: {
1149
+ selector: `${TOP_CARD} a[href*="/safety/go"]`,
1150
+ take: "attr",
1151
+ attr: "href",
1152
+ },
1153
+ lines: {
1154
+ selector: "h2, h3, p, dt, dd",
1155
+ take: "objectAll",
1156
+ parts: { t: { take: "text" } },
1157
+ },
1158
+ multiline_html: MULTILINE_HTML,
1159
+ },
1160
+ };
1161
+
1162
+ const COMPANY_FACTS = {
1163
+ website: "website",
1164
+ "verified page": "verified_since",
1165
+ industry: "industry",
1166
+ "company size": "company_size",
1167
+ headquarters: "headquarters",
1168
+ founded: "founded",
1169
+ type: "type",
1170
+ specialties: "specialties",
1171
+ phone: "phone",
1172
+ } as const;
1173
+
1174
+ function companyFactKey(line: string) {
1175
+ return COMPANY_FACTS[line.toLowerCase() as keyof typeof COMPANY_FACTS];
1176
+ }
1177
+
1178
+ /** The top card, then the Overview section's description and labelled facts. */
1179
+ function parseCompanyAbout(row: Row | undefined): Row {
1180
+ const lines = lineTexts(row?.lines);
1181
+ const facts: Record<string, string | null> = Object.fromEntries(
1182
+ Object.values(COMPANY_FACTS).map((key) => [key, null])
1183
+ );
1184
+ const overview = lines.indexOf("Overview");
1185
+ const body = overview >= 0 ? lines.slice(overview + 1) : [];
1186
+ body.forEach((line, index) => {
1187
+ const key = companyFactKey(line);
1188
+ const value = body[index + 1];
1189
+ if (key && value && facts[key] === null) facts[key] = value;
1190
+ });
1191
+ // The description runs until the highlights or the first labelled fact.
1192
+ const firstFact = body.findIndex((line) => companyFactKey(line));
1193
+ const highlightsStart = body.findIndex((line) =>
1194
+ line.startsWith("Highlights from ")
1195
+ );
1196
+ const aboutEnd = [highlightsStart, firstFact].filter((i) => i >= 0);
1197
+ const about = body
1198
+ .slice(0, aboutEnd.length ? Math.min(...aboutEnd) : 1)
1199
+ .map((paragraph) => withLineBreaks(paragraph, row?.multiline_html))
1200
+ .join("\n\n")
1201
+ .slice(0, MAX_ABOUT_CHARS);
1202
+ const highlights =
1203
+ highlightsStart >= 0
1204
+ ? body.slice(
1205
+ highlightsStart + 1,
1206
+ firstFact > highlightsStart ? firstFact : undefined
1207
+ )
1208
+ : [];
1209
+ const sizeIndex = body.findIndex(
1210
+ (line) => companyFactKey(line) === "company_size"
1211
+ );
1212
+ const membersLine =
1213
+ sizeIndex >= 0
1214
+ ? body
1215
+ .slice(sizeIndex + 2, sizeIndex + 4)
1216
+ .find((line) => /associated members?$/i.test(line))
1217
+ : undefined;
1218
+ const topFacts = lineTexts(row?.top_facts).filter((line) => line !== "·");
1219
+ const followersLine = topFacts.find((line) => /\bfollowers?$/i.test(line));
1220
+ const employeesLine = topFacts.find((line) => /\bemployees?$/i.test(line));
1221
+ const topLocation = topFacts.find(
1222
+ (line, index) =>
1223
+ index > 0 && line !== followersLine && line !== employeesLine
1224
+ );
1225
+ const companyId = cleanText(row?.top_card).match(/topCard\.(\d+)/)?.[1];
1226
+ const topWebsite = decodeLinkedInRedirect(cleanText(row?.top_website));
1227
+ return {
1228
+ company_id: companyId ?? null,
1229
+ name: nonEmpty(cleanText(row?.name)),
1230
+ tagline: nonEmpty(cleanText(row?.tagline)),
1231
+ about: nonEmpty(about),
1232
+ website: facts.website ?? (cleanText(row?.top_website) ? topWebsite : null),
1233
+ industry: facts.industry ?? nonEmpty(topFacts[0] ?? null),
1234
+ company_size: facts.company_size,
1235
+ employees_on_linkedin: membersLine ? parseCount(membersLine) : null,
1236
+ headquarters: facts.headquarters ?? nonEmpty(topLocation ?? null),
1237
+ founded: facts.founded,
1238
+ type: facts.type,
1239
+ specialties: facts.specialties
1240
+ ? facts.specialties
1241
+ .split(",")
1242
+ .map((specialty) => specialty.trim())
1243
+ .filter(Boolean)
1244
+ : [],
1245
+ phone: facts.phone,
1246
+ followers: followersLine ? parseFollowerCount(followersLine) : null,
1247
+ verified: facts.verified_since !== null,
1248
+ verified_since: facts.verified_since,
1249
+ highlights:
1250
+ highlights.length > 0
1251
+ ? highlights
1252
+ : lineTexts(row?.top_lines).filter((line) =>
1253
+ line.startsWith("Ranked on LinkedIn")
1254
+ ),
1255
+ following: /^Following\b/i.test(cleanText(row?.follow_state)),
1256
+ connections_working_here: networkConnections(linkList(row?.network)[0]),
1257
+ };
1258
+ }
1259
+
1260
+ export async function readLinkedInCompany(
1261
+ ctx: ActionContext
1262
+ ): Promise<ActionResult> {
1263
+ return runAction(ctx, (input) => {
1264
+ const companyUrl = canonicalCompanyUrl(requiredText(input, "company_url"));
1265
+ if (!companyUrl)
1266
+ throw new InputError(
1267
+ "company_url must be a LinkedIn company page URL (linkedin.com/company/<slug>)"
1268
+ );
1269
+ return async (dispatcher) => {
1270
+ const { rows, loggedIn, landedUrl } = await scrape(
1271
+ dispatcher,
1272
+ `${companyUrl}about/`,
1273
+ COMPANY_ABOUT_CONFIG
1274
+ );
1275
+ if (!loggedIn) return null;
1276
+ return {
1277
+ company_url: canonicalCompanyUrl(landedUrl) ?? companyUrl,
1278
+ ...parseCompanyAbout(rows[0]),
1279
+ };
1280
+ };
1281
+ });
1282
+ }
1283
+
1284
+ export { InputError as LinkedInInputError, requiredText, runAction };