@@ -22,12 +22,12 @@ class Particle {
22
22
*
23
23
* Create a new Particle object and call methods below on it.
24
24
*
25
- * @param {Object } options Options for this API call Options to be used for all requests (see [Defaults](../src/Defaults.js))
25
+ * @param {Object } options Options for this API call Options to be used for all requests (see [Defaults](../src/Defaults.js))
26
26
* @param {string } [options.baseUrl]
27
27
* @param {string } [options.clientSecret]
28
28
* @param {string } [options.clientId]
29
29
* @param {number } [options.tokenDuration]
30
- * @param {string } [options.auth] The access token. If not specified here, will have to be added to every request
30
+ * @param {string } [options.auth] The access token. If not specified here, will have to be added to every request
31
31
*/
32
32
constructor ( options = { } ) {
33
33
if ( options . auth ) {
@@ -37,13 +37,33 @@ class Particle {
37
37
// todo - this seems a bit dangerous - would be better to put all options/context in a contained object
38
38
Object . assign ( this , Defaults , options ) ;
39
39
this . context = { } ;
40
+
40
41
this . agent = new Agent ( this . baseUrl ) ;
41
42
}
42
43
43
44
_isValidContext ( name , context ) {
44
45
return ( name === 'tool' || name === 'project' ) && context !== undefined ;
45
46
}
46
47
48
+ /**
49
+ * @typedef {Object } ToolContext
50
+ * @property {string } name
51
+ * @property {string | number } [version]
52
+ * @property {Omit<ToolContext, 'components'>[] } [components]
53
+ */
54
+
55
+ /**
56
+ * @typedef {Record<string, string | number> } ProjectContext
57
+ * @property {string } name
58
+ */
59
+
60
+ /**
61
+ * Allows setting a tool or project context which will be sent as headers with every request.
62
+ * Tool- x-particle-tool
63
+ * Project- x-particle-project
64
+ * @param {'tool' | 'project' } name
65
+ * @param {ToolContext | ProjectContext | undefined } context
66
+ */
47
67
setContext ( name , context ) {
48
68
if ( context !== undefined ) {
49
69
if ( this . _isValidContext ( name , context ) ) {
0 commit comments