@dipswitch/sdk-vue 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Engineers Space LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,64 @@
1
- # Temporary Holding Version
1
+ # @dipswitch/sdk-vue
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Dipswitch feature flags for Vue 3: one plugin, and `useFlag(key, default)` as a reactive ref. It runs on `@dipswitch/sdk-js`, which is installed with it.
4
+
5
+ ## Install
6
+
7
+ Until the packages are on npm, install both tarballs together, so that this package's dependency on `@dipswitch/sdk-js` is met by the second tarball:
8
+
9
+ ```sh
10
+ npm install ./dipswitch-sdk-js-0.1.0.tgz ./dipswitch-sdk-vue-0.1.0.tgz
11
+ ```
12
+
13
+ ## First use
14
+
15
+ The example uses Vue Router for the billing route. If your app uses Vue 3.3.0, install the example's router with `npm install vue-router@4.2.5`.
16
+
17
+ ```ts
18
+ import { createDipswitch, useFlag } from '@dipswitch/sdk-vue'
19
+ import { createApp, defineComponent, h } from 'vue'
20
+ import { createRouter, createWebHistory } from 'vue-router'
21
+
22
+ const dipswitch = createDipswitch({ clientKey: 'ds_client_...', user: { id: 'user-42', name: 'Ana Petrović' } })
23
+
24
+ // In a component: the default until the flags are loaded, then the user's value, following every change.
25
+ const Billing = defineComponent({
26
+ setup() {
27
+ const newBilling = useFlag('new-billing', true)
28
+ return () => (newBilling.value ? h('p', 'New billing') : h('p', 'Old billing'))
29
+ },
30
+ })
31
+
32
+ // When another user signs in, keep the identify under way, so the guard can wait for it.
33
+ let switching: Promise<void> = Promise.resolve()
34
+ function signIn(user: { id: string; name?: string }) {
35
+ switching = dipswitch.client.identify(user)
36
+ }
37
+
38
+ // A router guard waits for the flags, and for a switch of user, before it decides.
39
+ const router = createRouter({ history: createWebHistory(), routes: [{ path: '/billing', component: Billing }] })
40
+ router.beforeEach(async () => {
41
+ await dipswitch.client.ready
42
+ await switching
43
+ return dipswitch.client.isEnabled('new-billing', true)
44
+ })
45
+
46
+ createApp(Billing).use(dipswitch).use(router).mount('#app')
47
+ signIn({ id: 'user-7', name: 'Boris Ilić' })
48
+ ```
49
+
50
+ ## Identity verification
51
+
52
+ For an environment that verifies identity, get the signed-in user's ID and signature from your backend. Pass the signature in the plugin options and with each user switch.
53
+
54
+ ```ts
55
+ import { createDipswitch } from '@dipswitch/sdk-vue'
56
+
57
+ type SignedUser = { id: string; signature: string }
58
+
59
+ export function setupFlags(clientKey: string, first: SignedUser) {
60
+ const dipswitch = createDipswitch({ clientKey, user: { id: first.id }, signature: first.signature })
61
+ const identify = (next: SignedUser) => dipswitch.client.identify({ id: next.id }, next.signature)
62
+ return { dipswitch, identify }
63
+ }
64
+ ```
@@ -0,0 +1,18 @@
1
+ import { ClientOptions, ClientUser, DipswitchClient } from "@dipswitch/sdk-js";
2
+ import { App, Ref } from "vue";
3
+ export interface DipswitchPlugin {
4
+ /** The sdk-js client: `ready` and `identify` for a router guard, `isEnabled` outside components. */
5
+ client: DipswitchClient;
6
+ install(app: App): void;
7
+ }
8
+ /** Creates the sdk-js client and the plugin that hands it to every component. */
9
+ export declare function createDipswitch(options: ClientOptions): DipswitchPlugin;
10
+ /** The client of the app, inside a component's `setup`. */
11
+ export declare function useDipswitch(): DipswitchClient;
12
+ /**
13
+ * A flag's value for the current user, as a read-only ref: `defaultValue`
14
+ * until flags are loaded, and whenever there is no data for the flag. It
15
+ * follows changes and `identify`, and stops listening when the component goes.
16
+ */
17
+ export declare function useFlag(flagKey: string, defaultValue: boolean): Readonly<Ref<boolean>>;
18
+ export type { ClientOptions, ClientUser, DipswitchClient };
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ import { createClient } from "@dipswitch/sdk-js";
2
+ import { inject, onScopeDispose, readonly, shallowRef } from "vue";
3
+ // src/index.ts
4
+ const CLIENT = Symbol("dipswitch");
5
+ /** Creates the sdk-js client and the plugin that hands it to every component. */
6
+ function createDipswitch(options) {
7
+ const client = createClient(options);
8
+ return {
9
+ client,
10
+ install: (app) => void app.provide(CLIENT, client)
11
+ };
12
+ }
13
+ /** The client of the app, inside a component's `setup`. */
14
+ function useDipswitch() {
15
+ const client = inject(CLIENT, void 0);
16
+ if (!client) throw new Error("useFlag and useDipswitch need the plugin: app.use(createDipswitch({ clientKey })).");
17
+ return client;
18
+ }
19
+ /**
20
+ * A flag's value for the current user, as a read-only ref: `defaultValue`
21
+ * until flags are loaded, and whenever there is no data for the flag. It
22
+ * follows changes and `identify`, and stops listening when the component goes.
23
+ */
24
+ function useFlag(flagKey, defaultValue) {
25
+ const client = useDipswitch();
26
+ const value = shallowRef(client.isEnabled(flagKey, defaultValue));
27
+ onScopeDispose(client.onChange(() => value.value = client.isEnabled(flagKey, defaultValue)));
28
+ return readonly(value);
29
+ }
30
+ export { createDipswitch, useDipswitch, useFlag };
package/package.json CHANGED
@@ -1,6 +1,25 @@
1
1
  {
2
2
  "name": "@dipswitch/sdk-vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Dipswitch feature flags for Vue 3: one plugin, and useFlag(key, default) as a reactive ref.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "sideEffects": false,
19
+ "dependencies": {
20
+ "@dipswitch/sdk-js": "0.1.0"
21
+ },
22
+ "peerDependencies": {
23
+ "vue": "^3.3.0"
24
+ }
6
25
  }