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/lib/helpers.js ADDED
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Helpers = void 0;
4
+ class Helpers {
5
+ static CloneLastSubmissionData(original) {
6
+ const subData = {
7
+ applicationCategory: original.applicationCategory,
8
+ pricing: original.pricing,
9
+ visibility: original.visibility,
10
+ targetPublishMode: original.targetPublishMode,
11
+ targetPublishDate: original.targetPublishDate,
12
+ listings: original.listings,
13
+ hardwarePreferences: original.hardwarePreferences,
14
+ automaticBackupEnabled: original.automaticBackupEnabled,
15
+ canInstallOnRemovableMedia: original.canInstallOnRemovableMedia,
16
+ isGameDvrEnabled: original.isGameDvrEnabled,
17
+ gamingOptions: original.gamingOptions,
18
+ hasExternalInAppProducts: original.hasExternalInAppProducts,
19
+ meetAccessibilityGuidelines: original.meetAccessibilityGuidelines,
20
+ notesForCertification: original.notesForCertification,
21
+ applicationPackages: original.applicationPackages,
22
+ packageDeliveryOptions: original.packageDeliveryOptions,
23
+ enterpriseLicensing: original.enterpriseLicensing,
24
+ allowMicrosoftDecideAppAvailabilityToFutureDeviceFamilies: original.allowMicrosoftDecideAppAvailabilityToFutureDeviceFamilies,
25
+ allowTargetFutureDeviceFamilies: original.allowTargetFutureDeviceFamilies,
26
+ trailers: original.trailers
27
+ };
28
+ return subData;
29
+ }
30
+ static GenerateSampleSubmission() {
31
+ const ovrde = {
32
+ description: ''
33
+ };
34
+ const pltOverrides = {
35
+ Windows81: ovrde
36
+ };
37
+ const imgs = [
38
+ {
39
+ fileName: '',
40
+ fileStatus: '',
41
+ id: '',
42
+ imageType: ''
43
+ },
44
+ {
45
+ fileName: '',
46
+ fileStatus: '',
47
+ id: '',
48
+ imageType: ''
49
+ }
50
+ ];
51
+ const bsListing = {
52
+ copyrightAndTrademarkInfo: '',
53
+ keywords: ['', ''],
54
+ licenseTerms: '',
55
+ privacyPolicy: '',
56
+ supportContact: '',
57
+ websiteUrl: '',
58
+ description: '',
59
+ features: ['', ''],
60
+ releaseNotes: '',
61
+ images: imgs,
62
+ recommendedHardware: [],
63
+ title: ''
64
+ };
65
+ const enusListing = {
66
+ baseListing: bsListing,
67
+ platformOverrides: pltOverrides
68
+ };
69
+ const listings = {
70
+ 'en-us': enusListing
71
+ };
72
+ const dvFams = {
73
+ Desktop: true,
74
+ Mobile: true,
75
+ Holographic: true,
76
+ Xbox: true,
77
+ Team: true
78
+ };
79
+ const rllout = {
80
+ isPackageRollout: true,
81
+ packageRolloutPercentage: 100,
82
+ packageRolloutStatus: '',
83
+ fallbackSubmissionId: ''
84
+ };
85
+ const delivOptns = {
86
+ packageRollout: rllout,
87
+ isMandatoryUpdate: true,
88
+ mandatoryUpdateEffectiveDate: new Date(Date.now())
89
+ };
90
+ const pckgs = [
91
+ {
92
+ fileName: '',
93
+ fileStatus: '',
94
+ id: '',
95
+ version: '',
96
+ architecture: '',
97
+ languages: ['', ''],
98
+ capabilities: ['', ''],
99
+ minimumDirectXVersion: '',
100
+ minimumSystemRam: '',
101
+ targetDeviceFamilies: ['', '']
102
+ },
103
+ {
104
+ fileName: '',
105
+ fileStatus: '',
106
+ id: '',
107
+ version: '',
108
+ architecture: '',
109
+ languages: ['', ''],
110
+ capabilities: ['', ''],
111
+ minimumDirectXVersion: '',
112
+ minimumSystemRam: '',
113
+ targetDeviceFamilies: ['', '']
114
+ }
115
+ ];
116
+ const msPcing = {};
117
+ const pcing = {
118
+ trialPeriod: '',
119
+ marketSpecificPricings: msPcing,
120
+ sales: [],
121
+ priceId: '',
122
+ isAdvancedPricingModel: false
123
+ };
124
+ const subData = {
125
+ applicationCategory: '',
126
+ pricing: pcing,
127
+ visibility: '',
128
+ targetPublishMode: '',
129
+ targetPublishDate: new Date(Date.now()),
130
+ listings: listings,
131
+ hardwarePreferences: ['', ''],
132
+ automaticBackupEnabled: true,
133
+ canInstallOnRemovableMedia: true,
134
+ isGameDvrEnabled: true,
135
+ gamingOptions: [],
136
+ hasExternalInAppProducts: false,
137
+ meetAccessibilityGuidelines: true,
138
+ notesForCertification: '',
139
+ applicationPackages: pckgs,
140
+ packageDeliveryOptions: delivOptns,
141
+ enterpriseLicensing: '',
142
+ allowMicrosoftDecideAppAvailabilityToFutureDeviceFamilies: true,
143
+ allowTargetFutureDeviceFamilies: dvFams,
144
+ trailers: []
145
+ };
146
+ return subData;
147
+ }
148
+ }
149
+ exports.Helpers = Helpers;
package/lib/index.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { GetSubmissionResult, SubmissionStatusResult, ServiceAuthenticationResult, CommitSubmissionResult, CreateAppSubmissionResult, AppResourceResult, UpdateSubmissionResult, SubmissionData, ApplicationSubmission, AllowTargetFutureDeviceFamilies, ApplicationPackage, Listings, PackageDeliveryOptions, Pricing, StatusDetails, EnUs, BaseListing, Image, PlatformOverrides, Windows81, PackageRollout, MarketSpecificPricings } from './interfaces';
2
+ /**
3
+ * @namespace DevCenter
4
+ */
5
+ declare namespace DevCenter {
6
+ export type { ServiceAuthenticationResult, CommitSubmissionResult, CreateAppSubmissionResult, AppResourceResult, GetSubmissionResult, SubmissionStatusResult, UpdateSubmissionResult, SubmissionData, ApplicationSubmission, AllowTargetFutureDeviceFamilies, ApplicationPackage, Listings, PackageDeliveryOptions, Pricing, StatusDetails, EnUs, BaseListing, Image, PlatformOverrides, Windows81, PackageRollout, MarketSpecificPricings };
7
+ }
8
+ declare class DevCenter {
9
+ tenantId: string;
10
+ clientId: string;
11
+ clientSecret: string;
12
+ authResult: ServiceAuthenticationResult | undefined;
13
+ constructor(_tenantId: string, _clientId: string, _clientSecret: string);
14
+ GetAppInfo(appId: string): Promise<AppResourceResult>;
15
+ CreateAppSubmission(appId: string): Promise<CreateAppSubmissionResult>;
16
+ UpdateSubmission(appId: string, submissionId: string, data: SubmissionData): Promise<UpdateSubmissionResult>;
17
+ CommitSubmission(appId: string, submissionId: string): Promise<CommitSubmissionResult>;
18
+ GetSubmission(appId: string, submissionId: string): Promise<GetSubmissionResult>;
19
+ GetSubmissionStatus(appId: string, submissionId: string): Promise<SubmissionStatusResult>;
20
+ DeleteSubmission(appId: string, submissionId: string): Promise<boolean>;
21
+ authorize(): Promise<ServiceAuthenticationResult>;
22
+ private signin;
23
+ }
24
+ export = DevCenter;
package/lib/index.js ADDED
@@ -0,0 +1,335 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const got_1 = __importDefault(require("got"));
6
+ const querystring_1 = __importDefault(require("querystring"));
7
+ const converters_1 = require("./converters");
8
+ // Partner Center API https://docs.microsoft.com/en-us/windows/uwp/monetize/create-and-manage-submissions-using-windows-store-services
9
+ // API endpoints https://docs.microsoft.com/en-us/windows/uwp/monetize/manage-app-submissions
10
+ class DevCenter {
11
+ constructor(_tenantId, _clientId, _clientSecret) {
12
+ if (typeof _tenantId != 'undefined' && !_tenantId) {
13
+ throw new Error('You must pass a valid Tenant ID. See the documentation for examples and guidance https://lancemccarthy.github.io/PartnerCenterBroker/.');
14
+ }
15
+ if (typeof _clientId != 'undefined' && !_clientId) {
16
+ throw new Error('You must pass a valid Client ID. See the documentation for examples and guidance https://lancemccarthy.github.io/PartnerCenterBroker/.');
17
+ }
18
+ if (typeof _clientSecret != 'undefined' && !_clientSecret) {
19
+ throw new Error('You must pass a valid Client Secret. See the documentation for examples and guidance https://lancemccarthy.github.io/PartnerCenterBroker/.');
20
+ }
21
+ this.tenantId = _tenantId;
22
+ this.clientId = _clientId;
23
+ this.clientSecret = _clientSecret;
24
+ }
25
+ async GetAppInfo(appId) {
26
+ try {
27
+ let auth = await this.authorize();
28
+ // https://docs.microsoft.com/en-us/windows/uwp/monetize/get-app-data
29
+ const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}"`;
30
+ const response = await (0, got_1.default)(requestUrl, {
31
+ method: 'get',
32
+ headers: {
33
+ Authorization: `"${auth.token_type} ${auth.access_token}"`
34
+ }
35
+ });
36
+ if (response.statusCode == 200) {
37
+ return converters_1.Convert.toAppInfoResult(response.body);
38
+ }
39
+ else if (response.statusCode === 400) {
40
+ throw console.error('400 - The request parameters are invalid.');
41
+ }
42
+ else if (response.statusCode === 404) {
43
+ throw console.error('404 - The specified submission could not be found.');
44
+ }
45
+ else if (response.statusCode === 409) {
46
+ 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.');
47
+ }
48
+ else {
49
+ throw console.error(response.statusMessage);
50
+ }
51
+ }
52
+ catch (err) {
53
+ throw err;
54
+ }
55
+ }
56
+ async CreateAppSubmission(appId) {
57
+ try {
58
+ let auth = await this.authorize();
59
+ // https://docs.microsoft.com/en-us/windows/uwp/monetize/create-an-app-submission
60
+ const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}/submissions"`;
61
+ const response = await (0, got_1.default)(requestUrl, {
62
+ method: 'post',
63
+ headers: {
64
+ Authorization: `"${auth.token_type} ${auth.access_token}"`,
65
+ ContentType: 'application/json'
66
+ }
67
+ });
68
+ if (response.statusCode == 200) {
69
+ return converters_1.Convert.toCreateAppSubmissionResult(response.body);
70
+ }
71
+ else if (response.statusCode === 400) {
72
+ throw console.error('400 - The request parameters are invalid.');
73
+ }
74
+ else if (response.statusCode === 404) {
75
+ throw console.error('404 - The specified submission could not be found.');
76
+ }
77
+ else if (response.statusCode === 409) {
78
+ 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.');
79
+ }
80
+ else {
81
+ throw console.error(response.statusMessage);
82
+ }
83
+ }
84
+ catch (err) {
85
+ throw console.error(err);
86
+ }
87
+ }
88
+ async UpdateSubmission(appId, submissionId, data) {
89
+ try {
90
+ let auth = await this.authorize();
91
+ // Special Note: carefully read Request Body section in the documentation
92
+ // https://docs.microsoft.com/en-us/windows/uwp/monetize/update-an-app-submission
93
+ const requestUrl = 'https://manage.devcenter.microsoft.com/v1.0/my/applications/{applicationId}/submissions/{submissionId}';
94
+ const response = await (0, got_1.default)(requestUrl, {
95
+ method: 'post',
96
+ headers: {
97
+ Authorization: `"${auth.token_type} ${auth.access_token}"`,
98
+ ContentType: 'application/json'
99
+ },
100
+ body: converters_1.Convert.submissionDataToJson(data)
101
+ });
102
+ if (response.statusCode == 200) {
103
+ return converters_1.Convert.toUpdateSubmissionResult(response.body);
104
+ }
105
+ else if (response.statusCode === 400) {
106
+ throw console.error('400 - The request parameters are invalid.');
107
+ }
108
+ else if (response.statusCode === 404) {
109
+ throw console.error('404 - The specified submission could not be found.');
110
+ }
111
+ else if (response.statusCode === 409) {
112
+ 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.');
113
+ }
114
+ else {
115
+ throw console.error(response.statusMessage);
116
+ }
117
+ }
118
+ catch (err) {
119
+ throw console.error(err);
120
+ }
121
+ }
122
+ async CommitSubmission(appId, submissionId) {
123
+ try {
124
+ let auth = await this.authorize();
125
+ // https://docs.microsoft.com/en-us/windows/uwp/monetize/commit-an-app-submission
126
+ const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}/submissions/${submissionId}/commit"`;
127
+ const response = await (0, got_1.default)(requestUrl, {
128
+ method: 'post',
129
+ headers: {
130
+ Authorization: `"${auth.token_type} ${auth.access_token}"`
131
+ }
132
+ });
133
+ if (response.statusCode == 200) {
134
+ return converters_1.Convert.toCommitSubmissionResult(response.body);
135
+ }
136
+ else if (response.statusCode === 400) {
137
+ throw console.error('400 - The request parameters are invalid.');
138
+ }
139
+ else if (response.statusCode === 404) {
140
+ throw console.error('404 - The specified submission could not be found.');
141
+ }
142
+ else if (response.statusCode === 409) {
143
+ 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.');
144
+ }
145
+ else {
146
+ throw console.error(response.statusMessage);
147
+ }
148
+ }
149
+ catch (err) {
150
+ throw err;
151
+ }
152
+ }
153
+ // https://docs.microsoft.com/en-us/windows/uwp/monetize/get-an-app-submission
154
+ async GetSubmission(appId, submissionId) {
155
+ try {
156
+ let auth = await this.authorize();
157
+ const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}/submissions/${submissionId}"`;
158
+ const response = await (0, got_1.default)(requestUrl, {
159
+ method: 'post',
160
+ headers: {
161
+ Authorization: `"${auth.token_type} ${auth.access_token}"`
162
+ }
163
+ });
164
+ if (response.statusCode == 200) {
165
+ return converters_1.Convert.toGetSubmissionResult(response.body);
166
+ }
167
+ else if (response.statusCode === 400) {
168
+ throw console.error('400 - The request parameters are invalid.');
169
+ }
170
+ else if (response.statusCode === 404) {
171
+ throw console.error('404 - The specified submission could not be found.');
172
+ }
173
+ else if (response.statusCode === 409) {
174
+ 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.');
175
+ }
176
+ else {
177
+ throw console.error(response.statusMessage);
178
+ }
179
+ }
180
+ catch (err) {
181
+ throw console.error(err);
182
+ }
183
+ }
184
+ // https://docs.microsoft.com/en-us/windows/uwp/monetize/get-status-for-an-app-submission
185
+ async GetSubmissionStatus(appId, submissionId) {
186
+ try {
187
+ let auth = await this.authorize();
188
+ const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}/submissions/${submissionId}/status"`;
189
+ const response = await (0, got_1.default)(requestUrl, {
190
+ method: 'get',
191
+ headers: {
192
+ Authorization: `"${auth.token_type} ${auth.access_token}"`
193
+ }
194
+ });
195
+ if (response.statusCode == 200) {
196
+ return converters_1.Convert.toSubmissionStatusResult(response.body);
197
+ }
198
+ else if (response.statusCode === 400) {
199
+ throw console.error('400 - The request parameters are invalid.');
200
+ }
201
+ else if (response.statusCode === 404) {
202
+ throw console.error('404 - The specified submission could not be found.');
203
+ }
204
+ else if (response.statusCode === 409) {
205
+ 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.');
206
+ }
207
+ else {
208
+ throw console.error(response.statusMessage);
209
+ }
210
+ }
211
+ catch (err) {
212
+ throw console.error(err);
213
+ }
214
+ }
215
+ // https://docs.microsoft.com/en-us/windows/uwp/monetize/delete-an-app-submission
216
+ async DeleteSubmission(appId, submissionId) {
217
+ try {
218
+ let auth = await this.authorize();
219
+ const requestUrl = `"https://manage.devcenter.microsoft.com/v1.0/my/applications/${appId}/submissions/${submissionId}"`;
220
+ const response = await (0, got_1.default)(requestUrl, {
221
+ method: 'post',
222
+ headers: {
223
+ Authorization: `"${auth.token_type} ${auth.access_token}"`
224
+ }
225
+ });
226
+ if (response.statusCode == 200) {
227
+ return true;
228
+ }
229
+ else if (response.statusCode === 400) {
230
+ throw console.error('400 - The request parameters are invalid.');
231
+ }
232
+ else if (response.statusCode === 404) {
233
+ throw console.error('404 - The specified submission could not be found.');
234
+ }
235
+ else if (response.statusCode === 409) {
236
+ 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.');
237
+ }
238
+ else {
239
+ return false;
240
+ }
241
+ }
242
+ catch (err) {
243
+ throw console.error(err);
244
+ }
245
+ }
246
+ async authorize() {
247
+ try {
248
+ let needsNewToken = false;
249
+ if (this.authResult == undefined) {
250
+ // First time authentication.
251
+ needsNewToken = true;
252
+ }
253
+ else if (Number(this.authResult.expires_on) < new Date('1970-01-01T0:0:0Z').getSeconds()) {
254
+ // If the previous authentication has expired.
255
+ needsNewToken = true;
256
+ }
257
+ if (needsNewToken) {
258
+ this.authResult = await this.signin();
259
+ }
260
+ if (this.authResult == null) {
261
+ throw new Error('You could not be authenticated, double check the TenantID, ClientID and ClientSecret. See readme for more info.');
262
+ }
263
+ else {
264
+ return this.authResult;
265
+ }
266
+ }
267
+ catch (ex1) {
268
+ try {
269
+ const error = ex1;
270
+ if (error.statusCode === 401) {
271
+ // If we got a 401 during a call, we need to get a new token anyways.
272
+ this.authResult = await this.signin();
273
+ if (this.authResult == null) {
274
+ throw new Error('You could not be authenticated, double check the TenantID, ClientID and ClientSecret. See readme for more info.');
275
+ }
276
+ else {
277
+ return this.authResult;
278
+ }
279
+ }
280
+ else if (error.statusCode === 400) {
281
+ throw console.error('400 - The request parameters are invalid.');
282
+ }
283
+ else if (error.statusCode === 404) {
284
+ throw console.error('404 - The specified submission could not be found.');
285
+ }
286
+ else if (error.statusCode === 409) {
287
+ 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.');
288
+ }
289
+ else {
290
+ throw console.error(error.statusMessage);
291
+ }
292
+ }
293
+ catch (ex2) {
294
+ throw ex2;
295
+ }
296
+ }
297
+ }
298
+ // https://docs.microsoft.com/en-us/windows/uwp/monetize/create-and-manage-submissions-using-windows-store-services
299
+ async signin() {
300
+ try {
301
+ const rootUrl = `"https://login.microsoftonline.com/${this.tenantId}/oauth2/token HTTP/1.1`;
302
+ let response = await (0, got_1.default)(rootUrl, {
303
+ method: 'post',
304
+ headers: {
305
+ 'content-type': 'application/x-www-form-urlencoded'
306
+ },
307
+ body: querystring_1.default.stringify({
308
+ grant_type: 'client_credentials',
309
+ resource: 'https://manage.devcenter.microsoft.com',
310
+ client_id: this.clientId,
311
+ client_secret: this.clientSecret
312
+ })
313
+ });
314
+ if (response.statusCode == 200) {
315
+ return converters_1.Convert.toServiceAuthenticationResult(response.body);
316
+ }
317
+ else if (response.statusCode === 400) {
318
+ throw console.error('400 - The request parameters are invalid.');
319
+ }
320
+ else if (response.statusCode === 404) {
321
+ throw console.error('404 - The specified submission could not be found.');
322
+ }
323
+ else if (response.statusCode === 409) {
324
+ 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.');
325
+ }
326
+ else {
327
+ throw console.error(response.statusMessage);
328
+ }
329
+ }
330
+ catch (err) {
331
+ throw console.error(err);
332
+ }
333
+ }
334
+ }
335
+ module.exports = DevCenter;