@squidcloud/client 1.0.130 → 1.0.132

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/cjs/index.js CHANGED
@@ -30692,6 +30692,7 @@ function createWebSocketWrapper(url, opts = {}) {
30692
30692
 
30693
30693
 
30694
30694
 
30695
+
30695
30696
 
30696
30697
 
30697
30698
 
@@ -49213,10 +49214,6 @@ class RpcManager {
49213
49214
  for (const [key, value] of Object.entries(headers)) {
49214
49215
  this.setStaticHeader(key, value);
49215
49216
  }
49216
- const apiKey = this.authManager.getApiKey();
49217
- if (apiKey) {
49218
- this.setStaticHeader('Authorization', `ApiKey ${apiKey}`);
49219
- }
49220
49217
  this.clientIdService.observeClientId().subscribe(clientId => {
49221
49218
  if (clientId) {
49222
49219
  this.setStaticHeader('x-squid-clientid', clientId);
@@ -49228,6 +49225,7 @@ class RpcManager {
49228
49225
  destructManager.onDestruct(async () => {
49229
49226
  await this.awaitAllSettled();
49230
49227
  });
49228
+ const apiKey = this.authManager.getApiKey();
49231
49229
  const rateLimiterMultiplier = apiKey ? 5 : 1;
49232
49230
  this.rateLimiters = {
49233
49231
  default: new RateLimiter(60 * rateLimiterMultiplier, 5),
@@ -49236,6 +49234,10 @@ class RpcManager {
49236
49234
  };
49237
49235
  }
49238
49236
  async getAuthHeaders() {
49237
+ const apiKey = this.authManager.getApiKey();
49238
+ if (apiKey) {
49239
+ return { Authorization: `ApiKey ${apiKey}` };
49240
+ }
49239
49241
  const { token, integrationId } = await this.authManager.getAuthData();
49240
49242
  if (!token)
49241
49243
  return {};
@@ -49736,6 +49738,7 @@ class Squid {
49736
49738
  * @param options The options for initializing the Squid instance.
49737
49739
  */
49738
49740
  constructor(options) {
49741
+ this.options = options;
49739
49742
  this.destructManager = new DestructManager();
49740
49743
  // Note: The following methods are bound using arrow functions to ensure that if a user accesses the methods via
49741
49744
  // destructuring (i.e. `{ setAuthIdToken } = squid`) then `this` will still be bound to the Squid class.
@@ -49834,6 +49837,30 @@ class Squid {
49834
49837
  this.executeNativeRelationalQuery = (integrationId, query, params = {}) => {
49835
49838
  return this.nativeQueryManager.executeNativeQuery(integrationId, { type: 'relational', query, params });
49836
49839
  };
49840
+ /**
49841
+ * Executes a native MongoDB aggregation pipeline with the given parameters and returns a promise with the result.
49842
+ *
49843
+ * Native queries allow you to execute raw MongoDB queries directly against the database.
49844
+ * This can be particularly useful when you need to perform complex operations or aggregations that are not
49845
+ * easily accomplished with standard query methods or other high-level abstractions provided by the database driver or ORM.
49846
+ *
49847
+ * @param {IntegrationId} integrationId - The id of the integration that the query is associated with.
49848
+ * @param {string} collectionName - The name of the MongoDB collection to run the aggregation pipeline against.
49849
+ * @param {Array<Record<string, any>>} [aggregationPipeline=[]] - The array of aggregation stages to be executed.
49850
+ * Each stage in the pipeline is an object specifying the operation to be performed.
49851
+ * @returns {Promise<Array<T>>} A promise that resolves with an array of documents resulting from the aggregation pipeline.
49852
+ * Each document in the array is of the generic type T, which can be specified when calling the function.
49853
+ * @template T - The type of the documents that are expected to be returned by the aggregation pipeline. If not specified,
49854
+ * any type is assumed by default.
49855
+ * @type {Promise<Array<SquidDocument>>}
49856
+ */
49857
+ this.executeNativeMongoQuery = (integrationId, collectionName, aggregationPipeline = []) => {
49858
+ return this.nativeQueryManager.executeNativeQuery(integrationId, {
49859
+ type: 'mongo',
49860
+ collectionName,
49861
+ aggregationPipeline,
49862
+ });
49863
+ };
49837
49864
  /**
49838
49865
  * Invokes the given HTTP API (defined by the integration ID and the endpoint ID) with the given request parameters
49839
49866
  * and returns a promise with the response. The structure of the request and the response is defined in the
@@ -26,6 +26,7 @@ export * from './named-query.context';
26
26
  export * from './named-query.schemas';
27
27
  export * from './named-query.types';
28
28
  export * from './native-query.context';
29
+ export * from './native-query.types';
29
30
  export * from './query';
30
31
  export * from './query.types';
31
32
  export * from './regions';
@@ -118,7 +118,7 @@ export type ObservabilityIntegrationType = (typeof ObservabilityIntegrationTypes
118
118
  export type ObservabilityIntegrationConfig = IntegrationConfigTypes[ObservabilityIntegrationType];
119
119
  export type AuthIntegrationType = (typeof AuthIntegrationTypes)[number];
120
120
  export type AuthIntegrationConfig = IntegrationConfigTypes[AuthIntegrationType];
121
- export declare function isDataIntegrationType(type: IntegrationType): type is DatabaseIntegrationType;
121
+ export declare function isDataIntegrationType(type: unknown): type is DatabaseIntegrationType;
122
122
  export declare function isDataIntegration(integration: any): integration is BaseDatabaseIntegrationConfig;
123
123
  export declare function isAuthIntegrationType(type: IntegrationType): type is AuthIntegrationType;
124
124
  export declare function isAuthIntegration(integration: any): integration is AuthIntegrationConfig;
@@ -0,0 +1,16 @@
1
+ export type NativeQueryRequestType = 'relational' | 'mongo';
2
+ interface BaseNativeQueryRequest {
3
+ type: NativeQueryRequestType;
4
+ }
5
+ export interface RelationalNativeQueryRequest extends BaseNativeQueryRequest {
6
+ type: 'relational';
7
+ query: string;
8
+ params: Record<string, any>;
9
+ }
10
+ export interface MongoNativeQueryRequest extends BaseNativeQueryRequest {
11
+ type: 'mongo';
12
+ collectionName: string;
13
+ aggregationPipeline: Array<any | undefined>;
14
+ }
15
+ export type NativeQueryRequest = RelationalNativeQueryRequest | MongoNativeQueryRequest;
16
+ export {};
@@ -5,5 +5,6 @@ export interface ExecuteAiQueryRequest {
5
5
  }
6
6
  export interface ExecuteAiQueryResponse {
7
7
  answer: string;
8
+ explanation?: string;
8
9
  executedQuery?: string;
9
10
  }
@@ -1,18 +1,7 @@
1
- import { IntegrationId } from '@squidcloud/common';
1
+ import { IntegrationId, NativeQueryRequest } from '@squidcloud/common';
2
2
  import { RpcManager } from './rpc.manager';
3
- export type NativeQueryRequestType = 'relational';
4
- interface BaseNativeQueryRequest {
5
- type: NativeQueryRequestType;
6
- }
7
- export interface RelationalNativeQueryRequest extends BaseNativeQueryRequest {
8
- type: 'relational';
9
- query: string;
10
- params: Record<string, any>;
11
- }
12
- export type NativeQueryRequest = RelationalNativeQueryRequest;
13
3
  export declare class NativeQueryManager {
14
4
  private readonly rpcManager;
15
5
  constructor(rpcManager: RpcManager);
16
6
  executeNativeQuery<T>(integrationId: IntegrationId, request: NativeQueryRequest): Promise<T>;
17
7
  }
18
- export {};
@@ -68,6 +68,7 @@ export type AuthTokenProvider = (integrationId?: string) => Promise<string | und
68
68
  * capabilities.
69
69
  */
70
70
  export declare class Squid {
71
+ readonly options: SquidOptions;
71
72
  private readonly socketManager;
72
73
  private readonly rpcManager;
73
74
  private readonly dataManager;
@@ -192,6 +193,24 @@ export declare class Squid {
192
193
  * @type {Promise<Array<SquidDocument>>}
193
194
  */
194
195
  executeNativeRelationalQuery: <T = any>(integrationId: IntegrationId, query: string, params?: Record<string, any>) => Promise<T[]>;
196
+ /**
197
+ * Executes a native MongoDB aggregation pipeline with the given parameters and returns a promise with the result.
198
+ *
199
+ * Native queries allow you to execute raw MongoDB queries directly against the database.
200
+ * This can be particularly useful when you need to perform complex operations or aggregations that are not
201
+ * easily accomplished with standard query methods or other high-level abstractions provided by the database driver or ORM.
202
+ *
203
+ * @param {IntegrationId} integrationId - The id of the integration that the query is associated with.
204
+ * @param {string} collectionName - The name of the MongoDB collection to run the aggregation pipeline against.
205
+ * @param {Array<Record<string, any>>} [aggregationPipeline=[]] - The array of aggregation stages to be executed.
206
+ * Each stage in the pipeline is an object specifying the operation to be performed.
207
+ * @returns {Promise<Array<T>>} A promise that resolves with an array of documents resulting from the aggregation pipeline.
208
+ * Each document in the array is of the generic type T, which can be specified when calling the function.
209
+ * @template T - The type of the documents that are expected to be returned by the aggregation pipeline. If not specified,
210
+ * any type is assumed by default.
211
+ * @type {Promise<Array<SquidDocument>>}
212
+ */
213
+ executeNativeMongoQuery: <T = any>(integrationId: IntegrationId, collectionName: string, aggregationPipeline?: Array<Record<string, any>>) => Promise<T[]>;
195
214
  /**
196
215
  * Invokes the given HTTP API (defined by the integration ID and the endpoint ID) with the given request parameters
197
216
  * and returns a promise with the response. The structure of the request and the response is defined in the
@@ -232,6 +251,30 @@ export declare class Squid {
232
251
  * @returns An AI Assistant client.
233
252
  */
234
253
  assistant: (integrationId: IntegrationId) => AiAssistantClient;
254
+ /**
255
+ * Executes an AI query using a specific DB integration, sending a prompt to the AI and returning its response.
256
+ * This function allows for direct interaction with the AI's capabilities by sending text prompts and receiving
257
+ * the AI's responses, which can be used for various applications such as automating tasks, generating content,
258
+ * or obtaining information.
259
+ *
260
+ * @param integrationId The identifier for the DB integration which is used to direct the query to the
261
+ * appropriate DB.
262
+ * @param prompt The text prompt to send to the AI. This should be formulated in a way that the AI can
263
+ * understand and respond to, taking into account the nature of the task or the information
264
+ * sought.
265
+ * @returns A promise that resolves to an `ExecuteAiQueryResponse`. This response includes the AI's
266
+ * reply to the provided prompt, along with any other relevant information that is part of
267
+ * the AI's response. The promise can be awaited to handle the response asynchronously.
268
+ *
269
+ * @example
270
+ * ```
271
+ * const response = await ai().executeAiQuery(myDbIntegrationId, "How many transactions ran yesterday?");
272
+ * console.log(response);
273
+ * ```
274
+ *
275
+ * For more details on the usage and capabilities of the AI Assistant, refer to the documentation provided at
276
+ * {@link https://docs.squid.cloud/docs/ai}.
277
+ */
235
278
  executeAiQuery: (integrationId: IntegrationId, prompt: string) => Promise<ExecuteAiQueryResponse>;
236
279
  };
237
280
  get secrets(): SecretClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squidcloud/client",
3
- "version": "1.0.130",
3
+ "version": "1.0.132",
4
4
  "description": "A typescript implementation of the Squid client",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/typescript-client/src/index.d.ts",
@@ -49,11 +49,7 @@
49
49
  "assertic": "^1.0.0",
50
50
  "copy-webpack-plugin": "^11.0.0",
51
51
  "cpx": "^1.5.0",
52
- "eslint": "8.22.0",
53
- "eslint-config-prettier": "^8.3.0",
54
- "eslint-plugin-prettier": "^4.0.0",
55
52
  "generate-package-json-webpack-plugin": "^2.6.0",
56
- "prettier": "^2.8.0",
57
53
  "tsconfig-paths-webpack-plugin": "^4.0.0",
58
54
  "tscpaths": "^0.0.9",
59
55
  "webpack": "^5.75.0",