Skip to content
Closed
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Config properties:
locale, // string; // [optional] To force the display to a specific language (e.g.: en-AU).
state, // string; // [optional] An opaque value, used for security purposes. If this request parameter is set in the request, then it is returned to the application as part of the redirect_uri.
appToken, // string; // [optional] The Access Token granted through oauth
isTestEnvironment // boolean; // [optional] If you wanna use the staging or production environemnt
isTestEnvironment // boolean; // [optional] If you wanna use the staging or production environment
}
```

Expand Down Expand Up @@ -114,3 +114,12 @@ You can pass the following options:
- `backTo`: Redirect URL for some actions (back, revoke, logout, delete)
- Values: A string representing a URL
- Default: Current URL

### Open the customer support to let the user contact support

`mtLinkSdk.openCustomerSupport(options);`
You can pass the following options:

- `newTab`: Open in a new browser tab
- Values: `true` or `false`
- Default: `false`
3 changes: 3 additions & 0 deletions dist/endpoints.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ export declare const DOMAIN = "getmoneytree.com";
export declare const VAULT: {
SUBDOMAIN: string;
TEST_SUBDOMAIN: string;
PATHS: {
CUSTOMER_SUPPORT: string;
};
};
export declare const MY_ACCOUNT: {
SUBDOMAIN: string;
Expand Down
1 change: 1 addition & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ declare class LinkSDK {
authorize({ newTab, email, authPage, backTo, showAuthToggle }?: IMyAccountOptions): void;
logout({ newTab }?: IMyAccountOptions): void;
openVault({ newTab, backTo }?: IVaultOptions): void;
openCustomerSupport({ newTab }?: IVaultOptions): void;
openSettings({ newTab, backTo }?: IMyAccountOptions): void;
}
declare const _default: LinkSDK;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sample/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h3>Welcome to the Moneytree Link Web SDK Sample App</h3>
<button id="settings-btn">Open Moneytree Settings</button>
<button id="vault-btn">Open Vault</button>
<button id="logout-btn">Logout</button>
<button id="customer-support-btn">Open Customer Support</button>
</div>
</body>
</html>
9 changes: 8 additions & 1 deletion sample/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ const authorizeBtn = document.getElementById('authorize-btn') as HTMLButtonEleme
const logoutBtn = document.getElementById('logout-btn') as HTMLButtonElement;
const goToSettingsBtn = document.getElementById('settings-btn') as HTMLButtonElement;
const goToVaultBtn = document.getElementById('vault-btn') as HTMLButtonElement;
const goToCustomerSupportBtn = document.getElementById('customer-support-btn') as HTMLButtonElement;
const tokenInfoLbl = document.getElementById('access-token-text') as HTMLButtonElement;
const accessTokenLabel = document.getElementById('access-token-text') as HTMLParagraphElement;

if (!authorizeBtn || !logoutBtn || !goToSettingsBtn || !goToVaultBtn) {
if (!authorizeBtn || !logoutBtn || !goToSettingsBtn || !goToVaultBtn || !goToCustomerSupportBtn) {
throw new Error('An error occurred');
}

Expand All @@ -42,6 +43,11 @@ goToVaultBtn.onclick = () => {
LinkSDK.openVault({ newTab: false });
};

// Launch vault route when clicked
goToCustomerSupportBtn.onclick = () => {
LinkSDK.openCustomerSupport({ newTab: false });
};

const initializeLinkSDK = () => {
LinkSDK.init({
clientId: AWESOME_APP_ID,
Expand All @@ -63,6 +69,7 @@ const validateToken = async () => {
goToSettingsBtn.disabled = true;
goToVaultBtn.disabled = true;
logoutBtn.disabled = true;
goToCustomerSupportBtn.disabled = true;
return;
}

Expand Down
57 changes: 57 additions & 0 deletions src/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,63 @@ describe('LinkSDK', () => {
expect(url).toBe(`${host}?${qs}&configs=${configs}`);
});
});
describe('openCustomerSupport', () => {
test('Calling "openCustomerSupport" method before an init will fail', async () => {
expect(() => {
linkSDK.openCustomerSupport();
}).toThrow('SDK not initialized');
});

test('default params', async () => {
const open = (window.open = jest.fn());

linkSDK.init.call(mockValue, {
clientId: value,
scope: [value]
});
// @ts-ignore Ignores missing arguments to test user passing no arguments
linkSDK.openCustomerSupport.call(mockValue);

expect(open).toBeCalled();

const [[url, isNewTab]] = open.mock.calls; // [0][1]

const host = `https://${mockValue.domains.vault}/${VAULT.PATHS.CUSTOMER_SUPPORT}`;
expect(url).toContain(host);
expect(isNewTab).toBe('_self');

const { params } = mockValue;
const qs = `client_id=${params.client_id}`;
const configs = encodeURIComponent(`sdk_platform=js;sdk_version=${packageJSON.version}`);

expect(url).toBe(`${host}?${qs}&configs=${configs}`);
});

test('with params', async () => {
const open = (window.open = jest.fn());

linkSDK.init.call(mockValue, {
clientId: value,
scope: [value],
isTestEnvironment: true
});
linkSDK.openCustomerSupport.call(mockValue, {
newTab: true
});

expect(open).toBeCalled();

const [[url, isNewTab]] = open.mock.calls; // [0][1]
expect(isNewTab).toBe('_blank');

const { params, domains } = mockValue;
const host = `https://${domains.vault}/${VAULT.PATHS.CUSTOMER_SUPPORT}`;
const qs = `client_id=${params.client_id}`;
const configs = encodeURIComponent(`sdk_platform=js;sdk_version=${packageJSON.version}`);

expect(url).toBe(`${host}?${qs}&configs=${configs}`);
});
});

describe('openSettings', () => {
test('Calling "openSettings" method before an init will failed', async () => {
Expand Down
5 changes: 4 additions & 1 deletion src/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ export const DOMAIN = 'getmoneytree.com';

export const VAULT = {
SUBDOMAIN: 'vault',
TEST_SUBDOMAIN: 'vault-staging'
TEST_SUBDOMAIN: 'vault-staging',
PATHS: {
CUSTOMER_SUPPORT: 'customer-support'
}
};

export const MY_ACCOUNT = {
Expand Down
13 changes: 13 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ class LinkSDK {
window.open(`https://${this.domains.vault}${params}`, newTab ? '_blank' : '_self');
}

// Open Customer Support page
public openCustomerSupport({ newTab = false }: IVaultOptions = {}): void {
if (!this.isInitialized) {
throw new Error('SDK not initialized');
}

const params = encodeConfigWithParams<IParams, ICommonUrlConfig>(this.params, {
...commonUrlConfig
});

window.open(`https://${this.domains.vault}/${VAULT.PATHS.CUSTOMER_SUPPORT}${params}`, newTab ? '_blank' : '_self');
}

// Open the Guest settings page
public openSettings({ newTab = false, backTo = location.href }: IMyAccountOptions = {}): void {
if (!this.isInitialized) {
Expand Down