particle-api-js 10.3.0 → 10.3.1
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/.eslintrc.js +23 -21
- package/CHANGELOG.md +8 -0
- package/EventStream-e2e-browser.html +7 -7
- package/EventStream-e2e-node.js +14 -14
- package/dist/particle.min.js +1 -1
- package/dist/particle.min.js.map +1 -1
- package/docs/api.md +3448 -875
- package/karma.conf.js +59 -59
- package/package.json +1 -1
- package/src/Agent.js +387 -363
- package/src/Client.js +162 -162
- package/src/Defaults.js +5 -5
- package/src/EventStream.js +254 -253
- package/src/Library.js +21 -21
- package/src/Particle.js +2685 -2649
- package/test/.eslintrc +5 -5
- package/test/Agent.integration.js +14 -14
- package/test/Agent.spec.js +495 -495
- package/test/Client.spec.js +203 -203
- package/test/Defaults.spec.js +20 -20
- package/test/EventStream.spec.js +231 -231
- package/test/FakeAgent.js +18 -18
- package/test/Library.spec.js +29 -29
- package/test/Particle.integration.js +29 -29
- package/test/Particle.spec.js +3127 -3127
- package/test/fixtures/index.js +7 -7
- package/test/support/FixtureHttpServer.js +16 -16
- package/test/test-setup.js +3 -3
- package/tsconfig.json +3 -1
- package/webpack.config.js +39 -39
package/test/Client.spec.js
CHANGED
|
@@ -9,207 +9,207 @@ let client;
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
describe('Client', () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
api = {};
|
|
14
|
+
client = new Client({ api: api, auth: token });
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('constructor', () => {
|
|
18
|
+
it('sets the auth token', () => {
|
|
19
|
+
expect(client.auth).to.equal(token);
|
|
20
|
+
});
|
|
21
|
+
it('sets the api', () => {
|
|
22
|
+
expect(client.api).to.equal(api);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('libraries', () => {
|
|
27
|
+
it('resolves to a list of Library objects', () => {
|
|
28
|
+
api.listLibraries = () => Promise.resolve({ body: fixtures.read('libraries.json') });
|
|
29
|
+
return client.libraries().then(libraries => {
|
|
30
|
+
expect(libraries.length).to.equal(1);
|
|
31
|
+
expect(libraries[0].name).to.equal('neopixel');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('library', () => {
|
|
37
|
+
it('resolves to a Library objects', () => {
|
|
38
|
+
api.getLibrary = () => Promise.resolve({ body: fixtures.read('library.json') });
|
|
39
|
+
return client.library('neopixel').then(library => {
|
|
40
|
+
expect(library.name).to.equal('neopixel');
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('libraryVersions', () => {
|
|
46
|
+
it('resolves to a Library objects', () => {
|
|
47
|
+
api.getLibraryVersions = () => Promise.resolve({ body: fixtures.read('libraryVersions.json') });
|
|
48
|
+
return client.libraryVersions().then(libraries => {
|
|
49
|
+
expect(libraries.length).to.equal(9);
|
|
50
|
+
expect(libraries[0].name).to.equal('neopixel');
|
|
51
|
+
expect(libraries[0].version).to.equal('0.0.10');
|
|
52
|
+
expect(libraries[1].version).to.equal('0.0.9');
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('downloadFile', () => {
|
|
58
|
+
it('delegates to api', () => {
|
|
59
|
+
api.downloadFile = ({ uri }) => Promise.resolve(`${uri} delegated`);
|
|
60
|
+
return expect(client.downloadFile('uri')).to.eventually.equal('uri delegated');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('compileCode', () => {
|
|
65
|
+
it('delegates to api', () => {
|
|
66
|
+
api.compileCode = ({ files, platformId, targetVersion, auth }) => {
|
|
67
|
+
return Promise.resolve([files, platformId, targetVersion, auth]);
|
|
68
|
+
};
|
|
69
|
+
return expect(client.compileCode('a', 'b', 'c')).to.eventually.eql(['a', 'b', 'c', client.auth]);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('signalDevice', () => {
|
|
74
|
+
it('delegates to api', () => {
|
|
75
|
+
api.signalDevice = () => {
|
|
76
|
+
return Promise.resolve([true, client.auth]);
|
|
77
|
+
};
|
|
78
|
+
return expect(client.signalDevice({ deviceId: 'testid', signal: true }))
|
|
79
|
+
.to.eventually.eql([true, client.auth]);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('publishLibrary', () => {
|
|
84
|
+
it('delegates to api and returns the library metadata on success', () => {
|
|
85
|
+
const name = 'fred';
|
|
86
|
+
const metadata = { name };
|
|
87
|
+
const library = new Library(client, metadata);
|
|
88
|
+
api.publishLibrary = sinon.stub().resolves({ body: { data: metadata } });
|
|
89
|
+
return client.publishLibrary(name)
|
|
90
|
+
.then(actual => {
|
|
91
|
+
expect(actual).to.eql(library);
|
|
92
|
+
expect(api.publishLibrary).to.have.been.calledWith({ name, auth:token });
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('delegates to api and calls _throwError to handle the error', () => {
|
|
97
|
+
const error = { message:'I don\'t like vegetables' };
|
|
98
|
+
api.publishLibrary = sinon.stub().rejects(error);
|
|
99
|
+
const name = 'notused';
|
|
100
|
+
return client.publishLibrary(name)
|
|
101
|
+
.then(() => {
|
|
102
|
+
throw new Error('expected an exception');
|
|
103
|
+
})
|
|
104
|
+
.catch(actual => {
|
|
105
|
+
expect(actual).to.eql(error);
|
|
106
|
+
expect(api.publishLibrary).to.have.been.calledWith({ name, auth:token });
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('contributeLibrary', () => {
|
|
112
|
+
it('delegates to api and returns the library metadata on success', () => {
|
|
113
|
+
const archive = {};
|
|
114
|
+
const metadata = { name:'' };
|
|
115
|
+
const library = new Library(client, metadata);
|
|
116
|
+
api.contributeLibrary = sinon.stub().resolves({ body: { data: metadata } });
|
|
117
|
+
return client.contributeLibrary(archive)
|
|
118
|
+
.then(actual => {
|
|
119
|
+
expect(actual).to.eql(library);
|
|
120
|
+
expect(api.contributeLibrary).to.have.been.calledWith({ archive, auth:token });
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('delegates to api and calls _throwError to handle the error', () => {
|
|
125
|
+
const archive = {};
|
|
126
|
+
const error = { message:'I don\'t like vegetables' };
|
|
127
|
+
api.contributeLibrary = sinon.stub().rejects(error);
|
|
128
|
+
return client.contributeLibrary(archive)
|
|
129
|
+
.then(() => {
|
|
130
|
+
throw new Error('expected an exception');
|
|
131
|
+
})
|
|
132
|
+
.catch(actual => {
|
|
133
|
+
expect(actual).to.eql(error);
|
|
134
|
+
expect(api.contributeLibrary).to.have.been.calledWith({ archive, auth:token });
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe('listDevices', () => {
|
|
140
|
+
it('delegates to api', () => {
|
|
141
|
+
api.listDevices = ({ auth }) => {
|
|
142
|
+
return Promise.resolve([auth]);
|
|
143
|
+
};
|
|
144
|
+
return expect(client.listDevices()).to.eventually.eql([client.auth]);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('listBuildTargets', () => {
|
|
149
|
+
it('delegates to api', () => {
|
|
150
|
+
const response = {
|
|
151
|
+
targets: [
|
|
152
|
+
{
|
|
153
|
+
platforms: [0, 6],
|
|
154
|
+
prereleases: [],
|
|
155
|
+
version: '1.2.3',
|
|
156
|
+
firmware_vendor: 'Foo'
|
|
157
|
+
}, {
|
|
158
|
+
platforms: [6, 8],
|
|
159
|
+
prereleases: [6],
|
|
160
|
+
version: '4.5.6',
|
|
161
|
+
firmware_vendor: 'Bar'
|
|
162
|
+
}
|
|
163
|
+
]
|
|
164
|
+
};
|
|
165
|
+
const expected = [
|
|
166
|
+
{
|
|
167
|
+
version: '1.2.3',
|
|
168
|
+
platform: 0,
|
|
169
|
+
prerelease: false,
|
|
170
|
+
firmware_vendor: 'Foo'
|
|
171
|
+
}, {
|
|
172
|
+
version: '1.2.3',
|
|
173
|
+
platform: 6,
|
|
174
|
+
prerelease: false,
|
|
175
|
+
|
|
176
|
+
firmware_vendor: 'Foo'
|
|
177
|
+
}, {
|
|
178
|
+
version: '4.5.6',
|
|
179
|
+
platform: 6,
|
|
180
|
+
prerelease: true,
|
|
181
|
+
firmware_vendor: 'Bar'
|
|
182
|
+
}, {
|
|
183
|
+
version: '4.5.6',
|
|
184
|
+
platform: 8,
|
|
185
|
+
prerelease: false,
|
|
186
|
+
firmware_vendor: 'Bar'
|
|
187
|
+
},
|
|
188
|
+
];
|
|
189
|
+
api.listBuildTargets = () => {
|
|
190
|
+
return Promise.resolve({ body: response });
|
|
191
|
+
};
|
|
192
|
+
return expect(client.listBuildTargets()).to.eventually.eql(expected);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe('trackingIdentity', () => {
|
|
197
|
+
it('delegates to api and unpacks the body', () => {
|
|
198
|
+
api.trackingIdentity = ({ auth, full, context }) => {
|
|
199
|
+
return Promise.resolve({ body: { auth, full, context } });
|
|
200
|
+
};
|
|
201
|
+
const context = { abd:123 };
|
|
202
|
+
const full = 456;
|
|
203
|
+
return expect(client.trackingIdentity({ full, context })).to.eventually.eql({ auth: client.auth, full, context });
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('delegates to api with default parameters and unpacks the body', () => {
|
|
207
|
+
api.trackingIdentity = ({ auth, full, context }) => {
|
|
208
|
+
return Promise.resolve({ body: { auth, full, context } });
|
|
209
|
+
};
|
|
210
|
+
const context = undefined;
|
|
211
|
+
const full = false;
|
|
212
|
+
return expect(client.trackingIdentity()).to.eventually.eql({ auth:client.auth, full, context });
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
215
|
});
|
package/test/Defaults.spec.js
CHANGED
|
@@ -2,28 +2,28 @@ const { expect } = require('./test-setup');
|
|
|
2
2
|
const Defaults = require('../src/Defaults');
|
|
3
3
|
|
|
4
4
|
describe('Default Particle constructor options', () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
it('includes baseUrl', () => {
|
|
6
|
+
expect(Defaults).to.have.property('baseUrl');
|
|
7
|
+
expect(Defaults.baseUrl).to.eql('https://api.particle.io');
|
|
8
|
+
});
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
it('includes clientSecret', () => {
|
|
11
|
+
expect(Defaults).to.have.property('clientSecret');
|
|
12
|
+
expect(Defaults.clientSecret).to.eql('particle-api');
|
|
13
|
+
});
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
it('includes clientId', () => {
|
|
16
|
+
expect(Defaults).to.have.property('clientId');
|
|
17
|
+
expect(Defaults.clientId).to.eql('particle-api');
|
|
18
|
+
});
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
it('includes tokenDuration', () => {
|
|
21
|
+
expect(Defaults).to.have.property('tokenDuration');
|
|
22
|
+
expect(Defaults.tokenDuration).to.eql(7776000);
|
|
23
|
+
});
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
it('includes defaultAuth', () => {
|
|
26
|
+
expect(Defaults).to.have.property('auth');
|
|
27
|
+
expect(Defaults.auth).to.eql(undefined);
|
|
28
|
+
});
|
|
29
29
|
});
|