render-lab-tasks-hubspot 0.1.0__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.
- render_lab_tasks_hubspot-0.1.0/.gitignore +11 -0
- render_lab_tasks_hubspot-0.1.0/LICENSE +21 -0
- render_lab_tasks_hubspot-0.1.0/PKG-INFO +71 -0
- render_lab_tasks_hubspot-0.1.0/README.md +58 -0
- render_lab_tasks_hubspot-0.1.0/pyproject.toml +22 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/__init__.py +1 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/_app.py +3 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/add_to_list.py +18 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/client.py +225 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/create_company.py +18 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/create_deal.py +18 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/create_task.py +18 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/get_contact.py +18 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/log_activity.py +18 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/move_deal_stage.py +18 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/py.typed +0 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/retry.py +3 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/search_contacts.py +18 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/tasks.py +35 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/types.py +128 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/update_deal.py +18 -0
- render_lab_tasks_hubspot-0.1.0/src/render_lab_tasks_hubspot/upsert_contact.py +18 -0
- render_lab_tasks_hubspot-0.1.0/tests/test_contracts.py +8 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Render Lab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: render-lab-tasks-hubspot
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: hubspot tasks for Render Workflows
|
|
5
|
+
Project-URL: Repository, https://github.com/render-lab/render-tasks-python
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Requires-Dist: httpx<0.29,>=0.28
|
|
10
|
+
Requires-Dist: render-lab-tasks-core<0.2,>=0.1.0
|
|
11
|
+
Requires-Dist: render==1.0.1
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# render-lab-tasks-hubspot
|
|
15
|
+
|
|
16
|
+
Python port of all 10 registered tasks in the pinned TypeScript pack at
|
|
17
|
+
`45f9c2d44bd28e01ae9813e0d2ff56ee6c533816`. Python 3.12+.
|
|
18
|
+
|
|
19
|
+
From the repository, install this pack and its supporting core together:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
pip install render-lab-tasks-hubspot==0.1.0
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Import task definitions from `render_lab_tasks_hubspot.tasks`. Combine its `app` with
|
|
26
|
+
other pack apps using `Workflows.from_workflows(...)` and call tasks with
|
|
27
|
+
`await ctx.run(task, input)`. Package roots do not register tasks. JSON fields
|
|
28
|
+
retain the TS spelling; Python functions use snake_case.
|
|
29
|
+
|
|
30
|
+
## Tasks
|
|
31
|
+
|
|
32
|
+
| Registered name | Python export (also exposes `_impl`) |
|
|
33
|
+
| --- | --- |
|
|
34
|
+
| `hubspot.addToList` | `add_to_list` |
|
|
35
|
+
| `hubspot.createCompany` | `create_company` |
|
|
36
|
+
| `hubspot.createDeal` | `create_deal` |
|
|
37
|
+
| `hubspot.createTask` | `create_task` |
|
|
38
|
+
| `hubspot.getContact` | `get_contact` |
|
|
39
|
+
| `hubspot.logActivity` | `log_activity` |
|
|
40
|
+
| `hubspot.moveDealStage` | `move_deal_stage` |
|
|
41
|
+
| `hubspot.searchContacts` | `search_contacts` |
|
|
42
|
+
| `hubspot.updateDeal` | `update_deal` |
|
|
43
|
+
| `hubspot.upsertContact` | `upsert_contact` |
|
|
44
|
+
|
|
45
|
+
## Dependencies and retries
|
|
46
|
+
|
|
47
|
+
Raw implementations accept context first and keyword-only `deps`. The `.client`
|
|
48
|
+
module exports typed `Port`, `Deps`, and `Client` classes (also vendor-named aliases).
|
|
49
|
+
Inject a fake port, or pass a caller-owned `httpx.AsyncClient` to `Client` for custom
|
|
50
|
+
transport/configuration. Default dependencies close their HTTP clients after the
|
|
51
|
+
operation. Credentials resolve at first use. HTTP and SDK retries are disabled;
|
|
52
|
+
`retry.py` owns durable retry settings. DTO types live in `.types`.
|
|
53
|
+
|
|
54
|
+
## Environment
|
|
55
|
+
|
|
56
|
+
| Variable | Contract |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| `HUBSPOT_ACCESS_TOKEN` | Required on API calls. |
|
|
59
|
+
|
|
60
|
+
## Verification and limitations
|
|
61
|
+
|
|
62
|
+
The HTTP adapter uses CRM v3 and the lists v3 membership API rather than a vendor SDK. Upsert searches email before create/update and is not atomic. Note/task timestamps default to current UTC. List/search operations preserve the TS single-page limit behavior.
|
|
63
|
+
|
|
64
|
+
Shared JSON fixtures compare the Python task output with the actual pinned TS
|
|
65
|
+
implementation. REST fixtures also compare HTTP requests; HubSpot and Linear
|
|
66
|
+
fixtures compare source SDK arguments with HTTP payloads/GraphQL variables.
|
|
67
|
+
No live vendor calls were made for this batch. Registered-task parity does not
|
|
68
|
+
claim live readiness or all supporting TS exports. See the root verification
|
|
69
|
+
tracker and docs/porting-batches.md. Licensed under MIT.
|
|
70
|
+
|
|
71
|
+
[Lists v3 reference](https://developers.hubspot.com/docs/api-reference/legacy/crm/lists/guide).
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# render-lab-tasks-hubspot
|
|
2
|
+
|
|
3
|
+
Python port of all 10 registered tasks in the pinned TypeScript pack at
|
|
4
|
+
`45f9c2d44bd28e01ae9813e0d2ff56ee6c533816`. Python 3.12+.
|
|
5
|
+
|
|
6
|
+
From the repository, install this pack and its supporting core together:
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pip install render-lab-tasks-hubspot==0.1.0
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Import task definitions from `render_lab_tasks_hubspot.tasks`. Combine its `app` with
|
|
13
|
+
other pack apps using `Workflows.from_workflows(...)` and call tasks with
|
|
14
|
+
`await ctx.run(task, input)`. Package roots do not register tasks. JSON fields
|
|
15
|
+
retain the TS spelling; Python functions use snake_case.
|
|
16
|
+
|
|
17
|
+
## Tasks
|
|
18
|
+
|
|
19
|
+
| Registered name | Python export (also exposes `_impl`) |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| `hubspot.addToList` | `add_to_list` |
|
|
22
|
+
| `hubspot.createCompany` | `create_company` |
|
|
23
|
+
| `hubspot.createDeal` | `create_deal` |
|
|
24
|
+
| `hubspot.createTask` | `create_task` |
|
|
25
|
+
| `hubspot.getContact` | `get_contact` |
|
|
26
|
+
| `hubspot.logActivity` | `log_activity` |
|
|
27
|
+
| `hubspot.moveDealStage` | `move_deal_stage` |
|
|
28
|
+
| `hubspot.searchContacts` | `search_contacts` |
|
|
29
|
+
| `hubspot.updateDeal` | `update_deal` |
|
|
30
|
+
| `hubspot.upsertContact` | `upsert_contact` |
|
|
31
|
+
|
|
32
|
+
## Dependencies and retries
|
|
33
|
+
|
|
34
|
+
Raw implementations accept context first and keyword-only `deps`. The `.client`
|
|
35
|
+
module exports typed `Port`, `Deps`, and `Client` classes (also vendor-named aliases).
|
|
36
|
+
Inject a fake port, or pass a caller-owned `httpx.AsyncClient` to `Client` for custom
|
|
37
|
+
transport/configuration. Default dependencies close their HTTP clients after the
|
|
38
|
+
operation. Credentials resolve at first use. HTTP and SDK retries are disabled;
|
|
39
|
+
`retry.py` owns durable retry settings. DTO types live in `.types`.
|
|
40
|
+
|
|
41
|
+
## Environment
|
|
42
|
+
|
|
43
|
+
| Variable | Contract |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| `HUBSPOT_ACCESS_TOKEN` | Required on API calls. |
|
|
46
|
+
|
|
47
|
+
## Verification and limitations
|
|
48
|
+
|
|
49
|
+
The HTTP adapter uses CRM v3 and the lists v3 membership API rather than a vendor SDK. Upsert searches email before create/update and is not atomic. Note/task timestamps default to current UTC. List/search operations preserve the TS single-page limit behavior.
|
|
50
|
+
|
|
51
|
+
Shared JSON fixtures compare the Python task output with the actual pinned TS
|
|
52
|
+
implementation. REST fixtures also compare HTTP requests; HubSpot and Linear
|
|
53
|
+
fixtures compare source SDK arguments with HTTP payloads/GraphQL variables.
|
|
54
|
+
No live vendor calls were made for this batch. Registered-task parity does not
|
|
55
|
+
claim live readiness or all supporting TS exports. See the root verification
|
|
56
|
+
tracker and docs/porting-batches.md. Licensed under MIT.
|
|
57
|
+
|
|
58
|
+
[Lists v3 reference](https://developers.hubspot.com/docs/api-reference/legacy/crm/lists/guide).
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27,<2"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "render-lab-tasks-hubspot"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "hubspot tasks for Render Workflows"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.12"
|
|
13
|
+
dependencies = ["render==1.0.1", "httpx>=0.28,<0.29", "render-lab-tasks-core>=0.1.0,<0.2"]
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Repository = "https://github.com/render-lab/render-tasks-python"
|
|
17
|
+
|
|
18
|
+
[tool.uv.sources]
|
|
19
|
+
render-lab-tasks-core = { workspace = true }
|
|
20
|
+
|
|
21
|
+
[tool.hatch.build.targets.wheel]
|
|
22
|
+
packages = ["src/render_lab_tasks_hubspot"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Import .tasks explicitly to register durable tasks."""
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import HUBSPOT_RETRY
|
|
6
|
+
from .types import AddToListInput, AddToListResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def add_to_list_impl(
|
|
10
|
+
ctx: TaskContext, input: AddToListInput, *, deps: Deps | None = None
|
|
11
|
+
) -> AddToListResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.hubspot.add_to_list(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="hubspot.addToList", retry=HUBSPOT_RETRY)
|
|
17
|
+
async def add_to_list(ctx: TaskContext, input: AddToListInput) -> AddToListResult:
|
|
18
|
+
return await add_to_list_impl(ctx, input)
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"""Injected vendor interface and one-attempt async HTTP adapter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from collections.abc import AsyncIterator, Mapping
|
|
7
|
+
from contextlib import asynccontextmanager
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from datetime import UTC, datetime
|
|
10
|
+
from typing import Any, Protocol
|
|
11
|
+
|
|
12
|
+
import httpx
|
|
13
|
+
from render_lab_tasks_core.http import HttpClient, enc, nullish, pick, query, required
|
|
14
|
+
|
|
15
|
+
from . import types as t
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def now_iso() -> str:
|
|
19
|
+
return datetime.now(UTC).isoformat(timespec="milliseconds").replace("+00:00", "Z")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def number_string(value: Any) -> str:
|
|
23
|
+
if isinstance(value, float) and value.is_integer():
|
|
24
|
+
return str(int(value))
|
|
25
|
+
return "null" if value is None else str(value)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def association(id: str | None, type_id: int) -> list[dict[str, Any]]:
|
|
29
|
+
return (
|
|
30
|
+
[
|
|
31
|
+
{
|
|
32
|
+
"to": {"id": id},
|
|
33
|
+
"types": [{"associationCategory": "HUBSPOT_DEFINED", "associationTypeId": type_id}],
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
if id
|
|
37
|
+
else []
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def to_crm(raw: Any) -> dict[str, Any]:
|
|
42
|
+
result = {"id": str(raw["id"]), "properties": nullish(raw.get("properties"), {})}
|
|
43
|
+
for key in ("createdAt", "updatedAt"):
|
|
44
|
+
if isinstance(raw.get(key), str):
|
|
45
|
+
result[key] = raw[key]
|
|
46
|
+
return result
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class Port(Protocol):
|
|
50
|
+
async def add_to_list(self, input: t.AddToListInput) -> t.AddToListResult: ...
|
|
51
|
+
async def create_company(self, input: t.CreateCompanyInput) -> t.CreateCompanyResult: ...
|
|
52
|
+
async def create_deal(self, input: t.CreateDealInput) -> t.CreateDealResult: ...
|
|
53
|
+
async def create_task(self, input: t.CreateTaskInput) -> t.CreateTaskResult: ...
|
|
54
|
+
async def get_contact(self, input: t.GetContactInput) -> t.GetContactResult: ...
|
|
55
|
+
async def log_activity(self, input: t.LogActivityInput) -> t.LogActivityResult: ...
|
|
56
|
+
async def move_deal_stage(self, input: t.MoveDealStageInput) -> t.MoveDealStageResult: ...
|
|
57
|
+
async def search_contacts(self, input: t.SearchContactsInput) -> t.SearchContactsResult: ...
|
|
58
|
+
async def update_deal(self, input: t.UpdateDealInput) -> t.UpdateDealResult: ...
|
|
59
|
+
async def upsert_contact(self, input: t.UpsertContactInput) -> t.UpsertContactResult: ...
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclass(frozen=True)
|
|
63
|
+
class Deps:
|
|
64
|
+
hubspot: Port
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class Client:
|
|
68
|
+
def __init__(self, http: httpx.AsyncClient, env: Mapping[str, str] | None = None) -> None:
|
|
69
|
+
self.env = os.environ if env is None else env
|
|
70
|
+
self.http = HttpClient(
|
|
71
|
+
http,
|
|
72
|
+
"https://api.hubapi.com",
|
|
73
|
+
auth=lambda: {"authorization": "Bearer " + required(self.env, "HUBSPOT_ACCESS_TOKEN")},
|
|
74
|
+
label="HubSpot API",
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
async def upsert_contact(self, input: t.UpsertContactInput) -> Any:
|
|
78
|
+
search = await self.http.call(
|
|
79
|
+
"/crm/v3/objects/contacts/search",
|
|
80
|
+
method="POST",
|
|
81
|
+
body={
|
|
82
|
+
"filterGroups": [
|
|
83
|
+
{
|
|
84
|
+
"filters": [
|
|
85
|
+
{"propertyName": "email", "operator": "EQ", "value": input["email"]}
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"properties": ["email"],
|
|
90
|
+
"limit": 1,
|
|
91
|
+
},
|
|
92
|
+
)
|
|
93
|
+
rows = search.get("results") or []
|
|
94
|
+
found = rows[0] if rows else None
|
|
95
|
+
props = {"email": input["email"], **nullish(input.get("properties"), {})}
|
|
96
|
+
if found is not None:
|
|
97
|
+
data = await self.http.call(
|
|
98
|
+
f"/crm/v3/objects/contacts/{enc(found['id'])}",
|
|
99
|
+
method="PATCH",
|
|
100
|
+
body={"properties": props},
|
|
101
|
+
)
|
|
102
|
+
else:
|
|
103
|
+
data = await self.http.call(
|
|
104
|
+
"/crm/v3/objects/contacts",
|
|
105
|
+
method="POST",
|
|
106
|
+
body={"properties": props, "associations": []},
|
|
107
|
+
)
|
|
108
|
+
return {"contactId": data["id"], "created": found is None}
|
|
109
|
+
|
|
110
|
+
async def log_activity(self, input: t.LogActivityInput) -> Any:
|
|
111
|
+
data = await self.http.call(
|
|
112
|
+
"/crm/v3/objects/notes",
|
|
113
|
+
method="POST",
|
|
114
|
+
body={
|
|
115
|
+
"properties": {"hs_note_body": input["note"], "hs_timestamp": now_iso()},
|
|
116
|
+
"associations": association(input["contactId"], 202),
|
|
117
|
+
},
|
|
118
|
+
)
|
|
119
|
+
return {"contactId": input["contactId"], "engagementId": data["id"]}
|
|
120
|
+
|
|
121
|
+
async def create_deal(self, input: t.CreateDealInput) -> Any:
|
|
122
|
+
props = {"dealname": input["name"]}
|
|
123
|
+
if "amount" in input:
|
|
124
|
+
props["amount"] = number_string(input["amount"])
|
|
125
|
+
if "stage" in input:
|
|
126
|
+
props["dealstage"] = input["stage"]
|
|
127
|
+
data = await self.http.call(
|
|
128
|
+
"/crm/v3/objects/deals",
|
|
129
|
+
method="POST",
|
|
130
|
+
body={"properties": props, "associations": association(input.get("contactId"), 3)},
|
|
131
|
+
)
|
|
132
|
+
return {"dealId": data["id"]}
|
|
133
|
+
|
|
134
|
+
async def get_contact(self, input: t.GetContactInput) -> Any:
|
|
135
|
+
params = (
|
|
136
|
+
"?" + query({"properties": ",".join(input["properties"])})
|
|
137
|
+
if input.get("properties") is not None
|
|
138
|
+
else ""
|
|
139
|
+
)
|
|
140
|
+
return to_crm(
|
|
141
|
+
await self.http.call(f"/crm/v3/objects/contacts/{enc(input['contactId'])}" + params)
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
async def search_contacts(self, input: t.SearchContactsInput) -> Any:
|
|
145
|
+
body = {
|
|
146
|
+
"limit": nullish(input.get("limit"), 10),
|
|
147
|
+
**pick(input, "query", "filterGroups", "properties"),
|
|
148
|
+
}
|
|
149
|
+
data = await self.http.call("/crm/v3/objects/contacts/search", method="POST", body=body)
|
|
150
|
+
return {"contacts": [to_crm(r) for r in nullish(data.get("results"), [])]}
|
|
151
|
+
|
|
152
|
+
async def update_deal(self, input: t.UpdateDealInput) -> Any:
|
|
153
|
+
return to_crm(
|
|
154
|
+
await self.http.call(
|
|
155
|
+
f"/crm/v3/objects/deals/{enc(input['dealId'])}",
|
|
156
|
+
method="PATCH",
|
|
157
|
+
body={"properties": input["properties"]},
|
|
158
|
+
)
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
async def move_deal_stage(self, input: t.MoveDealStageInput) -> Any:
|
|
162
|
+
return await self.update_deal(
|
|
163
|
+
{"dealId": input["dealId"], "properties": {"dealstage": input["stage"]}}
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
async def create_company(self, input: t.CreateCompanyInput) -> Any:
|
|
167
|
+
props = {
|
|
168
|
+
**nullish(input.get("properties"), {}),
|
|
169
|
+
"name": input["name"],
|
|
170
|
+
**pick(input, "domain"),
|
|
171
|
+
}
|
|
172
|
+
data = await self.http.call(
|
|
173
|
+
"/crm/v3/objects/companies",
|
|
174
|
+
method="POST",
|
|
175
|
+
body={"properties": props, "associations": []},
|
|
176
|
+
)
|
|
177
|
+
result = {"companyId": str(data["id"])}
|
|
178
|
+
for k in ("name", "domain"):
|
|
179
|
+
if k in (data.get("properties") or {}) or k in props:
|
|
180
|
+
result[k] = nullish((data.get("properties") or {}).get(k), props.get(k))
|
|
181
|
+
return result
|
|
182
|
+
|
|
183
|
+
async def create_task(self, input: t.CreateTaskInput) -> Any:
|
|
184
|
+
props = {
|
|
185
|
+
"hs_task_subject": input["subject"],
|
|
186
|
+
"hs_timestamp": nullish(input.get("timestamp"), now_iso()),
|
|
187
|
+
}
|
|
188
|
+
if "body" in input:
|
|
189
|
+
props["hs_task_body"] = input["body"]
|
|
190
|
+
data = await self.http.call(
|
|
191
|
+
"/crm/v3/objects/tasks",
|
|
192
|
+
method="POST",
|
|
193
|
+
body={"properties": props, "associations": association(input.get("contactId"), 204)},
|
|
194
|
+
)
|
|
195
|
+
return {"taskId": str(data["id"])}
|
|
196
|
+
|
|
197
|
+
async def add_to_list(self, input: t.AddToListInput) -> Any:
|
|
198
|
+
data = await self.http.call(
|
|
199
|
+
f"/crm/v3/lists/{enc(input['listId'])}/memberships/add",
|
|
200
|
+
method="PUT",
|
|
201
|
+
body=[input["contactId"]],
|
|
202
|
+
)
|
|
203
|
+
ids = (data or {}).get("recordsIdsAdded")
|
|
204
|
+
return {
|
|
205
|
+
"listId": input["listId"],
|
|
206
|
+
"added": str(input["contactId"]) in [str(id) for id in ids]
|
|
207
|
+
if isinstance(ids, list)
|
|
208
|
+
else False,
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
@asynccontextmanager
|
|
213
|
+
async def dependencies(deps: Deps | None) -> AsyncIterator[Deps]:
|
|
214
|
+
if deps is not None:
|
|
215
|
+
yield deps
|
|
216
|
+
else:
|
|
217
|
+
async with httpx.AsyncClient(
|
|
218
|
+
timeout=30, transport=httpx.AsyncHTTPTransport(retries=0)
|
|
219
|
+
) as http:
|
|
220
|
+
yield Deps(hubspot=Client(http))
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
HubspotPort = Port
|
|
224
|
+
HubspotClient = Client
|
|
225
|
+
HubspotDeps = Deps
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import HUBSPOT_RETRY
|
|
6
|
+
from .types import CreateCompanyInput, CreateCompanyResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def create_company_impl(
|
|
10
|
+
ctx: TaskContext, input: CreateCompanyInput, *, deps: Deps | None = None
|
|
11
|
+
) -> CreateCompanyResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.hubspot.create_company(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="hubspot.createCompany", retry=HUBSPOT_RETRY)
|
|
17
|
+
async def create_company(ctx: TaskContext, input: CreateCompanyInput) -> CreateCompanyResult:
|
|
18
|
+
return await create_company_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import HUBSPOT_RETRY
|
|
6
|
+
from .types import CreateDealInput, CreateDealResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def create_deal_impl(
|
|
10
|
+
ctx: TaskContext, input: CreateDealInput, *, deps: Deps | None = None
|
|
11
|
+
) -> CreateDealResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.hubspot.create_deal(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="hubspot.createDeal", retry=HUBSPOT_RETRY)
|
|
17
|
+
async def create_deal(ctx: TaskContext, input: CreateDealInput) -> CreateDealResult:
|
|
18
|
+
return await create_deal_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import HUBSPOT_RETRY
|
|
6
|
+
from .types import CreateTaskInput, CreateTaskResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def create_task_impl(
|
|
10
|
+
ctx: TaskContext, input: CreateTaskInput, *, deps: Deps | None = None
|
|
11
|
+
) -> CreateTaskResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.hubspot.create_task(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="hubspot.createTask", retry=HUBSPOT_RETRY)
|
|
17
|
+
async def create_task(ctx: TaskContext, input: CreateTaskInput) -> CreateTaskResult:
|
|
18
|
+
return await create_task_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import HUBSPOT_RETRY
|
|
6
|
+
from .types import GetContactInput, GetContactResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def get_contact_impl(
|
|
10
|
+
ctx: TaskContext, input: GetContactInput, *, deps: Deps | None = None
|
|
11
|
+
) -> GetContactResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.hubspot.get_contact(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="hubspot.getContact", retry=HUBSPOT_RETRY)
|
|
17
|
+
async def get_contact(ctx: TaskContext, input: GetContactInput) -> GetContactResult:
|
|
18
|
+
return await get_contact_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import HUBSPOT_RETRY
|
|
6
|
+
from .types import LogActivityInput, LogActivityResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def log_activity_impl(
|
|
10
|
+
ctx: TaskContext, input: LogActivityInput, *, deps: Deps | None = None
|
|
11
|
+
) -> LogActivityResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.hubspot.log_activity(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="hubspot.logActivity", retry=HUBSPOT_RETRY)
|
|
17
|
+
async def log_activity(ctx: TaskContext, input: LogActivityInput) -> LogActivityResult:
|
|
18
|
+
return await log_activity_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import HUBSPOT_RETRY
|
|
6
|
+
from .types import MoveDealStageInput, MoveDealStageResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def move_deal_stage_impl(
|
|
10
|
+
ctx: TaskContext, input: MoveDealStageInput, *, deps: Deps | None = None
|
|
11
|
+
) -> MoveDealStageResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.hubspot.move_deal_stage(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="hubspot.moveDealStage", retry=HUBSPOT_RETRY)
|
|
17
|
+
async def move_deal_stage(ctx: TaskContext, input: MoveDealStageInput) -> MoveDealStageResult:
|
|
18
|
+
return await move_deal_stage_impl(ctx, input)
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import HUBSPOT_RETRY
|
|
6
|
+
from .types import SearchContactsInput, SearchContactsResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def search_contacts_impl(
|
|
10
|
+
ctx: TaskContext, input: SearchContactsInput, *, deps: Deps | None = None
|
|
11
|
+
) -> SearchContactsResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.hubspot.search_contacts(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="hubspot.searchContacts", retry=HUBSPOT_RETRY)
|
|
17
|
+
async def search_contacts(ctx: TaskContext, input: SearchContactsInput) -> SearchContactsResult:
|
|
18
|
+
return await search_contacts_impl(ctx, input)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from ._app import app
|
|
2
|
+
from .add_to_list import add_to_list, add_to_list_impl
|
|
3
|
+
from .create_company import create_company, create_company_impl
|
|
4
|
+
from .create_deal import create_deal, create_deal_impl
|
|
5
|
+
from .create_task import create_task, create_task_impl
|
|
6
|
+
from .get_contact import get_contact, get_contact_impl
|
|
7
|
+
from .log_activity import log_activity, log_activity_impl
|
|
8
|
+
from .move_deal_stage import move_deal_stage, move_deal_stage_impl
|
|
9
|
+
from .search_contacts import search_contacts, search_contacts_impl
|
|
10
|
+
from .update_deal import update_deal, update_deal_impl
|
|
11
|
+
from .upsert_contact import upsert_contact, upsert_contact_impl
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"app",
|
|
15
|
+
"add_to_list",
|
|
16
|
+
"add_to_list_impl",
|
|
17
|
+
"create_company",
|
|
18
|
+
"create_company_impl",
|
|
19
|
+
"create_deal",
|
|
20
|
+
"create_deal_impl",
|
|
21
|
+
"create_task",
|
|
22
|
+
"create_task_impl",
|
|
23
|
+
"get_contact",
|
|
24
|
+
"get_contact_impl",
|
|
25
|
+
"log_activity",
|
|
26
|
+
"log_activity_impl",
|
|
27
|
+
"move_deal_stage",
|
|
28
|
+
"move_deal_stage_impl",
|
|
29
|
+
"search_contacts",
|
|
30
|
+
"search_contacts_impl",
|
|
31
|
+
"update_deal",
|
|
32
|
+
"update_deal_impl",
|
|
33
|
+
"upsert_contact",
|
|
34
|
+
"upsert_contact_impl",
|
|
35
|
+
]
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""JSON contracts ported from the pinned TypeScript pack."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import NotRequired, TypedDict
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class UpsertContactInput(TypedDict):
|
|
9
|
+
email: str
|
|
10
|
+
properties: NotRequired[dict[str, str]]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class UpsertContactResult(TypedDict):
|
|
14
|
+
contactId: str
|
|
15
|
+
created: bool
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class LogActivityInput(TypedDict):
|
|
19
|
+
contactId: str
|
|
20
|
+
note: str
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class LogActivityResult(TypedDict):
|
|
24
|
+
contactId: str
|
|
25
|
+
engagementId: str
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class CreateDealInput(TypedDict):
|
|
29
|
+
name: str
|
|
30
|
+
amount: NotRequired[float]
|
|
31
|
+
stage: NotRequired[str]
|
|
32
|
+
contactId: NotRequired[str]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class CreateDealResult(TypedDict):
|
|
36
|
+
dealId: str
|
|
37
|
+
url: NotRequired[str]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class CrmObjectDTO(TypedDict):
|
|
41
|
+
id: str
|
|
42
|
+
properties: dict[str, str | None]
|
|
43
|
+
createdAt: NotRequired[str]
|
|
44
|
+
updatedAt: NotRequired[str]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
type ContactDTO = CrmObjectDTO
|
|
48
|
+
|
|
49
|
+
type DealDTO = CrmObjectDTO
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class GetContactInput(TypedDict):
|
|
53
|
+
contactId: str
|
|
54
|
+
properties: NotRequired[list[str]]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
type GetContactResult = ContactDTO
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class SearchFilter(TypedDict):
|
|
61
|
+
propertyName: str
|
|
62
|
+
operator: str
|
|
63
|
+
value: NotRequired[str]
|
|
64
|
+
values: NotRequired[list[str]]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class SearchFilterGroup(TypedDict):
|
|
68
|
+
filters: list[SearchFilter]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class SearchContactsInput(TypedDict):
|
|
72
|
+
query: NotRequired[str]
|
|
73
|
+
filterGroups: NotRequired[list[SearchFilterGroup]]
|
|
74
|
+
properties: NotRequired[list[str]]
|
|
75
|
+
limit: NotRequired[float]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class SearchContactsResult(TypedDict):
|
|
79
|
+
contacts: list[ContactDTO]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class UpdateDealInput(TypedDict):
|
|
83
|
+
dealId: str
|
|
84
|
+
properties: dict[str, str]
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
type UpdateDealResult = DealDTO
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class MoveDealStageInput(TypedDict):
|
|
91
|
+
dealId: str
|
|
92
|
+
stage: str
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
type MoveDealStageResult = DealDTO
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class CreateCompanyInput(TypedDict):
|
|
99
|
+
name: str
|
|
100
|
+
domain: NotRequired[str]
|
|
101
|
+
properties: NotRequired[dict[str, str]]
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class CreateCompanyResult(TypedDict):
|
|
105
|
+
companyId: str
|
|
106
|
+
name: NotRequired[str]
|
|
107
|
+
domain: NotRequired[str]
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class CreateTaskInput(TypedDict):
|
|
111
|
+
subject: str
|
|
112
|
+
body: NotRequired[str]
|
|
113
|
+
timestamp: NotRequired[str]
|
|
114
|
+
contactId: NotRequired[str]
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class CreateTaskResult(TypedDict):
|
|
118
|
+
taskId: str
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class AddToListInput(TypedDict):
|
|
122
|
+
listId: str
|
|
123
|
+
contactId: str
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class AddToListResult(TypedDict):
|
|
127
|
+
listId: str
|
|
128
|
+
added: bool
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import HUBSPOT_RETRY
|
|
6
|
+
from .types import UpdateDealInput, UpdateDealResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def update_deal_impl(
|
|
10
|
+
ctx: TaskContext, input: UpdateDealInput, *, deps: Deps | None = None
|
|
11
|
+
) -> UpdateDealResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.hubspot.update_deal(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="hubspot.updateDeal", retry=HUBSPOT_RETRY)
|
|
17
|
+
async def update_deal(ctx: TaskContext, input: UpdateDealInput) -> UpdateDealResult:
|
|
18
|
+
return await update_deal_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import HUBSPOT_RETRY
|
|
6
|
+
from .types import UpsertContactInput, UpsertContactResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def upsert_contact_impl(
|
|
10
|
+
ctx: TaskContext, input: UpsertContactInput, *, deps: Deps | None = None
|
|
11
|
+
) -> UpsertContactResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.hubspot.upsert_contact(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="hubspot.upsertContact", retry=HUBSPOT_RETRY)
|
|
17
|
+
async def upsert_contact(ctx: TaskContext, input: UpsertContactInput) -> UpsertContactResult:
|
|
18
|
+
return await upsert_contact_impl(ctx, input)
|