plazbot-cli 0.2.24 → 0.2.25

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.
@@ -74,14 +74,44 @@ exports.whatsappConnectCommand = new commander_1.Command('connect')
74
74
  });
75
75
  console.log();
76
76
  }
77
- // Generar link de onboarding
78
- const spinner = (0, ora_1.default)({ text: chalk_1.default.gray('Generando link de conexion...'), spinner: 'dots', color: 'green' }).start();
79
- const linkRes = await axios_1.default.post(`${baseUrl}/api/workspace/${credentials.workspace}/onboarding-link`, { type: channelType }, { headers });
80
- if (!linkRes.data?.success) {
81
- spinner.fail(chalk_1.default.hex('#EF5350')(`Error: ${linkRes.data?.message || 'No se pudo generar el link'}`));
77
+ // Obtener o generar link de onboarding (mismo flujo que Plazbot Front)
78
+ const ONBOARDING_SHORT_DOMAIN = 'https://co.plzb.link';
79
+ const spinner = (0, ora_1.default)({ text: chalk_1.default.gray('Obteniendo link de conexion...'), spinner: 'dots', color: 'green' }).start();
80
+ let linkData = null;
81
+ // 1. Intentar obtener link existente (GET)
82
+ try {
83
+ const getRes = await axios_1.default.get(`${baseUrl}/api/workspace/${credentials.workspace}/onboarding-link`, { headers, params: { type: channelType } });
84
+ linkData = getRes.data?.data ?? null;
85
+ }
86
+ catch {
87
+ linkData = null;
88
+ }
89
+ // 2. Si existe pero esta expirado, regenerar
90
+ if (linkData?.expiresAt && new Date(linkData.expiresAt) < new Date()) {
91
+ try {
92
+ const regenRes = await axios_1.default.post(`${baseUrl}/api/workspace/${credentials.workspace}/onboarding-link/regenerate`, { type: channelType }, { headers });
93
+ linkData = regenRes.data?.data ?? null;
94
+ }
95
+ catch {
96
+ linkData = null;
97
+ }
98
+ }
99
+ // 3. Si no existe, generar uno nuevo (POST)
100
+ if (!linkData?.token) {
101
+ try {
102
+ const createRes = await axios_1.default.post(`${baseUrl}/api/workspace/${credentials.workspace}/onboarding-link`, { type: channelType }, { headers });
103
+ linkData = createRes.data?.data ?? null;
104
+ }
105
+ catch {
106
+ linkData = null;
107
+ }
108
+ }
109
+ if (!linkData?.token) {
110
+ spinner.fail(chalk_1.default.hex('#EF5350')('No se pudo obtener el link de conexion'));
82
111
  process.exit(1);
83
112
  }
84
- const shortUrl = linkRes.data.data?.shortUrl || '';
113
+ const shortUrl = `${ONBOARDING_SHORT_DOMAIN}/${linkData.token}`;
114
+ const expiresAt = linkData.expiresAt ? new Date(linkData.expiresAt).toLocaleDateString('es-ES', { day: 'numeric', month: 'long', year: 'numeric' }) : '';
85
115
  spinner.stop();
86
116
  // Mostrar link
87
117
  console.log(chalk_1.default.hex('#25D366')(' ┌' + '─'.repeat(54) + '┐'));
@@ -90,6 +120,9 @@ exports.whatsappConnectCommand = new commander_1.Command('connect')
90
120
  console.log(chalk_1.default.hex('#25D366')(' │') + chalk_1.default.hex('#22d3ee')(` ${shortUrl}`).padEnd(64) + chalk_1.default.hex('#25D366')('│'));
91
121
  console.log(chalk_1.default.hex('#25D366')(' │') + ''.padEnd(54) + chalk_1.default.hex('#25D366')('│'));
92
122
  console.log(chalk_1.default.hex('#25D366')(' │') + chalk_1.default.gray(' Escanea el codigo QR desde tu WhatsApp').padEnd(64) + chalk_1.default.hex('#25D366')('│'));
123
+ if (expiresAt) {
124
+ console.log(chalk_1.default.hex('#25D366')(' │') + chalk_1.default.gray(` Expira: ${expiresAt}`).padEnd(64) + chalk_1.default.hex('#25D366')('│'));
125
+ }
93
126
  console.log(chalk_1.default.hex('#25D366')(' └' + '─'.repeat(54) + '┘'));
94
127
  console.log();
95
128
  // Guardar IDs actuales para detectar nuevos
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plazbot-cli",
3
- "version": "0.2.24",
3
+ "version": "0.2.25",
4
4
  "description": "CLI para Plazbot SDK",
5
5
  "main": "dist/cli.js",
6
6
  "bin": {
@@ -79,21 +79,58 @@ export const whatsappConnectCommand = new Command('connect')
79
79
  console.log();
80
80
  }
81
81
 
82
- // Generar link de onboarding
83
- const spinner = ora({ text: chalk.gray('Generando link de conexion...'), spinner: 'dots', color: 'green' }).start();
82
+ // Obtener o generar link de onboarding (mismo flujo que Plazbot Front)
83
+ const ONBOARDING_SHORT_DOMAIN = 'https://co.plzb.link';
84
+ const spinner = ora({ text: chalk.gray('Obteniendo link de conexion...'), spinner: 'dots', color: 'green' }).start();
85
+
86
+ let linkData: any = null;
87
+
88
+ // 1. Intentar obtener link existente (GET)
89
+ try {
90
+ const getRes = await axios.get(
91
+ `${baseUrl}/api/workspace/${credentials.workspace}/onboarding-link`,
92
+ { headers, params: { type: channelType } }
93
+ );
94
+ linkData = getRes.data?.data ?? null;
95
+ } catch {
96
+ linkData = null;
97
+ }
84
98
 
85
- const linkRes = await axios.post(
86
- `${baseUrl}/api/workspace/${credentials.workspace}/onboarding-link`,
87
- { type: channelType },
88
- { headers }
89
- );
99
+ // 2. Si existe pero esta expirado, regenerar
100
+ if (linkData?.expiresAt && new Date(linkData.expiresAt) < new Date()) {
101
+ try {
102
+ const regenRes = await axios.post(
103
+ `${baseUrl}/api/workspace/${credentials.workspace}/onboarding-link/regenerate`,
104
+ { type: channelType },
105
+ { headers }
106
+ );
107
+ linkData = regenRes.data?.data ?? null;
108
+ } catch {
109
+ linkData = null;
110
+ }
111
+ }
90
112
 
91
- if (!linkRes.data?.success) {
92
- spinner.fail(chalk.hex('#EF5350')(`Error: ${linkRes.data?.message || 'No se pudo generar el link'}`));
113
+ // 3. Si no existe, generar uno nuevo (POST)
114
+ if (!linkData?.token) {
115
+ try {
116
+ const createRes = await axios.post(
117
+ `${baseUrl}/api/workspace/${credentials.workspace}/onboarding-link`,
118
+ { type: channelType },
119
+ { headers }
120
+ );
121
+ linkData = createRes.data?.data ?? null;
122
+ } catch {
123
+ linkData = null;
124
+ }
125
+ }
126
+
127
+ if (!linkData?.token) {
128
+ spinner.fail(chalk.hex('#EF5350')('No se pudo obtener el link de conexion'));
93
129
  process.exit(1);
94
130
  }
95
131
 
96
- const shortUrl = linkRes.data.data?.shortUrl || '';
132
+ const shortUrl = `${ONBOARDING_SHORT_DOMAIN}/${linkData.token}`;
133
+ const expiresAt = linkData.expiresAt ? new Date(linkData.expiresAt).toLocaleDateString('es-ES', { day: 'numeric', month: 'long', year: 'numeric' }) : '';
97
134
  spinner.stop();
98
135
 
99
136
  // Mostrar link
@@ -103,6 +140,9 @@ export const whatsappConnectCommand = new Command('connect')
103
140
  console.log(chalk.hex('#25D366')(' │') + chalk.hex('#22d3ee')(` ${shortUrl}`).padEnd(64) + chalk.hex('#25D366')('│'));
104
141
  console.log(chalk.hex('#25D366')(' │') + ''.padEnd(54) + chalk.hex('#25D366')('│'));
105
142
  console.log(chalk.hex('#25D366')(' │') + chalk.gray(' Escanea el codigo QR desde tu WhatsApp').padEnd(64) + chalk.hex('#25D366')('│'));
143
+ if (expiresAt) {
144
+ console.log(chalk.hex('#25D366')(' │') + chalk.gray(` Expira: ${expiresAt}`).padEnd(64) + chalk.hex('#25D366')('│'));
145
+ }
106
146
  console.log(chalk.hex('#25D366')(' └' + '─'.repeat(54) + '┘'));
107
147
  console.log();
108
148