Repository navigation
feat: Add @tryabby/vue integration package #234
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
Open
apdoi90
wants to merge
17
commits into
tryabby:main
Choose a base branch
from
apdoi90:feat/bounty-68-3725
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7d7565e
feat: add packages/vue/.gitignore for #68
apdoi90 b5e92ae
feat: add packages/vue/package.json for #68
apdoi90 579bcb6
feat: add packages/vue/README.md for #68
apdoi90 8d11c48
feat: add packages/vue/tsconfig.json for #68
apdoi90 6a49fcb
feat: add packages/vue/tsup.config.ts for #68
apdoi90 62600ee
feat: add packages/vue/vite.config.ts for #68
apdoi90 bcfdfb8
feat: add packages/vue/src/createAbby.ts for #68
apdoi90 9ae84e5
feat: add packages/vue/src/index.ts for #68
apdoi90 a805ada
feat: add packages/vue/src/StorageService.ts for #68
apdoi90 8bf8fb6
feat: add packages/vue/tests/setup.ts for #68
apdoi90 56ce0ea
feat: add packages/vue/tests/types.test.ts for #68
apdoi90 cb8c575
feat: add packages/vue/tests/useAbby.test.ts for #68
apdoi90 b277828
fix(vue): address SSR cleanup, lookup types, fallbacks, devtools guar…
apdoi90 0a8aecc
fix(vue,core): default missing remoteConfig and build core before vue…
apdoi90 3cec08b
fix(vue): skip core rebuild in test script when dist already exists
apdoi90 1103be6
fix(vue): rebuild core before vue tests only when dist is missing or …
apdoi90 f60b85f
Check validation declaration in core build staleness guard
apdoi90 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| dist | ||
| node_modules | ||
| coverage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # `@tryabby/vue` | ||
|
|
||
| Vue 3 and Nuxt integration for [Abby](https://tryabby.com) built on top of `@tryabby/core`. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pnpm add @tryabby/vue | ||
| ``` | ||
|
|
||
| ## Quick Start (Vue 3) | ||
|
|
||
| Create your typed Abby instance once (e.g. `src/abby.ts`): | ||
|
|
||
| ```ts | ||
| import { createAbby, defineConfig } from "@tryabby/vue"; | ||
|
|
||
| const abbyConfig = defineConfig( | ||
| { | ||
| projectId: "your-project-id", | ||
| currentEnvironment: "production", | ||
| }, | ||
| { | ||
| environments: ["development", "production"], | ||
| tests: { | ||
| ctaColor: { variants: ["blue", "green"] }, | ||
| }, | ||
| flags: ["newNavbar"], | ||
| remoteConfig: { | ||
| heroTitle: "String", | ||
| maxItems: "Number", | ||
| }, | ||
| } | ||
| ); | ||
|
|
||
| export const { | ||
| AbbyPlugin, | ||
| AbbyProvider, | ||
| useAbby, | ||
| useFeatureFlag, | ||
| useFeatureFlags, | ||
| useRemoteConfig, | ||
| useRemoteConfigVariables, | ||
| getFeatureFlagValue, | ||
| getRemoteConfig, | ||
| getABTestValue, | ||
| getABResetFunction, | ||
| getVariants, | ||
| updateUserProperties, | ||
| withDevtools, | ||
| } = createAbby(abbyConfig); | ||
| ``` | ||
|
|
||
| Install the plugin in `src/main.ts` (or wrap your tree in `<AbbyProvider>`): | ||
|
|
||
| ```ts | ||
| import { createApp } from "vue"; | ||
| import App from "./App.vue"; | ||
| import { AbbyPlugin } from "./abby"; | ||
|
|
||
| createApp(App).use(AbbyPlugin).mount("#app"); | ||
| ``` | ||
|
|
||
| Use composables inside any component: | ||
|
|
||
| ```vue | ||
| <script setup lang="ts"> | ||
| import { useAbby, useFeatureFlag, useRemoteConfig } from "./abby"; | ||
|
|
||
| const { variant, onAct } = useAbby("ctaColor"); | ||
| const showNewNavbar = useFeatureFlag("newNavbar"); | ||
| const heroTitle = useRemoteConfig("heroTitle"); | ||
| </script> | ||
|
|
||
| <template> | ||
| <header v-if="showNewNavbar">{{ heroTitle }}</header> | ||
| <button @click="onAct">Variant: {{ variant }}</button> | ||
| </template> | ||
| ``` | ||
|
|
||
| ## Nuxt 3 Usage | ||
|
|
||
| Register `AbbyPlugin` inside `plugins/abby.ts`: | ||
|
|
||
| ```ts | ||
| import { AbbyPlugin } from "~/abby"; | ||
|
|
||
| export default defineNuxtPlugin((nuxtApp) => { | ||
| nuxtApp.vueApp.use(AbbyPlugin); | ||
| }); | ||
| ``` | ||
|
|
||
| > **SSR note:** A module-level `createAbby(...)` instance exported from `~/abby` is shared across server requests in Node/Nitro. This works for anonymous/static evaluations, but if your app uses per-request user targeting with `updateUserProperties(...)`, create a fresh `createAbby(...)` instance per request inside `defineNuxtPlugin` so user state is not shared across requests. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| { | ||
| "name": "@tryabby/vue", | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| "version": "0.1.0", | ||
| "description": "Vue 3 and Nuxt integration for Abby", | ||
| "main": "dist/index.js", | ||
| "module": "dist/index.mjs", | ||
| "types": "dist/index.d.ts", | ||
| "files": ["dist"], | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.mjs", | ||
| "require": "./dist/index.js" | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "build": "tsup src/index.ts", | ||
| "dev": "pnpm run build --watch", | ||
| "typecheck": "tsc --noEmit", | ||
| "test": "node -e \"const fs=require('fs'),p=require('path'),cp=require('child_process');const req=['../core/dist/index.mjs','../core/dist/index.js','../core/dist/index.d.ts','../core/dist/validation/index.d.ts'];const maxM=d=>fs.readdirSync(d,{withFileTypes:true}).reduce((m,e)=>{const f=p.join(d,e.name);return Math.max(m,e.isDirectory()?maxM(f):fs.statSync(f).mtimeMs)},0);const stale=!req.every(f=>fs.existsSync(f))||maxM('../core/src')>Math.min(...req.map(f=>fs.statSync(f).mtimeMs));if(stale)cp.execSync('pnpm --filter @tryabby/core build',{stdio:'inherit'})\" && vitest run --typecheck" | ||
| }, | ||
| "homepage": "https://docs.tryabby.com", | ||
| "keywords": ["abby", "vue", "nuxt", "ab-testing", "feature-flags", "remote-config"], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "peerDependencies": { | ||
| "vue": "^3.3.0" | ||
| }, | ||
| "dependencies": { | ||
| "@tryabby/core": "workspace:*", | ||
| "js-cookie": "^3.0.5" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/js-cookie": "^3.0.3", | ||
| "@vue/test-utils": "^2.4.6", | ||
| "jsdom": "^20.0.3", | ||
| "tsconfig": "workspace:*", | ||
| "tsup": "^6.5.0", | ||
| "typescript": "5.5.4", | ||
| "vite": "5.4.0", | ||
| "vitest": "2.0.5", | ||
| "vue": "^3.4.38" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.