@volter/twin-calcom 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 +90 -0
- package/client/calcom-mirror.css +29 -0
- package/client/calcom-mirror.tsx +125 -0
- package/dist/client/calcom-mirror.bundle.js +321 -0
- package/dist/client/calcom-mirror.css +29 -0
- package/dist/client/calcom-mirror.d.ts +13 -0
- package/dist/client/calcom-mirror.js +61 -0
- package/dist/client/calcom-mirror.tsx +125 -0
- package/dist/src/calcom-budget.d.ts +52 -0
- package/dist/src/calcom-budget.js +145 -0
- package/dist/src/calcom-capabilities.d.ts +3 -0
- package/dist/src/calcom-capabilities.js +521 -0
- package/dist/src/calcom-conformance.d.ts +15 -0
- package/dist/src/calcom-conformance.js +86 -0
- package/dist/src/calcom-connector.d.ts +90 -0
- package/dist/src/calcom-connector.js +229 -0
- package/dist/src/calcom-mirror-ui.d.ts +23 -0
- package/dist/src/calcom-mirror-ui.js +100 -0
- package/dist/src/calcom-perform-harness.d.ts +5 -0
- package/dist/src/calcom-perform-harness.js +29 -0
- package/dist/src/calcom-server.d.ts +14 -0
- package/dist/src/calcom-server.js +31 -0
- package/dist/src/calcom-twin.d.ts +16 -0
- package/dist/src/calcom-twin.js +718 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +31 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +69 -0
- package/package.json +72 -0
- package/src/calcom-budget.ts +171 -0
- package/src/calcom-capabilities.ts +529 -0
- package/src/calcom-conformance.ts +92 -0
- package/src/calcom-connector.ts +258 -0
- package/src/calcom-mirror-ui.ts +110 -0
- package/src/calcom-perform-harness.ts +24 -0
- package/src/calcom-server.ts +39 -0
- package/src/calcom-twin.ts +675 -0
- package/src/cli.ts +29 -0
- package/src/index.ts +101 -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,90 @@
|
|
|
1
|
+
# @volter/twin-calcom
|
|
2
|
+
|
|
3
|
+
The **Cal.com twin** — a local, stateful, vendor-faithful replica of the [Cal.com](https://cal.com)
|
|
4
|
+
**v2 API** on the shared [`@volter/world-core`](../../world-core) kernel. An unmodified scheduling
|
|
5
|
+
integration (raw `fetch`/axios against `api.cal.com/v2`) talks to it and gets vendor-correct
|
|
6
|
+
responses; it is the QA stack's authoritative local Cal.com.
|
|
7
|
+
|
|
8
|
+
State lives in the kernel's append-only action/event log — a write appends an action that
|
|
9
|
+
projects into visible state; reads use the kernel’s tree. **No real Cal.com is ever called** (the only
|
|
10
|
+
network path is the connector, over an injected client). Auth is a **faked-locally Bearer API
|
|
11
|
+
key** (`cal_…`) — Cal.com's API auth is a plain bearer key, so there is **NO JWT, NO JWKS, NO
|
|
12
|
+
webhook signing**.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
bun run src/cli.ts serve # the Cal.com v2 API twin (writable)
|
|
18
|
+
bun run src/cli.ts serve --read-only
|
|
19
|
+
bun run src/cli.ts mirror # the React dashboard mirror (bookings + event types)
|
|
20
|
+
bun run src/cli.ts conformance # offline spec check over projected state
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Responses use Cal.com's v2 envelope: `{ "status": "success" | "error", "data": … }` (errors carry
|
|
24
|
+
`{ status: "error", error: { code, message } }`).
|
|
25
|
+
|
|
26
|
+
## Coverage
|
|
27
|
+
|
|
28
|
+
The capability manifest (`src/calcom-capabilities.ts`) is the **real Cal.com v2 surface as the
|
|
29
|
+
denominator** — coverage is honest and partial. Run `bun scripts/manifest-baseline-one.ts calcom`
|
|
30
|
+
for the live count. As of writing: **done=54 / total=84** (regressions=0).
|
|
31
|
+
|
|
32
|
+
**Modeled (proven `done`, each with a failable offline verify):**
|
|
33
|
+
|
|
34
|
+
- **Me** — `GET /v2/me` (the API-key owner profile, faithful shape).
|
|
35
|
+
- **Slots** — `GET /v2/slots` (availability keyed by date), `POST/GET /v2/slots/reservations`.
|
|
36
|
+
- **Bookings** — create / get / list (+status filter) / cancel / reschedule / confirm / decline.
|
|
37
|
+
Stateful: a created booking is retrievable by `uid`, `cancel` transitions `accepted → cancelled`,
|
|
38
|
+
a double-cancel is a `400`, an unknown `uid` is a `404`, `reschedule` cancels the old and creates
|
|
39
|
+
a new accepted booking, `confirm`/`decline` only act on a `pending` booking (else `400`).
|
|
40
|
+
- **Event types** — create / get / list / update / delete CRUD (delete then `404`).
|
|
41
|
+
- **Schedules** — create / get / list / update / delete CRUD.
|
|
42
|
+
- **Teams + memberships** — team create/get/list, membership create/list.
|
|
43
|
+
- **Webhooks** — registration CRUD (create/list/update/delete). **Registration only — no signing.**
|
|
44
|
+
- **Protocol** — `{ status, data }` success + `{ status:"error", error }` envelopes, unmodeled ops
|
|
45
|
+
fail like the vendor (`404`), read-only rejects writes (`405`).
|
|
46
|
+
- **Connector** — pull bookings + event types into the observed log (idempotent re-pull), push a
|
|
47
|
+
pending local create to the real API and confirm it (over an injected executor; offline in tests).
|
|
48
|
+
- **UI mirror** — the Bookings and Event Types dashboard screens are **data-coupled** (seed via the
|
|
49
|
+
twin → serve via the mirror server → render the dashboard's own component over the served rows →
|
|
50
|
+
assert one row per seeded record).
|
|
51
|
+
|
|
52
|
+
**Todo (real surface, not yet modeled):** profile update, slot-reservation delete, instant/recurring/
|
|
53
|
+
seated bookings, mark-absent, recordings/references/reassign, public event-type lookup, team event
|
|
54
|
+
types, locations/booking-fields/seats/buffers config, availability overrides, membership/team
|
|
55
|
+
update+delete, per-event-type webhooks, `cal-api-version` behavior pinning, pagination, rate limits,
|
|
56
|
+
booking-detail / availability-editor / teams UI screens.
|
|
57
|
+
|
|
58
|
+
The twin records booking intent without sending: no confirmation or reminder email or SMS leaves
|
|
59
|
+
the machine, no Zoom/Meet/Daily link is minted by an external provider, no Google/Outlook/CalDAV
|
|
60
|
+
account is synced, and no Stripe charge is captured. Its bearer key is seeded locally rather than
|
|
61
|
+
minted by Cal.com's platform OAuth.
|
|
62
|
+
|
|
63
|
+
## Files
|
|
64
|
+
|
|
65
|
+
- `src/calcom-twin.ts` — the v2 request handler (routes → kernel writes/reads).
|
|
66
|
+
- `src/calcom-server.ts` — `createCalcomTwinServer({ root?, port?, readOnly? })`.
|
|
67
|
+
- `src/calcom-mirror-ui.ts` + `client/calcom-mirror.tsx` — the React dashboard mirror.
|
|
68
|
+
- `src/calcom-connector.ts` — pull/push over an injected executor (`liveCalcomExecute` for real I/O).
|
|
69
|
+
- `src/calcom-conformance.ts` — offline, failable spec check (dev-only; lazy-imported by the CLI).
|
|
70
|
+
- `src/calcom-capabilities.ts` — the capability manifest (the real vendor surface).
|
|
71
|
+
|
|
72
|
+
## Rate budget — the fail-closed backstop on live calls
|
|
73
|
+
|
|
74
|
+
`liveCalcomExecute` is the **one place** this pack issues a live request, so every call it makes is charged
|
|
75
|
+
against a persistent, fail-closed spend ledger **before** the request goes out. Past the ceiling, or
|
|
76
|
+
while a `Retry-After`/429 cooldown is armed, it **throws instead of calling**. The ledger is keyed by
|
|
77
|
+
vendor and a hash of the credential (limits are per credential, so it is deliberately *not*
|
|
78
|
+
cwd-scoped) and persists across processes, so a fresh process does not get a fresh allowance; a
|
|
79
|
+
corrupt ledger counts as a **full** window rather than zero spend. There is no option to disable it,
|
|
80
|
+
and no value you can pass for `budget` that yields an unguarded client — an injected budget is
|
|
81
|
+
validated by *method identity*, so a subclass or a `Proxy` that replaces `checkBudget` is refused.
|
|
82
|
+
|
|
83
|
+
The declared numbers: **60 weighted units / 60s** — half Cal.com's documented **120 requests/minute per API key**. `POST /bookings` costs 3 (it sends e-mail, writes real connected calendars and fires webhooks — a human blast radius, not just a throttle) and `GET /slots` costs 2 (availability computed across every connected calendar); both judgement calls.
|
|
84
|
+
|
|
85
|
+
The mechanism is **shared and vendor-agnostic** — it lives in the kernel (`@volter/world-core` →
|
|
86
|
+
`packages/world-core/src/rateBudget.ts`); what lives here in [`src/calcom-budget.ts`](src/calcom-budget.ts) is this vendor's
|
|
87
|
+
**declaration** (window, ceiling, per-endpoint weights, and a `reason` citing the limits above) plus
|
|
88
|
+
the vendor-bound `CalcomBudget`. The rule is ratified as
|
|
89
|
+
[../../../docs/contributing/architecture.md](../../../docs/contributing/architecture.md) **D8**, and the kernel module's header documents what the
|
|
90
|
+
guard does *not* guarantee — read that before trusting it.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--bg: #0f1115;
|
|
3
|
+
--panel: #171a21;
|
|
4
|
+
--line: #262b35;
|
|
5
|
+
--text: #e6e9ef;
|
|
6
|
+
--muted: #9aa4b2;
|
|
7
|
+
--accent: #292929;
|
|
8
|
+
--ok: #2fae66;
|
|
9
|
+
--warn: #d9a334;
|
|
10
|
+
--bad: #d24b4b;
|
|
11
|
+
}
|
|
12
|
+
* { box-sizing: border-box; }
|
|
13
|
+
body { margin: 0; font-family: -apple-system, system-ui, sans-serif; background: var(--bg); color: var(--text); }
|
|
14
|
+
.app { display: grid; grid-template-columns: 200px 1fr; grid-template-rows: 52px 1fr; min-height: 100vh; }
|
|
15
|
+
.topbar { grid-column: 1 / 3; display: flex; align-items: center; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
|
|
16
|
+
.brand { font-weight: 700; }
|
|
17
|
+
.sidebar { border-right: 1px solid var(--line); padding: 12px 8px; background: var(--panel); }
|
|
18
|
+
.nav-item { display: block; width: 100%; text-align: left; background: none; border: none; color: var(--muted); padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; }
|
|
19
|
+
.nav-item.active, .nav-item:hover { background: var(--accent); color: var(--text); }
|
|
20
|
+
.content { padding: 20px; overflow: auto; }
|
|
21
|
+
table { width: 100%; border-collapse: collapse; }
|
|
22
|
+
th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; padding: 8px 10px; border-bottom: 1px solid var(--line); }
|
|
23
|
+
td { padding: 10px; border-bottom: 1px solid var(--line); font-size: 14px; }
|
|
24
|
+
.cell-title { font-weight: 600; }
|
|
25
|
+
.pill { padding: 2px 8px; border-radius: 999px; font-size: 12px; }
|
|
26
|
+
.pill-ok { background: rgba(47,174,102,0.18); color: var(--ok); }
|
|
27
|
+
.pill-warn { background: rgba(217,163,52,0.18); color: var(--warn); }
|
|
28
|
+
.pill-bad { background: rgba(210,75,75,0.18); color: var(--bad); }
|
|
29
|
+
.empty { color: var(--muted); padding: 24px; }
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Cal.com mirror — React/TSX dashboard client. Renders the twin's bookings + event types
|
|
2
|
+
// by fetching the twin's OWN v2 REST API on the same origin (/v2/bookings, /v2/event-types).
|
|
3
|
+
// API↔UI parity: the screen shows real twin state, not a hardcoded shell.
|
|
4
|
+
import { createRoot } from 'react-dom/client';
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
import { attendeeLabel, bookingTone, formatWindow, type CalcomRow, type PillTone } from '../src/calcom-mirror-ui.ts';
|
|
7
|
+
|
|
8
|
+
// WHERE THIS MIRROR LIVES. Served at a vendor root the base is '' (fetches are root-relative, as
|
|
9
|
+
// before); served under a path prefix with a <base> tag every read and write resolves inside that
|
|
10
|
+
// prefix instead of escaping it.
|
|
11
|
+
const WIRE_BASE = typeof document === 'undefined' || document.querySelector('base[href]') === null ? '' : new URL('.', document.baseURI).pathname.replace(/\/$/, '');
|
|
12
|
+
|
|
13
|
+
// Map a tone to a STATIC literal class name (a template-literal class is erased by the
|
|
14
|
+
// minifier, so `pill-${tone}` would vanish from the bundle — assert these instead).
|
|
15
|
+
const PILL_CLASS: Record<PillTone, string> = { ok: 'pill pill-ok', warn: 'pill pill-warn', bad: 'pill pill-bad', '': 'pill' };
|
|
16
|
+
|
|
17
|
+
const SECTIONS = [
|
|
18
|
+
{ key: 'bookings', label: 'Bookings', path: '/v2/bookings' },
|
|
19
|
+
{ key: 'event-types', label: 'Event Types', path: '/v2/event-types' },
|
|
20
|
+
] as const;
|
|
21
|
+
type SectionKey = (typeof SECTIONS)[number]['key'];
|
|
22
|
+
|
|
23
|
+
// Unwrap the v2 envelope ({ status, data }) to its data array.
|
|
24
|
+
async function fetchData(path: string): Promise<CalcomRow[]> {
|
|
25
|
+
const res = await fetch(`${WIRE_BASE}${path}`);
|
|
26
|
+
const body = (await res.json()) as { data?: unknown };
|
|
27
|
+
return Array.isArray(body.data) ? (body.data as CalcomRow[]) : [];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The bookings table — one `list-row` landmark per booking, carrying its uid. */
|
|
31
|
+
export function BookingsList({ rows }: { rows: CalcomRow[] }) {
|
|
32
|
+
if (rows.length === 0) return <div className="empty">No bookings yet.</div>;
|
|
33
|
+
return (
|
|
34
|
+
<table className="bookings-table">
|
|
35
|
+
<thead>
|
|
36
|
+
<tr><th>Title</th><th>When</th><th>Attendee</th><th>Status</th></tr>
|
|
37
|
+
</thead>
|
|
38
|
+
<tbody>
|
|
39
|
+
{rows.map((b) => (
|
|
40
|
+
<tr className="list-row" data-uid={b.uid} key={b.uid}>
|
|
41
|
+
<td className="cell-title">{b.title}</td>
|
|
42
|
+
<td className="cell-when">{formatWindow(b.start, b.end)}</td>
|
|
43
|
+
<td className="cell-attendee">{attendeeLabel(b.attendees)}</td>
|
|
44
|
+
<td><span className={PILL_CLASS[bookingTone(b.status)]}>{b.status}</span></td>
|
|
45
|
+
</tr>
|
|
46
|
+
))}
|
|
47
|
+
</tbody>
|
|
48
|
+
</table>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Booking detail — one `list-row` per attendee/host, plus a reschedule-history line. */
|
|
53
|
+
export function BookingDetail({ rows }: { rows: CalcomRow[] }) {
|
|
54
|
+
const b = rows[0];
|
|
55
|
+
if (!b) return <div className="empty">No booking.</div>;
|
|
56
|
+
const attendees = Array.isArray(b.attendees) ? b.attendees : [];
|
|
57
|
+
const hosts = Array.isArray(b.hosts) ? b.hosts : [];
|
|
58
|
+
const people = [
|
|
59
|
+
...hosts.map((h: Record<string, unknown>) => ({ role: 'host', name: h.name, email: (h as { email?: string }).email ?? '', id: `host-${h.id ?? h.name}` })),
|
|
60
|
+
...attendees.map((a: Record<string, unknown>) => ({ role: 'attendee', name: a.name, email: a.email, id: `att-${a.email}` })),
|
|
61
|
+
];
|
|
62
|
+
return (
|
|
63
|
+
<section className="booking-detail" data-uid={b.uid}>
|
|
64
|
+
<h2 className="detail-title">{b.title}</h2>
|
|
65
|
+
<div className="detail-when">{formatWindow(b.start, b.end)}</div>
|
|
66
|
+
<div><span className={PILL_CLASS[bookingTone(b.status)]}>{b.status}</span></div>
|
|
67
|
+
<table className="people-table">
|
|
68
|
+
<tbody>
|
|
69
|
+
{people.map((p) => (
|
|
70
|
+
<tr className="list-row" data-pid={p.id} key={p.id}>
|
|
71
|
+
<td className="cell-role">{p.role}</td>
|
|
72
|
+
<td className="cell-name">{String(p.name ?? '')}</td>
|
|
73
|
+
<td className="cell-email">{String(p.email ?? '')}</td>
|
|
74
|
+
</tr>
|
|
75
|
+
))}
|
|
76
|
+
</tbody>
|
|
77
|
+
</table>
|
|
78
|
+
{b.fromReschedule ? <div className="reschedule-history">rescheduled from {String(b.fromReschedule)}</div> : null}
|
|
79
|
+
</section>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Event types table — one `list-row` per event type. */
|
|
84
|
+
export function EventTypesList({ rows }: { rows: CalcomRow[] }) {
|
|
85
|
+
if (rows.length === 0) return <div className="empty">No event types yet.</div>;
|
|
86
|
+
return (
|
|
87
|
+
<table className="evt-table">
|
|
88
|
+
<thead><tr><th>Title</th><th>Slug</th><th>Length</th></tr></thead>
|
|
89
|
+
<tbody>
|
|
90
|
+
{rows.map((e) => (
|
|
91
|
+
<tr className="list-row" data-id={e.id} key={e.id}>
|
|
92
|
+
<td className="cell-title">{e.title}</td>
|
|
93
|
+
<td>{e.slug}</td>
|
|
94
|
+
<td>{e.lengthInMinutes} min</td>
|
|
95
|
+
</tr>
|
|
96
|
+
))}
|
|
97
|
+
</tbody>
|
|
98
|
+
</table>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function App() {
|
|
103
|
+
const [section, setSection] = useState<SectionKey>('bookings');
|
|
104
|
+
const [rows, setRows] = useState<CalcomRow[]>([]);
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
const sec = SECTIONS.find((s) => s.key === section)!;
|
|
107
|
+
fetchData(sec.path).then(setRows).catch(() => setRows([]));
|
|
108
|
+
}, [section]);
|
|
109
|
+
return (
|
|
110
|
+
<div className="app">
|
|
111
|
+
<header className="topbar"><span className="brand">Cal.com twin</span></header>
|
|
112
|
+
<nav className="sidebar">
|
|
113
|
+
{SECTIONS.map((s) => (
|
|
114
|
+
<button key={s.key} className={`nav-item${s.key === section ? ' active' : ''}`} onClick={() => setSection(s.key)}>{s.label}</button>
|
|
115
|
+
))}
|
|
116
|
+
</nav>
|
|
117
|
+
<main className="content">
|
|
118
|
+
{section === 'bookings' ? <BookingsList rows={rows} /> : <EventTypesList rows={rows} />}
|
|
119
|
+
</main>
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const el = typeof document !== 'undefined' ? document.getElementById('root') : null;
|
|
125
|
+
if (el) createRoot(el).render(<App />);
|