@intercom/cli 0.6.0 → 0.7.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.
|
@@ -26,8 +26,8 @@ var NotFoundError = class extends CLIError {
|
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
28
|
var PermissionError = class extends CLIError {
|
|
29
|
-
constructor(message) {
|
|
30
|
-
super(message, 5);
|
|
29
|
+
constructor(message, error) {
|
|
30
|
+
super(message, 5, error);
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
var TimeoutError = class extends CLIError {
|
|
@@ -106,4 +106,4 @@ export {
|
|
|
106
106
|
formatJson,
|
|
107
107
|
applyJq
|
|
108
108
|
};
|
|
109
|
-
//# sourceMappingURL=chunk-
|
|
109
|
+
//# sourceMappingURL=chunk-3V2ONMAU.js.map
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
applyJq,
|
|
10
10
|
detectAuthType,
|
|
11
11
|
formatJson
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-3V2ONMAU.js";
|
|
13
13
|
|
|
14
14
|
// src/index.ts
|
|
15
15
|
import { Command } from "commander";
|
|
@@ -65,7 +65,7 @@ var _dryRun = false;
|
|
|
65
65
|
function setDryRun(enabled) {
|
|
66
66
|
_dryRun = enabled;
|
|
67
67
|
}
|
|
68
|
-
var IntercomClient = class {
|
|
68
|
+
var IntercomClient = class _IntercomClient {
|
|
69
69
|
token;
|
|
70
70
|
authType;
|
|
71
71
|
appId;
|
|
@@ -88,7 +88,49 @@ var IntercomClient = class {
|
|
|
88
88
|
}
|
|
89
89
|
return `Bearer ${this.token}`;
|
|
90
90
|
}
|
|
91
|
-
|
|
91
|
+
// Dedicated error code the API returns when the `fin-sdk` feature flag gates
|
|
92
|
+
// a fin subcommand. It's specific to that self-fixable gate (not the generic
|
|
93
|
+
// plan-restriction code), so seeing it is a safe signal to auto-enable.
|
|
94
|
+
static FIN_SDK_GATE_CODE = "fin_sdk_not_enabled";
|
|
95
|
+
// Thin wrapper over requestOnce that transparently recovers from the fin-sdk
|
|
96
|
+
// gate: if a call is blocked because the flag isn't enabled, opt the
|
|
97
|
+
// workspace in via POST /fin-sdk/enable and retry the original request once.
|
|
98
|
+
// If enabling fails, the original gate error is surfaced unchanged.
|
|
99
|
+
async request(method, path, body, responseType = "json", extraHeaders, isFinSdkRetry = false) {
|
|
100
|
+
try {
|
|
101
|
+
return await this.requestOnce(
|
|
102
|
+
method,
|
|
103
|
+
path,
|
|
104
|
+
body,
|
|
105
|
+
responseType,
|
|
106
|
+
extraHeaders
|
|
107
|
+
);
|
|
108
|
+
} catch (err) {
|
|
109
|
+
if (!isFinSdkRetry && !_dryRun && err instanceof PermissionError && err.error?.code === _IntercomClient.FIN_SDK_GATE_CODE) {
|
|
110
|
+
try {
|
|
111
|
+
await this.enableFinSdk();
|
|
112
|
+
} catch {
|
|
113
|
+
throw err;
|
|
114
|
+
}
|
|
115
|
+
return this.request(
|
|
116
|
+
method,
|
|
117
|
+
path,
|
|
118
|
+
body,
|
|
119
|
+
responseType,
|
|
120
|
+
extraHeaders,
|
|
121
|
+
true
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
throw err;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Opt the current workspace into the fin-sdk feature flag. The notice goes to
|
|
128
|
+
// stderr so it never contaminates --json / piped stdout output.
|
|
129
|
+
async enableFinSdk() {
|
|
130
|
+
console.error("Fin SDK not enabled for this workspace \u2014 enabling it now...");
|
|
131
|
+
await this.requestOnce("POST", "/fin-sdk/enable", {}, "json");
|
|
132
|
+
}
|
|
133
|
+
async requestOnce(method, path, body, responseType = "json", extraHeaders) {
|
|
92
134
|
const url = `${this.baseUrl}${path}`;
|
|
93
135
|
if (_dryRun) {
|
|
94
136
|
console.error(`> ${method} ${url}`);
|
|
@@ -149,13 +191,18 @@ var IntercomClient = class {
|
|
|
149
191
|
}
|
|
150
192
|
const errorBody = await response.json().catch(() => ({}));
|
|
151
193
|
const errorMsg = errorBody?.errors?.[0]?.message ?? `HTTP ${response.status}`;
|
|
194
|
+
const errorCode = errorBody?.errors?.[0]?.code ?? "";
|
|
152
195
|
if (response.status === 401) {
|
|
153
196
|
throw new AuthError(
|
|
154
197
|
`Authentication expired or invalid: ${errorMsg}. Run "intercom auth login" to re-authenticate.`
|
|
155
198
|
);
|
|
156
199
|
}
|
|
157
200
|
if (response.status === 403) {
|
|
158
|
-
throw new PermissionError(`Permission denied: ${errorMsg}
|
|
201
|
+
throw new PermissionError(`Permission denied: ${errorMsg}`, {
|
|
202
|
+
code: errorCode,
|
|
203
|
+
message: errorMsg,
|
|
204
|
+
status: 403
|
|
205
|
+
});
|
|
159
206
|
}
|
|
160
207
|
if (response.status === 404) {
|
|
161
208
|
throw new NotFoundError(errorMsg);
|
|
@@ -905,13 +952,18 @@ async function deviseSignIn(baseUrl, email, password, timeoutMs = API_TIMEOUT_MS
|
|
|
905
952
|
}
|
|
906
953
|
const location = signInResponse.headers.get("location") ?? "";
|
|
907
954
|
if (location.includes("/admins/sign_in")) {
|
|
908
|
-
throw new
|
|
955
|
+
throw new AuthError("Invalid credentials");
|
|
909
956
|
}
|
|
910
957
|
if (location.includes("two_factor")) {
|
|
911
|
-
throw new
|
|
958
|
+
throw new AuthError(
|
|
912
959
|
"Two-factor authentication is required. Please use an API key instead."
|
|
913
960
|
);
|
|
914
961
|
}
|
|
962
|
+
if (location.includes("/login_verification")) {
|
|
963
|
+
throw new AuthError(
|
|
964
|
+
"Login email verification is required.\n Please sign in to the Intercom web app to complete verification, then retry this command."
|
|
965
|
+
);
|
|
966
|
+
}
|
|
915
967
|
cookies = mergeCookies(cookies, extractCookies(signInResponse));
|
|
916
968
|
return cookies;
|
|
917
969
|
}
|
|
@@ -3973,7 +4025,7 @@ function registerPricingCommand(program) {
|
|
|
3973
4025
|
}
|
|
3974
4026
|
const markdown = await response.text();
|
|
3975
4027
|
if (opts.json) {
|
|
3976
|
-
const { formatJson: formatJson2 } = await import("./json-
|
|
4028
|
+
const { formatJson: formatJson2 } = await import("./json-OEUXXCTX.js");
|
|
3977
4029
|
console.log(formatJson2({ url: PRICING_URL, content: markdown }));
|
|
3978
4030
|
} else {
|
|
3979
4031
|
console.log(markdown);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intercom/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "CLI tool for managing Intercom workspaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
"msw": "^2.12.13",
|
|
39
39
|
"tsup": "^8.5.1",
|
|
40
40
|
"typescript": "^5.9.3",
|
|
41
|
-
"vitest": "^
|
|
41
|
+
"vitest": "^4.1.0"
|
|
42
42
|
}
|
|
43
43
|
}
|