@awesomate/sdk 0.90.0 → 0.92.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.90.0";
29
+ export declare const VERSION = "0.92.0";
30
30
  /** Augmented by the generated awesomate.d.ts, so each kind's rows are typed. */
31
31
  export interface Kinds {
32
32
  }
@@ -1728,6 +1728,18 @@ export declare class AwesomateClient {
1728
1728
  get: (id: string, options?: {
1729
1729
  tz?: string;
1730
1730
  }) => Promise<ContactDetail | null>;
1731
+ /**
1732
+ * New leads waiting on whoever this token belongs to (the owner's token sees every one), newest
1733
+ * first, at most 50: open ones, and ones marked answered in the last 14 days. Each has the
1734
+ * person's id (`contactId`), their name where your token may read it (null otherwise), how they
1735
+ * came in (`door`, and `doorWords` such as 'your form') and how long it waited. To answer one,
1736
+ * draft a one-to-one service email to them (emails.draft with people and no list), which the
1737
+ * owner sends from the hub. Needs crm:read and New leads on the account (`lead_alert`).
1738
+ *
1739
+ * @example
1740
+ * const waiting = (await db.contacts.leads()).filter((l) => !l.answered);
1741
+ */
1742
+ leads: () => Promise<Lead[]>;
1731
1743
  /**
1732
1744
  * The person with exactly this email is changed, or added when there is none. `created: false`
1733
1745
  * means someone already had the address, and what you sent replaced their values. Tags are
@@ -2041,6 +2053,34 @@ export declare class AwesomateClient {
2041
2053
  * await db.archiveLink('vehicle', 'serviced_at');
2042
2054
  */
2043
2055
  archiveLink(kind: string, key: string): Promise<KindDescription>;
2056
+ /**
2057
+ * Contacts settings. `leadAlert()` reads the New leads setting: whether a new lead gives someone a
2058
+ * task, and who answers them. `setLeadAlert()` changes it, on the account owner's own token only
2059
+ * (anyone else's throws `forbidden`, server code `finish_in_hub`, and the owner changes it in the
2060
+ * hub at `settingsUrl`). Needs New leads on the account (`lead_alert`).
2061
+ *
2062
+ * @example
2063
+ * const alert = await db.setup.leadAlert();
2064
+ * if (alert.canChange) await db.setup.setLeadAlert({ answeredBy: 'owner' });
2065
+ */
2066
+ readonly setup: {
2067
+ /** The New leads setting. crm:read; any token may read it. */
2068
+ leadAlert: () => Promise<LeadAlertSetting>;
2069
+ /**
2070
+ * Change the New leads setting: `on`, and `answeredBy` ('map': the role the business map puts
2071
+ * in Enquiries and quotes, else the owner; 'owner'; or `{ roleId }` from the business map).
2072
+ * crm:write, the account owner's own token only. Answers the setting as it is now, with
2073
+ * `changed` false when it already was.
2074
+ */
2075
+ setLeadAlert: (change: {
2076
+ on?: boolean;
2077
+ answeredBy?: "map" | "owner" | {
2078
+ roleId: number;
2079
+ };
2080
+ }) => Promise<LeadAlertSetting & {
2081
+ changed: boolean;
2082
+ }>;
2083
+ };
2044
2084
  /**
2045
2085
  * Set this up for me: the hub's suggestion for one sentence about what the owner keeps track of
2046
2086
  * ("a job management system"), as a whole setup in the owner's words (fields, stages, lists,
@@ -2222,6 +2262,24 @@ export declare class AwesomateClient {
2222
2262
  businessJourneyQueue(step: number, opts?: {
2223
2263
  page?: number;
2224
2264
  }): Promise<BusinessJourneyQueue>;
2265
+ /**
2266
+ * The business's agents in one read: every helper on the map (agents, n8n agents, automations) with
2267
+ * its role, level and who looks after it, what it did in the last 7 or 30 days (conversations, ones
2268
+ * it could not answer or passed to a person, tasks raised, decisions filed, runs and errors), what is
2269
+ * waiting on a person because of it, and its role's KPIs with what feeds each figure. Counts, times
2270
+ * and ids only, never a conversation's or task's words. A figure a kind of helper does not have is
2271
+ * null, never 0. hosting:read and the agentic business feature (`feature_unavailable` otherwise). The
2272
+ * owner's own key reads every helper (`scope` `'all'`); a person's own key reads the helpers on roles
2273
+ * whose KPIs they would see (`'yours'`); a narrow key reads none.
2274
+ *
2275
+ * ```ts
2276
+ * const { rows } = await db.businessAgents({ period: 30 });
2277
+ * for (const a of rows.filter((x) => x.needsPerson.count > 0)) console.log(a.label, a.needsPerson.count);
2278
+ * ```
2279
+ */
2280
+ businessAgents(opts?: {
2281
+ period?: 7 | 30;
2282
+ }): Promise<BusinessAgents>;
2225
2283
  /**
2226
2284
  * The business's KPIs: each a number with a target and someone responsible for it, with where it
2227
2285
  * sits, who answers for it, its light against the target for the last complete period, the period
@@ -2792,6 +2850,94 @@ export interface BusinessJourneyQueueRecord {
2792
2850
  /** The open task raised because it ran late, if any. */
2793
2851
  roleTaskId: number | null;
2794
2852
  }
2853
+ /** One KPI on an agent's role, with what feeds its figure. */
2854
+ export interface BusinessAgentKpi {
2855
+ slug: string;
2856
+ name: string;
2857
+ light: KpiLight;
2858
+ /** Say this beside any colour. */
2859
+ lightWord: string;
2860
+ /** What feeds its figure: a helper on the map (by id), else who writes it, in words. */
2861
+ contributors: Array<{
2862
+ helperId: number | null;
2863
+ label: string;
2864
+ writtenBy: 'automation' | 'person' | 'agent';
2865
+ }>;
2866
+ }
2867
+ /** One helper on the map, as businessAgents() returns it. Every count is over the period; null where the helper has no such thing (an automation has no conversations). An automation's `runs`, `errors` and `lastRunAt` are also null when its runs could not be read or it has no workflow yet: never read that as no runs. */
2868
+ export interface BusinessAgent {
2869
+ /** The map helper's id. */
2870
+ id: number;
2871
+ /** 'agent' (an Awesomate agent), 'n8n_agent', 'build', 'template', 'bundle' or 'external'. */
2872
+ kind: string;
2873
+ ref: string;
2874
+ label: string;
2875
+ /** `department.no` is a fixed key, never said to people: say `department.name`. */
2876
+ role: {
2877
+ id: number;
2878
+ slug: string;
2879
+ title: string;
2880
+ department: {
2881
+ no: number;
2882
+ name: string;
2883
+ };
2884
+ };
2885
+ /** True when it holds the role, not only helps on it. */
2886
+ holds: boolean;
2887
+ /** `runsAt` is the level its runs start at; null when it holds its role with no level of its own (each process's level applies). */
2888
+ level: {
2889
+ declared: number | null;
2890
+ runsAt: number | null;
2891
+ };
2892
+ lookedAfterBy: string;
2893
+ /** An Awesomate agent on or off; null for anything else, or when that read was incomplete. */
2894
+ state: 'on' | 'off' | null;
2895
+ status: {
2896
+ conversations: number | null;
2897
+ couldntAnswer: number | null;
2898
+ transferred: number | null;
2899
+ tasksRaised: number | null;
2900
+ tasksOpen: number | null;
2901
+ decisionsFiled: number | null;
2902
+ decisionsWaiting: number | null;
2903
+ runs: number | null;
2904
+ errors: number | null;
2905
+ lastRunAt: string | null;
2906
+ };
2907
+ /** The newest conversation, task, decision or run in the period; null when none. */
2908
+ lastActive: string | null;
2909
+ /** Waiting on a person because of it: decisions not answered, tasks it raised still open, transfers that rang out. Ids are capped at 5 each; `count` is the whole. */
2910
+ needsPerson: {
2911
+ count: number;
2912
+ decisionIds: number[];
2913
+ taskIds: number[];
2914
+ conversationIds: string[];
2915
+ };
2916
+ /** Its role's KPIs; null where the hub does not keep this account's KPIs (they are in Reports: read them with `businessKpis()`), or, with `'kpis'` in `unavailable`, where they could not be read. */
2917
+ kpis: BusinessAgentKpi[] | null;
2918
+ }
2919
+ /** The business's agents, as businessAgents() returns them. */
2920
+ export interface BusinessAgents {
2921
+ /** Days. */
2922
+ period: 7 | 30;
2923
+ since: string;
2924
+ asOf: string;
2925
+ /** 'all': every helper; 'yours': the roles this key sees KPIs for (a person's own key). A narrow key reads none: 'yours' with no rows, which never means no agents work there. */
2926
+ scope: 'all' | 'yours';
2927
+ /** Every row this key may read, not only the ones returned. */
2928
+ total: number;
2929
+ /** True when there were more than the 50 rows returned. */
2930
+ truncated: boolean;
2931
+ rows: BusinessAgent[];
2932
+ /** Helpers the map could not place on a role (scope 'all' only). */
2933
+ unplaced: Array<{
2934
+ kind: string;
2935
+ ref: string;
2936
+ label: string;
2937
+ }>;
2938
+ /** Parts that could not be read just now (their figures are null, never 0). */
2939
+ unavailable: string[];
2940
+ }
2795
2941
  /** A step's queue, as businessJourneyQueue() returns it. */
2796
2942
  export interface BusinessJourneyQueue {
2797
2943
  asOf: string;
@@ -4564,6 +4710,41 @@ export interface RelatedRows {
4564
4710
  /** Pass to query() with where { <link>_id: id } and after, for more. */
4565
4711
  next: string | null;
4566
4712
  }
4713
+ /** How a lead came in. */
4714
+ export type LeadDoor = 'app' | 'form' | 'booking' | 'chat' | 'social' | 'phone' | 'email' | 'automation';
4715
+ /** A new lead, from contacts.leads(). */
4716
+ export interface Lead {
4717
+ /** The lead's task in the hub. */
4718
+ taskId: number;
4719
+ /** The person's contact id. */
4720
+ contactId: string;
4721
+ /** Their first and last name where your token may read them, else null (never their email). */
4722
+ name: string | null;
4723
+ door: LeadDoor;
4724
+ /** The door in words: 'your form', 'your app', 'your website chat'. */
4725
+ doorWords: string;
4726
+ /** When they came in, ISO 8601. */
4727
+ at: string;
4728
+ answered: boolean;
4729
+ /** When it was marked answered, ISO 8601, or null. */
4730
+ answeredAt: string | null;
4731
+ /** Open: minutes since they came in. Answered: minutes it waited before it was answered. */
4732
+ minutesWaiting: number;
4733
+ }
4734
+ /** The New leads setting, from setup.leadAlert(). */
4735
+ export interface LeadAlertSetting {
4736
+ /** Whether a new lead gives someone a task. */
4737
+ on: boolean;
4738
+ /** 'map': the role the business map puts in Enquiries and quotes, else the owner. */
4739
+ answeredBy: 'map' | 'owner' | {
4740
+ roleId: number;
4741
+ title: string;
4742
+ };
4743
+ /** Whether this token may change it (the account owner's own token). */
4744
+ canChange: boolean;
4745
+ /** The hub page where the owner changes it. */
4746
+ settingsUrl: string;
4747
+ }
4567
4748
  /** How a person asked to stop getting email, for contacts.unsubscribe(). */
4568
4749
  export type ContactStopHow = 'reply' | 'phone' | 'in_person' | 'in_writing' | 'other';
4569
4750
  /** What contacts.unsubscribe() recorded. */
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.90.0';
29
+ export const VERSION = '0.92.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;
@@ -241,6 +241,10 @@ function keyPath(method, path) {
241
241
  function contactsNeedAccount() {
242
242
  return new AwesomateError('forbidden', 'This needs the account\'s token (amt_pat_...). An app key made for contacts reads them with contacts.search() or query(\'contact\').', 0);
243
243
  }
244
+ /** A db.setup call on an app key: the account's own settings, refused before anything is sent. */
245
+ function setupNeedsAccount() {
246
+ return new AwesomateError('forbidden', 'This needs the account\'s token (amt_pat_...).', 0);
247
+ }
244
248
  /** A person's id, checked before it is sent: anything but a UUID names nobody. */
245
249
  function contactIdOf(id) {
246
250
  if (!RECORD_ID.test(String(id)))
@@ -1502,6 +1506,22 @@ export class AwesomateClient {
1502
1506
  ...(r.not_shown_to_you ? { notShownToYou: r.not_shown_to_you } : {}), asAt: r.as_at,
1503
1507
  };
1504
1508
  },
1509
+ /**
1510
+ * New leads waiting on whoever this token belongs to (the owner's token sees every one), newest
1511
+ * first, at most 50: open ones, and ones marked answered in the last 14 days. Each has the
1512
+ * person's id (`contactId`), their name where your token may read it (null otherwise), how they
1513
+ * came in (`door`, and `doorWords` such as 'your form') and how long it waited. To answer one,
1514
+ * draft a one-to-one service email to them (emails.draft with people and no list), which the
1515
+ * owner sends from the hub. Needs crm:read and New leads on the account (`lead_alert`).
1516
+ *
1517
+ * @example
1518
+ * const waiting = (await db.contacts.leads()).filter((l) => !l.answered);
1519
+ */
1520
+ leads: async () => {
1521
+ if (this.appKey)
1522
+ throw contactsNeedAccount();
1523
+ return (await this.request('GET', '/api/my-crm/v1/leads')).leads;
1524
+ },
1505
1525
  /**
1506
1526
  * The person with exactly this email is changed, or added when there is none. `created: false`
1507
1527
  * means someone already had the address, and what you sent replaced their values. Tags are
@@ -1993,6 +2013,39 @@ export class AwesomateClient {
1993
2013
  async archiveLink(kind, key) {
1994
2014
  return (await this.request('DELETE', `/api/my-crm/v1/kinds/${encodeURIComponent(kind)}/links/${encodeURIComponent(key)}`, undefined, false)).kind;
1995
2015
  }
2016
+ /**
2017
+ * Contacts settings. `leadAlert()` reads the New leads setting: whether a new lead gives someone a
2018
+ * task, and who answers them. `setLeadAlert()` changes it, on the account owner's own token only
2019
+ * (anyone else's throws `forbidden`, server code `finish_in_hub`, and the owner changes it in the
2020
+ * hub at `settingsUrl`). Needs New leads on the account (`lead_alert`).
2021
+ *
2022
+ * @example
2023
+ * const alert = await db.setup.leadAlert();
2024
+ * if (alert.canChange) await db.setup.setLeadAlert({ answeredBy: 'owner' });
2025
+ */
2026
+ setup = {
2027
+ /** The New leads setting. crm:read; any token may read it. */
2028
+ leadAlert: async () => {
2029
+ if (this.appKey)
2030
+ throw setupNeedsAccount();
2031
+ return leadAlertOf(await this.request('GET', '/api/my-crm/v1/leads/settings'));
2032
+ },
2033
+ /**
2034
+ * Change the New leads setting: `on`, and `answeredBy` ('map': the role the business map puts
2035
+ * in Enquiries and quotes, else the owner; 'owner'; or `{ roleId }` from the business map).
2036
+ * crm:write, the account owner's own token only. Answers the setting as it is now, with
2037
+ * `changed` false when it already was.
2038
+ */
2039
+ setLeadAlert: async (change) => {
2040
+ if (this.appKey)
2041
+ throw setupNeedsAccount();
2042
+ if (change.on === undefined && change.answeredBy === undefined) {
2043
+ throw new AwesomateError('validation', 'setLeadAlert needs on, answeredBy, or both.', 0);
2044
+ }
2045
+ const r = await this.request('PUT', '/api/my-crm/v1/leads/settings', change, false);
2046
+ return { ...leadAlertOf(r), changed: r.changed };
2047
+ },
2048
+ };
1996
2049
  /**
1997
2050
  * Set this up for me: the hub's suggestion for one sentence about what the owner keeps track of
1998
2051
  * ("a job management system"), as a whole setup in the owner's words (fields, stages, lists,
@@ -2221,6 +2274,25 @@ export class AwesomateClient {
2221
2274
  const q = opts.page ? `?page=${encodeURIComponent(String(opts.page))}` : '';
2222
2275
  return (await this.request('GET', `/api/my-business/v2/map/journey/steps/${encodeURIComponent(String(step))}/queue${q}`)).queue;
2223
2276
  }
2277
+ /**
2278
+ * The business's agents in one read: every helper on the map (agents, n8n agents, automations) with
2279
+ * its role, level and who looks after it, what it did in the last 7 or 30 days (conversations, ones
2280
+ * it could not answer or passed to a person, tasks raised, decisions filed, runs and errors), what is
2281
+ * waiting on a person because of it, and its role's KPIs with what feeds each figure. Counts, times
2282
+ * and ids only, never a conversation's or task's words. A figure a kind of helper does not have is
2283
+ * null, never 0. hosting:read and the agentic business feature (`feature_unavailable` otherwise). The
2284
+ * owner's own key reads every helper (`scope` `'all'`); a person's own key reads the helpers on roles
2285
+ * whose KPIs they would see (`'yours'`); a narrow key reads none.
2286
+ *
2287
+ * ```ts
2288
+ * const { rows } = await db.businessAgents({ period: 30 });
2289
+ * for (const a of rows.filter((x) => x.needsPerson.count > 0)) console.log(a.label, a.needsPerson.count);
2290
+ * ```
2291
+ */
2292
+ async businessAgents(opts = {}) {
2293
+ const q = opts.period ? `?period=${encodeURIComponent(String(opts.period))}` : '';
2294
+ return (await this.request('GET', `/api/my-business/v2/map/agents${q}`)).agents;
2295
+ }
2224
2296
  /**
2225
2297
  * The business's KPIs: each a number with a target and someone responsible for it, with where it
2226
2298
  * sits, who answers for it, its light against the target for the last complete period, the period
@@ -2537,6 +2609,7 @@ const BUSINESS_DOC_KINDS = [
2537
2609
  'business_summary', 'products_services', 'usps', 'ideal_customer', 'buyer_persona', 'customer_journey', 'messaging', 'voice_guide',
2538
2610
  'faqs', 'objections', 'article_ideas', 'founder_background', 'testimonials', 'business_history', 'team_directory', 'brand_guide', 'website_brand',
2539
2611
  ];
2612
+ const leadAlertOf = (r) => ({ on: r.on, answeredBy: r.answeredBy, canChange: r.can_change, settingsUrl: r.settings_url });
2540
2613
  function historyQuery(options) {
2541
2614
  const q = new URLSearchParams();
2542
2615
  for (const [k, v] of Object.entries(options)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awesomate/sdk",
3
- "version": "0.90.0",
3
+ "version": "0.92.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",