@schematichq/schematic-vue 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 +22 -0
- package/README.md +281 -0
- package/dist/schematic-vue.cjs.js +1692 -0
- package/dist/schematic-vue.d.ts +239 -0
- package/dist/schematic-vue.esm.js +1669 -0
- package/package.json +60 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { App } from 'vue';
|
|
2
|
+
import { CheckFlagReturn } from '@schematichq/schematic-js';
|
|
3
|
+
import { ComputedRef } from 'vue';
|
|
4
|
+
import { Event as Event_2 } from '@schematichq/schematic-js';
|
|
5
|
+
import { EventBody } from '@schematichq/schematic-js';
|
|
6
|
+
import { EventBodyIdentify } from '@schematichq/schematic-js';
|
|
7
|
+
import { EventBodyTrack } from '@schematichq/schematic-js';
|
|
8
|
+
import { EventType } from '@schematichq/schematic-js';
|
|
9
|
+
import { Keys } from '@schematichq/schematic-js';
|
|
10
|
+
import { Ref } from 'vue';
|
|
11
|
+
import { RuleType } from '@schematichq/schematic-js';
|
|
12
|
+
import { Schematic } from '@schematichq/schematic-js';
|
|
13
|
+
import { SchematicContext } from '@schematichq/schematic-js';
|
|
14
|
+
import * as SchematicJS from '@schematichq/schematic-js';
|
|
15
|
+
import { SchematicOptions } from '@schematichq/schematic-js';
|
|
16
|
+
import { StoragePersister } from '@schematichq/schematic-js';
|
|
17
|
+
import { Traits } from '@schematichq/schematic-js';
|
|
18
|
+
import { UsagePeriod } from '@schematichq/schematic-js';
|
|
19
|
+
|
|
20
|
+
declare type BaseSchematicPluginOptions = Omit<SchematicJS.SchematicOptions, "client" | "publishableKey">;
|
|
21
|
+
|
|
22
|
+
export { CheckFlagReturn }
|
|
23
|
+
|
|
24
|
+
export { Event_2 as Event }
|
|
25
|
+
|
|
26
|
+
export { EventBody }
|
|
27
|
+
|
|
28
|
+
export { EventBodyIdentify }
|
|
29
|
+
|
|
30
|
+
export { EventBodyTrack }
|
|
31
|
+
|
|
32
|
+
export { EventType }
|
|
33
|
+
|
|
34
|
+
export { Keys }
|
|
35
|
+
|
|
36
|
+
export { RuleType }
|
|
37
|
+
|
|
38
|
+
export { Schematic }
|
|
39
|
+
|
|
40
|
+
export declare interface SchematicComposableOpts {
|
|
41
|
+
client?: SchematicJS.Schematic;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { SchematicContext }
|
|
45
|
+
|
|
46
|
+
export declare interface SchematicContextValue {
|
|
47
|
+
client: SchematicJS.Schematic;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { SchematicOptions }
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Vue plugin for Schematic
|
|
54
|
+
* Install this plugin to make Schematic available throughout your Vue app
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { createApp } from 'vue'
|
|
59
|
+
* import { SchematicPlugin } from '@schematichq/schematic-vue'
|
|
60
|
+
*
|
|
61
|
+
* const app = createApp(App)
|
|
62
|
+
* app.use(SchematicPlugin, { publishableKey: 'your-publishable-key' })
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare const SchematicPlugin: {
|
|
66
|
+
install(app: App, options: SchematicPluginOptions): void;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export declare type SchematicPluginOptions = SchematicPluginOptionsWithClient | SchematicPluginOptionsWithPublishableKey;
|
|
70
|
+
|
|
71
|
+
declare type SchematicPluginOptionsWithClient = BaseSchematicPluginOptions & {
|
|
72
|
+
client: SchematicJS.Schematic;
|
|
73
|
+
publishableKey?: never;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
declare type SchematicPluginOptionsWithPublishableKey = BaseSchematicPluginOptions & {
|
|
77
|
+
client?: never;
|
|
78
|
+
publishableKey: string;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export { StoragePersister }
|
|
82
|
+
|
|
83
|
+
export { Traits }
|
|
84
|
+
|
|
85
|
+
export { UsagePeriod }
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Access the Schematic client instance
|
|
89
|
+
* Must be called within a component that has SchematicPlugin installed
|
|
90
|
+
*
|
|
91
|
+
* @throws Error if called outside of a component with SchematicPlugin
|
|
92
|
+
*/
|
|
93
|
+
export declare const useSchematic: () => SchematicContextValue;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Get the Schematic client instance
|
|
97
|
+
* Can optionally override with a custom client
|
|
98
|
+
*/
|
|
99
|
+
export declare const useSchematicClient: (opts?: SchematicComposableOpts) => SchematicJS.Schematic;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Access context management methods
|
|
103
|
+
* Provides setContext method to update user/company context
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const { setContext } = useSchematicContext()
|
|
108
|
+
* setContext({
|
|
109
|
+
* user: { id: 'user-123' },
|
|
110
|
+
* company: { id: 'company-456' }
|
|
111
|
+
* })
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare const useSchematicContext: (opts?: SchematicComposableOpts) => {
|
|
115
|
+
setContext: (context: SchematicJS.SchematicContext) => Promise<void>;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Check feature entitlement with usage details
|
|
120
|
+
* Returns reactive refs for flag value, usage, allocation, and exceeded status
|
|
121
|
+
*
|
|
122
|
+
* @param key - The flag/feature key to check
|
|
123
|
+
* @param opts - Optional configuration including fallback value
|
|
124
|
+
* @returns Object with reactive refs for entitlement data
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* const {
|
|
129
|
+
* value: isEnabled,
|
|
130
|
+
* featureUsage,
|
|
131
|
+
* featureAllocation,
|
|
132
|
+
* featureUsageExceeded
|
|
133
|
+
* } = useSchematicEntitlement('my-feature-key')
|
|
134
|
+
*
|
|
135
|
+
* // In template
|
|
136
|
+
* <div v-if="featureUsageExceeded">
|
|
137
|
+
* Usage limit reached: {{ featureUsage }} / {{ featureAllocation }}
|
|
138
|
+
* </div>
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export declare const useSchematicEntitlement: (key: string, opts?: UseSchematicFlagOpts) => {
|
|
142
|
+
check: ComputedRef< {
|
|
143
|
+
featureUsageExceeded?: boolean | undefined;
|
|
144
|
+
companyId?: string | undefined;
|
|
145
|
+
error?: string | undefined;
|
|
146
|
+
featureAllocation?: number | undefined;
|
|
147
|
+
featureUsage?: number | undefined;
|
|
148
|
+
featureUsageEvent?: string | undefined;
|
|
149
|
+
featureUsagePeriod?: SchematicJS.UsagePeriod | undefined;
|
|
150
|
+
featureUsageResetAt?: Date | undefined;
|
|
151
|
+
flag: string;
|
|
152
|
+
flagId?: string | undefined;
|
|
153
|
+
reason: string;
|
|
154
|
+
ruleId?: string | undefined;
|
|
155
|
+
ruleType?: SchematicJS.RuleType | undefined;
|
|
156
|
+
userId?: string | undefined;
|
|
157
|
+
value: boolean;
|
|
158
|
+
}>;
|
|
159
|
+
value: ComputedRef<boolean>;
|
|
160
|
+
flag: ComputedRef<string>;
|
|
161
|
+
reason: ComputedRef<string>;
|
|
162
|
+
featureUsage: ComputedRef<number | undefined>;
|
|
163
|
+
featureAllocation: ComputedRef<number | undefined>;
|
|
164
|
+
featureUsageExceeded: ComputedRef<boolean | undefined>;
|
|
165
|
+
featureUsageEvent: ComputedRef<string | undefined>;
|
|
166
|
+
featureUsagePeriod: ComputedRef<SchematicJS.UsagePeriod | undefined>;
|
|
167
|
+
flagId: ComputedRef<string | undefined>;
|
|
168
|
+
ruleId: ComputedRef<string | undefined>;
|
|
169
|
+
companyId: ComputedRef<string | undefined>;
|
|
170
|
+
userId: ComputedRef<string | undefined>;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Access event tracking methods
|
|
175
|
+
* Provides identify and track methods for user identification and event tracking
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const { identify, track } = useSchematicEvents()
|
|
180
|
+
*
|
|
181
|
+
* // Identify a user and company
|
|
182
|
+
* identify({
|
|
183
|
+
* keys: { id: 'user-123' },
|
|
184
|
+
* company: {
|
|
185
|
+
* keys: { id: 'company-456' },
|
|
186
|
+
* traits: { plan: 'enterprise' }
|
|
187
|
+
* }
|
|
188
|
+
* })
|
|
189
|
+
*
|
|
190
|
+
* // Track an event
|
|
191
|
+
* track({ event: 'query' })
|
|
192
|
+
* track({ event: 'query', quantity: 10 })
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
export declare const useSchematicEvents: (opts?: SchematicComposableOpts) => {
|
|
196
|
+
track: (body: SchematicJS.EventBodyTrack) => Promise<void>;
|
|
197
|
+
identify: (body: SchematicJS.EventBodyIdentify) => void;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Check a feature flag value
|
|
202
|
+
* Returns a reactive ref that updates when the flag value changes
|
|
203
|
+
*
|
|
204
|
+
* @param key - The flag key to check
|
|
205
|
+
* @param opts - Optional configuration including fallback value
|
|
206
|
+
* @returns Ref<boolean> - Reactive boolean value of the flag
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const isFeatureEnabled = useSchematicFlag('my-flag-key')
|
|
211
|
+
*
|
|
212
|
+
* // In template
|
|
213
|
+
* <div v-if="isFeatureEnabled">Feature content</div>
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
export declare const useSchematicFlag: (key: string, opts?: UseSchematicFlagOpts) => Ref<boolean>;
|
|
217
|
+
|
|
218
|
+
export declare type UseSchematicFlagOpts = SchematicComposableOpts & {
|
|
219
|
+
fallback?: boolean;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Check if Schematic data is still loading
|
|
224
|
+
* Returns a reactive ref that is true while initial flag data is being fetched
|
|
225
|
+
*
|
|
226
|
+
* Useful for showing loading states before displaying flag checks
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* const isPending = useSchematicIsPending()
|
|
231
|
+
*
|
|
232
|
+
* // In template
|
|
233
|
+
* <div v-if="isPending">Loading...</div>
|
|
234
|
+
* <div v-else-if="isFeatureEnabled">Feature content</div>
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
export declare const useSchematicIsPending: (opts?: SchematicComposableOpts) => Ref<boolean>;
|
|
238
|
+
|
|
239
|
+
export { }
|