@open-xamu-co/firebase-nuxt 1.0.0 → 1.1.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.
- package/CHANGELOG.md +15 -0
- package/README.md +0 -14
- package/dist/module.d.mts +50 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +137 -0
- package/dist/runtime/client/types/entities/base.d.ts +29 -0
- package/dist/runtime/client/types/entities/base.js +0 -0
- package/dist/runtime/client/types/entities/instance.d.ts +42 -0
- package/dist/runtime/client/types/entities/instance.js +0 -0
- package/dist/runtime/client/types/entities/logs.d.ts +9 -0
- package/dist/runtime/client/types/entities/logs.js +0 -0
- package/dist/runtime/client/types/entities/user.d.ts +27 -0
- package/dist/runtime/client/types/entities/user.js +0 -0
- package/dist/runtime/client/types/firestore.d.ts +55 -0
- package/dist/runtime/client/types/firestore.js +0 -0
- package/dist/runtime/client/types/index.d.ts +5 -0
- package/dist/runtime/client/types/index.js +5 -0
- package/dist/runtime/client/utils/locale.d.ts +185 -0
- package/dist/runtime/client/utils/locale.js +63 -0
- package/dist/runtime/client/utils/logger.d.ts +14 -0
- package/dist/runtime/client/utils/logger.js +65 -0
- package/dist/runtime/client/utils/resolver.d.ts +14 -0
- package/dist/runtime/client/utils/resolver.js +88 -0
- package/dist/runtime/components/ValueCellphone.d.vue.ts +24 -0
- package/dist/runtime/components/ValueCellphone.vue +21 -0
- package/dist/runtime/components/ValueCellphone.vue.d.ts +24 -0
- package/dist/runtime/components/ValueID.d.vue.ts +18 -0
- package/dist/runtime/components/ValueID.vue +14 -0
- package/dist/runtime/components/ValueID.vue.d.ts +18 -0
- package/dist/runtime/components/ValueIP.d.vue.ts +18 -0
- package/dist/runtime/components/ValueIP.vue +28 -0
- package/dist/runtime/components/ValueIP.vue.d.ts +18 -0
- package/dist/runtime/components/ValueLocation.d.vue.ts +21 -0
- package/dist/runtime/components/ValueLocation.vue +20 -0
- package/dist/runtime/components/ValueLocation.vue.d.ts +21 -0
- package/dist/runtime/components/ValuePrice.d.vue.ts +11 -0
- package/dist/runtime/components/ValuePrice.vue +12 -0
- package/dist/runtime/components/ValuePrice.vue.d.ts +11 -0
- package/dist/runtime/composables/firestore/auth.d.ts +4 -0
- package/dist/runtime/composables/firestore/auth.js +46 -0
- package/dist/runtime/composables/firestore/index.d.ts +2 -0
- package/dist/runtime/composables/firestore/index.js +2 -0
- package/dist/runtime/composables/firestore/write.d.ts +21 -0
- package/dist/runtime/composables/firestore/write.js +279 -0
- package/dist/runtime/composables/index.d.ts +4 -0
- package/dist/runtime/composables/index.js +4 -0
- package/dist/runtime/composables/store/app.d.ts +82 -0
- package/dist/runtime/composables/store/app.js +90 -0
- package/dist/runtime/composables/store/instance.d.ts +57 -0
- package/dist/runtime/composables/store/instance.js +94 -0
- package/dist/runtime/composables/store/session.d.ts +41 -0
- package/dist/runtime/composables/store/session.js +89 -0
- package/dist/runtime/composables/useAppLogger.d.ts +2 -0
- package/dist/runtime/composables/useAppLogger.js +8 -0
- package/dist/runtime/composables/useFilesUpload.d.ts +19 -0
- package/dist/runtime/composables/useFilesUpload.js +110 -0
- package/dist/runtime/composables/usePrice.d.ts +9 -0
- package/dist/runtime/composables/usePrice.js +6 -0
- package/dist/runtime/composables/useQuery.d.ts +12 -0
- package/dist/runtime/composables/useQuery.js +33 -0
- package/dist/runtime/composables/utils.d.ts +14 -0
- package/dist/runtime/composables/utils.js +65 -0
- package/dist/runtime/functions/types/entities/base.d.ts +56 -0
- package/dist/runtime/functions/types/entities/base.js +0 -0
- package/dist/runtime/functions/types/entities/instance.d.ts +73 -0
- package/dist/runtime/functions/types/entities/instance.js +0 -0
- package/dist/runtime/functions/types/entities/logs.d.ts +15 -0
- package/dist/runtime/functions/types/entities/logs.js +0 -0
- package/dist/runtime/functions/types/entities/user.d.ts +13 -0
- package/dist/runtime/functions/types/entities/user.js +0 -0
- package/dist/runtime/functions/types/index.d.ts +4 -0
- package/dist/runtime/functions/types/index.js +4 -0
- package/dist/runtime/functions/utils/encrypt.d.ts +24 -0
- package/dist/runtime/functions/utils/encrypt.js +17 -0
- package/dist/runtime/functions/utils/enums.d.ts +40 -0
- package/dist/runtime/functions/utils/enums.js +24 -0
- package/dist/runtime/functions/utils/event.d.ts +71 -0
- package/dist/runtime/functions/utils/event.js +91 -0
- package/dist/runtime/functions/utils/firebase.d.ts +7 -0
- package/dist/runtime/functions/utils/firebase.js +21 -0
- package/dist/runtime/functions/utils/logger.d.ts +3 -0
- package/dist/runtime/functions/utils/logger.js +17 -0
- package/dist/runtime/functions/utils/logs.d.ts +10 -0
- package/dist/runtime/functions/utils/logs.js +47 -0
- package/dist/runtime/functions/utils/price.d.ts +12 -0
- package/dist/runtime/functions/utils/price.js +26 -0
- package/dist/runtime/functions/utils/queue.d.ts +4 -0
- package/dist/runtime/functions/utils/queue.js +11 -0
- package/dist/runtime/functions/utils/search.d.ts +15 -0
- package/dist/runtime/functions/utils/search.js +38 -0
- package/dist/runtime/functions/utils/slugs.d.ts +2 -0
- package/dist/runtime/functions/utils/slugs.js +16 -0
- package/dist/runtime/plugins/firebase-setup.d.ts +26 -0
- package/dist/runtime/plugins/firebase-setup.js +35 -0
- package/dist/runtime/plugins/loaded.client.d.ts +2 -0
- package/dist/runtime/plugins/loaded.client.js +44 -0
- package/dist/runtime/plugins/scrollBehavior.client.d.ts +2 -0
- package/dist/runtime/plugins/scrollBehavior.client.js +20 -0
- package/dist/runtime/providers/firebase.d.ts +2 -0
- package/dist/runtime/providers/firebase.js +7 -0
- package/dist/runtime/public/js/file-upload.d.ts +1 -0
- package/dist/runtime/public/js/file-upload.js +67 -0
- package/dist/runtime/public/sample-loading.png +0 -0
- package/dist/runtime/public/sample-missing.png +0 -0
- package/dist/runtime/public/sample.png +0 -0
- package/dist/runtime/server/api/all-collection-document.get.d.ts +7 -0
- package/dist/runtime/server/api/all-collection-document.get.js +56 -0
- package/dist/runtime/server/api/all-collection.get.d.ts +8 -0
- package/dist/runtime/server/api/all-collection.get.js +67 -0
- package/dist/runtime/server/api/media.get.d.ts +8 -0
- package/dist/runtime/server/api/media.get.js +114 -0
- package/dist/runtime/server/middleware/0.hotlinking.d.ts +5 -0
- package/dist/runtime/server/middleware/0.hotlinking.js +28 -0
- package/dist/runtime/server/middleware/1.context.d.ts +5 -0
- package/dist/runtime/server/middleware/1.context.js +108 -0
- package/dist/runtime/server/types/index.d.ts +34 -0
- package/dist/runtime/server/types/index.js +0 -0
- package/dist/runtime/server/utils/auth.d.ts +10 -0
- package/dist/runtime/server/utils/auth.js +31 -0
- package/dist/runtime/server/utils/cache.d.ts +21 -0
- package/dist/runtime/server/utils/cache.js +20 -0
- package/dist/runtime/server/utils/environment.d.ts +45 -0
- package/dist/runtime/server/utils/environment.js +50 -0
- package/dist/runtime/server/utils/firebase.d.ts +9 -0
- package/dist/runtime/server/utils/firebase.js +13 -0
- package/dist/runtime/server/utils/firestore.d.ts +27 -0
- package/dist/runtime/server/utils/firestore.js +137 -0
- package/dist/runtime/server/utils/guards.d.ts +15 -0
- package/dist/runtime/server/utils/guards.js +23 -0
- package/dist/runtime/server/utils/instance.d.ts +21 -0
- package/dist/runtime/server/utils/instance.js +68 -0
- package/dist/types.d.mts +7 -0
- package/package.json +17 -17
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addDoc,
|
|
3
|
+
collection,
|
|
4
|
+
doc,
|
|
5
|
+
getDoc,
|
|
6
|
+
setDoc,
|
|
7
|
+
updateDoc,
|
|
8
|
+
onSnapshot,
|
|
9
|
+
arrayUnion
|
|
10
|
+
} from "firebase/firestore";
|
|
11
|
+
import set from "lodash-es/set";
|
|
12
|
+
import { getDocumentId } from "../../client/utils/resolver.js";
|
|
13
|
+
import { TimedPromise } from "../../server/utils/guards.js";
|
|
14
|
+
import { useAppLogger, useInstanceStore, useNuxtApp, useSessionStore } from "#imports";
|
|
15
|
+
export async function useDocumentCreate(collectionPath, partialRef, createdCallback, { omitLoggings, ...config } = { omitLoggings: false, level: 0 }) {
|
|
16
|
+
const { $clientFirestore, $resolveClientRefs } = useNuxtApp();
|
|
17
|
+
if (!collectionPath || !$clientFirestore) throw new Error("Collection path is required");
|
|
18
|
+
const SESSION = useSessionStore();
|
|
19
|
+
const INSTANCE = useInstanceStore();
|
|
20
|
+
const collRef = collection($clientFirestore, collectionPath);
|
|
21
|
+
if (collectionPath === "users") {
|
|
22
|
+
const instanceRef = doc($clientFirestore, INSTANCE.id);
|
|
23
|
+
partialRef.instancesRefs = arrayUnion(instanceRef);
|
|
24
|
+
}
|
|
25
|
+
if (SESSION.token) {
|
|
26
|
+
const memberId = getDocumentId(SESSION.path);
|
|
27
|
+
const memberPath = `${INSTANCE.id}/members/${memberId}`;
|
|
28
|
+
const createdByRef = memberId ? doc($clientFirestore, memberPath) : void 0;
|
|
29
|
+
partialRef.createdByRef = partialRef.updatedByRef = createdByRef;
|
|
30
|
+
}
|
|
31
|
+
delete partialRef.createdAt;
|
|
32
|
+
delete partialRef.updatedAt;
|
|
33
|
+
let createdRef;
|
|
34
|
+
try {
|
|
35
|
+
if (partialRef.id) {
|
|
36
|
+
createdRef = doc(collRef, getDocumentId(partialRef.id));
|
|
37
|
+
await setDoc(createdRef, partialRef, { merge: true });
|
|
38
|
+
} else createdRef = await addDoc(collRef, partialRef);
|
|
39
|
+
Promise.resolve(createdCallback?.(createdRef)).catch((err) => {
|
|
40
|
+
useAppLogger("composables:useDocumentCreate:callback", err);
|
|
41
|
+
});
|
|
42
|
+
const createdAt = /* @__PURE__ */ new Date();
|
|
43
|
+
const data = await $resolveClientRefs?.(
|
|
44
|
+
{
|
|
45
|
+
data: () => ({
|
|
46
|
+
...partialRef,
|
|
47
|
+
id: createdRef?.path,
|
|
48
|
+
createdAt,
|
|
49
|
+
updatedAt: createdAt
|
|
50
|
+
}),
|
|
51
|
+
exists: true,
|
|
52
|
+
ref: createdRef
|
|
53
|
+
},
|
|
54
|
+
config
|
|
55
|
+
);
|
|
56
|
+
return [
|
|
57
|
+
[
|
|
58
|
+
data || false,
|
|
59
|
+
// Wait for cloud function snapshot
|
|
60
|
+
TimedPromise(
|
|
61
|
+
(resolve, reject) => {
|
|
62
|
+
if (!createdRef) return reject("No document created");
|
|
63
|
+
const unsub = onSnapshot(
|
|
64
|
+
createdRef,
|
|
65
|
+
async (snapshot) => {
|
|
66
|
+
if (!snapshot.exists()) {
|
|
67
|
+
unsub();
|
|
68
|
+
reject("Document was deleted after creation");
|
|
69
|
+
} else if (!snapshot.data()?.createdAt) return;
|
|
70
|
+
const finalData = await $resolveClientRefs?.(
|
|
71
|
+
snapshot,
|
|
72
|
+
config
|
|
73
|
+
);
|
|
74
|
+
unsub();
|
|
75
|
+
resolve(finalData || false);
|
|
76
|
+
},
|
|
77
|
+
reject
|
|
78
|
+
);
|
|
79
|
+
},
|
|
80
|
+
{ fallback: false }
|
|
81
|
+
)
|
|
82
|
+
]
|
|
83
|
+
];
|
|
84
|
+
} catch (err) {
|
|
85
|
+
if (!omitLoggings) {
|
|
86
|
+
console.error("Error creating document", { createdRef, partialRef }, err);
|
|
87
|
+
useAppLogger("composables:useDocumentCreate", err);
|
|
88
|
+
}
|
|
89
|
+
return [false];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export async function useDocumentUpdate(node, middleRef = {}, { omitLoggings, ...config } = { omitLoggings: false, level: 0 }) {
|
|
93
|
+
const { $clientFirestore, $resolveClientRefs } = useNuxtApp();
|
|
94
|
+
if (!node.id || !$clientFirestore) throw new Error("Document id is required");
|
|
95
|
+
const SESSION = useSessionStore();
|
|
96
|
+
const INSTANCE = useInstanceStore();
|
|
97
|
+
const docRef = doc($clientFirestore, node.id || "");
|
|
98
|
+
const partialRef = middleRef;
|
|
99
|
+
const lastUpdatedAt = node.updatedAt ? new Date(node.updatedAt).getTime() : 0;
|
|
100
|
+
if (SESSION.token) {
|
|
101
|
+
const memberId = getDocumentId(SESSION.path);
|
|
102
|
+
const memberPath = `${INSTANCE.id}/members/${memberId}`;
|
|
103
|
+
const updatedByRef = memberId ? doc($clientFirestore, memberPath) : void 0;
|
|
104
|
+
partialRef.updatedByRef = updatedByRef;
|
|
105
|
+
}
|
|
106
|
+
delete partialRef.createdAt;
|
|
107
|
+
delete partialRef.updatedAt;
|
|
108
|
+
try {
|
|
109
|
+
await updateDoc(docRef, partialRef);
|
|
110
|
+
const updatedAt = /* @__PURE__ */ new Date();
|
|
111
|
+
const data = await $resolveClientRefs?.(
|
|
112
|
+
{
|
|
113
|
+
data: () => {
|
|
114
|
+
const newData = { ...partialRef, id: docRef?.path, updatedAt };
|
|
115
|
+
for (const k in newData) {
|
|
116
|
+
if (!Object.hasOwn(newData, k) || !k.includes(".")) continue;
|
|
117
|
+
set(newData, k, newData[k]);
|
|
118
|
+
delete newData[k];
|
|
119
|
+
}
|
|
120
|
+
return newData;
|
|
121
|
+
},
|
|
122
|
+
exists: true,
|
|
123
|
+
ref: docRef
|
|
124
|
+
},
|
|
125
|
+
config
|
|
126
|
+
);
|
|
127
|
+
return [
|
|
128
|
+
[
|
|
129
|
+
data || false,
|
|
130
|
+
// Wait for cloud function snapshot
|
|
131
|
+
TimedPromise(
|
|
132
|
+
(resolve, reject) => {
|
|
133
|
+
const unsub = onSnapshot(
|
|
134
|
+
docRef,
|
|
135
|
+
async (snapshot) => {
|
|
136
|
+
const updatedAt2 = snapshot.data()?.updatedAt?.toMillis() ?? 0;
|
|
137
|
+
if (lastUpdatedAt >= updatedAt2) return;
|
|
138
|
+
const finalData = await $resolveClientRefs?.(
|
|
139
|
+
snapshot,
|
|
140
|
+
config
|
|
141
|
+
);
|
|
142
|
+
unsub();
|
|
143
|
+
resolve(finalData || false);
|
|
144
|
+
},
|
|
145
|
+
reject
|
|
146
|
+
);
|
|
147
|
+
},
|
|
148
|
+
{ fallback: false }
|
|
149
|
+
)
|
|
150
|
+
]
|
|
151
|
+
];
|
|
152
|
+
} catch (err) {
|
|
153
|
+
if (!omitLoggings) {
|
|
154
|
+
console.error("Error updating document", { docRef, partialRef }, err);
|
|
155
|
+
useAppLogger("composables:useDocumentUpdate", err);
|
|
156
|
+
}
|
|
157
|
+
return [false];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export async function useDocumentClone(node, middleRef = {}, { omitLoggings, ...config } = { omitLoggings: false, level: 0 }) {
|
|
161
|
+
const { $clientFirestore, $resolveClientRefs } = useNuxtApp();
|
|
162
|
+
if (!node.id || !$clientFirestore) throw new Error("Document id is required");
|
|
163
|
+
const SESSION = useSessionStore();
|
|
164
|
+
const INSTANCE = useInstanceStore();
|
|
165
|
+
const docRef = doc($clientFirestore, node.id);
|
|
166
|
+
const partialRef = middleRef;
|
|
167
|
+
const source = (await getDoc(docRef)).data();
|
|
168
|
+
if (!source) return [false];
|
|
169
|
+
if (SESSION.token) {
|
|
170
|
+
const memberId = getDocumentId(SESSION.path);
|
|
171
|
+
const memberPath = `${INSTANCE.id}/members/${memberId}`;
|
|
172
|
+
const clonedByRef = memberId ? doc($clientFirestore, memberPath) : void 0;
|
|
173
|
+
partialRef.createdByRef = partialRef.updatedByRef = clonedByRef;
|
|
174
|
+
}
|
|
175
|
+
delete source.id;
|
|
176
|
+
delete source.createdAt;
|
|
177
|
+
delete source.updatedAt;
|
|
178
|
+
delete source.lock;
|
|
179
|
+
delete partialRef.createdAt;
|
|
180
|
+
delete partialRef.updatedAt;
|
|
181
|
+
const collRef = docRef.parent;
|
|
182
|
+
let clonedDoc;
|
|
183
|
+
try {
|
|
184
|
+
clonedDoc = await addDoc(collRef, {
|
|
185
|
+
...source,
|
|
186
|
+
...partialRef
|
|
187
|
+
});
|
|
188
|
+
const createdAt = /* @__PURE__ */ new Date();
|
|
189
|
+
const data = await $resolveClientRefs?.(
|
|
190
|
+
{
|
|
191
|
+
data: () => ({
|
|
192
|
+
...partialRef,
|
|
193
|
+
id: clonedDoc?.path,
|
|
194
|
+
createdAt,
|
|
195
|
+
updatedAt: createdAt
|
|
196
|
+
}),
|
|
197
|
+
exists: true,
|
|
198
|
+
ref: clonedDoc
|
|
199
|
+
},
|
|
200
|
+
config
|
|
201
|
+
);
|
|
202
|
+
return [
|
|
203
|
+
[
|
|
204
|
+
data || false,
|
|
205
|
+
// Wait for cloud function snapshot
|
|
206
|
+
TimedPromise(
|
|
207
|
+
(resolve, reject) => {
|
|
208
|
+
if (!clonedDoc) return reject("No document cloned");
|
|
209
|
+
const unsub = onSnapshot(
|
|
210
|
+
clonedDoc,
|
|
211
|
+
async (snapshot) => {
|
|
212
|
+
if (!snapshot.data()?.createdAt) return;
|
|
213
|
+
const finalData = await $resolveClientRefs?.(
|
|
214
|
+
snapshot,
|
|
215
|
+
config
|
|
216
|
+
);
|
|
217
|
+
unsub();
|
|
218
|
+
resolve(finalData || false);
|
|
219
|
+
},
|
|
220
|
+
reject
|
|
221
|
+
);
|
|
222
|
+
},
|
|
223
|
+
{ fallback: false }
|
|
224
|
+
)
|
|
225
|
+
]
|
|
226
|
+
];
|
|
227
|
+
} catch (err) {
|
|
228
|
+
if (!omitLoggings) {
|
|
229
|
+
console.error("Error cloning document", { clonedDoc, partialRef }, err);
|
|
230
|
+
useAppLogger("composables:useDocumentClone", err);
|
|
231
|
+
}
|
|
232
|
+
return [false];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
export async function useDocumentDelete(node, { omitLoggings } = { omitLoggings: false, level: 0 }) {
|
|
236
|
+
const { $clientFirestore } = useNuxtApp();
|
|
237
|
+
if (!node.id || !$clientFirestore) throw new Error("Document id is required");
|
|
238
|
+
const SESSION = useSessionStore();
|
|
239
|
+
const INSTANCE = useInstanceStore();
|
|
240
|
+
const docRef = doc($clientFirestore, node.id);
|
|
241
|
+
const memberId = getDocumentId(SESSION.path);
|
|
242
|
+
const memberPath = `${INSTANCE.id}/members/${memberId}`;
|
|
243
|
+
const deletedByRef = memberId ? doc($clientFirestore, memberPath) : void 0;
|
|
244
|
+
if (node.lock) return [false];
|
|
245
|
+
try {
|
|
246
|
+
await setDoc(docRef, { deletedByRef, updatedByRef: deletedByRef }, { merge: true });
|
|
247
|
+
return [
|
|
248
|
+
[
|
|
249
|
+
// Assume deleted
|
|
250
|
+
true,
|
|
251
|
+
// Wait for cloud function snapshot
|
|
252
|
+
TimedPromise(
|
|
253
|
+
(resolve, reject) => {
|
|
254
|
+
const unsub = onSnapshot(
|
|
255
|
+
docRef,
|
|
256
|
+
async (snapshot) => {
|
|
257
|
+
if (snapshot.exists()) return;
|
|
258
|
+
unsub();
|
|
259
|
+
resolve(true);
|
|
260
|
+
},
|
|
261
|
+
reject
|
|
262
|
+
);
|
|
263
|
+
setTimeout(() => {
|
|
264
|
+
unsub();
|
|
265
|
+
resolve(false);
|
|
266
|
+
}, 1e4);
|
|
267
|
+
},
|
|
268
|
+
{ fallback: false }
|
|
269
|
+
)
|
|
270
|
+
]
|
|
271
|
+
];
|
|
272
|
+
} catch (err) {
|
|
273
|
+
if (!omitLoggings) {
|
|
274
|
+
console.error("Error deleting document", { docRef }, err);
|
|
275
|
+
useAppLogger("composables:useDocumentDelete", err);
|
|
276
|
+
}
|
|
277
|
+
return [false];
|
|
278
|
+
}
|
|
279
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
interface Queue {
|
|
2
|
+
id: string;
|
|
3
|
+
message: string;
|
|
4
|
+
completed: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* App store
|
|
8
|
+
* Handle app state
|
|
9
|
+
*
|
|
10
|
+
* @state
|
|
11
|
+
*/
|
|
12
|
+
export declare const useAppStore: import("pinia").StoreDefinition<"app", Pick<{
|
|
13
|
+
queue: import("vue").Ref<Queue[], Queue[]>;
|
|
14
|
+
thumbnails: import("vue").Ref<Record<string, string>, Record<string, string>>;
|
|
15
|
+
tvMQRange: import("vue").Ref<boolean, boolean>;
|
|
16
|
+
laptopMQRange: import("vue").Ref<boolean, boolean>;
|
|
17
|
+
tabletMQRange: import("vue").Ref<boolean, boolean>;
|
|
18
|
+
mobileMQRange: import("vue").Ref<boolean, boolean>;
|
|
19
|
+
smartwatchMQRange: import("vue").Ref<boolean, boolean>;
|
|
20
|
+
activeQueue: import("vue").ComputedRef<Queue[]>;
|
|
21
|
+
useQueue: <T>(id: string, message: string, toQueue: () => Promise<string | {
|
|
22
|
+
data: T;
|
|
23
|
+
message: string;
|
|
24
|
+
}>, minutes?: number) => Promise<{
|
|
25
|
+
error?: Error;
|
|
26
|
+
data?: T;
|
|
27
|
+
}>;
|
|
28
|
+
clearQueue: () => void;
|
|
29
|
+
setTvMQRange: (newValue: boolean) => void;
|
|
30
|
+
setLaptopMQRange: (newValue: boolean) => void;
|
|
31
|
+
setTabletMQRange: (newValue: boolean) => void;
|
|
32
|
+
setMobileMQRange: (newValue: boolean) => void;
|
|
33
|
+
setSmartwatchMQRange: (newValue: boolean) => void;
|
|
34
|
+
saveThumbnail: (path: string, file: File) => Promise<void>;
|
|
35
|
+
}, "queue" | "thumbnails" | "tvMQRange" | "laptopMQRange" | "tabletMQRange" | "mobileMQRange" | "smartwatchMQRange">, Pick<{
|
|
36
|
+
queue: import("vue").Ref<Queue[], Queue[]>;
|
|
37
|
+
thumbnails: import("vue").Ref<Record<string, string>, Record<string, string>>;
|
|
38
|
+
tvMQRange: import("vue").Ref<boolean, boolean>;
|
|
39
|
+
laptopMQRange: import("vue").Ref<boolean, boolean>;
|
|
40
|
+
tabletMQRange: import("vue").Ref<boolean, boolean>;
|
|
41
|
+
mobileMQRange: import("vue").Ref<boolean, boolean>;
|
|
42
|
+
smartwatchMQRange: import("vue").Ref<boolean, boolean>;
|
|
43
|
+
activeQueue: import("vue").ComputedRef<Queue[]>;
|
|
44
|
+
useQueue: <T>(id: string, message: string, toQueue: () => Promise<string | {
|
|
45
|
+
data: T;
|
|
46
|
+
message: string;
|
|
47
|
+
}>, minutes?: number) => Promise<{
|
|
48
|
+
error?: Error;
|
|
49
|
+
data?: T;
|
|
50
|
+
}>;
|
|
51
|
+
clearQueue: () => void;
|
|
52
|
+
setTvMQRange: (newValue: boolean) => void;
|
|
53
|
+
setLaptopMQRange: (newValue: boolean) => void;
|
|
54
|
+
setTabletMQRange: (newValue: boolean) => void;
|
|
55
|
+
setMobileMQRange: (newValue: boolean) => void;
|
|
56
|
+
setSmartwatchMQRange: (newValue: boolean) => void;
|
|
57
|
+
saveThumbnail: (path: string, file: File) => Promise<void>;
|
|
58
|
+
}, "activeQueue">, Pick<{
|
|
59
|
+
queue: import("vue").Ref<Queue[], Queue[]>;
|
|
60
|
+
thumbnails: import("vue").Ref<Record<string, string>, Record<string, string>>;
|
|
61
|
+
tvMQRange: import("vue").Ref<boolean, boolean>;
|
|
62
|
+
laptopMQRange: import("vue").Ref<boolean, boolean>;
|
|
63
|
+
tabletMQRange: import("vue").Ref<boolean, boolean>;
|
|
64
|
+
mobileMQRange: import("vue").Ref<boolean, boolean>;
|
|
65
|
+
smartwatchMQRange: import("vue").Ref<boolean, boolean>;
|
|
66
|
+
activeQueue: import("vue").ComputedRef<Queue[]>;
|
|
67
|
+
useQueue: <T>(id: string, message: string, toQueue: () => Promise<string | {
|
|
68
|
+
data: T;
|
|
69
|
+
message: string;
|
|
70
|
+
}>, minutes?: number) => Promise<{
|
|
71
|
+
error?: Error;
|
|
72
|
+
data?: T;
|
|
73
|
+
}>;
|
|
74
|
+
clearQueue: () => void;
|
|
75
|
+
setTvMQRange: (newValue: boolean) => void;
|
|
76
|
+
setLaptopMQRange: (newValue: boolean) => void;
|
|
77
|
+
setTabletMQRange: (newValue: boolean) => void;
|
|
78
|
+
setMobileMQRange: (newValue: boolean) => void;
|
|
79
|
+
setSmartwatchMQRange: (newValue: boolean) => void;
|
|
80
|
+
saveThumbnail: (path: string, file: File) => Promise<void>;
|
|
81
|
+
}, "useQueue" | "clearQueue" | "setTvMQRange" | "setLaptopMQRange" | "setTabletMQRange" | "setMobileMQRange" | "setSmartwatchMQRange" | "saveThumbnail">>;
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { defineStore } from "pinia";
|
|
2
|
+
import { computed, ref } from "vue";
|
|
3
|
+
import { getBase64FromImageFile } from "@open-xamu-co/ui-common-helpers";
|
|
4
|
+
import { TimedPromise } from "../../server/utils/guards.js";
|
|
5
|
+
import { useState } from "#imports";
|
|
6
|
+
export const useAppStore = defineStore("app", () => {
|
|
7
|
+
const queue = useState("app.queue", () => []);
|
|
8
|
+
const thumbnails = ref({});
|
|
9
|
+
const tvMQRange = useState("app.tvMQRange", () => false);
|
|
10
|
+
const laptopMQRange = useState("app.laptopMQRange", () => false);
|
|
11
|
+
const tabletMQRange = useState("app.tabletMQRange", () => false);
|
|
12
|
+
const mobileMQRange = useState("app.mobileMQRange", () => false);
|
|
13
|
+
const smartwatchMQRange = useState("app.smartwatchMQRange", () => false);
|
|
14
|
+
const activeQueue = computed(() => queue.value.filter((item) => !item.completed));
|
|
15
|
+
async function useQueue(id, message, toQueue, minutes = 5) {
|
|
16
|
+
let error;
|
|
17
|
+
let data;
|
|
18
|
+
try {
|
|
19
|
+
queue.value.push({ id, message, completed: false });
|
|
20
|
+
data = await TimedPromise(
|
|
21
|
+
async (resolve) => {
|
|
22
|
+
const message2 = await toQueue();
|
|
23
|
+
const queued = typeof message2 === "string" ? { message: message2 } : message2;
|
|
24
|
+
const index = queue.value.findIndex((item) => item.id === id);
|
|
25
|
+
if (queue.value[index]) {
|
|
26
|
+
queue.value[index].message = queued.message;
|
|
27
|
+
queue.value[index].completed = true;
|
|
28
|
+
}
|
|
29
|
+
resolve(queued.data);
|
|
30
|
+
},
|
|
31
|
+
{ timeout: 1e3 * 60 * minutes }
|
|
32
|
+
);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
error = err instanceof Error ? err : new Error("Hubo un error");
|
|
35
|
+
const index = queue.value.findIndex((item) => item.id === id);
|
|
36
|
+
if (queue.value[index]) {
|
|
37
|
+
queue.value[index].message = error.message;
|
|
38
|
+
queue.value[index].completed = true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
queue.value = queue.value.filter((item) => item.id !== id);
|
|
43
|
+
}, 1e3 * 60);
|
|
44
|
+
return { error, data };
|
|
45
|
+
}
|
|
46
|
+
function clearQueue() {
|
|
47
|
+
queue.value = [];
|
|
48
|
+
}
|
|
49
|
+
function setTvMQRange(newValue) {
|
|
50
|
+
tvMQRange.value = newValue;
|
|
51
|
+
}
|
|
52
|
+
function setLaptopMQRange(newValue) {
|
|
53
|
+
laptopMQRange.value = newValue;
|
|
54
|
+
}
|
|
55
|
+
function setTabletMQRange(newValue) {
|
|
56
|
+
tabletMQRange.value = newValue;
|
|
57
|
+
}
|
|
58
|
+
function setMobileMQRange(newValue) {
|
|
59
|
+
mobileMQRange.value = newValue;
|
|
60
|
+
}
|
|
61
|
+
function setSmartwatchMQRange(newValue) {
|
|
62
|
+
smartwatchMQRange.value = newValue;
|
|
63
|
+
}
|
|
64
|
+
async function saveThumbnail(path, file) {
|
|
65
|
+
const thumb = await getBase64FromImageFile(file);
|
|
66
|
+
thumbnails.value[path] = thumb;
|
|
67
|
+
}
|
|
68
|
+
const store = {
|
|
69
|
+
// App, refs
|
|
70
|
+
queue,
|
|
71
|
+
thumbnails,
|
|
72
|
+
tvMQRange,
|
|
73
|
+
laptopMQRange,
|
|
74
|
+
tabletMQRange,
|
|
75
|
+
mobileMQRange,
|
|
76
|
+
smartwatchMQRange,
|
|
77
|
+
// App, computed
|
|
78
|
+
activeQueue,
|
|
79
|
+
// App, actions
|
|
80
|
+
useQueue,
|
|
81
|
+
clearQueue,
|
|
82
|
+
setTvMQRange,
|
|
83
|
+
setLaptopMQRange,
|
|
84
|
+
setTabletMQRange,
|
|
85
|
+
setMobileMQRange,
|
|
86
|
+
setSmartwatchMQRange,
|
|
87
|
+
saveThumbnail
|
|
88
|
+
};
|
|
89
|
+
return store;
|
|
90
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Instance, Root } from "../../client/types/index.js";
|
|
2
|
+
export interface City {
|
|
3
|
+
state?: {
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
country?: {
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
name: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Root instance store
|
|
13
|
+
* Handle root instance state
|
|
14
|
+
*
|
|
15
|
+
* @state
|
|
16
|
+
*/
|
|
17
|
+
export declare const useRootStore: import("pinia").StoreDefinition<"root", Pick<{
|
|
18
|
+
current: import("#app").CookieRef<Root | undefined>;
|
|
19
|
+
tax: import("vue").ComputedRef<number>;
|
|
20
|
+
setRoot: (newRoot?: Root) => void;
|
|
21
|
+
}, "current">, Pick<{
|
|
22
|
+
current: import("#app").CookieRef<Root | undefined>;
|
|
23
|
+
tax: import("vue").ComputedRef<number>;
|
|
24
|
+
setRoot: (newRoot?: Root) => void;
|
|
25
|
+
}, "tax">, Pick<{
|
|
26
|
+
current: import("#app").CookieRef<Root | undefined>;
|
|
27
|
+
tax: import("vue").ComputedRef<number>;
|
|
28
|
+
setRoot: (newRoot?: Root) => void;
|
|
29
|
+
}, "setRoot">>;
|
|
30
|
+
/**
|
|
31
|
+
* Instance store
|
|
32
|
+
* Handle current instance state
|
|
33
|
+
*
|
|
34
|
+
* @state
|
|
35
|
+
*/
|
|
36
|
+
export declare const useInstanceStore: import("pinia").StoreDefinition<"instance", Pick<{
|
|
37
|
+
fresh: import("#app").CookieRef<boolean>;
|
|
38
|
+
current: import("#app").CookieRef<Instance | undefined>;
|
|
39
|
+
location: import("#app").CookieRef<string | undefined>;
|
|
40
|
+
id: import("vue").ComputedRef<string>;
|
|
41
|
+
setInstance: (instance?: Instance) => Promise<void>;
|
|
42
|
+
unsetInstance: () => void;
|
|
43
|
+
}, "location" | "current" | "fresh">, Pick<{
|
|
44
|
+
fresh: import("#app").CookieRef<boolean>;
|
|
45
|
+
current: import("#app").CookieRef<Instance | undefined>;
|
|
46
|
+
location: import("#app").CookieRef<string | undefined>;
|
|
47
|
+
id: import("vue").ComputedRef<string>;
|
|
48
|
+
setInstance: (instance?: Instance) => Promise<void>;
|
|
49
|
+
unsetInstance: () => void;
|
|
50
|
+
}, "id">, Pick<{
|
|
51
|
+
fresh: import("#app").CookieRef<boolean>;
|
|
52
|
+
current: import("#app").CookieRef<Instance | undefined>;
|
|
53
|
+
location: import("#app").CookieRef<string | undefined>;
|
|
54
|
+
id: import("vue").ComputedRef<string>;
|
|
55
|
+
setInstance: (instance?: Instance) => Promise<void>;
|
|
56
|
+
unsetInstance: () => void;
|
|
57
|
+
}, "setInstance" | "unsetInstance">>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { defineStore, skipHydrate } from "pinia";
|
|
2
|
+
import { omit } from "lodash-es";
|
|
3
|
+
import { computed } from "vue";
|
|
4
|
+
import { makeLogger } from "../../client/utils/logger.js";
|
|
5
|
+
import { useCookie, useRuntimeConfig } from "#imports";
|
|
6
|
+
const cookieOptionsDefaults = {
|
|
7
|
+
sameSite: "strict",
|
|
8
|
+
maxAge: 60 * 60
|
|
9
|
+
// 1 hour
|
|
10
|
+
};
|
|
11
|
+
export const useRootStore = defineStore("root", () => {
|
|
12
|
+
const { production } = useRuntimeConfig().public;
|
|
13
|
+
const cookieOptions = {
|
|
14
|
+
...cookieOptionsDefaults,
|
|
15
|
+
secure: production,
|
|
16
|
+
partitioned: production
|
|
17
|
+
};
|
|
18
|
+
const current = useCookie("root.current", {
|
|
19
|
+
...cookieOptions,
|
|
20
|
+
default: () => void 0
|
|
21
|
+
});
|
|
22
|
+
const tax = computed(() => {
|
|
23
|
+
return (current.value?.config?.iva ?? 19) / 100 + 1;
|
|
24
|
+
});
|
|
25
|
+
function setRoot(newRoot) {
|
|
26
|
+
if (!newRoot) return;
|
|
27
|
+
current.value = newRoot;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
// State
|
|
31
|
+
current: skipHydrate(current),
|
|
32
|
+
// Getters
|
|
33
|
+
tax,
|
|
34
|
+
// Actions
|
|
35
|
+
setRoot
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
export const useInstanceStore = defineStore("instance", () => {
|
|
39
|
+
const { production, cache } = useRuntimeConfig().public;
|
|
40
|
+
const cookieOptions = {
|
|
41
|
+
...cookieOptionsDefaults,
|
|
42
|
+
secure: production,
|
|
43
|
+
partitioned: production
|
|
44
|
+
};
|
|
45
|
+
const current = useCookie("instance.current", {
|
|
46
|
+
...cookieOptions,
|
|
47
|
+
default: () => void 0
|
|
48
|
+
});
|
|
49
|
+
const location = useCookie("instance.location", {
|
|
50
|
+
...cookieOptions,
|
|
51
|
+
default: () => void 0
|
|
52
|
+
});
|
|
53
|
+
const fresh = useCookie("instance.fresh", {
|
|
54
|
+
...omit(cookieOptions, "maxAge"),
|
|
55
|
+
default: () => false
|
|
56
|
+
});
|
|
57
|
+
const id = computed(() => current.value?.id || "");
|
|
58
|
+
async function setInstance(instance) {
|
|
59
|
+
if (!instance) return;
|
|
60
|
+
const url = instance.url;
|
|
61
|
+
const logger = makeLogger({ instanceId: id.value });
|
|
62
|
+
const { locationCountry, locationState, locationCity } = instance;
|
|
63
|
+
current.value = { ...instance, url };
|
|
64
|
+
if (fresh.value || !locationCountry || !locationState || !locationCity) return;
|
|
65
|
+
const endpoint = `${url}/_countries/${locationCountry}/${locationState}/${locationCity}`;
|
|
66
|
+
fresh.value = true;
|
|
67
|
+
try {
|
|
68
|
+
const { data } = await $fetch(endpoint, {
|
|
69
|
+
query: { state: true, country: true },
|
|
70
|
+
headers: { "Cache-Control": cache.longterm }
|
|
71
|
+
});
|
|
72
|
+
if (!data) return;
|
|
73
|
+
location.value = `${data.name}. ${data.state?.name}. ${data.country?.name}.`;
|
|
74
|
+
} catch (err) {
|
|
75
|
+
logger("composables:useInstanceStore:setInstance", err);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function unsetInstance() {
|
|
79
|
+
location.value = void 0;
|
|
80
|
+
current.value = void 0;
|
|
81
|
+
fresh.value = false;
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
// Instance
|
|
85
|
+
fresh: skipHydrate(fresh),
|
|
86
|
+
current: skipHydrate(current),
|
|
87
|
+
location: skipHydrate(location),
|
|
88
|
+
// Getters
|
|
89
|
+
id,
|
|
90
|
+
// Actions
|
|
91
|
+
setInstance,
|
|
92
|
+
unsetInstance
|
|
93
|
+
};
|
|
94
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Auth } from "firebase/auth";
|
|
2
|
+
import type { InstanceMember, User } from "../../client/types/index.js";
|
|
3
|
+
interface iSessionUser extends User, Omit<InstanceMember, "user"> {
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Session store
|
|
7
|
+
* Handle authentication state
|
|
8
|
+
*
|
|
9
|
+
* Token is to large, so this store should handle its own cookie
|
|
10
|
+
*
|
|
11
|
+
* @state
|
|
12
|
+
*/
|
|
13
|
+
export declare const useSessionStore: import("pinia").StoreDefinition<"session", Pick<{
|
|
14
|
+
token: import("#app").CookieRef<string | null>;
|
|
15
|
+
expiredToken: import("#app").CookieRef<boolean>;
|
|
16
|
+
user: import("#app").CookieRef<iSessionUser | undefined>;
|
|
17
|
+
path: import("vue").ComputedRef<string>;
|
|
18
|
+
setUser: ({ createdAt, updatedAt, ...userData }: User, token: string) => void;
|
|
19
|
+
unsetSession: (expiredToken?: boolean) => void;
|
|
20
|
+
logout: (clientAuth?: Auth) => Promise<void>;
|
|
21
|
+
remove: (clientAuth?: Auth) => Promise<void>;
|
|
22
|
+
}, "user" | "token" | "expiredToken">, Pick<{
|
|
23
|
+
token: import("#app").CookieRef<string | null>;
|
|
24
|
+
expiredToken: import("#app").CookieRef<boolean>;
|
|
25
|
+
user: import("#app").CookieRef<iSessionUser | undefined>;
|
|
26
|
+
path: import("vue").ComputedRef<string>;
|
|
27
|
+
setUser: ({ createdAt, updatedAt, ...userData }: User, token: string) => void;
|
|
28
|
+
unsetSession: (expiredToken?: boolean) => void;
|
|
29
|
+
logout: (clientAuth?: Auth) => Promise<void>;
|
|
30
|
+
remove: (clientAuth?: Auth) => Promise<void>;
|
|
31
|
+
}, "path">, Pick<{
|
|
32
|
+
token: import("#app").CookieRef<string | null>;
|
|
33
|
+
expiredToken: import("#app").CookieRef<boolean>;
|
|
34
|
+
user: import("#app").CookieRef<iSessionUser | undefined>;
|
|
35
|
+
path: import("vue").ComputedRef<string>;
|
|
36
|
+
setUser: ({ createdAt, updatedAt, ...userData }: User, token: string) => void;
|
|
37
|
+
unsetSession: (expiredToken?: boolean) => void;
|
|
38
|
+
logout: (clientAuth?: Auth) => Promise<void>;
|
|
39
|
+
remove: (clientAuth?: Auth) => Promise<void>;
|
|
40
|
+
}, "remove" | "setUser" | "unsetSession" | "logout">>;
|
|
41
|
+
export {};
|