@sphereon/ssi-sdk.contact-manager-rest-api
Version:
173 lines • 8.63 kB
JavaScript
;
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.partiesReadEndpoint = partiesReadEndpoint;
exports.partyReadEndpoint = partyReadEndpoint;
exports.partyWriteEndpoint = partyWriteEndpoint;
exports.partyDeleteEndpoint = partyDeleteEndpoint;
exports.partiesTypeReadEndpoint = partiesTypeReadEndpoint;
exports.partyTypeReadEndpoint = partyTypeReadEndpoint;
exports.identitiesReadEndpoint = identitiesReadEndpoint;
exports.identityReadEndpoints = identityReadEndpoints;
const ssi_express_support_1 = require("@sphereon/ssi-express-support");
function partiesReadEndpoint(router, context, opts) {
var _a;
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
console.log(`"partiesReadEndpoint" Endpoint is disabled`);
return;
}
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/parties';
router.get(path, (0, ssi_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
try {
// later we will add filter to this
const parties = yield context.agent.cmGetContacts();
response.statusCode = 200;
return response.send(parties);
}
catch (error) {
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, error.message, error);
}
}));
}
function partyReadEndpoint(router, context, opts) {
var _a;
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
console.log(`"partyReadEndpoint" Endpoint is disabled`);
return;
}
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/parties';
router.get(`${path}/:partyId`, (0, ssi_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
try {
const partyId = request.params.partyId;
const party = yield context.agent.cmGetContact({ contactId: partyId });
response.statusCode = 200;
return response.send(party);
}
catch (error) {
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, error.message, error);
}
}));
}
function partyWriteEndpoint(router, context, opts) {
var _a;
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
console.log(`"partyWriteEndpoint" Endpoint is disabled`);
return;
}
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/parties';
router.post(path, (request, response) => __awaiter(this, void 0, void 0, function* () {
try {
const addParty = request.body;
const party = yield context.agent.cmAddContact(addParty);
response.statusCode = 201;
return response.send(party);
}
catch (error) {
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, error.message, error);
}
}));
}
function partyDeleteEndpoint(router, context, opts) {
var _a;
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
console.log(`"partyDeleteEndpoint" Endpoint is disabled`);
return;
}
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/parties';
router.delete(`${path}/:partyId`, (request, response) => __awaiter(this, void 0, void 0, function* () {
try {
const partyId = request.params.partyId;
const result = yield context.agent.cmRemoveContact({ contactId: partyId });
response.statusCode = 200;
return response.send(result);
}
catch (error) {
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, error.message, error);
}
}));
}
function partiesTypeReadEndpoint(router, context, opts) {
var _a;
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
console.log(`"partiesTypeReadEndpoint" Endpoint is disabled`);
return;
}
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/party-types';
router.get(path, (0, ssi_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
try {
// later we will add filter to this
const partyTypes = yield context.agent.cmGetContactTypes();
response.statusCode = 200;
return response.send(partyTypes);
}
catch (error) {
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, error.message, error);
}
}));
}
function partyTypeReadEndpoint(router, context, opts) {
var _a;
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
console.log(`"partyTypeReadEndpoint" Endpoint is disabled`);
return;
}
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/party-types';
router.get(`${path}/:partyTypeId`, (0, ssi_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
try {
const partyTypeId = request.params.partyTypeId;
const partyType = yield context.agent.cmGetContactType({ contactTypeId: partyTypeId });
response.statusCode = 200;
return response.send(partyType);
}
catch (error) {
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, error.message, error);
}
}));
}
function identitiesReadEndpoint(router, context, opts) {
var _a;
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
console.log(`"identitiesReadEndpoint" Endpoint is disabled`);
return;
}
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/identities';
router.get(path, (0, ssi_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
try {
// later we will add filter to this
const identities = yield context.agent.cmGetIdentities();
response.statusCode = 200;
return response.send(identities);
}
catch (error) {
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, error.message, error);
}
}));
}
function identityReadEndpoints(router, context, opts) {
var _a;
if ((opts === null || opts === void 0 ? void 0 : opts.enabled) === false) {
console.log(`"identityReadEndpoints" Endpoint is disabled`);
return;
}
const path = (_a = opts === null || opts === void 0 ? void 0 : opts.path) !== null && _a !== void 0 ? _a : '/identities';
router.get(`${path}/:identityId`, (0, ssi_express_support_1.checkAuth)(opts === null || opts === void 0 ? void 0 : opts.endpoint), (request, response) => __awaiter(this, void 0, void 0, function* () {
try {
const identityId = request.params.identityId;
const identity = yield context.agent.cmGetIdentity({ identityId });
response.statusCode = 200;
return response.send(identity);
}
catch (error) {
return (0, ssi_express_support_1.sendErrorResponse)(response, 500, error.message, error);
}
}));
}
//# sourceMappingURL=api-functions.js.map