@cloudnux/core-cloud-provider 0.1.0 → 0.3.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
@@ -131,77 +131,75 @@ interface EventMessage {
131
131
  publishedAt: Date;
132
132
  }
133
133
 
134
- interface LocationService {
135
- /**
136
- * Search for places based on a query
137
- * @param query Search query
138
- * @param options Search options like bounding box, filters, etc.
139
- * @returns Promise containing search results
140
- */
141
- searchPlaces(query: string, options?: PlaceSearchOptions): Promise<PlaceSearchResult[]>;
142
- /**
143
- * Get detailed information about a specific place
144
- * @param placeId ID of the place to get details for
145
- * @returns Promise containing place details
146
- */
147
- getPlaceDetails(placeId: string): Promise<PlaceDetails>;
134
+ interface LocationProviderConfig {
135
+ apiKey?: string;
136
+ region?: string;
137
+ language?: string;
138
+ countries?: string[];
139
+ timeout?: number;
140
+ retryAttempts?: number;
141
+ metadata?: Record<string, any>;
148
142
  }
149
- interface PlaceSearchOptions {
150
- /** Bounding box to search within */
151
- boundingBox?: {
152
- minLongitude: number;
153
- minLatitude: number;
154
- maxLongitude: number;
155
- maxLatitude: number;
156
- };
157
- /** Maximum number of results to return */
143
+ interface Coordinates {
144
+ lat: number;
145
+ lng: number;
146
+ }
147
+ interface SuggestionParams {
148
+ query: string;
158
149
  maxResults?: number;
159
- /** Filter results by category */
160
- categories?: string[];
161
- /** Language code for results */
162
150
  language?: string;
151
+ countries?: string[];
152
+ biasPosition?: Coordinates;
153
+ placeTypes?: string[];
163
154
  }
164
- interface PlaceSearchResult {
165
- /** Unique identifier for the place */
166
- placeId: string;
167
- /** Place name */
168
- text: string;
169
- }
170
- interface PlaceDetails extends PlaceSearchResult {
171
- /** Place address */
172
- address?: string;
173
- /** Geographic coordinates */
174
- coordinates: {
175
- latitude: number;
176
- longitude: number;
177
- };
178
- /** Distance from search center if applicable */
155
+ interface LocationSuggestion {
156
+ title: string;
157
+ subtitle?: string;
158
+ coordinates?: Coordinates;
159
+ placeId?: string;
160
+ queryId?: string;
161
+ placeType?: string;
179
162
  distance?: number;
180
- /** Place categories/types */
181
- categories?: string[];
182
- /** Full formatted address */
183
- formattedAddress: string;
184
- /** Phone number */
185
- phoneNumber?: string;
186
- /** Website URL */
187
- website?: string;
188
- /** Opening hours */
189
- openingHours?: {
190
- periods: {
191
- day: number;
192
- open?: string;
193
- close?: string;
194
- }[];
195
- weekdayText?: string[];
196
- };
197
- /** Reviews if available */
198
- reviews?: {
199
- rating: number;
200
- text?: string;
201
- time?: number;
202
- }[];
203
- /** Additional place data */
204
- additionalData?: Record<string, any>;
163
+ provider: string;
164
+ rawData?: any;
165
+ }
166
+ interface ReverseGeocodeParams {
167
+ coordinates: Coordinates;
168
+ language?: string;
169
+ maxResults?: number;
170
+ }
171
+ interface LocationAddress {
172
+ fullAddress: string;
173
+ street?: string;
174
+ streetNumber?: string;
175
+ city?: string;
176
+ district?: string;
177
+ region?: string;
178
+ postalCode?: string;
179
+ country?: string;
180
+ countryCode?: string;
181
+ coordinates: Coordinates;
182
+ placeType?: string;
183
+ accuracy?: number;
184
+ provider: string;
185
+ rawData?: any;
186
+ }
187
+ interface LocationService {
188
+ /**
189
+ * Get autocomplete suggestions for search box
190
+ * Use case: User types "Stock..." → Show ["Stockholm", "Stockton", ...]
191
+ */
192
+ getSuggestions(params: SuggestionParams): Promise<LocationSuggestion[]>;
193
+ /**
194
+ * Get address from coordinates (reverse geocoding)
195
+ * Use case: User clicks "Get my location" → Show "Drottninggatan 10, Stockholm"
196
+ */
197
+ reverseGeocode(params: ReverseGeocodeParams): Promise<LocationAddress>;
198
+ /**
199
+ * Optional: Get detailed location info if suggestion doesn't have coordinates
200
+ * Use case: User selects suggestion → Need full coordinates
201
+ */
202
+ getLocationDetails?(placeId: string): Promise<LocationAddress>;
205
203
  }
206
204
 
207
205
  interface StorageService {
@@ -381,4 +379,4 @@ interface CloudProvider {
381
379
  createFunctionsService(): FunctionsService;
382
380
  }
383
381
 
384
- export { type BaseEntry, type CloudProvider, 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 LocationService, type MessageFilter, type PeekOptions, type PlaceDetails, type PlaceSearchOptions, type PlaceSearchResult, type PublishOptions, type ReadOptions, type ScheduleEntry, type ScheduleFunctionContext, type ScheduleRequest, type ScheduleResponse, type ScheduleTrigger, type StorageService, type StorageWriteOptions, type StorageWriteResult };
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 };
package/dist/index.js CHANGED
@@ -1,29 +1,3 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- ErrorCode: () => ErrorCode
24
- });
25
- module.exports = __toCommonJS(index_exports);
26
-
27
1
  // src/services/functions.ts
28
2
  var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
29
3
  ErrorCode2["VALIDATION_ERROR"] = "VALIDATION_ERROR";
@@ -41,8 +15,7 @@ var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
41
15
  ErrorCode2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
42
16
  return ErrorCode2;
43
17
  })(ErrorCode || {});
44
- // Annotate the CommonJS export names for ESM import in node:
45
- 0 && (module.exports = {
18
+ export {
46
19
  ErrorCode
47
- });
20
+ };
48
21
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/services/functions.ts"],"sourcesContent":["export * from \"./entrypoint\";\nexport * from \"./services/event-broker\";\nexport * from \"./services/location\";\nexport * from \"./services/storage\";\nexport * from \"./services/functions\";\nexport * from \"./cloud-provider\";","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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC2CO,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 } 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"]}
package/package.json CHANGED
@@ -1,16 +1,15 @@
1
1
  {
2
2
  "name": "@cloudnux/core-cloud-provider",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "CloudNux core interfaces and types for multi-cloud abstraction",
5
5
  "license": "MIT",
6
+ "type": "module",
6
7
  "types": "./dist/index.d.ts",
7
8
  "main": "./dist/index.js",
8
- "module": "./dist/index.mjs",
9
9
  "exports": {
10
10
  ".": {
11
11
  "types": "./dist/index.d.ts",
12
- "import": "./dist/index.mjs",
13
- "require": "./dist/index.js"
12
+ "import": "./dist/index.js"
14
13
  }
15
14
  },
16
15
  "files": [
@@ -33,14 +32,11 @@
33
32
  ],
34
33
  "scripts": {
35
34
  "build": "tsup",
36
- "dev": "tsup --watch",
37
35
  "yalc:publish": "yalc publish --private",
38
36
  "yalc:push": "yalc push --private",
39
37
  "lint": "eslint . --max-warnings 0",
40
38
  "lint:fix": "eslint . --fix",
41
39
  "type-check": "tsc --noEmit",
42
- "test": "vitest run",
43
- "test:watch": "vitest",
44
40
  "clean": "rm -rf dist"
45
41
  },
46
42
  "dependencies": {},
package/dist/index.d.mts DELETED
@@ -1,384 +0,0 @@
1
- type HandlerType = "Http" | "Schedule" | "Event";
2
- type BaseEntry<TTrigger> = {
3
- handler: string;
4
- trigger: TTrigger;
5
- };
6
-
7
- type HttpMethod = "GET" | "PUT" | "POST" | "PATCH" | "DELETE";
8
- type HttpTrigger = {
9
- type: "http";
10
- options: {
11
- route: string;
12
- method: HttpMethod;
13
- };
14
- };
15
- type HttpEntry = BaseEntry<HttpTrigger>;
16
-
17
- type ScheduleTrigger = {
18
- type: "schedule";
19
- options: {
20
- name: string;
21
- pattern: string;
22
- };
23
- };
24
- type ScheduleEntry = BaseEntry<ScheduleTrigger>;
25
-
26
- interface ComparisonOperators {
27
- $eq?: any;
28
- $ne?: any;
29
- $gt?: number | string | Date;
30
- $gte?: number | string | Date;
31
- $lt?: number | string | Date;
32
- $lte?: number | string | Date;
33
- }
34
- interface ArrayOperators {
35
- $in?: any[];
36
- $nin?: any[];
37
- $all?: any[];
38
- $size?: number;
39
- }
40
- interface StringOperators {
41
- $regex?: string;
42
- $startsWith?: string;
43
- $endsWith?: string;
44
- $contains?: string;
45
- }
46
- interface ExistenceOperators {
47
- $exists?: boolean;
48
- $type?: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null' | 'undefined';
49
- }
50
- interface LogicalOperatorAnd {
51
- $and: FilterCondition[];
52
- }
53
- interface LogicalOperatorOr {
54
- $or: FilterCondition[];
55
- }
56
- type LogicalOperators = LogicalOperatorAnd | LogicalOperatorOr;
57
- type FilterCondition = ComparisonOperators | ArrayOperators | StringOperators | ExistenceOperators | LogicalOperators;
58
- type FilterPropertyValue = any | FilterCondition;
59
- type MessageFilter = {
60
- [propertyPath: string]: FilterPropertyValue;
61
- };
62
- type EventTrigger = {
63
- type: "event";
64
- options: {
65
- source: string;
66
- sourceType: string;
67
- filter?: MessageFilter;
68
- };
69
- };
70
- type EventEntry = BaseEntry<EventTrigger>;
71
-
72
- type Entry = HttpEntry | ScheduleEntry | EventEntry;
73
- type Entrypoint = {
74
- entries: Record<string, Entry>;
75
- };
76
-
77
- interface EventBrokerService {
78
- /**
79
- * Publish a message to a topic/queue
80
- * @param target Target topic/queue name
81
- * @param message Message to publish
82
- * @param options Optional publishing options
83
- * @returns Promise resolving when publishing is complete
84
- */
85
- publish(target: string, message: string | Record<string, any>, options?: PublishOptions): Promise<void>;
86
- /**
87
- * Read a message without removing it from the queue
88
- * @param source Source queue name
89
- * @param options Optional reading options
90
- * @returns Promise containing the peeked message(s)
91
- */
92
- peek(source: string, options?: PeekOptions): Promise<EventMessage[]>;
93
- /**
94
- * Read and remove message(s) from the queue
95
- * @param source Source queue name
96
- * @param options Optional reading options
97
- * @returns Promise containing the read message(s)
98
- */
99
- read(source: string, options?: ReadOptions): Promise<EventMessage[]>;
100
- }
101
- interface PublishOptions {
102
- /** Message attributes/headers */
103
- attributes?: Record<string, string>;
104
- /** Message group ID for FIFO queues */
105
- messageGroupId?: string;
106
- /** Message deduplication ID for FIFO queues */
107
- messageDeduplicationId?: string;
108
- /** Delay in seconds before the message becomes visible */
109
- delaySeconds?: number;
110
- }
111
- interface PeekOptions {
112
- /** Maximum number of messages to peek */
113
- maxMessages?: number;
114
- /** Wait time in seconds for long polling */
115
- waitTimeSeconds?: number;
116
- }
117
- interface ReadOptions extends PeekOptions {
118
- /** Visibility timeout in seconds */
119
- visibilityTimeout?: number;
120
- }
121
- interface EventMessage {
122
- /** Message ID */
123
- id: string;
124
- /** Message body */
125
- body: string;
126
- /** Message attributes/headers */
127
- attributes?: Record<string, string>;
128
- /** Message receipt handle (for operations like delete) */
129
- receiptHandle?: string;
130
- /** Message published timestamp */
131
- publishedAt: Date;
132
- }
133
-
134
- interface LocationService {
135
- /**
136
- * Search for places based on a query
137
- * @param query Search query
138
- * @param options Search options like bounding box, filters, etc.
139
- * @returns Promise containing search results
140
- */
141
- searchPlaces(query: string, options?: PlaceSearchOptions): Promise<PlaceSearchResult[]>;
142
- /**
143
- * Get detailed information about a specific place
144
- * @param placeId ID of the place to get details for
145
- * @returns Promise containing place details
146
- */
147
- getPlaceDetails(placeId: string): Promise<PlaceDetails>;
148
- }
149
- interface PlaceSearchOptions {
150
- /** Bounding box to search within */
151
- boundingBox?: {
152
- minLongitude: number;
153
- minLatitude: number;
154
- maxLongitude: number;
155
- maxLatitude: number;
156
- };
157
- /** Maximum number of results to return */
158
- maxResults?: number;
159
- /** Filter results by category */
160
- categories?: string[];
161
- /** Language code for results */
162
- language?: string;
163
- }
164
- interface PlaceSearchResult {
165
- /** Unique identifier for the place */
166
- placeId: string;
167
- /** Place name */
168
- text: string;
169
- }
170
- interface PlaceDetails extends PlaceSearchResult {
171
- /** Place address */
172
- address?: string;
173
- /** Geographic coordinates */
174
- coordinates: {
175
- latitude: number;
176
- longitude: number;
177
- };
178
- /** Distance from search center if applicable */
179
- distance?: number;
180
- /** Place categories/types */
181
- categories?: string[];
182
- /** Full formatted address */
183
- formattedAddress: string;
184
- /** Phone number */
185
- phoneNumber?: string;
186
- /** Website URL */
187
- website?: string;
188
- /** Opening hours */
189
- openingHours?: {
190
- periods: {
191
- day: number;
192
- open?: string;
193
- close?: string;
194
- }[];
195
- weekdayText?: string[];
196
- };
197
- /** Reviews if available */
198
- reviews?: {
199
- rating: number;
200
- text?: string;
201
- time?: number;
202
- }[];
203
- /** Additional place data */
204
- additionalData?: Record<string, any>;
205
- }
206
-
207
- interface StorageService {
208
- /**
209
- * Read data from storage
210
- * @param path Path to the file/object
211
- * @param bucket Bucket or container name
212
- * @returns Promise containing the file data
213
- */
214
- read(path: string, bucket: string): Promise<Buffer>;
215
- /**
216
- * Write data to storage
217
- * @param path Path where to store the file/object
218
- * @param data Data to write
219
- * @param bucket Bucket or container name
220
- * @param options Optional configuration for the write operation
221
- * @returns Promise resolving with the result including URL of the stored file
222
- */
223
- write(path: string, data: Buffer | string, bucket: string, options?: StorageWriteOptions): Promise<StorageWriteResult>;
224
- /**
225
- * Delete data from storage
226
- * @param path Path to the file/object to delete
227
- * @param bucket Bucket or container name
228
- * @returns Promise resolving when delete is complete
229
- */
230
- delete(path: string, bucket: string): Promise<void>;
231
- }
232
- interface StorageWriteOptions {
233
- /** Content type of the file */
234
- contentType?: string;
235
- /** Access control for the file (public, private, etc.) */
236
- acl?: 'private' | 'public-read' | 'public-read-write';
237
- /** Custom metadata to attach to the file */
238
- metadata?: Record<string, string>;
239
- }
240
- interface StorageWriteResult {
241
- /**
242
- * URL to access the stored file
243
- */
244
- url: string;
245
- /**
246
- * Storage bucket or container name
247
- */
248
- bucket: string;
249
- /**
250
- * Storage key or path
251
- */
252
- key: string;
253
- }
254
-
255
- /**
256
- * Represents the context object for a function handler.
257
- */
258
- type FunctionContext = {
259
- /**
260
- * The underlying context handler type.
261
- */
262
- type: HandlerType;
263
- /**
264
- * Creates a success response. This should be called when the handler is done successfully.
265
- * @param data - The response body.
266
- */
267
- success<T>(data: T): void;
268
- /**
269
- * Creates an error response. This should be called when the handler is done with an error.
270
- * @param message - The response body.
271
- *
272
- */
273
- error(message: string, code?: ErrorCode, details?: Record<string, any>, stack?: string): void;
274
- notFound(resource: string, id?: string | number): void;
275
- };
276
- /**
277
- * Error codes for API error responses
278
- */
279
- declare enum ErrorCode {
280
- VALIDATION_ERROR = "VALIDATION_ERROR",
281
- INVALID_INPUT = "INVALID_INPUT",
282
- UNAUTHORIZED = "UNAUTHORIZED",
283
- ACCESS_DENIED = "ACCESS_DENIED",
284
- RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND",
285
- RESOURCE_ALREADY_EXISTS = "RESOURCE_ALREADY_EXISTS",
286
- RESOURCE_CONFLICT = "RESOURCE_CONFLICT",
287
- INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR",
288
- SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",
289
- DATABASE_ERROR = "DATABASE_ERROR",
290
- BUSINESS_RULE_VIOLATION = "BUSINESS_RULE_VIOLATION",
291
- EXTERNAL_API_ERROR = "EXTERNAL_API_ERROR",
292
- UNKNOWN_ERROR = "UNKNOWN_ERROR"
293
- }
294
- type HTTPRequest = {
295
- method: HttpMethod;
296
- body?: string;
297
- headers: Record<string, string | string[] | undefined>;
298
- url: string;
299
- params: Record<string, string | undefined>;
300
- matchingKey?: string;
301
- rawQueryString?: string;
302
- requestId?: string;
303
- host?: string;
304
- };
305
- type HTTPResponse = {
306
- headers?: Record<string, string | string[] | undefined>;
307
- body?: string;
308
- status: number;
309
- };
310
- type HTTPAuth = {
311
- token: string;
312
- appId: string;
313
- memberId: string;
314
- customerId: string;
315
- claims: Record<string, string>;
316
- identity: "facebook" | "google" | "apple" | "password";
317
- };
318
- type HttpFunctionContext = FunctionContext & {
319
- type: "Http";
320
- request: HTTPRequest;
321
- auth?: HTTPAuth;
322
- response: HTTPResponse;
323
- model<T = Record<string, any>>(): T;
324
- params<T = Record<string, string>>(): T;
325
- list<T>(items: T[], page: number, pageSize: number, totalItems: number): void;
326
- created<T>(data: T): void;
327
- deleted(id?: string | number): void;
328
- validationError(details: Record<string, any>): void;
329
- serverError(err: Error): void;
330
- businessError(message: string, details?: Record<string, any>): void;
331
- output(status: number, body?: string, headers?: Record<string, string | string[]>): void;
332
- };
333
- type ScheduleResponse = {
334
- status: "success" | "error";
335
- body?: string | Record<string, any>;
336
- };
337
- type ScheduleRequest = {
338
- name: string;
339
- requestId?: string;
340
- };
341
- type ScheduleFunctionContext = FunctionContext & {
342
- response: ScheduleResponse;
343
- request: ScheduleRequest;
344
- type: "Schedule";
345
- };
346
- type EventRequest = {
347
- body: string | Record<string, any>;
348
- attributes: Record<string, string>;
349
- requestId?: string;
350
- timestamp: Date;
351
- attempts?: number;
352
- };
353
- type EventResponse = {
354
- status: "success" | "error";
355
- code?: ErrorCode;
356
- body?: Record<string, any>;
357
- stack?: string;
358
- };
359
- type EventFunctionContext = FunctionContext & {
360
- type: "Event";
361
- timestamp: Date;
362
- attempts?: number;
363
- response: EventResponse;
364
- message<T = Record<string, any>>(): T;
365
- attributes<T = Record<string, any>>(): T;
366
- };
367
- interface FunctionsService {
368
- createHttRequest(...args: any[]): [HTTPRequest, HTTPAuth?];
369
- createScheduleRequest(...args: any[]): [ScheduleRequest];
370
- createEventRequest(...args: any[]): [EventRequest];
371
- buildHttpResponse(httpFunctionContext: HttpFunctionContext, ...args: any[]): any;
372
- buildScheduleResponse(scheduleFunctionContext: ScheduleFunctionContext, ...args: any[]): any;
373
- buildEventResponse(eventFunctionContext: EventFunctionContext, ...args: any[]): any;
374
- }
375
-
376
- interface CloudProvider {
377
- name: string;
378
- createStorageService(): StorageService;
379
- createLocationService(): LocationService;
380
- createEventBrokerService(): EventBrokerService;
381
- createFunctionsService(): FunctionsService;
382
- }
383
-
384
- export { type BaseEntry, type CloudProvider, 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 LocationService, type MessageFilter, type PeekOptions, type PlaceDetails, type PlaceSearchOptions, type PlaceSearchResult, type PublishOptions, type ReadOptions, type ScheduleEntry, type ScheduleFunctionContext, type ScheduleRequest, type ScheduleResponse, type ScheduleTrigger, type StorageService, type StorageWriteOptions, type StorageWriteResult };
package/dist/index.mjs DELETED
@@ -1,21 +0,0 @@
1
- // src/services/functions.ts
2
- var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
3
- ErrorCode2["VALIDATION_ERROR"] = "VALIDATION_ERROR";
4
- ErrorCode2["INVALID_INPUT"] = "INVALID_INPUT";
5
- ErrorCode2["UNAUTHORIZED"] = "UNAUTHORIZED";
6
- ErrorCode2["ACCESS_DENIED"] = "ACCESS_DENIED";
7
- ErrorCode2["RESOURCE_NOT_FOUND"] = "RESOURCE_NOT_FOUND";
8
- ErrorCode2["RESOURCE_ALREADY_EXISTS"] = "RESOURCE_ALREADY_EXISTS";
9
- ErrorCode2["RESOURCE_CONFLICT"] = "RESOURCE_CONFLICT";
10
- ErrorCode2["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR";
11
- ErrorCode2["SERVICE_UNAVAILABLE"] = "SERVICE_UNAVAILABLE";
12
- ErrorCode2["DATABASE_ERROR"] = "DATABASE_ERROR";
13
- ErrorCode2["BUSINESS_RULE_VIOLATION"] = "BUSINESS_RULE_VIOLATION";
14
- ErrorCode2["EXTERNAL_API_ERROR"] = "EXTERNAL_API_ERROR";
15
- ErrorCode2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
16
- return ErrorCode2;
17
- })(ErrorCode || {});
18
- export {
19
- ErrorCode
20
- };
21
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
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"]}