@mouseless/baked 0.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.
Files changed (176) hide show
  1. package/README.md +11 -0
  2. package/dist/module.d.mts +45 -0
  3. package/dist/module.json +9 -0
  4. package/dist/module.mjs +110 -0
  5. package/dist/runtime/assets/overrides.css +1 -0
  6. package/dist/runtime/assets/tailwind.css +1 -0
  7. package/dist/runtime/components/AuthorizedContent.d.vue.ts +10 -0
  8. package/dist/runtime/components/AuthorizedContent.vue +14 -0
  9. package/dist/runtime/components/AuthorizedContent.vue.d.ts +10 -0
  10. package/dist/runtime/components/Bake.d.vue.ts +20 -0
  11. package/dist/runtime/components/Bake.vue +50 -0
  12. package/dist/runtime/components/Bake.vue.d.ts +20 -0
  13. package/dist/runtime/components/BasePersistentPopover.d.vue.ts +178 -0
  14. package/dist/runtime/components/BasePersistentPopover.vue +41 -0
  15. package/dist/runtime/components/BasePersistentPopover.vue.d.ts +178 -0
  16. package/dist/runtime/components/CardLink.d.vue.ts +11 -0
  17. package/dist/runtime/components/CardLink.vue +57 -0
  18. package/dist/runtime/components/CardLink.vue.d.ts +11 -0
  19. package/dist/runtime/components/DataPanel.d.vue.ts +20 -0
  20. package/dist/runtime/components/DataPanel.vue +138 -0
  21. package/dist/runtime/components/DataPanel.vue.d.ts +20 -0
  22. package/dist/runtime/components/DataTable.d.vue.ts +11 -0
  23. package/dist/runtime/components/DataTable.vue +213 -0
  24. package/dist/runtime/components/DataTable.vue.d.ts +11 -0
  25. package/dist/runtime/components/DefaultLayout.d.vue.ts +18 -0
  26. package/dist/runtime/components/DefaultLayout.vue +44 -0
  27. package/dist/runtime/components/DefaultLayout.vue.d.ts +18 -0
  28. package/dist/runtime/components/DeferredTabContent.d.vue.ts +16 -0
  29. package/dist/runtime/components/DeferredTabContent.vue +23 -0
  30. package/dist/runtime/components/DeferredTabContent.vue.d.ts +16 -0
  31. package/dist/runtime/components/Error.d.vue.ts +3 -0
  32. package/dist/runtime/components/Error.vue +13 -0
  33. package/dist/runtime/components/Error.vue.d.ts +3 -0
  34. package/dist/runtime/components/ErrorPage.d.vue.ts +11 -0
  35. package/dist/runtime/components/ErrorPage.vue +65 -0
  36. package/dist/runtime/components/ErrorPage.vue.d.ts +11 -0
  37. package/dist/runtime/components/Filter.d.vue.ts +11 -0
  38. package/dist/runtime/components/Filter.vue +23 -0
  39. package/dist/runtime/components/Filter.vue.d.ts +11 -0
  40. package/dist/runtime/components/Header.d.vue.ts +11 -0
  41. package/dist/runtime/components/Header.vue +78 -0
  42. package/dist/runtime/components/Header.vue.d.ts +11 -0
  43. package/dist/runtime/components/Icon.d.vue.ts +11 -0
  44. package/dist/runtime/components/Icon.vue +14 -0
  45. package/dist/runtime/components/Icon.vue.d.ts +11 -0
  46. package/dist/runtime/components/LanguageSwitcher.d.vue.ts +11 -0
  47. package/dist/runtime/components/LanguageSwitcher.vue +57 -0
  48. package/dist/runtime/components/LanguageSwitcher.vue.d.ts +11 -0
  49. package/dist/runtime/components/Layout.d.vue.ts +10 -0
  50. package/dist/runtime/components/Layout.vue +38 -0
  51. package/dist/runtime/components/Layout.vue.d.ts +10 -0
  52. package/dist/runtime/components/Logo.d.vue.ts +9 -0
  53. package/dist/runtime/components/Logo.vue +18 -0
  54. package/dist/runtime/components/Logo.vue.d.ts +9 -0
  55. package/dist/runtime/components/MenuPage.d.vue.ts +11 -0
  56. package/dist/runtime/components/MenuPage.vue +93 -0
  57. package/dist/runtime/components/MenuPage.vue.d.ts +11 -0
  58. package/dist/runtime/components/Message.d.vue.ts +11 -0
  59. package/dist/runtime/components/Message.vue +33 -0
  60. package/dist/runtime/components/Message.vue.d.ts +11 -0
  61. package/dist/runtime/components/ModalLayout.d.vue.ts +18 -0
  62. package/dist/runtime/components/ModalLayout.vue +14 -0
  63. package/dist/runtime/components/ModalLayout.vue.d.ts +18 -0
  64. package/dist/runtime/components/Money.d.vue.ts +11 -0
  65. package/dist/runtime/components/Money.vue +27 -0
  66. package/dist/runtime/components/Money.vue.d.ts +11 -0
  67. package/dist/runtime/components/NavLink.d.vue.ts +11 -0
  68. package/dist/runtime/components/NavLink.vue +30 -0
  69. package/dist/runtime/components/NavLink.vue.d.ts +11 -0
  70. package/dist/runtime/components/None.d.vue.ts +11 -0
  71. package/dist/runtime/components/None.vue +25 -0
  72. package/dist/runtime/components/None.vue.d.ts +11 -0
  73. package/dist/runtime/components/Number.d.vue.ts +11 -0
  74. package/dist/runtime/components/Number.vue +27 -0
  75. package/dist/runtime/components/Number.vue.d.ts +11 -0
  76. package/dist/runtime/components/Page.d.vue.ts +3 -0
  77. package/dist/runtime/components/Page.vue +24 -0
  78. package/dist/runtime/components/Page.vue.d.ts +3 -0
  79. package/dist/runtime/components/PageTitle.d.vue.ts +22 -0
  80. package/dist/runtime/components/PageTitle.vue +171 -0
  81. package/dist/runtime/components/PageTitle.vue.d.ts +22 -0
  82. package/dist/runtime/components/Parameters.d.vue.ts +11 -0
  83. package/dist/runtime/components/Parameters.vue +60 -0
  84. package/dist/runtime/components/Parameters.vue.d.ts +11 -0
  85. package/dist/runtime/components/PersistentPopover.d.vue.ts +46 -0
  86. package/dist/runtime/components/PersistentPopover.vue +335 -0
  87. package/dist/runtime/components/PersistentPopover.vue.d.ts +46 -0
  88. package/dist/runtime/components/QueryParameters.d.vue.ts +11 -0
  89. package/dist/runtime/components/QueryParameters.vue +103 -0
  90. package/dist/runtime/components/QueryParameters.vue.d.ts +11 -0
  91. package/dist/runtime/components/Rate.d.vue.ts +11 -0
  92. package/dist/runtime/components/Rate.vue +22 -0
  93. package/dist/runtime/components/Rate.vue.d.ts +11 -0
  94. package/dist/runtime/components/ReportPage.d.vue.ts +11 -0
  95. package/dist/runtime/components/ReportPage.vue +147 -0
  96. package/dist/runtime/components/ReportPage.vue.d.ts +11 -0
  97. package/dist/runtime/components/Select.d.vue.ts +11 -0
  98. package/dist/runtime/components/Select.vue +120 -0
  99. package/dist/runtime/components/Select.vue.d.ts +11 -0
  100. package/dist/runtime/components/SelectButton.d.vue.ts +11 -0
  101. package/dist/runtime/components/SelectButton.vue +94 -0
  102. package/dist/runtime/components/SelectButton.vue.d.ts +11 -0
  103. package/dist/runtime/components/SideMenu.d.vue.ts +20 -0
  104. package/dist/runtime/components/SideMenu.vue +121 -0
  105. package/dist/runtime/components/SideMenu.vue.d.ts +20 -0
  106. package/dist/runtime/components/SideMenuItem.d.vue.ts +11 -0
  107. package/dist/runtime/components/SideMenuItem.vue +33 -0
  108. package/dist/runtime/components/SideMenuItem.vue.d.ts +11 -0
  109. package/dist/runtime/components/Text.d.vue.ts +11 -0
  110. package/dist/runtime/components/Text.vue +36 -0
  111. package/dist/runtime/components/Text.vue.d.ts +11 -0
  112. package/dist/runtime/composables/useBreakpoints.d.ts +1 -0
  113. package/dist/runtime/composables/useBreakpoints.js +48 -0
  114. package/dist/runtime/composables/useCache.d.ts +13 -0
  115. package/dist/runtime/composables/useCache.js +60 -0
  116. package/dist/runtime/composables/useComponentResolver.d.ts +3 -0
  117. package/dist/runtime/composables/useComponentResolver.js +13 -0
  118. package/dist/runtime/composables/useComposableResolver.d.ts +3 -0
  119. package/dist/runtime/composables/useComposableResolver.js +15 -0
  120. package/dist/runtime/composables/useConditional.d.ts +3 -0
  121. package/dist/runtime/composables/useConditional.js +15 -0
  122. package/dist/runtime/composables/useContext.d.ts +15 -0
  123. package/dist/runtime/composables/useContext.js +60 -0
  124. package/dist/runtime/composables/useDataFetcher.d.ts +15 -0
  125. package/dist/runtime/composables/useDataFetcher.js +203 -0
  126. package/dist/runtime/composables/useFormat.d.ts +16 -0
  127. package/dist/runtime/composables/useFormat.js +116 -0
  128. package/dist/runtime/composables/useLayouts.d.ts +3 -0
  129. package/dist/runtime/composables/useLayouts.js +21 -0
  130. package/dist/runtime/composables/useLocalization.d.ts +6 -0
  131. package/dist/runtime/composables/useLocalization.js +34 -0
  132. package/dist/runtime/composables/useLoginRedirect.d.ts +3 -0
  133. package/dist/runtime/composables/useLoginRedirect.js +15 -0
  134. package/dist/runtime/composables/useMutex.d.ts +3 -0
  135. package/dist/runtime/composables/useMutex.js +26 -0
  136. package/dist/runtime/composables/useNuxtError.d.ts +3 -0
  137. package/dist/runtime/composables/useNuxtError.js +13 -0
  138. package/dist/runtime/composables/useNuxtRoute.d.ts +3 -0
  139. package/dist/runtime/composables/useNuxtRoute.js +13 -0
  140. package/dist/runtime/composables/usePages.d.ts +5 -0
  141. package/dist/runtime/composables/usePages.js +27 -0
  142. package/dist/runtime/composables/useQuery.d.ts +3 -0
  143. package/dist/runtime/composables/useQuery.js +13 -0
  144. package/dist/runtime/composables/useToast.d.ts +1 -0
  145. package/dist/runtime/composables/useToast.js +5 -0
  146. package/dist/runtime/composables/useToken.d.ts +11 -0
  147. package/dist/runtime/composables/useToken.js +99 -0
  148. package/dist/runtime/composables/useUiStates.d.ts +9 -0
  149. package/dist/runtime/composables/useUiStates.js +9 -0
  150. package/dist/runtime/composables/useUnref.d.ts +3 -0
  151. package/dist/runtime/composables/useUnref.js +109 -0
  152. package/dist/runtime/plugins/auth.d.ts +2 -0
  153. package/dist/runtime/plugins/auth.js +81 -0
  154. package/dist/runtime/plugins/baked.d.ts +10 -0
  155. package/dist/runtime/plugins/baked.js +50 -0
  156. package/dist/runtime/plugins/cacheApplication.d.ts +2 -0
  157. package/dist/runtime/plugins/cacheApplication.js +27 -0
  158. package/dist/runtime/plugins/cacheUser.d.ts +2 -0
  159. package/dist/runtime/plugins/cacheUser.js +37 -0
  160. package/dist/runtime/plugins/errorHandling.d.ts +14 -0
  161. package/dist/runtime/plugins/errorHandling.js +96 -0
  162. package/dist/runtime/plugins/fetch.d.ts +2 -0
  163. package/dist/runtime/plugins/fetch.js +80 -0
  164. package/dist/runtime/plugins/localization.d.ts +2 -0
  165. package/dist/runtime/plugins/localization.js +18 -0
  166. package/dist/runtime/plugins/mutex.d.ts +7 -0
  167. package/dist/runtime/plugins/mutex.js +15 -0
  168. package/dist/runtime/plugins/primeVue.d.ts +2 -0
  169. package/dist/runtime/plugins/primeVue.js +75 -0
  170. package/dist/runtime/plugins/toast.d.ts +6 -0
  171. package/dist/runtime/plugins/toast.js +18 -0
  172. package/dist/runtime/plugins/trailingSlash.d.ts +2 -0
  173. package/dist/runtime/plugins/trailingSlash.js +18 -0
  174. package/dist/runtime/server/tsconfig.json +3 -0
  175. package/dist/types.d.mts +3 -0
  176. package/package.json +74 -0
@@ -0,0 +1,3 @@
1
+ export default function _default(): {
2
+ fetch: (name: any) => Promise<any>;
3
+ };
@@ -0,0 +1,21 @@
1
+ import { createError, useNuxtApp } from "#app";
2
+
3
+ export default function() {
4
+ const { $layouts } = useNuxtApp();
5
+
6
+ async function fetch(name) {
7
+ if(!$layouts[name]) {
8
+ throw createError({
9
+ statusCode: 404,
10
+ statusMessage: `'${name}' Layout Not Found`,
11
+ fatal: true
12
+ });
13
+ }
14
+
15
+ return await $layouts[name]();
16
+ }
17
+
18
+ return {
19
+ fetch
20
+ };
21
+ }
@@ -0,0 +1,6 @@
1
+ export default function _default({ group }?: {}): {
2
+ localize: (key: any, parameters?: {}) => any;
3
+ locale: any;
4
+ getLocales: () => any;
5
+ setLocale: (language: any) => void;
6
+ };
@@ -0,0 +1,34 @@
1
+ import { useNuxtApp, useRouter, useRuntimeConfig } from "#imports";
2
+
3
+ export default function({ group } = {}) {
4
+ const { $i18n: { locale, locales: i18nLocales, setLocaleCookie, t } } = useNuxtApp();
5
+ const { public: { localization } } = useRuntimeConfig();
6
+ const router = useRouter();
7
+
8
+ function getLocales() {
9
+ return localization.supportedLanguages.filter(l =>
10
+ i18nLocales.value.map(l => l.code).includes(l.code)
11
+ );
12
+ }
13
+
14
+ function setLocale(language) {
15
+ setLocaleCookie(language);
16
+ router.go();
17
+ }
18
+
19
+ function localize(key, parameters = {}) {
20
+ if(!key) { return; }
21
+
22
+ const keyWithGroup = group ? `${group}.${key}` : key;
23
+ const result = t(keyWithGroup, parameters);
24
+
25
+ return result === keyWithGroup ? key : result;
26
+ }
27
+
28
+ return {
29
+ localize,
30
+ locale,
31
+ getLocales,
32
+ setLocale
33
+ };
34
+ }
@@ -0,0 +1,3 @@
1
+ export default function _default(): {
2
+ compute: () => string;
3
+ };
@@ -0,0 +1,15 @@
1
+ import { useRoute, useRuntimeConfig } from "#app";
2
+
3
+ export default function() {
4
+ const { public: { auth } } = useRuntimeConfig();
5
+
6
+ function compute() {
7
+ const route = useRoute();
8
+
9
+ return `/${auth.loginPageRoute}?redirect=${route.fullPath}`;
10
+ }
11
+
12
+ return {
13
+ compute
14
+ };
15
+ }
@@ -0,0 +1,3 @@
1
+ export default function _default(): {
2
+ run: (callback: any) => Promise<void>;
3
+ };
@@ -0,0 +1,26 @@
1
+ import { E_CANCELED } from "async-mutex";
2
+
3
+ export default function() {
4
+ async function run(callback) {
5
+ const mutex = useNuxtApp().$mutex;
6
+
7
+ try {
8
+ await mutex.acquire();
9
+ await callback();
10
+ } catch (e) {
11
+ if(e !== E_CANCELED) {
12
+ mutex.cancel();
13
+ }
14
+
15
+ throw e;
16
+ } finally {
17
+ if(mutex.isLocked()) {
18
+ mutex.release();
19
+ }
20
+ }
21
+ }
22
+
23
+ return {
24
+ run
25
+ };
26
+ }
@@ -0,0 +1,3 @@
1
+ export default function _default(): {
2
+ compute: () => import("vue").Ref<import("#app").NuxtError<unknown> | undefined, import("#app").NuxtError<unknown> | undefined>;
3
+ };
@@ -0,0 +1,13 @@
1
+ import { useError } from "#app";
2
+
3
+ export default function() {
4
+ const error = useError();
5
+
6
+ function compute() {
7
+ return error;
8
+ }
9
+
10
+ return {
11
+ compute
12
+ };
13
+ }
@@ -0,0 +1,3 @@
1
+ export default function _default(): {
2
+ compute: () => import("vue-router").RouteLocationNormalizedLoadedGeneric;
3
+ };
@@ -0,0 +1,13 @@
1
+ import { useRoute } from "#app";
2
+
3
+ export default function() {
4
+ const route = useRoute();
5
+
6
+ function compute() {
7
+ return route;
8
+ }
9
+
10
+ return {
11
+ compute
12
+ };
13
+ }
@@ -0,0 +1,5 @@
1
+ export default function _default(): {
2
+ fetch: (name: any, { throwNotFound }?: {
3
+ throwNotFound: boolean;
4
+ }) => Promise<any>;
5
+ };
@@ -0,0 +1,27 @@
1
+ import { createError, useNuxtApp } from "#app";
2
+
3
+ export default function() {
4
+ const { $pages } = useNuxtApp();
5
+
6
+ async function fetch(name,
7
+ { throwNotFound } = { throwNotFound: true }
8
+ ) {
9
+ if(!$pages[name]) {
10
+ if(throwNotFound) {
11
+ throw createError({
12
+ statusCode: 404,
13
+ statusMessage: `'${name}' Page Not Found`,
14
+ fatal: true
15
+ });
16
+ } else {
17
+ return null;
18
+ }
19
+ }
20
+
21
+ return await $pages[name]();
22
+ }
23
+
24
+ return {
25
+ fetch
26
+ };
27
+ }
@@ -0,0 +1,3 @@
1
+ export default function _default(): {
2
+ compute: () => import("vue-router").LocationQuery;
3
+ };
@@ -0,0 +1,13 @@
1
+ import { useRoute } from "#app";
2
+
3
+ export default function() {
4
+ const route = useRoute();
5
+
6
+ function compute() {
7
+ return route.query;
8
+ }
9
+
10
+ return {
11
+ compute
12
+ };
13
+ }
@@ -0,0 +1 @@
1
+ export default function _default(): unknown;
@@ -0,0 +1,5 @@
1
+ import { useNuxtApp } from "#app";
2
+
3
+ export default function() {
4
+ return useNuxtApp().$toast;
5
+ }
@@ -0,0 +1,11 @@
1
+ export default function _default(): {
2
+ current: (shouldRefresh?: boolean) => Promise<{
3
+ access: any;
4
+ refresh: any;
5
+ displayName: any;
6
+ accessIsExpired: () => boolean;
7
+ refreshIsExpired: () => boolean;
8
+ } | null>;
9
+ setCurrent: (value: any, dispatch?: boolean) => void;
10
+ onChanged: (callback: any) => void;
11
+ };
@@ -0,0 +1,99 @@
1
+ import { useRuntimeConfig } from "#app";
2
+ import { createError, useMutex } from "#imports";
3
+
4
+ export default function() {
5
+ const mutex = useMutex();
6
+ const { public: { auth, composables } } = useRuntimeConfig();
7
+
8
+ async function current(
9
+ shouldRefresh = true
10
+ ) {
11
+ const tokenString = localStorage.getItem("token");
12
+ if(!tokenString) { return null; }
13
+
14
+ const result = Token(tokenString);
15
+
16
+ if(!result.access) { return null; }
17
+ if(!result.refresh) { return null; }
18
+
19
+ if(result.refreshIsExpired()) { return null; }
20
+ if(result.accessIsExpired() && shouldRefresh) {
21
+ await refresh();
22
+
23
+ return current(false);
24
+ }
25
+
26
+ return result;
27
+ }
28
+
29
+ async function refresh() {
30
+ await mutex.run(async() => {
31
+ const token = await current(false);
32
+ if(!token?.accessIsExpired()) { return; }
33
+
34
+ const result = await $fetch(auth.refreshApiRoute,
35
+ {
36
+ baseURL: composables.useDataFetcher.baseURL,
37
+ method: "POST",
38
+ headers: { "Authorization": `Bearer ${token?.refresh}` }
39
+ }
40
+ );
41
+
42
+ setCurrent(result, false);
43
+ });
44
+ }
45
+
46
+ function setCurrent(value,
47
+ dispatch = true
48
+ ) {
49
+ if(!value) {
50
+ localStorage.removeItem("token");
51
+ } else {
52
+ localStorage.setItem("token", JSON.stringify(value));
53
+ }
54
+
55
+ if(dispatch) {
56
+ globalThis.dispatchEvent(new CustomEvent("token-changed"));
57
+ }
58
+ }
59
+
60
+ function onChanged(callback) {
61
+ globalThis.addEventListener("token-changed", callback);
62
+ }
63
+
64
+ return {
65
+ current,
66
+ setCurrent,
67
+ onChanged
68
+ };
69
+ };
70
+
71
+ function Token(tokenString) {
72
+ const { access, refresh, displayName } = JSON.parse(tokenString);
73
+
74
+ function accessIsExpired() {
75
+ return isExpired(access);
76
+ }
77
+
78
+ function refreshIsExpired() {
79
+ return isExpired(refresh);
80
+ }
81
+
82
+ function isExpired(token) {
83
+ try {
84
+ const claims = JSON.parse(atob(token.split(".")[1]));
85
+
86
+ return parseInt(claims.exp) * 1000 < Date.now();
87
+ } catch {
88
+ throw createError({ statusCode: 401 });
89
+ }
90
+ }
91
+
92
+ return {
93
+ access,
94
+ refresh,
95
+ displayName,
96
+ accessIsExpired,
97
+ refreshIsExpired
98
+ };
99
+ }
@@ -0,0 +1,9 @@
1
+ export default function _default(): import("vue").Ref<{
2
+ panelStates: {};
3
+ selectStates: {};
4
+ selectButtonStates: {};
5
+ }, {
6
+ panelStates: {};
7
+ selectStates: {};
8
+ selectButtonStates: {};
9
+ }>;
@@ -0,0 +1,9 @@
1
+ import { useState } from "#imports";
2
+
3
+ export default function() {
4
+ return useState("uiStates", () => ({
5
+ panelStates: { },
6
+ selectStates: { },
7
+ selectButtonStates: { }
8
+ }));
9
+ }
@@ -0,0 +1,3 @@
1
+ export default function _default(): {
2
+ deepUnref: (val: Mixed) => Mixed;
3
+ };
@@ -0,0 +1,109 @@
1
+ /*
2
+ MIT License
3
+
4
+ Copyright (c) 2021 Dan Hulton
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+
24
+ */
25
+
26
+ import { isRef, unref } from "vue";
27
+
28
+ const isObject = val => val !== null && typeof val === "object";
29
+ const isArray = Array.isArray;
30
+
31
+ /**
32
+ * Deeply unref a value, recursing into objects and arrays.
33
+ *
34
+ * @param {Mixed} val - The value to deeply unref.
35
+ *
36
+ * @return {Mixed}
37
+ */
38
+ const deepUnref = val => {
39
+ const checkedVal = isRef(val) ? unref(val) : val;
40
+
41
+ if(! isObject(checkedVal)) {
42
+ return checkedVal;
43
+ }
44
+
45
+ if(isArray(checkedVal)) {
46
+ return unrefArray(checkedVal);
47
+ }
48
+
49
+ return unrefObject(checkedVal);
50
+ };
51
+
52
+ /**
53
+ * Unref a value, recursing into it if it's an object.
54
+ *
55
+ * @param {Mixed} val - The value to unref.
56
+ *
57
+ * @return {Mixed}
58
+ */
59
+ const smartUnref = val => {
60
+ // Non-ref object? Go deeper!
61
+ if(val !== null && ! isRef(val) && typeof val === "object") {
62
+ return deepUnref(val);
63
+ }
64
+
65
+ return unref(val);
66
+ };
67
+
68
+ /**
69
+ * Unref an array, recursively.
70
+ *
71
+ * @param {Array} arr - The array to unref.
72
+ *
73
+ * @return {Array}
74
+ */
75
+ const unrefArray = arr => {
76
+ const unreffed = [];
77
+
78
+ arr.forEach(val => {
79
+ unreffed.push(smartUnref(val));
80
+ });
81
+
82
+ return unreffed;
83
+ };
84
+
85
+ /**
86
+ * Unref an object, recursively.
87
+ *
88
+ * @param {Object} obj - The object to unref.
89
+ *
90
+ * @return {Object}
91
+ */
92
+ const unrefObject = obj => {
93
+ const unreffed = {};
94
+
95
+ // Object? un-ref it!
96
+ Object.keys(obj).forEach(key => {
97
+ unreffed[key] = smartUnref(obj[key]);
98
+ });
99
+
100
+ return unreffed;
101
+ };
102
+
103
+ // --- END OF `vue-deepunref` --- //
104
+
105
+ export default function() {
106
+ return {
107
+ deepUnref
108
+ };
109
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;
@@ -0,0 +1,81 @@
1
+ import { defineNuxtPlugin, useNuxtApp, useRoute, useRuntimeConfig } from "#app";
2
+ import { useToken } from "#imports";
3
+
4
+ export default defineNuxtPlugin({
5
+ name: "auth",
6
+ enforce: "pre",
7
+ setup(nuxtApp) {
8
+ const { public: { auth } } = useRuntimeConfig();
9
+ const token = useToken();
10
+ const { $fetchInterceptors, $router } = nuxtApp;
11
+
12
+ $fetchInterceptors.register(
13
+ "auth",
14
+ async({ request, options }, next) => {
15
+ // filters out any api call that already has an authorization header,
16
+ // such as refresh token api call
17
+ if(options.headers["Authorization"] || options.headers["authorization"]) {
18
+ return await next();
19
+ }
20
+
21
+ // try get current token
22
+ let result = await token.current(false);
23
+ if(!result || result.accessIsExpired()) {
24
+ // if api is anonymous no need to have a token, will continue
25
+ // anonymously
26
+ if(auth.anonymousApiRoutes.some(route => request?.includes(route))) { return await next(); }
27
+
28
+ // force get an access token
29
+ result = await token.current(true);
30
+ }
31
+
32
+ options.headers["Authorization"] = `Bearer ${result?.access}`;
33
+
34
+ return await next();
35
+ },
36
+ // runs before other interceptors, even early ones like cache
37
+ // this is to prevent any unintended result when user is not authorized while it should be
38
+ //
39
+ // -10 is to leave a room just in case it is needed
40
+ Number.MIN_SAFE_INTEGER - 10
41
+ );
42
+
43
+ $router.beforeEach(async to => {
44
+ const token = useToken();
45
+
46
+ for(const route of auth.anonymousPageRoutes) {
47
+ const pattern = new RegExp(route);
48
+ if(to.path.match(pattern)?.length > 0) {
49
+ return;
50
+ }
51
+ }
52
+
53
+ const toLogin = to.path.includes(auth.loginPage);
54
+ const current = await token.current(!toLogin);
55
+
56
+ if(current && toLogin) {
57
+ await $router.replace(to.query.redirect || "/");
58
+ } else if(!current && !toLogin) {
59
+ await $router.replace(`/${auth.loginPageRoute}?redirect=${to.fullPath}`);
60
+ }
61
+ });
62
+ },
63
+ hooks: {
64
+ "app:mounted"() {
65
+ const { $router } = useNuxtApp();
66
+ const { public: { auth } } = useRuntimeConfig();
67
+ const route = useRoute();
68
+ const token = useToken();
69
+
70
+ token.onChanged(() => {
71
+ token.current().then(current => {
72
+ if(current) {
73
+ $router.push(route.query.redirect || "/");
74
+ } else {
75
+ $router.push(`/${auth.loginPageRoute}`);
76
+ }
77
+ });
78
+ });
79
+ }
80
+ }
81
+ });
@@ -0,0 +1,10 @@
1
+ declare const _default: import("#app").Plugin<{
2
+ composables: {};
3
+ pages: {};
4
+ layouts: {};
5
+ }> & import("#app").ObjectPlugin<{
6
+ composables: {};
7
+ pages: {};
8
+ layouts: {};
9
+ }>;
10
+ export default _default;
@@ -0,0 +1,50 @@
1
+ import { defineNuxtPlugin } from "#app";
2
+
3
+ export default defineNuxtPlugin({
4
+ name: "baked",
5
+ setup() {
6
+ const bakedComposables = import.meta.glob("../composables/*");
7
+ const projectComposables = import.meta.glob("@/composables/*");
8
+
9
+ const pages = import.meta.glob("@@/.baked/**/*.page.json");
10
+ const layouts = import.meta.glob("@@/.baked/**/*.layout.json");
11
+
12
+ return {
13
+ provide: {
14
+ composables: merge({
15
+ bakedImports: bakedComposables,
16
+ projectImports: projectComposables,
17
+ trimStart: "composables/",
18
+ trimEnd: "."
19
+ }),
20
+ pages: jsonFiles(pages, ".baked/", ".page.json"),
21
+ layouts: jsonFiles(layouts, ".baked/", ".layout.json")
22
+ }
23
+ };
24
+ }
25
+ });
26
+
27
+ function merge({ bakedImports, projectImports, trimStart, trimEnd }) {
28
+ return {
29
+ ...Object.keys(bakedImports).reduce((result, path) => {
30
+ result[path.slice(path.indexOf(trimStart) + trimStart.length, path.lastIndexOf(trimEnd))] = bakedImports[path];
31
+
32
+ return result;
33
+ }, { }),
34
+ ...Object.keys(projectImports).reduce((result, path) => {
35
+ result[path.slice(path.indexOf(trimStart) + trimStart.length, path.lastIndexOf(trimEnd))] = projectImports[path];
36
+
37
+ return result;
38
+ }, { })
39
+ };
40
+ }
41
+
42
+ function jsonFiles(imports, trimStart, trimEnd) {
43
+ return {
44
+ ...Object.keys(imports).reduce((result, path) => {
45
+ result[path.slice(path.indexOf(trimStart) + trimStart.length, path.lastIndexOf(trimEnd))] = imports[path];
46
+
47
+ return result;
48
+ }, { })
49
+ };
50
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;
@@ -0,0 +1,27 @@
1
+ import { defineNuxtPlugin, useRuntimeConfig } from "#app";
2
+ import { useCache } from "#imports";
3
+
4
+ export default defineNuxtPlugin({
5
+ name: "cache-application",
6
+ enforce: "pre",
7
+ setup(nuxtApp) {
8
+ const { public: { cacheApplication } } = useRuntimeConfig();
9
+ const { expirationInMinutes } = cacheApplication;
10
+ const cache = useCache("cache:application", { expirationInMinutes });
11
+ const { $fetchInterceptors } = nuxtApp;
12
+
13
+ $fetchInterceptors.register(
14
+ "cache-application",
15
+ async({ request, options }, next) => {
16
+ if(options.attributes["client-cache"] !== "application") {
17
+ return await next();
18
+ }
19
+
20
+ const key = cache.buildKey({ path: request, query: options.query });
21
+ return await cache.getOrCreate({ key, create: next });
22
+ },
23
+ // should run before other interceptors
24
+ -10
25
+ );
26
+ }
27
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;