particle-api-js 10.0.0 → 10.1.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 (46) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/EventStream-e2e-browser.html +0 -1
  3. package/EventStream-e2e-node.js +2 -3
  4. package/README.md +2 -2
  5. package/dist/particle.min.js +1 -434
  6. package/dist/particle.min.js.map +1 -1
  7. package/docs/api.md +4876 -226
  8. package/karma.conf.js +18 -6
  9. package/package.json +18 -22
  10. package/src/Agent.js +407 -0
  11. package/src/Client.js +170 -0
  12. package/src/Defaults.js +7 -0
  13. package/src/EventStream.js +263 -0
  14. package/src/Library.js +33 -0
  15. package/src/Particle.js +2644 -0
  16. package/test/Agent.integration.js +2 -3
  17. package/test/Agent.spec.js +2 -2
  18. package/test/Client.spec.js +7 -7
  19. package/test/Defaults.spec.js +2 -2
  20. package/test/EventStream.spec.js +6 -4
  21. package/test/FakeAgent.js +2 -2
  22. package/test/Library.spec.js +2 -2
  23. package/test/Particle.integration.js +2 -3
  24. package/test/Particle.spec.js +7 -7
  25. package/test/fixtures/index.js +4 -18
  26. package/test/support/FixtureHttpServer.js +5 -3
  27. package/test/test-setup.js +5 -5
  28. package/tsconfig.json +14 -0
  29. package/webpack.config.js +45 -0
  30. package/.babelrc +0 -4
  31. package/lib/Agent.js +0 -615
  32. package/lib/Agent.js.map +0 -1
  33. package/lib/Client.js +0 -312
  34. package/lib/Client.js.map +0 -1
  35. package/lib/Defaults.js +0 -14
  36. package/lib/Defaults.js.map +0 -1
  37. package/lib/EventStream.js +0 -335
  38. package/lib/EventStream.js.map +0 -1
  39. package/lib/Library.js +0 -67
  40. package/lib/Library.js.map +0 -1
  41. package/lib/Particle.js +0 -3831
  42. package/lib/Particle.js.map +0 -1
  43. package/test/Client.integration.js +0 -69
  44. package/test/fixtures/tarball.tar.gz +0 -0
  45. package/test/fixtures/test-library-publish-0.0.1.tar.gz +0 -0
  46. package/test/fixtures/test-library-publish-0.0.2.tar.gz +0 -0
@@ -21,9 +21,8 @@
21
21
  * Tests for real the Agent class using an external service.
22
22
  */
23
23
 
24
- import { expect } from './test-setup';
25
- import Agent from '../src/Agent';
26
-
24
+ const { expect } = require('./test-setup');
25
+ const Agent = require('../src/Agent');
27
26
 
28
27
  describe('Agent', () => {
29
28
  if (!process.env.SKIP_AGENT_TEST){
@@ -1,5 +1,5 @@
1
- import { sinon, expect } from './test-setup';
2
- import Agent from '../src/Agent.js';
1
+ const { sinon, expect } = require('./test-setup');
2
+ const Agent = require('../src/Agent.js');
3
3
 
4
4
  describe('Agent', () => {
5
5
  beforeEach(() => {
@@ -1,7 +1,7 @@
1
- import { expect, sinon } from './test-setup';
2
- import Client from '../src/Client';
3
- import * as fixtures from './fixtures';
4
- import Library from '../src/Library';
1
+ const { expect, sinon } = require('./test-setup');
2
+ const Client = require('../src/Client');
3
+ const fixtures = require('./fixtures');
4
+ const Library = require('../src/Library');
5
5
 
6
6
  let api;
7
7
  const token = 'tok';
@@ -25,7 +25,7 @@ describe('Client', () => {
25
25
 
26
26
  describe('libraries', () => {
27
27
  it('resolves to a list of Library objects', () => {
28
- api.listLibraries = () => Promise.resolve({ body: fixtures.readJSON('libraries.json') });
28
+ api.listLibraries = () => Promise.resolve({ body: fixtures.read('libraries.json') });
29
29
  return client.libraries().then(libraries => {
30
30
  expect(libraries.length).to.equal(1);
31
31
  expect(libraries[0].name).to.equal('neopixel');
@@ -35,7 +35,7 @@ describe('Client', () => {
35
35
 
36
36
  describe('library', () => {
37
37
  it('resolves to a Library objects', () => {
38
- api.getLibrary = () => Promise.resolve({ body: fixtures.readJSON('library.json') });
38
+ api.getLibrary = () => Promise.resolve({ body: fixtures.read('library.json') });
39
39
  return client.library('neopixel').then(library => {
40
40
  expect(library.name).to.equal('neopixel');
41
41
  });
@@ -44,7 +44,7 @@ describe('Client', () => {
44
44
 
45
45
  describe('libraryVersions', () => {
46
46
  it('resolves to a Library objects', () => {
47
- api.getLibraryVersions = () => Promise.resolve({ body: fixtures.readJSON('libraryVersions.json') });
47
+ api.getLibraryVersions = () => Promise.resolve({ body: fixtures.read('libraryVersions.json') });
48
48
  return client.libraryVersions().then(libraries => {
49
49
  expect(libraries.length).to.equal(9);
50
50
  expect(libraries[0].name).to.equal('neopixel');
@@ -1,5 +1,5 @@
1
- import { expect } from './test-setup';
2
- import Defaults from '../src/Defaults';
1
+ const { expect } = require('./test-setup');
2
+ const Defaults = require('../src/Defaults');
3
3
 
4
4
  describe('Default Particle constructor options', () => {
5
5
  it('includes baseUrl', () => {
@@ -1,8 +1,8 @@
1
- import { sinon, expect } from './test-setup';
2
- import http from 'http';
3
- import { EventEmitter } from 'events';
1
+ const { sinon, expect } = require('./test-setup');
2
+ const http = require('http');
3
+ const { EventEmitter } = require('events');
4
4
 
5
- import EventStream from '../src/EventStream';
5
+ const EventStream = require('../src/EventStream');
6
6
 
7
7
  describe('EventStream', () => {
8
8
  afterEach(() => {
@@ -32,6 +32,7 @@ describe('EventStream', () => {
32
32
 
33
33
  describe('connect', () => {
34
34
  it('successfully connects to http', () => {
35
+ sinon.useFakeTimers({ shouldAdvanceTime: true });
35
36
  const fakeRequest = makeRequest();
36
37
  sinon.stub(http, 'request').callsFake(() => {
37
38
  setImmediate(() => {
@@ -57,6 +58,7 @@ describe('EventStream', () => {
57
58
  });
58
59
 
59
60
  it('returns http errors on connect', () => {
61
+ sinon.useFakeTimers({ shouldAdvanceTime: true });
60
62
  const fakeRequest = makeRequest();
61
63
  sinon.stub(http, 'request').callsFake(() => {
62
64
  setImmediate(() => {
package/test/FakeAgent.js CHANGED
@@ -1,4 +1,4 @@
1
- export default class FakeAgent {
1
+ class FakeAgent {
2
2
  get({ uri, auth, headers, query, context }){
3
3
  return this.request({ uri, method: 'get', auth, headers, query, context });
4
4
  }
@@ -23,4 +23,4 @@ export default class FakeAgent {
23
23
  return new Promise((resolve) => resolve(opts));
24
24
  }
25
25
  }
26
-
26
+ module.exports = FakeAgent;
@@ -1,5 +1,5 @@
1
- import { expect } from './test-setup';
2
- import Library from '../src/Library';
1
+ const { expect } = require('./test-setup');
2
+ const Library = require('../src/Library');
3
3
 
4
4
  let client = {};
5
5
 
@@ -1,6 +1,5 @@
1
- import { expect, sinon } from './test-setup';
2
- import Particle from '../src/Particle';
3
-
1
+ const { expect, sinon } = require('./test-setup');
2
+ const Particle = require('../src/Particle');
4
3
 
5
4
  describe('Particle', () => {
6
5
  let api;
@@ -1,10 +1,10 @@
1
- import should from 'should'; // monkeypatch the world~!1
2
- import Particle from '../src/Particle';
3
- import Defaults from '../src/Defaults';
4
- import Client from '../src/Client';
5
- import EventStream from '../src/EventStream';
6
- import FakeAgent from './FakeAgent';
7
- import { sinon, expect } from './test-setup';
1
+ const should = require('should'); // monkeypatch the world~!1
2
+ const Particle = require('../src/Particle');
3
+ const Defaults = require('../src/Defaults');
4
+ const Client = require('../src/Client');
5
+ const EventStream = require('../src/EventStream');
6
+ const FakeAgent = require('./FakeAgent');
7
+ const { sinon, expect } = require('./test-setup');
8
8
 
9
9
  let api;
10
10
 
@@ -1,16 +1,8 @@
1
- /* In order for the tests to run in the browser the fixture files must
2
- * be loaded statically into an object. The 'brfs' module will replace
3
- * the fs.readFileSync('static_path') call by the contents of the file.
4
- */
5
- const fs = require('fs'); // import syntax doesn't work inside karma
6
-
7
1
 
8
2
  const fixtures = {
9
- 'libraries.json': fs.readFileSync(__dirname + '/libraries.json'),
10
- 'library.json': fs.readFileSync(__dirname + '/library.json'),
11
- 'libraryVersions.json': fs.readFileSync(__dirname + '/libraryVersions.json'),
12
- 'test-library-publish-0.0.1.tar.gz': fs.readFileSync(__dirname + '/test-library-publish-0.0.1.tar.gz'),
13
- 'test-library-publish-0.0.2.tar.gz': fs.readFileSync(__dirname + '/test-library-publish-0.0.2.tar.gz'),
3
+ 'libraries.json': require('./libraries.json'),
4
+ 'library.json': require('./library.json'),
5
+ 'libraryVersions.json': require('./libraryVersions.json')
14
6
  };
15
7
 
16
8
  function read(filename) {
@@ -20,10 +12,4 @@ function read(filename) {
20
12
  return fixtures[filename];
21
13
  }
22
14
 
23
- function readJSON(filename) {
24
- return JSON.parse(read(filename));
25
- }
26
-
27
- export {
28
- read, readJSON
29
- };
15
+ module.exports = { read };
@@ -1,9 +1,9 @@
1
1
  // Serve files from the fixture folder
2
- import express from 'express';
3
- import * as fixtures from '../fixtures';
2
+ const express = require('express');
3
+ const fixtures = require('../fixtures');
4
4
 
5
5
 
6
- export default class FixtureHttpServer {
6
+ class FixtureHttpServer {
7
7
  constructor(){
8
8
  this.app = express();
9
9
  this.app.get('/:filename', (req, res) => {
@@ -23,3 +23,5 @@ export default class FixtureHttpServer {
23
23
  return `http://localhost:${this.server.address().port}`;
24
24
  }
25
25
  }
26
+
27
+ module.exports = FixtureHttpServer;
@@ -1,16 +1,16 @@
1
1
  // Set up the Mocha test framework with the Chai assertion library and
2
2
  // the Sinon mock library
3
3
 
4
- import chai from 'chai';
5
- import sinon from 'sinon';
6
- import sinonChai from 'sinon-chai';
7
- import chaiAsPromised from 'chai-as-promised';
4
+ const chai = require('chai');
5
+ const sinon = require('sinon');
6
+ const sinonChai = require('sinon-chai');
7
+ const chaiAsPromised = require('chai-as-promised');
8
8
 
9
9
  chai.use(sinonChai);
10
10
  chai.use(chaiAsPromised);
11
11
  const expect = chai.expect;
12
12
 
13
- export {
13
+ module.exports = {
14
14
  chai,
15
15
  sinon,
16
16
  expect
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "target": "es6",
5
+ "allowJs": true,
6
+ "checkJs": true,
7
+ "skipLibCheck": true,
8
+ "esModuleInterop": true,
9
+ "resolveJsonModule": true
10
+ },
11
+ "types": ["node"],
12
+ "include": [ "src" ],
13
+ "exclude": ["node_modules"]
14
+ }
@@ -0,0 +1,45 @@
1
+ const path = require('path');
2
+ const webpack = require('webpack');
3
+ const TerserPlugin = require('terser-webpack-plugin');
4
+
5
+ module.exports = (env) => {
6
+ return {
7
+ mode: env.mode,
8
+ target: 'web',
9
+ entry: './src/Particle.js',
10
+ devtool: 'source-map',
11
+ output: {
12
+ filename: `particle${env.mode === 'production' ? '.min' : ''}.js`,
13
+ path: path.resolve(__dirname, 'dist'),
14
+ clean: true,
15
+ library: {
16
+ name: 'Particle',
17
+ type: 'var'
18
+ }
19
+ },
20
+ optimization: {
21
+ minimize: env.mode === 'production',
22
+ minimizer: [new TerserPlugin({
23
+ extractComments: false,
24
+ terserOptions: {
25
+ format: {
26
+ comments: false
27
+ }
28
+ }
29
+ })]
30
+ },
31
+ resolve: {
32
+ fallback: {
33
+ buffer: require.resolve('buffer'),
34
+ events: require.resolve('events'),
35
+ url: require.resolve('url')
36
+ }
37
+ },
38
+ plugins: [
39
+ new webpack.ProvidePlugin({
40
+ Buffer: ['buffer', 'Buffer'],
41
+ process: 'process/browser',
42
+ })
43
+ ]
44
+ };
45
+ };
package/.babelrc DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "presets": ["es2015"],
3
- "plugins": ["add-module-exports", "transform-runtime"]
4
- }