commet 0.4.0 → 0.4.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/LICENSE +202 -21
- package/README.md +29 -11
- package/dist/index.js +405 -329
- package/package.json +3 -4
package/LICENSE
CHANGED
|
@@ -1,21 +1,202 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2025 Commet
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -37,7 +37,13 @@ Authenticate with Commet using OAuth device flow.
|
|
|
37
37
|
commet login
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
Prompts you to select an environment (Sandbox or Production), then opens your browser to authenticate. Creates `~/.commet/auth.json` with your credentials.
|
|
41
|
+
|
|
42
|
+
**Important:** Sandbox and Production are completely isolated platforms with separate accounts:
|
|
43
|
+
- **Sandbox**: `sandbox.commet.co` - Development and testing
|
|
44
|
+
- **Production**: `billing.commet.co` - Live billing operations
|
|
45
|
+
|
|
46
|
+
Make sure to login to the correct environment for your needs.
|
|
41
47
|
|
|
42
48
|
#### `commet logout`
|
|
43
49
|
|
|
@@ -158,10 +164,13 @@ Stores authentication credentials. Created by `commet login`.
|
|
|
158
164
|
{
|
|
159
165
|
"token": "...",
|
|
160
166
|
"refreshToken": "...",
|
|
161
|
-
"expiresAt": 1234567890
|
|
167
|
+
"expiresAt": 1234567890,
|
|
168
|
+
"environment": "sandbox"
|
|
162
169
|
}
|
|
163
170
|
```
|
|
164
171
|
|
|
172
|
+
The `environment` field determines which platform your authentication is for (sandbox or production).
|
|
173
|
+
|
|
165
174
|
### Project Config (`.commet`)
|
|
166
175
|
|
|
167
176
|
Stores project-specific configuration. Created by `commet link`.
|
|
@@ -178,21 +187,27 @@ Stores project-specific configuration. Created by `commet link`.
|
|
|
178
187
|
|
|
179
188
|
## Environments
|
|
180
189
|
|
|
181
|
-
Commet supports two environments:
|
|
190
|
+
Commet supports two completely isolated environments:
|
|
191
|
+
|
|
192
|
+
- **Sandbox** (`sandbox.commet.co`): Development and testing with separate data
|
|
193
|
+
- **Production** (`billing.commet.co`): Live billing operations with real customers
|
|
182
194
|
|
|
183
|
-
|
|
184
|
-
- **Production**: Live billing operations
|
|
195
|
+
**Important:** Each environment requires separate authentication because they are independent platforms. To work with both:
|
|
185
196
|
|
|
186
|
-
|
|
197
|
+
1. Login to sandbox: `commet login` → Select "Sandbox"
|
|
198
|
+
2. Do your work in sandbox
|
|
199
|
+
3. When ready for production: `commet logout` → `commet login` → Select "Production"
|
|
200
|
+
|
|
201
|
+
Organizations and data do NOT transfer between environments.
|
|
187
202
|
|
|
188
203
|
## Workflow
|
|
189
204
|
|
|
190
205
|
Typical development workflow:
|
|
191
206
|
|
|
192
207
|
```bash
|
|
193
|
-
# 1. One-time setup
|
|
194
|
-
commet login
|
|
195
|
-
commet link
|
|
208
|
+
# 1. One-time setup (Sandbox)
|
|
209
|
+
commet login # Select "Sandbox"
|
|
210
|
+
commet link # Choose your organization
|
|
196
211
|
|
|
197
212
|
# 2. Generate types when you add/change event or seat types
|
|
198
213
|
commet pull
|
|
@@ -200,8 +215,11 @@ commet pull
|
|
|
200
215
|
# 3. Use types in your code with autocomplete
|
|
201
216
|
# (see TypeScript examples above)
|
|
202
217
|
|
|
203
|
-
# 4.
|
|
204
|
-
commet
|
|
218
|
+
# 4. When ready for production
|
|
219
|
+
commet logout
|
|
220
|
+
commet login # Select "Production"
|
|
221
|
+
commet link # Link to production organization
|
|
222
|
+
commet pull # Generate production types
|
|
205
223
|
```
|
|
206
224
|
|
|
207
225
|
## Troubleshooting
|
package/dist/index.js
CHANGED
|
@@ -24,14 +24,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
));
|
|
25
25
|
|
|
26
26
|
// src/index.ts
|
|
27
|
+
var import_chalk11 = __toESM(require("chalk"));
|
|
27
28
|
var import_commander10 = require("commander");
|
|
28
|
-
var import_chalk10 = __toESM(require("chalk"));
|
|
29
29
|
|
|
30
|
-
// src/commands/
|
|
31
|
-
var import_commander = require("commander");
|
|
30
|
+
// src/commands/info.ts
|
|
32
31
|
var import_chalk = __toESM(require("chalk"));
|
|
33
|
-
var
|
|
34
|
-
var import_open = __toESM(require("open"));
|
|
32
|
+
var import_commander = require("commander");
|
|
35
33
|
|
|
36
34
|
// src/utils/config.ts
|
|
37
35
|
var fs = __toESM(require("fs"));
|
|
@@ -95,12 +93,48 @@ function clearProjectConfig() {
|
|
|
95
93
|
}
|
|
96
94
|
}
|
|
97
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")
|
|
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_prompts = require("@inquirer/prompts");
|
|
128
|
+
var import_chalk3 = __toESM(require("chalk"));
|
|
129
|
+
var import_commander2 = require("commander");
|
|
130
|
+
var import_ora = __toESM(require("ora"));
|
|
131
|
+
|
|
98
132
|
// src/utils/api.ts
|
|
99
133
|
function getBaseURL(environment) {
|
|
100
134
|
if (environment === "production") {
|
|
101
135
|
return "https://billing.commet.co";
|
|
102
136
|
}
|
|
103
|
-
return "https://
|
|
137
|
+
return "https://sandbox.commet.co";
|
|
104
138
|
}
|
|
105
139
|
async function apiRequest(endpoint, options = {}) {
|
|
106
140
|
const auth = loadAuth();
|
|
@@ -131,18 +165,229 @@ async function apiRequest(endpoint, options = {}) {
|
|
|
131
165
|
}
|
|
132
166
|
}
|
|
133
167
|
|
|
168
|
+
// src/utils/prompt-theme.ts
|
|
169
|
+
var import_chalk2 = __toESM(require("chalk"));
|
|
170
|
+
var commetColor = import_chalk2.default.hex("#5BC0B0");
|
|
171
|
+
var promptTheme = {
|
|
172
|
+
prefix: commetColor("\u276F"),
|
|
173
|
+
style: {
|
|
174
|
+
answer: commetColor,
|
|
175
|
+
message: import_chalk2.default.bold,
|
|
176
|
+
error: import_chalk2.default.red,
|
|
177
|
+
help: import_chalk2.default.dim,
|
|
178
|
+
highlight: commetColor.bold,
|
|
179
|
+
// Selected option in mint
|
|
180
|
+
description: import_chalk2.default.dim,
|
|
181
|
+
defaultAnswer: import_chalk2.default.dim
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// src/commands/link.ts
|
|
186
|
+
var linkCommand = new import_commander2.Command("link").description("Link this project to a Commet organization").action(async () => {
|
|
187
|
+
if (!authExists()) {
|
|
188
|
+
console.log(import_chalk3.default.red("\u2717 Not authenticated"));
|
|
189
|
+
console.log(import_chalk3.default.dim("Run `commet login` first"));
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (projectConfigExists()) {
|
|
193
|
+
const config = loadProjectConfig();
|
|
194
|
+
console.log(import_chalk3.default.yellow("\u26A0 This project is already linked"));
|
|
195
|
+
console.log(
|
|
196
|
+
import_chalk3.default.dim(`Organization: ${config?.orgName} (${config?.environment})`)
|
|
197
|
+
);
|
|
198
|
+
console.log(
|
|
199
|
+
import_chalk3.default.dim(
|
|
200
|
+
"\nRun `commet unlink` first if you want to change the organization"
|
|
201
|
+
)
|
|
202
|
+
);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const spinner = (0, import_ora.default)("Fetching organizations...").start();
|
|
206
|
+
const auth = loadAuth();
|
|
207
|
+
if (!auth) {
|
|
208
|
+
spinner.fail("Authentication error");
|
|
209
|
+
console.log(import_chalk3.default.red("\u2717 Could not load authentication"));
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const baseURL = getBaseURL(auth.environment);
|
|
213
|
+
const result = await apiRequest(
|
|
214
|
+
`${baseURL}/api/cli/organizations`
|
|
215
|
+
);
|
|
216
|
+
if (result.error || !result.data) {
|
|
217
|
+
spinner.fail("Failed to fetch organizations");
|
|
218
|
+
console.error(import_chalk3.default.red("Error:"), result.error);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const { organizations } = result.data;
|
|
222
|
+
if (organizations.length === 0) {
|
|
223
|
+
spinner.stop();
|
|
224
|
+
console.log(import_chalk3.default.yellow("\u26A0 No organizations found"));
|
|
225
|
+
console.log(
|
|
226
|
+
import_chalk3.default.dim("Create an organization at https://billing.commet.co first")
|
|
227
|
+
);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
spinner.stop();
|
|
231
|
+
let orgId;
|
|
232
|
+
try {
|
|
233
|
+
orgId = await (0, import_prompts.select)({
|
|
234
|
+
message: "Select organization:",
|
|
235
|
+
choices: organizations.map((org) => ({
|
|
236
|
+
name: `${org.name} ${import_chalk3.default.dim(`(${org.slug})`)}`,
|
|
237
|
+
value: org.id
|
|
238
|
+
})),
|
|
239
|
+
theme: promptTheme
|
|
240
|
+
});
|
|
241
|
+
} catch (error) {
|
|
242
|
+
console.log(import_chalk3.default.yellow("\n\u26A0 Link cancelled"));
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const selectedOrg = organizations.find((org) => org.id === orgId);
|
|
246
|
+
if (!selectedOrg) {
|
|
247
|
+
console.log(import_chalk3.default.red("\u2717 Organization not found"));
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
saveProjectConfig({
|
|
251
|
+
orgId: selectedOrg.id,
|
|
252
|
+
orgName: selectedOrg.name,
|
|
253
|
+
environment: auth.environment
|
|
254
|
+
});
|
|
255
|
+
console.log(import_chalk3.default.green("\n\u2713 Project linked successfully!"));
|
|
256
|
+
console.log(import_chalk3.default.dim("\nProject configuration:"));
|
|
257
|
+
console.log(import_chalk3.default.dim(` Organization: ${selectedOrg.name}`));
|
|
258
|
+
console.log(import_chalk3.default.dim(` Environment: ${auth.environment}`));
|
|
259
|
+
console.log(
|
|
260
|
+
import_chalk3.default.dim(
|
|
261
|
+
"\nNext step:\n Run `commet pull` to generate TypeScript types"
|
|
262
|
+
)
|
|
263
|
+
);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// src/commands/list.ts
|
|
267
|
+
var import_chalk4 = __toESM(require("chalk"));
|
|
268
|
+
var import_commander3 = require("commander");
|
|
269
|
+
var import_ora2 = __toESM(require("ora"));
|
|
270
|
+
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) => {
|
|
271
|
+
if (type !== "events" && type !== "seats") {
|
|
272
|
+
console.log(import_chalk4.default.red('\u2717 Invalid type. Use "events" or "seats"'));
|
|
273
|
+
console.log(import_chalk4.default.dim("\nExamples:"));
|
|
274
|
+
console.log(import_chalk4.default.dim(" commet list events"));
|
|
275
|
+
console.log(import_chalk4.default.dim(" commet list seats"));
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (!authExists()) {
|
|
279
|
+
console.log(import_chalk4.default.red("\u2717 Not authenticated"));
|
|
280
|
+
console.log(import_chalk4.default.dim("Run `commet login` first"));
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (!projectConfigExists()) {
|
|
284
|
+
console.log(import_chalk4.default.red("\u2717 Project not linked"));
|
|
285
|
+
console.log(
|
|
286
|
+
import_chalk4.default.dim("Run `commet link` first to connect to an organization")
|
|
287
|
+
);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const projectConfig = loadProjectConfig();
|
|
291
|
+
if (!projectConfig) {
|
|
292
|
+
console.log(import_chalk4.default.red("\u2717 Invalid project configuration"));
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const spinner = (0, import_ora2.default)(`Fetching ${type}...`).start();
|
|
296
|
+
const baseURL = getBaseURL(projectConfig.environment);
|
|
297
|
+
const result = await apiRequest(
|
|
298
|
+
`${baseURL}/api/cli/types?orgId=${projectConfig.orgId}`
|
|
299
|
+
);
|
|
300
|
+
if (result.error || !result.data) {
|
|
301
|
+
spinner.fail(`Failed to fetch ${type}`);
|
|
302
|
+
console.error(import_chalk4.default.red("Error:"), result.error);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
spinner.stop();
|
|
306
|
+
if (type === "events") {
|
|
307
|
+
const { eventTypes } = result.data;
|
|
308
|
+
if (eventTypes.length === 0) {
|
|
309
|
+
console.log(import_chalk4.default.yellow("\u26A0 No event types found"));
|
|
310
|
+
console.log(
|
|
311
|
+
import_chalk4.default.dim("Create event types in your Commet dashboard first")
|
|
312
|
+
);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
console.log(import_chalk4.default.bold(`
|
|
316
|
+
\u{1F4CA} Event Types (${eventTypes.length})
|
|
317
|
+
`));
|
|
318
|
+
for (const eventType of eventTypes) {
|
|
319
|
+
console.log(import_chalk4.default.green(`\u2022 ${eventType.code}`));
|
|
320
|
+
console.log(import_chalk4.default.dim(` ${eventType.name}`));
|
|
321
|
+
if (eventType.description) {
|
|
322
|
+
console.log(import_chalk4.default.dim(` ${eventType.description}`));
|
|
323
|
+
}
|
|
324
|
+
console.log("");
|
|
325
|
+
}
|
|
326
|
+
} else {
|
|
327
|
+
const { seatTypes } = result.data;
|
|
328
|
+
if (seatTypes.length === 0) {
|
|
329
|
+
console.log(import_chalk4.default.yellow("\u26A0 No seat types found"));
|
|
330
|
+
console.log(
|
|
331
|
+
import_chalk4.default.dim("Create seat types in your Commet dashboard first")
|
|
332
|
+
);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
console.log(import_chalk4.default.bold(`
|
|
336
|
+
\u{1F4BA} Seat Types (${seatTypes.length})
|
|
337
|
+
`));
|
|
338
|
+
for (const seatType of seatTypes) {
|
|
339
|
+
console.log(
|
|
340
|
+
import_chalk4.default.green(`\u2022 ${seatType.code}${seatType.isFree ? " (Free)" : ""}`)
|
|
341
|
+
);
|
|
342
|
+
console.log(import_chalk4.default.dim(` ${seatType.name}`));
|
|
343
|
+
if (seatType.description) {
|
|
344
|
+
console.log(import_chalk4.default.dim(` ${seatType.description}`));
|
|
345
|
+
}
|
|
346
|
+
console.log("");
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
|
|
134
351
|
// src/commands/login.ts
|
|
135
|
-
var
|
|
352
|
+
var import_prompts2 = require("@inquirer/prompts");
|
|
353
|
+
var import_chalk5 = __toESM(require("chalk"));
|
|
354
|
+
var import_commander4 = require("commander");
|
|
355
|
+
var import_open = __toESM(require("open"));
|
|
356
|
+
var import_ora3 = __toESM(require("ora"));
|
|
357
|
+
var loginCommand = new import_commander4.Command("login").description("Authenticate with Commet").action(async () => {
|
|
136
358
|
if (authExists()) {
|
|
137
359
|
const auth = loadAuth();
|
|
138
|
-
console.log(
|
|
360
|
+
console.log(import_chalk5.default.yellow("\u26A0 You are already logged in."));
|
|
139
361
|
console.log(
|
|
140
|
-
|
|
362
|
+
import_chalk5.default.dim(
|
|
363
|
+
"Run `commet logout` first if you want to login with a different account."
|
|
364
|
+
)
|
|
141
365
|
);
|
|
142
366
|
return;
|
|
143
367
|
}
|
|
144
|
-
|
|
145
|
-
|
|
368
|
+
let environment;
|
|
369
|
+
try {
|
|
370
|
+
environment = await (0, import_prompts2.select)({
|
|
371
|
+
message: "Select environment to login:",
|
|
372
|
+
choices: [
|
|
373
|
+
{
|
|
374
|
+
name: `Sandbox ${import_chalk5.default.dim("(Development)")}`,
|
|
375
|
+
value: "sandbox"
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
name: "Production",
|
|
379
|
+
value: "production"
|
|
380
|
+
}
|
|
381
|
+
],
|
|
382
|
+
default: "sandbox",
|
|
383
|
+
theme: promptTheme
|
|
384
|
+
});
|
|
385
|
+
} catch (error) {
|
|
386
|
+
console.log(import_chalk5.default.yellow("\n\u26A0 Login cancelled"));
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
const spinner = (0, import_ora3.default)("Initiating login flow...").start();
|
|
390
|
+
const baseURL = getBaseURL(environment);
|
|
146
391
|
try {
|
|
147
392
|
const deviceResponse = await fetch(`${baseURL}/api/auth/device/code`, {
|
|
148
393
|
method: "POST",
|
|
@@ -154,7 +399,7 @@ var loginCommand = new import_commander.Command("login").description("Authentica
|
|
|
154
399
|
});
|
|
155
400
|
if (!deviceResponse.ok) {
|
|
156
401
|
spinner.fail("Failed to initiate login");
|
|
157
|
-
console.error(
|
|
402
|
+
console.error(import_chalk5.default.red("Error:"), await deviceResponse.text());
|
|
158
403
|
return;
|
|
159
404
|
}
|
|
160
405
|
const deviceData = await deviceResponse.json();
|
|
@@ -165,42 +410,46 @@ var loginCommand = new import_commander.Command("login").description("Authentica
|
|
|
165
410
|
interval = 5
|
|
166
411
|
} = deviceData;
|
|
167
412
|
spinner.stop();
|
|
168
|
-
console.log(
|
|
413
|
+
console.log(import_chalk5.default.bold("\n\u{1F510} Commet CLI Login\n"));
|
|
169
414
|
console.log("Visit the following URL in your browser:");
|
|
170
|
-
console.log(
|
|
415
|
+
console.log(import_chalk5.default.cyan.underline(verification_uri_complete));
|
|
171
416
|
console.log("\nOr enter this code manually:");
|
|
172
|
-
console.log(
|
|
173
|
-
console.log(
|
|
417
|
+
console.log(import_chalk5.default.bold.green(` ${user_code}`));
|
|
418
|
+
console.log(import_chalk5.default.dim("\nOpening browser...\n"));
|
|
174
419
|
try {
|
|
175
420
|
await (0, import_open.default)(verification_uri_complete);
|
|
176
421
|
} catch {
|
|
177
|
-
console.log(
|
|
422
|
+
console.log(import_chalk5.default.yellow("\u26A0 Could not open browser automatically."));
|
|
178
423
|
}
|
|
179
|
-
const pollSpinner = (0,
|
|
424
|
+
const pollSpinner = (0, import_ora3.default)("Waiting for authorization...").start();
|
|
180
425
|
let pollingInterval = interval;
|
|
181
426
|
let attempts = 0;
|
|
182
427
|
const maxAttempts = 180 / pollingInterval;
|
|
183
428
|
const poll = async () => {
|
|
184
429
|
if (attempts >= maxAttempts) {
|
|
185
430
|
pollSpinner.fail("Login timed out");
|
|
186
|
-
console.log(
|
|
431
|
+
console.log(import_chalk5.default.red("Authorization timed out. Please try again."));
|
|
187
432
|
return;
|
|
188
433
|
}
|
|
189
434
|
attempts++;
|
|
190
435
|
try {
|
|
191
|
-
const tokenResponse = await fetch(
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
436
|
+
const tokenResponse = await fetch(
|
|
437
|
+
`${baseURL}/api/auth/device/token`,
|
|
438
|
+
{
|
|
439
|
+
method: "POST",
|
|
440
|
+
headers: { "Content-Type": "application/json" },
|
|
441
|
+
body: JSON.stringify({
|
|
442
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
443
|
+
device_code,
|
|
444
|
+
client_id: "commet-cli"
|
|
445
|
+
})
|
|
446
|
+
}
|
|
447
|
+
);
|
|
200
448
|
const tokenData = await tokenResponse.json();
|
|
201
449
|
if (tokenData.access_token) {
|
|
202
450
|
const authConfig = {
|
|
203
|
-
token: tokenData.access_token
|
|
451
|
+
token: tokenData.access_token,
|
|
452
|
+
environment
|
|
204
453
|
};
|
|
205
454
|
if (tokenData.refresh_token) {
|
|
206
455
|
authConfig.refreshToken = tokenData.refresh_token;
|
|
@@ -210,9 +459,11 @@ var loginCommand = new import_commander.Command("login").description("Authentica
|
|
|
210
459
|
}
|
|
211
460
|
saveAuth(authConfig);
|
|
212
461
|
pollSpinner.succeed("Successfully logged in!");
|
|
213
|
-
console.log(
|
|
462
|
+
console.log(import_chalk5.default.green("\n\u2713 Authentication complete"));
|
|
214
463
|
console.log(
|
|
215
|
-
|
|
464
|
+
import_chalk5.default.dim(
|
|
465
|
+
"\nNext steps:\n 1. Run `commet link` to connect a project\n 2. Run `commet pull` to generate types\n"
|
|
466
|
+
)
|
|
216
467
|
);
|
|
217
468
|
return;
|
|
218
469
|
}
|
|
@@ -223,23 +474,28 @@ var loginCommand = new import_commander.Command("login").description("Authentica
|
|
|
223
474
|
setTimeout(() => poll(), pollingInterval * 1e3);
|
|
224
475
|
} else if (tokenData.error === "access_denied") {
|
|
225
476
|
pollSpinner.fail("Authorization denied");
|
|
226
|
-
console.log(
|
|
227
|
-
import_chalk.default.red("\n\u2717 You denied the authorization request.")
|
|
228
|
-
);
|
|
477
|
+
console.log(import_chalk5.default.red("\n\u2717 You denied the authorization request."));
|
|
229
478
|
return;
|
|
230
479
|
} else if (tokenData.error === "expired_token") {
|
|
231
480
|
pollSpinner.fail("Code expired");
|
|
232
|
-
console.log(
|
|
481
|
+
console.log(
|
|
482
|
+
import_chalk5.default.red(
|
|
483
|
+
"\n\u2717 The authorization code expired. Please try again."
|
|
484
|
+
)
|
|
485
|
+
);
|
|
233
486
|
return;
|
|
234
487
|
} else {
|
|
235
488
|
pollSpinner.fail("Authorization failed");
|
|
236
|
-
console.log(
|
|
489
|
+
console.log(
|
|
490
|
+
import_chalk5.default.red("\n\u2717 Error:"),
|
|
491
|
+
tokenData.error || "Unknown error"
|
|
492
|
+
);
|
|
237
493
|
return;
|
|
238
494
|
}
|
|
239
495
|
} catch (error) {
|
|
240
496
|
pollSpinner.fail("Network error");
|
|
241
497
|
console.error(
|
|
242
|
-
|
|
498
|
+
import_chalk5.default.red("Error:"),
|
|
243
499
|
error instanceof Error ? error.message : "Unknown error"
|
|
244
500
|
);
|
|
245
501
|
}
|
|
@@ -248,227 +504,38 @@ var loginCommand = new import_commander.Command("login").description("Authentica
|
|
|
248
504
|
} catch (error) {
|
|
249
505
|
spinner.fail("Login failed");
|
|
250
506
|
console.error(
|
|
251
|
-
|
|
507
|
+
import_chalk5.default.red("Error:"),
|
|
252
508
|
error instanceof Error ? error.message : "Unknown error"
|
|
253
509
|
);
|
|
254
510
|
}
|
|
255
511
|
});
|
|
256
512
|
|
|
257
513
|
// src/commands/logout.ts
|
|
258
|
-
var import_commander2 = require("commander");
|
|
259
|
-
var import_chalk2 = __toESM(require("chalk"));
|
|
260
|
-
var logoutCommand = new import_commander2.Command("logout").description("Log out of Commet").action(async () => {
|
|
261
|
-
if (!authExists()) {
|
|
262
|
-
console.log(import_chalk2.default.yellow("\u26A0 You are not logged in."));
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
clearAuth();
|
|
266
|
-
console.log(import_chalk2.default.green("\u2713 Successfully logged out"));
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
// src/commands/whoami.ts
|
|
270
|
-
var import_commander3 = require("commander");
|
|
271
|
-
var import_chalk3 = __toESM(require("chalk"));
|
|
272
|
-
var whoamiCommand = new import_commander3.Command("whoami").description("Display current authentication and project status").action(async () => {
|
|
273
|
-
if (!authExists()) {
|
|
274
|
-
console.log(import_chalk3.default.yellow("\u26A0 Not logged in"));
|
|
275
|
-
console.log(import_chalk3.default.dim("Run `commet login` to authenticate"));
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
console.log(import_chalk3.default.green("\u2713 Logged in"));
|
|
279
|
-
const projectConfig = loadProjectConfig();
|
|
280
|
-
if (projectConfig) {
|
|
281
|
-
console.log(import_chalk3.default.bold("\nProject:"));
|
|
282
|
-
console.log(import_chalk3.default.dim("Organization:"), projectConfig.orgName);
|
|
283
|
-
console.log(import_chalk3.default.dim("Environment:"), projectConfig.environment);
|
|
284
|
-
} else {
|
|
285
|
-
console.log(import_chalk3.default.yellow("\n\u26A0 No project linked"));
|
|
286
|
-
console.log(import_chalk3.default.dim("Run `commet link` to connect this directory to an organization"));
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
// src/commands/link.ts
|
|
291
|
-
var import_commander4 = require("commander");
|
|
292
|
-
var import_chalk4 = __toESM(require("chalk"));
|
|
293
|
-
var import_inquirer = __toESM(require("inquirer"));
|
|
294
|
-
var import_ora2 = __toESM(require("ora"));
|
|
295
|
-
var linkCommand = new import_commander4.Command("link").description("Link this project to a Commet organization").action(async () => {
|
|
296
|
-
if (!authExists()) {
|
|
297
|
-
console.log(import_chalk4.default.red("\u2717 Not authenticated"));
|
|
298
|
-
console.log(import_chalk4.default.dim("Run `commet login` first"));
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
if (projectConfigExists()) {
|
|
302
|
-
const config = loadProjectConfig();
|
|
303
|
-
console.log(import_chalk4.default.yellow("\u26A0 This project is already linked"));
|
|
304
|
-
console.log(
|
|
305
|
-
import_chalk4.default.dim(`Organization: ${config?.orgName} (${config?.environment})`)
|
|
306
|
-
);
|
|
307
|
-
console.log(
|
|
308
|
-
import_chalk4.default.dim("\nRun `commet unlink` first if you want to change the organization")
|
|
309
|
-
);
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
const spinner = (0, import_ora2.default)("Fetching organizations...").start();
|
|
313
|
-
const baseURL = getBaseURL("sandbox");
|
|
314
|
-
const result = await apiRequest(
|
|
315
|
-
`${baseURL}/api/cli/organizations`
|
|
316
|
-
);
|
|
317
|
-
if (result.error || !result.data) {
|
|
318
|
-
spinner.fail("Failed to fetch organizations");
|
|
319
|
-
console.error(import_chalk4.default.red("Error:"), result.error);
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
const { organizations } = result.data;
|
|
323
|
-
if (organizations.length === 0) {
|
|
324
|
-
spinner.stop();
|
|
325
|
-
console.log(import_chalk4.default.yellow("\u26A0 No organizations found"));
|
|
326
|
-
console.log(
|
|
327
|
-
import_chalk4.default.dim("Create an organization at https://billing.commet.co first")
|
|
328
|
-
);
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
spinner.stop();
|
|
332
|
-
const answers = await import_inquirer.default.prompt([
|
|
333
|
-
{
|
|
334
|
-
type: "list",
|
|
335
|
-
name: "orgId",
|
|
336
|
-
message: "Select organization:",
|
|
337
|
-
choices: organizations.map((org) => ({
|
|
338
|
-
name: `${org.name} (${org.slug})`,
|
|
339
|
-
value: org.id
|
|
340
|
-
}))
|
|
341
|
-
},
|
|
342
|
-
{
|
|
343
|
-
type: "list",
|
|
344
|
-
name: "environment",
|
|
345
|
-
message: "Select environment:",
|
|
346
|
-
choices: [
|
|
347
|
-
{ name: "Sandbox (Development)", value: "sandbox" },
|
|
348
|
-
{ name: "Production", value: "production" }
|
|
349
|
-
],
|
|
350
|
-
default: "sandbox"
|
|
351
|
-
}
|
|
352
|
-
]);
|
|
353
|
-
const selectedOrg = organizations.find((org) => org.id === answers.orgId);
|
|
354
|
-
if (!selectedOrg) {
|
|
355
|
-
console.log(import_chalk4.default.red("\u2717 Organization not found"));
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
saveProjectConfig({
|
|
359
|
-
orgId: selectedOrg.id,
|
|
360
|
-
orgName: selectedOrg.name,
|
|
361
|
-
environment: answers.environment
|
|
362
|
-
});
|
|
363
|
-
console.log(import_chalk4.default.green("\n\u2713 Project linked successfully!"));
|
|
364
|
-
console.log(import_chalk4.default.dim("\nProject configuration:"));
|
|
365
|
-
console.log(import_chalk4.default.dim(` Organization: ${selectedOrg.name}`));
|
|
366
|
-
console.log(import_chalk4.default.dim(` Environment: ${answers.environment}`));
|
|
367
|
-
console.log(
|
|
368
|
-
import_chalk4.default.dim("\nNext step:\n Run `commet pull` to generate TypeScript types")
|
|
369
|
-
);
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
// src/commands/unlink.ts
|
|
373
|
-
var import_commander5 = require("commander");
|
|
374
|
-
var import_chalk5 = __toESM(require("chalk"));
|
|
375
|
-
var unlinkCommand = new import_commander5.Command("unlink").description("Unlink this project from Commet").action(async () => {
|
|
376
|
-
if (!projectConfigExists()) {
|
|
377
|
-
console.log(import_chalk5.default.yellow("\u26A0 This project is not linked to any organization"));
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
clearProjectConfig();
|
|
381
|
-
console.log(import_chalk5.default.green("\u2713 Project unlinked successfully"));
|
|
382
|
-
console.log(import_chalk5.default.dim("Run `commet link` to connect to an organization"));
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
// src/commands/switch.ts
|
|
386
|
-
var import_commander6 = require("commander");
|
|
387
514
|
var import_chalk6 = __toESM(require("chalk"));
|
|
388
|
-
var
|
|
389
|
-
var
|
|
390
|
-
var switchCommand = new import_commander6.Command("switch").description("Switch to a different organization").action(async () => {
|
|
515
|
+
var import_commander5 = require("commander");
|
|
516
|
+
var logoutCommand = new import_commander5.Command("logout").description("Log out of Commet").action(async () => {
|
|
391
517
|
if (!authExists()) {
|
|
392
|
-
console.log(import_chalk6.default.
|
|
393
|
-
console.log(import_chalk6.default.dim("Run `commet login` first"));
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
if (!projectConfigExists()) {
|
|
397
|
-
console.log(import_chalk6.default.yellow("\u26A0 Project not linked"));
|
|
398
|
-
console.log(
|
|
399
|
-
import_chalk6.default.dim("Run `commet link` first to connect to an organization")
|
|
400
|
-
);
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
const spinner = (0, import_ora3.default)("Fetching organizations...").start();
|
|
404
|
-
const baseURL = getBaseURL("sandbox");
|
|
405
|
-
const result = await apiRequest(
|
|
406
|
-
`${baseURL}/api/cli/organizations`
|
|
407
|
-
);
|
|
408
|
-
if (result.error || !result.data) {
|
|
409
|
-
spinner.fail("Failed to fetch organizations");
|
|
410
|
-
console.error(import_chalk6.default.red("Error:"), result.error);
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
const { organizations } = result.data;
|
|
414
|
-
if (organizations.length === 0) {
|
|
415
|
-
spinner.stop();
|
|
416
|
-
console.log(import_chalk6.default.yellow("\u26A0 No organizations found"));
|
|
417
|
-
return;
|
|
418
|
-
}
|
|
419
|
-
spinner.stop();
|
|
420
|
-
const answers = await import_inquirer2.default.prompt([
|
|
421
|
-
{
|
|
422
|
-
type: "list",
|
|
423
|
-
name: "orgId",
|
|
424
|
-
message: "Select organization:",
|
|
425
|
-
choices: organizations.map((org) => ({
|
|
426
|
-
name: `${org.name} (${org.slug})`,
|
|
427
|
-
value: org.id
|
|
428
|
-
}))
|
|
429
|
-
},
|
|
430
|
-
{
|
|
431
|
-
type: "list",
|
|
432
|
-
name: "environment",
|
|
433
|
-
message: "Select environment:",
|
|
434
|
-
choices: [
|
|
435
|
-
{ name: "Sandbox (Development)", value: "sandbox" },
|
|
436
|
-
{ name: "Production", value: "production" }
|
|
437
|
-
],
|
|
438
|
-
default: "sandbox"
|
|
439
|
-
}
|
|
440
|
-
]);
|
|
441
|
-
const selectedOrg = organizations.find((org) => org.id === answers.orgId);
|
|
442
|
-
if (!selectedOrg) {
|
|
443
|
-
console.log(import_chalk6.default.red("\u2717 Organization not found"));
|
|
518
|
+
console.log(import_chalk6.default.yellow("\u26A0 You are not logged in."));
|
|
444
519
|
return;
|
|
445
520
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
orgName: selectedOrg.name,
|
|
449
|
-
environment: answers.environment
|
|
450
|
-
});
|
|
451
|
-
console.log(import_chalk6.default.green("\n\u2713 Switched organization successfully!"));
|
|
452
|
-
console.log(import_chalk6.default.dim("\nNew configuration:"));
|
|
453
|
-
console.log(import_chalk6.default.dim(` Organization: ${selectedOrg.name}`));
|
|
454
|
-
console.log(import_chalk6.default.dim(` Environment: ${answers.environment}`));
|
|
455
|
-
console.log(
|
|
456
|
-
import_chalk6.default.dim("\nRun `commet pull` to update TypeScript types for this organization")
|
|
457
|
-
);
|
|
521
|
+
clearAuth();
|
|
522
|
+
console.log(import_chalk6.default.green("\u2713 Successfully logged out"));
|
|
458
523
|
});
|
|
459
524
|
|
|
460
525
|
// src/commands/pull.ts
|
|
461
526
|
var fs2 = __toESM(require("fs"));
|
|
462
527
|
var path2 = __toESM(require("path"));
|
|
463
|
-
var import_commander7 = require("commander");
|
|
464
528
|
var import_chalk7 = __toESM(require("chalk"));
|
|
529
|
+
var import_commander6 = require("commander");
|
|
465
530
|
var import_ora4 = __toESM(require("ora"));
|
|
466
531
|
|
|
467
532
|
// src/utils/generator.ts
|
|
468
533
|
function generateTypes(eventTypes, seatTypes) {
|
|
469
534
|
const eventTypeUnion = eventTypes.length > 0 ? eventTypes.map((e) => `"${e.code}"`).join(" | ") : "string";
|
|
470
535
|
const seatTypeUnion = seatTypes.length > 0 ? seatTypes.map((s) => `"${s.code}"`).join(" | ") : "string";
|
|
471
|
-
const eventComments = eventTypes.map(
|
|
536
|
+
const eventComments = eventTypes.map(
|
|
537
|
+
(e) => ` * - "${e.code}": ${e.name}${e.description ? ` - ${e.description}` : ""}`
|
|
538
|
+
).join("\n");
|
|
472
539
|
const seatComments = seatTypes.map(
|
|
473
540
|
(s) => ` * - "${s.code}": ${s.name}${s.description ? ` - ${s.description}` : ""} ${s.isFree ? "(Free)" : ""}`
|
|
474
541
|
).join("\n");
|
|
@@ -514,11 +581,7 @@ export type CommetSeatType = ${seatTypeUnion};
|
|
|
514
581
|
}
|
|
515
582
|
|
|
516
583
|
// src/commands/pull.ts
|
|
517
|
-
var pullCommand = new
|
|
518
|
-
"-o, --output <file>",
|
|
519
|
-
"Output file path",
|
|
520
|
-
".commet.d.ts"
|
|
521
|
-
).action(async (options) => {
|
|
584
|
+
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) => {
|
|
522
585
|
if (!authExists()) {
|
|
523
586
|
console.log(import_chalk7.default.red("\u2717 Not authenticated"));
|
|
524
587
|
console.log(import_chalk7.default.dim("Run `commet login` first"));
|
|
@@ -526,7 +589,9 @@ var pullCommand = new import_commander7.Command("pull").description("Pull type d
|
|
|
526
589
|
}
|
|
527
590
|
if (!projectConfigExists()) {
|
|
528
591
|
console.log(import_chalk7.default.red("\u2717 Project not linked"));
|
|
529
|
-
console.log(
|
|
592
|
+
console.log(
|
|
593
|
+
import_chalk7.default.dim("Run `commet link` first to connect to an organization")
|
|
594
|
+
);
|
|
530
595
|
return;
|
|
531
596
|
}
|
|
532
597
|
const projectConfig = loadProjectConfig();
|
|
@@ -552,136 +617,147 @@ var pullCommand = new import_commander7.Command("pull").description("Pull type d
|
|
|
552
617
|
console.log(import_chalk7.default.green("\n\u2713 Success"));
|
|
553
618
|
console.log(import_chalk7.default.dim("\nGenerated types:"));
|
|
554
619
|
console.log(
|
|
555
|
-
import_chalk7.default.dim(
|
|
620
|
+
import_chalk7.default.dim(
|
|
621
|
+
` Event types: ${eventTypes.length > 0 ? eventTypes.map((e) => e.code).join(", ") : "none"}`
|
|
622
|
+
)
|
|
556
623
|
);
|
|
557
624
|
console.log(
|
|
558
|
-
import_chalk7.default.dim(
|
|
625
|
+
import_chalk7.default.dim(
|
|
626
|
+
` Seat types: ${seatTypes.length > 0 ? seatTypes.map((s) => s.code).join(", ") : "none"}`
|
|
627
|
+
)
|
|
559
628
|
);
|
|
560
629
|
console.log(import_chalk7.default.dim(`
|
|
561
630
|
Output file: ${outputPath}`));
|
|
562
631
|
if (eventTypes.length === 0 && seatTypes.length === 0) {
|
|
563
632
|
console.log(
|
|
564
|
-
import_chalk7.default.yellow(
|
|
633
|
+
import_chalk7.default.yellow(
|
|
634
|
+
"\n\u26A0 No types found. Create event types and seat types in your Commet dashboard."
|
|
635
|
+
)
|
|
565
636
|
);
|
|
566
637
|
}
|
|
567
638
|
});
|
|
568
639
|
|
|
569
|
-
// src/commands/
|
|
570
|
-
var
|
|
640
|
+
// src/commands/switch.ts
|
|
641
|
+
var import_prompts3 = require("@inquirer/prompts");
|
|
571
642
|
var import_chalk8 = __toESM(require("chalk"));
|
|
643
|
+
var import_commander7 = require("commander");
|
|
572
644
|
var import_ora5 = __toESM(require("ora"));
|
|
573
|
-
var
|
|
574
|
-
if (type !== "events" && type !== "seats") {
|
|
575
|
-
console.log(import_chalk8.default.red('\u2717 Invalid type. Use "events" or "seats"'));
|
|
576
|
-
console.log(import_chalk8.default.dim("\nExamples:"));
|
|
577
|
-
console.log(import_chalk8.default.dim(" commet list events"));
|
|
578
|
-
console.log(import_chalk8.default.dim(" commet list seats"));
|
|
579
|
-
return;
|
|
580
|
-
}
|
|
645
|
+
var switchCommand = new import_commander7.Command("switch").description("Switch to a different organization").action(async () => {
|
|
581
646
|
if (!authExists()) {
|
|
582
647
|
console.log(import_chalk8.default.red("\u2717 Not authenticated"));
|
|
583
648
|
console.log(import_chalk8.default.dim("Run `commet login` first"));
|
|
584
649
|
return;
|
|
585
650
|
}
|
|
586
651
|
if (!projectConfigExists()) {
|
|
587
|
-
console.log(import_chalk8.default.
|
|
588
|
-
console.log(
|
|
652
|
+
console.log(import_chalk8.default.yellow("\u26A0 Project not linked"));
|
|
653
|
+
console.log(
|
|
654
|
+
import_chalk8.default.dim("Run `commet link` first to connect to an organization")
|
|
655
|
+
);
|
|
589
656
|
return;
|
|
590
657
|
}
|
|
591
|
-
const
|
|
592
|
-
|
|
593
|
-
|
|
658
|
+
const spinner = (0, import_ora5.default)("Fetching organizations...").start();
|
|
659
|
+
const auth = loadAuth();
|
|
660
|
+
if (!auth) {
|
|
661
|
+
spinner.fail("Authentication error");
|
|
662
|
+
console.log(import_chalk8.default.red("\u2717 Could not load authentication"));
|
|
594
663
|
return;
|
|
595
664
|
}
|
|
596
|
-
const
|
|
597
|
-
const baseURL = getBaseURL(projectConfig.environment);
|
|
665
|
+
const baseURL = getBaseURL(auth.environment);
|
|
598
666
|
const result = await apiRequest(
|
|
599
|
-
`${baseURL}/api/cli/
|
|
667
|
+
`${baseURL}/api/cli/organizations`
|
|
600
668
|
);
|
|
601
669
|
if (result.error || !result.data) {
|
|
602
|
-
spinner.fail(
|
|
670
|
+
spinner.fail("Failed to fetch organizations");
|
|
603
671
|
console.error(import_chalk8.default.red("Error:"), result.error);
|
|
604
672
|
return;
|
|
605
673
|
}
|
|
674
|
+
const { organizations } = result.data;
|
|
675
|
+
if (organizations.length === 0) {
|
|
676
|
+
spinner.stop();
|
|
677
|
+
console.log(import_chalk8.default.yellow("\u26A0 No organizations found"));
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
606
680
|
spinner.stop();
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
import_chalk8.default.dim(
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
console.log("");
|
|
626
|
-
}
|
|
627
|
-
} else {
|
|
628
|
-
const { seatTypes } = result.data;
|
|
629
|
-
if (seatTypes.length === 0) {
|
|
630
|
-
console.log(import_chalk8.default.yellow("\u26A0 No seat types found"));
|
|
631
|
-
console.log(
|
|
632
|
-
import_chalk8.default.dim("Create seat types in your Commet dashboard first")
|
|
633
|
-
);
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
636
|
-
console.log(import_chalk8.default.bold(`
|
|
637
|
-
\u{1F4BA} Seat Types (${seatTypes.length})
|
|
638
|
-
`));
|
|
639
|
-
for (const seatType of seatTypes) {
|
|
640
|
-
console.log(
|
|
641
|
-
import_chalk8.default.green(`\u2022 ${seatType.code}${seatType.isFree ? " (Free)" : ""}`)
|
|
642
|
-
);
|
|
643
|
-
console.log(import_chalk8.default.dim(` ${seatType.name}`));
|
|
644
|
-
if (seatType.description) {
|
|
645
|
-
console.log(import_chalk8.default.dim(` ${seatType.description}`));
|
|
646
|
-
}
|
|
647
|
-
console.log("");
|
|
648
|
-
}
|
|
681
|
+
let orgId;
|
|
682
|
+
try {
|
|
683
|
+
orgId = await (0, import_prompts3.select)({
|
|
684
|
+
message: "Select organization:",
|
|
685
|
+
choices: organizations.map((org) => ({
|
|
686
|
+
name: `${org.name} ${import_chalk8.default.dim(`(${org.slug})`)}`,
|
|
687
|
+
value: org.id
|
|
688
|
+
})),
|
|
689
|
+
theme: promptTheme
|
|
690
|
+
});
|
|
691
|
+
} catch (error) {
|
|
692
|
+
console.log(import_chalk8.default.yellow("\n\u26A0 Switch cancelled"));
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
const selectedOrg = organizations.find((org) => org.id === orgId);
|
|
696
|
+
if (!selectedOrg) {
|
|
697
|
+
console.log(import_chalk8.default.red("\u2717 Organization not found"));
|
|
698
|
+
return;
|
|
649
699
|
}
|
|
700
|
+
saveProjectConfig({
|
|
701
|
+
orgId: selectedOrg.id,
|
|
702
|
+
orgName: selectedOrg.name,
|
|
703
|
+
environment: auth.environment
|
|
704
|
+
});
|
|
705
|
+
console.log(import_chalk8.default.green("\n\u2713 Switched organization successfully!"));
|
|
706
|
+
console.log(import_chalk8.default.dim("\nNew configuration:"));
|
|
707
|
+
console.log(import_chalk8.default.dim(` Organization: ${selectedOrg.name}`));
|
|
708
|
+
console.log(import_chalk8.default.dim(` Environment: ${auth.environment}`));
|
|
709
|
+
console.log(
|
|
710
|
+
import_chalk8.default.dim(
|
|
711
|
+
"\nRun `commet pull` to update TypeScript types for this organization"
|
|
712
|
+
)
|
|
713
|
+
);
|
|
650
714
|
});
|
|
651
715
|
|
|
652
|
-
// src/commands/
|
|
653
|
-
var import_commander9 = require("commander");
|
|
716
|
+
// src/commands/unlink.ts
|
|
654
717
|
var import_chalk9 = __toESM(require("chalk"));
|
|
655
|
-
var
|
|
656
|
-
|
|
657
|
-
if (!
|
|
658
|
-
console.log(
|
|
659
|
-
|
|
718
|
+
var import_commander8 = require("commander");
|
|
719
|
+
var unlinkCommand = new import_commander8.Command("unlink").description("Unlink this project from Commet").action(async () => {
|
|
720
|
+
if (!projectConfigExists()) {
|
|
721
|
+
console.log(
|
|
722
|
+
import_chalk9.default.yellow("\u26A0 This project is not linked to any organization")
|
|
723
|
+
);
|
|
660
724
|
return;
|
|
661
725
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
726
|
+
clearProjectConfig();
|
|
727
|
+
console.log(import_chalk9.default.green("\u2713 Project unlinked successfully"));
|
|
728
|
+
console.log(import_chalk9.default.dim("Run `commet link` to connect to an organization"));
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
// src/commands/whoami.ts
|
|
732
|
+
var import_chalk10 = __toESM(require("chalk"));
|
|
733
|
+
var import_commander9 = require("commander");
|
|
734
|
+
var whoamiCommand = new import_commander9.Command("whoami").description("Display current authentication and project status").action(async () => {
|
|
735
|
+
if (!authExists()) {
|
|
736
|
+
console.log(import_chalk10.default.yellow("\u26A0 Not logged in"));
|
|
737
|
+
console.log(import_chalk10.default.dim("Run `commet login` to authenticate"));
|
|
666
738
|
return;
|
|
667
739
|
}
|
|
740
|
+
console.log(import_chalk10.default.green("\u2713 Logged in"));
|
|
668
741
|
const projectConfig = loadProjectConfig();
|
|
669
|
-
if (
|
|
670
|
-
console.log(
|
|
671
|
-
|
|
742
|
+
if (projectConfig) {
|
|
743
|
+
console.log(import_chalk10.default.bold("\nProject:"));
|
|
744
|
+
console.log(import_chalk10.default.dim("Organization:"), projectConfig.orgName);
|
|
745
|
+
console.log(import_chalk10.default.dim("Environment:"), projectConfig.environment);
|
|
746
|
+
} else {
|
|
747
|
+
console.log(import_chalk10.default.yellow("\n\u26A0 No project linked"));
|
|
748
|
+
console.log(
|
|
749
|
+
import_chalk10.default.dim(
|
|
750
|
+
"Run `commet link` to connect this directory to an organization"
|
|
751
|
+
)
|
|
752
|
+
);
|
|
672
753
|
}
|
|
673
|
-
console.log(import_chalk9.default.green("\nProject: Linked \u2713"));
|
|
674
|
-
console.log(import_chalk9.default.dim(" Organization:"), projectConfig.orgName);
|
|
675
|
-
console.log(import_chalk9.default.dim(" Organization ID:"), projectConfig.orgId);
|
|
676
|
-
console.log(import_chalk9.default.dim(" Environment:"), projectConfig.environment);
|
|
677
|
-
console.log(
|
|
678
|
-
import_chalk9.default.dim("\nRun `commet pull` to generate type definitions\n")
|
|
679
|
-
);
|
|
680
754
|
});
|
|
681
755
|
|
|
682
756
|
// src/index.ts
|
|
683
757
|
var program = new import_commander10.Command();
|
|
684
|
-
program.name("commet").description(
|
|
758
|
+
program.name("commet").description(
|
|
759
|
+
"Commet CLI - Manage your billing platform from the command line"
|
|
760
|
+
).version("0.3.0");
|
|
685
761
|
program.addCommand(loginCommand);
|
|
686
762
|
program.addCommand(logoutCommand);
|
|
687
763
|
program.addCommand(whoamiCommand);
|
|
@@ -699,7 +775,7 @@ try {
|
|
|
699
775
|
if (error.message.includes("outputHelp")) {
|
|
700
776
|
process.exit(0);
|
|
701
777
|
}
|
|
702
|
-
console.error(
|
|
778
|
+
console.error(import_chalk11.default.red("Error:"), error.message);
|
|
703
779
|
}
|
|
704
780
|
process.exit(1);
|
|
705
781
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commet",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Commet CLI - Manage your billing platform from the command line",
|
|
5
5
|
"bin": {
|
|
6
6
|
"commet": "./bin/commet"
|
|
@@ -19,16 +19,15 @@
|
|
|
19
19
|
"author": "Commet Team",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@inquirer/prompts": "^7.8.6",
|
|
22
23
|
"chalk": "^5.3.0",
|
|
23
24
|
"commander": "^12.0.0",
|
|
24
|
-
"inquirer": "^9.2.0",
|
|
25
25
|
"open": "^10.0.0",
|
|
26
26
|
"ora": "^7.0.1",
|
|
27
27
|
"@commet/node": "0.4.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@biomejs/biome": "^1.9.4",
|
|
31
|
-
"@types/inquirer": "^9.0.9",
|
|
32
31
|
"@types/node": "^20.10.0",
|
|
33
32
|
"tsup": "^8.0.1",
|
|
34
33
|
"typescript": "^5.3.3"
|
|
@@ -38,7 +37,7 @@
|
|
|
38
37
|
},
|
|
39
38
|
"repository": {
|
|
40
39
|
"type": "git",
|
|
41
|
-
"url": "https://github.com/commet-labs/commet
|
|
40
|
+
"url": "https://github.com/commet-labs/commet.git",
|
|
42
41
|
"directory": "packages/cli"
|
|
43
42
|
},
|
|
44
43
|
"publishConfig": {
|