@athoscommerce/snap-store-mobx 1.2.3-beta.4 → 1.4.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 (81) hide show
  1. package/dist/cjs/Autocomplete/AutocompleteStore.d.ts +1 -1
  2. package/dist/cjs/Autocomplete/AutocompleteStore.d.ts.map +1 -1
  3. package/dist/cjs/Autocomplete/AutocompleteStore.js +4 -4
  4. package/dist/cjs/Autocomplete/Stores/AutocompleteFacetStore.d.ts.map +1 -1
  5. package/dist/cjs/Autocomplete/Stores/AutocompleteFacetStore.js +2 -4
  6. package/dist/cjs/Finder/FinderStore.d.ts +1 -1
  7. package/dist/cjs/Finder/FinderStore.d.ts.map +1 -1
  8. package/dist/cjs/Finder/FinderStore.js +3 -3
  9. package/dist/cjs/Finder/Stores/FinderSelectionStore.d.ts +1 -1
  10. package/dist/cjs/Finder/Stores/FinderSelectionStore.d.ts.map +1 -1
  11. package/dist/cjs/Search/SearchStore.d.ts +1 -1
  12. package/dist/cjs/Search/SearchStore.d.ts.map +1 -1
  13. package/dist/cjs/Search/SearchStore.js +2 -2
  14. package/dist/cjs/Search/Stores/SearchFacetStore.d.ts +12 -12
  15. package/dist/cjs/Search/Stores/SearchFacetStore.d.ts.map +1 -1
  16. package/dist/cjs/Search/Stores/SearchFacetStore.js +22 -32
  17. package/dist/cjs/Search/Stores/SearchHistoryStore.js +2 -2
  18. package/dist/cjs/Search/Stores/index.d.ts +1 -1
  19. package/dist/cjs/Search/Stores/index.d.ts.map +1 -1
  20. package/dist/cjs/Search/Stores/index.js +1 -2
  21. package/dist/cjs/index.d.ts +1 -5
  22. package/dist/cjs/index.d.ts.map +1 -1
  23. package/dist/cjs/index.js +4 -8
  24. package/dist/cjs/types.d.ts +2 -13
  25. package/dist/cjs/types.d.ts.map +1 -1
  26. package/dist/esm/Autocomplete/AutocompleteStore.d.ts +1 -1
  27. package/dist/esm/Autocomplete/AutocompleteStore.d.ts.map +1 -1
  28. package/dist/esm/Autocomplete/AutocompleteStore.js +2 -2
  29. package/dist/esm/Autocomplete/Stores/AutocompleteFacetStore.d.ts.map +1 -1
  30. package/dist/esm/Autocomplete/Stores/AutocompleteFacetStore.js +5 -7
  31. package/dist/esm/Finder/FinderStore.d.ts +1 -1
  32. package/dist/esm/Finder/FinderStore.d.ts.map +1 -1
  33. package/dist/esm/Finder/FinderStore.js +1 -1
  34. package/dist/esm/Finder/Stores/FinderSelectionStore.d.ts +1 -1
  35. package/dist/esm/Finder/Stores/FinderSelectionStore.d.ts.map +1 -1
  36. package/dist/esm/Search/SearchStore.d.ts +1 -1
  37. package/dist/esm/Search/SearchStore.d.ts.map +1 -1
  38. package/dist/esm/Search/SearchStore.js +1 -1
  39. package/dist/esm/Search/Stores/SearchFacetStore.d.ts +12 -12
  40. package/dist/esm/Search/Stores/SearchFacetStore.d.ts.map +1 -1
  41. package/dist/esm/Search/Stores/SearchFacetStore.js +22 -31
  42. package/dist/esm/Search/Stores/SearchHistoryStore.js +1 -1
  43. package/dist/esm/Search/Stores/index.d.ts +1 -1
  44. package/dist/esm/Search/Stores/index.d.ts.map +1 -1
  45. package/dist/esm/Search/Stores/index.js +1 -1
  46. package/dist/esm/index.d.ts +1 -5
  47. package/dist/esm/index.d.ts.map +1 -1
  48. package/dist/esm/index.js +1 -3
  49. package/dist/esm/types.d.ts +2 -13
  50. package/dist/esm/types.d.ts.map +1 -1
  51. package/package.json +11 -6
  52. package/dist/cjs/Chat/ChatStore.d.ts +0 -57
  53. package/dist/cjs/Chat/ChatStore.d.ts.map +0 -1
  54. package/dist/cjs/Chat/ChatStore.js +0 -415
  55. package/dist/cjs/Chat/Stores/ChatAttachmentStore.d.ts +0 -98
  56. package/dist/cjs/Chat/Stores/ChatAttachmentStore.d.ts.map +0 -1
  57. package/dist/cjs/Chat/Stores/ChatAttachmentStore.js +0 -314
  58. package/dist/cjs/Chat/Stores/ChatCompareStore.d.ts +0 -14
  59. package/dist/cjs/Chat/Stores/ChatCompareStore.d.ts.map +0 -1
  60. package/dist/cjs/Chat/Stores/ChatCompareStore.js +0 -63
  61. package/dist/cjs/Chat/Stores/ChatSessionStore.d.ts +0 -117
  62. package/dist/cjs/Chat/Stores/ChatSessionStore.d.ts.map +0 -1
  63. package/dist/cjs/Chat/Stores/ChatSessionStore.js +0 -689
  64. package/dist/cjs/Storage/StorageStore.d.ts +0 -27
  65. package/dist/cjs/Storage/StorageStore.d.ts.map +0 -1
  66. package/dist/cjs/Storage/StorageStore.js +0 -176
  67. package/dist/esm/Chat/ChatStore.d.ts +0 -57
  68. package/dist/esm/Chat/ChatStore.d.ts.map +0 -1
  69. package/dist/esm/Chat/ChatStore.js +0 -355
  70. package/dist/esm/Chat/Stores/ChatAttachmentStore.d.ts +0 -98
  71. package/dist/esm/Chat/Stores/ChatAttachmentStore.d.ts.map +0 -1
  72. package/dist/esm/Chat/Stores/ChatAttachmentStore.js +0 -222
  73. package/dist/esm/Chat/Stores/ChatCompareStore.d.ts +0 -14
  74. package/dist/esm/Chat/Stores/ChatCompareStore.d.ts.map +0 -1
  75. package/dist/esm/Chat/Stores/ChatCompareStore.js +0 -49
  76. package/dist/esm/Chat/Stores/ChatSessionStore.d.ts +0 -117
  77. package/dist/esm/Chat/Stores/ChatSessionStore.d.ts.map +0 -1
  78. package/dist/esm/Chat/Stores/ChatSessionStore.js +0 -661
  79. package/dist/esm/Storage/StorageStore.d.ts +0 -27
  80. package/dist/esm/Storage/StorageStore.d.ts.map +0 -1
  81. package/dist/esm/Storage/StorageStore.js +0 -169
@@ -1,169 +0,0 @@
1
- import { featureFlags, cookies } from '@athoscommerce/snap-toolbox';
2
- const utils = {
3
- cookies,
4
- };
5
- export class StorageStore {
6
- constructor(config) {
7
- this.type = null;
8
- this.expiration = 31536000000; // one year (ms)
9
- this.sameSite = 'Lax';
10
- this.key = 'ss-storage';
11
- this.cookieDomain = (typeof window !== 'undefined' && window.location.hostname && '.' + window.location.hostname.replace(/^www\./, '')) || undefined;
12
- this.state = {};
13
- if (config) {
14
- if (config.key.trim() !== '') {
15
- this.key = config.key.trim();
16
- }
17
- if (config?.cookie?.expiration) {
18
- this.expiration = config.cookie.expiration;
19
- }
20
- if (config?.cookie?.sameSite) {
21
- this.sameSite = config.cookie.sameSite;
22
- }
23
- switch (config.type) {
24
- case StorageType.session: {
25
- this.type = featureFlags.storage ? config.type : null;
26
- if (this.type) {
27
- this.state = JSON.parse(window.sessionStorage.getItem(this.key) || '{}');
28
- window.sessionStorage.setItem(this.key, JSON.stringify(this.state));
29
- }
30
- break;
31
- }
32
- case StorageType.local: {
33
- this.type = featureFlags.storage ? config.type : null;
34
- if (this.type) {
35
- this.state = JSON.parse(window.localStorage.getItem(this.key) || '{}');
36
- window.localStorage.setItem(this.key, JSON.stringify(this.state));
37
- }
38
- break;
39
- }
40
- case StorageType.cookie: {
41
- if (featureFlags.cookies) {
42
- this.type = config.type;
43
- const data = utils.cookies.get(this.key);
44
- if (data) {
45
- this.state = JSON.parse(data);
46
- }
47
- }
48
- break;
49
- }
50
- default: {
51
- this.type = StorageType.memory;
52
- }
53
- }
54
- }
55
- }
56
- set(path, value) {
57
- // read from the backing storage first to update local state to ensure we get any changes made outside of the storageStore
58
- switch (this.type) {
59
- case StorageType.session: {
60
- this.state = JSON.parse(window.sessionStorage.getItem(this.key) || '{}');
61
- break;
62
- }
63
- case StorageType.local: {
64
- this.state = JSON.parse(window.localStorage.getItem(this.key) || '{}');
65
- break;
66
- }
67
- case StorageType.cookie: {
68
- const data = utils.cookies.get(this.key);
69
- if (data) {
70
- this.state = JSON.parse(data);
71
- }
72
- break;
73
- }
74
- }
75
- let paths;
76
- if (typeof path == 'string') {
77
- paths = path?.split('.');
78
- }
79
- else {
80
- paths = path;
81
- }
82
- let location = this.state;
83
- paths?.forEach((p, i) => {
84
- const leaf = i == paths.length - 1;
85
- if (leaf) {
86
- location[p] = value;
87
- }
88
- else {
89
- location = location[p] = location[p] || {};
90
- }
91
- });
92
- try {
93
- switch (this.type) {
94
- case StorageType.session:
95
- window.sessionStorage.setItem(this.key, JSON.stringify(this.state));
96
- break;
97
- case StorageType.local:
98
- window.localStorage.setItem(this.key, JSON.stringify(this.state));
99
- break;
100
- case StorageType.cookie:
101
- utils.cookies.set(this.key, JSON.stringify(this.state), this.sameSite, this.expiration, this.cookieDomain);
102
- break;
103
- }
104
- }
105
- catch (err) {
106
- console.warn(`something went wrong setting ${this.key} to ${this.type} storage`);
107
- }
108
- }
109
- // TODO: change any to unknown and refactor
110
- get(path) {
111
- switch (this.type) {
112
- case StorageType.session:
113
- const sessionData = window.sessionStorage.getItem(this.key);
114
- this.state = sessionData ? JSON.parse(sessionData) : {};
115
- break;
116
- case StorageType.local:
117
- const localData = window.localStorage.getItem(this.key);
118
- this.state = localData ? JSON.parse(localData) : {};
119
- break;
120
- case StorageType.cookie:
121
- const data = utils.cookies.get(this.key);
122
- if (data) {
123
- this.state = JSON.parse(data) || {};
124
- }
125
- break;
126
- }
127
- let paths;
128
- if (typeof path == 'string') {
129
- paths = path?.split('.');
130
- }
131
- else {
132
- paths = path;
133
- }
134
- if (!paths?.length)
135
- return undefined;
136
- let value = this.state;
137
- for (const p of paths) {
138
- if (value && typeof value[p] != 'undefined') {
139
- value = value[p];
140
- }
141
- else {
142
- value = {};
143
- return;
144
- }
145
- }
146
- return value;
147
- }
148
- clear() {
149
- switch (this.type) {
150
- case StorageType.session:
151
- window.sessionStorage.removeItem(this.key);
152
- break;
153
- case StorageType.local:
154
- window.localStorage.removeItem(this.key);
155
- break;
156
- case StorageType.cookie:
157
- utils.cookies.unset(this.key, this.cookieDomain);
158
- break;
159
- }
160
- this.state = {};
161
- }
162
- }
163
- export var StorageType;
164
- (function (StorageType) {
165
- StorageType["session"] = "session";
166
- StorageType["local"] = "local";
167
- StorageType["cookie"] = "cookie";
168
- StorageType["memory"] = "memory";
169
- })(StorageType || (StorageType = {}));