@metamask-previews/notification-services-controller 18.2.0-preview-622f3f09 → 18.2.0-preview-44207a4

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 (24) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/NotificationServicesController/index.cjs +3 -1
  3. package/dist/NotificationServicesController/index.cjs.map +1 -1
  4. package/dist/NotificationServicesController/index.d.cts +1 -0
  5. package/dist/NotificationServicesController/index.d.cts.map +1 -1
  6. package/dist/NotificationServicesController/index.d.mts +1 -0
  7. package/dist/NotificationServicesController/index.d.mts.map +1 -1
  8. package/dist/NotificationServicesController/index.mjs +1 -0
  9. package/dist/NotificationServicesController/index.mjs.map +1 -1
  10. package/dist/NotificationServicesController/services/feature-announcements.cjs +6 -24
  11. package/dist/NotificationServicesController/services/feature-announcements.cjs.map +1 -1
  12. package/dist/NotificationServicesController/services/feature-announcements.d.cts.map +1 -1
  13. package/dist/NotificationServicesController/services/feature-announcements.d.mts.map +1 -1
  14. package/dist/NotificationServicesController/services/feature-announcements.mjs +6 -24
  15. package/dist/NotificationServicesController/services/feature-announcements.mjs.map +1 -1
  16. package/dist/NotificationServicesController/utils/isVersionInBounds.cjs +37 -0
  17. package/dist/NotificationServicesController/utils/isVersionInBounds.cjs.map +1 -0
  18. package/dist/NotificationServicesController/utils/isVersionInBounds.d.cts +18 -0
  19. package/dist/NotificationServicesController/utils/isVersionInBounds.d.cts.map +1 -0
  20. package/dist/NotificationServicesController/utils/isVersionInBounds.d.mts +18 -0
  21. package/dist/NotificationServicesController/utils/isVersionInBounds.d.mts.map +1 -0
  22. package/dist/NotificationServicesController/utils/isVersionInBounds.mjs +33 -0
  23. package/dist/NotificationServicesController/utils/isVersionInBounds.mjs.map +1 -0
  24. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+
12
+ - Add exported util `isVersionInBounds` to validate version number is in bounds ([#6793](https://github.com/MetaMask/core/pull/6793))
13
+
10
14
  ## [18.2.0]
11
15
 
12
16
  ### Added
@@ -29,7 +29,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.UI = exports.Mocks = exports.Constants = exports.Processors = exports.Controller = void 0;
32
+ exports.isVersionInBounds = exports.UI = exports.Mocks = exports.Constants = exports.Processors = exports.Controller = void 0;
33
33
  const NotificationServicesController_1 = __importDefault(require("./NotificationServicesController.cjs"));
34
34
  exports.Controller = NotificationServicesController_1.default;
35
35
  const NotificationServicesController = NotificationServicesController_1.default;
@@ -42,4 +42,6 @@ __exportStar(require("./constants/index.cjs"), exports);
42
42
  exports.Mocks = __importStar(require("./mocks/index.cjs"));
43
43
  exports.UI = __importStar(require("./ui/index.cjs"));
44
44
  __exportStar(require("../shared/index.cjs"), exports);
45
+ var isVersionInBounds_1 = require("./utils/isVersionInBounds.cjs");
46
+ Object.defineProperty(exports, "isVersionInBounds", { enumerable: true, get: function () { return isVersionInBounds_1.isVersionInBounds; } });
45
47
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/NotificationServicesController/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0GAA0D;AAGjD,qBAHF,wCAAU,CAGE;AADnB,MAAM,8BAA8B,GAAG,wCAAU,CAAC;AAElD,kBAAe,8BAA8B,CAAC;AAC9C,uEAAiD;AAGjD,qEAA2C;AAC3C,yDAA6B;AAC7B,mEAAyC;AACzC,wDAA4B;AAC5B,2DAAiC;AACjC,qDAA2B;AAC3B,sDAA0B","sourcesContent":["import Controller from './NotificationServicesController';\n\nconst NotificationServicesController = Controller;\nexport { Controller };\nexport default NotificationServicesController;\nexport * from './NotificationServicesController';\nexport type * as Types from './types';\nexport type * from './types';\nexport * as Processors from './processors';\nexport * from './processors';\nexport * as Constants from './constants';\nexport * from './constants';\nexport * as Mocks from './mocks';\nexport * as UI from './ui';\nexport * from '../shared';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/NotificationServicesController/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0GAA0D;AAGjD,qBAHF,wCAAU,CAGE;AADnB,MAAM,8BAA8B,GAAG,wCAAU,CAAC;AAElD,kBAAe,8BAA8B,CAAC;AAC9C,uEAAiD;AAGjD,qEAA2C;AAC3C,yDAA6B;AAC7B,mEAAyC;AACzC,wDAA4B;AAC5B,2DAAiC;AACjC,qDAA2B;AAC3B,sDAA0B;AAC1B,mEAA8D;AAArD,sHAAA,iBAAiB,OAAA","sourcesContent":["import Controller from './NotificationServicesController';\n\nconst NotificationServicesController = Controller;\nexport { Controller };\nexport default NotificationServicesController;\nexport * from './NotificationServicesController';\nexport type * as Types from './types';\nexport type * from './types';\nexport * as Processors from './processors';\nexport * from './processors';\nexport * as Constants from './constants';\nexport * from './constants';\nexport * as Mocks from './mocks';\nexport * as UI from './ui';\nexport * from '../shared';\nexport { isVersionInBounds } from './utils/isVersionInBounds';\n"]}
@@ -12,4 +12,5 @@ export * from "./constants/index.cjs";
12
12
  export * as Mocks from "./mocks/index.cjs";
13
13
  export * as UI from "./ui/index.cjs";
14
14
  export * from "../shared/index.cjs";
15
+ export { isVersionInBounds } from "./utils/isVersionInBounds.cjs";
15
16
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/NotificationServicesController/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,6CAAyC;AAE1D,QAAA,MAAM,8BAA8B,mBAAa,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,8BAA8B,CAAC;AAC9C,qDAAiD;AACjD,YAAY,KAAK,KAAK,0BAAgB;AACtC,uCAA6B;AAC7B,OAAO,KAAK,UAAU,+BAAqB;AAC3C,uCAA6B;AAC7B,OAAO,KAAK,SAAS,8BAAoB;AACzC,sCAA4B;AAC5B,OAAO,KAAK,KAAK,0BAAgB;AACjC,OAAO,KAAK,EAAE,uBAAa;AAC3B,oCAA0B"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/NotificationServicesController/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,6CAAyC;AAE1D,QAAA,MAAM,8BAA8B,mBAAa,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,8BAA8B,CAAC;AAC9C,qDAAiD;AACjD,YAAY,KAAK,KAAK,0BAAgB;AACtC,uCAA6B;AAC7B,OAAO,KAAK,UAAU,+BAAqB;AAC3C,uCAA6B;AAC7B,OAAO,KAAK,SAAS,8BAAoB;AACzC,sCAA4B;AAC5B,OAAO,KAAK,KAAK,0BAAgB;AACjC,OAAO,KAAK,EAAE,uBAAa;AAC3B,oCAA0B;AAC1B,OAAO,EAAE,iBAAiB,EAAE,sCAAkC"}
@@ -12,4 +12,5 @@ export * from "./constants/index.mjs";
12
12
  export * as Mocks from "./mocks/index.mjs";
13
13
  export * as UI from "./ui/index.mjs";
14
14
  export * from "../shared/index.mjs";
15
+ export { isVersionInBounds } from "./utils/isVersionInBounds.mjs";
15
16
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/NotificationServicesController/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,6CAAyC;AAE1D,QAAA,MAAM,8BAA8B,mBAAa,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,8BAA8B,CAAC;AAC9C,qDAAiD;AACjD,YAAY,KAAK,KAAK,0BAAgB;AACtC,uCAA6B;AAC7B,OAAO,KAAK,UAAU,+BAAqB;AAC3C,uCAA6B;AAC7B,OAAO,KAAK,SAAS,8BAAoB;AACzC,sCAA4B;AAC5B,OAAO,KAAK,KAAK,0BAAgB;AACjC,OAAO,KAAK,EAAE,uBAAa;AAC3B,oCAA0B"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/NotificationServicesController/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,6CAAyC;AAE1D,QAAA,MAAM,8BAA8B,mBAAa,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,8BAA8B,CAAC;AAC9C,qDAAiD;AACjD,YAAY,KAAK,KAAK,0BAAgB;AACtC,uCAA6B;AAC7B,OAAO,KAAK,UAAU,+BAAqB;AAC3C,uCAA6B;AAC7B,OAAO,KAAK,SAAS,8BAAoB;AACzC,sCAA4B;AAC5B,OAAO,KAAK,KAAK,0BAAgB;AACjC,OAAO,KAAK,EAAE,uBAAa;AAC3B,oCAA0B;AAC1B,OAAO,EAAE,iBAAiB,EAAE,sCAAkC"}
@@ -10,4 +10,5 @@ export * from "./constants/index.mjs";
10
10
  export * as Mocks from "./mocks/index.mjs";
11
11
  export * as UI from "./ui/index.mjs";
12
12
  export * from "../shared/index.mjs";
13
+ export { isVersionInBounds } from "./utils/isVersionInBounds.mjs";
13
14
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/NotificationServicesController/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,6CAAyC;AAE1D,MAAM,8BAA8B,GAAG,UAAU,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,8BAA8B,CAAC;AAC9C,qDAAiD;AAGjD,OAAO,KAAK,UAAU,+BAAqB;AAC3C,uCAA6B;AAC7B,OAAO,KAAK,SAAS,8BAAoB;AACzC,sCAA4B;AAC5B,OAAO,KAAK,KAAK,0BAAgB;AACjC,OAAO,KAAK,EAAE,uBAAa;AAC3B,oCAA0B","sourcesContent":["import Controller from './NotificationServicesController';\n\nconst NotificationServicesController = Controller;\nexport { Controller };\nexport default NotificationServicesController;\nexport * from './NotificationServicesController';\nexport type * as Types from './types';\nexport type * from './types';\nexport * as Processors from './processors';\nexport * from './processors';\nexport * as Constants from './constants';\nexport * from './constants';\nexport * as Mocks from './mocks';\nexport * as UI from './ui';\nexport * from '../shared';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/NotificationServicesController/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,6CAAyC;AAE1D,MAAM,8BAA8B,GAAG,UAAU,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,8BAA8B,CAAC;AAC9C,qDAAiD;AAGjD,OAAO,KAAK,UAAU,+BAAqB;AAC3C,uCAA6B;AAC7B,OAAO,KAAK,SAAS,8BAAoB;AACzC,sCAA4B;AAC5B,OAAO,KAAK,KAAK,0BAAgB;AACjC,OAAO,KAAK,EAAE,uBAAa;AAC3B,oCAA0B;AAC1B,OAAO,EAAE,iBAAiB,EAAE,sCAAkC","sourcesContent":["import Controller from './NotificationServicesController';\n\nconst NotificationServicesController = Controller;\nexport { Controller };\nexport default NotificationServicesController;\nexport * from './NotificationServicesController';\nexport type * as Types from './types';\nexport type * from './types';\nexport * as Processors from './processors';\nexport * from './processors';\nexport * as Constants from './constants';\nexport * from './constants';\nexport * as Mocks from './mocks';\nexport * as UI from './ui';\nexport * from '../shared';\nexport { isVersionInBounds } from './utils/isVersionInBounds';\n"]}
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFeatureAnnouncementNotifications = exports.getFeatureAnnouncementUrl = exports.FEATURE_ANNOUNCEMENT_URL = exports.FEATURE_ANNOUNCEMENT_API = void 0;
4
4
  const rich_text_html_renderer_1 = require("@contentful/rich-text-html-renderer");
5
- const semver_1 = require("semver");
6
5
  const notification_schema_1 = require("../constants/notification-schema.cjs");
7
6
  const process_feature_announcement_1 = require("../processors/process-feature-announcement.cjs");
7
+ const isVersionInBounds_1 = require("../utils/isVersionInBounds.cjs");
8
8
  const DEFAULT_SPACE_ID = ':space_id';
9
9
  const DEFAULT_ACCESS_TOKEN = ':access_token';
10
10
  const DEFAULT_CLIENT_ID = ':client_id';
@@ -104,29 +104,11 @@ const fetchFeatureAnnouncementNotifications = async (env, previewToken) => {
104
104
  const filteredRawNotifications = rawNotifications.filter((n) => {
105
105
  const minVersion = n.data?.[versionKeys[env.platform].min];
106
106
  const maxVersion = n.data?.[versionKeys[env.platform].max];
107
- // If no platform version is provided, show all notifications
108
- if (!env.platformVersion) {
109
- return true;
110
- }
111
- // min/max filtering
112
- try {
113
- let showNotification = true;
114
- // Check minimum version: current version must be greater than minimum
115
- if (minVersion) {
116
- showNotification =
117
- showNotification && (0, semver_1.gt)(env.platformVersion, minVersion);
118
- }
119
- // Check maximum version: current version must be less than maximum
120
- if (maxVersion) {
121
- showNotification =
122
- showNotification && (0, semver_1.lt)(env.platformVersion, maxVersion);
123
- }
124
- return showNotification;
125
- }
126
- catch {
127
- // something went wrong filtering, do not show notification
128
- return false;
129
- }
107
+ return (0, isVersionInBounds_1.isVersionInBounds)({
108
+ currentVersion: env.platformVersion,
109
+ minVersion,
110
+ maxVersion,
111
+ });
130
112
  });
131
113
  return filteredRawNotifications;
132
114
  };
@@ -1 +1 @@
1
- {"version":3,"file":"feature-announcements.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/feature-announcements.ts"],"names":[],"mappings":";;;AAAA,iFAA2E;AAE3E,mCAAgC;AAEhC,8EAAiE;AACjE,iGAAwF;AAcxF,MAAM,gBAAgB,GAAG,WAAW,CAAC;AACrC,MAAM,oBAAoB,GAAG,eAAe,CAAC;AAC7C,MAAM,iBAAiB,GAAG,YAAY,CAAC;AACvC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAC5C,MAAM,cAAc,GAAG,wBAAwB,CAAC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YAAqB;IAErB,IAAI,GAAG,EAAE,WAAW,IAAI,GAAG,EAAE,OAAO,IAAI,GAAG,EAAE,QAAQ,EAAE;QACrD,MAAM,gBAAgB,GAAG,MAAM,qCAAqC,CAClE,GAAG,EACH,YAAY,CACb,CAAC;QACF,MAAM,aAAa,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAC1D,IAAA,yDAA0B,EAAC,YAAY,CAAC,CACzC,CAAC;QAEF,OAAO,aAAa,CAAC;KACtB;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAjBD,kFAiBC","sourcesContent":["import { documentToHtmlString } from '@contentful/rich-text-html-renderer';\nimport type { Entry, Asset, EntryCollection } from 'contentful';\nimport { gt, lt } from 'semver';\n\nimport { TRIGGER_TYPES } from '../constants/notification-schema';\nimport { processFeatureAnnouncement } from '../processors/process-feature-announcement';\nimport type { FeatureAnnouncementRawNotification } from '../types/feature-announcement/feature-announcement';\nimport type {\n ImageFields,\n TypeFeatureAnnouncement,\n} from '../types/feature-announcement/type-feature-announcement';\nimport type {\n TypeExternalLinkFields,\n TypePortfolioLinkFields,\n TypeExtensionLinkFields,\n TypeMobileLinkFields,\n} from '../types/feature-announcement/type-links';\nimport type { INotification } from '../types/notification/notification';\n\nconst DEFAULT_SPACE_ID = ':space_id';\nconst DEFAULT_ACCESS_TOKEN = ':access_token';\nconst DEFAULT_CLIENT_ID = ':client_id';\nconst DEFAULT_DOMAIN = 'cdn.contentful.com';\nconst PREVIEW_DOMAIN = 'preview.contentful.com';\nexport const FEATURE_ANNOUNCEMENT_API = `https://${DEFAULT_DOMAIN}/spaces/${DEFAULT_SPACE_ID}/environments/master/entries`;\nexport const FEATURE_ANNOUNCEMENT_URL = `${FEATURE_ANNOUNCEMENT_API}?access_token=${DEFAULT_ACCESS_TOKEN}&content_type=productAnnouncement&include=10&fields.clients[in]=${DEFAULT_CLIENT_ID}`;\n\ntype Env = {\n spaceId: string;\n accessToken: string;\n platform: 'extension' | 'mobile';\n platformVersion?: string;\n};\n\n/**\n * Contentful API Response Shape\n */\nexport type ContentfulResult = {\n includes?: {\n Entry?: Entry[];\n Asset?: Asset[];\n };\n items?: TypeFeatureAnnouncement[];\n};\n\nexport const getFeatureAnnouncementUrl = (env: Env, previewToken?: string) => {\n const domain = previewToken ? PREVIEW_DOMAIN : DEFAULT_DOMAIN;\n const replacedUrl = FEATURE_ANNOUNCEMENT_URL.replace(\n DEFAULT_SPACE_ID,\n env.spaceId,\n )\n .replace(DEFAULT_ACCESS_TOKEN, previewToken || env.accessToken)\n .replace(DEFAULT_CLIENT_ID, env.platform)\n .replace(DEFAULT_DOMAIN, domain);\n return encodeURI(replacedUrl);\n};\n\nconst fetchFeatureAnnouncementNotifications = async (\n env: Env,\n previewToken?: string,\n): Promise<FeatureAnnouncementRawNotification[]> => {\n const url = getFeatureAnnouncementUrl(env, previewToken);\n\n const data = await fetch(url)\n .then((r) => r.json())\n .catch(() => null);\n\n if (!data) {\n return [];\n }\n\n const findIncludedItem = (sysId: string) => {\n const typedData: EntryCollection<\n | ImageFields\n | TypeExtensionLinkFields\n | TypePortfolioLinkFields\n | TypeMobileLinkFields\n | TypeExternalLinkFields\n > = data;\n const item =\n typedData?.includes?.Entry?.find((i: Entry) => i?.sys?.id === sysId) ||\n typedData?.includes?.Asset?.find((i: Asset) => i?.sys?.id === sysId);\n return item ? item?.fields : null;\n };\n\n const contentfulNotifications = data?.items ?? [];\n const rawNotifications: FeatureAnnouncementRawNotification[] =\n contentfulNotifications.map((n: TypeFeatureAnnouncement) => {\n const { fields } = n;\n const imageFields = fields.image\n ? (findIncludedItem(fields.image.sys.id) as ImageFields['fields'])\n : undefined;\n\n const externalLinkFields = fields.externalLink\n ? (findIncludedItem(\n fields.externalLink.sys.id,\n ) as TypeExternalLinkFields['fields'])\n : undefined;\n const portfolioLinkFields = fields.portfolioLink\n ? (findIncludedItem(\n fields.portfolioLink.sys.id,\n ) as TypePortfolioLinkFields['fields'])\n : undefined;\n const extensionLinkFields = fields.extensionLink\n ? (findIncludedItem(\n fields.extensionLink.sys.id,\n ) as TypeExtensionLinkFields['fields'])\n : undefined;\n const mobileLinkFields = fields.mobileLink\n ? (findIncludedItem(\n fields.mobileLink.sys.id,\n ) as TypeMobileLinkFields['fields'])\n : undefined;\n\n const notification: FeatureAnnouncementRawNotification = {\n type: TRIGGER_TYPES.FEATURES_ANNOUNCEMENT,\n createdAt: new Date(n.sys.createdAt).toString(),\n data: {\n id: fields.id,\n category: fields.category,\n title: fields.title,\n longDescription: documentToHtmlString(fields.longDescription),\n shortDescription: fields.shortDescription,\n image: {\n title: imageFields?.title,\n description: imageFields?.description,\n url: imageFields?.file?.url ?? '',\n },\n externalLink: externalLinkFields && {\n externalLinkText: externalLinkFields?.externalLinkText,\n externalLinkUrl: externalLinkFields?.externalLinkUrl,\n },\n portfolioLink: portfolioLinkFields && {\n portfolioLinkText: portfolioLinkFields?.portfolioLinkText,\n portfolioLinkUrl: portfolioLinkFields?.portfolioLinkUrl,\n },\n extensionLink: extensionLinkFields && {\n extensionLinkText: extensionLinkFields?.extensionLinkText,\n extensionLinkRoute: extensionLinkFields?.extensionLinkRoute,\n },\n mobileLink: mobileLinkFields && {\n mobileLinkText: mobileLinkFields?.mobileLinkText,\n mobileLinkUrl: mobileLinkFields?.mobileLinkUrl,\n },\n extensionMinimumVersionNumber: fields.extensionMinimumVersionNumber,\n mobileMinimumVersionNumber: fields.mobileMinimumVersionNumber,\n extensionMaximumVersionNumber: fields.extensionMaximumVersionNumber,\n mobileMaximumVersionNumber: fields.mobileMaximumVersionNumber,\n },\n };\n\n return notification;\n });\n\n const versionKeys = {\n extension: {\n min: 'extensionMinimumVersionNumber',\n max: 'extensionMaximumVersionNumber',\n },\n mobile: {\n min: 'mobileMinimumVersionNumber',\n max: 'mobileMaximumVersionNumber',\n },\n } as const;\n\n const filteredRawNotifications = rawNotifications.filter((n) => {\n const minVersion = n.data?.[versionKeys[env.platform].min];\n const maxVersion = n.data?.[versionKeys[env.platform].max];\n\n // If no platform version is provided, show all notifications\n if (!env.platformVersion) {\n return true;\n }\n\n // min/max filtering\n try {\n let showNotification = true;\n\n // Check minimum version: current version must be greater than minimum\n if (minVersion) {\n showNotification =\n showNotification && gt(env.platformVersion, minVersion);\n }\n\n // Check maximum version: current version must be less than maximum\n if (maxVersion) {\n showNotification =\n showNotification && lt(env.platformVersion, maxVersion);\n }\n\n return showNotification;\n } catch {\n // something went wrong filtering, do not show notification\n return false;\n }\n });\n\n return filteredRawNotifications;\n};\n\n/**\n * Gets Feature Announcement from our services\n *\n * @param env - environment for feature announcements\n * @param previewToken - the preview token to use if needed\n * @returns Raw Feature Announcements\n */\nexport async function getFeatureAnnouncementNotifications(\n env: Env,\n previewToken?: string,\n): Promise<INotification[]> {\n if (env?.accessToken && env?.spaceId && env?.platform) {\n const rawNotifications = await fetchFeatureAnnouncementNotifications(\n env,\n previewToken,\n );\n const notifications = rawNotifications.map((notification) =>\n processFeatureAnnouncement(notification),\n );\n\n return notifications;\n }\n\n return [];\n}\n"]}
1
+ {"version":3,"file":"feature-announcements.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/feature-announcements.ts"],"names":[],"mappings":";;;AAAA,iFAA2E;AAG3E,8EAAiE;AACjE,iGAAwF;AAaxF,sEAA+D;AAE/D,MAAM,gBAAgB,GAAG,WAAW,CAAC;AACrC,MAAM,oBAAoB,GAAG,eAAe,CAAC;AAC7C,MAAM,iBAAiB,GAAG,YAAY,CAAC;AACvC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAC5C,MAAM,cAAc,GAAG,wBAAwB,CAAC;AACnC,QAAA,wBAAwB,GAAG,WAAW,cAAc,WAAW,gBAAgB,8BAA8B,CAAC;AAC9G,QAAA,wBAAwB,GAAG,GAAG,gCAAwB,iBAAiB,oBAAoB,mEAAmE,iBAAiB,EAAE,CAAC;AAoBxL,MAAM,yBAAyB,GAAG,CAAC,GAAQ,EAAE,YAAqB,EAAE,EAAE;IAC3E,M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ACjC,GAAG,EAAE,4BAA4B;SAClC;KACO,CAAC;IAEX,MAAM,wBAAwB,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;QAC7D,MAAM,UAAU,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC;QAC3D,MAAM,UAAU,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC;QAC3D,OAAO,IAAA,qCAAiB,EAAC;YACvB,cAAc,EAAE,GAAG,CAAC,eAAe;YACnC,UAAU;YACV,UAAU;SACX,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,wBAAwB,CAAC;AAClC,CAAC,CAAC;AAEF;;;;;;GAMG;AACI,KAAK,UAAU,mCAAmC,CACvD,GAAQ,EACR,YAAqB;IAErB,IAAI,GAAG,EAAE,WAAW,IAAI,GAAG,EAAE,OAAO,IAAI,GAAG,EAAE,QAAQ,EAAE;QACrD,MAAM,gBAAgB,GAAG,MAAM,qCAAqC,CAClE,GAAG,EACH,YAAY,CACb,CAAC;QACF,MAAM,aAAa,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAC1D,IAAA,yDAA0B,EAAC,YAAY,CAAC,CACzC,CAAC;QAEF,OAAO,aAAa,CAAC;KACtB;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAjBD,kFAiBC","sourcesContent":["import { documentToHtmlString } from '@contentful/rich-text-html-renderer';\nimport type { Entry, Asset, EntryCollection } from 'contentful';\n\nimport { TRIGGER_TYPES } from '../constants/notification-schema';\nimport { processFeatureAnnouncement } from '../processors/process-feature-announcement';\nimport type { FeatureAnnouncementRawNotification } from '../types/feature-announcement/feature-announcement';\nimport type {\n ImageFields,\n TypeFeatureAnnouncement,\n} from '../types/feature-announcement/type-feature-announcement';\nimport type {\n TypeExternalLinkFields,\n TypePortfolioLinkFields,\n TypeExtensionLinkFields,\n TypeMobileLinkFields,\n} from '../types/feature-announcement/type-links';\nimport type { INotification } from '../types/notification/notification';\nimport { isVersionInBounds } from '../utils/isVersionInBounds';\n\nconst DEFAULT_SPACE_ID = ':space_id';\nconst DEFAULT_ACCESS_TOKEN = ':access_token';\nconst DEFAULT_CLIENT_ID = ':client_id';\nconst DEFAULT_DOMAIN = 'cdn.contentful.com';\nconst PREVIEW_DOMAIN = 'preview.contentful.com';\nexport const FEATURE_ANNOUNCEMENT_API = `https://${DEFAULT_DOMAIN}/spaces/${DEFAULT_SPACE_ID}/environments/master/entries`;\nexport const FEATURE_ANNOUNCEMENT_URL = `${FEATURE_ANNOUNCEMENT_API}?access_token=${DEFAULT_ACCESS_TOKEN}&content_type=productAnnouncement&include=10&fields.clients[in]=${DEFAULT_CLIENT_ID}`;\n\ntype Env = {\n spaceId: string;\n accessToken: string;\n platform: 'extension' | 'mobile';\n platformVersion?: string;\n};\n\n/**\n * Contentful API Response Shape\n */\nexport type ContentfulResult = {\n includes?: {\n Entry?: Entry[];\n Asset?: Asset[];\n };\n items?: TypeFeatureAnnouncement[];\n};\n\nexport const getFeatureAnnouncementUrl = (env: Env, previewToken?: string) => {\n const domain = previewToken ? PREVIEW_DOMAIN : DEFAULT_DOMAIN;\n const replacedUrl = FEATURE_ANNOUNCEMENT_URL.replace(\n DEFAULT_SPACE_ID,\n env.spaceId,\n )\n .replace(DEFAULT_ACCESS_TOKEN, previewToken || env.accessToken)\n .replace(DEFAULT_CLIENT_ID, env.platform)\n .replace(DEFAULT_DOMAIN, domain);\n return encodeURI(replacedUrl);\n};\n\nconst fetchFeatureAnnouncementNotifications = async (\n env: Env,\n previewToken?: string,\n): Promise<FeatureAnnouncementRawNotification[]> => {\n const url = getFeatureAnnouncementUrl(env, previewToken);\n\n const data = await fetch(url)\n .then((r) => r.json())\n .catch(() => null);\n\n if (!data) {\n return [];\n }\n\n const findIncludedItem = (sysId: string) => {\n const typedData: EntryCollection<\n | ImageFields\n | TypeExtensionLinkFields\n | TypePortfolioLinkFields\n | TypeMobileLinkFields\n | TypeExternalLinkFields\n > = data;\n const item =\n typedData?.includes?.Entry?.find((i: Entry) => i?.sys?.id === sysId) ||\n typedData?.includes?.Asset?.find((i: Asset) => i?.sys?.id === sysId);\n return item ? item?.fields : null;\n };\n\n const contentfulNotifications = data?.items ?? [];\n const rawNotifications: FeatureAnnouncementRawNotification[] =\n contentfulNotifications.map((n: TypeFeatureAnnouncement) => {\n const { fields } = n;\n const imageFields = fields.image\n ? (findIncludedItem(fields.image.sys.id) as ImageFields['fields'])\n : undefined;\n\n const externalLinkFields = fields.externalLink\n ? (findIncludedItem(\n fields.externalLink.sys.id,\n ) as TypeExternalLinkFields['fields'])\n : undefined;\n const portfolioLinkFields = fields.portfolioLink\n ? (findIncludedItem(\n fields.portfolioLink.sys.id,\n ) as TypePortfolioLinkFields['fields'])\n : undefined;\n const extensionLinkFields = fields.extensionLink\n ? (findIncludedItem(\n fields.extensionLink.sys.id,\n ) as TypeExtensionLinkFields['fields'])\n : undefined;\n const mobileLinkFields = fields.mobileLink\n ? (findIncludedItem(\n fields.mobileLink.sys.id,\n ) as TypeMobileLinkFields['fields'])\n : undefined;\n\n const notification: FeatureAnnouncementRawNotification = {\n type: TRIGGER_TYPES.FEATURES_ANNOUNCEMENT,\n createdAt: new Date(n.sys.createdAt).toString(),\n data: {\n id: fields.id,\n category: fields.category,\n title: fields.title,\n longDescription: documentToHtmlString(fields.longDescription),\n shortDescription: fields.shortDescription,\n image: {\n title: imageFields?.title,\n description: imageFields?.description,\n url: imageFields?.file?.url ?? '',\n },\n externalLink: externalLinkFields && {\n externalLinkText: externalLinkFields?.externalLinkText,\n externalLinkUrl: externalLinkFields?.externalLinkUrl,\n },\n portfolioLink: portfolioLinkFields && {\n portfolioLinkText: portfolioLinkFields?.portfolioLinkText,\n portfolioLinkUrl: portfolioLinkFields?.portfolioLinkUrl,\n },\n extensionLink: extensionLinkFields && {\n extensionLinkText: extensionLinkFields?.extensionLinkText,\n extensionLinkRoute: extensionLinkFields?.extensionLinkRoute,\n },\n mobileLink: mobileLinkFields && {\n mobileLinkText: mobileLinkFields?.mobileLinkText,\n mobileLinkUrl: mobileLinkFields?.mobileLinkUrl,\n },\n extensionMinimumVersionNumber: fields.extensionMinimumVersionNumber,\n mobileMinimumVersionNumber: fields.mobileMinimumVersionNumber,\n extensionMaximumVersionNumber: fields.extensionMaximumVersionNumber,\n mobileMaximumVersionNumber: fields.mobileMaximumVersionNumber,\n },\n };\n\n return notification;\n });\n\n const versionKeys = {\n extension: {\n min: 'extensionMinimumVersionNumber',\n max: 'extensionMaximumVersionNumber',\n },\n mobile: {\n min: 'mobileMinimumVersionNumber',\n max: 'mobileMaximumVersionNumber',\n },\n } as const;\n\n const filteredRawNotifications = rawNotifications.filter((n) => {\n const minVersion = n.data?.[versionKeys[env.platform].min];\n const maxVersion = n.data?.[versionKeys[env.platform].max];\n return isVersionInBounds({\n currentVersion: env.platformVersion,\n minVersion,\n maxVersion,\n });\n });\n\n return filteredRawNotifications;\n};\n\n/**\n * Gets Feature Announcement from our services\n *\n * @param env - environment for feature announcements\n * @param previewToken - the preview token to use if needed\n * @returns Raw Feature Announcements\n */\nexport async function getFeatureAnnouncementNotifications(\n env: Env,\n previewToken?: string,\n): Promise<INotification[]> {\n if (env?.accessToken && env?.spaceId && env?.platform) {\n const rawNotifications = await fetchFeatureAnnouncementNotifications(\n env,\n previewToken,\n );\n const notifications = rawNotifications.map((notification) =>\n processFeatureAnnouncement(notification),\n );\n\n return notifications;\n }\n\n return [];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"feature-announcements.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/feature-announcements.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAmB,mBAAmB;AAMhE,OAAO,KAAK,EAEV,uBAAuB,EACxB,oEAAgE;AAOjE,OAAO,KAAK,EAAE,aAAa,EAAE,+CAA2C;AAOxE,eAAO,MAAM,wBAAwB,4EAAqF,CAAC;AAC3H,eAAO,MAAM,wBAAwB,iLAAyJ,CAAC;AAE/L,KAAK,GAAG,GAAG;IACT,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,WAAW,GAAG,QAAQ,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;QAChB,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;KACjB,CAAC;IACF,KAAK,CAAC,EAAE,uBAAuB,EAAE,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAAS,GAAG,iBAAiB,MAAM,WAUxE,CAAC;AAiJF;;;;;;GAMG;AACH,wBAAsB,mCAAmC,CACvD,GAAG,EAAE,GAAG,EACR,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,aAAa,EAAE,CAAC,CAc1B"}
1
+ {"version":3,"file":"feature-announcements.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/feature-announcements.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAmB,mBAAmB;AAKhE,OAAO,KAAK,EAEV,uBAAuB,EACxB,oEAAgE;AAOjE,OAAO,KAAK,EAAE,aAAa,EAAE,+CAA2C;AAQxE,eAAO,MAAM,wBAAwB,4EAAqF,CAAC;AAC3H,eAAO,MAAM,wBAAwB,iLAAyJ,CAAC;AAE/L,KAAK,GAAG,GAAG;IACT,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,WAAW,GAAG,QAAQ,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;QAChB,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;KACjB,CAAC;IACF,KAAK,CAAC,EAAE,uBAAuB,EAAE,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAAS,GAAG,iBAAiB,MAAM,WAUxE,CAAC;AA2HF;;;;;;GAMG;AACH,wBAAsB,mCAAmC,CACvD,GAAG,EAAE,GAAG,EACR,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,aAAa,EAAE,CAAC,CAc1B"}
@@ -1 +1 @@
1
- {"version":3,"file":"feature-announcements.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/feature-announcements.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAmB,mBAAmB;AAMhE,OAAO,KAAK,EAEV,uBAAuB,EACxB,oEAAgE;AAOjE,OAAO,KAAK,EAAE,aAAa,EAAE,+CAA2C;AAOxE,eAAO,MAAM,wBAAwB,4EAAqF,CAAC;AAC3H,eAAO,MAAM,wBAAwB,iLAAyJ,CAAC;AAE/L,KAAK,GAAG,GAAG;IACT,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,WAAW,GAAG,QAAQ,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;QAChB,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;KACjB,CAAC;IACF,KAAK,CAAC,EAAE,uBAAuB,EAAE,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAAS,GAAG,iBAAiB,MAAM,WAUxE,CAAC;AAiJF;;;;;;GAMG;AACH,wBAAsB,mCAAmC,CACvD,GAAG,EAAE,GAAG,EACR,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,aAAa,EAAE,CAAC,CAc1B"}
1
+ {"version":3,"file":"feature-announcements.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/feature-announcements.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAmB,mBAAmB;AAKhE,OAAO,KAAK,EAEV,uBAAuB,EACxB,oEAAgE;AAOjE,OAAO,KAAK,EAAE,aAAa,EAAE,+CAA2C;AAQxE,eAAO,MAAM,wBAAwB,4EAAqF,CAAC;AAC3H,eAAO,MAAM,wBAAwB,iLAAyJ,CAAC;AAE/L,KAAK,GAAG,GAAG;IACT,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,WAAW,GAAG,QAAQ,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;QAChB,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;KACjB,CAAC;IACF,KAAK,CAAC,EAAE,uBAAuB,EAAE,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAAS,GAAG,iBAAiB,MAAM,WAUxE,CAAC;AA2HF;;;;;;GAMG;AACH,wBAAsB,mCAAmC,CACvD,GAAG,EAAE,GAAG,EACR,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,aAAa,EAAE,CAAC,CAc1B"}
@@ -1,7 +1,7 @@
1
1
  import { documentToHtmlString } from "@contentful/rich-text-html-renderer";
2
- import { gt, lt } from "semver";
3
2
  import { TRIGGER_TYPES } from "../constants/notification-schema.mjs";
4
3
  import { processFeatureAnnouncement } from "../processors/process-feature-announcement.mjs";
4
+ import { isVersionInBounds } from "../utils/isVersionInBounds.mjs";
5
5
  const DEFAULT_SPACE_ID = ':space_id';
6
6
  const DEFAULT_ACCESS_TOKEN = ':access_token';
7
7
  const DEFAULT_CLIENT_ID = ':client_id';
@@ -100,29 +100,11 @@ const fetchFeatureAnnouncementNotifications = async (env, previewToken) => {
100
100
  const filteredRawNotifications = rawNotifications.filter((n) => {
101
101
  const minVersion = n.data?.[versionKeys[env.platform].min];
102
102
  const maxVersion = n.data?.[versionKeys[env.platform].max];
103
- // If no platform version is provided, show all notifications
104
- if (!env.platformVersion) {
105
- return true;
106
- }
107
- // min/max filtering
108
- try {
109
- let showNotification = true;
110
- // Check minimum version: current version must be greater than minimum
111
- if (minVersion) {
112
- showNotification =
113
- showNotification && gt(env.platformVersion, minVersion);
114
- }
115
- // Check maximum version: current version must be less than maximum
116
- if (maxVersion) {
117
- showNotification =
118
- showNotification && lt(env.platformVersion, maxVersion);
119
- }
120
- return showNotification;
121
- }
122
- catch {
123
- // something went wrong filtering, do not show notification
124
- return false;
125
- }
103
+ return isVersionInBounds({
104
+ currentVersion: env.platformVersion,
105
+ minVersion,
106
+ maxVersion,
107
+ });
126
108
  });
127
109
  return filteredRawNotifications;
128
110
  };
@@ -1 +1 @@
1
- {"version":3,"file":"feature-announcements.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/feature-announcements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,4CAA4C;AAE3E,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,eAAe;AAEhC,OAAO,EAAE,aAAa,EAAE,6CAAyC;AACjE,OAAO,EAAE,0BAA0B,EAAE,uDAAmD;AAcxF,MAAM,gBAAgB,GAAG,WAAW,CAAC;AACrC,MAAM,oBAAoB,GAAG,eAAe,CAAC;AAC7C,MAAM,iBAAiB,GAAG,YAAY,CAAC;AACvC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAC5C,M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AAmC,CACvD,GAAQ,EACR,YAAqB;IAErB,IAAI,GAAG,EAAE,WAAW,IAAI,GAAG,EAAE,OAAO,IAAI,GAAG,EAAE,QAAQ,EAAE;QACrD,MAAM,gBAAgB,GAAG,MAAM,qCAAqC,CAClE,GAAG,EACH,YAAY,CACb,CAAC;QACF,MAAM,aAAa,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAC1D,0BAA0B,CAAC,YAAY,CAAC,CACzC,CAAC;QAEF,OAAO,aAAa,CAAC;KACtB;IAED,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["import { documentToHtmlString } from '@contentful/rich-text-html-renderer';\nimport type { Entry, Asset, EntryCollection } from 'contentful';\nimport { gt, lt } from 'semver';\n\nimport { TRIGGER_TYPES } from '../constants/notification-schema';\nimport { processFeatureAnnouncement } from '../processors/process-feature-announcement';\nimport type { FeatureAnnouncementRawNotification } from '../types/feature-announcement/feature-announcement';\nimport type {\n ImageFields,\n TypeFeatureAnnouncement,\n} from '../types/feature-announcement/type-feature-announcement';\nimport type {\n TypeExternalLinkFields,\n TypePortfolioLinkFields,\n TypeExtensionLinkFields,\n TypeMobileLinkFields,\n} from '../types/feature-announcement/type-links';\nimport type { INotification } from '../types/notification/notification';\n\nconst DEFAULT_SPACE_ID = ':space_id';\nconst DEFAULT_ACCESS_TOKEN = ':access_token';\nconst DEFAULT_CLIENT_ID = ':client_id';\nconst DEFAULT_DOMAIN = 'cdn.contentful.com';\nconst PREVIEW_DOMAIN = 'preview.contentful.com';\nexport const FEATURE_ANNOUNCEMENT_API = `https://${DEFAULT_DOMAIN}/spaces/${DEFAULT_SPACE_ID}/environments/master/entries`;\nexport const FEATURE_ANNOUNCEMENT_URL = `${FEATURE_ANNOUNCEMENT_API}?access_token=${DEFAULT_ACCESS_TOKEN}&content_type=productAnnouncement&include=10&fields.clients[in]=${DEFAULT_CLIENT_ID}`;\n\ntype Env = {\n spaceId: string;\n accessToken: string;\n platform: 'extension' | 'mobile';\n platformVersion?: string;\n};\n\n/**\n * Contentful API Response Shape\n */\nexport type ContentfulResult = {\n includes?: {\n Entry?: Entry[];\n Asset?: Asset[];\n };\n items?: TypeFeatureAnnouncement[];\n};\n\nexport const getFeatureAnnouncementUrl = (env: Env, previewToken?: string) => {\n const domain = previewToken ? PREVIEW_DOMAIN : DEFAULT_DOMAIN;\n const replacedUrl = FEATURE_ANNOUNCEMENT_URL.replace(\n DEFAULT_SPACE_ID,\n env.spaceId,\n )\n .replace(DEFAULT_ACCESS_TOKEN, previewToken || env.accessToken)\n .replace(DEFAULT_CLIENT_ID, env.platform)\n .replace(DEFAULT_DOMAIN, domain);\n return encodeURI(replacedUrl);\n};\n\nconst fetchFeatureAnnouncementNotifications = async (\n env: Env,\n previewToken?: string,\n): Promise<FeatureAnnouncementRawNotification[]> => {\n const url = getFeatureAnnouncementUrl(env, previewToken);\n\n const data = await fetch(url)\n .then((r) => r.json())\n .catch(() => null);\n\n if (!data) {\n return [];\n }\n\n const findIncludedItem = (sysId: string) => {\n const typedData: EntryCollection<\n | ImageFields\n | TypeExtensionLinkFields\n | TypePortfolioLinkFields\n | TypeMobileLinkFields\n | TypeExternalLinkFields\n > = data;\n const item =\n typedData?.includes?.Entry?.find((i: Entry) => i?.sys?.id === sysId) ||\n typedData?.includes?.Asset?.find((i: Asset) => i?.sys?.id === sysId);\n return item ? item?.fields : null;\n };\n\n const contentfulNotifications = data?.items ?? [];\n const rawNotifications: FeatureAnnouncementRawNotification[] =\n contentfulNotifications.map((n: TypeFeatureAnnouncement) => {\n const { fields } = n;\n const imageFields = fields.image\n ? (findIncludedItem(fields.image.sys.id) as ImageFields['fields'])\n : undefined;\n\n const externalLinkFields = fields.externalLink\n ? (findIncludedItem(\n fields.externalLink.sys.id,\n ) as TypeExternalLinkFields['fields'])\n : undefined;\n const portfolioLinkFields = fields.portfolioLink\n ? (findIncludedItem(\n fields.portfolioLink.sys.id,\n ) as TypePortfolioLinkFields['fields'])\n : undefined;\n const extensionLinkFields = fields.extensionLink\n ? (findIncludedItem(\n fields.extensionLink.sys.id,\n ) as TypeExtensionLinkFields['fields'])\n : undefined;\n const mobileLinkFields = fields.mobileLink\n ? (findIncludedItem(\n fields.mobileLink.sys.id,\n ) as TypeMobileLinkFields['fields'])\n : undefined;\n\n const notification: FeatureAnnouncementRawNotification = {\n type: TRIGGER_TYPES.FEATURES_ANNOUNCEMENT,\n createdAt: new Date(n.sys.createdAt).toString(),\n data: {\n id: fields.id,\n category: fields.category,\n title: fields.title,\n longDescription: documentToHtmlString(fields.longDescription),\n shortDescription: fields.shortDescription,\n image: {\n title: imageFields?.title,\n description: imageFields?.description,\n url: imageFields?.file?.url ?? '',\n },\n externalLink: externalLinkFields && {\n externalLinkText: externalLinkFields?.externalLinkText,\n externalLinkUrl: externalLinkFields?.externalLinkUrl,\n },\n portfolioLink: portfolioLinkFields && {\n portfolioLinkText: portfolioLinkFields?.portfolioLinkText,\n portfolioLinkUrl: portfolioLinkFields?.portfolioLinkUrl,\n },\n extensionLink: extensionLinkFields && {\n extensionLinkText: extensionLinkFields?.extensionLinkText,\n extensionLinkRoute: extensionLinkFields?.extensionLinkRoute,\n },\n mobileLink: mobileLinkFields && {\n mobileLinkText: mobileLinkFields?.mobileLinkText,\n mobileLinkUrl: mobileLinkFields?.mobileLinkUrl,\n },\n extensionMinimumVersionNumber: fields.extensionMinimumVersionNumber,\n mobileMinimumVersionNumber: fields.mobileMinimumVersionNumber,\n extensionMaximumVersionNumber: fields.extensionMaximumVersionNumber,\n mobileMaximumVersionNumber: fields.mobileMaximumVersionNumber,\n },\n };\n\n return notification;\n });\n\n const versionKeys = {\n extension: {\n min: 'extensionMinimumVersionNumber',\n max: 'extensionMaximumVersionNumber',\n },\n mobile: {\n min: 'mobileMinimumVersionNumber',\n max: 'mobileMaximumVersionNumber',\n },\n } as const;\n\n const filteredRawNotifications = rawNotifications.filter((n) => {\n const minVersion = n.data?.[versionKeys[env.platform].min];\n const maxVersion = n.data?.[versionKeys[env.platform].max];\n\n // If no platform version is provided, show all notifications\n if (!env.platformVersion) {\n return true;\n }\n\n // min/max filtering\n try {\n let showNotification = true;\n\n // Check minimum version: current version must be greater than minimum\n if (minVersion) {\n showNotification =\n showNotification && gt(env.platformVersion, minVersion);\n }\n\n // Check maximum version: current version must be less than maximum\n if (maxVersion) {\n showNotification =\n showNotification && lt(env.platformVersion, maxVersion);\n }\n\n return showNotification;\n } catch {\n // something went wrong filtering, do not show notification\n return false;\n }\n });\n\n return filteredRawNotifications;\n};\n\n/**\n * Gets Feature Announcement from our services\n *\n * @param env - environment for feature announcements\n * @param previewToken - the preview token to use if needed\n * @returns Raw Feature Announcements\n */\nexport async function getFeatureAnnouncementNotifications(\n env: Env,\n previewToken?: string,\n): Promise<INotification[]> {\n if (env?.accessToken && env?.spaceId && env?.platform) {\n const rawNotifications = await fetchFeatureAnnouncementNotifications(\n env,\n previewToken,\n );\n const notifications = rawNotifications.map((notification) =>\n processFeatureAnnouncement(notification),\n );\n\n return notifications;\n }\n\n return [];\n}\n"]}
1
+ {"version":3,"file":"feature-announcements.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/feature-announcements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,4CAA4C;AAG3E,OAAO,EAAE,aAAa,EAAE,6CAAyC;AACjE,OAAO,EAAE,0BAA0B,EAAE,uDAAmD;AAaxF,OAAO,EAAE,iBAAiB,EAAE,uCAAmC;AAE/D,MAAM,gBAAgB,GAAG,WAAW,CAAC;AACrC,MAAM,oBAAoB,GAAG,eAAe,CAAC;AAC7C,MAAM,iBAAiB,GAAG,YAAY,CAAC;AACvC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAC5C,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAChD,MAAM,CAAC,MAAM,wBAAwB,GAAG,WAAW,cAAc,WAAW,gBAAgB,8BAA8B,CAAC;AAC3H,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,wB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,GAAG,EAAE,+BAA+B;YACpC,GAAG,EAAE,+BAA+B;SACrC;QACD,MAAM,EAAE;YACN,GAAG,EAAE,4BAA4B;YACjC,GAAG,EAAE,4BAA4B;SAClC;KACO,CAAC;IAEX,MAAM,wBAAwB,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;QAC7D,MAAM,UAAU,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC;QAC3D,MAAM,UAAU,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC;QAC3D,OAAO,iBAAiB,CAAC;YACvB,cAAc,EAAE,GAAG,CAAC,eAAe;YACnC,UAAU;YACV,UAAU;SACX,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,wBAAwB,CAAC;AAClC,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,mCAAmC,CACvD,GAAQ,EACR,YAAqB;IAErB,IAAI,GAAG,EAAE,WAAW,IAAI,GAAG,EAAE,OAAO,IAAI,GAAG,EAAE,QAAQ,EAAE;QACrD,MAAM,gBAAgB,GAAG,MAAM,qCAAqC,CAClE,GAAG,EACH,YAAY,CACb,CAAC;QACF,MAAM,aAAa,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAC1D,0BAA0B,CAAC,YAAY,CAAC,CACzC,CAAC;QAEF,OAAO,aAAa,CAAC;KACtB;IAED,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["import { documentToHtmlString } from '@contentful/rich-text-html-renderer';\nimport type { Entry, Asset, EntryCollection } from 'contentful';\n\nimport { TRIGGER_TYPES } from '../constants/notification-schema';\nimport { processFeatureAnnouncement } from '../processors/process-feature-announcement';\nimport type { FeatureAnnouncementRawNotification } from '../types/feature-announcement/feature-announcement';\nimport type {\n ImageFields,\n TypeFeatureAnnouncement,\n} from '../types/feature-announcement/type-feature-announcement';\nimport type {\n TypeExternalLinkFields,\n TypePortfolioLinkFields,\n TypeExtensionLinkFields,\n TypeMobileLinkFields,\n} from '../types/feature-announcement/type-links';\nimport type { INotification } from '../types/notification/notification';\nimport { isVersionInBounds } from '../utils/isVersionInBounds';\n\nconst DEFAULT_SPACE_ID = ':space_id';\nconst DEFAULT_ACCESS_TOKEN = ':access_token';\nconst DEFAULT_CLIENT_ID = ':client_id';\nconst DEFAULT_DOMAIN = 'cdn.contentful.com';\nconst PREVIEW_DOMAIN = 'preview.contentful.com';\nexport const FEATURE_ANNOUNCEMENT_API = `https://${DEFAULT_DOMAIN}/spaces/${DEFAULT_SPACE_ID}/environments/master/entries`;\nexport const FEATURE_ANNOUNCEMENT_URL = `${FEATURE_ANNOUNCEMENT_API}?access_token=${DEFAULT_ACCESS_TOKEN}&content_type=productAnnouncement&include=10&fields.clients[in]=${DEFAULT_CLIENT_ID}`;\n\ntype Env = {\n spaceId: string;\n accessToken: string;\n platform: 'extension' | 'mobile';\n platformVersion?: string;\n};\n\n/**\n * Contentful API Response Shape\n */\nexport type ContentfulResult = {\n includes?: {\n Entry?: Entry[];\n Asset?: Asset[];\n };\n items?: TypeFeatureAnnouncement[];\n};\n\nexport const getFeatureAnnouncementUrl = (env: Env, previewToken?: string) => {\n const domain = previewToken ? PREVIEW_DOMAIN : DEFAULT_DOMAIN;\n const replacedUrl = FEATURE_ANNOUNCEMENT_URL.replace(\n DEFAULT_SPACE_ID,\n env.spaceId,\n )\n .replace(DEFAULT_ACCESS_TOKEN, previewToken || env.accessToken)\n .replace(DEFAULT_CLIENT_ID, env.platform)\n .replace(DEFAULT_DOMAIN, domain);\n return encodeURI(replacedUrl);\n};\n\nconst fetchFeatureAnnouncementNotifications = async (\n env: Env,\n previewToken?: string,\n): Promise<FeatureAnnouncementRawNotification[]> => {\n const url = getFeatureAnnouncementUrl(env, previewToken);\n\n const data = await fetch(url)\n .then((r) => r.json())\n .catch(() => null);\n\n if (!data) {\n return [];\n }\n\n const findIncludedItem = (sysId: string) => {\n const typedData: EntryCollection<\n | ImageFields\n | TypeExtensionLinkFields\n | TypePortfolioLinkFields\n | TypeMobileLinkFields\n | TypeExternalLinkFields\n > = data;\n const item =\n typedData?.includes?.Entry?.find((i: Entry) => i?.sys?.id === sysId) ||\n typedData?.includes?.Asset?.find((i: Asset) => i?.sys?.id === sysId);\n return item ? item?.fields : null;\n };\n\n const contentfulNotifications = data?.items ?? [];\n const rawNotifications: FeatureAnnouncementRawNotification[] =\n contentfulNotifications.map((n: TypeFeatureAnnouncement) => {\n const { fields } = n;\n const imageFields = fields.image\n ? (findIncludedItem(fields.image.sys.id) as ImageFields['fields'])\n : undefined;\n\n const externalLinkFields = fields.externalLink\n ? (findIncludedItem(\n fields.externalLink.sys.id,\n ) as TypeExternalLinkFields['fields'])\n : undefined;\n const portfolioLinkFields = fields.portfolioLink\n ? (findIncludedItem(\n fields.portfolioLink.sys.id,\n ) as TypePortfolioLinkFields['fields'])\n : undefined;\n const extensionLinkFields = fields.extensionLink\n ? (findIncludedItem(\n fields.extensionLink.sys.id,\n ) as TypeExtensionLinkFields['fields'])\n : undefined;\n const mobileLinkFields = fields.mobileLink\n ? (findIncludedItem(\n fields.mobileLink.sys.id,\n ) as TypeMobileLinkFields['fields'])\n : undefined;\n\n const notification: FeatureAnnouncementRawNotification = {\n type: TRIGGER_TYPES.FEATURES_ANNOUNCEMENT,\n createdAt: new Date(n.sys.createdAt).toString(),\n data: {\n id: fields.id,\n category: fields.category,\n title: fields.title,\n longDescription: documentToHtmlString(fields.longDescription),\n shortDescription: fields.shortDescription,\n image: {\n title: imageFields?.title,\n description: imageFields?.description,\n url: imageFields?.file?.url ?? '',\n },\n externalLink: externalLinkFields && {\n externalLinkText: externalLinkFields?.externalLinkText,\n externalLinkUrl: externalLinkFields?.externalLinkUrl,\n },\n portfolioLink: portfolioLinkFields && {\n portfolioLinkText: portfolioLinkFields?.portfolioLinkText,\n portfolioLinkUrl: portfolioLinkFields?.portfolioLinkUrl,\n },\n extensionLink: extensionLinkFields && {\n extensionLinkText: extensionLinkFields?.extensionLinkText,\n extensionLinkRoute: extensionLinkFields?.extensionLinkRoute,\n },\n mobileLink: mobileLinkFields && {\n mobileLinkText: mobileLinkFields?.mobileLinkText,\n mobileLinkUrl: mobileLinkFields?.mobileLinkUrl,\n },\n extensionMinimumVersionNumber: fields.extensionMinimumVersionNumber,\n mobileMinimumVersionNumber: fields.mobileMinimumVersionNumber,\n extensionMaximumVersionNumber: fields.extensionMaximumVersionNumber,\n mobileMaximumVersionNumber: fields.mobileMaximumVersionNumber,\n },\n };\n\n return notification;\n });\n\n const versionKeys = {\n extension: {\n min: 'extensionMinimumVersionNumber',\n max: 'extensionMaximumVersionNumber',\n },\n mobile: {\n min: 'mobileMinimumVersionNumber',\n max: 'mobileMaximumVersionNumber',\n },\n } as const;\n\n const filteredRawNotifications = rawNotifications.filter((n) => {\n const minVersion = n.data?.[versionKeys[env.platform].min];\n const maxVersion = n.data?.[versionKeys[env.platform].max];\n return isVersionInBounds({\n currentVersion: env.platformVersion,\n minVersion,\n maxVersion,\n });\n });\n\n return filteredRawNotifications;\n};\n\n/**\n * Gets Feature Announcement from our services\n *\n * @param env - environment for feature announcements\n * @param previewToken - the preview token to use if needed\n * @returns Raw Feature Announcements\n */\nexport async function getFeatureAnnouncementNotifications(\n env: Env,\n previewToken?: string,\n): Promise<INotification[]> {\n if (env?.accessToken && env?.spaceId && env?.platform) {\n const rawNotifications = await fetchFeatureAnnouncementNotifications(\n env,\n previewToken,\n );\n const notifications = rawNotifications.map((notification) =>\n processFeatureAnnouncement(notification),\n );\n\n return notifications;\n }\n\n return [];\n}\n"]}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isVersionInBounds = void 0;
4
+ const semver_1 = require("semver");
5
+ /**
6
+ * Checks if a given version is within bounds against a min and max bound
7
+ * Uses semver strings
8
+ *
9
+ * @param params - Object param containing current/min/max versions
10
+ * @param params.currentVersion - (optional) current version of application
11
+ * @param params.minVersion - (optional) exclusive min bounds
12
+ * @param params.maxVersion - (optional) exclusive max bounds
13
+ * @returns boolean is version provided is within bounds
14
+ */
15
+ function isVersionInBounds({ currentVersion, minVersion, maxVersion, }) {
16
+ if (!currentVersion) {
17
+ return true;
18
+ }
19
+ try {
20
+ let showNotification = true;
21
+ // Check minimum version: current version must be greater than minimum
22
+ if (minVersion) {
23
+ showNotification = showNotification && (0, semver_1.gt)(currentVersion, minVersion);
24
+ }
25
+ // Check maximum version: current version must be less than maximum
26
+ if (maxVersion) {
27
+ showNotification = showNotification && (0, semver_1.lt)(currentVersion, maxVersion);
28
+ }
29
+ return showNotification;
30
+ }
31
+ catch {
32
+ // something went wrong checking bounds
33
+ return false;
34
+ }
35
+ }
36
+ exports.isVersionInBounds = isVersionInBounds;
37
+ //# sourceMappingURL=isVersionInBounds.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isVersionInBounds.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/utils/isVersionInBounds.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAQhC;;;;;;;;;GASG;AACH,SAAgB,iBAAiB,CAAC,EAChC,cAAc,EACd,UAAU,EACV,UAAU,GACQ;IAClB,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,IAAI,CAAC;KACb;IAED,IAAI;QACF,IAAI,gBAAgB,GAAG,IAAI,CAAC;QAE5B,sEAAsE;QACtE,IAAI,UAAU,EAAE;YACd,gBAAgB,GAAG,gBAAgB,IAAI,IAAA,WAAE,EAAC,cAAc,EAAE,UAAU,CAAC,CAAC;SACvE;QAED,mEAAmE;QACnE,IAAI,UAAU,EAAE;YACd,gBAAgB,GAAG,gBAAgB,IAAI,IAAA,WAAE,EAAC,cAAc,EAAE,UAAU,CAAC,CAAC;SACvE;QAED,OAAO,gBAAgB,CAAC;KACzB;IAAC,MAAM;QACN,uCAAuC;QACvC,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AA3BD,8CA2BC","sourcesContent":["import { gt, lt } from 'semver';\n\ntype IsVersionInBounds = {\n currentVersion?: string;\n minVersion?: string;\n maxVersion?: string;\n};\n\n/**\n * Checks if a given version is within bounds against a min and max bound\n * Uses semver strings\n *\n * @param params - Object param containing current/min/max versions\n * @param params.currentVersion - (optional) current version of application\n * @param params.minVersion - (optional) exclusive min bounds\n * @param params.maxVersion - (optional) exclusive max bounds\n * @returns boolean is version provided is within bounds\n */\nexport function isVersionInBounds({\n currentVersion,\n minVersion,\n maxVersion,\n}: IsVersionInBounds) {\n if (!currentVersion) {\n return true;\n }\n\n try {\n let showNotification = true;\n\n // Check minimum version: current version must be greater than minimum\n if (minVersion) {\n showNotification = showNotification && gt(currentVersion, minVersion);\n }\n\n // Check maximum version: current version must be less than maximum\n if (maxVersion) {\n showNotification = showNotification && lt(currentVersion, maxVersion);\n }\n\n return showNotification;\n } catch {\n // something went wrong checking bounds\n return false;\n }\n}\n"]}
@@ -0,0 +1,18 @@
1
+ type IsVersionInBounds = {
2
+ currentVersion?: string;
3
+ minVersion?: string;
4
+ maxVersion?: string;
5
+ };
6
+ /**
7
+ * Checks if a given version is within bounds against a min and max bound
8
+ * Uses semver strings
9
+ *
10
+ * @param params - Object param containing current/min/max versions
11
+ * @param params.currentVersion - (optional) current version of application
12
+ * @param params.minVersion - (optional) exclusive min bounds
13
+ * @param params.maxVersion - (optional) exclusive max bounds
14
+ * @returns boolean is version provided is within bounds
15
+ */
16
+ export declare function isVersionInBounds({ currentVersion, minVersion, maxVersion, }: IsVersionInBounds): boolean;
17
+ export {};
18
+ //# sourceMappingURL=isVersionInBounds.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isVersionInBounds.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesController/utils/isVersionInBounds.ts"],"names":[],"mappings":"AAEA,KAAK,iBAAiB,GAAG;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,cAAc,EACd,UAAU,EACV,UAAU,GACX,EAAE,iBAAiB,WAuBnB"}
@@ -0,0 +1,18 @@
1
+ type IsVersionInBounds = {
2
+ currentVersion?: string;
3
+ minVersion?: string;
4
+ maxVersion?: string;
5
+ };
6
+ /**
7
+ * Checks if a given version is within bounds against a min and max bound
8
+ * Uses semver strings
9
+ *
10
+ * @param params - Object param containing current/min/max versions
11
+ * @param params.currentVersion - (optional) current version of application
12
+ * @param params.minVersion - (optional) exclusive min bounds
13
+ * @param params.maxVersion - (optional) exclusive max bounds
14
+ * @returns boolean is version provided is within bounds
15
+ */
16
+ export declare function isVersionInBounds({ currentVersion, minVersion, maxVersion, }: IsVersionInBounds): boolean;
17
+ export {};
18
+ //# sourceMappingURL=isVersionInBounds.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isVersionInBounds.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesController/utils/isVersionInBounds.ts"],"names":[],"mappings":"AAEA,KAAK,iBAAiB,GAAG;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,cAAc,EACd,UAAU,EACV,UAAU,GACX,EAAE,iBAAiB,WAuBnB"}
@@ -0,0 +1,33 @@
1
+ import { gt, lt } from "semver";
2
+ /**
3
+ * Checks if a given version is within bounds against a min and max bound
4
+ * Uses semver strings
5
+ *
6
+ * @param params - Object param containing current/min/max versions
7
+ * @param params.currentVersion - (optional) current version of application
8
+ * @param params.minVersion - (optional) exclusive min bounds
9
+ * @param params.maxVersion - (optional) exclusive max bounds
10
+ * @returns boolean is version provided is within bounds
11
+ */
12
+ export function isVersionInBounds({ currentVersion, minVersion, maxVersion, }) {
13
+ if (!currentVersion) {
14
+ return true;
15
+ }
16
+ try {
17
+ let showNotification = true;
18
+ // Check minimum version: current version must be greater than minimum
19
+ if (minVersion) {
20
+ showNotification = showNotification && gt(currentVersion, minVersion);
21
+ }
22
+ // Check maximum version: current version must be less than maximum
23
+ if (maxVersion) {
24
+ showNotification = showNotification && lt(currentVersion, maxVersion);
25
+ }
26
+ return showNotification;
27
+ }
28
+ catch {
29
+ // something went wrong checking bounds
30
+ return false;
31
+ }
32
+ }
33
+ //# sourceMappingURL=isVersionInBounds.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isVersionInBounds.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/utils/isVersionInBounds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,eAAe;AAQhC;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAChC,cAAc,EACd,UAAU,EACV,UAAU,GACQ;IAClB,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,IAAI,CAAC;KACb;IAED,IAAI;QACF,IAAI,gBAAgB,GAAG,IAAI,CAAC;QAE5B,sEAAsE;QACtE,IAAI,UAAU,EAAE;YACd,gBAAgB,GAAG,gBAAgB,IAAI,EAAE,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;SACvE;QAED,mEAAmE;QACnE,IAAI,UAAU,EAAE;YACd,gBAAgB,GAAG,gBAAgB,IAAI,EAAE,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;SACvE;QAED,OAAO,gBAAgB,CAAC;KACzB;IAAC,MAAM;QACN,uCAAuC;QACvC,OAAO,KAAK,CAAC;KACd;AACH,CAAC","sourcesContent":["import { gt, lt } from 'semver';\n\ntype IsVersionInBounds = {\n currentVersion?: string;\n minVersion?: string;\n maxVersion?: string;\n};\n\n/**\n * Checks if a given version is within bounds against a min and max bound\n * Uses semver strings\n *\n * @param params - Object param containing current/min/max versions\n * @param params.currentVersion - (optional) current version of application\n * @param params.minVersion - (optional) exclusive min bounds\n * @param params.maxVersion - (optional) exclusive max bounds\n * @returns boolean is version provided is within bounds\n */\nexport function isVersionInBounds({\n currentVersion,\n minVersion,\n maxVersion,\n}: IsVersionInBounds) {\n if (!currentVersion) {\n return true;\n }\n\n try {\n let showNotification = true;\n\n // Check minimum version: current version must be greater than minimum\n if (minVersion) {\n showNotification = showNotification && gt(currentVersion, minVersion);\n }\n\n // Check maximum version: current version must be less than maximum\n if (maxVersion) {\n showNotification = showNotification && lt(currentVersion, maxVersion);\n }\n\n return showNotification;\n } catch {\n // something went wrong checking bounds\n return false;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/notification-services-controller",
3
- "version": "18.2.0-preview-622f3f09",
3
+ "version": "18.2.0-preview-44207a4",
4
4
  "description": "Manages New MetaMask decentralized Notification system",
5
5
  "keywords": [
6
6
  "MetaMask",