@cloudnux/core-cloud-provider 0.3.0 → 0.10.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 CHANGED
@@ -1,4 +1,4 @@
1
- type HandlerType = "Http" | "Schedule" | "Event";
1
+ type HandlerType = "Http" | "Schedule" | "Event" | "WebSocket";
2
2
  type BaseEntry<TTrigger> = {
3
3
  handler: string;
4
4
  trigger: TTrigger;
@@ -69,7 +69,19 @@ type EventTrigger = {
69
69
  };
70
70
  type EventEntry = BaseEntry<EventTrigger>;
71
71
 
72
- type Entry = HttpEntry | ScheduleEntry | EventEntry;
72
+ type WebSocketEvent = "connect" | "disconnect" | "message";
73
+ type WebSocketTrigger = {
74
+ type: "websocket";
75
+ options: {
76
+ path: string;
77
+ event: WebSocketEvent;
78
+ route?: string;
79
+ routeKey?: string;
80
+ };
81
+ };
82
+ type WebSocketEntry = BaseEntry<WebSocketTrigger>;
83
+
84
+ type Entry = HttpEntry | ScheduleEntry | EventEntry | WebSocketEntry;
73
85
  type Entrypoint = {
74
86
  entries: Record<string, Entry>;
75
87
  };
@@ -144,6 +156,11 @@ interface Coordinates {
144
156
  lat: number;
145
157
  lng: number;
146
158
  }
159
+ interface RoutePoint {
160
+ lat: number;
161
+ lng: number;
162
+ distanceFromStartKm: number;
163
+ }
147
164
  interface SuggestionParams {
148
165
  query: string;
149
166
  maxResults?: number;
@@ -152,6 +169,11 @@ interface SuggestionParams {
152
169
  biasPosition?: Coordinates;
153
170
  placeTypes?: string[];
154
171
  }
172
+ interface ReverseGeocodeParams {
173
+ coordinates: Coordinates;
174
+ language?: string;
175
+ maxResults?: number;
176
+ }
155
177
  interface LocationSuggestion {
156
178
  title: string;
157
179
  subtitle?: string;
@@ -163,11 +185,6 @@ interface LocationSuggestion {
163
185
  provider: string;
164
186
  rawData?: any;
165
187
  }
166
- interface ReverseGeocodeParams {
167
- coordinates: Coordinates;
168
- language?: string;
169
- maxResults?: number;
170
- }
171
188
  interface LocationAddress {
172
189
  fullAddress: string;
173
190
  street?: string;
@@ -184,6 +201,26 @@ interface LocationAddress {
184
201
  provider: string;
185
202
  rawData?: any;
186
203
  }
204
+ interface RouteResult {
205
+ totalDistanceKm: number;
206
+ totalDurationMinutes: number;
207
+ /** Route coordinates as [lng, lat] pairs for GeoJSON */
208
+ /** TODO: convert array to coordinates */
209
+ coordinates: Coordinates[];
210
+ /** Sampled points along route for corridor search */
211
+ sampledPoints: RoutePoint[];
212
+ /** Bounding box [minLng, minLat, maxLng, maxLat] */
213
+ bbox: [number, number, number, number];
214
+ /** Individual leg data */
215
+ legs: Array<{
216
+ distanceKm: number;
217
+ durationMinutes: number;
218
+ /** TODO: convert array to coordinates */
219
+ coordinates: Coordinates[];
220
+ startPosition: Coordinates;
221
+ endPosition: Coordinates;
222
+ }>;
223
+ }
187
224
  interface LocationService {
188
225
  /**
189
226
  * Get autocomplete suggestions for search box
@@ -195,6 +232,11 @@ interface LocationService {
195
232
  * Use case: User clicks "Get my location" → Show "Drottninggatan 10, Stockholm"
196
233
  */
197
234
  reverseGeocode(params: ReverseGeocodeParams): Promise<LocationAddress>;
235
+ /**
236
+ * Calculate route between origin and destination with optional waypoints
237
+ * Use case: User plans trip → Show route on map + details
238
+ */
239
+ calculateRoute(origin: Coordinates, destination: Coordinates, waypoints?: Coordinates[], avoidTolls?: boolean): Promise<RouteResult>;
198
240
  /**
199
241
  * Optional: Get detailed location info if suggestion doesn't have coordinates
200
242
  * Use case: User selects suggestion → Need full coordinates
@@ -362,13 +404,46 @@ type EventFunctionContext = FunctionContext & {
362
404
  message<T = Record<string, any>>(): T;
363
405
  attributes<T = Record<string, any>>(): T;
364
406
  };
407
+ type WebSocketRequest = {
408
+ connectionId: string;
409
+ event: WebSocketEvent;
410
+ path: string;
411
+ route?: string;
412
+ body?: string | Record<string, any>;
413
+ headers?: Record<string, string | string[] | undefined>;
414
+ query?: Record<string, string>;
415
+ requestId?: string;
416
+ };
417
+ type WebSocketResponse = {
418
+ status: "success" | "error";
419
+ body?: any;
420
+ };
421
+ type WebSocketFunctionContext = FunctionContext & {
422
+ type: "WebSocket";
423
+ connectionId: string;
424
+ event: WebSocketEvent;
425
+ request: WebSocketRequest;
426
+ response: WebSocketResponse;
427
+ message<T = Record<string, any>>(): T;
428
+ };
365
429
  interface FunctionsService {
366
430
  createHttRequest(...args: any[]): [HTTPRequest, HTTPAuth?];
367
431
  createScheduleRequest(...args: any[]): [ScheduleRequest];
368
432
  createEventRequest(...args: any[]): [EventRequest];
433
+ createWebSocketRequest(...args: any[]): [WebSocketRequest];
369
434
  buildHttpResponse(httpFunctionContext: HttpFunctionContext, ...args: any[]): any;
370
435
  buildScheduleResponse(scheduleFunctionContext: ScheduleFunctionContext, ...args: any[]): any;
371
436
  buildEventResponse(eventFunctionContext: EventFunctionContext, ...args: any[]): any;
437
+ buildWebSocketResponse(webSocketFunctionContext: WebSocketFunctionContext, ...args: any[]): any;
438
+ }
439
+
440
+ interface WebSocketService {
441
+ /**
442
+ * Send a message to a specific connected client
443
+ * @param connectionId The connection ID of the target client
444
+ * @param data The data to send
445
+ */
446
+ sendToClient(connectionId: string, data: any): Promise<void>;
372
447
  }
373
448
 
374
449
  interface CloudProvider {
@@ -377,6 +452,7 @@ interface CloudProvider {
377
452
  createLocationService(): LocationService;
378
453
  createEventBrokerService(): EventBrokerService;
379
454
  createFunctionsService(): FunctionsService;
455
+ createWebSocketService(): WebSocketService;
380
456
  }
381
457
 
382
- export { type BaseEntry, type CloudProvider, type Coordinates, type Entry, type Entrypoint, ErrorCode, 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 ScheduleEntry, type ScheduleFunctionContext, type ScheduleRequest, type ScheduleResponse, type ScheduleTrigger, type StorageService, type StorageWriteOptions, type StorageWriteResult, type SuggestionParams };
458
+ export { type BaseEntry, type CloudProvider, type Coordinates, type Entry, type Entrypoint, ErrorCode, 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 };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/services/functions.ts"],"sourcesContent":["import { HandlerType, HttpMethod } 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 notFound(resource: string, id?: string | number): void;\n\n\n\n // success(body?: any): void;\n\n\n // error(body?: any): void;\n\n // /**\n // * Creates a not found response. This should be called when there is no matching handler.\n // * @param body - The response body.\n // * @returns A promise that resolves when the response is created, or void if not using a promise.\n // */\n // notFound(body?: any): 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 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 output(status: number, body?: string, 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};\n\nexport type EventFunctionContext = FunctionContext & {\n type: \"Event\";\n timestamp: Date;\n attempts?: number;\n response: EventResponse;\n message<T = Record<string, any>>(): T;\n attributes<T = Record<string, any>>(): T;\n}\n//#endregion\n\nexport interface FunctionsService {\n createHttRequest(...args: any[]): [HTTPRequest, HTTPAuth?];\n createScheduleRequest(...args: any[]): [ScheduleRequest];\n createEventRequest(...args: any[]): [EventRequest];\n\n buildHttpResponse(httpFunctionContext: HttpFunctionContext, ...args: any[]): any\n buildScheduleResponse(scheduleFunctionContext: ScheduleFunctionContext, ...args: any[]): any;\n buildEventResponse(eventFunctionContext: EventFunctionContext, ...args: any[]): any;\n}"],"mappings":";AA2CO,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"],"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 notFound(resource: string, id?: string | number): void;\n\n\n\n // success(body?: any): void;\n\n\n // error(body?: any): void;\n\n // /**\n // * Creates a not found response. This should be called when there is no matching handler.\n // * @param body - The response body.\n // * @returns A promise that resolves when the response is created, or void if not using a promise.\n // */\n // notFound(body?: any): 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 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 output(status: number, body?: string, 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};\n\nexport type EventFunctionContext = FunctionContext & {\n type: \"Event\";\n timestamp: Date;\n attempts?: number;\n response: EventResponse;\n message<T = Record<string, any>>(): T;\n attributes<T = Record<string, any>>(): T;\n}\n//#endregion\n\n//#region [WebSocket]\nexport type WebSocketRequest = {\n connectionId: string,\n event: WebSocketEvent,\n path: string,\n route?: string,\n body?: string | Record<string, any>,\n headers?: Record<string, string | string[] | undefined>,\n query?: Record<string, string>,\n requestId?: string,\n}\n\nexport type WebSocketResponse = {\n status: \"success\" | \"error\",\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}\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\n buildHttpResponse(httpFunctionContext: HttpFunctionContext, ...args: any[]): any\n buildScheduleResponse(scheduleFunctionContext: ScheduleFunctionContext, ...args: any[]): any;\n buildEventResponse(eventFunctionContext: EventFunctionContext, ...args: any[]): any;\n buildWebSocketResponse(webSocketFunctionContext: WebSocketFunctionContext, ...args: any[]): any;\n}"],"mappings":";AA2CO,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudnux/core-cloud-provider",
3
- "version": "0.3.0",
3
+ "version": "0.10.0",
4
4
  "description": "CloudNux core interfaces and types for multi-cloud abstraction",
5
5
  "license": "MIT",
6
6
  "type": "module",