@sbc-connect/nuxt-base 0.7.3 → 0.9.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @sbc-connect/nuxt-base
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#160](https://github.com/bcgov/connect-nuxt/pull/160) [`80b8318`](https://github.com/bcgov/connect-nuxt/commit/80b8318ab802a14f77e9fe88f96e66aaf23e18ad) Thanks [@deetz99](https://github.com/deetz99)! - Update Nuxt, pinia colada, keycloak, nuxt ui, i18n, vueuse, dompurify, es-toolkit, zod.
8
+
9
+ ## 0.8.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#158](https://github.com/bcgov/connect-nuxt/pull/158) [`fe5065e`](https://github.com/bcgov/connect-nuxt/commit/fe5065e12d776349e7093e52ecee51ce22a2c271) Thanks [@vysakh-menon-aot](https://github.com/vysakh-menon-aot)! - Switch LD dependency to js-client-sdk
14
+
3
15
  ## 0.7.3
4
16
 
5
17
  ### Patch Changes
@@ -8,7 +8,7 @@ const { myLayer } = useAppConfig()
8
8
  <h1>Hello World!</h1>
9
9
  <pre>{{ myLayer }}</pre>
10
10
  <p class="text-gray-900">
11
- Hello World text base should be gray-900 test
11
+ Hello World text base should be gray-900 test 3
12
12
  </p>
13
13
  </div>
14
14
  </template>
@@ -1,69 +1,72 @@
1
- import { initialize } from 'launchdarkly-js-client-sdk'
2
- import type { LDClient, LDFlagSet, LDOptions, LDContext } from 'launchdarkly-js-client-sdk'
3
-
4
- // state
5
- // Defined outside of composable, so they are created only once and shared
6
- const ldClient = shallowRef<LDClient | null>(null)
7
- const ldFlagSet = shallowRef<LDFlagSet>({})
8
- const ldInitialized = ref(false)
9
- const isInitializing = ref(false)
1
+ import { createClient } from '@launchdarkly/js-client-sdk'
2
+ import type { LDClient, LDFlagSet, LDOptions, LDContext } from '@launchdarkly/js-client-sdk'
10
3
 
11
4
  /**
12
- * Initializes the LaunchDarkly client with an anonymous context.
13
- */
14
- function init(): void {
15
- const rtc = useRuntimeConfig().public
16
-
17
- // Prevent re-initialization
18
- if (ldInitialized.value || isInitializing.value) {
19
- return
20
- }
21
- // Prevent initialization if missing client ID
22
- if (!rtc.ldClientId) {
23
- console.error('LaunchDarkly: ldClientId is not configured.')
24
- return
25
- }
5
+ * Composable for the LaunchDarkly service.
6
+ */
7
+ export const useConnectLaunchDarkly = () => {
8
+ const ldClient = useState<LDClient | null>('ld-client', () => null)
9
+ const ldFlagSet = useState<LDFlagSet>('ld-flag-set', () => ({}))
10
+ const ldInitialized = useState<boolean>('ld-initialized', () => false)
11
+ const isInitializing = useState<boolean>('ld-is-initializing', () => false)
26
12
 
27
- isInitializing.value = true
13
+ /**
14
+ * Initializes the LaunchDarkly client with an anonymous context.
15
+ */
16
+ function init(): void {
17
+ const rtc = useRuntimeConfig().public
28
18
 
29
- const ldContext: LDContext = {
30
- kind: 'user',
31
- key: 'anonymous',
32
- anonymous: true,
33
- appSource: rtc.appName
34
- }
19
+ // Prevent re-initialization
20
+ if (ldInitialized.value || isInitializing.value) {
21
+ return
22
+ }
23
+ // Prevent initialization if missing client ID
24
+ if (!rtc.ldClientId) {
25
+ console.error('LaunchDarkly: ldClientId is not configured.')
26
+ return
27
+ }
35
28
 
36
- const options: LDOptions = {
37
- streaming: false,
38
- useReport: false,
39
- diagnosticOptOut: true
40
- }
29
+ isInitializing.value = true
41
30
 
42
- try {
43
- ldClient.value = initialize(rtc.ldClientId, ldContext, options)
31
+ const ldContext: LDContext = {
32
+ kind: 'user',
33
+ key: 'anonymous',
34
+ anonymous: true,
35
+ appSource: rtc.appName
36
+ }
44
37
 
45
- ldClient.value.on('initialized', () => {
46
- ldFlagSet.value = ldClient.value?.allFlags() || {}
47
- ldInitialized.value = true
48
- isInitializing.value = false
49
- console.info('LaunchDarkly: Anonymous initialization complete.')
50
- })
38
+ const options: LDOptions = {
39
+ streaming: false,
40
+ useReport: false,
41
+ diagnosticOptOut: true
42
+ }
51
43
 
52
- ldClient.value.on('error', (error) => {
53
- console.error('LaunchDarkly: Initialization error.', error)
44
+ try {
45
+ const client = createClient(rtc.ldClientId, ldContext, options)
46
+
47
+ client.start().then((result) => {
48
+ if (result.status === 'complete') {
49
+ ldFlagSet.value = client.allFlags()
50
+ ldInitialized.value = true
51
+ isInitializing.value = false
52
+ console.info('LaunchDarkly: Anonymous initialization complete.')
53
+ } else {
54
+ console.error('LaunchDarkly: Initialization did not complete.', result)
55
+ isInitializing.value = false
56
+ }
57
+ }).catch((error) => {
58
+ console.error('LaunchDarkly: Initialization error.', error)
59
+ isInitializing.value = false
60
+ })
61
+
62
+ ldClient.value = client
63
+ } catch (error) {
64
+ console.error('LaunchDarkly: Failed to initialize.', error)
54
65
  isInitializing.value = false
55
- })
56
- } catch (error) {
57
- console.error('LaunchDarkly: Failed to initialize.', error)
58
- isInitializing.value = false
66
+ }
59
67
  }
60
- }
61
68
 
62
- /**
63
- * Composable for the LaunchDarkly service.
64
- */
65
- export const useConnectLaunchDarkly = () => {
66
- // initialize only once
69
+ // Initialize only once on the client
67
70
  if (!ldInitialized.value && !isInitializing.value && import.meta.client) {
68
71
  init()
69
72
  }
@@ -95,12 +98,12 @@ export const useConnectLaunchDarkly = () => {
95
98
  if (!ldClient.value) {
96
99
  return Promise.resolve(defaultValue)
97
100
  }
98
- return ldClient.value.waitUntilReady()
99
- .then(() => ldClient.value ? ldClient.value.variation(name, defaultValue) : defaultValue)
100
- .catch((error) => {
101
- console.error(`LaunchDarkly: Error waiting for client while getting flag "${name}".`, error)
102
- return defaultValue
103
- })
101
+ return ldClient.value.waitForInitialization().then(() =>
102
+ ldClient.value ? ldClient.value.variation(name, defaultValue) : defaultValue
103
+ ).catch((error) => {
104
+ console.error(`LaunchDarkly: Error waiting for client while getting flag "${name}".`, error)
105
+ return defaultValue
106
+ })
104
107
  }
105
108
 
106
109
  // reactive mode
@@ -131,12 +134,12 @@ export const useConnectLaunchDarkly = () => {
131
134
  if (!ldClient.value) {
132
135
  return Promise.resolve(defaultValue)
133
136
  }
134
- return ldClient.value.waitUntilReady()
135
- .then(() => ldFlagSet.value[name] ?? defaultValue)
136
- .catch((error) => {
137
- console.error(`LaunchDarkly: Error waiting for client while getting stored flag "${name}".`, error)
138
- return defaultValue
139
- })
137
+ return ldClient.value.waitForInitialization().then(() =>
138
+ ldFlagSet.value[name] ?? defaultValue
139
+ ).catch((error) => {
140
+ console.error(`LaunchDarkly: Error waiting for client while getting stored flag "${name}".`, error)
141
+ return defaultValue
142
+ })
140
143
  }
141
144
 
142
145
  // reactive mode
package/nuxt.config.ts CHANGED
@@ -143,5 +143,19 @@ export default defineNuxtConfig({
143
143
  statusApiUrl: '',
144
144
  statusApiVersion: ''
145
145
  }
146
+ },
147
+
148
+ vite: {
149
+ optimizeDeps: {
150
+ include: [
151
+ '@launchdarkly/js-client-sdk',
152
+ '@vue/devtools-core',
153
+ '@vue/devtools-kit',
154
+ 'dompurify',
155
+ 'es-toolkit',
156
+ 'maska/vue',
157
+ 'zod'
158
+ ]
159
+ }
146
160
  }
147
161
  })
package/package.json CHANGED
@@ -1,33 +1,33 @@
1
1
  {
2
2
  "name": "@sbc-connect/nuxt-base",
3
3
  "type": "module",
4
- "version": "0.7.3",
4
+ "version": "0.9.0",
5
5
  "repository": "github:bcgov/connect-nuxt",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "./nuxt.config.ts",
8
8
  "dependencies": {
9
9
  "@iconify-json/mdi": "1.2.3",
10
- "@nuxt/ui": "4.6.0",
11
- "@nuxtjs/i18n": "10.2.4",
12
- "@vueuse/core": "14.2.1",
13
- "@vueuse/nuxt": "14.2.1",
14
- "dompurify": "3.3.3",
15
- "es-toolkit": "1.45.1",
16
- "launchdarkly-vue-client-sdk": "2.5.0",
10
+ "@launchdarkly/js-client-sdk": "4.6.5",
11
+ "@nuxt/ui": "4.7.1",
12
+ "@nuxtjs/i18n": "10.3.0",
13
+ "@vueuse/core": "14.3.0",
14
+ "@vueuse/nuxt": "14.3.0",
15
+ "dompurify": "3.4.5",
16
+ "es-toolkit": "1.46.1",
17
17
  "luxon": "3.7.2",
18
18
  "maska": "3.2.0",
19
- "zod": "4.3.6"
19
+ "zod": "4.4.3"
20
20
  },
21
21
  "devDependencies": {
22
- "@axe-core/playwright": "4.11.1",
22
+ "@axe-core/playwright": "4.11.3",
23
23
  "@types/luxon": "3.7.1",
24
- "dotenv": "17.3.1",
25
- "nuxt": "4.2.2",
24
+ "dotenv": "^17.4.2",
25
+ "nuxt": "4.4.6",
26
26
  "typescript": "5.9.3",
27
27
  "vue-tsc": "3.2.5",
28
28
  "@sbc-connect/eslint-config": "0.0.8",
29
- "@sbc-connect/vitest-config": "0.1.1",
30
- "@sbc-connect/playwright-config": "0.1.1"
29
+ "@sbc-connect/playwright-config": "0.2.0",
30
+ "@sbc-connect/vitest-config": "0.2.0"
31
31
  },
32
32
  "scripts": {
33
33
  "preinstall": "npx only-allow pnpm",