@colisweb/rescript-toolkit 2.9.1-mobile → 2.11.1

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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "2.9.1-mobile",
3
+ "version": "2.11.1",
4
4
  "scripts": {
5
5
  "clean": "rescript clean",
6
6
  "build": "rescript build",
@@ -65,7 +65,7 @@
65
65
  "reschema": "1.3.1",
66
66
  "rescript": "9.1.4",
67
67
  "rescript-classnames": "6.0.0",
68
- "rescript-logger": "2.0.0",
68
+ "rescript-logger": "2.0.2",
69
69
  "rescript-react-update": "5.0.0",
70
70
  "restorative": "0.4.0-beta.1",
71
71
  "sanitize-html": "2.6.1",
@@ -0,0 +1,28 @@
1
+ module type Config = {
2
+ module Request: Toolkit__Request2.Config
3
+ let key: Request.argument => array<string>
4
+ }
5
+
6
+ module Make = (Config: Config) => {
7
+ let key: Config.Request.argument => array<string> = Config.key
8
+
9
+ let use = (
10
+ ~options: option<Swr.fetcherOptions>=?,
11
+ key: option<Config.Request.argument>,
12
+ ): Toolkit__Hooks.fetcher<Config.Request.response> =>
13
+ Toolkit__Hooks.useFetcher(~options?, key->Option.map(Config.key), () => {
14
+ let key = key->Option.getExn
15
+
16
+ Config.Request.exec(key)->Promise.Js.fromResult
17
+ })
18
+
19
+ let useOptional = (
20
+ ~options: option<Swr.fetcherOptions>=?,
21
+ key: option<Config.Request.argument>,
22
+ ): Toolkit__Hooks.fetcher<option<Config.Request.response>> =>
23
+ Toolkit__Hooks.useOptionalFetcher(~options?, key->Option.map(Config.key), () => {
24
+ let key = key->Option.getExn
25
+
26
+ Config.Request.exec(key)->Promise.Js.fromResult
27
+ })
28
+ }
@@ -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, Js.Json.t>>,
7
+ >
8
+ }
9
+
10
+ module Make = (Config: Config) => {
11
+ include Config
12
+ }
@@ -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
- (Axios.get(C.envUrl ++ C.featureName)
31
- |> Js.Promise.then_(res => res["data"]->Js.Promise.resolve)
32
- |> Js.Promise.then_(data =>
33
- switch t_decode(data) {
34
- | Result.Ok(feat) => Js.Promise.resolve(feat)
35
- | Result.Error(_err) =>
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,177 @@
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> = {
27
+ data: 'data,
28
+ status: int,
29
+ statusText: string,
30
+ headers: Js.Dict.t<string>,
31
+ config: config,
32
+ }
33
+
34
+ type error<'responseData> = {
35
+ request: option<Js.Json.t>,
36
+ response: option<response<'responseData>>,
37
+ message: string,
38
+ }
39
+
40
+ type adapter<'a, 'b, 'err> = config => Promise.Js.t<response<'a>, 'err>
41
+
42
+ @module("axios")
43
+ external isAxiosError: error<'a> => 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>, 'err> = "get"
76
+
77
+ @module("axios")
78
+ external post: (string, ~data: 'a, ~config: config=?, unit) => Promise.Js.t<response<'data>, 'err> =
79
+ "post"
80
+
81
+ @module("axios")
82
+ external put: (string, ~data: 'a, ~config: config=?, unit) => Promise.Js.t<response<'data>, 'err> =
83
+ "put"
84
+
85
+ @module("axios")
86
+ external patch: (
87
+ string,
88
+ ~data: 'a,
89
+ ~config: config=?,
90
+ unit,
91
+ ) => Promise.Js.t<response<'data>, 'err> = "patch"
92
+
93
+ @module("axios")
94
+ external delete: (string, ~config: config=?, unit) => Promise.Js.t<response<'data>, 'err> = "delete"
95
+
96
+ @module("axios")
97
+ external options: (string, ~config: config=?, unit) => Promise.Js.t<response<'data>, 'err> =
98
+ "options"
99
+
100
+ module Interceptors = {
101
+ @module("axios") @scope(("default", "interceptors", "request"))
102
+ external requestInterceptor: ('config => Promise.Js.t<'updatedConfig, 'error>) => unit = "use"
103
+
104
+ @module("axios") @scope(("default", "interceptors", "response"))
105
+ external responseInterceptor: ('response => Promise.Js.t<'updatedResponse, 'error>) => unit =
106
+ "use"
107
+ }
108
+
109
+ module WithResult = {
110
+ type customError<'apiError, 'response> = [
111
+ | #default(error<'response>)
112
+ | #decodeError(Decco.decodeError)
113
+ | #custom('apiError)
114
+ ]
115
+
116
+ type decodeData<'newData, 'err> = Js.Json.t => result<'newData, 'err>
117
+
118
+ type mapError<'a, 'response, 'headers, 'request> = error<'response> => customError<'a, 'response>
119
+
120
+ let toResult = (promise, ~mapError, ~decodeData) =>
121
+ promise
122
+ ->Promise.Js.toResult
123
+ ->Promise.mapError(err => mapError->Option.mapWithDefault(#default(err), fn => fn(err)))
124
+ ->Promise.flatMapOk(response => {
125
+ Promise.resolved(
126
+ switch decodeData(response.data) {
127
+ | Ok(_) as ok => ok
128
+ | Error(decodeError) => Error(#decodeError(decodeError))
129
+ },
130
+ )
131
+ })
132
+
133
+ let get = (
134
+ ~config=?,
135
+ ~decodeData: decodeData<'newData, 'err>,
136
+ ~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
137
+ string,
138
+ ) => get(string, ~config?, ())->toResult(~decodeData, ~mapError)
139
+
140
+ let post = (
141
+ ~data,
142
+ ~config=?,
143
+ ~decodeData: decodeData<'newData, 'err>,
144
+ ~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
145
+ string,
146
+ ) => post(string, ~data, ~config?, ())->toResult(~decodeData, ~mapError)
147
+
148
+ let put = (
149
+ ~data,
150
+ ~config=?,
151
+ ~decodeData: decodeData<'newData, 'err>,
152
+ ~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
153
+ string,
154
+ ) => put(string, ~data, ~config?, ())->toResult(~decodeData, ~mapError)
155
+
156
+ let patch = (
157
+ ~data,
158
+ ~config=?,
159
+ ~decodeData: decodeData<'newData, 'err>,
160
+ ~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
161
+ string,
162
+ ) => patch(string, ~data, ~config?, ())->toResult(~decodeData, ~mapError)
163
+
164
+ let delete = (
165
+ ~config=?,
166
+ ~decodeData: decodeData<'newData, 'err>,
167
+ ~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
168
+ string,
169
+ ) => delete(string, ~config?, ())->toResult(~decodeData, ~mapError)
170
+
171
+ let options = (
172
+ ~config=?,
173
+ ~decodeData: decodeData<'newData, 'err>,
174
+ ~mapError: option<mapError<'a, 'response, 'headers, 'request>>=?,
175
+ string,
176
+ ) => options(string, ~config?, ())->toResult(~decodeData, ~mapError)
177
+ }
package/.env DELETED
@@ -1 +0,0 @@
1
- STORYBOOK_HERE_API_KEY=XdOccRM258JaG5yYFTQYOwqSE_hrosqcWHugsLUOrIg
package/.merlin DELETED
@@ -1,66 +0,0 @@
1
- ####{BSB GENERATED: NO EDIT
2
- FLG -ppx /Users/colisweb/Projects/rescript-toolkit/node_modules/decco/ppx
3
- FLG -ppx /Users/colisweb/Projects/rescript-toolkit/node_modules/lenses-ppx/ppx
4
- FLG -ppx /Users/colisweb/Projects/rescript-toolkit/node_modules/rescript-logger/ppx
5
- FLG -ppx '/Users/colisweb/Projects/rescript-toolkit/node_modules/rescript/darwin/bsc.exe -as-ppx -bs-jsx 3'
6
- S /Users/colisweb/Projects/rescript-toolkit/node_modules/rescript/lib/ocaml
7
- B /Users/colisweb/Projects/rescript-toolkit/node_modules/rescript/lib/ocaml
8
- FLG -open Belt -open Cx
9
- FLG -w +a-4-9-20-40-41-42-50-61-102-44-30-32-40-42-61
10
- S /Users/colisweb/Projects/rescript-toolkit/node_modules/bs-css/lib/ocaml
11
- B /Users/colisweb/Projects/rescript-toolkit/node_modules/bs-css/lib/ocaml
12
- S /Users/colisweb/Projects/rescript-toolkit/node_modules/bs-css-emotion/lib/ocaml
13
- B /Users/colisweb/Projects/rescript-toolkit/node_modules/bs-css-emotion/lib/ocaml
14
- S /Users/colisweb/Projects/rescript-toolkit/node_modules/@rescript/react/lib/ocaml
15
- B /Users/colisweb/Projects/rescript-toolkit/node_modules/@rescript/react/lib/ocaml
16
- S /Users/colisweb/Projects/rescript-toolkit/node_modules/bs-axios/lib/ocaml
17
- B /Users/colisweb/Projects/rescript-toolkit/node_modules/bs-axios/lib/ocaml
18
- S /Users/colisweb/Projects/rescript-toolkit/node_modules/reason-promise/lib/ocaml
19
- B /Users/colisweb/Projects/rescript-toolkit/node_modules/reason-promise/lib/ocaml
20
- S /Users/colisweb/Projects/rescript-toolkit/node_modules/reason-react/lib/ocaml
21
- B /Users/colisweb/Projects/rescript-toolkit/node_modules/reason-react/lib/ocaml
22
- S /Users/colisweb/Projects/rescript-toolkit/node_modules/decco/lib/ocaml
23
- B /Users/colisweb/Projects/rescript-toolkit/node_modules/decco/lib/ocaml
24
- S /Users/colisweb/Projects/rescript-toolkit/node_modules/rescript-classnames/lib/ocaml
25
- B /Users/colisweb/Projects/rescript-toolkit/node_modules/rescript-classnames/lib/ocaml
26
- S /Users/colisweb/Projects/rescript-toolkit/node_modules/rescript-logger/lib/ocaml
27
- B /Users/colisweb/Projects/rescript-toolkit/node_modules/rescript-logger/lib/ocaml
28
- S /Users/colisweb/Projects/rescript-toolkit/node_modules/reschema/lib/ocaml
29
- B /Users/colisweb/Projects/rescript-toolkit/node_modules/reschema/lib/ocaml
30
- S /Users/colisweb/Projects/rescript-toolkit/node_modules/rescript-react-update/lib/ocaml
31
- B /Users/colisweb/Projects/rescript-toolkit/node_modules/rescript-react-update/lib/ocaml
32
- S /Users/colisweb/Projects/rescript-toolkit/node_modules/restorative/lib/ocaml
33
- B /Users/colisweb/Projects/rescript-toolkit/node_modules/restorative/lib/ocaml
34
- S stories
35
- B lib/bs/stories
36
- S src
37
- B lib/bs/src
38
- S src/router
39
- B lib/bs/src/router
40
- S src/unleash
41
- B lib/bs/src/unleash
42
- S src/sentry
43
- B lib/bs/src/sentry
44
- S src/request
45
- B lib/bs/src/request
46
- S src/decoders
47
- B lib/bs/src/decoders
48
- S src/hooks
49
- B lib/bs/src/hooks
50
- S src/identifier
51
- B lib/bs/src/identifier
52
- S src/primitives
53
- B lib/bs/src/primitives
54
- S src/utils
55
- B lib/bs/src/utils
56
- S src/fetcher
57
- B lib/bs/src/fetcher
58
- S src/form
59
- B lib/bs/src/form
60
- S src/vendors
61
- B lib/bs/src/vendors
62
- S src/vendors/reach-ui
63
- B lib/bs/src/vendors/reach-ui
64
- S src/ui
65
- B lib/bs/src/ui
66
- ####BSB GENERATED: NO EDIT}