Skip to content

Commit

Permalink
feat(sdk): Add option to open vault directly in the update and delete…
Browse files Browse the repository at this point in the history
… connection view
  • Loading branch information
mt-pcuba committed Oct 23, 2024
1 parent 8280682 commit 0a5d61d
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 4 deletions.
32 changes: 32 additions & 0 deletions src/api/__tests__/open-service-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,38 @@ describe('api', () => {
expect(url).toBe(`${VAULT_DOMAINS.production}/connection/123?${query}`);
});

test('vault/connection-update', () => {
const url = openServiceUrl(new MtLinkSdk().storedOptions, 'vault', {
view: 'connection-update',
credentialId: '123',
showRememberMe: false
});

const query = qs.stringify({
configs: generateConfigs({
showRememberMe: false
})
});

expect(url).toBe(`${VAULT_DOMAINS.production}/connection/123/update?${query}`);
});

test('vault/connection-delete', () => {
const url = openServiceUrl(new MtLinkSdk().storedOptions, 'vault', {
view: 'connection-delete',
credentialId: '123',
showRememberMe: false
});

const query = qs.stringify({
configs: generateConfigs({
showRememberMe: false
})
});

expect(url).toBe(`${VAULT_DOMAINS.production}/connection/123/delete?${query}`);
});

test('vault/customer-support', () => {
const url = openServiceUrl(new MtLinkSdk().storedOptions, 'vault', {
view: 'customer-support',
Expand Down
42 changes: 42 additions & 0 deletions src/api/__tests__/open-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,48 @@ describe('api', () => {
expect(open).toBeCalledWith(url, '_self', 'noreferrer');
});

test('vault/connection-update', () => {
open.mockClear();

openService(new MtLinkSdk().storedOptions, 'vault', {
view: 'connection-update',
credentialId: '123',
showRememberMe: false
});

expect(open).toBeCalledTimes(1);

const query = qs.stringify({
configs: generateConfigs({
showRememberMe: false
})
});
const url = `${VAULT_DOMAINS.production}/connection/123/update?${query}`;

expect(open).toBeCalledWith(url, '_self', 'noreferrer');
});

test('vault/connection-delete', () => {
open.mockClear();

openService(new MtLinkSdk().storedOptions, 'vault', {
view: 'connection-delete',
credentialId: '123',
showRememberMe: false
});

expect(open).toBeCalledTimes(1);

const query = qs.stringify({
configs: generateConfigs({
showRememberMe: false
})
});
const url = `${VAULT_DOMAINS.production}/connection/123/delete?${query}`;

expect(open).toBeCalledWith(url, '_self', 'noreferrer');
});

test('vault/customer-support', () => {
open.mockClear();

Expand Down
32 changes: 28 additions & 4 deletions src/api/open-service-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
VaultOpenServiceUrlViewServiceList,
VaultOpenServiceUrlViewServiceConnection,
VaultOpenServiceUrlViewConnectionSetting,
VaultOpenServiceUrlViewConnectionUpdate,
VaultOpenServiceUrlViewConnectionDelete,
VaultOpenServiceUrlViewCustomerSupport
} from '../typings';

Expand Down Expand Up @@ -57,6 +59,16 @@ export default function openServiceUrl(
serviceId: 'vault',
options?: VaultOpenServiceUrlViewConnectionSetting
): string;
export default function openServiceUrl(
storedOptions: StoredOptions,
serviceId: 'vault',
options?: VaultOpenServiceUrlViewConnectionUpdate
): string;
export default function openServiceUrl(
storedOptions: StoredOptions,
serviceId: 'vault',
options?: VaultOpenServiceUrlViewConnectionDelete
): string;
export default function openServiceUrl(
storedOptions: StoredOptions,
serviceId: 'vault',
Expand Down Expand Up @@ -105,17 +117,29 @@ export default function openServiceUrl(
search
})}`;

case 'service-connection':
// eslint-disable-next-line no-case-declarations
case 'service-connection': {
const { entityKey } = options as VaultViewServiceConnection;

return `${VAULT_DOMAINS[mode]}/service/${entityKey}?${getQueryValue()}`;
}

case 'connection-setting':
// eslint-disable-next-line no-case-declarations
case 'connection-setting': {
const { credentialId } = options as VaultViewConnectionSetting;

return `${VAULT_DOMAINS[mode]}/connection/${credentialId}?${getQueryValue()}`;
}

case 'connection-update': {
const { credentialId } = options as VaultViewConnectionSetting;

return `${VAULT_DOMAINS[mode]}/connection/${credentialId}/update?${getQueryValue()}`;
}

case 'connection-delete': {
const { credentialId } = options as VaultViewConnectionSetting;

return `${VAULT_DOMAINS[mode]}/connection/${credentialId}/delete?${getQueryValue()}`;
}

case 'customer-support':
default:
Expand Down
12 changes: 12 additions & 0 deletions src/api/open-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
VaultOpenServiceViewServiceList,
VaultOpenServiceViewServiceConnection,
VaultOpenServiceViewConnectionSetting,
VaultOpenServiceViewConnectionUpdate,
VaultOpenServiceViewConnectionDelete,
VaultOpenServiceViewCustomerSupport,
ConfigsOptions
} from '../typings';
Expand Down Expand Up @@ -39,6 +41,16 @@ export default function openService(
serviceId: 'vault',
options?: VaultOpenServiceViewConnectionSetting
): void;
export default function openService(
storedOptions: StoredOptions,
serviceId: 'vault',
options?: VaultOpenServiceViewConnectionUpdate
): void;
export default function openService(
storedOptions: StoredOptions,
serviceId: 'vault',
options?: VaultOpenServiceViewConnectionDelete
): void;
export default function openService(
storedOptions: StoredOptions,
serviceId: 'vault',
Expand Down
26 changes: 26 additions & 0 deletions src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,29 @@ export type VaultViewConnectionSetting = {
*/
credentialId: string;
};
export type VaultViewConnectionUpdate = {
view: 'connection-update';
/**
* Credential ID.
* @remark ⚠️ If credentialId is invalid the Vault top page will be shown.
*/
credentialId: string;
};
export type VaultViewConnectionDelete = {
view: 'connection-delete';
/**
* Credential ID.
* @remark ⚠️ If credentialId is invalid the Vault top page will be shown.
*/
credentialId: string;
};
export type VaultViewCustomerSupport = { view: 'customer-support' };
export type VaultServiceTypes =
| VaultViewServiceList
| VaultViewServiceConnection
| VaultViewConnectionSetting
| VaultViewConnectionUpdate
| VaultViewConnectionDelete
| VaultViewCustomerSupport;

export type MyAccountServiceTypes = {
Expand All @@ -160,10 +178,14 @@ export type MyAccountOpenServiceUrlOptions =
export type VaultOpenServiceViewServiceList = ConfigsOptions & VaultViewServiceList;
export type VaultOpenServiceViewServiceConnection = ConfigsOptions & VaultViewServiceConnection;
export type VaultOpenServiceViewConnectionSetting = ConfigsOptions & VaultViewConnectionSetting;
export type VaultOpenServiceViewConnectionUpdate = ConfigsOptions & VaultViewConnectionUpdate;
export type VaultOpenServiceViewConnectionDelete = ConfigsOptions & VaultViewConnectionDelete;
export type VaultOpenServiceViewCustomerSupport = ConfigsOptions & VaultViewCustomerSupport;
export type VaultOpenServiceUrlViewServiceList = ConfigsOptionsWithoutIsNewTab & VaultViewServiceList;
export type VaultOpenServiceUrlViewServiceConnection = ConfigsOptionsWithoutIsNewTab & VaultViewServiceConnection;
export type VaultOpenServiceUrlViewConnectionSetting = ConfigsOptionsWithoutIsNewTab & VaultViewConnectionSetting;
export type VaultOpenServiceUrlViewConnectionUpdate = ConfigsOptionsWithoutIsNewTab & VaultViewConnectionUpdate;
export type VaultOpenServiceUrlViewConnectionDelete = ConfigsOptionsWithoutIsNewTab & VaultViewConnectionDelete;
export type VaultOpenServiceUrlViewCustomerSupport = ConfigsOptionsWithoutIsNewTab & VaultViewCustomerSupport;

export type LinkKitOpenServiceOptions = ConfigsOptions;
Expand All @@ -174,13 +196,17 @@ export type OpenServiceOptions =
| ConfigsOptions
| VaultOpenServiceViewServiceList
| VaultOpenServiceViewConnectionSetting
| VaultOpenServiceViewConnectionUpdate
| VaultOpenServiceViewConnectionDelete
| VaultOpenServiceViewCustomerSupport
| LinkKitOpenServiceOptions;
export type OpenServiceUrlOptions =
| MyAccountOpenServiceUrlOptions
| ConfigsOptionsWithoutIsNewTab
| VaultOpenServiceUrlViewServiceList
| VaultOpenServiceUrlViewConnectionSetting
| VaultOpenServiceUrlViewConnectionUpdate
| VaultOpenServiceUrlViewConnectionDelete
| VaultOpenServiceUrlViewCustomerSupport
| LinkKitOpenServiceUrlOptions;

Expand Down

0 comments on commit 0a5d61d

Please sign in to comment.