diff --git a/.github/workflows/sub-cloudrun-deploy.yml b/.github/workflows/sub-cloudrun-deploy.yml index b64ec8e4..625f2e81 100644 --- a/.github/workflows/sub-cloudrun-deploy.yml +++ b/.github/workflows/sub-cloudrun-deploy.yml @@ -118,6 +118,8 @@ jobs: SENTRY_ORG=${{ vars.SENTRY_ORG }}, SENTRY_PROJECT=${{ vars.SENTRY_PROJECT }}, SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }}, + BACKOFFICE_API_URL=${{ vars.BACKOFFICE_API_URL }}, + BACKOFFICE_API_KEY=${{ secrets.BACKOFFICE_API_KEY }}, flags: | --min-instances=${{ inputs.min_instances }} --max-instances=${{ inputs.max_instances }} diff --git a/env.d.ts b/env.d.ts index 13f6ee86..3beb7dbc 100644 --- a/env.d.ts +++ b/env.d.ts @@ -19,5 +19,7 @@ namespace NodeJS { NEXT_PUBLIC_SENTRY_DSN?: string; SENTRY_ORG?: string; SENTRY_PROJECT?: string; + BACKOFFICE_API_URL?: string; + BACKOFFICE_API_KEY?: string; } } diff --git a/package.json b/package.json index 97050289..441550b7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cuenta-unica-registry", "description": "Portal de registro de Cuenta Única", - "version": "v1.4.1", + "version": "v1.4.2", "private": false, "author": "OGTIC", "license": "MIT", diff --git a/src/actions/iam.action.ts b/src/actions/iam.action.ts index f36c5f10..c8f2b916 100644 --- a/src/actions/iam.action.ts +++ b/src/actions/iam.action.ts @@ -10,11 +10,39 @@ export async function findIamCitizen(cedula: string) { }), ); - const { data: identities } = await backend.listIdentities({ - credentialsIdentifier: cedula, - }); + const { data: identities } = await backend + .listIdentities({ + credentialsIdentifier: cedula, + }) + .catch(() => findAccountInBackoffice(cedula)); return { exists: identities.length !== 0, }; } + +async function findAccountInBackoffice(cedula: string) { + const url = new URL('v1/accounts', process.env.BACKOFFICE_API_URL); + url.searchParams.append('term', cedula); + + const resp = await fetch(url, withCredentials()); + + if (resp.ok) { + return resp + .json() + .then((data: Array) => + data.map((data) => ({ ...data, verifiable_addresses: [] })), + ) + .then((data) => ({ data })); + } + + await resp.json().then(console.error); + + return { data: [] }; +} + +type BackofficeAccount = { id: string; cedula: string }; + +const withCredentials = () => ({ + headers: { 'x-account-apikey': `${process.env.BACKOFFICE_API_KEY}` }, +});