@kmlckj/licos-platform-sdk 0.8.5 → 0.9.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.
package/README.md CHANGED
@@ -136,26 +136,26 @@ const schema = await uns.schemaCurrent();
136
136
  const checked = await uns.validate(document);
137
137
  const reviewedPlan = await uns.plan(document);
138
138
 
139
- await uns.apply(document, {
139
+ await uns.apply(document, {
140
140
  expectedDocumentHash: reviewedPlan.documentHash,
141
141
  expectedPlanHash: reviewedPlan.planHash,
142
142
  confirmed: true,
143
- });
144
- ```
145
-
146
- Use a `UNSChangeSet` for an isolated structural change. Review the dedicated
147
- plan and pass both hashes back unchanged. Destructive or replacement actions
148
- also require `impactConfirmed: true`.
149
-
150
- ```js
151
- const changes = await uns.planChanges(changeSet);
152
- await uns.applyChanges(changeSet, {
153
- expectedDocumentHash: changes.documentHash,
154
- expectedPlanHash: changes.planHash,
155
- confirmed: true,
156
- impactConfirmed: true,
157
- });
158
- ```
143
+ });
144
+ ```
145
+
146
+ Use a `UNSChangeSet` for an isolated structural change. Review the dedicated
147
+ plan and pass both hashes back unchanged. Destructive or replacement actions
148
+ also require `impactConfirmed: true`.
149
+
150
+ ```js
151
+ const changes = await uns.planChanges(changeSet);
152
+ await uns.applyChanges(changeSet, {
153
+ expectedDocumentHash: changes.documentHash,
154
+ expectedPlanHash: changes.planHash,
155
+ confirmed: true,
156
+ impactConfirmed: true,
157
+ });
158
+ ```
159
159
 
160
160
  Use `uns.openPath(path)` when business code targets an existing enterprise UNS
161
161
  path without creating or changing `UNS.json`:
@@ -165,12 +165,48 @@ const temperature = uns.openPath('project:/production-line/temperature');
165
165
  const current = await temperature.pointCurrent();
166
166
  ```
167
167
 
168
- Resource apply, data writes, point writes, and video controls require explicit
169
- confirmation. Data deletion accepts the exact rows returned by a prior query
170
- and also requires explicit confirmation. Point writes require a reason and ticket. The browser entry
171
- does not export UNS helpers.
168
+ Realtime point consumers obtain the server-side WebSocket endpoint through the
169
+ authorized project runtime API. Create one upstream connection per returned
170
+ `nodeCode`; do not derive or hardcode a DataFactory address:
172
171
 
173
- ## OAuth2 Application Management
172
+ ```js
173
+ const realtime = await uns.pointRealtimeConfig('TEMP_01');
174
+ // Connect to realtime.websocketUrl and register with realtime.nodeCode.
175
+ ```
176
+
177
+ Resource apply, data writes, point writes, and video controls require explicit
178
+ confirmation. Data deletion accepts the exact rows returned by a prior query
179
+ and also requires explicit confirmation. Point writes require a reason and ticket. The browser entry
180
+ does not export UNS helpers.
181
+
182
+ ## Direct Industrial Integration
183
+
184
+ The server-only `industrial` facade manages collection and video resources
185
+ without creating DataFactory UNS nodes. Use it only when the user explicitly
186
+ selects direct collector integration; UNS failures must not trigger this mode.
187
+
188
+ ```js
189
+ import { industrial } from '@kmlckj/licos-platform-sdk';
190
+
191
+ const points = await industrial.searchResources('collectionPoint', {
192
+ scope: 'project',
193
+ keyword: 'temperature',
194
+ });
195
+
196
+ const current = await industrial.pointCurrent(points.items[0].id);
197
+ const realtime = await industrial.realtimeConnection({
198
+ pointIds: [points.items[0].id],
199
+ transport: 'websocket',
200
+ });
201
+ ```
202
+
203
+ Realtime subscription defaults to upstream WebSocket and supports explicitly
204
+ selected MQTT. Point control defaults to HTTP and supports explicitly selected
205
+ MQTT. Neither direction silently falls back. Resource writes use a reviewed
206
+ `IndustrialChangeSet`; point and video writes require independent confirmation.
207
+ The browser entry does not export industrial helpers or external credentials.
208
+
209
+ ## OAuth2 Application Management
174
210
 
175
211
  OAuth2 management is available only from trusted Node runtime code. It uses the
176
212
  current project owner's platform identity and is not exported by the browser
package/dist/index.d.ts CHANGED
@@ -28,7 +28,8 @@ export interface RuntimeConfig {
28
28
  export function runtimeConfig(options?: { environmentOverrideEnv?: string }): Promise<RuntimeConfig>;
29
29
  export function authHeaders(config: RuntimeConfig, contentType?: string): Record<string, string>;
30
30
 
31
- export * from './uns.js';
31
+ export * from './uns.js';
32
+ export * from './industrial.js';
32
33
 
33
34
  export type OAuthLoginAudience = 'ALL' | 'OWNER_TENANT';
34
35
 
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export{PlatformSdkError,ConfigurationError,ApiError}from"./shared.js";export{runtimeConfig,authHeaders}from"./runtime.js";export*from"./database.js";export*from"./knowledge.js";export*from"./oauth.js";export*from"./oauth-runtime.js";export*from"./storage.js";export*from"./uns.js";export{studioDatabase}from"./studio-database.js";
1
+ export{PlatformSdkError,ConfigurationError,ApiError}from"./shared.js";export{runtimeConfig,authHeaders}from"./runtime.js";export*from"./database.js";export*from"./knowledge.js";export*from"./industrial.js";export*from"./oauth.js";export*from"./oauth-runtime.js";export*from"./storage.js";export*from"./uns.js";export{studioDatabase}from"./studio-database.js";
@@ -0,0 +1,120 @@
1
+ export type IndustrialResourceType =
2
+ | 'edgeAgent'
3
+ | 'connection'
4
+ | 'collectionTask'
5
+ | 'collectionPoint'
6
+ | 'videoEdge'
7
+ | 'videoGateway'
8
+ | 'videoDevice'
9
+ | 'videoChannel';
10
+
11
+ export type IndustrialSubscriptionTransport = 'auto' | 'websocket' | 'mqtt';
12
+ export type IndustrialControlTransport = 'auto' | 'http' | 'mqtt';
13
+
14
+ export function getIndustrialProtocolSchema(protocol: string): Promise<Record<string, unknown>>;
15
+ export function searchIndustrialResources(
16
+ resourceType: IndustrialResourceType | string,
17
+ options?: {
18
+ protocol?: string;
19
+ keyword?: string;
20
+ scope?: 'project' | 'enterprise';
21
+ selector?: Record<string, unknown>;
22
+ page?: number;
23
+ pageSize?: number;
24
+ page_size?: number;
25
+ },
26
+ ): Promise<Record<string, unknown>>;
27
+ export function getIndustrialResource(
28
+ resourceType: IndustrialResourceType | string,
29
+ resourceId: string,
30
+ ): Promise<Record<string, unknown>>;
31
+ export function validateIndustrialChanges(document: Record<string, unknown>): Promise<Record<string, unknown>>;
32
+ export function planIndustrialChanges(document: Record<string, unknown>): Promise<Record<string, unknown>>;
33
+ export function applyIndustrialChanges(
34
+ document: Record<string, unknown>,
35
+ options: {
36
+ expectedDocumentHash?: string;
37
+ expected_document_hash?: string;
38
+ expectedPlanHash?: string;
39
+ expected_plan_hash?: string;
40
+ confirmed: boolean;
41
+ impactConfirmed?: boolean;
42
+ impact_confirmed?: boolean;
43
+ },
44
+ ): Promise<Record<string, unknown>>;
45
+ export function getIndustrialRuntimeCapabilities(): Promise<Record<string, unknown>>;
46
+ export function getIndustrialRealtimeConnection(options: {
47
+ pointIds?: string[];
48
+ point_ids?: string[];
49
+ tagCodes?: string[];
50
+ tag_codes?: string[];
51
+ transport?: IndustrialSubscriptionTransport;
52
+ }): Promise<{
53
+ url: string;
54
+ authentication: string;
55
+ subscribe: {
56
+ type: 'subscribe';
57
+ transport: IndustrialSubscriptionTransport;
58
+ pointIds: string[];
59
+ tagCodes: string[];
60
+ };
61
+ }>;
62
+ export function getIndustrialPointCurrent(pointId: string): Promise<Record<string, unknown>>;
63
+ export function getIndustrialPointHistory(
64
+ pointId: string,
65
+ options: {
66
+ startTime?: string;
67
+ start_time?: string;
68
+ endTime?: string;
69
+ end_time?: string;
70
+ page?: number;
71
+ pageSize?: number;
72
+ page_size?: number;
73
+ },
74
+ ): Promise<Record<string, unknown>>;
75
+ export function writeIndustrialPoint(
76
+ pointId: string,
77
+ value: unknown,
78
+ options: {
79
+ reason: string;
80
+ ticket: string;
81
+ transport?: IndustrialControlTransport;
82
+ requestId?: string;
83
+ request_id?: string;
84
+ dryRun?: boolean;
85
+ dry_run?: boolean;
86
+ confirmed?: boolean;
87
+ },
88
+ ): Promise<Record<string, unknown>>;
89
+ export function getIndustrialVideoStreamOptions(channelId: string): Promise<Record<string, unknown>>;
90
+ export function startIndustrialVideoPreview(
91
+ channelId: string,
92
+ options: {
93
+ confirmed: boolean;
94
+ preferredProtocol?: string;
95
+ preferred_protocol?: string;
96
+ preferredProtocolOrder?: string[];
97
+ preferred_protocol_order?: string[];
98
+ },
99
+ ): Promise<Record<string, unknown>>;
100
+ export function stopIndustrialVideoPreview(
101
+ channelId: string,
102
+ options: { confirmed: boolean },
103
+ ): Promise<Record<string, unknown>>;
104
+
105
+ export const industrial: {
106
+ protocolSchema: typeof getIndustrialProtocolSchema;
107
+ searchResources: typeof searchIndustrialResources;
108
+ resource: typeof getIndustrialResource;
109
+ validateChanges: typeof validateIndustrialChanges;
110
+ planChanges: typeof planIndustrialChanges;
111
+ applyChanges: typeof applyIndustrialChanges;
112
+ runtimeCapabilities: typeof getIndustrialRuntimeCapabilities;
113
+ realtimeConnection: typeof getIndustrialRealtimeConnection;
114
+ pointCurrent: typeof getIndustrialPointCurrent;
115
+ pointHistory: typeof getIndustrialPointHistory;
116
+ writePoint: typeof writeIndustrialPoint;
117
+ videoStreamOptions: typeof getIndustrialVideoStreamOptions;
118
+ startVideoPreview: typeof startIndustrialVideoPreview;
119
+ stopVideoPreview: typeof stopIndustrialVideoPreview;
120
+ };
@@ -0,0 +1 @@
1
+ import{ApiError as t}from"./shared.js";import{authHeaders as e,refreshRuntimeConfig as r,runtimeConfig as n,shouldRefreshUserToken as i}from"./runtime.js";function o(t){return Object.fromEntries(Object.entries(t).filter(([,t])=>null!=t))}function a(t,e){return`/projects/${encodeURIComponent(t.projectId)}${e}`}async function s(a,s,{body:c,config:d}={}){let u=d||await n();for(let n=0;n<2;n+=1)try{const r=await fetch(new URL(`${u.baseUrl}/api/v1${s}`),{method:a,headers:e(u,void 0===c?void 0:"application/json"),body:void 0===c?void 0:JSON.stringify(o(c))}),n=await r.text();let i=null;try{i=n?JSON.parse(n):null}catch{throw new t(n||`platform industrial API returned ${r.status}`,{status:r.status,details:n})}if(!r.ok||i&&void 0!==i.code&&0!==i.code||!1===i?.success)throw new t(i?.message||n||"platform industrial API failed",{status:r.status,code:"number"==typeof i?.code?i.code:void 0,details:i});return i&&"object"==typeof i?i.data:i}catch(t){if(0===n&&i(t)){u=await r(u);continue}throw t}throw new t("platform industrial API failed")}export async function getIndustrialProtocolSchema(t){const e=await n();return s("GET",a(e,`/industrial/protocols/${encodeURIComponent(t)}/schema`),{config:e})}export async function searchIndustrialResources(t,e={}){const r=await n();return s("POST",a(r,"/industrial/resources/search"),{body:{resourceType:t,protocol:e.protocol,keyword:e.keyword,scope:e.scope||"project",selector:e.selector||{},page:e.page??1,pageSize:e.pageSize??e.page_size??20},config:r})}export async function getIndustrialResource(t,e){const r=await n();return s("GET",a(r,`/industrial/resources/${encodeURIComponent(t)}/${encodeURIComponent(e)}`),{config:r})}async function c(t,e){const r=await n();return s("POST",a(r,`/industrial/changes/${t}`),{body:{document:e},config:r})}export function validateIndustrialChanges(t){return c("validate",t)}export function planIndustrialChanges(t){return c("plan",t)}export async function applyIndustrialChanges(t,e={}){const r=String(e.expectedDocumentHash??e.expected_document_hash??"").trim(),i=String(e.expectedPlanHash??e.expected_plan_hash??"").trim();if(!0!==e.confirmed)throw new TypeError("industrial changes apply requires explicit confirmation");if(!r||!i)throw new TypeError("industrial changes apply requires document and plan hashes");const o=await n();return s("POST",a(o,"/industrial/changes/apply"),{body:{document:t,expectedDocumentHash:r,expectedPlanHash:i,confirmed:!0,impactConfirmed:!0===e.impactConfirmed||!0===e.impact_confirmed},config:o})}export async function getIndustrialRuntimeCapabilities(){const t=await n();return s("GET",a(t,"/industrial/runtime/capabilities"),{config:t})}export async function getIndustrialRealtimeConnection(t={}){const e=(t.pointIds||t.point_ids||[]).map(String).map(t=>t.trim()).filter(Boolean),r=(t.tagCodes||t.tag_codes||[]).map(String).map(t=>t.trim()).filter(Boolean);if(0===e.length&&0===r.length)throw new TypeError("pointIds or tagCodes must be provided");const i=await n(),o=new URL(i.baseUrl);return o.protocol="https:"===o.protocol?"wss:":"ws:",o.pathname=`/api/v1${a(i,"/industrial/runtime/points/realtime")}`,o.search="",o.hash="",{url:o.toString(),authentication:"use platform session or Authorization header",subscribe:{type:"subscribe",transport:t.transport||"auto",pointIds:e,tagCodes:r}}}function d(t,e,r){return a(t,`/industrial/runtime/points/${encodeURIComponent(e)}/${r}`)}export async function getIndustrialPointCurrent(t){const e=await n();return s("GET",d(e,t,"current"),{config:e})}export async function getIndustrialPointHistory(t,e={}){const r=await n();return s("POST",d(r,t,"history"),{body:{startTime:e.startTime??e.start_time,endTime:e.endTime??e.end_time,page:e.page??1,pageSize:e.pageSize??e.page_size??100},config:r})}export async function writeIndustrialPoint(t,e,r={}){const i=String(r.reason||"").trim(),o=String(r.ticket||"").trim(),a=!0===r.dryRun||!0===r.dry_run;if(!a&&!0!==r.confirmed)throw new TypeError("industrial point write requires explicit confirmation");if(!i||!o)throw new TypeError("industrial point write requires reason and ticket");const c=await n();return s("POST",d(c,t,"write"),{body:{value:e,transport:r.transport||"auto",reason:i,ticket:o,requestId:r.requestId??r.request_id,dryRun:a,confirmed:!0===r.confirmed},config:c})}async function u(t,e,r,i){const o=await n();return s(t,a(o,`/industrial/runtime/video/channels/${encodeURIComponent(e)}/${r}`),{body:i,config:o})}export function getIndustrialVideoStreamOptions(t){return u("GET",t,"stream-options")}export function startIndustrialVideoPreview(t,e={}){if(!0!==e.confirmed)throw new TypeError("industrial video preview start requires explicit confirmation");return u("POST",t,"preview/start",{preferredProtocol:e.preferredProtocol??e.preferred_protocol??"http-flv",preferredProtocolOrder:e.preferredProtocolOrder??e.preferred_protocol_order??["http-flv","webrtc","hls"],confirmed:!0})}export function stopIndustrialVideoPreview(t,e={}){if(!0!==e.confirmed)throw new TypeError("industrial video preview stop requires explicit confirmation");return u("POST",t,"preview/stop",{confirmed:!0})}export const industrial={protocolSchema:getIndustrialProtocolSchema,searchResources:searchIndustrialResources,resource:getIndustrialResource,validateChanges:validateIndustrialChanges,planChanges:planIndustrialChanges,applyChanges:applyIndustrialChanges,runtimeCapabilities:getIndustrialRuntimeCapabilities,realtimeConnection:getIndustrialRealtimeConnection,pointCurrent:getIndustrialPointCurrent,pointHistory:getIndustrialPointHistory,writePoint:writeIndustrialPoint,videoStreamOptions:getIndustrialVideoStreamOptions,startVideoPreview:startIndustrialVideoPreview,stopVideoPreview:stopIndustrialVideoPreview};
package/dist/uns.d.ts CHANGED
@@ -50,7 +50,7 @@ export function listUnsBindings(): Promise<UnsObject[]>;
50
50
  export function resolveUnsPath(path: string): Promise<UnsObject>;
51
51
  export function validateUnsDocument(document: UnsObject): Promise<UnsObject>;
52
52
  export function planUnsDocument(document: UnsObject): Promise<UnsObject>;
53
- export function applyUnsDocument(
53
+ export function applyUnsDocument(
54
54
  document: UnsObject,
55
55
  options: {
56
56
  expectedDocumentHash?: string;
@@ -59,21 +59,21 @@ export function applyUnsDocument(
59
59
  expected_plan_hash?: string;
60
60
  confirmed: boolean;
61
61
  },
62
- ): Promise<UnsObject>;
63
- export function validateUnsChanges(document: UnsObject): Promise<UnsObject>;
64
- export function planUnsChanges(document: UnsObject): Promise<UnsObject>;
65
- export function applyUnsChanges(
66
- document: UnsObject,
67
- options: {
68
- expectedDocumentHash?: string;
69
- expected_document_hash?: string;
70
- expectedPlanHash?: string;
71
- expected_plan_hash?: string;
72
- confirmed: boolean;
73
- impactConfirmed?: boolean;
74
- impact_confirmed?: boolean;
75
- },
76
- ): Promise<UnsObject>;
62
+ ): Promise<UnsObject>;
63
+ export function validateUnsChanges(document: UnsObject): Promise<UnsObject>;
64
+ export function planUnsChanges(document: UnsObject): Promise<UnsObject>;
65
+ export function applyUnsChanges(
66
+ document: UnsObject,
67
+ options: {
68
+ expectedDocumentHash?: string;
69
+ expected_document_hash?: string;
70
+ expectedPlanHash?: string;
71
+ expected_plan_hash?: string;
72
+ confirmed: boolean;
73
+ impactConfirmed?: boolean;
74
+ impact_confirmed?: boolean;
75
+ },
76
+ ): Promise<UnsObject>;
77
77
  export function queryUnsNodeData(nodeCode: string, options?: UnsDataQueryOptions): Promise<UnsObject>;
78
78
  export function writeUnsNodeData(
79
79
  nodeCode: string,
@@ -86,6 +86,8 @@ export function writeUnsPathData(path: string, fieldValues: UnsObject, options:
86
86
  export function deleteUnsPathData(path: string, rows: UnsObject[], options: { confirmed: boolean }): Promise<UnsObject>;
87
87
  export function getUnsPointCurrent(nodeCode: string): Promise<UnsObject>;
88
88
  export function getUnsPathPointCurrent(path: string): Promise<UnsObject>;
89
+ export function getUnsPointRealtimeConfig(nodeCode: string): Promise<UnsObject>;
90
+ export function getUnsPathPointRealtimeConfig(path: string): Promise<UnsObject>;
89
91
  export function getUnsPointHistory(nodeCode: string, options: UnsPointHistoryOptions): Promise<UnsObject>;
90
92
  export function getUnsPathPointHistory(path: string, options: UnsPointHistoryOptions): Promise<UnsObject>;
91
93
  export function writeUnsPoint(nodeCode: string, value: unknown, options: UnsPointWriteOptions): Promise<UnsObject>;
@@ -105,6 +107,7 @@ export class UnsPathNode {
105
107
  writeData(fieldValues: UnsObject, options: { confirmed: boolean }): Promise<UnsObject>;
106
108
  deleteData(rows: UnsObject[], options: { confirmed: boolean }): Promise<UnsObject>;
107
109
  pointCurrent(): Promise<UnsObject>;
110
+ pointRealtimeConfig(): Promise<UnsObject>;
108
111
  pointHistory(options: UnsPointHistoryOptions): Promise<UnsObject>;
109
112
  writePoint(value: unknown, options: UnsPointWriteOptions): Promise<UnsObject>;
110
113
  videoStreamOptions(): Promise<UnsObject>;
@@ -124,12 +127,12 @@ export const uns: {
124
127
  searchResources: typeof searchUnsResources;
125
128
  bindings: typeof listUnsBindings;
126
129
  resolvePath: typeof resolveUnsPath;
127
- validate: typeof validateUnsDocument;
128
- plan: typeof planUnsDocument;
129
- apply: typeof applyUnsDocument;
130
- validateChanges: typeof validateUnsChanges;
131
- planChanges: typeof planUnsChanges;
132
- applyChanges: typeof applyUnsChanges;
130
+ validate: typeof validateUnsDocument;
131
+ plan: typeof planUnsDocument;
132
+ apply: typeof applyUnsDocument;
133
+ validateChanges: typeof validateUnsChanges;
134
+ planChanges: typeof planUnsChanges;
135
+ applyChanges: typeof applyUnsChanges;
133
136
  queryNodeData: typeof queryUnsNodeData;
134
137
  writeNodeData: typeof writeUnsNodeData;
135
138
  deleteNodeData: typeof deleteUnsNodeData;
@@ -138,6 +141,8 @@ export const uns: {
138
141
  deletePathData: typeof deleteUnsPathData;
139
142
  pointCurrent: typeof getUnsPointCurrent;
140
143
  pathPointCurrent: typeof getUnsPathPointCurrent;
144
+ pointRealtimeConfig: typeof getUnsPointRealtimeConfig;
145
+ pathPointRealtimeConfig: typeof getUnsPathPointRealtimeConfig;
141
146
  pointHistory: typeof getUnsPointHistory;
142
147
  pathPointHistory: typeof getUnsPathPointHistory;
143
148
  writePoint: typeof writeUnsPoint;
package/dist/uns.js CHANGED
@@ -1 +1 @@
1
- import{ApiError as t}from"./shared.js";import{authHeaders as e,refreshRuntimeConfig as n,runtimeConfig as o,shouldRefreshUserToken as r}from"./runtime.js";function a(t){return Object.fromEntries(Object.entries(t).filter(([,t])=>null!=t))}function i(t,e){return`/projects/${encodeURIComponent(t.projectId)}${e}`}function s(t,e,n,o){return i(t,`/uns/runtime/${e}/${encodeURIComponent(n)}/${o}`)}function c(t,e,n){const o=String(n||"").trim();if(!o)throw new TypeError("UNS path cannot be empty");return`${i(t,`/uns/runtime/path/${e}`)}?${new URLSearchParams({path:o})}`}function p(t,e){return new URL(`${t.baseUrl}/api/v1${e}`)}async function u(e){const n=await e.text();let o=null;try{o=n?JSON.parse(n):null}catch{throw new t(n||`platform UNS API returned ${e.status}`,{status:e.status,details:n})}if(!e.ok)throw new t(o?.message||n||`platform UNS API returned ${e.status}`,{status:e.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 t(o.message||"platform UNS API failed",{status:e.status,code:"number"==typeof o.code?o.code:void 0,details:o});return o.data}async function d(i,s,{body:c,config:d}={}){let h=d||await o();for(let t=0;t<2;t+=1)try{const t="function"==typeof s?s(h):s,n=await fetch(p(h,t),{method:i,headers:e(h,void 0===c?void 0:"application/json"),body:void 0===c?void 0:JSON.stringify(a(c))});return await u(n)}catch(e){if(0===t&&r(e)){h=await n(h);continue}throw e}throw new t("platform UNS API failed")}export function getCurrentUnsSchema(){return d("GET","/uns/schemas/current")}export function getUnsSchema(t="1.0"){return d("GET",`/uns/schemas/${encodeURIComponent(t)}`)}export function listUnsSchemaBlocks(t="1.0"){return d("GET",`/uns/schemas/${encodeURIComponent(t)}/blocks`)}export function getUnsSchemaBlock(t,{version:e="1.0",depth:n=1}={}){return d("GET",`/uns/schemas/${encodeURIComponent(e)}/blocks/${encodeURIComponent(t)}?depth=${encodeURIComponent(n)}`)}export function getUnsProtocolSchema(t,{version:e="1.0"}={}){return d("GET",`/uns/schemas/${encodeURIComponent(e)}/blocks/collection-point/protocols/${encodeURIComponent(t)}`)}export async function discoverUnsResources({resourceTypes:t=[],protocols:e=[]}={}){const n=await o();return d("POST",i(n,"/uns/discover"),{body:{resourceTypes:t,protocols:e},config:n})}export async function searchUnsResources(t,e={}){const n=await o();return d("POST",i(n,"/uns/resources/search"),{body:{resourceType:t,protocol:e.protocol,keyword:e.keyword,selector:e.selector||{},page:e.page??1,pageSize:e.pageSize??e.page_size??20},config:n})}export async function listUnsBindings(){const t=await o();return d("GET",i(t,"/uns/bindings"),{config:t})}export async function resolveUnsPath(t){const e=await o();return d("GET",c(e,"resolve",t),{config:e})}export async function validateUnsDocument(t){const e=await o();return d("POST",i(e,"/uns/validate"),{body:{document:t},config:e})}export async function planUnsDocument(t){const e=await o();return d("POST",i(e,"/uns/plan"),{body:{document:t},config:e})}export async function applyUnsDocument(t,e={}){const n=String(e.expectedDocumentHash??e.expected_document_hash??"").trim(),r=String(e.expectedPlanHash??e.expected_plan_hash??"").trim();if(!0!==e.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 d("POST",i(a,"/uns/apply"),{body:{document:t,expectedDocumentHash:n,expectedPlanHash:r,confirmed:!0},config:a})}export async function validateUnsChanges(t){const e=await o();return d("POST",i(e,"/uns/changes/validate"),{body:{document:t},config:e})}export async function planUnsChanges(t){const e=await o();return d("POST",i(e,"/uns/changes/plan"),{body:{document:t},config:e})}export async function applyUnsChanges(t,e={}){const n=String(e.expectedDocumentHash??e.expected_document_hash??"").trim(),r=String(e.expectedPlanHash??e.expected_plan_hash??"").trim();if(!0!==e.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 d("POST",i(a,"/uns/changes/apply"),{body:{document:t,expectedDocumentHash:n,expectedPlanHash:r,confirmed:!0,impactConfirmed:!0===e.impactConfirmed||!0===e.impact_confirmed},config:a})}function h(t={}){return a({pageNum:t.pageNum??t.page_num??1,pageSize:t.pageSize??t.page_size??50,paginationMode:t.paginationMode??t.pagination_mode??"OFFSET",pageToken:t.pageToken??t.page_token})}export async function queryUnsNodeData(t,e={}){const n=await o();return d("POST",s(n,"nodes",t,"query"),{body:h(e),config:n})}function f(t,e){if(!0!==e)throw new TypeError("UNS data write requires explicit confirmation");if(!t||"object"!=typeof t||0===Object.keys(t).length)throw new TypeError("UNS data write field values cannot be empty")}export async function writeUnsNodeData(t,e,{confirmed:n=!1}={}){f(e,n);const r=await o();return d("POST",s(r,"nodes",t,"write"),{body:{fieldValues:e,environment:r.environment,confirmed:!0},config:r})}function m(t,e){if(!0!==e)throw new TypeError("UNS data deletion requires explicit confirmation");if(!Array.isArray(t)||0===t.length||t.some(t=>!t||"object"!=typeof t||Array.isArray(t)||0===Object.keys(t).length))throw new TypeError("UNS data deletion rows cannot be empty")}export async function deleteUnsNodeData(t,e,{confirmed:n=!1}={}){m(e,n);const r=await o();return d("POST",s(r,"nodes",t,"delete"),{body:{rows:e,confirmed:!0},config:r})}export async function queryUnsPathData(t,e={}){const n=await o();return d("POST",c(n,"data/query",t),{body:h(e),config:n})}export async function writeUnsPathData(t,e,{confirmed:n=!1}={}){f(e,n);const r=await o();return d("POST",c(r,"data/write",t),{body:{fieldValues:e,environment:r.environment,confirmed:!0},config:r})}export async function deleteUnsPathData(t,e,{confirmed:n=!1}={}){m(e,n);const r=await o();return d("POST",c(r,"data/delete",t),{body:{rows:e,confirmed:!0},config:r})}export async function getUnsPointCurrent(t){const e=await o();return d("GET",s(e,"points",t,"current"),{config:e})}export async function getUnsPathPointCurrent(t){const e=await o();return d("GET",c(e,"point/current",t),{config:e})}function l(t={}){return{startTime:t.startTime??t.start_time,endTime:t.endTime??t.end_time,page:t.page??1,pageSize:t.pageSize??t.page_size??100}}export async function getUnsPointHistory(t,e){const n=await o();return d("POST",s(n,"points",t,"history"),{body:l(e),config:n})}export async function getUnsPathPointHistory(t,e){const n=await o();return d("POST",c(n,"point/history",t),{body:l(e),config:n})}function y(t,e={}){const n=String(e.reason||"").trim(),o=String(e.ticket||"").trim(),r=e.dryRun??e.dry_run??!1,i=e.confirmed??!1;if(!r&&!0!==i)throw new TypeError("UNS point write requires explicit confirmation");if(!n||!o)throw new TypeError("UNS point write requires reason and ticket");return a({value:t,reason:n,ticket:o,requestId:e.requestId??e.request_id,dryRun:r,confirmed:i})}export async function writeUnsPoint(t,e,n={}){const r=y(e,n),a=await o();return d("POST",s(a,"points",t,"write"),{body:r,config:a})}export async function writeUnsPathPoint(t,e,n={}){const r=y(e,n),a=await o();return d("POST",c(a,"point/write",t),{body:r,config:a})}export async function getUnsVideoStreamOptions(t){const e=await o();return d("GET",s(e,"videos",t,"stream-options"),{config:e})}export async function getUnsPathVideoStreamOptions(t){const e=await o();return d("GET",c(e,"video/stream-options",t),{config:e})}export async function createUnsVideoSnapshot(t){const e=await o();return d("POST",s(e,"videos",t,"snapshot"),{config:e})}export async function createUnsPathVideoSnapshot(t){const e=await o();return d("POST",c(e,"video/snapshot",t),{config:e})}function U(t,e={}){if(!0!==e.confirmed)throw new TypeError("UNS video control requires explicit confirmation");return{action:t,parameters:e.parameters||{},confirmed:!0}}export async function controlUnsVideo(t,e,n={}){const r=U(e,n),a=await o();return d("POST",s(a,"videos",t,"control"),{body:r,config:a})}export async function controlUnsPathVideo(t,e,n={}){const r=U(e,n),a=await o();return d("POST",c(a,"video/control",t),{body:r,config:a})}export class UnsPathNode{constructor(t){if(this.path=String(t||"").trim(),!this.path)throw new TypeError("UNS path cannot be empty")}resolve(){return resolveUnsPath(this.path)}queryData(t){return queryUnsPathData(this.path,t)}writeData(t,e){return writeUnsPathData(this.path,t,e)}deleteData(t,e){return deleteUnsPathData(this.path,t,e)}pointCurrent(){return getUnsPathPointCurrent(this.path)}pointHistory(t){return getUnsPathPointHistory(this.path,t)}writePoint(t,e){return writeUnsPathPoint(this.path,t,e)}videoStreamOptions(){return getUnsPathVideoStreamOptions(this.path)}videoSnapshot(){return createUnsPathVideoSnapshot(this.path)}controlVideo(t,e){return controlUnsPathVideo(this.path,t,e)}}export function openUnsPath(t){return new UnsPathNode(t)}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,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 t}from"./shared.js";import{authHeaders as e,refreshRuntimeConfig as n,runtimeConfig as o,shouldRefreshUserToken as r}from"./runtime.js";function a(t){return Object.fromEntries(Object.entries(t).filter(([,t])=>null!=t))}function i(t,e){return`/projects/${encodeURIComponent(t.projectId)}${e}`}function s(t,e,n,o){return i(t,`/uns/runtime/${e}/${encodeURIComponent(n)}/${o}`)}function c(t,e,n){const o=String(n||"").trim();if(!o)throw new TypeError("UNS path cannot be empty");return`${i(t,`/uns/runtime/path/${e}`)}?${new URLSearchParams({path:o})}`}function p(t,e){return new URL(`${t.baseUrl}/api/v1${e}`)}async function u(e){const n=await e.text();let o=null;try{o=n?JSON.parse(n):null}catch{throw new t(n||`platform UNS API returned ${e.status}`,{status:e.status,details:n})}if(!e.ok)throw new t(o?.message||n||`platform UNS API returned ${e.status}`,{status:e.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 t(o.message||"platform UNS API failed",{status:e.status,code:"number"==typeof o.code?o.code:void 0,details:o});return o.data}async function d(i,s,{body:c,config:d}={}){let h=d||await o();for(let t=0;t<2;t+=1)try{const t="function"==typeof s?s(h):s,n=await fetch(p(h,t),{method:i,headers:e(h,void 0===c?void 0:"application/json"),body:void 0===c?void 0:JSON.stringify(a(c))});return await u(n)}catch(e){if(0===t&&r(e)){h=await n(h);continue}throw e}throw new t("platform UNS API failed")}export function getCurrentUnsSchema(){return d("GET","/uns/schemas/current")}export function getUnsSchema(t="1.0"){return d("GET",`/uns/schemas/${encodeURIComponent(t)}`)}export function listUnsSchemaBlocks(t="1.0"){return d("GET",`/uns/schemas/${encodeURIComponent(t)}/blocks`)}export function getUnsSchemaBlock(t,{version:e="1.0",depth:n=1}={}){return d("GET",`/uns/schemas/${encodeURIComponent(e)}/blocks/${encodeURIComponent(t)}?depth=${encodeURIComponent(n)}`)}export function getUnsProtocolSchema(t,{version:e="1.0"}={}){return d("GET",`/uns/schemas/${encodeURIComponent(e)}/blocks/collection-point/protocols/${encodeURIComponent(t)}`)}export async function discoverUnsResources({resourceTypes:t=[],protocols:e=[]}={}){const n=await o();return d("POST",i(n,"/uns/discover"),{body:{resourceTypes:t,protocols:e},config:n})}export async function searchUnsResources(t,e={}){const n=await o();return d("POST",i(n,"/uns/resources/search"),{body:{resourceType:t,protocol:e.protocol,keyword:e.keyword,selector:e.selector||{},page:e.page??1,pageSize:e.pageSize??e.page_size??20},config:n})}export async function listUnsBindings(){const t=await o();return d("GET",i(t,"/uns/bindings"),{config:t})}export async function resolveUnsPath(t){const e=await o();return d("GET",c(e,"resolve",t),{config:e})}export async function validateUnsDocument(t){const e=await o();return d("POST",i(e,"/uns/validate"),{body:{document:t},config:e})}export async function planUnsDocument(t){const e=await o();return d("POST",i(e,"/uns/plan"),{body:{document:t},config:e})}export async function applyUnsDocument(t,e={}){const n=String(e.expectedDocumentHash??e.expected_document_hash??"").trim(),r=String(e.expectedPlanHash??e.expected_plan_hash??"").trim();if(!0!==e.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 d("POST",i(a,"/uns/apply"),{body:{document:t,expectedDocumentHash:n,expectedPlanHash:r,confirmed:!0},config:a})}export async function validateUnsChanges(t){const e=await o();return d("POST",i(e,"/uns/changes/validate"),{body:{document:t},config:e})}export async function planUnsChanges(t){const e=await o();return d("POST",i(e,"/uns/changes/plan"),{body:{document:t},config:e})}export async function applyUnsChanges(t,e={}){const n=String(e.expectedDocumentHash??e.expected_document_hash??"").trim(),r=String(e.expectedPlanHash??e.expected_plan_hash??"").trim();if(!0!==e.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 d("POST",i(a,"/uns/changes/apply"),{body:{document:t,expectedDocumentHash:n,expectedPlanHash:r,confirmed:!0,impactConfirmed:!0===e.impactConfirmed||!0===e.impact_confirmed},config:a})}function h(t={}){return a({pageNum:t.pageNum??t.page_num??1,pageSize:t.pageSize??t.page_size??50,paginationMode:t.paginationMode??t.pagination_mode??"OFFSET",pageToken:t.pageToken??t.page_token})}export async function queryUnsNodeData(t,e={}){const n=await o();return d("POST",s(n,"nodes",t,"query"),{body:h(e),config:n})}function f(t,e){if(!0!==e)throw new TypeError("UNS data write requires explicit confirmation");if(!t||"object"!=typeof t||0===Object.keys(t).length)throw new TypeError("UNS data write field values cannot be empty")}export async function writeUnsNodeData(t,e,{confirmed:n=!1}={}){f(e,n);const r=await o();return d("POST",s(r,"nodes",t,"write"),{body:{fieldValues:e,environment:r.environment,confirmed:!0},config:r})}function m(t,e){if(!0!==e)throw new TypeError("UNS data deletion requires explicit confirmation");if(!Array.isArray(t)||0===t.length||t.some(t=>!t||"object"!=typeof t||Array.isArray(t)||0===Object.keys(t).length))throw new TypeError("UNS data deletion rows cannot be empty")}export async function deleteUnsNodeData(t,e,{confirmed:n=!1}={}){m(e,n);const r=await o();return d("POST",s(r,"nodes",t,"delete"),{body:{rows:e,confirmed:!0},config:r})}export async function queryUnsPathData(t,e={}){const n=await o();return d("POST",c(n,"data/query",t),{body:h(e),config:n})}export async function writeUnsPathData(t,e,{confirmed:n=!1}={}){f(e,n);const r=await o();return d("POST",c(r,"data/write",t),{body:{fieldValues:e,environment:r.environment,confirmed:!0},config:r})}export async function deleteUnsPathData(t,e,{confirmed:n=!1}={}){m(e,n);const r=await o();return d("POST",c(r,"data/delete",t),{body:{rows:e,confirmed:!0},config:r})}export async function getUnsPointCurrent(t){const e=await o();return d("GET",s(e,"points",t,"current"),{config:e})}export async function getUnsPathPointCurrent(t){const e=await o();return d("GET",c(e,"point/current",t),{config:e})}export async function getUnsPointRealtimeConfig(t){const e=await o();return d("GET",s(e,"points",t,"realtime-config"),{config:e})}export async function getUnsPathPointRealtimeConfig(t){const e=await o();return d("GET",c(e,"point/realtime-config",t),{config:e})}function l(t={}){return{startTime:t.startTime??t.start_time,endTime:t.endTime??t.end_time,page:t.page??1,pageSize:t.pageSize??t.page_size??100}}export async function getUnsPointHistory(t,e){const n=await o();return d("POST",s(n,"points",t,"history"),{body:l(e),config:n})}export async function getUnsPathPointHistory(t,e){const n=await o();return d("POST",c(n,"point/history",t),{body:l(e),config:n})}function y(t,e={}){const n=String(e.reason||"").trim(),o=String(e.ticket||"").trim(),r=e.dryRun??e.dry_run??!1,i=e.confirmed??!1;if(!r&&!0!==i)throw new TypeError("UNS point write requires explicit confirmation");if(!n||!o)throw new TypeError("UNS point write requires reason and ticket");return a({value:t,reason:n,ticket:o,requestId:e.requestId??e.request_id,dryRun:r,confirmed:i})}export async function writeUnsPoint(t,e,n={}){const r=y(e,n),a=await o();return d("POST",s(a,"points",t,"write"),{body:r,config:a})}export async function writeUnsPathPoint(t,e,n={}){const r=y(e,n),a=await o();return d("POST",c(a,"point/write",t),{body:r,config:a})}export async function getUnsVideoStreamOptions(t){const e=await o();return d("GET",s(e,"videos",t,"stream-options"),{config:e})}export async function getUnsPathVideoStreamOptions(t){const e=await o();return d("GET",c(e,"video/stream-options",t),{config:e})}export async function createUnsVideoSnapshot(t){const e=await o();return d("POST",s(e,"videos",t,"snapshot"),{config:e})}export async function createUnsPathVideoSnapshot(t){const e=await o();return d("POST",c(e,"video/snapshot",t),{config:e})}function g(t,e={}){if(!0!==e.confirmed)throw new TypeError("UNS video control requires explicit confirmation");return{action:t,parameters:e.parameters||{},confirmed:!0}}export async function controlUnsVideo(t,e,n={}){const r=g(e,n),a=await o();return d("POST",s(a,"videos",t,"control"),{body:r,config:a})}export async function controlUnsPathVideo(t,e,n={}){const r=g(e,n),a=await o();return d("POST",c(a,"video/control",t),{body:r,config:a})}export class UnsPathNode{constructor(t){if(this.path=String(t||"").trim(),!this.path)throw new TypeError("UNS path cannot be empty")}resolve(){return resolveUnsPath(this.path)}queryData(t){return queryUnsPathData(this.path,t)}writeData(t,e){return writeUnsPathData(this.path,t,e)}deleteData(t,e){return deleteUnsPathData(this.path,t,e)}pointCurrent(){return getUnsPathPointCurrent(this.path)}pointRealtimeConfig(){return getUnsPathPointRealtimeConfig(this.path)}pointHistory(t){return getUnsPathPointHistory(this.path,t)}writePoint(t,e){return writeUnsPathPoint(this.path,t,e)}videoStreamOptions(){return getUnsPathVideoStreamOptions(this.path)}videoSnapshot(){return createUnsPathVideoSnapshot(this.path)}controlVideo(t,e){return controlUnsPathVideo(this.path,t,e)}}export function openUnsPath(t){return new UnsPathNode(t)}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,pointHistory:getUnsPointHistory,pathPointHistory:getUnsPathPointHistory,writePoint:writeUnsPoint,writePathPoint:writeUnsPathPoint,videoStreamOptions:getUnsVideoStreamOptions,pathVideoStreamOptions:getUnsPathVideoStreamOptions,videoSnapshot:createUnsVideoSnapshot,pathVideoSnapshot:createUnsPathVideoSnapshot,controlVideo:controlUnsVideo,controlPathVideo:controlUnsPathVideo,openPath:openUnsPath};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kmlckj/licos-platform-sdk",
3
- "version": "0.8.5",
3
+ "version": "0.9.0",
4
4
  "description": "LICOS platform SDK package shell for browser and Node runtimes",
5
5
  "author": "kmlckj",
6
6
  "type": "module",