@kmlckj/licos-platform-sdk 0.6.1 → 0.6.3

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
@@ -41,5 +41,7 @@ const file = await storage.uploadFile('/tmp/report.pdf');
41
41
  const link = await storage.shareUrl(file.id);
42
42
  ```
43
43
 
44
+ `uploadFile` limits each file to 20 MiB.
45
+
44
46
  The browser entry does not export object storage helpers because runtime tokens
45
47
  must not be bundled into public frontend code.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kmlckj/licos-platform-sdk",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "LICOS platform SDK package shell for browser and Node runtimes",
5
5
  "author": "kmlckj",
6
6
  "type": "module",
package/src/database.js CHANGED
@@ -2,7 +2,7 @@ import { ApiError } from './shared.js';
2
2
  import { authHeaders, runtimeConfig } from './runtime.js';
3
3
 
4
4
  function databaseConfig() {
5
- return runtimeConfig({ environmentOverrideEnv: 'LICOS_DATABASE_ENVIRONMENT' });
5
+ return runtimeConfig();
6
6
  }
7
7
 
8
8
  function databaseUrl(config, route) {
@@ -134,7 +134,7 @@ export async function transaction(operations) {
134
134
  type: operation.type,
135
135
  request: {
136
136
  ...operation.request,
137
- environment: operation.request?.environment || config.environment,
137
+ environment: config.environment,
138
138
  },
139
139
  }));
140
140
  return requestJson('/transaction', { operations: normalized });
package/src/index.d.ts CHANGED
@@ -168,6 +168,8 @@ export interface UploadFileOptions {
168
168
  contentType?: string;
169
169
  }
170
170
 
171
+ export const MAX_UPLOAD_FILE_BYTES: number;
172
+
171
173
  export interface ShareUrlOptions {
172
174
  expirySeconds?: number;
173
175
  }
package/src/storage.js CHANGED
@@ -1,9 +1,11 @@
1
- import { readFile } from 'node:fs/promises';
1
+ import { readFile, stat } from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
 
4
4
  import { ApiError } from './shared.js';
5
5
  import { authHeaders, runtimeConfig } from './runtime.js';
6
6
 
7
+ export const MAX_UPLOAD_FILE_BYTES = 20 * 1024 * 1024;
8
+
7
9
  function storageConfig() {
8
10
  return runtimeConfig({ environmentOverrideEnv: 'LICOS_STORAGE_SCOPE' });
9
11
  }
@@ -54,6 +56,8 @@ async function requestJson(method, route, { params, body } = {}) {
54
56
 
55
57
  async function filePart(input, options = {}) {
56
58
  if (typeof input === 'string') {
59
+ const info = await stat(input);
60
+ ensureUploadSize(info.size);
57
61
  const data = await readFile(input);
58
62
  return {
59
63
  blob: new Blob([data], { type: options.contentType || 'application/octet-stream' }),
@@ -61,9 +65,11 @@ async function filePart(input, options = {}) {
61
65
  };
62
66
  }
63
67
  if (input instanceof Blob) {
68
+ ensureUploadSize(input.size);
64
69
  return { blob: input, fileName: options.fileName || 'file' };
65
70
  }
66
71
  if (input instanceof Uint8Array || Buffer.isBuffer(input)) {
72
+ ensureUploadSize(input.byteLength);
67
73
  return {
68
74
  blob: new Blob([input], { type: options.contentType || 'application/octet-stream' }),
69
75
  fileName: options.fileName || 'file',
@@ -72,6 +78,12 @@ async function filePart(input, options = {}) {
72
78
  throw new TypeError('uploadFile input must be a file path, Blob, Buffer, or Uint8Array');
73
79
  }
74
80
 
81
+ function ensureUploadSize(size) {
82
+ if (size > MAX_UPLOAD_FILE_BYTES) {
83
+ throw new RangeError(`uploadFile input exceeds max size of ${MAX_UPLOAD_FILE_BYTES} bytes`);
84
+ }
85
+ }
86
+
75
87
  export async function summary() {
76
88
  return requestJson('GET', '/summary');
77
89
  }