ha-nitrous-personalization 0.0.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/cjs/components/PersonalizationWidget/PersonalizationWidget.cjs +1 -0
- package/dist/cjs/components/PersonalizationWidget/PersonalizationWidgetItem.cjs +1 -0
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/utils/api.cjs +1 -0
- package/dist/cjs/utils/etc.cjs +1 -0
- package/dist/esm/components/PersonalizationWidget/PersonalizationWidget.js +33 -0
- package/dist/esm/components/PersonalizationWidget/PersonalizationWidgetItem.js +17 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/utils/api.js +24 -0
- package/dist/esm/utils/etc.js +19 -0
- package/dist/types/index.d.ts +49 -0
- package/package.json +52 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("../../utils/api.cjs"),m=require("../../utils/etc.cjs"),i=require("react"),f=require("./PersonalizationWidgetItem.cjs"),z={"recommended-for-you":"user_personalization",trending:"trending_now",ymal:"similar_items"},P=({apiKey:o,brand:s,contentType:n="article",data:t,model:a})=>{const[r,l]=i.useState(void 0);return i.useEffect(()=>{(async()=>{var e;if(t)l(t);else if(n&&a&&o&&s){const d=z[a],c=(e=m.getNitrousCookie())==null?void 0:e.deviceId;if(console.log("fetching data",d,c),c){const u=await g.getPersonalizationData(o,{brand:s,type:n,useCase:d,userId:c});console.log("data",u),t&&l(u)}}})()},[o,t,n,a,s]),i.createElement("div",{"data-id":"personalization-widget"},r==null?void 0:r.data.recommendations.map(e=>i.createElement(f.PersonalizationWidgetItem,{item:e,key:e.id})))};exports.PersonalizationWidget=P;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),o=({item:e})=>{var r,a,n,l;return t.createElement("a",{"data-id":"personalization-item",href:(n=(a=(r=e==null?void 0:e.metadata)==null?void 0:r.links)==null?void 0:a.frontend)==null?void 0:n.url},t.createElement("img",{src:(l=e.media)==null?void 0:l[0].url}),t.createElement("h6",null,e.title),t.createElement("div",null,e.publish_from))};exports.PersonalizationWidgetItem=o;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./components/PersonalizationWidget/PersonalizationWidget.cjs"),t=require("./utils/api.cjs");exports.PersonalizationWidget=e.PersonalizationWidget;exports.getPersonalizationData=t.getPersonalizationData;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=async(a,t)=>{try{if(!t)return;const r=new URLSearchParams(t),e=await(await fetch(`https://ha-personalize-api.kubeprod.hearstapps.com/recommendations?${r.toString()}`,{headers:{"api-key":a},method:"GET"})).json();if(e.error)throw new Error(`Failed to fetch personalization data: ${JSON.stringify(e.error)}`);return e}catch{}};exports.getPersonalizationData=o;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=t=>{var i;const e=`; ${document.cookie}`.split(`; ${t}=`);if(e.length===2)return(i=e.pop())==null?void 0:i.split(";").shift()},r=()=>{const t=n("nit");let o;try{t&&(o=JSON.parse(decodeURIComponent(t)))}catch{}return o};exports.getNitrousCookie=r;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getPersonalizationData as f } from "../../utils/api.js";
|
|
2
|
+
import { getNitrousCookie as g } from "../../utils/etc.js";
|
|
3
|
+
import l, { useState as u, useEffect as p } from "react";
|
|
4
|
+
import { PersonalizationWidgetItem as z } from "./PersonalizationWidgetItem.js";
|
|
5
|
+
const P = {
|
|
6
|
+
"recommended-for-you": "user_personalization",
|
|
7
|
+
trending: "trending_now",
|
|
8
|
+
ymal: "similar_items"
|
|
9
|
+
}, E = ({ apiKey: o, brand: i, contentType: s = "article", data: t, model: a }) => {
|
|
10
|
+
const [r, c] = u(void 0);
|
|
11
|
+
return p(() => {
|
|
12
|
+
(async () => {
|
|
13
|
+
var e;
|
|
14
|
+
if (t)
|
|
15
|
+
c(t);
|
|
16
|
+
else if (s && a && o && i) {
|
|
17
|
+
const m = P[a], n = (e = g()) == null ? void 0 : e.deviceId;
|
|
18
|
+
if (console.log("fetching data", m, n), n) {
|
|
19
|
+
const d = await f(o, {
|
|
20
|
+
brand: i,
|
|
21
|
+
type: s,
|
|
22
|
+
useCase: m,
|
|
23
|
+
userId: n
|
|
24
|
+
});
|
|
25
|
+
console.log("data", d), t && c(d);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
})();
|
|
29
|
+
}, [o, t, s, a, i]), /* @__PURE__ */ l.createElement("div", { "data-id": "personalization-widget" }, r == null ? void 0 : r.data.recommendations.map((e) => /* @__PURE__ */ l.createElement(z, { item: e, key: e.id })));
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
E as PersonalizationWidget
|
|
33
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import r from "react";
|
|
2
|
+
const c = ({ item: e }) => {
|
|
3
|
+
var t, a, l, n;
|
|
4
|
+
return /* @__PURE__ */ r.createElement(
|
|
5
|
+
"a",
|
|
6
|
+
{
|
|
7
|
+
"data-id": "personalization-item",
|
|
8
|
+
href: (l = (a = (t = e == null ? void 0 : e.metadata) == null ? void 0 : t.links) == null ? void 0 : a.frontend) == null ? void 0 : l.url
|
|
9
|
+
},
|
|
10
|
+
/* @__PURE__ */ r.createElement("img", { src: (n = e.media) == null ? void 0 : n[0].url }),
|
|
11
|
+
/* @__PURE__ */ r.createElement("h6", null, e.title),
|
|
12
|
+
/* @__PURE__ */ r.createElement("div", null, e.publish_from)
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
c as PersonalizationWidgetItem
|
|
17
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const n = async (t, e) => {
|
|
2
|
+
try {
|
|
3
|
+
if (!e)
|
|
4
|
+
return;
|
|
5
|
+
const a = new URLSearchParams(e), r = await (await fetch(
|
|
6
|
+
`https://ha-personalize-api.kubeprod.hearstapps.com/recommendations?${a.toString()}`,
|
|
7
|
+
{
|
|
8
|
+
headers: {
|
|
9
|
+
"api-key": t
|
|
10
|
+
},
|
|
11
|
+
method: "GET"
|
|
12
|
+
}
|
|
13
|
+
)).json();
|
|
14
|
+
if (r.error)
|
|
15
|
+
throw new Error(
|
|
16
|
+
`Failed to fetch personalization data: ${JSON.stringify(r.error)}`
|
|
17
|
+
);
|
|
18
|
+
return r;
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
n as getPersonalizationData
|
|
24
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const n = (t) => {
|
|
2
|
+
var i;
|
|
3
|
+
const e = `; ${document.cookie}`.split(`; ${t}=`);
|
|
4
|
+
if (e.length === 2)
|
|
5
|
+
return (i = e.pop()) == null ? void 0 : i.split(";").shift();
|
|
6
|
+
}, r = () => {
|
|
7
|
+
const t = n("nit");
|
|
8
|
+
let o;
|
|
9
|
+
try {
|
|
10
|
+
t && (o = JSON.parse(
|
|
11
|
+
decodeURIComponent(t)
|
|
12
|
+
));
|
|
13
|
+
} catch {
|
|
14
|
+
}
|
|
15
|
+
return o;
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
r as getNitrousCookie
|
|
19
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { FunctionComponent } from 'react';
|
|
2
|
+
|
|
3
|
+
export declare const getPersonalizationData: (apiKey: string, params: GetPersonalizationDataParams) => Promise<GetPersonalizationDataResponse | undefined>;
|
|
4
|
+
|
|
5
|
+
declare type GetPersonalizationDataItem = {
|
|
6
|
+
__typename: 'Content';
|
|
7
|
+
id: string;
|
|
8
|
+
media: {
|
|
9
|
+
url: string;
|
|
10
|
+
}[];
|
|
11
|
+
metadata: {
|
|
12
|
+
dek: string;
|
|
13
|
+
links: {
|
|
14
|
+
frontend: {
|
|
15
|
+
url: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
publish_from: string;
|
|
20
|
+
title: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
declare type GetPersonalizationDataParams = {
|
|
24
|
+
brand: string;
|
|
25
|
+
type: 'article' | 'car' | 'video';
|
|
26
|
+
useCase: PersonalizationUseCase;
|
|
27
|
+
userId: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
declare type GetPersonalizationDataResponse = {
|
|
31
|
+
data: {
|
|
32
|
+
recommendations: GetPersonalizationDataItem[];
|
|
33
|
+
};
|
|
34
|
+
error?: unknown;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
declare type PersonalizationUseCase = 'similar_items' | 'trending_now' | 'user_personalization';
|
|
38
|
+
|
|
39
|
+
export declare const PersonalizationWidget: FunctionComponent<PersonalizationWidgetProps>;
|
|
40
|
+
|
|
41
|
+
declare type PersonalizationWidgetProps = {
|
|
42
|
+
apiKey?: string;
|
|
43
|
+
brand?: string;
|
|
44
|
+
contentType?: GetPersonalizationDataParams['type'];
|
|
45
|
+
data?: GetPersonalizationDataResponse;
|
|
46
|
+
model?: 'recommended-for-you' | 'trending' | 'ymal';
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { }
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"devDependencies": {
|
|
3
|
+
"@types/node": "^22.13.10",
|
|
4
|
+
"@types/react": "~19.0.12",
|
|
5
|
+
"@types/react-dom": "~19.0.4",
|
|
6
|
+
"eslint": "^9.22.0",
|
|
7
|
+
"prettier": "^3.5.3",
|
|
8
|
+
"react": "~19.0.0",
|
|
9
|
+
"react-dom": "~19.0.0",
|
|
10
|
+
"rimraf": "^6.0.1",
|
|
11
|
+
"rollup-plugin-node-externals": "~8.0.0",
|
|
12
|
+
"typescript": "^5.8.2",
|
|
13
|
+
"vite": "^6.2.2",
|
|
14
|
+
"vite-bundle-visualizer": "~1.2.1",
|
|
15
|
+
"vite-plugin-dts": "~4.5.3",
|
|
16
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
17
|
+
"@motortrend/prettier-config-nitrous": "0.0.4",
|
|
18
|
+
"@motortrend/eslint-plugin-nitrous": "0.0.12"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"react": ">=19",
|
|
22
|
+
"react-dom": ">=19"
|
|
23
|
+
},
|
|
24
|
+
"name": "ha-nitrous-personalization",
|
|
25
|
+
"repository": {
|
|
26
|
+
"directory": "packages/nitrous-personalization",
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/motortrend/nitrous-analytics.git"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"main": "./dist/cjs/index.cjs",
|
|
34
|
+
"module": "./dist/esm/index.js",
|
|
35
|
+
"types": "./dist/types/index.d.ts",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./dist/types/index.d.ts",
|
|
39
|
+
"import": "./dist/esm/index.js",
|
|
40
|
+
"require": "./dist/cjs/index.cjs"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"type": "module",
|
|
44
|
+
"version": "0.0.0",
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsc --noEmit && vite build",
|
|
47
|
+
"build:analyze": "vite-bundle-visualizer",
|
|
48
|
+
"clean": "rimraf dist",
|
|
49
|
+
"lint": "eslint --fix .",
|
|
50
|
+
"lint:format": "prettier --write ."
|
|
51
|
+
}
|
|
52
|
+
}
|