@simpleplatform/sdk 1.1.0 → 1.2.1
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/ai.js +1 -21
- package/dist/storage.d.ts +26 -0
- package/dist/storage.js +48 -3
- package/dist/types.d.ts +13 -4
- package/package.json +3 -3
package/dist/ai.js
CHANGED
|
@@ -266,21 +266,6 @@ export async function transcribe(input, options, context) {
|
|
|
266
266
|
// ============================================================================
|
|
267
267
|
// Face Recognition API
|
|
268
268
|
// ============================================================================
|
|
269
|
-
let _collectionEnsured = false;
|
|
270
|
-
/**
|
|
271
|
-
* Internal helper to ensure the face collection exists before making face operations.
|
|
272
|
-
* Caches the result per Javascript isolate execution to minimize RPC overhead over
|
|
273
|
-
* sequential calls in the same logic.
|
|
274
|
-
*/
|
|
275
|
-
async function _ensureFaceCollection(context) {
|
|
276
|
-
if (_collectionEnsured)
|
|
277
|
-
return;
|
|
278
|
-
const response = await hostExecute('action:ai/face/ensure-collection', {}, context);
|
|
279
|
-
if (!response.ok) {
|
|
280
|
-
throw new Error(response.error?.message || 'Failed to ensure face collection.');
|
|
281
|
-
}
|
|
282
|
-
_collectionEnsured = true;
|
|
283
|
-
}
|
|
284
269
|
/**
|
|
285
270
|
* Enrolls a face for a subject. The face is associated with the given `subjectId`
|
|
286
271
|
* within the tenant's secure collection.
|
|
@@ -298,9 +283,7 @@ export async function enrollFace(subjectId, image, context) {
|
|
|
298
283
|
if (!image) {
|
|
299
284
|
throw new Error('The `image` parameter is required for `enrollFace`.');
|
|
300
285
|
}
|
|
301
|
-
//
|
|
302
|
-
await _ensureFaceCollection(context);
|
|
303
|
-
// Upload pending documents if given handles
|
|
286
|
+
// Upload pending DocumentHandles to ephemeral storage
|
|
304
287
|
const processedImage = await _uploadPendingFiles(image, context);
|
|
305
288
|
const payload = {
|
|
306
289
|
image: processedImage,
|
|
@@ -325,8 +308,6 @@ export async function searchFace(image, options = {}, context) {
|
|
|
325
308
|
if (!image) {
|
|
326
309
|
throw new Error('The `image` parameter is required for `searchFace`.');
|
|
327
310
|
}
|
|
328
|
-
// Ensure collection exists before searching
|
|
329
|
-
await _ensureFaceCollection(context);
|
|
330
311
|
const processedImage = await _uploadPendingFiles(image, context);
|
|
331
312
|
// Map JS property names to Elixir convention if needed, though they are passed as options
|
|
332
313
|
// and parsed correctly in simple_logic if expected.
|
|
@@ -358,7 +339,6 @@ export async function deleteFace(faceIds, context) {
|
|
|
358
339
|
if (!faceIds || !Array.isArray(faceIds) || faceIds.length === 0) {
|
|
359
340
|
throw new Error('The `faceIds` parameter must be a non-empty array for `deleteFace`.');
|
|
360
341
|
}
|
|
361
|
-
await _ensureFaceCollection(context);
|
|
362
342
|
const payload = {
|
|
363
343
|
face_ids: faceIds,
|
|
364
344
|
};
|
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('
|
|
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
|
|
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
|
-
/**
|
|
37
|
-
|
|
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
|
|
3
|
+
"version": "1.2.1",
|
|
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.
|
|
64
|
+
"esbuild": "0.27.4"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@types/node": "25.
|
|
67
|
+
"@types/node": "25.5.0",
|
|
68
68
|
"typescript": "5.9.3"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|