@samsarahq/samsara 0.0.174
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 +21 -0
- package/README.md +197 -0
- package/package.json +71 -0
- package/reference.md +13459 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Samsara.
|
|
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,197 @@
|
|
|
1
|
+
# Samsara TypeScript Library
|
|
2
|
+
|
|
3
|
+
[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fsamsarahq%2Fsamsara-ts)
|
|
4
|
+
[](https://www.npmjs.com/package/@samsarahq/samsara)
|
|
5
|
+
|
|
6
|
+
The Samsara TypeScript library provides convenient access to the Samsara API from TypeScript.
|
|
7
|
+
|
|
8
|
+
## Documentation
|
|
9
|
+
|
|
10
|
+
API reference documentation is available [here](https://developers.samsara.com/reference/overview).
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm i -s @samsarahq/samsara
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Reference
|
|
19
|
+
|
|
20
|
+
A full reference for this library is available [here](https://github.com/samsarahq/samsara-ts/blob/HEAD/./reference.md).
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
Instantiate and use the client with the following:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { SamsaraClient } from "@samsarahq/samsara";
|
|
28
|
+
|
|
29
|
+
const client = new SamsaraClient({ token: "YOUR_TOKEN" });
|
|
30
|
+
const response = await client.vehicles.list();
|
|
31
|
+
for await (const item of response) {
|
|
32
|
+
console.log(item);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Or you can manually iterate page-by-page
|
|
36
|
+
const page = await client.vehicles.list();
|
|
37
|
+
while (page.hasNextPage()) {
|
|
38
|
+
page = page.getNextPage();
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Request And Response Types
|
|
43
|
+
|
|
44
|
+
The SDK exports all request and response types as TypeScript interfaces. Simply import them with the
|
|
45
|
+
following namespace:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { Samsara } from "@samsarahq/samsara";
|
|
49
|
+
|
|
50
|
+
const request: Samsara.AddressesListRequest = {
|
|
51
|
+
...
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Exception Handling
|
|
56
|
+
|
|
57
|
+
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
|
|
58
|
+
will be thrown.
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { SamsaraError } from "@samsarahq/samsara";
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
await client.vehicles.list(...);
|
|
65
|
+
} catch (err) {
|
|
66
|
+
if (err instanceof SamsaraError) {
|
|
67
|
+
console.log(err.statusCode);
|
|
68
|
+
console.log(err.message);
|
|
69
|
+
console.log(err.body);
|
|
70
|
+
console.log(err.rawResponse);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Pagination
|
|
76
|
+
|
|
77
|
+
List endpoints are paginated. The SDK provides an iterator so that you can simply loop over the items:
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { SamsaraClient } from "@samsarahq/samsara";
|
|
81
|
+
|
|
82
|
+
const client = new SamsaraClient({ token: "YOUR_TOKEN" });
|
|
83
|
+
const response = await client.addresses.list();
|
|
84
|
+
for await (const item of response) {
|
|
85
|
+
console.log(item);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Or you can manually iterate page-by-page
|
|
89
|
+
const page = await client.addresses.list();
|
|
90
|
+
while (page.hasNextPage()) {
|
|
91
|
+
page = page.getNextPage();
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Advanced
|
|
96
|
+
|
|
97
|
+
### Additional Headers
|
|
98
|
+
|
|
99
|
+
If you would like to send additional headers as part of the request, use the `headers` request option.
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
const response = await client.vehicles.list(..., {
|
|
103
|
+
headers: {
|
|
104
|
+
'X-Custom-Header': 'custom value'
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Retries
|
|
110
|
+
|
|
111
|
+
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
|
|
112
|
+
as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
|
|
113
|
+
retry limit (default: 2).
|
|
114
|
+
|
|
115
|
+
A request is deemed retryable when any of the following HTTP status codes is returned:
|
|
116
|
+
|
|
117
|
+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
|
|
118
|
+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
|
|
119
|
+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
|
|
120
|
+
|
|
121
|
+
Use the `maxRetries` request option to configure this behavior.
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
const response = await client.vehicles.list(..., {
|
|
125
|
+
maxRetries: 0 // override maxRetries at the request level
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Timeouts
|
|
130
|
+
|
|
131
|
+
The SDK defaults to a 60 second timeout. Use the `timeoutInSeconds` option to configure this behavior.
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
const response = await client.vehicles.list(..., {
|
|
135
|
+
timeoutInSeconds: 30 // override timeout to 30s
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Aborting Requests
|
|
140
|
+
|
|
141
|
+
The SDK allows users to abort requests at any point by passing in an abort signal.
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
const controller = new AbortController();
|
|
145
|
+
const response = await client.vehicles.list(..., {
|
|
146
|
+
abortSignal: controller.signal
|
|
147
|
+
});
|
|
148
|
+
controller.abort(); // aborts the request
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Access Raw Response Data
|
|
152
|
+
|
|
153
|
+
The SDK provides access to raw response data, including headers, through the `.withRawResponse()` method.
|
|
154
|
+
The `.withRawResponse()` method returns a promise that results to an object with a `data` and a `rawResponse` property.
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
const { data, rawResponse } = await client.vehicles.list(...).withRawResponse();
|
|
158
|
+
|
|
159
|
+
console.log(data);
|
|
160
|
+
console.log(rawResponse.headers['X-My-Header']);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Runtime Compatibility
|
|
164
|
+
|
|
165
|
+
The SDK defaults to `node-fetch` but will use the global fetch client if present. The SDK works in the following
|
|
166
|
+
runtimes:
|
|
167
|
+
|
|
168
|
+
- Node.js 18+
|
|
169
|
+
- Vercel
|
|
170
|
+
- Cloudflare Workers
|
|
171
|
+
- Deno v1.25+
|
|
172
|
+
- Bun 1.0+
|
|
173
|
+
- React Native
|
|
174
|
+
|
|
175
|
+
### Customizing Fetch Client
|
|
176
|
+
|
|
177
|
+
The SDK provides a way for you to customize the underlying HTTP client / Fetch function. If you're running in an
|
|
178
|
+
unsupported environment, this provides a way for you to break glass and ensure the SDK works.
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { SamsaraClient } from "@samsarahq/samsara";
|
|
182
|
+
|
|
183
|
+
const client = new SamsaraClient({
|
|
184
|
+
...
|
|
185
|
+
fetcher: // provide your implementation here
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Contributing
|
|
190
|
+
|
|
191
|
+
While we value open-source contributions to this SDK, this library is generated programmatically.
|
|
192
|
+
Additions made directly to this library would have to be moved over to our generation code,
|
|
193
|
+
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
|
|
194
|
+
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
|
|
195
|
+
an issue first to discuss with us!
|
|
196
|
+
|
|
197
|
+
On the other hand, contributions to the README are always very welcome!
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@samsarahq/samsara",
|
|
3
|
+
"version": "0.0.174",
|
|
4
|
+
"private": false,
|
|
5
|
+
"repository": "https://github.com/samsarahq/samsara-ts",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"main": "./dist/cjs/index.js",
|
|
9
|
+
"module": "./dist/esm/index.mjs",
|
|
10
|
+
"types": "./dist/cjs/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/cjs/index.d.ts",
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/esm/index.d.mts",
|
|
16
|
+
"default": "./dist/esm/index.mjs"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/cjs/index.d.ts",
|
|
20
|
+
"default": "./dist/cjs/index.js"
|
|
21
|
+
},
|
|
22
|
+
"default": "./dist/cjs/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"reference.md"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"format": "prettier . --write --ignore-unknown",
|
|
32
|
+
"build": "yarn build:cjs && yarn build:esm",
|
|
33
|
+
"build:cjs": "tsc --project ./tsconfig.cjs.json",
|
|
34
|
+
"build:esm": "tsc --project ./tsconfig.esm.json && node scripts/rename-to-esm-files.js dist/esm",
|
|
35
|
+
"test": "jest tests/unit --passWithNoTests",
|
|
36
|
+
"test:wire": "jest tests/wire --passWithNoTests",
|
|
37
|
+
"wire:test": "yarn test:wire"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"url-join": "4.0.1",
|
|
41
|
+
"form-data": "^4.0.0",
|
|
42
|
+
"formdata-node": "^6.0.3",
|
|
43
|
+
"node-fetch": "^2.7.0",
|
|
44
|
+
"qs": "^6.13.1",
|
|
45
|
+
"readable-stream": "^4.5.2",
|
|
46
|
+
"js-base64": "3.7.7"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/url-join": "4.0.1",
|
|
50
|
+
"@types/qs": "^6.9.17",
|
|
51
|
+
"@types/node-fetch": "^2.6.12",
|
|
52
|
+
"@types/readable-stream": "^4.0.18",
|
|
53
|
+
"webpack": "^5.97.1",
|
|
54
|
+
"ts-loader": "^9.5.1",
|
|
55
|
+
"jest": "^29.7.0",
|
|
56
|
+
"@jest/globals": "^29.7.0",
|
|
57
|
+
"@types/jest": "^29.5.14",
|
|
58
|
+
"ts-jest": "^29.3.4",
|
|
59
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
60
|
+
"msw": "^2.8.4",
|
|
61
|
+
"@types/node": "^18.19.70",
|
|
62
|
+
"prettier": "^3.4.2",
|
|
63
|
+
"typescript": "~5.7.2"
|
|
64
|
+
},
|
|
65
|
+
"browser": {
|
|
66
|
+
"fs": false,
|
|
67
|
+
"os": false,
|
|
68
|
+
"path": false
|
|
69
|
+
},
|
|
70
|
+
"packageManager": "yarn@1.22.22"
|
|
71
|
+
}
|