@deuna/react-native-sdk 1.0.0 → 1.0.1

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.
Files changed (47) hide show
  1. package/lib/module/DeunaSDK.js +18 -11
  2. package/lib/module/DeunaSDK.js.map +1 -1
  3. package/lib/module/components/DeunaWebView.js +2 -1
  4. package/lib/module/components/DeunaWebView.js.map +1 -1
  5. package/lib/module/components/DeunaWidget.js +4 -2
  6. package/lib/module/components/DeunaWidget.js.map +1 -1
  7. package/lib/module/components/NewTabWebView.js +2 -1
  8. package/lib/module/components/NewTabWebView.js.map +1 -1
  9. package/lib/module/controllers/BaseWebViewController.js +55 -13
  10. package/lib/module/controllers/BaseWebViewController.js.map +1 -1
  11. package/lib/module/controllers/OpenInNewTabController.js +21 -5
  12. package/lib/module/controllers/OpenInNewTabController.js.map +1 -1
  13. package/lib/module/types/helpers/buildElementsLink.js +71 -54
  14. package/lib/module/types/helpers/buildElementsLink.js.map +1 -1
  15. package/lib/module/types/helpers/buildNextActionLink.js +7 -2
  16. package/lib/module/types/helpers/buildNextActionLink.js.map +1 -1
  17. package/lib/module/types/helpers/buildPaymentLink.js +1 -2
  18. package/lib/module/types/helpers/buildPaymentLink.js.map +1 -1
  19. package/lib/module/types/helpers/buildVoucherLink.js +1 -2
  20. package/lib/module/types/helpers/buildVoucherLink.js.map +1 -1
  21. package/lib/typescript/deuna-sdk-react-native/src/DeunaSDK.d.ts +1 -0
  22. package/lib/typescript/deuna-sdk-react-native/src/DeunaSDK.d.ts.map +1 -1
  23. package/lib/typescript/deuna-sdk-react-native/src/components/DeunaWebView.d.ts +1 -0
  24. package/lib/typescript/deuna-sdk-react-native/src/components/DeunaWebView.d.ts.map +1 -1
  25. package/lib/typescript/deuna-sdk-react-native/src/components/DeunaWidget.d.ts.map +1 -1
  26. package/lib/typescript/deuna-sdk-react-native/src/components/NewTabWebView.d.ts.map +1 -1
  27. package/lib/typescript/deuna-sdk-react-native/src/controllers/BaseWebViewController.d.ts +24 -1
  28. package/lib/typescript/deuna-sdk-react-native/src/controllers/BaseWebViewController.d.ts.map +1 -1
  29. package/lib/typescript/deuna-sdk-react-native/src/controllers/OpenInNewTabController.d.ts +1 -0
  30. package/lib/typescript/deuna-sdk-react-native/src/controllers/OpenInNewTabController.d.ts.map +1 -1
  31. package/lib/typescript/deuna-sdk-react-native/src/types/base.d.ts +2 -2
  32. package/lib/typescript/deuna-sdk-react-native/src/types/helpers/buildElementsLink.d.ts +6 -1
  33. package/lib/typescript/deuna-sdk-react-native/src/types/helpers/buildElementsLink.d.ts.map +1 -1
  34. package/lib/typescript/deuna-sdk-react-native/src/types/helpers/buildNextActionLink.d.ts.map +1 -1
  35. package/lib/typescript/deuna-sdk-react-native/src/types/helpers/buildPaymentLink.d.ts.map +1 -1
  36. package/lib/typescript/deuna-sdk-react-native/src/types/helpers/buildVoucherLink.d.ts.map +1 -1
  37. package/package.json +1 -1
  38. package/src/DeunaSDK.ts +17 -11
  39. package/src/components/DeunaWebView.tsx +2 -0
  40. package/src/components/DeunaWidget.tsx +7 -0
  41. package/src/components/NewTabWebView.tsx +3 -0
  42. package/src/controllers/BaseWebViewController.ts +70 -13
  43. package/src/controllers/OpenInNewTabController.ts +26 -8
  44. package/src/types/helpers/buildElementsLink.ts +102 -66
  45. package/src/types/helpers/buildNextActionLink.ts +8 -3
  46. package/src/types/helpers/buildPaymentLink.ts +1 -3
  47. package/src/types/helpers/buildVoucherLink.ts +1 -3
@@ -1,87 +1,123 @@
1
- import { Environment } from "../base";
2
- import { hasKey } from "../utils/hasKey";
3
- import { getIntegrationType, UrlConfig } from "./urlConfig";
4
-
5
- const urls: Record<Environment, string> = {
6
- production: "https://elements.deuna.io",
7
- sandbox: "https://elements.sandbox.deuna.io",
8
- staging: "https://elements.stg.deuna.io",
9
- develop: "https://elements.dev.deuna.io",
10
- };
11
-
12
- const pathsMapper = {
13
- click_to_pay: "/click_to_pay",
14
- vault: "/vault",
1
+ import { Environment } from '../base';
2
+ import { hasKey } from '../utils/hasKey';
3
+ import { getIntegrationType, UrlConfig } from './urlConfig';
4
+
5
+ const ELEMENTS_URLS: Record<Environment, string> = {
6
+ production: 'https://elements.deuna.io',
7
+ sandbox: 'https://elements.sandbox.deuna.io',
8
+ staging: 'https://elements.stg.deuna.io',
9
+ develop: 'https://elements.dev.deuna.io',
10
+ } as const;
11
+
12
+ const WIDGET_PATHS = {
13
+ click_to_pay: '/click_to_pay',
14
+ vault: '/vault',
15
+ } as const;
16
+
17
+ type WidgetPath = keyof typeof WIDGET_PATHS;
18
+
19
+ interface SearchParams {
20
+ publicApiKey: string;
21
+ orderToken: string;
22
+ email: string;
23
+ firstName: string;
24
+ lastName: string;
25
+ int: string;
26
+ language: string;
27
+ cssFile?: string;
28
+ userToken?: string;
29
+ showSavedCardsFlow?: string;
30
+ showDefaultCardFlow?: string;
31
+ }
32
+
33
+ /**
34
+ * Builds the base URL for the Elements widget based on environment and domain configuration
35
+ */
36
+ const buildBaseUrl = (config: UrlConfig): string => {
37
+ if (config.domain) {
38
+ return config.domain;
39
+ }
40
+ return config.env ? ELEMENTS_URLS[config.env] : ELEMENTS_URLS.production;
15
41
  };
16
42
 
17
- export const buildElementsLink = (config: UrlConfig): string => {
18
- const { env, orderToken, userInfo, userToken, widgetExperience, types } =
43
+ /**
44
+ * Builds the search parameters for the Elements widget URL
45
+ */
46
+ const buildSearchParams = (config: UrlConfig): URLSearchParams => {
47
+ const { userInfo, userToken, widgetExperience, styleFile, mode, language } =
19
48
  config;
20
49
 
21
- let baseUrl = urls.production;
50
+ const searchParams: SearchParams = {
51
+ publicApiKey: config.publicApiKey,
52
+ orderToken: config.orderToken,
53
+ email: userInfo?.email || '',
54
+ firstName: userInfo?.firstName || '',
55
+ lastName: userInfo?.lastName || '',
56
+ int: getIntegrationType(mode),
57
+ language,
58
+ };
22
59
 
23
- if (env) {
24
- baseUrl = urls[env];
60
+ if (styleFile) {
61
+ searchParams.cssFile = styleFile;
25
62
  }
26
63
 
27
- if (config.domain) {
28
- baseUrl = config.domain;
64
+ if (userToken) {
65
+ searchParams.userToken = userToken;
29
66
  }
30
67
 
31
- const url = new URL(baseUrl);
32
-
33
- const publicApiKey = config.publicApiKey;
34
- const firstName = userInfo?.firstName || "";
35
- const lastName = userInfo?.lastName || "";
36
- const email = userInfo?.email || "";
37
-
38
- const searchParams = new URLSearchParams({
39
- publicApiKey,
40
- orderToken,
41
- email,
42
- firstName,
43
- lastName,
44
- ...(config.styleFile ? { cssFile: config.styleFile } : {}),
45
- int: getIntegrationType(config.mode),
46
- ...(userToken ? { userToken } : {}),
47
- ...(widgetExperience?.userExperience?.showSavedCardsFlow
48
- ? {
49
- showSavedCardsFlow: String(
50
- widgetExperience?.userExperience?.showSavedCardsFlow
51
- ),
52
- }
53
- : {}),
54
- ...(widgetExperience?.userExperience?.defaultCardFlow
55
- ? {
56
- showDefaultCardFlow: String(
57
- widgetExperience?.userExperience?.defaultCardFlow
58
- ),
59
- }
60
- : {}),
61
- language: config.language,
62
- });
68
+ if (widgetExperience?.userExperience?.showSavedCardsFlow) {
69
+ searchParams.showSavedCardsFlow = String(
70
+ widgetExperience.userExperience.showSavedCardsFlow
71
+ );
72
+ }
73
+
74
+ if (widgetExperience?.userExperience?.defaultCardFlow) {
75
+ searchParams.showDefaultCardFlow = String(
76
+ widgetExperience.userExperience.defaultCardFlow
77
+ );
78
+ }
79
+
80
+ return new URLSearchParams(searchParams as unknown as Record<string, string>);
81
+ };
82
+
83
+ /**
84
+ * Determines the widget path based on the provided types
85
+ */
86
+ const getWidgetPath = (types?: Array<{ name: string }>): string => {
87
+ if (types && types.length > 0) {
88
+ const firstPath = types[0].name as WidgetPath;
89
+ return hasKey(WIDGET_PATHS, firstPath)
90
+ ? WIDGET_PATHS[firstPath]
91
+ : WIDGET_PATHS.vault;
92
+ }
93
+ return WIDGET_PATHS.vault;
94
+ };
95
+
96
+ /**
97
+ * Builds a complete Elements widget URL with all necessary parameters
98
+ * @param config - Configuration object for building the Elements URL
99
+ * @returns The complete Elements widget URL as a string
100
+ */
101
+ export const buildElementsLink = (config: UrlConfig): string => {
102
+ const baseUrl = buildBaseUrl(config);
103
+ const searchParams = buildSearchParams(config);
63
104
 
64
105
  const xpropsB64 = {
65
106
  id: config.id,
66
107
  behavior: config.behavior || {},
67
108
  };
68
109
 
69
- const getWidgetPath = () => {
70
- if (types && types.length > 0) {
71
- const firstPath = types[0]!.name;
72
-
73
- if (hasKey(pathsMapper, firstPath)) {
74
- return pathsMapper[firstPath];
75
- }
76
- }
110
+ searchParams.append('xpropsB64', btoa(JSON.stringify(xpropsB64)));
77
111
 
78
- return pathsMapper.vault;
79
- };
112
+ const widgetPath = getWidgetPath(config.types);
113
+ const normalizedPath = widgetPath.startsWith('/')
114
+ ? widgetPath
115
+ : `/${widgetPath}`;
80
116
 
81
- searchParams.append("xpropsB64", btoa(JSON.stringify(xpropsB64)));
82
-
83
- url.pathname = getWidgetPath();
117
+ const url = new URL(normalizedPath, baseUrl);
84
118
  url.search = searchParams.toString();
85
119
 
120
+ console.log('url', url.toString());
121
+
86
122
  return url.toString();
87
123
  };
@@ -21,21 +21,26 @@ export const buildNextActionLink = (config: UrlConfig): string => {
21
21
  baseUrl = urls[env];
22
22
  }
23
23
 
24
+ const xpropsB64 = {
25
+ id: config.id
26
+ };
27
+
24
28
  const searchParams = new URLSearchParams({
25
29
  mode: "widget",
26
30
  int: getIntegrationType(config.mode),
27
31
  language: config.language,
28
32
  });
29
33
 
34
+ //encode to base64
35
+ searchParams.append("xpropsB64", btoa(JSON.stringify(xpropsB64)));
36
+
30
37
  configToQueryParams(config, searchParams);
31
38
 
32
39
  if (config.domain) {
33
40
  baseUrl = config.domain;
34
41
  }
35
42
 
36
- const url = new URL(baseUrl);
37
-
38
- url.pathname = `/next-action-purchase/${orderToken}`;
43
+ const url = new URL(`/next-action-purchase/${orderToken}`, baseUrl);
39
44
  url.search = searchParams.toString();
40
45
 
41
46
  return url.toString();
@@ -54,9 +54,7 @@ export const buildPaymentLink = (config: UrlConfig): string => {
54
54
  //encode to base64
55
55
  searchParams.append("xpropsB64", btoa(JSON.stringify(xpropsB64)));
56
56
 
57
- const url = new URL(baseUrl);
58
-
59
- url.pathname = `/now/${orderToken}`;
57
+ const url = new URL(`/now/${orderToken}`, baseUrl);
60
58
  url.search = searchParams.toString();
61
59
 
62
60
  return url.toString();
@@ -44,9 +44,7 @@ export const buildVoucherLink = (config: UrlConfig): string => {
44
44
  //encode to base64
45
45
  searchParams.append("xpropsB64", btoa(JSON.stringify(xpropsB64)));
46
46
 
47
- const url = new URL(baseUrl);
48
-
49
- url.pathname = `/voucher`;
47
+ const url = new URL("/voucher", baseUrl);
50
48
  url.search = searchParams.toString();
51
49
 
52
50
  return url.toString();