@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
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The studio's pure decisions, apart from React so they are tested alone: what one
3
+ * person's walk of a sequence says, a sequence's tally, how a step's delay reads, and
4
+ * the send time a form names.
5
+ */
6
+ import type { Enrollment, SequenceStep } from '../../lib/crm.js';
7
+ /**
8
+ * One person's state as the cloud reports it. A walk is `active` while a step is
9
+ * due; `completed` once its last step was taken — whether that send went out, was
10
+ * suppressed or failed is recorded by the cloud but not reported to the org, so
11
+ * the word is "taken", never "delivered".
12
+ */
13
+ export declare function walkState(e: Pick<Enrollment, 'status' | 'nextRunAt'>, now: number): string;
14
+ /** How many a sequence enrolled, how many are still due, taken, or canceled. */
15
+ export declare function tally(es: Pick<Enrollment, 'status'>[]): {
16
+ enrolled: number;
17
+ due: number;
18
+ taken: number;
19
+ canceled: number;
20
+ };
21
+ /** A step's delay in words: the first counts from enrollment, the rest from the step before. */
22
+ export declare function delayText(step: Pick<SequenceStep, 'idx' | 'delaySeconds'>): string;
23
+ /**
24
+ * The send time a `datetime-local` value names, in unix seconds; null for now (an
25
+ * empty value), and an error for a time that is not valid or not ahead.
26
+ */
27
+ export declare function sendAt(value: string, now: number): {
28
+ at: number | null;
29
+ } | {
30
+ error: string;
31
+ };
32
+ //# sourceMappingURL=logic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logic.d.ts","sourceRoot":"","sources":["../../../src/crm/studio/logic.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE7D;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,QAAQ,GAAG,WAAW,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAK1F;AAED,gFAAgF;AAChF,wBAAgB,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAO1H;AAED,gGAAgG;AAChG,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,KAAK,GAAG,cAAc,CAAC,GAAG,MAAM,CAQlF;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAO5F"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The studio's pure decisions, apart from React so they are tested alone: what one
3
+ * person's walk of a sequence says, a sequence's tally, how a step's delay reads, and
4
+ * the send time a form names.
5
+ */
6
+ /**
7
+ * One person's state as the cloud reports it. A walk is `active` while a step is
8
+ * due; `completed` once its last step was taken — whether that send went out, was
9
+ * suppressed or failed is recorded by the cloud but not reported to the org, so
10
+ * the word is "taken", never "delivered".
11
+ */
12
+ export function walkState(e, now) {
13
+ if (e.status === 'canceled')
14
+ return 'canceled';
15
+ if (e.status === 'completed')
16
+ return 'taken';
17
+ if (e.nextRunAt > now)
18
+ return `due ${new Date(e.nextRunAt * 1000).toLocaleString()}`;
19
+ return 'sending';
20
+ }
21
+ /** How many a sequence enrolled, how many are still due, taken, or canceled. */
22
+ export function tally(es) {
23
+ return {
24
+ enrolled: es.length,
25
+ due: es.filter((e) => e.status === 'active').length,
26
+ taken: es.filter((e) => e.status === 'completed').length,
27
+ canceled: es.filter((e) => e.status === 'canceled').length,
28
+ };
29
+ }
30
+ /** A step's delay in words: the first counts from enrollment, the rest from the step before. */
31
+ export function delayText(step) {
32
+ const after = step.idx === 0 ? 'enrollment' : 'the previous step';
33
+ const s = step.delaySeconds;
34
+ if (s <= 0)
35
+ return `at ${after}`;
36
+ if (s % 86400 === 0)
37
+ return `${s / 86400} d after ${after}`;
38
+ if (s % 3600 === 0)
39
+ return `${s / 3600} h after ${after}`;
40
+ if (s % 60 === 0)
41
+ return `${s / 60} min after ${after}`;
42
+ return `${s} s after ${after}`;
43
+ }
44
+ /**
45
+ * The send time a `datetime-local` value names, in unix seconds; null for now (an
46
+ * empty value), and an error for a time that is not valid or not ahead.
47
+ */
48
+ export function sendAt(value, now) {
49
+ if (!value)
50
+ return { at: null };
51
+ const ms = new Date(value).getTime();
52
+ if (!Number.isFinite(ms))
53
+ return { error: 'That send time is not a date.' };
54
+ const at = Math.floor(ms / 1000);
55
+ if (at <= now)
56
+ return { error: 'The send time has to be in the future.' };
57
+ return { at };
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C,IAAI,CAAC;QAAE,OAAO,MAAM,KAAK,EAAE,CAAA;IAChC,IAAI,CAAC,GAAG,KAAK,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC,GAAG,KAAK,YAAY,KAAK,EAAE,CAAA;IAC3D,IAAI,CAAC,GAAG,IAAI,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC,GAAG,IAAI,YAAY,KAAK,EAAE,CAAA;IACzD,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC,GAAG,EAAE,cAAc,KAAK,EAAE,CAAA;IACvD,OAAO,GAAG,CAAC,YAAY,KAAK,EAAE,CAAA;AAChC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,KAAa,EAAE,GAAW;IAC/C,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAA;IAC/B,MAAM,EAAE,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAA;IACpC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,+BAA+B,EAAE,CAAA;IAC3E,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAA;IAChC,IAAI,EAAE,IAAI,GAAG;QAAE,OAAO,EAAE,KAAK,EAAE,wCAAwC,EAAE,CAAA;IACzE,OAAO,EAAE,EAAE,EAAE,CAAA;AACf,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type React from 'react';
2
+ /** The studio's card box. */
3
+ export declare const cardBoxStyle: React.CSSProperties;
4
+ /** The studio's text input. */
5
+ export declare const inputStyle: React.CSSProperties;
6
+ /** A field label. */
7
+ export declare const labelStyle: React.CSSProperties;
8
+ //# sourceMappingURL=style.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../../src/crm/studio/style.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,6BAA6B;AAC7B,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,aAKhC,CAAA;AAED,+BAA+B;AAC/B,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,aAS9B,CAAA;AAED,qBAAqB;AACrB,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,aAAqF,CAAA"}
@@ -0,0 +1,21 @@
1
+ /** The studio's card box. */
2
+ export const cardBoxStyle = {
3
+ borderRadius: 12,
4
+ border: '1px solid rgba(255,255,255,0.08)',
5
+ background: 'rgba(12,12,15,0.75)',
6
+ padding: 16,
7
+ };
8
+ /** The studio's text input. */
9
+ export const inputStyle = {
10
+ width: '100%',
11
+ borderRadius: 8,
12
+ border: '1px solid rgba(255,255,255,0.12)',
13
+ background: 'rgba(9,9,11,0.9)',
14
+ padding: '8px 12px',
15
+ fontSize: 13,
16
+ color: '#f4f4f5',
17
+ outline: 'none',
18
+ };
19
+ /** A field label. */
20
+ export const labelStyle = { fontSize: 11, color: '#a1a1aa', display: 'block', marginBottom: 4 };
21
+ //# sourceMappingURL=style.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.js","sourceRoot":"","sources":["../../../src/crm/studio/style.ts"],"names":[],"mappings":"AAEA,6BAA6B;AAC7B,MAAM,CAAC,MAAM,YAAY,GAAwB;IAC/C,YAAY,EAAE,EAAE;IAChB,MAAM,EAAE,kCAAkC;IAC1C,UAAU,EAAE,qBAAqB;IACjC,OAAO,EAAE,EAAE;CACZ,CAAA;AAED,+BAA+B;AAC/B,MAAM,CAAC,MAAM,UAAU,GAAwB;IAC7C,KAAK,EAAE,MAAM;IACb,YAAY,EAAE,CAAC;IACf,MAAM,EAAE,kCAAkC;IAC1C,UAAU,EAAE,kBAAkB;IAC9B,OAAO,EAAE,UAAU;IACnB,QAAQ,EAAE,EAAE;IACZ,KAAK,EAAE,SAAS;IAChB,OAAO,EAAE,MAAM;CAChB,CAAA;AAED,qBAAqB;AACrB,MAAM,CAAC,MAAM,UAAU,GAAwB,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,EAAE,CAAA"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The suppression list's two pure decisions, kept apart from the components so they
3
+ * are tested without React: who may change the list, and what a refusal says.
4
+ */
5
+ import type { Account } from '../lib/host.js';
6
+ import type { SuppressionCheck } from '../lib/crm.js';
7
+ /** Whether this account may change the org's suppression list: an admin of the org or a SuperAdmin, as the cloud requires. */
8
+ export declare function managesSuppressions(account: Account | null | undefined, org: string): boolean;
9
+ /** Why an address may not be written to, in one line; null when the gate says it may or did not answer. */
10
+ export declare function unmailable(check: SuppressionCheck | null): string | null;
11
+ //# sourceMappingURL=suppression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suppression.d.ts","sourceRoot":"","sources":["../../src/crm/suppression.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,8HAA8H;AAC9H,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAE7F;AAQD,2GAA2G;AAC3G,wBAAgB,UAAU,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAGxE"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The suppression list's two pure decisions, kept apart from the components so they
3
+ * are tested without React: who may change the list, and what a refusal says.
4
+ */
5
+ /** Whether this account may change the org's suppression list: an admin of the org or a SuperAdmin, as the cloud requires. */
6
+ export function managesSuppressions(account, org) {
7
+ return account?.superAdmin === true || (account?.adminOrgs ?? []).includes(org);
8
+ }
9
+ const SCOPE = {
10
+ address: 'this address is on the suppression list',
11
+ domain: "their company's domain is on the suppression list",
12
+ platform: 'the address is on the platform blocklist',
13
+ };
14
+ /** Why an address may not be written to, in one line; null when the gate says it may or did not answer. */
15
+ export function unmailable(check) {
16
+ if (check?.state !== 'suppressed')
17
+ return null;
18
+ return `Not mailable: ${SCOPE[check.scope ?? 'address']}${check.reason ? ` (${check.reason})` : ''}.`;
19
+ }
20
+ //# sourceMappingURL=suppression.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suppression.js","sourceRoot":"","sources":["../../src/crm/suppression.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,8HAA8H;AAC9H,MAAM,UAAU,mBAAmB,CAAC,OAAmC,EAAE,GAAW;IAClF,OAAO,OAAO,EAAE,UAAU,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AACjF,CAAC;AAED,MAAM,KAAK,GAAsD;IAC/D,OAAO,EAAE,yCAAyC;IAClD,MAAM,EAAE,mDAAmD;IAC3D,QAAQ,EAAE,0CAA0C;CACrD,CAAA;AAED,2GAA2G;AAC3G,MAAM,UAAU,UAAU,CAAC,KAA8B;IACvD,IAAI,KAAK,EAAE,KAAK,KAAK,YAAY;QAAE,OAAO,IAAI,CAAA;IAC9C,OAAO,iBAAiB,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,SAAS,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAA;AACvG,CAAC"}
@@ -0,0 +1,12 @@
1
+ export { configureCrm } from './lib/host.js';
2
+ export type { CrmAccount, CrmBrand, CrmHost, CrmRouter, CrmSearchParams, CrmSession } from './lib/host.js';
3
+ export type { BaseClient, BaseListResult, BaseRecord, ListRecordsParams } from './lib/base-data/api.js';
4
+ export { baseClient } from './lib/base-data/client.js';
5
+ export type { BaseClientOptions, BaseSend } from './lib/base-data/client.js';
6
+ export type { BaseCollection, BaseField } from './lib/base-data/fields.js';
7
+ export { CrmModule } from './CrmModule.js';
8
+ export { CRM_PAGES } from './nav.js';
9
+ export type { CrmPage } from './nav.js';
10
+ export { OBJECTS, TABS, movedView, objectOf } from './crm/objects.js';
11
+ export type { CrmObject, ObjectId } from './crm/objects.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvG,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACpG,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,YAAY,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACzE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAEvE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,YAAY,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAGpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAClE,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ // @hanzo/crm — Hanzo CRM: the org's people, companies, pipeline, fundraising,
2
+ // tasks, lists, candidates and sequences, kept in the org's own Base.
3
+ //
4
+ // ONE CRM, drawn by every app that has one: Hanzo Cloud's console (/crm, and
5
+ // crm.<brand>) and Hanzo Team (/crm). Each app says what only it knows through
6
+ // `configureCrm` (how it signs a request, the org, the session, its router, its
7
+ // brand) and draws `<CrmModule params={{ tab, id }} />` where its CRM goes.
8
+ //
9
+ // import { configureCrm, CrmModule, CRM_PAGES } from '@hanzo/crm'
10
+ //
11
+ // `@hanzo/crm/base` is the Base client alone, with no screen behind it, for an
12
+ // app's data layer: `baseClient({ baseUrl, send })`.
13
+ export { configureCrm } from './lib/host.js';
14
+ export { baseClient } from './lib/base-data/client.js';
15
+ export { CrmModule } from './CrmModule.js';
16
+ export { CRM_PAGES } from './nav.js';
17
+ // What a host's navigation lists: the objects, in order, and where an address lands.
18
+ export { OBJECTS, TABS, movedView, objectOf } from './crm/objects.js';
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,sEAAsE;AACtE,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,gFAAgF;AAChF,4EAA4E;AAC5E,EAAE;AACF,oEAAoE;AACpE,EAAE;AACF,+EAA+E;AAC/E,qDAAqD;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAGzC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAInD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGjC,qFAAqF;AACrF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The org's Base, as the CRM reads and writes it: the record shapes Base answers
3
+ * (hanzoai/base, plain JSON REST, not the cloud's `{status,msg,data}` envelope)
4
+ * and the one client the CRM asks of its host.
5
+ *
6
+ * The CRM never builds a Base request itself. The host hands it a `BaseClient`
7
+ * already bound to the org's Base and the signed-in account's credential, because
8
+ * only the host knows how it signs a request (console: the PKCE access token and
9
+ * `X-Org-Id`; another app: its own IAM client). A refusal is an Error carrying the
10
+ * HTTP `status`, which is all the CRM reads of it.
11
+ */
12
+ import type { BaseCollection } from './fields.js';
13
+ /** A Base record — a flat map of field name → value (`id` always present). */
14
+ export type BaseRecord = Record<string, unknown> & {
15
+ id?: string;
16
+ };
17
+ /** Base's paginated list result. */
18
+ export interface BaseListResult<T> {
19
+ page: number;
20
+ perPage: number;
21
+ totalItems: number;
22
+ totalPages: number;
23
+ items: T[];
24
+ }
25
+ /** Record-list query params (a subset of Base's list API). */
26
+ export interface ListRecordsParams {
27
+ page?: number;
28
+ perPage?: number;
29
+ sort?: string;
30
+ filter?: string;
31
+ expand?: string;
32
+ fields?: string;
33
+ skipTotal?: boolean;
34
+ }
35
+ /**
36
+ * What the CRM asks of the org's Base: `GET /v1/base/collections/:name` and the
37
+ * record routes under it.
38
+ */
39
+ export interface BaseClient {
40
+ /** A collection's schema, or undefined when the org's Base has no such collection. */
41
+ getCollection(name: string): Promise<BaseCollection | undefined>;
42
+ listRecords(collection: string, params?: ListRecordsParams): Promise<BaseListResult<BaseRecord>>;
43
+ getRecord(collection: string, id: string): Promise<BaseRecord>;
44
+ createRecord(collection: string, body: Record<string, unknown>): Promise<BaseRecord>;
45
+ updateRecord(collection: string, id: string, body: Record<string, unknown>): Promise<BaseRecord>;
46
+ deleteRecord(collection: string, id: string): Promise<void>;
47
+ }
48
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/lib/base-data/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAE9C,8EAA8E;AAC9E,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,C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EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC5D"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/lib/base-data/api.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * A `BaseClient` over any JSON transport — for a host with no Base client of its own.
3
+ *
4
+ * The host's transport signs the request (its bearer, its org) and parses the
5
+ * reply; this builds Base's addresses and reads its answers. It is the console's
6
+ * Base client (`BaseDataApi`) with the transport taken out: the same record paths,
7
+ * each segment encoded, the same list query, and the same reading of a list that
8
+ * answers as a page or as a bare array.
9
+ */
10
+ import type { BaseClient, BaseListResult, ListRecordsParams } from './api.js';
11
+ export type { BaseClient, BaseListResult, BaseRecord, ListRecordsParams } from './api.js';
12
+ export type { BaseCollection } from './fields.js';
13
+ /**
14
+ * One request: the method, the full URL, and a JSON body when there is one. It
15
+ * resolves to the parsed JSON (null or undefined for an empty reply) and rejects
16
+ * with an Error carrying the HTTP `status` on a refusal.
17
+ */
18
+ export type BaseSend = (method: 'GET' | 'POST' | 'PATCH' | 'DELETE', url: string, body?: Record<string, unknown>) => Promise<unknown>;
19
+ export interface BaseClientOptions {
20
+ /** The Base API root, such as `https://api.hanzo.ai/v1/base`. */
21
+ baseUrl: string;
22
+ send: BaseSend;
23
+ }
24
+ /** A records answer as a `BaseListResult`, whether it came paginated or as a bare array. */
25
+ export declare function asListResult<T>(body: unknown): BaseListResult<T>;
26
+ /** The address of `path` under `root`, with the query's set values. */
27
+ export declare function baseUrlOf(root: string, path: string, query?: ListRecordsParams): string;
28
+ export declare function baseClient({ baseUrl, send }: BaseClientOptions): BaseClient;
29
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/lib/base-data/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAc,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAGtF,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AACtF,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAE9C;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAErI,MAAM,WAAW,iBAAiB;IAChC,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,QAAQ,CAAA;CACf;AAWD,4FAA4F;AAC5F,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,GAAG,cAAc,CAAC,CAAC,CAAC,CAehE;AAED,uEAAuE;AACvE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAOvF;AAOD,wBAAgB,UAAU,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,iBAAiB,GAAG,UAAU,CAgC3E"}
@@ -0,0 +1,76 @@
1
+ /** Pull a list out of `{ items }` (paginated) or a bare array. */
2
+ function asItems(body) {
3
+ if (Array.isArray(body))
4
+ return body;
5
+ if (body && typeof body === 'object' && Array.isArray(body.items)) {
6
+ return body.items;
7
+ }
8
+ return [];
9
+ }
10
+ /** A records answer as a `BaseListResult`, whether it came paginated or as a bare array. */
11
+ export function asListResult(body) {
12
+ if (body && typeof body === 'object' && !Array.isArray(body)) {
13
+ const o = body;
14
+ if (Array.isArray(o.items)) {
15
+ return {
16
+ page: o.page ?? 1,
17
+ perPage: o.perPage ?? o.items.length,
18
+ totalItems: o.totalItems ?? o.items.length,
19
+ totalPages: o.totalPages ?? 1,
20
+ items: o.items,
21
+ };
22
+ }
23
+ }
24
+ const items = asItems(body);
25
+ return { page: 1, perPage: items.length, totalItems: items.length, totalPages: 1, items };
26
+ }
27
+ /** The address of `path` under `root`, with the query's set values. */
28
+ export function baseUrlOf(root, path, query) {
29
+ const qs = new URLSearchParams();
30
+ for (const [k, v] of Object.entries(query ?? {})) {
31
+ if (v !== undefined && v !== null)
32
+ qs.set(k, String(v));
33
+ }
34
+ const q = qs.toString();
35
+ return `${root.replace(/\/+$/, '')}/${path}${q ? `?${q}` : ''}`;
36
+ }
37
+ const statusOf = (e) => {
38
+ const s = e?.status;
39
+ return typeof s === 'number' ? s : undefined;
40
+ };
41
+ export function baseClient({ baseUrl, send }) {
42
+ const records = (collection, id) => {
43
+ const at = `collections/${encodeURIComponent(collection)}/records`;
44
+ return id === undefined ? at : `${at}/${encodeURIComponent(id)}`;
45
+ };
46
+ const url = (path, query) => baseUrlOf(baseUrl, path, query);
47
+ return {
48
+ async getCollection(name) {
49
+ try {
50
+ const c = (await send('GET', url(`collections/${encodeURIComponent(name)}`)));
51
+ return c && c.name === name ? c : undefined;
52
+ }
53
+ catch (e) {
54
+ if (statusOf(e) === 404)
55
+ return undefined;
56
+ throw e;
57
+ }
58
+ },
59
+ async listRecords(collection, params) {
60
+ return asListResult(await send('GET', url(records(collection), params)));
61
+ },
62
+ async getRecord(collection, id) {
63
+ return (await send('GET', url(records(collection, id))));
64
+ },
65
+ async createRecord(collection, body) {
66
+ return (await send('POST', url(records(collection)), body));
67
+ },
68
+ async updateRecord(collection, id, body) {
69
+ return (await send('PATCH', url(records(collection, id)), body));
70
+ },
71
+ async deleteRecord(collection, id) {
72
+ await send('DELETE', url(records(collection, id)));
73
+ },
74
+ };
75
+ }
76
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sour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CAAA;QAChF,CAAC;QACD,KAAK,CAAC,YAAY,CAAC,UAAkB,EAAE,EAAU;YAC/C,MAAM,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;QACpD,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Pure mapping between a Hanzo Base (hanzoai/base) collection and @hanzo/data:
3
+ * the schema (`baseCollectionToFields` → `FieldDefinition[]`, the column model
4
+ * `DataTable` / `RecordForm` render from) and each value (`fromBase` for what a
5
+ * record holds, `toBase` for what an edit writes back).
6
+ *
7
+ * Base describes a collection as a list of typed fields (modern key `fields`;
8
+ * legacy PocketBase used `schema`, nesting a type's options under `options`). A
9
+ * module's field carries its own `label`, and a select its options with a label
10
+ * and a hue, so a CRM column reads "Last contact" and a stage "Term sheet". The
11
+ * composite types (`fullName`, `emails`, `phones`, `links`, `address`,
12
+ * `currency`, `actor`) are one JSON object of named parts in Base and one value
13
+ * of @hanzo/data's own shape here; `fromBase`/`toBase` are the only crossing.
14
+ *
15
+ * No I/O and no React — data in, data out, trivially testable. The @hanzo/data
16
+ * imports are `import type` (erased at build), so this module pulls in none of
17
+ * its runtime (the unit test runs in plain Node).
18
+ */
19
+ import type { FieldDefinition, SelectOption } from '@hanzo/data';
20
+ /** One option of a select, as a module declares it. */
21
+ export interface BaseOption {
22
+ value: string;
23
+ label?: string;
24
+ color?: string;
25
+ position?: number;
26
+ }
27
+ /** One field of a Base collection schema (modern flat shape + legacy `options`). */
28
+ export interface BaseField {
29
+ name: string;
30
+ type: string;
31
+ label?: string;
32
+ position?: number;
33
+ required?: boolean;
34
+ /** Hidden from the API response — never rendered. */
35
+ hidden?: boolean;
36
+ /** System field (`id`, `created`, `updated`, …). Skipped except `id`. */
37
+ system?: boolean;
38
+ /** select/file/relation: unset or 1 = single value, >1 = multiple. */
39
+ maxSelect?: number;
40
+ /** select: the accepted values. */
41
+ values?: string[];
42
+ /** relation: the collection it points at, by id (or, in a module document, by name). */
43
+ collectionId?: string;
44
+ /**
45
+ * A module's select options (`[{ value, label, color }]`), or legacy PocketBase's
46
+ * nested `{ maxSelect, values }`.
47
+ */
48
+ options?: BaseOption[] | ({
49
+ maxSelect?: number;
50
+ values?: string[];
51
+ } & Record<string, unknown>);
52
+ }
53
+ /** A Base collection schema. `fields` is canonical; `schema` is the legacy key. */
54
+ export interface BaseCollection {
55
+ /** Base collection id — the value a `relation` field targets (`collectionId`). */
56
+ id?: string;
57
+ name?: string;
58
+ label?: string;
59
+ plural?: string;
60
+ fields?: BaseField[];
61
+ schema?: BaseField[];
62
+ /** `base` | `auth` | `view` — a `view` collection is read-only. */
63
+ type?: string;
64
+ /** Internal Base collection (`_superusers`, `_mfas`, …) — hidden from the browser. */
65
+ system?: boolean;
66
+ }
67
+ /** A select's options: the module's (label, hue, order) where it gives them, else its bare values. */
68
+ export declare function optionsOf(f: BaseField): SelectOption[];
69
+ /** Options for mapping a schema: how a relation's target collection id reads as its name. */
70
+ export interface MapOptions {
71
+ /** Collection id → name, so a relation names the object it points at. */
72
+ names?: ReadonlyMap<string, string>;
73
+ }
74
+ /** The raw Base fields of a collection, in the module's order where it states one. */
75
+ export declare function baseFieldsOf(collection: BaseCollection | null | undefined): BaseField[];
76
+ /**
77
+ * Map a Base collection schema to the ordered `FieldDefinition[]` a `DataTable`
78
+ * renders. Accepts the modern `fields` key and the legacy `schema` key; skips
79
+ * hidden + system fields (keeping `id`). Total: returns `[]` for an absent or
80
+ * malformed schema.
81
+ */
82
+ export declare function baseCollectionToFields(collection: BaseCollection | null | undefined, opts?: MapOptions): FieldDefinition[];
83
+ /**
84
+ * A Base value as @hanzo/data reads it. A type that is the same on both sides
85
+ * passes through; money and links become @hanzo/data's shape; an expanded
86
+ * relation becomes the record it names, so a cell shows its name, not an id.
87
+ */
88
+ export declare function fromBase(baseType: string, value: unknown, expanded?: unknown): unknown;
89
+ /**
90
+ * What an edit writes back to Base for one field. `prior` is the record's current
91
+ * Base value, so a composite keeps the parts the editor does not show (a
92
+ * person's other addresses, a phone's calling code).
93
+ */
94
+ export declare function toBase(baseType: string, value: unknown, prior?: unknown): unknown;
95
+ /**
96
+ * A record's own value for a field. The hosted Base writes a record's stamps as
97
+ * `createdAt` and `updatedAt` while its schema, its filters and its sorts name them
98
+ * `created` and `updated`; an autodate is read under either.
99
+ */
100
+ export declare const valueOf: (f: Pick<BaseField, 'name' | 'type'>, record: Record<string, unknown>) => unknown;
101
+ /** A whole Base record as @hanzo/data reads it, each relation resolved from `expand`. */
102
+ export declare function recordFromBase(fields: readonly BaseField[], record: Record<string, unknown>): Record<string, unknown>;
103
+ //# sourceMappingURL=fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../src/lib/base-data/fields.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,eAAe,EAAa,YAAY,EAAY,MAAM,aAAa,CAAA;AAGrF,uDAAuD;AACvD,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,oFAAoF;AACpF,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,qDAAqD;IACrD,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,yEAAyE;IACzE,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,mCAAmC;IACnC,MAAM,CAAC,EAAE,MAAM,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