partner-center-broker 1.0.1 → 1.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.
- package/.editorconfig +12 -12
- package/.eslintignore +4 -3
- package/.eslintrc.json +54 -54
- package/.github/workflows/main.yml +30 -0
- package/.github/workflows/npm-publish.yml +58 -44
- package/.prettierignore +4 -3
- package/LICENSE +675 -674
- package/README.md +252 -135
- package/{dist → lib}/converters.d.ts +21 -17
- package/{dist → lib}/converters.js +62 -48
- package/lib/helpers.d.ts +5 -0
- package/lib/helpers.js +149 -0
- package/{dist → lib}/index.d.ts +18 -17
- package/{dist → lib}/index.js +361 -290
- package/{dist → lib}/interfaces.d.ts +221 -172
- package/{dist → lib}/interfaces.js +2 -2
- package/package.json +63 -57
package/{dist → lib}/index.js
RENAMED
|
@@ -1,290 +1,361 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
const got_1 = __importDefault(require("got"));
|
|
15
|
-
const querystring_1 = __importDefault(require("querystring"));
|
|
16
|
-
const converters_1 = require("./converters");
|
|
17
|
-
// Partner Center API https://docs.microsoft.com/en-us/windows/uwp/monetize/create-and-manage-submissions-using-windows-store-services
|
|
18
|
-
// API endpoints https://docs.microsoft.com/en-us/windows/uwp/monetize/manage-app-submissions
|
|
19
|
-
class DevCenter {
|
|
20
|
-
constructor(_tenantId, _clientId, _clientSecret) {
|
|
21
|
-
if (_tenantId
|
|
22
|
-
throw new Error(
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
try {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
else if (
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
const got_1 = __importDefault(require("got"));
|
|
15
|
+
const querystring_1 = __importDefault(require("querystring"));
|
|
16
|
+
const converters_1 = require("./converters");
|
|
17
|
+
// Partner Center API https://docs.microsoft.com/en-us/windows/uwp/monetize/create-and-manage-submissions-using-windows-store-services
|
|
18
|
+
// API endpoints https://docs.microsoft.com/en-us/windows/uwp/monetize/manage-app-submissions
|
|
19
|
+
class DevCenter {
|
|
20
|
+
constructor(_tenantId, _clientId, _clientSecret) {
|
|
21
|
+
if (typeof _tenantId != 'undefined' && !_tenantId) {
|
|
22
|
+
throw new Error('You must pass a valid Tenant ID. See the documentation for examples and guidance https://lancemccarthy.github.io/PartnerCenterBroker/.');
|
|
23
|
+
}
|
|
24
|
+
if (typeof _clientId != 'undefined' && !_clientId) {
|
|
25
|
+
throw new Error('You must pass a valid Client ID. See the documentation for examples and guidance https://lancemccarthy.github.io/PartnerCenterBroker/.');
|
|
26
|
+
}
|
|
27
|
+
if (typeof _clientSecret != 'undefined' && !_clientSecret) {
|
|
28
|
+
throw new Error('You must pass a valid Client Secret. See the documentation for examples and guidance https://lancemccarthy.github.io/PartnerCenterBroker/.');
|
|
29
|
+
}
|
|
30
|
+
this.tenantId = _tenantId;
|
|
31
|
+
this.clientId = _clientId;
|
|
32
|
+
this.clientSecret = _clientSecret;
|
|
33
|
+
}
|
|
34
|
+
GetAppInfo(appId) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
try {
|
|
37
|
+
let auth = yield this.authorize();
|
|
38
|
+
// https://docs.microsoft.com/en-us/windows/uwp/monetize/get-app-data
|
|
39
|
+
const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}"`;
|
|
40
|
+
const response = yield got_1.default(requestUrl, {
|
|
41
|
+
method: 'get',
|
|
42
|
+
headers: {
|
|
43
|
+
Authorization: `"${auth.token_type} ${auth.access_token}"`
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
if (response.statusCode == 200) {
|
|
47
|
+
return converters_1.Convert.toAppInfoResult(response.body);
|
|
48
|
+
}
|
|
49
|
+
else if (response.statusCode === 400) {
|
|
50
|
+
throw console.error('400 - The request parameters are invalid.');
|
|
51
|
+
}
|
|
52
|
+
else if (response.statusCode === 404) {
|
|
53
|
+
throw console.error('404 - The specified submission could not be found.');
|
|
54
|
+
}
|
|
55
|
+
else if (response.statusCode === 409) {
|
|
56
|
+
throw console.error('Error 409 - The specified submission was found but it could not be committed in its current state, or the app uses a Partner Center feature that is currently not supported by the Microsoft Store submission API.');
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw console.error(response.statusMessage);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
CreateAppSubmission(appId) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
try {
|
|
70
|
+
let auth = yield this.authorize();
|
|
71
|
+
// https://docs.microsoft.com/en-us/windows/uwp/monetize/create-an-app-submission
|
|
72
|
+
const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}/submissions"`;
|
|
73
|
+
const response = yield got_1.default(requestUrl, {
|
|
74
|
+
method: 'post',
|
|
75
|
+
headers: {
|
|
76
|
+
Authorization: `"${auth.token_type} ${auth.access_token}"`,
|
|
77
|
+
ContentType: 'application/json'
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
if (response.statusCode == 200) {
|
|
81
|
+
return converters_1.Convert.toCreateAppSubmissionResult(response.body);
|
|
82
|
+
}
|
|
83
|
+
else if (response.statusCode === 400) {
|
|
84
|
+
throw console.error('400 - The request parameters are invalid.');
|
|
85
|
+
}
|
|
86
|
+
else if (response.statusCode === 404) {
|
|
87
|
+
throw console.error('404 - The specified submission could not be found.');
|
|
88
|
+
}
|
|
89
|
+
else if (response.statusCode === 409) {
|
|
90
|
+
throw console.error('Error 409 - The specified submission was found but it could not be committed in its current state, or the app uses a Partner Center feature that is currently not supported by the Microsoft Store submission API.');
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
throw console.error(response.statusMessage);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
throw console.error(err);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
UpdateSubmission(appId, submissionId, data) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
try {
|
|
104
|
+
let auth = yield this.authorize();
|
|
105
|
+
// Special Note: carefully read Request Body section in the documentation
|
|
106
|
+
// https://docs.microsoft.com/en-us/windows/uwp/monetize/update-an-app-submission
|
|
107
|
+
const requestUrl = 'https://manage.devcenter.microsoft.com/v1.0/my/applications/{applicationId}/submissions/{submissionId}';
|
|
108
|
+
const response = yield got_1.default(requestUrl, {
|
|
109
|
+
method: 'post',
|
|
110
|
+
headers: {
|
|
111
|
+
Authorization: `"${auth.token_type} ${auth.access_token}"`,
|
|
112
|
+
ContentType: 'application/json'
|
|
113
|
+
},
|
|
114
|
+
body: converters_1.Convert.submissionDataToJson(data)
|
|
115
|
+
});
|
|
116
|
+
if (response.statusCode == 200) {
|
|
117
|
+
return converters_1.Convert.toUpdateSubmissionResult(response.body);
|
|
118
|
+
}
|
|
119
|
+
else if (response.statusCode === 400) {
|
|
120
|
+
throw console.error('400 - The request parameters are invalid.');
|
|
121
|
+
}
|
|
122
|
+
else if (response.statusCode === 404) {
|
|
123
|
+
throw console.error('404 - The specified submission could not be found.');
|
|
124
|
+
}
|
|
125
|
+
else if (response.statusCode === 409) {
|
|
126
|
+
throw console.error('Error 409 - The specified submission was found but it could not be committed in its current state, or the app uses a Partner Center feature that is currently not supported by the Microsoft Store submission API.');
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
throw console.error(response.statusMessage);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
throw console.error(err);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
CommitSubmission(appId, submissionId) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
try {
|
|
140
|
+
let auth = yield this.authorize();
|
|
141
|
+
// https://docs.microsoft.com/en-us/windows/uwp/monetize/commit-an-app-submission
|
|
142
|
+
const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}/submissions/${submissionId}/commit"`;
|
|
143
|
+
const response = yield got_1.default(requestUrl, {
|
|
144
|
+
method: 'post',
|
|
145
|
+
headers: {
|
|
146
|
+
Authorization: `"${auth.token_type} ${auth.access_token}"`
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
if (response.statusCode == 200) {
|
|
150
|
+
return converters_1.Convert.toCommitSubmissionResult(response.body);
|
|
151
|
+
}
|
|
152
|
+
else if (response.statusCode === 400) {
|
|
153
|
+
throw console.error('400 - The request parameters are invalid.');
|
|
154
|
+
}
|
|
155
|
+
else if (response.statusCode === 404) {
|
|
156
|
+
throw console.error('404 - The specified submission could not be found.');
|
|
157
|
+
}
|
|
158
|
+
else if (response.statusCode === 409) {
|
|
159
|
+
throw console.error('Error 409 - The specified submission was found but it could not be committed in its current state, or the app uses a Partner Center feature that is currently not supported by the Microsoft Store submission API.');
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
throw console.error(response.statusMessage);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
throw err;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
// https://docs.microsoft.com/en-us/windows/uwp/monetize/get-an-app-submission
|
|
171
|
+
GetSubmission(appId, submissionId) {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
try {
|
|
174
|
+
let auth = yield this.authorize();
|
|
175
|
+
const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}/submissions/${submissionId}"`;
|
|
176
|
+
const response = yield got_1.default(requestUrl, {
|
|
177
|
+
method: 'post',
|
|
178
|
+
headers: {
|
|
179
|
+
Authorization: `"${auth.token_type} ${auth.access_token}"`
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
if (response.statusCode == 200) {
|
|
183
|
+
return converters_1.Convert.toGetSubmissionResult(response.body);
|
|
184
|
+
}
|
|
185
|
+
else if (response.statusCode === 400) {
|
|
186
|
+
throw console.error('400 - The request parameters are invalid.');
|
|
187
|
+
}
|
|
188
|
+
else if (response.statusCode === 404) {
|
|
189
|
+
throw console.error('404 - The specified submission could not be found.');
|
|
190
|
+
}
|
|
191
|
+
else if (response.statusCode === 409) {
|
|
192
|
+
throw console.error('Error 409 - The specified submission was found but it could not be committed in its current state, or the app uses a Partner Center feature that is currently not supported by the Microsoft Store submission API.');
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
throw console.error(response.statusMessage);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
throw console.error(err);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
// https://docs.microsoft.com/en-us/windows/uwp/monetize/get-status-for-an-app-submission
|
|
204
|
+
GetSubmissionStatus(appId, submissionId) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
try {
|
|
207
|
+
let auth = yield this.authorize();
|
|
208
|
+
const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}/submissions/${submissionId}/status"`;
|
|
209
|
+
const response = yield got_1.default(requestUrl, {
|
|
210
|
+
method: 'get',
|
|
211
|
+
headers: {
|
|
212
|
+
Authorization: `"${auth.token_type} ${auth.access_token}"`
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
if (response.statusCode == 200) {
|
|
216
|
+
return converters_1.Convert.toSubmissionStatusResult(response.body);
|
|
217
|
+
}
|
|
218
|
+
else if (response.statusCode === 400) {
|
|
219
|
+
throw console.error('400 - The request parameters are invalid.');
|
|
220
|
+
}
|
|
221
|
+
else if (response.statusCode === 404) {
|
|
222
|
+
throw console.error('404 - The specified submission could not be found.');
|
|
223
|
+
}
|
|
224
|
+
else if (response.statusCode === 409) {
|
|
225
|
+
throw console.error('Error 409 - The specified submission was found but it could not be committed in its current state, or the app uses a Partner Center feature that is currently not supported by the Microsoft Store submission API.');
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
throw console.error(response.statusMessage);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
catch (err) {
|
|
232
|
+
throw console.error(err);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
// https://docs.microsoft.com/en-us/windows/uwp/monetize/delete-an-app-submission
|
|
237
|
+
DeleteSubmission(appId, submissionId) {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
try {
|
|
240
|
+
let auth = yield this.authorize();
|
|
241
|
+
const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}/submissions/${submissionId}"`;
|
|
242
|
+
const response = yield got_1.default(requestUrl, {
|
|
243
|
+
method: 'post',
|
|
244
|
+
headers: {
|
|
245
|
+
Authorization: `"${auth.token_type} ${auth.access_token}"`
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
if (response.statusCode == 200) {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
else if (response.statusCode === 400) {
|
|
252
|
+
throw console.error('400 - The request parameters are invalid.');
|
|
253
|
+
}
|
|
254
|
+
else if (response.statusCode === 404) {
|
|
255
|
+
throw console.error('404 - The specified submission could not be found.');
|
|
256
|
+
}
|
|
257
|
+
else if (response.statusCode === 409) {
|
|
258
|
+
throw console.error('Error 409 - The specified submission was found but it could not be committed in its current state, or the app uses a Partner Center feature that is currently not supported by the Microsoft Store submission API.');
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
catch (err) {
|
|
265
|
+
throw console.error(err);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
authorize() {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
try {
|
|
272
|
+
let needsNewToken = false;
|
|
273
|
+
if (this.authResult == undefined) {
|
|
274
|
+
// First time authentication.
|
|
275
|
+
needsNewToken = true;
|
|
276
|
+
}
|
|
277
|
+
else if (Number(this.authResult.expires_on) < new Date('1970-01-01T0:0:0Z').getSeconds()) {
|
|
278
|
+
// If the previous authentication has expired.
|
|
279
|
+
needsNewToken = true;
|
|
280
|
+
}
|
|
281
|
+
if (needsNewToken) {
|
|
282
|
+
this.authResult = yield this.signin();
|
|
283
|
+
}
|
|
284
|
+
if (this.authResult == null) {
|
|
285
|
+
throw new Error('You could not be authenticated, double check the TenantID, ClientID and ClientSecret. See readme for more info.');
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
return this.authResult;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
catch (ex) {
|
|
292
|
+
try {
|
|
293
|
+
if (ex.statusCode === 401) {
|
|
294
|
+
// If we got a 401 during a call, we need to get a new token anyways.
|
|
295
|
+
this.authResult = yield this.signin();
|
|
296
|
+
if (this.authResult == null) {
|
|
297
|
+
throw new Error('You could not be authenticated, double check the TenantID, ClientID and ClientSecret. See readme for more info.');
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
return this.authResult;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
else if (ex.statusCode === 400) {
|
|
304
|
+
throw console.error('400 - The request parameters are invalid.');
|
|
305
|
+
}
|
|
306
|
+
else if (ex.statusCode === 404) {
|
|
307
|
+
throw console.error('404 - The specified submission could not be found.');
|
|
308
|
+
}
|
|
309
|
+
else if (ex.statusCode === 409) {
|
|
310
|
+
throw console.error('Error 409 - The specified submission was found but it could not be committed in its current state, or the app uses a Partner Center feature that is currently not supported by the Microsoft Store submission API.');
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
throw console.error(ex.statusMessage);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
catch (ex) {
|
|
317
|
+
throw ex;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
// https://docs.microsoft.com/en-us/windows/uwp/monetize/create-and-manage-submissions-using-windows-store-services
|
|
323
|
+
signin() {
|
|
324
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
325
|
+
try {
|
|
326
|
+
const rootUrl = `"https://login.microsoftonline.com/${this.tenantId}/oauth2/token HTTP/1.1`;
|
|
327
|
+
let response = yield got_1.default(rootUrl, {
|
|
328
|
+
method: 'post',
|
|
329
|
+
headers: {
|
|
330
|
+
'content-type': 'application/x-www-form-urlencoded'
|
|
331
|
+
},
|
|
332
|
+
body: querystring_1.default.stringify({
|
|
333
|
+
grant_type: 'client_credentials',
|
|
334
|
+
resource: 'https://manage.devcenter.microsoft.com',
|
|
335
|
+
client_id: this.clientId,
|
|
336
|
+
client_secret: this.clientSecret
|
|
337
|
+
})
|
|
338
|
+
});
|
|
339
|
+
if (response.statusCode == 200) {
|
|
340
|
+
return converters_1.Convert.toServiceAuthenticationResult(response.body);
|
|
341
|
+
}
|
|
342
|
+
else if (response.statusCode === 400) {
|
|
343
|
+
throw console.error('400 - The request parameters are invalid.');
|
|
344
|
+
}
|
|
345
|
+
else if (response.statusCode === 404) {
|
|
346
|
+
throw console.error('404 - The specified submission could not be found.');
|
|
347
|
+
}
|
|
348
|
+
else if (response.statusCode === 409) {
|
|
349
|
+
throw console.error('Error 409 - The specified submission was found but it could not be committed in its current state, or the app uses a Partner Center feature that is currently not supported by the Microsoft Store submission API.');
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
throw console.error(response.statusMessage);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
catch (err) {
|
|
356
|
+
throw console.error(err);
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
module.exports = DevCenter;
|