├── .circleci └── config.yml ├── .gitignore ├── .npmignore ├── .nvmrc ├── CHANGELOG.md ├── EventStream-e2e-browser.html ├── EventStream-e2e-node.js ├── LICENSE ├── README.md ├── RELEASE.md ├── bower.json ├── dist ├── particle.min.js └── particle.min.js.map ├── docs └── api.md ├── eslint.config.mjs ├── examples └── login │ └── login.html ├── fs.js ├── karma.conf.js ├── package-lock.json ├── package.json ├── src ├── Agent.js ├── Client.js ├── Defaults.js ├── EventStream.js ├── Library.js └── Particle.js ├── test ├── Agent.integration.js ├── Agent.spec.js ├── Client.spec.js ├── Defaults.spec.js ├── EventStream.feature ├── EventStream.spec.js ├── FakeAgent.js ├── Library.spec.js ├── Particle.integration.js ├── Particle.spec.js ├── fixtures │ ├── index.js │ ├── libraries.json │ ├── library.json │ └── libraryVersions.json ├── out.tmp ├── support │ └── FixtureHttpServer.js └── test-setup.js ├── tsconfig.json └── webpack.config.js /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | orbs: 4 | browser-tools: circleci/browser-tools@2.2.0 5 | 6 | jobs: 7 | lint: 8 | docker: 9 | - image: cimg/node:22.18 # eslint 9.x requires 18+, so we've separated it from the test step 10 | auth: 11 | username: $DOCKERHUB_USERNAME 12 | password: $DOCKERHUB_PASSWORD 13 | steps: 14 | - checkout 15 | - run: 16 | name: NPM install 17 | command: npm ci 18 | - run: 19 | name: Lint 20 | command: npm run lint 21 | run-tests: 22 | parameters: 23 | node-version: 24 | type: string 25 | docker: 26 | - image: cimg/node:<< parameters.node-version >>-browsers # Primary execution image 27 | auth: 28 | username: $DOCKERHUB_USERNAME 29 | password: $DOCKERHUB_PASSWORD 30 | steps: 31 | - checkout 32 | - run: 33 | name: NPM install 34 | command: npm ci 35 | - run: 36 | name: Run tests with coverage 37 | command: npm run test:ci 38 | - when: 39 | condition: 40 | equal: ["16.20.0", << parameters.node-version >>] 41 | steps: 42 | - browser-tools/install_browser_tools 43 | - run: 44 | name: Run tests with browser 45 | command: npm run test:browser 46 | environment: 47 | # Currently this test fails in CircleCI. Skip to unblock release 48 | SKIP_AGENT_TEST: true 49 | publish-npm: 50 | docker: 51 | - image: cimg/node:16.20.0 # Primary execution image 52 | auth: 53 | username: $DOCKERHUB_USERNAME 54 | password: $DOCKERHUB_PASSWORD 55 | steps: 56 | - checkout 57 | - run: 58 | name: NPM install 59 | command: npm ci 60 | - run: 61 | name: Authenticate with NPM 62 | command: npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}" 63 | - run: 64 | name: Publish package 65 | command: | 66 | # Publish as beta for pre-release tags like v1.2.3-pre.1 67 | [[ $CIRCLE_TAG =~ ^v.*- ]] && NPM_TAG=--tag=beta 68 | npm publish $NPM_TAG 69 | 70 | workflows: 71 | version: 2 72 | test-and-publish: 73 | jobs: 74 | - lint: 75 | context: 76 | - particle-ci-private 77 | # run tests for all branches 78 | filters: 79 | branches: 80 | only: /.*/ 81 | - run-tests: 82 | context: 83 | - particle-ci-private 84 | matrix: 85 | parameters: 86 | node-version: ["16.20.0", "22.18"] 87 | # run tests for all branches and tags 88 | filters: 89 | tags: 90 | only: /^v.*/ 91 | branches: 92 | only: /.*/ 93 | - publish-npm: 94 | requires: 95 | - lint 96 | - run-tests 97 | context: 98 | - particle-ci-private 99 | # publish for tags only 100 | filters: 101 | tags: 102 | only: /^v.*/ 103 | branches: 104 | ignore: /.*/ 105 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | logs 2 | *.log 3 | pids 4 | *.pid 5 | *.seed 6 | lib-cov 7 | coverage 8 | .lock-wscript 9 | build/Release 10 | node_modules 11 | lib/ 12 | /.idea 13 | *.tgz 14 | .vscode 15 | tmp -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src/ 2 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 22 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # changelog 2 | 3 | ## 11.1.7 - 06 October 2025 4 | * Add downloadManufacturingBackup method 5 | 6 | ## 11.1.6 - 20 September 2025 7 | * Fix request params to support `FormData` passed in the data argument 8 | * Update docs on queries receiving `data` 9 | * Update eslint configuration 10 | 11 | ## 11.1.5 - 19 September 2025 12 | * Ensure node 22 works as expected 13 | * Remove node 12 validations 14 | * Update eslint configuration 15 | 16 | ## 11.1.4 - 20 August 2025 17 | * Clarify license is Apache 2.0 18 | 19 | ## 11.1.3 - 22 July 2025 20 | * Bump form-data to resolve security warning 21 | 22 | ## 11.1.2 - 11 December 2024 23 | * Add context docs for x-particle-tool and x-particle-project headers 24 | 25 | ## 11.1.1 - 5 November 2024 26 | * Workaround for Firefox failing to open multiple event streams 27 | 28 | ## 11.1.0 - 3 October 2024 29 | * Re-add `deleteAccessToken` method, but with basic auth removed 30 | 31 | ## 11.0.0 - 1 October 2024 32 | * Remove `listAccessTokens` and `deleteAccessToken` methods that relied on HTTP basic auth 33 | * Update EventStream to send access_token in the Authorization header instead. No functional change 34 | 35 | ## 10.6.0 - 21 August 2024 36 | * Add DeviceOS versions endpoints 37 | 38 | ## 10.5.1 - 21 June 2024 39 | * Don't add an empty query string to the URL 40 | 41 | ## 10.5.0 - 14 June 2024 42 | * Add `unprotectDevice` 43 | * Remove `changeProduct` 44 | 45 | ## 10.4.3 - 25 March 2024 46 | * Add `utm` paramater to `createUser` 47 | 48 | ## 10.4.2 - 3 January 2024 49 | * Add `setMode` arg to `setLedgerInstance` 50 | * Fix a few incorrect logic function JSDocs 51 | 52 | ## 10.4.1 - 2 January 2024 53 | 54 | * Fix `setLedgerInstance` taking wrong argument and passing a bad request body to the API 55 | 56 | ## 10.4.0 - 19 December 2023 57 | 58 | * Add `listLedgerInstanceVersions` function 59 | * Add `getLedgerInstanceVersion` function 60 | 61 | ## 10.3.1 - 6 December 2023 62 | 63 | * Add `todayStats` query option to listLogicFunctions 64 | * Add `scope`, `archived`, `page`, and `perPage` query options to listLedgers 65 | * Add `page` and `perPage` query options to listLedgerInstances 66 | * Add JSDocs for constructor 67 | * Fix JSDocs across most functions in the library to be more accurate 68 | 69 | ## 10.3.0 - 7 November 2023 70 | 71 | * Add support for sandbox accounts on all logic/ledger APIs by allowing the omission of the `org` property 72 | * Add `executeLogic` function for testing logic functions before deploying them 73 | 74 | ## 10.2.0 - 6 October 2023 75 | 76 | * Migrate LogicBlocks methods to LogicFunctions, LogicTriggers, and LogicRuns 77 | 78 | ## 10.1.0 - 8 Sept 2023 79 | 80 | * Use wepback to bundle for browser use 81 | * Remove babel, browserify and their related dependencies 82 | * Adds support for checkJS loose type/docs validations 83 | 84 | ## 10.0.0 - 8 Sept 2023 85 | 86 | * Change library to handle requests from `superagent` to `fetch`/`node-fetch` 87 | 88 | ## 9.4.1 - 17 June 2022 89 | 90 | * Fixes incompatible versions of `eslint`, `chai`, `sinon-chai` and `chai-as-promised`. 91 | 92 | ## 9.4.0 - 14 June 2022 93 | 94 | * Adds `.setDefaultAuth(auth)` so token authenticated methods don't need to pass their own auth token. 95 | * Adds support for `auth` option in Particle constructor, calls `.setDefaultAuth()` if provided 96 | * Fixes bug where `.setBaseUrl(baseUrl)` was not honored for `.getEventStream()` method (sc-105035) 97 | 98 | ## 9.3.0 - 8 June 2022 99 | * Adds `.setBaseUrl(baseUrl)` to override backend api endpoint 100 | 101 | ## 9.2.0 - 30 May 2022 102 | * Move to `node@16` and `npm@8` for local development 103 | 104 | ## 9.1.2 - 9 December 2021 105 | * Fix library download 106 | 107 | ## 9.1.1 - 7 December 2021 108 | * Use unforked copy of `stream-http` dependency 109 | 110 | ## 9.1.0 - 8 December 2020 111 | * `.listAccessTokens()` accepts `otp` option to support users with MFA enabled 112 | 113 | ## 9.0.2 - 28 July 2020 114 | * Add `.deleteActiveAccessTokens()` method 115 | * Add `invalidateTokens` arguments to `.confirmMfa()` and `.changeUsername()` methods 116 | 117 | ## 9.0.1 - 1 June 2020 118 | * Add `.getProductDeviceConfiguration()` and `.getProductDeviceConfigurationSchema()` methods 119 | 120 | ## 9.0.0 - 20 May 2020 121 | * Add support for configuration and location services 122 | * All top-level api methods optionally accept a `headers` option object 123 | * Breaking: Base http methods (`.get()`, `.put()`, etc) on agent and particle classes accept options object vs. positional arguments ([see here](https://github.com/particle-iot/particle-api-js/pull/115/commits/c209a43ebcda53b9dc6857e1b54228906f506feb)) 124 | * Breaking: `.downloadFile()` method uses `uri` option (vs. `url`) ([docs](https://github.com/particle-iot/particle-api-js/blob/master/docs/api.md#downloadfile)) 125 | * Breaking: Refactored options object for the `.createWebhook()` method - hook-related options are now passed in via `options.hook` ([docs](https://github.com/particle-iot/particle-api-js/blob/master/docs/api.md#createwebhook)) 126 | 127 | ## 8.4.0 - 28 April 2020 128 | * Allow invalidating access tokens when changing password 129 | 130 | ## 8.3.0 - 11 February 2020 131 | * Add delete user 132 | 133 | ## 8.2.1 - 4 February 2020 134 | * fix file download methods `.downloadFile()`, `.downloadFirmwareBinary()`, and `.downloadProductFirmware()` [PR #112](https://github.com/particle-iot/particle-api-js/pull/112) 135 | 136 | ## 8.2.0 - 28 January 2020 137 | * `.addDeviceToProduct()` accepts `file` option to facillitate bulk importing of devices [PR #109](https://github.com/particle-iot/particle-api-js/pull/109) 138 | 139 | ## 8.1.0 - 24 January 2020 140 | * Add support for `groups` query parameter when listing product devices via `.listDevices()` [PR #108](https://github.com/particle-iot/particle-api-js/pull/108) 141 | * Update `eslint` and related configuration [PR #107](https://github.com/particle-iot/particle-api-js/pull/107) 142 | 143 | ## 8.0.1 - 2 December 2019 144 | * Update to latest superagent to fix deprecation warnings in Node v12 145 | 146 | ## 8.0.0 - 30 July 2019 147 | 148 | * EventStream returned by getEventStream handles errors better [PR #99](https://github.com/particle-iot/particle-api-js/pull/99). 149 | **Breaking changes for EventStream:** 150 | - Only emits a single event named 'event' for each Particle event received instead of 2 events, one named 'event' and another named after the Particle event name. This behavior caused EventStream to disconnects if a Particle event named 'error' was published. 151 | - Does not emit the 'error' event when a network error happens. Instead it emits 'disconnect' and automatically reconnects. 152 | 153 | ## 7.4.1 - 6 May 2019 154 | * Do not require network ID to remove a device from its network [PR #103](https://github.com/particle-iot/particle-api-js/pull/103) 155 | 156 | ## 7.4.0 - 27 Feb 2019 157 | * Add support for mesh network management [PR #98](https://github.com/particle-iot/particle-api-js/pull/98) 158 | 159 | ## 7.3.0 - 10 Jan 2019 160 | * Support flashing product devices [PR #97](https://github.com/particle-iot/particle-api-js/pull/97) 161 | 162 | ## 7.2.3 - 4 Aug 2018 163 | * Add sendOtp method to allow users enrolled in MFA/Two-Step Auth to login [PR #92](https://github.com/particle-iot/particle-api-js/pull/92) 164 | 165 | ## 7.2.2 - 23 Jul 2018 166 | * Fix npm api key for publishing to registry 167 | 168 | ## 7.2.1 - 23 Jul 2018 169 | * Support enrolling user in MFA/Two-step authentication 170 | 171 | ## 7.2.0 - 22 Mar 2018 172 | * Support changing user's username(i.e., email) and password [PR #84](https://github.com/particle-iot/particle-api-js/pull/84) 173 | 174 | ## 7.1.1 - 13 Feb 2018 175 | * Fix country parameter for activate sim [PR #81](https://github.com/particle-iot/particle-api-js/pull/81) 176 | 177 | ## 7.1.0 - 17 Jan 2018 178 | 179 | * Update jsDelivr link [PR #66](https://github.com/particle-iot/particle-api-js/pull/66). Thanks @LukasDrgon! 180 | * Stop auto reconnecting when event stream is intentionally disconnected [PR #69](https://github.com/particle-iot/particle-api-js/pull/69). Thanks @spacetc62! 181 | * Add createCustomer [PR #78](https://github.com/particle-iot/particle-api-js/pull/78). Thanks @monkeytronics! 182 | * Fix event stream exception when it is an HTML response [PR #64](https://github.com/particle-iot/particle-api-js/pull/64). Thanks @spacetc62! 183 | * Update links after GitHub organization rename to `particle-iot` [PR #79](https://github.com/particle-iot/particle-api-js/pull/79) 184 | 185 | ## 7.0.1 - 16 Nov 2017 186 | * Add loginAsClientOwner method 187 | 188 | ## 7.0.0 - 7 Nov 2017 189 | * Update to latest superagent with support for nested directory. **Drops support for Node versions earlier than 4.** 190 | * Add serial number endpoint 191 | 192 | ## 6.6.2 - 15 Sep 2017 193 | * Fix nested directories bug 194 | 195 | ## 6.6.1 - 14 Sep 2017 196 | * Update form-data to v1.0.0-relativepath.2 197 | 198 | ## 6.6.0 - 12 Sep 2017 199 | 200 | * Add support for deleting current token 201 | 202 | ## 6.5.0 - 02 May 2017 203 | 204 | * Add support for all product API endpoints. 205 | * Add support for sending additional context with each call. 206 | 207 | ## 6.4.3 - 15 Feb 2017 208 | 209 | * Create a wrapper for `listBuildTargets` in `Client.js`. 210 | * Marked `compileCode`, `signalDevice`, `listDevices` and `listBuildTargets` as deprecated. Those methods will be removed in 6.5 211 | 212 | ## 6.4.2 - 05 Jan 2017 213 | 214 | * Create a wrapper for `listDevices` in `Client.js`. 215 | 216 | ## 6.4.1 - 15 Dec 2016 217 | 218 | * Add scopes to library listing 219 | 220 | ## 6.4.0 - 09 Nov 2016 221 | 222 | * Create a wrapper for `signalDevice` in `Client.js`. 223 | 224 | ## 6.3.0 - 31 Oct 2016 225 | 226 | * Add support for account verification endpoint via verifyUser function 227 | * Change account_info input parameter in createUser and setUserInfo to be camel case - accountInfo 228 | 229 | ## 6.2.0 - 19 Oct 2016 230 | 231 | * Add support for account information fields in createUser and setUserInfo 232 | * Add "shortErrorDescription" in response body to contain English description only 233 | 234 | ## 6.1.0 - 19 Oct 2016 235 | 236 | * Add library publish 237 | 238 | ## 6.0.8 - 17 Oct 2016 239 | 240 | * Rename library publish to library contribute 241 | 242 | ## 6.0.7 - 29 Sept 2016 243 | 244 | * Add library versions endpoint 245 | 246 | ## 6.0.6 - 19 Sept 2016 247 | 248 | * Add library delete 249 | 250 | ## 6.0.5 - 8 Sept 2016 251 | 252 | * Add library publish 253 | 254 | ## 6.0.4 - 30 Aug 2016 255 | 256 | * Use only HTTP dependencies to be able to install on computers without git 257 | 258 | ## 6.0.3 - 25 Aug 2016 259 | 260 | * Support nested directories when compiling sources 261 | 262 | ## 6.0.2 - 23 Aug 2016 263 | 264 | * Add compile code to client 265 | 266 | ## 6.0.1 - 22 Aug 2016 267 | 268 | * Fix the login method content type 269 | 270 | ## 6.0.0 - 17 Aug 2016 271 | 272 | * Add libraries endpoints 273 | * Add stateful client 274 | * Add object interface for libraries 275 | 276 | ## 5.3.1 - 2 Aug 2016 277 | 278 | * Handle empty event names in the event stream. 279 | 280 | ## 5.3.0 - 8 June 2016 281 | 282 | * Add details to README 283 | * Adding responseTemplate and responseTopic to webhook creation. Thanks @acasas! [#20](https://github.com/particle-iot/particle-api-js/pull/20) 284 | * Add password reset route [#27](https://github.com/particle-iot/particle-api-js/pull/27) 285 | * Make event stream compatible with new product routes [#28](https://github.com/particle-iot/particle-api-js/pull/28) 286 | 287 | ## 5.2.7 - 2 May 2016 288 | 289 | * Fix files parameter default name to be `file` and not `file1`. 290 | 291 | ## 5.2.6 - 25 Mar 2016 292 | 293 | * Don't double publish event stream events if the event is named `event`. 294 | 295 | ## 5.2.5 - 21 Mar 2016 296 | 297 | * Handle `JSON.parse` exceptions when parsing event stream 298 | 299 | ## 5.2.4 - 21 Mar 2016 300 | 301 | * `flashDevice` `latest` also needs to be a string, not a boolean. [#12](https://github.com/particle-iot/particle-api-js/issues/12) 302 | 303 | ## 5.2.3 - 11 Mar 2016 304 | 305 | * Remove setting of `User-Agent` header because that is not allowed in browsers. [#10](https://github.com/particle-iot/particle-api-js/issues/10) 306 | 307 | ## 5.2.2 - 3 Mar 2016 308 | 309 | * Fix named event streams by encoding event name. 310 | * Move access token to query string to eliminate preflight CORS request. 311 | * Use fork of `stream-http` that prevents usage of `fetch` because it does not abort. 312 | * Use correct streaming mode of `stream-http`. 313 | 314 | ## 5.2.1 - 3 Mar 2016 315 | 316 | * Improve cleanup on `abort`. 317 | 318 | ## 5.2.0 - 3 Mar 2016 319 | 320 | * Add support for organization and product slugs to `getEventStream`. 321 | 322 | ## 5.1.1 - 26 Feb 2016 323 | 324 | * `JSON.parse` HTTP response body for `getEventStream` error case. 325 | 326 | ## 5.1.0 - 26 Feb 2016 327 | 328 | * Fix event stream. [#8](https://github.com/particle-iot/particle-api-js/issues/8) 329 | * Add `downloadFirmwareBinary` 330 | * Add ability to intercept requests for debugging 331 | * Use library version for User-Agent 332 | * Allow request transfer for `claimDevice` 333 | * `signalDevice` needs to use strings, not numbers. 334 | * `compileCode` `latest` should be a string, not a boolean. 335 | 336 | ## 5.0.2 - 24 Feb 2016 337 | 338 | * Remove trailing slash from `baseUrl`. [#7](https://github.com/particle-iot/particle-api-js/issues/7) 339 | 340 | ## 5.0.1 - 18 Feb 2016 341 | 342 | * Remove need for `require('particle-api-js').default` in CommonJS usage. It is now just `require('particle-api-js')`. 343 | 344 | ## 5.0.0 - 18 Feb 2016 345 | 346 | * Removed need for `babel-runtime`. 347 | * Add `flashDevice`, `compileCode`, and `listAccessTokens`. 348 | * Add missing options to `createWebhook`. 349 | * Remove `downloadFirmwareBinary`. 350 | 351 | ## 4.2.1 - 8 Feb 2016 352 | 353 | * Update contributors. 354 | 355 | ## 4.2.0 - 8 Feb 2016 356 | 357 | * Add `downloadFirmwareBinary`. 358 | 359 | ## 4.1.0 - 14 Jan 2016 360 | 361 | * Add `validatePromoCode`. 362 | * `activateSIM` now requires `promo_code` and `action`. 363 | 364 | ## 4.0.2 - 16 Nov 2015 365 | 366 | * Fix old `code` reference. 367 | 368 | ## 4.0.1 - 16 Nov 2015 369 | 370 | * Change `code` to `statusCode` in rejection. 371 | 372 | ## 4.0.0 - 16 Nov 2015 373 | 374 | * Add `statusCode` to Promise fulfillment. 375 | 376 | ## 3.0.3 - 6 Nov 2015 377 | 378 | * Add `listBuildTargets`. 379 | 380 | ## 3.0.2 - 5 Nov 2015 381 | 382 | * Add `countryCode` to `activateSIM`. 383 | 384 | ## 3.0.1 - 26 Oct 2015 385 | 386 | * Fix `activateSIM`. 387 | 388 | ## 3.0.0 - 26 Oct 2015 389 | 390 | * Replace `request` with `superagent`. 391 | * Add `iccid` to `getClaimCode`. 392 | * Only use form encoding on `login` and `signup`. 393 | 394 | ## 2.0.1 - 23 Oct 2015 395 | 396 | * Removed browser entry in package.json. This makes it possible to bundle the module with other apps that use browserify without causing relative pathing issues. 397 | 398 | ## 2.0.0 - 20 Oct 2015 399 | 400 | * Improved error handling and reporting. Network errors and HTTP errors now both return `code` property that can be more easily used to programmatically detect error types. 401 | 402 | ## 1.0.1 - 24 Sep 2015 403 | 404 | ## 1.0.0 - 24 Sep 2015 405 | -------------------------------------------------------------------------------- /EventStream-e2e-browser.html: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 |
15 |Open the Javascript Console
16 | 17 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /EventStream-e2e-node.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | End-to-end test program for the event stream with Node 4 | 5 | Steps: 6 | - PARTICLE_API_TOKEN=