@kmlckj/licos-platform-sdk 0.8.4 → 0.8.6

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
@@ -119,44 +119,67 @@ const results = await knowledge.search('How do I reset my password?', {
119
119
  });
120
120
  ```
121
121
 
122
- The browser entry does not export knowledge helpers because runtime tokens must
123
- not be bundled into public frontend code.
124
-
125
- ## Unified Namespace (UNS)
126
-
127
- UNS helpers expose the same Schema, resource discovery, validation, plan,
128
- apply, binding, data, point, video, and enterprise path APIs as the Python
129
- platform SDK. They are server-only and derive the trusted project scope from
130
- the injected runtime identity.
131
-
132
- ```js
133
- import { uns } from '@kmlckj/licos-platform-sdk';
134
-
135
- const schema = await uns.schemaCurrent();
136
- const checked = await uns.validate(document);
137
- const reviewedPlan = await uns.plan(document);
138
-
139
- await uns.apply(document, {
140
- expectedDocumentHash: reviewedPlan.documentHash,
141
- expectedPlanHash: reviewedPlan.planHash,
142
- confirmed: true,
143
- });
122
+ The browser entry does not export knowledge helpers because runtime tokens must
123
+ not be bundled into public frontend code.
124
+
125
+ ## Unified Namespace (UNS)
126
+
127
+ UNS helpers expose the same Schema, resource discovery, validation, plan,
128
+ apply, binding, data, point, video, and enterprise path APIs as the Python
129
+ platform SDK. They are server-only and derive the trusted project scope from
130
+ the injected runtime identity.
131
+
132
+ ```js
133
+ import { uns } from '@kmlckj/licos-platform-sdk';
134
+
135
+ const schema = await uns.schemaCurrent();
136
+ const checked = await uns.validate(document);
137
+ const reviewedPlan = await uns.plan(document);
138
+
139
+ await uns.apply(document, {
140
+ expectedDocumentHash: reviewedPlan.documentHash,
141
+ expectedPlanHash: reviewedPlan.planHash,
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
+ ```
159
+
160
+ Use `uns.openPath(path)` when business code targets an existing enterprise UNS
161
+ path without creating or changing `UNS.json`:
162
+
163
+ ```js
164
+ const temperature = uns.openPath('project:/production-line/temperature');
165
+ const current = await temperature.pointCurrent();
144
166
  ```
145
167
 
146
- Use `uns.openPath(path)` when business code targets an existing enterprise UNS
147
- path without creating or changing `UNS.json`:
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:
148
171
 
149
172
  ```js
150
- const temperature = uns.openPath('project:/production-line/temperature');
151
- const current = await temperature.pointCurrent();
173
+ const realtime = await uns.pointRealtimeConfig('TEMP_01');
174
+ // Connect to realtime.websocketUrl and register with realtime.nodeCode.
152
175
  ```
153
176
 
154
177
  Resource apply, data writes, point writes, and video controls require explicit
155
- confirmation. Data deletion accepts the exact rows returned by a prior query
156
- and also requires explicit confirmation. Point writes require a reason and ticket. The browser entry
157
- does not export UNS helpers.
158
-
159
- ## OAuth2 Application Management
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
+ ## OAuth2 Application Management
160
183
 
161
184
  OAuth2 management is available only from trusted Node runtime code. It uses the
162
185
  current project owner's platform identity and is not exported by the browser
package/dist/index.d.ts CHANGED
@@ -26,9 +26,9 @@ export interface RuntimeConfig {
26
26
  }
27
27
 
28
28
  export function runtimeConfig(options?: { environmentOverrideEnv?: string }): Promise<RuntimeConfig>;
29
- export function authHeaders(config: RuntimeConfig, contentType?: string): Record<string, string>;
30
-
31
- export * from './uns.js';
29
+ export function authHeaders(config: RuntimeConfig, contentType?: string): Record<string, string>;
30
+
31
+ export * from './uns.js';
32
32
 
33
33
  export type OAuthLoginAudience = 'ALL' | 'OWNER_TENANT';
34
34
 
package/dist/uns.d.ts CHANGED
@@ -1,135 +1,157 @@
1
- export type UnsObject = Record<string, unknown>;
2
-
3
- export interface UnsDataQueryOptions {
4
- pageNum?: number;
5
- page_num?: number;
6
- pageSize?: number;
7
- page_size?: number;
8
- paginationMode?: string;
9
- pagination_mode?: string;
10
- pageToken?: string;
11
- page_token?: string;
12
- }
13
-
14
- export interface UnsPointHistoryOptions {
15
- startTime?: string;
16
- start_time?: string;
17
- endTime?: string;
18
- end_time?: string;
19
- page?: number;
20
- pageSize?: number;
21
- page_size?: number;
22
- }
23
-
24
- export interface UnsPointWriteOptions {
25
- reason: string;
26
- ticket: string;
27
- requestId?: string;
28
- request_id?: string;
29
- dryRun?: boolean;
30
- dry_run?: boolean;
31
- confirmed?: boolean;
32
- }
33
-
34
- export interface UnsVideoControlOptions {
35
- parameters?: UnsObject;
36
- confirmed: boolean;
37
- }
38
-
39
- export function getCurrentUnsSchema(): Promise<UnsObject>;
40
- export function getUnsSchema(version?: string): Promise<UnsObject>;
41
- export function listUnsSchemaBlocks(version?: string): Promise<UnsObject[]>;
42
- export function getUnsSchemaBlock(blockCode: string, options?: { version?: string; depth?: number }): Promise<UnsObject>;
43
- export function getUnsProtocolSchema(protocol: string, options?: { version?: string }): Promise<UnsObject>;
44
- export function discoverUnsResources(options?: { resourceTypes?: string[]; protocols?: string[] }): Promise<UnsObject>;
45
- export function searchUnsResources(
46
- resourceType: string,
47
- options?: { protocol?: string; keyword?: string; selector?: UnsObject; page?: number; pageSize?: number; page_size?: number },
48
- ): Promise<UnsObject>;
49
- export function listUnsBindings(): Promise<UnsObject[]>;
50
- export function resolveUnsPath(path: string): Promise<UnsObject>;
51
- export function validateUnsDocument(document: UnsObject): Promise<UnsObject>;
52
- export function planUnsDocument(document: UnsObject): Promise<UnsObject>;
53
- export function applyUnsDocument(
54
- document: UnsObject,
55
- options: {
56
- expectedDocumentHash?: string;
57
- expected_document_hash?: string;
58
- expectedPlanHash?: string;
59
- expected_plan_hash?: string;
60
- confirmed: boolean;
61
- },
62
- ): Promise<UnsObject>;
63
- export function queryUnsNodeData(nodeCode: string, options?: UnsDataQueryOptions): Promise<UnsObject>;
64
- export function writeUnsNodeData(
65
- nodeCode: string,
66
- fieldValues: UnsObject,
67
- options: { confirmed: boolean },
68
- ): Promise<UnsObject>;
69
- export function deleteUnsNodeData(nodeCode: string, rows: UnsObject[], options: { confirmed: boolean }): Promise<UnsObject>;
70
- export function queryUnsPathData(path: string, options?: UnsDataQueryOptions): Promise<UnsObject>;
71
- export function writeUnsPathData(path: string, fieldValues: UnsObject, options: { confirmed: boolean }): Promise<UnsObject>;
72
- export function deleteUnsPathData(path: string, rows: UnsObject[], options: { confirmed: boolean }): Promise<UnsObject>;
1
+ export type UnsObject = Record<string, unknown>;
2
+
3
+ export interface UnsDataQueryOptions {
4
+ pageNum?: number;
5
+ page_num?: number;
6
+ pageSize?: number;
7
+ page_size?: number;
8
+ paginationMode?: string;
9
+ pagination_mode?: string;
10
+ pageToken?: string;
11
+ page_token?: string;
12
+ }
13
+
14
+ export interface UnsPointHistoryOptions {
15
+ startTime?: string;
16
+ start_time?: string;
17
+ endTime?: string;
18
+ end_time?: string;
19
+ page?: number;
20
+ pageSize?: number;
21
+ page_size?: number;
22
+ }
23
+
24
+ export interface UnsPointWriteOptions {
25
+ reason: string;
26
+ ticket: string;
27
+ requestId?: string;
28
+ request_id?: string;
29
+ dryRun?: boolean;
30
+ dry_run?: boolean;
31
+ confirmed?: boolean;
32
+ }
33
+
34
+ export interface UnsVideoControlOptions {
35
+ parameters?: UnsObject;
36
+ confirmed: boolean;
37
+ }
38
+
39
+ export function getCurrentUnsSchema(): Promise<UnsObject>;
40
+ export function getUnsSchema(version?: string): Promise<UnsObject>;
41
+ export function listUnsSchemaBlocks(version?: string): Promise<UnsObject[]>;
42
+ export function getUnsSchemaBlock(blockCode: string, options?: { version?: string; depth?: number }): Promise<UnsObject>;
43
+ export function getUnsProtocolSchema(protocol: string, options?: { version?: string }): Promise<UnsObject>;
44
+ export function discoverUnsResources(options?: { resourceTypes?: string[]; protocols?: string[] }): Promise<UnsObject>;
45
+ export function searchUnsResources(
46
+ resourceType: string,
47
+ options?: { protocol?: string; keyword?: string; selector?: UnsObject; page?: number; pageSize?: number; page_size?: number },
48
+ ): Promise<UnsObject>;
49
+ export function listUnsBindings(): Promise<UnsObject[]>;
50
+ export function resolveUnsPath(path: string): Promise<UnsObject>;
51
+ export function validateUnsDocument(document: UnsObject): Promise<UnsObject>;
52
+ export function planUnsDocument(document: UnsObject): Promise<UnsObject>;
53
+ export function applyUnsDocument(
54
+ document: UnsObject,
55
+ options: {
56
+ expectedDocumentHash?: string;
57
+ expected_document_hash?: string;
58
+ expectedPlanHash?: string;
59
+ expected_plan_hash?: string;
60
+ confirmed: boolean;
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>;
77
+ export function queryUnsNodeData(nodeCode: string, options?: UnsDataQueryOptions): Promise<UnsObject>;
78
+ export function writeUnsNodeData(
79
+ nodeCode: string,
80
+ fieldValues: UnsObject,
81
+ options: { confirmed: boolean },
82
+ ): Promise<UnsObject>;
83
+ export function deleteUnsNodeData(nodeCode: string, rows: UnsObject[], options: { confirmed: boolean }): Promise<UnsObject>;
84
+ export function queryUnsPathData(path: string, options?: UnsDataQueryOptions): Promise<UnsObject>;
85
+ export function writeUnsPathData(path: string, fieldValues: UnsObject, options: { confirmed: boolean }): Promise<UnsObject>;
86
+ export function deleteUnsPathData(path: string, rows: UnsObject[], options: { confirmed: boolean }): Promise<UnsObject>;
73
87
  export function getUnsPointCurrent(nodeCode: string): Promise<UnsObject>;
74
88
  export function getUnsPathPointCurrent(path: string): Promise<UnsObject>;
89
+ export function getUnsPointRealtimeConfig(nodeCode: string): Promise<UnsObject>;
90
+ export function getUnsPathPointRealtimeConfig(path: string): Promise<UnsObject>;
75
91
  export function getUnsPointHistory(nodeCode: string, options: UnsPointHistoryOptions): Promise<UnsObject>;
76
- export function getUnsPathPointHistory(path: string, options: UnsPointHistoryOptions): Promise<UnsObject>;
77
- export function writeUnsPoint(nodeCode: string, value: unknown, options: UnsPointWriteOptions): Promise<UnsObject>;
78
- export function writeUnsPathPoint(path: string, value: unknown, options: UnsPointWriteOptions): Promise<UnsObject>;
79
- export function getUnsVideoStreamOptions(nodeCode: string): Promise<UnsObject>;
80
- export function getUnsPathVideoStreamOptions(path: string): Promise<UnsObject>;
81
- export function createUnsVideoSnapshot(nodeCode: string): Promise<UnsObject>;
82
- export function createUnsPathVideoSnapshot(path: string): Promise<UnsObject>;
83
- export function controlUnsVideo(nodeCode: string, action: string, options: UnsVideoControlOptions): Promise<UnsObject>;
84
- export function controlUnsPathVideo(path: string, action: string, options: UnsVideoControlOptions): Promise<UnsObject>;
85
-
86
- export class UnsPathNode {
87
- readonly path: string;
88
- constructor(path: string);
89
- resolve(): Promise<UnsObject>;
90
- queryData(options?: UnsDataQueryOptions): Promise<UnsObject>;
91
- writeData(fieldValues: UnsObject, options: { confirmed: boolean }): Promise<UnsObject>;
92
+ export function getUnsPathPointHistory(path: string, options: UnsPointHistoryOptions): Promise<UnsObject>;
93
+ export function writeUnsPoint(nodeCode: string, value: unknown, options: UnsPointWriteOptions): Promise<UnsObject>;
94
+ export function writeUnsPathPoint(path: string, value: unknown, options: UnsPointWriteOptions): Promise<UnsObject>;
95
+ export function getUnsVideoStreamOptions(nodeCode: string): Promise<UnsObject>;
96
+ export function getUnsPathVideoStreamOptions(path: string): Promise<UnsObject>;
97
+ export function createUnsVideoSnapshot(nodeCode: string): Promise<UnsObject>;
98
+ export function createUnsPathVideoSnapshot(path: string): Promise<UnsObject>;
99
+ export function controlUnsVideo(nodeCode: string, action: string, options: UnsVideoControlOptions): Promise<UnsObject>;
100
+ export function controlUnsPathVideo(path: string, action: string, options: UnsVideoControlOptions): Promise<UnsObject>;
101
+
102
+ export class UnsPathNode {
103
+ readonly path: string;
104
+ constructor(path: string);
105
+ resolve(): Promise<UnsObject>;
106
+ queryData(options?: UnsDataQueryOptions): Promise<UnsObject>;
107
+ writeData(fieldValues: UnsObject, options: { confirmed: boolean }): Promise<UnsObject>;
92
108
  deleteData(rows: UnsObject[], options: { confirmed: boolean }): Promise<UnsObject>;
93
109
  pointCurrent(): Promise<UnsObject>;
110
+ pointRealtimeConfig(): Promise<UnsObject>;
94
111
  pointHistory(options: UnsPointHistoryOptions): Promise<UnsObject>;
95
- writePoint(value: unknown, options: UnsPointWriteOptions): Promise<UnsObject>;
96
- videoStreamOptions(): Promise<UnsObject>;
97
- videoSnapshot(): Promise<UnsObject>;
98
- controlVideo(action: string, options: UnsVideoControlOptions): Promise<UnsObject>;
99
- }
100
-
101
- export function openUnsPath(path: string): UnsPathNode;
102
-
103
- export const uns: {
104
- schemaCurrent: typeof getCurrentUnsSchema;
105
- schema: typeof getUnsSchema;
106
- schemaBlocks: typeof listUnsSchemaBlocks;
107
- schemaBlock: typeof getUnsSchemaBlock;
108
- protocolSchema: typeof getUnsProtocolSchema;
109
- discover: typeof discoverUnsResources;
110
- searchResources: typeof searchUnsResources;
111
- bindings: typeof listUnsBindings;
112
- resolvePath: typeof resolveUnsPath;
113
- validate: typeof validateUnsDocument;
114
- plan: typeof planUnsDocument;
115
- apply: typeof applyUnsDocument;
116
- queryNodeData: typeof queryUnsNodeData;
117
- writeNodeData: typeof writeUnsNodeData;
118
- deleteNodeData: typeof deleteUnsNodeData;
119
- queryPathData: typeof queryUnsPathData;
120
- writePathData: typeof writeUnsPathData;
121
- deletePathData: typeof deleteUnsPathData;
112
+ writePoint(value: unknown, options: UnsPointWriteOptions): Promise<UnsObject>;
113
+ videoStreamOptions(): Promise<UnsObject>;
114
+ videoSnapshot(): Promise<UnsObject>;
115
+ controlVideo(action: string, options: UnsVideoControlOptions): Promise<UnsObject>;
116
+ }
117
+
118
+ export function openUnsPath(path: string): UnsPathNode;
119
+
120
+ export const uns: {
121
+ schemaCurrent: typeof getCurrentUnsSchema;
122
+ schema: typeof getUnsSchema;
123
+ schemaBlocks: typeof listUnsSchemaBlocks;
124
+ schemaBlock: typeof getUnsSchemaBlock;
125
+ protocolSchema: typeof getUnsProtocolSchema;
126
+ discover: typeof discoverUnsResources;
127
+ searchResources: typeof searchUnsResources;
128
+ bindings: typeof listUnsBindings;
129
+ resolvePath: typeof resolveUnsPath;
130
+ validate: typeof validateUnsDocument;
131
+ plan: typeof planUnsDocument;
132
+ apply: typeof applyUnsDocument;
133
+ validateChanges: typeof validateUnsChanges;
134
+ planChanges: typeof planUnsChanges;
135
+ applyChanges: typeof applyUnsChanges;
136
+ queryNodeData: typeof queryUnsNodeData;
137
+ writeNodeData: typeof writeUnsNodeData;
138
+ deleteNodeData: typeof deleteUnsNodeData;
139
+ queryPathData: typeof queryUnsPathData;
140
+ writePathData: typeof writeUnsPathData;
141
+ deletePathData: typeof deleteUnsPathData;
122
142
  pointCurrent: typeof getUnsPointCurrent;
123
143
  pathPointCurrent: typeof getUnsPathPointCurrent;
144
+ pointRealtimeConfig: typeof getUnsPointRealtimeConfig;
145
+ pathPointRealtimeConfig: typeof getUnsPathPointRealtimeConfig;
124
146
  pointHistory: typeof getUnsPointHistory;
125
- pathPointHistory: typeof getUnsPathPointHistory;
126
- writePoint: typeof writeUnsPoint;
127
- writePathPoint: typeof writeUnsPathPoint;
128
- videoStreamOptions: typeof getUnsVideoStreamOptions;
129
- pathVideoStreamOptions: typeof getUnsPathVideoStreamOptions;
130
- videoSnapshot: typeof createUnsVideoSnapshot;
131
- pathVideoSnapshot: typeof createUnsPathVideoSnapshot;
132
- controlVideo: typeof controlUnsVideo;
133
- controlPathVideo: typeof controlUnsPathVideo;
134
- openPath: typeof openUnsPath;
135
- };
147
+ pathPointHistory: typeof getUnsPathPointHistory;
148
+ writePoint: typeof writeUnsPoint;
149
+ writePathPoint: typeof writeUnsPathPoint;
150
+ videoStreamOptions: typeof getUnsVideoStreamOptions;
151
+ pathVideoStreamOptions: typeof getUnsPathVideoStreamOptions;
152
+ videoSnapshot: typeof createUnsVideoSnapshot;
153
+ pathVideoSnapshot: typeof createUnsPathVideoSnapshot;
154
+ controlVideo: typeof controlUnsVideo;
155
+ controlPathVideo: typeof controlUnsPathVideo;
156
+ openPath: typeof openUnsPath;
157
+ };
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 u(t,e){return new URL(`${t.baseUrl}/api/v1${e}`)}async function p(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(u(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 p(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})}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 y(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:y(e),config:n})}export async function getUnsPathPointHistory(t,e){const n=await o();return d("POST",c(n,"point/history",t),{body:y(e),config:n})}function l(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=l(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=l(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,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.4",
3
+ "version": "0.8.6",
4
4
  "description": "LICOS platform SDK package shell for browser and Node runtimes",
5
5
  "author": "kmlckj",
6
6
  "type": "module",