@colisweb/rescript-toolkit 2.8.5 → 2.10.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colisweb/rescript-toolkit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"clean": "rescript clean",
|
|
6
6
|
"build": "rescript build",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"postcss-loader": "4.2.0",
|
|
56
56
|
"postcss-preset-env": "6.7.0",
|
|
57
57
|
"prismjs": "1.25.0",
|
|
58
|
+
"react-datepicker": "3.8.0",
|
|
58
59
|
"react-icons": "4.3.1",
|
|
59
60
|
"react-select": "5.2.1",
|
|
60
61
|
"react-table": "7.7.0",
|
|
@@ -67,12 +68,11 @@
|
|
|
67
68
|
"rescript-logger": "2.0.2",
|
|
68
69
|
"rescript-react-update": "5.0.0",
|
|
69
70
|
"restorative": "0.4.0-beta.1",
|
|
71
|
+
"sanitize-html": "2.6.1",
|
|
70
72
|
"swr": "1.1.1",
|
|
71
|
-
"tailwindcss": "3.0.2"
|
|
72
|
-
"react-datepicker": "3.8.0"
|
|
73
|
+
"tailwindcss": "3.0.2"
|
|
73
74
|
},
|
|
74
75
|
"devDependencies": {
|
|
75
|
-
"highlight.js": "11.3.1",
|
|
76
76
|
"@babel/core": "7.16.5",
|
|
77
77
|
"@storybook/addon-actions": "6.1.21",
|
|
78
78
|
"@storybook/addon-essentials": "6.1.21",
|
|
@@ -82,6 +82,7 @@
|
|
|
82
82
|
"@storybook/react": "6.1.21",
|
|
83
83
|
"@storybook/theming": "6.1.21",
|
|
84
84
|
"babel-loader": "8.2.3",
|
|
85
|
+
"highlight.js": "11.3.1",
|
|
85
86
|
"raw-loader": "4.0.2",
|
|
86
87
|
"react": "17.0.2",
|
|
87
88
|
"react-dom": "17.0.2",
|
|
@@ -203,37 +203,3 @@ let delete = (
|
|
|
203
203
|
| Some(c) =>
|
|
204
204
|
request->Axios.Instance.deletec(url, c)->toResult(~mapError?, ~errorDecoder?, mapData)
|
|
205
205
|
}
|
|
206
|
-
|
|
207
|
-
module Error = {
|
|
208
|
-
type rec errorType = [
|
|
209
|
-
| #overlappingActivations(array<activation>)
|
|
210
|
-
| #compileError(string)
|
|
211
|
-
| #accessRefused
|
|
212
|
-
| #unknown
|
|
213
|
-
]
|
|
214
|
-
@decco and activation = {ruleTitle: string}
|
|
215
|
-
|
|
216
|
-
let encoder: Decco.encoder<errorType> = _v => ""->Decco.stringToJson
|
|
217
|
-
|
|
218
|
-
let decoder: Decco.decoder<errorType> = json => {
|
|
219
|
-
let error = json->Obj.magic
|
|
220
|
-
let value = switch error["code"] {
|
|
221
|
-
| Some("OVERLAPPING_ACTIVATIONS") =>
|
|
222
|
-
#overlappingActivations(
|
|
223
|
-
error["overlapped"]->Obj.magic->Array.map(a => a->activation_decode->Result.getExn),
|
|
224
|
-
)
|
|
225
|
-
|
|
226
|
-
| Some("COMPILE_ERROR") => #compileError(error["compileError"]->Obj.magic)
|
|
227
|
-
| Some("ACCESS_REFUSED") => #accessRefused
|
|
228
|
-
|
|
229
|
-
| _ => #unknown
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
value->Ok
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
let codec: Decco.codec<errorType> = (encoder, decoder)
|
|
236
|
-
|
|
237
|
-
@decco
|
|
238
|
-
type t = @decco.codec(codec) errorType
|
|
239
|
-
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module type Config = {
|
|
2
|
+
type argument
|
|
3
|
+
type response
|
|
4
|
+
type error
|
|
5
|
+
let exec: argument => Promise.promise<
|
|
6
|
+
result<response, Axios2.WithResult.customError<error, 'res, 'header, 'req>>,
|
|
7
|
+
>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module Make = (Config: Config) => {
|
|
11
|
+
include Config
|
|
12
|
+
}
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
let transformUrl = text =>
|
|
2
2
|
text |> Js.String.unsafeReplaceBy0(%re("/(https?:\\/\\/[^\\s]+)/g"), (url, _, _) =>
|
|
3
|
-
j`<a target='_blank' class='text-
|
|
3
|
+
j`<a target='_blank' class='text-info-500 underline' href="$url">$url</a>`
|
|
4
4
|
)
|
|
5
5
|
|
|
6
|
+
@module("sanitize-html")
|
|
7
|
+
external sanitizeHtml: (string, Js.t<'a>) => string = "default"
|
|
8
|
+
|
|
6
9
|
@react.component
|
|
7
|
-
let make = (~text) =>
|
|
10
|
+
let make = (~text) =>
|
|
11
|
+
<span
|
|
12
|
+
dangerouslySetInnerHTML={
|
|
13
|
+
"__html": text
|
|
14
|
+
->sanitizeHtml({
|
|
15
|
+
"allowedTags": ["a"],
|
|
16
|
+
"allowedAttributes": {
|
|
17
|
+
"a": ["href"],
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
->transformUrl,
|
|
21
|
+
}
|
|
22
|
+
/>
|
|
@@ -27,19 +27,10 @@ module MakeFeature = (C: Config) => {
|
|
|
27
27
|
type t = config<C.argument>
|
|
28
28
|
|
|
29
29
|
let exec = (var: C.input) =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
%log.error(
|
|
37
|
-
"unleash decode"
|
|
38
|
-
("err", _err)
|
|
39
|
-
)
|
|
40
|
-
Js.Promise.reject(Js.Exn.raiseError(C.featureName ++ " : parse error"))
|
|
41
|
-
}
|
|
42
|
-
)
|
|
43
|
-
|> Promise.Js.fromBsPromise
|
|
44
|
-
|> Promise.Js.toResult)->Promise.mapOk(C.exec(var))
|
|
30
|
+
Axios2.get(C.envUrl ++ C.featureName, ())
|
|
31
|
+
->Promise.Js.toResult
|
|
32
|
+
->Promise.flatMapOk(({data}) => {
|
|
33
|
+
Promise.resolved(t_decode(data))
|
|
34
|
+
})
|
|
35
|
+
->Promise.mapOk(C.exec(var))
|
|
45
36
|
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
type config
|
|
2
|
+
|
|
3
|
+
module Headers = {
|
|
4
|
+
type t
|
|
5
|
+
|
|
6
|
+
external fromObj: Js.t<{..}> => t = "%identity"
|
|
7
|
+
external fromDict: Js.Dict.t<string> => t = "%identity"
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module CancelToken = {
|
|
11
|
+
type t
|
|
12
|
+
|
|
13
|
+
@module("axios")
|
|
14
|
+
external source: unit => t = "source"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type requestTransformer<'data, 'a, 'transformedData> = ('data, Js.t<'a>) => 'transformedData
|
|
18
|
+
type responseTransformer<'data, 'transformedData> = 'data => 'transformedData
|
|
19
|
+
type paramsSerializer<'params, 'serializedParams> = 'params => 'serializedParams
|
|
20
|
+
type auth = {
|
|
21
|
+
username: string,
|
|
22
|
+
password: string,
|
|
23
|
+
}
|
|
24
|
+
type proxy = {host: int, port: int, auth: auth}
|
|
25
|
+
|
|
26
|
+
type response<'data, 'header> = {
|
|
27
|
+
data: 'data,
|
|
28
|
+
status: int,
|
|
29
|
+
statusText: string,
|
|
30
|
+
headers: Js.t<'header>,
|
|
31
|
+
config: config,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type error<'responseData, 'responseHeader, 'request> = {
|
|
35
|
+
request: option<'request>,
|
|
36
|
+
response: option<response<'responseData, 'responseHeader>>,
|
|
37
|
+
message: string,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type adapter<'a, 'b, 'err> = config => Promise.Js.t<response<'a, 'b>, 'err>
|
|
41
|
+
|
|
42
|
+
@module("axios")
|
|
43
|
+
external isAxiosError: error<'a, 'b, 'c> => bool = "isAxiosError"
|
|
44
|
+
|
|
45
|
+
@obj
|
|
46
|
+
external makeConfig: (
|
|
47
|
+
~url: string=?,
|
|
48
|
+
~_method: string=?,
|
|
49
|
+
~baseURL: string=?,
|
|
50
|
+
~transformRequest: array<requestTransformer<'data, Js.t<'a>, 'tranformedData>>=?,
|
|
51
|
+
~transformResponse: array<responseTransformer<'data, 'tranformedData>>=?,
|
|
52
|
+
~headers: Headers.t=?,
|
|
53
|
+
~params: Js.t<'params>=?,
|
|
54
|
+
~paramsSerializer: paramsSerializer<'params, 'serializedParams>=?,
|
|
55
|
+
~data: Js.t<'data>=?,
|
|
56
|
+
~timeout: int=?,
|
|
57
|
+
~withCredentials: bool=?,
|
|
58
|
+
~adapter: adapter<'a, 'b, 'err>=?,
|
|
59
|
+
~auth: auth=?,
|
|
60
|
+
~responseType: string=?,
|
|
61
|
+
~xsrfCookieName: string=?,
|
|
62
|
+
~xsrfHeaderName: string=?,
|
|
63
|
+
~onUploadProgress: 'uploadProgress => unit=?,
|
|
64
|
+
~onDownloadProgress: 'downloadProgress => unit=?,
|
|
65
|
+
~maxContentLength: int=?,
|
|
66
|
+
~validateStatus: int => bool=?,
|
|
67
|
+
~maxRedirects: int=?,
|
|
68
|
+
~socketPath: string=?,
|
|
69
|
+
~proxy: proxy=?,
|
|
70
|
+
~cancelToken: CancelToken.t=?,
|
|
71
|
+
unit,
|
|
72
|
+
) => config = ""
|
|
73
|
+
|
|
74
|
+
@module("axios")
|
|
75
|
+
external get: (string, ~config: config=?, unit) => Promise.Js.t<response<'data, 'headers>, 'err> =
|
|
76
|
+
"get"
|
|
77
|
+
|
|
78
|
+
@module("axios")
|
|
79
|
+
external post: (
|
|
80
|
+
string,
|
|
81
|
+
~data: 'a,
|
|
82
|
+
~config: config=?,
|
|
83
|
+
unit,
|
|
84
|
+
) => Promise.Js.t<response<'data, 'headers>, 'err> = "post"
|
|
85
|
+
|
|
86
|
+
@module("axios")
|
|
87
|
+
external put: (
|
|
88
|
+
string,
|
|
89
|
+
~data: 'a,
|
|
90
|
+
~config: config=?,
|
|
91
|
+
unit,
|
|
92
|
+
) => Promise.Js.t<response<'data, 'headers>, 'err> = "put"
|
|
93
|
+
|
|
94
|
+
@module("axios")
|
|
95
|
+
external patch: (
|
|
96
|
+
string,
|
|
97
|
+
~data: 'a,
|
|
98
|
+
~config: config=?,
|
|
99
|
+
unit,
|
|
100
|
+
) => Promise.Js.t<response<'data, 'headers>, 'err> = "patch"
|
|
101
|
+
|
|
102
|
+
@module("axios")
|
|
103
|
+
external delete: (
|
|
104
|
+
string,
|
|
105
|
+
~config: config=?,
|
|
106
|
+
unit,
|
|
107
|
+
) => Promise.Js.t<response<'data, 'headers>, 'err> = "delete"
|
|
108
|
+
|
|
109
|
+
@module("axios")
|
|
110
|
+
external options: (
|
|
111
|
+
string,
|
|
112
|
+
~config: config=?,
|
|
113
|
+
unit,
|
|
114
|
+
) => Promise.Js.t<response<'data, 'headers>, 'err> = "options"
|
|
115
|
+
|
|
116
|
+
module Interceptors = {
|
|
117
|
+
@module("axios") @scope(("default", "interceptors", "request"))
|
|
118
|
+
external requestInterceptor: ('config => Promise.Js.t<'updatedConfig, 'error>) => unit = "use"
|
|
119
|
+
|
|
120
|
+
@module("axios") @scope(("default", "interceptors", "response"))
|
|
121
|
+
external responseInterceptor: ('response => Promise.Js.t<'updatedResponse, 'error>) => unit =
|
|
122
|
+
"use"
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
module WithResult = {
|
|
126
|
+
type customError<'apiError, 'response, 'headers, 'request> = [
|
|
127
|
+
| #default(error<'response, 'headers, 'request>)
|
|
128
|
+
| #decodeError(Decco.decodeError)
|
|
129
|
+
| #custom('apiError)
|
|
130
|
+
]
|
|
131
|
+
|
|
132
|
+
type decodeData<'newData, 'err> = Js.Json.t => result<'newData, 'err>
|
|
133
|
+
|
|
134
|
+
type mapError<'a, 'response, 'headers, 'request> = error<
|
|
135
|
+
'response,
|
|
136
|
+
'headers,
|
|
137
|
+
'request,
|
|
138
|
+
> => customError<'a, 'response, 'headers, 'request>
|
|
139
|
+
|
|
140
|
+
let toResult = (promise, ~mapError, ~decodeData) =>
|
|
141
|
+
promise
|
|
142
|
+
->Promise.Js.toResult
|
|
143
|
+
->Promise.mapError(err => mapError->Option.mapWithDefault(#default(err), fn => fn(err)))
|
|
144
|
+
->Promise.flatMapOk(response => {
|
|
145
|
+
Promise.resolved(
|
|
146
|
+
switch decodeData(response.data) {
|
|
147
|
+
| Ok(_) as ok => ok
|
|
148
|
+
| Error(decodeError) => Error(#decodeError(decodeError))
|
|
149
|
+
},
|
|
150
|
+
)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
let get = (
|
|
154
|
+
string,
|
|
155
|
+
~config=?,
|
|
156
|
+
~decodeData: decodeData<'newData, 'err>,
|
|
157
|
+
~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
|
|
158
|
+
unit,
|
|
159
|
+
) => get(string, ~config?, unit)->toResult(~decodeData, ~mapError)
|
|
160
|
+
|
|
161
|
+
let post = (
|
|
162
|
+
string,
|
|
163
|
+
~data,
|
|
164
|
+
~config=?,
|
|
165
|
+
~decodeData: decodeData<'newData, 'err>,
|
|
166
|
+
~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
|
|
167
|
+
unit,
|
|
168
|
+
) => post(string, ~data, ~config?, unit)->toResult(~decodeData, ~mapError)
|
|
169
|
+
|
|
170
|
+
let put = (
|
|
171
|
+
string,
|
|
172
|
+
~data,
|
|
173
|
+
~config=?,
|
|
174
|
+
~decodeData: decodeData<'newData, 'err>,
|
|
175
|
+
~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
|
|
176
|
+
unit,
|
|
177
|
+
) => put(string, ~data, ~config?, unit)->toResult(~decodeData, ~mapError)
|
|
178
|
+
|
|
179
|
+
let patch = (
|
|
180
|
+
string,
|
|
181
|
+
~data,
|
|
182
|
+
~config=?,
|
|
183
|
+
~decodeData: decodeData<'newData, 'err>,
|
|
184
|
+
~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
|
|
185
|
+
unit,
|
|
186
|
+
) => patch(string, ~data, ~config?, unit)->toResult(~decodeData, ~mapError)
|
|
187
|
+
|
|
188
|
+
let delete = (
|
|
189
|
+
string,
|
|
190
|
+
~config=?,
|
|
191
|
+
~decodeData: decodeData<'newData, 'err>,
|
|
192
|
+
~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
|
|
193
|
+
unit,
|
|
194
|
+
) => delete(string, ~config?, unit)->toResult(~decodeData, ~mapError)
|
|
195
|
+
|
|
196
|
+
let options = (
|
|
197
|
+
string,
|
|
198
|
+
~config=?,
|
|
199
|
+
~decodeData: decodeData<'newData, 'err>,
|
|
200
|
+
~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
|
|
201
|
+
unit,
|
|
202
|
+
) => options(string, ~config?, unit)->toResult(~decodeData, ~mapError)
|
|
203
|
+
}
|