@volter/twin-hubspot 0.1.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/LICENSE +202 -0
- package/README.md +197 -0
- package/client/hubspot-mirror.css +43 -0
- package/client/hubspot-mirror.tsx +132 -0
- package/dist/client/hubspot-mirror.bundle.js +449 -0
- package/dist/client/hubspot-mirror.css +43 -0
- package/dist/client/hubspot-mirror.d.ts +15 -0
- package/dist/client/hubspot-mirror.js +59 -0
- package/dist/client/hubspot-mirror.tsx +132 -0
- package/dist/src/accounts.d.ts +30 -0
- package/dist/src/accounts.js +122 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +31 -0
- package/dist/src/generated/surface.gen.json +1 -0
- package/dist/src/generated/ui.gen.json +1 -0
- package/dist/src/hubspot-areas.d.ts +10 -0
- package/dist/src/hubspot-areas.js +114 -0
- package/dist/src/hubspot-budget.d.ts +58 -0
- package/dist/src/hubspot-budget.js +176 -0
- package/dist/src/hubspot-capabilities.d.ts +3 -0
- package/dist/src/hubspot-capabilities.js +1588 -0
- package/dist/src/hubspot-conformance.d.ts +16 -0
- package/dist/src/hubspot-conformance.js +523 -0
- package/dist/src/hubspot-connector.d.ts +125 -0
- package/dist/src/hubspot-connector.js +390 -0
- package/dist/src/hubspot-deferred-capabilities.d.ts +6 -0
- package/dist/src/hubspot-deferred-capabilities.js +64 -0
- package/dist/src/hubspot-mirror-ui.d.ts +62 -0
- package/dist/src/hubspot-mirror-ui.js +152 -0
- package/dist/src/hubspot-oauth.d.ts +8 -0
- package/dist/src/hubspot-oauth.js +291 -0
- package/dist/src/hubspot-server.d.ts +24 -0
- package/dist/src/hubspot-server.js +116 -0
- package/dist/src/hubspot-twin.d.ts +65 -0
- package/dist/src/hubspot-twin.js +1558 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +94 -0
- package/dist/src/manifest.d.ts +2 -0
- package/dist/src/manifest.js +68 -0
- package/dist/src/portal.d.ts +20 -0
- package/dist/src/portal.js +30 -0
- package/dist/src/screens/account.d.ts +1 -0
- package/dist/src/screens/account.js +139 -0
- package/dist/src/screens/crm.d.ts +2 -0
- package/dist/src/screens/crm.js +153 -0
- package/dist/src/screens/developer.d.ts +4 -0
- package/dist/src/screens/developer.js +191 -0
- package/dist/src/screens/forms.d.ts +5 -0
- package/dist/src/screens/forms.js +126 -0
- package/dist/src/screens/page.d.ts +21 -0
- package/dist/src/screens/page.js +49 -0
- package/dist/src/screens/session.d.ts +1 -0
- package/dist/src/screens/session.js +32 -0
- package/dist/src/semantics/crm.d.ts +8 -0
- package/dist/src/semantics/crm.js +101 -0
- package/dist/src/webhooks.d.ts +12 -0
- package/dist/src/webhooks.js +77 -0
- package/package.json +75 -0
- package/src/accounts.ts +127 -0
- package/src/cli.ts +29 -0
- package/src/generated/surface.gen.json +1 -0
- package/src/generated/ui.gen.json +1 -0
- package/src/hubspot-areas.ts +155 -0
- package/src/hubspot-budget.ts +202 -0
- package/src/hubspot-capabilities.ts +1523 -0
- package/src/hubspot-conformance.ts +537 -0
- package/src/hubspot-connector.ts +419 -0
- package/src/hubspot-deferred-capabilities.ts +99 -0
- package/src/hubspot-journey.uitest.ts +104 -0
- package/src/hubspot-mirror-ui.ts +166 -0
- package/src/hubspot-oauth.tsx +296 -0
- package/src/hubspot-server.ts +115 -0
- package/src/hubspot-twin.ts +1534 -0
- package/src/index.ts +152 -0
- package/src/manifest.ts +96 -0
- package/src/portal.ts +40 -0
- package/src/screens/account.tsx +129 -0
- package/src/screens/crm.tsx +154 -0
- package/src/screens/developer.tsx +181 -0
- package/src/screens/forms.tsx +117 -0
- package/src/screens/page.tsx +55 -0
- package/src/screens/session.tsx +36 -0
- package/src/semantics/crm.ts +116 -0
- package/src/webhooks.ts +80 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# @volter/twin-hubspot
|
|
2
|
+
|
|
3
|
+
The **HubSpot CRM twin** — a local, stateful, vendor-faithful replica of the
|
|
4
|
+
[HubSpot](https://developers.hubspot.com/docs/api/overview) **CRM v3/v4 API**, on the shared
|
|
5
|
+
[`@volter/world-core`](../../world-core) kernel. An **unmodified `@hubspot/api-client`** — pointed here
|
|
6
|
+
with its own public `basePath` option, or routed by the world injector's `api.hubapi.com`
|
|
7
|
+
interception — talks to it and gets vendor-correct responses.
|
|
8
|
+
|
|
9
|
+
State lives in the kernel's append-only action/event log — a write appends an action that projects
|
|
10
|
+
into visible state; reads use the kernel’s tree. **No real HubSpot is ever called** (the only network path
|
|
11
|
+
is the connector, over an injected client). The CRM API accepts a **faked-locally Bearer token**; an app's
|
|
12
|
+
**OAuth install** is served (`src/hubspot-oauth.tsx`: the consent at app.hubspot.com/oauth/authorize, the code and
|
|
13
|
+
refresh exchanges at POST /oauth/v1/token, token metadata at GET /oauth/v1/access-tokens/{token}). There is **NO
|
|
14
|
+
signature verification**.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
bun run src/cli.ts serve # the HubSpot CRM API twin (writable)
|
|
20
|
+
bun run src/cli.ts serve --read-only
|
|
21
|
+
bun run src/cli.ts mirror # the React CRM mirror (records + the deal pipeline board)
|
|
22
|
+
bun run src/cli.ts conformance # offline, failable endpoint probe over the live router
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Collections use HubSpot's envelope — `{ results, paging: { next: { after } } }` — and errors use
|
|
26
|
+
the documented `{ status: "error", message, correlationId, category }` shape (with `errors[]`
|
|
27
|
+
where the vendor carries per-field detail).
|
|
28
|
+
|
|
29
|
+
Two deliberate departures from the live vendor, both required by **serve-path determinism**
|
|
30
|
+
(CLAUDE.md — a served response must be a pure function of `(request, stored state)` and
|
|
31
|
+
byte-identical on replay):
|
|
32
|
+
|
|
33
|
+
- **`correlationId` is DERIVED, not random.** It is a hash of `(method, pathname, status,
|
|
34
|
+
category, message)` rendered in HubSpot's UUID shape. Real HubSpot mints a fresh one per
|
|
35
|
+
request; a twin that did the same could not be replayed.
|
|
36
|
+
- **The rate-limit `-Remaining` COUNTERS are not served.** Every response carries HubSpot's
|
|
37
|
+
documented *policy* headers with the real Professional-tier figures —
|
|
38
|
+
`X-HubSpot-RateLimit-Max: 190`, `X-HubSpot-RateLimit-Interval-Milliseconds: 10000`,
|
|
39
|
+
`X-HubSpot-RateLimit-Daily: 625000` — and deliberately **not**
|
|
40
|
+
`X-HubSpot-RateLimit-Remaining` / `-Daily-Remaining`: a truthful remaining count is a
|
|
41
|
+
wall-clock-metered, account-wide number no local twin observes, and fabricating one would both
|
|
42
|
+
break replayability and tell the caller something untrue. Filed as
|
|
43
|
+
`hubspot.protocol.rate_limit_remaining_headers`.
|
|
44
|
+
|
|
45
|
+
## Coverage
|
|
46
|
+
|
|
47
|
+
The capability manifest (`src/hubspot-capabilities.ts`) is the **real HubSpot surface as the
|
|
48
|
+
denominator** — coverage is honest and partial. Run `bun scripts/manifest-baseline-one.ts hubspot`
|
|
49
|
+
for the live count. As of writing: **done=105 / total=231**, regressions=0.
|
|
50
|
+
|
|
51
|
+
The denominator's source is `@hubspot/api-client` 14.0.1's own generated client — **936 operations
|
|
52
|
+
across eleven top-level API families**, enumerated from every `lib/codegen/**/apis/*Api.js` request
|
|
53
|
+
factory. Those eleven families are censused in `src/hubspot-areas.ts`; the generated request
|
|
54
|
+
factories, response processors and models are also the **oracle** for this twin's paths, status
|
|
55
|
+
codes and response shapes (HubSpot publishes no first-party OpenAPI document this repo can vendor,
|
|
56
|
+
which is why `spec-sources.json` records `kind: "none"` with that as the reason).
|
|
57
|
+
|
|
58
|
+
### Scope: this is the CRM
|
|
59
|
+
|
|
60
|
+
`api.hubapi.com` fronts eleven separate HubSpot products. **This twin models the CRM** — records,
|
|
61
|
+
properties, associations, pipelines, owners and the CRM Search API. Two different things follow
|
|
62
|
+
from that, and they get different treatment (the §9 round-one ruling):
|
|
63
|
+
|
|
64
|
+
- **Surface INSIDE the CRM that is not built yet is a plain `todo`**, however much work it is —
|
|
65
|
+
engagements, commerce, custom-object schemas, lists, imports/exports and CRM extensions all ride
|
|
66
|
+
the same `/crm/` routes this twin already serves, so carving them out would be shrinking the
|
|
67
|
+
denominator rather than describing it (`HUBSPOT_UNMODELED_CRM_CAPABILITIES`).
|
|
68
|
+
- **A separate HubSpot PRODUCT behind the same host is a deferred area**, whose capabilities are
|
|
69
|
+
`todo` and whose area records why it is a separate product
|
|
70
|
+
(`HUBSPOT_DEFERRED_AREA_CAPABILITIES`). `hubspot.deferred.area_routes_refused` drives a real request at one route per
|
|
71
|
+
deferred area — and asserts that route table **bijects with the area census** — proving the twin
|
|
72
|
+
**refuses** each in HubSpot's own error envelope, never a fabricated success.
|
|
73
|
+
|
|
74
|
+
Deferred (9 areas, all non-CRM): CMS · Marketing · Automation · Conversations · Files · Events ·
|
|
75
|
+
Communication preferences · Settings · Webhooks.
|
|
76
|
+
|
|
77
|
+
A CRM object type HubSpot really has but this twin does not model — `notes`, `line_items`, a
|
|
78
|
+
custom object — is refused **honestly** (`404`, "does not model"), never with HubSpot's own
|
|
79
|
+
`Unable to infer object type from` wording, which the vendor uses only for a segment it genuinely
|
|
80
|
+
cannot resolve. All three spellings are covered: the plural name, the `objectTypeId` form
|
|
81
|
+
(`0-46`, `2-3453932`) and the `fullyQualifiedName` form (`p2953265_car`).
|
|
82
|
+
|
|
83
|
+
**Modeled (proven `done`, each with a failable offline verify):**
|
|
84
|
+
|
|
85
|
+
- **CRM objects** — contacts / companies / deals / tickets: create, read (with `?properties=` and
|
|
86
|
+
`?associations=`), list (with the documented 100-per-page cap, `?archived=`, and
|
|
87
|
+
`paging.next.after` cursor paging), update, archive, and merge. Record ids are minted as
|
|
88
|
+
`max + 1` over the **id set already in state**, archived rows included, from a **namespaced base**
|
|
89
|
+
(`HUBSPOT_LOCAL_ID_BASE`, 9e11 — an order of magnitude above the largest HubSpot record id this
|
|
90
|
+
repo has observed). That covers both collision directions: an archived id is never reused, a
|
|
91
|
+
local mint never lands on an id a pull observed, and — the direction §9 round one found live — a
|
|
92
|
+
pull arriving LATER cannot land on a locally minted subject either. `mapCrmObject` additionally
|
|
93
|
+
stamps `hsLocalMint: false`, so an observed row always wins the addressability question.
|
|
94
|
+
- **Batch** — `batch/create` (201), `batch/read` (200, or **207** with `errors[]` when an id is
|
|
95
|
+
missing, and `idProperty` lookups), `batch/update`, `batch/upsert` (`new: true|false`),
|
|
96
|
+
`batch/archive` (204).
|
|
97
|
+
- **CRM Search** — `filterGroups` (AND within a group, OR across groups) over exactly the 13
|
|
98
|
+
documented `FilterOperatorEnum` values (an operator outside that closed set is a 400), numeric
|
|
99
|
+
comparison for `LT/LTE/GT/GTE/BETWEEN`, `IN`/`NOT_IN`, presence operators, tokenized
|
|
100
|
+
`CONTAINS_TOKEN` with a trailing-`*` wildcard, free-text `query`, `sorts`, `properties`
|
|
101
|
+
projection, offset paging, and the documented 200-per-page / 10 000-result / 5-group /
|
|
102
|
+
6-filter / 18-filter caps.
|
|
103
|
+
- **Properties + property groups** — the HubSpot-defined property set per object type, plus
|
|
104
|
+
create / read / update / archive for both, a 409 on a duplicate name, and a custom property that
|
|
105
|
+
round-trips on a record and is searchable.
|
|
106
|
+
- **Pipelines + stages** — HubSpot's out-of-the-box deal pipeline (`default`, seven stages) and
|
|
107
|
+
ticket pipeline (`0`, four stages), create / read / update / **replace (PUT, full body
|
|
108
|
+
required)** / archive, and full stage CRUD. Stage ids come from a persisted monotonic counter,
|
|
109
|
+
so removing a stage never frees its id for the next one.
|
|
110
|
+
- **Owners** — list, read, `?email=` filter, and owners observed by a connector pull.
|
|
111
|
+
- **Associations (v4)** — the `PUT` with an `AssociationSpec[]` body (201 `LabelsBetweenObjectPair`
|
|
112
|
+
carrying the NUMERIC objectTypeIds). `AssociationSpec` is a closed **two-key** shape: there is no
|
|
113
|
+
`label` on the request — HubSpot resolves labels from the association-type *definition*, which
|
|
114
|
+
this twin does not model, so `labels` is empty and a caller-supplied label is never echoed back.
|
|
115
|
+
Also the `default` PUT
|
|
116
|
+
using HubSpot's documented type ids (contact→company 279 / company→contact 280 / …),
|
|
117
|
+
bidirectional readback, archive from both directions, the `associations` block on a create, the
|
|
118
|
+
closed `AssociationSpec` category set, and batch create/read/archive.
|
|
119
|
+
- **Protocol** — the documented error envelope, unmodeled ops failing like the vendor (404),
|
|
120
|
+
read-only rejecting writes (405), the rate-limit policy headers, deterministic replay, and the
|
|
121
|
+
three kernel-reserved field names (`id`/`createdAt`/`updatedAt`) surviving the projection.
|
|
122
|
+
- **Connector** — pull the four object types plus owners, following `paging.next.after`;
|
|
123
|
+
idempotent re-pull; a **refused** pull throws rather than folding an empty account over real
|
|
124
|
+
state (including a failure delivered as HTTP 200 with an error envelope); push confirms only on
|
|
125
|
+
a genuine success, and **never addresses a locally minted record id at a real portal**.
|
|
126
|
+
- **UI mirror** — the contacts list, the **deal pipeline board** (grouping asserted per column,
|
|
127
|
+
not just card counts), the stage pills, the record property sheet, the nav (bijected against
|
|
128
|
+
`MIRROR_SECTIONS`, so deleting a destination reddens it), the empty state, and the **write
|
|
129
|
+
path** — a UI write goes through the vendor's own endpoint on the same handler, and an
|
|
130
|
+
A→B→A revert through it still lands. All **data-coupled** (seed through the twin's write
|
|
131
|
+
path → fetch the SAME vendor endpoint the screen reads → render the mirror's OWN component →
|
|
132
|
+
assert the seeded value survives), plus two Playwright journeys.
|
|
133
|
+
|
|
134
|
+
**Todo (real surface, not yet modeled):** the six unbuilt CRM families above (engagements,
|
|
135
|
+
commerce, custom-object schemas, lists, imports/exports, extensions), `?idProperty=` reads,
|
|
136
|
+
`propertiesWithHistory`,
|
|
137
|
+
GDPR delete, per-object required-property and enumeration validation, unique-value conflicts,
|
|
138
|
+
HubSpot's automatic de-duplication, batch size caps and partial-207 creates, search sort direction
|
|
139
|
+
and association filters, calculated properties, pipeline audit trails
|
|
140
|
+
and stage validation on records, association label definitions and cardinality limits, 401/403
|
|
141
|
+
auth refusals, the 429 body, connector pulls of properties/pipelines/associations and push id
|
|
142
|
+
reconciliation, and the board drag-to-stage / saved-views / search-bar / inline-edit UI screens.
|
|
143
|
+
|
|
144
|
+
Also planned: **Breeze / AI content assistant endpoints** — the documented request/response
|
|
145
|
+
envelope with a deterministic, labeled twin-stub result — plus the deferred product areas above.
|
|
146
|
+
|
|
147
|
+
### The human surface: this vendor gets a mirror
|
|
148
|
+
|
|
149
|
+
Settled with the recipe's rule, not by "does a UI exist": **when someone does HubSpot's core job,
|
|
150
|
+
do they open a browser or write code?** A sales rep works a deal by dragging it across the pipeline
|
|
151
|
+
board and a support agent works a ticket in the ticket view — the CRM screen *is* the product, the
|
|
152
|
+
same shape as Jira's board. So this pack ships a mirror, and it is **archetype A (API
|
|
153
|
+
passthrough)**: non-asset requests fall through to `handleHubspotTwinRequest` and the browser
|
|
154
|
+
client fetches HubSpot's real API paths, so API↔UI parity cannot drift — there is only one code
|
|
155
|
+
path.
|
|
156
|
+
|
|
157
|
+
## Files
|
|
158
|
+
|
|
159
|
+
- `src/hubspot-twin.ts` — the CRM v3/v4 request handler (routes → kernel writes/reads) and the
|
|
160
|
+
hand-authored endpoint census.
|
|
161
|
+
- `src/hubspot-server.ts` — `createHubspotTwinServer({ root?, port?, readOnly? })`.
|
|
162
|
+
- `src/hubspot-mirror-ui.ts` + `client/hubspot-mirror.tsx` — the React CRM mirror.
|
|
163
|
+
- `src/hubspot-connector.ts` — pull/push over an injected executor (`liveHubspotExecute` for real I/O).
|
|
164
|
+
- `src/hubspot-conformance.ts` — one live request per claimed endpoint, plus a router census
|
|
165
|
+
checked in both directions (dev-only; lazy-imported by the CLI).
|
|
166
|
+
- `src/hubspot-areas.ts` / `src/hubspot-deferred-capabilities.ts` — the top-down product-area
|
|
167
|
+
census and the deferred areas' todos.
|
|
168
|
+
- `src/hubspot-capabilities.ts` — the capability manifest (the real vendor surface).
|
|
169
|
+
- `src/hubspot-sdk.integration.test.ts` — the **unmodified `@hubspot/api-client` 14.0.1** driving
|
|
170
|
+
the twin over its own public `basePath` option (a devDependency; never in the runtime graph).
|
|
171
|
+
|
|
172
|
+
## Rate budget — the fail-closed backstop on live calls
|
|
173
|
+
|
|
174
|
+
`liveHubspotExecute` is the **one place** this pack issues a live request, so every call it makes
|
|
175
|
+
is charged against a persistent, fail-closed spend ledger **before** the request goes out. Past the
|
|
176
|
+
ceiling, or while a `Retry-After`/429 cooldown is armed, it **throws instead of calling**. The
|
|
177
|
+
ledger is keyed by vendor and a hash of the credential (limits are per app/token, so it is
|
|
178
|
+
deliberately *not* cwd-scoped) and persists across processes, so a fresh process does not get a
|
|
179
|
+
fresh allowance; a corrupt ledger counts as a **full** window rather than zero spend. There is no
|
|
180
|
+
option to disable it, and no value you can pass for `budget` that yields an unguarded client — an
|
|
181
|
+
injected budget is validated by *method identity*, so a subclass or a `Proxy` that replaces
|
|
182
|
+
`checkBudget` is refused.
|
|
183
|
+
|
|
184
|
+
The declared numbers: **30 weighted units / 10 s** — HubSpot's own 10-second interval, at under a
|
|
185
|
+
third of its tightest published tier (Free/Starter: 100 requests per 10 seconds for a privately
|
|
186
|
+
distributed app; Professional and Enterprise get 190, the API-add-on 250, a public OAuth app 110).
|
|
187
|
+
CRM **search** costs 3, anchored in HubSpot's own separate five-requests-per-second search limit;
|
|
188
|
+
**batch object writes** cost 5 and **batch association writes** 3 — judgement calls, because one
|
|
189
|
+
batch call mutates up to 100 real CRM records.
|
|
190
|
+
|
|
191
|
+
The mechanism is **shared and vendor-agnostic** — it lives in the kernel (`@volter/world-core` →
|
|
192
|
+
`packages/world-core/src/rateBudget.ts`); what lives here in
|
|
193
|
+
[`src/hubspot-budget.ts`](src/hubspot-budget.ts) is this vendor's **declaration** (window, ceiling,
|
|
194
|
+
per-endpoint weights, and a `reason` citing the limits above) plus the vendor-bound
|
|
195
|
+
`HubspotBudget`. The rule is ratified as [../../../docs/contributing/architecture.md](../../../docs/contributing/architecture.md) **D8**, and
|
|
196
|
+
the kernel module's header documents what the guard does *not* guarantee — read that before
|
|
197
|
+
trusting it.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--bg: #f5f8fa;
|
|
3
|
+
--panel: #ffffff;
|
|
4
|
+
--line: #dfe3eb;
|
|
5
|
+
--text: #33475b;
|
|
6
|
+
--muted: #7c98b6;
|
|
7
|
+
--accent: #eaf0f6;
|
|
8
|
+
--brand: #ff7a59;
|
|
9
|
+
--ok: #00bda5;
|
|
10
|
+
--warn: #f5c26b;
|
|
11
|
+
--bad: #f2545b;
|
|
12
|
+
}
|
|
13
|
+
* { box-sizing: border-box; }
|
|
14
|
+
body { margin: 0; font-family: -apple-system, system-ui, "Helvetica Neue", sans-serif; background: var(--bg); color: var(--text); }
|
|
15
|
+
.app { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 56px 1fr; min-height: 100vh; }
|
|
16
|
+
.topbar { grid-column: 1 / 3; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
|
|
17
|
+
.brand { font-weight: 700; color: var(--brand); letter-spacing: 0.2px; }
|
|
18
|
+
.view-toggle { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 4px; padding: 6px 14px; cursor: pointer; font-size: 13px; }
|
|
19
|
+
.view-toggle:hover { background: var(--accent); }
|
|
20
|
+
.sidebar { border-right: 1px solid var(--line); padding: 14px 10px; background: var(--panel); }
|
|
21
|
+
.nav-item { display: block; width: 100%; text-align: left; background: none; border: none; color: var(--muted); padding: 9px 12px; border-radius: 4px; cursor: pointer; font-size: 14px; }
|
|
22
|
+
.nav-item.active, .nav-item:hover { background: var(--accent); color: var(--text); }
|
|
23
|
+
.content { padding: 24px; overflow: auto; }
|
|
24
|
+
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
|
|
25
|
+
th { text-align: left; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
|
|
26
|
+
td { padding: 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
|
|
27
|
+
tr:last-child td { border-bottom: none; }
|
|
28
|
+
.cell-title { font-weight: 600; }
|
|
29
|
+
.cell-id { color: var(--muted); font-variant-numeric: tabular-nums; }
|
|
30
|
+
.cell-prop-name { color: var(--muted); font-size: 12px; width: 40%; }
|
|
31
|
+
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; background: var(--accent); }
|
|
32
|
+
.pill-ok { background: rgba(0, 189, 165, 0.16); color: var(--ok); }
|
|
33
|
+
.pill-warn { background: rgba(245, 194, 107, 0.22); color: #b07d1a; }
|
|
34
|
+
.pill-bad { background: rgba(242, 84, 91, 0.16); color: var(--bad); }
|
|
35
|
+
.empty { color: var(--muted); padding: 28px; background: var(--panel); border: 1px dashed var(--line); border-radius: 6px; }
|
|
36
|
+
.deal-board { display: flex; gap: 14px; align-items: flex-start; overflow-x: auto; padding-bottom: 8px; }
|
|
37
|
+
.board-column { min-width: 220px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 12px; }
|
|
38
|
+
.board-column-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
|
|
39
|
+
.board-count { color: var(--muted); font-size: 12px; }
|
|
40
|
+
.deal-card { border: 1px solid var(--line); border-radius: 4px; padding: 10px; margin-bottom: 8px; }
|
|
41
|
+
.deal-amount { color: var(--muted); font-size: 13px; margin-top: 4px; }
|
|
42
|
+
.record-detail { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 20px; }
|
|
43
|
+
.detail-title { margin: 0 0 14px; font-size: 20px; }
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// HubSpot mirror — React/TSX CRM client. Renders the twin's contacts, companies, deals and
|
|
2
|
+
// tickets by fetching the twin's OWN CRM REST API on the same origin
|
|
3
|
+
// (`/crm/v3/objects/contacts`, …) — HubSpot's real paths, the same ones the SDK calls.
|
|
4
|
+
// API↔UI parity: the screen shows real twin state, not a hardcoded shell.
|
|
5
|
+
import { createRoot } from 'react-dom/client';
|
|
6
|
+
import { useEffect, useState } from 'react';
|
|
7
|
+
import {
|
|
8
|
+
MIRROR_SECTIONS, SECTION_COLUMNS, formatAmount, groupByStage, recordTitle, stageTone,
|
|
9
|
+
type HubspotRow, type MirrorSectionKey, type PillTone,
|
|
10
|
+
} from '../src/hubspot-mirror-ui.ts';
|
|
11
|
+
|
|
12
|
+
// WHERE THIS MIRROR LIVES. Served at a vendor root the base is '' (fetches are root-relative, as
|
|
13
|
+
// before); served under a path prefix with a <base> tag every read and write resolves inside that
|
|
14
|
+
// prefix instead of escaping it.
|
|
15
|
+
const WIRE_BASE = typeof document === 'undefined' || document.querySelector('base[href]') === null ? '' : new URL('.', document.baseURI).pathname.replace(/\/$/, '');
|
|
16
|
+
|
|
17
|
+
// Map a tone to a STATIC literal class name (a template-literal class is erased by the
|
|
18
|
+
// minifier, so `pill-${tone}` would vanish from the bundle — assert these instead).
|
|
19
|
+
const PILL_CLASS: Record<PillTone, string> = { ok: 'pill pill-ok', warn: 'pill pill-warn', bad: 'pill pill-bad', '': 'pill' };
|
|
20
|
+
|
|
21
|
+
/** Unwrap HubSpot's collection envelope (`{ results, paging }`) to its results array. */
|
|
22
|
+
async function fetchRows(path: string): Promise<HubspotRow[]> {
|
|
23
|
+
const res = await fetch(`${WIRE_BASE}${path}`);
|
|
24
|
+
const body = (await res.json()) as { results?: unknown };
|
|
25
|
+
return Array.isArray(body.results) ? (body.results as HubspotRow[]) : [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A CRM record list — one `list-row` landmark per record, carrying its HubSpot record id. */
|
|
29
|
+
export function RecordsTable({ section, rows }: { section: MirrorSectionKey; rows: HubspotRow[] }) {
|
|
30
|
+
if (rows.length === 0) return <div className="empty">No {section} yet.</div>;
|
|
31
|
+
const columns = SECTION_COLUMNS[section];
|
|
32
|
+
return (
|
|
33
|
+
<table className="records-table">
|
|
34
|
+
<thead>
|
|
35
|
+
<tr><th>Name</th>{columns.map((c) => <th key={c.prop}>{c.label}</th>)}<th>Record ID</th></tr>
|
|
36
|
+
</thead>
|
|
37
|
+
<tbody>
|
|
38
|
+
{rows.map((r) => (
|
|
39
|
+
<tr className="list-row" data-record-id={r.id} key={r.id}>
|
|
40
|
+
<td className="cell-title">{recordTitle(section, r.properties)}</td>
|
|
41
|
+
{columns.map((c) => (
|
|
42
|
+
<td className="cell-prop" key={c.prop}>
|
|
43
|
+
{c.prop === 'amount' ? formatAmount(r.properties?.amount)
|
|
44
|
+
: c.prop === 'dealstage'
|
|
45
|
+
? <span className={PILL_CLASS[stageTone(r.properties?.dealstage)]}>{r.properties?.dealstage ?? '—'}</span>
|
|
46
|
+
: (r.properties?.[c.prop] ?? '—')}
|
|
47
|
+
</td>
|
|
48
|
+
))}
|
|
49
|
+
<td className="cell-id">{r.id}</td>
|
|
50
|
+
</tr>
|
|
51
|
+
))}
|
|
52
|
+
</tbody>
|
|
53
|
+
</table>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The deal pipeline board — the screen a sales rep actually works in, one column per stage. */
|
|
58
|
+
export function DealBoard({ rows }: { rows: HubspotRow[] }) {
|
|
59
|
+
const groups = groupByStage(rows);
|
|
60
|
+
if (groups.length === 0) return <div className="empty">No deals yet.</div>;
|
|
61
|
+
return (
|
|
62
|
+
<div className="deal-board">
|
|
63
|
+
{groups.map((g) => (
|
|
64
|
+
<section className="board-column" data-stage={g.stage} key={g.stage}>
|
|
65
|
+
<header className="board-column-head">
|
|
66
|
+
<span className={PILL_CLASS[stageTone(g.stage)]}>{g.stage}</span>
|
|
67
|
+
<span className="board-count">{g.rows.length}</span>
|
|
68
|
+
</header>
|
|
69
|
+
{g.rows.map((r) => (
|
|
70
|
+
<article className="deal-card list-row" data-record-id={r.id} key={r.id}>
|
|
71
|
+
<div className="cell-title">{recordTitle('deals', r.properties)}</div>
|
|
72
|
+
<div className="deal-amount">{formatAmount(r.properties?.amount)}</div>
|
|
73
|
+
</article>
|
|
74
|
+
))}
|
|
75
|
+
</section>
|
|
76
|
+
))}
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Record detail — the property sheet HubSpot shows on the right of a record. */
|
|
82
|
+
export function RecordDetail({ section, rows }: { section: MirrorSectionKey; rows: HubspotRow[] }) {
|
|
83
|
+
const r = rows[0];
|
|
84
|
+
if (!r) return <div className="empty">No record.</div>;
|
|
85
|
+
const entries = Object.entries(r.properties ?? {});
|
|
86
|
+
return (
|
|
87
|
+
<section className="record-detail" data-record-id={r.id}>
|
|
88
|
+
<h2 className="detail-title">{recordTitle(section, r.properties)}</h2>
|
|
89
|
+
<table className="property-table">
|
|
90
|
+
<tbody>
|
|
91
|
+
{entries.map(([k, v]) => (
|
|
92
|
+
<tr className="list-row" data-prop={k} key={k}>
|
|
93
|
+
<td className="cell-prop-name">{k}</td>
|
|
94
|
+
<td className="cell-prop-value">{v ?? '—'}</td>
|
|
95
|
+
</tr>
|
|
96
|
+
))}
|
|
97
|
+
</tbody>
|
|
98
|
+
</table>
|
|
99
|
+
</section>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function App() {
|
|
104
|
+
const [section, setSection] = useState<MirrorSectionKey>('contacts');
|
|
105
|
+
const [board, setBoard] = useState(false);
|
|
106
|
+
const [rows, setRows] = useState<HubspotRow[]>([]);
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
const sec = MIRROR_SECTIONS.find((s) => s.key === section)!;
|
|
109
|
+
fetchRows(sec.path).then(setRows).catch(() => setRows([]));
|
|
110
|
+
}, [section]);
|
|
111
|
+
return (
|
|
112
|
+
<div className="app">
|
|
113
|
+
<header className="topbar">
|
|
114
|
+
<span className="brand">HubSpot twin</span>
|
|
115
|
+
{section === 'deals' ? (
|
|
116
|
+
<button className="view-toggle" onClick={() => setBoard((b) => !b)}>{board ? 'Table' : 'Board'}</button>
|
|
117
|
+
) : null}
|
|
118
|
+
</header>
|
|
119
|
+
<nav className="sidebar">
|
|
120
|
+
{MIRROR_SECTIONS.map((s) => (
|
|
121
|
+
<button key={s.key} className={`nav-item${s.key === section ? ' active' : ''}`} onClick={() => { setSection(s.key); setBoard(false); }}>{s.label}</button>
|
|
122
|
+
))}
|
|
123
|
+
</nav>
|
|
124
|
+
<main className="content">
|
|
125
|
+
{section === 'deals' && board ? <DealBoard rows={rows} /> : <RecordsTable section={section} rows={rows} />}
|
|
126
|
+
</main>
|
|
127
|
+
</div>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const el = typeof document !== 'undefined' ? document.getElementById('root') : null;
|
|
132
|
+
if (el) createRoot(el).render(<App />);
|