editor-sdk 0.1.7 → 0.1.8
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 +72 -5
- package/dist/SecureScene.js +22 -11
- package/dist/cli.js +30 -2
- package/package.json +38 -38
package/README.md
CHANGED
|
@@ -20,14 +20,39 @@ Authenticate with your registry API key.
|
|
|
20
20
|
npx editor-sdk login
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
You can specify a custom registry URL:
|
|
24
|
+
```bash
|
|
25
|
+
npx editor-sdk login --host https://your-registry.com
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. Configure Registry URL (Optional)
|
|
29
|
+
Set a default registry URL to avoid specifying `--host` every time.
|
|
30
|
+
```bash
|
|
31
|
+
# View current configuration
|
|
32
|
+
npx editor-sdk config
|
|
33
|
+
|
|
34
|
+
# Set default registry URL
|
|
35
|
+
npx editor-sdk config --set-registry https://your-registry.com
|
|
36
|
+
|
|
37
|
+
# For production
|
|
38
|
+
npx editor-sdk config --set-registry https://api.yourdomain.com
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Configuration is saved to `~/.3d-editor/config.json`.
|
|
42
|
+
|
|
43
|
+
### 3. Add Component
|
|
24
44
|
Fetch a component by its ID.
|
|
25
45
|
```bash
|
|
26
|
-
npx editor-sdk add <component-id>
|
|
46
|
+
npx editor-sdk add <component-id>
|
|
27
47
|
```
|
|
28
|
-
|
|
48
|
+
|
|
49
|
+
*Examples:*
|
|
29
50
|
```bash
|
|
30
|
-
|
|
51
|
+
# Uses configured registry URL
|
|
52
|
+
npx editor-sdk add my-scene-123
|
|
53
|
+
|
|
54
|
+
# Override with --host flag
|
|
55
|
+
npx editor-sdk add my-scene-123 --host http://localhost:8080
|
|
31
56
|
```
|
|
32
57
|
|
|
33
58
|
---
|
|
@@ -53,10 +78,52 @@ export default function My3DComponent() {
|
|
|
53
78
|
| Prop | Type | Description |
|
|
54
79
|
|------|------|-------------|
|
|
55
80
|
| `id` | `string` | The unique ID of the component in the registry. |
|
|
56
|
-
| `registryUrl` | `string` | Base URL of the registry
|
|
81
|
+
| `registryUrl` | `string` | (Optional) Base URL of the registry. Auto-detected if not provided. |
|
|
57
82
|
| `token` | `string` | (Optional) Auth token for private components. |
|
|
58
83
|
| `onLoad` | `() => void` | Callback when the model finishes loading. |
|
|
59
84
|
| `onError` | `(err) => void` | Callback if loading fails. |
|
|
85
|
+
| `animation` | `object` | (Optional) Override animation settings. |
|
|
86
|
+
| `position` | `[x, y, z]` | (Optional) Override position. |
|
|
87
|
+
| `scale` | `[x, y, z]` | (Optional) Override scale. |
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 🌐 Registry URL Configuration
|
|
92
|
+
|
|
93
|
+
The SDK automatically detects the registry URL using the following priority:
|
|
94
|
+
|
|
95
|
+
1. **Explicit prop**: `<SecureScene registryUrl="..." />`
|
|
96
|
+
2. **Environment variable**: `NEXT_PUBLIC_REGISTRY_URL`
|
|
97
|
+
3. **Auto-detect localhost**: `http://localhost:{current-port}` (works on any port!)
|
|
98
|
+
4. **Auto-detect domain**: Uses `window.location.origin` for deployed apps
|
|
99
|
+
5. **Fallback**: `http://localhost:3000`
|
|
100
|
+
|
|
101
|
+
### Development (Any Port)
|
|
102
|
+
The SDK automatically works on **any localhost port**:
|
|
103
|
+
```tsx
|
|
104
|
+
// Works on localhost:3000, localhost:8080, localhost:3001, etc.
|
|
105
|
+
<SecureScene id="my-component-123" />
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Production (Environment Variable)
|
|
109
|
+
Set the registry URL in your environment:
|
|
110
|
+
```bash
|
|
111
|
+
# .env.production
|
|
112
|
+
NEXT_PUBLIC_REGISTRY_URL=https://api.yourdomain.com
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
// Component automatically uses NEXT_PUBLIC_REGISTRY_URL
|
|
117
|
+
<SecureScene id="my-component-123" />
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Override for Specific Component
|
|
121
|
+
```tsx
|
|
122
|
+
<SecureScene
|
|
123
|
+
id="my-component-123"
|
|
124
|
+
registryUrl="https://custom-registry.com"
|
|
125
|
+
/>
|
|
126
|
+
```
|
|
60
127
|
|
|
61
128
|
---
|
|
62
129
|
|
package/dist/SecureScene.js
CHANGED
|
@@ -3,7 +3,25 @@ import { useEffect, useState, Suspense, useRef } from 'react';
|
|
|
3
3
|
import { useGLTF, Html } from '@react-three/drei';
|
|
4
4
|
import { useFrame } from '@react-three/fiber';
|
|
5
5
|
// Default Registry URL (can be overridden)
|
|
6
|
-
|
|
6
|
+
// Supports environment variable or falls back to localhost detection
|
|
7
|
+
const getDefaultRegistryUrl = () => {
|
|
8
|
+
// 1. Check for environment variable (for production)
|
|
9
|
+
if (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_REGISTRY_URL) {
|
|
10
|
+
return process.env.NEXT_PUBLIC_REGISTRY_URL;
|
|
11
|
+
}
|
|
12
|
+
// 2. Auto-detect localhost with current port (for development)
|
|
13
|
+
if (typeof window !== 'undefined' && window.location.hostname === 'localhost') {
|
|
14
|
+
const port = window.location.port || '3000';
|
|
15
|
+
return `http://localhost:${port}`;
|
|
16
|
+
}
|
|
17
|
+
// 3. Use current origin if on a whitelisted domain
|
|
18
|
+
if (typeof window !== 'undefined') {
|
|
19
|
+
return window.location.origin;
|
|
20
|
+
}
|
|
21
|
+
// 4. Fallback
|
|
22
|
+
return 'http://localhost:3000';
|
|
23
|
+
};
|
|
24
|
+
const DEFAULT_REGISTRY_URL = getDefaultRegistryUrl();
|
|
7
25
|
const CACHE_DURATION_MS = 50 * 60 * 1000; // 50 minutes
|
|
8
26
|
// --- Internal Animator (Copied from Editor) ---
|
|
9
27
|
function SecureAnimator({ children, animation, ...props }) {
|
|
@@ -105,19 +123,12 @@ export function SecureScene({ id, registryUrl = DEFAULT_REGISTRY_URL, token, onL
|
|
|
105
123
|
}
|
|
106
124
|
}
|
|
107
125
|
fetchMetadata();
|
|
108
|
-
|
|
109
|
-
//
|
|
110
|
-
if (typeof window !== 'undefined' && window.location.hostname === 'localhost') {
|
|
111
|
-
interval = setInterval(() => {
|
|
112
|
-
fetchMetadata(true); // Force refresh
|
|
113
|
-
}, 2000);
|
|
114
|
-
}
|
|
126
|
+
// Polling disabled to prevent infinite fetch loops
|
|
127
|
+
// Only fetch once on mount or when id/registryUrl changes
|
|
115
128
|
return () => {
|
|
116
129
|
mounted = false;
|
|
117
|
-
if (interval)
|
|
118
|
-
clearInterval(interval);
|
|
119
130
|
};
|
|
120
|
-
}, [id, registryUrl
|
|
131
|
+
}, [id, registryUrl]); // Removed onLoad and onError from dependencies
|
|
121
132
|
if (error) {
|
|
122
133
|
return (_jsx("group", { children: _jsx(Html, { position: [0, 1, 0], center: true, children: _jsxs("div", { style: { color: 'red', background: 'white', padding: 4, border: '1px solid red' }, children: ["Error: ", error] }) }) }));
|
|
123
134
|
}
|
package/dist/cli.js
CHANGED
|
@@ -72,17 +72,45 @@ program
|
|
|
72
72
|
console.log(chalk.yellow('Login cancelled.'));
|
|
73
73
|
}
|
|
74
74
|
});
|
|
75
|
+
// Config Command
|
|
76
|
+
program
|
|
77
|
+
.command('config')
|
|
78
|
+
.description('Configure registry settings')
|
|
79
|
+
.option('--set-registry <url>', 'Set the default registry URL')
|
|
80
|
+
.option('--show', 'Show current configuration')
|
|
81
|
+
.action(async (options) => {
|
|
82
|
+
const config = loadConfig();
|
|
83
|
+
if (options.setRegistry) {
|
|
84
|
+
config.registryUrl = options.setRegistry;
|
|
85
|
+
saveConfig(config);
|
|
86
|
+
console.log(chalk.green(`✓ Registry URL set to: ${options.setRegistry}`));
|
|
87
|
+
console.log(chalk.gray(`Saved to ${CONFIG_FILE}`));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (options.show || (!options.setRegistry)) {
|
|
91
|
+
console.log(chalk.blue('📋 Current Configuration:'));
|
|
92
|
+
console.log(chalk.gray(`Config file: ${CONFIG_FILE}`));
|
|
93
|
+
console.log('');
|
|
94
|
+
console.log(`Registry URL: ${config.registryUrl || chalk.gray('(auto-detect)')}`);
|
|
95
|
+
console.log(`API Key: ${config.apiKey ? chalk.green('✓ Set') : chalk.yellow('✗ Not set')}`);
|
|
96
|
+
console.log('');
|
|
97
|
+
console.log(chalk.gray('Use --set-registry <url> to change the registry URL'));
|
|
98
|
+
console.log(chalk.gray('Example: npx editor-sdk config --set-registry https://your-domain.com'));
|
|
99
|
+
}
|
|
100
|
+
});
|
|
75
101
|
// Add Command
|
|
76
102
|
program
|
|
77
103
|
.command('add <componentId>')
|
|
78
104
|
.description('Add a component by ID')
|
|
79
105
|
.option('-p, --package', 'Install as a node_module package', false)
|
|
80
106
|
.option('-f, --force', 'Force overwrite of existing files', false)
|
|
81
|
-
.option('--host <url>', 'Registry Host URL
|
|
107
|
+
.option('--host <url>', 'Registry Host URL (overrides config)')
|
|
82
108
|
.action(async (componentId, options) => {
|
|
83
109
|
try {
|
|
84
110
|
const config = loadConfig();
|
|
85
111
|
const apiKey = config.apiKey;
|
|
112
|
+
// Use --host flag, then config, then default
|
|
113
|
+
const defaultHost = options.host || config.registryUrl || 'http://localhost:3000';
|
|
86
114
|
if (!apiKey) {
|
|
87
115
|
console.warn(chalk.yellow('⚠ You are not logged in. Public components only.'));
|
|
88
116
|
console.warn(chalk.yellow('Run `npx 3d-editor login` to access private components.'));
|
|
@@ -96,7 +124,7 @@ program
|
|
|
96
124
|
idFromArg = parts[parts.length - 1] || 'component';
|
|
97
125
|
}
|
|
98
126
|
else {
|
|
99
|
-
registryUrl = `${
|
|
127
|
+
registryUrl = `${defaultHost}/api/registry/${componentId}`;
|
|
100
128
|
}
|
|
101
129
|
console.log(chalk.blue(`📦 Fetching component from ${registryUrl}...`));
|
|
102
130
|
const res = await fetch(registryUrl, {
|
package/package.json
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "editor-sdk",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"module": "dist/index.mjs",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"bin": {
|
|
8
|
-
"editor-sdk": "./dist/cli.js"
|
|
9
|
-
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "tsc",
|
|
12
|
-
"dev": "tsc --watch"
|
|
13
|
-
},
|
|
14
|
-
"peerDependencies": {
|
|
15
|
-
"@react-three/drei": ">=9.0.0",
|
|
16
|
-
"@react-three/fiber": ">=8.0.0",
|
|
17
|
-
"react": ">=18.0.0",
|
|
18
|
-
"react-dom": ">=18.0.0",
|
|
19
|
-
"three": ">=0.160.0"
|
|
20
|
-
},
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"prompts": "^2.4.2"
|
|
26
|
-
},
|
|
27
|
-
"files": [
|
|
28
|
-
"dist"
|
|
29
|
-
],
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"@react-three/drei": ">=9.0.0",
|
|
32
|
-
"@react-three/fiber": ">=8.0.0",
|
|
33
|
-
"@types/
|
|
34
|
-
"@types/
|
|
35
|
-
"@types/
|
|
36
|
-
"@types/
|
|
37
|
-
"typescript": "^5.9.3"
|
|
38
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "editor-sdk",
|
|
3
|
+
"version": "0.1.8",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"module": "dist/index.mjs",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"editor-sdk": "./dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"dev": "tsc --watch"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@react-three/drei": ">=9.0.0",
|
|
16
|
+
"@react-three/fiber": ">=8.0.0",
|
|
17
|
+
"react": ">=18.0.0",
|
|
18
|
+
"react-dom": ">=18.0.0",
|
|
19
|
+
"three": ">=0.160.0"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"chalk": "^4.1.2",
|
|
23
|
+
"commander": "^11.1.0",
|
|
24
|
+
"node-fetch": "^3.3.2",
|
|
25
|
+
"prompts": "^2.4.2"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@react-three/drei": ">=9.0.0",
|
|
32
|
+
"@react-three/fiber": ">=8.0.0",
|
|
33
|
+
"@types/node": "^20.0.0",
|
|
34
|
+
"@types/prompts": "^2.4.9",
|
|
35
|
+
"@types/react": "^18.3.27",
|
|
36
|
+
"@types/three": "^0.160.0",
|
|
37
|
+
"typescript": "^5.9.3"
|
|
38
|
+
}
|
|
39
39
|
}
|