@awesomate/sdk 0.51.0 → 0.52.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.51.0";
29
+ export declare const VERSION = "0.52.0";
30
30
  /** Augmented by the generated awesomate.d.ts, so each kind's rows are typed. */
31
31
  export interface Kinds {
32
32
  }
@@ -1349,6 +1349,21 @@ export declare class AwesomateClient {
1349
1349
  * const { id, created } = await db.upsertByRef('job', { system: 'servicem8', externalId: 'JOB-0042' }, { title: 'Possum in the roof' }, { links: { customer: contactId } });
1350
1350
  */
1351
1351
  upsertByRef<K extends KindName>(kind: K, ref: RecordRef, data?: Partial<RowOf<K>> | Record<string, unknown>, options?: Omit<WriteOptions, 'id'>): Promise<UpsertByRefResult>;
1352
+ /**
1353
+ * The record that mirrors one in another system, read back by that system's name and its id there
1354
+ * (the same `ref` upsertByRef() keys on), so a sync can ask "do I have Xero invoice INV-0042?"
1355
+ * without keeping our ids. Answers the row exactly as get() reads it (fields readable by AI only),
1356
+ * or null when this kind has no record with that id. A record with that id that was archived throws
1357
+ * `conflict` (as upsertByRef() does): a sync leaves it alone rather than making another. Contacts and
1358
+ * companies have no outside ids. The account's token only (never an app key), crm:read, every plan.
1359
+ *
1360
+ * @example
1361
+ * const job = await db.getByRef('job', { system: 'servicem8', externalId: 'JOB-0042' });
1362
+ * if (!job) await db.upsertByRef('job', { system: 'servicem8', externalId: 'JOB-0042' }, { title: 'Possum in the roof' });
1363
+ */
1364
+ getByRef<K extends KindName>(kind: K, ref: RecordRef, options?: {
1365
+ tz?: string;
1366
+ }): Promise<RowOf<K> | null>;
1352
1367
  /** The saved queries on this account. crm:read, every plan: the account's token or an app key. */
1353
1368
  queries(): Promise<SavedQueryDescription[]>;
1354
1369
  /**
@@ -2357,7 +2372,7 @@ export interface WriteOptions {
2357
2372
  /** Set a link by its key ('<id>'), or end it (null). */
2358
2373
  links?: Record<string, string | null>;
2359
2374
  }
2360
- /** Which record in another system a record mirrors, for upsertByRef(). */
2375
+ /** Which record in another system a record mirrors, for upsertByRef() and getByRef(). */
2361
2376
  export interface RecordRef {
2362
2377
  /** That system's name, lower case: letters, digits, `_`, `.` or `-`, at most 40 characters (`xero`, `shopify`). */
2363
2378
  system: 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.51.0';
29
+ export const VERSION = '0.52.0';
30
30
  const DEFAULT_BASE = 'https://hub.awesomate.ai';
31
31
  /** Every record and contact id is a UUID; anything else can name no row. */
32
32
  const RECORD_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -1181,6 +1181,27 @@ export class AwesomateClient {
1181
1181
  }, false);
1182
1182
  return r.result;
1183
1183
  }
1184
+ /**
1185
+ * The record that mirrors one in another system, read back by that system's name and its id there
1186
+ * (the same `ref` upsertByRef() keys on), so a sync can ask "do I have Xero invoice INV-0042?"
1187
+ * without keeping our ids. Answers the row exactly as get() reads it (fields readable by AI only),
1188
+ * or null when this kind has no record with that id. A record with that id that was archived throws
1189
+ * `conflict` (as upsertByRef() does): a sync leaves it alone rather than making another. Contacts and
1190
+ * companies have no outside ids. The account's token only (never an app key), crm:read, every plan.
1191
+ *
1192
+ * @example
1193
+ * const job = await db.getByRef('job', { system: 'servicem8', externalId: 'JOB-0042' });
1194
+ * if (!job) await db.upsertByRef('job', { system: 'servicem8', externalId: 'JOB-0042' }, { title: 'Possum in the roof' });
1195
+ */
1196
+ async getByRef(kind, ref, options = {}) {
1197
+ if (this.appKey)
1198
+ throw new AwesomateError('forbidden', "getByRef needs the account's token (amt_pat_...). An app key reads records with get() and query().", 0);
1199
+ const qs = new URLSearchParams({ system: ref.system, external_id: ref.externalId });
1200
+ if (options.tz)
1201
+ qs.set('tz', options.tz);
1202
+ const r = await nullIfMissing(this.request('GET', `/api/my-crm/v1/records/${encodeURIComponent(kind)}/by-ref?${qs}`));
1203
+ return r ? r.row : null;
1204
+ }
1184
1205
  /** The saved queries on this account. crm:read, every plan: the account's token or an app key. */
1185
1206
  async queries() {
1186
1207
  return (await this.request('GET', '/api/my-crm/v1/queries')).queries;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awesomate/sdk",
3
- "version": "0.51.0",
3
+ "version": "0.52.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",