@ductape/sdk 0.0.4-v16-lite → 0.0.4-v17
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/api/services/pricingApi.service.d.ts +10 -0
- package/dist/api/services/pricingApi.service.js +34 -0
- package/dist/api/services/pricingApi.service.js.map +1 -0
- package/dist/api/urls.d.ts +2 -0
- package/dist/api/urls.js +8 -1
- package/dist/api/urls.js.map +1 -1
- package/dist/clients/pricing.client.d.ts +3 -0
- package/dist/clients/pricing.client.js +33 -0
- package/dist/clients/pricing.client.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +102 -147
- package/dist/index.js.map +1 -1
- package/dist/logs/logs.types.d.ts +4 -0
- package/dist/logs/logs.types.js.map +1 -1
- package/dist/pricing/pricing.repo.d.ts +0 -0
- package/dist/pricing/pricing.repo.js +1 -0
- package/dist/pricing/pricing.repo.js.map +1 -0
- package/dist/pricing/pricing.service.d.ts +24 -0
- package/dist/pricing/pricing.service.js +51 -0
- package/dist/pricing/pricing.service.js.map +1 -0
- package/dist/pricing/pricing.types.d.ts +76 -0
- package/dist/pricing/pricing.types.js +21 -0
- package/dist/pricing/pricing.types.js.map +1 -0
- package/dist/pricing/utils/string.utils.d.ts +1 -0
- package/dist/pricing/utils/string.utils.js +9 -0
- package/dist/pricing/utils/string.utils.js.map +1 -0
- package/dist/processor/services/processor.service.d.ts +6 -0
- package/dist/processor/services/processor.service.js +108 -3
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/processor/services/request.service.d.ts +36 -0
- package/dist/processor/services/request.service.js +304 -0
- package/dist/processor/services/request.service.js.map +1 -0
- package/dist/processor/types/request.types.d.ts +14 -0
- package/dist/processor/types/request.types.js +3 -0
- package/dist/processor/types/request.types.js.map +1 -0
- package/dist/processor/utils/processor.utils.js +23 -19
- package/dist/processor/utils/processor.utils.js.map +1 -1
- package/dist/processor/utils/request.utils.d.ts +20 -0
- package/dist/processor/utils/request.utils.js +113 -0
- package/dist/processor/utils/request.utils.js.map +1 -0
- package/dist/products/services/products.service.js +3 -0
- package/dist/products/services/products.service.js.map +1 -1
- package/dist/test/test.imports.js +5 -8
- package/dist/test/test.imports.js.map +1 -1
- package/dist/test/test.processor.js +13 -26
- package/dist/test/test.processor.js.map +1 -1
- package/dist/test/test.products.d.ts +1 -0
- package/dist/test/test.products.js +49 -0
- package/dist/test/test.products.js.map +1 -0
- package/dist/types/pricing.types.d.ts +4 -0
- package/dist/types/pricing.types.js +3 -0
- package/dist/types/pricing.types.js.map +1 -0
- package/dist/types/productsBuilder.types.d.ts +6 -1
- package/dist/types/productsBuilder.types.js +6 -1
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/dist/types/request-tracker.interface.d.ts +0 -0
- package/dist/types/request-tracker.interface.js +1 -0
- package/dist/types/request-tracker.interface.js.map +1 -0
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.js +5 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IPricingInit } from "../types/pricing.types";
|
|
2
|
+
import { IPricing } from "./pricing.types";
|
|
3
|
+
export interface IPricingService {
|
|
4
|
+
initializePricingByTag: (pricing_tag: string, app_id: string) => Promise<void>;
|
|
5
|
+
fetchPricing(): IPricing;
|
|
6
|
+
fetchOveragePricing(): IPricing;
|
|
7
|
+
}
|
|
8
|
+
export default class PricingService implements IPricingService {
|
|
9
|
+
private user_id;
|
|
10
|
+
private workspace_id;
|
|
11
|
+
private token;
|
|
12
|
+
private public_key;
|
|
13
|
+
private app_id;
|
|
14
|
+
private pricingApi;
|
|
15
|
+
private pricing;
|
|
16
|
+
private overagePricing;
|
|
17
|
+
private pricing_tag;
|
|
18
|
+
private overage_pricing_tag;
|
|
19
|
+
constructor({ workspace_id, public_key, user_id, token, env_type, redis_client }: IPricingInit);
|
|
20
|
+
fetchPricing(): IPricing;
|
|
21
|
+
fetchOveragePricing(): IPricing;
|
|
22
|
+
initializePricingByTag(pricing_tag: string, app_id: string): Promise<void>;
|
|
23
|
+
private getUserAccess;
|
|
24
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const pricingApi_service_1 = require("../api/services/pricingApi.service");
|
|
4
|
+
const string_utils_1 = require("./utils/string.utils");
|
|
5
|
+
class PricingService {
|
|
6
|
+
constructor({ workspace_id, public_key, user_id, token, env_type, redis_client }) {
|
|
7
|
+
this.workspace_id = workspace_id;
|
|
8
|
+
this.public_key = public_key;
|
|
9
|
+
this.user_id = user_id;
|
|
10
|
+
this.token = token;
|
|
11
|
+
this.pricingApi = new pricingApi_service_1.PricingApiService(env_type);
|
|
12
|
+
}
|
|
13
|
+
fetchPricing() {
|
|
14
|
+
if (!this.pricing) {
|
|
15
|
+
throw new Error('Pricing not yet initiated');
|
|
16
|
+
}
|
|
17
|
+
return this.pricing;
|
|
18
|
+
}
|
|
19
|
+
fetchOveragePricing() {
|
|
20
|
+
if (!this.overagePricing) {
|
|
21
|
+
throw new Error('Pricing not yet initiated');
|
|
22
|
+
}
|
|
23
|
+
return this.overagePricing;
|
|
24
|
+
}
|
|
25
|
+
async initializePricingByTag(pricing_tag, app_id) {
|
|
26
|
+
try {
|
|
27
|
+
const params = { pricing_tag, app_id };
|
|
28
|
+
const overage_params = { pricing_tag: (0, string_utils_1.extractOverageTag)(pricing_tag), app_id };
|
|
29
|
+
console.log('Fetching pricing for:', params);
|
|
30
|
+
console.log('Fetching overage pricing for:', overage_params);
|
|
31
|
+
[this.pricing, this.overagePricing] = await Promise.all([this.pricingApi.fetchPricingByTag(params, this.getUserAccess()), this.pricingApi.fetchPricingByTag(overage_params, this.getUserAccess())]);
|
|
32
|
+
console.error(this.pricing, pricing_tag);
|
|
33
|
+
this.pricing_tag = pricing_tag;
|
|
34
|
+
this.overage_pricing_tag = (0, string_utils_1.extractOverageTag)(pricing_tag);
|
|
35
|
+
this.app_id = app_id;
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
throw e;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
getUserAccess() {
|
|
42
|
+
return {
|
|
43
|
+
user_id: this.user_id,
|
|
44
|
+
workspace_id: this.workspace_id,
|
|
45
|
+
token: this.token,
|
|
46
|
+
public_key: this.public_key,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.default = PricingService;
|
|
51
|
+
//# sourceMappingURL=pricing.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricing.service.js","sourceRoot":"","sources":["../../src/pricing/pricing.service.ts"],"names":[],"mappings":";;AAAA,2EAA2F;AAI3F,uDAAyD;AAQzD,MAAqB,cAAc;IAc/B,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAgB;QAC1F,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,UAAU,GAAG,IAAI,sCAAiB,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED,YAAY;QACR,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,mBAAmB;QACf,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,sBAAsB,CAAC,WAAmB,EAAE,MAAc;QAC5D,IAAI,CAAC;YACD,MAAM,MAAM,GAAsB,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;YAC1D,MAAM,cAAc,GAAsB,EAAE,WAAW,EAAE,IAAA,gCAAiB,EAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;YAClG,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;YAC7C,OAAO,CAAC,GAAG,CAAC,+BAA+B,EAAE,cAAc,CAAC,CAAC;YAC7D,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,cAAc,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC;YACpM,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;YACxC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;YAC/B,IAAI,CAAC,mBAAmB,GAAG,IAAA,gCAAiB,EAAC,WAAW,CAAC,CAAC;YAC1D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACzB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,MAAM,CAAC,CAAC;QACZ,CAAC;IACL,CAAC;IAEO,aAAa;QACjB,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC;IACJ,CAAC;CAEN;AA7DD,iCA6DC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { IRequestCounter } from "../processor/types/request.types";
|
|
2
|
+
export declare enum paymentInterval {
|
|
3
|
+
DAILY = "daily",
|
|
4
|
+
WEEKLY = "weekly",
|
|
5
|
+
BI_WEEKLY = "bi-weekly",
|
|
6
|
+
MONTHLY = "monthly",
|
|
7
|
+
QUARTERLY = "quarterly",
|
|
8
|
+
YEARLY = "yearly",
|
|
9
|
+
ONCE = "one-time"
|
|
10
|
+
}
|
|
11
|
+
export declare enum pricingMode {
|
|
12
|
+
PER_REQUEST = "per_request",
|
|
13
|
+
ONE_TIME = "one_time",
|
|
14
|
+
UPFRONT = "upfront",
|
|
15
|
+
RECURRING = "recurring"
|
|
16
|
+
}
|
|
17
|
+
export interface IPricing {
|
|
18
|
+
_id: string;
|
|
19
|
+
user_id: string;
|
|
20
|
+
action_id: string;
|
|
21
|
+
app_tag?: string;
|
|
22
|
+
pricing_tag: string;
|
|
23
|
+
public_key: string;
|
|
24
|
+
id?: string;
|
|
25
|
+
app_id?: string;
|
|
26
|
+
name: string;
|
|
27
|
+
limits?: {
|
|
28
|
+
per_minute?: number;
|
|
29
|
+
per_day?: number;
|
|
30
|
+
per_hour?: number;
|
|
31
|
+
per_week?: number;
|
|
32
|
+
per_month?: number;
|
|
33
|
+
};
|
|
34
|
+
pricing_mode: pricingMode;
|
|
35
|
+
interval?: paymentInterval;
|
|
36
|
+
unit_price: number;
|
|
37
|
+
currency: string;
|
|
38
|
+
envs: Array<string>;
|
|
39
|
+
}
|
|
40
|
+
export interface IPricingLimits {
|
|
41
|
+
per_minute?: number;
|
|
42
|
+
per_hour?: number;
|
|
43
|
+
per_day?: number;
|
|
44
|
+
per_week?: number;
|
|
45
|
+
per_month?: number;
|
|
46
|
+
}
|
|
47
|
+
export interface IPricingData {
|
|
48
|
+
_id: string;
|
|
49
|
+
app_id: string;
|
|
50
|
+
pricing_tag: string;
|
|
51
|
+
action_id: string;
|
|
52
|
+
pricing_mode: pricingMode;
|
|
53
|
+
interval: paymentInterval;
|
|
54
|
+
limits: IPricingLimits;
|
|
55
|
+
unit_price: number;
|
|
56
|
+
name: string;
|
|
57
|
+
currency: string;
|
|
58
|
+
user_id: string;
|
|
59
|
+
public_key: string;
|
|
60
|
+
}
|
|
61
|
+
export interface ILogData {
|
|
62
|
+
app_id?: string;
|
|
63
|
+
workspace_id?: string;
|
|
64
|
+
user_id?: string;
|
|
65
|
+
timestamp?: Date;
|
|
66
|
+
[key: string]: any;
|
|
67
|
+
}
|
|
68
|
+
export interface IPricingResult {
|
|
69
|
+
pricing_tag: string;
|
|
70
|
+
pricing_cost: number;
|
|
71
|
+
currency: string;
|
|
72
|
+
is_overage: boolean;
|
|
73
|
+
requests_made: IRequestCounter;
|
|
74
|
+
limit_exceeded: boolean;
|
|
75
|
+
exceeded_limits: string[];
|
|
76
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pricingMode = exports.paymentInterval = void 0;
|
|
4
|
+
var paymentInterval;
|
|
5
|
+
(function (paymentInterval) {
|
|
6
|
+
paymentInterval["DAILY"] = "daily";
|
|
7
|
+
paymentInterval["WEEKLY"] = "weekly";
|
|
8
|
+
paymentInterval["BI_WEEKLY"] = "bi-weekly";
|
|
9
|
+
paymentInterval["MONTHLY"] = "monthly";
|
|
10
|
+
paymentInterval["QUARTERLY"] = "quarterly";
|
|
11
|
+
paymentInterval["YEARLY"] = "yearly";
|
|
12
|
+
paymentInterval["ONCE"] = "one-time";
|
|
13
|
+
})(paymentInterval || (exports.paymentInterval = paymentInterval = {}));
|
|
14
|
+
var pricingMode;
|
|
15
|
+
(function (pricingMode) {
|
|
16
|
+
pricingMode["PER_REQUEST"] = "per_request";
|
|
17
|
+
pricingMode["ONE_TIME"] = "one_time";
|
|
18
|
+
pricingMode["UPFRONT"] = "upfront";
|
|
19
|
+
pricingMode["RECURRING"] = "recurring";
|
|
20
|
+
})(pricingMode || (exports.pricingMode = pricingMode = {}));
|
|
21
|
+
//# sourceMappingURL=pricing.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricing.types.js","sourceRoot":"","sources":["../../src/pricing/pricing.types.ts"],"names":[],"mappings":";;;AAEA,IAAY,eAQX;AARD,WAAY,eAAe;IACvB,kCAAe,CAAA;IACf,oCAAiB,CAAA;IACjB,0CAAuB,CAAA;IACvB,sCAAmB,CAAA;IACnB,0CAAuB,CAAA;IACvB,oCAAiB,CAAA;IACjB,oCAAiB,CAAA;AACrB,CAAC,EARW,eAAe,+BAAf,eAAe,QAQ1B;AAED,IAAY,WAKX;AALD,WAAY,WAAW;IACnB,0CAA2B,CAAA;IAC3B,oCAAqB,CAAA;IACrB,kCAAmB,CAAA;IACnB,sCAAuB,CAAA;AAC3B,CAAC,EALW,WAAW,2BAAX,WAAW,QAKtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const extractOverageTag: (input: string) => string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractOverageTag = void 0;
|
|
4
|
+
const extractOverageTag = (input) => {
|
|
5
|
+
const [origin, tag] = input.split(":");
|
|
6
|
+
return `${origin}:${tag}:overage`;
|
|
7
|
+
};
|
|
8
|
+
exports.extractOverageTag = extractOverageTag;
|
|
9
|
+
//# sourceMappingURL=string.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.utils.js","sourceRoot":"","sources":["../../../src/pricing/utils/string.utils.ts"],"names":[],"mappings":";;;AAAO,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAU,EAAE;IACzD,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACvC,OAAO,GAAG,MAAM,IAAI,GAAG,UAAU,CAAC;AACpC,CAAC,CAAA;AAHY,QAAA,iBAAiB,qBAG7B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IAppVersion, IBuilderInit, IGenerateWebhookLink, INotificationsHandler, IProcessingFailure, IProcessorInput, IProcessorSequenceLevels, IActionProcessorInput, IDBActionProcessorInput, IFunctionProcessorInput, INotificationProcessorInput, IProductNotificationTemplate, IStorageProcessorInput, IRegisterWebhook, WebhookEventTypes, IJobProcessorInput, IMessageBrokerPublishInput, IMessageBrokerSubscribeInput, FeatureEventTypes, IActionRequest, IActionSamples, IDbActionRequest, IDependencyMatrix, IFeatureEvent, IFeatureInput, IFeatureSequence, IProductAppEnvs, IProductEnv, IProductFeature, IRetryMeta, IProductDatabaseEnvs, IStorageRequest, IProductStorageEnvs, HttpMethods, ILogData, LogEventStatus, IAppRetryPolicy, IParsedIndexes, IParsedSample, IProductQuota, IProductFallback, IQuotaOptions, IFallbackOptions, FetchRemoteCachePayload, ISessionInput, ISessionOutput, ISessionPayload, ISessionRefreshPayload } from '../../types';
|
|
2
|
+
import { IPricingResult } from '../../pricing/pricing.types';
|
|
2
3
|
export interface IProcessorService {
|
|
3
4
|
processFeature(data: IProcessorInput): Promise<any>;
|
|
4
5
|
processDBAction(db_action: IDBActionProcessorInput): Promise<any>;
|
|
@@ -21,7 +22,9 @@ export default class ProcessorService implements IProcessorService {
|
|
|
21
22
|
private productBuilderService;
|
|
22
23
|
private processorApiService;
|
|
23
24
|
private logService;
|
|
25
|
+
private pricingService;
|
|
24
26
|
private inputService;
|
|
27
|
+
private requestTrackerService;
|
|
25
28
|
private start;
|
|
26
29
|
private end;
|
|
27
30
|
private processingOutput;
|
|
@@ -35,6 +38,7 @@ export default class ProcessorService implements IProcessorService {
|
|
|
35
38
|
private processingFailure;
|
|
36
39
|
private doneWithProcessing;
|
|
37
40
|
private productTag;
|
|
41
|
+
private pricingTag;
|
|
38
42
|
private apps;
|
|
39
43
|
private baseLogs;
|
|
40
44
|
private clone;
|
|
@@ -70,6 +74,7 @@ export default class ProcessorService implements IProcessorService {
|
|
|
70
74
|
process_id: string;
|
|
71
75
|
}>;
|
|
72
76
|
intializeProduct(additional_logs: Partial<ILogData>): Promise<void>;
|
|
77
|
+
initializePricing(additional_logs: Partial<ILogData>, access_tag: string): Promise<void>;
|
|
73
78
|
fetchFeature(tag: string, additional_logs: Partial<ILogData>): IProductFeature;
|
|
74
79
|
fetchQuota(tag: string, additional_logs: Partial<ILogData>): IProductQuota;
|
|
75
80
|
fetchFallback(tag: string, additional_logs: Partial<ILogData>): IProductFallback;
|
|
@@ -184,6 +189,7 @@ export default class ProcessorService implements IProcessorService {
|
|
|
184
189
|
status?: undefined;
|
|
185
190
|
data?: undefined;
|
|
186
191
|
}>;
|
|
192
|
+
processPricingCost(additional_logs: Partial<ILogData>): Promise<IPricingResult>;
|
|
187
193
|
addToSuccessOutput(event: IFeatureEvent, output: any, additional_logs: Partial<ILogData>): Promise<void>;
|
|
188
194
|
checkIsSuccessful(): boolean;
|
|
189
195
|
addToWaitingOutput(event: IFeatureEvent, dependants: Array<IDependencyMatrix>): void;
|
|
@@ -69,6 +69,9 @@ const postgres_repo_1 = require("../repos/postgres.repo");
|
|
|
69
69
|
const storage_util_1 = require("../utils/storage.util");
|
|
70
70
|
const sms_repo_1 = require("../repos/sms.repo");
|
|
71
71
|
const quota_service_1 = __importDefault(require("./quota.service"));
|
|
72
|
+
const pricing_service_1 = __importDefault(require("../../pricing/pricing.service"));
|
|
73
|
+
const request_utils_1 = require("../utils/request.utils");
|
|
74
|
+
const request_service_1 = __importDefault(require("./request.service"));
|
|
72
75
|
async function loadBrokerService() {
|
|
73
76
|
if (typeof window === 'undefined') {
|
|
74
77
|
const { createBrokerService } = await Promise.resolve().then(() => __importStar(require('./messagebrokers')));
|
|
@@ -98,6 +101,14 @@ class ProcessorService {
|
|
|
98
101
|
env_type,
|
|
99
102
|
redis_client
|
|
100
103
|
});
|
|
104
|
+
this.pricingService = new pricing_service_1.default({
|
|
105
|
+
workspace_id,
|
|
106
|
+
public_key,
|
|
107
|
+
user_id,
|
|
108
|
+
token,
|
|
109
|
+
env_type,
|
|
110
|
+
redis_client,
|
|
111
|
+
});
|
|
101
112
|
this.inputService = new inputs_service_1.default();
|
|
102
113
|
this.requestTime = 0;
|
|
103
114
|
this.totalRequests = 0;
|
|
@@ -108,6 +119,7 @@ class ProcessorService {
|
|
|
108
119
|
skipped: [],
|
|
109
120
|
};
|
|
110
121
|
this.apps = [];
|
|
122
|
+
this.requestTrackerService = request_service_1.default.getInstance(redis_client);
|
|
111
123
|
this.processorApiService = new processorApi_service_1.ProcessorApiService(env_type);
|
|
112
124
|
this.environment = env_type;
|
|
113
125
|
if (redis_client && this.productTag) {
|
|
@@ -663,6 +675,32 @@ class ProcessorService {
|
|
|
663
675
|
throw e;
|
|
664
676
|
}
|
|
665
677
|
}
|
|
678
|
+
async initializePricing(additional_logs, access_tag) {
|
|
679
|
+
if (!this.logService) {
|
|
680
|
+
this.logService = new logs_service_1.default({
|
|
681
|
+
product_id: this.productId,
|
|
682
|
+
workspace_id: this.workspace_id,
|
|
683
|
+
public_key: this.public_key,
|
|
684
|
+
user_id: this.user_id,
|
|
685
|
+
token: this.token,
|
|
686
|
+
env_type: this.environment,
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
try {
|
|
690
|
+
console.log(`Initializing pricing for access tag: ${access_tag}`);
|
|
691
|
+
const product_app = this.productBuilderService.fetchApp(access_tag); // validate app exists
|
|
692
|
+
console.log(`Found product app: ${JSON.stringify(product_app)}`);
|
|
693
|
+
const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(product_app.access_tag);
|
|
694
|
+
await this.pricingService.initializePricingByTag(product_app.pricing_tag, app._id);
|
|
695
|
+
const { pricing_tag } = this.pricingService.fetchPricing();
|
|
696
|
+
this.pricingTag = pricing_tag;
|
|
697
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Pricing initialize - success', data: { pricing_tag: this.pricingTag }, status: types_1.LogEventStatus.SUCCESS }));
|
|
698
|
+
}
|
|
699
|
+
catch (e) {
|
|
700
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Pricing initialize - failed', data: e, status: types_1.LogEventStatus.FAIL }));
|
|
701
|
+
throw e;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
666
704
|
fetchFeature(tag, additional_logs) {
|
|
667
705
|
try {
|
|
668
706
|
const feature = this.productBuilderService.fetchFeature(tag); // validate feature exists
|
|
@@ -2022,7 +2060,7 @@ class ProcessorService {
|
|
|
2022
2060
|
additional_logs.app_env = app_env_slug;
|
|
2023
2061
|
console.log(app, appEnvs);
|
|
2024
2062
|
const env = appEnvs.find((item) => item.slug === app_env_slug); // fetch the actuall app Environment variable
|
|
2025
|
-
if (!active) {
|
|
2063
|
+
if (!active && recipient_workspace_id !== this.baseLogs.workspace_id) {
|
|
2026
2064
|
throw new Error(`App ${event.app} version ${app.version} is not active`);
|
|
2027
2065
|
}
|
|
2028
2066
|
if (!env.active) {
|
|
@@ -2109,6 +2147,7 @@ class ProcessorService {
|
|
|
2109
2147
|
}
|
|
2110
2148
|
}
|
|
2111
2149
|
async processRequest(payload, event, retries, additional_logs, returnValue = false) {
|
|
2150
|
+
var _a;
|
|
2112
2151
|
const { request_base_url, resource, payloads, method, env, app_id } = payload;
|
|
2113
2152
|
const start = Date.now();
|
|
2114
2153
|
try {
|
|
@@ -2119,7 +2158,11 @@ class ProcessorService {
|
|
|
2119
2158
|
const end = Date.now();
|
|
2120
2159
|
this.requestTime += end - start;
|
|
2121
2160
|
this.totalRequests += 1;
|
|
2122
|
-
this.
|
|
2161
|
+
const { pricing_tag, pricing_cost, is_overage, currency } = await this.processPricingCost(Object.assign(Object.assign({}, additional_logs), { app_id, workspace_id: this.workspace_id }));
|
|
2162
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { pricing_tag,
|
|
2163
|
+
pricing_cost,
|
|
2164
|
+
currency,
|
|
2165
|
+
is_overage, message: 'Process http request - success', successful_execution: true, data: { response: (0, processor_utils_1.anonymizeObject)(results) }, status: types_1.LogEventStatus.SUCCESS, app_id, action: event.event, start,
|
|
2123
2166
|
end }));
|
|
2124
2167
|
await this.addToSuccessOutput(event, results, additional_logs);
|
|
2125
2168
|
if (returnValue) {
|
|
@@ -2132,7 +2175,7 @@ class ProcessorService {
|
|
|
2132
2175
|
catch (e) {
|
|
2133
2176
|
const end = Date.now();
|
|
2134
2177
|
let error = e;
|
|
2135
|
-
if (e.response.data) {
|
|
2178
|
+
if ((_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.data) {
|
|
2136
2179
|
error = e.response.data;
|
|
2137
2180
|
}
|
|
2138
2181
|
this.requestTime += end - start;
|
|
@@ -2165,6 +2208,67 @@ class ProcessorService {
|
|
|
2165
2208
|
}
|
|
2166
2209
|
}
|
|
2167
2210
|
}
|
|
2211
|
+
async processPricingCost(additional_logs) {
|
|
2212
|
+
try {
|
|
2213
|
+
const { app_id, workspace_id } = additional_logs;
|
|
2214
|
+
if (!app_id || !workspace_id) {
|
|
2215
|
+
throw new Error('app_id and workspace_id are required in additional_logs');
|
|
2216
|
+
}
|
|
2217
|
+
const primaryPricing = this.pricingService.fetchPricing();
|
|
2218
|
+
const overagePricing = this.pricingService.fetchOveragePricing();
|
|
2219
|
+
const requests = await this.requestTrackerService.incrementRequest(app_id, workspace_id);
|
|
2220
|
+
const limitCheck = (0, request_utils_1.checkLimitExceeded)(requests, primaryPricing.limits);
|
|
2221
|
+
let finalCost = 0;
|
|
2222
|
+
let usedPricing = primaryPricing;
|
|
2223
|
+
let isOverage = false;
|
|
2224
|
+
let finalCurrency = primaryPricing.currency;
|
|
2225
|
+
if ((0, request_utils_1.isFreeTag)(primaryPricing.pricing_tag)) {
|
|
2226
|
+
if (limitCheck.exceeded) {
|
|
2227
|
+
const overageRequests = (0, request_utils_1.calculateOverageRequests)(requests, primaryPricing.limits);
|
|
2228
|
+
finalCost = (0, request_utils_1.calculateCost)(overagePricing.pricing_mode, overagePricing.unit_price, overageRequests);
|
|
2229
|
+
usedPricing = overagePricing;
|
|
2230
|
+
isOverage = true;
|
|
2231
|
+
finalCurrency = overagePricing.currency;
|
|
2232
|
+
}
|
|
2233
|
+
else {
|
|
2234
|
+
finalCost = 0;
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
else {
|
|
2238
|
+
if (limitCheck.exceeded) {
|
|
2239
|
+
const overageRequests = (0, request_utils_1.calculateOverageRequests)(requests, primaryPricing.limits);
|
|
2240
|
+
const overageCost = (0, request_utils_1.calculateCost)(overagePricing.pricing_mode, overagePricing.unit_price, overageRequests);
|
|
2241
|
+
finalCost = overageCost;
|
|
2242
|
+
isOverage = true;
|
|
2243
|
+
}
|
|
2244
|
+
else {
|
|
2245
|
+
const pricingRequests = (0, request_utils_1.calculateRequests)(requests);
|
|
2246
|
+
finalCost = (0, request_utils_1.calculateCost)(primaryPricing.pricing_mode, primaryPricing.unit_price, pricingRequests);
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process Pricing Cost - success', data: {
|
|
2250
|
+
pricing_tag: usedPricing.pricing_tag,
|
|
2251
|
+
cost: finalCost,
|
|
2252
|
+
currency: finalCurrency,
|
|
2253
|
+
is_overage: isOverage,
|
|
2254
|
+
requests: requests,
|
|
2255
|
+
limit_exceeded: limitCheck.exceeded
|
|
2256
|
+
}, status: types_1.LogEventStatus.SUCCESS }));
|
|
2257
|
+
return {
|
|
2258
|
+
pricing_tag: usedPricing.pricing_tag,
|
|
2259
|
+
pricing_cost: Math.round(finalCost * 100) / 100,
|
|
2260
|
+
currency: finalCurrency,
|
|
2261
|
+
is_overage: isOverage,
|
|
2262
|
+
requests_made: requests,
|
|
2263
|
+
limit_exceeded: limitCheck.exceeded,
|
|
2264
|
+
exceeded_limits: limitCheck.exceededLimits
|
|
2265
|
+
};
|
|
2266
|
+
}
|
|
2267
|
+
catch (e) {
|
|
2268
|
+
this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process Pricing Cost - failed', data: { error: e }, status: types_1.LogEventStatus.FAIL }));
|
|
2269
|
+
throw e;
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2168
2272
|
async addToSuccessOutput(event, output, additional_logs) {
|
|
2169
2273
|
// Remove event from failed, skipped, and waiting arrays
|
|
2170
2274
|
this.processingOutput.failure = this.processingOutput.failure.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
|
|
@@ -3351,6 +3455,7 @@ class ProcessorService {
|
|
|
3351
3455
|
data: input,
|
|
3352
3456
|
};
|
|
3353
3457
|
await this.intializeProduct(additional_logs);
|
|
3458
|
+
await this.initializePricing(additional_logs, app);
|
|
3354
3459
|
this.process_id = process_id;
|
|
3355
3460
|
this.baseLogs.product_id = this.productId;
|
|
3356
3461
|
const productEnv = this.fetchEnv(env, additional_logs);
|