@awesomate/sdk 0.8.0 → 0.9.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/README.md CHANGED
@@ -160,6 +160,22 @@ await app.write('job', { title: 'Gutters' }, { links: { customer: jo.id } });
160
160
 
161
161
  Name, email and phone only, and nothing the owner marked sensitive. Anyone else is refused.
162
162
 
163
+ An attribute can also be visible to some roles only (`awesomate_crm_kinds`, `set_visibility`, for
164
+ example a cost only `staff` see). For everyone else it comes back `null` and a write that sets it
165
+ is refused, whatever the app asks for.
166
+
167
+ Some things a customer should do without being able to edit the record: accept their quote, say.
168
+ Save it as a write recipe and open it to their role (`awesomate_crm_recipes`, `run_by`, Pro and
169
+ above), then:
170
+
171
+ ```ts
172
+ await app.call('accept_quote', { job: job.id });
173
+ ```
174
+
175
+ The database lets them do exactly the recipe's steps: only its params take their values, every
176
+ other value is fixed, and an existing record must be one they can already read. A recipe not
177
+ opened to their role is "not found".
178
+
163
179
  The rules are kept in your own database, which applies them to every read and write, so a mistake
164
180
  in the app cannot show anyone more than their role allows. A disabled person is refused on their
165
181
  next call. Sessions are kept in `localStorage`; in a Capacitor app pass `storage` (Preferences) and
package/dist/index.d.ts CHANGED
@@ -492,6 +492,13 @@ export declare class AwesomateAppClient {
492
492
  /** Create a record (returns its id) or change one with options.id, inside the kind's write rule for this user. */
493
493
  write<K extends KindName>(kind: K, data: Partial<RowOf<K>> | Record<string, unknown>, options?: WriteOptions): Promise<string>;
494
494
  archive<K extends KindName>(kind: K, id: string): Promise<void>;
495
+ /**
496
+ * Run a recipe the account opened to this person's role: "accept this quote", something their
497
+ * write rule would not let them do by hand. Every step commits or none does; a recipe they may
498
+ * not run reads as not found. Never retried once sent: a write that may have landed is not safe
499
+ * to send twice (a refused sign-in is, and is retried after a refresh like every data call).
500
+ */
501
+ call<R extends RecipeName>(recipe: R, args?: ArgsOf<R>): Promise<RecipeResult>;
495
502
  /**
496
503
  * Customers by name or email (two characters or more), or by id, so staff can find one and put
497
504
  * a record under them. Only for a role the account lets look customers up in this app; anyone
package/dist/index.js CHANGED
@@ -514,6 +514,15 @@ export class AwesomateAppClient {
514
514
  async archive(kind, id) {
515
515
  await this.data('POST', '/call', { fn: 'archive_record', args: { kind, id } });
516
516
  }
517
+ /**
518
+ * Run a recipe the account opened to this person's role: "accept this quote", something their
519
+ * write rule would not let them do by hand. Every step commits or none does; a recipe they may
520
+ * not run reads as not found. Never retried once sent: a write that may have landed is not safe
521
+ * to send twice (a refused sign-in is, and is retried after a refresh like every data call).
522
+ */
523
+ async call(recipe, args = {}) {
524
+ return (await this.data('POST', '/call', { fn: recipe, args })).result;
525
+ }
517
526
  /**
518
527
  * Customers by name or email (two characters or more), or by id, so staff can find one and put
519
528
  * a record under them. Only for a role the account lets look customers up in this app; anyone
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awesomate/sdk",
3
- "version": "0.8.0",
3
+ "version": "0.9.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",