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

rest-client-sdk

Package Overview
Dependencies
Maintainers
3
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rest-client-sdk - npm Package Compare versions

Comparing version 7.0.0-rc.1 to 7.0.0-rc.3

dist/types/utils/logging.d.ts

1

dist/types/client/headerUtils.d.ts

@@ -7,1 +7,2 @@ export declare function removeAuthorization(headers: undefined | HeadersInit): undefined | HeadersInit;

export declare function removeUndefinedHeaders(headers: HeadersInit): HeadersInit;
export declare function convertToRecord(headers: HeadersInit): Record<string, string>;

5

dist/types/index.d.ts

@@ -16,2 +16,3 @@ import RestClientSdk from './RestClientSdk';

import Relation from './Mapping/Relation';
import { Logger, Log, LoggerHistory } from './utils/logging';
import type { Token, ErrorBody, TokenBody, TokenResponse } from './TokenGenerator/types';

@@ -26,3 +27,3 @@ import type { SdkMetadata, MetadataDefinition } from './RestClientSdk';

export default RestClientSdk;
export { AbstractClient, AbstractTokenGenerator, AuthorizationCodeFlowTokenGenerator, ClientCredentialsGenerator, PasswordGenerator, ProvidedTokenGenerator, Serializer, TokenStorage, UnauthorizedError, BadRequestError, ConflictError, ForbiddenError, OauthError, InvalidGrantError, InvalidScopeError, HttpError, InternalServerError, ResourceNotFoundError, Mapping, ClassMetadata, Attribute, Relation, };
export type { SerializerInterface, Token, ErrorBody, TokenResponse, TokenBody, HasExpiresAt, Config, SdkMetadata, RestClientSdkInterface, TokenStorageInterface, TokenGeneratorInterface, AsyncStorageInterface, MetadataDefinition, };
export { AbstractClient, AbstractTokenGenerator, AuthorizationCodeFlowTokenGenerator, ClientCredentialsGenerator, PasswordGenerator, ProvidedTokenGenerator, Serializer, TokenStorage, UnauthorizedError, BadRequestError, ConflictError, ForbiddenError, OauthError, InvalidGrantError, InvalidScopeError, HttpError, InternalServerError, ResourceNotFoundError, Mapping, ClassMetadata, Attribute, Relation, Logger, };
export type { SerializerInterface, Token, ErrorBody, TokenResponse, TokenBody, HasExpiresAt, Config, SdkMetadata, RestClientSdkInterface, TokenStorageInterface, TokenGeneratorInterface, AsyncStorageInterface, MetadataDefinition, LoggerHistory, Log, };

@@ -9,2 +9,3 @@ import UnitOfWork from './UnitOfWork';

import type { Config } from './RestClientSdkInterface';
import { Logger } from './utils/logging';
declare type Entity = any;

@@ -23,2 +24,3 @@ export declare type MetadataDefinition = {

unitOfWork: UnitOfWork;
readonly logger?: Logger;
constructor(tokenStorage: TokenStorageInterface<Token>, config: Config, mapping: Mapping, serializer?: SerializerInterface);

@@ -25,0 +27,0 @@ /**

@@ -14,2 +14,3 @@ import AbstractClient from './client/AbstractClient';

unitOfWorkEnabled?: boolean;
loggerEnabled?: boolean;
};

@@ -16,0 +17,0 @@ export default interface RestClientSdkInterface<M extends SdkMetadata> {

import TokenGeneratorInterface, { TokenBodyReturn } from './TokenGeneratorInterface';
import { Token, TokenResponse } from './types';
import { Logger } from '../utils/logging';
interface UrlConfig {

@@ -10,3 +11,4 @@ scheme: string;

readonly tokenGeneratorConfig: C;
constructor(tokenGeneratorConfig: C);
protected logger?: Logger;
constructor(tokenGeneratorConfig: C, logger?: Logger);
abstract generateToken(parameters: unknown): Promise<TokenBodyReturn<T> | TokenResponse<T>>;

@@ -13,0 +15,0 @@ abstract refreshToken(accessToken: null | T): Promise<TokenBodyReturn<T> | TokenResponse<T>>;

@@ -6,6 +6,7 @@ import TokenGeneratorInterface from './TokenGenerator/TokenGeneratorInterface';

import type { HasExpiresAt } from './TokenStorageInterface';
import { Logger } from './utils/logging';
declare class TokenStorage<T extends Token> implements TokenStorageInterface<T> {
#private;
accessTokenKey: string;
constructor(tokenGenerator: TokenGeneratorInterface<T>, asyncStorage: AsyncStorageInterface, accessTokenKey?: string);
constructor(tokenGenerator: TokenGeneratorInterface<T>, asyncStorage: AsyncStorageInterface, accessTokenKey?: string, logger?: Logger);
setAsyncStorage(asyncStorage: AsyncStorageInterface): void;

@@ -12,0 +13,0 @@ hasAccessToken(): Promise<boolean>;

{
"name": "rest-client-sdk",
"version": "7.0.0-rc.1",
"version": "7.0.0-rc.3",
"description": "Rest Client SDK for API",

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

@@ -494,4 +494,13 @@ import URI from 'urijs';

let logId: undefined|string;
if (this.sdk.logger) {
logId = this.sdk.logger.logRequest({ url: input, ...params });
}
// eslint-disable-next-line consistent-return
return fetch(input, params).then((response) => {
if (this.sdk.logger) {
this.sdk.logger.logResponse(response, logId);
}
if (response.status < 400) {

@@ -498,0 +507,0 @@ return response;

@@ -42,1 +42,13 @@ /* eslint-disable consistent-return */

}
export function convertToRecord(headers: HeadersInit): Record<string, string> {
if (headers instanceof Headers) {
return Object.fromEntries(headers.entries());
}
if (Array.isArray(headers)) {
return Object.fromEntries(headers);
}
return headers;
}

@@ -27,2 +27,4 @@ import RestClientSdk from './RestClientSdk';

import Relation from './Mapping/Relation';
import { Logger, Log, LoggerHistory } from './utils/logging';
import type {

@@ -71,2 +73,3 @@ Token,

Relation,
Logger,
};

@@ -87,2 +90,4 @@ export type {

MetadataDefinition,
LoggerHistory,
Log,
};

@@ -13,2 +13,3 @@ import JsSerializer from './serializer/JsSerializer';

import { generateRepository } from './utils/repositoryGenerator';
import { Logger } from './utils/logging';

@@ -42,2 +43,4 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any

public readonly logger?: Logger;
constructor(

@@ -65,2 +68,6 @@ tokenStorage: TokenStorageInterface<Token>,

if (config.loggerEnabled) {
this.logger = new Logger();
}
this.#repositoryList = {};

@@ -67,0 +74,0 @@ }

@@ -15,2 +15,3 @@ import AbstractClient from './client/AbstractClient';

unitOfWorkEnabled?: boolean;
loggerEnabled?: boolean;
};

@@ -17,0 +18,0 @@

@@ -13,2 +13,3 @@ /* eslint no-unused-vars: 0 */

import { ErrorBody, Token, TokenResponse } from './types';
import { Logger } from '../utils/logging';

@@ -24,3 +25,8 @@ interface UrlConfig {

constructor(tokenGeneratorConfig: C) {
protected logger?: Logger;
constructor(tokenGeneratorConfig: C, logger?: Logger) {
if (logger) {
this.logger = logger;
}
this.tokenGeneratorConfig = tokenGeneratorConfig;

@@ -27,0 +33,0 @@ if (typeof this.checkTokenGeneratorConfig === 'function') {

@@ -49,3 +49,3 @@ /* eslint-disable camelcase */

return fetch(url, {
const params = {
method: 'POST',

@@ -62,3 +62,9 @@ headers: {

}),
});
};
if (this.logger) {
this.logger.logRequest({ url, ...params });
}
return fetch(url, params);
}

@@ -85,3 +91,3 @@

return fetch(url, {
const params = {
method: 'POST',

@@ -97,3 +103,9 @@ headers: {

}),
});
};
if (this.logger) {
this.logger.logRequest({ url, ...params });
}
return fetch(url, params);
}

@@ -100,0 +112,0 @@

@@ -58,5 +58,3 @@ /* eslint-disable camelcase */

const url = this.generateUrlFromConfig(this.tokenGeneratorConfig);
return fetch(url, {
const params = {
method: 'POST',

@@ -67,3 +65,11 @@ headers: {

body,
});
};
const url = this.generateUrlFromConfig(this.tokenGeneratorConfig);
if (this.logger) {
this.logger.logRequest({ url, ...params });
}
return fetch(url, params);
}

@@ -70,0 +76,0 @@

@@ -62,3 +62,3 @@ /* eslint-disable camelcase */

return fetch(url, {
const params = {
method: 'POST',

@@ -69,3 +69,9 @@ headers: {

body,
});
};
if (this.logger) {
this.logger.logRequest({ url, ...params });
}
return fetch(url, params);
}

@@ -96,3 +102,3 @@

return fetch(url, {
const params = {
method: 'POST',

@@ -103,3 +109,9 @@ headers: {

body,
});
};
if (this.logger) {
this.logger.logRequest({ url, ...params });
}
return fetch(url, params);
}

@@ -106,0 +118,0 @@

@@ -24,2 +24,3 @@ /* eslint-disable camelcase */

} from './ErrorFactory';
import { Logger } from './utils/logging';

@@ -56,7 +57,13 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any

#logger?: Logger;
constructor(
tokenGenerator: TokenGeneratorInterface<T>,
asyncStorage: AsyncStorageInterface,
accessTokenKey = 'rest_client_sdk.api.access_token'
accessTokenKey = 'rest_client_sdk.api.access_token',
logger?: Logger
) {
if (logger) {
this.#logger = logger;
}
this.#tokenGenerator = tokenGenerator;

@@ -67,2 +74,4 @@ this.#hasATokenBeenGenerated = false;

this.handleTokenResponse = this.handleTokenResponse.bind(this);
this.generateToken = memoizePromise(this.generateToken);

@@ -185,2 +194,7 @@ this.refreshToken = memoizePromise(this.refreshToken);

const originalResponse = response.clone();
if (this.#logger) {
this.#logger.logResponse(response);
}
return response

@@ -187,0 +201,0 @@ .json()

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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