@carbonorm/carbonnode 5.0.0 → 6.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 (139) hide show
  1. package/dist/api/convertForRequestBody.d.ts +1 -1
  2. package/dist/api/restOrm.d.ts +6 -6
  3. package/dist/api/restRequest.d.ts +2 -2
  4. package/dist/{api/executors → executors}/HttpExecutor.d.ts +2 -2
  5. package/dist/{api/handlers → handlers}/ExpressHandler.d.ts +3 -3
  6. package/dist/index.cjs.js +229 -160
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.d.ts +30 -29
  9. package/dist/index.esm.js +225 -161
  10. package/dist/index.esm.js.map +1 -1
  11. package/dist/{api/types → types}/ormGenerics.d.ts +1 -1
  12. package/dist/{api/types → types}/ormInterfaces.d.ts +7 -6
  13. package/dist/{api/utils → utils}/apiHelpers.d.ts +2 -2
  14. package/dist/{api/utils → utils}/cacheManager.d.ts +2 -2
  15. package/dist/utils/sqlAllowList.d.ts +5 -0
  16. package/dist/utils/toastRuntime.d.ts +5 -0
  17. package/dist/variables/toastOptions.d.ts +10 -1
  18. package/package.json +2 -7
  19. package/scripts/assets/handlebars/C6.test.ts.handlebars +4 -8
  20. package/src/__tests__/binaryHex.e2e.test.ts +1 -1
  21. package/src/__tests__/cacheManager.test.ts +2 -3
  22. package/src/__tests__/expressServer.e2e.test.ts +1 -1
  23. package/src/__tests__/fixtures/c6.fixture.ts +1 -1
  24. package/src/__tests__/fixtures/createTestServer.ts +2 -2
  25. package/src/__tests__/fixtures/pu.fixture.ts +1 -2
  26. package/src/__tests__/httpExecutorSingular.e2e.test.ts +1 -1
  27. package/src/__tests__/normalizeSingularRequest.test.ts +3 -3
  28. package/src/__tests__/sakila-db/C6.js +1 -1
  29. package/src/__tests__/sakila-db/C6.mysqldump.json +1 -1
  30. package/src/__tests__/sakila-db/C6.mysqldump.sql +1 -1
  31. package/src/__tests__/sakila-db/C6.test.ts +4 -8
  32. package/src/__tests__/sakila-db/C6.ts +1 -1
  33. package/src/__tests__/sakila-db/sqlResponses/C6.actor.post.json +3 -3
  34. package/src/__tests__/sakila-db/sqlResponses/C6.actor.post.latest.json +3 -3
  35. package/src/__tests__/sakila-db/sqlResponses/C6.actor.put.json +1 -1
  36. package/src/__tests__/sakila-db/sqlResponses/C6.actor.put.lookup.json +3 -3
  37. package/src/__tests__/sakila-db/sqlResponses/C6.address.post.json +5 -5
  38. package/src/__tests__/sakila-db/sqlResponses/C6.address.post.latest.json +5 -5
  39. package/src/__tests__/sakila-db/sqlResponses/C6.address.put.json +1 -1
  40. package/src/__tests__/sakila-db/sqlResponses/C6.address.put.lookup.json +5 -5
  41. package/src/__tests__/sakila-db/sqlResponses/C6.category.post.json +2 -2
  42. package/src/__tests__/sakila-db/sqlResponses/C6.category.post.latest.json +2 -2
  43. package/src/__tests__/sakila-db/sqlResponses/C6.category.put.json +1 -1
  44. package/src/__tests__/sakila-db/sqlResponses/C6.category.put.lookup.json +2 -2
  45. package/src/__tests__/sakila-db/sqlResponses/C6.city.post.json +2 -2
  46. package/src/__tests__/sakila-db/sqlResponses/C6.city.post.latest.json +2 -2
  47. package/src/__tests__/sakila-db/sqlResponses/C6.city.put.json +1 -1
  48. package/src/__tests__/sakila-db/sqlResponses/C6.city.put.lookup.json +2 -2
  49. package/src/__tests__/sakila-db/sqlResponses/C6.country.post.json +2 -2
  50. package/src/__tests__/sakila-db/sqlResponses/C6.country.post.latest.json +2 -2
  51. package/src/__tests__/sakila-db/sqlResponses/C6.country.put.json +1 -1
  52. package/src/__tests__/sakila-db/sqlResponses/C6.country.put.lookup.json +2 -2
  53. package/src/__tests__/sakila-db/sqlResponses/C6.customer.post.json +5 -5
  54. package/src/__tests__/sakila-db/sqlResponses/C6.customer.post.latest.json +5 -5
  55. package/src/__tests__/sakila-db/sqlResponses/C6.customer.put.json +1 -1
  56. package/src/__tests__/sakila-db/sqlResponses/C6.customer.put.lookup.json +5 -5
  57. package/src/__tests__/sakila-db/sqlResponses/C6.film.post.json +2 -2
  58. package/src/__tests__/sakila-db/sqlResponses/C6.film.post.latest.json +2 -2
  59. package/src/__tests__/sakila-db/sqlResponses/C6.film.put.json +1 -1
  60. package/src/__tests__/sakila-db/sqlResponses/C6.film.put.lookup.json +2 -2
  61. package/src/__tests__/sakila-db/sqlResponses/C6.inventory.post.json +1 -1
  62. package/src/__tests__/sakila-db/sqlResponses/C6.inventory.post.latest.json +1 -1
  63. package/src/__tests__/sakila-db/sqlResponses/C6.inventory.put.json +1 -1
  64. package/src/__tests__/sakila-db/sqlResponses/C6.inventory.put.lookup.json +1 -1
  65. package/src/__tests__/sakila-db/sqlResponses/C6.language.post.json +2 -2
  66. package/src/__tests__/sakila-db/sqlResponses/C6.language.post.latest.json +2 -2
  67. package/src/__tests__/sakila-db/sqlResponses/C6.language.put.json +1 -1
  68. package/src/__tests__/sakila-db/sqlResponses/C6.language.put.lookup.json +2 -2
  69. package/src/__tests__/sakila-db/sqlResponses/C6.payment.post.json +2 -2
  70. package/src/__tests__/sakila-db/sqlResponses/C6.payment.post.latest.json +2 -2
  71. package/src/__tests__/sakila-db/sqlResponses/C6.payment.put.lookup.json +2 -2
  72. package/src/__tests__/sakila-db/sqlResponses/C6.rental.post.json +3 -3
  73. package/src/__tests__/sakila-db/sqlResponses/C6.rental.post.latest.json +3 -3
  74. package/src/__tests__/sakila-db/sqlResponses/C6.rental.put.json +1 -1
  75. package/src/__tests__/sakila-db/sqlResponses/C6.rental.put.lookup.json +3 -3
  76. package/src/__tests__/sqlAllowList.test.ts +67 -74
  77. package/src/__tests__/sqlBuilders.complex.test.ts +3 -3
  78. package/src/__tests__/sqlBuilders.expressions.test.ts +2 -2
  79. package/src/__tests__/sqlBuilders.test.ts +5 -5
  80. package/src/__tests__/toastRuntime.test.ts +22 -0
  81. package/src/api/convertForRequestBody.ts +2 -2
  82. package/src/api/restOrm.ts +2 -2
  83. package/src/api/restRequest.ts +4 -5
  84. package/src/{api/executors → executors}/HttpExecutor.ts +21 -13
  85. package/src/{api/executors → executors}/SqlExecutor.ts +2 -2
  86. package/src/{api/handlers → handlers}/ExpressHandler.ts +5 -5
  87. package/src/index.ts +30 -29
  88. package/src/{api/orm → orm}/builders/AggregateBuilder.ts +1 -1
  89. package/src/{api/orm → orm}/builders/ConditionBuilder.ts +1 -1
  90. package/src/{api/orm → orm}/builders/JoinBuilder.ts +1 -1
  91. package/src/{api/orm → orm}/builders/PaginationBuilder.ts +1 -1
  92. package/src/{api/orm → orm}/queries/PostQueryBuilder.ts +1 -1
  93. package/src/{api/orm → orm}/queries/UpdateQueryBuilder.ts +1 -1
  94. package/src/{api/orm → orm}/queryHelpers.ts +1 -2
  95. package/src/{api/types → types}/ormGenerics.ts +1 -1
  96. package/src/{api/types → types}/ormInterfaces.ts +8 -6
  97. package/src/{api/utils → utils}/apiHelpers.ts +8 -8
  98. package/src/{api/utils → utils}/cacheManager.ts +2 -2
  99. package/src/{api/utils → utils}/normalizeSingularRequest.ts +1 -1
  100. package/src/utils/sqlAllowList.ts +120 -0
  101. package/src/{api/utils → utils}/testHelpers.ts +1 -1
  102. package/src/{api/utils → utils}/toastNotifier.ts +3 -3
  103. package/src/utils/toastRuntime.ts +22 -0
  104. package/src/variables/toastOptions.ts +10 -3
  105. package/dist/api/utils/sqlAllowList.d.ts +0 -2
  106. package/src/api/utils/sqlAllowList.ts +0 -54
  107. /package/dist/{api → constants}/C6Constants.d.ts +0 -0
  108. /package/dist/{api/executors → executors}/Executor.d.ts +0 -0
  109. /package/dist/{api/executors → executors}/SqlExecutor.d.ts +0 -0
  110. /package/dist/{api/orm → orm}/builders/AggregateBuilder.d.ts +0 -0
  111. /package/dist/{api/orm → orm}/builders/ConditionBuilder.d.ts +0 -0
  112. /package/dist/{api/orm → orm}/builders/JoinBuilder.d.ts +0 -0
  113. /package/dist/{api/orm → orm}/builders/PaginationBuilder.d.ts +0 -0
  114. /package/dist/{api/orm → orm}/queries/DeleteQueryBuilder.d.ts +0 -0
  115. /package/dist/{api/orm → orm}/queries/PostQueryBuilder.d.ts +0 -0
  116. /package/dist/{api/orm → orm}/queries/SelectQueryBuilder.d.ts +0 -0
  117. /package/dist/{api/orm → orm}/queries/UpdateQueryBuilder.d.ts +0 -0
  118. /package/dist/{api/orm → orm}/queryHelpers.d.ts +0 -0
  119. /package/dist/{api/orm → orm}/utils/sqlUtils.d.ts +0 -0
  120. /package/dist/{api/types → types}/dynamicFetching.d.ts +0 -0
  121. /package/dist/{api/types → types}/modifyTypes.d.ts +0 -0
  122. /package/dist/{api/types → types}/mysqlTypes.d.ts +0 -0
  123. /package/dist/{api/utils → utils}/determineRuntimeJsType.d.ts +0 -0
  124. /package/dist/{api/utils → utils}/logger.d.ts +0 -0
  125. /package/dist/{api/utils → utils}/normalizeSingularRequest.d.ts +0 -0
  126. /package/dist/{api/utils → utils}/sortAndSerializeQueryObject.d.ts +0 -0
  127. /package/dist/{api/utils → utils}/testHelpers.d.ts +0 -0
  128. /package/dist/{api/utils → utils}/toastNotifier.d.ts +0 -0
  129. /package/src/{api → constants}/C6Constants.ts +0 -0
  130. /package/src/{api/executors → executors}/Executor.ts +0 -0
  131. /package/src/{api/orm → orm}/queries/DeleteQueryBuilder.ts +0 -0
  132. /package/src/{api/orm → orm}/queries/SelectQueryBuilder.ts +0 -0
  133. /package/src/{api/orm → orm}/utils/sqlUtils.ts +0 -0
  134. /package/src/{api/types → types}/dynamicFetching.ts +0 -0
  135. /package/src/{api/types → types}/modifyTypes.ts +0 -0
  136. /package/src/{api/types → types}/mysqlTypes.ts +0 -0
  137. /package/src/{api/utils → utils}/determineRuntimeJsType.ts +0 -0
  138. /package/src/{api/utils → utils}/logger.ts +0 -0
  139. /package/src/{api/utils → utils}/sortAndSerializeQueryObject.ts +0 -0
@@ -1,4 +1,4 @@
1
- import { iC6Object, iRestMethods, RequestQueryBody } from "./types/ormInterfaces";
1
+ import { iC6Object, iRestMethods, RequestQueryBody } from "../types/ormInterfaces";
2
2
  export default function <RequestMethod extends iRestMethods, RestTableInterface extends {
3
3
  [key: string]: any;
4
4
  }, CustomAndRequiredFields extends {
@@ -1,12 +1,12 @@
1
- import { OrmGenerics } from "./types/ormGenerics";
2
- import { iRest, iRestMethods } from "./types/ormInterfaces";
1
+ import { OrmGenerics } from "../types/ormGenerics";
2
+ import { iRest, iRestMethods } from "../types/ormInterfaces";
3
3
  type WithMethod<G extends Omit<OrmGenerics, "RequestMethod">, M extends iRestMethods> = Omit<G, "RequestMethod"> & {
4
4
  RequestMethod: M;
5
5
  };
6
6
  export declare function restOrm<G extends Omit<OrmGenerics, "RequestMethod">>(configFn: () => Omit<iRest<G['RestShortTableName'], G['RestTableInterface'], G['PrimaryKey']>, "requestMethod">): {
7
- Get: (request: import("./types/ormInterfaces").RequestQueryBody<WithMethod<G, "GET">["RequestMethod"], WithMethod<G, "GET">["RestTableInterface"], WithMethod<G, "GET">["CustomAndRequiredFields"], WithMethod<G, "GET">["RequestTableOverrides"]>) => Promise<import("./types/ormInterfaces").DetermineResponseDataType<WithMethod<G, "GET">["RequestMethod"], WithMethod<G, "GET">["RestTableInterface"], {}>>;
8
- Put: (request: import("./types/ormInterfaces").RequestQueryBody<WithMethod<G, "PUT">["RequestMethod"], WithMethod<G, "PUT">["RestTableInterface"], WithMethod<G, "PUT">["CustomAndRequiredFields"], WithMethod<G, "PUT">["RequestTableOverrides"]>) => Promise<import("./types/ormInterfaces").DetermineResponseDataType<WithMethod<G, "PUT">["RequestMethod"], WithMethod<G, "PUT">["RestTableInterface"], {}>>;
9
- Post: (request: import("./types/ormInterfaces").RequestQueryBody<WithMethod<G, "POST">["RequestMethod"], WithMethod<G, "POST">["RestTableInterface"], WithMethod<G, "POST">["CustomAndRequiredFields"], WithMethod<G, "POST">["RequestTableOverrides"]>) => Promise<import("./types/ormInterfaces").DetermineResponseDataType<WithMethod<G, "POST">["RequestMethod"], WithMethod<G, "POST">["RestTableInterface"], {}>>;
10
- Delete: (request: import("./types/ormInterfaces").RequestQueryBody<WithMethod<G, "DELETE">["RequestMethod"], WithMethod<G, "DELETE">["RestTableInterface"], WithMethod<G, "DELETE">["CustomAndRequiredFields"], WithMethod<G, "DELETE">["RequestTableOverrides"]>) => Promise<import("./types/ormInterfaces").DetermineResponseDataType<WithMethod<G, "DELETE">["RequestMethod"], WithMethod<G, "DELETE">["RestTableInterface"], {}>>;
7
+ Get: (request: import("../types/ormInterfaces").RequestQueryBody<WithMethod<G, "GET">["RequestMethod"], WithMethod<G, "GET">["RestTableInterface"], WithMethod<G, "GET">["CustomAndRequiredFields"], WithMethod<G, "GET">["RequestTableOverrides"]>) => Promise<import("../types/ormInterfaces").DetermineResponseDataType<WithMethod<G, "GET">["RequestMethod"], WithMethod<G, "GET">["RestTableInterface"], {}>>;
8
+ Put: (request: import("../types/ormInterfaces").RequestQueryBody<WithMethod<G, "PUT">["RequestMethod"], WithMethod<G, "PUT">["RestTableInterface"], WithMethod<G, "PUT">["CustomAndRequiredFields"], WithMethod<G, "PUT">["RequestTableOverrides"]>) => Promise<import("../types/ormInterfaces").DetermineResponseDataType<WithMethod<G, "PUT">["RequestMethod"], WithMethod<G, "PUT">["RestTableInterface"], {}>>;
9
+ Post: (request: import("../types/ormInterfaces").RequestQueryBody<WithMethod<G, "POST">["RequestMethod"], WithMethod<G, "POST">["RestTableInterface"], WithMethod<G, "POST">["CustomAndRequiredFields"], WithMethod<G, "POST">["RequestTableOverrides"]>) => Promise<import("../types/ormInterfaces").DetermineResponseDataType<WithMethod<G, "POST">["RequestMethod"], WithMethod<G, "POST">["RestTableInterface"], {}>>;
10
+ Delete: (request: import("../types/ormInterfaces").RequestQueryBody<WithMethod<G, "DELETE">["RequestMethod"], WithMethod<G, "DELETE">["RestTableInterface"], WithMethod<G, "DELETE">["CustomAndRequiredFields"], WithMethod<G, "DELETE">["RequestTableOverrides"]>) => Promise<import("../types/ormInterfaces").DetermineResponseDataType<WithMethod<G, "DELETE">["RequestMethod"], WithMethod<G, "DELETE">["RestTableInterface"], {}>>;
11
11
  };
12
12
  export {};
@@ -1,5 +1,5 @@
1
- import { OrmGenerics } from "./types/ormGenerics";
2
- import { DetermineResponseDataType, iRest, RequestQueryBody } from "./types/ormInterfaces";
1
+ import { OrmGenerics } from "../types/ormGenerics";
2
+ import { DetermineResponseDataType, iRest, RequestQueryBody } from "../types/ormInterfaces";
3
3
  /**
4
4
  * Facade: routes API calls to SQL or HTTP executors based on runtime context.
5
5
  */
@@ -1,5 +1,5 @@
1
- import { AxiosResponse } from "axios";
2
- import { OrmGenerics } from "../types/ormGenerics";
1
+ import type { AxiosResponse } from "axios";
2
+ import type { OrmGenerics } from "../types/ormGenerics";
3
3
  import { DetermineResponseDataType, RequestQueryBody } from "../types/ormInterfaces";
4
4
  import { Executor } from "./Executor";
5
5
  export declare class HttpExecutor<G extends OrmGenerics> extends Executor<G> {
@@ -1,6 +1,6 @@
1
- import { Request, Response, NextFunction } from "express";
2
- import { Pool } from "mysql2/promise";
3
- import { iC6Object } from "../types/ormInterfaces";
1
+ import type { Request, Response, NextFunction } from "express";
2
+ import type { Pool } from "mysql2/promise";
3
+ import type { iC6Object } from "../types/ormInterfaces";
4
4
  export declare function ExpressHandler({ C6, mysqlPool, sqlAllowListPath, }: {
5
5
  C6: iC6Object;
6
6
  mysqlPool: Pool;
package/dist/index.cjs.js CHANGED
@@ -3,11 +3,157 @@
3
3
  var axios = require('axios');
4
4
  var Qs = require('qs');
5
5
  var tslib = require('tslib');
6
- var reactToastify = require('react-toastify');
7
6
  var namedPlaceholders = require('named-placeholders');
8
7
  var buffer = require('buffer');
9
8
 
10
9
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
10
+ // @link https://www.npmjs.com/package/axios-cache-adapter
11
+ var carbonNodeQsStringify = function (params) {
12
+ return Qs.stringify(params, {
13
+ arrayFormat: "indices",
14
+ indices: true,
15
+ skipNulls: false,
16
+ strictNullHandling: true,
17
+ });
18
+ };
19
+ // updating these values
20
+ // @link https://github.com/axios/axios/issues/209
21
+ //
22
+ // only affects the global instance and instances created afterwards
23
+ // axios.defaults.headers.common['Auth-Token'] = 'foo bar';
24
+ //
25
+ // immediately affects this instance
26
+ // axiosInstance.defaults.headers['Auth-Token'] = 'foo bar';
27
+ var axiosInstance = (axios.create({
28
+ // `baseURL` will be prepended to `url` unless `url` is absolute.
29
+ // It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
30
+ // to methods of that instance.
31
+ baseURL: '',
32
+ /**
33
+ * These headers are important to C6.
34
+ * XMLHttpRequest - is a standard header all jquery ajax requests send by default. This allows our php side to return
35
+ * nothing while running the get_header() and get_footer() functions with (bool) DropVariables::$ajax;
36
+ *
37
+ * application/json - is for the error catcher in php; this header will cause a JSON response instead of the default HTML
38
+ */
39
+ headers: {
40
+ crossDomain: true,
41
+ 'Access-Control-Allow-Credentials': true,
42
+ 'X-Requested-With': 'XMLHttpRequest',
43
+ 'Content-Type': 'application/json',
44
+ },
45
+ // `paramsSerializer` is an optional function in charge of serializing `params`
46
+ // (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/)
47
+ paramsSerializer: function (params) {
48
+ // Nested get params [][][,,,] do not serialize correctly without Qs
49
+ return carbonNodeQsStringify(params);
50
+ },
51
+ // `data` is the data to be sent as the request body
52
+ // Only applicable for request methods 'PUT', 'POST', and 'PATCH'
53
+ // When no `transformRequest` is set, must be of one of the following types:
54
+ // - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams
55
+ // - Browser only: FormData, File, Blob
56
+ // - Node only: Stream, Buffer
57
+ // data should be default to empty for get request to serialize correctly
58
+ data: {}, // do not change
59
+ // `timeout` specifies the number of milliseconds before the request times out.
60
+ // If the request takes longer than `timeout`, the request will be aborted.
61
+ // Default is 1000 - lets increase this for large request which we are favored for
62
+ timeout: 120000, // shit fails
63
+ // `withCredentials` indicates weather cross-site Access-Control requests
64
+ // should be made using credentials
65
+ withCredentials: true,
66
+ // `adapter` allows custom handling of requests which makes testing easier.
67
+ // Return a promise and supply a valid response (see lib/adapters/README.md).
68
+ // adapter: cache.adapter,
69
+ // `auth` indicates that HTTP Basic auth should be used, and supplies credentials.
70
+ // This will set an `Authorization` header, overwriting any existing
71
+ // `Authorization` custom headers you have set using `headers`.
72
+ /*
73
+ auth: {
74
+ username: 'janedoe',
75
+ password: 's00pers3cret'
76
+ },
77
+ */
78
+ // `responseType` indicates the type of data that the server will respond with
79
+ // options are 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream'
80
+ // responseType: 'json', // default
81
+ // `responseEncoding` indicates encoding to use for decoding responses
82
+ // Note: Ignored for `responseType` of 'stream' or client-side requests
83
+ // `xsrfCookieName` is the name of the cookie to use as a value for xsrf token
84
+ //xsrfCookieName: 'XSRF-TOKEN', // default
85
+ // `xsrfHeaderName` is the name of the http header that carries the xsrf token value
86
+ //xsrfHeaderName: 'X-XSRF-TOKEN', // default
87
+ // `onUploadProgress` allows handling of progress events for uploads
88
+ onUploadProgress: function () {
89
+ // Do whatever you want with the native progress event
90
+ },
91
+ // `onDownloadProgress` allows handling of progress events for downloads
92
+ onDownloadProgress: function () {
93
+ // Do whatever you want with the native progress event
94
+ },
95
+ // `maxContentLength` defines the max size of the http response content in bytes allowed
96
+ /*maxContentLength: 2000,*/
97
+ // `validateStatus` defines whether to resolve or reject the promise for a given
98
+ // HTTP response status code. If `validateStatus` returns `true` (or is set to `null`
99
+ // or `undefined`), the promise will be resolved; otherwise, the promise will be
100
+ // rejected.
101
+ /* validateStatus: function (status) {
102
+ return status >= 200 && status < 300;
103
+ },*/
104
+ // `maxRedirects` defines the maximum number of redirects to follow in node.js.
105
+ // If set to 0, no redirects will be followed.
106
+ maxRedirects: 2, // default
107
+ // `socketPath` defines a UNIX Socket to be used in node.js.
108
+ // e.g. '/var/run/docker.sock' to send requests to the docker daemon.
109
+ // Only either `socketPath` or `proxy` can be specified.
110
+ // If both are specified, `socketPath` is used.
111
+ socketPath: null, // default
112
+ // `httpAgent` and `httpsAgent` define a custom agent to be used when performing http
113
+ // and https requests, respectively, in node.js. This allows options to be added like
114
+ // `keepAlive` that are not enabled by default.
115
+ /*
116
+ httpAgent: new http.Agent({ keepAlive: true }),
117
+ httpsAgent: new https.Agent({ keepAlive: true }),
118
+ */
119
+ }));
120
+ axiosInstance.interceptors.request.use(function (config) {
121
+ if (config.params) {
122
+ var serialized = carbonNodeQsStringify(config.params);
123
+ if (serialized.length > 2000) {
124
+ // Move params into body but keep track of intended method
125
+ config.method = "post";
126
+ config.data = config.params;
127
+ config.params = {
128
+ METHOD: "GET", // 👈 explicit signal for your REST parser
129
+ };
130
+ }
131
+ }
132
+ config.__carbonStart = performance.now();
133
+ return config;
134
+ });
135
+ axiosInstance.interceptors.response.use(function (response) {
136
+ var end = performance.now();
137
+ var start = response.config.__carbonStart;
138
+ response.__carbonTiming = {
139
+ start: start,
140
+ end: end,
141
+ duration: end - start,
142
+ };
143
+ return response;
144
+ }, function (error) {
145
+ if (error.config) {
146
+ var end = performance.now();
147
+ var start = error.config.__carbonStart;
148
+ error.__carbonTiming = {
149
+ start: start,
150
+ end: end,
151
+ duration: end - start,
152
+ };
153
+ }
154
+ throw error;
155
+ });
156
+
11
157
  var C6Constants = {
12
158
  // try to 1=1 match the Rest abstract class
13
159
  ADDDATE: 'ADDDATE',
@@ -185,153 +331,6 @@ var C6Constants = {
185
331
  };
186
332
  var C6C = C6Constants;
187
333
 
188
- // @link https://www.npmjs.com/package/axios-cache-adapter
189
- var carbonNodeQsStringify = function (params) {
190
- return Qs.stringify(params, {
191
- arrayFormat: "indices",
192
- indices: true,
193
- skipNulls: false,
194
- strictNullHandling: true,
195
- });
196
- };
197
- // updating these values
198
- // @link https://github.com/axios/axios/issues/209
199
- //
200
- // only affects the global instance and instances created afterwards
201
- // axios.defaults.headers.common['Auth-Token'] = 'foo bar';
202
- //
203
- // immediately affects this instance
204
- // axiosInstance.defaults.headers['Auth-Token'] = 'foo bar';
205
- var axiosInstance = (axios.create({
206
- // `baseURL` will be prepended to `url` unless `url` is absolute.
207
- // It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
208
- // to methods of that instance.
209
- baseURL: '',
210
- /**
211
- * These headers are important to C6.
212
- * XMLHttpRequest - is a standard header all jquery ajax requests send by default. This allows our php side to return
213
- * nothing while running the get_header() and get_footer() functions with (bool) DropVariables::$ajax;
214
- *
215
- * application/json - is for the error catcher in php; this header will cause a JSON response instead of the default HTML
216
- */
217
- headers: {
218
- crossDomain: true,
219
- 'Access-Control-Allow-Credentials': true,
220
- 'X-Requested-With': 'XMLHttpRequest',
221
- 'Content-Type': 'application/json',
222
- },
223
- // `paramsSerializer` is an optional function in charge of serializing `params`
224
- // (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/)
225
- paramsSerializer: function (params) {
226
- // Nested get params [][][,,,] do not serialize correctly without Qs
227
- return carbonNodeQsStringify(params);
228
- },
229
- // `data` is the data to be sent as the request body
230
- // Only applicable for request methods 'PUT', 'POST', and 'PATCH'
231
- // When no `transformRequest` is set, must be of one of the following types:
232
- // - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams
233
- // - Browser only: FormData, File, Blob
234
- // - Node only: Stream, Buffer
235
- // data should be default to empty for get request to serialize correctly
236
- data: {}, // do not change
237
- // `timeout` specifies the number of milliseconds before the request times out.
238
- // If the request takes longer than `timeout`, the request will be aborted.
239
- // Default is 1000 - lets increase this for large request which we are favored for
240
- timeout: 120000, // shit fails
241
- // `withCredentials` indicates weather cross-site Access-Control requests
242
- // should be made using credentials
243
- withCredentials: true,
244
- // `adapter` allows custom handling of requests which makes testing easier.
245
- // Return a promise and supply a valid response (see lib/adapters/README.md).
246
- // adapter: cache.adapter,
247
- // `auth` indicates that HTTP Basic auth should be used, and supplies credentials.
248
- // This will set an `Authorization` header, overwriting any existing
249
- // `Authorization` custom headers you have set using `headers`.
250
- /*
251
- auth: {
252
- username: 'janedoe',
253
- password: 's00pers3cret'
254
- },
255
- */
256
- // `responseType` indicates the type of data that the server will respond with
257
- // options are 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream'
258
- // responseType: 'json', // default
259
- // `responseEncoding` indicates encoding to use for decoding responses
260
- // Note: Ignored for `responseType` of 'stream' or client-side requests
261
- // `xsrfCookieName` is the name of the cookie to use as a value for xsrf token
262
- //xsrfCookieName: 'XSRF-TOKEN', // default
263
- // `xsrfHeaderName` is the name of the http header that carries the xsrf token value
264
- //xsrfHeaderName: 'X-XSRF-TOKEN', // default
265
- // `onUploadProgress` allows handling of progress events for uploads
266
- onUploadProgress: function () {
267
- // Do whatever you want with the native progress event
268
- },
269
- // `onDownloadProgress` allows handling of progress events for downloads
270
- onDownloadProgress: function () {
271
- // Do whatever you want with the native progress event
272
- },
273
- // `maxContentLength` defines the max size of the http response content in bytes allowed
274
- /*maxContentLength: 2000,*/
275
- // `validateStatus` defines whether to resolve or reject the promise for a given
276
- // HTTP response status code. If `validateStatus` returns `true` (or is set to `null`
277
- // or `undefined`), the promise will be resolved; otherwise, the promise will be
278
- // rejected.
279
- /* validateStatus: function (status) {
280
- return status >= 200 && status < 300;
281
- },*/
282
- // `maxRedirects` defines the maximum number of redirects to follow in node.js.
283
- // If set to 0, no redirects will be followed.
284
- maxRedirects: 2, // default
285
- // `socketPath` defines a UNIX Socket to be used in node.js.
286
- // e.g. '/var/run/docker.sock' to send requests to the docker daemon.
287
- // Only either `socketPath` or `proxy` can be specified.
288
- // If both are specified, `socketPath` is used.
289
- socketPath: null, // default
290
- // `httpAgent` and `httpsAgent` define a custom agent to be used when performing http
291
- // and https requests, respectively, in node.js. This allows options to be added like
292
- // `keepAlive` that are not enabled by default.
293
- /*
294
- httpAgent: new http.Agent({ keepAlive: true }),
295
- httpsAgent: new https.Agent({ keepAlive: true }),
296
- */
297
- }));
298
- axiosInstance.interceptors.request.use(function (config) {
299
- if (config.params) {
300
- var serialized = carbonNodeQsStringify(config.params);
301
- if (serialized.length > 2000) {
302
- // Move params into body but keep track of intended method
303
- config.method = "post";
304
- config.data = config.params;
305
- config.params = {
306
- METHOD: "GET", // 👈 explicit signal for your REST parser
307
- };
308
- }
309
- }
310
- config.__carbonStart = performance.now();
311
- return config;
312
- });
313
- axiosInstance.interceptors.response.use(function (response) {
314
- var end = performance.now();
315
- var start = response.config.__carbonStart;
316
- response.__carbonTiming = {
317
- start: start,
318
- end: end,
319
- duration: end - start,
320
- };
321
- return response;
322
- }, function (error) {
323
- if (error.config) {
324
- var end = performance.now();
325
- var start = error.config.__carbonStart;
326
- error.__carbonTiming = {
327
- start: start,
328
- end: end,
329
- duration: end - start,
330
- };
331
- }
332
- throw error;
333
- });
334
-
335
334
  function convertForRequestBody (restfulObject, tableName, C6, regexErrorHandler) {
336
335
  if (regexErrorHandler === void 0) { regexErrorHandler = alert; }
337
336
  var payload = {};
@@ -605,6 +604,14 @@ var toastOptionsDevs = {
605
604
  theme: "dark",
606
605
  };
607
606
 
607
+ var toastHandler = null;
608
+ var setToastHandler = function (handler) {
609
+ toastHandler = handler;
610
+ };
611
+ var notifyToast = function (level, message, options) {
612
+ toastHandler === null || toastHandler === void 0 ? void 0 : toastHandler(level, message, options);
613
+ };
614
+
608
615
  // When we capture DropExceptions and display them as a custom page, this will change.
609
616
  function TestRestfulResponse(response, success, error) {
610
617
  var _a, _b, _c, _d, _e, _f, _g, _h;
@@ -615,14 +622,14 @@ function TestRestfulResponse(response, success, error) {
615
622
  || undefined !== ((_e = response.data) === null || _e === void 0 ? void 0 : _e.deleted))) {
616
623
  var successReturn = 'function' === typeof success ? success === null || success === void 0 ? void 0 : success(response) : success;
617
624
  if (typeof successReturn === 'string') {
618
- reactToastify.toast.success(successReturn, toastOptions);
625
+ notifyToast("success", successReturn, toastOptions);
619
626
  }
620
627
  // this could end up with bad results for deleting id's === 0
621
628
  return (_h = (_g = (_f = response.data.created) !== null && _f !== void 0 ? _f : response.data.updated) !== null && _g !== void 0 ? _g : response.data.deleted) !== null && _h !== void 0 ? _h : true;
622
629
  }
623
630
  var errorReturn = 'function' === typeof error ? error === null || error === void 0 ? void 0 : error(response) : error;
624
631
  if (typeof errorReturn === 'string') {
625
- reactToastify.toast.error(errorReturn, toastOptions);
632
+ notifyToast("error", errorReturn, toastOptions);
626
633
  }
627
634
  return false;
628
635
  }
@@ -874,10 +881,10 @@ var HttpExecutor = /** @class */ (function (_super) {
874
881
  cachingConfirmed = true;
875
882
  }
876
883
  else if (debug && isLocal()) {
877
- reactToastify.toast.info("DEVS: Ignore cache was set to true.", toastOptionsDevs);
884
+ notifyToast("info", "DEVS: Ignore cache was set to true.", toastOptionsDevs);
878
885
  }
879
886
  if (cacheResults && debug && isLocal()) {
880
- reactToastify.toast.success("DEVS: Request not in cache." + (requestMethod === C6.GET ? " Page (" + query[C6.PAGINATION][C6.PAGE] + ")" : ''), toastOptionsDevs);
887
+ notifyToast("success", "DEVS: Request not in cache." + (requestMethod === C6.GET ? " Page (" + query[C6.PAGINATION][C6.PAGE] + ")" : ''), toastOptionsDevs);
881
888
  }
882
889
  restRequestUri = restURL + operatingTable + '/';
883
890
  needsConditionOrPrimaryCheck = (PUT === requestMethod || DELETE === requestMethod)
@@ -902,13 +909,13 @@ var HttpExecutor = /** @class */ (function (_super) {
902
909
  || null === query
903
910
  || (!(primaryKey in query) && !(primaryKeyFullyQualified && primaryKeyFullyQualified in query))) {
904
911
  if (true === debug && isLocal()) {
905
- reactToastify.toast.error('DEVS: The primary key (' + primaryKey + ') was not provided!!');
912
+ notifyToast("error", "DEVS: The primary key (".concat(primaryKey, ") was not provided!!"));
906
913
  }
907
914
  throw Error('You must provide the primary key (' + primaryKey + ') for table (' + operatingTable + '). Request (' + JSON.stringify(this.request, undefined, 4) + ') Query (' + JSON.stringify(query) + ')');
908
915
  }
909
916
  providedPrimary = (_k = query === null || query === void 0 ? void 0 : query[primaryKey]) !== null && _k !== void 0 ? _k : (primaryKeyFullyQualified ? query === null || query === void 0 ? void 0 : query[primaryKeyFullyQualified] : undefined);
910
917
  if (undefined === providedPrimary || null === providedPrimary) {
911
- reactToastify.toast.error('The primary key (' + primaryKey + ') provided is undefined or null explicitly!!');
918
+ notifyToast("error", "The primary key (".concat(primaryKey, ") provided is undefined or null explicitly!!"));
912
919
  throw Error('The primary key (' + primaryKey + ') provided in the request was exactly equal to undefined.');
913
920
  }
914
921
  }
@@ -950,7 +957,7 @@ var HttpExecutor = /** @class */ (function (_super) {
950
957
  });
951
958
  axiosActiveRequest_1 = (_e = axios)[requestMethod.toLowerCase()].apply(_e, tslib.__spreadArray([restRequestUri], (function () {
952
959
  var convert = function (data) {
953
- return convertForRequestBody(data, fullTableList, C6, function (message) { return reactToastify.toast.error(message, toastOptions); });
960
+ return convertForRequestBody(data, fullTableList, C6, function (message) { return notifyToast("error", message, toastOptions); });
954
961
  };
955
962
  var baseConfig = {
956
963
  withCredentials: withCredentials,
@@ -1020,7 +1027,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1020
1027
  apiResponse = TestRestfulResponse(response, success, error);
1021
1028
  if (false === apiResponse) {
1022
1029
  if (debug && isLocal()) {
1023
- reactToastify.toast.warning("DEVS: TestRestfulResponse returned false.", toastOptionsDevs);
1030
+ notifyToast("warning", "DEVS: TestRestfulResponse returned false.", toastOptionsDevs);
1024
1031
  }
1025
1032
  // Force a null payload so the final .then(response => response.data) yields null
1026
1033
  return [2 /*return*/, Promise.resolve(tslib.__assign(tslib.__assign({}, response), { data: null }))];
@@ -1254,7 +1261,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1254
1261
  });
1255
1262
  }
1256
1263
  if (debug && isLocal()) {
1257
- reactToastify.toast.success("DEVS: (" + requestMethod + ") request complete.", toastOptionsDevs);
1264
+ notifyToast("success", "DEVS: (".concat(requestMethod, ") request complete."), toastOptionsDevs);
1258
1265
  }
1259
1266
  // this is the literal axios return
1260
1267
  return [2 /*return*/, response];
@@ -3019,6 +3026,63 @@ var loadSqlAllowList = function (allowListPath) { return tslib.__awaiter(void 0,
3019
3026
  }
3020
3027
  });
3021
3028
  }); };
3029
+ var extractSqlEntries = function (payload) {
3030
+ if (typeof payload === "string") {
3031
+ return [payload];
3032
+ }
3033
+ if (Array.isArray(payload)) {
3034
+ return payload.flatMap(extractSqlEntries);
3035
+ }
3036
+ if (!payload || typeof payload !== "object") {
3037
+ return [];
3038
+ }
3039
+ var sqlValue = payload.sql;
3040
+ if (typeof sqlValue === "string") {
3041
+ return [sqlValue];
3042
+ }
3043
+ if (sqlValue && typeof sqlValue === "object") {
3044
+ var nested = sqlValue.sql;
3045
+ if (typeof nested === "string") {
3046
+ return [nested];
3047
+ }
3048
+ }
3049
+ return [];
3050
+ };
3051
+ var collectSqlAllowListEntries = function (payload, entries) {
3052
+ if (entries === void 0) { entries = new Set(); }
3053
+ var sqlEntries = extractSqlEntries(payload)
3054
+ .map(normalizeSql)
3055
+ .filter(function (entry) { return entry.length > 0; });
3056
+ sqlEntries.forEach(function (entry) { return entries.add(entry); });
3057
+ return entries;
3058
+ };
3059
+ var compileSqlAllowList = function (allowListPath, entries) { return tslib.__awaiter(void 0, void 0, void 0, function () {
3060
+ var _a, writeFile, mkdir, path, compiled;
3061
+ return tslib.__generator(this, function (_b) {
3062
+ switch (_b.label) {
3063
+ case 0:
3064
+ if (!isNode()) {
3065
+ throw new Error("SQL allowlist compilation requires a Node runtime.");
3066
+ }
3067
+ return [4 /*yield*/, import('node:fs/promises')];
3068
+ case 1:
3069
+ _a = _b.sent(), writeFile = _a.writeFile, mkdir = _a.mkdir;
3070
+ return [4 /*yield*/, import('node:path')];
3071
+ case 2:
3072
+ path = _b.sent();
3073
+ return [4 /*yield*/, mkdir(path.dirname(allowListPath), { recursive: true })];
3074
+ case 3:
3075
+ _b.sent();
3076
+ compiled = Array.from(new Set(Array.from(entries)
3077
+ .map(normalizeSql)
3078
+ .filter(function (entry) { return entry.length > 0; }))).sort();
3079
+ return [4 /*yield*/, writeFile(allowListPath, JSON.stringify(compiled, null, 2))];
3080
+ case 4:
3081
+ _b.sent();
3082
+ return [2 /*return*/, compiled];
3083
+ }
3084
+ });
3085
+ }); };
3022
3086
 
3023
3087
  var SqlExecutor = /** @class */ (function (_super) {
3024
3088
  tslib.__extends(SqlExecutor, _super);
@@ -3565,7 +3629,7 @@ function checkAllRequestsComplete() {
3565
3629
  var cacheEntries = Array.from(apiRequestCache.values());
3566
3630
  var stillRunning = cacheEntries.filter(function (cache) { return undefined === cache.response; });
3567
3631
  if (stillRunning.length !== 0) {
3568
- if (document === null || document === undefined) {
3632
+ if (typeof document === "undefined" || document === null) {
3569
3633
  throw new Error('document is undefined while waiting for API requests to complete (' + JSON.stringify(cacheEntries) + ')');
3570
3634
  }
3571
3635
  // when requests return emtpy sets in full renders, it may not be possible to track their progress.
@@ -3576,10 +3640,10 @@ function checkAllRequestsComplete() {
3576
3640
  }
3577
3641
 
3578
3642
  function onSuccess(message) {
3579
- reactToastify.toast.success(message, isLocal() ? toastOptionsDevs : toastOptions);
3643
+ notifyToast("success", message, isLocal() ? toastOptionsDevs : toastOptions);
3580
3644
  }
3581
3645
  function onError(message) {
3582
- reactToastify.toast.error(message, isLocal() ? toastOptionsDevs : toastOptions);
3646
+ notifyToast("error", message, isLocal() ? toastOptionsDevs : toastOptions);
3583
3647
  }
3584
3648
 
3585
3649
  function isVerbose () {
@@ -3615,12 +3679,15 @@ exports.carbonNodeQsStringify = carbonNodeQsStringify;
3615
3679
  exports.checkAllRequestsComplete = checkAllRequestsComplete;
3616
3680
  exports.checkCache = checkCache;
3617
3681
  exports.clearCache = clearCache;
3682
+ exports.collectSqlAllowListEntries = collectSqlAllowListEntries;
3683
+ exports.compileSqlAllowList = compileSqlAllowList;
3618
3684
  exports.convertForRequestBody = convertForRequestBody;
3619
3685
  exports.convertHexIfBinary = convertHexIfBinary;
3620
3686
  exports.derivedTable = derivedTable;
3621
3687
  exports.determineRuntimeJsType = determineRuntimeJsType;
3622
3688
  exports.distSphere = distSphere;
3623
3689
  exports.error = error;
3690
+ exports.extractSqlEntries = extractSqlEntries;
3624
3691
  exports.fieldEq = fieldEq;
3625
3692
  exports.getEnvVar = getEnvVar;
3626
3693
  exports.getPrimaryKeyTypes = getPrimaryKeyTypes;
@@ -3634,6 +3701,7 @@ exports.isVerbose = isVerbose;
3634
3701
  exports.loadSqlAllowList = loadSqlAllowList;
3635
3702
  exports.normalizeSingularRequest = normalizeSingularRequest;
3636
3703
  exports.normalizeSql = normalizeSql;
3704
+ exports.notifyToast = notifyToast;
3637
3705
  exports.onError = onError;
3638
3706
  exports.onSuccess = onSuccess;
3639
3707
  exports.removeInvalidKeys = removeInvalidKeys;
@@ -3642,6 +3710,7 @@ exports.resolveDerivedTable = resolveDerivedTable;
3642
3710
  exports.restOrm = restOrm;
3643
3711
  exports.restRequest = restRequest;
3644
3712
  exports.setCache = setCache;
3713
+ exports.setToastHandler = setToastHandler;
3645
3714
  exports.sortAndSerializeQueryObject = sortAndSerializeQueryObject;
3646
3715
  exports.stContains = stContains;
3647
3716
  exports.timeout = timeout;