ebay-api 1.13.4 → 6.0.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 +18 -19
- package/README.md +512 -118
- package/lib/api/apiFactory.d.ts +27 -0
- package/lib/api/apiFactory.js +100 -0
- package/lib/api/apiFactory.js.map +1 -0
- package/lib/api/base.d.ts +13 -0
- package/lib/api/base.js +25 -0
- package/lib/api/base.js.map +1 -0
- package/lib/api/index.d.ts +11 -0
- package/lib/api/index.js +18 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/restful/buy/browse/index.d.ts +84 -0
- package/lib/api/restful/buy/browse/index.js +142 -0
- package/lib/api/restful/buy/browse/index.js.map +1 -0
- package/lib/api/restful/buy/deal/index.d.ts +55 -0
- package/lib/api/restful/buy/deal/index.js +80 -0
- package/lib/api/restful/buy/deal/index.js.map +1 -0
- package/lib/api/restful/buy/feed/index.d.ts +43 -0
- package/lib/api/restful/buy/feed/index.js +85 -0
- package/lib/api/restful/buy/feed/index.js.map +1 -0
- package/lib/api/restful/buy/index.d.ts +17 -0
- package/lib/api/restful/buy/index.js +21 -0
- package/lib/api/restful/buy/index.js.map +1 -0
- package/lib/api/restful/buy/marketing/index.d.ts +27 -0
- package/lib/api/restful/buy/marketing/index.js +51 -0
- package/lib/api/restful/buy/marketing/index.js.map +1 -0
- package/lib/api/restful/buy/marketplaceInsights/index.d.ts +28 -0
- package/lib/api/restful/buy/marketplaceInsights/index.js +51 -0
- package/lib/api/restful/buy/marketplaceInsights/index.js.map +1 -0
- package/lib/api/restful/buy/offer/index.d.ts +23 -0
- package/lib/api/restful/buy/offer/index.js +37 -0
- package/lib/api/restful/buy/offer/index.js.map +1 -0
- package/lib/api/restful/buy/order/index.d.ts +264 -0
- package/lib/api/restful/buy/order/index.js +369 -0
- package/lib/api/restful/buy/order/index.js.map +1 -0
- package/lib/api/restful/commerce/catalog/index.d.ts +73 -0
- package/lib/api/restful/commerce/catalog/index.js +108 -0
- package/lib/api/restful/commerce/catalog/index.js.map +1 -0
- package/lib/api/restful/commerce/charity/index.d.ts +34 -0
- package/lib/api/restful/commerce/charity/index.js +56 -0
- package/lib/api/restful/commerce/charity/index.js.map +1 -0
- package/lib/api/restful/commerce/identity/index.d.ts +14 -0
- package/lib/api/restful/commerce/identity/index.js +27 -0
- package/lib/api/restful/commerce/identity/index.js.map +1 -0
- package/lib/api/restful/commerce/index.d.ts +15 -0
- package/lib/api/restful/commerce/index.js +19 -0
- package/lib/api/restful/commerce/index.js.map +1 -0
- package/lib/api/restful/commerce/notification/index.d.ts +117 -0
- package/lib/api/restful/commerce/notification/index.js +187 -0
- package/lib/api/restful/commerce/notification/index.js.map +1 -0
- package/lib/api/restful/commerce/taxonomy/index.d.ts +78 -0
- package/lib/api/restful/commerce/taxonomy/index.js +135 -0
- package/lib/api/restful/commerce/taxonomy/index.js.map +1 -0
- package/lib/api/restful/commerce/translation/index.d.ts +15 -0
- package/lib/api/restful/commerce/translation/index.js +25 -0
- package/lib/api/restful/commerce/translation/index.js.map +1 -0
- package/lib/api/restful/developer/analytics/index.d.ts +22 -0
- package/lib/api/restful/developer/analytics/index.js +45 -0
- package/lib/api/restful/developer/analytics/index.js.map +1 -0
- package/lib/api/restful/developer/index.d.ts +5 -0
- package/lib/api/restful/developer/index.js +9 -0
- package/lib/api/restful/developer/index.js.map +1 -0
- package/lib/api/restful/index.d.ts +63 -0
- package/lib/api/restful/index.js +165 -0
- package/lib/api/restful/index.js.map +1 -0
- package/lib/api/restful/postOrder/cancellation/index.d.ts +57 -0
- package/lib/api/restful/postOrder/cancellation/index.js +95 -0
- package/lib/api/restful/postOrder/cancellation/index.js.map +1 -0
- package/lib/api/restful/postOrder/case/index.d.ts +63 -0
- package/lib/api/restful/postOrder/case/index.js +97 -0
- package/lib/api/restful/postOrder/case/index.js.map +1 -0
- package/lib/api/restful/postOrder/index.d.ts +11 -0
- package/lib/api/restful/postOrder/index.js +15 -0
- package/lib/api/restful/postOrder/index.js.map +1 -0
- package/lib/api/restful/postOrder/inquiry/index.d.ts +82 -0
- package/lib/api/restful/postOrder/inquiry/index.js +131 -0
- package/lib/api/restful/postOrder/inquiry/index.js.map +1 -0
- package/lib/api/restful/postOrder/return/index.d.ts +231 -0
- package/lib/api/restful/postOrder/return/index.js +361 -0
- package/lib/api/restful/postOrder/return/index.js.map +1 -0
- package/lib/api/restful/sell/account/index.d.ts +217 -0
- package/lib/api/restful/sell/account/index.js +337 -0
- package/lib/api/restful/sell/account/index.js.map +1 -0
- package/lib/api/restful/sell/analytics/index.d.ts +41 -0
- package/lib/api/restful/sell/analytics/index.js +61 -0
- package/lib/api/restful/sell/analytics/index.js.map +1 -0
- package/lib/api/restful/sell/compliance/index.d.ts +37 -0
- package/lib/api/restful/sell/compliance/index.js +57 -0
- package/lib/api/restful/sell/compliance/index.js.map +1 -0
- package/lib/api/restful/sell/feed/index.d.ts +151 -0
- package/lib/api/restful/sell/feed/index.js +255 -0
- package/lib/api/restful/sell/feed/index.js.map +1 -0
- package/lib/api/restful/sell/finances/index.d.ts +74 -0
- package/lib/api/restful/sell/finances/index.js +105 -0
- package/lib/api/restful/sell/finances/index.js.map +1 -0
- package/lib/api/restful/sell/fulfillment/index.d.ts +137 -0
- package/lib/api/restful/sell/fulfillment/index.js +199 -0
- package/lib/api/restful/sell/fulfillment/index.js.map +1 -0
- package/lib/api/restful/sell/index.d.ts +29 -0
- package/lib/api/restful/sell/index.js +33 -0
- package/lib/api/restful/sell/index.js.map +1 -0
- package/lib/api/restful/sell/inventory/index.d.ts +248 -0
- package/lib/api/restful/sell/inventory/index.js +346 -0
- package/lib/api/restful/sell/inventory/index.js.map +1 -0
- package/lib/api/restful/sell/listing/index.d.ts +14 -0
- package/lib/api/restful/sell/listing/index.js +25 -0
- package/lib/api/restful/sell/listing/index.js.map +1 -0
- package/lib/api/restful/sell/logistics/index.d.ts +44 -0
- package/lib/api/restful/sell/logistics/index.js +66 -0
- package/lib/api/restful/sell/logistics/index.js.map +1 -0
- package/lib/api/restful/sell/marketing/index.d.ts +443 -0
- package/lib/api/restful/sell/marketing/index.js +609 -0
- package/lib/api/restful/sell/marketing/index.js.map +1 -0
- package/lib/api/restful/sell/metadata/index.d.ts +77 -0
- package/lib/api/restful/sell/metadata/index.js +131 -0
- package/lib/api/restful/sell/metadata/index.js.map +1 -0
- package/lib/api/restful/sell/negotiation/index.d.ts +24 -0
- package/lib/api/restful/sell/negotiation/index.js +39 -0
- package/lib/api/restful/sell/negotiation/index.js.map +1 -0
- package/lib/api/restful/sell/recommendation/index.d.ts +26 -0
- package/lib/api/restful/sell/recommendation/index.js +39 -0
- package/lib/api/restful/sell/recommendation/index.js.map +1 -0
- package/lib/api/traditional/XMLRequest.d.ts +98 -0
- package/lib/api/traditional/XMLRequest.js +191 -0
- package/lib/api/traditional/XMLRequest.js.map +1 -0
- package/lib/api/traditional/clientAlerts/index.d.ts +9 -0
- package/lib/api/traditional/clientAlerts/index.js +15 -0
- package/lib/api/traditional/clientAlerts/index.js.map +1 -0
- package/lib/api/traditional/clientAlerts/types.d.ts +31 -0
- package/lib/api/traditional/clientAlerts/types.js +36 -0
- package/lib/api/traditional/clientAlerts/types.js.map +1 -0
- package/lib/api/traditional/fields.d.ts +1948 -0
- package/lib/api/traditional/fields.js +1949 -0
- package/lib/api/traditional/fields.js.map +1 -0
- package/lib/api/traditional/finding/index.d.ts +12 -0
- package/lib/api/traditional/finding/index.js +16 -0
- package/lib/api/traditional/finding/index.js.map +1 -0
- package/lib/api/traditional/index.d.ts +17 -0
- package/lib/api/traditional/index.js +207 -0
- package/lib/api/traditional/index.js.map +1 -0
- package/lib/api/traditional/merchandising/index.d.ts +7 -0
- package/lib/api/traditional/merchandising/index.js +11 -0
- package/lib/api/traditional/merchandising/index.js.map +1 -0
- package/lib/api/traditional/shopping/index.d.ts +11 -0
- package/lib/api/traditional/shopping/index.js +16 -0
- package/lib/api/traditional/shopping/index.js.map +1 -0
- package/lib/api/traditional/trading/index.d.ts +142 -0
- package/lib/api/traditional/trading/index.js +146 -0
- package/lib/api/traditional/trading/index.js.map +1 -0
- package/lib/auth/authNAuth.d.ts +49 -0
- package/lib/auth/authNAuth.js +122 -0
- package/lib/auth/authNAuth.js.map +1 -0
- package/lib/auth/index.d.ts +17 -0
- package/lib/auth/index.js +32 -0
- package/lib/auth/index.js.map +1 -0
- package/lib/auth/oAuth2.d.ts +90 -0
- package/lib/auth/oAuth2.js +258 -0
- package/lib/auth/oAuth2.js.map +1 -0
- package/lib/ebay-api.min.js +2 -0
- package/lib/ebay-api.min.js.map +1 -0
- package/lib/enums/apiEnums.d.ts +49 -0
- package/lib/enums/apiEnums.js +55 -0
- package/lib/enums/apiEnums.js.map +1 -0
- package/lib/enums/index.d.ts +2 -0
- package/lib/enums/index.js +15 -0
- package/lib/enums/index.js.map +1 -0
- package/lib/enums/restfulEnums.d.ts +672 -0
- package/lib/enums/restfulEnums.js +714 -0
- package/lib/enums/restfulEnums.js.map +1 -0
- package/lib/errors/index.d.ts +66 -0
- package/lib/errors/index.js +208 -0
- package/lib/errors/index.js.map +1 -0
- package/lib/index.d.ts +55 -0
- package/lib/index.js +98 -0
- package/lib/index.js.map +1 -0
- package/lib/request.d.ts +26 -0
- package/lib/request.js +51 -0
- package/lib/request.js.map +1 -0
- package/lib/types/apiTypes.d.ts +28 -0
- package/lib/types/apiTypes.js +3 -0
- package/lib/types/apiTypes.js.map +1 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/index.js +16 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/restfulTypes.d.ts +1067 -0
- package/lib/types/restfulTypes.js +3 -0
- package/lib/types/restfulTypes.js.map +1 -0
- package/lib/types/traditonalTypes.d.ts +34 -0
- package/lib/types/traditonalTypes.js +3 -0
- package/lib/types/traditonalTypes.js.map +1 -0
- package/package.json +115 -21
- package/.npmignore +0 -17
- package/.travis.yml +0 -7
- package/examples/Finding-FindItemsByKeywords.js +0 -46
- package/examples/Merchandising-GetMostWatchedItemsRequest.js +0 -16
- package/examples/Shopping-GetSingleItem.js +0 -18
- package/examples/Trading-GetOrders.js +0 -26
- package/index.js +0 -10
- package/lib/deep-to-array.js +0 -42
- package/lib/defaults.js +0 -69
- package/lib/errors.js +0 -44
- package/lib/json-parser.js +0 -336
- package/lib/key-lists.js +0 -64
- package/lib/urls.js +0 -64
- package/lib/versions.js +0 -35
- package/lib/xml-converter.js +0 -21
- package/lib/xml-request.js +0 -207
- package/scripts/parse-input-xml.js +0 -41
- package/test/deep-to-array.test.js +0 -100
- package/test/errors.test.js +0 -75
- package/test/helpers.js +0 -22
- package/test/mocha.opts +0 -1
- package/test/mocks/GetMultipleItems.xml +0 -115
- package/test/mocks/GetOrders-empty.xml +0 -17
- package/test/mocks/GetOrders.xml +0 -463
- package/test/pagination.test.js +0 -5
- package/test/parsing.test.js +0 -248
- package/test/xml-request.test.js +0 -447
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const debug_1 = __importDefault(require("debug"));
|
|
7
|
+
const base_1 = __importDefault(require("../api/base"));
|
|
8
|
+
const log = (0, debug_1.default)('ebay:oauth2');
|
|
9
|
+
/**
|
|
10
|
+
* https://developer.ebay.com/api-docs/static/oauth-tokens.html
|
|
11
|
+
*
|
|
12
|
+
* Client credentials grant flow mints a new Application access token that you can use to access the resources owned by the application.
|
|
13
|
+
* Authorization code grant flow mints a new User access token that you can use to access the resources owned by the user.
|
|
14
|
+
*/
|
|
15
|
+
class OAuth2 extends base_1.default {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
this.scope = this.config.scope || OAuth2.defaultScopes;
|
|
19
|
+
}
|
|
20
|
+
static generateAuthUrl(sandbox, appId, ruName, scope, state = '') {
|
|
21
|
+
return [
|
|
22
|
+
sandbox ? OAuth2.AUTHORIZE_ENDPOINT.sandbox : OAuth2.AUTHORIZE_ENDPOINT.production,
|
|
23
|
+
'?client_id=', encodeURIComponent(appId),
|
|
24
|
+
'&redirect_uri=', encodeURIComponent(ruName),
|
|
25
|
+
'&response_type=code',
|
|
26
|
+
'&state=', encodeURIComponent(state),
|
|
27
|
+
'&scope=', encodeURIComponent(scope.join(' '))
|
|
28
|
+
].join('');
|
|
29
|
+
}
|
|
30
|
+
get identityEndpoint() {
|
|
31
|
+
return this.config.sandbox ? OAuth2.IDENTITY_ENDPOINT.sandbox : OAuth2.IDENTITY_ENDPOINT.production;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Return the access token.
|
|
35
|
+
* First return user access token, if not set Application Access Token.
|
|
36
|
+
*/
|
|
37
|
+
async getAccessToken() {
|
|
38
|
+
return this.getUserAccessToken() || this.getApplicationAccessToken();
|
|
39
|
+
}
|
|
40
|
+
getUserAccessToken() {
|
|
41
|
+
return this._authToken?.access_token ?? null;
|
|
42
|
+
}
|
|
43
|
+
async getApplicationAccessToken() {
|
|
44
|
+
if (this._clientToken) {
|
|
45
|
+
log('Return existing application access token: ', this._clientToken);
|
|
46
|
+
return this._clientToken.access_token;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const token = await this.obtainApplicationAccessToken();
|
|
50
|
+
return token.access_token;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
setClientToken(clientToken) {
|
|
57
|
+
this._clientToken = clientToken;
|
|
58
|
+
}
|
|
59
|
+
setScope(scope) {
|
|
60
|
+
this.scope = scope;
|
|
61
|
+
}
|
|
62
|
+
getScope() {
|
|
63
|
+
return [...this.scope];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Client credentials grant flow.
|
|
67
|
+
*/
|
|
68
|
+
async mintApplicationAccessToken() {
|
|
69
|
+
if (!this.config.appId) {
|
|
70
|
+
throw new Error('Missing App ID (Client Id)');
|
|
71
|
+
}
|
|
72
|
+
if (!this.config.certId) {
|
|
73
|
+
throw new Error('Missing Cert Id (Client Secret)');
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
return await this.req.postForm(this.identityEndpoint, {
|
|
77
|
+
scope: this.scope.join(' '),
|
|
78
|
+
grant_type: 'client_credentials'
|
|
79
|
+
}, {
|
|
80
|
+
auth: {
|
|
81
|
+
username: this.config.appId,
|
|
82
|
+
password: this.config.certId
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
log('Failed to mint application token', error);
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Client credentials grant flow.
|
|
93
|
+
*/
|
|
94
|
+
async obtainApplicationAccessToken() {
|
|
95
|
+
log('Obtain a new application access token with scope: ', this.scope.join(','));
|
|
96
|
+
try {
|
|
97
|
+
const token = await this.mintApplicationAccessToken();
|
|
98
|
+
log('Obtained a new application access token:', token);
|
|
99
|
+
this.setClientToken(token);
|
|
100
|
+
this.emit('refreshClientToken', token);
|
|
101
|
+
return token;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
log('Failed to obtain application token', error);
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Generates URL for consent page landing.
|
|
110
|
+
*
|
|
111
|
+
* @param ruName RuName
|
|
112
|
+
* @param scope the scopes
|
|
113
|
+
* @param state state parameter returned in the redirect URL
|
|
114
|
+
*/
|
|
115
|
+
generateAuthUrl(ruName, scope = this.scope, state = '') {
|
|
116
|
+
ruName = ruName || this.config.ruName;
|
|
117
|
+
if (!ruName) {
|
|
118
|
+
throw new Error('RuName is required.');
|
|
119
|
+
}
|
|
120
|
+
return OAuth2.generateAuthUrl(this.config.sandbox, this.config.appId, ruName, scope, state);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Authorization code grant flow.
|
|
124
|
+
*
|
|
125
|
+
* Mint the user access token for the given code.
|
|
126
|
+
*
|
|
127
|
+
* @param code the code
|
|
128
|
+
* @param ruName the redirectUri
|
|
129
|
+
*/
|
|
130
|
+
async mintUserAccessToken(code, ruName = this.config.ruName) {
|
|
131
|
+
try {
|
|
132
|
+
const token = await this.req.postForm(this.identityEndpoint, {
|
|
133
|
+
grant_type: 'authorization_code',
|
|
134
|
+
code,
|
|
135
|
+
redirect_uri: ruName
|
|
136
|
+
}, {
|
|
137
|
+
auth: {
|
|
138
|
+
username: this.config.appId,
|
|
139
|
+
password: this.config.certId
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
log('User Access Token', token);
|
|
143
|
+
return token;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
log('Failed to get the token', error);
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Authorization code grant flow.
|
|
152
|
+
*
|
|
153
|
+
* Mint the access token for the given code.
|
|
154
|
+
*
|
|
155
|
+
* @param code the code
|
|
156
|
+
* @param ruName the redirectUri
|
|
157
|
+
*/
|
|
158
|
+
async getToken(code, ruName = this.config.ruName) {
|
|
159
|
+
return await this.mintUserAccessToken(code, ruName);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Authorization code grant flow.
|
|
163
|
+
*/
|
|
164
|
+
async refreshUserAccessToken() {
|
|
165
|
+
if (!this._authToken || !this._authToken.refresh_token) {
|
|
166
|
+
log('Tried to refresh user access token before it was set.');
|
|
167
|
+
throw new Error('Failed to refresh the user access token. Token or refresh_token is not set.');
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
const token = await this.req.postForm(this.identityEndpoint, {
|
|
171
|
+
grant_type: 'refresh_token',
|
|
172
|
+
refresh_token: this._authToken.refresh_token,
|
|
173
|
+
scope: this.scope.join(' ')
|
|
174
|
+
}, {
|
|
175
|
+
auth: {
|
|
176
|
+
username: this.config.appId,
|
|
177
|
+
password: this.config.certId
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
log('Successfully refreshed token', token);
|
|
181
|
+
const refreshedToken = {
|
|
182
|
+
...this._authToken,
|
|
183
|
+
...token
|
|
184
|
+
};
|
|
185
|
+
this.setCredentials(refreshedToken);
|
|
186
|
+
this.emit('refreshAuthToken', refreshedToken);
|
|
187
|
+
return refreshedToken;
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
log('Failed to refresh the token', error);
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Gets and sets the user access token for the given code.
|
|
196
|
+
*
|
|
197
|
+
* Authorization code grant flow.
|
|
198
|
+
*
|
|
199
|
+
* @param code the code
|
|
200
|
+
*/
|
|
201
|
+
async obtainToken(code) {
|
|
202
|
+
const token = await this.getToken(code);
|
|
203
|
+
log('Obtain user access token', token);
|
|
204
|
+
this.setCredentials(token);
|
|
205
|
+
return token;
|
|
206
|
+
}
|
|
207
|
+
getCredentials() {
|
|
208
|
+
if (this._authToken) {
|
|
209
|
+
return {
|
|
210
|
+
...this._authToken
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
else if (this._clientToken) {
|
|
214
|
+
return {
|
|
215
|
+
...this._clientToken
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
setCredentials(authToken) {
|
|
221
|
+
if (typeof authToken === 'string') {
|
|
222
|
+
this._authToken = {
|
|
223
|
+
refresh_token: '',
|
|
224
|
+
expires_in: 7200,
|
|
225
|
+
refresh_token_expires_in: 47304000,
|
|
226
|
+
token_type: 'User Access Token',
|
|
227
|
+
access_token: authToken
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
this._authToken = authToken;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Refresh the user access token if set or application access token
|
|
236
|
+
*/
|
|
237
|
+
async refreshToken() {
|
|
238
|
+
if (this._authToken) {
|
|
239
|
+
return await this.refreshUserAccessToken();
|
|
240
|
+
}
|
|
241
|
+
else if (this._clientToken) {
|
|
242
|
+
return await this.obtainApplicationAccessToken();
|
|
243
|
+
}
|
|
244
|
+
throw new Error('Missing credentials. To refresh a token an application access token or user access token must be already set.');
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
exports.default = OAuth2;
|
|
248
|
+
// If all the calls in our application require just an Application access token we can use this endpoint
|
|
249
|
+
OAuth2.IDENTITY_ENDPOINT = {
|
|
250
|
+
production: 'https://api.ebay.com/identity/v1/oauth2/token',
|
|
251
|
+
sandbox: 'https://api.sandbox.ebay.com/identity/v1/oauth2/token'
|
|
252
|
+
};
|
|
253
|
+
OAuth2.AUTHORIZE_ENDPOINT = {
|
|
254
|
+
production: 'https://auth.ebay.com/oauth2/authorize',
|
|
255
|
+
sandbox: 'https://auth.sandbox.ebay.com/oauth2/authorize'
|
|
256
|
+
};
|
|
257
|
+
OAuth2.defaultScopes = ['https://api.ebay.com/oauth/api_scope'];
|
|
258
|
+
//# sourceMappingURL=oAuth2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oAuth2.js","sourceRoot":"","sources":["../../src/auth/oAuth2.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAC1B,uDAA+B;AAG/B,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,aAAa,CAAC,CAAC;AAejC;;;;;GAKG;AACH,MAAqB,MAAO,SAAQ,cAAI;IAAxC;;QA+BU,UAAK,GAAU,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,aAAa,CAAC;IAsPnE,CAAC;IAvQQ,MAAM,CAAC,eAAe,CAC3B,OAAgB,EAChB,KAAa,EACb,MAAc,EACd,KAAe,E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