@hanzo/crm 0.0.0-stage → 0.1.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 (109) hide show
  1. package/LICENSE-MIT +21 -0
  2. package/LICENSE.md +21 -0
  3. package/NOTICE +52 -0
  4. package/README.md +72 -2
  5. package/dist/CrmModule.d.ts +4 -0
  6. package/dist/CrmModule.d.ts.map +1 -0
  7. package/dist/CrmModule.js +78 -0
  8. package/dist/CrmModule.js.map +1 -0
  9. package/dist/crm/Access.d.ts +10 -0
  10. package/dist/crm/Access.d.ts.map +1 -0
  11. package/dist/crm/Access.js +35 -0
  12. package/dist/crm/Access.js.map +1 -0
  13. package/dist/crm/Actions.d.ts +38 -0
  14. package/dist/crm/Actions.d.ts.map +1 -0
  15. package/dist/crm/Actions.js +224 -0
  16. package/dist/crm/Actions.js.map +1 -0
  17. package/dist/crm/Create.d.ts +13 -0
  18. package/dist/crm/Create.d.ts.map +1 -0
  19. package/dist/crm/Create.js +64 -0
  20. package/dist/crm/Create.js.map +1 -0
  21. package/dist/crm/Import.d.ts +7 -0
  22. package/dist/crm/Import.d.ts.map +1 -0
  23. package/dist/crm/Import.js +94 -0
  24. package/dist/crm/Import.js.map +1 -0
  25. package/dist/crm/Record.d.ts +6 -0
  26. package/dist/crm/Record.d.ts.map +1 -0
  27. package/dist/crm/Record.js +257 -0
  28. package/dist/crm/Record.js.map +1 -0
  29. package/dist/crm/Records.d.ts +33 -0
  30. package/dist/crm/Records.d.ts.map +1 -0
  31. package/dist/crm/Records.js +277 -0
  32. package/dist/crm/Records.js.map +1 -0
  33. package/dist/crm/Timeline.d.ts +22 -0
  34. package/dist/crm/Timeline.d.ts.map +1 -0
  35. package/dist/crm/Timeline.js +117 -0
  36. package/dist/crm/Timeline.js.map +1 -0
  37. package/dist/crm/csv.d.ts +75 -0
  38. package/dist/crm/csv.d.ts.map +1 -0
  39. package/dist/crm/csv.js +300 -0
  40. package/dist/crm/csv.js.map +1 -0
  41. package/dist/crm/importer.d.ts +39 -0
  42. package/dist/crm/importer.d.ts.map +1 -0
  43. package/dist/crm/importer.js +147 -0
  44. package/dist/crm/importer.js.map +1 -0
  45. package/dist/crm/objects.d.ts +80 -0
  46. package/dist/crm/objects.d.ts.map +1 -0
  47. package/dist/crm/objects.js +167 -0
  48. package/dist/crm/objects.js.map +1 -0
  49. package/dist/crm/schema.d.ts +58 -0
  50. package/dist/crm/schema.d.ts.map +1 -0
  51. package/dist/crm/schema.js +175 -0
  52. package/dist/crm/schema.js.map +1 -0
  53. package/dist/crm/studio/Sequences.d.ts +4 -0
  54. package/dist/crm/studio/Sequences.d.ts.map +1 -0
  55. package/dist/crm/studio/Sequences.js +114 -0
  56. package/dist/crm/studio/Sequences.js.map +1 -0
  57. package/dist/crm/studio/logic.d.ts +32 -0
  58. package/dist/crm/studio/logic.d.ts.map +1 -0
  59. package/dist/crm/studio/logic.js +59 -0
  60. package/dist/crm/studio/logic.js.map +1 -0
  61. package/dist/crm/studio/style.d.ts +8 -0
  62. package/dist/crm/studio/style.d.ts.map +1 -0
  63. package/dist/crm/studio/style.js +21 -0
  64. package/dist/crm/studio/style.js.map +1 -0
  65. package/dist/crm/suppression.d.ts +11 -0
  66. package/dist/crm/suppression.d.ts.map +1 -0
  67. package/dist/crm/suppression.js +20 -0
  68. package/dist/crm/suppression.js.map +1 -0
  69. package/dist/index.d.ts +12 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +19 -0
  72. package/dist/index.js.map +1 -0
  73. package/dist/lib/base-data/api.d.ts +48 -0
  74. package/dist/lib/base-data/api.d.ts.map +1 -0
  75. package/dist/lib/base-data/api.js +2 -0
  76. package/dist/lib/base-data/api.js.map +1 -0
  77. package/dist/lib/base-data/client.d.ts +29 -0
  78. package/dist/lib/base-data/client.d.ts.map +1 -0
  79. package/dist/lib/base-data/client.js +76 -0
  80. package/dist/lib/base-data/client.js.map +1 -0
  81. package/dist/lib/base-data/fields.d.ts +103 -0
  82. package/dist/lib/base-data/fields.d.ts.map +1 -0
  83. package/dist/lib/base-data/fields.js +251 -0
  84. package/dist/lib/base-data/fields.js.map +1 -0
  85. package/dist/lib/base-data/html.d.ts +20 -0
  86. package/dist/lib/base-data/html.d.ts.map +1 -0
  87. package/dist/lib/base-data/html.js +49 -0
  88. package/dist/lib/base-data/html.js.map +1 -0
  89. package/dist/lib/base-data/query.d.ts +50 -0
  90. package/dist/lib/base-data/query.d.ts.map +1 -0
  91. package/dist/lib/base-data/query.js +220 -0
  92. package/dist/lib/base-data/query.js.map +1 -0
  93. package/dist/lib/crm.d.ts +374 -0
  94. package/dist/lib/crm.d.ts.map +1 -0
  95. package/dist/lib/crm.js +337 -0
  96. package/dist/lib/crm.js.map +1 -0
  97. package/dist/lib/host.d.ts +117 -0
  98. package/dist/lib/host.d.ts.map +1 -0
  99. package/dist/lib/host.js +43 -0
  100. package/dist/lib/host.js.map +1 -0
  101. package/dist/lib/live.d.ts +5 -0
  102. package/dist/lib/live.d.ts.map +1 -0
  103. package/dist/lib/live.js +63 -0
  104. package/dist/lib/live.js.map +1 -0
  105. package/dist/nav.d.ts +7 -0
  106. package/dist/nav.d.ts.map +1 -0
  107. package/dist/nav.js +18 -0
  108. package/dist/nav.js.map +1 -0
  109. package/package.json +58 -3
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hanzo AI, Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 hanzo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/NOTICE ADDED
@@ -0,0 +1,52 @@
1
+ ui
2
+ Copyright (c) 2023 Hanzo AI, Inc.
3
+
4
+ This product includes software from shadcn/ui (https://github.com/shadcn-ui/ui), licensed under MIT:
5
+
6
+ Copyright (c) 2023 shadcn
7
+
8
+ This product includes software derived from Hanzo Build v2
9
+ (https://github.com/hanzoai/build-v2), licensed under MIT:
10
+
11
+ Copyright (c) 2025 Hanzo AI, Inc.
12
+
13
+ which is derived from OSW Studio (https://github.com/o-stahl/osw-studio),
14
+ licensed under MIT:
15
+
16
+ Copyright (c) 2025 Otto Stahl
17
+
18
+ which is itself derived from DeepSite v2
19
+ (https://huggingface.co/spaces/enzostvs/deepsite), by enzostvs and the
20
+ DeepSite authors, licensed under MIT.
21
+
22
+ The derived files are the builder workspace in pkg/ui/src/agents:
23
+ Workspace, Choice, FileTree, FileTabs, PreviewFrame, Console, Suggestions,
24
+ Attachments and Feedback (.tsx), and tree, log and bridge (.ts). The MIT
25
+ permission notice that governs them is the one in LICENSE-MIT.
26
+
27
+ This product includes software derived from Twenty's twenty-ui package
28
+ (https://github.com/twentyhq/twenty, packages/twenty-ui, commit
29
+ dd7099a02f83ddc021231b71d5344d3b83f4cf7d), licensed under MIT:
30
+
31
+ Copyright (c) 2023-present Twenty.com, PBC
32
+
33
+ The derived parts are the record kit, held in pkg/ui/src/backends/gui (its
34
+ record-density parts), pkg/ui/src/product, pkg/ui/src/settings, the record
35
+ motion in pkg/ui/src/motion.tsx and pkg/ui/src/styles/motion.css,
36
+ pkg/data/src and pkg/tokens/src/data.ts. Each re-expresses a twenty-ui
37
+ component's props, states and measured values on @hanzo/gui; no twenty-ui
38
+ source, stylesheet or asset is copied. "Twenty" and the Twenty logo are
39
+ trademarks of Twenty.com, PBC and are not licensed; neither appears in this
40
+ product.
41
+
42
+ This product includes the colour scales of Radix Colors
43
+ (https://github.com/radix-ui/colors), licensed under MIT:
44
+
45
+ Copyright (c) 2021 Radix
46
+
47
+ They are the data palette in pkg/tokens/src/data.ts: twenty of its
48
+ twenty-one pickable hues and all five tinted neutrals are Radix Colors 3.0.0
49
+ scales (its `blue` is Radix indigo, its `teal` Radix teal), as twenty-ui ships
50
+ them, converted from display-p3 to sRGB. Its `gray` is twenty-ui's own.
51
+
52
+ The MIT permission notice that governs both is the one in LICENSE-MIT.
package/README.md CHANGED
@@ -1,3 +1,73 @@
1
- # Temporary Holding Version
1
+ # @hanzo/crm
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
+ Hanzo CRM: the org's people, companies, sales pipeline, fundraising, tasks, lists,
4
+ candidates and sequences, kept in the org's own Base (hanzoai/base module `crm`).
5
+
6
+ It is one CRM drawn by every app that has one:
7
+
8
+ - Hanzo Cloud's console, at `console.<brand>/crm`, and as Hanzo CRM on `crm.<brand>`
9
+ - Hanzo Team, at `hanzo.team/crm`
10
+
11
+ Every app reads and writes the same records, because the records are the org's
12
+ Base and nothing else. What differs between apps is only what each one knows about
13
+ itself, and the app supplies that through `configureCrm`.
14
+
15
+ ## Use
16
+
17
+ ```tsx
18
+ import { configureCrm, CrmModule } from '@hanzo/crm'
19
+
20
+ configureCrm({
21
+ // Plain-JSON REST over the signed-in account's credential, in the org.
22
+ // A refusal rejects with an Error carrying the HTTP `status` (and `body`).
23
+ v1Url: (path) => `https://api.hanzo.ai/v1/${path}`,
24
+ get: (url) => rest('GET', url),
25
+ post: (url, body) => rest('POST', url, body),
26
+ del: (url) => rest('DELETE', url),
27
+ // The org's Base (/v1/base), signed the same way.
28
+ base: () => myBaseClient,
29
+ org: () => currentOrg,
30
+ leaveOrg: () => switchToOwnOrg(),
31
+ brand: () => ({ brandName: 'Hanzo', websiteUrl: 'https://hanzo.ai' }),
32
+ // True on the crm face: the org's `crm` enablement is read first, and an org
33
+ // without it is shown how to join the beta.
34
+ gated: false,
35
+ // React hooks over the app's own session, router and address.
36
+ useSession: () => ({ account, signOut }),
37
+ useRouter: () => ({ push, replace }),
38
+ useSearchParams: () => searchParams,
39
+ })
40
+
41
+ // Where the CRM goes: /crm/:tab and /crm/:tab/:id.
42
+ <CrmModule params={{ tab, id }} />
43
+ ```
44
+
45
+ `OBJECTS` and `TABS` list the objects in order, for an app's own navigation, and
46
+ `objectOf` / `movedView` say where an older address lands.
47
+
48
+ The CRM writes console-style addresses (`/crm`, `/crm/companies`,
49
+ `/crm/deals/<id>`, `?view=`). An app whose CRM lives somewhere else maps them in its
50
+ `useRouter`.
51
+
52
+ ## Requests
53
+
54
+ | What | Route |
55
+ | --- | --- |
56
+ | Records, schemas | `GET/POST/PATCH/DELETE /v1/base/collections/:name[/records[/:id]]` (through `base`) |
57
+ | Grow the org's CRM | `POST /v1/base/modules/crm` |
58
+ | The beta | `GET /v1/entitlement/orgs/:org` |
59
+ | Mail | `POST /v1/email`, `POST /v1/email/verify`, `POST /v1/marketing/mail` |
60
+ | Sequences | `/v1/marketing/sequences[/:id[/steps,/status,/enroll,/enrollments]]` |
61
+ | Audiences, suppressions | `/v1/marketing/audiences`, `/v1/marketing/suppressions[/check]` |
62
+
63
+ ## Develop
64
+
65
+ ```sh
66
+ pnpm --filter @hanzo/crm typecheck
67
+ pnpm --filter @hanzo/crm test
68
+ pnpm --filter @hanzo/crm build
69
+ ```
70
+
71
+ The suites are the CRM's logic in plain Node (Base field and value mapping, view
72
+ queries, CSV and import plans, the objects and their views, mail and suppression
73
+ reads over a host's REST).
@@ -0,0 +1,4 @@
1
+ export declare function CrmModule({ params }: {
2
+ params: Record<string, string>;
3
+ }): import("react").JSX.Element;
4
+ //# sourceMappingURL=CrmModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CrmModule.d.ts","sourceRoot":"","sources":["../src/CrmModule.tsx"],"names":[],"mappings":"AAoCA,wBAAgB,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,+BASvE"}
@@ -0,0 +1,78 @@
1
+ 'use client';
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * CRM — the org's people, companies, sales pipeline, fundraising, tasks, lists and
5
+ * sequences, kept in the org's own Base (hanzoai/base module `crm`).
6
+ *
7
+ * /crm People: everyone the org knows, investors and customers alike
8
+ * /crm/companies firms, investor firms among them
9
+ * /crm/deals the sales pipeline, a board by stage
10
+ * /crm/fundraising the round, a board by stage: intro, meeting, diligence, term sheet, closed
11
+ * /crm/tasks what is to be done, and for whom
12
+ * /crm/lists who outreach goes to: lists made by hand, from a view, or from a file
13
+ * /crm/sequences the cloud's drip: steps, who is enrolled, where each walk stands
14
+ * /crm/candidates hiring
15
+ * /crm/:tab/:id one record and its timeline
16
+ *
17
+ * Every table is the server's: the view is a Base query and the browser holds one
18
+ * page (crm/Records). On the crm face (crm.<brand>, where the host is `gated`) the CRM
19
+ * is a product any account opens in its own org, and a beta: `BetaGate` reads the
20
+ * org's `crm` enablement first and shows `BetaScreen` to an org without it; a read
21
+ * the engine refuses is `NoRole`.
22
+ */
23
+ import { useCallback, useEffect, useState } from 'react';
24
+ import { Spinner, Text, YStack } from '@hanzo/gui';
25
+ import { BackendStateCard, classifyBackend } from '@hanzo/ui/product';
26
+ import { CrmApi } from './lib/crm.js';
27
+ import { currentOrg, host, useRouter, useSearchParams } from './lib/host.js';
28
+ import { BetaScreen, NoRole } from './crm/Access.js';
29
+ import { movedView, objectOf } from './crm/objects.js';
30
+ import { Records } from './crm/Records.js';
31
+ import { RecordPage } from './crm/Record.js';
32
+ import { Sequences } from './crm/studio/Sequences.js';
33
+ export function CrmModule({ params }) {
34
+ // The crm face (crm.<brand>) opens the CRM behind its beta; the host says whether this is one.
35
+ return host().gated ? (_jsx(BetaGate, { children: _jsx(Crm, { params: params }) })) : (_jsx(Crm, { params: params }));
36
+ }
37
+ /**
38
+ * The crm face's door: the org's `crm` enablement, read once before any CRM call. An
39
+ * org that has it gets the CRM; one that has not gets `BetaScreen`, which checks again
40
+ * on request, so an account back from applying opens it without a reload. An account
41
+ * the read refuses does not act in the org at all and gets `NoRole`.
42
+ */
43
+ function BetaGate({ children }) {
44
+ const org = currentOrg();
45
+ const [state, setState] = useState({ phase: 'loading' });
46
+ const check = useCallback(() => {
47
+ setState({ phase: 'loading' });
48
+ CrmApi.beta(org)
49
+ .then((data) => setState({ phase: 'ready', data }))
50
+ .catch((e) => setState({ phase: 'error', error: classifyBackend(e) }));
51
+ }, [org]);
52
+ useEffect(() => {
53
+ check();
54
+ }, [check]);
55
+ if (state.phase === 'loading') {
56
+ return (_jsx(YStack, { flex: 1, minH: "60vh", items: "center", justify: "center", children: _jsx(Spinner, { size: "large", color: "$color11" }) }));
57
+ }
58
+ if (state.phase === 'error') {
59
+ return state.error.kind === 'access' ? _jsx(NoRole, { org: org }) : _jsx(BackendStateCard, { state: state.error, onRetry: check, hint: "endpoint \u00B7 GET /v1/entitlement/orgs/:org" });
60
+ }
61
+ return state.data ? _jsx(_Fragment, { children: children }) : _jsx(BetaScreen, { org: org, onCheck: check });
62
+ }
63
+ function Crm({ params }) {
64
+ const router = useRouter();
65
+ const tab = (params.tab ?? '').toLowerCase();
66
+ const obj = objectOf(tab);
67
+ const named = useSearchParams()?.get('view') ?? null;
68
+ // An address from before the CRM was one table per object lands on what replaced it,
69
+ // and on the view that was that table (/crm/customers is People's Customers).
70
+ useEffect(() => {
71
+ if (!obj || !tab || tab === obj.id || params.id)
72
+ return;
73
+ const view = movedView(tab);
74
+ router.replace(`/crm/${obj.id === 'people' ? '' : obj.id}${view ? `?view=${view}` : ''}`);
75
+ }, [obj, tab, params.id, router]);
76
+ return (_jsx(YStack, { p: "$4", $sm: { p: '$2' }, gap: "$4", width: "100%", maxW: 1600, mx: "auto", "data-slot": "crm", children: tab === 'sequences' ? (_jsxs(YStack, { gap: "$3", children: [_jsx(Text, { fontSize: "$7", fontWeight: "700", color: "$color12", children: "Sequences" }), _jsx(Text, { fontSize: "$3", color: "$color10", children: "A sequence is a series of emails, each sent a delay after the last. Enroll people from People or a list; every step goes through the org's suppression list, and the unsubscribe link in each one is honoured." }), _jsx(Sequences, { openId: params.id ?? null })] })) : !obj ? (_jsx(BackendStateCard, { state: classifyBackend(new Error(`The CRM has no "${tab}".`)), hint: "crm" })) : params.id ? (_jsx(RecordPage, { obj: obj, id: params.id }, `${obj.id}/${params.id}`)) : (_jsx(Records, { obj: obj, view: named ?? movedView(tab) }, `${obj.id}:${named ?? movedView(tab) ?? ''}`)) }));
77
+ }
78
+ //# sourceMappingURL=CrmModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CrmModule.js","sourceRoot":"","sources":["../src/CrmModule.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AACxE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAqB,MAAM,mBAAmB,CAAA;AAExF,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAIlD,MAAM,UAAU,SAAS,CAAC,EAAE,MAAM,EAAsC;IACtE,+FAA+F;IAC/F,OAAO,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CACpB,KAAC,QAAQ,cACP,KAAC,GAAG,IAAC,MAAM,EAAE,MAAM,GAAI,GACd,CACZ,CAAC,CAAC,CAAC,CACF,KAAC,GAAG,IAAC,MAAM,EAAE,MAAM,GAAI,CACxB,CAAA;AACH,CAAC;AAED;;;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AAE,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,EAAC,IAAI,EAAC,KAAK,EAAC,MAAM,EAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAC,MAAM,eAAW,KAAK,YACzF,GAAG,KAAK,WAAW,CAAC,CAAC,CAAC,CACrB,MAAC,MAAM,IAAC,GAAG,EAAC,IAAI,aACd,KAAC,IAAI,IAAC,QAAQ,EAAC,IAAI,EAAC,UAAU,EAAC,KAAK,EAAC,KAAK,EAAC,UAAU,0BAE9C,EACP,KAAC,IAAI,IAAC,QAAQ,EAAC,IAAI,EAAC,KAAK,EAAC,UAAU,YACjC,gNAAgN,GAC5M,EACP,KAAC,SAAS,IAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,IAAI,GAAI,IACjC,CACV,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CACT,KAAC,gBAAgB,IAAC,KAAK,EAAE,eAAe,CAAC,IAAI,KAAK,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC,EAAE,IAAI,EAAC,KAAK,GAAG,CAC/F,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CACd,KAAC,UAAU,IAAgC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,IAAjD,GAAG,GAAG,CAAC,EAAE,IAAI,MAAM,CAAC,EAAE,EAAE,CAA6B,CACvE,CAAC,CAAC,CAAC,CACF,KAAC,OAAO,IAAoD,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,IAAI,SAAS,CAAC,GAAG,CAAC,IAArF,GAAG,GAAG,CAAC,EAAE,IAAI,KAAK,IAAI,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAA6C,CACxG,GACM,CACV,CAAA;AACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ /** The brand's beta application, opened on its beta tester program. */
2
+ export declare const betaUrl: () => string;
3
+ export declare function BetaScreen({ org, onCheck }: {
4
+ org: string;
5
+ onCheck: () => void;
6
+ }): import("react").JSX.Element;
7
+ export declare function NoRole({ org }: {
8
+ org: string;
9
+ }): import("react").JSX.Element;
10
+ //# sourceMappingURL=Access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Access.d.ts","sourceRoot":"","sources":["../../src/crm/Access.tsx"],"names":[],"mappings":"AAqBA,uEAAuE;AACvE,eAAO,MAAM,OAAO,QAAO,MAAsD,CAAA;AAYjF,wBAAgB,UAAU,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,+BAwBhF;AAED,wBAAgB,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,+BAqB9C"}
@@ -0,0 +1,35 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * What crm.<brand> answers an account it does not open for. The CRM is a beta, and
5
+ * whether an org has it is the server's: the `crm` enablement, which every CRM call
6
+ * asks (cloud apps/framework elective) and which this face reads once to pick the
7
+ * screen (`CrmApi.beta`). Neither card makes a CRM call.
8
+ *
9
+ * - `BetaScreen` — the org has not joined the beta: join it on the brand's site,
10
+ * signed in, and the CRM opens here with no other step.
11
+ * - `NoRole` — this account's role in the org does not reach its CRM: the CRM's own
12
+ * reads refuse it, or cloud does not let it act in the org at all (a plain member
13
+ * of an org the platform runs, such as hanzo, acts in none of it).
14
+ * The account may still have the CRM in an org of its own, so the card opens the
15
+ * organization list, where one is chosen or created.
16
+ */
17
+ import { Button, Text, XStack, YStack } from '@hanzo/gui';
18
+ import { Card } from '@hanzo/ui';
19
+ import { getBrand, leaveOrg, useSession } from '../lib/host.js';
20
+ /** The brand's beta application, opened on its beta tester program. */
21
+ export const betaUrl = () => `${getBrand().websiteUrl}/beta?program=beta`;
22
+ function Frame({ children }) {
23
+ return (_jsx(YStack, { flex: 1, minH: "60vh", items: "center", justify: "center", p: "$6", children: _jsx(Card, { p: "$6", gap: "$3", maxW: 480, width: "100%", borderWidth: 1, borderColor: "$borderColor", role: "status", children: children }) }));
24
+ }
25
+ export function BetaScreen({ org, onCheck }) {
26
+ const name = getBrand().brandName.replace(/\s+Cloud$/, '');
27
+ const { signOut } = useSession();
28
+ return (_jsxs(Frame, { children: [_jsx(Text, { fontSize: "$7", fontWeight: "700", color: "$color12", children: `${name} CRM is in beta` }), _jsx(Text, { fontSize: "$3", color: "$color11", children: `Join the beta to open it for ${org}. Apply while signed in to this account, and the CRM opens here as soon as you come back.` }), _jsxs(XStack, { gap: "$2", flexWrap: "wrap", pt: "$2", children: [_jsx(Button, { size: "$3", theme: "accent", onPress: () => window.location.assign(betaUrl()), children: "Join the beta" }), _jsx(Button, { size: "$3", chromeless: true, onPress: onCheck, children: "I have joined" }), _jsx(Button, { size: "$3", chromeless: true, onPress: () => void signOut(), children: "Sign out" })] })] }));
29
+ }
30
+ export function NoRole({ org }) {
31
+ const name = getBrand().brandName.replace(/\s+Cloud$/, '');
32
+ const { signOut } = useSession();
33
+ return (_jsxs(Frame, { children: [_jsx(Text, { fontSize: "$7", fontWeight: "700", color: "$color12", children: `${name} CRM` }), _jsx(Text, { fontSize: "$3", color: "$color11", children: `Your role in ${org} does not open its CRM. Ask an admin of ${org} for one, or open the CRM in an organization of your own.` }), _jsxs(XStack, { gap: "$2", flexWrap: "wrap", pt: "$2", children: [_jsx(Button, { size: "$3", theme: "accent", onPress: () => leaveOrg(), children: "Choose an organization" }), _jsx(Button, { size: "$3", chromeless: true, onPress: () => void signOut(), children: "Sign out" })] })] }));
34
+ }
35
+ //# sourceMappingURL=Access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Access.js","sourceRoot":"","sources":["../../src/crm/Access.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,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,KAAK,OAAO,EAAE,yBAEjD,IACF,IACH,CACT,CAAA;AACH,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { SelectOption } from '@hanzo/data';
2
+ import type { BaseRecord } from '../lib/base-data/api.js';
3
+ import type { BaseQuery } from '../lib/base-data/query.js';
4
+ import type { CrmObject } from './objects.js';
5
+ import { type Schema } from './schema.js';
6
+ /** At most this many rows go into one export or one action over a whole view. */
7
+ export declare const MOST = 50000;
8
+ /** The selected rows' actions. */
9
+ export declare function Bulk({ obj, schema, ids, raw, onDone }: {
10
+ obj: CrmObject;
11
+ schema: Schema;
12
+ ids: string[];
13
+ raw: Map<string, BaseRecord>;
14
+ onDone: () => void;
15
+ }): import("react").JSX.Element;
16
+ /** Actions over every row the view admits, and the way in for a file. */
17
+ export declare function Everyone({ obj, schema, query, total, onDone }: {
18
+ obj: CrmObject;
19
+ schema: Schema;
20
+ query: () => BaseQuery;
21
+ total: number;
22
+ onDone: () => void;
23
+ }): import("react").JSX.Element;
24
+ /** A CRM installed before a field this table reads: an admin grows it in one press. */
25
+ export declare function Grow({ admin, what, quiet, onGrown }: {
26
+ admin: boolean;
27
+ what: string;
28
+ quiet?: boolean;
29
+ onGrown: () => void;
30
+ }): import("react").JSX.Element;
31
+ /** A native select, labelled: one control a phone and a keyboard both drive. */
32
+ export declare function Picker({ label, value, onChange, options }: {
33
+ label: string;
34
+ value: string;
35
+ onChange: (v: string) => void;
36
+ options: SelectOption[];
37
+ }): import("react").JSX.Element;
38
+ //# sourceMappingURL=Actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Actions.d.ts","sourceRoot":"","sources":["../../src/crm/Actions.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAmB,YAAY,EAAE,MAAM,aAAa,CAAA;AAGhE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAEvD,OAAO,KAA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;IAAC,OAAO,EAAE,YAAY,EAAE,CAAA;CAAE,+BAoBnJ"}
@@ -0,0 +1,224 @@
1
+ 'use client';
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * What a person does to many records at once: to the rows they chose (`Bulk`), or
5
+ * to every row the view admits (`Everyone`) — export them, put them on a list,
6
+ * enroll them in a sequence, set a field, opt them out, delete them. Every write
7
+ * is one request per record, six at a time, and the dialog counts what happened:
8
+ * nothing is said to have happened that the server did not answer.
9
+ *
10
+ * Enrolling hands addresses to the cloud's drip (apps/marketing). It sends nothing
11
+ * itself: each step goes through the org's suppression gate when it comes due, so
12
+ * an address that opted out is enrolled and never mailed.
13
+ */
14
+ import { useEffect, useState } from 'react';
15
+ import { Button, Input, Text, XStack, YStack } from '@hanzo/gui';
16
+ import { Dialog, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@hanzo/ui';
17
+ import { ApiError } from '../lib/host.js';
18
+ import { CrmApi } from '../lib/crm.js';
19
+ import { cellText, toCsv } from './csv.js';
20
+ import { Import } from './Import.js';
21
+ import { expandOf, pool, rowOf, save, words } from './schema.js';
22
+ import { inputStyle } from './studio/style.js';
23
+ /** At most this many rows go into one export or one action over a whole view. */
24
+ export const MOST = 50_000;
25
+ const LABEL = {
26
+ export: 'Export CSV',
27
+ list: 'Add to list',
28
+ enroll: 'Enroll in sequence',
29
+ set: 'Set a field',
30
+ optout: 'Opt out',
31
+ delete: 'Delete',
32
+ };
33
+ /** The actions an object offers on many records. */
34
+ function actsFor(obj) {
35
+ if (obj.collection === 'people')
36
+ return ['export', 'list', 'enroll', 'set', 'optout', 'delete'];
37
+ if (obj.collection === 'views')
38
+ return ['delete'];
39
+ return ['export', 'set', 'delete'];
40
+ }
41
+ /** The selected rows' actions. */
42
+ export function Bulk({ obj, schema, ids, raw, onDone }) {
43
+ const [act, setAct] = useState(null);
44
+ const records = () => Promise.resolve(ids.map((id) => raw.get(id) ?? { id }));
45
+ return (_jsxs(_Fragment, { children: [actsFor(obj).map((a) => (_jsx(Button, { size: "$2", theme: a === 'delete' ? 'red' : undefined, onPress: () => setAct(a), children: LABEL[a] }, a))), act ? _jsx(Run, { act: act, obj: obj, schema: schema, count: ids.length, records: records, onClose: () => setAct(null), onDone: onDone }) : null] }));
46
+ }
47
+ /** Actions over every row the view admits, and the way in for a file. */
48
+ export function Everyone({ obj, schema, query, total, onDone }) {
49
+ const [act, setAct] = useState(null);
50
+ const [importing, setImporting] = useState(false);
51
+ const records = (fields) => {
52
+ const q = query();
53
+ return CrmApi.each(obj.collection, { filter: q.filter || undefined, sort: q.sort || undefined, expand: fields ? undefined : expandOf(schema) || undefined, fields }, MOST);
54
+ };
55
+ const acts = actsFor(obj).filter((a) => a === 'export' || a === 'list' || a === 'enroll');
56
+ return (_jsxs(_Fragment, { children: [acts.map((a) => (_jsx(Button, { size: "$2", disabled: total === 0, onPress: () => setAct(a), children: a === 'export' ? 'Export' : a === 'list' ? 'Add all to list' : 'Enroll all' }, a))), obj.importable ? (_jsx(Button, { size: "$2", onPress: () => setImporting(true), children: "Import" })) : null, act ? (_jsx(Run, { act: act, obj: obj, schema: schema, count: Math.min(total, MOST), every: true, records: () => records(act === 'export' ? undefined : 'id,emails'), onClose: () => setAct(null), onDone: onDone })) : null, importing ? _jsx(Import, { obj: obj, onClose: () => setImporting(false), onDone: onDone }) : null] }));
57
+ }
58
+ /** A CRM installed before a field this table reads: an admin grows it in one press. */
59
+ export function Grow({ admin, what, quiet, onGrown }) {
60
+ const [state, setState] = useState('idle');
61
+ return (_jsxs(XStack, { items: "center", gap: "$3", p: quiet ? '$2' : '$4', rounded: "$4", borderWidth: 1, borderColor: "$borderColor", flexWrap: "wrap", "data-slot": "crm-grow", children: [_jsxs(Text, { fontSize: "$2", color: "$color11", flex: 1, minW: 200, children: [what, " ", admin ? '' : 'An admin of this org can update it.'] }), admin ? (_jsx(Button, { size: "$2", disabled: state === 'busy', onPress: async () => {
62
+ setState('busy');
63
+ try {
64
+ const { grew } = await CrmApi.grow();
65
+ if (!grew)
66
+ return setState('This cloud does not ship the update yet: nothing was added.');
67
+ setState('idle');
68
+ onGrown();
69
+ }
70
+ catch (e) {
71
+ setState(e instanceof ApiError && e.status === 404 ? 'This cloud does not ship the update yet.' : words(e, 'The CRM was not updated.'));
72
+ }
73
+ }, children: state === 'busy' ? 'Updating…' : 'Update the CRM' })) : null, state !== 'idle' && state !== 'busy' ? (_jsx(Text, { fontSize: "$2", color: "$red10", width: "100%", children: state })) : null] }));
74
+ }
75
+ /** The primary address a person record holds. */
76
+ const emailOf = (r) => {
77
+ const e = r.emails && typeof r.emails === 'object' ? r.emails.primaryEmail : '';
78
+ return typeof e === 'string' ? e.trim().toLowerCase() : '';
79
+ };
80
+ /** One action, asked for what it needs, run, and counted. */
81
+ function Run({ act, obj, schema, count, every, records, onClose, onDone }) {
82
+ const [progress, setProgress] = useState(null);
83
+ const [result, setResult] = useState(null);
84
+ const [busy, setBusy] = useState(false);
85
+ // what the action needs
86
+ const [lists, setLists] = useState(null);
87
+ const [listId, setListId] = useState('');
88
+ const [newList, setNewList] = useState('');
89
+ const [sequences, setSequences] = useState(null);
90
+ const [seqId, setSeqId] = useState('');
91
+ const selects = schema.fields.filter((f) => f.type === 'select' && !f.readOnly);
92
+ const [field, setField] = useState(selects[0]?.name ?? '');
93
+ const [value, setValue] = useState('');
94
+ useEffect(() => {
95
+ if (act === 'list') {
96
+ CrmApi.list('lists', { filter: 'object = "people" || object = ""', sort: '-created', perPage: 200, skipTotal: true })
97
+ .then((r) => setLists(r.items.map((x) => ({ value: String(x.id), label: String(x.name || x.id) }))))
98
+ .catch(() => setLists([]));
99
+ }
100
+ if (act === 'enroll')
101
+ CrmApi.marketing.listSequences().then(setSequences).catch(() => setSequences([]));
102
+ }, [act]);
103
+ const who = every ? `all ${count.toLocaleString()} ${obj.plural.toLowerCase()} in this view` : `${count.toLocaleString()} selected`;
104
+ const go = async () => {
105
+ setBusy(true);
106
+ setResult(null);
107
+ try {
108
+ setProgress({ n: 0, of: count, failed: 0 });
109
+ const rs = await records();
110
+ const tick = (n, failed) => setProgress({ n, of: rs.length, failed });
111
+ switch (act) {
112
+ case 'export': {
113
+ const full = rs.some((r) => !r.created && !r.updated) && !every ? await refetch(obj, schema, rs) : rs;
114
+ const header = schema.fields.map((f) => f.label);
115
+ const rows = full.map((r) => {
116
+ const row = rowOf(schema, r);
117
+ return schema.fields.map((f) => cellText(f, row[f.name]));
118
+ });
119
+ save(`${obj.id}-${new Date().toISOString().slice(0, 10)}.csv`, toCsv(['ID', ...header], rows.map((r, i) => [String(full[i].id), ...r])));
120
+ setResult(`Exported ${full.length.toLocaleString()} ${obj.plural.toLowerCase()}.`);
121
+ break;
122
+ }
123
+ case 'list': {
124
+ let list = listId;
125
+ if (!list) {
126
+ const name = newList.trim();
127
+ if (!name)
128
+ throw new Error('Choose a list, or name a new one.');
129
+ list = String((await CrmApi.create('lists', { name, object: 'people', purpose: 'outreach' })).id);
130
+ }
131
+ let added = 0;
132
+ let already = 0;
133
+ const r = await pool(rs, 6, async (p) => {
134
+ try {
135
+ await CrmApi.create('list_members', { list, person: p.id, source: every ? 'segment' : 'manual' });
136
+ added++;
137
+ }
138
+ catch (e) {
139
+ // A person is on a list once: the unique index refuses a second.
140
+ if (e instanceof ApiError && e.status === 400)
141
+ already++;
142
+ else
143
+ throw e;
144
+ }
145
+ }, tick);
146
+ setResult(`Added ${added.toLocaleString()} to the list${already ? `; ${already.toLocaleString()} were on it already` : ''}${r.failed ? `; ${r.failed} failed (${r.errors[0]})` : ''}.`);
147
+ break;
148
+ }
149
+ case 'enroll': {
150
+ if (!seqId)
151
+ throw new Error('Choose an active sequence.');
152
+ let enrolled = 0;
153
+ let already = 0;
154
+ let none = 0;
155
+ const r = await pool(rs, 6, async (p) => {
156
+ const address = emailOf(p);
157
+ if (!address)
158
+ return void none++;
159
+ const res = await CrmApi.marketing.enroll(seqId, { address });
160
+ enrolled += res.enrolled;
161
+ already += res.alreadyEnrolled;
162
+ }, tick);
163
+ setResult(`Enrolled ${enrolled.toLocaleString()}${already ? `; ${already.toLocaleString()} were enrolled already` : ''}${none ? `; ${none.toLocaleString()} have no email` : ''}${r.failed ? `; ${r.failed} failed (${r.errors[0]})` : ''}. Each step is sent when it comes due, never to an address that opted out.`);
164
+ break;
165
+ }
166
+ case 'set': {
167
+ if (!field || !value)
168
+ throw new Error('Choose a field and a value.');
169
+ const r = await pool(rs, 6, (x) => CrmApi.update(obj.collection, String(x.id), { [field]: value }).then(() => undefined), tick);
170
+ setResult(`Set ${schema.fields.find((f) => f.name === field)?.label ?? field} on ${(rs.length - r.failed).toLocaleString()}${r.failed ? `; ${r.failed} failed (${r.errors[0]})` : ''}.`);
171
+ break;
172
+ }
173
+ case 'optout': {
174
+ let out = 0;
175
+ let none = 0;
176
+ const stamp = schema.names.has('outreach');
177
+ const r = await pool(rs, 6, async (p) => {
178
+ const address = emailOf(p);
179
+ if (!address)
180
+ return void none++;
181
+ await CrmApi.marketing.addSuppression(address, 'opted out in the CRM');
182
+ if (stamp)
183
+ await CrmApi.update('people', String(p.id), { outreach: 'unsubscribed' });
184
+ out++;
185
+ }, tick);
186
+ setResult(`Opted out ${out.toLocaleString()}: no rail will mail them${none ? `; ${none} have no email` : ''}${r.failed ? `; ${r.failed} failed (${r.errors[0]})` : ''}.`);
187
+ break;
188
+ }
189
+ case 'delete': {
190
+ const r = await pool(rs, 6, (x) => CrmApi.remove(obj.collection, String(x.id)), tick);
191
+ setResult(`Deleted ${(rs.length - r.failed).toLocaleString()}${r.failed ? `; ${r.failed} failed (${r.errors[0]})` : ''}.`);
192
+ break;
193
+ }
194
+ }
195
+ onDone();
196
+ }
197
+ catch (e) {
198
+ setResult(words(e, 'That did not finish.'));
199
+ }
200
+ finally {
201
+ setBusy(false);
202
+ }
203
+ };
204
+ const body = act === 'list' ? (_jsxs(YStack, { gap: "$2", children: [_jsx(Picker, { label: "List", value: listId, onChange: setListId, options: [{ value: '', label: lists === null ? 'Reading lists…' : 'A new list' }, ...(lists ?? [])] }), listId ? null : _jsx(Input, { size: "$3", placeholder: "New list name", value: newList, onChangeText: setNewList, "aria-label": "New list name" })] })) : act === 'enroll' ? (_jsxs(YStack, { gap: "$2", children: [_jsx(Picker, { label: "Sequence", value: seqId, onChange: setSeqId, options: [
205
+ { value: '', label: sequences === null ? 'Reading sequences…' : 'Choose a sequence' },
206
+ ...(sequences ?? []).filter((s) => s.status === 'active').map((s) => ({ value: s.id, label: s.name })),
207
+ ] }), sequences && !sequences.some((s) => s.status === 'active') ? (_jsx(Text, { fontSize: "$2", color: "$color10", children: "No sequence is active. Make one in Sequences, add its steps, and set it active." })) : null] })) : act === 'set' ? (_jsxs(YStack, { gap: "$2", children: [_jsx(Picker, { label: "Field", value: field, onChange: (f) => { setField(f); setValue(''); }, options: selects.map((f) => ({ value: f.name, label: f.label })) }), _jsx(Picker, { label: "Value", value: value, onChange: setValue, options: [{ value: '', label: 'Choose a value' }, ...(selects.find((f) => f.name === field)?.metadata?.options ?? [])] })] })) : act === 'delete' ? (_jsx(Text, { fontSize: "$3", color: "$color11", children: "This removes them for everyone in the org. It cannot be undone." })) : act === 'optout' ? (_jsx(Text, { fontSize: "$3", color: "$color11", children: "Their addresses go on the org's suppression list: no sequence, send or rail will mail them again until an admin re-subscribes them." })) : null;
208
+ return (_jsx(Dialog, { open: true, onOpenChange: (o) => !o && !busy && onClose(), children: _jsxs(DialogContent, { children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: LABEL[act] }), _jsx(DialogDescription, { children: who })] }), _jsxs(DialogBody, { gap: "$3", children: [body, progress ? (_jsx(Text, { fontSize: "$2", color: "$color10", "data-slot": "crm-progress", children: `${progress.n.toLocaleString()} of ${progress.of.toLocaleString()}${progress.failed ? ` · ${progress.failed} failed` : ''}` })) : null, result ? (_jsx(Text, { fontSize: "$3", color: "$color12", "data-slot": "crm-result", children: result })) : null] }), _jsxs(DialogFooter, { children: [_jsx(Button, { size: "$3", chromeless: true, disabled: busy, onPress: onClose, children: result ? 'Close' : 'Cancel' }), result ? null : (_jsx(Button, { size: "$3", theme: act === 'delete' ? 'red' : 'blue', disabled: busy, onPress: () => void go(), children: busy ? 'Working…' : LABEL[act] }))] })] }) }));
209
+ }
210
+ /** The selected rows read again whole, with their relations, for an export. */
211
+ async function refetch(obj, schema, rs) {
212
+ const out = [];
213
+ for (let i = 0; i < rs.length; i += 50) {
214
+ const ids = rs.slice(i, i + 50).map((r) => `id = "${String(r.id).replace(/"/g, '')}"`);
215
+ const page = await CrmApi.list(obj.collection, { filter: ids.join(' || '), perPage: 50, expand: expandOf(schema) || undefined, skipTotal: true });
216
+ out.push(...page.items);
217
+ }
218
+ return out;
219
+ }
220
+ /** A native select, labelled: one control a phone and a keyboard both drive. */
221
+ export function Picker({ label, value, onChange, options }) {
222
+ return (_jsxs(YStack, { gap: "$1", children: [_jsx(Text, { fontSize: "$2", color: "$color10", children: label }), _jsx("select", { "aria-label": label, value: value, onChange: (e) => onChange(e.target.value), style: { ...inputStyle, height: 36 }, children: options.map((o) => (_jsx("option", { value: o.value, children: o.label }, o.value))) })] }));
223
+ }
224
+ //# sourceMappingURL=Actions.js.map