partner-center-broker 1.0.1 → 1.2.1
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 +29 -0
- package/.github/workflows/npm-publish.yml +78 -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/lib/index.d.ts +24 -0
- package/lib/index.js +335 -0
- package/{dist → lib}/interfaces.d.ts +221 -172
- package/{dist → lib}/interfaces.js +2 -2
- package/package.json +64 -57
- package/dist/index.d.ts +0 -17
- package/dist/index.js +0 -290
package/dist/index.js
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
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 == null || _clientId == null || _clientSecret) {
|
|
22
|
-
throw new Error("you must pass a valid Tenent ID, Client ID and Client Secret. See the documentation for more information.");
|
|
23
|
-
}
|
|
24
|
-
this.tenantId = _tenantId;
|
|
25
|
-
this.clientId = _clientId;
|
|
26
|
-
this.clientSecret = _clientSecret;
|
|
27
|
-
}
|
|
28
|
-
// https://docs.microsoft.com/en-us/windows/uwp/monetize/get-app-data
|
|
29
|
-
GetAppInfo(appId) {
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
try {
|
|
32
|
-
const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}"`;
|
|
33
|
-
const response = yield this.apiRequest(requestUrl, 'get');
|
|
34
|
-
if (response.statusCode == 200) {
|
|
35
|
-
return converters_1.Convert.toAppInfoResult(response.body);
|
|
36
|
-
}
|
|
37
|
-
else if (response.statusCode === 400) {
|
|
38
|
-
throw console.error('400 - The request parameters are invalid.');
|
|
39
|
-
}
|
|
40
|
-
else if (response.statusCode === 404) {
|
|
41
|
-
throw console.error('404 - The specified submission could not be found.');
|
|
42
|
-
}
|
|
43
|
-
else if (response.statusCode === 409) {
|
|
44
|
-
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.');
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
throw console.error(response.statusMessage);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
catch (err) {
|
|
51
|
-
throw err;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
// https://docs.microsoft.com/en-us/windows/uwp/monetize/create-an-app-submission
|
|
56
|
-
CreateAppSubmission(appId) {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
try {
|
|
59
|
-
const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}/submissions"`;
|
|
60
|
-
const response = yield this.apiRequest(requestUrl, 'post');
|
|
61
|
-
if (response.statusCode == 200) {
|
|
62
|
-
return converters_1.Convert.toCreateAppSubmissionResult(response.body);
|
|
63
|
-
}
|
|
64
|
-
else if (response.statusCode === 400) {
|
|
65
|
-
throw console.error('400 - The request parameters are invalid.');
|
|
66
|
-
}
|
|
67
|
-
else if (response.statusCode === 404) {
|
|
68
|
-
throw console.error('404 - The specified submission could not be found.');
|
|
69
|
-
}
|
|
70
|
-
else if (response.statusCode === 409) {
|
|
71
|
-
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.');
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
throw console.error(response.statusMessage);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
throw console.error(err);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
// https://docs.microsoft.com/en-us/windows/uwp/monetize/commit-an-app-submission
|
|
83
|
-
CommitSubmission(appId, submissionId) {
|
|
84
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
try {
|
|
86
|
-
const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}/submissions/${submissionId}/commit"`;
|
|
87
|
-
const response = yield this.apiRequest(requestUrl, 'post');
|
|
88
|
-
if (response.statusCode == 200) {
|
|
89
|
-
return converters_1.Convert.toCommitSubmissionResult(response.body);
|
|
90
|
-
}
|
|
91
|
-
else if (response.statusCode === 400) {
|
|
92
|
-
throw console.error('400 - The request parameters are invalid.');
|
|
93
|
-
}
|
|
94
|
-
else if (response.statusCode === 404) {
|
|
95
|
-
throw console.error('404 - The specified submission could not be found.');
|
|
96
|
-
}
|
|
97
|
-
else if (response.statusCode === 409) {
|
|
98
|
-
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.');
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
throw console.error(response.statusMessage);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
catch (err) {
|
|
105
|
-
throw err;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
// https://docs.microsoft.com/en-us/windows/uwp/monetize/get-an-app-submission
|
|
110
|
-
GetSubmission(appId, submissionId) {
|
|
111
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
try {
|
|
113
|
-
const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}/submissions/${submissionId}"`;
|
|
114
|
-
const response = yield this.apiRequest(requestUrl, 'post');
|
|
115
|
-
if (response.statusCode == 200) {
|
|
116
|
-
return converters_1.Convert.toGetSubmissionResult(response.body);
|
|
117
|
-
}
|
|
118
|
-
else if (response.statusCode === 400) {
|
|
119
|
-
throw console.error('400 - The request parameters are invalid.');
|
|
120
|
-
}
|
|
121
|
-
else if (response.statusCode === 404) {
|
|
122
|
-
throw console.error('404 - The specified submission could not be found.');
|
|
123
|
-
}
|
|
124
|
-
else if (response.statusCode === 409) {
|
|
125
|
-
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.');
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
throw console.error(response.statusMessage);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
catch (err) {
|
|
132
|
-
throw console.error(err);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
// https://docs.microsoft.com/en-us/windows/uwp/monetize/get-status-for-an-app-submission
|
|
137
|
-
GetSubmissionStatus(appId, submissionId) {
|
|
138
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
try {
|
|
140
|
-
const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}/submissions/${submissionId}/status"`;
|
|
141
|
-
const response = yield this.apiRequest(requestUrl, 'get');
|
|
142
|
-
if (response.statusCode == 200) {
|
|
143
|
-
return converters_1.Convert.toSubmissionStatusResult(response.body);
|
|
144
|
-
}
|
|
145
|
-
else if (response.statusCode === 400) {
|
|
146
|
-
throw console.error('400 - The request parameters are invalid.');
|
|
147
|
-
}
|
|
148
|
-
else if (response.statusCode === 404) {
|
|
149
|
-
throw console.error('404 - The specified submission could not be found.');
|
|
150
|
-
}
|
|
151
|
-
else if (response.statusCode === 409) {
|
|
152
|
-
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.');
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
throw console.error(response.statusMessage);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
catch (err) {
|
|
159
|
-
throw console.error(err);
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
DeleteSubmission(appId, submissionId) {
|
|
164
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
-
try {
|
|
166
|
-
const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}/submissions/${submissionId}"`;
|
|
167
|
-
const response = yield this.apiRequest(requestUrl, 'post');
|
|
168
|
-
if (response.statusCode == 200) {
|
|
169
|
-
return true;
|
|
170
|
-
}
|
|
171
|
-
else if (response.statusCode === 400) {
|
|
172
|
-
throw console.error('400 - The request parameters are invalid.');
|
|
173
|
-
}
|
|
174
|
-
else if (response.statusCode === 404) {
|
|
175
|
-
throw console.error('404 - The specified submission could not be found.');
|
|
176
|
-
}
|
|
177
|
-
else if (response.statusCode === 409) {
|
|
178
|
-
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.');
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
catch (err) {
|
|
185
|
-
throw console.error(err);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
apiRequest(url, httpRequestMethod) {
|
|
190
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
try {
|
|
192
|
-
let needsNewToken = false;
|
|
193
|
-
if (this.authResult == undefined) {
|
|
194
|
-
// First time authentication.
|
|
195
|
-
needsNewToken = true;
|
|
196
|
-
}
|
|
197
|
-
else if (Number(this.authResult.expires_on) < new Date('1970-01-01T0:0:0Z').getSeconds()) {
|
|
198
|
-
// If the previous authentication has expired.
|
|
199
|
-
needsNewToken = true;
|
|
200
|
-
}
|
|
201
|
-
if (needsNewToken) {
|
|
202
|
-
this.authResult = yield this.signin();
|
|
203
|
-
// To future-proof this, instead of hard coding the token type to "Bearer", I am appending the expected type
|
|
204
|
-
//const authHeader = `"${authResult.token_type} ${authResult.access_token}"`;
|
|
205
|
-
//options.headers.authorization = authHeader;
|
|
206
|
-
}
|
|
207
|
-
if (this.authResult == null) {
|
|
208
|
-
throw new Error("You could not be authenticated, double check the TenantID, ClientID and ClientSecret. See readme for more info.");
|
|
209
|
-
}
|
|
210
|
-
return yield got_1.default(url, {
|
|
211
|
-
method: httpRequestMethod,
|
|
212
|
-
headers: {
|
|
213
|
-
'Authorization': `"${this.authResult.token_type} ${this.authResult.access_token}"`
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
catch (ex) {
|
|
218
|
-
try {
|
|
219
|
-
if (ex.statusCode === 401) {
|
|
220
|
-
// If we got a 401 during a call, we need to get a new token anyways.
|
|
221
|
-
this.authResult = yield this.signin();
|
|
222
|
-
if (this.authResult == null) {
|
|
223
|
-
throw new Error("You could not be authenticated, double check the TenantID, ClientID and ClientSecret. See readme for more info.");
|
|
224
|
-
}
|
|
225
|
-
return yield got_1.default(url, {
|
|
226
|
-
method: httpRequestMethod,
|
|
227
|
-
headers: {
|
|
228
|
-
'Authorization': `"${this.authResult.token_type} ${this.authResult.access_token}"`
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
else if (ex.statusCode === 400) {
|
|
233
|
-
throw console.error('400 - The request parameters are invalid.');
|
|
234
|
-
}
|
|
235
|
-
else if (ex.statusCode === 404) {
|
|
236
|
-
throw console.error('404 - The specified submission could not be found.');
|
|
237
|
-
}
|
|
238
|
-
else if (ex.statusCode === 409) {
|
|
239
|
-
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.');
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
throw console.error(ex.statusMessage);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
catch (ex) {
|
|
246
|
-
throw ex;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
// https://docs.microsoft.com/en-us/windows/uwp/monetize/create-and-manage-submissions-using-windows-store-services
|
|
252
|
-
signin() {
|
|
253
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
-
try {
|
|
255
|
-
const rootUrl = `"https://login.microsoftonline.com/${this.tenantId}/oauth2/token HTTP/1.1`;
|
|
256
|
-
let response = yield got_1.default(rootUrl, {
|
|
257
|
-
method: 'post',
|
|
258
|
-
headers: {
|
|
259
|
-
'content-type': 'application/x-www-form-urlencoded'
|
|
260
|
-
},
|
|
261
|
-
body: querystring_1.default.stringify({
|
|
262
|
-
grant_type: 'client_credentials',
|
|
263
|
-
resource: 'https://manage.devcenter.microsoft.com',
|
|
264
|
-
client_id: this.clientId,
|
|
265
|
-
client_secret: this.clientSecret
|
|
266
|
-
})
|
|
267
|
-
});
|
|
268
|
-
if (response.statusCode == 200) {
|
|
269
|
-
return converters_1.Convert.toServiceAuthenticationResult(response.body);
|
|
270
|
-
}
|
|
271
|
-
else if (response.statusCode === 400) {
|
|
272
|
-
throw console.error('400 - The request parameters are invalid.');
|
|
273
|
-
}
|
|
274
|
-
else if (response.statusCode === 404) {
|
|
275
|
-
throw console.error('404 - The specified submission could not be found.');
|
|
276
|
-
}
|
|
277
|
-
else if (response.statusCode === 409) {
|
|
278
|
-
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.');
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
throw console.error(response.statusMessage);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
catch (err) {
|
|
285
|
-
throw console.error(err);
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
module.exports = DevCenter;
|