@privateid/cryptonets-web-sdk
Version:
CryptoNets WebAssembly SDK
79 lines • 3.7 kB
JavaScript
/* eslint-disable default-param-last */
/* eslint-disable import/no-cycle */
/* eslint-disable camelcase */
/**
* @module PrivID
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { detect } from 'detect-browser';
import { isLoad, getDebugType, getIsSIMD, iOS, getUrlParameter, printLogs, checkPackageSupport } from './utils';
import { clearDB } from './dbUtils';
import { apiKey, cacheConfig } from './envUtils';
let isSimd = null;
let moduleLoaded = false;
const debugType = getDebugType();
printLogs('debug_type', debugType, debugType);
/**
* This function load the wasm module
* @category Utils
*/
export const loadPrivIdModule = function ({ api_url, api_key, api_orchestration_url, cache_config, timeout, useCdn, }) {
return __awaiter(this, void 0, void 0, function* () {
try {
const supportResult = yield checkPackageSupport();
if (!supportResult.support) {
return supportResult;
}
const clearCacheParam = getUrlParameter('clear_cache', 'false');
const cacheAge = localStorage.getItem('cacheAge');
if (!cacheAge) {
localStorage.setItem('cacheAge', Date.now().toString());
}
if ((cacheAge && Date.now() - Number(cacheAge) > 24 * 60 * 60 * 1000) || clearCacheParam === 'true') {
printLogs('------clearingCache------', '', debugType);
yield clearDB();
localStorage.clear();
localStorage.setItem('cacheAge', Date.now().toString());
}
if (moduleLoaded)
return { support: true };
const hasSIMD = yield getIsSIMD();
printLogs('=====> is SIMD or NOT SIMD?', hasSIMD, debugType);
printLogs('===> is IOS', iOS(), debugType);
printLogs('==> browser? ', detect(), debugType);
const { name: browserName, os } = detect();
if (iOS() || os === 'iOS' || (os === 'Mac OS' && browserName !== 'chrome')) {
isSimd = false;
}
else {
isSimd = hasSIMD;
}
const loadBuild = isSimd;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const loaded = yield isLoad(loadBuild, api_url, api_key ? api_key : apiKey, debugType, cache_config ? cache_config : cacheConfig, timeout, useCdn);
printLogs('------loaded------', loaded, debugType);
moduleLoaded = loaded === 'Loaded';
return supportResult;
}
catch (e) {
console.log('ERROR LOADING:', e);
return { support: false, message: 'Unable to load wasm' };
}
});
};
export const isModuleLoaded = () => moduleLoaded;
export * from './apiUtils';
export { clearDB, clearCache } from './dbUtils';
export * from './faceModule';
export { setEnvVariables } from './envUtils';
export { convertCroppedImage, checkPackageSupport, getScreenOrientation } from './utils';
//# sourceMappingURL=index.js.map