@machhub-dev/sdk-ts 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/classes/auth.d.ts +18 -0
- package/dist/cjs/classes/auth.js +90 -0
- package/dist/cjs/classes/collection.d.ts +18 -0
- package/dist/cjs/classes/collection.js +43 -0
- package/dist/cjs/classes/flow.d.ts +6 -0
- package/dist/cjs/classes/flow.js +12 -0
- package/dist/cjs/classes/function.d.ts +10 -0
- package/dist/cjs/classes/function.js +29 -0
- package/dist/cjs/classes/historian.d.ts +12 -0
- package/dist/cjs/classes/historian.js +40 -0
- package/dist/cjs/classes/tag.d.ts +10 -0
- package/dist/cjs/classes/tag.js +25 -0
- package/dist/cjs/client.d.ts +13 -0
- package/dist/cjs/client.js +35 -0
- package/dist/cjs/config.d.ts +21 -0
- package/dist/cjs/config.js +37 -0
- package/dist/cjs/example/functions-file-config.d.ts +0 -0
- package/dist/cjs/example/functions-file-config.js +1 -0
- package/dist/cjs/example/functions.d.ts +1 -0
- package/dist/cjs/example/functions.js +18 -0
- package/dist/cjs/http-client.d.ts +10 -0
- package/dist/cjs/http-client.js +62 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/sdk-ts-clean.d.ts +108 -0
- package/dist/cjs/sdk-ts-clean.js +294 -0
- package/dist/cjs/sdk-ts.d.ts +71 -0
- package/dist/cjs/sdk-ts.js +227 -0
- package/dist/cjs/services/http.service.d.ts +41 -0
- package/dist/cjs/services/http.service.js +178 -0
- package/dist/cjs/services/mqtt.service.d.ts +15 -0
- package/dist/cjs/services/mqtt.service.js +103 -0
- package/dist/cjs/services/nats.service.d.ts +78 -0
- package/dist/cjs/services/nats.service.js +237 -0
- package/dist/cjs/types/auth.models.d.ts +52 -0
- package/dist/cjs/types/auth.models.js +100 -0
- package/dist/cjs/types/recordID.models.d.ts +7 -0
- package/dist/cjs/types/recordID.models.js +32 -0
- package/dist/cjs/types/response.models.d.ts +4 -0
- package/dist/cjs/types/response.models.js +2 -0
- package/dist/cjs/types/tag.models.d.ts +4 -0
- package/dist/cjs/types/tag.models.js +2 -0
- package/dist/cjs/utils/appConfig.d.ts +5 -0
- package/dist/cjs/utils/appConfig.js +62 -0
- package/dist/cjs/websocket-client.d.ts +15 -0
- package/dist/cjs/websocket-client.js +96 -0
- package/dist/classes/auth.d.ts +18 -0
- package/dist/classes/auth.js +86 -0
- package/dist/classes/collection.d.ts +18 -0
- package/dist/classes/collection.js +39 -0
- package/dist/classes/flow.d.ts +6 -0
- package/dist/classes/flow.js +8 -0
- package/dist/classes/function.d.ts +10 -0
- package/dist/classes/function.js +25 -0
- package/dist/classes/historian.d.ts +12 -0
- package/dist/classes/historian.js +36 -0
- package/dist/classes/tag.d.ts +10 -0
- package/dist/classes/tag.js +21 -0
- package/dist/client.d.ts +13 -0
- package/dist/client.js +31 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.js +33 -0
- package/dist/example/functions-file-config.d.ts +0 -0
- package/dist/example/functions-file-config.js +1 -0
- package/dist/example/functions.d.ts +1 -0
- package/dist/example/functions.js +16 -0
- package/dist/http-client.d.ts +10 -0
- package/dist/http-client.js +58 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2 -0
- package/dist/sdk-ts-clean.d.ts +108 -0
- package/dist/sdk-ts-clean.js +290 -0
- package/dist/sdk-ts.d.ts +71 -0
- package/dist/sdk-ts.js +223 -0
- package/dist/services/http.service.d.ts +41 -0
- package/dist/services/http.service.js +173 -0
- package/dist/services/mqtt.service.d.ts +15 -0
- package/dist/services/mqtt.service.js +96 -0
- package/dist/services/nats.service.d.ts +78 -0
- package/dist/services/nats.service.js +233 -0
- package/dist/types/auth.models.d.ts +52 -0
- package/dist/types/auth.models.js +97 -0
- package/dist/types/recordID.models.d.ts +7 -0
- package/dist/types/recordID.models.js +27 -0
- package/dist/types/response.models.d.ts +4 -0
- package/dist/types/response.models.js +1 -0
- package/dist/types/tag.models.d.ts +4 -0
- package/dist/types/tag.models.js +1 -0
- package/dist/utils/appConfig.d.ts +5 -0
- package/dist/utils/appConfig.js +26 -0
- package/dist/websocket-client.d.ts +15 -0
- package/dist/websocket-client.js +92 -0
- package/package.json +33 -0
- package/src/classes/auth.ts +103 -0
- package/src/classes/collection.ts +55 -0
- package/src/classes/flow.ts +13 -0
- package/src/classes/function.ts +34 -0
- package/src/classes/historian.ts +49 -0
- package/src/classes/tag.ts +30 -0
- package/src/example/functions.ts +21 -0
- package/src/index.ts +8 -0
- package/src/sdk-ts.ts +255 -0
- package/src/services/http.service.ts +239 -0
- package/src/services/mqtt.service.ts +114 -0
- package/src/services/nats.service.ts +262 -0
- package/src/types/auth.models.ts +157 -0
- package/src/types/recordID.models.ts +33 -0
- package/src/types/response.models.ts +4 -0
- package/src/types/tag.models.ts +4 -0
- package/src/utils/appConfig.ts +30 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { RecordID } from "./recordID.models";
|
|
2
|
+
import { BaseResponse } from "./response.models";
|
|
3
|
+
|
|
4
|
+
export interface LoginResponse extends BaseResponse {
|
|
5
|
+
tkn: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface PermissionResponse extends BaseResponse {
|
|
9
|
+
permission: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ValidateJWTResponse extends BaseResponse {
|
|
13
|
+
valid: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export interface User {
|
|
18
|
+
id?: RecordID;
|
|
19
|
+
firstName: string;
|
|
20
|
+
lastName: string;
|
|
21
|
+
username: string;
|
|
22
|
+
email: string;
|
|
23
|
+
password: string
|
|
24
|
+
number: string;
|
|
25
|
+
createdDt?: string;
|
|
26
|
+
userImage: string | ArrayBuffer | null;
|
|
27
|
+
group_ids?: string[];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export interface Group {
|
|
31
|
+
id?: RecordID;
|
|
32
|
+
features?: {
|
|
33
|
+
name: string;
|
|
34
|
+
action: string;
|
|
35
|
+
domain: string;
|
|
36
|
+
scope: string;
|
|
37
|
+
}[];
|
|
38
|
+
name: string;
|
|
39
|
+
user_ids: RecordID[];
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export interface Feature {
|
|
43
|
+
name:string
|
|
44
|
+
action:string
|
|
45
|
+
scope:Scope
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface Permission {
|
|
49
|
+
displayName:string;
|
|
50
|
+
description:string;
|
|
51
|
+
name: string;
|
|
52
|
+
action: string;
|
|
53
|
+
scope: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function machhubPermissions(): Permission[]{
|
|
57
|
+
return [
|
|
58
|
+
{
|
|
59
|
+
displayName: 'Applications',
|
|
60
|
+
description: 'View or manage applications all applications in MACHHUB',
|
|
61
|
+
name: 'applications',
|
|
62
|
+
action: 'nil',
|
|
63
|
+
scope: 'all'
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
displayName: 'Users',
|
|
67
|
+
description: 'View or manage user accounts in this domain',
|
|
68
|
+
name: 'users',
|
|
69
|
+
action: 'nil',
|
|
70
|
+
scope: 'domain'
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
displayName: 'Groups',
|
|
74
|
+
description: 'View or manage user groups in this domain',
|
|
75
|
+
name: 'groups',
|
|
76
|
+
action: 'nil',
|
|
77
|
+
scope: 'domain'
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
displayName: 'Manage Own API Keys',
|
|
81
|
+
description: 'View or manage API keys for own account',
|
|
82
|
+
name: 'api_keys',
|
|
83
|
+
action: 'nil',
|
|
84
|
+
scope: 'self'
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
displayName: 'Manage All API Keys',
|
|
88
|
+
description: 'View or manage all API keys in MACHHUB',
|
|
89
|
+
name: 'api_keys',
|
|
90
|
+
action: 'nil',
|
|
91
|
+
scope: 'all'
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
displayName: 'Upstreams',
|
|
95
|
+
description: 'View or manage all upstream configurations in MACHHUB',
|
|
96
|
+
name: 'upstreams',
|
|
97
|
+
action: 'nil',
|
|
98
|
+
scope: 'domain'
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
displayName: 'Manage Namespace',
|
|
102
|
+
description: 'View or manage namespaces in this domain',
|
|
103
|
+
name: 'namespace',
|
|
104
|
+
action: 'nil',
|
|
105
|
+
scope: 'domain'
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
displayName: 'Historian',
|
|
109
|
+
description: 'View or manage historian data in this domain',
|
|
110
|
+
name: 'historian',
|
|
111
|
+
action: 'nil',
|
|
112
|
+
scope: 'domain'
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
displayName: 'Collections',
|
|
116
|
+
description: 'View or manage collections in this domain',
|
|
117
|
+
name: 'collections',
|
|
118
|
+
action: 'nil',
|
|
119
|
+
scope: 'domain'
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
displayName: 'Logs',
|
|
123
|
+
description: 'View or manage system logs',
|
|
124
|
+
name: 'logs',
|
|
125
|
+
action: 'nil',
|
|
126
|
+
scope: 'all'
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
displayName: 'General Settings',
|
|
130
|
+
description: 'View or manage general system settings',
|
|
131
|
+
name: 'general_settings',
|
|
132
|
+
action: 'nil',
|
|
133
|
+
scope: 'all'
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
displayName: 'Gateway Settings',
|
|
137
|
+
description: 'View or manage gateway settings',
|
|
138
|
+
name: 'gateway',
|
|
139
|
+
action: 'nil',
|
|
140
|
+
scope: 'all'
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
displayName: 'License',
|
|
144
|
+
description: 'View or manage MACHHUB licensing details',
|
|
145
|
+
name: 'license',
|
|
146
|
+
action: 'nil',
|
|
147
|
+
scope: 'all'
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface ActionResponse extends BaseResponse {
|
|
153
|
+
action: "read" | "read-write" | ""
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export type Action = "read" | "read-write"
|
|
157
|
+
export type Scope = "self" | "domain" | "all"| "nil"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface RecordID {
|
|
2
|
+
Table: string;
|
|
3
|
+
ID: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function StringToRecordID(id: string): RecordID {
|
|
7
|
+
const splitID = id.split(":");
|
|
8
|
+
if (splitID.length != 2) return emptyRecordID();
|
|
9
|
+
return {
|
|
10
|
+
Table: containsSpace(splitID[0]) ? `(${splitID[0]})` : splitID[0],
|
|
11
|
+
ID: splitID[1]
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function RecordIDToString(recordID: RecordID | undefined): string {
|
|
16
|
+
if (recordID != undefined) {
|
|
17
|
+
return recordID.Table + ":" + recordID.ID;
|
|
18
|
+
} else {
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function emptyRecordID(): RecordID {
|
|
24
|
+
return {
|
|
25
|
+
Table: "",
|
|
26
|
+
ID: "",
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Helper function to check if a string contains spaces
|
|
31
|
+
function containsSpace(s: string): boolean {
|
|
32
|
+
return s.includes(" ");
|
|
33
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
interface AppConfig {
|
|
5
|
+
application_id: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getAppConfig(): AppConfig {
|
|
9
|
+
console.log("getAppConfig")
|
|
10
|
+
if (typeof process !== 'undefined' && process.env && process.env.APP_CONFIG_PATH) {
|
|
11
|
+
// Node.js environment
|
|
12
|
+
console.log(process.env)
|
|
13
|
+
console.log(process.env.APP_CONFIG_PATH)
|
|
14
|
+
|
|
15
|
+
const configPath = process.env.APP_CONFIG_PATH || path.resolve(__dirname, '../../../sdk.config.json');
|
|
16
|
+
const rawData = fs.readFileSync(configPath, 'utf-8');
|
|
17
|
+
return JSON.parse(rawData) as AppConfig;
|
|
18
|
+
} else {
|
|
19
|
+
try {
|
|
20
|
+
const configPath = path.resolve('../../../sdk.config.json');
|
|
21
|
+
console.log(configPath)
|
|
22
|
+
const rawData = fs.readFileSync(configPath, 'utf-8');
|
|
23
|
+
console.log("TEST")
|
|
24
|
+
console.log(rawData)
|
|
25
|
+
return JSON.parse(rawData) as AppConfig;
|
|
26
|
+
} catch (e:any){
|
|
27
|
+
throw new Error("Configuration not found. Set it via the APP_CONFIG_PATH environment variable : " + e);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Node",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true
|
|
11
|
+
},
|
|
12
|
+
"include": ["src/**/*"],
|
|
13
|
+
"exclude": ["node_modules", "dist"]
|
|
14
|
+
}
|