@webresto/graphql 1.3.7 → 1.3.8
Sign up to get free protection for your applications and to get access to all the features.
- package/.gitattributes +2 -0
- package/.gitlab-ci.yml +18 -0
- package/.vscode/extensions.json +5 -0
- package/docs/actions.md +25 -0
- package/docs/authorization.md +215 -0
- package/docs/captcha.md +71 -0
- package/docs/device-id.md +30 -0
- package/docs/messages.md +10 -0
- package/docs/user.md +54 -0
- package/index.d.ts +0 -1
- package/index.js +6 -2
- package/index.ts +2 -2
- package/lib/afterHook.js +8 -0
- package/lib/afterHook.ts +9 -0
- package/lib/bindTranslations.d.ts +1 -0
- package/lib/bindTranslations.js +40 -0
- package/lib/bindTranslations.ts +39 -0
- package/lib/defaults.d.ts +1 -0
- package/lib/defaults.js +49 -10
- package/lib/defaults.ts +55 -0
- package/lib/eventHelper.d.ts +14 -5
- package/lib/eventHelper.js +28 -9
- package/lib/eventHelper.ts +41 -8
- package/lib/getRecomended.d.ts +1 -0
- package/lib/getRecomended.js +29 -0
- package/lib/getRecomended.ts +31 -0
- package/lib/graphqlHelper.d.ts +3 -4
- package/lib/graphqlHelper.js +184 -72
- package/lib/graphqlHelper.ts +329 -185
- package/lib/jwt.d.ts +10 -0
- package/lib/jwt.js +43 -0
- package/lib/jwt.ts +61 -0
- package/package.json +13 -6
- package/src/additionalResolvers.d.ts +72 -9
- package/src/additionalResolvers.js +93 -24
- package/src/additionalResolvers.ts +105 -34
- package/src/graphql.d.ts +5 -3
- package/src/graphql.js +170 -37
- package/src/graphql.ts +210 -60
- package/src/resolvers/bonusProgram.d.ts +32 -0
- package/src/resolvers/bonusProgram.js +65 -0
- package/src/resolvers/bonusProgram.ts +79 -0
- package/src/resolvers/captcha.d.ts +11 -0
- package/src/resolvers/captcha.js +19 -0
- package/src/resolvers/captcha.ts +16 -0
- package/src/resolvers/checkout.d.ts +35 -16
- package/src/resolvers/checkout.js +171 -94
- package/src/resolvers/checkout.ts +214 -104
- package/src/resolvers/dishAndModifier.js +8 -4
- package/src/resolvers/dishAndModifier.ts +4 -0
- package/src/resolvers/error.d.ts +9 -0
- package/src/resolvers/error.js +21 -0
- package/src/resolvers/error.ts +21 -0
- package/src/resolvers/menu.d.ts +9 -0
- package/src/resolvers/menu.js +12 -0
- package/src/resolvers/menu.ts +10 -0
- package/src/resolvers/order.d.ts +527 -0
- package/src/resolvers/order.js +349 -0
- package/src/resolvers/order.ts +435 -0
- package/src/resolvers/paymentMethod.js +7 -3
- package/src/resolvers/paymentMethod.ts +9 -5
- package/src/resolvers/pickupPoint.d.ts +1 -0
- package/src/resolvers/pickupPoint.js +24 -0
- package/src/resolvers/pickupPoint.ts +23 -0
- package/src/resolvers/recomended.d.ts +13 -0
- package/src/resolvers/recomended.js +80 -0
- package/src/resolvers/recomended.ts +86 -0
- package/src/resolvers/restrictions.d.ts +37 -1
- package/src/resolvers/restrictions.js +100 -15
- package/src/resolvers/restrictions.ts +106 -14
- package/src/resolvers/streets.d.ts +1 -1
- package/src/resolvers/streets.js +1 -4
- package/src/resolvers/streets.ts +1 -3
- package/src/resolvers/subscriptions.d.ts +4 -4
- package/src/resolvers/subscriptions.js +49 -12
- package/src/resolvers/subscriptions.ts +59 -14
- package/src/resolvers/telemetry.d.ts +14 -0
- package/src/resolvers/telemetry.js +25 -0
- package/src/resolvers/telemetry.ts +24 -0
- package/src/resolvers/user.d.ts +82 -0
- package/src/resolvers/user.js +416 -0
- package/src/resolvers/user.ts +621 -0
- package/src/resolvers/userLocation.d.ts +53 -0
- package/src/resolvers/userLocation.js +74 -0
- package/src/resolvers/userLocation.ts +125 -0
- package/src/resolvers/userOTPrequest.d.ts +21 -0
- package/src/resolvers/userOTPrequest.js +57 -0
- package/src/resolvers/userOTPrequest.ts +75 -0
- package/test/e2e_helper.js +157 -0
- package/test/e2e_helper.ts +212 -0
- package/test/fixture/config/i18n.js +7 -20
- package/test/fixture/config/locales/de.json +1 -0
- package/test/fixture/config/locales/en.json +10 -0
- package/test/fixture/config/locales/es.json +3 -0
- package/test/fixture/config/locales/fr.json +1 -0
- package/test/fixture/config/log.js +1 -1
- package/test/fixture/package.json +5 -6
- package/test/fixture/patches/rttc+10.0.1.patch +17 -0
- package/test/integration/captcha.test.js +20 -0
- package/test/integration/captcha.test.ts +25 -0
- package/test/integration/dish.test.js +35 -0
- package/test/integration/dish.test.ts +43 -0
- package/test/integration/graphql.test.js +5 -2
- package/test/integration/graphql.test.ts +2 -4
- package/test/integration/images.test.js +35 -0
- package/test/integration/images.test.ts +40 -0
- package/test/integration/locale.test.js +26 -0
- package/test/integration/locale.test.ts +32 -0
- package/test/integration/order.test.js +56 -43
- package/test/integration/order.test.ts +59 -59
- package/test/integration/subscriptions.test.js +136 -0
- package/test/integration/subscriptions.test.ts +162 -0
- package/test/integration/user.test.js +249 -0
- package/test/integration/user.test.ts +299 -0
- package/test/unit/first.test.js +4 -2
- package/test/unit/first.test.ts +1 -1
- package/test/unit/get-recomended.test.js +56 -0
- package/test/unit/get-recomended.test.ts +63 -0
- package/translations/de.json +2 -0
- package/translations/en.json +3 -0
- package/translations/es.json +3 -0
- package/translations/fr.json +2 -0
- package/translations/ru.json +36 -0
- package/tsconfig.json +20 -5
- package/types/global.d.ts +30 -0
- package/types/global.js +2 -0
- package/types/global.ts +31 -0
- package/types/primitives.d.ts +19 -0
- package/types/references.d.ts +1 -0
- package/types/restoGraphQLConfig.d.ts +13 -0
- package/lib/afterHook.ts___graphql-transport-ws +0 -138
- package/lib/afterHook.ts___graphql-ws +0 -133
- package/lib/errorWrapper.d.ts +0 -4
- package/lib/errorWrapper.js +0 -13
- package/lib/errorWrapper.ts +0 -12
- package/notes.md +0 -1976
- package/src/resolvers/cart.d.ts +0 -343
- package/src/resolvers/cart.js +0 -196
- package/src/resolvers/cart.ts +0 -278
- package/test/fixture/config/connections.js +0 -9
- package/test/integration/sails_not_crash.test.js +0 -3
- package/test/integration/sails_not_crash.test.ts +0 -3
package/.gitattributes
ADDED
package/.gitlab-ci.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
variables:
|
2
|
+
DOC_PUB_SH: https://raw.githubusercontent.com/webresto/docs/master/ci-publish.sh
|
3
|
+
DOC_DIR: content/en/docs/graphql
|
4
|
+
stages:
|
5
|
+
- doc
|
6
|
+
|
7
|
+
doc-publish:
|
8
|
+
stage: doc
|
9
|
+
# only:
|
10
|
+
# - master
|
11
|
+
# - main
|
12
|
+
script:
|
13
|
+
- curl $DOC_PUB_SH | bash /dev/stdin docs/authorization.md $DOC_DIR/authorization.md
|
14
|
+
- curl $DOC_PUB_SH | bash /dev/stdin docs/captcha.md $DOC_DIR/captcha.md
|
15
|
+
- curl $DOC_PUB_SH | bash /dev/stdin docs/messages.md $DOC_DIR/messages.md
|
16
|
+
- curl $DOC_PUB_SH | bash /dev/stdin docs/actions.md $DOC_DIR/actions.md
|
17
|
+
- curl $DOC_PUB_SH | bash /dev/stdin docs/user.md $DOC_DIR/user.md
|
18
|
+
- curl $DOC_PUB_SH | bash /dev/stdin docs/device-id.md $DOC_DIR/device-id.md
|
package/docs/actions.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
---
|
2
|
+
title: "Actions"
|
3
|
+
linkTitle: "Actions"
|
4
|
+
description: >
|
5
|
+
WebServer action subscription
|
6
|
+
---
|
7
|
+
|
8
|
+
|
9
|
+
> ⚠️ [`X-Device-Id`](./device-id.md) You should pass deviceID
|
10
|
+
|
11
|
+
|
12
|
+
const action = {
|
13
|
+
type: "PaymentRedirect",
|
14
|
+
data: {
|
15
|
+
redirectLink: paymentResponse.redirectLink,
|
16
|
+
},
|
17
|
+
};
|
18
|
+
|
19
|
+
|
20
|
+
let action: Action = {
|
21
|
+
type: "GoTo",
|
22
|
+
data: {
|
23
|
+
"section": "login"
|
24
|
+
}
|
25
|
+
}
|
@@ -0,0 +1,215 @@
|
|
1
|
+
---
|
2
|
+
title: "Login and authorization process for the webresto server"
|
3
|
+
linkTitle: "Authorization & login"
|
4
|
+
description: >
|
5
|
+
Webresto server GraphQL API login process
|
6
|
+
---
|
7
|
+
|
8
|
+
## Lyrics
|
9
|
+
|
10
|
+
Registration can be flexibly configured through flags in restrictions. In fact, the two main cases that we want to cover are quick registration by phone or email.
|
11
|
+
|
12
|
+
The email can be useful for corporate catering, or nutrition subscriptions. Email and phone are the same.
|
13
|
+
|
14
|
+
We understand that in most cases the phone will be selected as the login for the webresto account account. therefore it is the default when the site is deployed.
|
15
|
+
|
16
|
+
[There is a method for quick entry by OTP](#login) `login`, with quick registration. In this case, we register an account if there is none, or we carry out authorization
|
17
|
+
|
18
|
+
If a `passwordPolicy` is required, then the user must also specify a password during registration. In next login, it will be possible to enter with a password. It is possible that the password is set from the last OTP `from_otp`. So the password may be, not be, or even the last of the OTP is put
|
19
|
+
|
20
|
+
Other types of authorization must be implemented in-house and are not included in the basic package
|
21
|
+
|
22
|
+
|
23
|
+
> ⚠️ By default setting `passwordPolicy = from_otp` it means what last OTP was setting as password, but you can get OTP in any time
|
24
|
+
|
25
|
+
> ⚠️ `X-Device-Id` you should pass [deviceId](./device-id.md)
|
26
|
+
|
27
|
+
> ⚠️ read more about [mocks](./mocks.md)
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
## User restrictions
|
32
|
+
|
33
|
+
To get user settings use the user section in restrictions
|
34
|
+
|
35
|
+
```gql
|
36
|
+
{restrictions{
|
37
|
+
user {
|
38
|
+
loginField # by default: `phone`
|
39
|
+
passwordPolicy # possible 3 variants ['required', 'from_otp', 'disabled'] by default: `from_otp` it means what need only OTP, for next logins passwordRequired, disabled is means password forbidden and you need all time get OTP password
|
40
|
+
loginOTPRequired # by default: `false`
|
41
|
+
allowedPhoneCountries # List of all countries allowed to login by phone
|
42
|
+
linkToProcessingPersonalData # Link to doc
|
43
|
+
linkToUserAgreement # Link to doc
|
44
|
+
customFields # Zodiac sign, Human desing type, Best Friend, referal link
|
45
|
+
}
|
46
|
+
}}
|
47
|
+
|
48
|
+
```
|
49
|
+
|
50
|
+
---
|
51
|
+
|
52
|
+
## 🛡 Authentication
|
53
|
+
|
54
|
+
Get JWTtoken from `action` field on `login` mutation responce, and next pass JWT token without any marks in header `Authorization`
|
55
|
+
```
|
56
|
+
header: {
|
57
|
+
Authorization: "ciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InVzZX",
|
58
|
+
}
|
59
|
+
```
|
60
|
+
|
61
|
+
|
62
|
+
## OTPRequest
|
63
|
+
Send OTP for specific login
|
64
|
+
|
65
|
+
> ⚠️ See stdout nodejs log in development mode you will see OTPcode
|
66
|
+
|
67
|
+
### Definition
|
68
|
+
|
69
|
+
```gql
|
70
|
+
mutation OTPRequest(
|
71
|
+
login: String! (by loginField)
|
72
|
+
captcha: Captcha! (solved captcha for label "OTPRequest:%login%")
|
73
|
+
): OTPResponse
|
74
|
+
```
|
75
|
+
|
76
|
+
1. The OTPRequest mutation requests an OTP code for the provided phone or email login.
|
77
|
+
2. The captcha provided must match the solved captcha for the label "OTPRequest:%login%".
|
78
|
+
3. The OTP is generated and sent to the provided phone or email login.
|
79
|
+
|
80
|
+
### Error Handling
|
81
|
+
|
82
|
+
If the provided captcha does not match, a generic error message with the message "bad captcha" will be thrown.
|
83
|
+
Example
|
84
|
+
|
85
|
+
```gql
|
86
|
+
|
87
|
+
mutation {
|
88
|
+
OTPRequest(
|
89
|
+
login: "13450000123",
|
90
|
+
captcha: {
|
91
|
+
id: "uuid",
|
92
|
+
solution: "123n"
|
93
|
+
}
|
94
|
+
) {
|
95
|
+
id
|
96
|
+
nextOTPSeconds
|
97
|
+
message {
|
98
|
+
id
|
99
|
+
title
|
100
|
+
type
|
101
|
+
message
|
102
|
+
}
|
103
|
+
action {
|
104
|
+
id
|
105
|
+
type
|
106
|
+
data
|
107
|
+
}
|
108
|
+
}
|
109
|
+
}
|
110
|
+
```
|
111
|
+
|
112
|
+
|
113
|
+
---
|
114
|
+
|
115
|
+
## Login
|
116
|
+
|
117
|
+
If you getting account access by OTP for unknown account, server create new account. For cases when account is registred
|
118
|
+
server restore account and send login token automaticaly in action. When account is not registred, server make new account, (with `hasFilledAllCustomFields: false` ).
|
119
|
+
|
120
|
+
> ⚠️ It's funny but we first create an account and then go through the process of filling it out (registration)
|
121
|
+
|
122
|
+
>Step by step:
|
123
|
+
>1. get OTP
|
124
|
+
>2. Solve captcha
|
125
|
+
>3. Send auth mutatuion and receive JWT token
|
126
|
+
|
127
|
+
> ⚠️ After login you receive JWT in action (login)
|
128
|
+
|
129
|
+
### Definition
|
130
|
+
|
131
|
+
```gql
|
132
|
+
mutation login(
|
133
|
+
login: String!
|
134
|
+
|
135
|
+
"(required when login field is phone)"
|
136
|
+
phone: Phone
|
137
|
+
|
138
|
+
"(when passwordPolicy is required )"
|
139
|
+
password: String
|
140
|
+
|
141
|
+
"from otpRequest"
|
142
|
+
otp: String!
|
143
|
+
|
144
|
+
"(solved captcha for label 'auth:%login%')"
|
145
|
+
captcha: Captcha!
|
146
|
+
): UserResponse
|
147
|
+
```
|
148
|
+
|
149
|
+
### Function
|
150
|
+
|
151
|
+
1. if `passwordPolicy == 'required'` you should pass password for setup password in next time, in other case last OTP sets as password
|
152
|
+
2. When `passwordPolicy == 'from_otp'` you can pass password or OTP
|
153
|
+
3. When `passwordPolicy == 'disabled'` you not need pass password
|
154
|
+
4. When loginField is phone you need pass Phone in Object format
|
155
|
+
5. When `loginOTPRequired` you should pass OTP
|
156
|
+
|
157
|
+
### Error Handling
|
158
|
+
|
159
|
+
|
160
|
+
### Example
|
161
|
+
|
162
|
+
```gql
|
163
|
+
mutation {
|
164
|
+
login(
|
165
|
+
login: "13450000123",
|
166
|
+
password: "Password",
|
167
|
+
otp: "123456"
|
168
|
+
phone: { otp: "+1", number: "3450000123" },
|
169
|
+
captcha: {
|
170
|
+
id: "uuid",
|
171
|
+
solution: "123n"
|
172
|
+
}
|
173
|
+
) {
|
174
|
+
user {
|
175
|
+
id
|
176
|
+
name
|
177
|
+
}
|
178
|
+
# Toast "You logined successfully", also this will be sent by Messages subscription
|
179
|
+
message {
|
180
|
+
id # unique id is equal subscription message id
|
181
|
+
title
|
182
|
+
type
|
183
|
+
message
|
184
|
+
}
|
185
|
+
# Here recive JWT token, also this will be sent by Actions subscription
|
186
|
+
action {
|
187
|
+
id # unique id is equal subscription action id
|
188
|
+
type # returns `authorization`
|
189
|
+
data # retruns `JWT_TOKEN`
|
190
|
+
}
|
191
|
+
}}
|
192
|
+
```
|
193
|
+
|
194
|
+
---
|
195
|
+
|
196
|
+
## Logout
|
197
|
+
|
198
|
+
> 🛡 Authentication required
|
199
|
+
>
|
200
|
+
```gql
|
201
|
+
logout(
|
202
|
+
deviceID: String (Optional field if not pass logout from current device)
|
203
|
+
): Response
|
204
|
+
```
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
## logout from all devices
|
209
|
+
|
210
|
+
> 🛡 Authentication required
|
211
|
+
|
212
|
+
```gql
|
213
|
+
logoutFromAllDevices: Response
|
214
|
+
```
|
215
|
+
|
package/docs/captcha.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
---
|
2
|
+
title: "Catcha POW captcha"
|
3
|
+
linkTitle: "Captcha"
|
4
|
+
description: >
|
5
|
+
WebServer generate captcha for request
|
6
|
+
---
|
7
|
+
|
8
|
+
## Get captcha type
|
9
|
+
Where a captcha is expected, it is required at the beginning to request the type of captcha, and solve it. Before making a mutation on the server
|
10
|
+
|
11
|
+
```gql
|
12
|
+
{restrictions{
|
13
|
+
captchaType
|
14
|
+
}}
|
15
|
+
```
|
16
|
+
|
17
|
+
## POW captcha type
|
18
|
+
By default you recive `captchaType='POW'` this captcha refer from https://github.com/fabiospampinato/crypto-puzzle
|
19
|
+
This module implements a simple cryptographic captcha.
|
20
|
+
|
21
|
+
```js
|
22
|
+
import Puzzle from 'crypto-puzzle';
|
23
|
+
|
24
|
+
const difficulty = 100000;
|
25
|
+
const puzzle = await Puzzle.generate ( difficulty );
|
26
|
+
const solution = await Puzzle.solve ( puzzle.question );
|
27
|
+
|
28
|
+
console.assert ( puzzle.solution === solution );
|
29
|
+
```
|
30
|
+
|
31
|
+
The server generates a job and issues a job request to the client `captchaGetJob`
|
32
|
+
|
33
|
+
|
34
|
+
## Get captcha job
|
35
|
+
|
36
|
+
```gql
|
37
|
+
{captchaGetJob(label: "login:+12340000123") {
|
38
|
+
id
|
39
|
+
task
|
40
|
+
}}
|
41
|
+
```
|
42
|
+
|
43
|
+
The label is calculated according to the formula for each mutation differently. This gives us the opportunity to separate each mutation in and the task for the captcha into a separate thread. If the stream is attacked then the server will increase difficulty for separate thread.
|
44
|
+
|
45
|
+
> Default make formula logic for **`label` = [mutation name] + ":" + [some `id` or `login`]**
|
46
|
+
|
47
|
+
> ⚠️ **Any mutation which required captcha must contain label description.** See in graphql sandbox
|
48
|
+
|
49
|
+
## Other captchas
|
50
|
+
Server can connect other captcha it possible by captcha adapter
|
51
|
+
But all data types will remain the same
|
52
|
+
|
53
|
+
## Data types
|
54
|
+
|
55
|
+
```gql
|
56
|
+
type CaptchaJob {
|
57
|
+
""
|
58
|
+
id: String
|
59
|
+
""
|
60
|
+
task: String
|
61
|
+
}
|
62
|
+
|
63
|
+
input Captcha {
|
64
|
+
"Captcha job ID"
|
65
|
+
id: String
|
66
|
+
"Resolved captcha"
|
67
|
+
solution: String
|
68
|
+
}
|
69
|
+
```
|
70
|
+
|
71
|
+
input Captcha
|
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
title: "Device ID"
|
3
|
+
linkTitle: "DeviceID"
|
4
|
+
description: >
|
5
|
+
Abount WebResto server deviceID
|
6
|
+
---
|
7
|
+
|
8
|
+
|
9
|
+
> ⚠️ `X-Device-Id` header required for all graphql request
|
10
|
+
|
11
|
+
## Device ID
|
12
|
+
|
13
|
+
`deviceId` is Unique `string` passed as Header `X-Device-Id: 3d5ab688e195587101e2aa9496448d9b`
|
14
|
+
|
15
|
+
For `subscribtions` you should pass deviceId as params
|
16
|
+
|
17
|
+
```gql
|
18
|
+
order(deviceId: String): Order
|
19
|
+
```
|
20
|
+
|
21
|
+
> 🧠 After login you can pass only JWT token because `deviceId` present in JWT
|
22
|
+
|
23
|
+
If user restore account from same browser/device it can helps to identify. When user wants to close session on forgoten, need just select session by DeviceId
|
24
|
+
|
25
|
+
As example you can use:
|
26
|
+
[**biri**](https://github.com/dashersw/biri)
|
27
|
+
[**fingerprintjs**](https://fingerprintjs.github.io/fingerprintjs/)
|
28
|
+
|
29
|
+
|
30
|
+
Please set deviceId header globaly for all request
|
package/docs/messages.md
ADDED
package/docs/user.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
---
|
2
|
+
title: "User methods"
|
3
|
+
linkTitle: "User methods"
|
4
|
+
description: >
|
5
|
+
User methods after login
|
6
|
+
---
|
7
|
+
|
8
|
+
> ⚠️ `X-Device-Id` you should pass [deviceId](./device-id.md)
|
9
|
+
|
10
|
+
## Get user info
|
11
|
+
|
12
|
+
> 🛡 Authentication required
|
13
|
+
|
14
|
+
To get user model data
|
15
|
+
|
16
|
+
```gql
|
17
|
+
aboutMe {
|
18
|
+
firstName
|
19
|
+
lastName
|
20
|
+
hasFilledAllCustomFields
|
21
|
+
customFields
|
22
|
+
}
|
23
|
+
```
|
24
|
+
|
25
|
+
---
|
26
|
+
|
27
|
+
|
28
|
+
## Update user info
|
29
|
+
|
30
|
+
> 🛡 Authentication required
|
31
|
+
|
32
|
+
Update user model
|
33
|
+
|
34
|
+
### Definition
|
35
|
+
|
36
|
+
```gql
|
37
|
+
mutation updateMe(
|
38
|
+
user: InputUser
|
39
|
+
): UserResponse
|
40
|
+
```
|
41
|
+
|
42
|
+
## Delete the User
|
43
|
+
|
44
|
+
> 🛡 Authentication required
|
45
|
+
|
46
|
+
Deleting after depend of webresto server flag `KEEP_DELETED_USER_DAYS`
|
47
|
+
|
48
|
+
### Definition
|
49
|
+
|
50
|
+
```gql
|
51
|
+
mutation deleteMe(
|
52
|
+
otp: String
|
53
|
+
): UserResponse
|
54
|
+
```
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
'use strict';
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
3
|
if (k2 === undefined) k2 = k;
|
4
|
-
Object.
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
5
9
|
}) : (function(o, m, k, k2) {
|
6
10
|
if (k2 === undefined) k2 = k;
|
7
11
|
o[k2] = m[k];
|
@@ -10,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
11
15
|
};
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
/// <reference path="../node_modules/@webresto/core/interfaces/globalTypes.d.ts"/>
|
13
18
|
const helper = require('./lib/graphqlHelper').default;
|
14
19
|
module.exports = function (sails) {
|
15
20
|
return {
|
@@ -19,4 +24,3 @@ module.exports = function (sails) {
|
|
19
24
|
};
|
20
25
|
__exportStar(require("./lib/eventHelper"), exports);
|
21
26
|
__exportStar(require("./lib/graphqlHelper"), exports);
|
22
|
-
__exportStar(require("./lib/errorWrapper"), exports);
|
package/index.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
'use strict';
|
2
|
+
/// <reference path="../node_modules/@webresto/core/interfaces/globalTypes.d.ts"/>
|
2
3
|
|
3
4
|
const helper = require('./lib/graphqlHelper').default;
|
4
5
|
|
@@ -10,5 +11,4 @@ module.exports = function (sails) {
|
|
10
11
|
};
|
11
12
|
|
12
13
|
export * from './lib/eventHelper';
|
13
|
-
export * from './lib/graphqlHelper';
|
14
|
-
export * from './lib/errorWrapper';
|
14
|
+
export * from './lib/graphqlHelper';
|
package/lib/afterHook.js
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
const graphql_1 = require("../src/graphql");
|
4
|
+
const bindTranslations_1 = require("./bindTranslations");
|
4
5
|
let cache = null;
|
6
|
+
const eventHelper_1 = require("./eventHelper");
|
5
7
|
async function default_1() {
|
6
8
|
try {
|
7
9
|
sails.log.verbose('>>> graphql hook starting');
|
@@ -16,6 +18,12 @@ async function default_1() {
|
|
16
18
|
sails.hooks.http.app._router.stack.splice(1, 0, layer);
|
17
19
|
graphServer.installSubscriptionHandlers(sails.hooks.http.server);
|
18
20
|
});
|
21
|
+
if (await Settings.get("JWT_SECRET") === undefined) {
|
22
|
+
//@ts-ignore
|
23
|
+
const random = (0, eventHelper_1.getRandom)();
|
24
|
+
await Settings.set("JWT_SECRET", random);
|
25
|
+
}
|
26
|
+
(0, bindTranslations_1.default)();
|
19
27
|
}
|
20
28
|
catch (e) {
|
21
29
|
sails.log.error('graphql > afterHook > error1', e);
|
package/lib/afterHook.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import graphql from '../src/graphql';
|
2
|
+
import bindTranslations from './bindTranslations';
|
2
3
|
let cache = null;
|
4
|
+
import { getRandom } from "./eventHelper";
|
3
5
|
|
4
6
|
export default async function () {
|
5
7
|
try {
|
@@ -18,7 +20,14 @@ export default async function () {
|
|
18
20
|
graphServer.installSubscriptionHandlers(sails.hooks.http.server);
|
19
21
|
})
|
20
22
|
|
23
|
+
if (await Settings.get("JWT_SECRET") === undefined) {
|
24
|
+
//@ts-ignore
|
25
|
+
const random = getRandom();
|
26
|
+
await Settings.set("JWT_SECRET", random)
|
27
|
+
}
|
21
28
|
|
29
|
+
|
30
|
+
bindTranslations()
|
22
31
|
} catch (e) {
|
23
32
|
sails.log.error('graphql > afterHook > error1', e);
|
24
33
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export default function bindTranslations(): void;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const path = require("path");
|
4
|
+
const fs = require("fs");
|
5
|
+
function bindTranslations() {
|
6
|
+
// load adminpanel translations
|
7
|
+
const moduleTranslationPath = path.resolve(__dirname, `../translations`);
|
8
|
+
if (fs.existsSync(moduleTranslationPath)) {
|
9
|
+
loadTranslations(path.resolve(moduleTranslationPath));
|
10
|
+
}
|
11
|
+
}
|
12
|
+
exports.default = bindTranslations;
|
13
|
+
function loadTranslations(translationsPath) {
|
14
|
+
console.log(translationsPath);
|
15
|
+
try {
|
16
|
+
let translationsDirectoryPath = path.resolve(translationsPath);
|
17
|
+
let translations = fs.readdirSync(translationsDirectoryPath).filter(function (file) {
|
18
|
+
return path.extname(file).toLowerCase() === ".json";
|
19
|
+
});
|
20
|
+
let localesList = sails.config.i18n.locales;
|
21
|
+
for (let locale of localesList) {
|
22
|
+
if (translations.includes(`${locale}.json`)) {
|
23
|
+
try {
|
24
|
+
let jsonData = require(`${translationsDirectoryPath}/${locale}.json`);
|
25
|
+
console.log(locale, jsonData);
|
26
|
+
sails.hooks.i18n.appendLocale(locale, jsonData);
|
27
|
+
}
|
28
|
+
catch (error) {
|
29
|
+
sails.log.error(`Load translations > Error when reading ${locale}.json: ${error}`);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
else {
|
33
|
+
sails.log.debug(`Load translations > Cannot find ${locale} locale in translations directory`);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
catch (e) {
|
38
|
+
sails.log.error("Load translations > Error when loading translations", e);
|
39
|
+
}
|
40
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import * as path from "path";
|
2
|
+
import * as fs from "fs";
|
3
|
+
|
4
|
+
export default function bindTranslations() {
|
5
|
+
// load adminpanel translations
|
6
|
+
|
7
|
+
const moduleTranslationPath = path.resolve(__dirname, `../translations`)
|
8
|
+
if (fs.existsSync(moduleTranslationPath)) {
|
9
|
+
loadTranslations(path.resolve(moduleTranslationPath));
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
function loadTranslations(translationsPath: string): void {
|
14
|
+
console.log(translationsPath)
|
15
|
+
|
16
|
+
try {
|
17
|
+
let translationsDirectoryPath = path.resolve(translationsPath);
|
18
|
+
let translations = fs.readdirSync(translationsDirectoryPath).filter(function (file) {
|
19
|
+
return path.extname(file).toLowerCase() === ".json";
|
20
|
+
});
|
21
|
+
|
22
|
+
let localesList = sails.config.i18n.locales;
|
23
|
+
for (let locale of localesList) {
|
24
|
+
if (translations.includes(`${locale}.json`)) {
|
25
|
+
try {
|
26
|
+
let jsonData = require(`${translationsDirectoryPath}/${locale}.json`);
|
27
|
+
console.log(locale, jsonData)
|
28
|
+
sails.hooks.i18n.appendLocale(locale, jsonData);
|
29
|
+
} catch (error) {
|
30
|
+
sails.log.error(`Load translations > Error when reading ${locale}.json: ${error}`);
|
31
|
+
}
|
32
|
+
} else {
|
33
|
+
sails.log.debug(`Load translations > Cannot find ${locale} locale in translations directory`)
|
34
|
+
}
|
35
|
+
}
|
36
|
+
} catch (e) {
|
37
|
+
sails.log.error("Load translations > Error when loading translations", e)
|
38
|
+
}
|
39
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/lib/defaults.js
CHANGED
@@ -1,12 +1,51 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
let userConfig = {};
|
4
|
+
if (process.env.USER_API != "NO") {
|
5
|
+
userConfig = {
|
6
|
+
...userConfig,
|
7
|
+
user: ['query', 'subscription'],
|
8
|
+
};
|
9
|
+
if (process.env.BONUS_PROGRAM_API != "NO") {
|
10
|
+
userConfig = {
|
11
|
+
...userConfig,
|
12
|
+
bonusprogram: ['query', 'subscription'],
|
13
|
+
userbonusprogram: ['query', 'subscription'],
|
14
|
+
userbonustransaction: ['query', 'subscription']
|
15
|
+
};
|
16
|
+
}
|
17
|
+
if (process.env.USER_LOCATION_API != "NO") {
|
18
|
+
userConfig = {
|
19
|
+
...userConfig,
|
20
|
+
userlocation: ['query', 'subscription'],
|
21
|
+
};
|
22
|
+
}
|
23
|
+
if (process.env.USER_ORDER_HISTORY_API != "NO") {
|
24
|
+
userConfig = {
|
25
|
+
...userConfig,
|
26
|
+
userorderhistory: ['query', 'subscription']
|
27
|
+
};
|
28
|
+
}
|
29
|
+
}
|
1
30
|
module.exports.restographql = {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
31
|
+
whiteListAutoGen: {
|
32
|
+
group: ['query', 'subscription'],
|
33
|
+
dish: ['query', 'subscription'],
|
34
|
+
...userConfig
|
35
|
+
},
|
36
|
+
blackList: [
|
37
|
+
'Order.groupModifiers',
|
38
|
+
'Order.promotionCode',
|
39
|
+
'Order.isPromoting',
|
40
|
+
'Order.rmsOrderData',
|
41
|
+
'Order.promotionFlatDiscount',
|
42
|
+
'Order.promotionDelivery',
|
43
|
+
'Order.promotionCodeCheckValidTill',
|
44
|
+
'Dish.favorites',
|
45
|
+
'worktime',
|
46
|
+
'hash',
|
47
|
+
'isDeleted',
|
48
|
+
'createdAt',
|
49
|
+
'updatedAt'
|
50
|
+
]
|
12
51
|
};
|