@clonecommand/cloud 0.0.1

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 ADDED
@@ -0,0 +1,65 @@
1
+ # @clonecommand/cloud
2
+
3
+ The official SDK for CloneCommand managed services. This library simplifies integration with ephemeral preview environments and provides access to CloneCommand Cloud services.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @clonecommand/cloud
9
+ ```
10
+
11
+ ## 🔐 Login Service: OAuth Proxy
12
+
13
+ OAuth providers (LinkedIn, Google, GitHub, etc.) require a strict whitelist of redirect URLs. This makes testing on dynamic, branch-specific preview environments (`*.clonecommand.app`) difficult.
14
+
15
+ The **CloneCommand Login Service** acts as a trusted intermediary, providing a single, stable redirect URL for all your environments.
16
+
17
+ ### 1. Initialize the SDK
18
+
19
+ For client-side applications (e.g., Vite, Nuxt), initialize the SDK with your Project ID.
20
+
21
+ ```typescript
22
+ import { ccc } from '@clonecommand/cloud';
23
+
24
+ ccc.init({
25
+ projectId: 'your-project-id' // Found in your CloneCommand Dashboard
26
+ });
27
+ ```
28
+
29
+ > [!NOTE]
30
+ > In managed CloneCommand deployments, your Project ID and Service Tokens are automatically detected—no manual initialization is required for server-side operations.
31
+
32
+ ### 2. Wrap your Login URL
33
+
34
+ Instead of redirecting directly to the OAuth provider, wrap your generated URL with `ccc.login.proxy()`.
35
+
36
+ ```typescript
37
+ // Before
38
+ const loginUrl = 'https://www.linkedin.com/oauth/v2/authorization?...';
39
+ window.location.href = loginUrl;
40
+
41
+ // After (Works on localhost, preview branches, and production!)
42
+ import { ccc } from '@clonecommand/cloud';
43
+
44
+ const loginUrl = 'https://www.linkedin.com/oauth/v2/authorization?...';
45
+ window.location.href = ccc.login.proxy(loginUrl);
46
+ ```
47
+
48
+ ### ⚠️ The "Redirect URI Paradox" (Important Quirk)
49
+ When using the proxy, the OAuth provider sees the **Proxy Callback URL** as your application's redirect URI.
50
+
51
+ 1. **Provider Config**: In your OAuth provider settings (e.g., LinkedIn Developer Portal), you **only** need to whitelist this single URL:
52
+ `https://graph.clonecommand.com/login/proxy/callback`
53
+
54
+ 2. **Backend Token Exchange**: When your application receives the `code` and you call the provider's API to swap it for an `access_token`, you **must** use that same proxy callback URL as the `redirect_uri` parameter:
55
+ ```typescript
56
+ // Even if your app is on localhost:3000, you MUST use the proxy callback here
57
+ const redirect_uri = 'https://graph.clonecommand.com/login/proxy/callback';
58
+ ```
59
+ *CloneCommand handles the final hop back to your specific environment automatically.*
60
+
61
+ ### 🤖 Why this is great for Agents
62
+ Using `ccc.login.proxy()` ensures that any new feature you build will have working authentication immediately upon deployment to a preview environment, without requiring human intervention to update provider settings.
63
+
64
+ ---
65
+ Built with ❤️ by [CloneCommand](https://clonecommand.com)
@@ -0,0 +1,28 @@
1
+ export interface CCCConfig {
2
+ projectId?: string;
3
+ baseUrl?: string;
4
+ }
5
+ export declare class CloneCommandCloud {
6
+ private config;
7
+ init(config: CCCConfig): void;
8
+ private get projectId();
9
+ private get baseUrl();
10
+ private get serviceToken();
11
+ /**
12
+ * Internal helper to make authenticated requests to the CloneCommand API.
13
+ * This is used by server-side methods (e.g., image uploads).
14
+ */
15
+ private request;
16
+ get login(): {
17
+ /**
18
+ * Wraps a standard OAuth authorization URL with the CloneCommand Proxy.
19
+ * This allows ephemeral preview environments (*.clonecommand.app) to handle
20
+ * OAuth redirects without constant provider configuration changes.
21
+ *
22
+ * @param originalUrl The standard OAuth authorization URL
23
+ * @returns The proxied URL to redirect the user to
24
+ */
25
+ proxy: (originalUrl: string) => string;
26
+ };
27
+ }
28
+ export declare const ccc: CloneCommandCloud;
package/dist/index.js ADDED
@@ -0,0 +1,60 @@
1
+ export class CloneCommandCloud {
2
+ config = {};
3
+ init(config) {
4
+ this.config = {
5
+ ...this.config,
6
+ ...config,
7
+ };
8
+ }
9
+ get projectId() {
10
+ return this.config.projectId;
11
+ }
12
+ get baseUrl() {
13
+ return this.config.baseUrl || 'https://graph.clonecommand.com';
14
+ }
15
+ get serviceToken() {
16
+ return typeof process !== 'undefined' ? process.env.CC_TOKEN : undefined;
17
+ }
18
+ /**
19
+ * Internal helper to make authenticated requests to the CloneCommand API.
20
+ * This is used by server-side methods (e.g., image uploads).
21
+ */
22
+ async request(path, options = {}) {
23
+ const token = this.serviceToken;
24
+ const headers = new Headers(options.headers);
25
+ if (token) {
26
+ headers.set('Authorization', `Bearer ${token}`);
27
+ }
28
+ const response = await fetch(`${this.baseUrl}${path}`, {
29
+ ...options,
30
+ headers,
31
+ });
32
+ if (!response.ok) {
33
+ const error = await response.text();
34
+ throw new Error(`CloneCommand API Error: ${error}`);
35
+ }
36
+ return response.json();
37
+ }
38
+ get login() {
39
+ return {
40
+ /**
41
+ * Wraps a standard OAuth authorization URL with the CloneCommand Proxy.
42
+ * This allows ephemeral preview environments (*.clonecommand.app) to handle
43
+ * OAuth redirects without constant provider configuration changes.
44
+ *
45
+ * @param originalUrl The standard OAuth authorization URL
46
+ * @returns The proxied URL to redirect the user to
47
+ */
48
+ proxy: (originalUrl) => {
49
+ const pid = this.projectId;
50
+ if (!pid) {
51
+ throw new Error("CloneCommand: projectId is required. Provide it in ccc.init({ projectId }) " +
52
+ "or set the CLONECOMMAND_PROJECT_ID environment variable.");
53
+ }
54
+ const encodedUrl = encodeURIComponent(originalUrl);
55
+ return `${this.baseUrl}/login/proxy/start?projectId=${pid}&url=${encodedUrl}`;
56
+ }
57
+ };
58
+ }
59
+ }
60
+ export const ccc = new CloneCommandCloud();
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@clonecommand/cloud",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "description": "The official SDK for CloneCommand managed services",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "dev": "tsc -w"
18
+ },
19
+ "license": "MIT",
20
+ "devDependencies": {
21
+ "typescript": "^5.0.0"
22
+ }
23
+ }