@adobe/ccweb-add-on-ssl 0.1.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 (90) hide show
  1. package/.c8rc.json +7 -0
  2. package/.mocharc.json +5 -0
  3. package/CODE_OF_CONDUCT.md +79 -0
  4. package/CONTRIBUTING.md +47 -0
  5. package/LICENSE +21 -0
  6. package/README.md +21 -0
  7. package/bin/run.cmd +3 -0
  8. package/bin/run.js +8 -0
  9. package/dist/AnalyticsMarkers.d.ts +35 -0
  10. package/dist/AnalyticsMarkers.d.ts.map +1 -0
  11. package/dist/AnalyticsMarkers.js +37 -0
  12. package/dist/app/CommandExecutor.d.ts +36 -0
  13. package/dist/app/CommandExecutor.d.ts.map +1 -0
  14. package/dist/app/CommandExecutor.js +25 -0
  15. package/dist/app/SSLReader.d.ts +48 -0
  16. package/dist/app/SSLReader.d.ts.map +1 -0
  17. package/dist/app/SSLReader.js +25 -0
  18. package/dist/app/SetupCommandExecutor.d.ts +64 -0
  19. package/dist/app/SetupCommandExecutor.d.ts.map +1 -0
  20. package/dist/app/SetupCommandExecutor.js +243 -0
  21. package/dist/app/WxpSSLReader.d.ts +60 -0
  22. package/dist/app/WxpSSLReader.d.ts.map +1 -0
  23. package/dist/app/WxpSSLReader.js +113 -0
  24. package/dist/app/index.d.ts +28 -0
  25. package/dist/app/index.d.ts.map +1 -0
  26. package/dist/app/index.js +28 -0
  27. package/dist/commands/setup.d.ts +54 -0
  28. package/dist/commands/setup.d.ts.map +1 -0
  29. package/dist/commands/setup.js +118 -0
  30. package/dist/config/index.d.ts +26 -0
  31. package/dist/config/index.d.ts.map +1 -0
  32. package/dist/config/index.js +26 -0
  33. package/dist/config/inversify.config.d.ts +27 -0
  34. package/dist/config/inversify.config.d.ts.map +1 -0
  35. package/dist/config/inversify.config.js +42 -0
  36. package/dist/config/inversify.types.d.ts +29 -0
  37. package/dist/config/inversify.types.d.ts.map +1 -0
  38. package/dist/config/inversify.types.js +29 -0
  39. package/dist/constants.d.ts +25 -0
  40. package/dist/constants.d.ts.map +1 -0
  41. package/dist/constants.js +25 -0
  42. package/dist/index.d.ts +28 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +28 -0
  45. package/dist/models/SetupCommandOptions.d.ts +49 -0
  46. package/dist/models/SetupCommandOptions.d.ts.map +1 -0
  47. package/dist/models/SetupCommandOptions.js +53 -0
  48. package/dist/models/Types.d.ts +57 -0
  49. package/dist/models/Types.d.ts.map +1 -0
  50. package/dist/models/Types.js +40 -0
  51. package/dist/models/index.d.ts +26 -0
  52. package/dist/models/index.d.ts.map +1 -0
  53. package/dist/models/index.js +26 -0
  54. package/dist/tsconfig.tsbuildinfo +1 -0
  55. package/dist/validators/CommandValidator.d.ts +36 -0
  56. package/dist/validators/CommandValidator.d.ts.map +1 -0
  57. package/dist/validators/CommandValidator.js +25 -0
  58. package/dist/validators/SetupCommandValidator.d.ts +52 -0
  59. package/dist/validators/SetupCommandValidator.d.ts.map +1 -0
  60. package/dist/validators/SetupCommandValidator.js +94 -0
  61. package/dist/validators/index.d.ts +26 -0
  62. package/dist/validators/index.d.ts.map +1 -0
  63. package/dist/validators/index.js +26 -0
  64. package/package.json +65 -0
  65. package/src/AnalyticsMarkers.ts +36 -0
  66. package/src/app/CommandExecutor.ts +37 -0
  67. package/src/app/SSLReader.ts +51 -0
  68. package/src/app/SetupCommandExecutor.ts +310 -0
  69. package/src/app/WxpSSLReader.ts +121 -0
  70. package/src/app/index.ts +28 -0
  71. package/src/commands/setup.ts +146 -0
  72. package/src/config/index.ts +26 -0
  73. package/src/config/inversify.config.ts +49 -0
  74. package/src/config/inversify.types.ts +29 -0
  75. package/src/constants.ts +25 -0
  76. package/src/index.ts +28 -0
  77. package/src/models/SetupCommandOptions.ts +56 -0
  78. package/src/models/Types.ts +61 -0
  79. package/src/models/index.ts +26 -0
  80. package/src/test/app/SetupCommandExecutor.spec.ts +800 -0
  81. package/src/test/app/WxpSSLReader.spec.ts +244 -0
  82. package/src/test/commands/setup.spec.ts +161 -0
  83. package/src/test/data/cert/cert.pem +19 -0
  84. package/src/test/data/cert/key.pem +27 -0
  85. package/src/test/models/SetupCommandOptions.spec.ts +53 -0
  86. package/src/test/validators/SetupCommandValidator.spec.ts +168 -0
  87. package/src/validators/CommandValidator.ts +37 -0
  88. package/src/validators/SetupCommandValidator.ts +116 -0
  89. package/src/validators/index.ts +26 -0
  90. package/tsconfig.json +31 -0
@@ -0,0 +1,243 @@
1
+ /********************************************************************************
2
+ * MIT License
3
+
4
+ * © Copyright 2023 Adobe. All rights reserved.
5
+
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ ********************************************************************************/
24
+ import { __decorate, __metadata, __param } from "tslib";
25
+ import { ITypes as IAnalyticsTypes } from "@adobe/ccweb-add-on-analytics";
26
+ import { ITypes as ICoreTypes, isFile } from "@adobe/ccweb-add-on-core";
27
+ import chalk from "chalk";
28
+ import devcert from "@adobe/ccweb-add-on-devcert";
29
+ import { inject, injectable } from "inversify";
30
+ import path from "path";
31
+ import process from "process";
32
+ import prompts from "prompts";
33
+ import "reflect-metadata";
34
+ import format from "string-template";
35
+ import { AnalyticsErrorMarkers, AnalyticsSuccessMarkers } from "../AnalyticsMarkers.js";
36
+ import { ITypes } from "../config/inversify.types.js";
37
+ import { SSLRemoveOption, SSLSetupOption } from "../models/Types.js";
38
+ const MAX_PROMPT_RETRIES = 3;
39
+ /**
40
+ * Setup command execution implementation class.
41
+ */
42
+ let SetupCommandExecutor = class SetupCommandExecutor {
43
+ _preferences;
44
+ _sslReader;
45
+ _analyticsService;
46
+ _logger;
47
+ /**
48
+ * Instantiate {@link SetupCommandExecutor}.
49
+ * @param preferences - {@link Preferences} reference.
50
+ * @param sslReader - {@link SSLReader} reference.
51
+ * @param analyticsService - {@link AnalyticsService} reference.
52
+ * @param logger - {@link Logger} reference.
53
+ * @returns Reference to a new {@link SetupCommandExecutor} instance.
54
+ */
55
+ constructor(preferences, sslReader, analyticsService, logger) {
56
+ this._preferences = preferences;
57
+ this._sslReader = sslReader;
58
+ this._analyticsService = analyticsService;
59
+ this._logger = logger;
60
+ }
61
+ /**
62
+ * Setup self-signed SSL certificate and key by checking if user defined preferences
63
+ * have SSL config data or if the user has already setup the certificates last time.
64
+ * Otherwise prompt the user to setup the SSL themselves by providing paths as the input or
65
+ * by allowing the CLI to setup the certificates on user's behalf.
66
+ * @param options - Command arguments provided by user represented as {@link SetupCommandOptions}.
67
+ * @returns Promise.
68
+ */
69
+ async execute(options) {
70
+ if (!(await this._shouldSetupNewSSL(options))) {
71
+ return;
72
+ }
73
+ const response = await prompts.prompt({
74
+ type: "select",
75
+ name: "sslSetupType",
76
+ message: this._promptMessage(LOGS.setupSSL),
77
+ choices: [
78
+ { title: this._promptMessageOption(LOGS.automatically), value: SSLSetupOption.Automatically },
79
+ { title: this._promptMessageOption(LOGS.manually), value: SSLSetupOption.Manually }
80
+ ],
81
+ initial: 0
82
+ });
83
+ if (!response || !response.sslSetupType) {
84
+ this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_SSL_SETUP, LOGS.sslSetupOptionNotSpecified, false);
85
+ return process.exit(1);
86
+ }
87
+ if (response.sslSetupType === SSLSetupOption.Manually) {
88
+ await this._setupSSLManually(options.hostname);
89
+ this._analyticsService.postEvent(AnalyticsSuccessMarkers.SUCCESSFUL_SSL_MANUAL_SETUP, options.hostname, true);
90
+ }
91
+ else {
92
+ await this._setupSSLAutomatically(options.hostname);
93
+ this._analyticsService.postEvent(AnalyticsSuccessMarkers.SUCCESSFUL_SSL_AUTOMATIC_SETUP, options.hostname, true);
94
+ }
95
+ }
96
+ async _shouldSetupNewSSL(options) {
97
+ const isCustomSSL = this._sslReader.isCustomSSL(options.hostname);
98
+ const isWxpSSL = this._sslReader.isWxpSSL(options.hostname);
99
+ const doesSSLExist = isCustomSSL || isWxpSSL;
100
+ // When SSL is not configured, set up a new SSL.
101
+ if (!doesSSLExist) {
102
+ this._logger.warning(format(LOGS.sslRequired, { hostname: options.hostname }), { prefix: LOGS.newLine });
103
+ return true;
104
+ }
105
+ // When SSL is configured and the option to use existing is passed, do not set up a new SSL.
106
+ if (options.useExisting) {
107
+ console.log();
108
+ return false;
109
+ }
110
+ // Prompt the user about the existing SSL and
111
+ // check if the user wants to remove the existing to create a new one.
112
+ this._logger.warning(format(LOGS.sslAlreadyConfigured, { hostname: options.hostname }), {
113
+ prefix: LOGS.newLine
114
+ });
115
+ // Consider updating the signature of `_removeExistingSSL` to accept only `options`
116
+ // when we introduce the @oclf command to `remove` an existing SSL.
117
+ return await this._removeExistingSSL(options, isCustomSSL, isWxpSSL);
118
+ }
119
+ async _setupSSLManually(hostname) {
120
+ const certificatePath = await this._promptUserForPath("certificate");
121
+ const keyPath = await this._promptUserForPath("key");
122
+ const userPreference = this._preferences.get();
123
+ if (userPreference.ssl === undefined) {
124
+ userPreference.ssl = new Map();
125
+ }
126
+ userPreference.ssl.set(hostname, { certificatePath, keyPath });
127
+ this._preferences.set(userPreference);
128
+ this._logger.success(LOGS.preferencesSaved, { prefix: LOGS.newLine, postfix: LOGS.newLine });
129
+ }
130
+ async _setupSSLAutomatically(hostname) {
131
+ this._logger.information(LOGS.settingUpSSL, { prefix: LOGS.newLine });
132
+ this._logger.message(LOGS.requireSystemPassword);
133
+ this._logger.message(LOGS.requireSystemPasswordReason);
134
+ this._logger.message(LOGS.retryRunningIfTakingLonger);
135
+ const sslData = await devcert.certificateFor(hostname, { getCaPath: true });
136
+ this._logger.success(LOGS.sslSetupComplete, { prefix: LOGS.newLine });
137
+ if (sslData?.caPath) {
138
+ const sslDirectory = path.resolve(sslData.caPath, "..", "..", "domains", hostname);
139
+ this._logger.information(format(LOGS.findSSLCertificate, { sslDirectory }), { postfix: LOGS.newLine });
140
+ }
141
+ }
142
+ async _removeExistingSSL(options, isCustomSSL, isWxpSSL) {
143
+ const response = await prompts.prompt({
144
+ type: "select",
145
+ name: "shouldRemove",
146
+ message: this._promptMessage(LOGS.removeExistingSSL),
147
+ choices: [
148
+ { title: this._promptMessageOption(LOGS.removeSSL), value: SSLRemoveOption.Remove },
149
+ { title: this._promptMessageOption(LOGS.keepSSL), value: SSLRemoveOption.Keep }
150
+ ],
151
+ initial: 0
152
+ });
153
+ // If no response is obtained, which indicates something has gone wrong, then exit.
154
+ if (!response || !response.shouldRemove) {
155
+ this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_SSL_REMOVE, LOGS.sslRemoveOptionNotSpecified, false);
156
+ return process.exit(1);
157
+ }
158
+ // If the user chooses to keep the existing SSL, do not set up a new SSL.
159
+ if (response.shouldRemove === SSLRemoveOption.Keep) {
160
+ console.log();
161
+ return false;
162
+ }
163
+ // Remove the existing SSL based on how it was set up earlier.
164
+ if (isCustomSSL) {
165
+ const userPreference = this._preferences.get();
166
+ userPreference.ssl.delete(options.hostname);
167
+ this._preferences.set(userPreference);
168
+ this._analyticsService.postEvent(AnalyticsSuccessMarkers.SUCCESSFUL_SSL_MANUAL_REMOVE, options.hostname, true);
169
+ }
170
+ if (isWxpSSL) {
171
+ await devcert.removeDomain(options.hostname);
172
+ this._analyticsService.postEvent(AnalyticsSuccessMarkers.SUCCESSFUL_SSL_AUTOMATIC_REMOVE, options.hostname, true);
173
+ }
174
+ this._logger.success(LOGS.removed, { postfix: LOGS.newLine });
175
+ return true;
176
+ }
177
+ async _promptUserForPath(asset) {
178
+ const promptData = {
179
+ certificate: {
180
+ type: "text",
181
+ name: "sslPath",
182
+ message: this._promptMessage(LOGS.specifyCertificatePath)
183
+ },
184
+ key: {
185
+ type: "text",
186
+ name: "sslPath",
187
+ message: this._promptMessage(LOGS.specifyKeyPath)
188
+ }
189
+ };
190
+ let maxTries = MAX_PROMPT_RETRIES;
191
+ /* eslint-disable no-await-in-loop -- Retry logic */
192
+ while (maxTries > 0) {
193
+ const { sslPath } = await prompts.prompt(promptData[asset]);
194
+ if (isFile(sslPath)) {
195
+ return sslPath;
196
+ }
197
+ maxTries--;
198
+ this._logger.error(format(LOGS.invalidPathSpecified, { asset }));
199
+ }
200
+ this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_SSL_SETUP, format(LOGS.invalidPathSpecified, { asset }), false);
201
+ return process.exit(1);
202
+ }
203
+ _promptMessage(message) {
204
+ return chalk.hex("#E59400")(message);
205
+ }
206
+ _promptMessageOption(message) {
207
+ return chalk.green.bold(message);
208
+ }
209
+ };
210
+ SetupCommandExecutor = __decorate([
211
+ injectable(),
212
+ __param(0, inject(ICoreTypes.Preferences)),
213
+ __param(1, inject(ITypes.SSLReader)),
214
+ __param(2, inject(IAnalyticsTypes.AnalyticsService)),
215
+ __param(3, inject(ICoreTypes.Logger)),
216
+ __metadata("design:paramtypes", [Object, Object, Object, Object])
217
+ ], SetupCommandExecutor);
218
+ export { SetupCommandExecutor };
219
+ const LOGS = {
220
+ newLine: "\n",
221
+ sslRequired: "The Add-on requires a trusted SSL certificate in order to run on https://{hostname}",
222
+ sslAlreadyConfigured: "A trusted SSL certificate is already configured for the Add-on to run on https://{hostname}",
223
+ removeExistingSSL: "Do you want to remove your existing SSL certificate to set up a new one",
224
+ removeSSL: "Yes, remove the existing SSL certificate",
225
+ keepSSL: "No, keep my existing SSL certificate",
226
+ setupSSL: "How do you want to set up your SSL certificate",
227
+ automatically: "Automatically, set it up for me",
228
+ manually: "Manually, I already have an SSL certificate and key",
229
+ settingUpSSL: "Setting up self-signed SSL certificate ...",
230
+ requireSystemPassword: "This is only a one time step and may require you to enter your system's password",
231
+ requireSystemPasswordReason: "so that the SSL certificate can be added to your system's trusted certificate path.",
232
+ retryRunningIfTakingLonger: "[If this takes longer than expected, please break and retry]",
233
+ sslSetupComplete: "SSL setup complete!",
234
+ preferencesSaved: "Your preferences have been saved.",
235
+ findSSLCertificate: "You can find the SSL certificate in {sslDirectory}.",
236
+ specifyCertificatePath: "Please enter the path of your SSL certificate file",
237
+ specifyKeyPath: "Please enter the path of your SSL key file",
238
+ invalidPathSpecified: "Invalid {asset} path specified.",
239
+ sslSetupOptionNotSpecified: "SSL setup option is not specified.",
240
+ sslRemoveOptionNotSpecified: "SSL remove option is not specified.",
241
+ removed: "Removed."
242
+ };
243
+ //# sourceMappingURL=SetupCommandExecutor.js.map
@@ -0,0 +1,60 @@
1
+ /********************************************************************************
2
+ * MIT License
3
+
4
+ * © Copyright 2023 Adobe. All rights reserved.
5
+
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ ********************************************************************************/
24
+ import type { Logger, Preferences } from "@adobe/ccweb-add-on-core";
25
+ import "reflect-metadata";
26
+ import type { SSLData } from "../models/index.js";
27
+ /**
28
+ * Implementation class for reading the SSL artifacts.
29
+ */
30
+ export declare class WxpSSLReader {
31
+ private readonly _preferences;
32
+ private readonly _logger;
33
+ /**
34
+ * Instantiate {@link WxpSSLReader}.
35
+ * @param Preferences - {@link Preferences} reference.
36
+ * @param logger - {@link Logger} reference.
37
+ * @returns Reference to a new {@link WxpSSLReader} instance.
38
+ */
39
+ constructor(preferences: Preferences, logger: Logger);
40
+ /**
41
+ * Is SSL set up manually by the user.
42
+ * @param hostname - Hostname in the SSL certificate.
43
+ * @returns Boolean value representing whether SSL is set up manually.
44
+ */
45
+ isCustomSSL(hostname: string): boolean;
46
+ /**
47
+ * Is SSL set up automatically by the tool.
48
+ * @param hostname - Hostname in the SSL certificate.
49
+ * @returns Boolean value representing whether SSL is set up automatically.
50
+ */
51
+ isWxpSSL(hostname: string): boolean;
52
+ /**
53
+ * Read the SSL artifacts.
54
+ * @param hostname - Hostname in the SSL certificate.
55
+ * @returns Promise of {@link SSLData}.
56
+ */
57
+ read(hostname: string): Promise<SSLData>;
58
+ private _getUserDefinedSSL;
59
+ }
60
+ //# sourceMappingURL=WxpSSLReader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WxpSSLReader.d.ts","sourceRoot":"","sources":["../../src/app/WxpSSLReader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAe,MAAM,0BAA0B,CAAC;AAKjF,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD;;GAEG;AACH,qBACa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC;;;;;OAKG;gBACyC,WAAW,EAAE,WAAW,EAA6B,MAAM,EAAE,MAAM;IAK/G;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAItC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAInC;;;;OAIG;IACG,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA+B9C,OAAO,CAAC,kBAAkB;CAQ7B"}
@@ -0,0 +1,113 @@
1
+ /********************************************************************************
2
+ * MIT License
3
+
4
+ * © Copyright 2023 Adobe. All rights reserved.
5
+
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ ********************************************************************************/
24
+ import { __decorate, __metadata, __param } from "tslib";
25
+ import { ITypes as ICoreTypes, isFile } from "@adobe/ccweb-add-on-core";
26
+ import devcert from "@adobe/ccweb-add-on-devcert";
27
+ import fs from "fs-extra";
28
+ import { inject, injectable } from "inversify";
29
+ import "reflect-metadata";
30
+ /**
31
+ * Implementation class for reading the SSL artifacts.
32
+ */
33
+ let WxpSSLReader = class WxpSSLReader {
34
+ _preferences;
35
+ _logger;
36
+ /**
37
+ * Instantiate {@link WxpSSLReader}.
38
+ * @param Preferences - {@link Preferences} reference.
39
+ * @param logger - {@link Logger} reference.
40
+ * @returns Reference to a new {@link WxpSSLReader} instance.
41
+ */
42
+ constructor(preferences, logger) {
43
+ this._preferences = preferences;
44
+ this._logger = logger;
45
+ }
46
+ /**
47
+ * Is SSL set up manually by the user.
48
+ * @param hostname - Hostname in the SSL certificate.
49
+ * @returns Boolean value representing whether SSL is set up manually.
50
+ */
51
+ isCustomSSL(hostname) {
52
+ return this._getUserDefinedSSL(hostname) !== undefined;
53
+ }
54
+ /**
55
+ * Is SSL set up automatically by the tool.
56
+ * @param hostname - Hostname in the SSL certificate.
57
+ * @returns Boolean value representing whether SSL is set up automatically.
58
+ */
59
+ isWxpSSL(hostname) {
60
+ return devcert.hasCertificateFor(hostname);
61
+ }
62
+ /**
63
+ * Read the SSL artifacts.
64
+ * @param hostname - Hostname in the SSL certificate.
65
+ * @returns Promise of {@link SSLData}.
66
+ */
67
+ async read(hostname) {
68
+ const sslSettings = this._getUserDefinedSSL(hostname);
69
+ // When SSL is set up manuually by the `user`.
70
+ if (sslSettings !== undefined) {
71
+ const { certificatePath, keyPath } = sslSettings;
72
+ if (!certificatePath || !isFile(certificatePath)) {
73
+ this._logger.error(LOGS.invalidCertificatePath);
74
+ return process.exit(1);
75
+ }
76
+ if (!keyPath || !isFile(keyPath)) {
77
+ this._logger.error(LOGS.invalidKeyPath);
78
+ return process.exit(1);
79
+ }
80
+ return {
81
+ cert: fs.readFileSync(certificatePath),
82
+ key: fs.readFileSync(keyPath)
83
+ };
84
+ }
85
+ // When SSL is set up automatically by `devcert`.
86
+ if (this.isWxpSSL(hostname)) {
87
+ return await devcert.certificateFor(hostname);
88
+ }
89
+ this._logger.error(LOGS.noSSLDataFound, { postfix: LOGS.newLine });
90
+ return process.exit(1);
91
+ }
92
+ _getUserDefinedSSL(hostname) {
93
+ const { ssl } = this._preferences.get();
94
+ if (ssl === undefined) {
95
+ return undefined;
96
+ }
97
+ return ssl.get(hostname);
98
+ }
99
+ };
100
+ WxpSSLReader = __decorate([
101
+ injectable(),
102
+ __param(0, inject(ICoreTypes.Preferences)),
103
+ __param(1, inject(ICoreTypes.Logger)),
104
+ __metadata("design:paramtypes", [Object, Object])
105
+ ], WxpSSLReader);
106
+ export { WxpSSLReader };
107
+ const LOGS = {
108
+ newLine: "\n",
109
+ invalidCertificatePath: "Invalid SSL certificate file path.",
110
+ invalidKeyPath: "Invalid SSL key file path.",
111
+ noSSLDataFound: "No SSL related certificate or key files were found. Please retry after setting them up."
112
+ };
113
+ //# sourceMappingURL=WxpSSLReader.js.map
@@ -0,0 +1,28 @@
1
+ /********************************************************************************
2
+ * MIT License
3
+
4
+ * © Copyright 2023 Adobe. All rights reserved.
5
+
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ ********************************************************************************/
24
+ export * from "./CommandExecutor.js";
25
+ export * from "./SSLReader.js";
26
+ export * from "./SetupCommandExecutor.js";
27
+ export * from "./WxpSSLReader.js";
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAElF,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,28 @@
1
+ /********************************************************************************
2
+ * MIT License
3
+
4
+ * © Copyright 2023 Adobe. All rights reserved.
5
+
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ ********************************************************************************/
24
+ export * from "./CommandExecutor.js";
25
+ export * from "./SSLReader.js";
26
+ export * from "./SetupCommandExecutor.js";
27
+ export * from "./WxpSSLReader.js";
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ /********************************************************************************
3
+ * MIT License
4
+
5
+ * © Copyright 2023 Adobe. All rights reserved.
6
+
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ ********************************************************************************/
25
+ import type { Config } from "@oclif/core";
26
+ import { Command } from "@oclif/core";
27
+ import "reflect-metadata";
28
+ /**
29
+ * SSL Setup command.
30
+ */
31
+ export declare class Setup extends Command {
32
+ private readonly _accountService;
33
+ private readonly _analyticsConsent;
34
+ private readonly _analyticsService;
35
+ private readonly _commandValidator;
36
+ private readonly _commandExecutor;
37
+ static description: string;
38
+ static args: {};
39
+ static flags: {
40
+ hostname: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
41
+ useExisting: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
42
+ login: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
43
+ analytics: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
44
+ verbose: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
45
+ };
46
+ constructor(argv: string[], config: Config);
47
+ run(): Promise<void>;
48
+ catch(error: {
49
+ message: string;
50
+ }): Promise<void>;
51
+ private _seekTermsOfUseConsent;
52
+ private _seekAnalyticsConsent;
53
+ }
54
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;;kFAsBkF;AAOlF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAC;AAE7C,OAAO,kBAAkB,CAAC;AAQ1B;;GAEG;AACH,qBAAa,KAAM,SAAQ,OAAO;IAC9B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAiB;IAEjD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IACrD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IAErD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IACrD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkB;IAEnD,MAAM,CAAC,WAAW,SAA4D;IAE9E,MAAM,CAAC,IAAI,KAAM;IAEjB,MAAM,CAAC,KAAK;;;;;;MA+BV;gBAEU,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM;IAepC,GAAG;IAmBH,KAAK,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;YAKxB,sBAAsB;YAQtB,qBAAqB;CAOtC"}
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+ /********************************************************************************
3
+ * MIT License
4
+
5
+ * © Copyright 2023 Adobe. All rights reserved.
6
+
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ ********************************************************************************/
25
+ import { CLIProgram, ITypes as IAnalyticsTypes } from "@adobe/ccweb-add-on-analytics";
26
+ import { UncaughtExceptionHandler } from "@adobe/ccweb-add-on-core";
27
+ import { ITypes as IDeveloperTermsTypes } from "@adobe/ccweb-add-on-developer-terms";
28
+ import { Command, Flags } from "@oclif/core";
29
+ import process from "process";
30
+ import "reflect-metadata";
31
+ import { AnalyticsErrorMarkers } from "../AnalyticsMarkers.js";
32
+ import { IContainer, ITypes } from "../config/index.js";
33
+ import { PROGRAM_NAME } from "../constants.js";
34
+ import { SetupCommandOptions } from "../models/SetupCommandOptions.js";
35
+ /**
36
+ * SSL Setup command.
37
+ */
38
+ export class Setup extends Command {
39
+ _accountService;
40
+ _analyticsConsent;
41
+ _analyticsService;
42
+ _commandValidator;
43
+ _commandExecutor;
44
+ static description = "Setup a trusted SSL certificate for hosting an add-on.";
45
+ static args = {};
46
+ static flags = {
47
+ hostname: Flags.string({
48
+ char: "h",
49
+ description: "Hostname in the SSL certificate.",
50
+ required: true
51
+ }),
52
+ useExisting: Flags.boolean({
53
+ char: "e",
54
+ description: "Use existing SSL if present.",
55
+ required: false,
56
+ default: false,
57
+ hidden: true
58
+ }),
59
+ login: Flags.boolean({
60
+ char: "l",
61
+ description: "Force login.",
62
+ required: false,
63
+ default: false
64
+ }),
65
+ analytics: Flags.string({
66
+ char: "a",
67
+ description: "Turn on/off sending analytics to Adobe.",
68
+ options: ["on", "off"],
69
+ required: false
70
+ }),
71
+ verbose: Flags.boolean({
72
+ char: "v",
73
+ description: "Print detailed logs.",
74
+ required: false,
75
+ default: false
76
+ })
77
+ };
78
+ constructor(argv, config) {
79
+ super(argv, config);
80
+ this._accountService = IContainer.get(IDeveloperTermsTypes.AccountService);
81
+ this._analyticsConsent = IContainer.get(IAnalyticsTypes.AnalyticsConsent);
82
+ this._analyticsService = IContainer.get(IAnalyticsTypes.AnalyticsService);
83
+ this._analyticsService.program = new CLIProgram(PROGRAM_NAME, this.config.name + "@" + this.config.version);
84
+ this._analyticsService.startTime = Date.now();
85
+ this._commandValidator = IContainer.getNamed(ITypes.CommandValidator, "setup");
86
+ this._commandExecutor = IContainer.getNamed(ITypes.CommandExecutor, "setup");
87
+ }
88
+ async run() {
89
+ UncaughtExceptionHandler.registerExceptionHandler(PROGRAM_NAME);
90
+ const rootDirectory = process.cwd();
91
+ process.chdir(rootDirectory);
92
+ const { flags: { hostname, useExisting, login, analytics, verbose } } = await this.parse(Setup);
93
+ await this._seekTermsOfUseConsent(login, verbose);
94
+ await this._seekAnalyticsConsent(analytics);
95
+ const options = new SetupCommandOptions(hostname, useExisting, verbose);
96
+ await this._commandValidator.validate(options);
97
+ await this._commandExecutor.execute(options);
98
+ }
99
+ async catch(error) {
100
+ this._analyticsService.postEvent(AnalyticsErrorMarkers.ERROR_SSL_SETUP, error.message, false);
101
+ throw error;
102
+ }
103
+ async _seekTermsOfUseConsent(login, verbose) {
104
+ if (login) {
105
+ await this._accountService.invalidateToken(verbose);
106
+ }
107
+ await this._accountService.seekTermsOfUseConsent();
108
+ }
109
+ async _seekAnalyticsConsent(analytics) {
110
+ if (analytics === undefined) {
111
+ await this._analyticsConsent.get();
112
+ }
113
+ else {
114
+ await this._analyticsConsent.set(analytics === "on");
115
+ }
116
+ }
117
+ }
118
+ //# sourceMappingURL=setup.js.map