@adtrackify/at-service-common 1.1.21 → 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 -6
- 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,139 +0,0 @@
|
|
|
1
|
-
import { axiosHttpService } from '../generic/http-client.js';
|
|
2
|
-
import * as log from 'lambda-log';
|
|
3
|
-
|
|
4
|
-
export class ShopifyClient {
|
|
5
|
-
static _shopify_api_version = process.env.SHOPIFY_API_VERSION as string;
|
|
6
|
-
static getConfig = (shopifyDomain: string, accessToken: string) => {
|
|
7
|
-
const config = {
|
|
8
|
-
baseURL: `https://${shopifyDomain}/admin/api/${this._shopify_api_version}`,
|
|
9
|
-
headers: {
|
|
10
|
-
common: {
|
|
11
|
-
'X-Shopify-Access-Token': accessToken,
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
return config;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
static getClient = (shopifyDomain: string, accessToken: string) => {
|
|
19
|
-
return axiosHttpService(
|
|
20
|
-
this.getConfig(shopifyDomain, accessToken)
|
|
21
|
-
);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
static registerApp = async (shop: string, code: string, appKey: string, appSecret: string) => {
|
|
25
|
-
const client = axiosHttpService();
|
|
26
|
-
const url = 'https://' + shop + '/admin/oauth/access_token';
|
|
27
|
-
const payload = {
|
|
28
|
-
client_id: appKey,
|
|
29
|
-
client_secret: appSecret,
|
|
30
|
-
code
|
|
31
|
-
};
|
|
32
|
-
const res = await client.post(url, payload);
|
|
33
|
-
return res;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
static registerWebhookTopic = async (shop: string, accessToken: string, eventBridgeArn: string, topic: string) => {
|
|
37
|
-
const client = axiosHttpService();
|
|
38
|
-
const url = `https://${shop}/admin/api/${this._shopify_api_version}/webhooks.json`;
|
|
39
|
-
const payload = {
|
|
40
|
-
webhook: {
|
|
41
|
-
topic,
|
|
42
|
-
address: eventBridgeArn,
|
|
43
|
-
format: 'json'
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const res = await client.post(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });
|
|
47
|
-
if (res.status >= 400) {
|
|
48
|
-
log.error('Failed to register Webhook Topic', { shop, accessToken, eventBridgeArn, topic, url, payload });
|
|
49
|
-
}
|
|
50
|
-
log.debug('Shopify Client Webhook Registration Response', { registrationResponse: res });
|
|
51
|
-
return res;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
static updateShopifyAppMetafield = async (shop: string, accessToken: string, pixelId: string) => {
|
|
55
|
-
const url = `https://${shop}/admin/api/${this._shopify_api_version}/metafields.json`;
|
|
56
|
-
const payload = {
|
|
57
|
-
metafield: {
|
|
58
|
-
namespace: 'adtr',
|
|
59
|
-
key: 'adtr.config',
|
|
60
|
-
value: pixelId,
|
|
61
|
-
type: 'single_line_text_field'
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
const res = await this.genericShopifyPost(url, accessToken, payload);
|
|
65
|
-
|
|
66
|
-
if (res.status >= 400) {
|
|
67
|
-
log.error('Failed to update Shopify app Metafield ', { shop, accessToken, url, payload });
|
|
68
|
-
}
|
|
69
|
-
return res;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
static getShopifyStoreProperties = async (shop: string, accessToken: string) => {
|
|
73
|
-
const url = `https://${shop}/admin/api/${this._shopify_api_version}/shop.json`;
|
|
74
|
-
const res = await this.genericShopifyGet(url, accessToken);
|
|
75
|
-
|
|
76
|
-
if (res.status >= 400) {
|
|
77
|
-
log.error('Failed to get Shopify Store Properties', { shop, accessToken, url });
|
|
78
|
-
}
|
|
79
|
-
return res;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
static createAppSubscription = async (shop: string, accessToken: string,
|
|
83
|
-
planName: string, price: number, returnUrl: string, trialDays: number, test?: boolean) => {
|
|
84
|
-
const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges.json`;
|
|
85
|
-
const recurring_application_charge = {
|
|
86
|
-
name: planName,
|
|
87
|
-
price,
|
|
88
|
-
return_url: returnUrl,
|
|
89
|
-
trial_days: trialDays,
|
|
90
|
-
test
|
|
91
|
-
};
|
|
92
|
-
const res = await this.genericShopifyPost(url, accessToken, { recurring_application_charge });
|
|
93
|
-
if (res.status >= 400) {
|
|
94
|
-
log.error('Failed to create App Subscription', { shop, accessToken, url });
|
|
95
|
-
}
|
|
96
|
-
return res;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
static cancelAppSubscription = async (shop: string, accessToken: string, chargeId: string) => {
|
|
100
|
-
const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges/${chargeId}.json`;
|
|
101
|
-
const client = axiosHttpService();
|
|
102
|
-
const res = await client.delete(url, { headers: { 'X-Shopify-Access-Token': accessToken } });
|
|
103
|
-
|
|
104
|
-
if (res.status !== 200) {
|
|
105
|
-
log.error('Failed to cancel recurring App billing', { shop, accessToken, url });
|
|
106
|
-
}
|
|
107
|
-
return res;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
static listAppSubscriptions = async (shop: string, accessToken: string) => {
|
|
111
|
-
const url = `https://${shop}/admin/api/${this._shopify_api_version}/recurring_application_charges.json`;
|
|
112
|
-
const res = await this.genericShopifyGet(url, accessToken);
|
|
113
|
-
if (res.status >= 400) {
|
|
114
|
-
log.error('Failed to get App Subscriptions', { shop, accessToken, url });
|
|
115
|
-
}
|
|
116
|
-
return res;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
static genericShopifyPost = async (url: string, accessToken: string, payload: any) => {
|
|
120
|
-
const client = axiosHttpService();
|
|
121
|
-
const res = await client.post(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken, 'Content-Type': 'application/json' } });
|
|
122
|
-
log.debug('Shopify Client Response', { res });
|
|
123
|
-
return res;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
static genericShopifyGet = async (url: string, accessToken: string) => {
|
|
127
|
-
const client = axiosHttpService();
|
|
128
|
-
const res = await client.get(url, { headers: { 'X-Shopify-Access-Token': accessToken } });
|
|
129
|
-
log.debug('Shopify Client Response', { res });
|
|
130
|
-
return res;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
static genericShopifyPut = async (url: string, accessToken: string, payload: any) => {
|
|
134
|
-
const client = axiosHttpService();
|
|
135
|
-
const res = await client.put(url, payload, { headers: { 'X-Shopify-Access-Token': accessToken } });
|
|
136
|
-
log.debug('Shopify Client Response', { res });
|
|
137
|
-
return res;
|
|
138
|
-
};
|
|
139
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import Joi from 'joi';
|
|
2
|
-
import * as log from 'lambda-log';
|
|
3
|
-
import { HttpError } from '../libs/http-error.js';
|
|
4
|
-
|
|
5
|
-
export const validateInput = (schema: Joi.ObjectSchema<any>, input: any) => {
|
|
6
|
-
const { error, value } = schema.validate(input);
|
|
7
|
-
if (error) {
|
|
8
|
-
log.info('', { error });
|
|
9
|
-
|
|
10
|
-
const httperr = HttpError.badRequest('Bad Request', {
|
|
11
|
-
errors: error.details.map(detail => ({
|
|
12
|
-
message: detail?.message,
|
|
13
|
-
key: detail?.context?.key,
|
|
14
|
-
path: detail?.path,
|
|
15
|
-
}))
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
log.info('', { httperr });
|
|
19
|
-
throw httperr;
|
|
20
|
-
}
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as log from 'lambda-log';
|
|
2
|
-
const stage = process?.env?.STAGE;
|
|
3
|
-
|
|
4
|
-
export const configureLogger = (event: any, context: any, debug = true) => {
|
|
5
|
-
log.options.meta.stage = stage;
|
|
6
|
-
log.options.meta.source_name = context?.functionName || 'unknown';
|
|
7
|
-
log.options.meta.awsRequestId = context?.awsRequestId || 'unknown';
|
|
8
|
-
log.options.meta.lambdaEvent = event;
|
|
9
|
-
log.options.debug = debug;
|
|
10
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export const success = (body: any) => {
|
|
3
|
-
return buildResponse(200, body);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
const defaultError = {
|
|
7
|
-
message: 'internalServerError'
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const failure = (error: any, statusCode = 500) => {
|
|
11
|
-
statusCode = error?.statusCode ?? statusCode;
|
|
12
|
-
|
|
13
|
-
let body = defaultError;
|
|
14
|
-
if (error?.body) {
|
|
15
|
-
body = error.body;
|
|
16
|
-
}
|
|
17
|
-
else if (error?.message) {
|
|
18
|
-
body = { message: error.message };
|
|
19
|
-
} else if (statusCode === 500) {
|
|
20
|
-
body = defaultError;
|
|
21
|
-
}
|
|
22
|
-
return buildResponse(statusCode, body);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const buildResponse = (statusCode: number, body: any = {}) => {
|
|
26
|
-
delete body.stack;
|
|
27
|
-
return {
|
|
28
|
-
statusCode: statusCode,
|
|
29
|
-
headers: {
|
|
30
|
-
'Access-Control-Allow-Origin': '*',
|
|
31
|
-
'Access-Control-Allow-Credentials': true,
|
|
32
|
-
'cache-control': 'max-age=86400',
|
|
33
|
-
Date: new Date(),
|
|
34
|
-
'Last-Modified': new Date(),
|
|
35
|
-
'Access-Control-Allow-Headers':
|
|
36
|
-
'Content-Type, Content-Encoding'
|
|
37
|
-
},
|
|
38
|
-
body: JSON.stringify(body),
|
|
39
|
-
};
|
|
40
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { createHmac } from 'crypto';
|
|
2
|
-
import * as log from 'lambda-log';
|
|
3
|
-
import { HttpError } from '../libs/http-error.js';
|
|
4
|
-
import { mapObjectToQueryString } from '../libs/url.js';
|
|
5
|
-
export interface ShopifyRequestValidationParameters {
|
|
6
|
-
code: string,
|
|
7
|
-
hmac?: string,
|
|
8
|
-
shop: string,
|
|
9
|
-
state: string,
|
|
10
|
-
timestamp: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const isShopifyRequestValid = (validationParams: ShopifyRequestValidationParameters, validationHmac: string, shopifyAppApiSecret: string): boolean => {
|
|
14
|
-
// remove hmac if it exists
|
|
15
|
-
// map input to query string
|
|
16
|
-
// generate hash using api secret key and validate it matches hmac
|
|
17
|
-
delete validationParams.hmac;
|
|
18
|
-
const hmacString = mapObjectToQueryString(validationParams);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const generatedHash = createHmac('sha256', shopifyAppApiSecret)
|
|
22
|
-
.update(hmacString)
|
|
23
|
-
.digest('hex');
|
|
24
|
-
|
|
25
|
-
return generatedHash === validationHmac;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const validateShopifyRequest = (validationParams: ShopifyRequestValidationParameters, validationHmac: string, shopifyAppApiSecret: string) => {
|
|
29
|
-
log.info('Validating shopify request is authentic', { validationParams });
|
|
30
|
-
const isValid = isShopifyRequestValid(validationParams, validationHmac as string, shopifyAppApiSecret);
|
|
31
|
-
if (!isValid) {
|
|
32
|
-
const message = 'Failed: Shopify Request hmac validation';
|
|
33
|
-
log.error(message);
|
|
34
|
-
throw HttpError.badRequest(message);
|
|
35
|
-
}
|
|
36
|
-
log.info('Sucess: Shopify Request hmac validation');
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import { SubscriptionPlan, PLAN_BILLING_FREQUENCY } from '@adtrackify/at-tracking-event-types';
|
|
2
|
-
|
|
3
|
-
export const StripeBillingMap: any = {
|
|
4
|
-
dev2: {
|
|
5
|
-
'free': 'price_1JzjbKK7krGh4037ezNbGJEm',
|
|
6
|
-
'starter_monthly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
7
|
-
'starter_yearly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
8
|
-
'scale_monthly': 'price_1JzjcSK7krGh4037yh34LPk3',
|
|
9
|
-
'scale_yearly': 'price_1JzjcSK7krGh4037QiBJYfnD',
|
|
10
|
-
'growth_monthly': 'price_1Jzje1K7krGh4037KErHBp5N',
|
|
11
|
-
'growth_yearly': 'price_1Jzje1K7krGh4037MhCUhTDh'
|
|
12
|
-
},
|
|
13
|
-
qa2: {
|
|
14
|
-
'free': 'price_1JzjbKK7krGh4037ezNbGJEm',
|
|
15
|
-
'starter_monthly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
16
|
-
'starter_yearly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
17
|
-
'scale_monthly': 'price_1JzjcSK7krGh4037yh34LPk3',
|
|
18
|
-
'scale_yearly': 'price_1JzjcSK7krGh4037QiBJYfnD',
|
|
19
|
-
'growth_monthly': 'price_1Jzje1K7krGh4037KErHBp5N',
|
|
20
|
-
'growth_yearly': 'price_1Jzje1K7krGh4037MhCUhTDh'
|
|
21
|
-
},
|
|
22
|
-
prod2: {
|
|
23
|
-
'free': 'price_1KAFsIK7krGh4037RsaAYMEl',
|
|
24
|
-
'starter_monthly': 'price_1KAFsMK7krGh4037Lz3P0ksU',
|
|
25
|
-
'starter_yearly': 'price_1KAFsMK7krGh4037Dj1WmSi8',
|
|
26
|
-
'scale_monthly': 'price_1KAFrxK7krGh4037zWCdaTly',
|
|
27
|
-
'scale_yearly': 'price_1KAFrxK7krGh40375fhymyWP',
|
|
28
|
-
'growth_monthly': 'price_1KAFs7K7krGh4037JChjz5Cr',
|
|
29
|
-
'growth_yearly': 'price_1KAFs7K7krGh4037rZElg12s'
|
|
30
|
-
},
|
|
31
|
-
dev: {
|
|
32
|
-
'free': 'price_1JzjbKK7krGh4037ezNbGJEm',
|
|
33
|
-
'starter_monthly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
34
|
-
'starter_yearly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
35
|
-
'scale_monthly': 'price_1JzjcSK7krGh4037yh34LPk3',
|
|
36
|
-
'scale_yearly': 'price_1JzjcSK7krGh4037QiBJYfnD',
|
|
37
|
-
'growth_monthly': 'price_1Jzje1K7krGh4037KErHBp5N',
|
|
38
|
-
'growth_yearly': 'price_1Jzje1K7krGh4037MhCUhTDh'
|
|
39
|
-
},
|
|
40
|
-
qa: {
|
|
41
|
-
'free': 'price_1JzjbKK7krGh4037ezNbGJEm',
|
|
42
|
-
'starter_monthly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
43
|
-
'starter_yearly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
44
|
-
'scale_monthly': 'price_1JzjcSK7krGh4037yh34LPk3',
|
|
45
|
-
'scale_yearly': 'price_1JzjcSK7krGh4037QiBJYfnD',
|
|
46
|
-
'growth_monthly': 'price_1Jzje1K7krGh4037KErHBp5N',
|
|
47
|
-
'growth_yearly': 'price_1Jzje1K7krGh4037MhCUhTDh'
|
|
48
|
-
},
|
|
49
|
-
prod: {
|
|
50
|
-
'free': 'price_1KAFsIK7krGh4037RsaAYMEl',
|
|
51
|
-
'starter_monthly': 'price_1KAFsMK7krGh4037Lz3P0ksU',
|
|
52
|
-
'starter_yearly': 'price_1KAFsMK7krGh4037Dj1WmSi8',
|
|
53
|
-
'scale_monthly': 'price_1KAFrxK7krGh4037zWCdaTly',
|
|
54
|
-
'scale_yearly': 'price_1KAFrxK7krGh40375fhymyWP',
|
|
55
|
-
'growth_monthly': 'price_1KAFs7K7krGh4037JChjz5Cr',
|
|
56
|
-
'growth_yearly': 'price_1KAFs7K7krGh4037rZElg12s'
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export const CommonPlanInfo = [
|
|
61
|
-
//'60-day Risk Free Trial',
|
|
62
|
-
'Free Server Side Tracking & Conversion API',
|
|
63
|
-
'MultiPixel Support (Multiple facebook, tiktok, etc)',
|
|
64
|
-
'Corrects Facebook Conversion Tracking post IOS14',
|
|
65
|
-
'Increase ROAS & Attribution Data',
|
|
66
|
-
'Enhanced Fingerprinting & Identity Resolution',
|
|
67
|
-
'Unlimited Integrations',
|
|
68
|
-
'Advanced Integrations (Webhooks, Custom JS/HTML, Hubspot)'
|
|
69
|
-
];
|
|
70
|
-
|
|
71
|
-
export const SubscriptionPlanSeedItems: {
|
|
72
|
-
items: SubscriptionPlan[];
|
|
73
|
-
} = {
|
|
74
|
-
items: [ {
|
|
75
|
-
id: 1,
|
|
76
|
-
planName: 'free',
|
|
77
|
-
displayName: 'Free',
|
|
78
|
-
sku: 'ADT-001',
|
|
79
|
-
description: 'Free Plan - Monthly',
|
|
80
|
-
price: '0',
|
|
81
|
-
displayPrice: '$0',
|
|
82
|
-
billingFrequency: PLAN_BILLING_FREQUENCY.MONTHLY,
|
|
83
|
-
trialLengthDays: 0,
|
|
84
|
-
trialRequiresCreditCard: false,
|
|
85
|
-
planDesc: [
|
|
86
|
-
...CommonPlanInfo,
|
|
87
|
-
'Free Up to 500 orders/month (50,000 events)*'
|
|
88
|
-
],
|
|
89
|
-
unitPriceText: 'try now - free forever',
|
|
90
|
-
isHighlighted: false,
|
|
91
|
-
isBanner: false
|
|
92
|
-
},
|
|
93
|
-
// STARTER PLANS
|
|
94
|
-
{
|
|
95
|
-
id: 2,
|
|
96
|
-
planName: 'starter_monthly',
|
|
97
|
-
displayName: 'Starter',
|
|
98
|
-
sku: 'ADT-002',
|
|
99
|
-
description: 'Starter Plan - Monthly',
|
|
100
|
-
price: '79.99',
|
|
101
|
-
displayPrice: '$79.99',
|
|
102
|
-
billingFrequency: PLAN_BILLING_FREQUENCY.MONTHLY,
|
|
103
|
-
trialLengthDays: 60,
|
|
104
|
-
trialRequiresCreditCard: false,
|
|
105
|
-
planDesc: [
|
|
106
|
-
'60-day Risk Free Trial',
|
|
107
|
-
...CommonPlanInfo,
|
|
108
|
-
'Up to 2,000 orders/month (250,000 events)*'
|
|
109
|
-
],
|
|
110
|
-
isHighlighted: true,
|
|
111
|
-
isBanner: true,
|
|
112
|
-
bannerColor: 'blue',
|
|
113
|
-
bannerText: 'MOST POPULAR'
|
|
114
|
-
}, {
|
|
115
|
-
id: 3,
|
|
116
|
-
planName: 'starter_yearly',
|
|
117
|
-
displayName: 'Starter',
|
|
118
|
-
sku: 'ADT-003',
|
|
119
|
-
description: 'Starter Plan - Yearly',
|
|
120
|
-
price: '767.90',
|
|
121
|
-
displayPrice: '$63.99',
|
|
122
|
-
billingFrequency: PLAN_BILLING_FREQUENCY.YEARLY,
|
|
123
|
-
trialLengthDays: 30,
|
|
124
|
-
trialRequiresCreditCard: false,
|
|
125
|
-
planDesc: [
|
|
126
|
-
'60-day Risk Free Trial',
|
|
127
|
-
...CommonPlanInfo,
|
|
128
|
-
'Up to 2,000 orders/month (250,000 events)*'
|
|
129
|
-
],
|
|
130
|
-
unitPriceText: 'billed yearly ($767.90) - 20% savings',
|
|
131
|
-
isHighlighted: true,
|
|
132
|
-
isBanner: true,
|
|
133
|
-
bannerColor: 'blue',
|
|
134
|
-
bannerText: 'MOST POPULAR'
|
|
135
|
-
},
|
|
136
|
-
// SCALE PLANS
|
|
137
|
-
{
|
|
138
|
-
id: 4,
|
|
139
|
-
planName: 'scale_monthly',
|
|
140
|
-
displayName: 'Scale',
|
|
141
|
-
sku: 'ADT-004',
|
|
142
|
-
description: 'Scale Plan - Monthly',
|
|
143
|
-
price: '199.99',
|
|
144
|
-
displayPrice: '$199.99',
|
|
145
|
-
billingFrequency: PLAN_BILLING_FREQUENCY.MONTHLY,
|
|
146
|
-
trialLengthDays: 60,
|
|
147
|
-
trialRequiresCreditCard: false,
|
|
148
|
-
planDesc: [
|
|
149
|
-
'60-day Risk Free Trial',
|
|
150
|
-
...CommonPlanInfo,
|
|
151
|
-
'Up to 7,500 orders/month (750,000 events)*'
|
|
152
|
-
],
|
|
153
|
-
unitPriceText: '',
|
|
154
|
-
isHighlighted: false,
|
|
155
|
-
isBanner: false
|
|
156
|
-
}, {
|
|
157
|
-
id: 5,
|
|
158
|
-
planName: 'scale_yearly',
|
|
159
|
-
displayName: 'Scale',
|
|
160
|
-
sku: 'ADT-005',
|
|
161
|
-
description: 'Scale Plan - Yearly',
|
|
162
|
-
price: '1823.91',
|
|
163
|
-
displayPrice: '$151.99',
|
|
164
|
-
billingFrequency: PLAN_BILLING_FREQUENCY.YEARLY,
|
|
165
|
-
trialLengthDays: 60,
|
|
166
|
-
trialRequiresCreditCard: false,
|
|
167
|
-
planDesc: [
|
|
168
|
-
'60-day Risk Free Trial',
|
|
169
|
-
...CommonPlanInfo,
|
|
170
|
-
'Up to 7,500 orders/month (750,000 events)*'
|
|
171
|
-
],
|
|
172
|
-
unitPriceText: 'billed yearly ($1823.91) - 24% savings',
|
|
173
|
-
isHighlighted: false,
|
|
174
|
-
isBanner: false
|
|
175
|
-
},
|
|
176
|
-
// // GROWTH PLANS
|
|
177
|
-
// {
|
|
178
|
-
// id: 6,
|
|
179
|
-
// planName: 'growth_monthly',
|
|
180
|
-
// displayName: 'Growth',
|
|
181
|
-
// sku: 'ADT-006',
|
|
182
|
-
// description: 'Growth Plan - Monthly',
|
|
183
|
-
// price: '199.99',
|
|
184
|
-
// displayPrice: '$199.99',
|
|
185
|
-
// billingFrequency: PLAN_BILLING_FREQUENCY.MONTHLY,
|
|
186
|
-
// trialLengthDays: 60,
|
|
187
|
-
// trialRequiresCreditCard: false,
|
|
188
|
-
// planDesc: [
|
|
189
|
-
// '60-day Risk Free Trial',
|
|
190
|
-
// ...CommonPlanInfo,
|
|
191
|
-
// '250,000 tracking events/mo'
|
|
192
|
-
// ],
|
|
193
|
-
// unitPriceText: 'billed yearly ($540) - 25% savings',
|
|
194
|
-
// isHighlighted: false,
|
|
195
|
-
// isBanner: true,
|
|
196
|
-
// bannerColor: 'orange',
|
|
197
|
-
// bannerText: 'BEST VALUE'
|
|
198
|
-
// }, {
|
|
199
|
-
// id: 7,
|
|
200
|
-
// planName: 'growth_yearly',
|
|
201
|
-
// displayName: 'Growth',
|
|
202
|
-
// sku: 'ADT-007',
|
|
203
|
-
// description: 'Growth Plan - Yearly',
|
|
204
|
-
// price: '1799.91',
|
|
205
|
-
// displayPrice: '$149.99',
|
|
206
|
-
// billingFrequency: PLAN_BILLING_FREQUENCY.YEARLY,
|
|
207
|
-
// trialLengthDays: 60,
|
|
208
|
-
// trialRequiresCreditCard: false,
|
|
209
|
-
// planDesc: [
|
|
210
|
-
// '30-day Risk Free Trial',
|
|
211
|
-
// 'Fixes IOS14.5 tracking',
|
|
212
|
-
// 'Multi Pixel Support',
|
|
213
|
-
// 'Enhanced Tracking / Attribution',
|
|
214
|
-
// 'Unlimited Facebook Conversion API',
|
|
215
|
-
// 'Unlimited Integrations',
|
|
216
|
-
// 'Easy no code setup',
|
|
217
|
-
// '100,000 tracking events/mo'
|
|
218
|
-
// ],
|
|
219
|
-
// unitPriceText: 'billed yearly ($1799.91) - 25% savings',
|
|
220
|
-
// isHighlighted: false,
|
|
221
|
-
// isBanner: true,
|
|
222
|
-
// bannerColor: 'orange',
|
|
223
|
-
// bannerText: 'BEST VALUE'
|
|
224
|
-
// },
|
|
225
|
-
]
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
export const getPlanDetails = (planId: number, stage: string) => {
|
|
230
|
-
const plan = SubscriptionPlanSeedItems.items.filter(x => x.id === planId)[ 0 ] as any;
|
|
231
|
-
plan.stripePriceId = StripeBillingMap[ stage ][ plan.planName ];
|
|
232
|
-
return plan as SubscriptionPlan;
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
export const getPlanByStripePriceId = (stripePriceId: string, stage: string) => {
|
|
236
|
-
const stripePriceIds = StripeBillingMap[ stage ];
|
|
237
|
-
const planName = Object.keys(stripePriceIds).find(key => stripePriceIds[ key ] === stripePriceId);
|
|
238
|
-
|
|
239
|
-
const plan = SubscriptionPlanSeedItems.items.filter(x => x.planName === planName)[ 0 ] as any;
|
|
240
|
-
plan.stripePriceId = stripePriceId;
|
|
241
|
-
|
|
242
|
-
return plan as SubscriptionPlan;
|
|
243
|
-
};
|
package/src/index.ts
DELETED
package/src/libs/crypto.ts
DELETED
package/src/libs/dates.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { DateTime } from 'luxon';
|
|
3
|
-
|
|
4
|
-
export const getCurrentTimestamp = (): string => {
|
|
5
|
-
return DateTime.utc().toJSDate().toISOString();
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const getDateFromTimestamp = (timestamp: string) => {
|
|
9
|
-
return timestamp.split('T')[0];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const getCurrentDate = (): string => {
|
|
13
|
-
return getDateFromTimestamp(getCurrentTimestamp());
|
|
14
|
-
}
|
package/src/libs/http-error.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-dupe-class-members */
|
|
2
|
-
import { strict as assert } from 'assert';
|
|
3
|
-
|
|
4
|
-
const deepClone = (o = {}) => JSON.parse(JSON.stringify(o));
|
|
5
|
-
const containsStackTrace = (text = '') => /at.+\.js:\d+:\d+/.test(text);
|
|
6
|
-
const objectContainsStackTrace = (obj: any) =>
|
|
7
|
-
!obj ? false : containsStackTrace(JSON.stringify(obj));
|
|
8
|
-
|
|
9
|
-
// may only be expanded by governance, never reduced
|
|
10
|
-
const supportedStatusCodes: any = {
|
|
11
|
-
400: 'Bad Request',
|
|
12
|
-
401: 'Unauthorized',
|
|
13
|
-
403: 'Forbidden',
|
|
14
|
-
404: 'Not Found',
|
|
15
|
-
405: 'Method Not Allowed',
|
|
16
|
-
409: 'Conflict',
|
|
17
|
-
412: 'Precondition Failed',
|
|
18
|
-
413: 'Payload Too Large',
|
|
19
|
-
415: 'Unsupported Media Type',
|
|
20
|
-
428: 'Precondition Required',
|
|
21
|
-
429: 'Too Many Requests',
|
|
22
|
-
500: 'Internal Server Error',
|
|
23
|
-
501: 'Not Implemented',
|
|
24
|
-
502: 'Bad Gateway',
|
|
25
|
-
503: 'Service Unavailable',
|
|
26
|
-
504: 'Gateway Timeout'
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const supportedStatusCodesMessage = `statusCode must be one of the following: ${JSON.stringify(Object.keys(supportedStatusCodes))}`;
|
|
30
|
-
//const onlyStatusCodeMessage = 'Server errors may not specify any parameter except statusCode';
|
|
31
|
-
|
|
32
|
-
//const isNullOrUndefined = (value: any) => value === null || value === undefined;
|
|
33
|
-
|
|
34
|
-
export class HttpError extends Error {
|
|
35
|
-
body: {
|
|
36
|
-
[ key: string ]: any;
|
|
37
|
-
};
|
|
38
|
-
headers: object[];
|
|
39
|
-
statusCode: number;
|
|
40
|
-
isServerError: boolean;
|
|
41
|
-
|
|
42
|
-
constructor (statusCode: number,
|
|
43
|
-
message?: string,
|
|
44
|
-
body?: {
|
|
45
|
-
[ key: string ]: any;
|
|
46
|
-
},
|
|
47
|
-
headers?: object[]) {
|
|
48
|
-
assert(statusCode in supportedStatusCodes, supportedStatusCodesMessage);
|
|
49
|
-
|
|
50
|
-
const isServerError = statusCode > 499;
|
|
51
|
-
|
|
52
|
-
assert(
|
|
53
|
-
body === undefined || typeof body === 'object',
|
|
54
|
-
'body must be an object or omitted'
|
|
55
|
-
);
|
|
56
|
-
assert(
|
|
57
|
-
headers === undefined || typeof headers === 'object',
|
|
58
|
-
'headers must be an object or omitted'
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
message = message ?? supportedStatusCodes[ statusCode ];
|
|
62
|
-
|
|
63
|
-
assert(
|
|
64
|
-
!containsStackTrace(message) && !objectContainsStackTrace(body),
|
|
65
|
-
'the message or data parameters may not contain errors or stack traces'
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
super(message);
|
|
69
|
-
|
|
70
|
-
this.body = deepClone(body);
|
|
71
|
-
this.headers = deepClone(headers);
|
|
72
|
-
this.statusCode = statusCode;
|
|
73
|
-
this.isServerError = isServerError;
|
|
74
|
-
if (!this?.body?.message) {
|
|
75
|
-
this.body.message = this.message;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
static get supportedStatusCodes() { return supportedStatusCodes; }
|
|
81
|
-
static badRequest = (message?: string, body?: object, headers?: object[]) => { return new HttpError(400, message, body, headers); };
|
|
82
|
-
static unauthorized = (message?: string, body?: object, headers?: object[]) => new HttpError(401, message, body, headers);
|
|
83
|
-
static forbidden = (message?: string, body?: object, headers?: object[]) => new HttpError(403, message, body, headers);
|
|
84
|
-
static notFound = (message?: string, body?: object, headers?: object[]) => new HttpError(404, message, body, headers);
|
|
85
|
-
static internal = (message?: string, body?: object, headers?: object[]) => new HttpError(500, message, body, headers);
|
|
86
|
-
static notImplemented = () => new HttpError(501);
|
|
87
|
-
static badGateway = () => new HttpError(502);
|
|
88
|
-
static serviceUnavailable = (headers: object[]) => new HttpError(503, undefined, undefined, headers);
|
|
89
|
-
static gatewayTimeout = () => new HttpError(504);
|
|
90
|
-
}
|