@ibiliaze/global-vars 1.111.0 → 1.113.0

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/dist/flows.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import { FixtureCategoryBase, FixtureCategoryFlowBase, FlowBase, OccupanceBase, StaffBase } from './ticketops/inputsDefault';
2
2
  export declare const flows: readonly ["Online", "Offline", "Special link", "Seasonal ticket"];
3
+ export declare const idsEqual: <Id>(a: Id | null | undefined, b: Id | null | undefined) => boolean;
4
+ export declare const arrayHasId: <Id>(list: readonly (Id | null | undefined)[] | null | undefined, target: Id | null | undefined) => boolean;
3
5
  export declare function makeSaleLogic<Id, TDate>(): SaleLogic<Id, TDate>;
4
6
  export type Path = '/' | '/link' | '/pos' | '/seasonal';
5
7
  export type Who = 'guest' | 'root' | 'cashier';
6
- export type SeatsByCat = {
8
+ export type SeatsByCat<Id> = {
7
9
  categoryName: string;
8
- categoryId: string;
10
+ categoryId: Id;
9
11
  available: number;
10
12
  price: number;
11
13
  color: string;
@@ -21,9 +23,9 @@ export interface CanISeeSectionArgs<Id, TDate> {
21
23
  who: Who;
22
24
  where: WhereOf<Id, TDate>;
23
25
  fixtureCategories: FixtureCategoryOf<Id>[];
24
- sectionId: string;
26
+ sectionId: Id;
25
27
  staffFlowIds: StaffFlowIdsOf<Id, TDate>;
26
- signedFlowId?: string | null;
28
+ signedFlowId?: Id | null;
27
29
  }
28
30
  export interface CanISeeSeatArgs<Id, TDate> {
29
31
  who: Who;
@@ -31,12 +33,12 @@ export interface CanISeeSeatArgs<Id, TDate> {
31
33
  staffFlowIds: StaffFlowIdsOf<Id, TDate>;
32
34
  occupanceCategory?: OccupanceCategoryOf<Id, TDate>;
33
35
  fixtureCategories: FixtureCategoryOf<Id>[];
34
- signedFlowId?: string | null;
36
+ signedFlowId?: Id | null;
35
37
  }
36
38
  export interface AuthoriserArgs<Id, TDate> {
37
39
  who: Who;
38
40
  where: WhereOf<Id, TDate>;
39
- signedFlowId?: string | null;
41
+ signedFlowId?: Id | null;
40
42
  effectiveFlows: EffectiveFlowsOf<Id>;
41
43
  staffFlowIds: StaffFlowIdsOf<Id, TDate>;
42
44
  }
package/dist/flows.js CHANGED
@@ -1,8 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.flows = void 0;
3
+ exports.arrayHasId = exports.idsEqual = exports.flows = void 0;
4
4
  exports.makeSaleLogic = makeSaleLogic;
5
5
  exports.flows = ['Online', 'Offline', 'Special link', 'Seasonal ticket'];
6
+ const idsEqual = (a, b) => {
7
+ if (a == null || b == null)
8
+ return false;
9
+ return String(a) === String(b);
10
+ };
11
+ exports.idsEqual = idsEqual;
12
+ const arrayHasId = (list = [], target) => {
13
+ if (!list || target == null)
14
+ return false;
15
+ return list.some(item => (0, exports.idsEqual)(item, target));
16
+ };
17
+ exports.arrayHasId = arrayHasId;
6
18
  function makeSaleLogic() {
7
19
  function whereAmI(path) {
8
20
  try {
@@ -24,8 +36,8 @@ function makeSaleLogic() {
24
36
  }
25
37
  }
26
38
  const isOnlineOrSeasonal = (flow) => flow.type === 'Seasonal ticket' || flow.type === 'Online';
27
- const cashierSeesSeasonal = (flow, staffFlowIds) => flow.type === 'Seasonal ticket' && (staffFlowIds || [])?.includes(flow.flowId);
28
- const comesFromSpecialLink = (flow, signedFlowId) => flow.type === 'Special link' && flow.flowId === signedFlowId;
39
+ const cashierSeesSeasonal = (flow, staffFlowIds) => flow.type === 'Seasonal ticket' && (0, exports.arrayHasId)(staffFlowIds, flow.flowId);
40
+ const comesFromSpecialLink = (flow, signedFlowId) => flow.type === 'Special link' && (0, exports.idsEqual)(flow.flowId, signedFlowId);
29
41
  const authoriser = ({ who, where, effectiveFlows, signedFlowId, staffFlowIds, }) => {
30
42
  // Guest
31
43
  if (who === 'guest') {
@@ -47,7 +59,7 @@ function makeSaleLogic() {
47
59
  if (where === 'Special link')
48
60
  return false;
49
61
  if (where === 'Offline') {
50
- return effectiveFlows.some(f => f.type === 'Offline' && staffFlowIds.includes(f.flowId));
62
+ return effectiveFlows.some(f => f.type === 'Offline' && (0, exports.arrayHasId)(staffFlowIds, f.flowId));
51
63
  }
52
64
  if (where === 'Seasonal ticket') {
53
65
  return effectiveFlows.some(f => cashierSeesSeasonal(f, staffFlowIds));
@@ -62,10 +74,10 @@ function makeSaleLogic() {
62
74
  if (!fixtureCategories || !fixtureCategories.length)
63
75
  return false;
64
76
  const sectionFlows = [
65
- ...fixtureCategories.flatMap(link => link.sections?.flatMap(section => (section.sectionId === sectionId ? section.flows : []))),
77
+ ...fixtureCategories.flatMap(link => link.sections?.flatMap(section => ((0, exports.idsEqual)(section.sectionId, sectionId) ? section.flows : []))),
66
78
  ];
67
79
  const categoryFlows = [
68
- ...fixtureCategories.flatMap(link => link.sections?.some(section => section.sectionId === sectionId) ? link.flows : []),
80
+ ...fixtureCategories.flatMap(link => link.sections?.some(section => (0, exports.idsEqual)(section.sectionId, sectionId)) ? link.flows : []),
69
81
  ];
70
82
  const effectiveFlows = sectionFlows.length ? sectionFlows : categoryFlows;
71
83
  return authoriser({ who, where, effectiveFlows, signedFlowId, staffFlowIds });
@@ -81,7 +93,7 @@ function makeSaleLogic() {
81
93
  if (!occupanceCategory || !occupanceCategory.categoryId)
82
94
  return true;
83
95
  const effectiveFlows = (fixtureCategories || [])
84
- .filter(link => link.categoryId === occupanceCategory.categoryId)
96
+ .filter(link => (0, exports.idsEqual)(link.categoryId, occupanceCategory.categoryId))
85
97
  .flatMap(link => link.flows);
86
98
  return authoriser({ who, where, effectiveFlows, signedFlowId, staffFlowIds });
87
99
  }
@@ -91,7 +103,7 @@ function makeSaleLogic() {
91
103
  }
92
104
  function getSectorCategory({ sectionId, fixtureCategories }) {
93
105
  try {
94
- const sectionCat = fixtureCategories?.find(link => link.sections?.some(section => section.sectionId === sectionId));
106
+ const sectionCat = fixtureCategories?.find(link => link.sections?.some(section => (0, exports.idsEqual)(section.sectionId, sectionId)));
95
107
  return {
96
108
  categoryId: sectionCat?.categoryId,
97
109
  name: sectionCat?.name ?? '',
@@ -108,7 +120,7 @@ function makeSaleLogic() {
108
120
  }
109
121
  function getOccupanceCategory({ occupanceCategory, fixtureCategories, }) {
110
122
  try {
111
- const occupanceCat = fixtureCategories?.find(link => link.categoryId === occupanceCategory?.categoryId);
123
+ const occupanceCat = fixtureCategories?.find(link => (0, exports.idsEqual)(link.categoryId, occupanceCategory?.categoryId));
112
124
  return {
113
125
  categoryId: occupanceCat?.categoryId,
114
126
  name: occupanceCat?.name ?? '',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibiliaze/global-vars",
3
- "version": "1.111.0",
3
+ "version": "1.113.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "sideEffects": false,
@@ -22,7 +22,7 @@
22
22
  "scripts": {
23
23
  "build": "tsc",
24
24
  "pub": "npm publish --access public",
25
- "git": "git add .; git commit -m 'changes'; git tag -a v1.111.0 -m 'v1.111.0'; git push origin v1.111.0; git push",
25
+ "git": "git add .; git commit -m 'changes'; git tag -a v1.113.0 -m 'v1.113.0'; git push origin v1.113.0; git push",
26
26
  "push": "npm run build; npm run git; npm run pub"
27
27
  },
28
28
  "author": "Ibi Hasanli",