@progressive-development/pd-spa-helper 0.1.164 → 0.1.166
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/PdSpaHelper.js +5 -3
- package/dist/src/PdSpaHelper.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/service-provider/firebase/auth.d.ts +7 -0
- package/dist/src/service-provider/firebase/auth.js +28 -4
- package/dist/src/service-provider/firebase/auth.js.map +1 -1
- package/dist/src/service-provider/firebase/firestorage-client.d.ts +2 -1
- package/dist/src/service-provider/firebase/firestorage-client.js +46 -1
- package/dist/src/service-provider/firebase/firestorage-client.js.map +1 -1
- package/dist/src/service-provider/mock/storage-client.d.ts +2 -1
- package/dist/src/service-provider/mock/storage-client.js +8 -0
- 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 +14 -3
- package/dist/src/service-provider/service-provider-impl.js.map +1 -1
- package/dist/src/service-provider/service-provider-model.d.ts +8 -0
- 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/PdSpaHelper.ts +8 -4
- package/src/index.ts +2 -1
- package/src/service-provider/firebase/auth.ts +35 -9
- package/src/service-provider/firebase/firestorage-client.ts +54 -2
- package/src/service-provider/mock/storage-client.ts +12 -1
- package/src/service-provider/service-provider-impl.ts +17 -5
- package/src/service-provider/service-provider-model.ts +8 -1
package/package.json
CHANGED
package/src/PdSpaHelper.ts
CHANGED
|
@@ -90,6 +90,8 @@ const transformRoutes = () => {
|
|
|
90
90
|
*/
|
|
91
91
|
export const startInit = (config: AppConfiguration) => {
|
|
92
92
|
|
|
93
|
+
console.log("Start init for config: ", config);
|
|
94
|
+
|
|
93
95
|
// set service provider
|
|
94
96
|
setServiceProvider(config.serviceProvider);
|
|
95
97
|
|
|
@@ -101,6 +103,7 @@ export const startInit = (config: AppConfiguration) => {
|
|
|
101
103
|
// init app
|
|
102
104
|
initAppImpl(config);
|
|
103
105
|
|
|
106
|
+
// add login route if set in config
|
|
104
107
|
if (config.navigationConfigParam.includeLogin) {
|
|
105
108
|
config.navigationConfigParam.pages.push({
|
|
106
109
|
name: "login",
|
|
@@ -110,15 +113,16 @@ export const startInit = (config: AppConfiguration) => {
|
|
|
110
113
|
pattern: ["login"],
|
|
111
114
|
auth: false
|
|
112
115
|
});
|
|
113
|
-
|
|
114
|
-
// init ready, trigger by even (if getAuth is called before, error is thrown)
|
|
115
|
-
document.dispatchEvent(new CustomEvent("init-app-event"));
|
|
116
|
-
console.log("Init done, Event created");
|
|
117
116
|
}
|
|
118
117
|
|
|
119
118
|
// generate routes from navigation config
|
|
120
119
|
navigationConfig = config.navigationConfigParam;
|
|
121
120
|
transformedRoutes = transformRoutes();
|
|
121
|
+
|
|
122
|
+
// init ready, trigger by even (if getAuth is called before, error is thrown)
|
|
123
|
+
document.dispatchEvent(new CustomEvent("init-app-event"));
|
|
124
|
+
console.log("Init done, Event created");
|
|
125
|
+
|
|
122
126
|
};
|
|
123
127
|
|
|
124
128
|
const TOP_MENU_HEIGHT = 50;
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FirebaseApp } from 'firebase/app';
|
|
2
|
+
import { Auth, getAuth, onAuthStateChanged, signInWithEmailAndPassword, signOut, User } from 'firebase/auth';
|
|
3
|
+
|
|
4
|
+
let auth: Auth;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* During start/load application, initialize functions.
|
|
8
|
+
*
|
|
9
|
+
* @param {*} app - initialized app.
|
|
10
|
+
*/
|
|
11
|
+
export const initAuth = (appParam: FirebaseApp) => {
|
|
12
|
+
auth = getAuth(appParam);
|
|
13
|
+
console.log("App for auth is set: ", auth);
|
|
14
|
+
}
|
|
2
15
|
|
|
3
16
|
export const logout = async (): Promise<boolean> => {
|
|
4
|
-
|
|
17
|
+
if (!auth) {
|
|
18
|
+
throw new Error("logout: Auth was not initialized");
|
|
19
|
+
}
|
|
5
20
|
try {
|
|
6
21
|
await signOut(auth);
|
|
7
22
|
return true;
|
|
@@ -10,12 +25,21 @@ export const logout = async (): Promise<boolean> => {
|
|
|
10
25
|
}
|
|
11
26
|
};
|
|
12
27
|
|
|
13
|
-
export const isAuthenticated = (): boolean =>
|
|
14
|
-
|
|
28
|
+
export const isAuthenticated = (): boolean => {
|
|
29
|
+
if (!auth) {
|
|
30
|
+
throw new Error("isAuthenticated: Auth was not initialized");
|
|
31
|
+
}
|
|
32
|
+
const authCheck = auth.currentUser !== null;
|
|
33
|
+
console.log("Check auth: ", authCheck);
|
|
34
|
+
return authCheck;
|
|
35
|
+
};
|
|
15
36
|
|
|
16
37
|
|
|
17
|
-
export const authStateChanged = (callback: Function) => {
|
|
18
|
-
|
|
38
|
+
export const authStateChanged = (callback: Function) => {
|
|
39
|
+
if (!auth) {
|
|
40
|
+
throw new Error("authStateChanged: Auth was not initialized");
|
|
41
|
+
}
|
|
42
|
+
onAuthStateChanged(auth, (user) => callback(user));
|
|
19
43
|
/* Alter code aus init in pd-spa-helper, hier falsch, noch refactorieren
|
|
20
44
|
if (user) {
|
|
21
45
|
this._user = user;
|
|
@@ -44,9 +68,11 @@ export const authStateChanged = (callback: Function) => {
|
|
|
44
68
|
}
|
|
45
69
|
*/
|
|
46
70
|
}
|
|
47
|
-
|
|
71
|
+
|
|
48
72
|
export const login = async (user:string, sec:string): Promise<User> => {
|
|
49
|
-
|
|
73
|
+
if (!auth) {
|
|
74
|
+
throw new Error("login: Auth was not initialized");
|
|
75
|
+
}
|
|
50
76
|
const credentials = await signInWithEmailAndPassword(auth, user, sec);
|
|
51
|
-
return credentials.user;
|
|
77
|
+
return credentials.user;
|
|
52
78
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FirebaseApp } from 'firebase/app';
|
|
2
|
-
import { FirebaseStorage, StorageReference, UploadResult, getStorage, ref, uploadString } from "firebase/storage";
|
|
2
|
+
import { FirebaseStorage, StorageReference, UploadResult, getStorage, listAll, ref, uploadString } from "firebase/storage";
|
|
3
3
|
|
|
4
|
-
import { FileStorageConfig, UploadFile } from '../service-provider-model.js';
|
|
4
|
+
import { FileStorageConfig, StorageDocument, UploadFile } from '../service-provider-model.js';
|
|
5
5
|
|
|
6
6
|
const DEFAULT_STORAGE = "default_storage";
|
|
7
7
|
|
|
@@ -89,6 +89,58 @@ export const uploadFirestorageFile = (file: UploadFile):Promise<UploadResult> =>
|
|
|
89
89
|
return uploadString(fileRef, file.base64DataURL, 'data_url', metadata);
|
|
90
90
|
};
|
|
91
91
|
|
|
92
|
+
export const getFirestorageFileList = (storageName: string, refKey: string):Promise<StorageDocument[]> => {
|
|
93
|
+
|
|
94
|
+
if (!storageMap || storageMap.size === 0) {
|
|
95
|
+
throw new Error("No storage is configured");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// get storage
|
|
99
|
+
const storageConf = storageMap.get(storageName);
|
|
100
|
+
if (!storageConf ) {
|
|
101
|
+
throw new Error(`Invalid storage name: ${storageName}`);
|
|
102
|
+
}
|
|
103
|
+
if (!storageConf.references || storageConf.references.length === 0) {
|
|
104
|
+
throw new Error(`No references configured for storage: ${storageName || DEFAULT_STORAGE}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// get refrence
|
|
108
|
+
const storageRef = storageConf.references.filter(refIt => refIt.key === refKey)[0];
|
|
109
|
+
|
|
110
|
+
const itemRefs: StorageDocument[] = [];
|
|
111
|
+
return listAll(storageRef.storageRef)
|
|
112
|
+
.then((res) => {
|
|
113
|
+
res.items.forEach((itemRef) => {
|
|
114
|
+
// All the items under listRef.
|
|
115
|
+
itemRefs.push({
|
|
116
|
+
fileName: itemRef.name,
|
|
117
|
+
filePath: itemRef.fullPath,
|
|
118
|
+
documentType: "ToDo",
|
|
119
|
+
// description: "ToDo Some Description",
|
|
120
|
+
// creator: "ToDo",
|
|
121
|
+
// creation: new Date(),
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// MetaData for each item with own promise
|
|
126
|
+
/*
|
|
127
|
+
// Get metadata properties
|
|
128
|
+
getMetadata(forestRef)
|
|
129
|
+
.then((metadata) => {
|
|
130
|
+
// Metadata now contains the metadata for 'images/forest.jpg'
|
|
131
|
+
}).catch((error) => {
|
|
132
|
+
// Uh-oh, an error occurred!
|
|
133
|
+
});
|
|
134
|
+
*/
|
|
135
|
+
return itemRefs;
|
|
136
|
+
}).catch((error) => {
|
|
137
|
+
// TODO: add error handling
|
|
138
|
+
console.log("Error during file list", error);
|
|
139
|
+
throw error;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
};
|
|
143
|
+
|
|
92
144
|
|
|
93
145
|
/* Firestorage Error List: https://firebase.google.com/docs/storage/web/handle-errors */
|
|
94
146
|
/*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FileStorageConfig, UploadFile } from '../service-provider-model.js';
|
|
1
|
+
import { FileStorageConfig, StorageDocument, UploadFile } from '../service-provider-model.js';
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
const DEFAULT_STORAGE = "default_storage";
|
|
@@ -124,4 +124,15 @@ export const uploadStorageFileMock = (file: UploadFile):Promise<any> => {
|
|
|
124
124
|
return storageConf.storage.uploadFile(fileRef, file);
|
|
125
125
|
};
|
|
126
126
|
|
|
127
|
+
export const getMockFileList = (storageName: string, keyRef: string):Promise<StorageDocument[]> => {
|
|
128
|
+
console.log("Searching for Documents in ", storageName, keyRef);
|
|
129
|
+
return Promise.resolve([{
|
|
130
|
+
fileName: "workReport.png",
|
|
131
|
+
filePath: "workReports/1234234f2fswf/workReport.png",
|
|
132
|
+
documentType: "ToDo",
|
|
133
|
+
}]);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
127
138
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { FirebaseApp, FirebaseOptions, initializeApp } from "firebase/app";
|
|
2
2
|
|
|
3
|
-
import { authStateChanged, isAuthenticated, login, logout } from "./firebase/auth.js";
|
|
3
|
+
import { authStateChanged, initAuth, isAuthenticated, login, logout } from "./firebase/auth.js";
|
|
4
4
|
import { authStateChangedMock, isAuthenticatedMock, loginMock, logoutMock } from "./mock/auth.js";
|
|
5
|
-
import { AppConfiguration, FileStorageConfig, FunctionDefinition, FunctionResult, FunctionsConfig, ServiceProviderConfiguration, UploadFile } from "./service-provider-model.js";
|
|
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";
|
|
8
8
|
import { callFunctionMock, initMockResponse } from "./mock/function-client.js";
|
|
9
9
|
import { ServiceCallController } from "../service-call-controller2.js";
|
|
10
|
-
import { initFirestorage, uploadFirestorageFile } from "./firebase/firestorage-client.js";
|
|
11
|
-
import { initStorageMock, uploadStorageFileMock } from "./mock/storage-client.js";
|
|
10
|
+
import { getFirestorageFileList, initFirestorage, uploadFirestorageFile } from "./firebase/firestorage-client.js";
|
|
11
|
+
import { getMockFileList, initStorageMock, uploadStorageFileMock } from "./mock/storage-client.js";
|
|
12
12
|
|
|
13
13
|
let provider: ServiceProviderConfiguration | undefined;
|
|
14
14
|
let controller: ServiceCallController;
|
|
@@ -36,10 +36,12 @@ const initFirebaseApplicationServices = (
|
|
|
36
36
|
storageConfig?: FileStorageConfig,
|
|
37
37
|
) => {
|
|
38
38
|
// do something with the app, init db, firestore and functions
|
|
39
|
+
initAuth(firebaseApp);
|
|
39
40
|
initFunctions(firebaseApp, functionsConfig);
|
|
40
41
|
initFirestore(firebaseApp);
|
|
41
42
|
initFirestorage(firebaseApp, firebaseConfig.storageBucket, storageConfig);
|
|
42
|
-
|
|
43
|
+
|
|
44
|
+
console.log("Firebase App with functions, firestore and firestorage initialized");
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
export const initAppImpl = (config: AppConfiguration) => {
|
|
@@ -153,4 +155,14 @@ export const uploadFile = (file: UploadFile): Promise<unknown> => {
|
|
|
153
155
|
return uploadStorageFileMock(file)
|
|
154
156
|
}
|
|
155
157
|
return throwUndefinedProviderError();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export const getStorageFileList = (storageName: string, keyRef: string): Promise<StorageDocument[]> => {
|
|
161
|
+
if (provider === "firebase") {
|
|
162
|
+
return getFirestorageFileList(storageName, keyRef);
|
|
163
|
+
}
|
|
164
|
+
if (provider === "mock") {
|
|
165
|
+
return getMockFileList(storageName, keyRef);
|
|
166
|
+
}
|
|
167
|
+
return throwUndefinedProviderError();
|
|
156
168
|
}
|
|
@@ -127,4 +127,11 @@ export interface UploadFile {
|
|
|
127
127
|
subFolderName?: string,
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
export interface StorageDocument {
|
|
131
|
+
fileName: string,
|
|
132
|
+
documentType: string,
|
|
133
|
+
filePath: string,
|
|
134
|
+
description?:string,
|
|
135
|
+
creation?:Date,
|
|
136
|
+
creator?:string,
|
|
137
|
+
}
|