@ascendkit/cli 0.2.0 → 0.3.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/api/client.d.ts +2 -0
- package/dist/api/client.js +34 -8
- package/dist/cli.js +1047 -314
- package/dist/commands/auth.d.ts +4 -0
- package/dist/commands/auth.js +12 -0
- package/dist/commands/campaigns.d.ts +22 -0
- package/dist/commands/campaigns.js +25 -0
- 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/import.d.ts +75 -0
- package/dist/commands/import.js +97 -0
- package/dist/commands/journeys.d.ts +3 -0
- package/dist/commands/journeys.js +9 -6
- package/dist/commands/platform.d.ts +28 -0
- package/dist/commands/platform.js +219 -101
- package/dist/commands/surveys.js +5 -5
- package/dist/mcp.js +35 -3
- package/dist/tools/auth.js +66 -8
- package/dist/tools/campaigns.d.ts +3 -0
- package/dist/tools/campaigns.js +78 -0
- package/dist/tools/content.js +24 -12
- package/dist/tools/email.js +47 -17
- package/dist/tools/import.d.ts +3 -0
- package/dist/tools/import.js +116 -0
- package/dist/tools/journeys.js +25 -14
- package/dist/tools/platform.js +151 -6
- package/dist/tools/surveys.js +9 -9
- package/dist/utils/journey-format.d.ts +6 -0
- package/dist/utils/journey-format.js +6 -4
- package/dist/utils/survey-format.js +2 -2
- 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;
|
|
@@ -32,6 +33,7 @@ export declare class AscendKitClient {
|
|
|
32
33
|
delete<T = unknown>(path: string): Promise<T>;
|
|
33
34
|
/** Write operation requiring both public key and platform auth. */
|
|
34
35
|
managedRequest<T = unknown>(method: string, path: string, body?: unknown): Promise<T>;
|
|
36
|
+
managedGet<T = unknown>(path: string): Promise<T>;
|
|
35
37
|
managedPut<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
36
38
|
managedPost<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
37
39
|
managedDelete<T = unknown>(path: string): Promise<T>;
|
package/dist/api/client.js
CHANGED
|
@@ -17,6 +17,30 @@ function readPackageVersion() {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
export const CLI_VERSION = readPackageVersion();
|
|
20
|
+
async function extractErrorMessage(response) {
|
|
21
|
+
const text = await response.text();
|
|
22
|
+
if (!text) {
|
|
23
|
+
return `AscendKit API error ${response.status}: ${response.statusText}`;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const parsed = JSON.parse(text);
|
|
27
|
+
if (typeof parsed.error === "string") {
|
|
28
|
+
return parsed.error;
|
|
29
|
+
}
|
|
30
|
+
if (typeof parsed.detail === "string") {
|
|
31
|
+
return parsed.detail;
|
|
32
|
+
}
|
|
33
|
+
if (parsed.detail
|
|
34
|
+
&& typeof parsed.detail === "object"
|
|
35
|
+
&& typeof parsed.detail.message === "string") {
|
|
36
|
+
return parsed.detail.message;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Fall back to the raw response body below.
|
|
41
|
+
}
|
|
42
|
+
return `AscendKit API error ${response.status}: ${text}`;
|
|
43
|
+
}
|
|
20
44
|
export class AscendKitClient {
|
|
21
45
|
baseUrl;
|
|
22
46
|
publicKey;
|
|
@@ -33,6 +57,9 @@ export class AscendKitClient {
|
|
|
33
57
|
get currentPublicKey() {
|
|
34
58
|
return this.publicKey;
|
|
35
59
|
}
|
|
60
|
+
get currentApiUrl() {
|
|
61
|
+
return this.baseUrl;
|
|
62
|
+
}
|
|
36
63
|
get platformConfigured() {
|
|
37
64
|
return this.platformToken !== null;
|
|
38
65
|
}
|
|
@@ -105,8 +132,7 @@ export class AscendKitClient {
|
|
|
105
132
|
const response = await fetch(url, init);
|
|
106
133
|
this.checkUpgradeHeader(response);
|
|
107
134
|
if (!response.ok) {
|
|
108
|
-
|
|
109
|
-
throw new Error(`AscendKit API error ${response.status}: ${text}`);
|
|
135
|
+
throw new Error(await extractErrorMessage(response));
|
|
110
136
|
}
|
|
111
137
|
const json = (await response.json());
|
|
112
138
|
return json.data;
|
|
@@ -123,8 +149,7 @@ export class AscendKitClient {
|
|
|
123
149
|
const response = await fetch(url, init);
|
|
124
150
|
this.checkUpgradeHeader(response);
|
|
125
151
|
if (!response.ok) {
|
|
126
|
-
|
|
127
|
-
throw new Error(`AscendKit API error ${response.status}: ${text}`);
|
|
152
|
+
throw new Error(await extractErrorMessage(response));
|
|
128
153
|
}
|
|
129
154
|
const json = (await response.json());
|
|
130
155
|
return json.data;
|
|
@@ -142,8 +167,7 @@ export class AscendKitClient {
|
|
|
142
167
|
const response = await fetch(url, init);
|
|
143
168
|
this.checkUpgradeHeader(response);
|
|
144
169
|
if (!response.ok) {
|
|
145
|
-
|
|
146
|
-
throw new Error(`AscendKit API error ${response.status}: ${text}`);
|
|
170
|
+
throw new Error(await extractErrorMessage(response));
|
|
147
171
|
}
|
|
148
172
|
const json = (await response.json());
|
|
149
173
|
return json.data;
|
|
@@ -173,12 +197,14 @@ export class AscendKitClient {
|
|
|
173
197
|
const response = await fetch(url, init);
|
|
174
198
|
this.checkUpgradeHeader(response);
|
|
175
199
|
if (!response.ok) {
|
|
176
|
-
|
|
177
|
-
throw new Error(`AscendKit API error ${response.status}: ${text}`);
|
|
200
|
+
throw new Error(await extractErrorMessage(response));
|
|
178
201
|
}
|
|
179
202
|
const json = (await response.json());
|
|
180
203
|
return json.data;
|
|
181
204
|
}
|
|
205
|
+
managedGet(path) {
|
|
206
|
+
return this.managedRequest("GET", path);
|
|
207
|
+
}
|
|
182
208
|
managedPut(path, body) {
|
|
183
209
|
return this.managedRequest("PUT", path, body);
|
|
184
210
|
}
|