@cakemail-org/ui-components-v2 2.1.1 → 2.1.3
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/index.js
CHANGED
|
@@ -9501,6 +9501,7 @@ var AccountModel = /** @class */ (function () {
|
|
|
9501
9501
|
this.overrides = params.overrides || {};
|
|
9502
9502
|
this.stripe_customer_id = params.stripe_customer_id || "";
|
|
9503
9503
|
this.metadata = params.metadata || {};
|
|
9504
|
+
this.usage = params.usage || undefined;
|
|
9504
9505
|
if (params.isMainAccount) {
|
|
9505
9506
|
this.getUsageReport();
|
|
9506
9507
|
}
|
|
@@ -9515,8 +9516,12 @@ var AccountModel = /** @class */ (function () {
|
|
|
9515
9516
|
return __awaiter(this, void 0, void 0, function () {
|
|
9516
9517
|
var _this = this;
|
|
9517
9518
|
return __generator(this, function (_a) {
|
|
9519
|
+
if (["1", "131010", "133315"].includes(this.id.toString())) {
|
|
9520
|
+
return [2 /*return*/, {}];
|
|
9521
|
+
}
|
|
9518
9522
|
return [2 /*return*/, this.getReport({}).then(function (report) {
|
|
9519
9523
|
_this.usage = report;
|
|
9524
|
+
return report;
|
|
9520
9525
|
})];
|
|
9521
9526
|
});
|
|
9522
9527
|
});
|
|
@@ -9601,56 +9606,43 @@ var AccountModel = /** @class */ (function () {
|
|
|
9601
9606
|
return this.partner || this.organization;
|
|
9602
9607
|
};
|
|
9603
9608
|
AccountModel.prototype.hasAccessTo = function (_a) {
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
9607
|
-
return
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
|
|
9612
|
-
|
|
9613
|
-
|
|
9614
|
-
|
|
9615
|
-
|
|
9616
|
-
|
|
9617
|
-
|
|
9618
|
-
|
|
9619
|
-
|
|
9620
|
-
|
|
9621
|
-
|
|
9622
|
-
|
|
9623
|
-
|
|
9624
|
-
|
|
9625
|
-
case 1:
|
|
9626
|
-
if (!!this.usage) return [3 /*break*/, 3];
|
|
9627
|
-
return [4 /*yield*/, this.getUsageReport()];
|
|
9628
|
-
case 2:
|
|
9629
|
-
_c.sent();
|
|
9630
|
-
_c.label = 3;
|
|
9631
|
-
case 3:
|
|
9632
|
-
if (this.usage) {
|
|
9633
|
-
if (feature === "lists") {
|
|
9634
|
-
return [2 /*return*/, this.usage.current_lists <= featureValue];
|
|
9635
|
-
}
|
|
9636
|
-
else if (feature === "users" && userCount !== undefined) {
|
|
9637
|
-
return [2 /*return*/, userCount <= featureValue];
|
|
9638
|
-
}
|
|
9639
|
-
else if (feature === "per_month") {
|
|
9640
|
-
return [2 /*return*/, this.usage.emails_usage <= 100];
|
|
9641
|
-
}
|
|
9642
|
-
else if (feature === "maximum_contacts") {
|
|
9643
|
-
return [2 /*return*/, this.usage.active_contacts <= featureValue];
|
|
9644
|
-
}
|
|
9645
|
-
throw new Error("Requested Feature does not exist in account usage");
|
|
9646
|
-
}
|
|
9647
|
-
else {
|
|
9648
|
-
return [2 /*return*/, true];
|
|
9649
|
-
}
|
|
9650
|
-
case 4: return [2 /*return*/];
|
|
9609
|
+
var feature = _a.feature, partnerBrand = _a.partnerBrand, userCount = _a.userCount;
|
|
9610
|
+
var featureValue = this.usage_limits[feature];
|
|
9611
|
+
if (featureValue === undefined) {
|
|
9612
|
+
return false;
|
|
9613
|
+
}
|
|
9614
|
+
var brandDisabledLimitsFeatures = getNestedProperty(partnerBrand, "config.disabledLimitsFeatures") || [];
|
|
9615
|
+
if (brandDisabledLimitsFeatures.includes(feature))
|
|
9616
|
+
return true;
|
|
9617
|
+
if (typeof featureValue === "boolean" || Number.isNaN(featureValue)) {
|
|
9618
|
+
//Some feature flags are inverted
|
|
9619
|
+
if (feature === "insert_reseller_logo") {
|
|
9620
|
+
return !featureValue;
|
|
9621
|
+
}
|
|
9622
|
+
else {
|
|
9623
|
+
return Boolean(featureValue);
|
|
9624
|
+
}
|
|
9625
|
+
}
|
|
9626
|
+
else {
|
|
9627
|
+
if (this.usage) {
|
|
9628
|
+
if (feature === "lists") {
|
|
9629
|
+
return this.usage.current_lists <= featureValue;
|
|
9651
9630
|
}
|
|
9652
|
-
|
|
9653
|
-
|
|
9631
|
+
else if (feature === "users" && userCount !== undefined) {
|
|
9632
|
+
return userCount <= featureValue;
|
|
9633
|
+
}
|
|
9634
|
+
else if (feature === "per_month") {
|
|
9635
|
+
return this.usage.emails_usage <= 100;
|
|
9636
|
+
}
|
|
9637
|
+
else if (feature === "maximum_contacts") {
|
|
9638
|
+
return this.usage.active_contacts <= featureValue;
|
|
9639
|
+
}
|
|
9640
|
+
throw new Error("Requested Feature does not exist in account usage");
|
|
9641
|
+
}
|
|
9642
|
+
else {
|
|
9643
|
+
throw new Error("Usage not fetched, please call getUsageReport() before calling hasAccessTo() with usage-based features");
|
|
9644
|
+
}
|
|
9645
|
+
}
|
|
9654
9646
|
};
|
|
9655
9647
|
return AccountModel;
|
|
9656
9648
|
}());
|
|
@@ -21,10 +21,11 @@ export declare class AccountModel {
|
|
|
21
21
|
usage?: TAccountReport;
|
|
22
22
|
constructor(params: Partial<TAccountModel> & {
|
|
23
23
|
isMainAccount?: boolean;
|
|
24
|
+
usage?: TAccountReport;
|
|
24
25
|
});
|
|
25
26
|
toJson(): any;
|
|
26
27
|
set<T extends keyof this>(property: T, value: this[T]): void;
|
|
27
|
-
getUsageReport(): Promise<
|
|
28
|
+
getUsageReport(): Promise<TAccountReport>;
|
|
28
29
|
getReport({ ...options }: TGetAccountReport): Promise<TAccountReport>;
|
|
29
30
|
impersonate(byContext?: boolean): Promise<any>;
|
|
30
31
|
getDomains(): Promise<TAccountDomains>;
|
|
@@ -39,6 +40,6 @@ export declare class AccountModel {
|
|
|
39
40
|
feature: keyof TAccountLimits;
|
|
40
41
|
partnerBrand?: TBrand;
|
|
41
42
|
userCount?: number;
|
|
42
|
-
}):
|
|
43
|
+
}): boolean;
|
|
43
44
|
}
|
|
44
45
|
export * from "./types";
|
package/dist/esm/index.js
CHANGED
|
@@ -9481,6 +9481,7 @@ var AccountModel = /** @class */ (function () {
|
|
|
9481
9481
|
this.overrides = params.overrides || {};
|
|
9482
9482
|
this.stripe_customer_id = params.stripe_customer_id || "";
|
|
9483
9483
|
this.metadata = params.metadata || {};
|
|
9484
|
+
this.usage = params.usage || undefined;
|
|
9484
9485
|
if (params.isMainAccount) {
|
|
9485
9486
|
this.getUsageReport();
|
|
9486
9487
|
}
|
|
@@ -9495,8 +9496,12 @@ var AccountModel = /** @class */ (function () {
|
|
|
9495
9496
|
return __awaiter(this, void 0, void 0, function () {
|
|
9496
9497
|
var _this = this;
|
|
9497
9498
|
return __generator(this, function (_a) {
|
|
9499
|
+
if (["1", "131010", "133315"].includes(this.id.toString())) {
|
|
9500
|
+
return [2 /*return*/, {}];
|
|
9501
|
+
}
|
|
9498
9502
|
return [2 /*return*/, this.getReport({}).then(function (report) {
|
|
9499
9503
|
_this.usage = report;
|
|
9504
|
+
return report;
|
|
9500
9505
|
})];
|
|
9501
9506
|
});
|
|
9502
9507
|
});
|
|
@@ -9581,56 +9586,43 @@ var AccountModel = /** @class */ (function () {
|
|
|
9581
9586
|
return this.partner || this.organization;
|
|
9582
9587
|
};
|
|
9583
9588
|
AccountModel.prototype.hasAccessTo = function (_a) {
|
|
9584
|
-
|
|
9585
|
-
|
|
9586
|
-
|
|
9587
|
-
return
|
|
9588
|
-
|
|
9589
|
-
|
|
9590
|
-
|
|
9591
|
-
|
|
9592
|
-
|
|
9593
|
-
|
|
9594
|
-
|
|
9595
|
-
|
|
9596
|
-
|
|
9597
|
-
|
|
9598
|
-
|
|
9599
|
-
|
|
9600
|
-
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
-
case 1:
|
|
9606
|
-
if (!!this.usage) return [3 /*break*/, 3];
|
|
9607
|
-
return [4 /*yield*/, this.getUsageReport()];
|
|
9608
|
-
case 2:
|
|
9609
|
-
_c.sent();
|
|
9610
|
-
_c.label = 3;
|
|
9611
|
-
case 3:
|
|
9612
|
-
if (this.usage) {
|
|
9613
|
-
if (feature === "lists") {
|
|
9614
|
-
return [2 /*return*/, this.usage.current_lists <= featureValue];
|
|
9615
|
-
}
|
|
9616
|
-
else if (feature === "users" && userCount !== undefined) {
|
|
9617
|
-
return [2 /*return*/, userCount <= featureValue];
|
|
9618
|
-
}
|
|
9619
|
-
else if (feature === "per_month") {
|
|
9620
|
-
return [2 /*return*/, this.usage.emails_usage <= 100];
|
|
9621
|
-
}
|
|
9622
|
-
else if (feature === "maximum_contacts") {
|
|
9623
|
-
return [2 /*return*/, this.usage.active_contacts <= featureValue];
|
|
9624
|
-
}
|
|
9625
|
-
throw new Error("Requested Feature does not exist in account usage");
|
|
9626
|
-
}
|
|
9627
|
-
else {
|
|
9628
|
-
return [2 /*return*/, true];
|
|
9629
|
-
}
|
|
9630
|
-
case 4: return [2 /*return*/];
|
|
9589
|
+
var feature = _a.feature, partnerBrand = _a.partnerBrand, userCount = _a.userCount;
|
|
9590
|
+
var featureValue = this.usage_limits[feature];
|
|
9591
|
+
if (featureValue === undefined) {
|
|
9592
|
+
return false;
|
|
9593
|
+
}
|
|
9594
|
+
var brandDisabledLimitsFeatures = getNestedProperty(partnerBrand, "config.disabledLimitsFeatures") || [];
|
|
9595
|
+
if (brandDisabledLimitsFeatures.includes(feature))
|
|
9596
|
+
return true;
|
|
9597
|
+
if (typeof featureValue === "boolean" || Number.isNaN(featureValue)) {
|
|
9598
|
+
//Some feature flags are inverted
|
|
9599
|
+
if (feature === "insert_reseller_logo") {
|
|
9600
|
+
return !featureValue;
|
|
9601
|
+
}
|
|
9602
|
+
else {
|
|
9603
|
+
return Boolean(featureValue);
|
|
9604
|
+
}
|
|
9605
|
+
}
|
|
9606
|
+
else {
|
|
9607
|
+
if (this.usage) {
|
|
9608
|
+
if (feature === "lists") {
|
|
9609
|
+
return this.usage.current_lists <= featureValue;
|
|
9631
9610
|
}
|
|
9632
|
-
|
|
9633
|
-
|
|
9611
|
+
else if (feature === "users" && userCount !== undefined) {
|
|
9612
|
+
return userCount <= featureValue;
|
|
9613
|
+
}
|
|
9614
|
+
else if (feature === "per_month") {
|
|
9615
|
+
return this.usage.emails_usage <= 100;
|
|
9616
|
+
}
|
|
9617
|
+
else if (feature === "maximum_contacts") {
|
|
9618
|
+
return this.usage.active_contacts <= featureValue;
|
|
9619
|
+
}
|
|
9620
|
+
throw new Error("Requested Feature does not exist in account usage");
|
|
9621
|
+
}
|
|
9622
|
+
else {
|
|
9623
|
+
throw new Error("Usage not fetched, please call getUsageReport() before calling hasAccessTo() with usage-based features");
|
|
9624
|
+
}
|
|
9625
|
+
}
|
|
9634
9626
|
};
|
|
9635
9627
|
return AccountModel;
|
|
9636
9628
|
}());
|
|
@@ -21,10 +21,11 @@ export declare class AccountModel {
|
|
|
21
21
|
usage?: TAccountReport;
|
|
22
22
|
constructor(params: Partial<TAccountModel> & {
|
|
23
23
|
isMainAccount?: boolean;
|
|
24
|
+
usage?: TAccountReport;
|
|
24
25
|
});
|
|
25
26
|
toJson(): any;
|
|
26
27
|
set<T extends keyof this>(property: T, value: this[T]): void;
|
|
27
|
-
getUsageReport(): Promise<
|
|
28
|
+
getUsageReport(): Promise<TAccountReport>;
|
|
28
29
|
getReport({ ...options }: TGetAccountReport): Promise<TAccountReport>;
|
|
29
30
|
impersonate(byContext?: boolean): Promise<any>;
|
|
30
31
|
getDomains(): Promise<TAccountDomains>;
|
|
@@ -39,6 +40,6 @@ export declare class AccountModel {
|
|
|
39
40
|
feature: keyof TAccountLimits;
|
|
40
41
|
partnerBrand?: TBrand;
|
|
41
42
|
userCount?: number;
|
|
42
|
-
}):
|
|
43
|
+
}): boolean;
|
|
43
44
|
}
|
|
44
45
|
export * from "./types";
|