@webresto/graphql 1.3.6 → 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. package/.gitattributes +2 -0
  2. package/.gitlab-ci.yml +18 -0
  3. package/.vscode/extensions.json +5 -0
  4. package/docs/actions.md +25 -0
  5. package/docs/authorization.md +215 -0
  6. package/docs/captcha.md +71 -0
  7. package/docs/device-id.md +30 -0
  8. package/docs/messages.md +10 -0
  9. package/docs/user.md +54 -0
  10. package/index.d.ts +0 -1
  11. package/index.js +6 -2
  12. package/index.ts +2 -2
  13. package/lib/afterHook.js +8 -0
  14. package/lib/afterHook.ts +9 -0
  15. package/lib/bindTranslations.d.ts +1 -0
  16. package/lib/bindTranslations.js +40 -0
  17. package/lib/bindTranslations.ts +39 -0
  18. package/lib/defaults.d.ts +1 -0
  19. package/lib/defaults.js +49 -10
  20. package/lib/defaults.ts +55 -0
  21. package/lib/eventHelper.d.ts +14 -5
  22. package/lib/eventHelper.js +28 -9
  23. package/lib/eventHelper.ts +41 -8
  24. package/lib/getRecomended.d.ts +1 -0
  25. package/lib/getRecomended.js +29 -0
  26. package/lib/getRecomended.ts +31 -0
  27. package/lib/graphqlHelper.d.ts +3 -4
  28. package/lib/graphqlHelper.js +184 -73
  29. package/lib/graphqlHelper.ts +329 -186
  30. package/lib/jwt.d.ts +10 -0
  31. package/lib/jwt.js +43 -0
  32. package/lib/jwt.ts +61 -0
  33. package/package.json +13 -6
  34. package/src/additionalResolvers.d.ts +72 -9
  35. package/src/additionalResolvers.js +93 -24
  36. package/src/additionalResolvers.ts +105 -34
  37. package/src/graphql.d.ts +5 -3
  38. package/src/graphql.js +170 -37
  39. package/src/graphql.ts +210 -60
  40. package/src/resolvers/bonusProgram.d.ts +32 -0
  41. package/src/resolvers/bonusProgram.js +65 -0
  42. package/src/resolvers/bonusProgram.ts +79 -0
  43. package/src/resolvers/captcha.d.ts +11 -0
  44. package/src/resolvers/captcha.js +19 -0
  45. package/src/resolvers/captcha.ts +16 -0
  46. package/src/resolvers/checkout.d.ts +43 -14
  47. package/src/resolvers/checkout.js +172 -122
  48. package/src/resolvers/checkout.ts +218 -142
  49. package/src/resolvers/dishAndModifier.js +8 -4
  50. package/src/resolvers/dishAndModifier.ts +4 -0
  51. package/src/resolvers/error.d.ts +9 -0
  52. package/src/resolvers/error.js +21 -0
  53. package/src/resolvers/error.ts +21 -0
  54. package/src/resolvers/menu.d.ts +9 -0
  55. package/src/resolvers/menu.js +12 -0
  56. package/src/resolvers/menu.ts +10 -0
  57. package/src/resolvers/order.d.ts +527 -0
  58. package/src/resolvers/order.js +349 -0
  59. package/src/resolvers/order.ts +435 -0
  60. package/src/resolvers/paymentMethod.js +7 -3
  61. package/src/resolvers/paymentMethod.ts +9 -5
  62. package/src/resolvers/pickupPoint.d.ts +1 -0
  63. package/src/resolvers/pickupPoint.js +24 -0
  64. package/src/resolvers/pickupPoint.ts +23 -0
  65. package/src/resolvers/recomended.d.ts +13 -0
  66. package/src/resolvers/recomended.js +80 -0
  67. package/src/resolvers/recomended.ts +86 -0
  68. package/src/resolvers/restrictions.d.ts +37 -1
  69. package/src/resolvers/restrictions.js +100 -15
  70. package/src/resolvers/restrictions.ts +106 -14
  71. package/src/resolvers/streets.d.ts +1 -1
  72. package/src/resolvers/streets.js +1 -4
  73. package/src/resolvers/streets.ts +1 -3
  74. package/src/resolvers/subscriptions.d.ts +4 -4
  75. package/src/resolvers/subscriptions.js +49 -12
  76. package/src/resolvers/subscriptions.ts +59 -14
  77. package/src/resolvers/telemetry.d.ts +14 -0
  78. package/src/resolvers/telemetry.js +25 -0
  79. package/src/resolvers/telemetry.ts +24 -0
  80. package/src/resolvers/user.d.ts +82 -0
  81. package/src/resolvers/user.js +416 -0
  82. package/src/resolvers/user.ts +621 -0
  83. package/src/resolvers/userLocation.d.ts +53 -0
  84. package/src/resolvers/userLocation.js +74 -0
  85. package/src/resolvers/userLocation.ts +125 -0
  86. package/src/resolvers/userOTPrequest.d.ts +21 -0
  87. package/src/resolvers/userOTPrequest.js +57 -0
  88. package/src/resolvers/userOTPrequest.ts +75 -0
  89. package/test/e2e_helper.js +157 -0
  90. package/test/e2e_helper.ts +212 -0
  91. package/test/fixture/config/i18n.js +7 -20
  92. package/test/fixture/config/locales/de.json +1 -0
  93. package/test/fixture/config/locales/en.json +10 -0
  94. package/test/fixture/config/locales/es.json +3 -0
  95. package/test/fixture/config/locales/fr.json +1 -0
  96. package/test/fixture/config/log.js +1 -1
  97. package/test/fixture/package.json +5 -6
  98. package/test/fixture/patches/rttc+10.0.1.patch +17 -0
  99. package/test/integration/captcha.test.js +20 -0
  100. package/test/integration/captcha.test.ts +25 -0
  101. package/test/integration/dish.test.js +35 -0
  102. package/test/integration/dish.test.ts +43 -0
  103. package/test/integration/graphql.test.js +5 -2
  104. package/test/integration/graphql.test.ts +2 -4
  105. package/test/integration/images.test.js +35 -0
  106. package/test/integration/images.test.ts +40 -0
  107. package/test/integration/locale.test.js +26 -0
  108. package/test/integration/locale.test.ts +32 -0
  109. package/test/integration/order.test.js +56 -43
  110. package/test/integration/order.test.ts +59 -59
  111. package/test/integration/subscriptions.test.js +136 -0
  112. package/test/integration/subscriptions.test.ts +162 -0
  113. package/test/integration/user.test.js +249 -0
  114. package/test/integration/user.test.ts +299 -0
  115. package/test/unit/first.test.js +4 -2
  116. package/test/unit/first.test.ts +1 -1
  117. package/test/unit/get-recomended.test.js +56 -0
  118. package/test/unit/get-recomended.test.ts +63 -0
  119. package/translations/de.json +2 -0
  120. package/translations/en.json +3 -0
  121. package/translations/es.json +3 -0
  122. package/translations/fr.json +2 -0
  123. package/translations/ru.json +36 -0
  124. package/tsconfig.json +20 -5
  125. package/types/global.d.ts +30 -0
  126. package/types/global.js +2 -0
  127. package/types/global.ts +31 -0
  128. package/types/primitives.d.ts +19 -0
  129. package/types/references.d.ts +1 -0
  130. package/types/restoGraphQLConfig.d.ts +13 -0
  131. package/lib/afterHook.ts___graphql-transport-ws +0 -138
  132. package/lib/afterHook.ts___graphql-ws +0 -133
  133. package/lib/errorWrapper.d.ts +0 -4
  134. package/lib/errorWrapper.js +0 -13
  135. package/lib/errorWrapper.ts +0 -12
  136. package/notes.md +0 -1976
  137. package/src/resolvers/cart.d.ts +0 -343
  138. package/src/resolvers/cart.js +0 -196
  139. package/src/resolvers/cart.ts +0 -277
  140. package/test/fixture/config/connections.js +0 -9
  141. package/test/integration/sails_not_crash.test.js +0 -3
  142. package/test/integration/sails_not_crash.test.ts +0 -3
@@ -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;
@@ -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
- declare function sendMessage(orderId: String, message: any): void;
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: String, data: Json}
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(orderId: String, action: any): void;
29
+ declare function sendAction(action: Action): ActionWithId;
30
+ declare function getRandom(length?: number): string;
@@ -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
- // import * as gql from '@webresto/graphql';
5
+ const crypto = require("crypto");
6
6
  exports.default = {
7
7
  sendMessage,
8
- sendAction
8
+ sendAction,
9
+ getRandom
9
10
  };
10
- function sendMessage(orderId, message) {
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", { orderId, 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: String, data: Json}
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(orderId, action) {
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", { orderId, 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;
@@ -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
- function sendMessage(orderId: String, message: any) {
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", {orderId, 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: String, data: Json}
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(orderId: String, action: any) {
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", {orderId, 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
+ }
@@ -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(typeString: String): void;
9
+ declare function addType(type: string): void;
11
10
  /**
12
11
  * Мержит новый резолвер с объектом резолверов. Новый резолвер заменит старый при совпадении имен
13
12
  *
14
13
  * @param resolvers
15
14
  * resolverExample = {
16
- * def: "user(id: String)",
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: String")
38
+ * Пример: addCustomField("Order", "customField: string")
40
39
  *
41
40
  * @param model string
42
41
  * @param field string