@sbc-connect/nuxt-auth 0.0.0-test-ld-20260520212549
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.
- package/.env.example +35 -0
- package/CHANGELOG.md +495 -0
- package/LICENSE +28 -0
- package/README.md +58 -0
- package/app/app.config.ts +22 -0
- package/app/components/Connect/Account/Create/Name.vue +73 -0
- package/app/components/Connect/Account/Create/index.vue +148 -0
- package/app/components/Connect/Account/Existing/Alert.vue +10 -0
- package/app/components/Connect/Account/Existing/List/Item.vue +54 -0
- package/app/components/Connect/Account/Existing/List/index.vue +30 -0
- package/app/components/Connect/Header/AccountLabel.vue +39 -0
- package/app/components/Connect/Header/AccountOptionsMenu.vue +52 -0
- package/app/components/Connect/Header/Auth.vue +14 -0
- package/app/components/Connect/Header/AuthenticatedOptions.vue +13 -0
- package/app/components/Connect/Header/CreateAccountButton.vue +13 -0
- package/app/components/Connect/Header/LoginMenu.vue +27 -0
- package/app/components/Connect/Header/Notifications.vue +30 -0
- package/app/components/Connect/Header/UnauthenticatedOptions.vue +15 -0
- package/app/components/Connect/Layout/Auth.vue +19 -0
- package/app/components/Connect/Modal/InvalidIdp.vue +55 -0
- package/app/components/Connect/Modal/SessionExpired.vue +107 -0
- package/app/components/Connect/TermsOfUse/Content.vue +28 -0
- package/app/components/Connect/TermsOfUse/Form.vue +101 -0
- package/app/components/HelloWorld/Auth.vue +12 -0
- package/app/composables/useAuthApi.ts +156 -0
- package/app/composables/useConnectAccountFlowRedirect.ts +54 -0
- package/app/composables/useConnectAppConfig.ts +31 -0
- package/app/composables/useConnectAuth.ts +90 -0
- package/app/composables/useConnectAuthModals.ts +76 -0
- package/app/composables/useConnectHeaderOptions.ts +236 -0
- package/app/composables/useConnectLaunchDarkly.ts +250 -0
- package/app/coverage/app/app.config.ts.html +148 -0
- package/app/coverage/app/components/Connect/Account/Create/Name.vue.html +304 -0
- package/app/coverage/app/components/Connect/Account/Create/index.html +131 -0
- package/app/coverage/app/components/Connect/Account/Create/index.vue.html +487 -0
- package/app/coverage/app/components/Connect/Account/Existing/Alert.vue.html +115 -0
- package/app/coverage/app/components/Connect/Account/Existing/List/Item.vue.html +247 -0
- package/app/coverage/app/components/Connect/Account/Existing/List/index.html +131 -0
- package/app/coverage/app/components/Connect/Account/Existing/List/index.vue.html +175 -0
- package/app/coverage/app/components/Connect/Account/Existing/index.html +116 -0
- package/app/coverage/app/components/Connect/Header/AccountLabel.vue.html +202 -0
- package/app/coverage/app/components/Connect/Header/AccountOptionsMenu.vue.html +241 -0
- package/app/coverage/app/components/Connect/Header/Auth.vue.html +127 -0
- package/app/coverage/app/components/Connect/Header/AuthenticatedOptions.vue.html +124 -0
- package/app/coverage/app/components/Connect/Header/CreateAccountButton.vue.html +124 -0
- package/app/coverage/app/components/Connect/Header/LoginMenu.vue.html +166 -0
- package/app/coverage/app/components/Connect/Header/Notifications.vue.html +175 -0
- package/app/coverage/app/components/Connect/Header/UnauthenticatedOptions.vue.html +130 -0
- package/app/coverage/app/components/Connect/Header/index.html +221 -0
- package/app/coverage/app/components/Connect/Layout/Auth.vue.html +142 -0
- package/app/coverage/app/components/Connect/Layout/index.html +116 -0
- package/app/coverage/app/components/Connect/Modal/SessionExpired.vue.html +364 -0
- package/app/coverage/app/components/Connect/Modal/index.html +116 -0
- package/app/coverage/app/components/Connect/TermsOfUse/Content.vue.html +169 -0
- package/app/coverage/app/components/Connect/TermsOfUse/Form.vue.html +388 -0
- package/app/coverage/app/components/Connect/TermsOfUse/index.html +131 -0
- package/app/coverage/app/components/HelloWorld/Auth.vue.html +121 -0
- package/app/coverage/app/components/HelloWorld/index.html +116 -0
- package/app/coverage/app/composables/index.html +191 -0
- package/app/coverage/app/composables/useAuthApi.ts.html +547 -0
- package/app/coverage/app/composables/useConnectAccountFlowRedirect.ts.html +202 -0
- package/app/coverage/app/composables/useConnectAuth.ts.html +352 -0
- package/app/coverage/app/composables/useConnectAuthModals.ts.html +313 -0
- package/app/coverage/app/composables/useConnectHeaderOptions.ts.html +781 -0
- package/app/coverage/app/composables/useConnectLaunchDarkly.ts.html +820 -0
- package/app/coverage/app/enums/account-status.ts.html +112 -0
- package/app/coverage/app/enums/account-type.ts.html +103 -0
- package/app/coverage/app/enums/connect-access-type.ts.html +94 -0
- package/app/coverage/app/enums/connect-auth-storage-key.ts.html +94 -0
- package/app/coverage/app/enums/connect-idp-hint.ts.html +103 -0
- package/app/coverage/app/enums/connect-login-source.ts.html +103 -0
- package/app/coverage/app/enums/connect-payment-method.ts.html +94 -0
- package/app/coverage/app/enums/connect-product-code.ts.html +94 -0
- package/app/coverage/app/enums/connect-product-type.ts.html +94 -0
- package/app/coverage/app/enums/index.html +251 -0
- package/app/coverage/app/enums/user-settings-type.ts.html +100 -0
- package/app/coverage/app/index.html +116 -0
- package/app/coverage/app/interfaces/connect-account-address.ts.html +88 -0
- package/app/coverage/app/interfaces/connect-account.ts.html +154 -0
- package/app/coverage/app/interfaces/connect-auth-contact.ts.html +130 -0
- package/app/coverage/app/interfaces/connect-auth-profile.ts.html +157 -0
- package/app/coverage/app/interfaces/connect-auth-user.ts.html +115 -0
- package/app/coverage/app/interfaces/connect-terms-of-use.ts.html +103 -0
- package/app/coverage/app/interfaces/connect-user-settings.ts.html +115 -0
- package/app/coverage/app/interfaces/index.html +206 -0
- package/app/coverage/app/layouts/ConnectAuth.vue.html +100 -0
- package/app/coverage/app/layouts/index.html +116 -0
- package/app/coverage/app/middleware/01.setup-accounts.global.ts.html +124 -0
- package/app/coverage/app/middleware/02.keycloak-params.global.ts.html +130 -0
- package/app/coverage/app/middleware/03.allowed-idps.global.ts.html +145 -0
- package/app/coverage/app/middleware/connect-auth.ts.html +238 -0
- package/app/coverage/app/middleware/connect-login-page.ts.html +163 -0
- package/app/coverage/app/middleware/index.html +176 -0
- package/app/coverage/app/pages/auth/account/index.html +116 -0
- package/app/coverage/app/pages/auth/account/select.vue.html +424 -0
- package/app/coverage/app/pages/auth/index.html +146 -0
- package/app/coverage/app/pages/auth/login.vue.html +334 -0
- package/app/coverage/app/pages/auth/logout.vue.html +154 -0
- package/app/coverage/app/pages/auth/terms-of-use.vue.html +316 -0
- package/app/coverage/app/plugins/auth-api.ts.html +169 -0
- package/app/coverage/app/plugins/connect-auth.client.ts.html +382 -0
- package/app/coverage/app/plugins/index.html +131 -0
- package/app/coverage/app/stores/connect-account.ts.html +826 -0
- package/app/coverage/app/stores/index.html +116 -0
- package/app/coverage/app/types/connect-valid-idps.ts.html +100 -0
- package/app/coverage/app/types/index.html +116 -0
- package/app/coverage/app/utils/constants/index.html +131 -0
- package/app/coverage/app/utils/constants/index.ts.html +88 -0
- package/app/coverage/app/utils/constants/valid-idps.ts.html +106 -0
- package/app/coverage/app/utils/index.html +146 -0
- package/app/coverage/app/utils/index.ts.html +88 -0
- package/app/coverage/app/utils/resetPiniaStores.ts.html +184 -0
- package/app/coverage/app/utils/schemas/account.ts.html +313 -0
- package/app/coverage/app/utils/schemas/index.html +116 -0
- package/app/coverage/app/utils/setOnBeforeSessionExpired.ts.html +154 -0
- package/app/coverage/base.css +224 -0
- package/app/coverage/block-navigation.js +87 -0
- package/app/coverage/clover.xml +1939 -0
- package/app/coverage/coverage-final.json +63 -0
- package/app/coverage/favicon.png +0 -0
- package/app/coverage/index.html +431 -0
- package/app/coverage/prettify.css +1 -0
- package/app/coverage/prettify.js +2 -0
- package/app/coverage/sort-arrow-sprite.png +0 -0
- package/app/coverage/sorter.js +210 -0
- package/app/enums/account-status.ts +9 -0
- package/app/enums/account-type.ts +6 -0
- package/app/enums/connect-access-type.ts +3 -0
- package/app/enums/connect-auth-storage-key.ts +3 -0
- package/app/enums/connect-idp-hint.ts +6 -0
- package/app/enums/connect-login-source.ts +6 -0
- package/app/enums/connect-payment-method.ts +3 -0
- package/app/enums/connect-preset-type.ts +4 -0
- package/app/enums/connect-product-code.ts +3 -0
- package/app/enums/connect-product-type.ts +3 -0
- package/app/enums/user-settings-type.ts +5 -0
- package/app/interfaces/app-config-shapes.ts +40 -0
- package/app/interfaces/connect-account-address.ts +3 -0
- package/app/interfaces/connect-account.ts +23 -0
- package/app/interfaces/connect-auth-contact.ts +15 -0
- package/app/interfaces/connect-auth-profile.ts +24 -0
- package/app/interfaces/connect-auth-user.ts +10 -0
- package/app/interfaces/connect-terms-of-use.ts +6 -0
- package/app/interfaces/connect-user-settings.ts +10 -0
- package/app/layouts/ConnectAuth.vue +5 -0
- package/app/middleware/01.setup-accounts.global.ts +13 -0
- package/app/middleware/02.keycloak-params.global.ts +15 -0
- package/app/middleware/03.app-config-presets.global.ts +10 -0
- package/app/middleware/04.idp-enforcement.global.ts +30 -0
- package/app/middleware/connect-auth.ts +72 -0
- package/app/pages/auth/account/select.vue +121 -0
- package/app/pages/auth/login.vue +104 -0
- package/app/pages/auth/logout.vue +23 -0
- package/app/pages/auth/terms-of-use.vue +77 -0
- package/app/plugins/auth-api.ts +28 -0
- package/app/plugins/connect-auth.client.ts +112 -0
- package/app/stores/connect-account.ts +270 -0
- package/app/types/auth-app-config.d.ts +16 -0
- package/app/types/auth-page-meta.d.ts +8 -0
- package/app/types/connect-valid-idps.ts +5 -0
- package/app/utils/constants/index.ts +1 -0
- package/app/utils/constants/valid-idps.ts +7 -0
- package/app/utils/index.ts +1 -0
- package/app/utils/resetPiniaStores.ts +33 -0
- package/app/utils/schemas/account.ts +76 -0
- package/app/utils/setOnBeforeSessionExpired.ts +23 -0
- package/i18n/locales/en-CA.ts +114 -0
- package/i18n/locales/fr-CA.ts +1 -0
- package/nuxt.config.ts +84 -0
- package/package.json +44 -0
- package/playwright-report/index.html +85 -0
- package/public/img/BCReg_Generic_Login_image.jpg +0 -0
- package/test-results/.last-run.json +4 -0
- package/testMocks/auth/index.ts +2 -0
- package/testMocks/auth/profile/index.ts +9 -0
- package/testMocks/auth/profile/json/PUBLIC_USER.json +29 -0
- package/testMocks/auth/settings/index.ts +11 -0
- package/testMocks/auth/settings/json/PREMIUM.json +38 -0
- package/testMocks/auth/settings/json/SBC_STAFF.json +27 -0
- package/testMocks/auth/settings/json/STAFF.json +27 -0
- package/testMocks/mock-helpers.ts +15 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import type { DropdownMenuItem } from '@nuxt/ui'
|
|
2
|
+
import { useStorage } from '@vueuse/core'
|
|
3
|
+
import { ConnectSlideoverWhatsNew } from '#components'
|
|
4
|
+
|
|
5
|
+
// handle navigation items and functionality
|
|
6
|
+
export function useConnectHeaderOptions() {
|
|
7
|
+
const rtc = useRuntimeConfig().public
|
|
8
|
+
const authWebUrl = rtc.authWebUrl
|
|
9
|
+
const appBaseUrl = rtc.baseUrl
|
|
10
|
+
const ac = useAppConfig().connect
|
|
11
|
+
const route = useRoute()
|
|
12
|
+
const overlay = useOverlay()
|
|
13
|
+
const { t } = useNuxtApp().$i18n
|
|
14
|
+
const { login, isAuthenticated, authUser } = useConnectAuth()
|
|
15
|
+
const accountStore = useConnectAccountStore()
|
|
16
|
+
const localePath = useLocalePath()
|
|
17
|
+
|
|
18
|
+
const whatsNew = useStorage<ConnectWhatsNewState>('connect-whats-new', { viewed: false, items: [] })
|
|
19
|
+
const slideover = overlay.create(ConnectSlideoverWhatsNew)
|
|
20
|
+
|
|
21
|
+
/** return the correct account creation link based on auth state */
|
|
22
|
+
function createAccountUrl(): string {
|
|
23
|
+
if (isAuthenticated.value) {
|
|
24
|
+
return authWebUrl + 'setup-account'
|
|
25
|
+
} else {
|
|
26
|
+
return authWebUrl + 'choose-authentication-method'
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const basicAccountOptions = computed<DropdownMenuItem[]>(() => {
|
|
31
|
+
const options: DropdownMenuItem[] = [{ slot: 'account', type: 'label' }]
|
|
32
|
+
if ([ConnectLoginSource.BCEID, ConnectLoginSource.BCSC].includes(authUser?.value.loginSource)) {
|
|
33
|
+
options.push({
|
|
34
|
+
label: t('connect.label.editProfile'),
|
|
35
|
+
icon: 'i-mdi-account-outline',
|
|
36
|
+
to: authWebUrl + 'userprofile'
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
options.push({
|
|
40
|
+
label: t('connect.label.logout'),
|
|
41
|
+
icon: 'i-mdi-logout-variant',
|
|
42
|
+
onSelect: () => navigateTo(localePath('/auth/logout'))
|
|
43
|
+
})
|
|
44
|
+
return options
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const accountSettingsOptions = computed<DropdownMenuItem[]>(() => {
|
|
48
|
+
const accountId = accountStore.currentAccount.id
|
|
49
|
+
const options: DropdownMenuItem[] = [
|
|
50
|
+
{
|
|
51
|
+
label: t('connect.label.accountSettings'),
|
|
52
|
+
type: 'label'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
label: t('connect.label.accountInfo'),
|
|
56
|
+
icon: 'i-mdi-information-outline',
|
|
57
|
+
to: authWebUrl + `account/${accountId}/settings/account-info`
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
label: t('connect.label.teamMembers'),
|
|
61
|
+
icon: 'i-mdi-account-group-outline',
|
|
62
|
+
to: authWebUrl + `account/${accountId}/settings/team-members`
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
// TODO: remove staff checks?
|
|
66
|
+
if (
|
|
67
|
+
[AccountType.PREMIUM, AccountType.SBC_STAFF, AccountType.STAFF].includes(accountStore.currentAccount.accountType)
|
|
68
|
+
) {
|
|
69
|
+
options.push({
|
|
70
|
+
label: t('connect.label.transactions'),
|
|
71
|
+
icon: 'i-mdi-file-document-outline',
|
|
72
|
+
to: authWebUrl + `account/${accountId}/settings/transactions`
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
return options
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const switchAccountOptions = computed<DropdownMenuItem[]>(() => {
|
|
79
|
+
const options: DropdownMenuItem[] = []
|
|
80
|
+
|
|
81
|
+
if (accountStore.userAccounts.length > 1) {
|
|
82
|
+
options.push({ label: t('connect.label.switchAccount'), type: 'label' })
|
|
83
|
+
|
|
84
|
+
accountStore.userAccounts.forEach((account) => {
|
|
85
|
+
const isActive = accountStore.currentAccount.id === account.id
|
|
86
|
+
options.push({
|
|
87
|
+
label: account.label,
|
|
88
|
+
onSelect: async () => {
|
|
89
|
+
if (!isActive && account.id) {
|
|
90
|
+
if (route.meta.onAccountChange) {
|
|
91
|
+
const allowAccountChange = route.meta.onAccountChange(accountStore.currentAccount, account)
|
|
92
|
+
if (allowAccountChange) {
|
|
93
|
+
await accountStore.switchCurrentAccount(account.id)
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
await accountStore.switchCurrentAccount(account.id)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
slot: 'account-item',
|
|
101
|
+
icon: isActive ? 'i-mdi-check' : '',
|
|
102
|
+
class: isActive ? 'bg-shade text-primary' : '',
|
|
103
|
+
ui: {
|
|
104
|
+
itemLabel: isActive ? '' : 'pl-6',
|
|
105
|
+
itemLeadingIcon: isActive ? 'size-5 text-primary shrink-0' : ''
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return options
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const createAccountOptions = computed<DropdownMenuItem[]>(() => {
|
|
115
|
+
if ([ConnectLoginSource.BCROS, ConnectLoginSource.IDIR].includes(authUser?.value.loginSource)) {
|
|
116
|
+
return []
|
|
117
|
+
}
|
|
118
|
+
return [{ label: t('connect.label.createAccount'), icon: 'i-mdi-plus', to: createAccountUrl() }]
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
const loggedInUserOptions = computed<DropdownMenuItem[][]>(() => {
|
|
122
|
+
const options = [
|
|
123
|
+
basicAccountOptions.value,
|
|
124
|
+
accountSettingsOptions.value
|
|
125
|
+
]
|
|
126
|
+
|
|
127
|
+
if (switchAccountOptions.value.length > 0) {
|
|
128
|
+
options.push(switchAccountOptions.value)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (createAccountOptions.value.length > 0) {
|
|
132
|
+
options.push(createAccountOptions.value)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return options
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
// Build a redirect URL through the login page so the connect-auth middleware
|
|
139
|
+
// processes query params (e.g. 'return') after Keycloak authentication
|
|
140
|
+
function getLoginRedirectUrl(): string {
|
|
141
|
+
const loginPath = localePath('/auth/login')
|
|
142
|
+
const queryString = window.location.search
|
|
143
|
+
return `${appBaseUrl}${loginPath.startsWith('/') ? loginPath.slice(1) : loginPath}${queryString}`
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const loginOptionsMap: Record<'bcsc' | 'bceid' | 'idir',
|
|
147
|
+
{ label: string, icon: string, onSelect: () => Promise<void> }
|
|
148
|
+
> = {
|
|
149
|
+
bcsc: {
|
|
150
|
+
label: t('connect.label.bcsc'),
|
|
151
|
+
icon: 'i-mdi-account-card-details-outline',
|
|
152
|
+
onSelect: () => login(ConnectIdpHint.BCSC, getLoginRedirectUrl())
|
|
153
|
+
},
|
|
154
|
+
bceid: {
|
|
155
|
+
label: t('connect.label.bceid'),
|
|
156
|
+
icon: 'i-mdi-two-factor-authentication',
|
|
157
|
+
onSelect: () => login(ConnectIdpHint.BCEID, getLoginRedirectUrl())
|
|
158
|
+
},
|
|
159
|
+
idir: {
|
|
160
|
+
label: t('connect.label.idir'),
|
|
161
|
+
icon: 'i-mdi-account-group-outline',
|
|
162
|
+
onSelect: () => login(ConnectIdpHint.IDIR, getLoginRedirectUrl())
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const loggedOutUserOptions = computed<DropdownMenuItem[][]>(() => {
|
|
167
|
+
const options: DropdownMenuItem[][] = [[{ label: t('connect.label.selectLoginMethod'), type: 'label' }]]
|
|
168
|
+
|
|
169
|
+
const idps = ac.login.idps.map(key => loginOptionsMap[key as keyof typeof loginOptionsMap])
|
|
170
|
+
|
|
171
|
+
options.push(idps)
|
|
172
|
+
|
|
173
|
+
return options
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
const loggedOutUserOptionsMobile = computed<DropdownMenuItem[][]>(() => {
|
|
177
|
+
const config = ac.header
|
|
178
|
+
const options: DropdownMenuItem[][] = []
|
|
179
|
+
|
|
180
|
+
if (config.loginMenu) {
|
|
181
|
+
options.push(...loggedOutUserOptions.value)
|
|
182
|
+
}
|
|
183
|
+
if (config.whatsNew) {
|
|
184
|
+
options.push([
|
|
185
|
+
{
|
|
186
|
+
'label': t('connect.label.whatsNew'),
|
|
187
|
+
'aria-label': t('connect.label.whatsNewAria', {
|
|
188
|
+
count: whatsNew.value.viewed ? 0 : whatsNew.value.items.length }
|
|
189
|
+
),
|
|
190
|
+
'slot': 'whatsnew' as const,
|
|
191
|
+
'icon': 'i-mdi-new-box',
|
|
192
|
+
'onSelect': () => {
|
|
193
|
+
slideover.open({
|
|
194
|
+
items: whatsNew.value.items
|
|
195
|
+
})
|
|
196
|
+
whatsNew.value.viewed = true
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
])
|
|
200
|
+
}
|
|
201
|
+
if (config.createAccount) {
|
|
202
|
+
options.push([{ label: t('connect.label.createAccount'), icon: 'i-mdi-plus', to: createAccountUrl() }])
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return options
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
const notificationsOptions = computed<DropdownMenuItem[][]>(() => {
|
|
209
|
+
const count = accountStore.pendingApprovalCount
|
|
210
|
+
const options = []
|
|
211
|
+
if (count > 0) {
|
|
212
|
+
options.push([{
|
|
213
|
+
to: authWebUrl + `account/${accountStore.currentAccount.id}/settings/team-members`,
|
|
214
|
+
label: t('connect.text.notifications.teamMemberApproval', {
|
|
215
|
+
count: accountStore.pendingApprovalCount
|
|
216
|
+
}, accountStore.pendingApprovalCount
|
|
217
|
+
)
|
|
218
|
+
}])
|
|
219
|
+
} else {
|
|
220
|
+
options.push([{ label: t('connect.text.notifications.none') }])
|
|
221
|
+
}
|
|
222
|
+
return options
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
basicAccountOptions,
|
|
227
|
+
accountSettingsOptions,
|
|
228
|
+
switchAccountOptions,
|
|
229
|
+
createAccountOptions,
|
|
230
|
+
loggedInUserOptions,
|
|
231
|
+
loggedOutUserOptions,
|
|
232
|
+
loggedOutUserOptionsMobile,
|
|
233
|
+
notificationsOptions,
|
|
234
|
+
createAccountUrl
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { createClient } from '@launchdarkly/js-client-sdk'
|
|
2
|
+
import type { LDClient, LDFlagSet, LDOptions, LDMultiKindContext } from '@launchdarkly/js-client-sdk'
|
|
3
|
+
import { isEqual } from 'es-toolkit'
|
|
4
|
+
|
|
5
|
+
// Default anonymous context
|
|
6
|
+
const anonymousContext: LDMultiKindContext = {
|
|
7
|
+
kind: 'multi',
|
|
8
|
+
org: { key: 'anonymous' },
|
|
9
|
+
user: { key: 'anonymous' }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Composable for the LaunchDarkly service.
|
|
14
|
+
* Extends the base composable with authenticated user and account context.
|
|
15
|
+
*/
|
|
16
|
+
export const useConnectLaunchDarkly = () => {
|
|
17
|
+
const ldClient = useState<LDClient | null>('ld-client', () => null)
|
|
18
|
+
const ldFlagSet = useState<LDFlagSet>('ld-flag-set', () => ({}))
|
|
19
|
+
const ldContext = useState<LDMultiKindContext>('ld-context', () => anonymousContext)
|
|
20
|
+
const ldInitialized = useState<boolean>('ld-initialized', () => false)
|
|
21
|
+
const isInitializing = useState<boolean>('ld-is-initializing', () => false)
|
|
22
|
+
|
|
23
|
+
function _createLdContext(): LDMultiKindContext {
|
|
24
|
+
const appName = useRuntimeConfig().public.appName
|
|
25
|
+
const { authUser, isAuthenticated } = useConnectAuth()
|
|
26
|
+
const account = useConnectAccountStore().currentAccount
|
|
27
|
+
|
|
28
|
+
if (!isAuthenticated.value) {
|
|
29
|
+
return anonymousContext
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Create user context
|
|
33
|
+
const user = {
|
|
34
|
+
key: authUser.value.keycloakGuid,
|
|
35
|
+
firstName: authUser.value.firstName,
|
|
36
|
+
lastName: authUser.value.lastName,
|
|
37
|
+
email: authUser.value.email,
|
|
38
|
+
roles: authUser.value.roles,
|
|
39
|
+
loginSource: authUser.value.loginSource,
|
|
40
|
+
appSource: appName
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Default org to user key if no account
|
|
44
|
+
let org: Partial<ConnectAccount> & { key: string, appSource: string } = { key: user.key, appSource: appName }
|
|
45
|
+
|
|
46
|
+
// Use account info if available
|
|
47
|
+
if (account.id) {
|
|
48
|
+
org = {
|
|
49
|
+
key: String(account.id),
|
|
50
|
+
accountType: account.accountType,
|
|
51
|
+
accountStatus: account.accountStatus,
|
|
52
|
+
type: account.type,
|
|
53
|
+
label: account.label,
|
|
54
|
+
appSource: appName
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return { kind: 'multi', org, user }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function _updateLdContext() {
|
|
62
|
+
if (!ldClient.value) {
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const newContext = _createLdContext()
|
|
67
|
+
if (isEqual(ldContext.value, newContext)) {
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
ldContext.value = newContext
|
|
72
|
+
ldClient.value.identify(newContext).then(() => {
|
|
73
|
+
ldFlagSet.value = ldClient.value?.allFlags() || {}
|
|
74
|
+
}).catch((error) => {
|
|
75
|
+
console.error('LaunchDarkly: Failed to update context.', error)
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Initializes the LaunchDarkly client.
|
|
81
|
+
*/
|
|
82
|
+
function _init(): void {
|
|
83
|
+
const rtc = useRuntimeConfig().public
|
|
84
|
+
|
|
85
|
+
// Prevent re-initialization
|
|
86
|
+
if (ldInitialized.value || isInitializing.value) {
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
// Prevent initialization if missing client ID
|
|
90
|
+
if (!rtc.ldClientId) {
|
|
91
|
+
console.error('LaunchDarkly: ldClientId is not configured.')
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
isInitializing.value = true
|
|
96
|
+
|
|
97
|
+
ldContext.value = _createLdContext()
|
|
98
|
+
|
|
99
|
+
const options: LDOptions = {
|
|
100
|
+
streaming: false,
|
|
101
|
+
useReport: false,
|
|
102
|
+
diagnosticOptOut: true
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const client = createClient(rtc.ldClientId, ldContext.value, options)
|
|
107
|
+
|
|
108
|
+
client.start().then((result) => {
|
|
109
|
+
if (result.status === 'complete') {
|
|
110
|
+
ldInitialized.value = true
|
|
111
|
+
isInitializing.value = false
|
|
112
|
+
ldFlagSet.value = client.allFlags()
|
|
113
|
+
console.info('LaunchDarkly: Initialization complete.')
|
|
114
|
+
} else {
|
|
115
|
+
console.error('LaunchDarkly: Initialization did not complete.', result)
|
|
116
|
+
isInitializing.value = false
|
|
117
|
+
}
|
|
118
|
+
}).catch((error) => {
|
|
119
|
+
console.error('LaunchDarkly: Initialization error.', error)
|
|
120
|
+
isInitializing.value = false
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
ldClient.value = client
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error('LaunchDarkly: Failed to initialize.', error)
|
|
126
|
+
isInitializing.value = false
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Initialize only once on the client
|
|
131
|
+
if (!ldInitialized.value && !isInitializing.value && import.meta.client) {
|
|
132
|
+
_init()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const { isAuthenticated } = useConnectAuth()
|
|
136
|
+
const accountStore = useConnectAccountStore()
|
|
137
|
+
|
|
138
|
+
watch(
|
|
139
|
+
[isAuthenticated, () => accountStore.currentAccount],
|
|
140
|
+
() => {
|
|
141
|
+
_updateLdContext()
|
|
142
|
+
},
|
|
143
|
+
{ immediate: true }
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Returns a flag's value. Can operate in two modes.
|
|
148
|
+
* @param name The name of the feature flag.
|
|
149
|
+
* @param defaultValue The value to use until the flag is loaded.
|
|
150
|
+
* @param mode - 'reactive' (default) returns a ref that updates automatically.
|
|
151
|
+
* 'await' returns a promise that resolves when the client is ready.
|
|
152
|
+
* @returns A readonly ref or a promise resolving to the flag's value.
|
|
153
|
+
*/
|
|
154
|
+
function getFeatureFlag<T>(
|
|
155
|
+
name: string,
|
|
156
|
+
defaultValue: T,
|
|
157
|
+
mode: 'await'
|
|
158
|
+
): Promise<T>
|
|
159
|
+
function getFeatureFlag<T>(
|
|
160
|
+
name: string,
|
|
161
|
+
defaultValue: T,
|
|
162
|
+
mode?: 'reactive'
|
|
163
|
+
): Readonly<Ref<T>>
|
|
164
|
+
function getFeatureFlag<T>(
|
|
165
|
+
name: string,
|
|
166
|
+
defaultValue?: T,
|
|
167
|
+
mode?: 'reactive'
|
|
168
|
+
): Readonly<Ref<T | undefined>>
|
|
169
|
+
function getFeatureFlag<T>(
|
|
170
|
+
name: string,
|
|
171
|
+
defaultValue?: T,
|
|
172
|
+
mode: 'reactive' | 'await' = 'reactive'
|
|
173
|
+
): Readonly<Ref<T | undefined>> | Promise<T | undefined> {
|
|
174
|
+
if (mode === 'await') {
|
|
175
|
+
if (!ldClient.value) {
|
|
176
|
+
return Promise.resolve(defaultValue)
|
|
177
|
+
}
|
|
178
|
+
return ldClient.value.waitForInitialization().then(() =>
|
|
179
|
+
ldClient.value ? ldClient.value.variation(name, defaultValue) : defaultValue
|
|
180
|
+
).catch((error) => {
|
|
181
|
+
console.error(`LaunchDarkly: Error waiting for client while getting flag "${name}".`, error)
|
|
182
|
+
return defaultValue
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return readonly(computed(() => {
|
|
187
|
+
if (!ldClient.value || !ldInitialized.value || !ldFlagSet.value) {
|
|
188
|
+
return defaultValue
|
|
189
|
+
}
|
|
190
|
+
return ldClient.value.variation(name, defaultValue)
|
|
191
|
+
}))
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Returns a flag's value from the locally stored flag set. Can operate in two modes.
|
|
196
|
+
* @param name The name of the feature flag.
|
|
197
|
+
* @param defaultValue The value to use until the flag is loaded.
|
|
198
|
+
* @param mode - 'reactive' (default) returns a ref that updates automatically.
|
|
199
|
+
* 'await' returns a promise that resolves when the client is ready.
|
|
200
|
+
* @returns A readonly ref or a promise resolving to the flag's value.
|
|
201
|
+
*/
|
|
202
|
+
async function getStoredFlag<T>(name: string, defaultValue: T, mode: 'await'): Promise<T>
|
|
203
|
+
function getStoredFlag<T>(name: string, defaultValue?: T, mode?: 'reactive'): Readonly<Ref<T>>
|
|
204
|
+
function getStoredFlag<T>(
|
|
205
|
+
name: string,
|
|
206
|
+
defaultValue: T,
|
|
207
|
+
mode: 'reactive' | 'await' = 'reactive'
|
|
208
|
+
): Readonly<Ref<T>> | Promise<T> {
|
|
209
|
+
if (mode === 'await') {
|
|
210
|
+
if (!ldClient.value) {
|
|
211
|
+
return Promise.resolve(defaultValue)
|
|
212
|
+
}
|
|
213
|
+
return ldClient.value.waitForInitialization().then(() =>
|
|
214
|
+
ldFlagSet.value[name] ?? defaultValue
|
|
215
|
+
).catch((error) => {
|
|
216
|
+
console.error(`LaunchDarkly: Error waiting for client while getting stored flag "${name}".`, error)
|
|
217
|
+
return defaultValue
|
|
218
|
+
})
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// reactive mode
|
|
222
|
+
return readonly(computed(() => {
|
|
223
|
+
if (!ldInitialized.value || !ldFlagSet.value) {
|
|
224
|
+
return defaultValue
|
|
225
|
+
}
|
|
226
|
+
return ldFlagSet.value[name] ?? defaultValue
|
|
227
|
+
}))
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Resets the LaunchDarkly state and closes the client connection.
|
|
232
|
+
*/
|
|
233
|
+
const $reset = () => {
|
|
234
|
+
ldInitialized.value = false
|
|
235
|
+
isInitializing.value = false
|
|
236
|
+
ldClient.value?.close()
|
|
237
|
+
ldClient.value = null
|
|
238
|
+
ldFlagSet.value = {}
|
|
239
|
+
ldContext.value = anonymousContext
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
getFeatureFlag,
|
|
244
|
+
getStoredFlag,
|
|
245
|
+
ldInitialized: readonly(ldInitialized),
|
|
246
|
+
ldFlagSet: readonly(ldFlagSet),
|
|
247
|
+
ldClient: readonly(ldClient),
|
|
248
|
+
$reset
|
|
249
|
+
}
|
|
250
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
|
|
2
|
+
<!doctype html>
|
|
3
|
+
<html lang="en">
|
|
4
|
+
|
|
5
|
+
<head>
|
|
6
|
+
<title>Code coverage report for app/app.config.ts</title>
|
|
7
|
+
<meta charset="utf-8" />
|
|
8
|
+
<link rel="stylesheet" href="../prettify.css" />
|
|
9
|
+
<link rel="stylesheet" href="../base.css" />
|
|
10
|
+
<link rel="shortcut icon" type="image/x-icon" href="../favicon.png" />
|
|
11
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
12
|
+
<style type='text/css'>
|
|
13
|
+
.coverage-summary .sorter {
|
|
14
|
+
background-image: url(../sort-arrow-sprite.png);
|
|
15
|
+
}
|
|
16
|
+
</style>
|
|
17
|
+
</head>
|
|
18
|
+
|
|
19
|
+
<body>
|
|
20
|
+
<div class='wrapper'>
|
|
21
|
+
<div class='pad1'>
|
|
22
|
+
<h1><a href="../index.html">All files</a> / <a href="index.html">app</a> app.config.ts</h1>
|
|
23
|
+
<div class='clearfix'>
|
|
24
|
+
|
|
25
|
+
<div class='fl pad1y space-right2'>
|
|
26
|
+
<span class="strong">100% </span>
|
|
27
|
+
<span class="quiet">Statements</span>
|
|
28
|
+
<span class='fraction'>19/19</span>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<div class='fl pad1y space-right2'>
|
|
33
|
+
<span class="strong">100% </span>
|
|
34
|
+
<span class="quiet">Branches</span>
|
|
35
|
+
<span class='fraction'>0/0</span>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
<div class='fl pad1y space-right2'>
|
|
40
|
+
<span class="strong">100% </span>
|
|
41
|
+
<span class="quiet">Functions</span>
|
|
42
|
+
<span class='fraction'>0/0</span>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<div class='fl pad1y space-right2'>
|
|
47
|
+
<span class="strong">100% </span>
|
|
48
|
+
<span class="quiet">Lines</span>
|
|
49
|
+
<span class='fraction'>19/19</span>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
<p class="quiet">
|
|
55
|
+
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
|
56
|
+
</p>
|
|
57
|
+
<template id="filterTemplate">
|
|
58
|
+
<div class="quiet">
|
|
59
|
+
Filter:
|
|
60
|
+
<input type="search" id="fileSearch">
|
|
61
|
+
</div>
|
|
62
|
+
</template>
|
|
63
|
+
</div>
|
|
64
|
+
<div class='status-line high'></div>
|
|
65
|
+
<pre><table class="coverage">
|
|
66
|
+
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
|
|
67
|
+
<a name='L2'></a><a href='#L2'>2</a>
|
|
68
|
+
<a name='L3'></a><a href='#L3'>3</a>
|
|
69
|
+
<a name='L4'></a><a href='#L4'>4</a>
|
|
70
|
+
<a name='L5'></a><a href='#L5'>5</a>
|
|
71
|
+
<a name='L6'></a><a href='#L6'>6</a>
|
|
72
|
+
<a name='L7'></a><a href='#L7'>7</a>
|
|
73
|
+
<a name='L8'></a><a href='#L8'>8</a>
|
|
74
|
+
<a name='L9'></a><a href='#L9'>9</a>
|
|
75
|
+
<a name='L10'></a><a href='#L10'>10</a>
|
|
76
|
+
<a name='L11'></a><a href='#L11'>11</a>
|
|
77
|
+
<a name='L12'></a><a href='#L12'>12</a>
|
|
78
|
+
<a name='L13'></a><a href='#L13'>13</a>
|
|
79
|
+
<a name='L14'></a><a href='#L14'>14</a>
|
|
80
|
+
<a name='L15'></a><a href='#L15'>15</a>
|
|
81
|
+
<a name='L16'></a><a href='#L16'>16</a>
|
|
82
|
+
<a name='L17'></a><a href='#L17'>17</a>
|
|
83
|
+
<a name='L18'></a><a href='#L18'>18</a>
|
|
84
|
+
<a name='L19'></a><a href='#L19'>19</a>
|
|
85
|
+
<a name='L20'></a><a href='#L20'>20</a>
|
|
86
|
+
<a name='L21'></a><a href='#L21'>21</a>
|
|
87
|
+
<a name='L22'></a><a href='#L22'>22</a></td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span>
|
|
88
|
+
<span class="cline-any cline-neutral"> </span>
|
|
89
|
+
<span class="cline-any cline-yes">1x</span>
|
|
90
|
+
<span class="cline-any cline-yes">1x</span>
|
|
91
|
+
<span class="cline-any cline-yes">1x</span>
|
|
92
|
+
<span class="cline-any cline-yes">1x</span>
|
|
93
|
+
<span class="cline-any cline-yes">1x</span>
|
|
94
|
+
<span class="cline-any cline-yes">1x</span>
|
|
95
|
+
<span class="cline-any cline-neutral"> </span>
|
|
96
|
+
<span class="cline-any cline-yes">1x</span>
|
|
97
|
+
<span class="cline-any cline-yes">1x</span>
|
|
98
|
+
<span class="cline-any cline-yes">1x</span>
|
|
99
|
+
<span class="cline-any cline-yes">1x</span>
|
|
100
|
+
<span class="cline-any cline-yes">1x</span>
|
|
101
|
+
<span class="cline-any cline-yes">1x</span>
|
|
102
|
+
<span class="cline-any cline-yes">1x</span>
|
|
103
|
+
<span class="cline-any cline-yes">1x</span>
|
|
104
|
+
<span class="cline-any cline-yes">1x</span>
|
|
105
|
+
<span class="cline-any cline-yes">1x</span>
|
|
106
|
+
<span class="cline-any cline-yes">1x</span>
|
|
107
|
+
<span class="cline-any cline-yes">1x</span>
|
|
108
|
+
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">import { ConnectIdpHint } from '#auth/app/enums/connect-idp-hint'
|
|
109
|
+
|
|
110
|
+
export default defineAppConfig({
|
|
111
|
+
connect: {
|
|
112
|
+
login: {
|
|
113
|
+
redirect: '/',
|
|
114
|
+
idps: [ConnectIdpHint.BCSC, ConnectIdpHint.BCEID, ConnectIdpHint.IDIR],
|
|
115
|
+
skipAccountRedirect: false
|
|
116
|
+
// idpEnforcement: 'strict' - future potentially
|
|
117
|
+
},
|
|
118
|
+
logout: {
|
|
119
|
+
redirect: ''
|
|
120
|
+
},
|
|
121
|
+
header: {
|
|
122
|
+
loginMenu: true,
|
|
123
|
+
createAccount: true,
|
|
124
|
+
notifications: true,
|
|
125
|
+
accountOptionsMenu: true
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
</pre></td></tr></table></pre>
|
|
130
|
+
|
|
131
|
+
<div class='push'></div><!-- for sticky footer -->
|
|
132
|
+
</div><!-- /wrapper -->
|
|
133
|
+
<div class='footer quiet pad2 space-top1 center small'>
|
|
134
|
+
Code coverage generated by
|
|
135
|
+
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
136
|
+
at 2026-01-02T19:47:22.295Z
|
|
137
|
+
</div>
|
|
138
|
+
<script src="../prettify.js"></script>
|
|
139
|
+
<script>
|
|
140
|
+
window.onload = function () {
|
|
141
|
+
prettyPrint();
|
|
142
|
+
};
|
|
143
|
+
</script>
|
|
144
|
+
<script src="../sorter.js"></script>
|
|
145
|
+
<script src="../block-navigation.js"></script>
|
|
146
|
+
</body>
|
|
147
|
+
</html>
|
|
148
|
+
|