Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,965 changes: 985 additions & 980 deletions packages/core/src/index.ts

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/vue/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
node_modules
coverage
93 changes: 93 additions & 0 deletions packages/vue/README.md
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";
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

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.
44 changes: 44 additions & 0 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "@tryabby/vue",
Comment thread
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"
}
}
76 changes: 76 additions & 0 deletions packages/vue/src/StorageService.ts
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();
Loading