@sidgaikwad/db-setup 1.1.0 → 1.2.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/dist/index.js CHANGED
@@ -23868,81 +23868,54 @@ ${databaseUrl}
23868
23868
 
23869
23869
  // src/providers/supabase.ts
23870
23870
  import { spawnSync as spawnSync2 } from "child_process";
23871
- function genAlphanumericPassword(length) {
23872
- const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
23873
- let password = "";
23871
+
23872
+ // src/utils/db-utils.ts
23873
+ var genAlphanumericPassword = (length = 24) => {
23874
+ const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
23875
+ let result = "";
23874
23876
  for (let i = 0;i < length; i++) {
23875
- password += chars.charAt(Math.floor(Math.random() * chars.length));
23877
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
23876
23878
  }
23877
- return password;
23878
- }
23879
- var checkSupabaseAuth = async () => {
23880
- process.stdout.write(source_default.blueBright("Checking Supabase authentication... "));
23879
+ return result;
23880
+ };
23881
+ var genRandomIdentifier = (length = 10) => {
23882
+ const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
23883
+ let result = "";
23884
+ for (let i = 0;i < length; i++) {
23885
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
23886
+ }
23887
+ return result;
23888
+ };
23889
+
23890
+ // src/providers/supabase.ts
23891
+ var checkSupabaseAuth = () => {
23892
+ process.stdout.write(source_default.blueBright(`
23893
+ Checking Supabase authentication... `));
23881
23894
  const authCheckResult = spawnSync2("npx", ["supabase", "orgs", "list"], {
23882
23895
  encoding: "utf-8",
23883
23896
  shell: true,
23884
23897
  stdio: "pipe"
23885
23898
  });
23886
23899
  if (authCheckResult.status !== 0) {
23887
- console.log(source_default.yellowBright(`not logged in
23888
- `));
23889
- console.log(source_default.cyan("\uD83D\uDD10 Opening browser for authentication..."));
23890
- console.log(source_default.gray(`Please complete the authentication in your browser.
23900
+ console.log(source_default.yellowBright("not logged in"));
23901
+ console.log(source_default.blueBright(`
23902
+ Launching Supabase login...`));
23903
+ console.log(source_default.gray(`Please complete authentication in your browser.
23891
23904
  `));
23892
- console.log(source_default.blueBright(" Waiting for authentication..."));
23893
- const loginResult = spawnSync2("npx", ["supabase", "login"], {
23894
- stdio: "inherit",
23895
- shell: true
23896
- });
23897
- if (loginResult.status !== 0) {
23898
- console.log(source_default.red(`
23899
- ❌ Authentication failed or was cancelled.`));
23900
- process.exit(1);
23901
- }
23905
+ spawnSync2("npx", ["supabase", "login"], { stdio: "inherit", shell: true });
23902
23906
  console.log(source_default.greenBright(`
23903
- Successfully authenticated!`));
23904
- return true;
23907
+ Authentication completed!`));
23908
+ return false;
23905
23909
  }
23906
23910
  console.log(source_default.greenBright("✓"));
23907
23911
  return true;
23908
23912
  };
23909
- var logoutSupabase = () => {
23910
- console.log(source_default.blueBright(`
23911
- Logging out from Supabase...`));
23912
- const logoutResult = spawnSync2("supabase", ["logout"], {
23913
- stdio: "inherit",
23914
- shell: true
23915
- });
23916
- if (logoutResult.status === 0) {
23917
- console.log(source_default.greenBright("✅ Successfully logged out from Supabase."));
23918
- } else {
23919
- console.log(source_default.red("❌ Failed to logout."));
23920
- }
23921
- };
23922
- var getSupabaseRegions = () => {
23923
- return [
23924
- { name: "\uD83C\uDDF8\uD83C\uDDEC Southeast Asia (Singapore)", value: "ap-southeast-1" },
23925
- { name: "\uD83C\uDDE6\uD83C\uDDFA Asia Pacific (Sydney)", value: "ap-southeast-2" },
23926
- { name: "\uD83C\uDDEE\uD83C\uDDF3 Asia Pacific (Mumbai)", value: "ap-south-1" },
23927
- { name: "\uD83C\uDDEF\uD83C\uDDF5 Asia Pacific (Tokyo)", value: "ap-northeast-1" },
23928
- { name: "\uD83C\uDDF0\uD83C\uDDF7 Asia Pacific (Seoul)", value: "ap-northeast-2" },
23929
- { name: "\uD83C\uDDFA\uD83C\uDDF8 US East (N. Virginia)", value: "us-east-1" },
23930
- { name: "\uD83C\uDDFA\uD83C\uDDF8 US West (Oregon)", value: "us-west-1" },
23931
- { name: "\uD83C\uDDE8\uD83C\uDDE6 Canada (Central)", value: "ca-central-1" },
23932
- { name: "\uD83C\uDDEA\uD83C\uDDFA Europe (Frankfurt)", value: "eu-central-1" },
23933
- { name: "\uD83C\uDDEC\uD83C\uDDE7 Europe (London)", value: "eu-west-2" },
23934
- { name: "\uD83C\uDDE7\uD83C\uDDF7 South America (São Paulo)", value: "sa-east-1" }
23935
- ];
23936
- };
23937
23913
  var getOrCreateSupabaseOrg = async () => {
23938
- process.stdout.write(source_default.blueBright("Checking organizations... "));
23939
23914
  const orgListResult = spawnSync2("npx", ["supabase", "orgs", "list"], {
23940
23915
  encoding: "utf-8",
23941
- shell: true,
23942
- stdio: "pipe"
23916
+ shell: true
23943
23917
  });
23944
23918
  if (orgListResult.status !== 0) {
23945
- console.log(source_default.red("✗"));
23946
23919
  console.error(source_default.red("❌ Failed to list Supabase orgs."));
23947
23920
  process.exit(1);
23948
23921
  }
@@ -23950,109 +23923,66 @@ var getOrCreateSupabaseOrg = async () => {
23950
23923
  `).map((l) => l.trim()).filter(Boolean);
23951
23924
  const sepIdx = lines2.findIndex((line) => line.includes("|") && line.includes("-"));
23952
23925
  if (lines2.length <= sepIdx + 1) {
23953
- console.log(source_default.yellowBright(`none found
23954
- `));
23955
- console.log(source_default.yellowBright("⚠️ No Supabase organizations found."));
23926
+ console.log(source_default.yellowBright("No Supabase organizations found."));
23956
23927
  const createOrg = await esm_default2({
23957
- message: source_default.cyan("Would you like to create a new Supabase organization?"),
23928
+ message: source_default.cyan("Would you like to create a new Supabase organization now?"),
23958
23929
  default: true
23959
23930
  });
23960
23931
  if (!createOrg) {
23961
- console.log(source_default.red(`
23962
- ❌ Cannot continue without a Supabase organization.`));
23963
- console.log(source_default.gray(`You can create one later at: https://supabase.com/dashboard
23964
- `));
23932
+ console.log(source_default.red("❌ Cannot continue without a Supabase organization. Exiting."));
23965
23933
  process.exit(1);
23966
23934
  }
23967
23935
  const orgName = await esm_default3({
23968
23936
  message: source_default.cyan("Enter a name for your new Supabase organization:"),
23969
23937
  validate: (inputValue) => {
23970
- if (!inputValue || inputValue.trim().length < 3) {
23938
+ if (!inputValue || inputValue.length < 3) {
23971
23939
  return "Organization name must be at least 3 characters";
23972
23940
  }
23973
23941
  return true;
23974
23942
  }
23975
23943
  });
23976
23944
  console.log(source_default.blueBright(`
23977
- Creating Supabase organization '${orgName}'...`));
23945
+ Creating Supabase organization '${orgName}'...`));
23978
23946
  const createOrgResult = spawnSync2("npx", ["supabase", "orgs", "create", orgName], {
23979
23947
  stdio: "inherit",
23980
23948
  encoding: "utf-8",
23981
23949
  shell: true
23982
23950
  });
23983
23951
  if (createOrgResult.status !== 0) {
23984
- console.error(source_default.red(`
23985
- ❌ Failed to create Supabase organization.`));
23952
+ console.error(source_default.red("❌ Failed to create Supabase organization."));
23986
23953
  process.exit(1);
23987
23954
  }
23988
- console.log(source_default.greenBright("✅ Organization created!"));
23989
- } else {
23990
- console.log(source_default.greenBright("✓"));
23991
23955
  }
23992
23956
  };
23993
- var createSupabaseProject = async (projectName, dbPassword, region) => {
23957
+ var createSupabaseProject = async (projectName, dbPassword) => {
23994
23958
  console.log(source_default.blueBright(`
23995
- Creating Supabase project '${projectName}' in ${region}...`));
23996
- console.log(source_default.gray(`This may take 2-3 minutes. Please wait...
23997
- `));
23959
+ Creating Supabase project '${projectName}'...`));
23998
23960
  const createResult = spawnSync2("npx", [
23999
23961
  "supabase",
24000
23962
  "projects",
24001
23963
  "create",
24002
23964
  projectName,
24003
23965
  "--db-password",
24004
- dbPassword,
24005
- "--region",
24006
- region,
24007
- "--plan",
24008
- "free"
23966
+ dbPassword
24009
23967
  ], { stdio: "inherit", encoding: "utf-8", shell: true });
24010
23968
  if (createResult.status !== 0) {
24011
- console.error(source_default.red(`
24012
- ❌ Failed to create Supabase project.`));
24013
- console.log(source_default.yellow(`
24014
- Possible reasons:`));
24015
- console.log(source_default.gray(" • You've reached the free project limit (2 projects)"));
24016
- console.log(source_default.gray(" • Project name already exists"));
24017
- console.log(source_default.gray(` • Organization quota exceeded
24018
- `));
24019
- console.log(source_default.cyan("\uD83D\uDCA1 Solutions:"));
24020
- console.log(source_default.gray(" 1. Delete or pause an existing project at https://supabase.com/dashboard"));
24021
- console.log(source_default.gray(" 2. Upgrade your plan"));
24022
- console.log(source_default.gray(` 3. Use a different organization
24023
- `));
24024
- const shouldLogout = await esm_default2({
24025
- message: source_default.yellow("Would you like to logout and try with a different account?"),
24026
- default: false
24027
- });
24028
- if (shouldLogout) {
24029
- logoutSupabase();
24030
- console.log(source_default.cyan(`
24031
- Run the setup again to login with a different account.
24032
- `));
24033
- }
23969
+ console.error(source_default.red("❌ Failed to create Supabase project."));
24034
23970
  process.exit(1);
24035
23971
  }
24036
- process.stdout.write(source_default.blueBright(`
24037
- Fetching project details... `));
24038
23972
  const listResult = spawnSync2("npx", ["supabase", "projects", "list", "--output", "json"], {
24039
23973
  encoding: "utf-8",
24040
- shell: true,
24041
- stdio: "pipe"
23974
+ shell: true
24042
23975
  });
24043
23976
  if (listResult.status !== 0) {
24044
- console.log(source_default.red("✗"));
24045
23977
  console.error(source_default.red("❌ Failed to list Supabase projects."));
24046
23978
  process.exit(1);
24047
23979
  }
24048
23980
  const projects = JSON.parse(listResult.stdout);
24049
23981
  const found = projects.find((p) => p.name === projectName);
24050
23982
  if (!found) {
24051
- console.log(source_default.red("✗"));
24052
23983
  console.error(source_default.red("❌ Failed to find new Supabase project."));
24053
23984
  process.exit(1);
24054
23985
  }
24055
- console.log(source_default.greenBright("✓"));
24056
23986
  return {
24057
23987
  projectId: found.id,
24058
23988
  region: found.region
@@ -24064,15 +23994,9 @@ var setupSupabase = async () => {
24064
23994
  `));
24065
23995
  checkSupabaseAuth();
24066
23996
  await getOrCreateSupabaseOrg();
24067
- const regions = getSupabaseRegions();
24068
- const selectedRegion = await esm_default4({
24069
- message: source_default.cyan("Select your Supabase region:"),
24070
- choices: regions,
24071
- default: "ap-south-1"
24072
- });
24073
23997
  const projectName = await esm_default3({
24074
23998
  message: source_default.cyan("Enter a name for your Supabase project:"),
24075
- default: "my-supabase-project",
23999
+ default: "ZeroStarter-oss-db",
24076
24000
  validate: (inputValue) => {
24077
24001
  if (!inputValue || inputValue.trim().length === 0) {
24078
24002
  return "Project name cannot be empty";
@@ -24087,17 +24011,14 @@ var setupSupabase = async () => {
24087
24011
  }
24088
24012
  });
24089
24013
  const dbPassword = genAlphanumericPassword(24);
24090
- console.log(source_default.gray(`
24091
- \uD83D\uDD11 Generated secure database password`));
24092
- const { projectId, region } = await createSupabaseProject(projectName, dbPassword, selectedRegion);
24014
+ const { projectId, region } = await createSupabaseProject(projectName, dbPassword);
24093
24015
  const databaseUrl = `postgresql://postgres.${projectId}:${dbPassword}@aws-0-${region}.pooler.supabase.com:6543/postgres`;
24094
24016
  console.log(source_default.greenBright(`
24095
- Supabase project created successfully!`));
24096
- console.log(source_default.greenBright(`Project ID: ${projectId}`));
24097
- console.log(source_default.greenBright(`Region: ${region}`));
24098
- console.log(source_default.gray(`
24099
- \uD83D\uDCA1 Save this password safely: ${dbPassword}`));
24100
- console.log(source_default.gray(`Dashboard: https://supabase.com/dashboard/project/${projectId}
24017
+ Generated DB password: ${dbPassword}
24018
+ `));
24019
+ console.log(source_default.greenBright(`
24020
+ Your DATABASE_URL is:
24021
+ ${databaseUrl}
24101
24022
  `));
24102
24023
  console.log(source_default.yellow("--------------------------------"));
24103
24024
  return databaseUrl;
@@ -27893,26 +27814,6 @@ Fetching DATABASE_URL...`));
27893
27814
 
27894
27815
  // src/providers/local-docker.ts
27895
27816
  import { spawnSync as spawnSync5 } from "child_process";
27896
-
27897
- // src/utils/db-utils.ts
27898
- var genAlphanumericPassword2 = (length = 24) => {
27899
- const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
27900
- let result = "";
27901
- for (let i = 0;i < length; i++) {
27902
- result += chars.charAt(Math.floor(Math.random() * chars.length));
27903
- }
27904
- return result;
27905
- };
27906
- var genRandomIdentifier = (length = 10) => {
27907
- const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
27908
- let result = "";
27909
- for (let i = 0;i < length; i++) {
27910
- result += chars.charAt(Math.floor(Math.random() * chars.length));
27911
- }
27912
- return result;
27913
- };
27914
-
27915
- // src/providers/local-docker.ts
27916
27817
  var setupLocalDocker = async () => {
27917
27818
  console.log(source_default.magentaBright(`
27918
27819
  ================ Local Docker PostgreSQL Setup ================
@@ -27931,7 +27832,7 @@ var setupLocalDocker = async () => {
27931
27832
  console.log(source_default.greenBright("✅ Docker is installed"));
27932
27833
  const containerName = `zerostarter-postgres-${genRandomIdentifier(6)}`;
27933
27834
  const dbUser = "postgres";
27934
- const dbPassword = genAlphanumericPassword2(24);
27835
+ const dbPassword = genAlphanumericPassword(24);
27935
27836
  const dbName = "zerostarter";
27936
27837
  const dbPort = 5432;
27937
27838
  console.log(source_default.blueBright(`
@@ -1,7 +1,3 @@
1
- /**
2
- * Logout from Supabase
3
- */
4
- export declare const logoutSupabase: () => void;
5
1
  /**
6
2
  * Main function to set up Supabase and return DATABASE_URL
7
3
  */
@@ -1 +1 @@
1
- {"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/providers/supabase.ts"],"names":[],"mappings":"AAmEA;;GAEG;AACH,eAAO,MAAM,cAAc,QAAO,IAYjC,CAAC;AAgNF;;GAEG;AACH,eAAO,MAAM,aAAa,QAAa,OAAO,CAAC,MAAM,CAgEpD,CAAC"}
1
+ {"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/providers/supabase.ts"],"names":[],"mappings":"AA4KA;;GAEG;AACH,eAAO,MAAM,aAAa,QAAa,OAAO,CAAC,MAAM,CA8CpD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sidgaikwad/db-setup",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Interactive CLI for setting up PostgreSQL databases with multiple providers (Neon, Supabase, Railway, Local)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",