@point-api/js-sdk
Version:
Javascript SDK for Point API
50 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const account_1 = require("../ApiModules/account");
const snippets_1 = require("../ApiModules/snippets");
const interactions_1 = require("../ApiModules/interactions");
const authManagerDummy_1 = require("./authManagerDummy");
const autocompleteDemoSession_1 = require("./autocompleteDemoSession");
const localApiServer_1 = require("./localApiServer");
class PointApiDemo {
constructor(emailAddress) {
this.emailAddress = emailAddress;
this.apiUrl = "demo";
// Init API submodules
this.account = new account_1.default(this);
this.snippets = new snippets_1.default(this);
this.interactions = new interactions_1.default(this);
this.authManager = new authManagerDummy_1.default();
this.server = new localApiServer_1.default();
}
setCredentials(emailAddress, apiKey) {
this.emailAddress = emailAddress;
this.authManager.setCredentials(emailAddress, apiKey);
}
initAutocompleteSession(searchType) {
return new autocompleteDemoSession_1.default(this.server);
}
async initAutocompleteSessionAsync(searchType) {
const autocompleteDummySession = this.initAutocompleteSession(searchType);
return Promise.resolve(autocompleteDummySession);
}
async authFetch(method, url, data, headers) {
const jwt = await this.authManager.getJwt();
const authHeaders = {
Authorization: `Bearer ${jwt}`,
...headers
};
return this.fetch(method, url, data, authHeaders);
}
async fetch(method, url, data, headers) {
const response = this.server.httpRequest(method, url, data, headers);
return Promise.resolve(response);
}
setCustomSuggestionsData(snippetGetResponse) {
for (const snippet of snippetGetResponse.snippets) {
this.server.addSnippet(snippet.name, snippet.content, snippet.labels, true);
}
}
}
exports.default = PointApiDemo;
//# sourceMappingURL=pointApiDemo.js.map