elm-pages 3.0.0-beta.1 → 3.0.0-beta.10
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/README.md +10 -1
- package/codegen/elm-pages-codegen.js +803 -284
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +285 -101
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +140 -17
- package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +218 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- package/generator/src/SharedTemplate.elm +1 -1
- package/generator/src/build.js +75 -42
- package/generator/src/compatibility-key.js +1 -0
- package/generator/src/config.js +41 -0
- package/generator/src/dev-server.js +36 -56
- package/generator/src/generate-template-module-connector.js +0 -28
- package/generator/src/pre-render-html.js +31 -17
- package/generator/src/render.js +2 -0
- package/generator/src/seo-renderer.js +11 -4
- package/generator/src/vite-utils.js +78 -0
- package/generator/template/app/Api.elm +1 -1
- package/generator/template/app/Site.elm +6 -1
- package/package.json +2 -3
- package/src/ApiRoute.elm +0 -3
- package/src/DataSource/File.elm +1 -1
- package/src/DataSource/Internal/Request.elm +0 -5
- package/src/DataSource.elm +39 -31
- package/src/Form/Field.elm +1 -1
- package/src/Form.elm +1 -1
- package/src/Head/Seo.elm +16 -27
- package/src/Head.elm +126 -0
- package/src/HtmlPrinter.elm +7 -3
- package/src/Pages/Generate.elm +544 -102
- package/src/Pages/Internal/NotFoundReason.elm +3 -2
- package/src/Pages/Internal/Platform/Cli.elm +91 -27
- package/src/Pages/Internal/Platform/Cli.elm.bak +1276 -0
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +6 -0
- package/src/Pages/Internal/Platform.elm +34 -27
- package/src/Pages/ProgramConfig.elm +6 -3
- package/src/Server/Session.elm +149 -83
- package/src/Server/SetCookie.elm +89 -31
package/src/Server/SetCookie.elm
CHANGED
|
@@ -1,15 +1,38 @@
|
|
|
1
1
|
module Server.SetCookie exposing
|
|
2
|
-
( SetCookie
|
|
3
|
-
,
|
|
2
|
+
( SetCookie
|
|
3
|
+
, SameSite(..)
|
|
4
|
+
, Options, initOptions
|
|
5
|
+
, withImmediateExpiration, makeVisibleToJavaScript, nonSecure, setCookie, withDomain, withExpiration, withMaxAge, withPath, withSameSite
|
|
4
6
|
, toString
|
|
5
7
|
)
|
|
6
8
|
|
|
7
|
-
{-|
|
|
9
|
+
{-| Server-rendered pages in your `elm-pages` can set cookies. `elm-pages` provides two high-level ways to work with cookies:
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
- [`Server.Session.withSession`](Server-Session#withSession)
|
|
12
|
+
- [`Server.Response.withSetCookieHeader`](Server-Response#withSetCookieHeader)
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
[`Server.Session.withSession`](Server-Session#withSession) provides a high-level way to manage key-value pairs of data using cookie storage,
|
|
15
|
+
whereas `Server.Response.withSetCookieHeader` gives a more low-level tool for setting cookies. It's often best to use the
|
|
16
|
+
most high-level tool that will fit your use case.
|
|
17
|
+
|
|
18
|
+
You can learn more about the basics of cookies in the Web Platform in these helpful MDN documentation pages:
|
|
19
|
+
|
|
20
|
+
- <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie>
|
|
21
|
+
- <https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies>
|
|
22
|
+
|
|
23
|
+
@docs SetCookie
|
|
24
|
+
|
|
25
|
+
@docs SameSite
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## Options
|
|
29
|
+
|
|
30
|
+
@docs Options, initOptions
|
|
31
|
+
|
|
32
|
+
@docs withImmediateExpiration, makeVisibleToJavaScript, nonSecure, setCookie, withDomain, withExpiration, withMaxAge, withPath, withSameSite
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## Internal
|
|
13
36
|
|
|
14
37
|
@docs toString
|
|
15
38
|
|
|
@@ -24,8 +47,14 @@ import Utc
|
|
|
24
47
|
type alias SetCookie =
|
|
25
48
|
{ name : String
|
|
26
49
|
, value : String
|
|
27
|
-
,
|
|
28
|
-
|
|
50
|
+
, options : Options
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
{-| -}
|
|
55
|
+
type alias Options =
|
|
56
|
+
{ expiration : Maybe Time.Posix
|
|
57
|
+
, visibleToJavaScript : Bool
|
|
29
58
|
, maxAge : Maybe Int
|
|
30
59
|
, path : Maybe String
|
|
31
60
|
, domain : Maybe String
|
|
@@ -41,7 +70,11 @@ type SameSite
|
|
|
41
70
|
| None
|
|
42
71
|
|
|
43
72
|
|
|
44
|
-
{-| -
|
|
73
|
+
{-| Usually you'll want to use [`Server.Response.withSetCookieHeader`](Server-Response#withSetCookieHeader) instead.
|
|
74
|
+
|
|
75
|
+
This is a low-level helper that's there in case you want it but most users will never need this.
|
|
76
|
+
|
|
77
|
+
-}
|
|
45
78
|
toString : SetCookie -> String
|
|
46
79
|
toString builder =
|
|
47
80
|
let
|
|
@@ -61,17 +94,25 @@ toString builder =
|
|
|
61
94
|
|
|
62
95
|
else
|
|
63
96
|
""
|
|
97
|
+
|
|
98
|
+
options : Options
|
|
99
|
+
options =
|
|
100
|
+
builder.options
|
|
101
|
+
|
|
102
|
+
httpOnly : Bool
|
|
103
|
+
httpOnly =
|
|
104
|
+
not options.visibleToJavaScript
|
|
64
105
|
in
|
|
65
106
|
builder.name
|
|
66
107
|
++ "="
|
|
67
108
|
++ Url.percentEncode builder.value
|
|
68
|
-
++ option "Expires" (
|
|
69
|
-
++ option "Max-Age" (
|
|
70
|
-
++ option "Path"
|
|
71
|
-
++ option "Domain"
|
|
72
|
-
++ option "SameSite" (
|
|
73
|
-
++ boolOption "HttpOnly"
|
|
74
|
-
++ boolOption "Secure"
|
|
109
|
+
++ option "Expires" (options.expiration |> Maybe.map Utc.fromTime)
|
|
110
|
+
++ option "Max-Age" (options.maxAge |> Maybe.map String.fromInt)
|
|
111
|
+
++ option "Path" options.path
|
|
112
|
+
++ option "Domain" options.domain
|
|
113
|
+
++ option "SameSite" (options.sameSite |> Maybe.map sameSiteToString)
|
|
114
|
+
++ boolOption "HttpOnly" httpOnly
|
|
115
|
+
++ boolOption "Secure" options.secure
|
|
75
116
|
|
|
76
117
|
|
|
77
118
|
sameSiteToString : SameSite -> String
|
|
@@ -88,12 +129,19 @@ sameSiteToString sameSite =
|
|
|
88
129
|
|
|
89
130
|
|
|
90
131
|
{-| -}
|
|
91
|
-
setCookie : String -> String -> SetCookie
|
|
92
|
-
setCookie name value =
|
|
132
|
+
setCookie : String -> String -> Options -> SetCookie
|
|
133
|
+
setCookie name value options =
|
|
93
134
|
{ name = name
|
|
94
135
|
, value = value
|
|
95
|
-
,
|
|
96
|
-
|
|
136
|
+
, options = options
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
{-| -}
|
|
141
|
+
initOptions : Options
|
|
142
|
+
initOptions =
|
|
143
|
+
{ expiration = Nothing
|
|
144
|
+
, visibleToJavaScript = False
|
|
97
145
|
, maxAge = Nothing
|
|
98
146
|
, path = Nothing
|
|
99
147
|
, domain = Nothing
|
|
@@ -103,7 +151,7 @@ setCookie name value =
|
|
|
103
151
|
|
|
104
152
|
|
|
105
153
|
{-| -}
|
|
106
|
-
withExpiration : Time.Posix ->
|
|
154
|
+
withExpiration : Time.Posix -> Options -> Options
|
|
107
155
|
withExpiration time builder =
|
|
108
156
|
{ builder
|
|
109
157
|
| expiration = Just time
|
|
@@ -111,23 +159,33 @@ withExpiration time builder =
|
|
|
111
159
|
|
|
112
160
|
|
|
113
161
|
{-| -}
|
|
114
|
-
withImmediateExpiration :
|
|
162
|
+
withImmediateExpiration : Options -> Options
|
|
115
163
|
withImmediateExpiration builder =
|
|
116
164
|
{ builder
|
|
117
165
|
| expiration = Just (Time.millisToPosix 0)
|
|
118
166
|
}
|
|
119
167
|
|
|
120
168
|
|
|
121
|
-
{-| -
|
|
122
|
-
|
|
123
|
-
|
|
169
|
+
{-| The default option in this API is for HttpOnly cookies <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#httponly>.
|
|
170
|
+
|
|
171
|
+
Cookies can be exposed so you can read them from JavaScript using `Document.cookie`. When this is intended and understood
|
|
172
|
+
then there's nothing unsafe about that (for example, if you are setting a `darkMode` cookie and what to access that
|
|
173
|
+
dynamically). In this API you opt into exposing a cookie you set to JavaScript to ensure cookies aren't exposed to JS unintentionally.
|
|
174
|
+
|
|
175
|
+
In general if you can accomplish your goal using HttpOnly cookies (i.e. not using `makeVisibleToJavaScript`) then
|
|
176
|
+
it's a good practice. With server-rendered `elm-pages` applications you can often manage your session state by pulling
|
|
177
|
+
in session data from cookies in a `DataSource` (which is resolved server-side before it ever reaches the browser).
|
|
178
|
+
|
|
179
|
+
-}
|
|
180
|
+
makeVisibleToJavaScript : Options -> Options
|
|
181
|
+
makeVisibleToJavaScript builder =
|
|
124
182
|
{ builder
|
|
125
|
-
|
|
|
183
|
+
| visibleToJavaScript = True
|
|
126
184
|
}
|
|
127
185
|
|
|
128
186
|
|
|
129
187
|
{-| -}
|
|
130
|
-
withMaxAge : Int ->
|
|
188
|
+
withMaxAge : Int -> Options -> Options
|
|
131
189
|
withMaxAge maxAge builder =
|
|
132
190
|
{ builder
|
|
133
191
|
| maxAge = Just maxAge
|
|
@@ -135,7 +193,7 @@ withMaxAge maxAge builder =
|
|
|
135
193
|
|
|
136
194
|
|
|
137
195
|
{-| -}
|
|
138
|
-
withPath : String ->
|
|
196
|
+
withPath : String -> Options -> Options
|
|
139
197
|
withPath path builder =
|
|
140
198
|
{ builder
|
|
141
199
|
| path = Just path
|
|
@@ -143,7 +201,7 @@ withPath path builder =
|
|
|
143
201
|
|
|
144
202
|
|
|
145
203
|
{-| -}
|
|
146
|
-
withDomain : String ->
|
|
204
|
+
withDomain : String -> Options -> Options
|
|
147
205
|
withDomain domain builder =
|
|
148
206
|
{ builder
|
|
149
207
|
| domain = Just domain
|
|
@@ -153,7 +211,7 @@ withDomain domain builder =
|
|
|
153
211
|
{-| Secure (only sent over https, or localhost on http) is the default. This overrides that and
|
|
154
212
|
removes the `Secure` attribute from the cookie.
|
|
155
213
|
-}
|
|
156
|
-
nonSecure :
|
|
214
|
+
nonSecure : Options -> Options
|
|
157
215
|
nonSecure builder =
|
|
158
216
|
{ builder
|
|
159
217
|
| secure = False
|
|
@@ -162,7 +220,7 @@ nonSecure builder =
|
|
|
162
220
|
|
|
163
221
|
{-| The default SameSite policy is Lax if one is not explicitly set. See the SameSite section in <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes>.
|
|
164
222
|
-}
|
|
165
|
-
withSameSite : SameSite ->
|
|
223
|
+
withSameSite : SameSite -> Options -> Options
|
|
166
224
|
withSameSite sameSite builder =
|
|
167
225
|
{ builder
|
|
168
226
|
| sameSite = Just sameSite
|