@webresto/graphql 1.3.7 → 1.3.8
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/.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/lib/defaults.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { RestoGraphQLConfig } from "../types/restoGraphQLConfig"
|
|
2
|
+
let userConfig = {};
|
|
3
|
+
|
|
4
|
+
if (process.env.USER_API != "NO" ) {
|
|
5
|
+
userConfig = {
|
|
6
|
+
...userConfig,
|
|
7
|
+
user: ['query', 'subscription'],
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (process.env.BONUS_PROGRAM_API != "NO") {
|
|
11
|
+
userConfig = {
|
|
12
|
+
...userConfig,
|
|
13
|
+
bonusprogram: ['query', 'subscription'],
|
|
14
|
+
userbonusprogram: ['query', 'subscription'],
|
|
15
|
+
userbonustransaction: ['query', 'subscription']
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (process.env.USER_LOCATION_API != "NO") {
|
|
20
|
+
userConfig = {
|
|
21
|
+
...userConfig,
|
|
22
|
+
userlocation: ['query', 'subscription'],
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (process.env.USER_ORDER_HISTORY_API != "NO") {
|
|
27
|
+
userConfig = {
|
|
28
|
+
...userConfig,
|
|
29
|
+
userorderhistory: ['query', 'subscription']
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports.restographql = {
|
|
35
|
+
whiteListAutoGen: {
|
|
36
|
+
group: ['query', 'subscription'],
|
|
37
|
+
dish: ['query', 'subscription'],
|
|
38
|
+
...userConfig
|
|
39
|
+
},
|
|
40
|
+
blackList: [
|
|
41
|
+
'Order.groupModifiers',
|
|
42
|
+
'Order.promotionCode',
|
|
43
|
+
'Order.isPromoting',
|
|
44
|
+
'Order.rmsOrderData',
|
|
45
|
+
'Order.promotionFlatDiscount',
|
|
46
|
+
'Order.promotionDelivery',
|
|
47
|
+
'Order.promotionCodeCheckValidTill',
|
|
48
|
+
'Dish.favorites',
|
|
49
|
+
'worktime',
|
|
50
|
+
'hash',
|
|
51
|
+
'isDeleted',
|
|
52
|
+
'createdAt',
|
|
53
|
+
'updatedAt'
|
|
54
|
+
]
|
|
55
|
+
} as unknown as RestoGraphQLConfig;
|
package/lib/eventHelper.d.ts
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
+
import { Message, Action } from "../types/primitives";
|
|
1
2
|
declare const _default: {
|
|
2
3
|
sendMessage: typeof sendMessage;
|
|
3
4
|
sendAction: typeof sendAction;
|
|
5
|
+
getRandom: typeof getRandom;
|
|
4
6
|
};
|
|
5
7
|
export default _default;
|
|
6
|
-
export { sendMessage, sendAction };
|
|
7
|
-
|
|
8
|
+
export { sendMessage, sendAction, getRandom };
|
|
9
|
+
interface MessageWithId extends Message {
|
|
10
|
+
id: string;
|
|
11
|
+
}
|
|
12
|
+
interface ActionWithId extends Action {
|
|
13
|
+
id: string;
|
|
14
|
+
}
|
|
15
|
+
declare function sendMessage(message: Message): Promise<MessageWithId>;
|
|
8
16
|
/**
|
|
9
17
|
*
|
|
10
18
|
* @param orderId
|
|
11
|
-
* @param action - obj {type
|
|
12
|
-
*
|
|
19
|
+
* @param action - obj {type, data: Json}
|
|
20
|
+
* @returns Action with ID
|
|
13
21
|
* @example
|
|
14
22
|
* {
|
|
15
23
|
* type: "PaymentRedirect",
|
|
@@ -18,4 +26,5 @@ declare function sendMessage(orderId: String, message: any): void;
|
|
|
18
26
|
* }
|
|
19
27
|
* }
|
|
20
28
|
*/
|
|
21
|
-
declare function sendAction(
|
|
29
|
+
declare function sendAction(action: Action): ActionWithId;
|
|
30
|
+
declare function getRandom(length?: number): string;
|
package/lib/eventHelper.js
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendAction = exports.sendMessage = void 0;
|
|
3
|
+
exports.getRandom = exports.sendAction = exports.sendMessage = void 0;
|
|
4
4
|
const graphql_1 = require("../src/graphql");
|
|
5
|
-
|
|
5
|
+
const crypto = require("crypto");
|
|
6
6
|
exports.default = {
|
|
7
7
|
sendMessage,
|
|
8
|
-
sendAction
|
|
8
|
+
sendAction,
|
|
9
|
+
getRandom
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
+
//TODO: Add ID for all message and add returun
|
|
12
|
+
//TODO rename to makeMessage
|
|
13
|
+
async function sendMessage(message) {
|
|
14
|
+
if (!message) {
|
|
15
|
+
sails.log.error(`API > sendMessage: Message is not defined`);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (!message.id) {
|
|
19
|
+
message.id = getRandom();
|
|
20
|
+
}
|
|
11
21
|
const pubsub = graphql_1.default.getPubsub();
|
|
12
|
-
pubsub.publish("message", {
|
|
22
|
+
pubsub.publish("message", { deviceId: message.deviceId, message });
|
|
23
|
+
return message;
|
|
13
24
|
}
|
|
14
25
|
exports.sendMessage = sendMessage;
|
|
15
26
|
/**
|
|
16
27
|
*
|
|
17
28
|
* @param orderId
|
|
18
|
-
* @param action - obj {type
|
|
19
|
-
*
|
|
29
|
+
* @param action - obj {type, data: Json}
|
|
30
|
+
* @returns Action with ID
|
|
20
31
|
* @example
|
|
21
32
|
* {
|
|
22
33
|
* type: "PaymentRedirect",
|
|
@@ -25,8 +36,16 @@ exports.sendMessage = sendMessage;
|
|
|
25
36
|
* }
|
|
26
37
|
* }
|
|
27
38
|
*/
|
|
28
|
-
function sendAction(
|
|
39
|
+
function sendAction(action) {
|
|
40
|
+
if (!action.id) {
|
|
41
|
+
action.id = getRandom();
|
|
42
|
+
}
|
|
29
43
|
const pubsub = graphql_1.default.getPubsub();
|
|
30
|
-
pubsub.publish("action", {
|
|
44
|
+
pubsub.publish("action", { deviceId: action.deviceId, action });
|
|
45
|
+
return action;
|
|
31
46
|
}
|
|
32
47
|
exports.sendAction = sendAction;
|
|
48
|
+
function getRandom(length = 16) {
|
|
49
|
+
return crypto.randomBytes(length).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
50
|
+
}
|
|
51
|
+
exports.getRandom = getRandom;
|
package/lib/eventHelper.ts
CHANGED
|
@@ -1,25 +1,48 @@
|
|
|
1
1
|
import graphql from '../src/graphql';
|
|
2
2
|
// import * as gql from '@webresto/graphql';
|
|
3
|
+
import { Message, Action } from "../types/primitives"
|
|
4
|
+
import * as crypto from "crypto"
|
|
3
5
|
|
|
4
6
|
export default {
|
|
5
7
|
sendMessage,
|
|
6
|
-
sendAction
|
|
8
|
+
sendAction,
|
|
9
|
+
getRandom
|
|
7
10
|
}
|
|
8
11
|
export {
|
|
9
12
|
sendMessage,
|
|
10
|
-
sendAction
|
|
13
|
+
sendAction,
|
|
14
|
+
getRandom
|
|
11
15
|
}
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
interface MessageWithId extends Message {
|
|
18
|
+
id: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface ActionWithId extends Action {
|
|
22
|
+
id: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//TODO: Add ID for all message and add returun
|
|
26
|
+
//TODO rename to makeMessage
|
|
27
|
+
async function sendMessage(message: Message): Promise<MessageWithId> {
|
|
28
|
+
if (!message){
|
|
29
|
+
sails.log.error(`API > sendMessage: Message is not defined`)
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
if(!message.id){
|
|
33
|
+
message.id = getRandom();
|
|
34
|
+
}
|
|
35
|
+
|
|
14
36
|
const pubsub = graphql.getPubsub();
|
|
15
|
-
pubsub.publish("message", {
|
|
37
|
+
pubsub.publish("message", {deviceId:message.deviceId, message});
|
|
38
|
+
return message as MessageWithId
|
|
16
39
|
}
|
|
17
40
|
|
|
18
41
|
/**
|
|
19
42
|
*
|
|
20
43
|
* @param orderId
|
|
21
|
-
* @param action - obj {type
|
|
22
|
-
*
|
|
44
|
+
* @param action - obj {type, data: Json}
|
|
45
|
+
* @returns Action with ID
|
|
23
46
|
* @example
|
|
24
47
|
* {
|
|
25
48
|
* type: "PaymentRedirect",
|
|
@@ -29,7 +52,17 @@ function sendMessage(orderId: String, message: any) {
|
|
|
29
52
|
* }
|
|
30
53
|
*/
|
|
31
54
|
|
|
32
|
-
function sendAction(
|
|
55
|
+
function sendAction(action: Action): ActionWithId {
|
|
56
|
+
if(!action.id){
|
|
57
|
+
action.id = getRandom();
|
|
58
|
+
}
|
|
59
|
+
|
|
33
60
|
const pubsub = graphql.getPubsub();
|
|
34
|
-
pubsub.publish("action", {
|
|
61
|
+
pubsub.publish("action", {deviceId: action.deviceId, action});
|
|
62
|
+
return action as ActionWithId
|
|
35
63
|
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
function getRandom(length:number = 16): string{
|
|
67
|
+
return crypto.randomBytes(length).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getRecomendElements(array: any, count: any): any[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRecomendElements = void 0;
|
|
4
|
+
function getRecomendElements(array, count) {
|
|
5
|
+
if (!Array.isArray(array) || array.length === 0 || count <= 0) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
if (array.length <= count) {
|
|
9
|
+
return array;
|
|
10
|
+
}
|
|
11
|
+
const maxPrice = Math.max(...array.map(item => item.price));
|
|
12
|
+
const minPrice = maxPrice * 0.2; // 20% of the maximum price
|
|
13
|
+
const maxPriceRange = maxPrice * 0.8; // 80% of the maximum price
|
|
14
|
+
let filteredArray = array.filter(item => item.price >= minPrice && item.price <= maxPriceRange);
|
|
15
|
+
if (filteredArray.length === 0) {
|
|
16
|
+
filteredArray = array;
|
|
17
|
+
}
|
|
18
|
+
const randomElements = [];
|
|
19
|
+
const indices = new Set();
|
|
20
|
+
while (randomElements.length < count && indices.size < filteredArray.length) {
|
|
21
|
+
const index = Math.floor(Math.random() * filteredArray.length);
|
|
22
|
+
if (!indices.has(index)) {
|
|
23
|
+
indices.add(index);
|
|
24
|
+
randomElements.push(filteredArray[index]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return randomElements.reverse();
|
|
28
|
+
}
|
|
29
|
+
exports.getRecomendElements = getRecomendElements;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function getRecomendElements(array, count) {
|
|
2
|
+
if (!Array.isArray(array) || array.length === 0 || count <= 0) {
|
|
3
|
+
return [];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
if (array.length <= count) {
|
|
7
|
+
return array;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const maxPrice = Math.max(...array.map(item => item.price));
|
|
11
|
+
const minPrice = maxPrice * 0.2; // 20% of the maximum price
|
|
12
|
+
const maxPriceRange = maxPrice * 0.8; // 80% of the maximum price
|
|
13
|
+
|
|
14
|
+
let filteredArray = array.filter(item => item.price >= minPrice && item.price <= maxPriceRange);
|
|
15
|
+
|
|
16
|
+
if (filteredArray.length === 0) {
|
|
17
|
+
filteredArray = array;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const randomElements = [];
|
|
21
|
+
const indices = new Set();
|
|
22
|
+
while (randomElements.length < count && indices.size < filteredArray.length) {
|
|
23
|
+
const index = Math.floor(Math.random() * filteredArray.length);
|
|
24
|
+
if (!indices.has(index)) {
|
|
25
|
+
indices.add(index);
|
|
26
|
+
randomElements.push(filteredArray[index]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return randomElements.reverse();
|
|
31
|
+
}
|
package/lib/graphqlHelper.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="@webresto/core/libs/globalTypes" />
|
|
2
1
|
/**
|
|
3
2
|
* Добавляет модель в список моделей для создания типов схемы graphql
|
|
4
3
|
*
|
|
@@ -7,13 +6,13 @@
|
|
|
7
6
|
* @returns void
|
|
8
7
|
*/
|
|
9
8
|
declare function addModel(modelName: string): void;
|
|
10
|
-
declare function addType(
|
|
9
|
+
declare function addType(type: string): void;
|
|
11
10
|
/**
|
|
12
11
|
* Мержит новый резолвер с объектом резолверов. Новый резолвер заменит старый при совпадении имен
|
|
13
12
|
*
|
|
14
13
|
* @param resolvers
|
|
15
14
|
* resolverExample = {
|
|
16
|
-
* def: "user(id:
|
|
15
|
+
* def: "user(id: string)",
|
|
17
16
|
* fn: function (parent, args, context) {
|
|
18
17
|
* return User.find({id: args.id})
|
|
19
18
|
* }
|
|
@@ -36,7 +35,7 @@ declare function addAllSailsModels(): void;
|
|
|
36
35
|
declare function addToBlackList(list: Array<string>): void;
|
|
37
36
|
/**
|
|
38
37
|
* Добавляет в указаную модель новое поле
|
|
39
|
-
* Пример: addCustomField("Order", "customField:
|
|
38
|
+
* Пример: addCustomField("Order", "customField: string")
|
|
40
39
|
*
|
|
41
40
|
* @param model string
|
|
42
41
|
* @param field string
|