@miketromba/loops-cli 0.1.0 → 0.1.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.
Files changed (3) hide show
  1. package/README.md +171 -20
  2. package/dist/loops.js +24 -24
  3. package/package.json +5 -1
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img src="assets/banner.png" alt="loops-cli banner" width="100%" />
2
+ <img src="https://raw.githubusercontent.com/miketromba/loops-cli/main/assets/banner.png" alt="loops-cli banner" width="100%" />
3
3
  </p>
4
4
 
5
5
  <p align="center">
@@ -14,29 +14,49 @@ Optimized for both developers and AI agents with multiple output formats.
14
14
 
15
15
  > **Unofficial** — this project is not affiliated with or endorsed by Loops. It is a community-built tool powered by the official TypeScript SDK.
16
16
 
17
- ## Install
17
+ ## Getting Started
18
+
19
+ Install the CLI, then give your AI assistant the skill to use it:
18
20
 
19
21
  ```bash
20
22
  npm install -g @miketromba/loops-cli
23
+ npx skills add miketromba/loops-cli
21
24
  ```
22
25
 
23
- Or use without installing:
26
+ That's it. Your AI assistant now knows how to manage your Loops contacts, send events, transactional emails, and more — just ask it naturally.
27
+
28
+ ### Other package managers
24
29
 
25
30
  ```bash
26
- npx @miketromba/loops-cli --help
31
+ # yarn
32
+ yarn global add @miketromba/loops-cli
33
+
34
+ # pnpm
35
+ pnpm add -g @miketromba/loops-cli
36
+
37
+ # bun
38
+ bun install -g @miketromba/loops-cli
39
+
40
+ # or run without installing
41
+ npx @miketromba/loops-cli contacts find --email user@example.com
27
42
  ```
28
43
 
44
+ Works with Node.js 18+.
45
+
29
46
  ## Quick start
30
47
 
31
48
  ```bash
32
49
  # Authenticate
33
50
  loops auth login --api-key <your-api-key>
34
51
 
52
+ # Create a contact
53
+ loops contacts create --email user@example.com --properties '{"firstName":"Jane"}'
54
+
35
55
  # Find a contact
36
56
  loops contacts find --email user@example.com
37
57
 
38
- # Create a contact
39
- loops contacts create --email user@example.com --properties '{"firstName":"Jane"}'
58
+ # Update a contact
59
+ loops contacts update --email user@example.com --properties '{"firstName":"Updated"}'
40
60
 
41
61
  # Send an event
42
62
  loops events send --email user@example.com --event-name signup
@@ -46,6 +66,9 @@ loops mailing-lists list
46
66
 
47
67
  # Send a transactional email
48
68
  loops transactional send --transactional-id txn_123 --email user@example.com --data-variables '{"name":"Jane"}'
69
+
70
+ # Delete a contact
71
+ loops contacts delete --email user@example.com
49
72
  ```
50
73
 
51
74
  ## Authentication
@@ -53,38 +76,154 @@ loops transactional send --transactional-id txn_123 --email user@example.com --d
53
76
  Get your API key at [Settings > API](https://app.loops.so/settings?page=api).
54
77
 
55
78
  ```bash
56
- # Store locally
79
+ # Store locally (~/.loops-cli/credentials.json)
57
80
  loops auth login --api-key <your-api-key>
58
81
 
59
- # Or use environment variable
82
+ # Or use environment variable (preferred for CI/scripts/agents)
60
83
  export LOOPS_API_KEY=your_api_key_here
84
+
85
+ # Check auth status
86
+ loops auth status
61
87
  ```
62
88
 
63
89
  ## Commands
64
90
 
65
- | Command | Description |
66
- |---------|-------------|
67
- | `contacts` | Create, update, find, delete contacts |
68
- | `contact-properties` | List and create custom contact properties |
69
- | `mailing-lists` | List mailing lists |
70
- | `events` | Send events to trigger email workflows |
71
- | `transactional` | List and send transactional emails |
72
- | `api-key` | Test API key validity |
73
- | `auth` | Login, logout, check auth status |
74
- | `config` | CLI configuration management |
91
+ ### contacts
92
+
93
+ Manage contacts in your Loops audience.
94
+
95
+ | Subcommand | Description |
96
+ |-----------|-------------|
97
+ | `contacts create` | Create a new contact |
98
+ | `contacts update` | Update an existing contact |
99
+ | `contacts find` | Find a contact by email or user ID |
100
+ | `contacts delete` | Delete a contact by email or user ID |
101
+
102
+ ```bash
103
+ loops contacts create --email user@example.com --properties '{"firstName":"Jane","lastName":"Doe"}'
104
+ loops contacts create --email user@example.com --mailing-lists '{"list_id":true}'
105
+ loops contacts update --email user@example.com --properties '{"plan":"pro"}'
106
+ loops contacts update --user-id usr_123 --properties '{"firstName":"Updated"}'
107
+ loops contacts find --email user@example.com
108
+ loops contacts find --user-id usr_123
109
+ loops contacts delete --email user@example.com
110
+ ```
111
+
112
+ ### contact-properties
113
+
114
+ Manage custom contact properties.
115
+
116
+ | Subcommand | Description |
117
+ |-----------|-------------|
118
+ | `contact-properties list` | List all contact properties |
119
+ | `contact-properties create` | Create a new property |
120
+
121
+ ```bash
122
+ loops contact-properties list
123
+ loops contact-properties create --name favoriteColor --type string
124
+ ```
125
+
126
+ ### mailing-lists
127
+
128
+ View mailing lists.
129
+
130
+ ```bash
131
+ loops mailing-lists list
132
+ loops mailing-lists list -o json
133
+ ```
134
+
135
+ ### events
136
+
137
+ Send events to trigger automated email workflows.
138
+
139
+ ```bash
140
+ loops events send --email user@example.com --event-name signup
141
+ loops events send --email user@example.com --event-name purchase --event-properties '{"plan":"pro","amount":29}'
142
+ loops events send --email user@example.com --event-name signup --contact-properties '{"firstName":"Jane"}'
143
+ ```
144
+
145
+ ### transactional
146
+
147
+ Send and manage transactional emails.
148
+
149
+ | Subcommand | Description |
150
+ |-----------|-------------|
151
+ | `transactional list` | List all transactional email templates |
152
+ | `transactional send` | Send a transactional email |
153
+
154
+ ```bash
155
+ loops transactional list
156
+ loops transactional send --transactional-id txn_123 --email user@example.com
157
+ loops transactional send --transactional-id txn_123 --email user@example.com --data-variables '{"name":"Jane","url":"https://example.com"}'
158
+ loops transactional send --transactional-id txn_123 --email user@example.com --add-to-audience
159
+ ```
160
+
161
+ ### api-key
162
+
163
+ ```bash
164
+ loops api-key test
165
+ ```
166
+
167
+ ### auth
168
+
169
+ ```bash
170
+ loops auth login --api-key <your-api-key>
171
+ loops auth status
172
+ loops auth logout
173
+ ```
174
+
175
+ ### config
176
+
177
+ ```bash
178
+ loops config list
179
+ loops config get output
180
+ loops config set output compact
181
+ loops config reset
182
+ ```
75
183
 
76
184
  ## Output formats
77
185
 
78
186
  Auto-detects TTY for human-readable output, pipes for agent-optimized output.
79
187
 
188
+ | Format | Flag | Use case |
189
+ |--------|------|----------|
190
+ | table | `-o table` | Human-readable (TTY default) |
191
+ | compact | `-o compact` | AI agents, scripting (piped default) |
192
+ | json | `-o json` | Programmatic consumption |
193
+ | jsonl | `-o jsonl` | Streaming, `jq` pipelines |
194
+ | csv | `-o csv` | Export, spreadsheets |
195
+ | tsv | `-o tsv` | Unix tools (`cut`, `awk`) |
196
+ | id | `-o id` | Pipe IDs to other commands |
197
+ | count | `-o count` | "How many?" queries |
198
+
80
199
  ```bash
81
200
  loops mailing-lists list # table (TTY) or compact (piped)
82
201
  loops mailing-lists list -o json # JSON
83
202
  loops mailing-lists list -o csv # CSV
203
+ loops contacts find --email user@example.com -o jsonl | jq '.firstName'
84
204
  loops mailing-lists list -o id # IDs only
85
205
  loops mailing-lists list -o count # count only
86
206
  ```
87
207
 
208
+ ## Global flags
209
+
210
+ | Flag | Short | Description |
211
+ |------|-------|-------------|
212
+ | `--output <format>` | `-o` | Output format |
213
+ | `--fields <list>` | `-f` | Comma-separated field selection |
214
+ | `--detail` | `-d` | Full detail view (all fields) |
215
+ | `--no-color` | | Disable color output |
216
+ | `--verbose` | | Debug output to stderr |
217
+ | `--quiet` | `-q` | Data only, no hints or headers |
218
+ | `--yes` | `-y` | Skip confirmation prompts |
219
+
220
+ ## Environment variables
221
+
222
+ | Variable | Purpose |
223
+ |----------|---------|
224
+ | `LOOPS_API_KEY` | API key (overrides stored credential) |
225
+ | `LOOPS_OUTPUT` | Default output format |
226
+
88
227
  ## AI agent usage
89
228
 
90
229
  The CLI is optimized for AI agents with compact output format:
@@ -97,13 +236,25 @@ mailingLists 1-2/2 page=1
97
236
 
98
237
  Set `LOOPS_API_KEY` and pipe commands for minimal-token responses.
99
238
 
239
+ ```bash
240
+ # Get all mailing list IDs
241
+ loops mailing-lists list -o id
242
+
243
+ # Count contacts matching criteria
244
+ loops contact-properties list -o count
245
+
246
+ # Export as JSON
247
+ loops mailing-lists list -o json > lists.json
248
+ ```
249
+
100
250
  ## Development
101
251
 
102
252
  ```bash
103
253
  bun install
104
254
  bun run dev -- --help
105
- bun test
106
- bun run build
255
+ bun test # unit + integration (143 tests)
256
+ LOOPS_API_KEY=<key> bun run test:e2e # live API tests (32 tests)
257
+ bun run build # bundle to dist/loops.js
107
258
  ```
108
259
 
109
260
  ## License
package/dist/loops.js CHANGED
@@ -1,19 +1,19 @@
1
1
  #!/usr/bin/env node
2
2
  // @bun
3
- import{createRequire as k0}from"node:module";var I0=Object.create;var{getPrototypeOf:E0,defineProperty:W$,getOwnPropertyNames:N0}=Object;var w0=Object.prototype.hasOwnProperty;var F0=($,J,f)=>{f=$!=null?I0(E0($)):{};let R=J||!$||!$.__esModule?W$(f,"default",{value:$,enumerable:!0}):f;for(let T of N0($))if(!w0.call(R,T))W$(R,T,{get:()=>$[T],enumerable:!0});return R};var V=($,J)=>()=>(J||$((J={exports:{}}).exports,J),J.exports);var O=k0(import.meta.url);var A=V((O0)=>{class r extends Error{constructor($,J,f){super(f);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=J,this.exitCode=$,this.nestedError=void 0}}class V$ extends r{constructor($){super(1,"commander.invalidArgument",$);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}O0.CommanderError=r;O0.InvalidArgumentError=V$});var u=V((C0)=>{var{InvalidArgumentError:y0}=A();class D${constructor($,J){switch(this.description=J||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,$[0]){case"<":this.required=!0,this._name=$.slice(1,-1);break;case"[":this.required=!1,this._name=$.slice(1,-1);break;default:this.required=!0,this._name=$;break}if(this._name.endsWith("..."))this.variadic=!0,this._name=this._name.slice(0,-3)}name(){return this._name}_collectValue($,J){if(J===this.defaultValue||!Array.isArray(J))return[$];return J.push($),J}default($,J){return this.defaultValue=$,this.defaultValueDescription=J,this}argParser($){return this.parseArg=$,this}choices($){return this.argChoices=$.slice(),this.parseArg=(J,f)=>{if(!this.argChoices.includes(J))throw new y0(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(J,f);return J},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}}function b0($){let J=$.name()+($.variadic===!0?"...":"");return $.required?"<"+J+">":"["+J+"]"}C0.Argument=D$;C0.humanReadableArgName=b0});var e=V((c0)=>{var{humanReadableArgName:u0}=u();class I${constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext($){this.helpWidth=this.helpWidth??$.helpWidth??80}visibleCommands($){let J=$.commands.filter((R)=>!R._hidden),f=$._getHelpCommand();if(f&&!f._hidden)J.push(f);if(this.sortSubcommands)J.sort((R,T)=>{return R.name().localeCompare(T.name())});return J}compareOptions($,J){let f=(R)=>{return R.short?R.short.replace(/^-/,""):R.long.replace(/^--/,"")};return f($).localeCompare(f(J))}visibleOptions($){let J=$.options.filter((R)=>!R.hidden),f=$._getHelpOption();if(f&&!f.hidden){let R=f.short&&$._findOption(f.short),T=f.long&&$._findOption(f.long);if(!R&&!T)J.push(f);else if(f.long&&!T)J.push($.createOption(f.long,f.description));else if(f.short&&!R)J.push($.createOption(f.short,f.description))}if(this.sortOptions)J.sort(this.compareOptions);return J}visibleGlobalOptions($){if(!this.showGlobalOptions)return[];let J=[];for(let f=$.parent;f;f=f.parent){let R=f.options.filter((T)=>!T.hidden);J.push(...R)}if(this.sortOptions)J.sort(this.compareOptions);return J}visibleArguments($){if($._argsDescription)$.registeredArguments.forEach((J)=>{J.description=J.description||$._argsDescription[J.name()]||""});if($.registeredArguments.find((J)=>J.description))return $.registeredArguments;return[]}subcommandTerm($){let J=$.registeredArguments.map((f)=>u0(f)).join(" ");return $._name+($._aliases[0]?"|"+$._aliases[0]:"")+($.options.length?" [options]":"")+(J?" "+J:"")}optionTerm($){return $.flags}argumentTerm($){return $.name()}longestSubcommandTermLength($,J){return J.visibleCommands($).reduce((f,R)=>{return Math.max(f,this.displayWidth(J.styleSubcommandTerm(J.subcommandTerm(R))))},0)}longestOptionTermLength($,J){return J.visibleOptions($).reduce((f,R)=>{return Math.max(f,this.displayWidth(J.styleOptionTerm(J.optionTerm(R))))},0)}longestGlobalOptionTermLength($,J){return J.visibleGlobalOptions($).reduce((f,R)=>{return Math.max(f,this.displayWidth(J.styleOptionTerm(J.optionTerm(R))))},0)}longestArgumentTermLength($,J){return J.visibleArguments($).reduce((f,R)=>{return Math.max(f,this.displayWidth(J.styleArgumentTerm(J.argumentTerm(R))))},0)}commandUsage($){let J=$._name;if($._aliases[0])J=J+"|"+$._aliases[0];let f="";for(let R=$.parent;R;R=R.parent)f=R.name()+" "+f;return f+J+" "+$.usage()}commandDescription($){return $.description()}subcommandDescription($){return $.summary()||$.description()}optionDescription($){let J=[];if($.argChoices)J.push(`choices: ${$.argChoices.map((f)=>JSON.stringify(f)).join(", ")}`);if($.defaultValue!==void 0){if($.required||$.optional||$.isBoolean()&&typeof $.defaultValue==="boolean")J.push(`default: ${$.defaultValueDescription||JSON.stringify($.defaultValue)}`)}if($.presetArg!==void 0&&$.optional)J.push(`preset: ${JSON.stringify($.presetArg)}`);if($.envVar!==void 0)J.push(`env: ${$.envVar}`);if(J.length>0){let f=`(${J.join(", ")})`;if($.description)return`${$.description} ${f}`;return f}return $.description}argumentDescription($){let J=[];if($.argChoices)J.push(`choices: ${$.argChoices.map((f)=>JSON.stringify(f)).join(", ")}`);if($.defaultValue!==void 0)J.push(`default: ${$.defaultValueDescription||JSON.stringify($.defaultValue)}`);if(J.length>0){let f=`(${J.join(", ")})`;if($.description)return`${$.description} ${f}`;return f}return $.description}formatItemList($,J,f){if(J.length===0)return[];return[f.styleTitle($),...J,""]}groupItems($,J,f){let R=new Map;return $.forEach((T)=>{let q=f(T);if(!R.has(q))R.set(q,[])}),J.forEach((T)=>{let q=f(T);if(!R.has(q))R.set(q,[]);R.get(q).push(T)}),R}formatHelp($,J){let f=J.padWidth($,J),R=J.helpWidth??80;function T(Q,G){return J.formatItem(Q,f,G,J)}let q=[`${J.styleTitle("Usage:")} ${J.styleUsage(J.commandUsage($))}`,""],X=J.commandDescription($);if(X.length>0)q=q.concat([J.boxWrap(J.styleCommandDescription(X),R),""]);let z=J.visibleArguments($).map((Q)=>{return T(J.styleArgumentTerm(J.argumentTerm(Q)),J.styleArgumentDescription(J.argumentDescription(Q)))});if(q=q.concat(this.formatItemList("Arguments:",z,J)),this.groupItems($.options,J.visibleOptions($),(Q)=>Q.helpGroupHeading??"Options:").forEach((Q,G)=>{let S=Q.map((B)=>{return T(J.styleOptionTerm(J.optionTerm(B)),J.styleOptionDescription(J.optionDescription(B)))});q=q.concat(this.formatItemList(G,S,J))}),J.showGlobalOptions){let Q=J.visibleGlobalOptions($).map((G)=>{return T(J.styleOptionTerm(J.optionTerm(G)),J.styleOptionDescription(J.optionDescription(G)))});q=q.concat(this.formatItemList("Global Options:",Q,J))}return this.groupItems($.commands,J.visibleCommands($),(Q)=>Q.helpGroup()||"Commands:").forEach((Q,G)=>{let S=Q.map((B)=>{return T(J.styleSubcommandTerm(J.subcommandTerm(B)),J.styleSubcommandDescription(J.subcommandDescription(B)))});q=q.concat(this.formatItemList(G,S,J))}),q.join(`
3
+ import{createRequire as x0}from"node:module";var I0=Object.create;var{getPrototypeOf:E0,defineProperty:W$,getOwnPropertyNames:N0}=Object;var w0=Object.prototype.hasOwnProperty;function F0($){return this[$]}var k0,O0,A0=($,J,f)=>{var R=$!=null&&typeof $==="object";if(R){var T=J?k0??=new WeakMap:O0??=new WeakMap,q=T.get($);if(q)return q}f=$!=null?I0(E0($)):{};let X=J||!$||!$.__esModule?W$(f,"default",{value:$,enumerable:!0}):f;for(let z of N0($))if(!w0.call(X,z))W$(X,z,{get:F0.bind($,z),enumerable:!0});if(R)T.set($,X);return X};var V=($,J)=>()=>(J||$((J={exports:{}}).exports,J),J.exports);var O=x0(import.meta.url);var A=V((y0)=>{class r extends Error{constructor($,J,f){super(f);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=J,this.exitCode=$,this.nestedError=void 0}}class V$ extends r{constructor($){super(1,"commander.invalidArgument",$);Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}y0.CommanderError=r;y0.InvalidArgumentError=V$});var u=V((u0)=>{var{InvalidArgumentError:h0}=A();class D${constructor($,J){switch(this.description=J||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,$[0]){case"<":this.required=!0,this._name=$.slice(1,-1);break;case"[":this.required=!1,this._name=$.slice(1,-1);break;default:this.required=!0,this._name=$;break}if(this._name.endsWith("..."))this.variadic=!0,this._name=this._name.slice(0,-3)}name(){return this._name}_collectValue($,J){if(J===this.defaultValue||!Array.isArray(J))return[$];return J.push($),J}default($,J){return this.defaultValue=$,this.defaultValueDescription=J,this}argParser($){return this.parseArg=$,this}choices($){return this.argChoices=$.slice(),this.parseArg=(J,f)=>{if(!this.argChoices.includes(J))throw new h0(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(J,f);return J},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}}function v0($){let J=$.name()+($.variadic===!0?"...":"");return $.required?"<"+J+">":"["+J+"]"}u0.Argument=D$;u0.humanReadableArgName=v0});var e=V((d0)=>{var{humanReadableArgName:m0}=u();class I${constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext($){this.helpWidth=this.helpWidth??$.helpWidth??80}visibleCommands($){let J=$.commands.filter((R)=>!R._hidden),f=$._getHelpCommand();if(f&&!f._hidden)J.push(f);if(this.sortSubcommands)J.sort((R,T)=>{return R.name().localeCompare(T.name())});return J}compareOptions($,J){let f=(R)=>{return R.short?R.short.replace(/^-/,""):R.long.replace(/^--/,"")};return f($).localeCompare(f(J))}visibleOptions($){let J=$.options.filter((R)=>!R.hidden),f=$._getHelpOption();if(f&&!f.hidden){let R=f.short&&$._findOption(f.short),T=f.long&&$._findOption(f.long);if(!R&&!T)J.push(f);else if(f.long&&!T)J.push($.createOption(f.long,f.description));else if(f.short&&!R)J.push($.createOption(f.short,f.description))}if(this.sortOptions)J.sort(this.compareOptions);return J}visibleGlobalOptions($){if(!this.showGlobalOptions)return[];let J=[];for(let f=$.parent;f;f=f.parent){let R=f.options.filter((T)=>!T.hidden);J.push(...R)}if(this.sortOptions)J.sort(this.compareOptions);return J}visibleArguments($){if($._argsDescription)$.registeredArguments.forEach((J)=>{J.description=J.description||$._argsDescription[J.name()]||""});if($.registeredArguments.find((J)=>J.description))return $.registeredArguments;return[]}subcommandTerm($){let J=$.registeredArguments.map((f)=>m0(f)).join(" ");return $._name+($._aliases[0]?"|"+$._aliases[0]:"")+($.options.length?" [options]":"")+(J?" "+J:"")}optionTerm($){return $.flags}argumentTerm($){return $.name()}longestSubcommandTermLength($,J){return J.visibleCommands($).reduce((f,R)=>{return Math.max(f,this.displayWidth(J.styleSubcommandTerm(J.subcommandTerm(R))))},0)}longestOptionTermLength($,J){return J.visibleOptions($).reduce((f,R)=>{return Math.max(f,this.displayWidth(J.styleOptionTerm(J.optionTerm(R))))},0)}longestGlobalOptionTermLength($,J){return J.visibleGlobalOptions($).reduce((f,R)=>{return Math.max(f,this.displayWidth(J.styleOptionTerm(J.optionTerm(R))))},0)}longestArgumentTermLength($,J){return J.visibleArguments($).reduce((f,R)=>{return Math.max(f,this.displayWidth(J.styleArgumentTerm(J.argumentTerm(R))))},0)}commandUsage($){let J=$._name;if($._aliases[0])J=J+"|"+$._aliases[0];let f="";for(let R=$.parent;R;R=R.parent)f=R.name()+" "+f;return f+J+" "+$.usage()}commandDescription($){return $.description()}subcommandDescription($){return $.summary()||$.description()}optionDescription($){let J=[];if($.argChoices)J.push(`choices: ${$.argChoices.map((f)=>JSON.stringify(f)).join(", ")}`);if($.defaultValue!==void 0){if($.required||$.optional||$.isBoolean()&&typeof $.defaultValue==="boolean")J.push(`default: ${$.defaultValueDescription||JSON.stringify($.defaultValue)}`)}if($.presetArg!==void 0&&$.optional)J.push(`preset: ${JSON.stringify($.presetArg)}`);if($.envVar!==void 0)J.push(`env: ${$.envVar}`);if(J.length>0){let f=`(${J.join(", ")})`;if($.description)return`${$.description} ${f}`;return f}return $.description}argumentDescription($){let J=[];if($.argChoices)J.push(`choices: ${$.argChoices.map((f)=>JSON.stringify(f)).join(", ")}`);if($.defaultValue!==void 0)J.push(`default: ${$.defaultValueDescription||JSON.stringify($.defaultValue)}`);if(J.length>0){let f=`(${J.join(", ")})`;if($.description)return`${$.description} ${f}`;return f}return $.description}formatItemList($,J,f){if(J.length===0)return[];return[f.styleTitle($),...J,""]}groupItems($,J,f){let R=new Map;return $.forEach((T)=>{let q=f(T);if(!R.has(q))R.set(q,[])}),J.forEach((T)=>{let q=f(T);if(!R.has(q))R.set(q,[]);R.get(q).push(T)}),R}formatHelp($,J){let f=J.padWidth($,J),R=J.helpWidth??80;function T(Q,G){return J.formatItem(Q,f,G,J)}let q=[`${J.styleTitle("Usage:")} ${J.styleUsage(J.commandUsage($))}`,""],X=J.commandDescription($);if(X.length>0)q=q.concat([J.boxWrap(J.styleCommandDescription(X),R),""]);let z=J.visibleArguments($).map((Q)=>{return T(J.styleArgumentTerm(J.argumentTerm(Q)),J.styleArgumentDescription(J.argumentDescription(Q)))});if(q=q.concat(this.formatItemList("Arguments:",z,J)),this.groupItems($.options,J.visibleOptions($),(Q)=>Q.helpGroupHeading??"Options:").forEach((Q,G)=>{let S=Q.map((B)=>{return T(J.styleOptionTerm(J.optionTerm(B)),J.styleOptionDescription(J.optionDescription(B)))});q=q.concat(this.formatItemList(G,S,J))}),J.showGlobalOptions){let Q=J.visibleGlobalOptions($).map((G)=>{return T(J.styleOptionTerm(J.optionTerm(G)),J.styleOptionDescription(J.optionDescription(G)))});q=q.concat(this.formatItemList("Global Options:",Q,J))}return this.groupItems($.commands,J.visibleCommands($),(Q)=>Q.helpGroup()||"Commands:").forEach((Q,G)=>{let S=Q.map((B)=>{return T(J.styleSubcommandTerm(J.subcommandTerm(B)),J.styleSubcommandDescription(J.subcommandDescription(B)))});q=q.concat(this.formatItemList(G,S,J))}),q.join(`
4
4
  `)}displayWidth($){return E$($).length}styleTitle($){return $}styleUsage($){return $.split(" ").map((J)=>{if(J==="[options]")return this.styleOptionText(J);if(J==="[command]")return this.styleSubcommandText(J);if(J[0]==="["||J[0]==="<")return this.styleArgumentText(J);return this.styleCommandText(J)}).join(" ")}styleCommandDescription($){return this.styleDescriptionText($)}styleOptionDescription($){return this.styleDescriptionText($)}styleSubcommandDescription($){return this.styleDescriptionText($)}styleArgumentDescription($){return this.styleDescriptionText($)}styleDescriptionText($){return $}styleOptionTerm($){return this.styleOptionText($)}styleSubcommandTerm($){return $.split(" ").map((J)=>{if(J==="[options]")return this.styleOptionText(J);if(J[0]==="["||J[0]==="<")return this.styleArgumentText(J);return this.styleSubcommandText(J)}).join(" ")}styleArgumentTerm($){return this.styleArgumentText($)}styleOptionText($){return $}styleArgumentText($){return $}styleSubcommandText($){return $}styleCommandText($){return $}padWidth($,J){return Math.max(J.longestOptionTermLength($,J),J.longestGlobalOptionTermLength($,J),J.longestSubcommandTermLength($,J),J.longestArgumentTermLength($,J))}preformatted($){return/\n[^\S\r\n]/.test($)}formatItem($,J,f,R){let q=" ".repeat(2);if(!f)return q+$;let X=$.padEnd(J+$.length-R.displayWidth($)),z=2,Z=(this.helpWidth??80)-J-z-2,Q;if(Z<this.minWidthToWrap||R.preformatted(f))Q=f;else Q=R.boxWrap(f,Z).replace(/\n/g,`
5
5
  `+" ".repeat(J+z));return q+X+" ".repeat(z)+Q.replace(/\n/g,`
6
6
  ${q}`)}boxWrap($,J){if(J<this.minWidthToWrap)return $;let f=$.split(/\r\n|\n/),R=/[\s]*[^\s]+/g,T=[];return f.forEach((q)=>{let X=q.match(R);if(X===null){T.push("");return}let z=[X.shift()],M=this.displayWidth(z[0]);X.forEach((Z)=>{let Q=this.displayWidth(Z);if(M+Q<=J){z.push(Z),M+=Q;return}T.push(z.join(""));let G=Z.trimStart();z=[G],M=this.displayWidth(G)}),T.push(z.join(""))}),T.join(`
7
- `)}}function E$($){let J=/\x1b\[\d*(;\d*)*m/g;return $.replace(J,"")}c0.Help=I$;c0.stripColor=E$});var $$=V((l0)=>{var{InvalidArgumentError:d0}=A();class w${constructor($,J){this.flags=$,this.description=J||"",this.required=$.includes("<"),this.optional=$.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test($),this.mandatory=!1;let f=t0($);if(this.short=f.shortFlag,this.long=f.longFlag,this.negate=!1,this.long)this.negate=this.long.startsWith("--no-");this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0}default($,J){return this.defaultValue=$,this.defaultValueDescription=J,this}preset($){return this.presetArg=$,this}conflicts($){return this.conflictsWith=this.conflictsWith.concat($),this}implies($){let J=$;if(typeof $==="string")J={[$]:!0};return this.implied=Object.assign(this.implied||{},J),this}env($){return this.envVar=$,this}argParser($){return this.parseArg=$,this}makeOptionMandatory($=!0){return this.mandatory=!!$,this}hideHelp($=!0){return this.hidden=!!$,this}_collectValue($,J){if(J===this.defaultValue||!Array.isArray(J))return[$];return J.push($),J}choices($){return this.argChoices=$.slice(),this.parseArg=(J,f)=>{if(!this.argChoices.includes(J))throw new d0(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(J,f);return J},this}name(){if(this.long)return this.long.replace(/^--/,"");return this.short.replace(/^-/,"")}attributeName(){if(this.negate)return N$(this.name().replace(/^no-/,""));return N$(this.name())}helpGroup($){return this.helpGroupHeading=$,this}is($){return this.short===$||this.long===$}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class F${constructor($){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,$.forEach((J)=>{if(J.negate)this.negativeOptions.set(J.attributeName(),J);else this.positiveOptions.set(J.attributeName(),J)}),this.negativeOptions.forEach((J,f)=>{if(this.positiveOptions.has(f))this.dualOptions.add(f)})}valueFromOption($,J){let f=J.attributeName();if(!this.dualOptions.has(f))return!0;let R=this.negativeOptions.get(f).presetArg,T=R!==void 0?R:!1;return J.negate===(T===$)}}function N$($){return $.split("-").reduce((J,f)=>{return J+f[0].toUpperCase()+f.slice(1)})}function t0($){let J,f,R=/^-[^-]$/,T=/^--[^-]/,q=$.split(/[ |,]+/).concat("guard");if(R.test(q[0]))J=q.shift();if(T.test(q[0]))f=q.shift();if(!J&&R.test(q[0]))J=q.shift();if(!J&&T.test(q[0]))J=f,f=q.shift();if(q[0].startsWith("-")){let X=q[0],z=`option creation failed due to '${X}' in option flags '${$}'`;if(/^-[^-][^-]/.test(X))throw Error(`${z}
7
+ `)}}function E$($){let J=/\x1b\[\d*(;\d*)*m/g;return $.replace(J,"")}d0.Help=I$;d0.stripColor=E$});var $$=V((p0)=>{var{InvalidArgumentError:n0}=A();class w${constructor($,J){this.flags=$,this.description=J||"",this.required=$.includes("<"),this.optional=$.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test($),this.mandatory=!1;let f=i0($);if(this.short=f.shortFlag,this.long=f.longFlag,this.negate=!1,this.long)this.negate=this.long.startsWith("--no-");this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0}default($,J){return this.defaultValue=$,this.defaultValueDescription=J,this}preset($){return this.presetArg=$,this}conflicts($){return this.conflictsWith=this.conflictsWith.concat($),this}implies($){let J=$;if(typeof $==="string")J={[$]:!0};return this.implied=Object.assign(this.implied||{},J),this}env($){return this.envVar=$,this}argParser($){return this.parseArg=$,this}makeOptionMandatory($=!0){return this.mandatory=!!$,this}hideHelp($=!0){return this.hidden=!!$,this}_collectValue($,J){if(J===this.defaultValue||!Array.isArray(J))return[$];return J.push($),J}choices($){return this.argChoices=$.slice(),this.parseArg=(J,f)=>{if(!this.argChoices.includes(J))throw new n0(`Allowed choices are ${this.argChoices.join(", ")}.`);if(this.variadic)return this._collectValue(J,f);return J},this}name(){if(this.long)return this.long.replace(/^--/,"");return this.short.replace(/^-/,"")}attributeName(){if(this.negate)return N$(this.name().replace(/^no-/,""));return N$(this.name())}helpGroup($){return this.helpGroupHeading=$,this}is($){return this.short===$||this.long===$}isBoolean(){return!this.required&&!this.optional&&!this.negate}}class F${constructor($){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,$.forEach((J)=>{if(J.negate)this.negativeOptions.set(J.attributeName(),J);else this.positiveOptions.set(J.attributeName(),J)}),this.negativeOptions.forEach((J,f)=>{if(this.positiveOptions.has(f))this.dualOptions.add(f)})}valueFromOption($,J){let f=J.attributeName();if(!this.dualOptions.has(f))return!0;let R=this.negativeOptions.get(f).presetArg,T=R!==void 0?R:!1;return J.negate===(T===$)}}function N$($){return $.split("-").reduce((J,f)=>{return J+f[0].toUpperCase()+f.slice(1)})}function i0($){let J,f,R=/^-[^-]$/,T=/^--[^-]/,q=$.split(/[ |,]+/).concat("guard");if(R.test(q[0]))J=q.shift();if(T.test(q[0]))f=q.shift();if(!J&&R.test(q[0]))J=q.shift();if(!J&&T.test(q[0]))J=f,f=q.shift();if(q[0].startsWith("-")){let X=q[0],z=`option creation failed due to '${X}' in option flags '${$}'`;if(/^-[^-][^-]/.test(X))throw Error(`${z}
8
8
  - a short flag is a single dash and a single character
9
9
  - either use a single dash and a single character (for a short flag)
10
10
  - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);if(R.test(X))throw Error(`${z}
11
11
  - too many short flags`);if(T.test(X))throw Error(`${z}
12
12
  - too many long flags`);throw Error(`${z}
13
- - unrecognised flag format`)}if(J===void 0&&f===void 0)throw Error(`option creation failed due to no flags found in '${$}'.`);return{shortFlag:J,longFlag:f}}l0.Option=w$;l0.DualOptions=F$});var k$=V((a0)=>{function p0($,J){if(Math.abs($.length-J.length)>3)return Math.max($.length,J.length);let f=[];for(let R=0;R<=$.length;R++)f[R]=[R];for(let R=0;R<=J.length;R++)f[0][R]=R;for(let R=1;R<=J.length;R++)for(let T=1;T<=$.length;T++){let q=1;if($[T-1]===J[R-1])q=0;else q=1;if(f[T][R]=Math.min(f[T-1][R]+1,f[T][R-1]+1,f[T-1][R-1]+q),T>1&&R>1&&$[T-1]===J[R-2]&&$[T-2]===J[R-1])f[T][R]=Math.min(f[T][R],f[T-2][R-2]+1)}return f[$.length][J.length]}function s0($,J){if(!J||J.length===0)return"";J=Array.from(new Set(J));let f=$.startsWith("--");if(f)$=$.slice(2),J=J.map((X)=>X.slice(2));let R=[],T=3,q=0.4;if(J.forEach((X)=>{if(X.length<=1)return;let z=p0($,X),M=Math.max($.length,X.length);if((M-z)/M>q){if(z<T)T=z,R=[X];else if(z===T)R.push(X)}}),R.sort((X,z)=>X.localeCompare(z)),f)R=R.map((X)=>`--${X}`);if(R.length>1)return`
13
+ - unrecognised flag format`)}if(J===void 0&&f===void 0)throw Error(`option creation failed due to no flags found in '${$}'.`);return{shortFlag:J,longFlag:f}}p0.Option=w$;p0.DualOptions=F$});var k$=V((e0)=>{function o0($,J){if(Math.abs($.length-J.length)>3)return Math.max($.length,J.length);let f=[];for(let R=0;R<=$.length;R++)f[R]=[R];for(let R=0;R<=J.length;R++)f[0][R]=R;for(let R=1;R<=J.length;R++)for(let T=1;T<=$.length;T++){let q=1;if($[T-1]===J[R-1])q=0;else q=1;if(f[T][R]=Math.min(f[T-1][R]+1,f[T][R-1]+1,f[T-1][R-1]+q),T>1&&R>1&&$[T-1]===J[R-2]&&$[T-2]===J[R-1])f[T][R]=Math.min(f[T][R],f[T-2][R-2]+1)}return f[$.length][J.length]}function r0($,J){if(!J||J.length===0)return"";J=Array.from(new Set(J));let f=$.startsWith("--");if(f)$=$.slice(2),J=J.map((X)=>X.slice(2));let R=[],T=3,q=0.4;if(J.forEach((X)=>{if(X.length<=1)return;let z=o0($,X),M=Math.max($.length,X.length);if((M-z)/M>q){if(z<T)T=z,R=[X];else if(z===T)R.push(X)}}),R.sort((X,z)=>X.localeCompare(z)),f)R=R.map((X)=>`--${X}`);if(R.length>1)return`
14
14
  (Did you mean one of ${R.join(", ")}?)`;if(R.length===1)return`
15
- (Did you mean ${R[0]}?)`;return""}a0.suggestSimilar=s0});var y$=V((T1)=>{var r0=O("node:events").EventEmitter,J$=O("node:child_process"),_=O("node:path"),c=O("node:fs"),L=O("node:process"),{Argument:e0,humanReadableArgName:$1}=u(),{CommanderError:f$}=A(),{Help:J1,stripColor:f1}=e(),{Option:O$,DualOptions:R1}=$$(),{suggestSimilar:A$}=k$();class T$ extends r0{constructor($){super();this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=$||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:(J)=>L.stdout.write(J),writeErr:(J)=>L.stderr.write(J),outputError:(J,f)=>f(J),getOutHelpWidth:()=>L.stdout.isTTY?L.stdout.columns:void 0,getErrHelpWidth:()=>L.stderr.isTTY?L.stderr.columns:void 0,getOutHasColors:()=>R$()??(L.stdout.isTTY&&L.stdout.hasColors?.()),getErrHasColors:()=>R$()??(L.stderr.isTTY&&L.stderr.hasColors?.()),stripColor:(J)=>f1(J)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings($){return this._outputConfiguration=$._outputConfiguration,this._helpOption=$._helpOption,this._helpCommand=$._helpCommand,this._helpConfiguration=$._helpConfiguration,this._exitCallback=$._exitCallback,this._storeOptionsAsProperties=$._storeOptionsAsProperties,this._combineFlagAndOptionalValue=$._combineFlagAndOptionalValue,this._allowExcessArguments=$._allowExcessArguments,this._enablePositionalOptions=$._enablePositionalOptions,this._showHelpAfterError=$._showHelpAfterError,this._showSuggestionAfterError=$._showSuggestionAfterError,this}_getCommandAndAncestors(){let $=[];for(let J=this;J;J=J.parent)$.push(J);return $}command($,J,f){let R=J,T=f;if(typeof R==="object"&&R!==null)T=R,R=null;T=T||{};let[,q,X]=$.match(/([^ ]+) *(.*)/),z=this.createCommand(q);if(R)z.description(R),z._executableHandler=!0;if(T.isDefault)this._defaultCommandName=z._name;if(z._hidden=!!(T.noHelp||T.hidden),z._executableFile=T.executableFile||null,X)z.arguments(X);if(this._registerCommand(z),z.parent=this,z.copyInheritedSettings(this),R)return this;return z}createCommand($){return new T$($)}createHelp(){return Object.assign(new J1,this.configureHelp())}configureHelp($){if($===void 0)return this._helpConfiguration;return this._helpConfiguration=$,this}configureOutput($){if($===void 0)return this._outputConfiguration;return this._outputConfiguration={...this._outputConfiguration,...$},this}showHelpAfterError($=!0){if(typeof $!=="string")$=!!$;return this._showHelpAfterError=$,this}showSuggestionAfterError($=!0){return this._showSuggestionAfterError=!!$,this}addCommand($,J){if(!$._name)throw Error(`Command passed to .addCommand() must have a name
16
- - specify the name in Command constructor or using .name()`);if(J=J||{},J.isDefault)this._defaultCommandName=$._name;if(J.noHelp||J.hidden)$._hidden=!0;return this._registerCommand($),$.parent=this,$._checkForBrokenPassThrough(),this}createArgument($,J){return new e0($,J)}argument($,J,f,R){let T=this.createArgument($,J);if(typeof f==="function")T.default(R).argParser(f);else T.default(f);return this.addArgument(T),this}arguments($){return $.trim().split(/ +/).forEach((J)=>{this.argument(J)}),this}addArgument($){let J=this.registeredArguments.slice(-1)[0];if(J?.variadic)throw Error(`only the last argument can be variadic '${J.name()}'`);if($.required&&$.defaultValue!==void 0&&$.parseArg===void 0)throw Error(`a default value for a required argument is never used: '${$.name()}'`);return this.registeredArguments.push($),this}helpCommand($,J){if(typeof $==="boolean"){if(this._addImplicitHelpCommand=$,$&&this._defaultCommandGroup)this._initCommandGroup(this._getHelpCommand());return this}let f=$??"help [command]",[,R,T]=f.match(/([^ ]+) *(.*)/),q=J??"display help for command",X=this.createCommand(R);if(X.helpOption(!1),T)X.arguments(T);if(q)X.description(q);if(this._addImplicitHelpCommand=!0,this._helpCommand=X,$||J)this._initCommandGroup(X);return this}addHelpCommand($,J){if(typeof $!=="object")return this.helpCommand($,J),this;return this._addImplicitHelpCommand=!0,this._helpCommand=$,this._initCommandGroup($),this}_getHelpCommand(){if(this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))){if(this._helpCommand===void 0)this.helpCommand(void 0,void 0);return this._helpCommand}return null}hook($,J){let f=["preSubcommand","preAction","postAction"];if(!f.includes($))throw Error(`Unexpected value for event passed to hook : '${$}'.
15
+ (Did you mean ${R[0]}?)`;return""}e0.suggestSimilar=r0});var y$=V((z1)=>{var J1=O("node:events").EventEmitter,J$=O("node:child_process"),_=O("node:path"),c=O("node:fs"),L=O("node:process"),{Argument:f1,humanReadableArgName:R1}=u(),{CommanderError:f$}=A(),{Help:T1,stripColor:q1}=e(),{Option:O$,DualOptions:X1}=$$(),{suggestSimilar:A$}=k$();class T$ extends J1{constructor($){super();this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=$||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:(J)=>L.stdout.write(J),writeErr:(J)=>L.stderr.write(J),outputError:(J,f)=>f(J),getOutHelpWidth:()=>L.stdout.isTTY?L.stdout.columns:void 0,getErrHelpWidth:()=>L.stderr.isTTY?L.stderr.columns:void 0,getOutHasColors:()=>R$()??(L.stdout.isTTY&&L.stdout.hasColors?.()),getErrHasColors:()=>R$()??(L.stderr.isTTY&&L.stderr.hasColors?.()),stripColor:(J)=>q1(J)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings($){return this._outputConfiguration=$._outputConfiguration,this._helpOption=$._helpOption,this._helpCommand=$._helpCommand,this._helpConfiguration=$._helpConfiguration,this._exitCallback=$._exitCallback,this._storeOptionsAsProperties=$._storeOptionsAsProperties,this._combineFlagAndOptionalValue=$._combineFlagAndOptionalValue,this._allowExcessArguments=$._allowExcessArguments,this._enablePositionalOptions=$._enablePositionalOptions,this._showHelpAfterError=$._showHelpAfterError,this._showSuggestionAfterError=$._showSuggestionAfterError,this}_getCommandAndAncestors(){let $=[];for(let J=this;J;J=J.parent)$.push(J);return $}command($,J,f){let R=J,T=f;if(typeof R==="object"&&R!==null)T=R,R=null;T=T||{};let[,q,X]=$.match(/([^ ]+) *(.*)/),z=this.createCommand(q);if(R)z.description(R),z._executableHandler=!0;if(T.isDefault)this._defaultCommandName=z._name;if(z._hidden=!!(T.noHelp||T.hidden),z._executableFile=T.executableFile||null,X)z.arguments(X);if(this._registerCommand(z),z.parent=this,z.copyInheritedSettings(this),R)return this;return z}createCommand($){return new T$($)}createHelp(){return Object.assign(new T1,this.configureHelp())}configureHelp($){if($===void 0)return this._helpConfiguration;return this._helpConfiguration=$,this}configureOutput($){if($===void 0)return this._outputConfiguration;return this._outputConfiguration={...this._outputConfiguration,...$},this}showHelpAfterError($=!0){if(typeof $!=="string")$=!!$;return this._showHelpAfterError=$,this}showSuggestionAfterError($=!0){return this._showSuggestionAfterError=!!$,this}addCommand($,J){if(!$._name)throw Error(`Command passed to .addCommand() must have a name
16
+ - specify the name in Command constructor or using .name()`);if(J=J||{},J.isDefault)this._defaultCommandName=$._name;if(J.noHelp||J.hidden)$._hidden=!0;return this._registerCommand($),$.parent=this,$._checkForBrokenPassThrough(),this}createArgument($,J){return new f1($,J)}argument($,J,f,R){let T=this.createArgument($,J);if(typeof f==="function")T.default(R).argParser(f);else T.default(f);return this.addArgument(T),this}arguments($){return $.trim().split(/ +/).forEach((J)=>{this.argument(J)}),this}addArgument($){let J=this.registeredArguments.slice(-1)[0];if(J?.variadic)throw Error(`only the last argument can be variadic '${J.name()}'`);if($.required&&$.defaultValue!==void 0&&$.parseArg===void 0)throw Error(`a default value for a required argument is never used: '${$.name()}'`);return this.registeredArguments.push($),this}helpCommand($,J){if(typeof $==="boolean"){if(this._addImplicitHelpCommand=$,$&&this._defaultCommandGroup)this._initCommandGroup(this._getHelpCommand());return this}let f=$??"help [command]",[,R,T]=f.match(/([^ ]+) *(.*)/),q=J??"display help for command",X=this.createCommand(R);if(X.helpOption(!1),T)X.arguments(T);if(q)X.description(q);if(this._addImplicitHelpCommand=!0,this._helpCommand=X,$||J)this._initCommandGroup(X);return this}addHelpCommand($,J){if(typeof $!=="object")return this.helpCommand($,J),this;return this._addImplicitHelpCommand=!0,this._helpCommand=$,this._initCommandGroup($),this}_getHelpCommand(){if(this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))){if(this._helpCommand===void 0)this.helpCommand(void 0,void 0);return this._helpCommand}return null}hook($,J){let f=["preSubcommand","preAction","postAction"];if(!f.includes($))throw Error(`Unexpected value for event passed to hook : '${$}'.
17
17
  Expecting one of '${f.join("', '")}'`);if(this._lifeCycleHooks[$])this._lifeCycleHooks[$].push(J);else this._lifeCycleHooks[$]=[J];return this}exitOverride($){if($)this._exitCallback=$;else this._exitCallback=(J)=>{if(J.code!=="commander.executeSubCommandAsync")throw J};return this}_exit($,J,f){if(this._exitCallback)this._exitCallback(new f$($,J,f));L.exit($)}action($){let J=(f)=>{let R=this.registeredArguments.length,T=f.slice(0,R);if(this._storeOptionsAsProperties)T[R]=this;else T[R]=this.opts();return T.push(this),$.apply(this,T)};return this._actionHandler=J,this}createOption($,J){return new O$($,J)}_callParseArg($,J,f,R){try{return $.parseArg(J,f)}catch(T){if(T.code==="commander.invalidArgument"){let q=`${R} ${T.message}`;this.error(q,{exitCode:T.exitCode,code:T.code})}throw T}}_registerOption($){let J=$.short&&this._findOption($.short)||$.long&&this._findOption($.long);if(J){let f=$.long&&this._findOption($.long)?$.long:$.short;throw Error(`Cannot add option '${$.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${f}'
18
18
  - already used by option '${J.flags}'`)}this._initOptionGroup($),this.options.push($)}_registerCommand($){let J=(R)=>{return[R.name()].concat(R.aliases())},f=J($).find((R)=>this._findCommand(R));if(f){let R=J(this._findCommand(f)).join("|"),T=J($).join("|");throw Error(`cannot add command '${T}' as already have command '${R}'`)}this._initCommandGroup($),this.commands.push($)}addOption($){this._registerOption($);let J=$.name(),f=$.attributeName();if($.negate){let T=$.long.replace(/^--no-/,"--");if(!this._findOption(T))this.setOptionValueWithSource(f,$.defaultValue===void 0?!0:$.defaultValue,"default")}else if($.defaultValue!==void 0)this.setOptionValueWithSource(f,$.defaultValue,"default");let R=(T,q,X)=>{if(T==null&&$.presetArg!==void 0)T=$.presetArg;let z=this.getOptionValue(f);if(T!==null&&$.parseArg)T=this._callParseArg($,T,z,q);else if(T!==null&&$.variadic)T=$._collectValue(T,z);if(T==null)if($.negate)T=!1;else if($.isBoolean()||$.optional)T=!0;else T="";this.setOptionValueWithSource(f,T,X)};if(this.on("option:"+J,(T)=>{let q=`error: option '${$.flags}' argument '${T}' is invalid.`;R(T,q,"cli")}),$.envVar)this.on("optionEnv:"+J,(T)=>{let q=`error: option '${$.flags}' value '${T}' from env '${$.envVar}' is invalid.`;R(T,q,"env")});return this}_optionEx($,J,f,R,T){if(typeof J==="object"&&J instanceof O$)throw Error("To add an Option object use addOption() instead of option() or requiredOption()");let q=this.createOption(J,f);if(q.makeOptionMandatory(!!$.mandatory),typeof R==="function")q.default(T).argParser(R);else if(R instanceof RegExp){let X=R;R=(z,M)=>{let Z=X.exec(z);return Z?Z[0]:M},q.default(T).argParser(R)}else q.default(R);return this.addOption(q)}option($,J,f,R){return this._optionEx({},$,J,f,R)}requiredOption($,J,f,R){return this._optionEx({mandatory:!0},$,J,f,R)}combineFlagAndOptionalValue($=!0){return this._combineFlagAndOptionalValue=!!$,this}allowUnknownOption($=!0){return this._allowUnknownOption=!!$,this}allowExcessArguments($=!0){return this._allowExcessArguments=!!$,this}enablePositionalOptions($=!0){return this._enablePositionalOptions=!!$,this}passThroughOptions($=!0){return this._passThroughOptions=!!$,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties($=!0){if(this.options.length)throw Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!$,this}getOptionValue($){if(this._storeOptionsAsProperties)return this[$];return this._optionValues[$]}setOptionValue($,J){return this.setOptionValueWithSource($,J,void 0)}setOptionValueWithSource($,J,f){if(this._storeOptionsAsProperties)this[$]=J;else this._optionValues[$]=J;return this._optionValueSources[$]=f,this}getOptionValueSource($){return this._optionValueSources[$]}getOptionValueSourceWithGlobals($){let J;return this._getCommandAndAncestors().forEach((f)=>{if(f.getOptionValueSource($)!==void 0)J=f.getOptionValueSource($)}),J}_prepareUserArgs($,J){if($!==void 0&&!Array.isArray($))throw Error("first parameter to parse must be array or undefined");if(J=J||{},$===void 0&&J.from===void 0){if(L.versions?.electron)J.from="electron";let R=L.execArgv??[];if(R.includes("-e")||R.includes("--eval")||R.includes("-p")||R.includes("--print"))J.from="eval"}if($===void 0)$=L.argv;this.rawArgs=$.slice();let f;switch(J.from){case void 0:case"node":this._scriptPath=$[1],f=$.slice(2);break;case"electron":if(L.defaultApp)this._scriptPath=$[1],f=$.slice(2);else f=$.slice(1);break;case"user":f=$.slice(0);break;case"eval":f=$.slice(1);break;default:throw Error(`unexpected parse option { from: '${J.from}' }`)}if(!this._name&&this._scriptPath)this.nameFromFilename(this._scriptPath);return this._name=this._name||"program",f}parse($,J){this._prepareForParse();let f=this._prepareUserArgs($,J);return this._parseCommand([],f),this}async parseAsync($,J){this._prepareForParse();let f=this._prepareUserArgs($,J);return await this._parseCommand([],f),this}_prepareForParse(){if(this._savedState===null)this.saveStateBeforeParse();else this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw Error(`Can not call parse again when storeOptionsAsProperties is true.
19
19
  - either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable($,J,f){if(c.existsSync($))return;let R=J?`searched for local subcommand relative to directory '${J}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",T=`'${$}' does not exist
@@ -22,36 +22,36 @@ Expecting one of '${f.join("', '")}'`);if(this._lifeCycleHooks[$])this._lifeCycl
22
22
  - ${R}`;throw Error(T)}_executeSubCommand($,J){J=J.slice();let f=!1,R=[".js",".ts",".tsx",".mjs",".cjs"];function T(Z,Q){let G=_.resolve(Z,Q);if(c.existsSync(G))return G;if(R.includes(_.extname(Q)))return;let S=R.find((B)=>c.existsSync(`${G}${B}`));if(S)return`${G}${S}`;return}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let q=$._executableFile||`${this._name}-${$._name}`,X=this._executableDir||"";if(this._scriptPath){let Z;try{Z=c.realpathSync(this._scriptPath)}catch{Z=this._scriptPath}X=_.resolve(_.dirname(Z),X)}if(X){let Z=T(X,q);if(!Z&&!$._executableFile&&this._scriptPath){let Q=_.basename(this._scriptPath,_.extname(this._scriptPath));if(Q!==this._name)Z=T(X,`${Q}-${$._name}`)}q=Z||q}f=R.includes(_.extname(q));let z;if(L.platform!=="win32")if(f)J.unshift(q),J=x$(L.execArgv).concat(J),z=J$.spawn(L.argv[0],J,{stdio:"inherit"});else z=J$.spawn(q,J,{stdio:"inherit"});else this._checkForMissingExecutable(q,X,$._name),J.unshift(q),J=x$(L.execArgv).concat(J),z=J$.spawn(L.execPath,J,{stdio:"inherit"});if(!z.killed)["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach((Q)=>{L.on(Q,()=>{if(z.killed===!1&&z.exitCode===null)z.kill(Q)})});let M=this._exitCallback;z.on("close",(Z)=>{if(Z=Z??1,!M)L.exit(Z);else M(new f$(Z,"commander.executeSubCommandAsync","(close)"))}),z.on("error",(Z)=>{if(Z.code==="ENOENT")this._checkForMissingExecutable(q,X,$._name);else if(Z.code==="EACCES")throw Error(`'${q}' not executable`);if(!M)L.exit(1);else{let Q=new f$(1,"commander.executeSubCommandAsync","(error)");Q.nestedError=Z,M(Q)}}),this.runningCommand=z}_dispatchSubcommand($,J,f){let R=this._findCommand($);if(!R)this.help({error:!0});R._prepareForParse();let T;return T=this._chainOrCallSubCommandHook(T,R,"preSubcommand"),T=this._chainOrCall(T,()=>{if(R._executableHandler)this._executeSubCommand(R,J.concat(f));else return R._parseCommand(J,f)}),T}_dispatchHelpCommand($){if(!$)this.help();let J=this._findCommand($);if(J&&!J._executableHandler)J.help();return this._dispatchSubcommand($,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){if(this.registeredArguments.forEach(($,J)=>{if($.required&&this.args[J]==null)this.missingArgument($.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)return;if(this.args.length>this.registeredArguments.length)this._excessArguments(this.args)}_processArguments(){let $=(f,R,T)=>{let q=R;if(R!==null&&f.parseArg){let X=`error: command-argument value '${R}' is invalid for argument '${f.name()}'.`;q=this._callParseArg(f,R,T,X)}return q};this._checkNumberOfArguments();let J=[];this.registeredArguments.forEach((f,R)=>{let T=f.defaultValue;if(f.variadic){if(R<this.args.length){if(T=this.args.slice(R),f.parseArg)T=T.reduce((q,X)=>{return $(f,X,q)},f.defaultValue)}else if(T===void 0)T=[]}else if(R<this.args.length){if(T=this.args[R],f.parseArg)T=$(f,T,f.defaultValue)}J[R]=T}),this.processedArgs=J}_chainOrCall($,J){if($?.then&&typeof $.then==="function")return $.then(()=>J());return J()}_chainOrCallHooks($,J){let f=$,R=[];if(this._getCommandAndAncestors().reverse().filter((T)=>T._lifeCycleHooks[J]!==void 0).forEach((T)=>{T._lifeCycleHooks[J].forEach((q)=>{R.push({hookedCommand:T,callback:q})})}),J==="postAction")R.reverse();return R.forEach((T)=>{f=this._chainOrCall(f,()=>{return T.callback(T.hookedCommand,this)})}),f}_chainOrCallSubCommandHook($,J,f){let R=$;if(this._lifeCycleHooks[f]!==void 0)this._lifeCycleHooks[f].forEach((T)=>{R=this._chainOrCall(R,()=>{return T(this,J)})});return R}_parseCommand($,J){let f=this.parseOptions(J);if(this._parseOptionsEnv(),this._parseOptionsImplied(),$=$.concat(f.operands),J=f.unknown,this.args=$.concat(J),$&&this._findCommand($[0]))return this._dispatchSubcommand($[0],$.slice(1),J);if(this._getHelpCommand()&&$[0]===this._getHelpCommand().name())return this._dispatchHelpCommand($[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(J),this._dispatchSubcommand(this._defaultCommandName,$,J);if(this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName)this.help({error:!0});this._outputHelpIfRequested(f.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let R=()=>{if(f.unknown.length>0)this.unknownOption(f.unknown[0])},T=`command:${this.name()}`;if(this._actionHandler){R(),this._processArguments();let q;if(q=this._chainOrCallHooks(q,"preAction"),q=this._chainOrCall(q,()=>this._actionHandler(this.processedArgs)),this.parent)q=this._chainOrCall(q,()=>{this.parent.emit(T,$,J)});return q=this._chainOrCallHooks(q,"postAction"),q}if(this.parent?.listenerCount(T))R(),this._processArguments(),this.parent.emit(T,$,J);else if($.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",$,J);if(this.listenerCount("command:*"))this.emit("command:*",$,J);else if(this.commands.length)this.unknownCommand();else R(),this._processArguments()}else if(this.commands.length)R(),this.help({error:!0});else R(),this._processArguments()}_findCommand($){if(!$)return;return this.commands.find((J)=>J._name===$||J._aliases.includes($))}_findOption($){return this.options.find((J)=>J.is($))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(($)=>{$.options.forEach((J)=>{if(J.mandatory&&$.getOptionValue(J.attributeName())===void 0)$.missingMandatoryOptionValue(J)})})}_checkForConflictingLocalOptions(){let $=this.options.filter((f)=>{let R=f.attributeName();if(this.getOptionValue(R)===void 0)return!1;return this.getOptionValueSource(R)!=="default"});$.filter((f)=>f.conflictsWith.length>0).forEach((f)=>{let R=$.find((T)=>f.conflictsWith.includes(T.attributeName()));if(R)this._conflictingOption(f,R)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(($)=>{$._checkForConflictingLocalOptions()})}parseOptions($){let J=[],f=[],R=J;function T(Z){return Z.length>1&&Z[0]==="-"}let q=(Z)=>{if(!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(Z))return!1;return!this._getCommandAndAncestors().some((Q)=>Q.options.map((G)=>G.short).some((G)=>/^-\d$/.test(G)))},X=null,z=null,M=0;while(M<$.length||z){let Z=z??$[M++];if(z=null,Z==="--"){if(R===f)R.push(Z);R.push(...$.slice(M));break}if(X&&(!T(Z)||q(Z))){this.emit(`option:${X.name()}`,Z);continue}if(X=null,T(Z)){let Q=this._findOption(Z);if(Q){if(Q.required){let G=$[M++];if(G===void 0)this.optionMissingArgument(Q);this.emit(`option:${Q.name()}`,G)}else if(Q.optional){let G=null;if(M<$.length&&(!T($[M])||q($[M])))G=$[M++];this.emit(`option:${Q.name()}`,G)}else this.emit(`option:${Q.name()}`);X=Q.variadic?Q:null;continue}}if(Z.length>2&&Z[0]==="-"&&Z[1]!=="-"){let Q=this._findOption(`-${Z[1]}`);if(Q){if(Q.required||Q.optional&&this._combineFlagAndOptionalValue)this.emit(`option:${Q.name()}`,Z.slice(2));else this.emit(`option:${Q.name()}`),z=`-${Z.slice(2)}`;continue}}if(/^--[^=]+=/.test(Z)){let Q=Z.indexOf("="),G=this._findOption(Z.slice(0,Q));if(G&&(G.required||G.optional)){this.emit(`option:${G.name()}`,Z.slice(Q+1));continue}}if(R===J&&T(Z)&&!(this.commands.length===0&&q(Z)))R=f;if((this._enablePositionalOptions||this._passThroughOptions)&&J.length===0&&f.length===0){if(this._findCommand(Z)){J.push(Z),f.push(...$.slice(M));break}else if(this._getHelpCommand()&&Z===this._getHelpCommand().name()){J.push(Z,...$.slice(M));break}else if(this._defaultCommandName){f.push(Z,...$.slice(M));break}}if(this._passThroughOptions){R.push(Z,...$.slice(M));break}R.push(Z)}return{operands:J,unknown:f}}opts(){if(this._storeOptionsAsProperties){let $={},J=this.options.length;for(let f=0;f<J;f++){let R=this.options[f].attributeName();$[R]=R===this._versionOptionName?this._version:this[R]}return $}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce(($,J)=>Object.assign($,J.opts()),{})}error($,J){if(this._outputConfiguration.outputError(`${$}
23
23
  `,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==="string")this._outputConfiguration.writeErr(`${this._showHelpAfterError}
24
24
  `);else if(this._showHelpAfterError)this._outputConfiguration.writeErr(`
25
- `),this.outputHelp({error:!0});let f=J||{},R=f.exitCode||1,T=f.code||"commander.error";this._exit(R,T,$)}_parseOptionsEnv(){this.options.forEach(($)=>{if($.envVar&&$.envVar in L.env){let J=$.attributeName();if(this.getOptionValue(J)===void 0||["default","config","env"].includes(this.getOptionValueSource(J)))if($.required||$.optional)this.emit(`optionEnv:${$.name()}`,L.env[$.envVar]);else this.emit(`optionEnv:${$.name()}`)}})}_parseOptionsImplied(){let $=new R1(this.options),J=(f)=>{return this.getOptionValue(f)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(f))};this.options.filter((f)=>f.implied!==void 0&&J(f.attributeName())&&$.valueFromOption(this.getOptionValue(f.attributeName()),f)).forEach((f)=>{Object.keys(f.implied).filter((R)=>!J(R)).forEach((R)=>{this.setOptionValueWithSource(R,f.implied[R],"implied")})})}missingArgument($){let J=`error: missing required argument '${$}'`;this.error(J,{code:"commander.missingArgument"})}optionMissingArgument($){let J=`error: option '${$.flags}' argument missing`;this.error(J,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue($){let J=`error: required option '${$.flags}' not specified`;this.error(J,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption($,J){let f=(q)=>{let X=q.attributeName(),z=this.getOptionValue(X),M=this.options.find((Q)=>Q.negate&&X===Q.attributeName()),Z=this.options.find((Q)=>!Q.negate&&X===Q.attributeName());if(M&&(M.presetArg===void 0&&z===!1||M.presetArg!==void 0&&z===M.presetArg))return M;return Z||q},R=(q)=>{let X=f(q),z=X.attributeName();if(this.getOptionValueSource(z)==="env")return`environment variable '${X.envVar}'`;return`option '${X.flags}'`},T=`error: ${R($)} cannot be used with ${R(J)}`;this.error(T,{code:"commander.conflictingOption"})}unknownOption($){if(this._allowUnknownOption)return;let J="";if($.startsWith("--")&&this._showSuggestionAfterError){let R=[],T=this;do{let q=T.createHelp().visibleOptions(T).filter((X)=>X.long).map((X)=>X.long);R=R.concat(q),T=T.parent}while(T&&!T._enablePositionalOptions);J=A$($,R)}let f=`error: unknown option '${$}'${J}`;this.error(f,{code:"commander.unknownOption"})}_excessArguments($){if(this._allowExcessArguments)return;let J=this.registeredArguments.length,f=J===1?"":"s",T=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${J} argument${f} but got ${$.length}.`;this.error(T,{code:"commander.excessArguments"})}unknownCommand(){let $=this.args[0],J="";if(this._showSuggestionAfterError){let R=[];this.createHelp().visibleCommands(this).forEach((T)=>{if(R.push(T.name()),T.alias())R.push(T.alias())}),J=A$($,R)}let f=`error: unknown command '${$}'${J}`;this.error(f,{code:"commander.unknownCommand"})}version($,J,f){if($===void 0)return this._version;this._version=$,J=J||"-V, --version",f=f||"output the version number";let R=this.createOption(J,f);return this._versionOptionName=R.attributeName(),this._registerOption(R),this.on("option:"+R.name(),()=>{this._outputConfiguration.writeOut(`${$}
26
- `),this._exit(0,"commander.version",$)}),this}description($,J){if($===void 0&&J===void 0)return this._description;if(this._description=$,J)this._argsDescription=J;return this}summary($){if($===void 0)return this._summary;return this._summary=$,this}alias($){if($===void 0)return this._aliases[0];let J=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)J=this.commands[this.commands.length-1];if($===J._name)throw Error("Command alias can't be the same as its name");let f=this.parent?._findCommand($);if(f){let R=[f.name()].concat(f.aliases()).join("|");throw Error(`cannot add alias '${$}' to command '${this.name()}' as already have command '${R}'`)}return J._aliases.push($),this}aliases($){if($===void 0)return this._aliases;return $.forEach((J)=>this.alias(J)),this}usage($){if($===void 0){if(this._usage)return this._usage;let J=this.registeredArguments.map((f)=>{return $1(f)});return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?J:[]).join(" ")}return this._usage=$,this}name($){if($===void 0)return this._name;return this._name=$,this}helpGroup($){if($===void 0)return this._helpGroupHeading??"";return this._helpGroupHeading=$,this}commandsGroup($){if($===void 0)return this._defaultCommandGroup??"";return this._defaultCommandGroup=$,this}optionsGroup($){if($===void 0)return this._defaultOptionGroup??"";return this._defaultOptionGroup=$,this}_initOptionGroup($){if(this._defaultOptionGroup&&!$.helpGroupHeading)$.helpGroup(this._defaultOptionGroup)}_initCommandGroup($){if(this._defaultCommandGroup&&!$.helpGroup())$.helpGroup(this._defaultCommandGroup)}nameFromFilename($){return this._name=_.basename($,_.extname($)),this}executableDir($){if($===void 0)return this._executableDir;return this._executableDir=$,this}helpInformation($){let J=this.createHelp(),f=this._getOutputContext($);J.prepareContext({error:f.error,helpWidth:f.helpWidth,outputHasColors:f.hasColors});let R=J.formatHelp(this,J);if(f.hasColors)return R;return this._outputConfiguration.stripColor(R)}_getOutputContext($){$=$||{};let J=!!$.error,f,R,T;if(J)f=(X)=>this._outputConfiguration.writeErr(X),R=this._outputConfiguration.getErrHasColors(),T=this._outputConfiguration.getErrHelpWidth();else f=(X)=>this._outputConfiguration.writeOut(X),R=this._outputConfiguration.getOutHasColors(),T=this._outputConfiguration.getOutHelpWidth();return{error:J,write:(X)=>{if(!R)X=this._outputConfiguration.stripColor(X);return f(X)},hasColors:R,helpWidth:T}}outputHelp($){let J;if(typeof $==="function")J=$,$=void 0;let f=this._getOutputContext($),R={error:f.error,write:f.write,command:this};this._getCommandAndAncestors().reverse().forEach((q)=>q.emit("beforeAllHelp",R)),this.emit("beforeHelp",R);let T=this.helpInformation({error:f.error});if(J){if(T=J(T),typeof T!=="string"&&!Buffer.isBuffer(T))throw Error("outputHelp callback must return a string or a Buffer")}if(f.write(T),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",R),this._getCommandAndAncestors().forEach((q)=>q.emit("afterAllHelp",R))}helpOption($,J){if(typeof $==="boolean"){if($){if(this._helpOption===null)this._helpOption=void 0;if(this._defaultOptionGroup)this._initOptionGroup(this._getHelpOption())}else this._helpOption=null;return this}if(this._helpOption=this.createOption($??"-h, --help",J??"display help for command"),$||J)this._initOptionGroup(this._helpOption);return this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption($){return this._helpOption=$,this._initOptionGroup($),this}help($){this.outputHelp($);let J=Number(L.exitCode??0);if(J===0&&$&&typeof $!=="function"&&$.error)J=1;this._exit(J,"commander.help","(outputHelp)")}addHelpText($,J){let f=["beforeAll","before","after","afterAll"];if(!f.includes($))throw Error(`Unexpected value for position to addHelpText.
25
+ `),this.outputHelp({error:!0});let f=J||{},R=f.exitCode||1,T=f.code||"commander.error";this._exit(R,T,$)}_parseOptionsEnv(){this.options.forEach(($)=>{if($.envVar&&$.envVar in L.env){let J=$.attributeName();if(this.getOptionValue(J)===void 0||["default","config","env"].includes(this.getOptionValueSource(J)))if($.required||$.optional)this.emit(`optionEnv:${$.name()}`,L.env[$.envVar]);else this.emit(`optionEnv:${$.name()}`)}})}_parseOptionsImplied(){let $=new X1(this.options),J=(f)=>{return this.getOptionValue(f)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(f))};this.options.filter((f)=>f.implied!==void 0&&J(f.attributeName())&&$.valueFromOption(this.getOptionValue(f.attributeName()),f)).forEach((f)=>{Object.keys(f.implied).filter((R)=>!J(R)).forEach((R)=>{this.setOptionValueWithSource(R,f.implied[R],"implied")})})}missingArgument($){let J=`error: missing required argument '${$}'`;this.error(J,{code:"commander.missingArgument"})}optionMissingArgument($){let J=`error: option '${$.flags}' argument missing`;this.error(J,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue($){let J=`error: required option '${$.flags}' not specified`;this.error(J,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption($,J){let f=(q)=>{let X=q.attributeName(),z=this.getOptionValue(X),M=this.options.find((Q)=>Q.negate&&X===Q.attributeName()),Z=this.options.find((Q)=>!Q.negate&&X===Q.attributeName());if(M&&(M.presetArg===void 0&&z===!1||M.presetArg!==void 0&&z===M.presetArg))return M;return Z||q},R=(q)=>{let X=f(q),z=X.attributeName();if(this.getOptionValueSource(z)==="env")return`environment variable '${X.envVar}'`;return`option '${X.flags}'`},T=`error: ${R($)} cannot be used with ${R(J)}`;this.error(T,{code:"commander.conflictingOption"})}unknownOption($){if(this._allowUnknownOption)return;let J="";if($.startsWith("--")&&this._showSuggestionAfterError){let R=[],T=this;do{let q=T.createHelp().visibleOptions(T).filter((X)=>X.long).map((X)=>X.long);R=R.concat(q),T=T.parent}while(T&&!T._enablePositionalOptions);J=A$($,R)}let f=`error: unknown option '${$}'${J}`;this.error(f,{code:"commander.unknownOption"})}_excessArguments($){if(this._allowExcessArguments)return;let J=this.registeredArguments.length,f=J===1?"":"s",T=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${J} argument${f} but got ${$.length}.`;this.error(T,{code:"commander.excessArguments"})}unknownCommand(){let $=this.args[0],J="";if(this._showSuggestionAfterError){let R=[];this.createHelp().visibleCommands(this).forEach((T)=>{if(R.push(T.name()),T.alias())R.push(T.alias())}),J=A$($,R)}let f=`error: unknown command '${$}'${J}`;this.error(f,{code:"commander.unknownCommand"})}version($,J,f){if($===void 0)return this._version;this._version=$,J=J||"-V, --version",f=f||"output the version number";let R=this.createOption(J,f);return this._versionOptionName=R.attributeName(),this._registerOption(R),this.on("option:"+R.name(),()=>{this._outputConfiguration.writeOut(`${$}
26
+ `),this._exit(0,"commander.version",$)}),this}description($,J){if($===void 0&&J===void 0)return this._description;if(this._description=$,J)this._argsDescription=J;return this}summary($){if($===void 0)return this._summary;return this._summary=$,this}alias($){if($===void 0)return this._aliases[0];let J=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)J=this.commands[this.commands.length-1];if($===J._name)throw Error("Command alias can't be the same as its name");let f=this.parent?._findCommand($);if(f){let R=[f.name()].concat(f.aliases()).join("|");throw Error(`cannot add alias '${$}' to command '${this.name()}' as already have command '${R}'`)}return J._aliases.push($),this}aliases($){if($===void 0)return this._aliases;return $.forEach((J)=>this.alias(J)),this}usage($){if($===void 0){if(this._usage)return this._usage;let J=this.registeredArguments.map((f)=>{return R1(f)});return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?J:[]).join(" ")}return this._usage=$,this}name($){if($===void 0)return this._name;return this._name=$,this}helpGroup($){if($===void 0)return this._helpGroupHeading??"";return this._helpGroupHeading=$,this}commandsGroup($){if($===void 0)return this._defaultCommandGroup??"";return this._defaultCommandGroup=$,this}optionsGroup($){if($===void 0)return this._defaultOptionGroup??"";return this._defaultOptionGroup=$,this}_initOptionGroup($){if(this._defaultOptionGroup&&!$.helpGroupHeading)$.helpGroup(this._defaultOptionGroup)}_initCommandGroup($){if(this._defaultCommandGroup&&!$.helpGroup())$.helpGroup(this._defaultCommandGroup)}nameFromFilename($){return this._name=_.basename($,_.extname($)),this}executableDir($){if($===void 0)return this._executableDir;return this._executableDir=$,this}helpInformation($){let J=this.createHelp(),f=this._getOutputContext($);J.prepareContext({error:f.error,helpWidth:f.helpWidth,outputHasColors:f.hasColors});let R=J.formatHelp(this,J);if(f.hasColors)return R;return this._outputConfiguration.stripColor(R)}_getOutputContext($){$=$||{};let J=!!$.error,f,R,T;if(J)f=(X)=>this._outputConfiguration.writeErr(X),R=this._outputConfiguration.getErrHasColors(),T=this._outputConfiguration.getErrHelpWidth();else f=(X)=>this._outputConfiguration.writeOut(X),R=this._outputConfiguration.getOutHasColors(),T=this._outputConfiguration.getOutHelpWidth();return{error:J,write:(X)=>{if(!R)X=this._outputConfiguration.stripColor(X);return f(X)},hasColors:R,helpWidth:T}}outputHelp($){let J;if(typeof $==="function")J=$,$=void 0;let f=this._getOutputContext($),R={error:f.error,write:f.write,command:this};this._getCommandAndAncestors().reverse().forEach((q)=>q.emit("beforeAllHelp",R)),this.emit("beforeHelp",R);let T=this.helpInformation({error:f.error});if(J){if(T=J(T),typeof T!=="string"&&!Buffer.isBuffer(T))throw Error("outputHelp callback must return a string or a Buffer")}if(f.write(T),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",R),this._getCommandAndAncestors().forEach((q)=>q.emit("afterAllHelp",R))}helpOption($,J){if(typeof $==="boolean"){if($){if(this._helpOption===null)this._helpOption=void 0;if(this._defaultOptionGroup)this._initOptionGroup(this._getHelpOption())}else this._helpOption=null;return this}if(this._helpOption=this.createOption($??"-h, --help",J??"display help for command"),$||J)this._initOptionGroup(this._helpOption);return this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption($){return this._helpOption=$,this._initOptionGroup($),this}help($){this.outputHelp($);let J=Number(L.exitCode??0);if(J===0&&$&&typeof $!=="function"&&$.error)J=1;this._exit(J,"commander.help","(outputHelp)")}addHelpText($,J){let f=["beforeAll","before","after","afterAll"];if(!f.includes($))throw Error(`Unexpected value for position to addHelpText.
27
27
  Expecting one of '${f.join("', '")}'`);let R=`${$}Help`;return this.on(R,(T)=>{let q;if(typeof J==="function")q=J({error:T.error,command:T.command});else q=J;if(q)T.write(`${q}
28
- `)}),this}_outputHelpIfRequested($){let J=this._getHelpOption();if(J&&$.find((R)=>J.is(R)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function x$($){return $.map((J)=>{if(!J.startsWith("--inspect"))return J;let f,R="127.0.0.1",T="9229",q;if((q=J.match(/^(--inspect(-brk)?)$/))!==null)f=q[1];else if((q=J.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(f=q[1],/^\d+$/.test(q[3]))T=q[3];else R=q[3];else if((q=J.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)f=q[1],R=q[3],T=q[4];if(f&&T!=="0")return`${f}=${R}:${parseInt(T)+1}`;return J})}function R$(){if(L.env.NO_COLOR||L.env.FORCE_COLOR==="0"||L.env.FORCE_COLOR==="false")return!1;if(L.env.FORCE_COLOR||L.env.CLICOLOR_FORCE!==void 0)return!0;return}T1.Command=T$;T1.useColor=R$});var v$=V((Q1)=>{var{Argument:b$}=u(),{Command:q$}=y$(),{CommanderError:z1,InvalidArgumentError:C$}=A(),{Help:Z1}=e(),{Option:h$}=$$();Q1.program=new q$;Q1.createCommand=($)=>new q$($);Q1.createOption=($,J)=>new h$($,J);Q1.createArgument=($,J)=>new b$($,J);Q1.Command=q$;Q1.Option=h$;Q1.Argument=b$;Q1.Help=Z1;Q1.CommanderError=z1;Q1.InvalidArgumentError=C$;Q1.InvalidOptionArgumentError=C$});var u$=F0(v$(),1),{program:W2,createCommand:V2,createArgument:D2,createOption:I2,CommanderError:E2,InvalidArgumentError:N2,InvalidOptionArgumentError:w2,Command:c$,Argument:F2,Option:k2,Help:O2}=u$.default;var g$={name:"@miketromba/loops-cli",version:"0.1.0",description:"CLI for the Loops email marketing API — manage contacts, send events, transactional emails, and more from the command line. AI-agent optimized output.",type:"module",bin:{loops:"./dist/loops.js"},files:["dist","README.md","LICENSE"],scripts:{dev:"bun run bin/loops.ts",build:"bun run scripts/build.ts",test:"bun test tests/unit tests/integration","test:watch":"bun test --watch","test:unit":"bun test tests/unit","test:integration":"bun test tests/integration","test:e2e":"bun test tests/e2e",lint:"bunx biome check .","lint:fix":"bunx biome check --write .",format:"bunx biome format --write .",typecheck:"bunx tsc --noEmit",prepublishOnly:"bun run lint && bun run typecheck && bun test && bun run build",loops:"bun run bin/loops.ts",prepare:"husky"},keywords:["loops","email","marketing","transactional","cli","contacts","mailing-lists","events","api"],license:"MIT",engines:{node:">=18.0.0"},devDependencies:{"@biomejs/biome":"^2.4.1","@types/bun":"latest",husky:"^9.1.7"},peerDependencies:{typescript:"^5"},dependencies:{loops:"^6.2.1",chalk:"^5.6.2",commander:"^14.0.3"},publishConfig:{access:"public"}};import{existsSync as g,mkdirSync as W1,readFileSync as m$,unlinkSync as V1,writeFileSync as D1}from"node:fs";import{join as X$}from"node:path";class E{credPath;constructor($){let J=$??X$(process.env.HOME??"~",".loops-cli");this.credPath=X$(J,"credentials.json")}async login($){let J=X$(this.credPath,"..");if(!g(J))W1(J,{recursive:!0});let f={apiKey:$};D1(this.credPath,`${JSON.stringify(f,null,2)}
29
- `)}async logout(){if(g(this.credPath))V1(this.credPath)}async isAuthenticated(){return await this.getApiKey()!==null}async getApiKey($){if($)return $;try{if(g(this.credPath)){let J=m$(this.credPath,"utf-8");return JSON.parse(J).apiKey??null}}catch{}return null}async status(){try{if(g(this.credPath)){let $=m$(this.credPath,"utf-8"),f=JSON.parse($).apiKey;return{authenticated:!0,keyPrefix:f.length>20?`${f.slice(0,14)}...${f.slice(-3)}`:f}}}catch{}return{authenticated:!1}}}var I1=class extends Error{limit;remaining;constructor($,J){super(`Rate limit of ${$} requests per second exceeded.`);this.name="RateLimitExceededError",this.limit=$,this.remaining=J}},d$=class $ extends Error{statusCode;json;rawBody;constructor(J,f,R){let T;if(f!==null){if("error"in f&&typeof f.error==="object"&&f.error?.message)T=f.error.message;else if("error"in f&&typeof f.error==="string")T=f.error;else if("message"in f&&typeof f.message==="string")T=f.message}super(`${J}${T?` - ${T}`:""}`);if(this.name="APIError",this.statusCode=J,this.json=f,this.rawBody=R,Error.captureStackTrace)Error.captureStackTrace(this,$)}},N=class extends Error{constructor($){super($);this.name="ValidationError"}},t$=class{apiKey;apiRoot="https://app.loops.so/api/";constructor($){if(!$)throw Error("API key is required");this.apiKey=$}async _makeQuery({path:$,method:J="GET",headers:f,payload:R,params:T}){let q=new Headers;if(q.set("Authorization",`Bearer ${this.apiKey}`),q.set("Content-Type","application/json"),f)Object.entries(f).forEach(([Q,G])=>{if(G!==""&&G!==void 0&&G!==null)q.set(Q,G)});let X=new URL($,this.apiRoot);if(T&&J==="GET")Object.entries(T).forEach(([Q,G])=>X.searchParams.append(Q,G));let z=await fetch(X.href,{method:J,headers:q,body:R?JSON.stringify(R):void 0});if(z.status===429){let Q=parseInt(z.headers.get("x-ratelimit-limit")||"10",10),G=parseInt(z.headers.get("x-ratelimit-remaining")||"10",10);throw new I1(Q,G)}let M=await z.text(),Z=null;try{Z=JSON.parse(M)}catch{}if(!z.ok)throw new d$(z.status,Z,Z===null?M:void 0);if(Z===null)throw new d$(z.status,null,M);return Z}async testApiKey(){return this._makeQuery({path:"v1/api-key"})}async createContact({email:$,properties:J,mailingLists:f}){let R={...J,mailingLists:f};return R.email=$,this._makeQuery({path:"v1/contacts/create",method:"POST",payload:R})}async updateContact({email:$,userId:J,properties:f,mailingLists:R}){if(!J&&!$)throw new N("You must provide an `email` or `userId` value.");let T={...f,mailingLists:R};if($)T.email=$;if(J)T.userId=J;return this._makeQuery({path:"v1/contacts/update",method:"PUT",payload:T})}async findContact({email:$,userId:J}){if($&&J)throw new N("Only one parameter is permitted.");if(!$&&!J)throw new N("You must provide an `email` or `userId` value.");let f={};if($)f.email=$;else if(J)f.userId=J;return this._makeQuery({path:"v1/contacts/find",params:f})}async deleteContact({email:$,userId:J}){if($&&J)throw new N("Only one parameter is permitted.");if(!$&&!J)throw new N("You must provide an `email` or `userId` value.");let f={};if($)f.email=$;else if(J)f.userId=J;return this._makeQuery({path:"v1/contacts/delete",method:"POST",payload:f})}async createContactProperty($,J){return this._makeQuery({path:"v1/contacts/properties",method:"POST",payload:{name:$,type:J}})}async getCustomProperties($){return this._makeQuery({path:"v1/contacts/properties",params:{list:$||"all"}})}async getMailingLists(){return this._makeQuery({path:"v1/lists"})}async sendEvent({email:$,userId:J,eventName:f,contactProperties:R,eventProperties:T,mailingLists:q,headers:X}){if(!J&&!$)throw new N("You must provide an `email` or `userId` value.");let z={eventName:f,...R,eventProperties:T,mailingLists:q};if($)z.email=$;if(J)z.userId=J;return this._makeQuery({path:"v1/events/send",method:"POST",headers:X,payload:z})}async sendTransactionalEmail({transactionalId:$,email:J,addToAudience:f,dataVariables:R,attachments:T,headers:q}){let X={transactionalId:$,email:J,addToAudience:f,dataVariables:R,attachments:T};return this._makeQuery({path:"v1/transactional",method:"POST",headers:q,payload:X})}async getTransactionalEmails({perPage:$,cursor:J}={}){let f={perPage:($||20).toString()};if(J)f.cursor=J;return this._makeQuery({path:"v1/transactional",params:f})}};function l$($){if(!$.apiKey)throw Error("API key is required. Run 'loops auth login' or set LOOPS_API_KEY.");return new t$($.apiKey)}function i$($){if(typeof $==="string"){if($.length>80)$=`${$.slice(0,80)}...`;if($.includes(" "))return`"${$}"`;return $}if(typeof $==="boolean"||typeof $==="number")return String($);return String($)}function E1($){if(typeof $!=="string")return!1;return/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test($)}function n$($){return $.slice(0,10)}function z$($,J=""){let f=[];for(let[R,T]of Object.entries($)){let q=J?`${J}.${R}`:R;if(T===null||T===void 0||T==="")continue;if(T instanceof Date){f.push([q,n$(T.toISOString())]);continue}if(Array.isArray(T)){f.push([q,T.length]);continue}if(typeof T==="object"&&T!==null){f.push(...z$(T,q));continue}if(E1(T)){f.push([q,n$(T)]);continue}f.push([q,T])}return f}function p$($,J){if(!J)return $;return $.filter(([f])=>J.includes(f))}function s$($,J,f){let R=z$(J),q=p$(R,f?.fields).map(([X,z])=>`${X}=${i$(z)}`);return`${$} ${q.join(" ")}`}function a$($,J,f){let{items:R,pagination:T}=J,{page:q,limit:X,totalCount:z}=T;if(z===0&&R.length===0)return`${$} 0/0`;let M=(q-1)*X+1,Z=M+R.length-1,G=[`${$} ${M}-${Z}/${z} page=${q}`];for(let B=0;B<R.length;B++){let D=R[B]??{},v=z$(D),a=p$(v,f?.fields).map(([o,W])=>`${o}=${i$(W)}`);G.push(` [${B+1}] ${a.join(" ")}`)}if(Z<z)G.push(`next: loops ${$} list --page ${q+1} --limit ${X}`);return G.join(`
30
- `)}function o$($){return String($)}function N1($){if(typeof $!=="string")return!1;return/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test($)}function r$($){return $.slice(0,10)}function w1($){if($===null||$===void 0)return"";if($ instanceof Date)return r$($.toISOString());if(Array.isArray($))return`[${$.length}]`;if(typeof $==="object"&&$!==null){let J=$;if("id"in J)return String(J.id);return`{${Object.keys(J).length} keys}`}if(N1($))return r$($);return String($)}function e$($,J){if($.includes(J)||$.includes(`
31
- `)||$.includes('"'))return`"${$.replace(/"/g,'""')}"`;return $}function m($,J){if($.length===0)return"";let f=J?.delimiter??",",R=[];for(let X of $)for(let z of Object.keys(X))if(!R.includes(z))R.push(z);let T=R.map((X)=>e$(X,f)).join(f),q=$.map((X)=>R.map((z)=>e$(w1(X[z]),f)).join(f));return[T,...q].join(`
32
- `)}function Z$($){return m($,{delimiter:"\t"})}var F1={contact:["id","email","firstName","lastName","source","subscribed"],contacts:["id","email","firstName","lastName","source","subscribed"],contactProperty:["key","label","type"],contactProperties:["key","label","type"],mailingList:["id","name","isPublic"],mailingLists:["id","name","isPublic"],transactionalEmail:["id","name","dataVariables"],transactionalEmails:["id","name","dataVariables"],event:["email","eventName","success"],events:["email","eventName","success"],apiKey:["success","teamName"],apiKeys:["success","teamName"]};function Q$($){return F1[$]??["id"]}function M$($,J){if(J==="all")return{...$};if(J==="minimal"){let R={id:$.id},T=["name","email","key","label"];for(let q of T)if(q in $&&$[q]!==null&&$[q]!==void 0){R[q]=$[q];break}return R}let f={};for(let R of J)if(R in $)f[R]=$[R];if(Object.keys(f).length===0)return{...$};return f}function $0($){return JSON.stringify($)}function J0($){return $.map((J)=>JSON.stringify(J)).join(`
33
- `)}function f0($,J){return JSON.stringify({items:$,pagination:J})}var R0=($=0)=>(J)=>`\x1B[${J+$}m`,T0=($=0)=>(J)=>`\x1B[${38+$};5;${J}m`,q0=($=0)=>(J,f,R)=>`\x1B[${38+$};2;${J};${f};${R}m`,H={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},i2=Object.keys(H.modifier),k1=Object.keys(H.color),O1=Object.keys(H.bgColor),p2=[...k1,...O1];function A1(){let $=new Map;for(let[J,f]of Object.entries(H)){for(let[R,T]of Object.entries(f))H[R]={open:`\x1B[${T[0]}m`,close:`\x1B[${T[1]}m`},f[R]=H[R],$.set(T[0],T[1]);Object.defineProperty(H,J,{value:f,enumerable:!1})}return Object.defineProperty(H,"codes",{value:$,enumerable:!1}),H.color.close="\x1B[39m",H.bgColor.close="\x1B[49m",H.color.ansi=R0(),H.color.ansi256=T0(),H.color.ansi16m=q0(),H.bgColor.ansi=R0(10),H.bgColor.ansi256=T0(10),H.bgColor.ansi16m=q0(10),Object.defineProperties(H,{rgbToAnsi256:{value(J,f,R){if(J===f&&f===R){if(J<8)return 16;if(J>248)return 231;return Math.round((J-8)/247*24)+232}return 16+36*Math.round(J/255*5)+6*Math.round(f/255*5)+Math.round(R/255*5)},enumerable:!1},hexToRgb:{value(J){let f=/[a-f\d]{6}|[a-f\d]{3}/i.exec(J.toString(16));if(!f)return[0,0,0];let[R]=f;if(R.length===3)R=[...R].map((q)=>q+q).join("");let T=Number.parseInt(R,16);return[T>>16&255,T>>8&255,T&255]},enumerable:!1},hexToAnsi256:{value:(J)=>H.rgbToAnsi256(...H.hexToRgb(J)),enumerable:!1},ansi256ToAnsi:{value(J){if(J<8)return 30+J;if(J<16)return 90+(J-8);let f,R,T;if(J>=232)f=((J-232)*10+8)/255,R=f,T=f;else{J-=16;let z=J%36;f=Math.floor(J/36)/5,R=Math.floor(z/6)/5,T=z%6/5}let q=Math.max(f,R,T)*2;if(q===0)return 30;let X=30+(Math.round(T)<<2|Math.round(R)<<1|Math.round(f));if(q===2)X+=60;return X},enumerable:!1},rgbToAnsi:{value:(J,f,R)=>H.ansi256ToAnsi(H.rgbToAnsi256(J,f,R)),enumerable:!1},hexToAnsi:{value:(J)=>H.ansi256ToAnsi(H.hexToAnsi256(J)),enumerable:!1}}),H}var x1=A1(),K=x1;import G$ from"node:process";import y1 from"node:os";import X0 from"node:tty";function P($,J=globalThis.Deno?globalThis.Deno.args:G$.argv){let f=$.startsWith("-")?"":$.length===1?"-":"--",R=J.indexOf(f+$),T=J.indexOf("--");return R!==-1&&(T===-1||R<T)}var{env:U}=G$,d;if(P("no-color")||P("no-colors")||P("color=false")||P("color=never"))d=0;else if(P("color")||P("colors")||P("color=true")||P("color=always"))d=1;function b1(){if("FORCE_COLOR"in U){if(U.FORCE_COLOR==="true")return 1;if(U.FORCE_COLOR==="false")return 0;return U.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(U.FORCE_COLOR,10),3)}}function C1($){if($===0)return!1;return{level:$,hasBasic:!0,has256:$>=2,has16m:$>=3}}function h1($,{streamIsTTY:J,sniffFlags:f=!0}={}){let R=b1();if(R!==void 0)d=R;let T=f?d:R;if(T===0)return 0;if(f){if(P("color=16m")||P("color=full")||P("color=truecolor"))return 3;if(P("color=256"))return 2}if("TF_BUILD"in U&&"AGENT_NAME"in U)return 1;if($&&!J&&T===void 0)return 0;let q=T||0;if(U.TERM==="dumb")return q;if(G$.platform==="win32"){let X=y1.release().split(".");if(Number(X[0])>=10&&Number(X[2])>=10586)return Number(X[2])>=14931?3:2;return 1}if("CI"in U){if(["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some((X)=>(X in U)))return 3;if(["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some((X)=>(X in U))||U.CI_NAME==="codeship")return 1;return q}if("TEAMCITY_VERSION"in U)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(U.TEAMCITY_VERSION)?1:0;if(U.COLORTERM==="truecolor")return 3;if(U.TERM==="xterm-kitty")return 3;if(U.TERM==="xterm-ghostty")return 3;if(U.TERM==="wezterm")return 3;if("TERM_PROGRAM"in U){let X=Number.parseInt((U.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(U.TERM_PROGRAM){case"iTerm.app":return X>=3?3:2;case"Apple_Terminal":return 2}}if(/-256(color)?$/i.test(U.TERM))return 2;if(/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(U.TERM))return 1;if("COLORTERM"in U)return 1;return q}function z0($,J={}){let f=h1($,{streamIsTTY:$&&$.isTTY,...J});return C1(f)}var v1={stdout:z0({isTTY:X0.isatty(1)}),stderr:z0({isTTY:X0.isatty(2)})},Z0=v1;function Q0($,J,f){let R=$.indexOf(J);if(R===-1)return $;let T=J.length,q=0,X="";do X+=$.slice(q,R)+J+f,q=R+T,R=$.indexOf(J,q);while(R!==-1);return X+=$.slice(q),X}function M0($,J,f,R){let T=0,q="";do{let X=$[R-1]==="\r";q+=$.slice(T,X?R-1:R)+J+(X?`\r
28
+ `)}),this}_outputHelpIfRequested($){let J=this._getHelpOption();if(J&&$.find((R)=>J.is(R)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function x$($){return $.map((J)=>{if(!J.startsWith("--inspect"))return J;let f,R="127.0.0.1",T="9229",q;if((q=J.match(/^(--inspect(-brk)?)$/))!==null)f=q[1];else if((q=J.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(f=q[1],/^\d+$/.test(q[3]))T=q[3];else R=q[3];else if((q=J.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)f=q[1],R=q[3],T=q[4];if(f&&T!=="0")return`${f}=${R}:${parseInt(T)+1}`;return J})}function R$(){if(L.env.NO_COLOR||L.env.FORCE_COLOR==="0"||L.env.FORCE_COLOR==="false")return!1;if(L.env.FORCE_COLOR||L.env.CLICOLOR_FORCE!==void 0)return!0;return}z1.Command=T$;z1.useColor=R$});var v$=V((L1)=>{var{Argument:b$}=u(),{Command:q$}=y$(),{CommanderError:M1,InvalidArgumentError:C$}=A(),{Help:G1}=e(),{Option:h$}=$$();L1.program=new q$;L1.createCommand=($)=>new q$($);L1.createOption=($,J)=>new h$($,J);L1.createArgument=($,J)=>new b$($,J);L1.Command=q$;L1.Option=h$;L1.Argument=b$;L1.Help=G1;L1.CommanderError=M1;L1.InvalidArgumentError=C$;L1.InvalidOptionArgumentError=C$});var u$=A0(v$(),1),{program:I2,createCommand:E2,createArgument:N2,createOption:w2,CommanderError:F2,InvalidArgumentError:k2,InvalidOptionArgumentError:O2,Command:c$,Argument:A2,Option:x2,Help:y2}=u$.default;var g$={name:"@miketromba/loops-cli",version:"0.1.1",description:"CLI for the Loops email marketing API — manage contacts, send events, transactional emails, and more from the command line. AI-agent optimized output.",type:"module",bin:{loops:"./dist/loops.js"},files:["dist","README.md","LICENSE"],scripts:{dev:"bun run bin/loops.ts",build:"bun run scripts/build.ts",test:"bun test tests/unit tests/integration","test:watch":"bun test --watch","test:unit":"bun test tests/unit","test:integration":"bun test tests/integration","test:e2e":"bun test tests/e2e",lint:"bunx biome check .","lint:fix":"bunx biome check --write .",format:"bunx biome format --write .",typecheck:"bunx tsc --noEmit",prepublishOnly:"bun run lint && bun run typecheck && bun test && bun run build",loops:"bun run bin/loops.ts",prepare:"husky"},keywords:["loops","email","marketing","transactional","cli","contacts","mailing-lists","events","api"],license:"MIT",repository:{type:"git",url:"https://github.com/miketromba/loops-cli"},engines:{node:">=18.0.0"},devDependencies:{"@biomejs/biome":"^2.4.1","@types/bun":"latest",husky:"^9.1.7"},peerDependencies:{typescript:"^5"},dependencies:{loops:"^6.2.1",chalk:"^5.6.2",commander:"^14.0.3"},publishConfig:{access:"public"}};import{existsSync as g,mkdirSync as I1,readFileSync as m$,unlinkSync as E1,writeFileSync as N1}from"node:fs";import{join as X$}from"node:path";class E{credPath;constructor($){let J=$??X$(process.env.HOME??"~",".loops-cli");this.credPath=X$(J,"credentials.json")}async login($){let J=X$(this.credPath,"..");if(!g(J))I1(J,{recursive:!0});let f={apiKey:$};N1(this.credPath,`${JSON.stringify(f,null,2)}
29
+ `)}async logout(){if(g(this.credPath))E1(this.credPath)}async isAuthenticated(){return await this.getApiKey()!==null}async getApiKey($){if($)return $;try{if(g(this.credPath)){let J=m$(this.credPath,"utf-8");return JSON.parse(J).apiKey??null}}catch{}return null}async status(){try{if(g(this.credPath)){let $=m$(this.credPath,"utf-8"),f=JSON.parse($).apiKey;return{authenticated:!0,keyPrefix:f.length>20?`${f.slice(0,14)}...${f.slice(-3)}`:f}}}catch{}return{authenticated:!1}}}var w1=class extends Error{limit;remaining;constructor($,J){super(`Rate limit of ${$} requests per second exceeded.`);this.name="RateLimitExceededError",this.limit=$,this.remaining=J}},d$=class $ extends Error{statusCode;json;rawBody;constructor(J,f,R){let T;if(f!==null){if("error"in f&&typeof f.error==="object"&&f.error?.message)T=f.error.message;else if("error"in f&&typeof f.error==="string")T=f.error;else if("message"in f&&typeof f.message==="string")T=f.message}super(`${J}${T?` - ${T}`:""}`);if(this.name="APIError",this.statusCode=J,this.json=f,this.rawBody=R,Error.captureStackTrace)Error.captureStackTrace(this,$)}},N=class extends Error{constructor($){super($);this.name="ValidationError"}},t$=class{apiKey;apiRoot="https://app.loops.so/api/";constructor($){if(!$)throw Error("API key is required");this.apiKey=$}async _makeQuery({path:$,method:J="GET",headers:f,payload:R,params:T}){let q=new Headers;if(q.set("Authorization",`Bearer ${this.apiKey}`),q.set("Content-Type","application/json"),f)Object.entries(f).forEach(([Q,G])=>{if(G!==""&&G!==void 0&&G!==null)q.set(Q,G)});let X=new URL($,this.apiRoot);if(T&&J==="GET")Object.entries(T).forEach(([Q,G])=>X.searchParams.append(Q,G));let z=await fetch(X.href,{method:J,headers:q,body:R?JSON.stringify(R):void 0});if(z.status===429){let Q=parseInt(z.headers.get("x-ratelimit-limit")||"10",10),G=parseInt(z.headers.get("x-ratelimit-remaining")||"10",10);throw new w1(Q,G)}let M=await z.text(),Z=null;try{Z=JSON.parse(M)}catch{}if(!z.ok)throw new d$(z.status,Z,Z===null?M:void 0);if(Z===null)throw new d$(z.status,null,M);return Z}async testApiKey(){return this._makeQuery({path:"v1/api-key"})}async createContact({email:$,properties:J,mailingLists:f}){let R={...J,mailingLists:f};return R.email=$,this._makeQuery({path:"v1/contacts/create",method:"POST",payload:R})}async updateContact({email:$,userId:J,properties:f,mailingLists:R}){if(!J&&!$)throw new N("You must provide an `email` or `userId` value.");let T={...f,mailingLists:R};if($)T.email=$;if(J)T.userId=J;return this._makeQuery({path:"v1/contacts/update",method:"PUT",payload:T})}async findContact({email:$,userId:J}){if($&&J)throw new N("Only one parameter is permitted.");if(!$&&!J)throw new N("You must provide an `email` or `userId` value.");let f={};if($)f.email=$;else if(J)f.userId=J;return this._makeQuery({path:"v1/contacts/find",params:f})}async deleteContact({email:$,userId:J}){if($&&J)throw new N("Only one parameter is permitted.");if(!$&&!J)throw new N("You must provide an `email` or `userId` value.");let f={};if($)f.email=$;else if(J)f.userId=J;return this._makeQuery({path:"v1/contacts/delete",method:"POST",payload:f})}async createContactProperty($,J){return this._makeQuery({path:"v1/contacts/properties",method:"POST",payload:{name:$,type:J}})}async getCustomProperties($){return this._makeQuery({path:"v1/contacts/properties",params:{list:$||"all"}})}async getMailingLists(){return this._makeQuery({path:"v1/lists"})}async sendEvent({email:$,userId:J,eventName:f,contactProperties:R,eventProperties:T,mailingLists:q,headers:X}){if(!J&&!$)throw new N("You must provide an `email` or `userId` value.");let z={eventName:f,...R,eventProperties:T,mailingLists:q};if($)z.email=$;if(J)z.userId=J;return this._makeQuery({path:"v1/events/send",method:"POST",headers:X,payload:z})}async sendTransactionalEmail({transactionalId:$,email:J,addToAudience:f,dataVariables:R,attachments:T,headers:q}){let X={transactionalId:$,email:J,addToAudience:f,dataVariables:R,attachments:T};return this._makeQuery({path:"v1/transactional",method:"POST",headers:q,payload:X})}async getTransactionalEmails({perPage:$,cursor:J}={}){let f={perPage:($||20).toString()};if(J)f.cursor=J;return this._makeQuery({path:"v1/transactional",params:f})}};function l$($){if(!$.apiKey)throw Error("API key is required. Run 'loops auth login' or set LOOPS_API_KEY.");return new t$($.apiKey)}function i$($){if(typeof $==="string"){if($.length>80)$=`${$.slice(0,80)}...`;if($.includes(" "))return`"${$}"`;return $}if(typeof $==="boolean"||typeof $==="number")return String($);return String($)}function F1($){if(typeof $!=="string")return!1;return/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test($)}function n$($){return $.slice(0,10)}function z$($,J=""){let f=[];for(let[R,T]of Object.entries($)){let q=J?`${J}.${R}`:R;if(T===null||T===void 0||T==="")continue;if(T instanceof Date){f.push([q,n$(T.toISOString())]);continue}if(Array.isArray(T)){f.push([q,T.length]);continue}if(typeof T==="object"&&T!==null){f.push(...z$(T,q));continue}if(F1(T)){f.push([q,n$(T)]);continue}f.push([q,T])}return f}function p$($,J){if(!J)return $;return $.filter(([f])=>J.includes(f))}function s$($,J,f){let R=z$(J),q=p$(R,f?.fields).map(([X,z])=>`${X}=${i$(z)}`);return`${$} ${q.join(" ")}`}function a$($,J,f){let{items:R,pagination:T}=J,{page:q,limit:X,totalCount:z}=T;if(z===0&&R.length===0)return`${$} 0/0`;let M=(q-1)*X+1,Z=M+R.length-1,G=[`${$} ${M}-${Z}/${z} page=${q}`];for(let B=0;B<R.length;B++){let D=R[B]??{},v=z$(D),a=p$(v,f?.fields).map(([o,W])=>`${o}=${i$(W)}`);G.push(` [${B+1}] ${a.join(" ")}`)}if(Z<z)G.push(`next: loops ${$} list --page ${q+1} --limit ${X}`);return G.join(`
30
+ `)}function o$($){return String($)}function k1($){if(typeof $!=="string")return!1;return/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test($)}function r$($){return $.slice(0,10)}function O1($){if($===null||$===void 0)return"";if($ instanceof Date)return r$($.toISOString());if(Array.isArray($))return`[${$.length}]`;if(typeof $==="object"&&$!==null){let J=$;if("id"in J)return String(J.id);return`{${Object.keys(J).length} keys}`}if(k1($))return r$($);return String($)}function e$($,J){if($.includes(J)||$.includes(`
31
+ `)||$.includes('"'))return`"${$.replace(/"/g,'""')}"`;return $}function m($,J){if($.length===0)return"";let f=J?.delimiter??",",R=[];for(let X of $)for(let z of Object.keys(X))if(!R.includes(z))R.push(z);let T=R.map((X)=>e$(X,f)).join(f),q=$.map((X)=>R.map((z)=>e$(O1(X[z]),f)).join(f));return[T,...q].join(`
32
+ `)}function Z$($){return m($,{delimiter:"\t"})}var A1={contact:["id","email","firstName","lastName","source","subscribed"],contacts:["id","email","firstName","lastName","source","subscribed"],contactProperty:["key","label","type"],contactProperties:["key","label","type"],mailingList:["id","name","isPublic"],mailingLists:["id","name","isPublic"],transactionalEmail:["id","name","dataVariables"],transactionalEmails:["id","name","dataVariables"],event:["email","eventName","success"],events:["email","eventName","success"],apiKey:["success","teamName"],apiKeys:["success","teamName"]};function Q$($){return A1[$]??["id"]}function M$($,J){if(J==="all")return{...$};if(J==="minimal"){let R={id:$.id},T=["name","email","key","label"];for(let q of T)if(q in $&&$[q]!==null&&$[q]!==void 0){R[q]=$[q];break}return R}let f={};for(let R of J)if(R in $)f[R]=$[R];if(Object.keys(f).length===0)return{...$};return f}function $0($){return JSON.stringify($)}function J0($){return $.map((J)=>JSON.stringify(J)).join(`
33
+ `)}function f0($,J){return JSON.stringify({items:$,pagination:J})}var R0=($=0)=>(J)=>`\x1B[${J+$}m`,T0=($=0)=>(J)=>`\x1B[${38+$};5;${J}m`,q0=($=0)=>(J,f,R)=>`\x1B[${38+$};2;${J};${f};${R}m`,H={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},a2=Object.keys(H.modifier),x1=Object.keys(H.color),y1=Object.keys(H.bgColor),o2=[...x1,...y1];function b1(){let $=new Map;for(let[J,f]of Object.entries(H)){for(let[R,T]of Object.entries(f))H[R]={open:`\x1B[${T[0]}m`,close:`\x1B[${T[1]}m`},f[R]=H[R],$.set(T[0],T[1]);Object.defineProperty(H,J,{value:f,enumerable:!1})}return Object.defineProperty(H,"codes",{value:$,enumerable:!1}),H.color.close="\x1B[39m",H.bgColor.close="\x1B[49m",H.color.ansi=R0(),H.color.ansi256=T0(),H.color.ansi16m=q0(),H.bgColor.ansi=R0(10),H.bgColor.ansi256=T0(10),H.bgColor.ansi16m=q0(10),Object.defineProperties(H,{rgbToAnsi256:{value(J,f,R){if(J===f&&f===R){if(J<8)return 16;if(J>248)return 231;return Math.round((J-8)/247*24)+232}return 16+36*Math.round(J/255*5)+6*Math.round(f/255*5)+Math.round(R/255*5)},enumerable:!1},hexToRgb:{value(J){let f=/[a-f\d]{6}|[a-f\d]{3}/i.exec(J.toString(16));if(!f)return[0,0,0];let[R]=f;if(R.length===3)R=[...R].map((q)=>q+q).join("");let T=Number.parseInt(R,16);return[T>>16&255,T>>8&255,T&255]},enumerable:!1},hexToAnsi256:{value:(J)=>H.rgbToAnsi256(...H.hexToRgb(J)),enumerable:!1},ansi256ToAnsi:{value(J){if(J<8)return 30+J;if(J<16)return 90+(J-8);let f,R,T;if(J>=232)f=((J-232)*10+8)/255,R=f,T=f;else{J-=16;let z=J%36;f=Math.floor(J/36)/5,R=Math.floor(z/6)/5,T=z%6/5}let q=Math.max(f,R,T)*2;if(q===0)return 30;let X=30+(Math.round(T)<<2|Math.round(R)<<1|Math.round(f));if(q===2)X+=60;return X},enumerable:!1},rgbToAnsi:{value:(J,f,R)=>H.ansi256ToAnsi(H.rgbToAnsi256(J,f,R)),enumerable:!1},hexToAnsi:{value:(J)=>H.ansi256ToAnsi(H.hexToAnsi256(J)),enumerable:!1}}),H}var C1=b1(),K=C1;import G$ from"node:process";import h1 from"node:os";import X0 from"node:tty";function P($,J=globalThis.Deno?globalThis.Deno.args:G$.argv){let f=$.startsWith("-")?"":$.length===1?"-":"--",R=J.indexOf(f+$),T=J.indexOf("--");return R!==-1&&(T===-1||R<T)}var{env:U}=G$,d;if(P("no-color")||P("no-colors")||P("color=false")||P("color=never"))d=0;else if(P("color")||P("colors")||P("color=true")||P("color=always"))d=1;function v1(){if("FORCE_COLOR"in U){if(U.FORCE_COLOR==="true")return 1;if(U.FORCE_COLOR==="false")return 0;return U.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(U.FORCE_COLOR,10),3)}}function u1($){if($===0)return!1;return{level:$,hasBasic:!0,has256:$>=2,has16m:$>=3}}function c1($,{streamIsTTY:J,sniffFlags:f=!0}={}){let R=v1();if(R!==void 0)d=R;let T=f?d:R;if(T===0)return 0;if(f){if(P("color=16m")||P("color=full")||P("color=truecolor"))return 3;if(P("color=256"))return 2}if("TF_BUILD"in U&&"AGENT_NAME"in U)return 1;if($&&!J&&T===void 0)return 0;let q=T||0;if(U.TERM==="dumb")return q;if(G$.platform==="win32"){let X=h1.release().split(".");if(Number(X[0])>=10&&Number(X[2])>=10586)return Number(X[2])>=14931?3:2;return 1}if("CI"in U){if(["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some((X)=>(X in U)))return 3;if(["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some((X)=>(X in U))||U.CI_NAME==="codeship")return 1;return q}if("TEAMCITY_VERSION"in U)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(U.TEAMCITY_VERSION)?1:0;if(U.COLORTERM==="truecolor")return 3;if(U.TERM==="xterm-kitty")return 3;if(U.TERM==="xterm-ghostty")return 3;if(U.TERM==="wezterm")return 3;if("TERM_PROGRAM"in U){let X=Number.parseInt((U.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(U.TERM_PROGRAM){case"iTerm.app":return X>=3?3:2;case"Apple_Terminal":return 2}}if(/-256(color)?$/i.test(U.TERM))return 2;if(/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(U.TERM))return 1;if("COLORTERM"in U)return 1;return q}function z0($,J={}){let f=c1($,{streamIsTTY:$&&$.isTTY,...J});return u1(f)}var g1={stdout:z0({isTTY:X0.isatty(1)}),stderr:z0({isTTY:X0.isatty(2)})},Z0=g1;function Q0($,J,f){let R=$.indexOf(J);if(R===-1)return $;let T=J.length,q=0,X="";do X+=$.slice(q,R)+J+f,q=R+T,R=$.indexOf(J,q);while(R!==-1);return X+=$.slice(q),X}function M0($,J,f,R){let T=0,q="";do{let X=$[R-1]==="\r";q+=$.slice(T,X?R-1:R)+J+(X?`\r
34
34
  `:`
35
35
  `)+f,T=R+1,R=$.indexOf(`
36
- `,T)}while(R!==-1);return q+=$.slice(T),q}var{stdout:G0,stderr:L0}=Z0,L$=Symbol("GENERATOR"),w=Symbol("STYLER"),x=Symbol("IS_EMPTY"),H0=["ansi","ansi","ansi256","ansi16m"],F=Object.create(null),u1=($,J={})=>{if(J.level&&!(Number.isInteger(J.level)&&J.level>=0&&J.level<=3))throw Error("The `level` option should be an integer from 0 to 3");let f=G0?G0.level:0;$.level=J.level===void 0?f:J.level};var c1=($)=>{let J=(...f)=>f.join(" ");return u1(J,$),Object.setPrototypeOf(J,y.prototype),J};function y($){return c1($)}Object.setPrototypeOf(y.prototype,Function.prototype);for(let[$,J]of Object.entries(K))F[$]={get(){let f=t(this,U$(J.open,J.close,this[w]),this[x]);return Object.defineProperty(this,$,{value:f}),f}};F.visible={get(){let $=t(this,this[w],!0);return Object.defineProperty(this,"visible",{value:$}),$}};var H$=($,J,f,...R)=>{if($==="rgb"){if(J==="ansi16m")return K[f].ansi16m(...R);if(J==="ansi256")return K[f].ansi256(K.rgbToAnsi256(...R));return K[f].ansi(K.rgbToAnsi(...R))}if($==="hex")return H$("rgb",J,f,...K.hexToRgb(...R));return K[f][$](...R)},g1=["rgb","hex","ansi256"];for(let $ of g1){F[$]={get(){let{level:f}=this;return function(...R){let T=U$(H$($,H0[f],"color",...R),K.color.close,this[w]);return t(this,T,this[x])}}};let J="bg"+$[0].toUpperCase()+$.slice(1);F[J]={get(){let{level:f}=this;return function(...R){let T=U$(H$($,H0[f],"bgColor",...R),K.bgColor.close,this[w]);return t(this,T,this[x])}}}}var m1=Object.defineProperties(()=>{},{...F,level:{enumerable:!0,get(){return this[L$].level},set($){this[L$].level=$}}}),U$=($,J,f)=>{let R,T;if(f===void 0)R=$,T=J;else R=f.openAll+$,T=J+f.closeAll;return{open:$,close:J,openAll:R,closeAll:T,parent:f}},t=($,J,f)=>{let R=(...T)=>d1(R,T.length===1?""+T[0]:T.join(" "));return Object.setPrototypeOf(R,m1),R[L$]=$,R[w]=J,R[x]=f,R},d1=($,J)=>{if($.level<=0||!J)return $[x]?"":J;let f=$[w];if(f===void 0)return J;let{openAll:R,closeAll:T}=f;if(J.includes("\x1B"))while(f!==void 0)J=Q0(J,f.close,f.open),f=f.parent;let q=J.indexOf(`
37
- `);if(q!==-1)J=M0(J,T,R,q);return R+J+T};Object.defineProperties(y.prototype,F);var t1=y(),TJ=y({level:L0?L0.level:0});var l=t1;var Y$=40;function l1($){if(typeof $!=="string")return!1;return/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test($)}function U0($){return $.slice(0,10)}function Y0($){if($===null||$===void 0)return"";if($ instanceof Date)return U0($.toISOString());if(Array.isArray($))return`[${$.length}]`;if(typeof $==="object"&&$!==null){let f=$;if("id"in f)return String(f.id);return`{${Object.keys(f).length} keys}`}if(l1($))return U0($);let J=String($);if(J.length>Y$)return`${J.slice(0,Y$-3)}...`;return J}function B0($,J){if($.length===0)return"No results.";let f=!J?.noColor,R=[];for(let Z of $)for(let Q of Object.keys(Z))if(!R.includes(Q))R.push(Q);let T=$.map((Z)=>R.map((Q)=>Y0(Z[Q]))),q=R.map((Z,Q)=>{let G=T.reduce((S,B)=>Math.max(S,(B[Q]??"").length),0);return Math.max(Z.length,G)}),X=R.map((Z,Q)=>Z.padEnd(q[Q]??0)).join(" "),z=q.map((Z)=>"─".repeat(Z)).join(" "),M=T.map((Z)=>Z.map((Q,G)=>Q.padEnd(q[G]??0)).join(" "));if(f)return[l.bold(X),z,...M].join(`
36
+ `,T)}while(R!==-1);return q+=$.slice(T),q}var{stdout:G0,stderr:L0}=Z0,L$=Symbol("GENERATOR"),w=Symbol("STYLER"),x=Symbol("IS_EMPTY"),H0=["ansi","ansi","ansi256","ansi16m"],F=Object.create(null),m1=($,J={})=>{if(J.level&&!(Number.isInteger(J.level)&&J.level>=0&&J.level<=3))throw Error("The `level` option should be an integer from 0 to 3");let f=G0?G0.level:0;$.level=J.level===void 0?f:J.level};var d1=($)=>{let J=(...f)=>f.join(" ");return m1(J,$),Object.setPrototypeOf(J,y.prototype),J};function y($){return d1($)}Object.setPrototypeOf(y.prototype,Function.prototype);for(let[$,J]of Object.entries(K))F[$]={get(){let f=t(this,U$(J.open,J.close,this[w]),this[x]);return Object.defineProperty(this,$,{value:f}),f}};F.visible={get(){let $=t(this,this[w],!0);return Object.defineProperty(this,"visible",{value:$}),$}};var H$=($,J,f,...R)=>{if($==="rgb"){if(J==="ansi16m")return K[f].ansi16m(...R);if(J==="ansi256")return K[f].ansi256(K.rgbToAnsi256(...R));return K[f].ansi(K.rgbToAnsi(...R))}if($==="hex")return H$("rgb",J,f,...K.hexToRgb(...R));return K[f][$](...R)},t1=["rgb","hex","ansi256"];for(let $ of t1){F[$]={get(){let{level:f}=this;return function(...R){let T=U$(H$($,H0[f],"color",...R),K.color.close,this[w]);return t(this,T,this[x])}}};let J="bg"+$[0].toUpperCase()+$.slice(1);F[J]={get(){let{level:f}=this;return function(...R){let T=U$(H$($,H0[f],"bgColor",...R),K.bgColor.close,this[w]);return t(this,T,this[x])}}}}var l1=Object.defineProperties(()=>{},{...F,level:{enumerable:!0,get(){return this[L$].level},set($){this[L$].level=$}}}),U$=($,J,f)=>{let R,T;if(f===void 0)R=$,T=J;else R=f.openAll+$,T=J+f.closeAll;return{open:$,close:J,openAll:R,closeAll:T,parent:f}},t=($,J,f)=>{let R=(...T)=>n1(R,T.length===1?""+T[0]:T.join(" "));return Object.setPrototypeOf(R,l1),R[L$]=$,R[w]=J,R[x]=f,R},n1=($,J)=>{if($.level<=0||!J)return $[x]?"":J;let f=$[w];if(f===void 0)return J;let{openAll:R,closeAll:T}=f;if(J.includes("\x1B"))while(f!==void 0)J=Q0(J,f.close,f.open),f=f.parent;let q=J.indexOf(`
37
+ `);if(q!==-1)J=M0(J,T,R,q);return R+J+T};Object.defineProperties(y.prototype,F);var i1=y(),zJ=y({level:L0?L0.level:0});var l=i1;var Y$=40;function p1($){if(typeof $!=="string")return!1;return/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test($)}function U0($){return $.slice(0,10)}function Y0($){if($===null||$===void 0)return"";if($ instanceof Date)return U0($.toISOString());if(Array.isArray($))return`[${$.length}]`;if(typeof $==="object"&&$!==null){let f=$;if("id"in f)return String(f.id);return`{${Object.keys(f).length} keys}`}if(p1($))return U0($);let J=String($);if(J.length>Y$)return`${J.slice(0,Y$-3)}...`;return J}function B0($,J){if($.length===0)return"No results.";let f=!J?.noColor,R=[];for(let Z of $)for(let Q of Object.keys(Z))if(!R.includes(Q))R.push(Q);let T=$.map((Z)=>R.map((Q)=>Y0(Z[Q]))),q=R.map((Z,Q)=>{let G=T.reduce((S,B)=>Math.max(S,(B[Q]??"").length),0);return Math.max(Z.length,G)}),X=R.map((Z,Q)=>Z.padEnd(q[Q]??0)).join(" "),z=q.map((Z)=>"─".repeat(Z)).join(" "),M=T.map((Z)=>Z.map((Q,G)=>Q.padEnd(q[G]??0)).join(" "));if(f)return[l.bold(X),z,...M].join(`
38
38
  `);return[X,z,...M].join(`
39
39
  `)}function S0($,J,f){let R=!f?.noColor,T=Object.entries(J);if(T.length===0)return`No ${$} data.`;let q=Math.max(...T.map(([G])=>G.length)),X=`${"─".repeat(q)} ${"─".repeat(Y$)}`,Z=`${"Key".padEnd(q)} ${"Value"}`,Q=T.map(([G,S])=>{let B=G.padEnd(q),D=Y0(S);if(R)return`${l.bold(B)} ${D}`;return`${B} ${D}`});if(R)return[l.bold(Z),X,...Q].join(`
40
40
  `);return[Z,X,...Q].join(`
41
41
  `)}function P0($,J,f){if($)return $;if(J)return J;return f?"table":"compact"}function n($,J,f,R){let T=Q$($),q=R.fields??T,X=J.map((M)=>M$(M,q)),z=R.fields!=null;switch(R.format){case"count":return o$(f.totalCount);case"id":return J.map((M)=>M.id).join(`
42
- `);case"json":return f0(z?X:J,f);case"jsonl":return J0(z?X:J);case"csv":return m(z?X:J);case"tsv":return Z$(z?X:J);case"table":return B0(X,{noColor:R.noColor});default:return a$($,{items:X,pagination:f},{fields:R.fields})}}function i($,J,f){let R=f.detail?"all":f.fields??Q$($),T=M$(J,R);switch(f.format){case"id":return String(J.id??"");case"json":return $0(f.fields||f.detail?T:J);case"csv":return m([T]);case"tsv":return Z$([T]);case"table":return S0($,T,{noColor:f.noColor});default:return s$($,T)}}function n1($){switch($.type){case"Unauthorized":return"Run 'loops auth login --api-key <your-key>' to authenticate. Get your key at https://app.loops.so/settings?page=api";case"Forbidden":return"Check that your API key has the required permissions";case"ResourceNotFound":return $.resource?`Run 'loops ${$.resource} list' to see available items`:"Verify the resource identifier is correct";case"ValidationError":return $.resource?`Run 'loops ${$.resource} --help' for required flags and usage`:"Check the flag values and try again";case"RateLimited":return"Wait a moment and try again. Loops allows 10 requests per second";case"ServerError":return"This is a Loops API issue. Try again later";case"ConnectionError":return"Check your network connection and try again";default:return}}function b($){let J=[];switch($.type){case"Unauthorized":if(J.push("Error: Not authenticated"),J.push(" Run 'loops auth login --api-key <your-key>' to authenticate."),J.push(" Get your key at https://app.loops.so/settings?page=api"),$.message&&$.message!=="No API key found"&&$.message!=="Unauthorized")J.push(` Detail: ${$.message}`);break;case"Forbidden":if(J.push(`Error: Access denied${$.resource?` for ${$.resource}`:""} (403)`),$.message)J.push(` Detail: ${$.message}`);J.push(" Hint: Check that your API key has the required permissions.");break;case"ResourceNotFound":if(J.push(`Error: ${$.resource??"Resource"} not found (404)`),$.id)J.push(` ID: ${$.id}`);if($.resource)J.push(` Hint: Run 'loops ${$.resource} list' to see available items.`);else J.push(" Hint: Verify the resource identifier is correct.");break;case"ValidationError":if(J.push("Error: Validation failed (422)"),$.fields)for(let[f,R]of Object.entries($.fields))J.push(` - ${f}: ${R}`);if($.message&&!$.fields)J.push(` Detail: ${$.message}`);break;case"RateLimited":J.push("Error: Rate limit exceeded (429)"),J.push(" Hint: Wait a moment and try again. Loops allows 10 requests per second.");break;case"ServerError":if(J.push(`Error: Loops API error (${$.code??500})`),$.message)J.push(` Detail: ${$.message}`);J.push(" Hint: This is a server-side issue. Try again later.");break;case"ConnectionError":if(J.push("Error: Could not connect to the Loops API"),$.message)J.push(` Detail: ${$.message}`);J.push(" Hint: Check your network connection and try again.");break;default:J.push(`Error: ${$.message??$.type}${$.code?` (${$.code})`:""}`);break}return J.join(`
43
- `)}function C($){let J=["error"];if($.code!==void 0)J.push(`code=${$.code}`);if(J.push(`type=${$.type}`),$.resource)J.push(`resource=${$.resource}`);if($.id)J.push(`id=${$.id}`);if($.fields){let R=Object.entries($.fields).map(([T,q])=>`${T}: ${q}`).join("; ");J.push(`fields="${R}"`)}if($.message)J.push(`message="${$.message.slice(0,200)}"`);let f=n1($);if(f)J.push(`hint="${f}"`);return J.join(" ")}function p($,J){let f=$.statusCode??$.status??$.response?.status,R=$.json?.message??$.json?.error??$.message??String($);if($.code==="ECONNREFUSED"||$.code==="ENOTFOUND"||$.code==="ETIMEDOUT"||$.cause?.code==="ECONNREFUSED"||$.cause?.code==="ENOTFOUND"||$.name==="TypeError"&&R.includes("fetch"))return{type:"ConnectionError",message:R.slice(0,200),resource:J};if($.constructor?.name==="RateLimitExceededError")return{type:"RateLimited",code:429,resource:J};switch(f){case 401:return{type:"Unauthorized",code:401,message:R.slice(0,200),resource:J};case 403:return{type:"Forbidden",code:403,message:R.slice(0,200),resource:J};case 404:return{type:"ResourceNotFound",code:404,resource:J,message:R.slice(0,200)};case 422:return{type:"ValidationError",code:422,resource:J,message:R.slice(0,200)};case 429:return{type:"RateLimited",code:429,resource:J};default:if(f&&f>=500)return{type:"ServerError",code:f,message:R.slice(0,200),resource:J};return{type:$.constructor?.name??"UnexpectedError",code:f,message:R.slice(0,200),resource:J}}}function h($,J){let f={};if($.flags)for(let R of $.flags){let T=J.flags[R.sdkField]??J.flags[R.name];if(T!==void 0&&T!==null)if(R.type==="json"&&typeof T==="string")try{f[R.sdkField]=JSON.parse(T)}catch{f[R.sdkField]=T}else f[R.sdkField]=T}return f}function B$($,J){if(!$.positionalFlags||!$.flags)return[];let f=h($,J);return $.positionalFlags.map((R)=>f[R])}async function K0($,J,f,R){let T=$[f.sdkMethod];if(!T){let q=process.stdout.isTTY??!1,X={type:"NotImplemented",resource:J.name,message:`Method '${f.sdkMethod}' is not available on the Loops client`};return{stdout:"",stderr:q?b(X):C(X),exitCode:1}}try{switch(f.type){case"list":{let q;if(f.positionalFlags){let Z=B$(f,R);q=await T.apply($,Z)}else if(f.flags?.length){let Z=h(f,R);q=await T.call($,Z)}else q=await T.call($);let X;if(Array.isArray(q))X=q;else if(q&&typeof q==="object"&&Array.isArray(q.data))X=q.data;else if(q)X=[q];else X=[];let z={page:1,limit:X.length,totalCount:X.length};return{stdout:n(J.plural,X,z,R.output),stderr:"",exitCode:0}}case"create":{let q;if(f.positionalFlags){let z=B$(f,R);q=await T.apply($,z)}else{let z=h(f,R);q=await T.call($,z)}return{stdout:i(J.name,q,R.output),stderr:"",exitCode:0}}case"update":{let q=h(f,R),X=await T.call($,q);return{stdout:i(J.name,X,R.output),stderr:"",exitCode:0}}case"custom":{let q;if(f.positionalFlags){let z=B$(f,R);q=await T.apply($,z)}else{let z=h(f,R);q=await T.call($,z)}if(q===void 0||q===null)return{stdout:`${f.sdkMethod} completed`,stderr:"",exitCode:0};if(Array.isArray(q)){let z=q,M={page:1,limit:z.length,totalCount:z.length};return{stdout:n(J.plural,z,M,R.output),stderr:"",exitCode:0}}if(typeof q==="object"&&Array.isArray(q.data)){let z=q.data,M={page:1,limit:z.length,totalCount:z.length};return{stdout:n(J.plural,z,M,R.output),stderr:"",exitCode:0}}return{stdout:i(J.name,q,R.output),stderr:"",exitCode:0}}default:return{stdout:"",stderr:`Unknown operation type: ${f.type}`,exitCode:1}}}catch(q){let X=p(q,J.name);return{stdout:"",stderr:process.stdout.isTTY??!1?b(X):C(X),exitCode:1}}}function i1($){return $.replace(/([A-Z])/g,"-$1").toLowerCase()}function p1($,J){for(let f of J){let R=i1(f.name),T=f.type==="boolean"?`--${R}`:`--${R} <value>`;if(f.required)$.requiredOption(T,f.description);else $.option(T,f.description)}}function s1($,J){let f={};if(!J)return f;for(let R of J){let T=$[R.sdkField]??$[R.name];if(T!==void 0)if(R.type==="number"&&typeof T==="string")f[R.sdkField]=Number.parseInt(T,10);else if(R.type==="boolean"&&typeof T==="string")f[R.sdkField]=T==="true";else if(R.type==="json"&&typeof T==="string")try{f[R.sdkField]=JSON.parse(T)}catch{f[R.sdkField]=T}else if(R.type==="string[]"&&typeof T==="string")f[R.sdkField]=T.split(",").map((q)=>q.trim());else f[R.sdkField]=T}return f}function a1($,J,f,R){let T=$.command(J.cliName).description(J.description);if(J.examples?.length)T.addHelpText("after",`
42
+ `);case"json":return f0(z?X:J,f);case"jsonl":return J0(z?X:J);case"csv":return m(z?X:J);case"tsv":return Z$(z?X:J);case"table":return B0(X,{noColor:R.noColor});default:return a$($,{items:X,pagination:f},{fields:R.fields})}}function i($,J,f){let R=f.detail?"all":f.fields??Q$($),T=M$(J,R);switch(f.format){case"id":return String(J.id??"");case"json":return $0(f.fields||f.detail?T:J);case"csv":return m([T]);case"tsv":return Z$([T]);case"table":return S0($,T,{noColor:f.noColor});default:return s$($,T)}}function s1($){switch($.type){case"Unauthorized":return"Run 'loops auth login --api-key <your-key>' to authenticate. Get your key at https://app.loops.so/settings?page=api";case"Forbidden":return"Check that your API key has the required permissions";case"ResourceNotFound":return $.resource?`Run 'loops ${$.resource} list' to see available items`:"Verify the resource identifier is correct";case"ValidationError":return $.resource?`Run 'loops ${$.resource} --help' for required flags and usage`:"Check the flag values and try again";case"RateLimited":return"Wait a moment and try again. Loops allows 10 requests per second";case"ServerError":return"This is a Loops API issue. Try again later";case"ConnectionError":return"Check your network connection and try again";default:return}}function b($){let J=[];switch($.type){case"Unauthorized":if(J.push("Error: Not authenticated"),J.push(" Run 'loops auth login --api-key <your-key>' to authenticate."),J.push(" Get your key at https://app.loops.so/settings?page=api"),$.message&&$.message!=="No API key found"&&$.message!=="Unauthorized")J.push(` Detail: ${$.message}`);break;case"Forbidden":if(J.push(`Error: Access denied${$.resource?` for ${$.resource}`:""} (403)`),$.message)J.push(` Detail: ${$.message}`);J.push(" Hint: Check that your API key has the required permissions.");break;case"ResourceNotFound":if(J.push(`Error: ${$.resource??"Resource"} not found (404)`),$.id)J.push(` ID: ${$.id}`);if($.resource)J.push(` Hint: Run 'loops ${$.resource} list' to see available items.`);else J.push(" Hint: Verify the resource identifier is correct.");break;case"ValidationError":if(J.push("Error: Validation failed (422)"),$.fields)for(let[f,R]of Object.entries($.fields))J.push(` - ${f}: ${R}`);if($.message&&!$.fields)J.push(` Detail: ${$.message}`);break;case"RateLimited":J.push("Error: Rate limit exceeded (429)"),J.push(" Hint: Wait a moment and try again. Loops allows 10 requests per second.");break;case"ServerError":if(J.push(`Error: Loops API error (${$.code??500})`),$.message)J.push(` Detail: ${$.message}`);J.push(" Hint: This is a server-side issue. Try again later.");break;case"ConnectionError":if(J.push("Error: Could not connect to the Loops API"),$.message)J.push(` Detail: ${$.message}`);J.push(" Hint: Check your network connection and try again.");break;default:J.push(`Error: ${$.message??$.type}${$.code?` (${$.code})`:""}`);break}return J.join(`
43
+ `)}function C($){let J=["error"];if($.code!==void 0)J.push(`code=${$.code}`);if(J.push(`type=${$.type}`),$.resource)J.push(`resource=${$.resource}`);if($.id)J.push(`id=${$.id}`);if($.fields){let R=Object.entries($.fields).map(([T,q])=>`${T}: ${q}`).join("; ");J.push(`fields="${R}"`)}if($.message)J.push(`message="${$.message.slice(0,200)}"`);let f=s1($);if(f)J.push(`hint="${f}"`);return J.join(" ")}function p($,J){let f=$.statusCode??$.status??$.response?.status,R=$.json?.message??$.json?.error??$.message??String($);if($.code==="ECONNREFUSED"||$.code==="ENOTFOUND"||$.code==="ETIMEDOUT"||$.cause?.code==="ECONNREFUSED"||$.cause?.code==="ENOTFOUND"||$.name==="TypeError"&&R.includes("fetch"))return{type:"ConnectionError",message:R.slice(0,200),resource:J};if($.constructor?.name==="RateLimitExceededError")return{type:"RateLimited",code:429,resource:J};switch(f){case 401:return{type:"Unauthorized",code:401,message:R.slice(0,200),resource:J};case 403:return{type:"Forbidden",code:403,message:R.slice(0,200),resource:J};case 404:return{type:"ResourceNotFound",code:404,resource:J,message:R.slice(0,200)};case 422:return{type:"ValidationError",code:422,resource:J,message:R.slice(0,200)};case 429:return{type:"RateLimited",code:429,resource:J};default:if(f&&f>=500)return{type:"ServerError",code:f,message:R.slice(0,200),resource:J};return{type:$.constructor?.name??"UnexpectedError",code:f,message:R.slice(0,200),resource:J}}}function h($,J){let f={};if($.flags)for(let R of $.flags){let T=J.flags[R.sdkField]??J.flags[R.name];if(T!==void 0&&T!==null)if(R.type==="json"&&typeof T==="string")try{f[R.sdkField]=JSON.parse(T)}catch{f[R.sdkField]=T}else f[R.sdkField]=T}return f}function B$($,J){if(!$.positionalFlags||!$.flags)return[];let f=h($,J);return $.positionalFlags.map((R)=>f[R])}async function K0($,J,f,R){let T=$[f.sdkMethod];if(!T){let q=process.stdout.isTTY??!1,X={type:"NotImplemented",resource:J.name,message:`Method '${f.sdkMethod}' is not available on the Loops client`};return{stdout:"",stderr:q?b(X):C(X),exitCode:1}}try{switch(f.type){case"list":{let q;if(f.positionalFlags){let Z=B$(f,R);q=await T.apply($,Z)}else if(f.flags?.length){let Z=h(f,R);q=await T.call($,Z)}else q=await T.call($);let X;if(Array.isArray(q))X=q;else if(q&&typeof q==="object"&&Array.isArray(q.data))X=q.data;else if(q)X=[q];else X=[];let z={page:1,limit:X.length,totalCount:X.length};return{stdout:n(J.plural,X,z,R.output),stderr:"",exitCode:0}}case"create":{let q;if(f.positionalFlags){let z=B$(f,R);q=await T.apply($,z)}else{let z=h(f,R);q=await T.call($,z)}return{stdout:i(J.name,q,R.output),stderr:"",exitCode:0}}case"update":{let q=h(f,R),X=await T.call($,q);return{stdout:i(J.name,X,R.output),stderr:"",exitCode:0}}case"custom":{let q;if(f.positionalFlags){let z=B$(f,R);q=await T.apply($,z)}else{let z=h(f,R);q=await T.call($,z)}if(q===void 0||q===null)return{stdout:`${f.sdkMethod} completed`,stderr:"",exitCode:0};if(Array.isArray(q)){let z=q,M={page:1,limit:z.length,totalCount:z.length};return{stdout:n(J.plural,z,M,R.output),stderr:"",exitCode:0}}if(typeof q==="object"&&Array.isArray(q.data)){let z=q.data,M={page:1,limit:z.length,totalCount:z.length};return{stdout:n(J.plural,z,M,R.output),stderr:"",exitCode:0}}return{stdout:i(J.name,q,R.output),stderr:"",exitCode:0}}default:return{stdout:"",stderr:`Unknown operation type: ${f.type}`,exitCode:1}}}catch(q){let X=p(q,J.name);return{stdout:"",stderr:process.stdout.isTTY??!1?b(X):C(X),exitCode:1}}}function a1($){return $.replace(/([A-Z])/g,"-$1").toLowerCase()}function o1($,J){for(let f of J){let R=a1(f.name),T=f.type==="boolean"?`--${R}`:`--${R} <value>`;if(f.required)$.requiredOption(T,f.description);else $.option(T,f.description)}}function r1($,J){let f={};if(!J)return f;for(let R of J){let T=$[R.sdkField]??$[R.name];if(T!==void 0)if(R.type==="number"&&typeof T==="string")f[R.sdkField]=Number.parseInt(T,10);else if(R.type==="boolean"&&typeof T==="string")f[R.sdkField]=T==="true";else if(R.type==="json"&&typeof T==="string")try{f[R.sdkField]=JSON.parse(T)}catch{f[R.sdkField]=T}else if(R.type==="string[]"&&typeof T==="string")f[R.sdkField]=T.split(",").map((q)=>q.trim());else f[R.sdkField]=T}return f}function e1($,J,f,R){let T=$.command(J.cliName).description(J.description);if(J.examples?.length)T.addHelpText("after",`
44
44
  Examples:
45
45
  ${J.examples.map((q)=>` $ ${q}`).join(`
46
- `)}`);for(let q of J.operations)o1(T,J,q,f,R)}function o1($,J,f,R,T){let q,X="";switch(f.type){case"list":q="list";break;case"get":q="get",X="<id>";break;case"create":q="create";break;case"update":q="update";break;case"delete":q="delete";break;case"custom":if(q=f.cliName??f.sdkMethod.replace(/([A-Z])/g,"-$1").toLowerCase().replace(/^-/,""),f.args)X=f.args.map((M)=>M.required?`<${M.name}>`:`[${M.name}]`).join(" ");break}let z=$.command(`${q}${X?` ${X}`:""}`).description(f.description);if(f.examples?.length)z.addHelpText("after",`
46
+ `)}`);for(let q of J.operations)$2(T,J,q,f,R)}function $2($,J,f,R,T){let q,X="";switch(f.type){case"list":q="list";break;case"get":q="get",X="<id>";break;case"create":q="create";break;case"update":q="update";break;case"delete":q="delete";break;case"custom":if(q=f.cliName??f.sdkMethod.replace(/([A-Z])/g,"-$1").toLowerCase().replace(/^-/,""),f.args)X=f.args.map((M)=>M.required?`<${M.name}>`:`[${M.name}]`).join(" ");break}let z=$.command(`${q}${X?` ${X}`:""}`).description(f.description);if(f.examples?.length)z.addHelpText("after",`
47
47
  Examples:
48
48
  ${f.examples.map((M)=>` $ ${M}`).join(`
49
- `)}`);if(f.flags)p1(z,f.flags);z.action(async(...M)=>{try{let Z=await R(),Q=T(),G={},B={...M[M.length-2]??{}};if(f.type==="get")G.id=M[0];else if(f.type==="custom"&&f.args)for(let I=0;I<f.args.length;I++){let j$=f.args[I];if(j$)G[j$.name]=M[I]}let D=s1(B,f.flags),v=process.stdout.isTTY??!1,_$=P0(Q.output,process.env.LOOPS_OUTPUT,v),a=Q.fields?.split(",").map((I)=>I.trim()),o={args:G,flags:D,output:{format:_$,fields:a,detail:Q.detail,quiet:Q.quiet,noColor:Q.noColor??!v}},W=await K0(Z,J,f,o);if(W.stdout)process.stdout.write(`${W.stdout}
49
+ `)}`);if(f.flags)o1(z,f.flags);z.action(async(...M)=>{try{let Z=await R(),Q=T(),G={},B={...M[M.length-2]??{}};if(f.type==="get")G.id=M[0];else if(f.type==="custom"&&f.args)for(let I=0;I<f.args.length;I++){let j$=f.args[I];if(j$)G[j$.name]=M[I]}let D=r1(B,f.flags),v=process.stdout.isTTY??!1,_$=P0(Q.output,process.env.LOOPS_OUTPUT,v),a=Q.fields?.split(",").map((I)=>I.trim()),o={args:G,flags:D,output:{format:_$,fields:a,detail:Q.detail,quiet:Q.quiet,noColor:Q.noColor??!v}},W=await K0(Z,J,f,o);if(W.stdout)process.stdout.write(`${W.stdout}
50
50
  `);if(W.stderr)process.stderr.write(`${W.stderr}
51
51
  `);process.exit(W.exitCode)}catch(Z){let Q=p(Z,J.name),G=process.stdout.isTTY??!1;process.stderr.write(`${G?b(Q):C(Q)}
52
- `),process.exit(Q.code===2?2:1)}})}function _0($,J,f,R){for(let T of J)a1($,T,f,R)}import{existsSync as j0,mkdirSync as r1,readFileSync as e1,writeFileSync as $2}from"node:fs";import{join as S$}from"node:path";var P$={output:"table",defaultLimit:25,noColor:!1},J2=new Set(["output","defaultLimit","noColor"]);class k{configPath;values;constructor($){let J=$??S$(process.env.HOME??"~",".loops-cli");this.configPath=S$(J,"config.json"),this.values={...P$},this.loadSync()}loadSync(){try{if(j0(this.configPath)){let $=e1(this.configPath,"utf-8"),J=JSON.parse($);this.values={...P$,...J}}}catch{}}async load(){this.loadSync()}get($){return this.values[$]}set($,J){if(!J2.has($))throw Error(`Invalid config key: ${String($)}`);this.values[$]=J,this.save()}list(){return{...this.values}}async reset(){this.values={...P$},this.save()}save(){let $=S$(this.configPath,"..");if(!j0($))r1($,{recursive:!0});$2(this.configPath,`${JSON.stringify(this.values,null,2)}
53
- `)}}function f2($,J,f,R,T){return{name:$,sdkField:J,type:f,description:R,...T?{required:T}:{}}}function R2($){return $.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function Y($,J,f,R){return f2(R2($),$,J,f,R)}var T2={name:"contact",plural:"contacts",cliName:"contacts",description:"Manage contacts in your Loops audience",defaultFields:["id","email","firstName","lastName","source","subscribed"],examples:["loops contacts create --email user@example.com",`loops contacts create --email user@example.com --properties '{"firstName":"Jane","lastName":"Doe"}'`,`loops contacts create --email user@example.com --mailing-lists '{"list_id":true}'`,`loops contacts update --email user@example.com --properties '{"firstName":"Updated"}'`,"loops contacts find --email user@example.com","loops contacts find --user-id usr_123","loops contacts delete --email user@example.com","loops contacts delete --user-id usr_123"],operations:[{type:"create",sdkMethod:"createContact",description:"Create a new contact",flags:[Y("email","string","Contact email address",!0),Y("properties","json","Contact properties (JSON object)"),Y("mailingLists","json","Mailing list subscriptions (JSON object)")]},{type:"update",sdkMethod:"updateContact",description:"Update an existing contact",flags:[Y("email","string","Contact email address"),Y("userId","string","Contact user ID"),Y("properties","json","Contact properties to update (JSON object)"),Y("mailingLists","json","Mailing list subscriptions (JSON object)")]},{type:"custom",sdkMethod:"findContact",cliName:"find",description:"Find a contact by email or user ID",flags:[Y("email","string","Contact email address"),Y("userId","string","Contact user ID")],examples:["loops contacts find --email user@example.com","loops contacts find --user-id usr_123"]},{type:"custom",sdkMethod:"deleteContact",cliName:"delete",description:"Delete a contact by email or user ID",flags:[Y("email","string","Contact email address"),Y("userId","string","Contact user ID")],examples:["loops contacts delete --email user@example.com","loops contacts delete --user-id usr_123"]}]},q2={name:"contactProperty",plural:"contactProperties",cliName:"contact-properties",description:"Manage contact properties (custom fields)",defaultFields:["key","label","type"],examples:["loops contact-properties list","loops contact-properties create --name favoriteColor --type string"],operations:[{type:"list",sdkMethod:"getCustomProperties",description:"List all contact properties"},{type:"create",sdkMethod:"createContactProperty",description:"Create a new contact property",positionalFlags:["name","type"],flags:[Y("name","string","Property name",!0),Y("type","string","Property type: string, number, boolean, date",!0)]}]},X2={name:"mailingList",plural:"mailingLists",cliName:"mailing-lists",description:"View mailing lists",defaultFields:["id","name","isPublic"],examples:["loops mailing-lists list","loops mailing-lists list --output json"],operations:[{type:"list",sdkMethod:"getMailingLists",description:"List all mailing lists"}]},z2={name:"event",plural:"events",cliName:"events",description:"Send events to trigger emails in Loops",defaultFields:["success"],examples:["loops events send --email user@example.com --event-name signup",`loops events send --email user@example.com --event-name purchase --event-properties '{"plan":"pro","amount":29}'`,`loops events send --email user@example.com --event-name signup --contact-properties '{"firstName":"Jane"}'`,`loops events send --email user@example.com --event-name signup --mailing-lists '{"list_id":true}'`],operations:[{type:"custom",sdkMethod:"sendEvent",cliName:"send",description:"Send an event for a contact",flags:[Y("email","string","Contact email address"),Y("userId","string","Contact user ID"),Y("eventName","string","Event name",!0),Y("eventProperties","json","Event properties (JSON object)"),Y("contactProperties","json","Contact properties to update (JSON object)"),Y("mailingLists","json","Mailing list subscriptions (JSON object)")]}]},Z2={name:"transactionalEmail",plural:"transactionalEmails",cliName:"transactional",description:"Send and manage transactional emails",defaultFields:["id","name","dataVariables"],examples:["loops transactional list","loops transactional send --transactional-id txn_123 --email user@example.com",`loops transactional send --transactional-id txn_123 --email user@example.com --data-variables '{"name":"Jane","url":"https://example.com"}'`,"loops transactional send --transactional-id txn_123 --email user@example.com --add-to-audience","loops transactional list --output json"],operations:[{type:"list",sdkMethod:"getTransactionalEmails",description:"List all transactional emails"},{type:"custom",sdkMethod:"sendTransactionalEmail",cliName:"send",description:"Send a transactional email",flags:[Y("transactionalId","string","Transactional email ID",!0),Y("email","string","Recipient email address",!0),Y("addToAudience","boolean","Add recipient to audience"),Y("dataVariables","json","Data variables for email template (JSON object)"),Y("attachments","json","File attachments (JSON array)")]}]},Q2={name:"apiKey",plural:"apiKeys",cliName:"api-key",description:"Test your API key",defaultFields:["success","teamName"],examples:["loops api-key test"],operations:[{type:"custom",sdkMethod:"testApiKey",cliName:"test",description:"Verify your API key is valid"}]},W0=[T2,q2,X2,z2,Z2,Q2];function M2($){switch($.type){case"Unauthorized":return"Run 'loops auth login --api-key <your-key>' to authenticate. Get your key at https://app.loops.so/settings?page=api";case"Forbidden":return"Check that your API key has the required permissions";case"ResourceNotFound":return $.resource?`Run 'loops ${$.resource} list' to see available items`:"Verify the resource identifier is correct";case"ValidationError":return $.resource?`Run 'loops ${$.resource} --help' for required flags and usage`:"Check the flag values and try again";case"RateLimited":return"Wait a moment and try again. Loops allows 10 requests per second";case"ServerError":return"This is a Loops API issue. Try again later";case"ConnectionError":return"Check your network connection and try again";default:return}}function V0($){let J=[];switch($.type){case"Unauthorized":if(J.push("Error: Not authenticated"),J.push(" Run 'loops auth login --api-key <your-key>' to authenticate."),J.push(" Get your key at https://app.loops.so/settings?page=api"),$.message&&$.message!=="No API key found"&&$.message!=="Unauthorized")J.push(` Detail: ${$.message}`);break;case"Forbidden":if(J.push(`Error: Access denied${$.resource?` for ${$.resource}`:""} (403)`),$.message)J.push(` Detail: ${$.message}`);J.push(" Hint: Check that your API key has the required permissions.");break;case"ResourceNotFound":if(J.push(`Error: ${$.resource??"Resource"} not found (404)`),$.id)J.push(` ID: ${$.id}`);if($.resource)J.push(` Hint: Run 'loops ${$.resource} list' to see available items.`);else J.push(" Hint: Verify the resource identifier is correct.");break;case"ValidationError":if(J.push("Error: Validation failed (422)"),$.fields)for(let[f,R]of Object.entries($.fields))J.push(` - ${f}: ${R}`);if($.message&&!$.fields)J.push(` Detail: ${$.message}`);break;case"RateLimited":J.push("Error: Rate limit exceeded (429)"),J.push(" Hint: Wait a moment and try again. Loops allows 10 requests per second.");break;case"ServerError":if(J.push(`Error: Loops API error (${$.code??500})`),$.message)J.push(` Detail: ${$.message}`);J.push(" Hint: This is a server-side issue. Try again later.");break;case"ConnectionError":if(J.push("Error: Could not connect to the Loops API"),$.message)J.push(` Detail: ${$.message}`);J.push(" Hint: Check your network connection and try again.");break;default:J.push(`Error: ${$.message??$.type}${$.code?` (${$.code})`:""}`);break}return J.join(`
54
- `)}function D0($){let J=["error"];if($.code!==void 0)J.push(`code=${$.code}`);if(J.push(`type=${$.type}`),$.resource)J.push(`resource=${$.resource}`);if($.id)J.push(`id=${$.id}`);if($.fields){let R=Object.entries($.fields).map(([T,q])=>`${T}: ${q}`).join("; ");J.push(`fields="${R}"`)}if($.message)J.push(`message="${$.message.slice(0,200)}"`);let f=M2($);if(f)J.push(`hint="${f}"`);return J.join(" ")}var G2=g$.version,j=new c$().name("loops").description("CLI for Loops (loops.so) \u2014 manage contacts, send events, transactional emails, and more from the command line").version(G2).addHelpText("after",`
52
+ `),process.exit(Q.code===2?2:1)}})}function _0($,J,f,R){for(let T of J)e1($,T,f,R)}import{existsSync as j0,mkdirSync as J2,readFileSync as f2,writeFileSync as R2}from"node:fs";import{join as S$}from"node:path";var P$={output:"table",defaultLimit:25,noColor:!1},T2=new Set(["output","defaultLimit","noColor"]);class k{configPath;values;constructor($){let J=$??S$(process.env.HOME??"~",".loops-cli");this.configPath=S$(J,"config.json"),this.values={...P$},this.loadSync()}loadSync(){try{if(j0(this.configPath)){let $=f2(this.configPath,"utf-8"),J=JSON.parse($);this.values={...P$,...J}}}catch{}}async load(){this.loadSync()}get($){return this.values[$]}set($,J){if(!T2.has($))throw Error(`Invalid config key: ${String($)}`);this.values[$]=J,this.save()}list(){return{...this.values}}async reset(){this.values={...P$},this.save()}save(){let $=S$(this.configPath,"..");if(!j0($))J2($,{recursive:!0});R2(this.configPath,`${JSON.stringify(this.values,null,2)}
53
+ `)}}function q2($,J,f,R,T){return{name:$,sdkField:J,type:f,description:R,...T?{required:T}:{}}}function X2($){return $.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function Y($,J,f,R){return q2(X2($),$,J,f,R)}var z2={name:"contact",plural:"contacts",cliName:"contacts",description:"Manage contacts in your Loops audience",defaultFields:["id","email","firstName","lastName","source","subscribed"],examples:["loops contacts create --email user@example.com",`loops contacts create --email user@example.com --properties '{"firstName":"Jane","lastName":"Doe"}'`,`loops contacts create --email user@example.com --mailing-lists '{"list_id":true}'`,`loops contacts update --email user@example.com --properties '{"firstName":"Updated"}'`,"loops contacts find --email user@example.com","loops contacts find --user-id usr_123","loops contacts delete --email user@example.com","loops contacts delete --user-id usr_123"],operations:[{type:"create",sdkMethod:"createContact",description:"Create a new contact",flags:[Y("email","string","Contact email address",!0),Y("properties","json","Contact properties (JSON object)"),Y("mailingLists","json","Mailing list subscriptions (JSON object)")]},{type:"update",sdkMethod:"updateContact",description:"Update an existing contact",flags:[Y("email","string","Contact email address"),Y("userId","string","Contact user ID"),Y("properties","json","Contact properties to update (JSON object)"),Y("mailingLists","json","Mailing list subscriptions (JSON object)")]},{type:"custom",sdkMethod:"findContact",cliName:"find",description:"Find a contact by email or user ID",flags:[Y("email","string","Contact email address"),Y("userId","string","Contact user ID")],examples:["loops contacts find --email user@example.com","loops contacts find --user-id usr_123"]},{type:"custom",sdkMethod:"deleteContact",cliName:"delete",description:"Delete a contact by email or user ID",flags:[Y("email","string","Contact email address"),Y("userId","string","Contact user ID")],examples:["loops contacts delete --email user@example.com","loops contacts delete --user-id usr_123"]}]},Z2={name:"contactProperty",plural:"contactProperties",cliName:"contact-properties",description:"Manage contact properties (custom fields)",defaultFields:["key","label","type"],examples:["loops contact-properties list","loops contact-properties create --name favoriteColor --type string"],operations:[{type:"list",sdkMethod:"getCustomProperties",description:"List all contact properties"},{type:"create",sdkMethod:"createContactProperty",description:"Create a new contact property",positionalFlags:["name","type"],flags:[Y("name","string","Property name",!0),Y("type","string","Property type: string, number, boolean, date",!0)]}]},Q2={name:"mailingList",plural:"mailingLists",cliName:"mailing-lists",description:"View mailing lists",defaultFields:["id","name","isPublic"],examples:["loops mailing-lists list","loops mailing-lists list --output json"],operations:[{type:"list",sdkMethod:"getMailingLists",description:"List all mailing lists"}]},M2={name:"event",plural:"events",cliName:"events",description:"Send events to trigger emails in Loops",defaultFields:["success"],examples:["loops events send --email user@example.com --event-name signup",`loops events send --email user@example.com --event-name purchase --event-properties '{"plan":"pro","amount":29}'`,`loops events send --email user@example.com --event-name signup --contact-properties '{"firstName":"Jane"}'`,`loops events send --email user@example.com --event-name signup --mailing-lists '{"list_id":true}'`],operations:[{type:"custom",sdkMethod:"sendEvent",cliName:"send",description:"Send an event for a contact",flags:[Y("email","string","Contact email address"),Y("userId","string","Contact user ID"),Y("eventName","string","Event name",!0),Y("eventProperties","json","Event properties (JSON object)"),Y("contactProperties","json","Contact properties to update (JSON object)"),Y("mailingLists","json","Mailing list subscriptions (JSON object)")]}]},G2={name:"transactionalEmail",plural:"transactionalEmails",cliName:"transactional",description:"Send and manage transactional emails",defaultFields:["id","name","dataVariables"],examples:["loops transactional list","loops transactional send --transactional-id txn_123 --email user@example.com",`loops transactional send --transactional-id txn_123 --email user@example.com --data-variables '{"name":"Jane","url":"https://example.com"}'`,"loops transactional send --transactional-id txn_123 --email user@example.com --add-to-audience","loops transactional list --output json"],operations:[{type:"list",sdkMethod:"getTransactionalEmails",description:"List all transactional emails"},{type:"custom",sdkMethod:"sendTransactionalEmail",cliName:"send",description:"Send a transactional email",flags:[Y("transactionalId","string","Transactional email ID",!0),Y("email","string","Recipient email address",!0),Y("addToAudience","boolean","Add recipient to audience"),Y("dataVariables","json","Data variables for email template (JSON object)"),Y("attachments","json","File attachments (JSON array)")]}]},L2={name:"apiKey",plural:"apiKeys",cliName:"api-key",description:"Test your API key",defaultFields:["success","teamName"],examples:["loops api-key test"],operations:[{type:"custom",sdkMethod:"testApiKey",cliName:"test",description:"Verify your API key is valid"}]},W0=[z2,Z2,Q2,M2,G2,L2];function H2($){switch($.type){case"Unauthorized":return"Run 'loops auth login --api-key <your-key>' to authenticate. Get your key at https://app.loops.so/settings?page=api";case"Forbidden":return"Check that your API key has the required permissions";case"ResourceNotFound":return $.resource?`Run 'loops ${$.resource} list' to see available items`:"Verify the resource identifier is correct";case"ValidationError":return $.resource?`Run 'loops ${$.resource} --help' for required flags and usage`:"Check the flag values and try again";case"RateLimited":return"Wait a moment and try again. Loops allows 10 requests per second";case"ServerError":return"This is a Loops API issue. Try again later";case"ConnectionError":return"Check your network connection and try again";default:return}}function V0($){let J=[];switch($.type){case"Unauthorized":if(J.push("Error: Not authenticated"),J.push(" Run 'loops auth login --api-key <your-key>' to authenticate."),J.push(" Get your key at https://app.loops.so/settings?page=api"),$.message&&$.message!=="No API key found"&&$.message!=="Unauthorized")J.push(` Detail: ${$.message}`);break;case"Forbidden":if(J.push(`Error: Access denied${$.resource?` for ${$.resource}`:""} (403)`),$.message)J.push(` Detail: ${$.message}`);J.push(" Hint: Check that your API key has the required permissions.");break;case"ResourceNotFound":if(J.push(`Error: ${$.resource??"Resource"} not found (404)`),$.id)J.push(` ID: ${$.id}`);if($.resource)J.push(` Hint: Run 'loops ${$.resource} list' to see available items.`);else J.push(" Hint: Verify the resource identifier is correct.");break;case"ValidationError":if(J.push("Error: Validation failed (422)"),$.fields)for(let[f,R]of Object.entries($.fields))J.push(` - ${f}: ${R}`);if($.message&&!$.fields)J.push(` Detail: ${$.message}`);break;case"RateLimited":J.push("Error: Rate limit exceeded (429)"),J.push(" Hint: Wait a moment and try again. Loops allows 10 requests per second.");break;case"ServerError":if(J.push(`Error: Loops API error (${$.code??500})`),$.message)J.push(` Detail: ${$.message}`);J.push(" Hint: This is a server-side issue. Try again later.");break;case"ConnectionError":if(J.push("Error: Could not connect to the Loops API"),$.message)J.push(` Detail: ${$.message}`);J.push(" Hint: Check your network connection and try again.");break;default:J.push(`Error: ${$.message??$.type}${$.code?` (${$.code})`:""}`);break}return J.join(`
54
+ `)}function D0($){let J=["error"];if($.code!==void 0)J.push(`code=${$.code}`);if(J.push(`type=${$.type}`),$.resource)J.push(`resource=${$.resource}`);if($.id)J.push(`id=${$.id}`);if($.fields){let R=Object.entries($.fields).map(([T,q])=>`${T}: ${q}`).join("; ");J.push(`fields="${R}"`)}if($.message)J.push(`message="${$.message.slice(0,200)}"`);let f=H2($);if(f)J.push(`hint="${f}"`);return J.join(" ")}var U2=g$.version,j=new c$().name("loops").description("CLI for Loops (loops.so) \u2014 manage contacts, send events, transactional emails, and more from the command line").version(U2).addHelpText("after",`
55
55
  Getting started:
56
56
  $ loops auth login --api-key <your-api-key>
57
57
  $ loops contacts find --email user@example.com
@@ -79,6 +79,6 @@ Get your API key at https://app.loops.so/settings?page=api`);K$.command("login")
79
79
  `)});K$.command("logout").description("Remove stored credentials").action(async()=>{await new E().logout(),process.stdout.write(`Logged out.
80
80
  `)});K$.command("status").description("Show current auth state").action(async()=>{let J=await new E().status();if(J.authenticated)process.stdout.write(`Authenticated: ${J.keyPrefix}
81
81
  `);else process.stdout.write(`Not authenticated. Run 'loops auth login'.
82
- `)});function L2(){let $=new E;return async()=>{let J=process.env.LOOPS_API_KEY??await $.getApiKey();if(!J){let f=process.stdout.isTTY??!1,R={type:"Unauthorized",code:401,message:"No API key found"};process.stderr.write(`${f?V0(R):D0(R)}
83
- `),process.exit(1)}return l$({apiKey:J})}}_0(j,W0,L2(),()=>j.opts());j.showSuggestionAfterError(!0);j.configureOutput({writeErr:($)=>process.stderr.write($),writeOut:($)=>process.stdout.write($)});j.exitOverride(($)=>{if($.code==="commander.unknownCommand")process.exit(2);if($.code==="commander.helpDisplayed"||$.code==="commander.version")process.exit(0)});j.parseAsync(process.argv).catch(($)=>{if($.code==="commander.unknownCommand")process.exit(2);process.stderr.write(`${$.message}
82
+ `)});function Y2(){let $=new E;return async()=>{let J=process.env.LOOPS_API_KEY??await $.getApiKey();if(!J){let f=process.stdout.isTTY??!1,R={type:"Unauthorized",code:401,message:"No API key found"};process.stderr.write(`${f?V0(R):D0(R)}
83
+ `),process.exit(1)}return l$({apiKey:J})}}_0(j,W0,Y2(),()=>j.opts());j.showSuggestionAfterError(!0);j.configureOutput({writeErr:($)=>process.stderr.write($),writeOut:($)=>process.stdout.write($)});j.exitOverride(($)=>{if($.code==="commander.unknownCommand")process.exit(2);if($.code==="commander.helpDisplayed"||$.code==="commander.version")process.exit(0)});j.parseAsync(process.argv).catch(($)=>{if($.code==="commander.unknownCommand")process.exit(2);process.stderr.write(`${$.message}
84
84
  `),process.exit(1)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miketromba/loops-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "CLI for the Loops email marketing API — manage contacts, send events, transactional emails, and more from the command line. AI-agent optimized output.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -39,6 +39,10 @@
39
39
  "api"
40
40
  ],
41
41
  "license": "MIT",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/miketromba/loops-cli"
45
+ },
42
46
  "engines": {
43
47
  "node": ">=18.0.0"
44
48
  },