@cakemail-org/ui-components-v2 2.1.0 → 2.1.2
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
|
}
|
|
@@ -9601,56 +9602,43 @@ var AccountModel = /** @class */ (function () {
|
|
|
9601
9602
|
return this.partner || this.organization;
|
|
9602
9603
|
};
|
|
9603
9604
|
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*/];
|
|
9605
|
+
var feature = _a.feature, partnerBrand = _a.partnerBrand, userCount = _a.userCount;
|
|
9606
|
+
var featureValue = this.usage_limits[feature];
|
|
9607
|
+
if (featureValue === undefined) {
|
|
9608
|
+
return false;
|
|
9609
|
+
}
|
|
9610
|
+
var brandDisabledLimitsFeatures = getNestedProperty(partnerBrand, "config.disabledLimitsFeatures") || [];
|
|
9611
|
+
if (brandDisabledLimitsFeatures.includes(feature))
|
|
9612
|
+
return true;
|
|
9613
|
+
if (typeof featureValue === "boolean" || Number.isNaN(featureValue)) {
|
|
9614
|
+
//Some feature flags are inverted
|
|
9615
|
+
if (feature === "insert_reseller_logo") {
|
|
9616
|
+
return !featureValue;
|
|
9617
|
+
}
|
|
9618
|
+
else {
|
|
9619
|
+
return Boolean(featureValue);
|
|
9620
|
+
}
|
|
9621
|
+
}
|
|
9622
|
+
else {
|
|
9623
|
+
if (this.usage) {
|
|
9624
|
+
if (feature === "lists") {
|
|
9625
|
+
return this.usage.current_lists <= featureValue;
|
|
9651
9626
|
}
|
|
9652
|
-
|
|
9653
|
-
|
|
9627
|
+
else if (feature === "users" && userCount !== undefined) {
|
|
9628
|
+
return userCount <= featureValue;
|
|
9629
|
+
}
|
|
9630
|
+
else if (feature === "per_month") {
|
|
9631
|
+
return this.usage.emails_usage <= 100;
|
|
9632
|
+
}
|
|
9633
|
+
else if (feature === "maximum_contacts") {
|
|
9634
|
+
return this.usage.active_contacts <= featureValue;
|
|
9635
|
+
}
|
|
9636
|
+
throw new Error("Requested Feature does not exist in account usage");
|
|
9637
|
+
}
|
|
9638
|
+
else {
|
|
9639
|
+
throw new Error("Usage not fetched, please call getUsageReport() before calling hasAccessTo() with usage-based features");
|
|
9640
|
+
}
|
|
9641
|
+
}
|
|
9654
9642
|
};
|
|
9655
9643
|
return AccountModel;
|
|
9656
9644
|
}());
|
|
@@ -10522,7 +10510,7 @@ var GenericWrapperContext = React.createContext({
|
|
|
10522
10510
|
function GenericWrapper(_a) {
|
|
10523
10511
|
var children = _a.children, brandObj = _a.brandObj, userBrandObj = _a.userBrandObj, brandId = _a.brandId, brandHost = _a.brandHost, account = _a.account, user = _a.user, _b = _a.setPageHead, setPageHead = _b === void 0 ? true : _b, _c = _a.setPostHog, setPostHog = _c === void 0 ? true : _c, LocizeInitializer = _a.LocizeInitializer, brandThemeContext = _a.brandThemeContext, proxyUrl = _a.proxyUrl, _d = _a.styleOverride, styleOverride = _d === void 0 ? {} : _d, _e = _a.includeHandlers, includeHandlers = _e === void 0 ? true : _e;
|
|
10524
10512
|
var _f = React.useState(brandObj ? buildMUITheme({ brand: brandObj }) : undefined), mUITheme = _f[0], setMUITheme = _f[1];
|
|
10525
|
-
var _g = React.useState(brandObj),
|
|
10513
|
+
var _g = React.useState(brandObj), partnerBrand = _g[0], setPartnerBrand = _g[1];
|
|
10526
10514
|
var _h = React.useState(userBrandObj), userBrand = _h[0], setUserBrand = _h[1];
|
|
10527
10515
|
var _j = reactI18next.useTranslation(); _j.t; _j.i18n;
|
|
10528
10516
|
var dialogRef = React.useRef(undefined);
|
|
@@ -10537,7 +10525,7 @@ function GenericWrapper(_a) {
|
|
|
10537
10525
|
var _a, _b;
|
|
10538
10526
|
if (user) {
|
|
10539
10527
|
//@ts-ignore
|
|
10540
|
-
var locale = getBestLocalMatch((_a = user === null || user === void 0 ? void 0 : user.language) === null || _a === void 0 ? void 0 : _a.replace("_", "-"), (_b =
|
|
10528
|
+
var locale = getBestLocalMatch((_a = user === null || user === void 0 ? void 0 : user.language) === null || _a === void 0 ? void 0 : _a.replace("_", "-"), (_b = partnerBrand === null || partnerBrand === void 0 ? void 0 : partnerBrand.client_config) === null || _b === void 0 ? void 0 : _b.languages);
|
|
10541
10529
|
if (LocizeInitializer) {
|
|
10542
10530
|
LocizeInitializer.changeLanguage(locale);
|
|
10543
10531
|
}
|
|
@@ -10581,13 +10569,13 @@ function GenericWrapper(_a) {
|
|
|
10581
10569
|
}
|
|
10582
10570
|
var content = React.createElement(BrandWrapper, { MUITheme: mUITheme, brandId: brandId, styleOverride: styleOverride, brandHost: brandHost, onBrandSuccess: function (compiledBrand, theme) {
|
|
10583
10571
|
initPH(compiledBrand);
|
|
10584
|
-
|
|
10572
|
+
setPartnerBrand(compiledBrand);
|
|
10585
10573
|
setMUITheme(theme);
|
|
10586
10574
|
}, onBrandError: function () {
|
|
10587
10575
|
setMUITheme(buildMUITheme({ brand: whiteLabelBrand }));
|
|
10588
|
-
}, noFetch: !!brandObj, setPageHead: setPageHead, brandThemeContext: brandThemeContext, includeHandlers: false },
|
|
10576
|
+
}, noFetch: !!brandObj, setPageHead: setPageHead, brandThemeContext: brandThemeContext, includeHandlers: false }, partnerBrand &&
|
|
10589
10577
|
React.createElement(GenericWrapperContext.Provider, { value: {
|
|
10590
|
-
partnerBrand:
|
|
10578
|
+
partnerBrand: partnerBrand,
|
|
10591
10579
|
userBrand: userBrand,
|
|
10592
10580
|
account: account ? new AccountModel(account) : new AccountModel({}),
|
|
10593
10581
|
user: user ? new UserModel(user) : new UserModel({})
|
|
@@ -21,6 +21,7 @@ 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;
|
|
@@ -35,10 +36,10 @@ export declare class AccountModel {
|
|
|
35
36
|
}>;
|
|
36
37
|
logOut(): Promise<any>;
|
|
37
38
|
isPartnerOrOrganization(): boolean;
|
|
38
|
-
hasAccessTo({ feature,
|
|
39
|
+
hasAccessTo({ feature, partnerBrand, userCount }: {
|
|
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
|
}
|
|
@@ -9581,56 +9582,43 @@ var AccountModel = /** @class */ (function () {
|
|
|
9581
9582
|
return this.partner || this.organization;
|
|
9582
9583
|
};
|
|
9583
9584
|
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*/];
|
|
9585
|
+
var feature = _a.feature, partnerBrand = _a.partnerBrand, userCount = _a.userCount;
|
|
9586
|
+
var featureValue = this.usage_limits[feature];
|
|
9587
|
+
if (featureValue === undefined) {
|
|
9588
|
+
return false;
|
|
9589
|
+
}
|
|
9590
|
+
var brandDisabledLimitsFeatures = getNestedProperty(partnerBrand, "config.disabledLimitsFeatures") || [];
|
|
9591
|
+
if (brandDisabledLimitsFeatures.includes(feature))
|
|
9592
|
+
return true;
|
|
9593
|
+
if (typeof featureValue === "boolean" || Number.isNaN(featureValue)) {
|
|
9594
|
+
//Some feature flags are inverted
|
|
9595
|
+
if (feature === "insert_reseller_logo") {
|
|
9596
|
+
return !featureValue;
|
|
9597
|
+
}
|
|
9598
|
+
else {
|
|
9599
|
+
return Boolean(featureValue);
|
|
9600
|
+
}
|
|
9601
|
+
}
|
|
9602
|
+
else {
|
|
9603
|
+
if (this.usage) {
|
|
9604
|
+
if (feature === "lists") {
|
|
9605
|
+
return this.usage.current_lists <= featureValue;
|
|
9631
9606
|
}
|
|
9632
|
-
|
|
9633
|
-
|
|
9607
|
+
else if (feature === "users" && userCount !== undefined) {
|
|
9608
|
+
return userCount <= featureValue;
|
|
9609
|
+
}
|
|
9610
|
+
else if (feature === "per_month") {
|
|
9611
|
+
return this.usage.emails_usage <= 100;
|
|
9612
|
+
}
|
|
9613
|
+
else if (feature === "maximum_contacts") {
|
|
9614
|
+
return this.usage.active_contacts <= featureValue;
|
|
9615
|
+
}
|
|
9616
|
+
throw new Error("Requested Feature does not exist in account usage");
|
|
9617
|
+
}
|
|
9618
|
+
else {
|
|
9619
|
+
throw new Error("Usage not fetched, please call getUsageReport() before calling hasAccessTo() with usage-based features");
|
|
9620
|
+
}
|
|
9621
|
+
}
|
|
9634
9622
|
};
|
|
9635
9623
|
return AccountModel;
|
|
9636
9624
|
}());
|
|
@@ -10502,7 +10490,7 @@ var GenericWrapperContext = createContext({
|
|
|
10502
10490
|
function GenericWrapper(_a) {
|
|
10503
10491
|
var children = _a.children, brandObj = _a.brandObj, userBrandObj = _a.userBrandObj, brandId = _a.brandId, brandHost = _a.brandHost, account = _a.account, user = _a.user, _b = _a.setPageHead, setPageHead = _b === void 0 ? true : _b, _c = _a.setPostHog, setPostHog = _c === void 0 ? true : _c, LocizeInitializer = _a.LocizeInitializer, brandThemeContext = _a.brandThemeContext, proxyUrl = _a.proxyUrl, _d = _a.styleOverride, styleOverride = _d === void 0 ? {} : _d, _e = _a.includeHandlers, includeHandlers = _e === void 0 ? true : _e;
|
|
10504
10492
|
var _f = useState(brandObj ? buildMUITheme({ brand: brandObj }) : undefined), mUITheme = _f[0], setMUITheme = _f[1];
|
|
10505
|
-
var _g = useState(brandObj),
|
|
10493
|
+
var _g = useState(brandObj), partnerBrand = _g[0], setPartnerBrand = _g[1];
|
|
10506
10494
|
var _h = useState(userBrandObj), userBrand = _h[0], setUserBrand = _h[1];
|
|
10507
10495
|
var _j = useTranslation(); _j.t; _j.i18n;
|
|
10508
10496
|
var dialogRef = useRef(undefined);
|
|
@@ -10517,7 +10505,7 @@ function GenericWrapper(_a) {
|
|
|
10517
10505
|
var _a, _b;
|
|
10518
10506
|
if (user) {
|
|
10519
10507
|
//@ts-ignore
|
|
10520
|
-
var locale = getBestLocalMatch((_a = user === null || user === void 0 ? void 0 : user.language) === null || _a === void 0 ? void 0 : _a.replace("_", "-"), (_b =
|
|
10508
|
+
var locale = getBestLocalMatch((_a = user === null || user === void 0 ? void 0 : user.language) === null || _a === void 0 ? void 0 : _a.replace("_", "-"), (_b = partnerBrand === null || partnerBrand === void 0 ? void 0 : partnerBrand.client_config) === null || _b === void 0 ? void 0 : _b.languages);
|
|
10521
10509
|
if (LocizeInitializer) {
|
|
10522
10510
|
LocizeInitializer.changeLanguage(locale);
|
|
10523
10511
|
}
|
|
@@ -10561,13 +10549,13 @@ function GenericWrapper(_a) {
|
|
|
10561
10549
|
}
|
|
10562
10550
|
var content = React__default.createElement(BrandWrapper, { MUITheme: mUITheme, brandId: brandId, styleOverride: styleOverride, brandHost: brandHost, onBrandSuccess: function (compiledBrand, theme) {
|
|
10563
10551
|
initPH(compiledBrand);
|
|
10564
|
-
|
|
10552
|
+
setPartnerBrand(compiledBrand);
|
|
10565
10553
|
setMUITheme(theme);
|
|
10566
10554
|
}, onBrandError: function () {
|
|
10567
10555
|
setMUITheme(buildMUITheme({ brand: whiteLabelBrand }));
|
|
10568
|
-
}, noFetch: !!brandObj, setPageHead: setPageHead, brandThemeContext: brandThemeContext, includeHandlers: false },
|
|
10556
|
+
}, noFetch: !!brandObj, setPageHead: setPageHead, brandThemeContext: brandThemeContext, includeHandlers: false }, partnerBrand &&
|
|
10569
10557
|
React__default.createElement(GenericWrapperContext.Provider, { value: {
|
|
10570
|
-
partnerBrand:
|
|
10558
|
+
partnerBrand: partnerBrand,
|
|
10571
10559
|
userBrand: userBrand,
|
|
10572
10560
|
account: account ? new AccountModel(account) : new AccountModel({}),
|
|
10573
10561
|
user: user ? new UserModel(user) : new UserModel({})
|
|
@@ -21,6 +21,7 @@ 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;
|
|
@@ -35,10 +36,10 @@ export declare class AccountModel {
|
|
|
35
36
|
}>;
|
|
36
37
|
logOut(): Promise<any>;
|
|
37
38
|
isPartnerOrOrganization(): boolean;
|
|
38
|
-
hasAccessTo({ feature,
|
|
39
|
+
hasAccessTo({ feature, partnerBrand, userCount }: {
|
|
39
40
|
feature: keyof TAccountLimits;
|
|
40
|
-
|
|
41
|
+
partnerBrand?: TBrand;
|
|
41
42
|
userCount?: number;
|
|
42
|
-
}):
|
|
43
|
+
}): boolean;
|
|
43
44
|
}
|
|
44
45
|
export * from "./types";
|