@kmlckj/licos-platform-sdk 0.8.1 → 0.8.2

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
@@ -94,7 +94,7 @@ const file = await storage.uploadFile('/tmp/report.pdf');
94
94
  const link = await storage.shareUrl(file.id);
95
95
  ```
96
96
 
97
- `uploadFile` limits each file to 20 MiB.
97
+ `uploadFile` limits each file to 100 MiB. Payloads larger than 8 MiB automatically use the platform chunk-upload protocol.
98
98
 
99
99
  The browser entry does not export object storage helpers because runtime tokens
100
100
  must not be bundled into public frontend code.
package/dist/index.d.ts CHANGED
@@ -115,19 +115,19 @@ export class OAuthProtocolError extends ApiError {
115
115
  error?: string;
116
116
  }
117
117
 
118
- export interface OAuthRuntimeConfig {
119
- clientId: string;
120
- publicBaseUrl: string;
121
- scopes: readonly string[];
122
- redirectUriConfigs: readonly OAuthRedirectUriConfig[];
123
- redirectUris: readonly string[];
118
+ export interface OAuthRuntimeConfig {
119
+ clientId: string;
120
+ publicBaseUrl: string;
121
+ scopes: readonly string[];
122
+ redirectUriConfigs: readonly OAuthRedirectUriConfig[];
123
+ redirectUris: readonly string[];
124
124
  endpoints: Readonly<Record<string, string>>;
125
125
  appId?: string;
126
126
  appCode?: string;
127
127
  loginAudience?: OAuthLoginAudience;
128
- }
129
-
130
- export function oauthRedirectUriForEnvironment(config: OAuthRuntimeConfig, environment: string): string;
128
+ }
129
+
130
+ export function oauthRedirectUriForEnvironment(config: OAuthRuntimeConfig, environment: string): string;
131
131
 
132
132
  export interface OAuthAuthorizationRequest {
133
133
  authorizationUrl: string;
@@ -180,9 +180,9 @@ export function completeOAuthAuthorization(
180
180
  options: { code: string; redirectUri: string; codeVerifier: string },
181
181
  ): Promise<{ tokens: OAuthTokenResponse; user: Record<string, unknown> }>;
182
182
 
183
- export const oauthRuntime: {
184
- loadConfig: typeof loadOAuthRuntimeConfig;
185
- redirectUriForEnvironment: typeof oauthRedirectUriForEnvironment;
183
+ export const oauthRuntime: {
184
+ loadConfig: typeof loadOAuthRuntimeConfig;
185
+ redirectUriForEnvironment: typeof oauthRedirectUriForEnvironment;
186
186
  createAuthorizationRequest: typeof createOAuthAuthorizationRequest;
187
187
  exchangeAuthorizationCode: typeof exchangeOAuthAuthorizationCode;
188
188
  refreshAccessToken: typeof refreshOAuthAccessToken;
package/dist/storage.js CHANGED
@@ -1 +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};
1
+ import{createReadStream as e}from"node:fs";import{readFile as t,stat as o}from"node:fs/promises";import n from"node:path";import{ApiError as r}from"./shared.js";import{authHeaders as a,refreshRuntimeConfig as i,runtimeConfig as s,shouldRefreshUserToken as l}from"./runtime.js";export const MAX_UPLOAD_FILE_BYTES=104857600;export const DIRECT_UPLOAD_THRESHOLD_BYTES=8388608;async function c(){return s({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,n]of Object.entries(t))null!=n&&o.set(e,String(n));return o.toString()}(e,o)}`}async function f(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 u(e,t,{params:o,body:n}={}){let s=await c();for(let r=0;r<2;r+=1)try{const r=await fetch(d(s,t,o),{method:e,headers:a(s),body:void 0===n?void 0:JSON.stringify(n)});return await f(r)}catch(e){if(0===r&&l(e)){s=await i(s);continue}throw e}throw new r("platform storage API failed")}function p(e){if(e>104857600)throw new RangeError("uploadFile input exceeds max size of 104857600 bytes")}export async function summary(){return u("GET","/summary")}export async function listFolders(){return await u("GET","/folders")||[]}export async function listEntries({folderId:e}={}){return u("GET","/entries",{params:{folderId:e}})}export async function listFiles(){return await u("GET","/files")||[]}export async function createFolder(e,{parentId:t}={}){return u("POST","/folders",{body:{folderName:e,parentId:t}})}export async function renameFolder(e,t){return u("PUT",`/folders/${encodeURIComponent(e)}`,{body:{folderName:t}})}export async function deleteFolder(e){await u("DELETE",`/folders/${encodeURIComponent(e)}`)}export async function uploadFile(s,d={}){const y=await async function(r,a={}){if("string"==typeof r){const i=await o(r);return p(i.size),{size:i.size,fileName:a.fileName||n.basename(r),contentType:a.contentType||"application/octet-stream",readAll:async()=>t(r),chunks:t=>e(r,{highWaterMark:t})}}if(r instanceof Blob)return p(r.size),{size:r.size,fileName:a.fileName||"file",contentType:a.contentType||r.type||"application/octet-stream",readAll:async()=>new Uint8Array(await r.arrayBuffer()),chunks:async function*(e){for(let t=0;t<r.size;t+=e)yield new Uint8Array(await r.slice(t,t+e).arrayBuffer())}};if(r instanceof Uint8Array||Buffer.isBuffer(r)){p(r.byteLength);const e=Buffer.from(r);return{size:e.byteLength,fileName:a.fileName||"file",contentType:a.contentType||"application/octet-stream",readAll:async()=>e,chunks:async function*(t){for(let o=0;o<e.byteLength;o+=t)yield e.subarray(o,Math.min(o+t,e.byteLength))}}}throw new TypeError("uploadFile input must be a file path, Blob, Buffer, or Uint8Array")}(s,d);if(y.size>8388608)return async function(e,t){const o=await u("POST","/files/upload/init",{body:{fileName:e.fileName,contentType:e.contentType,sizeBytes:e.size,folderId:t.folderId}}),n=o?.uploadId;if(!n)throw new r("platform storage upload init returned no uploadId");const a=Number(o.partSize||8388608);let i=0;try{for await(const t of e.chunks(a))i+=1,await m("PUT",`/files/upload/${encodeURIComponent(n)}/parts/${i}`,t);return await u("POST",`/files/upload/${encodeURIComponent(n)}/complete`,{body:{partCount:i}})}catch(e){try{await u("DELETE",`/files/upload/${encodeURIComponent(n)}`)}catch{}throw e}}(y,d);const w=await y.readAll(),h=new Blob([w],{type:y.contentType});let b=await c();for(let e=0;e<2;e+=1){const t=new FormData;t.set("projectId",b.projectId),t.set("scope",b.environment),d.folderId&&t.set("folderId",d.folderId),t.set("file",h,y.fileName);try{const e=await fetch(`${b.baseUrl}/api/v1/studio/storage/files/upload`,{method:"POST",headers:a(b,null),body:t});return await f(e)}catch(t){if(0===e&&l(t)){b=await i(b);continue}throw t}}throw new r("platform storage upload failed")}async function m(e,t,o){let n=await c();for(let r=0;r<2;r+=1)try{const r=await fetch(d(n,t),{method:e,headers:a(n,"application/octet-stream"),body:o});return await f(r)}catch(e){if(0===r&&l(e)){n=await i(n);continue}throw e}throw new r("platform storage upload failed")}export async function renameFile(e,t){return u("PUT",`/files/${encodeURIComponent(e)}/rename`,{body:{fileName:t}})}export async function moveFile(e,{folderId:t}={}){return u("PUT",`/files/${encodeURIComponent(e)}/move`,{body:{folderId:t}})}export async function shareUrl(e,{expirySeconds:t}={}){return u("POST",`/files/${encodeURIComponent(e)}/share-url`,{body:{expirySeconds:t}})}export async function objectExists({fileId:e,objectKey:t}={}){return u("POST","/objects/exists",{body:{fileId:e,objectKey:t}})}export async function deleteFile(e){await u("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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kmlckj/licos-platform-sdk",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "LICOS platform SDK package shell for browser and Node runtimes",
5
5
  "author": "kmlckj",
6
6
  "type": "module",