Files
klz-cables.com/.pnpm-store/v10/files/e9/efc419bad90b95dd089eb1c81db154942b8baf018e775c72e6330e43b21ef93d476f935e9527dba0c288984e01011e4488316f8a2b7c5e0d6468e63330ffa3
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

89 lines
3.5 KiB
Plaintext

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseKeyPairsIntoRecord = exports.parsePairKeyValue = exports.getKeyPairs = exports.serializeKeyPairs = void 0;
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const api_1 = require("@opentelemetry/api");
const constants_1 = require("./constants");
function serializeKeyPairs(keyPairs) {
return keyPairs.reduce((hValue, current) => {
const value = `${hValue}${hValue !== '' ? constants_1.BAGGAGE_ITEMS_SEPARATOR : ''}${current}`;
return value.length > constants_1.BAGGAGE_MAX_TOTAL_LENGTH ? hValue : value;
}, '');
}
exports.serializeKeyPairs = serializeKeyPairs;
function getKeyPairs(baggage) {
return baggage.getAllEntries().map(([key, value]) => {
let entry = `${encodeURIComponent(key)}=${encodeURIComponent(value.value)}`;
// include opaque metadata if provided
// NOTE: we intentionally don't URI-encode the metadata - that responsibility falls on the metadata implementation
if (value.metadata !== undefined) {
entry += constants_1.BAGGAGE_PROPERTIES_SEPARATOR + value.metadata.toString();
}
return entry;
});
}
exports.getKeyPairs = getKeyPairs;
function parsePairKeyValue(entry) {
if (!entry)
return;
const metadataSeparatorIndex = entry.indexOf(constants_1.BAGGAGE_PROPERTIES_SEPARATOR);
const keyPairPart = metadataSeparatorIndex === -1
? entry
: entry.substring(0, metadataSeparatorIndex);
const separatorIndex = keyPairPart.indexOf(constants_1.BAGGAGE_KEY_PAIR_SEPARATOR);
if (separatorIndex <= 0)
return;
const rawKey = keyPairPart.substring(0, separatorIndex).trim();
const rawValue = keyPairPart.substring(separatorIndex + 1).trim();
if (!rawKey || !rawValue)
return;
let key;
let value;
try {
key = decodeURIComponent(rawKey);
value = decodeURIComponent(rawValue);
}
catch {
return;
}
let metadata;
if (metadataSeparatorIndex !== -1 &&
metadataSeparatorIndex < entry.length - 1) {
const metadataString = entry.substring(metadataSeparatorIndex + 1);
metadata = (0, api_1.baggageEntryMetadataFromString)(metadataString);
}
return { key, value, metadata };
}
exports.parsePairKeyValue = parsePairKeyValue;
/**
* Parse a string serialized in the baggage HTTP Format (without metadata):
* https://github.com/w3c/baggage/blob/master/baggage/HTTP_HEADER_FORMAT.md
*/
function parseKeyPairsIntoRecord(value) {
const result = {};
if (typeof value === 'string' && value.length > 0) {
value.split(constants_1.BAGGAGE_ITEMS_SEPARATOR).forEach(entry => {
const keyPair = parsePairKeyValue(entry);
if (keyPair !== undefined && keyPair.value.length > 0) {
result[keyPair.key] = keyPair.value;
}
});
}
return result;
}
exports.parseKeyPairsIntoRecord = parseKeyPairsIntoRecord;
//# sourceMappingURL=utils.js.map