@squidcloud/client 1.0.181 → 1.0.183

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 CHANGED
@@ -50371,7 +50371,6 @@ var external_axios_default = /*#__PURE__*/__webpack_require__.n(external_axios_n
50371
50371
 
50372
50372
 
50373
50373
 
50374
-
50375
50374
  class RpcError extends Error {
50376
50375
  /** @internal */
50377
50376
  constructor(statusCode, statusText, url, headers, body, message) {
@@ -50383,25 +50382,24 @@ class RpcError extends Error {
50383
50382
  this.body = body;
50384
50383
  }
50385
50384
  }
50385
+ function isFetchMode() {
50386
+ // Temporary (1 week) keep the old code to simplify rollback.
50387
+ return true;
50388
+ // Native fetch is used in json request mode or when the corresponding private Squid option is enabled.
50389
+ // This option is enabled in console-local and console-dev modes both in Web & Backend.
50390
+ // return files.length === 0 || !!getSquidPrivateOption(SQUID_PRIVATE_OPTION_USE_FETCH_IN_RPC_MANAGER);
50391
+ }
50386
50392
  /**
50387
50393
  * Runs a post request to the given URL.
50388
50394
  * @internal.
50389
50395
  */
50390
- async function rawSquidHttpPost({ url, headers, files, filesFieldName, message, extractErrorMessage, }) {
50391
- // Native fetch is used in json request mode or when the corresponding private Squid option is enabled.
50392
- // This option is enabled in console-local and console-dev modes both in Web & Backend.
50393
- const isFetch = files.length === 0 || !!getSquidPrivateOption(SQUID_PRIVATE_OPTION_USE_FETCH_IN_RPC_MANAGER);
50394
- let response;
50395
- if (isFetch) {
50396
- response = await performFetchRequest(headers, files, filesFieldName, message, url, extractErrorMessage);
50397
- }
50398
- else {
50399
- response = await performAxiosRequest(files, filesFieldName, message, url, headers, extractErrorMessage);
50400
- }
50396
+ async function rawSquidHttpPost(input) {
50397
+ const isFetch = isFetchMode();
50398
+ const response = await (isFetch ? performFetchRequest(input) : performAxiosRequest(input));
50401
50399
  response.body = tryDeserializing(response.body);
50402
50400
  return response;
50403
50401
  }
50404
- async function performFetchRequest(headers, files, filesFieldName, body, url, extractErrorMessage) {
50402
+ async function performFetchRequest({ headers, files, filesFieldName, message: body, url, extractErrorMessage, }) {
50405
50403
  const requestOptionHeaders = new Headers(headers);
50406
50404
  const requestOptions = { method: 'POST', headers: requestOptionHeaders, body: undefined };
50407
50405
  if (files.length) {
@@ -50431,7 +50429,7 @@ async function performFetchRequest(headers, files, filesFieldName, body, url, ex
50431
50429
  }
50432
50430
  let message;
50433
50431
  try {
50434
- message = typeof parsedBody === 'string' ? parsedBody : parsedBody['message'] || rawBody;
50432
+ message = typeof parsedBody === 'string' ? parsedBody : (parsedBody === null || parsedBody === void 0 ? void 0 : parsedBody['message']) || rawBody;
50435
50433
  }
50436
50434
  catch (_a) { }
50437
50435
  if (!message)
@@ -50453,7 +50451,7 @@ function extractAxiosResponseHeaders(response) {
50453
50451
  return acc;
50454
50452
  }, {});
50455
50453
  }
50456
- async function performAxiosRequest(files, filesFieldName, body, url, headers, extractErrorMessage) {
50454
+ async function performAxiosRequest({ files, filesFieldName, message: body, url, headers, extractErrorMessage, }) {
50457
50455
  let axiosResponse;
50458
50456
  try {
50459
50457
  if (files.length) {
@@ -50490,7 +50488,7 @@ async function performAxiosRequest(files, filesFieldName, body, url, headers, ex
50490
50488
  }
50491
50489
  let message;
50492
50490
  try {
50493
- message = typeof parsedBody === 'string' ? parsedBody : parsedBody['message'] || rawBody;
50491
+ message = typeof parsedBody === 'string' ? parsedBody : (parsedBody === null || parsedBody === void 0 ? void 0 : parsedBody['message']) || rawBody;
50494
50492
  }
50495
50493
  catch (_a) { }
50496
50494
  if (!message)
@@ -50529,7 +50527,7 @@ function tryDeserializing(text) {
50529
50527
 
50530
50528
 
50531
50529
  class RpcManager {
50532
- constructor(region, appId, destructManager, headers = {}, authManager, clientIdService) {
50530
+ constructor(region, appId, destructManager, headers, authManager, clientIdService) {
50533
50531
  this.region = region;
50534
50532
  this.appId = appId;
50535
50533
  this.authManager = authManager;
@@ -26,10 +26,10 @@ export interface CallApiOptions {
26
26
  */
27
27
  originOverride?: string;
28
28
  }
29
- export interface CallApiRequest {
29
+ export interface CallApiRequest<BodyType = any> {
30
30
  integrationId: IntegrationId;
31
31
  endpointId: ApiEndpointId;
32
- body?: any;
32
+ body?: BodyType;
33
33
  overrideMethod?: HttpMethod;
34
34
  options: ApiOptions;
35
35
  }
@@ -4,17 +4,17 @@ import { ApiOptions } from '../../internal-common/src/public-types/api-call.publ
4
4
  import { HttpResponse } from './squid-http-client';
5
5
  export declare class ApiClient {
6
6
  private readonly rpcManager;
7
- get<T = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, options?: ApiOptions): Promise<HttpResponse<T>>;
8
- post<T = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, body?: unknown, options?: ApiOptions): Promise<HttpResponse<T>>;
9
- delete<T = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, body?: unknown, options?: ApiOptions): Promise<HttpResponse<T>>;
10
- patch<T = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, body?: unknown, options?: ApiOptions): Promise<HttpResponse<T>>;
11
- put<T = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, body?: unknown, options?: ApiOptions): Promise<HttpResponse<T>>;
7
+ get<ResponseBodyType = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, options?: ApiOptions): Promise<HttpResponse<ResponseBodyType>>;
8
+ post<ResponseBodyType = unknown, RequestBodyType = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, body?: RequestBodyType, options?: ApiOptions): Promise<HttpResponse<ResponseBodyType>>;
9
+ delete<ResponseBodyType = unknown, RequestBodyType = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, body?: RequestBodyType, options?: ApiOptions): Promise<HttpResponse<ResponseBodyType>>;
10
+ patch<ResponseBodyType = unknown, RequestBodyType = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, body?: RequestBodyType, options?: ApiOptions): Promise<HttpResponse<ResponseBodyType>>;
11
+ put<ResponseBodyType = unknown, RequestBodyType = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, body?: RequestBodyType, options?: ApiOptions): Promise<HttpResponse<ResponseBodyType>>;
12
12
  /**
13
13
  * Performs an HTTP API request to the given integration ID and endpoint ID.
14
14
  * The provided options will be merged with the default options.
15
15
  * In case of error (status code >= 400 or other error), the promise will be rejected with an RpcError.
16
16
  */
17
- request<T = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, body?: unknown, options?: ApiOptions, method?: HttpMethod): Promise<HttpResponse<T>>;
17
+ request<ResponseBodyType = unknown, RequestBodyType = unknown>(integrationId: IntegrationId, endpointId: ApiEndpointId, body?: RequestBodyType, options?: ApiOptions, method?: HttpMethod): Promise<HttpResponse<ResponseBodyType>>;
18
18
  private convertOptionsToStrings;
19
19
  private convertToStrings;
20
20
  }
@@ -12,13 +12,13 @@ export declare class RpcManager {
12
12
  private readonly staticHeaders;
13
13
  private readonly onGoingRpcCounter;
14
14
  private readonly rateLimiters;
15
- constructor(region: SquidRegion, appId: string, destructManager: DestructManager, headers: Record<string, string> | undefined, authManager: AuthManager, clientIdService: ClientIdService);
15
+ constructor(region: SquidRegion, appId: string, destructManager: DestructManager, headers: Record<string, string>, authManager: AuthManager, clientIdService: ClientIdService);
16
16
  private getAuthHeaders;
17
17
  awaitAllSettled(): Promise<void>;
18
18
  setStaticHeader(key: string, value: string): void;
19
19
  deleteStaticHeader(key: string): void;
20
20
  getStaticHeaders(): Record<string, string>;
21
- post<T>(path: string, message: unknown, files?: Array<File | BlobAndFilename>, filesFieldName?: string): Promise<T>;
22
- rawPost<T = unknown>(path: string, message: unknown, files?: Array<File | BlobAndFilename>, filesFieldName?: string, extractErrorMessage?: boolean): Promise<HttpResponse<T>>;
21
+ post<ResponseType = unknown, RequestType = unknown>(path: string, message: RequestType, files?: Array<File | BlobAndFilename>, filesFieldName?: string): Promise<ResponseType>;
22
+ rawPost<ResponseType = unknown, RequestType = unknown>(path: string, message: RequestType, files?: Array<File | BlobAndFilename>, filesFieldName?: string, extractErrorMessage?: boolean): Promise<HttpResponse<ResponseType>>;
23
23
  private getRateLimiterBucket;
24
24
  }
@@ -1,23 +1,23 @@
1
1
  import { BlobAndFilename } from './types';
2
- export declare class RpcError extends Error {
2
+ export declare class RpcError<BodyType = unknown> extends Error {
3
3
  readonly statusCode: number;
4
4
  readonly statusText: string;
5
5
  readonly url: string;
6
6
  readonly headers: Record<string, string>;
7
- readonly body?: unknown;
7
+ readonly body: BodyType;
8
8
  }
9
- export interface HttpPostInput {
9
+ export interface HttpPostInput<RequestBodyType = unknown> {
10
10
  url: string;
11
11
  headers: Record<string, string>;
12
- message: unknown;
12
+ message: RequestBodyType;
13
13
  files: Array<File | BlobAndFilename>;
14
14
  filesFieldName: string;
15
15
  extractErrorMessage: boolean;
16
16
  }
17
17
  /** A response object with type T for the body. */
18
- export interface HttpResponse<T = unknown> {
18
+ export interface HttpResponse<BodyType = unknown> {
19
19
  status: number;
20
20
  statusText: string;
21
21
  headers: Record<string, string>;
22
- body: T;
22
+ body: BodyType;
23
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squidcloud/client",
3
- "version": "1.0.181",
3
+ "version": "1.0.183",
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",