@lobu/runtime-server 24.11.1 → 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.
- package/dist/catalogs/connectors.json +1113 -107
- package/dist/catalogs/skills.json +2 -2
- package/dist/component.json +1 -1
- package/dist/connectors/README.md +2 -2
- package/dist/connectors/chat-transport-actions.ts +50 -0
- package/dist/connectors/discord.ts +2 -0
- package/dist/connectors/gchat.ts +2 -0
- package/dist/connectors/github.ts +4 -4
- package/dist/connectors/google_drive.ts +20 -0
- package/dist/connectors/google_gmail.ts +49 -8
- package/dist/connectors/herdr.ts +1 -1
- package/dist/connectors/imessage.ts +1 -0
- package/dist/connectors/linkedin-browser-script.ts +11 -0
- package/dist/connectors/linkedin-draft-page.js +24 -8
- package/dist/connectors/linkedin-inbox-adapter.js +209 -19
- package/dist/connectors/linkedin-inbox.ts +152 -4
- package/dist/connectors/linkedin-network.ts +788 -0
- package/dist/connectors/linkedin-search.ts +1284 -0
- package/dist/connectors/linkedin.ts +892 -27
- package/dist/connectors/microsoft_outlook.ts +57 -19
- package/dist/connectors/rss.ts +179 -33
- package/dist/connectors/slack.ts +2 -0
- package/dist/connectors/source-file-attachment.ts +46 -0
- package/dist/connectors/teams.ts +2 -0
- package/dist/connectors/telegram.ts +2 -0
- package/dist/connectors/tiktok_web.ts +1 -1
- package/dist/connectors/whatsapp.ts +2 -0
- package/dist/connectors/whatsapp_web.ts +3 -3
- package/dist/connectors/x-dm-adapter.js +8 -10
- package/dist/connectors/x.ts +8 -9
- package/dist/db/migrations/20261115040000_account_two_factor.sql +20 -0
- package/dist/db/migrations/20261115130000_entities_retired_type_idx.sql +34 -0
- package/dist/db/migrations/20261115140000_entity_identities_personal_owner_idx.sql +34 -0
- package/dist/db/migrations/20261117090000_write_policy_kind_note.sql +65 -0
- package/dist/db/migrations/20261117120000_app_policy_principal.sql +48 -0
- package/dist/db/migrations/20261117170000_personal_org_connector_auto_policy_backfill.sql +57 -0
- package/dist/db/migrations/20261117190000_org_slug_reserved_paths.sql +29 -0
- package/dist/db/migrations/20261118120000_workspace_view_top_level_paths.sql +69 -0
- package/dist/db/migrations/preconditions/20261117190000_org_slug_reserved_paths.sql +14 -0
- package/dist/db/migrations/preconditions/20261118120000_workspace_view_top_level_paths.sql +21 -0
- package/dist/dependencies.bun.lock +51 -46
- package/dist/guest.bundle.js +11 -2
- package/dist/owletto/dist/assets/_-BC9j6MkU.js +2 -0
- package/dist/owletto/dist/assets/_-Z1u1cIe6.js +3 -0
- package/dist/owletto/dist/assets/_agentId-B-TFq9TP.js +2 -0
- package/dist/owletto/dist/assets/{_agentId-CGScf8z_.js → _agentId-BGatZWsd.js} +2 -2
- package/dist/owletto/dist/assets/_automationId-CMUrWPvr.js +2 -0
- package/dist/owletto/dist/assets/_connectorKey._connectionId-CUoAoP0_.js +2 -0
- package/dist/owletto/dist/assets/_connectorKey.index-Bs49QGGH.js +2 -0
- package/dist/owletto/dist/assets/_conversationId-CszP1den.js +2 -0
- package/dist/owletto/dist/assets/_eventId-C0AZUBnD.js +2 -0
- package/dist/owletto/dist/assets/_owner-B4ydA75k.js +3 -0
- package/dist/owletto/dist/assets/_shape-C4-ikE70.js +2 -0
- package/dist/owletto/dist/assets/_slug-DE5J3KVu.js +2 -0
- package/dist/owletto/dist/assets/_viewKey-Dkcd8JQC.js +2 -0
- package/dist/owletto/dist/assets/{accept-invitation-BKeIzZXE.js → accept-invitation-DmrQQu_W.js} +2 -2
- package/dist/owletto/dist/assets/{activity-route-location-sLvKaSCa.js → activity-route-location-Bec6fW-t.js} +2 -2
- package/dist/owletto/dist/assets/activity-route-view-DCSNBKZU.js +2 -0
- package/dist/owletto/dist/assets/agent-client-connections-xvabPpi6.js +4 -0
- package/dist/owletto/dist/assets/agent-connect-pages-DDPtkcmq.js +6 -0
- package/dist/owletto/dist/assets/{agent-editor-form-DVFyyMyd.js → agent-editor-form-BrhQbHZg.js} +2 -2
- package/dist/owletto/dist/assets/{agent-loading-shells-BLNHIy-r.js → agent-loading-shells-D3y98xuO.js} +2 -2
- package/dist/owletto/dist/assets/{agent-permissions-matrix-UBKRR5vs.js → agent-permissions-matrix-jQJjSa9i.js} +2 -2
- package/dist/owletto/dist/assets/{agent-skill-context-fqedKd0D.js → agent-skill-context-CCcknBYE.js} +2 -2
- package/dist/owletto/dist/assets/{agent-subpage-shell-BUCoY2Nf.js → agent-subpage-shell-6f_53cSf.js} +2 -2
- package/dist/owletto/dist/assets/agent-thread-v_lSSnJi.js +6 -0
- package/dist/owletto/dist/assets/{app._appId-ByIypCL9.js → app._appId-CKWzZ2ic.js} +2 -2
- package/dist/owletto/dist/assets/assist-composer-Q9ZJjAta.js +2 -0
- package/dist/owletto/dist/assets/automation-run-now-Dl0MKx3N.js +2 -0
- package/dist/owletto/dist/assets/{callback-Pz5uS-k7.js → callback-Bentv78L.js} +2 -2
- package/dist/owletto/dist/assets/{card-CAPpY9P5.js → card-C4oPCVh6.js} +2 -2
- package/dist/owletto/dist/assets/{claim-DgWWK0KI.js → claim-B3C4qIi2.js} +2 -2
- package/dist/owletto/dist/assets/client-activity-scopes-DqaFEyir.js +2 -0
- package/dist/owletto/dist/assets/{client-rows-Dd5YV8vn.js → client-rows-rse9thnk.js} +2 -2
- package/dist/owletto/dist/assets/{clients-Bf7ZgGro.js → clients-BhPMbxHi.js} +2 -2
- package/dist/owletto/dist/assets/{code-editor-z1Sy_hiX.js → code-editor-CTdKUDPY.js} +2 -2
- package/dist/owletto/dist/assets/connect-D8o7HBlo.js +2 -0
- package/dist/owletto/dist/assets/connect-menu-D5EZvSHb.js +2 -0
- package/dist/owletto/dist/assets/connect._clientId-Dbagcg9L.js +2 -0
- package/dist/owletto/dist/assets/connected._clientId-DALW9S2K.js +2 -0
- package/dist/owletto/dist/assets/connection-DyxzSqVE.js +2 -0
- package/dist/owletto/dist/assets/connection-feed-detail-LqpxUCdy.js +2 -0
- package/dist/owletto/dist/assets/{connector-page-shell-an3SYLim.js → connector-page-shell-DZjKv9zQ.js} +2 -2
- package/dist/owletto/dist/assets/{connector-provenance-mSZCOud-.js → connector-provenance-DtTJn1Nk.js} +2 -2
- package/dist/owletto/dist/assets/connectors-BVl-AR33.js +2 -0
- package/dist/owletto/dist/assets/{consent-1ulwyJ3k.js → consent-XCqsHLxS.js} +2 -2
- package/dist/owletto/dist/assets/{core.esm-Ctg_pXLe.js → core.esm-B1du4Zwy.js} +3 -3
- package/dist/owletto/dist/assets/create-BYKCtGL4.js +2 -0
- package/dist/owletto/dist/assets/create-D6Mmuxcq.js +2 -0
- package/dist/owletto/dist/assets/{create-CGuoqPh8.js → create-GHTb6wKX.js} +2 -2
- package/dist/owletto/dist/assets/{create-automation-form-CD6jSlWL.js → create-automation-form-CTiy_S9G.js} +3 -3
- package/dist/owletto/dist/assets/create._connectorKey-DMH97KkK.js +2 -0
- package/dist/owletto/dist/assets/custom-guardrail-edits-DZy66ucV.js +2 -0
- package/dist/owletto/dist/assets/definition-comparison-C2mPfIMD.js +2 -0
- package/dist/owletto/dist/assets/detail-page-skeleton-DNBL7nyk.js +2 -0
- package/dist/owletto/dist/assets/device-CwP1PY8q.js +2 -0
- package/dist/owletto/dist/assets/{device-pin-tombstone-Dkj7hrBE.js → device-pin-tombstone-DYTt7kU5.js} +2 -2
- package/dist/owletto/dist/assets/device._deviceId-DZ2kqI4Y.js +2 -0
- package/dist/owletto/dist/assets/{entity-options-D4t-NAcg.js → entity-options-D9K_5Lcs.js} +2 -2
- package/dist/owletto/dist/assets/entity-page-DggKXrcE.js +2 -0
- package/dist/owletto/dist/assets/entity-pages-C6M6yKFf.js +2 -0
- package/dist/owletto/dist/assets/{entity-schema-graph-Cq96SJ3c.js → entity-schema-graph-B255NKjF.js} +2 -2
- package/dist/owletto/dist/assets/entity-type-page-CGBAP2wt.js +2 -0
- package/dist/owletto/dist/assets/event-attachments-D8Z8uwv9.js +2 -0
- package/dist/owletto/dist/assets/event-detail-CgG3pDLA.js +2 -0
- package/dist/owletto/dist/assets/events-feed-ClhEywwV.js +2 -0
- package/dist/owletto/dist/assets/{filter-editors-DGVl9U4D.js → filter-editors-D_Sfn0dv.js} +3 -3
- package/dist/owletto/dist/assets/{full-page-spinner-CtVlF8GQ.js → full-page-spinner-C1clibUY.js} +2 -2
- package/dist/owletto/dist/assets/{index-CK5GDX4B.js → index-04B26s6E.js} +2 -2
- package/dist/owletto/dist/assets/index-2HrEO-nl.js +2 -0
- package/dist/owletto/dist/assets/index-BU3k9wpw.js +2 -0
- package/dist/owletto/dist/assets/{index-DvuJ_S_o.js → index-BXHqp23o.js} +2 -2
- package/dist/owletto/dist/assets/index-BdLRUDIR.js +2 -0
- package/dist/owletto/dist/assets/index-C2FrGwYN.js +2 -0
- package/dist/owletto/dist/assets/index-CB9wGfUm.js +2 -0
- package/dist/owletto/dist/assets/index-Caihaftb.js +2 -0
- package/dist/owletto/dist/assets/index-CwH59DJV.js +2 -0
- package/dist/owletto/dist/assets/index-DB2lVKuV.js +7908 -0
- package/dist/owletto/dist/assets/{index-DbjbHlDe.js → index-DTvJRjrM.js} +2 -2
- package/dist/owletto/dist/assets/index-SF2ni1Rs.css +1 -0
- package/dist/owletto/dist/assets/{index-BifR-LE9.js → index-mSrdbx3C.js} +9 -9
- package/dist/owletto/dist/assets/index-uFn-Ilrx.js +2 -0
- package/dist/owletto/dist/assets/{json-diff-OjtREegr.js → json-diff-Ce6YAXzY.js} +2 -2
- package/dist/owletto/dist/assets/{list-skeleton-CH0qQBYk.js → list-skeleton-DLPBTnbR.js} +2 -2
- package/dist/owletto/dist/assets/login-DeWlvogD.js +2 -0
- package/dist/owletto/dist/assets/{logout-DfdgOLoM.js → logout-CJY0ceN9.js} +2 -2
- package/dist/owletto/dist/assets/{member-scope-gate-Cxg2zGQT.js → member-scope-gate-CBPMprXu.js} +2 -2
- package/dist/owletto/dist/assets/memory-browse-page-D5kj1RaR.js +74 -0
- package/dist/owletto/dist/assets/{model-selector-D2OpDkwH.js → model-selector-CjkBPpjN.js} +2 -2
- package/dist/owletto/dist/assets/new-BKrNkOQD.js +2 -0
- package/dist/owletto/dist/assets/new-BetiMuDq.js +2 -0
- package/dist/owletto/dist/assets/new-dk_-eXqU.js +2 -0
- package/dist/owletto/dist/assets/new-efN--4Wx.js +2 -0
- package/dist/owletto/dist/assets/organization-C3rpwx_d.js +2 -0
- package/dist/owletto/dist/assets/pdf-document--AN-oCKj.css +1 -0
- package/dist/owletto/dist/assets/pdf-document-2W1q0sRA.js +56 -0
- package/dist/owletto/dist/assets/pdf.worker.min-CIqJB0yW.mjs +28 -0
- package/dist/owletto/dist/assets/peek-pane-content-ChsBWO0P.js +3 -0
- package/dist/owletto/dist/assets/{pending-seed-BBACroge.js → pending-seed-CTKYdA4X.js} +2 -2
- package/dist/owletto/dist/assets/proposal-review-shell-EyGWEYwQ.js +2 -0
- package/dist/owletto/dist/assets/public-shell-ready-_KWdfzEM.js +2 -0
- package/dist/owletto/dist/assets/record-session-D27VNxP_.js +2 -0
- package/dist/owletto/dist/assets/{renderer-CTKNMcXP.js → renderer-B8yZ5lql.js} +34 -33
- package/dist/owletto/dist/assets/{reset-password-DKBEneyR.js → reset-password-BGVJIh2I.js} +2 -2
- package/dist/owletto/dist/assets/run-initiator-C0sur8lU.js +2 -0
- package/dist/owletto/dist/assets/runs-list-CJOFMgpk.js +2 -0
- package/dist/owletto/dist/assets/schema-value-DDNHANGs.js +3 -0
- package/dist/owletto/dist/assets/{scoped-feed-bar-DNFL0sYX.js → scoped-feed-bar-BTv9mPcR.js} +2 -2
- package/dist/owletto/dist/assets/settings-Ponr5XbS.js +3 -0
- package/dist/owletto/dist/assets/{status-variants-SzXYYedJ.js → status-variants-mLqVhg5O.js} +2 -2
- package/dist/owletto/dist/assets/subDays-BGA_fkig.js +2 -0
- package/dist/owletto/dist/assets/two-factor-pqoxGSgL.js +2 -0
- package/dist/owletto/dist/assets/{use-automations-DfBtVzGa.js → use-automations-DcdlmVuX.js} +2 -2
- package/dist/owletto/dist/assets/{use-login-redirect-BDiS3eyl.js → use-login-redirect-D7HW5Ed6.js} +2 -2
- package/dist/owletto/dist/assets/{use-mention-search-khySpz_V.js → use-mention-search-BniE-K2d.js} +3 -3
- package/dist/owletto/dist/assets/view-card-Cg6PeEiV.js +2 -0
- package/dist/owletto/dist/assets/view-param-filters-CvrKw0mZ.js +2 -0
- package/dist/owletto/dist/index.html +2 -2
- package/dist/server-main.bundle.mjs +5718 -2991
- package/npm-shrinkwrap.json +195 -172
- package/package.json +2 -1
- package/vendor/connector-sdk/dist/connector-types.d.ts +20 -0
- package/vendor/connector-sdk/dist/define-connector.js +2 -0
- package/vendor/connector-sdk/dist/extension-dom-scrape.d.ts +2 -0
- package/vendor/connector-sdk/dist/extension-dom-scrape.js +5 -0
- package/vendor/connector-sdk/dist/reaction-client-types.d.ts +20 -0
- package/vendor/connector-sdk/package.json +1 -1
- package/vendor/core/dist/contracts/entity-reference.d.ts +2 -0
- package/vendor/core/dist/contracts/entity-reference.js +4 -3
- package/vendor/core/dist/contracts/tools/entity-list-sort.d.ts +18 -0
- package/vendor/core/dist/contracts/tools/entity-list-sort.js +64 -0
- package/vendor/core/dist/contracts/tools/manage-agents.d.ts +1 -1
- package/vendor/core/dist/contracts/tools/manage-agents.js +3 -3
- package/vendor/core/dist/contracts/tools/manage-entity-schema.d.ts +4 -0
- package/vendor/core/dist/contracts/tools/manage-entity-schema.js +4 -0
- package/vendor/core/dist/contracts/tools/manage-entity.d.ts +4 -0
- package/vendor/core/dist/contracts/tools/manage-entity.js +11 -1
- package/vendor/core/dist/contracts/tools/manage-operations.d.ts +29 -3
- package/vendor/core/dist/contracts/tools/manage-operations.js +24 -2
- package/vendor/core/dist/contracts/tools/manage-views.d.ts +36 -0
- package/vendor/core/dist/contracts/tools/manage-views.js +15 -2
- package/vendor/core/dist/contracts/tools/view-definition.js +7 -2
- package/vendor/core/dist/contracts/tools/view-host.js +5 -0
- package/vendor/core/dist/contracts/tools/view-path.d.ts +8 -1
- package/vendor/core/dist/contracts/tools/view-path.js +11 -1
- package/vendor/core/dist/reserved.d.ts +7 -1
- package/vendor/core/dist/reserved.js +17 -0
- package/vendor/core/package.json +6 -1
- package/vendor/views/dist/api.d.ts +19 -3
- package/vendor/views/dist/api.js +53 -5
- package/vendor/views/dist/components.d.ts +7 -0
- package/vendor/views/dist/components.js +223 -2
- package/vendor/views/dist/embed.js +13 -2
- package/vendor/views/dist/live-gate.d.ts +34 -0
- package/vendor/views/dist/live-gate.js +100 -0
- package/vendor/views/dist/native.d.ts +43 -1
- package/vendor/views/dist/native.js +1 -0
- package/vendor/views/package.json +1 -1
- package/dist/owletto/dist/assets/_-BDMUN9XZ.js +0 -2
- package/dist/owletto/dist/assets/_-CF5X4ANe.js +0 -3
- package/dist/owletto/dist/assets/_agentId-EQU2aUP0.js +0 -2
- package/dist/owletto/dist/assets/_automationId-PXZ33jsF.js +0 -2
- package/dist/owletto/dist/assets/_connectorKey._connectionId-DcI29kGy.js +0 -2
- package/dist/owletto/dist/assets/_connectorKey.index-Cr2NDJWX.js +0 -2
- package/dist/owletto/dist/assets/_conversationId-CnmLYlVS.js +0 -2
- package/dist/owletto/dist/assets/_eventId-w5sDz5oa.js +0 -2
- package/dist/owletto/dist/assets/_owner-CkOZR4n0.js +0 -3
- package/dist/owletto/dist/assets/_shape-C_FmSf9G.js +0 -2
- package/dist/owletto/dist/assets/_slug-COPpRXLt.js +0 -2
- package/dist/owletto/dist/assets/_viewKey-BVdJiilV.js +0 -2
- package/dist/owletto/dist/assets/_viewKey-mxxpqjtC.js +0 -2
- package/dist/owletto/dist/assets/activity-route-view-msesKUwn.js +0 -2
- package/dist/owletto/dist/assets/agent-connect-pages-DVq9nAR7.js +0 -4
- package/dist/owletto/dist/assets/agent-thread-Cqf9ITrT.js +0 -6
- package/dist/owletto/dist/assets/assist-composer-kG_heHXo.js +0 -2
- package/dist/owletto/dist/assets/automation-run-now-C5XTS00o.js +0 -2
- package/dist/owletto/dist/assets/client-activity-scopes-Aqdo6Pdr.js +0 -2
- package/dist/owletto/dist/assets/connect-BFNp1y_s.js +0 -2
- package/dist/owletto/dist/assets/connect-menu-BWrAhMqO.js +0 -2
- package/dist/owletto/dist/assets/connect._clientId-CSPfwYIN.js +0 -2
- package/dist/owletto/dist/assets/connected._clientId-CuOeHafK.js +0 -2
- package/dist/owletto/dist/assets/connection-CVeHmDLs.js +0 -2
- package/dist/owletto/dist/assets/connection-feed-detail-BYo7zdVD.js +0 -2
- package/dist/owletto/dist/assets/connectors-DBEM9QQz.js +0 -2
- package/dist/owletto/dist/assets/copy-button-Xhh7ZnjO.js +0 -2
- package/dist/owletto/dist/assets/create-Ccb5R-S4.js +0 -2
- package/dist/owletto/dist/assets/create-DmhbacIa.js +0 -2
- package/dist/owletto/dist/assets/create._connectorKey-CZsAqj1p.js +0 -2
- package/dist/owletto/dist/assets/custom-guardrail-edits-Ce_BwiwD.js +0 -2
- package/dist/owletto/dist/assets/definition-comparison-D_qP25jR.js +0 -2
- package/dist/owletto/dist/assets/detail-page-skeleton-CPAfZLG0.js +0 -2
- package/dist/owletto/dist/assets/device-DDl5XKvt.js +0 -2
- package/dist/owletto/dist/assets/device._deviceId-bNhTcops.js +0 -2
- package/dist/owletto/dist/assets/dynamic-schema-form-CRyUchXo.js +0 -2
- package/dist/owletto/dist/assets/entity-page-BOOL_vy3.js +0 -2
- package/dist/owletto/dist/assets/entity-pages-_nuesgnp.js +0 -2
- package/dist/owletto/dist/assets/entity-type-page-CkCSbkBx.js +0 -2
- package/dist/owletto/dist/assets/event-detail-DUvlqn9b.js +0 -2
- package/dist/owletto/dist/assets/events-feed-DcKTkJVe.js +0 -2
- package/dist/owletto/dist/assets/index-BUlkNJzX.js +0 -2
- package/dist/owletto/dist/assets/index-BoqrvLHQ.js +0 -7906
- package/dist/owletto/dist/assets/index-CA9mW_ZM.js +0 -2
- package/dist/owletto/dist/assets/index-CH0GzG4i.js +0 -2
- package/dist/owletto/dist/assets/index-CtI5Eomq.js +0 -2
- package/dist/owletto/dist/assets/index-DmtQ0bds.js +0 -2
- package/dist/owletto/dist/assets/index-Du_J8hnx.js +0 -2
- package/dist/owletto/dist/assets/index-Pae_f9LM.css +0 -1
- package/dist/owletto/dist/assets/index-XETZnN7L.js +0 -2
- package/dist/owletto/dist/assets/login-DG0b9uSC.js +0 -2
- package/dist/owletto/dist/assets/memory-browse-page-qEDQ9Z18.js +0 -74
- package/dist/owletto/dist/assets/missing-view-xT0B-f5z.js +0 -2
- package/dist/owletto/dist/assets/needs-you-list-3uMsWcDv.js +0 -2
- package/dist/owletto/dist/assets/new-AdGV6a8R.js +0 -2
- package/dist/owletto/dist/assets/new-BdtIhBpo.js +0 -2
- package/dist/owletto/dist/assets/new-BjGwX6s6.js +0 -2
- package/dist/owletto/dist/assets/new-D-iMjV74.js +0 -2
- package/dist/owletto/dist/assets/organization-qaIpEiQg.js +0 -2
- package/dist/owletto/dist/assets/peek-pane-content-CEsDVScl.js +0 -2
- package/dist/owletto/dist/assets/proposal-review-shell-C8ZfIAYn.js +0 -2
- package/dist/owletto/dist/assets/public-shell-ready-K2R8iXSI.js +0 -2
- package/dist/owletto/dist/assets/record-session-BrM9cdXu.js +0 -2
- package/dist/owletto/dist/assets/run-initiator-BKSgI1o0.js +0 -2
- package/dist/owletto/dist/assets/runs-k2NpbZm8.js +0 -2
- package/dist/owletto/dist/assets/runs-list-DUXRMkWN.js +0 -2
- package/dist/owletto/dist/assets/schema-value-wjqGxXhv.js +0 -3
- package/dist/owletto/dist/assets/settings-V0m5Om5j.js +0 -2
- package/dist/owletto/dist/assets/source-record-panels-BMut9YIA.js +0 -2
- package/dist/owletto/dist/assets/subDays-9s9OEl5t.js +0 -2
- package/dist/owletto/dist/assets/table-ZuYMOjVR.js +0 -2
- package/dist/owletto/dist/assets/view-card-DiHWlypr.js +0 -2
- package/dist/owletto/dist/assets/view-param-filters-DGKxSr7r.js +0 -2
- package/dist/owletto/dist/assets/views-access-required-HA-PiOwA.js +0 -2
|
@@ -0,0 +1,788 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LinkedIn network actions: connection requests (send, withdraw), removing a
|
|
3
|
+
* connection, following people and companies, and listing pending sent
|
|
4
|
+
* invitations. Each write opens a scratch tab on the exact profile or company,
|
|
5
|
+
* acts only through the controls LinkedIn renders for that named member,
|
|
6
|
+
* re-reads the state after a reload, and closes its tab. Controls are matched
|
|
7
|
+
* by their accessible names, which carry the member's name, so a control for
|
|
8
|
+
* another member (sidebars, feeds, sticky headers) is never clicked.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
ActionContext,
|
|
13
|
+
ActionResult,
|
|
14
|
+
ChromeActionDispatcher,
|
|
15
|
+
} from "@lobu/connector-sdk";
|
|
16
|
+
import { requireBrowser } from "@lobu/connector-sdk";
|
|
17
|
+
import {
|
|
18
|
+
LINKEDIN_ALLOWED_ORIGINS,
|
|
19
|
+
linkedInScriptArgument,
|
|
20
|
+
} from "./linkedin-browser-script.js";
|
|
21
|
+
import { canonicalCompanyUrl, canonicalProfileUrl } from "./linkedin-search.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Connection requests this connector sends per LinkedIn account per UTC day
|
|
25
|
+
* from one browser. LinkedIn restricts accounts that invite in bursts well
|
|
26
|
+
* before its own weekly limit, so the connector caps itself.
|
|
27
|
+
*/
|
|
28
|
+
export const DAILY_CONNECTION_REQUEST_LIMIT = 20;
|
|
29
|
+
const MAX_NOTE_CHARS = 300;
|
|
30
|
+
const MAX_EMAIL_CHARS = 254;
|
|
31
|
+
const MAX_LISTED_INVITATIONS = 200;
|
|
32
|
+
const DEFAULT_LISTED_INVITATIONS = 50;
|
|
33
|
+
export const SENT_INVITATIONS_URL =
|
|
34
|
+
"https://www.linkedin.com/mynetwork/invitation-manager/sent/";
|
|
35
|
+
|
|
36
|
+
export type LinkedInNetworkRequest =
|
|
37
|
+
| { op: "read"; kind: "profile" | "company"; path: string }
|
|
38
|
+
| ({ op: "connect"; kind: "profile"; path: string } & InvitationBudget)
|
|
39
|
+
| ({
|
|
40
|
+
op: "invite";
|
|
41
|
+
kind: "profile";
|
|
42
|
+
path: string;
|
|
43
|
+
name: string;
|
|
44
|
+
note: string | null;
|
|
45
|
+
email: string | null;
|
|
46
|
+
} & InvitationBudget)
|
|
47
|
+
| { op: "withdraw" | "remove"; kind: "profile"; path: string; account: string }
|
|
48
|
+
| {
|
|
49
|
+
op: "follow";
|
|
50
|
+
kind: "profile" | "company";
|
|
51
|
+
path: string;
|
|
52
|
+
account: string;
|
|
53
|
+
following: boolean;
|
|
54
|
+
}
|
|
55
|
+
| { op: "list"; limit: number; account: string };
|
|
56
|
+
|
|
57
|
+
/** The signed-in account and its daily invitation allowance. */
|
|
58
|
+
interface InvitationBudget {
|
|
59
|
+
account: string;
|
|
60
|
+
daily_limit: number;
|
|
61
|
+
/** UTC day (YYYY-MM-DD) the allowance is counted on. */
|
|
62
|
+
day: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** What the page reports about one member or company. */
|
|
66
|
+
export interface LinkedInRelationship {
|
|
67
|
+
name: string;
|
|
68
|
+
/** Members only: connected, pending (sent request), none, or unavailable (no Connect offered). */
|
|
69
|
+
relation?: "connected" | "pending" | "none" | "unavailable";
|
|
70
|
+
degree?: string | null;
|
|
71
|
+
following: boolean | null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** A refusal the page made before acting (nothing was sent or changed). */
|
|
75
|
+
interface Refusal {
|
|
76
|
+
refused: string;
|
|
77
|
+
message: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type PageResult =
|
|
81
|
+
| (LinkedInRelationship & {
|
|
82
|
+
changed?: boolean;
|
|
83
|
+
/** Connect: LinkedIn's invite route for this member, when one can be sent. */
|
|
84
|
+
invite_url?: string;
|
|
85
|
+
requests_sent_today?: number;
|
|
86
|
+
/** The write's own outcome was lost; only the reload can tell whether it landed. */
|
|
87
|
+
uncertain?: string;
|
|
88
|
+
})
|
|
89
|
+
| Refusal;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The page program. Requests are passed as inert JSON. Writes check the
|
|
93
|
+
* signed-in member first, act at most once, and leave verification of the
|
|
94
|
+
* persisted state to a fresh read after reload.
|
|
95
|
+
*/
|
|
96
|
+
export function buildLinkedInNetworkExpression(
|
|
97
|
+
request: LinkedInNetworkRequest
|
|
98
|
+
): string {
|
|
99
|
+
return String.raw`(async () => {
|
|
100
|
+
const req = ${linkedInScriptArgument(request)};
|
|
101
|
+
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
102
|
+
const shown = el => !!el && el.getClientRects().length > 0;
|
|
103
|
+
const text = el => (el && (el.innerText || el.textContent) || '').trim();
|
|
104
|
+
const refuse = (refused, message) => ({ refused, message });
|
|
105
|
+
const wait = async (read, message, tries = 40) => {
|
|
106
|
+
for (let i = 0; i < tries; i++) {
|
|
107
|
+
const value = read();
|
|
108
|
+
if (value) return value;
|
|
109
|
+
await sleep(200);
|
|
110
|
+
}
|
|
111
|
+
if (message) throw new Error(message);
|
|
112
|
+
return null;
|
|
113
|
+
};
|
|
114
|
+
const decoded = value => { try { return decodeURIComponent(value); } catch { return value; } };
|
|
115
|
+
const pathOf = value => {
|
|
116
|
+
const path = decoded(value).toLowerCase();
|
|
117
|
+
return path.endsWith('/') ? path : path + '/';
|
|
118
|
+
};
|
|
119
|
+
const onTarget = () => {
|
|
120
|
+
if (!location.hostname.endsWith('linkedin.com')) return false;
|
|
121
|
+
const here = pathOf(location.pathname);
|
|
122
|
+
// An invitation is sent from LinkedIn's invite route for the same member.
|
|
123
|
+
if (req.op === 'invite') {
|
|
124
|
+
const vanity = new URLSearchParams(location.search).get('vanityName') || '';
|
|
125
|
+
return here === '/preload/custom-invite/' && '/in/' + vanity.toLowerCase() + '/' === req.path;
|
|
126
|
+
}
|
|
127
|
+
return here.startsWith(req.path);
|
|
128
|
+
};
|
|
129
|
+
const assertPage = () => {
|
|
130
|
+
if (!onTarget()) throw new Error('LinkedIn page changed; refusing to act');
|
|
131
|
+
};
|
|
132
|
+
const assertAccount = async () => {
|
|
133
|
+
const cookie = document.cookie.split('; ').find(c => c.startsWith('JSESSIONID='));
|
|
134
|
+
if (!cookie) throw new Error('Not logged into LinkedIn');
|
|
135
|
+
let csrf = decoded(cookie.slice('JSESSIONID='.length));
|
|
136
|
+
if (csrf.startsWith('"') && csrf.endsWith('"')) csrf = csrf.slice(1, -1);
|
|
137
|
+
const response = await fetch('/voyager/api/me', {
|
|
138
|
+
credentials: 'include',
|
|
139
|
+
headers: { 'csrf-token': csrf, 'x-restli-protocol-version': '2.0.0' },
|
|
140
|
+
});
|
|
141
|
+
if (!response.ok) throw new Error('LinkedIn account check failed (HTTP ' + response.status + ')');
|
|
142
|
+
const self = await response.json();
|
|
143
|
+
if (self?.miniProfile?.entityUrn !== req.account)
|
|
144
|
+
throw new Error('The signed-in LinkedIn account is not the connected account; refusing to act');
|
|
145
|
+
};
|
|
146
|
+
// LinkedIn renders confirmations as a native <dialog> with no role.
|
|
147
|
+
const dialogs = () => [...document.querySelectorAll('dialog[open], [role="dialog"], [role="alertdialog"]')].filter(shown);
|
|
148
|
+
const labelled = root => [root, ...root.querySelectorAll('[aria-label]')]
|
|
149
|
+
.filter(el => shown(el) && el.getAttribute('aria-label'));
|
|
150
|
+
const findLabel = (els, label) => els.filter(el => el.getAttribute('aria-label') === label);
|
|
151
|
+
const enabled = el => el && !el.disabled && el.getAttribute('aria-disabled') !== 'true';
|
|
152
|
+
const click = el => {
|
|
153
|
+
assertPage();
|
|
154
|
+
if (!enabled(el)) throw new Error('LinkedIn control is disabled');
|
|
155
|
+
el.click();
|
|
156
|
+
};
|
|
157
|
+
const buttonNamed = (root, names) => [...root.querySelectorAll('button')]
|
|
158
|
+
.filter(b => shown(b) && (names.includes(text(b)) || names.includes(b.getAttribute('aria-label') || '')));
|
|
159
|
+
const dismiss = async dialog => {
|
|
160
|
+
const close = buttonNamed(dialog, ['Dismiss', 'Cancel'])[0];
|
|
161
|
+
if (close) close.click();
|
|
162
|
+
await wait(() => !dialogs().includes(dialog), null, 15);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// ── Member profile ──────────────────────────────────────────
|
|
166
|
+
const unfollowLabels = name => ['Following, click to unfollow ' + name, 'Following ' + name, 'Unfollow ' + name];
|
|
167
|
+
const hasMore = el => [...el.querySelectorAll('button')].some(b => shown(b) && text(b) === 'More');
|
|
168
|
+
/** The member's own header: the innermost section around the heading that names them. */
|
|
169
|
+
const profileCard = () => {
|
|
170
|
+
let title = document.title;
|
|
171
|
+
if (title.startsWith('(')) title = title.slice(title.indexOf(')') + 1).trim();
|
|
172
|
+
const end = title.lastIndexOf(' | LinkedIn');
|
|
173
|
+
const name = end > 0 ? title.slice(0, end).trim() : '';
|
|
174
|
+
if (!name) return null;
|
|
175
|
+
const heading = [...document.querySelectorAll('main h1, main h2')].find(h => shown(h) && text(h) === name);
|
|
176
|
+
let card = heading;
|
|
177
|
+
while (card && !(card.tagName === 'SECTION' && hasMore(card))) card = card.parentElement;
|
|
178
|
+
if (!card) return null;
|
|
179
|
+
const more = [...card.querySelectorAll('button')].filter(b => shown(b) && text(b) === 'More');
|
|
180
|
+
if (more.length !== 1) throw new Error('LinkedIn profile menu is ambiguous');
|
|
181
|
+
const lines = text(card).split('\n').map(line => line.trim());
|
|
182
|
+
const badge = lines.find(line => line === '· 1st' || line === '· 2nd' || line.startsWith('· 3rd'));
|
|
183
|
+
return { card, name, more: more[0], degree: badge ? badge.slice(2) : null };
|
|
184
|
+
};
|
|
185
|
+
const openMenu = async more => {
|
|
186
|
+
if (more.getAttribute('aria-expanded') !== 'true') more.click();
|
|
187
|
+
return wait(() => document.querySelectorAll('[role="menu"]').length
|
|
188
|
+
? [...document.querySelectorAll('[role="menu"]')].filter(shown)[0] : null,
|
|
189
|
+
'LinkedIn profile menu did not open');
|
|
190
|
+
};
|
|
191
|
+
const closeMenu = async more => {
|
|
192
|
+
if (more.getAttribute('aria-expanded') === 'true') more.click();
|
|
193
|
+
await wait(() => more.getAttribute('aria-expanded') !== 'true', null, 10);
|
|
194
|
+
};
|
|
195
|
+
/** The member's relationship and the controls that change it; the More menu is left open. */
|
|
196
|
+
const profileState = async () => {
|
|
197
|
+
assertPage();
|
|
198
|
+
const top = await wait(profileCard, 'LinkedIn profile header was not found');
|
|
199
|
+
if (!top.name) throw new Error('LinkedIn profile name was not found');
|
|
200
|
+
const menu = await openMenu(top.more);
|
|
201
|
+
const els = [...labelled(top.card), ...labelled(menu)];
|
|
202
|
+
const one = label => {
|
|
203
|
+
const found = findLabel(els, label);
|
|
204
|
+
return found[0] || null;
|
|
205
|
+
};
|
|
206
|
+
const controls = {
|
|
207
|
+
follow: one('Follow ' + top.name),
|
|
208
|
+
unfollow: unfollowLabels(top.name).map(one).find(Boolean) || null,
|
|
209
|
+
invite: one('Invite ' + top.name + ' to connect'),
|
|
210
|
+
pending: one('Pending, click to withdraw invitation sent to ' + top.name),
|
|
211
|
+
remove: labelled(menu).filter(el => el.getAttribute('aria-label') === 'Remove connection')[0] || null,
|
|
212
|
+
};
|
|
213
|
+
if (controls.follow && controls.unfollow) throw new Error('LinkedIn follow state is ambiguous');
|
|
214
|
+
if ([controls.invite, controls.pending, controls.remove].filter(Boolean).length > 1)
|
|
215
|
+
throw new Error('LinkedIn connection state is ambiguous');
|
|
216
|
+
const relation = controls.pending ? 'pending'
|
|
217
|
+
: controls.remove || top.degree === '1st' ? 'connected'
|
|
218
|
+
: controls.invite ? 'none' : 'unavailable';
|
|
219
|
+
const following = controls.follow ? false : controls.unfollow ? true : null;
|
|
220
|
+
return { top, controls, state: { name: top.name, relation, degree: top.degree, following } };
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// ── Company page ────────────────────────────────────────────
|
|
224
|
+
const companyState = async () => {
|
|
225
|
+
assertPage();
|
|
226
|
+
const read = () => {
|
|
227
|
+
const els = labelled(document.querySelector('main') || document.body);
|
|
228
|
+
const found = [...document.querySelectorAll('main h1, main h2')].filter(shown).map(heading => {
|
|
229
|
+
const name = text(heading);
|
|
230
|
+
const follow = findLabel(els, 'Follow ' + name)[0] || null;
|
|
231
|
+
const unfollow = els.find(el => unfollowLabels(name).includes(el.getAttribute('aria-label'))) || null;
|
|
232
|
+
return { name, follow, unfollow };
|
|
233
|
+
}).filter(match => match.name && (match.follow || match.unfollow));
|
|
234
|
+
// Suggested pages carry their own names, so only the page's heading matches.
|
|
235
|
+
if (found.length > 1) throw new Error('LinkedIn company header is ambiguous');
|
|
236
|
+
return found[0] || null;
|
|
237
|
+
};
|
|
238
|
+
const found = await wait(read, 'LinkedIn company follow control was not found');
|
|
239
|
+
if (found.follow && found.unfollow) throw new Error('LinkedIn follow state is ambiguous');
|
|
240
|
+
return { controls: found, state: { name: found.name, following: !found.follow } };
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
/** Wait out a confirmation LinkedIn may show, confirming only the named action. */
|
|
244
|
+
const confirm = async names => {
|
|
245
|
+
const dialog = await wait(() => dialogs()[0] || null, null, 50);
|
|
246
|
+
if (!dialog) return;
|
|
247
|
+
const button = buttonNamed(dialog, names)[0];
|
|
248
|
+
if (!button) {
|
|
249
|
+
const message = text(dialog).slice(0, 300);
|
|
250
|
+
await dismiss(dialog);
|
|
251
|
+
throw new Error('LinkedIn showed an unexpected dialog: ' + message);
|
|
252
|
+
}
|
|
253
|
+
click(button);
|
|
254
|
+
await wait(() => !dialogs().includes(dialog), 'LinkedIn confirmation did not close');
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
/** This browser's per-account count of invitations sent today (UTC). */
|
|
258
|
+
const counterKey = () => 'lobu.linkedin.connection_requests.' + req.account + '.' + req.day;
|
|
259
|
+
const sentToday = () => Number(localStorage.getItem(counterKey())) || 0;
|
|
260
|
+
const dailyLimit = () => sentToday() >= req.daily_limit
|
|
261
|
+
? refuse('daily_limit_reached', 'Already sent ' + sentToday() + ' connection requests today from this browser (limit ' + req.daily_limit + '); try again tomorrow')
|
|
262
|
+
: null;
|
|
263
|
+
|
|
264
|
+
if (req.op === 'invite') {
|
|
265
|
+
assertPage();
|
|
266
|
+
await assertAccount();
|
|
267
|
+
const limited = dailyLimit();
|
|
268
|
+
if (limited) return limited;
|
|
269
|
+
if (!navigator.locks) throw new Error('This browser cannot count connection requests safely');
|
|
270
|
+
const dialog = await wait(() => dialogs()[0] || null, 'LinkedIn invitation dialog did not open', 50);
|
|
271
|
+
const sendBare = buttonNamed(dialog, ['Send without a note'])[0];
|
|
272
|
+
const addNote = buttonNamed(dialog, ['Add a note'])[0];
|
|
273
|
+
if (!sendBare && !addNote && !buttonNamed(dialog, ['Send invitation'])[0]) {
|
|
274
|
+
const message = text(dialog).slice(0, 300);
|
|
275
|
+
await dismiss(dialog);
|
|
276
|
+
// LinkedIn explains its own invitation limits only in prose.
|
|
277
|
+
return refuse(message.toLowerCase().includes('limit') ? 'invitation_limit_reached' : 'unexpected_dialog', 'LinkedIn did not offer to send an invitation: ' + message);
|
|
278
|
+
}
|
|
279
|
+
const setValue = (field, value) => {
|
|
280
|
+
const proto = field.tagName === 'TEXTAREA' ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
|
|
281
|
+
Object.getOwnPropertyDescriptor(proto, 'value').set.call(field, value);
|
|
282
|
+
field.dispatchEvent(new Event('input', { bubbles: true }));
|
|
283
|
+
field.dispatchEvent(new Event('change', { bubbles: true }));
|
|
284
|
+
if (field.value !== value) throw new Error('LinkedIn did not accept the typed value');
|
|
285
|
+
};
|
|
286
|
+
const emailField = [...dialog.querySelectorAll('input[name="email"]')].filter(shown)[0];
|
|
287
|
+
if (emailField) {
|
|
288
|
+
if (!req.email) {
|
|
289
|
+
await dismiss(dialog);
|
|
290
|
+
return refuse('email_required', 'LinkedIn requires ' + req.name + "'s email address before it accepts an invitation; pass email to send one");
|
|
291
|
+
}
|
|
292
|
+
setValue(emailField, req.email);
|
|
293
|
+
}
|
|
294
|
+
let send = sendBare;
|
|
295
|
+
if (req.note) {
|
|
296
|
+
if (addNote) addNote.click();
|
|
297
|
+
const note = await wait(() => [...document.querySelectorAll('textarea[name="message"]')].filter(shown)[0] || null, 'LinkedIn note field did not open');
|
|
298
|
+
setValue(note, req.note);
|
|
299
|
+
send = await wait(() => buttonNamed(document, ['Send invitation'])[0] || null, 'LinkedIn send button was not found');
|
|
300
|
+
}
|
|
301
|
+
if (!send) throw new Error('LinkedIn send button was not found');
|
|
302
|
+
await wait(() => enabled(send), 'LinkedIn kept the send button disabled');
|
|
303
|
+
// Reserve the request under a lock shared by every tab of this browser, so
|
|
304
|
+
// concurrent sends cannot pass the cap together. The reservation is made
|
|
305
|
+
// before clicking: an uncertain send still spends budget.
|
|
306
|
+
const reserved = await navigator.locks.request('lobu.linkedin.connection_requests', async () => {
|
|
307
|
+
if (dailyLimit()) return 0;
|
|
308
|
+
const used = sentToday() + 1;
|
|
309
|
+
localStorage.setItem(counterKey(), String(used));
|
|
310
|
+
return used;
|
|
311
|
+
});
|
|
312
|
+
if (!reserved) {
|
|
313
|
+
await dismiss(dialog);
|
|
314
|
+
return dailyLimit();
|
|
315
|
+
}
|
|
316
|
+
click(send);
|
|
317
|
+
await wait(() => !dialogs().some(d => d === dialog || d.contains(send)), 'LinkedIn invitation dialog did not close');
|
|
318
|
+
const after = dialogs()[0];
|
|
319
|
+
if (after) {
|
|
320
|
+
const message = text(after).slice(0, 300);
|
|
321
|
+
await dismiss(after);
|
|
322
|
+
throw new Error('LinkedIn showed a dialog after sending; check the invitation: ' + message);
|
|
323
|
+
}
|
|
324
|
+
return { name: req.name, relation: 'pending', following: null, changed: true, requests_sent_today: reserved };
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (req.op === 'list') {
|
|
328
|
+
await assertAccount();
|
|
329
|
+
const rows = () => [...document.querySelectorAll('main a[aria-label^="Withdraw invitation sent to "]')].filter(shown).map(link => {
|
|
330
|
+
let row = link.parentElement;
|
|
331
|
+
while (row && row !== document.body && !row.querySelector('a[href*="/in/"]')) row = row.parentElement;
|
|
332
|
+
const profile = row && row.querySelector('a[href*="/in/"]');
|
|
333
|
+
const lines = text(row).split('\n').map(line => line.trim()).filter(Boolean);
|
|
334
|
+
const name = link.getAttribute('aria-label').slice('Withdraw invitation sent to '.length);
|
|
335
|
+
const at = lines.indexOf(name);
|
|
336
|
+
return {
|
|
337
|
+
name,
|
|
338
|
+
headline: at >= 0 && lines[at + 1] && !lines[at + 1].startsWith('Sent ') ? lines[at + 1] : null,
|
|
339
|
+
profile_url: profile ? profile.href : null,
|
|
340
|
+
sent: lines.find(line => line.startsWith('Sent ')) || null,
|
|
341
|
+
};
|
|
342
|
+
});
|
|
343
|
+
await wait(() => document.querySelector('main') && (rows().length || text(document.querySelector('main')).includes('Sent')), 'LinkedIn sent invitations did not load');
|
|
344
|
+
await sleep(800);
|
|
345
|
+
let seen = rows().length;
|
|
346
|
+
for (let i = 0; i < 20 && seen < req.limit; i++) {
|
|
347
|
+
const more = buttonNamed(document, ['Load more', 'Show more', 'Show more results'])[0];
|
|
348
|
+
if (more) more.click(); else window.scrollTo(0, document.body.scrollHeight);
|
|
349
|
+
await sleep(1200);
|
|
350
|
+
const now = rows().length;
|
|
351
|
+
if (now === seen && !more) break;
|
|
352
|
+
seen = now;
|
|
353
|
+
}
|
|
354
|
+
const tab = [...document.querySelectorAll('main a[href*="/invitation-manager/sent/"]')].map(text).find(t => t.startsWith('People'));
|
|
355
|
+
const total = tab ? Number(tab.slice('People'.length).trim().split(' ')[0].split(',').join('')) : NaN;
|
|
356
|
+
const all = rows();
|
|
357
|
+
const invitations = all.slice(0, req.limit);
|
|
358
|
+
// Loading stops once the limit is reached, so LinkedIn's own count is what
|
|
359
|
+
// shows whether more invitations exist.
|
|
360
|
+
const more = all.length > req.limit || (Number.isFinite(total) && total > invitations.length);
|
|
361
|
+
return { invitations, total: Number.isFinite(total) ? total : null, truncated: more };
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Wait until the page itself shows the change. Returning earlier lets the
|
|
366
|
+
* connector's reload cancel LinkedIn's request while it is still in flight.
|
|
367
|
+
*/
|
|
368
|
+
const shows = async (readState, test) => {
|
|
369
|
+
let last = null;
|
|
370
|
+
for (const deadline = Date.now() + 12000; Date.now() < deadline;) {
|
|
371
|
+
await sleep(500);
|
|
372
|
+
last = await readState().catch(error => ({ error: String(error && error.message || error) }));
|
|
373
|
+
if (!last.error && test(last)) return { ...last, changed: true };
|
|
374
|
+
}
|
|
375
|
+
throw new Error('LinkedIn did not show the change on ' + location.href + ': ' + JSON.stringify(last));
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
if (req.kind === 'company') {
|
|
379
|
+
const { controls, state } = await companyState();
|
|
380
|
+
if (req.op === 'read') return { ...state, changed: false };
|
|
381
|
+
await assertAccount();
|
|
382
|
+
if (state.following === req.following) return { ...state, changed: false };
|
|
383
|
+
click(req.following ? controls.follow : controls.unfollow);
|
|
384
|
+
if (!req.following) await confirm(['Unfollow']);
|
|
385
|
+
return shows(async () => (await companyState()).state, now => now.following === req.following);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const { top, controls, state } = await profileState();
|
|
389
|
+
const done = changed => closeMenu(top.more).then(() => ({ ...state, changed }));
|
|
390
|
+
const profileNow = async () => {
|
|
391
|
+
const now = await profileState();
|
|
392
|
+
await closeMenu(now.top.more);
|
|
393
|
+
return now.state;
|
|
394
|
+
};
|
|
395
|
+
if (req.op === 'read') return done(false);
|
|
396
|
+
await assertAccount();
|
|
397
|
+
|
|
398
|
+
if (req.op === 'follow') {
|
|
399
|
+
if (state.following === null) throw new Error('LinkedIn shows no follow control for ' + state.name);
|
|
400
|
+
if (state.following === req.following) return done(false);
|
|
401
|
+
click(req.following ? controls.follow : controls.unfollow);
|
|
402
|
+
if (!req.following) await confirm(['Unfollow']);
|
|
403
|
+
return shows(profileNow, now => now.following === req.following);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
if (req.op === 'withdraw') {
|
|
407
|
+
if (state.relation !== 'pending') return done(false);
|
|
408
|
+
click(controls.pending);
|
|
409
|
+
await confirm(['Withdraw']);
|
|
410
|
+
return shows(profileNow, now => now.relation !== 'pending');
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
if (req.op === 'remove') {
|
|
414
|
+
if (state.relation !== 'connected') return done(false);
|
|
415
|
+
if (!controls.remove) throw new Error('LinkedIn shows no Remove connection option for ' + state.name);
|
|
416
|
+
click(controls.remove);
|
|
417
|
+
await confirm(['Remove', 'Remove connection']);
|
|
418
|
+
return shows(profileNow, now => now.relation !== 'connected');
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// connect
|
|
422
|
+
if (state.relation !== 'none') {
|
|
423
|
+
await closeMenu(top.more);
|
|
424
|
+
if (state.relation === 'unavailable')
|
|
425
|
+
return refuse('not_connectable', 'LinkedIn offers no Connect option for ' + state.name + '; they may only accept followers or invitations from people who know their email');
|
|
426
|
+
return { ...state, changed: false };
|
|
427
|
+
}
|
|
428
|
+
const limited = dailyLimit();
|
|
429
|
+
if (limited) {
|
|
430
|
+
await closeMenu(top.more);
|
|
431
|
+
return limited;
|
|
432
|
+
}
|
|
433
|
+
// Connect is a link to LinkedIn's invite route; clicking it reloads the tab,
|
|
434
|
+
// so the connector opens the route itself and sends from there.
|
|
435
|
+
const link = controls.invite.closest('a[href]');
|
|
436
|
+
if (!link || !link.href.startsWith('https://www.linkedin.com/preload/custom-invite/'))
|
|
437
|
+
throw new Error('LinkedIn Connect option has no invitation link');
|
|
438
|
+
await closeMenu(top.more);
|
|
439
|
+
return { ...state, changed: false, invite_url: link.href };
|
|
440
|
+
})()`;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
async function evaluate<T>(
|
|
444
|
+
browser: ChromeActionDispatcher,
|
|
445
|
+
tabId: number,
|
|
446
|
+
request: LinkedInNetworkRequest
|
|
447
|
+
): Promise<T> {
|
|
448
|
+
const result = await browser.dispatch<{ value?: T; exception?: unknown }>(
|
|
449
|
+
"evaluate",
|
|
450
|
+
{
|
|
451
|
+
tab_id: tabId,
|
|
452
|
+
expression: buildLinkedInNetworkExpression(request),
|
|
453
|
+
allowed_origins: LINKEDIN_ALLOWED_ORIGINS,
|
|
454
|
+
}
|
|
455
|
+
);
|
|
456
|
+
if (result.exception || !result.value)
|
|
457
|
+
throw new Error(
|
|
458
|
+
`LinkedIn ${request.op} failed: ${JSON.stringify(result.exception ?? "empty response")}`
|
|
459
|
+
);
|
|
460
|
+
return result.value;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
async function navigate(
|
|
464
|
+
browser: ChromeActionDispatcher,
|
|
465
|
+
tabId: number,
|
|
466
|
+
url: string
|
|
467
|
+
): Promise<void> {
|
|
468
|
+
await browser.dispatch("navigate", {
|
|
469
|
+
url,
|
|
470
|
+
tab_id: tabId,
|
|
471
|
+
wait_for_load: true,
|
|
472
|
+
allowed_origins: LINKEDIN_ALLOWED_ORIGINS,
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/** Run page work in a scratch tab that is always closed. */
|
|
477
|
+
async function inScratchTab<T>(
|
|
478
|
+
browser: ChromeActionDispatcher,
|
|
479
|
+
url: string,
|
|
480
|
+
work: (tabId: number) => Promise<T>
|
|
481
|
+
): Promise<T> {
|
|
482
|
+
let tabId: number | undefined;
|
|
483
|
+
try {
|
|
484
|
+
const nav = await browser.dispatch<{ tab_id?: number }>("navigate", {
|
|
485
|
+
url,
|
|
486
|
+
new_tab: true,
|
|
487
|
+
wait_for_load: true,
|
|
488
|
+
allowed_origins: LINKEDIN_ALLOWED_ORIGINS,
|
|
489
|
+
});
|
|
490
|
+
tabId = nav.tab_id;
|
|
491
|
+
if (typeof tabId !== "number")
|
|
492
|
+
throw new Error("LinkedIn scratch tab was not created");
|
|
493
|
+
return await work(tabId);
|
|
494
|
+
} finally {
|
|
495
|
+
if (typeof tabId === "number")
|
|
496
|
+
await browser.dispatch("close_tab", {
|
|
497
|
+
tab_id: tabId,
|
|
498
|
+
allowed_origins: LINKEDIN_ALLOWED_ORIGINS,
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
class InputError extends Error {}
|
|
504
|
+
|
|
505
|
+
function savedAccount(ctx: ActionContext): string {
|
|
506
|
+
const account = ctx.sessionState?.account_id;
|
|
507
|
+
if (
|
|
508
|
+
typeof account !== "string" ||
|
|
509
|
+
!account.startsWith("urn:li:fs_miniProfile:")
|
|
510
|
+
)
|
|
511
|
+
throw new InputError(
|
|
512
|
+
"LinkedIn actions require the connection's saved account; reconnect this source"
|
|
513
|
+
);
|
|
514
|
+
return account;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function profileTarget(input: Record<string, unknown>): {
|
|
518
|
+
url: string;
|
|
519
|
+
path: string;
|
|
520
|
+
} {
|
|
521
|
+
const url =
|
|
522
|
+
typeof input.profile_url === "string"
|
|
523
|
+
? canonicalProfileUrl(input.profile_url)
|
|
524
|
+
: null;
|
|
525
|
+
if (!url)
|
|
526
|
+
throw new InputError(
|
|
527
|
+
"profile_url must be a LinkedIn member profile URL (linkedin.com/in/<slug>)"
|
|
528
|
+
);
|
|
529
|
+
return { url, path: pathOf(url) };
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function pathOf(url: string): string {
|
|
533
|
+
return decodeURIComponent(new URL(url).pathname).toLowerCase();
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function optionalString(
|
|
537
|
+
input: Record<string, unknown>,
|
|
538
|
+
name: string,
|
|
539
|
+
max: number
|
|
540
|
+
): string | null {
|
|
541
|
+
const value = input[name];
|
|
542
|
+
if (value === undefined || value === null) return null;
|
|
543
|
+
if (typeof value !== "string") throw new InputError(`${name} must be a string`);
|
|
544
|
+
const trimmed = value.trim();
|
|
545
|
+
if (trimmed.length > max)
|
|
546
|
+
throw new InputError(`${name} must be at most ${max} characters`);
|
|
547
|
+
return trimmed || null;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function isRefusal(value: unknown): value is Refusal {
|
|
551
|
+
return (
|
|
552
|
+
typeof value === "object" &&
|
|
553
|
+
value !== null &&
|
|
554
|
+
typeof (value as Refusal).refused === "string"
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/** A write that is one page evaluation. */
|
|
559
|
+
function once(
|
|
560
|
+
browser: ChromeActionDispatcher,
|
|
561
|
+
request: Exclude<LinkedInNetworkRequest, { op: "read" | "list" }>
|
|
562
|
+
) {
|
|
563
|
+
return (tabId: number) => evaluate<PageResult>(browser, tabId, request);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* One write against a member or company: act once, then reload and re-read the
|
|
568
|
+
* persisted state. A retry after an uncertain result finds the state already
|
|
569
|
+
* reached and changes nothing.
|
|
570
|
+
*/
|
|
571
|
+
async function writeAndVerify(
|
|
572
|
+
browser: ChromeActionDispatcher,
|
|
573
|
+
url: string,
|
|
574
|
+
target: { op: string; kind: "profile" | "company"; path: string },
|
|
575
|
+
act: (tabId: number) => Promise<PageResult>,
|
|
576
|
+
reached: (state: LinkedInRelationship) => boolean
|
|
577
|
+
): Promise<ActionResult> {
|
|
578
|
+
return inScratchTab(browser, url, async (tabId) => {
|
|
579
|
+
const effect = await act(tabId);
|
|
580
|
+
if (isRefusal(effect))
|
|
581
|
+
return {
|
|
582
|
+
success: false,
|
|
583
|
+
error: effect.message,
|
|
584
|
+
output: { code: effect.refused },
|
|
585
|
+
};
|
|
586
|
+
await navigate(browser, tabId, url);
|
|
587
|
+
const persisted = await evaluate<LinkedInRelationship>(browser, tabId, {
|
|
588
|
+
op: "read",
|
|
589
|
+
kind: target.kind,
|
|
590
|
+
path: target.path,
|
|
591
|
+
});
|
|
592
|
+
if (!reached(persisted))
|
|
593
|
+
throw new Error(
|
|
594
|
+
effect.uncertain ??
|
|
595
|
+
`LinkedIn ${target.op} did not persist after reload for ${persisted.name}`
|
|
596
|
+
);
|
|
597
|
+
const { requests_sent_today } = effect;
|
|
598
|
+
return {
|
|
599
|
+
success: true,
|
|
600
|
+
output: {
|
|
601
|
+
url,
|
|
602
|
+
name: persisted.name,
|
|
603
|
+
...(persisted.relation ? { relation: persisted.relation } : {}),
|
|
604
|
+
...(persisted.degree !== undefined ? { degree: persisted.degree } : {}),
|
|
605
|
+
following: persisted.following,
|
|
606
|
+
changed: effect.changed === true,
|
|
607
|
+
verified: true,
|
|
608
|
+
...(requests_sent_today ? { requests_sent_today } : {}),
|
|
609
|
+
},
|
|
610
|
+
};
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
async function guarded(
|
|
615
|
+
run: () => Promise<ActionResult>
|
|
616
|
+
): Promise<ActionResult> {
|
|
617
|
+
try {
|
|
618
|
+
return await run();
|
|
619
|
+
} catch (error) {
|
|
620
|
+
return {
|
|
621
|
+
success: false,
|
|
622
|
+
error: error instanceof Error ? error.message : String(error),
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
export function sendLinkedInConnectionRequest(
|
|
628
|
+
ctx: ActionContext,
|
|
629
|
+
now: Date = new Date()
|
|
630
|
+
): Promise<ActionResult> {
|
|
631
|
+
return guarded(async () => {
|
|
632
|
+
const target = profileTarget(ctx.input);
|
|
633
|
+
const note = optionalString(ctx.input, "note", MAX_NOTE_CHARS);
|
|
634
|
+
const email = optionalString(ctx.input, "email", MAX_EMAIL_CHARS);
|
|
635
|
+
if (email && (!email.includes("@") || email.includes(" ")))
|
|
636
|
+
throw new InputError("email must be an email address");
|
|
637
|
+
const budget = {
|
|
638
|
+
account: savedAccount(ctx),
|
|
639
|
+
daily_limit: DAILY_CONNECTION_REQUEST_LIMIT,
|
|
640
|
+
day: now.toISOString().slice(0, 10),
|
|
641
|
+
};
|
|
642
|
+
const browser = requireBrowser(ctx);
|
|
643
|
+
const profile = { kind: "profile" as const, path: target.path };
|
|
644
|
+
return writeAndVerify(
|
|
645
|
+
browser,
|
|
646
|
+
target.url,
|
|
647
|
+
{ op: "connect", ...profile },
|
|
648
|
+
async (tabId) => {
|
|
649
|
+
const found = await evaluate<PageResult>(browser, tabId, {
|
|
650
|
+
op: "connect",
|
|
651
|
+
...profile,
|
|
652
|
+
...budget,
|
|
653
|
+
});
|
|
654
|
+
if (isRefusal(found) || !found.invite_url) return found;
|
|
655
|
+
const invite = new URL(found.invite_url);
|
|
656
|
+
if (
|
|
657
|
+
invite.origin !== "https://www.linkedin.com" ||
|
|
658
|
+
invite.pathname !== "/preload/custom-invite/"
|
|
659
|
+
)
|
|
660
|
+
throw new Error("LinkedIn offered an unexpected invitation link");
|
|
661
|
+
await navigate(browser, tabId, invite.href);
|
|
662
|
+
try {
|
|
663
|
+
return await evaluate<PageResult>(browser, tabId, {
|
|
664
|
+
op: "invite",
|
|
665
|
+
...profile,
|
|
666
|
+
...budget,
|
|
667
|
+
name: found.name,
|
|
668
|
+
note,
|
|
669
|
+
email,
|
|
670
|
+
});
|
|
671
|
+
} catch (error) {
|
|
672
|
+
// Sending can move the tab off the invite route before the page
|
|
673
|
+
// reports back; the reload decides whether the invitation exists.
|
|
674
|
+
return {
|
|
675
|
+
name: found.name,
|
|
676
|
+
following: found.following,
|
|
677
|
+
changed: true,
|
|
678
|
+
uncertain: error instanceof Error ? error.message : String(error),
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
},
|
|
682
|
+
(state) => state.relation === "pending" || state.relation === "connected"
|
|
683
|
+
);
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
export function withdrawLinkedInConnectionRequest(
|
|
688
|
+
ctx: ActionContext
|
|
689
|
+
): Promise<ActionResult> {
|
|
690
|
+
return guarded(async () => {
|
|
691
|
+
const target = profileTarget(ctx.input);
|
|
692
|
+
const browser = requireBrowser(ctx);
|
|
693
|
+
return writeAndVerify(
|
|
694
|
+
browser,
|
|
695
|
+
target.url,
|
|
696
|
+
{ op: "withdraw", kind: "profile", path: target.path },
|
|
697
|
+
once(browser, {
|
|
698
|
+
op: "withdraw",
|
|
699
|
+
kind: "profile",
|
|
700
|
+
path: target.path,
|
|
701
|
+
account: savedAccount(ctx),
|
|
702
|
+
}),
|
|
703
|
+
(state) => state.relation !== "pending"
|
|
704
|
+
);
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
export function removeLinkedInConnection(
|
|
709
|
+
ctx: ActionContext
|
|
710
|
+
): Promise<ActionResult> {
|
|
711
|
+
return guarded(async () => {
|
|
712
|
+
const target = profileTarget(ctx.input);
|
|
713
|
+
const browser = requireBrowser(ctx);
|
|
714
|
+
return writeAndVerify(
|
|
715
|
+
browser,
|
|
716
|
+
target.url,
|
|
717
|
+
{ op: "remove", kind: "profile", path: target.path },
|
|
718
|
+
once(browser, {
|
|
719
|
+
op: "remove",
|
|
720
|
+
kind: "profile",
|
|
721
|
+
path: target.path,
|
|
722
|
+
account: savedAccount(ctx),
|
|
723
|
+
}),
|
|
724
|
+
(state) => state.relation !== "connected"
|
|
725
|
+
);
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
export function setLinkedInFollow(ctx: ActionContext): Promise<ActionResult> {
|
|
730
|
+
return guarded(async () => {
|
|
731
|
+
const following = ctx.input.following;
|
|
732
|
+
if (typeof following !== "boolean")
|
|
733
|
+
throw new InputError("following must be a boolean");
|
|
734
|
+
const raw = ctx.input.target_url;
|
|
735
|
+
const profile = typeof raw === "string" ? canonicalProfileUrl(raw) : null;
|
|
736
|
+
const company =
|
|
737
|
+
profile || typeof raw !== "string" ? null : canonicalCompanyUrl(raw);
|
|
738
|
+
const url = profile ?? company;
|
|
739
|
+
if (!url)
|
|
740
|
+
throw new InputError(
|
|
741
|
+
"target_url must be a LinkedIn member profile (linkedin.com/in/<slug>) or company page (linkedin.com/company/<slug>) URL"
|
|
742
|
+
);
|
|
743
|
+
const request = {
|
|
744
|
+
op: "follow" as const,
|
|
745
|
+
kind: profile ? ("profile" as const) : ("company" as const),
|
|
746
|
+
path: pathOf(url),
|
|
747
|
+
account: savedAccount(ctx),
|
|
748
|
+
following,
|
|
749
|
+
};
|
|
750
|
+
const browser = requireBrowser(ctx);
|
|
751
|
+
return writeAndVerify(
|
|
752
|
+
browser,
|
|
753
|
+
url,
|
|
754
|
+
request,
|
|
755
|
+
once(browser, request),
|
|
756
|
+
(state) => state.following === following
|
|
757
|
+
);
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
export function listLinkedInSentInvitations(
|
|
762
|
+
ctx: ActionContext
|
|
763
|
+
): Promise<ActionResult> {
|
|
764
|
+
return guarded(async () => {
|
|
765
|
+
const raw = ctx.input.limit;
|
|
766
|
+
if (
|
|
767
|
+
raw !== undefined &&
|
|
768
|
+
(typeof raw !== "number" ||
|
|
769
|
+
!Number.isInteger(raw) ||
|
|
770
|
+
raw < 1 ||
|
|
771
|
+
raw > MAX_LISTED_INVITATIONS)
|
|
772
|
+
)
|
|
773
|
+
throw new InputError(
|
|
774
|
+
`limit must be an integer from 1 to ${MAX_LISTED_INVITATIONS}`
|
|
775
|
+
);
|
|
776
|
+
const limit = (raw as number | undefined) ?? DEFAULT_LISTED_INVITATIONS;
|
|
777
|
+
const account = savedAccount(ctx);
|
|
778
|
+
const browser = requireBrowser(ctx);
|
|
779
|
+
const output = await inScratchTab(browser, SENT_INVITATIONS_URL, (tabId) =>
|
|
780
|
+
evaluate<Record<string, unknown>>(browser, tabId, {
|
|
781
|
+
op: "list",
|
|
782
|
+
limit,
|
|
783
|
+
account,
|
|
784
|
+
})
|
|
785
|
+
);
|
|
786
|
+
return { success: true, output };
|
|
787
|
+
});
|
|
788
|
+
}
|