@squidcloud/client 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 (206) hide show
  1. package/dist/cjs/index.js +1 -53942
  2. package/dist/esm/index.js +1 -0
  3. package/dist/internal-common/src/metric-name.d.ts +9 -0
  4. package/dist/internal-common/src/public-types/ai-agent-integrations.public-types.d.ts +47 -0
  5. package/dist/internal-common/src/public-types/ai-agent.public-types.d.ts +895 -0
  6. package/dist/internal-common/src/public-types/ai-assistant.public-types.d.ts +31 -0
  7. package/dist/internal-common/src/public-types/ai-common.public-types.d.ts +185 -0
  8. package/dist/internal-common/src/public-types/ai-knowledge-base.public-types.d.ts +431 -0
  9. package/dist/internal-common/src/public-types/ai-matchmaking.public-types.d.ts +186 -0
  10. package/dist/internal-common/src/public-types/ai-query.public-types.d.ts +170 -0
  11. package/dist/internal-common/src/public-types/api-client.public-types.d.ts +9 -0
  12. package/dist/internal-common/src/public-types/api.public-types.d.ts +91 -0
  13. package/dist/internal-common/src/public-types/backend.public-types.d.ts +50 -0
  14. package/dist/{common/src/backend-function.schemas.d.ts → internal-common/src/public-types/code-executor.public-types.d.ts} +1 -1
  15. package/dist/internal-common/src/public-types/communication.public-types.d.ts +30 -0
  16. package/dist/internal-common/src/public-types/context.public-types.d.ts +83 -0
  17. package/dist/internal-common/src/public-types/document.public-types.d.ts +71 -0
  18. package/dist/internal-common/src/public-types/external-auth/external-auth.public-types.d.ts +39 -0
  19. package/dist/internal-common/src/public-types/extraction.public-types.d.ts +183 -0
  20. package/dist/internal-common/src/public-types/http-status.public-types.d.ts +415 -0
  21. package/dist/internal-common/src/public-types/integration.public-types.d.ts +51 -0
  22. package/dist/internal-common/src/public-types/job.public-types.d.ts +59 -0
  23. package/dist/internal-common/src/public-types/metric.public-types.d.ts +154 -0
  24. package/dist/internal-common/src/public-types/openapi.public-types.d.ts +9 -0
  25. package/dist/internal-common/src/public-types/query.public-types.d.ts +113 -0
  26. package/dist/internal-common/src/public-types/regions.public-types.d.ts +4 -0
  27. package/dist/internal-common/src/public-types/scheduler.public-types.d.ts +43 -0
  28. package/dist/{common/src/schema/schema.types.d.ts → internal-common/src/public-types/schema.public-types.d.ts} +54 -54
  29. package/dist/internal-common/src/public-types/secret.public-types.d.ts +51 -0
  30. package/dist/internal-common/src/public-types/serialized-query.public-types.d.ts +60 -0
  31. package/dist/internal-common/src/public-types/socket.public-types.d.ts +4 -0
  32. package/dist/{common/src/types.d.ts → internal-common/src/public-types/typescript.public-types.d.ts} +20 -14
  33. package/dist/internal-common/src/public-types/web.public-types.d.ts +93 -0
  34. package/dist/internal-common/src/public-types-backend/api-call.public-context.d.ts +30 -0
  35. package/dist/internal-common/src/public-types-backend/mutation.public-context.d.ts +148 -0
  36. package/dist/internal-common/src/public-types-backend/native-query.public-context.d.ts +72 -0
  37. package/dist/{common/src/query/query-context.d.ts → internal-common/src/public-types-backend/query.public-context.d.ts} +177 -137
  38. package/dist/{common/src/ai-chatbot.schemas.d.ts → internal-common/src/public-utils/context-utils.d.ts} +1 -1
  39. package/dist/internal-common/src/public-utils/id-utils.d.ts +44 -0
  40. package/dist/internal-common/src/types/ai-agent.types.d.ts +199 -0
  41. package/dist/{common/src/mutation.schemas.d.ts → internal-common/src/types/ai-assistant.types.d.ts} +1 -1
  42. package/dist/internal-common/src/types/ai-knowledge-base.types.d.ts +202 -0
  43. package/dist/internal-common/src/types/ai-matchmaking.types.d.ts +59 -0
  44. package/dist/{common/src → internal-common/src/types}/backend-function.types.d.ts +1 -1
  45. package/dist/internal-common/src/types/communication.types.d.ts +1 -0
  46. package/dist/internal-common/src/types/document.types.d.ts +1 -0
  47. package/dist/internal-common/src/types/file.types.d.ts +6 -0
  48. package/dist/internal-common/src/types/headers.types.d.ts +17 -0
  49. package/dist/internal-common/src/types/mutation.types.d.ts +1 -0
  50. package/dist/internal-common/src/types/notification.types.d.ts +5 -0
  51. package/dist/internal-common/src/types/observability.types.d.ts +78 -0
  52. package/dist/internal-common/src/types/query.types.d.ts +13 -0
  53. package/dist/internal-common/src/types/secret.types.d.ts +7 -0
  54. package/dist/internal-common/src/types/socket.types.d.ts +1 -0
  55. package/dist/internal-common/src/types/stage.d.ts +9 -0
  56. package/dist/{common/src → internal-common/src/types}/time-units.d.ts +1 -1
  57. package/dist/internal-common/src/types/url-shortener.types.d.ts +41 -0
  58. package/dist/internal-common/src/utils/array.d.ts +7 -0
  59. package/dist/internal-common/src/utils/e2e-test-utils.d.ts +2 -0
  60. package/dist/{common → internal-common}/src/utils/global.utils.d.ts +1 -1
  61. package/dist/internal-common/src/utils/http.d.ts +5 -0
  62. package/dist/{common → internal-common}/src/utils/lock.manager.d.ts +14 -14
  63. package/dist/internal-common/src/utils/metric-utils.d.ts +4 -0
  64. package/dist/internal-common/src/utils/metrics.types.d.ts +7 -0
  65. package/dist/internal-common/src/utils/object.d.ts +58 -0
  66. package/dist/internal-common/src/utils/serialization.d.ts +17 -0
  67. package/dist/internal-common/src/utils/squid.constants.d.ts +1 -0
  68. package/dist/internal-common/src/utils/trace-id-generator.d.ts +1 -0
  69. package/dist/internal-common/src/utils/validation.d.ts +19 -0
  70. package/dist/{common → internal-common}/src/websocket.impl.d.ts +26 -21
  71. package/dist/node_modules/json-schema-typed/draft-2020-12.d.ts +1239 -1239
  72. package/dist/typescript-client/src/admin-client.d.ts +23 -0
  73. package/dist/typescript-client/src/agent/ai-agent-client-reference.d.ts +181 -0
  74. package/dist/typescript-client/src/agent/ai-agent-client.d.ts +37 -0
  75. package/dist/typescript-client/src/agent/ai-agent-client.types.d.ts +69 -0
  76. package/dist/typescript-client/src/ai-assistant-client.d.ts +72 -73
  77. package/dist/typescript-client/src/ai-audio-client.d.ts +25 -0
  78. package/dist/typescript-client/src/ai-client.d.ts +129 -0
  79. package/dist/typescript-client/src/ai-files-client.d.ts +33 -0
  80. package/dist/typescript-client/src/ai-image-client.d.ts +25 -0
  81. package/dist/typescript-client/src/ai-knowledge-base/ai-knowledge-base-client-reference.d.ts +86 -0
  82. package/dist/typescript-client/src/ai-knowledge-base/ai-knowledge-base-client.d.ts +28 -0
  83. package/dist/typescript-client/src/ai-matchmaking-client.d.ts +99 -0
  84. package/dist/typescript-client/src/api-client.d.ts +69 -0
  85. package/dist/typescript-client/src/auth.manager.d.ts +11 -26
  86. package/dist/typescript-client/src/backend-function.manager.d.ts +1 -9
  87. package/dist/typescript-client/src/client-customization.utils.d.ts +1 -0
  88. package/dist/typescript-client/src/client-id.service.d.ts +1 -27
  89. package/dist/typescript-client/src/collection-reference.d.ts +105 -80
  90. package/dist/typescript-client/src/collection-reference.factory.d.ts +1 -13
  91. package/dist/typescript-client/src/connection-details.d.ts +24 -23
  92. package/dist/typescript-client/src/console-utils.d.ts +1 -0
  93. package/dist/typescript-client/src/data.manager.d.ts +1 -173
  94. package/dist/typescript-client/src/destruct.manager.d.ts +1 -12
  95. package/dist/typescript-client/src/distributed-lock.manager.d.ts +39 -16
  96. package/dist/typescript-client/src/document-identity.service.d.ts +1 -12
  97. package/dist/typescript-client/src/document-reference.d.ts +151 -140
  98. package/dist/typescript-client/src/document-reference.factory.d.ts +1 -13
  99. package/dist/typescript-client/src/document-store.d.ts +1 -14
  100. package/dist/typescript-client/src/execute-function-options.d.ts +73 -0
  101. package/dist/typescript-client/src/external-auth-client.d.ts +36 -0
  102. package/dist/typescript-client/src/extraction-client.d.ts +32 -0
  103. package/dist/typescript-client/src/file-args-transformer.d.ts +1 -0
  104. package/dist/typescript-client/src/file-utils.d.ts +1 -0
  105. package/dist/typescript-client/src/index.d.ts +63 -9
  106. package/dist/typescript-client/src/integration-client.d.ts +60 -0
  107. package/dist/typescript-client/src/job-client.d.ts +32 -0
  108. package/dist/typescript-client/src/mutation/mutation-sender.d.ts +1 -10
  109. package/dist/typescript-client/src/native-query-manager.d.ts +1 -7
  110. package/dist/typescript-client/src/notification-client.d.ts +20 -0
  111. package/dist/typescript-client/src/observability-client.d.ts +43 -0
  112. package/dist/typescript-client/src/public-types.d.ts +30 -0
  113. package/dist/typescript-client/src/public-utils.d.ts +1 -0
  114. package/dist/typescript-client/src/query/deserializer.d.ts +10 -3
  115. package/dist/typescript-client/src/query/join-query-builder.factory.d.ts +316 -161
  116. package/dist/typescript-client/src/query/local-query-manager.d.ts +1 -9
  117. package/dist/{common → typescript-client}/src/query/pagination.d.ts +65 -62
  118. package/dist/typescript-client/src/query/query-builder.factory.d.ts +228 -77
  119. package/dist/typescript-client/src/query/query-sender.d.ts +1 -33
  120. package/dist/typescript-client/src/query/query-subscription.manager.d.ts +1 -130
  121. package/dist/typescript-client/src/query/query.types.d.ts +16 -49
  122. package/dist/typescript-client/src/query/snapshot-emitter.d.ts +41 -0
  123. package/dist/typescript-client/src/query-utils.d.ts +18 -0
  124. package/dist/typescript-client/src/queue.manager.d.ts +12 -0
  125. package/dist/typescript-client/src/rate-limiter.d.ts +1 -32
  126. package/dist/typescript-client/src/rpc.manager.d.ts +1 -30
  127. package/dist/typescript-client/src/scheduler-client.d.ts +31 -0
  128. package/dist/typescript-client/src/secret.client.d.ts +96 -22
  129. package/dist/typescript-client/src/socket.manager.d.ts +1 -43
  130. package/dist/typescript-client/src/squid-http-client.d.ts +11 -0
  131. package/dist/typescript-client/src/squid.d.ts +378 -269
  132. package/dist/typescript-client/src/state/state.service.spec.d.ts +1 -1
  133. package/dist/typescript-client/src/storage-client.d.ts +145 -0
  134. package/dist/typescript-client/src/types.d.ts +27 -2
  135. package/dist/typescript-client/src/version.d.ts +5 -0
  136. package/dist/typescript-client/src/web-client.d.ts +63 -0
  137. package/dist/typescript-client/src/webhook.manager.d.ts +10 -0
  138. package/package.json +34 -18
  139. package/dist/common/src/ai-assistant.types.d.ts +0 -25
  140. package/dist/common/src/ai-chatbot.context.d.ts +0 -12
  141. package/dist/common/src/ai-chatbot.types.d.ts +0 -27
  142. package/dist/common/src/api-call.context.d.ts +0 -13
  143. package/dist/common/src/api.types.d.ts +0 -4
  144. package/dist/common/src/application.schemas.d.ts +0 -66
  145. package/dist/common/src/application.types.d.ts +0 -143
  146. package/dist/common/src/backend-run.types.d.ts +0 -2
  147. package/dist/common/src/bundle-api.types.d.ts +0 -43
  148. package/dist/common/src/bundle-data.types.d.ts +0 -5
  149. package/dist/common/src/communication.types.d.ts +0 -8
  150. package/dist/common/src/context.types.d.ts +0 -40
  151. package/dist/common/src/distributed-lock.context.d.ts +0 -4
  152. package/dist/common/src/document.types.d.ts +0 -22
  153. package/dist/common/src/graphql.context.d.ts +0 -7
  154. package/dist/common/src/graphql.types.d.ts +0 -9
  155. package/dist/common/src/heartbeat.types.d.ts +0 -1
  156. package/dist/common/src/http-status.enum.d.ts +0 -50
  157. package/dist/common/src/index.d.ts +0 -57
  158. package/dist/common/src/integrations/ai_chatbot.types.d.ts +0 -31
  159. package/dist/common/src/integrations/api.types.d.ts +0 -80
  160. package/dist/common/src/integrations/auth.types.d.ts +0 -47
  161. package/dist/common/src/integrations/database.types.d.ts +0 -274
  162. package/dist/common/src/integrations/index.d.ts +0 -134
  163. package/dist/common/src/integrations/observability.types.d.ts +0 -23
  164. package/dist/common/src/logger.types.d.ts +0 -21
  165. package/dist/common/src/metrics.types.d.ts +0 -1
  166. package/dist/common/src/mutation.context.d.ts +0 -14
  167. package/dist/common/src/mutation.types.d.ts +0 -53
  168. package/dist/common/src/named-query.context.d.ts +0 -4
  169. package/dist/common/src/named-query.schemas.d.ts +0 -1
  170. package/dist/common/src/named-query.types.d.ts +0 -1
  171. package/dist/common/src/native-query.context.d.ts +0 -7
  172. package/dist/common/src/native-query.types.d.ts +0 -16
  173. package/dist/common/src/query/base-query-builder.d.ts +0 -147
  174. package/dist/common/src/query/index.d.ts +0 -4
  175. package/dist/common/src/query/serialized-query.types.d.ts +0 -24
  176. package/dist/common/src/query.types.d.ts +0 -64
  177. package/dist/common/src/regions.d.ts +0 -1
  178. package/dist/common/src/secret.schemas.d.ts +0 -1
  179. package/dist/common/src/secret.types.d.ts +0 -22
  180. package/dist/common/src/security.types.d.ts +0 -1
  181. package/dist/common/src/socket.schemas.d.ts +0 -1
  182. package/dist/common/src/socket.types.d.ts +0 -5
  183. package/dist/common/src/trigger.types.d.ts +0 -1
  184. package/dist/common/src/utils/array.d.ts +0 -1
  185. package/dist/common/src/utils/assert.d.ts +0 -1
  186. package/dist/common/src/utils/error.d.ts +0 -4
  187. package/dist/common/src/utils/http.d.ts +0 -2
  188. package/dist/common/src/utils/id.d.ts +0 -2
  189. package/dist/common/src/utils/object.d.ts +0 -5
  190. package/dist/common/src/utils/serialization.d.ts +0 -6
  191. package/dist/common/src/utils/transforms.d.ts +0 -18
  192. package/dist/common/src/utils/url.d.ts +0 -1
  193. package/dist/common/src/utils/validation.d.ts +0 -25
  194. package/dist/common/src/webhook-response.d.ts +0 -1
  195. package/dist/typescript-client/src/ai-chatbot-client.d.ts +0 -174
  196. package/dist/typescript-client/src/ai-chatbot-client.factory.d.ts +0 -8
  197. package/dist/typescript-client/src/ai.types.d.ts +0 -61
  198. package/dist/typescript-client/src/api.manager.d.ts +0 -11
  199. package/dist/typescript-client/src/graphql-client.d.ts +0 -14
  200. package/dist/typescript-client/src/graphql-client.factory.d.ts +0 -11
  201. package/dist/typescript-client/src/named-query.manager.d.ts +0 -11
  202. package/dist/typescript-client/src/state/action.applier.d.ts +0 -7
  203. package/dist/typescript-client/src/state/actions.d.ts +0 -29
  204. package/dist/typescript-client/src/state/path_trie.d.ts +0 -27
  205. package/dist/typescript-client/src/state/state.service.d.ts +0 -22
  206. package/dist/typescript-client/src/testing/setup-tests.d.ts +0 -1
@@ -1,269 +1,378 @@
1
- import { ApiEndpointId, ApiKey, AppId, CollectionName, DocumentData, EnvironmentId, IntegrationId, QueryName, SquidDeveloperId, SupportedSquidRegion } from '@squidcloud/common';
2
- import { CollectionReference } from './collection-reference';
3
- import { ConnectionDetails } from './connection-details';
4
- import { DistributedLock } from './distributed-lock.manager';
5
- import { GraphQLClient } from './graphql-client';
6
- import { SecretClient } from './secret.client';
7
- import { TransactionId } from './types';
8
- import { AiClient } from './ai.types';
9
- /** The different options that can be used to initialize a Squid instance. */
10
- export interface SquidOptions {
11
- /**
12
- * A function that can be used to wrap messages coming from Squid to the application. This is useful for
13
- * different frameworks that need to wrap messages in order to detect changes (like Angular).
14
- * @param fn The function to wrap.
15
- */
16
- messageNotificationWrapper?: (fn: () => any) => any;
17
- /**
18
- * The application ID that is used to identify the application in Squid. The ID can be found in the Squid Cloud
19
- * Console.
20
- */
21
- appId: AppId;
22
- /**
23
- * The application API key, using the API key can be used to bypass security rules and other restrictions.
24
- * The API key can be found in the Squid Cloud Console.
25
- */
26
- apiKey?: ApiKey;
27
- /**
28
- * Access token provider for the Squid instance.
29
- * Used for managing the process of verifying the identity and authorization of users who attempt to access this
30
- * application via the current Squid instance.
31
- *
32
- * When the authProvider is set, the Squid service will fetch a token and include it with every request to the Squid
33
- * backend.
34
- *
35
- * On the backend, Squid will validate the access token.
36
- */
37
- authProvider?: SquidAuthProvider;
38
- /**
39
- * The region that the application is running in. This is used to determine the URL of the Squid Cloud API.
40
- */
41
- region: SupportedSquidRegion;
42
- /**
43
- * The environment ID to work with, if not specified the default environment (prod) will be used.
44
- */
45
- environmentId?: EnvironmentId;
46
- /**
47
- * The user ID of the developer that runs the environment locally.
48
- */
49
- squidDeveloperId?: SquidDeveloperId;
50
- /**
51
- * A list of API endpoints that can be used for overriding the default API endpoints for the different integrations.
52
- * This is useful for APIs that have multiple base urls hosted in different regions.
53
- */
54
- apiServerUrlOverrideMapping?: Record<IntegrationId, string>;
55
- }
56
- /** Authentication data provider for Squid requests. */
57
- export interface SquidAuthProvider {
58
- /**
59
- * Returns a valid AccessToken.
60
- * Called by Squid every time a Squid client makes requests to the Squid backend.
61
- */
62
- getToken(): Promise<string | undefined>;
63
- /**
64
- * Optional Auth integration id.
65
- * Sent as a part of all Squid requests to the backend.
66
- */
67
- integrationId?: string;
68
- }
69
- /**
70
- * The main entry point to the Squid Client SDK.
71
- *
72
- * The Squid class provides a comprehensive array of functionality for accessing the different integrations, executing
73
- * backend functions, managing data, and more. Upon instantiating the Squid class, you will have access to all of these
74
- * capabilities.
75
- */
76
- export declare class Squid {
77
- readonly options: SquidOptions;
78
- private readonly socketManager;
79
- private readonly rpcManager;
80
- private readonly dataManager;
81
- private readonly documentReferenceFactory;
82
- private readonly documentStore;
83
- private readonly lockManager;
84
- private readonly querySubscriptionManager;
85
- private readonly localQueryManager;
86
- private readonly queryBuilderFactory;
87
- private readonly collectionReferenceFactory;
88
- private readonly backendFunctionManager;
89
- private readonly namedQueryManager;
90
- private readonly nativeQueryManager;
91
- private readonly apiManager;
92
- private readonly graphqlClientFactory;
93
- private readonly destructManager;
94
- private readonly documentIdentityService;
95
- private readonly distributedLockManager;
96
- private readonly authManager;
97
- private readonly clientIdService;
98
- private readonly aiClientFactory;
99
- private readonly _connectionDetails;
100
- private readonly secretClient;
101
- private readonly querySender;
102
- private static readonly squidInstancesMap;
103
- private readonly aiClient;
104
- /**
105
- * Creates a new instance of Squid with the given options.
106
- *
107
- * @param options The options for initializing the Squid instance.
108
- */
109
- constructor(options: SquidOptions);
110
- /**
111
- * Returns the global Squid instance with the given options, creating a new instance if one with the same options
112
- * does not exist.
113
- *
114
- * @param options The options for initializing the Squid instance.
115
- * @returns A global Squid instance with the given options.
116
- */
117
- static getInstance(options: SquidOptions): Squid;
118
- /**
119
- * Returns all the global Squid instances.
120
- *
121
- * @returns An array of all the global Squid instances.
122
- */
123
- static getInstances(): Array<Squid>;
124
- /**
125
- * Sets the authorization access token (OAuth2.0) provider that will be sent to the server and will be used for
126
- * providing the `auth` object to the security rules.
127
- *
128
- * @param authProvider The OAuth2.0 access token provider invoked for every backend request by Squid.
129
- * When the provider returns undefined, no authorization information is sent.
130
- * When a new provider is set, all future Squid backend requests will use the new token provider, and exising
131
- * in-flight requests won't be affected.
132
- * @returns void
133
- */
134
- setAuthProvider(authProvider: SquidAuthProvider): void;
135
- /**
136
- * Returns a reference to the collection in the provided integration.
137
- *
138
- * If the integrationId is not provided, the `built_in_db` integration id will be used.
139
- *
140
- * For more information on the CollectionReference object, please refer to the
141
- * {@link https://docs.squid.cloud/docs/development-tools/client-sdk/collection-reference documentation}.
142
- *
143
- * @param collectionName The name of the collection.
144
- * @param integrationId The id of the integration, default to `built_in_db`.
145
- * @returns A reference to the collection in the provided integration.
146
- * @typeParam T The type of the documents in the collection.
147
- */
148
- collection: <T extends DocumentData>(collectionName: CollectionName, integrationId?: IntegrationId) => CollectionReference<T>;
149
- /**
150
- * Runs the given callback as an atomic change. All the mutations that are executed using the provided transactionId
151
- * will be atomic. Note that mutations for different integrations will not be atomic.
152
- *
153
- * For more information about transactions in Squid, please refer to the
154
- * {@link https://docs.squid.cloud/docs/development-tools/client-sdk/transactions documentation}.
155
- *
156
- * @param fn The callback to run as an atomic change. The function receives a transactionId that should be used for
157
- * all the mutations that should be atomic. The function should return a promise.
158
- *
159
- * @returns A promise that resolves when the transactions are committed on the server.
160
- */
161
- runInTransaction: <T = any>(fn: (transactionId: TransactionId) => Promise<T>) => Promise<T>;
162
- /**
163
- * Executes the given backend function with the given parameters and returns a promise with the result.
164
- *
165
- * For more information about backend functions in Squid, please refer to the
166
- * {@link https://docs.squid.cloud/docs/development-tools/backend/executables documentation}.
167
- *
168
- * @param functionName The name of the function to execute on the server.
169
- * @param params The parameters to pass to the function.
170
- * @returns A promise that resolves with the result of the function.
171
- * @typeParam T The type of the result of the function.
172
- */
173
- executeFunction: <T = any>(functionName: string, ...params: any[]) => Promise<T>;
174
- /**
175
- * Executes the given named query with the given parameters and returns a promise with the result.
176
- *
177
- * For more information about named queries in Squid, please refer to the
178
- * {@link https://docs.squid.cloud/docs/development-tools/backend/named-queries documentation}.
179
- *
180
- * @param integrationId The id of the integration that the named query is defined with.
181
- * @param queryName The name of the named query.
182
- * @param params The parameters to pass to the named query.
183
- * @returns A promise that resolves with the result of the named query.
184
- * @typeParam T The type of the result of the named query.
185
- */
186
- executeNamedQuery: <T = any>(integrationId: IntegrationId, queryName: QueryName, params: Record<string, any>) => Promise<T[]>;
187
- /**
188
- * Executes a native relational query with the given parameters and returns a promise with the result.
189
- *
190
- * Native queries allow you to execute raw SQL or other database-specific queries directly against the database.
191
- * This can be useful when you need to perform operations that are not easily accomplished with named queries or
192
- * other high-level abstractions.
193
- *
194
- * @param integrationId The id of the integration that the query is associated with.
195
- * @param query The raw SQL or other database-specific query to execute.
196
- * @param params (Optional) The parameters to pass to the query. Defaults to an empty object.
197
- * @returns A promise that resolves with the result of the query.
198
- * @type {Promise<Array<SquidDocument>>}
199
- */
200
- executeNativeRelationalQuery: <T = any>(integrationId: IntegrationId, query: string, params?: Record<string, any>) => Promise<T[]>;
201
- /**
202
- * Executes a native MongoDB aggregation pipeline with the given parameters and returns a promise with the result.
203
- *
204
- * Native queries allow you to execute raw MongoDB queries directly against the database.
205
- * This can be particularly useful when you need to perform complex operations or aggregations that are not
206
- * easily accomplished with standard query methods or other high-level abstractions provided by the database driver
207
- * or ORM.
208
- *
209
- * @param {IntegrationId} integrationId - The id of the integration that the query is associated with.
210
- * @param {string} collectionName - The name of the MongoDB collection to run the aggregation pipeline against.
211
- * @param {Array<Record<string, any>>} [aggregationPipeline=[]] - The array of aggregation stages to be executed.
212
- * Each stage in the pipeline is an object specifying the operation to be performed.
213
- * @returns {Promise<Array<T>>} A promise that resolves with an array of documents resulting from the aggregation
214
- * pipeline. Each document in the array is of the generic type T, which can be specified when calling the function.
215
- * @template T - The type of the documents that are expected to be returned by the aggregation pipeline. If not
216
- * specified, any type is assumed by default.
217
- * @type {Promise<Array<SquidDocument>>}
218
- */
219
- executeNativeMongoQuery: <T = any>(integrationId: IntegrationId, collectionName: string, aggregationPipeline?: Array<Record<string, any>>) => Promise<T[]>;
220
- /**
221
- * Invokes the given HTTP API (defined by the integration ID and the endpoint ID) with the given request parameters
222
- * and returns a promise with the response. The structure of the request and the response is defined in the
223
- * integration's schema page.
224
- *
225
- * For more information about API integrations in Squid, please refer to the
226
- * {@link https://docs.squid.cloud/docs/integrations/api/httpapi documentation}.
227
- *
228
- * @param integrationId The id of the integration that the API is defined with.
229
- * @param endpointId The id of the endpoint in the API integration.
230
- * @param request The request parameters to pass to the API.
231
- * @returns A promise that resolves with the response of the API.
232
- * @typeParam T The type of the response of the API.
233
- */
234
- callApi: <T = any>(integrationId: IntegrationId, endpointId: ApiEndpointId, request?: Record<string, any>) => Promise<T>;
235
- /**
236
- * Returns a GraphQL client for the given integration. The GraphQL client can be used to execute GraphQL queries and
237
- * mutations. For more information about GraphQL in Squid, please refer to the
238
- * {@link https://docs.squid.cloud/docs/integrations/api/graphql documentation}.
239
- *
240
- * @param integrationId The id of the integration that the GraphQL API is defined with.
241
- * @returns A GraphQL client for the given integration.
242
- */
243
- graphql: (integrationId: IntegrationId) => GraphQLClient;
244
- /**
245
- * Returns a set of AI specific clients.
246
- *
247
- * @returns A set of AI specific clients.
248
- */
249
- ai: () => AiClient;
250
- get secrets(): SecretClient;
251
- /**
252
- * Returns a distributed lock for the given mutex. The lock can be used to synchronize access to a shared resource.
253
- * The lock will be released when the release method on the returned object is invoked or whenever the connection
254
- * with the server is lost.
255
- * @param mutex A string that uniquely identifies the lock.
256
- * @returns A promise that resolves with the lock object. The promise will reject if failed to acquire the lock.
257
- */
258
- acquireLock: (mutex: string) => Promise<DistributedLock>;
259
- /**
260
- * Destructs the Squid Client. Unsubscribes from all ongoing queries or requests, and clears the local data.
261
- * After invoking this method, the Squid client will not be usable.
262
- *
263
- * @returns A promise that resolves when the destruct process is complete.
264
- */
265
- destruct: () => Promise<void>;
266
- /** Provides information about the connection to the Squid Server. */
267
- connectionDetails: () => ConnectionDetails;
268
- private validateNotDestructed;
269
- }
1
+ import { AdminClient } from './admin-client';
2
+ import { AiClient } from './ai-client';
3
+ import { ApiClient } from './api-client';
4
+ import { CollectionReference } from './collection-reference';
5
+ import { ConnectionDetails } from './connection-details';
6
+ import { DistributedLock, DistributedLockOptions } from './distributed-lock.manager';
7
+ import { ExecuteFunctionOptions } from './execute-function-options';
8
+ import { ExternalAuthClient } from './external-auth-client';
9
+ import { ExtractionClient } from './extraction-client';
10
+ import { JobClient } from './job-client';
11
+ import { NotificationClient } from './notification-client';
12
+ import { ObservabilityClient } from './observability-client';
13
+ import { ApiKey, AppId, CollectionName, DocumentData, EnvironmentId, IntegrationId, SquidDeveloperId, SquidRegion } from './public-types';
14
+ import { QueueManager } from './queue.manager';
15
+ import { SchedulerClient } from './scheduler-client';
16
+ import { StorageClient } from './storage-client';
17
+ import { TransactionId } from './types';
18
+ import { WebClient } from './web-client';
19
+ import { ExecuteWebhookOptions } from './webhook.manager';
20
+ /**
21
+ * The different options that can be used to initialize a Squid instance.
22
+ * @category Platform
23
+ */
24
+ export interface SquidOptions {
25
+ /**
26
+ * A function that can be used to wrap messages coming from Squid to the application. This is useful for
27
+ * different frameworks that need to wrap messages in order to detect changes (like Angular).
28
+ * @param fn The function to wrap.
29
+ */
30
+ messageNotificationWrapper?: (fn: () => any) => any;
31
+ /**
32
+ * The application ID that is used to identify the application in Squid. The ID can be found in the Squid Cloud
33
+ * Console.
34
+ */
35
+ appId: AppId;
36
+ /**
37
+ * The application API key, using the API key can be used to bypass security rules and other restrictions.
38
+ * The API key can be found in the Squid Console.
39
+ */
40
+ apiKey?: ApiKey;
41
+ /**
42
+ * Access token provider for the Squid instance.
43
+ * Used for managing the process of verifying the identity and authorization of users who attempt to access this
44
+ * application via the current Squid instance.
45
+ *
46
+ * When the authProvider is set, the Squid service will fetch a token and include it with every request to the Squid
47
+ * backend.
48
+ *
49
+ * On the backend, Squid will validate the access token.
50
+ */
51
+ authProvider?: SquidAuthProvider;
52
+ /**
53
+ * The region that the application is running in. This is used to determine the URL of the Squid API.
54
+ */
55
+ region: SquidRegion;
56
+ /**
57
+ * The environment ID to work with, if not specified the default environment (prod) will be used.
58
+ */
59
+ environmentId?: EnvironmentId;
60
+ /**
61
+ * The user ID of the developer that runs the environment locally.
62
+ */
63
+ squidDeveloperId?: SquidDeveloperId;
64
+ /**
65
+ * The console region (optional and used for on-prem deployments of Squid)
66
+ */
67
+ consoleRegion?: string;
68
+ }
69
+ /**
70
+ * Authentication data provider for Squid requests.
71
+ * @category Authentication
72
+ */
73
+ export interface SquidAuthProvider {
74
+ /**
75
+ * Optional Auth integration id.
76
+ * Sent as a part of all Squid requests to the backend.
77
+ */
78
+ integrationId: string;
79
+ /**
80
+ * Returns a valid AccessToken or undefined if there is no active authorized session.
81
+ * Called by Squid every time a Squid client makes requests to the Squid backend.
82
+ */
83
+ getToken(): Promise<string | undefined> | string | undefined;
84
+ }
85
+ /**
86
+ * The main entry point to the Squid Client SDK.
87
+ *
88
+ * The Squid class provides a comprehensive array of functionality for accessing the different integrations, executing
89
+ * backend functions, managing data, and more. Upon instantiating the Squid class, you will have access to all of these
90
+ * capabilities.
91
+ * All public Squid functions are bound to `this` and can be used with a destructuring patterns,
92
+ * like `const {setAuthProvider} = useSquid()`
93
+ *
94
+ * @category Platform
95
+ */
96
+ export declare class Squid {
97
+ readonly options: SquidOptions;
98
+ private static readonly squidInstancesMap;
99
+ private readonly socketManager;
100
+ private readonly dataManager;
101
+ private readonly documentReferenceFactory;
102
+ private readonly documentStore;
103
+ private readonly lockManager;
104
+ private readonly querySubscriptionManager;
105
+ private readonly localQueryManager;
106
+ private readonly queryBuilderFactory;
107
+ private readonly collectionReferenceFactory;
108
+ private readonly backendFunctionManager;
109
+ private readonly webhookManager;
110
+ private readonly nativeQueryManager;
111
+ private readonly destructManager;
112
+ private readonly documentIdentityService;
113
+ private readonly distributedLockManager;
114
+ private readonly authManager;
115
+ private readonly clientIdService;
116
+ private readonly _connectionDetails;
117
+ private readonly querySender;
118
+ private readonly aiClient;
119
+ private readonly jobClient;
120
+ private readonly apiClient;
121
+ private readonly adminClient;
122
+ private readonly webClient;
123
+ private readonly observabilityClient;
124
+ private readonly queueManagerFactory;
125
+ private readonly schedulerClient;
126
+ private readonly notificationClient;
127
+ private readonly _appId;
128
+ /**
129
+ * Creates a new instance of Squid with the given options.
130
+ *
131
+ * @param options The options for initializing the Squid instance.
132
+ */
133
+ constructor(options: SquidOptions);
134
+ /**
135
+ * Returns the observability client for metrics.
136
+ */
137
+ get observability(): ObservabilityClient;
138
+ /**
139
+ * Returns the scheduler client for managing scheduled jobs and tasks.
140
+ */
141
+ get schedulers(): SchedulerClient;
142
+ /**
143
+ * Returns the application ID of the current Squid instance.
144
+ */
145
+ get appId(): AppId;
146
+ /**
147
+ * Returns the global Squid instance with the given options, creating a new instance if one with the same options
148
+ * does not exist.
149
+ *
150
+ * @param options The options for initializing the Squid instance.
151
+ * @returns A global Squid instance with the given options.
152
+ */
153
+ static getInstance(options: SquidOptions): Squid;
154
+ /**
155
+ * Returns all the global Squid instances.
156
+ *
157
+ * @returns An array of all the global Squid instances.
158
+ */
159
+ static getInstances(): Array<Squid>;
160
+ /**
161
+ * Sets the authorization access token (OAuth2.0) provider that will be sent to the server and will be used for
162
+ * providing the `auth` object to the security rules.
163
+ *
164
+ * @param authProvider The OAuth2.0 access token provider invoked for every backend request by Squid.
165
+ * When the provider returns undefined, no authorization information is sent.
166
+ * When a new provider is set, all future Squid backend requests will use the new token provider, and exising
167
+ * in-flight requests won't be affected.
168
+ * @returns void.
169
+ */
170
+ setAuthProvider(authProvider: SquidAuthProvider): void;
171
+ /**
172
+ * Returns a reference to the collection in the provided integration.
173
+ *
174
+ * If the integrationId is not provided, the `built_in_db` integration id will be used.
175
+ *
176
+ * For more information on the CollectionReference object, please refer to the
177
+ * {@link https://docs.getsquid.ai/docs/sdk/client-sdk/database/collection-reference documentation}.
178
+ *
179
+ * @param collectionName The name of the collection.
180
+ * @param integrationId The id of the integration, default to `built_in_db`.
181
+ * @returns A reference to the collection in the provided integration.
182
+ * @typeParam T The type of the documents in the collection.
183
+ */
184
+ collection<T extends DocumentData>(collectionName: CollectionName, integrationId?: IntegrationId): CollectionReference<T>;
185
+ /**
186
+ * Runs the given callback as an atomic change. All the mutations that are executed using the provided transactionId
187
+ * will be atomic. Note that mutations for different integrations will not be atomic.
188
+ *
189
+ * For more information about transactions in Squid, please refer to the
190
+ * {@link https://docs.getsquid.ai/docs/sdk/client-sdk/database/transactions documentation}.
191
+ *
192
+ * @param fn The callback to run as an atomic change. The function receives a transactionId that should be used for
193
+ * all the mutations that should be atomic. The function should return a promise.
194
+ *
195
+ * @returns A promise that resolves when the transactions are committed on the server.
196
+ */
197
+ runInTransaction<T = any>(fn: (transactionId: TransactionId) => Promise<T>): Promise<T>;
198
+ /**
199
+ * Executes a backend function identified by its name, passing the provided parameters, and returns a promise with
200
+ * the result.
201
+ *
202
+ * For detailed information on backend functions in Squid, see the
203
+ * {@link https://docs.getsquid.ai/docs/sdk/backend-sdk/executables documentation}.
204
+ *
205
+ * Files support:
206
+ * - To send a file to the backend, simply include it as one of the parameters; it will be received as a `SquidFile`
207
+ * on the backend.
208
+ * - Arrays of files can also be passed directly as parameters.
209
+ *
210
+ * @param functionNameOrOptions - The name of the backend function to execute or detailed options which include
211
+ * additional advanced options along with the function name.
212
+ * @param params - A list of parameters to pass to the backend function.
213
+ * @returns A promise that resolves to the result of the backend function.
214
+ * @typeParam T - The expected type of the result returned by the backend function.
215
+ */
216
+ executeFunction<T = any>(functionNameOrOptions: string | ExecuteFunctionOptions<T>, ...params: Array<any | File>): Promise<T>;
217
+ /**
218
+ * Executes a backend function with custom headers, passing the provided parameters, and returns a promise with
219
+ * the result. The headers will be accessible in the backend via `this.context.headers`.
220
+ *
221
+ * For detailed information on backend functions in Squid, see the
222
+ * {@link https://docs.getsquid.ai/docs/sdk/backend-sdk/executables documentation}.
223
+ *
224
+ * Files support:
225
+ * - To send a file to the backend, simply include it as one of the parameters; it will be received as a `SquidFile`
226
+ * on the backend.
227
+ * - Arrays of files can also be passed directly as parameters.
228
+ *
229
+ * @param functionNameOrOptions - The name of the backend function to execute or detailed options which include
230
+ * additional advanced options along with the function name.
231
+ * @param headers - Custom HTTP headers to send with the request. These headers will be available in the backend
232
+ * function via `this.context.headers`.
233
+ * @param params - A list of parameters to pass to the backend function.
234
+ * @returns A promise that resolves to the result of the backend function.
235
+ * @typeParam T - The expected type of the result returned by the backend function.
236
+ */
237
+ executeFunctionWithHeaders<T = any>(functionNameOrOptions: string | ExecuteFunctionOptions<T>, headers: Record<string, string>, ...params: Array<any | File>): Promise<T>;
238
+ /**
239
+ * Executes a webhook identified by its ID, passing the provided options, and returns a promise with the result.
240
+ *
241
+ * For detailed information on webhooks in Squid, see the
242
+ * {@link https://docs.getsquid.ai/docs/sdk/backend-sdk/webhooks documentation}.
243
+ *
244
+ * Files support:
245
+ * - To send files to the webhook, include them in the options.files array; they will be received as `SquidFile`
246
+ * objects on the backend.
247
+ *
248
+ * @param webhookId - The ID of the webhook to execute.
249
+ * @param options - Optional configuration including headers, query parameters, body, and files.
250
+ * @returns A promise that resolves to the result of the webhook execution.
251
+ * @typeParam T - The expected type of the result returned by the webhook.
252
+ */
253
+ executeWebhook<T = any>(webhookId: string, options?: ExecuteWebhookOptions): Promise<T>;
254
+ /**
255
+ * Executes a native relational query with the given parameters and returns a promise with the result.
256
+ * See https://docs.getsquid.ai/docs/sdk/client-sdk/database/native-queries.
257
+ *
258
+ * @param integrationId The id of the integration that the query is associated with.
259
+ * @param query The raw SQL or database-specific query string to execute. Use named bind variables enclosed in ${},
260
+ * e.g., ${firstName}.
261
+ * @param params (Optional) An object containing key-value pairs to bind to the query variables. Defaults to an empty
262
+ * object.
263
+ * @returns A promise that resolves with the result of the query.
264
+ */
265
+ executeNativeRelationalQuery<T = any>(integrationId: IntegrationId, query: string, params?: Record<string, any>): Promise<Array<T>>;
266
+ /**
267
+ * Executes a native pure query with the given parameters and returns a promise with the result.
268
+ * See https://docs.getsquid.ai/docs/sdk/client-sdk/database/native-queries.
269
+ *
270
+ * @param integrationId The id of the integration that the query is associated with.
271
+ * @param query The raw SQL or database-specific query string to execute. Use named bind variables enclosed in ${},
272
+ * e.g., ${firstName}.
273
+ * @param params (Optional) An object containing key-value pairs to bind to the query variables. Defaults to an empty
274
+ * object.
275
+ * @returns A promise that resolves with the result of the query.
276
+ */
277
+ executeNativePureQuery<T = any>(integrationId: IntegrationId, query: string, params?: Record<string, any>): Promise<Array<T>>;
278
+ /**
279
+ * Executes a native Mongo/built-in-db query with the given pipeline and returns a promise with the result.
280
+ * See https://docs.getsquid.ai/docs/sdk/client-sdk/database/native-queries#native-mongodb-queries.
281
+ *
282
+ * @param integrationId The id of the integration that the query is associated with.
283
+ * @param collectionName The collection to query.
284
+ * @param aggregationPipeline The aggregation pipeline for the query.
285
+ * @returns A promise that resolves with the result of the query.
286
+ */
287
+ executeNativeMongoQuery<T = any>(integrationId: IntegrationId, collectionName: string, aggregationPipeline: Array<any | undefined>): Promise<Array<T>>;
288
+ /**
289
+ * Executes a native Elasticsearch query against the given index and endpoint.
290
+ * See https://docs.getsquid.ai/docs/sdk/client-sdk/database/native-queries.
291
+ *
292
+ * @param integrationId The id of the integration that the query is associated with.
293
+ * @param index The Elasticsearch index to query.
294
+ * @param body The raw request body to send (must be a valid ES query DSL object).
295
+ * @param endpoint The Elasticsearch endpoint to call (default: "_search").
296
+ * @param method The HTTP method to use (default: "GET").
297
+ * @returns A promise that resolves with the result array.
298
+ */
299
+ executeNativeElasticQuery<T = any>(integrationId: IntegrationId, index: string, body: Record<string, any>, endpoint?: string, method?: 'GET' | 'POST'): Promise<Array<T>>;
300
+ /**
301
+ * Returns a set of AI specific clients.
302
+ */
303
+ ai(): AiClient;
304
+ /**
305
+ * Returns a set of functionality for interacting with jobs.
306
+ */
307
+ job(): JobClient;
308
+ /**
309
+ * Returns a set of functionality for interacting with API integrations.
310
+ */
311
+ api(): ApiClient;
312
+ /**
313
+ * Returns the AdminClient instance for performing administrative operations.
314
+ */
315
+ admin(): AdminClient;
316
+ /**
317
+ * Returns a set of functionality for interacting with the web.
318
+ */
319
+ web(): WebClient;
320
+ /**
321
+ * Returns a client for accessing file storage for the current app.
322
+ * Defaults to the built-in storage integration if none is provided.
323
+ *
324
+ * @param integrationId The storage integration ID (default is 'built_in_storage').
325
+ */
326
+ storage(integrationId?: IntegrationId): StorageClient;
327
+ /**
328
+ * Returns a client for managing external oauth tokens for integrations.
329
+ * Use this to save authorization codes and retrieve access tokens.
330
+ * Squid automatically handles token refresh when tokens expire.
331
+ *
332
+ * @param integrationId The integration ID
333
+ * @returns An ExternalAuthClient instance for the specified integration
334
+ */
335
+ externalAuth(integrationId: IntegrationId): ExternalAuthClient;
336
+ /**
337
+ * Returns a client for working with structured data extraction tools.
338
+ */
339
+ extraction(): ExtractionClient;
340
+ /**
341
+ * Returns a distributed lock for the given mutex. The lock can be used to synchronize access to a shared resource.
342
+ * The lock will be released when the release method on the returned object is invoked or whenever the connection
343
+ * with the server is lost.
344
+ * @param mutex A string that uniquely identifies the lock.
345
+ * @param options Optional configuration for the lock, including maxHoldTimeMillis to automatically release the lock
346
+ * after a specified duration.
347
+ * @returns A promise that resolves with the lock object. The promise will reject if failed to acquire the lock.
348
+ */
349
+ acquireLock(mutex: string, options?: DistributedLockOptions): Promise<DistributedLock>;
350
+ /**
351
+ * Executes the given callback while holding a lock for the given mutex. The lock will be released when the callback
352
+ * finishes.
353
+ * @param mutex A string that uniquely identifies the lock.
354
+ * @param fn The callback to execute while holding the lock.
355
+ * @returns A promise that resolves with the result of the callback. The promise will reject if failed
356
+ * to acquire the lock.
357
+ */
358
+ withLock<T>(mutex: string, fn: (lock: DistributedLock) => Promise<T>): Promise<T>;
359
+ /**
360
+ * Returns a queue manager for the given topic name and integration id. Using the queue manager you can consume and
361
+ * produce messages
362
+ */
363
+ queue<T>(topicName: string, integrationId?: IntegrationId): QueueManager<T>;
364
+ /**
365
+ * Destructs the Squid Client. Unsubscribes from all ongoing queries or requests, and clears the local data.
366
+ * After invoking this method, the Squid client will not be usable.
367
+ *
368
+ * @returns A promise that resolves when the destruct process is complete.
369
+ */
370
+ destruct(): Promise<void>;
371
+ /** Set to true if the client was destructured. */
372
+ get isDestructed(): boolean;
373
+ /** Provides information about the connection to the Squid Server. */
374
+ connectionDetails(): ConnectionDetails;
375
+ /** Returns the notification client for handling (publishing and receiving) custom messages. */
376
+ getNotificationClient(): NotificationClient;
377
+ private _validateNotDestructed;
378
+ }