@kmlckj/licos-platform-sdk 0.10.0 → 0.10.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 +95 -85
- package/dist/enterprise-knowledge.js +1 -0
- package/dist/index.d.ts +318 -12
- package/dist/index.js +1 -1
- package/dist/industrial.d.ts +158 -119
- package/dist/industrial.js +1 -1
- package/dist/runtime.js +1 -1
- package/dist/uns.d.ts +162 -166
- package/dist/uns.js +1 -1
- package/package.json +7 -7
package/dist/uns.d.ts
CHANGED
|
@@ -1,166 +1,162 @@
|
|
|
1
|
-
export type UnsObject = Record<string, unknown>;
|
|
2
|
-
|
|
3
|
-
export interface
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export function
|
|
42
|
-
export function
|
|
43
|
-
|
|
44
|
-
export function
|
|
45
|
-
export function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
export function
|
|
50
|
-
export function
|
|
51
|
-
export function
|
|
52
|
-
export function
|
|
53
|
-
export function
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
): Promise<
|
|
63
|
-
export function
|
|
64
|
-
export function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
export
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
export function
|
|
85
|
-
export function
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
export function
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
export function
|
|
104
|
-
export function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
controlVideo: typeof controlUnsVideo;
|
|
164
|
-
controlPathVideo: typeof controlUnsPathVideo;
|
|
165
|
-
openPath: typeof openUnsPath;
|
|
166
|
-
};
|
|
1
|
+
export type UnsObject = Record<string, unknown>;
|
|
2
|
+
|
|
3
|
+
export interface UnsProvisioningJob extends UnsObject {
|
|
4
|
+
jobId: string;
|
|
5
|
+
status: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface UnsPageOptions {
|
|
9
|
+
page?: number;
|
|
10
|
+
pageSize?: number;
|
|
11
|
+
page_size?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getUnsProvisioningSchema(): Promise<UnsObject>;
|
|
15
|
+
export function getUnsProvisioningCapabilities(): Promise<UnsObject>;
|
|
16
|
+
export function validateUnsProvisioning(document: UnsObject): Promise<UnsObject>;
|
|
17
|
+
export function planUnsProvisioning(document: UnsObject): Promise<UnsObject>;
|
|
18
|
+
export function submitUnsProvisioning(
|
|
19
|
+
document: UnsObject,
|
|
20
|
+
options?: { idempotencyKey?: string; idempotency_key?: string },
|
|
21
|
+
): Promise<UnsObject>;
|
|
22
|
+
export function getUnsProvisioningJob(jobId: string): Promise<UnsProvisioningJob>;
|
|
23
|
+
export function getUnsProvisioningOperations(jobId: string): Promise<UnsObject>;
|
|
24
|
+
export function waitForUnsProvisioningJob(
|
|
25
|
+
jobId: string,
|
|
26
|
+
options?: {
|
|
27
|
+
timeoutMs?: number;
|
|
28
|
+
timeout_ms?: number;
|
|
29
|
+
pollIntervalMs?: number;
|
|
30
|
+
poll_interval_ms?: number;
|
|
31
|
+
},
|
|
32
|
+
): Promise<UnsProvisioningJob>;
|
|
33
|
+
|
|
34
|
+
export function listUnsNodes(): Promise<UnsObject[]>;
|
|
35
|
+
export function createUnsNode(node: UnsObject): Promise<UnsObject>;
|
|
36
|
+
export function batchCreateUnsNodes(nodes: UnsObject[]): Promise<UnsObject[]>;
|
|
37
|
+
export function copyUnsNode(
|
|
38
|
+
nodeId: string,
|
|
39
|
+
options?: { parentId?: string | null; parent_id?: string | null },
|
|
40
|
+
): Promise<UnsObject>;
|
|
41
|
+
export function updateUnsNode(nodeId: string, node: UnsObject): Promise<UnsObject>;
|
|
42
|
+
export function deleteUnsNode(nodeId: string): Promise<void>;
|
|
43
|
+
|
|
44
|
+
export function listUnsTemplates(): Promise<UnsObject[]>;
|
|
45
|
+
export function createUnsTemplate(template: UnsObject): Promise<UnsObject>;
|
|
46
|
+
export function updateUnsTemplate(templateId: string, template: UnsObject): Promise<UnsObject>;
|
|
47
|
+
export function deleteUnsTemplate(templateId: string): Promise<void>;
|
|
48
|
+
|
|
49
|
+
export function listUnsLabels(): Promise<UnsObject[]>;
|
|
50
|
+
export function createUnsLabel(label: UnsObject): Promise<UnsObject>;
|
|
51
|
+
export function updateUnsLabel(labelId: string, label: UnsObject): Promise<UnsObject>;
|
|
52
|
+
export function replaceUnsLabelNodes(labelId: string, nodeIds: string[]): Promise<UnsObject>;
|
|
53
|
+
export function deleteUnsLabel(labelId: string): Promise<void>;
|
|
54
|
+
|
|
55
|
+
export function getUnsNodeSchema(
|
|
56
|
+
schemaType: 'folder' | 'file' | 'template' | 'label' | string,
|
|
57
|
+
): Promise<string>;
|
|
58
|
+
export function inferUnsDefinition(
|
|
59
|
+
sample: string | UnsObject | unknown[],
|
|
60
|
+
): Promise<UnsObject[]>;
|
|
61
|
+
export function listUnsReverseDatasources(): Promise<Record<string, string>[]>;
|
|
62
|
+
export function listUnsReverseSchemas(): Promise<string[]>;
|
|
63
|
+
export function listUnsReverseTables(schema: string): Promise<string[]>;
|
|
64
|
+
export function listUnsReverseFields(
|
|
65
|
+
schema: string,
|
|
66
|
+
table: string,
|
|
67
|
+
): Promise<UnsObject[]>;
|
|
68
|
+
|
|
69
|
+
export interface UnsAttachmentUpload {
|
|
70
|
+
/** File name persisted by the platform. */
|
|
71
|
+
name: string;
|
|
72
|
+
/** File bytes. Browser File and Blob values are supported through Blob. */
|
|
73
|
+
data: Blob | Uint8Array | ArrayBuffer;
|
|
74
|
+
/** MIME type used when data is not already a Blob. */
|
|
75
|
+
contentType?: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface UnsAttachmentDownload {
|
|
79
|
+
data: Uint8Array;
|
|
80
|
+
contentType: string | null;
|
|
81
|
+
contentDisposition: string | null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function listUnsAttachments(nodeId: string): Promise<UnsObject[]>;
|
|
85
|
+
export function uploadUnsAttachments(
|
|
86
|
+
nodeId: string,
|
|
87
|
+
files: UnsAttachmentUpload[],
|
|
88
|
+
): Promise<UnsObject[]>;
|
|
89
|
+
export function downloadUnsAttachment(
|
|
90
|
+
nodeId: string,
|
|
91
|
+
attachmentId: string,
|
|
92
|
+
): Promise<UnsAttachmentDownload>;
|
|
93
|
+
export function deleteUnsAttachment(nodeId: string, attachmentId: string): Promise<void>;
|
|
94
|
+
|
|
95
|
+
export function getUnsNodeLatest(nodeId: string): Promise<UnsObject>;
|
|
96
|
+
export function getUnsNodeHistory(nodeId: string, options?: { limit?: number }): Promise<UnsObject[]>;
|
|
97
|
+
export function getUnsRealtimeConnection(): Promise<{
|
|
98
|
+
ticket: string;
|
|
99
|
+
expiresInSeconds: number;
|
|
100
|
+
url: string;
|
|
101
|
+
}>;
|
|
102
|
+
|
|
103
|
+
export function listUnsIotCollectors(sourceType: string, options?: UnsPageOptions): Promise<unknown>;
|
|
104
|
+
export function listUnsIotPoints(
|
|
105
|
+
sourceType: string,
|
|
106
|
+
taskId: string,
|
|
107
|
+
options?: UnsPageOptions,
|
|
108
|
+
): Promise<unknown>;
|
|
109
|
+
export function getUnsIotLatest(
|
|
110
|
+
taskId: string,
|
|
111
|
+
pointId: string,
|
|
112
|
+
options?: {
|
|
113
|
+
tagCode?: string;
|
|
114
|
+
tag_code?: string;
|
|
115
|
+
nodeId?: string;
|
|
116
|
+
node_id?: string;
|
|
117
|
+
},
|
|
118
|
+
): Promise<unknown>;
|
|
119
|
+
export function getUnsIotVideoStreamOptions(channelId: string): Promise<unknown>;
|
|
120
|
+
|
|
121
|
+
export const uns: {
|
|
122
|
+
provisioningSchema: typeof getUnsProvisioningSchema;
|
|
123
|
+
provisioningCapabilities: typeof getUnsProvisioningCapabilities;
|
|
124
|
+
validate: typeof validateUnsProvisioning;
|
|
125
|
+
plan: typeof planUnsProvisioning;
|
|
126
|
+
submit: typeof submitUnsProvisioning;
|
|
127
|
+
job: typeof getUnsProvisioningJob;
|
|
128
|
+
operations: typeof getUnsProvisioningOperations;
|
|
129
|
+
waitJob: typeof waitForUnsProvisioningJob;
|
|
130
|
+
listNodes: typeof listUnsNodes;
|
|
131
|
+
createNode: typeof createUnsNode;
|
|
132
|
+
batchCreateNodes: typeof batchCreateUnsNodes;
|
|
133
|
+
copyNode: typeof copyUnsNode;
|
|
134
|
+
updateNode: typeof updateUnsNode;
|
|
135
|
+
deleteNode: typeof deleteUnsNode;
|
|
136
|
+
listTemplates: typeof listUnsTemplates;
|
|
137
|
+
createTemplate: typeof createUnsTemplate;
|
|
138
|
+
updateTemplate: typeof updateUnsTemplate;
|
|
139
|
+
deleteTemplate: typeof deleteUnsTemplate;
|
|
140
|
+
listLabels: typeof listUnsLabels;
|
|
141
|
+
createLabel: typeof createUnsLabel;
|
|
142
|
+
updateLabel: typeof updateUnsLabel;
|
|
143
|
+
replaceLabelNodes: typeof replaceUnsLabelNodes;
|
|
144
|
+
deleteLabel: typeof deleteUnsLabel;
|
|
145
|
+
nodeSchema: typeof getUnsNodeSchema;
|
|
146
|
+
inferDefinition: typeof inferUnsDefinition;
|
|
147
|
+
listReverseDatasources: typeof listUnsReverseDatasources;
|
|
148
|
+
listReverseSchemas: typeof listUnsReverseSchemas;
|
|
149
|
+
listReverseTables: typeof listUnsReverseTables;
|
|
150
|
+
listReverseFields: typeof listUnsReverseFields;
|
|
151
|
+
listAttachments: typeof listUnsAttachments;
|
|
152
|
+
uploadAttachments: typeof uploadUnsAttachments;
|
|
153
|
+
downloadAttachment: typeof downloadUnsAttachment;
|
|
154
|
+
deleteAttachment: typeof deleteUnsAttachment;
|
|
155
|
+
nodeLatest: typeof getUnsNodeLatest;
|
|
156
|
+
nodeHistory: typeof getUnsNodeHistory;
|
|
157
|
+
realtimeConnection: typeof getUnsRealtimeConnection;
|
|
158
|
+
listCollectors: typeof listUnsIotCollectors;
|
|
159
|
+
listPoints: typeof listUnsIotPoints;
|
|
160
|
+
sourceLatest: typeof getUnsIotLatest;
|
|
161
|
+
videoStreamOptions: typeof getUnsIotVideoStreamOptions;
|
|
162
|
+
};
|
package/dist/uns.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ApiError as e}from"./shared.js";import{authHeaders as t,refreshRuntimeConfig as n,runtimeConfig as o,shouldRefreshUserToken as r}from"./runtime.js";import{WebSocket as a,WebSocketServer as i}from"ws";function s(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>null!=e))}function c(e,t){return`/projects/${encodeURIComponent(e.projectId)}${t}`}function p(e,t,n,o){return c(e,`/uns/runtime/${t}/${encodeURIComponent(n)}/${o}`)}function u(e,t,n){const o=String(n||"").trim();if(!o)throw new TypeError("UNS path cannot be empty");return`${c(e,`/uns/runtime/path/${t}`)}?${new URLSearchParams({path:o})}`}function d(e,t){return new URL(`${e.baseUrl}/api/v1${t}`)}async function l(t){const n=await t.text();let o=null;try{o=n?JSON.parse(n):null}catch{throw new e(n||`platform UNS API returned ${t.status}`,{status:t.status,details:n})}if(!t.ok)throw new e(o?.message||n||`platform UNS API returned ${t.status}`,{status:t.status,code:"number"==typeof o?.code?o.code:void 0,details:o});if(!o||"object"!=typeof o)return o;if(void 0!==o.code&&0!==o.code||!1===o.success)throw new e(o.message||"platform UNS API failed",{status:t.status,code:"number"==typeof o.code?o.code:void 0,details:o});return o.data}async function h(a,i,{body:c,config:p}={}){let u=p||await o();for(let e=0;e<2;e+=1)try{const e="function"==typeof i?i(u):i,n=await fetch(d(u,e),{method:a,headers:t(u,void 0===c?void 0:"application/json"),body:void 0===c?void 0:JSON.stringify(s(c))});return await l(n)}catch(t){if(0===e&&r(t)){u=await n(u);continue}throw t}throw new e("platform UNS API failed")}export function getCurrentUnsSchema(){return h("GET","/uns/schemas/current")}export function getUnsSchema(e="1.0"){return h("GET",`/uns/schemas/${encodeURIComponent(e)}`)}export function listUnsSchemaBlocks(e="1.0"){return h("GET",`/uns/schemas/${encodeURIComponent(e)}/blocks`)}export function getUnsSchemaBlock(e,{version:t="1.0",depth:n=1}={}){return h("GET",`/uns/schemas/${encodeURIComponent(t)}/blocks/${encodeURIComponent(e)}?depth=${encodeURIComponent(n)}`)}export function getUnsProtocolSchema(e,{version:t="1.0"}={}){return h("GET",`/uns/schemas/${encodeURIComponent(t)}/blocks/collection-point/protocols/${encodeURIComponent(e)}`)}export async function discoverUnsResources({resourceTypes:e=[],protocols:t=[]}={}){const n=await o();return h("POST",c(n,"/uns/discover"),{body:{resourceTypes:e,protocols:t},config:n})}export async function searchUnsResources(e,t={}){const n=await o();return h("POST",c(n,"/uns/resources/search"),{body:{resourceType:e,protocol:t.protocol,keyword:t.keyword,selector:t.selector||{},page:t.page??1,pageSize:t.pageSize??t.page_size??20},config:n})}export async function listUnsBindings(){const e=await o();return h("GET",c(e,"/uns/bindings"),{config:e})}export async function resolveUnsPath(e){const t=await o();return h("GET",u(t,"resolve",e),{config:t})}export async function validateUnsDocument(e){const t=await o();return h("POST",c(t,"/uns/validate"),{body:{document:e},config:t})}export async function planUnsDocument(e){const t=await o();return h("POST",c(t,"/uns/plan"),{body:{document:e},config:t})}export async function applyUnsDocument(e,t={}){const n=String(t.expectedDocumentHash??t.expected_document_hash??"").trim(),r=String(t.expectedPlanHash??t.expected_plan_hash??"").trim();if(!0!==t.confirmed)throw new TypeError("UNS apply requires explicit confirmation");if(!n||!r)throw new TypeError("UNS apply requires document and plan hashes");const a=await o();return h("POST",c(a,"/uns/apply"),{body:{document:e,expectedDocumentHash:n,expectedPlanHash:r,confirmed:!0},config:a})}export async function validateUnsChanges(e){const t=await o();return h("POST",c(t,"/uns/changes/validate"),{body:{document:e},config:t})}export async function planUnsChanges(e){const t=await o();return h("POST",c(t,"/uns/changes/plan"),{body:{document:e},config:t})}export async function applyUnsChanges(e,t={}){const n=String(t.expectedDocumentHash??t.expected_document_hash??"").trim(),r=String(t.expectedPlanHash??t.expected_plan_hash??"").trim();if(!0!==t.confirmed)throw new TypeError("UNS changes apply requires explicit confirmation");if(!n||!r)throw new TypeError("UNS changes apply requires document and plan hashes");const a=await o();return h("POST",c(a,"/uns/changes/apply"),{body:{document:e,expectedDocumentHash:n,expectedPlanHash:r,confirmed:!0,impactConfirmed:!0===t.impactConfirmed||!0===t.impact_confirmed},config:a})}function f(e={}){return s({pageNum:e.pageNum??e.page_num??1,pageSize:e.pageSize??e.page_size??50,paginationMode:e.paginationMode??e.pagination_mode??"OFFSET",pageToken:e.pageToken??e.page_token})}export async function queryUnsNodeData(e,t={}){const n=await o();return h("POST",p(n,"nodes",e,"query"),{body:f(t),config:n})}function m(e,t){if(!0!==t)throw new TypeError("UNS data write requires explicit confirmation");if(!e||"object"!=typeof e||0===Object.keys(e).length)throw new TypeError("UNS data write field values cannot be empty")}export async function writeUnsNodeData(e,t,{confirmed:n=!1}={}){m(t,n);const r=await o();return h("POST",p(r,"nodes",e,"write"),{body:{fieldValues:t,environment:r.environment,confirmed:!0},config:r})}function y(e,t){if(!0!==t)throw new TypeError("UNS data deletion requires explicit confirmation");if(!Array.isArray(e)||0===e.length||e.some(e=>!e||"object"!=typeof e||Array.isArray(e)||0===Object.keys(e).length))throw new TypeError("UNS data deletion rows cannot be empty")}export async function deleteUnsNodeData(e,t,{confirmed:n=!1}={}){y(t,n);const r=await o();return h("POST",p(r,"nodes",e,"delete"),{body:{rows:t,confirmed:!0},config:r})}export async function queryUnsPathData(e,t={}){const n=await o();return h("POST",u(n,"data/query",e),{body:f(t),config:n})}export async function writeUnsPathData(e,t,{confirmed:n=!1}={}){m(t,n);const r=await o();return h("POST",u(r,"data/write",e),{body:{fieldValues:t,environment:r.environment,confirmed:!0},config:r})}export async function deleteUnsPathData(e,t,{confirmed:n=!1}={}){y(t,n);const r=await o();return h("POST",u(r,"data/delete",e),{body:{rows:t,confirmed:!0},config:r})}export async function getUnsPointCurrent(e){const t=await o();return h("GET",p(t,"points",e,"current"),{config:t})}export async function getUnsPathPointCurrent(e){const t=await o();return h("GET",u(t,"point/current",e),{config:t})}export async function getUnsPointRealtimeConfig(e){const t=await o();return h("GET",p(t,"points",e,"realtime-config"),{config:t})}export async function getUnsPathPointRealtimeConfig(e){const t=await o();return h("GET",u(t,"point/realtime-config",e),{config:t})}function g(e,t){if(null==e)return[];if(!Array.isArray(e))throw new TypeError(`${t} must be an array`);return e.map(String).map(e=>e.trim()).filter(Boolean)}function w(e,t){const n="string"==typeof e?e.trim():"";if(!n)throw new TypeError(`UNS point realtime config is missing ${t}`);return n}function U(e,t){return"string"==typeof e&&e.trim()?e.trim():t}function P(e){return"code"===e.kind?{code:e.value}:{path:e.value}}function S(e,t){e.readyState===a.OPEN&&e.send(JSON.stringify(t))}export function attachUnsPointRealtimeRelay(e={}){const t=e.server;if(!t||"function"!=typeof t.on||"function"!=typeof t.removeListener)throw new TypeError("UNS point realtime relay requires a Node HTTP server");const n=function(e){const t=String(e||"").trim();if(!t.startsWith("/")||t.includes("?")||t.includes("#"))throw new TypeError("UNS point realtime relay path must be an absolute path without query or hash");return t}(e.path),o=function(e){const t=g(e.codes??e.nodeCodes??e.node_codes,"codes"),n=g(e.paths,"paths"),o=[...t.map(e=>({kind:"code",value:e})),...n.map(e=>({kind:"path",value:e}))],r=new Map(o.map(e=>[`${e.kind}:${e.value}`,e]));if(0===r.size)throw new TypeError("UNS point realtime relay requires at least one code or path");return[...r.values()]}(e),r=new i({noServer:!0});let c=!1;const p=o.map(e=>({target:e,socket:null,reconnectTimer:null,reconnectAttempt:0,status:"connecting",statusMessage:void 0,lastMessage:null,messageFingerprints:new Set})),u=e=>s({type:"uns.point.status",target:P(e.target),status:e.status,message:e.statusMessage}),d=e=>{for(const t of r.clients)S(t,e)},l=(e,t,n)=>{e.status=t,e.statusMessage=n,d(u(e))},h=async e=>{if(c)return;let t,n;l(e,"connecting");try{const n="code"===e.target.kind?await getUnsPointRealtimeConfig(e.target.value):await getUnsPathPointRealtimeConfig(e.target.value);t=function(e){if(!e||"object"!=typeof e||Array.isArray(e))throw new TypeError("UNS point realtime config must be an object");const t=e.registration&&"object"==typeof e.registration&&!Array.isArray(e.registration)?e.registration:{},n=w(e.nodeCode,"nodeCode"),o=new URL(w(e.websocketUrl,"websocketUrl"));if("ws:"!==o.protocol&&"wss:"!==o.protocol)throw new TypeError("UNS point realtime websocketUrl must use ws or wss");const r=U(t.queryParameter,"clientKey");return o.searchParams.set(r,n),{nodeCode:n,websocketUrl:o.toString(),queryParameter:r,connectedType:U(t.connectedType,"CONNECTED"),registerType:U(t.registerType,"REGISTER"),registeredType:U(t.registeredType,"REGISTERED"),messageType:U(t.messageType,"UNS_POINT_MESSAGE"),pingType:U(t.pingType,"PING"),pongType:U(t.pongType,"PONG")}}(n)}catch{return void l(e,"error","无法获取 UNS 点位实时连接配置")}if(c)return;try{n=new a(t.websocketUrl)}catch{return void l(e,"error","无法建立数据工厂实时连接")}e.socket=n;let o=!1,r=!1;n.on("open",()=>{c||e.socket!==n||l(e,"connected")}),n.on("message",(i,s)=>{if(c||e.socket!==n)return;const p=function(e,t){if(t)return null;try{const t=JSON.parse(e.toString());return t&&"object"==typeof t&&!Array.isArray(t)?t:null}catch{return null}}(i,s);if(!p)return;const u="string"==typeof p.type?p.type:"";if(u===t.pingType)return void(n.readyState===a.OPEN&&n.send(JSON.stringify({type:t.pongType})));if(u===t.connectedType&&!o&&!r)return r=!0,void n.send(JSON.stringify({type:t.registerType,[t.queryParameter]:t.nodeCode}));if(u===t.registeredType)return o=!0,e.reconnectAttempt=0,void l(e,"registered");if(u!==t.messageType||!o)return;if(void 0!==p.nodeCode&&String(p.nodeCode)!==t.nodeCode)return void l(e,"error","数据工厂返回了不匹配的 UNS 点位消息");if(!function(e,t){const n=function(e){try{return JSON.stringify([e.nodeCode,e.topicName,e.receivedAt,e.status,e.message])}catch{return null}}(t);return!n||!e.messageFingerprints.has(n)&&(e.messageFingerprints.add(n),e.messageFingerprints.size>256&&e.messageFingerprints.delete(e.messageFingerprints.values().next().value),!0)}(e,p))return;const h={type:"uns.point.message",target:P(e.target),payload:p};e.lastMessage=h,d(h)}),n.on("error",()=>{c||e.socket!==n||l(e,"error","数据工厂实时连接失败")}),n.on("close",t=>{e.socket===n&&(e.socket=null,o=!1,c||(1e3!==t&&1001!==t?((e,t)=>{if(c||e.reconnectTimer)return;e.reconnectAttempt+=1;const n=Math.min(3e4,500*2**Math.min(e.reconnectAttempt-1,6)),o=Math.round(n*(.75+.5*Math.random()));l(e,"reconnecting","数据工厂实时连接已断开,正在重连"),e.reconnectTimer=setTimeout(()=>{e.reconnectTimer=null,t(e)},o)})(e,h):l(e,"disconnected")))})};r.on("connection",e=>{for(const t of p)S(e,u(t)),t.lastMessage&&S(e,t.lastMessage)});const f=(e,t,o)=>{let a;try{a=new URL(e.url||"/",`http://${e.headers.host||"localhost"}`).pathname}catch{return}a===n&&r.handleUpgrade(e,t,o,t=>{r.emit("connection",t,e)})};t.on("upgrade",f);for(const e of p)h(e);return()=>{if(!c){c=!0,t.removeListener("upgrade",f);for(const e of p)e.reconnectTimer&&clearTimeout(e.reconnectTimer),!e.socket||e.socket.readyState!==a.OPEN&&e.socket.readyState!==a.CONNECTING||e.socket.close(1001,"relay closed"),e.socket=null;for(const e of r.clients)e.close(1001,"relay closed");r.close()}}}function T(e={}){return{startTime:e.startTime??e.start_time,endTime:e.endTime??e.end_time,page:e.page??1,pageSize:e.pageSize??e.page_size??100}}export async function getUnsPointHistory(e,t){const n=await o();return h("POST",p(n,"points",e,"history"),{body:T(t),config:n})}export async function getUnsPathPointHistory(e,t){const n=await o();return h("POST",u(n,"point/history",e),{body:T(t),config:n})}function v(e,t={}){const n=String(t.reason||"").trim(),o=String(t.ticket||"").trim(),r=t.dryRun??t.dry_run??!1,a=t.confirmed??!1;if(!r&&!0!==a)throw new TypeError("UNS point write requires explicit confirmation");if(!n||!o)throw new TypeError("UNS point write requires reason and ticket");return s({value:e,reason:n,ticket:o,requestId:t.requestId??t.request_id,dryRun:r,confirmed:a})}export async function writeUnsPoint(e,t,n={}){const r=v(t,n),a=await o();return h("POST",p(a,"points",e,"write"),{body:r,config:a})}export async function writeUnsPathPoint(e,t,n={}){const r=v(t,n),a=await o();return h("POST",u(a,"point/write",e),{body:r,config:a})}export async function getUnsVideoStreamOptions(e){const t=await o();return h("GET",p(t,"videos",e,"stream-options"),{config:t})}export async function getUnsPathVideoStreamOptions(e){const t=await o();return h("GET",u(t,"video/stream-options",e),{config:t})}export async function createUnsVideoSnapshot(e){const t=await o();return h("POST",p(t,"videos",e,"snapshot"),{config:t})}export async function createUnsPathVideoSnapshot(e){const t=await o();return h("POST",u(t,"video/snapshot",e),{config:t})}function x(e,t={}){if(!0!==t.confirmed)throw new TypeError("UNS video control requires explicit confirmation");return{action:e,parameters:t.parameters||{},confirmed:!0}}export async function controlUnsVideo(e,t,n={}){const r=x(t,n),a=await o();return h("POST",p(a,"videos",e,"control"),{body:r,config:a})}export async function controlUnsPathVideo(e,t,n={}){const r=x(t,n),a=await o();return h("POST",u(a,"video/control",e),{body:r,config:a})}export class UnsPathNode{constructor(e){if(this.path=String(e||"").trim(),!this.path)throw new TypeError("UNS path cannot be empty")}resolve(){return resolveUnsPath(this.path)}queryData(e){return queryUnsPathData(this.path,e)}writeData(e,t){return writeUnsPathData(this.path,e,t)}deleteData(e,t){return deleteUnsPathData(this.path,e,t)}pointCurrent(){return getUnsPathPointCurrent(this.path)}pointRealtimeConfig(){return getUnsPathPointRealtimeConfig(this.path)}pointHistory(e){return getUnsPathPointHistory(this.path,e)}writePoint(e,t){return writeUnsPathPoint(this.path,e,t)}videoStreamOptions(){return getUnsPathVideoStreamOptions(this.path)}videoSnapshot(){return createUnsPathVideoSnapshot(this.path)}controlVideo(e,t){return controlUnsPathVideo(this.path,e,t)}}export function openUnsPath(e){return new UnsPathNode(e)}export const uns={schemaCurrent:getCurrentUnsSchema,schema:getUnsSchema,schemaBlocks:listUnsSchemaBlocks,schemaBlock:getUnsSchemaBlock,protocolSchema:getUnsProtocolSchema,discover:discoverUnsResources,searchResources:searchUnsResources,bindings:listUnsBindings,resolvePath:resolveUnsPath,validate:validateUnsDocument,plan:planUnsDocument,apply:applyUnsDocument,validateChanges:validateUnsChanges,planChanges:planUnsChanges,applyChanges:applyUnsChanges,queryNodeData:queryUnsNodeData,writeNodeData:writeUnsNodeData,deleteNodeData:deleteUnsNodeData,queryPathData:queryUnsPathData,writePathData:writeUnsPathData,deletePathData:deleteUnsPathData,pointCurrent:getUnsPointCurrent,pathPointCurrent:getUnsPathPointCurrent,pointRealtimeConfig:getUnsPointRealtimeConfig,pathPointRealtimeConfig:getUnsPathPointRealtimeConfig,attachPointRealtimeRelay:attachUnsPointRealtimeRelay,pointHistory:getUnsPointHistory,pathPointHistory:getUnsPathPointHistory,writePoint:writeUnsPoint,writePathPoint:writeUnsPathPoint,videoStreamOptions:getUnsVideoStreamOptions,pathVideoStreamOptions:getUnsPathVideoStreamOptions,videoSnapshot:createUnsVideoSnapshot,pathVideoSnapshot:createUnsPathVideoSnapshot,controlVideo:controlUnsVideo,controlPathVideo:controlUnsPathVideo,openPath:openUnsPath};
|
|
1
|
+
import{ApiError as e}from"./shared.js";import{authHeaders as t,refreshRuntimeConfig as n,runtimeConfig as o,shouldRefreshUserToken as s}from"./runtime.js";const r="/api/v1/uns-modeling",a=`${r}/provisioning`,i=new Set(["INVALID","SUCCEEDED","FAILED","ROLLED_BACK","PARTIALLY_ROLLED_BACK"]);async function c(r,a,{body:i,query:c,config:l,headers:d}={}){let p=l||await o({requireProject:!1});for(let o=0;o<2;o+=1)try{const n=new URL(`${p.baseUrl}${a}`);for(const[e,t]of Object.entries(c||{}))null!=t&&n.searchParams.set(e,String(t));const o="undefined"!=typeof FormData&&i instanceof FormData,s=await fetch(n,{method:r,headers:{...t(p,void 0===i||o?null:"application/json"),...d||{}},body:void 0===i?void 0:o?i:JSON.stringify(i)}),l=await s.text();let u=null;try{u=l?JSON.parse(l):null}catch{throw new e(l||`platform UNS API returned ${s.status}`,{status:s.status,details:l})}if(!s.ok||void 0!==u?.code&&0!==u.code||!1===u?.success)throw new e(u?.message||l||"platform UNS API failed",{status:s.status,code:"number"==typeof u?.code?u.code:void 0,details:u});return u&&"object"==typeof u?u.data:u}catch(e){if(0===o&&s(e)){p=await n(p);continue}throw e}throw new e("platform UNS API failed")}function l(e,t,n=""){const o=encodeURIComponent(String(t));return`${r}/${e}/${o}${n}`}function d(e){return new Promise(t=>setTimeout(t,e))}export function getUnsProvisioningSchema(){return c("GET",`${a}/json-schema`)}export function getUnsProvisioningCapabilities(){return c("GET",`${a}/capabilities`)}export function validateUnsProvisioning(e){return c("POST",`${a}/validate`,{body:e})}export function planUnsProvisioning(e){return c("POST",`${a}/plan`,{body:e})}export function submitUnsProvisioning(e,t={}){const n=t.idempotencyKey??t.idempotency_key;return c("POST",`${a}/jobs`,{body:e,headers:n?{"Idempotency-Key":n}:void 0})}export function getUnsProvisioningJob(e){return c("GET",`${a}/jobs/${encodeURIComponent(e)}`)}export function getUnsProvisioningOperations(e){return c("GET",`${a}/jobs/${encodeURIComponent(e)}/operations`)}export async function waitForUnsProvisioningJob(e,t={}){const n=t.timeoutMs??t.timeout_ms??6e5,o=t.pollIntervalMs??t.poll_interval_ms??1500;if(!(n>0))throw new TypeError("timeoutMs must be greater than zero");if(!(o>0))throw new TypeError("pollIntervalMs must be greater than zero");const s=Date.now()+n;for(;;){const t=await getUnsProvisioningJob(e);if(i.has(String(t?.status||"").toUpperCase()))return t;const n=s-Date.now();if(n<=0)throw new Error(`UNS provisioning job ${e} did not finish in time`);await d(Math.min(o,n))}}export function listUnsNodes(){return c("GET",`${r}/nodes`)}export function createUnsNode(e){return c("POST",`${r}/nodes`,{body:e})}export function batchCreateUnsNodes(e){return c("POST",`${r}/nodes/batch`,{body:{nodes:e}})}export function copyUnsNode(e,t={}){return c("POST",l("nodes",e,"/copy"),{body:{parentId:t.parentId??t.parent_id??null}})}export function updateUnsNode(e,t){return c("PUT",l("nodes",e),{body:t})}export async function deleteUnsNode(e){await c("DELETE",l("nodes",e))}export function listUnsTemplates(){return c("GET",`${r}/templates`)}export function createUnsTemplate(e){return c("POST",`${r}/templates`,{body:e})}export function updateUnsTemplate(e,t){return c("PUT",l("templates",e),{body:t})}export async function deleteUnsTemplate(e){await c("DELETE",l("templates",e))}export function listUnsLabels(){return c("GET",`${r}/labels`)}export function createUnsLabel(e){return c("POST",`${r}/labels`,{body:e})}export function updateUnsLabel(e,t){return c("PUT",l("labels",e),{body:t})}export function replaceUnsLabelNodes(e,t){return c("PUT",l("labels",e,"/nodes"),{body:{nodeIds:t}})}export async function deleteUnsLabel(e){await c("DELETE",l("labels",e))}export function getUnsNodeSchema(e){return c("GET",`${r}/schemas/${encodeURIComponent(e)}`)}export function inferUnsDefinition(e){return c("POST",`${r}/definitions/infer-json`,{body:{sample:"string"==typeof e?e:JSON.stringify(e)}})}export function listUnsReverseDatasources(){return c("GET",`${r}/reverse/datasources`)}export function listUnsReverseSchemas(){return c("GET",`${r}/reverse/schemas`)}export function listUnsReverseTables(e){return c("GET",`${r}/reverse/tables`,{query:{schema:e}})}export function listUnsReverseFields(e,t){return c("GET",`${r}/reverse/fields`,{query:{schema:e,table:t}})}export function listUnsAttachments(e){return c("GET",l("nodes",e,"/attachments"))}function p(e){if(e.data instanceof Blob)return e.data;if(e.data instanceof Uint8Array)return new Blob([e.data],{type:e.contentType||"application/octet-stream"});if(e.data instanceof ArrayBuffer)return new Blob([new Uint8Array(e.data)],{type:e.contentType||"application/octet-stream"});throw new TypeError("UNS attachment data must be Blob, Uint8Array, or ArrayBuffer")}export function uploadUnsAttachments(e,t){if(!Array.isArray(t)||0===t.length)throw new TypeError("files must contain at least one attachment");const n=new FormData;for(const e of t){if(!e||"string"!=typeof e.name||!e.name.trim())throw new TypeError("each UNS attachment requires a non-empty name");n.append("files",p(e),e.name)}return c("POST",l("nodes",e,"/attachments"),{body:n})}export async function downloadUnsAttachment(r,a){let i=await o({requireProject:!1});const c=l("nodes",r,`/attachments/${encodeURIComponent(a)}`);for(let o=0;o<2;o+=1){const r=await fetch(new URL(`${i.baseUrl}${c}`),{method:"GET",headers:t(i,null)});if(r.ok)return{data:new Uint8Array(await r.arrayBuffer()),contentType:r.headers.get("content-type"),contentDisposition:r.headers.get("content-disposition")};const a=await r.text();let l=a;try{l=a?JSON.parse(a):null}catch{}const d=new e(l?.message||a||"download UNS attachment failed",{status:r.status,code:"number"==typeof l?.code?l.code:void 0,details:l});if(0!==o||!s(d))throw d;i=await n(i)}throw new e("download UNS attachment failed")}export async function deleteUnsAttachment(e,t){await c("DELETE",l("nodes",e,`/attachments/${encodeURIComponent(t)}`))}export function getUnsNodeLatest(e){return c("GET",l("nodes",e,"/runtime/latest"))}export function getUnsNodeHistory(e,t={}){const n=t.limit??100;if(!(n>0))throw new TypeError("limit must be greater than zero");return c("GET",l("nodes",e,"/runtime/history"),{query:{limit:n}})}export async function getUnsRealtimeConnection(){const e=await o({requireProject:!1}),t=await c("POST",`${r}/realtime/ticket`,{config:e}),n=new URL(e.baseUrl);return n.protocol="https:"===n.protocol?"wss:":"ws:",n.pathname=`${r}/iot-source/realtime`,n.search="",n.searchParams.set("ticket",t.ticket),{...t,url:n.toString()}}function u(e,t){return c("POST",`${r}/iot-source/${e}`,{body:(n=t,Object.fromEntries(Object.entries(n).filter(([,e])=>void 0!==e)))});var n}export function listUnsIotCollectors(e,t={}){return u("collectors",{source_type:e,page:t.page??1,page_size:t.pageSize??t.page_size??20})}export function listUnsIotPoints(e,t,n={}){return u("points",{source_type:e,task_id:t,page:n.page??1,page_size:n.pageSize??n.page_size??20})}export function getUnsIotLatest(e,t,n={}){return u("latest",{task_id:e,point_id:t,tag_code:n.tagCode??n.tag_code,node_id:n.nodeId??n.node_id})}export function getUnsIotVideoStreamOptions(e){return u("video-stream-options",{point_id:e})}export const uns={provisioningSchema:getUnsProvisioningSchema,provisioningCapabilities:getUnsProvisioningCapabilities,validate:validateUnsProvisioning,plan:planUnsProvisioning,submit:submitUnsProvisioning,job:getUnsProvisioningJob,operations:getUnsProvisioningOperations,waitJob:waitForUnsProvisioningJob,listNodes:listUnsNodes,createNode:createUnsNode,batchCreateNodes:batchCreateUnsNodes,copyNode:copyUnsNode,updateNode:updateUnsNode,deleteNode:deleteUnsNode,listTemplates:listUnsTemplates,createTemplate:createUnsTemplate,updateTemplate:updateUnsTemplate,deleteTemplate:deleteUnsTemplate,listLabels:listUnsLabels,createLabel:createUnsLabel,updateLabel:updateUnsLabel,replaceLabelNodes:replaceUnsLabelNodes,deleteLabel:deleteUnsLabel,nodeSchema:getUnsNodeSchema,inferDefinition:inferUnsDefinition,listReverseDatasources:listUnsReverseDatasources,listReverseSchemas:listUnsReverseSchemas,listReverseTables:listUnsReverseTables,listReverseFields:listUnsReverseFields,listAttachments:listUnsAttachments,uploadAttachments:uploadUnsAttachments,downloadAttachment:downloadUnsAttachment,deleteAttachment:deleteUnsAttachment,nodeLatest:getUnsNodeLatest,nodeHistory:getUnsNodeHistory,realtimeConnection:getUnsRealtimeConnection,listCollectors:listUnsIotCollectors,listPoints:listUnsIotPoints,sourceLatest:getUnsIotLatest,videoStreamOptions:getUnsIotVideoStreamOptions};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kmlckj/licos-platform-sdk",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "LICOS platform SDK package shell for browser and Node runtimes",
|
|
5
5
|
"author": "kmlckj",
|
|
6
6
|
"type": "module",
|
|
@@ -34,15 +34,15 @@
|
|
|
34
34
|
"dist",
|
|
35
35
|
"README.md"
|
|
36
36
|
],
|
|
37
|
-
"scripts": {
|
|
37
|
+
"scripts": {
|
|
38
38
|
"build": "node build.mjs",
|
|
39
39
|
"prepack": "npm run build",
|
|
40
40
|
"test": "node --test"
|
|
41
|
-
},
|
|
42
|
-
"dependencies": {
|
|
43
|
-
"ws": "8.21.1"
|
|
44
|
-
},
|
|
45
|
-
"devDependencies": {
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"ws": "8.21.1"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
46
|
"terser": "5.48.0"
|
|
47
47
|
},
|
|
48
48
|
"license": "MIT",
|