|
| 1 | +# Bucket Vue SDK |
| 2 | + |
| 3 | +Vue client side library for [Bucket.co](https://bucket.co) |
| 4 | + |
| 5 | +Bucket supports feature toggling, tracking feature usage, requesting feedback on features and remotely configuring features. |
| 6 | + |
| 7 | +The Bucket Vue SDK comes with the same built-in toolbar as the browser SDK which appears on `localhost` by default. |
| 8 | + |
| 9 | +## Install |
| 10 | + |
| 11 | +Install via npm: |
| 12 | + |
| 13 | +```shell |
| 14 | +npm i @bucketco/vue-sdk |
| 15 | +``` |
| 16 | + |
| 17 | +## Get started |
| 18 | + |
| 19 | +### 1. Wrap your application with the `BucketProvider` |
| 20 | + |
| 21 | +```vue |
| 22 | +<script setup lang="ts"> |
| 23 | +import { BucketProvider } from '@bucketco/vue-sdk' |
| 24 | +</script> |
| 25 | +
|
| 26 | +<BucketProvider |
| 27 | + publishableKey="{YOUR_PUBLISHABLE_KEY}" |
| 28 | + :company="{ id: 'acme_inc', plan: 'pro' }" |
| 29 | + :user="{ id: 'john doe' }" |
| 30 | +> |
| 31 | + <!-- your app --> |
| 32 | +</BucketProvider> |
| 33 | +``` |
| 34 | + |
| 35 | +### 2. Create a new feature and set up type safety |
| 36 | + |
| 37 | +Install the Bucket CLI: |
| 38 | + |
| 39 | +```shell |
| 40 | +npm i --save-dev @bucketco/cli |
| 41 | +``` |
| 42 | + |
| 43 | +Run `npx bucket new` to create your first feature! |
| 44 | +On the first run, it will sign into Bucket and set up type generation for your project: |
| 45 | + |
| 46 | +```shell |
| 47 | +❯ npx bucket new |
| 48 | +Opened web browser to facilitate login: https://app.bucket.co/api/oauth/cli/authorize |
| 49 | + |
| 50 | +Welcome to Bucket! |
| 51 | + |
| 52 | +? Where should we generate the types? gen/features.d.ts |
| 53 | +? What is the output format? vue |
| 54 | +✔ Configuration created at bucket.config.json. |
| 55 | + |
| 56 | +Creating feature for app Slick app. |
| 57 | +? New feature name: Huddle |
| 58 | +? New feature key: huddle |
| 59 | +✔ Created feature Huddle with key huddle (https://app.bucket.co/features/huddles) |
| 60 | +✔ Generated vue types in gen/features.d.ts. |
| 61 | +``` |
| 62 | + |
| 63 | +> [!Note] |
| 64 | +> By default, types will be generated in `gen/features.d.ts`. |
| 65 | +> The default `tsconfig.json` file `include`s this file by default, but if your `tsconfig.json` is different, make sure the file is covered in the `include` property. |
| 66 | +
|
| 67 | +### 3. Use `useFeature(key)` to get feature status |
| 68 | + |
| 69 | +```vue |
| 70 | +<script setup lang="ts"> |
| 71 | +import { useFeature } from '@bucketco/vue-sdk' |
| 72 | +
|
| 73 | +const huddle = useFeature('huddle') |
| 74 | +</script> |
| 75 | +
|
| 76 | +<template> |
| 77 | + <button v-if="huddle.isEnabled" @click="huddle.track()"> |
| 78 | + {{ huddle.config?.payload?.buttonTitle ?? 'Start Huddle' }} |
| 79 | + </button> |
| 80 | +</template> |
| 81 | +``` |
| 82 | + |
| 83 | +See the [browser SDK documentation](../browser-sdk/README.md) for all available methods. |
0 commit comments