@retailcrm/embed-ui-v1-contexts 0.4.4
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/README.md +16 -0
- package/dist/common/customer/card-phone.d.ts +6 -0
- package/dist/common/customer/card.d.ts +6 -0
- package/dist/common/order/card.d.ts +6 -0
- package/dist/common/settings.d.ts +7 -0
- package/dist/common/user/current.d.ts +6 -0
- package/dist/host.cjs +104 -0
- package/dist/host.d.ts +16 -0
- package/dist/host.js +104 -0
- package/dist/meta.json +442 -0
- package/dist/predicates.cjs.js +28 -0
- package/dist/predicates.d.ts +11 -0
- package/dist/predicates.es.js +29 -0
- package/dist/remote/customer/card-phone.cjs +20 -0
- package/dist/remote/customer/card-phone.d.ts +12 -0
- package/dist/remote/customer/card-phone.js +20 -0
- package/dist/remote/customer/card.cjs +30 -0
- package/dist/remote/customer/card.d.ts +12 -0
- package/dist/remote/customer/card.js +30 -0
- package/dist/remote/order/card.cjs +138 -0
- package/dist/remote/order/card.d.ts +12 -0
- package/dist/remote/order/card.js +138 -0
- package/dist/remote/settings.cjs +17 -0
- package/dist/remote/settings.d.ts +13 -0
- package/dist/remote/settings.js +17 -0
- package/dist/remote/user/current.cjs +50 -0
- package/dist/remote/user/current.d.ts +12 -0
- package/dist/remote/user/current.js +50 -0
- package/dist/remote.cjs +62 -0
- package/dist/remote.d.ts +22 -0
- package/dist/remote.js +62 -0
- package/dist/utilities.cjs.js +3 -0
- package/dist/utilities.d.ts +1 -0
- package/dist/utilities.es.js +4 -0
- package/package.json +106 -0
- package/types/customer/card-phone.d.ts +6 -0
- package/types/customer/card.d.ts +8 -0
- package/types/index.d.ts +13 -0
- package/types/order/card.d.ts +29 -0
- package/types/settings.d.ts +6 -0
- package/types/user/current.d.ts +12 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const remote = require("../../remote.cjs");
|
|
4
|
+
const predicates = require("../../predicates.cjs.js");
|
|
5
|
+
const id = "order/card";
|
|
6
|
+
const schema = {
|
|
7
|
+
"id": {
|
|
8
|
+
accepts: predicates.oneOf(predicates.isNumber, predicates.isNull),
|
|
9
|
+
defaults: () => null,
|
|
10
|
+
readonly: true
|
|
11
|
+
},
|
|
12
|
+
"externalId": {
|
|
13
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
14
|
+
defaults: () => null,
|
|
15
|
+
readonly: true
|
|
16
|
+
},
|
|
17
|
+
"type": {
|
|
18
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
19
|
+
defaults: () => null,
|
|
20
|
+
readonly: true
|
|
21
|
+
},
|
|
22
|
+
"site": {
|
|
23
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
24
|
+
defaults: () => null,
|
|
25
|
+
readonly: true
|
|
26
|
+
},
|
|
27
|
+
"number": {
|
|
28
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
29
|
+
defaults: () => null,
|
|
30
|
+
readonly: true
|
|
31
|
+
},
|
|
32
|
+
"customer.type": {
|
|
33
|
+
accepts: predicates.oneOf(
|
|
34
|
+
predicates.isExactly("customer"),
|
|
35
|
+
predicates.isExactly("customer_corporate")
|
|
36
|
+
),
|
|
37
|
+
defaults: () => "customer",
|
|
38
|
+
readonly: true
|
|
39
|
+
},
|
|
40
|
+
"customer.lastName": {
|
|
41
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
42
|
+
defaults: () => null,
|
|
43
|
+
readonly: false
|
|
44
|
+
},
|
|
45
|
+
"customer.firstName": {
|
|
46
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
47
|
+
defaults: () => null,
|
|
48
|
+
readonly: false
|
|
49
|
+
},
|
|
50
|
+
"customer.patronymic": {
|
|
51
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
52
|
+
defaults: () => null,
|
|
53
|
+
readonly: false
|
|
54
|
+
},
|
|
55
|
+
"customer.phone": {
|
|
56
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
57
|
+
defaults: () => null,
|
|
58
|
+
readonly: false
|
|
59
|
+
},
|
|
60
|
+
"customer.email": {
|
|
61
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
62
|
+
defaults: () => null,
|
|
63
|
+
readonly: false
|
|
64
|
+
},
|
|
65
|
+
"country": {
|
|
66
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
67
|
+
defaults: () => null,
|
|
68
|
+
readonly: true
|
|
69
|
+
},
|
|
70
|
+
"currency": {
|
|
71
|
+
accepts: predicates.isString,
|
|
72
|
+
defaults: () => "",
|
|
73
|
+
readonly: true
|
|
74
|
+
},
|
|
75
|
+
"status": {
|
|
76
|
+
accepts: predicates.isString,
|
|
77
|
+
defaults: () => "",
|
|
78
|
+
readonly: true
|
|
79
|
+
},
|
|
80
|
+
"company.name": {
|
|
81
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
82
|
+
defaults: () => null,
|
|
83
|
+
readonly: false
|
|
84
|
+
},
|
|
85
|
+
"company.legalName": {
|
|
86
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
87
|
+
defaults: () => null,
|
|
88
|
+
readonly: false
|
|
89
|
+
},
|
|
90
|
+
"company.legalAddress": {
|
|
91
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
92
|
+
defaults: () => null,
|
|
93
|
+
readonly: false
|
|
94
|
+
},
|
|
95
|
+
"company.INN": {
|
|
96
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
97
|
+
defaults: () => null,
|
|
98
|
+
readonly: false
|
|
99
|
+
},
|
|
100
|
+
"company.OKPO": {
|
|
101
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
102
|
+
defaults: () => null,
|
|
103
|
+
readonly: false
|
|
104
|
+
},
|
|
105
|
+
"company.BIK": {
|
|
106
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
107
|
+
defaults: () => null,
|
|
108
|
+
readonly: false
|
|
109
|
+
},
|
|
110
|
+
"company.bank": {
|
|
111
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
112
|
+
defaults: () => null,
|
|
113
|
+
readonly: false
|
|
114
|
+
},
|
|
115
|
+
"company.bankAddress": {
|
|
116
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
117
|
+
defaults: () => null,
|
|
118
|
+
readonly: false
|
|
119
|
+
},
|
|
120
|
+
"company.corrAccount": {
|
|
121
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
122
|
+
defaults: () => null,
|
|
123
|
+
readonly: false
|
|
124
|
+
},
|
|
125
|
+
"company.bankAccount": {
|
|
126
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
127
|
+
defaults: () => null,
|
|
128
|
+
readonly: false
|
|
129
|
+
},
|
|
130
|
+
"delivery.address": {
|
|
131
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
132
|
+
defaults: () => null,
|
|
133
|
+
readonly: false
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const useContext = remote.defineContext(id, schema);
|
|
137
|
+
exports.schema = schema;
|
|
138
|
+
exports.useContext = useContext;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { schema } from '../../common/order/card';
|
|
2
|
+
import { StoreDefinition } from 'pinia';
|
|
3
|
+
import { Context, TypeOf, RejectionHandler } from '@retailcrm/embed-ui-v1-types/context';
|
|
4
|
+
import { Schema } from '../../../types/order/card';
|
|
5
|
+
import { Maybe } from '@retailcrm/embed-ui-v1-types/scaffolding';
|
|
6
|
+
export { schema };
|
|
7
|
+
export declare const useContext: StoreDefinition<"order/card", Context<Schema>, {
|
|
8
|
+
schema: () => Schema;
|
|
9
|
+
}, {
|
|
10
|
+
initialize(): Promise<void>;
|
|
11
|
+
set<F extends "customer.lastName" | "customer.firstName" | "customer.patronymic" | "customer.email" | "customer.phone" | "company.name" | "company.legalName" | "company.legalAddress" | "company.INN" | "company.OKPO" | "company.BIK" | "company.bank" | "company.bankAddress" | "company.corrAccount" | "company.bankAccount" | "delivery.address">(field: F, value: TypeOf< Schema[F]>, onReject?: Maybe<RejectionHandler>): void;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { defineContext } from "../../remote.js";
|
|
2
|
+
import { o as oneOf, d as isExactly, i as isString, b as isNull, c as isNumber } from "../../predicates.es.js";
|
|
3
|
+
const id = "order/card";
|
|
4
|
+
const schema = {
|
|
5
|
+
"id": {
|
|
6
|
+
accepts: oneOf(isNumber, isNull),
|
|
7
|
+
defaults: () => null,
|
|
8
|
+
readonly: true
|
|
9
|
+
},
|
|
10
|
+
"externalId": {
|
|
11
|
+
accepts: oneOf(isString, isNull),
|
|
12
|
+
defaults: () => null,
|
|
13
|
+
readonly: true
|
|
14
|
+
},
|
|
15
|
+
"type": {
|
|
16
|
+
accepts: oneOf(isString, isNull),
|
|
17
|
+
defaults: () => null,
|
|
18
|
+
readonly: true
|
|
19
|
+
},
|
|
20
|
+
"site": {
|
|
21
|
+
accepts: oneOf(isString, isNull),
|
|
22
|
+
defaults: () => null,
|
|
23
|
+
readonly: true
|
|
24
|
+
},
|
|
25
|
+
"number": {
|
|
26
|
+
accepts: oneOf(isString, isNull),
|
|
27
|
+
defaults: () => null,
|
|
28
|
+
readonly: true
|
|
29
|
+
},
|
|
30
|
+
"customer.type": {
|
|
31
|
+
accepts: oneOf(
|
|
32
|
+
isExactly("customer"),
|
|
33
|
+
isExactly("customer_corporate")
|
|
34
|
+
),
|
|
35
|
+
defaults: () => "customer",
|
|
36
|
+
readonly: true
|
|
37
|
+
},
|
|
38
|
+
"customer.lastName": {
|
|
39
|
+
accepts: oneOf(isString, isNull),
|
|
40
|
+
defaults: () => null,
|
|
41
|
+
readonly: false
|
|
42
|
+
},
|
|
43
|
+
"customer.firstName": {
|
|
44
|
+
accepts: oneOf(isString, isNull),
|
|
45
|
+
defaults: () => null,
|
|
46
|
+
readonly: false
|
|
47
|
+
},
|
|
48
|
+
"customer.patronymic": {
|
|
49
|
+
accepts: oneOf(isString, isNull),
|
|
50
|
+
defaults: () => null,
|
|
51
|
+
readonly: false
|
|
52
|
+
},
|
|
53
|
+
"customer.phone": {
|
|
54
|
+
accepts: oneOf(isString, isNull),
|
|
55
|
+
defaults: () => null,
|
|
56
|
+
readonly: false
|
|
57
|
+
},
|
|
58
|
+
"customer.email": {
|
|
59
|
+
accepts: oneOf(isString, isNull),
|
|
60
|
+
defaults: () => null,
|
|
61
|
+
readonly: false
|
|
62
|
+
},
|
|
63
|
+
"country": {
|
|
64
|
+
accepts: oneOf(isString, isNull),
|
|
65
|
+
defaults: () => null,
|
|
66
|
+
readonly: true
|
|
67
|
+
},
|
|
68
|
+
"currency": {
|
|
69
|
+
accepts: isString,
|
|
70
|
+
defaults: () => "",
|
|
71
|
+
readonly: true
|
|
72
|
+
},
|
|
73
|
+
"status": {
|
|
74
|
+
accepts: isString,
|
|
75
|
+
defaults: () => "",
|
|
76
|
+
readonly: true
|
|
77
|
+
},
|
|
78
|
+
"company.name": {
|
|
79
|
+
accepts: oneOf(isString, isNull),
|
|
80
|
+
defaults: () => null,
|
|
81
|
+
readonly: false
|
|
82
|
+
},
|
|
83
|
+
"company.legalName": {
|
|
84
|
+
accepts: oneOf(isString, isNull),
|
|
85
|
+
defaults: () => null,
|
|
86
|
+
readonly: false
|
|
87
|
+
},
|
|
88
|
+
"company.legalAddress": {
|
|
89
|
+
accepts: oneOf(isString, isNull),
|
|
90
|
+
defaults: () => null,
|
|
91
|
+
readonly: false
|
|
92
|
+
},
|
|
93
|
+
"company.INN": {
|
|
94
|
+
accepts: oneOf(isString, isNull),
|
|
95
|
+
defaults: () => null,
|
|
96
|
+
readonly: false
|
|
97
|
+
},
|
|
98
|
+
"company.OKPO": {
|
|
99
|
+
accepts: oneOf(isString, isNull),
|
|
100
|
+
defaults: () => null,
|
|
101
|
+
readonly: false
|
|
102
|
+
},
|
|
103
|
+
"company.BIK": {
|
|
104
|
+
accepts: oneOf(isString, isNull),
|
|
105
|
+
defaults: () => null,
|
|
106
|
+
readonly: false
|
|
107
|
+
},
|
|
108
|
+
"company.bank": {
|
|
109
|
+
accepts: oneOf(isString, isNull),
|
|
110
|
+
defaults: () => null,
|
|
111
|
+
readonly: false
|
|
112
|
+
},
|
|
113
|
+
"company.bankAddress": {
|
|
114
|
+
accepts: oneOf(isString, isNull),
|
|
115
|
+
defaults: () => null,
|
|
116
|
+
readonly: false
|
|
117
|
+
},
|
|
118
|
+
"company.corrAccount": {
|
|
119
|
+
accepts: oneOf(isString, isNull),
|
|
120
|
+
defaults: () => null,
|
|
121
|
+
readonly: false
|
|
122
|
+
},
|
|
123
|
+
"company.bankAccount": {
|
|
124
|
+
accepts: oneOf(isString, isNull),
|
|
125
|
+
defaults: () => null,
|
|
126
|
+
readonly: false
|
|
127
|
+
},
|
|
128
|
+
"delivery.address": {
|
|
129
|
+
accepts: oneOf(isString, isNull),
|
|
130
|
+
defaults: () => null,
|
|
131
|
+
readonly: false
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const useContext = defineContext(id, schema);
|
|
135
|
+
export {
|
|
136
|
+
schema,
|
|
137
|
+
useContext
|
|
138
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const remote = require("../remote.cjs");
|
|
4
|
+
const predicates = require("../predicates.cjs.js");
|
|
5
|
+
const id = "settings";
|
|
6
|
+
const locales = ["en-GB", "es-ES", "ru-RU"];
|
|
7
|
+
const schema = {
|
|
8
|
+
"system.locale": {
|
|
9
|
+
accepts: predicates.oneOf(...locales.map(predicates.isExactly)),
|
|
10
|
+
defaults: () => "en-GB",
|
|
11
|
+
readonly: true
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const useContext = remote.defineContext(id, schema);
|
|
15
|
+
exports.locales = locales;
|
|
16
|
+
exports.schema = schema;
|
|
17
|
+
exports.useContext = useContext;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { locales, schema } from '../common/settings';
|
|
2
|
+
import { StoreDefinition } from 'pinia';
|
|
3
|
+
import { Context, TypeOf, RejectionHandler } from '@retailcrm/embed-ui-v1-types/context';
|
|
4
|
+
import { Schema } from '../../types/settings';
|
|
5
|
+
import { Maybe } from '@retailcrm/embed-ui-v1-types/scaffolding';
|
|
6
|
+
export { locales };
|
|
7
|
+
export { schema };
|
|
8
|
+
export declare const useContext: StoreDefinition<"settings", Context<Schema>, {
|
|
9
|
+
schema: () => Schema;
|
|
10
|
+
}, {
|
|
11
|
+
initialize(): Promise<void>;
|
|
12
|
+
set<F extends never>(field: F, value: TypeOf< Schema[F]>, onReject?: Maybe<RejectionHandler>): void;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineContext } from "../remote.js";
|
|
2
|
+
import { o as oneOf, d as isExactly } from "../predicates.es.js";
|
|
3
|
+
const id = "settings";
|
|
4
|
+
const locales = ["en-GB", "es-ES", "ru-RU"];
|
|
5
|
+
const schema = {
|
|
6
|
+
"system.locale": {
|
|
7
|
+
accepts: oneOf(...locales.map(isExactly)),
|
|
8
|
+
defaults: () => "en-GB",
|
|
9
|
+
readonly: true
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const useContext = defineContext(id, schema);
|
|
13
|
+
export {
|
|
14
|
+
locales,
|
|
15
|
+
schema,
|
|
16
|
+
useContext
|
|
17
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const remote = require("../../remote.cjs");
|
|
4
|
+
const predicates = require("../../predicates.cjs.js");
|
|
5
|
+
const id = "user/current";
|
|
6
|
+
const schema = {
|
|
7
|
+
"id": {
|
|
8
|
+
accepts: predicates.oneOf(predicates.isNumber, predicates.isNull),
|
|
9
|
+
defaults: () => null,
|
|
10
|
+
readonly: true
|
|
11
|
+
},
|
|
12
|
+
"email": {
|
|
13
|
+
accepts: predicates.isString,
|
|
14
|
+
defaults: () => "",
|
|
15
|
+
readonly: true
|
|
16
|
+
},
|
|
17
|
+
"firstName": {
|
|
18
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
19
|
+
defaults: () => null,
|
|
20
|
+
readonly: true
|
|
21
|
+
},
|
|
22
|
+
"lastName": {
|
|
23
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
24
|
+
defaults: () => null,
|
|
25
|
+
readonly: true
|
|
26
|
+
},
|
|
27
|
+
"patronymic": {
|
|
28
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
29
|
+
defaults: () => null,
|
|
30
|
+
readonly: true
|
|
31
|
+
},
|
|
32
|
+
"photo": {
|
|
33
|
+
accepts: predicates.oneOf(predicates.isString, predicates.isNull),
|
|
34
|
+
defaults: () => null,
|
|
35
|
+
readonly: true
|
|
36
|
+
},
|
|
37
|
+
"groups": {
|
|
38
|
+
accepts: predicates.arrayOf(predicates.isString),
|
|
39
|
+
defaults: () => [],
|
|
40
|
+
readonly: true
|
|
41
|
+
},
|
|
42
|
+
"permissions": {
|
|
43
|
+
accepts: predicates.arrayOf(predicates.isString),
|
|
44
|
+
defaults: () => [],
|
|
45
|
+
readonly: true
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const useContext = remote.defineContext(id, schema);
|
|
49
|
+
exports.schema = schema;
|
|
50
|
+
exports.useContext = useContext;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { schema } from '../../common/user/current';
|
|
2
|
+
import { StoreDefinition } from 'pinia';
|
|
3
|
+
import { Context, TypeOf, RejectionHandler } from '@retailcrm/embed-ui-v1-types/context';
|
|
4
|
+
import { Schema } from '../../../types/user/current';
|
|
5
|
+
import { Maybe } from '@retailcrm/embed-ui-v1-types/scaffolding';
|
|
6
|
+
export { schema };
|
|
7
|
+
export declare const useContext: StoreDefinition<"user/current", Context<Schema>, {
|
|
8
|
+
schema: () => Schema;
|
|
9
|
+
}, {
|
|
10
|
+
initialize(): Promise<void>;
|
|
11
|
+
set<F extends never>(field: F, value: TypeOf< Schema[F]>, onReject?: Maybe<RejectionHandler>): void;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { defineContext } from "../../remote.js";
|
|
2
|
+
import { o as oneOf, i as isString, a as arrayOf, b as isNull, c as isNumber } from "../../predicates.es.js";
|
|
3
|
+
const id = "user/current";
|
|
4
|
+
const schema = {
|
|
5
|
+
"id": {
|
|
6
|
+
accepts: oneOf(isNumber, isNull),
|
|
7
|
+
defaults: () => null,
|
|
8
|
+
readonly: true
|
|
9
|
+
},
|
|
10
|
+
"email": {
|
|
11
|
+
accepts: isString,
|
|
12
|
+
defaults: () => "",
|
|
13
|
+
readonly: true
|
|
14
|
+
},
|
|
15
|
+
"firstName": {
|
|
16
|
+
accepts: oneOf(isString, isNull),
|
|
17
|
+
defaults: () => null,
|
|
18
|
+
readonly: true
|
|
19
|
+
},
|
|
20
|
+
"lastName": {
|
|
21
|
+
accepts: oneOf(isString, isNull),
|
|
22
|
+
defaults: () => null,
|
|
23
|
+
readonly: true
|
|
24
|
+
},
|
|
25
|
+
"patronymic": {
|
|
26
|
+
accepts: oneOf(isString, isNull),
|
|
27
|
+
defaults: () => null,
|
|
28
|
+
readonly: true
|
|
29
|
+
},
|
|
30
|
+
"photo": {
|
|
31
|
+
accepts: oneOf(isString, isNull),
|
|
32
|
+
defaults: () => null,
|
|
33
|
+
readonly: true
|
|
34
|
+
},
|
|
35
|
+
"groups": {
|
|
36
|
+
accepts: arrayOf(isString),
|
|
37
|
+
defaults: () => [],
|
|
38
|
+
readonly: true
|
|
39
|
+
},
|
|
40
|
+
"permissions": {
|
|
41
|
+
accepts: arrayOf(isString),
|
|
42
|
+
defaults: () => [],
|
|
43
|
+
readonly: true
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const useContext = defineContext(id, schema);
|
|
47
|
+
export {
|
|
48
|
+
schema,
|
|
49
|
+
useContext
|
|
50
|
+
};
|
package/dist/remote.cjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const pinia = require("pinia");
|
|
4
|
+
const utilities = require("./utilities.cjs.js");
|
|
5
|
+
const injectEndpoint = (endpoint) => {
|
|
6
|
+
return (context) => {
|
|
7
|
+
context.store.endpoint = endpoint;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
const defineContext = (id, schema) => {
|
|
11
|
+
return pinia.defineStore(id, {
|
|
12
|
+
state() {
|
|
13
|
+
return {
|
|
14
|
+
...utilities.keysOf(schema).reduce((state, field) => ({
|
|
15
|
+
...state,
|
|
16
|
+
[field]: schema[field].defaults()
|
|
17
|
+
}), {})
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
getters: {
|
|
21
|
+
schema: () => schema
|
|
22
|
+
},
|
|
23
|
+
actions: {
|
|
24
|
+
async initialize() {
|
|
25
|
+
const context = this;
|
|
26
|
+
const endpoint = this.endpoint;
|
|
27
|
+
const state = await endpoint.call.get(id, "~", (rejection) => {
|
|
28
|
+
console.error(rejection);
|
|
29
|
+
});
|
|
30
|
+
if (!state) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
utilities.keysOf(schema).forEach((field) => {
|
|
34
|
+
context[field] = state[field];
|
|
35
|
+
endpoint.call.on(id, `change:${field}`, (value) => {
|
|
36
|
+
context[field] = value;
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
set(field, value, onReject = null) {
|
|
41
|
+
guard(id, schema, field, value);
|
|
42
|
+
const context = this;
|
|
43
|
+
const endpoint = this.endpoint;
|
|
44
|
+
context[field] = value;
|
|
45
|
+
endpoint.call.set(id, field, value, onReject);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
function guard(id, schema, field, value) {
|
|
51
|
+
if (!(field in schema)) {
|
|
52
|
+
throw new Error(`[crm:embed:remote] Field ${String(field)} is not present in context ${id}`);
|
|
53
|
+
}
|
|
54
|
+
if (schema[field].readonly) {
|
|
55
|
+
throw new Error(`[crm:embed:remote] Field ${String(field)} is readonly in context ${id}`);
|
|
56
|
+
}
|
|
57
|
+
if (!schema[field].accepts(value)) {
|
|
58
|
+
throw new Error(`[crm:embed:remote] Invalid value for field ${String(field)} in context ${id}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.defineContext = defineContext;
|
|
62
|
+
exports.injectEndpoint = injectEndpoint;
|
package/dist/remote.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Context, ContextAccessor, ContextSchema, ContextSchemaMap, RejectionHandler, TypeOf, Writable } from '@retailcrm/embed-ui-v1-types/context';
|
|
2
|
+
import { Endpoint } from '@remote-ui/rpc';
|
|
3
|
+
import { Maybe } from '@retailcrm/embed-ui-v1-types/scaffolding';
|
|
4
|
+
import { PiniaPluginContext, Store, StoreDefinition } from 'pinia';
|
|
5
|
+
export type ContextStore<S extends ContextSchema> = Store<string, Context<S>, {
|
|
6
|
+
schema(): S;
|
|
7
|
+
}, {
|
|
8
|
+
initialize(): Promise<void>;
|
|
9
|
+
set<F extends keyof Writable<S>>(field: F, value: TypeOf<S[F]>): void;
|
|
10
|
+
}>;
|
|
11
|
+
declare module 'pinia' {
|
|
12
|
+
interface PiniaCustomProperties {
|
|
13
|
+
endpoint: Endpoint<ContextAccessor>;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export declare const injectEndpoint: <M extends ContextSchemaMap, A extends ContextAccessor<M> = ContextAccessor<M>>(endpoint: Endpoint<A>) => (context: PiniaPluginContext) => void;
|
|
17
|
+
export declare const defineContext: <Id extends string, S extends ContextSchema>(id: Id, schema: S) => StoreDefinition<Id, Context<S>, {
|
|
18
|
+
schema: () => S;
|
|
19
|
+
}, {
|
|
20
|
+
initialize(): Promise<void>;
|
|
21
|
+
set<F extends keyof Writable<S>>(field: F, value: TypeOf<S[F]>, onReject?: Maybe<RejectionHandler>): void;
|
|
22
|
+
}>;
|
package/dist/remote.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { defineStore } from "pinia";
|
|
2
|
+
import { k as keysOf } from "./utilities.es.js";
|
|
3
|
+
const injectEndpoint = (endpoint) => {
|
|
4
|
+
return (context) => {
|
|
5
|
+
context.store.endpoint = endpoint;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
const defineContext = (id, schema) => {
|
|
9
|
+
return defineStore(id, {
|
|
10
|
+
state() {
|
|
11
|
+
return {
|
|
12
|
+
...keysOf(schema).reduce((state, field) => ({
|
|
13
|
+
...state,
|
|
14
|
+
[field]: schema[field].defaults()
|
|
15
|
+
}), {})
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
getters: {
|
|
19
|
+
schema: () => schema
|
|
20
|
+
},
|
|
21
|
+
actions: {
|
|
22
|
+
async initialize() {
|
|
23
|
+
const context = this;
|
|
24
|
+
const endpoint = this.endpoint;
|
|
25
|
+
const state = await endpoint.call.get(id, "~", (rejection) => {
|
|
26
|
+
console.error(rejection);
|
|
27
|
+
});
|
|
28
|
+
if (!state) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
keysOf(schema).forEach((field) => {
|
|
32
|
+
context[field] = state[field];
|
|
33
|
+
endpoint.call.on(id, `change:${field}`, (value) => {
|
|
34
|
+
context[field] = value;
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
set(field, value, onReject = null) {
|
|
39
|
+
guard(id, schema, field, value);
|
|
40
|
+
const context = this;
|
|
41
|
+
const endpoint = this.endpoint;
|
|
42
|
+
context[field] = value;
|
|
43
|
+
endpoint.call.set(id, field, value, onReject);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
function guard(id, schema, field, value) {
|
|
49
|
+
if (!(field in schema)) {
|
|
50
|
+
throw new Error(`[crm:embed:remote] Field ${String(field)} is not present in context ${id}`);
|
|
51
|
+
}
|
|
52
|
+
if (schema[field].readonly) {
|
|
53
|
+
throw new Error(`[crm:embed:remote] Field ${String(field)} is readonly in context ${id}`);
|
|
54
|
+
}
|
|
55
|
+
if (!schema[field].accepts(value)) {
|
|
56
|
+
throw new Error(`[crm:embed:remote] Invalid value for field ${String(field)} in context ${id}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
defineContext,
|
|
61
|
+
injectEndpoint
|
|
62
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const keysOf: <T extends object>(o: T) => (keyof T)[];
|