@masonlandcattle/servicetitan-sdk 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 MasonLandCattle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ ## ServiceTitan SDK (Node.js / TypeScript)
2
+
3
+ A pragmatic ServiceTitan API client with:
4
+
5
+ - Robust auth (Client Credentials)
6
+ - **Retries** with exponential backoff + jitter
7
+ - Honors **Retry-After**, handles 429/5xx
8
+ - **Rate limiting** with Bottleneck (concurrency + minTime)
9
+ - URL builder and **pagination** helpers (`getAll`)
10
+ - Modular resources (Jobs, Appointments, Materials, Accounting/Invoices)
11
+
12
+ ### Install
13
+
14
+ ```bash
15
+ npm install @masonlandcattle/servicetitan-sdk
16
+ ```
17
+
18
+ ### Configure
19
+
20
+ Set env vars or pass options:
21
+
22
+ - `TENANT_ID`
23
+ - `APP_KEY`
24
+ - `CLIENT_ID`
25
+ - `SECRET_KEY`
26
+ - Optional: `ENVIRONMENT` = `production` | `development`
27
+
28
+ ### Usage
29
+
30
+ ```ts
31
+ import { ServiceTitanClient, Jobs, Materials, Accounting } from "@masonlandcattle/servicetitan-sdk";
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,
38
+ environment: (process.env.ENVIRONMENT as any) || "production",
39
+ retries: 3,
40
+ maxConcurrent: 5,
41
+ minTimeMs: 100,
42
+ });
43
+
44
+ const jobs = await Jobs.listJobs(st, { page: 1, pageSize: 100 });
45
+ await Jobs.createJobNote(st, 123456, "Hello from SDK", true);
46
+
47
+ const mats = await Materials.listMaterials(st, { page: 1, pageSize: 200 });
48
+ await Materials.createMaterial(st, { name: "Widget", code: "W-1" });
49
+
50
+ const allInvoices = await Accounting.getAllInvoices(st, { customerId: 42 }, 500);
51
+ ```
52
+
53
+ ### Local development / testing without publishing
54
+
55
+ Run local example scripts directly against the source using `tsx`.
56
+
57
+ 1. Set environment variables:
58
+ - `TENANT_ID`
59
+ - `APP_KEY`
60
+ - `CLIENT_ID`
61
+ - `SECRET_KEY`
62
+
63
+ 2. Execute examples:
64
+
65
+ ```bash
66
+ npm run ex:crm
67
+ npm run ex:dispatch
68
+ npm run ex:equip
69
+ ```
70
+
71
+ These scripts import from `../src`, so there's no need to publish/install.
72
+
73
+ ### API Shape
74
+
75
+ `/{category}/v2/tenant/{TENANT_ID}/{subject}`
76
+
77
+ Use `client.buildPath({ category, subject, idOrSubpath })` and `client.request(method, path, { params, data })`.
78
+
79
+ ### Publish
80
+
81
+ ```bash
82
+ npm run build
83
+ npm publish --access public
84
+ ```
85
+
86
+ > Not affiliated with ServiceTitan. Respect rate limits and terms.