@squidcloud/client 1.0.189 → 1.0.191

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.
@@ -1,7 +1,7 @@
1
1
  import { MutationContext } from './mutation.public-context';
2
2
  import { ApiCallContext } from './api-call.public-context';
3
3
  import { QueryContext } from './query.public-context';
4
- import { AiChatbotActionType, DatabaseActionType, TopicActionType } from './bundle-data.public-types';
4
+ import { AiChatbotActionType, DatabaseActionType, StorageActionType, TopicActionType } from './bundle-data.public-types';
5
5
  import { ClientConnectionState } from './socket.public-types';
6
6
  import { DocumentData } from './document.public-types';
7
7
  import { MutationType } from './mutation.public-types';
@@ -11,7 +11,9 @@ import { NativeQueryContext } from './native-query.public-context';
11
11
  import { DistributedLockContext } from './distributed-lock.public-context';
12
12
  import { GraphqlContext } from './graphql.public-context';
13
13
  import { AiChatbotChatContext, AiChatbotMutationContext } from './ai-chatbot.public-context';
14
+ import { SecureStorageRequest } from './storage.types';
14
15
  export type SecureDatabaseAction<T extends DatabaseActionType> = T extends 'all' ? () => boolean | Promise<boolean> : T extends 'read' ? ((context: QueryContext) => boolean | Promise<boolean>) | (() => boolean | Promise<boolean>) : ((context: MutationContext) => boolean | Promise<boolean>) | (() => boolean | Promise<boolean>);
16
+ export type SecureStorageAction<T extends StorageActionType> = T extends 'all' ? () => boolean | Promise<boolean> : (request: SecureStorageRequest) => boolean | Promise<boolean>;
15
17
  export type SecureTopicAction<T extends TopicActionType> = T extends 'all' ? () => boolean | Promise<boolean> : T extends 'read' ? ((context: TopicReadContext) => boolean | Promise<boolean>) | (() => boolean | Promise<boolean>) : ((context: TopicWriteContext<T>) => boolean | Promise<boolean>) | (() => boolean | Promise<boolean>);
16
18
  export type SecureApiAction = ((context: ApiCallContext) => boolean | Promise<boolean>) | (() => boolean | Promise<boolean>);
17
19
  export type SecureNativeQueryAction = ((context: NativeQueryContext) => boolean | Promise<boolean>) | (() => boolean | Promise<boolean>);
@@ -1,5 +1,7 @@
1
1
  /** The different types of actions that can be performed on a database. */
2
2
  export type DatabaseActionType = 'read' | 'write' | 'update' | 'insert' | 'delete' | 'all';
3
+ /** The different types of actions that can be performed for storage. */
4
+ export type StorageActionType = 'read' | 'write' | 'update' | 'insert' | 'delete' | 'all';
3
5
  /** The different types of actions that can be performed on a topic. */
4
6
  export type TopicActionType = 'read' | 'write' | 'all';
5
7
  /** The different types of actions that can be performed on an AI chatbot. */
@@ -21,6 +21,8 @@ export declare enum IntegrationType {
21
21
  'kafka' = "kafka",
22
22
  'confluent' = "confluent",
23
23
  'built_in_queue' = "built_in_queue",
24
+ 's3' = "s3",
25
+ 'built_in_s3' = "built_in_s3",
24
26
  'algolia' = "algolia",
25
27
  'elastic_observability' = "elastic_observability",
26
28
  'elastic_search' = "elastic_search",
@@ -39,3 +39,6 @@ export interface DiscoverOpenApiSchemaRequest {
39
39
  integrationType: IntegrationType.api;
40
40
  discoveryOptions: OpenApiDiscoveryOptions;
41
41
  }
42
+ export interface DiscoverOpenApiSchemaFromFileRequest {
43
+ integrationType: IntegrationType.api;
44
+ }
@@ -0,0 +1,9 @@
1
+ import { IntegrationId } from './communication.public-types';
2
+ import { StorageActionType } from './bundle-data.public-types';
3
+ export type StorageFunctionality = 'fileUpload';
4
+ export interface SecureStorageRequest {
5
+ integrationId: IntegrationId;
6
+ pathsInBucket: Array<string>;
7
+ action: StorageActionType;
8
+ functionality: StorageFunctionality;
9
+ }
@@ -1 +1,10 @@
1
- export {};
1
+ /**
2
+ * Generates the regex pattern, handling special characters as follows:
3
+ * - `_` is replaced with a `.`
4
+ * - `%` is replaced with `[\s\S]*`.
5
+ * - The above characters can be escaped with \, eg. `\_` is replaced with `_` and `\%` with `%`.
6
+ * - All special characters in regex (-, /, \, ^, $, *, +, ?, ., (, ), |, [, ], {, }) get escaped with \
7
+ *
8
+ * Exported for testing purposes.
9
+ * */
10
+ export declare function replaceSpecialCharacters(input: string): string;
@@ -9,8 +9,14 @@ export declare function replaceKeyInRecord<K extends keyof any, T>(record: Recor
9
9
  export declare function isNil(obj: unknown): obj is null | undefined;
10
10
  export declare function isEqual(a: unknown, b: unknown): boolean;
11
11
  export declare function isEmpty(a: unknown): boolean;
12
- export declare function omit<T extends object, K extends (string | number | symbol)[]>(object: T | null | undefined, ...paths: K): Pick<T, Exclude<keyof T, K[number]>>;
12
+ export declare function omit<T extends object, K extends PropertyKey[]>(object: T | null | undefined, ...fieldsToRemove: K): Pick<T, Exclude<keyof T, K[number]>>;
13
13
  /** Creates a deep copy of the object. Copies all Date, Map, Set fields. */
14
14
  export declare function cloneDeep<T>(value: T): T;
15
+ /** Creates a shallow clone of the object. */
16
+ export declare function cloneShallow<T>(value: T): T;
15
17
  /** Compares 2 values. 'null' and 'undefined' values are considered equal and are less than any other values. */
16
- export declare function compareValues(a: any, b: any): number;
18
+ export declare function compareValues(v1: unknown, v2: unknown): number;
19
+ /** Returns a new object with all top-level object fields re-mapped using `valueMapperFn`. */
20
+ export declare function mapValues<ResultType extends object = Record<string, unknown>, InputType extends Record<string, unknown> = Record<string, unknown>>(obj: InputType, valueMapperFn: (value: any, key: keyof InputType, obj: InputType) => unknown): ResultType;
21
+ /** Groups elements of the array by key. See _.groupBy for details. */
22
+ export declare function groupBy<T, K extends PropertyKey>(array: T[], getKey: (item: T) => K): Record<K, T[]>;
@@ -40,3 +40,4 @@ export * from './socket.manager';
40
40
  export * from './squid-http-client';
41
41
  export * from './squid';
42
42
  export * from './types';
43
+ export * from './storage-client';
@@ -29,3 +29,4 @@ export * from '../../internal-common/src/public-types/serialized-query.public-ty
29
29
  export * from '../../internal-common/src/public-types/socket.public-types';
30
30
  export * from '../../internal-common/src/public-types/topic.public-context';
31
31
  export * from '../../internal-common/src/public-types/typescript.public-types';
32
+ export * from '../../internal-common/src/public-types/storage.types';
@@ -87,7 +87,7 @@ export declare abstract class BaseQueryBuilder<MyDocType extends DocumentData> {
87
87
  * A shortcut for where(fieldName, 'like', pattern).
88
88
  *
89
89
  * @param fieldName The name of the field to query.
90
- * @param pattern The pattern to compare against. '%' is the only allowed wildcard
90
+ * @param pattern The pattern to compare against. '%' matches 0 or more wildcard characters. '_' matches exactly one wildcard character. '\' can be used to escape '%', '_'. or another '\'. Note that any '\' that is not followed by '%', '_', or '\' is invalid.
91
91
  * @param caseSensitive Whether to use case-sensitive comparison. Defaults to true.
92
92
  * @returns The query builder.
93
93
  */
@@ -96,11 +96,12 @@ export declare abstract class BaseQueryBuilder<MyDocType extends DocumentData> {
96
96
  * A shortcut for where(fieldName, 'not like', pattern).
97
97
  *
98
98
  * @param fieldName The name of the field to query.
99
- * @param pattern The pattern to compare against. '%' is the only allowed wildcard
99
+ * @param pattern The pattern to compare against. '%' matches 0 or more wildcard characters. '_' matches exactly one wildcard character. '\' can be used to escape '%', '_'. or another '\'. Note that any '\' that is not followed by '%', '_', or '\' is invalid.
100
100
  * @param caseSensitive Whether to use case-sensitive comparison. Defaults to true.
101
101
  * @returns The query builder.
102
102
  */
103
103
  notLike(fieldName: (keyof MyDocType & FieldName) | string, pattern: string, caseSensitive?: boolean): this;
104
+ throwIfInvalidLikePattern(pattern: string): void;
104
105
  /**
105
106
  * Sets a limit to the number of results returned by the query. The maximum limit is 20,000 and the default is 1,000
106
107
  * if none is provided.
@@ -5,9 +5,10 @@ import { GraphQLClient } from './graphql-client';
5
5
  import { SecretClient } from './secret.client';
6
6
  import { TransactionId } from './types';
7
7
  import { AiClient } from './ai.types';
8
- import { ApiEndpointId, ApiKey, CallApiOptions, AppId, CollectionName, DocumentData, EnvironmentId, IntegrationId, NativeApiCallResponse, SquidDeveloperId, SquidRegion } from './public-types';
8
+ import { ApiEndpointId, ApiKey, AppId, CallApiOptions, CollectionName, DocumentData, EnvironmentId, IntegrationId, NativeApiCallResponse, SquidDeveloperId, SquidRegion } from './public-types';
9
9
  import { QueueManager } from './queue.manager';
10
10
  import { ApiClient } from './api-client';
11
+ import { StorageClient } from './storage-client';
11
12
  /** The different options that can be used to initialize a Squid instance. */
12
13
  export interface SquidOptions {
13
14
  /**
@@ -207,6 +208,7 @@ export declare class Squid {
207
208
  */
208
209
  ai(): AiClient;
209
210
  api(): ApiClient;
211
+ storage(integrationId?: IntegrationId): StorageClient;
210
212
  get secrets(): SecretClient;
211
213
  /**
212
214
  * Returns a distributed lock for the given mutex. The lock can be used to synchronize access to a shared resource.
@@ -216,6 +218,15 @@ export declare class Squid {
216
218
  * @returns A promise that resolves with the lock object. The promise will reject if failed to acquire the lock.
217
219
  */
218
220
  acquireLock(mutex: string): Promise<DistributedLock>;
221
+ /**
222
+ * Executes the given callback while holding a lock for the given mutex. The lock will be released when the callback
223
+ * finishes.
224
+ * @param mutex A string that uniquely identifies the lock.
225
+ * @param fn The callback to execute while holding the lock.
226
+ * @returns A promise that resolves with the result of the callback. The promise will reject if failed
227
+ * to acquire the lock.
228
+ */
229
+ withLock<T>(mutex: string, fn: (lock: DistributedLock) => Promise<T>): Promise<T>;
219
230
  /**
220
231
  * Returns a queue manager for the given topic name and integration id. Using the queue manager you can consume and
221
232
  * produce messages
@@ -0,0 +1,53 @@
1
+ import { BlobAndFilename } from './types';
2
+ import { IntegrationId } from '../../internal-common/src/public-types/communication.public-types';
3
+ export interface StorageFileUploadRequest {
4
+ integrationId: IntegrationId;
5
+ pathInBucket: string;
6
+ expirationInSeconds?: number;
7
+ }
8
+ export interface GetFileMetadataRequest {
9
+ integrationId: IntegrationId;
10
+ pathInBucket: string;
11
+ }
12
+ export interface GetFileMetadataResponse {
13
+ filename: string;
14
+ size: number;
15
+ lastModified: Date;
16
+ metadata: Record<string, string>;
17
+ }
18
+ export interface GetDownloadUrlRequest {
19
+ integrationId: IntegrationId;
20
+ pathInBucket: string;
21
+ urlExpirationInSeconds?: number;
22
+ }
23
+ export interface GetDownloadUrlResponse {
24
+ url: string;
25
+ }
26
+ export interface DeleteFilesRequest {
27
+ integrationId: IntegrationId;
28
+ pathsInBucket: Array<string>;
29
+ }
30
+ export interface ListDirectoryContentsRequest {
31
+ integrationId: IntegrationId;
32
+ pathInBucket: string;
33
+ }
34
+ export interface FileInDirectory {
35
+ filename: string;
36
+ absolutePathInBucket: string;
37
+ size: number;
38
+ lastModified: Date;
39
+ }
40
+ export interface ListDirectoryContentsResponse {
41
+ directories: Array<string>;
42
+ files: Array<FileInDirectory>;
43
+ }
44
+ export declare class StorageClient {
45
+ private readonly integrationId;
46
+ private readonly rpcManager;
47
+ uploadFile(pathInBucket: string, file: File | BlobAndFilename, expirationInSeconds?: number): Promise<void>;
48
+ getFileMetadata(pathInBucket: string): Promise<GetFileMetadataResponse>;
49
+ getDownloadUrl(pathInBucket: string, urlExpirationInSeconds?: number): Promise<GetDownloadUrlResponse>;
50
+ listDirectoryContents(pathInBucket: string): Promise<ListDirectoryContentsResponse>;
51
+ deleteFile(pathInBucket: string): Promise<void>;
52
+ deleteFiles(pathsInBucket: Array<string>): Promise<void>;
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squidcloud/client",
3
- "version": "1.0.189",
3
+ "version": "1.0.191",
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",
@@ -40,7 +40,6 @@
40
40
  "ajv": "^8.11.2",
41
41
  "ajv-formats": "^2.1.1",
42
42
  "bufferutil": "^4.0.7",
43
- "cross-fetch": "^3.1.5",
44
43
  "date-fns": "^2.30.0",
45
44
  "deep-diff": "^1.0.2",
46
45
  "graphql": "^16.6.0",
@@ -1,8 +0,0 @@
1
- export declare function setSquidPrivateOption<T = unknown>(optionName: string, value: T): void;
2
- export declare function getSquidPrivateOption<T = unknown>(optionName: string): T | undefined;
3
- /**
4
- * When set to 'true' (boolean), the Graphql client in Squid uses new 'fetch' based
5
- * HTTP client instead of cross-fetch library.
6
- * The option will be removed after the migration is tested and all issues are fixed.
7
- */
8
- export declare const SQUID_PRIVATE_OPTION_USE_FETCH_IN_GRAPHQL_CLIENT = "useFetchInGraphqlClient";