@databuddy/sdk 2.1.76 → 2.1.77
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/dist/core/index.d.mts +41 -1
- package/dist/core/index.d.ts +41 -1
- package/dist/core/index.mjs +3 -3
- package/dist/react/index.d.mts +4 -42
- package/dist/react/index.d.ts +4 -42
- package/dist/react/index.mjs +54 -431
- package/dist/shared/@databuddy/sdk.DsZMb6-q.mjs +465 -0
- package/dist/shared/@databuddy/{sdk.DrN7UcWM.mjs → sdk.VZOaS2Dk.mjs} +1 -1
- package/dist/shared/@databuddy/sdk.YfiY9DoZ.d.mts +64 -0
- package/dist/shared/@databuddy/sdk.YfiY9DoZ.d.ts +64 -0
- package/dist/vue/index.d.mts +33 -1
- package/dist/vue/index.d.ts +33 -1
- package/dist/vue/index.mjs +87 -3
- package/package.json +58 -58
- package/dist/shared/@databuddy/sdk.D3SKeeIX.mjs +0 -29
package/dist/vue/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineComponent, ref, onMounted, onUnmounted, watch } from 'vue';
|
|
2
|
-
import { i as isScriptInjected, c as createScript } from '../shared/@databuddy/sdk.
|
|
1
|
+
import { defineComponent, ref, onMounted, onUnmounted, watch, reactive, watchEffect, computed } from 'vue';
|
|
2
|
+
import { i as isScriptInjected, c as createScript, B as BrowserFlagStorage, C as CoreFlagsManager } from '../shared/@databuddy/sdk.DsZMb6-q.mjs';
|
|
3
3
|
|
|
4
4
|
const Databuddy = defineComponent({
|
|
5
5
|
props: {},
|
|
@@ -37,4 +37,88 @@ const Databuddy = defineComponent({
|
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
const FLAGS_SYMBOL = Symbol("flags");
|
|
41
|
+
let globalState = null;
|
|
42
|
+
let globalManager = null;
|
|
43
|
+
function createFlagsPlugin(options) {
|
|
44
|
+
return {
|
|
45
|
+
install(app) {
|
|
46
|
+
const storage = options.skipStorage ? void 0 : new BrowserFlagStorage();
|
|
47
|
+
const state = reactive({
|
|
48
|
+
memoryFlags: {},
|
|
49
|
+
pendingFlags: /* @__PURE__ */ new Set()
|
|
50
|
+
});
|
|
51
|
+
const manager = new CoreFlagsManager({
|
|
52
|
+
config: options,
|
|
53
|
+
storage,
|
|
54
|
+
onFlagsUpdate: (flags) => {
|
|
55
|
+
state.memoryFlags = flags;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
globalManager = manager;
|
|
59
|
+
globalState = state;
|
|
60
|
+
app.provide(FLAGS_SYMBOL, state);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function useFlags() {
|
|
65
|
+
if (!globalState) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
"Flags plugin not installed. Install with app.use(createFlagsPlugin(config))"
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
if (!globalManager) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
"Flags manager not initialized. Please reinstall the plugin."
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
const state = globalState;
|
|
76
|
+
const manager = globalManager;
|
|
77
|
+
const isEnabled = (key) => {
|
|
78
|
+
return manager.isEnabled(key);
|
|
79
|
+
};
|
|
80
|
+
const fetchAllFlags = () => {
|
|
81
|
+
return manager.fetchAllFlags();
|
|
82
|
+
};
|
|
83
|
+
const updateUser = (user) => {
|
|
84
|
+
manager.updateUser(user);
|
|
85
|
+
};
|
|
86
|
+
const refresh = (forceClear = false) => {
|
|
87
|
+
manager.refresh(forceClear);
|
|
88
|
+
};
|
|
89
|
+
const updateConfig = (config) => {
|
|
90
|
+
manager.updateConfig(config);
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
isEnabled,
|
|
94
|
+
fetchAllFlags,
|
|
95
|
+
updateUser,
|
|
96
|
+
refresh,
|
|
97
|
+
updateConfig,
|
|
98
|
+
memoryFlags: state.memoryFlags
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function useFlag(key) {
|
|
103
|
+
const { isEnabled } = useFlags();
|
|
104
|
+
const flagState = ref({
|
|
105
|
+
enabled: false,
|
|
106
|
+
isLoading: true,
|
|
107
|
+
isReady: false
|
|
108
|
+
});
|
|
109
|
+
watchEffect(() => {
|
|
110
|
+
flagState.value = isEnabled(key);
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
enabled: computed(() => flagState.value.enabled),
|
|
114
|
+
isLoading: computed(() => flagState.value.isLoading),
|
|
115
|
+
isReady: computed(() => flagState.value.isReady),
|
|
116
|
+
state: computed(() => flagState.value)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function useBooleanFlag(key) {
|
|
120
|
+
const { enabled } = useFlag(key);
|
|
121
|
+
return enabled;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export { Databuddy, createFlagsPlugin, useBooleanFlag, useFlag, useFlags };
|
package/package.json
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@databuddy/sdk",
|
|
3
|
-
"version": "2.1.
|
|
4
|
-
"description": "Official Databuddy Analytics SDK",
|
|
5
|
-
"main": "./dist/core/index.mjs",
|
|
6
|
-
"types": "./dist/core/index.d.ts",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"private": false,
|
|
9
|
-
"scripts": {
|
|
10
|
-
"build": "unbuild"
|
|
11
|
-
},
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"jotai": ">=2.0.0"
|
|
14
|
-
},
|
|
15
|
-
"devDependencies": {
|
|
16
|
-
"@types/node": "^20.0.0",
|
|
17
|
-
"@vitejs/plugin-react": "^5.0.0",
|
|
18
|
-
"typescript": "catalog:",
|
|
19
|
-
"unbuild": "^3.6.1"
|
|
20
|
-
},
|
|
21
|
-
"peerDependencies": {
|
|
22
|
-
"react": ">=18",
|
|
23
|
-
"vue": ">=3"
|
|
24
|
-
},
|
|
25
|
-
"peerDependenciesMeta": {
|
|
26
|
-
"react": {
|
|
27
|
-
"optional": true
|
|
28
|
-
},
|
|
29
|
-
"vue": {
|
|
30
|
-
"optional": true
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"exports": {
|
|
34
|
-
".": {
|
|
35
|
-
"types": "./dist/core/index.d.ts",
|
|
36
|
-
"import": "./dist/core/index.mjs"
|
|
37
|
-
},
|
|
38
|
-
"./react": {
|
|
39
|
-
"types": "./dist/react/index.d.ts",
|
|
40
|
-
"import": "./dist/react/index.mjs"
|
|
41
|
-
},
|
|
42
|
-
"./vue": {
|
|
43
|
-
"types": "./dist/vue/index.d.ts",
|
|
44
|
-
"import": "./dist/vue/index.mjs"
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
"files": [
|
|
48
|
-
"dist"
|
|
49
|
-
],
|
|
50
|
-
"keywords": [
|
|
51
|
-
"analytics",
|
|
52
|
-
"tracking",
|
|
53
|
-
"databuddy",
|
|
54
|
-
"sdk",
|
|
55
|
-
"react",
|
|
56
|
-
"vue"
|
|
57
|
-
]
|
|
58
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@databuddy/sdk",
|
|
3
|
+
"version": "2.1.77",
|
|
4
|
+
"description": "Official Databuddy Analytics SDK",
|
|
5
|
+
"main": "./dist/core/index.mjs",
|
|
6
|
+
"types": "./dist/core/index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"private": false,
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "unbuild"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"jotai": ">=2.0.0"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/node": "^20.0.0",
|
|
17
|
+
"@vitejs/plugin-react": "^5.0.0",
|
|
18
|
+
"typescript": "catalog:",
|
|
19
|
+
"unbuild": "^3.6.1"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"react": ">=18",
|
|
23
|
+
"vue": ">=3"
|
|
24
|
+
},
|
|
25
|
+
"peerDependenciesMeta": {
|
|
26
|
+
"react": {
|
|
27
|
+
"optional": true
|
|
28
|
+
},
|
|
29
|
+
"vue": {
|
|
30
|
+
"optional": true
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/core/index.d.ts",
|
|
36
|
+
"import": "./dist/core/index.mjs"
|
|
37
|
+
},
|
|
38
|
+
"./react": {
|
|
39
|
+
"types": "./dist/react/index.d.ts",
|
|
40
|
+
"import": "./dist/react/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./vue": {
|
|
43
|
+
"types": "./dist/vue/index.d.ts",
|
|
44
|
+
"import": "./dist/vue/index.mjs"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"dist"
|
|
49
|
+
],
|
|
50
|
+
"keywords": [
|
|
51
|
+
"analytics",
|
|
52
|
+
"tracking",
|
|
53
|
+
"databuddy",
|
|
54
|
+
"sdk",
|
|
55
|
+
"react",
|
|
56
|
+
"vue"
|
|
57
|
+
]
|
|
58
|
+
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const version = "2.1.76";
|
|
2
|
-
|
|
3
|
-
const INJECTED_SCRIPT_ATTRIBUTE = "data-databuddy-injected";
|
|
4
|
-
function isScriptInjected() {
|
|
5
|
-
return !!document.querySelector(`script[${INJECTED_SCRIPT_ATTRIBUTE}]`);
|
|
6
|
-
}
|
|
7
|
-
function createScript({
|
|
8
|
-
scriptUrl,
|
|
9
|
-
sdkVersion,
|
|
10
|
-
...props
|
|
11
|
-
}) {
|
|
12
|
-
const script = document.createElement("script");
|
|
13
|
-
script.src = scriptUrl || "https://cdn.databuddy.cc/databuddy.js";
|
|
14
|
-
script.async = true;
|
|
15
|
-
script.crossOrigin = "anonymous";
|
|
16
|
-
script.setAttribute(INJECTED_SCRIPT_ATTRIBUTE, "true");
|
|
17
|
-
script.setAttribute("data-sdk-version", sdkVersion || version);
|
|
18
|
-
for (const [key, value] of Object.entries(props)) {
|
|
19
|
-
const dataKey = `data-${key.replace(/([A-Z])/g, "-$1").toLowerCase()}`;
|
|
20
|
-
if (Array.isArray(value) || value && typeof value === "object") {
|
|
21
|
-
script.setAttribute(dataKey, JSON.stringify(value));
|
|
22
|
-
} else {
|
|
23
|
-
script.setAttribute(dataKey, String(value));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return script;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { createScript as c, isScriptInjected as i };
|