@castlabs/ui 7.18.0 → 7.19.0

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.
@@ -1,4 +1,4 @@
1
- /* @castlabs/ui v7.18.0 */
1
+ /* @castlabs/ui v7.19.0 */
2
2
 
3
3
  /*!
4
4
  * Bootstrap v5.3.8 (https://getbootstrap.com/)
@@ -360,6 +360,9 @@ const SERVICE = {
360
360
  CP: 'Content Platform',
361
361
  CP_TAGLINE: 'Access the Content Platform, manage, encode and watermark assets',
362
362
  CP_URN: 'urn:janus:service:76b6e8558263431d9d766779987d6410',
363
+ CPS: 'Content Platform Staging',
364
+ CPS_TAGLINE: 'Access the Content Platform, manage, encode and watermark assets',
365
+ CPS_URN: 'urn:janus:service:f57f4728d2a54a0d99b77b9bb7e04bf6',
363
366
  CS: 'Castlabs hub',
364
367
  CS_TAGLINE: 'Manage organizations, plans, downloads',
365
368
  CS_URN: 'urn:janus:service:OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO',
@@ -384,6 +387,9 @@ const SERVICE = {
384
387
  VTK: 'Video Toolkit',
385
388
  VTK_TAGLINE: 'Cloud encoding, packaging, watermarking',
386
389
  VTK_URN: 'urn:janus:service:a50e21d6a5e246809b636854abfbd34d',
390
+ VTKS: 'Video Toolkit Staging',
391
+ VTKS_TAGLINE: 'Cloud encoding, packaging, watermarking',
392
+ VTKS_URN: 'urn:janus:service:ca5bb34e8f39459796778e74fa097248',
387
393
  WM: 'STARDUSTmark',
388
394
  WM_TAGLINE: 'Video & image forensic watermarking',
389
395
  WM_URN: 'urn:janus:service:76b6e8558263431d9d766779987d64c4'
@@ -446,8 +452,6 @@ const ROLE = {
446
452
  DTS_DELIVERIES: 'Deliveries',
447
453
  DTS_DELIVERIES_URN: 'urn:janus:role:e79a8f99a96a45238283b3c049e7374b',
448
454
 
449
- VTK_ADMIN: 'Video Toolkit admin',
450
- VTK_ADMIN_URN: 'urn:janus:role:8ff40a162b834e96a36f7ddbfda475ef',
451
455
  VTK_USER: 'Video Toolkit user',
452
456
  VTK_USER_URN: 'urn:janus:role:33c9c2001ca14dde9c3b310d0748b8b4',
453
457
 
@@ -500,6 +504,18 @@ const APPS = {
500
504
  sidenav: false
501
505
  },
502
506
 
507
+ CPS: {
508
+ id: 'CPS',
509
+ subtitle: SERVICE.CPS_TAGLINE,
510
+ title: SERVICE.CPS,
511
+ services: [SERVICE.CPS_URN],
512
+ roles: [ROLE.CP_USER_URN],
513
+ urlManage: (env, oid) =>
514
+ `https://platform.content-stag.castlabs.com/#/o/${oid ?? ''}`,
515
+ urlPlan: (env, oid) => urlCS(env, oid),
516
+ sidenav: false
517
+ },
518
+
503
519
  CS: {
504
520
  id: 'CS',
505
521
  subtitle: SERVICE.CS_TAGLINE,
@@ -619,7 +635,7 @@ const APPS = {
619
635
  id: 'VTK',
620
636
  subtitle: SERVICE.VTK_TAGLINE,
621
637
  services: [SERVICE.VTK_URN],
622
- roles: [ROLE.VTK_USER_URN, ROLE.VTK_ADMIN_URN],
638
+ roles: [ROLE.VTK_USER_URN],
623
639
  title: SERVICE.VTK,
624
640
  urlManage: (env, oid) =>
625
641
  getEnvUrl(
@@ -629,6 +645,18 @@ const APPS = {
629
645
  ),
630
646
  urlPlan: (env, oid) => urlCS(env, oid, '/plans/vtk'),
631
647
  sidenav: true
648
+ },
649
+
650
+ VTKS: {
651
+ id: 'VTKS',
652
+ subtitle: SERVICE.VTKS_TAGLINE,
653
+ title: SERVICE.VTKS,
654
+ services: [SERVICE.VTKS_URN],
655
+ roles: [ROLE.VTK_USER_URN],
656
+ urlManage: (env, oid) =>
657
+ `https://vtks.castlabs.com/${oid}/jobs/`,
658
+ urlPlan: (env, oid) => urlCS(env, oid, '/plans/vtk'),
659
+ sidenav: false
632
660
  }
633
661
  }
634
662
 
@@ -757,7 +785,7 @@ function variant (service, license, oid, env, hasRole) {
757
785
  // no license = show subscribe ad
758
786
  if (!license) {
759
787
  // some items are hidden if there is no license
760
- if ([APPS.DTS.id].includes(service.id)) return null
788
+ if ([APPS.DTS.id, APPS.CPS.id, APPS.VTKS.id].includes(service.id)) return null
761
789
 
762
790
  // other items we hint the user to subscribe
763
791
  return subscribe(service, oid, env)
@@ -791,12 +819,16 @@ function csGetNavVariant (membership, service, oid, env) {
791
819
  function csParseMembership (membership, oid, env) {
792
820
  const nav = [subscribed(APPS.CS, oid, env)]
793
821
 
822
+ const cps = csGetNavVariant(membership, APPS.CPS, oid, env)
823
+ if (cps) nav.push(cps)
794
824
  nav.push(csGetNavVariant(membership, APPS.DT, oid, env))
795
825
  const dts = csGetNavVariant(membership, APPS.DTS, oid, env)
796
826
  if (dts) nav.push(dts)
797
827
  nav.push(csGetNavVariant(membership, APPS.PP, oid, env))
798
828
  nav.push(csGetNavVariant(membership, APPS.WM, oid, env))
799
829
  nav.push(csGetNavVariant(membership, APPS.VTK, oid, env))
830
+ const vtks = csGetNavVariant(membership, APPS.VTKS, oid, env)
831
+ if (vtks) nav.push(vtks)
800
832
 
801
833
  return nav
802
834
  }
@@ -910,6 +942,41 @@ export function clScrollToId (id, smooth = true) {
910
942
  }, 0)
911
943
  }
912
944
 
945
+ export function setDomainCookieJson (name, value, maxAge = 60 * 60 * 24 * (365 + 30)) {
946
+ const b64 = btoa(JSON.stringify(value))
947
+ document.cookie = `${name}=${b64}; max-age=${maxAge}; domain=${getDomain()}; path=/; SameSite=Lax;`
948
+ }
949
+
950
+ export function getDomainCookieJson (name) {
951
+ for (const cookie of document?.cookie?.split(/; */) ?? []) {
952
+ const [key, value] = cookie.split('=')
953
+ if (key === name) {
954
+ try {
955
+ return JSON.parse(atob(value))
956
+ } catch (e) {
957
+ e.ignore?.() // ignore reason
958
+ return {}
959
+ }
960
+ }
961
+ }
962
+ return {}
963
+ }
964
+
965
+ function getDomain () {
966
+ if (window.location.hostname.match(/^[0-9]+.[0-9]+.[0-9]+.[0-9]+$/)) {
967
+ // IP domain
968
+ return window.location.hostname
969
+ }
970
+ const parts = window.location.hostname.split('.').reverse()
971
+ if (parts.length > 1) {
972
+ // regular multi-part domain name
973
+ return `.${parts[1]}.${parts[0]}`
974
+ } else {
975
+ // single-name domain like 'localhost'
976
+ return parts[0]
977
+ }
978
+ }
979
+
913
980
  // -----------------------------------------------------------------------------
914
981
  // --- modals ------------------------------------------------------------------
915
982
  // -----------------------------------------------------------------------------
@@ -1716,44 +1783,21 @@ export function clSleep (ms) {
1716
1783
  // -----------------------------------------------------------------------------
1717
1784
 
1718
1785
  export function clThemeSetup () {
1719
- let dark = null
1720
-
1721
- // try to load settings
1722
- try {
1723
- switch (localStorage.getItem('themeDark')) {
1724
- case 'true':
1725
- dark = true
1726
- break
1727
- case 'false':
1728
- dark = false
1729
- break
1730
- default:
1731
- dark = null
1732
- }
1733
- } catch (e) {
1734
- e.ignore?.()
1735
- } // catch & ignore private mode
1736
-
1737
- // use OS default if unknown
1738
- if (dark === null) {
1739
- const darkModeMql = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)')
1740
- if (darkModeMql?.matches) {
1741
- dark = true
1742
- } else {
1743
- dark = false
1744
- }
1786
+ const settings = getDomainCookieJson('cl_ui_settings')
1787
+ const dark = settings?.theme === 'dark'
1788
+ clThemeSetDark(dark) // re-set to prolong expiration
1789
+ const checkbox = document.querySelector('#cl-mode-dark')
1790
+ if (checkbox) {
1791
+ checkbox.checked = dark
1792
+ checkbox.addEventListener('change', () => {
1793
+ clThemeSetDark(checkbox.checked)
1794
+ })
1745
1795
  }
1746
-
1747
- // persist value
1748
- clThemeSetDark(dark)
1749
-
1750
1796
  return dark
1751
1797
  }
1752
1798
 
1753
1799
  export function clThemeSetDark (dark) {
1754
- try {
1755
- localStorage.setItem('themeDark', dark)
1756
- } catch (e) {
1757
- e.ignore?.()
1758
- } // catch & ignore private mode
1800
+ const settings = getDomainCookieJson('cl_ui_settings')
1801
+ settings.theme = dark ? 'dark' : 'light'
1802
+ setDomainCookieJson('cl_ui_settings', settings)
1759
1803
  }