Skip to content

Commit

Permalink
Merge pull request #1493 from estuary/luis/source-hubspot-native
Browse files Browse the repository at this point in the history
Modified OAuth2 and Access Token specs in estuary_cdk & source-hubspot-native fixes
  • Loading branch information
jonwihl authored Apr 16, 2024
2 parents 6ec5752 + 2230064 commit eff39f9
Show file tree
Hide file tree
Showing 24 changed files with 1,186 additions and 176 deletions.
32 changes: 25 additions & 7 deletions estuary-cdk/estuary_cdk/flow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import abc
from dataclasses import dataclass
from pydantic import BaseModel, NonNegativeInt, PositiveInt
from pydantic import BaseModel, NonNegativeInt, PositiveInt, Field
from typing import Any, Literal, TypeVar, Generic, Literal

from .pydantic_polyfill import GenericModel
Expand Down Expand Up @@ -90,8 +90,14 @@ class ConnectorStateUpdate(GenericModel, Generic[ConnectorState]):


class AccessToken(BaseModel):
credentials_title: Literal["Private App Credentials"] = "Private App Credentials"
access_token: str
credentials_title: Literal["Private App Credentials"] = Field(
default="Private App Credentials",
json_schema_extra={"type": "string"}
)
access_token: str = Field(
title="Access Token",
json_schema_extra={"secret": True},
)


class BasicAuth(BaseModel):
Expand All @@ -110,10 +116,22 @@ class ValidationError(Exception):


class BaseOAuth2Credentials(abc.ABC, BaseModel):
credentials_title: Literal["OAuth Credentials"] = "OAuth Credentials"
client_id: str
client_secret: str
refresh_token: str
credentials_title: Literal["OAuth Credentials"] = Field(
default="OAuth Credentials",
json_schema_extra={"type": "string"}
)
client_id: str = Field(
title="Client Id",
json_schema_extra={"secret": True},
)
client_secret: str = Field(
title="Client Secret",
json_schema_extra={"secret": True},
)
refresh_token: str = Field(
title="Refresh Token",
json_schema_extra={"secret": True},
)

@abc.abstractmethod
def _you_must_build_oauth2_credentials_for_a_provider(self): ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"credentials_title": {
"const": "Private App Credentials",
"default": "Private App Credentials",
"title": "Credentials Title"
"title": "Credentials Title",
"type": "string"
},
"access_token": {
"secret": true,
"title": "Access Token",
"type": "string"
}
Expand All @@ -26,17 +28,21 @@
"credentials_title": {
"const": "OAuth Credentials",
"default": "OAuth Credentials",
"title": "Credentials Title"
"title": "Credentials Title",
"type": "string"
},
"client_id": {
"secret": true,
"title": "Client Id",
"type": "string"
},
"client_secret": {
"secret": true,
"title": "Client Secret",
"type": "string"
},
"refresh_token": {
"secret": true,
"title": "Refresh Token",
"type": "string"
}
Expand Down
2 changes: 1 addition & 1 deletion source-hubspot-native/acmeCo/companies.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
$defs:
History:
additionalProperties: false
additionalProperties: true
properties:
_meta:
allOf:
Expand Down
2 changes: 1 addition & 1 deletion source-hubspot-native/acmeCo/contacts.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
$defs:
History:
additionalProperties: false
additionalProperties: true
properties:
_meta:
allOf:
Expand Down
2 changes: 1 addition & 1 deletion source-hubspot-native/acmeCo/deals.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
$defs:
History:
additionalProperties: false
additionalProperties: true
properties:
_meta:
allOf:
Expand Down
2 changes: 1 addition & 1 deletion source-hubspot-native/acmeCo/engagements.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
$defs:
History:
additionalProperties: false
additionalProperties: true
properties:
_meta:
allOf:
Expand Down
2 changes: 1 addition & 1 deletion source-hubspot-native/acmeCo/engagements_calls.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
$defs:
History:
additionalProperties: false
additionalProperties: true
properties:
_meta:
allOf:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
$defs:
History:
additionalProperties: false
additionalProperties: true
properties:
_meta:
allOf:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
$defs:
History:
additionalProperties: false
additionalProperties: true
properties:
_meta:
allOf:
Expand Down
2 changes: 1 addition & 1 deletion source-hubspot-native/acmeCo/engagements_notes.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
$defs:
History:
additionalProperties: false
additionalProperties: true
properties:
_meta:
allOf:
Expand Down
2 changes: 1 addition & 1 deletion source-hubspot-native/acmeCo/engagements_tasks.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
$defs:
History:
additionalProperties: false
additionalProperties: true
properties:
_meta:
allOf:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
$defs:
History:
additionalProperties: false
additionalProperties: true
properties:
_meta:
allOf:
Expand Down
2 changes: 1 addition & 1 deletion source-hubspot-native/acmeCo/goal_targets.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
$defs:
History:
additionalProperties: false
additionalProperties: true
properties:
_meta:
allOf:
Expand Down
2 changes: 1 addition & 1 deletion source-hubspot-native/acmeCo/line_items.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
$defs:
History:
additionalProperties: false
additionalProperties: true
properties:
_meta:
allOf:
Expand Down
2 changes: 1 addition & 1 deletion source-hubspot-native/acmeCo/products.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
$defs:
History:
additionalProperties: false
additionalProperties: true
properties:
_meta:
allOf:
Expand Down
2 changes: 1 addition & 1 deletion source-hubspot-native/acmeCo/ticket_pipelines.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
$defs:
History:
additionalProperties: false
additionalProperties: true
properties:
_meta:
allOf:
Expand Down
2 changes: 1 addition & 1 deletion source-hubspot-native/acmeCo/tickets.schema.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
$defs:
History:
additionalProperties: false
additionalProperties: true
properties:
_meta:
allOf:
Expand Down
2 changes: 1 addition & 1 deletion source-hubspot-native/source_hubspot_native/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def request_class(self):

async def spec(self, log: Logger, _: request.Spec) -> ConnectorSpec:
return ConnectorSpec(
documentationUrl="https://go.estuary.dev/source-hubspot-native",
documentationUrl="https://go.estuary.dev/hubspot-real-time",
configSchema=EndpointConfig.model_json_schema(),
oauth2=OAUTH2_SPEC,
resourceConfigSchema=ResourceConfig.model_json_schema(),
Expand Down
26 changes: 22 additions & 4 deletions source-hubspot-native/source_hubspot_native/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ async def fetch_changes(

recent.sort() # Oldest updates first.

for batch_it in itertools.batched(recent, 100):
for batch_it in itertools.batched(recent, 50):
batch = list(batch_it)

documents: BatchResult[CRMObject] = await fetch_batch_with_associations(
Expand Down Expand Up @@ -397,7 +397,9 @@ async def fetch_changes_no_batch(

for ts, id, result in iter:
recent.append((ts, id)) # Used later to update log_cursor value
yield V1CRMObject.model_validate_json(json.dumps(result))
doc = V1CRMObject.model_validate_json(json.dumps(result))
doc.meta_= V1CRMObject.Meta(op="u")
yield doc


if not next_page:
Expand Down Expand Up @@ -447,11 +449,18 @@ async def fetch_recent_deals(
) -> tuple[Iterable[tuple[datetime, str]], PageCursor]:

url = f"{HUB}/deals/v1/deal/recent/modified"
params = {"count": 100, "offset": page} if page else {"count": 1}
params = {"count": 100, "offset": page, "since": int(since.timestamp())} if page else {"count": 100}

result = OldRecentDeals.model_validate_json(
await http.request(log, url, params=params)
)
if page:
if page == 9800:
return (
(_ms_to_dt(r.properties.hs_lastmodifieddate.timestamp), str(r.dealId))
for r in result.results
), None

return (
(_ms_to_dt(r.properties.hs_lastmodifieddate.timestamp), str(r.dealId))
for r in result.results
Expand All @@ -463,11 +472,18 @@ async def fetch_recent_engagements(
) -> tuple[Iterable[tuple[datetime, str]], PageCursor]:

url = f"{HUB}/engagements/v1/engagements/recent/modified"
params = {"count": 100, "offset": page} if page else {"count": 1}
params = {"count": 100, "offset": page, "since": int(since.timestamp())} if page else {"count": 100}

result = OldRecentEngagements.model_validate_json(
await http.request(log, url, params=params)
)
if page:
if page == 9800:
return(
(_ms_to_dt(r.engagement.lastUpdated), str(r.engagement.id))
for r in result.results
), None

return (
(_ms_to_dt(r.engagement.lastUpdated), str(r.engagement.id))
for r in result.results
Expand Down Expand Up @@ -660,6 +676,8 @@ async def fetch_campaigns(
result = V1CRMObject.model_validate_json(
data
)
for item in result.campaigns:
item["id"] = str(item["id"])

if result.hasMore is False:
return (
Expand Down
5 changes: 3 additions & 2 deletions source-hubspot-native/source_hubspot_native/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ class EndpointConfig(BaseModel):
credentials: OAuth2Credentials | AccessToken = Field(
discriminator="credentials_title",
title="Authentication",
json_schema_extra={"type": "object"}
)
start_date: AwareDatetime = Field(
title="start_date",
title="Start Date",
)


Expand Down Expand Up @@ -172,7 +173,7 @@ class BaseCRMObject(BaseDocument, extra="forbid"):
IGNORE_PROPERTY_SEARCH: ClassVar[bool] = False
ENFORCE_URL: ClassVar[str]

class History(BaseDocument, extra="forbid"):
class History(BaseDocument, extra="allow"):
timestamp: datetime
value: str
sourceType: str
Expand Down
Loading

0 comments on commit eff39f9

Please sign in to comment.