@autoship/react 0.5.0 → 0.6.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/README.md CHANGED
@@ -26,7 +26,7 @@ Create a new Supabase project (or use an existing one). Get the SUPABASE_URL and
26
26
  Run the migrations using the CLI:
27
27
 
28
28
  ```bash
29
- npx @autoship init
29
+ npx @autoship/react init
30
30
  ```
31
31
 
32
32
  The CLI will prompt you for credentials. You can provide them in two ways:
@@ -35,23 +35,24 @@ The CLI will prompt you for credentials. You can provide them in two ways:
35
35
 
36
36
  ```bash
37
37
  # Find this in Supabase Dashboard > Project Settings > Database > Connection string > URI
38
- npx @autoship init --database-url "postgresql://postgres.xxx:password@aws-0-region.pooler.supabase.com:6543/postgres"
38
+ npx @autoship/react init --database-url "postgresql://postgres:password@db.xxxx.supabase.co:5432/postgres"
39
39
  ```
40
40
 
41
- **Option B: Supabase URL + Database Password**
41
+ **Option B: Project Ref + Database Password**
42
42
 
43
43
  ```bash
44
- npx @autoship init --supabase-url https://xxx.supabase.co --db-password yourpassword
44
+ # Find project ref in Supabase Dashboard > Project Settings > General > Reference ID
45
+ npx @autoship/react init --project-ref abcdefghijklmnop --db-password yourpassword
45
46
  ```
46
47
 
47
48
  **Using environment variables:**
48
49
 
49
50
  ```bash
50
51
  # Option A
51
- DATABASE_URL="postgresql://..." npx @autoship init
52
+ DATABASE_URL="postgresql://..." npx @autoship/react init
52
53
 
53
54
  # Option B
54
- SUPABASE_URL="https://xxx.supabase.co" DB_PASSWORD="yourpassword" npx @autoship/react init
55
+ SUPABASE_PROJECT_REF="abcdefghijklmnop" DB_PASSWORD="yourpassword" npx @autoship/react init
55
56
  ```
56
57
 
57
58
  ### 3. Expose the Autoship Schema in Supabase
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/cli/init.ts"],"names":[],"mappings":"AAkXA,wBAAsB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAcvD"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/cli/init.ts"],"names":[],"mappings":"AA4WA,wBAAsB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAcvD"}
package/dist/cli/init.js CHANGED
@@ -35,8 +35,8 @@ function parseArgs(args) {
35
35
  if (arg === "--database-url" && args[i + 1]) {
36
36
  options.databaseUrl = args[++i];
37
37
  }
38
- else if (arg === "--supabase-url" && args[i + 1]) {
39
- options.supabaseUrl = args[++i];
38
+ else if (arg === "--project-ref" && args[i + 1]) {
39
+ options.projectRef = args[++i];
40
40
  }
41
41
  else if (arg === "--db-password" && args[i + 1]) {
42
42
  options.dbPassword = args[++i];
@@ -56,39 +56,41 @@ function printHelp() {
56
56
  autoship init - Initialize Autoship database schema
57
57
 
58
58
  Usage:
59
- npx autoship init [options]
59
+ npx @autoship/react init [options]
60
60
 
61
61
  Options:
62
- --database-url <url> Full PostgreSQL connection URL (includes password)
63
- --supabase-url <url> Supabase project URL (used to construct DATABASE_URL)
64
- --db-password <pwd> Database password (used with --supabase-url)
65
- -y, --non-interactive Skip confirmation prompts
66
- -h, --help Show this help message
62
+ --database-url <url> Full PostgreSQL connection URL (includes password)
63
+ --project-ref <ref> Supabase project ref (used to construct DATABASE_URL)
64
+ --db-password <pwd> Database password (used with --project-ref)
65
+ -y, --non-interactive Skip confirmation prompts
66
+ -h, --help Show this help message
67
67
 
68
68
  Environment Variables:
69
- DATABASE_URL Full PostgreSQL connection URL (preferred)
70
- SUPABASE_URL Supabase project URL (fallback, requires DB_PASSWORD)
71
- DB_PASSWORD Database password (used with SUPABASE_URL)
69
+ DATABASE_URL Full PostgreSQL connection URL (preferred)
70
+ SUPABASE_PROJECT_REF Supabase project ref (fallback, requires DB_PASSWORD)
71
+ DB_PASSWORD Database password (used with SUPABASE_PROJECT_REF)
72
72
 
73
73
  Connection Methods:
74
- 1. Provide DATABASE_URL directly (recommended):
75
- DATABASE_URL=postgresql://postgres.xxx:[password]@aws-0-region.pooler.supabase.com:6543/postgres
74
+ 1. Provide DATABASE_URL directly:
75
+ Find in Supabase Dashboard > Project Settings > Database > Connection string > URI
76
76
 
77
- 2. Provide SUPABASE_URL + DB_PASSWORD:
78
- The CLI will construct the DATABASE_URL from your Supabase project URL.
77
+ 2. Provide SUPABASE_PROJECT_REF + DB_PASSWORD:
78
+ Find project ref in Supabase Dashboard > Project Settings > General > Reference ID
79
+ Find password in Supabase Dashboard > Project Settings > Database > Database password
79
80
 
80
81
  Examples:
81
82
  # Interactive mode (prompts for credentials)
82
- npx autoship init
83
+ npx @autoship/react init
83
84
 
84
85
  # With full database URL
85
- npx autoship init --database-url "postgresql://postgres.xxx:password@aws-0-region.pooler.supabase.com:6543/postgres"
86
+ npx @autoship/react init --database-url "postgresql://postgres:password@db.xxxx.supabase.co:5432/postgres"
86
87
 
87
- # With Supabase URL + password
88
- npx autoship init --supabase-url https://xxx.supabase.co --db-password mypassword
88
+ # With project ref + password
89
+ npx @autoship/react init --project-ref abcdefghijklmnop --db-password mypassword
89
90
 
90
91
  # Using environment variables
91
- DATABASE_URL="postgresql://..." npx autoship init
92
+ DATABASE_URL="postgresql://..." npx @autoship/react init
93
+ SUPABASE_PROJECT_REF="abcdefghijklmnop" DB_PASSWORD="mypassword" npx @autoship/react init
92
94
  `);
93
95
  }
94
96
  function createReadlineInterface() {
@@ -143,28 +145,20 @@ async function promptSecret(rl, question) {
143
145
  });
144
146
  }
145
147
  /**
146
- * Constructs a DATABASE_URL from a Supabase project URL and password.
148
+ * Constructs a DATABASE_URL from a Supabase project ref and password.
147
149
  *
148
- * Supabase URL format: https://[project-ref].supabase.co
149
- * Database URL format: postgresql://postgres.[project-ref]:[password]@aws-0-[region].pooler.supabase.com:6543/postgres
150
+ * Project ref: The unique identifier for your Supabase project (e.g., "abcdefghijklmnop")
151
+ * Database URL format: postgresql://postgres:[password]@db.[project-ref].supabase.co:5432/postgres
150
152
  *
151
- * Note: We use the transaction pooler (port 6543) for compatibility.
152
- * The region is detected from the Supabase URL or defaults to us-east-1.
153
+ * Note: We use the direct connection (port 5432) instead of the pooler
154
+ * because the pooler requires region-specific endpoints.
153
155
  */
154
- function constructDatabaseUrl(supabaseUrl, password) {
155
- const url = new URL(supabaseUrl);
156
- const hostname = url.hostname; // e.g., "xxx.supabase.co"
157
- const projectRef = hostname.split(".")[0];
156
+ function constructDatabaseUrl(projectRef, password) {
158
157
  if (!projectRef) {
159
- throw new Error("Could not extract project reference from Supabase URL");
158
+ throw new Error("Project ref is required");
160
159
  }
161
- // Supabase uses different regional pooler endpoints
162
- // Default to us-east-1, but this can be adjusted
163
- // The actual region is embedded in the project, but we can't easily detect it
164
- // Users can provide DATABASE_URL directly if they need a specific region
165
- const region = "us-east-1";
166
160
  const encodedPassword = encodeURIComponent(password);
167
- return `postgresql://postgres.${projectRef}:${encodedPassword}@aws-0-${region}.pooler.supabase.com:6543/postgres`;
161
+ return `postgresql://postgres:${encodedPassword}@db.${projectRef}.supabase.co:5432/postgres`;
168
162
  }
169
163
  async function getConnectionUrl(options) {
170
164
  // Priority: CLI args > env vars > interactive prompt
@@ -173,11 +167,11 @@ async function getConnectionUrl(options) {
173
167
  if (databaseUrl) {
174
168
  return databaseUrl;
175
169
  }
176
- // Check for SUPABASE_URL + DB_PASSWORD combination
177
- let supabaseUrl = options.supabaseUrl || process.env.SUPABASE_URL;
170
+ // Check for PROJECT_REF + DB_PASSWORD combination
171
+ let projectRef = options.projectRef || process.env.SUPABASE_PROJECT_REF;
178
172
  let dbPassword = options.dbPassword || process.env.DB_PASSWORD;
179
- if (supabaseUrl && dbPassword) {
180
- return constructDatabaseUrl(supabaseUrl, dbPassword);
173
+ if (projectRef && dbPassword) {
174
+ return constructDatabaseUrl(projectRef, dbPassword);
181
175
  }
182
176
  // Interactive mode
183
177
  const rl = createReadlineInterface();
@@ -186,8 +180,8 @@ async function getConnectionUrl(options) {
186
180
  console.log(" This will create the required tables in your Supabase database.\n");
187
181
  console.log(" You can provide credentials in two ways:");
188
182
  console.log(" 1. Full DATABASE_URL (includes password)");
189
- console.log(" 2. Supabase URL + database password\n");
190
- const choice = await prompt(rl, " Enter (1) for DATABASE_URL or (2) for Supabase URL + password: ");
183
+ console.log(" 2. Supabase project ref + database password\n");
184
+ const choice = await prompt(rl, " Enter (1) for DATABASE_URL or (2) for project ref + password: ");
191
185
  if (choice === "1") {
192
186
  console.log("\n Find your DATABASE_URL in Supabase Dashboard:");
193
187
  console.log(" Project Settings > Database > Connection string > URI\n");
@@ -195,18 +189,20 @@ async function getConnectionUrl(options) {
195
189
  return databaseUrl;
196
190
  }
197
191
  else {
198
- if (!supabaseUrl) {
199
- supabaseUrl = await prompt(rl, "\n Supabase URL (e.g., https://xxx.supabase.co): ");
192
+ if (!projectRef) {
193
+ console.log("\n Find your project ref in Supabase Dashboard:");
194
+ console.log(" Project Settings > General > Reference ID\n");
195
+ projectRef = await prompt(rl, " Project ref: ");
200
196
  }
201
197
  else {
202
- console.log(`\n Supabase URL: ${supabaseUrl}`);
198
+ console.log(`\n Project ref: ${projectRef}`);
203
199
  }
204
200
  if (!dbPassword) {
205
201
  console.log("\n Find your database password in Supabase Dashboard:");
206
202
  console.log(" Project Settings > Database > Database password\n");
207
203
  dbPassword = await promptSecret(rl, " Database password: ");
208
204
  }
209
- return constructDatabaseUrl(supabaseUrl, dbPassword);
205
+ return constructDatabaseUrl(projectRef, dbPassword);
210
206
  }
211
207
  }
212
208
  finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autoship/react",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",