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
5 changes: 5 additions & 0 deletions .changeset/tryabby-vue-integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tryabby/vue": minor
---

Add `@tryabby/vue`, a Vue 3 & Nuxt integration for Abby. It ships fully-typed `useAbby`, `useFeatureFlag`, and `useRemoteConfig` composables, an `AbbyProvider` plugin for data loading/SSR, and non-reactive getters — with the same API surface and type quality as the React and Svelte packages.
1 change: 1 addition & 0 deletions packages/vue/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
127 changes: 127 additions & 0 deletions packages/vue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# @tryabby/vue

The official [Abby](https://www.tryabby.com) integration for **Vue 3** and **Nuxt**.

It gives you fully-typed composables for A/B tests, feature flags and remote config, with the same API surface and type quality as the React and Svelte packages.

## Installation

```bash
npm install @tryabby/vue
# or
pnpm add @tryabby/vue
```

## Quick start

Create your Abby instance once and export the composables from it:

```ts
// abby.ts
import { createAbby } from "@tryabby/vue";

export const {
useAbby,
useFeatureFlag,
useRemoteConfig,
AbbyProvider,
getFeatureFlagValue,
getRemoteConfig,
getABTestValue,
} = createAbby({
projectId: "<YOUR_PROJECT_ID>",
currentEnvironment: import.meta.env.MODE,
environments: ["development", "production"],
tests: {
"footer-test": { variants: ["old", "new"] },
},
flags: ["new-dashboard"],
remoteConfig: { theme: "String" },
});
```

Register the `AbbyProvider` plugin on your app. It loads your project data on
the client (and accepts server-fetched `initialData` for SSR):

```ts
// main.ts
import { createApp } from "vue";
import App from "./App.vue";
import { AbbyProvider } from "./abby";

createApp(App).use(AbbyProvider).mount("#app");
```

## Composables

### `useAbby`

Returns the reactive variant for a test and an `onAct` callback to report an
interaction. The variant is a `ComputedRef`, so it works in templates directly.

```vue
<script setup lang="ts">
import { useAbby } from "./abby";

const { variant, onAct } = useAbby("footer-test");
</script>

<template>
<NewFooter v-if="variant === 'new'" @click="onAct" />
<OldFooter v-else @click="onAct" />
</template>
```

You can also pass a lookup object to map each variant to a value:

```ts
const { variant } = useAbby("footer-test", { old: 0, new: 1 });
// variant.value is 0 | 1
```

### `useFeatureFlag`

```vue
<script setup lang="ts">
import { useFeatureFlag } from "./abby";

const showDashboard = useFeatureFlag("new-dashboard"); // Ref<boolean>
</script>
```

### `useRemoteConfig`

```vue
<script setup lang="ts">
import { useRemoteConfig } from "./abby";

const theme = useRemoteConfig("theme"); // Ref<string>
</script>
```

## Non-reactive helpers

For places outside of a component's reactive scope (route guards, plain
modules, event handlers) the instance also exposes plain getters:

- `getFeatureFlagValue(name)` – the current value of a feature flag
- `getRemoteConfig(name)` – the current value of a remote config entry
- `getABTestValue(name, lookup?)` – the currently selected variant of a test
- `getVariants(name)` – all variants of a test
- `getABResetFunction(name)` – resets the persisted variant of a test
- `updateUserProperties(user)` – updates user properties for targeting

## Nuxt / SSR

To avoid hydration mismatches, `useAbby` renders an empty variant on the server
and resolves the real variant on mount. When you fetch project data on the
server, hand it to the provider so flags and remote config are available during
the first render:

```ts
app.use(AbbyProvider, { initialData });
```

## License

ISC
46 changes: 46 additions & 0 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@tryabby/vue",
"version": "0.1.0",
"description": "Vue 3 & Nuxt integration for Abby",
"main": "dist/index.js",
"files": ["dist"],
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"homepage": "https://docs.tryabby.com",
"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",
"typecheck": "tsc --noEmit"
},
"keywords": ["abby", "vue", "nuxt", "feature-flags", "ab-testing"],
"author": "",
"license": "ISC",
"peerDependencies": {
"vue": "^3.3.0"
},
"devDependencies": {
"@types/js-cookie": "^3.0.3",
"@vue/test-utils": "^2.4.6",
"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"
},
"dependencies": {
"@tryabby/core": "workspace:*",
"js-cookie": "^3.0.5"
}
}
68 changes: 68 additions & 0 deletions packages/vue/src/StorageService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {
type IStorageService,
type StorageServiceOptions,
getABStorageKey,
getFFStorageKey,
getRCStorageKey,
} from "@tryabby/core";
import Cookie from "js-cookie";

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 : 365,
});
}

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);
}

remove(projectId: string, flagName: string): void {
Cookie.remove(getFFStorageKey(projectId, flagName));
}
}
Comment on lines +34 to +49

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Feature-flag/remote-config cookies are session-only, unlike AB test cookies.

ABStorageService.set persists cookies for 365 days by default, but FFStorageService.set (Line 42-44) and RCStorageService.set (Line 57-59) call Cookie.set without an expires option, so js-cookie creates session cookies that vanish on browser close. This is an inconsistent persistence contract across the three storage types with no apparent intent behind the difference.

🍪 Proposed fix to align persistence behavior
 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);
+  set(
+    projectId: string,
+    flagName: string,
+    value: string,
+    options?: StorageServiceOptions
+  ): void {
+    Cookie.set(getFFStorageKey(projectId, flagName), value, {
+      expires: options?.expiresInDays ?? 365,
+    });
   }

   remove(projectId: string, flagName: string): void {
     Cookie.remove(getFFStorageKey(projectId, flagName));
   }
 }

Apply the same pattern to RCStorageService.set.

Also applies to: 51-64

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/vue/src/StorageService.ts` around lines 34 - 49, FFStorageService
and RCStorageService are creating session-only cookies because their set methods
call Cookie.set without an expires option, unlike ABStorageService.set. Update
the set implementations in FFStorageService and RCStorageService to use the same
persistence policy as ABStorageService, reusing the existing cookie key helpers
like getFFStorageKey and the remote-config equivalent so all storage types
behave consistently across browser restarts.


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);
}

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