@churchapps/helpers 1.2.23 → 1.2.25

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 (80) hide show
  1. package/dist/ApiHelper.js +4 -4
  2. package/dist/ApiHelper.js.map +1 -1
  3. package/dist/ArrayHelper.d.ts.map +1 -1
  4. package/dist/ArrayHelper.js.map +1 -1
  5. package/dist/CommonEnvironmentHelper.d.ts.map +1 -1
  6. package/dist/CommonEnvironmentHelper.js.map +1 -1
  7. package/dist/CurrencyHelper.js +3 -3
  8. package/dist/DateHelper.d.ts.map +1 -1
  9. package/dist/DateHelper.js +22 -22
  10. package/dist/DateHelper.js.map +1 -1
  11. package/dist/DonationHelper.d.ts.map +1 -1
  12. package/dist/DonationHelper.js +2 -2
  13. package/dist/DonationHelper.js.map +1 -1
  14. package/dist/ErrorHelper.d.ts.map +1 -1
  15. package/dist/ErrorHelper.js.map +1 -1
  16. package/dist/EventHelper.d.ts.map +1 -1
  17. package/dist/EventHelper.js +1 -1
  18. package/dist/EventHelper.js.map +1 -1
  19. package/dist/FileHelper.d.ts.map +1 -1
  20. package/dist/FileHelper.js +11 -9
  21. package/dist/FileHelper.js.map +1 -1
  22. package/dist/PersonHelper.d.ts.map +1 -1
  23. package/dist/PersonHelper.js +3 -3
  24. package/dist/PersonHelper.js.map +1 -1
  25. package/dist/PlanHelper.d.ts.map +1 -1
  26. package/dist/PlanHelper.js +1 -3
  27. package/dist/PlanHelper.js.map +1 -1
  28. package/dist/UniqueIdHelper.d.ts.map +1 -1
  29. package/dist/UniqueIdHelper.js +130 -7
  30. package/dist/UniqueIdHelper.js.map +1 -1
  31. package/dist/UserHelper.d.ts.map +1 -1
  32. package/dist/UserHelper.js.map +1 -1
  33. package/dist/contentProviders/LessonsContentProvider.d.ts.map +1 -1
  34. package/dist/contentProviders/LessonsContentProvider.js.map +1 -1
  35. package/dist/interfaces/Doing.d.ts +3 -0
  36. package/dist/interfaces/Doing.d.ts.map +1 -1
  37. package/dist/interfaces/Messaging.d.ts +21 -0
  38. package/dist/interfaces/Messaging.d.ts.map +1 -1
  39. package/dist/interfaces/Permissions.d.ts +9 -0
  40. package/dist/interfaces/Permissions.d.ts.map +1 -1
  41. package/dist/interfaces/Permissions.js +12 -21
  42. package/dist/interfaces/Permissions.js.map +1 -1
  43. package/package.json +13 -11
  44. package/.eslintrc.json +0 -29
  45. package/.github/FUNDING.yml +0 -1
  46. package/.prettierrc +0 -12
  47. package/.yarnrc.yml +0 -6
  48. package/scripts/build-cjs.js +0 -33
  49. package/src/ApiHelper.ts +0 -169
  50. package/src/AppearanceHelper.ts +0 -69
  51. package/src/ArrayHelper.ts +0 -157
  52. package/src/CommonEnvironmentHelper.ts +0 -104
  53. package/src/CurrencyHelper.ts +0 -66
  54. package/src/DateHelper.ts +0 -183
  55. package/src/DonationHelper.ts +0 -26
  56. package/src/ErrorHelper.ts +0 -39
  57. package/src/EventHelper.ts +0 -84
  58. package/src/FileHelper.ts +0 -55
  59. package/src/PersonHelper.ts +0 -82
  60. package/src/PlanHelper.ts +0 -137
  61. package/src/UniqueIdHelper.ts +0 -36
  62. package/src/UserHelper.ts +0 -62
  63. package/src/contentProviders/ContentProvider.ts +0 -15
  64. package/src/contentProviders/LessonsContentProvider.ts +0 -279
  65. package/src/contentProviders/index.ts +0 -2
  66. package/src/index.ts +0 -16
  67. package/src/interfaces/Access.ts +0 -138
  68. package/src/interfaces/Attendance.ts +0 -45
  69. package/src/interfaces/Content.ts +0 -84
  70. package/src/interfaces/Doing.ts +0 -139
  71. package/src/interfaces/Donation.ts +0 -193
  72. package/src/interfaces/Error.ts +0 -17
  73. package/src/interfaces/Lessons.ts +0 -61
  74. package/src/interfaces/Membership.ts +0 -184
  75. package/src/interfaces/Messaging.ts +0 -96
  76. package/src/interfaces/Permissions.ts +0 -92
  77. package/src/interfaces/Reporting.ts +0 -41
  78. package/src/interfaces/UserContextInterface.ts +0 -13
  79. package/src/interfaces/index.ts +0 -14
  80. package/tsconfig.json +0 -36
package/src/ApiHelper.ts DELETED
@@ -1,169 +0,0 @@
1
- import { ApiConfig, RolePermissionInterface, ApiListType } from "./interfaces/index.js";
2
- import { ErrorHelper } from "./ErrorHelper.js";
3
-
4
- // Global singleton pattern to ensure single instance across all packages
5
- declare global {
6
- interface Window {
7
- __CHURCHAPPS_API_HELPER__?: ApiHelperClass;
8
- }
9
- var __CHURCHAPPS_API_HELPER__: ApiHelperClass | undefined;
10
- }
11
-
12
- class ApiHelperClass {
13
-
14
- apiConfigs: ApiConfig[] = [];
15
- isAuthenticated = false;
16
- onRequest: (url:string, requestOptions:any) => void;
17
- onError: (url:string, requestOptions:any, error: any) => void;
18
-
19
- getConfig(keyName: string) {
20
- let result: ApiConfig = null;
21
- this.apiConfigs.forEach(config => { if (config.keyName === keyName) result = config });
22
- //if (result === null) throw new Error("Unconfigured API: " + keyName);
23
- return result;
24
- }
25
-
26
- setDefaultPermissions(jwt: string) {
27
- this.apiConfigs.forEach(config => {
28
- config.jwt = jwt;
29
- config.permissions = [];
30
- });
31
- this.isAuthenticated = true;
32
- }
33
-
34
- setPermissions(keyName: string, jwt: string, permissions: RolePermissionInterface[]) {
35
- this.apiConfigs.forEach(config => {
36
- if (config.keyName === keyName) {
37
- config.jwt = jwt;
38
- config.permissions = permissions;
39
- }
40
- });
41
- this.isAuthenticated = true;
42
- }
43
-
44
- clearPermissions() {
45
- this.apiConfigs.forEach(config => { config.jwt = ""; config.permissions = []; });
46
- this.isAuthenticated = false;
47
- }
48
-
49
- async get(path: string, apiName: ApiListType) {
50
- const config = this.getConfig(apiName);
51
- if (!config) throw new Error(`API configuration not found: ${apiName}`);
52
- const requestOptions = { method: "GET", headers: { Authorization: "Bearer " + config.jwt } };
53
- return await this.fetchWithErrorHandling(config.url + path, requestOptions);
54
- }
55
-
56
- async getAnonymous(path: string, apiName: ApiListType) {
57
- const config = this.getConfig(apiName);
58
- if (!config) throw new Error(`API configuration not found: ${apiName}`);
59
- const requestOptions = { method: "GET" };
60
- return await this.fetchWithErrorHandling(config.url + path, requestOptions);
61
- }
62
-
63
- async post(path: string, data: any[] | {}, apiName: ApiListType) {
64
- const config = this.getConfig(apiName);
65
- if (!config) throw new Error(`API configuration not found: ${apiName}`);
66
- const requestOptions = {
67
- method: "POST",
68
- headers: { Authorization: "Bearer " + config.jwt, "Content-Type": "application/json" },
69
- body: JSON.stringify(data)
70
- };
71
- return await this.fetchWithErrorHandling(config.url + path, requestOptions);
72
- }
73
-
74
- async patch(path: string, data: any[] | {}, apiName: ApiListType) {
75
- const config = this.getConfig(apiName);
76
- if (!config) throw new Error(`API configuration not found: ${apiName}`);
77
- const requestOptions = {
78
- method: "PATCH",
79
- headers: { Authorization: "Bearer " + config.jwt, "Content-Type": "application/json" },
80
- body: JSON.stringify(data)
81
- };
82
- return await this.fetchWithErrorHandling(config.url + path, requestOptions);
83
- }
84
-
85
- async delete(path: string, apiName: ApiListType) {
86
- const config = this.getConfig(apiName);
87
- if (!config) throw new Error(`API configuration not found: ${apiName}`);
88
- const requestOptions = {
89
- method: "DELETE",
90
- headers: { Authorization: "Bearer " + config.jwt }
91
- };
92
- if (this.onRequest) this.onRequest(config.url + path, requestOptions);
93
- try {
94
- const response = await fetch(config.url + path, requestOptions);
95
- if (!response.ok) await this.throwApiError(response);
96
- } catch (e) {
97
- if (this.onError) this.onError(config.url + path, requestOptions, e);
98
- throw (e);
99
- }
100
- }
101
-
102
- async postAnonymous(path: string, data: any[] | {}, apiName: ApiListType) {
103
- const config = this.getConfig(apiName);
104
- if (!config) throw new Error(`API configuration not found: ${apiName}`);
105
- const requestOptions = {
106
- method: "POST",
107
- headers: { "Content-Type": "application/json" },
108
- body: JSON.stringify(data)
109
- };
110
- return await this.fetchWithErrorHandling(config.url + path, requestOptions);
111
- }
112
-
113
- async fetchWithErrorHandling(url: string, requestOptions: any) {
114
- if (this.onRequest) this.onRequest(url, requestOptions);
115
- try {
116
- const response = await fetch(url, requestOptions);
117
- if (!response.ok) await this.throwApiError(response);
118
- else {
119
- if (response.status !== 204 ) {
120
- return response.json();
121
- }
122
- }
123
- } catch (e) {
124
- throw (e);
125
- }
126
- }
127
-
128
- private async throwApiError(response: Response) {
129
- let msg = response.statusText;
130
- try {
131
- msg = await response.text();
132
- } catch {}
133
- try {
134
- const json = await response.json();
135
- msg = json.errors[0];
136
- } catch { }
137
- ErrorHelper.logError(response.status.toString(), response.url, msg);
138
- throw new Error(msg || "Error");
139
- }
140
-
141
- }
142
-
143
- // Force singleton with immediate global assignment
144
- const getGlobalObject = () => {
145
- if (typeof window !== 'undefined') return window;
146
- if (typeof global !== 'undefined') return global;
147
- if (typeof globalThis !== 'undefined') return globalThis;
148
- return {};
149
- };
150
-
151
- // Get or create singleton immediately - FORCE SINGLE INSTANCE
152
- const ensureSingleton = () => {
153
- const globalObj = getGlobalObject() as any;
154
-
155
- // Use a more unique key to avoid conflicts
156
- const SINGLETON_KEY = '__CHURCHAPPS_API_HELPER_SINGLETON__';
157
-
158
- if (!globalObj[SINGLETON_KEY]) {
159
- globalObj[SINGLETON_KEY] = new ApiHelperClass();
160
- }
161
-
162
- return globalObj[SINGLETON_KEY];
163
- };
164
-
165
- // Export the singleton instance
166
- export const ApiHelper = ensureSingleton();
167
-
168
- // Also export the class for type usage
169
- export type { ApiHelperClass };
@@ -1,69 +0,0 @@
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 null;
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, 3));
40
- g = this.getHexValue(backgroundColor.substring(3, 5));
41
- b = this.getHexValue(backgroundColor.substring(5, 7));
42
- valid = true;
43
- } else if (backgroundColor.match(/#[0-9a-fA-F]{3}/)) {
44
- r = this.getHexValue(backgroundColor.substring(1, 2));
45
- g = this.getHexValue(backgroundColor.substring(2, 3));
46
- b = this.getHexValue(backgroundColor.substring(3, 4));
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
- }
@@ -1,157 +0,0 @@
1
- import { UniqueIdHelper } from "./UniqueIdHelper.js";
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[propChain[i]] !== undefined) obj = obj[propChain[i]];
56
- else return false;
57
- }
58
- return obj[propChain[propChain.length - 1]] === value;
59
- }
60
- }
61
-
62
- static getUniqueValues(array: any[], propertyName: string) {
63
- const result: any[] = [];
64
-
65
- for (const item of array) {
66
- const val = (propertyName.indexOf(".") === -1) ? item[propertyName] : this.getDeepValue(item, propertyName)
67
- if (result.indexOf(val) === -1) result.push(val);
68
- }
69
- return result;
70
- }
71
-
72
- static getUnique(array: any[]) {
73
- const result: any[] = []
74
- const jsonList: string[] = [];
75
- for (const item of array) {
76
- const json = JSON.stringify(item);
77
- if (jsonList.indexOf(json) === -1) {
78
- result.push(item);
79
- jsonList.push(json);
80
- }
81
- }
82
- return result;
83
- }
84
-
85
- static getAllOperatorArray(array: any[], propertyName: string, values: any[], operator: string, dataType = "string") {
86
- const result: any[] = [];
87
- values.forEach(v => {
88
- const filtered = this.getAllOperator(array, propertyName, v, operator.replace("notIn", "notEqual").replace("in", "equals").replace("donatedToAny", "equals").replace("donatedTo", "equals").replace("attendedCampus", "equals").replace("attendedAny", "equals").replace("attendedServiceTime", "equals").replace("attendedService", "equals").replace("attendedGroup", "equals"), dataType);
89
- filtered.forEach(f => result.push(f));
90
- })
91
- return result;
92
- }
93
-
94
- static getAllOperator(array: any[], propertyName: string, value: any, operator: string, dataType = "string") {
95
- const result: any[] = []
96
- for (const item of array) {
97
-
98
-
99
- let propVal = item[propertyName] || "";
100
- let compVal = value || "";
101
- if (dataType === "number") {
102
- propVal = parseFloat(propVal);
103
- compVal = parseFloat(compVal);
104
- } else if (dataType === "string") {
105
- propVal = propVal.toLowerCase();
106
- compVal = compVal.toLowerCase();
107
- }
108
-
109
- switch (operator) {
110
- case "equals":
111
- if (propVal === compVal) result.push(item);
112
- break;
113
- case "startsWith":
114
- if (propVal.indexOf(compVal) === 0) result.push(item);
115
- break;
116
- case "endsWith":
117
- if (propVal.indexOf(compVal) === propVal.length - compVal.length) result.push(item);
118
- break;
119
- case "contains":
120
- if (propVal.indexOf(compVal) > -1) result.push(item);
121
- break;
122
- case "greaterThan":
123
- if (propVal > compVal) result.push(item);
124
- break;
125
- case "greaterThanEqual":
126
- if (propVal >= compVal) result.push(item);
127
- break;
128
- case "lessThan":
129
- if (propVal < compVal) result.push(item);
130
- break;
131
- case "lessThanEqual":
132
- if (propVal <= compVal) result.push(item);
133
- break;
134
- case "notEqual":
135
- if (propVal !== compVal) result.push(item);
136
- break;
137
- }
138
- }
139
- return result;
140
- }
141
-
142
- static getDeepValue(item: any, propertyName: string) {
143
- const propertyNames = propertyName.split(".");
144
- let result: any = item;
145
- propertyNames.forEach(name => {
146
- if (result != null) result = result[name];
147
- });
148
- return result;
149
- }
150
-
151
- static fillArray(contents: string, length: number) {
152
- const result = [];
153
- for (let i = 0; i < length; i++) result.push(contents);
154
- return result;
155
- }
156
-
157
- }
@@ -1,104 +0,0 @@
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 AskApi = "";
12
- public static GoogleAnalyticsTag = "";
13
-
14
- static ContentRoot = "";
15
- static B1Root = "";
16
- static B1AdminRoot = "";
17
- static LessonsRoot = "";
18
-
19
- static init = (stage: string) => {
20
- switch (stage) {
21
- case "demo": CommonEnvironmentHelper.initDemo(); break;
22
- case "staging": CommonEnvironmentHelper.initStaging(); break;
23
- case "prod": CommonEnvironmentHelper.initProd(); break;
24
- default: CommonEnvironmentHelper.initDev(); break;
25
- }
26
- }
27
-
28
- static initDev = () => {
29
- this.initStaging(); //Use staging values for anything not provided
30
- CommonEnvironmentHelper.AttendanceApi = process.env.REACT_APP_ATTENDANCE_API || process.env.NEXT_PUBLIC_ATTENDANCE_API || CommonEnvironmentHelper.AttendanceApi;
31
- CommonEnvironmentHelper.DoingApi = process.env.REACT_APP_DOING_API || process.env.NEXT_PUBLIC_DOING_API || CommonEnvironmentHelper.DoingApi;
32
- CommonEnvironmentHelper.GivingApi = process.env.REACT_APP_GIVING_API || process.env.NEXT_PUBLIC_GIVING_API || CommonEnvironmentHelper.GivingApi;
33
- CommonEnvironmentHelper.MembershipApi = process.env.REACT_APP_MEMBERSHIP_API || process.env.NEXT_PUBLIC_MEMBERSHIP_API || CommonEnvironmentHelper.MembershipApi;
34
- CommonEnvironmentHelper.ReportingApi = process.env.REACT_APP_REPORTING_API || process.env.NEXT_PUBLIC_REPORTING_API || CommonEnvironmentHelper.ReportingApi;
35
- CommonEnvironmentHelper.MessagingApi = process.env.REACT_APP_MESSAGING_API || process.env.NEXT_PUBLIC_MESSAGING_API || CommonEnvironmentHelper.MessagingApi;
36
- CommonEnvironmentHelper.MessagingApiSocket = process.env.REACT_APP_MESSAGING_API_SOCKET || process.env.NEXT_PUBLIC_MESSAGING_API_SOCKET || CommonEnvironmentHelper.MessagingApiSocket;
37
- CommonEnvironmentHelper.ContentApi = process.env.REACT_APP_CONTENT_API || process.env.NEXT_PUBLIC_CONTENT_API || CommonEnvironmentHelper.ContentApi;
38
- CommonEnvironmentHelper.AskApi = process.env.REACT_APP_ASK_API || process.env.NEXT_PUBLIC_ASK_API || CommonEnvironmentHelper.AskApi;
39
- CommonEnvironmentHelper.GoogleAnalyticsTag = process.env.REACT_APP_GOOGLE_ANALYTICS || process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS || CommonEnvironmentHelper.GoogleAnalyticsTag;
40
-
41
- CommonEnvironmentHelper.ContentRoot = process.env.REACT_APP_CONTENT_ROOT || process.env.NEXT_PUBLIC_CONTENT_ROOT || CommonEnvironmentHelper.ContentRoot;
42
- CommonEnvironmentHelper.B1Root = process.env.REACT_APP_B1_ROOT || process.env.NEXT_PUBLIC_B1_ROOT || CommonEnvironmentHelper.B1Root;
43
- CommonEnvironmentHelper.B1AdminRoot = process.env.REACT_APP_B1ADMIN_ROOT || process.env.NEXT_PUBLIC_B1ADMIN_ROOT || CommonEnvironmentHelper.B1AdminRoot;
44
- CommonEnvironmentHelper.LessonsRoot = process.env.REACT_APP_LESSONS_ROOT || process.env.NEXT_PUBLIC_LESSONS_ROOT || CommonEnvironmentHelper.LessonsRoot;
45
- }
46
-
47
- //NOTE: None of these values are secret.
48
- static initDemo = () => {
49
- CommonEnvironmentHelper.AttendanceApi = "https://api.demo.churchapps.org/attendance";
50
- CommonEnvironmentHelper.DoingApi = "https://api.demo.churchapps.org/doing";
51
- CommonEnvironmentHelper.GivingApi = "https://api.demo.churchapps.org/giving";
52
- CommonEnvironmentHelper.MembershipApi = "https://api.demo.churchapps.org/membership";
53
- CommonEnvironmentHelper.ReportingApi = "https://api.demo.churchapps.org/reporting";
54
- CommonEnvironmentHelper.MessagingApi = "https://api.demo.churchapps.org/messaging";
55
- CommonEnvironmentHelper.MessagingApiSocket = "wss://socket.demo.churchapps.org";
56
- CommonEnvironmentHelper.ContentApi = "https://api.demo.churchapps.org/content";
57
- CommonEnvironmentHelper.AskApi = "https://askapi.demo.churchapps.org";
58
- CommonEnvironmentHelper.GoogleAnalyticsTag = "";
59
-
60
- CommonEnvironmentHelper.ContentRoot = "https://democontent.churchapps.org";
61
- CommonEnvironmentHelper.B1Root = "https://{key}.demo.b1.church";
62
- CommonEnvironmentHelper.B1AdminRoot = "https://demo.b1.church";
63
- CommonEnvironmentHelper.LessonsRoot = "https://demo.lessons.church";
64
- }
65
-
66
- //NOTE: None of these values are secret.
67
- static initStaging = () => {
68
- CommonEnvironmentHelper.AttendanceApi = "https://api.staging.churchapps.org/attendance";
69
- CommonEnvironmentHelper.DoingApi = "https://api.staging.churchapps.org/doing";
70
- CommonEnvironmentHelper.GivingApi = "https://api.staging.churchapps.org/giving";
71
- CommonEnvironmentHelper.MembershipApi = "https://api.staging.churchapps.org/membership";
72
- CommonEnvironmentHelper.ReportingApi = "https://api.staging.churchapps.org/reporting";
73
- CommonEnvironmentHelper.MessagingApi = "https://api.staging.churchapps.org/messaging";
74
- CommonEnvironmentHelper.MessagingApiSocket = "wss://socket.staging.churchapps.org";
75
- CommonEnvironmentHelper.ContentApi = "https://api.staging.churchapps.org/content";
76
- CommonEnvironmentHelper.AskApi = "https://askapi.staging.churchapps.org";
77
- CommonEnvironmentHelper.GoogleAnalyticsTag = "";
78
-
79
- CommonEnvironmentHelper.ContentRoot = "https://content.staging.churchapps.org";
80
- CommonEnvironmentHelper.B1Root = "https://{key}.staging.b1.church";
81
- CommonEnvironmentHelper.B1AdminRoot = "https://admin.staging.b1.church";
82
- CommonEnvironmentHelper.LessonsRoot = "https://staging.lessons.church";
83
- }
84
-
85
- //NOTE: None of these values are secret.
86
- static initProd = () => {
87
- CommonEnvironmentHelper.AttendanceApi = "https://api.churchapps.org/attendance";
88
- CommonEnvironmentHelper.DoingApi = "https://api.churchapps.org/doing";
89
- CommonEnvironmentHelper.GivingApi = "https://api.churchapps.org/giving";
90
- CommonEnvironmentHelper.MembershipApi = "https://api.churchapps.org/membership";
91
- CommonEnvironmentHelper.ReportingApi = "https://api.churchapps.org/reporting";
92
- CommonEnvironmentHelper.MessagingApi = "https://api.churchapps.org/messaging";
93
- CommonEnvironmentHelper.MessagingApiSocket = "wss://socket.churchapps.org";
94
- CommonEnvironmentHelper.ContentApi = "https://api.churchapps.org/content";
95
- CommonEnvironmentHelper.AskApi = "https://askapi.churchapps.org";
96
-
97
- CommonEnvironmentHelper.ContentRoot = "https://content.churchapps.org";
98
- CommonEnvironmentHelper.B1Root = "https://{key}.b1.church";
99
- CommonEnvironmentHelper.B1AdminRoot = "https://admin.b1.church";
100
- CommonEnvironmentHelper.LessonsRoot = "https://lessons.church";
101
- }
102
-
103
- }
104
-
@@ -1,66 +0,0 @@
1
- export class CurrencyHelper {
2
- static formatCurrency(amount: number) {
3
- const formatter = new Intl.NumberFormat("en-US", {
4
- style: "currency",
5
- currency: "USD",
6
- minimumFractionDigits: 2
7
- });
8
- return formatter.format(amount);
9
- }
10
-
11
- static formatCurrencyWithLocale(amount: number, currency: string = "USD") {
12
- const normalizedCurrency = currency.toUpperCase();
13
- const locale = this.getLocaleForCurrency(normalizedCurrency);
14
-
15
- const formatter = new Intl.NumberFormat(locale, {
16
- style: "currency",
17
- currency: normalizedCurrency,
18
- minimumFractionDigits: 2,
19
- });
20
- return formatter.format(amount);
21
- }
22
-
23
- static getCurrencySymbol(currency?: string) {
24
- const normalizedCurrency = currency?.toLowerCase() || "usd";
25
- const stripeCurrencyFees: any = {
26
- usd: { percent: 2.9, fixed: 0.3, symbol: "$" },
27
- eur: { percent: 2.9, fixed: 0.25, symbol: "€" },
28
- gbp: { percent: 2.9, fixed: 0.2, symbol: "£" },
29
- cad: { percent: 2.9, fixed: 0.3, symbol: "$" },
30
- aud: { percent: 2.9, fixed: 0.3, symbol: "$" },
31
- inr: { percent: 2.9, fixed: 3.0, symbol: "₹" },
32
- jpy: { percent: 2.9, fixed: 30.0, symbol: "¥" },
33
- sgd: { percent: 2.9, fixed: 0.5, symbol: "S$" },
34
- hkd: { percent: 2.9, fixed: 2.35, symbol: "元" },
35
- sek: { percent: 2.9, fixed: 2.5, symbol: "kr" },
36
- nok: { percent: 2.9, fixed: 2.0, symbol: "kr" },
37
- dkk: { percent: 2.9, fixed: 1.8, symbol: "kr" },
38
- chf: { percent: 2.9, fixed: 0.3, symbol: "CHF" },
39
- mxn: { percent: 2.9, fixed: 3.0, symbol: "MXN" },
40
- brl: { percent: 3.9, fixed: 0.5, symbol: "R$" },
41
- };
42
- return stripeCurrencyFees[normalizedCurrency]?.symbol || "$";
43
- }
44
-
45
- private static getLocaleForCurrency(currency: string): string {
46
- const currencyLocaleMap: { [key: string]: string } = {
47
- USD: "en-US",
48
- EUR: "en-GB",
49
- GBP: "en-GB",
50
- CAD: "en-CA",
51
- AUD: "en-AU",
52
- INR: "en-IN",
53
- JPY: "ja-JP",
54
- SGD: "en-SG",
55
- HKD: "en-HK",
56
- SEK: "sv-SE",
57
- NOK: "nb-NO",
58
- DKK: "da-DK",
59
- CHF: "de-CH",
60
- MXN: "es-MX",
61
- BRL: "pt-BR",
62
- };
63
-
64
- return currencyLocaleMap[currency] || "en-US";
65
- }
66
- }