@supernova-studio/client 1.4.20 → 1.4.22

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/index.mjs CHANGED
@@ -4972,6 +4972,98 @@ var PersonalAccessToken = z186.object({
4972
4972
  expireAt: z186.coerce.date().optional()
4973
4973
  });
4974
4974
 
4975
+ // src/api/conversion/analytics/page-visits-to-dto.ts
4976
+ function pageVisitsToDto(entries) {
4977
+ const result = [];
4978
+ const { userBasedEntries, sessionLessResults } = splitEntries(entries);
4979
+ result.push(...sessionLessResults);
4980
+ const userBasedPageVisitsGroupedByDate = groupBy(
4981
+ userBasedEntries,
4982
+ (entry) => getTimestampKey(entry.timestamp)
4983
+ // Need to group by date and hour.
4984
+ );
4985
+ for (const date of userBasedPageVisitsGroupedByDate.keys()) {
4986
+ const pageData = userBasedPageVisitsGroupedByDate.get(date);
4987
+ if (!pageData) {
4988
+ throw SupernovaException.shouldNotHappen();
4989
+ }
4990
+ const { visitsPerPage, sessionsPerPage } = aggregatePageVisitsAndSessions(pageData);
4991
+ const pageDataGroupedByPageId = groupBy(
4992
+ pageData,
4993
+ (entry) => entry.pagePersistentId
4994
+ );
4995
+ const pagePersistentIds = pageDataGroupedByPageId.keys();
4996
+ for (const id of pagePersistentIds) {
4997
+ const pageData2 = pageDataGroupedByPageId.get(id);
4998
+ if (!pageData2) {
4999
+ throw SupernovaException.shouldNotHappen();
5000
+ }
5001
+ const entry = pageData2[0];
5002
+ if (!entry) {
5003
+ throw SupernovaException.shouldNotHappen();
5004
+ }
5005
+ result.push({
5006
+ versionId: entry.versionId,
5007
+ pagePersistentId: entry.pagePersistentId,
5008
+ timestamp: entry.timestamp,
5009
+ visits: visitsPerPage.get(id) ?? 0,
5010
+ sessions: sessionsPerPage.get(id) ?? 0,
5011
+ locale: entry.locale
5012
+ });
5013
+ }
5014
+ }
5015
+ return result;
5016
+ }
5017
+ function getTimestampKey(timestamp) {
5018
+ const date = timestamp.toISOString().split("T")[0];
5019
+ const hour = timestamp.toISOString().split("T")[1].split(":")[0];
5020
+ return `${date}:${hour}`;
5021
+ }
5022
+ function aggregatePageVisitsAndSessions(pageData) {
5023
+ const visitsPerPage = /* @__PURE__ */ new Map();
5024
+ const sessionsPerPage = /* @__PURE__ */ new Map();
5025
+ const uniqueSessions = /* @__PURE__ */ new Set();
5026
+ for (const entry of pageData) {
5027
+ const pageId = entry.pagePersistentId;
5028
+ const visits = entry.visits;
5029
+ const currentSessionIdsLength = uniqueSessions.size;
5030
+ if (!entry.anonymousId) {
5031
+ throw SupernovaException.shouldNotHappen();
5032
+ }
5033
+ uniqueSessions.add(entry.anonymousId);
5034
+ const newSessionIdsLength = uniqueSessions.size;
5035
+ if (newSessionIdsLength > currentSessionIdsLength) {
5036
+ sessionsPerPage.set(pageId, (sessionsPerPage.get(pageId) ?? 0) + 1);
5037
+ }
5038
+ visitsPerPage.set(pageId, (visitsPerPage.get(pageId) ?? 0) + visits);
5039
+ }
5040
+ return {
5041
+ visitsPerPage,
5042
+ sessionsPerPage
5043
+ };
5044
+ }
5045
+ function splitEntries(entries) {
5046
+ const sessionLessResults = [];
5047
+ const dataCopy = [...entries];
5048
+ const userBasedEntries = dataCopy.filter((entry) => entry.anonymousId);
5049
+ for (const entry of dataCopy) {
5050
+ if (!entry.anonymousId) {
5051
+ sessionLessResults.push({
5052
+ versionId: entry.versionId,
5053
+ pagePersistentId: entry.pagePersistentId,
5054
+ timestamp: entry.timestamp,
5055
+ visits: entry.visits,
5056
+ sessions: 0,
5057
+ locale: entry.locale
5058
+ });
5059
+ }
5060
+ }
5061
+ return {
5062
+ userBasedEntries,
5063
+ sessionLessResults
5064
+ };
5065
+ }
5066
+
4975
5067
  // src/api/conversion/documentation/documentation-item-configuration-v1-to-dto.ts
4976
5068
  var getDtoDefaultItemConfigurationV1 = () => ({
4977
5069
  showSidebar: true,
@@ -5583,7 +5675,8 @@ var DTODataSourceFigma = z197.object({
5583
5675
  scope: DTODataSourceFigmaScope,
5584
5676
  brandId: z197.string(),
5585
5677
  themeId: z197.string().nullish(),
5586
- cloud: DTODataSourceFigmaCloud.nullish()
5678
+ cloud: DTODataSourceFigmaCloud.nullish(),
5679
+ sortOrder: z197.number().optional()
5587
5680
  });
5588
5681
  var DTODataSourceTokenStudio = z197.object({
5589
5682
  id: z197.string(),
@@ -5591,6 +5684,7 @@ var DTODataSourceTokenStudio = z197.object({
5591
5684
  fileName: z197.string(),
5592
5685
  brandId: z197.string(),
5593
5686
  themeId: z197.string().nullish(),
5687
+ sortOrder: z197.number().optional(),
5594
5688
  tokenStudio: z197.object({
5595
5689
  settings: z197.object({
5596
5690
  dryRun: z197.boolean(),
@@ -5619,6 +5713,7 @@ var DTODataSourceFigmaVariablesPlugin = z197.object({
5619
5713
  type: z197.literal(DataSourceRemoteType.Enum.FigmaVariablesPlugin),
5620
5714
  fileName: z197.string(),
5621
5715
  brandId: z197.string(),
5716
+ sortOrder: z197.number().optional(),
5622
5717
  upload: z197.object({
5623
5718
  remoteId: z197.string(),
5624
5719
  remoteSourceType: DataSourceUploadRemoteSource,
@@ -14724,6 +14819,7 @@ export {
14724
14819
  pageToProsemirrorDoc,
14725
14820
  pageToYDoc,
14726
14821
  pageToYXmlFragment,
14822
+ pageVisitsToDto,
14727
14823
  pipelineToDto,
14728
14824
  prosemirrorDocToPage,
14729
14825
  prosemirrorDocToRichTextPropertyValue,