@progressive-development/pd-spa-helper 0.1.170 → 0.1.172
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/dist/src/service-provider/firebase/auth.d.ts +1 -0
- package/dist/src/service-provider/firebase/auth.js +6 -0
- package/dist/src/service-provider/firebase/auth.js.map +1 -1
- package/dist/src/service-provider/firebase/firestorage-client.d.ts +1 -1
- package/dist/src/service-provider/firebase/firestorage-client.js +35 -19
- package/dist/src/service-provider/firebase/firestorage-client.js.map +1 -1
- package/dist/src/service-provider/firebase/functions-client.js +3 -0
- package/dist/src/service-provider/firebase/functions-client.js.map +1 -1
- package/dist/src/service-provider/mock/auth.d.ts +1 -0
- package/dist/src/service-provider/mock/auth.js +4 -0
- package/dist/src/service-provider/mock/auth.js.map +1 -1
- package/dist/src/service-provider/mock/storage-client.d.ts +1 -1
- package/dist/src/service-provider/mock/storage-client.js +2 -2
- package/dist/src/service-provider/mock/storage-client.js.map +1 -1
- package/dist/src/service-provider/service-provider-impl.d.ts +2 -1
- package/dist/src/service-provider/service-provider-impl.js +15 -5
- package/dist/src/service-provider/service-provider-impl.js.map +1 -1
- package/dist/src/service-provider/service-provider-model.d.ts +8 -3
- package/dist/src/service-provider/service-provider-model.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/service-provider/firebase/auth.ts +6 -0
- package/src/service-provider/firebase/firestorage-client.ts +44 -22
- package/src/service-provider/firebase/functions-client.ts +5 -0
- package/src/service-provider/mock/auth.ts +6 -0
- package/src/service-provider/mock/storage-client.ts +7 -2
- package/src/service-provider/service-provider-impl.ts +21 -5
- package/src/service-provider/service-provider-model.ts +11 -4
package/package.json
CHANGED
|
@@ -34,6 +34,12 @@ export const isAuthenticated = (): boolean => {
|
|
|
34
34
|
return authCheck;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
export const getAuthUser = (): unknown => {
|
|
38
|
+
if (!auth) {
|
|
39
|
+
throw new Error("isAuthenticated: Auth was not initialized");
|
|
40
|
+
}
|
|
41
|
+
return auth.currentUser;
|
|
42
|
+
};
|
|
37
43
|
|
|
38
44
|
export const authStateChanged = (callback: Function) => {
|
|
39
45
|
if (!auth) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { FirebaseApp } from 'firebase/app';
|
|
2
|
-
import { FirebaseStorage, StorageReference, UploadResult, getStorage, listAll, ref, uploadString } from "firebase/storage";
|
|
2
|
+
import { FirebaseStorage, FullMetadata, StorageReference, UploadResult, getMetadata, getStorage, listAll, ref, uploadString } from "firebase/storage";
|
|
3
3
|
|
|
4
4
|
import { FileStorageConfig, StorageDocument, UploadFile } from '../service-provider-model.js';
|
|
5
|
+
import { getUser } from '../service-provider-impl.js';
|
|
5
6
|
|
|
6
7
|
const DEFAULT_STORAGE = "default_storage";
|
|
7
8
|
|
|
@@ -79,21 +80,30 @@ export const uploadFirestorageFile = (file: UploadFile):Promise<UploadResult> =>
|
|
|
79
80
|
// create file reference and upload
|
|
80
81
|
const fileRef = ref(uploadRefConf.storageRef, subFolderName ? `${subFolderName}/${fileName}` : fileName);
|
|
81
82
|
|
|
82
|
-
//
|
|
83
|
+
// default usefull metadata: contentType, size, timeCreated, updated
|
|
84
|
+
|
|
85
|
+
// additional custom metadata
|
|
83
86
|
const metadata = {
|
|
84
87
|
customMetadata: {
|
|
88
|
+
'creator': (getUser() as any)?.displayName,
|
|
85
89
|
'comment': file.description,
|
|
90
|
+
'name': file.descriptionName,
|
|
86
91
|
}
|
|
87
92
|
};
|
|
88
93
|
|
|
89
94
|
return uploadString(fileRef, file.base64DataURL, 'data_url', metadata);
|
|
90
95
|
};
|
|
91
96
|
|
|
92
|
-
export const getFirestorageFileList = (
|
|
97
|
+
export const getFirestorageFileList = (
|
|
98
|
+
storageName: string,
|
|
99
|
+
refKey: string,
|
|
100
|
+
subFolder?: string,
|
|
101
|
+
includeMetaData?: boolean
|
|
102
|
+
):Promise<StorageDocument[]> => {
|
|
93
103
|
|
|
94
104
|
if (!storageMap || storageMap.size === 0) {
|
|
95
105
|
throw new Error("No storage is configured");
|
|
96
|
-
}
|
|
106
|
+
}
|
|
97
107
|
|
|
98
108
|
// get storage
|
|
99
109
|
const storageConf = storageMap.get(storageName);
|
|
@@ -106,32 +116,44 @@ export const getFirestorageFileList = (storageName: string, refKey: string):Prom
|
|
|
106
116
|
|
|
107
117
|
// get refrence
|
|
108
118
|
const storageRef = storageConf.references.filter(refIt => refIt.key === refKey)[0];
|
|
109
|
-
|
|
119
|
+
if (!storageRef) {
|
|
120
|
+
throw new Error(`No reference available for storage: ${storageName || DEFAULT_STORAGE} and ref: ${refKey}`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const usedRef = subFolder ? ref(storageRef.storageRef, subFolder) : storageRef.storageRef;
|
|
110
124
|
const itemRefs: StorageDocument[] = [];
|
|
111
|
-
return listAll(
|
|
125
|
+
return listAll(usedRef)
|
|
112
126
|
.then((res) => {
|
|
113
|
-
|
|
114
|
-
|
|
127
|
+
|
|
128
|
+
const metaPromises:Promise<FullMetadata>[] = [];
|
|
129
|
+
res.items.forEach((itemRef) => {
|
|
130
|
+
// All the items under listRef .
|
|
115
131
|
itemRefs.push({
|
|
116
132
|
fileName: itemRef.name,
|
|
117
133
|
filePath: itemRef.fullPath,
|
|
118
|
-
documentType: "ToDo",
|
|
119
|
-
// description: "ToDo Some Description",
|
|
120
|
-
// creator: "ToDo",
|
|
121
|
-
// creation: new Date(),
|
|
122
134
|
});
|
|
135
|
+
|
|
136
|
+
// MetaData for each item with own promise
|
|
137
|
+
if (includeMetaData) {
|
|
138
|
+
metaPromises.push(getMetadata(itemRef));
|
|
139
|
+
}
|
|
123
140
|
});
|
|
124
141
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
142
|
+
if (includeMetaData) {
|
|
143
|
+
return Promise.all(metaPromises)
|
|
144
|
+
.then(metaResults => itemRefs.map((item: StorageDocument, index: number) => (
|
|
145
|
+
{
|
|
146
|
+
...item,
|
|
147
|
+
creation: new Date(metaResults[index]?.timeCreated),
|
|
148
|
+
documentType: metaResults[index]?.contentType,
|
|
149
|
+
creator: metaResults[index]?.customMetadata?.creator,
|
|
150
|
+
descriptionName: metaResults[index]?.customMetadata?.name,
|
|
151
|
+
description: metaResults[index]?.customMetadata?.comment,
|
|
152
|
+
size: metaResults[index]?.size,
|
|
153
|
+
metaData: metaResults[index]
|
|
154
|
+
}
|
|
155
|
+
)));
|
|
156
|
+
}
|
|
135
157
|
return itemRefs;
|
|
136
158
|
}).catch((error) => {
|
|
137
159
|
// TODO: add error handling
|
|
@@ -32,6 +32,11 @@ const internalCallFunction = async (def: FunctionDefinition, functionInput: any)
|
|
|
32
32
|
&& funcResult.data && def.successCodes.includes(funcResult.data.statusCode)) {
|
|
33
33
|
return funcResult.data as FunctionResult;
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
if (funcResult && funcResult.data) {
|
|
37
|
+
throw new Error(`Error: ${funcResult.data.statusCode} - ${funcResult.data.resultData}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
35
40
|
/*
|
|
36
41
|
const ne = new Error("Invalid result");
|
|
37
42
|
if (result.data) {
|
|
@@ -37,6 +37,12 @@ export const isAuthenticatedMock = (): boolean => {
|
|
|
37
37
|
return loginAvailable;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
export const getAuthUserMock = (): unknown =>
|
|
41
|
+
isAuthenticatedMock() ? {
|
|
42
|
+
uid: "34234234",
|
|
43
|
+
displayName: "userMockName"
|
|
44
|
+
} : undefined;
|
|
45
|
+
|
|
40
46
|
|
|
41
47
|
export const authStateChangedMock = () => {
|
|
42
48
|
console.log("Not implemented for MOCK");
|
|
@@ -124,8 +124,13 @@ export const uploadStorageFileMock = (file: UploadFile):Promise<any> => {
|
|
|
124
124
|
return storageConf.storage.uploadFile(fileRef, file);
|
|
125
125
|
};
|
|
126
126
|
|
|
127
|
-
export const getMockFileList = (
|
|
128
|
-
|
|
127
|
+
export const getMockFileList = (
|
|
128
|
+
storageName: string,
|
|
129
|
+
keyRef: string,
|
|
130
|
+
subFolder?: string,
|
|
131
|
+
includeMetadata?: boolean
|
|
132
|
+
):Promise<StorageDocument[]> => {
|
|
133
|
+
console.log("Searching for Documents in ", storageName, keyRef, subFolder, includeMetadata);
|
|
129
134
|
return Promise.resolve([{
|
|
130
135
|
fileName: "workReport.png",
|
|
131
136
|
filePath: "workReports/1234234f2fswf/workReport.png",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FirebaseApp, FirebaseOptions, initializeApp } from "firebase/app";
|
|
2
2
|
|
|
3
|
-
import { authStateChanged, initAuth, isAuthenticated, login, logout } from "./firebase/auth.js";
|
|
4
|
-
import { authStateChangedMock, isAuthenticatedMock, loginMock, logoutMock } from "./mock/auth.js";
|
|
3
|
+
import { authStateChanged, getAuthUser, initAuth, isAuthenticated, login, logout } from "./firebase/auth.js";
|
|
4
|
+
import { authStateChangedMock, getAuthUserMock, isAuthenticatedMock, loginMock, logoutMock } from "./mock/auth.js";
|
|
5
5
|
import { AppConfiguration, FileStorageConfig, FunctionDefinition, FunctionResult, FunctionsConfig, ServiceProviderConfiguration, StorageDocument, UploadFile } from "./service-provider-model.js";
|
|
6
6
|
import { callFunction, initFunctions } from "./firebase/functions-client.js";
|
|
7
7
|
import { initFirestore } from "./firebase/firestore-client.js";
|
|
@@ -142,6 +142,17 @@ export const logoutImpl = () => {
|
|
|
142
142
|
return logoutMock();
|
|
143
143
|
}
|
|
144
144
|
return throwUndefinedProviderError();
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// Refactor: Return defined USer Object
|
|
148
|
+
export const getUser = () => {
|
|
149
|
+
if (provider === "firebase") {
|
|
150
|
+
return getAuthUser();
|
|
151
|
+
}
|
|
152
|
+
if (provider === "mock") {
|
|
153
|
+
return getAuthUserMock();
|
|
154
|
+
}
|
|
155
|
+
return throwUndefinedProviderError();
|
|
145
156
|
}
|
|
146
157
|
|
|
147
158
|
/* #####################
|
|
@@ -157,12 +168,17 @@ export const uploadFile = (file: UploadFile): Promise<unknown> => {
|
|
|
157
168
|
return throwUndefinedProviderError();
|
|
158
169
|
}
|
|
159
170
|
|
|
160
|
-
export const getStorageFileList = (
|
|
171
|
+
export const getStorageFileList = (
|
|
172
|
+
storageName: string,
|
|
173
|
+
keyRef: string,
|
|
174
|
+
subFolder?: string,
|
|
175
|
+
includeMetadata?:boolean
|
|
176
|
+
): Promise<StorageDocument[]> => {
|
|
161
177
|
if (provider === "firebase") {
|
|
162
|
-
return getFirestorageFileList(storageName, keyRef);
|
|
178
|
+
return getFirestorageFileList(storageName, keyRef, subFolder, includeMetadata);
|
|
163
179
|
}
|
|
164
180
|
if (provider === "mock") {
|
|
165
|
-
return getMockFileList(storageName, keyRef);
|
|
181
|
+
return getMockFileList(storageName, keyRef, subFolder, includeMetadata);
|
|
166
182
|
}
|
|
167
183
|
return throwUndefinedProviderError();
|
|
168
184
|
}
|
|
@@ -123,16 +123,23 @@ export interface UploadFile {
|
|
|
123
123
|
base64DataURL:string,
|
|
124
124
|
descriptionName:string,
|
|
125
125
|
description:string,
|
|
126
|
-
storageName
|
|
127
|
-
referenceKey
|
|
126
|
+
storageName: string
|
|
127
|
+
referenceKey: string
|
|
128
128
|
subFolderName?: string,
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
export interface StorageMetadata {
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
|
|
131
135
|
export interface StorageDocument {
|
|
132
|
-
fileName: string,
|
|
133
|
-
documentType: string,
|
|
136
|
+
fileName: string,
|
|
134
137
|
filePath: string,
|
|
138
|
+
documentType?: string,
|
|
135
139
|
description?:string,
|
|
140
|
+
descriptionName?: string,
|
|
136
141
|
creation?:Date,
|
|
137
142
|
creator?:string,
|
|
143
|
+
size?: number,
|
|
144
|
+
metaData?: StorageMetadata
|
|
138
145
|
}
|