@squidcloud/client 1.0.188 → 1.0.190

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 (35) hide show
  1. package/dist/cjs/index.js +21383 -21132
  2. package/dist/internal-common/src/public-types/bundle-api.public-types.d.ts +3 -1
  3. package/dist/internal-common/src/public-types/bundle-data.public-types.d.ts +2 -0
  4. package/dist/internal-common/src/public-types/integration.public-types.d.ts +2 -9
  5. package/dist/internal-common/src/public-types/integrations/api.public-types.d.ts +3 -0
  6. package/dist/internal-common/src/public-types/storage.types.d.ts +9 -0
  7. package/dist/internal-common/src/types/query.types.d.ts +10 -1
  8. package/dist/internal-common/src/utils/object.d.ts +6 -2
  9. package/dist/typescript-client/src/ai-assistant-client.d.ts +0 -2
  10. package/dist/typescript-client/src/ai-chatbot-client.d.ts +20 -25
  11. package/dist/typescript-client/src/api.manager.d.ts +1 -10
  12. package/dist/typescript-client/src/auth.manager.d.ts +1 -22
  13. package/dist/typescript-client/src/backend-function.manager.d.ts +1 -9
  14. package/dist/typescript-client/src/client-id.service.d.ts +1 -27
  15. package/dist/typescript-client/src/collection-reference.d.ts +2 -1
  16. package/dist/typescript-client/src/graphql-client.d.ts +1 -3
  17. package/dist/typescript-client/src/graphql-client.factory.d.ts +1 -11
  18. package/dist/typescript-client/src/index.d.ts +41 -10
  19. package/dist/typescript-client/src/native-query-manager.d.ts +1 -7
  20. package/dist/typescript-client/src/public-types.d.ts +1 -2
  21. package/dist/typescript-client/src/query/deserializer.d.ts +2 -1
  22. package/dist/typescript-client/src/query/join-query-builder.factory.d.ts +12 -2
  23. package/dist/{internal-common/src/public-types/pagination.public-types.d.ts → typescript-client/src/query/pagination.d.ts} +1 -1
  24. package/dist/typescript-client/src/query/query-builder.factory.d.ts +118 -10
  25. package/dist/typescript-client/src/query/snapshot-emitter.d.ts +34 -0
  26. package/dist/typescript-client/src/rate-limiter.d.ts +1 -32
  27. package/dist/typescript-client/src/rpc.manager.d.ts +1 -24
  28. package/dist/typescript-client/src/secret.client.d.ts +1 -5
  29. package/dist/typescript-client/src/squid-http-client.d.ts +0 -9
  30. package/dist/typescript-client/src/squid.d.ts +12 -1
  31. package/dist/typescript-client/src/storage-client.d.ts +53 -0
  32. package/package.json +1 -1
  33. package/dist/internal-common/src/public-types/base-query-builder.public-types.d.ts +0 -147
  34. package/dist/typescript-client/src/backend-transforms.d.ts +0 -0
  35. /package/dist/{typescript-client/src/testing/setup-tests.d.ts → internal-common/src/types/integrations/storage-types.d.ts} +0 -0
@@ -0,0 +1,34 @@
1
+ import { Observable } from 'rxjs';
2
+ import { Pagination, PaginationOptions } from './pagination';
3
+ export interface SnapshotEmitter<ReturnType> {
4
+ /**
5
+ * Returns a promise that resolves to the query results.
6
+ *
7
+ * @returns A promise that resolves to the query results.
8
+ */
9
+ snapshot(): Promise<Array<ReturnType>>;
10
+ /**
11
+ * Returns an observable that emits the query results and updates whenever the query results change unless
12
+ * `subscribe=false` is provided.
13
+ *
14
+ * Important: Make sure to unsubscribe from the observable when you are done with it.
15
+ *
16
+ * @param subscribe Whether to subscribe to changes to the query results. Defaults to `true`.
17
+ * @returns An observable for the query results.
18
+ */
19
+ snapshots(subscribe?: boolean): Observable<Array<ReturnType>>;
20
+ /**
21
+ * Returns the results of the query based on the data that is currently available on the client. This method is useful
22
+ * for synchronously accessing data that has already been fetched by another query. The method will return an empty
23
+ * array if data has not yet been populated.
24
+ *
25
+ * @returns An array of query results.
26
+ */
27
+ peek(): Array<ReturnType>;
28
+ limit(limit: number): SnapshotEmitter<ReturnType>;
29
+ /**
30
+ * Returns a pagination wrapper for this query.
31
+ * @param options The pagination options. Defaults to `{ subscribe: true, pageSize: 100 }`.
32
+ */
33
+ paginate(options?: Partial<PaginationOptions>): Pagination<ReturnType>;
34
+ }
@@ -1,32 +1 @@
1
- export declare class RateLimiter {
2
- private readonly capacity;
3
- private readonly seconds;
4
- private tokens;
5
- private lastRefillTimestamp;
6
- private readonly refillRatePerMs;
7
- /**
8
- * Creates a new rate limiter. It limits the number of requests using two parameters:
9
- * - capacity: the maximum number of tokens (actions) that can be stored at any given time
10
- * - seconds: the number of seconds it takes to refill the bucket to its maximum capacity
11
- *
12
- * We then can calculate the refillRatePerMs: the number of tokens (actions) that are added to the bucket every
13
- * millisecond
14
- *
15
- * Example:
16
- * Say we want to allow maximum 60 requests in a period of 5 seconds. We can create a rate limiter with:
17
- * - capacity: 60
18
- * - seconds: 5
19
- * And we will get refillRatePerMs: 60 / (5 * 1000) = 0.012
20
- *
21
- * To use:
22
- * const rateLimiter = new RateLimiter(60, 5);
23
- * await rateLimiter.consume();
24
- *
25
- * @param capacity
26
- * @param refillRatePerMs
27
- */
28
- constructor(capacity: number, seconds: number);
29
- consume(): Promise<void>;
30
- private attemptConsume;
31
- private refill;
32
- }
1
+ export {};
@@ -1,24 +1 @@
1
- import { AuthManager } from './auth.manager';
2
- import { ClientIdService } from './client-id.service';
3
- import { DestructManager } from './destruct.manager';
4
- import { BlobAndFilename } from './types';
5
- import { SquidRegion } from './public-types';
6
- import { HttpResponse } from './squid-http-client';
7
- export declare class RpcManager {
8
- private readonly region;
9
- private readonly appId;
10
- private readonly authManager;
11
- private readonly clientIdService;
12
- private readonly staticHeaders;
13
- private readonly onGoingRpcCounter;
14
- private readonly rateLimiters;
15
- constructor(region: SquidRegion, appId: string, destructManager: DestructManager, headers: Record<string, string>, authManager: AuthManager, clientIdService: ClientIdService);
16
- private getAuthHeaders;
17
- awaitAllSettled(): Promise<void>;
18
- setStaticHeader(key: string, value: string): void;
19
- deleteStaticHeader(key: string): void;
20
- getStaticHeaders(): Record<string, string>;
21
- post<ResponseType = unknown, RequestType = unknown>(path: string, message: RequestType, files?: Array<File | BlobAndFilename>, filesFieldName?: string): Promise<ResponseType>;
22
- rawPost<ResponseType = unknown, RequestType = unknown>(path: string, message: RequestType, files?: Array<File | BlobAndFilename>, filesFieldName?: string, extractErrorMessage?: boolean): Promise<HttpResponse<ResponseType>>;
23
- private getRateLimiterBucket;
24
- }
1
+ export {};
@@ -1,8 +1,6 @@
1
1
  import { SecretEntry, SecretKey, SecretValue, SetSecretRequestEntry } from './public-types';
2
- import { RpcManager } from './rpc.manager';
3
2
  export declare class SecretClient {
4
3
  private readonly rpcManager;
5
- constructor(rpcManager: RpcManager);
6
4
  get(key: SecretKey): Promise<SecretEntry | undefined>;
7
5
  getAll(): Promise<Record<SecretKey, SecretEntry>>;
8
6
  upsert(key: SecretKey, value: SecretValue): Promise<SecretEntry>;
@@ -11,12 +9,10 @@ export declare class SecretClient {
11
9
  deleteMany(keys: Array<SecretKey>): Promise<void>;
12
10
  get apiKeys(): ApiKeysSecretClient;
13
11
  }
14
- declare class ApiKeysSecretClient {
12
+ export declare class ApiKeysSecretClient {
15
13
  private readonly rpcManager;
16
- constructor(rpcManager: RpcManager);
17
14
  get(key: SecretKey): Promise<SecretEntry | undefined>;
18
15
  getAll(): Promise<Record<SecretKey, SecretEntry>>;
19
16
  upsert(key: SecretKey): Promise<SecretEntry>;
20
17
  delete(key: SecretKey): Promise<void>;
21
18
  }
22
- export {};
@@ -1,4 +1,3 @@
1
- import { BlobAndFilename } from './types';
2
1
  export declare class RpcError<BodyType = unknown> extends Error {
3
2
  readonly statusCode: number;
4
3
  readonly statusText: string;
@@ -6,14 +5,6 @@ export declare class RpcError<BodyType = unknown> extends Error {
6
5
  readonly headers: Record<string, string>;
7
6
  readonly body: BodyType;
8
7
  }
9
- export interface HttpPostInput<RequestBodyType = unknown> {
10
- url: string;
11
- headers: Record<string, string>;
12
- message: RequestBodyType;
13
- files: Array<File | BlobAndFilename>;
14
- filesFieldName: string;
15
- extractErrorMessage: boolean;
16
- }
17
8
  /** A response object with type T for the body. */
18
9
  export interface HttpResponse<BodyType = unknown> {
19
10
  status: number;
@@ -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.188",
3
+ "version": "1.0.190",
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",
@@ -1,147 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { SerializedQuery } from './serialized-query.public-types';
3
- import { Pagination, PaginationOptions } from './pagination.public-types';
4
- import { Operator } from './query.public-types';
5
- import { DocumentData, FieldName, PrimitiveFieldType } from './document.public-types';
6
- export interface SnapshotEmitter<ReturnType> {
7
- /**
8
- * Returns a promise that resolves to the query results.
9
- *
10
- * @returns A promise that resolves to the query results.
11
- */
12
- snapshot(): Promise<Array<ReturnType>>;
13
- /**
14
- * Returns an observable that emits the query results and updates whenever the query results change unless
15
- * `subscribe=false` is provided.
16
- *
17
- * Important: Make sure to unsubscribe from the observable when you are done with it.
18
- *
19
- * @param subscribe Whether to subscribe to changes to the query results. Defaults to `true`.
20
- * @returns An observable for the query results.
21
- */
22
- snapshots(subscribe?: boolean): Observable<Array<ReturnType>>;
23
- /**
24
- * Returns the results of the query based on the data that is currently available on the client. This method is useful
25
- * for synchronously accessing data that has already been fetched by another query. The method will return an empty
26
- * array if data has not yet been populated.
27
- *
28
- * @returns An array of query results.
29
- */
30
- peek(): Array<ReturnType>;
31
- limit(limit: number): SnapshotEmitter<ReturnType>;
32
- /**
33
- * Returns a pagination wrapper for this query.
34
- * @param options The pagination options. Defaults to `{ subscribe: true, pageSize: 100 }`.
35
- */
36
- paginate(options?: Partial<PaginationOptions>): Pagination<ReturnType>;
37
- serialize(): SerializedQuery;
38
- }
39
- /** Query builder base class. */
40
- export declare abstract class BaseQueryBuilder<MyDocType extends DocumentData> {
41
- /**
42
- * Adds a condition to the query.
43
- * @param fieldName The name of the field to query.
44
- * @param operator The operator to use.
45
- * @param value The value to compare against.
46
- * @returns The query builder.
47
- */
48
- abstract where(fieldName: (keyof MyDocType & FieldName) | string, operator: Operator | 'in' | 'not in', value: PrimitiveFieldType | Array<PrimitiveFieldType>): this;
49
- /**
50
- * A shortcut for where(fieldName, '==', value)
51
- *
52
- * @param fieldName The name of the field to query.
53
- * @param value The value to compare against.
54
- * @returns The query builder.
55
- */
56
- eq(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
57
- /**
58
- * A shortcut for where(fieldName, '!=', value)
59
- * @param fieldName The name of the field to query.
60
- * @param value The value to compare against.
61
- * @returns The query builder.
62
- */
63
- neq(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
64
- /**
65
- * A shortcut for where(fieldName, 'in', value)
66
- * @param fieldName The name of the field to query.
67
- * @param value An array of values to compare against.
68
- * @returns The query builder.
69
- */
70
- in(fieldName: (keyof MyDocType & FieldName) | string, value: Array<PrimitiveFieldType>): this;
71
- /**
72
- * A shortcut for where(fieldName, 'not in', value)
73
- * @param fieldName The name of the field to query.
74
- * @param value An array of values to compare against.
75
- * @returns The query builder.
76
- */
77
- nin(fieldName: (keyof MyDocType & FieldName) | string, value: Array<PrimitiveFieldType>): this;
78
- /**
79
- * A shortcut for where(fieldName, '>', value)
80
- * @param fieldName The name of the field to query.
81
- * @param value The value to compare against.
82
- * @returns The query builder.
83
- */
84
- gt(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
85
- /**
86
- * A shortcut for where(fieldName, '>=', value)
87
- * @param fieldName The name of the field to query.
88
- * @param value The value to compare against.
89
- * @returns The query builder.
90
- */
91
- gte(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
92
- /**
93
- * A shortcut for where(fieldName, '<', value)
94
- * @param fieldName The name of the field to query.
95
- * @param value The value to compare against.
96
- * @returns The query builder.
97
- */
98
- lt(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
99
- /**
100
- * A shortcut for where(fieldName, '<=', value)
101
- * @param fieldName The name of the field to query.
102
- * @param value The value to compare against.
103
- * @returns The query builder.
104
- */
105
- lte(fieldName: (keyof MyDocType & FieldName) | string, value: PrimitiveFieldType): this;
106
- /**
107
- * A shortcut for where(fieldName, 'like', pattern).
108
- *
109
- * @param fieldName The name of the field to query.
110
- * @param pattern The pattern to compare against. '%' is the only allowed wildcard
111
- * @param caseSensitive Whether to use case-sensitive comparison. Defaults to true.
112
- * @returns The query builder.
113
- */
114
- like(fieldName: (keyof MyDocType & FieldName) | string, pattern: string, caseSensitive?: boolean): this;
115
- /**
116
- * A shortcut for where(fieldName, 'not like', pattern).
117
- *
118
- * @param fieldName The name of the field to query.
119
- * @param pattern The pattern to compare against. '%' is the only allowed wildcard
120
- * @param caseSensitive Whether to use case-sensitive comparison. Defaults to true.
121
- * @returns The query builder.
122
- */
123
- notLike(fieldName: (keyof MyDocType & FieldName) | string, pattern: string, caseSensitive?: boolean): this;
124
- /**
125
- * Sets a limit to the number of results returned by the query. The maximum limit is 20,000 and the default is 1,000
126
- * if none is provided.
127
- * @param limit The limit to set.
128
- * @returns The query builder.
129
- */
130
- abstract limit(limit: number): this;
131
- /**
132
- * Adds a sort order to the query. You can add multiple sort orders to the query. The order in which you add them
133
- * determines the order in which they are applied.
134
- * @param fieldName The name of the field to sort by.
135
- * @param asc Whether to sort in ascending order. Defaults to true.
136
- * @returns The query builder.
137
- */
138
- abstract sortBy(fieldName: keyof MyDocType & FieldName, asc?: boolean): this;
139
- }
140
- export interface HasDereference {
141
- /**
142
- * Dereferences the document references in the result of this query. For example, collection.query().snapshot()
143
- * returns an array of DocumentReference objects, but collection.query().dereference().snapshot() returns an array of
144
- * the actual document data.
145
- */
146
- dereference(): any;
147
- }