@moneylion/react-native-offer-carousel 1.9.0 → 1.9.1
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/CHANGELOG.md +6 -0
- package/lib/commonjs/apiEnvironment.js +1 -7
- package/lib/commonjs/apiEnvironment.js.map +1 -1
- package/lib/commonjs/components/MoneyLionOfferCarousel.js +3 -8
- package/lib/commonjs/components/MoneyLionOfferCarousel.js.map +1 -1
- package/lib/commonjs/pageData.js +1 -12
- package/lib/commonjs/pageData.js.map +1 -1
- package/lib/commonjs/services/getDynamicOffers.js +1 -2
- package/lib/commonjs/services/getDynamicOffers.js.map +1 -1
- package/lib/commonjs/services/getProductTypes.js +3 -22
- package/lib/commonjs/services/getProductTypes.js.map +1 -1
- package/lib/commonjs/utils/index.js +0 -11
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/resolveProductTypes.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/apiEnvironment.js +0 -5
- package/lib/module/apiEnvironment.js.map +1 -1
- package/lib/module/components/MoneyLionOfferCarousel.js +3 -8
- package/lib/module/components/MoneyLionOfferCarousel.js.map +1 -1
- package/lib/module/pageData.js +1 -11
- package/lib/module/pageData.js.map +1 -1
- package/lib/module/services/getDynamicOffers.js +2 -3
- package/lib/module/services/getDynamicOffers.js.map +1 -1
- package/lib/module/services/getProductTypes.js +3 -22
- package/lib/module/services/getProductTypes.js.map +1 -1
- package/lib/module/utils/index.js +0 -1
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/resolveProductTypes.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/src/apiEnvironment.d.ts +0 -4
- package/lib/typescript/src/apiEnvironment.d.ts.map +1 -1
- package/lib/typescript/src/components/MoneyLionOfferCarousel.d.ts +0 -2
- package/lib/typescript/src/components/MoneyLionOfferCarousel.d.ts.map +1 -1
- package/lib/typescript/src/pageData.d.ts +0 -2
- package/lib/typescript/src/pageData.d.ts.map +1 -1
- package/lib/typescript/src/services/getDynamicOffers.d.ts +3 -4
- package/lib/typescript/src/services/getDynamicOffers.d.ts.map +1 -1
- package/lib/typescript/src/services/getProductTypes.d.ts +2 -7
- package/lib/typescript/src/services/getProductTypes.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +0 -1
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/resolveProductTypes.d.ts +0 -5
- package/lib/typescript/src/utils/resolveProductTypes.d.ts.map +1 -1
- package/lib/typescript/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/apiEnvironment.ts +0 -6
- package/src/components/MoneyLionOfferCarousel.tsx +2 -11
- package/src/pageData.ts +2 -20
- package/src/services/getDynamicOffers.ts +4 -21
- package/src/services/getProductTypes.ts +5 -28
- package/src/utils/index.ts +0 -1
- package/src/utils/resolveProductTypes.ts +0 -5
- package/src/version.ts +1 -1
- package/lib/commonjs/capabilities/core/src/domain/third-party-search/index.js +0 -17
- package/lib/commonjs/capabilities/core/src/domain/third-party-search/index.js.map +0 -1
- package/lib/commonjs/capabilities/core/src/domain/third-party-search/orderProductTypesByRankUtils.js +0 -33
- package/lib/commonjs/capabilities/core/src/domain/third-party-search/orderProductTypesByRankUtils.js.map +0 -1
- package/lib/commonjs/services/getProductTypesByQuery.js +0 -72
- package/lib/commonjs/services/getProductTypesByQuery.js.map +0 -1
- package/lib/commonjs/utils/selectDynamicOffers.js +0 -13
- package/lib/commonjs/utils/selectDynamicOffers.js.map +0 -1
- package/lib/module/capabilities/core/src/domain/third-party-search/index.js +0 -2
- package/lib/module/capabilities/core/src/domain/third-party-search/index.js.map +0 -1
- package/lib/module/capabilities/core/src/domain/third-party-search/orderProductTypesByRankUtils.js +0 -26
- package/lib/module/capabilities/core/src/domain/third-party-search/orderProductTypesByRankUtils.js.map +0 -1
- package/lib/module/services/getProductTypesByQuery.js +0 -65
- package/lib/module/services/getProductTypesByQuery.js.map +0 -1
- package/lib/module/utils/selectDynamicOffers.js +0 -6
- package/lib/module/utils/selectDynamicOffers.js.map +0 -1
- package/lib/typescript/src/capabilities/core/src/domain/third-party-search/index.d.ts +0 -2
- package/lib/typescript/src/capabilities/core/src/domain/third-party-search/index.d.ts.map +0 -1
- package/lib/typescript/src/capabilities/core/src/domain/third-party-search/orderProductTypesByRankUtils.d.ts +0 -19
- package/lib/typescript/src/capabilities/core/src/domain/third-party-search/orderProductTypesByRankUtils.d.ts.map +0 -1
- package/lib/typescript/src/services/getProductTypesByQuery.d.ts +0 -30
- package/lib/typescript/src/services/getProductTypesByQuery.d.ts.map +0 -1
- package/lib/typescript/src/utils/selectDynamicOffers.d.ts +0 -3
- package/lib/typescript/src/utils/selectDynamicOffers.d.ts.map +0 -1
- package/src/capabilities/core/src/domain/third-party-search/index.ts +0 -1
- package/src/capabilities/core/src/domain/third-party-search/orderProductTypesByRankUtils.ts +0 -33
- package/src/services/getProductTypesByQuery.ts +0 -76
- package/src/utils/selectDynamicOffers.ts +0 -17
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.selectDynamicOffers = void 0;
|
|
7
|
-
var _sortOffersByRecommendationScore = require("./sortOffersByRecommendationScore");
|
|
8
|
-
const selectDynamicOffers = (offers, productTypes) => {
|
|
9
|
-
const resultOffers = productTypes.flatMap(productType => (0, _sortOffersByRecommendationScore.sortOffersByRecommendationScore)(offers.filter(offer => offer.productType === productType))).slice(0, 10);
|
|
10
|
-
return resultOffers;
|
|
11
|
-
};
|
|
12
|
-
exports.selectDynamicOffers = selectDynamicOffers;
|
|
13
|
-
//# sourceMappingURL=selectDynamicOffers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_sortOffersByRecommendationScore","require","selectDynamicOffers","offers","productTypes","resultOffers","flatMap","productType","sortOffersByRecommendationScore","filter","offer","slice","exports"],"sourceRoot":"../../../src","sources":["utils/selectDynamicOffers.ts"],"mappings":";;;;;;AACA,IAAAA,gCAAA,GAAAC,OAAA;AAEO,MAAMC,mBAAmB,GAAGA,CAClCC,MAAmB,EACnBC,YAAsB,KAClB;EACJ,MAAMC,YAAY,GAAGD,YAAY,CAC/BE,OAAO,CAAEC,WAAW,IACpB,IAAAC,gEAA+B,EAC9BL,MAAM,CAACM,MAAM,CAAEC,KAAK,IAAKA,KAAK,CAACH,WAAW,KAAKA,WAAW,CAC3D,CACD,CAAC,CACAI,KAAK,CAAC,CAAC,EAAE,EAAE,CAAgB;EAE7B,OAAON,YAAY;AACpB,CAAC;AAACO,OAAA,CAAAV,mBAAA,GAAAA,mBAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../../../../../src","sources":["capabilities/core/src/domain/third-party-search/index.ts"],"mappings":"AAAA,cAAc,gCAAgC","ignoreList":[]}
|
package/lib/module/capabilities/core/src/domain/third-party-search/orderProductTypesByRankUtils.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Orders product types by rank.
|
|
3
|
-
*
|
|
4
|
-
* @param productTypes {Record<string, number>} - The product types to order.
|
|
5
|
-
* @returns {string[]} The product types ordered by rank.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* const productTypes = {
|
|
10
|
-
* 'credit-card': 1,
|
|
11
|
-
* 'loan': 2,
|
|
12
|
-
* 'insurance': 3,
|
|
13
|
-
* }
|
|
14
|
-
* const orderedProductTypes = orderProductTypesByRank(productTypes)
|
|
15
|
-
* // orderedProductTypes = ['insurance', 'loan', 'credit-card']
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export const orderProductTypesByRank = productTypes => {
|
|
19
|
-
const productTypesWithRank = Object.entries(productTypes).map(([productType, count]) => ({
|
|
20
|
-
productType,
|
|
21
|
-
rank: count
|
|
22
|
-
}));
|
|
23
|
-
const sortedProductTypes = productTypesWithRank.sort((a, b) => b.rank - a.rank);
|
|
24
|
-
return sortedProductTypes.map(pt => pt.productType);
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=orderProductTypesByRankUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["orderProductTypesByRank","productTypes","productTypesWithRank","Object","entries","map","productType","count","rank","sortedProductTypes","sort","a","b","pt"],"sourceRoot":"../../../../../../../src","sources":["capabilities/core/src/domain/third-party-search/orderProductTypesByRankUtils.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,uBAAuB,GACnCC,YAAoC,IAChC;EACJ,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,OAAO,CAACH,YAAY,CAAC,CAACI,GAAG,CAC5D,CAAC,CAACC,WAAW,EAAEC,KAAK,CAAC,MAAM;IAC1BD,WAAW;IACXE,IAAI,EAAED;EACP,CAAC,CACF,CAAC;EAED,MAAME,kBAAkB,GAAGP,oBAAoB,CAACQ,IAAI,CACnD,CAACC,CAAC,EAAEC,CAAC,KAAKA,CAAC,CAACJ,IAAI,GAAGG,CAAC,CAACH,IACtB,CAAC;EAED,OAAOC,kBAAkB,CAACJ,GAAG,CAAEQ,EAAE,IAAKA,EAAE,CAACP,WAAW,CAAC;AACtD,CAAC","ignoreList":[]}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { pipe } from "effect";
|
|
2
|
-
import { getEwsSearchApiBaseUrl } from "../apiEnvironment";
|
|
3
|
-
import { orderProductTypesByRank } from "../capabilities/core/src/domain/third-party-search";
|
|
4
|
-
import { ErrorCodes } from "../capabilities/errors/types";
|
|
5
|
-
import { getApiErrorLogProperties } from "../components/utils/errorUtils";
|
|
6
|
-
/**
|
|
7
|
-
* Get product types by query
|
|
8
|
-
* @param query {string} - The query to get the product types for
|
|
9
|
-
* @param context The context to get the product types from
|
|
10
|
-
* @returns {Promise<string[]>} The product types
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* const productTypes = await getProductTypesByQuery('best credit cards', {
|
|
15
|
-
* cnfEnv: {
|
|
16
|
-
* THIRD_PARTY_SEARCH_API_URL: 'https://api.third-party-search.com',
|
|
17
|
-
* THIRD_PARTY_SEARCH_API_TOKEN: 'your-token',
|
|
18
|
-
* },
|
|
19
|
-
* thirdPartySearchApiClient: makeThirdPartySearchApiClient,
|
|
20
|
-
* })
|
|
21
|
-
* // productTypes = ['credit-card', 'loan', 'insurance']
|
|
22
|
-
* or
|
|
23
|
-
* // productTypes = []
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
export const getProductTypesByQuery = async ({
|
|
28
|
-
query,
|
|
29
|
-
searchAPIToken,
|
|
30
|
-
isDev,
|
|
31
|
-
onError
|
|
32
|
-
}) => {
|
|
33
|
-
const url = `${getEwsSearchApiBaseUrl(isDev)}/search/product-types?query=${encodeURIComponent(query)}`;
|
|
34
|
-
const headers = {
|
|
35
|
-
Authorization: `Bearer ${searchAPIToken}`
|
|
36
|
-
};
|
|
37
|
-
try {
|
|
38
|
-
const response = await fetch(url, {
|
|
39
|
-
headers
|
|
40
|
-
});
|
|
41
|
-
if (!response.ok) {
|
|
42
|
-
const error = new Error();
|
|
43
|
-
error.code = response.status;
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
const productTypes = await response.json();
|
|
47
|
-
return pipe(productTypes, orderProductTypesByRank);
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error("Error fetching ProductTypesByQuery", JSON.stringify(error));
|
|
50
|
-
onError === null || onError === void 0 || onError({
|
|
51
|
-
message: "Failed to fetch product types by query",
|
|
52
|
-
error,
|
|
53
|
-
additionalInfo: {
|
|
54
|
-
query,
|
|
55
|
-
isDev
|
|
56
|
-
},
|
|
57
|
-
...(getApiErrorLogProperties(error) || {
|
|
58
|
-
code: ErrorCodes.FLOW_ERROR,
|
|
59
|
-
severity: "error"
|
|
60
|
-
})
|
|
61
|
-
});
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
//# sourceMappingURL=getProductTypesByQuery.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["pipe","getEwsSearchApiBaseUrl","orderProductTypesByRank","ErrorCodes","getApiErrorLogProperties","getProductTypesByQuery","query","searchAPIToken","isDev","onError","url","encodeURIComponent","headers","Authorization","response","fetch","ok","error","Error","code","status","productTypes","json","console","JSON","stringify","message","additionalInfo","FLOW_ERROR","severity"],"sourceRoot":"../../../src","sources":["services/getProductTypesByQuery.ts"],"mappings":"AAAA,SAASA,IAAI,QAAQ,QAAQ;AAC7B,SAASC,sBAAsB,QAAQ,mBAAmB;AAC1D,SAASC,uBAAuB,QAAQ,oDAAoD;AAC5F,SACCC,UAAU,QAGJ,8BAA8B;AACrC,SAASC,wBAAwB,QAAQ,gCAAgC;AASzE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMC,sBAAsB,GAAG,MAAAA,CAAO;EAC5CC,KAAK;EACLC,cAAc;EACdC,KAAK;EACLC;AAC4B,CAAC,KAAK;EAClC,MAAMC,GAAG,GAAG,GAAGT,sBAAsB,CAACO,KAAK,CAAC,+BAA+BG,kBAAkB,CAACL,KAAK,CAAC,EAAE;EACtG,MAAMM,OAAO,GAAG;IACfC,aAAa,EAAE,UAAUN,cAAc;EACxC,CAAC;EACD,IAAI;IACH,MAAMO,QAAQ,GAAG,MAAMC,KAAK,CAACL,GAAG,EAAE;MAAEE;IAAQ,CAAC,CAAC;IAC9C,IAAI,CAACE,QAAQ,CAACE,EAAE,EAAE;MACjB,MAAMC,KAAK,GAAG,IAAIC,KAAK,CAAC,CAAa;MACrCD,KAAK,CAACE,IAAI,GAAGL,QAAQ,CAACM,MAAM;MAC5B,MAAMH,KAAK;IACZ;IACA,MAAMI,YAAY,GAAG,MAAMP,QAAQ,CAACQ,IAAI,CAAC,CAAC;IAE1C,OAAOtB,IAAI,CAACqB,YAAY,EAAEnB,uBAAuB,CAAC;EACnD,CAAC,CAAC,OAAOe,KAAK,EAAE;IACfM,OAAO,CAACN,KAAK,CAAC,oCAAoC,EAAEO,IAAI,CAACC,SAAS,CAACR,KAAK,CAAC,CAAC;IAC1ER,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAG;MACTiB,OAAO,EAAE,wCAAwC;MACjDT,KAAK;MACLU,cAAc,EAAE;QACfrB,KAAK;QACLE;MACD,CAAC;MACD,IAAIJ,wBAAwB,CAACa,KAAK,CAAC,IAAI;QACtCE,IAAI,EAAEhB,UAAU,CAACyB,UAAU;QAC3BC,QAAQ,EAAE;MACX,CAAC;IACF,CAAC,CAAC;IAEF,OAAO,EAAE;EACV;AACD,CAAC","ignoreList":[]}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { sortOffersByRecommendationScore } from "./sortOffersByRecommendationScore";
|
|
2
|
-
export const selectDynamicOffers = (offers, productTypes) => {
|
|
3
|
-
const resultOffers = productTypes.flatMap(productType => sortOffersByRecommendationScore(offers.filter(offer => offer.productType === productType))).slice(0, 10);
|
|
4
|
-
return resultOffers;
|
|
5
|
-
};
|
|
6
|
-
//# sourceMappingURL=selectDynamicOffers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["sortOffersByRecommendationScore","selectDynamicOffers","offers","productTypes","resultOffers","flatMap","productType","filter","offer","slice"],"sourceRoot":"../../../src","sources":["utils/selectDynamicOffers.ts"],"mappings":"AACA,SAASA,+BAA+B,QAAQ,mCAAmC;AAEnF,OAAO,MAAMC,mBAAmB,GAAGA,CAClCC,MAAmB,EACnBC,YAAsB,KAClB;EACJ,MAAMC,YAAY,GAAGD,YAAY,CAC/BE,OAAO,CAAEC,WAAW,IACpBN,+BAA+B,CAC9BE,MAAM,CAACK,MAAM,CAAEC,KAAK,IAAKA,KAAK,CAACF,WAAW,KAAKA,WAAW,CAC3D,CACD,CAAC,CACAG,KAAK,CAAC,CAAC,EAAE,EAAE,CAAgB;EAE7B,OAAOL,YAAY;AACpB,CAAC","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../src/capabilities/core/src/domain/third-party-search/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Orders product types by rank.
|
|
3
|
-
*
|
|
4
|
-
* @param productTypes {Record<string, number>} - The product types to order.
|
|
5
|
-
* @returns {string[]} The product types ordered by rank.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* const productTypes = {
|
|
10
|
-
* 'credit-card': 1,
|
|
11
|
-
* 'loan': 2,
|
|
12
|
-
* 'insurance': 3,
|
|
13
|
-
* }
|
|
14
|
-
* const orderedProductTypes = orderProductTypesByRank(productTypes)
|
|
15
|
-
* // orderedProductTypes = ['insurance', 'loan', 'credit-card']
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare const orderProductTypesByRank: (productTypes: Record<string, number>) => string[];
|
|
19
|
-
//# sourceMappingURL=orderProductTypesByRankUtils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"orderProductTypesByRankUtils.d.ts","sourceRoot":"","sources":["../../../../../../../../src/capabilities/core/src/domain/third-party-search/orderProductTypesByRankUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,uBAAuB,GACnC,cAAc,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,aAcpC,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { type InternalOnErrorCallback } from "../capabilities/errors/types";
|
|
2
|
-
type GetProductTypesByQueryProps = {
|
|
3
|
-
query: string;
|
|
4
|
-
searchAPIToken: string;
|
|
5
|
-
isDev: boolean;
|
|
6
|
-
onError?: InternalOnErrorCallback;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Get product types by query
|
|
10
|
-
* @param query {string} - The query to get the product types for
|
|
11
|
-
* @param context The context to get the product types from
|
|
12
|
-
* @returns {Promise<string[]>} The product types
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* const productTypes = await getProductTypesByQuery('best credit cards', {
|
|
17
|
-
* cnfEnv: {
|
|
18
|
-
* THIRD_PARTY_SEARCH_API_URL: 'https://api.third-party-search.com',
|
|
19
|
-
* THIRD_PARTY_SEARCH_API_TOKEN: 'your-token',
|
|
20
|
-
* },
|
|
21
|
-
* thirdPartySearchApiClient: makeThirdPartySearchApiClient,
|
|
22
|
-
* })
|
|
23
|
-
* // productTypes = ['credit-card', 'loan', 'insurance']
|
|
24
|
-
* or
|
|
25
|
-
* // productTypes = []
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export declare const getProductTypesByQuery: ({ query, searchAPIToken, isDev, onError, }: GetProductTypesByQueryProps) => Promise<string[]>;
|
|
29
|
-
export {};
|
|
30
|
-
//# sourceMappingURL=getProductTypesByQuery.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getProductTypesByQuery.d.ts","sourceRoot":"","sources":["../../../../src/services/getProductTypesByQuery.ts"],"names":[],"mappings":"AAGA,OAAO,EAGN,KAAK,uBAAuB,EAC5B,MAAM,8BAA8B,CAAC;AAGtC,KAAK,2BAA2B,GAAG;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,uBAAuB,CAAC;CAClC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,eAAO,MAAM,sBAAsB,GAAU,4CAK1C,2BAA2B,sBAgC7B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selectDynamicOffers.d.ts","sourceRoot":"","sources":["../../../../src/utils/selectDynamicOffers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAGnE,eAAO,MAAM,mBAAmB,GAC/B,QAAQ,SAAS,EAAE,EACnB,cAAc,MAAM,EAAE,gBAWtB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./orderProductTypesByRankUtils";
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Orders product types by rank.
|
|
3
|
-
*
|
|
4
|
-
* @param productTypes {Record<string, number>} - The product types to order.
|
|
5
|
-
* @returns {string[]} The product types ordered by rank.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* const productTypes = {
|
|
10
|
-
* 'credit-card': 1,
|
|
11
|
-
* 'loan': 2,
|
|
12
|
-
* 'insurance': 3,
|
|
13
|
-
* }
|
|
14
|
-
* const orderedProductTypes = orderProductTypesByRank(productTypes)
|
|
15
|
-
* // orderedProductTypes = ['insurance', 'loan', 'credit-card']
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export const orderProductTypesByRank = (
|
|
19
|
-
productTypes: Record<string, number>
|
|
20
|
-
) => {
|
|
21
|
-
const productTypesWithRank = Object.entries(productTypes).map(
|
|
22
|
-
([productType, count]) => ({
|
|
23
|
-
productType,
|
|
24
|
-
rank: count as number,
|
|
25
|
-
})
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
const sortedProductTypes = productTypesWithRank.sort(
|
|
29
|
-
(a, b) => b.rank - a.rank
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
return sortedProductTypes.map((pt) => pt.productType);
|
|
33
|
-
};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { pipe } from "effect";
|
|
2
|
-
import { getEwsSearchApiBaseUrl } from "../apiEnvironment";
|
|
3
|
-
import { orderProductTypesByRank } from "../capabilities/core/src/domain/third-party-search";
|
|
4
|
-
import {
|
|
5
|
-
ErrorCodes,
|
|
6
|
-
type ApiError,
|
|
7
|
-
type InternalOnErrorCallback,
|
|
8
|
-
} from "../capabilities/errors/types";
|
|
9
|
-
import { getApiErrorLogProperties } from "../components/utils/errorUtils";
|
|
10
|
-
|
|
11
|
-
type GetProductTypesByQueryProps = {
|
|
12
|
-
query: string;
|
|
13
|
-
searchAPIToken: string;
|
|
14
|
-
isDev: boolean;
|
|
15
|
-
onError?: InternalOnErrorCallback;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Get product types by query
|
|
20
|
-
* @param query {string} - The query to get the product types for
|
|
21
|
-
* @param context The context to get the product types from
|
|
22
|
-
* @returns {Promise<string[]>} The product types
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* const productTypes = await getProductTypesByQuery('best credit cards', {
|
|
27
|
-
* cnfEnv: {
|
|
28
|
-
* THIRD_PARTY_SEARCH_API_URL: 'https://api.third-party-search.com',
|
|
29
|
-
* THIRD_PARTY_SEARCH_API_TOKEN: 'your-token',
|
|
30
|
-
* },
|
|
31
|
-
* thirdPartySearchApiClient: makeThirdPartySearchApiClient,
|
|
32
|
-
* })
|
|
33
|
-
* // productTypes = ['credit-card', 'loan', 'insurance']
|
|
34
|
-
* or
|
|
35
|
-
* // productTypes = []
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
export const getProductTypesByQuery = async ({
|
|
40
|
-
query,
|
|
41
|
-
searchAPIToken,
|
|
42
|
-
isDev,
|
|
43
|
-
onError,
|
|
44
|
-
}: GetProductTypesByQueryProps) => {
|
|
45
|
-
const url = `${getEwsSearchApiBaseUrl(isDev)}/search/product-types?query=${encodeURIComponent(query)}`;
|
|
46
|
-
const headers = {
|
|
47
|
-
Authorization: `Bearer ${searchAPIToken}`,
|
|
48
|
-
};
|
|
49
|
-
try {
|
|
50
|
-
const response = await fetch(url, { headers });
|
|
51
|
-
if (!response.ok) {
|
|
52
|
-
const error = new Error() as ApiError;
|
|
53
|
-
error.code = response.status;
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
const productTypes = await response.json();
|
|
57
|
-
|
|
58
|
-
return pipe(productTypes, orderProductTypesByRank);
|
|
59
|
-
} catch (error) {
|
|
60
|
-
console.error("Error fetching ProductTypesByQuery", JSON.stringify(error));
|
|
61
|
-
onError?.({
|
|
62
|
-
message: "Failed to fetch product types by query",
|
|
63
|
-
error,
|
|
64
|
-
additionalInfo: {
|
|
65
|
-
query,
|
|
66
|
-
isDev,
|
|
67
|
-
},
|
|
68
|
-
...(getApiErrorLogProperties(error) || {
|
|
69
|
-
code: ErrorCodes.FLOW_ERROR,
|
|
70
|
-
severity: "error",
|
|
71
|
-
}),
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
return [];
|
|
75
|
-
}
|
|
76
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { BaseOffer } from "../capabilities/offer-catalog/src";
|
|
2
|
-
import { sortOffersByRecommendationScore } from "./sortOffersByRecommendationScore";
|
|
3
|
-
|
|
4
|
-
export const selectDynamicOffers = (
|
|
5
|
-
offers: BaseOffer[],
|
|
6
|
-
productTypes: string[]
|
|
7
|
-
) => {
|
|
8
|
-
const resultOffers = productTypes
|
|
9
|
-
.flatMap((productType) =>
|
|
10
|
-
sortOffersByRecommendationScore(
|
|
11
|
-
offers.filter((offer) => offer.productType === productType)
|
|
12
|
-
)
|
|
13
|
-
)
|
|
14
|
-
.slice(0, 10) as BaseOffer[];
|
|
15
|
-
|
|
16
|
-
return resultOffers;
|
|
17
|
-
};
|