jxp 2.16.0 → 4.0.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/.env.sample +31 -6
- package/README.md +27 -13
- package/dist/bin/init_db.d.ts +3 -0
- package/dist/bin/init_db.d.ts.map +1 -0
- package/dist/bin/init_db.js +48 -0
- package/dist/bin/init_db.js.map +1 -0
- package/dist/bin/server.d.ts +4 -0
- package/dist/bin/server.d.ts.map +1 -0
- package/dist/bin/server.js +132 -0
- package/dist/bin/server.js.map +1 -0
- package/dist/bin/setup.d.ts +3 -0
- package/dist/bin/setup.d.ts.map +1 -0
- package/dist/bin/setup.js +185 -0
- package/dist/bin/setup.js.map +1 -0
- package/dist/globals.d.ts +14 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +3 -0
- package/dist/globals.js.map +1 -0
- package/dist/libs/aggregate_guard.d.ts +5 -0
- package/dist/libs/aggregate_guard.d.ts.map +1 -0
- package/dist/libs/aggregate_guard.js +58 -0
- package/dist/libs/aggregate_guard.js.map +1 -0
- package/dist/libs/bulkwrite_guard.d.ts +5 -0
- package/dist/libs/bulkwrite_guard.d.ts.map +1 -0
- package/dist/libs/bulkwrite_guard.js +44 -0
- package/dist/libs/bulkwrite_guard.js.map +1 -0
- package/dist/libs/cache.d.ts +2 -0
- package/dist/libs/cache.d.ts.map +1 -0
- package/dist/libs/cache.js +94 -0
- package/dist/libs/cache.js.map +1 -0
- package/dist/libs/call_guard.d.ts +3 -0
- package/dist/libs/call_guard.d.ts.map +1 -0
- package/dist/libs/call_guard.js +17 -0
- package/dist/libs/call_guard.js.map +1 -0
- package/dist/libs/connection_string.d.ts +3 -0
- package/dist/libs/connection_string.d.ts.map +1 -0
- package/dist/libs/connection_string.js +4 -0
- package/dist/libs/connection_string.js.map +1 -0
- package/dist/libs/datamunging.d.ts +2 -0
- package/dist/libs/datamunging.d.ts.map +1 -0
- package/dist/libs/datamunging.js +320 -0
- package/dist/libs/datamunging.js.map +1 -0
- package/dist/libs/docs.d.ts +2 -0
- package/dist/libs/docs.d.ts.map +1 -0
- package/dist/libs/docs.js +307 -0
- package/dist/libs/docs.js.map +1 -0
- package/dist/libs/groups.d.ts +2 -0
- package/dist/libs/groups.d.ts.map +1 -0
- package/dist/libs/groups.js +136 -0
- package/dist/libs/groups.js.map +1 -0
- package/dist/libs/jxp.d.ts +4 -0
- package/dist/libs/jxp.d.ts.map +1 -0
- package/dist/libs/jxp.js +1157 -0
- package/dist/libs/jxp.js.map +1 -0
- package/dist/libs/link_index.d.ts +14 -0
- package/dist/libs/link_index.d.ts.map +1 -0
- package/dist/libs/link_index.js +37 -0
- package/dist/libs/link_index.js.map +1 -0
- package/dist/libs/load-config.d.ts +16 -0
- package/dist/libs/load-config.d.ts.map +1 -0
- package/dist/libs/load-config.js +155 -0
- package/dist/libs/load-config.js.map +1 -0
- package/dist/libs/login.d.ts +2 -0
- package/dist/libs/login.d.ts.map +1 -0
- package/dist/libs/login.js +244 -0
- package/dist/libs/login.js.map +1 -0
- package/dist/libs/modeldir.d.ts +5 -0
- package/dist/libs/modeldir.d.ts.map +1 -0
- package/dist/libs/modeldir.js +15 -0
- package/dist/libs/modeldir.js.map +1 -0
- package/dist/libs/query_limits.d.ts +2 -0
- package/dist/libs/query_limits.d.ts.map +1 -0
- package/dist/libs/query_limits.js +84 -0
- package/dist/libs/query_limits.js.map +1 -0
- package/dist/libs/query_manipulation.d.ts +3 -0
- package/dist/libs/query_manipulation.d.ts.map +1 -0
- package/{libs → dist/libs}/query_manipulation.js +22 -21
- package/dist/libs/query_manipulation.js.map +1 -0
- package/dist/libs/query_sanitize.d.ts +5 -0
- package/dist/libs/query_sanitize.d.ts.map +1 -0
- package/dist/libs/query_sanitize.js +109 -0
- package/dist/libs/query_sanitize.js.map +1 -0
- package/dist/libs/response_sanitize.d.ts +7 -0
- package/dist/libs/response_sanitize.d.ts.map +1 -0
- package/dist/libs/response_sanitize.js +57 -0
- package/dist/libs/response_sanitize.js.map +1 -0
- package/dist/libs/safe_error.d.ts +3 -0
- package/dist/libs/safe_error.d.ts.map +1 -0
- package/dist/libs/safe_error.js +14 -0
- package/dist/libs/safe_error.js.map +1 -0
- package/dist/libs/schema.d.ts +14 -0
- package/dist/libs/schema.d.ts.map +1 -0
- package/dist/libs/schema.js +98 -0
- package/dist/libs/schema.js.map +1 -0
- package/dist/libs/schema_description.d.ts +3 -0
- package/dist/libs/schema_description.d.ts.map +1 -0
- package/{libs → dist/libs}/schema_description.js +12 -21
- package/dist/libs/schema_description.js.map +1 -0
- package/dist/libs/security.d.ts +2 -0
- package/dist/libs/security.d.ts.map +1 -0
- package/dist/libs/security.js +428 -0
- package/dist/libs/security.js.map +1 -0
- package/dist/libs/setup.d.ts +2 -0
- package/dist/libs/setup.d.ts.map +1 -0
- package/dist/libs/setup.js +87 -0
- package/dist/libs/setup.js.map +1 -0
- package/dist/libs/startup-deprecations.d.ts +2 -0
- package/dist/libs/startup-deprecations.d.ts.map +1 -0
- package/dist/libs/startup-deprecations.js +21 -0
- package/dist/libs/startup-deprecations.js.map +1 -0
- package/dist/libs/startup.d.ts +16 -0
- package/dist/libs/startup.d.ts.map +1 -0
- package/dist/libs/startup.js +63 -0
- package/dist/libs/startup.js.map +1 -0
- package/dist/libs/ws.d.ts +2 -0
- package/dist/libs/ws.d.ts.map +1 -0
- package/{libs → dist/libs}/ws.js +114 -73
- package/dist/libs/ws.js.map +1 -0
- package/dist/models/apikey_model.d.ts +10 -0
- package/dist/models/apikey_model.d.ts.map +1 -0
- package/dist/models/apikey_model.js +14 -0
- package/dist/models/apikey_model.js.map +1 -0
- package/dist/models/link_model.d.ts +9 -0
- package/dist/models/link_model.d.ts.map +1 -0
- package/dist/models/link_model.js +20 -0
- package/dist/models/link_model.js.map +1 -0
- package/dist/models/refreshtoken_model.d.ts +11 -0
- package/dist/models/refreshtoken_model.d.ts.map +1 -0
- package/dist/models/refreshtoken_model.js +22 -0
- package/dist/models/refreshtoken_model.js.map +1 -0
- package/dist/models/test_model.d.ts +24 -0
- package/dist/models/test_model.d.ts.map +1 -0
- package/dist/models/test_model.js +44 -0
- package/dist/models/test_model.js.map +1 -0
- package/dist/models/token_model.d.ts +14 -0
- package/dist/models/token_model.d.ts.map +1 -0
- package/dist/models/token_model.js +25 -0
- package/dist/models/token_model.js.map +1 -0
- package/dist/models/user_model.d.ts +15 -0
- package/dist/models/user_model.d.ts.map +1 -0
- package/dist/models/user_model.js +38 -0
- package/dist/models/user_model.js.map +1 -0
- package/dist/models/usergroups_model.d.ts +9 -0
- package/dist/models/usergroups_model.d.ts.map +1 -0
- package/dist/models/usergroups_model.js +18 -0
- package/dist/models/usergroups_model.js.map +1 -0
- package/dist/types/jxp-config.d.ts +134 -0
- package/dist/types/jxp-config.d.ts.map +1 -0
- package/dist/types/jxp-config.js +3 -0
- package/dist/types/jxp-config.js.map +1 -0
- package/dist/types/schema-fields.d.ts +43 -0
- package/dist/types/schema-fields.d.ts.map +1 -0
- package/dist/types/schema-fields.js +3 -0
- package/dist/types/schema-fields.js.map +1 -0
- package/docs/aggregations.md +40 -21
- package/docs/api.md +55 -15
- package/docs/authentication.md +60 -37
- package/docs/bulk_writes.md +11 -8
- package/docs/caching.md +28 -11
- package/docs/changelog.md +237 -31
- package/docs/configuration.md +99 -118
- package/docs/hooks.md +12 -8
- package/docs/index.md +17 -17
- package/docs/installation.md +23 -18
- package/docs/permissions.md +33 -19
- package/docs/queries.md +9 -5
- package/docs/schemas.md +21 -10
- package/docs/special.md +4 -4
- package/docs/typescript.md +86 -0
- package/docs/websocket.md +99 -1
- package/mkdocs.yml +1 -0
- package/package.json +121 -69
- package/templates/api.pug +32 -0
- package/templates/app-server.js +43 -0
- package/templates/app.env.sample +8 -0
- package/templates/assets/api-console.js +133 -0
- package/templates/assets/docs.css +227 -0
- package/templates/index.pug +62 -2
- package/templates/layout.pug +17 -11
- package/templates/md.pug +1 -1
- package/templates/model.pug +117 -68
- package/templates/navbar.pug +14 -21
- package/templates/sidebar.pug +30 -0
- package/.env +0 -9
- package/.eslintrc.json +0 -20
- package/.jshintrc +0 -4
- package/.vscode/launch.json +0 -29
- package/.vscode/settings.json +0 -3
- package/Dockerfile +0 -7
- package/bin/init_db.js +0 -54
- package/bin/server.js +0 -84
- package/bin/setup.js +0 -190
- package/config_sample.json +0 -10
- package/docker-compose.yml +0 -32
- package/libs/cache.js +0 -92
- package/libs/connection_string.js +0 -24
- package/libs/datamunging.js +0 -335
- package/libs/docs.js +0 -162
- package/libs/groups.js +0 -133
- package/libs/jxp.js +0 -1208
- package/libs/login.js +0 -218
- package/libs/modeldir.js +0 -14
- package/libs/schema.js +0 -99
- package/libs/security.js +0 -410
- package/libs/setup.js +0 -90
- package/models/apikey_model.js +0 -10
- package/models/link_model.js +0 -17
- package/models/refreshtoken_model.js +0 -20
- package/models/test_model.js +0 -50
- package/models/token_model.js +0 -23
- package/models/user_model.js +0 -38
- package/models/usergroups_model.js +0 -15
- package/setup.sh +0 -3
- package/test/.eslintrc.json +0 -13
- package/test/init.js +0 -92
- package/test/setup.test.js +0 -62
- package/test/test.js +0 -1527
- package/test/wstest.js.old +0 -124
package/docs/api.md
CHANGED
|
@@ -92,6 +92,41 @@ You can paginate with the `page=<page number>` parameter. Page count starts at 1
|
|
|
92
92
|
|
|
93
93
|
If you go beyond the total number of pages, you will get an empty `data` array.
|
|
94
94
|
|
|
95
|
+
#### Default limit
|
|
96
|
+
|
|
97
|
+
When `query_limits.enabled` is true (default), list and query endpoints apply **`?limit=100`** if you omit `limit`. Use `?limit=` up to the configured maximum (default **1000**) for larger pages.
|
|
98
|
+
|
|
99
|
+
#### Large collections (explicit limit)
|
|
100
|
+
|
|
101
|
+
For collections with at least **10,000** documents (by default), you must pass an explicit `?limit=` between 1 and the maximum. Omitting `limit` on a large collection returns **400 Bad Request** (the default limit does not satisfy this rule).
|
|
102
|
+
|
|
103
|
+
Use `GET /count/<model>` for totals. Add **`?count=true`** (or **`?page=`**) when you need `count` / `page_count` in the list response without paginating.
|
|
104
|
+
|
|
105
|
+
#### Totals in list responses
|
|
106
|
+
|
|
107
|
+
By default, list responses **omit** `count` unless you pass **`?count=true`** or **`?page=`**, to avoid expensive `countDocuments` on every request.
|
|
108
|
+
|
|
109
|
+
Configure globally when starting JXP:
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
query_limits: {
|
|
113
|
+
enabled: true,
|
|
114
|
+
large_collection_threshold: 10000,
|
|
115
|
+
max: 1000,
|
|
116
|
+
default: 100,
|
|
117
|
+
skip_count_unless_paginated: true,
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Override per model in schema options:
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
const ReaderSchema = new JXPSchema({ ... }, {
|
|
125
|
+
perms: { ... },
|
|
126
|
+
query_limits: { large_collection_threshold: 5000, max: 500 },
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
95
130
|
*Note* If you have more than 100,000 items in your collection, `count` will return as -1, else doing a full-dataset filtered count becomes too expensive and can cause serious performance issues.
|
|
96
131
|
|
|
97
132
|
### Counting
|
|
@@ -149,7 +184,7 @@ To ensure a full-text index across all fields on your model, add this to your sc
|
|
|
149
184
|
|
|
150
185
|
`MySchema.index( { "$**": "text" } );`
|
|
151
186
|
|
|
152
|
-
See [https://
|
|
187
|
+
See [MongoDB Text Indexes](https://www.mongodb.com/docs/manual/core/index-text/) for more options, such as weighted indexing.
|
|
153
188
|
|
|
154
189
|
Note that you can only declare one index per collection (and hence schema).
|
|
155
190
|
|
|
@@ -168,28 +203,33 @@ As with PUT, we need to reference a specific item, so the endpoint needs to incl
|
|
|
168
203
|
|
|
169
204
|
## Advanced queries
|
|
170
205
|
|
|
171
|
-
If you need to send an advanced query, such as a combined
|
|
206
|
+
If you need to send an advanced query, such as a combined `$and`/`$or`, POST JSON to `/query/{modelname}` with a **`query` object** (required). Most URL features from `GET /api/{modelname}` still apply (`limit`, `page`, `sort`, `populate`, `filter`, `autopopulate`, `fields`) except `search`.
|
|
172
207
|
|
|
173
208
|
Eg.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
"
|
|
209
|
+
|
|
210
|
+
```json
|
|
211
|
+
{
|
|
212
|
+
"query": {
|
|
213
|
+
"$and": [
|
|
214
|
+
{
|
|
215
|
+
"foo": {
|
|
216
|
+
"$regex": "foo",
|
|
217
|
+
"$options": "i"
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
"bar": "Bar"
|
|
181
222
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
"bar": "Bar"
|
|
185
|
-
}
|
|
186
|
-
]
|
|
223
|
+
]
|
|
224
|
+
}
|
|
187
225
|
}
|
|
188
226
|
```
|
|
189
227
|
|
|
228
|
+
See [Queries](queries.md) for more examples.
|
|
229
|
+
|
|
190
230
|
## Aggregate queries
|
|
191
231
|
|
|
192
|
-
You can perform an aggregate query by POSTing
|
|
232
|
+
You can perform an aggregate query by POSTing a pipeline array to `/aggregate/{modelname}`, or wrapping it in `{ "query": [ ... ] }`. See [Aggregations](aggregations.md).
|
|
193
233
|
|
|
194
234
|
Eg.
|
|
195
235
|
```javascript
|
package/docs/authentication.md
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
# Authentication
|
|
2
2
|
|
|
3
|
-
## API Key
|
|
4
|
-
|
|
5
3
|
There are four ways of authenticating:
|
|
6
4
|
|
|
7
5
|
* Basic Auth
|
|
8
6
|
* A Bearer Token
|
|
9
7
|
* An API Key
|
|
10
|
-
* A Javascript Web Token
|
|
8
|
+
* A Javascript Web Token (JWT)
|
|
11
9
|
|
|
12
|
-
We always use `email` and `password` to identify the user.
|
|
10
|
+
We always use `email` and `password` to identify the user. Passwords are one-way encrypted using bcrypt.
|
|
13
11
|
|
|
14
|
-
In a typical application, your front-end site would present a login page asking for the user's email and password. In addition, you would present a "Forgotten Password" link.
|
|
12
|
+
In a typical application, your front-end site would present a login page asking for the user's email and password. In addition, you would present a "Forgotten Password" link.
|
|
15
13
|
|
|
16
|
-
When the user submits their username and password, you would POST that data to the `/login` endpoint. If the login succeeds, the
|
|
14
|
+
When the user submits their username and password, you would POST that data to the `/login` endpoint. If the login succeeds, the response includes their API key and bearer token.
|
|
17
15
|
|
|
18
16
|
## Login endpoints
|
|
19
17
|
|
|
@@ -22,7 +20,9 @@ When the user submits their username and password, you would POST that data to t
|
|
|
22
20
|
Logging in will always delete the previous token and give you a new one.
|
|
23
21
|
|
|
24
22
|
POST `http://localhost:4001/login`
|
|
23
|
+
|
|
25
24
|
Data:
|
|
25
|
+
|
|
26
26
|
```json
|
|
27
27
|
{
|
|
28
28
|
"email": "blah@blah.com",
|
|
@@ -31,6 +31,7 @@ Data:
|
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
Successful Response (Status 200):
|
|
34
|
+
|
|
34
35
|
```json
|
|
35
36
|
{
|
|
36
37
|
"user_id": "5dadbd7e2384ad419975e4a1",
|
|
@@ -43,6 +44,7 @@ Successful Response (Status 200):
|
|
|
43
44
|
```
|
|
44
45
|
|
|
45
46
|
Failed Response (Status 401):
|
|
47
|
+
|
|
46
48
|
```json
|
|
47
49
|
{
|
|
48
50
|
"status": "fail",
|
|
@@ -53,19 +55,22 @@ Failed Response (Status 401):
|
|
|
53
55
|
|
|
54
56
|
### Refresh Token
|
|
55
57
|
|
|
56
|
-
You can use your refresh_token to refresh a token, even if it's expired. By default, refresh tokens last 30 days, whereas tokens last 24 hours.
|
|
58
|
+
You can use your refresh_token to refresh a token, even if it's expired. By default, refresh tokens last 30 days, whereas tokens last 24 hours (configurable via `REFRESH_TOKEN_EXPIRY` and `TOKEN_EXPIRY`).
|
|
57
59
|
|
|
58
60
|
Note that the response is almost identical to the `/login` endpoint, except it doesn't have the `apikey`.
|
|
59
61
|
|
|
60
62
|
POST `http://localhost:4001/refresh`
|
|
61
|
-
|
|
63
|
+
|
|
64
|
+
Header:
|
|
65
|
+
|
|
62
66
|
```json
|
|
63
67
|
{
|
|
64
|
-
"Authorization": "Bearer <refresh token>"
|
|
68
|
+
"Authorization": "Bearer <refresh token>"
|
|
65
69
|
}
|
|
66
70
|
```
|
|
67
71
|
|
|
68
72
|
Successful Response (Status 200):
|
|
73
|
+
|
|
69
74
|
```json
|
|
70
75
|
{
|
|
71
76
|
"user_id": "5dadbd7e2384ad419975e4a1",
|
|
@@ -77,6 +82,7 @@ Successful Response (Status 200):
|
|
|
77
82
|
```
|
|
78
83
|
|
|
79
84
|
Failed Response (Status 401):
|
|
85
|
+
|
|
80
86
|
```json
|
|
81
87
|
{
|
|
82
88
|
"status": "fail",
|
|
@@ -87,65 +93,74 @@ Failed Response (Status 401):
|
|
|
87
93
|
|
|
88
94
|
### Logout
|
|
89
95
|
|
|
90
|
-
This will
|
|
96
|
+
This will immediately expire the token. You must be authenticated (Bearer token or other method).
|
|
97
|
+
|
|
98
|
+
GET `http://localhost:4001/login/logout`
|
|
99
|
+
|
|
100
|
+
GET `http://localhost:4001/logout`
|
|
91
101
|
|
|
92
|
-
|
|
102
|
+
Successful Response (200):
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"status": "ok",
|
|
107
|
+
"message": "User logged out"
|
|
108
|
+
}
|
|
109
|
+
```
|
|
93
110
|
|
|
94
111
|
### Recover Password
|
|
95
112
|
|
|
96
|
-
Send the user an email with
|
|
113
|
+
Send the user an email with a JWT embedded so that they can reset their password. Requires SMTP settings on the `JXP()` config object (see [Configuration](configuration.md#smtp-and-password-recovery)).
|
|
97
114
|
|
|
98
115
|
POST `http://localhost:4001/login/recover`
|
|
99
116
|
|
|
100
117
|
Data:
|
|
101
|
-
|
|
118
|
+
|
|
119
|
+
```json
|
|
102
120
|
{
|
|
103
121
|
"email": "blah@blah.com"
|
|
104
122
|
}
|
|
105
123
|
```
|
|
106
124
|
|
|
107
|
-
Successful Response (200):
|
|
108
|
-
|
|
125
|
+
Successful Response (200):
|
|
126
|
+
|
|
127
|
+
```json
|
|
109
128
|
{
|
|
110
129
|
"status": "ok",
|
|
111
130
|
"message": "Sent recovery email"
|
|
112
131
|
}
|
|
113
132
|
```
|
|
114
133
|
|
|
115
|
-
Failed
|
|
116
|
-
```
|
|
117
|
-
{
|
|
118
|
-
"status": "fail",
|
|
119
|
-
"message": "Unauthorized",
|
|
120
|
-
"err": "Could not find email"
|
|
121
|
-
}
|
|
122
|
-
```
|
|
134
|
+
Failed responses include 400 (missing email), 404 (user not found), or 401/500 depending on configuration errors.
|
|
123
135
|
|
|
124
|
-
***Note:*** You will still have to build the password reset page on your front end.
|
|
136
|
+
***Note:*** You will still have to build the password reset page on your front end. The recovery link uses `password_recovery_url` from config plus the JWT token.
|
|
125
137
|
|
|
126
138
|
### JWT
|
|
127
139
|
|
|
128
|
-
A Javascript Web Token can be used to log the user in through a URL.
|
|
140
|
+
A Javascript Web Token can be used to log the user in through a URL.
|
|
129
141
|
|
|
130
142
|
POST `http://localhost:4001/login/getjwt`
|
|
131
143
|
|
|
132
144
|
Data:
|
|
133
|
-
|
|
145
|
+
|
|
146
|
+
```json
|
|
134
147
|
{
|
|
135
148
|
"email": "blah@blah.com"
|
|
136
149
|
}
|
|
137
150
|
```
|
|
138
151
|
|
|
139
|
-
Successful Response (200):
|
|
140
|
-
|
|
152
|
+
Successful Response (200):
|
|
153
|
+
|
|
154
|
+
```json
|
|
141
155
|
{
|
|
142
156
|
"status": "ok",
|
|
143
157
|
"jwt": "<jwt>"
|
|
144
158
|
}
|
|
145
159
|
```
|
|
146
160
|
|
|
147
|
-
Failed Response (403):
|
|
148
|
-
|
|
161
|
+
Failed Response (403 or 404):
|
|
162
|
+
|
|
163
|
+
```json
|
|
149
164
|
{
|
|
150
165
|
"status": "fail",
|
|
151
166
|
"message": "Unauthorized",
|
|
@@ -153,7 +168,16 @@ Failed Response (403):
|
|
|
153
168
|
}
|
|
154
169
|
```
|
|
155
170
|
|
|
156
|
-
|
|
171
|
+
### OAuth2
|
|
172
|
+
|
|
173
|
+
OAuth login is configured programmatically (see [Configuration](configuration.md#oauth)).
|
|
174
|
+
|
|
175
|
+
- `GET /login/oauth/:provider` — redirects to the provider's authorization URL
|
|
176
|
+
- `GET /login/oauth/callback/:provider` — handles the callback and redirects to `oauth.success_uri` or `oauth.fail_uri` with a token or error
|
|
177
|
+
|
|
178
|
+
The provider name (`:provider`) must match a key under `oauth` in your config (excluding `success_uri` and `fail_uri`).
|
|
179
|
+
|
|
180
|
+
## Authenticating API requests
|
|
157
181
|
|
|
158
182
|
### Basic Auth
|
|
159
183
|
|
|
@@ -161,11 +185,11 @@ Basic auth encodes (NOTE: ***NOT*** encrypts) your username and password and sen
|
|
|
161
185
|
|
|
162
186
|
***WARNING:*** You must only use basic auth over SSL, since it is trivial to decode the username and password. In fact, you should use SSL for everything, anyway.
|
|
163
187
|
|
|
164
|
-
A basic auth is created by base64-encoding your username and password, separated by a colon.
|
|
188
|
+
A basic auth token is created by base64-encoding your username and password, separated by a colon.
|
|
165
189
|
|
|
166
|
-
Eg. `echo "blah@blah.com:password" | base64` would generate a basic auth token on the command line.
|
|
190
|
+
Eg. `echo -n "blah@blah.com:password" | base64` would generate a basic auth token on the command line.
|
|
167
191
|
|
|
168
|
-
However, `echo "
|
|
192
|
+
However, `echo "YmxhaEBibGFoLmNvbTpwYXNzd29yZA==" | base64 --decode` would reveal the username and password, which is why it's not safe to use it on an unencrypted connection.
|
|
169
193
|
|
|
170
194
|
Header: `Authorization: Basic <your basic token>`
|
|
171
195
|
|
|
@@ -173,11 +197,10 @@ Header: `Authorization: Basic <your basic token>`
|
|
|
173
197
|
|
|
174
198
|
_This is the preferred method of authenticating._
|
|
175
199
|
|
|
176
|
-
Bearer tokens are ephemeral tokens that will expire
|
|
200
|
+
Bearer tokens are ephemeral tokens that will expire after a configured period. When a user logs out of a session, they are revoked.
|
|
177
201
|
|
|
178
202
|
Header: `Authorization: Bearer <your bearer token>`
|
|
179
203
|
|
|
180
204
|
### API Key
|
|
181
205
|
|
|
182
|
-
The API Key is a permanent key that doesn't expire. It can be used by adding `?apikey=<apikey>` to the end of any request, or sending `
|
|
183
|
-
|
|
206
|
+
The API Key is a permanent key that doesn't expire. It can be used by adding `?apikey=<apikey>` to the end of any request, or sending `x-api-key: <apikey>` in the header.
|
package/docs/bulk_writes.md
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
# Bulk Writes
|
|
2
2
|
|
|
3
|
-
You can bulk writes through the `/bulkwrite/<modelname>` endpoint.
|
|
3
|
+
You can perform bulk writes through the `/bulkwrite/<modelname>` endpoint. **Disabled by default** unless the model opts in with `advanced_queries: { bulkwrite: true }`. Only allowlisted operations (`insertOne`, `updateOne`, `replaceOne`, `deleteOne`) are accepted; `updateMany` / `deleteMany` require admin.
|
|
4
|
+
|
|
5
|
+
Authorisation works a little differently — the user must have **create, read, update, and delete** permissions on the model.
|
|
4
6
|
|
|
5
7
|
***WARNING*** Be cautious when using bulk writes because you can destroy your data. Don't forget to back up!
|
|
6
8
|
|
|
7
9
|
Eg:
|
|
8
|
-
|
|
10
|
+
|
|
11
|
+
```json
|
|
9
12
|
[
|
|
10
13
|
{
|
|
11
14
|
"insertOne": {
|
|
12
15
|
"document": {
|
|
13
16
|
"foo": "Foo2",
|
|
14
17
|
"bar": "Bar2",
|
|
15
|
-
"yack": { "yack": "yack2", "shmack": 2 }
|
|
18
|
+
"yack": { "yack": "yack2", "shmack": 2 }
|
|
16
19
|
}
|
|
17
|
-
}
|
|
20
|
+
}
|
|
18
21
|
},
|
|
19
22
|
{
|
|
20
23
|
"updateOne": {
|
|
@@ -36,10 +39,10 @@ Eg:
|
|
|
36
39
|
"update": {
|
|
37
40
|
"foo": "Foo3",
|
|
38
41
|
"bar": "Bar3",
|
|
39
|
-
"yack": { "yack": "yack3", "shmack": 3 }
|
|
42
|
+
"yack": { "yack": "yack3", "shmack": 3 }
|
|
40
43
|
},
|
|
41
44
|
"upsert": true
|
|
42
|
-
}
|
|
45
|
+
}
|
|
43
46
|
}
|
|
44
|
-
]
|
|
45
|
-
```
|
|
47
|
+
]
|
|
48
|
+
```
|
package/docs/caching.md
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
1
|
# Caching
|
|
2
2
|
|
|
3
|
-
Enable caching to speed up
|
|
4
|
-
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
Enable caching to speed up repeated GET requests. Caching is disabled by default. Enable via environment variables (or pass `cache` in the object to `JXP()`):
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
CACHE_ENABLED=true
|
|
7
|
+
CACHE_DEBUG=false
|
|
8
|
+
CACHE_TTL=3600
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## How it works
|
|
12
|
+
|
|
13
|
+
JXP uses an in-process [node-cache](https://www.npmjs.com/package/node-cache) store (not Memcached or Redis). When caching is enabled:
|
|
14
|
+
|
|
15
|
+
- Successful GET responses for list and single-item routes may be stored under a key derived from the model name, item id, and query string.
|
|
16
|
+
- Response headers include:
|
|
17
|
+
- `jxp-cache`: `hit` or `miss`
|
|
18
|
+
- `jxp-cache-key`: the cache key used for that request
|
|
19
|
+
- POST, PUT, and DELETE operations clear cached keys for the affected model.
|
|
20
|
+
|
|
21
|
+
Set `CACHE_DEBUG=true` to log cache expiry and flush events to the console.
|
|
22
|
+
|
|
23
|
+
## Admin endpoints
|
|
24
|
+
|
|
25
|
+
Requires **admin** authentication (same as other admin-only routes):
|
|
26
|
+
|
|
27
|
+
- `GET /cache/stats` — returns node-cache statistics when caching is enabled, or `{ "cache_enabled": false }` when disabled
|
|
28
|
+
- `GET /cache/clear` — flushes all cached entries
|
|
29
|
+
|
|
30
|
+
See also [Configuration](configuration.md#cache).
|