Skip to content
Snippets Groups Projects

feat: ocm did svdx generation for sender OP#250

Merged Alexey Lunin requested to merge feat/250-hin-ocm into main
All threads resolved!
Files
3
+ 47
0
import { Injectable, Logger } from "@nestjs/common";
import { IConfCatalog } from "@ocm-engine/config";
import { ConfigService } from "@nestjs/config";
import axios, { AxiosError } from "axios";
@Injectable()
export class CatalogClient {
private readonly logger = new Logger(CatalogClient.name);
private catalogConfig: IConfCatalog;
constructor(private readonly configService: ConfigService) {
this.catalogConfig = this.configService.get<IConfCatalog>("catalog")!;
}
searchAccount = async (email: string): Promise<string | null> => {
this.logger.debug(`searchAccount`, email);
try {
const response = await axios.post(
`${this.catalogConfig.catalogUrl}/v1/accounts/search`,
{
email: email,
},
);
return response.data.did;
} catch (e) {
this.logger.debug("searchAccount failed", e);
if (e instanceof AxiosError && e.status === 404) {
return null;
} else {
throw e;
}
}
};
createAccount = async (email: string, didSvdx: string): Promise<void> => {
this.logger.debug(`createAccount`, email);
try {
await axios.post(`${this.catalogConfig.catalogUrl}/v1/accounts`, {
email: email,
did: didSvdx,
});
} catch (e) {
this.logger.debug("createAccount failed", e);
throw e;
}
};
}
Loading