bt-core-app 1.4.2 → 1.4.3

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 (68) hide show
  1. package/package.json +8 -2
  2. package/dist/useApi.d.ts +0 -0
  3. package/src/assets/vue.svg +0 -1
  4. package/src/components/BT-Btn.vue +0 -41
  5. package/src/components/BT-Col.vue +0 -36
  6. package/src/components/BT-Field-Checkbox.vue +0 -70
  7. package/src/components/BT-Field-Date.vue +0 -108
  8. package/src/components/BT-Field-Entity.vue +0 -48
  9. package/src/components/BT-Field-Select.vue +0 -67
  10. package/src/components/BT-Field-String.vue +0 -78
  11. package/src/components/BT-Field-Switch.vue +0 -68
  12. package/src/components/BT-Field-Tags.vue +0 -66
  13. package/src/components/BT-Field-Textarea.vue +0 -67
  14. package/src/components/BT-Field-Trigger.vue +0 -315
  15. package/src/components/BT-Header-Option.vue +0 -39
  16. package/src/components/BT-Json.vue +0 -67
  17. package/src/components/BT-Nav-Menu-Item.vue +0 -60
  18. package/src/components/BT-Nav-Sidebar.vue +0 -78
  19. package/src/components/BT-Select-List-Box.vue +0 -258
  20. package/src/components/BT-Select.vue +0 -46
  21. package/src/components/BT-Snack.vue +0 -31
  22. package/src/components/BT-Span.vue +0 -21
  23. package/src/components/Dialog-Confirm.vue +0 -47
  24. package/src/components/Dialog-Select-Date.vue +0 -89
  25. package/src/components/Dialog-Select.vue +0 -140
  26. package/src/components/Dialog-Text.vue +0 -59
  27. package/src/composables/actions-tracker.ts +0 -99
  28. package/src/composables/actions.ts +0 -354
  29. package/src/composables/api.ts +0 -479
  30. package/src/composables/auth.ts +0 -452
  31. package/src/composables/cosmetics.ts +0 -177
  32. package/src/composables/csv.ts +0 -198
  33. package/src/composables/dates.ts +0 -86
  34. package/src/composables/demo.ts +0 -33
  35. package/src/composables/dialogs.ts +0 -114
  36. package/src/composables/document-meta.ts +0 -44
  37. package/src/composables/draggable.ts +0 -189
  38. package/src/composables/filters.ts +0 -264
  39. package/src/composables/forage.ts +0 -49
  40. package/src/composables/helpers.ts +0 -647
  41. package/src/composables/id.ts +0 -20
  42. package/src/composables/list.ts +0 -604
  43. package/src/composables/navigation.ts +0 -222
  44. package/src/composables/presets.ts +0 -28
  45. package/src/composables/pwa.ts +0 -97
  46. package/src/composables/resizable.ts +0 -382
  47. package/src/composables/rules.ts +0 -40
  48. package/src/composables/stores.ts +0 -818
  49. package/src/composables/track.ts +0 -55
  50. package/src/composables/urls.ts +0 -66
  51. package/src/core.ts +0 -113
  52. package/src/index.ts +0 -48
  53. package/src/types.ts +0 -17
  54. package/src/useApi.ts +0 -68
  55. package/src/vite-env.d.ts +0 -1
  56. package/test/api.test.ts +0 -84
  57. package/test/auth.test.ts +0 -74
  58. package/test/forage.test.ts +0 -31
  59. package/test/helpers.test.ts +0 -231
  60. package/test/navigation.test.ts +0 -99
  61. package/test/stores-last-update.test.ts +0 -138
  62. package/test/stores-session.test.ts +0 -118
  63. package/test/track.test.ts +0 -29
  64. package/test/urls.test.ts +0 -42
  65. package/test/utils.ts +0 -15
  66. package/tsconfig.json +0 -28
  67. package/tsconfig.node.json +0 -11
  68. package/vite.config.ts +0 -45
@@ -1,479 +0,0 @@
1
- import { toValue } from 'vue'
2
- import { appendUrl } from '../composables/helpers'
3
- import { type BTAuth } from './auth'
4
-
5
- export interface QueryParams {
6
- filterBy?: string,
7
- includeCount?: boolean,
8
- includeDetails?: boolean,
9
- includeInactive?: boolean,
10
- lastUpdate?: string,
11
- other?: any //for other random params
12
- properties?: string[] | string,
13
- query?: string,
14
- searchString?: string,
15
- sortOrder?: string,
16
- sortBy?: string,
17
- takeFrom?: number,
18
- takeAmount?: number
19
- }
20
-
21
- export interface PathOptions {
22
- /**always added to end before query {url}/{additionalUrl}?{query} */
23
- additionalUrl?: string
24
- /**application/json or other options */
25
- contentType?: string
26
- /**that data to send in the body for POST, PATCH, and DELETE requests */
27
- data?: any
28
- /** resulting url after building {nav | url}/{additionalUrl}?{params} */
29
- finalUrl?: string,
30
- /**override default headers */
31
- headers?: HeadersInit
32
- /**id will be added as a url paramter (/{id}?) rather than as a query parameter */
33
- id?: string
34
- /**where to find the url */
35
- nav?: string
36
- /**headers will not be calculated. Only the given headers in these options will be used */
37
- overrideHeaders?: boolean
38
- /**query parameters */
39
- params?: QueryParams
40
- /**attaches a proxyID to the request */
41
- proxyID?: string
42
- /**whether to refresh the store data and go straight to the server */
43
- refresh?: boolean
44
- /**returns result as a json object. Defaults to true. */
45
- returnJson?: boolean
46
- /**returns result as a string */
47
- returnText?: boolean
48
- /**If false, returns response no matter the status code */
49
- throwError?: boolean
50
- /**if exists then overrides default nav */
51
- url?: string
52
- /**whether to preference using the local cache */
53
- useLocalCache?: boolean
54
- }
55
-
56
- type FindPath = (navName?: string) => string | undefined
57
- // type BuildHeaders = (path: PathOptions) => HeadersInit
58
- // type BuildQuery = (params: any) => string
59
- // type BuildUrl = (path: PathOptions) => string
60
-
61
- export interface UseApiOptions {
62
- auth?: BTAuth
63
- /**overrides the default */
64
- buildHeaders?: (path: PathOptions) => HeadersInit
65
- /**build a query. Overrides the default */
66
- buildQuery?: (params: any) => string
67
- /**overrides the default */
68
- buildUrl?: (path: PathOptions) => string
69
- /**defaults to 'application/json' */
70
- defaultContentType?: string
71
- /**returns result as a json object. Defaults to true. */
72
- defaultReturnJson?: boolean
73
- /**returns result as a string */
74
- defaultReturnText?: boolean
75
- /**defaults to true. Will throw an error on fail */
76
- defaultThrowError?: boolean
77
- /**defaults to a function that returns '' */
78
- findPath?: FindPath
79
- /**if true and logged in then will set an authorization header with 'bearer [token]' */
80
- useBearerToken?: boolean
81
- }
82
-
83
- export interface BTApi {
84
- buildHeaders: (options: PathOptions) => HeadersInit
85
- buildQuery: (params: any) => string
86
- buildUrl: (path: PathOptions) => string
87
- deleteItem: (pathOptions: PathOptions) => Promise<string | undefined>
88
- get: <T>(pathOptions: PathOptions) => Promise<T>
89
- getAll: <T>(pathOptions: PathOptions) => Promise<T>
90
- post: <T>(pathOptions: PathOptions) => Promise<T | undefined>
91
- patch: <T>(pathOptions: PathOptions) => Promise<T | undefined>
92
- }
93
-
94
- let current: BTApi
95
-
96
- export function useApi(): BTApi {
97
- return current
98
- }
99
-
100
- export function createApi(options?: UseApiOptions): BTApi {
101
- const buildHeaders = options?.buildHeaders ?? defaultBuildHeaders
102
- const buildQuery = options?.buildQuery ?? defaultBuildQuery
103
- const buildUrl = options?.buildUrl ?? defaultBuildUrl
104
-
105
- function defaultBuildQuery(params: QueryParams): string {
106
- let query = new URLSearchParams()
107
-
108
- Object.entries(params).forEach(x => {
109
- if (x[1] != undefined) {
110
- query.append(x[0], x[1])
111
- }
112
- })
113
-
114
- if (params.filterBy) {
115
- query.set('filterBy', params.filterBy)
116
- }
117
-
118
- if (params.includeCount)
119
- query.set('includeCount', params.includeCount.toString())
120
-
121
- if (params.includeDetails != undefined)
122
- query.set('includeDetails', params.includeDetails.toString())
123
-
124
- if (params.includeInactive)
125
- query.set('includeInactive', params.includeInactive.toString())
126
-
127
- if (params.properties)
128
- query.set('properties', params.properties.toString())
129
-
130
- if (params.query)
131
- query.set('query', params.query.toString())
132
-
133
- if (params.searchString)
134
- query.set('searchString', params.searchString)
135
-
136
- if (params.sortOrder)
137
- query.set('sortOrder', params.sortOrder)
138
-
139
- if (params.sortBy)
140
- query.set('sortBy', params.sortBy)
141
-
142
- if (params.takeFrom)
143
- query.set('takeFrom', params.takeFrom.toString())
144
-
145
- if (params.takeAmount)
146
- query.set('takeAmount', params.takeAmount.toString())
147
-
148
- if (params.other) {
149
- Object.entries(params.other).forEach(x => {
150
- if (x[1] != undefined) {
151
- query.append(x[0], x[1].toString())
152
- }
153
- })
154
- }
155
-
156
- return query.toString()
157
- }
158
-
159
- /**returns path and sets final url */
160
- function defaultBuildUrl(path: PathOptions) {
161
- let url: string | undefined = toValue(path.url) ?? undefined
162
- let id = toValue(path.id)
163
-
164
- if (url == null && path.nav != null && options?.findPath != null)
165
- url = options.findPath(path.nav)
166
-
167
- if (path.additionalUrl != null) {
168
- if (url == null)
169
- url = path.additionalUrl
170
- else
171
- url = appendUrl(url, path.additionalUrl)
172
- }
173
-
174
- if (id != null) {
175
- if (url?.includes('{id}'))
176
- url = url.replaceAll('{id}', id)
177
- else
178
- url = appendUrl(url, id)
179
- }
180
-
181
- if (path.params != null)
182
- url = `${url}?${buildQuery(path.params)}`
183
-
184
- path.finalUrl = url
185
-
186
- return path.finalUrl ?? ''
187
- }
188
-
189
- function defaultBuildHeaders(path: PathOptions): HeadersInit {
190
- let fetchOptions:any = { ...path.headers }
191
- //const auth = options?.auth?.credentials
192
-
193
- if (path.proxyID)
194
- fetchOptions.ManagedCompanyAccountID ??= path.proxyID
195
-
196
- if (options?.useBearerToken != false && options?.auth?.isLoggedIn.value == true)
197
- fetchOptions.authorization ??= `bearer ${options?.auth?.credentials.value.token}`
198
-
199
- fetchOptions['Content-Type'] ??= (path.contentType ?? options?.defaultContentType ?? 'application/json')
200
-
201
- return fetchOptions
202
- }
203
-
204
- async function get<T>(pathOptions: PathOptions): Promise<T> {
205
- const throwError = pathOptions.throwError ?? options?.defaultThrowError ?? true
206
- const returnJson = pathOptions.returnJson ?? options?.defaultReturnJson ?? true
207
- const returnText = pathOptions.returnText ?? options?.defaultReturnText ?? false
208
-
209
- let url = pathOptions.finalUrl
210
- let headers = pathOptions.headers
211
-
212
- if (url == null)
213
- url = buildUrl(pathOptions)
214
-
215
- if (pathOptions.overrideHeaders !== true)
216
- headers = buildHeaders(pathOptions)
217
-
218
- console.log(`Get from ${url}`)
219
-
220
- let res: any = undefined
221
-
222
- try {
223
- res = await fetch(url, {
224
- method: 'GET',
225
- mode: 'cors',
226
- cache: 'no-cache',
227
- headers
228
- });
229
-
230
- // if (!throwError) {
231
- // return res
232
- // }
233
-
234
- if (!res.ok) {
235
- let errorContent = await res.text()
236
- throw new Error(errorContent ?? res.statusText ?? 'Get error')
237
- }
238
-
239
- if (returnText)
240
- return await res.text()
241
- if (returnJson)
242
- return await res.json()
243
-
244
- return res
245
- }
246
- catch (err) {
247
- if (!throwError) {
248
- return res
249
- }
250
-
251
- throw new Error(err as string)
252
- }
253
- }
254
-
255
- async function getAll<T>(pathOptions: PathOptions): Promise<T> {
256
- const throwError = pathOptions.throwError ?? options?.defaultThrowError ?? true
257
- const returnJson = pathOptions.returnJson ?? options?.defaultReturnJson ?? true
258
- const returnText = pathOptions.returnText ?? options?.defaultReturnText ?? false
259
-
260
- let url = pathOptions.finalUrl
261
- let headers = pathOptions.headers
262
-
263
- if (url == null)
264
- url = buildUrl(pathOptions)
265
-
266
- if (pathOptions.overrideHeaders !== true)
267
- headers = buildHeaders(pathOptions)
268
-
269
- console.log(`Get all from ${url}`)
270
-
271
- let res: any = undefined
272
-
273
- try {
274
- res = await fetch(url, {
275
- method: 'GET',
276
- mode: 'cors',
277
- cache: 'no-cache',
278
- headers
279
- });
280
-
281
- // if (!throwError) {
282
- // return res
283
- // }
284
-
285
- if (!res.ok) {
286
- let errorContent = await res.text()
287
- throw new Error(errorContent ?? res.statusText ?? 'Get all error')
288
- }
289
-
290
- if (returnText)
291
- return await res.text()
292
- if (returnJson)
293
- return await res.json()
294
-
295
- return res
296
- }
297
- catch (err) {
298
- if (!throwError) {
299
- return res
300
- }
301
-
302
- throw new Error(err as string)
303
- }
304
-
305
- }
306
-
307
- async function post<T>(pathOptions: PathOptions): Promise<T | undefined> {
308
- const throwError = pathOptions.throwError ?? options?.defaultThrowError ?? true
309
- const returnJson = pathOptions.returnJson ?? options?.defaultReturnJson ?? true
310
- const returnText = pathOptions.returnText ?? options?.defaultReturnText ?? false
311
-
312
- let url = pathOptions.finalUrl
313
- let headers = pathOptions.headers
314
-
315
- if (url == null)
316
- url = buildUrl(pathOptions)
317
-
318
- if (pathOptions.overrideHeaders !== true)
319
- headers = buildHeaders(pathOptions)
320
-
321
- console.log(`Post to ${url}`)
322
-
323
- let res: any = undefined
324
-
325
- try {
326
- res = await fetch(url, {
327
- method: 'POST',
328
- mode: 'cors',
329
- cache: 'no-cache',
330
- headers,
331
- body: JSON.stringify(pathOptions.data)
332
- })
333
-
334
- // if (!throwError) {
335
- // return res
336
- // }
337
-
338
- if (!res.ok) {
339
- let errorContent = await res.text()
340
- throw new Error(errorContent ?? res.statusText ?? 'Post error!')
341
- }
342
-
343
- if (returnText)
344
- return await res.text()
345
- if (returnJson)
346
- return await res.json()
347
-
348
- return res
349
- }
350
- catch (err) {
351
- if (!throwError) {
352
- return res
353
- }
354
-
355
- if (res.status == 200)
356
- return undefined
357
-
358
- throw new Error(err as string)
359
- }
360
- }
361
-
362
- async function patch<T>(pathOptions: PathOptions): Promise<T | undefined> {
363
- const throwError = pathOptions.throwError ?? options?.defaultThrowError ?? true
364
- const returnJson = pathOptions.returnJson ?? options?.defaultReturnJson ?? true
365
- const returnText = pathOptions.returnText ?? options?.defaultReturnText ?? false
366
-
367
- let url = pathOptions.finalUrl
368
- let headers = pathOptions.headers
369
-
370
- if (url == null)
371
- url = buildUrl(pathOptions)
372
-
373
- if (pathOptions.overrideHeaders !== true)
374
- headers = buildHeaders(pathOptions)
375
-
376
- console.log(`Patch to ${url}`)
377
-
378
- let res: any = undefined
379
-
380
- try {
381
- res = await fetch(url, {
382
- method: 'PATCH',
383
- mode: 'cors',
384
- cache: 'no-cache',
385
- headers,
386
- body: JSON.stringify(pathOptions.data)
387
- })
388
-
389
- // if (!throwError) {
390
- // return res
391
- // }
392
-
393
- if (!res.ok) {
394
- let errorContent = await res.text()
395
- throw new Error(errorContent ?? res.statusText ?? 'Patch error!')
396
- }
397
-
398
- if (returnText)
399
- return await res.text()
400
- if (returnJson)
401
- return await res.json()
402
-
403
- return res
404
- }
405
- catch (err) {
406
- if (!throwError) {
407
- return res
408
- }
409
-
410
- if (res.status == 200)
411
- return undefined
412
-
413
- throw new Error(err as string)
414
- }
415
- }
416
-
417
- /**
418
- *
419
- * @param options
420
- * returns an error msg if failed
421
- */
422
- async function deleteItem(pathOptions: PathOptions): Promise<string | undefined> {
423
- const throwError = pathOptions.throwError ?? options?.defaultThrowError ?? true
424
-
425
- let url = pathOptions.finalUrl
426
- let headers = pathOptions.headers
427
-
428
- if (url == null)
429
- url = buildUrl(pathOptions)
430
-
431
- if (pathOptions.overrideHeaders !== true)
432
- headers = buildHeaders(pathOptions)
433
-
434
- console.log(`Delete ${url}`)
435
-
436
- let res: any = undefined
437
-
438
- try {
439
- res = await fetch(url, {
440
- method: 'DELETE',
441
- mode: 'cors',
442
- cache: 'no-cache',
443
- headers,
444
- body: JSON.stringify(pathOptions.data)
445
- })
446
-
447
- // if (!throwError) {
448
- // return res
449
- // }
450
-
451
- if (res.status == 200) {
452
- return undefined
453
- }
454
- else {
455
- return res.statusText
456
- }
457
- }
458
- catch (err) {
459
- if (!throwError) {
460
- return res
461
- }
462
-
463
- throw new Error(err as string)
464
- }
465
- }
466
-
467
- current = {
468
- buildHeaders,
469
- buildQuery,
470
- buildUrl,
471
- deleteItem,
472
- get,
473
- getAll,
474
- patch,
475
- post
476
- }
477
-
478
- return current
479
- }