particle-api-js 11.1.7 → 12.0.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 +90 -10
- package/dist/particle.min.js +1 -1
- package/dist/particle.min.js.map +1 -1
- package/fs.d.ts +2 -0
- package/lib/fs.d.ts +2 -0
- package/lib/fs.js +3 -0
- package/lib/package.json +109 -0
- package/lib/src/Agent.d.ts +38 -0
- package/lib/src/Agent.d.ts.map +1 -0
- package/lib/src/Agent.js +228 -0
- package/lib/src/Agent.js.map +1 -0
- package/lib/src/Client.d.ts +80 -0
- package/lib/src/Client.d.ts.map +1 -0
- package/lib/src/Client.js +104 -0
- package/lib/src/Client.js.map +1 -0
- package/lib/src/Defaults.d.ts +6 -0
- package/lib/src/Defaults.d.ts.map +1 -0
- package/lib/src/Defaults.js +12 -0
- package/lib/src/Defaults.js.map +1 -0
- package/lib/src/EventStream.d.ts +29 -0
- package/lib/src/EventStream.d.ts.map +1 -0
- package/lib/src/EventStream.js +270 -0
- package/lib/src/EventStream.js.map +1 -0
- package/lib/src/Library.d.ts +33 -0
- package/lib/src/Library.d.ts.map +1 -0
- package/lib/src/Library.js +19 -0
- package/lib/src/Library.js.map +1 -0
- package/{src/Particle.js → lib/src/Particle.d.ts} +790 -1666
- package/lib/src/Particle.d.ts.map +1 -0
- package/lib/src/Particle.js +2794 -0
- package/lib/src/Particle.js.map +1 -0
- package/lib/src/types/common.d.ts +71 -0
- package/lib/src/types/common.d.ts.map +1 -0
- package/lib/src/types/common.js +3 -0
- package/lib/src/types/common.js.map +1 -0
- package/lib/src/types/index.d.ts +4 -0
- package/lib/src/types/index.d.ts.map +1 -0
- package/lib/src/types/index.js +20 -0
- package/lib/src/types/index.js.map +1 -0
- package/lib/src/types/requests.d.ts +667 -0
- package/lib/src/types/requests.d.ts.map +1 -0
- package/lib/src/types/requests.js +3 -0
- package/lib/src/types/requests.js.map +1 -0
- package/lib/src/types/responses.d.ts +472 -0
- package/lib/src/types/responses.d.ts.map +1 -0
- package/lib/src/types/responses.js +3 -0
- package/lib/src/types/responses.js.map +1 -0
- package/package.json +34 -14
- package/scripts/postprocess-docs.js +306 -0
- package/typedoc.json +20 -0
- package/.circleci/config.yml +0 -104
- package/.nvmrc +0 -1
- package/CHANGELOG.md +0 -404
- package/EventStream-e2e-browser.html +0 -39
- package/EventStream-e2e-node.js +0 -34
- package/RELEASE.md +0 -12
- package/bower.json +0 -30
- package/docs/api.md +0 -2594
- package/eslint.config.mjs +0 -7
- package/examples/login/login.html +0 -17
- package/karma.conf.js +0 -80
- package/src/Agent.js +0 -397
- package/src/Client.js +0 -171
- package/src/Defaults.js +0 -8
- package/src/EventStream.js +0 -269
- package/src/Library.js +0 -33
- package/test/Agent.integration.js +0 -23
- package/test/Agent.spec.js +0 -488
- package/test/Client.spec.js +0 -216
- package/test/Defaults.spec.js +0 -30
- package/test/EventStream.feature +0 -65
- package/test/EventStream.spec.js +0 -263
- package/test/FakeAgent.js +0 -27
- package/test/Library.spec.js +0 -40
- package/test/Particle.integration.js +0 -38
- package/test/Particle.spec.js +0 -3198
- package/test/fixtures/index.js +0 -15
- package/test/fixtures/libraries.json +0 -33
- package/test/fixtures/library.json +0 -31
- package/test/fixtures/libraryVersions.json +0 -211
- package/test/out.tmp +0 -0
- package/test/support/FixtureHttpServer.js +0 -28
- package/test/test-setup.js +0 -17
- package/tsconfig.json +0 -17
- package/webpack.config.js +0 -46
package/README.md
CHANGED
|
@@ -5,6 +5,31 @@ JS Library for the Particle Cloud API for Node.js and the browser
|
|
|
5
5
|
|
|
6
6
|
[Installation](#installation) | [Development](#development) | [Conventions](#conventions) | [Docs](#docs--resources) | [Examples](#examples) | [Building](#building) | [Releasing](#releasing) | [License](#license)
|
|
7
7
|
|
|
8
|
+
## TypeScript Support
|
|
9
|
+
|
|
10
|
+
`particle-api-js` is written in TypeScript and ships with full type declarations. All methods return fully typed responses — no casting needed:
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import Particle from 'particle-api-js';
|
|
14
|
+
import type { DeviceInfo, LoginResponse, JSONResponse } from 'particle-api-js';
|
|
15
|
+
|
|
16
|
+
const particle = new Particle({ auth: 'your-token' });
|
|
17
|
+
|
|
18
|
+
// Response body is fully typed — no casting needed
|
|
19
|
+
const response = await particle.getDevice({ deviceId: 'abc123' });
|
|
20
|
+
console.log(response.body.name); // string — fully typed as DeviceInfo
|
|
21
|
+
|
|
22
|
+
// Login response
|
|
23
|
+
const loginResponse = await particle.login({ username: 'user@example.com', password: 'pass' });
|
|
24
|
+
const token = loginResponse.body.access_token; // string
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
All request option types and response types are exported from the package:
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import type { GetDeviceOptions, ListDevicesOptions, JSONResponse } from 'particle-api-js';
|
|
31
|
+
```
|
|
32
|
+
|
|
8
33
|
## Installation
|
|
9
34
|
|
|
10
35
|
`particle-api-js` is available from `npm` to use in Node.js, `bower` or jsDelivr CDN for use in the browser.
|
|
@@ -30,21 +55,76 @@ $ bower install particle-api-js
|
|
|
30
55
|
|
|
31
56
|
All essential commands are available at the root via `npm run <script name>` - e.g. `npm run lint`. To view the available commands, run: `npm run`
|
|
32
57
|
|
|
33
|
-
<details id="develop-
|
|
34
|
-
<summary><b>
|
|
35
|
-
<p>
|
|
58
|
+
<details id="develop-testing">
|
|
59
|
+
<summary><b>Testing Guide</b></summary>
|
|
36
60
|
|
|
37
|
-
|
|
61
|
+
### Running Tests
|
|
38
62
|
|
|
39
|
-
|
|
63
|
+
```bash
|
|
64
|
+
npm test # lint + typecheck + unit tests
|
|
65
|
+
npm run test:unit # unit tests only
|
|
66
|
+
npm run test:watch # unit tests in watch mode
|
|
67
|
+
npm run test:browser # browser tests via karma
|
|
68
|
+
npm run coverage # unit tests with coverage report
|
|
69
|
+
```
|
|
40
70
|
|
|
41
|
-
`
|
|
71
|
+
The `Agent` integration tests ([source](./test/Agent.integration.ts)) depend on a real HTTP API backend and a valid Particle access token. Set environment variables to avoid test failures:
|
|
42
72
|
|
|
43
|
-
|
|
73
|
+
```bash
|
|
74
|
+
PARTICLE_API_BASE_URL=<url> PARTICLE_API_TOKEN=<token> npm test
|
|
75
|
+
```
|
|
44
76
|
|
|
45
|
-
|
|
77
|
+
### Test Structure
|
|
78
|
+
|
|
79
|
+
- All test files are TypeScript (`.spec.ts`, `.test.ts`, `.integration.ts`) in the `test/` directory
|
|
80
|
+
- Tests use `import` syntax — compiled output uses `require()` via `module: "commonjs"` in `tsconfig.json`
|
|
81
|
+
- Test runner: [mocha](https://mochajs.org/) with [tsx](https://github.com/privatenumber/tsx) for direct `.ts` execution (no pre-compilation needed)
|
|
82
|
+
- Assertions: [chai](https://www.chaijs.com/) (`expect` style) + [chai-subset](https://github.com/debitoor/chai-subset) for partial matching + [sinon-chai](https://github.com/domenic/sinon-chai) for spy/stub assertions + [chai-as-promised](https://github.com/domenic/chai-as-promised) for promise assertions
|
|
83
|
+
- Mocking: [sinon](https://sinonjs.org/)
|
|
84
|
+
|
|
85
|
+
### Writing a New Test
|
|
86
|
+
|
|
87
|
+
1. Create a file in `test/` following the naming convention: `<Module>.spec.ts`
|
|
88
|
+
2. Import the test setup and modules:
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { sinon, expect } from './test-setup';
|
|
92
|
+
import MyModule from '../src/MyModule';
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
3. Use `describe`/`it` blocks with `expect` assertions:
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
describe('MyModule', () => {
|
|
99
|
+
afterEach(() => {
|
|
100
|
+
sinon.restore();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('does something', () => {
|
|
104
|
+
const result = new MyModule();
|
|
105
|
+
expect(result.value).to.equal('expected');
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
4. For partial object matching, use `containSubset`:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
expect(result).to.containSubset({
|
|
114
|
+
method: 'get',
|
|
115
|
+
uri: '/v1/devices'
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
5. Run your tests: `npm run test:unit`
|
|
120
|
+
|
|
121
|
+
### Key Conventions
|
|
122
|
+
|
|
123
|
+
- Always import from `../src/<Module>` (not `../lib/src/<Module>`)
|
|
124
|
+
- Use `sinon.restore()` in `afterEach` to clean up stubs
|
|
125
|
+
- Use `FakeAgent` (in `test/FakeAgent.ts`) for mocking HTTP requests in Particle API tests
|
|
126
|
+
- Avoid `any` and `unknown` types in test files
|
|
46
127
|
|
|
47
|
-
</p>
|
|
48
128
|
</details>
|
|
49
129
|
|
|
50
130
|
<details id="develop-run-locally">
|
|
@@ -102,7 +182,7 @@ sometimes your new script will be very similar to an existing script. in those c
|
|
|
102
182
|
* document developer-facing process / tooling instructions in the [Development](#development) section
|
|
103
183
|
* plan to release your changes upon merging to `main` - refrain from merging if you cannot so you don't leave unpublished changes to others
|
|
104
184
|
* avoid making changes in files unrelated to the work you are doing so you aren't having to publish trivial updates
|
|
105
|
-
* test files live
|
|
185
|
+
* test files live in the `test/` directory and are named like `*.spec.ts`, `*.test.ts`, or `*.integration.ts`
|
|
106
186
|
* if the linter does not flag your code (error or warning), it's formatted properly
|
|
107
187
|
* avoid reformatting unflagged code as it can obscure more meaningful changes and increase the chance of merge conflicts
|
|
108
188
|
* todo comments include your last name and are formatted like: `TODO (mirande): <message>`
|