From 7ce275284e9aae11a182d69e92785d4ce4a11833 Mon Sep 17 00:00:00 2001 From: Swati Goel Date: Fri, 8 Sep 2023 13:52:43 +0530 Subject: [PATCH 1/5] feat(INJI-360): Add esignet host as env variable and use in QR login flow. --- .env | 6 +++++- machines/QrLoginMachine.ts | 14 +++++++++----- machines/app.ts | 4 ++-- shared/constants.ts | 6 ++++-- shared/request.ts | 11 ++++++----- types/react-native-dotenv/index.d.ts | 5 +++++ 6 files changed, 31 insertions(+), 15 deletions(-) diff --git a/.env b/.env index 6f09c5b55d..e0f07e3439 100644 --- a/.env +++ b/.env @@ -1,9 +1,13 @@ # after making changes to the env file, ensure to start the bundler (or the project) with a --reset-cache # eg . npm build android:newlogic --reset-cache -MIMOTO_HOST=https://api.qa-inji.mosip.net #MIMOTO_HOST=http://mock.mimoto.newlogic.dev +MIMOTO_HOST=https://api.qa-inji.mosip.net + +ESIGNET_HOST=https://api.qa-inji.mosip.net + GOOGLE_NEARBY_MESSAGES_API_KEY= + #Application Theme can be ( orange | purple ) APPLICATION_THEME=orange diff --git a/machines/QrLoginMachine.ts b/machines/QrLoginMachine.ts index 42dd9a8e90..d020b82bb1 100644 --- a/machines/QrLoginMachine.ts +++ b/machines/QrLoginMachine.ts @@ -8,7 +8,7 @@ import { } from 'xstate'; import { createModel } from 'xstate/lib/model'; import { AppServices } from '../shared/GlobalContext'; -import { MY_VCS_STORE_KEY } from '../shared/constants'; +import { MY_VCS_STORE_KEY, ESIGNET_BASE_URL } from '../shared/constants'; import { StoreEvents } from './store'; import { linkTransactionResponse, VC } from '../types/vc'; import { request } from '../shared/request'; @@ -349,7 +349,8 @@ export const qrLoginMachine = request: { linkCode: context.linkCode, }, - } + }, + ESIGNET_BASE_URL ); return response.response; }, @@ -386,7 +387,8 @@ export const qrLoginMachine = }, ], }, - } + }, + ESIGNET_BASE_URL ); return response.response.linkedTransactionId; }, @@ -421,7 +423,8 @@ export const qrLoginMachine = }, ], }, - } + }, + ESIGNET_BASE_URL ); var linkedTrnId = response.response.linkedTransactionId; @@ -437,7 +440,8 @@ export const qrLoginMachine = ), permittedAuthorizeScopes: context.authorizeScopes, }, - } + }, + ESIGNET_BASE_URL ); console.log(resp.response.linkedTransactionId); }, diff --git a/machines/app.ts b/machines/app.ts index cd35a0e351..337af37b5f 100644 --- a/machines/app.ts +++ b/machines/app.ts @@ -24,8 +24,8 @@ import { request } from '../shared/request'; import { changeCrendetialRegistry, SETTINGS_STORE_KEY, + MIMOTO_BASE_URL } from '../shared/constants'; -import { MIMOTO_HOST } from 'react-native-dotenv'; const model = createModel( { @@ -328,7 +328,7 @@ export const appMachine = model.createMachine( loadCredentialRegistryInConstants: (_context, event) => { changeCrendetialRegistry( !event.response?.credentialRegistry - ? MIMOTO_HOST + ? MIMOTO_BASE_URL : event.response?.credentialRegistry ); }, diff --git a/shared/constants.ts b/shared/constants.ts index f60f8ddc37..47db1b5515 100644 --- a/shared/constants.ts +++ b/shared/constants.ts @@ -2,13 +2,15 @@ import { Platform } from 'react-native'; import { VC } from '../types/vc'; import { MIMOTO_HOST, + ESIGNET_HOST, GOOGLE_NEARBY_MESSAGES_API_KEY, } from 'react-native-dotenv'; import { Argon2iConfig } from './commonUtil'; -export let HOST = MIMOTO_HOST; +export let MIMOTO_BASE_URL = MIMOTO_HOST; +export const ESIGNET_BASE_URL = ESIGNET_HOST; -export const changeCrendetialRegistry = (host) => (HOST = host); +export const changeCrendetialRegistry = (host) => (MIMOTO_BASE_URL = host); export const MY_VCS_STORE_KEY = 'myVCs'; diff --git a/shared/request.ts b/shared/request.ts index 48a5fe50bf..9cfa8da8f2 100644 --- a/shared/request.ts +++ b/shared/request.ts @@ -1,5 +1,5 @@ import { DecodedCredential, VerifiableCredential } from '../types/vc'; -import { HOST } from './constants'; +import { MIMOTO_BASE_URL } from './constants'; export class BackendResponseError extends Error { constructor(name: string, message: string) { @@ -23,14 +23,15 @@ export class AppId { export async function request( method: 'GET' | 'POST' | 'PATCH', path: `/${string}`, - body?: Record + body?: Record, + host= MIMOTO_BASE_URL ) { const headers = { 'Content-Type': 'application/json', }; if (path.includes('residentmobileapp')) headers['X-AppId'] = AppId.getValue(); - const response = await fetch(HOST + path, { + const response = await fetch(host + path, { method, headers, body: JSON.stringify(body), @@ -39,7 +40,7 @@ export async function request( const jsonResponse = await response.json(); if (response.status >= 400) { - let backendUrl = HOST + path; + let backendUrl = host + path; let errorMessage = jsonResponse.message || jsonResponse.error; console.error( 'The backend API ' + @@ -51,7 +52,7 @@ export async function request( } if (jsonResponse.errors && jsonResponse.errors.length) { - let backendUrl = HOST + path; + let backendUrl = host + path; const { errorCode, errorMessage } = jsonResponse.errors.shift(); console.error( 'The backend API ' + diff --git a/types/react-native-dotenv/index.d.ts b/types/react-native-dotenv/index.d.ts index 1396640f93..6b452f3420 100644 --- a/types/react-native-dotenv/index.d.ts +++ b/types/react-native-dotenv/index.d.ts @@ -4,6 +4,11 @@ declare module 'react-native-dotenv' { */ export const MIMOTO_HOST: string; + /** + * URL for the Esignet backend server + */ + export const ESIGNET_HOST: string; + /** * API key to use Google Nearby Messages API */ From bd4e5324bd0f7df5d17e4f63cddeb1a15048044e Mon Sep 17 00:00:00 2001 From: Swati Goel Date: Sun, 10 Sep 2023 23:19:17 +0530 Subject: [PATCH 2/5] feat(INJI-360): Fix compile error. --- machines/settings.ts | 4 ++-- machines/vcItem.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/machines/settings.ts b/machines/settings.ts index 8aec51ecc3..cbcfeddad0 100644 --- a/machines/settings.ts +++ b/machines/settings.ts @@ -4,7 +4,7 @@ import { AppServices } from '../shared/GlobalContext'; import { APP_ID_DICTIONARY, APP_ID_LENGTH, - HOST, + MIMOTO_BASE_URL, isIOS, SETTINGS_STORE_KEY, } from '../shared/constants'; @@ -27,7 +27,7 @@ const model = createModel( plural: 'Cards', } as VCLabel, isBiometricUnlockEnabled: false, - credentialRegistry: HOST, + credentialRegistry: MIMOTO_BASE_URL, appId: null, hasUserShownWithHardwareKeystoreNotExists: false, credentialRegistryResponse: '' as string, diff --git a/machines/vcItem.ts b/machines/vcItem.ts index fa4d46e31c..b120defdbd 100644 --- a/machines/vcItem.ts +++ b/machines/vcItem.ts @@ -1,7 +1,7 @@ import { assign, ErrorPlatformEvent, EventFrom, send, StateFrom } from 'xstate'; import { createModel } from 'xstate/lib/model'; import { - HOST, + MIMOTO_BASE_URL, MY_VCS_STORE_KEY, VC_ITEM_STORE_KEY, VC_ITEM_STORE_KEY_AFTER_DOWNLOAD, @@ -913,7 +913,7 @@ export const vcItemMachine = storeContext: send( (context) => { const { serviceRefs, ...data } = context; - data.credentialRegistry = HOST; + data.credentialRegistry = MIMOTO_BASE_URL; return StoreEvents.SET(VC_ITEM_STORE_KEY(context), data); }, { From 3e1032e8942499be5873b7fac5fc630b4ac4e006 Mon Sep 17 00:00:00 2001 From: Swati Goel Date: Tue, 12 Sep 2023 23:15:37 +0530 Subject: [PATCH 3/5] chore(INJI-360): support esignet and mimoto base url in workflows for Android and iOS --- .github/workflows/android-beta-build.yml | 15 +++++++++++---- .github/workflows/android-internal-build.yml | 15 +++++++++++---- .github/workflows/ios-build.yml | 12 +++++++++--- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/.github/workflows/android-beta-build.yml b/.github/workflows/android-beta-build.yml index 4747fcd60c..21844566c1 100644 --- a/.github/workflows/android-beta-build.yml +++ b/.github/workflows/android-beta-build.yml @@ -1,7 +1,8 @@ name: Android Beta Build env: - backendServiceDefaultUrl: https://api.sandbox.mosip.net + mimotoBackendServiceDefaultUrl: https://api.sandbox.mosip.net + esignetBackendServiceDefaultUrl: https://api.sandbox.mosip.net on: workflow_dispatch: @@ -21,8 +22,13 @@ on: required: true default: False type: string - backendServiceUrl: - description: 'Backend service URL' + mimotoBackendServiceUrl: + description: 'Mimoto backend service URL' + required: true + default: 'https://api.sandbox.mosip.net' + type: string + esignetBackendServiceUrl: + description: 'Esignet backend service URL' required: true default: 'https://api.sandbox.mosip.net' type: string @@ -133,7 +139,8 @@ jobs: cd android/scripts ./beta-build.sh env: - MIMOTO_HOST: ${{ github.event.inputs.backendServiceUrl }} + MIMOTO_HOST: ${{ github.event.inputs.mimotoBackendServiceUrl }} + ESIGNET_HOST: ${{ github.event.inputs.esignetBackendServiceUrl }} APPLICATION_THEME: ${{ github.event.inputs.theme }} RELEASE_KEYSTORE_ALIAS: androidreleasekey RELEASE_KEYSTORE_PASSWORD: '${{secrets.INJI_ANDROID_RELEASE_STOREPASS}}' diff --git a/.github/workflows/android-internal-build.yml b/.github/workflows/android-internal-build.yml index 9e0622e86d..aafb3ce87c 100644 --- a/.github/workflows/android-internal-build.yml +++ b/.github/workflows/android-internal-build.yml @@ -1,13 +1,19 @@ name: Android Internal Build env: - backendServiceDefaultUrl: https://api.sandbox.mosip.net + mimotoBackendServiceDefaultUrl: https://api.sandbox.mosip.net + esignetBackendServiceDefaultUrl: https://api.sandbox.mosip.net on: workflow_dispatch: inputs: - backendServiceUrl: - description: 'Backend service URL' + mimotoBackendServiceUrl: + description: 'Mimoto backend service URL' + required: true + default: 'https://api.sandbox.mosip.net' + type: string + esignetBackendServiceUrl: + description: 'Esignet backend service URL' required: true default: 'https://api.sandbox.mosip.net' type: string @@ -115,7 +121,8 @@ jobs: cd android/scripts ./internal-build.sh env: - MIMOTO_HOST: ${{ github.event.inputs.backendServiceUrl }} + MIMOTO_HOST: ${{ github.event.inputs.mimotoBackendServiceUrl }} + ESIGNET_HOST: ${{ github.event.inputs.esignetBackendServiceUrl }} APPLICATION_THEME: ${{ github.event.inputs.theme }} RELEASE_KEYSTORE_ALIAS: androidreleasekey RELEASE_KEYSTORE_PASSWORD: '${{secrets.INJI_ANDROID_RELEASE_STOREPASS}}' diff --git a/.github/workflows/ios-build.yml b/.github/workflows/ios-build.yml index 2a955c5df6..022eb8d0c0 100644 --- a/.github/workflows/ios-build.yml +++ b/.github/workflows/ios-build.yml @@ -3,8 +3,13 @@ name: Inji iOS build on: workflow_dispatch: inputs: - backendServiceUrl: - description: 'Backend service URL' + mimotoBackendServiceUrl: + description: 'Mimoto backend service URL' + required: true + default: 'https://api.sandbox.mosip.net' + type: string + esignetBackendServiceUrl: + description: 'Esignet backend service URL' required: true default: 'https://api.sandbox.mosip.net' type: string @@ -83,6 +88,7 @@ jobs: MATCH_PASSWORD: '${{ secrets.INJI_IOS_MATCH_PASSWORD }}' APPLICATION_THEME: ${{ github.event.inputs.theme }} CREDENTIAL_REGISTRY_EDIT: ${{ github.event.inputs.registry_edit }} - MIMOTO_HOST: ${{ github.event.inputs.backendServiceUrl }} + MIMOTO_HOST: ${{ github.event.inputs.mimotoBackendServiceUrl }} + ESIGNET_HOST: ${{ github.event.inputs.esignetBackendServiceUrl }} TESTFLIGHT_INTERNAL_TESTERS_GROUP: ${{ github.event.inputs.internal-testers }} TESTFLIGHT_BETA_APP_DESCRIPTION: ${{ github.event.inputs.buildDescription }} From dc06c685ea847f01838da469a64a69d9d92589dc Mon Sep 17 00:00:00 2001 From: Swati Goel Date: Wed, 13 Sep 2023 10:02:05 +0530 Subject: [PATCH 4/5] chore(INJI-360): add ESIGNET_HOST in Fastfile for android. --- android/fastlane/Fastfile | 1 + 1 file changed, 1 insertion(+) diff --git a/android/fastlane/Fastfile b/android/fastlane/Fastfile index 6b3ebfadc6..44489aba64 100644 --- a/android/fastlane/Fastfile +++ b/android/fastlane/Fastfile @@ -1,6 +1,7 @@ default_platform(:android) MIMOTO_HOST = ENV["MIMOTO_HOST"] +ESIGNET_HOST = ENV["ESIGNET_HOST"] APPLICATION_THEME = ENV["APPLICATION_THEME"] RELEASE_KEYSTORE_ALIAS = ENV["RELEASE_KEYSTORE_ALIAS"] RELEASE_KEYSTORE_PASSWORD = ENV["RELEASE_KEYSTORE_PASSWORD"] From 0aa474e0bba1a946a5491cf1cdb87a6c1a03755e Mon Sep 17 00:00:00 2001 From: Swati Goel Date: Wed, 13 Sep 2023 11:01:39 +0530 Subject: [PATCH 5/5] chore(INJI-360): remove unnecessary env variables from ios build workflow. --- .github/workflows/ios-build.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ios-build.yml b/.github/workflows/ios-build.yml index 022eb8d0c0..76d56181c5 100644 --- a/.github/workflows/ios-build.yml +++ b/.github/workflows/ios-build.yml @@ -87,8 +87,5 @@ jobs: SLACK_URL: '${{ secrets.SLACK_WEBHOOK_DEVOPS }}' MATCH_PASSWORD: '${{ secrets.INJI_IOS_MATCH_PASSWORD }}' APPLICATION_THEME: ${{ github.event.inputs.theme }} - CREDENTIAL_REGISTRY_EDIT: ${{ github.event.inputs.registry_edit }} - MIMOTO_HOST: ${{ github.event.inputs.mimotoBackendServiceUrl }} - ESIGNET_HOST: ${{ github.event.inputs.esignetBackendServiceUrl }} TESTFLIGHT_INTERNAL_TESTERS_GROUP: ${{ github.event.inputs.internal-testers }} TESTFLIGHT_BETA_APP_DESCRIPTION: ${{ github.event.inputs.buildDescription }}