@colisweb/rescript-toolkit 4.20.5 → 4.21.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": "4.20.5",
3
+ "version": "4.21.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "clean": "rescript clean",
@@ -94,5 +94,8 @@
94
94
  "sass": "1.69.3",
95
95
  "vite": "4.4.11"
96
96
  },
97
- "packageManager": "yarn@3.3.1"
97
+ "packageManager": "yarn@3.3.1",
98
+ "msw": {
99
+ "workerDirectory": "public"
100
+ }
98
101
  }
@@ -80,6 +80,8 @@ module Make = (Config: IntlConfig) => {
80
80
  let setCurrentLocale = (locale: availableLanguages) => store.dispatch(SetLocale(locale))
81
81
 
82
82
  let useCurrentLocale = () => store.useStore().locale
83
+ let getCurrentLocale = () => store.getState().locale
84
+ let getIntl = () => store.getState().intl
83
85
  let useIntl = () => store.useStore().intl
84
86
 
85
87
  let getDateFnsLocale = locale =>
@@ -23,8 +23,11 @@ module Make: (Config: IntlConfig) =>
23
23
  let locale: availableLanguages
24
24
  let intl: ReactIntl.Intl.t
25
25
  let useIntl: unit => ReactIntl.Intl.t
26
+ let getIntl: unit => ReactIntl.Intl.t
27
+ let getCurrentLocale: unit => availableLanguages
26
28
  let useCurrentLocale: unit => availableLanguages
27
29
  let setCurrentLocale: availableLanguages => unit
30
+
28
31
  let getDateFnsLocale: availableLanguages => DateFns.dateFnsLocale
29
32
 
30
33
  module Provider: {
@@ -1,7 +1,7 @@
1
1
  let localStorageKey = "@colisweb/mock"
2
2
 
3
3
  @react.component
4
- let make = (~worker: Msw.worker, ~workerOptions: Msw.startOptions={}, ~children) => {
4
+ let make = (~worker: Msw.worker, ~workerOptions: Msw.startOptions={}, ~className="", ~children) => {
5
5
  let (mockEnabled, setMock) = Toolkit__Hooks.useLocalStorageState(
6
6
  localStorageKey,
7
7
  {
@@ -26,9 +26,13 @@ let make = (~worker: Msw.worker, ~workerOptions: Msw.startOptions={}, ~children)
26
26
 
27
27
  <React.Suspense fallback={<Toolkit__Ui_SpinnerFullScreen />}>
28
28
  <label
29
- className={`fixed top-2 left-1/2 flex flex-row gap-2 items-center justify-center ${mockEnabled
29
+ className={cx([
30
+ "fixed top-2 left-1/2 flex flex-row gap-2 items-center justify-center",
31
+ mockEnabled
30
32
  ? "bg-success-100 border-success-400 text-success-700"
31
- : "bg-neutral-100"} p-1 border rounded-lg z-50 cursor-pointer`}>
33
+ : "bg-neutral-100 p-1 border rounded-lg z-50 cursor-pointer",
34
+ className,
35
+ ])}>
32
36
  <span> {"Mock"->React.string} </span>
33
37
  <input
34
38
  type_={"checkbox"}
package/src/mock/index.md CHANGED
@@ -49,7 +49,7 @@ open Identifiers
49
49
  let mocks = [
50
50
  Msw.Rest.get(
51
51
  "https://api.url",
52
- (req, res, ctx) => {
52
+ ({params}) => {
53
53
  open ColiswebApi.V5.Transporter.GetContactsWithParameters.Config
54
54
  let _emptyResponse = []
55
55
  let defaultResponse = [
@@ -69,18 +69,18 @@ let mocks = [
69
69
  }
70
70
  ]
71
71
 
72
- let transporterId = req.params["transporterId"]
72
+ let transporterId = params->Js.Dict.get("transporterId")
73
73
 
74
74
  switch transporterId {
75
- | "9" => res(Msw.Ctx.json(ctx, defaultResponse))
76
- | _ => ()
75
+ | Some("9") => Msw.HttpResponse.json(defaultResponse->response_encode)
76
+ | _ => Msw.HttpResponse.json(_emptyResponse->response_encode)
77
77
  }
78
78
  },
79
79
  ),
80
80
  Msw.Rest.put(
81
81
  "https://api.url",
82
- (_req, res, ctx) => {
83
- res(Msw.Ctx.status(ctx, 200))
82
+ (_) => {
83
+ Msw.HttpResponse.jsonWithOptions(Js.Json.null, {status: 200})
84
84
  },
85
85
  ),
86
86
  ]
@@ -15,7 +15,7 @@ external stop: worker => unit = "stop"
15
15
  @module("msw")
16
16
  external delay: unit => Promise.Js.t<unit, unit> = "delay"
17
17
  @module("msw")
18
- external delayCustom: int => Promise.Js.t<unit, unit> = "delay"
18
+ external delayCustom: int => Promise.Js.t<unit, 'err> = "delay"
19
19
 
20
20
  module HttpResponse = {
21
21
  type t
@@ -54,6 +54,18 @@ module Http = {
54
54
  external delete: (string, httpRequest => HttpResponse.t) => mock = "delete"
55
55
  @module("msw") @scope("http")
56
56
  external all: (string, httpRequest => HttpResponse.t) => mock = "all"
57
+
58
+ @module("msw") @scope("http")
59
+ external getAsync: (string, httpRequest => Promise.Js.t<HttpResponse.t, 'err>) => mock = "get"
60
+ @module("msw") @scope("http")
61
+ external putAsync: (string, httpRequest => Promise.Js.t<HttpResponse.t, 'err>) => mock = "put"
62
+ @module("msw") @scope("http")
63
+ external postAsync: (string, httpRequest => Promise.Js.t<HttpResponse.t, 'err>) => mock = "post"
64
+ @module("msw") @scope("http")
65
+ external deleteAsync: (string, httpRequest => Promise.Js.t<HttpResponse.t, 'err>) => mock =
66
+ "delete"
67
+ @module("msw") @scope("http")
68
+ external allAsync: (string, httpRequest => Promise.Js.t<HttpResponse.t, 'err>) => mock = "all"
57
69
  }
58
70
 
59
71
  @module("msw")