Skip to content

Commit 7c3aae2

Browse files
committed
feat(v-contexts): ref #102071 Context for embed targets of the order form in chats
1 parent 691990b commit 7c3aae2

File tree

17 files changed

+1189
-224
lines changed

17 files changed

+1189
-224
lines changed

packages/v1-contexts/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@
7272
"remote/order/card-settings": [
7373
"./dist/remote/order/card-settings.d.ts"
7474
],
75+
"remote/order/mg": [
76+
"./dist/remote/order/mg.d.ts"
77+
],
78+
"remote/order/mg-settings": [
79+
"./dist/remote/order/mg-settings.d.ts"
80+
],
7581
"remote/user/current": [
7682
"./dist/remote/user/current.d.ts"
7783
],

packages/v1-contexts/scripts/build.meta.ts

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@ import { keysOf } from '@/utilities'
2020

2121
import * as customer from '@/common/customer/card'
2222
import * as customerPhone from '@/common/customer/card-phone'
23-
import * as order from '@/common/order/card'
24-
import * as orderSettings from '@/common/order/card-settings'
23+
import * as orderCard from '@/common/order/card'
24+
import * as orderCardSettings from '@/common/order/card-settings'
25+
import * as orderMg from '@/common/order/mg'
26+
import * as orderMgSettings from '@/common/order/mg-settings'
2527
import * as user from '@/common/user/current'
2628
import * as settings from '@/common/settings'
2729

2830
const schema: SchemaList = {
2931
[customer.id]: customer.schema,
3032
[customerPhone.id]: customerPhone.schema,
31-
[order.id]: order.schema,
32-
[orderSettings.id]: orderSettings.schema,
33+
[orderCard.id]: orderCard.schema,
34+
[orderCardSettings.id]: orderCardSettings.schema,
35+
[orderMg.id]: orderMg.schema,
36+
[orderMgSettings.id]: orderMgSettings.schema,
3337
[user.id]: user.schema,
3438
[settings.id]: settings.schema,
3539
}
@@ -39,8 +43,10 @@ const description: {
3943
} = {
4044
[customer.id]: customer.description,
4145
[customerPhone.id]: customerPhone.description,
42-
[order.id]: order.description,
43-
[orderSettings.id]: orderSettings.description,
46+
[orderCard.id]: orderCard.description,
47+
[orderCardSettings.id]: orderCardSettings.description,
48+
[orderMg.id]: orderMg.description,
49+
[orderMgSettings.id]: orderMgSettings.description,
4450
[user.id]: user.description,
4551
[settings.id]: settings.description,
4652
}
@@ -50,20 +56,24 @@ const usage: {
5056
} = {
5157
[customer.id]: customer.usage,
5258
[customerPhone.id]: customerPhone.usage,
53-
[order.id]: order.usage,
54-
[orderSettings.id]: orderSettings.usage,
59+
[orderCard.id]: orderCard.usage,
60+
[orderCardSettings.id]: orderCardSettings.usage,
61+
[orderMg.id]: orderMg.usage,
62+
[orderMgSettings.id]: orderMgSettings.usage,
5563
[user.id]: user.usage,
5664
[settings.id]: settings.usage,
5765
}
5866

5967
const actions: ActionSchemaList = {
60-
[order.id]: order.actions,
68+
[orderCard.id]: orderCard.actions,
69+
[orderMg.id]: orderMg.actions,
6170
}
6271

6372
const actionsDescription: {
6473
[K in keyof ActionSchemaList]: ObjectDescription<ActionSchemaList[K]>;
6574
} = {
66-
[order.id]: order.actionsDescription,
75+
[orderCard.id]: orderCard.actionsDescription,
76+
[orderMg.id]: orderMg.actionsDescription,
6777
}
6878

6979
const __dirname = dirname(fileURLToPath(import.meta.url))
@@ -153,21 +163,29 @@ const types: ObjectMeta[] = [{
153163
}]
154164

155165
fs.writeFileSync(join(dist, 'meta.json'), JSON.stringify({
156-
types: [...keysOf(order.typesDescription).reduce((meta, name) => {
157-
const types = order.types[name]
158-
const descriptions = order.typesDescription[name]
159-
160-
meta.push({
161-
name,
162-
fields: keysOf(descriptions).map(field => ({
163-
name: field,
164-
type: types[field],
165-
description: descriptions[field],
166-
})),
167-
})
168-
169-
return meta
170-
}, [] as Array<{ name: string; fields: ObjectFieldMeta[]; }>), ...types],
166+
types: [
167+
...keysOf({
168+
...orderCard.typesDescription,
169+
...orderMg.typesDescription,
170+
}).reduce((meta, name) => {
171+
const types = { ...orderCard.types, ...orderMg.types }[name] as Record<string, string>
172+
const descriptions = {
173+
...orderCard.typesDescription,
174+
...orderMg.typesDescription,
175+
}[name]
176+
177+
meta.push({
178+
name: name,
179+
fields: keysOf(descriptions).map(field => ({
180+
name: field as string,
181+
type: types[field as string],
182+
description: descriptions[field],
183+
})),
184+
})
185+
186+
return meta
187+
}, [] as Array<{ name: string; fields: ObjectFieldMeta[]; }>), ...types,
188+
],
171189
actions: keysOf(actions).reduce((meta, scope) => {
172190
meta[scope] = keysOf(actions[scope]).map(name => ({
173191
name,

packages/v1-contexts/scripts/generate.known-types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ type SchemaName = string
2424
const schemas: Record<SchemaName, Path[]> = {
2525
'order/card': [
2626
path.resolve(__root, 'types/order/card.d.ts'),
27+
path.resolve(__root, 'types/order/common.d.ts'),
28+
],
29+
'order/mg': [
30+
path.resolve(__root, 'types/order/mg.d.ts'),
31+
path.resolve(__root, 'types/order/common.d.ts'),
2732
],
2833
}
2934

packages/v1-contexts/src/common/order/card.ts

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
ContextSchemaUsage,
77
} from '@retailcrm/embed-ui-v1-types/context-doc'
88

9-
import type { KnownTypes } from '~generated/order/card'
9+
import type { KnownTypes } from '~generated/order/card.d.ts'
1010
import type { MethodList } from '~types/order/card'
1111
import type { Schema } from '~types/order/card'
1212

@@ -15,22 +15,26 @@ import {
1515
cortegeOf,
1616
isExactly,
1717
isNull,
18-
isNumber, isShape,
18+
isNumber,
19+
isShape,
1920
isString,
2021
isVoid,
2122
oneOf,
2223
} from '@/predicates'
2324

2425
import {
25-
isCreateOrderItemInput,
26-
isDiscount,
27-
isItem,
2826
isOffer,
2927
isPriceType,
3028
isProduct,
3129
isProductGroup,
3230
isProperty,
3331
isStatus,
32+
} from '@/predicates/order/common'
33+
34+
import {
35+
isCreateOrderItemInput,
36+
isDiscount,
37+
isItem,
3438
} from '@/predicates/order/card'
3539

3640
export const id = 'order/card'
@@ -613,6 +617,58 @@ export const typesDescription: {
613617
'ru-RU': 'Размер скидки',
614618
},
615619
},
620+
'Offer': {
621+
'id': {
622+
'en-GB': 'ID',
623+
'es-ES': 'ID',
624+
'ru-RU': 'Идентификатор',
625+
},
626+
'name': {
627+
'en-GB': 'Name',
628+
'es-ES': 'Nombre',
629+
'ru-RU': 'Наименование',
630+
},
631+
'image': {
632+
'en-GB': 'Image URL',
633+
'es-ES': 'URL de la imagen',
634+
'ru-RU': 'URL изображения',
635+
},
636+
'dimensions': {
637+
'en-GB': 'Product dimensions L - length, W - width, H - height',
638+
'es-ES': 'Dimensiones del producto L - longitud, W - ancho, H - altura',
639+
'ru-RU': 'Размеры товара L - длина, W - ширина, H - высота',
640+
},
641+
'weight': {
642+
'en-GB': 'Weight',
643+
'es-ES': 'Peso',
644+
'ru-RU': 'Вес',
645+
},
646+
'article': {
647+
'en-GB': 'Article',
648+
'es-ES': 'Artículo',
649+
'ru-RU': 'Артикул',
650+
},
651+
'barcode': {
652+
'en-GB': 'Barcode',
653+
'es-ES': 'Código de barras',
654+
'ru-RU': 'Штрих-код',
655+
},
656+
'properties': {
657+
'en-GB': 'Array of custom properties',
658+
'es-ES': 'Matriz de propiedades personalizadas',
659+
'ru-RU': 'Массив пользовательских свойств',
660+
},
661+
'unit': {
662+
'en-GB': 'Unit of quantity measurement, if not specified (null), will be set to "pcs."',
663+
'es-ES': 'Unidad de medida de cantidad, si no se especifica (null), se establecerá en "pcs."',
664+
'ru-RU': 'Единица измерения количества, если не указана (null), будет указано "шт."',
665+
},
666+
'purchasePrice': {
667+
'en-GB': 'Purchase price, value + currency',
668+
'es-ES': 'Precio de compra, valor + moneda',
669+
'ru-RU': 'Закупочная цена, значение + валюта',
670+
},
671+
},
616672
'PriceType': {
617673
'id': {
618674
'en-GB': 'ID',
@@ -726,58 +782,6 @@ export const typesDescription: {
726782
'ru-RU': 'Наименование',
727783
},
728784
},
729-
'Offer': {
730-
'id': {
731-
'en-GB': 'ID',
732-
'es-ES': 'ID',
733-
'ru-RU': 'Идентификатор',
734-
},
735-
'name': {
736-
'en-GB': 'Name',
737-
'es-ES': 'Nombre',
738-
'ru-RU': 'Наименование',
739-
},
740-
'image': {
741-
'en-GB': 'Image URL',
742-
'es-ES': 'URL de la imagen',
743-
'ru-RU': 'URL изображения',
744-
},
745-
'dimensions': {
746-
'en-GB': 'Product dimensions L - length, W - width, H - height',
747-
'es-ES': 'Dimensiones del producto L - longitud, W - ancho, H - altura',
748-
'ru-RU': 'Размеры товара L - длина, W - ширина, H - высота',
749-
},
750-
'weight': {
751-
'en-GB': 'Weight',
752-
'es-ES': 'Peso',
753-
'ru-RU': 'Вес',
754-
},
755-
'article': {
756-
'en-GB': 'Article',
757-
'es-ES': 'Artículo',
758-
'ru-RU': 'Артикул',
759-
},
760-
'barcode': {
761-
'en-GB': 'Barcode',
762-
'es-ES': 'Código de barras',
763-
'ru-RU': 'Штрих-код',
764-
},
765-
'properties': {
766-
'en-GB': 'Array of custom properties',
767-
'es-ES': 'Matriz de propiedades personalizadas',
768-
'ru-RU': 'Массив пользовательских свойств',
769-
},
770-
'unit': {
771-
'en-GB': 'Unit of quantity measurement, if not specified (null), will be set to "pcs."',
772-
'es-ES': 'Unidad de medida de cantidad, si no se especifica (null), se establecerá en "pcs."',
773-
'ru-RU': 'Единица измерения количества, если не указана (null), будет указано "шт."',
774-
},
775-
'purchasePrice': {
776-
'en-GB': 'Purchase price, value + currency',
777-
'es-ES': 'Precio de compra, valor + moneda',
778-
'ru-RU': 'Закупочная цена, значение + валюта',
779-
},
780-
},
781785
'OrderItem': {
782786
'id': {
783787
'en-GB': 'ID',
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import type { ContextSchemaDescription } from '@retailcrm/embed-ui-v1-types/context-doc'
2+
import type { ContextSchemaUsage } from '@retailcrm/embed-ui-v1-types/context-doc'
3+
import type { Schema } from '~types/order/mg-settings'
4+
5+
import {
6+
arrayOf,
7+
isBoolean,
8+
isNull,
9+
isString,
10+
oneOf,
11+
} from '@/predicates'
12+
13+
import { isStatus } from '@/predicates/order/common'
14+
15+
export const id = 'order/mg:settings'
16+
17+
export const schema: Schema = {
18+
'defaultUnit': {
19+
accepts: oneOf(isString, isNull),
20+
defaults: () => null,
21+
readonly: true,
22+
},
23+
'duplicatesAllowed': {
24+
accepts: isBoolean,
25+
defaults: () => false,
26+
readonly: true,
27+
},
28+
'quantityIsFractional': {
29+
accepts: isBoolean,
30+
defaults: () => false,
31+
readonly: true,
32+
},
33+
'priceEditable': {
34+
accepts: isBoolean,
35+
defaults: () => false,
36+
readonly: true,
37+
},
38+
'availableStatuses': {
39+
accepts: arrayOf(isStatus),
40+
defaults: () => [],
41+
readonly: true,
42+
},
43+
}
44+
45+
export const description: ContextSchemaDescription<Schema> = {
46+
'defaultUnit': {
47+
description: {
48+
'en-GB': 'Default quantity unit of measurement',
49+
'es-ES': 'Unidad de medida de cantidad predeterminada',
50+
'ru-RU': 'Единица измерения количества по-умолчанию',
51+
},
52+
},
53+
'duplicatesAllowed': {
54+
description: {
55+
'en-GB': 'Possibility of adding the same SKUs to the order as different items',
56+
'es-ES': 'La posibilidad de añadir las mismas variantes como diferentes productos al pedido',
57+
'ru-RU': 'Возможность добавлять в заказ одинаковые торговые предложения как разные позиции',
58+
},
59+
},
60+
'quantityIsFractional': {
61+
description: {
62+
'en-GB': 'Integer or fractional quantity of items',
63+
'es-ES': 'Cantidad entera o fraccionada de productos',
64+
'ru-RU': 'Целое или дробное количество товара',
65+
},
66+
},
67+
'priceEditable': {
68+
description: {
69+
'en-GB': 'Ability to edit item prices',
70+
'es-ES': 'Capacidad de editar precios de artículos',
71+
'ru-RU': 'Возможность редактировать цену товарных позиций',
72+
},
73+
},
74+
'availableStatuses': {
75+
description: {
76+
'en-GB': 'List of available order item statuses',
77+
'es-ES': 'Lista de estados disponibles de los artículos del pedido',
78+
'ru-RU': 'Доступные статусы товарных позиций заказа',
79+
},
80+
},
81+
}
82+
83+
export const usage: ContextSchemaUsage = {
84+
import: 'import { useContext } from \'@retailcrm/embed-ui-v1-contexts/remote/order/mg-settings\'',
85+
call: 'const orderSettings = useContext()',
86+
}

0 commit comments

Comments
 (0)