commet 0.4.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 +29 -11
- package/dist/index.js +408 -341
- package/package.json +2 -2
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_commander10 = require("commander");
|
|
28
27
|
var import_chalk10 = __toESM(require("chalk"));
|
|
28
|
+
var import_commander10 = require("commander");
|
|
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_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
|
+
|
|
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,213 @@ async function apiRequest(endpoint, options = {}) {
|
|
|
131
165
|
}
|
|
132
166
|
}
|
|
133
167
|
|
|
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
|
+
});
|
|
255
|
+
|
|
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
|
+
}
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
|
|
134
341
|
// src/commands/login.ts
|
|
135
|
-
var
|
|
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 () => {
|
|
136
348
|
if (authExists()) {
|
|
137
349
|
const auth = loadAuth();
|
|
138
|
-
console.log(
|
|
350
|
+
console.log(import_chalk4.default.yellow("\u26A0 You are already logged in."));
|
|
139
351
|
console.log(
|
|
140
|
-
|
|
352
|
+
import_chalk4.default.dim(
|
|
353
|
+
"Run `commet logout` first if you want to login with a different account."
|
|
354
|
+
)
|
|
141
355
|
);
|
|
142
356
|
return;
|
|
143
357
|
}
|
|
144
|
-
const
|
|
145
|
-
|
|
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);
|
|
146
375
|
try {
|
|
147
376
|
const deviceResponse = await fetch(`${baseURL}/api/auth/device/code`, {
|
|
148
377
|
method: "POST",
|
|
@@ -154,7 +383,7 @@ var loginCommand = new import_commander.Command("login").description("Authentica
|
|
|
154
383
|
});
|
|
155
384
|
if (!deviceResponse.ok) {
|
|
156
385
|
spinner.fail("Failed to initiate login");
|
|
157
|
-
console.error(
|
|
386
|
+
console.error(import_chalk4.default.red("Error:"), await deviceResponse.text());
|
|
158
387
|
return;
|
|
159
388
|
}
|
|
160
389
|
const deviceData = await deviceResponse.json();
|
|
@@ -165,42 +394,46 @@ var loginCommand = new import_commander.Command("login").description("Authentica
|
|
|
165
394
|
interval = 5
|
|
166
395
|
} = deviceData;
|
|
167
396
|
spinner.stop();
|
|
168
|
-
console.log(
|
|
397
|
+
console.log(import_chalk4.default.bold("\n\u{1F510} Commet CLI Login\n"));
|
|
169
398
|
console.log("Visit the following URL in your browser:");
|
|
170
|
-
console.log(
|
|
399
|
+
console.log(import_chalk4.default.cyan.underline(verification_uri_complete));
|
|
171
400
|
console.log("\nOr enter this code manually:");
|
|
172
|
-
console.log(
|
|
173
|
-
console.log(
|
|
401
|
+
console.log(import_chalk4.default.bold.green(` ${user_code}`));
|
|
402
|
+
console.log(import_chalk4.default.dim("\nOpening browser...\n"));
|
|
174
403
|
try {
|
|
175
404
|
await (0, import_open.default)(verification_uri_complete);
|
|
176
405
|
} catch {
|
|
177
|
-
console.log(
|
|
406
|
+
console.log(import_chalk4.default.yellow("\u26A0 Could not open browser automatically."));
|
|
178
407
|
}
|
|
179
|
-
const pollSpinner = (0,
|
|
408
|
+
const pollSpinner = (0, import_ora3.default)("Waiting for authorization...").start();
|
|
180
409
|
let pollingInterval = interval;
|
|
181
410
|
let attempts = 0;
|
|
182
411
|
const maxAttempts = 180 / pollingInterval;
|
|
183
412
|
const poll = async () => {
|
|
184
413
|
if (attempts >= maxAttempts) {
|
|
185
414
|
pollSpinner.fail("Login timed out");
|
|
186
|
-
console.log(
|
|
415
|
+
console.log(import_chalk4.default.red("Authorization timed out. Please try again."));
|
|
187
416
|
return;
|
|
188
417
|
}
|
|
189
418
|
attempts++;
|
|
190
419
|
try {
|
|
191
|
-
const tokenResponse = await fetch(
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
+
}
|
|
431
|
+
);
|
|
200
432
|
const tokenData = await tokenResponse.json();
|
|
201
433
|
if (tokenData.access_token) {
|
|
202
434
|
const authConfig = {
|
|
203
|
-
token: tokenData.access_token
|
|
435
|
+
token: tokenData.access_token,
|
|
436
|
+
environment
|
|
204
437
|
};
|
|
205
438
|
if (tokenData.refresh_token) {
|
|
206
439
|
authConfig.refreshToken = tokenData.refresh_token;
|
|
@@ -210,9 +443,11 @@ var loginCommand = new import_commander.Command("login").description("Authentica
|
|
|
210
443
|
}
|
|
211
444
|
saveAuth(authConfig);
|
|
212
445
|
pollSpinner.succeed("Successfully logged in!");
|
|
213
|
-
console.log(
|
|
446
|
+
console.log(import_chalk4.default.green("\n\u2713 Authentication complete"));
|
|
214
447
|
console.log(
|
|
215
|
-
|
|
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
|
+
)
|
|
216
451
|
);
|
|
217
452
|
return;
|
|
218
453
|
}
|
|
@@ -223,23 +458,28 @@ var loginCommand = new import_commander.Command("login").description("Authentica
|
|
|
223
458
|
setTimeout(() => poll(), pollingInterval * 1e3);
|
|
224
459
|
} else if (tokenData.error === "access_denied") {
|
|
225
460
|
pollSpinner.fail("Authorization denied");
|
|
226
|
-
console.log(
|
|
227
|
-
import_chalk.default.red("\n\u2717 You denied the authorization request.")
|
|
228
|
-
);
|
|
461
|
+
console.log(import_chalk4.default.red("\n\u2717 You denied the authorization request."));
|
|
229
462
|
return;
|
|
230
463
|
} else if (tokenData.error === "expired_token") {
|
|
231
464
|
pollSpinner.fail("Code expired");
|
|
232
|
-
console.log(
|
|
465
|
+
console.log(
|
|
466
|
+
import_chalk4.default.red(
|
|
467
|
+
"\n\u2717 The authorization code expired. Please try again."
|
|
468
|
+
)
|
|
469
|
+
);
|
|
233
470
|
return;
|
|
234
471
|
} else {
|
|
235
472
|
pollSpinner.fail("Authorization failed");
|
|
236
|
-
console.log(
|
|
473
|
+
console.log(
|
|
474
|
+
import_chalk4.default.red("\n\u2717 Error:"),
|
|
475
|
+
tokenData.error || "Unknown error"
|
|
476
|
+
);
|
|
237
477
|
return;
|
|
238
478
|
}
|
|
239
479
|
} catch (error) {
|
|
240
480
|
pollSpinner.fail("Network error");
|
|
241
481
|
console.error(
|
|
242
|
-
|
|
482
|
+
import_chalk4.default.red("Error:"),
|
|
243
483
|
error instanceof Error ? error.message : "Unknown error"
|
|
244
484
|
);
|
|
245
485
|
}
|
|
@@ -248,227 +488,38 @@ var loginCommand = new import_commander.Command("login").description("Authentica
|
|
|
248
488
|
} catch (error) {
|
|
249
489
|
spinner.fail("Login failed");
|
|
250
490
|
console.error(
|
|
251
|
-
|
|
491
|
+
import_chalk4.default.red("Error:"),
|
|
252
492
|
error instanceof Error ? error.message : "Unknown error"
|
|
253
493
|
);
|
|
254
494
|
}
|
|
255
495
|
});
|
|
256
496
|
|
|
257
497
|
// 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
498
|
var import_chalk5 = __toESM(require("chalk"));
|
|
375
|
-
var
|
|
376
|
-
|
|
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
|
-
var import_chalk6 = __toESM(require("chalk"));
|
|
388
|
-
var import_inquirer2 = __toESM(require("inquirer"));
|
|
389
|
-
var import_ora3 = __toESM(require("ora"));
|
|
390
|
-
var switchCommand = new import_commander6.Command("switch").description("Switch to a different organization").action(async () => {
|
|
499
|
+
var import_commander5 = require("commander");
|
|
500
|
+
var logoutCommand = new import_commander5.Command("logout").description("Log out of Commet").action(async () => {
|
|
391
501
|
if (!authExists()) {
|
|
392
|
-
console.log(
|
|
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);
|
|
502
|
+
console.log(import_chalk5.default.yellow("\u26A0 You are not logged in."));
|
|
411
503
|
return;
|
|
412
504
|
}
|
|
413
|
-
|
|
414
|
-
|
|
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"));
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
saveProjectConfig({
|
|
447
|
-
orgId: selectedOrg.id,
|
|
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
|
-
);
|
|
505
|
+
clearAuth();
|
|
506
|
+
console.log(import_chalk5.default.green("\u2713 Successfully logged out"));
|
|
458
507
|
});
|
|
459
508
|
|
|
460
509
|
// src/commands/pull.ts
|
|
461
510
|
var fs2 = __toESM(require("fs"));
|
|
462
511
|
var path2 = __toESM(require("path"));
|
|
463
|
-
var
|
|
464
|
-
var
|
|
512
|
+
var import_chalk6 = __toESM(require("chalk"));
|
|
513
|
+
var import_commander6 = require("commander");
|
|
465
514
|
var import_ora4 = __toESM(require("ora"));
|
|
466
515
|
|
|
467
516
|
// src/utils/generator.ts
|
|
468
517
|
function generateTypes(eventTypes, seatTypes) {
|
|
469
518
|
const eventTypeUnion = eventTypes.length > 0 ? eventTypes.map((e) => `"${e.code}"`).join(" | ") : "string";
|
|
470
519
|
const seatTypeUnion = seatTypes.length > 0 ? seatTypes.map((s) => `"${s.code}"`).join(" | ") : "string";
|
|
471
|
-
const eventComments = eventTypes.map(
|
|
520
|
+
const eventComments = eventTypes.map(
|
|
521
|
+
(e) => ` * - "${e.code}": ${e.name}${e.description ? ` - ${e.description}` : ""}`
|
|
522
|
+
).join("\n");
|
|
472
523
|
const seatComments = seatTypes.map(
|
|
473
524
|
(s) => ` * - "${s.code}": ${s.name}${s.description ? ` - ${s.description}` : ""} ${s.isFree ? "(Free)" : ""}`
|
|
474
525
|
).join("\n");
|
|
@@ -514,24 +565,22 @@ export type CommetSeatType = ${seatTypeUnion};
|
|
|
514
565
|
}
|
|
515
566
|
|
|
516
567
|
// src/commands/pull.ts
|
|
517
|
-
var pullCommand = new
|
|
518
|
-
"-o, --output <file>",
|
|
519
|
-
"Output file path",
|
|
520
|
-
".commet.d.ts"
|
|
521
|
-
).action(async (options) => {
|
|
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) => {
|
|
522
569
|
if (!authExists()) {
|
|
523
|
-
console.log(
|
|
524
|
-
console.log(
|
|
570
|
+
console.log(import_chalk6.default.red("\u2717 Not authenticated"));
|
|
571
|
+
console.log(import_chalk6.default.dim("Run `commet login` first"));
|
|
525
572
|
return;
|
|
526
573
|
}
|
|
527
574
|
if (!projectConfigExists()) {
|
|
528
|
-
console.log(
|
|
529
|
-
console.log(
|
|
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
|
+
);
|
|
530
579
|
return;
|
|
531
580
|
}
|
|
532
581
|
const projectConfig = loadProjectConfig();
|
|
533
582
|
if (!projectConfig) {
|
|
534
|
-
console.log(
|
|
583
|
+
console.log(import_chalk6.default.red("\u2717 Invalid project configuration"));
|
|
535
584
|
return;
|
|
536
585
|
}
|
|
537
586
|
const spinner = (0, import_ora4.default)("Fetching type definitions...").start();
|
|
@@ -541,7 +590,7 @@ var pullCommand = new import_commander7.Command("pull").description("Pull type d
|
|
|
541
590
|
);
|
|
542
591
|
if (result.error || !result.data) {
|
|
543
592
|
spinner.fail("Failed to fetch types");
|
|
544
|
-
console.error(
|
|
593
|
+
console.error(import_chalk6.default.red("Error:"), result.error);
|
|
545
594
|
return;
|
|
546
595
|
}
|
|
547
596
|
const { eventTypes, seatTypes } = result.data;
|
|
@@ -549,139 +598,157 @@ var pullCommand = new import_commander7.Command("pull").description("Pull type d
|
|
|
549
598
|
const outputPath = path2.resolve(process.cwd(), options.output);
|
|
550
599
|
fs2.writeFileSync(outputPath, typeDefinitions, "utf8");
|
|
551
600
|
spinner.succeed("Type definitions generated!");
|
|
552
|
-
console.log(
|
|
553
|
-
console.log(
|
|
601
|
+
console.log(import_chalk6.default.green("\n\u2713 Success"));
|
|
602
|
+
console.log(import_chalk6.default.dim("\nGenerated types:"));
|
|
554
603
|
console.log(
|
|
555
|
-
|
|
604
|
+
import_chalk6.default.dim(
|
|
605
|
+
` Event types: ${eventTypes.length > 0 ? eventTypes.map((e) => e.code).join(", ") : "none"}`
|
|
606
|
+
)
|
|
556
607
|
);
|
|
557
608
|
console.log(
|
|
558
|
-
|
|
609
|
+
import_chalk6.default.dim(
|
|
610
|
+
` Seat types: ${seatTypes.length > 0 ? seatTypes.map((s) => s.code).join(", ") : "none"}`
|
|
611
|
+
)
|
|
559
612
|
);
|
|
560
|
-
console.log(
|
|
613
|
+
console.log(import_chalk6.default.dim(`
|
|
561
614
|
Output file: ${outputPath}`));
|
|
562
615
|
if (eventTypes.length === 0 && seatTypes.length === 0) {
|
|
563
616
|
console.log(
|
|
564
|
-
|
|
617
|
+
import_chalk6.default.yellow(
|
|
618
|
+
"\n\u26A0 No types found. Create event types and seat types in your Commet dashboard."
|
|
619
|
+
)
|
|
565
620
|
);
|
|
566
621
|
}
|
|
567
622
|
});
|
|
568
623
|
|
|
569
|
-
// src/commands/
|
|
570
|
-
var
|
|
571
|
-
var
|
|
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"));
|
|
572
628
|
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
|
-
}
|
|
629
|
+
var switchCommand = new import_commander7.Command("switch").description("Switch to a different organization").action(async () => {
|
|
581
630
|
if (!authExists()) {
|
|
582
|
-
console.log(
|
|
583
|
-
console.log(
|
|
631
|
+
console.log(import_chalk7.default.red("\u2717 Not authenticated"));
|
|
632
|
+
console.log(import_chalk7.default.dim("Run `commet login` first"));
|
|
584
633
|
return;
|
|
585
634
|
}
|
|
586
635
|
if (!projectConfigExists()) {
|
|
587
|
-
console.log(
|
|
588
|
-
console.log(
|
|
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
|
+
);
|
|
589
640
|
return;
|
|
590
641
|
}
|
|
591
|
-
const
|
|
592
|
-
|
|
593
|
-
|
|
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"));
|
|
594
647
|
return;
|
|
595
648
|
}
|
|
596
|
-
const
|
|
597
|
-
const baseURL = getBaseURL(projectConfig.environment);
|
|
649
|
+
const baseURL = getBaseURL(auth.environment);
|
|
598
650
|
const result = await apiRequest(
|
|
599
|
-
`${baseURL}/api/cli/
|
|
651
|
+
`${baseURL}/api/cli/organizations`
|
|
600
652
|
);
|
|
601
653
|
if (result.error || !result.data) {
|
|
602
|
-
spinner.fail(
|
|
603
|
-
console.error(
|
|
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"));
|
|
604
662
|
return;
|
|
605
663
|
}
|
|
606
664
|
spinner.stop();
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
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("");
|
|
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"
|
|
648
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;
|
|
649
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
|
+
);
|
|
650
705
|
});
|
|
651
706
|
|
|
652
|
-
// src/commands/
|
|
653
|
-
var
|
|
654
|
-
var
|
|
655
|
-
var
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
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
|
+
);
|
|
660
715
|
return;
|
|
661
716
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
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"));
|
|
666
729
|
return;
|
|
667
730
|
}
|
|
731
|
+
console.log(import_chalk9.default.green("\u2713 Logged in"));
|
|
668
732
|
const projectConfig = loadProjectConfig();
|
|
669
|
-
if (
|
|
670
|
-
console.log(import_chalk9.default.
|
|
671
|
-
|
|
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
|
+
);
|
|
672
744
|
}
|
|
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
745
|
});
|
|
681
746
|
|
|
682
747
|
// src/index.ts
|
|
683
748
|
var program = new import_commander10.Command();
|
|
684
|
-
program.name("commet").description(
|
|
749
|
+
program.name("commet").description(
|
|
750
|
+
"Commet CLI - Manage your billing platform from the command line"
|
|
751
|
+
).version("0.3.0");
|
|
685
752
|
program.addCommand(loginCommand);
|
|
686
753
|
program.addCommand(logoutCommand);
|
|
687
754
|
program.addCommand(whoamiCommand);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commet",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Commet CLI - Manage your billing platform from the command line",
|
|
5
5
|
"bin": {
|
|
6
6
|
"commet": "./bin/commet"
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"repository": {
|
|
40
40
|
"type": "git",
|
|
41
|
-
"url": "https://github.com/commet-labs/commet
|
|
41
|
+
"url": "https://github.com/commet-labs/commet.git",
|
|
42
42
|
"directory": "packages/cli"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|