@cloudnux/core-cloud-provider 0.15.0 → 0.17.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/index.d.ts +53 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type HandlerType = "Http" | "Schedule" | "Event" | "WebSocket";
|
|
1
|
+
type HandlerType = "Http" | "Schedule" | "Event" | "WebSocket" | "Invoke";
|
|
2
2
|
type BaseEntry<TTrigger> = {
|
|
3
3
|
handler: string;
|
|
4
4
|
trigger: TTrigger;
|
|
@@ -81,7 +81,15 @@ type WebSocketTrigger = {
|
|
|
81
81
|
};
|
|
82
82
|
type WebSocketEntry = BaseEntry<WebSocketTrigger>;
|
|
83
83
|
|
|
84
|
-
type
|
|
84
|
+
type InvokeTrigger = {
|
|
85
|
+
type: "invoke";
|
|
86
|
+
options: {
|
|
87
|
+
name: string;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
type InvokeEntry = BaseEntry<InvokeTrigger>;
|
|
91
|
+
|
|
92
|
+
type Entry = HttpEntry | ScheduleEntry | EventEntry | WebSocketEntry | InvokeEntry;
|
|
85
93
|
type Entrypoint = {
|
|
86
94
|
entries: Record<string, Entry>;
|
|
87
95
|
};
|
|
@@ -143,6 +151,17 @@ interface EventMessage {
|
|
|
143
151
|
publishedAt: Date;
|
|
144
152
|
}
|
|
145
153
|
|
|
154
|
+
interface InvokeService {
|
|
155
|
+
/**
|
|
156
|
+
* Invoke a function directly.
|
|
157
|
+
* @param moduleName - The name of the module containing the function to invoke.
|
|
158
|
+
* @param triggerName - The invoke trigger name registered in the target function's entrypoint.
|
|
159
|
+
* @param payload - The payload to pass to the invoked function.
|
|
160
|
+
* @returns The response body returned by the invoked function.
|
|
161
|
+
*/
|
|
162
|
+
invoke<TPayload = any, TResponse = any>(moduleName: string, triggerName: string, payload: TPayload): Promise<TResponse>;
|
|
163
|
+
}
|
|
164
|
+
|
|
146
165
|
interface LocationProviderConfig {
|
|
147
166
|
apiKey?: string;
|
|
148
167
|
region?: string;
|
|
@@ -305,12 +324,22 @@ type FunctionContext = {
|
|
|
305
324
|
* @param data - The response body.
|
|
306
325
|
*/
|
|
307
326
|
success<T>(data: T): void;
|
|
327
|
+
/**
|
|
328
|
+
* Creates a server error response. This should be called when the handler encounters an unexpected error.
|
|
329
|
+
* @param err - The error object.
|
|
330
|
+
*/
|
|
331
|
+
serverError(err: Error): void;
|
|
308
332
|
/**
|
|
309
333
|
* Creates an error response. This should be called when the handler is done with an error.
|
|
310
334
|
* @param message - The response body.
|
|
311
335
|
*
|
|
312
336
|
*/
|
|
313
337
|
error(message: string, code?: ErrorCode, details?: Record<string, any>, stack?: string): void;
|
|
338
|
+
/**
|
|
339
|
+
* Creates a not found response. This should be called when the requested resource is not found.
|
|
340
|
+
* @param resource - The name of the resource that was not found.
|
|
341
|
+
* @param id - The id of the resource that was not found (optional).
|
|
342
|
+
*/
|
|
314
343
|
notFound(resource: string, id?: string | number): void;
|
|
315
344
|
};
|
|
316
345
|
/**
|
|
@@ -404,6 +433,7 @@ type EventFunctionContext = FunctionContext & {
|
|
|
404
433
|
type: "Event";
|
|
405
434
|
timestamp: Date;
|
|
406
435
|
attempts?: number;
|
|
436
|
+
request: EventRequest;
|
|
407
437
|
response: EventResponse;
|
|
408
438
|
message<T = Record<string, any>>(): T;
|
|
409
439
|
attributes<T = Record<string, any>>(): T;
|
|
@@ -412,6 +442,23 @@ type EventFunctionContext = FunctionContext & {
|
|
|
412
442
|
type EventBatchItemResult = {
|
|
413
443
|
failureId: string;
|
|
414
444
|
} | undefined;
|
|
445
|
+
type InvokeRequest = {
|
|
446
|
+
payload: any;
|
|
447
|
+
calledModule: string;
|
|
448
|
+
invokeTriggerName: string;
|
|
449
|
+
requestId?: string;
|
|
450
|
+
};
|
|
451
|
+
type InvokeResponse = {
|
|
452
|
+
status: "success" | "error";
|
|
453
|
+
body?: any;
|
|
454
|
+
code?: ErrorCode;
|
|
455
|
+
};
|
|
456
|
+
type InvokeFunctionContext = FunctionContext & {
|
|
457
|
+
type: "Invoke";
|
|
458
|
+
request: InvokeRequest;
|
|
459
|
+
response: InvokeResponse;
|
|
460
|
+
payload<T = Record<string, any>>(): T;
|
|
461
|
+
};
|
|
415
462
|
type WebSocketRequest = {
|
|
416
463
|
connectionId: string;
|
|
417
464
|
event: WebSocketEvent;
|
|
@@ -445,10 +492,12 @@ interface FunctionsService {
|
|
|
445
492
|
createScheduleRequest(...args: any[]): [ScheduleRequest];
|
|
446
493
|
createEventRequest(...args: any[]): [EventRequest];
|
|
447
494
|
createWebSocketRequest(...args: any[]): [WebSocketRequest];
|
|
495
|
+
createInvokeRequest(...args: any[]): [InvokeRequest];
|
|
448
496
|
buildHttpResponse(httpFunctionContext: HttpFunctionContext, ...args: any[]): any;
|
|
449
497
|
buildScheduleResponse(scheduleFunctionContext: ScheduleFunctionContext, ...args: any[]): any;
|
|
450
498
|
buildEventResponse(eventFunctionContext: EventFunctionContext, ...args: any[]): Promise<EventBatchItemResult>;
|
|
451
499
|
buildWebSocketResponse(webSocketFunctionContext: WebSocketFunctionContext, ...args: any[]): any;
|
|
500
|
+
buildInvokeResponse(invokeFunctionContext: InvokeFunctionContext, ...args: any[]): any;
|
|
452
501
|
}
|
|
453
502
|
|
|
454
503
|
interface WebSocketService {
|
|
@@ -472,6 +521,7 @@ interface CloudProvider {
|
|
|
472
521
|
createEventBrokerService(): EventBrokerService;
|
|
473
522
|
createFunctionsService(): FunctionsService;
|
|
474
523
|
createWebSocketService(): WebSocketService;
|
|
524
|
+
createInvokeService(): InvokeService;
|
|
475
525
|
}
|
|
476
526
|
|
|
477
|
-
export { type BaseEntry, type CloudProvider, type Coordinates, type Entry, type Entrypoint, ErrorCode, type EventBatchItemResult, type EventBrokerService, type EventEntry, type EventFunctionContext, type EventMessage, type EventRequest, type EventResponse, type EventTrigger, type FunctionContext, type FunctionsService, type HTTPAuth, type HTTPRequest, type HTTPResponse, type HandlerType, type HttpEntry, type HttpFunctionContext, type HttpMethod, type HttpTrigger, type LocationAddress, type LocationProviderConfig, type LocationService, type LocationSuggestion, type MessageFilter, type PeekOptions, type PublishOptions, type ReadOptions, type ReverseGeocodeParams, type RoutePoint, type RouteResult, type ScheduleEntry, type ScheduleFunctionContext, type ScheduleRequest, type ScheduleResponse, type ScheduleTrigger, type StorageService, type StorageWriteOptions, type StorageWriteResult, type SuggestionParams, type WebSocketEntry, type WebSocketEvent, type WebSocketFunctionContext, type WebSocketRequest, type WebSocketResponse, type WebSocketService, type WebSocketTrigger };
|
|
527
|
+
export { type BaseEntry, type CloudProvider, type Coordinates, type Entry, type Entrypoint, ErrorCode, type EventBatchItemResult, type EventBrokerService, type EventEntry, type EventFunctionContext, type EventMessage, type EventRequest, type EventResponse, type EventTrigger, type FunctionContext, type FunctionsService, type HTTPAuth, type HTTPRequest, type HTTPResponse, type HandlerType, type HttpEntry, type HttpFunctionContext, type HttpMethod, type HttpTrigger, type InvokeEntry, type InvokeFunctionContext, type InvokeRequest, type InvokeResponse, type InvokeService, type InvokeTrigger, type LocationAddress, type LocationProviderConfig, type LocationService, type LocationSuggestion, type MessageFilter, type PeekOptions, type PublishOptions, type ReadOptions, type ReverseGeocodeParams, type RoutePoint, type RouteResult, type ScheduleEntry, type ScheduleFunctionContext, type ScheduleRequest, type ScheduleResponse, type ScheduleTrigger, type StorageService, type StorageWriteOptions, type StorageWriteResult, type SuggestionParams, type WebSocketEntry, type WebSocketEvent, type WebSocketFunctionContext, type WebSocketRequest, type WebSocketResponse, type WebSocketService, type WebSocketTrigger };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/services/functions.ts"],"sourcesContent":["import { HandlerType, HttpMethod, WebSocketEvent } from \"../entrypoint\";\n\n/**\n * Represents the context object for a function handler.\n */\nexport type FunctionContext = {\n /**\n * The underlying context handler type.\n */\n type: HandlerType;\n\n /**\n * Creates a success response. This should be called when the handler is done successfully.\n * @param data - The response body.\n */\n success<T>(data: T): void;\n\n /**\n * Creates an error response. This should be called when the handler is done with an error.\n * @param message - The response body.\n * \n */\n error(message: string, code?: ErrorCode, details?: Record<string, any>, stack?: string): void;\n
|
|
1
|
+
{"version":3,"sources":["../src/services/functions.ts"],"sourcesContent":["import { HandlerType, HttpMethod, WebSocketEvent } from \"../entrypoint\";\n\n/**\n * Represents the context object for a function handler.\n */\nexport type FunctionContext = {\n /**\n * The underlying context handler type.\n */\n type: HandlerType;\n\n /**\n * Creates a success response. This should be called when the handler is done successfully.\n * @param data - The response body.\n */\n success<T>(data: T): void;\n\n /**\n * Creates a server error response. This should be called when the handler encounters an unexpected error.\n * @param err - The error object.\n */\n serverError(err: Error): void;\n /**\n * Creates an error response. This should be called when the handler is done with an error.\n * @param message - The response body.\n * \n */\n error(message: string, code?: ErrorCode, details?: Record<string, any>, stack?: string): void;\n /**\n * Creates a not found response. This should be called when the requested resource is not found.\n * @param resource - The name of the resource that was not found.\n * @param id - The id of the resource that was not found (optional).\n */\n notFound(resource: string, id?: string | number): void;\n};\n\n/**\n * Error codes for API error responses\n */\nexport enum ErrorCode {\n // Validation errors\n VALIDATION_ERROR = 'VALIDATION_ERROR',\n INVALID_INPUT = 'INVALID_INPUT',\n\n // Authentication errors\n UNAUTHORIZED = 'UNAUTHORIZED',\n ACCESS_DENIED = 'ACCESS_DENIED',\n\n // Resource errors\n RESOURCE_NOT_FOUND = 'RESOURCE_NOT_FOUND',\n RESOURCE_ALREADY_EXISTS = 'RESOURCE_ALREADY_EXISTS',\n RESOURCE_CONFLICT = 'RESOURCE_CONFLICT',\n\n // System errors\n INTERNAL_SERVER_ERROR = 'INTERNAL_SERVER_ERROR',\n SERVICE_UNAVAILABLE = 'SERVICE_UNAVAILABLE',\n DATABASE_ERROR = 'DATABASE_ERROR',\n\n // Business logic errors\n BUSINESS_RULE_VIOLATION = 'BUSINESS_RULE_VIOLATION',\n\n // External API errors\n EXTERNAL_API_ERROR = 'EXTERNAL_API_ERROR',\n\n // Other errors\n UNKNOWN_ERROR = 'UNKNOWN_ERROR'\n}\n\n//#region [ Http ]\n\nexport type HTTPRequest = {\n method: HttpMethod;\n body?: string;\n headers: Record<string, string | string[] | undefined>;\n url: string;\n params: Record<string, string | undefined>\n matchingKey?: string;\n rawQueryString?: string,\n requestId?: string,\n host?: string\n};\n\nexport type HTTPResponse = {\n headers?: Record<string, string | string[] | undefined>;\n body?: string;\n status: number;\n};\n\nexport type HTTPAuth = {\n token: string;\n appId: string;\n memberId: string;\n customerId: string;\n claims: Record<string, string>;\n identity: \"facebook\" | \"google\" | \"apple\" | \"password\";\n};\n\nexport type HttpFunctionContext = FunctionContext & {\n type: \"Http\";\n request: HTTPRequest;\n auth?: HTTPAuth;\n response: HTTPResponse;\n model<T = Record<string, any>>(): T;\n params<T = Record<string, string>>(): T;\n\n list<T>(items: T[], page: number, pageSize: number, totalItems: number): void;\n cursorList<T>(items: T[], nextCursor: string | null, pageSize: number, prevCursor?: string | null): void;\n created<T>(data: T): void;\n deleted(id?: string | number): void;\n validationError(details: Record<string, any>): void;\n serverError(err: Error): void;\n businessError(message: string, details?: Record<string, any>): void;\n\n unauthorized(message?: string): void;\n forbidden(message?: string): void;\n output(status: number, body?: string | object, headers?: Record<string, string | string[]>): void;\n}\n\n//#endregion\n\n//#region [Schedule]\n\nexport type ScheduleResponse = {\n status: \"success\" | \"error\",\n body?: string | Record<string, any>;\n}\n\nexport type ScheduleRequest = {\n name: string,\n requestId?: string\n};\n\nexport type ScheduleFunctionContext = FunctionContext & {\n response: ScheduleResponse;\n request: ScheduleRequest;\n type: \"Schedule\";\n}\n//#endregion\n\n//#region [Event]\nexport type EventRequest = {\n body: string | Record<string, any>,\n attributes: Record<string, string>,\n requestId?: string,\n timestamp: Date,\n attempts?: number;\n}\n\nexport type EventResponse = {\n status: \"success\" | \"error\",\n code?: ErrorCode,\n body?: Record<string, any>\n stack?: string,\n retryDelay?: number,\n};\n\nexport type EventFunctionContext = FunctionContext & {\n type: \"Event\";\n timestamp: Date;\n attempts?: number;\n request: EventRequest;\n response: EventResponse;\n message<T = Record<string, any>>(): T;\n attributes<T = Record<string, any>>(): T;\n retryWithDelay(seconds: number): void;\n}\n\nexport type EventBatchItemResult = { failureId: string } | undefined;\n//#endregion\n\n//#region [Invoke]\nexport type InvokeRequest = {\n payload: any,\n calledModule: string,\n invokeTriggerName: string,\n requestId?: string,\n}\n\nexport type InvokeResponse = {\n status: \"success\" | \"error\",\n body?: any,\n code?: ErrorCode,\n}\n\nexport type InvokeFunctionContext = FunctionContext & {\n type: \"Invoke\";\n request: InvokeRequest;\n response: InvokeResponse;\n payload<T = Record<string, any>>(): T;\n}\n//#endregion\n\n//#region [WebSocket]\nexport type WebSocketRequest = {\n connectionId: string,\n event: WebSocketEvent,\n route?: string,\n url?: string,\n params: Record<string, string | undefined> | null,\n body?: string | Record<string, any> | null,\n headers?: Record<string, string | string[] | undefined>,\n queryString: Record<string, string | undefined> | null,\n requestId?: string,\n}\n\nexport type WebSocketResponse = {\n status: \"success\" | \"error\",\n statusCode?: number,\n body?: any,\n}\n\nexport type WebSocketFunctionContext = FunctionContext & {\n type: \"WebSocket\";\n connectionId: string;\n event: WebSocketEvent;\n request: WebSocketRequest;\n response: WebSocketResponse;\n message<T = Record<string, any>>(): T;\n params<T = Record<string, string>>(): T;\n unauthorized(body?: any): void;\n forbidden(body?: any): void;\n validationError(details: Record<string, any>): void;\n}\n//#endregion\n\nexport interface FunctionsService {\n createHttRequest(...args: any[]): [HTTPRequest, HTTPAuth?];\n createScheduleRequest(...args: any[]): [ScheduleRequest];\n createEventRequest(...args: any[]): [EventRequest];\n createWebSocketRequest(...args: any[]): [WebSocketRequest];\n createInvokeRequest(...args: any[]): [InvokeRequest];\n\n buildHttpResponse(httpFunctionContext: HttpFunctionContext, ...args: any[]): any\n buildScheduleResponse(scheduleFunctionContext: ScheduleFunctionContext, ...args: any[]): any;\n buildEventResponse(eventFunctionContext: EventFunctionContext, ...args: any[]): Promise<EventBatchItemResult>;\n buildWebSocketResponse(webSocketFunctionContext: WebSocketFunctionContext, ...args: any[]): any;\n buildInvokeResponse(invokeFunctionContext: InvokeFunctionContext, ...args: any[]): any;\n}"],"mappings":";AAuCO,IAAK,YAAL,kBAAKA,eAAL;AAEH,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,mBAAgB;AAGhB,EAAAA,WAAA,kBAAe;AACf,EAAAA,WAAA,mBAAgB;AAGhB,EAAAA,WAAA,wBAAqB;AACrB,EAAAA,WAAA,6BAA0B;AAC1B,EAAAA,WAAA,uBAAoB;AAGpB,EAAAA,WAAA,2BAAwB;AACxB,EAAAA,WAAA,yBAAsB;AACtB,EAAAA,WAAA,oBAAiB;AAGjB,EAAAA,WAAA,6BAA0B;AAG1B,EAAAA,WAAA,wBAAqB;AAGrB,EAAAA,WAAA,mBAAgB;AA1BR,SAAAA;AAAA,GAAA;","names":["ErrorCode"]}
|