@colisweb/rescript-toolkit 4.20.4 → 4.20.6

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.4",
3
+ "version": "4.20.6",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "clean": "rescript clean",
@@ -69,7 +69,7 @@
69
69
  "rescript-classnames": "6.0.0",
70
70
  "rescript-react-update": "5.0.2",
71
71
  "sanitize-html": "1.27.4",
72
- "swr": "2.2.4",
72
+ "swr": "2.2.2",
73
73
  "tailwindcss": "3.3.3",
74
74
  "use-local-storage-state": "19.1.0"
75
75
  },
@@ -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
  }
@@ -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")