@simpleplatform/sdk 1.1.0 → 1.2.0

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/dist/storage.d.ts CHANGED
@@ -1,4 +1,30 @@
1
1
  import type { Context, DocumentHandle, ExternalFileSource, StorageTarget } from './types';
2
+ /**
3
+ * Uploads an in-memory binary buffer as a document to the platform's storage system.
4
+ *
5
+ * Accepts any binary content (images, PDFs, etc.) as an `ArrayBuffer` or `Uint8Array`.
6
+ * The bytes are base64-encoded once here at the JSON boundary, decoded on the backend,
7
+ * and then stored via the same pipeline as `uploadExternal`.
8
+ *
9
+ * @param buffer The binary content to upload.
10
+ * @param filename The filename to assign to the stored document.
11
+ * @param mimeType The MIME type of the content (e.g. `'application/pdf'`, `'image/png'`).
12
+ * @param target The target location where the file should be stored.
13
+ * @param context The execution context for the request.
14
+ * @returns A promise that resolves with a DocumentHandle containing file metadata.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const handle = await uploadBuffer(
19
+ * pdfBytes,
20
+ * 'report.pdf',
21
+ * 'application/pdf',
22
+ * { app_id: 'dev.simple.system', table_name: 'documents', field_name: 'attachment' },
23
+ * context
24
+ * )
25
+ * ```
26
+ */
27
+ export declare function uploadBuffer(buffer: ArrayBuffer | Uint8Array, filename: string, mimeType: string, target: StorageTarget, context: Context): Promise<DocumentHandle>;
2
28
  /**
3
29
  * Uploads a file from an external URL to the platform's storage system.
4
30
  *
package/dist/storage.js CHANGED
@@ -1,4 +1,49 @@
1
1
  import { execute as hostExecute } from './host';
2
+ /**
3
+ * Uploads an in-memory binary buffer as a document to the platform's storage system.
4
+ *
5
+ * Accepts any binary content (images, PDFs, etc.) as an `ArrayBuffer` or `Uint8Array`.
6
+ * The bytes are base64-encoded once here at the JSON boundary, decoded on the backend,
7
+ * and then stored via the same pipeline as `uploadExternal`.
8
+ *
9
+ * @param buffer The binary content to upload.
10
+ * @param filename The filename to assign to the stored document.
11
+ * @param mimeType The MIME type of the content (e.g. `'application/pdf'`, `'image/png'`).
12
+ * @param target The target location where the file should be stored.
13
+ * @param context The execution context for the request.
14
+ * @returns A promise that resolves with a DocumentHandle containing file metadata.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const handle = await uploadBuffer(
19
+ * pdfBytes,
20
+ * 'report.pdf',
21
+ * 'application/pdf',
22
+ * { app_id: 'dev.simple.system', table_name: 'documents', field_name: 'attachment' },
23
+ * context
24
+ * )
25
+ * ```
26
+ */
27
+ export async function uploadBuffer(buffer, filename, mimeType, target, context) {
28
+ if (!filename || filename.trim() === '')
29
+ throw new Error('filename is required');
30
+ if (!mimeType || mimeType.trim() === '')
31
+ throw new Error('mimeType is required');
32
+ if (!target.app_id || target.app_id.trim() === '')
33
+ throw new Error('Target app_id is required and cannot be empty');
34
+ if (!target.table_name || target.table_name.trim() === '')
35
+ throw new Error('Target table_name is required and cannot be empty');
36
+ if (!target.field_name || target.field_name.trim() === '')
37
+ throw new Error('Target field_name is required and cannot be empty');
38
+ const bytes = buffer instanceof ArrayBuffer ? new Uint8Array(buffer) : buffer;
39
+ // Base64-encode at the JSON boundary (JSON.stringify cannot carry raw binary)
40
+ const base64 = btoa(String.fromCharCode(...bytes));
41
+ const source = { bytes: base64, filename, mime_type: mimeType };
42
+ const response = await hostExecute('action:storage/upload-external', { source, target }, context);
43
+ if (!response.ok)
44
+ throw new Error(response.error?.message ?? 'Buffer upload failed');
45
+ return response.data;
46
+ }
2
47
  /**
3
48
  * Uploads a file from an external URL to the platform's storage system.
4
49
  *
@@ -32,9 +77,9 @@ import { execute as hostExecute } from './host';
32
77
  * ```
33
78
  */
34
79
  export async function uploadExternal(source, target, context) {
35
- // Validate source
36
- if (!source.url || source.url.trim() === '') {
37
- throw new Error('Source URL is required and cannot be empty');
80
+ // Validate source: must have either url or bytes
81
+ if ((!source.url || source.url.trim() === '') && !source.bytes) {
82
+ throw new Error('Either source URL or bytes must be provided');
38
83
  }
39
84
  // Validate target
40
85
  if (!target.app_id || target.app_id.trim() === '') {
package/dist/types.d.ts CHANGED
@@ -20,9 +20,9 @@ export interface DocumentHandle {
20
20
  /** The storage path where the file is stored. */
21
21
  storage_path: string;
22
22
  }
23
- /** Represents the source configuration for downloading an external file. */
23
+ /** Represents the source configuration for an external file upload (URL or in-memory bytes). */
24
24
  export interface ExternalFileSource {
25
- /** Optional authentication configuration for accessing the external file. */
25
+ /** Optional authentication configuration for accessing the external file (URL path only). */
26
26
  auth?: {
27
27
  /** Bearer token for bearer authentication. */
28
28
  bearer_token?: string;
@@ -33,8 +33,17 @@ export interface ExternalFileSource {
33
33
  /** Username for basic authentication. */
34
34
  username?: string;
35
35
  };
36
- /** The URL of the external file to download. */
37
- url: string;
36
+ /**
37
+ * Base64-encoded binary content for in-memory uploads.
38
+ * Use this with `filename` and `mime_type` instead of `url`.
39
+ */
40
+ bytes?: string;
41
+ /** Original filename — required when using `bytes`. */
42
+ filename?: string;
43
+ /** MIME type of the file — required when using `bytes`. */
44
+ mime_type?: string;
45
+ /** The URL of the external file to download. Mutually exclusive with `bytes`. */
46
+ url?: string;
38
47
  }
39
48
  /** Contains metadata about the specific logic execution. */
40
49
  export interface Logic {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simpleplatform/sdk",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Simple Platform Typescript SDK",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://docs.simple.dev",
@@ -61,10 +61,10 @@
61
61
  "dist"
62
62
  ],
63
63
  "dependencies": {
64
- "esbuild": "0.27.3"
64
+ "esbuild": "0.27.4"
65
65
  },
66
66
  "devDependencies": {
67
- "@types/node": "25.3.3",
67
+ "@types/node": "25.5.0",
68
68
  "typescript": "5.9.3"
69
69
  },
70
70
  "scripts": {