@kmlckj/licos-platform-sdk 0.6.4 → 0.6.7
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 +53 -15
- package/dist/browser.js +1 -0
- package/dist/database.js +1 -0
- package/dist/index.d.ts +531 -0
- package/dist/index.js +1 -0
- package/dist/knowledge.js +1 -0
- package/dist/runtime.js +1 -0
- package/dist/shared.js +1 -0
- package/dist/storage.js +1 -0
- package/dist/studio-database.js +1 -0
- package/package.json +42 -37
- package/src/browser.js +0 -1
- package/src/database.js +0 -688
- package/src/index.d.ts +0 -251
- package/src/index.js +0 -3
- package/src/runtime.js +0 -70
- package/src/shared.js +0 -12
- package/src/storage.js +0 -167
- /package/{src → dist}/browser.d.ts +0 -0
package/dist/runtime.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ConfigurationError as e}from"./shared.js";const t=new Map;export function env(e){const t=process.env[e];if("string"!=typeof t)return;return t.trim()||void 0}function n(e,t,n){const r=env(e);if(r)return`http://${r}:${env(t)||n}`}export function platformBaseUrl(){const t=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(!t)throw new e("LICOS_PLATFORM_API_BASE_URL is not configured");return function(e){let t=e.trim().replace(/\/+$/,"");return t.endsWith("/api/v1")&&(t=t.slice(0,-7)),t.replace(/\/+$/,"")}(t)}export function projectEnvironment(e){const t=((e?env(e):void 0)||"").toLowerCase();if("dev"===t||"prod"===t)return t;const n=(env("LICOS_PROJECT_ENV")||env("AGENT_ENV")||"").toLowerCase();return["prod","production","release"].includes(n)?"prod":"dev"}async function r(n,r,{forceRefresh:o=!1}={}){const s=String(r||"").trim();if(!s)throw new e("project owner user ID is not configured");const i=env("LICOS_AI_AGENT_TOKEN");if(!i)throw new e("platform runtime identity is unavailable");const c=`${n}\n${s}\n${i}`;if(t.has(c)){const e=t.get(c);if(!o)return e;if(e&&"function"==typeof e.then)return e}const a=fetch(`${n}/api/v1/internal/auth/ai-user-token`,{method:"POST",headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json"},body:JSON.stringify({userId:s})}).then(async n=>{const r=await n.text();let o=null;try{o=r?JSON.parse(r):null}catch(t){const o=new e("parse AI user token exchange response failed");throw o.status=n.status,o.details=r,o}if(!n.ok){const t=o?.message||r||`AI user token exchange returned ${n.status}`,s=new e(t);throw s.status=n.status,s.details=o,s}const s=function(t){if(!t||"object"!=typeof t)throw new e("AI user token exchange response is not an object");if(void 0!==t.code&&0!==t.code||!1===t.success){const n=new e(t.message||"AI user token exchange failed");throw n.code="number"==typeof t.code?t.code:void 0,n.details=t,n}const n=t.data,r="string"==typeof n?n.trim():String(n?.accessToken||n?.access_token||n?.token||"").trim();if(!r){const n=new e("AI user token exchange response missing accessToken");throw n.details=t,n}return r}(o);return t.set(c,s),s});t.set(c,a);try{return await a}catch(e){throw t.delete(c),e}}export function clearTokenCacheForTests(){t.clear()}export function shouldRefreshUserToken(e){return 401===e?.status||10002===e?.code}export async function refreshRuntimeConfig(e){return{...e,token:await r(e.baseUrl,e.userId,{forceRefresh:!0})}}export async function runtimeConfig({environmentOverrideEnv:t}={}){const n=env("LICOS_PROJECT_ID")||env("AGENT_PROJECT_ID");if(!n)throw new e("LICOS_PROJECT_ID or AGENT_PROJECT_ID is not configured");const o=platformBaseUrl(),s=env("LICOS_USER_ID")||env("AGENT_USER_ID"),i=await r(o,s);return{baseUrl:o,projectId:n,environment:projectEnvironment(t),token:i,workspaceId:env("LICOS_WORKSPACE_ID")||env("AGENT_WORKSPACE_ID"),userId:s}}export function authHeaders(e,t="application/json"){const n={Authorization:`Bearer ${e.token}`};return t&&(n["Content-Type"]=t),e.workspaceId&&(n["X-Workspace-Id"]=e.workspaceId),e.userId&&(n["X-User-Id"]=e.userId),n}
|
package/dist/shared.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class PlatformSdkError extends Error{constructor(r,t={}){super(r),this.name=new.target.name,this.status=t.status,this.code=t.code,this.details=t.details}}export class ConfigurationError extends PlatformSdkError{}export class ApiError extends PlatformSdkError{}
|
package/dist/storage.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readFile as e,stat as t}from"node:fs/promises";import o from"node:path";import{ApiError as r}from"./shared.js";import{authHeaders as n,refreshRuntimeConfig as i,runtimeConfig as a,shouldRefreshUserToken as s}from"./runtime.js";export const MAX_UPLOAD_FILE_BYTES=20971520;async function l(){return a({environmentOverrideEnv:"LICOS_STORAGE_SCOPE"})}function d(e,t,o){return`${e.baseUrl}/api/v1/studio/storage${t}?${function(e,t={}){const o=new URLSearchParams;o.set("projectId",e.projectId),o.set("scope",e.environment);for(const[e,r]of Object.entries(t))null!=r&&o.set(e,String(r));return o.toString()}(e,o)}`}async function c(e){const t=await e.text(),o=t?JSON.parse(t):null;if(!e.ok)throw new r(t||`platform storage API returned ${e.status}`,{status:e.status,details:o});if(!o||"object"!=typeof o)return o;if(void 0!==o.code&&0!==o.code||!1===o.success)throw new r(o.message||"platform storage API failed",{status:e.status,code:"number"==typeof o.code?o.code:void 0,details:o});return o.data}async function f(e,t,{params:o,body:a}={}){let f=await l();for(let r=0;r<2;r+=1)try{const r=await fetch(d(f,t,o),{method:e,headers:n(f),body:void 0===a?void 0:JSON.stringify(a)});return await c(r)}catch(e){if(0===r&&s(e)){f=await i(f);continue}throw e}throw new r("platform storage API failed")}function u(e){if(e>20971520)throw new RangeError("uploadFile input exceeds max size of 20971520 bytes")}export async function summary(){return f("GET","/summary")}export async function listFolders(){return await f("GET","/folders")||[]}export async function listEntries({folderId:e}={}){return f("GET","/entries",{params:{folderId:e}})}export async function listFiles(){return await f("GET","/files")||[]}export async function createFolder(e,{parentId:t}={}){return f("POST","/folders",{body:{folderName:e,parentId:t}})}export async function renameFolder(e,t){return f("PUT",`/folders/${encodeURIComponent(e)}`,{body:{folderName:t}})}export async function deleteFolder(e){await f("DELETE",`/folders/${encodeURIComponent(e)}`)}export async function uploadFile(a,d={}){const{blob:f,fileName:p}=await async function(r,n={}){if("string"==typeof r){u((await t(r)).size);const i=await e(r);return{blob:new Blob([i],{type:n.contentType||"application/octet-stream"}),fileName:n.fileName||o.basename(r)}}if(r instanceof Blob)return u(r.size),{blob:r,fileName:n.fileName||"file"};if(r instanceof Uint8Array||Buffer.isBuffer(r))return u(r.byteLength),{blob:new Blob([r],{type:n.contentType||"application/octet-stream"}),fileName:n.fileName||"file"};throw new TypeError("uploadFile input must be a file path, Blob, Buffer, or Uint8Array")}(a,d);let m=await l();for(let e=0;e<2;e+=1){const t=new FormData;t.set("projectId",m.projectId),t.set("scope",m.environment),d.folderId&&t.set("folderId",d.folderId),t.set("file",f,p);try{const e=await fetch(`${m.baseUrl}/api/v1/studio/storage/files/upload`,{method:"POST",headers:n(m,void 0),body:t});return await c(e)}catch(t){if(0===e&&s(t)){m=await i(m);continue}throw t}}throw new r("platform storage upload failed")}export async function renameFile(e,t){return f("PUT",`/files/${encodeURIComponent(e)}/rename`,{body:{fileName:t}})}export async function moveFile(e,{folderId:t}={}){return f("PUT",`/files/${encodeURIComponent(e)}/move`,{body:{folderId:t}})}export async function shareUrl(e,{expirySeconds:t}={}){return f("POST",`/files/${encodeURIComponent(e)}/share-url`,{body:{expirySeconds:t}})}export async function objectExists({fileId:e,objectKey:t}={}){return f("POST","/objects/exists",{body:{fileId:e,objectKey:t}})}export async function deleteFile(e){await f("DELETE",`/files/${encodeURIComponent(e)}`)}export const storage={summary:summary,listFolders:listFolders,listEntries:listEntries,listFiles:listFiles,createFolder:createFolder,renameFolder:renameFolder,deleteFolder:deleteFolder,uploadFile:uploadFile,renameFile:renameFile,moveFile:moveFile,shareUrl:shareUrl,objectExists:objectExists,deleteFile:deleteFile};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ApiError as e}from"./shared.js";import{authHeaders as t,refreshRuntimeConfig as a,runtimeConfig as n,shouldRefreshUserToken as r}from"./runtime.js";async function o(){return n({environmentOverrideEnv:"LICOS_STUDIO_DATABASE_SCOPE"})}function s(e,t){const a=String(t||e.environment||"dev").toLowerCase();return["prod","production","release"].includes(a)?"prod":"dev"}function c(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>null!=e))}async function i(t){const a=await t.text(),n=a?JSON.parse(a):null;if(!t.ok)throw new e(a||`platform Studio database API returned ${t.status}`,{status:t.status,details:n});if(!n||"object"!=typeof n)return n;if(void 0!==n.code&&0!==n.code||!1===n.success)throw new e(n.message||"platform Studio database API failed",{status:t.status,code:"number"==typeof n.code?n.code:void 0,details:n});return n.data}async function u(n,s,{body:u}={}){let p=await o();for(let e=0;e<2;e+=1)try{const e=void 0!==u,a=await fetch(s(p),{method:n,headers:t(p,e?"application/json":void 0),body:e?JSON.stringify(c(u)):void 0});return await i(a)}catch(t){if(0===e&&r(t)){p=await a(p);continue}throw t}throw new e("platform Studio database API failed")}async function p(e,t={}){return{envScope:s(await o(),e),...t}}function d(e,t,{params:a,body:n}={}){return u(e,e=>function(e,t,a={}){const n=function(e,t={}){const a=new URLSearchParams;a.set("projectId",e.projectId);for(const[e,n]of Object.entries(c(t)))if(Array.isArray(n))for(const t of n)a.append(e,String(t));else a.set(e,String(n));return a.toString()}(e,a);return`${e.baseUrl}/api/v1/studio/databases${t}${n?`?${n}`:""}`}(e,t,a),{body:n})}function l(e,t,{params:a,body:n}={}){return u(e,e=>function(e,t,a={}){const n=new URLSearchParams;for(const[e,t]of Object.entries(c(a)))n.set(e,String(t));const r=n.toString();return`${e.baseUrl}/api/v1/studio/control/database/projects/${encodeURIComponent(e.projectId)}${t}${r?`?${r}`:""}`}(e,t,a),{body:n})}export async function getDatabase(e={}){return d("GET","/dev",{params:await p(e.envScope)})}export async function createDefaultDatabase(e={}){return d("POST","/dev/default",{params:await p(e.envScope)})}export async function deleteDatabase(e={}){await d("DELETE","/dev",{params:await p(e.envScope)})}export async function listTables(e={}){return await d("GET","/dev/tables",{params:await p(e.envScope,{keyword:e.keyword})})||[]}export async function createTable(e,t={}){return d("POST","/dev/tables",{params:await p(t.envScope),body:{tableName:e,description:t.description,columns:t.columns||[]}})}export async function updateTable(e,t={}){return d("PUT","/dev/tables",{params:await p(t.envScope,{tableName:e,schema:t.schema}),body:{tableName:t.newTableName,description:t.description,columns:t.columns}})}export async function deleteTable(e,t={}){await d("POST","/dev/tables/delete",{params:await p(t.envScope,{tableName:e,schema:t.schema})})}export async function addColumn(e,t={}){return d("POST","/dev/tables/columns",{params:await p(t.envScope,{tableName:e,schema:t.schema}),body:{name:t.name,type:t.type,description:t.description,defaultValue:t.defaultValue,array:t.array,primaryKey:t.primaryKey,nullable:t.nullable,unique:t.unique,checkExpression:t.checkExpression}})}export async function getTableData(e,t={}){return d("GET","/dev/tables/data",{params:await p(t.envScope,{tableName:e,schema:t.schema})})}export async function insertRow(e,t,a={}){return d("POST","/dev/tables/rows",{params:await p(a.envScope,{tableName:e,schema:a.schema}),body:{values:t}})}export async function updateRow(e,t,a={}){return d("POST","/dev/tables/rows/update",{params:await p(a.envScope,{tableName:e,schema:a.schema}),body:{rowId:a.rowId,rowIndex:a.rowIndex,values:t}})}export async function deleteRows(e,t={}){return d("POST","/dev/tables/rows/delete",{params:await p(t.envScope,{tableName:e,schema:t.schema}),body:{rowIds:t.rowIds,rowIndexes:t.rowIndexes}})}export async function executeSql(e,t={}){return d("POST","/dev/sql/execute",{params:await p(t.envScope),body:{sqlText:e}})}export async function sqlHistory(e={}){return await d("GET","/dev/sql/history",{params:await p(e.envScope)})||[]}export async function exportBackup(e={}){return d("GET","/backup/export",{params:await p(e.envScope||"prod")})}export async function importBackup(e,t={}){return d("POST","/backup/import",{params:await p(t.envScope||"prod"),body:e})}export async function sync(e={}){return d("POST","/sync",{body:{sourceScope:e.sourceScope||"dev",targetScope:e.targetScope||"prod",tables:e.tables||[],source_project_id:e.sourceProjectId,target_project_id:e.targetProjectId}})}export async function syncProject(e,t,a={}){return d("POST","/sync_project",{body:{sourceScope:a.sourceScope||"dev",targetScope:a.targetScope||"prod",tables:a.tables||[],source_project_id:e,target_project_id:t}})}export async function ensureDatabase(e={}){return l("POST","/ensure",{params:{environment:e.environment}})}export async function getSchema(e={}){return l("GET","/schema",{params:{environment:e.environment}})}export async function getConfig(e={}){return l("GET","/config",{params:{environment:e.environment}})}export async function controlSql(e,t={}){return l("POST","/sql",{params:{environment:t.environment},body:{sqlText:e}})}export async function explainSql(e,t={}){return l("POST","/sql/explain",{params:{environment:t.environment},body:{sqlText:e}})}export async function validateSchema(e,t={}){return l("POST","/schema/validate",{body:{environment:t.environment,schema:e}})}export async function diffSchema(e,t={}){return l("POST","/schema/diff",{body:{environment:t.environment,schema:e}})}export async function listMigrations(e={}){return await l("GET","/migrations",{params:{environment:e.environment}})||[]}export async function createMigration(e={}){return l("POST","/migrations",{body:{environment:e.environment,dryRun:e.dryRun??!0,title:e.title,statements:e.statements||[],schema:e.schema}})}export async function getMigration(e){return l("GET",`/migrations/${encodeURIComponent(e)}`)}export const studioDatabase={getDatabase:getDatabase,createDefaultDatabase:createDefaultDatabase,deleteDatabase:deleteDatabase,listTables:listTables,createTable:createTable,updateTable:updateTable,deleteTable:deleteTable,addColumn:addColumn,getTableData:getTableData,insertRow:insertRow,updateRow:updateRow,deleteRows:deleteRows,executeSql:executeSql,sqlHistory:sqlHistory,exportBackup:exportBackup,importBackup:importBackup,sync:sync,syncProject:syncProject,ensureDatabase:ensureDatabase,getSchema:getSchema,getConfig:getConfig,controlSql:controlSql,explainSql:explainSql,validateSchema:validateSchema,diffSchema:diffSchema,listMigrations:listMigrations,createMigration:createMigration,getMigration:getMigration};
|
package/package.json
CHANGED
|
@@ -1,43 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kmlckj/licos-platform-sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"description": "LICOS platform SDK package shell for browser and Node runtimes",
|
|
5
|
-
"author": "kmlckj",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"main": "./
|
|
8
|
-
"browser": "./
|
|
9
|
-
"types": "./
|
|
10
|
-
"typesVersions": {
|
|
11
|
-
"*": {
|
|
12
|
-
"browser": [
|
|
13
|
-
"
|
|
14
|
-
]
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
"exports": {
|
|
18
|
-
".": {
|
|
19
|
-
"browser": {
|
|
20
|
-
"types": "./
|
|
21
|
-
"default": "./
|
|
22
|
-
},
|
|
23
|
-
"types": "./
|
|
24
|
-
"import": "./
|
|
25
|
-
"default": "./
|
|
26
|
-
},
|
|
27
|
-
"./browser": {
|
|
28
|
-
"types": "./
|
|
29
|
-
"import": "./
|
|
30
|
-
"default": "./
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"files": [
|
|
34
|
-
"
|
|
35
|
-
"README.md"
|
|
36
|
-
],
|
|
37
|
-
"scripts": {
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
5
|
+
"author": "kmlckj",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"browser": "./dist/browser.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"typesVersions": {
|
|
11
|
+
"*": {
|
|
12
|
+
"browser": [
|
|
13
|
+
"dist/browser.d.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"browser": {
|
|
20
|
+
"types": "./dist/browser.d.ts",
|
|
21
|
+
"default": "./dist/browser.js"
|
|
22
|
+
},
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./browser": {
|
|
28
|
+
"types": "./dist/browser.d.ts",
|
|
29
|
+
"import": "./dist/browser.js",
|
|
30
|
+
"default": "./dist/browser.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"README.md"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "node build.mjs",
|
|
39
|
+
"prepack": "npm run build",
|
|
40
|
+
"test": "node --test"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"terser": "5.48.0"
|
|
44
|
+
},
|
|
45
|
+
"license": "MIT",
|
|
41
46
|
"publishConfig": {
|
|
42
47
|
"access": "public",
|
|
43
48
|
"registry": "https://registry.npmjs.org"
|
package/src/browser.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { PlatformSdkError, ConfigurationError, ApiError } from './shared.js';
|