diff --git a/.github/workflows/vue.yml b/.github/workflows/vue.yml index 9470739964..05559c6fc9 100644 --- a/.github/workflows/vue.yml +++ b/.github/workflows/vue.yml @@ -23,10 +23,15 @@ jobs: workspace_name: '@launchdarkly/vue-client-sdk' workspace_path: packages/sdk/vue should_build_docs: false - - name: Build example + - name: Build getting-started example run: | yarn workspaces focus @launchdarkly/vue-client-sdk-example-getting-started yarn workspaces foreach -pR --topological-dev --from '@launchdarkly/vue-client-sdk-example-getting-started' run build + - name: Build and type-check data-saving-mode example + run: | + yarn workspaces focus @launchdarkly/vue-client-sdk-example-data-saving-mode + yarn workspaces foreach -pR --topological-dev --from '@launchdarkly/vue-client-sdk-example-data-saving-mode' run build + yarn workspace @launchdarkly/vue-client-sdk-example-data-saving-mode run tsc run-example: runs-on: ubuntu-latest diff --git a/package.json b/package.json index 1be36967b3..0990163365 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,8 @@ "packages/sdk/openfeature-node-server/examples/getting-started", "packages/sdk/vue", "packages/sdk/vue/contract-tests", - "packages/sdk/vue/examples/getting-started" + "packages/sdk/vue/examples/getting-started", + "packages/sdk/vue/examples/features/data-saving-mode" ], "private": true, "scripts": { diff --git a/packages/sdk/react/examples/features/data-saving-mode/README.md b/packages/sdk/react/examples/features/data-saving-mode/README.md index cf92c30474..44bb633707 100644 --- a/packages/sdk/react/examples/features/data-saving-mode/README.md +++ b/packages/sdk/react/examples/features/data-saving-mode/README.md @@ -12,8 +12,9 @@ FDv2 **data saving mode** (`dataSystem`) configuration. - Enabling the FDv2 data system through the provider's `ldOptions` (`dataSystem: {}`), in [`src/LDClient.tsx`](./src/LDClient.tsx). -- Evaluating a flag with `useBoolVariation`, which updates live as the data - system delivers changes. +- Evaluating a flag with `useBoolVariation`, which updates live once you switch + the connection mode to `streaming` or `polling` (the browser default, + `one-shot`, fetches once at page load and does not update afterward). - Switching the connection mode at runtime (`streaming`, `polling`, `offline`, `one-shot`, `background`, or automatic) via `useLDClient().setConnectionMode`. - Toggling streaming via `setStreaming`. diff --git a/packages/sdk/react/examples/features/data-saving-mode/src/LDClient.tsx b/packages/sdk/react/examples/features/data-saving-mode/src/LDClient.tsx index e152b88ecc..5426792b2e 100644 --- a/packages/sdk/react/examples/features/data-saving-mode/src/LDClient.tsx +++ b/packages/sdk/react/examples/features/data-saving-mode/src/LDClient.tsx @@ -12,12 +12,12 @@ export const initialContext: LDContext = { const options: LDReactProviderOptions = { ldOptions: { - // Enable the FDv2 data system. An empty object opts in with default - // behavior: a streaming connection for real-time flag updates, with - // polling as a fallback. + // Enable the FDv2 data system. An empty object opts in with the browser + // default: a one-time flag fetch at page load (cache, then polling, then + // streaming as fallbacks), with no further updates afterward. // - // Data saving mode is an Early Access feature. To pin a specific - // connection mode instead, use manual mode switching, for example: + // Data saving mode is an Early Access feature. To get live updates, or to + // pin a specific connection mode, use manual mode switching, for example: // dataSystem: { // automaticModeSwitching: { type: 'manual', initialConnectionMode: 'polling' }, // }, diff --git a/packages/sdk/vue/examples/README.md b/packages/sdk/vue/examples/README.md index 083a229a58..63b9713f09 100644 --- a/packages/sdk/vue/examples/README.md +++ b/packages/sdk/vue/examples/README.md @@ -5,3 +5,4 @@ This directory contains example applications demonstrating the LaunchDarkly Vue | Example | Description | |---------|-------------| | [getting-started](./getting-started/) | Minimal Vite + Vue app that evaluates a boolean feature flag and reactively displays the result with real-time updates. This is the recommended starting point. | +| [features/data-saving-mode](./features/data-saving-mode/) | Minimal Vite + Vue app that exercises the Vue SDK's FDv2 data saving mode (`dataSystem`) configuration. Data saving mode is an Early Access Program (EAP) feature. | diff --git a/packages/sdk/vue/examples/features/data-saving-mode/.env.example b/packages/sdk/vue/examples/features/data-saving-mode/.env.example new file mode 100644 index 0000000000..0f4dc41688 --- /dev/null +++ b/packages/sdk/vue/examples/features/data-saving-mode/.env.example @@ -0,0 +1,5 @@ +# Set when running yarn start / yarn build +# (e.g. LAUNCHDARKLY_CLIENT_SIDE_ID=xxx LAUNCHDARKLY_FLAG_KEY=my-flag yarn start). + +LAUNCHDARKLY_CLIENT_SIDE_ID= +LAUNCHDARKLY_FLAG_KEY=sample-feature diff --git a/packages/sdk/vue/examples/features/data-saving-mode/.gitignore b/packages/sdk/vue/examples/features/data-saving-mode/.gitignore new file mode 100644 index 0000000000..066b5c5fff --- /dev/null +++ b/packages/sdk/vue/examples/features/data-saving-mode/.gitignore @@ -0,0 +1,11 @@ +/node_modules +/dist +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local +.env +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/packages/sdk/vue/examples/features/data-saving-mode/README.md b/packages/sdk/vue/examples/features/data-saving-mode/README.md new file mode 100644 index 0000000000..76a3afd71b --- /dev/null +++ b/packages/sdk/vue/examples/features/data-saving-mode/README.md @@ -0,0 +1,40 @@ +# LaunchDarkly Vue SDK FDv2 example + +A minimal [Vite](https://vitejs.dev/) + Vue 3 app that exercises the Vue SDK's +FDv2 **data saving mode** (`dataSystem`) configuration. + +> [!NOTE] +> Data saving mode is a LaunchDarkly Early Access Program (EAP) feature. The +> `dataSystem` option and its behaviors are not stable and may change before +> General Availability. + +## What it demonstrates + +- Enabling the FDv2 data system through the plugin's `ldOptions` + (`dataSystem: {}`), in [`src/LDClient.ts`](./src/LDClient.ts). +- Evaluating a flag with `useBoolVariation`, which updates live once you switch + the connection mode to `streaming` or `polling` (the browser default, + `one-shot`, fetches once at page load and does not update afterward). +- Switching the connection mode at runtime (`streaming`, `polling`, `offline`, + `one-shot`, `background`, or automatic) via `useLDClient().setConnectionMode`. +- Toggling streaming via `setStreaming`. +- Switching the evaluation context via `identify`. + +## Run it + +This example uses the workspace build of `@launchdarkly/vue-client-sdk`. From the +repository root, build the SDK and its dependencies first: + +```bash +yarn workspaces foreach -pR --topological-dev --from '@launchdarkly/vue-client-sdk' run build +``` + +Then start the example with your client-side ID (and optionally a flag key): + +```bash +LAUNCHDARKLY_CLIENT_SIDE_ID=your-client-side-id \ +LAUNCHDARKLY_FLAG_KEY=your-flag-key \ +yarn workspace @launchdarkly/vue-client-sdk-example-data-saving-mode start +``` + +Open the URL Vite prints (default ). diff --git a/packages/sdk/vue/examples/features/data-saving-mode/index.html b/packages/sdk/vue/examples/features/data-saving-mode/index.html new file mode 100644 index 0000000000..300e9a19b1 --- /dev/null +++ b/packages/sdk/vue/examples/features/data-saving-mode/index.html @@ -0,0 +1,12 @@ + + + + + + LaunchDarkly Vue SDK FDv2 Example + + +
+ + + diff --git a/packages/sdk/vue/examples/features/data-saving-mode/package.json b/packages/sdk/vue/examples/features/data-saving-mode/package.json new file mode 100644 index 0000000000..6fbc9c2af7 --- /dev/null +++ b/packages/sdk/vue/examples/features/data-saving-mode/package.json @@ -0,0 +1,22 @@ +{ + "name": "@launchdarkly/vue-client-sdk-example-data-saving-mode", + "version": "0.1.0", + "private": true, + "type": "module", + "scripts": { + "start": "vite", + "build": "vite build", + "preview": "vite preview", + "tsc": "vue-tsc --noEmit" + }, + "dependencies": { + "@launchdarkly/vue-client-sdk": "0.2.0", + "vue": "^3.3.0" + }, + "devDependencies": { + "@vitejs/plugin-vue": "^5.1.2", + "vue-tsc": "3.3.9", + "typescript": "^5.5.3", + "vite": "^5.4.1" + } +} diff --git a/packages/sdk/vue/examples/features/data-saving-mode/src/App.vue b/packages/sdk/vue/examples/features/data-saving-mode/src/App.vue new file mode 100644 index 0000000000..b045d66980 --- /dev/null +++ b/packages/sdk/vue/examples/features/data-saving-mode/src/App.vue @@ -0,0 +1,176 @@ + + + + + diff --git a/packages/sdk/vue/examples/features/data-saving-mode/src/LDClient.ts b/packages/sdk/vue/examples/features/data-saving-mode/src/LDClient.ts new file mode 100644 index 0000000000..3d6548d7c4 --- /dev/null +++ b/packages/sdk/vue/examples/features/data-saving-mode/src/LDClient.ts @@ -0,0 +1,22 @@ +import type { LDContext, LDVueClientOptions } from '@launchdarkly/vue-client-sdk'; + +export const LAUNCHDARKLY_CLIENT_SIDE_ID = import.meta.env.LAUNCHDARKLY_CLIENT_SIDE_ID ?? ''; + +// The initial evaluation context. This context should appear on your +// LaunchDarkly contexts dashboard soon after you run the demo. +export const initialContext: LDContext = { + kind: 'user', + key: 'example-user-key', + name: 'Sandy', +}; + +// Enable the FDv2 data system. An empty object opts in with the browser default: +// a one-time flag fetch at page load (cache, then polling, then streaming as +// fallbacks), with no further updates afterward. +// +// Data saving mode is an Early Access feature. To get live updates, or to pin +// a specific connection mode, use manual mode switching, for example: +// dataSystem: { +// automaticModeSwitching: { type: 'manual', initialConnectionMode: 'polling' }, +// }, +export const ldOptions: LDVueClientOptions = { dataSystem: {} }; diff --git a/packages/sdk/vue/examples/features/data-saving-mode/src/index.css b/packages/sdk/vue/examples/features/data-saving-mode/src/index.css new file mode 100644 index 0000000000..d049c4cbae --- /dev/null +++ b/packages/sdk/vue/examples/features/data-saving-mode/src/index.css @@ -0,0 +1,6 @@ +body { + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; + background-color: #f4f5f8; + color: #21242b; +} diff --git a/packages/sdk/vue/examples/features/data-saving-mode/src/main.ts b/packages/sdk/vue/examples/features/data-saving-mode/src/main.ts new file mode 100644 index 0000000000..479b5ca3a2 --- /dev/null +++ b/packages/sdk/vue/examples/features/data-saving-mode/src/main.ts @@ -0,0 +1,14 @@ +import { createApp } from 'vue'; +import { LDVuePlugin } from '@launchdarkly/vue-client-sdk'; + +import App from './App.vue'; +import { initialContext, LAUNCHDARKLY_CLIENT_SIDE_ID, ldOptions } from './LDClient'; +import './index.css'; + +createApp(App) + .use(LDVuePlugin, { + clientSideID: LAUNCHDARKLY_CLIENT_SIDE_ID, + context: initialContext, + ldOptions, + }) + .mount('#app'); diff --git a/packages/sdk/vue/examples/features/data-saving-mode/src/shims-vue.d.ts b/packages/sdk/vue/examples/features/data-saving-mode/src/shims-vue.d.ts new file mode 100644 index 0000000000..37a085b7ea --- /dev/null +++ b/packages/sdk/vue/examples/features/data-saving-mode/src/shims-vue.d.ts @@ -0,0 +1,6 @@ +declare module '*.vue' { + import type { DefineComponent } from 'vue'; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const component: DefineComponent, Record, any>; + export default component; +} diff --git a/packages/sdk/vue/examples/features/data-saving-mode/src/vite-env.d.ts b/packages/sdk/vue/examples/features/data-saving-mode/src/vite-env.d.ts new file mode 100644 index 0000000000..11f02fe2a0 --- /dev/null +++ b/packages/sdk/vue/examples/features/data-saving-mode/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/packages/sdk/vue/examples/features/data-saving-mode/tsconfig.json b/packages/sdk/vue/examples/features/data-saving-mode/tsconfig.json new file mode 100644 index 0000000000..beb06c73f1 --- /dev/null +++ b/packages/sdk/vue/examples/features/data-saving-mode/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "target": "ES2020", + "lib": ["dom", "dom.iterable", "esnext"], + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "module": "ESNext", + "moduleResolution": "bundler", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "preserve", + "verbatimModuleSyntax": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/packages/sdk/vue/examples/features/data-saving-mode/vite.config.ts b/packages/sdk/vue/examples/features/data-saving-mode/vite.config.ts new file mode 100644 index 0000000000..30182ca163 --- /dev/null +++ b/packages/sdk/vue/examples/features/data-saving-mode/vite.config.ts @@ -0,0 +1,7 @@ +import vue from '@vitejs/plugin-vue'; +import { defineConfig } from 'vite'; + +export default defineConfig({ + plugins: [vue()], + envPrefix: ['VITE_', 'LAUNCHDARKLY_'], +}); diff --git a/release-please-config.json b/release-please-config.json index bfd941819b..f155f7a0a2 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -430,6 +430,11 @@ "type": "json", "path": "examples/getting-started/package.json", "jsonpath": "$.dependencies['@launchdarkly/vue-client-sdk']" + }, + { + "type": "json", + "path": "examples/features/data-saving-mode/package.json", + "jsonpath": "$.dependencies['@launchdarkly/vue-client-sdk']" } ] }