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

@acrolinx/sdk

Package Overview
Dependencies
Maintainers
2
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@acrolinx/sdk - npm Package Compare versions

Comparing version 1.2.0-dev.12 to 1.2.0-dev.13

21

dist/src/errors.js

@@ -34,3 +34,2 @@ "use strict";

exports.CheckCanceledByClientError = exports.wrapFetchError = exports.createErrorFromFetchResponse = exports.AcrolinxError = exports.ErrorType = void 0;
var ai_service_types_1 = require("./services/ai-service/ai-service.types");
var ai_service_utils_1 = require("./services/ai-service/ai-service.utils");

@@ -91,4 +90,13 @@ /**

function createErrorFromFetchResponse(req, res, jsonBody) {
if (jsonBody && jsonBody.type) {
if ((0, ai_service_utils_1.isAIServiceError)(jsonBody)) {
return new AcrolinxError({
detail: jsonBody.message,
status: jsonBody.code,
type: jsonBody.errorId,
title: jsonBody.message,
httpRequest: req,
});
}
else if (jsonBody && jsonBody.type) {
return new AcrolinxError({
detail: jsonBody.detail || 'Unknown HTTP Error',

@@ -105,11 +113,2 @@ status: jsonBody.status || res.status,

}
else if ((0, ai_service_utils_1.isAIServiceError)(jsonBody)) {
return new AcrolinxError({
detail: jsonBody.message,
status: jsonBody.code,
type: ai_service_types_1.AIServiceErrorTypes.AI_SERVICE_ERROR,
title: jsonBody.message,
httpRequest: req,
});
}
else {

@@ -116,0 +115,0 @@ return new AcrolinxError({

@@ -22,5 +22,11 @@ import { CommonIssue } from '../../check';

message: string;
errorId: AIServiceErrorTypes;
}
export declare enum AIServiceErrorTypes {
AI_SERVICE_ERROR = "AI_SERVICE_ERROR"
GENERAL_EXCEPTION = "GENERAL_EXCEPTION",
AI_PROVIDER_ERROR = "AI_PROVIDER_ERROR",
INVALID_USER_INPUT = "INVALID_USER_INPUT",
BUDGET_EXCEEDED = "BUDGET_EXCEEDED",
BUDGET_EXPIRED = "BUDGET_EXPIRED",
BUDGET_CONFIGURATION_ERROR = "BUDGET_CONFIGURATION_ERROR"
}

@@ -21,4 +21,9 @@ "use strict";

(function (AIServiceErrorTypes) {
AIServiceErrorTypes["AI_SERVICE_ERROR"] = "AI_SERVICE_ERROR";
AIServiceErrorTypes["GENERAL_EXCEPTION"] = "GENERAL_EXCEPTION";
AIServiceErrorTypes["AI_PROVIDER_ERROR"] = "AI_PROVIDER_ERROR";
AIServiceErrorTypes["INVALID_USER_INPUT"] = "INVALID_USER_INPUT";
AIServiceErrorTypes["BUDGET_EXCEEDED"] = "BUDGET_EXCEEDED";
AIServiceErrorTypes["BUDGET_EXPIRED"] = "BUDGET_EXPIRED";
AIServiceErrorTypes["BUDGET_CONFIGURATION_ERROR"] = "BUDGET_CONFIGURATION_ERROR";
})(AIServiceErrorTypes || (exports.AIServiceErrorTypes = AIServiceErrorTypes = {}));
//# sourceMappingURL=ai-service.types.js.map

@@ -19,6 +19,10 @@ "use strict";

exports.isAIServiceError = void 0;
var ai_service_types_1 = require("./ai-service.types");
function isAIServiceError(error) {
return error && typeof error.code === 'number' && typeof error.message === 'string';
return (error &&
typeof error.message === 'string' &&
typeof error.code === 'number' &&
error.errorId in ai_service_types_1.AIServiceErrorTypes);
}
exports.isAIServiceError = isAIServiceError;
//# sourceMappingURL=ai-service.utils.js.map

@@ -59,2 +59,3 @@ "use strict";

var dummy_data_1 = require("../test-utils/dummy-data");
var ai_service_types_1 = require("../../src/services/ai-service/ai-service.types");
var ai_service_1 = require("../../src/services/ai-service/ai-service");

@@ -126,8 +127,8 @@ describe('AI-service', function () {

case 0:
endpoint = new index_1.AcrolinxEndpoint(common_1.DUMMY_ENDPOINT_PROPS);
mockFetch.mock(aiEnabledMatcher, {
status: 403,
throws: {
body: {
code: 403,
message: 'missing privilege GENERATE',
errorId: 'INSUFFICIENT_PRIVILEGES',
},

@@ -145,2 +146,3 @@ });

describe('/getAIChatCompletions', function () {
var REQUEST_ERROR_MESSAGE = 'There was an error processing your request. It has been logged (ID some-random-id).';
var getGetAIChatCompletionMatcher = function (count, internalName) {

@@ -170,5 +172,15 @@ return "end:/ai-service/api/v1/ai/chat-completions?count=".concat(count, "&issueInternalName=").concat(internalName);

code: 500,
message: 'There was an error processing your request. It has been logged (ID some-random-id).',
message: REQUEST_ERROR_MESSAGE,
errorId: ai_service_types_1.AIServiceErrorTypes.GENERAL_EXCEPTION,
});
return [4 /*yield*/, expect(response).rejects.toThrow('There was an error processing your request. It has been logged (ID some-random-id).')];
return [4 /*yield*/, expect(response).rejects.toThrowError(new index_1.AcrolinxError({
detail: REQUEST_ERROR_MESSAGE,
status: 500,
type: ai_service_types_1.AIServiceErrorTypes.GENERAL_EXCEPTION,
title: REQUEST_ERROR_MESSAGE,
httpRequest: {
url: expect.stringContaining('/ai-service/api/v1/ai/chat-completions'),
method: 'POST',
},
}))];
case 1:

@@ -181,11 +193,22 @@ _a.sent();

it('should throw if response was filtered', function () { return __awaiter(void 0, void 0, void 0, function () {
var response;
var FILTERED_RESPONSE_MESSAGE, response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
FILTERED_RESPONSE_MESSAGE = 'The response was filtered...bla bla';
response = createDummyAIServiceRequest(400, {
code: 400,
message: 'The response was filtered...bla bla',
message: FILTERED_RESPONSE_MESSAGE,
errorId: ai_service_types_1.AIServiceErrorTypes.INVALID_USER_INPUT,
});
return [4 /*yield*/, expect(response).rejects.toThrow('The response was filtered...bla bla')];
return [4 /*yield*/, expect(response).rejects.toThrowError(new index_1.AcrolinxError({
detail: FILTERED_RESPONSE_MESSAGE,
status: 400,
type: ai_service_types_1.AIServiceErrorTypes.INVALID_USER_INPUT,
title: FILTERED_RESPONSE_MESSAGE,
httpRequest: {
url: expect.stringContaining('/ai-service/api/v1/ai/chat-completions'),
method: 'POST',
},
}))];
case 1:

@@ -192,0 +215,0 @@ _a.sent();

{
"name": "@acrolinx/sdk",
"version": "1.2.0-dev.12",
"version": "1.2.0-dev.13",
"description": "Acrolinx JavaScript SDK for the Acrolinx API",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

@@ -18,3 +18,2 @@ /*

import { DocumentId } from './document-descriptor';
import { AIServiceErrorTypes } from './services/ai-service/ai-service.types';
import { isAIServiceError } from './services/ai-service/ai-service.utils';

@@ -128,4 +127,12 @@

): AcrolinxError {
if (jsonBody && jsonBody.type) {
if (isAIServiceError(jsonBody)) {
return new AcrolinxError({
detail: jsonBody.message,
status: jsonBody.code,
type: jsonBody.errorId,
title: jsonBody.message,
httpRequest: req,
});
} else if (jsonBody && jsonBody.type) {
return new AcrolinxError({
detail: jsonBody.detail || 'Unknown HTTP Error',

@@ -141,10 +148,2 @@ status: jsonBody.status || res.status,

});
} else if (isAIServiceError(jsonBody)) {
return new AcrolinxError({
detail: jsonBody.message,
status: jsonBody.code,
type: AIServiceErrorTypes.AI_SERVICE_ERROR,
title: jsonBody.message,
httpRequest: req,
});
} else {

@@ -151,0 +150,0 @@ return new AcrolinxError({

@@ -43,6 +43,12 @@ /*

message: string;
errorId: AIServiceErrorTypes;
}
export enum AIServiceErrorTypes {
AI_SERVICE_ERROR = 'AI_SERVICE_ERROR',
GENERAL_EXCEPTION = 'GENERAL_EXCEPTION',
AI_PROVIDER_ERROR = 'AI_PROVIDER_ERROR',
INVALID_USER_INPUT = 'INVALID_USER_INPUT',
BUDGET_EXCEEDED = 'BUDGET_EXCEEDED',
BUDGET_EXPIRED = 'BUDGET_EXPIRED',
BUDGET_CONFIGURATION_ERROR = 'BUDGET_CONFIGURATION_ERROR',
}

@@ -17,6 +17,11 @@ /*

import { AIServiceError } from './ai-service.types';
import { AIServiceError, AIServiceErrorTypes } from './ai-service.types';
export function isAIServiceError(error: any): error is AIServiceError {
return error && typeof error.code === 'number' && typeof error.message === 'string';
return (
error &&
typeof error.message === 'string' &&
typeof error.code === 'number' &&
error.errorId in AIServiceErrorTypes
);
}

@@ -17,7 +17,7 @@ /*

import * as mockFetch from 'fetch-mock';
import { AcrolinxEndpoint, Issue } from '../../src/index';
import { AcrolinxEndpoint, AcrolinxError, Issue } from '../../src/index';
import { DUMMY_ACCESS_TOKEN } from '../test-utils/mock-server';
import { DUMMY_ENDPOINT_PROPS } from './common';
import { DUMMY_AI_REWRITE_CONTEXT } from '../test-utils/dummy-data';
import { WriteResponse } from '../../src/services/ai-service/ai-service.types';
import { AIServiceErrorTypes, WriteResponse } from '../../src/services/ai-service/ai-service.types';
import { AIService } from '../../src/services/ai-service/ai-service';

@@ -71,8 +71,8 @@

it('error response', async () => {
endpoint = new AcrolinxEndpoint(DUMMY_ENDPOINT_PROPS);
mockFetch.mock(aiEnabledMatcher, {
status: 403,
throws: {
body: {
code: 403,
message: 'missing privilege GENERATE',
errorId: 'INSUFFICIENT_PRIVILEGES',
},

@@ -86,2 +86,3 @@ });

describe('/getAIChatCompletions', () => {
const REQUEST_ERROR_MESSAGE = 'There was an error processing your request. It has been logged (ID some-random-id).';
const getGetAIChatCompletionMatcher = (count: number, internalName: string) =>

@@ -99,7 +100,17 @@ `end:/ai-service/api/v1/ai/chat-completions?count=${count}&issueInternalName=${internalName}`;

code: 500,
message: 'There was an error processing your request. It has been logged (ID some-random-id).',
message: REQUEST_ERROR_MESSAGE,
errorId: AIServiceErrorTypes.GENERAL_EXCEPTION,
});
await expect(response).rejects.toThrow(
'There was an error processing your request. It has been logged (ID some-random-id).',
await expect(response).rejects.toThrowError(
new AcrolinxError({
detail: REQUEST_ERROR_MESSAGE,
status: 500,
type: AIServiceErrorTypes.GENERAL_EXCEPTION,
title: REQUEST_ERROR_MESSAGE,
httpRequest: {
url: expect.stringContaining('/ai-service/api/v1/ai/chat-completions'),
method: 'POST',
},
}),
);

@@ -109,7 +120,21 @@ });

it('should throw if response was filtered', async () => {
const FILTERED_RESPONSE_MESSAGE = 'The response was filtered...bla bla';
const response = createDummyAIServiceRequest(400, {
code: 400,
message: 'The response was filtered...bla bla',
message: FILTERED_RESPONSE_MESSAGE,
errorId: AIServiceErrorTypes.INVALID_USER_INPUT,
});
await expect(response).rejects.toThrow('The response was filtered...bla bla');
await expect(response).rejects.toThrowError(
new AcrolinxError({
detail: FILTERED_RESPONSE_MESSAGE,
status: 400,
type: AIServiceErrorTypes.INVALID_USER_INPUT,
title: FILTERED_RESPONSE_MESSAGE,
httpRequest: {
url: expect.stringContaining('/ai-service/api/v1/ai/chat-completions'),
method: 'POST',
},
}),
);
});

@@ -116,0 +141,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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