Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions sample/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import mtLinkSdk, {
AuthAction,
AuthorizeOptions,
OnboardOptions,
OpenServicesConfigsOptions,
VaultOpenServiceViewServiceList,
VaultOpenServiceViewServiceConnection,
VaultOpenServiceViewConnectionSetting,
MyAccountOpenServiceOptions,
VaultOpenServiceViewCustomerSupport,
ServiceId,
LoginLinkTo,
VaultViewServiceList
Expand All @@ -19,8 +23,6 @@ interface ITokenInfo {
scopes: string[];
}

const AWESOME_APP_ID = 'af84f08f40970caf17f2e53b31771ceb50d0f32f7d44b826753982e809395290';

// Re-initialize when clicked
elements.initializeBtn.onclick = () => {
const commonOptions: InitOptions = {};
Expand Down Expand Up @@ -75,7 +77,7 @@ elements.doOnboardBtn.onclick = async () => {
onBoardOptions.email = onboardOptionsElms.email.value;
onBoardOptions.pkce = true;

await mtLinkSdk.onboard(onBoardOptions);
mtLinkSdk.onboard(onBoardOptions);
} catch (error) {
console.log(error);
}
Expand Down Expand Up @@ -117,11 +119,16 @@ elements.logoutBtn.onclick = () => {
// Launch open service
elements.openServiceBtn.onclick = () => {
const { openServiceOptionsElms } = elements;
let OpenServicesConfigsOptions: OpenServicesConfigsOptions = {};
const serviceId = openServiceOptionsElms.serviceId.options[openServiceOptionsElms.serviceId.selectedIndex]
const serviceId: ServiceId = openServiceOptionsElms.serviceId.options[openServiceOptionsElms.serviceId.selectedIndex]
.value as ServiceId;

if (serviceId === 'vault') {
type VaultOptions =
| VaultOpenServiceViewServiceConnection
| VaultOpenServiceViewConnectionSetting
| VaultOpenServiceViewServiceList
| VaultOpenServiceViewCustomerSupport;
let openServicesOptions: VaultOptions = {} as VaultOptions;
const view = openServiceOptionsElms.vaultView.options[openServiceOptionsElms.vaultView.selectedIndex].value as
| 'services-list'
| 'service-connection'
Expand All @@ -130,7 +137,7 @@ elements.openServiceBtn.onclick = () => {

switch (view) {
case 'services-list':
OpenServicesConfigsOptions = {
openServicesOptions = {
view: 'services-list',
type:
(openServiceOptionsElms.type.options[openServiceOptionsElms.type.selectedIndex].value as Pick<
Expand All @@ -146,21 +153,22 @@ elements.openServiceBtn.onclick = () => {
};
break;
case 'service-connection':
OpenServicesConfigsOptions = {
openServicesOptions = {
view: 'service-connection',
entityKey: openServiceOptionsElms.entityKey.value
};
break;
case 'connection-setting':
OpenServicesConfigsOptions = {
openServicesOptions = {
view: 'connection-setting',
credentialId: openServiceOptionsElms.credentialId.value
};
break;
case 'customer-support':
default:
OpenServicesConfigsOptions = { view };
openServicesOptions = { view };
}
mtLinkSdk.openService(serviceId, openServicesOptions);
}

if (serviceId === 'myaccount') {
Expand All @@ -174,10 +182,8 @@ elements.openServiceBtn.onclick = () => {
| 'settings/update-email'
| 'settings/update-password';

OpenServicesConfigsOptions = { view };
mtLinkSdk.openService(serviceId, { view });
}

mtLinkSdk.openService(serviceId, OpenServicesConfigsOptions);
};

// Launch open login link
Expand Down Expand Up @@ -234,11 +240,11 @@ elements.openServiceOptionsElms.vaultView.onchange = () => {
};

const initializeLinkSDK = (options: InitOptions = {}) => {
mtLinkSdk.init(AWESOME_APP_ID, {
mtLinkSdk.init('af84f08f40970caf17f2e53b31771ceb50d0f32f7d44b826753982e809395290', {
sdkPlatform: 'js',
redirectUri: 'https://localhost:9000',
locale: 'en',
mode: 'develop',
mode: 'staging',
...options
});
};
Expand Down