@digital-realty/ix-account-switcher 1.0.1 → 1.0.3

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.
@@ -1,19 +1,19 @@
1
- import '@digital-realty/ix-dialog/ix-dialog.js';
2
- import '@digital-realty/ix-field/ix-field.js';
3
- import '@digital-realty/ix-icon-button/ix-icon-button.js';
4
- import '@digital-realty/ix-label-tag/ix-label-tag.js';
5
- import '@digital-realty/ix-select/ix-select.js';
6
- import '@digital-realty/ix-select/ix-select-option.js';
7
- import '@digital-realty/ix-tree/ix-tree.js';
8
- import { TemplateResult } from 'lit';
9
- import { MobxLitElement } from '@adobe/lit-mobx';
10
- import type { NestedAccounts } from './types.js';
11
- export declare class IxAccountSwitcher extends MobxLitElement {
12
- accounts: NestedAccounts[];
13
- showDialog: boolean;
14
- private renderDialog;
15
- getSelectedAccount(): NestedAccounts | null;
16
- private renderNestedAccountStructureSelect;
17
- private renderFlatAccountStructureSelect;
18
- render(): TemplateResult<1>;
19
- }
1
+ import '@digital-realty/ix-dialog/ix-dialog.js';
2
+ import '@digital-realty/ix-field/ix-field.js';
3
+ import '@digital-realty/ix-icon-button/ix-icon-button.js';
4
+ import '@digital-realty/ix-label-tag/ix-label-tag.js';
5
+ import '@digital-realty/ix-select/ix-select.js';
6
+ import '@digital-realty/ix-select/ix-select-option.js';
7
+ import '@digital-realty/ix-tree/ix-tree.js';
8
+ import { TemplateResult } from 'lit';
9
+ import { MobxLitElement } from '@adobe/lit-mobx';
10
+ import type { NestedAccounts } from './types.js';
11
+ export declare class IxAccountSwitcher extends MobxLitElement {
12
+ accounts: NestedAccounts[];
13
+ showDialog: boolean;
14
+ private renderDialog;
15
+ getSelectedAccount(): NestedAccounts | null;
16
+ private renderNestedAccountStructureSelect;
17
+ private renderFlatAccountStructureSelect;
18
+ render(): TemplateResult<1>;
19
+ }
@@ -1,38 +1,38 @@
1
- import { __decorate } from "tslib";
2
- import '@digital-realty/ix-dialog/ix-dialog.js';
3
- import '@digital-realty/ix-field/ix-field.js';
4
- import '@digital-realty/ix-icon-button/ix-icon-button.js';
5
- import '@digital-realty/ix-label-tag/ix-label-tag.js';
6
- import '@digital-realty/ix-select/ix-select.js';
7
- import '@digital-realty/ix-select/ix-select-option.js';
8
- import '@digital-realty/ix-tree/ix-tree.js';
9
- import { html, nothing } from 'lit';
10
- import { property, state } from 'lit/decorators.js';
11
- import { MobxLitElement } from '@adobe/lit-mobx';
12
- import { userProfile } from './state/userProfile.js';
13
- import findAccountById from './utils/find-account-by-id.js';
14
- import { mapAccountsToTreeNode } from './utils/map-accounts-to-tree.js';
15
- export class IxAccountSwitcher extends MobxLitElement {
16
- constructor() {
17
- super(...arguments);
18
- this.accounts = [];
19
- this.showDialog = false;
20
- }
21
- renderDialog() {
22
- const rootNode = mapAccountsToTreeNode(this.accounts);
1
+ import { __decorate } from "tslib";
2
+ import '@digital-realty/ix-dialog/ix-dialog.js';
3
+ import '@digital-realty/ix-field/ix-field.js';
4
+ import '@digital-realty/ix-icon-button/ix-icon-button.js';
5
+ import '@digital-realty/ix-label-tag/ix-label-tag.js';
6
+ import '@digital-realty/ix-select/ix-select.js';
7
+ import '@digital-realty/ix-select/ix-select-option.js';
8
+ import '@digital-realty/ix-tree/ix-tree.js';
9
+ import { html, nothing } from 'lit';
10
+ import { property, state } from 'lit/decorators.js';
11
+ import { MobxLitElement } from '@adobe/lit-mobx';
12
+ import { userProfile } from './state/userProfile.js';
13
+ import findAccountById from './utils/find-account-by-id.js';
14
+ import { mapAccountsToTreeNode } from './utils/map-accounts-to-tree.js';
15
+ export class IxAccountSwitcher extends MobxLitElement {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.accounts = [];
19
+ this.showDialog = false;
20
+ }
21
+ renderDialog() {
22
+ const rootNode = mapAccountsToTreeNode(this.accounts);
23
23
  return html `<ix-dialog
24
24
  id="account-switcher-dialog"
25
25
  class="relative z-50"
26
26
  ?open=${this.showDialog}
27
- @blur=${() => {
28
- this.showDialog = false;
27
+ @blur=${() => {
28
+ this.showDialog = false;
29
29
  }}
30
30
  >
31
31
  <div class="headline" slot="headline">
32
32
  <span class="title">Switch Account</span>
33
33
  <ix-icon-button
34
- @click=${() => {
35
- this.showDialog = false;
34
+ @click=${() => {
35
+ this.showDialog = false;
36
36
  }}
37
37
  icon="close"
38
38
  >
@@ -47,29 +47,29 @@ export class IxAccountSwitcher extends MobxLitElement {
47
47
  <ix-tree
48
48
  .rootNode=${rootNode}
49
49
  .selectedNodeId=${userProfile.accountNumber}
50
- @on-tree-node-selected=${(e) => {
51
- userProfile.setAccountNumber(e.detail.message.id);
52
- this.showDialog = false;
53
- this.requestUpdate();
54
- this.dispatchEvent(new CustomEvent('account-switched', {
55
- detail: e.detail.message.id,
56
- bubbles: true,
57
- composed: true,
58
- }));
50
+ @on-tree-node-selected=${(e) => {
51
+ userProfile.setAccountNumber(e.detail.message.id);
52
+ this.showDialog = false;
53
+ this.requestUpdate();
54
+ this.dispatchEvent(new CustomEvent('account-switched', {
55
+ detail: e.detail.message.id,
56
+ bubbles: true,
57
+ composed: true,
58
+ }));
59
59
  }}
60
60
  ></ix-tree>
61
61
  </form>
62
- </ix-dialog>`;
63
- }
64
- getSelectedAccount() {
65
- return findAccountById(this.accounts, userProfile.accountNumber);
66
- }
67
- renderNestedAccountStructureSelect() {
68
- const selectedAccount = this.getSelectedAccount();
62
+ </ix-dialog>`;
63
+ }
64
+ getSelectedAccount() {
65
+ return findAccountById(this.accounts, userProfile.accountNumber);
66
+ }
67
+ renderNestedAccountStructureSelect() {
68
+ const selectedAccount = this.getSelectedAccount();
69
69
  return html `
70
70
  <ix-field
71
- @click=${() => {
72
- this.showDialog = true;
71
+ @click=${() => {
72
+ this.showDialog = true;
73
73
  }}
74
74
  >
75
75
  <div class="subaccount-wrap">
@@ -77,46 +77,46 @@ export class IxAccountSwitcher extends MobxLitElement {
77
77
  <ix-icon class="dd-icon">arrow_drop_down</ix-icon>
78
78
  </div>
79
79
  </ix-field>
80
- `;
81
- }
82
- renderFlatAccountStructureSelect() {
83
- const selectedAccount = this.getSelectedAccount();
84
- const activeLabelTag = html `<ix-label-tag>Active</ix-label-tag>`;
85
- const options = this.accounts.map(account => {
86
- const isSelected = account.id === (selectedAccount === null || selectedAccount === void 0 ? void 0 : selectedAccount.id);
80
+ `;
81
+ }
82
+ renderFlatAccountStructureSelect() {
83
+ const selectedAccount = this.getSelectedAccount();
84
+ const activeLabelTag = html `<ix-label-tag>Active</ix-label-tag>`;
85
+ const options = this.accounts.map(account => {
86
+ const isSelected = account.id === (selectedAccount === null || selectedAccount === void 0 ? void 0 : selectedAccount.id);
87
87
  return html `<ix-select-option value=${account.id} .selected=${isSelected}>
88
88
  <div slot="headline">${account.name}</div>
89
89
  <div slot="end">${isSelected ? activeLabelTag : nothing}</div>
90
- </ix-select-option>`;
91
- });
90
+ </ix-select-option>`;
91
+ });
92
92
  return html `<div class="account-switcher__select">
93
93
  <ix-select
94
- @request-selection=${(e) => {
95
- const target = e.target;
96
- userProfile.setAccountNumber(target.value);
94
+ @request-selection=${(e) => {
95
+ const target = e.target;
96
+ userProfile.setAccountNumber(target.value);
97
97
  }}
98
98
  >
99
99
  ${options}
100
100
  </ix-select>
101
- </div>`;
102
- }
103
- render() {
104
- const hasSubaccounts = this.accounts.some(a => a.subaccounts && a.subaccounts.length > 0);
101
+ </div>`;
102
+ }
103
+ render() {
104
+ const hasSubaccounts = this.accounts.some(a => a.subaccounts && a.subaccounts.length > 0);
105
105
  return html `
106
106
  <div class="account-switcher-container">
107
- ${hasSubaccounts
108
- ? this.renderNestedAccountStructureSelect()
107
+ ${hasSubaccounts
108
+ ? this.renderNestedAccountStructureSelect()
109
109
  : this.renderFlatAccountStructureSelect()}
110
110
  </div>
111
111
 
112
112
  ${hasSubaccounts ? this.renderDialog() : null}
113
- `;
114
- }
115
- }
116
- __decorate([
117
- property({ type: Array })
118
- ], IxAccountSwitcher.prototype, "accounts", void 0);
119
- __decorate([
120
- state()
121
- ], IxAccountSwitcher.prototype, "showDialog", void 0);
113
+ `;
114
+ }
115
+ }
116
+ __decorate([
117
+ property({ type: Array })
118
+ ], IxAccountSwitcher.prototype, "accounts", void 0);
119
+ __decorate([
120
+ state()
121
+ ], IxAccountSwitcher.prototype, "showDialog", void 0);
122
122
  //# sourceMappingURL=IxAccountSwitcher.js.map
@@ -1,2 +1,2 @@
1
- import type { Account, IAccount } from './types.js';
2
- export declare const mapAccountToIAccount: (payload: Account[]) => IAccount[];
1
+ import type { Account, IAccount } from './types.js';
2
+ export declare const mapAccountToIAccount: (payload: Account[]) => IAccount[];
@@ -1,12 +1,12 @@
1
- export const mapAccountToIAccount = (payload) => {
2
- const response = [];
3
- payload.forEach(account => {
4
- response.push({
5
- accountNumber: account.account_number,
6
- name: account.name,
7
- parentAccountNumber: account.parent_account_number,
8
- });
9
- });
10
- return response;
11
- };
1
+ export const mapAccountToIAccount = (payload) => {
2
+ const response = [];
3
+ payload.forEach(account => {
4
+ response.push({
5
+ accountNumber: account.account_number,
6
+ name: account.name,
7
+ parentAccountNumber: account.parent_account_number,
8
+ });
9
+ });
10
+ return response;
11
+ };
12
12
  //# sourceMappingURL=account-mapper.js.map
@@ -1 +1 @@
1
- export declare const AccountSwitcherStyles: import("lit").CSSResult;
1
+ export declare const AccountSwitcherStyles: import("lit").CSSResult;
@@ -1,4 +1,4 @@
1
- import { css } from 'lit';
1
+ import { css } from 'lit';
2
2
  export const AccountSwitcherStyles = css `
3
3
  .subaccount-wrap {
4
4
  display: flex;
@@ -29,5 +29,5 @@ export const AccountSwitcherStyles = css `
29
29
  width: calc(560px - 3rem);
30
30
  overflow: auto;
31
31
  }
32
- `;
32
+ `;
33
33
  //# sourceMappingURL=account-switcher-styles.js.map
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { IxAccountSwitcher } from './IxAccountSwitcher.js';
1
+ export { IxAccountSwitcher } from './IxAccountSwitcher.js';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { IxAccountSwitcher } from './IxAccountSwitcher.js';
1
+ export { IxAccountSwitcher } from './IxAccountSwitcher.js';
2
2
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { IxAccountSwitcher } from './IxAccountSwitcher.js';
2
- export declare class IxAccountSwitcherStyled extends IxAccountSwitcher {
3
- static styles: import("lit").CSSResult[];
4
- }
1
+ import { IxAccountSwitcher } from './IxAccountSwitcher.js';
2
+ export declare class IxAccountSwitcherStyled extends IxAccountSwitcher {
3
+ static styles: import("lit").CSSResult[];
4
+ }
@@ -1,17 +1,17 @@
1
- import { css } from 'lit';
2
- import { elementTheme } from '@digital-realty/theme';
3
- import { IxAccountSwitcher } from './IxAccountSwitcher.js';
4
- import { AccountSwitcherStyles } from './account-switcher-styles.js';
5
- export class IxAccountSwitcherStyled extends IxAccountSwitcher {
6
- }
7
- IxAccountSwitcherStyled.styles = [
8
- elementTheme,
9
- AccountSwitcherStyles,
1
+ import { css } from 'lit';
2
+ import { elementTheme } from '@digital-realty/theme';
3
+ import { IxAccountSwitcher } from './IxAccountSwitcher.js';
4
+ import { AccountSwitcherStyles } from './account-switcher-styles.js';
5
+ export class IxAccountSwitcherStyled extends IxAccountSwitcher {
6
+ }
7
+ IxAccountSwitcherStyled.styles = [
8
+ elementTheme,
9
+ AccountSwitcherStyles,
10
10
  css `
11
11
  :host {
12
12
  --md-theme-primary: var(--ix-sys-primary, blue);
13
13
  }
14
- `,
15
- ];
16
- window.customElements.define('ix-account-switcher', IxAccountSwitcherStyled);
14
+ `,
15
+ ];
16
+ window.customElements.define('ix-account-switcher', IxAccountSwitcherStyled);
17
17
  //# sourceMappingURL=ix-account-switcher.js.map
@@ -1,28 +1,28 @@
1
- import type { IContactInputAccountsInner, AccountPermission, IContact } from '../types.js';
2
- declare class UserProfileState {
3
- constructor();
4
- accountNumber?: string;
5
- accountPermissions: AccountPermission[];
6
- contact: IContact | undefined;
7
- setPermissions(permissions: AccountPermission[]): void;
8
- setAccountNumber(accountNumber: string): void;
9
- setContact(contact: IContact): void;
10
- get account(): IContactInputAccountsInner;
11
- hasUserManagementExternalUserRead(): boolean;
12
- hasUserManagementExternalUserUpdate(): boolean;
13
- hasUserManagementInternalUserUpdate(): boolean;
14
- hasCustomRoleManagementApprove(): boolean;
15
- hasCustomRoleManagementCreate(): boolean;
16
- hasCustomRoleManagementUpdate(): boolean;
17
- hasCustomRoleManagementRead(): boolean;
18
- hasInternalRoleManagementCreate(): boolean;
19
- hasInternalRoleManagementUpdate(): boolean;
20
- hasInternalRoleManagementRead(): boolean;
21
- hasDefaultSystemRoleManagementCreate(): boolean;
22
- hasDefaultSystemRoleManagementUpdate(): boolean;
23
- hasDefaultSystemRoleManagementRead(): boolean;
24
- private hasPrivilegeLevel;
25
- private hasPermission;
26
- }
27
- export declare const userProfile: UserProfileState;
28
- export {};
1
+ import type { IContactInputAccountsInner, AccountPermission, IContact } from '../types.js';
2
+ declare class UserProfileState {
3
+ constructor();
4
+ accountNumber?: string;
5
+ accountPermissions: AccountPermission[];
6
+ contact: IContact | undefined;
7
+ setPermissions(permissions: AccountPermission[]): void;
8
+ setAccountNumber(accountNumber: string): void;
9
+ setContact(contact: IContact): void;
10
+ get account(): IContactInputAccountsInner;
11
+ hasUserManagementExternalUserRead(): boolean;
12
+ hasUserManagementExternalUserUpdate(): boolean;
13
+ hasUserManagementInternalUserUpdate(): boolean;
14
+ hasCustomRoleManagementApprove(): boolean;
15
+ hasCustomRoleManagementCreate(): boolean;
16
+ hasCustomRoleManagementUpdate(): boolean;
17
+ hasCustomRoleManagementRead(): boolean;
18
+ hasInternalRoleManagementCreate(): boolean;
19
+ hasInternalRoleManagementUpdate(): boolean;
20
+ hasInternalRoleManagementRead(): boolean;
21
+ hasDefaultSystemRoleManagementCreate(): boolean;
22
+ hasDefaultSystemRoleManagementUpdate(): boolean;
23
+ hasDefaultSystemRoleManagementRead(): boolean;
24
+ private hasPrivilegeLevel;
25
+ private hasPermission;
26
+ }
27
+ export declare const userProfile: UserProfileState;
28
+ export {};
@@ -1,91 +1,91 @@
1
- import { makeAutoObservable, toJS } from 'mobx';
2
- import { makePersistable } from 'mobx-persist-store';
3
- class UserProfileState {
4
- constructor() {
5
- this.accountNumber = undefined;
6
- this.accountPermissions = [];
7
- makeAutoObservable(this);
8
- makePersistable(this, {
9
- name: 'user-profile',
10
- properties: ['accountNumber', 'accountPermissions', 'contact'],
11
- storage: window.localStorage,
12
- });
13
- }
14
- setPermissions(permissions) {
15
- this.accountPermissions = permissions;
16
- }
17
- setAccountNumber(accountNumber) {
18
- this.accountNumber = accountNumber;
19
- }
20
- setContact(contact) {
21
- this.contact = contact;
22
- }
23
- get account() {
24
- var _a;
25
- return (_a = this.contact) === null || _a === void 0 ? void 0 : _a.accounts.find(x => x.accountNumber === this.accountNumber);
26
- }
27
- hasUserManagementExternalUserRead() {
28
- return this.hasPermission('User Management - External User', 'read');
29
- }
30
- hasUserManagementExternalUserUpdate() {
31
- return this.hasPermission('User Management - External User', 'update');
32
- }
33
- hasUserManagementInternalUserUpdate() {
34
- return this.hasPermission('User Management - Internal User', 'update');
35
- }
36
- hasCustomRoleManagementApprove() {
37
- return this.hasPermission('Role Management - Custom Role', 'approve');
38
- }
39
- hasCustomRoleManagementCreate() {
40
- return this.hasPermission('Role Management - Custom Roles', 'create');
41
- }
42
- hasCustomRoleManagementUpdate() {
43
- return this.hasPermission('Role Management - Custom Roles', 'update');
44
- }
45
- hasCustomRoleManagementRead() {
46
- return this.hasPermission('Role Management - Custom Roles', 'read');
47
- }
48
- hasInternalRoleManagementCreate() {
49
- return this.hasPermission('Role Management - Internal Roles', 'create');
50
- }
51
- hasInternalRoleManagementUpdate() {
52
- return this.hasPermission('Role Management - Internal Roles', 'update');
53
- }
54
- hasInternalRoleManagementRead() {
55
- return this.hasPermission('Role Management - Internal Roles', 'read');
56
- }
57
- hasDefaultSystemRoleManagementCreate() {
58
- return this.hasPermission('Role Management - Default System Roles', 'create');
59
- }
60
- hasDefaultSystemRoleManagementUpdate() {
61
- return this.hasPermission('Role Management - Default System Roles', 'update');
62
- }
63
- hasDefaultSystemRoleManagementRead() {
64
- return this.hasPermission('Role Management - Default System Roles', 'read');
65
- }
66
- // eslint-disable-next-line class-methods-use-this
67
- hasPrivilegeLevel(requiredPrivilege, currentUserPrivilege) {
68
- const privileges = ['approve', 'create', 'update', 'read'];
69
- const requiredIndex = privileges.findIndex(x => x === requiredPrivilege.toLowerCase());
70
- const currentIndex = privileges.findIndex(x => x === currentUserPrivilege.toLowerCase());
71
- return requiredIndex >= currentIndex;
72
- }
73
- hasPermission(permission, privilege) {
74
- const accountPermissionArray = toJS(this.accountPermissions);
75
- const accountPermission = accountPermissionArray.find(x => x.accountNumber === this.accountNumber || x.accountNumber === null);
76
- let hasPermission = false;
77
- if (accountPermission) {
78
- accountPermission.permissions.forEach(accPermission => {
79
- if (accPermission.permissionName === permission) {
80
- if (privilege &&
81
- this.hasPrivilegeLevel(privilege.toLowerCase(), accPermission.privilege.toLowerCase())) {
82
- hasPermission = true;
83
- }
84
- }
85
- });
86
- }
87
- return hasPermission;
88
- }
89
- }
90
- export const userProfile = new UserProfileState();
1
+ import { makeAutoObservable, toJS } from 'mobx';
2
+ import { makePersistable } from 'mobx-persist-store';
3
+ class UserProfileState {
4
+ constructor() {
5
+ this.accountNumber = undefined;
6
+ this.accountPermissions = [];
7
+ makeAutoObservable(this);
8
+ makePersistable(this, {
9
+ name: 'user-profile',
10
+ properties: ['accountNumber', 'accountPermissions', 'contact'],
11
+ storage: window.localStorage,
12
+ });
13
+ }
14
+ setPermissions(permissions) {
15
+ this.accountPermissions = permissions;
16
+ }
17
+ setAccountNumber(accountNumber) {
18
+ this.accountNumber = accountNumber;
19
+ }
20
+ setContact(contact) {
21
+ this.contact = contact;
22
+ }
23
+ get account() {
24
+ var _a;
25
+ return (_a = this.contact) === null || _a === void 0 ? void 0 : _a.accounts.find(x => x.accountNumber === this.accountNumber);
26
+ }
27
+ hasUserManagementExternalUserRead() {
28
+ return this.hasPermission('User Management - External User', 'read');
29
+ }
30
+ hasUserManagementExternalUserUpdate() {
31
+ return this.hasPermission('User Management - External User', 'update');
32
+ }
33
+ hasUserManagementInternalUserUpdate() {
34
+ return this.hasPermission('User Management - Internal User', 'update');
35
+ }
36
+ hasCustomRoleManagementApprove() {
37
+ return this.hasPermission('Role Management - Custom Role', 'approve');
38
+ }
39
+ hasCustomRoleManagementCreate() {
40
+ return this.hasPermission('Role Management - Custom Roles', 'create');
41
+ }
42
+ hasCustomRoleManagementUpdate() {
43
+ return this.hasPermission('Role Management - Custom Roles', 'update');
44
+ }
45
+ hasCustomRoleManagementRead() {
46
+ return this.hasPermission('Role Management - Custom Roles', 'read');
47
+ }
48
+ hasInternalRoleManagementCreate() {
49
+ return this.hasPermission('Role Management - Internal Roles', 'create');
50
+ }
51
+ hasInternalRoleManagementUpdate() {
52
+ return this.hasPermission('Role Management - Internal Roles', 'update');
53
+ }
54
+ hasInternalRoleManagementRead() {
55
+ return this.hasPermission('Role Management - Internal Roles', 'read');
56
+ }
57
+ hasDefaultSystemRoleManagementCreate() {
58
+ return this.hasPermission('Role Management - Default System Roles', 'create');
59
+ }
60
+ hasDefaultSystemRoleManagementUpdate() {
61
+ return this.hasPermission('Role Management - Default System Roles', 'update');
62
+ }
63
+ hasDefaultSystemRoleManagementRead() {
64
+ return this.hasPermission('Role Management - Default System Roles', 'read');
65
+ }
66
+ // eslint-disable-next-line class-methods-use-this
67
+ hasPrivilegeLevel(requiredPrivilege, currentUserPrivilege) {
68
+ const privileges = ['approve', 'create', 'update', 'read'];
69
+ const requiredIndex = privileges.findIndex(x => x === requiredPrivilege.toLowerCase());
70
+ const currentIndex = privileges.findIndex(x => x === currentUserPrivilege.toLowerCase());
71
+ return requiredIndex >= currentIndex;
72
+ }
73
+ hasPermission(permission, privilege) {
74
+ const accountPermissionArray = toJS(this.accountPermissions);
75
+ const accountPermission = accountPermissionArray.find(x => x.accountNumber === this.accountNumber || x.accountNumber === null);
76
+ let hasPermission = false;
77
+ if (accountPermission) {
78
+ accountPermission.permissions.forEach(accPermission => {
79
+ if (accPermission.permissionName === permission) {
80
+ if (privilege &&
81
+ this.hasPrivilegeLevel(privilege.toLowerCase(), accPermission.privilege.toLowerCase())) {
82
+ hasPermission = true;
83
+ }
84
+ }
85
+ });
86
+ }
87
+ return hasPermission;
88
+ }
89
+ }
90
+ export const userProfile = new UserProfileState();
91
91
  //# sourceMappingURL=userProfile.js.map
package/dist/types.d.ts CHANGED
@@ -1,43 +1,43 @@
1
- export interface IAccount {
2
- accountNumber?: string;
3
- parentAccountNumber?: string | null;
4
- name?: string;
5
- }
6
- export interface Account {
7
- account_number?: string;
8
- parent_account_number?: string | null;
9
- name?: string;
10
- }
11
- export interface NestedAccounts {
12
- id: string;
13
- name: string;
14
- status: string;
15
- accountNumber: string;
16
- subaccounts?: NestedAccounts[];
17
- }
18
- export interface IContactInputAccountsInner {
19
- id: string;
20
- name: string;
21
- status: string;
22
- accountNumber?: string;
23
- statusUpdateAt?: string;
24
- statusUpdateBy?: string;
25
- }
26
- export interface IContact {
27
- id: string;
28
- firstName: string;
29
- lastName: string;
30
- email: string;
31
- phone: string;
32
- evacAssistance: boolean;
33
- accounts: Array<IContactInputAccountsInner>;
34
- status?: string;
35
- }
36
- export type UserPermission = {
37
- permissionName: string;
38
- privilege: string;
39
- };
40
- export type AccountPermission = {
41
- accountNumber: string;
42
- permissions: UserPermission[];
43
- };
1
+ export interface IAccount {
2
+ accountNumber?: string;
3
+ parentAccountNumber?: string | null;
4
+ name?: string;
5
+ }
6
+ export interface Account {
7
+ account_number?: string;
8
+ parent_account_number?: string | null;
9
+ name?: string;
10
+ }
11
+ export interface NestedAccounts {
12
+ id: string;
13
+ name: string;
14
+ status: string;
15
+ accountNumber: string;
16
+ subaccounts?: NestedAccounts[];
17
+ }
18
+ export interface IContactInputAccountsInner {
19
+ id: string;
20
+ name: string;
21
+ status: string;
22
+ accountNumber?: string;
23
+ statusUpdateAt?: string;
24
+ statusUpdateBy?: string;
25
+ }
26
+ export interface IContact {
27
+ id: string;
28
+ firstName: string;
29
+ lastName: string;
30
+ email: string;
31
+ phone: string;
32
+ evacAssistance: boolean;
33
+ accounts: Array<IContactInputAccountsInner>;
34
+ status?: string;
35
+ }
36
+ export type UserPermission = {
37
+ permissionName: string;
38
+ privilege: string;
39
+ };
40
+ export type AccountPermission = {
41
+ accountNumber: string;
42
+ permissions: UserPermission[];
43
+ };
package/dist/types.js CHANGED
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=types.js.map
@@ -1,3 +1,3 @@
1
- import type { NestedAccounts } from '../types.js';
2
- declare const findAccountById: (accounts: NestedAccounts[], id: string) => NestedAccounts | null;
3
- export default findAccountById;
1
+ import type { NestedAccounts } from '../types.js';
2
+ declare const findAccountById: (accounts: NestedAccounts[], id: string) => NestedAccounts | null;
3
+ export default findAccountById;
@@ -1,17 +1,17 @@
1
- const findAccountById = (accounts, id) => {
2
- const account = accounts.find(a => a.id === id);
3
- if (account) {
4
- return account;
5
- }
6
- for (const a of accounts) {
7
- if (a.subaccounts) {
8
- const foundAccount = findAccountById(a.subaccounts, id);
9
- if (foundAccount) {
10
- return foundAccount;
11
- }
12
- }
13
- }
14
- return null;
15
- };
16
- export default findAccountById;
1
+ const findAccountById = (accounts, id) => {
2
+ const account = accounts.find(a => a.id === id);
3
+ if (account) {
4
+ return account;
5
+ }
6
+ for (const a of accounts) {
7
+ if (a.subaccounts) {
8
+ const foundAccount = findAccountById(a.subaccounts, id);
9
+ if (foundAccount) {
10
+ return foundAccount;
11
+ }
12
+ }
13
+ }
14
+ return null;
15
+ };
16
+ export default findAccountById;
17
17
  //# sourceMappingURL=find-account-by-id.js.map
@@ -1,8 +1,8 @@
1
- import type { IIxTreeNode } from '@digital-realty/ix-tree';
2
- export interface IAccount {
3
- accountNumber?: string;
4
- parentAccountNumber?: string | null;
5
- name?: string;
6
- }
7
- export declare const mapAccountToTreeNode: (account: any, parentNode: IIxTreeNode) => IIxTreeNode;
8
- export declare const mapAccountsToTreeNode: (accounts: Array<IAccount>) => IIxTreeNode;
1
+ import type { IIxTreeNode } from '@digital-realty/ix-tree';
2
+ export interface IAccount {
3
+ accountNumber?: string;
4
+ parentAccountNumber?: string | null;
5
+ name?: string;
6
+ }
7
+ export declare const mapAccountToTreeNode: (account: any, parentNode: IIxTreeNode) => IIxTreeNode;
8
+ export declare const mapAccountsToTreeNode: (accounts: Array<IAccount>) => IIxTreeNode;
@@ -1,23 +1,23 @@
1
- // TODO: Should use correctly typed definition rather than any
2
- export const mapAccountToTreeNode = (account, parentNode) => {
3
- var _a;
4
- const treeNode = {
5
- expanded: false,
6
- id: account.id,
7
- label: account.name,
8
- parentId: parentNode.id,
9
- };
10
- treeNode.children = (_a = account.subaccounts) === null || _a === void 0 ? void 0 : _a.map((childAccount) => mapAccountToTreeNode(childAccount, treeNode));
11
- return treeNode;
12
- };
13
- export const mapAccountsToTreeNode = (accounts) => {
14
- const rootNode = {
15
- expanded: false,
16
- id: 'root',
17
- label: '',
18
- parentId: undefined,
19
- };
20
- rootNode.children = accounts.map(account => mapAccountToTreeNode(account, rootNode));
21
- return rootNode;
22
- };
1
+ // TODO: Should use correctly typed definition rather than any
2
+ export const mapAccountToTreeNode = (account, parentNode) => {
3
+ var _a;
4
+ const treeNode = {
5
+ expanded: false,
6
+ id: account.id,
7
+ label: account.name,
8
+ parentId: parentNode.id,
9
+ };
10
+ treeNode.children = (_a = account.subaccounts) === null || _a === void 0 ? void 0 : _a.map((childAccount) => mapAccountToTreeNode(childAccount, treeNode));
11
+ return treeNode;
12
+ };
13
+ export const mapAccountsToTreeNode = (accounts) => {
14
+ const rootNode = {
15
+ expanded: false,
16
+ id: 'root',
17
+ label: '',
18
+ parentId: undefined,
19
+ };
20
+ rootNode.children = accounts.map(account => mapAccountToTreeNode(account, rootNode));
21
+ return rootNode;
22
+ };
23
23
  //# sourceMappingURL=map-accounts-to-tree.js.map
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent ix-account-switcher following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "Digital Realty",
6
- "version": "1.0.1",
6
+ "version": "1.0.3",
7
7
  "type": "module",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.js",
@@ -106,5 +106,6 @@
106
106
  "package.json",
107
107
  "README.md",
108
108
  "LICENSE"
109
- ]
109
+ ],
110
+ "gitHead": "23d7b6d3c091c0f832ede265983a8f0c4d90ac72"
110
111
  }