@hesed/gchat 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # sentry
1
+ # gchat
2
2
 
3
3
  CLI for Google Chat API interaction
4
4
 
@@ -12,7 +12,7 @@ sdkck plugins install @hesed/gchat
12
12
  ```
13
13
 
14
14
  <!-- toc -->
15
- * [sentry](#sentry)
15
+ * [gchat](#gchat)
16
16
  * [Install](#install)
17
17
  * [Usage](#usage)
18
18
  * [Commands](#commands)
@@ -26,7 +26,7 @@ $ npm install -g @hesed/gchat
26
26
  $ gchat COMMAND
27
27
  running command...
28
28
  $ gchat (--version)
29
- @hesed/gchat/0.1.0 darwin-arm64 node-v22.14.0
29
+ @hesed/gchat/0.2.1 linux-x64 node-v22.22.0
30
30
  $ gchat --help [COMMAND]
31
31
  USAGE
32
32
  $ gchat COMMAND
@@ -37,60 +37,103 @@ USAGE
37
37
  # Commands
38
38
 
39
39
  <!-- commands -->
40
- * [`gchat gchat create-message SPACEID`](#gchat-gchat-create-message-spaceid)
41
- * [`gchat gchat reply-message THREADNAME`](#gchat-gchat-reply-message-threadname)
40
+ * [`gchat gchat config add-token SPACEID TOKEN`](#gchat-gchat-config-add-token-spaceid-token)
41
+ * [`gchat gchat config set-key KEY`](#gchat-gchat-config-set-key-key)
42
+ * [`gchat gchat create-message SPACEID MESSAGE`](#gchat-gchat-create-message-spaceid-message)
43
+ * [`gchat gchat reply-message THREADNAME MESSAGE`](#gchat-gchat-reply-message-threadname-message)
42
44
 
43
- ## `gchat gchat create-message SPACEID`
45
+ ## `gchat gchat config add-token SPACEID TOKEN`
46
+
47
+ Add or update an API token for a Google Chat space
48
+
49
+ ```
50
+ USAGE
51
+ $ gchat gchat config add-token SPACEID TOKEN
52
+
53
+ ARGUMENTS
54
+ SPACEID Google Chat space ID
55
+ TOKEN API token for this space
56
+
57
+ DESCRIPTION
58
+ Add or update an API token for a Google Chat space
59
+
60
+ EXAMPLES
61
+ $ gchat gchat config add-token AAQAKA6hsFw your-space-token
62
+ ```
63
+
64
+ _See code: [src/commands/gchat/config/add-token.ts](https://github.com/hesedcasa/gchat/blob/v0.2.1/src/commands/gchat/config/add-token.ts)_
65
+
66
+ ## `gchat gchat config set-key KEY`
67
+
68
+ Set the Google Chat API key in the config file
69
+
70
+ ```
71
+ USAGE
72
+ $ gchat gchat config set-key KEY
73
+
74
+ ARGUMENTS
75
+ KEY Google Chat API key
76
+
77
+ DESCRIPTION
78
+ Set the Google Chat API key in the config file
79
+
80
+ EXAMPLES
81
+ $ gchat gchat config set-key your-api-key
82
+ ```
83
+
84
+ _See code: [src/commands/gchat/config/set-key.ts](https://github.com/hesedcasa/gchat/blob/v0.2.1/src/commands/gchat/config/set-key.ts)_
85
+
86
+ ## `gchat gchat create-message SPACEID MESSAGE`
44
87
 
45
88
  Send a message to a Google Chat space
46
89
 
47
90
  ```
48
91
  USAGE
49
- $ gchat gchat create-message SPACEID -m <value> [-f] [--toon]
92
+ $ gchat gchat create-message SPACEID MESSAGE [-f] [--toon]
50
93
 
51
94
  ARGUMENTS
52
95
  SPACEID Google Chat space ID
96
+ MESSAGE Message text to send
53
97
 
54
98
  FLAGS
55
- -f, --formatted Enable formatted text (bold, italic, links)
56
- -m, --message=<value> (required) Message text to send
57
- --toon Format output as toon
99
+ -f, --formatted Enable formatted text (bold, italic, links)
100
+ --toon Format output as toon
58
101
 
59
102
  DESCRIPTION
60
103
  Send a message to a Google Chat space
61
104
 
62
105
  EXAMPLES
63
- $ gchat gchat create-message AAQAKA6hsFw --message "Hello team"
106
+ $ gchat gchat create-message AAQAKA6hsFw "Hello team"
64
107
 
65
- $ gchat gchat create-message AAQAKA6hsFw --message "*Bold message*" --formatted
108
+ $ gchat gchat create-message AAQAKA6hsFw "*Bold message*" --formatted
66
109
  ```
67
110
 
68
- _See code: [src/commands/gchat/create-message.ts](https://github.com/hesedcasa/gchat/blob/v0.1.0/src/commands/gchat/create-message.ts)_
111
+ _See code: [src/commands/gchat/create-message.ts](https://github.com/hesedcasa/gchat/blob/v0.2.1/src/commands/gchat/create-message.ts)_
69
112
 
70
- ## `gchat gchat reply-message THREADNAME`
113
+ ## `gchat gchat reply-message THREADNAME MESSAGE`
71
114
 
72
115
  Reply to a message thread in Google Chat
73
116
 
74
117
  ```
75
118
  USAGE
76
- $ gchat gchat reply-message THREADNAME -m <value> [-f] [--toon]
119
+ $ gchat gchat reply-message THREADNAME MESSAGE [-f] [--toon]
77
120
 
78
121
  ARGUMENTS
79
122
  THREADNAME Thread name (e.g. spaces/SPACE_ID/threads/THREAD_ID)
123
+ MESSAGE Message text to send
80
124
 
81
125
  FLAGS
82
- -f, --formatted Enable formatted text (bold, italic, links)
83
- -m, --message=<value> (required) Message text to send
84
- --toon Format output as toon
126
+ -f, --formatted Enable formatted text (bold, italic, links)
127
+ --toon Format output as toon
85
128
 
86
129
  DESCRIPTION
87
130
  Reply to a message thread in Google Chat
88
131
 
89
132
  EXAMPLES
90
- $ gchat gchat reply-message spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA --message "Reply here"
133
+ $ gchat gchat reply-message spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA "Reply here"
91
134
 
92
- $ gchat gchat reply-message spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA --message "*Bold reply*" --formatted
135
+ $ gchat gchat reply-message spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA "*Bold reply*" --formatted
93
136
  ```
94
137
 
95
- _See code: [src/commands/gchat/reply-message.ts](https://github.com/hesedcasa/gchat/blob/v0.1.0/src/commands/gchat/reply-message.ts)_
138
+ _See code: [src/commands/gchat/reply-message.ts](https://github.com/hesedcasa/gchat/blob/v0.2.1/src/commands/gchat/reply-message.ts)_
96
139
  <!-- commandsstop -->
@@ -0,0 +1,10 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class ConfigAddToken extends Command {
3
+ static args: {
4
+ spaceId: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
5
+ token: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
6
+ };
7
+ static description: string;
8
+ static examples: string[];
9
+ run(): Promise<void>;
10
+ }
@@ -0,0 +1,17 @@
1
+ import { Args, Command } from '@oclif/core';
2
+ import { readConfigOrEmpty, writeConfig } from '../../../config.js';
3
+ export default class ConfigAddToken extends Command {
4
+ static args = {
5
+ spaceId: Args.string({ description: 'Google Chat space ID', required: true }),
6
+ token: Args.string({ description: 'API token for this space', required: true }),
7
+ };
8
+ static description = 'Add or update an API token for a Google Chat space';
9
+ static examples = ['<%= config.bin %> <%= command.id %> AAQAKA6hsFw your-space-token'];
10
+ async run() {
11
+ const { args } = await this.parse(ConfigAddToken);
12
+ const config = await readConfigOrEmpty(this.config.configDir);
13
+ config.auth.tokens[args.spaceId] = args.token;
14
+ await writeConfig(this.config.configDir, config);
15
+ this.log(`Token for space ${args.spaceId} updated successfully.`);
16
+ }
17
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class ConfigSetKey extends Command {
3
+ static args: {
4
+ key: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
5
+ };
6
+ static description: string;
7
+ static examples: string[];
8
+ run(): Promise<void>;
9
+ }
@@ -0,0 +1,16 @@
1
+ import { Args, Command } from '@oclif/core';
2
+ import { readConfigOrEmpty, writeConfig } from '../../../config.js';
3
+ export default class ConfigSetKey extends Command {
4
+ static args = {
5
+ key: Args.string({ description: 'Google Chat API key', required: true }),
6
+ };
7
+ static description = 'Set the Google Chat API key in the config file';
8
+ static examples = ['<%= config.bin %> <%= command.id %> your-api-key'];
9
+ async run() {
10
+ const { args } = await this.parse(ConfigSetKey);
11
+ const config = await readConfigOrEmpty(this.config.configDir);
12
+ config.auth.key = args.key;
13
+ await writeConfig(this.config.configDir, config);
14
+ this.log('API key updated successfully.');
15
+ }
16
+ }
@@ -2,12 +2,12 @@ import { Command } from '@oclif/core';
2
2
  export default class GChatCreateMessage extends Command {
3
3
  static args: {
4
4
  spaceId: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
5
+ message: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
5
6
  };
6
7
  static description: string;
7
8
  static examples: string[];
8
9
  static flags: {
9
10
  formatted: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
- message: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
11
  toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
12
  };
13
13
  run(): Promise<void>;
@@ -3,17 +3,19 @@ import { readConfig } from '../../config.js';
3
3
  import { formatAsToon } from '../../format.js';
4
4
  import { clearClients, newMessage } from '../../gchat/gchat-client.js';
5
5
  export default class GChatCreateMessage extends Command {
6
+ /* eslint-disable perfectionist/sort-objects */
6
7
  static args = {
7
8
  spaceId: Args.string({ description: 'Google Chat space ID', required: true }),
9
+ message: Args.string({ description: 'Message text to send', required: true }),
8
10
  };
11
+ /* eslint-enable perfectionist/sort-objects */
9
12
  static description = 'Send a message to a Google Chat space';
10
13
  static examples = [
11
- '<%= config.bin %> <%= command.id %> AAQAKA6hsFw --message "Hello team"',
12
- '<%= config.bin %> <%= command.id %> AAQAKA6hsFw --message "*Bold message*" --formatted',
14
+ '<%= config.bin %> <%= command.id %> AAQAKA6hsFw "Hello team"',
15
+ '<%= config.bin %> <%= command.id %> AAQAKA6hsFw "*Bold message*" --formatted',
13
16
  ];
14
17
  static flags = {
15
18
  formatted: Flags.boolean({ char: 'f', description: 'Enable formatted text (bold, italic, links)', required: false }),
16
- message: Flags.string({ char: 'm', description: 'Message text to send', required: true }),
17
19
  toon: Flags.boolean({ description: 'Format output as toon', required: false }),
18
20
  };
19
21
  async run() {
@@ -21,7 +23,8 @@ export default class GChatCreateMessage extends Command {
21
23
  const config = await readConfig(this.config.configDir, this.log.bind(this));
22
24
  if (!config)
23
25
  return;
24
- const result = await newMessage(config.auth, args.spaceId, flags.message, flags.formatted);
26
+ // eslint-disable-next-line unicorn/prefer-string-replace-all
27
+ const result = await newMessage(config.auth, args.spaceId, args.message.replace(/\\n/g, '\n'), flags.formatted);
25
28
  clearClients();
26
29
  if (flags.toon) {
27
30
  this.log(formatAsToon(result));
@@ -2,12 +2,12 @@ import { Command } from '@oclif/core';
2
2
  export default class GChatReplyMessage extends Command {
3
3
  static args: {
4
4
  threadName: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
5
+ message: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
5
6
  };
6
7
  static description: string;
7
8
  static examples: string[];
8
9
  static flags: {
9
10
  formatted: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
- message: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
11
  toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
12
  };
13
13
  run(): Promise<void>;
@@ -3,20 +3,22 @@ import { readConfig } from '../../config.js';
3
3
  import { formatAsToon } from '../../format.js';
4
4
  import { clearClients, replyMessage } from '../../gchat/gchat-client.js';
5
5
  export default class GChatReplyMessage extends Command {
6
+ /* eslint-disable perfectionist/sort-objects */
6
7
  static args = {
7
8
  threadName: Args.string({
8
9
  description: 'Thread name (e.g. spaces/SPACE_ID/threads/THREAD_ID)',
9
10
  required: true,
10
11
  }),
12
+ message: Args.string({ description: 'Message text to send', required: true }),
11
13
  };
14
+ /* eslint-enable perfectionist/sort-objects */
12
15
  static description = 'Reply to a message thread in Google Chat';
13
16
  static examples = [
14
- '<%= config.bin %> <%= command.id %> spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA --message "Reply here"',
15
- '<%= config.bin %> <%= command.id %> spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA --message "*Bold reply*" --formatted',
17
+ '<%= config.bin %> <%= command.id %> spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA "Reply here"',
18
+ '<%= config.bin %> <%= command.id %> spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA "*Bold reply*" --formatted',
16
19
  ];
17
20
  static flags = {
18
21
  formatted: Flags.boolean({ char: 'f', description: 'Enable formatted text (bold, italic, links)', required: false }),
19
- message: Flags.string({ char: 'm', description: 'Message text to send', required: true }),
20
22
  toon: Flags.boolean({ description: 'Format output as toon', required: false }),
21
23
  };
22
24
  async run() {
@@ -24,7 +26,8 @@ export default class GChatReplyMessage extends Command {
24
26
  const config = await readConfig(this.config.configDir, this.log.bind(this));
25
27
  if (!config)
26
28
  return;
27
- const result = await replyMessage(config.auth, args.threadName, flags.message, flags.formatted);
29
+ // eslint-disable-next-line unicorn/prefer-string-replace-all
30
+ const result = await replyMessage(config.auth, args.threadName, args.message.replace(/\\n/g, '\n'), flags.formatted);
28
31
  clearClients();
29
32
  if (flags.toon) {
30
33
  this.log(formatAsToon(result));
package/dist/config.d.ts CHANGED
@@ -2,7 +2,10 @@ export interface GChatAuth {
2
2
  key: string;
3
3
  tokens: Record<string, string>;
4
4
  }
5
- export interface GChatConfig {
5
+ interface GChatConfig {
6
6
  auth: GChatAuth;
7
7
  }
8
+ export declare function readConfigOrEmpty(configDir: string): Promise<GChatConfig>;
9
+ export declare function writeConfig(configDir: string, config: GChatConfig): Promise<void>;
8
10
  export declare function readConfig(configDir: string, log: (msg: string) => void): Promise<GChatConfig | null>;
11
+ export {};
package/dist/config.js CHANGED
@@ -1,5 +1,20 @@
1
- import { readFile } from 'node:fs/promises';
1
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
+ export async function readConfigOrEmpty(configDir) {
4
+ const configPath = join(configDir, 'gchat-config.json');
5
+ try {
6
+ const raw = JSON.parse(await readFile(configPath, 'utf8'));
7
+ return { auth: { key: raw.key ?? '', tokens: raw.tokens ?? {} } };
8
+ }
9
+ catch {
10
+ return { auth: { key: '', tokens: {} } };
11
+ }
12
+ }
13
+ export async function writeConfig(configDir, config) {
14
+ const configPath = join(configDir, 'gchat-config.json');
15
+ await mkdir(configDir, { recursive: true });
16
+ await writeFile(configPath, JSON.stringify(config.auth, null, 2));
17
+ }
3
18
  export async function readConfig(configDir, log) {
4
19
  const configPath = join(configDir, 'gchat-config.json');
5
20
  try {
@@ -7,12 +7,17 @@
7
7
  "description": "Google Chat space ID",
8
8
  "name": "spaceId",
9
9
  "required": true
10
+ },
11
+ "message": {
12
+ "description": "Message text to send",
13
+ "name": "message",
14
+ "required": true
10
15
  }
11
16
  },
12
17
  "description": "Send a message to a Google Chat space",
13
18
  "examples": [
14
- "<%= config.bin %> <%= command.id %> AAQAKA6hsFw --message \"Hello team\"",
15
- "<%= config.bin %> <%= command.id %> AAQAKA6hsFw --message \"*Bold message*\" --formatted"
19
+ "<%= config.bin %> <%= command.id %> AAQAKA6hsFw \"Hello team\"",
20
+ "<%= config.bin %> <%= command.id %> AAQAKA6hsFw \"*Bold message*\" --formatted"
16
21
  ],
17
22
  "flags": {
18
23
  "formatted": {
@@ -23,15 +28,6 @@
23
28
  "allowNo": false,
24
29
  "type": "boolean"
25
30
  },
26
- "message": {
27
- "char": "m",
28
- "description": "Message text to send",
29
- "name": "message",
30
- "required": true,
31
- "hasDynamicHelp": false,
32
- "multiple": false,
33
- "type": "option"
34
- },
35
31
  "toon": {
36
32
  "description": "Format output as toon",
37
33
  "name": "toon",
@@ -63,12 +59,17 @@
63
59
  "description": "Thread name (e.g. spaces/SPACE_ID/threads/THREAD_ID)",
64
60
  "name": "threadName",
65
61
  "required": true
62
+ },
63
+ "message": {
64
+ "description": "Message text to send",
65
+ "name": "message",
66
+ "required": true
66
67
  }
67
68
  },
68
69
  "description": "Reply to a message thread in Google Chat",
69
70
  "examples": [
70
- "<%= config.bin %> <%= command.id %> spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA --message \"Reply here\"",
71
- "<%= config.bin %> <%= command.id %> spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA --message \"*Bold reply*\" --formatted"
71
+ "<%= config.bin %> <%= command.id %> spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA \"Reply here\"",
72
+ "<%= config.bin %> <%= command.id %> spaces/AAQAKA6hsFw/threads/D1NI3W2B6vA \"*Bold reply*\" --formatted"
72
73
  ],
73
74
  "flags": {
74
75
  "formatted": {
@@ -79,15 +80,6 @@
79
80
  "allowNo": false,
80
81
  "type": "boolean"
81
82
  },
82
- "message": {
83
- "char": "m",
84
- "description": "Message text to send",
85
- "name": "message",
86
- "required": true,
87
- "hasDynamicHelp": false,
88
- "multiple": false,
89
- "type": "option"
90
- },
91
83
  "toon": {
92
84
  "description": "Format output as toon",
93
85
  "name": "toon",
@@ -111,7 +103,74 @@
111
103
  "gchat",
112
104
  "reply-message.js"
113
105
  ]
106
+ },
107
+ "gchat:config:add-token": {
108
+ "aliases": [],
109
+ "args": {
110
+ "spaceId": {
111
+ "description": "Google Chat space ID",
112
+ "name": "spaceId",
113
+ "required": true
114
+ },
115
+ "token": {
116
+ "description": "API token for this space",
117
+ "name": "token",
118
+ "required": true
119
+ }
120
+ },
121
+ "description": "Add or update an API token for a Google Chat space",
122
+ "examples": [
123
+ "<%= config.bin %> <%= command.id %> AAQAKA6hsFw your-space-token"
124
+ ],
125
+ "flags": {},
126
+ "hasDynamicHelp": false,
127
+ "hiddenAliases": [],
128
+ "id": "gchat:config:add-token",
129
+ "pluginAlias": "@hesed/gchat",
130
+ "pluginName": "@hesed/gchat",
131
+ "pluginType": "core",
132
+ "strict": true,
133
+ "enableJsonFlag": false,
134
+ "isESM": true,
135
+ "relativePath": [
136
+ "dist",
137
+ "commands",
138
+ "gchat",
139
+ "config",
140
+ "add-token.js"
141
+ ]
142
+ },
143
+ "gchat:config:set-key": {
144
+ "aliases": [],
145
+ "args": {
146
+ "key": {
147
+ "description": "Google Chat API key",
148
+ "name": "key",
149
+ "required": true
150
+ }
151
+ },
152
+ "description": "Set the Google Chat API key in the config file",
153
+ "examples": [
154
+ "<%= config.bin %> <%= command.id %> your-api-key"
155
+ ],
156
+ "flags": {},
157
+ "hasDynamicHelp": false,
158
+ "hiddenAliases": [],
159
+ "id": "gchat:config:set-key",
160
+ "pluginAlias": "@hesed/gchat",
161
+ "pluginName": "@hesed/gchat",
162
+ "pluginType": "core",
163
+ "strict": true,
164
+ "enableJsonFlag": false,
165
+ "isESM": true,
166
+ "relativePath": [
167
+ "dist",
168
+ "commands",
169
+ "gchat",
170
+ "config",
171
+ "set-key.js"
172
+ ]
114
173
  }
115
174
  },
116
- "version": "0.1.0"
175
+ "version": "0.2.1"
117
176
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hesed/gchat",
3
3
  "description": "CLI for Google Chat API interaction",
4
- "version": "0.1.0",
4
+ "version": "0.2.1",
5
5
  "author": "Hesed",
6
6
  "bin": {
7
7
  "gchat": "./bin/run.js"