@keak/sdk 1.0.1 → 1.0.2
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/README.md +4 -4
- package/package.json +1 -1
- package/src/cli/ai-helper.js +2 -2
- package/src/cli/code-transformer.js +1 -1
- package/src/cli/install.js +8 -8
- package/src/cli/revert-conversions.js +1 -1
- package/src/cli/safe-transformer.js +3 -3
- package/src/cli/simple-transformer.js +2 -2
- package/src/plugins/README.md +5 -5
- package/src/plugins/next.cjs +4 -4
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Production-ready A/B testing and experimentation SDK for React applications with
|
|
|
7
7
|
### 1. Install the SDK
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install keak
|
|
10
|
+
npm install @keak/sdk
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
All dependencies are bundled with the SDK - no additional packages required.
|
|
@@ -38,7 +38,7 @@ If you're using Next.js 15, you'll need additional configuration to enable sourc
|
|
|
38
38
|
The auto-setup will add `KeakProvider` to your app. If you need to configure it manually:
|
|
39
39
|
|
|
40
40
|
```tsx
|
|
41
|
-
import { KeakProvider } from 'keak
|
|
41
|
+
import { KeakProvider } from '@keak/sdk';
|
|
42
42
|
|
|
43
43
|
function App() {
|
|
44
44
|
return (
|
|
@@ -54,7 +54,7 @@ function App() {
|
|
|
54
54
|
Wrap your content with `Experiment` and `Variant` components:
|
|
55
55
|
|
|
56
56
|
```tsx
|
|
57
|
-
import { Experiment, Variant } from 'keak
|
|
57
|
+
import { Experiment, Variant } from '@keak/sdk';
|
|
58
58
|
|
|
59
59
|
export default function HeroHome() {
|
|
60
60
|
return (
|
|
@@ -79,7 +79,7 @@ export default function HeroHome() {
|
|
|
79
79
|
You can also use the `useExperiment` hook for programmatic access:
|
|
80
80
|
|
|
81
81
|
```tsx
|
|
82
|
-
import { useExperiment } from 'keak
|
|
82
|
+
import { useExperiment } from '@keak/sdk';
|
|
83
83
|
|
|
84
84
|
function MyComponent() {
|
|
85
85
|
const { variant, track, isInExperiment } = useExperiment('my-experiment');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keak/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Production-ready A/B testing and experimentation SDK for React applications with visual editing, source mapping, and real-time variant testing",
|
|
5
5
|
"author": "Keak Team",
|
|
6
6
|
"homepage": "https://www.keak.com/",
|
package/src/cli/ai-helper.js
CHANGED
|
@@ -131,14 +131,14 @@ class LocalAIHelper {
|
|
|
131
131
|
result.push(lines[i]);
|
|
132
132
|
|
|
133
133
|
if (i === lastImportLine && !importAdded) {
|
|
134
|
-
result.push("import { KeakProvider } from 'keak
|
|
134
|
+
result.push("import { KeakProvider } from '@keak/sdk';");
|
|
135
135
|
importAdded = true;
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
// If no imports found, add at the beginning
|
|
140
140
|
if (!importAdded) {
|
|
141
|
-
result.unshift("import { KeakProvider } from 'keak
|
|
141
|
+
result.unshift("import { KeakProvider } from '@keak/sdk';");
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
// Now wrap the appropriate component
|
|
@@ -19,7 +19,7 @@ class CodeTransformer {
|
|
|
19
19
|
this.importAdded = false;
|
|
20
20
|
|
|
21
21
|
// Skip if file already has Conversion imports
|
|
22
|
-
if (content.includes('import') && content.includes('Conversion') && content.includes('keak
|
|
22
|
+
if (content.includes('import') && content.includes('Conversion') && content.includes('@keak/sdk')) {
|
|
23
23
|
return content;
|
|
24
24
|
}
|
|
25
25
|
|
package/src/cli/install.js
CHANGED
|
@@ -281,7 +281,7 @@ class KeakInstaller {
|
|
|
281
281
|
if (!this.entryFile) return false;
|
|
282
282
|
|
|
283
283
|
const content = fs.readFileSync(this.entryFile, 'utf-8');
|
|
284
|
-
return content.includes('KeakProvider') || content.includes('keak
|
|
284
|
+
return content.includes('KeakProvider') || content.includes('@keak/sdk');
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
async autoInstall() {
|
|
@@ -325,7 +325,7 @@ class KeakInstaller {
|
|
|
325
325
|
// Next.js 13+ App Directory
|
|
326
326
|
if (!content.includes('KeakProvider')) {
|
|
327
327
|
// Add import - include both KeakProvider and KeakToolbar
|
|
328
|
-
const importLine = "import { KeakProvider, KeakToolbar } from 'keak
|
|
328
|
+
const importLine = "import { KeakProvider, KeakToolbar } from '@keak/sdk';\n";
|
|
329
329
|
let modified = content;
|
|
330
330
|
|
|
331
331
|
// Add import after existing imports
|
|
@@ -356,7 +356,7 @@ ${bodyContent}
|
|
|
356
356
|
// Next.js Pages Directory
|
|
357
357
|
if (!content.includes('KeakProvider')) {
|
|
358
358
|
// Add import - include both KeakProvider and KeakToolbar
|
|
359
|
-
const importLine = "import { KeakProvider, KeakToolbar } from 'keak
|
|
359
|
+
const importLine = "import { KeakProvider, KeakToolbar } from '@keak/sdk';\n";
|
|
360
360
|
let modified = content;
|
|
361
361
|
|
|
362
362
|
const lastImportIndex = modified.lastIndexOf('import ');
|
|
@@ -391,7 +391,7 @@ ${bodyContent}
|
|
|
391
391
|
|
|
392
392
|
// Add import - include both KeakProvider and KeakToolbar
|
|
393
393
|
if (!content.includes('KeakProvider')) {
|
|
394
|
-
const importLine = "import { KeakProvider, KeakToolbar } from 'keak
|
|
394
|
+
const importLine = "import { KeakProvider, KeakToolbar } from '@keak/sdk';\n";
|
|
395
395
|
|
|
396
396
|
const lastImportIndex = modified.lastIndexOf('import ');
|
|
397
397
|
if (lastImportIndex !== -1) {
|
|
@@ -510,7 +510,7 @@ Please add Keak to your app manually:
|
|
|
510
510
|
1. Open ${colors.cyan}${relativeEntry}${colors.reset}
|
|
511
511
|
|
|
512
512
|
2. Add this import at the top:
|
|
513
|
-
${colors.green}import { KeakProvider } from 'keak
|
|
513
|
+
${colors.green}import { KeakProvider } from '@keak/sdk';${colors.reset}
|
|
514
514
|
|
|
515
515
|
3. Wrap your main component:
|
|
516
516
|
${colors.green}<KeakProvider config={{ apiKey: 'demo', debug: true }}><YourApp /></KeakProvider>${colors.reset}
|
|
@@ -524,7 +524,7 @@ ${this.getFrameworkExample()}
|
|
|
524
524
|
const examples = {
|
|
525
525
|
'nextjs': `
|
|
526
526
|
// app/layout.tsx
|
|
527
|
-
import { KeakProvider } from 'keak
|
|
527
|
+
import { KeakProvider } from '@keak/sdk';
|
|
528
528
|
|
|
529
529
|
export default function RootLayout({ children }) {
|
|
530
530
|
return (
|
|
@@ -536,7 +536,7 @@ export default function RootLayout({ children }) {
|
|
|
536
536
|
}`,
|
|
537
537
|
'create-react-app': `
|
|
538
538
|
// src/index.js
|
|
539
|
-
import { KeakProvider } from 'keak
|
|
539
|
+
import { KeakProvider } from '@keak/sdk';
|
|
540
540
|
|
|
541
541
|
root.render(
|
|
542
542
|
<KeakProvider config={{ apiKey: 'demo', debug: true }}>
|
|
@@ -545,7 +545,7 @@ root.render(
|
|
|
545
545
|
);`,
|
|
546
546
|
'vite-react': `
|
|
547
547
|
// src/main.tsx
|
|
548
|
-
import { KeakProvider } from 'keak
|
|
548
|
+
import { KeakProvider } from '@keak/sdk';
|
|
549
549
|
|
|
550
550
|
ReactDOM.createRoot(document.getElementById('root')).render(
|
|
551
551
|
<KeakProvider config={{ apiKey: 'demo', debug: true }}>
|
|
@@ -113,7 +113,7 @@ class ConversionReverter {
|
|
|
113
113
|
let modified = content;
|
|
114
114
|
|
|
115
115
|
// Remove Conversion imports
|
|
116
|
-
modified = modified.replace(/import\s*{\s*Conversion\s*}\s*from\s*['"]keak
|
|
116
|
+
modified = modified.replace(/import\s*{\s*Conversion\s*}\s*from\s*['"]@keak\/sdk['"];\s*\n?/g, '');
|
|
117
117
|
|
|
118
118
|
// Remove orphaned Conversion wrapper tags (in case of partial cleanup)
|
|
119
119
|
modified = modified.replace(/]*\s*\n?/g, '');
|
|
@@ -15,7 +15,7 @@ class SafeTransformer {
|
|
|
15
15
|
// Safe approach: Only transform simple, well-formed JSX elements
|
|
16
16
|
transformReactFile(content, filePath) {
|
|
17
17
|
// Skip if file already has Conversion imports
|
|
18
|
-
if (content.includes('import') && content.includes('Conversion') && content.includes('keak
|
|
18
|
+
if (content.includes('import') && content.includes('Conversion') && content.includes('@keak/sdk')) {
|
|
19
19
|
return content;
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -188,7 +188,7 @@ class SafeTransformer {
|
|
|
188
188
|
|
|
189
189
|
// Add import statement safely
|
|
190
190
|
addImport(content) {
|
|
191
|
-
if (content.includes("import { Conversion } from 'keak
|
|
191
|
+
if (content.includes("import { Conversion } from '@keak/sdk'")) {
|
|
192
192
|
return content;
|
|
193
193
|
}
|
|
194
194
|
|
|
@@ -227,7 +227,7 @@ class SafeTransformer {
|
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
-
|
|
230
|
+
lines.splice(insertIndex, 0, "import { Conversion } from '@keak/sdk';");
|
|
231
231
|
return lines.join('\n');
|
|
232
232
|
}
|
|
233
233
|
|
|
@@ -15,7 +15,7 @@ class SimpleTransformer {
|
|
|
15
15
|
// Simple approach: Transform React files to add Conversion wrapper using AST-like approach
|
|
16
16
|
transformReactFile(content, filePath) {
|
|
17
17
|
// Skip if file already has Conversion imports
|
|
18
|
-
if (content.includes('import') && content.includes('Conversion') && content.includes('keak
|
|
18
|
+
if (content.includes('import') && content.includes('Conversion') && content.includes('@keak/sdk')) {
|
|
19
19
|
return content;
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -109,7 +109,7 @@ class SimpleTransformer {
|
|
|
109
109
|
|
|
110
110
|
// Add import statement
|
|
111
111
|
addImport(content) {
|
|
112
|
-
if (content.includes("import { Conversion } from 'keak
|
|
112
|
+
if (content.includes("import { Conversion } from '@keak/sdk'")) {
|
|
113
113
|
return content;
|
|
114
114
|
}
|
|
115
115
|
|
package/src/plugins/README.md
CHANGED
|
@@ -8,14 +8,14 @@ Automatically injects `data-keak-src` attributes into JSX elements for precise e
|
|
|
8
8
|
|
|
9
9
|
### Installation
|
|
10
10
|
|
|
11
|
-
The plugin is included with
|
|
11
|
+
The plugin is included with `@keak/sdk` - no additional installation needed.
|
|
12
12
|
|
|
13
13
|
### Usage
|
|
14
14
|
|
|
15
15
|
**For CommonJS (next.config.js):**
|
|
16
16
|
|
|
17
17
|
```javascript
|
|
18
|
-
const { withKeak } = require('keak
|
|
18
|
+
const { withKeak } = require('@keak/sdk/plugins/next');
|
|
19
19
|
|
|
20
20
|
/** @type {import('next').NextConfig} */
|
|
21
21
|
const nextConfig = {
|
|
@@ -30,7 +30,7 @@ module.exports = withKeak(nextConfig);
|
|
|
30
30
|
**For ES Modules (next.config.mjs):**
|
|
31
31
|
|
|
32
32
|
```javascript
|
|
33
|
-
import { withKeak } from 'keak
|
|
33
|
+
import { withKeak } from '@keak/sdk/plugins/next';
|
|
34
34
|
|
|
35
35
|
/** @type {import('next').NextConfig} */
|
|
36
36
|
const nextConfig = {
|
|
@@ -67,7 +67,7 @@ If you have a custom Babel setup:
|
|
|
67
67
|
module.exports = {
|
|
68
68
|
plugins: [
|
|
69
69
|
[
|
|
70
|
-
'keak
|
|
70
|
+
'@keak/sdk/plugins/babel-source-inject',
|
|
71
71
|
{
|
|
72
72
|
includeElementIndex: true // Optional
|
|
73
73
|
}
|
|
@@ -90,7 +90,7 @@ export default defineConfig({
|
|
|
90
90
|
react({
|
|
91
91
|
babel: {
|
|
92
92
|
plugins: [
|
|
93
|
-
['keak
|
|
93
|
+
['@keak/sdk/plugins/babel-source-inject', { includeElementIndex: true }]
|
|
94
94
|
]
|
|
95
95
|
}
|
|
96
96
|
})
|
package/src/plugins/next.cjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Usage in next.config.js:
|
|
8
8
|
*
|
|
9
|
-
* const { withKeak } = require('keak
|
|
9
|
+
* const { withKeak } = require('@keak/sdk/plugins/next');
|
|
10
10
|
*
|
|
11
11
|
* module.exports = withKeak({
|
|
12
12
|
* // your existing Next.js config
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* Or for ESM (next.config.mjs):
|
|
16
16
|
*
|
|
17
|
-
* import { withKeak } from 'keak
|
|
17
|
+
* import { withKeak } from '@keak/sdk/plugins/next';
|
|
18
18
|
* export default withKeak({ ... });
|
|
19
19
|
*/
|
|
20
20
|
|
|
@@ -40,8 +40,8 @@ function withKeak(nextConfig = {}) {
|
|
|
40
40
|
paths: [process.cwd()]
|
|
41
41
|
});
|
|
42
42
|
} catch (e) {
|
|
43
|
-
// Fallback to resolving from keak
|
|
44
|
-
console.warn(`[Keak] Could not resolve ${moduleName} from project, falling back to keak
|
|
43
|
+
// Fallback to resolving from @keak/sdk's context
|
|
44
|
+
console.warn(`[Keak] Could not resolve ${moduleName} from project, falling back to @keak/sdk`);
|
|
45
45
|
return require.resolve(moduleName);
|
|
46
46
|
}
|
|
47
47
|
};
|