@scopetickets/checkout 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/README.md +203 -0
- package/package.json +68 -0
package/README.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# @scopetickets/checkout
|
|
2
|
+
|
|
3
|
+
ScopeTicketsCheckout — an embeddable checkout widget. A host mounts it, hands it
|
|
4
|
+
an order to complete, and it draws the card, the motion between its states, and
|
|
5
|
+
the steps it collects answers in.
|
|
6
|
+
|
|
7
|
+
It is a package beside `@scopetickets/sdk`, not a part of it. Nothing here
|
|
8
|
+
imports the SDK, and the SDK's public API is unchanged by its arrival.
|
|
9
|
+
|
|
10
|
+
## What is here
|
|
11
|
+
|
|
12
|
+
The widget, its island and the steps it mounts — 99 files, of which 35 are
|
|
13
|
+
tests. `src/island` is the surface and its motion; `src/domain` is the flow it
|
|
14
|
+
walks, as pure functions with no React in them.
|
|
15
|
+
|
|
16
|
+
Not everything it draws is reachable yet, and the gaps are all in the same
|
|
17
|
+
place: there is no account service to sign into, so `ScopeTicketsCheckout`
|
|
18
|
+
routes every buyer as a guest and the auth cards draw without anywhere to send
|
|
19
|
+
anybody. What a host passes it works today.
|
|
20
|
+
|
|
21
|
+
## What a host installs
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
npm install @scopetickets/checkout
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { ScopeTicketsCheckout } from '@scopetickets/checkout';
|
|
29
|
+
import '@scopetickets/checkout/styles.css';
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
<ScopeTicketsCheckout
|
|
34
|
+
appKey="…"
|
|
35
|
+
intent={{ subject: { kind: 'series', key: 'a-run-of-nights' } }}
|
|
36
|
+
align="bottom" // or "top", or "center" — which way the card grows
|
|
37
|
+
initialPresentation="card" // or "pill" — the state the page loads on
|
|
38
|
+
/>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The host supplies no copy, no styling and no steps: hand it what is already known
|
|
42
|
+
about the order and it asks for the rest in its own words. `intent` is how much it
|
|
43
|
+
already knows, and every field in it is a step the buyer is not asked for.
|
|
44
|
+
|
|
45
|
+
**Leave `intent` out and it mounts with nothing to sell.** No walk, no steps, no
|
|
46
|
+
cart and nothing fetched — one card about the buyer's account, which is what
|
|
47
|
+
belongs on a page that is not selling anything:
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
<ScopeTicketsCheckout appKey="…" align="top" />
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
It draws the checkout's own `IDLE` card: sign in, welcome back, or "you're ready
|
|
54
|
+
to go" for a buyer already in an account. Hand it an `intent` the moment there is
|
|
55
|
+
something to buy and the same widget becomes the purchase. `OrderIntent.subject`
|
|
56
|
+
stays required under it — an intent with no subject is not a half-composed order,
|
|
57
|
+
it is nothing to sell — so the absence is the prop's rather than the subject's.
|
|
58
|
+
|
|
59
|
+
The buttons on that card do not go anywhere yet, for the reason the ones inside
|
|
60
|
+
the flow do not: there is no account service to sign into.
|
|
61
|
+
|
|
62
|
+
**Or rest on a cart the buyer is still filling** — `opensOn="cart"`. This is the
|
|
63
|
+
shape a host on `@scopetickets/sdk` has: a product is in the cart, and the buyer
|
|
64
|
+
may add more before they check out.
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
<ScopeTicketsCheckout
|
|
68
|
+
appKey="…"
|
|
69
|
+
intent={intent}
|
|
70
|
+
cart={{ key: cartKey }}
|
|
71
|
+
quote={quote}
|
|
72
|
+
cartLines={lines} // optional; without it the adopted cart's own items are listed
|
|
73
|
+
opensOn="cart"
|
|
74
|
+
/>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The island draws the account card while the cart is empty and the cart once there
|
|
78
|
+
is something in it, and the change between them is a transition rather than a
|
|
79
|
+
remount: the leaving card fades, the surface morphs to the new height, the cart
|
|
80
|
+
fades in. Adding a line does _not_ start a transition — the card grows to fit the
|
|
81
|
+
new row instead, which is what the island's own resize observer is for.
|
|
82
|
+
|
|
83
|
+
It follows what you hand it. Every row, the total and the countdown are derived
|
|
84
|
+
from props on each render, so the SDK re-rendering with a changed `Cart` is all
|
|
85
|
+
the notification the widget needs. A cart the widget only _read_ is read once: it
|
|
86
|
+
does not poll, because this library runs inside somebody else's page. Pass
|
|
87
|
+
`cartLines` and `quote` for a cart that changes.
|
|
88
|
+
|
|
89
|
+
`opensOn` defaults to `flow`, which is what every host has had — including the
|
|
90
|
+
multi-page split, which passes `cart` on every page and means the opposite by it.
|
|
91
|
+
|
|
92
|
+
**Check Out runs the checks first.** `runCheckoutPreflight` walks the six the
|
|
93
|
+
steps have always named — `party-size`, `series-date`, `select-time`,
|
|
94
|
+
`signed-in`, `order-requirements`, `questionnaire` — and the first that has
|
|
95
|
+
something to ask decides which card the flow opens on. Two of them READ: whether
|
|
96
|
+
the day sells sessions and whether the event asks its own questions are the
|
|
97
|
+
tickets' to answer, and a synchronous guess there is what walks a buyer past a
|
|
98
|
+
picker they needed. The four that can answer from the intent run first and often
|
|
99
|
+
spare the request. A check that throws sends the buyer to the card it guards
|
|
100
|
+
rather than past it.
|
|
101
|
+
|
|
102
|
+
**A host that already opened a cart passes it**, and the widget adopts it rather
|
|
103
|
+
than opening a second:
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
<ScopeTicketsCheckout appKey="…" intent={intent} cart={{ key: cartKey }} />
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Without it, a host that composes the order itself ends up with two carts for one
|
|
110
|
+
purchase — the items added twice, the payment settled against the widget's, and
|
|
111
|
+
the host's left holding stock nobody will buy. Given a key the cart is read and
|
|
112
|
+
never created or filled: what is in it is the host's statement.
|
|
113
|
+
|
|
114
|
+
What the host asserts is also now checked rather than taken. A party over
|
|
115
|
+
`maxParty`, or a `timeslot` the run does not sell, opens no cart at all and says
|
|
116
|
+
why — an unresolvable slot used to be dropped on the way, so the order was placed
|
|
117
|
+
for the right day at no particular time.
|
|
118
|
+
|
|
119
|
+
The stylesheet is a separate entry point so a host that supplies its own can skip
|
|
120
|
+
it. Every value in it resolves through `var(--scope-…, fallback)`: inside the SDK
|
|
121
|
+
its ThemeProvider wins with no wiring, and standalone the fallbacks apply.
|
|
122
|
+
|
|
123
|
+
React is a peer dependency. `@scopetickets/icons` and `@scopetickets/avatar` are
|
|
124
|
+
regular dependencies rather than peers, so an integrator installs one thing — the
|
|
125
|
+
trade is that a host already on one of them at a different range may end up with
|
|
126
|
+
two copies. They are the only two: everything else this widget draws, including
|
|
127
|
+
its brand marks, is inside it.
|
|
128
|
+
|
|
129
|
+
## Seeing the flow before the platform is there
|
|
130
|
+
|
|
131
|
+
Auth and payments do not exist yet, and two of the flow's cards report things only a
|
|
132
|
+
payment provider can know. `simulate` fabricates those answers so the rest can be
|
|
133
|
+
walked:
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
import { ScopeTicketsCheckout, SIMULATED_SESSIONS } from '@scopetickets/checkout';
|
|
137
|
+
|
|
138
|
+
<ScopeTicketsCheckout
|
|
139
|
+
appKey="…"
|
|
140
|
+
intent={{ subject: { kind: 'series', key: '…' } }}
|
|
141
|
+
session={SIMULATED_SESSIONS.guest} // or unrecognised, recognised, authenticated
|
|
142
|
+
simulate
|
|
143
|
+
/>;
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
That one prop is enough to walk the whole flow. It supplies a run for the day and time
|
|
147
|
+
pickers as well as the payment answers — a host that defers the calendar has to hand in a
|
|
148
|
+
`schedule`, and a demo should not have to invent three weeks of dates before it can see
|
|
149
|
+
one. Pass your own `schedule` and it wins; the calendar and the payment are stood in for
|
|
150
|
+
separately.
|
|
151
|
+
|
|
152
|
+
The scenarios are the PAYMENT METHODS. Open "Select Payment Method" and each row is a
|
|
153
|
+
different thing to test — an instant approval, an ordinary one, one slow enough to reach
|
|
154
|
+
Payment Confirming, a decline, and a decline after a long wait. Pick one, pay, and the
|
|
155
|
+
flow does what that row says.
|
|
156
|
+
|
|
157
|
+
Nothing is reached without the prop, and taking it out is deleting
|
|
158
|
+
`src/testing/simulate.tsx` and the prop that names it: the typechecker then points at the
|
|
159
|
+
three places real logic plugs in — the payment list, the outcome that arrives while
|
|
160
|
+
Processing is up, and what Try Again does with a failure. The file's own header says the
|
|
161
|
+
same thing at more length.
|
|
162
|
+
|
|
163
|
+
AUTH NEEDS NO MACHINERY, which is why there is none. `session` is already a plain data
|
|
164
|
+
prop, so every state the flow reasons about was expressible; `SIMULATED_SESSIONS` is four
|
|
165
|
+
of them written down.
|
|
166
|
+
|
|
167
|
+
## Working on it
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
pnpm --filter @scopetickets/checkout build
|
|
171
|
+
pnpm --filter @scopetickets/checkout typecheck
|
|
172
|
+
pnpm test # from the repo root; the workspace includes this package
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Tests are colocated with the code they cover.
|
|
176
|
+
|
|
177
|
+
## Three guards worth knowing about
|
|
178
|
+
|
|
179
|
+
**The build checks its own externals.** An external is written into `dist` as a
|
|
180
|
+
literal specifier and resolved by the consumer's bundler, so nothing in this repo
|
|
181
|
+
typechecks it — a package renamed elsewhere ships green here and fails on an
|
|
182
|
+
integrator's machine. `tsup.config.ts` collects every `@scopetickets/*` specifier
|
|
183
|
+
left in the output and fails the build on any the manifest does not declare.
|
|
184
|
+
|
|
185
|
+
**The manifest is tested like an API.** `src/__tests__/package-contract.test.ts`
|
|
186
|
+
asserts the `exports` entry, the stylesheet beside it, the `files` list and the
|
|
187
|
+
React-as-peer rule. Assertions rather than snapshots, so a change reads as a
|
|
188
|
+
decision.
|
|
189
|
+
|
|
190
|
+
**No dependency a consumer could not install.** A `file:` or `link:` specifier is
|
|
191
|
+
written into the published manifest verbatim, so it names a path on the machine
|
|
192
|
+
that published it and nowhere else. This shipped once — the brand marks came from
|
|
193
|
+
a private package reached through a tarball — and both guards above passed it,
|
|
194
|
+
because the manifest did declare what the output imported. It was the specifier
|
|
195
|
+
that was unpublishable, not the dependency.
|
|
196
|
+
|
|
197
|
+
## Publishing
|
|
198
|
+
|
|
199
|
+
`.github/workflows/release-checkout.yml` publishes on a `checkout-v*` tag using
|
|
200
|
+
npm Trusted Publishing: GitHub mints a short-lived OIDC token and npm verifies it
|
|
201
|
+
against a publisher configured on the package, so there is no npm token in this
|
|
202
|
+
repository. That publisher must be registered once on npmjs.com before the first
|
|
203
|
+
release; until then the workflow fails at its final step, which is correct.
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@scopetickets/checkout",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ScopeTicketsCheckout — the embeddable checkout widget: the island, its motion, and the steps it mounts.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": [
|
|
8
|
+
"*.css"
|
|
9
|
+
],
|
|
10
|
+
"main": "./dist/index.cjs",
|
|
11
|
+
"module": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"require": "./dist/index.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./pickers": {
|
|
20
|
+
"types": "./dist/pickers.d.ts",
|
|
21
|
+
"import": "./dist/pickers.js",
|
|
22
|
+
"require": "./dist/pickers.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./styles.css": "./dist/styles.css",
|
|
25
|
+
"./pickers.css": "./dist/pickers.css"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/Scope-Tickets/sdk.git",
|
|
36
|
+
"directory": "packages/checkout"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=20"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@scopetickets/avatar": "^0.1.1",
|
|
46
|
+
"@scopetickets/icons": "^0.1.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@microsoft/api-extractor": "^7.59.1",
|
|
50
|
+
"@testing-library/dom": "^10.4.0",
|
|
51
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
52
|
+
"@testing-library/react": "^16.1.0",
|
|
53
|
+
"@types/node": "^22.0.0",
|
|
54
|
+
"@types/react": "^18.3.12",
|
|
55
|
+
"@types/react-dom": "^18.3.1",
|
|
56
|
+
"happy-dom": "^15.11.7",
|
|
57
|
+
"react": "^18.3.1",
|
|
58
|
+
"react-dom": "^18.3.1",
|
|
59
|
+
"tsup": "^8.3.5",
|
|
60
|
+
"typescript": "^5.7.2",
|
|
61
|
+
"@scopetickets/api": "0.1.0"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "pnpm --filter @scopetickets/api build && tsup && node scripts/verify-declarations.mjs",
|
|
65
|
+
"dev": "tsup --watch",
|
|
66
|
+
"typecheck": "tsc --noEmit"
|
|
67
|
+
}
|
|
68
|
+
}
|