-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathappStoreApi.ts
More file actions
392 lines (351 loc) · 19.8 KB
/
appStoreApi.ts
File metadata and controls
392 lines (351 loc) · 19.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
139
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
/**
* Xero AppStore API
* These endpoints are for Xero Partners to interact with the App Store Billing platform
*
* The version of the OpenAPI document: 12.0.1
* Contact: api@xero.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import http = require('http');
import fs = require('fs');
/* tslint:disable:no-unused-locals */
import { CreateUsageRecord } from '../model/appstore/createUsageRecord';
import { ProblemDetails } from '../model/appstore/problemDetails';
import { Subscription } from '../model/appstore/subscription';
import { UpdateUsageRecord } from '../model/appstore/updateUsageRecord';
import { UsageRecord } from '../model/appstore/usageRecord';
import { UsageRecordsList } from '../model/appstore/usageRecordsList';
import { ObjectSerializer, Authentication, VoidAuth } from '../model/appstore/models';
import { ApiError } from '../../model/ApiError';
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import { Readable } from "stream";
import { OAuth } from '../model/appstore/models';
let defaultBasePath = 'https://api.xero.com/appstore/2.0';
// ===============================================
// This file is autogenerated - Please do not edit
// ===============================================
export enum AppStoreApiApiKeys {
}
export class AppStoreApi {
protected _basePath = defaultBasePath;
protected defaultHeaders : any = {'user-agent': 'xero-node-15.0.1'};
protected _useQuerystring : boolean = false;
protected binaryHeaders : any = {};
protected authentications = {
'default': <Authentication>new VoidAuth(),
'OAuth2': new OAuth(),
}
constructor(basePath?: string);
constructor(basePathOrUsername: string, password?: string, basePath?: string) {
if (password) {
if (basePath) {
this.basePath = basePath;
}
} else {
if (basePathOrUsername) {
this.basePath = basePathOrUsername
}
}
}
set useQuerystring(value: boolean) {
this._useQuerystring = value;
}
set basePath(basePath: string) {
this._basePath = basePath;
}
get basePath() {
return this._basePath;
}
public setDefaultAuthentication(auth: Authentication) {
this.authentications.default = auth;
}
public setApiKey(key: AppStoreApiApiKeys, value: string) {
(this.authentications as any)[AppStoreApiApiKeys[key]].apiKey = value;
}
set accessToken(token: string) {
this.authentications.OAuth2.accessToken = token;
}
/**
*
* @summary Retrieves a subscription for a given subscriptionId
* @param subscriptionId Unique identifier for Subscription object
*/
public async getSubscription (subscriptionId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: AxiosResponse; body: Subscription; }> {
const localVarPath = this.basePath + '/subscriptions/{subscriptionId}'
.replace('{' + 'subscriptionId' + '}', encodeURIComponent(String(subscriptionId)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this.defaultHeaders);
let localVarFormParams: any = {};
let acceptHeadersFromSpec = [
"application/json"
];
const isBufferType = acceptHeadersFromSpec.includes("application/pdf")|| acceptHeadersFromSpec.includes("application/octet-stream") || acceptHeadersFromSpec.includes("application/jpg");
const responseTypeOption = isBufferType ? "arraybuffer" : "json";
// verify required parameter 'subscriptionId' is not null or undefined
if (subscriptionId === null || subscriptionId === undefined) {
throw new Error('Required parameter subscriptionId was null or undefined when calling getSubscription.');
}
localVarHeaderParams['Accept'] = acceptHeadersFromSpec.join();
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let localVarRequestOptions: AxiosRequestConfig = {
method: 'GET',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
responseType: responseTypeOption,
data: {},
};
let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.OAuth2.applyToRequest(localVarRequestOptions));
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
return authenticationPromise.then(() => {
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
(<any>localVarRequestOptions).data = localVarFormParams;
localVarRequestOptions.headers = { ...localVarRequestOptions.headers, 'Content-Type': 'multipart/form-data' };
} else {
localVarRequestOptions.data = localVarFormParams;
localVarRequestOptions.headers = { ...localVarRequestOptions.headers, 'content-type': 'application/x-www-form-urlencoded' };
}
}
return new Promise<{ response: AxiosResponse; body: Subscription; }>(async (resolve, reject) => {
let body = null
try {
const response = await axios(localVarRequestOptions)
body = ObjectSerializer.deserialize(response.data, "Subscription");
if (response.status && response.status >= 200 && response.status <= 299) {
resolve({ response: response, body: body });
} else {
reject({ response: response, body: body });
}
}
catch(error) {
const errorResponse = new ApiError(error)
reject(JSON.stringify(errorResponse.generateError()))
}
});
});
}
/**
*
* @summary Gets all usage records related to the subscription
* @param subscriptionId Unique identifier for Subscription object
*/
public async getUsageRecords (subscriptionId: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: AxiosResponse; body: UsageRecordsList; }> {
const localVarPath = this.basePath + '/subscriptions/{subscriptionId}/usage-records'
.replace('{' + 'subscriptionId' + '}', encodeURIComponent(String(subscriptionId)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this.defaultHeaders);
let localVarFormParams: any = {};
let acceptHeadersFromSpec = [
"application/json"
];
const isBufferType = acceptHeadersFromSpec.includes("application/pdf")|| acceptHeadersFromSpec.includes("application/octet-stream") || acceptHeadersFromSpec.includes("application/jpg");
const responseTypeOption = isBufferType ? "arraybuffer" : "json";
// verify required parameter 'subscriptionId' is not null or undefined
if (subscriptionId === null || subscriptionId === undefined) {
throw new Error('Required parameter subscriptionId was null or undefined when calling getUsageRecords.');
}
localVarHeaderParams['Accept'] = acceptHeadersFromSpec.join();
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let localVarRequestOptions: AxiosRequestConfig = {
method: 'GET',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
responseType: responseTypeOption,
data: {},
};
let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.OAuth2.applyToRequest(localVarRequestOptions));
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
return authenticationPromise.then(() => {
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
(<any>localVarRequestOptions).data = localVarFormParams;
localVarRequestOptions.headers = { ...localVarRequestOptions.headers, 'Content-Type': 'multipart/form-data' };
} else {
localVarRequestOptions.data = localVarFormParams;
localVarRequestOptions.headers = { ...localVarRequestOptions.headers, 'content-type': 'application/x-www-form-urlencoded' };
}
}
return new Promise<{ response: AxiosResponse; body: UsageRecordsList; }>(async (resolve, reject) => {
let body = null
try {
const response = await axios(localVarRequestOptions)
body = ObjectSerializer.deserialize(response.data, "UsageRecordsList");
if (response.status && response.status >= 200 && response.status <= 299) {
resolve({ response: response, body: body });
} else {
reject({ response: response, body: body });
}
}
catch(error) {
const errorResponse = new ApiError(error)
reject(JSON.stringify(errorResponse.generateError()))
}
});
});
}
/**
*
* @summary Send metered usage belonging to this subscription and subscription item
* @param subscriptionId Unique identifier for Subscription object
* @param subscriptionItemId The unique identifier of the subscriptionItem
* @param createUsageRecord Contains the quantity for the usage record to create
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate processing. 128 character max.
*/
public async postUsageRecords (subscriptionId: string, subscriptionItemId: string, createUsageRecord: CreateUsageRecord, idempotencyKey?: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: AxiosResponse; body: UsageRecord; }> {
const localVarPath = this.basePath + '/subscriptions/{subscriptionId}/items/{subscriptionItemId}/usage-records'
.replace('{' + 'subscriptionId' + '}', encodeURIComponent(String(subscriptionId)))
.replace('{' + 'subscriptionItemId' + '}', encodeURIComponent(String(subscriptionItemId)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this.defaultHeaders);
let localVarFormParams: any = {};
let acceptHeadersFromSpec = [
"application/json"
];
const isBufferType = acceptHeadersFromSpec.includes("application/pdf")|| acceptHeadersFromSpec.includes("application/octet-stream") || acceptHeadersFromSpec.includes("application/jpg");
const responseTypeOption = isBufferType ? "arraybuffer" : "json";
// verify required parameter 'subscriptionId' is not null or undefined
if (subscriptionId === null || subscriptionId === undefined) {
throw new Error('Required parameter subscriptionId was null or undefined when calling postUsageRecords.');
}
// verify required parameter 'subscriptionItemId' is not null or undefined
if (subscriptionItemId === null || subscriptionItemId === undefined) {
throw new Error('Required parameter subscriptionItemId was null or undefined when calling postUsageRecords.');
}
// verify required parameter 'createUsageRecord' is not null or undefined
if (createUsageRecord === null || createUsageRecord === undefined) {
throw new Error('Required parameter createUsageRecord was null or undefined when calling postUsageRecords.');
}
localVarHeaderParams['Idempotency-Key'] = ObjectSerializer.serialize(idempotencyKey, "string");
localVarHeaderParams['Accept'] = acceptHeadersFromSpec.join();
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let localVarRequestOptions: AxiosRequestConfig = {
method: 'POST',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
responseType: responseTypeOption,
data: ObjectSerializer.serialize(createUsageRecord, "CreateUsageRecord"),
};
let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.OAuth2.applyToRequest(localVarRequestOptions));
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
return authenticationPromise.then(() => {
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
(<any>localVarRequestOptions).data = localVarFormParams;
localVarRequestOptions.headers = { ...localVarRequestOptions.headers, 'Content-Type': 'multipart/form-data' };
} else {
localVarRequestOptions.data = localVarFormParams;
localVarRequestOptions.headers = { ...localVarRequestOptions.headers, 'content-type': 'application/x-www-form-urlencoded' };
}
}
return new Promise<{ response: AxiosResponse; body: UsageRecord; }>(async (resolve, reject) => {
let body = null
try {
const response = await axios(localVarRequestOptions)
body = ObjectSerializer.deserialize(response.data, "UsageRecord");
if (response.status && response.status >= 200 && response.status <= 299) {
resolve({ response: response, body: body });
} else {
reject({ response: response, body: body });
}
}
catch(error) {
const errorResponse = new ApiError(error)
reject(JSON.stringify(errorResponse.generateError()))
}
});
});
}
/**
*
* @summary Update and existing metered usage belonging to this subscription and subscription item
* @param subscriptionId Unique identifier for Subscription object
* @param subscriptionItemId The unique identifier of the subscriptionItem
* @param usageRecordId The unique identifier of the usage record
* @param updateUsageRecord Contains the quantity for the usage record to update
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate processing. 128 character max.
*/
public async putUsageRecords (subscriptionId: string, subscriptionItemId: string, usageRecordId: string, updateUsageRecord: UpdateUsageRecord, idempotencyKey?: string, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: AxiosResponse; body: UsageRecord; }> {
const localVarPath = this.basePath + '/subscriptions/{subscriptionId}/items/{subscriptionItemId}/usage-records/{usageRecordId}'
.replace('{' + 'subscriptionId' + '}', encodeURIComponent(String(subscriptionId)))
.replace('{' + 'subscriptionItemId' + '}', encodeURIComponent(String(subscriptionItemId)))
.replace('{' + 'usageRecordId' + '}', encodeURIComponent(String(usageRecordId)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this.defaultHeaders);
let localVarFormParams: any = {};
let acceptHeadersFromSpec = [
"application/json"
];
const isBufferType = acceptHeadersFromSpec.includes("application/pdf")|| acceptHeadersFromSpec.includes("application/octet-stream") || acceptHeadersFromSpec.includes("application/jpg");
const responseTypeOption = isBufferType ? "arraybuffer" : "json";
// verify required parameter 'subscriptionId' is not null or undefined
if (subscriptionId === null || subscriptionId === undefined) {
throw new Error('Required parameter subscriptionId was null or undefined when calling putUsageRecords.');
}
// verify required parameter 'subscriptionItemId' is not null or undefined
if (subscriptionItemId === null || subscriptionItemId === undefined) {
throw new Error('Required parameter subscriptionItemId was null or undefined when calling putUsageRecords.');
}
// verify required parameter 'usageRecordId' is not null or undefined
if (usageRecordId === null || usageRecordId === undefined) {
throw new Error('Required parameter usageRecordId was null or undefined when calling putUsageRecords.');
}
// verify required parameter 'updateUsageRecord' is not null or undefined
if (updateUsageRecord === null || updateUsageRecord === undefined) {
throw new Error('Required parameter updateUsageRecord was null or undefined when calling putUsageRecords.');
}
localVarHeaderParams['Idempotency-Key'] = ObjectSerializer.serialize(idempotencyKey, "string");
localVarHeaderParams['Accept'] = acceptHeadersFromSpec.join();
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let localVarRequestOptions: AxiosRequestConfig = {
method: 'PUT',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
responseType: responseTypeOption,
data: ObjectSerializer.serialize(updateUsageRecord, "UpdateUsageRecord"),
};
let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.OAuth2.applyToRequest(localVarRequestOptions));
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
return authenticationPromise.then(() => {
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
(<any>localVarRequestOptions).data = localVarFormParams;
localVarRequestOptions.headers = { ...localVarRequestOptions.headers, 'Content-Type': 'multipart/form-data' };
} else {
localVarRequestOptions.data = localVarFormParams;
localVarRequestOptions.headers = { ...localVarRequestOptions.headers, 'content-type': 'application/x-www-form-urlencoded' };
}
}
return new Promise<{ response: AxiosResponse; body: UsageRecord; }>(async (resolve, reject) => {
let body = null
try {
const response = await axios(localVarRequestOptions)
body = ObjectSerializer.deserialize(response.data, "UsageRecord");
if (response.status && response.status >= 200 && response.status <= 299) {
resolve({ response: response, body: body });
} else {
reject({ response: response, body: body });
}
}
catch(error) {
const errorResponse = new ApiError(error)
reject(JSON.stringify(errorResponse.generateError()))
}
});
});
}
}