@awesomate/sdk 0.63.0 → 0.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -26,7 +26,7 @@
26
26
  * Docs: https://hub.awesomate.ai/docs/sdk/
27
27
  */
28
28
  /** This package's version, sent to the hub with every server call. */
29
- export declare const VERSION = "0.63.0";
29
+ export declare const VERSION = "0.64.0";
30
30
  /** Augmented by the generated awesomate.d.ts, so each kind's rows are typed. */
31
31
  export interface Kinds {
32
32
  }
@@ -1640,6 +1640,52 @@ export declare class AwesomateClient {
1640
1640
  * await db.archiveLink('vehicle', 'serviced_at');
1641
1641
  */
1642
1642
  archiveLink(kind: string, key: string): Promise<KindDescription>;
1643
+ /**
1644
+ * Set this up for me: the hub's suggestion for one sentence about what the owner keeps track of
1645
+ * ("a job management system"), as a whole setup in the owner's words (fields, stages, lists,
1646
+ * links, small related things, the brief). Nothing is saved. Pass `kind` to ask about one of
1647
+ * their things: the suggestion then only adds to it, and `matched` says what it has already.
1648
+ * Edit it if you like, then checkSetup(). The account's token, crm:write, Support Plus and above,
1649
+ * with Set this up for me on the account; a few a person in ten minutes.
1650
+ *
1651
+ * @example
1652
+ * const proposal = await db.proposeSetup('property bookings');
1653
+ * console.log(proposal.sentence);
1654
+ */
1655
+ proposeSetup(sentence: string, options?: {
1656
+ kind?: string;
1657
+ }): Promise<SetupProposal>;
1658
+ /**
1659
+ * Check a setup exactly as a click would, and read the sentence the owner should agree to before
1660
+ * applySetup(). Nothing is saved. On one of their things it is additions only, and answers
1661
+ * `base`, which applySetup() needs. A setup that does not fit throws `validation` naming the
1662
+ * item (`at`, like `fields.2`). The account's token, crm:write.
1663
+ *
1664
+ * @example
1665
+ * const proposal = await db.proposeSetup('a quote pipeline');
1666
+ * const check = await db.checkSetup(proposal.setup);
1667
+ * if (check.can_apply) console.log(check.sentence);
1668
+ */
1669
+ checkSetup(setup: SetupSpec, options?: {
1670
+ replaceBrief?: boolean;
1671
+ }): Promise<SetupCheck>;
1672
+ /**
1673
+ * Set it up, all in one go or not at all: the thing, its fields, sections, stages, links, small
1674
+ * related things, lists and the brief. On one of their things it only adds (nothing is removed,
1675
+ * renamed or retyped) and needs `base` from checkSetup() (without it, `validation`, server code
1676
+ * `base_required`); if the thing changed since, it throws
1677
+ * `conflict` (server code `changed`): check again. Only an Owner's key may apply (anyone else's
1678
+ * throws `forbidden`, server code `owner_only`). Apply only what the owner agreed to.
1679
+ *
1680
+ * @example
1681
+ * const { setup } = await db.proposeSetup('property bookings');
1682
+ * const made = await db.applySetup(setup); // once the owner has agreed to checkSetup()'s sentence
1683
+ * console.log(made.kind.key, made.land);
1684
+ */
1685
+ applySetup(setup: SetupSpec, options?: {
1686
+ base?: SetupBase;
1687
+ replaceBrief?: boolean;
1688
+ }): Promise<SetupApplied>;
1643
1689
  /**
1644
1690
  * Create a record (returns its id), or change one with options.id. Every value is checked
1645
1691
  * against the kind. crm:write, Support Plus and above: the account's token, or an app key made
@@ -2666,6 +2712,132 @@ export interface LinkSpec {
2666
2712
  /** Every record must set it. Only when added to a kind with no records yet; a link is never made required later. */
2667
2713
  required?: boolean;
2668
2714
  }
2715
+ /** A field in a setup, in the owner's words. */
2716
+ export interface SetupField {
2717
+ label: string;
2718
+ type: 'text' | 'long_text' | 'number' | 'money' | 'date' | 'datetime' | 'yes_no' | 'choice' | 'choices' | 'address' | 'phone' | 'email' | 'url';
2719
+ /** For choice and choices. */
2720
+ choices?: string[];
2721
+ required?: boolean;
2722
+ /** Whether AI may read it. Leave names, notes and contact details off unless the owner says so. */
2723
+ ai_may_read?: boolean;
2724
+ /** A section's label. */
2725
+ section?: string;
2726
+ }
2727
+ /**
2728
+ * A setup: what an owner keeps track of, in their own words, never keys. `thing` is a new thing
2729
+ * (`{label, label_plural?}`) or one of theirs to add to (`{kind}`). Limits: 6 sections, 15
2730
+ * fields, 2 to 8 stages, 4 links, 2 related things of up to 6 fields, 3 lists of up to 12
2731
+ * columns, a brief focus of up to 200 characters and 6 pins.
2732
+ */
2733
+ export interface SetupSpec {
2734
+ thing: {
2735
+ label: string;
2736
+ label_plural?: string;
2737
+ } | {
2738
+ kind: string;
2739
+ };
2740
+ sections?: Array<{
2741
+ label: string;
2742
+ description?: string;
2743
+ }>;
2744
+ fields?: SetupField[];
2745
+ /** The stage field and its stages in order; `role` is a role on the business map, whose turn it is. */
2746
+ stages?: {
2747
+ field_label?: string;
2748
+ stages: Array<{
2749
+ name: string;
2750
+ colour?: 'grey' | 'blue' | 'green' | 'amber' | 'red' | 'purple';
2751
+ closed?: boolean;
2752
+ role?: string;
2753
+ }>;
2754
+ } | null;
2755
+ /** `to` is 'People', 'Companies' or one of the owner's things. */
2756
+ links?: Array<{
2757
+ to: string;
2758
+ label?: string;
2759
+ required?: boolean;
2760
+ }>;
2761
+ /** Small new things, each belonging to the main thing. */
2762
+ new_related?: Array<{
2763
+ label: string;
2764
+ label_plural?: string;
2765
+ fields?: SetupField[];
2766
+ link_label?: string;
2767
+ }>;
2768
+ lists?: Array<{
2769
+ name: string;
2770
+ display: 'table' | 'board' | 'calendar' | 'week' | 'timeline';
2771
+ group_by?: string;
2772
+ date_field?: string;
2773
+ columns?: string[];
2774
+ }>;
2775
+ /** What the summary at the top of each record leads with, and the fields pinned under it. */
2776
+ brief?: {
2777
+ focus?: string;
2778
+ pins?: string[];
2779
+ } | null;
2780
+ }
2781
+ /** What one of the owner's things has already, by the owner's labels. */
2782
+ export interface SetupMatched {
2783
+ fields: string[];
2784
+ links: string[];
2785
+ stages: string[];
2786
+ lists: string[];
2787
+ }
2788
+ /** The versions checkSetup() read a thing at; pass it to applySetup() as it came. */
2789
+ export type SetupBase = Record<string, unknown>;
2790
+ /** proposeSetup()'s answer. */
2791
+ export interface SetupProposal {
2792
+ setup: SetupSpec;
2793
+ /** What it would do, in plain words: show this to the owner. */
2794
+ sentence: string;
2795
+ /** How many suggested parts did not fit and were left out. */
2796
+ dropped: number;
2797
+ /** How many parts the thing has already (adding to one of theirs). */
2798
+ already: number;
2799
+ matched?: SetupMatched;
2800
+ notes?: string[];
2801
+ /** Set when the sentence named one of their things: the setup adds to it. */
2802
+ adds_to?: {
2803
+ key: string;
2804
+ label: string;
2805
+ label_plural: string;
2806
+ };
2807
+ }
2808
+ /** checkSetup()'s answer. */
2809
+ export interface SetupCheck {
2810
+ /** Exactly what applySetup() would do: the owner agrees to this. */
2811
+ sentence: string;
2812
+ setup: SetupSpec;
2813
+ /** Whether this key may apply it (an Owner's). */
2814
+ can_apply: boolean;
2815
+ makes: {
2816
+ key: string;
2817
+ related: string[];
2818
+ lists: number;
2819
+ stages: number;
2820
+ fields?: number;
2821
+ links?: number;
2822
+ };
2823
+ matched?: SetupMatched;
2824
+ notes?: string[];
2825
+ /** Adding to one of theirs: true when there is nothing to add. */
2826
+ nothing?: boolean;
2827
+ base?: SetupBase;
2828
+ }
2829
+ /** applySetup()'s answer: the thing set up, its related things, and the list to open first. */
2830
+ export interface SetupApplied {
2831
+ kind: {
2832
+ key: string;
2833
+ label_plural: string;
2834
+ };
2835
+ related: string[];
2836
+ land: {
2837
+ kind: string;
2838
+ list?: string;
2839
+ };
2840
+ }
2669
2841
  /** A kind to define: a table an app keeps. */
2670
2842
  export interface KindSpec {
2671
2843
  key: string;
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@
26
26
  * Docs: https://hub.awesomate.ai/docs/sdk/
27
27
  */
28
28
  /** This package's version, sent to the hub with every server call. */
29
- export const VERSION = '0.63.0';
29
+ export const VERSION = '0.64.0';
30
30
  const DEFAULT_BASE = 'https://hub.awesomate.ai';
31
31
  /** The one check for a platform `watch_url` (mirrored in the hub's awesomate-knowledge.ts and its MCP). */
32
32
  const WATCH_URL = /^https:\/\/[^\s"'<>]+$/i;
@@ -130,7 +130,8 @@ function errorCode(status, server, body = {}) {
130
130
  return 'rate_limited';
131
131
  // stale: a form or webinar changed since it was read (update with version). not_draft: a webinar's
132
132
  // registration is open, so it is fixed in Zoom. not_run: a recording goes only on a webinar that has run.
133
- if (server === 'conflict' || server === 'stale' || server === 'not_draft' || server === 'not_run')
133
+ // changed: a thing a setup adds to changed since checkSetup().
134
+ if (server === 'conflict' || server === 'stale' || server === 'not_draft' || server === 'not_run' || server === 'changed')
134
135
  return 'conflict';
135
136
  if (status === 404 && server !== 'not_live')
136
137
  return 'not_found';
@@ -1476,6 +1477,53 @@ export class AwesomateClient {
1476
1477
  async archiveLink(kind, key) {
1477
1478
  return (await this.request('DELETE', `/api/my-crm/v1/kinds/${encodeURIComponent(kind)}/links/${encodeURIComponent(key)}`, undefined, false)).kind;
1478
1479
  }
1480
+ /**
1481
+ * Set this up for me: the hub's suggestion for one sentence about what the owner keeps track of
1482
+ * ("a job management system"), as a whole setup in the owner's words (fields, stages, lists,
1483
+ * links, small related things, the brief). Nothing is saved. Pass `kind` to ask about one of
1484
+ * their things: the suggestion then only adds to it, and `matched` says what it has already.
1485
+ * Edit it if you like, then checkSetup(). The account's token, crm:write, Support Plus and above,
1486
+ * with Set this up for me on the account; a few a person in ten minutes.
1487
+ *
1488
+ * @example
1489
+ * const proposal = await db.proposeSetup('property bookings');
1490
+ * console.log(proposal.sentence);
1491
+ */
1492
+ async proposeSetup(sentence, options = {}) {
1493
+ return this.request('POST', '/api/my-crm/v1/setup/propose', { sentence, ...(options.kind ? { kind: options.kind } : {}) }, false);
1494
+ }
1495
+ /**
1496
+ * Check a setup exactly as a click would, and read the sentence the owner should agree to before
1497
+ * applySetup(). Nothing is saved. On one of their things it is additions only, and answers
1498
+ * `base`, which applySetup() needs. A setup that does not fit throws `validation` naming the
1499
+ * item (`at`, like `fields.2`). The account's token, crm:write.
1500
+ *
1501
+ * @example
1502
+ * const proposal = await db.proposeSetup('a quote pipeline');
1503
+ * const check = await db.checkSetup(proposal.setup);
1504
+ * if (check.can_apply) console.log(check.sentence);
1505
+ */
1506
+ async checkSetup(setup, options = {}) {
1507
+ return this.request('POST', '/api/my-crm/v1/setup/check', { setup, ...(options.replaceBrief ? { replace_brief: true } : {}) }, false);
1508
+ }
1509
+ /**
1510
+ * Set it up, all in one go or not at all: the thing, its fields, sections, stages, links, small
1511
+ * related things, lists and the brief. On one of their things it only adds (nothing is removed,
1512
+ * renamed or retyped) and needs `base` from checkSetup() (without it, `validation`, server code
1513
+ * `base_required`); if the thing changed since, it throws
1514
+ * `conflict` (server code `changed`): check again. Only an Owner's key may apply (anyone else's
1515
+ * throws `forbidden`, server code `owner_only`). Apply only what the owner agreed to.
1516
+ *
1517
+ * @example
1518
+ * const { setup } = await db.proposeSetup('property bookings');
1519
+ * const made = await db.applySetup(setup); // once the owner has agreed to checkSetup()'s sentence
1520
+ * console.log(made.kind.key, made.land);
1521
+ */
1522
+ async applySetup(setup, options = {}) {
1523
+ return this.request('POST', '/api/my-crm/v1/setup/apply', {
1524
+ setup, ...(options.base ? { base: options.base } : {}), ...(options.replaceBrief ? { replace_brief: true } : {}),
1525
+ }, false);
1526
+ }
1479
1527
  /**
1480
1528
  * Create a record (returns its id), or change one with options.id. Every value is checked
1481
1529
  * against the kind. crm:write, Support Plus and above: the account's token, or an app key made
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awesomate/sdk",
3
- "version": "0.63.0",
3
+ "version": "0.64.0",
4
4
  "description": "Your own Awesomate data from Node and the browser: query contacts and app data with generated types, and sign your app's own users in",
5
5
  "license": "MIT",
6
6
  "type": "module",