@ambisafe/tabla-client
Version:
Ambisafe Tabla client library
116 lines (110 loc) • 3.54 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
CorporateKYCTypes: () => CorporateKYCTypes,
PersonalKYCTypes: () => PersonalKYCTypes,
TablaClient: () => TablaClient
});
module.exports = __toCommonJS(src_exports);
// src/client.ts
var import_axios = __toESM(require("axios"));
var import_ethers = require("ethers");
var jwt = __toESM(require("jsonwebtoken"));
// src/mappers/kyc-data.mapper.ts
var KycDataMapper = class {
map(dto) {
if ("firstName" in dto) {
return this.mapPersonal(dto);
}
return this.mapCorporate(dto);
}
mapPersonal(dto) {
return dto;
}
mapCorporate(dto) {
const { companyName, dateOfIncorporation, ...rest } = dto;
return {
...rest,
firstName: companyName,
birthDate: dateOfIncorporation
};
}
};
var kyc_data_mapper_default = new KycDataMapper();
// src/client.ts
var TablaClient = class {
constructor(url, platformPublicId, jwtSecret) {
this.url = url;
this.platformPublicId = platformPublicId;
this.jwtSecret = jwtSecret;
}
/**
* @param kycData User KYC data that will passed on Tabla
*/
async userWhitelist(kycData) {
const mappedKycData = kyc_data_mapper_default.map(kycData);
const hashedData = import_ethers.utils.keccak256(Buffer.from(JSON.stringify(mappedKycData)));
const accessToken = jwt.sign(
{
platformPublicId: this.platformPublicId,
hashedData,
exp: Math.round(Date.now() / 1e3) + 60
},
this.jwtSecret
);
const response = await import_axios.default.post(
`${this.url}/api/v2/accounts/kyc/set-kyc-properties/calldata`,
mappedKycData,
{
headers: {
"platform-authorization": `Bearer ${accessToken}`
}
}
);
return response.data;
}
};
// src/types.ts
var PersonalKYCTypes = [
"PERSONAL:EMPTY",
"PERSONAL:BASIC_KYC",
"PERSONAL:ACCREDITED_INVESTOR"
];
var CorporateKYCTypes = [
"CORPORATE:EMPTY",
"CORPORATE:BASIC_KYC"
];
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CorporateKYCTypes,
PersonalKYCTypes,
TablaClient
});