@thefittingroom/shop-ui 5.0.11 → 5.0.17

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.
Files changed (3) hide show
  1. package/README.md +135 -0
  2. package/dist/index.js +1124 -457
  3. package/package.json +12 -2
package/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # shop-sdk-ui
2
+
3
+ The Fitting Room's browser SDK. A React/TypeScript ESM library that brands embed
4
+ on product pages to render virtual try-on, size recommendations, and avatar
5
+ creation flows. Authenticates against Firebase and talks to `tfr-backend`.
6
+
7
+ Distributed via npm and served to consumers through jsdelivr. The SDK registers
8
+ a `<tfr-widget>` custom element and exposes an `init()` entrypoint.
9
+
10
+ ## Install
11
+
12
+ ```sh
13
+ npm ci
14
+ ```
15
+
16
+ ## Scripts
17
+
18
+ | Script | What it does |
19
+ |---|---|
20
+ | `npm run build` | Clean + production build into `dist/` |
21
+ | `npm run check` | Type-check (`tsc --noEmit`) |
22
+ | `npm run watch` | Vite build in watch mode |
23
+ | `npm run serve` | Static-serve the repo on `:5173` with CORS |
24
+ | `npm run watch-serve` | Both `watch` and `serve` together; Ctrl+C stops both |
25
+ | `npm run gen-types` | Regenerate `src/api/gen/*.ts` from `tfr-backend` Go types |
26
+ | `npm run promote-latest [version]` | Move npm dist-tag `latest` onto a published version (defaults to current `package.json` version) |
27
+ | `npm run manual-release [patch\|minor\|major]` | Emergency local release path (rarely needed; CI handles normal releases) |
28
+
29
+ ## Release process
30
+
31
+ Releases are CI-driven. The day-to-day flow:
32
+
33
+ **1. Auto-publish to `next` on every PR merge.** Open a PR, label it
34
+ `patch` / `minor` / `major` / `chore` (exactly one). On merge:
35
+
36
+ - `chore` → workflow skips entirely (use this for docs, CI fixes,
37
+ internal refactors that don't ship to consumers)
38
+ - `patch` / `minor` / `major` → two-stage CI:
39
+ 1. `.github/workflows/dev.yaml` bumps `package.json` and pushes the
40
+ `vX.Y.Z` tag back to `main`
41
+ 2. The tag push triggers `.github/workflows/publish.yaml`, which
42
+ builds the SDK and publishes to npm under dist-tag `next` via
43
+ [npm trusted publishing](https://docs.npmjs.com/trusted-publishers)
44
+ (OIDC, no long-lived secret)
45
+
46
+ The split exists because npm's OIDC trusted publishing doesn't work
47
+ with `pull_request_target`-triggered workflows
48
+ ([npm/cli#8739](https://github.com/npm/cli/issues/8739)). The publish
49
+ has to happen in a `push`-triggered workflow, hence the two-stage
50
+ chain. The npm trusted-publisher entry for `@thefittingroom/shop-ui`
51
+ must point at `publish.yaml` (not `dev.yaml`).
52
+
53
+ **2. Promote `next` → `latest` when ready to ship.** When a `next` build
54
+ has been validated and you want it to become the default install for
55
+ end users, run from your local checkout (logged in to npm with publish
56
+ rights to `@thefittingroom/shop-ui`):
57
+
58
+ ```sh
59
+ git pull origin main # ensure package.json reflects the latest publish
60
+ npm run promote-latest # moves dist-tag latest onto current package.json version
61
+ ```
62
+
63
+ This runs `npm dist-tag add @thefittingroom/shop-ui@<ver> latest` — no
64
+ new artifact is published; we just point the `latest` tag at the
65
+ already-published `next` build, so consumers running `npm install
66
+ @thefittingroom/shop-ui` get the new version.
67
+
68
+ To promote a specific older version: `npm run promote-latest -- 5.0.13`.
69
+
70
+ **3. Verify the promotion** with `npm dist-tag ls @thefittingroom/shop-ui`.
71
+
72
+ The `manual-release` script is kept as an emergency local fallback for
73
+ when CI is unavailable; it does the version bump + git push but expects
74
+ you to run `npm publish` yourself afterward (which requires you to be
75
+ logged in to npm with publish rights).
76
+
77
+ ## Local development
78
+
79
+ Run the SDK against the local backend stack from
80
+ [`local-deployment`](https://github.com/TheFittingRoom/local-deployment).
81
+
82
+ 1. Bring up the local stack (Postgres, Redis, MinIO, `tfr-backend`):
83
+
84
+ ```sh
85
+ cd /path/to/local-deployment && docker compose up -d
86
+ ```
87
+
88
+ 2. In this repo, start the watcher and dev server:
89
+
90
+ ```sh
91
+ npm run watch-serve
92
+ ```
93
+
94
+ This rebuilds `dist/index.js` on every file change and serves the repo at
95
+ `http://localhost:5173/dist/index.js` with CORS enabled.
96
+
97
+ 3. Open the test storefront:
98
+
99
+ <https://tfrshop-1346.myshopify.com/products/blackbandana-fitted-dress?tfr-source=local>
100
+
101
+ The `?tfr-source=local` query param tells the storefront's `tfr.js` to load
102
+ the SDK from `http://localhost:5173/dist/index.js` instead of jsdelivr, and
103
+ to initialize it with `environment: 'local'` (see `src/lib/config.ts` —
104
+ that env points at `http://localhost:8080` for the API and the local
105
+ s3proxy bucket for assets at `http://localhost:9000`).
106
+
107
+ Reload the storefront page after a rebuild to pick up changes.
108
+
109
+ ### Working with the storefront
110
+
111
+ The test storefront lives in the
112
+ [`shopify`](https://github.com/TheFittingRoom/shopify) theme repo. Its
113
+ `development` branch syncs to `tfrshop-1346.myshopify.com` automatically —
114
+ push to `origin/development` and the live demo store updates without any
115
+ `shopify theme push`.
116
+
117
+ The integration glue lives in three places in that repo:
118
+
119
+ - `assets/tfr.js` — bootstraps the SDK. Builds `currentProduct` from
120
+ `window.currentProduct` (set inline by `main-product.liquid`), wires the
121
+ `productLookup` and `getOverlayTopOffset` callbacks, and selects the SDK
122
+ source URL based on `?tfr-source=local`.
123
+ - `layout/theme.liquid` — loads `tfr.js` site-wide.
124
+ - `<tfr-widget>` embeds across `sections/main-product.liquid`,
125
+ `sections/header.liquid`, and `snippets/card-product.liquid`.
126
+
127
+ When iterating with `?tfr-source=local`, the SDK comes from your watcher
128
+ and the theme from the live demo store — you only need to push to
129
+ `shopify` when changing markup, the bootstrap script, or merchant
130
+ callbacks (`getSelectedOptions`, `addToCart`, `productLookup`,
131
+ `getOverlayTopOffset`). For SDK-only changes, just rebuild and reload.
132
+
133
+ If you're using `local-deployment`, both repos are cloned side-by-side
134
+ under `local-repo/` for you. See `local-repo/shopify/AGENTS.md` for the
135
+ theme conventions.