pinme 2.0.0-beta.4 → 2.0.0-beta.6

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.
Files changed (2) hide show
  1. package/dist/index.js +163 -36
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -96,8 +96,8 @@ var require_package = __commonJS({
96
96
  // node_modules/.pnpm/dotenv@16.5.0/node_modules/dotenv/lib/main.js
97
97
  var require_main = __commonJS({
98
98
  "node_modules/.pnpm/dotenv@16.5.0/node_modules/dotenv/lib/main.js"(exports2, module2) {
99
- var fs15 = require("fs");
100
- var path16 = require("path");
99
+ var fs16 = require("fs");
100
+ var path17 = require("path");
101
101
  var os5 = require("os");
102
102
  var crypto3 = require("crypto");
103
103
  var packageJson = require_package();
@@ -200,7 +200,7 @@ var require_main = __commonJS({
200
200
  if (options && options.path && options.path.length > 0) {
201
201
  if (Array.isArray(options.path)) {
202
202
  for (const filepath of options.path) {
203
- if (fs15.existsSync(filepath)) {
203
+ if (fs16.existsSync(filepath)) {
204
204
  possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
205
205
  }
206
206
  }
@@ -208,15 +208,15 @@ var require_main = __commonJS({
208
208
  possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
209
209
  }
210
210
  } else {
211
- possibleVaultPath = path16.resolve(process.cwd(), ".env.vault");
211
+ possibleVaultPath = path17.resolve(process.cwd(), ".env.vault");
212
212
  }
213
- if (fs15.existsSync(possibleVaultPath)) {
213
+ if (fs16.existsSync(possibleVaultPath)) {
214
214
  return possibleVaultPath;
215
215
  }
216
216
  return null;
217
217
  }
218
218
  function _resolveHome(envPath) {
219
- return envPath[0] === "~" ? path16.join(os5.homedir(), envPath.slice(1)) : envPath;
219
+ return envPath[0] === "~" ? path17.join(os5.homedir(), envPath.slice(1)) : envPath;
220
220
  }
221
221
  function _configVault(options) {
222
222
  const debug = Boolean(options && options.debug);
@@ -232,7 +232,7 @@ var require_main = __commonJS({
232
232
  return { parsed };
233
233
  }
234
234
  function configDotenv(options) {
235
- const dotenvPath = path16.resolve(process.cwd(), ".env");
235
+ const dotenvPath = path17.resolve(process.cwd(), ".env");
236
236
  let encoding = "utf8";
237
237
  const debug = Boolean(options && options.debug);
238
238
  if (options && options.encoding) {
@@ -255,13 +255,13 @@ var require_main = __commonJS({
255
255
  }
256
256
  let lastError;
257
257
  const parsedAll = {};
258
- for (const path17 of optionPaths) {
258
+ for (const path18 of optionPaths) {
259
259
  try {
260
- const parsed = DotenvModule.parse(fs15.readFileSync(path17, { encoding }));
260
+ const parsed = DotenvModule.parse(fs16.readFileSync(path18, { encoding }));
261
261
  DotenvModule.populate(parsedAll, parsed, options);
262
262
  } catch (e) {
263
263
  if (debug) {
264
- _debug(`Failed to load ${path17} ${e.message}`);
264
+ _debug(`Failed to load ${path18} ${e.message}`);
265
265
  }
266
266
  lastError = e;
267
267
  }
@@ -1519,11 +1519,11 @@ function checkNodeVersion() {
1519
1519
 
1520
1520
  // bin/index.ts
1521
1521
  var import_commander = require("commander");
1522
- var import_chalk21 = __toESM(require("chalk"));
1522
+ var import_chalk22 = __toESM(require("chalk"));
1523
1523
  var import_figlet5 = __toESM(require("figlet"));
1524
1524
 
1525
1525
  // package.json
1526
- var version = "2.0.0-beta.4";
1526
+ var version = "2.0.0-beta.6";
1527
1527
 
1528
1528
  // bin/upload.ts
1529
1529
  var import_path7 = __toESM(require("path"));
@@ -1968,9 +1968,9 @@ function isVisitable(thing) {
1968
1968
  function removeBrackets(key) {
1969
1969
  return utils_default.endsWith(key, "[]") ? key.slice(0, -2) : key;
1970
1970
  }
1971
- function renderKey(path16, key, dots) {
1972
- if (!path16) return key;
1973
- return path16.concat(key).map(function each(token, i) {
1971
+ function renderKey(path17, key, dots) {
1972
+ if (!path17) return key;
1973
+ return path17.concat(key).map(function each(token, i) {
1974
1974
  token = removeBrackets(token);
1975
1975
  return !dots && i ? "[" + token + "]" : token;
1976
1976
  }).join(dots ? "." : "");
@@ -2015,9 +2015,9 @@ function toFormData(obj, formData, options) {
2015
2015
  }
2016
2016
  return value;
2017
2017
  }
2018
- function defaultVisitor(value, key, path16) {
2018
+ function defaultVisitor(value, key, path17) {
2019
2019
  let arr = value;
2020
- if (value && !path16 && typeof value === "object") {
2020
+ if (value && !path17 && typeof value === "object") {
2021
2021
  if (utils_default.endsWith(key, "{}")) {
2022
2022
  key = metaTokens ? key : key.slice(0, -2);
2023
2023
  value = JSON.stringify(value);
@@ -2036,7 +2036,7 @@ function toFormData(obj, formData, options) {
2036
2036
  if (isVisitable(value)) {
2037
2037
  return true;
2038
2038
  }
2039
- formData.append(renderKey(path16, key, dots), convertValue(value));
2039
+ formData.append(renderKey(path17, key, dots), convertValue(value));
2040
2040
  return false;
2041
2041
  }
2042
2042
  const stack = [];
@@ -2045,10 +2045,10 @@ function toFormData(obj, formData, options) {
2045
2045
  convertValue,
2046
2046
  isVisitable
2047
2047
  });
2048
- function build(value, path16) {
2048
+ function build(value, path17) {
2049
2049
  if (utils_default.isUndefined(value)) return;
2050
2050
  if (stack.indexOf(value) !== -1) {
2051
- throw Error("Circular reference detected in " + path16.join("."));
2051
+ throw Error("Circular reference detected in " + path17.join("."));
2052
2052
  }
2053
2053
  stack.push(value);
2054
2054
  utils_default.forEach(value, function each(el, key) {
@@ -2056,11 +2056,11 @@ function toFormData(obj, formData, options) {
2056
2056
  formData,
2057
2057
  el,
2058
2058
  utils_default.isString(key) ? key.trim() : key,
2059
- path16,
2059
+ path17,
2060
2060
  exposedHelpers
2061
2061
  );
2062
2062
  if (result === true) {
2063
- build(el, path16 ? path16.concat(key) : [key]);
2063
+ build(el, path17 ? path17.concat(key) : [key]);
2064
2064
  }
2065
2065
  });
2066
2066
  stack.pop();
@@ -2221,7 +2221,7 @@ var node_default = {
2221
2221
  // node_modules/.pnpm/axios@1.3.2/node_modules/axios/lib/helpers/toURLEncodedForm.js
2222
2222
  function toURLEncodedForm(data, options) {
2223
2223
  return toFormData_default(data, new node_default.classes.URLSearchParams(), Object.assign({
2224
- visitor: function(value, key, path16, helpers) {
2224
+ visitor: function(value, key, path17, helpers) {
2225
2225
  if (node_default.isNode && utils_default.isBuffer(value)) {
2226
2226
  this.append(key, value.toString("base64"));
2227
2227
  return false;
@@ -2250,10 +2250,10 @@ function arrayToObject(arr) {
2250
2250
  return obj;
2251
2251
  }
2252
2252
  function formDataToJSON(formData) {
2253
- function buildPath(path16, value, target, index) {
2254
- let name = path16[index++];
2253
+ function buildPath(path17, value, target, index) {
2254
+ let name = path17[index++];
2255
2255
  const isNumericKey = Number.isFinite(+name);
2256
- const isLast = index >= path16.length;
2256
+ const isLast = index >= path17.length;
2257
2257
  name = !name && utils_default.isArray(target) ? target.length : name;
2258
2258
  if (isLast) {
2259
2259
  if (utils_default.hasOwnProp(target, name)) {
@@ -2266,7 +2266,7 @@ function formDataToJSON(formData) {
2266
2266
  if (!target[name] || !utils_default.isObject(target[name])) {
2267
2267
  target[name] = [];
2268
2268
  }
2269
- const result = buildPath(path16, value, target[name], index);
2269
+ const result = buildPath(path17, value, target[name], index);
2270
2270
  if (result && utils_default.isArray(target[name])) {
2271
2271
  target[name] = arrayToObject(target[name]);
2272
2272
  }
@@ -3328,9 +3328,9 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
3328
3328
  auth = urlUsername + ":" + urlPassword;
3329
3329
  }
3330
3330
  auth && headers.delete("authorization");
3331
- let path16;
3331
+ let path17;
3332
3332
  try {
3333
- path16 = buildURL(
3333
+ path17 = buildURL(
3334
3334
  parsed.pathname + parsed.search,
3335
3335
  config.params,
3336
3336
  config.paramsSerializer
@@ -3348,7 +3348,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
3348
3348
  false
3349
3349
  );
3350
3350
  const options = {
3351
- path: path16,
3351
+ path: path17,
3352
3352
  method,
3353
3353
  headers: headers.toJSON(),
3354
3354
  agents: { http: config.httpAgent, https: config.httpsAgent },
@@ -3567,14 +3567,14 @@ var cookies_default = node_default.isStandardBrowserEnv ? (
3567
3567
  // Standard browser envs support document.cookie
3568
3568
  /* @__PURE__ */ function standardBrowserEnv() {
3569
3569
  return {
3570
- write: function write(name, value, expires, path16, domain, secure) {
3570
+ write: function write(name, value, expires, path17, domain, secure) {
3571
3571
  const cookie = [];
3572
3572
  cookie.push(name + "=" + encodeURIComponent(value));
3573
3573
  if (utils_default.isNumber(expires)) {
3574
3574
  cookie.push("expires=" + new Date(expires).toGMTString());
3575
3575
  }
3576
- if (utils_default.isString(path16)) {
3577
- cookie.push("path=" + path16);
3576
+ if (utils_default.isString(path17)) {
3577
+ cookie.push("path=" + path17);
3578
3578
  }
3579
3579
  if (utils_default.isString(domain)) {
3580
3580
  cookie.push("domain=" + domain);
@@ -7110,7 +7110,6 @@ var import_fs_extra6 = __toESM(require("fs-extra"));
7110
7110
  var import_path11 = __toESM(require("path"));
7111
7111
  var import_inquirer8 = __toESM(require("inquirer"));
7112
7112
  var import_child_process2 = require("child_process");
7113
- var TEMPLATE_DIR = import_path11.default.join(__dirname, "../template");
7114
7113
  var PROJECT_DIR = process.cwd();
7115
7114
  var API_BASE = "https://pinme.dev/api/v4";
7116
7115
  var TEMPLATE_REPO = "https://github.com/glitternetwork/pinme-worker-template.git";
@@ -7218,6 +7217,21 @@ Directory "${projectName}" already exists.`));
7218
7217
  /# database_id = ".*"/,
7219
7218
  `database_id = "${workerData.uuid}"`
7220
7219
  );
7220
+ if (workerData.api_key) {
7221
+ console.log(import_chalk16.default.gray(` API Key: ${workerData.api_key.slice(0, 8)}...`));
7222
+ updatedConfig = updatedConfig.replace(
7223
+ /^# api_key = ".*"$/m,
7224
+ `api_key = "${workerData.api_key}"`
7225
+ );
7226
+ if (!updatedConfig.includes(`api_key = "${workerData.api_key}"`)) {
7227
+ updatedConfig = updatedConfig.replace(
7228
+ /^api_key = ".*"$/m,
7229
+ `api_key = "${workerData.api_key}"`
7230
+ );
7231
+ }
7232
+ } else {
7233
+ console.log(import_chalk16.default.yellow(" Warning: No API Key returned from API"));
7234
+ }
7221
7235
  import_fs_extra6.default.writeFileSync(configPath, updatedConfig);
7222
7236
  console.log(import_chalk16.default.green(` Updated pinme.toml`));
7223
7237
  console.log(import_chalk16.default.gray(` metadata: ${workerData.metadata}`));
@@ -7231,6 +7245,16 @@ Directory "${projectName}" already exists.`));
7231
7245
  );
7232
7246
  console.log(import_chalk16.default.green(` Saved metadata.json`));
7233
7247
  }
7248
+ const wranglerPath = import_path11.default.join(backendDir, "wrangler.toml");
7249
+ if (import_fs_extra6.default.existsSync(wranglerPath) && workerData.api_key) {
7250
+ let wranglerContent = import_fs_extra6.default.readFileSync(wranglerPath, "utf-8");
7251
+ wranglerContent = wranglerContent.replace(
7252
+ /^API_KEY = ".*"$/m,
7253
+ `API_KEY = "${workerData.api_key}"`
7254
+ );
7255
+ import_fs_extra6.default.writeFileSync(wranglerPath, wranglerContent);
7256
+ console.log(import_chalk16.default.green(` Updated backend/wrangler.toml API_KEY`));
7257
+ }
7234
7258
  const envExamplePath = import_path11.default.join(targetDir, "frontend", ".env.example");
7235
7259
  const envPath = import_path11.default.join(targetDir, "frontend", ".env");
7236
7260
  if (import_fs_extra6.default.existsSync(envExamplePath)) {
@@ -7244,6 +7268,10 @@ Directory "${projectName}" already exists.`));
7244
7268
  /^VITE_API_URL=.*$/m,
7245
7269
  `VITE_API_URL=${workerData.api_domain}`
7246
7270
  );
7271
+ envContent = envContent.replace(
7272
+ /^VITE_API_URL=.*$/m,
7273
+ `VITE_API_KEY=${workerData.api_key}`
7274
+ );
7247
7275
  import_fs_extra6.default.writeFileSync(envPath, envContent);
7248
7276
  console.log(import_chalk16.default.green(` Created frontend/.env file`));
7249
7277
  }
@@ -7889,14 +7917,112 @@ async function updateWebCmd(options) {
7889
7917
  }
7890
7918
  }
7891
7919
 
7920
+ // bin/delete.ts
7921
+ var import_chalk21 = __toESM(require("chalk"));
7922
+ var import_inquirer9 = __toESM(require("inquirer"));
7923
+ var import_fs_extra11 = __toESM(require("fs-extra"));
7924
+ var import_path16 = __toESM(require("path"));
7925
+ var API_BASE5 = "https://pinme.dev/api/v4";
7926
+ function getProjectName() {
7927
+ const configPath = import_path16.default.join(process.cwd(), "pinme.toml");
7928
+ if (!import_fs_extra11.default.existsSync(configPath)) {
7929
+ return null;
7930
+ }
7931
+ const config = import_fs_extra11.default.readFileSync(configPath, "utf-8");
7932
+ const match = config.match(/project_name\s*=\s*"([^"]+)"/);
7933
+ return (match == null ? void 0 : match[1]) || null;
7934
+ }
7935
+ async function deleteCmd(options) {
7936
+ var _a, _b;
7937
+ try {
7938
+ const headers = getAuthHeaders();
7939
+ if (!headers["authentication-tokens"] || !headers["token-address"]) {
7940
+ console.log(import_chalk21.default.yellow("\n\u26A0\uFE0F You are not logged in."));
7941
+ console.log(import_chalk21.default.gray("Please run: pinme login"));
7942
+ process.exit(1);
7943
+ }
7944
+ console.log(import_chalk21.default.blue("Deleting project...\n"));
7945
+ let projectName = options.name || getProjectName();
7946
+ if (!projectName) {
7947
+ console.log(import_chalk21.default.red("\n\u274C Error: Cannot find project name."));
7948
+ console.log(import_chalk21.default.yellow(" Please make sure you are in the project directory."));
7949
+ console.log(import_chalk21.default.gray(" The project directory should contain a pinme.toml file."));
7950
+ console.log(import_chalk21.default.gray("\n Or specify the project name:"));
7951
+ console.log(import_chalk21.default.gray(" cd /path/to/your-project"));
7952
+ console.log(import_chalk21.default.gray(" pinme delete"));
7953
+ process.exit(1);
7954
+ }
7955
+ console.log(import_chalk21.default.gray(`Project: ${projectName}`));
7956
+ console.log(import_chalk21.default.gray(`Directory: ${process.cwd()}`));
7957
+ if (!options.force) {
7958
+ const answers = await import_inquirer9.default.prompt([
7959
+ {
7960
+ type: "confirm",
7961
+ name: "confirm",
7962
+ message: `Are you sure you want to delete project "${projectName}"? This will remove Worker, domain binding, and D1 database.`,
7963
+ default: false
7964
+ }
7965
+ ]);
7966
+ if (!answers.confirm) {
7967
+ console.log(import_chalk21.default.gray("Cancelled."));
7968
+ process.exit(0);
7969
+ }
7970
+ }
7971
+ console.log(import_chalk21.default.blue("Deleting project on platform..."));
7972
+ const apiUrl = `${API_BASE5}/delete_project`;
7973
+ console.log(import_chalk21.default.gray(`API URL: ${apiUrl}`));
7974
+ console.log(import_chalk21.default.gray(`Project name: ${projectName}`));
7975
+ const response = await axios_default.post(apiUrl, {
7976
+ project_name: projectName
7977
+ }, {
7978
+ headers: {
7979
+ ...headers,
7980
+ "Content-Type": "application/json"
7981
+ }
7982
+ }).catch((error) => {
7983
+ var _a2, _b2;
7984
+ console.log(import_chalk21.default.red(` Response status: ${(_a2 = error.response) == null ? void 0 : _a2.status}`));
7985
+ console.log(import_chalk21.default.red(` Response data: ${JSON.stringify((_b2 = error.response) == null ? void 0 : _b2.data)}`));
7986
+ throw error;
7987
+ });
7988
+ const data = response.data;
7989
+ if (data.code === 200) {
7990
+ console.log(import_chalk21.default.green("\n\u2705 Project deleted successfully!"));
7991
+ console.log(import_chalk21.default.gray(`
7992
+ Project: ${data.data.project_name}`));
7993
+ console.log(import_chalk21.default.gray(` Domain deleted: ${data.data.domain_deleted ? "\u2705" : "\u274C"}`));
7994
+ console.log(import_chalk21.default.gray(` Worker deleted: ${data.data.worker_deleted ? "\u2705" : "\u274C"}`));
7995
+ console.log(import_chalk21.default.gray(` Database deleted: ${data.data.database_deleted ? "\u2705" : "\u274C"}`));
7996
+ const projectDir = process.cwd();
7997
+ if (import_fs_extra11.default.existsSync(projectDir)) {
7998
+ console.log(import_chalk21.default.blue("\nDeleting local project directory..."));
7999
+ const parentDir = import_path16.default.dirname(projectDir);
8000
+ process.chdir(parentDir);
8001
+ await import_fs_extra11.default.remove(projectDir);
8002
+ console.log(import_chalk21.default.green(`\u2705 Local directory deleted: ${projectDir}`));
8003
+ }
8004
+ } else {
8005
+ const errorMsg = (data == null ? void 0 : data.msg) || "Failed to delete project";
8006
+ throw new Error(errorMsg);
8007
+ }
8008
+ process.exit(0);
8009
+ } catch (error) {
8010
+ console.log(import_chalk21.default.red(error));
8011
+ const errorMsg = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.msg) || error.message || "Failed to delete project";
8012
+ console.error(import_chalk21.default.red(`
8013
+ \u274C Error: ${errorMsg}`));
8014
+ process.exit(1);
8015
+ }
8016
+ }
8017
+
7892
8018
  // bin/index.ts
7893
8019
  import_dotenv.default.config();
7894
8020
  checkNodeVersion();
7895
8021
  function showBanner() {
7896
8022
  console.log(
7897
- import_chalk21.default.cyan(import_figlet5.default.textSync("Pinme", { horizontalLayout: "full" }))
8023
+ import_chalk22.default.cyan(import_figlet5.default.textSync("Pinme", { horizontalLayout: "full" }))
7898
8024
  );
7899
- console.log(import_chalk21.default.cyan("A command-line tool for uploading files to IPFS\n"));
8025
+ console.log(import_chalk22.default.cyan("A command-line tool for uploading files to IPFS\n"));
7900
8026
  }
7901
8027
  var program = new import_commander.Command();
7902
8028
  program.name("pinme").version(version).option("-v, --version", "output the current version");
@@ -7919,6 +8045,7 @@ program.command("save").description("Deploy the project (frontend + backend)").a
7919
8045
  program.command("update-db").description("Execute database migration").action(() => updateDbCmd());
7920
8046
  program.command("update-worker").description("Execute worker migration").action(() => updateWorkerCmd());
7921
8047
  program.command("update-web").description("Deploy frontend to IPFS").action((options) => updateWebCmd(options));
8048
+ program.command("delete").description("Delete a project (Worker, domain, D1 database)").argument("[name]", "Project name").option("-f, --force", "Skip confirmation").action((name, options) => deleteCmd({ name, force: options == null ? void 0 : options.force }));
7922
8049
  program.command("domain").description("Alias for 'my-domains' command").action(() => myDomainsCmd());
7923
8050
  program.command("list").description("show upload history").option(
7924
8051
  "-l, --limit <number>",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinme",
3
- "version": "2.0.0-beta.4",
3
+ "version": "2.0.0-beta.6",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },