linkedapi 1.4.2__tar.gz → 1.4.4__tar.gz
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.
- {linkedapi-1.4.2 → linkedapi-1.4.4}/PKG-INFO +1 -1
- linkedapi-1.4.4/examples/verify_webhook_signature.py +19 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/__init__.py +12 -2
- linkedapi-1.4.4/linkedapi/admin/webhooks.py +162 -0
- linkedapi-1.4.4/linkedapi/changelog.py +45 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/__init__.py +20 -0
- linkedapi-1.4.4/linkedapi/types/changelog.py +20 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/post.py +9 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/search_posts.py +14 -4
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/webhooks.py +79 -1
- linkedapi-1.4.4/linkedapi/webhooks/__init__.py +13 -0
- linkedapi-1.4.4/linkedapi/webhooks/headers.py +2 -0
- linkedapi-1.4.4/linkedapi/webhooks/signature.py +75 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/pyproject.toml +1 -1
- linkedapi-1.4.4/tests/test_admin_webhooks.py +241 -0
- linkedapi-1.4.4/tests/test_changelog.py +120 -0
- linkedapi-1.4.4/tests/test_webhook_signature.py +224 -0
- linkedapi-1.4.2/linkedapi/admin/webhooks.py +0 -82
- linkedapi-1.4.2/linkedapi/webhooks/__init__.py +0 -3
- {linkedapi-1.4.2 → linkedapi-1.4.4}/.github/workflows/publish.yaml +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/.gitignore +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/LICENSE +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/README.md +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/admin/__init__.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/admin/accounts.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/admin/admin.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/admin/http_client.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/admin/limits.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/admin/subscription.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/client.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/config.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/core/__init__.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/core/operation.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/core/polling.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/errors.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/http/__init__.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/http/base.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/http/linked_api_http_client.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/mappers/__init__.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/mappers/array.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/mappers/base.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/mappers/send_message.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/mappers/simple.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/mappers/then.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/mappers/void.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/__init__.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/accept_invitation.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/check_connection_status.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/comment_on_post.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/create_post.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/create_repost.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/custom_workflow.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/fetch_company.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/fetch_job.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/fetch_person.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/fetch_post.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/ignore_invitation.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/manage_conversation.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/nv_fetch_company.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/nv_fetch_person.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/nv_manage_conversation.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/nv_search_companies.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/nv_search_people.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/nv_send_message.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/nv_sync_conversation.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/nv_sync_inbox.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/react_to_comment.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/react_to_post.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/remove_connection.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/reply_to_comment.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/retrieve_connections.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/retrieve_feed.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/retrieve_invitations.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/retrieve_pending_requests.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/retrieve_performance.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/retrieve_profile_viewers.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/retrieve_ssi.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/search_companies.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/search_jobs.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/search_people.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/search_posts.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/send_connection_request.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/send_message.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/sync_conversation.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/sync_inbox.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/sync_network.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/operations/withdraw_connection_request.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/py.typed +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/account.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/admin/__init__.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/admin/accounts.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/admin/config.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/admin/limits.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/admin/subscription.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/base.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/company.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/connection.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/feed.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/jobs.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/message.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/network.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/params.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/person.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/profile_viewers.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/responses.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/search_companies.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/search_people.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/statistics.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/viewer_state.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/types/workflow.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/linkedapi/webhooks/parse.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/tests/conftest.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/tests/test_admin.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/tests/test_direct_methods.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/tests/test_errors.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/tests/test_http_client.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/tests/test_mappers.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/tests/test_models.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/tests/test_operations.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/tests/test_polling.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/tests/test_webhooks.py +0 -0
- {linkedapi-1.4.2 → linkedapi-1.4.4}/tests/test_working_hours_contract.py +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
|
|
5
|
+
from linkedapi import (
|
|
6
|
+
WEBHOOK_SIGNATURE_HEADER,
|
|
7
|
+
WEBHOOK_SIGNATURE_TIMESTAMP_HEADER,
|
|
8
|
+
verify_webhook_signature,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def verify_request(raw_body: bytes, headers: Mapping[str, str], *, secret: str | None) -> bool:
|
|
13
|
+
"""Pass Flask's request.get_data() or Django's request.body and request.headers."""
|
|
14
|
+
return verify_webhook_signature(
|
|
15
|
+
raw_body=raw_body,
|
|
16
|
+
timestamp=headers.get(WEBHOOK_SIGNATURE_TIMESTAMP_HEADER),
|
|
17
|
+
signature=headers.get(WEBHOOK_SIGNATURE_HEADER),
|
|
18
|
+
secret=secret,
|
|
19
|
+
)
|
|
@@ -6,6 +6,7 @@ from linkedapi.admin import (
|
|
|
6
6
|
AdminWebhooks,
|
|
7
7
|
LinkedApiAdmin,
|
|
8
8
|
)
|
|
9
|
+
from linkedapi.changelog import get_changelog
|
|
9
10
|
from linkedapi.client import LinkedApi
|
|
10
11
|
from linkedapi.config import LinkedApiConfig
|
|
11
12
|
from linkedapi.core import Operation, poll_workflow_result
|
|
@@ -79,9 +80,14 @@ from linkedapi.operations import (
|
|
|
79
80
|
)
|
|
80
81
|
from linkedapi.types import * # noqa: F403
|
|
81
82
|
from linkedapi.types import __all__ as _types_all
|
|
82
|
-
from linkedapi.webhooks import
|
|
83
|
+
from linkedapi.webhooks import (
|
|
84
|
+
WEBHOOK_SIGNATURE_HEADER,
|
|
85
|
+
WEBHOOK_SIGNATURE_TIMESTAMP_HEADER,
|
|
86
|
+
parse_webhook_event,
|
|
87
|
+
verify_webhook_signature,
|
|
88
|
+
)
|
|
83
89
|
|
|
84
|
-
__version__ = "1.4.
|
|
90
|
+
__version__ = "1.4.4"
|
|
85
91
|
PredefinedOperation = Operation
|
|
86
92
|
|
|
87
93
|
__all__ = [
|
|
@@ -158,8 +164,12 @@ __all__ = [
|
|
|
158
164
|
"SyncNetwork",
|
|
159
165
|
"ThenWorkflowMapper",
|
|
160
166
|
"VoidWorkflowMapper",
|
|
167
|
+
"WEBHOOK_SIGNATURE_HEADER",
|
|
168
|
+
"WEBHOOK_SIGNATURE_TIMESTAMP_HEADER",
|
|
161
169
|
"WithdrawConnectionRequest",
|
|
162
170
|
"__version__",
|
|
171
|
+
"get_changelog",
|
|
163
172
|
"parse_webhook_event",
|
|
164
173
|
"poll_workflow_result",
|
|
174
|
+
"verify_webhook_signature",
|
|
165
175
|
]
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from linkedapi.errors import LinkedApiError
|
|
6
|
+
from linkedapi.http import HttpClient
|
|
7
|
+
from linkedapi.types.webhooks import (
|
|
8
|
+
DeleteWebhookHeaderParams,
|
|
9
|
+
DeleteWebhookParams,
|
|
10
|
+
ReplayWebhookDeliveryParams,
|
|
11
|
+
RevealWebhookSecretParams,
|
|
12
|
+
RotateWebhookSecretParams,
|
|
13
|
+
SetWebhookEventsParams,
|
|
14
|
+
SetWebhookHeaderParams,
|
|
15
|
+
SetWebhookHeadersParams,
|
|
16
|
+
SetWebhookParams,
|
|
17
|
+
SetWebhookPayloadModeParams,
|
|
18
|
+
SetWebhookSigningParams,
|
|
19
|
+
WebhookDelivery,
|
|
20
|
+
WebhookSubscription,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class AdminWebhooks:
|
|
25
|
+
"""Manage the client's registered outbound webhook and inspect recent deliveries.
|
|
26
|
+
|
|
27
|
+
A client may hold at most one active webhook. Its event selectors control which workflow,
|
|
28
|
+
account, inbox and network events it receives; None selects all events. Test events are
|
|
29
|
+
always delivered. Signing and custom headers are configured per subscription.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def __init__(self, http_client: HttpClient[Any]) -> None:
|
|
33
|
+
self.http_client = http_client
|
|
34
|
+
|
|
35
|
+
def set(self, params: SetWebhookParams) -> WebhookSubscription:
|
|
36
|
+
result = self._post_result("/admin/webhook.set", "Failed to set webhook", params)
|
|
37
|
+
return WebhookSubscription.model_validate(result["webhook"])
|
|
38
|
+
|
|
39
|
+
def get(self) -> list[WebhookSubscription]:
|
|
40
|
+
result = self._post_result("/admin/webhook.get", "Failed to get webhooks")
|
|
41
|
+
return [WebhookSubscription.model_validate(item) for item in result["webhooks"]]
|
|
42
|
+
|
|
43
|
+
def set_payload_mode(self, params: SetWebhookPayloadModeParams) -> WebhookSubscription:
|
|
44
|
+
result = self._post_result(
|
|
45
|
+
"/admin/webhook.setPayloadMode",
|
|
46
|
+
"Failed to set webhook payload mode",
|
|
47
|
+
params,
|
|
48
|
+
)
|
|
49
|
+
return WebhookSubscription.model_validate(result["webhook"])
|
|
50
|
+
|
|
51
|
+
def set_signing(self, params: SetWebhookSigningParams) -> WebhookSubscription:
|
|
52
|
+
"""Enable or disable signing. Enabling returns the stored secret."""
|
|
53
|
+
result = self._post_result(
|
|
54
|
+
"/admin/webhook.setSigning",
|
|
55
|
+
"Failed to set webhook signing",
|
|
56
|
+
params,
|
|
57
|
+
)
|
|
58
|
+
return WebhookSubscription.model_validate(result["webhook"])
|
|
59
|
+
|
|
60
|
+
def set_headers(self, params: SetWebhookHeadersParams) -> WebhookSubscription:
|
|
61
|
+
"""Replace all custom headers. None or an empty dict clears them."""
|
|
62
|
+
result = self._post_result(
|
|
63
|
+
"/admin/webhook.setHeaders",
|
|
64
|
+
"Failed to set webhook headers",
|
|
65
|
+
params,
|
|
66
|
+
)
|
|
67
|
+
return WebhookSubscription.model_validate(result["webhook"])
|
|
68
|
+
|
|
69
|
+
def set_header(self, params: SetWebhookHeaderParams) -> WebhookSubscription:
|
|
70
|
+
"""Set one custom header; its name is matched case-insensitively."""
|
|
71
|
+
result = self._post_result(
|
|
72
|
+
"/admin/webhook.setHeader",
|
|
73
|
+
"Failed to set webhook header",
|
|
74
|
+
params,
|
|
75
|
+
)
|
|
76
|
+
return WebhookSubscription.model_validate(result["webhook"])
|
|
77
|
+
|
|
78
|
+
def delete_header(self, params: DeleteWebhookHeaderParams) -> WebhookSubscription:
|
|
79
|
+
"""Remove one custom header; its name is matched case-insensitively."""
|
|
80
|
+
result = self._post_result(
|
|
81
|
+
"/admin/webhook.deleteHeader",
|
|
82
|
+
"Failed to delete webhook header",
|
|
83
|
+
params,
|
|
84
|
+
)
|
|
85
|
+
return WebhookSubscription.model_validate(result["webhook"])
|
|
86
|
+
|
|
87
|
+
def reveal_secret(self, params: RevealWebhookSecretParams) -> WebhookSubscription:
|
|
88
|
+
"""Return the current signing secret without changing it."""
|
|
89
|
+
result = self._post_result(
|
|
90
|
+
"/admin/webhook.revealSecret",
|
|
91
|
+
"Failed to reveal webhook secret",
|
|
92
|
+
params,
|
|
93
|
+
)
|
|
94
|
+
return WebhookSubscription.model_validate(result["webhook"])
|
|
95
|
+
|
|
96
|
+
def rotate_secret(self, params: RotateWebhookSecretParams) -> WebhookSubscription:
|
|
97
|
+
"""Replace the signing secret and return its new value."""
|
|
98
|
+
result = self._post_result(
|
|
99
|
+
"/admin/webhook.rotateSecret",
|
|
100
|
+
"Failed to rotate webhook secret",
|
|
101
|
+
params,
|
|
102
|
+
)
|
|
103
|
+
return WebhookSubscription.model_validate(result["webhook"])
|
|
104
|
+
|
|
105
|
+
def set_events(self, params: SetWebhookEventsParams) -> WebhookSubscription:
|
|
106
|
+
"""Select event types or namespace wildcards; None selects all. Tests always deliver."""
|
|
107
|
+
result = self._post_result(
|
|
108
|
+
"/admin/webhook.setEvents",
|
|
109
|
+
"Failed to set webhook events",
|
|
110
|
+
params,
|
|
111
|
+
)
|
|
112
|
+
return WebhookSubscription.model_validate(result["webhook"])
|
|
113
|
+
|
|
114
|
+
def event_types(self) -> list[str]:
|
|
115
|
+
"""Return selectable event types in the server's order.
|
|
116
|
+
|
|
117
|
+
The catalog excludes webhook.test, which is always delivered.
|
|
118
|
+
"""
|
|
119
|
+
result = self._post_result("/admin/webhook.eventTypes", "Failed to get webhook event types")
|
|
120
|
+
event_types: list[str] = result["eventTypes"]
|
|
121
|
+
return event_types
|
|
122
|
+
|
|
123
|
+
def delete(self, params: DeleteWebhookParams) -> None:
|
|
124
|
+
self._post_void("/admin/webhook.delete", "Failed to delete webhook", params)
|
|
125
|
+
|
|
126
|
+
def deliveries(self) -> list[WebhookDelivery]:
|
|
127
|
+
result = self._post_result("/admin/webhook.deliveries", "Failed to get webhook deliveries")
|
|
128
|
+
return [WebhookDelivery.model_validate(item) for item in result["deliveries"]]
|
|
129
|
+
|
|
130
|
+
def replay_delivery(self, params: ReplayWebhookDeliveryParams) -> None:
|
|
131
|
+
self._post_void(
|
|
132
|
+
"/admin/webhook.replayDelivery",
|
|
133
|
+
"Failed to replay webhook delivery",
|
|
134
|
+
params,
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
def send_test(self) -> None:
|
|
138
|
+
self._post_void("/admin/webhook.sendTest", "Failed to send test webhook")
|
|
139
|
+
|
|
140
|
+
def _post_result(
|
|
141
|
+
self,
|
|
142
|
+
path: str,
|
|
143
|
+
default_message: str,
|
|
144
|
+
params: Any | None = None,
|
|
145
|
+
) -> dict[str, Any]:
|
|
146
|
+
response = self.http_client.post(path, params)
|
|
147
|
+
if response.success and response.result is not None:
|
|
148
|
+
result: dict[str, Any] = response.result
|
|
149
|
+
return result
|
|
150
|
+
raise LinkedApiError(
|
|
151
|
+
response.error.type if response.error else "httpError",
|
|
152
|
+
response.error.message if response.error else default_message,
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
def _post_void(self, path: str, default_message: str, params: Any | None = None) -> None:
|
|
156
|
+
response = self.http_client.post(path, params)
|
|
157
|
+
if response.success:
|
|
158
|
+
return
|
|
159
|
+
raise LinkedApiError(
|
|
160
|
+
response.error.type if response.error else "httpError",
|
|
161
|
+
response.error.message if response.error else default_message,
|
|
162
|
+
)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import date, datetime
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
|
|
7
|
+
from linkedapi.errors import LinkedApiError
|
|
8
|
+
from linkedapi.types.changelog import ChangelogResponse
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_changelog(
|
|
12
|
+
since: str | date | datetime | None = None,
|
|
13
|
+
*,
|
|
14
|
+
url: str = "https://linkedapi.io/api/changelog",
|
|
15
|
+
) -> ChangelogResponse:
|
|
16
|
+
"""Read the public Linked API changelog.
|
|
17
|
+
|
|
18
|
+
A release counts as shipped at the end of its week, so callers deduplicate by date.
|
|
19
|
+
|
|
20
|
+
Raises:
|
|
21
|
+
LinkedApiError: on a non-2xx response or network failure.
|
|
22
|
+
"""
|
|
23
|
+
since_value = since.isoformat() if isinstance(since, date) else since
|
|
24
|
+
try:
|
|
25
|
+
response = requests.get(
|
|
26
|
+
url, params={"since": since_value} if since_value is not None else None
|
|
27
|
+
)
|
|
28
|
+
except requests.RequestException as error:
|
|
29
|
+
raise LinkedApiError("httpError", f"Request error: {error}", {"error": error}) from error
|
|
30
|
+
|
|
31
|
+
if not 200 <= response.status_code < 300:
|
|
32
|
+
try:
|
|
33
|
+
error_data = response.json()
|
|
34
|
+
except ValueError:
|
|
35
|
+
error_data = None
|
|
36
|
+
message = f"HTTP {response.status_code}: {response.reason}"
|
|
37
|
+
if isinstance(error_data, dict) and isinstance(error_data.get("error"), str):
|
|
38
|
+
message = error_data["error"]
|
|
39
|
+
raise LinkedApiError(
|
|
40
|
+
"httpError",
|
|
41
|
+
message,
|
|
42
|
+
{"status": response.status_code, "statusText": response.reason, "url": response.url},
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
return ChangelogResponse.model_validate(response.json())
|
|
@@ -47,6 +47,7 @@ from linkedapi.types.base import (
|
|
|
47
47
|
serialize_model,
|
|
48
48
|
serialize_value,
|
|
49
49
|
)
|
|
50
|
+
from linkedapi.types.changelog import ChangelogItem, ChangelogRelease, ChangelogResponse
|
|
50
51
|
from linkedapi.types.company import (
|
|
51
52
|
BaseFetchCompanyParams,
|
|
52
53
|
BaseFetchCompanyParamsWide,
|
|
@@ -242,17 +243,25 @@ from linkedapi.types.webhooks import (
|
|
|
242
243
|
AccountWebhookEvent,
|
|
243
244
|
AccountWebhookEventData,
|
|
244
245
|
AccountWebhookStatus,
|
|
246
|
+
DeleteWebhookHeaderParams,
|
|
245
247
|
DeleteWebhookParams,
|
|
246
248
|
MessageWebhookEvent,
|
|
247
249
|
MessageWebhookEventData,
|
|
248
250
|
NetworkWebhookEvent,
|
|
249
251
|
NetworkWebhookEventData,
|
|
250
252
|
ReplayWebhookDeliveryParams,
|
|
253
|
+
RevealWebhookSecretParams,
|
|
254
|
+
RotateWebhookSecretParams,
|
|
255
|
+
SetWebhookEventsParams,
|
|
256
|
+
SetWebhookHeaderParams,
|
|
257
|
+
SetWebhookHeadersParams,
|
|
251
258
|
SetWebhookParams,
|
|
252
259
|
SetWebhookPayloadModeParams,
|
|
260
|
+
SetWebhookSigningParams,
|
|
253
261
|
WebhookDelivery,
|
|
254
262
|
WebhookDeliveryStatus,
|
|
255
263
|
WebhookEvent,
|
|
264
|
+
WebhookEventSelector,
|
|
256
265
|
WebhookEventType,
|
|
257
266
|
WebhookPayloadMode,
|
|
258
267
|
WebhookSubscription,
|
|
@@ -300,6 +309,9 @@ __all__ = [
|
|
|
300
309
|
"BaseFetchPostParamsWide",
|
|
301
310
|
"BillingPeriod",
|
|
302
311
|
"CancelConnectionSessionParams",
|
|
312
|
+
"ChangelogItem",
|
|
313
|
+
"ChangelogRelease",
|
|
314
|
+
"ChangelogResponse",
|
|
303
315
|
"CheckConnectionStatusParams",
|
|
304
316
|
"CheckConnectionStatusResult",
|
|
305
317
|
"Comment",
|
|
@@ -327,6 +339,7 @@ __all__ = [
|
|
|
327
339
|
"CreateRepostResult",
|
|
328
340
|
"DeleteLimitEntry",
|
|
329
341
|
"DeleteLimitsParams",
|
|
342
|
+
"DeleteWebhookHeaderParams",
|
|
330
343
|
"DeleteWebhookParams",
|
|
331
344
|
"DisconnectParams",
|
|
332
345
|
"EmploymentType",
|
|
@@ -456,6 +469,8 @@ __all__ = [
|
|
|
456
469
|
"RetrievePerformanceResult",
|
|
457
470
|
"RetrieveProfileViewersParams",
|
|
458
471
|
"RetrieveSSIResult",
|
|
472
|
+
"RevealWebhookSecretParams",
|
|
473
|
+
"RotateWebhookSecretParams",
|
|
459
474
|
"SalaryPeriod",
|
|
460
475
|
"SearchCompaniesFilter",
|
|
461
476
|
"SearchCompaniesParams",
|
|
@@ -485,8 +500,12 @@ __all__ = [
|
|
|
485
500
|
"SetSeatsParams",
|
|
486
501
|
"SetSeatsResult",
|
|
487
502
|
"SetSeatsStatus",
|
|
503
|
+
"SetWebhookEventsParams",
|
|
504
|
+
"SetWebhookHeaderParams",
|
|
505
|
+
"SetWebhookHeadersParams",
|
|
488
506
|
"SetWebhookParams",
|
|
489
507
|
"SetWebhookPayloadModeParams",
|
|
508
|
+
"SetWebhookSigningParams",
|
|
490
509
|
"StCompanyDm",
|
|
491
510
|
"StCompanyEmployee",
|
|
492
511
|
"StCompanyEmployeesFilter",
|
|
@@ -502,6 +521,7 @@ __all__ = [
|
|
|
502
521
|
"WebhookDelivery",
|
|
503
522
|
"WebhookDeliveryStatus",
|
|
504
523
|
"WebhookEvent",
|
|
524
|
+
"WebhookEventSelector",
|
|
505
525
|
"WebhookEventType",
|
|
506
526
|
"WebhookPayloadMode",
|
|
507
527
|
"WebhookSubscription",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from linkedapi.types.base import LinkedApiModel
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ChangelogItem(LinkedApiModel):
|
|
7
|
+
title: str
|
|
8
|
+
body: str
|
|
9
|
+
docs: str
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ChangelogRelease(LinkedApiModel):
|
|
13
|
+
date: str
|
|
14
|
+
items: list[ChangelogItem]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ChangelogResponse(LinkedApiModel):
|
|
18
|
+
since: str | None
|
|
19
|
+
count: int
|
|
20
|
+
entries: list[ChangelogRelease]
|
|
@@ -112,6 +112,15 @@ class PostComment(LinkedApiModel):
|
|
|
112
112
|
|
|
113
113
|
|
|
114
114
|
class PostReaction(LinkedApiModel):
|
|
115
|
+
"""One reaction on a post.
|
|
116
|
+
|
|
117
|
+
"actor" is whoever reacted, in the same shape a post's author has.
|
|
118
|
+
|
|
119
|
+
Deprecated: the engager_* fields are still returned; use "actor" instead.
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
actor: PostAuthor | None = None
|
|
123
|
+
# Deprecated: use "actor" instead of the five engager_* fields.
|
|
115
124
|
engager_urn: str | None = None
|
|
116
125
|
engager_url: str | None = None
|
|
117
126
|
engager_name: str | None = None
|
|
@@ -16,20 +16,30 @@ PostSearchPostedBy = Literal["me", "firstConnections", "peopleYouFollow"]
|
|
|
16
16
|
class SearchPostsPersonFilter(LinkedApiModel):
|
|
17
17
|
"""One person to narrow a post search by.
|
|
18
18
|
|
|
19
|
-
"name"
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
With "name" alone the filter may match a namesake. "id" is any identifier of the person - its
|
|
20
|
+
URN, or its public or hashed LinkedIn URL - and pins the filter to exactly that person; when it
|
|
21
|
+
cannot be applied, the action fails with "filterNotApplied" rather than filtering by somebody
|
|
22
|
+
else.
|
|
23
|
+
|
|
24
|
+
Deprecated: "urn" and "person_hashed_url" are still accepted; use "id" instead.
|
|
22
25
|
"""
|
|
23
26
|
|
|
24
27
|
name: str
|
|
28
|
+
id: str | None = None
|
|
25
29
|
urn: str | None = None
|
|
26
30
|
person_hashed_url: str | None = None
|
|
27
31
|
|
|
28
32
|
|
|
29
33
|
class SearchPostsCompanyFilter(LinkedApiModel):
|
|
30
|
-
"""One company to narrow a post search by. Same contract as SearchPostsPersonFilter.
|
|
34
|
+
"""One company to narrow a post search by. Same contract as SearchPostsPersonFilter.
|
|
35
|
+
|
|
36
|
+
"id" is the company's URN, its public or hashed LinkedIn URL, or its numeric ID.
|
|
37
|
+
|
|
38
|
+
Deprecated: "urn" and "company_hashed_url" are still accepted; use "id" instead.
|
|
39
|
+
"""
|
|
31
40
|
|
|
32
41
|
name: str
|
|
42
|
+
id: str | None = None
|
|
33
43
|
urn: str | None = None
|
|
34
44
|
company_hashed_url: str | None = None
|
|
35
45
|
|
|
@@ -2,6 +2,8 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from typing import Any, Literal
|
|
4
4
|
|
|
5
|
+
from pydantic import SerializerFunctionWrapHandler, model_serializer
|
|
6
|
+
|
|
5
7
|
from linkedapi.types.base import LinkedApiModel
|
|
6
8
|
from linkedapi.types.message import ConversationType, MessageSender
|
|
7
9
|
|
|
@@ -21,6 +23,24 @@ WebhookEventType = Literal[
|
|
|
21
23
|
"network.connectionRequestReceived",
|
|
22
24
|
"webhook.test",
|
|
23
25
|
]
|
|
26
|
+
WebhookEventSelector = Literal[
|
|
27
|
+
"workflow.created",
|
|
28
|
+
"workflow.started",
|
|
29
|
+
"workflow.completed",
|
|
30
|
+
"account.active",
|
|
31
|
+
"account.reconnectionRequired",
|
|
32
|
+
"account.frozen",
|
|
33
|
+
"account.deleted",
|
|
34
|
+
"inbox.messageReceived",
|
|
35
|
+
"inbox.messageSent",
|
|
36
|
+
"network.connectionAccepted",
|
|
37
|
+
"network.connectionAdded",
|
|
38
|
+
"network.connectionRequestReceived",
|
|
39
|
+
"workflow.*",
|
|
40
|
+
"account.*",
|
|
41
|
+
"inbox.*",
|
|
42
|
+
"network.*",
|
|
43
|
+
]
|
|
24
44
|
WebhookDeliveryStatus = Literal["pending", "delivering", "success", "failed"]
|
|
25
45
|
WorkflowWebhookStatus = Literal["pending", "running", "completed", "failed"]
|
|
26
46
|
AccountWebhookStatus = Literal["active", "reconnection_required", "frozen", "deleted"]
|
|
@@ -31,12 +51,17 @@ class WebhookSubscription(LinkedApiModel):
|
|
|
31
51
|
url: str | None = None
|
|
32
52
|
payload_mode: WebhookPayloadMode | None = None
|
|
33
53
|
is_active: bool | None = None
|
|
54
|
+
signing_enabled: bool | None = None
|
|
55
|
+
header_names: list[str] | None = None
|
|
56
|
+
events: list[str] | None = None
|
|
57
|
+
# Returned only by set with signing on, set_signing(True), reveal_secret or rotate_secret.
|
|
58
|
+
secret: str | None = None
|
|
34
59
|
created_at: str | None = None
|
|
35
60
|
|
|
36
61
|
|
|
37
62
|
class WebhookDelivery(LinkedApiModel):
|
|
38
63
|
id: str | None = None
|
|
39
|
-
event_type:
|
|
64
|
+
event_type: str | None = None
|
|
40
65
|
event_id: str | None = None
|
|
41
66
|
status: WebhookDeliveryStatus | None = None
|
|
42
67
|
attempts: int | None = None
|
|
@@ -49,6 +74,9 @@ class WebhookDelivery(LinkedApiModel):
|
|
|
49
74
|
class SetWebhookParams(LinkedApiModel):
|
|
50
75
|
url: str
|
|
51
76
|
payload_mode: WebhookPayloadMode | None = None
|
|
77
|
+
signing_enabled: bool | None = None
|
|
78
|
+
headers: dict[str, str] | None = None
|
|
79
|
+
events: list[WebhookEventSelector] | None = None
|
|
52
80
|
|
|
53
81
|
|
|
54
82
|
class SetWebhookPayloadModeParams(LinkedApiModel):
|
|
@@ -56,6 +84,56 @@ class SetWebhookPayloadModeParams(LinkedApiModel):
|
|
|
56
84
|
payload_mode: WebhookPayloadMode
|
|
57
85
|
|
|
58
86
|
|
|
87
|
+
class SetWebhookSigningParams(LinkedApiModel):
|
|
88
|
+
id: str
|
|
89
|
+
signing_enabled: bool
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class SetWebhookHeadersParams(LinkedApiModel):
|
|
93
|
+
id: str
|
|
94
|
+
headers: dict[str, str] | None
|
|
95
|
+
|
|
96
|
+
@model_serializer(mode="wrap")
|
|
97
|
+
def _serialize(self, handler: SerializerFunctionWrapHandler) -> dict[str, Any]:
|
|
98
|
+
result: dict[str, Any] = handler(self)
|
|
99
|
+
# Core requires explicit null to clear headers, even when requests exclude None.
|
|
100
|
+
if self.headers is None:
|
|
101
|
+
result["headers"] = None
|
|
102
|
+
return result
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class SetWebhookHeaderParams(LinkedApiModel):
|
|
106
|
+
id: str
|
|
107
|
+
name: str
|
|
108
|
+
value: str
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class DeleteWebhookHeaderParams(LinkedApiModel):
|
|
112
|
+
id: str
|
|
113
|
+
name: str
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class RevealWebhookSecretParams(LinkedApiModel):
|
|
117
|
+
id: str
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class RotateWebhookSecretParams(LinkedApiModel):
|
|
121
|
+
id: str
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class SetWebhookEventsParams(LinkedApiModel):
|
|
125
|
+
id: str
|
|
126
|
+
events: list[WebhookEventSelector] | None
|
|
127
|
+
|
|
128
|
+
@model_serializer(mode="wrap")
|
|
129
|
+
def _serialize(self, handler: SerializerFunctionWrapHandler) -> dict[str, Any]:
|
|
130
|
+
result: dict[str, Any] = handler(self)
|
|
131
|
+
# Core requires explicit null to select all events, even when requests exclude None.
|
|
132
|
+
if self.events is None:
|
|
133
|
+
result["events"] = None
|
|
134
|
+
return result
|
|
135
|
+
|
|
136
|
+
|
|
59
137
|
class DeleteWebhookParams(LinkedApiModel):
|
|
60
138
|
id: str
|
|
61
139
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from linkedapi.webhooks.headers import (
|
|
2
|
+
WEBHOOK_SIGNATURE_HEADER,
|
|
3
|
+
WEBHOOK_SIGNATURE_TIMESTAMP_HEADER,
|
|
4
|
+
)
|
|
5
|
+
from linkedapi.webhooks.parse import parse_webhook_event
|
|
6
|
+
from linkedapi.webhooks.signature import verify_webhook_signature
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"WEBHOOK_SIGNATURE_HEADER",
|
|
10
|
+
"WEBHOOK_SIGNATURE_TIMESTAMP_HEADER",
|
|
11
|
+
"parse_webhook_event",
|
|
12
|
+
"verify_webhook_signature",
|
|
13
|
+
]
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import hmac
|
|
5
|
+
import math
|
|
6
|
+
import re
|
|
7
|
+
import time
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def verify_webhook_signature(
|
|
11
|
+
*,
|
|
12
|
+
raw_body: str | bytes | bytearray | memoryview,
|
|
13
|
+
timestamp: str | int | list[str] | None,
|
|
14
|
+
signature: str | list[str] | None,
|
|
15
|
+
secret: str | None,
|
|
16
|
+
now_seconds: float | None = None,
|
|
17
|
+
tolerance_seconds: float = 300,
|
|
18
|
+
) -> bool:
|
|
19
|
+
"""Verify a signed webhook before parsing its raw request body.
|
|
20
|
+
|
|
21
|
+
Use the secret as literal UTF-8 text, never hex-decode it. Timestamps are integer Unix
|
|
22
|
+
seconds. The default tolerance is 300 seconds in either direction and must be finite
|
|
23
|
+
and non-negative. Inject now_seconds to check a stored delivery at a chosen time.
|
|
24
|
+
Malformed inputs return False.
|
|
25
|
+
|
|
26
|
+
Example:
|
|
27
|
+
verify_webhook_signature(
|
|
28
|
+
raw_body=request.body,
|
|
29
|
+
timestamp=request.headers.get(WEBHOOK_SIGNATURE_TIMESTAMP_HEADER),
|
|
30
|
+
signature=request.headers.get(WEBHOOK_SIGNATURE_HEADER),
|
|
31
|
+
secret=secret,
|
|
32
|
+
)
|
|
33
|
+
"""
|
|
34
|
+
try:
|
|
35
|
+
if (
|
|
36
|
+
not isinstance(signature, str)
|
|
37
|
+
or re.fullmatch(r"[0-9a-f]{64}", signature) is None
|
|
38
|
+
or not isinstance(secret, str)
|
|
39
|
+
or not secret
|
|
40
|
+
or not isinstance(raw_body, (str, bytes, bytearray, memoryview))
|
|
41
|
+
):
|
|
42
|
+
return False
|
|
43
|
+
|
|
44
|
+
if isinstance(timestamp, bool):
|
|
45
|
+
return False
|
|
46
|
+
if isinstance(timestamp, str):
|
|
47
|
+
if re.fullmatch(r"[0-9]+", timestamp) is None:
|
|
48
|
+
return False
|
|
49
|
+
sent_at = int(timestamp)
|
|
50
|
+
elif isinstance(timestamp, int):
|
|
51
|
+
sent_at = timestamp
|
|
52
|
+
else:
|
|
53
|
+
return False
|
|
54
|
+
|
|
55
|
+
if now_seconds is None:
|
|
56
|
+
now_seconds = int(time.time())
|
|
57
|
+
if (
|
|
58
|
+
isinstance(now_seconds, bool)
|
|
59
|
+
or not isinstance(now_seconds, (int, float))
|
|
60
|
+
or not math.isfinite(now_seconds)
|
|
61
|
+
or isinstance(tolerance_seconds, bool)
|
|
62
|
+
or not isinstance(tolerance_seconds, (int, float))
|
|
63
|
+
or not math.isfinite(tolerance_seconds)
|
|
64
|
+
or tolerance_seconds < 0
|
|
65
|
+
or abs(now_seconds - sent_at) > tolerance_seconds
|
|
66
|
+
):
|
|
67
|
+
return False
|
|
68
|
+
|
|
69
|
+
body_bytes = raw_body.encode("utf-8") if isinstance(raw_body, str) else bytes(raw_body)
|
|
70
|
+
expected = hmac.new(secret.encode("utf-8"), digestmod=hashlib.sha256)
|
|
71
|
+
expected.update(f"{timestamp}.".encode())
|
|
72
|
+
expected.update(body_bytes)
|
|
73
|
+
return hmac.compare_digest(expected.hexdigest(), signature)
|
|
74
|
+
except Exception:
|
|
75
|
+
return False
|