@adtrackify/at-service-common 1.1.20 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/helpers/subscription-helper.spec.d.ts +1 -0
- package/dist/__tests__/helpers/subscription-helper.spec.js +28 -0
- package/dist/__tests__/helpers/subscription-helper.spec.js.map +1 -0
- package/dist/clients/generic/cognito-client.d.ts +19 -0
- package/dist/clients/generic/cognito-client.js +140 -0
- package/dist/clients/generic/cognito-client.js.map +1 -0
- package/dist/clients/generic/dynamodb-client.d.ts +15 -0
- package/dist/clients/generic/dynamodb-client.js +123 -0
- package/dist/clients/generic/dynamodb-client.js.map +1 -0
- package/dist/clients/generic/eventbridge-client.d.ts +14 -0
- package/dist/clients/generic/eventbridge-client.js +46 -0
- package/dist/clients/generic/eventbridge-client.js.map +1 -0
- package/dist/clients/generic/http-client.d.ts +29 -0
- package/dist/clients/generic/http-client.js +30 -0
- package/dist/clients/generic/http-client.js.map +1 -0
- package/{src/clients/generic/index.ts → dist/clients/generic/index.d.ts} +5 -5
- package/dist/clients/generic/index.js +6 -0
- package/dist/clients/generic/index.js.map +1 -0
- package/dist/clients/generic/s3-client.d.ts +6 -0
- package/dist/clients/generic/s3-client.js +25 -0
- package/dist/clients/generic/s3-client.js.map +1 -0
- package/{src/clients/index.ts → dist/clients/index.d.ts} +3 -3
- package/dist/clients/index.js +4 -0
- package/dist/clients/index.js.map +1 -0
- package/dist/clients/internal-api/accounts-client.d.ts +82 -0
- package/dist/clients/internal-api/accounts-client.js +79 -0
- package/dist/clients/internal-api/accounts-client.js.map +1 -0
- package/dist/clients/internal-api/destinations-client.d.ts +54 -0
- package/dist/clients/internal-api/destinations-client.js +37 -0
- package/dist/clients/internal-api/destinations-client.js.map +1 -0
- package/{src/clients/internal-api/index.ts → dist/clients/internal-api/index.d.ts} +4 -4
- package/dist/clients/internal-api/index.js +5 -0
- package/dist/clients/internal-api/index.js.map +1 -0
- package/dist/clients/internal-api/shopify-app-install-client.d.ts +57 -0
- package/dist/clients/internal-api/shopify-app-install-client.js +43 -0
- package/dist/clients/internal-api/shopify-app-install-client.js.map +1 -0
- package/dist/clients/internal-api/users-auth-client.d.ts +61 -0
- package/dist/clients/internal-api/users-auth-client.js +74 -0
- package/dist/clients/internal-api/users-auth-client.js.map +1 -0
- package/dist/clients/third-party/index.d.ts +1 -0
- package/dist/clients/third-party/index.js +2 -0
- package/dist/clients/third-party/index.js.map +1 -0
- package/dist/clients/third-party/shopify-client.d.ts +90 -0
- package/dist/clients/third-party/shopify-client.js +122 -0
- package/dist/clients/third-party/shopify-client.js.map +1 -0
- package/{src/helpers/index.ts → dist/helpers/index.d.ts} +5 -5
- package/dist/helpers/index.js +6 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/input-validation-helper.d.ts +2 -0
- package/dist/helpers/input-validation-helper.js +19 -0
- package/dist/helpers/input-validation-helper.js.map +1 -0
- package/dist/helpers/logging-helper.d.ts +1 -0
- package/dist/helpers/logging-helper.js +10 -0
- package/dist/helpers/logging-helper.js.map +1 -0
- package/dist/helpers/response-helper.d.ts +36 -0
- package/dist/helpers/response-helper.js +36 -0
- package/dist/helpers/response-helper.js.map +1 -0
- package/dist/helpers/shopify-helper.d.ts +9 -0
- package/dist/helpers/shopify-helper.js +24 -0
- package/dist/helpers/shopify-helper.js.map +1 -0
- package/dist/helpers/subscription-helper.d.ts +8 -0
- package/dist/helpers/subscription-helper.js +182 -0
- package/dist/helpers/subscription-helper.js.map +1 -0
- package/dist/index.d.ts +5 -737
- package/dist/index.esm.js +6 -2
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +6 -1404
- package/dist/index.js.map +1 -7
- package/dist/libs/crypto.d.ts +1 -0
- package/dist/libs/crypto.js +6 -0
- package/dist/libs/crypto.js.map +1 -0
- package/dist/libs/dates.d.ts +3 -0
- package/dist/libs/dates.js +11 -0
- package/dist/libs/dates.js.map +1 -0
- package/dist/libs/http-error.d.ts +21 -0
- package/dist/libs/http-error.js +56 -0
- package/dist/libs/http-error.js.map +1 -0
- package/dist/libs/http-status-codes.d.ts +58 -0
- package/dist/libs/http-status-codes.js +60 -0
- package/dist/libs/http-status-codes.js.map +1 -0
- package/{src/libs/index.ts → dist/libs/index.d.ts} +6 -7
- package/dist/libs/index.js +7 -0
- package/dist/libs/index.js.map +1 -0
- package/dist/libs/url.d.ts +1 -0
- package/dist/libs/url.js +10 -0
- package/dist/libs/url.js.map +1 -0
- package/dist/services/eventbridge-integration-service.d.ts +9 -0
- package/dist/services/eventbridge-integration-service.js +25 -0
- package/dist/services/eventbridge-integration-service.js.map +1 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +2 -0
- package/dist/services/index.js.map +1 -0
- package/{src/types/api-response.ts → dist/types/api-response.d.ts} +6 -6
- package/dist/types/api-response.js +2 -0
- package/dist/types/api-response.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/internal-events/event-detail-types.d.ts +20 -0
- package/dist/types/internal-events/event-detail-types.js +25 -0
- package/dist/types/internal-events/event-detail-types.js.map +1 -0
- package/dist/types/internal-events/index.d.ts +1 -0
- package/dist/types/internal-events/index.js +2 -0
- package/dist/types/internal-events/index.js.map +1 -0
- package/package.json +11 -10
- package/.editorconfig +0 -12
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -37
- package/.husky/pre-push +0 -4
- package/.vscode/settings.json +0 -10
- package/bitbucket-pipelines.yml +0 -20
- package/build.js +0 -39
- package/env.yml +0 -9
- package/jest.config.ts +0 -41
- package/src/__tests__/helpers/subscription-helper.spec.ts +0 -41
- package/src/clients/generic/axios.d.ts +0 -8
- package/src/clients/generic/cognito-client.ts +0 -154
- package/src/clients/generic/dynamodb-client.ts +0 -127
- package/src/clients/generic/eventbridge-client.ts +0 -53
- package/src/clients/generic/http-client.ts +0 -34
- package/src/clients/generic/s3-client.ts +0 -27
- package/src/clients/internal-api/accounts-client.ts +0 -126
- package/src/clients/internal-api/destinations-client.ts +0 -58
- package/src/clients/internal-api/shopify-app-install-client.ts +0 -66
- package/src/clients/internal-api/users-auth-client.ts +0 -112
- package/src/clients/third-party/index.ts +0 -1
- package/src/clients/third-party/shopify-client.ts +0 -139
- package/src/helpers/input-validation-helper.ts +0 -22
- package/src/helpers/logging-helper.ts +0 -10
- package/src/helpers/response-helper.ts +0 -40
- package/src/helpers/shopify-helper.ts +0 -39
- package/src/helpers/subscription-helper.ts +0 -243
- package/src/index.ts +0 -5
- package/src/libs/crypto.ts +0 -6
- package/src/libs/dates.ts +0 -14
- package/src/libs/http-error.ts +0 -90
- package/src/libs/http-status-codes.ts +0 -344
- package/src/libs/url.ts +0 -10
- package/src/services/eventbridge-integration-service.ts +0 -44
- package/src/services/index.ts +0 -1
- package/src/types/index.ts +0 -1
- package/src/types/internal-events/event-detail-types.ts +0 -10
- package/src/types/internal-events/index.ts +0 -1
- package/tsconfig.json +0 -35
- package/tsconfig.tsbuildinfo +0 -1
- package/tslint.json +0 -6
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { DynamoDBClient, QueryOutput } from '@aws-sdk/client-dynamodb';
|
|
2
|
-
import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
|
|
3
|
-
import * as log from 'lambda-log';
|
|
4
|
-
|
|
5
|
-
const marshallOptions = {
|
|
6
|
-
convertEmptyValues: false,
|
|
7
|
-
removeUndefinedValues: false,
|
|
8
|
-
convertClassInstanceToMap: true
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const unmarshallOptions = {
|
|
12
|
-
wrapNumbers: false,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const translateConfig = { marshallOptions, unmarshallOptions };
|
|
16
|
-
const ddbClient = new DynamoDBClient({});
|
|
17
|
-
const client = DynamoDBDocument.from(ddbClient, translateConfig);
|
|
18
|
-
|
|
19
|
-
export class DynamoDbClient {
|
|
20
|
-
static safeGet = async (tableName: string, keyName: string, keyValue: any) => {
|
|
21
|
-
try {
|
|
22
|
-
const params = {
|
|
23
|
-
TableName: tableName,
|
|
24
|
-
Key: {
|
|
25
|
-
[ keyName ]: keyValue
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
const res = await client.get(params);
|
|
29
|
-
return res?.Item ?? null;
|
|
30
|
-
} catch (e: any) {
|
|
31
|
-
log.error(e, { message: 'Dynamo Client Get Failed' });
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
static safePut = async (tableName: string, data: any) => {
|
|
37
|
-
try {
|
|
38
|
-
const params = {
|
|
39
|
-
TableName: tableName,
|
|
40
|
-
Item: data
|
|
41
|
-
};
|
|
42
|
-
const res = await client.put(params);
|
|
43
|
-
return res;
|
|
44
|
-
} catch (e: any) {
|
|
45
|
-
log.error(e, { message: 'Dynamo failed simplePut' });
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
static safeDelete = async (tableName: string, keyName: string, keyValue: any) => {
|
|
51
|
-
try {
|
|
52
|
-
const params = {
|
|
53
|
-
TableName: tableName,
|
|
54
|
-
Key: {
|
|
55
|
-
[ keyName ]: keyValue
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
const res = await client.delete(params);
|
|
59
|
-
return res;
|
|
60
|
-
} catch (e: any) {
|
|
61
|
-
log.error(e, { message: 'Dynamo failed safeDelete' });
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
static safeQueryByGSI = async (tableName: string, gsiName: string, keyName: string, keyValue: any) => {
|
|
67
|
-
const query = {
|
|
68
|
-
TableName: tableName,
|
|
69
|
-
IndexName: gsiName,
|
|
70
|
-
KeyConditionExpression: `${keyName} = :value`,
|
|
71
|
-
ExpressionAttributeValues: {
|
|
72
|
-
':value': keyValue
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const results = await DynamoDbClient.queryAll(query);
|
|
76
|
-
return results;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
static safeBatchGet = async (tableName: string, keys: any) => {
|
|
80
|
-
try {
|
|
81
|
-
const params: any = {
|
|
82
|
-
RequestItems: {}
|
|
83
|
-
};
|
|
84
|
-
params.RequestItems[ tableName ] = {
|
|
85
|
-
Keys: keys
|
|
86
|
-
};
|
|
87
|
-
const res = await client.batchGet(params);
|
|
88
|
-
log.info('batchget res', { batchGetRes: res });
|
|
89
|
-
if (res?.Responses?.[ tableName ]) {
|
|
90
|
-
return res?.Responses?.[ tableName ];
|
|
91
|
-
}
|
|
92
|
-
return [];
|
|
93
|
-
} catch (e: any) {
|
|
94
|
-
log.error(e, { message: 'Dynamo failed safeBatchGet' });
|
|
95
|
-
return [];
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
static queryAll = async (params: any) => {
|
|
100
|
-
try {
|
|
101
|
-
log.info('Invoke Query All', { params });
|
|
102
|
-
let currentResult: QueryOutput, exclusiveStartKey;
|
|
103
|
-
let accumulatedResults: any[] = [];
|
|
104
|
-
do {
|
|
105
|
-
params.ExclusiveStartKey = exclusiveStartKey;
|
|
106
|
-
params.Limit = 200;
|
|
107
|
-
currentResult = await client.query(params);
|
|
108
|
-
if (currentResult.Items) {
|
|
109
|
-
exclusiveStartKey = currentResult.LastEvaluatedKey;
|
|
110
|
-
accumulatedResults = [ ...accumulatedResults, ...currentResult.Items ];
|
|
111
|
-
}
|
|
112
|
-
} while (currentResult.Items && currentResult.Items.length > 0 && currentResult.LastEvaluatedKey);
|
|
113
|
-
return accumulatedResults;
|
|
114
|
-
} catch (e: any) {
|
|
115
|
-
log.error(e, { message: 'Dynamo failed queryAll' });
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
static batchGet = (params: any) => client.batchGet(params);
|
|
121
|
-
static get = (params: any) => client.get(params);
|
|
122
|
-
static put = (params: any) => client.put(params);
|
|
123
|
-
static query = (params: any) => client.query(params);
|
|
124
|
-
static scan = (params: any) => client.scan(params);
|
|
125
|
-
static update = (params: any) => client.update(params);
|
|
126
|
-
static delete = (params: any) => client.delete(params);
|
|
127
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { EventBridgeClient as EventBridge, PutEventsCommand, PutEventsCommandInput } from '@aws-sdk/client-eventbridge';
|
|
2
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
-
import { getCurrentTimestamp } from '../../libs/dates.js';
|
|
4
|
-
import * as log from 'lambda-log';
|
|
5
|
-
|
|
6
|
-
export class EventBridgeClient {
|
|
7
|
-
public eventBridge: EventBridge;
|
|
8
|
-
public EVENT_BUS_NAME: string;
|
|
9
|
-
|
|
10
|
-
constructor (eventBusName: string) {
|
|
11
|
-
this.eventBridge = new EventBridge({});
|
|
12
|
-
this.EVENT_BUS_NAME = eventBusName;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public buildAndSendEvent = async (eventSource: string, eventType: string, eventData: any) => {
|
|
16
|
-
const event = this.buildEvent(eventType, eventData);
|
|
17
|
-
return await this.putEvent(eventSource, eventType, event);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
public buildEvent = (eventType: string, eventData: any, eventId: string = uuidv4(), eventTime: string = getCurrentTimestamp()) => {
|
|
21
|
-
return {
|
|
22
|
-
eventId,
|
|
23
|
-
eventType,
|
|
24
|
-
eventTime,
|
|
25
|
-
eventData
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
public putEvent = async (source: string, detailType: string, data: any, headers: any = null) => {
|
|
30
|
-
const params: PutEventsCommandInput = {
|
|
31
|
-
Entries: [ {
|
|
32
|
-
Detail: JSON.stringify({ headers, data }),
|
|
33
|
-
DetailType: detailType,
|
|
34
|
-
EventBusName: this.EVENT_BUS_NAME,
|
|
35
|
-
Source: source,
|
|
36
|
-
Time: new Date(),
|
|
37
|
-
} ],
|
|
38
|
-
};
|
|
39
|
-
const putEventscommand = new PutEventsCommand(params);
|
|
40
|
-
const response = await this.eventBridge.send(putEventscommand);
|
|
41
|
-
log.debug('EventBus Event Published',
|
|
42
|
-
{
|
|
43
|
-
eventBusName: this.EVENT_BUS_NAME,
|
|
44
|
-
eventSource: source,
|
|
45
|
-
eventType: detailType,
|
|
46
|
-
event: data,
|
|
47
|
-
response
|
|
48
|
-
});
|
|
49
|
-
return response;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
//import axiosRetry from 'axios-retry';
|
|
3
|
-
import https from 'https';
|
|
4
|
-
import httpAdapter from 'axios/lib/adapters/http';
|
|
5
|
-
|
|
6
|
-
const httpResponse = (res: any = {}) => {
|
|
7
|
-
return {
|
|
8
|
-
headers: res?.header || {},
|
|
9
|
-
data: res?.data || {},
|
|
10
|
-
status: res?.status || 0,
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const handleAxiosError = (error: any) => {
|
|
15
|
-
if (!error?.response && !error?.request) throw error;
|
|
16
|
-
return error.response ? httpResponse(error.response) : httpResponse({ status: 500, data: { error: error.request } });
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const axiosHttpService = (config: any = {}) => {
|
|
20
|
-
config.adapter = httpAdapter;
|
|
21
|
-
config.httpsAgent = new https.Agent({ keepAlive: true });
|
|
22
|
-
const axiosService = axios.create(config);
|
|
23
|
-
// axiosRetry(axiosService, { retryDelay: axiosRetry.exponentialDelay, retries: 3 });
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
instance: () => axiosService,
|
|
27
|
-
get: (url: string, config?: any) => axiosService.get(url, config).then(httpResponse, handleAxiosError),
|
|
28
|
-
post: (url: string, data?: any, config?: any) => axiosService.post(url, data, config).then(httpResponse, handleAxiosError),
|
|
29
|
-
delete: (url: string, config?: any) => axiosService.delete(url, config).then(httpResponse, handleAxiosError),
|
|
30
|
-
put: (url: string, data?: any, config?: any) => axiosService.put(url, data, config).then(httpResponse, handleAxiosError),
|
|
31
|
-
patch: (url: string, data?: any, config?: any) => axiosService.patch(url, data, config).then(httpResponse, handleAxiosError),
|
|
32
|
-
setBaseUrl: (url: string) => !!(axiosService.defaults.baseURL = url)
|
|
33
|
-
};
|
|
34
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ObjectCannedACL, S3 } from '@aws-sdk/client-s3';
|
|
2
|
-
import * as log from 'lambda-log';
|
|
3
|
-
|
|
4
|
-
export class S3Client {
|
|
5
|
-
s3: S3;
|
|
6
|
-
|
|
7
|
-
constructor (region = 'us-west-2') {
|
|
8
|
-
this.s3 = new S3({ region });
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async uploadJson(path: string, bucket: string, jsonData: any, ACL: ObjectCannedACL | string = ObjectCannedACL.private) {
|
|
12
|
-
try {
|
|
13
|
-
const res = await this.s3.putObject({
|
|
14
|
-
ACL,
|
|
15
|
-
Bucket: bucket,
|
|
16
|
-
ContentType: 'application/json; charset=utf-8',
|
|
17
|
-
Body: JSON.stringify(jsonData),
|
|
18
|
-
Key: path
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
return res;
|
|
22
|
-
} catch (error) {
|
|
23
|
-
log.error('Error in s3 upload json', { error });
|
|
24
|
-
return error;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import * as log from 'lambda-log';
|
|
2
|
-
import { ApiResponse } from '../../types/api-response.js';
|
|
3
|
-
import { Account, ACCOUNT_STATUS, Destination } from '@adtrackify/at-tracking-event-types';
|
|
4
|
-
import { axiosHttpService } from '../generic/http-client.js';
|
|
5
|
-
|
|
6
|
-
//const BASE_API_URL = process.env.BASE_API_URL;
|
|
7
|
-
|
|
8
|
-
//const SERVICE_API_ROOT_URL = `${BASE_API_URL}/accounts`;
|
|
9
|
-
//const ACCOUNTS_API_KEY = process.env.ACCOUNTS_API_KEY;
|
|
10
|
-
|
|
11
|
-
export interface AccountResponseData {
|
|
12
|
-
account: Account;
|
|
13
|
-
[ key: string ]: any;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface IsAuthorizedUserResponseData {
|
|
17
|
-
isAccountUser: boolean;
|
|
18
|
-
[ key: string ]: any;
|
|
19
|
-
}
|
|
20
|
-
export interface PixelConfigResponseData {
|
|
21
|
-
id: string;
|
|
22
|
-
destinations: Destination[];
|
|
23
|
-
[ key: string ]: any;
|
|
24
|
-
}
|
|
25
|
-
export interface AddUserToAccountResponseData {
|
|
26
|
-
userId: string;
|
|
27
|
-
accountId: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface UpdateAccountRequest {
|
|
31
|
-
accountName?: string,
|
|
32
|
-
companyName?: string,
|
|
33
|
-
primaryEmail?: string,
|
|
34
|
-
ownerId?: string,
|
|
35
|
-
subscriptionId?: string,
|
|
36
|
-
accountStatus?: ACCOUNT_STATUS;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export class AccountsClient {
|
|
40
|
-
public BASE_API_URL: string;
|
|
41
|
-
public ACCOUNTS_API_KEY?: string;
|
|
42
|
-
|
|
43
|
-
constructor (baseApiUrl: string, accountsApiKey?: string) {
|
|
44
|
-
this.BASE_API_URL = baseApiUrl;
|
|
45
|
-
this.ACCOUNTS_API_KEY = accountsApiKey;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
getConfig = () => {
|
|
49
|
-
const SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/accounts`;
|
|
50
|
-
const params: any = {
|
|
51
|
-
baseURL: SERVICE_API_ROOT_URL
|
|
52
|
-
};
|
|
53
|
-
if (this.ACCOUNTS_API_KEY) {
|
|
54
|
-
params.headers = {
|
|
55
|
-
common: {
|
|
56
|
-
'x-api-key': this.ACCOUNTS_API_KEY
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
return params;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
getClient = async () => {
|
|
64
|
-
return axiosHttpService(this.getConfig());
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
createAccount = async (createAccountRequest: any) => {
|
|
68
|
-
const client = await this.getClient();
|
|
69
|
-
const createAccountResponse = await client.post('', createAccountRequest);
|
|
70
|
-
log.info('createAccountResponse', { createAccountResponse });
|
|
71
|
-
return createAccountResponse;
|
|
72
|
-
};
|
|
73
|
-
updateAccount = async (accountId: string, body: any): Promise<ApiResponse<AccountResponseData>> => {
|
|
74
|
-
const client = await this.getClient();
|
|
75
|
-
const response = await client.patch(`/${accountId}/`, body);
|
|
76
|
-
log.info('update Account response', { response });
|
|
77
|
-
return response as ApiResponse<AccountResponseData>;
|
|
78
|
-
};
|
|
79
|
-
addOwner = async (accountId: string, userId: string) => {
|
|
80
|
-
const client = await this.getClient();
|
|
81
|
-
const addOwnerResponse = await client.post('/addOwner', { accountId, userId });
|
|
82
|
-
log.info('addOwnerResponse', { addOwnerResponse });
|
|
83
|
-
return addOwnerResponse;
|
|
84
|
-
};
|
|
85
|
-
isAuthorizedUser = async (userId: string, accountId: string, pixelId?: string): Promise<ApiResponse<IsAuthorizedUserResponseData>> => {
|
|
86
|
-
const client = await this.getClient();
|
|
87
|
-
const body = {
|
|
88
|
-
userId, accountId, pixelId
|
|
89
|
-
};
|
|
90
|
-
const response = await client.post('/checkUserAuthorization', body);
|
|
91
|
-
log.info('checkUserAuthorization', { response });
|
|
92
|
-
return response as ApiResponse<IsAuthorizedUserResponseData>;
|
|
93
|
-
};
|
|
94
|
-
adminDeleteAccount = async (accountId: string) => {
|
|
95
|
-
const client = await this.getClient();
|
|
96
|
-
const success = await client.delete(`/${accountId}`);
|
|
97
|
-
log.info('adminDeleteAccount');
|
|
98
|
-
return success;
|
|
99
|
-
};
|
|
100
|
-
getPixelConfigById = async (pixelId: string): Promise<ApiResponse<PixelConfigResponseData>> => {
|
|
101
|
-
const client = await this.getClient();
|
|
102
|
-
const pixelResponse = await client.get(`/px/${pixelId}/config`);
|
|
103
|
-
log.debug('get pixelResponse', { pixelResponse });
|
|
104
|
-
return pixelResponse;
|
|
105
|
-
};
|
|
106
|
-
getAccount = async (accountId: string): Promise<ApiResponse<AccountResponseData>> => {
|
|
107
|
-
const client = await this.getClient();
|
|
108
|
-
const response = await client.get(`/${accountId}/`);
|
|
109
|
-
log.info('get account response', { response });
|
|
110
|
-
return response as ApiResponse<AccountResponseData>;
|
|
111
|
-
};
|
|
112
|
-
addUserToAccount = async (accountId: string, userId: string): Promise<ApiResponse<AddUserToAccountResponseData>> => {
|
|
113
|
-
const client = await this.getClient();
|
|
114
|
-
const response = await client.post('/addUser', { accountId, userId });
|
|
115
|
-
log.info('add user account response', { response });
|
|
116
|
-
return response as ApiResponse<AddUserToAccountResponseData>;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
// setAccountSubscriptionId = async (accountId: string, subscriptionId: string): Promise<ApiResponse<any>> => {
|
|
121
|
-
// const client = await this.getClient();
|
|
122
|
-
// const pixelResponse = await client.get(`/px/${pixelId}/config`);
|
|
123
|
-
// log.debug('pixelResponse', { pixelResponse });
|
|
124
|
-
// return pixelResponse;
|
|
125
|
-
// };
|
|
126
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import * as log from 'lambda-log';
|
|
2
|
-
//const log = require('lambda-log');
|
|
3
|
-
import { ApiResponse } from '../../types/api-response.js';
|
|
4
|
-
import { axiosHttpService } from '../generic/http-client.js';
|
|
5
|
-
import { Destination } from '@adtrackify/at-tracking-event-types';
|
|
6
|
-
//const BASE_API_URL = process.env.BASE_API_URL;
|
|
7
|
-
//const DESTINATIONS_API_KEY = process.env.DESTINATIONS_API_KEY;
|
|
8
|
-
|
|
9
|
-
export interface GetDestinationsResponseData {
|
|
10
|
-
destinations: Destination[];
|
|
11
|
-
[ key: string ]: any;
|
|
12
|
-
}
|
|
13
|
-
export interface CreateDestinationResponseData {
|
|
14
|
-
destination: Destination;
|
|
15
|
-
[ key: string ]: any;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export class DestinationsClient {
|
|
20
|
-
|
|
21
|
-
public BASE_API_URL: string;
|
|
22
|
-
public DESTINATIONS_API_KEY: string;
|
|
23
|
-
|
|
24
|
-
constructor (baseApiUrl: string, destinationsApiKey: string) {
|
|
25
|
-
this.BASE_API_URL = baseApiUrl;
|
|
26
|
-
this.DESTINATIONS_API_KEY = destinationsApiKey;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
getConfig = () => {
|
|
30
|
-
const SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/destinations`;
|
|
31
|
-
return {
|
|
32
|
-
baseURL: SERVICE_API_ROOT_URL,
|
|
33
|
-
headers: {
|
|
34
|
-
common: {
|
|
35
|
-
'x-api-key': this.DESTINATIONS_API_KEY
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
getClient = async () => {
|
|
42
|
-
return axiosHttpService(this.getConfig());
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
createDestination = async (createDestinationRequest: any): Promise<ApiResponse<CreateDestinationResponseData>> => {
|
|
46
|
-
const client = await this.getClient();
|
|
47
|
-
const response = await client.post('/', createDestinationRequest);
|
|
48
|
-
log.info('createDestinationResponse', { response });
|
|
49
|
-
return response as ApiResponse<CreateDestinationResponseData>;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
getPixelDestinations = async (pixelId: string): Promise<ApiResponse<GetDestinationsResponseData>> => {
|
|
53
|
-
const client = await this.getClient();
|
|
54
|
-
const response = await client.get(`/?pixelId=${pixelId}`);
|
|
55
|
-
log.info('getPixelResponse', { response });
|
|
56
|
-
return response as ApiResponse<GetDestinationsResponseData>;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import log from 'lambda-log';
|
|
2
|
-
import { ApiResponse } from '../../types/api-response.js';
|
|
3
|
-
import { axiosHttpService } from '../generic/http-client.js';
|
|
4
|
-
import { ShopifyAppInstall, ShopifyAppSubscriptionStatus } from '@adtrackify/at-tracking-event-types';
|
|
5
|
-
//const BASE_API_URL = process.env.BASE_API_URL;
|
|
6
|
-
//const DESTINATIONS_API_KEY = process.env.DESTINATIONS_API_KEY;
|
|
7
|
-
|
|
8
|
-
export interface ShopifyAppInstallResponseData {
|
|
9
|
-
shopifyAppInstall: ShopifyAppInstall;
|
|
10
|
-
[ key: string ]: any;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface UpdateShopifyAppInstallRequest {
|
|
14
|
-
appSubscriptionStatus?: ShopifyAppSubscriptionStatus,
|
|
15
|
-
pixelId?: string,
|
|
16
|
-
shopifyAppInstallId: string;
|
|
17
|
-
isAppEnabled?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class ShopifyAppInstallClient {
|
|
21
|
-
|
|
22
|
-
public BASE_API_URL: string;
|
|
23
|
-
public SHOPIFY_APP_INSTALL_API_KEY: string;
|
|
24
|
-
|
|
25
|
-
constructor (baseApiUrl: string, shopifyAppInstallApiKey: string) {
|
|
26
|
-
this.BASE_API_URL = baseApiUrl;
|
|
27
|
-
this.SHOPIFY_APP_INSTALL_API_KEY = shopifyAppInstallApiKey;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
getConfig = () => {
|
|
31
|
-
const SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/shopify-app-installs`;
|
|
32
|
-
return {
|
|
33
|
-
baseURL: SERVICE_API_ROOT_URL,
|
|
34
|
-
headers: {
|
|
35
|
-
common: {
|
|
36
|
-
'x-api-key': this.SHOPIFY_APP_INSTALL_API_KEY
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
getClient = async () => {
|
|
43
|
-
return axiosHttpService(this.getConfig());
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
updateShopifyAppInstall = async (shopifyAppInstallId: string, updateShopifyAppInstallRequest: UpdateShopifyAppInstallRequest): Promise<ApiResponse<ShopifyAppInstallResponseData>> => {
|
|
47
|
-
const client = await this.getClient();
|
|
48
|
-
const response = await client.put(`/${shopifyAppInstallId}`, updateShopifyAppInstallRequest);
|
|
49
|
-
log.info('updateShopifyAppInstall', { response });
|
|
50
|
-
return response as ApiResponse<ShopifyAppInstallResponseData>;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
getShopifyAppInstall = async (shopifyAppInstallId: string): Promise<ApiResponse<ShopifyAppInstallResponseData>> => {
|
|
54
|
-
const client = await this.getClient();
|
|
55
|
-
const response = await client.get(`/${shopifyAppInstallId}`);
|
|
56
|
-
log.info('getShopifyAppInstall', { response });
|
|
57
|
-
return response as ApiResponse<ShopifyAppInstallResponseData>;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
getShopifyAppInstallByShop = async (shop: string): Promise<ApiResponse<ShopifyAppInstallResponseData>> => {
|
|
61
|
-
const client = await this.getClient();
|
|
62
|
-
const response = await client.get(`/?shop=${shop}`);
|
|
63
|
-
log.info('getShopifyAppInstallByShop', { response });
|
|
64
|
-
return response as ApiResponse<ShopifyAppInstallResponseData>;
|
|
65
|
-
};
|
|
66
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { User } from '@adtrackify/at-tracking-event-types';
|
|
2
|
-
import * as log from 'lambda-log';
|
|
3
|
-
import { HttpError } from '../../libs/http-error.js';
|
|
4
|
-
import { HttpStatusCodes } from '../../libs/http-status-codes.js';
|
|
5
|
-
import { ApiResponse } from '../../types/api-response.js';
|
|
6
|
-
import { axiosHttpService } from '../generic/http-client.js';
|
|
7
|
-
|
|
8
|
-
export interface UserResponseData {
|
|
9
|
-
user: User;
|
|
10
|
-
[ key: string ]: any;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface UserSignupRequest {
|
|
14
|
-
email: string,
|
|
15
|
-
password: string,
|
|
16
|
-
givenName: string,
|
|
17
|
-
familyName: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class UsersAuthClient {
|
|
21
|
-
|
|
22
|
-
public SERVICE_API_ROOT_URL: string;
|
|
23
|
-
public BASE_API_URL: string;
|
|
24
|
-
public USERS_AUTH_API_KEY: string;
|
|
25
|
-
constructor (baseApiUrl: string, usersAuthApiKey?: string) {
|
|
26
|
-
this.BASE_API_URL = baseApiUrl;
|
|
27
|
-
this.USERS_AUTH_API_KEY = usersAuthApiKey as string;
|
|
28
|
-
this.SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/auth`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getConfig = () => {
|
|
32
|
-
return {
|
|
33
|
-
baseURL: this.SERVICE_API_ROOT_URL,
|
|
34
|
-
headers: {
|
|
35
|
-
common: {
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
getClient = async () => {
|
|
42
|
-
return axiosHttpService(this.getConfig());
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
signupAndConfirmUser = async (userSignupRequest: any): Promise<any> => {
|
|
46
|
-
const user = await this.signupUser(userSignupRequest);
|
|
47
|
-
await this.adminConfirmUser(user.email);
|
|
48
|
-
// if fail - delete user and throw error
|
|
49
|
-
return user;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
signupUser = async (userSignupRequest: UserSignupRequest): Promise<any> => {
|
|
53
|
-
log.info('Attempting to signup user', { email: userSignupRequest.email });
|
|
54
|
-
|
|
55
|
-
const client = await this.getClient();
|
|
56
|
-
const response = await client.post('/signup', userSignupRequest);
|
|
57
|
-
|
|
58
|
-
// Check if Successful or throw error
|
|
59
|
-
if (response.status !== 200 || !response?.data?.user) {
|
|
60
|
-
const message = 'User Signup Failed';
|
|
61
|
-
log.error(message, { response });
|
|
62
|
-
throw new HttpError(HttpStatusCodes.INTERNAL_SERVER_ERROR, message);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
log.info('User Signup Successful', { response });
|
|
66
|
-
return response.data.user;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
//userName is same as user id
|
|
70
|
-
adminConfirmUser = async (email: string) => {
|
|
71
|
-
//confirm user
|
|
72
|
-
//@TODO update user auth service with admin confirm user endpoint
|
|
73
|
-
log.info('Attempting to admin confirm user', { email });
|
|
74
|
-
|
|
75
|
-
const client = await this.getClient();
|
|
76
|
-
const response = await client.post('/admin/confirm',
|
|
77
|
-
{
|
|
78
|
-
email
|
|
79
|
-
}, {
|
|
80
|
-
headers: {
|
|
81
|
-
'x-api-key': this.USERS_AUTH_API_KEY
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
// Check if Successful or throw error
|
|
87
|
-
if (response.status !== 200) {
|
|
88
|
-
const message = 'Admin User Confirmation Failed';
|
|
89
|
-
log.error(message, { response });
|
|
90
|
-
throw new HttpError(HttpStatusCodes.INTERNAL_SERVER_ERROR, message);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
log.info('Admin User Confirmation Successful', { response });
|
|
94
|
-
return response;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
getUserByEmail = async (email: string): Promise<ApiResponse<UserResponseData>> => {
|
|
98
|
-
const client = await this.getClient();
|
|
99
|
-
const getUserResponse = await client.get('/lookup', {
|
|
100
|
-
headers: {
|
|
101
|
-
'x-api-key': this.USERS_AUTH_API_KEY
|
|
102
|
-
},
|
|
103
|
-
params: {
|
|
104
|
-
email
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
log.info('getUserResponse', { getUserResponse });
|
|
108
|
-
return getUserResponse;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './shopify-client.js';
|