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 change: 1 addition & 0 deletions packages/vue/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
176 changes: 176 additions & 0 deletions packages/vue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# @tryabby/vue

## createAbby

### Parameters

The `createAbby` function takes an object as a parameter. The object can contain the following properties:

| Name | Type | Required | Description | details |
| ------------------ | -------- | :------: | ------------------------------------------------------- | --------------------- |
| projectId | `string` | ✅ | The ID of your project in Abby | - |
| apiUrl | `string` | | The URL of the Abby API. Defaults to the hosted version | - |
| currentEnvironment | `string` | ✅ | The current environment of your application | [link](/environments) |
| tests | `object` | | An object containing your defined A/B Tests | - |
| flags | `object` | | An array containing your defined Feature Flags | - |
| settings | `object` | | An object with additional settings for Abby | - |

#### tests

The tests property is an object containing your defined A/B Tests. You probably want to use the Copy Button in your dashboard to copy the tests object.
They keys of the object represent the names of your predefined A/B tests. The values are objects containing the following properties:

| Name | Type | Required | Description |
| -------- | --------------- | :------: | ------------------------------------------------------- |
| variants | `Array<string>` | ✅ | An array of strings containing the variants of the test |

##### Example

```ts
const abby = createAbby({
// ... your config
tests: {
"test-abtest": {
variants: ["control", "variant-a", "variant-b"],
},
},
});
```

#### flags

The flags property is an array containing your defined Feature Flags. You probably want to use the Copy Button in your dashboard to copy the flags array.

##### Example

```ts
const abby = createAbby({
// ... your config
flags: { "test-flag": "Boolean" },
});
```

#### settings

The settings property is an object containing additional settings for Abby. The following properties are available:

- `flags.defaultValues`: Allows you to set a general default value for each flag type. The keys of the object represent the types of the flags.
The default value is the following:

```json
{
"Boolean": false,
"String": "",
"Number": 0,
"JSON": {}
}
```

- `flags.devOverrides`: An object containing the values of feature flags in development mode. The keys of the object represent the names of the flags.
The values need to be of the type of the flag. This means if your flag is a `String` flag, this needs to be a `string`.

### Return Values

#### useAbby

`useAbby` is a react hook that used to access the value of an A/B Test.
Recurring users will always get the same value for a test.
New users will get a random value for a test depending on the defined weights

##### Parameters

- `string`: The name of the test or flag, needs to be one of the defined tests.

##### Return Values

- `variant` : The variant of the test

- `onAct`: A function to call when the user performs an action associated with the test _Type: `function`_

#### useFeatureFlag

`useFeatureFlag` is a react hook that used to access the value of a Feature Flag.

##### Parameters

The name of the test or flag, needs to be one of the defined flags.

##### Return Value

The value of the flag _Type: `boolean`_

#### AbbyProvider

A react component to wrap your application.

##### Props

- `children`: The children of the component
- `initialData (optional)`: The data (weights, tests, etc). If not provided, the data will be fetched on the client.

#### getFeatureFlagValue

`getFeatureFlagValue` is a function to access the value of a feature flag. This can be called in a non-react scope

##### Parameters

The name of the test or flag, needs to be one of the defined flags.

#### getABTestValue

`getABTestValue` is a function to access the users variant of an A/B Test. This can be called in a non-react scope.
If the user is new, a random variant will be generated based on the weights, persisted in a cookie and returned.
Otherwise the variant will be read from the cookie and returned.

##### Parameters

The name of the test, needs to be one of the defined tests.

##### Return Values

The variant of the test.

#### withDevtools

`withDevtools` is a higher order function to wrap the Devtools from [`@tryabby/devtools`](/devtools) for usage within Reacts.

##### Parameters

The Devtools component from `@tryabby/devtools`

##### Example

```jsx
import { AbbyDevTools } from "@tryabby/devtools";
export const AbbyDevtools = withDevtools(AbbyDevTools);
```

#### getABResetFunction

This is a function which returns a function that can be used to reset the stored variant for the current user.
This means the cookie will be deleted and the user will get a new variant on the next page load.

#### Parameters

The name of the test, needs to be one of the defined tests.

#### Example

```tsx
import { getABResetFunction } from "lib/abby";

export default function SomePage() {
const onReset = () => {
const resetCookie = getABResetFunction("SignupButton");
resetCookie();
window.reload();
};

return (
<div>
<h1>Hello World</h1>
<button onClick={onReset}>Reset Cookie</button>
</div>
);
}
```
Comment on lines +1 to +176
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Documentation contains React-specific content instead of Vue integration details

The documentation appears to be copied from the React package without proper adaptation for Vue. This needs to be completely reworked to use Vue-specific terminology and concepts:

  1. Replace React hooks with Vue composables:

    • useAbby should be documented as a Vue composable
    • useFeatureFlag should be documented as a Vue composable
  2. Replace React components with Vue components:

    • AbbyProvider should be documented as a Vue component or plugin
    • Examples should use Vue template syntax
  3. Update implementation examples to use Vue's composition API style

Would you like assistance in generating Vue-specific documentation templates for these sections?

🧰 Tools
🪛 LanguageTool

[grammar] ~21-~21: The pronoun ‘They’ must be used with a non-third-person form of a verb.
Context: ...ashboard to copy the tests object. They keys of the object represent the names of yo...

(NON3PRS_VERB)


[uncategorized] ~57-~57: Loose punctuation mark.
Context: ... are available: - flags.defaultValues: Allows you to set a general default val...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~69-~69: Loose punctuation mark.
Context: ...N": {} } ``` - flags.devOverrides: An object containing the values of feat...

(UNLIKELY_OPENING_PUNCTUATION)


[grammar] ~76-~76: “React” is a proper noun and needs to be capitalized.
Context: ...rn Values #### useAbby useAbby is a react hook that used to access the value of a...

(A_GOOGLE)


[uncategorized] ~82-~82: Loose punctuation mark.
Context: ...ed weights ##### Parameters - string: The name of the test or flag, needs to ...

(UNLIKELY_OPENING_PUNCTUATION)


[style] ~82-~82: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...string: The name of the test or flag, needs to be one of the defined tests. ##### Ret...

(REP_NEED_TO_VB)


[uncategorized] ~86-~86: Loose punctuation mark.
Context: ...ests. ##### Return Values - variant : The variant of the test - onAct: A f...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~88-~88: Loose punctuation mark.
Context: ...nt: The variant of the test -onAct`: A function to call when the user perfor...

(UNLIKELY_OPENING_PUNCTUATION)


[grammar] ~92-~92: “React” is a proper noun and needs to be capitalized.
Context: ...# useFeatureFlag useFeatureFlag is a react hook that used to access the value of a...

(A_GOOGLE)


[grammar] ~104-~104: “React” is a proper noun and needs to be capitalized.
Context: ...Type: boolean #### AbbyProvider A react component to wrap your application. ##...

(A_GOOGLE)


[uncategorized] ~108-~108: Loose punctuation mark.
Context: ... application. ##### Props - children: The children of the component - `initia...

(UNLIKELY_OPENING_PUNCTUATION)


[style] ~109-~109: In American English, abbreviations like “etc.” require a period.
Context: ... (optional)`: The data (weights, tests, etc). If not provided, the data will be fet...

(ETC_PERIOD)


[uncategorized] ~122-~122: A comma may be missing after the conjunctive/linking adverb ‘Otherwise’.
Context: ...ts, persisted in a cookie and returned. Otherwise the variant will be read from the cooki...

(SENT_START_CONJUNCTIVE_LINKING_ADVERB_COMMA)


[formatting] ~127-~127: If the ‘needs’ clause is essential to the meaning, do not use a comma before the clause.
Context: ...ned. ##### Parameters The name of the test, needs to be one of the defined tests. ##### ...

(COMMA_AFTER_PREPOSITION_PHRASES)


[uncategorized] ~135-~135: Did you mean the adjective “higher-order” (spelled with a hyphen)?
Context: ... #### withDevtools withDevtools is a higher order function to wrap the Devtools from [`@t...

(HIGHER_ORDER_HYPHEN)


[uncategorized] ~151-~151: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ...r. This means the cookie will be deleted and the user will get a new variant on the ...

(COMMA_COMPOUND_SENTENCE_2)


[formatting] ~155-~155: If the ‘needs’ clause is essential to the meaning, do not use a comma before the clause.
Context: ...load. #### Parameters The name of the test, needs to be one of the defined tests. #### E...

(COMMA_AFTER_PREPOSITION_PHRASES)

47 changes: 47 additions & 0 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@tryabby/vue",
"version": "0.1.0",
"description": "",
"main": "dist/index.js",
"files": ["dist"],
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
"scripts": {
"build": "tsup src/",
"dev": "pnpm run build --watch",
"test": "vitest"
},
"homepage": "https://docs.tryabby.com",
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/vue": "^8.1.0",
"@vue/test-utils": "^2.4.6",
"@tryabby/devtools": "workspace:*",
"@types/js-cookie": "^3.0.3",
"@vitejs/plugin-vue": "5.1.4",
"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"
},
Comment on lines +23 to +39
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Clean up development dependencies.

There are several issues with the devDependencies:

  1. React-related testing packages are included but not needed for a Vue package
  2. Vue is missing from devDependencies
  3. Version patterns are inconsistent

Apply these changes:

   "devDependencies": {
-    "@testing-library/jest-dom": "^5.16.5",
-    "@testing-library/react": "^13.4.0",
     "@testing-library/vue": "^8.1.0",
     "@vue/test-utils": "^2.4.6",
     "@tryabby/devtools": "workspace:*",
     "@types/js-cookie": "^3.0.3",
     "@vitejs/plugin-vue": "5.1.4",
     "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"
+    "vitest": "2.0.5",
+    "vue": "^3.5.12"
   },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"devDependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/vue": "^8.1.0",
"@vue/test-utils": "^2.4.6",
"@tryabby/devtools": "workspace:*",
"@types/js-cookie": "^3.0.3",
"@vitejs/plugin-vue": "5.1.4",
"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"
},
"devDependencies": {
"@testing-library/vue": "^8.1.0",
"@vue/test-utils": "^2.4.6",
"@tryabby/devtools": "workspace:*",
"@types/js-cookie": "^3.0.3",
"@vitejs/plugin-vue": "5.1.4",
"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.5.12"
},

"peerDependencies": {
"vue": "^3.5.12"
},
"dependencies": {
"@tryabby/core": "workspace:*",
"js-cookie": "^3.0.1"
}
}
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,
getABStorageKey,
getFFStorageKey,
getRCStorageKey,
} from "@tryabby/core";
import type { StorageServiceOptions } from "@tryabby/core/dist/shared/interfaces";
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));
}
}
Comment on lines +12 to +36
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling and type validation

The ABStorageService implementation should handle potential cookie-related errors and validate input types:

 class ABStorageService implements IStorageService {
   get(projectId: string, testName: string): string | null {
+    try {
       const retrievedValue = Cookie.get(getABStorageKey(projectId, testName));
       if (!retrievedValue) return null;
       return retrievedValue;
+    } catch (error) {
+      console.error(`Failed to retrieve A/B test value: ${error}`);
+      return null;
+    }
   }

   set(
     projectId: string,
     testName: string,
     value: string,
     options?: StorageServiceOptions
   ): void {
+    if (!projectId || !testName) {
+      throw new Error('Project ID and test name are required');
+    }
+    try {
       Cookie.set(getABStorageKey(projectId, testName), value, {
         expires: options?.expiresInDays
           ? options.expiresInDays
           : DEFAULT_COOKIE_AGE,
       });
+    } catch (error) {
+      console.error(`Failed to set A/B test value: ${error}`);
+      throw error;
+    }
   }

Committable suggestion skipped: line range outside the PR's diff.


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));
}
}
Comment on lines +38 to +55
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Reduce code duplication and standardize API

Consider creating a base storage service class to reduce duplication and maintain consistency:

+abstract class BaseStorageService implements IStorageService {
+  constructor(protected getStorageKey: (projectId: string, key: string) => string) {}
+
+  get(projectId: string, key: string): string | null {
+    try {
+      const retrievedValue = Cookie.get(this.getStorageKey(projectId, key));
+      return retrievedValue ?? null;
+    } catch (error) {
+      console.error(`Failed to retrieve value: ${error}`);
+      return null;
+    }
+  }
+
+  set(projectId: string, key: string, value: string, options?: StorageServiceOptions): void {
+    if (!projectId || !key) {
+      throw new Error('Project ID and key are required');
+    }
+    try {
+      Cookie.set(this.getStorageKey(projectId, key), value, {
+        expires: options?.expiresInDays ?? DEFAULT_COOKIE_AGE,
+      });
+    } catch (error) {
+      console.error(`Failed to set value: ${error}`);
+      throw error;
+    }
+  }
+
+  remove(projectId: string, key: string): void {
+    Cookie.remove(this.getStorageKey(projectId, key));
+  }
+}

-class FFStorageService implements IStorageService {
+class FFStorageService extends BaseStorageService {
+  constructor() {
+    super(getFFStorageKey);
+  }
-  // Remove duplicated methods
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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));
}
}
abstract class BaseStorageService implements IStorageService {
constructor(protected getStorageKey: (projectId: string, key: string) => string) {}
get(projectId: string, key: string): string | null {
try {
const retrievedValue = Cookie.get(this.getStorageKey(projectId, key));
return retrievedValue ?? null;
} catch (error) {
console.error(`Failed to retrieve value: ${error}`);
return null;
}
}
set(projectId: string, key: string, value: string, options?: StorageServiceOptions): void {
if (!projectId || !key) {
throw new Error('Project ID and key are required');
}
try {
Cookie.set(this.getStorageKey(projectId, key), value, {
expires: options?.expiresInDays ?? DEFAULT_COOKIE_AGE,
});
} catch (error) {
console.error(`Failed to set value: ${error}`);
throw error;
}
}
remove(projectId: string, key: string): void {
Cookie.remove(this.getStorageKey(projectId, key));
}
}
class FFStorageService extends BaseStorageService {
constructor() {
super(getFFStorageKey);
}
}


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