particle-api-js 11.1.7 → 12.0.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.
Files changed (85) hide show
  1. package/README.md +90 -10
  2. package/dist/particle.min.js +1 -1
  3. package/dist/particle.min.js.map +1 -1
  4. package/fs.d.ts +2 -0
  5. package/lib/fs.d.ts +2 -0
  6. package/lib/fs.js +3 -0
  7. package/lib/package.json +110 -0
  8. package/lib/src/Agent.d.ts +40 -0
  9. package/lib/src/Agent.d.ts.map +1 -0
  10. package/lib/src/Agent.js +233 -0
  11. package/lib/src/Agent.js.map +1 -0
  12. package/lib/src/Client.d.ts +80 -0
  13. package/lib/src/Client.d.ts.map +1 -0
  14. package/lib/src/Client.js +104 -0
  15. package/lib/src/Client.js.map +1 -0
  16. package/lib/src/Defaults.d.ts +6 -0
  17. package/lib/src/Defaults.d.ts.map +1 -0
  18. package/lib/src/Defaults.js +12 -0
  19. package/lib/src/Defaults.js.map +1 -0
  20. package/lib/src/EventStream.d.ts +31 -0
  21. package/lib/src/EventStream.d.ts.map +1 -0
  22. package/lib/src/EventStream.js +275 -0
  23. package/lib/src/EventStream.js.map +1 -0
  24. package/lib/src/Library.d.ts +33 -0
  25. package/lib/src/Library.d.ts.map +1 -0
  26. package/lib/src/Library.js +19 -0
  27. package/lib/src/Library.js.map +1 -0
  28. package/{src/Particle.js → lib/src/Particle.d.ts} +623 -1779
  29. package/lib/src/Particle.d.ts.map +1 -0
  30. package/lib/src/Particle.js +2578 -0
  31. package/lib/src/Particle.js.map +1 -0
  32. package/lib/src/types/common.d.ts +73 -0
  33. package/lib/src/types/common.d.ts.map +1 -0
  34. package/lib/src/types/common.js +3 -0
  35. package/lib/src/types/common.js.map +1 -0
  36. package/lib/src/types/index.d.ts +4 -0
  37. package/lib/src/types/index.d.ts.map +1 -0
  38. package/lib/src/types/index.js +20 -0
  39. package/lib/src/types/index.js.map +1 -0
  40. package/lib/src/types/requests.d.ts +568 -0
  41. package/lib/src/types/requests.d.ts.map +1 -0
  42. package/lib/src/types/requests.js +3 -0
  43. package/lib/src/types/requests.js.map +1 -0
  44. package/lib/src/types/responses.d.ts +449 -0
  45. package/lib/src/types/responses.d.ts.map +1 -0
  46. package/lib/src/types/responses.js +3 -0
  47. package/lib/src/types/responses.js.map +1 -0
  48. package/package.json +35 -14
  49. package/scripts/postprocess-docs.js +306 -0
  50. package/typedoc.json +20 -0
  51. package/.circleci/config.yml +0 -104
  52. package/.nvmrc +0 -1
  53. package/CHANGELOG.md +0 -404
  54. package/EventStream-e2e-browser.html +0 -39
  55. package/EventStream-e2e-node.js +0 -34
  56. package/RELEASE.md +0 -12
  57. package/bower.json +0 -30
  58. package/docs/api.md +0 -2594
  59. package/eslint.config.mjs +0 -7
  60. package/examples/login/login.html +0 -17
  61. package/karma.conf.js +0 -80
  62. package/src/Agent.js +0 -397
  63. package/src/Client.js +0 -171
  64. package/src/Defaults.js +0 -8
  65. package/src/EventStream.js +0 -269
  66. package/src/Library.js +0 -33
  67. package/test/Agent.integration.js +0 -23
  68. package/test/Agent.spec.js +0 -488
  69. package/test/Client.spec.js +0 -216
  70. package/test/Defaults.spec.js +0 -30
  71. package/test/EventStream.feature +0 -65
  72. package/test/EventStream.spec.js +0 -263
  73. package/test/FakeAgent.js +0 -27
  74. package/test/Library.spec.js +0 -40
  75. package/test/Particle.integration.js +0 -38
  76. package/test/Particle.spec.js +0 -3198
  77. package/test/fixtures/index.js +0 -15
  78. package/test/fixtures/libraries.json +0 -33
  79. package/test/fixtures/library.json +0 -31
  80. package/test/fixtures/libraryVersions.json +0 -211
  81. package/test/out.tmp +0 -0
  82. package/test/support/FixtureHttpServer.js +0 -28
  83. package/test/test-setup.js +0 -17
  84. package/tsconfig.json +0 -17
  85. package/webpack.config.js +0 -46
@@ -0,0 +1,306 @@
1
+ #!/usr/bin/env node
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ const docsPath = path.join(__dirname, '..', 'docs', 'api.md');
6
+ let content = fs.readFileSync(docsPath, 'utf8');
7
+
8
+ // Extract git revision from existing source links
9
+ const revMatch = content.match(/blob\/([a-f0-9]+)\//);
10
+ const gitRevision = revMatch ? revMatch[1] : 'master';
11
+ const baseUrl = `https://github.com/particle-iot/particle-api-js/blob/${gitRevision}`;
12
+
13
+ // 1. Replace 'export=' with 'Particle'
14
+ content = content.replace(/\bexport=/g, 'Particle');
15
+
16
+ // 2. Remove top-level headings
17
+ content = content.replace(/^# particle-api-js\n\n## Classes\n\n/, '');
18
+
19
+ // 3. Remove section group headings
20
+ content = content.replace(/^#### Constructors\n\n/gm, '');
21
+ content = content.replace(/^#### Methods\n\n/gm, '');
22
+
23
+ // 4. Fix class heading level: ### Particle -> ## Particle
24
+ content = content.replace(/^### Particle$/m, '## Particle');
25
+
26
+ // 5. Remove constructor signature line
27
+ content = content.replace(/^> \*\*new Particle\*\*\(.*\n\n/m, '');
28
+
29
+ // 6. Fix constructor heading
30
+ content = content.replace(/^##### Constructor$/m, '### constructor');
31
+
32
+ // 7. Remove method signature lines (> **methodName**(...): ...)
33
+ content = content.replace(/^> \*\*\w+\*\*\(.*\n\n/gm, '');
34
+
35
+ // 8. Convert method headings: ##### methodName() -> ### methodName
36
+ content = content.replace(/^##### (\w+)\(\)$/gm, '### $1');
37
+
38
+ // 9. Fix return type references
39
+ content = content.replace(/\[`Particle`\]\(#[^)]*\)/g, '`Particle`');
40
+
41
+ // 10. Convert ###### parameter sections to bullet lists
42
+ // TypeDoc generates:
43
+ // ###### Parameters
44
+ // ###### options
45
+ // `Type`
46
+ // description
47
+ // ###### options.field (or just ###### field for expanded objects)
48
+ // `Type`
49
+ // description
50
+ // ###### Returns
51
+ // `Type`
52
+ // description
53
+ //
54
+ // We want:
55
+ // **Parameters**
56
+ // - `options` **Type** description
57
+ // - `options.field` **Type** description
58
+ // **Returns** Type description
59
+
60
+ const lines = content.split('\n');
61
+ const result = [];
62
+ let i = 0;
63
+
64
+ while (i < lines.length) {
65
+ const line = lines[i];
66
+
67
+ // Match ###### heading
68
+ if (line.startsWith('###### ')) {
69
+ const heading = line.slice(7).trim();
70
+
71
+ if (heading === 'Parameters') {
72
+ result.push('**Parameters**');
73
+ result.push('');
74
+ i++;
75
+ // Process parameter entries until we hit ###### Returns or a non-###### heading or ### heading
76
+ // The first param is typically `options` - all subsequent non-dotted params are its children.
77
+ // Dotted params (like context.project) are grandchildren.
78
+ let isFirstParam = true;
79
+ while (i < lines.length) {
80
+ const pline = lines[i];
81
+
82
+ // Stop at Returns or a method heading
83
+ if (pline === '###### Returns') {
84
+ break;
85
+ }
86
+ if (pline.startsWith('### ') || pline.startsWith('## ')) {
87
+ break;
88
+ }
89
+
90
+ // New param heading
91
+ if (pline.startsWith('###### ')) {
92
+ const paramName = pline.slice(7).trim();
93
+
94
+ // Collect type (next non-empty line starting with `)
95
+ i++;
96
+ let paramType = '';
97
+ let paramDesc = '';
98
+
99
+ // Skip blank lines
100
+ while (i < lines.length && lines[i].trim() === '') {
101
+ i++;
102
+ }
103
+
104
+ // Check if next line is a type (starts with ` or \{)
105
+ if (i < lines.length && (lines[i].startsWith('`') || lines[i].startsWith('\\{'))) {
106
+ paramType = lines[i].trim();
107
+ i++;
108
+ while (i < lines.length && lines[i].trim() === '') {
109
+ i++;
110
+ }
111
+ }
112
+
113
+ // Collect description lines until next heading or blank+heading
114
+ const descLines = [];
115
+ while (i < lines.length && !lines[i].startsWith('#') && !(lines[i].trim() === '' && i + 1 < lines.length && lines[i + 1].startsWith('#'))) {
116
+ if (lines[i].trim() === '') {
117
+ let j = i;
118
+ while (j < lines.length && lines[j].trim() === '') {
119
+ j++;
120
+ }
121
+ if (j >= lines.length || lines[j].startsWith('#')) {
122
+ break;
123
+ }
124
+ }
125
+ descLines.push(lines[i]);
126
+ i++;
127
+ }
128
+ paramDesc = descLines.join(' ').trim();
129
+
130
+ // Skip trailing blank lines
131
+ while (i < lines.length && lines[i].trim() === '') {
132
+ i++;
133
+ }
134
+
135
+ // Determine indentation:
136
+ // - First param (options/params/args) is top-level
137
+ // - Subsequent non-dotted params are children of options -> indent once
138
+ // - Dotted params (context.project) are grandchildren -> indent twice
139
+ let indent = '';
140
+ if (isFirstParam) {
141
+ indent = '';
142
+ isFirstParam = false;
143
+ } else if (paramName.includes('.')) {
144
+ indent = ' ';
145
+ } else {
146
+ indent = ' ';
147
+ }
148
+
149
+ let bullet = `${indent}- \`${paramName}\``;
150
+ if (paramType) {
151
+ bullet += ` **${paramType}**`;
152
+ }
153
+ if (paramDesc) {
154
+ bullet += ` ${paramDesc}`;
155
+ }
156
+
157
+ result.push(bullet);
158
+ } else {
159
+ // Skip blank lines between params
160
+ i++;
161
+ }
162
+ }
163
+ result.push('');
164
+ continue;
165
+ }
166
+
167
+ if (heading === 'Returns') {
168
+ i++;
169
+ while (i < lines.length && lines[i].trim() === '') {
170
+ i++;
171
+ }
172
+
173
+ let returnType = '';
174
+ let returnDesc = '';
175
+
176
+ if (i < lines.length && (lines[i].startsWith('`') || lines[i].startsWith('\\{'))) {
177
+ returnType = lines[i].trim();
178
+ i++;
179
+ while (i < lines.length && lines[i].trim() === '') {
180
+ i++;
181
+ }
182
+ }
183
+
184
+ const descLines = [];
185
+ while (i < lines.length && !lines[i].startsWith('#')) {
186
+ if (lines[i].trim() === '') {
187
+ let j = i;
188
+ while (j < lines.length && lines[j].trim() === '') {
189
+ j++;
190
+ }
191
+ if (j >= lines.length || lines[j].startsWith('#')) {
192
+ break;
193
+ }
194
+ }
195
+ descLines.push(lines[i]);
196
+ i++;
197
+ }
198
+ returnDesc = descLines.join(' ').trim();
199
+
200
+ while (i < lines.length && lines[i].trim() === '') {
201
+ i++;
202
+ }
203
+
204
+ let returnsLine = `Returns **${returnType}**`;
205
+ if (returnDesc) {
206
+ returnsLine += ` ${returnDesc}`;
207
+ }
208
+ result.push(returnsLine);
209
+ result.push('');
210
+ continue;
211
+ }
212
+
213
+ // Other ###### headings (shouldn't happen after our transforms, but just in case)
214
+ result.push(line);
215
+ i++;
216
+ continue;
217
+ }
218
+
219
+ result.push(line);
220
+ i++;
221
+ }
222
+
223
+ content = result.join('\n');
224
+
225
+ // 11. Inject typedef entries
226
+ const typedefs = [
227
+ {
228
+ after: '### publishEvent',
229
+ content: `### Hook
230
+
231
+ Defined in: [Particle.ts:940](${baseUrl}/src/Particle.ts#L940)
232
+
233
+ Type: \`Object\`
234
+
235
+ **Properties**
236
+
237
+ - \`method\` **\`string\`** (optional, default \`POST\`) Type of web request triggered by the Webhook (GET, POST, PUT, or DELETE)
238
+ - \`auth\` **\`object\`** (optional) Auth data like \`{ user: 'me', pass: '1234' }\` for basic auth or \`{ bearer: 'token' }\` to send with the Webhook request
239
+ - \`headers\` **\`object\`** (optional) Additional headers to add to the Webhook like \`{ 'X-ONE': '1', X-TWO: '2' }\`
240
+ - \`query\` **\`object\`** (optional) Query params to add to the Webhook request like \`{ foo: 'foo', bar: 'bar' }\`
241
+ - \`json\` **\`object\`** (optional) JSON data to send with the Webhook request - sets \`Content-Type\` to \`application/json\`
242
+ - \`form\` **\`object\`** (optional) Form data to send with the Webhook request - sets \`Content-Type\` to \`application/x-www-form-urlencoded\`
243
+ - \`body\` **\`string\`** (optional) Custom body to send with the Webhook request
244
+ - \`responseTemplate\` **\`object\`** (optional) Template to use to customize the Webhook response body
245
+ - \`responseEvent\` **\`object\`** (optional) The Webhook response event name that your devices can subscribe to
246
+ - \`errorResponseEvent\` **\`object\`** (optional) The Webhook error response event name that your devices can subscribe to
247
+ `
248
+ },
249
+ {
250
+ after: '### archiveLedger',
251
+ content: `### Scope
252
+
253
+ Defined in: [Particle.ts:2436](${baseUrl}/src/Particle.ts#L2436)
254
+
255
+ Type: \`"Owner" | "Product" | "Device"\`
256
+ `
257
+ },
258
+ {
259
+ after: '### getLedgerInstance',
260
+ content: `### SetMode
261
+
262
+ Defined in: [Particle.ts:2492](${baseUrl}/src/Particle.ts#L2492)
263
+
264
+ Type: \`"Replace" | "Merge"\`
265
+ `
266
+ }
267
+ ];
268
+
269
+ for (const def of typedefs) {
270
+ const idx = content.indexOf(def.after);
271
+ if (idx === -1) {
272
+ console.warn(`Warning: Could not find "${def.after}" to insert typedef`);
273
+ continue;
274
+ }
275
+ const afterAnchor = content.indexOf('\n### ', idx + def.after.length);
276
+ if (afterAnchor === -1) {
277
+ content = content + '\n' + def.content;
278
+ } else {
279
+ content = content.slice(0, afterAnchor) + '\n\n' + def.content + content.slice(afterAnchor);
280
+ }
281
+ }
282
+
283
+ // 12. Generate Table of Contents
284
+ const tocEntries = [];
285
+ const headingRegex = /^### (.+)$/gm;
286
+ let match;
287
+ while ((match = headingRegex.exec(content)) !== null) {
288
+ const name = match[1];
289
+ const anchor = name.toLowerCase().replace(/[^a-z0-9]+/g, '');
290
+ tocEntries.push(`- [${name}](#${anchor})`);
291
+ }
292
+
293
+ const toc = `### Table of Contents\n\n- [Particle](#particle)\n${tocEntries.map(e => ' ' + e).join('\n')}\n`;
294
+
295
+ // Insert TOC at the very top of the file
296
+ content = toc + '\n' + content;
297
+
298
+ // 13. Unescape angle brackets: \< and \> -> < and >
299
+ content = content.replace(/\\</g, '<');
300
+ content = content.replace(/\\>/g, '>');
301
+
302
+ // 14. Clean up multiple consecutive blank lines
303
+ content = content.replace(/\n{3,}/g, '\n\n');
304
+
305
+ fs.writeFileSync(docsPath, content, 'utf8');
306
+ console.log('Post-processed docs/api.md');
package/typedoc.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "entryPoints": ["src/Particle.ts"],
3
+ "tsconfig": "tsconfig.build.json",
4
+ "plugin": ["typedoc-plugin-markdown"],
5
+ "out": "docs",
6
+ "router": "module",
7
+ "entryFileName": "api",
8
+ "fileExtension": ".md",
9
+ "parametersFormat": "list",
10
+ "sourceLinkTemplate": "https://github.com/particle-iot/particle-api-js/blob/{gitRevision}/{path}#L{line}",
11
+ "sort": ["source-order"],
12
+ "excludeInternal": true,
13
+ "excludePrivate": true,
14
+ "excludeNotDocumented": true,
15
+ "expandObjects": true,
16
+ "expandParameters": true,
17
+ "hidePageHeader": true,
18
+ "hideBreadcrumbs": true,
19
+ "readme": "none"
20
+ }
@@ -1,104 +0,0 @@
1
- version: 2.1
2
-
3
- orbs:
4
- browser-tools: circleci/browser-tools@2.2.0
5
-
6
- jobs:
7
- lint:
8
- docker:
9
- - image: cimg/node:22.18 # eslint 9.x requires 18+, so we've separated it from the test step
10
- auth:
11
- username: $DOCKERHUB_USERNAME
12
- password: $DOCKERHUB_PASSWORD
13
- steps:
14
- - checkout
15
- - run:
16
- name: NPM install
17
- command: npm ci
18
- - run:
19
- name: Lint
20
- command: npm run lint
21
- run-tests:
22
- parameters:
23
- node-version:
24
- type: string
25
- docker:
26
- - image: cimg/node:<< parameters.node-version >>-browsers # Primary execution image
27
- auth:
28
- username: $DOCKERHUB_USERNAME
29
- password: $DOCKERHUB_PASSWORD
30
- steps:
31
- - checkout
32
- - run:
33
- name: NPM install
34
- command: npm ci
35
- - run:
36
- name: Run tests with coverage
37
- command: npm run test:ci
38
- - when:
39
- condition:
40
- equal: ["16.20.0", << parameters.node-version >>]
41
- steps:
42
- - browser-tools/install_browser_tools
43
- - run:
44
- name: Run tests with browser
45
- command: npm run test:browser
46
- environment:
47
- # Currently this test fails in CircleCI. Skip to unblock release
48
- SKIP_AGENT_TEST: true
49
- publish-npm:
50
- docker:
51
- - image: cimg/node:16.20.0 # Primary execution image
52
- auth:
53
- username: $DOCKERHUB_USERNAME
54
- password: $DOCKERHUB_PASSWORD
55
- steps:
56
- - checkout
57
- - run:
58
- name: NPM install
59
- command: npm ci
60
- - run:
61
- name: Authenticate with NPM
62
- command: npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
63
- - run:
64
- name: Publish package
65
- command: |
66
- # Publish as beta for pre-release tags like v1.2.3-pre.1
67
- [[ $CIRCLE_TAG =~ ^v.*- ]] && NPM_TAG=--tag=beta
68
- npm publish $NPM_TAG
69
-
70
- workflows:
71
- version: 2
72
- test-and-publish:
73
- jobs:
74
- - lint:
75
- context:
76
- - particle-ci-private
77
- # run tests for all branches
78
- filters:
79
- branches:
80
- only: /.*/
81
- - run-tests:
82
- context:
83
- - particle-ci-private
84
- matrix:
85
- parameters:
86
- node-version: ["16.20.0", "22.18"]
87
- # run tests for all branches and tags
88
- filters:
89
- tags:
90
- only: /^v.*/
91
- branches:
92
- only: /.*/
93
- - publish-npm:
94
- requires:
95
- - lint
96
- - run-tests
97
- context:
98
- - particle-ci-private
99
- # publish for tags only
100
- filters:
101
- tags:
102
- only: /^v.*/
103
- branches:
104
- ignore: /.*/
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- 22