@inzombieland/core 0.0.1 → 1.18.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 (45) hide show
  1. package/AppProvider.vue +36 -0
  2. package/LICENSE +8 -0
  3. package/api-client.d.ts +7 -0
  4. package/api-client.mjs +130 -0
  5. package/bus.d.ts +7 -0
  6. package/bus.mjs +22 -0
  7. package/comet-client.d.ts +11 -0
  8. package/comet-client.mjs +73 -0
  9. package/composables/use-active-sessions.d.ts +26 -0
  10. package/composables/use-active-sessions.mjs +14 -0
  11. package/composables/use-api-actions.d.ts +13 -0
  12. package/composables/use-api-actions.mjs +5 -0
  13. package/composables/use-app-locale.d.ts +1 -0
  14. package/composables/use-app-locale.mjs +13 -0
  15. package/composables/use-subscribe.d.ts +10 -0
  16. package/composables/use-subscribe.mjs +22 -0
  17. package/composables/use-theme-mode.d.ts +1 -0
  18. package/composables/use-theme-mode.mjs +14 -0
  19. package/composables/use-user.d.ts +32 -0
  20. package/composables/use-user.mjs +5 -0
  21. package/get-user.d.ts +2 -0
  22. package/get-user.mjs +55 -0
  23. package/get-visitor.d.ts +11 -0
  24. package/get-visitor.mjs +48 -0
  25. package/helpers/api-helper.d.ts +6 -0
  26. package/helpers/api-helper.mjs +99 -0
  27. package/helpers/current-device.d.ts +67 -0
  28. package/helpers/current-device.mjs +368 -0
  29. package/helpers/date-helper.d.ts +15 -0
  30. package/helpers/date-helper.mjs +230 -0
  31. package/helpers/device-helper.d.ts +43 -0
  32. package/helpers/device-helper.mjs +15 -0
  33. package/helpers/index.d.ts +4 -0
  34. package/helpers/index.mjs +15 -0
  35. package/index.d.ts +53 -0
  36. package/index.mjs +60 -0
  37. package/init-application.d.ts +1 -0
  38. package/init-application.mjs +89 -0
  39. package/package.json +12 -1
  40. package/refresh-token.d.ts +2 -0
  41. package/refresh-token.mjs +39 -0
  42. package/types.d.ts +71 -0
  43. package/types.mjs +0 -0
  44. package/user-actions.d.ts +15 -0
  45. package/user-actions.mjs +38 -0
@@ -0,0 +1,99 @@
1
+ import { dateHelper } from "./date-helper.mjs";
2
+ const isoExp = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)((-(\d{2}):(\d{2})|Z)?)$/gm;
3
+ const isISODate = (value) => {
4
+ return typeof value === "string" && isoExp.test(value);
5
+ };
6
+ const isDate = (value) => {
7
+ return value instanceof Date;
8
+ };
9
+ const isObject = (value) => {
10
+ return typeof value === "object" && value !== null && value.constructor === Object;
11
+ };
12
+ const hasOwnProp = {}.hasOwnProperty;
13
+ export function convertToClient(data) {
14
+ if (!isObject(data) && !Array.isArray(data)) {
15
+ return data;
16
+ }
17
+ if (Array.isArray(data)) {
18
+ return data.map((item) => {
19
+ if (isObject(item)) {
20
+ return convertToClient(item);
21
+ }
22
+ return item;
23
+ });
24
+ }
25
+ const res = {};
26
+ const objectData = data;
27
+ for (const key in objectData) {
28
+ if (!hasOwnProp.call(objectData, key)) {
29
+ return;
30
+ }
31
+ const value = objectData[key];
32
+ const newKey = key === key.toUpperCase() ? key.toLowerCase() : key.slice(0, 1).toLowerCase() + key.slice(1);
33
+ if (Array.isArray(value)) {
34
+ res[newKey] = value.map((item) => {
35
+ if (isObject(item)) {
36
+ return convertToClient(item);
37
+ }
38
+ return item;
39
+ });
40
+ } else if (isObject(value)) {
41
+ res[newKey] = convertToClient(value);
42
+ } else if (isISODate(value)) {
43
+ res[newKey] = dateHelper.stringToDate(value);
44
+ } else if (value === null) {
45
+ delete res[newKey];
46
+ } else {
47
+ res[newKey] = value;
48
+ }
49
+ }
50
+ return res;
51
+ }
52
+ export function convertToServer(data) {
53
+ if (typeof data === "string") {
54
+ data = parseData(data);
55
+ }
56
+ if (!isObject(data) && !Array.isArray(data)) {
57
+ return data;
58
+ }
59
+ if (Array.isArray(data)) {
60
+ return data.map((item) => {
61
+ if (isObject(item)) {
62
+ return convertToServer(item);
63
+ }
64
+ return item;
65
+ });
66
+ }
67
+ const res = {};
68
+ const objectData = data;
69
+ for (const key in objectData) {
70
+ if (!hasOwnProp.call(objectData, key)) {
71
+ return;
72
+ }
73
+ const value = objectData[key];
74
+ const newKey = key.slice(0, 1).toUpperCase() + key.slice(1);
75
+ if (Array.isArray(value)) {
76
+ res[newKey] = value.map((item) => {
77
+ if (isObject(item)) {
78
+ return convertToServer(item);
79
+ }
80
+ return item;
81
+ });
82
+ } else if (isObject(value)) {
83
+ res[newKey] = convertToServer(value);
84
+ } else if (isDate(value)) {
85
+ res[newKey] = dateHelper.dateFormat(value, "isoDateTime");
86
+ } else {
87
+ res[newKey] = value;
88
+ }
89
+ }
90
+ return res;
91
+ }
92
+ function parseData(data) {
93
+ try {
94
+ return JSON.parse(data);
95
+ } catch {
96
+ return data;
97
+ }
98
+ }
99
+ export const apiHelper = { convertToClient, convertToServer };
@@ -0,0 +1,67 @@
1
+ export namespace device {
2
+ function macos(): any;
3
+ function ios(): any;
4
+ function iphone(): any;
5
+ function ipod(): any;
6
+ function ipad(): any;
7
+ function android(): any;
8
+ function androidPhone(): any;
9
+ function androidTablet(): any;
10
+ function blackberry(): any;
11
+ function blackberryPhone(): any;
12
+ function blackberryTablet(): any;
13
+ function windows(): any;
14
+ function windowsPhone(): any;
15
+ function windowsTablet(): any;
16
+ function fxos(): any;
17
+ function fxosPhone(): any;
18
+ function fxosTablet(): any;
19
+ function meego(): any;
20
+ function cordova(): any;
21
+ function mobile(): any;
22
+ function tablet(): any;
23
+ function desktop(): boolean;
24
+ function television(): boolean;
25
+ function portrait(): any;
26
+ function landscape(): any;
27
+ function noConflict(): {
28
+ macos(): any;
29
+ ios(): any;
30
+ iphone(): any;
31
+ ipod(): any;
32
+ ipad(): any;
33
+ android(): any;
34
+ androidPhone(): any;
35
+ androidTablet(): any;
36
+ blackberry(): any;
37
+ blackberryPhone(): any;
38
+ blackberryTablet(): any;
39
+ windows(): any;
40
+ windowsPhone(): any;
41
+ windowsTablet(): any;
42
+ fxos(): any;
43
+ fxosPhone(): any;
44
+ fxosTablet(): any;
45
+ meego(): any;
46
+ cordova(): any;
47
+ mobile(): any;
48
+ tablet(): any;
49
+ desktop(): boolean;
50
+ television(): boolean;
51
+ portrait(): any;
52
+ landscape(): any;
53
+ noConflict(): /*elided*/ any;
54
+ onChangeOrientation(cb: any): void;
55
+ linux(): any;
56
+ ubuntu(): any;
57
+ type: any;
58
+ os: any;
59
+ osName(): any;
60
+ };
61
+ function onChangeOrientation(cb: any): void;
62
+ function linux(): any;
63
+ function ubuntu(): any;
64
+ let type: any;
65
+ let os: any;
66
+ function osName(): any;
67
+ }
@@ -0,0 +1,368 @@
1
+ const device = {}
2
+
3
+ // https://github.com/matthewhudson/current-device
4
+ if (typeof window !== "undefined") {
5
+ // Public functions to get the current value of type, os, or orientation.
6
+ const findMatch = arr => {
7
+ for (const name of arr) {
8
+ if (device[name]()) {
9
+ return name
10
+ }
11
+ }
12
+ return "unknown"
13
+ }
14
+
15
+ const setOrientationCache = () => {
16
+ device.orientation = findMatch(["portrait", "landscape"])
17
+ }
18
+
19
+ const walkOnChangeOrientationList = newOrientation => {
20
+ for (const cb of changeOrientationList) {
21
+ cb(newOrientation)
22
+ }
23
+ }
24
+
25
+ // Check if documentElement already has a given class.
26
+ const hasClass = className => {
27
+ return documentElement.classList.contains(className)
28
+ }
29
+
30
+ // Add one or more CSS classes to the <html> element.
31
+ const addClass = className => {
32
+ let currentClassNames = null
33
+ if (!hasClass(className)) {
34
+ currentClassNames = documentElement.classList.toString().trim()
35
+ documentElement.className = `${currentClassNames} ${className}`
36
+ }
37
+ }
38
+
39
+ // Remove single CSS class from the <html> element.
40
+ const removeClass = className => {
41
+ if (hasClass(className)) {
42
+ documentElement.className = documentElement.className.replace(` ${className}`, "")
43
+ }
44
+ }
45
+
46
+ // Handle device orientation changes.
47
+ const handleOrientation = () => {
48
+ if (device.landscape()) {
49
+ removeClass("portrait")
50
+ addClass("landscape")
51
+ walkOnChangeOrientationList("landscape")
52
+ } else {
53
+ removeClass("landscape")
54
+ addClass("portrait")
55
+ walkOnChangeOrientationList("portrait")
56
+ }
57
+ setOrientationCache()
58
+ }
59
+
60
+ // Check if element exists.
61
+ const includes = (haystack, needle) => {
62
+ return haystack.includes(needle)
63
+ }
64
+
65
+ // Simple UA string search.
66
+ const find = needle => {
67
+ return includes(userAgent, needle)
68
+ }
69
+
70
+ // Save the previous value of the device variable.
71
+ const previousDevice = window.device
72
+
73
+ const changeOrientationList = []
74
+
75
+ // Add device as a global object.
76
+ window.device = device
77
+
78
+ // The <html> element.
79
+ const documentElement = window.document.documentElement
80
+
81
+ // The client user agent string.
82
+ // Lowercase, so we can use the more efficient indexOf(), instead of Regex
83
+ const userAgent = window.navigator.userAgent.toLowerCase()
84
+
85
+ // Detectable television devices.
86
+ const television = [
87
+ "googletv",
88
+ "viera",
89
+ "smarttv",
90
+ "internet.tv",
91
+ "netcast",
92
+ "nettv",
93
+ "appletv",
94
+ "boxee",
95
+ "kylo",
96
+ "roku",
97
+ "dlnadoc",
98
+ "pov_tv",
99
+ "hbbtv",
100
+ "ce-html",
101
+ ]
102
+
103
+ // Main functions
104
+ // --------------
105
+
106
+ device.macos = function () {
107
+ return find("mac")
108
+ }
109
+
110
+ device.ios = function () {
111
+ return device.iphone() || device.ipod() || device.ipad()
112
+ }
113
+
114
+ device.iphone = function () {
115
+ return !device.windows() && find("iphone")
116
+ }
117
+
118
+ device.ipod = function () {
119
+ return find("ipod")
120
+ }
121
+
122
+ device.ipad = function () {
123
+ const iPadOS13Up = navigator.userAgent.includes("Mac") && navigator.maxTouchPoints > 1
124
+ return find("ipad") || iPadOS13Up
125
+ }
126
+
127
+ device.android = function () {
128
+ return !device.windows() && find("android")
129
+ }
130
+
131
+ device.androidPhone = function () {
132
+ return device.android() && find("mobile")
133
+ }
134
+
135
+ device.androidTablet = function () {
136
+ return device.android() && !find("mobile")
137
+ }
138
+
139
+ device.blackberry = function () {
140
+ return find("blackberry") || find("bb10")
141
+ }
142
+
143
+ device.blackberryPhone = function () {
144
+ return device.blackberry() && !find("tablet")
145
+ }
146
+
147
+ device.blackberryTablet = function () {
148
+ return device.blackberry() && find("tablet")
149
+ }
150
+
151
+ device.windows = function () {
152
+ return find("windows")
153
+ }
154
+
155
+ device.windowsPhone = function () {
156
+ return device.windows() && find("phone")
157
+ }
158
+
159
+ device.windowsTablet = function () {
160
+ return device.windows() && find("touch") && !device.windowsPhone()
161
+ }
162
+
163
+ device.fxos = function () {
164
+ return (find("(mobile") || find("(tablet")) && find(" rv:")
165
+ }
166
+
167
+ device.fxosPhone = function () {
168
+ return device.fxos() && find("mobile")
169
+ }
170
+
171
+ device.fxosTablet = function () {
172
+ return device.fxos() && find("tablet")
173
+ }
174
+
175
+ device.meego = function () {
176
+ return find("meego")
177
+ }
178
+
179
+ device.cordova = function () {
180
+ return window.cordova && location.protocol === "file:"
181
+ }
182
+
183
+ device.mobile = function () {
184
+ return (
185
+ device.androidPhone() ||
186
+ device.iphone() ||
187
+ device.ipod() ||
188
+ device.windowsPhone() ||
189
+ device.blackberryPhone() ||
190
+ device.fxosPhone() ||
191
+ device.meego()
192
+ )
193
+ }
194
+
195
+ device.tablet = function () {
196
+ return (
197
+ device.ipad() ||
198
+ device.androidTablet() ||
199
+ device.blackberryTablet() ||
200
+ device.windowsTablet() ||
201
+ device.fxosTablet()
202
+ )
203
+ }
204
+
205
+ device.desktop = function () {
206
+ return !device.tablet() && !device.mobile()
207
+ }
208
+
209
+ device.television = function () {
210
+ let i = 0
211
+ while (i < television.length) {
212
+ if (find(television[i])) {
213
+ return true
214
+ }
215
+ i++
216
+ }
217
+ return false
218
+ }
219
+
220
+ device.portrait = function () {
221
+ if (screen.orientation) {
222
+ return includes(screen.orientation.type, "portrait")
223
+ }
224
+ return window.innerHeight / window.innerWidth > 1
225
+ }
226
+
227
+ device.landscape = function () {
228
+ if (screen.orientation) {
229
+ return includes(screen.orientation.type, "landscape")
230
+ }
231
+ return window.innerHeight / window.innerWidth < 1
232
+ }
233
+
234
+ // Public Utility Functions
235
+ // ------------------------
236
+
237
+ // Run device.js in noConflict mode,
238
+ // returning the device variable to its previous owner.
239
+ device.noConflict = function () {
240
+ window.device = previousDevice
241
+ return this
242
+ }
243
+
244
+ // Insert the appropriate CSS class based on the _user_agent.
245
+ if (device.ios()) {
246
+ if (device.ipad()) {
247
+ addClass("ios ipad tablet")
248
+ } else if (device.iphone()) {
249
+ addClass("ios iphone mobile")
250
+ } else if (device.ipod()) {
251
+ addClass("ios ipod mobile")
252
+ }
253
+ } else if (device.macos()) {
254
+ addClass("macos desktop")
255
+ } else if (device.android()) {
256
+ if (device.androidTablet()) {
257
+ addClass("android tablet")
258
+ } else {
259
+ addClass("android mobile")
260
+ }
261
+ } else if (device.blackberry()) {
262
+ if (device.blackberryTablet()) {
263
+ addClass("blackberry tablet")
264
+ } else {
265
+ addClass("blackberry mobile")
266
+ }
267
+ } else if (device.windows()) {
268
+ if (device.windowsTablet()) {
269
+ addClass("windows tablet")
270
+ } else if (device.windowsPhone()) {
271
+ addClass("windows mobile")
272
+ } else {
273
+ addClass("windows desktop")
274
+ }
275
+ } else if (device.fxos()) {
276
+ if (device.fxosTablet()) {
277
+ addClass("fxos tablet")
278
+ } else {
279
+ addClass("fxos mobile")
280
+ }
281
+ } else if (device.meego()) {
282
+ addClass("meego mobile")
283
+ } else if (device.television()) {
284
+ addClass("television")
285
+ } else if (device.desktop()) {
286
+ addClass("desktop")
287
+ }
288
+
289
+ if (device.cordova()) {
290
+ addClass("cordova")
291
+ }
292
+
293
+ device.onChangeOrientation = function (cb) {
294
+ if (typeof cb == "function") {
295
+ changeOrientationList.push(cb)
296
+ }
297
+ }
298
+
299
+ // Listen for changes in orientation.
300
+ if (screen?.orientation?.addEventListener) {
301
+ screen.orientation.addEventListener("change", handleOrientation, false)
302
+ }
303
+
304
+ handleOrientation()
305
+
306
+ device.linux = function () {
307
+ return find("linux")
308
+ }
309
+
310
+ device.ubuntu = function () {
311
+ return device.linux() && find("ubuntu")
312
+ }
313
+
314
+ device.type = findMatch(["mobile", "tablet", "desktop"])
315
+
316
+ device.os = findMatch([
317
+ "iphone",
318
+ "ipad",
319
+ "ipod",
320
+ "ios",
321
+ "android",
322
+ "blackberry",
323
+ "macos",
324
+ "windows",
325
+ "ubuntu",
326
+ "linux",
327
+ "fxos",
328
+ "meego",
329
+ "television",
330
+ ])
331
+
332
+ device.osName = function () {
333
+ switch (device.os) {
334
+ case "iphone":
335
+ return "iPhone"
336
+ case "ipad":
337
+ return "iPad"
338
+ case "ipod":
339
+ return "iPod"
340
+ case "ios":
341
+ return "iOS"
342
+ case "android":
343
+ return "Android"
344
+ case "blackberry":
345
+ return "BlackBerry"
346
+ case "macos":
347
+ return "Mac OS"
348
+ case "windows":
349
+ return "Windows"
350
+ case "ubuntu":
351
+ return "Ubuntu Linux"
352
+ case "linux":
353
+ return "Linux"
354
+ case "fxos":
355
+ return "FXOS"
356
+ case "meego":
357
+ return "MeeGo"
358
+ case "television":
359
+ return "Television"
360
+ default:
361
+ return device.os
362
+ }
363
+ }
364
+
365
+ setOrientationCache()
366
+ }
367
+
368
+ export { device }
@@ -0,0 +1,15 @@
1
+ export declare function stringToDate(dateString: unknown): Date | undefined;
2
+ /**
3
+ * Преобразование даты.
4
+ * Например из "d mmmm:R yyyy" в "5 февраля 2020"
5
+ * @param date - дата
6
+ * @param format - формат даты
7
+ * @param locale
8
+ * @param dateTimeNow
9
+ */
10
+ export declare function dateFormat(// @SONAR_STOP@
11
+ date?: Date, format?: string, locale?: string, dateTimeNow?: Date): string;
12
+ export declare const dateHelper: {
13
+ stringToDate: typeof stringToDate;
14
+ dateFormat: typeof dateFormat;
15
+ };