@ductape/sdk 0.0.4-v16 → 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.
Files changed (65) hide show
  1. package/dist/api/services/pricingApi.service.d.ts +10 -0
  2. package/dist/api/services/pricingApi.service.js +34 -0
  3. package/dist/api/services/pricingApi.service.js.map +1 -0
  4. package/dist/api/urls.d.ts +2 -0
  5. package/dist/api/urls.js +8 -1
  6. package/dist/api/urls.js.map +1 -1
  7. package/dist/apps/services/app.service.js +1 -1
  8. package/dist/apps/services/app.service.js.map +1 -1
  9. package/dist/clients/pricing.client.d.ts +3 -0
  10. package/dist/clients/pricing.client.js +33 -0
  11. package/dist/clients/pricing.client.js.map +1 -0
  12. package/dist/inputs/utils/inputs.utils.create.js +1 -1
  13. package/dist/inputs/utils/inputs.utils.create.js.map +1 -1
  14. package/dist/logs/logs.types.d.ts +4 -0
  15. package/dist/logs/logs.types.js.map +1 -1
  16. package/dist/pricing/pricing.repo.d.ts +0 -0
  17. package/dist/pricing/pricing.repo.js +1 -0
  18. package/dist/pricing/pricing.repo.js.map +1 -0
  19. package/dist/pricing/pricing.service.d.ts +24 -0
  20. package/dist/pricing/pricing.service.js +51 -0
  21. package/dist/pricing/pricing.service.js.map +1 -0
  22. package/dist/pricing/pricing.types.d.ts +76 -0
  23. package/dist/pricing/pricing.types.js +21 -0
  24. package/dist/pricing/pricing.types.js.map +1 -0
  25. package/dist/pricing/utils/string.utils.d.ts +1 -0
  26. package/dist/pricing/utils/string.utils.js +9 -0
  27. package/dist/pricing/utils/string.utils.js.map +1 -0
  28. package/dist/processor/services/processor.service.d.ts +6 -0
  29. package/dist/processor/services/processor.service.js +108 -3
  30. package/dist/processor/services/processor.service.js.map +1 -1
  31. package/dist/processor/services/request.service.d.ts +36 -0
  32. package/dist/processor/services/request.service.js +304 -0
  33. package/dist/processor/services/request.service.js.map +1 -0
  34. package/dist/processor/types/request.types.d.ts +14 -0
  35. package/dist/processor/types/request.types.js +3 -0
  36. package/dist/processor/types/request.types.js.map +1 -0
  37. package/dist/processor/utils/processor.utils.js +23 -19
  38. package/dist/processor/utils/processor.utils.js.map +1 -1
  39. package/dist/processor/utils/request.utils.d.ts +20 -0
  40. package/dist/processor/utils/request.utils.js +113 -0
  41. package/dist/processor/utils/request.utils.js.map +1 -0
  42. package/dist/products/services/products.service.js +3 -0
  43. package/dist/products/services/products.service.js.map +1 -1
  44. package/dist/test/test.imports.js +5 -8
  45. package/dist/test/test.imports.js.map +1 -1
  46. package/dist/test/test.processor.js +13 -26
  47. package/dist/test/test.processor.js.map +1 -1
  48. package/dist/test/test.products.d.ts +1 -0
  49. package/dist/test/test.products.js +49 -0
  50. package/dist/test/test.products.js.map +1 -0
  51. package/dist/types/pricing.types.d.ts +4 -0
  52. package/dist/types/pricing.types.js +3 -0
  53. package/dist/types/pricing.types.js.map +1 -0
  54. package/dist/types/productsBuilder.types.d.ts +6 -1
  55. package/dist/types/productsBuilder.types.js +6 -1
  56. package/dist/types/productsBuilder.types.js.map +1 -1
  57. package/dist/types/request-tracker.interface.d.ts +0 -0
  58. package/dist/types/request-tracker.interface.js +1 -0
  59. package/dist/types/request-tracker.interface.js.map +1 -0
  60. package/dist/utils/constants.d.ts +1 -0
  61. package/dist/utils/constants.js +5 -0
  62. package/dist/utils/constants.js.map +1 -0
  63. package/dist/utils/index.js +1 -1
  64. package/dist/utils/index.js.map +1 -1
  65. package/package.json +5 -2
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFreeTag = isFreeTag;
4
+ exports.checkLimitExceeded = checkLimitExceeded;
5
+ exports.calculateOverageRequests = calculateOverageRequests;
6
+ exports.calculateRequests = calculateRequests;
7
+ exports.calculateCost = calculateCost;
8
+ exports.getRequestStats = getRequestStats;
9
+ exports.resetRequestCounter = resetRequestCounter;
10
+ exports.cleanupOldCounters = cleanupOldCounters;
11
+ exports.checkRateLimit = checkRateLimit;
12
+ const pricing_types_1 = require("../../pricing/pricing.types");
13
+ function isFreeTag(pricing_tag) {
14
+ return pricing_tag.endsWith(':free');
15
+ }
16
+ function checkLimitExceeded(requests, limits) {
17
+ const exceededLimits = [];
18
+ if (limits.per_minute && requests.per_minute > limits.per_minute) {
19
+ exceededLimits.push('per_minute');
20
+ }
21
+ if (limits.per_hour && requests.per_hour > limits.per_hour) {
22
+ exceededLimits.push('per_hour');
23
+ }
24
+ if (limits.per_day && requests.per_day > limits.per_day) {
25
+ exceededLimits.push('per_day');
26
+ }
27
+ if (limits.per_week && requests.per_week > limits.per_week) {
28
+ exceededLimits.push('per_week');
29
+ }
30
+ if (limits.per_month && requests.per_month > limits.per_month) {
31
+ exceededLimits.push('per_month');
32
+ }
33
+ return {
34
+ exceeded: exceededLimits.length > 0,
35
+ exceededLimits,
36
+ };
37
+ }
38
+ function calculateOverageRequests(requests, limits) {
39
+ let maxOverage = 0;
40
+ if (limits.per_minute && requests.per_minute > limits.per_minute) {
41
+ maxOverage = Math.max(maxOverage, requests.per_minute - limits.per_minute);
42
+ }
43
+ if (limits.per_hour && requests.per_hour > limits.per_hour) {
44
+ maxOverage = Math.max(maxOverage, requests.per_hour - limits.per_hour);
45
+ }
46
+ if (limits.per_day && requests.per_day > limits.per_day) {
47
+ maxOverage = Math.max(maxOverage, requests.per_day - limits.per_day);
48
+ }
49
+ if (limits.per_week && requests.per_week > limits.per_week) {
50
+ maxOverage = Math.max(maxOverage, requests.per_week - limits.per_week);
51
+ }
52
+ if (limits.per_month && requests.per_month > limits.per_month) {
53
+ maxOverage = Math.max(maxOverage, requests.per_month - limits.per_month);
54
+ }
55
+ return maxOverage;
56
+ }
57
+ function calculateRequests(requests) {
58
+ return Math.max(requests.per_minute, requests.per_hour, requests.per_day, requests.per_week, requests.per_month);
59
+ }
60
+ function calculateCost(pricing_mode, unit_price, requests) {
61
+ switch (pricing_mode) {
62
+ case pricing_types_1.pricingMode.PER_REQUEST:
63
+ return requests * unit_price;
64
+ case pricing_types_1.pricingMode.ONE_TIME:
65
+ case pricing_types_1.pricingMode.UPFRONT:
66
+ return requests > 0 ? unit_price : 0;
67
+ case pricing_types_1.pricingMode.RECURRING:
68
+ return requests > 0 ? unit_price : 0;
69
+ default:
70
+ return 0;
71
+ }
72
+ }
73
+ async function getRequestStats(app_id, workspace_id, requestTrackerService) {
74
+ return requestTrackerService.getRequestCount(app_id, workspace_id);
75
+ }
76
+ async function resetRequestCounter(app_id, workspace_id, requestTrackerService) {
77
+ const key = `${app_id}:${workspace_id}`;
78
+ requestTrackerService.requestCounts.delete(key);
79
+ }
80
+ async function cleanupOldCounters(requestTrackerService) {
81
+ requestTrackerService.cleanup();
82
+ }
83
+ async function checkRateLimit(app_id, workspace_id, limits, requestTrackerService) {
84
+ const requests = await requestTrackerService.getRequestCount(app_id, workspace_id);
85
+ const limitCheck = this.checkLimitExceeded(requests, limits);
86
+ if (limitCheck.exceeded) {
87
+ let nextReset = new Date(Date.now() + 60 * 1000);
88
+ if (limitCheck.exceededLimits.includes('per_minute')) {
89
+ nextReset = new Date(requests.last_reset.minute.getTime() + 60 * 1000);
90
+ }
91
+ else if (limitCheck.exceededLimits.includes('per_hour')) {
92
+ nextReset = new Date(requests.last_reset.hour.getTime() + 60 * 60 * 1000);
93
+ }
94
+ else if (limitCheck.exceededLimits.includes('per_day')) {
95
+ nextReset = new Date(requests.last_reset.day.getTime() + 24 * 60 * 60 * 1000);
96
+ }
97
+ else if (limitCheck.exceededLimits.includes('per_week')) {
98
+ nextReset = new Date(requests.last_reset.week.getTime() + 7 * 24 * 60 * 60 * 1000);
99
+ }
100
+ else if (limitCheck.exceededLimits.includes('per_month')) {
101
+ const nextMonth = new Date(requests.last_reset.month);
102
+ nextMonth.setMonth(nextMonth.getMonth() + 1);
103
+ nextReset = nextMonth;
104
+ }
105
+ return {
106
+ allowed: false,
107
+ reason: `Rate limit exceeded: ${limitCheck.exceededLimits.join(', ')}`,
108
+ reset_time: nextReset,
109
+ };
110
+ }
111
+ return { allowed: true };
112
+ }
113
+ //# sourceMappingURL=request.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.utils.js","sourceRoot":"","sources":["../../../src/processor/utils/request.utils.ts"],"names":[],"mappings":";;AAMA,8BAEC;AAED,gDA6BC;AAED,4DAoBC;AAED,8CAEC;AAED,sCAeC;AAED,0CAMC;AAED,kDAOC;AAED,gDAEC;AAED,wCAkCC;AA1ID,+DAA0E;AAK1E,SAAgB,SAAS,CAAC,WAAmB;IAC3C,OAAO,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC;AAED,SAAgB,kBAAkB,CAChC,QAAyB,EACzB,MAAsB;IAKtB,MAAM,cAAc,GAAa,EAAE,CAAC;IAEpC,IAAI,MAAM,CAAC,UAAU,IAAI,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QACjE,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACpC,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC3D,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;QACxD,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACjC,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC3D,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IACD,IAAI,MAAM,CAAC,SAAS,IAAI,QAAQ,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QAC9D,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC;IA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G,IAAI,CAAC,CAAC;QACrF,CAAC;aAAM,IAAI,UAAU,CAAC,cAAc,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC3D,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YACtD,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;YAC7C,SAAS,GAAG,SAAS,CAAC;QACxB,CAAC;QAED,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,wBAAwB,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACtE,UAAU,EAAE,SAAS;SACtB,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC"}
@@ -1354,6 +1354,9 @@ class ProductsBuilderService {
1354
1354
  throw new Error(`App ${app.access_tag} not found`);
1355
1355
  }
1356
1356
  const cleanedAppData = await this.validateAppData(appData, app);
1357
+ if (!cleanedAppData.pricing_tag) {
1358
+ cleanedAppData.pricing_tag = `${appData.tag}:${productsBuilder_types_1.PricingTag.FREE}`;
1359
+ }
1357
1360
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, cleanedAppData), { app_tag: appData.tag, component: enums_1.ProductComponents.APP, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
1358
1361
  await this.initializeProduct(this.product_id);
1359
1362
  }