dce-reactkit 2.0.10 → 3.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.
Files changed (187) hide show
  1. package/lib/cjs/index.js +2 -0
  2. package/lib/cjs/index.js.map +1 -0
  3. package/lib/cjs/lib/components/AppWrapper.d.ts +35 -0
  4. package/lib/{components → cjs/lib/components}/ErrorBox.d.ts +0 -0
  5. package/lib/{components → cjs/lib/components}/LoadingSpinner.d.ts +1 -0
  6. package/lib/cjs/lib/components/Modal.d.ts +40 -0
  7. package/lib/cjs/lib/components/TabBox.d.ts +11 -0
  8. package/lib/{errors → cjs/lib/errors}/ErrorWithCode.d.ts +0 -0
  9. package/lib/{helpers → cjs/lib/helpers}/abbreviate.d.ts +1 -0
  10. package/lib/{helpers → cjs/lib/helpers}/avg.d.ts +0 -0
  11. package/lib/{helpers → cjs/lib/helpers}/ceilToNumDecimals.d.ts +0 -0
  12. package/lib/{helpers → cjs/lib/helpers}/floorToNumDecimals.d.ts +0 -0
  13. package/lib/{helpers → cjs/lib/helpers}/forceNumIntoBounds.d.ts +0 -0
  14. package/lib/{helpers → cjs/lib/helpers}/handleError.d.ts +0 -0
  15. package/lib/{helpers → cjs/lib/helpers}/handleSuccess.d.ts +0 -0
  16. package/lib/{helpers → cjs/lib/helpers}/padDecimalZeros.d.ts +0 -0
  17. package/lib/{helpers → cjs/lib/helpers}/padZerosLeft.d.ts +0 -0
  18. package/lib/{helpers → cjs/lib/helpers}/parseRequest.d.ts +1 -1
  19. package/lib/{helpers → cjs/lib/helpers}/roundToNumDecimals.d.ts +0 -0
  20. package/lib/{helpers → cjs/lib/helpers}/sum.d.ts +0 -0
  21. package/lib/{helpers → cjs/lib/helpers}/visitServerEndpoint.d.ts +2 -2
  22. package/lib/{helpers → cjs/lib/helpers}/waitMs.d.ts +0 -0
  23. package/lib/cjs/lib/index.d.ts +27 -0
  24. package/lib/cjs/lib/types/ModalButtonType.d.ts +17 -0
  25. package/lib/cjs/lib/types/ModalSize.d.ts +11 -0
  26. package/lib/cjs/lib/types/ModalType.d.ts +16 -0
  27. package/lib/{types → cjs/lib/types}/ParamType.d.ts +0 -0
  28. package/lib/{types → cjs/lib/types}/ReactKitErrorCode.d.ts +0 -0
  29. package/lib/{types → cjs/lib/types}/Variant.d.ts +0 -0
  30. package/lib/cjs/types/components/AppWrapper.d.ts +40 -0
  31. package/lib/cjs/types/components/ErrorBox.d.ts +12 -0
  32. package/lib/cjs/types/components/LoadingSpinner.d.ts +7 -0
  33. package/lib/cjs/types/components/Modal.d.ts +40 -0
  34. package/lib/cjs/types/components/TabBox.d.ts +11 -0
  35. package/lib/cjs/types/errors/ErrorWithCode.d.ts +9 -0
  36. package/lib/cjs/types/helpers/abbreviate.d.ts +10 -0
  37. package/lib/cjs/types/helpers/alert.d.ts +2 -0
  38. package/lib/cjs/types/helpers/avg.d.ts +8 -0
  39. package/lib/cjs/types/helpers/ceilToNumDecimals.d.ts +9 -0
  40. package/lib/cjs/types/helpers/confirm.d.ts +2 -0
  41. package/lib/cjs/types/helpers/floorToNumDecimals.d.ts +9 -0
  42. package/lib/cjs/types/helpers/forceNumIntoBounds.d.ts +10 -0
  43. package/lib/cjs/types/helpers/handleError.d.ts +14 -0
  44. package/lib/cjs/types/helpers/handleSuccess.d.ts +8 -0
  45. package/lib/cjs/types/helpers/padDecimalZeros.d.ts +10 -0
  46. package/lib/cjs/types/helpers/padZerosLeft.d.ts +9 -0
  47. package/lib/cjs/types/helpers/parseRequest.d.ts +21 -0
  48. package/lib/cjs/types/helpers/roundToNumDecimals.d.ts +9 -0
  49. package/lib/cjs/types/helpers/showFatalError.d.ts +2 -0
  50. package/lib/cjs/types/helpers/sum.d.ts +8 -0
  51. package/lib/cjs/types/helpers/visitServerEndpoint.d.ts +23 -0
  52. package/lib/cjs/types/helpers/waitMs.d.ts +7 -0
  53. package/lib/cjs/types/index.d.ts +22 -0
  54. package/lib/cjs/types/types/ModalButtonType.d.ts +17 -0
  55. package/lib/cjs/types/types/ModalSize.d.ts +11 -0
  56. package/lib/cjs/types/types/ModalType.d.ts +16 -0
  57. package/lib/cjs/types/types/ParamType.d.ts +17 -0
  58. package/lib/cjs/types/types/ReactKitErrorCode.d.ts +13 -0
  59. package/lib/cjs/types/types/Variant.d.ts +15 -0
  60. package/lib/esm/index.js +16 -0
  61. package/lib/esm/index.js.map +1 -0
  62. package/lib/esm/lib/components/AppWrapper.d.ts +35 -0
  63. package/lib/esm/lib/components/ErrorBox.d.ts +12 -0
  64. package/lib/esm/lib/components/LoadingSpinner.d.ts +7 -0
  65. package/lib/esm/lib/components/Modal.d.ts +40 -0
  66. package/lib/esm/lib/components/TabBox.d.ts +11 -0
  67. package/lib/esm/lib/errors/ErrorWithCode.d.ts +9 -0
  68. package/lib/esm/lib/helpers/abbreviate.d.ts +10 -0
  69. package/lib/esm/lib/helpers/avg.d.ts +8 -0
  70. package/lib/esm/lib/helpers/ceilToNumDecimals.d.ts +9 -0
  71. package/lib/esm/lib/helpers/floorToNumDecimals.d.ts +9 -0
  72. package/lib/esm/lib/helpers/forceNumIntoBounds.d.ts +10 -0
  73. package/lib/esm/lib/helpers/handleError.d.ts +14 -0
  74. package/lib/esm/lib/helpers/handleSuccess.d.ts +8 -0
  75. package/lib/esm/lib/helpers/padDecimalZeros.d.ts +10 -0
  76. package/lib/esm/lib/helpers/padZerosLeft.d.ts +9 -0
  77. package/lib/esm/lib/helpers/parseRequest.d.ts +21 -0
  78. package/lib/esm/lib/helpers/roundToNumDecimals.d.ts +9 -0
  79. package/lib/esm/lib/helpers/sum.d.ts +8 -0
  80. package/lib/esm/lib/helpers/visitServerEndpoint.d.ts +23 -0
  81. package/lib/esm/lib/helpers/waitMs.d.ts +7 -0
  82. package/lib/esm/lib/index.d.ts +27 -0
  83. package/lib/esm/lib/types/ModalButtonType.d.ts +17 -0
  84. package/lib/esm/lib/types/ModalSize.d.ts +11 -0
  85. package/lib/esm/lib/types/ModalType.d.ts +16 -0
  86. package/lib/esm/lib/types/ParamType.d.ts +17 -0
  87. package/lib/esm/lib/types/ReactKitErrorCode.d.ts +13 -0
  88. package/lib/esm/lib/types/Variant.d.ts +15 -0
  89. package/lib/esm/types/components/AppWrapper.d.ts +40 -0
  90. package/lib/esm/types/components/ErrorBox.d.ts +12 -0
  91. package/lib/esm/types/components/LoadingSpinner.d.ts +7 -0
  92. package/lib/esm/types/components/Modal.d.ts +40 -0
  93. package/lib/esm/types/components/TabBox.d.ts +11 -0
  94. package/lib/esm/types/errors/ErrorWithCode.d.ts +9 -0
  95. package/lib/esm/types/helpers/abbreviate.d.ts +10 -0
  96. package/lib/esm/types/helpers/alert.d.ts +2 -0
  97. package/lib/esm/types/helpers/avg.d.ts +8 -0
  98. package/lib/esm/types/helpers/ceilToNumDecimals.d.ts +9 -0
  99. package/lib/esm/types/helpers/confirm.d.ts +2 -0
  100. package/lib/esm/types/helpers/floorToNumDecimals.d.ts +9 -0
  101. package/lib/esm/types/helpers/forceNumIntoBounds.d.ts +10 -0
  102. package/lib/esm/types/helpers/handleError.d.ts +14 -0
  103. package/lib/esm/types/helpers/handleSuccess.d.ts +8 -0
  104. package/lib/esm/types/helpers/padDecimalZeros.d.ts +10 -0
  105. package/lib/esm/types/helpers/padZerosLeft.d.ts +9 -0
  106. package/lib/esm/types/helpers/parseRequest.d.ts +21 -0
  107. package/lib/esm/types/helpers/roundToNumDecimals.d.ts +9 -0
  108. package/lib/esm/types/helpers/showFatalError.d.ts +2 -0
  109. package/lib/esm/types/helpers/sum.d.ts +8 -0
  110. package/lib/esm/types/helpers/visitServerEndpoint.d.ts +23 -0
  111. package/lib/esm/types/helpers/waitMs.d.ts +7 -0
  112. package/lib/esm/types/index.d.ts +22 -0
  113. package/lib/esm/types/types/ModalButtonType.d.ts +17 -0
  114. package/lib/esm/types/types/ModalSize.d.ts +11 -0
  115. package/lib/esm/types/types/ModalType.d.ts +16 -0
  116. package/lib/esm/types/types/ParamType.d.ts +17 -0
  117. package/lib/esm/types/types/ReactKitErrorCode.d.ts +13 -0
  118. package/lib/esm/types/types/Variant.d.ts +15 -0
  119. package/lib/index.d.ts +274 -0
  120. package/package.json +26 -5
  121. package/rollup.config.js +43 -0
  122. package/src/components/AppWrapper.tsx +212 -36
  123. package/src/components/LoadingSpinner.tsx +3 -0
  124. package/src/components/Modal.tsx +65 -95
  125. package/src/components/TabBox.tsx +136 -0
  126. package/src/helpers/abbreviate.tsx +2 -0
  127. package/src/helpers/padDecimalZeros.tsx +1 -1
  128. package/src/index.ts +61 -0
  129. package/src/types/ModalButtonType.tsx +18 -0
  130. package/src/types/ModalSize.tsx +12 -0
  131. package/src/types/ModalType.tsx +17 -0
  132. package/tsconfig.json +14 -17
  133. package/lib/components/AppWrapper.d.ts +0 -20
  134. package/lib/components/AppWrapper.js +0 -133
  135. package/lib/components/AppWrapper.js.map +0 -1
  136. package/lib/components/ErrorBox.js +0 -65
  137. package/lib/components/ErrorBox.js.map +0 -1
  138. package/lib/components/LoadingSpinner.js +0 -41
  139. package/lib/components/LoadingSpinner.js.map +0 -1
  140. package/lib/components/Modal.d.ts +0 -69
  141. package/lib/components/Modal.js +0 -315
  142. package/lib/components/Modal.js.map +0 -1
  143. package/lib/errors/ErrorWithCode.js +0 -33
  144. package/lib/errors/ErrorWithCode.js.map +0 -1
  145. package/lib/helpers/abbreviate.js +0 -21
  146. package/lib/helpers/abbreviate.js.map +0 -1
  147. package/lib/helpers/avg.js +0 -24
  148. package/lib/helpers/avg.js.map +0 -1
  149. package/lib/helpers/ceilToNumDecimals.js +0 -15
  150. package/lib/helpers/ceilToNumDecimals.js.map +0 -1
  151. package/lib/helpers/floorToNumDecimals.js +0 -15
  152. package/lib/helpers/floorToNumDecimals.js.map +0 -1
  153. package/lib/helpers/forceNumIntoBounds.js +0 -15
  154. package/lib/helpers/forceNumIntoBounds.js.map +0 -1
  155. package/lib/helpers/handleError.js +0 -54
  156. package/lib/helpers/handleError.js.map +0 -1
  157. package/lib/helpers/handleSuccess.js +0 -20
  158. package/lib/helpers/handleSuccess.js.map +0 -1
  159. package/lib/helpers/padDecimalZeros.js +0 -30
  160. package/lib/helpers/padDecimalZeros.js.map +0 -1
  161. package/lib/helpers/padZerosLeft.js +0 -21
  162. package/lib/helpers/padZerosLeft.js.map +0 -1
  163. package/lib/helpers/parseRequest.js +0 -240
  164. package/lib/helpers/parseRequest.js.map +0 -1
  165. package/lib/helpers/roundToNumDecimals.js +0 -15
  166. package/lib/helpers/roundToNumDecimals.js.map +0 -1
  167. package/lib/helpers/showFatalError.d.ts +0 -2
  168. package/lib/helpers/showFatalError.js +0 -5
  169. package/lib/helpers/showFatalError.js.map +0 -1
  170. package/lib/helpers/sum.js +0 -15
  171. package/lib/helpers/sum.js.map +0 -1
  172. package/lib/helpers/visitServerEndpoint.js +0 -135
  173. package/lib/helpers/visitServerEndpoint.js.map +0 -1
  174. package/lib/helpers/waitMs.js +0 -55
  175. package/lib/helpers/waitMs.js.map +0 -1
  176. package/lib/types/ParamType.js +0 -21
  177. package/lib/types/ParamType.js.map +0 -1
  178. package/lib/types/ReactKitErrorCode.js +0 -18
  179. package/lib/types/ReactKitErrorCode.js.map +0 -1
  180. package/lib/types/Variant.js +0 -19
  181. package/lib/types/Variant.js.map +0 -1
  182. package/src/helpers/handleError.ts +0 -65
  183. package/src/helpers/handleSuccess.ts +0 -18
  184. package/src/helpers/parseRequest.ts +0 -299
  185. package/src/helpers/showFatalError.tsx +0 -3
  186. package/src/helpers/visitServerEndpoint.tsx +0 -110
  187. package/src/types/ParamType.ts +0 -18
@@ -1,110 +0,0 @@
1
- // Initialize caccl
2
- import { sendRequest } from 'caccl/client';
3
-
4
- // Import custom error
5
- import ErrorWithCode from '../errors/ErrorWithCode';
6
- import ReactKitErrorCode from '../types/ReactKitErrorCode';
7
-
8
- /*------------------------------------------------------------------------*/
9
- /* Listener */
10
- /*------------------------------------------------------------------------*/
11
-
12
- // Handler for session expiry
13
- let sessionExpiryHandler: () => void;
14
-
15
- // Keep track of whether or not session expiry has already been handled
16
- let sessionAlreadyExpired = false;
17
-
18
- /**
19
- * Set the session expiry handler
20
- * @author Gabe Abrams
21
- * @param handler new handler to use when session expires
22
- */
23
- export const setSessionExpiryHandler = (handler: () => void) => {
24
- sessionExpiryHandler = handler;
25
- };
26
-
27
- /*------------------------------------------------------------------------*/
28
- /* Main */
29
- /*------------------------------------------------------------------------*/
30
-
31
- /**
32
- * Visit an endpoint on the server [for client only]
33
- * @author Gabe Abrams
34
- * @param opts object containing all arguments
35
- * @param opts.path - the path of the server endpoint
36
- * @param [opts.method=GET] - the method of the endpoint
37
- * @param [opts.params] - query/body parameters to include
38
- * @returns response from server
39
- */
40
- const visitServerEndpoint = async (
41
- opts: {
42
- path: string,
43
- method?: ('GET' | 'POST' | 'DELETE' | 'PUT'),
44
- params?: { [key in string]: any },
45
- },
46
- ): Promise<any> => {
47
- // Send the request
48
- const response = await sendRequest({
49
- path: opts.path,
50
- method: opts.method,
51
- params: opts.params,
52
- });
53
-
54
- // Check for failure
55
- if (!response || !response.body) {
56
- throw new ErrorWithCode(
57
- 'We didn\'t get a response from the server. Please check your internet connection.',
58
- ReactKitErrorCode.NoResponse,
59
- );
60
- }
61
- if (!response.body.success) {
62
- // Session expired
63
- if (response.body.code === ReactKitErrorCode.SessionExpired) {
64
- // Skip notice if session was already expired
65
- if (sessionAlreadyExpired) {
66
- // Never return (browser is already reloading)
67
- await new Promise<{ [key in string]: any }>(() => {
68
- // Promise that never returns
69
- });
70
- }
71
- sessionAlreadyExpired = true;
72
-
73
- // Show session expiration message
74
- if (sessionExpiryHandler) {
75
- // Use handler
76
- sessionExpiryHandler();
77
- } else {
78
- // Fallback to alert
79
-
80
- // eslint-disable-next-line no-alert
81
- alert('Your session has expired. Please start over.');
82
- }
83
-
84
- // Never return (don't continue execution)
85
- await new Promise<{ [key in string]: any }>(() => {
86
- // Promise that never returns
87
- });
88
- }
89
-
90
- // Other errors
91
- throw new ErrorWithCode(
92
- (
93
- response.body.message
94
- || 'An unknown error occurred. Please contact an admin.'
95
- ),
96
- (
97
- response.body.code
98
- || ReactKitErrorCode.NoCode
99
- ),
100
- );
101
- }
102
-
103
- // Success! Extract the body
104
- const { body } = response.body;
105
-
106
- // Return
107
- return body;
108
- };
109
-
110
- export default visitServerEndpoint;
@@ -1,18 +0,0 @@
1
- /**
2
- * API param types
3
- * @author Gabe Abrams
4
- */
5
- enum ParamType {
6
- Boolean = 'boolean', // Boolean
7
- BooleanOptional = 'boolean-optional', // Optional boolean
8
- Float = 'float', // Float Number
9
- FloatOptional = 'float-optional', // Optional Float Number
10
- Int = 'int', // Integer Number
11
- IntOptional = 'int-optional', // Optional Integer Number
12
- JSON = 'json', // JSONified object
13
- JSONOptional = 'json-optional', // Optional JSONified object
14
- String = 'string', // String
15
- StringOptional = 'string-optional', // Optional string
16
- }
17
-
18
- export default ParamType;