websequencediagrams 2.0.1 → 3.0.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.
package/README.md CHANGED
@@ -13,6 +13,9 @@ Call the WebSequenceDiagram.com API.
13
13
  -s, --style Output style (one of: [default, earth, modern-blue, mscgen,
14
14
  omegapple, qsd, rose, roundgreen, napkin, magazine, vs2010,
15
15
  patent])
16
+ -r, --root The base URL for the service, which defaults to
17
+ "http://www.websequencediagrams.com". It can be modified
18
+ to suit your needs, if you have a private installation.
16
19
  -k, --key WebSequenceDiagrams API key. Key can also be specified with
17
20
  the WSD_APIKEY environment variable. Requires a premium
18
21
  account. See https://www.websequencediagrams.com/order.html
package/bin/wsd_get CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- /* eslint-disable node/shebang */
3
2
  'use strict'
4
3
 
5
4
  const yargs = require('yargs')
@@ -30,6 +29,12 @@ const {argv} = yargs
30
29
  choices: wsd.styles,
31
30
  default: 'default',
32
31
  },
32
+ root: {
33
+ alias: 'r',
34
+ desc: 'WebSequenceDiagrams root URL',
35
+ type: 'string',
36
+ default: 'https://websequencediagrams.com',
37
+ },
33
38
  key: {
34
39
  alias: 'k',
35
40
  desc: 'WebSequenceDiagrams API key',
@@ -57,7 +62,7 @@ FileStream.createAll(files)
57
62
  .then(async streams => {
58
63
  for (const s of streams) {
59
64
  const inp = await s.read()
60
- const [buf, typ] = await wsd.diagram(inp, argv.s, argv.f, argv.k)
65
+ const [buf, typ] = await wsd.diagram(inp, argv.s, argv.f, argv.k, argv.r)
61
66
 
62
67
  let output = argv.o
63
68
  if (!output) {
package/lib/fileStream.js CHANGED
@@ -35,7 +35,6 @@ class FileStream {
35
35
  return new Promise((resolve, reject) => {
36
36
  const bufs = []
37
37
  this.stream.on('error', er => {
38
- console.error(`error opening file ${this.name}`)
39
38
  reject(er)
40
39
  })
41
40
  this.stream.on('data', data => bufs.push(data))
package/lib/wsd.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const fetch = require('node-fetch')
4
4
  const {Buffer} = require('buffer')
5
5
 
6
- const root = 'http://www.websequencediagrams.com'
6
+ const defaultRoot = 'http://www.websequencediagrams.com'
7
7
  const styles = [
8
8
  'default',
9
9
  'earth',
@@ -30,14 +30,24 @@ class WSD {
30
30
  *
31
31
  * @param {string|Buffer} message The diagram description.
32
32
  * @param {string} [style='default'] Style of the diagram. Valid styles
33
- * include: 'default', 'earth', 'modern-blue', 'mscgen', 'omegapple', 'qsd',
34
- * 'rose', 'roundgreen', 'napkin', 'magazine', 'vs2010', or 'patent'.
35
- * @param {string} [format='png'] Format for the output. Valid output formats
36
- * include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid account.
33
+ * include: 'default', 'earth', 'modern-blue', 'mscgen', 'omegapple',
34
+ * 'qsd', 'rose', 'roundgreen', 'napkin', 'magazine', 'vs2010', or
35
+ * 'patent'.
36
+ * @param {string} [format='png'] Format for the output. Valid output
37
+ * formats include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid
38
+ * account.
37
39
  * @param {string} [apikey] API key for non-free usage.
40
+ * @param {string} [root='http://www.websequencediagrams.com'] Root URL for
41
+ * the service.
38
42
  * @returns {Promise<string>} The URL for the diagram.
39
43
  */
40
- static async diagramURL(message, style = 'default', format = 'png', apikey = null) {
44
+ // eslint-disable-next-line max-params
45
+ static async diagramURL(
46
+ message, style = 'default',
47
+ format = 'png',
48
+ apikey = null,
49
+ root = defaultRoot
50
+ ) {
41
51
  if (message instanceof Buffer) {
42
52
  message = message.toString('utf8')
43
53
  }
@@ -62,7 +72,7 @@ class WSD {
62
72
  style,
63
73
  format,
64
74
  })
65
- const res = await fetch(`${WSD.root}/index.php`, {
75
+ const res = await fetch(`${root}/index.php`, {
66
76
  method: 'POST',
67
77
  body: query,
68
78
  })
@@ -76,7 +86,7 @@ class WSD {
76
86
  if (jres.errors.length > 0) {
77
87
  throw new Error(jres.errors.join(', '))
78
88
  }
79
- return `${WSD.root}/${jres.img}`
89
+ return `${root}/${jres.img}`
80
90
  }
81
91
 
82
92
  /**
@@ -91,11 +101,13 @@ class WSD {
91
101
  * formats include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid
92
102
  * account.
93
103
  * @param {string} [apikey] API key for non-free usage.
104
+ * @param {string} [root] Root URL for the service.
94
105
  * @returns {Promise<Array>} Array with the contents of the diagram as the
95
106
  * first item and the MIME type of the response as the second item.
96
107
  */
97
- static async diagram(description, style, format, apikey) {
98
- const u = await WSD.diagramURL(description, style, format, apikey)
108
+ // eslint-disable-next-line max-params
109
+ static async diagram(description, style, format, apikey, root) {
110
+ const u = await WSD.diagramURL(description, style, format, apikey, root)
99
111
  const res = await fetch(u)
100
112
  const ct = res.headers.get('content-type')
101
113
  const buf = await res.buffer()
@@ -103,6 +115,5 @@ class WSD {
103
115
  }
104
116
  }
105
117
  WSD.styles = styles
106
- WSD.root = root
107
118
 
108
119
  module.exports = WSD
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
- "author": "Joe Hildebrand <joe-github@cursive.net>",
3
2
  "name": "websequencediagrams",
4
3
  "description": "Interface to websequencediagrams.com",
5
- "version": "2.0.1",
4
+ "version": "3.0.0",
5
+ "author": "Joe Hildebrand <joe-github@cursive.net>",
6
+ "contributors": [
7
+ "Ed Crump <ed.crump@gmail.com> (https://github.com/icedawn)",
8
+ "Michael Callaghan <michael@walkingriver.com> (https://walkingriver.com)"
9
+ ],
6
10
  "homepage": "https://github.com/hildjj/node-websequencediagrams",
7
11
  "repository": {
8
12
  "type": "git",
@@ -14,9 +18,6 @@
14
18
  },
15
19
  "main": "lib/wsd",
16
20
  "types": "types/wsd.d.ts",
17
- "engines": {
18
- "node": ">=12.19"
19
- },
20
21
  "keywords": [
21
22
  "uml",
22
23
  "sequence diagram",
@@ -35,23 +36,23 @@
35
36
  "release": "npm version patch && git push --follow-tags && npm publish"
36
37
  },
37
38
  "devDependencies": {
38
- "@cto.af/eslint-config": "^0.0.11",
39
- "@types/node": "^16.11.4",
40
- "ava": "^4.0.0-alpha.2",
39
+ "@cto.af/eslint-config": "^0.1.7",
40
+ "@types/node": "^18.11.5",
41
+ "ava": "^5.0.1",
41
42
  "coveralls": "^3.1.1",
42
- "eslint": "^8.1.0",
43
- "eslint-plugin-jsdoc": "^37.0.0",
44
- "eslint-plugin-markdown": "^2.2.1",
43
+ "eslint": "^8.26.0",
44
+ "eslint-plugin-jsdoc": "^39.3.24",
45
+ "eslint-plugin-markdown": "^3.0.0",
45
46
  "eslint-plugin-node": "^11.1.0",
46
- "nock": "^13.1.4",
47
+ "nock": "^13.2.9",
47
48
  "nyc": "^15.1.0",
48
- "tmp-promise": "^3.0.2"
49
+ "tmp-promise": "^3.0.3"
49
50
  },
50
51
  "dependencies": {
51
52
  "node-fetch": "^2.6.5",
52
- "yargs": "^17.2.1"
53
+ "yargs": "^17.6.0"
53
54
  },
54
- "contributors": [
55
- "Ed Crump <ed.crump@gmail.com> (https://github.com/icedawn)"
56
- ]
55
+ "engines": {
56
+ "node": ">=14"
57
+ }
57
58
  }
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  export = FileStream;
3
4
  /**
4
5
  * Promisified stream for a file. Can be replaced with fs.promises one day.
package/types/wsd.d.ts CHANGED
@@ -11,14 +11,18 @@ declare class WSD {
11
11
  *
12
12
  * @param {string|Buffer} message The diagram description.
13
13
  * @param {string} [style='default'] Style of the diagram. Valid styles
14
- * include: 'default', 'earth', 'modern-blue', 'mscgen', 'omegapple', 'qsd',
15
- * 'rose', 'roundgreen', 'napkin', 'magazine', 'vs2010', or 'patent'.
16
- * @param {string} [format='png'] Format for the output. Valid output formats
17
- * include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid account.
14
+ * include: 'default', 'earth', 'modern-blue', 'mscgen', 'omegapple',
15
+ * 'qsd', 'rose', 'roundgreen', 'napkin', 'magazine', 'vs2010', or
16
+ * 'patent'.
17
+ * @param {string} [format='png'] Format for the output. Valid output
18
+ * formats include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid
19
+ * account.
18
20
  * @param {string} [apikey] API key for non-free usage.
21
+ * @param {string} [root='http://www.websequencediagrams.com'] Root URL for
22
+ * the service.
19
23
  * @returns {Promise<string>} The URL for the diagram.
20
24
  */
21
- static diagramURL(message: string | Buffer, style?: string, format?: string, apikey?: string): Promise<string>;
25
+ static diagramURL(message: string | Buffer, style?: string, format?: string, apikey?: string, root?: string): Promise<string>;
22
26
  /**
23
27
  * Retrieve a diagram.
24
28
  *
@@ -31,15 +35,14 @@ declare class WSD {
31
35
  * formats include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid
32
36
  * account.
33
37
  * @param {string} [apikey] API key for non-free usage.
34
- * @returns {Promise<Array<{diagram:Buffer, mimeType:string}>>} Array with the
35
- * contents of the diagram and the MIME type of the response.
38
+ * @param {string} [root] Root URL for the service.
39
+ * @returns {Promise<Array>} Array with the contents of the diagram as the
40
+ * first item and the MIME type of the response as the second item.
36
41
  */
37
- static diagram(description: string, style?: string, format?: string, apikey?: string): Promise<[Buffer, string]>; // MANUAL EDIT!
42
+ static diagram(description: string, style?: string, format?: string, apikey?: string, root?: string): Promise<any[]>;
38
43
  }
39
44
  declare namespace WSD {
40
45
  export { styles };
41
- export { root };
42
46
  }
43
47
  import { Buffer } from "buffer";
44
48
  declare const styles: string[];
45
- declare const root: "http://www.websequencediagrams.com";