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