Repository navigation
feat(vue): add @tryabby/vue integration package (#68) #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| dist |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| # @tryabby/vue | ||
|
|
||
| Vue 3 integration for [Abby](https://tryabby.com) - A/B testing, feature flags, and remote config. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| npm install @tryabby/vue | ||
| # or | ||
| pnpm add @tryabby/vue | ||
| # or | ||
| yarn add @tryabby/vue | ||
| ``` | ||
|
|
||
| ## Quickstart | ||
|
|
||
| ### 1. Initialize Abby | ||
|
|
||
| Create an Abby instance with your project configuration: | ||
|
|
||
| ```ts | ||
| // abby.ts | ||
| import { createAbby } from "@tryabby/vue"; | ||
|
|
||
| export const { | ||
| useAbby, | ||
| useFeatureFlag, | ||
| useFeatureFlags, | ||
| useRemoteConfig, | ||
| useRemoteConfigVariables, | ||
| AbbyProvider, | ||
| AbbyPlugin, | ||
| } = createAbby({ | ||
| projectId: "your-project-id", | ||
| currentEnvironment: "production", | ||
| tests: { | ||
| heroTitle: { | ||
| variants: ["headlineA", "headlineB"], | ||
| }, | ||
| }, | ||
| flags: { | ||
| newCheckout: "Boolean", | ||
| }, | ||
|
Comment on lines
+41
to
+43
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Pass feature-flag names as an array. Core defines 🤖 Prompt for AI Agents
|
||
| remoteConfig: { | ||
| bannerText: "String", | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| ### 2. Provide Abby Context | ||
|
|
||
| You can wrap your application with `<AbbyProvider>` or use `app.use(AbbyPlugin)`: | ||
|
|
||
| #### Option A: Component Provider | ||
|
|
||
| ```vue | ||
| <!-- App.vue --> | ||
| <script setup lang="ts"> | ||
| import { AbbyProvider } from "./abby"; | ||
| </script> | ||
|
|
||
| <template> | ||
| <AbbyProvider> | ||
| <RouterView /> | ||
| </AbbyProvider> | ||
| </template> | ||
| ``` | ||
|
|
||
| #### Option B: Vue Plugin | ||
|
|
||
| ```ts | ||
| // main.ts | ||
| import { createApp } from "vue"; | ||
| import App from "./App.vue"; | ||
| import { AbbyPlugin } from "./abby"; | ||
|
|
||
| const app = createApp(App); | ||
| app.use(AbbyPlugin); | ||
| app.mount("#app"); | ||
| ``` | ||
|
|
||
| ### 3. Use Composables | ||
|
|
||
| #### A/B Testing (`useAbby`) | ||
|
|
||
| ```vue | ||
| <script setup lang="ts"> | ||
| import { useAbby } from "./abby"; | ||
|
|
||
| const { variant, onAct } = useAbby("heroTitle", { | ||
| headlineA: "Supercharge your business", | ||
| headlineB: "The fastest way to grow", | ||
| }); | ||
| </script> | ||
|
|
||
| <template> | ||
| <div> | ||
| <h1>{{ variant }}</h1> | ||
| <button @click="onAct">Get Started</button> | ||
| </div> | ||
| </template> | ||
| ``` | ||
|
|
||
| #### Feature Flags (`useFeatureFlag`) | ||
|
|
||
| ```vue | ||
| <script setup lang="ts"> | ||
| import { useFeatureFlag } from "./abby"; | ||
|
|
||
| const newCheckoutEnabled = useFeatureFlag("newCheckout"); | ||
| </script> | ||
|
|
||
| <template> | ||
| <NewCheckout v-if="newCheckoutEnabled" /> | ||
| <LegacyCheckout v-else /> | ||
| </template> | ||
| ``` | ||
|
|
||
| #### Remote Config (`useRemoteConfig`) | ||
|
|
||
| ```vue | ||
| <script setup lang="ts"> | ||
| import { useRemoteConfig } from "./abby"; | ||
|
|
||
| const bannerText = useRemoteConfig("bannerText"); | ||
| </script> | ||
|
|
||
| <template> | ||
| <div v-if="bannerText" class="announcement"> | ||
| {{ bannerText }} | ||
| </div> | ||
| </template> | ||
| ``` | ||
|
|
||
| ## Synchronous Helpers | ||
|
|
||
| Direct programmatic access outside Vue components: | ||
|
|
||
| ```ts | ||
| import { | ||
| getABTestValue, | ||
| getFeatureFlagValue, | ||
| getRemoteConfig, | ||
| } from "./abby"; | ||
|
|
||
| const variant = getABTestValue("heroTitle"); | ||
| const flag = getFeatureFlagValue("newCheckout"); | ||
| const banner = getRemoteConfig("bannerText"); | ||
| ``` | ||
|
|
||
| ## License | ||
|
|
||
| ISC | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| { | ||
| "name": "@tryabby/vue", | ||
| "version": "1.0.0", | ||
| "description": "Vue 3 integration for Abby A/B testing and feature flags", | ||
| "main": "dist/index.js", | ||
| "files": ["dist"], | ||
| "module": "dist/index.mjs", | ||
| "types": "dist/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.mjs", | ||
| "require": "./dist/index.js" | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "build": "tsup src/", | ||
| "dev": "tsup src/ --watch", | ||
| "test": "vitest run" | ||
| }, | ||
| "homepage": "https://docs.tryabby.com", | ||
| "keywords": ["abby", "vue", "vue3", "a/b testing", "feature flags", "remote config"], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "peerDependencies": { | ||
| "vue": "^3.3.0" | ||
| }, | ||
| "dependencies": { | ||
| "@tryabby/core": "workspace:*", | ||
| "js-cookie": "^3.0.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@tryabby/devtools": "workspace:*", | ||
| "@types/js-cookie": "^3.0.3", | ||
| "jsdom": "^20.0.3", | ||
| "msw": "^0.49.1", | ||
| "node-fetch": "^3.3.0", | ||
| "tsconfig": "workspace:*", | ||
| "tsup": "^6.5.0", | ||
| "typescript": "5.5.4", | ||
| "vite": "5.4.0", | ||
| "vitest": "2.0.5", | ||
| "vue": "^3.4.0" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { | ||
| type IStorageService, | ||
| type StorageServiceOptions, | ||
| getABStorageKey, | ||
| getFFStorageKey, | ||
| getRCStorageKey, | ||
| } from "@tryabby/core"; | ||
| import Cookie from "js-cookie"; | ||
|
|
||
| const DEFAULT_COOKIE_AGE = 365; | ||
|
|
||
| class ABStorageService implements IStorageService { | ||
| get(projectId: string, testName: string): string | null { | ||
| const retrievedValue = Cookie.get(getABStorageKey(projectId, testName)); | ||
| if (!retrievedValue) return null; | ||
|
|
||
| return retrievedValue; | ||
| } | ||
|
|
||
| set( | ||
| projectId: string, | ||
| testName: string, | ||
| value: string, | ||
| options?: StorageServiceOptions | ||
| ): void { | ||
| Cookie.set(getABStorageKey(projectId, testName), value, { | ||
| expires: options?.expiresInDays | ||
| ? options.expiresInDays | ||
| : DEFAULT_COOKIE_AGE, | ||
| }); | ||
| } | ||
|
|
||
| remove(projectId: string, testName: string): void { | ||
| Cookie.remove(getABStorageKey(projectId, testName)); | ||
| } | ||
| } | ||
|
|
||
| class FFStorageService implements IStorageService { | ||
| get(projectId: string, flagName: string): string | null { | ||
| const retrievedValue = Cookie.get(getFFStorageKey(projectId, flagName)); | ||
| if (!retrievedValue) return null; | ||
|
|
||
| return retrievedValue; | ||
| } | ||
|
|
||
| set(projectId: string, flagName: string, value: string): void { | ||
| Cookie.set(getFFStorageKey(projectId, flagName), value, { | ||
| expires: DEFAULT_COOKIE_AGE, | ||
| }); | ||
| } | ||
|
|
||
| remove(projectId: string, flagName: string): void { | ||
| Cookie.remove(getFFStorageKey(projectId, flagName)); | ||
| } | ||
| } | ||
|
|
||
| class RCStorageService implements IStorageService { | ||
| get(projectId: string, key: string): string | null { | ||
| const retrievedValue = Cookie.get(getRCStorageKey(projectId, key)); | ||
| return retrievedValue ?? null; | ||
| } | ||
|
|
||
| set(projectId: string, key: string, value: string): void { | ||
| Cookie.set(getRCStorageKey(projectId, key), value, { | ||
| expires: DEFAULT_COOKIE_AGE, | ||
| }); | ||
| } | ||
|
|
||
| remove(projectId: string, key: string): void { | ||
| Cookie.remove(getRCStorageKey(projectId, key)); | ||
| } | ||
| } | ||
|
|
||
| export const TestStorageService = new ABStorageService(); | ||
| export const FlagStorageService = new FFStorageService(); | ||
| export const RemoteConfigStorageService = new RCStorageService(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Add the required
environmentsconfiguration.The documented
createAbbycall omitsenvironments, whichAbbyConfigrequires. A TypeScript user who copies this quickstart gets a configuration type error. Addenvironments: ["production"]besidecurrentEnvironment. (raw.githubusercontent.com)🤖 Prompt for AI Agents