@ibiliaze/global-vars 1.108.0 → 1.109.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 +1,65 @@
1
+ import { FixtureCategoryBase, FixtureCategoryFlowBase, FlowBase, OccupanceBase, StaffBase } from './ticketops/inputsDefault';
1
2
  export declare const flows: readonly ["Online", "Offline", "Special link", "Seasonal ticket"];
3
+ export declare function makeSaleLogic<Id, TDate>(): SaleLogic<Id, TDate>;
4
+ export type Path = '/' | '/link' | '/pos' | '/seasonal';
5
+ export type Who = 'guest' | 'root' | 'cashier';
6
+ export type SeatsByCat = {
7
+ categoryName: string;
8
+ categoryId: string;
9
+ available: number;
10
+ price: number;
11
+ color: string;
12
+ disabled: boolean;
13
+ }[];
14
+ export type WhereOf<Id, TDate> = FlowOf<Id, TDate>['type'];
15
+ type FlowOf<Id, TDate> = FlowBase<Id, TDate>;
16
+ type FixtureCategoryOf<Id> = FixtureCategoryBase<Id>;
17
+ type OccupanceCategoryOf<Id, TDate> = OccupanceBase<Id, TDate>['category'];
18
+ type StaffFlowIdsOf<Id, TDate> = StaffBase<Id, TDate>['flowIds'];
19
+ type EffectiveFlowsOf<Id> = FixtureCategoryFlowBase<Id>[];
20
+ export interface CanISeeSectionArgs<Id, TDate> {
21
+ who: Who;
22
+ where: WhereOf<Id, TDate>;
23
+ fixtureCategories: FixtureCategoryOf<Id>[];
24
+ sectionId: string;
25
+ staffFlowIds: StaffFlowIdsOf<Id, TDate>;
26
+ signedFlowId?: string | null;
27
+ }
28
+ export interface CanISeeSeatArgs<Id, TDate> {
29
+ who: Who;
30
+ where: WhereOf<Id, TDate>;
31
+ staffFlowIds: StaffFlowIdsOf<Id, TDate>;
32
+ occupanceCategory?: OccupanceCategoryOf<Id, TDate>;
33
+ fixtureCategories: FixtureCategoryOf<Id>[];
34
+ signedFlowId?: string | null;
35
+ }
36
+ export interface AuthoriserArgs<Id, TDate> {
37
+ who: Who;
38
+ where: WhereOf<Id, TDate>;
39
+ signedFlowId?: string | null;
40
+ effectiveFlows: EffectiveFlowsOf<Id>;
41
+ staffFlowIds: StaffFlowIdsOf<Id, TDate>;
42
+ }
43
+ export interface GetSectorCategoryArgs<Id> {
44
+ sectionId: string;
45
+ fixtureCategories: FixtureCategoryOf<Id>[];
46
+ }
47
+ export interface GetOccupanceCategoryArgs<Id, TDate> {
48
+ occupanceCategory: OccupanceCategoryOf<Id, TDate>;
49
+ fixtureCategories: FixtureCategoryOf<Id>[];
50
+ }
51
+ export interface GetCategoryArgs<Id, TDate> {
52
+ where: WhereOf<Id, TDate>;
53
+ fixtureCategories: FixtureCategoryOf<Id>[];
54
+ occupanceCategory: FixtureCategoryOf<Id> | undefined;
55
+ sectionCategory: FixtureCategoryOf<Id> | undefined;
56
+ }
57
+ export interface SaleLogic<Id, TDate> {
58
+ whereAmI(path: Path): WhereOf<Id, TDate>;
59
+ canISeeSection(args: CanISeeSectionArgs<Id, TDate>): boolean;
60
+ canISeeSeat(args: CanISeeSeatArgs<Id, TDate>): boolean;
61
+ getSectorCategory(args: GetSectorCategoryArgs<Id>): FixtureCategoryOf<Id> | undefined;
62
+ getOccupanceCategory(args: GetOccupanceCategoryArgs<Id, TDate>): FixtureCategoryOf<Id> | undefined;
63
+ getCategory(args: GetCategoryArgs<Id, TDate>): FixtureCategoryOf<Id> | undefined;
64
+ }
65
+ export {};
package/dist/flows.js CHANGED
@@ -1,4 +1,154 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.flows = void 0;
4
+ exports.makeSaleLogic = makeSaleLogic;
4
5
  exports.flows = ['Online', 'Offline', 'Special link', 'Seasonal ticket'];
6
+ function makeSaleLogic() {
7
+ function whereAmI(path) {
8
+ try {
9
+ switch (path) {
10
+ case '/':
11
+ return 'Online';
12
+ case '/link':
13
+ return 'Special link';
14
+ case '/pos':
15
+ return 'Offline';
16
+ case '/seasonal':
17
+ return 'Seasonal ticket';
18
+ default:
19
+ return 'Online';
20
+ }
21
+ }
22
+ catch {
23
+ return 'Online';
24
+ }
25
+ }
26
+ 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;
29
+ const authoriser = ({ who, where, effectiveFlows, signedFlowId, staffFlowIds, }) => {
30
+ // Guest
31
+ if (who === 'guest') {
32
+ if (where === 'Offline')
33
+ return false;
34
+ if (where === 'Special link')
35
+ return effectiveFlows.some(f => comesFromSpecialLink(f, signedFlowId));
36
+ if (where === 'Online')
37
+ return effectiveFlows.some(f => isOnlineOrSeasonal(f));
38
+ if (where === 'Seasonal ticket')
39
+ return effectiveFlows.some(f => f.type === 'Seasonal ticket');
40
+ }
41
+ // Cashier
42
+ if (who === 'cashier') {
43
+ if (!staffFlowIds || !staffFlowIds.length)
44
+ return false;
45
+ if (where === 'Online')
46
+ return false;
47
+ if (where === 'Special link')
48
+ return false;
49
+ if (where === 'Offline') {
50
+ return effectiveFlows.some(f => f.type === 'Offline' && staffFlowIds.includes(f.flowId));
51
+ }
52
+ if (where === 'Seasonal ticket') {
53
+ return effectiveFlows.some(f => cashierSeesSeasonal(f, staffFlowIds));
54
+ }
55
+ }
56
+ return false;
57
+ };
58
+ function canISeeSection({ who, where, sectionId, staffFlowIds, signedFlowId, fixtureCategories, }) {
59
+ try {
60
+ if (who === 'root')
61
+ return true;
62
+ if (!fixtureCategories || !fixtureCategories.length)
63
+ return false;
64
+ const sectionFlows = [
65
+ ...fixtureCategories.flatMap(link => link.sections?.flatMap(section => (section.sectionId === sectionId ? section.flows : []))),
66
+ ];
67
+ const categoryFlows = [
68
+ ...fixtureCategories.flatMap(link => link.sections?.some(section => section.sectionId === sectionId) ? link.flows : []),
69
+ ];
70
+ const effectiveFlows = sectionFlows.length ? sectionFlows : categoryFlows;
71
+ return authoriser({ who, where, effectiveFlows, signedFlowId, staffFlowIds });
72
+ }
73
+ catch {
74
+ return false;
75
+ }
76
+ }
77
+ function canISeeSeat({ who, where, signedFlowId, staffFlowIds, occupanceCategory, fixtureCategories, }) {
78
+ try {
79
+ if (who === 'root')
80
+ return true;
81
+ if (!occupanceCategory || !occupanceCategory.categoryId)
82
+ return true;
83
+ const effectiveFlows = (fixtureCategories || [])
84
+ .filter(link => link.categoryId === occupanceCategory.categoryId)
85
+ .flatMap(link => link.flows);
86
+ return authoriser({ who, where, effectiveFlows, signedFlowId, staffFlowIds });
87
+ }
88
+ catch {
89
+ return false;
90
+ }
91
+ }
92
+ function getSectorCategory({ sectionId, fixtureCategories }) {
93
+ try {
94
+ const sectionCat = fixtureCategories?.find(link => link.sections?.some(section => section.sectionId === sectionId));
95
+ return {
96
+ categoryId: sectionCat?.categoryId,
97
+ name: sectionCat?.name ?? '',
98
+ color: sectionCat?.color || 'blue.4',
99
+ disabled: sectionCat?.disabled ?? false,
100
+ price: sectionCat?.price ?? 0,
101
+ flows: sectionCat?.flows ?? [],
102
+ sections: sectionCat?.sections ?? [],
103
+ };
104
+ }
105
+ catch {
106
+ return undefined;
107
+ }
108
+ }
109
+ function getOccupanceCategory({ occupanceCategory, fixtureCategories, }) {
110
+ try {
111
+ const occupanceCat = fixtureCategories?.find(link => link.categoryId === occupanceCategory?.categoryId);
112
+ return {
113
+ categoryId: occupanceCat?.categoryId,
114
+ name: occupanceCat?.name ?? '',
115
+ color: occupanceCat?.color || 'blue.4',
116
+ disabled: occupanceCat?.disabled ?? false,
117
+ price: occupanceCat?.price ?? 0,
118
+ flows: occupanceCat?.flows ?? [],
119
+ sections: occupanceCat?.sections ?? [],
120
+ };
121
+ }
122
+ catch {
123
+ return undefined;
124
+ }
125
+ }
126
+ function getCategory({ where, fixtureCategories, occupanceCategory, sectionCategory, }) {
127
+ try {
128
+ const occupanceCatOverride = !!occupanceCategory?.categoryId;
129
+ const category = occupanceCatOverride ? occupanceCategory : sectionCategory;
130
+ const isSeasonal = category?.flows.find(flow => flow.type === 'Seasonal ticket');
131
+ const effectiveCategory = {
132
+ categoryId: (category?.categoryId ?? undefined),
133
+ name: category?.name ?? '',
134
+ color: category?.color || 'blue',
135
+ disabled: category?.disabled ?? false,
136
+ price: category?.price ?? 0,
137
+ flows: category?.flows ?? [],
138
+ sections: category?.sections ?? [],
139
+ };
140
+ if (!isSeasonal)
141
+ return effectiveCategory;
142
+ if (where === 'Seasonal ticket')
143
+ return effectiveCategory;
144
+ if (where === 'Offline')
145
+ return effectiveCategory;
146
+ const onlineFlowCategory = fixtureCategories?.find(link => link.flows?.some(flow => flow.type === 'Online'));
147
+ return onlineFlowCategory;
148
+ }
149
+ catch {
150
+ return undefined;
151
+ }
152
+ }
153
+ return { whereAmI, canISeeSection, canISeeSeat, getSectorCategory, getOccupanceCategory, getCategory };
154
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibiliaze/global-vars",
3
- "version": "1.108.0",
3
+ "version": "1.109.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.108.0 -m 'v1.108.0'; git push origin v1.108.0; git push",
25
+ "git": "git add .; git commit -m 'changes'; git tag -a v1.109.0 -m 'v1.109.0'; git push origin v1.109.0; git push",
26
26
  "push": "npm run build; npm run git; npm run pub"
27
27
  },
28
28
  "author": "Ibi Hasanli",