@adobe/alloy 2.30.1-beta.9 → 2.31.0-beta.24
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/libEs5/components/Advertising/createComponent.js +7 -3
- package/libEs5/components/Advertising/handlers/onBeforeSendEventHandler.js +8 -2
- package/libEs5/components/Advertising/handlers/sendAdConversion.js +11 -6
- package/libEs5/components/Advertising/handlers/viewThroughHandler.js +8 -2
- package/libEs5/components/Advertising/identities/collectSurferId.js +8 -1
- package/libEs5/components/Advertising/index.js +2 -1
- package/libEs5/components/BrandConcierge/configValidators.js +25 -0
- package/libEs5/components/BrandConcierge/constants.js +16 -0
- package/libEs5/components/BrandConcierge/createBuildEndpointUrl.js +33 -0
- package/libEs5/components/BrandConcierge/createConversationServiceRequest.js +35 -0
- package/libEs5/components/BrandConcierge/createSendConversationEvent.js +148 -0
- package/libEs5/components/BrandConcierge/createSendConversationServiceRequest.js +85 -0
- package/libEs5/components/BrandConcierge/createStreamParser.js +131 -0
- package/libEs5/components/BrandConcierge/createTimeoutWrapper.js +79 -0
- package/libEs5/components/BrandConcierge/index.js +102 -0
- package/libEs5/components/BrandConcierge/utils.js +33 -0
- package/libEs5/components/BrandConcierge/validateMessage.js +44 -0
- package/libEs5/components/Consent/types.js +12 -0
- package/libEs5/components/Context/createComponent.js +1 -2
- package/libEs5/components/Context/implementationDetails.js +7 -9
- package/libEs5/components/Context/index.js +4 -1
- package/libEs5/components/Context/injectDevice.js +2 -2
- package/libEs5/components/Context/injectEnvironment.js +2 -2
- package/libEs5/components/Context/injectHighEntropyUserAgentHints.js +2 -2
- package/libEs5/components/Context/injectOneTimeAnalyticsReferrer.js +52 -0
- package/libEs5/components/Context/injectPlaceContext.js +2 -2
- package/libEs5/components/Context/injectTimestamp.js +2 -3
- package/libEs5/components/Context/injectWeb.js +9 -11
- package/libEs5/components/EventMerge/createEventMergeId.js +1 -1
- package/libEs5/components/Personalization/createComponent.js +3 -1
- package/libEs5/components/Personalization/createFetchDataHandler.js +10 -4
- package/libEs5/components/Personalization/createNotificationHandler.js +5 -3
- package/libEs5/components/Personalization/createOnDecisionHandler.js +4 -3
- package/libEs5/components/Personalization/createPersonalizationDetails.js +1 -1
- package/libEs5/components/Personalization/dom-actions/initDomActionsModules.js +1 -1
- package/libEs5/components/Personalization/dom-actions/remapHeadOffers.js +5 -0
- package/libEs5/components/Personalization/handlers/createProcessInAppMessage.js +2 -1
- package/libEs5/components/Personalization/handlers/createProcessRedirect.js +2 -1
- package/libEs5/components/Personalization/handlers/injectCreateProposition.js +4 -1
- package/libEs5/components/Personalization/in-app-message-actions/actions/displayIframeContent.js +4 -2
- package/libEs5/components/Personalization/index.js +2 -2
- package/libEs5/components/PushNotifications/types.js +12 -0
- package/libEs5/components/RulesEngine/createApplyResponse.js +3 -1
- package/libEs5/components/RulesEngine/types.js +12 -0
- package/libEs5/components/StreamingMedia/createMediaEventManager.js +1 -1
- package/libEs5/constants/libraryVersion.js +1 -1
- package/libEs5/constants/surface.js +19 -0
- package/libEs5/core/componentCreators.js +8 -1
- package/libEs5/core/consent/types.js +12 -0
- package/libEs5/core/createEvent.js +7 -0
- package/libEs5/core/edgeNetwork/injectSendEdgeNetworkRequest.js +23 -0
- package/libEs5/core/edgeNetwork/types.js +12 -0
- package/libEs5/core/identity/types.js +12 -0
- package/libEs5/core/index.js +5 -1
- package/libEs5/core/types.js +12 -0
- package/libEs5/utils/clamp.js +25 -0
- package/libEs5/utils/createCollect.js +4 -2
- package/libEs5/utils/deepAssign.js +5 -0
- package/libEs5/utils/dom/createGetPageLocation.js +20 -0
- package/libEs5/utils/filterObject.js +1 -1
- package/libEs5/utils/index.js +8 -1
- package/libEs5/utils/prepareConfigOverridesForEdge.js +4 -2
- package/libEs5/utils/request/createDataCollectionRequestPayload.js +3 -0
- package/libEs5/utils/request/createRequest.js +5 -1
- package/libEs5/utils/request/createRequestParams.js +1 -0
- package/libEs5/utils/request/createRequestPayload.js +11 -1
- package/libEs5/utils/request/types.js +13 -0
- package/libEs5/utils/surfaceUtils.js +82 -0
- package/libEs5/utils/types.js +12 -0
- package/libEs6/components/Advertising/createComponent.js +7 -3
- package/libEs6/components/Advertising/handlers/onBeforeSendEventHandler.js +8 -2
- package/libEs6/components/Advertising/handlers/sendAdConversion.js +11 -6
- package/libEs6/components/Advertising/handlers/viewThroughHandler.js +8 -2
- package/libEs6/components/Advertising/identities/collectSurferId.js +8 -1
- package/libEs6/components/Advertising/index.js +2 -1
- package/libEs6/components/BrandConcierge/configValidators.js +22 -0
- package/libEs6/components/BrandConcierge/constants.js +13 -0
- package/libEs6/components/BrandConcierge/createBuildEndpointUrl.js +30 -0
- package/libEs6/components/BrandConcierge/createConversationServiceRequest.js +31 -0
- package/libEs6/components/BrandConcierge/createSendConversationEvent.js +144 -0
- package/libEs6/components/BrandConcierge/createSendConversationServiceRequest.js +81 -0
- package/libEs6/components/BrandConcierge/createStreamParser.js +127 -0
- package/libEs6/components/BrandConcierge/createTimeoutWrapper.js +76 -0
- package/libEs6/components/BrandConcierge/index.js +98 -0
- package/libEs6/components/BrandConcierge/utils.js +27 -0
- package/libEs6/components/BrandConcierge/validateMessage.js +40 -0
- package/libEs6/components/Consent/types.js +12 -0
- package/libEs6/components/Context/createComponent.js +1 -2
- package/libEs6/components/Context/implementationDetails.js +7 -9
- package/libEs6/components/Context/index.js +4 -1
- package/libEs6/components/Context/injectDevice.js +3 -3
- package/libEs6/components/Context/injectEnvironment.js +3 -3
- package/libEs6/components/Context/injectHighEntropyUserAgentHints.js +3 -3
- package/libEs6/components/Context/injectOneTimeAnalyticsReferrer.js +48 -0
- package/libEs6/components/Context/injectPlaceContext.js +3 -3
- package/libEs6/components/Context/injectTimestamp.js +2 -3
- package/libEs6/components/Context/injectWeb.js +9 -11
- package/libEs6/components/EventMerge/createEventMergeId.js +1 -1
- package/libEs6/components/Personalization/createComponent.js +3 -1
- package/libEs6/components/Personalization/createFetchDataHandler.js +10 -4
- package/libEs6/components/Personalization/createNotificationHandler.js +5 -3
- package/libEs6/components/Personalization/createOnDecisionHandler.js +4 -3
- package/libEs6/components/Personalization/createPersonalizationDetails.js +1 -1
- package/libEs6/components/Personalization/dom-actions/initDomActionsModules.js +1 -1
- package/libEs6/components/Personalization/dom-actions/remapHeadOffers.js +6 -1
- package/libEs6/components/Personalization/handlers/createProcessInAppMessage.js +2 -1
- package/libEs6/components/Personalization/handlers/createProcessRedirect.js +2 -1
- package/libEs6/components/Personalization/handlers/injectCreateProposition.js +4 -1
- package/libEs6/components/Personalization/in-app-message-actions/actions/displayIframeContent.js +4 -2
- package/libEs6/components/Personalization/index.js +2 -2
- package/libEs6/components/PushNotifications/types.js +12 -0
- package/libEs6/components/RulesEngine/createApplyResponse.js +3 -1
- package/libEs6/components/RulesEngine/types.js +12 -0
- package/libEs6/components/StreamingMedia/createMediaEventManager.js +1 -1
- package/libEs6/constants/libraryVersion.js +1 -1
- package/libEs6/constants/surface.js +16 -0
- package/libEs6/core/componentCreators.js +2 -1
- package/libEs6/core/consent/types.js +12 -0
- package/libEs6/core/createEvent.js +7 -0
- package/libEs6/core/edgeNetwork/injectSendEdgeNetworkRequest.js +23 -0
- package/libEs6/core/edgeNetwork/types.js +12 -0
- package/libEs6/core/identity/types.js +12 -0
- package/libEs6/core/index.js +5 -1
- package/libEs6/core/types.js +12 -0
- package/libEs6/utils/clamp.js +22 -0
- package/libEs6/utils/createCollect.js +4 -2
- package/libEs6/utils/deepAssign.js +6 -0
- package/libEs6/utils/dom/createGetPageLocation.js +17 -0
- package/libEs6/utils/filterObject.js +1 -1
- package/libEs6/utils/index.js +2 -1
- package/libEs6/utils/prepareConfigOverridesForEdge.js +4 -2
- package/libEs6/utils/request/createDataCollectionRequestPayload.js +3 -0
- package/libEs6/utils/request/createRequest.js +5 -1
- package/libEs6/utils/request/createRequestParams.js +1 -0
- package/libEs6/utils/request/createRequestPayload.js +11 -1
- package/libEs6/utils/request/types.js +13 -0
- package/libEs6/utils/surfaceUtils.js +76 -0
- package/libEs6/utils/types.js +12 -0
- package/package.json +32 -36
- package/scripts/helpers/path.js +12 -0
- package/scripts/helpers/versionBabelPlugin.js +12 -0
- package/types/components/Advertising/createComponent.d.ts +3 -2
- package/types/components/Advertising/createComponent.d.ts.map +1 -1
- package/types/components/Advertising/handlers/onBeforeSendEventHandler.d.ts.map +1 -1
- package/types/components/Advertising/handlers/sendAdConversion.d.ts +2 -1
- package/types/components/Advertising/handlers/sendAdConversion.d.ts.map +1 -1
- package/types/components/Advertising/handlers/viewThroughHandler.d.ts.map +1 -1
- package/types/components/Advertising/identities/collectSurferId.d.ts.map +1 -1
- package/types/components/Advertising/index.d.ts +1 -1
- package/types/components/Advertising/index.d.ts.map +1 -1
- package/types/components/BrandConcierge/configValidators.d.ts +3 -0
- package/types/components/BrandConcierge/configValidators.d.ts.map +1 -0
- package/types/components/BrandConcierge/constants.d.ts +3 -0
- package/types/components/BrandConcierge/constants.d.ts.map +1 -0
- package/types/components/BrandConcierge/createBuildEndpointUrl.d.ts +9 -0
- package/types/components/BrandConcierge/createBuildEndpointUrl.d.ts.map +1 -0
- package/types/components/BrandConcierge/createConversationServiceRequest.d.ts +7 -0
- package/types/components/BrandConcierge/createConversationServiceRequest.d.ts.map +1 -0
- package/types/components/BrandConcierge/createSendConversationEvent.d.ts +15 -0
- package/types/components/BrandConcierge/createSendConversationEvent.d.ts.map +1 -0
- package/types/components/BrandConcierge/createSendConversationServiceRequest.d.ts +11 -0
- package/types/components/BrandConcierge/createSendConversationServiceRequest.d.ts.map +1 -0
- package/types/components/BrandConcierge/createStreamParser.d.ts +7 -0
- package/types/components/BrandConcierge/createStreamParser.d.ts.map +1 -0
- package/types/components/BrandConcierge/createTimeoutWrapper.d.ts +6 -0
- package/types/components/BrandConcierge/createTimeoutWrapper.d.ts.map +1 -0
- package/types/components/BrandConcierge/index.d.ts +32 -0
- package/types/components/BrandConcierge/index.d.ts.map +1 -0
- package/types/components/BrandConcierge/utils.d.ts +6 -0
- package/types/components/BrandConcierge/utils.d.ts.map +1 -0
- package/types/components/BrandConcierge/validateMessage.d.ts +5 -0
- package/types/components/BrandConcierge/validateMessage.d.ts.map +1 -0
- package/types/components/Consent/types.d.ts.map +1 -1
- package/types/components/Context/createComponent.d.ts +1 -1
- package/types/components/Context/createComponent.d.ts.map +1 -1
- package/types/components/Context/implementationDetails.d.ts +1 -1
- package/types/components/Context/implementationDetails.d.ts.map +1 -1
- package/types/components/Context/index.d.ts +1 -1
- package/types/components/Context/index.d.ts.map +1 -1
- package/types/components/Context/injectDevice.d.ts +1 -1
- package/types/components/Context/injectDevice.d.ts.map +1 -1
- package/types/components/Context/injectEnvironment.d.ts +1 -1
- package/types/components/Context/injectEnvironment.d.ts.map +1 -1
- package/types/components/Context/injectHighEntropyUserAgentHints.d.ts +1 -1
- package/types/components/Context/injectHighEntropyUserAgentHints.d.ts.map +1 -1
- package/types/components/Context/injectOneTimeAnalyticsReferrer.d.ts +3 -0
- package/types/components/Context/injectOneTimeAnalyticsReferrer.d.ts.map +1 -0
- package/types/components/Context/injectPlaceContext.d.ts +1 -1
- package/types/components/Context/injectPlaceContext.d.ts.map +1 -1
- package/types/components/Context/injectTimestamp.d.ts +1 -1
- package/types/components/Context/injectTimestamp.d.ts.map +1 -1
- package/types/components/Context/injectWeb.d.ts +1 -1
- package/types/components/Context/injectWeb.d.ts.map +1 -1
- package/types/components/Personalization/createComponent.d.ts.map +1 -1
- package/types/components/Personalization/createFetchDataHandler.d.ts +2 -1
- package/types/components/Personalization/createFetchDataHandler.d.ts.map +1 -1
- package/types/components/Personalization/createNotificationHandler.d.ts +1 -1
- package/types/components/Personalization/createNotificationHandler.d.ts.map +1 -1
- package/types/components/Personalization/createOnDecisionHandler.d.ts +2 -1
- package/types/components/Personalization/createOnDecisionHandler.d.ts.map +1 -1
- package/types/components/Personalization/createPersonalizationDetails.d.ts.map +1 -1
- package/types/components/Personalization/dom-actions/remapHeadOffers.d.ts.map +1 -1
- package/types/components/Personalization/handlers/createProcessInAppMessage.d.ts.map +1 -1
- package/types/components/Personalization/handlers/createProcessRedirect.d.ts.map +1 -1
- package/types/components/Personalization/handlers/injectCreateProposition.d.ts +2 -1
- package/types/components/Personalization/handlers/injectCreateProposition.d.ts.map +1 -1
- package/types/components/Personalization/in-app-message-actions/actions/displayIframeContent.d.ts.map +1 -1
- package/types/components/Personalization/index.d.ts.map +1 -1
- package/types/components/PushNotifications/types.d.ts.map +1 -1
- package/types/components/RulesEngine/createApplyResponse.d.ts.map +1 -1
- package/types/components/RulesEngine/index.d.ts.map +1 -1
- package/types/components/RulesEngine/types.d.ts.map +1 -1
- package/types/constants/surface.d.ts +5 -0
- package/types/constants/surface.d.ts.map +1 -0
- package/types/core/componentCreators.d.ts +1 -0
- package/types/core/consent/types.d.ts.map +1 -1
- package/types/core/createEvent.d.ts +2 -0
- package/types/core/createEvent.d.ts.map +1 -1
- package/types/core/edgeNetwork/injectSendEdgeNetworkRequest.d.ts.map +1 -1
- package/types/core/edgeNetwork/types.d.ts.map +1 -1
- package/types/core/identity/types.d.ts.map +1 -1
- package/types/core/index.d.ts.map +1 -1
- package/types/core/types.d.ts.map +1 -1
- package/types/utils/clamp.d.ts +3 -0
- package/types/utils/clamp.d.ts.map +1 -0
- package/types/utils/createCollect.d.ts +2 -1
- package/types/utils/createCollect.d.ts.map +1 -1
- package/types/utils/deepAssign.d.ts.map +1 -1
- package/types/utils/dom/createGetPageLocation.d.ts +5 -0
- package/types/utils/dom/createGetPageLocation.d.ts.map +1 -0
- package/types/utils/index.d.ts +1 -0
- package/types/utils/prepareConfigOverridesForEdge.d.ts.map +1 -1
- package/types/utils/request/createDataCollectionRequestPayload.d.ts.map +1 -1
- package/types/utils/request/createRequest.d.ts.map +1 -1
- package/types/utils/request/createRequestParams.d.ts.map +1 -1
- package/types/utils/request/createRequestPayload.d.ts.map +1 -1
- package/types/utils/request/types.d.ts +2 -0
- package/types/utils/request/types.d.ts.map +1 -1
- package/types/utils/surfaceUtils.d.ts +4 -0
- package/types/utils/surfaceUtils.d.ts.map +1 -0
- package/types/utils/types.d.ts.map +1 -1
|
@@ -20,7 +20,8 @@ var _default = ({
|
|
|
20
20
|
eventManager,
|
|
21
21
|
cookieManager,
|
|
22
22
|
adConversionHandler,
|
|
23
|
-
getBrowser
|
|
23
|
+
getBrowser,
|
|
24
|
+
consent
|
|
24
25
|
}) => {
|
|
25
26
|
const componentConfig = config.advertising;
|
|
26
27
|
const sendAdConversionHandler = (0, _sendAdConversion.default)({
|
|
@@ -29,12 +30,15 @@ var _default = ({
|
|
|
29
30
|
adConversionHandler,
|
|
30
31
|
logger,
|
|
31
32
|
componentConfig,
|
|
32
|
-
getBrowser
|
|
33
|
+
getBrowser,
|
|
34
|
+
consent
|
|
33
35
|
});
|
|
34
36
|
return {
|
|
35
37
|
lifecycle: {
|
|
36
38
|
onComponentsRegistered() {
|
|
37
|
-
return
|
|
39
|
+
// Fire-and-forget: don't return the promise so we don't block
|
|
40
|
+
// the configure command from resolving while waiting for consent.
|
|
41
|
+
sendAdConversionHandler();
|
|
38
42
|
},
|
|
39
43
|
onBeforeEvent: ({
|
|
40
44
|
event,
|
|
@@ -10,8 +10,14 @@ var _consentStatus = require("../../../constants/consentStatus.js");
|
|
|
10
10
|
var _browser = require("../../../constants/browser.js");
|
|
11
11
|
/*
|
|
12
12
|
Copyright 2023 Adobe. All rights reserved.
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
14
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
15
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
|
|
17
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
18
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
19
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
20
|
+
governing permissions and limitations under the License.
|
|
15
21
|
*/
|
|
16
22
|
|
|
17
23
|
const isAdvertisingDisabled = advertising => {
|
|
@@ -26,16 +26,21 @@ var _default = ({
|
|
|
26
26
|
adConversionHandler,
|
|
27
27
|
logger,
|
|
28
28
|
componentConfig,
|
|
29
|
-
getBrowser
|
|
29
|
+
getBrowser,
|
|
30
|
+
consent
|
|
30
31
|
}) => {
|
|
31
32
|
const activeAdvertiserIds = componentConfig?.advertiserSettings ? (0, _helpers.normalizeAdvertiser)(componentConfig.advertiserSettings) : "";
|
|
32
33
|
return async () => {
|
|
33
|
-
const {
|
|
34
|
-
skwcid,
|
|
35
|
-
efid
|
|
36
|
-
} = (0, _helpers.getUrlParams)();
|
|
37
|
-
const isClickThru = !!(skwcid || efid);
|
|
38
34
|
try {
|
|
35
|
+
// Wait for consent before any ad conversion processing.
|
|
36
|
+
// This ensures no advertising cookies are set without user consent.
|
|
37
|
+
// If consent is declined, awaitConsent() rejects and we exit gracefully.
|
|
38
|
+
await consent.awaitConsent();
|
|
39
|
+
const {
|
|
40
|
+
skwcid,
|
|
41
|
+
efid
|
|
42
|
+
} = (0, _helpers.getUrlParams)();
|
|
43
|
+
const isClickThru = !!(skwcid || efid);
|
|
39
44
|
if (isClickThru) {
|
|
40
45
|
// wait for click through to complete
|
|
41
46
|
return (0, _clickThroughHandler.default)({
|
|
@@ -6,8 +6,14 @@ var _index = require("../constants/index.js");
|
|
|
6
6
|
var _helpers = require("../utils/helpers.js");
|
|
7
7
|
/*
|
|
8
8
|
Copyright 2025 Adobe. All rights reserved.
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
11
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
14
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
15
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
16
|
+
governing permissions and limitations under the License.
|
|
11
17
|
*/
|
|
12
18
|
|
|
13
19
|
async function handleViewThrough({
|
|
@@ -6,7 +6,14 @@ var _createNode = require("../../../utils/dom/createNode.js");
|
|
|
6
6
|
var _index2 = require("../../../utils/index.js");
|
|
7
7
|
/*
|
|
8
8
|
Copyright 2025 Adobe. All rights reserved.
|
|
9
|
-
This file is licensed under the Apache License, Version 2.0
|
|
9
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
11
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
14
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
15
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
16
|
+
governing permissions and limitations under the License.
|
|
10
17
|
*/
|
|
11
18
|
|
|
12
19
|
let surferId = "";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var _constants = require("./constants.js");
|
|
5
|
+
var _index = require("../../utils/validation/index.js");
|
|
6
|
+
/*
|
|
7
|
+
Copyright 2026 Adobe. All rights reserved.
|
|
8
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
10
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
13
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
14
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
15
|
+
governing permissions and limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
var _default = exports.default = (0, _index.objectOf)({
|
|
18
|
+
conversation: (0, _index.objectOf)({
|
|
19
|
+
stickyConversationSession: (0, _index.boolean)().default(false),
|
|
20
|
+
streamTimeout: (0, _index.number)().integer().minimum(_constants.STREAM_START_TIMEOUT_MS).default(_constants.STREAM_START_TIMEOUT_MS)
|
|
21
|
+
}).default({
|
|
22
|
+
stickyConversationSession: false,
|
|
23
|
+
streamTimeout: _constants.STREAM_START_TIMEOUT_MS
|
|
24
|
+
})
|
|
25
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.STREAM_START_TIMEOUT_MS = exports.BC_SESSION_COOKIE_NAME = void 0;
|
|
4
|
+
/*
|
|
5
|
+
Copyright 2025 Adobe. All rights reserved.
|
|
6
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
const BC_SESSION_COOKIE_NAME = exports.BC_SESSION_COOKIE_NAME = "bc_session_id";
|
|
16
|
+
const STREAM_START_TIMEOUT_MS = exports.STREAM_START_TIMEOUT_MS = 10000;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
/*
|
|
5
|
+
Copyright 2025 Adobe. All rights reserved.
|
|
6
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
var _default = ({
|
|
16
|
+
queryString
|
|
17
|
+
}) => {
|
|
18
|
+
return ({
|
|
19
|
+
edgeDomain,
|
|
20
|
+
request,
|
|
21
|
+
datastreamId
|
|
22
|
+
}) => {
|
|
23
|
+
const params = request.getRequestParams();
|
|
24
|
+
const configId = request.getDatastreamIdOverride() || datastreamId;
|
|
25
|
+
params.requestId = request.getId();
|
|
26
|
+
params.configId = configId;
|
|
27
|
+
const stringifiedRequestParams = queryString.stringify({
|
|
28
|
+
...params
|
|
29
|
+
});
|
|
30
|
+
return "https://" + edgeDomain + request.getEdgeSubPath() + "/" + request.getAction() + "?" + stringifiedRequestParams;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
exports.default = _default;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var _index = require("../../utils/request/index.js");
|
|
5
|
+
/*
|
|
6
|
+
Copyright 2023 Adobe. All rights reserved.
|
|
7
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
9
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
12
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
13
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
14
|
+
governing permissions and limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
var _default = ({
|
|
17
|
+
payload,
|
|
18
|
+
action = "conversations",
|
|
19
|
+
sessionId
|
|
20
|
+
}) => {
|
|
21
|
+
return (0, _index.createRequest)({
|
|
22
|
+
payload: payload,
|
|
23
|
+
edgeSubPath: "/brand-concierge",
|
|
24
|
+
requestParams: {
|
|
25
|
+
sessionId
|
|
26
|
+
},
|
|
27
|
+
getAction() {
|
|
28
|
+
return action;
|
|
29
|
+
},
|
|
30
|
+
getUseSendBeacon() {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
exports.default = _default;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var _index = require("../../utils/request/index.js");
|
|
5
|
+
var _createConversationServiceRequest = require("./createConversationServiceRequest.js");
|
|
6
|
+
var _utils = require("./utils.js");
|
|
7
|
+
var _uuid = require("../../utils/uuid.js");
|
|
8
|
+
var _createStreamParser = require("./createStreamParser.js");
|
|
9
|
+
var _createTimeoutWrapper = require("./createTimeoutWrapper.js");
|
|
10
|
+
/*
|
|
11
|
+
Copyright 2025 Adobe. All rights reserved.
|
|
12
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
14
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
|
|
16
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
17
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
18
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
19
|
+
governing permissions and limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
var _default = ({
|
|
22
|
+
eventManager,
|
|
23
|
+
loggingCookieJar,
|
|
24
|
+
config,
|
|
25
|
+
logger,
|
|
26
|
+
sendConversationServiceRequest,
|
|
27
|
+
buildEndpointUrl,
|
|
28
|
+
cookieTransfer,
|
|
29
|
+
createResponse,
|
|
30
|
+
decodeKndctrCookie,
|
|
31
|
+
lifecycle,
|
|
32
|
+
consent
|
|
33
|
+
}) => {
|
|
34
|
+
const {
|
|
35
|
+
edgeDomain,
|
|
36
|
+
edgeBasePath,
|
|
37
|
+
datastreamId,
|
|
38
|
+
onBeforeEventSend,
|
|
39
|
+
conversation
|
|
40
|
+
} = config;
|
|
41
|
+
return options => {
|
|
42
|
+
let streamingEnabled = false;
|
|
43
|
+
const {
|
|
44
|
+
message,
|
|
45
|
+
onStreamResponse,
|
|
46
|
+
xdm,
|
|
47
|
+
data
|
|
48
|
+
} = options;
|
|
49
|
+
const sessionId = (0, _utils.getConciergeSessionCookie)({
|
|
50
|
+
loggingCookieJar,
|
|
51
|
+
config
|
|
52
|
+
}) || (0, _uuid.default)();
|
|
53
|
+
const payload = (0, _index.createDataCollectionRequestPayload)();
|
|
54
|
+
const request = (0, _createConversationServiceRequest.default)({
|
|
55
|
+
payload,
|
|
56
|
+
sessionId: sessionId
|
|
57
|
+
});
|
|
58
|
+
const event = eventManager.createEvent();
|
|
59
|
+
if (message || data) {
|
|
60
|
+
const pageSurface = (0, _utils.getPageSurface)();
|
|
61
|
+
event.mergeQuery({
|
|
62
|
+
conversation: {
|
|
63
|
+
surfaces: [pageSurface],
|
|
64
|
+
message,
|
|
65
|
+
data
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const {
|
|
70
|
+
state
|
|
71
|
+
} = consent.current();
|
|
72
|
+
event.mergeMeta({
|
|
73
|
+
consent: {
|
|
74
|
+
state: state
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const ecid = decodeKndctrCookie();
|
|
78
|
+
event.mergeXdm({
|
|
79
|
+
identityMap: {
|
|
80
|
+
ECID: [{
|
|
81
|
+
id: ecid
|
|
82
|
+
}]
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
event.mergeXdm({
|
|
86
|
+
...xdm
|
|
87
|
+
});
|
|
88
|
+
if (message || data) {
|
|
89
|
+
streamingEnabled = true;
|
|
90
|
+
}
|
|
91
|
+
const url = buildEndpointUrl({
|
|
92
|
+
edgeDomain,
|
|
93
|
+
edgeBasePath,
|
|
94
|
+
datastreamId,
|
|
95
|
+
request
|
|
96
|
+
});
|
|
97
|
+
return lifecycle.onBeforeEvent({
|
|
98
|
+
event
|
|
99
|
+
}).then(() => {
|
|
100
|
+
try {
|
|
101
|
+
// NOTE: this calls onBeforeEventSend callback (if configured)
|
|
102
|
+
event.finalize(onBeforeEventSend);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
onStreamResponse({
|
|
105
|
+
error
|
|
106
|
+
});
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
payload.addEvent(event);
|
|
110
|
+
cookieTransfer.cookiesToPayload(payload, edgeDomain);
|
|
111
|
+
return sendConversationServiceRequest({
|
|
112
|
+
requestId: (0, _uuid.default)(),
|
|
113
|
+
url,
|
|
114
|
+
request,
|
|
115
|
+
onStreamResponse,
|
|
116
|
+
streamingEnabled
|
|
117
|
+
}).then(response => {
|
|
118
|
+
if (response.status === 204) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const onStreamResponseCallback = event => {
|
|
122
|
+
if (event.error) {
|
|
123
|
+
logger.error("Stream error occurred", event.error);
|
|
124
|
+
onStreamResponse({
|
|
125
|
+
error: event.error
|
|
126
|
+
});
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const substr = event.data.replace("data: ", "");
|
|
130
|
+
const responseJson = JSON.parse(substr);
|
|
131
|
+
const response = createResponse({
|
|
132
|
+
content: responseJson
|
|
133
|
+
});
|
|
134
|
+
cookieTransfer.responseToCookies(response);
|
|
135
|
+
logger.info("onStreamResponse callback called with", response.getPayloadsByType("brand-concierge:conversation"));
|
|
136
|
+
onStreamResponse(response.getPayloadsByType("brand-concierge:conversation"));
|
|
137
|
+
};
|
|
138
|
+
const timeoutWrapper = (0, _createTimeoutWrapper.default)({
|
|
139
|
+
onStreamResponseCallback,
|
|
140
|
+
streamTimeout: conversation.streamTimeout
|
|
141
|
+
});
|
|
142
|
+
const streamParser = (0, _createStreamParser.default)();
|
|
143
|
+
streamParser(response.body, timeoutWrapper);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
exports.default = _default;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var _index = require("../../utils/index.js");
|
|
5
|
+
/*
|
|
6
|
+
Copyright 2025 Adobe. All rights reserved.
|
|
7
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
9
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
12
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
13
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
14
|
+
governing permissions and limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
var _default = ({
|
|
17
|
+
logger,
|
|
18
|
+
fetch
|
|
19
|
+
}) => {
|
|
20
|
+
return async ({
|
|
21
|
+
requestId,
|
|
22
|
+
url,
|
|
23
|
+
request,
|
|
24
|
+
streamingEnabled = true
|
|
25
|
+
}) => {
|
|
26
|
+
const payload = request.getPayload();
|
|
27
|
+
const stringifiedPayload = JSON.stringify(payload);
|
|
28
|
+
const parsedPayload = JSON.parse(stringifiedPayload);
|
|
29
|
+
const headers = {
|
|
30
|
+
"Content-Type": "text/plain"
|
|
31
|
+
};
|
|
32
|
+
if (streamingEnabled) {
|
|
33
|
+
headers.Accept = "text/event-stream";
|
|
34
|
+
} else {
|
|
35
|
+
headers.Accept = "text/plain";
|
|
36
|
+
}
|
|
37
|
+
logger.logOnBeforeNetworkRequest({
|
|
38
|
+
url,
|
|
39
|
+
requestId,
|
|
40
|
+
payload: parsedPayload
|
|
41
|
+
});
|
|
42
|
+
const fetchWithRetries = async (attemptNumber = 1) => {
|
|
43
|
+
const maxAttempts = 4;
|
|
44
|
+
const retryDelays = [2000, 3000, 5000];
|
|
45
|
+
try {
|
|
46
|
+
const response = await fetch(url, {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: headers,
|
|
49
|
+
body: stringifiedPayload
|
|
50
|
+
});
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
throw new Error("Request failed with status " + response.status);
|
|
53
|
+
}
|
|
54
|
+
return response;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (attemptNumber < maxAttempts) {
|
|
57
|
+
const delay = retryDelays[attemptNumber - 1];
|
|
58
|
+
logger.logOnNetworkError({
|
|
59
|
+
requestId,
|
|
60
|
+
url,
|
|
61
|
+
payload: parsedPayload,
|
|
62
|
+
error: new Error("Attempt " + attemptNumber + " failed, retrying in " + delay + "ms: " + error.message)
|
|
63
|
+
});
|
|
64
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
65
|
+
return fetchWithRetries(attemptNumber + 1);
|
|
66
|
+
}
|
|
67
|
+
logger.logOnNetworkError({
|
|
68
|
+
requestId,
|
|
69
|
+
url,
|
|
70
|
+
payload: parsedPayload,
|
|
71
|
+
error
|
|
72
|
+
});
|
|
73
|
+
throw (0, _index.stackError)({
|
|
74
|
+
error,
|
|
75
|
+
message: "Network request failed after all retries."
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const executeRequest = async () => {
|
|
80
|
+
return fetchWithRetries();
|
|
81
|
+
};
|
|
82
|
+
return executeRequest();
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
exports.default = _default;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
/*
|
|
5
|
+
Copyright 2024 Adobe. All rights reserved.
|
|
6
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
var _default = () => {
|
|
16
|
+
// SSE streams are always UTF-8 encoded per specification
|
|
17
|
+
const ENCODING = "utf-8";
|
|
18
|
+
// SSE spec allows three line ending styles: CRLF (\r\n), LF (\n), or CR (\r)
|
|
19
|
+
const LINE_ENDING_REGEX = /\r\n|\r|\n/;
|
|
20
|
+
// Events are separated by blank lines (double line endings)
|
|
21
|
+
const EVENT_SEPARATOR_REGEX = /\r\n\r\n|\n\n|\r\r/;
|
|
22
|
+
// Ping comment format: `: ping` (colon followed immediately by "ping")
|
|
23
|
+
const PING_COMMENT = ": ping";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Check if an event block is a ping comment.
|
|
27
|
+
* Ping comments are SSE comments in the format `:ping`
|
|
28
|
+
*
|
|
29
|
+
* @param {string} eventData - Raw event data
|
|
30
|
+
* @returns {boolean} - True if this is a ping comment
|
|
31
|
+
*/
|
|
32
|
+
const isPingComment = eventData => {
|
|
33
|
+
const trimmed = eventData.trim();
|
|
34
|
+
return trimmed.startsWith(PING_COMMENT);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Parse a single SSE event from raw event data.
|
|
39
|
+
* Follows the Server-Sent Events specification (https://html.spec.whatwg.org/multipage/server-sent-events.html)
|
|
40
|
+
*
|
|
41
|
+
* @param {string} eventData - Raw event data (multi-line string containing SSE fields)
|
|
42
|
+
* @returns {Object|null} - Parsed SSE event with structure { type, data, id } or null if invalid
|
|
43
|
+
*/
|
|
44
|
+
const parseEventFromBuffer = eventData => {
|
|
45
|
+
const lines = eventData.split(LINE_ENDING_REGEX);
|
|
46
|
+
const parsedEvent = {};
|
|
47
|
+
for (const line of lines) {
|
|
48
|
+
const trimmedLine = line.trim();
|
|
49
|
+
if (!trimmedLine) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const colonIndex = trimmedLine.indexOf(":");
|
|
53
|
+
if (colonIndex === -1) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const field = trimmedLine.substring(0, colonIndex).trim();
|
|
57
|
+
const value = trimmedLine.substring(colonIndex + 1).trim();
|
|
58
|
+
if (field === "data") {
|
|
59
|
+
parsedEvent.data = (parsedEvent.data || "") + value;
|
|
60
|
+
} else if (field === "event") {
|
|
61
|
+
parsedEvent.type = value;
|
|
62
|
+
} else if (field === "id") {
|
|
63
|
+
parsedEvent.id = value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return parsedEvent.data ? parsedEvent : null;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Parse SSE stream using callbacks.
|
|
71
|
+
* Uses modern async iteration (for await...of) for clean, performant stream processing.
|
|
72
|
+
*
|
|
73
|
+
* @param {ReadableStream} stream - The readable stream from fetch response
|
|
74
|
+
* @param {Object} callbacks - Callback functions for stream events
|
|
75
|
+
* @param {Function} callbacks.onEvent - Callback function called for each parsed event
|
|
76
|
+
* @param {Function} callbacks.onPing - Callback function called for ping comments
|
|
77
|
+
* @param {Function} callbacks.onComplete - Callback function called when stream ends
|
|
78
|
+
*/
|
|
79
|
+
return async (stream, {
|
|
80
|
+
onEvent,
|
|
81
|
+
onPing,
|
|
82
|
+
onComplete
|
|
83
|
+
}) => {
|
|
84
|
+
const decoder = new TextDecoder(ENCODING);
|
|
85
|
+
let buffer = "";
|
|
86
|
+
try {
|
|
87
|
+
for await (const chunk of stream) {
|
|
88
|
+
buffer += decoder.decode(chunk, {
|
|
89
|
+
stream: true
|
|
90
|
+
});
|
|
91
|
+
const events = buffer.split(EVENT_SEPARATOR_REGEX);
|
|
92
|
+
buffer = events.pop() || "";
|
|
93
|
+
for (const event of events) {
|
|
94
|
+
const trimmedEvent = event.trim();
|
|
95
|
+
if (!trimmedEvent) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (isPingComment(trimmedEvent)) {
|
|
99
|
+
onPing();
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const parsedEvent = parseEventFromBuffer(trimmedEvent);
|
|
103
|
+
if (parsedEvent !== null) {
|
|
104
|
+
onEvent(parsedEvent);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const trimmedBuffer = buffer.trim();
|
|
109
|
+
if (!trimmedBuffer) {
|
|
110
|
+
onComplete();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (isPingComment(trimmedBuffer)) {
|
|
114
|
+
onPing();
|
|
115
|
+
onComplete();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const event = parseEventFromBuffer(trimmedBuffer);
|
|
119
|
+
if (event !== null) {
|
|
120
|
+
onEvent(event);
|
|
121
|
+
}
|
|
122
|
+
onComplete();
|
|
123
|
+
} catch (error) {
|
|
124
|
+
onEvent({
|
|
125
|
+
error
|
|
126
|
+
});
|
|
127
|
+
onComplete();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
exports.default = _default;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
/*
|
|
5
|
+
Copyright 2025 Adobe. All rights reserved.
|
|
6
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Creates a wrapper around a callback that implements a rolling timeout.
|
|
17
|
+
* The timeout resets on every data event or ping. If no activity occurs
|
|
18
|
+
* within the timeout period, an error is passed to the callback.
|
|
19
|
+
* After timeout fires, all subsequent calls are ignored.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} options - Configuration options
|
|
22
|
+
* @param {Function} options.onStreamResponseCallback - The callback function to wrap
|
|
23
|
+
* @param {number} options.streamTimeout - Timeout duration in milliseconds
|
|
24
|
+
* @returns {Object} Object with onEvent, onPing, and onComplete handler functions
|
|
25
|
+
*/
|
|
26
|
+
var _default = ({
|
|
27
|
+
onStreamResponseCallback,
|
|
28
|
+
streamTimeout
|
|
29
|
+
}) => {
|
|
30
|
+
let timedOut = false;
|
|
31
|
+
let timeoutId;
|
|
32
|
+
const resetTimeout = () => {
|
|
33
|
+
clearTimeout(timeoutId);
|
|
34
|
+
timeoutId = setTimeout(() => {
|
|
35
|
+
timedOut = true;
|
|
36
|
+
onStreamResponseCallback({
|
|
37
|
+
error: {
|
|
38
|
+
message: "Stream timeout: No data received within 10 seconds"
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}, streamTimeout);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Start initial timeout
|
|
45
|
+
resetTimeout();
|
|
46
|
+
return {
|
|
47
|
+
/**
|
|
48
|
+
* Handle data events from the stream parser.
|
|
49
|
+
* Resets the timeout and forwards the event to the callback.
|
|
50
|
+
*
|
|
51
|
+
* @param {Object} event - The parsed SSE event
|
|
52
|
+
*/
|
|
53
|
+
onEvent: event => {
|
|
54
|
+
if (timedOut) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
resetTimeout();
|
|
58
|
+
onStreamResponseCallback(event);
|
|
59
|
+
},
|
|
60
|
+
/**
|
|
61
|
+
* Handle ping events from the stream parser.
|
|
62
|
+
* Resets the timeout but does not forward anything to the callback.
|
|
63
|
+
*/
|
|
64
|
+
onPing: () => {
|
|
65
|
+
if (timedOut) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
resetTimeout();
|
|
69
|
+
},
|
|
70
|
+
/**
|
|
71
|
+
* Handle stream completion.
|
|
72
|
+
* Clears the timeout since the stream has ended successfully.
|
|
73
|
+
*/
|
|
74
|
+
onComplete: () => {
|
|
75
|
+
clearTimeout(timeoutId);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
exports.default = _default;
|