@sinch/functions-runtime 0.3.9 → 0.4.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/bin/sinch-runtime.js +446 -73
- package/dist/bin/sinch-runtime.js.map +1 -1
- package/dist/index.d.ts +100 -2
- package/dist/index.js +413 -58
- package/dist/index.js.map +1 -1
- package/package.json +1 -4
package/dist/index.d.ts
CHANGED
|
@@ -760,7 +760,7 @@ export declare function createPieBuilder(): PieSvamlBuilder;
|
|
|
760
760
|
/**
|
|
761
761
|
* Cache interface for Sinch Functions
|
|
762
762
|
*
|
|
763
|
-
* Both dev (LocalCache) and prod (
|
|
763
|
+
* Both dev (LocalCache) and prod (ApiBackedCache) implement this interface,
|
|
764
764
|
* allowing seamless package swap during deployment.
|
|
765
765
|
*/
|
|
766
766
|
/**
|
|
@@ -865,6 +865,46 @@ export interface IFunctionCache {
|
|
|
865
865
|
*/
|
|
866
866
|
getMany<T = unknown>(keys: string[]): Promise<Record<string, T | null>>;
|
|
867
867
|
}
|
|
868
|
+
/**
|
|
869
|
+
* Storage interface for Sinch Functions
|
|
870
|
+
*
|
|
871
|
+
* Both dev (LocalStorage) and prod (S3Storage) implement this interface,
|
|
872
|
+
* allowing seamless package swap during deployment.
|
|
873
|
+
*/
|
|
874
|
+
/**
|
|
875
|
+
* Function storage interface
|
|
876
|
+
*
|
|
877
|
+
* Provides file/blob storage for persistent data.
|
|
878
|
+
* In development, uses the local filesystem (./storage/ directory).
|
|
879
|
+
* In production, uses S3 with local disk caching for reads.
|
|
880
|
+
*
|
|
881
|
+
* Access via `context.storage` — do not construct directly.
|
|
882
|
+
*
|
|
883
|
+
* @example
|
|
884
|
+
* ```typescript
|
|
885
|
+
* // Write a file
|
|
886
|
+
* await context.storage.write('reports/daily.json', JSON.stringify(data));
|
|
887
|
+
*
|
|
888
|
+
* // Read it back
|
|
889
|
+
* const buf = await context.storage.read('reports/daily.json');
|
|
890
|
+
* const data = JSON.parse(buf.toString());
|
|
891
|
+
*
|
|
892
|
+
* // List files
|
|
893
|
+
* const files = await context.storage.list('reports/');
|
|
894
|
+
*
|
|
895
|
+
* // Check existence and delete
|
|
896
|
+
* if (await context.storage.exists('reports/old.json')) {
|
|
897
|
+
* await context.storage.delete('reports/old.json');
|
|
898
|
+
* }
|
|
899
|
+
* ```
|
|
900
|
+
*/
|
|
901
|
+
export interface IFunctionStorage {
|
|
902
|
+
write(key: string, data: string | Buffer): Promise<void>;
|
|
903
|
+
read(key: string): Promise<Buffer>;
|
|
904
|
+
list(prefix?: string): Promise<string[]>;
|
|
905
|
+
exists(key: string): Promise<boolean>;
|
|
906
|
+
delete(key: string): Promise<void>;
|
|
907
|
+
}
|
|
868
908
|
/**
|
|
869
909
|
* Function configuration with environment variables
|
|
870
910
|
*/
|
|
@@ -932,6 +972,37 @@ export interface FunctionContext {
|
|
|
932
972
|
* Available when `ENABLE_NUMBERS_API=true` is set.
|
|
933
973
|
*/
|
|
934
974
|
numbers?: NumbersService;
|
|
975
|
+
/**
|
|
976
|
+
* Persistent file/blob storage.
|
|
977
|
+
* Local filesystem during development, S3-backed in production.
|
|
978
|
+
* @see {@link IFunctionStorage} for available methods
|
|
979
|
+
*/
|
|
980
|
+
storage: IFunctionStorage;
|
|
981
|
+
/**
|
|
982
|
+
* File path to a SQLite database for persistent structured data.
|
|
983
|
+
* The database file is managed by a Litestream sidecar in production
|
|
984
|
+
* (continuous WAL replication to S3). In development, it's a local file.
|
|
985
|
+
*
|
|
986
|
+
* Use any SQLite library — `sql.js` (pure WASM, no native deps) or
|
|
987
|
+
* `better-sqlite3` (native C++, fastest but requires build tooling).
|
|
988
|
+
*
|
|
989
|
+
* @example
|
|
990
|
+
* ```typescript
|
|
991
|
+
* // sql.js (recommended — works everywhere)
|
|
992
|
+
* import initSqlJs from 'sql.js';
|
|
993
|
+
* const SQL = await initSqlJs();
|
|
994
|
+
* const buf = existsSync(context.database) ? readFileSync(context.database) : undefined;
|
|
995
|
+
* const db = new SQL.Database(buf);
|
|
996
|
+
* db.run('CREATE TABLE IF NOT EXISTS kv (key TEXT PRIMARY KEY, value TEXT)');
|
|
997
|
+
* writeFileSync(context.database, Buffer.from(db.export()));
|
|
998
|
+
*
|
|
999
|
+
* // better-sqlite3 (fastest — needs python3/make/g++)
|
|
1000
|
+
* import Database from 'better-sqlite3';
|
|
1001
|
+
* const db = new Database(context.database);
|
|
1002
|
+
* db.exec('CREATE TABLE IF NOT EXISTS kv (key TEXT PRIMARY KEY, value TEXT)');
|
|
1003
|
+
* ```
|
|
1004
|
+
*/
|
|
1005
|
+
database: string;
|
|
935
1006
|
/** Read a file from the assets/ directory (private, not served over HTTP) */
|
|
936
1007
|
assets(filename: string): Promise<string>;
|
|
937
1008
|
}
|
|
@@ -1221,6 +1292,12 @@ export declare function createLenientJsonParser(options?: JsonParsingOptions): (
|
|
|
1221
1292
|
* @internal
|
|
1222
1293
|
*/
|
|
1223
1294
|
export declare function setupJsonParsing(app: Express, options?: JsonParsingOptions): Express;
|
|
1295
|
+
/**
|
|
1296
|
+
* Declarative auth configuration exported by user functions.
|
|
1297
|
+
* - string[] — protect specific handler names
|
|
1298
|
+
* - '*' — protect all handlers
|
|
1299
|
+
*/
|
|
1300
|
+
export type AuthConfig = string[] | "*";
|
|
1224
1301
|
/**
|
|
1225
1302
|
* Get the landing page HTML content
|
|
1226
1303
|
* Exported so production runtime can also use it
|
|
@@ -1258,6 +1335,12 @@ export interface RequestHandlerOptions {
|
|
|
1258
1335
|
logger?: (...args: unknown[]) => void;
|
|
1259
1336
|
/** Enable landing page for browser requests at root (default: true) */
|
|
1260
1337
|
landingPageEnabled?: boolean;
|
|
1338
|
+
/** Declarative auth config from user module (string[] or '*') */
|
|
1339
|
+
authConfig?: AuthConfig;
|
|
1340
|
+
/** API key for Basic Auth validation */
|
|
1341
|
+
authKey?: string;
|
|
1342
|
+
/** API secret for Basic Auth validation */
|
|
1343
|
+
authSecret?: string;
|
|
1261
1344
|
/** Called when request starts */
|
|
1262
1345
|
onRequestStart?: (data: {
|
|
1263
1346
|
functionName: string;
|
|
@@ -2292,6 +2375,18 @@ export declare class LocalCache implements IFunctionCache {
|
|
|
2292
2375
|
* @internal Dev-only factory — access cache via `context.cache`
|
|
2293
2376
|
*/
|
|
2294
2377
|
export declare function createCacheClient(_projectId?: string, _functionName?: string): IFunctionCache;
|
|
2378
|
+
export declare class LocalStorage implements IFunctionStorage {
|
|
2379
|
+
private baseDir;
|
|
2380
|
+
constructor(baseDir?: string);
|
|
2381
|
+
private resolvePath;
|
|
2382
|
+
write(key: string, data: string | Buffer): Promise<void>;
|
|
2383
|
+
read(key: string): Promise<Buffer>;
|
|
2384
|
+
list(prefix?: string): Promise<string[]>;
|
|
2385
|
+
exists(key: string): Promise<boolean>;
|
|
2386
|
+
delete(key: string): Promise<void>;
|
|
2387
|
+
private walkDir;
|
|
2388
|
+
}
|
|
2389
|
+
export declare function createStorageClient(baseDir?: string): LocalStorage;
|
|
2295
2390
|
/**
|
|
2296
2391
|
* Tunnel Client for Sinch Functions
|
|
2297
2392
|
*
|
|
@@ -2380,7 +2475,10 @@ export declare class SecretsLoader {
|
|
|
2380
2475
|
*/
|
|
2381
2476
|
loadCustomSecrets(secretNames?: string[]): Promise<Record<string, string>>;
|
|
2382
2477
|
/**
|
|
2383
|
-
* Check if
|
|
2478
|
+
* Check if the native keychain is available.
|
|
2479
|
+
* Always true — no native npm deps required. The underlying OS tool
|
|
2480
|
+
* (secret-tool, security, CredManager) may still be absent, in which
|
|
2481
|
+
* case getPassword() silently returns null per credential.
|
|
2384
2482
|
*/
|
|
2385
2483
|
isAvailable(): Promise<boolean>;
|
|
2386
2484
|
}
|