mpp-sdk
Version:
SDK to talk to the Memento Payments Platform
114 lines (113 loc) • 5.62 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.MPPSDK = void 0;
const tslib_1 = require("tslib");
const axios_1 = tslib_1.__importDefault(require("axios"));
const storage_1 = require("./storage");
const helpers_1 = require("./utils/helpers");
const sessions_1 = tslib_1.__importDefault(require("./endpoints/sessions"));
const users_1 = tslib_1.__importDefault(require("./endpoints/users"));
const funding_sources_1 = tslib_1.__importDefault(require("./endpoints/funding_sources"));
const devices_1 = tslib_1.__importDefault(require("./endpoints/devices"));
const tokens_1 = tslib_1.__importDefault(require("./endpoints/tokens"));
const verifications_1 = tslib_1.__importDefault(require("./endpoints/verifications"));
const images_1 = tslib_1.__importDefault(require("./endpoints/images"));
const notifications_1 = tslib_1.__importDefault(require("./endpoints/notifications"));
const announcements_1 = tslib_1.__importDefault(require("./endpoints/announcements"));
const referrals_1 = tslib_1.__importDefault(require("./endpoints/referrals"));
const onboarding_1 = tslib_1.__importDefault(require("./endpoints/onboarding"));
const projects_1 = tslib_1.__importDefault(require("./endpoints/projects"));
const transfer_1 = tslib_1.__importDefault(require("./endpoints/transfer"));
const public_tokens_1 = tslib_1.__importDefault(require("./endpoints/public_tokens"));
const transactions_1 = tslib_1.__importDefault(require("./endpoints/transactions"));
const categories_1 = tslib_1.__importDefault(require("./endpoints/categories"));
const invites_1 = tslib_1.__importDefault(require("./endpoints/invites"));
const wallet_1 = tslib_1.__importDefault(require("./endpoints/wallet"));
const teams_1 = require("./endpoints/teams");
class MPPSDK {
constructor(config) {
this.config = {
// This are set in the constructor
host: "",
version: "v1",
appName: "DefaultName",
appVersion: "0.0.1",
// Optional config options
autoRefreshSession: true,
storage: new storage_1.InMemoryStorage(),
projectId: null,
};
this.config = Object.assign(Object.assign({}, this.config), config);
if (this.config.host === "") {
throw new Error("Empty host");
}
// Just to make sure that we're always working with null instead of
// potentially undefined.
if (!this.config.projectId) {
this.config.projectId = null;
}
// Remove old version information from sdk host input
const rePathVersion = /\/v1\/*$/;
if (this.config.host.match(rePathVersion)) {
console.warn("[mpp-sdk] Version information in the host url is deprecated.", "Please use the version parameter on the config instead.");
this.config.host = this.config.host.replace(rePathVersion, "");
// this.config.host = this.config.host.substring(
// 0,
// this.config.host.length - 2
// );
}
// Remove spaces from appName and appVersion
this.config.appName = this.config.appName.replace(" ", "");
this.config.appVersion = this.config.appVersion.replace(" ", "");
this.http = axios_1.default.create({
baseURL: this.config.host,
});
// Set default base headers
this.http.interceptors.request.use((config) => {
config.headers = Object.assign(Object.assign({}, config.headers), (0, helpers_1.headers)(config, this.config));
return config;
});
this.tokens = new tokens_1.default(this.config, this.http);
this.sessions = new sessions_1.default(this.http, this.config, this.tokens);
const baseConfig = {
config: this.config,
http: this.http,
sessions: this.sessions,
};
this.users = new users_1.default(baseConfig);
this.fundingSources = new funding_sources_1.default(baseConfig);
this.devices = new devices_1.default(baseConfig);
this.verifications = new verifications_1.default(baseConfig);
this.images = new images_1.default(baseConfig);
this.notifications = new notifications_1.default(baseConfig);
this.announcements = new announcements_1.default(baseConfig);
this.referrals = new referrals_1.default(baseConfig);
this.onboarding = new onboarding_1.default(baseConfig);
this.projects = new projects_1.default(baseConfig);
this.transfers = new transfer_1.default(baseConfig);
this.transactions = new transactions_1.default(baseConfig);
this.publicTokens = new public_tokens_1.default(baseConfig);
this.categories = new categories_1.default(baseConfig);
this.invites = new invites_1.default(baseConfig);
this.wallet = new wallet_1.default(this.config, this.fundingSources, this.users);
this.teams = new teams_1.TeamsEndpoint(baseConfig);
}
logout() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.tokens.delete();
this.sessions.clear();
yield this.config.storage.clearAuthToken();
});
}
getCurrentDeviceId() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return this.tokens.getCurrentDeviceId();
});
}
setProjectId(id) {
this.config.projectId = id;
}
}
exports.MPPSDK = MPPSDK;
tslib_1.__exportStar(require("./errors"), exports);
tslib_1.__exportStar(require("./types"), exports);
;