@sitecore-jss/sitecore-jss-dev-tools 22.4.0-canary.8 → 22.4.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/LICENSE.txt CHANGED
@@ -1,202 +1,202 @@
1
-
2
- Apache License
3
- Version 2.0, January 2004
4
- http://www.apache.org/licenses/
5
-
6
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
-
8
- 1. Definitions.
9
-
10
- "License" shall mean the terms and conditions for use, reproduction,
11
- and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by
14
- the copyright owner that is granting the License.
15
-
16
- "Legal Entity" shall mean the union of the acting entity and all
17
- other entities that control, are controlled by, or are under common
18
- control with that entity. For the purposes of this definition,
19
- "control" means (i) the power, direct or indirect, to cause the
20
- direction or management of such entity, whether by contract or
21
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
- outstanding shares, or (iii) beneficial ownership of such entity.
23
-
24
- "You" (or "Your") shall mean an individual or Legal Entity
25
- exercising permissions granted by this License.
26
-
27
- "Source" form shall mean the preferred form for making modifications,
28
- including but not limited to software source code, documentation
29
- source, and configuration files.
30
-
31
- "Object" form shall mean any form resulting from mechanical
32
- transformation or translation of a Source form, including but
33
- not limited to compiled object code, generated documentation,
34
- and conversions to other media types.
35
-
36
- "Work" shall mean the work of authorship, whether in Source or
37
- Object form, made available under the License, as indicated by a
38
- copyright notice that is included in or attached to the work
39
- (an example is provided in the Appendix below).
40
-
41
- "Derivative Works" shall mean any work, whether in Source or Object
42
- form, that is based on (or derived from) the Work and for which the
43
- editorial revisions, annotations, elaborations, or other modifications
44
- represent, as a whole, an original work of authorship. For the purposes
45
- of this License, Derivative Works shall not include works that remain
46
- separable from, or merely link (or bind by name) to the interfaces of,
47
- the Work and Derivative Works thereof.
48
-
49
- "Contribution" shall mean any work of authorship, including
50
- the original version of the Work and any modifications or additions
51
- to that Work or Derivative Works thereof, that is intentionally
52
- submitted to Licensor for inclusion in the Work by the copyright owner
53
- or by an individual or Legal Entity authorized to submit on behalf of
54
- the copyright owner. For the purposes of this definition, "submitted"
55
- means any form of electronic, verbal, or written communication sent
56
- to the Licensor or its representatives, including but not limited to
57
- communication on electronic mailing lists, source code control systems,
58
- and issue tracking systems that are managed by, or on behalf of, the
59
- Licensor for the purpose of discussing and improving the Work, but
60
- excluding communication that is conspicuously marked or otherwise
61
- designated in writing by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to reproduce, prepare Derivative Works of,
71
- publicly display, publicly perform, sublicense, and distribute the
72
- Work and such Derivative Works in Source or Object form.
73
-
74
- 3. Grant of Patent License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- (except as stated in this section) patent license to make, have made,
78
- use, offer to sell, sell, import, and otherwise transfer the Work,
79
- where such license applies only to those patent claims licensable
80
- by such Contributor that are necessarily infringed by their
81
- Contribution(s) alone or by combination of their Contribution(s)
82
- with the Work to which such Contribution(s) was submitted. If You
83
- institute patent litigation against any entity (including a
84
- cross-claim or counterclaim in a lawsuit) alleging that the Work
85
- or a Contribution incorporated within the Work constitutes direct
86
- or contributory patent infringement, then any patent licenses
87
- granted to You under this License for that Work shall terminate
88
- as of the date such litigation is filed.
89
-
90
- 4. Redistribution. You may reproduce and distribute copies of the
91
- Work or Derivative Works thereof in any medium, with or without
92
- modifications, and in Source or Object form, provided that You
93
- meet the following conditions:
94
-
95
- (a) You must give any other recipients of the Work or
96
- Derivative Works a copy of this License; and
97
-
98
- (b) You must cause any modified files to carry prominent notices
99
- stating that You changed the files; and
100
-
101
- (c) You must retain, in the Source form of any Derivative Works
102
- that You distribute, all copyright, patent, trademark, and
103
- attribution notices from the Source form of the Work,
104
- excluding those notices that do not pertain to any part of
105
- the Derivative Works; and
106
-
107
- (d) If the Work includes a "NOTICE" text file as part of its
108
- distribution, then any Derivative Works that You distribute must
109
- include a readable copy of the attribution notices contained
110
- within such NOTICE file, excluding those notices that do not
111
- pertain to any part of the Derivative Works, in at least one
112
- of the following places: within a NOTICE text file distributed
113
- as part of the Derivative Works; within the Source form or
114
- documentation, if provided along with the Derivative Works; or,
115
- within a display generated by the Derivative Works, if and
116
- wherever such third-party notices normally appear. The contents
117
- of the NOTICE file are for informational purposes only and
118
- do not modify the License. You may add Your own attribution
119
- notices within Derivative Works that You distribute, alongside
120
- or as an addendum to the NOTICE text from the Work, provided
121
- that such additional attribution notices cannot be construed
122
- as modifying the License.
123
-
124
- You may add Your own copyright statement to Your modifications and
125
- may provide additional or different license terms and conditions
126
- for use, reproduction, or distribution of Your modifications, or
127
- for any such Derivative Works as a whole, provided Your use,
128
- reproduction, and distribution of the Work otherwise complies with
129
- the conditions stated in this License.
130
-
131
- 5. Submission of Contributions. Unless You explicitly state otherwise,
132
- any Contribution intentionally submitted for inclusion in the Work
133
- by You to the Licensor shall be under the terms and conditions of
134
- this License, without any additional terms or conditions.
135
- Notwithstanding the above, nothing herein shall supersede or modify
136
- the terms of any separate license agreement you may have executed
137
- with Licensor regarding such Contributions.
138
-
139
- 6. Trademarks. This License does not grant permission to use the trade
140
- names, trademarks, service marks, or product names of the Licensor,
141
- except as required for reasonable and customary use in describing the
142
- origin of the Work and reproducing the content of the NOTICE file.
143
-
144
- 7. Disclaimer of Warranty. Unless required by applicable law or
145
- agreed to in writing, Licensor provides the Work (and each
146
- Contributor provides its Contributions) on an "AS IS" BASIS,
147
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
- implied, including, without limitation, any warranties or conditions
149
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
- PARTICULAR PURPOSE. You are solely responsible for determining the
151
- appropriateness of using or redistributing the Work and assume any
152
- risks associated with Your exercise of permissions under this License.
153
-
154
- 8. Limitation of Liability. In no event and under no legal theory,
155
- whether in tort (including negligence), contract, or otherwise,
156
- unless required by applicable law (such as deliberate and grossly
157
- negligent acts) or agreed to in writing, shall any Contributor be
158
- liable to You for damages, including any direct, indirect, special,
159
- incidental, or consequential damages of any character arising as a
160
- result of this License or out of the use or inability to use the
161
- Work (including but not limited to damages for loss of goodwill,
162
- work stoppage, computer failure or malfunction, or any and all
163
- other commercial damages or losses), even if such Contributor
164
- has been advised of the possibility of such damages.
165
-
166
- 9. Accepting Warranty or Additional Liability. While redistributing
167
- the Work or Derivative Works thereof, You may choose to offer,
168
- and charge a fee for, acceptance of support, warranty, indemnity,
169
- or other liability obligations and/or rights consistent with this
170
- License. However, in accepting such obligations, You may act only
171
- on Your own behalf and on Your sole responsibility, not on behalf
172
- of any other Contributor, and only if You agree to indemnify,
173
- defend, and hold each Contributor harmless for any liability
174
- incurred by, or claims asserted against, such Contributor by reason
175
- of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- APPENDIX: How to apply the Apache License to your work.
180
-
181
- To apply the Apache License to your work, attach the following
182
- boilerplate notice, with the fields enclosed by brackets "[]"
183
- replaced with your own identifying information. (Don't include
184
- the brackets!) The text should be enclosed in the appropriate
185
- comment syntax for the file format. We also recommend that a
186
- file or class name and description of purpose be included on the
187
- same "printed page" as the copyright notice for easier
188
- identification within third-party archives.
189
-
190
- Copyright [yyyy] [name of copyright owner]
191
-
192
- Licensed under the Apache License, Version 2.0 (the "License");
193
- you may not use this file except in compliance with the License.
194
- You may obtain a copy of the License at
195
-
196
- http://www.apache.org/licenses/LICENSE-2.0
197
-
198
- Unless required by applicable law or agreed to in writing, software
199
- distributed under the License is distributed on an "AS IS" BASIS,
200
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
- See the License for the specific language governing permissions and
202
- limitations under the License.
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
- # Sitecore JavaScript Rendering SDK Developer Tools
2
-
3
- This module is provided as a part of Sitecore JavaScript Rendering SDK (JSS). It contains developer tooling, such as development proxies and deployment scripts.
4
-
5
- <!---
6
- @TODO: Update to next version docs before release
7
- -->
8
- [Documentation (Experience Platform)](https://doc.sitecore.com/xp/en/developers/hd/22/sitecore-headless-development/sitecore-javascript-rendering-sdks--jss-.html)
9
-
10
- [Documentation (XM Cloud)](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-javascript-rendering-sdks--jss-.html)
11
-
12
- [API reference documentation](/ref-docs/sitecore-jss-dev-tools/)
1
+ # Sitecore JavaScript Rendering SDK Developer Tools
2
+
3
+ This module is provided as a part of Sitecore JavaScript Rendering SDK (JSS). It contains developer tooling, such as development proxies and deployment scripts.
4
+
5
+ <!---
6
+ @TODO: Update to next version docs before release
7
+ -->
8
+ [Documentation (Experience Platform)](https://doc.sitecore.com/xp/en/developers/hd/22/sitecore-headless-development/sitecore-javascript-rendering-sdks--jss-.html)
9
+
10
+ [Documentation (XM Cloud)](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-javascript-rendering-sdks--jss-.html)
11
+
12
+ [API reference documentation](/ref-docs/sitecore-jss-dev-tools/)
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -40,15 +17,16 @@ exports.normalizeFingerprint = normalizeFingerprint;
40
17
  exports.doFingerprintsMatch = doFingerprintsMatch;
41
18
  exports.finishWatchJobStatusTask = finishWatchJobStatusTask;
42
19
  exports.logJobStatus = logJobStatus;
20
+ exports.watchJobStatus = watchJobStatus;
43
21
  exports.packageDeploy = packageDeploy;
44
- exports.extractProxy = extractProxy;
45
- exports.getHttpsTransport = getHttpsTransport;
22
+ exports.setProxy = setProxy;
23
+ exports.attachFormDataHandlers = attachFormDataHandlers;
46
24
  const chalk_1 = __importDefault(require("chalk"));
47
25
  const fs_1 = __importDefault(require("fs"));
48
- const https_1 = __importStar(require("https"));
26
+ const https_1 = __importDefault(require("https"));
27
+ const http_1 = __importDefault(require("http"));
49
28
  const path_1 = __importDefault(require("path"));
50
29
  const form_data_1 = __importDefault(require("form-data"));
51
- const axios_1 = __importDefault(require("axios"));
52
30
  const digest_1 = require("./digest");
53
31
  // Node does not use system level trusted CAs. This causes issues because SIF likes to install
54
32
  // using a Windows trusted CA - so SSL connections to Sitecore will fail from Node.
@@ -161,18 +139,21 @@ function watchJobStatus(options, taskName) {
161
139
  const warnings = [];
162
140
  const factors = [options.appName, taskName, `${options.importServiceUrl}/status`];
163
141
  const mac = (0, digest_1.hmac)(factors, options.secret);
142
+ const url = new URL(`${options.importServiceUrl}/status?appName=${options.appName}&jobName=${taskName}&after=${logOffset}`);
164
143
  const isHttps = options.importServiceUrl.startsWith('https');
165
- const requestBaseOptions = {
166
- transport: isHttps ? getHttpsTransport(options) : undefined,
144
+ const client = isHttps ? https_1.default : http_1.default;
145
+ const reqOptions = {
167
146
  headers: {
168
147
  'User-Agent': 'Sitecore/JSS-Import',
169
148
  'Cache-Control': 'no-cache',
170
149
  'X-JSS-Auth': mac,
171
150
  },
172
- proxy: extractProxy(options.proxy),
173
- maxRedirects: 0,
174
- httpsAgent: isHttps
175
- ? new https_1.Agent({
151
+ method: 'GET',
152
+ hostname: url.hostname,
153
+ protocol: url.protocol,
154
+ path: url.pathname + url.search,
155
+ agent: isHttps
156
+ ? new https_1.default.Agent({
176
157
  // we turn off normal CA cert validation when we are whitelisting a single cert thumbprint
177
158
  rejectUnauthorized: options.acceptCertificate ? false : true,
178
159
  // needed to allow whitelisting a cert thumbprint if a connection is reused
@@ -184,60 +165,76 @@ function watchJobStatus(options, taskName) {
184
165
  console.log(`Deployment status security factors: ${factors}`);
185
166
  console.log(`Deployment status HMAC: ${mac}`);
186
167
  }
187
- return new Promise((resolve, reject) => {
188
- /**
189
- * Send job status request
190
- */
191
- function sendJobStatusRequest() {
192
- axios_1.default
193
- .get(`${options.importServiceUrl}/status?appName=${options.appName}&jobName=${taskName}&after=${logOffset}`, requestBaseOptions)
194
- .then((response) => {
195
- const body = response.data;
196
- try {
197
- const { state, messages } = body;
198
- messages.forEach((entry) => {
199
- logOffset++;
200
- const entryBits = /^(\[([A-Z]+)\] )?(.+)/.exec(entry);
201
- let entryLevel = 'INFO';
202
- let message = entry;
203
- if (entryBits && entryBits[2]) {
204
- entryLevel = entryBits[2];
205
- // 3 = '[] ' in say [INFO] My log message
206
- // we're not using the capture group as the message might be multi-line
207
- message = entry.substring(entryLevel.length + 3);
208
- }
209
- if (message.startsWith('[JSS] - ')) {
210
- message = message.substring(8);
211
- }
212
- logJobStatus({ message, entryLevel, warnings, errors });
213
- });
214
- if (state === 'Finished') {
215
- finishWatchJobStatusTask({ warnings, errors, resolve, reject });
216
- return;
217
- }
218
- setTimeout(sendJobStatusRequest, 1000);
219
- }
220
- catch (error) {
221
- console.error(chalk_1.default.red(`Unexpected error processing reply from import status service: ${error}`));
222
- console.error(chalk_1.default.red(`Response: ${body}`));
223
- console.error(chalk_1.default.red('Consult the Sitecore logs for details.'));
224
- reject(error);
225
- }
226
- })
227
- .catch((error) => {
168
+ if (options.proxy) {
169
+ setProxy(reqOptions, options.proxy, options.importServiceUrl);
170
+ }
171
+ const req = client.request(reqOptions);
172
+ if (isHttps) {
173
+ applyCertPinning(req, options);
174
+ }
175
+ let responseData = '';
176
+ req.on('response', (res) => {
177
+ if (res.statusCode !== 200) {
178
+ let errorData = '';
179
+ res.on('data', (chunk) => {
180
+ errorData += chunk;
181
+ });
182
+ res.on('end', () => {
228
183
  console.error(chalk_1.default.red('Unexpected response from import status service. The import task is probably still running; check the Sitecore logs for details.'));
229
- if (error.response) {
230
- console.error(chalk_1.default.red(`Status message: ${error.response.statusText}`));
231
- console.error(chalk_1.default.red(`Status: ${error.response.status}`));
232
- }
233
- else {
234
- console.error(chalk_1.default.red(error.message));
235
- }
236
- reject();
184
+ console.error(chalk_1.default.red(`Status message: ${res.statusMessage}`));
185
+ console.error(chalk_1.default.red(`Status: ${res.statusCode}`));
186
+ process.exit(1);
237
187
  });
188
+ return;
238
189
  }
239
- setTimeout(sendJobStatusRequest, 1000);
190
+ res.on('error', (err) => {
191
+ console.error(chalk_1.default.red('Unexpected response from import status service. The import task is probably still running; check the Sitecore logs for details.'));
192
+ console.error(chalk_1.default.red(`Status message: ${err.message}`));
193
+ console.error(chalk_1.default.red(`Status: ${res.statusCode}`));
194
+ process.exit(1);
195
+ });
196
+ res.on('data', (chunk) => {
197
+ responseData += chunk;
198
+ });
199
+ res.on('end', () => {
200
+ try {
201
+ const body = JSON.parse(responseData);
202
+ const { state, messages } = body;
203
+ messages.forEach((entry) => {
204
+ logOffset++;
205
+ const entryBits = /^(\[([A-Z]+)\] )?(.+)/.exec(entry);
206
+ let entryLevel = 'INFO';
207
+ let message = entry;
208
+ if (entryBits && entryBits[2]) {
209
+ entryLevel = entryBits[2];
210
+ // 3 = '[] ' in say [INFO] My log message
211
+ // we're not using the capture group as the message might be multi-line
212
+ message = entry.substring(entryLevel.length + 3);
213
+ }
214
+ if (message.startsWith('[JSS] - ')) {
215
+ message = message.substring(8);
216
+ }
217
+ logJobStatus({ message, entryLevel, warnings, errors });
218
+ });
219
+ if (state === 'Finished') {
220
+ finishWatchJobStatusTask({ warnings, errors, resolve: () => { }, reject: () => { } });
221
+ return;
222
+ }
223
+ setTimeout(() => watchJobStatus(options, taskName), 1000);
224
+ }
225
+ catch (error) {
226
+ console.error(chalk_1.default.red(`Unexpected error processing reply from import status service: ${error}`));
227
+ console.error(chalk_1.default.red(`Response: ${responseData}`));
228
+ console.error(chalk_1.default.red('Consult the Sitecore logs for details.'));
229
+ process.exit(1);
230
+ }
231
+ });
240
232
  });
233
+ req.on('error', (err) => {
234
+ console.error(chalk_1.default.red(`Request error: ${err.message}`));
235
+ process.exit(1);
236
+ });
237
+ req.end();
241
238
  });
242
239
  }
243
240
  /**
@@ -251,7 +248,7 @@ function packageDeploy(options) {
251
248
  if (options.secret.length < 32) {
252
249
  throw new Error('Deployment secret was too short. Use a RANDOM (not words or phrases) secret at least 32 characters long.');
253
250
  }
254
- let packageFile = null;
251
+ let packageFile = '';
255
252
  fs_1.default.readdirSync(options.packagePath).forEach((file) => {
256
253
  if (file.startsWith(options.appName) && file.endsWith('.manifest.zip')) {
257
254
  packageFile = path_1.default.join(options.packagePath, file);
@@ -268,60 +265,84 @@ function packageDeploy(options) {
268
265
  console.log(`Deployment HMAC: ${(0, digest_1.hmac)(factors, options.secret)}`);
269
266
  }
270
267
  const formData = new form_data_1.default();
271
- formData.append('path', fs_1.default.createReadStream(packageFile));
268
+ const fileStream = fs_1.default.createReadStream(packageFile);
269
+ const url = new URL(options.importServiceUrl);
272
270
  formData.append('appName', options.appName);
271
+ formData.append('path', fileStream);
273
272
  const isHttps = options.importServiceUrl.startsWith('https');
274
- const requestBaseOptions = {
275
- transport: isHttps ? getHttpsTransport(options) : undefined,
273
+ const client = isHttps ? https_1.default : http_1.default;
274
+ const reqOptions = {
276
275
  headers: Object.assign({ 'User-Agent': 'Sitecore/JSS-Import', 'Cache-Control': 'no-cache', 'X-JSS-Auth': (0, digest_1.hmac)(factors, options.secret) }, formData.getHeaders()),
277
- proxy: extractProxy(options.proxy),
278
- httpsAgent: isHttps
279
- ? new https_1.Agent({
276
+ method: 'POST',
277
+ hostname: url.hostname,
278
+ protocol: url.protocol,
279
+ path: url.pathname,
280
+ agent: isHttps
281
+ ? new https_1.default.Agent({
280
282
  // we turn off normal CA cert validation when we are whitelisting a single cert thumbprint
281
283
  rejectUnauthorized: options.acceptCertificate ? false : true,
282
284
  // needed to allow whitelisting a cert thumbprint if a connection is reused
283
285
  maxCachedSessions: options.acceptCertificate ? 0 : undefined,
284
286
  })
285
287
  : undefined,
286
- maxRedirects: 0,
287
288
  };
288
- console.log(`Sending package ${packageFile} to ${options.importServiceUrl}...`);
289
- return new Promise((resolve, reject) => {
290
- axios_1.default
291
- .post(options.importServiceUrl, formData, requestBaseOptions)
292
- .then((response) => {
293
- const body = response.data;
294
- console.log(chalk_1.default.green(`Sitecore has accepted import task ${body}`));
295
- resolve(body);
296
- })
297
- .catch((error) => {
298
- console.error(chalk_1.default.red('Unexpected response from import service:'));
299
- if (error.response) {
300
- console.error(chalk_1.default.red(`Status message: ${error.response.statusText}`));
301
- console.error(chalk_1.default.red(`Status: ${error.response.status}`));
302
- }
303
- else {
304
- console.error(chalk_1.default.red(error.message));
305
- }
306
- reject();
289
+ if (options.proxy) {
290
+ setProxy(reqOptions, options.proxy, options.importServiceUrl);
291
+ }
292
+ const req = client.request(reqOptions);
293
+ if (https_1.default) {
294
+ applyCertPinning(req, options);
295
+ }
296
+ attachFormDataHandlers(req, formData);
297
+ formData.pipe(req);
298
+ req.on('response', (res) => {
299
+ if (res.statusCode !== 200) {
300
+ let errorData = '';
301
+ res.on('data', (chunk) => {
302
+ errorData += chunk;
303
+ });
304
+ res.on('end', () => {
305
+ console.error(chalk_1.default.red(`Error while uploading package: ${res.statusCode} ${res.statusMessage}`));
306
+ console.error(chalk_1.default.red(errorData));
307
+ process.exit(1);
308
+ });
309
+ return;
310
+ }
311
+ let responseData = '';
312
+ res.on('error', (err) => {
313
+ console.error(chalk_1.default.red(`Response error when uploading package: ${err.message}`));
314
+ process.exit(1);
315
+ });
316
+ res.on('data', (chunk) => {
317
+ responseData += chunk;
307
318
  });
308
- }).then((taskName) => watchJobStatus(options, taskName));
319
+ res.on('end', () => {
320
+ const taskName = responseData;
321
+ console.log('we are in packageDeploy', responseData);
322
+ console.log(chalk_1.default.green(`Package uploaded. Import task name: ${taskName}`));
323
+ watchJobStatus(options, taskName);
324
+ });
325
+ });
326
+ req.on('error', (err) => {
327
+ console.error(chalk_1.default.red(`Error while uploading package: ${err.message}`));
328
+ process.exit(1);
329
+ });
309
330
  });
310
331
  }
311
332
  /**
312
- * Creates valid proxy object which fit to axios configuration
313
- * @param {string} [proxy] proxy url
333
+ * Creates valid proxy object
334
+ * @param {RequestOptions} reqOptions
335
+ * @param {string} proxy proxy url
336
+ * @param {string} targetUrl target url
314
337
  */
315
- function extractProxy(proxy) {
316
- if (!proxy)
317
- return undefined;
338
+ function setProxy(reqOptions, proxy, targetUrl) {
318
339
  try {
319
340
  const proxyUrl = new URL(proxy);
320
- return {
321
- protocol: proxyUrl.protocol.slice(0, -1),
322
- host: proxyUrl.hostname,
323
- port: +proxyUrl.port,
324
- };
341
+ reqOptions.hostname = proxyUrl.hostname;
342
+ reqOptions.port = proxyUrl.port || (proxyUrl.protocol === 'https:' ? '443' : '80');
343
+ reqOptions.protocol = proxyUrl.protocol;
344
+ reqOptions.path = targetUrl;
345
+ reqOptions.headers = Object.assign(Object.assign({}, reqOptions.headers), { Host: new URL(targetUrl).hostname });
325
346
  }
326
347
  catch (error) {
327
348
  console.error(chalk_1.default.red(`Invalid proxy url provided ${proxy}`));
@@ -329,15 +350,24 @@ function extractProxy(proxy) {
329
350
  }
330
351
  }
331
352
  /**
332
- * Provides way to customize axios request adapter
333
- * in order to execute certificate pinning before request sent:
334
- * {@link https://github.com/axios/axios/issues/2808}
335
- * @param {PackageDeployOptions} options
353
+ * Attach form data handlers to handle errors and close events
354
+ * @param {ClientRequest} req request object
355
+ * @param {FormData} formData FormData object
336
356
  */
337
- function getHttpsTransport(options) {
338
- return Object.assign(Object.assign({}, https_1.default), { request: (reqOptions, callback) => {
339
- const req = https_1.default.request(Object.assign({}, reqOptions), callback);
340
- applyCertPinning(req, options);
341
- return req;
342
- } });
357
+ function attachFormDataHandlers(req, formData) {
358
+ let ended = false;
359
+ let errored = false;
360
+ formData.on('end', () => {
361
+ ended = true;
362
+ });
363
+ formData.once('error', (err) => {
364
+ errored = true;
365
+ console.log('Error when uploading package:', err);
366
+ req.destroy(err);
367
+ });
368
+ formData.on('close', () => {
369
+ if (!ended && !errored) {
370
+ new Error('Request stream has been aborted');
371
+ }
372
+ });
343
373
  }
@@ -9,10 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import chalk from 'chalk';
11
11
  import fs from 'fs';
12
- import https, { Agent as HttpsAgent } from 'https';
12
+ import https from 'https';
13
+ import http from 'http';
13
14
  import path from 'path';
14
15
  import FormData from 'form-data';
15
- import axios from 'axios';
16
16
  import { digest, hmac } from './digest';
17
17
  // Node does not use system level trusted CAs. This causes issues because SIF likes to install
18
18
  // using a Windows trusted CA - so SSL connections to Sitecore will fail from Node.
@@ -118,25 +118,28 @@ export function logJobStatus({ message, entryLevel, warnings, errors, }) {
118
118
  * @param {PackageDeployOptions} options
119
119
  * @param {string} taskName
120
120
  */
121
- function watchJobStatus(options, taskName) {
121
+ export function watchJobStatus(options, taskName) {
122
122
  return __awaiter(this, void 0, void 0, function* () {
123
123
  let logOffset = 0;
124
124
  const errors = [];
125
125
  const warnings = [];
126
126
  const factors = [options.appName, taskName, `${options.importServiceUrl}/status`];
127
127
  const mac = hmac(factors, options.secret);
128
+ const url = new URL(`${options.importServiceUrl}/status?appName=${options.appName}&jobName=${taskName}&after=${logOffset}`);
128
129
  const isHttps = options.importServiceUrl.startsWith('https');
129
- const requestBaseOptions = {
130
- transport: isHttps ? getHttpsTransport(options) : undefined,
130
+ const client = isHttps ? https : http;
131
+ const reqOptions = {
131
132
  headers: {
132
133
  'User-Agent': 'Sitecore/JSS-Import',
133
134
  'Cache-Control': 'no-cache',
134
135
  'X-JSS-Auth': mac,
135
136
  },
136
- proxy: extractProxy(options.proxy),
137
- maxRedirects: 0,
138
- httpsAgent: isHttps
139
- ? new HttpsAgent({
137
+ method: 'GET',
138
+ hostname: url.hostname,
139
+ protocol: url.protocol,
140
+ path: url.pathname + url.search,
141
+ agent: isHttps
142
+ ? new https.Agent({
140
143
  // we turn off normal CA cert validation when we are whitelisting a single cert thumbprint
141
144
  rejectUnauthorized: options.acceptCertificate ? false : true,
142
145
  // needed to allow whitelisting a cert thumbprint if a connection is reused
@@ -148,60 +151,76 @@ function watchJobStatus(options, taskName) {
148
151
  console.log(`Deployment status security factors: ${factors}`);
149
152
  console.log(`Deployment status HMAC: ${mac}`);
150
153
  }
151
- return new Promise((resolve, reject) => {
152
- /**
153
- * Send job status request
154
- */
155
- function sendJobStatusRequest() {
156
- axios
157
- .get(`${options.importServiceUrl}/status?appName=${options.appName}&jobName=${taskName}&after=${logOffset}`, requestBaseOptions)
158
- .then((response) => {
159
- const body = response.data;
160
- try {
161
- const { state, messages } = body;
162
- messages.forEach((entry) => {
163
- logOffset++;
164
- const entryBits = /^(\[([A-Z]+)\] )?(.+)/.exec(entry);
165
- let entryLevel = 'INFO';
166
- let message = entry;
167
- if (entryBits && entryBits[2]) {
168
- entryLevel = entryBits[2];
169
- // 3 = '[] ' in say [INFO] My log message
170
- // we're not using the capture group as the message might be multi-line
171
- message = entry.substring(entryLevel.length + 3);
172
- }
173
- if (message.startsWith('[JSS] - ')) {
174
- message = message.substring(8);
175
- }
176
- logJobStatus({ message, entryLevel, warnings, errors });
177
- });
178
- if (state === 'Finished') {
179
- finishWatchJobStatusTask({ warnings, errors, resolve, reject });
180
- return;
181
- }
182
- setTimeout(sendJobStatusRequest, 1000);
183
- }
184
- catch (error) {
185
- console.error(chalk.red(`Unexpected error processing reply from import status service: ${error}`));
186
- console.error(chalk.red(`Response: ${body}`));
187
- console.error(chalk.red('Consult the Sitecore logs for details.'));
188
- reject(error);
189
- }
190
- })
191
- .catch((error) => {
154
+ if (options.proxy) {
155
+ setProxy(reqOptions, options.proxy, options.importServiceUrl);
156
+ }
157
+ const req = client.request(reqOptions);
158
+ if (isHttps) {
159
+ applyCertPinning(req, options);
160
+ }
161
+ let responseData = '';
162
+ req.on('response', (res) => {
163
+ if (res.statusCode !== 200) {
164
+ let errorData = '';
165
+ res.on('data', (chunk) => {
166
+ errorData += chunk;
167
+ });
168
+ res.on('end', () => {
192
169
  console.error(chalk.red('Unexpected response from import status service. The import task is probably still running; check the Sitecore logs for details.'));
193
- if (error.response) {
194
- console.error(chalk.red(`Status message: ${error.response.statusText}`));
195
- console.error(chalk.red(`Status: ${error.response.status}`));
196
- }
197
- else {
198
- console.error(chalk.red(error.message));
199
- }
200
- reject();
170
+ console.error(chalk.red(`Status message: ${res.statusMessage}`));
171
+ console.error(chalk.red(`Status: ${res.statusCode}`));
172
+ process.exit(1);
201
173
  });
174
+ return;
202
175
  }
203
- setTimeout(sendJobStatusRequest, 1000);
176
+ res.on('error', (err) => {
177
+ console.error(chalk.red('Unexpected response from import status service. The import task is probably still running; check the Sitecore logs for details.'));
178
+ console.error(chalk.red(`Status message: ${err.message}`));
179
+ console.error(chalk.red(`Status: ${res.statusCode}`));
180
+ process.exit(1);
181
+ });
182
+ res.on('data', (chunk) => {
183
+ responseData += chunk;
184
+ });
185
+ res.on('end', () => {
186
+ try {
187
+ const body = JSON.parse(responseData);
188
+ const { state, messages } = body;
189
+ messages.forEach((entry) => {
190
+ logOffset++;
191
+ const entryBits = /^(\[([A-Z]+)\] )?(.+)/.exec(entry);
192
+ let entryLevel = 'INFO';
193
+ let message = entry;
194
+ if (entryBits && entryBits[2]) {
195
+ entryLevel = entryBits[2];
196
+ // 3 = '[] ' in say [INFO] My log message
197
+ // we're not using the capture group as the message might be multi-line
198
+ message = entry.substring(entryLevel.length + 3);
199
+ }
200
+ if (message.startsWith('[JSS] - ')) {
201
+ message = message.substring(8);
202
+ }
203
+ logJobStatus({ message, entryLevel, warnings, errors });
204
+ });
205
+ if (state === 'Finished') {
206
+ finishWatchJobStatusTask({ warnings, errors, resolve: () => { }, reject: () => { } });
207
+ return;
208
+ }
209
+ setTimeout(() => watchJobStatus(options, taskName), 1000);
210
+ }
211
+ catch (error) {
212
+ console.error(chalk.red(`Unexpected error processing reply from import status service: ${error}`));
213
+ console.error(chalk.red(`Response: ${responseData}`));
214
+ console.error(chalk.red('Consult the Sitecore logs for details.'));
215
+ process.exit(1);
216
+ }
217
+ });
218
+ });
219
+ req.on('error', (err) => {
220
+ console.error(chalk.red(`Request error: ${err.message}`));
221
+ process.exit(1);
204
222
  });
223
+ req.end();
205
224
  });
206
225
  }
207
226
  /**
@@ -215,7 +234,7 @@ export function packageDeploy(options) {
215
234
  if (options.secret.length < 32) {
216
235
  throw new Error('Deployment secret was too short. Use a RANDOM (not words or phrases) secret at least 32 characters long.');
217
236
  }
218
- let packageFile = null;
237
+ let packageFile = '';
219
238
  fs.readdirSync(options.packagePath).forEach((file) => {
220
239
  if (file.startsWith(options.appName) && file.endsWith('.manifest.zip')) {
221
240
  packageFile = path.join(options.packagePath, file);
@@ -232,60 +251,84 @@ export function packageDeploy(options) {
232
251
  console.log(`Deployment HMAC: ${hmac(factors, options.secret)}`);
233
252
  }
234
253
  const formData = new FormData();
235
- formData.append('path', fs.createReadStream(packageFile));
254
+ const fileStream = fs.createReadStream(packageFile);
255
+ const url = new URL(options.importServiceUrl);
236
256
  formData.append('appName', options.appName);
257
+ formData.append('path', fileStream);
237
258
  const isHttps = options.importServiceUrl.startsWith('https');
238
- const requestBaseOptions = {
239
- transport: isHttps ? getHttpsTransport(options) : undefined,
259
+ const client = isHttps ? https : http;
260
+ const reqOptions = {
240
261
  headers: Object.assign({ 'User-Agent': 'Sitecore/JSS-Import', 'Cache-Control': 'no-cache', 'X-JSS-Auth': hmac(factors, options.secret) }, formData.getHeaders()),
241
- proxy: extractProxy(options.proxy),
242
- httpsAgent: isHttps
243
- ? new HttpsAgent({
262
+ method: 'POST',
263
+ hostname: url.hostname,
264
+ protocol: url.protocol,
265
+ path: url.pathname,
266
+ agent: isHttps
267
+ ? new https.Agent({
244
268
  // we turn off normal CA cert validation when we are whitelisting a single cert thumbprint
245
269
  rejectUnauthorized: options.acceptCertificate ? false : true,
246
270
  // needed to allow whitelisting a cert thumbprint if a connection is reused
247
271
  maxCachedSessions: options.acceptCertificate ? 0 : undefined,
248
272
  })
249
273
  : undefined,
250
- maxRedirects: 0,
251
274
  };
252
- console.log(`Sending package ${packageFile} to ${options.importServiceUrl}...`);
253
- return new Promise((resolve, reject) => {
254
- axios
255
- .post(options.importServiceUrl, formData, requestBaseOptions)
256
- .then((response) => {
257
- const body = response.data;
258
- console.log(chalk.green(`Sitecore has accepted import task ${body}`));
259
- resolve(body);
260
- })
261
- .catch((error) => {
262
- console.error(chalk.red('Unexpected response from import service:'));
263
- if (error.response) {
264
- console.error(chalk.red(`Status message: ${error.response.statusText}`));
265
- console.error(chalk.red(`Status: ${error.response.status}`));
266
- }
267
- else {
268
- console.error(chalk.red(error.message));
269
- }
270
- reject();
275
+ if (options.proxy) {
276
+ setProxy(reqOptions, options.proxy, options.importServiceUrl);
277
+ }
278
+ const req = client.request(reqOptions);
279
+ if (https) {
280
+ applyCertPinning(req, options);
281
+ }
282
+ attachFormDataHandlers(req, formData);
283
+ formData.pipe(req);
284
+ req.on('response', (res) => {
285
+ if (res.statusCode !== 200) {
286
+ let errorData = '';
287
+ res.on('data', (chunk) => {
288
+ errorData += chunk;
289
+ });
290
+ res.on('end', () => {
291
+ console.error(chalk.red(`Error while uploading package: ${res.statusCode} ${res.statusMessage}`));
292
+ console.error(chalk.red(errorData));
293
+ process.exit(1);
294
+ });
295
+ return;
296
+ }
297
+ let responseData = '';
298
+ res.on('error', (err) => {
299
+ console.error(chalk.red(`Response error when uploading package: ${err.message}`));
300
+ process.exit(1);
301
+ });
302
+ res.on('data', (chunk) => {
303
+ responseData += chunk;
304
+ });
305
+ res.on('end', () => {
306
+ const taskName = responseData;
307
+ console.log('we are in packageDeploy', responseData);
308
+ console.log(chalk.green(`Package uploaded. Import task name: ${taskName}`));
309
+ watchJobStatus(options, taskName);
271
310
  });
272
- }).then((taskName) => watchJobStatus(options, taskName));
311
+ });
312
+ req.on('error', (err) => {
313
+ console.error(chalk.red(`Error while uploading package: ${err.message}`));
314
+ process.exit(1);
315
+ });
273
316
  });
274
317
  }
275
318
  /**
276
- * Creates valid proxy object which fit to axios configuration
277
- * @param {string} [proxy] proxy url
319
+ * Creates valid proxy object
320
+ * @param {RequestOptions} reqOptions
321
+ * @param {string} proxy proxy url
322
+ * @param {string} targetUrl target url
278
323
  */
279
- export function extractProxy(proxy) {
280
- if (!proxy)
281
- return undefined;
324
+ export function setProxy(reqOptions, proxy, targetUrl) {
282
325
  try {
283
326
  const proxyUrl = new URL(proxy);
284
- return {
285
- protocol: proxyUrl.protocol.slice(0, -1),
286
- host: proxyUrl.hostname,
287
- port: +proxyUrl.port,
288
- };
327
+ reqOptions.hostname = proxyUrl.hostname;
328
+ reqOptions.port = proxyUrl.port || (proxyUrl.protocol === 'https:' ? '443' : '80');
329
+ reqOptions.protocol = proxyUrl.protocol;
330
+ reqOptions.path = targetUrl;
331
+ reqOptions.headers = Object.assign(Object.assign({}, reqOptions.headers), { Host: new URL(targetUrl).hostname });
289
332
  }
290
333
  catch (error) {
291
334
  console.error(chalk.red(`Invalid proxy url provided ${proxy}`));
@@ -293,15 +336,24 @@ export function extractProxy(proxy) {
293
336
  }
294
337
  }
295
338
  /**
296
- * Provides way to customize axios request adapter
297
- * in order to execute certificate pinning before request sent:
298
- * {@link https://github.com/axios/axios/issues/2808}
299
- * @param {PackageDeployOptions} options
339
+ * Attach form data handlers to handle errors and close events
340
+ * @param {ClientRequest} req request object
341
+ * @param {FormData} formData FormData object
300
342
  */
301
- export function getHttpsTransport(options) {
302
- return Object.assign(Object.assign({}, https), { request: (reqOptions, callback) => {
303
- const req = https.request(Object.assign({}, reqOptions), callback);
304
- applyCertPinning(req, options);
305
- return req;
306
- } });
343
+ export function attachFormDataHandlers(req, formData) {
344
+ let ended = false;
345
+ let errored = false;
346
+ formData.on('end', () => {
347
+ ended = true;
348
+ });
349
+ formData.once('error', (err) => {
350
+ errored = true;
351
+ console.log('Error when uploading package:', err);
352
+ req.destroy(err);
353
+ });
354
+ formData.on('close', () => {
355
+ if (!ended && !errored) {
356
+ new Error('Request stream has been aborted');
357
+ }
358
+ });
307
359
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss-dev-tools",
3
- "version": "22.4.0-canary.8",
3
+ "version": "22.4.0",
4
4
  "description": "Utilities to assist in the development and deployment of Sitecore JSS apps.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -33,8 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@babel/parser": "^7.24.0",
36
- "@sitecore-jss/sitecore-jss": "^22.4.0-canary.8",
37
- "axios": "^1.3.2",
36
+ "@sitecore-jss/sitecore-jss": "22.4.0",
38
37
  "chalk": "^4.1.2",
39
38
  "chokidar": "^3.6.0",
40
39
  "del": "^6.0.0",
@@ -86,7 +85,7 @@
86
85
  "typescript": "~5.6.3"
87
86
  },
88
87
  "types": "types/index.d.ts",
89
- "gitHead": "8f30b87b7f4ee14b37224c5858f072f21a130549",
88
+ "gitHead": "775a85600b541df7bcffd0e4056154ee6d068992",
90
89
  "files": [
91
90
  "dist",
92
91
  "types",
@@ -1,5 +1,6 @@
1
- import https from 'https';
2
- import { ClientRequest, IncomingMessage } from 'http';
1
+ import { RequestOptions } from 'https';
2
+ import FormData from 'form-data';
3
+ import { ClientRequest } from 'http';
3
4
  export interface PackageDeployOptions {
4
5
  packagePath: string;
5
6
  appName: string;
@@ -51,30 +52,23 @@ export declare function logJobStatus({ message, entryLevel, warnings, errors, }:
51
52
  }): void;
52
53
  /**
53
54
  * @param {PackageDeployOptions} options
55
+ * @param {string} taskName
54
56
  */
55
- export declare function packageDeploy(options: PackageDeployOptions): Promise<unknown>;
57
+ export declare function watchJobStatus(options: PackageDeployOptions, taskName: string): Promise<void>;
56
58
  /**
57
- * Creates valid proxy object which fit to axios configuration
58
- * @param {string} [proxy] proxy url
59
+ * @param {PackageDeployOptions} options
59
60
  */
60
- export declare function extractProxy(proxy?: string): {
61
- protocol: string;
62
- host: string;
63
- port: number;
64
- } | undefined;
61
+ export declare function packageDeploy(options: PackageDeployOptions): Promise<void>;
65
62
  /**
66
- * Provides way to customize axios request adapter
67
- * in order to execute certificate pinning before request sent:
68
- * {@link https://github.com/axios/axios/issues/2808}
69
- * @param {PackageDeployOptions} options
63
+ * Creates valid proxy object
64
+ * @param {RequestOptions} reqOptions
65
+ * @param {string} proxy proxy url
66
+ * @param {string} targetUrl target url
67
+ */
68
+ export declare function setProxy(reqOptions: RequestOptions, proxy: string, targetUrl: string): void;
69
+ /**
70
+ * Attach form data handlers to handle errors and close events
71
+ * @param {ClientRequest} req request object
72
+ * @param {FormData} formData FormData object
70
73
  */
71
- export declare function getHttpsTransport(options: PackageDeployOptions): {
72
- request: (reqOptions: https.RequestOptions, callback: (res: IncomingMessage) => void) => ClientRequest;
73
- createServer<Request extends typeof IncomingMessage = typeof IncomingMessage, Response extends typeof import("http").ServerResponse = typeof import("http").ServerResponse>(requestListener?: import("http").RequestListener<Request, Response>): https.Server<Request, Response>;
74
- createServer<Request extends typeof IncomingMessage = typeof IncomingMessage, Response extends typeof import("http").ServerResponse = typeof import("http").ServerResponse>(options: https.ServerOptions<Request, Response>, requestListener?: import("http").RequestListener<Request, Response>): https.Server<Request, Response>;
75
- get(options: https.RequestOptions | string | import("url").URL, callback?: (res: IncomingMessage) => void): ClientRequest;
76
- get(url: string | import("url").URL, options: https.RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
77
- Agent: typeof https.Agent;
78
- Server: typeof https.Server;
79
- globalAgent: https.Agent;
80
- };
74
+ export declare function attachFormDataHandlers(req: ClientRequest, formData: FormData): void;