@b2y/ecommerce-common 1.4.3 → 1.4.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b2y/ecommerce-common",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "E-commerce common library",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,26 @@
1
+ // Brand colour used for {{themeColour}} in transactional email templates
2
+ // (the header band / accent colour) whenever a tenant hasn't set their own
3
+ // TenantSettings.ThemeColour yet.
4
+ const DEFAULT_THEME_COLOUR = '#FFFFFF';
5
+
6
+ /**
7
+ * Resolve the brand colour to use for a tenant's transactional emails.
8
+ *
9
+ * TenantSettings is passed in (not required here) because each service owns
10
+ * its own Sequelize connection/model instance - same dependency-injection
11
+ * convention as TenantSettingsAbstractController.
12
+ *
13
+ * @param {object} TenantSettings the caller's own TenantSettings Sequelize model
14
+ * @param {string} [tenantId] tenant to look up (omit for a platform/admin-only send - resolves straight to the default)
15
+ * @param {string} [override] explicit colour that skips the TenantSettings lookup entirely
16
+ * @returns {Promise<string>} override, else the tenant's TenantSettings.ThemeColour, else DEFAULT_THEME_COLOUR
17
+ */
18
+ const resolveThemeColour = async (TenantSettings, tenantId, override) => {
19
+ if (override) return override;
20
+ if (!tenantId) return DEFAULT_THEME_COLOUR;
21
+
22
+ const settings = await TenantSettings.findOne({ where: { TenantID: tenantId } }).catch(() => null);
23
+ return settings?.ThemeColour || DEFAULT_THEME_COLOUR;
24
+ };
25
+
26
+ module.exports = { DEFAULT_THEME_COLOUR, resolveThemeColour };