@tap-payments/connect-v2 0.0.21-test → 0.0.23-test

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
- export declare const CONNECT_CONFIG_URL = "https://68b564fae5dc090291aeddd7.mockapi.io/api/config";
1
+ export declare const CONNECT_CONFIG_URL: string;
2
+ export declare const CONNECT_CONFIG_URL_SA: string;
3
+ export declare const CONNECT_CONFIG_URL_SA_DR: string;
2
4
  export declare const CONNECT_IFRAME_ID = "tap-connect-sdk-iframe";
3
5
  export declare const CONNECT_ORIGIN: string;
@@ -1,6 +1,7 @@
1
- // TODO: Add URL (should it be env variables based on the enviornment?)
2
1
  // Added mock up api until api ready from Backend
3
- export const CONNECT_CONFIG_URL = 'https://68b564fae5dc090291aeddd7.mockapi.io/api/config';
2
+ export const CONNECT_CONFIG_URL = import.meta.env.VITE_CONNECT_CONFIG_URL;
3
+ export const CONNECT_CONFIG_URL_SA = import.meta.env.VITE_CONNECT_CONFIG_URL_SA;
4
+ export const CONNECT_CONFIG_URL_SA_DR = import.meta.env.VITE_CONNECT_CONFIG_URL_SA_DR;
4
5
  export const CONNECT_IFRAME_ID = 'tap-connect-sdk-iframe';
5
6
  // TODO: import.meta.env works only in vite build when do npm publish does not work find another way
6
7
  export const CONNECT_ORIGIN = import.meta.env.VITE_CONNECT_ORIGIN || 'https://connect.alpha.tap.company';
@@ -2,16 +2,17 @@ import * as React from 'react';
2
2
  import { WebErrorHandler } from '@tap-payments/web-error-handing';
3
3
  import { ConnectMode, SearchParams } from '../types';
4
4
  import { useConnectContext } from '../context';
5
- import { CONNECT_CONFIG_URL, CONNECT_ORIGIN } from '../constants';
5
+ import { CONNECT_ORIGIN } from '../constants';
6
+ import { getBaseUrl } from '../utils';
6
7
  const useConfig = () => {
7
8
  const [connectLink, setConnectLink] = React.useState('');
8
- const { onError, onLoadingHandler, ...config } = useConnectContext();
9
+ const { onError, onLoadingHandler, loginMode, region, ...config } = useConnectContext();
9
10
  const generateConfig = async () => {
10
11
  onLoadingHandler(true);
11
12
  try {
12
13
  // TODO: Do we need further headers/data for the iframe scenario
13
14
  // TODO: Add proper type for the response
14
- const response = await fetch(CONNECT_CONFIG_URL, {
15
+ const response = await fetch(getBaseUrl(region), {
15
16
  method: 'POST',
16
17
  headers: {
17
18
  'Content-Type': 'application/json',
@@ -30,7 +31,8 @@ const useConfig = () => {
30
31
  if (config?.language)
31
32
  params.append(SearchParams.LANGUAGE, config.language);
32
33
  params.append(SearchParams.PROFILE_TOKEN, data.id);
33
- data.redirect_url = `${CONNECT_ORIGIN}?${params.toString()}`;
34
+ const baseUrl = loginMode ? `${CONNECT_ORIGIN}/auth` : CONNECT_ORIGIN;
35
+ data.redirect_url = `${baseUrl}?${params.toString()}`;
34
36
  }
35
37
  if (config.mode !== ConnectMode.PAGE)
36
38
  return setConnectLink(data.redirect_url);
@@ -43,7 +43,6 @@ export type ConnectProps = {
43
43
  businessCountryCode?: string;
44
44
  scope: ConnectScope;
45
45
  showBoard?: boolean;
46
- leadId?: string;
47
46
  platforms?: Array<string>;
48
47
  paymentProvider?: ConnectPaymentProvider;
49
48
  features?: {
@@ -65,4 +64,6 @@ export type ConnectProps = {
65
64
  userId?: string;
66
65
  userType?: string;
67
66
  operationType?: ConnectPasswordOperationType;
67
+ loginMode?: boolean;
68
+ region?: string;
68
69
  };
@@ -0,0 +1,2 @@
1
+ export * from './dom';
2
+ export * from './region';
@@ -0,0 +1,2 @@
1
+ export * from './dom';
2
+ export * from './region';
@@ -0,0 +1 @@
1
+ export declare const getBaseUrl: (region?: string | undefined) => string;
@@ -0,0 +1,16 @@
1
+ import { CONNECT_CONFIG_URL, CONNECT_CONFIG_URL_SA, CONNECT_CONFIG_URL_SA_DR } from '../constants';
2
+ const isSA = (country) => {
3
+ if (!country)
4
+ return false;
5
+ return ['sa', 'sau'].includes(country.toLowerCase());
6
+ };
7
+ const isDisasterRecoveryEnv = (type) => type === 'dr';
8
+ export const getBaseUrl = (region = '') => {
9
+ const [country, envType] = region.split('-');
10
+ if (isSA(country)) {
11
+ return isDisasterRecoveryEnv(envType) ? CONNECT_CONFIG_URL_SA_DR : CONNECT_CONFIG_URL_SA;
12
+ }
13
+ else {
14
+ return CONNECT_CONFIG_URL;
15
+ }
16
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tap-payments/connect-v2",
3
3
  "private": false,
4
- "version": "0.0.21-test",
4
+ "version": "0.0.23-test",
5
5
  "type": "module",
6
6
  "main": "build/index.js",
7
7
  "module": "build/index.js",
@@ -15,6 +15,9 @@
15
15
  "dev": "vite",
16
16
  "tsc:alias": "tsc-alias -p tsconfig.app.json",
17
17
  "build": "yarn clean && tsc -b && yarn tsc:alias && vite build",
18
+ "build:production": "npm run build -- --mode production",
19
+ "build:beta": "npm run build -- --mode beta",
20
+ "build:development": "npm run build -- --mode development",
18
21
  "lint": "eslint .",
19
22
  "lint:fix": "eslint . --fix",
20
23
  "preview": "vite preview",
File without changes
File without changes