@kmlckj/licos-platform-sdk 0.8.4 → 0.8.5

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,58 @@ 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
-
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
139
  await uns.apply(document, {
140
- expectedDocumentHash: reviewedPlan.documentHash,
141
- expectedPlanHash: reviewedPlan.planHash,
142
- confirmed: true,
140
+ expectedDocumentHash: reviewedPlan.documentHash,
141
+ expectedPlanHash: reviewedPlan.planHash,
142
+ confirmed: true,
143
143
  });
144
144
  ```
145
145
 
146
- Use `uns.openPath(path)` when business code targets an existing enterprise UNS
147
- path without creating or changing `UNS.json`:
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`.
148
149
 
149
150
  ```js
150
- const temperature = uns.openPath('project:/production-line/temperature');
151
- const current = await temperature.pointCurrent();
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
+ });
152
158
  ```
153
-
154
- 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
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();
166
+ ```
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.
172
+
173
+ ## OAuth2 Application Management
160
174
 
161
175
  OAuth2 management is available only from trusted Node runtime code. It uses the
162
176
  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,56 +1,68 @@
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>;
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
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(
54
66
  document: UnsObject,
55
67
  options: {
56
68
  expectedDocumentHash?: string;
@@ -58,78 +70,83 @@ export function applyUnsDocument(
58
70
  expectedPlanHash?: string;
59
71
  expected_plan_hash?: string;
60
72
  confirmed: boolean;
73
+ impactConfirmed?: boolean;
74
+ impact_confirmed?: boolean;
61
75
  },
62
76
  ): 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>;
73
- export function getUnsPointCurrent(nodeCode: string): Promise<UnsObject>;
74
- export function getUnsPathPointCurrent(path: string): Promise<UnsObject>;
75
- 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
- deleteData(rows: UnsObject[], options: { confirmed: boolean }): Promise<UnsObject>;
93
- pointCurrent(): Promise<UnsObject>;
94
- 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;
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>;
87
+ export function getUnsPointCurrent(nodeCode: string): Promise<UnsObject>;
88
+ export function getUnsPathPointCurrent(path: string): Promise<UnsObject>;
89
+ export function getUnsPointHistory(nodeCode: string, options: UnsPointHistoryOptions): Promise<UnsObject>;
90
+ export function getUnsPathPointHistory(path: string, options: UnsPointHistoryOptions): Promise<UnsObject>;
91
+ export function writeUnsPoint(nodeCode: string, value: unknown, options: UnsPointWriteOptions): Promise<UnsObject>;
92
+ export function writeUnsPathPoint(path: string, value: unknown, options: UnsPointWriteOptions): Promise<UnsObject>;
93
+ export function getUnsVideoStreamOptions(nodeCode: string): Promise<UnsObject>;
94
+ export function getUnsPathVideoStreamOptions(path: string): Promise<UnsObject>;
95
+ export function createUnsVideoSnapshot(nodeCode: string): Promise<UnsObject>;
96
+ export function createUnsPathVideoSnapshot(path: string): Promise<UnsObject>;
97
+ export function controlUnsVideo(nodeCode: string, action: string, options: UnsVideoControlOptions): Promise<UnsObject>;
98
+ export function controlUnsPathVideo(path: string, action: string, options: UnsVideoControlOptions): Promise<UnsObject>;
99
+
100
+ export class UnsPathNode {
101
+ readonly path: string;
102
+ constructor(path: string);
103
+ resolve(): Promise<UnsObject>;
104
+ queryData(options?: UnsDataQueryOptions): Promise<UnsObject>;
105
+ writeData(fieldValues: UnsObject, options: { confirmed: boolean }): Promise<UnsObject>;
106
+ deleteData(rows: UnsObject[], options: { confirmed: boolean }): Promise<UnsObject>;
107
+ pointCurrent(): Promise<UnsObject>;
108
+ pointHistory(options: UnsPointHistoryOptions): Promise<UnsObject>;
109
+ writePoint(value: unknown, options: UnsPointWriteOptions): Promise<UnsObject>;
110
+ videoStreamOptions(): Promise<UnsObject>;
111
+ videoSnapshot(): Promise<UnsObject>;
112
+ controlVideo(action: string, options: UnsVideoControlOptions): Promise<UnsObject>;
113
+ }
114
+
115
+ export function openUnsPath(path: string): UnsPathNode;
116
+
117
+ export const uns: {
118
+ schemaCurrent: typeof getCurrentUnsSchema;
119
+ schema: typeof getUnsSchema;
120
+ schemaBlocks: typeof listUnsSchemaBlocks;
121
+ schemaBlock: typeof getUnsSchemaBlock;
122
+ protocolSchema: typeof getUnsProtocolSchema;
123
+ discover: typeof discoverUnsResources;
124
+ searchResources: typeof searchUnsResources;
125
+ bindings: typeof listUnsBindings;
126
+ resolvePath: typeof resolveUnsPath;
113
127
  validate: typeof validateUnsDocument;
114
128
  plan: typeof planUnsDocument;
115
129
  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;
122
- pointCurrent: typeof getUnsPointCurrent;
123
- pathPointCurrent: typeof getUnsPathPointCurrent;
124
- 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
- };
130
+ validateChanges: typeof validateUnsChanges;
131
+ planChanges: typeof planUnsChanges;
132
+ applyChanges: typeof applyUnsChanges;
133
+ queryNodeData: typeof queryUnsNodeData;
134
+ writeNodeData: typeof writeUnsNodeData;
135
+ deleteNodeData: typeof deleteUnsNodeData;
136
+ queryPathData: typeof queryUnsPathData;
137
+ writePathData: typeof writeUnsPathData;
138
+ deletePathData: typeof deleteUnsPathData;
139
+ pointCurrent: typeof getUnsPointCurrent;
140
+ pathPointCurrent: typeof getUnsPathPointCurrent;
141
+ pointHistory: typeof getUnsPointHistory;
142
+ pathPointHistory: typeof getUnsPathPointHistory;
143
+ writePoint: typeof writeUnsPoint;
144
+ writePathPoint: typeof writeUnsPathPoint;
145
+ videoStreamOptions: typeof getUnsVideoStreamOptions;
146
+ pathVideoStreamOptions: typeof getUnsPathVideoStreamOptions;
147
+ videoSnapshot: typeof createUnsVideoSnapshot;
148
+ pathVideoSnapshot: typeof createUnsPathVideoSnapshot;
149
+ controlVideo: typeof controlUnsVideo;
150
+ controlPathVideo: typeof controlUnsPathVideo;
151
+ openPath: typeof openUnsPath;
152
+ };
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})}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};
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.5",
4
4
  "description": "LICOS platform SDK package shell for browser and Node runtimes",
5
5
  "author": "kmlckj",
6
6
  "type": "module",