@tak-ps/node-tak 8.10.0 → 9.0.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.
Files changed (65) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +36 -1
  3. package/cli.ts +174 -0
  4. package/dist/cli.js +135 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/index.js +16 -5
  7. package/dist/index.js.map +1 -1
  8. package/dist/lib/api/contacts.js +24 -4
  9. package/dist/lib/api/contacts.js.map +1 -1
  10. package/dist/lib/api/credentials.js +16 -4
  11. package/dist/lib/api/credentials.js.map +1 -1
  12. package/dist/lib/api/export.js +5 -4
  13. package/dist/lib/api/export.js.map +1 -1
  14. package/dist/lib/api/files.js +40 -8
  15. package/dist/lib/api/files.js.map +1 -1
  16. package/dist/lib/api/groups.js +24 -4
  17. package/dist/lib/api/groups.js.map +1 -1
  18. package/dist/lib/api/injectors.js +24 -4
  19. package/dist/lib/api/injectors.js.map +1 -1
  20. package/dist/lib/api/mission-layer.js +11 -4
  21. package/dist/lib/api/mission-layer.js.map +1 -1
  22. package/dist/lib/api/mission-log.js +5 -4
  23. package/dist/lib/api/mission-log.js.map +1 -1
  24. package/dist/lib/api/mission.js +24 -4
  25. package/dist/lib/api/mission.js.map +1 -1
  26. package/dist/lib/api/oauth.js +5 -4
  27. package/dist/lib/api/oauth.js.map +1 -1
  28. package/dist/lib/api/package.js +24 -4
  29. package/dist/lib/api/package.js.map +1 -1
  30. package/dist/lib/api/query.js +5 -4
  31. package/dist/lib/api/query.js.map +1 -1
  32. package/dist/lib/api/repeater.js +5 -4
  33. package/dist/lib/api/repeater.js.map +1 -1
  34. package/dist/lib/api/subscriptions.js +5 -4
  35. package/dist/lib/api/subscriptions.js.map +1 -1
  36. package/dist/lib/api/video.js +16 -4
  37. package/dist/lib/api/video.js.map +1 -1
  38. package/dist/lib/api.js +17 -0
  39. package/dist/lib/api.js.map +1 -1
  40. package/dist/lib/auth.js +11 -0
  41. package/dist/lib/auth.js.map +1 -1
  42. package/dist/lib/commands.js +27 -0
  43. package/dist/lib/commands.js.map +1 -0
  44. package/dist/tsconfig.tsbuildinfo +1 -1
  45. package/index.ts +29 -19
  46. package/lib/api/contacts.ts +23 -5
  47. package/lib/api/credentials.ts +17 -6
  48. package/lib/api/export.ts +5 -5
  49. package/lib/api/files.ts +43 -10
  50. package/lib/api/groups.ts +24 -5
  51. package/lib/api/injectors.ts +24 -5
  52. package/lib/api/mission-layer.ts +11 -5
  53. package/lib/api/mission-log.ts +5 -5
  54. package/lib/api/mission.ts +24 -5
  55. package/lib/api/oauth.ts +5 -5
  56. package/lib/api/package.ts +24 -5
  57. package/lib/api/query.ts +5 -5
  58. package/lib/api/repeater.ts +5 -5
  59. package/lib/api/subscriptions.ts +5 -5
  60. package/lib/api/video.ts +16 -5
  61. package/lib/api.ts +18 -0
  62. package/lib/auth.ts +12 -0
  63. package/lib/commands.ts +41 -0
  64. package/package.json +7 -1
  65. package/tsconfig.json +1 -0
package/lib/api/oauth.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import Err from '@openaddresses/batch-error';
2
- import TAKAPI from '../api.js';
3
2
  import { Type, Static } from '@sinclair/typebox';
3
+ import Commands from '../commands.js';
4
4
 
5
5
  export const LoginInput = Type.Object({
6
6
  username: Type.String(),
@@ -15,11 +15,11 @@ export const TokenContents = Type.Object({
15
15
  iat: Type.Number()
16
16
  })
17
17
 
18
- export default class {
19
- api: TAKAPI;
18
+ export default class OAuthCommands extends Commands {
19
+ schema = {}
20
20
 
21
- constructor(api: TAKAPI) {
22
- this.api = api;
21
+ async cli(): Promise<object | string> {
22
+ throw new Error('Unsupported Subcommand');
23
23
  }
24
24
 
25
25
  parse(jwt: string): Static<typeof TokenContents>{
@@ -1,5 +1,6 @@
1
- import TAKAPI from '../api.js';
2
1
  import { Type, Static } from '@sinclair/typebox';
2
+ import type { ParsedArgs } from 'minimist'
3
+ import Commands from '../commands.js';
3
4
 
4
5
  export const Package = Type.Object({
5
6
  EXPIRATION: Type.String(),
@@ -24,11 +25,29 @@ export const ListInput = Type.Object({
24
25
  /**
25
26
  * @class
26
27
  */
27
- export default class {
28
- api: TAKAPI;
28
+ export default class PackageCommands extends Commands {
29
+ schema = {
30
+ list: {
31
+ description: 'List Data Packages',
32
+ params: Type.Object({}),
33
+ query: Type.Object({})
34
+ }
35
+ }
36
+
37
+ async cli(args: ParsedArgs): Promise<object | string> {
38
+ if (args._[3] === 'list') {
39
+ const list = await this.list({});
29
40
 
30
- constructor(api: TAKAPI) {
31
- this.api = api;
41
+ if (args.format === 'json') {
42
+ return list;
43
+ } else {
44
+ return list.results.map((data) => {
45
+ return data.Name;
46
+ }).join('\n');
47
+ }
48
+ } else {
49
+ throw new Error('Unsupported Subcommand');
50
+ }
32
51
  }
33
52
 
34
53
  async list(query: Static<typeof ListInput>): Promise<{
package/lib/api/query.ts CHANGED
@@ -1,9 +1,9 @@
1
- import TAKAPI from '../api.js';
2
1
  import Err from '@openaddresses/batch-error';
3
2
  import xmljs from 'xml-js';
4
3
  import { Type, Static } from '@sinclair/typebox';
5
4
  import CoT from '@tak-ps/node-cot';
6
5
  import type { Feature } from '@tak-ps/node-cot';
6
+ import Commands from '../commands.js';
7
7
 
8
8
  export const HistoryOptions = Type.Object({
9
9
  start: Type.Optional(Type.String()),
@@ -11,11 +11,11 @@ export const HistoryOptions = Type.Object({
11
11
  secago: Type.Optional(Type.String()),
12
12
  })
13
13
 
14
- export default class COTQuery {
15
- api: TAKAPI;
14
+ export default class QueryCommands extends Commands {
15
+ schema = {}
16
16
 
17
- constructor(api: TAKAPI) {
18
- this.api = api;
17
+ async cli(): Promise<object | string> {
18
+ throw new Error('Unsupported Subcommand');
19
19
  }
20
20
 
21
21
  async singleFeat(uid: string): Promise<Static<typeof Feature.Feature>> {
@@ -1,6 +1,6 @@
1
- import TAKAPI from '../api.js';
2
1
  import { TAKList } from './types.js';
3
2
  import { Type, Static } from '@sinclair/typebox';
3
+ import Commands from '../commands.js';
4
4
 
5
5
  export const Repeater = Type.Object({
6
6
  uid: Type.String(),
@@ -13,11 +13,11 @@ export const Repeater = Type.Object({
13
13
 
14
14
  export const TAKList_Repeater = TAKList(Repeater);
15
15
 
16
- export default class {
17
- api: TAKAPI;
16
+ export default class RepeaterCommands extends Commands {
17
+ schema = {}
18
18
 
19
- constructor(api: TAKAPI) {
20
- this.api = api;
19
+ async cli(): Promise<object | string> {
20
+ throw new Error('Unsupported Subcommand');
21
21
  }
22
22
 
23
23
  /**
@@ -1,7 +1,7 @@
1
- import TAKAPI from '../api.js';
2
1
  import { Type, Static } from '@sinclair/typebox';
3
2
  import { Group } from './groups.js';
4
3
  import { TAKList } from './types.js';
4
+ import Commands from '../commands.js';
5
5
 
6
6
  export const Subscription = Type.Object({
7
7
  dn: Type.Union([Type.String(), Type.Null()]),
@@ -58,11 +58,11 @@ export const ListSubscriptionInput = Type.Object({
58
58
  export const TAKList_Subscription = TAKList(Subscription);
59
59
 
60
60
 
61
- export default class {
62
- api: TAKAPI;
61
+ export default class SubscriptionCommands extends Commands {
62
+ schema = {}
63
63
 
64
- constructor(api: TAKAPI) {
65
- this.api = api;
64
+ async cli(): Promise<object | string> {
65
+ throw new Error('Unsupported Subcommand');
66
66
  }
67
67
 
68
68
  async list(
package/lib/api/video.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import Err from '@openaddresses/batch-error';
2
+ import type { ParsedArgs } from 'minimist'
2
3
  import { Static, Type } from '@sinclair/typebox';
3
4
  import { randomUUID } from 'node:crypto';
4
- import TAKAPI from '../api.js';
5
+ import Commands from '../commands.js';
5
6
 
6
7
  export const FeedInput = Type.Object({
7
8
  uuid: Type.Optional(Type.String()),
@@ -62,11 +63,21 @@ export const VideoConnectionListInput = Type.Object({
62
63
  protocol: Type.Optional(Type.String())
63
64
  })
64
65
 
65
- export default class {
66
- api: TAKAPI;
66
+ export default class VideoCommands extends Commands {
67
+ schema = {
68
+ list: {
69
+ description: 'List V2 Video Configs',
70
+ params: Type.Object({}),
71
+ query: Type.Object({})
72
+ }
73
+ }
67
74
 
68
- constructor(api: TAKAPI) {
69
- this.api = api;
75
+ async cli(args: ParsedArgs): Promise<object | string> {
76
+ if (args._[3] === 'list') {
77
+ return await this.list()
78
+ } else {
79
+ throw new Error('Unsupported Subcommand');
80
+ }
70
81
  }
71
82
 
72
83
  async list(
package/lib/api.ts CHANGED
@@ -17,6 +17,24 @@ import Export from './api/export.js';
17
17
  import Err from '@openaddresses/batch-error';
18
18
  import * as auth from './auth.js';
19
19
 
20
+ export const CommandList: Record<string, keyof TAKAPI> = {
21
+ package: 'Package',
22
+ oauth: 'OAuth',
23
+ mission: 'Mission',
24
+ 'mission-log': 'MissionLog',
25
+ 'mission-layer': 'MissionLayer',
26
+ credential: 'Credentials',
27
+ contact: 'Contacts',
28
+ subscription: 'Subscription',
29
+ injector: 'Injectors',
30
+ repeater: 'Repeater',
31
+ group: 'Group',
32
+ video: 'Video',
33
+ export: 'Export',
34
+ query: 'Query',
35
+ file: 'Files'
36
+ }
37
+
20
38
  /**
21
39
  * Handle TAK HTTP API Operations
22
40
  * @class
package/lib/auth.ts CHANGED
@@ -1,10 +1,22 @@
1
1
  import fetch from './fetch.js';
2
+ import { Type } from '@sinclair/typebox';
2
3
  import { CookieJar, Cookie } from 'tough-cookie';
3
4
  import { CookieAgent } from 'http-cookie-agent/undici';
4
5
  import { Client } from 'undici';
5
6
  import TAKAPI from './api.js';
6
7
  import stream2buffer from './stream.js';
7
8
 
9
+ /**
10
+ * Store the TAK Client Certificate for a connection
11
+ */
12
+ export const TAKAuth = Type.Object({
13
+ cert: Type.String(),
14
+ key: Type.String(),
15
+ passphrase: Type.Optional(Type.String()),
16
+ ca: Type.Optional(Type.String()),
17
+ rejectUnauthorized: Type.Optional(Type.Boolean())
18
+ })
19
+
8
20
  export class APIAuth {
9
21
  async init(api: TAKAPI) { // eslint-disable-line @typescript-eslint/no-unused-vars
10
22
 
@@ -0,0 +1,41 @@
1
+ import { TAKAuth } from './auth.js';
2
+ import type { ParsedArgs } from 'minimist';
3
+ import TAKAPI from './api.js';
4
+ import type { TObject } from '@sinclair/typebox';
5
+ import { Type } from '@sinclair/typebox';
6
+
7
+ export const CommandConfig = Type.Object({
8
+ version: Type.Integer(),
9
+ profiles: Type.Record(
10
+ Type.String(),
11
+ Type.Object({
12
+ host: Type.String(),
13
+ ports: Type.Object({
14
+ marti: Type.Integer(),
15
+ webtak: Type.Integer(),
16
+ stream: Type.Integer()
17
+ }),
18
+ auth: Type.Optional(TAKAuth)
19
+ })
20
+ )
21
+ })
22
+
23
+
24
+ export default class Commands {
25
+ api: TAKAPI;
26
+
27
+ schema: Record<string, {
28
+ description: string,
29
+ params: TObject<any>,
30
+ query: TObject<any>,
31
+ }> = {};
32
+
33
+ constructor(api: TAKAPI) {
34
+ this.api = api;
35
+ }
36
+
37
+ async cli(args: ParsedArgs): Promise<object | string> {
38
+ if (!args) throw new Error('Args object must be provided');
39
+ throw new Error('Command not yet supported');
40
+ }
41
+ }
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@tak-ps/node-tak",
3
3
  "type": "module",
4
- "version": "8.10.0",
4
+ "version": "9.0.0",
5
5
  "description": "Lightweight JavaScript library for communicating with TAK Server",
6
6
  "author": "Nick Ingalls <nick@ingalls.ca>",
7
7
  "main": "dist/index.js",
8
8
  "types": "index.ts",
9
+ "bin": {
10
+ "tak": "tsx ./cli.ts"
11
+ },
9
12
  "exports": {
10
13
  ".": "./dist/index.js",
11
14
  "./lib/*": "./dist/lib/*.js",
@@ -35,12 +38,15 @@
35
38
  "@tak-ps/node-cot": "^12.0.0"
36
39
  },
37
40
  "devDependencies": {
41
+ "@inquirer/prompts": "^7.5.1",
42
+ "@types/minimist": "^1.2.5",
38
43
  "@types/node": "^22.0.0",
39
44
  "@types/pem": "^1.14.4",
40
45
  "@types/tape": "^5.6.0",
41
46
  "@types/xml2js": "^0.4.14",
42
47
  "c8": "^10.1.3",
43
48
  "eslint": "^9.0.0",
49
+ "minimist": "^1.2.8",
44
50
  "tape": "^5.6.1",
45
51
  "ts-node": "^10.9.1",
46
52
  "ts-node-test": "^0.4.0",
package/tsconfig.json CHANGED
@@ -22,6 +22,7 @@
22
22
  }
23
23
  },
24
24
  "include": [
25
+ "cli.ts",
25
26
  "index.ts",
26
27
  "test/**/*",
27
28
  "lib/**/*",