@ibiliaze/global-vars 1.112.0 → 1.114.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 +3 -0
- package/dist/flows.js +28 -15
- package/package.json +2 -2
package/dist/flows.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
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';
|
|
@@ -51,6 +53,7 @@ export interface GetOccupanceCategoryArgs<Id, TDate> {
|
|
|
51
53
|
export interface GetCategoryArgs<Id, TDate> {
|
|
52
54
|
where: WhereOf<Id, TDate>;
|
|
53
55
|
fixtureCategories: FixtureCategoryOf<Id>[];
|
|
56
|
+
sectionId: Id;
|
|
54
57
|
occupanceCategory: FixtureCategoryOf<Id> | undefined;
|
|
55
58
|
sectionCategory: FixtureCategoryOf<Id> | undefined;
|
|
56
59
|
}
|
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' && (
|
|
28
|
-
const comesFromSpecialLink = (flow, signedFlowId) => flow.type === 'Special link' && flow.flowId
|
|
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' &&
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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 ?? '',
|
|
@@ -123,7 +135,7 @@ function makeSaleLogic() {
|
|
|
123
135
|
return undefined;
|
|
124
136
|
}
|
|
125
137
|
}
|
|
126
|
-
function getCategory({ where, fixtureCategories, occupanceCategory, sectionCategory, }) {
|
|
138
|
+
function getCategory({ where, sectionId, fixtureCategories, occupanceCategory, sectionCategory, }) {
|
|
127
139
|
try {
|
|
128
140
|
const occupanceCatOverride = !!occupanceCategory?.categoryId;
|
|
129
141
|
const category = occupanceCatOverride ? occupanceCategory : sectionCategory;
|
|
@@ -137,14 +149,15 @@ function makeSaleLogic() {
|
|
|
137
149
|
flows: category?.flows ?? [],
|
|
138
150
|
sections: category?.sections ?? [],
|
|
139
151
|
};
|
|
152
|
+
// If it isn't a seasonal seat, return the effective cat
|
|
140
153
|
if (!isSeasonal)
|
|
141
154
|
return effectiveCategory;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (where === 'Offline')
|
|
155
|
+
// If Return the effective category is Sale Channel is Seasonal or Offline
|
|
156
|
+
if (where === 'Seasonal ticket' || where === 'Offline')
|
|
145
157
|
return effectiveCategory;
|
|
146
|
-
|
|
147
|
-
|
|
158
|
+
// If sale channel is not seasonal but the seat is seasonal, return a default category
|
|
159
|
+
const defaultFlowCategory = fixtureCategories.find(cat => cat.sections?.some(sec => (0, exports.idsEqual)(sec.sectionId, sectionId)));
|
|
160
|
+
return defaultFlowCategory;
|
|
148
161
|
}
|
|
149
162
|
catch {
|
|
150
163
|
return undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibiliaze/global-vars",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.114.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.
|
|
25
|
+
"git": "git add .; git commit -m 'changes'; git tag -a v1.114.0 -m 'v1.114.0'; git push origin v1.114.0; git push",
|
|
26
26
|
"push": "npm run build; npm run git; npm run pub"
|
|
27
27
|
},
|
|
28
28
|
"author": "Ibi Hasanli",
|