@squidcloud/backend 1.0.145 → 1.0.146-beta

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.
Files changed (32) hide show
  1. package/dist/backend/src/actions.d.ts +480 -193
  2. package/dist/backend/src/index.d.ts +7 -3
  3. package/dist/backend/src/llm-service.d.ts +13 -0
  4. package/dist/backend/src/metadata.d.ts +1 -273
  5. package/dist/backend/src/metadata.spec.d.ts +1 -0
  6. package/dist/backend/src/project.d.ts +12 -7
  7. package/dist/backend/src/public-types.d.ts +15 -0
  8. package/dist/backend/src/squid.service.d.ts +143 -0
  9. package/dist/backend/src/utils.d.ts +3 -0
  10. package/dist/cjs/index.js +2 -0
  11. package/dist/cjs/index.js.LICENSE.txt +8 -0
  12. package/dist/esm/index.js +2 -0
  13. package/dist/esm/index.js.LICENSE.txt +8 -0
  14. package/dist/internal-common/src/public-types-backend/ai-agent.public-context.d.ts +71 -0
  15. package/dist/internal-common/src/public-types-backend/api-call.public-context.d.ts +30 -0
  16. package/dist/internal-common/src/public-types-backend/application.public-types.d.ts +94 -0
  17. package/dist/internal-common/src/public-types-backend/bundle-api.public-types.d.ts +178 -0
  18. package/dist/internal-common/src/public-types-backend/bundle-data.public-types.d.ts +46 -0
  19. package/dist/internal-common/src/public-types-backend/distributed-lock.public-context.d.ts +4 -0
  20. package/dist/internal-common/src/public-types-backend/graphql.public-context.d.ts +7 -0
  21. package/dist/internal-common/src/public-types-backend/llm.public-types.d.ts +10 -0
  22. package/dist/internal-common/src/public-types-backend/mcp.public-types.d.ts +31 -0
  23. package/dist/internal-common/src/public-types-backend/metric.public-context.d.ts +12 -0
  24. package/dist/internal-common/src/public-types-backend/mutation.public-context.d.ts +148 -0
  25. package/dist/internal-common/src/public-types-backend/native-query.public-context.d.ts +72 -0
  26. package/dist/internal-common/src/public-types-backend/query.public-context.d.ts +177 -0
  27. package/dist/internal-common/src/public-types-backend/storage.public-types.d.ts +15 -0
  28. package/dist/internal-common/src/public-types-backend/topic.public-context.d.ts +17 -0
  29. package/dist/node_modules/json-schema-typed/draft-2020-12.d.ts +1239 -0
  30. package/package.json +28 -9
  31. package/dist/backend/src/service.d.ts +0 -83
  32. package/dist/index.js +0 -2
@@ -1,3 +1,7 @@
1
- export * from './actions';
2
- export * from './project';
3
- export * from './service';
1
+ export * from './actions';
2
+ export * from './llm-service';
3
+ export * from './metadata';
4
+ export * from './project';
5
+ export * from './public-types';
6
+ export * from './squid.service';
7
+ export * from './utils';
@@ -0,0 +1,13 @@
1
+ import { UserAiAskResponse, UserAiChatOptions } from '@squidcloud/client';
2
+ import { SquidService } from './squid.service';
3
+ /**
4
+ * Abstract class representing a service for interacting with LLMs (Large Language Models).
5
+ */
6
+ export declare abstract class SquidLlmService extends SquidService {
7
+ /**
8
+ * Sends a prompt to the LLM and returns the response.
9
+ * @param prompt The prompt to send to the LLM.
10
+ * @param options Chat options to specify additional parameters for the request.
11
+ */
12
+ abstract ask(prompt: string, options: UserAiChatOptions): Promise<UserAiAskResponse>;
13
+ }
@@ -1,273 +1 @@
1
- import { AiChatbotActionType, AiFunctionParam, ApiEndpointId, ApplicationBundleData, CollectionName, DatabaseActionType, IntegrationId, QueryName, SchedulerId, ServiceFunctionName, TriggerId, WebhookId } from '@squidcloud/common';
2
- declare class Meta {
3
- data: ApplicationBundleData;
4
- /**
5
- * @secureDatabase("read", "ExampleIntegration")
6
- *
7
- * Applying the decorator above to the myMethod method on the MyService
8
- * class will generate the following metadata:
9
- *
10
- * data: {
11
- * databases: {
12
- * ExampleIntegration: {
13
- * security: {
14
- * read: ['MyService:myMethod']
15
- * }
16
- * }
17
- * }
18
- * }
19
- */
20
- secureDatabase(type: DatabaseActionType, serviceFunction: ServiceFunctionName, integrationId?: IntegrationId): void;
21
- /**
22
- * @secureCollection("ExampleCollection", "read", "ExampleIntegration")
23
- *
24
- * Applying the decorator above to the myMethod method on the MyService
25
- * class will generate the following metadata:
26
- *
27
- * data: {
28
- * databases: {
29
- * ExampleIntegration: {
30
- * collections: {
31
- * ExampleCollection: {
32
- * security: {
33
- * read: ['MyService:myMethod']
34
- * }
35
- * }
36
- * }
37
- * }
38
- * }
39
- * }
40
- */
41
- secureCollection(collectionName: CollectionName, type: DatabaseActionType, serviceFunction: ServiceFunctionName, integrationId?: IntegrationId): void;
42
- /**
43
- * @secureApi("ExampleIntegration", "myEndpoint")
44
- *
45
- * Applying the decorator above to the myMethod method on the MyService
46
- * class will generate the following metadata:
47
- *
48
- * data: {
49
- * apis: {
50
- * ExampleIntegration: {
51
- * myEndpoint: {
52
- * security: ['MyService:myMethod']
53
- * }
54
- * }
55
- * }
56
- * }
57
- */
58
- secureApi(integrationId: IntegrationId, endpointId: ApiEndpointId | undefined, serviceFunction: ServiceFunctionName): void;
59
- /**
60
- * @secureGraphQL("ExampleIntegration")
61
- *
62
- * Applying the decorator above to the myMethod method on the MyService
63
- * class will generate the following metadata:
64
- *
65
- * data: {
66
- * graphql: {
67
- * ExampleIntegration: {
68
- * security: ['MyService:myMethod']
69
- * }
70
- * }
71
- * }
72
- */
73
- secureGraphQL(integrationId: IntegrationId, serviceFunction: ServiceFunctionName): void;
74
- /**
75
- * @transformDatabase(""read", "ExampleIntegration")
76
- *
77
- * Applying the decorator above to the myMethod method on the MyService
78
- * class will generate the following metadata:
79
- *
80
- * data: {
81
- * databases: {
82
- * ExampleIntegration: {
83
- * transform: {
84
- * read: {
85
- * type: "read"
86
- * functionName: "MyService:myMethod"
87
- * }
88
- * }
89
- * }
90
- * }
91
- * }
92
- */
93
- transformDatabase(type: DatabaseActionType, serviceFunction: ServiceFunctionName, integrationId?: IntegrationId): void;
94
- /**
95
- * @transformCollection("ExampleCollection", "read", "ExampleIntegration")
96
- *
97
- * Applying the decorator above to the myMethod method on the MyService
98
- * class will generate the following metadata:
99
- *
100
- * data: {
101
- * databases: {
102
- * ExampleIntegration: {
103
- * collections: {
104
- * ExampleCollection: {
105
- * transform: {
106
- * read: {
107
- * type: "read"
108
- * functionName: "MyService:myMethod"
109
- * }
110
- * }
111
- * }
112
- * }
113
- * }
114
- * }
115
- * }
116
- */
117
- transformCollection(collectionName: CollectionName, type: DatabaseActionType, serviceFunction: ServiceFunctionName, integrationId?: IntegrationId): void;
118
- /**
119
- * @executable()
120
- *
121
- * Applying the decorator above to the myMethod method on the MyService
122
- * class will generate the following metadata:
123
- *
124
- * data: {
125
- * executables: {
126
- * myExecutable: {
127
- * serviceName: "MyService:myMethod",
128
- * }
129
- * }
130
- * }
131
- */
132
- executable(serviceFunction: ServiceFunctionName): void;
133
- /**
134
- * @aiFunction()
135
- * TODO: update docs
136
- * TODO: update all other functions to use Pick<> like we do here
137
- * Applying the decorator above to the myMethod method on the MyService
138
- * class will generate the following metadata:
139
- *
140
- * data: {
141
- * aiFunctions: {
142
- * myAiFunction: {
143
- * serviceName: "MyService:myMethod",
144
- * }
145
- * }
146
- * }
147
- */
148
- aiFunction(serviceFunction: ServiceFunctionName, description: string, params: Array<AiFunctionParam>): void;
149
- /**
150
- * @trigger("my-trigger", "ExampleCollection", "ExampleIntegration")
151
- *
152
- * Applying the decorator above to the myMethod method on the MyService
153
- * class will generate the following metadata:
154
- *
155
- * data: {
156
- * triggers: {
157
- * "my-trigger": {
158
- * integrationId: "ExampleIntegration"
159
- * collectionName: "ExampleCollection"
160
- * functionName: "MyService:myMethod",
161
- * }
162
- * }
163
- * }
164
- */
165
- trigger(id: TriggerId, collectionName: CollectionName, serviceFunction: ServiceFunctionName, integrationId?: IntegrationId): void;
166
- /**
167
- * @scheduler("my-scheduler", "CronExpression", true)
168
- *
169
- * Applying the decorator above to the myMethod method on the MyService
170
- * class will generate the following metadata:
171
- *
172
- * data: {
173
- * schedulers: {
174
- * "my-scheduler", {
175
- * cronExpression: "CronExpression"
176
- * functionName: "MyService:myMethod",
177
- * }
178
- * }
179
- * }
180
- */
181
- scheduler(id: SchedulerId, cronExpression: string, serviceFunction: ServiceFunctionName, exclusive: boolean): void;
182
- /**
183
- * @webhook("my-webhook")
184
- *
185
- * Applying the decorator above to the myMethod method on the MyService
186
- * class will generate the following metadata:
187
- *
188
- * data: {
189
- * webhooks: {
190
- * "my-webhook", {
191
- * functionName: "MyService:myMethod",
192
- * }
193
- * }
194
- * }
195
- */
196
- webhook(id: WebhookId, serviceFunction: ServiceFunctionName): void;
197
- /**
198
- * @namedQuery('exampleIntegration', 'my-query')
199
- * static myQuery = "select * from my-table where id = ${id}";
200
- *
201
- * Applying the decorator above to the myQuery static string in MyService
202
- * class will generate the following metadata:
203
- *
204
- *
205
- *
206
- * data: {
207
- * namedQueries: {
208
- * "exampleIntegration", {
209
- * my-query: {
210
- * queryString: "select * from my-table where id = $id"
211
- * }
212
- * }
213
- * }
214
- * }
215
- */
216
- namedQuery(integrationId: IntegrationId, name: QueryName, queryString: string): void;
217
- /**
218
- * @secureNamedQuery("exampleIntegration", "queryName")
219
- *
220
- * Applying the decorator above to the myMethod method on the MyService
221
- * class will generate the following metadata:
222
- *
223
- * data: {
224
- * namedQueries: {
225
- * exampleIntegration: {
226
- * queryName: {
227
- * security: MyService:myMethod
228
- * }
229
- * }
230
- * }
231
- * }
232
- */
233
- secureNamedQuery(integrationId: IntegrationId, name: QueryName, serviceFunction: ServiceFunctionName): void;
234
- secureNativeQuery(integrationId: IntegrationId, serviceFunction: ServiceFunctionName): void;
235
- /**
236
- * @secureDistributedLock("mutex", true)
237
- *
238
- * Applying the decorator above to the myMethod method on the MyService
239
- * class will generate the following metadata:
240
- *
241
- * data: {
242
- * distributedLocks: {
243
- * security: [MyService:myMethod]
244
- * }
245
- * }
246
- */
247
- secureDistributedLock(mutex: string | undefined, serviceFunction: ServiceFunctionName): void;
248
- /**
249
- * @secureAiChatbot(ExampleIntegration, "chat", myProfile)
250
- *
251
- * Applying the decorator above to the myMethod method on the MyService
252
- * class will generate the following metadata:
253
- *
254
- * data: {
255
- * aiChatbots: {
256
- * ExampleIntegration: {
257
- * myProfile: {
258
- * security: {
259
- * chat: ['MyService:myMethod']
260
- * }
261
- * }
262
- * }
263
- * }
264
- * }
265
- */
266
- secureAiChatbot(type: AiChatbotActionType, integrationId: IntegrationId, profileId: string | undefined, serviceFunction: ServiceFunctionName): void;
267
- clientConnectionChangeHandler(serviceFunction: ServiceFunctionName): void;
268
- }
269
- /**
270
- * @internal
271
- */
272
- export declare const metadata: Meta;
273
- export {};
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,12 @@
1
- /**
2
- * The SquidProject class is the entry point for the Squid backend project.
3
- */
4
- export declare class SquidProject {
5
- private metadata;
6
- private cleanup;
7
- }
1
+ import { Squid } from '@squidcloud/client';
2
+ /**
3
+ * The SquidProject class is the entry point for the Squid backend project.
4
+ */
5
+ export declare class SquidProject {
6
+ /**
7
+ * Initializes lifecycle metadata so the runtime knows which hooks the connector implements.
8
+ */
9
+ constructor();
10
+ /** Returns the main Squid instance with the current backend configuration. */
11
+ get squid(): Squid;
12
+ }
@@ -0,0 +1,15 @@
1
+ export * from '../../internal-common/src/public-types-backend/ai-agent.public-context';
2
+ export * from '../../internal-common/src/public-types-backend/api-call.public-context';
3
+ export * from '../../internal-common/src/public-types-backend/application.public-types';
4
+ export * from '../../internal-common/src/public-types-backend/bundle-api.public-types';
5
+ export * from '../../internal-common/src/public-types-backend/bundle-data.public-types';
6
+ export * from '../../internal-common/src/public-types-backend/distributed-lock.public-context';
7
+ export * from '../../internal-common/src/public-types-backend/graphql.public-context';
8
+ export * from '../../internal-common/src/public-types-backend/llm.public-types';
9
+ export * from '../../internal-common/src/public-types-backend/mcp.public-types';
10
+ export * from '../../internal-common/src/public-types-backend/metric.public-context';
11
+ export * from '../../internal-common/src/public-types-backend/mutation.public-context';
12
+ export * from '../../internal-common/src/public-types-backend/native-query.public-context';
13
+ export * from '../../internal-common/src/public-types-backend/query.public-context';
14
+ export * from '../../internal-common/src/public-types-backend/storage.public-types';
15
+ export * from '../../internal-common/src/public-types-backend/topic.public-context';
@@ -0,0 +1,143 @@
1
+ import { AiStatusMessage, AuthWithApiKey, AuthWithBearer, ClientId, RunContext, SecretKey, SecretValue, Squid, SquidRegion } from '@squidcloud/client';
2
+ import { SquidFile } from '../../internal-common/src/public-types-backend/bundle-api.public-types';
3
+ import { TenantModuleId } from '../../internal-common/src/public-types-backend/bundle-data.public-types';
4
+ /**
5
+ * A base class for all the different types of Squid backend services. This class serves as a container
6
+ * for the various methods implemented in the backend in order to customize the Squid backend for an application.
7
+ */
8
+ export declare class SquidService {
9
+ /**
10
+ * Your application's region. When developing locally, the region will be set to `local`.
11
+ */
12
+ readonly region: SquidRegion;
13
+ readonly backendBaseUrl: string;
14
+ private readonly config;
15
+ constructor();
16
+ /** The list of your application's secrets as defined in the Squid Console. */
17
+ get secrets(): Record<SecretKey, SecretValue>;
18
+ /** The list of your application's api keys. */
19
+ get apiKeys(): Record<SecretKey, string>;
20
+ /**
21
+ * The context object for the current request. This object contains information about the current request, such as
22
+ * the current user, the IP address, the user agent used, the request headers, and more.
23
+ */
24
+ get context(): RunContext;
25
+ /**
26
+ * Returns the Squid client instance for your application.
27
+ *
28
+ * @returns the Squid client instance for your application.
29
+ */
30
+ get squid(): Squid;
31
+ /**
32
+ * Returns the assets directory for your application.
33
+ *
34
+ * @returns the assets directory for your application.
35
+ */
36
+ get assetsDirectory(): string;
37
+ /**
38
+ * Returns the API key used by the backend for your application.
39
+ */
40
+ getApiKey(): string;
41
+ /**
42
+ * Returns the auth object for the current request or undefined if unauthenticated or if using an API key.
43
+ *
44
+ * @returns The auth object for the current request or undefined if unauthenticated or if using an API key.
45
+ */
46
+ getUserAuth(): AuthWithBearer | undefined;
47
+ /**
48
+ * Returns the auth object for the current request or undefined if unauthenticated or if using a user token.
49
+ *
50
+ * @returns The auth object for the current request or undefined if unauthenticated or if using a user token.
51
+ */
52
+ getApiKeyAuth(): AuthWithApiKey | undefined;
53
+ /**
54
+ * Returns true if the current request is authenticated (using a user token or an API key).
55
+ *
56
+ * @returns true if the current request is authenticated (using a user token or an API key).
57
+ */
58
+ isAuthenticated(): boolean;
59
+ /**
60
+ * Asserts that the current request is authenticated (using a user token or an API key).
61
+ * @throws UNAUTHORIZED if the current request is not authenticated.
62
+ */
63
+ assertIsAuthenticated(): void;
64
+ /**
65
+ * Asserts that the method is called within a valid request scope.
66
+ * Throws an error if no request context can be found.
67
+ */
68
+ assertInRequestScope(): void;
69
+ /**
70
+ * Asserts that the current method call includes an API key in the context.
71
+ * Throws an error if called without an API key.
72
+ */
73
+ assertApiKeyCall(): void;
74
+ /**
75
+ * A helper method to create a webhook response. This method should be used inside a webhook handler (function
76
+ * decorated with @webhook).
77
+ *
78
+ * @param body The body of the response.
79
+ * @param statusCode The status code of the response.
80
+ * @param headers The headers of the response.
81
+ * @returns The webhook response.
82
+ */
83
+ createWebhookResponse(body?: unknown, statusCode?: number, headers?: Record<string, unknown>): any;
84
+ /**
85
+ * Throws a webhook response. This function is useful when you want to interrupt normal execution
86
+ * and immediately return a response from a webhook handler.
87
+ *
88
+ * @param content The response content including optional body, status code, and headers.
89
+ * @throws An object marked as a webhook response.
90
+ */
91
+ throwWebhookResponse(content: Partial<{
92
+ body: unknown;
93
+ statusCode: number;
94
+ headers: Record<string, unknown>;
95
+ }>): never;
96
+ /**
97
+ * Constructs a response for an OpenAPI operation. This function is typically used within an OpenAPI handler.
98
+ *
99
+ * @param body The payload of the response. If not provided, defaults to an empty string.
100
+ * @param statusCode The HTTP status code for the response. Defaults to 200 if a body is present, otherwise 204.
101
+ * @param headers An object containing response headers. Defaults to an empty object if not provided.
102
+ * @returns The openapi response.
103
+ */
104
+ createOpenApiResponse(body?: unknown, statusCode?: number, headers?: Record<string, unknown>): any;
105
+ /**
106
+ * Throws an OpenAPI response. This function is useful when you want to interrupt normal execution
107
+ * and immediately return a response from an OpenAPI handler.
108
+ *
109
+ * @param content The response content including optional body, status code, and headers.
110
+ * @throws An object marked as an OpenAPI response.
111
+ */
112
+ throwOpenApiResponse(content: Partial<{
113
+ body: unknown;
114
+ statusCode: number;
115
+ headers: Record<string, unknown>;
116
+ }>): never;
117
+ /**
118
+ * Converts a file to a SquidFile object. This function is useful when you want to return a file using OpenAPI (tsoa
119
+ * decorators).
120
+ */
121
+ convertToSquidFile(file: File): Promise<SquidFile>;
122
+ /**
123
+ * Publishes an AI status update to a specific client. Can be used to notify the client about the status of an AI
124
+ * operation, such as a chat or an aiFunction.
125
+ */
126
+ publishAiStatusUpdate(update: AiStatusMessage, clientId: ClientId): Promise<void>;
127
+ }
128
+ /**
129
+ * Returns a singleton instance of Squid service. Creates the service if needed.
130
+ * Inherits code bundle info from the caller service: should only be called from the services within the same code
131
+ * bundle (user code, connector, etc...).
132
+ * @deprecated: Use `squidInject`.
133
+ * This method will be removed in the future.
134
+ */
135
+ export declare function getSquidService<T extends SquidService>(ctor: new () => T, callerService?: unknown): T;
136
+ /**
137
+ * Returns a singleton instance of Squid service. Creates the service if needed.
138
+ * This method can only be used after the Squid module is initialized:
139
+ * not from the static context when the module is loading.
140
+ */
141
+ export declare function squidInject<T extends SquidService>(ctor: new () => T, moduleId?: TenantModuleId): T;
142
+ /** Returns the main Squid instance with the current backend configuration. */
143
+ export declare function getSquid(): Squid;
@@ -0,0 +1,3 @@
1
+ import { WebhookResponse } from '../../internal-common/src/public-types-backend/bundle-api.public-types';
2
+ /** Builds a fully defined WebhookResponse using a partial model. */
3
+ export declare function createWebhookResponse(partialResponse: Partial<WebhookResponse>): WebhookResponse;