@kmlckj/licos-platform-sdk 0.6.8 → 0.6.9
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 +45 -45
- package/dist/index.d.ts +21 -0
- package/dist/index.js +1 -1
- package/dist/runtime.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,50 +17,50 @@ is resolved automatically by the runtime:
|
|
|
17
17
|
|
|
18
18
|
## Database
|
|
19
19
|
|
|
20
|
-
Database CRUD helpers call the runtime database data plane only. Tooling helpers
|
|
21
|
-
can fetch platform schema metadata for ORM export. The SDK does not expose
|
|
22
|
-
service deletion APIs.
|
|
23
|
-
|
|
24
|
-
`database.table(name)` is a query builder. Use it for `select` queries only.
|
|
25
|
-
|
|
26
|
-
```js
|
|
27
|
-
import { database } from '@kmlckj/licos-platform-sdk';
|
|
28
|
-
|
|
29
|
-
const rows = await database
|
|
20
|
+
Database CRUD helpers call the runtime database data plane only. Tooling helpers
|
|
21
|
+
can fetch platform schema metadata for ORM export. The SDK does not expose
|
|
22
|
+
service deletion APIs.
|
|
23
|
+
|
|
24
|
+
`database.table(name)` is a query builder. Use it for `select` queries only.
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
import { database } from '@kmlckj/licos-platform-sdk';
|
|
28
|
+
|
|
29
|
+
const rows = await database
|
|
30
30
|
.table('todos')
|
|
31
31
|
.select('id', 'title')
|
|
32
32
|
.eq('done', false)
|
|
33
33
|
.order('created_at', { desc: true })
|
|
34
|
-
.limit(10)
|
|
35
|
-
.execute();
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Use top-level helpers for mutations:
|
|
39
|
-
|
|
40
|
-
```js
|
|
41
|
-
import { database } from '@kmlckj/licos-platform-sdk';
|
|
42
|
-
|
|
43
|
-
const inserted = await database.insert('todos', {
|
|
44
|
-
row: { title: 'Call customer', done: false },
|
|
45
|
-
returning: true,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
await database.updateRows('todos', {
|
|
49
|
-
filters: [{ field: 'id', op: 'eq', value: inserted.data?.[0]?.id }],
|
|
50
|
-
values: { done: true },
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
await database.deleteRows('todos', {
|
|
54
|
-
filters: [{ field: 'done', op: 'eq', value: true }],
|
|
55
|
-
});
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
Do not call `.table('todos').insert(...)`, `.table('todos').updateRows(...)`,
|
|
59
|
-
or `.table('todos').deleteRows(...)`; those methods do not exist on the query
|
|
60
|
-
builder.
|
|
61
|
-
|
|
62
|
-
ORM export is a tooling helper. It fetches platform schema metadata and returns
|
|
63
|
-
source text; it does not use direct database credentials.
|
|
34
|
+
.limit(10)
|
|
35
|
+
.execute();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Use top-level helpers for mutations:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import { database } from '@kmlckj/licos-platform-sdk';
|
|
42
|
+
|
|
43
|
+
const inserted = await database.insert('todos', {
|
|
44
|
+
row: { title: 'Call customer', done: false },
|
|
45
|
+
returning: true,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
await database.updateRows('todos', {
|
|
49
|
+
filters: [{ field: 'id', op: 'eq', value: inserted.data?.[0]?.id }],
|
|
50
|
+
values: { done: true },
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
await database.deleteRows('todos', {
|
|
54
|
+
filters: [{ field: 'done', op: 'eq', value: true }],
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Do not call `.table('todos').insert(...)`, `.table('todos').updateRows(...)`,
|
|
59
|
+
or `.table('todos').deleteRows(...)`; those methods do not exist on the query
|
|
60
|
+
builder.
|
|
61
|
+
|
|
62
|
+
ORM export is a tooling helper. It fetches platform schema metadata and returns
|
|
63
|
+
source text; it does not use direct database credentials.
|
|
64
64
|
|
|
65
65
|
```js
|
|
66
66
|
import { database } from '@kmlckj/licos-platform-sdk';
|
|
@@ -68,11 +68,11 @@ import { database } from '@kmlckj/licos-platform-sdk';
|
|
|
68
68
|
const source = await database.exportOrm({ language: 'typescript', orm: 'drizzle' });
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
Studio project database management is exposed through `studioDatabase` for
|
|
72
|
-
server-side tooling flows. Use it for tables, rows, controlled SQL, migrations,
|
|
73
|
-
sync, and backup. Do not import it into browser/client bundles. Do not put
|
|
74
|
-
schema creation or migration logic in normal project runtime request handlers;
|
|
75
|
-
run those operations from LICOS agent/tooling flows before the app starts.
|
|
71
|
+
Studio project database management is exposed through `studioDatabase` for
|
|
72
|
+
server-side tooling flows. Use it for tables, rows, controlled SQL, migrations,
|
|
73
|
+
sync, and backup. Do not import it into browser/client bundles. Do not put
|
|
74
|
+
schema creation or migration logic in normal project runtime request handlers;
|
|
75
|
+
run those operations from LICOS agent/tooling flows before the app starts.
|
|
76
76
|
|
|
77
77
|
```js
|
|
78
78
|
import { studioDatabase } from '@kmlckj/licos-platform-sdk';
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,27 @@ export class PlatformSdkError extends Error {
|
|
|
7
7
|
export class ConfigurationError extends PlatformSdkError {}
|
|
8
8
|
export class ApiError extends PlatformSdkError {}
|
|
9
9
|
|
|
10
|
+
export interface RuntimeConfig {
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
projectId: string;
|
|
13
|
+
workspaceId?: string;
|
|
14
|
+
userId?: string;
|
|
15
|
+
token?: string;
|
|
16
|
+
environment: string;
|
|
17
|
+
ownerProjectId?: string;
|
|
18
|
+
ownerWorkspaceId?: string;
|
|
19
|
+
ownerOrgId?: string;
|
|
20
|
+
ownerUserId?: string;
|
|
21
|
+
ownerProjectType?: string;
|
|
22
|
+
ownerApplicationType?: string;
|
|
23
|
+
runtimeEnv?: string;
|
|
24
|
+
currentUserId?: string;
|
|
25
|
+
currentUserOrgId?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function runtimeConfig(options?: { environmentOverrideEnv?: string }): Promise<RuntimeConfig>;
|
|
29
|
+
export function authHeaders(config: RuntimeConfig, contentType?: string): Record<string, string>;
|
|
30
|
+
|
|
10
31
|
export const DataSourceType: {
|
|
11
32
|
TEXT: 0;
|
|
12
33
|
URL: 1;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{PlatformSdkError,ConfigurationError,ApiError}from"./shared.js";export*from"./database.js";export*from"./knowledge.js";export*from"./storage.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"./storage.js";export{studioDatabase}from"./studio-database.js";
|
package/dist/runtime.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ConfigurationError as e}from"./shared.js";const
|
|
1
|
+
import{ConfigurationError as e}from"./shared.js";const r=new Map;export function env(e){const r=process.env[e];if("string"!=typeof r)return;return r.trim()||void 0}function n(e,r,n){const t=env(e);if(t)return`http://${t}:${env(r)||n}`}export function platformBaseUrl(){const r=env("LICOS_PLATFORM_API_BASE_URL")||n("AIOS_PLATFORM_SERVICE_HOST","AIOS_PLATFORM_SERVICE_PORT","9100")||n("LICOS_PLATFORM_SERVICE_HOST","LICOS_PLATFORM_SERVICE_PORT","9100")||n("PLATFORM_SERVICE_HOST","PLATFORM_SERVICE_PORT","9100");if(!r)throw new e("LICOS_PLATFORM_API_BASE_URL is not configured");return function(e){let r=e.trim().replace(/\/+$/,"");return r.endsWith("/api/v1")&&(r=r.slice(0,-7)),r.replace(/\/+$/,"")}(r)}export function projectEnvironment(e){const r=((e?env(e):void 0)||"").toLowerCase();if("dev"===r||"prod"===r)return r;const n=(env("LICOS_PROJECT_ENV")||env("AGENT_ENV")||"").toLowerCase();return["prod","production","release"].includes(n)?"prod":"dev"}async function t(n,t,{forceRefresh:o=!1}={}){const s=String(t||"").trim();if(!s)throw new e("project owner user ID is not configured");const c=env("LICOS_AI_AGENT_TOKEN");if(!c)throw new e("platform runtime identity is unavailable");const i=`${n}\n${s}\n${c}`;if(r.has(i)){const e=r.get(i);if(!o)return e;if(e&&"function"==typeof e.then)return e}const I=fetch(`${n}/api/v1/internal/auth/ai-user-token`,{method:"POST",headers:{Authorization:`Bearer ${c}`,"Content-Type":"application/json"},body:JSON.stringify({userId:s})}).then(async n=>{const t=await n.text();let o=null;try{o=t?JSON.parse(t):null}catch(r){const o=new e("parse AI user token exchange response failed");throw o.status=n.status,o.details=t,o}if(!n.ok){const r=o?.message||t||`AI user token exchange returned ${n.status}`,s=new e(r);throw s.status=n.status,s.details=o,s}const s=function(r){if(!r||"object"!=typeof r)throw new e("AI user token exchange response is not an object");if(void 0!==r.code&&0!==r.code||!1===r.success){const n=new e(r.message||"AI user token exchange failed");throw n.code="number"==typeof r.code?r.code:void 0,n.details=r,n}const n=r.data,t="string"==typeof n?n.trim():String(n?.accessToken||n?.access_token||n?.token||"").trim();if(!t){const n=new e("AI user token exchange response missing accessToken");throw n.details=r,n}return t}(o);return r.set(i,s),s});r.set(i,I);try{return await I}catch(e){throw r.delete(i),e}}export function clearTokenCacheForTests(){r.clear()}export function shouldRefreshUserToken(e){return 401===e?.status||10002===e?.code}export async function refreshRuntimeConfig(e){return{...e,token:await t(e.baseUrl,e.userId,{forceRefresh:!0})}}export async function runtimeConfig({environmentOverrideEnv:r}={}){const n=env("LICOS_OWNER_PROJECT_ID"),o=env("LICOS_OWNER_WORKSPACE_ID"),s=env("LICOS_OWNER_USER_ID"),c=env("LICOS_PROJECT_ID")||n||env("AGENT_PROJECT_ID");if(!c)throw new e("LICOS_PROJECT_ID or AGENT_PROJECT_ID is not configured");const i=platformBaseUrl(),I=env("LICOS_USER_ID")||s||env("AGENT_USER_ID"),a=await t(i,I);return{baseUrl:i,projectId:c,environment:projectEnvironment(r),token:a,workspaceId:env("LICOS_WORKSPACE_ID")||o||env("AGENT_WORKSPACE_ID"),userId:I,ownerProjectId:n||c,ownerWorkspaceId:o,ownerOrgId:env("LICOS_OWNER_ORG_ID"),ownerUserId:s||I,ownerProjectType:env("LICOS_OWNER_PROJECT_TYPE"),ownerApplicationType:env("LICOS_OWNER_APPLICATION_TYPE"),runtimeEnv:env("LICOS_RUNTIME_ENV"),currentUserId:env("LICOS_CURRENT_USER_ID"),currentUserOrgId:env("LICOS_CURRENT_USER_ORG_ID")}}export function authHeaders(e,r="application/json"){const n={Authorization:`Bearer ${e.token}`};return r&&(n["Content-Type"]=r),e.workspaceId&&(n["X-Workspace-Id"]=e.workspaceId),e.userId&&(n["X-User-Id"]=e.userId),o(n,"X-Licos-Current-User-Id",e.currentUserId),o(n,"X-Licos-Current-Org-Id",e.currentUserOrgId),o(n,"current_user_id",e.currentUserId),o(n,"current_user_org_id",e.currentUserOrgId),o(n,"X-Licos-Runtime-Env",e.runtimeEnv),o(n,"X-Runtime-Env",e.runtimeEnv),o(n,"runtime_env",e.runtimeEnv),o(n,"owner_project_type",e.ownerProjectType),o(n,"owner_application_type",e.ownerApplicationType),e.ownerProjectId&&(o(n,"X-Licos-Owner-Project-Id",e.ownerProjectId),o(n,"X-Licos-Owner-Workspace-Id",e.ownerWorkspaceId),o(n,"X-Licos-Owner-Org-Id",e.ownerOrgId),o(n,"X-Licos-Owner-User-Id",e.ownerUserId),o(n,"owner_project_id",e.ownerProjectId),o(n,"owner_workspace_id",e.ownerWorkspaceId),o(n,"owner_org_id",e.ownerOrgId),o(n,"owner_user_id",e.ownerUserId),o(n,"X-Project-Id",e.ownerProjectId),o(n,"X-Workspace-Id",e.ownerWorkspaceId),o(n,"X-Tenant-Id",e.ownerOrgId),o(n,"X-User-Id",e.ownerUserId)),n}function o(e,r,n){if("string"!=typeof n)return;const t=n.trim();t&&(e[r]=t)}
|