Skip to content

Commit

Permalink
fix: keep function name in minified version
Browse files Browse the repository at this point in the history
 * update playground, add upload
  • Loading branch information
dantio committed Aug 27, 2021
1 parent 45870d5 commit e4e58cc
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 12 deletions.
68 changes: 59 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.9/languages/json.min.js"></script>
<main>
<div id="sidebar">
<form>
<form onsubmit="event.preventDefault()">
<div>
<fieldset>
<legend>Credentials</legend>
Expand All @@ -123,6 +123,10 @@
<span>Dev ID</span>
<input name="devId" placeholder="DevId" type="text">
</label>
<label>
<span>Access Token</span>
<textarea rows="4" cols="50" name="accessToken" placeholder="accessToken"></textarea>
</label>
</fieldset>
<fieldset>
<legend>Config</legend>
Expand All @@ -143,13 +147,19 @@
<label>
<span>Get Item</span>
<input value="254188828753" name="itemId" type="text">
<button type="button" class="submit" onclick="getItem()">Get Item</button>
<button type="submit" class="submit" onclick="getItem()">Get Item</button>
</label>

<label>
<span>Search</span>
<input value="" name="query" type="text">
<button type="button" class="submit" onclick="search()">Search</button>
<button type="submit" class="submit" onclick="search()">Search</button>
</label>

<label>
<span>Upload to EPS</span>
<input type="file" name="image">
<button type="submit" class="submit" onclick="upload()">Upload</button>
</label>
</form>
</div>
Expand Down Expand Up @@ -177,7 +187,7 @@ <h1>eBay API Browser - Playground</h1>
devId: form.devId.value,

sandbox: form.sandbox.checked,
siteId: form.siteId.value,
siteId: parseInt(form.siteId.value, 10),
marketplaceId: form.marketplaceId.value,
contentLanguage: 'en-US'
});
Expand All @@ -187,23 +197,63 @@ <h1>eBay API Browser - Playground</h1>
return request;
})

if (form.accessToken.value) {
eBay.OAuth2.setCredentials(form.accessToken.value.trim());
}

return eBay
}

function handleError(e) {code.innerText = e.message}
function handleError(e) {
console.error(e);
code.innerText = e.message
}
function handleResponse(data) {
code.innerText = JSON.stringify(data, null, 2);
hljs.highlightBlock(code);
}

function getItem() {
createApi().buy.browse.getItem('v1|' + form.itemId.value + '|0').then(handleResponse)
.catch(handleError);
try {
createApi().buy.browse.getItem('v1|' + form.itemId.value + '|0').then(handleResponse)
.catch(handleError);
} catch (e) {
handleError(e)
}
}

function search() {
createApi().buy.browse.search({q: form.query }).then(handleResponse)
.catch(handleError);
try {
createApi().buy.browse.search({q: form.query}).then(handleResponse)
.catch(handleError);
} catch (e) {
handleError(e)
}
}

function upload() {
const file = document.forms[0].image.files[0];
if (!file) {
alert('File is required.');
return;
}
try {
createApi().trading.UploadSiteHostedPictures({ExtensionInDays: 1}, {
hook: (xml) => {
const formData = new FormData();
// XML should be always first
formData.append('XML Payload', xml);
formData.append('image', file);
return {
body: formData,
headers: {'Content-Type': 'multipart/form-data'}
}
}
}).then(handleResponse)
.catch(handleError);
} catch (e) {
handleError(e)
}
}
</script>
</body>
5 changes: 4 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ export default {
format: 'umd',
name: 'eBayApi',
exports: "default",
sourcemap: true
}
],
plugins: [
resolve({
browser: true
}),
commonjs(),
terser(),
terser({
keep_fnames: true
}),
strip({
include: [/^.+\.min\.js$/],
debugger: true,
Expand Down
2 changes: 1 addition & 1 deletion src/auth/oAuth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,6 @@ export default class OAuth2 extends Base {
return await this.obtainApplicationAccessToken();
}

throw new Error('To refresh a Token a application access token or user access token must be already set.');
throw new Error('Missing credentials. To refresh a token an application access token or user access token must be already set.');
}
}
2 changes: 1 addition & 1 deletion test/api/oAuth2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe('OAuth2', () => {
try {
await oAuth2.refreshToken();
} catch (e: any) {
expect(e.message).to.equal('To refresh a Token a application access token or user access token must be already set.');
expect(e.message).to.equal('Missing credentials. To refresh a token an application access token or user access token must be already set.');
}
});

Expand Down

0 comments on commit e4e58cc

Please sign in to comment.