@squidcloud/client 1.0.174 → 1.0.176
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +168 -114
- package/dist/internal-common/src/public-types/api-call.public-context.d.ts +17 -1
- package/dist/internal-common/src/public-types/bundle-api.public-types.d.ts +50 -0
- package/dist/typescript-client/src/ai-assistant-client.d.ts +1 -1
- package/dist/typescript-client/src/ai-chatbot-client.d.ts +2 -2
- package/dist/typescript-client/src/api.manager.d.ts +3 -4
- package/dist/typescript-client/src/rpc.manager.d.ts +0 -8
- package/dist/typescript-client/src/squid-http-client.d.ts +1 -0
- package/dist/typescript-client/src/squid.d.ts +7 -21
- package/package.json +3 -2
package/dist/cjs/index.js
CHANGED
|
@@ -27525,7 +27525,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27525
27525
|
deserializeQuery: () => (/* reexport */ deserializeQuery),
|
|
27526
27526
|
generateId: () => (/* reexport */ generateId),
|
|
27527
27527
|
generateShortId: () => (/* reexport */ generateShortId),
|
|
27528
|
-
isSimpleCondition: () => (/* reexport */ isSimpleCondition)
|
|
27528
|
+
isSimpleCondition: () => (/* reexport */ isSimpleCondition),
|
|
27529
|
+
limiterConfigToOptions: () => (/* reexport */ limiterConfigToOptions)
|
|
27529
27530
|
});
|
|
27530
27531
|
|
|
27531
27532
|
// EXTERNAL MODULE: external "rxjs"
|
|
@@ -28730,7 +28731,7 @@ class AiChatbotContextReference {
|
|
|
28730
28731
|
* Updates an existing context entry on the chatbot profile. This will result in an error if an entry has not yet
|
|
28731
28732
|
* been created for the current context id.
|
|
28732
28733
|
*
|
|
28733
|
-
* @param data An object containing options for
|
|
28734
|
+
* @param data An object containing options for updating the entry.
|
|
28734
28735
|
* @param data.title - The title of the entry.
|
|
28735
28736
|
* @param data.context - The context data.
|
|
28736
28737
|
* @returns A promise that resolves when the context is successfully updated.
|
|
@@ -28803,7 +28804,7 @@ class AiChatbotInstructionReference {
|
|
|
28803
28804
|
* Updates an existing instruction entry on the chatbot profile. This will result in an error if an entry has not
|
|
28804
28805
|
* yet been created for the current instruction id.
|
|
28805
28806
|
*
|
|
28806
|
-
* @param data An object containing options for
|
|
28807
|
+
* @param data An object containing options for updating the entry.
|
|
28807
28808
|
* @param data.instruction - The instruction data.
|
|
28808
28809
|
* @returns A promise that resolves when the instruction is successfully updated.
|
|
28809
28810
|
*/
|
|
@@ -28886,7 +28887,7 @@ class ApiCallContext {
|
|
|
28886
28887
|
this.body = prototype.body;
|
|
28887
28888
|
this.queryParams = prototype.queryParams;
|
|
28888
28889
|
this.pathParams = prototype.pathParams;
|
|
28889
|
-
this.
|
|
28890
|
+
this.options = prototype.options;
|
|
28890
28891
|
}
|
|
28891
28892
|
}
|
|
28892
28893
|
|
|
@@ -29087,6 +29088,51 @@ class BaseQueryBuilder {
|
|
|
29087
29088
|
}
|
|
29088
29089
|
}
|
|
29089
29090
|
|
|
29091
|
+
;// CONCATENATED MODULE: ../internal-common/src/public-types/bundle-api.public-types.ts
|
|
29092
|
+
/**
|
|
29093
|
+
* Convert LimiterConfig to LimiterOptions.
|
|
29094
|
+
*
|
|
29095
|
+
* This decouples the required syntax for the developer from the internal implementation.
|
|
29096
|
+
*
|
|
29097
|
+
* @param config LimiterConfig to convert.
|
|
29098
|
+
*/
|
|
29099
|
+
function limiterConfigToOptions(config) {
|
|
29100
|
+
// Deal with rateLimit if provided.
|
|
29101
|
+
if (config.rateLimit !== undefined) {
|
|
29102
|
+
// Check if rateLimit is of type number and convert to RateLimitOptions.
|
|
29103
|
+
if (typeof config.rateLimit === 'number') {
|
|
29104
|
+
config.rateLimit = [{ value: config.rateLimit, scope: 'global' }];
|
|
29105
|
+
}
|
|
29106
|
+
else if (typeof config.rateLimit === 'object' && !Array.isArray(config.rateLimit)) {
|
|
29107
|
+
config.rateLimit = [config.rateLimit];
|
|
29108
|
+
}
|
|
29109
|
+
// Set defaults if not provided for each item in rateLimit and quotaLimit.
|
|
29110
|
+
config.rateLimit.forEach((options) => {
|
|
29111
|
+
if (options.scope === undefined) {
|
|
29112
|
+
options.scope = 'global';
|
|
29113
|
+
}
|
|
29114
|
+
});
|
|
29115
|
+
}
|
|
29116
|
+
// Same for quotaLimit.
|
|
29117
|
+
if (config.quotaLimit !== undefined) {
|
|
29118
|
+
if (typeof config.quotaLimit === 'number') {
|
|
29119
|
+
config.quotaLimit = [{ value: config.quotaLimit, scope: 'global', renewPeriod: 'monthly' }];
|
|
29120
|
+
}
|
|
29121
|
+
else if (typeof config.quotaLimit === 'object' && !Array.isArray(config.quotaLimit)) {
|
|
29122
|
+
config.quotaLimit = [config.quotaLimit];
|
|
29123
|
+
}
|
|
29124
|
+
config.quotaLimit.forEach((options) => {
|
|
29125
|
+
if (options.scope === undefined) {
|
|
29126
|
+
options.scope = 'global';
|
|
29127
|
+
}
|
|
29128
|
+
if (options.renewPeriod === undefined) {
|
|
29129
|
+
options.renewPeriod = 'monthly';
|
|
29130
|
+
}
|
|
29131
|
+
});
|
|
29132
|
+
}
|
|
29133
|
+
return config;
|
|
29134
|
+
}
|
|
29135
|
+
|
|
29090
29136
|
;// CONCATENATED MODULE: ../internal-common/src/public-types/communication.public-types.ts
|
|
29091
29137
|
const ENVIRONMENT_IDS = ['dev', 'prod'];
|
|
29092
29138
|
// noinspection JSUnusedGtypeslobalSymbols
|
|
@@ -47733,17 +47779,16 @@ class AiChatbotClientFactory {
|
|
|
47733
47779
|
|
|
47734
47780
|
|
|
47735
47781
|
class ApiManager {
|
|
47736
|
-
constructor(clientIdService, rpcManager
|
|
47782
|
+
constructor(clientIdService, rpcManager) {
|
|
47737
47783
|
this.clientIdService = clientIdService;
|
|
47738
47784
|
this.rpcManager = rpcManager;
|
|
47739
|
-
this.apiServerUrlOverrideMapping = apiServerUrlOverrideMapping;
|
|
47740
47785
|
}
|
|
47741
|
-
callApiAndSubscribe(integrationId, endpointId, request) {
|
|
47786
|
+
callApiAndSubscribe(integrationId, endpointId, request, options) {
|
|
47742
47787
|
const callApiRequest = {
|
|
47743
47788
|
integrationId,
|
|
47744
47789
|
endpointId,
|
|
47745
47790
|
request,
|
|
47746
|
-
|
|
47791
|
+
options,
|
|
47747
47792
|
};
|
|
47748
47793
|
return (0,external_rxjs_.race)((0,external_rxjs_.from)(this.rpcManager.post('api/call', callApiRequest)).pipe(map(response => {
|
|
47749
47794
|
const parsedPayload = response.payload ? deserializeObj(response.payload) : undefined;
|
|
@@ -47751,7 +47796,7 @@ class ApiManager {
|
|
|
47751
47796
|
return parsedPayload;
|
|
47752
47797
|
}
|
|
47753
47798
|
else {
|
|
47754
|
-
throw new Error(`Got error while calling API (HTTP Status ${response.httpStatus}). Message: ${
|
|
47799
|
+
throw new Error(`Got error while calling API (HTTP Status ${response.httpStatus}). Message: ${response.payload}`);
|
|
47755
47800
|
}
|
|
47756
47801
|
})), this.clientIdService.observeClientTooOld().pipe(map(() => {
|
|
47757
47802
|
throw new Error('CLIENT_NOT_CONNECTED');
|
|
@@ -50254,11 +50299,117 @@ class RateLimiter {
|
|
|
50254
50299
|
;// CONCATENATED MODULE: external "axios"
|
|
50255
50300
|
const external_axios_namespaceObject = require("axios");
|
|
50256
50301
|
var external_axios_default = /*#__PURE__*/__webpack_require__.n(external_axios_namespaceObject);
|
|
50257
|
-
;// CONCATENATED MODULE: ./src/
|
|
50302
|
+
;// CONCATENATED MODULE: ./src/squid-http-client.ts
|
|
50258
50303
|
|
|
50259
50304
|
|
|
50260
50305
|
|
|
50261
50306
|
|
|
50307
|
+
/** @internal. */
|
|
50308
|
+
class RpcError extends Error {
|
|
50309
|
+
constructor(statusCode, statusText, headers, url, message) {
|
|
50310
|
+
super(message || `RPC error ${statusCode} ${statusText} calling ${url}`);
|
|
50311
|
+
this.statusCode = statusCode;
|
|
50312
|
+
this.statusText = statusText;
|
|
50313
|
+
this.headers = headers;
|
|
50314
|
+
this.url = url;
|
|
50315
|
+
}
|
|
50316
|
+
}
|
|
50317
|
+
/**
|
|
50318
|
+
* Runs a post request to the given URL.
|
|
50319
|
+
* @internal.
|
|
50320
|
+
*/
|
|
50321
|
+
async function squidHttpPost({ url, headers, files, filesFieldName, message }) {
|
|
50322
|
+
const isFetch = !!getSquidPrivateOption(SQUID_PRIVATE_OPTION_USE_FETCH_IN_RPC_MANAGER);
|
|
50323
|
+
if (isFetch) {
|
|
50324
|
+
const requestOptionHeaders = new Headers(headers);
|
|
50325
|
+
const requestOptions = { method: 'POST', headers: requestOptionHeaders, body: undefined };
|
|
50326
|
+
if (files.length) {
|
|
50327
|
+
const formData = new FormData();
|
|
50328
|
+
for (const file of files) {
|
|
50329
|
+
const blob = file instanceof Blob ? file : file.blob;
|
|
50330
|
+
const filename = file instanceof Blob ? undefined : file.name;
|
|
50331
|
+
formData.append(filesFieldName, blob, filename);
|
|
50332
|
+
}
|
|
50333
|
+
formData.append('body', serializeObj(message));
|
|
50334
|
+
requestOptions.body = formData;
|
|
50335
|
+
}
|
|
50336
|
+
else {
|
|
50337
|
+
requestOptionHeaders.append('Content-Type', 'application/json');
|
|
50338
|
+
requestOptions.body = serializeObj(message);
|
|
50339
|
+
}
|
|
50340
|
+
const response = await fetch(url, requestOptions);
|
|
50341
|
+
if (!response.ok) {
|
|
50342
|
+
const errorBody = await response.text();
|
|
50343
|
+
const errorResponse = tryDeserializing(errorBody);
|
|
50344
|
+
const errorResponseMessage = typeof errorResponse === 'string' ? errorResponse : errorResponse['message'];
|
|
50345
|
+
throw new RpcError(response.status, response.statusText, response.headers, url, errorResponseMessage);
|
|
50346
|
+
}
|
|
50347
|
+
const responseData = await response.text();
|
|
50348
|
+
const parsedResponse = tryDeserializing(responseData);
|
|
50349
|
+
DebugLogger.debug(`received response: ${JSON.stringify(parsedResponse)}`);
|
|
50350
|
+
return parsedResponse;
|
|
50351
|
+
}
|
|
50352
|
+
else {
|
|
50353
|
+
let axiosResponse;
|
|
50354
|
+
try {
|
|
50355
|
+
if (files.length) {
|
|
50356
|
+
const formData = new FormData();
|
|
50357
|
+
for (const file of files) {
|
|
50358
|
+
const blob = file instanceof Blob ? file : file.blob;
|
|
50359
|
+
const filename = file instanceof Blob ? undefined : file.name;
|
|
50360
|
+
formData.append(filesFieldName, blob, filename);
|
|
50361
|
+
}
|
|
50362
|
+
formData.append('body', serializeObj(message));
|
|
50363
|
+
// Make the axios call
|
|
50364
|
+
axiosResponse = await external_axios_default().post(url, formData, {
|
|
50365
|
+
headers: Object.assign({}, headers),
|
|
50366
|
+
responseType: 'text',
|
|
50367
|
+
});
|
|
50368
|
+
}
|
|
50369
|
+
else {
|
|
50370
|
+
axiosResponse = await external_axios_default().post(url, serializeObj(message), {
|
|
50371
|
+
headers: Object.assign(Object.assign({}, headers), { 'Content-Type': 'application/json' }),
|
|
50372
|
+
responseType: 'text',
|
|
50373
|
+
});
|
|
50374
|
+
}
|
|
50375
|
+
}
|
|
50376
|
+
catch (error) {
|
|
50377
|
+
if ((0,external_axios_namespaceObject.isAxiosError)(error)) {
|
|
50378
|
+
const { response } = error;
|
|
50379
|
+
if (!response)
|
|
50380
|
+
throw error;
|
|
50381
|
+
let message;
|
|
50382
|
+
try {
|
|
50383
|
+
const errorResponse = tryDeserializing(response.data);
|
|
50384
|
+
message = typeof errorResponse === 'string' ? errorResponse : errorResponse['message'];
|
|
50385
|
+
}
|
|
50386
|
+
catch (_a) { }
|
|
50387
|
+
if (!message)
|
|
50388
|
+
message = response.statusText;
|
|
50389
|
+
throw new RpcError(response.status, response.statusText, response.headers, url, message);
|
|
50390
|
+
}
|
|
50391
|
+
else {
|
|
50392
|
+
throw error;
|
|
50393
|
+
}
|
|
50394
|
+
}
|
|
50395
|
+
const parsedResponse = tryDeserializing(axiosResponse.data);
|
|
50396
|
+
DebugLogger.debug(`received response: ${JSON.stringify(parsedResponse)}`);
|
|
50397
|
+
return parsedResponse;
|
|
50398
|
+
}
|
|
50399
|
+
}
|
|
50400
|
+
function tryDeserializing(text) {
|
|
50401
|
+
if (!text)
|
|
50402
|
+
return undefined;
|
|
50403
|
+
try {
|
|
50404
|
+
return deserializeObj(text);
|
|
50405
|
+
}
|
|
50406
|
+
catch (_a) { }
|
|
50407
|
+
return text;
|
|
50408
|
+
}
|
|
50409
|
+
|
|
50410
|
+
;// CONCATENATED MODULE: ./src/rpc.manager.ts
|
|
50411
|
+
|
|
50412
|
+
|
|
50262
50413
|
|
|
50263
50414
|
|
|
50264
50415
|
|
|
@@ -50323,105 +50474,16 @@ class RpcManager {
|
|
|
50323
50474
|
this.onGoingRpcCounter.next(this.onGoingRpcCounter.value + 1);
|
|
50324
50475
|
try {
|
|
50325
50476
|
await this.getRateLimiterBucket(path).consume();
|
|
50326
|
-
let headers = {};
|
|
50327
|
-
if (Object.keys(this.staticHeaders)) {
|
|
50328
|
-
headers = Object.assign(Object.assign({}, headers), this.staticHeaders);
|
|
50329
|
-
}
|
|
50330
50477
|
const authHeaders = await this.getAuthHeaders();
|
|
50331
|
-
headers = Object.assign(Object.assign({},
|
|
50478
|
+
const headers = Object.assign(Object.assign({}, this.staticHeaders), authHeaders);
|
|
50332
50479
|
DebugLogger.debug(`sending request: path: ${path} message: ${JSON.stringify(message)}`);
|
|
50333
50480
|
const url = getApplicationUrl(this.region, this.appId, path);
|
|
50334
|
-
|
|
50335
|
-
if (isFetch) {
|
|
50336
|
-
const requestOptionHeaders = new Headers(headers);
|
|
50337
|
-
const requestOptions = { method: 'POST', headers: requestOptionHeaders, body: undefined };
|
|
50338
|
-
if (files.length) {
|
|
50339
|
-
const formData = new FormData();
|
|
50340
|
-
files.forEach(file => {
|
|
50341
|
-
const blob = file instanceof Blob ? file : file.blob;
|
|
50342
|
-
const filename = file instanceof Blob ? undefined : file.name;
|
|
50343
|
-
formData.append(filesFieldName, blob, filename);
|
|
50344
|
-
});
|
|
50345
|
-
formData.append('body', serializeObj(message));
|
|
50346
|
-
requestOptions.body = formData;
|
|
50347
|
-
}
|
|
50348
|
-
else {
|
|
50349
|
-
requestOptionHeaders.append('Content-Type', 'application/json');
|
|
50350
|
-
requestOptions.body = serializeObj(message);
|
|
50351
|
-
}
|
|
50352
|
-
const response = await fetch(url, requestOptions);
|
|
50353
|
-
if (!response.ok) {
|
|
50354
|
-
const errorBody = await response.text();
|
|
50355
|
-
const errorResponse = this.tryDeserializing(errorBody);
|
|
50356
|
-
const errorResponseMessage = typeof errorResponse === 'string' ? errorResponse : errorResponse['message'];
|
|
50357
|
-
throw new RpcError(response.status, response.statusText, response.headers, url, errorResponseMessage);
|
|
50358
|
-
}
|
|
50359
|
-
const responseData = await response.text();
|
|
50360
|
-
const parsedResponse = this.tryDeserializing(responseData);
|
|
50361
|
-
DebugLogger.debug(`received response: ${JSON.stringify(parsedResponse)}`);
|
|
50362
|
-
return parsedResponse;
|
|
50363
|
-
}
|
|
50364
|
-
else {
|
|
50365
|
-
let axiosResponse;
|
|
50366
|
-
try {
|
|
50367
|
-
if (files.length) {
|
|
50368
|
-
const formData = new FormData();
|
|
50369
|
-
files.forEach(file => {
|
|
50370
|
-
const blob = file instanceof Blob ? file : file.blob;
|
|
50371
|
-
const filename = file instanceof Blob ? undefined : file.name;
|
|
50372
|
-
formData.append(filesFieldName, blob, filename);
|
|
50373
|
-
});
|
|
50374
|
-
formData.append('body', serializeObj(message));
|
|
50375
|
-
// Make the axios call
|
|
50376
|
-
axiosResponse = await external_axios_default().post(url, formData, {
|
|
50377
|
-
headers: Object.assign({}, headers),
|
|
50378
|
-
responseType: 'text',
|
|
50379
|
-
});
|
|
50380
|
-
}
|
|
50381
|
-
else {
|
|
50382
|
-
axiosResponse = await external_axios_default().post(url, serializeObj(message), {
|
|
50383
|
-
headers: Object.assign(Object.assign({}, headers), { 'Content-Type': 'application/json' }),
|
|
50384
|
-
responseType: 'text',
|
|
50385
|
-
});
|
|
50386
|
-
}
|
|
50387
|
-
}
|
|
50388
|
-
catch (error) {
|
|
50389
|
-
if ((0,external_axios_namespaceObject.isAxiosError)(error)) {
|
|
50390
|
-
const { response } = error;
|
|
50391
|
-
if (!response)
|
|
50392
|
-
throw error;
|
|
50393
|
-
let message;
|
|
50394
|
-
try {
|
|
50395
|
-
const errorResponse = this.tryDeserializing(response.data);
|
|
50396
|
-
message = typeof errorResponse === 'string' ? errorResponse : errorResponse['message'];
|
|
50397
|
-
}
|
|
50398
|
-
catch (_a) { }
|
|
50399
|
-
if (!message)
|
|
50400
|
-
message = response.statusText;
|
|
50401
|
-
throw new RpcError(response.status, response.statusText, response.headers, url, message);
|
|
50402
|
-
}
|
|
50403
|
-
else {
|
|
50404
|
-
throw error;
|
|
50405
|
-
}
|
|
50406
|
-
}
|
|
50407
|
-
const parsedResponse = this.tryDeserializing(axiosResponse.data);
|
|
50408
|
-
DebugLogger.debug(`received response: ${JSON.stringify(parsedResponse)}`);
|
|
50409
|
-
return parsedResponse;
|
|
50410
|
-
}
|
|
50481
|
+
return await squidHttpPost({ url, headers, message, files, filesFieldName });
|
|
50411
50482
|
}
|
|
50412
50483
|
finally {
|
|
50413
50484
|
this.onGoingRpcCounter.next(this.onGoingRpcCounter.value - 1);
|
|
50414
50485
|
}
|
|
50415
50486
|
}
|
|
50416
|
-
tryDeserializing(text) {
|
|
50417
|
-
if (!text)
|
|
50418
|
-
return undefined;
|
|
50419
|
-
try {
|
|
50420
|
-
return deserializeObj(text);
|
|
50421
|
-
}
|
|
50422
|
-
catch (_a) { }
|
|
50423
|
-
return text;
|
|
50424
|
-
}
|
|
50425
50487
|
getRateLimiterBucket(path) {
|
|
50426
50488
|
if (path.startsWith('ai/chatbot')) {
|
|
50427
50489
|
return (0,dist.truthy)(this.rateLimiters['ai'], 'MISSING_RATE_LIMITER_AI');
|
|
@@ -50432,15 +50494,6 @@ class RpcManager {
|
|
|
50432
50494
|
return (0,dist.truthy)(this.rateLimiters['default'], 'MISSING_RATE_LIMITER_DEFAULT');
|
|
50433
50495
|
}
|
|
50434
50496
|
}
|
|
50435
|
-
class RpcError extends Error {
|
|
50436
|
-
constructor(statusCode, statusText, headers, url, message) {
|
|
50437
|
-
super(message || `RPC error ${statusCode} ${statusText} calling ${url}`);
|
|
50438
|
-
this.statusCode = statusCode;
|
|
50439
|
-
this.statusText = statusText;
|
|
50440
|
-
this.headers = headers;
|
|
50441
|
-
this.url = url;
|
|
50442
|
-
}
|
|
50443
|
-
}
|
|
50444
50497
|
|
|
50445
50498
|
;// CONCATENATED MODULE: ./src/secret.client.ts
|
|
50446
50499
|
class SecretClient {
|
|
@@ -50900,7 +50953,7 @@ class AiAssistantClient {
|
|
|
50900
50953
|
* @param name - The name of the assistant.
|
|
50901
50954
|
* @param instructions - Instructions for the assistant.
|
|
50902
50955
|
* @param functions - Array of function names annotated with "@aiFunction" in your Squid backend that will be
|
|
50903
|
-
* available
|
|
50956
|
+
* available to the assistant.
|
|
50904
50957
|
* @param toolTypes - Optional array of tool types. If you want to use files for retrieval, you must add them using
|
|
50905
50958
|
* the addFileToAssistant method.
|
|
50906
50959
|
* @returns A promise that resolves to the created assistant's ID.
|
|
@@ -51356,7 +51409,7 @@ class Squid {
|
|
|
51356
51409
|
this.documentReferenceFactory.setDataManager(this.dataManager);
|
|
51357
51410
|
this.backendFunctionManager = new BackendFunctionManager(this.clientIdService, this.rpcManager);
|
|
51358
51411
|
this.nativeQueryManager = new NativeQueryManager(this.rpcManager);
|
|
51359
|
-
this.apiManager = new ApiManager(this.clientIdService, this.rpcManager
|
|
51412
|
+
this.apiManager = new ApiManager(this.clientIdService, this.rpcManager);
|
|
51360
51413
|
this.graphqlClientFactory = new GraphQLClientFactory(this.rpcManager, options.region, appId);
|
|
51361
51414
|
this.secretClient = new SecretClient(this.rpcManager);
|
|
51362
51415
|
this._connectionDetails = new ConnectionDetails(this.clientIdService, this.socketManager);
|
|
@@ -51474,12 +51527,13 @@ class Squid {
|
|
|
51474
51527
|
* @param integrationId The id of the integration that the API is defined with.
|
|
51475
51528
|
* @param endpointId The id of the endpoint in the API integration.
|
|
51476
51529
|
* @param request The request parameters to pass to the API.
|
|
51530
|
+
* @param options optional options for the API call.
|
|
51477
51531
|
* @returns A promise that resolves with the response of the API.
|
|
51478
51532
|
* @typeParam T The type of the response of the API.
|
|
51479
51533
|
*/
|
|
51480
|
-
callApi(integrationId, endpointId, request = {}) {
|
|
51534
|
+
callApi(integrationId, endpointId, request = {}, options) {
|
|
51481
51535
|
this._validateNotDestructed();
|
|
51482
|
-
return (0,external_rxjs_.firstValueFrom)(this.apiManager.callApiAndSubscribe(integrationId, endpointId, request));
|
|
51536
|
+
return (0,external_rxjs_.firstValueFrom)(this.apiManager.callApiAndSubscribe(integrationId, endpointId, request, options || {}));
|
|
51483
51537
|
}
|
|
51484
51538
|
/**
|
|
51485
51539
|
* Returns a GraphQL client for the given integration. The GraphQL client can be used to execute GraphQL queries and
|
|
@@ -10,5 +10,21 @@ export declare class ApiCallContext {
|
|
|
10
10
|
readonly body: Record<string, any>;
|
|
11
11
|
readonly queryParams: Record<string, string | number | boolean>;
|
|
12
12
|
readonly pathParams: Record<string, string>;
|
|
13
|
-
readonly
|
|
13
|
+
readonly options: ApiOptions;
|
|
14
|
+
}
|
|
15
|
+
/** The options for calling an API. */
|
|
16
|
+
export interface ApiOptions {
|
|
17
|
+
/** If true, the response will be returned as-is without any processing. */
|
|
18
|
+
nativeResponse?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* An optional string to override the default origin of the API (e.g. https://host:port). Useful for
|
|
21
|
+
* scenarios such as testing, development, or accessing the API from different environments.
|
|
22
|
+
*/
|
|
23
|
+
originOverride?: string;
|
|
24
|
+
}
|
|
25
|
+
/** A native API call response. */
|
|
26
|
+
export interface NativeApiCallResponse<T = unknown> {
|
|
27
|
+
body: T;
|
|
28
|
+
headers: ApiHeaders;
|
|
29
|
+
status: number;
|
|
14
30
|
}
|
|
@@ -30,6 +30,56 @@ export interface TriggerRequest<T extends DocumentData = any> {
|
|
|
30
30
|
docAfter?: T;
|
|
31
31
|
}
|
|
32
32
|
export type SchedulerAction = () => void | Promise<void>;
|
|
33
|
+
export type LimitedAction = () => any | Promise<any>;
|
|
34
|
+
export type LimiterScope = 'ip' | 'user' | 'global';
|
|
35
|
+
export type QuotaRenewPeriod = 'hourly' | 'daily' | 'weekly' | 'monthly' | 'quarterly' | 'annually';
|
|
36
|
+
/**
|
|
37
|
+
* Options for rate limiting.
|
|
38
|
+
*
|
|
39
|
+
* @param value Number of executions permitted per second. Note that we
|
|
40
|
+
* permit bursts of up to 3x the specified limit.
|
|
41
|
+
* @param scope What this limit applies to: per user? per IP? global?
|
|
42
|
+
*/
|
|
43
|
+
export interface RateLimitOptions {
|
|
44
|
+
value: number;
|
|
45
|
+
scope?: LimiterScope;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Options for quota limiting.
|
|
49
|
+
*
|
|
50
|
+
* @param value Number of total executions allowed. Note that this would be
|
|
51
|
+
* reset upon any redeployment of the backend.
|
|
52
|
+
* @param scope What this limit applies to: per user? per IP? global?
|
|
53
|
+
*/
|
|
54
|
+
export interface QuotaLimitOptions {
|
|
55
|
+
value: number;
|
|
56
|
+
scope?: LimiterScope;
|
|
57
|
+
renewPeriod?: QuotaRenewPeriod;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Options for rate and quota limiting backend functions.
|
|
61
|
+
*
|
|
62
|
+
* This mirrors the type in Kotlin. It is not the type the developer defines in their code, which is LimiterConfig.
|
|
63
|
+
*
|
|
64
|
+
* @param rateLimit RateLimitOptions configurations. Allows for different limits at different scopes.
|
|
65
|
+
* @param quotaLimit QuotaLimitOptions configurations. Allows for different limits at different scopes.
|
|
66
|
+
*/
|
|
67
|
+
export interface LimiterOptions {
|
|
68
|
+
rateLimit?: RateLimitOptions[];
|
|
69
|
+
quotaLimit?: QuotaLimitOptions[];
|
|
70
|
+
}
|
|
71
|
+
export type LimiterConfig = {
|
|
72
|
+
rateLimit?: number | RateLimitOptions | Array<RateLimitOptions>;
|
|
73
|
+
quotaLimit?: number | QuotaLimitOptions | Array<QuotaLimitOptions>;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Convert LimiterConfig to LimiterOptions.
|
|
77
|
+
*
|
|
78
|
+
* This decouples the required syntax for the developer from the internal implementation.
|
|
79
|
+
*
|
|
80
|
+
* @param config LimiterConfig to convert.
|
|
81
|
+
*/
|
|
82
|
+
export declare function limiterConfigToOptions(config: LimiterConfig): LimiterOptions;
|
|
33
83
|
export type WebhookAction = ((request: WebhookRequest) => any) | (() => any);
|
|
34
84
|
/** The context provided to a webhook function. */
|
|
35
85
|
export interface WebhookRequest<T = any> {
|
|
@@ -14,7 +14,7 @@ export declare class AiAssistantClient {
|
|
|
14
14
|
* @param name - The name of the assistant.
|
|
15
15
|
* @param instructions - Instructions for the assistant.
|
|
16
16
|
* @param functions - Array of function names annotated with "@aiFunction" in your Squid backend that will be
|
|
17
|
-
* available
|
|
17
|
+
* available to the assistant.
|
|
18
18
|
* @param toolTypes - Optional array of tool types. If you want to use files for retrieval, you must add them using
|
|
19
19
|
* the addFileToAssistant method.
|
|
20
20
|
* @returns A promise that resolves to the created assistant's ID.
|
|
@@ -113,7 +113,7 @@ declare class AiChatbotContextReference {
|
|
|
113
113
|
* Updates an existing context entry on the chatbot profile. This will result in an error if an entry has not yet
|
|
114
114
|
* been created for the current context id.
|
|
115
115
|
*
|
|
116
|
-
* @param data An object containing options for
|
|
116
|
+
* @param data An object containing options for updating the entry.
|
|
117
117
|
* @param data.title - The title of the entry.
|
|
118
118
|
* @param data.context - The context data.
|
|
119
119
|
* @returns A promise that resolves when the context is successfully updated.
|
|
@@ -150,7 +150,7 @@ declare class AiChatbotInstructionReference {
|
|
|
150
150
|
* Updates an existing instruction entry on the chatbot profile. This will result in an error if an entry has not
|
|
151
151
|
* yet been created for the current instruction id.
|
|
152
152
|
*
|
|
153
|
-
* @param data An object containing options for
|
|
153
|
+
* @param data An object containing options for updating the entry.
|
|
154
154
|
* @param data.instruction - The instruction data.
|
|
155
155
|
* @returns A promise that resolves when the instruction is successfully updated.
|
|
156
156
|
*/
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { RpcManager } from './rpc.manager';
|
|
3
3
|
import { ClientIdService } from './client-id.service';
|
|
4
|
-
import { ApiEndpointId, IntegrationId } from './public-types';
|
|
4
|
+
import { ApiEndpointId, ApiOptions, IntegrationId } from './public-types';
|
|
5
5
|
export declare class ApiManager {
|
|
6
6
|
private readonly clientIdService;
|
|
7
7
|
private readonly rpcManager;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
callApiAndSubscribe<T>(integrationId: IntegrationId, endpointId: ApiEndpointId, request: Record<string, any>): Observable<T>;
|
|
8
|
+
constructor(clientIdService: ClientIdService, rpcManager: RpcManager);
|
|
9
|
+
callApiAndSubscribe<T>(integrationId: IntegrationId, endpointId: ApiEndpointId, request: Record<string, any>, options: ApiOptions): Observable<T>;
|
|
11
10
|
}
|
|
@@ -18,13 +18,5 @@ export declare class RpcManager {
|
|
|
18
18
|
deleteStaticHeader(key: string): void;
|
|
19
19
|
getStaticHeaders(): Record<string, string>;
|
|
20
20
|
post<T>(path: string, message: unknown, files?: Array<File | BlobAndFilename>, filesFieldName?: string): Promise<T>;
|
|
21
|
-
private tryDeserializing;
|
|
22
21
|
private getRateLimiterBucket;
|
|
23
22
|
}
|
|
24
|
-
export declare class RpcError extends Error {
|
|
25
|
-
readonly statusCode: number;
|
|
26
|
-
readonly statusText: string;
|
|
27
|
-
readonly headers: Headers;
|
|
28
|
-
readonly url: string;
|
|
29
|
-
constructor(statusCode: number, statusText: string, headers: Headers, url: string, message?: string);
|
|
30
|
-
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -5,7 +5,7 @@ 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, AppId, CollectionName, DocumentData, EnvironmentId, IntegrationId, SquidDeveloperId, SquidRegion } from './public-types';
|
|
8
|
+
import { ApiEndpointId, ApiKey, AppId, ApiOptions, CollectionName, DocumentData, EnvironmentId, IntegrationId, NativeApiCallResponse, SquidDeveloperId, SquidRegion } from './public-types';
|
|
9
9
|
import { QueueManager } from './queue.manager';
|
|
10
10
|
/** The different options that can be used to initialize a Squid instance. */
|
|
11
11
|
export interface SquidOptions {
|
|
@@ -48,11 +48,6 @@ export interface SquidOptions {
|
|
|
48
48
|
* The user ID of the developer that runs the environment locally.
|
|
49
49
|
*/
|
|
50
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
51
|
}
|
|
57
52
|
/** Authentication data provider for Squid requests. */
|
|
58
53
|
export interface SquidAuthProvider {
|
|
@@ -188,21 +183,12 @@ export declare class Squid {
|
|
|
188
183
|
* @type {Promise<Array<SquidDocument>>}
|
|
189
184
|
*/
|
|
190
185
|
executeNativeRelationalQuery<T = any>(integrationId: IntegrationId, query: string, params?: Record<string, any>): Promise<Array<T>>;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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>;
|
|
186
|
+
callApi<T = any>(integrationId: IntegrationId, endpointId: ApiEndpointId, request?: Record<string, any>, options?: Omit<ApiOptions, 'nativeResponse'> | (ApiOptions & {
|
|
187
|
+
nativeResponse: false;
|
|
188
|
+
})): Promise<T>;
|
|
189
|
+
callApi<T = any>(integrationId: IntegrationId, endpointId: ApiEndpointId, request?: Record<string, any>, options?: ApiOptions & {
|
|
190
|
+
nativeResponse: true;
|
|
191
|
+
}): Promise<NativeApiCallResponse<T>>;
|
|
206
192
|
/**
|
|
207
193
|
* Returns a GraphQL client for the given integration. The GraphQL client can be used to execute GraphQL queries and
|
|
208
194
|
* mutations. For more information about GraphQL in Squid, please refer to the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squidcloud/client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.176",
|
|
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",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"test:cov": "jest --coverage",
|
|
22
22
|
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
|
23
23
|
"test:e2e": "jest --config ./test/jest-e2e.json",
|
|
24
|
-
"publish:public": "npm run build && npm publish --access public"
|
|
24
|
+
"publish:public": "npm run build && npm publish --access public",
|
|
25
|
+
"full-bundle-size-report": "cross-env BUILD_FULL_BUNDLE_SIZE_REPORT=1 webpack --mode=production"
|
|
25
26
|
},
|
|
26
27
|
"keywords": [
|
|
27
28
|
"typescript",
|