commet 0.3.0 → 0.4.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/LICENSE +202 -21
- package/README.md +234 -20
- package/bin/commet +2 -0
- package/dist/index.js +725 -395
- package/package.json +23 -30
- package/dist/index.d.mts +0 -366
- package/dist/index.d.ts +0 -366
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -413
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
2
4
|
var __defProp = Object.defineProperty;
|
|
3
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
9
|
var __copyProps = (to, from, except, desc) => {
|
|
11
10
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
11
|
for (let key of __getOwnPropNames(from))
|
|
@@ -15,431 +14,762 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
14
|
}
|
|
16
15
|
return to;
|
|
17
16
|
};
|
|
18
|
-
var
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
19
25
|
|
|
20
26
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
Commet: () => Commet,
|
|
24
|
-
CommetAPIError: () => CommetAPIError,
|
|
25
|
-
CommetError: () => CommetError,
|
|
26
|
-
CommetValidationError: () => CommetValidationError,
|
|
27
|
-
default: () => index_default,
|
|
28
|
-
isProduction: () => isProduction,
|
|
29
|
-
isSandbox: () => isSandbox
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var import_chalk10 = __toESM(require("chalk"));
|
|
28
|
+
var import_commander10 = require("commander");
|
|
32
29
|
|
|
33
|
-
// src/
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
this.httpClient = httpClient;
|
|
37
|
-
}
|
|
38
|
-
async create(params, options) {
|
|
39
|
-
return this.httpClient.post("/customers", params, options);
|
|
40
|
-
}
|
|
41
|
-
async retrieve(customerId, options) {
|
|
42
|
-
const params = options?.expand ? { expand: options.expand.join(",") } : void 0;
|
|
43
|
-
return this.httpClient.get(`/customers/${customerId}`, params);
|
|
44
|
-
}
|
|
45
|
-
async update(customerId, params, options) {
|
|
46
|
-
return this.httpClient.put(`/customers/${customerId}`, params, options);
|
|
47
|
-
}
|
|
48
|
-
async list(params) {
|
|
49
|
-
return this.httpClient.get("/customers", params);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Deactivate a customer (soft delete)
|
|
53
|
-
*/
|
|
54
|
-
async deactivate(customerId, options) {
|
|
55
|
-
return this.httpClient.put(
|
|
56
|
-
`/customers/${customerId}`,
|
|
57
|
-
{ isActive: false },
|
|
58
|
-
options
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
30
|
+
// src/commands/info.ts
|
|
31
|
+
var import_chalk = __toESM(require("chalk"));
|
|
32
|
+
var import_commander = require("commander");
|
|
62
33
|
|
|
63
|
-
// src/
|
|
64
|
-
var
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
34
|
+
// src/utils/config.ts
|
|
35
|
+
var fs = __toESM(require("fs"));
|
|
36
|
+
var os = __toESM(require("os"));
|
|
37
|
+
var path = __toESM(require("path"));
|
|
38
|
+
function getAuthPath() {
|
|
39
|
+
return path.join(os.homedir(), ".commet", "auth.json");
|
|
40
|
+
}
|
|
41
|
+
function getProjectConfigPath() {
|
|
42
|
+
return path.join(process.cwd(), ".commet");
|
|
43
|
+
}
|
|
44
|
+
function authExists() {
|
|
45
|
+
return fs.existsSync(getAuthPath());
|
|
46
|
+
}
|
|
47
|
+
function loadAuth() {
|
|
48
|
+
try {
|
|
49
|
+
const authPath = getAuthPath();
|
|
50
|
+
if (!fs.existsSync(authPath)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const data = fs.readFileSync(authPath, "utf8");
|
|
54
|
+
return JSON.parse(data);
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
74
57
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
58
|
+
}
|
|
59
|
+
function saveAuth(data) {
|
|
60
|
+
const authPath = getAuthPath();
|
|
61
|
+
fs.mkdirSync(path.dirname(authPath), { recursive: true });
|
|
62
|
+
fs.writeFileSync(authPath, JSON.stringify(data, null, 2), "utf8");
|
|
63
|
+
}
|
|
64
|
+
function clearAuth() {
|
|
65
|
+
const authPath = getAuthPath();
|
|
66
|
+
if (fs.existsSync(authPath)) {
|
|
67
|
+
fs.unlinkSync(authPath);
|
|
81
68
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
69
|
+
}
|
|
70
|
+
function projectConfigExists() {
|
|
71
|
+
return fs.existsSync(getProjectConfigPath());
|
|
72
|
+
}
|
|
73
|
+
function loadProjectConfig() {
|
|
74
|
+
try {
|
|
75
|
+
const configPath = getProjectConfigPath();
|
|
76
|
+
if (!fs.existsSync(configPath)) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const data = fs.readFileSync(configPath, "utf8");
|
|
80
|
+
return JSON.parse(data);
|
|
81
|
+
} catch {
|
|
82
|
+
return null;
|
|
88
83
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
84
|
+
}
|
|
85
|
+
function saveProjectConfig(data) {
|
|
86
|
+
const configPath = getProjectConfigPath();
|
|
87
|
+
fs.writeFileSync(configPath, JSON.stringify(data, null, 2), "utf8");
|
|
88
|
+
}
|
|
89
|
+
function clearProjectConfig() {
|
|
90
|
+
const configPath = getProjectConfigPath();
|
|
91
|
+
if (fs.existsSync(configPath)) {
|
|
92
|
+
fs.unlinkSync(configPath);
|
|
95
93
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/commands/info.ts
|
|
97
|
+
var infoCommand = new import_commander.Command("info").description("Display information about the current project").action(async () => {
|
|
98
|
+
console.log(import_chalk.default.bold("\n\u{1F4E6} Project Information\n"));
|
|
99
|
+
if (!authExists()) {
|
|
100
|
+
console.log(import_chalk.default.yellow("Authentication: Not logged in"));
|
|
101
|
+
console.log(import_chalk.default.dim("Run `commet login` to authenticate\n"));
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
console.log(import_chalk.default.green("Authentication: Logged in \u2713"));
|
|
105
|
+
if (!projectConfigExists()) {
|
|
106
|
+
console.log(import_chalk.default.yellow("\nProject: Not linked"));
|
|
107
|
+
console.log(
|
|
108
|
+
import_chalk.default.dim("Run `commet link` to connect to an organization\n")
|
|
99
109
|
);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const projectConfig = loadProjectConfig();
|
|
113
|
+
if (!projectConfig) {
|
|
114
|
+
console.log(import_chalk.default.red("\nProject: Invalid configuration"));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
console.log(import_chalk.default.green("\nProject: Linked \u2713"));
|
|
118
|
+
console.log(import_chalk.default.dim(" Organization:"), projectConfig.orgName);
|
|
119
|
+
console.log(import_chalk.default.dim(" Organization ID:"), projectConfig.orgId);
|
|
120
|
+
console.log(import_chalk.default.dim(" Environment:"), projectConfig.environment);
|
|
121
|
+
console.log(
|
|
122
|
+
import_chalk.default.dim("\nRun `commet pull` to generate type definitions\n")
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// src/commands/link.ts
|
|
127
|
+
var import_chalk2 = __toESM(require("chalk"));
|
|
128
|
+
var import_commander2 = require("commander");
|
|
129
|
+
var import_inquirer = __toESM(require("inquirer"));
|
|
130
|
+
var import_ora = __toESM(require("ora"));
|
|
131
|
+
|
|
132
|
+
// src/utils/api.ts
|
|
133
|
+
function getBaseURL(environment) {
|
|
134
|
+
if (environment === "production") {
|
|
135
|
+
return "https://billing.commet.co";
|
|
100
136
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
137
|
+
return "https://sandbox.commet.co";
|
|
138
|
+
}
|
|
139
|
+
async function apiRequest(endpoint, options = {}) {
|
|
140
|
+
const auth = loadAuth();
|
|
141
|
+
if (!auth) {
|
|
142
|
+
return { error: "Not authenticated. Run `commet login` first." };
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
const response = await fetch(endpoint, {
|
|
146
|
+
...options,
|
|
147
|
+
headers: {
|
|
148
|
+
...options.headers,
|
|
149
|
+
Authorization: `Bearer ${auth.token}`,
|
|
150
|
+
"Content-Type": "application/json"
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (!response.ok) {
|
|
154
|
+
const errorData = await response.json().catch(() => ({}));
|
|
155
|
+
return {
|
|
156
|
+
error: errorData.message || errorData.error || `Request failed with status ${response.status}`
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const data = await response.json();
|
|
160
|
+
return { data };
|
|
161
|
+
} catch (error) {
|
|
162
|
+
return {
|
|
163
|
+
error: error instanceof Error ? error.message : "Unknown error occurred"
|
|
109
164
|
};
|
|
110
|
-
return this.httpClient.get(
|
|
111
|
-
`/customers/${customerId}/seats/history`,
|
|
112
|
-
queryParams
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
async listEvents(params) {
|
|
116
|
-
return this.httpClient.get("/seats/events", params);
|
|
117
165
|
}
|
|
118
|
-
}
|
|
166
|
+
}
|
|
119
167
|
|
|
120
|
-
// src/
|
|
121
|
-
var
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
168
|
+
// src/commands/link.ts
|
|
169
|
+
var linkCommand = new import_commander2.Command("link").description("Link this project to a Commet organization").action(async () => {
|
|
170
|
+
if (!authExists()) {
|
|
171
|
+
console.log(import_chalk2.default.red("\u2717 Not authenticated"));
|
|
172
|
+
console.log(import_chalk2.default.dim("Run `commet login` first"));
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (projectConfigExists()) {
|
|
176
|
+
const config = loadProjectConfig();
|
|
177
|
+
console.log(import_chalk2.default.yellow("\u26A0 This project is already linked"));
|
|
178
|
+
console.log(
|
|
179
|
+
import_chalk2.default.dim(`Organization: ${config?.orgName} (${config?.environment})`)
|
|
180
|
+
);
|
|
181
|
+
console.log(
|
|
182
|
+
import_chalk2.default.dim(
|
|
183
|
+
"\nRun `commet unlink` first if you want to change the organization"
|
|
184
|
+
)
|
|
185
|
+
);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const spinner = (0, import_ora.default)("Fetching organizations...").start();
|
|
189
|
+
const auth = loadAuth();
|
|
190
|
+
if (!auth) {
|
|
191
|
+
spinner.fail("Authentication error");
|
|
192
|
+
console.log(import_chalk2.default.red("\u2717 Could not load authentication"));
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const baseURL = getBaseURL(auth.environment);
|
|
196
|
+
const result = await apiRequest(
|
|
197
|
+
`${baseURL}/api/cli/organizations`
|
|
198
|
+
);
|
|
199
|
+
if (result.error || !result.data) {
|
|
200
|
+
spinner.fail("Failed to fetch organizations");
|
|
201
|
+
console.error(import_chalk2.default.red("Error:"), result.error);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const { organizations } = result.data;
|
|
205
|
+
if (organizations.length === 0) {
|
|
206
|
+
spinner.stop();
|
|
207
|
+
console.log(import_chalk2.default.yellow("\u26A0 No organizations found"));
|
|
208
|
+
console.log(
|
|
209
|
+
import_chalk2.default.dim("Create an organization at https://billing.commet.co first")
|
|
210
|
+
);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
spinner.stop();
|
|
214
|
+
const answers = await import_inquirer.default.prompt([
|
|
215
|
+
{
|
|
216
|
+
type: "list",
|
|
217
|
+
name: "orgId",
|
|
218
|
+
message: "Select organization:",
|
|
219
|
+
choices: organizations.map((org) => ({
|
|
220
|
+
name: `${org.name} (${org.slug})`,
|
|
221
|
+
value: org.id
|
|
222
|
+
}))
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
type: "list",
|
|
226
|
+
name: "environment",
|
|
227
|
+
message: "Select environment:",
|
|
228
|
+
choices: [
|
|
229
|
+
{ name: "Sandbox (Development)", value: "sandbox" },
|
|
230
|
+
{ name: "Production", value: "production" }
|
|
231
|
+
],
|
|
232
|
+
default: "sandbox"
|
|
233
|
+
}
|
|
234
|
+
]);
|
|
235
|
+
const selectedOrg = organizations.find((org) => org.id === answers.orgId);
|
|
236
|
+
if (!selectedOrg) {
|
|
237
|
+
console.log(import_chalk2.default.red("\u2717 Organization not found"));
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
saveProjectConfig({
|
|
241
|
+
orgId: selectedOrg.id,
|
|
242
|
+
orgName: selectedOrg.name,
|
|
243
|
+
environment: answers.environment
|
|
244
|
+
});
|
|
245
|
+
console.log(import_chalk2.default.green("\n\u2713 Project linked successfully!"));
|
|
246
|
+
console.log(import_chalk2.default.dim("\nProject configuration:"));
|
|
247
|
+
console.log(import_chalk2.default.dim(` Organization: ${selectedOrg.name}`));
|
|
248
|
+
console.log(import_chalk2.default.dim(` Environment: ${answers.environment}`));
|
|
249
|
+
console.log(
|
|
250
|
+
import_chalk2.default.dim(
|
|
251
|
+
"\nNext step:\n Run `commet pull` to generate TypeScript types"
|
|
252
|
+
)
|
|
253
|
+
);
|
|
254
|
+
});
|
|
162
255
|
|
|
163
|
-
// src/
|
|
164
|
-
var
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
256
|
+
// src/commands/list.ts
|
|
257
|
+
var import_chalk3 = __toESM(require("chalk"));
|
|
258
|
+
var import_commander3 = require("commander");
|
|
259
|
+
var import_ora2 = __toESM(require("ora"));
|
|
260
|
+
var listCommand = new import_commander3.Command("list").description("List event types or seat types").argument("<type>", "Type to list (events or seats)").action(async (type) => {
|
|
261
|
+
if (type !== "events" && type !== "seats") {
|
|
262
|
+
console.log(import_chalk3.default.red('\u2717 Invalid type. Use "events" or "seats"'));
|
|
263
|
+
console.log(import_chalk3.default.dim("\nExamples:"));
|
|
264
|
+
console.log(import_chalk3.default.dim(" commet list events"));
|
|
265
|
+
console.log(import_chalk3.default.dim(" commet list seats"));
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (!authExists()) {
|
|
269
|
+
console.log(import_chalk3.default.red("\u2717 Not authenticated"));
|
|
270
|
+
console.log(import_chalk3.default.dim("Run `commet login` first"));
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (!projectConfigExists()) {
|
|
274
|
+
console.log(import_chalk3.default.red("\u2717 Project not linked"));
|
|
275
|
+
console.log(
|
|
276
|
+
import_chalk3.default.dim("Run `commet link` first to connect to an organization")
|
|
277
|
+
);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const projectConfig = loadProjectConfig();
|
|
281
|
+
if (!projectConfig) {
|
|
282
|
+
console.log(import_chalk3.default.red("\u2717 Invalid project configuration"));
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const spinner = (0, import_ora2.default)(`Fetching ${type}...`).start();
|
|
286
|
+
const baseURL = getBaseURL(projectConfig.environment);
|
|
287
|
+
const result = await apiRequest(
|
|
288
|
+
`${baseURL}/api/cli/types?orgId=${projectConfig.orgId}`
|
|
289
|
+
);
|
|
290
|
+
if (result.error || !result.data) {
|
|
291
|
+
spinner.fail(`Failed to fetch ${type}`);
|
|
292
|
+
console.error(import_chalk3.default.red("Error:"), result.error);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
spinner.stop();
|
|
296
|
+
if (type === "events") {
|
|
297
|
+
const { eventTypes } = result.data;
|
|
298
|
+
if (eventTypes.length === 0) {
|
|
299
|
+
console.log(import_chalk3.default.yellow("\u26A0 No event types found"));
|
|
300
|
+
console.log(
|
|
301
|
+
import_chalk3.default.dim("Create event types in your Commet dashboard first")
|
|
302
|
+
);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
console.log(import_chalk3.default.bold(`
|
|
306
|
+
\u{1F4CA} Event Types (${eventTypes.length})
|
|
307
|
+
`));
|
|
308
|
+
for (const eventType of eventTypes) {
|
|
309
|
+
console.log(import_chalk3.default.green(`\u2022 ${eventType.code}`));
|
|
310
|
+
console.log(import_chalk3.default.dim(` ${eventType.name}`));
|
|
311
|
+
if (eventType.description) {
|
|
312
|
+
console.log(import_chalk3.default.dim(` ${eventType.description}`));
|
|
313
|
+
}
|
|
314
|
+
console.log("");
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
const { seatTypes } = result.data;
|
|
318
|
+
if (seatTypes.length === 0) {
|
|
319
|
+
console.log(import_chalk3.default.yellow("\u26A0 No seat types found"));
|
|
320
|
+
console.log(
|
|
321
|
+
import_chalk3.default.dim("Create seat types in your Commet dashboard first")
|
|
322
|
+
);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
console.log(import_chalk3.default.bold(`
|
|
326
|
+
\u{1F4BA} Seat Types (${seatTypes.length})
|
|
327
|
+
`));
|
|
328
|
+
for (const seatType of seatTypes) {
|
|
329
|
+
console.log(
|
|
330
|
+
import_chalk3.default.green(`\u2022 ${seatType.code}${seatType.isFree ? " (Free)" : ""}`)
|
|
331
|
+
);
|
|
332
|
+
console.log(import_chalk3.default.dim(` ${seatType.name}`));
|
|
333
|
+
if (seatType.description) {
|
|
334
|
+
console.log(import_chalk3.default.dim(` ${seatType.description}`));
|
|
335
|
+
}
|
|
336
|
+
console.log("");
|
|
337
|
+
}
|
|
187
338
|
}
|
|
188
|
-
};
|
|
339
|
+
});
|
|
189
340
|
|
|
190
|
-
// src/
|
|
191
|
-
var
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
341
|
+
// src/commands/login.ts
|
|
342
|
+
var import_chalk4 = __toESM(require("chalk"));
|
|
343
|
+
var import_commander4 = require("commander");
|
|
344
|
+
var import_inquirer2 = __toESM(require("inquirer"));
|
|
345
|
+
var import_open = __toESM(require("open"));
|
|
346
|
+
var import_ora3 = __toESM(require("ora"));
|
|
347
|
+
var loginCommand = new import_commander4.Command("login").description("Authenticate with Commet").action(async () => {
|
|
348
|
+
if (authExists()) {
|
|
349
|
+
const auth = loadAuth();
|
|
350
|
+
console.log(import_chalk4.default.yellow("\u26A0 You are already logged in."));
|
|
351
|
+
console.log(
|
|
352
|
+
import_chalk4.default.dim(
|
|
353
|
+
"Run `commet logout` first if you want to login with a different account."
|
|
354
|
+
)
|
|
355
|
+
);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const { environment } = await import_inquirer2.default.prompt([
|
|
359
|
+
{
|
|
360
|
+
type: "list",
|
|
361
|
+
name: "environment",
|
|
362
|
+
message: "Select environment to login:",
|
|
363
|
+
choices: [
|
|
364
|
+
{
|
|
365
|
+
name: "Sandbox (Development) - sandbox.commet.co",
|
|
366
|
+
value: "sandbox"
|
|
367
|
+
},
|
|
368
|
+
{ name: "Production - billing.commet.co", value: "production" }
|
|
369
|
+
],
|
|
370
|
+
default: "sandbox"
|
|
371
|
+
}
|
|
372
|
+
]);
|
|
373
|
+
const spinner = (0, import_ora3.default)("Initiating login flow...").start();
|
|
374
|
+
const baseURL = getBaseURL(environment);
|
|
375
|
+
try {
|
|
376
|
+
const deviceResponse = await fetch(`${baseURL}/api/auth/device/code`, {
|
|
377
|
+
method: "POST",
|
|
378
|
+
headers: { "Content-Type": "application/json" },
|
|
379
|
+
body: JSON.stringify({
|
|
380
|
+
client_id: "commet-cli",
|
|
381
|
+
scope: "openid profile email"
|
|
382
|
+
})
|
|
383
|
+
});
|
|
384
|
+
if (!deviceResponse.ok) {
|
|
385
|
+
spinner.fail("Failed to initiate login");
|
|
386
|
+
console.error(import_chalk4.default.red("Error:"), await deviceResponse.text());
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
const deviceData = await deviceResponse.json();
|
|
390
|
+
const {
|
|
391
|
+
device_code,
|
|
392
|
+
user_code,
|
|
393
|
+
verification_uri_complete,
|
|
394
|
+
interval = 5
|
|
395
|
+
} = deviceData;
|
|
396
|
+
spinner.stop();
|
|
397
|
+
console.log(import_chalk4.default.bold("\n\u{1F510} Commet CLI Login\n"));
|
|
398
|
+
console.log("Visit the following URL in your browser:");
|
|
399
|
+
console.log(import_chalk4.default.cyan.underline(verification_uri_complete));
|
|
400
|
+
console.log("\nOr enter this code manually:");
|
|
401
|
+
console.log(import_chalk4.default.bold.green(` ${user_code}`));
|
|
402
|
+
console.log(import_chalk4.default.dim("\nOpening browser...\n"));
|
|
231
403
|
try {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
signal: AbortSignal.timeout(
|
|
246
|
-
options?.timeout ?? this.config.timeout ?? 3e4
|
|
247
|
-
)
|
|
248
|
-
};
|
|
249
|
-
if (data) {
|
|
250
|
-
requestConfig.body = JSON.stringify(data);
|
|
251
|
-
}
|
|
252
|
-
if (this.config.debug) {
|
|
253
|
-
console.log(`[Commet SDK] ${method} ${url}`);
|
|
254
|
-
if (data) {
|
|
255
|
-
console.log("Request data:", JSON.stringify(data, null, 2));
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
const response = await fetch(url, requestConfig);
|
|
259
|
-
if (this.config.debug) {
|
|
260
|
-
console.log(
|
|
261
|
-
`[Commet SDK] Response status: ${response.status} ${response.statusText}`
|
|
262
|
-
);
|
|
404
|
+
await (0, import_open.default)(verification_uri_complete);
|
|
405
|
+
} catch {
|
|
406
|
+
console.log(import_chalk4.default.yellow("\u26A0 Could not open browser automatically."));
|
|
407
|
+
}
|
|
408
|
+
const pollSpinner = (0, import_ora3.default)("Waiting for authorization...").start();
|
|
409
|
+
let pollingInterval = interval;
|
|
410
|
+
let attempts = 0;
|
|
411
|
+
const maxAttempts = 180 / pollingInterval;
|
|
412
|
+
const poll = async () => {
|
|
413
|
+
if (attempts >= maxAttempts) {
|
|
414
|
+
pollSpinner.fail("Login timed out");
|
|
415
|
+
console.log(import_chalk4.default.red("Authorization timed out. Please try again."));
|
|
416
|
+
return;
|
|
263
417
|
}
|
|
264
|
-
|
|
265
|
-
let responseText;
|
|
418
|
+
attempts++;
|
|
266
419
|
try {
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
"[Commet SDK] Failed to parse JSON response:",
|
|
279
|
-
responseText
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
throw new CommetAPIError(
|
|
283
|
-
`Invalid JSON response: ${response.status} ${response.statusText}`,
|
|
284
|
-
response.status,
|
|
285
|
-
"INVALID_JSON",
|
|
286
|
-
{ responseText }
|
|
420
|
+
const tokenResponse = await fetch(
|
|
421
|
+
`${baseURL}/api/auth/device/token`,
|
|
422
|
+
{
|
|
423
|
+
method: "POST",
|
|
424
|
+
headers: { "Content-Type": "application/json" },
|
|
425
|
+
body: JSON.stringify({
|
|
426
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
427
|
+
device_code,
|
|
428
|
+
client_id: "commet-cli"
|
|
429
|
+
})
|
|
430
|
+
}
|
|
287
431
|
);
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
)
|
|
295
|
-
|
|
296
|
-
console.log(
|
|
297
|
-
`[Commet SDK] Retrying in ${delay}ms (attempt ${attempt}/${this.retryConfig.maxRetries})`
|
|
298
|
-
);
|
|
432
|
+
const tokenData = await tokenResponse.json();
|
|
433
|
+
if (tokenData.access_token) {
|
|
434
|
+
const authConfig = {
|
|
435
|
+
token: tokenData.access_token,
|
|
436
|
+
environment
|
|
437
|
+
};
|
|
438
|
+
if (tokenData.refresh_token) {
|
|
439
|
+
authConfig.refreshToken = tokenData.refresh_token;
|
|
299
440
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
441
|
+
if (tokenData.expires_in) {
|
|
442
|
+
authConfig.expiresAt = Date.now() + tokenData.expires_in * 1e3;
|
|
443
|
+
}
|
|
444
|
+
saveAuth(authConfig);
|
|
445
|
+
pollSpinner.succeed("Successfully logged in!");
|
|
446
|
+
console.log(import_chalk4.default.green("\n\u2713 Authentication complete"));
|
|
304
447
|
console.log(
|
|
305
|
-
|
|
306
|
-
|
|
448
|
+
import_chalk4.default.dim(
|
|
449
|
+
"\nNext steps:\n 1. Run `commet link` to connect a project\n 2. Run `commet pull` to generate types\n"
|
|
450
|
+
)
|
|
307
451
|
);
|
|
452
|
+
return;
|
|
308
453
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
454
|
+
if (tokenData.error === "authorization_pending") {
|
|
455
|
+
setTimeout(() => poll(), pollingInterval * 1e3);
|
|
456
|
+
} else if (tokenData.error === "slow_down") {
|
|
457
|
+
pollingInterval += 5;
|
|
458
|
+
setTimeout(() => poll(), pollingInterval * 1e3);
|
|
459
|
+
} else if (tokenData.error === "access_denied") {
|
|
460
|
+
pollSpinner.fail("Authorization denied");
|
|
461
|
+
console.log(import_chalk4.default.red("\n\u2717 You denied the authorization request."));
|
|
462
|
+
return;
|
|
463
|
+
} else if (tokenData.error === "expired_token") {
|
|
464
|
+
pollSpinner.fail("Code expired");
|
|
465
|
+
console.log(
|
|
466
|
+
import_chalk4.default.red(
|
|
467
|
+
"\n\u2717 The authorization code expired. Please try again."
|
|
468
|
+
)
|
|
317
469
|
);
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
if (this.config.debug) {
|
|
327
|
-
console.log("[Commet SDK] Response:", responseData);
|
|
328
|
-
}
|
|
329
|
-
return responseData;
|
|
330
|
-
} catch (error) {
|
|
331
|
-
if (error instanceof TypeError && error.message.includes("fetch")) {
|
|
332
|
-
if (attempt <= this.retryConfig.maxRetries) {
|
|
333
|
-
const delay = Math.min(
|
|
334
|
-
this.retryConfig.baseDelay * 2 ** (attempt - 1),
|
|
335
|
-
this.retryConfig.maxDelay
|
|
470
|
+
return;
|
|
471
|
+
} else {
|
|
472
|
+
pollSpinner.fail("Authorization failed");
|
|
473
|
+
console.log(
|
|
474
|
+
import_chalk4.default.red("\n\u2717 Error:"),
|
|
475
|
+
tokenData.error || "Unknown error"
|
|
336
476
|
);
|
|
337
|
-
|
|
338
|
-
console.log(`[Commet SDK] Network error, retrying in ${delay}ms`);
|
|
339
|
-
}
|
|
340
|
-
await this.sleep(delay);
|
|
341
|
-
return this.executeRequest(method, url, data, options, attempt + 1);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
throw error;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Get base URL based on environment
|
|
349
|
-
*/
|
|
350
|
-
getBaseURL() {
|
|
351
|
-
return this.environment === "production" ? "https://billing.commet.co" : "https://sandbox.commet.co";
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* Build full URL from endpoint and params
|
|
355
|
-
*/
|
|
356
|
-
buildURL(endpoint, params) {
|
|
357
|
-
const baseURL = this.getBaseURL();
|
|
358
|
-
const fullPath = `/api${endpoint.startsWith("/") ? endpoint : `/${endpoint}`}`;
|
|
359
|
-
if (this.config.debug) {
|
|
360
|
-
console.log(
|
|
361
|
-
`[Commet SDK] Building URL - baseURL: ${baseURL}, endpoint: ${endpoint}, fullPath: ${fullPath}`
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
|
-
const url = new URL(fullPath, baseURL);
|
|
365
|
-
if (params) {
|
|
366
|
-
for (const [key, value] of Object.entries(params)) {
|
|
367
|
-
if (value !== void 0 && value !== null) {
|
|
368
|
-
url.searchParams.append(key, String(value));
|
|
477
|
+
return;
|
|
369
478
|
}
|
|
479
|
+
} catch (error) {
|
|
480
|
+
pollSpinner.fail("Network error");
|
|
481
|
+
console.error(
|
|
482
|
+
import_chalk4.default.red("Error:"),
|
|
483
|
+
error instanceof Error ? error.message : "Unknown error"
|
|
484
|
+
);
|
|
370
485
|
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
* Generate idempotency key
|
|
380
|
-
*/
|
|
381
|
-
generateIdempotencyKey() {
|
|
382
|
-
return `sdk_${Date.now()}_${Math.random().toString(36).substring(2)}`;
|
|
486
|
+
};
|
|
487
|
+
poll();
|
|
488
|
+
} catch (error) {
|
|
489
|
+
spinner.fail("Login failed");
|
|
490
|
+
console.error(
|
|
491
|
+
import_chalk4.default.red("Error:"),
|
|
492
|
+
error instanceof Error ? error.message : "Unknown error"
|
|
493
|
+
);
|
|
383
494
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
// src/commands/logout.ts
|
|
498
|
+
var import_chalk5 = __toESM(require("chalk"));
|
|
499
|
+
var import_commander5 = require("commander");
|
|
500
|
+
var logoutCommand = new import_commander5.Command("logout").description("Log out of Commet").action(async () => {
|
|
501
|
+
if (!authExists()) {
|
|
502
|
+
console.log(import_chalk5.default.yellow("\u26A0 You are not logged in."));
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
clearAuth();
|
|
506
|
+
console.log(import_chalk5.default.green("\u2713 Successfully logged out"));
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
// src/commands/pull.ts
|
|
510
|
+
var fs2 = __toESM(require("fs"));
|
|
511
|
+
var path2 = __toESM(require("path"));
|
|
512
|
+
var import_chalk6 = __toESM(require("chalk"));
|
|
513
|
+
var import_commander6 = require("commander");
|
|
514
|
+
var import_ora4 = __toESM(require("ora"));
|
|
515
|
+
|
|
516
|
+
// src/utils/generator.ts
|
|
517
|
+
function generateTypes(eventTypes, seatTypes) {
|
|
518
|
+
const eventTypeUnion = eventTypes.length > 0 ? eventTypes.map((e) => `"${e.code}"`).join(" | ") : "string";
|
|
519
|
+
const seatTypeUnion = seatTypes.length > 0 ? seatTypes.map((s) => `"${s.code}"`).join(" | ") : "string";
|
|
520
|
+
const eventComments = eventTypes.map(
|
|
521
|
+
(e) => ` * - "${e.code}": ${e.name}${e.description ? ` - ${e.description}` : ""}`
|
|
522
|
+
).join("\n");
|
|
523
|
+
const seatComments = seatTypes.map(
|
|
524
|
+
(s) => ` * - "${s.code}": ${s.name}${s.description ? ` - ${s.description}` : ""} ${s.isFree ? "(Free)" : ""}`
|
|
525
|
+
).join("\n");
|
|
526
|
+
return `// Auto-generated by Commet CLI
|
|
527
|
+
// Do not edit this file manually - run 'commet pull' to update
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Event types available in your organization
|
|
531
|
+
${eventComments}
|
|
532
|
+
*/
|
|
533
|
+
export type CommetEventType = ${eventTypeUnion};
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Seat types available in your organization
|
|
537
|
+
${seatComments}
|
|
538
|
+
*/
|
|
539
|
+
export type CommetSeatType = ${seatTypeUnion};
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Use these types with the Commet SDK for type-safe event and seat tracking
|
|
543
|
+
*
|
|
544
|
+
* @example
|
|
545
|
+
* import { Commet } from 'commet';
|
|
546
|
+
* import type { CommetEventType, CommetSeatType } from './.commet';
|
|
547
|
+
*
|
|
548
|
+
* const commet = new Commet({ apiKey: 'your-api-key' });
|
|
549
|
+
*
|
|
550
|
+
* // Type-safe event tracking
|
|
551
|
+
* await commet.usage.sendEvent<CommetEventType>({
|
|
552
|
+
* customerId: 'cust_123',
|
|
553
|
+
* eventType: 'api_call', // Autocomplete works!
|
|
554
|
+
* timestamp: new Date(),
|
|
555
|
+
* });
|
|
556
|
+
*
|
|
557
|
+
* // Type-safe seat management
|
|
558
|
+
* await commet.seats.updateSeats<CommetSeatType>({
|
|
559
|
+
* customerId: 'cust_123',
|
|
560
|
+
* seatType: 'admin_seat', // Autocomplete works!
|
|
561
|
+
* totalSeats: 5,
|
|
562
|
+
* });
|
|
563
|
+
*/
|
|
564
|
+
`;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// src/commands/pull.ts
|
|
568
|
+
var pullCommand = new import_commander6.Command("pull").description("Pull type definitions from Commet").option("-o, --output <file>", "Output file path", ".commet.d.ts").action(async (options) => {
|
|
569
|
+
if (!authExists()) {
|
|
570
|
+
console.log(import_chalk6.default.red("\u2717 Not authenticated"));
|
|
571
|
+
console.log(import_chalk6.default.dim("Run `commet login` first"));
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
if (!projectConfigExists()) {
|
|
575
|
+
console.log(import_chalk6.default.red("\u2717 Project not linked"));
|
|
576
|
+
console.log(
|
|
577
|
+
import_chalk6.default.dim("Run `commet link` first to connect to an organization")
|
|
578
|
+
);
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
const projectConfig = loadProjectConfig();
|
|
582
|
+
if (!projectConfig) {
|
|
583
|
+
console.log(import_chalk6.default.red("\u2717 Invalid project configuration"));
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
const spinner = (0, import_ora4.default)("Fetching type definitions...").start();
|
|
587
|
+
const baseURL = getBaseURL(projectConfig.environment);
|
|
588
|
+
const result = await apiRequest(
|
|
589
|
+
`${baseURL}/api/cli/types?orgId=${projectConfig.orgId}`
|
|
590
|
+
);
|
|
591
|
+
if (result.error || !result.data) {
|
|
592
|
+
spinner.fail("Failed to fetch types");
|
|
593
|
+
console.error(import_chalk6.default.red("Error:"), result.error);
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
const { eventTypes, seatTypes } = result.data;
|
|
597
|
+
const typeDefinitions = generateTypes(eventTypes, seatTypes);
|
|
598
|
+
const outputPath = path2.resolve(process.cwd(), options.output);
|
|
599
|
+
fs2.writeFileSync(outputPath, typeDefinitions, "utf8");
|
|
600
|
+
spinner.succeed("Type definitions generated!");
|
|
601
|
+
console.log(import_chalk6.default.green("\n\u2713 Success"));
|
|
602
|
+
console.log(import_chalk6.default.dim("\nGenerated types:"));
|
|
603
|
+
console.log(
|
|
604
|
+
import_chalk6.default.dim(
|
|
605
|
+
` Event types: ${eventTypes.length > 0 ? eventTypes.map((e) => e.code).join(", ") : "none"}`
|
|
606
|
+
)
|
|
607
|
+
);
|
|
608
|
+
console.log(
|
|
609
|
+
import_chalk6.default.dim(
|
|
610
|
+
` Seat types: ${seatTypes.length > 0 ? seatTypes.map((s) => s.code).join(", ") : "none"}`
|
|
611
|
+
)
|
|
612
|
+
);
|
|
613
|
+
console.log(import_chalk6.default.dim(`
|
|
614
|
+
Output file: ${outputPath}`));
|
|
615
|
+
if (eventTypes.length === 0 && seatTypes.length === 0) {
|
|
616
|
+
console.log(
|
|
617
|
+
import_chalk6.default.yellow(
|
|
618
|
+
"\n\u26A0 No types found. Create event types and seat types in your Commet dashboard."
|
|
619
|
+
)
|
|
620
|
+
);
|
|
389
621
|
}
|
|
390
|
-
};
|
|
622
|
+
});
|
|
391
623
|
|
|
392
|
-
// src/
|
|
393
|
-
var
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
624
|
+
// src/commands/switch.ts
|
|
625
|
+
var import_chalk7 = __toESM(require("chalk"));
|
|
626
|
+
var import_commander7 = require("commander");
|
|
627
|
+
var import_inquirer3 = __toESM(require("inquirer"));
|
|
628
|
+
var import_ora5 = __toESM(require("ora"));
|
|
629
|
+
var switchCommand = new import_commander7.Command("switch").description("Switch to a different organization").action(async () => {
|
|
630
|
+
if (!authExists()) {
|
|
631
|
+
console.log(import_chalk7.default.red("\u2717 Not authenticated"));
|
|
632
|
+
console.log(import_chalk7.default.dim("Run `commet login` first"));
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
if (!projectConfigExists()) {
|
|
636
|
+
console.log(import_chalk7.default.yellow("\u26A0 Project not linked"));
|
|
637
|
+
console.log(
|
|
638
|
+
import_chalk7.default.dim("Run `commet link` first to connect to an organization")
|
|
639
|
+
);
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
const spinner = (0, import_ora5.default)("Fetching organizations...").start();
|
|
643
|
+
const auth = loadAuth();
|
|
644
|
+
if (!auth) {
|
|
645
|
+
spinner.fail("Authentication error");
|
|
646
|
+
console.log(import_chalk7.default.red("\u2717 Could not load authentication"));
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
const baseURL = getBaseURL(auth.environment);
|
|
650
|
+
const result = await apiRequest(
|
|
651
|
+
`${baseURL}/api/cli/organizations`
|
|
652
|
+
);
|
|
653
|
+
if (result.error || !result.data) {
|
|
654
|
+
spinner.fail("Failed to fetch organizations");
|
|
655
|
+
console.error(import_chalk7.default.red("Error:"), result.error);
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
const { organizations } = result.data;
|
|
659
|
+
if (organizations.length === 0) {
|
|
660
|
+
spinner.stop();
|
|
661
|
+
console.log(import_chalk7.default.yellow("\u26A0 No organizations found"));
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
spinner.stop();
|
|
665
|
+
const answers = await import_inquirer3.default.prompt([
|
|
666
|
+
{
|
|
667
|
+
type: "list",
|
|
668
|
+
name: "orgId",
|
|
669
|
+
message: "Select organization:",
|
|
670
|
+
choices: organizations.map((org) => ({
|
|
671
|
+
name: `${org.name} (${org.slug})`,
|
|
672
|
+
value: org.id
|
|
673
|
+
}))
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
type: "list",
|
|
677
|
+
name: "environment",
|
|
678
|
+
message: "Select environment:",
|
|
679
|
+
choices: [
|
|
680
|
+
{ name: "Sandbox (Development)", value: "sandbox" },
|
|
681
|
+
{ name: "Production", value: "production" }
|
|
682
|
+
],
|
|
683
|
+
default: "sandbox"
|
|
413
684
|
}
|
|
685
|
+
]);
|
|
686
|
+
const selectedOrg = organizations.find((org) => org.id === answers.orgId);
|
|
687
|
+
if (!selectedOrg) {
|
|
688
|
+
console.log(import_chalk7.default.red("\u2717 Organization not found"));
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
saveProjectConfig({
|
|
692
|
+
orgId: selectedOrg.id,
|
|
693
|
+
orgName: selectedOrg.name,
|
|
694
|
+
environment: answers.environment
|
|
695
|
+
});
|
|
696
|
+
console.log(import_chalk7.default.green("\n\u2713 Switched organization successfully!"));
|
|
697
|
+
console.log(import_chalk7.default.dim("\nNew configuration:"));
|
|
698
|
+
console.log(import_chalk7.default.dim(` Organization: ${selectedOrg.name}`));
|
|
699
|
+
console.log(import_chalk7.default.dim(` Environment: ${answers.environment}`));
|
|
700
|
+
console.log(
|
|
701
|
+
import_chalk7.default.dim(
|
|
702
|
+
"\nRun `commet pull` to update TypeScript types for this organization"
|
|
703
|
+
)
|
|
704
|
+
);
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
// src/commands/unlink.ts
|
|
708
|
+
var import_chalk8 = __toESM(require("chalk"));
|
|
709
|
+
var import_commander8 = require("commander");
|
|
710
|
+
var unlinkCommand = new import_commander8.Command("unlink").description("Unlink this project from Commet").action(async () => {
|
|
711
|
+
if (!projectConfigExists()) {
|
|
712
|
+
console.log(
|
|
713
|
+
import_chalk8.default.yellow("\u26A0 This project is not linked to any organization")
|
|
714
|
+
);
|
|
715
|
+
return;
|
|
414
716
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
717
|
+
clearProjectConfig();
|
|
718
|
+
console.log(import_chalk8.default.green("\u2713 Project unlinked successfully"));
|
|
719
|
+
console.log(import_chalk8.default.dim("Run `commet link` to connect to an organization"));
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
// src/commands/whoami.ts
|
|
723
|
+
var import_chalk9 = __toESM(require("chalk"));
|
|
724
|
+
var import_commander9 = require("commander");
|
|
725
|
+
var whoamiCommand = new import_commander9.Command("whoami").description("Display current authentication and project status").action(async () => {
|
|
726
|
+
if (!authExists()) {
|
|
727
|
+
console.log(import_chalk9.default.yellow("\u26A0 Not logged in"));
|
|
728
|
+
console.log(import_chalk9.default.dim("Run `commet login` to authenticate"));
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
console.log(import_chalk9.default.green("\u2713 Logged in"));
|
|
732
|
+
const projectConfig = loadProjectConfig();
|
|
733
|
+
if (projectConfig) {
|
|
734
|
+
console.log(import_chalk9.default.bold("\nProject:"));
|
|
735
|
+
console.log(import_chalk9.default.dim("Organization:"), projectConfig.orgName);
|
|
736
|
+
console.log(import_chalk9.default.dim("Environment:"), projectConfig.environment);
|
|
737
|
+
} else {
|
|
738
|
+
console.log(import_chalk9.default.yellow("\n\u26A0 No project linked"));
|
|
739
|
+
console.log(
|
|
740
|
+
import_chalk9.default.dim(
|
|
741
|
+
"Run `commet link` to connect this directory to an organization"
|
|
742
|
+
)
|
|
743
|
+
);
|
|
423
744
|
}
|
|
424
|
-
};
|
|
745
|
+
});
|
|
425
746
|
|
|
426
|
-
// src/
|
|
427
|
-
|
|
428
|
-
|
|
747
|
+
// src/index.ts
|
|
748
|
+
var program = new import_commander10.Command();
|
|
749
|
+
program.name("commet").description(
|
|
750
|
+
"Commet CLI - Manage your billing platform from the command line"
|
|
751
|
+
).version("0.3.0");
|
|
752
|
+
program.addCommand(loginCommand);
|
|
753
|
+
program.addCommand(logoutCommand);
|
|
754
|
+
program.addCommand(whoamiCommand);
|
|
755
|
+
program.addCommand(linkCommand);
|
|
756
|
+
program.addCommand(unlinkCommand);
|
|
757
|
+
program.addCommand(switchCommand);
|
|
758
|
+
program.addCommand(infoCommand);
|
|
759
|
+
program.addCommand(pullCommand);
|
|
760
|
+
program.addCommand(listCommand);
|
|
761
|
+
program.exitOverride();
|
|
762
|
+
try {
|
|
763
|
+
program.parse(process.argv);
|
|
764
|
+
} catch (error) {
|
|
765
|
+
if (error instanceof Error) {
|
|
766
|
+
if (error.message.includes("outputHelp")) {
|
|
767
|
+
process.exit(0);
|
|
768
|
+
}
|
|
769
|
+
console.error(import_chalk10.default.red("Error:"), error.message);
|
|
770
|
+
}
|
|
771
|
+
process.exit(1);
|
|
429
772
|
}
|
|
430
|
-
|
|
431
|
-
|
|
773
|
+
if (!process.argv.slice(2).length) {
|
|
774
|
+
program.outputHelp();
|
|
432
775
|
}
|
|
433
|
-
|
|
434
|
-
// src/index.ts
|
|
435
|
-
var index_default = Commet;
|
|
436
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
437
|
-
0 && (module.exports = {
|
|
438
|
-
Commet,
|
|
439
|
-
CommetAPIError,
|
|
440
|
-
CommetError,
|
|
441
|
-
CommetValidationError,
|
|
442
|
-
isProduction,
|
|
443
|
-
isSandbox
|
|
444
|
-
});
|
|
445
|
-
//# sourceMappingURL=index.js.map
|