@haatlabs-core/ui 0.0.0-stage → 0.11.1

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 (45) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +37 -2
  3. package/dist/Drawer.d.ts +12 -0
  4. package/dist/Drawer.js +20 -0
  5. package/dist/Drawer.js.map +1 -0
  6. package/dist/EmptyState.d.ts +6 -0
  7. package/dist/EmptyState.js +6 -0
  8. package/dist/EmptyState.js.map +1 -0
  9. package/dist/FullScreen.d.ts +7 -0
  10. package/dist/FullScreen.js +18 -0
  11. package/dist/FullScreen.js.map +1 -0
  12. package/dist/Loading.d.ts +10 -0
  13. package/dist/Loading.js +16 -0
  14. package/dist/Loading.js.map +1 -0
  15. package/dist/SearchBox.d.ts +10 -0
  16. package/dist/SearchBox.js +23 -0
  17. package/dist/SearchBox.js.map +1 -0
  18. package/dist/admin/PlanControls.d.ts +47 -0
  19. package/dist/admin/PlanControls.js +39 -0
  20. package/dist/admin/PlanControls.js.map +1 -0
  21. package/dist/admin/index.d.ts +2 -0
  22. package/dist/admin/index.js +2 -0
  23. package/dist/admin/index.js.map +1 -0
  24. package/dist/client/EmailSignInPanel.d.ts +22 -0
  25. package/dist/client/EmailSignInPanel.js +66 -0
  26. package/dist/client/EmailSignInPanel.js.map +1 -0
  27. package/dist/client/LoginPage.d.ts +23 -0
  28. package/dist/client/LoginPage.js +57 -0
  29. package/dist/client/LoginPage.js.map +1 -0
  30. package/dist/client/UsagePage.d.ts +97 -0
  31. package/dist/client/UsagePage.js +186 -0
  32. package/dist/client/UsagePage.js.map +1 -0
  33. package/dist/client/index.d.ts +9 -0
  34. package/dist/client/index.js +6 -0
  35. package/dist/client/index.js.map +1 -0
  36. package/dist/client/query-client.d.ts +17 -0
  37. package/dist/client/query-client.js +41 -0
  38. package/dist/client/query-client.js.map +1 -0
  39. package/dist/client/transport.d.ts +56 -0
  40. package/dist/client/transport.js +125 -0
  41. package/dist/client/transport.js.map +1 -0
  42. package/dist/index.d.ts +5 -0
  43. package/dist/index.js +6 -0
  44. package/dist/index.js.map +1 -0
  45. package/package.json +74 -4
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Haatlabs
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,38 @@
1
- # Temporary Holding Version
1
+ # @haatlabs-core/ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ React components the apps share. Fonts, theme and colours stay with each app: the
4
+ components carry class names, and each app's stylesheet styles them.
5
+
6
+ import { Drawer, EmptyState, FullScreen, Loading, SearchBox } from '@haatlabs-core/ui';
7
+
8
+ | Component | What it is | Class names it uses |
9
+ | ------------ | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
10
+ | `EmptyState` | What a list shows when it has nothing: a title and what to do next | `.empty` |
11
+ | `Loading` | Placeholder rows (`rows`) or a spinner, labelled for assistive technology | `.skeleton`, `.skeleton-row`, `.skeleton-box`, `.skeleton-line`, `.short`, `.loading`, `.spinner` |
12
+ | `Drawer` | A card's detail beside its list, with a link to its full page; Escape closes it | `.drawer`, `.drawer-bar`, `.drawer-body`, `.row`, `.spread` |
13
+ | `FullScreen` | A picture over the whole screen; Escape or a click outside closes it | `.full-screen`, `.full-screen-close` |
14
+ | `SearchBox` | Calls `onSearch` with the trimmed phrase once typing pauses for 300 ms | `.search-box` |
15
+
16
+ `react`, `react-dom` and `react-router-dom` are peers: the app's own copies are used.
17
+
18
+ ## Install
19
+
20
+ pnpm add @haatlabs-core/ui
21
+
22
+ It leaves these packages to your app, so the app holds one copy: `react`, `react-dom`, `react-router-dom`, `@tanstack/react-query`, `zod`.
23
+
24
+ ## `@haatlabs-core/ui/client`
25
+
26
+ What an app's pages use to talk to its API, and the sign-in pages:
27
+
28
+ - `createTransport({ baseUrl, credentials, fetch, envelope })`: `call`, `adminCall`, `send`,
29
+ `queryOf`. Writes carry the CSRF header (`x-csrf-token`); administrators' writes carry
30
+ `x-admin-csrf`. A failure is an `ApiError` with the API's code and status.
31
+ - `cookieCredentials(appName)`: the dashboard's session cookie and its CSRF cookie
32
+ `<appName>_csrf`. Inside Shopify admin, pass `{ kind: 'bearer', getToken }`.
33
+ - `createQueryClient()`: reads and writes that fail on the network or with a 5xx are tried
34
+ again, twice at most; a 401 asks for `me` again.
35
+ - `LoginPage({ client, aside })` and `EmailSignInPanel({ client })`: signing in with a code,
36
+ and giving a store installed from Shopify an email to sign in with.
37
+
38
+ `@tanstack/react-query` and `zod` are peers.
@@ -0,0 +1,12 @@
1
+ import type { ReactElement } from 'react';
2
+ /**
3
+ * What a card leads to, beside the list it was opened from. The list stays in view and
4
+ * keeps updating; the drawer closes with its button or Escape.
5
+ */
6
+ export declare function Drawer(props: {
7
+ label: string;
8
+ /** The same thing at an address of its own. */
9
+ fullPage: string;
10
+ onClose: () => void;
11
+ children: ReactElement;
12
+ }): ReactElement;
package/dist/Drawer.js ADDED
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect } from 'react';
3
+ import { Link } from 'react-router-dom';
4
+ /**
5
+ * What a card leads to, beside the list it was opened from. The list stays in view and
6
+ * keeps updating; the drawer closes with its button or Escape.
7
+ */
8
+ export function Drawer(props) {
9
+ const { onClose } = props;
10
+ useEffect(() => {
11
+ const onKey = (event) => {
12
+ if (event.key === 'Escape')
13
+ onClose();
14
+ };
15
+ window.addEventListener('keydown', onKey);
16
+ return () => window.removeEventListener('keydown', onKey);
17
+ }, [onClose]);
18
+ return (_jsxs("aside", { role: "dialog", "aria-label": props.label, className: "drawer", children: [_jsxs("div", { className: "row spread drawer-bar", children: [_jsx(Link, { to: props.fullPage, children: "Open full page" }), _jsx("button", { type: "button", onClick: onClose, children: "Close" })] }), _jsx("div", { className: "drawer-body", children: props.children })] }));
19
+ }
20
+ //# sourceMappingURL=Drawer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Drawer.js","sourceRoot":"","sources":["../src/Drawer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,KAMtB;IACC,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC1B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,KAAK,GAAG,CAAC,KAAoB,EAAQ,EAAE;YAC3C,IAAI,KAAK,CAAC,GAAG,KAAK,QAAQ;gBAAE,OAAO,EAAE,CAAC;QACxC,CAAC,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAC1C,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC5D,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IACd,OAAO,CACL,iBAAO,IAAI,EAAC,QAAQ,gBAAa,KAAK,CAAC,KAAK,EAAE,SAAS,EAAC,QAAQ,aAC9D,eAAK,SAAS,EAAC,uBAAuB,aACpC,KAAC,IAAI,IAAC,EAAE,EAAE,KAAK,CAAC,QAAQ,+BAAuB,EAC/C,iBAAQ,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,OAAO,sBAE7B,IACL,EACN,cAAK,SAAS,EAAC,aAAa,YAAE,KAAK,CAAC,QAAQ,GAAO,IAC7C,CACT,CAAC;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ /** What a list shows when it has nothing to list: what that means, and what to do next. */
3
+ export declare function EmptyState(props: {
4
+ title: string;
5
+ children?: ReactNode;
6
+ }): ReactElement;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /** What a list shows when it has nothing to list: what that means, and what to do next. */
3
+ export function EmptyState(props) {
4
+ return (_jsxs("div", { className: "empty", role: "status", children: [_jsxs("svg", { width: "40", height: "40", viewBox: "0 0 40 40", "aria-hidden": "true", children: [_jsx("rect", { x: "6", y: "9", width: "28", height: "22", rx: "4", fill: "none", stroke: "currentColor", strokeWidth: "2" }), _jsx("path", { d: "M6 25l8-7 6 5 5-4 9 8", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinejoin: "round" }), _jsx("circle", { cx: "26", cy: "15", r: "2", fill: "currentColor" })] }), _jsx("strong", { children: props.title }), props.children && _jsx("p", { children: props.children })] }));
5
+ }
6
+ //# sourceMappingURL=EmptyState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EmptyState.js","sourceRoot":"","sources":["../src/EmptyState.tsx"],"names":[],"mappings":";AAEA,2FAA2F;AAC3F,MAAM,UAAU,UAAU,CAAC,KAA8C;IACvE,OAAO,CACL,eAAK,SAAS,EAAC,OAAO,EAAC,IAAI,EAAC,QAAQ,aAClC,eAAK,KAAK,EAAC,IAAI,EAAC,MAAM,EAAC,IAAI,EAAC,OAAO,EAAC,WAAW,iBAAa,MAAM,aAChE,eACE,CAAC,EAAC,GAAG,EACL,CAAC,EAAC,GAAG,EACL,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,EAAE,EAAC,GAAG,EACN,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,GAAG,GACf,EACF,eACE,CAAC,EAAC,uBAAuB,EACzB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,GAAG,EACf,cAAc,EAAC,OAAO,GACtB,EACF,iBAAQ,EAAE,EAAC,IAAI,EAAC,EAAE,EAAC,IAAI,EAAC,CAAC,EAAC,GAAG,EAAC,IAAI,EAAC,cAAc,GAAG,IAChD,EACN,2BAAS,KAAK,CAAC,KAAK,GAAU,EAC7B,KAAK,CAAC,QAAQ,IAAI,sBAAI,KAAK,CAAC,QAAQ,GAAK,IACtC,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { ReactElement } from 'react';
2
+ /** A picture over the whole screen, until it is clicked away or Escape is pressed. */
3
+ export declare function FullScreen(props: {
4
+ src: string;
5
+ label: string;
6
+ onClose: () => void;
7
+ }): ReactElement;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from 'react';
3
+ /** A picture over the whole screen, until it is clicked away or Escape is pressed. */
4
+ export function FullScreen(props) {
5
+ const { onClose } = props;
6
+ const close = useRef(null);
7
+ useEffect(() => {
8
+ const onKey = (event) => {
9
+ if (event.key === 'Escape')
10
+ onClose();
11
+ };
12
+ document.addEventListener('keydown', onKey);
13
+ close.current?.focus();
14
+ return () => document.removeEventListener('keydown', onKey);
15
+ }, [onClose]);
16
+ return (_jsxs("div", { role: "dialog", "aria-modal": "true", "aria-label": props.label, className: "full-screen", onClick: onClose, children: [_jsx("button", { ref: close, type: "button", className: "full-screen-close", onClick: onClose, children: "Close" }), _jsx("img", { src: props.src, alt: "", onClick: (event) => event.stopPropagation() })] }));
17
+ }
18
+ //# sourceMappingURL=FullScreen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FullScreen.js","sourceRoot":"","sources":["../src/FullScreen.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAG1C,sFAAsF;AACtF,MAAM,UAAU,UAAU,CAAC,KAI1B;IACC,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC1B,MAAM,KAAK,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAC9C,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,KAAK,GAAG,CAAC,KAAoB,EAAQ,EAAE;YAC3C,IAAI,KAAK,CAAC,GAAG,KAAK,QAAQ;gBAAE,OAAO,EAAE,CAAC;QACxC,CAAC,CAAC;QACF,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAC5C,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QACvB,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC9D,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IACd,OAAO,CAEL,eACE,IAAI,EAAC,QAAQ,gBACF,MAAM,gBACL,KAAK,CAAC,KAAK,EACvB,SAAS,EAAC,aAAa,EACvB,OAAO,EAAE,OAAO,aAEhB,iBAAQ,GAAG,EAAE,KAAK,EAAE,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,mBAAmB,EAAC,OAAO,EAAE,OAAO,sBAEvE,EACT,cAAK,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAC,EAAE,EAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,eAAe,EAAE,GAAI,IACvE,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ReactElement } from 'react';
2
+ /**
3
+ * Something is on its way. With `rows`, grey placeholder rows where a list will be, so
4
+ * the page keeps its shape; without, a small spinner and what is being waited for. The
5
+ * label is always there for assistive technology.
6
+ */
7
+ export declare function Loading(props: {
8
+ label: string;
9
+ rows?: number | boolean;
10
+ }): ReactElement;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ const DEFAULT_ROWS = 6;
3
+ /**
4
+ * Something is on its way. With `rows`, grey placeholder rows where a list will be, so
5
+ * the page keeps its shape; without, a small spinner and what is being waited for. The
6
+ * label is always there for assistive technology.
7
+ */
8
+ export function Loading(props) {
9
+ const { label, rows } = props;
10
+ if (rows) {
11
+ const count = rows === true ? DEFAULT_ROWS : rows;
12
+ return (_jsx("div", { className: "skeleton", role: "progressbar", "aria-label": label, "aria-busy": "true", children: Array.from({ length: count }, (_unused, index) => (_jsxs("div", { className: "skeleton-row", children: [_jsx("span", { className: "skeleton-box" }), _jsx("span", { className: "skeleton-line" }), _jsx("span", { className: "skeleton-line short" })] }, index))) }));
13
+ }
14
+ return (_jsxs("div", { className: "loading", role: "progressbar", "aria-label": label, "aria-busy": "true", children: [_jsx("span", { className: "spinner", "aria-hidden": "true" }), _jsxs("span", { "aria-hidden": "true", children: [label, "\u2026"] })] }));
15
+ }
16
+ //# sourceMappingURL=Loading.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Loading.js","sourceRoot":"","sources":["../src/Loading.tsx"],"names":[],"mappings":";AAEA,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,KAAiD;IACvE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IAC9B,IAAI,IAAI,EAAE,CAAC;QACT,MAAM,KAAK,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC;QAClD,OAAO,CACL,cAAK,SAAS,EAAC,UAAU,EAAC,IAAI,EAAC,aAAa,gBAAa,KAAK,eAAY,MAAM,YAC7E,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,CACjD,eAAiB,SAAS,EAAC,cAAc,aACvC,eAAM,SAAS,EAAC,cAAc,GAAG,EACjC,eAAM,SAAS,EAAC,eAAe,GAAG,EAClC,eAAM,SAAS,EAAC,qBAAqB,GAAG,KAHhC,KAAK,CAIT,CACP,CAAC,GACE,CACP,CAAC;IACJ,CAAC;IACD,OAAO,CACL,eAAK,SAAS,EAAC,SAAS,EAAC,IAAI,EAAC,aAAa,gBAAa,KAAK,eAAY,MAAM,aAC7E,eAAM,SAAS,EAAC,SAAS,iBAAa,MAAM,GAAG,EAC/C,+BAAkB,MAAM,aAAE,KAAK,cAAS,IACpC,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ReactElement } from 'react';
2
+ /**
3
+ * A search box for a list. `onSearch` is called with the trimmed phrase once typing
4
+ * pauses, and at once when the box is emptied.
5
+ */
6
+ export declare function SearchBox(props: {
7
+ label: string;
8
+ placeholder: string;
9
+ onSearch: (phrase: string) => void;
10
+ }): ReactElement;
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useState } from 'react';
3
+ /** How long typing must pause before the search is made: one request, not one a letter. */
4
+ const PAUSE_MS = 300;
5
+ /**
6
+ * A search box for a list. `onSearch` is called with the trimmed phrase once typing
7
+ * pauses, and at once when the box is emptied.
8
+ */
9
+ export function SearchBox(props) {
10
+ const { label, placeholder, onSearch } = props;
11
+ const [text, setText] = useState('');
12
+ useEffect(() => {
13
+ const phrase = text.trim();
14
+ if (phrase === '') {
15
+ onSearch('');
16
+ return undefined;
17
+ }
18
+ const timer = window.setTimeout(() => onSearch(phrase), PAUSE_MS);
19
+ return () => window.clearTimeout(timer);
20
+ }, [text, onSearch]);
21
+ return (_jsx("input", { type: "search", className: "search-box", "aria-label": label, placeholder: placeholder, value: text, onChange: (event) => setText(event.target.value) }));
22
+ }
23
+ //# sourceMappingURL=SearchBox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SearchBox.js","sourceRoot":"","sources":["../src/SearchBox.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG5C,2FAA2F;AAC3F,MAAM,QAAQ,GAAG,GAAG,CAAC;AAErB;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,KAIzB;IACC,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC/C,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACrC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC3B,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;YAClB,QAAQ,CAAC,EAAE,CAAC,CAAC;YACb,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC;QAClE,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IACrB,OAAO,CACL,gBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,YAAY,gBACV,KAAK,EACjB,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,IAAI,EACX,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAChD,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,47 @@
1
+ import type { ReactElement } from 'react';
2
+ /** What PlanControls shows of one organization. */
3
+ export interface PlanControlsOrganization {
4
+ id: string;
5
+ plan: {
6
+ code: string;
7
+ name: string;
8
+ /** The gateway charging for the plan, if one is. */
9
+ paidThrough: string | null;
10
+ /** The last day of a plan an administrator assigned. */
11
+ assignedUntil: string | null;
12
+ };
13
+ /** Its own number of stores, set here, and its plan's; null: none set, or no cap. */
14
+ storeLimit: {
15
+ own: number | null;
16
+ plan: number | null;
17
+ };
18
+ /** What it may start now, by feature. */
19
+ features: Record<string, boolean>;
20
+ /** The features decided here, whatever its plan says. */
21
+ overrides: string[];
22
+ }
23
+ /**
24
+ * What an administrator can change for one organization: the plan it is on, without
25
+ * payment, its number of stores, and which kinds of work it may start. Off stops new work
26
+ * only; what is under way finishes. Each change goes through the app's own handler, which
27
+ * reads the organization again when it is done.
28
+ */
29
+ export declare function PlanControls(props: {
30
+ organization: PlanControlsOrganization;
31
+ /** The plans it can be put on; while they load, its own. */
32
+ plans: {
33
+ code: string;
34
+ name: string;
35
+ }[] | undefined;
36
+ /** The features an administrator may switch, in words and in the order shown. */
37
+ features: Record<string, string>;
38
+ onAssignPlan(input: {
39
+ planCode: string;
40
+ until?: string;
41
+ }): Promise<unknown>;
42
+ onSetFeature(change: {
43
+ feature: string;
44
+ enabled: boolean | null;
45
+ }): Promise<unknown>;
46
+ onSetStoreLimit(limit: number | null): Promise<unknown>;
47
+ }): ReactElement;
@@ -0,0 +1,39 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useMutation } from '@tanstack/react-query';
3
+ import { useState } from 'react';
4
+ /**
5
+ * What an administrator can change for one organization: the plan it is on, without
6
+ * payment, its number of stores, and which kinds of work it may start. Off stops new work
7
+ * only; what is under way finishes. Each change goes through the app's own handler, which
8
+ * reads the organization again when it is done.
9
+ */
10
+ export function PlanControls(props) {
11
+ const { organization, features: featureNames } = props;
12
+ const [planCode, setPlanCode] = useState(organization.plan.code);
13
+ const [until, setUntil] = useState('');
14
+ const assign = useMutation({
15
+ mutationFn: () => props.onAssignPlan({ planCode, ...(until ? { until } : {}) }),
16
+ });
17
+ const [stores, setStores] = useState('');
18
+ const storeLimit = useMutation({
19
+ mutationFn: (limit) => props.onSetStoreLimit(limit),
20
+ onSuccess: () => setStores(''),
21
+ });
22
+ const feature = useMutation({
23
+ mutationFn: (change) => props.onSetFeature(change),
24
+ });
25
+ const { paidThrough, assignedUntil } = organization.plan;
26
+ const nameOf = (name) => featureNames[name] ?? name;
27
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "detail-card", children: [_jsx("h3", { className: "eyebrow", children: "Plan" }), _jsxs("p", { children: [_jsx("strong", { children: organization.plan.name }), _jsxs("span", { className: "muted", children: [assignedUntil && ` · assigned until ${assignedUntil}`, paidThrough && ` · paid through ${paidThrough}`, !assignedUntil && !paidThrough && ' · no end date'] })] }), paidThrough ? (_jsx("p", { className: "muted", children: "The plan can be changed here once that subscription has ended: changing it now would leave the organization charged for a plan it is no longer on." })) : (_jsxs("form", { className: "plan-form", onSubmit: (event) => {
28
+ event.preventDefault();
29
+ assign.mutate();
30
+ }, children: [_jsxs("label", { children: ["Plan", _jsx("select", { value: planCode, onChange: (event) => setPlanCode(event.target.value), children: (props.plans ?? [organization.plan]).map((plan) => (_jsx("option", { value: plan.code, children: plan.name }, plan.code))) })] }), _jsxs("label", { children: ["Until (optional)", _jsx("input", { type: "date", value: until, onChange: (event) => setUntil(event.target.value) })] }), _jsx("button", { type: "submit", className: "primary", disabled: assign.isPending, children: "Change plan" })] })), !paidThrough && (_jsx("p", { className: "muted small", children: "No payment is taken. With no day chosen it holds for a month." })), assign.isSuccess && _jsx("p", { role: "status", children: "The plan was changed. No payment was taken." }), assign.error && _jsx("p", { role: "alert", children: assign.error.message }), _jsx("p", { className: "muted small", children: organization.storeLimit.own === null
31
+ ? `Its plan allows ${organization.storeLimit.plan ?? 'any number of'} ${organization.storeLimit.plan === 1 ? 'store' : 'stores'}.`
32
+ : `${organization.storeLimit.own} ${organization.storeLimit.own === 1 ? 'store' : 'stores'}, set here; its plan allows ${organization.storeLimit.plan ?? 'any number'}.` }), _jsxs("form", { className: "plan-form", onSubmit: (event) => {
33
+ event.preventDefault();
34
+ const limit = Number(stores);
35
+ if (Number.isInteger(limit) && limit > 0)
36
+ storeLimit.mutate(limit);
37
+ }, children: [_jsxs("label", { children: ["Stores allowed", _jsx("input", { type: "number", min: 1, step: 1, required: true, value: stores, onChange: (event) => setStores(event.target.value) })] }), _jsx("button", { type: "submit", disabled: storeLimit.isPending, children: "Set stores" }), organization.storeLimit.own !== null && (_jsx("button", { type: "button", className: "quiet", disabled: storeLimit.isPending, "aria-label": "Use the plan's store limit", onClick: () => storeLimit.mutate(null), children: "Use the plan's" }))] }), storeLimit.error && _jsx("p", { role: "alert", children: storeLimit.error.message })] }), _jsxs("div", { className: "detail-card", children: [_jsx("h3", { className: "eyebrow", children: "Features" }), _jsx("fieldset", { disabled: feature.isPending, "aria-label": "Features", children: Object.keys(featureNames).map((name) => (_jsxs("label", { children: [_jsx("input", { type: "checkbox", checked: organization.features[name] ?? true, onChange: (event) => feature.mutate({ feature: name, enabled: event.target.checked }) }), ' ', nameOf(name)] }, name))) }), organization.overrides.length > 0 && (_jsx("ul", { className: "plain lines", children: organization.overrides.map((name) => (_jsxs("li", { children: [_jsxs("span", { className: "muted small", children: [nameOf(name), " was decided here, whatever the plan says."] }), _jsx("button", { type: "button", className: "quiet", disabled: feature.isPending, "aria-label": `Use the plan's choice for ${nameOf(name)}`, onClick: () => feature.mutate({ feature: name, enabled: null }), children: "Use the plan's" })] }, name))) })), _jsx("p", { className: "muted small", children: "A box shows what the organization has now: what its plan includes, unless it was decided here. Off stops new work of that kind; what is under way finishes." }), feature.error && _jsx("p", { role: "alert", children: feature.error.message })] })] }));
38
+ }
39
+ //# sourceMappingURL=PlanControls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlanControls.js","sourceRoot":"","sources":["../../src/admin/PlanControls.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAsBjC;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,KAS5B;IACC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IACvD,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvC,MAAM,MA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"}
@@ -0,0 +1,2 @@
1
+ export { PlanControls } from './PlanControls.js';
2
+ export type { PlanControlsOrganization } from './PlanControls.js';
@@ -0,0 +1,2 @@
1
+ export { PlanControls } from './PlanControls.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { EmailSignInResponse } from '@haatlabs-core/auth-contracts';
2
+ import type { ReactElement } from 'react';
3
+ /** What the panel asks of an app's API client. */
4
+ export interface EmailSignInClient {
5
+ emailSignIn(): Promise<EmailSignInResponse>;
6
+ requestEmailSignInCode(input: {
7
+ email: string;
8
+ }): Promise<unknown>;
9
+ setEmailSignIn(input: {
10
+ email: string;
11
+ code: string;
12
+ }): Promise<EmailSignInResponse>;
13
+ }
14
+ /**
15
+ * A store installed from Shopify admin has no email to sign in to the dashboard with. This
16
+ * gives it one, once. Whoever reads email at that address can then sign in, so the address
17
+ * is not taken on trust: a code is sent to it, and the email is set when the code is given
18
+ * back.
19
+ */
20
+ export declare function EmailSignInPanel({ client }: {
21
+ client: EmailSignInClient;
22
+ }): ReactElement | null;
@@ -0,0 +1,66 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
3
+ import { SIGN_IN_CODE_DIGITS, SIGN_IN_CODE_MINUTES } from '@haatlabs-core/auth-contracts';
4
+ import { useEffect, useState } from 'react';
5
+ const KEY = ['email-sign-in'];
6
+ const CODE_LENGTH = SIGN_IN_CODE_DIGITS;
7
+ /**
8
+ * A store installed from Shopify admin has no email to sign in to the dashboard with. This
9
+ * gives it one, once. Whoever reads email at that address can then sign in, so the address
10
+ * is not taken on trust: a code is sent to it, and the email is set when the code is given
11
+ * back.
12
+ */
13
+ export function EmailSignInPanel({ client }) {
14
+ const queryClient = useQueryClient();
15
+ const current = useQuery({ queryKey: KEY, queryFn: () => client.emailSignIn() });
16
+ const [email, setEmail] = useState('');
17
+ const [code, setCode] = useState('');
18
+ /** The email a code was sent to; null while the email is still being typed. */
19
+ const [sentTo, setSentTo] = useState(null);
20
+ const suggested = current.data?.suggestedEmail;
21
+ // Shopify's email for the owner is a starting point; what they type replaces it.
22
+ useEffect(() => {
23
+ if (suggested)
24
+ setEmail((typed) => typed || suggested);
25
+ }, [suggested]);
26
+ const send = useMutation({
27
+ mutationFn: (to) => client.requestEmailSignInCode({ email: to }),
28
+ // Never asked again by itself: each ask counts against the address's allowance.
29
+ retry: false,
30
+ onSuccess: (_result, to) => {
31
+ setSentTo(to);
32
+ setCode('');
33
+ },
34
+ });
35
+ const confirm = useMutation({
36
+ mutationFn: () => client.setEmailSignIn({ email: sentTo ?? email, code }),
37
+ onSuccess: (result) => queryClient.setQueryData(KEY, result),
38
+ });
39
+ const onEmail = (event) => {
40
+ event.preventDefault();
41
+ // Read from the box itself: something may have filled it without the page hearing.
42
+ const typed = new FormData(event.currentTarget).get('email');
43
+ const to = (typeof typed === 'string' ? typed : email).trim();
44
+ setEmail(to);
45
+ confirm.reset();
46
+ send.mutate(to);
47
+ };
48
+ const onCode = (event) => {
49
+ event.preventDefault();
50
+ confirm.mutate();
51
+ };
52
+ if (!current.data) {
53
+ return current.error ? _jsx("p", { role: "alert", children: current.error.message }) : null;
54
+ }
55
+ const { dashboardUrl } = current.data;
56
+ const dashboard = (_jsx("a", { href: dashboardUrl, target: "_blank", rel: "noreferrer", children: dashboardUrl }));
57
+ return (_jsxs("section", { className: "panel", children: [_jsx("h2", { children: "Sign in outside Shopify" }), current.data.email ? (_jsxs("p", { children: ["Sign in at ", dashboard, " as ", _jsx("strong", { children: current.data.email }), " to work on this store without opening Shopify admin. There is no password: a code is emailed to that address each time."] })) : !current.data.canCreate ? (_jsxs("p", { className: "muted", children: ["Only the owner of this store's Shopify account can create an email sign-in for the dashboard at ", dashboard, ". Ask them to open the app here."] })) : sentTo === null ? (_jsxs(_Fragment, { children: [_jsxs("p", { className: "muted", children: ["Choose the email to sign in with at ", dashboard, ", to work on this store without opening Shopify admin. Anyone who can read that inbox will be able to sign in, and it cannot be changed from here later."] }), _jsxs("form", { onSubmit: onEmail, className: "fields stacked", children: [_jsxs("label", { children: ["Email", _jsx("input", { type: "email", name: "email", autoComplete: "email", required: true, value: email, onChange: (event) => setEmail(event.target.value) })] }), _jsx("button", { type: "submit", className: "primary", disabled: send.isPending, children: "Send a code" }), send.error && _jsx("p", { role: "alert", children: send.error.message })] })] })) : (_jsxs("form", { onSubmit: onCode, className: "fields stacked", children: [_jsxs("p", { children: ["We sent an ", CODE_LENGTH, "-digit code to ", _jsx("strong", { children: sentTo }), ". Enter it to show the address is yours. It works once, for ", SIGN_IN_CODE_MINUTES, " minutes."] }), _jsxs("label", { children: ["Code", _jsx("input", { inputMode: "numeric", autoComplete: "one-time-code", pattern: `[0-9]{${CODE_LENGTH}}`, maxLength: CODE_LENGTH, required: true, autoFocus: true, value: code, onChange: (event) => setCode(event.target.value.replace(/\D/g, '')) })] }), _jsx("button", { type: "submit", className: "primary", disabled: confirm.isPending, children: "Confirm email" }), confirm.error && _jsx("p", { role: "alert", children: confirm.error.message }), send.error && _jsx("p", { role: "alert", children: send.error.message }), _jsxs("p", { className: "row", children: [_jsx("button", { type: "button", className: "quiet", disabled: send.isPending, onClick: () => {
58
+ confirm.reset();
59
+ send.mutate(sentTo);
60
+ }, children: "Send a new code" }), _jsx("button", { type: "button", className: "quiet", onClick: () => {
61
+ confirm.reset();
62
+ send.reset();
63
+ setSentTo(null);
64
+ }, children: "Use another email" })] })] }))] }));
65
+ }
66
+ //# sourceMappingURL=EmailSignInPanel.js.map