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.
Files changed (85) hide show
  1. package/README.md +90 -10
  2. package/dist/particle.min.js +1 -1
  3. package/dist/particle.min.js.map +1 -1
  4. package/fs.d.ts +2 -0
  5. package/lib/fs.d.ts +2 -0
  6. package/lib/fs.js +3 -0
  7. package/lib/package.json +109 -0
  8. package/lib/src/Agent.d.ts +38 -0
  9. package/lib/src/Agent.d.ts.map +1 -0
  10. package/lib/src/Agent.js +228 -0
  11. package/lib/src/Agent.js.map +1 -0
  12. package/lib/src/Client.d.ts +80 -0
  13. package/lib/src/Client.d.ts.map +1 -0
  14. package/lib/src/Client.js +104 -0
  15. package/lib/src/Client.js.map +1 -0
  16. package/lib/src/Defaults.d.ts +6 -0
  17. package/lib/src/Defaults.d.ts.map +1 -0
  18. package/lib/src/Defaults.js +12 -0
  19. package/lib/src/Defaults.js.map +1 -0
  20. package/lib/src/EventStream.d.ts +29 -0
  21. package/lib/src/EventStream.d.ts.map +1 -0
  22. package/lib/src/EventStream.js +270 -0
  23. package/lib/src/EventStream.js.map +1 -0
  24. package/lib/src/Library.d.ts +33 -0
  25. package/lib/src/Library.d.ts.map +1 -0
  26. package/lib/src/Library.js +19 -0
  27. package/lib/src/Library.js.map +1 -0
  28. package/{src/Particle.js → lib/src/Particle.d.ts} +790 -1666
  29. package/lib/src/Particle.d.ts.map +1 -0
  30. package/lib/src/Particle.js +2794 -0
  31. package/lib/src/Particle.js.map +1 -0
  32. package/lib/src/types/common.d.ts +71 -0
  33. package/lib/src/types/common.d.ts.map +1 -0
  34. package/lib/src/types/common.js +3 -0
  35. package/lib/src/types/common.js.map +1 -0
  36. package/lib/src/types/index.d.ts +4 -0
  37. package/lib/src/types/index.d.ts.map +1 -0
  38. package/lib/src/types/index.js +20 -0
  39. package/lib/src/types/index.js.map +1 -0
  40. package/lib/src/types/requests.d.ts +667 -0
  41. package/lib/src/types/requests.d.ts.map +1 -0
  42. package/lib/src/types/requests.js +3 -0
  43. package/lib/src/types/requests.js.map +1 -0
  44. package/lib/src/types/responses.d.ts +472 -0
  45. package/lib/src/types/responses.d.ts.map +1 -0
  46. package/lib/src/types/responses.js +3 -0
  47. package/lib/src/types/responses.js.map +1 -0
  48. package/package.json +34 -14
  49. package/scripts/postprocess-docs.js +306 -0
  50. package/typedoc.json +20 -0
  51. package/.circleci/config.yml +0 -104
  52. package/.nvmrc +0 -1
  53. package/CHANGELOG.md +0 -404
  54. package/EventStream-e2e-browser.html +0 -39
  55. package/EventStream-e2e-node.js +0 -34
  56. package/RELEASE.md +0 -12
  57. package/bower.json +0 -30
  58. package/docs/api.md +0 -2594
  59. package/eslint.config.mjs +0 -7
  60. package/examples/login/login.html +0 -17
  61. package/karma.conf.js +0 -80
  62. package/src/Agent.js +0 -397
  63. package/src/Client.js +0 -171
  64. package/src/Defaults.js +0 -8
  65. package/src/EventStream.js +0 -269
  66. package/src/Library.js +0 -33
  67. package/test/Agent.integration.js +0 -23
  68. package/test/Agent.spec.js +0 -488
  69. package/test/Client.spec.js +0 -216
  70. package/test/Defaults.spec.js +0 -30
  71. package/test/EventStream.feature +0 -65
  72. package/test/EventStream.spec.js +0 -263
  73. package/test/FakeAgent.js +0 -27
  74. package/test/Library.spec.js +0 -40
  75. package/test/Particle.integration.js +0 -38
  76. package/test/Particle.spec.js +0 -3198
  77. package/test/fixtures/index.js +0 -15
  78. package/test/fixtures/libraries.json +0 -33
  79. package/test/fixtures/library.json +0 -31
  80. package/test/fixtures/libraryVersions.json +0 -211
  81. package/test/out.tmp +0 -0
  82. package/test/support/FixtureHttpServer.js +0 -28
  83. package/test/test-setup.js +0 -17
  84. package/tsconfig.json +0 -17
  85. 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-run-tests">
34
- <summary><b>How to run your tests</b></summary>
35
- <p>
58
+ <details id="develop-testing">
59
+ <summary><b>Testing Guide</b></summary>
36
60
 
37
- The `Agent` integration tests ([source](./test/Agent.integration.js)) depend on a real HTTP api backend and a valid Particle access token. Be sure to set relevant environment variables to avoid test failures. You can prefix commands test commands like this `PARTICLE_API_BASE_URL=<url> PARTICLE_API_TOKEN=<token> npm test`
61
+ ### Running Tests
38
62
 
39
- `npm test` runs the tests.
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
- `npm run coverage` shows code coverage
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
- `npm run test:browser` runs tests in a browser via [karma](https://karma-runner.github.io/latest/index.html).
73
+ ```bash
74
+ PARTICLE_API_BASE_URL=<url> PARTICLE_API_TOKEN=<token> npm test
75
+ ```
44
76
 
45
- `npm run test:ci` runs tests in the exact same way CI system does
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 alongside their source files and are named like `*.test.js` or `*.spec.js`
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>`