@telia-ace/knowledge-data-client-flamingo 1.0.62 → 1.1.1-rc.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/.eslintrc.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "extends": ["../../.eslintrc.json"],
3
+ "ignorePatterns": ["!**/*"],
4
+ "overrides": [
5
+ {
6
+ "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7
+ "rules": {}
8
+ },
9
+ {
10
+ "files": ["*.ts", "*.tsx"],
11
+ "rules": {}
12
+ },
13
+ {
14
+ "files": ["*.js", "*.jsx"],
15
+ "rules": {}
16
+ },
17
+ {
18
+ "files": ["*.json"],
19
+ "parser": "jsonc-eslint-parser",
20
+ "rules": {
21
+ "@nx/dependency-checks": [
22
+ "error",
23
+ {
24
+ "ignoredFiles": ["{projectRoot}/vite.config.{js,ts,mjs,mts}"]
25
+ }
26
+ ]
27
+ }
28
+ }
29
+ ]
30
+ }
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # knowledge-data-client
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build knowledge-data-client` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test knowledge-data-client` to execute the unit tests via [Jest](https://jestjs.io).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/knowledge-data-client-flamingo",
3
- "version": "1.0.62",
3
+ "version": "1.1.1-rc.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -8,14 +8,7 @@
8
8
  "@webprovisions/platform": "^1.1.3",
9
9
  "@telia-ace/knowledge-serviceclient": "^1.0.31",
10
10
  "@telia-ace/widget-utilities": "^1.0.16",
11
- "@telia-ace/widget-core": "^1.0.27",
12
- "@telia-ace/widget-runtime-flamingo": "1.0.62",
13
- "@telia-ace/widget-conversation-flamingo": "1.0.62",
14
- "@telia-ace/knowledge-widget-bot-provider-flamingo": "1.0.62",
15
- "@telia-ace/knowledge-data-client-flamingo": "1.0.62",
16
- "@telia-ace/widget-components-copyright-flamingo": "1.0.62",
17
- "@telia-ace/widget-components-list-flamingo": "1.0.62",
18
- "@telia-ace/widget-components-widget-header-flamingo": "1.0.62"
11
+ "@telia-ace/widget-core": "^1.0.27"
19
12
  },
20
13
  "main": "./index.js",
21
14
  "module": "./index.mjs",
package/project.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "data-client",
3
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "libs/data-client/src",
5
+ "projectType": "library",
6
+ "targets": {
7
+ "build": {
8
+ "executor": "@nx/vite:build",
9
+ "outputs": ["{options.outputPath}"],
10
+ "options": {
11
+ "outputPath": "dist/libs/data-client"
12
+ }
13
+ },
14
+ "publish": {
15
+ "executor": "nx:run-commands",
16
+ "options": {
17
+ "command": "npm publish",
18
+ "cwd": "dist/libs/data-client"
19
+ }
20
+ },
21
+ "prerelease": {
22
+ "executor": "nx:run-commands",
23
+ "options": {
24
+ "command": "npm publish --tag=rc",
25
+ "cwd": "dist/libs/data-client"
26
+ }
27
+ },
28
+ "test": {
29
+ "executor": "@nx/vite:test",
30
+ "outputs": ["{options.reportsDirectory}"],
31
+ "options": {
32
+ "passWithNoTests": true,
33
+ "reportsDirectory": "../../coverage/libs/data-client"
34
+ }
35
+ },
36
+ "lint": {
37
+ "executor": "@nx/eslint:lint",
38
+ "outputs": ["{options.outputFile}"],
39
+ "options": {
40
+ "lintFilePatterns": [
41
+ "libs/data-client/**/*.ts",
42
+ "libs/data-client/package.json"
43
+ ]
44
+ }
45
+ }
46
+ },
47
+ "tags": []
48
+ }
@@ -0,0 +1,68 @@
1
+ // import { WidgetSettings } from '@telia-ace/knowledge-widget-core';
2
+ import { Container, Widget } from '@webprovisions/platform';
3
+
4
+ export const createServiceClient = (container: Container) => {
5
+ return import('@telia-ace/knowledge-serviceclient').then(
6
+ ({ ServiceClient, ServiceProxy }) => {
7
+ return container.get('settings').then((settings: any) => {
8
+ const { name, events }: Widget = container.get('$widget');
9
+ const {
10
+ data: { projection = '', site = 'current', forceHttps = false },
11
+ } = settings;
12
+
13
+ const proxy = new ServiceProxy(projection, {
14
+ credentials: 'same-origin',
15
+ });
16
+
17
+ // Replacing '_contact' & '_contact-method' while
18
+ // still using the shadow widget concept
19
+ const client = new ServiceClient(
20
+ proxy,
21
+ {
22
+ funnel: name.replace('_contact-method', '').replace('_contact', ''),
23
+ site: createSiteProvider(site, forceHttps),
24
+ },
25
+ null,
26
+ container
27
+ );
28
+
29
+ events.subscribe('widget:settings-updated', (_event, { data }: any) => {
30
+ if (data && data.projection !== projection) {
31
+ client.proxy.setBaseUrl(data.projection);
32
+ }
33
+ });
34
+
35
+ return client;
36
+ });
37
+ }
38
+ );
39
+ };
40
+
41
+ type SiteLocation = {
42
+ host: string;
43
+ pathname: string;
44
+ };
45
+
46
+ const createSiteProvider = (
47
+ site: 'current' | 'referrer',
48
+ forceHttps: boolean
49
+ ): (() => string) => {
50
+ return () => {
51
+ const parseLocation = (href: string): SiteLocation => {
52
+ const link = document.createElement('a');
53
+ link.href = href;
54
+ return link;
55
+ };
56
+
57
+ let location: SiteLocation = window.location;
58
+ if (site === 'referrer' && document.referrer) {
59
+ location = parseLocation(document.referrer);
60
+ }
61
+ return [
62
+ forceHttps ? 'https:' : '',
63
+ '//',
64
+ location.host,
65
+ location.pathname,
66
+ ].join('');
67
+ };
68
+ };