@ascendkit/cli 0.2.6 → 0.3.1
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/api/client.d.ts +1 -0
- package/dist/api/client.js +36 -9
- package/dist/cli.js +869 -474
- package/dist/commands/content.js +4 -4
- package/dist/commands/email.d.ts +62 -6
- package/dist/commands/email.js +26 -17
- package/dist/commands/journeys.d.ts +1 -0
- package/dist/commands/journeys.js +9 -6
- package/dist/commands/platform.d.ts +22 -2
- package/dist/commands/platform.js +211 -103
- package/dist/commands/surveys.js +5 -5
- package/dist/mcp.js +31 -3
- package/dist/tools/auth.js +32 -11
- package/dist/tools/content.js +24 -12
- package/dist/tools/email.js +47 -17
- package/dist/tools/import.js +9 -9
- package/dist/tools/journeys.js +21 -14
- package/dist/tools/platform.js +125 -10
- package/dist/tools/surveys.js +9 -9
- package/dist/utils/correlation.d.ts +11 -0
- package/dist/utils/correlation.js +67 -0
- package/dist/utils/exit.d.ts +23 -0
- package/dist/utils/exit.js +64 -0
- package/dist/utils/journey-format.d.ts +6 -0
- package/dist/utils/journey-format.js +6 -4
- package/dist/utils/redaction.d.ts +16 -0
- package/dist/utils/redaction.js +114 -0
- package/dist/utils/survey-format.js +2 -2
- package/dist/utils/telemetry.d.ts +32 -0
- package/dist/utils/telemetry.js +47 -0
- package/package.json +5 -5
package/dist/api/client.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare class AscendKitClient {
|
|
|
13
13
|
});
|
|
14
14
|
get configured(): boolean;
|
|
15
15
|
get currentPublicKey(): string | null;
|
|
16
|
+
get currentApiUrl(): string;
|
|
16
17
|
get platformConfigured(): boolean;
|
|
17
18
|
configure(publicKey: string, apiUrl?: string): void;
|
|
18
19
|
configurePlatform(token: string, apiUrl?: string): void;
|
package/dist/api/client.js
CHANGED
|
@@ -5,6 +5,7 @@ import { readFileSync } from "fs";
|
|
|
5
5
|
import { fileURLToPath } from "url";
|
|
6
6
|
import { dirname, resolve } from "path";
|
|
7
7
|
import { DEFAULT_API_URL } from "../constants.js";
|
|
8
|
+
import { correlationHeaders } from "../utils/correlation.js";
|
|
8
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
10
|
const __dirname = dirname(__filename);
|
|
10
11
|
function readPackageVersion() {
|
|
@@ -17,6 +18,30 @@ function readPackageVersion() {
|
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
export const CLI_VERSION = readPackageVersion();
|
|
21
|
+
async function extractErrorMessage(response) {
|
|
22
|
+
const text = await response.text();
|
|
23
|
+
if (!text) {
|
|
24
|
+
return `AscendKit API error ${response.status}: ${response.statusText}`;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const parsed = JSON.parse(text);
|
|
28
|
+
if (typeof parsed.error === "string") {
|
|
29
|
+
return parsed.error;
|
|
30
|
+
}
|
|
31
|
+
if (typeof parsed.detail === "string") {
|
|
32
|
+
return parsed.detail;
|
|
33
|
+
}
|
|
34
|
+
if (parsed.detail
|
|
35
|
+
&& typeof parsed.detail === "object"
|
|
36
|
+
&& typeof parsed.detail.message === "string") {
|
|
37
|
+
return parsed.detail.message;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Fall back to the raw response body below.
|
|
42
|
+
}
|
|
43
|
+
return `AscendKit API error ${response.status}: ${text}`;
|
|
44
|
+
}
|
|
20
45
|
export class AscendKitClient {
|
|
21
46
|
baseUrl;
|
|
22
47
|
publicKey;
|
|
@@ -33,6 +58,9 @@ export class AscendKitClient {
|
|
|
33
58
|
get currentPublicKey() {
|
|
34
59
|
return this.publicKey;
|
|
35
60
|
}
|
|
61
|
+
get currentApiUrl() {
|
|
62
|
+
return this.baseUrl;
|
|
63
|
+
}
|
|
36
64
|
get platformConfigured() {
|
|
37
65
|
return this.platformToken !== null;
|
|
38
66
|
}
|
|
@@ -47,7 +75,10 @@ export class AscendKitClient {
|
|
|
47
75
|
this.baseUrl = apiUrl;
|
|
48
76
|
}
|
|
49
77
|
get versionHeader() {
|
|
50
|
-
return {
|
|
78
|
+
return {
|
|
79
|
+
"X-AscendKit-Client-Version": `cli/${CLI_VERSION}`,
|
|
80
|
+
...correlationHeaders(),
|
|
81
|
+
};
|
|
51
82
|
}
|
|
52
83
|
get headers() {
|
|
53
84
|
if (!this.publicKey) {
|
|
@@ -105,8 +136,7 @@ export class AscendKitClient {
|
|
|
105
136
|
const response = await fetch(url, init);
|
|
106
137
|
this.checkUpgradeHeader(response);
|
|
107
138
|
if (!response.ok) {
|
|
108
|
-
|
|
109
|
-
throw new Error(`AscendKit API error ${response.status}: ${text}`);
|
|
139
|
+
throw new Error(await extractErrorMessage(response));
|
|
110
140
|
}
|
|
111
141
|
const json = (await response.json());
|
|
112
142
|
return json.data;
|
|
@@ -123,8 +153,7 @@ export class AscendKitClient {
|
|
|
123
153
|
const response = await fetch(url, init);
|
|
124
154
|
this.checkUpgradeHeader(response);
|
|
125
155
|
if (!response.ok) {
|
|
126
|
-
|
|
127
|
-
throw new Error(`AscendKit API error ${response.status}: ${text}`);
|
|
156
|
+
throw new Error(await extractErrorMessage(response));
|
|
128
157
|
}
|
|
129
158
|
const json = (await response.json());
|
|
130
159
|
return json.data;
|
|
@@ -142,8 +171,7 @@ export class AscendKitClient {
|
|
|
142
171
|
const response = await fetch(url, init);
|
|
143
172
|
this.checkUpgradeHeader(response);
|
|
144
173
|
if (!response.ok) {
|
|
145
|
-
|
|
146
|
-
throw new Error(`AscendKit API error ${response.status}: ${text}`);
|
|
174
|
+
throw new Error(await extractErrorMessage(response));
|
|
147
175
|
}
|
|
148
176
|
const json = (await response.json());
|
|
149
177
|
return json.data;
|
|
@@ -173,8 +201,7 @@ export class AscendKitClient {
|
|
|
173
201
|
const response = await fetch(url, init);
|
|
174
202
|
this.checkUpgradeHeader(response);
|
|
175
203
|
if (!response.ok) {
|
|
176
|
-
|
|
177
|
-
throw new Error(`AscendKit API error ${response.status}: ${text}`);
|
|
204
|
+
throw new Error(await extractErrorMessage(response));
|
|
178
205
|
}
|
|
179
206
|
const json = (await response.json());
|
|
180
207
|
return json.data;
|