@adtrackify/at-service-common 2.0.12 → 2.0.13
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/cjs/__tests__/helpers/subscription-helper.spec.d.ts +1 -1
- package/dist/cjs/__tests__/helpers/subscription-helper.spec.js +52 -52
- package/dist/cjs/__tests__/s3-client/s3-client.spec.d.ts +1 -1
- package/dist/cjs/__tests__/s3-client/s3-client.spec.js +26 -26
- package/dist/cjs/clients/generic/cognito-client.d.ts +19 -19
- package/dist/cjs/clients/generic/cognito-client.js +144 -144
- package/dist/cjs/clients/generic/dynamodb-client.d.ts +15 -15
- package/dist/cjs/clients/generic/dynamodb-client.js +124 -124
- package/dist/cjs/clients/generic/eventbridge-client.d.ts +14 -14
- package/dist/cjs/clients/generic/eventbridge-client.js +49 -49
- package/dist/cjs/clients/generic/http-client.d.ts +30 -30
- package/dist/cjs/clients/generic/http-client.js +35 -35
- package/dist/cjs/clients/generic/index.d.ts +6 -6
- package/dist/cjs/clients/generic/index.js +22 -22
- package/dist/cjs/clients/generic/s3-client.d.ts +14 -14
- package/dist/cjs/clients/generic/s3-client.js +82 -82
- package/dist/cjs/clients/generic/sqs-client.d.ts +14 -14
- package/dist/cjs/clients/generic/sqs-client.js +38 -38
- package/dist/cjs/clients/index.d.ts +3 -3
- package/dist/cjs/clients/index.js +19 -19
- package/dist/cjs/clients/internal-api/accounts-client.d.ts +82 -82
- package/dist/cjs/clients/internal-api/accounts-client.js +82 -82
- package/dist/cjs/clients/internal-api/destinations-client.d.ts +54 -54
- package/dist/cjs/clients/internal-api/destinations-client.js +40 -40
- package/dist/cjs/clients/internal-api/identity-client.d.ts +7 -7
- package/dist/cjs/clients/internal-api/identity-client.js +41 -41
- package/dist/cjs/clients/internal-api/index.d.ts +5 -5
- package/dist/cjs/clients/internal-api/index.js +21 -21
- package/dist/cjs/clients/internal-api/shopify-app-install-client.d.ts +57 -57
- package/dist/cjs/clients/internal-api/shopify-app-install-client.js +49 -49
- package/dist/cjs/clients/internal-api/users-auth-client.d.ts +61 -61
- package/dist/cjs/clients/internal-api/users-auth-client.js +77 -77
- package/dist/cjs/clients/third-party/index.d.ts +1 -1
- package/dist/cjs/clients/third-party/index.js +17 -17
- package/dist/cjs/clients/third-party/shopify-client.d.ts +90 -90
- package/dist/cjs/clients/third-party/shopify-client.js +125 -125
- package/dist/cjs/helpers/index.d.ts +5 -5
- package/dist/cjs/helpers/index.js +21 -21
- package/dist/cjs/helpers/input-validation-helper.d.ts +2 -2
- package/dist/cjs/helpers/input-validation-helper.js +22 -22
- package/dist/cjs/helpers/logging-helper.d.ts +15 -15
- package/dist/cjs/helpers/logging-helper.js +80 -80
- package/dist/cjs/helpers/response-helper.d.ts +36 -36
- package/dist/cjs/helpers/response-helper.js +41 -41
- package/dist/cjs/helpers/shopify-helper.d.ts +9 -9
- package/dist/cjs/helpers/shopify-helper.js +28 -28
- package/dist/cjs/helpers/subscription-helper.d.ts +8 -8
- package/dist/cjs/helpers/subscription-helper.js +104 -104
- package/dist/cjs/index.d.ts +5 -5
- package/dist/cjs/index.js +21 -21
- package/dist/cjs/libs/clickId-parser.d.ts +23 -18
- package/dist/cjs/libs/clickId-parser.js +49 -38
- package/dist/cjs/libs/clickId-parser.js.map +1 -1
- package/dist/cjs/libs/crypto.d.ts +1 -1
- package/dist/cjs/libs/crypto.js +12 -12
- package/dist/cjs/libs/dates.d.ts +3 -3
- package/dist/cjs/libs/dates.js +16 -16
- package/dist/cjs/libs/http-error.d.ts +21 -21
- package/dist/cjs/libs/http-error.js +59 -59
- package/dist/cjs/libs/http-status-codes.d.ts +58 -58
- package/dist/cjs/libs/http-status-codes.js +62 -62
- package/dist/cjs/libs/index.d.ts +8 -8
- package/dist/cjs/libs/index.js +24 -24
- package/dist/cjs/libs/referrer-parser/index.d.ts +2 -2
- package/dist/cjs/libs/referrer-parser/index.js +18 -18
- package/dist/cjs/libs/referrer-parser/referrer-data.d.ts +9 -9
- package/dist/cjs/libs/referrer-parser/referrer-data.js +4712 -4712
- package/dist/cjs/libs/referrer-parser/referrer-parser-util.d.ts +20 -20
- package/dist/cjs/libs/referrer-parser/referrer-parser-util.js +123 -123
- package/dist/cjs/libs/url.d.ts +1 -1
- package/dist/cjs/libs/url.js +13 -13
- package/dist/cjs/services/eventbridge-integration-service.d.ts +9 -9
- package/dist/cjs/services/eventbridge-integration-service.js +28 -28
- package/dist/cjs/services/index.d.ts +4 -4
- package/dist/cjs/services/index.js +20 -20
- package/dist/cjs/services/ipdata-lookup-service.d.ts +8 -8
- package/dist/cjs/services/ipdata-lookup-service.js +59 -59
- package/dist/cjs/services/log-event-service.d.ts +9 -9
- package/dist/cjs/services/log-event-service.js +50 -50
- package/dist/cjs/services/metric-event-service.d.ts +9 -9
- package/dist/cjs/services/metric-event-service.js +49 -49
- package/dist/cjs/types/api-response.d.ts +6 -6
- package/dist/cjs/types/api-response.js +2 -2
- package/dist/cjs/types/index.d.ts +1 -1
- package/dist/cjs/types/index.js +17 -17
- package/dist/cjs/types/internal-events/event-detail-types.d.ts +20 -20
- package/dist/cjs/types/internal-events/event-detail-types.js +27 -27
- package/dist/cjs/types/internal-events/index.d.ts +1 -1
- package/dist/cjs/types/internal-events/index.js +17 -17
- package/dist/esm/__tests__/helpers/subscription-helper.spec.d.ts +1 -1
- package/dist/esm/__tests__/helpers/subscription-helper.spec.js +27 -27
- package/dist/esm/__tests__/s3-client/s3-client.spec.d.ts +1 -1
- package/dist/esm/__tests__/s3-client/s3-client.spec.js +24 -24
- package/dist/esm/clients/generic/cognito-client.d.ts +19 -19
- package/dist/esm/clients/generic/cognito-client.js +139 -139
- package/dist/esm/clients/generic/dynamodb-client.d.ts +15 -15
- package/dist/esm/clients/generic/dynamodb-client.js +120 -120
- package/dist/esm/clients/generic/eventbridge-client.d.ts +14 -14
- package/dist/esm/clients/generic/eventbridge-client.js +45 -45
- package/dist/esm/clients/generic/http-client.d.ts +30 -30
- package/dist/esm/clients/generic/http-client.js +28 -28
- package/dist/esm/clients/generic/index.d.ts +6 -6
- package/dist/esm/clients/generic/index.js +6 -6
- package/dist/esm/clients/generic/s3-client.d.ts +14 -14
- package/dist/esm/clients/generic/s3-client.js +78 -78
- package/dist/esm/clients/generic/sqs-client.d.ts +14 -14
- package/dist/esm/clients/generic/sqs-client.js +34 -34
- package/dist/esm/clients/index.d.ts +3 -3
- package/dist/esm/clients/index.js +3 -3
- package/dist/esm/clients/internal-api/accounts-client.d.ts +82 -82
- package/dist/esm/clients/internal-api/accounts-client.js +78 -78
- package/dist/esm/clients/internal-api/destinations-client.d.ts +54 -54
- package/dist/esm/clients/internal-api/destinations-client.js +36 -36
- package/dist/esm/clients/internal-api/identity-client.d.ts +7 -7
- package/dist/esm/clients/internal-api/identity-client.js +37 -37
- package/dist/esm/clients/internal-api/index.d.ts +5 -5
- package/dist/esm/clients/internal-api/index.js +5 -5
- package/dist/esm/clients/internal-api/shopify-app-install-client.d.ts +57 -57
- package/dist/esm/clients/internal-api/shopify-app-install-client.js +42 -42
- package/dist/esm/clients/internal-api/users-auth-client.d.ts +61 -61
- package/dist/esm/clients/internal-api/users-auth-client.js +73 -73
- package/dist/esm/clients/third-party/index.d.ts +1 -1
- package/dist/esm/clients/third-party/index.js +1 -1
- package/dist/esm/clients/third-party/shopify-client.d.ts +90 -90
- package/dist/esm/clients/third-party/shopify-client.js +121 -121
- package/dist/esm/helpers/index.d.ts +5 -5
- package/dist/esm/helpers/index.js +5 -5
- package/dist/esm/helpers/input-validation-helper.d.ts +2 -2
- package/dist/esm/helpers/input-validation-helper.js +18 -18
- package/dist/esm/helpers/logging-helper.d.ts +15 -15
- package/dist/esm/helpers/logging-helper.js +53 -53
- package/dist/esm/helpers/response-helper.d.ts +36 -36
- package/dist/esm/helpers/response-helper.js +35 -35
- package/dist/esm/helpers/shopify-helper.d.ts +9 -9
- package/dist/esm/helpers/shopify-helper.js +23 -23
- package/dist/esm/helpers/subscription-helper.d.ts +8 -8
- package/dist/esm/helpers/subscription-helper.js +99 -99
- package/dist/esm/index.d.ts +5 -5
- package/dist/esm/index.js +5 -5
- package/dist/esm/libs/clickId-parser.d.ts +23 -18
- package/dist/esm/libs/clickId-parser.js +45 -34
- package/dist/esm/libs/clickId-parser.js.map +1 -1
- package/dist/esm/libs/crypto.d.ts +1 -1
- package/dist/esm/libs/crypto.js +5 -5
- package/dist/esm/libs/dates.d.ts +3 -3
- package/dist/esm/libs/dates.js +10 -10
- package/dist/esm/libs/http-error.d.ts +21 -21
- package/dist/esm/libs/http-error.js +55 -55
- package/dist/esm/libs/http-status-codes.d.ts +58 -58
- package/dist/esm/libs/http-status-codes.js +59 -59
- package/dist/esm/libs/index.d.ts +8 -8
- package/dist/esm/libs/index.js +8 -8
- package/dist/esm/libs/referrer-parser/index.d.ts +2 -2
- package/dist/esm/libs/referrer-parser/index.js +2 -2
- package/dist/esm/libs/referrer-parser/referrer-data.d.ts +9 -9
- package/dist/esm/libs/referrer-parser/referrer-data.js +4709 -4709
- package/dist/esm/libs/referrer-parser/referrer-parser-util.d.ts +20 -20
- package/dist/esm/libs/referrer-parser/referrer-parser-util.js +116 -116
- package/dist/esm/libs/url.d.ts +1 -1
- package/dist/esm/libs/url.js +9 -9
- package/dist/esm/services/eventbridge-integration-service.d.ts +9 -9
- package/dist/esm/services/eventbridge-integration-service.js +24 -24
- package/dist/esm/services/index.d.ts +4 -4
- package/dist/esm/services/index.js +4 -4
- package/dist/esm/services/ipdata-lookup-service.d.ts +8 -8
- package/dist/esm/services/ipdata-lookup-service.js +55 -55
- package/dist/esm/services/log-event-service.d.ts +9 -9
- package/dist/esm/services/log-event-service.js +46 -46
- package/dist/esm/services/metric-event-service.d.ts +9 -9
- package/dist/esm/services/metric-event-service.js +45 -45
- package/dist/esm/types/api-response.d.ts +6 -6
- package/dist/esm/types/api-response.js +1 -1
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/types/index.js +1 -1
- package/dist/esm/types/internal-events/event-detail-types.d.ts +20 -20
- package/dist/esm/types/internal-events/event-detail-types.js +24 -24
- package/dist/esm/types/internal-events/index.d.ts +1 -1
- package/dist/esm/types/internal-events/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { createHmac } from 'crypto';
|
|
2
|
-
import { Logger } from './logging-helper.js';
|
|
3
|
-
import { HttpError } from '../libs/http-error.js';
|
|
4
|
-
import { mapObjectToQueryString } from '../libs/url.js';
|
|
5
|
-
export const isShopifyRequestValid = (validationParams, validationHmac, shopifyAppApiSecret) => {
|
|
6
|
-
delete validationParams.hmac;
|
|
7
|
-
const hmacString = mapObjectToQueryString(validationParams);
|
|
8
|
-
const generatedHash = createHmac('sha256', shopifyAppApiSecret)
|
|
9
|
-
.update(hmacString)
|
|
10
|
-
.digest('hex');
|
|
11
|
-
return generatedHash === validationHmac;
|
|
12
|
-
};
|
|
13
|
-
export const validateShopifyRequest = (validationParams, validationHmac, shopifyAppApiSecret) => {
|
|
14
|
-
Logger.info('Validating shopify request is authentic', { validationParams });
|
|
15
|
-
const isValid = isShopifyRequestValid(validationParams, validationHmac, shopifyAppApiSecret);
|
|
16
|
-
if (!isValid) {
|
|
17
|
-
const message = 'Failed: Shopify Request hmac validation';
|
|
18
|
-
Logger.error(message);
|
|
19
|
-
throw HttpError.badRequest(message);
|
|
20
|
-
}
|
|
21
|
-
Logger.info('Sucess: Shopify Request hmac validation');
|
|
22
|
-
return true;
|
|
23
|
-
};
|
|
1
|
+
import { createHmac } from 'crypto';
|
|
2
|
+
import { Logger } from './logging-helper.js';
|
|
3
|
+
import { HttpError } from '../libs/http-error.js';
|
|
4
|
+
import { mapObjectToQueryString } from '../libs/url.js';
|
|
5
|
+
export const isShopifyRequestValid = (validationParams, validationHmac, shopifyAppApiSecret) => {
|
|
6
|
+
delete validationParams.hmac;
|
|
7
|
+
const hmacString = mapObjectToQueryString(validationParams);
|
|
8
|
+
const generatedHash = createHmac('sha256', shopifyAppApiSecret)
|
|
9
|
+
.update(hmacString)
|
|
10
|
+
.digest('hex');
|
|
11
|
+
return generatedHash === validationHmac;
|
|
12
|
+
};
|
|
13
|
+
export const validateShopifyRequest = (validationParams, validationHmac, shopifyAppApiSecret) => {
|
|
14
|
+
Logger.info('Validating shopify request is authentic', { validationParams });
|
|
15
|
+
const isValid = isShopifyRequestValid(validationParams, validationHmac, shopifyAppApiSecret);
|
|
16
|
+
if (!isValid) {
|
|
17
|
+
const message = 'Failed: Shopify Request hmac validation';
|
|
18
|
+
Logger.error(message);
|
|
19
|
+
throw HttpError.badRequest(message);
|
|
20
|
+
}
|
|
21
|
+
Logger.info('Sucess: Shopify Request hmac validation');
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
24
|
//# sourceMappingURL=shopify-helper.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { SubscriptionPlan } from '@adtrackify/at-tracking-event-types';
|
|
2
|
-
export declare const StripeBillingMap: any;
|
|
3
|
-
export declare const CommonPlanInfo: string[];
|
|
4
|
-
export declare const SubscriptionPlanSeedItems: {
|
|
5
|
-
items: SubscriptionPlan[];
|
|
6
|
-
};
|
|
7
|
-
export declare const getPlanDetails: (planId: number, stage: string) => SubscriptionPlan;
|
|
8
|
-
export declare const getPlanByStripePriceId: (stripePriceId: string, stage: string) => SubscriptionPlan;
|
|
1
|
+
import { SubscriptionPlan } from '@adtrackify/at-tracking-event-types';
|
|
2
|
+
export declare const StripeBillingMap: any;
|
|
3
|
+
export declare const CommonPlanInfo: string[];
|
|
4
|
+
export declare const SubscriptionPlanSeedItems: {
|
|
5
|
+
items: SubscriptionPlan[];
|
|
6
|
+
};
|
|
7
|
+
export declare const getPlanDetails: (planId: number, stage: string) => SubscriptionPlan;
|
|
8
|
+
export declare const getPlanByStripePriceId: (stripePriceId: string, stage: string) => SubscriptionPlan;
|
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
import { PLAN_BILLING_FREQUENCY } from '@adtrackify/at-tracking-event-types';
|
|
2
|
-
export const StripeBillingMap = {
|
|
3
|
-
dev2: {
|
|
4
|
-
'free': 'price_1JzjbKK7krGh4037ezNbGJEm',
|
|
5
|
-
'starter_monthly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
6
|
-
'starter_yearly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
7
|
-
'scale_monthly': 'price_1JzjcSK7krGh4037yh34LPk3',
|
|
8
|
-
'scale_yearly': 'price_1JzjcSK7krGh4037QiBJYfnD',
|
|
9
|
-
'growth_monthly': 'price_1Jzje1K7krGh4037KErHBp5N',
|
|
10
|
-
'growth_yearly': 'price_1Jzje1K7krGh4037MhCUhTDh'
|
|
11
|
-
},
|
|
12
|
-
qa2: {
|
|
13
|
-
'free': 'price_1JzjbKK7krGh4037ezNbGJEm',
|
|
14
|
-
'starter_monthly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
15
|
-
'starter_yearly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
16
|
-
'scale_monthly': 'price_1JzjcSK7krGh4037yh34LPk3',
|
|
17
|
-
'scale_yearly': 'price_1JzjcSK7krGh4037QiBJYfnD',
|
|
18
|
-
'growth_monthly': 'price_1Jzje1K7krGh4037KErHBp5N',
|
|
19
|
-
'growth_yearly': 'price_1Jzje1K7krGh4037MhCUhTDh'
|
|
20
|
-
},
|
|
21
|
-
prod2: {
|
|
22
|
-
'free': 'price_1KAFsIK7krGh4037RsaAYMEl',
|
|
23
|
-
'starter_monthly': 'price_1KAFsMK7krGh4037Lz3P0ksU',
|
|
24
|
-
'starter_yearly': 'price_1KAFsMK7krGh4037Dj1WmSi8',
|
|
25
|
-
'scale_monthly': 'price_1KAFrxK7krGh4037zWCdaTly',
|
|
26
|
-
'scale_yearly': 'price_1KAFrxK7krGh40375fhymyWP',
|
|
27
|
-
'growth_monthly': 'price_1KAFs7K7krGh4037JChjz5Cr',
|
|
28
|
-
'growth_yearly': 'price_1KAFs7K7krGh4037rZElg12s'
|
|
29
|
-
},
|
|
30
|
-
dev: {
|
|
31
|
-
'free': 'price_1JzjbKK7krGh4037ezNbGJEm',
|
|
32
|
-
'starter_monthly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
33
|
-
'starter_yearly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
34
|
-
'scale_monthly': 'price_1JzjcSK7krGh4037yh34LPk3',
|
|
35
|
-
'scale_yearly': 'price_1JzjcSK7krGh4037QiBJYfnD',
|
|
36
|
-
'growth_monthly': 'price_1Jzje1K7krGh4037KErHBp5N',
|
|
37
|
-
'growth_yearly': 'price_1Jzje1K7krGh4037MhCUhTDh'
|
|
38
|
-
},
|
|
39
|
-
qa: {
|
|
40
|
-
'free': 'price_1JzjbKK7krGh4037ezNbGJEm',
|
|
41
|
-
'starter_monthly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
42
|
-
'starter_yearly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
43
|
-
'scale_monthly': 'price_1JzjcSK7krGh4037yh34LPk3',
|
|
44
|
-
'scale_yearly': 'price_1JzjcSK7krGh4037QiBJYfnD',
|
|
45
|
-
'growth_monthly': 'price_1Jzje1K7krGh4037KErHBp5N',
|
|
46
|
-
'growth_yearly': 'price_1Jzje1K7krGh4037MhCUhTDh'
|
|
47
|
-
},
|
|
48
|
-
prod: {
|
|
49
|
-
'free': 'price_1KAFsIK7krGh4037RsaAYMEl',
|
|
50
|
-
'starter_monthly': 'price_1KAFsMK7krGh4037Lz3P0ksU',
|
|
51
|
-
'starter_yearly': 'price_1KAFsMK7krGh4037Dj1WmSi8',
|
|
52
|
-
'scale_monthly': 'price_1KAFrxK7krGh4037zWCdaTly',
|
|
53
|
-
'scale_yearly': 'price_1KAFrxK7krGh40375fhymyWP',
|
|
54
|
-
'growth_monthly': 'price_1KAFs7K7krGh4037JChjz5Cr',
|
|
55
|
-
'growth_yearly': 'price_1KAFs7K7krGh4037rZElg12s'
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
export const CommonPlanInfo = [
|
|
59
|
-
'Free Server Side Tracking & Conversion API',
|
|
60
|
-
'MultiPixel Support (Multiple facebook, tiktok, etc)',
|
|
61
|
-
'Corrects Facebook Conversion Tracking post IOS14',
|
|
62
|
-
'Increase ROAS & Attribution Data',
|
|
63
|
-
'Enhanced Fingerprinting & Identity Resolution',
|
|
64
|
-
'Unlimited Integrations',
|
|
65
|
-
'Advanced Integrations (Webhooks, Custom JS/HTML, Hubspot)'
|
|
66
|
-
];
|
|
67
|
-
export const SubscriptionPlanSeedItems = {
|
|
68
|
-
items: [{
|
|
69
|
-
id: 1,
|
|
70
|
-
planName: 'free',
|
|
71
|
-
displayName: 'Free',
|
|
72
|
-
sku: 'ADT-001',
|
|
73
|
-
description: 'Free Plan - Monthly',
|
|
74
|
-
price: '0',
|
|
75
|
-
displayPrice: '$0',
|
|
76
|
-
billingFrequency: PLAN_BILLING_FREQUENCY.MONTHLY,
|
|
77
|
-
trialLengthDays: 0,
|
|
78
|
-
trialRequiresCreditCard: false,
|
|
79
|
-
planDesc: [
|
|
80
|
-
...CommonPlanInfo,
|
|
81
|
-
],
|
|
82
|
-
unitPriceText: 'try now - free plan',
|
|
83
|
-
isHighlighted: false,
|
|
84
|
-
isBanner: false
|
|
85
|
-
},
|
|
86
|
-
]
|
|
87
|
-
};
|
|
88
|
-
export const getPlanDetails = (planId, stage) => {
|
|
89
|
-
const plan = SubscriptionPlanSeedItems.items.filter(x => x.id === planId)[0];
|
|
90
|
-
plan.stripePriceId = StripeBillingMap[stage][plan.planName];
|
|
91
|
-
return plan;
|
|
92
|
-
};
|
|
93
|
-
export const getPlanByStripePriceId = (stripePriceId, stage) => {
|
|
94
|
-
const stripePriceIds = StripeBillingMap[stage];
|
|
95
|
-
const planName = Object.keys(stripePriceIds).find(key => stripePriceIds[key] === stripePriceId);
|
|
96
|
-
const plan = SubscriptionPlanSeedItems.items.filter(x => x.planName === planName)[0];
|
|
97
|
-
plan.stripePriceId = stripePriceId;
|
|
98
|
-
return plan;
|
|
99
|
-
};
|
|
1
|
+
import { PLAN_BILLING_FREQUENCY } from '@adtrackify/at-tracking-event-types';
|
|
2
|
+
export const StripeBillingMap = {
|
|
3
|
+
dev2: {
|
|
4
|
+
'free': 'price_1JzjbKK7krGh4037ezNbGJEm',
|
|
5
|
+
'starter_monthly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
6
|
+
'starter_yearly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
7
|
+
'scale_monthly': 'price_1JzjcSK7krGh4037yh34LPk3',
|
|
8
|
+
'scale_yearly': 'price_1JzjcSK7krGh4037QiBJYfnD',
|
|
9
|
+
'growth_monthly': 'price_1Jzje1K7krGh4037KErHBp5N',
|
|
10
|
+
'growth_yearly': 'price_1Jzje1K7krGh4037MhCUhTDh'
|
|
11
|
+
},
|
|
12
|
+
qa2: {
|
|
13
|
+
'free': 'price_1JzjbKK7krGh4037ezNbGJEm',
|
|
14
|
+
'starter_monthly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
15
|
+
'starter_yearly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
16
|
+
'scale_monthly': 'price_1JzjcSK7krGh4037yh34LPk3',
|
|
17
|
+
'scale_yearly': 'price_1JzjcSK7krGh4037QiBJYfnD',
|
|
18
|
+
'growth_monthly': 'price_1Jzje1K7krGh4037KErHBp5N',
|
|
19
|
+
'growth_yearly': 'price_1Jzje1K7krGh4037MhCUhTDh'
|
|
20
|
+
},
|
|
21
|
+
prod2: {
|
|
22
|
+
'free': 'price_1KAFsIK7krGh4037RsaAYMEl',
|
|
23
|
+
'starter_monthly': 'price_1KAFsMK7krGh4037Lz3P0ksU',
|
|
24
|
+
'starter_yearly': 'price_1KAFsMK7krGh4037Dj1WmSi8',
|
|
25
|
+
'scale_monthly': 'price_1KAFrxK7krGh4037zWCdaTly',
|
|
26
|
+
'scale_yearly': 'price_1KAFrxK7krGh40375fhymyWP',
|
|
27
|
+
'growth_monthly': 'price_1KAFs7K7krGh4037JChjz5Cr',
|
|
28
|
+
'growth_yearly': 'price_1KAFs7K7krGh4037rZElg12s'
|
|
29
|
+
},
|
|
30
|
+
dev: {
|
|
31
|
+
'free': 'price_1JzjbKK7krGh4037ezNbGJEm',
|
|
32
|
+
'starter_monthly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
33
|
+
'starter_yearly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
34
|
+
'scale_monthly': 'price_1JzjcSK7krGh4037yh34LPk3',
|
|
35
|
+
'scale_yearly': 'price_1JzjcSK7krGh4037QiBJYfnD',
|
|
36
|
+
'growth_monthly': 'price_1Jzje1K7krGh4037KErHBp5N',
|
|
37
|
+
'growth_yearly': 'price_1Jzje1K7krGh4037MhCUhTDh'
|
|
38
|
+
},
|
|
39
|
+
qa: {
|
|
40
|
+
'free': 'price_1JzjbKK7krGh4037ezNbGJEm',
|
|
41
|
+
'starter_monthly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
42
|
+
'starter_yearly': 'price_1JwzsGK7krGh4037Li0hPpsZ',
|
|
43
|
+
'scale_monthly': 'price_1JzjcSK7krGh4037yh34LPk3',
|
|
44
|
+
'scale_yearly': 'price_1JzjcSK7krGh4037QiBJYfnD',
|
|
45
|
+
'growth_monthly': 'price_1Jzje1K7krGh4037KErHBp5N',
|
|
46
|
+
'growth_yearly': 'price_1Jzje1K7krGh4037MhCUhTDh'
|
|
47
|
+
},
|
|
48
|
+
prod: {
|
|
49
|
+
'free': 'price_1KAFsIK7krGh4037RsaAYMEl',
|
|
50
|
+
'starter_monthly': 'price_1KAFsMK7krGh4037Lz3P0ksU',
|
|
51
|
+
'starter_yearly': 'price_1KAFsMK7krGh4037Dj1WmSi8',
|
|
52
|
+
'scale_monthly': 'price_1KAFrxK7krGh4037zWCdaTly',
|
|
53
|
+
'scale_yearly': 'price_1KAFrxK7krGh40375fhymyWP',
|
|
54
|
+
'growth_monthly': 'price_1KAFs7K7krGh4037JChjz5Cr',
|
|
55
|
+
'growth_yearly': 'price_1KAFs7K7krGh4037rZElg12s'
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
export const CommonPlanInfo = [
|
|
59
|
+
'Free Server Side Tracking & Conversion API',
|
|
60
|
+
'MultiPixel Support (Multiple facebook, tiktok, etc)',
|
|
61
|
+
'Corrects Facebook Conversion Tracking post IOS14',
|
|
62
|
+
'Increase ROAS & Attribution Data',
|
|
63
|
+
'Enhanced Fingerprinting & Identity Resolution',
|
|
64
|
+
'Unlimited Integrations',
|
|
65
|
+
'Advanced Integrations (Webhooks, Custom JS/HTML, Hubspot)'
|
|
66
|
+
];
|
|
67
|
+
export const SubscriptionPlanSeedItems = {
|
|
68
|
+
items: [{
|
|
69
|
+
id: 1,
|
|
70
|
+
planName: 'free',
|
|
71
|
+
displayName: 'Free',
|
|
72
|
+
sku: 'ADT-001',
|
|
73
|
+
description: 'Free Plan - Monthly',
|
|
74
|
+
price: '0',
|
|
75
|
+
displayPrice: '$0',
|
|
76
|
+
billingFrequency: PLAN_BILLING_FREQUENCY.MONTHLY,
|
|
77
|
+
trialLengthDays: 0,
|
|
78
|
+
trialRequiresCreditCard: false,
|
|
79
|
+
planDesc: [
|
|
80
|
+
...CommonPlanInfo,
|
|
81
|
+
],
|
|
82
|
+
unitPriceText: 'try now - free plan',
|
|
83
|
+
isHighlighted: false,
|
|
84
|
+
isBanner: false
|
|
85
|
+
},
|
|
86
|
+
]
|
|
87
|
+
};
|
|
88
|
+
export const getPlanDetails = (planId, stage) => {
|
|
89
|
+
const plan = SubscriptionPlanSeedItems.items.filter(x => x.id === planId)[0];
|
|
90
|
+
plan.stripePriceId = StripeBillingMap[stage][plan.planName];
|
|
91
|
+
return plan;
|
|
92
|
+
};
|
|
93
|
+
export const getPlanByStripePriceId = (stripePriceId, stage) => {
|
|
94
|
+
const stripePriceIds = StripeBillingMap[stage];
|
|
95
|
+
const planName = Object.keys(stripePriceIds).find(key => stripePriceIds[key] === stripePriceId);
|
|
96
|
+
const plan = SubscriptionPlanSeedItems.items.filter(x => x.planName === planName)[0];
|
|
97
|
+
plan.stripePriceId = stripePriceId;
|
|
98
|
+
return plan;
|
|
99
|
+
};
|
|
100
100
|
//# sourceMappingURL=subscription-helper.js.map
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './clients/index.js';
|
|
2
|
-
export * from './helpers/index.js';
|
|
3
|
-
export * from './libs/index.js';
|
|
4
|
-
export * from './types/index.js';
|
|
5
|
-
export * from './services/index.js';
|
|
1
|
+
export * from './clients/index.js';
|
|
2
|
+
export * from './helpers/index.js';
|
|
3
|
+
export * from './libs/index.js';
|
|
4
|
+
export * from './types/index.js';
|
|
5
|
+
export * from './services/index.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './clients/index.js';
|
|
2
|
-
export * from './helpers/index.js';
|
|
3
|
-
export * from './libs/index.js';
|
|
4
|
-
export * from './types/index.js';
|
|
5
|
-
export * from './services/index.js';
|
|
1
|
+
export * from './clients/index.js';
|
|
2
|
+
export * from './helpers/index.js';
|
|
3
|
+
export * from './libs/index.js';
|
|
4
|
+
export * from './types/index.js';
|
|
5
|
+
export * from './services/index.js';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
export
|
|
15
|
-
mktClickParam
|
|
16
|
-
mktClickId
|
|
17
|
-
|
|
18
|
-
}
|
|
1
|
+
export declare enum CLICK_NETWORK {
|
|
2
|
+
GOOGLE = "Google",
|
|
3
|
+
FACEBOOK = "Facebook",
|
|
4
|
+
TIKTOK = "TikTok",
|
|
5
|
+
TWITTER = "Twitter",
|
|
6
|
+
SNAPCHAT = "Snapchat",
|
|
7
|
+
TABOOLA = "Taboola",
|
|
8
|
+
OUTBRAIN = "Outbrain",
|
|
9
|
+
MICROSOFT = "Microsoft"
|
|
10
|
+
}
|
|
11
|
+
export declare const ClickIdDictionary: {
|
|
12
|
+
[key: string]: CLICK_NETWORK;
|
|
13
|
+
};
|
|
14
|
+
export interface ParsedClickId {
|
|
15
|
+
mktClickParam?: string;
|
|
16
|
+
mktClickId?: string;
|
|
17
|
+
mkyClickNetwork?: CLICK_NETWORK;
|
|
18
|
+
}
|
|
19
|
+
export declare const parseClickId: (qsp: URLSearchParams) => {
|
|
20
|
+
mktClickParam: string;
|
|
21
|
+
mktClickId: string | null;
|
|
22
|
+
mktClickNetwork: CLICK_NETWORK;
|
|
23
|
+
} | undefined;
|
|
@@ -1,35 +1,46 @@
|
|
|
1
|
-
import { isEmpty } from '@adtrackify/at-shared-utils';
|
|
2
|
-
import { Logger } from '../helpers';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
import { isEmpty } from '@adtrackify/at-shared-utils';
|
|
2
|
+
import { Logger } from '../helpers';
|
|
3
|
+
export var CLICK_NETWORK;
|
|
4
|
+
(function (CLICK_NETWORK) {
|
|
5
|
+
CLICK_NETWORK["GOOGLE"] = "Google";
|
|
6
|
+
CLICK_NETWORK["FACEBOOK"] = "Facebook";
|
|
7
|
+
CLICK_NETWORK["TIKTOK"] = "TikTok";
|
|
8
|
+
CLICK_NETWORK["TWITTER"] = "Twitter";
|
|
9
|
+
CLICK_NETWORK["SNAPCHAT"] = "Snapchat";
|
|
10
|
+
CLICK_NETWORK["TABOOLA"] = "Taboola";
|
|
11
|
+
CLICK_NETWORK["OUTBRAIN"] = "Outbrain";
|
|
12
|
+
CLICK_NETWORK["MICROSOFT"] = "Microsoft";
|
|
13
|
+
})(CLICK_NETWORK || (CLICK_NETWORK = {}));
|
|
14
|
+
export const ClickIdDictionary = {
|
|
15
|
+
'gclid': CLICK_NETWORK.GOOGLE,
|
|
16
|
+
'dclid': CLICK_NETWORK.GOOGLE,
|
|
17
|
+
'gbraid': CLICK_NETWORK.GOOGLE,
|
|
18
|
+
'wbraid': CLICK_NETWORK.GOOGLE,
|
|
19
|
+
'fbclid': CLICK_NETWORK.FACEBOOK,
|
|
20
|
+
'ttclid': CLICK_NETWORK.TIKTOK,
|
|
21
|
+
'twclid': CLICK_NETWORK.TWITTER,
|
|
22
|
+
'sccid': CLICK_NETWORK.SNAPCHAT,
|
|
23
|
+
'taboola_click_id': CLICK_NETWORK.TABOOLA,
|
|
24
|
+
'ob_click_id': CLICK_NETWORK.OUTBRAIN,
|
|
25
|
+
'microsoftclickid': CLICK_NETWORK.MICROSOFT,
|
|
26
|
+
};
|
|
27
|
+
export const parseClickId = (qsp) => {
|
|
28
|
+
try {
|
|
29
|
+
if (!isEmpty(qsp)) {
|
|
30
|
+
for (const item of Object.entries(ClickIdDictionary)) {
|
|
31
|
+
if (qsp.has(item?.[0])) {
|
|
32
|
+
return {
|
|
33
|
+
mktClickParam: item[0],
|
|
34
|
+
mktClickId: qsp.get(item[0]),
|
|
35
|
+
mktClickNetwork: item[1]
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
Logger.warn('Unable to parse click ID', { error });
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
35
46
|
//# sourceMappingURL=clickId-parser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clickId-parser.js","sourceRoot":"","sources":["../../../src/libs/clickId-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,MAAM,CAAC,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"clickId-parser.js","sourceRoot":"","sources":["../../../src/libs/clickId-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,MAAM,CAAN,IAAY,aASX;AATD,WAAY,aAAa;IACvB,kCAAiB,CAAA;IACjB,sCAAqB,CAAA;IACrB,kCAAiB,CAAA;IACjB,oCAAmB,CAAA;IACnB,sCAAqB,CAAA;IACrB,oCAAmB,CAAA;IACnB,sCAAqB,CAAA;IACrB,wCAAuB,CAAA;AACzB,CAAC,EATW,aAAa,KAAb,aAAa,QASxB;AAED,MAAM,CAAC,MAAM,iBAAiB,GAE1B;IACF,OAAO,EAAE,aAAa,CAAC,MAAM;IAC7B,OAAO,EAAE,aAAa,CAAC,MAAM;IAC7B,QAAQ,EAAE,aAAa,CAAC,MAAM;IAC9B,QAAQ,EAAE,aAAa,CAAC,MAAM;IAC9B,QAAQ,EAAE,aAAa,CAAC,QAAQ;IAChC,QAAQ,EAAE,aAAa,CAAC,MAAM;IAC9B,QAAQ,EAAE,aAAa,CAAC,OAAO;IAC/B,OAAO,EAAE,aAAa,CAAC,QAAQ;IAC/B,kBAAkB,EAAE,aAAa,CAAC,OAAO;IACzC,aAAa,EAAE,aAAa,CAAC,QAAQ;IACrC,kBAAkB,EAAE,aAAa,CAAC,SAAS;CAC5C,CAAC;AASF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAoB,EAAE,EAAE;IACnD,IAAI;QACF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACjB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE;gBACpD,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE;oBACtB,OAAO;wBACL,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC;wBACtB,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;wBAC5B,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC;qBACzB,CAAC;iBACH;aACF;SACF;KACF;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QAClD,OAAO,SAAS,CAAA;KACjB;AACH,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const generatePublicKey: () => string;
|
|
1
|
+
export declare const generatePublicKey: () => string;
|
package/dist/esm/libs/crypto.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
export const generatePublicKey = () => {
|
|
3
|
-
const publicKey = crypto.randomBytes(26);
|
|
4
|
-
return publicKey.toString('utf8');
|
|
5
|
-
};
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
export const generatePublicKey = () => {
|
|
3
|
+
const publicKey = crypto.randomBytes(26);
|
|
4
|
+
return publicKey.toString('utf8');
|
|
5
|
+
};
|
|
6
6
|
//# sourceMappingURL=crypto.js.map
|
package/dist/esm/libs/dates.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const getCurrentTimestamp: () => string;
|
|
2
|
-
export declare const getDateFromTimestamp: (timestamp: string) => string;
|
|
3
|
-
export declare const getCurrentDate: () => string;
|
|
1
|
+
export declare const getCurrentTimestamp: () => string;
|
|
2
|
+
export declare const getDateFromTimestamp: (timestamp: string) => string;
|
|
3
|
+
export declare const getCurrentDate: () => string;
|
package/dist/esm/libs/dates.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { DateTime } from 'luxon';
|
|
2
|
-
export const getCurrentTimestamp = () => {
|
|
3
|
-
return DateTime.utc().toJSDate().toISOString();
|
|
4
|
-
};
|
|
5
|
-
export const getDateFromTimestamp = (timestamp) => {
|
|
6
|
-
return timestamp.split('T')[0];
|
|
7
|
-
};
|
|
8
|
-
export const getCurrentDate = () => {
|
|
9
|
-
return getDateFromTimestamp(getCurrentTimestamp());
|
|
10
|
-
};
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
export const getCurrentTimestamp = () => {
|
|
3
|
+
return DateTime.utc().toJSDate().toISOString();
|
|
4
|
+
};
|
|
5
|
+
export const getDateFromTimestamp = (timestamp) => {
|
|
6
|
+
return timestamp.split('T')[0];
|
|
7
|
+
};
|
|
8
|
+
export const getCurrentDate = () => {
|
|
9
|
+
return getDateFromTimestamp(getCurrentTimestamp());
|
|
10
|
+
};
|
|
11
11
|
//# sourceMappingURL=dates.js.map
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
export declare class HttpError extends Error {
|
|
2
|
-
body: {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
};
|
|
5
|
-
headers: object[];
|
|
6
|
-
statusCode: number;
|
|
7
|
-
isServerError: boolean;
|
|
8
|
-
constructor(statusCode: number, message?: string, body?: {
|
|
9
|
-
[key: string]: any;
|
|
10
|
-
}, headers?: object[]);
|
|
11
|
-
static get supportedStatusCodes(): any;
|
|
12
|
-
static badRequest: (message?: string, body?: object, headers?: object[]) => HttpError;
|
|
13
|
-
static unauthorized: (message?: string, body?: object, headers?: object[]) => HttpError;
|
|
14
|
-
static forbidden: (message?: string, body?: object, headers?: object[]) => HttpError;
|
|
15
|
-
static notFound: (message?: string, body?: object, headers?: object[]) => HttpError;
|
|
16
|
-
static internal: (message?: string, body?: object, headers?: object[]) => HttpError;
|
|
17
|
-
static notImplemented: () => HttpError;
|
|
18
|
-
static badGateway: () => HttpError;
|
|
19
|
-
static serviceUnavailable: (headers: object[]) => HttpError;
|
|
20
|
-
static gatewayTimeout: () => HttpError;
|
|
21
|
-
}
|
|
1
|
+
export declare class HttpError extends Error {
|
|
2
|
+
body: {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
};
|
|
5
|
+
headers: object[];
|
|
6
|
+
statusCode: number;
|
|
7
|
+
isServerError: boolean;
|
|
8
|
+
constructor(statusCode: number, message?: string, body?: {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}, headers?: object[]);
|
|
11
|
+
static get supportedStatusCodes(): any;
|
|
12
|
+
static badRequest: (message?: string, body?: object, headers?: object[]) => HttpError;
|
|
13
|
+
static unauthorized: (message?: string, body?: object, headers?: object[]) => HttpError;
|
|
14
|
+
static forbidden: (message?: string, body?: object, headers?: object[]) => HttpError;
|
|
15
|
+
static notFound: (message?: string, body?: object, headers?: object[]) => HttpError;
|
|
16
|
+
static internal: (message?: string, body?: object, headers?: object[]) => HttpError;
|
|
17
|
+
static notImplemented: () => HttpError;
|
|
18
|
+
static badGateway: () => HttpError;
|
|
19
|
+
static serviceUnavailable: (headers: object[]) => HttpError;
|
|
20
|
+
static gatewayTimeout: () => HttpError;
|
|
21
|
+
}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { strict as assert } from 'assert';
|
|
2
|
-
const deepClone = (o = {}) => JSON.parse(JSON.stringify(o));
|
|
3
|
-
const containsStackTrace = (text = '') => /at.+\.js:\d+:\d+/.test(text);
|
|
4
|
-
const objectContainsStackTrace = (obj) => !obj ? false : containsStackTrace(JSON.stringify(obj));
|
|
5
|
-
const supportedStatusCodes = {
|
|
6
|
-
400: 'Bad Request',
|
|
7
|
-
401: 'Unauthorized',
|
|
8
|
-
403: 'Forbidden',
|
|
9
|
-
404: 'Not Found',
|
|
10
|
-
405: 'Method Not Allowed',
|
|
11
|
-
409: 'Conflict',
|
|
12
|
-
412: 'Precondition Failed',
|
|
13
|
-
413: 'Payload Too Large',
|
|
14
|
-
415: 'Unsupported Media Type',
|
|
15
|
-
428: 'Precondition Required',
|
|
16
|
-
429: 'Too Many Requests',
|
|
17
|
-
500: 'Internal Server Error',
|
|
18
|
-
501: 'Not Implemented',
|
|
19
|
-
502: 'Bad Gateway',
|
|
20
|
-
503: 'Service Unavailable',
|
|
21
|
-
504: 'Gateway Timeout'
|
|
22
|
-
};
|
|
23
|
-
const supportedStatusCodesMessage = `statusCode must be one of the following: ${JSON.stringify(Object.keys(supportedStatusCodes))}`;
|
|
24
|
-
export class HttpError extends Error {
|
|
25
|
-
body;
|
|
26
|
-
headers;
|
|
27
|
-
statusCode;
|
|
28
|
-
isServerError;
|
|
29
|
-
constructor(statusCode, message, body, headers) {
|
|
30
|
-
assert(statusCode in supportedStatusCodes, supportedStatusCodesMessage);
|
|
31
|
-
const isServerError = statusCode > 499;
|
|
32
|
-
assert(body === undefined || typeof body === 'object', 'body must be an object or omitted');
|
|
33
|
-
assert(headers === undefined || typeof headers === 'object', 'headers must be an object or omitted');
|
|
34
|
-
message = message ?? supportedStatusCodes[statusCode];
|
|
35
|
-
assert(!containsStackTrace(message) && !objectContainsStackTrace(body), 'the message or data parameters may not contain errors or stack traces');
|
|
36
|
-
super(message);
|
|
37
|
-
this.body = deepClone(body);
|
|
38
|
-
this.headers = deepClone(headers);
|
|
39
|
-
this.statusCode = statusCode;
|
|
40
|
-
this.isServerError = isServerError;
|
|
41
|
-
if (!this?.body?.message) {
|
|
42
|
-
this.body.message = this.message;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
static get supportedStatusCodes() { return supportedStatusCodes; }
|
|
46
|
-
static badRequest = (message, body, headers) => { return new HttpError(400, message, body, headers); };
|
|
47
|
-
static unauthorized = (message, body, headers) => new HttpError(401, message, body, headers);
|
|
48
|
-
static forbidden = (message, body, headers) => new HttpError(403, message, body, headers);
|
|
49
|
-
static notFound = (message, body, headers) => new HttpError(404, message, body, headers);
|
|
50
|
-
static internal = (message, body, headers) => new HttpError(500, message, body, headers);
|
|
51
|
-
static notImplemented = () => new HttpError(501);
|
|
52
|
-
static badGateway = () => new HttpError(502);
|
|
53
|
-
static serviceUnavailable = (headers) => new HttpError(503, undefined, undefined, headers);
|
|
54
|
-
static gatewayTimeout = () => new HttpError(504);
|
|
55
|
-
}
|
|
1
|
+
import { strict as assert } from 'assert';
|
|
2
|
+
const deepClone = (o = {}) => JSON.parse(JSON.stringify(o));
|
|
3
|
+
const containsStackTrace = (text = '') => /at.+\.js:\d+:\d+/.test(text);
|
|
4
|
+
const objectContainsStackTrace = (obj) => !obj ? false : containsStackTrace(JSON.stringify(obj));
|
|
5
|
+
const supportedStatusCodes = {
|
|
6
|
+
400: 'Bad Request',
|
|
7
|
+
401: 'Unauthorized',
|
|
8
|
+
403: 'Forbidden',
|
|
9
|
+
404: 'Not Found',
|
|
10
|
+
405: 'Method Not Allowed',
|
|
11
|
+
409: 'Conflict',
|
|
12
|
+
412: 'Precondition Failed',
|
|
13
|
+
413: 'Payload Too Large',
|
|
14
|
+
415: 'Unsupported Media Type',
|
|
15
|
+
428: 'Precondition Required',
|
|
16
|
+
429: 'Too Many Requests',
|
|
17
|
+
500: 'Internal Server Error',
|
|
18
|
+
501: 'Not Implemented',
|
|
19
|
+
502: 'Bad Gateway',
|
|
20
|
+
503: 'Service Unavailable',
|
|
21
|
+
504: 'Gateway Timeout'
|
|
22
|
+
};
|
|
23
|
+
const supportedStatusCodesMessage = `statusCode must be one of the following: ${JSON.stringify(Object.keys(supportedStatusCodes))}`;
|
|
24
|
+
export class HttpError extends Error {
|
|
25
|
+
body;
|
|
26
|
+
headers;
|
|
27
|
+
statusCode;
|
|
28
|
+
isServerError;
|
|
29
|
+
constructor(statusCode, message, body, headers) {
|
|
30
|
+
assert(statusCode in supportedStatusCodes, supportedStatusCodesMessage);
|
|
31
|
+
const isServerError = statusCode > 499;
|
|
32
|
+
assert(body === undefined || typeof body === 'object', 'body must be an object or omitted');
|
|
33
|
+
assert(headers === undefined || typeof headers === 'object', 'headers must be an object or omitted');
|
|
34
|
+
message = message ?? supportedStatusCodes[statusCode];
|
|
35
|
+
assert(!containsStackTrace(message) && !objectContainsStackTrace(body), 'the message or data parameters may not contain errors or stack traces');
|
|
36
|
+
super(message);
|
|
37
|
+
this.body = deepClone(body);
|
|
38
|
+
this.headers = deepClone(headers);
|
|
39
|
+
this.statusCode = statusCode;
|
|
40
|
+
this.isServerError = isServerError;
|
|
41
|
+
if (!this?.body?.message) {
|
|
42
|
+
this.body.message = this.message;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
static get supportedStatusCodes() { return supportedStatusCodes; }
|
|
46
|
+
static badRequest = (message, body, headers) => { return new HttpError(400, message, body, headers); };
|
|
47
|
+
static unauthorized = (message, body, headers) => new HttpError(401, message, body, headers);
|
|
48
|
+
static forbidden = (message, body, headers) => new HttpError(403, message, body, headers);
|
|
49
|
+
static notFound = (message, body, headers) => new HttpError(404, message, body, headers);
|
|
50
|
+
static internal = (message, body, headers) => new HttpError(500, message, body, headers);
|
|
51
|
+
static notImplemented = () => new HttpError(501);
|
|
52
|
+
static badGateway = () => new HttpError(502);
|
|
53
|
+
static serviceUnavailable = (headers) => new HttpError(503, undefined, undefined, headers);
|
|
54
|
+
static gatewayTimeout = () => new HttpError(504);
|
|
55
|
+
}
|
|
56
56
|
//# sourceMappingURL=http-error.js.map
|