@retailcrm/embed-ui-v1-types 0.5.2 → 0.5.3

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.
Files changed (2) hide show
  1. package/context.d.ts +98 -2
  2. package/package.json +1 -1
package/context.d.ts CHANGED
@@ -24,10 +24,12 @@ export type ContextSchema = {
24
24
  [key: string]: Field<unknown, boolean>;
25
25
  }
26
26
 
27
- export type ContextSchemaMap = {
27
+ export type ContextSchemaList = {
28
28
  [key: string]: ContextSchema;
29
29
  }
30
30
 
31
+ export type ContextSchemaMap = ContextSchemaList
32
+
31
33
  export type Context<S extends ContextSchema> = {
32
34
  [F in keyof S]: TypeOf<S[F]>;
33
35
  }
@@ -49,7 +51,7 @@ export type EventHandler<
49
51
  E extends keyof EventPayloadMap<S>
50
52
  > = (payload: EventPayloadMap<S>[E]) => void
51
53
 
52
- export type ContextAccessor<M extends ContextSchemaMap = ContextSchemaMap> = {
54
+ export type ContextAccessor<M extends ContextSchemaList = ContextSchemaList> = {
53
55
  get <
54
56
  C extends keyof M,
55
57
  F extends keyof M[C]
@@ -115,3 +117,97 @@ export interface LogicalRejection extends Rejection {
115
117
  export interface RuntimeRejection extends Rejection {
116
118
  type: 'runtime';
117
119
  }
120
+
121
+ export type CustomDictionary = CustomDictionaryItem[]
122
+ export type CustomDictionaryItem = {
123
+ code: string;
124
+ text: string;
125
+ cursor: string;
126
+ }
127
+
128
+ export type CustomDictionaryFilter = {
129
+ after?: string;
130
+ first?: number;
131
+ }
132
+
133
+ export interface BasicCustomField<K extends string, T> {
134
+ kind: K;
135
+ code: string;
136
+ readonly: boolean;
137
+ initial: T;
138
+ }
139
+
140
+ export interface DictionaryCustomField extends BasicCustomField<'dictionary', string | null> {
141
+ dictionaryCode: string;
142
+ }
143
+
144
+ export interface MultiselectDictionaryCustomField extends BasicCustomField<'multiselect_dictionary', string[]> {
145
+ dictionaryCode: string;
146
+ }
147
+
148
+ export type CustomField<K extends CustomFieldKind = CustomFieldKind> = CustomFieldList[K]
149
+
150
+ export type CustomFieldType = TypeOfCustom<CustomFieldKind>
151
+ export type CustomFieldKind = keyof CustomFieldList
152
+ export type CustomFieldList = {
153
+ 'boolean': BasicCustomField<'boolean', boolean | null>;
154
+ 'date': BasicCustomField<'date', string | null>;
155
+ 'datetime': BasicCustomField<'datetime', string | null>;
156
+ 'dictionary': DictionaryCustomField;
157
+ 'multiselect_dictionary': MultiselectDictionaryCustomField;
158
+ 'email': BasicCustomField<'email', string | null>;
159
+ 'integer': BasicCustomField<'integer', number | null>;
160
+ 'numeric': BasicCustomField<'numeric', number | null>;
161
+ 'string': BasicCustomField<'string', string | null>;
162
+ 'text': BasicCustomField<'text', string | null>;
163
+ }
164
+
165
+ export type TypeOfCustom<K extends string> = K extends CustomFieldKind
166
+ ? CustomFieldList[K] extends BasicCustomField<string, infer T> ? T : never
167
+ : unknown;
168
+
169
+ export type CustomContextSchema = {
170
+ entity: string;
171
+ fields: CustomField[];
172
+ }
173
+
174
+ export type CustomContext = {
175
+ [code: string]: CustomFieldType
176
+ }
177
+
178
+ export type CustomContextAccessor = {
179
+ getCustomSchema (entity: string, onReject?: Maybe<RejectionHandler>): CustomContextSchema | null;
180
+
181
+ getCustomDictionary (
182
+ code: string,
183
+ filter?: CustomDictionaryFilter,
184
+ onReject?: Maybe<RejectionHandler>
185
+ ): Promise<CustomDictionary>;
186
+
187
+ getCustomField (entity: string, code: string, onReject?: Maybe<RejectionHandler>): unknown;
188
+ setCustomField (
189
+ entity: string,
190
+ code: string,
191
+ value: CustomFieldType,
192
+ onReject?: Maybe<RejectionHandler>
193
+ ): void;
194
+
195
+ onCustomFieldChange (
196
+ entity: string,
197
+ code: string,
198
+ handler: (value: CustomFieldType) => void,
199
+ onReject?: Maybe<RejectionHandler>
200
+ ): void | (() => void);
201
+ }
202
+
203
+ export type CustomFieldAccessor = {
204
+ readonly schema: CustomContextSchema;
205
+
206
+ get (code: string): unknown;
207
+ set (code: string, value: CustomFieldType): void;
208
+
209
+ onChange (
210
+ code: string,
211
+ handler: (value: CustomFieldType) => void
212
+ ): void | (() => void);
213
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@retailcrm/embed-ui-v1-types",
3
3
  "description": "Basic types declarations for RetailCRM JS API",
4
4
  "type": "module",
5
- "version": "0.5.2",
5
+ "version": "0.5.3",
6
6
  "license": "MIT",
7
7
  "author": "RetailDriverLLC <integration@retailcrm.ru>",
8
8
  "repository": "git@github.com:retailcrm/embed-ui.git",