@@ -4,13 +4,19 @@ import { generateConfigs, mergeConfigs } from '../helper';
44import { MY_ACCOUNT_DOMAINS , VAULT_DOMAINS , LINK_KIT_DOMAINS } from '../server-paths' ;
55import {
66 StoredOptions ,
7- ServiceId ,
8- ConnectionSettingType ,
9- ServiceConnectionType ,
10- ServicesListType ,
7+ VaultViewConnectionSetting ,
8+ VaultViewServiceConnection ,
9+ VaultViewServiceList ,
1110 OpenServiceUrlOptions ,
12- VaultOpenServiceOptions ,
13- MyAccountOpenServiceOptions
11+ VaultServiceTypes ,
12+ MyAccountServiceTypes ,
13+ LinkKitOpenServiceUrlOptions ,
14+ MyAccountOpenServiceUrlOptions ,
15+ ConfigsOptionsWithoutIsNewTab ,
16+ VaultOpenServiceUrlViewServiceList ,
17+ VaultOpenServiceUrlViewServiceConnection ,
18+ VaultOpenServiceUrlViewConnectionSetting ,
19+ VaultOpenServiceUrlViewCustomerSupport
1420} from '../typings' ;
1521
1622interface QueryData {
@@ -23,19 +29,53 @@ interface QueryData {
2329
2430export default function openServiceUrl (
2531 storedOptions : StoredOptions ,
26- serviceId : ServiceId ,
32+ serviceId : 'link-kit' ,
33+ options ?: LinkKitOpenServiceUrlOptions
34+ ) : string ;
35+ export default function openServiceUrl (
36+ storedOptions : StoredOptions ,
37+ serviceId : 'myaccount' ,
38+ options ?: MyAccountOpenServiceUrlOptions
39+ ) : string ;
40+ export default function openServiceUrl (
41+ storedOptions : StoredOptions ,
42+ serviceId : 'vault' ,
43+ options ?: ConfigsOptionsWithoutIsNewTab
44+ ) : string ;
45+ export default function openServiceUrl (
46+ storedOptions : StoredOptions ,
47+ serviceId : 'vault' ,
48+ options ?: VaultOpenServiceUrlViewServiceList
49+ ) : string ;
50+ export default function openServiceUrl (
51+ storedOptions : StoredOptions ,
52+ serviceId : 'vault' ,
53+ options ?: VaultOpenServiceUrlViewServiceConnection
54+ ) : string ;
55+ export default function openServiceUrl (
56+ storedOptions : StoredOptions ,
57+ serviceId : 'vault' ,
58+ options ?: VaultOpenServiceUrlViewConnectionSetting
59+ ) : string ;
60+ export default function openServiceUrl (
61+ storedOptions : StoredOptions ,
62+ serviceId : 'vault' ,
63+ options ?: VaultOpenServiceUrlViewCustomerSupport
64+ ) : string ;
65+ export default function openServiceUrl (
66+ storedOptions : StoredOptions ,
67+ serviceId : 'myaccount' | 'vault' | 'link-kit' ,
2768 options : OpenServiceUrlOptions = { }
2869) : string {
2970 const { clientId, mode, cobrandClientId, locale, samlSubjectId } = storedOptions ;
30- const { view = '' , ...rest } = options as VaultOpenServiceOptions | MyAccountOpenServiceOptions ;
3171
3272 const getQueryValue = ( needStringify = true ) : string | QueryData => {
3373 const query : QueryData = {
3474 client_id : clientId ,
3575 cobrand_client_id : cobrandClientId ,
3676 locale,
3777 saml_subject_id : samlSubjectId ,
38- configs : generateConfigs ( mergeConfigs ( storedOptions , rest ) )
78+ configs : generateConfigs ( mergeConfigs ( storedOptions , options ) )
3979 } ;
4080
4181 if ( ! needStringify ) {
@@ -47,14 +87,16 @@ export default function openServiceUrl(
4787
4888 switch ( serviceId ) {
4989 case 'vault' :
50- if ( ! view ) {
90+ let { view : vaultView } = options as VaultServiceTypes ;
91+
92+ if ( ! vaultView ) {
5193 return `${ VAULT_DOMAINS [ mode ] } ?${ getQueryValue ( ) } ` ;
5294 }
5395
54- switch ( view ) {
96+ switch ( vaultView ) {
5597 case 'services-list' :
5698 // eslint-disable-next-line no-case-declarations
57- const { group, type, search } = options as ServicesListType ;
99+ const { group, type, search } = options as VaultViewServiceList ;
58100
59101 return `${ VAULT_DOMAINS [ mode ] } /services?${ stringify ( {
60102 ...( getQueryValue ( false ) as QueryData ) ,
@@ -65,13 +107,13 @@ export default function openServiceUrl(
65107
66108 case 'service-connection' :
67109 // eslint-disable-next-line no-case-declarations
68- const { entityKey } = options as ServiceConnectionType ;
110+ const { entityKey } = options as VaultViewServiceConnection ;
69111
70112 return `${ VAULT_DOMAINS [ mode ] } /service/${ entityKey } ?${ getQueryValue ( ) } ` ;
71113
72114 case 'connection-setting' :
73115 // eslint-disable-next-line no-case-declarations
74- const { credentialId } = options as ConnectionSettingType ;
116+ const { credentialId } = options as VaultViewConnectionSetting ;
75117
76118 return `${ VAULT_DOMAINS [ mode ] } /connection/${ credentialId } ?${ getQueryValue ( ) } ` ;
77119
@@ -81,12 +123,13 @@ export default function openServiceUrl(
81123 }
82124
83125 case 'myaccount' :
84- return `${ MY_ACCOUNT_DOMAINS [ mode ] } /${ view } ?${ getQueryValue ( ) } ` ;
126+ let { view : myAccountView = '' } = options as MyAccountServiceTypes ;
127+ return `${ MY_ACCOUNT_DOMAINS [ mode ] } /${ myAccountView } ?${ getQueryValue ( ) } ` ;
85128
86129 case 'link-kit' :
87130 return `${ LINK_KIT_DOMAINS [ mode ] } ?${ getQueryValue ( ) } ` ;
88131
89132 default :
90- throw new Error ( `[mt-link-sdk] Invalid \`serviceId\` in \`openServiceUrl/openService \`, got: ${ serviceId } ` ) ;
133+ throw new Error ( `[mt-link-sdk] Invalid \`serviceId\` in \`openServiceUrl\`, got: ${ serviceId } ` ) ;
91134 }
92135}
0 commit comments