@squidcloud/client 1.0.168 → 1.0.169

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 (105) hide show
  1. package/dist/cjs/index.js +17 -10
  2. package/dist/internal-common/src/public-types/ai-assistant.public-types.d.ts +25 -0
  3. package/dist/internal-common/src/public-types/ai-chatbot.public-context.d.ts +12 -0
  4. package/dist/internal-common/src/public-types/ai-chatbot.public-types.d.ts +31 -0
  5. package/dist/internal-common/src/public-types/api-call.public-context.d.ts +14 -0
  6. package/dist/internal-common/src/public-types/application.public-types.d.ts +149 -0
  7. package/dist/internal-common/src/public-types/base-query-builder.public-types.d.ts +147 -0
  8. package/dist/internal-common/src/public-types/bundle-api.public-types.d.ts +57 -0
  9. package/dist/internal-common/src/public-types/bundle-data.public-types.d.ts +8 -0
  10. package/dist/internal-common/src/public-types/communication.public-types.d.ts +12 -0
  11. package/dist/internal-common/src/public-types/context.public-types.d.ts +40 -0
  12. package/dist/internal-common/src/public-types/distributed-lock.public-context.d.ts +4 -0
  13. package/dist/internal-common/src/public-types/document.public-types.d.ts +32 -0
  14. package/dist/internal-common/src/public-types/graphql.public-context.d.ts +7 -0
  15. package/dist/internal-common/src/public-types/graphql.public-types.d.ts +9 -0
  16. package/dist/internal-common/src/public-types/http-status.enum.d.ts +50 -0
  17. package/dist/internal-common/src/public-types/integration.public-types.d.ts +61 -0
  18. package/dist/internal-common/src/public-types/integrations/ai_chatbot.types.d.ts +32 -0
  19. package/dist/internal-common/src/public-types/integrations/api.types.d.ts +81 -0
  20. package/dist/internal-common/src/public-types/integrations/auth.types.d.ts +54 -0
  21. package/dist/internal-common/src/public-types/integrations/database.types.d.ts +206 -0
  22. package/dist/internal-common/src/public-types/integrations/observability.types.d.ts +24 -0
  23. package/dist/internal-common/src/public-types/integrations/queue-types.d.ts +40 -0
  24. package/dist/internal-common/src/public-types/integrations/schemas.d.ts +70 -0
  25. package/dist/internal-common/src/public-types/mutation.public-context.d.ts +14 -0
  26. package/dist/internal-common/src/public-types/mutation.public-types.d.ts +53 -0
  27. package/dist/internal-common/src/public-types/native-query.public-context.d.ts +7 -0
  28. package/dist/internal-common/src/public-types/native-query.public-types.d.ts +16 -0
  29. package/dist/internal-common/src/public-types/pagination.public-types.d.ts +62 -0
  30. package/dist/internal-common/src/public-types/query.public-context.d.ts +137 -0
  31. package/dist/internal-common/src/public-types/query.public-types.d.ts +64 -0
  32. package/dist/internal-common/src/public-types/regions.public-types.d.ts +5 -0
  33. package/dist/internal-common/src/public-types/schema.public-types.d.ts +46 -0
  34. package/dist/internal-common/src/public-types/secret.public-types.d.ts +16 -0
  35. package/dist/internal-common/src/public-types/serialized-query.public-types.d.ts +24 -0
  36. package/dist/internal-common/src/public-types/socket.public-types.d.ts +5 -0
  37. package/dist/internal-common/src/public-types/topic.public-context.d.ts +10 -0
  38. package/dist/internal-common/src/public-types/typescript.public-types.d.ts +15 -0
  39. package/dist/internal-common/src/public-utils/id-utils.d.ts +6 -0
  40. package/dist/internal-common/src/types/ai-assistant.types.d.ts +1 -0
  41. package/dist/internal-common/src/types/ai-chatbot.types.d.ts +1 -0
  42. package/dist/internal-common/src/types/api.types.d.ts +2 -0
  43. package/dist/internal-common/src/types/backend-function.types.d.ts +1 -0
  44. package/dist/internal-common/src/types/backend-run.types.d.ts +1 -0
  45. package/dist/internal-common/src/types/bundle-data.types.d.ts +1 -0
  46. package/dist/internal-common/src/types/communication.types.d.ts +1 -0
  47. package/dist/internal-common/src/types/document.types.d.ts +1 -0
  48. package/dist/internal-common/src/types/mutation.types.d.ts +1 -0
  49. package/dist/internal-common/src/types/openapi.types.d.ts +1 -0
  50. package/dist/internal-common/src/types/query.types.d.ts +1 -0
  51. package/dist/internal-common/src/types/secret.types.d.ts +11 -0
  52. package/dist/internal-common/src/types/socket.types.d.ts +1 -0
  53. package/dist/internal-common/src/utils/array.d.ts +1 -0
  54. package/dist/internal-common/src/utils/assert.d.ts +1 -0
  55. package/dist/internal-common/src/utils/global.utils.d.ts +1 -0
  56. package/dist/internal-common/src/utils/http.d.ts +2 -0
  57. package/dist/internal-common/src/utils/lock.manager.d.ts +14 -0
  58. package/dist/internal-common/src/utils/object.d.ts +5 -0
  59. package/dist/internal-common/src/utils/serialization.d.ts +5 -0
  60. package/dist/internal-common/src/utils/validation.d.ts +24 -0
  61. package/dist/internal-common/src/websocket.impl.d.ts +21 -0
  62. package/dist/node_modules/json-schema-typed/draft-2020-12.d.ts +1239 -0
  63. package/dist/typescript-client/src/ai-assistant-client.d.ts +73 -0
  64. package/dist/typescript-client/src/ai-chatbot-client.d.ts +168 -0
  65. package/dist/typescript-client/src/ai-chatbot-client.factory.d.ts +1 -0
  66. package/dist/typescript-client/src/ai.types.d.ts +60 -0
  67. package/dist/typescript-client/src/api.manager.d.ts +11 -0
  68. package/dist/typescript-client/src/auth.manager.d.ts +27 -0
  69. package/dist/typescript-client/src/backend-function.manager.d.ts +9 -0
  70. package/dist/typescript-client/src/backend-transforms.d.ts +0 -0
  71. package/dist/typescript-client/src/client-id.service.d.ts +27 -0
  72. package/dist/typescript-client/src/collection-reference.d.ts +80 -0
  73. package/dist/typescript-client/src/collection-reference.factory.d.ts +1 -0
  74. package/dist/typescript-client/src/connection-details.d.ts +23 -0
  75. package/dist/typescript-client/src/data.manager.d.ts +5 -0
  76. package/dist/typescript-client/src/destruct.manager.d.ts +13 -0
  77. package/dist/typescript-client/src/distributed-lock.manager.d.ts +16 -0
  78. package/dist/typescript-client/src/document-identity.service.d.ts +1 -0
  79. package/dist/typescript-client/src/document-reference.d.ts +149 -0
  80. package/dist/typescript-client/src/document-reference.factory.d.ts +1 -0
  81. package/dist/typescript-client/src/document-store.d.ts +14 -0
  82. package/dist/typescript-client/src/graphql-client.d.ts +14 -0
  83. package/dist/typescript-client/src/graphql-client.factory.d.ts +11 -0
  84. package/dist/typescript-client/src/index.d.ts +11 -0
  85. package/dist/typescript-client/src/mutation/mutation-sender.d.ts +1 -0
  86. package/dist/typescript-client/src/native-query-manager.d.ts +7 -0
  87. package/dist/typescript-client/src/public-types.d.ts +37 -0
  88. package/dist/typescript-client/src/public-utils.d.ts +1 -0
  89. package/dist/typescript-client/src/query/deserializer.d.ts +3 -0
  90. package/dist/typescript-client/src/query/join-query-builder.factory.d.ts +161 -0
  91. package/dist/typescript-client/src/query/local-query-manager.d.ts +1 -0
  92. package/dist/typescript-client/src/query/query-builder.factory.d.ts +77 -0
  93. package/dist/typescript-client/src/query/query-sender.d.ts +1 -0
  94. package/dist/typescript-client/src/query/query-subscription.manager.d.ts +2 -0
  95. package/dist/typescript-client/src/query/query.types.d.ts +49 -0
  96. package/dist/typescript-client/src/queue.manager.d.ts +7 -0
  97. package/dist/typescript-client/src/rate-limiter.d.ts +32 -0
  98. package/dist/typescript-client/src/rpc.manager.d.ts +30 -0
  99. package/dist/typescript-client/src/secret.client.d.ts +23 -0
  100. package/dist/typescript-client/src/socket.manager.d.ts +1 -0
  101. package/dist/typescript-client/src/squid.d.ts +245 -0
  102. package/dist/typescript-client/src/state/state.service.spec.d.ts +1 -0
  103. package/dist/typescript-client/src/testing/setup-tests.d.ts +1 -0
  104. package/dist/typescript-client/src/types.d.ts +6 -0
  105. package/package.json +3 -1
@@ -0,0 +1,23 @@
1
+ import { SetSecretRequestEntry } from '../../internal-common/src/types/secret.types';
2
+ import { SecretEntry, SecretKey, SecretValue } from './public-types';
3
+ import { RpcManager } from './rpc.manager';
4
+ export declare class SecretClient {
5
+ private readonly rpcManager;
6
+ constructor(rpcManager: RpcManager);
7
+ get(key: SecretKey): Promise<SecretEntry | undefined>;
8
+ getAll(): Promise<Record<SecretKey, SecretEntry>>;
9
+ upsert(key: SecretKey, value: SecretValue): Promise<SecretEntry>;
10
+ upsertMany(entries: Array<SetSecretRequestEntry>): Promise<Array<SecretEntry>>;
11
+ delete(key: SecretKey): Promise<void>;
12
+ deleteMany(keys: Array<SecretKey>): Promise<void>;
13
+ get apiKeys(): ApiKeysSecretClient;
14
+ }
15
+ declare class ApiKeysSecretClient {
16
+ private readonly rpcManager;
17
+ constructor(rpcManager: RpcManager);
18
+ get(key: SecretKey): Promise<SecretEntry | undefined>;
19
+ getAll(): Promise<Record<SecretKey, SecretEntry>>;
20
+ upsert(key: SecretKey): Promise<SecretEntry>;
21
+ delete(key: SecretKey): Promise<void>;
22
+ }
23
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,245 @@
1
+ import { CollectionReference } from './collection-reference';
2
+ import { ConnectionDetails } from './connection-details';
3
+ import { DistributedLock } from './distributed-lock.manager';
4
+ import { GraphQLClient } from './graphql-client';
5
+ import { SecretClient } from './secret.client';
6
+ import { TransactionId } from './types';
7
+ import { AiClient } from './ai.types';
8
+ import { ApiEndpointId, ApiKey, AppId, CollectionName, DocumentData, EnvironmentId, IntegrationId, SquidDeveloperId, SupportedSquidRegion } from './public-types';
9
+ import { QueueManager } from './queue.manager';
10
+ /** The different options that can be used to initialize a Squid instance. */
11
+ export interface SquidOptions {
12
+ /**
13
+ * A function that can be used to wrap messages coming from Squid to the application. This is useful for
14
+ * different frameworks that need to wrap messages in order to detect changes (like Angular).
15
+ * @param fn The function to wrap.
16
+ */
17
+ messageNotificationWrapper?: (fn: () => any) => any;
18
+ /**
19
+ * The application ID that is used to identify the application in Squid. The ID can be found in the Squid Cloud
20
+ * Console.
21
+ */
22
+ appId: AppId;
23
+ /**
24
+ * The application API key, using the API key can be used to bypass security rules and other restrictions.
25
+ * The API key can be found in the Squid Cloud Console.
26
+ */
27
+ apiKey?: ApiKey;
28
+ /**
29
+ * Access token provider for the Squid instance.
30
+ * Used for managing the process of verifying the identity and authorization of users who attempt to access this
31
+ * application via the current Squid instance.
32
+ *
33
+ * When the authProvider is set, the Squid service will fetch a token and include it with every request to the Squid
34
+ * backend.
35
+ *
36
+ * On the backend, Squid will validate the access token.
37
+ */
38
+ authProvider?: SquidAuthProvider;
39
+ /**
40
+ * The region that the application is running in. This is used to determine the URL of the Squid Cloud API.
41
+ */
42
+ region: SupportedSquidRegion;
43
+ /**
44
+ * The environment ID to work with, if not specified the default environment (prod) will be used.
45
+ */
46
+ environmentId?: EnvironmentId;
47
+ /**
48
+ * The user ID of the developer that runs the environment locally.
49
+ */
50
+ squidDeveloperId?: SquidDeveloperId;
51
+ /**
52
+ * A list of API endpoints that can be used for overriding the default API endpoints for the different integrations.
53
+ * This is useful for APIs that have multiple base urls hosted in different regions.
54
+ */
55
+ apiServerUrlOverrideMapping?: Record<IntegrationId, string>;
56
+ }
57
+ /** Authentication data provider for Squid requests. */
58
+ export interface SquidAuthProvider {
59
+ /**
60
+ * Returns a valid AccessToken or undefined if there is no active authorized session.
61
+ * Called by Squid every time a Squid client makes requests to the Squid backend.
62
+ */
63
+ getToken(): Promise<string | undefined> | string | undefined;
64
+ /**
65
+ * Optional Auth integration id.
66
+ * Sent as a part of all Squid requests to the backend.
67
+ */
68
+ integrationId?: string;
69
+ }
70
+ /**
71
+ * The main entry point to the Squid Client SDK.
72
+ *
73
+ * The Squid class provides a comprehensive array of functionality for accessing the different integrations, executing
74
+ * backend functions, managing data, and more. Upon instantiating the Squid class, you will have access to all of these
75
+ * capabilities.
76
+ * All public Squid functions are bound to `this` and can be used with a destructuring patterns,
77
+ * like `const {setAuthProvider} = useSquid()`
78
+ */
79
+ export declare class Squid {
80
+ readonly options: SquidOptions;
81
+ private readonly socketManager;
82
+ private readonly rpcManager;
83
+ private readonly dataManager;
84
+ private readonly documentReferenceFactory;
85
+ private readonly documentStore;
86
+ private readonly lockManager;
87
+ private readonly querySubscriptionManager;
88
+ private readonly localQueryManager;
89
+ private readonly queryBuilderFactory;
90
+ private readonly collectionReferenceFactory;
91
+ private readonly backendFunctionManager;
92
+ private readonly nativeQueryManager;
93
+ private readonly apiManager;
94
+ private readonly graphqlClientFactory;
95
+ private readonly destructManager;
96
+ private readonly documentIdentityService;
97
+ private readonly distributedLockManager;
98
+ private readonly authManager;
99
+ private readonly clientIdService;
100
+ private readonly aiClientFactory;
101
+ private readonly _connectionDetails;
102
+ private readonly secretClient;
103
+ private readonly querySender;
104
+ private static readonly squidInstancesMap;
105
+ private readonly aiClient;
106
+ private readonly queueManagerFactory;
107
+ /**
108
+ * Creates a new instance of Squid with the given options.
109
+ *
110
+ * @param options The options for initializing the Squid instance.
111
+ */
112
+ constructor(options: SquidOptions);
113
+ /**
114
+ * Returns the global Squid instance with the given options, creating a new instance if one with the same options
115
+ * does not exist.
116
+ *
117
+ * @param options The options for initializing the Squid instance.
118
+ * @returns A global Squid instance with the given options.
119
+ */
120
+ static getInstance(options: SquidOptions): Squid;
121
+ /**
122
+ * Returns all the global Squid instances.
123
+ *
124
+ * @returns An array of all the global Squid instances.
125
+ */
126
+ static getInstances(): Array<Squid>;
127
+ /**
128
+ * Sets the authorization access token (OAuth2.0) provider that will be sent to the server and will be used for
129
+ * providing the `auth` object to the security rules.
130
+ *
131
+ * @param authProvider The OAuth2.0 access token provider invoked for every backend request by Squid.
132
+ * When the provider returns undefined, no authorization information is sent.
133
+ * When a new provider is set, all future Squid backend requests will use the new token provider, and exising
134
+ * in-flight requests won't be affected.
135
+ * @returns void.
136
+ */
137
+ setAuthProvider(authProvider: SquidAuthProvider): void;
138
+ /**
139
+ * Returns a reference to the collection in the provided integration.
140
+ *
141
+ * If the integrationId is not provided, the `built_in_db` integration id will be used.
142
+ *
143
+ * For more information on the CollectionReference object, please refer to the
144
+ * {@link https://docs.squid.cloud/docs/development-tools/client-sdk/collection-reference documentation}.
145
+ *
146
+ * @param collectionName The name of the collection.
147
+ * @param integrationId The id of the integration, default to `built_in_db`.
148
+ * @returns A reference to the collection in the provided integration.
149
+ * @typeParam T The type of the documents in the collection.
150
+ */
151
+ collection<T extends DocumentData>(collectionName: CollectionName, integrationId?: IntegrationId): CollectionReference<T>;
152
+ /**
153
+ * Runs the given callback as an atomic change. All the mutations that are executed using the provided transactionId
154
+ * will be atomic. Note that mutations for different integrations will not be atomic.
155
+ *
156
+ * For more information about transactions in Squid, please refer to the
157
+ * {@link https://docs.squid.cloud/docs/development-tools/client-sdk/transactions documentation}.
158
+ *
159
+ * @param fn The callback to run as an atomic change. The function receives a transactionId that should be used for
160
+ * all the mutations that should be atomic. The function should return a promise.
161
+ *
162
+ * @returns A promise that resolves when the transactions are committed on the server.
163
+ */
164
+ runInTransaction<T = any>(fn: (transactionId: TransactionId) => Promise<T>): Promise<T>;
165
+ /**
166
+ * Executes the given backend function with the given parameters and returns a promise with the result.
167
+ *
168
+ * For more information about backend functions in Squid, please refer to the
169
+ * {@link https://docs.squid.cloud/docs/development-tools/backend/executables documentation}.
170
+ *
171
+ * @param functionName The name of the function to execute on the server.
172
+ * @param params The parameters to pass to the function.
173
+ * @returns A promise that resolves with the result of the function.
174
+ * @typeParam T The type of the result of the function.
175
+ */
176
+ executeFunction<T = any>(functionName: string, ...params: any[]): Promise<T>;
177
+ /**
178
+ * Executes a native relational query with the given parameters and returns a promise with the result.
179
+ *
180
+ * Native queries allow you to execute raw SQL or other database-specific queries directly against the database.
181
+ * This can be useful when you need to perform operations that are not easily accomplished with other high-level
182
+ * abstractions.
183
+ *
184
+ * @param integrationId The id of the integration that the query is associated with.
185
+ * @param query The raw SQL or other database-specific query to execute.
186
+ * @param params (Optional) The parameters to pass to the query. Defaults to an empty object.
187
+ * @returns A promise that resolves with the result of the query.
188
+ * @type {Promise<Array<SquidDocument>>}
189
+ */
190
+ executeNativeRelationalQuery<T = any>(integrationId: IntegrationId, query: string, params?: Record<string, any>): Promise<Array<T>>;
191
+ /**
192
+ * Invokes the given HTTP API (defined by the integration ID and the endpoint ID) with the given request parameters
193
+ * and returns a promise with the response. The structure of the request and the response is defined in the
194
+ * integration's schema page.
195
+ *
196
+ * For more information about API integrations in Squid, please refer to the
197
+ * {@link https://docs.squid.cloud/docs/integrations/api/httpapi documentation}.
198
+ *
199
+ * @param integrationId The id of the integration that the API is defined with.
200
+ * @param endpointId The id of the endpoint in the API integration.
201
+ * @param request The request parameters to pass to the API.
202
+ * @returns A promise that resolves with the response of the API.
203
+ * @typeParam T The type of the response of the API.
204
+ */
205
+ callApi<T = any>(integrationId: IntegrationId, endpointId: ApiEndpointId, request?: Record<string, any>): Promise<T>;
206
+ /**
207
+ * Returns a GraphQL client for the given integration. The GraphQL client can be used to execute GraphQL queries and
208
+ * mutations. For more information about GraphQL in Squid, please refer to the
209
+ * {@link https://docs.squid.cloud/docs/integrations/api/graphql documentation}.
210
+ *
211
+ * @param integrationId The id of the integration that the GraphQL API is defined with.
212
+ * @returns A GraphQL client for the given integration.
213
+ */
214
+ graphql(integrationId: IntegrationId): GraphQLClient;
215
+ /**
216
+ * Returns a set of AI specific clients.
217
+ *
218
+ * @returns A set of AI specific clients.
219
+ */
220
+ ai(): AiClient;
221
+ get secrets(): SecretClient;
222
+ /**
223
+ * Returns a distributed lock for the given mutex. The lock can be used to synchronize access to a shared resource.
224
+ * The lock will be released when the release method on the returned object is invoked or whenever the connection
225
+ * with the server is lost.
226
+ * @param mutex A string that uniquely identifies the lock.
227
+ * @returns A promise that resolves with the lock object. The promise will reject if failed to acquire the lock.
228
+ */
229
+ acquireLock(mutex: string): Promise<DistributedLock>;
230
+ /**
231
+ * Returns a queue manager for the given topic name and integration id. Using the queue manager you can consume and
232
+ * produce messages
233
+ */
234
+ queue(topicName: string, integrationId?: IntegrationId): QueueManager;
235
+ /**
236
+ * Destructs the Squid Client. Unsubscribes from all ongoing queries or requests, and clears the local data.
237
+ * After invoking this method, the Squid client will not be usable.
238
+ *
239
+ * @returns A promise that resolves when the destruct process is complete.
240
+ */
241
+ destruct(): Promise<void>;
242
+ /** Provides information about the connection to the Squid Server. */
243
+ connectionDetails(): ConnectionDetails;
244
+ private _validateNotDestructed;
245
+ }
@@ -0,0 +1,6 @@
1
+ /** A transactionId - alias for string */
2
+ export type TransactionId = string;
3
+ export interface BlobAndFilename {
4
+ blob: Blob;
5
+ name: string;
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squidcloud/client",
3
- "version": "1.0.168",
3
+ "version": "1.0.169",
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",
@@ -14,6 +14,8 @@
14
14
  "build:prod": "webpack --mode=production",
15
15
  "watch": "webpack --watch",
16
16
  "lint": "eslint . --ext .ts",
17
+ "build-and-check-public-types": "npm run prebuild && npm run build && npm run check-public-types",
18
+ "check-public-types": "tsc -p tsconfig.types.json",
17
19
  "test": "jest --detectOpenHandles",
18
20
  "test:watch": "jest --watch",
19
21
  "test:cov": "jest --coverage",