@vorlek/cli 0.2.1 → 0.2.2
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/cli.js +1 -1
- package/dist/client.js +3 -0
- package/dist/commands/contact.js +38 -12
- package/dist/deps.js +1 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -23,7 +23,7 @@ import { defaultDeps } from './deps.js';
|
|
|
23
23
|
*/
|
|
24
24
|
const cli = cac('vorlek');
|
|
25
25
|
cli.help();
|
|
26
|
-
cli.version('0.2.
|
|
26
|
+
cli.version('0.2.2');
|
|
27
27
|
cli.option('--api-base <url>', 'Override API base URL (default: from config or https://api.vorlek.com)');
|
|
28
28
|
cli.option('--json', 'Output raw JSON (machine-readable)');
|
|
29
29
|
cli.option('-v, --verbose', 'Verbose logging (includes stack traces on errors)');
|
package/dist/client.js
CHANGED
|
@@ -132,6 +132,9 @@ export function createApiClient(opts) {
|
|
|
132
132
|
getContact(input) {
|
|
133
133
|
return call('v1/tools/get_contact', toolPostInit(input));
|
|
134
134
|
},
|
|
135
|
+
getContactWithMeta(input) {
|
|
136
|
+
return callResult('v1/tools/get_contact', toolPostInit(input));
|
|
137
|
+
},
|
|
135
138
|
getConnectionStatus(input) {
|
|
136
139
|
return call('v1/tools/get_connection_status', toolPostInit(input));
|
|
137
140
|
},
|
package/dist/commands/contact.js
CHANGED
|
@@ -29,9 +29,7 @@ export async function runUpsertContact(deps, ctx, opts) {
|
|
|
29
29
|
email: opts.email,
|
|
30
30
|
first_name: opts.firstName,
|
|
31
31
|
last_name: opts.lastName,
|
|
32
|
-
|
|
33
|
-
// phone (e.g., "+15551234567") as a JS Number; the server requires string.
|
|
34
|
-
phone: opts.phone === undefined ? undefined : String(opts.phone),
|
|
32
|
+
phone: phoneFromOpts(deps, opts),
|
|
35
33
|
properties,
|
|
36
34
|
...(detail ? { detail } : {}),
|
|
37
35
|
...(opts.idempotencyKey ? { idempotencyKey: opts.idempotencyKey } : {}),
|
|
@@ -69,7 +67,7 @@ export async function runUpsertAllContacts(deps, ctx, opts) {
|
|
|
69
67
|
email: opts.email,
|
|
70
68
|
first_name: opts.firstName,
|
|
71
69
|
last_name: opts.lastName,
|
|
72
|
-
phone:
|
|
70
|
+
phone: phoneFromOpts(deps, opts),
|
|
73
71
|
properties,
|
|
74
72
|
...(detail ? { detail } : {}),
|
|
75
73
|
...(opts.idempotencyKey ? { idempotencyKey: opts.idempotencyKey } : {}),
|
|
@@ -91,23 +89,24 @@ export async function runGetContact(deps, ctx, opts) {
|
|
|
91
89
|
throw new ConfigMissingError();
|
|
92
90
|
const apiBase = ctx.apiBaseOverride ?? cfg.api_base;
|
|
93
91
|
const client = deps.createApiClient({ apiBase, apiKey: cfg.api_key });
|
|
94
|
-
if (!client.getContact)
|
|
92
|
+
if (!client.getContact && !client.getContactWithMeta) {
|
|
95
93
|
throw new Error('Configured API client does not support get_contact.');
|
|
94
|
+
}
|
|
96
95
|
const provider = await resolveProvider(client, opts.provider);
|
|
97
96
|
const detail = parseDetail(opts.detail);
|
|
98
|
-
const result = await client
|
|
97
|
+
const result = await getContactWithResult(client, {
|
|
99
98
|
provider,
|
|
100
99
|
email: opts.email,
|
|
101
100
|
...(detail ? { detail } : {}),
|
|
102
101
|
...(opts.idempotencyKey ? { idempotencyKey: opts.idempotencyKey } : {}),
|
|
103
102
|
});
|
|
104
|
-
renderSuccess(deps, ctx, result, () => {
|
|
105
|
-
if (!result.found) {
|
|
106
|
-
return `${pc.yellow('!')} No ${pc.bold(result.provider)} contact found for ${pc.bold(result.email)}.`;
|
|
103
|
+
renderSuccess(deps, ctx, result.data, () => {
|
|
104
|
+
if (!result.data.found) {
|
|
105
|
+
return `${pc.yellow('!')} No ${pc.bold(result.data.provider)} contact found for ${pc.bold(result.data.email)}.`;
|
|
107
106
|
}
|
|
108
|
-
const contactId = contactIdFromResult(result.contact);
|
|
109
|
-
return `${pc.green('✓')} Found ${pc.bold(result.provider)} contact ${pc.bold(contactId ?? result.email)}.`;
|
|
110
|
-
});
|
|
107
|
+
const contactId = contactIdFromResult(result.data.contact);
|
|
108
|
+
return `${pc.green('✓')} Found ${pc.bold(result.data.provider)} contact ${pc.bold(contactId ?? result.data.email)}.`;
|
|
109
|
+
}, result.meta);
|
|
111
110
|
}
|
|
112
111
|
catch (err) {
|
|
113
112
|
deps.exit(renderError(deps, ctx, err));
|
|
@@ -136,6 +135,26 @@ export function registerContactCommands(cli, deps, ctx) {
|
|
|
136
135
|
deps.exit(1);
|
|
137
136
|
});
|
|
138
137
|
}
|
|
138
|
+
function phoneFromOpts(deps, opts) {
|
|
139
|
+
if (opts.phone === undefined)
|
|
140
|
+
return undefined;
|
|
141
|
+
const raw = rawFlagValue(deps.argv ?? process.argv, '--phone');
|
|
142
|
+
return raw ?? String(opts.phone);
|
|
143
|
+
}
|
|
144
|
+
function rawFlagValue(argv, flag) {
|
|
145
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
146
|
+
const token = argv[i];
|
|
147
|
+
if (token === '--')
|
|
148
|
+
return undefined;
|
|
149
|
+
if (token === flag) {
|
|
150
|
+
const next = argv[i + 1];
|
|
151
|
+
return next && next !== '--' && !next.startsWith('--') ? next : undefined;
|
|
152
|
+
}
|
|
153
|
+
if (token?.startsWith(`${flag}=`))
|
|
154
|
+
return token.slice(flag.length + 1);
|
|
155
|
+
}
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
139
158
|
function contactIdFromResult(contact) {
|
|
140
159
|
if (typeof contact !== 'object' || contact === null)
|
|
141
160
|
return null;
|
|
@@ -162,6 +181,13 @@ async function upsertContactWithResult(client, input) {
|
|
|
162
181
|
return client.upsertContactWithMeta(input);
|
|
163
182
|
return { data: await client.upsertContact(input) };
|
|
164
183
|
}
|
|
184
|
+
async function getContactWithResult(client, input) {
|
|
185
|
+
if (client.getContactWithMeta)
|
|
186
|
+
return client.getContactWithMeta(input);
|
|
187
|
+
if (!client.getContact)
|
|
188
|
+
throw new Error('Configured API client does not support get_contact.');
|
|
189
|
+
return { data: await client.getContact(input) };
|
|
190
|
+
}
|
|
165
191
|
async function resolveTargetProviders(client, opts) {
|
|
166
192
|
const listed = parseProviderList(opts.providers);
|
|
167
193
|
if (listed.length > 0)
|
package/dist/deps.js
CHANGED