Skip to content
Merged
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
11 changes: 8 additions & 3 deletions src/internal/api/authApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,9 @@ export class AuthApi {
});
}
/**
* This endpoint is used to test if authentication is working correctly.
* @summary Test endpoint for validating middleware authentication
* @param authorization Bearer token (API Key or JWT)
* This endpoint validates a user JWT token and returns the associated user information if valid
* @summary Validates user JWT and returns user data
* @param authorization Bearer token (User JWT)
*/
public async authControllerTestAuth(
authorization: string,
Expand Down Expand Up @@ -557,6 +557,11 @@ export class AuthApi {
};

let authenticationPromise = Promise.resolve();
if (this.authentications.API_Key.accessToken) {
authenticationPromise = authenticationPromise.then(() =>
this.authentications.API_Key.applyToRequest(localVarRequestOptions)
);
}
authenticationPromise = authenticationPromise.then(() =>
this.authentications.default.applyToRequest(localVarRequestOptions)
);
Expand Down
131 changes: 102 additions & 29 deletions src/lib/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
LogVisitEventRequest,
VisitEventResponse,
} from '../internal/api';

import { ApiCredentials } from './apiCredentials';
import { validateString } from './validators';

export class AnalyticsAPI {
Expand Down Expand Up @@ -217,15 +217,28 @@ export class AnalyticsAPI {
}

async getCustomEventTypesByProject(
projectName: string
projectName: string,
credentials?: ApiCredentials
): Promise<GetAllCustomEventTypeResponse> {
validateString(
projectName,
'The projectName must be provided as an input and has to be nonempty.'
);

const headers: any = {};
if (credentials?.userJwt) {
headers['X-User-JWT'] = credentials.userJwt;
}
if (
credentials?.projectId !== undefined &&
credentials.projectId !== null
) {
headers['X-Project-Id'] = String(credentials.projectId);
}
Comment thread
UZ9 marked this conversation as resolved.

const res = await this.internalApi.analyticsControllerGetCustomEventTypes(
projectName
projectName,
{ headers }
);

return res.body;
Expand Down Expand Up @@ -255,73 +268,121 @@ export class AnalyticsAPI {
return res.body;
}

async getAllClickEvents(event: {
projectName: string;
afterTime?: string;
limit?: number;
}): Promise<GetAllClickEventsResponse> {
async getAllClickEvents(
event: {
projectName: string;
afterTime?: string;
limit?: number;
},
credentials?: ApiCredentials
): Promise<GetAllClickEventsResponse> {
const { projectName, afterTime, limit } = event;

validateString(
projectName,
'The projectName must be provided as an input and has to be nonempty.'
);

const headers: any = {};
if (credentials?.userJwt) {
headers['X-User-JWT'] = credentials.userJwt;
}
if (
credentials?.projectId !== undefined &&
credentials.projectId !== null
) {
headers['X-Project-Id'] = String(credentials.projectId);
}

const res = await this.internalApi.analyticsControllerGetAllClickEvents(
projectName,
afterTime,
limit
limit,
{ headers }
);
return res.body;
}

async getAllVisitEvents(event: {
projectName: string;
afterTime?: string;
limit?: number;
}): Promise<GetAllVisitEventsResponse> {
async getAllVisitEvents(
event: {
projectName: string;
afterTime?: string;
limit?: number;
},
credentials?: ApiCredentials
): Promise<GetAllVisitEventsResponse> {
const { projectName, afterTime, limit } = event;

validateString(
projectName,
'The projectName must be provided as an input and has to be nonempty.'
);

const headers: any = {};
if (credentials?.userJwt) {
headers['X-User-JWT'] = credentials.userJwt;
}
if (
credentials?.projectId !== undefined &&
credentials.projectId !== null
) {
headers['X-Project-Id'] = String(credentials.projectId);
}

const res = await this.internalApi.analyticsControllerGetAllVisitEvents(
projectName,
afterTime,
limit
limit,
{ headers }
);
return res.body;
}

async getAllInputEvents(event: {
projectName: string;
afterTime?: string;
limit?: number;
}): Promise<GetAllInputEventsResponse> {
async getAllInputEvents(
event: {
projectName: string;
afterTime?: string;
limit?: number;
},
credentials?: ApiCredentials
): Promise<GetAllInputEventsResponse> {
const { projectName, afterTime, limit } = event;

validateString(
projectName,
'The projectName must be provided as an input and has to be nonempty.'
);

const headers: any = {};
if (credentials?.userJwt) {
headers['X-User-JWT'] = credentials.userJwt;
}
if (
credentials?.projectId !== undefined &&
credentials.projectId !== null
) {
headers['X-Project-Id'] = String(credentials.projectId);
}

const res = await this.internalApi.analyticsControllerGetAllInputEvents(
projectName,
afterTime,
limit
limit,
{ headers }
);
return res.body;
}

async getAllCustomEvents(event: {
projectName: string;
category: string;
subcategory: string;
afterTime?: string;
limit?: number;
}): Promise<GetAllCustomEventsResponse> {
async getAllCustomEvents(
event: {
projectName: string;
category: string;
subcategory: string;
afterTime?: string;
limit?: number;
},
credentials?: ApiCredentials
): Promise<GetAllCustomEventsResponse> {
const { projectName, category, subcategory, afterTime, limit } = event;

validateString(
Expand All @@ -339,12 +400,24 @@ export class AnalyticsAPI {
'The subcategory must be provided as an input and has to be nonempty.'
);

const headers: any = {};
if (credentials?.userJwt) {
headers['X-User-JWT'] = credentials.userJwt;
}
if (
credentials?.projectId !== undefined &&
credentials.projectId !== null
) {
headers['X-Project-Id'] = String(credentials.projectId);
}

const res = await this.internalApi.analyticsControllerGetAllCustomEvents(
projectName,
category,
subcategory,
afterTime,
limit
limit,
{ headers }
);
return res.body;
}
Expand Down
32 changes: 28 additions & 4 deletions src/lib/analyticsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
CreateAnalyticsConfigModel,
UpdateAnalyticsConfigModel,
} from '../internal/api';
import { ApiCredentials } from './apiCredentials';
import { validateString } from './validators';

export class AnalyticsConfigAPI {
Expand All @@ -14,7 +15,8 @@ export class AnalyticsConfigAPI {
}

async createAnalyticsConfig(
config: CreateAnalyticsConfigModel
config: CreateAnalyticsConfigModel,
credentials?: ApiCredentials
): Promise<AnalyticsConfigResponse> {
validateString(
config.clientAnalyticsKey,
Expand All @@ -26,24 +28,46 @@ export class AnalyticsConfigAPI {
'The serverAnalyticsKey must be provided as an input and has to be nonempty.'
);

const headers: any = {};
if (credentials?.userJwt) {
headers['X-User-JWT'] = credentials.userJwt;
}
if (
credentials?.projectId !== undefined &&
credentials.projectId !== null
) {
headers['X-Project-Id'] = String(credentials.projectId);
}

const res =
await this.internalApi.analyticsConfigControllerCreateAnalyticsConfig(
config
config,
{ headers }
);
return res.body;
}

async getAnalyticsConfig(
projectId: string
projectId: string,
credentials?: ApiCredentials
): Promise<AnalyticsConfigResponse> {
validateString(
projectId,
'The projectId must be provided as an input and has to be nonempty.'
);

const headers: any = {};
if (credentials?.userJwt) {
headers['X-User-JWT'] = credentials.userJwt;
}
if (credentials?.projectId !== undefined) {
headers['X-Project-Id'] = String(credentials.projectId);
}

const res =
await this.internalApi.analyticsConfigControllerGetAnalyticsConfig(
projectId
projectId,
{ headers }
);
return res.body;
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/apiCredentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface ApiCredentials {
userJwt?: string;
projectId?: number | string;
}
Loading