Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@crowdin/crowdin-api-client

Package Overview
Dependencies
Maintainers
5
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@crowdin/crowdin-api-client - npm Package Compare versions

Comparing version 1.17.1 to 1.18.0

25

out/core/index.d.ts

@@ -47,19 +47,2 @@ import { RetryConfig, RetryService } from './internal/retry';

export declare type PaginationOptions = Partial<Pagination>;
export interface ValidationErrorResponse {
errors: ErrorHolder[];
}
export interface CommonErrorResponse {
error: Error;
}
export interface ErrorHolder {
error: ErrorKey;
}
export interface ErrorKey {
key: string;
errors: Error[];
}
export interface Error {
code: string;
message: string;
}
export interface PatchRequest {

@@ -92,2 +75,10 @@ value?: any;

}
export declare class CrowdinError extends Error {
code: number;
constructor(message: string, code: number);
}
export declare class CrowdinValidationError extends CrowdinError {
validationCodes: string[];
constructor(messsage: string, validationCodes: string[]);
}
export declare abstract class CrowdinApi {

@@ -94,0 +85,0 @@ private static readonly CROWDIN_URL_SUFFIX;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isOptionalNumber = exports.isOptionalString = exports.CrowdinApi = exports.BooleanInt = void 0;
exports.isOptionalNumber = exports.isOptionalString = exports.CrowdinApi = exports.CrowdinValidationError = exports.CrowdinError = exports.BooleanInt = void 0;
const axiosProvider_1 = require("./internal/axios/axiosProvider");

@@ -12,2 +12,39 @@ const fetchClient_1 = require("./internal/fetch/fetchClient");

})(BooleanInt = exports.BooleanInt || (exports.BooleanInt = {}));
class CrowdinError extends Error {
constructor(message, code) {
super(message);
this.code = code;
}
}
exports.CrowdinError = CrowdinError;
class CrowdinValidationError extends CrowdinError {
constructor(messsage, validationCodes) {
super(messsage, 400);
this.validationCodes = validationCodes;
}
}
exports.CrowdinValidationError = CrowdinValidationError;
function handleError(error = {}) {
var _a, _b;
if (Array.isArray(error.errors)) {
const validationCodes = [];
const validationMessages = [];
error.errors.forEach((e) => {
var _a;
if (Array.isArray((_a = e.error) === null || _a === void 0 ? void 0 : _a.errors)) {
e.error.errors.forEach((er) => {
if (er.message && er.code) {
validationCodes.push(er.code);
validationMessages.push(er.message);
}
});
}
});
const message = validationMessages.length === 0 ? 'Validation error' : validationMessages.join(', ');
throw new CrowdinValidationError(message, validationCodes);
}
const message = ((_a = error.error) === null || _a === void 0 ? void 0 : _a.message) || 'Error occured';
const code = ((_b = error.error) === null || _b === void 0 ? void 0 : _b.code) || 500;
throw new CrowdinError(message, code);
}
class CrowdinApi {

@@ -138,18 +175,18 @@ /**

get(url, config) {
return this.retryService.executeAsyncFunc(() => this.httpClient.get(url, config));
return this.retryService.executeAsyncFunc(() => this.httpClient.get(url, config).catch(e => handleError(e)));
}
delete(url, config) {
return this.retryService.executeAsyncFunc(() => this.httpClient.delete(url, config));
return this.retryService.executeAsyncFunc(() => this.httpClient.delete(url, config).catch(e => handleError(e)));
}
head(url, config) {
return this.retryService.executeAsyncFunc(() => this.httpClient.head(url, config));
return this.retryService.executeAsyncFunc(() => this.httpClient.head(url, config).catch(e => handleError(e)));
}
post(url, data, config) {
return this.retryService.executeAsyncFunc(() => this.httpClient.post(url, data, config));
return this.retryService.executeAsyncFunc(() => this.httpClient.post(url, data, config).catch(e => handleError(e)));
}
put(url, data, config) {
return this.retryService.executeAsyncFunc(() => this.httpClient.put(url, data, config));
return this.retryService.executeAsyncFunc(() => this.httpClient.put(url, data, config).catch(e => handleError(e)));
}
patch(url, data, config) {
return this.retryService.executeAsyncFunc(() => this.httpClient.patch(url, data, config));
return this.retryService.executeAsyncFunc(() => this.httpClient.patch(url, data, config).catch(e => handleError(e)));
}

@@ -156,0 +193,0 @@ }

@@ -31,22 +31,4 @@ "use strict";

}, error => {
var _a, _b, _c;
this.pendingRequests = Math.max(0, this.pendingRequests - 1);
if ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) {
if (error.response.status === 400) {
return Promise.reject(error.response.data);
}
else {
return Promise.reject(error.response.data);
}
}
else {
const errorCode = (_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.status) !== null && _c !== void 0 ? _c : '500';
const defaultError = {
error: {
code: errorCode,
message: `Request failed. ${error}`,
},
};
return Promise.reject(defaultError);
}
return Promise.reject(error.response.data);
});

@@ -53,0 +35,0 @@ }

{
"name": "@crowdin/crowdin-api-client",
"version": "1.17.1",
"version": "1.18.0",
"description": "JavaScript library for Crowdin API v2.",

@@ -5,0 +5,0 @@ "main": "out/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc