@@ -22,12 +22,12 @@ class Particle {
2222 *
2323 * Create a new Particle object and call methods below on it.
2424 *
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))
2626 * @param {string } [options.baseUrl]
2727 * @param {string } [options.clientSecret]
2828 * @param {string } [options.clientId]
2929 * @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
3131 */
3232 constructor ( options = { } ) {
3333 if ( options . auth ) {
@@ -37,13 +37,33 @@ class Particle {
3737 // todo - this seems a bit dangerous - would be better to put all options/context in a contained object
3838 Object . assign ( this , Defaults , options ) ;
3939 this . context = { } ;
40+
4041 this . agent = new Agent ( this . baseUrl ) ;
4142 }
4243
4344 _isValidContext ( name , context ) {
4445 return ( name === 'tool' || name === 'project' ) && context !== undefined ;
4546 }
4647
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+ */
4767 setContext ( name , context ) {
4868 if ( context !== undefined ) {
4969 if ( this . _isValidContext ( name , context ) ) {
0 commit comments