UNPKG

adastra-ui-comment

Version:

Testing locally 1) in this file - `npm i` install dependencies - `npm run build` or `npm run tsc` to build your module 2) in childApp - in package.json under dependencies add ui-astra-assets with file:(relativePathToRepo) - "ui-astra-a

36 lines 2.02 kB
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 { DiscoverySdk } from '@adastradev/serverless-discovery-sdk'; import Cache from '@aws-amplify/cache'; import { call } from 'redux-saga/effects'; import moment from 'moment'; export default function lookupService(serviceName, retry) { return __awaiter(this, void 0, void 0, function* () { if (!retry && Cache.getItem(`${serviceName}-uri`)) { return Cache.getItem(`${serviceName}-uri`); } const sdk = new DiscoverySdk(process.env.REACT_APP_SERVICE_DISCOVERY_URL, process.env.REACT_APP_SERVICE_DISCOVERY_REGION, process.env.REACT_APP_SERVICE_DISCOVERY_STAGE, undefined, new Map(Object.entries(require('../../package.json')['cloudDependencies']))); const endpoints = yield sdk.lookupService(serviceName); Cache.setItem(`${serviceName}-uri`, endpoints[0], { priority: 1, expires: moment().add(5, 'm').valueOf(), }); return endpoints[0]; }); } export function* retrySagaWithNewService(serviceName, callBackSaga, callBackAction) { const pastEndpoint = Cache.getItem(`${serviceName}-uri`); const endpoint = yield call(lookupService, serviceName, true); if (pastEndpoint === endpoint) { throw 'Service URI has not changed'; } yield call(callBackSaga, callBackAction); } //# sourceMappingURL=lookupService.js.map