Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle custom base telemetry urls #48

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ const Supergood = () => {
ignoredDomains: supergoodConfig.ignoredDomains,
allowLocalUrls: supergoodConfig.allowLocalUrls,
allowIpAddresses: supergoodConfig.allowIpAddresses,
baseUrl
baseUrl,
baseTelemetryUrl
};

interceptor = new BatchInterceptor([
Expand Down
1 change: 1 addition & 0 deletions src/interceptor/FetchInterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class FetchInterceptor extends Interceptor {
ignoredDomains: this.options.ignoredDomains ?? [],
allowedDomains: this.options.allowedDomains ?? [],
baseUrl: this.options.baseUrl ?? '',
baseTelemetryUrl: this.options.baseTelemetryUrl ?? '',
allowLocalUrls: this.options.allowLocalUrls ?? false,
allowIpAddresses: this.options.allowIpAddresses ?? false,
isWithinContext: isWithinContext ?? (() => true),
Expand Down
1 change: 1 addition & 0 deletions src/interceptor/Interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface NodeRequestInterceptorOptions {
allowLocalUrls?: boolean;
allowIpAddresses?: boolean;
baseUrl?: string;
baseTelemetryUrl?: string;
}

export class Interceptor {
Expand Down
4 changes: 4 additions & 0 deletions src/interceptor/NodeClientRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import { getArrayBuffer } from './utils/bufferUtils';
import { isInterceptable } from './utils/isInterceptable';
import { IsomorphicResponse } from './utils/IsomorphicResponse';
import { cloneIncomingMessage } from './utils/cloneIncomingMessage';
import { logger } from '../utils'

export type NodeClientOptions = {
emitter: EventEmitter;
allowLocalUrls?: boolean;
baseUrl?: string;
baseTelemetryUrl?: string;
ignoredDomains?: string[];
allowedDomains?: string[];
allowIpAddresses?: boolean;
Expand Down Expand Up @@ -53,6 +55,7 @@ export class NodeClientRequest extends ClientRequest {
ignoredDomains: options.ignoredDomains ?? [],
allowedDomains: options.allowedDomains ?? [],
baseUrl: options.baseUrl ?? '',
baseTelemetryUrl: options.baseTelemetryUrl ?? '',
allowLocalUrls: options.allowLocalUrls ?? false,
allowIpAddresses: options.allowIpAddresses ?? false,
isWithinContext: options.isWithinContext ?? (() => true)
Expand Down Expand Up @@ -115,6 +118,7 @@ export class NodeClientRequest extends ClientRequest {
emit(event: string | symbol, ...args: any[]) {
if (event === 'response' && this.isInterceptable) {
try {
const debugLogger = logger({errorSinkUrl: '', headerOptions: {headers: {'Content-Type': '', Authorization: ''}, timeout: 0}})
const response = args[0] as IncomingMessage;
const firstClone = cloneIncomingMessage(response);
const secondClone = cloneIncomingMessage(response);
Expand Down
1 change: 1 addition & 0 deletions src/interceptor/NodeRequestInterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class NodeRequestInterceptor extends Interceptor {
allowLocalUrls: this.options.allowLocalUrls,
allowIpAddresses: this.options.allowIpAddresses,
baseUrl: this.options.baseUrl,
baseTelemetryUrl: this.options.baseTelemetryUrl,
isWithinContext,
};

Expand Down
18 changes: 18 additions & 0 deletions src/interceptor/utils/isInterceptable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('isInterceptable', () => {
const ignoredDomains: string[] = [];
const allowedDomains: string[] = [];
const baseUrl = 'https://api.supergood.ai';
const baseTelemetryUrl = "https://telemetry.supergood.ai"
const allowLocalUrls = false;
const allowIpAddresses = false;

Expand All @@ -16,6 +17,7 @@ describe('isInterceptable', () => {
ignoredDomains,
allowedDomains,
baseUrl,
baseTelemetryUrl,
allowLocalUrls,
allowIpAddresses,
isWithinContext
Expand All @@ -29,6 +31,7 @@ describe('isInterceptable', () => {
const ignoredDomains: string[] = [];
const allowedDomains: string[] = [];
const baseUrl = 'https://api.supergood.ai';
const baseTelemetryUrl = "https://telemetry.supergood.ai"
const allowLocalUrls = false;
const allowIpAddresses = false;

Expand All @@ -38,6 +41,7 @@ describe('isInterceptable', () => {
ignoredDomains,
allowedDomains,
baseUrl,
baseTelemetryUrl,
allowLocalUrls,
allowIpAddresses,
isWithinContext
Expand All @@ -51,6 +55,7 @@ describe('isInterceptable', () => {
const ignoredDomains: string[] = [];
const allowedDomains: string[] = [];
const baseUrl = 'https://api.supergood.ai';
const baseTelemetryUrl = "https://telemetry.supergood.ai"
const allowLocalUrls = true;
const allowIpAddresses = false;

Expand All @@ -59,6 +64,7 @@ describe('isInterceptable', () => {
ignoredDomains,
allowedDomains,
baseUrl,
baseTelemetryUrl,
allowLocalUrls,
allowIpAddresses,
isWithinContext
Expand All @@ -72,6 +78,7 @@ describe('isInterceptable', () => {
const ignoredDomains: string[] = [];
const allowedDomains: string[] = [];
const baseUrl = 'https://api.supergood.ai';
const baseTelemetryUrl = "https://telemetry.supergood.ai"
const allowLocalUrls = false;
const allowIpAddresses = false;

Expand All @@ -80,6 +87,7 @@ describe('isInterceptable', () => {
ignoredDomains,
allowedDomains,
baseUrl,
baseTelemetryUrl,
allowLocalUrls,
allowIpAddresses,
isWithinContext
Expand All @@ -93,6 +101,7 @@ describe('isInterceptable', () => {
const ignoredDomains: string[] = [];
const allowedDomains: string[] = [];
const baseUrl = 'https://api.supergood.ai';
const baseTelemetryUrl = "https://telemetry.supergood.ai"
const allowLocalUrls = true;
const allowIpAddresses = false;

Expand All @@ -101,6 +110,7 @@ describe('isInterceptable', () => {
ignoredDomains,
allowedDomains,
baseUrl,
baseTelemetryUrl,
allowLocalUrls,
allowIpAddresses,
isWithinContext
Expand All @@ -114,6 +124,7 @@ describe('isInterceptable', () => {
const ignoredDomains: string[] = ['somedomain.com'];
const allowedDomains: string[] = [];
const baseUrl = 'https://api.supergood.ai';
const baseTelemetryUrl = "https://telemetry.supergood.ai"
const allowLocalUrls = false;
const allowIpAddresses = false;

Expand All @@ -122,6 +133,7 @@ describe('isInterceptable', () => {
ignoredDomains,
allowedDomains,
baseUrl,
baseTelemetryUrl,
allowLocalUrls,
allowIpAddresses,
isWithinContext
Expand All @@ -135,6 +147,7 @@ describe('isInterceptable', () => {
const ignoredDomains: string[] = ['someotherdomain.com'];
const allowedDomains: string[] = ['somedomain.com'];
const baseUrl = 'https://api.supergood.ai';
const baseTelemetryUrl = "https://telemetry.supergood.ai"
const allowLocalUrls = false;
const allowIpAddresses = false;

Expand All @@ -143,6 +156,7 @@ describe('isInterceptable', () => {
ignoredDomains,
allowedDomains,
baseUrl,
baseTelemetryUrl,
allowLocalUrls,
allowIpAddresses,
isWithinContext
Expand All @@ -156,6 +170,7 @@ describe('isInterceptable', () => {
const ignoredDomains: string[] = ['somedomain.com'];
const allowedDomains: string[] = ['someotherdomain.com'];
const baseUrl = 'https://api.supergood.ai';
const baseTelemetryUrl = "https://telemetry.supergood.ai"
const allowLocalUrls = false;
const allowIpAddresses = false;

Expand All @@ -164,6 +179,7 @@ describe('isInterceptable', () => {
ignoredDomains,
allowedDomains,
baseUrl,
baseTelemetryUrl,
allowLocalUrls,
allowIpAddresses,
isWithinContext
Expand All @@ -177,6 +193,7 @@ describe('isInterceptable', () => {
const ignoredDomains: string[] = ['somedomain.com'];
const allowedDomains: string[] = ['somedomain'];
const baseUrl = 'https://api.supergood.ai';
const baseTelemetryUrl = "https://telemetry.supergood.ai"
const allowLocalUrls = false;
const allowIpAddresses = false;

Expand All @@ -185,6 +202,7 @@ describe('isInterceptable', () => {
ignoredDomains,
allowedDomains,
baseUrl,
baseTelemetryUrl,
allowLocalUrls,
allowIpAddresses,
isWithinContext
Expand Down
4 changes: 3 additions & 1 deletion src/interceptor/utils/isInterceptable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function isInterceptable({
ignoredDomains,
allowedDomains,
baseUrl,
baseTelemetryUrl,
allowLocalUrls,
allowIpAddresses,
isWithinContext: isWithinContext = () => true,
Expand All @@ -17,6 +18,7 @@ export function isInterceptable({
ignoredDomains: string[];
allowedDomains: string[];
baseUrl: string;
baseTelemetryUrl: string;
allowLocalUrls: boolean;
allowIpAddresses: boolean;
isWithinContext: () => boolean;
Expand All @@ -30,7 +32,7 @@ export function isInterceptable({
const hostname = url.hostname;
const [, tld] = hostname.split('.');

if (baseOrigin === url.origin || containsAnyPartial(['supergood.ai'], hostname)) {
if (baseOrigin === url.origin || containsAnyPartial(['supergood.ai', baseTelemetryUrl, baseUrl], hostname)) {
return false;
}

Expand Down
19 changes: 10 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface JSONObject {
[key: string]: JSONValue;
}

type BodyType = JSONObject
type BodyType = JSONObject;

interface RequestType {
id: string;
Expand Down Expand Up @@ -68,16 +68,17 @@ interface TelemetryType {

interface EndpointConfigType {
location: string;
method: string;
regex: string;
ignored: boolean;
sensitiveKeys: Array<{ keyPath: string, action: string }>;
sensitiveKeys: Array<{ keyPath: string; action: string }>;
}

interface RemoteConfigType {
[domain: string]: {
[endpointName: string]: EndpointConfigType;
};
};
}

interface MetadataType {
keys?: number;
Expand Down Expand Up @@ -141,18 +142,18 @@ type RemoteConfigPayloadType = Array<{
domain: string;
endpoints: Array<{
name: string;
method: string;
matchingRegex: {
regex: string;
location: string;
};
endpointConfiguration: {
action: string;
sensitiveKeys: Array<
{
keyPath: string;
action: string;
}>;
}
sensitiveKeys: Array<{
keyPath: string;
action: string;
}>;
};
}>;
}>;

Expand Down
Loading
Loading