Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async getTemplate(templateUri) {
const cacheKey = this.getTemplateCacheKey(templateUri);
const result = globalTemplateCache.get(cacheKey);
if (result) {
Logger.info('Returning template from cache', templateUri);
return result;
}
const templateUriInfo = TemplateLibrary.parseURI(templateUri);
const templateIndex = await this.getTemplateIndex();
const templateMetadata = templateIndex[`${templateUriInfo.templateName}@${templateUriInfo.templateVersion}`];
if(!templateMetadata) {
throw new Error(`Failed to find template ${templateUri}`);
}
// fetch the template
const template = await Template.fromUrl(templateMetadata.url);
// check the hash matches
const templateHash = template.getHash();
if(templateHash !== templateUriInfo.templateHash) {
async getTemplateIndex(options) {
const cacheKey = this.getTemplateIndexCacheKey(options);
const result = globalTemplateIndexCache.get(cacheKey);
if (result) {
Logger.info('Returning template index from cache');
return Promise.resolve(result);
}
const httpOptions = {
uri: `${this.url}/template-library.json`,
headers: {
'User-Agent': 'clause',
},
json: true, // Automatically parses the JSON string in the response
};
Logger.info('Loading template library from', httpOptions.uri);
return rp(httpOptions)
.then((templateIndex) => {
if(options && options.latestVersion) {
static validateInvokeArgs(argv) {
argv = Commands.validateCommonArgs(argv);
argv = Commands.setDefaultFileArg(argv, 'sample', 'text/sample.md', ((argv, argDefaultName) => { return path.resolve(argv.template,argDefaultName); }));
argv = Commands.setDefaultFileArg(argv, 'params', 'params.json', ((argv, argDefaultName) => { return [path.resolve(argv.template,argDefaultName)]; }));
if(argv.verbose) {
Logger.info(`initialize sample ${argv.sample} using a template ${argv.template}`);
}
return argv;
}
.then((result) => {
Logger.info('Completed.');
})
.catch((err) => {
static validateTriggerArgs(argv) {
argv = Commands.validateCommonArgs(argv);
argv = Commands.setDefaultFileArg(argv, 'sample', 'text/sample.md', ((argv, argDefaultName) => { return path.resolve(argv.template,argDefaultName); }));
argv = Commands.setDefaultFileArg(argv, 'request', 'request.json', ((argv, argDefaultName) => { return [path.resolve(argv.template,argDefaultName)]; }));
//argv = Commands.setDefaultFileArg(argv, 'state', 'state.json', ((argv, argDefaultName) => { return path.resolve(argv.template,argDefaultName); }));
if(argv.verbose) {
Logger.info(`trigger sample ${argv.sample} using a template ${argv.template} with request ${argv.request} with state ${argv.state}`);
}
return argv;
}
.then((result) => {
if(result) {Logger.info(JSON.stringify(result));}
})
.catch((err) => {
}, (argv) => {
if (argv.verbose) {
Logger.info(`create contract from data ${argv.data} for template ${argv.template}`);
}
try {
argv = Commands.validateDraftArgs(argv);
const options = {
wrapVariables: argv.wrapVariables,
warnings: argv.warnings,
};
return Commands.draft(argv.template, argv.data, argv.output, argv.currentTime, options)
.then((result) => {
if(result) {Logger.info(result);}
})
.catch((err) => {
Logger.error(err.message);
});
} catch (err){
.then((result) => {
Logger.info(result);
})
.catch((err) => {
static validateInitializeArgs(argv) {
argv = Commands.validateCommonArgs(argv);
argv = Commands.setDefaultFileArg(argv, 'sample', 'text/sample.md', ((argv, argDefaultName) => { return path.resolve(argv.template,argDefaultName); }));
if(argv.verbose) {
Logger.info(`initialize sample ${argv.sample} using a template ${argv.template}`);
}
return argv;
}
static validateParseArgs(argv) {
argv = Commands.validateCommonArgs(argv);
argv = Commands.setDefaultFileArg(argv, 'sample', 'text/sample.md', ((argv, argDefaultName) => { return path.resolve(argv.template,argDefaultName); }));
if(argv.verbose) {
Logger.info(`parse sample ${argv.sample} using a template ${argv.template}`);
}
return argv;
}