@churchapps/helpers 1.2.3 → 1.2.5

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 (53) hide show
  1. package/.eslintrc.json +28 -28
  2. package/.github/FUNDING.yml +1 -1
  3. package/.prettierrc +11 -11
  4. package/.yarnrc.yml +5 -5
  5. package/LICENSE +21 -21
  6. package/README.md +15 -15
  7. package/dist/ApiHelper.d.ts.map +1 -1
  8. package/dist/ApiHelper.js +4 -10
  9. package/dist/ApiHelper.js.map +1 -1
  10. package/dist/ArrayHelper.js +2 -1
  11. package/dist/ArrayHelper.js.map +1 -1
  12. package/dist/CommonEnvironmentHelper.d.ts +1 -1
  13. package/dist/CommonEnvironmentHelper.d.ts.map +1 -1
  14. package/dist/CommonEnvironmentHelper.js +5 -5
  15. package/dist/CommonEnvironmentHelper.js.map +1 -1
  16. package/dist/DateHelper.d.ts.map +1 -1
  17. package/dist/DateHelper.js +2 -0
  18. package/dist/DateHelper.js.map +1 -1
  19. package/dist/PersonHelper.js +2 -2
  20. package/dist/PersonHelper.js.map +1 -1
  21. package/dist/UserHelper.d.ts.map +1 -1
  22. package/dist/UserHelper.js +6 -2
  23. package/dist/UserHelper.js.map +1 -1
  24. package/package.json +50 -49
  25. package/scripts/build-cjs.js +32 -32
  26. package/src/ApiHelper.ts +169 -176
  27. package/src/AppearanceHelper.ts +69 -69
  28. package/src/ArrayHelper.ts +157 -157
  29. package/src/CommonEnvironmentHelper.ts +104 -104
  30. package/src/CurrencyHelper.ts +10 -10
  31. package/src/DateHelper.ts +154 -153
  32. package/src/DonationHelper.ts +26 -26
  33. package/src/ErrorHelper.ts +39 -39
  34. package/src/EventHelper.ts +49 -49
  35. package/src/FileHelper.ts +55 -55
  36. package/src/PersonHelper.ts +82 -82
  37. package/src/UniqueIdHelper.ts +36 -36
  38. package/src/UserHelper.ts +62 -59
  39. package/src/index.ts +15 -15
  40. package/src/interfaces/Access.ts +138 -138
  41. package/src/interfaces/Attendance.ts +45 -45
  42. package/src/interfaces/Content.ts +84 -84
  43. package/src/interfaces/Doing.ts +93 -93
  44. package/src/interfaces/Donation.ts +190 -190
  45. package/src/interfaces/Error.ts +17 -17
  46. package/src/interfaces/Membership.ts +184 -184
  47. package/src/interfaces/Messaging.ts +96 -96
  48. package/src/interfaces/Permissions.ts +92 -92
  49. package/src/interfaces/Reporting.ts +41 -41
  50. package/src/interfaces/UserContextInterface.ts +13 -13
  51. package/src/interfaces/index.ts +13 -13
  52. package/tsconfig.json +36 -36
  53. package/CLAUDE.md +0 -98
@@ -1,82 +1,82 @@
1
- import { PersonInterface, ContactInfoInterface } from "./interfaces";
2
- import { CommonEnvironmentHelper } from "./CommonEnvironmentHelper";
3
-
4
- export class PersonHelper {
5
-
6
- public static getPhotoPath(churchId: string, person: any) {
7
- if (!person.photoUpdated) {
8
- if (person.id?.startsWith("PER0000")) return "https://app.staging.chums.org/images/demo/avatars/" + person.id + ".svg";
9
- else return "";
10
- }
11
- else return "/" + churchId + "/membership/people/" + person.id + ".png?dt=" + person.photoUpdated.getTime().toString();
12
- }
13
-
14
- static getPhotoUrl(person: PersonInterface) {
15
- if (!person?.photo) return "/images/sample-profile.png"
16
- else {
17
- return (person?.photo?.startsWith("data:image/png;base64,") || person.photo?.indexOf("://") > -1)
18
- ? person.photo
19
- : CommonEnvironmentHelper.ContentRoot + person.photo;
20
- }
21
- }
22
-
23
- static getAge(birthdate: Date): string {
24
- if (birthdate !== undefined && birthdate !== null) {
25
- let ageDifMs = Date.now() - new Date(birthdate).getTime();
26
- let ageDate = new Date(ageDifMs);
27
- let years = Math.abs(ageDate.getUTCFullYear() - 1970);
28
- return years + " years";
29
- }
30
- else return "";
31
- }
32
-
33
- public static getDisplayNameFromPerson(person: any) {
34
- if (person?.name?.nick !== null && person?.name?.nick !== "" && person?.name?.nick !== undefined) return person.name.first + " \"" + person.name.nick + "\" " + person.name.last;
35
- else return person.name.first + " " + person.name.last;
36
- }
37
-
38
- static getDisplayName(firstName: string, lastName: string, nickName: string): string {
39
- if (nickName !== undefined && nickName !== null && nickName.length > 0) return firstName + ' "' + nickName + '" ' + lastName;
40
- else return firstName + " " + lastName;
41
- }
42
-
43
- public static getBirthMonth(birthdate: Date): number {
44
- if (birthdate) return new Date(birthdate).getMonth() + 1;
45
- else return -1;
46
- }
47
-
48
- public static compareAddress(address1: ContactInfoInterface, address2: ContactInfoInterface): boolean {
49
- const displayAddress1: string = this.addressToString(address1).trim();
50
- const displayAddress2: string = this.addressToString(address2).trim();
51
-
52
- if (displayAddress1 !== displayAddress2) {
53
- return true
54
- }
55
- return false
56
- }
57
-
58
- public static addressToString(address: ContactInfoInterface): string {
59
- return `${address.address1 || ""} ${address.address2 || ""} ${address.city || ""}${(address.city && address.state) ? "," : ""} ${address.state || ""} ${address.zip || ""}`
60
- }
61
-
62
- public static changeOnlyAddress(contactInfo1: ContactInfoInterface, contactInfo2: ContactInfoInterface): ContactInfoInterface {
63
- const updatedAddress: ContactInfoInterface = {
64
- ...contactInfo1,
65
- address1: contactInfo2.address1,
66
- address2: contactInfo2.address2,
67
- city: contactInfo2.city,
68
- state: contactInfo2.state,
69
- zip: contactInfo2.zip
70
- }
71
-
72
- return updatedAddress
73
- }
74
-
75
- public static checkAddressAvailabilty(person: PersonInterface): boolean {
76
- const addressString: string = this.addressToString(person.contactInfo).trim();
77
- if (addressString !== "") {
78
- return true;
79
- }
80
- return false;
81
- }
82
- }
1
+ import { PersonInterface, ContactInfoInterface } from "./interfaces";
2
+ import { CommonEnvironmentHelper } from "./CommonEnvironmentHelper";
3
+
4
+ export class PersonHelper {
5
+
6
+ public static getPhotoPath(churchId: string, person: any) {
7
+ if (!person.photoUpdated) {
8
+ if (person.id?.startsWith("PER0000")) return "https://app.staging.b1.church/images/demo/avatars/" + person.id + ".svg";
9
+ else return "";
10
+ }
11
+ else return "/" + churchId + "/membership/people/" + person.id + ".png?dt=" + new Date(person.photoUpdated).getTime().toString();
12
+ }
13
+
14
+ static getPhotoUrl(person: PersonInterface) {
15
+ if (!person?.photo) return "/images/sample-profile.png"
16
+ else {
17
+ return (person?.photo?.startsWith("data:image/png;base64,") || person.photo?.indexOf("://") > -1)
18
+ ? person.photo
19
+ : CommonEnvironmentHelper.ContentRoot + person.photo;
20
+ }
21
+ }
22
+
23
+ static getAge(birthdate: Date): string {
24
+ if (birthdate !== undefined && birthdate !== null) {
25
+ let ageDifMs = Date.now() - new Date(birthdate).getTime();
26
+ let ageDate = new Date(ageDifMs);
27
+ let years = Math.abs(ageDate.getUTCFullYear() - 1970);
28
+ return years + " years";
29
+ }
30
+ else return "";
31
+ }
32
+
33
+ public static getDisplayNameFromPerson(person: any) {
34
+ if (person?.name?.nick !== null && person?.name?.nick !== "" && person?.name?.nick !== undefined) return person.name.first + " \"" + person.name.nick + "\" " + person.name.last;
35
+ else return person.name.first + " " + person.name.last;
36
+ }
37
+
38
+ static getDisplayName(firstName: string, lastName: string, nickName: string): string {
39
+ if (nickName !== undefined && nickName !== null && nickName.length > 0) return firstName + ' "' + nickName + '" ' + lastName;
40
+ else return firstName + " " + lastName;
41
+ }
42
+
43
+ public static getBirthMonth(birthdate: Date): number {
44
+ if (birthdate) return new Date(birthdate).getMonth() + 1;
45
+ else return -1;
46
+ }
47
+
48
+ public static compareAddress(address1: ContactInfoInterface, address2: ContactInfoInterface): boolean {
49
+ const displayAddress1: string = this.addressToString(address1).trim();
50
+ const displayAddress2: string = this.addressToString(address2).trim();
51
+
52
+ if (displayAddress1 !== displayAddress2) {
53
+ return true
54
+ }
55
+ return false
56
+ }
57
+
58
+ public static addressToString(address: ContactInfoInterface): string {
59
+ return `${address.address1 || ""} ${address.address2 || ""} ${address.city || ""}${(address.city && address.state) ? "," : ""} ${address.state || ""} ${address.zip || ""}`
60
+ }
61
+
62
+ public static changeOnlyAddress(contactInfo1: ContactInfoInterface, contactInfo2: ContactInfoInterface): ContactInfoInterface {
63
+ const updatedAddress: ContactInfoInterface = {
64
+ ...contactInfo1,
65
+ address1: contactInfo2.address1,
66
+ address2: contactInfo2.address2,
67
+ city: contactInfo2.city,
68
+ state: contactInfo2.state,
69
+ zip: contactInfo2.zip
70
+ }
71
+
72
+ return updatedAddress
73
+ }
74
+
75
+ public static checkAddressAvailabilty(person: PersonInterface): boolean {
76
+ const addressString: string = this.addressToString(person.contactInfo).trim();
77
+ if (addressString !== "") {
78
+ return true;
79
+ }
80
+ return false;
81
+ }
82
+ }
@@ -1,36 +1,36 @@
1
- export class UniqueIdHelper {
2
-
3
- static chars = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
4
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
5
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
6
- "-", "_"];
7
-
8
- static alphanumericChars = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
9
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
10
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
11
-
12
- public static isMissing(obj: any) {
13
- if (obj === undefined || obj === null) return true;
14
- else if (obj.toString() === "") return true;
15
- else return false;
16
- }
17
-
18
- public static shortId() {
19
- return this.generate(UniqueIdHelper.chars, 11);
20
- }
21
-
22
- public static generateAlphanumeric() {
23
- return this.generate(UniqueIdHelper.alphanumericChars, 11);
24
- }
25
-
26
- public static generate(charList: string[], length: number) {
27
- let result = "";
28
- for (let i = 0; i < length; i++) {
29
- const idx = Math.floor(Math.random() * charList.length);
30
- const c = charList[idx];
31
- result += c;
32
- }
33
- return result;
34
- }
35
-
36
- }
1
+ export class UniqueIdHelper {
2
+
3
+ static chars = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
4
+ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
5
+ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
6
+ "-", "_"];
7
+
8
+ static alphanumericChars = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
9
+ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
10
+ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
11
+
12
+ public static isMissing(obj: any) {
13
+ if (obj === undefined || obj === null) return true;
14
+ else if (obj.toString() === "") return true;
15
+ else return false;
16
+ }
17
+
18
+ public static shortId() {
19
+ return this.generate(UniqueIdHelper.chars, 11);
20
+ }
21
+
22
+ public static generateAlphanumeric() {
23
+ return this.generate(UniqueIdHelper.alphanumericChars, 11);
24
+ }
25
+
26
+ public static generate(charList: string[], length: number) {
27
+ let result = "";
28
+ for (let i = 0; i < length; i++) {
29
+ const idx = Math.floor(Math.random() * charList.length);
30
+ const c = charList[idx];
31
+ result += c;
32
+ }
33
+ return result;
34
+ }
35
+
36
+ }
package/src/UserHelper.ts CHANGED
@@ -1,59 +1,62 @@
1
- import { ApiHelper } from "./ApiHelper"
2
- import { UserInterface, UserContextInterface, IApiPermission, PersonInterface, LoginUserChurchInterface } from "./interfaces";
3
-
4
- export class UserHelper {
5
- static currentUserChurch: LoginUserChurchInterface;
6
- static userChurches: LoginUserChurchInterface[];
7
- static user: UserInterface;
8
- static churchChanged: boolean = false;
9
- static person: PersonInterface;
10
-
11
- static selectChurch = async (context?: UserContextInterface, churchId?: string, keyName?: string) => {
12
- let userChurch = null;
13
-
14
- if (churchId) {
15
- UserHelper.userChurches.forEach(uc => {
16
- if (uc.church.id === churchId) userChurch = uc;
17
- });
18
- }
19
- else if (keyName) UserHelper.userChurches.forEach(uc => { if (uc.church.subDomain === keyName) userChurch = uc; });
20
- else userChurch = UserHelper.userChurches[0];
21
- if (!userChurch) return;
22
- else {
23
- UserHelper.currentUserChurch = userChurch;
24
- UserHelper.setupApiHelper(UserHelper.currentUserChurch);
25
- // TODO - remove context code from here and perform the logic in the component itself.
26
- if (context) {
27
- if (context.userChurch !== null) UserHelper.churchChanged = true;
28
- context.setUserChurch(UserHelper.currentUserChurch);
29
- }
30
- }
31
- }
32
-
33
- static setupApiHelper(userChurch: LoginUserChurchInterface) {
34
- ApiHelper.setDefaultPermissions(userChurch.jwt);
35
- userChurch.apis.forEach(api => { ApiHelper.setPermissions(api.keyName, api.jwt, api.permissions); });
36
- }
37
-
38
- static setupApiHelperNoChurch(user: LoginUserChurchInterface) {
39
- ApiHelper.setDefaultPermissions(user.jwt);
40
- }
41
-
42
- static checkAccess({ api, contentType, action }: IApiPermission): boolean {
43
- const permissions = ApiHelper.getConfig(api).permissions;
44
-
45
- let result = false;
46
- if (permissions !== undefined) {
47
- permissions.forEach(element => {
48
- if (element.contentType === contentType && element.action === action) result = true;
49
- });
50
- }
51
- return result;
52
- }
53
-
54
- static createAppUrl(appUrl: string, returnUrl: string) {
55
- const jwt = ApiHelper.getConfig("MembershipApi").jwt;
56
-
57
- return `${appUrl}/login/?jwt=${jwt}&returnUrl=${returnUrl}`;
58
- }
59
- }
1
+ import { ApiHelper } from "./ApiHelper"
2
+ import { UserInterface, UserContextInterface, IApiPermission, PersonInterface, LoginUserChurchInterface } from "./interfaces";
3
+
4
+ export class UserHelper {
5
+ static currentUserChurch: LoginUserChurchInterface;
6
+ static userChurches: LoginUserChurchInterface[];
7
+ static user: UserInterface;
8
+ static churchChanged: boolean = false;
9
+ static person: PersonInterface;
10
+
11
+ static selectChurch = async (context?: UserContextInterface, churchId?: string, keyName?: string) => {
12
+ let userChurch = null;
13
+
14
+ if (churchId) {
15
+ UserHelper.userChurches.forEach(uc => {
16
+ if (uc.church.id === churchId) userChurch = uc;
17
+ });
18
+ }
19
+ else if (keyName) UserHelper.userChurches.forEach(uc => { if (uc.church.subDomain === keyName) userChurch = uc; });
20
+ else userChurch = UserHelper.userChurches[0];
21
+ if (!userChurch) return;
22
+ else {
23
+ UserHelper.currentUserChurch = userChurch;
24
+ UserHelper.setupApiHelper(UserHelper.currentUserChurch);
25
+ // TODO - remove context code from here and perform the logic in the component itself.
26
+ if (context) {
27
+ if (context.userChurch !== null) UserHelper.churchChanged = true;
28
+ context.setUserChurch(UserHelper.currentUserChurch);
29
+ }
30
+ }
31
+ }
32
+
33
+ static setupApiHelper(userChurch: LoginUserChurchInterface) {
34
+ ApiHelper.setDefaultPermissions(userChurch.jwt);
35
+ userChurch.apis.forEach(api => { ApiHelper.setPermissions(api.keyName, api.jwt, api.permissions); });
36
+ }
37
+
38
+ static setupApiHelperNoChurch(user: LoginUserChurchInterface) {
39
+ ApiHelper.setDefaultPermissions(user.jwt);
40
+ }
41
+
42
+ static checkAccess({ api, contentType, action }: IApiPermission): boolean {
43
+ const config = ApiHelper.getConfig(api);
44
+ if (!config) return false;
45
+ const permissions = config.permissions;
46
+
47
+ let result = false;
48
+ if (permissions !== undefined) {
49
+ permissions.forEach(element => {
50
+ if (element.contentType === contentType && element.action === action) result = true;
51
+ });
52
+ }
53
+ return result;
54
+ }
55
+
56
+ static createAppUrl(appUrl: string, returnUrl: string) {
57
+ const config = ApiHelper.getConfig("MembershipApi");
58
+ const jwt = config?.jwt || "";
59
+
60
+ return `${appUrl}/login/?jwt=${jwt}&returnUrl=${returnUrl}`;
61
+ }
62
+ }
package/src/index.ts CHANGED
@@ -1,15 +1,15 @@
1
- export * from "./interfaces";
2
- export { ApiHelper } from "./ApiHelper";
3
- export { AppearanceHelper } from "./AppearanceHelper";
4
- export { ArrayHelper } from "./ArrayHelper";
5
- export { CommonEnvironmentHelper } from "./CommonEnvironmentHelper";
6
- export { CurrencyHelper } from "./CurrencyHelper";
7
- export { DateHelper } from "./DateHelper";
8
- export { DonationHelper } from "./DonationHelper";
9
- export { ErrorHelper } from "./ErrorHelper";
10
- export { EventHelper } from "./EventHelper";
11
- export { FileHelper } from "./FileHelper";
12
- export { PersonHelper } from "./PersonHelper";
13
- export { UserHelper } from "./UserHelper";
14
- export { UniqueIdHelper } from "./UniqueIdHelper";
15
-
1
+ export * from "./interfaces";
2
+ export { ApiHelper } from "./ApiHelper";
3
+ export { AppearanceHelper } from "./AppearanceHelper";
4
+ export { ArrayHelper } from "./ArrayHelper";
5
+ export { CommonEnvironmentHelper } from "./CommonEnvironmentHelper";
6
+ export { CurrencyHelper } from "./CurrencyHelper";
7
+ export { DateHelper } from "./DateHelper";
8
+ export { DonationHelper } from "./DonationHelper";
9
+ export { ErrorHelper } from "./ErrorHelper";
10
+ export { EventHelper } from "./EventHelper";
11
+ export { FileHelper } from "./FileHelper";
12
+ export { PersonHelper } from "./PersonHelper";
13
+ export { UserHelper } from "./UserHelper";
14
+ export { UniqueIdHelper } from "./UniqueIdHelper";
15
+