@adtrackify/at-service-common 1.0.30 → 1.0.32

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adtrackify/at-service-common",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -52,7 +52,6 @@
52
52
  "aws-sdk": "^2.1189.0",
53
53
  "babel-eslint": "^10.1.0",
54
54
  "babel-jest": "^26.6.3",
55
- "babel-loader": "^8.2.2",
56
55
  "babel-polyfill": "^6.26.0",
57
56
  "core-js": "^3.21.1",
58
57
  "cross-env": "^7.0.3",
@@ -79,13 +78,13 @@
79
78
  "rimraf": "^3.0.2",
80
79
  "tslint": "^6.1.3",
81
80
  "tslint-config-prettier": "^1.18.0",
82
- "typescript": "^4.7.4"
81
+ "typescript": "4.7.4"
83
82
  },
84
83
  "repository": {
85
84
  "type": "git",
86
- "url": "git+ssh://git@bitbucket.org/eacap/at-tracking-event-types.git"
85
+ "url": "git+ssh://git@bitbucket.org/eacap/at-service-common.git"
87
86
  },
88
87
  "author": "",
89
88
  "license": "ISC",
90
- "homepage": "https://bitbucket.org/eacap/at-tracking-event-types#readme"
89
+ "homepage": "https://bitbucket.org/eacap/at-service-common#readme"
91
90
  }
@@ -1,6 +1,7 @@
1
1
  import { EventBridge } from 'aws-sdk';
2
2
  import { v4 as uuidv4 } from 'uuid';
3
3
  import { getCurrentTimestamp } from '../../libs/dates';
4
+ import * as log from 'lambda-log';
4
5
 
5
6
  export class EventBridgeClient {
6
7
  public eventBridge: EventBridge;
@@ -11,6 +12,11 @@ export class EventBridgeClient {
11
12
  this.EVENT_BUS_NAME = eventBusName;
12
13
  }
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
+
14
20
  public buildEvent = (eventType: string, eventData: any, eventId: string = uuidv4(), eventTime: string = getCurrentTimestamp()) => {
15
21
  return {
16
22
  eventId,
@@ -20,7 +26,6 @@ export class EventBridgeClient {
20
26
  };
21
27
  };
22
28
 
23
-
24
29
  public putEvent = async (source: string, detailType: string, data: any, headers: any = null) => {
25
30
  const params = {
26
31
  Entries: [ {
@@ -31,7 +36,16 @@ export class EventBridgeClient {
31
36
  Time: new Date(),
32
37
  } ],
33
38
  };
34
- return await this.eventBridge.putEvents(params).promise();
39
+ const response = await this.eventBridge.putEvents(params).promise();
40
+ log.debug('EventBus Event Published',
41
+ {
42
+ eventBusName: this.EVENT_BUS_NAME,
43
+ eventSource: source,
44
+ eventType: detailType,
45
+ event: data,
46
+ response
47
+ });
48
+ return response;
35
49
  };
36
50
 
37
51
  }
@@ -47,7 +47,19 @@ export class AccountsClient {
47
47
  return axiosHttpService(this.getConfig());
48
48
  };
49
49
 
50
- isAuthorizedUser = async (userId: string, accountId: string, pixelId: string): Promise<ApiResponse<IsAuthorizedUserResponseData>> => {
50
+ createAccount = async (createAccountRequest: any) => {
51
+ const client = await this.getClient();
52
+ const createAccountResponse = await client.post('', createAccountRequest);
53
+ log.info('createAccountResponse', { createAccountResponse });
54
+ return createAccountResponse;
55
+ };
56
+ addOwner = async (accountId: string, userId: string) => {
57
+ const client = await this.getClient();
58
+ const addOwnerResponse = await client.post('/addOwner', { accountId, userId });
59
+ log.info('addOwnerResponse', { addOwnerResponse });
60
+ return addOwnerResponse;
61
+ };
62
+ isAuthorizedUser = async (userId: string, accountId: string, pixelId?: string): Promise<ApiResponse<IsAuthorizedUserResponseData>> => {
51
63
  const client = await this.getClient();
52
64
  const body = {
53
65
  userId, accountId, pixelId
@@ -56,7 +68,12 @@ export class AccountsClient {
56
68
  log.info('checkUserAuthorization', { response });
57
69
  return response as ApiResponse<IsAuthorizedUserResponseData>;
58
70
  };
59
-
71
+ adminDeleteAccount = async (accountId: string) => {
72
+ const client = await this.getClient();
73
+ const success = await client.delete(`/${accountId}`);
74
+ log.info('adminDeleteAccount');
75
+ return success;
76
+ };
60
77
  getPixelConfigById = async (pixelId: string): Promise<ApiResponse<PixelConfigResponseData>> => {
61
78
  const client = await this.getClient();
62
79
  const pixelResponse = await client.get(`/px/${pixelId}/config`);
@@ -1,2 +1,3 @@
1
1
  export * from './destinations-client';
2
- export * from './accounts-client';
2
+ export * from './accounts-client';
3
+ export * from './users-auth-client';
@@ -0,0 +1,51 @@
1
+ import { axiosHttpService } from '../generic/http-client';
2
+ import * as log from 'lambda-log';
3
+
4
+ export class UsersAuthClient {
5
+
6
+ public SERVICE_API_ROOT_URL: string;
7
+ public BASE_API_URL: string;
8
+ public USERS_AUTH_API_KEY: string;
9
+ constructor (baseApiUrl: string, usersAuthApiKey?: string) {
10
+ this.BASE_API_URL = baseApiUrl;
11
+ this.USERS_AUTH_API_KEY = usersAuthApiKey as string;
12
+ this.SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/auth`;
13
+ }
14
+
15
+ getConfig = () => {
16
+ return {
17
+ baseURL: this.SERVICE_API_ROOT_URL,
18
+ headers: {
19
+ common: {
20
+ }
21
+ }
22
+ };
23
+ };
24
+
25
+ getClient = async () => {
26
+ return axiosHttpService(this.getConfig());
27
+ };
28
+
29
+ signupUser = async (userSignupRequest: any) => {
30
+ const client = await this.getClient();
31
+ const signupUserResponse = await client.post('/signup', userSignupRequest);
32
+ log.info('signupUser response', { signupUserResponse });
33
+ return signupUserResponse;
34
+ };
35
+
36
+ getUserByEmail = async (email: string) => {
37
+ const client = await this.getClient();
38
+ const getUserResponse = await client.get('/lookup', {
39
+ headers: {
40
+ 'x-api-key': this.USERS_AUTH_API_KEY
41
+ },
42
+ params: {
43
+ email
44
+ }
45
+ });
46
+ log.info('getUserResponse', { getUserResponse });
47
+ return getUserResponse;
48
+ };
49
+
50
+ }
51
+
@@ -1 +1,2 @@
1
- export * from './db';
1
+ export * from './db';
2
+ export * from './internal-events';
@@ -0,0 +1,9 @@
1
+ export enum ADTRACKIFY_EVENT_TYPES {
2
+ NOTIFY_SHOPIFY_SUBSCRIPTION_CREATED = 'shopifySubscriptionCreated',
3
+
4
+ REQUEST_SET_ACCOUNT_SUBSCRIPTION_ID = 'setAccountSubscriptionId',
5
+ }
6
+
7
+ export enum ADTRACKIFY_EVENT_SOURCES {
8
+ SUBSCRIPTIONS = 'subscriptions',
9
+ }
@@ -0,0 +1 @@
1
+ export * from './event-detail-types';