roster-server 2.2.10 → 2.3.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.
Files changed (52) hide show
  1. package/README.md +25 -2
  2. package/index.js +28 -38
  3. package/lib/resolve-site-app.js +42 -0
  4. package/lib/static-site-handler.js +122 -0
  5. package/package.json +12 -3
  6. package/skills/roster-server/SKILL.md +15 -4
  7. package/test/roster-server.test.js +87 -0
  8. package/vendor/greenlock/.prettierrc +8 -0
  9. package/vendor/greenlock/LICENSE +312 -0
  10. package/vendor/greenlock/MIGRATION_GUIDE.md +403 -0
  11. package/vendor/greenlock/README.md +667 -0
  12. package/vendor/greenlock/accounts.js +218 -0
  13. package/vendor/greenlock/bin/add.js +72 -0
  14. package/vendor/greenlock/bin/certonly.js +368 -0
  15. package/vendor/greenlock/bin/config.js +77 -0
  16. package/vendor/greenlock/bin/defaults.js +58 -0
  17. package/vendor/greenlock/bin/greenlock.js +26 -0
  18. package/vendor/greenlock/bin/init.js +159 -0
  19. package/vendor/greenlock/bin/lib/cli.js +230 -0
  20. package/vendor/greenlock/bin/lib/flags.js +385 -0
  21. package/vendor/greenlock/bin/remove.js +46 -0
  22. package/vendor/greenlock/bin/tmpl/app.tmpl.js +9 -0
  23. package/vendor/greenlock/bin/tmpl/cluster.tmpl.js +30 -0
  24. package/vendor/greenlock/bin/tmpl/greenlock.tmpl.js +13 -0
  25. package/vendor/greenlock/bin/tmpl/server.tmpl.js +20 -0
  26. package/vendor/greenlock/bin/update.js +62 -0
  27. package/vendor/greenlock/certificates.js +324 -0
  28. package/vendor/greenlock/errors.js +58 -0
  29. package/vendor/greenlock/greenlock.js +621 -0
  30. package/vendor/greenlock/greenlockrc.js +169 -0
  31. package/vendor/greenlock/lib/challenges-wrapper.js +88 -0
  32. package/vendor/greenlock/lib/directory-url.js +44 -0
  33. package/vendor/greenlock/lib/init.js +191 -0
  34. package/vendor/greenlock/lib/manager-wrapper.js +625 -0
  35. package/vendor/greenlock/lib/rc.js +70 -0
  36. package/vendor/greenlock/logo/beaker-browser-301x112.png +0 -0
  37. package/vendor/greenlock/logo/from-not-secure-to-secure-url-bar.png +0 -0
  38. package/vendor/greenlock/logo/greenlock-1063x250.png +0 -0
  39. package/vendor/greenlock/logo/greenlock-850x200.png +0 -0
  40. package/vendor/greenlock/logo/ibm-301x112.png +0 -0
  41. package/vendor/greenlock/logo/telebit-301x112.png +0 -0
  42. package/vendor/greenlock/order.js +63 -0
  43. package/vendor/greenlock/package-lock.json +140 -0
  44. package/vendor/greenlock/package.json +56 -0
  45. package/vendor/greenlock/plugins.js +270 -0
  46. package/vendor/greenlock/tests/cli.sh +31 -0
  47. package/vendor/greenlock/tests/index.js +53 -0
  48. package/vendor/greenlock/user-events.js +7 -0
  49. package/vendor/greenlock/utils.js +281 -0
  50. package/vendor/greenlock-express/greenlock-shim.js +3 -1
  51. package/vendor/greenlock-express/package.json +0 -1
  52. package/tasks/lessons.md +0 -4
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ var log = require('lemonlog')('greenlock-config');
4
+ var args = process.argv.slice(3);
5
+ var cli = require('./lib/cli.js');
6
+ //var path = require('path');
7
+ //var pkgpath = path.join(__dirname, '..', 'package.json');
8
+ //var pkgpath = path.join(process.cwd(), 'package.json');
9
+
10
+ var Flags = require('./lib/flags.js');
11
+
12
+ Flags.init().then(function({ flagOptions, greenlock, mconf }) {
13
+ var myFlags = {};
14
+ ['all', 'subject', 'servername' /*, 'servernames', 'altnames'*/].forEach(
15
+ function(k) {
16
+ myFlags[k] = flagOptions[k];
17
+ }
18
+ );
19
+
20
+ cli.parse(myFlags);
21
+ cli.main(function(argList, flags) {
22
+ Flags.mangleFlags(flags, mconf);
23
+ main(argList, flags, greenlock);
24
+ }, args);
25
+ });
26
+
27
+ async function main(_, flags, greenlock) {
28
+ var servernames = [flags.subject]
29
+ .concat([flags.servername])
30
+ //.concat(flags.servernames)
31
+ //.concat(flags.altnames)
32
+ .filter(Boolean);
33
+ delete flags.subject;
34
+ delete flags.altnames;
35
+ flags.servernames = servernames;
36
+ if (!flags.all && flags.servernames.length > 1) {
37
+ log.error('Specify either --subject OR --servername');
38
+ process.exit(1);
39
+ return;
40
+ } else if (!flags.all && flags.servernames.length !== 1) {
41
+ log.error('Missing --servername <example.com>');
42
+ process.exit(1);
43
+ return;
44
+ }
45
+ if (!flags.all) {
46
+ flags.servername = flags.servernames[0];
47
+ } else if (flags.servername) {
48
+ log.error('Cannot use both --all and --servername/--subject');
49
+ process.exit(1);
50
+ }
51
+ delete flags.servernames;
52
+
53
+ var getter = function() {
54
+ return greenlock._config(flags);
55
+ };
56
+ if (flags.all) {
57
+ getter = function() {
58
+ return greenlock._configAll(flags);
59
+ };
60
+ }
61
+ return getter()
62
+ .catch(function(err) {
63
+ log.error('Config failed:', err.message);
64
+ process.exit(1);
65
+ })
66
+ .then(function(sites) {
67
+ if (!sites) {
68
+ log.info(flags.all ? 'No configs found' : 'No config for %s', flags.servername);
69
+ process.exit(1);
70
+ return;
71
+ }
72
+ if (!Array.isArray(sites)) sites = [sites];
73
+ sites.forEach(function(site) {
74
+ log.info('Config for %s:', flags.servername || site.subject, site);
75
+ });
76
+ });
77
+ }
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ var log = require('lemonlog')('greenlock-defaults');
4
+ var args = process.argv.slice(3);
5
+ var cli = require('./lib/cli.js');
6
+ //var path = require('path');
7
+ //var pkgpath = path.join(__dirname, '..', 'package.json');
8
+ //var pkgpath = path.join(process.cwd(), 'package.json');
9
+
10
+ var Flags = require('./lib/flags.js');
11
+
12
+ Flags.init({ forceSave: true }).then(function({
13
+ flagOptions,
14
+ greenlock,
15
+ mconf
16
+ }) {
17
+ var myFlags = {};
18
+ [
19
+ 'agree-to-terms',
20
+ 'account-key-type',
21
+ 'server-key-type',
22
+ 'subscriber-email',
23
+ 'renew-offset',
24
+ 'store',
25
+ 'store-xxxx',
26
+ 'challenge-http-01-xxxx',
27
+ 'challenge-dns-01',
28
+ 'challenge-dns-01-xxxx',
29
+ 'challenge-tls-alpn-01',
30
+ 'challenge-tls-alpn-01-xxxx',
31
+ 'challenge',
32
+ 'challenge-xxxx',
33
+ 'challenge-http-01'
34
+ ].forEach(function(k) {
35
+ myFlags[k] = flagOptions[k];
36
+ });
37
+
38
+ cli.parse(myFlags);
39
+ cli.main(function(argList, flags) {
40
+ Flags.mangleFlags(flags, mconf, null, { forceSave: true });
41
+ main(argList, flags, greenlock);
42
+ }, args);
43
+ });
44
+
45
+ async function main(_, flags, greenlock) {
46
+ greenlock.manager
47
+ .defaults(flags)
48
+ .catch(function(err) {
49
+ log.error('Defaults failed:', err.message);
50
+ process.exit(1);
51
+ })
52
+ .then(function() {
53
+ return greenlock.manager.defaults();
54
+ })
55
+ .then(function(dconf) {
56
+ log.info('Global config:', dconf);
57
+ });
58
+ }
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ var log = require('lemonlog')('greenlock-cli');
5
+ var args = process.argv.slice(2);
6
+ var arg0 = args[0];
7
+
8
+ var found = [
9
+ 'certonly',
10
+ 'add',
11
+ 'update',
12
+ 'config',
13
+ 'defaults',
14
+ 'remove',
15
+ 'init'
16
+ ].some(function(k) {
17
+ if (k === arg0) {
18
+ require('./' + k);
19
+ return true;
20
+ }
21
+ });
22
+
23
+ if (!found) {
24
+ log.error("Command '%s' not implemented", arg0 || '(none)');
25
+ process.exit(1);
26
+ }
@@ -0,0 +1,159 @@
1
+ 'use strict';
2
+
3
+ var log = require('lemonlog')('greenlock-init');
4
+ var P = require('../plugins.js');
5
+ var args = process.argv.slice(3);
6
+ var cli = require('./lib/cli.js');
7
+ var Greenlock = require('../');
8
+
9
+ var Flags = require('./lib/flags.js');
10
+
11
+ var flagOptions = Flags.flags();
12
+ var myFlags = {};
13
+ [
14
+ 'config-dir',
15
+ 'maintainer-email',
16
+ 'cluster',
17
+ 'manager',
18
+ 'manager-xxxx'
19
+ ].forEach(function(k) {
20
+ myFlags[k] = flagOptions[k];
21
+ });
22
+
23
+ cli.parse(myFlags);
24
+ cli.main(async function(argList, flags) {
25
+ var pkgRoot = process.cwd();
26
+ var manager = flags.manager;
27
+
28
+ if (['fs', 'cloud'].includes(manager)) {
29
+ manager = '@greenlock/manager';
30
+ }
31
+ if (['cloud'].includes(manager)) {
32
+ flags.managerOpts.cloud = true;
33
+ }
34
+
35
+ flags.manager = flags.managerOpts;
36
+ delete flags.managerOpts;
37
+ flags.manager.module = manager;
38
+
39
+ try {
40
+ if ('.' === String(manager)[0]) {
41
+ manager = require('path').resolve(pkgRoot, manager);
42
+ }
43
+ P._loadSync(manager);
44
+ } catch (e) {
45
+ try {
46
+ P._installSync(manager);
47
+ } catch (e) {
48
+ log.error('Manager %s could not be loaded or installed', manager);
49
+ process.exit(1);
50
+ }
51
+ }
52
+
53
+ var greenlock = Greenlock.create({
54
+ packageRoot: pkgRoot,
55
+ manager: flags.manager,
56
+ configDir: flags.configDir,
57
+ maintainerEmail: flags.maintainerEmail,
58
+ _mustPackage: true
59
+ });
60
+ await greenlock.manager.defaults();
61
+
62
+ //writeGreenlockJs(pkgdir, flags);
63
+ writeServerJs(pkgRoot, flags);
64
+ writeAppJs(pkgRoot);
65
+
66
+ /*
67
+ rc._bin_mode = true;
68
+ var Greenlock = require('../');
69
+ // this is a copy, so it's safe to modify
70
+ var greenlock = Greenlock.create(rc);
71
+ var mconf = await greenlock.manager.defaults();
72
+ var flagOptions = Flags.flags(mconf, myOpts);
73
+ */
74
+ }, args);
75
+
76
+ /*
77
+ function writeGreenlockJs(pkgdir, flags) {
78
+ var greenlockJs = 'greenlock.js';
79
+ var fs = require('fs');
80
+ var path = require('path');
81
+ var tmpl = fs.readFileSync(
82
+ path.join(__dirname, 'tmpl/greenlock.tmpl.js'),
83
+ 'utf8'
84
+ );
85
+
86
+ try {
87
+ fs.accessSync(path.join(pkgdir, greenlockJs));
88
+ console.warn("[skip] '%s' exists", greenlockJs);
89
+ return;
90
+ } catch (e) {
91
+ // continue
92
+ }
93
+
94
+ if (flags.maintainerEmail) {
95
+ tmpl = tmpl.replace(
96
+ /pkg.author/g,
97
+ JSON.stringify(flags.maintainerEmail)
98
+ );
99
+ }
100
+ fs.writeFileSync(path.join(pkgdir, greenlockJs), tmpl);
101
+ console.info("created '%s'", greenlockJs);
102
+ }
103
+ */
104
+
105
+ function writeServerJs(pkgdir, flags) {
106
+ var serverJs = 'server.js';
107
+ var fs = require('fs');
108
+ var path = require('path');
109
+ var tmpl;
110
+
111
+ try {
112
+ fs.accessSync(path.join(pkgdir, serverJs));
113
+ log.warn("Skipping existing %s", serverJs);
114
+ return;
115
+ } catch (e) {
116
+ // continue
117
+ }
118
+
119
+ if (flags.cluster) {
120
+ tmpl = fs.readFileSync(
121
+ path.join(__dirname, 'tmpl/cluster.tmpl.js'),
122
+ 'utf8'
123
+ );
124
+ tmpl = tmpl.replace(/cluster: false/g, 'cluster: true');
125
+ } else {
126
+ tmpl = fs.readFileSync(
127
+ path.join(__dirname, 'tmpl/server.tmpl.js'),
128
+ 'utf8'
129
+ );
130
+ }
131
+
132
+ if (flags.maintainerEmail) {
133
+ tmpl = tmpl
134
+ .replace(/pkg.author/g, JSON.stringify(flags.maintainerEmail))
135
+ .replace(/\/\/maintainerEmail/g, 'maintainerEmail');
136
+ }
137
+
138
+ fs.writeFileSync(path.join(pkgdir, serverJs), tmpl);
139
+ log.info("Created %s", serverJs);
140
+ }
141
+
142
+ function writeAppJs(pkgdir) {
143
+ var appJs = 'app.js';
144
+ var fs = require('fs');
145
+ var path = require('path');
146
+ var tmpl = fs.readFileSync(
147
+ path.join(__dirname, 'tmpl/app.tmpl.js'),
148
+ 'utf8'
149
+ );
150
+
151
+ try {
152
+ fs.accessSync(path.join(pkgdir, appJs));
153
+ log.warn("Skipping existing %s", appJs);
154
+ return;
155
+ } catch (e) {
156
+ fs.writeFileSync(path.join(pkgdir, appJs), tmpl);
157
+ log.info("Created %s", appJs);
158
+ }
159
+ }
@@ -0,0 +1,230 @@
1
+ 'use strict';
2
+
3
+ var CLI = module.exports;
4
+ var log = require('lemonlog')('greenlock-cli-lib');
5
+
6
+ var defaultConf;
7
+ var defaultOpts;
8
+ var bags = [];
9
+
10
+ CLI.parse = function(conf) {
11
+ var opts = (defaultOpts = {});
12
+ defaultConf = conf;
13
+
14
+ Object.keys(conf).forEach(function(k) {
15
+ var v = conf[k];
16
+ if (!v) {
17
+ log.error('Missing CLI flag definition for %s', k);
18
+ process.exit(1);
19
+ }
20
+ var aliases = v[5];
21
+ var bag;
22
+ var bagName;
23
+
24
+ // the name of the argument set is now the 0th argument
25
+ v.unshift(k);
26
+ // v[0] flagname
27
+ // v[1] short flagname
28
+ // v[2] description
29
+ // v[3] type
30
+ // v[4] default value
31
+ // v[5] aliases
32
+
33
+ if ('bag' === v[3]) {
34
+ bag = v[0]; // 'bag-option-xxxx' => '--bag-option-'
35
+ bag = '--' + bag.replace(/xxx.*/, '');
36
+ bags.push(bag);
37
+
38
+ bagName = toBagName(bag.replace(/^--/, ''));
39
+ opts[bagName] = {};
40
+ }
41
+
42
+ if ('json' === v[3]) {
43
+ bagName = toBagName(v[0].replace(/-json$/, '')); // 'bag-option-json' => 'bagOptionOpts'
44
+ opts[bagName] = {};
45
+ } else if ('ignore' !== v[3] && 'undefined' !== typeof v[4]) {
46
+ // set the default values (where 'undefined' is not an allowed value)
47
+ opts[toCamel(k)] = v[4];
48
+ }
49
+
50
+ if (!aliases) {
51
+ aliases = [];
52
+ } else if ('string' === typeof aliases) {
53
+ aliases = aliases.split(',');
54
+ }
55
+ aliases.forEach(function(alias) {
56
+ if (alias in conf) {
57
+ throw new Error(
58
+ "Cannot alias '" +
59
+ alias +
60
+ "' from '" +
61
+ k +
62
+ "': option already exists"
63
+ );
64
+ }
65
+ conf[alias] = v;
66
+ });
67
+ });
68
+ };
69
+
70
+ CLI.main = function(cb, args) {
71
+ var leftovers = [];
72
+ var conf = defaultConf;
73
+ var opts = defaultOpts;
74
+
75
+ if (!opts) {
76
+ throw new Error("you didn't call `CLI.parse(configuration)`");
77
+ }
78
+
79
+ // TODO what's the existing API for this?
80
+ if (!args) {
81
+ args = process.argv.slice(2);
82
+ }
83
+
84
+ var flag;
85
+ var cnf;
86
+ var typ;
87
+
88
+ function grab(bag) {
89
+ var bagName = toBagName(bag);
90
+ if (bag !== flag.slice(0, bag.length)) {
91
+ return false;
92
+ }
93
+ opts[bagName][toCamel(flag.slice(bag.length))] = args.shift();
94
+ return true;
95
+ }
96
+
97
+ while (args.length) {
98
+ // take one off the top
99
+ flag = args.shift();
100
+
101
+ // mind the gap
102
+ if ('--' === flag) {
103
+ leftovers = leftovers.concat(args);
104
+ break;
105
+ }
106
+
107
+ // help!
108
+ if (
109
+ '--help' === flag ||
110
+ '-h' === flag ||
111
+ '/?' === flag ||
112
+ 'help' === flag
113
+ ) {
114
+ printHelp(conf);
115
+ process.exit(1);
116
+ }
117
+
118
+ // only long names are actually used
119
+ if ('--' !== flag.slice(0, 2)) {
120
+ log.error("Unrecognized flag '%s'", flag);
121
+ process.exit(1);
122
+ }
123
+
124
+ cnf = conf[flag.slice(2)];
125
+ if (!cnf) {
126
+ // look for arbitrary flags
127
+ if (bags.some(grab)) {
128
+ continue;
129
+ }
130
+
131
+ // other arbitrary args are not used
132
+ log.error("Unrecognized flag '%s'", flag);
133
+ process.exit(1);
134
+ }
135
+
136
+ if (flag !== '--' + cnf[0]) {
137
+ log.warn("Prefer '--%s' over deprecated '%s'", cnf[0], flag);
138
+ }
139
+
140
+ // look for xxx-json flags
141
+ if ('json' === cnf[3]) {
142
+ try {
143
+ var json = JSON.parse(args.shift());
144
+ var bagName = toBagName(cnf[0].replace(/-json$/, ''));
145
+ Object.keys(json).forEach(function(k) {
146
+ opts[bagName][k] = json[k];
147
+ });
148
+ } catch (e) {
149
+ log.error("Invalid JSON for option '%s': %s", flag, e.message);
150
+ process.exit(1);
151
+ }
152
+ continue;
153
+ }
154
+
155
+ // set booleans, otherwise grab the next arg in line
156
+ typ = cnf[3];
157
+ // TODO --no-<whatever> to negate
158
+ if (Boolean === typ || 'boolean' === typ) {
159
+ opts[toCamel(cnf[0])] = true;
160
+ continue;
161
+ }
162
+ opts[toCamel(cnf[0])] = args.shift();
163
+ continue;
164
+ }
165
+
166
+ cb(leftovers, opts);
167
+ };
168
+
169
+ function toCamel(str) {
170
+ return str.replace(/-([a-z0-9])/g, function(m) {
171
+ return m[1].toUpperCase();
172
+ });
173
+ }
174
+
175
+ function toBagName(bag) {
176
+ // trim leading and trailing '-'
177
+ bag = bag.replace(/^-+/g, '').replace(/-+$/g, '');
178
+ return toCamel(bag) + 'Opts'; // '--bag-option-' => bagOptionOpts
179
+ }
180
+
181
+ function printHelp(conf) {
182
+ var flagLen = 0;
183
+ var typeLen = 0;
184
+ var defLen = 0;
185
+
186
+ Object.keys(conf).forEach(function(k) {
187
+ flagLen = Math.max(flagLen, conf[k][0].length);
188
+ typeLen = Math.max(typeLen, conf[k][3].length);
189
+ if ('undefined' !== typeof conf[k][4]) {
190
+ defLen = Math.max(
191
+ defLen,
192
+ '(Default: )'.length + String(conf[k][4]).length
193
+ );
194
+ }
195
+ });
196
+
197
+ Object.keys(conf).forEach(function(k) {
198
+ var v = conf[k];
199
+
200
+ // skip aliases
201
+ if (v[0] !== k) {
202
+ return;
203
+ }
204
+
205
+ var def = v[4];
206
+ if ('undefined' === typeof def) {
207
+ def = '';
208
+ } else {
209
+ def = '(default: ' + JSON.stringify(def) + ')';
210
+ }
211
+
212
+ var msg =
213
+ ' --' +
214
+ v[0].padEnd(flagLen) +
215
+ ' ' +
216
+ v[3].padStart(typeLen + 1) +
217
+ ' ' +
218
+ (v[2] || '') +
219
+ ' ' +
220
+ def; /*.padStart(defLen)*/
221
+ // v[0] flagname
222
+ // v[1] short flagname
223
+ // v[2] description
224
+ // v[3] type
225
+ // v[4] default value
226
+ // v[5] aliases
227
+
228
+ log.info(msg);
229
+ });
230
+ }