@churchapps/helpers 1.0.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/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/ArrayHelper.d.ts +12 -0
- package/dist/ArrayHelper.d.ts.map +1 -0
- package/dist/ArrayHelper.js +85 -0
- package/dist/ArrayHelper.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/package.json +36 -0
- package/src/ApiHelper.ts +125 -0
- package/src/AppearanceHelper.ts +69 -0
- package/src/ArrayHelper.ts +80 -0
- package/src/CommonEnvironmentHelper.ts +80 -0
- package/src/CurrencyHelper.ts +10 -0
- package/src/DateHelper.ts +108 -0
- package/src/DonationHelper.ts +26 -0
- package/src/ErrorHelper.ts +36 -0
- package/src/EventHelper.ts +49 -0
- package/src/FileHelper.ts +31 -0
- package/src/PersonHelper.ts +60 -0
- package/src/UniqueIdHelper.ts +36 -0
- package/src/UserHelper.ts +59 -0
- package/src/index.ts +11 -0
- package/src/interfaces/Access.ts +24 -0
- package/src/interfaces/Attendance.ts +8 -0
- package/src/interfaces/Content.ts +10 -0
- package/src/interfaces/Doing.ts +24 -0
- package/src/interfaces/Donation.ts +45 -0
- package/src/interfaces/Error.ts +17 -0
- package/src/interfaces/Membership.ts +51 -0
- package/src/interfaces/Messaging.ts +20 -0
- package/src/interfaces/Permissions.ts +68 -0
- package/src/interfaces/Reporting.ts +7 -0
- package/src/interfaces/UserContextInterface.ts +13 -0
- package/src/interfaces/index.ts +12 -0
- package/tsconfig.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Live Church Solutions
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Helpers
|
|
2
|
+
|
|
3
|
+
Library of helper functions not specific to any project or framework.
|
|
4
|
+
|
|
5
|
+
## To Test
|
|
6
|
+
|
|
7
|
+
1. After making changes run `npm build` followed by `npm link` to expose the package locally
|
|
8
|
+
2. In your test project run `@npm link @churchapps/helpers`
|
|
9
|
+
3. Rerun both after changes
|
|
10
|
+
|
|
11
|
+
## To Publish
|
|
12
|
+
|
|
13
|
+
1. Run `npm publish --access=public`
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class ArrayHelper {
|
|
2
|
+
static getIds(array: any[], propertyName: string): string[];
|
|
3
|
+
static sortBy(array: any[], propertyName: string, descending?: boolean): void;
|
|
4
|
+
static getIndex(array: any[], propertyName: string, value: any): number;
|
|
5
|
+
static getOne(array: any[], propertyName: string, value: any): any;
|
|
6
|
+
static getAll(array: any[], propertyName: string, value: any): any[];
|
|
7
|
+
static getAllArray(array: any[], propertyName: string, values: any[]): any[];
|
|
8
|
+
private static compare;
|
|
9
|
+
static getUniqueValues(array: any[], propertyName: string): any[];
|
|
10
|
+
static getDeepValue(item: any, propertyName: string): any;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=ArrayHelper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArrayHelper.d.ts","sourceRoot":"","sources":["../src/ArrayHelper.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAW;IACtB,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,YAAY,EAAE,MAAM;IAShD,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,GAAE,OAAe;IAS7E,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG;IAQ9D,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG;IAK5D,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG;IAQ5D,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE;IAMpE,OAAO,CAAC,MAAM,CAAC,OAAO;IAYtB,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,YAAY,EAAE,MAAM;IAUzD,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM;CASpD"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArrayHelper = void 0;
|
|
4
|
+
class ArrayHelper {
|
|
5
|
+
static getIds(array, propertyName) {
|
|
6
|
+
const result = [];
|
|
7
|
+
for (const item of array) {
|
|
8
|
+
const id = item[propertyName]?.toString();
|
|
9
|
+
if (id && result.indexOf(id) === -1)
|
|
10
|
+
result.push(id);
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
static sortBy(array, propertyName, descending = false) {
|
|
15
|
+
array.sort((a, b) => {
|
|
16
|
+
const valA = a[propertyName];
|
|
17
|
+
const valB = b[propertyName];
|
|
18
|
+
if (valA < valB)
|
|
19
|
+
return descending ? 1 : -1;
|
|
20
|
+
else
|
|
21
|
+
return descending ? -1 : 1;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
static getIndex(array, propertyName, value) {
|
|
25
|
+
for (let i = 0; i < array.length; i++) {
|
|
26
|
+
const item = array[i];
|
|
27
|
+
if (ArrayHelper.compare(item, propertyName, value))
|
|
28
|
+
return i;
|
|
29
|
+
}
|
|
30
|
+
return -1;
|
|
31
|
+
}
|
|
32
|
+
static getOne(array, propertyName, value) {
|
|
33
|
+
for (const item of array || [])
|
|
34
|
+
if (ArrayHelper.compare(item, propertyName, value))
|
|
35
|
+
return item;
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
static getAll(array, propertyName, value) {
|
|
39
|
+
const result = [];
|
|
40
|
+
for (const item of array || []) {
|
|
41
|
+
if (ArrayHelper.compare(item, propertyName, value))
|
|
42
|
+
result.push(item);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
static getAllArray(array, propertyName, values) {
|
|
47
|
+
const result = [];
|
|
48
|
+
for (const item of array || [])
|
|
49
|
+
if (values.indexOf(item[propertyName]) > -1)
|
|
50
|
+
result.push(item);
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
static compare(item, propertyName, value) {
|
|
54
|
+
const propChain = propertyName.split(".");
|
|
55
|
+
if (propChain.length === 1)
|
|
56
|
+
return item[propertyName] === value;
|
|
57
|
+
else {
|
|
58
|
+
let obj = item;
|
|
59
|
+
for (let i = 0; i < propChain.length - 1; i++) {
|
|
60
|
+
if (obj)
|
|
61
|
+
obj = item[propChain[i]];
|
|
62
|
+
}
|
|
63
|
+
return obj[propChain[propChain.length - 1]] === value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
static getUniqueValues(array, propertyName) {
|
|
67
|
+
const result = [];
|
|
68
|
+
for (const item of array) {
|
|
69
|
+
const val = (propertyName.indexOf(".") === -1) ? item[propertyName] : this.getDeepValue(item, propertyName);
|
|
70
|
+
if (result.indexOf(val) === -1)
|
|
71
|
+
result.push(val);
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
static getDeepValue(item, propertyName) {
|
|
76
|
+
const propertyNames = propertyName.split(".");
|
|
77
|
+
let result = item;
|
|
78
|
+
propertyNames.forEach(name => {
|
|
79
|
+
result = result[name];
|
|
80
|
+
});
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.ArrayHelper = ArrayHelper;
|
|
85
|
+
//# sourceMappingURL=ArrayHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArrayHelper.js","sourceRoot":"","sources":["../src/ArrayHelper.ts"],"names":[],"mappings":";;;AAAA,MAAa,WAAW;IACtB,MAAM,CAAC,MAAM,CAAC,KAAY,EAAE,YAAoB;QAC9C,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,MAAM,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC;YAC1C,IAAI,EAAE,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,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AC;QAEzB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,MAAM,GAAG,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;YAC3G,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SAClD;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,IAAS,EAAE,YAAoB;QACjD,MAAM,aAAa,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9C,IAAI,MAAM,GAAQ,IAAI,CAAC;QACvB,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC3B,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CAEF;AA7ED,kCA6EC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArrayHelper = void 0;
|
|
4
|
+
var ArrayHelper_1 = require("./ArrayHelper");
|
|
5
|
+
Object.defineProperty(exports, "ArrayHelper", { enumerable: true, get: function () { return ArrayHelper_1.ArrayHelper; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAAlC,0GAAA,WAAW,OAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@churchapps/helpers",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Library of helper functions not specific to any one ChurchApps project or framework.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"clean": "rimraf dist",
|
|
9
|
+
"tsc": "tsc",
|
|
10
|
+
"build": "npm-run-all clean tsc"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/LiveChurchSolutions/Helpers.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"ChurchApps"
|
|
18
|
+
],
|
|
19
|
+
"author": "ChurchApps.org",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/LiveChurchSolutions/Helpers/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/LiveChurchSolutions/Helpers#readme",
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^20.5.6",
|
|
27
|
+
"npm-run-all": "^4.1.5",
|
|
28
|
+
"rimraf": "^5.0.1",
|
|
29
|
+
"typescript": "^5.2.2"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"date-fns": "^2.30.0",
|
|
33
|
+
"react-ga4": "^2.1.0",
|
|
34
|
+
"rrule": "^2.7.2"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/ApiHelper.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { ApiConfig, RolePermissionInterface, ApiListType } from "./interfaces";
|
|
2
|
+
import { ErrorHelper } from "./ErrorHelper";
|
|
3
|
+
|
|
4
|
+
export class ApiHelper {
|
|
5
|
+
|
|
6
|
+
static apiConfigs: ApiConfig[] = [];
|
|
7
|
+
static isAuthenticated = false;
|
|
8
|
+
|
|
9
|
+
static getConfig(keyName: string) {
|
|
10
|
+
let result: ApiConfig = null;
|
|
11
|
+
this.apiConfigs.forEach(config => { if (config.keyName === keyName) result = config });
|
|
12
|
+
//if (result === null) throw new Error("Unconfigured API: " + keyName);
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static setDefaultPermissions(jwt: string) {
|
|
17
|
+
this.apiConfigs.forEach(config => {
|
|
18
|
+
config.jwt = jwt;
|
|
19
|
+
config.permisssions = [];
|
|
20
|
+
});
|
|
21
|
+
this.isAuthenticated = true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static setPermissions(keyName: string, jwt: string, permissions: RolePermissionInterface[]) {
|
|
25
|
+
this.apiConfigs.forEach(config => {
|
|
26
|
+
if (config.keyName === keyName) {
|
|
27
|
+
config.jwt = jwt;
|
|
28
|
+
config.permisssions = permissions;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
this.isAuthenticated = true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static clearPermissions() {
|
|
35
|
+
this.apiConfigs.forEach(config => { config.jwt = ""; config.permisssions = []; });
|
|
36
|
+
this.isAuthenticated = false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static async get(path: string, apiName: ApiListType) {
|
|
40
|
+
const config = this.getConfig(apiName);
|
|
41
|
+
const requestOptions = { method: "GET", headers: { Authorization: "Bearer " + config.jwt } };
|
|
42
|
+
return await this.fetchWithErrorHandling(config.url + path, requestOptions);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static async getAnonymous(path: string, apiName: ApiListType) {
|
|
46
|
+
const config = this.getConfig(apiName);
|
|
47
|
+
const requestOptions = { method: "GET" };
|
|
48
|
+
return await this.fetchWithErrorHandling(config.url + path, requestOptions);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static async post(path: string, data: any[] | {}, apiName: ApiListType) {
|
|
52
|
+
const config = this.getConfig(apiName);
|
|
53
|
+
const requestOptions = {
|
|
54
|
+
method: "POST",
|
|
55
|
+
headers: { Authorization: "Bearer " + config.jwt, "Content-Type": "application/json" },
|
|
56
|
+
body: JSON.stringify(data)
|
|
57
|
+
};
|
|
58
|
+
return await this.fetchWithErrorHandling(config.url + path, requestOptions);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static async patch(path: string, data: any[] | {}, apiName: ApiListType) {
|
|
62
|
+
const config = this.getConfig(apiName);
|
|
63
|
+
const requestOptions = {
|
|
64
|
+
method: "PATCH",
|
|
65
|
+
headers: { Authorization: "Bearer " + config.jwt, "Content-Type": "application/json" },
|
|
66
|
+
body: JSON.stringify(data)
|
|
67
|
+
};
|
|
68
|
+
return await this.fetchWithErrorHandling(config.url + path, requestOptions);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static async delete(path: string, apiName: ApiListType) {
|
|
72
|
+
const config = this.getConfig(apiName);
|
|
73
|
+
const requestOptions = {
|
|
74
|
+
method: "DELETE",
|
|
75
|
+
headers: { Authorization: "Bearer " + config.jwt }
|
|
76
|
+
};
|
|
77
|
+
try {
|
|
78
|
+
const response = await fetch(config.url + path, requestOptions);
|
|
79
|
+
if (!response.ok) await this.throwApiError(response);
|
|
80
|
+
} catch (e) {
|
|
81
|
+
console.log(e)
|
|
82
|
+
throw (e);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static async postAnonymous(path: string, data: any[] | {}, apiName: ApiListType) {
|
|
87
|
+
const config = this.getConfig(apiName);
|
|
88
|
+
const requestOptions = {
|
|
89
|
+
method: "POST",
|
|
90
|
+
headers: { "Content-Type": "application/json" },
|
|
91
|
+
body: JSON.stringify(data)
|
|
92
|
+
};
|
|
93
|
+
console.log(config.url + path, requestOptions);
|
|
94
|
+
return await this.fetchWithErrorHandling(config.url + path, requestOptions);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static async fetchWithErrorHandling(url: string, requestOptions: any) {
|
|
98
|
+
try {
|
|
99
|
+
const response = await fetch(url, requestOptions);
|
|
100
|
+
if (!response.ok) await this.throwApiError(response);
|
|
101
|
+
else {
|
|
102
|
+
if (response.status !== 204 ) {
|
|
103
|
+
return response.json();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} catch (e) {
|
|
107
|
+
console.log("Error loading url: " + url);
|
|
108
|
+
console.log(e)
|
|
109
|
+
throw (e);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private static async throwApiError(response: Response) {
|
|
114
|
+
console.log("THROW API ERROR");
|
|
115
|
+
let msg = response.statusText;
|
|
116
|
+
try {
|
|
117
|
+
const json = await response.json();
|
|
118
|
+
msg = json.errors[0];
|
|
119
|
+
} catch { }
|
|
120
|
+
console.log("RESPONSE", response)
|
|
121
|
+
ErrorHelper.logError(response.status.toString(), response.url, msg);
|
|
122
|
+
throw new Error(msg || "Error");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
|
|
2
|
+
export interface AppearanceInterface { primaryColor?: string, primaryContrast?: string, secondaryColor?: string, secondaryContrast?: string, logoLight?: string, logoDark?: string, favicon_400x400?: string, favicon_16x16?: string }
|
|
3
|
+
|
|
4
|
+
export class AppearanceHelper {
|
|
5
|
+
|
|
6
|
+
public static getLogoDark(appearanceSettings: AppearanceInterface, defaultLogo: string) {
|
|
7
|
+
return (appearanceSettings?.logoDark) ? appearanceSettings.logoDark : defaultLogo;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public static getLogoLight(appearanceSettings: AppearanceInterface, defaultLogo: string) {
|
|
11
|
+
return (appearanceSettings?.logoLight) ? appearanceSettings.logoLight : defaultLogo;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public static getFavicon(appearanceSettings: AppearanceInterface, size: "400" | "16") {
|
|
15
|
+
if (size === "400") {
|
|
16
|
+
return appearanceSettings?.favicon_400x400;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (size === "16") {
|
|
20
|
+
return appearanceSettings?.favicon_16x16;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public static getLogo(appearanceSettings: AppearanceInterface, defaultLogoLight: string, defaultLogoDark: string, backgroundColor: string) {
|
|
27
|
+
const isDark = (appearanceSettings.logoDark) ? this.isDark(backgroundColor) : false;
|
|
28
|
+
if (isDark) return this.getLogoDark(appearanceSettings, defaultLogoDark);
|
|
29
|
+
else return this.getLogoLight(appearanceSettings, defaultLogoLight);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private static isDark(backgroundColor: string) {
|
|
33
|
+
let valid = false;
|
|
34
|
+
let r = 0;
|
|
35
|
+
let g = 0;
|
|
36
|
+
let b = 0;
|
|
37
|
+
|
|
38
|
+
if (backgroundColor.match(/#[0-9a-fA-F{6}]/)) {
|
|
39
|
+
r = this.getHexValue(backgroundColor.substring(1, 2));
|
|
40
|
+
g = this.getHexValue(backgroundColor.substring(3, 4));
|
|
41
|
+
b = this.getHexValue(backgroundColor.substring(5, 6));
|
|
42
|
+
valid = true;
|
|
43
|
+
} else if (backgroundColor.match(/#[0-9a-fA-F{3}]/)) {
|
|
44
|
+
r = this.getHexValue(backgroundColor.substring(1, 1));
|
|
45
|
+
g = this.getHexValue(backgroundColor.substring(2, 2));
|
|
46
|
+
b = this.getHexValue(backgroundColor.substring(3, 3));
|
|
47
|
+
valid = true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!valid) return false;
|
|
51
|
+
else {
|
|
52
|
+
//HSP brightness formula. Some colors have a bigger impact on our perceived brightness than others.
|
|
53
|
+
const rWeight = .299 * Math.pow(r, 2);
|
|
54
|
+
const gWeight = .587 * Math.pow(g, 2);
|
|
55
|
+
const bWeight = .114 * Math.pow(b, 2);
|
|
56
|
+
const brightness = Math.sqrt(rWeight + gWeight + bWeight);
|
|
57
|
+
//return brightness < 128; //
|
|
58
|
+
return brightness < 156;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private static getHexValue(hex: string) {
|
|
64
|
+
let result = parseInt(hex, 16);
|
|
65
|
+
if (hex.length === 1) result = result * 16;
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { UniqueIdHelper } from "./UniqueIdHelper";
|
|
2
|
+
|
|
3
|
+
export class ArrayHelper {
|
|
4
|
+
static getIds(array: any[], propertyName: string) {
|
|
5
|
+
const result: string[] = [];
|
|
6
|
+
for (const item of array) {
|
|
7
|
+
const id = item[propertyName]?.toString();
|
|
8
|
+
if (!UniqueIdHelper.isMissing(id) && result.indexOf(id) === -1) result.push(id);
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static sortBy(array: any[], propertyName: string, descending: boolean = false) {
|
|
14
|
+
array.sort((a, b) => {
|
|
15
|
+
const valA = a[propertyName];
|
|
16
|
+
const valB = b[propertyName];
|
|
17
|
+
if (valA < valB) return descending ? 1 : -1;
|
|
18
|
+
else return descending ? -1 : 1;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static getIndex(array: any[], propertyName: string, value: any) {
|
|
23
|
+
for (let i = 0; i < array.length; i++) {
|
|
24
|
+
const item = array[i];
|
|
25
|
+
if (ArrayHelper.compare(item, propertyName, value)) return i;
|
|
26
|
+
}
|
|
27
|
+
return -1;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static getOne(array: any[], propertyName: string, value: any) {
|
|
31
|
+
for (const item of array || []) if (ArrayHelper.compare(item, propertyName, value)) return item;
|
|
32
|
+
return null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static getAll(array: any[], propertyName: string, value: any) {
|
|
36
|
+
const result: any[] = []
|
|
37
|
+
for (const item of array || []) {
|
|
38
|
+
if (ArrayHelper.compare(item, propertyName, value)) result.push(item);
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static getAllArray(array: any[], propertyName: string, values: any[]) {
|
|
44
|
+
const result: any[] = []
|
|
45
|
+
for (const item of array || []) if (values.indexOf(item[propertyName]) > -1) result.push(item);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private static compare(item: any, propertyName: string, value: any) {
|
|
50
|
+
const propChain = propertyName.split(".");
|
|
51
|
+
if (propChain.length === 1) return item[propertyName] === value;
|
|
52
|
+
else {
|
|
53
|
+
let obj = item;
|
|
54
|
+
for (let i = 0; i < propChain.length - 1; i++) {
|
|
55
|
+
if (obj) obj = item[propChain[i]];
|
|
56
|
+
}
|
|
57
|
+
return obj[propChain[propChain.length - 1]] === value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static getUniqueValues(array: any[], propertyName: string) {
|
|
62
|
+
const result: any[] = [];
|
|
63
|
+
|
|
64
|
+
for (const item of array) {
|
|
65
|
+
const val = (propertyName.indexOf(".") === -1) ? item[propertyName] : this.getDeepValue(item, propertyName)
|
|
66
|
+
if (result.indexOf(val) === -1) result.push(val);
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static getDeepValue(item: any, propertyName: string) {
|
|
72
|
+
const propertyNames = propertyName.split(".");
|
|
73
|
+
let result: any = item;
|
|
74
|
+
propertyNames.forEach(name => {
|
|
75
|
+
result = result[name];
|
|
76
|
+
});
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
|
|
2
|
+
export class CommonEnvironmentHelper {
|
|
3
|
+
public static AttendanceApi = "";
|
|
4
|
+
public static DoingApi = "";
|
|
5
|
+
public static GivingApi = "";
|
|
6
|
+
public static MembershipApi = "";
|
|
7
|
+
public static ReportingApi = "";
|
|
8
|
+
public static MessagingApi = "";
|
|
9
|
+
public static MessagingApiSocket = "";
|
|
10
|
+
public static ContentApi = "";
|
|
11
|
+
public static GoogleAnalyticsTag = "";
|
|
12
|
+
|
|
13
|
+
static ContentRoot = "";
|
|
14
|
+
static B1Root = "";
|
|
15
|
+
static ChumsRoot = "";
|
|
16
|
+
static LessonsRoot = "";
|
|
17
|
+
|
|
18
|
+
static init = (stage: string) => {
|
|
19
|
+
switch (stage) {
|
|
20
|
+
case "staging": CommonEnvironmentHelper.initStaging(); break;
|
|
21
|
+
case "prod": CommonEnvironmentHelper.initProd(); break;
|
|
22
|
+
default: CommonEnvironmentHelper.initDev(); break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static initDev = () => {
|
|
27
|
+
this.initStaging(); //Use staging values for anything not provided
|
|
28
|
+
CommonEnvironmentHelper.AttendanceApi = process.env.REACT_APP_ATTENDANCE_API || process.env.NEXT_PUBLIC_ATTENDANCE_API || CommonEnvironmentHelper.AttendanceApi;
|
|
29
|
+
CommonEnvironmentHelper.DoingApi = process.env.REACT_APP_DOING_API || process.env.NEXT_PUBLIC_DOING_API || CommonEnvironmentHelper.DoingApi;
|
|
30
|
+
CommonEnvironmentHelper.GivingApi = process.env.REACT_APP_GIVING_API || process.env.NEXT_PUBLIC_GIVING_API || CommonEnvironmentHelper.GivingApi;
|
|
31
|
+
CommonEnvironmentHelper.MembershipApi = process.env.REACT_APP_MEMBERSHIP_API || process.env.NEXT_PUBLIC_MEMBERSHIP_API || CommonEnvironmentHelper.MembershipApi;
|
|
32
|
+
CommonEnvironmentHelper.ReportingApi = process.env.REACT_APP_REPORTING_API || process.env.NEXT_PUBLIC_REPORTING_API || CommonEnvironmentHelper.ReportingApi;
|
|
33
|
+
CommonEnvironmentHelper.MessagingApi = process.env.REACT_APP_MESSAGING_API || process.env.NEXT_PUBLIC_MESSAGING_API || CommonEnvironmentHelper.MessagingApi;
|
|
34
|
+
CommonEnvironmentHelper.MessagingApiSocket = process.env.REACT_APP_MESSAGING_API_SOCKET || process.env.NEXT_PUBLIC_MESSAGING_API_SOCKET || CommonEnvironmentHelper.MessagingApiSocket;
|
|
35
|
+
CommonEnvironmentHelper.ContentApi = process.env.REACT_APP_CONTENT_API || process.env.NEXT_PUBLIC_CONTENT_API || CommonEnvironmentHelper.ContentApi;
|
|
36
|
+
CommonEnvironmentHelper.GoogleAnalyticsTag = process.env.REACT_APP_GOOGLE_ANALYTICS || process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS || CommonEnvironmentHelper.GoogleAnalyticsTag;
|
|
37
|
+
|
|
38
|
+
CommonEnvironmentHelper.ContentRoot = process.env.REACT_APP_CONTENT_ROOT || process.env.NEXT_PUBLIC_CONTENT_ROOT || CommonEnvironmentHelper.ContentRoot;
|
|
39
|
+
CommonEnvironmentHelper.B1Root = process.env.REACT_APP_B1_ROOT || process.env.NEXT_PUBLIC_B1_ROOT || CommonEnvironmentHelper.B1Root;
|
|
40
|
+
CommonEnvironmentHelper.ChumsRoot = process.env.REACT_APP_CHUMS_ROOT || process.env.NEXT_PUBLIC_CHUMS_ROOT || CommonEnvironmentHelper.ChumsRoot;
|
|
41
|
+
CommonEnvironmentHelper.LessonsRoot = process.env.REACT_APP_LESSONS_ROOT || process.env.NEXT_PUBLIC_LESSONS_ROOT || CommonEnvironmentHelper.LessonsRoot;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//NOTE: None of these values are secret.
|
|
45
|
+
static initStaging = () => {
|
|
46
|
+
CommonEnvironmentHelper.AttendanceApi = "https://attendanceapi.staging.churchapps.org";
|
|
47
|
+
CommonEnvironmentHelper.DoingApi = "https://doingapi.staging.churchapps.org";
|
|
48
|
+
CommonEnvironmentHelper.GivingApi = "https://givingapi.staging.churchapps.org";
|
|
49
|
+
CommonEnvironmentHelper.MembershipApi = "https://membershipapi.staging.churchapps.org";
|
|
50
|
+
CommonEnvironmentHelper.ReportingApi = "https://reportingapi.staging.churchapps.org";
|
|
51
|
+
CommonEnvironmentHelper.MessagingApi = "https://messagingapi.staging.churchapps.org";
|
|
52
|
+
CommonEnvironmentHelper.MessagingApiSocket = "wss://socket.staging.churchapps.org";
|
|
53
|
+
CommonEnvironmentHelper.ContentApi = "https://contentapi.staging.churchapps.org";
|
|
54
|
+
CommonEnvironmentHelper.GoogleAnalyticsTag = "";
|
|
55
|
+
|
|
56
|
+
CommonEnvironmentHelper.ContentRoot = "https://content.staging.churchapps.org";
|
|
57
|
+
CommonEnvironmentHelper.B1Root = "https://{key}.staging.b1.church";
|
|
58
|
+
CommonEnvironmentHelper.ChumsRoot = "https://app.staging.chums.org";
|
|
59
|
+
CommonEnvironmentHelper.LessonsRoot = "https://staging.lessons.church";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//NOTE: None of these values are secret.
|
|
63
|
+
static initProd = () => {
|
|
64
|
+
CommonEnvironmentHelper.AttendanceApi = "https://attendanceapi.churchapps.org";
|
|
65
|
+
CommonEnvironmentHelper.DoingApi = "https://doingapi.churchapps.org";
|
|
66
|
+
CommonEnvironmentHelper.GivingApi = "https://givingapi.churchapps.org";
|
|
67
|
+
CommonEnvironmentHelper.MembershipApi = "https://membershipapi.churchapps.org";
|
|
68
|
+
CommonEnvironmentHelper.ReportingApi = "https://reportingapi.churchapps.org";
|
|
69
|
+
CommonEnvironmentHelper.MessagingApi = "https://messagingapi.churchapps.org";
|
|
70
|
+
CommonEnvironmentHelper.MessagingApiSocket = "wss://socket.churchapps.org";
|
|
71
|
+
CommonEnvironmentHelper.ContentApi = "https://contentapi.churchapps.org";
|
|
72
|
+
|
|
73
|
+
CommonEnvironmentHelper.ContentRoot = "https://content.churchapps.org";
|
|
74
|
+
CommonEnvironmentHelper.B1Root = "https://{key}.b1.church";
|
|
75
|
+
CommonEnvironmentHelper.ChumsRoot = "https://app.chums.org";
|
|
76
|
+
CommonEnvironmentHelper.LessonsRoot = "https://lessons.church";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|