@phystack/hub-device 4.3.40-dev
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/.prettierignore +10 -0
- package/.prettierrc +10 -0
- package/CHANGELOG.md +1202 -0
- package/README.md +12 -0
- package/dist/index.d.ts +114 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +967 -0
- package/dist/index.js.map +1 -0
- package/dist/storage/browser.d.ts +2 -0
- package/dist/storage/browser.d.ts.map +1 -0
- package/dist/storage/browser.js +20 -0
- package/dist/storage/browser.js.map +1 -0
- package/dist/storage/index.d.ts +6 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +31 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/node.d.ts +2 -0
- package/dist/storage/node.d.ts.map +1 -0
- package/dist/storage/node.js +47 -0
- package/dist/storage/node.js.map +1 -0
- package/dist/sysinfo/browser.d.ts +3 -0
- package/dist/sysinfo/browser.d.ts.map +1 -0
- package/dist/sysinfo/browser.js +194 -0
- package/dist/sysinfo/browser.js.map +1 -0
- package/dist/sysinfo/index.d.ts +3 -0
- package/dist/sysinfo/index.d.ts.map +1 -0
- package/dist/sysinfo/index.js +34 -0
- package/dist/sysinfo/index.js.map +1 -0
- package/dist/sysinfo/node.d.ts +3 -0
- package/dist/sysinfo/node.d.ts.map +1 -0
- package/dist/sysinfo/node.js +53 -0
- package/dist/sysinfo/node.js.map +1 -0
- package/dist/sysinfo/tizen.d.ts +8 -0
- package/dist/sysinfo/tizen.d.ts.map +1 -0
- package/dist/sysinfo/tizen.js +168 -0
- package/dist/sysinfo/tizen.js.map +1 -0
- package/dist/types/command.types.d.ts +8 -0
- package/dist/types/command.types.d.ts.map +1 -0
- package/dist/types/command.types.js +8 -0
- package/dist/types/command.types.js.map +1 -0
- package/dist/types/container.types.d.ts +10 -0
- package/dist/types/container.types.d.ts.map +1 -0
- package/dist/types/container.types.js +3 -0
- package/dist/types/container.types.js.map +1 -0
- package/dist/types/job.types.d.ts +31 -0
- package/dist/types/job.types.d.ts.map +1 -0
- package/dist/types/job.types.js +15 -0
- package/dist/types/job.types.js.map +1 -0
- package/dist/types/twin.types.d.ts +653 -0
- package/dist/types/twin.types.d.ts.map +1 -0
- package/dist/types/twin.types.js +21 -0
- package/dist/types/twin.types.js.map +1 -0
- package/dist/utilities/get-device-identifier.utility.d.ts +2 -0
- package/dist/utilities/get-device-identifier.utility.d.ts.map +1 -0
- package/dist/utilities/get-device-identifier.utility.js +140 -0
- package/dist/utilities/get-device-identifier.utility.js.map +1 -0
- package/dist/utilities/get-hub-credentials.utility.d.ts +8 -0
- package/dist/utilities/get-hub-credentials.utility.d.ts.map +1 -0
- package/dist/utilities/get-hub-credentials.utility.js +47 -0
- package/dist/utilities/get-hub-credentials.utility.js.map +1 -0
- package/dist/utilities/get-provisioning-code.utility.d.ts +3 -0
- package/dist/utilities/get-provisioning-code.utility.d.ts.map +1 -0
- package/dist/utilities/get-provisioning-code.utility.js +49 -0
- package/dist/utilities/get-provisioning-code.utility.js.map +1 -0
- package/package.json +39 -0
- package/src/hub-device.d.ts +0 -0
- package/src/index.ts +1228 -0
- package/src/storage/browser.ts +16 -0
- package/src/storage/index.ts +46 -0
- package/src/storage/node.ts +42 -0
- package/src/sysinfo/browser.ts +217 -0
- package/src/sysinfo/index.ts +29 -0
- package/src/sysinfo/node.ts +387 -0
- package/src/sysinfo/tizen.ts +203 -0
- package/src/types/command.types.ts +8 -0
- package/src/types/container.types.ts +12 -0
- package/src/types/job.types.ts +36 -0
- package/src/types/twin.types.ts +751 -0
- package/src/utilities/get-device-identifier.utility.ts +179 -0
- package/src/utilities/get-hub-credentials.utility.ts +56 -0
- package/src/utilities/get-provisioning-code.utility.ts +55 -0
- package/tsconfig.json +45 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default async function initializeBrowserStorage(): Promise<any> {
|
|
2
|
+
return {
|
|
3
|
+
set: (key: string, value: any) => {
|
|
4
|
+
localStorage.setItem(`phyHub-${key}`, JSON.stringify(value));
|
|
5
|
+
return Promise.resolve();
|
|
6
|
+
},
|
|
7
|
+
get: (key: string) => {
|
|
8
|
+
const value = localStorage.getItem(`phyHub-${key}`);
|
|
9
|
+
return Promise.resolve(value ? JSON.parse(value) : null);
|
|
10
|
+
},
|
|
11
|
+
remove: (key: string) => {
|
|
12
|
+
localStorage.removeItem(key);
|
|
13
|
+
return Promise.resolve();
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
let storage: {
|
|
2
|
+
set: (key: string, value: any) => Promise<void>;
|
|
3
|
+
get: (key: string) => Promise<any>;
|
|
4
|
+
remove: (key: string) => Promise<void>;
|
|
5
|
+
} | null = null;
|
|
6
|
+
|
|
7
|
+
const isNode = typeof window === 'undefined';
|
|
8
|
+
|
|
9
|
+
const logger = console;
|
|
10
|
+
|
|
11
|
+
export default async function getStorage(): Promise<{
|
|
12
|
+
set: (key: string, value: any) => Promise<void>;
|
|
13
|
+
get: (key: string) => Promise<any>;
|
|
14
|
+
remove: (key: string) => Promise<void>;
|
|
15
|
+
}> {
|
|
16
|
+
if (!storage) {
|
|
17
|
+
try {
|
|
18
|
+
if (isNode) {
|
|
19
|
+
logger.info('getStorage(): Initializing Node storage');
|
|
20
|
+
const initializeStorage = require('./node').default;
|
|
21
|
+
storage = await initializeStorage();
|
|
22
|
+
} else {
|
|
23
|
+
logger.info('getStorage(): Initializing Browser storage');
|
|
24
|
+
const initializeStorage = require('./browser').default;
|
|
25
|
+
storage = await initializeStorage();
|
|
26
|
+
}
|
|
27
|
+
} catch (error) {
|
|
28
|
+
logger.error('getStorage(): Error during storage initialization:', error);
|
|
29
|
+
throw new Error('Storage initialization failed');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!storage) {
|
|
34
|
+
throw new Error('Storage initialization failed');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return storage;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Example usage:
|
|
41
|
+
// (async () => {
|
|
42
|
+
// const storage = await getStorage();
|
|
43
|
+
// await storage.set('exampleKey', { example: 'value' });
|
|
44
|
+
// const value = await storage.get('exampleKey');
|
|
45
|
+
// console.log(value);
|
|
46
|
+
// })();
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export default async function initializeNodeStorage(): Promise<any> {
|
|
2
|
+
try {
|
|
3
|
+
console.log('Initializing Node storage');
|
|
4
|
+
const path = await import('path');
|
|
5
|
+
const fs = await import('fs');
|
|
6
|
+
const dirPath = '/data/settings';
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
set: async (key: string, value: any) => {
|
|
10
|
+
const filePath = path.join(dirPath, 'phyhub', `${key}.json`);
|
|
11
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
12
|
+
fs.writeFileSync(filePath, JSON.stringify(value), 'utf-8');
|
|
13
|
+
},
|
|
14
|
+
get: async (key: string) => {
|
|
15
|
+
const filePath = path.join(dirPath, 'phyhub', `${key}.json`);
|
|
16
|
+
try {
|
|
17
|
+
const data = fs.readFileSync(filePath, 'utf-8');
|
|
18
|
+
return JSON.parse(data);
|
|
19
|
+
} catch (error: any) {
|
|
20
|
+
if (error.code === 'ENOENT') {
|
|
21
|
+
// console.error(`[Warning] Storage not initialized for ${key} yet`);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
console.error(`[Error] Error to get ${key} from node storage`, error);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
async remove(key: string): Promise<void> {
|
|
28
|
+
const filePath = path.join(dirPath, 'phyhub', `${key}.json`);
|
|
29
|
+
try {
|
|
30
|
+
fs.unlinkSync(filePath);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
|
|
33
|
+
console.error(`[Error] Failed to remove ${key} from node storage`, error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error('Failed to initialize Node storage:', error);
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import UAParser from 'ua-parser-js';
|
|
2
|
+
|
|
3
|
+
// Extending the Navigator interface to include deviceMemory and connection properties
|
|
4
|
+
interface NavigatorExtended extends Navigator {
|
|
5
|
+
deviceMemory?: number;
|
|
6
|
+
connection?: {
|
|
7
|
+
type?: string;
|
|
8
|
+
effectiveType?: string;
|
|
9
|
+
addEventListener?: (type: string, listener: (event: Event) => void) => void;
|
|
10
|
+
};
|
|
11
|
+
getBattery?: () => Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getBrowserSystemInfo(): any {
|
|
15
|
+
const parser = new UAParser();
|
|
16
|
+
const uaResult = parser.getResult();
|
|
17
|
+
// console.log({ uaResult })
|
|
18
|
+
|
|
19
|
+
function isCanvasSupported(): boolean {
|
|
20
|
+
try {
|
|
21
|
+
let canvas = document.createElement('canvas');
|
|
22
|
+
return !!(canvas.getContext && canvas.getContext('2d'));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isWebGLSupported(): boolean {
|
|
29
|
+
try {
|
|
30
|
+
let canvas = document.createElement('canvas');
|
|
31
|
+
return !!(
|
|
32
|
+
window.WebGLRenderingContext &&
|
|
33
|
+
(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'))
|
|
34
|
+
);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function computeCPUScore(timeFrame: number): number {
|
|
41
|
+
let sysm = 0;
|
|
42
|
+
let start = new Date().getTime();
|
|
43
|
+
let end = start;
|
|
44
|
+
|
|
45
|
+
while (end - start === 0) {
|
|
46
|
+
end = new Date().getTime();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
start = end;
|
|
50
|
+
|
|
51
|
+
while (end - start < timeFrame) {
|
|
52
|
+
sysm++;
|
|
53
|
+
end = new Date().getTime();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return sysm;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const navigatorExtended = navigator as NavigatorExtended;
|
|
60
|
+
|
|
61
|
+
const systemInfo: any = {
|
|
62
|
+
system: {
|
|
63
|
+
manufacturer: uaResult.device.vendor || '',
|
|
64
|
+
model: uaResult.device.model || '',
|
|
65
|
+
version: '',
|
|
66
|
+
serial: '',
|
|
67
|
+
uuid: '',
|
|
68
|
+
sku: '',
|
|
69
|
+
},
|
|
70
|
+
browser: {
|
|
71
|
+
name: uaResult.browser.name || '',
|
|
72
|
+
version: uaResult.browser.version || '',
|
|
73
|
+
major: uaResult.browser.major || '',
|
|
74
|
+
agent: uaResult.ua,
|
|
75
|
+
},
|
|
76
|
+
os: {
|
|
77
|
+
platform: uaResult.device.model || '',
|
|
78
|
+
distro: uaResult.os.name || '',
|
|
79
|
+
release: uaResult.os.version || '',
|
|
80
|
+
codename: '',
|
|
81
|
+
kernel: '',
|
|
82
|
+
arch: uaResult.cpu.architecture || '',
|
|
83
|
+
hostname: '',
|
|
84
|
+
codepage: '',
|
|
85
|
+
logofile: '',
|
|
86
|
+
},
|
|
87
|
+
bios: {
|
|
88
|
+
vendor: '',
|
|
89
|
+
version: '',
|
|
90
|
+
releaseDate: '',
|
|
91
|
+
revision: '',
|
|
92
|
+
},
|
|
93
|
+
baseboard: {
|
|
94
|
+
manufacturer: '',
|
|
95
|
+
model: '',
|
|
96
|
+
version: '',
|
|
97
|
+
serial: '',
|
|
98
|
+
assetTag: '',
|
|
99
|
+
},
|
|
100
|
+
chassis: {
|
|
101
|
+
manufacturer: '',
|
|
102
|
+
model: '',
|
|
103
|
+
version: '',
|
|
104
|
+
serial: '',
|
|
105
|
+
assetTag: '',
|
|
106
|
+
sku: '',
|
|
107
|
+
},
|
|
108
|
+
cpu: {
|
|
109
|
+
manufacturer: '',
|
|
110
|
+
brand: '',
|
|
111
|
+
vendor: '',
|
|
112
|
+
family: '',
|
|
113
|
+
model: '',
|
|
114
|
+
stepping: '',
|
|
115
|
+
revision: '',
|
|
116
|
+
voltage: '',
|
|
117
|
+
speed: '',
|
|
118
|
+
speedmin: '',
|
|
119
|
+
speedmax: '',
|
|
120
|
+
cores: navigator.hardwareConcurrency || '',
|
|
121
|
+
physicalCores: '',
|
|
122
|
+
processors: '',
|
|
123
|
+
socket: '',
|
|
124
|
+
cache: {
|
|
125
|
+
l1d: '',
|
|
126
|
+
l1i: '',
|
|
127
|
+
l2: '',
|
|
128
|
+
l3: '',
|
|
129
|
+
},
|
|
130
|
+
score: computeCPUScore(20),
|
|
131
|
+
},
|
|
132
|
+
memory: {
|
|
133
|
+
total: navigatorExtended.deviceMemory ? navigatorExtended.deviceMemory * 1073741824 : '', // in bytes
|
|
134
|
+
free: '',
|
|
135
|
+
used: '',
|
|
136
|
+
active: '',
|
|
137
|
+
available: '',
|
|
138
|
+
buffers: '',
|
|
139
|
+
cached: '',
|
|
140
|
+
slab: '',
|
|
141
|
+
buffcache: '',
|
|
142
|
+
swaptotal: '',
|
|
143
|
+
swapused: '',
|
|
144
|
+
swapfree: '',
|
|
145
|
+
},
|
|
146
|
+
graphics: {
|
|
147
|
+
controllers: [
|
|
148
|
+
{
|
|
149
|
+
vendor: '',
|
|
150
|
+
model: '',
|
|
151
|
+
bus: '',
|
|
152
|
+
vram: '',
|
|
153
|
+
vramDynamic: '',
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
displays: [
|
|
157
|
+
{
|
|
158
|
+
model: '',
|
|
159
|
+
main: true,
|
|
160
|
+
resolutionx: window.screen.width,
|
|
161
|
+
resolutiony: window.screen.height,
|
|
162
|
+
sizex: window.screen.width, // in pixels
|
|
163
|
+
sizey: window.screen.height, // in pixels
|
|
164
|
+
pixeldepth: window.screen.pixelDepth,
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
features: {
|
|
168
|
+
canvas: isCanvasSupported(),
|
|
169
|
+
webgl: isWebGLSupported(),
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
network: [],
|
|
173
|
+
battery: {
|
|
174
|
+
hasbattery: false,
|
|
175
|
+
cyclecount: '',
|
|
176
|
+
ischarging: '',
|
|
177
|
+
designedcapacity: '',
|
|
178
|
+
maxcapacity: '',
|
|
179
|
+
currentcapacity: '',
|
|
180
|
+
voltage: '',
|
|
181
|
+
capacityUnit: '',
|
|
182
|
+
},
|
|
183
|
+
usb: [],
|
|
184
|
+
audio: [],
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// Determine display orientation
|
|
188
|
+
systemInfo.graphics.orientation =
|
|
189
|
+
systemInfo.graphics.displays[0].resolutionx > systemInfo.graphics.displays[0].resolutiony
|
|
190
|
+
? 'landscape'
|
|
191
|
+
: 'portrait';
|
|
192
|
+
|
|
193
|
+
if (navigatorExtended.getBattery) {
|
|
194
|
+
navigatorExtended.getBattery().then(battery => {
|
|
195
|
+
systemInfo.battery.hasbattery = true;
|
|
196
|
+
systemInfo.battery.ischarging = battery.charging;
|
|
197
|
+
systemInfo.battery.currentcapacity = battery.level * 100; // Convert to percentage
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (navigatorExtended.connection) {
|
|
202
|
+
systemInfo.network.push({
|
|
203
|
+
iface: '',
|
|
204
|
+
ifaceName: '',
|
|
205
|
+
ip4: '',
|
|
206
|
+
ip6: '',
|
|
207
|
+
mac: '',
|
|
208
|
+
internal: false,
|
|
209
|
+
effectiveType: navigatorExtended.connection.effectiveType,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return systemInfo;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Example usage:
|
|
217
|
+
export default getBrowserSystemInfo;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const isNode = typeof window === 'undefined';
|
|
2
|
+
export const isTizen =
|
|
3
|
+
typeof window !== 'undefined' && typeof (window as any).tizen !== 'undefined';
|
|
4
|
+
|
|
5
|
+
const logger = console;
|
|
6
|
+
export default async function getSystemInfo() {
|
|
7
|
+
let info: any = {};
|
|
8
|
+
try {
|
|
9
|
+
if (isNode) {
|
|
10
|
+
logger.info('getSystemInfo(): Initializing Node sysinfo');
|
|
11
|
+
const getInfo = require('./node').default;
|
|
12
|
+
info = await getInfo();
|
|
13
|
+
} else if (isTizen) {
|
|
14
|
+
logger.info('getSystemInfo(): Initializing Tizen sysinfo');
|
|
15
|
+
const getInfo = require('./tizen').default;
|
|
16
|
+
info = await getInfo();
|
|
17
|
+
logger.info(`getSystemInfo(): Fetched Tizen sysinfo`, info);
|
|
18
|
+
} else {
|
|
19
|
+
logger.info('getSystemInfo(): Initializing Browser sysinfo');
|
|
20
|
+
const getInfo = require('./browser').default;
|
|
21
|
+
info = await getInfo();
|
|
22
|
+
}
|
|
23
|
+
} catch (error) {
|
|
24
|
+
logger.error('getSystemInfo(): Error during sysinfo initialization:', error);
|
|
25
|
+
throw new Error('System information initialization failed');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return info;
|
|
29
|
+
}
|