@masonlandcattle/servicetitan-sdk 0.1.0 → 0.3.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
@@ -25,29 +25,41 @@ Set env vars or pass options:
25
25
  - `SECRET_KEY`
26
26
  - Optional: `ENVIRONMENT` = `production` | `development`
27
27
 
28
- ### Usage
28
+ ### Usage (namespaced client)
29
29
 
30
30
  ```ts
31
- import { ServiceTitanClient, Jobs, Materials, Accounting } from "@masonlandcattle/servicetitan-sdk";
31
+ import { createClient } from "@masonlandcattle/servicetitan-sdk";
32
32
 
33
- const st = new ServiceTitanClient({
34
- tenantId: process.env.TENANT_ID,
35
- appKey: process.env.APP_KEY,
36
- clientId: process.env.CLIENT_ID,
37
- clientSecret: process.env.SECRET_KEY,
33
+ const st = createClient({
34
+ tenantId: process.env.TENANT_ID!,
35
+ appKey: process.env.APP_KEY!,
36
+ clientId: process.env.CLIENT_ID!,
37
+ clientSecret: process.env.SECRET_KEY!,
38
38
  environment: (process.env.ENVIRONMENT as any) || "production",
39
39
  retries: 3,
40
40
  maxConcurrent: 5,
41
41
  minTimeMs: 100,
42
42
  });
43
43
 
44
- const jobs = await Jobs.listJobs(st, { page: 1, pageSize: 100 });
45
- await Jobs.createJobNote(st, 123456, "Hello from SDK", true);
44
+ // List jobs (single page)
45
+ const page = await st.jpm.listJobs({ page: 1, pageSize: 100 });
46
46
 
47
- const mats = await Materials.listMaterials(st, { page: 1, pageSize: 200 });
48
- await Materials.createMaterial(st, { name: "Widget", code: "W-1" });
47
+ // List all jobs server-side (aggregates pages)
48
+ const allJobs = await st.jpm.listJobs({ status: "Open" }, { all: true, pageSize: 500 });
49
49
 
50
- const allInvoices = await Accounting.getAllInvoices(st, { customerId: 42 }, 500);
50
+ // Create a job note
51
+ await st.jpm.createJobNote(123456, { text: "Hello from SDK", pinToTop: true });
52
+
53
+ // Materials (with get-all)
54
+ const materials = await st.pricebook.listMaterials({}, { all: true, pageSize: 500 });
55
+ ```
56
+
57
+ ### Alternate import style (functional)
58
+
59
+ ```ts
60
+ import { ServiceTitanClient, CRM } from "@masonlandcattle/servicetitan-sdk";
61
+ const st = new ServiceTitanClient({ /* creds */ });
62
+ const customers = await CRM.listCustomers(st, { updatedAfter: "2024-01-01" }, { all: true });
51
63
  ```
52
64
 
53
65
  ### Local development / testing without publishing
@@ -74,7 +86,7 @@ These scripts import from `../src`, so there's no need to publish/install.
74
86
 
75
87
  `/{category}/v2/tenant/{TENANT_ID}/{subject}`
76
88
 
77
- Use `client.buildPath({ category, subject, idOrSubpath })` and `client.request(method, path, { params, data })`.
89
+ Use `client.buildPath({ category, subject, idOrSubpath })` and `client.request(method, path, { params, data })`. To fetch every page server-side, pass `{ all: true, pageSize?: number }` to supported list functions.
78
90
 
79
91
  ### Publish
80
92