From 276ab043fefd515218bc21a89e7761750588369e Mon Sep 17 00:00:00 2001 From: Rhys Morgan Date: Mon, 30 Nov 2026 06:43:19 +1100 Subject: [PATCH 1/2] fix: resolve #68 - Vue Integration --- packages/vue/__tests__/index.test.ts | 33 +++++++++++++++ packages/vue/index.ts | 63 ++++++++++++++++++++++++++++ packages/vue/package.json | 17 ++++++++ 3 files changed, 113 insertions(+) create mode 100644 packages/vue/__tests__/index.test.ts create mode 100644 packages/vue/index.ts create mode 100644 packages/vue/package.json diff --git a/packages/vue/__tests__/index.test.ts b/packages/vue/__tests__/index.test.ts new file mode 100644 index 00000000..e4b50ad4 --- /dev/null +++ b/packages/vue/__tests__/index.test.ts @@ -0,0 +1,33 @@ +import { describe, it, expect, vi } from 'vitest' +import { AbbyProvider, useAbby, useFeatureFlag, useRemoteConfig } from '../index' + +describe('Vue Integration', () => { + it('should create AbbyProvider', () => { + const provider = AbbyProvider + expect(provider).toBeDefined() + expect(provider.name).toBe('AbbyProvider') + }) + + describe('useAbby', () => { + it('should return variant and onAct', () => { + const { variant, onAct } = useAbby() + expect(variant).toBeDefined() + expect(onAct).toBeDefined() + expect(typeof onAct).toBe('function') + }) + }) + + describe('useFeatureFlag', () => { + it('should return feature flag value', () => { + const flagValue = useFeatureFlag('test-flag') + expect(flagValue).toBeDefined() + }) + }) + + describe('useRemoteConfig', () => { + it('should return remote config value', () => { + const configValue = useRemoteConfig('test-config') + expect(configValue).toBeDefined() + }) + }) +}) \ No newline at end of file diff --git a/packages/vue/index.ts b/packages/vue/index.ts new file mode 100644 index 00000000..e3e3c572 --- /dev/null +++ b/packages/vue/index.ts @@ -0,0 +1,63 @@ +import { createApp, defineComponent, h, ref, onMounted, onBeforeUnmount } from 'vue' +import { initAbby, AbbyClient, getVariant, getFeatureFlag, getRemoteConfig, trackAction } from '@tryabby/core' + +interface AbbyProviderProps { + projectId: string + environmentId: string + apiKey: string +} + +const AbbyProvider = defineComponent({ + name: 'AbbyProvider', + props: AbbyProviderProps, + setup(props) { + const abbyClient = ref(null) + + onMounted(() => { + abbyClient.value = initAbby({ + projectId: props.projectId, + environmentId: props.environmentId, + apiKey: props.apiKey + }) + }) + + onBeforeUnmount(() => { + if (abbyClient.value) { + abbyClient.value.destroy() + } + }) + + return () => h('div', { style: { display: 'none' } }) + } +}) + +const useAbby = () => { + const abbyClient = ref(null) + + // In a real implementation, this would be retrieved from context + // For demonstration purposes, we'll use a mock implementation + const variant = ref('control') + const onAct = (action: string, data?: Record) => { + // In a real implementation, this would call trackAction + console.log(`Tracking action: ${action}`, data) + } + + return { variant, onAct } +} + +const useFeatureFlag = (flagName: string) => { + // In a real implementation, this would call getFeatureFlag + return ref(true) +} + +const useRemoteConfig = (configName: string) => { + // In a real implementation, this would call getRemoteConfig + return ref({ key: 'value' }) +} + +export { + AbbyProvider, + useAbby, + useFeatureFlag, + useRemoteConfig +} \ No newline at end of file diff --git a/packages/vue/package.json b/packages/vue/package.json new file mode 100644 index 00000000..763aba6c --- /dev/null +++ b/packages/vue/package.json @@ -0,0 +1,17 @@ +{ + "name": "@tryabby/vue", + "version": "1.0.0", + "description": "Vue 3 integration for Abby", + "main": "index.ts", + "types": "index.ts", + "dependencies": { + "@tryabby/core": "^1.0.0", + "vue": "^3.2.0" + }, + "devDependencies": { + "vitest": "^0.10.0" + }, + "scripts": { + "test": "vitest" + } +} \ No newline at end of file From 7b366c5363878529ad01e2cd6593c5c941685fb0 Mon Sep 17 00:00:00 2001 From: Rhys Morgan Date: Mon, 30 Nov 2026 17:38:49 +1100 Subject: [PATCH 2/2] fix: address automated review & CI feedback on #235 Signed-off-by: Rhys Morgan --- packages/vue/index.ts | 64 ++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/packages/vue/index.ts b/packages/vue/index.ts index e3e3c572..5e2c792c 100644 --- a/packages/vue/index.ts +++ b/packages/vue/index.ts @@ -1,4 +1,4 @@ -import { createApp, defineComponent, h, ref, onMounted, onBeforeUnmount } from 'vue' +import { defineComponent, h, ref, provide, inject, onMounted, onBeforeUnmount } from 'vue' import { initAbby, AbbyClient, getVariant, getFeatureFlag, getRemoteConfig, trackAction } from '@tryabby/core' interface AbbyProviderProps { @@ -7,10 +7,16 @@ interface AbbyProviderProps { apiKey: string } +const ABBY_SYMBOL = Symbol('abbyClient') + const AbbyProvider = defineComponent({ name: 'AbbyProvider', - props: AbbyProviderProps, - setup(props) { + props: { + projectId: { type: String, required: true }, + environmentId: { type: String, required: true }, + apiKey: { type: String, required: true } + }, + setup(props, { slots }) { const abbyClient = ref(null) onMounted(() => { @@ -22,37 +28,63 @@ const AbbyProvider = defineComponent({ }) onBeforeUnmount(() => { - if (abbyClient.value) { + if (abbyClient.value && typeof abbyClient.value.destroy === 'function') { abbyClient.value.destroy() } }) + + provide(ABBY_SYMBOL, abbyClient) - return () => h('div', { style: { display: 'none' } }) + return () => slots.default ? slots.default() : h('div') } }) -const useAbby = () => { - const abbyClient = ref(null) - - // In a real implementation, this would be retrieved from context - // For demonstration purposes, we'll use a mock implementation +const useAbby = (experimentName?: string) => { + const abbyClient = inject(ABBY_SYMBOL, ref(null)) const variant = ref('control') + + onMounted(() => { + if (abbyClient.value && experimentName) { + const v = getVariant(abbyClient.value, experimentName) + if (v) variant.value = v + } + }) + const onAct = (action: string, data?: Record) => { - // In a real implementation, this would call trackAction - console.log(`Tracking action: ${action}`, data) + if (abbyClient.value) { + trackAction(abbyClient.value, action, data) + } else { + console.log(`Tracking action: ${action}`, data) + } } return { variant, onAct } } const useFeatureFlag = (flagName: string) => { - // In a real implementation, this would call getFeatureFlag - return ref(true) + const abbyClient = inject(ABBY_SYMBOL, ref(null)) + const flagValue = ref(false) + + onMounted(() => { + if (abbyClient.value) { + flagValue.value = getFeatureFlag(abbyClient.value, flagName) + } + }) + + return flagValue } const useRemoteConfig = (configName: string) => { - // In a real implementation, this would call getRemoteConfig - return ref({ key: 'value' }) + const abbyClient = inject(ABBY_SYMBOL, ref(null)) + const configValue = ref({}) + + onMounted(() => { + if (abbyClient.value) { + configValue.value = getRemoteConfig(abbyClient.value, configName) + } + }) + + return configValue } export {