@masonlandcattle/servicetitan-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 +70 -8
- package/dist/index.cjs +3 -2
- package/dist/index.js +3 -2
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -10,6 +10,11 @@ A pragmatic ServiceTitan API client with:
|
|
|
10
10
|
- Broad tenant API namespace coverage across the current ServiceTitan developer portal
|
|
11
11
|
- Exported TypeScript helper types for better IntelliSense when using the SDK
|
|
12
12
|
|
|
13
|
+
The package supports both:
|
|
14
|
+
|
|
15
|
+
- a namespaced client via `createClient(...)`
|
|
16
|
+
- direct functional imports per namespace when preferred
|
|
17
|
+
|
|
13
18
|
### Release status
|
|
14
19
|
|
|
15
20
|
Current release focus:
|
|
@@ -19,6 +24,24 @@ Current release focus:
|
|
|
19
24
|
- Added missing documented resource modules and helpers
|
|
20
25
|
- Expanded exported TypeScript helper types to improve IntelliSense
|
|
21
26
|
|
|
27
|
+
Recommended release posture for the current line:
|
|
28
|
+
|
|
29
|
+
- `0.9.x` is the stabilization phase after the broad OpenAPI alignment pass
|
|
30
|
+
- the current public surface is intended to be much closer to the local OpenAPI specs than earlier releases
|
|
31
|
+
- future breaking changes should mostly be reserved for upstream ServiceTitan API changes or clear correctness fixes
|
|
32
|
+
|
|
33
|
+
### Repo notes
|
|
34
|
+
|
|
35
|
+
If you are editing this SDK with Codex or another coding agent, use [`AGENTS.md`](./AGENTS.md) as the repo-specific guide.
|
|
36
|
+
|
|
37
|
+
The short version:
|
|
38
|
+
|
|
39
|
+
- local OpenAPI JSON files are the source of truth
|
|
40
|
+
- breaking changes are acceptable when the schema and SDK disagree
|
|
41
|
+
- prefer namespace-specific types over generic placeholders
|
|
42
|
+
- keep [`src/types/resources.ts`](./src/types/resources.ts) for shared base helpers only
|
|
43
|
+
- run `npm run build` after changes
|
|
44
|
+
|
|
22
45
|
### Install
|
|
23
46
|
|
|
24
47
|
```bash
|
|
@@ -64,6 +87,27 @@ await st.jpm.createJobNote(123456, { text: "Hello from SDK", pinToTop: true });
|
|
|
64
87
|
const materials = await st.pricebook.listMaterials({}, { all: true, pageSize: 500 });
|
|
65
88
|
```
|
|
66
89
|
|
|
90
|
+
### Important behaviors
|
|
91
|
+
|
|
92
|
+
- Local OpenAPI JSON files in [`ServiceTitanOpenAPIJson`](./ServiceTitanOpenAPIJson) are the source of truth for this SDK.
|
|
93
|
+
- Breaking changes are allowed when the documented ServiceTitan contract and the previous SDK surface disagree.
|
|
94
|
+
- Export feeds generally use `{ from, includeRecentChanges }` continuation params and return `{ data, hasMore, continueFrom }`.
|
|
95
|
+
- Binary telecom media endpoints return `ArrayBuffer`.
|
|
96
|
+
- `options.all` is only used on endpoints with safe paginated `data` plus `hasMore` behavior.
|
|
97
|
+
|
|
98
|
+
### Known limits
|
|
99
|
+
|
|
100
|
+
- Webhook verification helpers are not included yet. The public docs available in this repo workflow are not specific enough to safely implement the exact signature contract.
|
|
101
|
+
- Some nested model fields are still intentionally broad where the upstream schema is weak or highly open-ended.
|
|
102
|
+
- This package is an API SDK, not an application framework. Queueing, persistence, workflow orchestration, and webhook hosting should stay in the consuming app.
|
|
103
|
+
- ServiceTitan may change upstream schemas over time. When that happens, the local OpenAPI JSON files should be updated first, then the SDK should be realigned to match.
|
|
104
|
+
|
|
105
|
+
### Docs map
|
|
106
|
+
|
|
107
|
+
- [`README.md`](./README.md): install, usage, examples, and package behavior
|
|
108
|
+
- [`AGENTS.md`](./AGENTS.md): repo-specific engineering rules for Codex and contributors
|
|
109
|
+
- [`docs/architecture.md`](./docs/architecture.md): structure, boundaries, and extension patterns
|
|
110
|
+
|
|
67
111
|
### Resources and quick examples
|
|
68
112
|
|
|
69
113
|
Below is a brief tour of the main resource namespaces. Each list function supports `{ all?: boolean; pageSize?: number }` to fetch all pages server‑side.
|
|
@@ -165,10 +209,19 @@ const appts = await st.jpm.listAppointments({ scheduledOnOrAfter: "2025-01-01" }
|
|
|
165
209
|
```
|
|
166
210
|
|
|
167
211
|
#### Marketing (`st.marketing`) and Marketing Ads (`st.marketingAds`)
|
|
168
|
-
- Campaigns/Categories/Costs
|
|
212
|
+
- Campaigns/Categories/Costs; Ads Attributions, Performance, and Capacity Warnings.
|
|
169
213
|
```ts
|
|
170
214
|
const campaigns = await st.marketing.listCampaigns({}, { all: true });
|
|
171
|
-
|
|
215
|
+
await st.marketingAds.createWebLeadFormAttribution({
|
|
216
|
+
leadId: 42,
|
|
217
|
+
webSessionData: {
|
|
218
|
+
landingPageUrl: "https://example.com/landing",
|
|
219
|
+
referrerUrl: "https://google.com",
|
|
220
|
+
utmSource: "google",
|
|
221
|
+
utmMedium: "cpc",
|
|
222
|
+
utmCampaign: "spring-promo",
|
|
223
|
+
},
|
|
224
|
+
});
|
|
172
225
|
```
|
|
173
226
|
|
|
174
227
|
#### Marketing Reputation (`st.marketingReputation`)
|
|
@@ -262,16 +315,18 @@ The package exports helper types from the root for stronger autocomplete and pay
|
|
|
262
315
|
|
|
263
316
|
```ts
|
|
264
317
|
import type {
|
|
265
|
-
|
|
318
|
+
CrmExportCustomer,
|
|
319
|
+
CreateEstimateRequest,
|
|
320
|
+
CreateWebLeadFormAttributionRequest,
|
|
266
321
|
Contact,
|
|
267
322
|
ContactMethodCreatePayload,
|
|
268
323
|
CustomerInteractionsExportResponse,
|
|
269
|
-
EstimatePayload,
|
|
270
|
-
ExportParams,
|
|
271
324
|
FindingCreatePayload,
|
|
272
325
|
Invoice,
|
|
273
|
-
|
|
274
|
-
|
|
326
|
+
JpmExportJob,
|
|
327
|
+
MarketingAdsPerformanceRecord,
|
|
328
|
+
SalesEstimatesExportResponse,
|
|
329
|
+
TelecomExportCall,
|
|
275
330
|
} from "@masonlandcattle/servicetitan-sdk";
|
|
276
331
|
```
|
|
277
332
|
|
|
@@ -282,7 +337,7 @@ Many resource methods now use typed params and payload helpers directly, so edit
|
|
|
282
337
|
```ts
|
|
283
338
|
import { ServiceTitanClient, CRM } from "@masonlandcattle/servicetitan-sdk";
|
|
284
339
|
const st = new ServiceTitanClient({ /* creds */ });
|
|
285
|
-
const customers = await CRM.listCustomers(st, {
|
|
340
|
+
const customers = await CRM.listCustomers(st, { createdOnOrAfter: "2024-01-01" }, { all: true });
|
|
286
341
|
```
|
|
287
342
|
|
|
288
343
|
### Local development / testing without publishing
|
|
@@ -301,6 +356,9 @@ Run local example scripts directly against the source using `tsx`.
|
|
|
301
356
|
npm run ex:crm
|
|
302
357
|
npm run ex:dispatch
|
|
303
358
|
npm run ex:equip
|
|
359
|
+
npm run ex:namespaced
|
|
360
|
+
npm run ex:crm-export
|
|
361
|
+
npm run ex:telecom-media
|
|
304
362
|
```
|
|
305
363
|
|
|
306
364
|
These scripts import from `../src`, so there's no need to publish/install.
|
|
@@ -311,6 +369,10 @@ These scripts import from `../src`, so there's no need to publish/install.
|
|
|
311
369
|
|
|
312
370
|
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.
|
|
313
371
|
|
|
372
|
+
### Contributing / Codex
|
|
373
|
+
|
|
374
|
+
If you are updating the SDK with Codex or another coding agent, read [`AGENTS.md`](./AGENTS.md) first. It captures the repo conventions used for the OpenAPI alignment work.
|
|
375
|
+
|
|
314
376
|
### Publish
|
|
315
377
|
|
|
316
378
|
```bash
|
package/dist/index.cjs
CHANGED
|
@@ -108,8 +108,9 @@ var ServiceTitanClient = class {
|
|
|
108
108
|
});
|
|
109
109
|
this.axiosInstance.interceptors.request.use((config) => {
|
|
110
110
|
if (this.token) {
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
const headers = config.headers ?? {};
|
|
112
|
+
headers.Authorization = `Bearer ${this.token}`;
|
|
113
|
+
config.headers = headers;
|
|
113
114
|
}
|
|
114
115
|
return config;
|
|
115
116
|
});
|
package/dist/index.js
CHANGED
|
@@ -49,8 +49,9 @@ var ServiceTitanClient = class {
|
|
|
49
49
|
});
|
|
50
50
|
this.axiosInstance.interceptors.request.use((config) => {
|
|
51
51
|
if (this.token) {
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
const headers = config.headers ?? {};
|
|
53
|
+
headers.Authorization = `Bearer ${this.token}`;
|
|
54
|
+
config.headers = headers;
|
|
54
55
|
}
|
|
55
56
|
return config;
|
|
56
57
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@masonlandcattle/servicetitan-sdk",
|
|
3
3
|
"author": "Mason Land & Cattle (https://github.com/MasonLandCattle)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.0",
|
|
5
5
|
"description": "ServiceTitan API SDK for Node.js and TypeScript with retries, rate limiting, pagination, and broad tenant API coverage.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"servicetitan",
|
|
@@ -43,7 +43,10 @@
|
|
|
43
43
|
"ex:crm": "tsx examples/quick-crm.ts",
|
|
44
44
|
"ex:dispatch": "tsx examples/quick-dispatch.ts",
|
|
45
45
|
"ex:equip": "tsx examples/quick-equipment.ts",
|
|
46
|
-
"ex:jobs": "tsx examples/quick-jobs.ts"
|
|
46
|
+
"ex:jobs": "tsx examples/quick-jobs.ts",
|
|
47
|
+
"ex:namespaced": "tsx examples/namespaced-client.ts",
|
|
48
|
+
"ex:crm-export": "tsx examples/export-crm-customers.ts",
|
|
49
|
+
"ex:telecom-media": "tsx examples/telecom-media.ts"
|
|
47
50
|
},
|
|
48
51
|
"dependencies": {
|
|
49
52
|
"axios": "^1.7.7",
|