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

@postman/postman-sdk

Package Overview
Dependencies
Maintainers
349
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@postman/postman-sdk - npm Package Compare versions

Comparing version 0.0.38 to 0.0.41

build/postman/postman-otel/BatchSpanProcessor.d.ts

3

build/index.js

@@ -10,5 +10,4 @@ "use strict";

function initialize(config) {
const postmanObj = new base_sdk_1.PostmanBaseSDK(config);
return postmanObj;
return new base_sdk_1.PostmanBaseSDK(config);
}
exports.initialize = initialize;

@@ -11,5 +11,6 @@ import { BaseConfig } from './interfaces/base-config';

constructor(config: BaseConfig);
enableHealthcheck(): void;
enableHealthCheck(intervalInMilliseconds?: number): void;
disable(): void;
disableHealtcheck(): void;
retryHealthCheck(): void;
disableHealthCheck(): void;
bootstrapSDK(): Promise<void>;

@@ -16,0 +17,0 @@ pingcheckHealth(): Promise<void>;

@@ -36,18 +36,30 @@ "use strict";

}
enableHealthcheck() {
context_1.PostmanContext.setHealthcheckSetTimeoutID(setTimeout(this.pingcheckHealth.bind(this), this.postmanTracer.config.healthPingInterval));
enableHealthCheck(intervalInMilliseconds = base_types_1.DEFAULT_HEALTH_PING_INTERVAL) {
context_1.PostmanContext.setHealthCheckSetTimeoutID(setTimeout(this.pingcheckHealth.bind(this), intervalInMilliseconds));
}
disable() {
api_1.diag.debug('Disabling Postman SDK');
this.postmanTracer.suppress();
this.disableHealtcheck();
this.disableHealthCheck();
}
disableHealtcheck() {
const healthCheckSetTimeoutId = context_1.PostmanContext.getHealthcheckSetTimeoutID();
retryHealthCheck() {
this.postmanTracer.suppress();
const retryCount = context_1.PostmanContext.getHealthCheckRetryCount();
if (retryCount > base_types_1.DEFAULT_HEALTH_CHECK_RETRIES) {
api_1.diag.debug('Postman SDK healthcheck retries exhausted');
this.disable();
return;
}
context_1.PostmanContext.setHealthCheckRetryCount(retryCount + 1);
api_1.diag.debug(`Retrying Postman SDK healthcheck count: ${retryCount}`);
this.enableHealthCheck(Math.pow(base_types_1.EXPONENTIAL_BACKOFF_BASE, retryCount) *
base_types_1.DEFAULT_HEALTH_PING_INTERVAL);
}
disableHealthCheck() {
const healthCheckSetTimeoutId = context_1.PostmanContext.getHealthCheckSetTimeoutID();
if (!healthCheckSetTimeoutId)
return;
api_1.diag.debug('Disabling Healtcheck of Postman SDK');
api_1.diag.debug('Disabling Postman SDK healthcheck');
// @ts-expect-error Ignore param type checking
clearTimeout(healthCheckSetTimeoutId);
context_1.PostmanContext.unsetHealthcheckSetTimeoutID();
context_1.PostmanContext.unsetHealthCheckSetTimeoutID();
}

@@ -61,3 +73,4 @@ bootstrapSDK() {

// @ts-expect-error Ignore property currentConfig doesn't exist
if (!response.respBody.currentConfig.enabled) {
this.config.enable = response.respBody.currentConfig.enabled;
if (!this.config.enable) {
this.postmanTracer.suppress();

@@ -68,3 +81,3 @@ }

}
this.enableHealthcheck();
this.pingcheckHealth();
break;

@@ -83,3 +96,2 @@ default:

return __awaiter(this, void 0, void 0, function* () {
api_1.diag.debug('Running healthcheck ping');
try {

@@ -89,9 +101,22 @@ const response = yield (0, healthcheck_1.checkHealth)(this.postmanTracer.config);

case error_1.HttpCode.OK:
this.enableHealthCheck();
// @ts-expect-error Ignore property respBody doesn't exist
if (response.respBody.healthy) {
context_1.PostmanContext.setHealthCheckRetryCount(0);
this.postmanTracer.unsupress();
}
break;
case error_1.HttpCode.SDK_CONIG_OUTDATED:
this.disableHealtcheck();
this.disableHealthCheck();
this.bootstrapSDK();
return;
break;
case error_1.HttpCode.NOT_FOUND:
// @ts-expect-error Ignore property respBody doesn't exist
if ('healthy' in response.respBody && !response.respBody.healthy) {
this.disableHealthCheck();
this.bootstrapSDK();
}
break;
default:
this.disable();
this.retryHealthCheck();
break;

@@ -101,3 +126,3 @@ }

catch (error) {
this.disable();
this.retryHealthCheck();
}

@@ -116,3 +141,3 @@ });

}
const keysOfProps = ["collectionId", "apiKey", "receiverBaseUrl", "samplingRatio", "healthPingInterval", "enable", "debug", "dataTruncation", "environment", "configFilePath", "dataRedactions", "ignoreIncomingRequests", "ignoreOutgoingRequests"];
const keysOfProps = ["collectionId", "apiKey", "receiverBaseUrl", "bufferIntervalInMilliseconds", "enable", "debug", "dataTruncation", "configFilePath", "dataRedactions", "ignoreIncomingRequests", "ignoreOutgoingRequests"];
for (let key of keysOfProps) {

@@ -148,5 +173,2 @@ if (!(key in config)) {

}
if (!config.healthPingInterval) {
config.healthPingInterval = base_types_1.DEFAULT_HEALTH_PING_INTERVAL;
}
return config;

@@ -153,0 +175,0 @@ }

@@ -15,6 +15,2 @@ "use strict";

}
// eslint-disable-next-line no-unused-vars
function postmanIgnoreIncomingRequestHook(request) {
return (0, core_1.isTracingSuppressed)(context_1.PostmanContext.getInstance());
}
const getHttpInstrumentationConfig = (userIgnoreIncomingRequestHook, userIgnoreOutgoingRequestHook) => {

@@ -25,3 +21,3 @@ return {

userIgnoreIncomingRequestHook(request)) ||
postmanIgnoreIncomingRequestHook(request));
(0, core_1.isTracingSuppressed)(context_1.PostmanContext.getInstance()));
},

@@ -28,0 +24,0 @@ ignoreOutgoingRequestHook: (request) => {

@@ -7,7 +7,5 @@ import { IgnoreIncomingRequestFunction, IgnoreOutgoingRequestFunction } from '@opentelemetry/instrumentation-http';

* apiKey: any api key needed for collector
* samplingRatio: sampling ration ( TO-DO)
* healthPingInterval: Interval to ping healthcheck of SDK
* bufferIntervalInMilliseconds: Time interval for data queueing. Export is triggered after every interval.
* enable: enable or disable tracing.
* debug: enable debug logger
* environment: instrumentation environment development/prod etc. ( implementation TO-DO)
* configFilePath: path to config YAML file.

@@ -19,8 +17,6 @@ */

receiverBaseUrl?: string;
samplingRatio?: number | string;
healthPingInterval?: number;
bufferIntervalInMilliseconds?: number;
enable?: boolean;
debug?: boolean;
dataTruncation?: boolean;
environment?: string;
configFilePath?: string;

@@ -31,2 +27,1 @@ dataRedactions?: DataRedactionRules;

}
export type RuleMap = Map<string, boolean>;

@@ -1,1 +0,1 @@

export declare const POSTMAN_COLLECTION_ID = "postman.collection.id";
export declare const POSTMAN_COLLECTION_ID = "postman.collection.id", POSTMAN_SDK_VERSION = "postman.sdk.version";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.POSTMAN_COLLECTION_ID = void 0;
exports.POSTMAN_COLLECTION_ID = 'postman.collection.id';
exports.POSTMAN_SDK_VERSION = exports.POSTMAN_COLLECTION_ID = void 0;
exports.POSTMAN_COLLECTION_ID = 'postman.collection.id', exports.POSTMAN_SDK_VERSION = 'postman.sdk.version';

@@ -5,8 +5,10 @@ import { Context } from '@opentelemetry/api';

static healthCheckSetTimeoutIDkey: symbol;
static healthCheckRetryCountKey: symbol;
static getInstance(): Context;
static log(): void;
static setHealthcheckSetTimeoutID(timeoutId: any): void;
static unsetHealthcheckSetTimeoutID(): void;
static getHealthcheckSetTimeoutID(): unknown;
static setHealthCheckSetTimeoutID(timeoutId: any): void;
static unsetHealthCheckSetTimeoutID(): void;
static getHealthCheckSetTimeoutID(): unknown;
static setNewContext(newContext: Context): void;
static getHealthCheckRetryCount(): number;
static setHealthCheckRetryCount(retryCount: number): void;
}

@@ -10,33 +10,27 @@ "use strict";

this._instance = api_1.ROOT_CONTEXT.setValue(key, 'postman');
this.log();
this._instance = api_1.ROOT_CONTEXT.setValue(this.healthCheckRetryCountKey, 0);
}
return this._instance;
}
static log() {
api_1.diag.debug('Postman context values');
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Ignore accessing _currentContext
this.getInstance()._currentContext.forEach((k, v) => {
api_1.diag.debug(k, v);
});
api_1.diag.debug('---------------');
}
static setHealthcheckSetTimeoutID(timeoutId) {
static setHealthCheckSetTimeoutID(timeoutId) {
this.setNewContext(this.getInstance().setValue(this.healthCheckSetTimeoutIDkey, timeoutId));
}
static unsetHealthcheckSetTimeoutID() {
static unsetHealthCheckSetTimeoutID() {
this.setNewContext(this.getInstance().deleteValue(this.healthCheckSetTimeoutIDkey));
}
static getHealthcheckSetTimeoutID() {
static getHealthCheckSetTimeoutID() {
return this.getInstance().getValue(this.healthCheckSetTimeoutIDkey);
}
static setNewContext(newContext) {
api_1.diag.debug('Context before replacement');
this.log();
this._instance = newContext;
api_1.diag.debug('Context after replacement');
this.log();
}
static getHealthCheckRetryCount() {
return this.getInstance().getValue(this.healthCheckRetryCountKey);
}
static setHealthCheckRetryCount(retryCount) {
this.setNewContext(this.getInstance().setValue(this.healthCheckRetryCountKey, retryCount));
}
}
exports.PostmanContext = PostmanContext;
PostmanContext.healthCheckSetTimeoutIDkey = (0, api_1.createContextKey)('HealtCheck Timeout ID');
PostmanContext.healthCheckSetTimeoutIDkey = (0, api_1.createContextKey)('HealthCheck Timeout ID');
PostmanContext.healthCheckRetryCountKey = (0, api_1.createContextKey)('HealthCheck Retry Count');

@@ -12,4 +12,2 @@ "use strict";

const semantic_attributes_1 = require("../interfaces/semantic-attributes");
const SpanProcessor_1 = require("./SpanProcessor");
const context_1 = require("./context");
const express_1 = require("../instrumentation-configs/express");

@@ -20,2 +18,5 @@ const instrumentation_express_1 = require("../instrumentation/instrumentation-express");

const config_1 = require("../receiver-service/config");
const BatchSpanProcessor_1 = require("./BatchSpanProcessor");
const version_1 = require("../../version");
const context_1 = require("./context");
class PostmanTracer {

@@ -31,3 +32,4 @@ constructor(config) {

resource: new resources_1.Resource({
[semantic_attributes_1.POSTMAN_COLLECTION_ID]: this.config.collectionId
[semantic_attributes_1.POSTMAN_COLLECTION_ID]: this.config.collectionId,
[semantic_attributes_1.POSTMAN_SDK_VERSION]: version_1.VERSION
})

@@ -38,5 +40,13 @@ });

}
let simpleSpanProcessor = new SpanProcessor_1.PostmanSpanProcessor(this.getExporter());
simpleSpanProcessor.loadDataRedactor(this.dataRedactionEngine);
provider.addSpanProcessor(simpleSpanProcessor);
let bufferConfig;
if (this.config.bufferIntervalInMilliseconds !== undefined &&
typeof this.config.bufferIntervalInMilliseconds === 'number' &&
this.config.bufferIntervalInMilliseconds > 0) {
bufferConfig = {
scheduledDelayMillis: this.config.bufferIntervalInMilliseconds
};
}
let spanProcessor = new BatchSpanProcessor_1.PostmanBatchSpanProcessor(this.getExporter(), bufferConfig);
spanProcessor.loadDataRedactor(this.dataRedactionEngine);
provider.addSpanProcessor(spanProcessor);
(0, instrumentation_1.registerInstrumentations)({

@@ -76,3 +86,3 @@ instrumentations: this._getInstrumentations()

suppress() {
api_1.diag.debug('Supress Postman Instrumentation');
api_1.diag.debug('Disable PostmanTracer');
api_1.context.with((0, core_1.suppressTracing)(context_1.PostmanContext.getInstance()), () => {

@@ -83,3 +93,3 @@ context_1.PostmanContext.setNewContext(api_1.context.active());

unsupress() {
api_1.diag.debug('Unsupress Postman Instrumentation');
api_1.diag.debug('Enable PostmanTracer');
api_1.context.with((0, core_1.unsuppressTracing)(context_1.PostmanContext.getInstance()), () => {

@@ -86,0 +96,0 @@ context_1.PostmanContext.setNewContext(api_1.context.active());

@@ -17,3 +17,8 @@ export declare const enum ConfigSource {

export declare const DEFAULT_HEALTH_PING_INTERVAL = 60000;
export declare const DEFAULT_FETCH_RETRY_DELAY = 1000;
export declare const BOOTSTRAP_RETRY_COUNT = 2;
export declare const HEALTHCHECK_RETRY_COUNT = 0;
export declare const DEFAULT_HEALTH_CHECK_RETRIES = 5;
export declare const EXPONENTIAL_BACKOFF_BASE = 2;
export declare const POSTMAN_SDK_USER_AGENT: string;
export declare const NEW_RELIC_AGENT_USER_AGENT = "NewRelic";

@@ -5,3 +5,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.NEW_RELIC_AGENT_USER_AGENT = exports.POSTMAN_SDK_USER_AGENT = exports.DEFAULT_HEALTH_PING_INTERVAL = exports.DEFAULT_DATA_TRUNCATION_LEVEL = exports.POSTMAN_DATA_REDACTION_SPAN_ATTRIBUTE = exports.BASE_REDACTION_REPLACEMENT_STRING = exports.RequestMethod = void 0;
exports.NEW_RELIC_AGENT_USER_AGENT = exports.POSTMAN_SDK_USER_AGENT = exports.EXPONENTIAL_BACKOFF_BASE = exports.DEFAULT_HEALTH_CHECK_RETRIES = exports.HEALTHCHECK_RETRY_COUNT = exports.BOOTSTRAP_RETRY_COUNT = exports.DEFAULT_FETCH_RETRY_DELAY = exports.DEFAULT_HEALTH_PING_INTERVAL = exports.DEFAULT_DATA_TRUNCATION_LEVEL = exports.POSTMAN_DATA_REDACTION_SPAN_ATTRIBUTE = exports.BASE_REDACTION_REPLACEMENT_STRING = exports.RequestMethod = void 0;
const version_1 = require("../../version");

@@ -21,3 +21,8 @@ var RequestMethod;

exports.DEFAULT_HEALTH_PING_INTERVAL = 60000; // miliseconds
exports.DEFAULT_FETCH_RETRY_DELAY = 1000;
exports.BOOTSTRAP_RETRY_COUNT = 2;
exports.HEALTHCHECK_RETRY_COUNT = 0;
exports.DEFAULT_HEALTH_CHECK_RETRIES = 5;
exports.EXPONENTIAL_BACKOFF_BASE = 2;
exports.POSTMAN_SDK_USER_AGENT = `Postman-SDK/${version_1.VERSION}`;
exports.NEW_RELIC_AGENT_USER_AGENT = 'NewRelic';

@@ -14,7 +14,9 @@ "use strict";

const api_1 = require("@opentelemetry/api");
const base_types_1 = require("../postman-types/base-types");
const rest_client_1 = require("../utils/rest-client");
const config_1 = require("./config");
const error_1 = require("./error");
function bootstrap(sdkConfig) {
return __awaiter(this, void 0, void 0, function* () {
api_1.diag.debug('Boot strapping SDK with backend');
api_1.diag.debug('Postman SDK Bootstraping');
const response = yield (0, rest_client_1.syncRequest)(sdkConfig.receiverBaseUrl + config_1.BOOTSTRAP_PATH, {

@@ -33,2 +35,17 @@ method: 'POST',

})
}, {
retries: base_types_1.BOOTSTRAP_RETRY_COUNT,
retryOn: [
error_1.HttpCode.RATE_LIMIT_EXCEEDED,
error_1.HttpCode.INTERNAL_SERVER_ERROR,
error_1.HttpCode.BAD_GATEWAY
],
retryDelay: function (attempt, error, response) {
if (error !== null ||
response.status === error_1.HttpCode.RATE_LIMIT_EXCEEDED) {
return (Math.pow(base_types_1.EXPONENTIAL_BACKOFF_BASE, attempt) *
base_types_1.DEFAULT_FETCH_RETRY_DELAY);
}
return base_types_1.DEFAULT_FETCH_RETRY_DELAY;
}
});

@@ -35,0 +52,0 @@ return response;

@@ -7,17 +7,5 @@ export declare enum HttpCode {

INTERNAL_SERVER_ERROR = 500,
BAD_GATEWAY = 502,
RATE_LIMIT_EXCEEDED = 429,
SDK_CONIG_OUTDATED = 409
}
interface ExternalServiceErrorArgs {
name?: string;
httpCode: HttpCode;
description: string;
isOperational?: boolean;
}
export declare class externalServiceError extends Error {
readonly name: string;
readonly httpCode: HttpCode;
readonly isOperational: boolean;
constructor(args: ExternalServiceErrorArgs);
}
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.externalServiceError = exports.HttpCode = void 0;
exports.HttpCode = void 0;
/* eslint-disable no-unused-vars */

@@ -12,18 +12,5 @@ var HttpCode;

HttpCode[HttpCode["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
HttpCode[HttpCode["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
HttpCode[HttpCode["RATE_LIMIT_EXCEEDED"] = 429] = "RATE_LIMIT_EXCEEDED";
HttpCode[HttpCode["SDK_CONIG_OUTDATED"] = 409] = "SDK_CONIG_OUTDATED";
})(HttpCode = exports.HttpCode || (exports.HttpCode = {}));
class externalServiceError extends Error {
constructor(args) {
super(args.description);
this.isOperational = true;
Object.setPrototypeOf(this, new.target.prototype);
this.name = args.name || 'Error';
this.httpCode = args.httpCode;
if (args.isOperational !== undefined) {
this.isOperational = args.isOperational;
}
Error.captureStackTrace(this);
}
}
exports.externalServiceError = externalServiceError;

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

const api_1 = require("@opentelemetry/api");
const base_types_1 = require("../postman-types/base-types");
const rest_client_1 = require("../utils/rest-client");

@@ -19,3 +20,3 @@ const config_1 = require("./config");

return __awaiter(this, void 0, void 0, function* () {
api_1.diag.debug('Checking SDK health with backend');
api_1.diag.debug('Postman SDK healthcheck');
const response = yield (0, rest_client_1.syncRequest)(sdkConfig.receiverBaseUrl + config_1.HEALTHCHECK_PATH, {

@@ -34,3 +35,3 @@ method: 'POST',

})
});
}, { retries: base_types_1.HEALTHCHECK_RETRY_COUNT });
return response;

@@ -37,0 +38,0 @@ });

@@ -1,1 +0,1 @@

export declare function syncRequest(url: string, requestOptions: object): Promise<import("node-fetch").Response>;
export declare function syncRequest(url: string, requestOptions: object, retryOptions: object): Promise<import("node-fetch").Response>;

@@ -15,4 +15,5 @@ "use strict";

const node_fetch_1 = require("node-fetch");
const fetch_retry_ts_1 = require("fetch-retry-ts");
const base_types_1 = require("../postman-types/base-types");
function syncRequest(url, requestOptions) {
function syncRequest(url, requestOptions, retryOptions) {
return __awaiter(this, void 0, void 0, function* () {

@@ -22,3 +23,4 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment

requestOptions.headers['User-Agent'] = base_types_1.POSTMAN_SDK_USER_AGENT;
const response = yield (0, node_fetch_1.default)(url, requestOptions);
const retryFetch = (0, fetch_retry_ts_1.default)(node_fetch_1.default, retryOptions);
const response = yield retryFetch(url, requestOptions);
let respBody = {};

@@ -29,3 +31,3 @@ try {

catch (error) {
respBody = { message: 'Something went wrong' };
respBody = { message: 'JSON parsing error' };
throw Error();

@@ -32,0 +34,0 @@ }

@@ -1,1 +0,1 @@

export declare const VERSION = "0.0.39";
export declare const VERSION = "0.0.41";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VERSION = void 0;
exports.VERSION = '0.0.39';
exports.VERSION = '0.0.41';
{
"name": "@postman/postman-sdk",
"version": "0.0.38",
"version": "0.0.41",
"description": "",

@@ -42,2 +42,3 @@ "main": "build/index.js",

"@opentelemetry/semantic-conventions": "^1.9.0",
"fetch-retry-ts": "^1.1.25",
"js-yaml": "^4.1.0",

@@ -44,0 +45,0 @@ "node-fetch": "^2.6.9",

@@ -28,10 +28,11 @@ ### About

- type: string
- **receiverBaseUrl**: where the data should be shipped to collector's http endpoint.
- **receiverBaseUrl**: Where the data should be shipped to collector's http endpoint.
- type: string(valid url)
- default: 'https://api.getpostman-beta.com' , **if using default please connect to postman VPN**
- **samplingRatio**: sampling ration ( TO-DO)
- **bufferIntervalInMilliseconds**: Time interval for data queueing. Export is triggered after every interval.
- type: number
- default: 5000
- **enable**: enable or disable tracing.
- type: boolean
- **debug**: enable debug logger
- **debug**: Enable debug logger
- type: boolean

@@ -41,5 +42,5 @@ - **dataTruncation**: Changes data in request/response body from {key: value} to {key: { type: typeof(value) } }

- default: false
- **environment**: instrumentation environment development/prod etc. ( implementation TO-DO)
- **environment**: Instrumentation environment development/prod etc. ( implementation TO-DO)
- type: string
- **configFilePath**: path to config YAML file.
- **configFilePath**: Path to config YAML file.
- type: string

@@ -46,0 +47,0 @@ - **dataRedactions**: Regex rules to redact data from requests.

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