@1msg/cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +21 -0
- package/LICENSE +21 -0
- package/README.md +69 -0
- package/dist/commands.d.ts +8 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +90 -0
- package/dist/commands.js.map +1 -0
- package/dist/completion.d.ts +11 -0
- package/dist/completion.d.ts.map +1 -0
- package/dist/completion.js +205 -0
- package/dist/completion.js.map +1 -0
- package/dist/config.d.ts +37 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +185 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +30 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +111 -0
- package/dist/context.js.map +1 -0
- package/dist/dest.d.ts +27 -0
- package/dist/dest.d.ts.map +1 -0
- package/dist/dest.js +63 -0
- package/dist/dest.js.map +1 -0
- package/dist/errors.d.ts +34 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +133 -0
- package/dist/errors.js.map +1 -0
- package/dist/execute.d.ts +11 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/execute.js +89 -0
- package/dist/execute.js.map +1 -0
- package/dist/help-text.d.ts +3 -0
- package/dist/help-text.d.ts.map +1 -0
- package/dist/help-text.js +55 -0
- package/dist/help-text.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/io.d.ts +14 -0
- package/dist/io.d.ts.map +1 -0
- package/dist/io.js +128 -0
- package/dist/io.js.map +1 -0
- package/dist/local.d.ts +30 -0
- package/dist/local.d.ts.map +1 -0
- package/dist/local.js +247 -0
- package/dist/local.js.map +1 -0
- package/dist/output.d.ts +20 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +118 -0
- package/dist/output.js.map +1 -0
- package/dist/paths.d.ts +5 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +33 -0
- package/dist/paths.js.map +1 -0
- package/dist/program.d.ts +5 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +507 -0
- package/dist/program.js.map +1 -0
- package/dist/rest.d.ts +112 -0
- package/dist/rest.d.ts.map +1 -0
- package/dist/rest.js +549 -0
- package/dist/rest.js.map +1 -0
- package/dist/run.d.ts +3 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +33 -0
- package/dist/run.js.map +1 -0
- package/dist/send.d.ts +188 -0
- package/dist/send.d.ts.map +1 -0
- package/dist/send.js +498 -0
- package/dist/send.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/package.json +50 -0
package/ARCHITECTURE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# CLI package architecture
|
|
2
|
+
|
|
3
|
+
The `@1msg/cli` package **must not** call the 1MSG API directly.
|
|
4
|
+
All HTTP goes through [`@1msg/sdk`](https://www.npmjs.com/package/@1msg/sdk).
|
|
5
|
+
|
|
6
|
+
```text
|
|
7
|
+
OpenAPI YAML (1msg-api monorepo)
|
|
8
|
+
└─► codegen
|
|
9
|
+
├─► NestJS controllers
|
|
10
|
+
├─► @1msg/sdk ← HTTP + types (published npm)
|
|
11
|
+
└─► @1msg/cli ← commander + config + help; SDK client only
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Commands are hand-mapped (verb + noun), not generated 1:1 from OpenAPI.
|
|
15
|
+
Coverage is asserted in the `1msg-api` monorepo: 61 mapped public
|
|
16
|
+
`operationId`s + explicit `deleteMediaLegacy` skip = 62.
|
|
17
|
+
|
|
18
|
+
`--help` text is frozen from the RFC in `1msg-api` (`docs/CLI.md`).
|
|
19
|
+
|
|
20
|
+
This repository is the **distribution** package. Implementation source of
|
|
21
|
+
truth remains `1msg-api/packages/cli`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 1msg
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# @1msg/cli
|
|
2
|
+
|
|
3
|
+
Command-line client for the [1MSG](https://1msg.io) WhatsApp Business API — **61 public operations** (legacy `deleteMediaLegacy` is not exposed).
|
|
4
|
+
|
|
5
|
+
| | |
|
|
6
|
+
|--|--|
|
|
7
|
+
| **npm** | [`@1msg/cli`](https://www.npmjs.com/package/@1msg/cli) |
|
|
8
|
+
| **Binary** | `1msg` |
|
|
9
|
+
| **SDK** | [`@1msg/sdk`](https://www.npmjs.com/package/@1msg/sdk) |
|
|
10
|
+
|
|
11
|
+
API hosts:
|
|
12
|
+
|
|
13
|
+
| Environment | `ONE_MSG_BASE_URL` |
|
|
14
|
+
|-------------|--------------------|
|
|
15
|
+
| Live channels | `https://api.1msg.io` |
|
|
16
|
+
| Test channels | `https://sandbox.1msg.io` |
|
|
17
|
+
|
|
18
|
+
> Source of truth for the CLI implementation still lives in the `1msg-api` monorepo (`packages/cli`). This repository is the **distribution** package for `npx` / clone / npm.
|
|
19
|
+
|
|
20
|
+
## Quick start
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npx -y @1msg/cli --help
|
|
24
|
+
npx -y @1msg/cli init
|
|
25
|
+
npx -y @1msg/cli status
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or install globally: `npm i -g @1msg/cli`.
|
|
29
|
+
|
|
30
|
+
### Clone and run
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
git clone https://github.com/1msg/1msg-cli.git
|
|
34
|
+
cd 1msg-cli
|
|
35
|
+
npm install
|
|
36
|
+
npm run build
|
|
37
|
+
node dist/index.js --help
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Config and environment
|
|
41
|
+
|
|
42
|
+
Config file: `~/.config/1msg/config.yaml` (Windows: `%AppData%\1msg\config.yaml`). Mode `0600`.
|
|
43
|
+
|
|
44
|
+
| Variable | Description |
|
|
45
|
+
|----------|-------------|
|
|
46
|
+
| `ONE_MSG_BASE_URL` | API root: `https://api.1msg.io` (live) or `https://sandbox.1msg.io` (test) |
|
|
47
|
+
| `ONE_MSG_INSTANCE_ID` | Channel instance id |
|
|
48
|
+
| `ONE_MSG_TOKEN` | Channel API token |
|
|
49
|
+
| `ONE_MSG_CHANNEL` | Named channel from the config file |
|
|
50
|
+
|
|
51
|
+
Deprecated aliases match MCP: `CHAT_API_*`, `TOKEN`, `INSTANCE_ID`.
|
|
52
|
+
|
|
53
|
+
Precedence: named channel (`--channel` / `ONE_MSG_CHANNEL` / `default_channel` / the only channel) → fill empty fields from env → flags win. A named channel token is not overwritten by leftover `ONE_MSG_TOKEN`. No config file + the three env vars = implicit CI channel.
|
|
54
|
+
|
|
55
|
+
## Scripts
|
|
56
|
+
|
|
57
|
+
| Script | Purpose |
|
|
58
|
+
|--------|---------|
|
|
59
|
+
| `npm run build` | Compile TypeScript → `dist/` |
|
|
60
|
+
| `npm test` | Jest unit tests |
|
|
61
|
+
| `npm start` | Run `dist/index.js` |
|
|
62
|
+
|
|
63
|
+
## Architecture
|
|
64
|
+
|
|
65
|
+
All API HTTP goes through `@1msg/sdk`. See [ARCHITECTURE.md](./ARCHITECTURE.md).
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
MIT
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public operationId → CLI command (source of truth for coverage CI).
|
|
3
|
+
* Must stay in sync with docs/CLI.md "Full map".
|
|
4
|
+
*/
|
|
5
|
+
export declare const SKIPPED_OPERATION_IDS: readonly ["deleteMediaLegacy"];
|
|
6
|
+
export declare const OPERATION_COMMANDS: Record<string, string>;
|
|
7
|
+
export declare const COMPLETION_COMMANDS: readonly ["init", "send", "message", "template", "channel", "me", "status", "media", "group", "flow", "webhook", "user", "catalog", "call", "completion", "version"];
|
|
8
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,qBAAqB,gCAAiC,CAAC;AAEpE,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA8DrD,CAAC;AAEF,eAAO,MAAM,mBAAmB,sKAiBtB,CAAC"}
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.COMPLETION_COMMANDS = exports.OPERATION_COMMANDS = exports.SKIPPED_OPERATION_IDS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Public operationId → CLI command (source of truth for coverage CI).
|
|
6
|
+
* Must stay in sync with docs/CLI.md "Full map".
|
|
7
|
+
*/
|
|
8
|
+
exports.SKIPPED_OPERATION_IDS = ['deleteMediaLegacy'];
|
|
9
|
+
exports.OPERATION_COMMANDS = {
|
|
10
|
+
sendMessage: 'message send --text / send --text',
|
|
11
|
+
sendFile: 'message send --file / --media-id',
|
|
12
|
+
createUploadMedia: 'media upload',
|
|
13
|
+
listMessages: 'message list',
|
|
14
|
+
createReadMessage: 'message read',
|
|
15
|
+
sendTemplate: 'template send',
|
|
16
|
+
listTemplates: 'template list',
|
|
17
|
+
addTemplate: 'template add',
|
|
18
|
+
removeTemplate: 'template remove',
|
|
19
|
+
getStatus: 'status / channel status',
|
|
20
|
+
getMe: 'me',
|
|
21
|
+
updateMe: 'me update',
|
|
22
|
+
retrieveMedia: 'media get',
|
|
23
|
+
deleteMedia: 'media delete',
|
|
24
|
+
sendReaction: 'message react',
|
|
25
|
+
sendLocation: 'message location',
|
|
26
|
+
sendLocationRequest: 'message location-request',
|
|
27
|
+
sendContact: 'message contact',
|
|
28
|
+
sendButton: 'message buttons',
|
|
29
|
+
sendList: 'message menu',
|
|
30
|
+
sendCarousel: 'message carousel',
|
|
31
|
+
sendProduct: 'message product',
|
|
32
|
+
sendCtaUrl: 'message cta',
|
|
33
|
+
sendAddressMessage: 'message address',
|
|
34
|
+
sendOrderDetails: 'message order',
|
|
35
|
+
sendPaymentRequest: 'message payment',
|
|
36
|
+
sendSticker: 'message sticker',
|
|
37
|
+
sendFlow: 'message flow',
|
|
38
|
+
getWebhook: 'webhook get',
|
|
39
|
+
setWebhook: 'webhook set',
|
|
40
|
+
listSettings: 'channel settings',
|
|
41
|
+
createSettings: 'channel settings set / webhook clear',
|
|
42
|
+
getMmLiteStatus: 'channel mm-lite',
|
|
43
|
+
getCommerce: 'catalog get',
|
|
44
|
+
createCommerce: 'catalog set',
|
|
45
|
+
getConversationalAutomation: 'channel automation',
|
|
46
|
+
setConversationalAutomation: 'channel automation set',
|
|
47
|
+
blockUser: 'user block',
|
|
48
|
+
unblockUser: 'user unblock',
|
|
49
|
+
listBlockedUsers: 'user blocked',
|
|
50
|
+
createGroups: 'group create',
|
|
51
|
+
listGroups: 'group list',
|
|
52
|
+
getGroupsGroupId: 'group get',
|
|
53
|
+
createGroupsGroupId: 'group update',
|
|
54
|
+
deleteGroupsGroupId: 'group delete',
|
|
55
|
+
getGroupsGroupIdInvitelink: 'group invite-link',
|
|
56
|
+
createGroupsGroupIdInvitelink: 'group invite-link reset',
|
|
57
|
+
createFlows: 'flow create',
|
|
58
|
+
listFlows: 'flow list',
|
|
59
|
+
getFlowsFlowId: 'flow get',
|
|
60
|
+
deleteFlowsFlowId: 'flow delete',
|
|
61
|
+
patchFlowsFlowIdMetadata: 'flow metadata',
|
|
62
|
+
patchFlowsFlowIdAssets: 'flow assets',
|
|
63
|
+
getFlowsFlowIdPreview: 'flow preview',
|
|
64
|
+
createFlowsFlowIdPublish: 'flow publish',
|
|
65
|
+
createFlowsFlowIdDeprecate: 'flow deprecate',
|
|
66
|
+
getCallingSettings: 'call settings',
|
|
67
|
+
updateCallingSettings: 'call settings set',
|
|
68
|
+
initiateCall: 'call connect / pre-accept / accept / reject / hangup',
|
|
69
|
+
getWhatsappBusinessEncryption: 'flow encryption',
|
|
70
|
+
setWhatsappBusinessEncryption: 'flow encryption set',
|
|
71
|
+
};
|
|
72
|
+
exports.COMPLETION_COMMANDS = [
|
|
73
|
+
'init',
|
|
74
|
+
'send',
|
|
75
|
+
'message',
|
|
76
|
+
'template',
|
|
77
|
+
'channel',
|
|
78
|
+
'me',
|
|
79
|
+
'status',
|
|
80
|
+
'media',
|
|
81
|
+
'group',
|
|
82
|
+
'flow',
|
|
83
|
+
'webhook',
|
|
84
|
+
'user',
|
|
85
|
+
'catalog',
|
|
86
|
+
'call',
|
|
87
|
+
'completion',
|
|
88
|
+
'version',
|
|
89
|
+
];
|
|
90
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,qBAAqB,GAAG,CAAC,mBAAmB,CAAU,CAAC;AAEvD,QAAA,kBAAkB,GAA2B;IACxD,WAAW,EAAE,mCAAmC;IAChD,QAAQ,EAAE,kCAAkC;IAC5C,iBAAiB,EAAE,cAAc;IACjC,YAAY,EAAE,cAAc;IAC5B,iBAAiB,EAAE,cAAc;IACjC,YAAY,EAAE,eAAe;IAC7B,aAAa,EAAE,eAAe;IAC9B,WAAW,EAAE,cAAc;IAC3B,cAAc,EAAE,iBAAiB;IACjC,SAAS,EAAE,yBAAyB;IACpC,KAAK,EAAE,IAAI;IACX,QAAQ,EAAE,WAAW;IACrB,aAAa,EAAE,WAAW;IAC1B,WAAW,EAAE,cAAc;IAC3B,YAAY,EAAE,eAAe;IAC7B,YAAY,EAAE,kBAAkB;IAChC,mBAAmB,EAAE,0BAA0B;IAC/C,WAAW,EAAE,iBAAiB;IAC9B,UAAU,EAAE,iBAAiB;IAC7B,QAAQ,EAAE,cAAc;IACxB,YAAY,EAAE,kBAAkB;IAChC,WAAW,EAAE,iBAAiB;IAC9B,UAAU,EAAE,aAAa;IACzB,kBAAkB,EAAE,iBAAiB;IACrC,gBAAgB,EAAE,eAAe;IACjC,kBAAkB,EAAE,iBAAiB;IACrC,WAAW,EAAE,iBAAiB;IAC9B,QAAQ,EAAE,cAAc;IACxB,UAAU,EAAE,aAAa;IACzB,UAAU,EAAE,aAAa;IACzB,YAAY,EAAE,kBAAkB;IAChC,cAAc,EAAE,sCAAsC;IACtD,eAAe,EAAE,iBAAiB;IAClC,WAAW,EAAE,aAAa;IAC1B,cAAc,EAAE,aAAa;IAC7B,2BAA2B,EAAE,oBAAoB;IACjD,2BAA2B,EAAE,wBAAwB;IACrD,SAAS,EAAE,YAAY;IACvB,WAAW,EAAE,cAAc;IAC3B,gBAAgB,EAAE,cAAc;IAChC,YAAY,EAAE,cAAc;IAC5B,UAAU,EAAE,YAAY;IACxB,gBAAgB,EAAE,WAAW;IAC7B,mBAAmB,EAAE,cAAc;IACnC,mBAAmB,EAAE,cAAc;IACnC,0BAA0B,EAAE,mBAAmB;IAC/C,6BAA6B,EAAE,yBAAyB;IACxD,WAAW,EAAE,aAAa;IAC1B,SAAS,EAAE,WAAW;IACtB,cAAc,EAAE,UAAU;IAC1B,iBAAiB,EAAE,aAAa;IAChC,wBAAwB,EAAE,eAAe;IACzC,sBAAsB,EAAE,aAAa;IACrC,qBAAqB,EAAE,cAAc;IACrC,wBAAwB,EAAE,cAAc;IACxC,0BAA0B,EAAE,gBAAgB;IAC5C,kBAAkB,EAAE,eAAe;IACnC,qBAAqB,EAAE,mBAAmB;IAC1C,YAAY,EAAE,sDAAsD;IACpE,6BAA6B,EAAE,iBAAiB;IAChD,6BAA6B,EAAE,qBAAqB;CACrD,CAAC;AAEW,QAAA,mBAAmB,GAAG;IACjC,MAAM;IACN,MAAM;IACN,SAAS;IACT,UAAU;IACV,SAAS;IACT,IAAI;IACJ,QAAQ;IACR,OAAO;IACP,OAAO;IACP,MAAM;IACN,SAAS;IACT,MAAM;IACN,SAAS;IACT,MAAM;IACN,YAAY;IACZ,SAAS;CACD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CliContext } from './context';
|
|
2
|
+
export interface CompletionCache {
|
|
3
|
+
updated_at: string;
|
|
4
|
+
channel: string;
|
|
5
|
+
templates: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare function loadCompletionCache(ctx: CliContext): CompletionCache | null;
|
|
8
|
+
export declare function writeCompletionCache(ctx: CliContext, channel: string, templates: string[]): void;
|
|
9
|
+
export declare function completeKind(ctx: CliContext, kind: string): string[];
|
|
10
|
+
export declare function completionScript(shell: string): string;
|
|
11
|
+
//# sourceMappingURL=completion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completion.d.ts","sourceRoot":"","sources":["../src/completion.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAK5C,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,UAAU,GAAG,eAAe,GAAG,IAAI,CAU3E;AAED,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EAAE,GAClB,IAAI,CAYN;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAapE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMtD"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loadCompletionCache = loadCompletionCache;
|
|
7
|
+
exports.writeCompletionCache = writeCompletionCache;
|
|
8
|
+
exports.completeKind = completeKind;
|
|
9
|
+
exports.completionScript = completionScript;
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const commands_1 = require("./commands");
|
|
12
|
+
const config_1 = require("./config");
|
|
13
|
+
const paths_1 = require("./paths");
|
|
14
|
+
function loadCompletionCache(ctx) {
|
|
15
|
+
const filePath = (0, paths_1.cacheFilePath)(ctx);
|
|
16
|
+
if (!ctx.fs.existsSync(filePath))
|
|
17
|
+
return null;
|
|
18
|
+
try {
|
|
19
|
+
const parsed = JSON.parse(ctx.fs.readFileSync(filePath, 'utf8').toString());
|
|
20
|
+
if (!parsed || !Array.isArray(parsed.templates))
|
|
21
|
+
return null;
|
|
22
|
+
return parsed;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function writeCompletionCache(ctx, channel, templates) {
|
|
29
|
+
const filePath = (0, paths_1.cacheFilePath)(ctx);
|
|
30
|
+
const parent = path_1.default.dirname(filePath);
|
|
31
|
+
ctx.fs.mkdirSync(parent, { recursive: true });
|
|
32
|
+
const body = {
|
|
33
|
+
updated_at: ctx.now().toISOString(),
|
|
34
|
+
channel,
|
|
35
|
+
templates: [...new Set(templates.filter(Boolean))],
|
|
36
|
+
};
|
|
37
|
+
ctx.fs.writeFileSync(filePath, `${JSON.stringify(body, null, 2)}\n`, {
|
|
38
|
+
encoding: 'utf8',
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function completeKind(ctx, kind) {
|
|
42
|
+
if (kind === 'commands')
|
|
43
|
+
return [...commands_1.COMPLETION_COMMANDS];
|
|
44
|
+
if (kind === 'channels')
|
|
45
|
+
return (0, config_1.channelNames)(ctx);
|
|
46
|
+
if (kind === 'templates') {
|
|
47
|
+
const cache = loadCompletionCache(ctx);
|
|
48
|
+
const file = (0, config_1.loadConfig)(ctx);
|
|
49
|
+
if (!cache)
|
|
50
|
+
return [];
|
|
51
|
+
if (file?.default_channel && cache.channel && cache.channel !== file.default_channel) {
|
|
52
|
+
return cache.templates;
|
|
53
|
+
}
|
|
54
|
+
return cache.templates;
|
|
55
|
+
}
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
function completionScript(shell) {
|
|
59
|
+
const normalized = shell.toLowerCase();
|
|
60
|
+
if (normalized === 'bash')
|
|
61
|
+
return BASH_SCRIPT;
|
|
62
|
+
if (normalized === 'zsh')
|
|
63
|
+
return ZSH_SCRIPT;
|
|
64
|
+
if (normalized === 'powershell' || normalized === 'pwsh')
|
|
65
|
+
return POWERSHELL_SCRIPT;
|
|
66
|
+
throw new Error(`unsupported shell "${shell}" (bash | zsh | powershell)`);
|
|
67
|
+
}
|
|
68
|
+
const BASH_SCRIPT = `# 1msg bash completion — redirect to a file, then reload the shell
|
|
69
|
+
# mkdir -p ~/.local/share/bash-completion/completions
|
|
70
|
+
# 1msg completion bash > ~/.local/share/bash-completion/completions/1msg
|
|
71
|
+
|
|
72
|
+
_1msg() {
|
|
73
|
+
local cur prev
|
|
74
|
+
COMPREPLY=()
|
|
75
|
+
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
76
|
+
prev="\${COMP_WORDS[COMP_CWORD-1]}"
|
|
77
|
+
|
|
78
|
+
local roots="init send message template channel me status media group flow webhook user catalog call completion version"
|
|
79
|
+
local message_cmds="send list read react location location-request contact buttons menu carousel product cta address order payment sticker flow"
|
|
80
|
+
local template_cmds="list send add remove"
|
|
81
|
+
local channel_cmds="list use add remove current info status settings mm-lite automation"
|
|
82
|
+
local media_cmds="upload get delete"
|
|
83
|
+
local group_cmds="list create get update delete invite-link"
|
|
84
|
+
local flow_cmds="list create get delete preview publish deprecate metadata assets encryption"
|
|
85
|
+
local webhook_cmds="get set clear"
|
|
86
|
+
local user_cmds="blocked block unblock"
|
|
87
|
+
local catalog_cmds="get set"
|
|
88
|
+
local call_cmds="settings connect pre-accept accept reject hangup"
|
|
89
|
+
local flags="-c --channel --instance-id --base-url --token --json --no-color -h --help -v --version"
|
|
90
|
+
|
|
91
|
+
local cmd=""
|
|
92
|
+
local i
|
|
93
|
+
for ((i=1; i<COMP_CWORD; i++)); do
|
|
94
|
+
case "\${COMP_WORDS[i]}" in
|
|
95
|
+
-c|--channel|--instance-id|--base-url|--token) i=$((i+1)) ;;
|
|
96
|
+
--json|--no-color|-h|--help|-v|--version) ;;
|
|
97
|
+
-*) ;;
|
|
98
|
+
*) cmd="\${COMP_WORDS[i]}"; break ;;
|
|
99
|
+
esac
|
|
100
|
+
done
|
|
101
|
+
|
|
102
|
+
if [[ "$prev" == "-c" || "$prev" == "--channel" ]]; then
|
|
103
|
+
COMPREPLY=( $(compgen -W "$(1msg __complete channels 2>/dev/null)" -- "$cur") )
|
|
104
|
+
return
|
|
105
|
+
fi
|
|
106
|
+
if [[ "$prev" == "--name" && "$cmd" == "template" ]]; then
|
|
107
|
+
COMPREPLY=( $(compgen -W "$(1msg __complete templates 2>/dev/null)" -- "$cur") )
|
|
108
|
+
return
|
|
109
|
+
fi
|
|
110
|
+
|
|
111
|
+
if [[ -z "$cmd" ]]; then
|
|
112
|
+
COMPREPLY=( $(compgen -W "$roots $flags" -- "$cur") )
|
|
113
|
+
return
|
|
114
|
+
fi
|
|
115
|
+
|
|
116
|
+
case "$cmd" in
|
|
117
|
+
message) COMPREPLY=( $(compgen -W "$message_cmds $flags" -- "$cur") ) ;;
|
|
118
|
+
template) COMPREPLY=( $(compgen -W "$template_cmds $flags" -- "$cur") ) ;;
|
|
119
|
+
channel)
|
|
120
|
+
if [[ "$prev" == "use" || "$prev" == "remove" ]]; then
|
|
121
|
+
COMPREPLY=( $(compgen -W "$(1msg __complete channels 2>/dev/null)" -- "$cur") )
|
|
122
|
+
else
|
|
123
|
+
COMPREPLY=( $(compgen -W "$channel_cmds $flags" -- "$cur") )
|
|
124
|
+
fi
|
|
125
|
+
;;
|
|
126
|
+
media) COMPREPLY=( $(compgen -W "$media_cmds $flags" -- "$cur") ) ;;
|
|
127
|
+
group) COMPREPLY=( $(compgen -W "$group_cmds $flags" -- "$cur") ) ;;
|
|
128
|
+
flow) COMPREPLY=( $(compgen -W "$flow_cmds $flags" -- "$cur") ) ;;
|
|
129
|
+
webhook) COMPREPLY=( $(compgen -W "$webhook_cmds $flags" -- "$cur") ) ;;
|
|
130
|
+
user) COMPREPLY=( $(compgen -W "$user_cmds $flags" -- "$cur") ) ;;
|
|
131
|
+
catalog) COMPREPLY=( $(compgen -W "$catalog_cmds $flags" -- "$cur") ) ;;
|
|
132
|
+
call) COMPREPLY=( $(compgen -W "$call_cmds $flags" -- "$cur") ) ;;
|
|
133
|
+
completion) COMPREPLY=( $(compgen -W "bash zsh powershell" -- "$cur") ) ;;
|
|
134
|
+
*) COMPREPLY=( $(compgen -W "$flags" -- "$cur") ) ;;
|
|
135
|
+
esac
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
complete -F _1msg 1msg
|
|
139
|
+
`;
|
|
140
|
+
const ZSH_SCRIPT = `#compdef 1msg
|
|
141
|
+
# 1msg zsh completion — write to ~/.zsh/completions/_1msg and add that dir to fpath
|
|
142
|
+
|
|
143
|
+
_1msg() {
|
|
144
|
+
local -a roots flags
|
|
145
|
+
roots=(init send message template channel me status media group flow webhook user catalog call completion version)
|
|
146
|
+
flags=(-c --channel --instance-id --base-url --token --json --no-color -h --help -v --version)
|
|
147
|
+
|
|
148
|
+
if [[ "$words[CURRENT-1]" == "-c" || "$words[CURRENT-1]" == "--channel" ]]; then
|
|
149
|
+
local -a channels
|
|
150
|
+
channels=(\${(f)"$(1msg __complete channels 2>/dev/null)"})
|
|
151
|
+
_describe 'channel' channels
|
|
152
|
+
return
|
|
153
|
+
fi
|
|
154
|
+
|
|
155
|
+
if [[ "$words[2]" == "channel" && ( "$words[3]" == "use" || "$words[3]" == "remove" ) ]]; then
|
|
156
|
+
local -a channels
|
|
157
|
+
channels=(\${(f)"$(1msg __complete channels 2>/dev/null)"})
|
|
158
|
+
_describe 'channel' channels
|
|
159
|
+
return
|
|
160
|
+
fi
|
|
161
|
+
|
|
162
|
+
if [[ "$words[2]" == "template" && ( "$words[CURRENT-1]" == "--name" || "$words[3]" == "remove" ) ]]; then
|
|
163
|
+
local -a templates
|
|
164
|
+
templates=(\${(f)"$(1msg __complete templates 2>/dev/null)"})
|
|
165
|
+
_describe 'template' templates
|
|
166
|
+
return
|
|
167
|
+
fi
|
|
168
|
+
|
|
169
|
+
case "$words[2]" in
|
|
170
|
+
message) _values 'command' send list read react location location-request contact buttons menu carousel product cta address order payment sticker flow ;;
|
|
171
|
+
template) _values 'command' list send add remove ;;
|
|
172
|
+
channel) _values 'command' list use add remove current info status settings mm-lite automation ;;
|
|
173
|
+
media) _values 'command' upload get delete ;;
|
|
174
|
+
group) _values 'command' list create get update delete invite-link ;;
|
|
175
|
+
flow) _values 'command' list create get delete preview publish deprecate metadata assets encryption ;;
|
|
176
|
+
webhook) _values 'command' get set clear ;;
|
|
177
|
+
user) _values 'command' blocked block unblock ;;
|
|
178
|
+
catalog) _values 'command' get set ;;
|
|
179
|
+
call) _values 'command' settings connect pre-accept accept reject hangup ;;
|
|
180
|
+
completion) _values 'shell' bash zsh powershell ;;
|
|
181
|
+
"") _describe 'command' roots ;;
|
|
182
|
+
*) _describe 'flag' flags ;;
|
|
183
|
+
esac
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
_1msg "$@"
|
|
187
|
+
`;
|
|
188
|
+
const POWERSHELL_SCRIPT = `# 1msg PowerShell completion
|
|
189
|
+
Register-ArgumentCompleter -Native -CommandName 1msg -ScriptBlock {
|
|
190
|
+
param($wordToComplete, $commandAst, $cursorPosition)
|
|
191
|
+
$cmd = $commandAst.CommandElements | ForEach-Object { $_.Extent.Text }
|
|
192
|
+
$prev = if ($cmd.Count -ge 2) { $cmd[-2] } else { '' }
|
|
193
|
+
$roots = @('init','send','message','template','channel','me','status','media','group','flow','webhook','user','catalog','call','completion','version')
|
|
194
|
+
if ($prev -eq '-c' -or $prev -eq '--channel' -or ($cmd -contains 'use') -or ($cmd -contains 'remove' -and $cmd -contains 'channel')) {
|
|
195
|
+
& 1msg __complete channels 2>$null | Where-Object { $_ -like "$wordToComplete*" }
|
|
196
|
+
return
|
|
197
|
+
}
|
|
198
|
+
if ($cmd -contains 'template' -and $prev -eq '--name') {
|
|
199
|
+
& 1msg __complete templates 2>$null | Where-Object { $_ -like "$wordToComplete*" }
|
|
200
|
+
return
|
|
201
|
+
}
|
|
202
|
+
$roots | Where-Object { $_ -like "$wordToComplete*" }
|
|
203
|
+
}
|
|
204
|
+
`;
|
|
205
|
+
//# sourceMappingURL=completion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completion.js","sourceRoot":"","sources":["../src/completion.ts"],"names":[],"mappings":"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"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { CliContext } from './context';
|
|
2
|
+
export interface ChannelBlock {
|
|
3
|
+
base_url?: string;
|
|
4
|
+
instance_id?: string;
|
|
5
|
+
token?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface FileConfig {
|
|
8
|
+
version: 1;
|
|
9
|
+
default_channel?: string;
|
|
10
|
+
channels: Record<string, ChannelBlock>;
|
|
11
|
+
}
|
|
12
|
+
export interface GlobalFlags {
|
|
13
|
+
channel?: string;
|
|
14
|
+
instanceId?: string;
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
token?: string;
|
|
17
|
+
json?: boolean;
|
|
18
|
+
color?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface ResolvedChannel {
|
|
21
|
+
name?: string;
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
instanceId: string;
|
|
24
|
+
token: string;
|
|
25
|
+
}
|
|
26
|
+
export declare function normalizeBaseUrl(raw: string): string;
|
|
27
|
+
export declare function envChannel(ctx: CliContext): string | undefined;
|
|
28
|
+
export declare function envBaseUrl(ctx: CliContext): string | undefined;
|
|
29
|
+
export declare function envInstanceId(ctx: CliContext): string | undefined;
|
|
30
|
+
export declare function envToken(ctx: CliContext): string | undefined;
|
|
31
|
+
export declare function loadConfig(ctx: CliContext): FileConfig | null;
|
|
32
|
+
export declare function saveConfig(ctx: CliContext, config: FileConfig): void;
|
|
33
|
+
export declare function emptyConfig(): FileConfig;
|
|
34
|
+
export declare function resolveChannel(ctx: CliContext, flags: GlobalFlags): ResolvedChannel;
|
|
35
|
+
export declare function lookupChannelName(config: FileConfig, nameOrId: string): string;
|
|
36
|
+
export declare function channelNames(ctx: CliContext): string[];
|
|
37
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAI5C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,CAAC,CAAC;IACX,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf;AAUD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAyBpD;AAUD,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAE9D;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAM9D;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAEjE;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAE5D;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,UAAU,GAAG,IAAI,CAc7D;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAepE;AAED,wBAAgB,WAAW,IAAI,UAAU,CAExC;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,GAAG,eAAe,CA8BnF;AA4BD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAY9E;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,EAAE,CAGtD"}
|