@cloudnux/core-cloud-provider 0.17.0 → 0.19.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 +50 -6
- package/dist/index.js +43 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -94,7 +94,14 @@ type Entrypoint = {
|
|
|
94
94
|
entries: Record<string, Entry>;
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
-
interface
|
|
97
|
+
interface IService {
|
|
98
|
+
}
|
|
99
|
+
type ServiceKind = "storage" | "location" | "event-broker" | "functions" | "websocket" | "invoke" | "logger";
|
|
100
|
+
declare function registerService(kind: ServiceKind, factory: () => IService): void;
|
|
101
|
+
declare function registerServices(services: Record<ServiceKind, () => IService>): void;
|
|
102
|
+
declare function getService<T extends IService>(kind: ServiceKind): T;
|
|
103
|
+
|
|
104
|
+
interface EventBrokerService extends IService {
|
|
98
105
|
/**
|
|
99
106
|
* Publish a message to a topic/queue
|
|
100
107
|
* @param target Target topic/queue name
|
|
@@ -151,7 +158,7 @@ interface EventMessage {
|
|
|
151
158
|
publishedAt: Date;
|
|
152
159
|
}
|
|
153
160
|
|
|
154
|
-
interface InvokeService {
|
|
161
|
+
interface InvokeService extends IService {
|
|
155
162
|
/**
|
|
156
163
|
* Invoke a function directly.
|
|
157
164
|
* @param moduleName - The name of the module containing the function to invoke.
|
|
@@ -240,7 +247,7 @@ interface RouteResult {
|
|
|
240
247
|
endPosition: Coordinates;
|
|
241
248
|
}>;
|
|
242
249
|
}
|
|
243
|
-
interface LocationService {
|
|
250
|
+
interface LocationService extends IService {
|
|
244
251
|
/**
|
|
245
252
|
* Get autocomplete suggestions for search box
|
|
246
253
|
* Use case: User types "Stock..." → Show ["Stockholm", "Stockton", ...]
|
|
@@ -263,7 +270,7 @@ interface LocationService {
|
|
|
263
270
|
getLocationDetails?(placeId: string): Promise<LocationAddress>;
|
|
264
271
|
}
|
|
265
272
|
|
|
266
|
-
interface StorageService {
|
|
273
|
+
interface StorageService extends IService {
|
|
267
274
|
/**
|
|
268
275
|
* Read data from storage
|
|
269
276
|
* @param path Path to the file/object
|
|
@@ -311,6 +318,26 @@ interface StorageWriteResult {
|
|
|
311
318
|
key: string;
|
|
312
319
|
}
|
|
313
320
|
|
|
321
|
+
interface LoggerService extends IService {
|
|
322
|
+
level: string;
|
|
323
|
+
setBindings(bindings: Record<string, string>): void;
|
|
324
|
+
fatal(mergeObject: Record<string, any> | string, msg?: string): void;
|
|
325
|
+
error(mergeObject: Record<string, any> | string, msg?: string): void;
|
|
326
|
+
warn(mergeObject: Record<string, any> | string, msg?: string): void;
|
|
327
|
+
info(mergeObject: Record<string, any> | string, msg?: string): void;
|
|
328
|
+
debug(mergeObject: Record<string, any> | string, msg?: string): void;
|
|
329
|
+
trace(mergeObject: Record<string, any> | string, msg?: string): void;
|
|
330
|
+
}
|
|
331
|
+
type LogEntry = {
|
|
332
|
+
level: number;
|
|
333
|
+
levelName: string;
|
|
334
|
+
time: number;
|
|
335
|
+
module: string;
|
|
336
|
+
reqId: string;
|
|
337
|
+
msg: string;
|
|
338
|
+
meta?: Record<string, unknown>;
|
|
339
|
+
};
|
|
340
|
+
|
|
314
341
|
/**
|
|
315
342
|
* Represents the context object for a function handler.
|
|
316
343
|
*/
|
|
@@ -319,6 +346,10 @@ type FunctionContext = {
|
|
|
319
346
|
* The underlying context handler type.
|
|
320
347
|
*/
|
|
321
348
|
type: HandlerType;
|
|
349
|
+
/**
|
|
350
|
+
* Logger bound to this invocation's module name and request id.
|
|
351
|
+
*/
|
|
352
|
+
logger: LoggerService;
|
|
322
353
|
/**
|
|
323
354
|
* Creates a success response. This should be called when the handler is done successfully.
|
|
324
355
|
* @param data - The response body.
|
|
@@ -370,6 +401,7 @@ type HTTPRequest = {
|
|
|
370
401
|
rawQueryString?: string;
|
|
371
402
|
requestId?: string;
|
|
372
403
|
host?: string;
|
|
404
|
+
moduleName?: string;
|
|
373
405
|
};
|
|
374
406
|
type HTTPResponse = {
|
|
375
407
|
headers?: Record<string, string | string[] | undefined>;
|
|
@@ -409,6 +441,7 @@ type ScheduleResponse = {
|
|
|
409
441
|
type ScheduleRequest = {
|
|
410
442
|
name: string;
|
|
411
443
|
requestId?: string;
|
|
444
|
+
moduleName?: string;
|
|
412
445
|
};
|
|
413
446
|
type ScheduleFunctionContext = FunctionContext & {
|
|
414
447
|
response: ScheduleResponse;
|
|
@@ -421,6 +454,7 @@ type EventRequest = {
|
|
|
421
454
|
requestId?: string;
|
|
422
455
|
timestamp: Date;
|
|
423
456
|
attempts?: number;
|
|
457
|
+
moduleName?: string;
|
|
424
458
|
};
|
|
425
459
|
type EventResponse = {
|
|
426
460
|
status: "success" | "error";
|
|
@@ -469,6 +503,7 @@ type WebSocketRequest = {
|
|
|
469
503
|
headers?: Record<string, string | string[] | undefined>;
|
|
470
504
|
queryString: Record<string, string | undefined> | null;
|
|
471
505
|
requestId?: string;
|
|
506
|
+
moduleName?: string;
|
|
472
507
|
};
|
|
473
508
|
type WebSocketResponse = {
|
|
474
509
|
status: "success" | "error";
|
|
@@ -487,7 +522,7 @@ type WebSocketFunctionContext = FunctionContext & {
|
|
|
487
522
|
forbidden(body?: any): void;
|
|
488
523
|
validationError(details: Record<string, any>): void;
|
|
489
524
|
};
|
|
490
|
-
interface FunctionsService {
|
|
525
|
+
interface FunctionsService extends IService {
|
|
491
526
|
createHttRequest(...args: any[]): [HTTPRequest, HTTPAuth?];
|
|
492
527
|
createScheduleRequest(...args: any[]): [ScheduleRequest];
|
|
493
528
|
createEventRequest(...args: any[]): [EventRequest];
|
|
@@ -500,6 +535,14 @@ interface FunctionsService {
|
|
|
500
535
|
buildInvokeResponse(invokeFunctionContext: InvokeFunctionContext, ...args: any[]): any;
|
|
501
536
|
}
|
|
502
537
|
|
|
538
|
+
/**
|
|
539
|
+
* Thrown when a sendToClient/disconnect is attempted against a connectionId
|
|
540
|
+
* that is no longer connected (AWS API Gateway GoneException equivalent, HTTP 410).
|
|
541
|
+
*/
|
|
542
|
+
declare class WebSocketConnectionGoneError extends Error {
|
|
543
|
+
readonly connectionId: string;
|
|
544
|
+
constructor(connectionId: string);
|
|
545
|
+
}
|
|
503
546
|
interface WebSocketService {
|
|
504
547
|
/**
|
|
505
548
|
* Send a message to a specific connected client
|
|
@@ -522,6 +565,7 @@ interface CloudProvider {
|
|
|
522
565
|
createFunctionsService(): FunctionsService;
|
|
523
566
|
createWebSocketService(): WebSocketService;
|
|
524
567
|
createInvokeService(): InvokeService;
|
|
568
|
+
createLoggerService(): LoggerService;
|
|
525
569
|
}
|
|
526
570
|
|
|
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 };
|
|
571
|
+
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 IService, type InvokeEntry, type InvokeFunctionContext, type InvokeRequest, type InvokeResponse, type InvokeService, type InvokeTrigger, type LocationAddress, type LocationProviderConfig, type LocationService, type LocationSuggestion, type LogEntry, type LoggerService, 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 ServiceKind, type StorageService, type StorageWriteOptions, type StorageWriteResult, type SuggestionParams, WebSocketConnectionGoneError, type WebSocketEntry, type WebSocketEvent, type WebSocketFunctionContext, type WebSocketRequest, type WebSocketResponse, type WebSocketService, type WebSocketTrigger, getService, registerService, registerServices };
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,49 @@ var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
|
|
|
15
15
|
ErrorCode2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
16
16
|
return ErrorCode2;
|
|
17
17
|
})(ErrorCode || {});
|
|
18
|
+
|
|
19
|
+
// src/services/websocket.ts
|
|
20
|
+
var WebSocketConnectionGoneError = class extends Error {
|
|
21
|
+
connectionId;
|
|
22
|
+
constructor(connectionId) {
|
|
23
|
+
super(`WebSocket connection ${connectionId} is gone`);
|
|
24
|
+
this.name = "WebSocketConnectionGoneError";
|
|
25
|
+
this.connectionId = connectionId;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/cloud-container.ts
|
|
30
|
+
var _cloudContainer = {
|
|
31
|
+
storage: void 0,
|
|
32
|
+
location: void 0,
|
|
33
|
+
"event-broker": void 0,
|
|
34
|
+
functions: void 0,
|
|
35
|
+
websocket: void 0,
|
|
36
|
+
invoke: void 0,
|
|
37
|
+
logger: void 0
|
|
38
|
+
};
|
|
39
|
+
function registerService(kind, factory) {
|
|
40
|
+
_cloudContainer[kind] = factory;
|
|
41
|
+
}
|
|
42
|
+
function registerServices(services) {
|
|
43
|
+
for (const kind in services) {
|
|
44
|
+
if (services.hasOwnProperty(kind)) {
|
|
45
|
+
_cloudContainer[kind] = services[kind];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function getService(kind) {
|
|
50
|
+
const service = _cloudContainer[kind];
|
|
51
|
+
if (!service) {
|
|
52
|
+
throw new Error(`Service of kind ${kind} is not registered.`);
|
|
53
|
+
}
|
|
54
|
+
return service();
|
|
55
|
+
}
|
|
18
56
|
export {
|
|
19
|
-
ErrorCode
|
|
57
|
+
ErrorCode,
|
|
58
|
+
WebSocketConnectionGoneError,
|
|
59
|
+
getService,
|
|
60
|
+
registerService,
|
|
61
|
+
registerServices
|
|
20
62
|
};
|
|
21
63
|
//# sourceMappingURL=index.js.map
|
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 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"]}
|
|
1
|
+
{"version":3,"sources":["../src/services/functions.ts","../src/services/websocket.ts","../src/cloud-container.ts"],"sourcesContent":["import { IService } from \"../cloud-container\";\nimport { HandlerType, HttpMethod, WebSocketEvent } from \"../entrypoint\";\nimport { LoggerService } from \"./logger\";\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 * Logger bound to this invocation's module name and request id.\n */\n logger: LoggerService;\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 moduleName?: 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 moduleName?: 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 moduleName?: string,\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 moduleName?: 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 extends IService {\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}","/**\n * Thrown when a sendToClient/disconnect is attempted against a connectionId\n * that is no longer connected (AWS API Gateway GoneException equivalent, HTTP 410).\n */\nexport class WebSocketConnectionGoneError extends Error {\n public readonly connectionId: string;\n\n constructor(connectionId: string) {\n super(`WebSocket connection ${connectionId} is gone`);\n this.name = \"WebSocketConnectionGoneError\";\n this.connectionId = connectionId;\n }\n}\n\nexport interface WebSocketService {\n /**\n * Send a message to a specific connected client\n * @param connectionId The connection ID of the target client\n * @param data The data to send\n */\n sendToClient(connectionId: string, data: any): Promise<void>;\n\n /**\n * Disconnect a specific connected client\n * @param connectionId The connection ID of the client to disconnect\n */\n disconnect(connectionId: string): Promise<void>;\n}\n","export interface IService { };\nexport type ServiceKind = \"storage\" | \"location\" | \"event-broker\" | \"functions\" | \"websocket\" | \"invoke\" | \"logger\";\n\n\nconst _cloudContainer: Record<ServiceKind, (() => IService) | undefined> = {\n storage: undefined,\n location: undefined,\n \"event-broker\": undefined,\n functions: undefined,\n websocket: undefined,\n invoke: undefined,\n logger: undefined\n};\n\nexport function registerService(kind: ServiceKind, factory: () => IService) {\n _cloudContainer[kind] = factory;\n}\n\nexport function registerServices(services: Record<ServiceKind, () => IService>) {\n for (const kind in services) {\n if (services.hasOwnProperty(kind)) {\n _cloudContainer[kind as ServiceKind] = services[kind as ServiceKind];\n }\n }\n}\n\nexport function getService<T extends IService>(kind: ServiceKind): T {\n const service = _cloudContainer[kind];\n if (!service) {\n throw new Error(`Service of kind ${kind} is not registered.`);\n }\n return service() as T;\n}\n"],"mappings":";AA8CO,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;;;AC1CL,IAAM,+BAAN,cAA2C,MAAM;AAAA,EACpC;AAAA,EAEhB,YAAY,cAAsB;AAC9B,UAAM,wBAAwB,YAAY,UAAU;AACpD,SAAK,OAAO;AACZ,SAAK,eAAe;AAAA,EACxB;AACJ;;;ACRA,IAAM,kBAAqE;AAAA,EACvE,SAAS;AAAA,EACT,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,QAAQ;AACZ;AAEO,SAAS,gBAAgB,MAAmB,SAAyB;AACxE,kBAAgB,IAAI,IAAI;AAC5B;AAEO,SAAS,iBAAiB,UAA+C;AAC5E,aAAW,QAAQ,UAAU;AACzB,QAAI,SAAS,eAAe,IAAI,GAAG;AAC/B,sBAAgB,IAAmB,IAAI,SAAS,IAAmB;AAAA,IACvE;AAAA,EACJ;AACJ;AAEO,SAAS,WAA+B,MAAsB;AACjE,QAAM,UAAU,gBAAgB,IAAI;AACpC,MAAI,CAAC,SAAS;AACV,UAAM,IAAI,MAAM,mBAAmB,IAAI,qBAAqB;AAAA,EAChE;AACA,SAAO,QAAQ;AACnB;","names":["ErrorCode"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudnux/core-cloud-provider",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "CloudNux core interfaces and types for multi-cloud abstraction",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -40,7 +40,9 @@
|
|
|
40
40
|
"clean": "rm -rf dist"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {},
|
|
43
|
-
"devDependencies": {
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^24.10.1"
|
|
45
|
+
},
|
|
44
46
|
"publishConfig": {
|
|
45
47
|
"access": "public"
|
|
46
48
|
}
|