@escapenavigator/utils 2.1.11 → 2.1.14
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.
|
@@ -31,6 +31,11 @@ export type BuildBookingPageUrlOptions = {
|
|
|
31
31
|
* провайдером слотов виджета как `?initialDate=`.
|
|
32
32
|
*/
|
|
33
33
|
initialDate?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Открыть продажу конкретного пакета (`?packageId=`). Виджет сразу
|
|
36
|
+
* поднимает конфигуратор этого пакета, а не общее расписание.
|
|
37
|
+
*/
|
|
38
|
+
packageId?: number;
|
|
34
39
|
};
|
|
35
40
|
/**
|
|
36
41
|
* Собирает tracking-параметры из URLSearchParams (или строки query).
|
|
@@ -49,6 +54,7 @@ export declare function appendBookingParamsToUrl(baseUrl: string, options?: {
|
|
|
49
54
|
* Базовый URL standalone booking-страницы:
|
|
50
55
|
* `{ordersDomain}/booking/{widgetUuid}` + testMode/lang/tracking/consent.
|
|
51
56
|
*/
|
|
57
|
+
export declare function parsePackageId(value?: string | null): number | undefined;
|
|
52
58
|
export declare function buildBookingPageUrl(options: BuildBookingPageUrlOptions): string;
|
|
53
59
|
/**
|
|
54
60
|
* Standalone-страница формы заявки: `{ordersDomain}/lead/{formUuid}`.
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.BOOKING_TRACKING_QUERY_PARAMS = void 0;
|
|
11
11
|
exports.collectTrackingParamsFromSearch = collectTrackingParamsFromSearch;
|
|
12
12
|
exports.appendBookingParamsToUrl = appendBookingParamsToUrl;
|
|
13
|
+
exports.parsePackageId = parsePackageId;
|
|
13
14
|
exports.buildBookingPageUrl = buildBookingPageUrl;
|
|
14
15
|
exports.buildLeadFormPageUrl = buildLeadFormPageUrl;
|
|
15
16
|
exports.buildBookingButtonOnclick = buildBookingButtonOnclick;
|
|
@@ -67,8 +68,14 @@ function appendBookingParamsToUrl(baseUrl, options) {
|
|
|
67
68
|
* Базовый URL standalone booking-страницы:
|
|
68
69
|
* `{ordersDomain}/booking/{widgetUuid}` + testMode/lang/tracking/consent.
|
|
69
70
|
*/
|
|
71
|
+
function parsePackageId(value) {
|
|
72
|
+
if (value == null || value === '')
|
|
73
|
+
return undefined;
|
|
74
|
+
const id = Number(value);
|
|
75
|
+
return Number.isInteger(id) && id > 0 ? id : undefined;
|
|
76
|
+
}
|
|
70
77
|
function buildBookingPageUrl(options) {
|
|
71
|
-
const { ordersDomain, widgetUuid, testMode, lang, tracking, consent, promocode, initialDate } = options;
|
|
78
|
+
const { ordersDomain, widgetUuid, testMode, lang, tracking, consent, promocode, initialDate, packageId, } = options;
|
|
72
79
|
const base = `${normalizeOrdersDomain(ordersDomain)}/booking/${encodeURIComponent(widgetUuid)}`;
|
|
73
80
|
const url = new URL(base);
|
|
74
81
|
if (testMode) {
|
|
@@ -83,6 +90,10 @@ function buildBookingPageUrl(options) {
|
|
|
83
90
|
if (initialDate?.trim()) {
|
|
84
91
|
url.searchParams.set('initialDate', initialDate.trim());
|
|
85
92
|
}
|
|
93
|
+
const resolvedPackageId = parsePackageId(packageId == null ? undefined : String(packageId));
|
|
94
|
+
if (resolvedPackageId) {
|
|
95
|
+
url.searchParams.set('packageId', String(resolvedPackageId));
|
|
96
|
+
}
|
|
86
97
|
return appendBookingParamsToUrl(url.toString(), { tracking, consent });
|
|
87
98
|
}
|
|
88
99
|
/**
|
|
@@ -57,4 +57,24 @@ describe('buildBookingPageUrl', () => {
|
|
|
57
57
|
});
|
|
58
58
|
expect(url).toBe('https://orders.example.com/booking/W1');
|
|
59
59
|
});
|
|
60
|
+
it('carries packageId so the widget opens that package sale', () => {
|
|
61
|
+
const url = (0, index_1.buildBookingPageUrl)({
|
|
62
|
+
ordersDomain: 'https://orders.example.com',
|
|
63
|
+
widgetUuid: 'W1',
|
|
64
|
+
packageId: 42,
|
|
65
|
+
});
|
|
66
|
+
expect(url).toBe('https://orders.example.com/booking/W1?packageId=42');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe('parsePackageId', () => {
|
|
70
|
+
it('accepts a positive integer', () => {
|
|
71
|
+
expect((0, index_1.parsePackageId)('42')).toBe(42);
|
|
72
|
+
});
|
|
73
|
+
it('rejects empty and invalid values', () => {
|
|
74
|
+
expect((0, index_1.parsePackageId)('')).toBeUndefined();
|
|
75
|
+
expect((0, index_1.parsePackageId)('0')).toBeUndefined();
|
|
76
|
+
expect((0, index_1.parsePackageId)('-3')).toBeUndefined();
|
|
77
|
+
expect((0, index_1.parsePackageId)('12.5')).toBeUndefined();
|
|
78
|
+
expect((0, index_1.parsePackageId)('abc')).toBeUndefined();
|
|
79
|
+
});
|
|
60
80
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@escapenavigator/utils",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.14",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"test": "jest"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@escapenavigator/types": "^2.1.
|
|
17
|
+
"@escapenavigator/types": "^2.1.13",
|
|
18
18
|
"axios": "^0.21.4",
|
|
19
19
|
"class-transformer": "^0.5.1",
|
|
20
20
|
"class-validator": "^0.13.2",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"ts-jest": "^29.1.1",
|
|
30
30
|
"typescript": "^5.6"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "c43b309381f1541293a3c5cf74f4ac11ae14cdf8"
|
|
33
33
|
}
|