@andre1502/react-utilities 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. package/README.md +340 -0
  2. package/dist/Config/Config.d.ts +28 -0
  3. package/dist/Config/Config.js +200 -0
  4. package/dist/Config/Config.js.map +1 -0
  5. package/dist/Config/GoogleAuth.d.ts +15 -0
  6. package/dist/Config/GoogleAuth.js +71 -0
  7. package/dist/Config/GoogleAuth.js.map +1 -0
  8. package/dist/Config/Locales.d.ts +18 -0
  9. package/dist/Config/Locales.js +62 -0
  10. package/dist/Config/Locales.js.map +1 -0
  11. package/dist/Config/Output.d.ts +10 -0
  12. package/dist/Config/Output.js +28 -0
  13. package/dist/Config/Output.js.map +1 -0
  14. package/dist/Config/Sitemap.d.ts +13 -0
  15. package/dist/Config/Sitemap.js +73 -0
  16. package/dist/Config/Sitemap.js.map +1 -0
  17. package/dist/Format/NumberFormat.d.ts +6 -0
  18. package/dist/Format/NumberFormat.js +77 -0
  19. package/dist/Format/NumberFormat.js.map +1 -0
  20. package/dist/Format/NumberParser.d.ts +9 -0
  21. package/dist/Format/NumberParser.js +51 -0
  22. package/dist/Format/NumberParser.js.map +1 -0
  23. package/dist/React-BaJ1KfGF.js +87 -0
  24. package/dist/React-BaJ1KfGF.js.map +1 -0
  25. package/dist/React-qUl0CBmE.js +109 -0
  26. package/dist/React-qUl0CBmE.js.map +1 -0
  27. package/dist/ReactNative-CqUrY2ZJ.js +3856 -0
  28. package/dist/ReactNative-CqUrY2ZJ.js.map +1 -0
  29. package/dist/ReactNative-mNnws-b5.js +3834 -0
  30. package/dist/ReactNative-mNnws-b5.js.map +1 -0
  31. package/dist/Sentry/Build.d.ts +9 -0
  32. package/dist/Sentry/Build.js +88 -0
  33. package/dist/Sentry/Build.js.map +1 -0
  34. package/dist/Sentry/React.d.ts +18 -0
  35. package/dist/Sentry/React.js +104 -0
  36. package/dist/Sentry/React.js.map +1 -0
  37. package/dist/Sentry/ReactNative.d.ts +18 -0
  38. package/dist/Sentry/ReactNative.js +114 -0
  39. package/dist/Sentry/ReactNative.js.map +1 -0
  40. package/dist/Sentry/Utils.d.ts +2 -0
  41. package/dist/Sentry/Utils.js +24 -0
  42. package/dist/Sentry/Utils.js.map +1 -0
  43. package/dist/Utils/Files.d.ts +7 -0
  44. package/dist/Utils/Files.js +52 -0
  45. package/dist/Utils/Files.js.map +1 -0
  46. package/dist/Utils-Cq948gfa.js +20 -0
  47. package/dist/Utils-Cq948gfa.js.map +1 -0
  48. package/dist/Utils-Dilye04y.js +22 -0
  49. package/dist/Utils-Dilye04y.js.map +1 -0
  50. package/dist/config-cli.cjs +471 -0
  51. package/dist/config-cli.cjs.map +1 -0
  52. package/dist/config-cli.d.ts +34 -0
  53. package/dist/config-cli.js +220 -0
  54. package/dist/config-cli.js.map +1 -0
  55. package/dist/config-cli.mjs +443 -0
  56. package/dist/config-cli.mjs.map +1 -0
  57. package/dist/enums/CurrencySymbolEnum.d.ts +5 -0
  58. package/dist/enums/CurrencySymbolEnum.js +13 -0
  59. package/dist/enums/CurrencySymbolEnum.js.map +1 -0
  60. package/dist/format.cjs +122 -0
  61. package/dist/format.cjs.map +1 -0
  62. package/dist/format.d.ts +3 -0
  63. package/dist/format.js +55 -0
  64. package/dist/format.js.map +1 -0
  65. package/dist/format.mjs +117 -0
  66. package/dist/format.mjs.map +1 -0
  67. package/dist/index-cli.cjs +24 -0
  68. package/dist/index-cli.cjs.map +1 -0
  69. package/dist/index-cli.d.ts +2 -0
  70. package/dist/index-cli.js +28 -0
  71. package/dist/index-cli.js.map +1 -0
  72. package/dist/index-cli.mjs +12 -0
  73. package/dist/index-cli.mjs.map +1 -0
  74. package/dist/index-fmt.cjs +16 -0
  75. package/dist/index-fmt.cjs.map +1 -0
  76. package/dist/index-fmt.d.ts +1 -0
  77. package/dist/index-fmt.js +17 -0
  78. package/dist/index-fmt.js.map +1 -0
  79. package/dist/index-fmt.mjs +3 -0
  80. package/dist/index-fmt.mjs.map +1 -0
  81. package/dist/index-rn.cjs +21 -0
  82. package/dist/index-rn.cjs.map +1 -0
  83. package/dist/index-rn.d.ts +2 -0
  84. package/dist/index-rn.js +28 -0
  85. package/dist/index-rn.js.map +1 -0
  86. package/dist/index-rn.mjs +6 -0
  87. package/dist/index-rn.mjs.map +1 -0
  88. package/dist/index.cjs +21 -0
  89. package/dist/index.cjs.map +1 -0
  90. package/dist/index.d.ts +2 -0
  91. package/dist/index.js +28 -0
  92. package/dist/index.js.map +1 -0
  93. package/dist/index.mjs +6 -0
  94. package/dist/index.mjs.map +1 -0
  95. package/dist/interfaces/Config/ConfigOptions.d.ts +8 -0
  96. package/dist/interfaces/Config/ConfigOptions.js +6 -0
  97. package/dist/interfaces/Config/ConfigOptions.js.map +1 -0
  98. package/dist/interfaces/Config/OutputMap.d.ts +3 -0
  99. package/dist/interfaces/Config/OutputMap.js +6 -0
  100. package/dist/interfaces/Config/OutputMap.js.map +1 -0
  101. package/dist/interfaces/Config/OutputOptions.d.ts +7 -0
  102. package/dist/interfaces/Config/OutputOptions.js +6 -0
  103. package/dist/interfaces/Config/OutputOptions.js.map +1 -0
  104. package/dist/interfaces/Config/SitemapMap.d.ts +5 -0
  105. package/dist/interfaces/Config/SitemapMap.js +6 -0
  106. package/dist/interfaces/Config/SitemapMap.js.map +1 -0
  107. package/dist/interfaces/Config/StringMap.d.ts +3 -0
  108. package/dist/interfaces/Config/StringMap.js +6 -0
  109. package/dist/interfaces/Config/StringMap.js.map +1 -0
  110. package/dist/interfaces/Format/FormatOptions.d.ts +14 -0
  111. package/dist/interfaces/Format/FormatOptions.js +6 -0
  112. package/dist/interfaces/Format/FormatOptions.js.map +1 -0
  113. package/dist/interfaces/Sentry/InitOptions.d.ts +20 -0
  114. package/dist/interfaces/Sentry/InitOptions.js +6 -0
  115. package/dist/interfaces/Sentry/InitOptions.js.map +1 -0
  116. package/dist/interfaces/Sentry/InitOptionsRN.d.ts +4 -0
  117. package/dist/interfaces/Sentry/InitOptionsRN.js +6 -0
  118. package/dist/interfaces/Sentry/InitOptionsRN.js.map +1 -0
  119. package/dist/interfaces/Sentry/SourceMapOptions.d.ts +7 -0
  120. package/dist/interfaces/Sentry/SourceMapOptions.js +6 -0
  121. package/dist/interfaces/Sentry/SourceMapOptions.js.map +1 -0
  122. package/dist/sentry-cli.cjs +119 -0
  123. package/dist/sentry-cli.cjs.map +1 -0
  124. package/dist/sentry-cli.d.ts +9 -0
  125. package/dist/sentry-cli.js +50 -0
  126. package/dist/sentry-cli.js.map +1 -0
  127. package/dist/sentry-cli.mjs +98 -0
  128. package/dist/sentry-cli.mjs.map +1 -0
  129. package/dist/sentry-rn.cjs +11 -0
  130. package/dist/sentry-rn.cjs.map +1 -0
  131. package/dist/sentry-rn.d.ts +2 -0
  132. package/dist/sentry-rn.js +28 -0
  133. package/dist/sentry-rn.js.map +1 -0
  134. package/dist/sentry-rn.mjs +4 -0
  135. package/dist/sentry-rn.mjs.map +1 -0
  136. package/dist/sentry.cjs +11 -0
  137. package/dist/sentry.cjs.map +1 -0
  138. package/dist/sentry.d.ts +2 -0
  139. package/dist/sentry.js +28 -0
  140. package/dist/sentry.js.map +1 -0
  141. package/dist/sentry.mjs +4 -0
  142. package/dist/sentry.mjs.map +1 -0
  143. package/dist/types/Config/OptionType.d.ts +2 -0
  144. package/dist/types/Config/OptionType.js +6 -0
  145. package/dist/types/Config/OptionType.js.map +1 -0
  146. package/dist/types/Format/OptionType.d.ts +3 -0
  147. package/dist/types/Format/OptionType.js +6 -0
  148. package/dist/types/Format/OptionType.js.map +1 -0
  149. package/dist/types/Sentry/OptionType.d.ts +1 -0
  150. package/dist/types/Sentry/OptionType.js +6 -0
  151. package/dist/types/Sentry/OptionType.js.map +1 -0
  152. package/package.json +139 -0
  153. package/src/Config/Config.ts +258 -0
  154. package/src/Config/GoogleAuth.ts +54 -0
  155. package/src/Config/Locales.ts +72 -0
  156. package/src/Config/Output.ts +29 -0
  157. package/src/Config/Sitemap.ts +67 -0
  158. package/src/Format/NumberFormat.ts +96 -0
  159. package/src/Format/NumberParser.ts +42 -0
  160. package/src/Sentry/Build.ts +67 -0
  161. package/src/Sentry/React.ts +127 -0
  162. package/src/Sentry/ReactNative.ts +133 -0
  163. package/src/Sentry/Utils.ts +26 -0
  164. package/src/Utils/Files.ts +51 -0
  165. package/src/config-cli.ts +152 -0
  166. package/src/enums/CurrencySymbolEnum.ts +5 -0
  167. package/src/format.ts +39 -0
  168. package/src/index-cli.ts +2 -0
  169. package/src/index-fmt.ts +1 -0
  170. package/src/index-rn.ts +2 -0
  171. package/src/index.ts +2 -0
  172. package/src/interfaces/Config/ConfigOptions.ts +9 -0
  173. package/src/interfaces/Config/OutputMap.ts +3 -0
  174. package/src/interfaces/Config/OutputOptions.ts +8 -0
  175. package/src/interfaces/Config/SitemapMap.ts +5 -0
  176. package/src/interfaces/Config/StringMap.ts +3 -0
  177. package/src/interfaces/Format/FormatOptions.ts +19 -0
  178. package/src/interfaces/Sentry/InitOptions.ts +23 -0
  179. package/src/interfaces/Sentry/InitOptionsRN.ts +5 -0
  180. package/src/interfaces/Sentry/SourceMapOptions.ts +7 -0
  181. package/src/sentry-cli.ts +16 -0
  182. package/src/sentry-rn.ts +2 -0
  183. package/src/sentry.ts +2 -0
  184. package/src/types/Config/OptionType.ts +2 -0
  185. package/src/types/Format/OptionType.ts +15 -0
  186. package/src/types/Sentry/OptionType.ts +1 -0
@@ -0,0 +1,96 @@
1
+ import { NumberFormat } from '@formatjs/intl-numberformat';
2
+ import { CurrencySymbolEnum } from '../enums/CurrencySymbolEnum';
3
+ import { FormatOptions } from '../interfaces/Format/FormatOptions';
4
+ import { NumberParser } from './NumberParser';
5
+
6
+ const formatAccountNumber = (
7
+ accountNumber: string,
8
+ separator: string = ' ',
9
+ ) => {
10
+ return accountNumber
11
+ ?.replace(/\s?/g, '')
12
+ .replace(/(\d{4})/g, `$1${separator}`)
13
+ .trim();
14
+ };
15
+
16
+ const getCurrencySymbol = (currency: string, showCurrency: boolean = true) => {
17
+ let symbol;
18
+
19
+ switch (currency) {
20
+ case 'TWD':
21
+ symbol = CurrencySymbolEnum.TWD;
22
+ break;
23
+ case 'USD':
24
+ symbol = CurrencySymbolEnum.USD;
25
+ break;
26
+ case 'VND':
27
+ symbol = CurrencySymbolEnum.VND;
28
+ break;
29
+ default:
30
+ symbol = '';
31
+ }
32
+
33
+ if (!showCurrency) {
34
+ symbol = '';
35
+ }
36
+
37
+ return symbol;
38
+ };
39
+
40
+ const formatNumber = (options: FormatOptions) => {
41
+ options.value = options.value ?? 0;
42
+ options.styleCurrency = options.styleCurrency ?? 'currency';
43
+ options.currencyDisplay = options.currencyDisplay ?? 'code';
44
+ options.showValue = options.showValue ?? true;
45
+ options.showCurrency = options.showCurrency ?? true;
46
+ options.minimumFractionDigits = options.minimumFractionDigits ?? 0;
47
+ options.maximumFractionDigits = options.maximumFractionDigits ?? 0;
48
+ options.trailingZeroDisplay = options.trailingZeroDisplay ?? 'stripIfInteger';
49
+
50
+ // console.log(`options: ${JSON.stringify(options)}.`);
51
+
52
+ let formatOptions = {
53
+ style: options.styleCurrency,
54
+ currency: options.currency,
55
+ currencyDisplay: options.currencyDisplay,
56
+ minimumFractionDigits: options.minimumFractionDigits,
57
+ maximumFractionDigits: options.maximumFractionDigits,
58
+ trailingZeroDisplay: options.trailingZeroDisplay,
59
+ };
60
+
61
+ if (options.options) {
62
+ formatOptions = {
63
+ ...formatOptions,
64
+ ...options.options,
65
+ };
66
+ }
67
+
68
+ let localizedNumber = NumberFormat(options.lang, formatOptions)
69
+ .format(options.value)
70
+ .replace(/^([\d,.]+)(\s*)([A-Z]{3})$/, '$3$2$1')
71
+ .replace(/([\d,.]+)$/, options.showValue ? ' $1' : ' ********')
72
+ .replace(
73
+ options.currency,
74
+ getCurrencySymbol(options.currency, options.showCurrency),
75
+ )
76
+ .trim();
77
+
78
+ // console.log(`localizedNumber: ${localizedNumber}.`);
79
+
80
+ return localizedNumber;
81
+ };
82
+
83
+ const parseFormatNumber = (lang: string, value: string) => {
84
+ if (!value) {
85
+ return null;
86
+ }
87
+
88
+ return new NumberParser(lang).parse(value);
89
+ };
90
+
91
+ export {
92
+ formatAccountNumber,
93
+ formatNumber,
94
+ getCurrencySymbol,
95
+ parseFormatNumber,
96
+ };
@@ -0,0 +1,42 @@
1
+ import { NumberFormat } from '@formatjs/intl-numberformat';
2
+
3
+ class NumberParser {
4
+ private _group: RegExp;
5
+ private _decimal: RegExp;
6
+ private _numeral: RegExp;
7
+ private _index: (d: any) => any;
8
+
9
+ constructor(locale: string) {
10
+ const parts = new NumberFormat(locale).formatToParts(12345.6);
11
+
12
+ const numerals = [
13
+ ...new NumberFormat(locale, { useGrouping: false }).format(9876543210),
14
+ ].reverse();
15
+
16
+ const index = new Map(numerals.map((d, i) => [d, i]));
17
+
18
+ this._group = new RegExp(
19
+ `[${parts.find((d) => d.type === 'group')?.value}]`,
20
+ 'g',
21
+ );
22
+
23
+ this._decimal = new RegExp(
24
+ `[${parts.find((d) => d.type === 'decimal')?.value}]`,
25
+ );
26
+
27
+ this._numeral = new RegExp(`[${numerals.join('')}]`, 'g');
28
+ this._index = (d) => index.get(d);
29
+ }
30
+
31
+ parse(value: string) {
32
+ value = value
33
+ ?.trim()
34
+ ?.replace(this._group, '')
35
+ ?.replace(this._decimal, '.')
36
+ ?.replace(this._numeral, this._index);
37
+
38
+ return value ? +value : NaN;
39
+ }
40
+ }
41
+
42
+ export { NumberParser };
@@ -0,0 +1,67 @@
1
+ // sentry-cli sourcemaps inject --org <org> --project <project> ./build/static/js && sentry-cli sourcemaps upload --org <org> --project <project> ./build/static/js
2
+
3
+ import SentryCli from '@sentry/cli';
4
+ import { SourceMapOptions } from '../interfaces/Sentry/SourceMapOptions';
5
+ import { deleteFile } from '../Utils/Files';
6
+
7
+ /**
8
+ * Create Sentry release and upload to Sentry host.
9
+ *
10
+ * @param {SourceMapOptions} options
11
+ * @return {Promise<void>}
12
+ */
13
+ const releaseSourceMap = async (options: SourceMapOptions): Promise<void> => {
14
+ if (
15
+ !options.requiredEnvForSourceMap ||
16
+ options.requiredEnvForSourceMap.length <= 0
17
+ ) {
18
+ options.requiredEnvForSourceMap = ['production'];
19
+ }
20
+
21
+ if (!options.urlPrefix) {
22
+ options.urlPrefix = '';
23
+ }
24
+
25
+ if (!options.includeFolder || options.includeFolder.length <= 0) {
26
+ console.error('includeFolder value is empty.');
27
+ return;
28
+ }
29
+
30
+ if (!options.requiredEnvForSourceMap.includes(options.env)) {
31
+ console.log(
32
+ 'No need to upload sentry source map, required env:',
33
+ options.requiredEnvForSourceMap,
34
+ );
35
+
36
+ options.includeFolder.forEach((folder) => deleteFile(folder, ['.map']));
37
+
38
+ return;
39
+ }
40
+
41
+ try {
42
+ const cli = new SentryCli();
43
+
44
+ console.log('Now creating sentry release ' + options.release);
45
+
46
+ await cli.releases.new(options.release);
47
+
48
+ console.log('Now uploading source maps');
49
+ await cli.releases.uploadSourceMaps(options.release, {
50
+ urlPrefix: options.urlPrefix,
51
+ include: options.includeFolder,
52
+ rewrite: true,
53
+ validate: true,
54
+ useArtifactBundle: true,
55
+ });
56
+
57
+ console.log('Releasing release');
58
+
59
+ await cli.releases.finalize(options.release);
60
+
61
+ options.includeFolder.forEach((folder) => deleteFile(folder, ['.map']));
62
+ } catch (ex) {
63
+ console.error('Source maps uploading failed:', ex);
64
+ }
65
+ };
66
+
67
+ export { releaseSourceMap };
@@ -0,0 +1,127 @@
1
+ import * as Sentry from '@sentry/react';
2
+ import { InitOptions } from '../interfaces/Sentry/InitOptions';
3
+ import { StringRegexArr } from '../types/Sentry/OptionType';
4
+ import { recordSentryHttp } from './Utils';
5
+
6
+ /**
7
+ * Initialize Sentry for React.
8
+ *
9
+ * @param {InitOptions} options
10
+ * @return {void}
11
+ */
12
+ const initSentry = (options: InitOptions): void => {
13
+ let shouldSendToSentry = options?.requiredEnvForSendToSentry?.includes(
14
+ options.env,
15
+ );
16
+
17
+ let ignoreErrors: StringRegexArr = [
18
+ /antd:/,
19
+ /is deprecated in StrictMode/,
20
+ /React Intl/,
21
+ ];
22
+
23
+ if (options?.ignoreErrorsOptions) {
24
+ ignoreErrors = ignoreErrors.concat(options.ignoreErrorsOptions);
25
+ }
26
+
27
+ if (options?.options?.ignoreErrors) {
28
+ ignoreErrors = ignoreErrors.concat(options.options.ignoreErrors);
29
+ delete options.options.ignoreErrors;
30
+ }
31
+
32
+ let integrations: any[] = [];
33
+
34
+ if (
35
+ options?.httpClientIntegrationOptions?.failedRequestStatusCodes &&
36
+ options?.httpClientIntegrationOptions?.failedRequestTargets
37
+ ) {
38
+ integrations.push(
39
+ Sentry.httpClientIntegration({
40
+ failedRequestStatusCodes:
41
+ options.httpClientIntegrationOptions.failedRequestStatusCodes,
42
+ failedRequestTargets:
43
+ options.httpClientIntegrationOptions.failedRequestTargets,
44
+ }),
45
+ );
46
+ }
47
+
48
+ if (options?.captureConsoleIntegrationOptions?.levels) {
49
+ integrations.push(
50
+ Sentry.captureConsoleIntegration({
51
+ levels: options.captureConsoleIntegrationOptions.levels,
52
+ }),
53
+ );
54
+ }
55
+
56
+ if (options?.options?.hasOwnProperty('integrations')) {
57
+ options.options.integrations = [
58
+ ...options.options.integrations,
59
+ ...integrations,
60
+ ];
61
+ } else {
62
+ options.options = options.options || {};
63
+ options.options.integrations = integrations;
64
+ }
65
+
66
+ let sentryOptions: Sentry.BrowserOptions = {
67
+ dsn: options.dsn,
68
+ debug: options.debug,
69
+ release: options.release,
70
+ environment: options.env,
71
+ ignoreErrors: ignoreErrors,
72
+ sampleRate: 1.0,
73
+ maxBreadcrumbs: 50,
74
+ attachStacktrace: true,
75
+ autoSessionTracking: true,
76
+ sendClientReports: true,
77
+ enableTracing: true,
78
+ // Performance Monitoring
79
+ tracesSampleRate: 1.0, // Capture 100% of the transactions
80
+ // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
81
+ tracePropagationTargets: ['localhost'],
82
+ sendDefaultPii: true,
83
+ beforeSend: (event) => {
84
+ if (
85
+ event?.message?.includes('antd:') ||
86
+ event?.message?.includes('is deprecated in StrictMode') ||
87
+ event?.message?.includes('React Intl') ||
88
+ !shouldSendToSentry
89
+ ) {
90
+ return null;
91
+ }
92
+
93
+ return event;
94
+ },
95
+ };
96
+
97
+ if (options?.beforeSend) {
98
+ sentryOptions.beforeSend = options.beforeSend;
99
+ }
100
+
101
+ if (options?.options) {
102
+ sentryOptions = {
103
+ ...sentryOptions,
104
+ ...options.options,
105
+ };
106
+ }
107
+
108
+ Sentry.init(sentryOptions);
109
+ };
110
+
111
+ /**
112
+ * Record additional http data for Sentry.
113
+ *
114
+ * @param {any | null} config
115
+ * @param {any | null} request
116
+ * @param {any | null} response
117
+ * @return {void}
118
+ */
119
+ const recordAdditionalSentryHttp = (
120
+ config?: any,
121
+ request?: any,
122
+ response?: any,
123
+ ) => {
124
+ recordSentryHttp(Sentry, config, request, response);
125
+ };
126
+
127
+ export { initSentry, recordAdditionalSentryHttp };
@@ -0,0 +1,133 @@
1
+ import {
2
+ captureConsoleIntegration,
3
+ httpClientIntegration,
4
+ } from '@sentry/integrations';
5
+ import * as Sentry from '@sentry/react-native';
6
+ import { InitOptionsRN } from '../interfaces/Sentry/InitOptionsRN';
7
+ import { StringRegexArr } from '../types/Sentry/OptionType';
8
+ import { recordSentryHttp } from './Utils';
9
+
10
+ /**
11
+ * Initialize Sentry for React Native.
12
+ *
13
+ * @param {InitOptionsRN} options
14
+ * @return {void}
15
+ */
16
+ const initSentry = (options: InitOptionsRN): void => {
17
+ let shouldSendToSentry = options?.requiredEnvForSendToSentry?.includes(
18
+ options.env,
19
+ );
20
+
21
+ let ignoreErrors: StringRegexArr = [/StallTracking/];
22
+
23
+ if (options?.ignoreErrorsOptions) {
24
+ ignoreErrors = ignoreErrors.concat(options.ignoreErrorsOptions);
25
+ }
26
+
27
+ if (options?.options?.ignoreErrors) {
28
+ ignoreErrors = ignoreErrors.concat(options.options.ignoreErrors);
29
+ delete options.options.ignoreErrors;
30
+ }
31
+
32
+ let integrations: any[] = [];
33
+
34
+ if (
35
+ options?.httpClientIntegrationOptions?.failedRequestStatusCodes &&
36
+ options?.httpClientIntegrationOptions?.failedRequestTargets
37
+ ) {
38
+ integrations.push(
39
+ httpClientIntegration({
40
+ failedRequestStatusCodes:
41
+ options.httpClientIntegrationOptions.failedRequestStatusCodes,
42
+ failedRequestTargets:
43
+ options.httpClientIntegrationOptions.failedRequestTargets,
44
+ }),
45
+ );
46
+ }
47
+
48
+ if (options?.captureConsoleIntegrationOptions?.levels) {
49
+ integrations.push(
50
+ captureConsoleIntegration({
51
+ levels: options.captureConsoleIntegrationOptions.levels,
52
+ }),
53
+ );
54
+ }
55
+
56
+ if (options?.options?.hasOwnProperty('integrations')) {
57
+ options.options.integrations = [
58
+ ...options.options.integrations,
59
+ ...integrations,
60
+ ];
61
+ } else {
62
+ options.options = options.options || {};
63
+ options.options.integrations = integrations;
64
+ }
65
+
66
+ let sentryOptions: Sentry.ReactNativeOptions = {
67
+ dsn: options.dsn,
68
+ debug: options.debug,
69
+ environment: options.env,
70
+ ignoreErrors: ignoreErrors,
71
+ sampleRate: 1.0,
72
+ maxBreadcrumbs: 50,
73
+ autoSessionTracking: true,
74
+ attachScreenshot: true,
75
+ enableCaptureFailedRequests: true,
76
+ enableTracing: true,
77
+ tracesSampleRate: 1.0,
78
+ enableNative: true,
79
+ autoInitializeNativeSdk: true,
80
+ enableNativeCrashHandling: true,
81
+ enableNativeNagger: true,
82
+ enableAutoSessionTracking: true,
83
+ enableNdkScopeSync: true,
84
+ attachThreads: true,
85
+ enableAutoPerformanceTracing: true,
86
+ enableWatchdogTerminationTracking: true,
87
+ enableAppHangTracking: true,
88
+ appHangTimeoutInterval: 5,
89
+ sendDefaultPii: true,
90
+ beforeSend: (event) => {
91
+ if (event?.message?.includes('StallTracking') || !shouldSendToSentry) {
92
+ return null;
93
+ }
94
+
95
+ return event;
96
+ },
97
+ };
98
+
99
+ if (options?.release) {
100
+ sentryOptions.release = options.release;
101
+ }
102
+
103
+ if (options?.beforeSend) {
104
+ sentryOptions.beforeSend = options.beforeSend;
105
+ }
106
+
107
+ if (options?.options) {
108
+ sentryOptions = {
109
+ ...sentryOptions,
110
+ ...options.options,
111
+ };
112
+ }
113
+
114
+ Sentry.init(sentryOptions);
115
+ };
116
+
117
+ /**
118
+ * Record additional http data for Sentry.
119
+ *
120
+ * @param {any | null} config
121
+ * @param {any | null} request
122
+ * @param {any | null} response
123
+ * @return {void}
124
+ */
125
+ const recordAdditionalSentryHttp = (
126
+ config?: any,
127
+ request?: any,
128
+ response?: any,
129
+ ) => {
130
+ recordSentryHttp(Sentry, config, request, response);
131
+ };
132
+
133
+ export { initSentry, recordAdditionalSentryHttp };
@@ -0,0 +1,26 @@
1
+ const recordSentryHttp = (
2
+ Sentry: any,
3
+ config?: any,
4
+ request?: any,
5
+ response?: any,
6
+ ) => {
7
+ if (config) {
8
+ Sentry.withScope((scope: any) => {
9
+ scope.setContext('config', config);
10
+ });
11
+ }
12
+
13
+ if (request) {
14
+ Sentry.withScope((scope: any) => {
15
+ scope.setContext('request', request);
16
+ });
17
+ }
18
+
19
+ if (response) {
20
+ Sentry.withScope((scope: any) => {
21
+ scope.setContext('response', response);
22
+ });
23
+ }
24
+ };
25
+
26
+ export { recordSentryHttp };
@@ -0,0 +1,51 @@
1
+ import { lstatSync, readdir, unlinkSync } from 'fs';
2
+ import * as path from 'path';
3
+
4
+ /**
5
+ * @param {string} path - The path.
6
+ * @returns {boolean} Whether path is a directory, otherwise always false.
7
+ */
8
+ const isDir = (path: string): boolean => {
9
+ try {
10
+ const stat = lstatSync(path);
11
+ return stat.isDirectory();
12
+ } catch (error) {
13
+ // lstatSync throws an error if path doesn't exist
14
+ return false;
15
+ }
16
+ };
17
+
18
+ /**
19
+ * @param {string} dirPath - Directory path.
20
+ * @param {string[]} exts - List of Extension file need to be removed.
21
+ * @returns {void}
22
+ */
23
+ const deleteFile = (dirPath: string, exts: string[]): void => {
24
+ readdir(dirPath, (err, files) => {
25
+ if (err) {
26
+ console.error(err);
27
+ }
28
+
29
+ files.forEach((file) => {
30
+ const fileDir = path.join(`${dirPath}/${file}`);
31
+ // Get the extension name of the file, lowercase it, then see if it is in the array of extensions
32
+ // defined above. If so, remove it.
33
+
34
+ if (isDir(fileDir)) {
35
+ deleteFile(fileDir, exts);
36
+ return;
37
+ }
38
+
39
+ if (
40
+ file.toLowerCase() === '.ds_store' ||
41
+ exts.includes(path.extname(file).toLowerCase())
42
+ ) {
43
+ unlinkSync(fileDir);
44
+
45
+ console.log(`File: ${fileDir} deleted successfully.`);
46
+ }
47
+ });
48
+ });
49
+ };
50
+
51
+ export { deleteFile };
@@ -0,0 +1,152 @@
1
+ import { GoogleAuth } from 'google-auth-library';
2
+ import { JSONClient } from 'google-auth-library/build/src/auth/googleauth';
3
+ import { exportConfig, processConfig } from './Config/Config';
4
+ import { authorizeServiceAccount, fetchGoogleSheet } from './Config/GoogleAuth';
5
+ import { exportLocales, processLocales } from './Config/Locales';
6
+ import { ConfigOptions } from './interfaces/Config/ConfigOptions';
7
+
8
+ export { transformConfig } from './Config/Config';
9
+ export { transformSitemap } from './Config/Sitemap';
10
+ export * from './interfaces/Config/ConfigOptions';
11
+ export * from './interfaces/Config/OutputOptions';
12
+ export type { ExportAs, FormatAs } from './types/Config/OptionType';
13
+
14
+ /**
15
+ * Private function to fetch locales
16
+ *
17
+ * @param {GoogleAuth<JSONClient>} auth
18
+ * @param {ConfigOption} options
19
+ * @return {Promise<void>}
20
+ */
21
+ const innerFetchLocales = async (
22
+ auth: GoogleAuth<JSONClient>,
23
+ options: ConfigOptions,
24
+ ): Promise<void> => {
25
+ // console.log('auth', auth);
26
+
27
+ const values = await fetchGoogleSheet(
28
+ auth,
29
+ options.spreadsheetId,
30
+ options.spreadsheetTab,
31
+ );
32
+
33
+ if (!values || values.length === 0) {
34
+ console.log('No data found.');
35
+ return;
36
+ }
37
+
38
+ // console.log('values,', values);
39
+
40
+ const data = processLocales(values);
41
+
42
+ exportLocales(data, options.output);
43
+ };
44
+
45
+ /**
46
+ * Private function to fetch config
47
+ *
48
+ * @param {GoogleAuth<JSONClient>} auth
49
+ * @param {ConfigOption} options
50
+ * @return {Promise<void>}
51
+ */
52
+ const innerFetchConfig = async (
53
+ auth: GoogleAuth<JSONClient>,
54
+ options: ConfigOptions,
55
+ ): Promise<void> => {
56
+ // console.log('auth', auth);
57
+
58
+ const values = await fetchGoogleSheet(
59
+ auth,
60
+ options.spreadsheetId,
61
+ options.spreadsheetTab,
62
+ );
63
+
64
+ if (!values || values.length === 0) {
65
+ console.log('No data found.');
66
+ return;
67
+ }
68
+
69
+ // console.log('values,', values);
70
+
71
+ const data = processConfig(values);
72
+
73
+ exportConfig(data, options.output);
74
+ };
75
+
76
+ /**
77
+ * Fetch locales
78
+ *
79
+ * @param {ConfigOptions} options
80
+ * @return {void}
81
+ */
82
+ export const fetchLocales = (options: ConfigOptions): void => {
83
+ try {
84
+ const auth = authorizeServiceAccount();
85
+
86
+ innerFetchLocales(auth, options);
87
+ } catch (error) {
88
+ console.error(error);
89
+ }
90
+ };
91
+
92
+ /**
93
+ * Fetch config
94
+ *
95
+ * @param {ConfigOptions} options
96
+ * @return {void}
97
+ */
98
+ export const fetchConfig = (options: ConfigOptions): void => {
99
+ try {
100
+ const auth = authorizeServiceAccount();
101
+
102
+ innerFetchConfig(auth, options);
103
+ } catch (error) {
104
+ console.error(error);
105
+ }
106
+ };
107
+
108
+ /**
109
+ * Fetch all format from array options
110
+ *
111
+ * @param {ConfigOptions[]} options
112
+ * @return {void}
113
+ */
114
+ export const fetchAll = (options: ConfigOptions[]): void => {
115
+ try {
116
+ const auth = authorizeServiceAccount();
117
+
118
+ options.forEach((option) => {
119
+ if (option.formatAs === 'locales') {
120
+ innerFetchLocales(auth, option);
121
+ } else if (option.formatAs === 'config') {
122
+ innerFetchConfig(auth, option);
123
+ }
124
+ });
125
+ } catch (error) {
126
+ console.error(error);
127
+ }
128
+ };
129
+
130
+ /**
131
+ * Fetch raw value
132
+ *
133
+ * @param {ConfigOptions} options
134
+ * @return {Promise<any[][] | null | undefined>}
135
+ */
136
+ export const fetchRawValue = async (
137
+ options: ConfigOptions,
138
+ ): Promise<any[][] | null | undefined> => {
139
+ try {
140
+ const auth = authorizeServiceAccount();
141
+
142
+ return await fetchGoogleSheet(
143
+ auth,
144
+ options.spreadsheetId,
145
+ options.spreadsheetTab,
146
+ );
147
+ } catch (error) {
148
+ console.error(error);
149
+ }
150
+
151
+ return null;
152
+ };
@@ -0,0 +1,5 @@
1
+ export enum CurrencySymbolEnum {
2
+ TWD = 'NT$', // Taiwan
3
+ USD = 'US$', // USA
4
+ VND = '₫', // Vietnam
5
+ }