Repository navigation
feat(vue): add @tryabby/vue integration package with composables and tests (#68) #227
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,36 @@ | ||
| # `@tryabby/vue` | ||
|
|
||
| Official Vue 3 & Nuxt integration for [Abby](https://tryabby.com) feature flags, A/B testing, and remote configuration. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pnpm add @tryabby/vue | ||
| ``` | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ```ts | ||
| import { createAbby, defineConfig } from "@tryabby/vue"; | ||
|
|
||
| const config = defineConfig({ | ||
| projectId: "<YOUR_PROJECT_ID>", | ||
| currentEnvironment: "production", | ||
| environments: ["production", "development"], | ||
| flags: ["darkMode"], | ||
| tests: { | ||
| heroBanner: { variants: ["Control", "VariantB"] }, | ||
| }, | ||
| remoteConfig: { | ||
| welcomeCopy: "String", | ||
| }, | ||
| }); | ||
|
|
||
| export const { | ||
| AbbyProvider, | ||
| abbyPlugin, | ||
| useAbby, | ||
| useFeatureFlag, | ||
| useRemoteConfig, | ||
| } = createAbby(config); | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| { | ||
| "name": "@tryabby/vue", | ||
| "version": "1.0.0", | ||
|
Comment on lines
+1
to
+3
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.
|
||
| "description": "Official Vue 3 & Nuxt integration for Abby feature flags, A/B testing, and remote config", | ||
| "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/index.ts", | ||
| "dev": "pnpm run build --watch", | ||
| "test": "vitest run" | ||
| }, | ||
| "homepage": "https://docs.tryabby.com", | ||
| "keywords": ["abby", "vue", "nuxt", "feature-flags", "ab-testing", "remote-config"], | ||
| "license": "ISC", | ||
| "peerDependencies": { | ||
| "vue": "^3.2.0" | ||
| }, | ||
| "dependencies": { | ||
| "@tryabby/core": "workspace:*", | ||
| "js-cookie": "^3.0.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@tryabby/devtools": "workspace:*", | ||
| "@types/js-cookie": "^3.0.3", | ||
| "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.0" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| 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.
Pass both arguments to
defineConfig.The re-exported
defineConfigrequiresdynamicConfigandconfig. This quick start passes one object, so TypeScript reports a missing argument. PutprojectIdandcurrentEnvironmentin the first object. Putenvironments,flags,tests, andremoteConfigin the second. (raw.githubusercontent.com)