@retailcrm/embed-ui-v1-contexts 0.5.11 → 0.5.12

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.
@@ -2,6 +2,15 @@ import { ContextSchemaDescription, ContextSchemaUsage } from '@retailcrm/embed-u
2
2
  import { Locale, Schema } from '../../types/settings';
3
3
  export declare const id = "settings";
4
4
  export declare const locales: Locale[];
5
+ export declare const routingDataDefaults: {
6
+ base_url: string;
7
+ routes: {};
8
+ prefix: string;
9
+ host: string;
10
+ port: string;
11
+ scheme: string;
12
+ locale: string;
13
+ };
5
14
  export declare const schema: Schema;
6
15
  export declare const description: ContextSchemaDescription<Schema>;
7
16
  export declare const usage: ContextSchemaUsage;
package/dist/meta.json CHANGED
@@ -474,6 +474,26 @@
474
474
  "ru-RU": "Символьные коды доступных пользователю разрешений"
475
475
  },
476
476
  "readonly": true
477
+ },
478
+ {
479
+ "name": "isAdmin",
480
+ "type": "boolean",
481
+ "description": {
482
+ "en-GB": "Indicates whether the user has administrator privileges",
483
+ "es-ES": "Indica si el usuario tiene privilegios de administrador",
484
+ "ru-RU": "Указывает, имеет ли пользователь права администратора"
485
+ },
486
+ "readonly": true
487
+ },
488
+ {
489
+ "name": "isManager",
490
+ "type": "boolean",
491
+ "description": {
492
+ "en-GB": "Indicates whether the user has manager privileges",
493
+ "es-ES": "Indica si el usuario tiene privilegios de gerente",
494
+ "ru-RU": "Указывает, имеет ли пользователь права менеджера"
495
+ },
496
+ "readonly": true
477
497
  }
478
498
  ],
479
499
  "usage": {
@@ -502,6 +522,16 @@
502
522
  "ru-RU": "Текущая локаль системы"
503
523
  },
504
524
  "readonly": true
525
+ },
526
+ {
527
+ "name": "system.routing",
528
+ "type": "RoutingData",
529
+ "description": {
530
+ "en-GB": "Data for Symfony's JS router",
531
+ "es-ES": "Datos para el enrutador JS de Symfony",
532
+ "ru-RU": "Данные для js-маршрутизатора symfony"
533
+ },
534
+ "readonly": true
505
535
  }
506
536
  ],
507
537
  "usage": {
@@ -2,15 +2,18 @@
2
2
  const withMeta = (predicate, type) => {
3
3
  return Object.assign(predicate, { type });
4
4
  };
5
+ const isArray = withMeta((value) => Array.isArray(value), "unknown[]");
6
+ const isBoolean = withMeta((value) => typeof value === "boolean", "boolean");
5
7
  const isExactly = (expected) => {
6
8
  return withMeta((value) => value === expected, JSON.stringify(expected));
7
9
  };
8
10
  const isNull = withMeta((value) => value === null, "null");
9
11
  const isNumber = withMeta((value) => typeof value === "number", "number");
12
+ const isObject = withMeta((value) => typeof value === "object" && value !== null, "object");
10
13
  const isString = withMeta((value) => typeof value === "string", "string");
11
14
  const arrayOf = (predicate) => withMeta(
12
15
  (value) => {
13
- return Array.isArray(value) && value.every(predicate);
16
+ return isArray(value) && value.every(predicate);
14
17
  },
15
18
  `Array<${predicate.type}>`
16
19
  );
@@ -21,8 +24,12 @@ const oneOf = (...predicates) => withMeta(
21
24
  predicates.map((p) => p.type).join(" | ")
22
25
  );
23
26
  exports.arrayOf = arrayOf;
27
+ exports.isArray = isArray;
28
+ exports.isBoolean = isBoolean;
24
29
  exports.isExactly = isExactly;
25
30
  exports.isNull = isNull;
26
31
  exports.isNumber = isNumber;
32
+ exports.isObject = isObject;
27
33
  exports.isString = isString;
28
34
  exports.oneOf = oneOf;
35
+ exports.withMeta = withMeta;
@@ -3,9 +3,12 @@ export type PredicateWithMeta<T = unknown> = Predicate<T> & {
3
3
  type: string;
4
4
  };
5
5
  export declare const withMeta: <T>(predicate: Predicate<T>, type: string) => PredicateWithMeta<T>;
6
+ export declare const isArray: PredicateWithMeta<unknown[]>;
7
+ export declare const isBoolean: PredicateWithMeta<boolean>;
6
8
  export declare const isExactly: <T extends string | number>(expected: T) => PredicateWithMeta<T>;
7
9
  export declare const isNull: PredicateWithMeta<null>;
8
10
  export declare const isNumber: PredicateWithMeta<number>;
11
+ export declare const isObject: PredicateWithMeta<object>;
9
12
  export declare const isString: PredicateWithMeta<string>;
10
13
  export declare const arrayOf: <T>(predicate: PredicateWithMeta<T>) => PredicateWithMeta<T[]>;
11
- export declare const oneOf: (...predicates: PredicateWithMeta[]) => PredicateWithMeta<unknown>;
14
+ export declare const oneOf: <T extends unknown[]>(...predicates: { [K in keyof T]: PredicateWithMeta<T[K]>; }) => PredicateWithMeta<T[number]>;
@@ -1,15 +1,18 @@
1
1
  const withMeta = (predicate, type) => {
2
2
  return Object.assign(predicate, { type });
3
3
  };
4
+ const isArray = withMeta((value) => Array.isArray(value), "unknown[]");
5
+ const isBoolean = withMeta((value) => typeof value === "boolean", "boolean");
4
6
  const isExactly = (expected) => {
5
7
  return withMeta((value) => value === expected, JSON.stringify(expected));
6
8
  };
7
9
  const isNull = withMeta((value) => value === null, "null");
8
10
  const isNumber = withMeta((value) => typeof value === "number", "number");
11
+ const isObject = withMeta((value) => typeof value === "object" && value !== null, "object");
9
12
  const isString = withMeta((value) => typeof value === "string", "string");
10
13
  const arrayOf = (predicate) => withMeta(
11
14
  (value) => {
12
- return Array.isArray(value) && value.every(predicate);
15
+ return isArray(value) && value.every(predicate);
13
16
  },
14
17
  `Array<${predicate.type}>`
15
18
  );
@@ -24,6 +27,10 @@ export {
24
27
  isNull as b,
25
28
  isNumber as c,
26
29
  isExactly as d,
30
+ isBoolean as e,
31
+ isObject as f,
32
+ isArray as g,
27
33
  isString as i,
28
- oneOf as o
34
+ oneOf as o,
35
+ withMeta as w
29
36
  };
@@ -2,8 +2,43 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const remote = require("../remote.cjs");
4
4
  const predicates = require("../predicates.cjs.js");
5
+ const utilities = require("../utilities.cjs.js");
5
6
  const id = "settings";
6
7
  const locales = ["en-GB", "es-ES", "ru-RU"];
8
+ const routeSchema = {
9
+ tokens: predicates.arrayOf(predicates.arrayOf(predicates.oneOf(predicates.isString, predicates.isBoolean))),
10
+ defaults: predicates.oneOf(predicates.isArray, predicates.isObject),
11
+ requirements: predicates.oneOf(predicates.isArray, predicates.isObject),
12
+ hosttokens: predicates.arrayOf(predicates.arrayOf(predicates.isString)),
13
+ schemes: predicates.arrayOf(predicates.isString),
14
+ methods: predicates.arrayOf(predicates.isString)
15
+ };
16
+ const isRoute = (value) => {
17
+ return typeof value === "object" && value !== null && utilities.keysOf(routeSchema).every((key) => {
18
+ return key in value && routeSchema[key](value[key]);
19
+ });
20
+ };
21
+ const isRoutesMap = (value) => {
22
+ return predicates.isObject(value) && utilities.keysOf(value).every((key) => isRoute(value[key]));
23
+ };
24
+ const routingDataSchema = {
25
+ base_url: [true, predicates.isString],
26
+ routes: [true, isRoutesMap],
27
+ prefix: [false, predicates.isString],
28
+ host: [true, predicates.isString],
29
+ port: [false, predicates.isString],
30
+ scheme: [false, predicates.isString],
31
+ locale: [false, predicates.isString]
32
+ };
33
+ const routingDataDefaults = {
34
+ base_url: "",
35
+ routes: {},
36
+ prefix: "",
37
+ host: "",
38
+ port: "",
39
+ scheme: "http",
40
+ locale: ""
41
+ };
7
42
  const schema = {
8
43
  "image.workers": {
9
44
  accepts: predicates.arrayOf(predicates.isString),
@@ -14,6 +49,19 @@ const schema = {
14
49
  accepts: predicates.oneOf(...locales.map(predicates.isExactly)),
15
50
  defaults: () => "en-GB",
16
51
  readonly: true
52
+ },
53
+ "system.routing": {
54
+ accepts: predicates.withMeta((value) => {
55
+ return predicates.isObject(value) && utilities.keysOf(routingDataSchema).every((key) => {
56
+ const [required, predicate] = routingDataSchema[key];
57
+ if (!(key in value)) {
58
+ return !required;
59
+ }
60
+ return predicate(value[key]);
61
+ });
62
+ }, "RoutingData"),
63
+ defaults: () => ({ ...routingDataDefaults, routes: {} }),
64
+ readonly: true
17
65
  }
18
66
  };
19
67
  const useContext = remote.defineContext(id, schema);
@@ -1,7 +1,42 @@
1
1
  import { defineContext } from "../remote.js";
2
- import { a as arrayOf, o as oneOf, d as isExactly, i as isString } from "../predicates.es.js";
2
+ import { a as arrayOf, o as oneOf, i as isString, d as isExactly, w as withMeta, e as isBoolean, f as isObject, g as isArray } from "../predicates.es.js";
3
+ import { k as keysOf } from "../utilities.es.js";
3
4
  const id = "settings";
4
5
  const locales = ["en-GB", "es-ES", "ru-RU"];
6
+ const routeSchema = {
7
+ tokens: arrayOf(arrayOf(oneOf(isString, isBoolean))),
8
+ defaults: oneOf(isArray, isObject),
9
+ requirements: oneOf(isArray, isObject),
10
+ hosttokens: arrayOf(arrayOf(isString)),
11
+ schemes: arrayOf(isString),
12
+ methods: arrayOf(isString)
13
+ };
14
+ const isRoute = (value) => {
15
+ return typeof value === "object" && value !== null && keysOf(routeSchema).every((key) => {
16
+ return key in value && routeSchema[key](value[key]);
17
+ });
18
+ };
19
+ const isRoutesMap = (value) => {
20
+ return isObject(value) && keysOf(value).every((key) => isRoute(value[key]));
21
+ };
22
+ const routingDataSchema = {
23
+ base_url: [true, isString],
24
+ routes: [true, isRoutesMap],
25
+ prefix: [false, isString],
26
+ host: [true, isString],
27
+ port: [false, isString],
28
+ scheme: [false, isString],
29
+ locale: [false, isString]
30
+ };
31
+ const routingDataDefaults = {
32
+ base_url: "",
33
+ routes: {},
34
+ prefix: "",
35
+ host: "",
36
+ port: "",
37
+ scheme: "http",
38
+ locale: ""
39
+ };
5
40
  const schema = {
6
41
  "image.workers": {
7
42
  accepts: arrayOf(isString),
@@ -12,6 +47,19 @@ const schema = {
12
47
  accepts: oneOf(...locales.map(isExactly)),
13
48
  defaults: () => "en-GB",
14
49
  readonly: true
50
+ },
51
+ "system.routing": {
52
+ accepts: withMeta((value) => {
53
+ return isObject(value) && keysOf(routingDataSchema).every((key) => {
54
+ const [required, predicate] = routingDataSchema[key];
55
+ if (!(key in value)) {
56
+ return !required;
57
+ }
58
+ return predicate(value[key]);
59
+ });
60
+ }, "RoutingData"),
61
+ defaults: () => ({ ...routingDataDefaults, routes: {} }),
62
+ readonly: true
15
63
  }
16
64
  };
17
65
  const useContext = defineContext(id, schema);
@@ -43,6 +43,16 @@ const schema = {
43
43
  accepts: predicates.arrayOf(predicates.isString),
44
44
  defaults: () => [],
45
45
  readonly: true
46
+ },
47
+ "isAdmin": {
48
+ accepts: predicates.isBoolean,
49
+ defaults: () => false,
50
+ readonly: true
51
+ },
52
+ "isManager": {
53
+ accepts: predicates.isBoolean,
54
+ defaults: () => false,
55
+ readonly: true
46
56
  }
47
57
  };
48
58
  const useContext = remote.defineContext(id, schema);
@@ -1,5 +1,5 @@
1
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";
2
+ import { o as oneOf, i as isString, a as arrayOf, e as isBoolean, b as isNull, c as isNumber } from "../../predicates.es.js";
3
3
  const id = "user/current";
4
4
  const schema = {
5
5
  "id": {
@@ -41,6 +41,16 @@ const schema = {
41
41
  accepts: arrayOf(isString),
42
42
  defaults: () => [],
43
43
  readonly: true
44
+ },
45
+ "isAdmin": {
46
+ accepts: isBoolean,
47
+ defaults: () => false,
48
+ readonly: true
49
+ },
50
+ "isManager": {
51
+ accepts: isBoolean,
52
+ defaults: () => false,
53
+ readonly: true
44
54
  }
45
55
  };
46
56
  const useContext = defineContext(id, schema);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@retailcrm/embed-ui-v1-contexts",
3
3
  "description": "Reactive contexts for RetailCRM JS API",
4
4
  "type": "module",
5
- "version": "0.5.11",
5
+ "version": "0.5.12",
6
6
  "license": "MIT",
7
7
  "author": "RetailDriverLLC <integration@retailcrm.ru>",
8
8
  "repository": "git@github.com:retailcrm/embed-ui.git",
@@ -102,10 +102,11 @@
102
102
  "pinia": "^2.2"
103
103
  },
104
104
  "dependencies": {
105
- "@retailcrm/embed-ui-v1-types": "^0.5.11"
105
+ "@omnicajs/symfony-router": "^1.0.0",
106
+ "@retailcrm/embed-ui-v1-types": "^0.5.12"
106
107
  },
107
108
  "devDependencies": {
108
- "@retailcrm/embed-ui-v1-testing": "^0.5.11",
109
+ "@retailcrm/embed-ui-v1-testing": "^0.5.12",
109
110
  "tsx": "^4.19.2",
110
111
  "typescript": "^5.6.3",
111
112
  "vite": "^5.4.11",
@@ -1,7 +1,9 @@
1
1
  import type { ReadonlyField } from '@retailcrm/embed-ui-v1-types/context'
2
+ import type { RoutingData } from '@omnicajs/symfony-router'
2
3
 
3
4
  export type Locale = 'en-GB' | 'es-ES' | 'ru-RU'
4
5
  export type Schema = {
5
6
  'image.workers': ReadonlyField<string[]>;
6
7
  'system.locale': ReadonlyField<Locale>;
8
+ 'system.routing': ReadonlyField<RoutingData>;
7
9
  }
@@ -9,4 +9,6 @@ export type Schema = {
9
9
  'photo': ReadonlyField<string | null>;
10
10
  'groups': ReadonlyField<string[]>;
11
11
  'permissions': ReadonlyField<string[]>;
12
+ 'isAdmin': ReadonlyField<boolean>;
13
+ 'isManager': ReadonlyField<boolean>;
12
14
  }