@vonq/hapi-elements-types 1.5.0 → 1.6.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.
Files changed (156) hide show
  1. package/package.json +15 -4
  2. package/src/_window/api.types.ts +9 -7
  3. package/src/_window/auth.types.ts +6 -4
  4. package/src/_window/config.types.ts +0 -25
  5. package/src/_window/events.types.ts +15 -14
  6. package/src/_window/instances.types.ts +19 -10
  7. package/src/_window/qa.types.ts +7 -5
  8. package/src/_window/routing.types.ts +6 -4
  9. package/src/_window/sdk.types.ts +29 -27
  10. package/src/_window/service.types.ts +9 -7
  11. package/src/_window/state.types.ts +55 -53
  12. package/src/_window/ui.types.ts +6 -4
  13. package/src/_window/utils.types.ts +7 -5
  14. package/src/_window/validation.types.ts +7 -5
  15. package/src/_window/window.ts +126 -42
  16. package/src/alert/index.ts +4 -7
  17. package/src/alert/service.types.ts +2 -2
  18. package/src/alert/state.types.ts +1 -19
  19. package/src/ats/api.types.ts +2 -2
  20. package/src/ats/index.ts +4 -7
  21. package/src/ats/service.types.ts +2 -2
  22. package/src/ats/state.types.ts +1 -1
  23. package/src/basket/index.ts +5 -10
  24. package/src/basket/service.types.ts +2 -2
  25. package/src/basket/state.types.ts +1 -1
  26. package/src/basket/utils.types.ts +2 -2
  27. package/src/campaign/api.types.ts +2 -2
  28. package/src/campaign/index.ts +8 -13
  29. package/src/campaign/qa.types.ts +4 -4
  30. package/src/campaign/service.types.ts +2 -2
  31. package/src/campaign/state.types.ts +1 -1
  32. package/src/campaign/utils.types.ts +2 -2
  33. package/{enums.ts → src/common/enums.ts} +2 -1
  34. package/src/common/events/types.ts +6 -6
  35. package/src/common/index.ts +5 -20
  36. package/src/common/logger/types.ts +11 -0
  37. package/src/common/qa.types.ts +2 -2
  38. package/src/common/types.ts +5 -6
  39. package/src/common/validator/types.ts +4 -0
  40. package/src/contract/api.types.ts +2 -2
  41. package/src/contract/index.ts +7 -12
  42. package/src/contract/qa.types.ts +2 -2
  43. package/src/contract/service.types.ts +2 -2
  44. package/src/contract/state.types.ts +1 -1
  45. package/src/contract/utils.types.ts +2 -2
  46. package/src/debugging/index.ts +1 -4
  47. package/src/debugging/state.types.ts +1 -1
  48. package/src/index.ts +16 -20
  49. package/src/language/index.ts +3 -9
  50. package/src/language/qa.types.ts +2 -2
  51. package/src/language/state.types.ts +1 -1
  52. package/src/modal/index.ts +4 -9
  53. package/src/modal/service.types.ts +2 -2
  54. package/src/modal/state.types.ts +1 -1
  55. package/src/orderJourney/index.ts +6 -11
  56. package/src/orderJourney/qa.types.ts +2 -2
  57. package/src/orderJourney/state.types.ts +1 -1
  58. package/src/orderJourney/utils.types.ts +2 -2
  59. package/src/product/api.types.ts +2 -2
  60. package/src/product/index.ts +8 -12
  61. package/src/product/qa.types.ts +2 -2
  62. package/src/product/service.types.ts +2 -2
  63. package/src/product/state.types.ts +1 -1
  64. package/src/product/utils.types.ts +2 -2
  65. package/src/routing/index.ts +1 -3
  66. package/src/theming/index.ts +4 -9
  67. package/src/theming/qa.types.ts +2 -2
  68. package/src/theming/state.types.ts +1 -1
  69. package/src/ui/service.types.ts +2 -2
  70. package/src/wallet/api.types.ts +2 -2
  71. package/src/wallet/index.ts +5 -9
  72. package/src/wallet/service.types.ts +2 -2
  73. package/src/wallet/state.types.ts +1 -1
  74. package/tsconfig.json +6 -11
  75. package/src/alert/functions.types.ts +0 -13
  76. package/src/alert/state.initial.ts +0 -16
  77. package/src/alert/state.validations.ts +0 -11
  78. package/src/ats/functions.types.ts +0 -7
  79. package/src/ats/state.initial.ts +0 -5
  80. package/src/ats/state.validations.ts +0 -6
  81. package/src/basket/consts.ts +0 -1
  82. package/src/basket/functions.types.ts +0 -40
  83. package/src/basket/state.initial.ts +0 -11
  84. package/src/basket/state.validations.ts +0 -12
  85. package/src/basket/utils.ts +0 -79
  86. package/src/campaign/consts.ts +0 -1
  87. package/src/campaign/functions.types.ts +0 -90
  88. package/src/campaign/state.initial.ts +0 -84
  89. package/src/campaign/state.validations.ts +0 -16
  90. package/src/campaign/utils.ts +0 -53
  91. package/src/common/LocalStorage.ts +0 -123
  92. package/src/common/browser.ts +0 -2
  93. package/src/common/color.ts +0 -9
  94. package/src/common/immutable.ts +0 -28
  95. package/src/common/instances/Instance.ts +0 -13
  96. package/src/common/instances/consts.ts +0 -1
  97. package/src/common/instances/index.ts +0 -4
  98. package/src/common/json.ts +0 -25
  99. package/src/common/logger/Logger.ts +0 -70
  100. package/src/common/logger/index.ts +0 -5
  101. package/src/common/logger-datadog/LoggerDatadog.ts +0 -42
  102. package/src/common/logger-datadog/index.ts +0 -3
  103. package/src/common/misc.ts +0 -114
  104. package/src/common/promise.ts +0 -161
  105. package/src/common/proxy.ts +0 -77
  106. package/src/common/regExTest.ts +0 -12
  107. package/src/common/tree.ts +0 -148
  108. package/src/common/utm.ts +0 -19
  109. package/src/common/validators.ts +0 -21
  110. package/src/common/webComponents.ts +0 -26
  111. package/src/config/functions.types.ts +0 -23
  112. package/src/config/index.ts +0 -5
  113. package/src/config/state.initial.ts +0 -11
  114. package/src/config/state.types.ts +0 -15
  115. package/src/consts.ts +0 -980
  116. package/src/contract/consts.ts +0 -1
  117. package/src/contract/functions.types.ts +0 -112
  118. package/src/contract/state.initial.ts +0 -39
  119. package/src/contract/state.validations.ts +0 -21
  120. package/src/contract/utils.ts +0 -36
  121. package/src/debugging/functions.types.ts +0 -34
  122. package/src/debugging/state.initial.ts +0 -10
  123. package/src/debugging/state.validations.ts +0 -10
  124. package/src/language/consts.ts +0 -6
  125. package/src/language/en.ts +0 -530
  126. package/src/language/functions.types.ts +0 -29
  127. package/src/language/state.initial.ts +0 -13
  128. package/src/language/state.validations.ts +0 -10
  129. package/src/language/utils.ts +0 -17
  130. package/src/modal/consts.ts +0 -6
  131. package/src/modal/functions.types.ts +0 -22
  132. package/src/modal/state.initial.ts +0 -9
  133. package/src/modal/state.validations.ts +0 -6
  134. package/src/modal/store.types.ts +0 -5
  135. package/src/orderJourney/consts.ts +0 -289
  136. package/src/orderJourney/functions.types.ts +0 -140
  137. package/src/orderJourney/state.initial.ts +0 -401
  138. package/src/orderJourney/state.validations.ts +0 -78
  139. package/src/orderJourney/utils.ts +0 -7
  140. package/src/product/consts.ts +0 -1
  141. package/src/product/functions.types.ts +0 -156
  142. package/src/product/state.initial.ts +0 -28
  143. package/src/product/state.validations.ts +0 -25
  144. package/src/routing/functions.types.ts +0 -48
  145. package/src/routing/state.initial.ts +0 -10
  146. package/src/theming/consts.ts +0 -7727
  147. package/src/theming/functions.types.ts +0 -13
  148. package/src/theming/state.initial.ts +0 -16
  149. package/src/theming/state.validations.ts +0 -8
  150. package/src/theming/utils.ts +0 -581
  151. package/src/types.ts +0 -229
  152. package/src/utils.ts +0 -3
  153. package/src/wallet/consts.ts +0 -3
  154. package/src/wallet/functions.types.ts +0 -58
  155. package/src/wallet/state.initial.ts +0 -18
  156. package/src/wallet/state.validations.ts +0 -18
@@ -1,7 +0,0 @@
1
- import { ATSSettings } from "./types"
2
-
3
- export type ATSStoreSetUserSettingsHandler = (settings: ATSSettings) => void
4
-
5
- export type ATSStoreFunctions = {
6
- setUserSettings: ATSStoreSetUserSettingsHandler
7
- }
@@ -1,5 +0,0 @@
1
- import { ATSStoreState } from "./state.types"
2
-
3
- export const initialATSStoreState: ATSStoreState = {
4
- userSettings: null,
5
- }
@@ -1,6 +0,0 @@
1
- import { ATSStoreState } from "./state.types"
2
- import { StateValidations } from "../_window/state.types"
3
-
4
- export const atsStoreStateValidations: StateValidations<ATSStoreState> = {
5
- userSettings: "common.genericObject",
6
- }
@@ -1 +0,0 @@
1
- export const CAMPAIGN_BASKET_PRODUCTS_LOCALSTORAGE_KEY = "basketProducts"
@@ -1,40 +0,0 @@
1
- import { BasketProduct } from "./types"
2
- import { Product } from "../product/types"
3
- import { Contract } from "../contract/types"
4
-
5
- export type BasketStoreClearHandler = () => void
6
- export type BasketStoreAddProductOrContractByIdHandler = (
7
- contractOrProductId: string,
8
- isProduct: boolean,
9
- ) => void
10
- export type BasketStoreRemoveProductOrContractByIdHandler = (
11
- contractOrProductId: string,
12
- ) => void
13
- export type BasketStoreSetProductsMetaHandler = (
14
- productOrContractIds: BasketProduct[],
15
- ) => void
16
- export type BasketStoreSetProductsAreLoadingHandler = (
17
- isLoading: boolean,
18
- ) => void
19
- export type BasketStoreSetProductsHandler = (
20
- data: (Product | Contract)[],
21
- ) => void
22
-
23
- export type BasketStoreFunctions = {
24
- /**
25
- * Removes all products and contracts from Basket
26
- */
27
- clear: BasketStoreClearHandler
28
- /**
29
- * Sets the array of Products and/or Contracts to be displayed in the Basket
30
- */
31
- setProducts: BasketStoreSetProductsHandler
32
- /**
33
- * Shows a loading spinner in the Basket when `products` are loading
34
- */
35
- setProductsAreLoading: BasketStoreSetProductsAreLoadingHandler
36
- /**
37
- * Sets array of objects with `id: string | number` for and `isProduct: boolean` so that the up-to-date data can be loaded from the API and set to `products`
38
- */
39
- setProductsMeta: BasketStoreSetProductsMetaHandler
40
- }
@@ -1,11 +0,0 @@
1
- import { BasketStoreState } from "./state.types"
2
-
3
- export const initialBasketStoreState: BasketStoreState = {
4
- totalInUSD: 0,
5
- totalInEUR: 0,
6
- totalInGBP: 0,
7
- totalInDisplayCurrency: 0,
8
- productsMeta: [],
9
- products: [],
10
- productsAreLoading: false,
11
- }
@@ -1,12 +0,0 @@
1
- import { BasketStoreState } from "./state.types"
2
- import { StateValidations } from "../_window/state.types"
3
-
4
- export const basketStoreStateValidations: StateValidations<BasketStoreState> = {
5
- productsMeta: "basket.productsMeta",
6
- products: "basket.products",
7
- productsAreLoading: "common.genericBoolean",
8
- totalInEUR: "throwHasNoSetterError",
9
- totalInGBP: "throwHasNoSetterError",
10
- totalInUSD: "throwHasNoSetterError",
11
- totalInDisplayCurrency: "throwHasNoSetterError",
12
- }
@@ -1,79 +0,0 @@
1
- import { Product } from "../product/types"
2
- import { Contract } from "../contract/types"
3
- import { ProductPriceCurrency } from "../product/enums"
4
- import { BasketProduct } from "./types"
5
-
6
- export const getIsBasketProductContract = (product: Product | Contract) => {
7
- return (product as Contract).contract_id !== undefined
8
- }
9
- export const getIsBasketProductProduct = (product: Product | Contract) => {
10
- return (product as Product).product_id !== undefined
11
- }
12
- export const getBasketProductId = (product: Product | Contract) => {
13
- const isProduct = getIsBasketProductProduct(product)
14
- return isProduct
15
- ? (product as Product).product_id
16
- : (product as Contract).contract_id
17
- }
18
- export const getBasketProductTitle = (product: Product | Contract) => {
19
- const isProduct = getIsBasketProductProduct(product)
20
- return isProduct
21
- ? (product as Product).title
22
- : (product as Contract).product.title
23
- }
24
-
25
- export const getBasketProductPrice = (
26
- product: Product | Contract,
27
- displayCurrency: ProductPriceCurrency,
28
- ) => {
29
- if ((product as Product).product_id) {
30
- const price = (product as Product).vonq_price.find(
31
- (price) => price.currency === displayCurrency,
32
- )
33
- if (price) {
34
- return price
35
- }
36
- return undefined
37
- } else {
38
- return undefined
39
- }
40
- }
41
-
42
- export const getBasketProductBoardType = (product: Product | Contract) => {
43
- if ((product as Product).product_id) {
44
- return (product as Product).type
45
- } else {
46
- return (product as Contract).channel?.type
47
- }
48
- }
49
-
50
- export const getBasketProductTimeToProcess = (product: Product | Contract) => {
51
- if ((product as Product).product_id) {
52
- return `${(product as Product).time_to_process.period} ${
53
- (product as Product).time_to_process.range
54
- }`
55
- } else {
56
- return undefined
57
- }
58
- }
59
-
60
- export const getBasketProductDuration = (product: Product | Contract) => {
61
- if ((product as Product).product_id) {
62
- return `${(product as Product).duration.period} ${
63
- (product as Product).duration.range
64
- }`
65
- } else {
66
- return undefined
67
- }
68
- }
69
-
70
- export const getIsProductOrContractInBasket = (
71
- contractOrProductId: string,
72
- productsMeta: BasketProduct[],
73
- ) => {
74
- const alreadyInBasket = productsMeta.find(
75
- (basketProduct) => basketProduct.id === contractOrProductId,
76
- )
77
-
78
- return alreadyInBasket !== undefined
79
- }
@@ -1 +0,0 @@
1
- export const CAMPAIGN_CREATE_FORM_LOCALSTORAGE_KEY = "createCampaignForm"
@@ -1,90 +0,0 @@
1
- /* Campaign */
2
-
3
- import {
4
- Campaign,
5
- CampaignCreateForm,
6
- TaxonomyEducationAndSeniorityLevel,
7
- TaxonomySeniority,
8
- } from "./types"
9
- import { PaginationResponseV2, RecursivePartial } from "../common/types"
10
-
11
- export type CampaignStoreSetCampaignsHandler = (campaigns: Campaign[]) => void
12
- export type CampaignStoreSetCampaignsPaginationMetaHandler = (
13
- meta: PaginationResponseV2 | null,
14
- ) => void
15
- export type CampaignStoreSetCampaignsAreLoadingHandler = (
16
- isLoading: boolean,
17
- ) => void
18
- export type CampaignStoreSetCampaignHandler = (
19
- campaignId: string,
20
- campaign: Partial<Campaign>,
21
- ) => void
22
- export type CampaignStoreSetCampaignFormHandler = (
23
- campaign: RecursivePartial<CampaignCreateForm>,
24
- replaceAsIs?: boolean,
25
- ) => void
26
- export type CampaignStoreSetCampaignIsCreatingHandler = (
27
- isCreating: boolean,
28
- ) => void
29
-
30
- /* Education Levels */
31
- export type CampaignStoreSetEducationLevelsHandler = (
32
- educationLevels: TaxonomyEducationAndSeniorityLevel[],
33
- ) => void
34
- export type CampaignStoreSetEducationLevelsAreLoadingHandler = (
35
- isLoading: boolean,
36
- ) => void
37
-
38
- /* Seniorities */
39
- export type CampaignStoreSetSenioritiesHandler = (
40
- seniorities: TaxonomySeniority[],
41
- ) => void
42
- export type CampaignStoreSetSenioritiesAreLoadingHandler = (
43
- isLoading: boolean,
44
- ) => void
45
-
46
- export type CampaignStoreFunctions = {
47
- /* Campaign */
48
- /**
49
- * The function that sets the value of `campaigns`. Refer to [CampaignStoreState](/docs/sdk/campaigns/#campaignstorestate) for more details.
50
- */
51
- setCampaigns: CampaignStoreSetCampaignsHandler
52
- /**
53
- * The function that sets the value of `campaignsPaginationMeta`. Refer to [CampaignStoreState](/docs/sdk/campaigns/#campaignstorestate) for more details.
54
- */
55
- setCampaignsPaginationMeta: CampaignStoreSetCampaignsPaginationMetaHandler
56
- /**
57
- * The function that sets the value of `campaignsAreLoading`. Refer to [CampaignStoreState](/docs/sdk/campaigns/#campaignstorestate) for more details.
58
- */
59
- setCampaignsAreLoading: CampaignStoreSetCampaignsAreLoadingHandler
60
- /**
61
- * The function that updates properties of a Campaign in the array of `campaigns` by given Campaign ID. Refer to [CampaignStoreState](/docs/sdk/campaigns/#campaignstorestate) for more details.
62
- */
63
- setCampaign: CampaignStoreSetCampaignHandler
64
- /**
65
- * The function that updates properties of `campaignForm`. Refer to [CampaignStoreState](/docs/sdk/campaigns/#campaignstorestate) for more details.
66
- */
67
- setCampaignForm: CampaignStoreSetCampaignFormHandler
68
- /**
69
- * The function that sets the value of `campaignIsCreating`. Refer to [CampaignStoreState](/docs/sdk/campaigns/#campaignstorestate) for more details.
70
- */
71
- setCampaignIsCreating: CampaignStoreSetCampaignIsCreatingHandler
72
- /* Education Levels */
73
- /**
74
- * The function that sets the value of `educationLevels`. Refer to [CampaignStoreState](/docs/sdk/campaigns/#campaignstorestate) for more details.
75
- */
76
- setEducationLevels: CampaignStoreSetEducationLevelsHandler
77
- /**
78
- * The function that sets the value of `educationLevelsAreLoading`. Refer to [CampaignStoreState](/docs/sdk/campaigns/#campaignstorestate) for more details.
79
- */
80
- setEducationLevelsAreLoading: CampaignStoreSetEducationLevelsAreLoadingHandler
81
- /* Seniorities */
82
- /**
83
- * The function that sets the value of `seniorities`. Refer to [CampaignStoreState](/docs/sdk/campaigns/#campaignstorestate) for more details.
84
- */
85
- setSeniorities: CampaignStoreSetSenioritiesHandler
86
- /**
87
- * The function that sets the value of `senioritiesAreLoading`. Refer to [CampaignStoreState](/docs/sdk/campaigns/#campaignstorestate) for more details.
88
- */
89
- setSenoritiesAreLoading: CampaignStoreSetSenioritiesAreLoadingHandler
90
- }
@@ -1,84 +0,0 @@
1
- import { EmploymentType, SalaryPeriod } from "./enums"
2
- import { CampaignStoreState } from "./state.types"
3
-
4
- export const initialCampaignStoreState: CampaignStoreState = {
5
- campaigns: [],
6
- campaignsPaginationMeta: {
7
- limit: 20,
8
- offset: 0,
9
- },
10
- campaignsAreLoading: false,
11
- campaignForm: {
12
- recruiterInfo: {
13
- name: "",
14
- emailAddress: "",
15
- },
16
- postingDetails: {
17
- title: "",
18
- description: "",
19
- organization: {
20
- name: "",
21
- companyLogo: "",
22
- },
23
- contactInfo: {
24
- name: "",
25
- emailAddress: "",
26
- phoneNumber: "",
27
- },
28
- workingLocation: {
29
- addressLine1: "",
30
- addressLine2: "",
31
- postcode: "",
32
- city: "",
33
- country: "",
34
- allowsRemoteWork: 0,
35
- },
36
- yearsOfExperience: 0,
37
- employmentType: EmploymentType.permanent,
38
- weeklyWorkingHours: {
39
- from: 0,
40
- to: 0,
41
- },
42
- salaryIndication: {
43
- period: SalaryPeriod.MONTHLY,
44
- range: {
45
- from: 0,
46
- to: 0,
47
- currency: "",
48
- },
49
- },
50
- jobPageUrl: "",
51
- applicationUrl: "",
52
- },
53
- targetGroup: {
54
- educationLevel: [],
55
- seniority: [],
56
- industry: [],
57
- jobCategory: [],
58
- },
59
- orderedProducts: [],
60
- orderedProductsSpecs: {},
61
- campaignName: "",
62
- companyId: "",
63
- },
64
- campaignIsCreating: false,
65
- /* Education Levels */
66
- educationLevels: [],
67
- educationLevelsAreLoading: false,
68
- /* Seniorities */
69
- seniorities: [],
70
- senioritiesAreLoading: false,
71
- /* Employment Types */
72
- employmentTypes: [
73
- { value: EmploymentType.permanent, label: "Permanent" },
74
- { value: EmploymentType.temporary, label: "Temporary" },
75
- { value: EmploymentType.fixed_term, label: "Fixed term" },
76
- {
77
- value: EmploymentType.fixed_term_with_option_for_permanent,
78
- label: "Fixed term with option for permanent",
79
- },
80
- { value: EmploymentType.freelance, label: "Freelance" },
81
- { value: EmploymentType.traineeship, label: "Traineeship" },
82
- { value: EmploymentType.internship, label: "Internship" },
83
- ],
84
- }
@@ -1,16 +0,0 @@
1
- import { CampaignStoreState } from "./state.types"
2
- import { StateValidations } from "../_window/state.types"
3
-
4
- export const campaignStoreStateValidations: StateValidations<CampaignStoreState> =
5
- {
6
- campaigns: "campaign.campaigns",
7
- campaignsPaginationMeta: "common.paginationMetaV2",
8
- campaignsAreLoading: "common.genericBoolean",
9
- campaignIsCreating: "common.genericBoolean",
10
- campaignForm: "campaign.campaignForm",
11
- educationLevels: "campaign.educationLevels",
12
- educationLevelsAreLoading: "common.genericBoolean",
13
- seniorities: "campaign.seniorities",
14
- senioritiesAreLoading: "common.genericBoolean",
15
- employmentTypes: "campaign.employmentTypes",
16
- }
@@ -1,53 +0,0 @@
1
- import { TransformedPostingRequirement } from "./types"
2
-
3
- export const getShouldDisplayPostingRequirement = (
4
- requirement: TransformedPostingRequirement,
5
- form: Record<string, any>,
6
- ) => {
7
- const getIsFacetVisible = (
8
- operation: string,
9
- operationValues: any[],
10
- value: any,
11
- ) => {
12
- if (operation == "equal") {
13
- return value == operationValues
14
- } else if (operation == "in") {
15
- if (Array.isArray(value)) {
16
- const values = value.map((val) => val.value)
17
- return operationValues.some((operationValue) =>
18
- values.includes(operationValue),
19
- )
20
- }
21
- return operationValues.includes(value)
22
- } else if (operation === "notempty") {
23
- if (typeof value === "string") {
24
- return value.trim() !== ""
25
- } else if (Array.isArray(value)) {
26
- return value.length > 0
27
- } else if (typeof value === "object") {
28
- return Object.keys(value).length > 0
29
- } else {
30
- return !!value
31
- }
32
- }
33
- return false
34
- }
35
- let shouldShow = true
36
- if (!requirement.display_rules?.show?.length) return true
37
- const foundRule = requirement.display_rules.show.findIndex((rule) => {
38
- const facetCheckValue = form[rule.facet]
39
- if (facetCheckValue === undefined) {
40
- shouldShow = false
41
- }
42
- return getIsFacetVisible(
43
- rule.op,
44
- rule.value,
45
- typeof facetCheckValue === "object" &&
46
- !Array.isArray(facetCheckValue)
47
- ? facetCheckValue?.value
48
- : facetCheckValue,
49
- )
50
- })
51
- shouldShow = foundRule != -1
52
- return shouldShow
53
- }
@@ -1,123 +0,0 @@
1
- import { isBrowser } from "./browser"
2
-
3
- export default class LocalStorage {
4
- private static localStorageFull: boolean = false
5
-
6
- static set(key: string, value: any): void {
7
- try {
8
- if (isBrowser && !this.localStorageFull) {
9
- localStorage.setItem(key, JSON.stringify(value))
10
- }
11
- } catch (e) {
12
- try {
13
- if (isBrowser && !this.localStorageFull) {
14
- localStorage.setItem(key, JSON.stringify(value))
15
- }
16
- } catch (error) {
17
- this.localStorageFull = true
18
- }
19
- }
20
- }
21
-
22
- static setPlain(key: string, value: any): void {
23
- if (isBrowser) {
24
- localStorage.setItem(key, value)
25
- }
26
- }
27
-
28
- static remove(key: string): void {
29
- if (isBrowser) {
30
- localStorage.removeItem(key)
31
- this.localStorageFull = false
32
- }
33
- }
34
-
35
- static get(key: string): any {
36
- if (isBrowser) {
37
- const data = localStorage.getItem(key)
38
- const value = !!data ? JSON.parse(data) : ""
39
- return value
40
- }
41
- }
42
-
43
- static getOrDefault<T>(key: string, defaultValue: T): T {
44
- let response = defaultValue
45
- if (isBrowser) {
46
- const data = localStorage.getItem(key)
47
- response = !!data ? JSON.parse(data) : defaultValue
48
- }
49
- return response
50
- }
51
-
52
- static getPlain(key: string): any {
53
- if (isBrowser) {
54
- return localStorage.getItem(key)
55
- }
56
- return null
57
- }
58
-
59
- // use with caution
60
- static clear(): void {
61
- if (isBrowser) {
62
- localStorage.clear()
63
- this.localStorageFull = false
64
- }
65
- }
66
-
67
- static clearSpecific(keyChoice: (key: string) => boolean): void {
68
- if (isBrowser) {
69
- Object.keys(localStorage).forEach(
70
- (key) => keyChoice(key) && localStorage.removeItem(key),
71
- )
72
- this.localStorageFull = false
73
- }
74
- }
75
-
76
- static setWithExpiry = (key: string, value: any, ttl: number) => {
77
- const now = new Date()
78
- const item = {
79
- value: value,
80
- expiry: now.getTime() + ttl,
81
- }
82
-
83
- // New thing
84
- localStorage.setItem(key, JSON.stringify(item))
85
- }
86
-
87
- static getWithExpiry = (key: string) => {
88
- const itemStr = localStorage.getItem(key)
89
-
90
- if (!itemStr) {
91
- return null
92
- }
93
-
94
- const item = JSON.parse(itemStr)
95
- const now = new Date()
96
-
97
- if (now.getTime() > item.expiry) {
98
- localStorage.removeItem(key)
99
- return null
100
- }
101
- return item.value
102
- }
103
-
104
- static loadState = () => {
105
- try {
106
- const state = this.getWithExpiry("state")
107
- if (state === null) {
108
- return undefined
109
- }
110
- return state
111
- } catch (err) {
112
- return undefined
113
- }
114
- }
115
-
116
- static saveState = (state: any) => {
117
- try {
118
- this.setWithExpiry("state", state, 30 * 24 * 60 * 60 * 1000) // Days * Hours * Minutes * Seconds * millis
119
- } catch {
120
- // ignore write errors
121
- }
122
- }
123
- }
@@ -1,2 +0,0 @@
1
- export const isServer = typeof window === "undefined"
2
- export const isBrowser = !isServer
@@ -1,9 +0,0 @@
1
- import Color from "color"
2
-
3
- export const getColorInstanceOrUndefined = (color?: string) => {
4
- if (color?.startsWith("#")) {
5
- return Color(color)
6
- }
7
-
8
- return undefined
9
- }
@@ -1,28 +0,0 @@
1
- import { isObject } from "./misc"
2
- import isEqual from "lodash/isEqual"
3
-
4
- export const mergeDeepOverwriteArrays = (original: any, _overwrites: any) => {
5
- const output = Object.assign({}, original)
6
- const overwrites = Object.assign({}, _overwrites)
7
-
8
- if (isObject(overwrites) && Object.keys(overwrites).length > 0) {
9
- Object.keys(overwrites).forEach((key) => {
10
- const value = overwrites[key]
11
- if (Array.isArray(value) && !isEqual(output[key], value)) {
12
- output[key] = value
13
- } else if (
14
- isObject(value) &&
15
- !isEqual(
16
- output[key],
17
- mergeDeepOverwriteArrays(output[key], value),
18
- )
19
- ) {
20
- output[key] = mergeDeepOverwriteArrays(output[key], value)
21
- } else if (!isEqual(output[key], value)) {
22
- output[key] = value
23
- }
24
- })
25
- }
26
-
27
- return output
28
- }
@@ -1,13 +0,0 @@
1
- import { Logger } from "../logger/Logger"
2
- import { BaseService } from "../types"
3
-
4
- export default class HapiInstance implements BaseService {
5
- logger: Logger
6
- name: string
7
- window?: Window
8
- constructor(private _name: string, private _window?: Window) {
9
- this.name = _name
10
- this.logger = new Logger(this.name)
11
- this.window = _window
12
- }
13
- }
@@ -1 +0,0 @@
1
- export const atsInstanceName: string = "ats"
@@ -1,4 +0,0 @@
1
- // created from 'create-ts-index'
2
-
3
- export * from './Instance';
4
- export * from './consts';
@@ -1,25 +0,0 @@
1
- export const decycle = (obj: any, stack: any[] = []): any => {
2
- if (!obj || typeof obj !== "object") return obj
3
-
4
- if (stack.includes(obj)) return null
5
-
6
- let s = stack.concat([obj])
7
-
8
- return Array.isArray(obj)
9
- ? obj.map((x) => decycle(x, s))
10
- : Object.fromEntries(
11
- Object.entries(obj)
12
- .filter(
13
- ([k]) =>
14
- k !== "window" &&
15
- k !== "_window" &&
16
- k !== "core" &&
17
- k !== "events" &&
18
- k !== "state",
19
- )
20
- .map(([k, v]) => [
21
- k.startsWith("_") ? k.replace("_", "") : k,
22
- decycle(v, s),
23
- ]),
24
- )
25
- }