@vroskus/library-crisp 1.0.0 → 1.0.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/.eslintrc ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "root": true,
3
+ "parser": "@typescript-eslint/parser",
4
+ "parserOptions": {
5
+ "requireConfigFile": false,
6
+ "project": ["tsconfig.json"]
7
+ },
8
+ "extends": [
9
+ "airbnb-base",
10
+ "airbnb-typescript",
11
+ "plugin:import/recommended",
12
+ "plugin:@typescript-eslint/eslint-recommended",
13
+ "plugin:@typescript-eslint/recommended",
14
+ "plugin:sort/recommended"
15
+ ],
16
+ "plugins": [
17
+ "@typescript-eslint",
18
+ "import",
19
+ "import-newlines",
20
+ "react",
21
+ "sort"
22
+ ],
23
+ "rules": {
24
+ "complexity": ["error", 5],
25
+ "@typescript-eslint/ban-ts-comment": [1],
26
+ "@typescript-eslint/no-unused-vars": [2],
27
+ "curly": ["error", "all"],
28
+ "import/no-cycle": [0],
29
+ "no-await-in-loop": 0,
30
+ "no-console": "error",
31
+ "no-duplicate-imports": [0],
32
+ "no-loss-of-precision": [0],
33
+ "no-restricted-syntax": 0,
34
+ "no-unreachable-loop": [0],
35
+ "no-useless-backreference": [0],
36
+ "no-unused-private-class-members": [2],
37
+ "padding-line-between-statements": ["error", {
38
+ "blankLine": "always",
39
+ "prev": ["const", "let"],
40
+ "next": "*"
41
+ }, {
42
+ "blankLine": "any",
43
+ "prev": ["const", "let"],
44
+ "next": ["const", "let"]
45
+ }, {
46
+ "blankLine": "always",
47
+ "prev": ["if", "function", "for"],
48
+ "next": "*"
49
+ }, {
50
+ "blankLine": "always",
51
+ "prev": "*",
52
+ "next": "return"
53
+ }],
54
+ "object-curly-newline": ["error", {
55
+ "ObjectExpression": "always",
56
+ "ObjectPattern": "always",
57
+ "ImportDeclaration": "always",
58
+ "ExportDeclaration": "always"
59
+ }],
60
+ "function-call-argument-newline": ["error", "always"],
61
+ "object-property-newline": ["error", {
62
+ "allowMultiplePropertiesPerLine": false
63
+ }],
64
+ "import-newlines/enforce": ["error", {
65
+ "items": 1,
66
+ "forceSingleLine": false
67
+ }],
68
+ "sort/imports": [0],
69
+ "sort/exports": [0]
70
+ },
71
+ "env": {
72
+ "browser": true,
73
+ "node": true,
74
+ "jest": true,
75
+ "es6": true
76
+ }
77
+ }
@@ -0,0 +1,24 @@
1
+ import type { $Config as Config } from './types';
2
+ declare global {
3
+ interface Window {
4
+ $crisp: Array<Array<unknown>>;
5
+ CRISP_WEBSITE_ID: string | void;
6
+ }
7
+ }
8
+ type $User = {
9
+ Name: string;
10
+ Email: string;
11
+ };
12
+ type $Attr = {
13
+ key: string;
14
+ value: string;
15
+ };
16
+ export type $Config = Config;
17
+ declare class CrispService<C extends Config> {
18
+ websiteId: string;
19
+ constructor({ websiteId, }: C);
20
+ init(): void;
21
+ setUser({ Email, Name, }: $User): void;
22
+ setAttr({ key, value, }: $Attr): void;
23
+ }
24
+ export default CrispService;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAwBA,MAAM,YAAY;IAGhB,YAAY,EACV,SAAS,GACP;QACF,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,EAAE,CAAC;IACnC,CAAC;IAED,IAAI;QACF,IAAI,MAAM,IAAI,IAAI,CAAC,SAAS,KAAK,EAAE,EAAE;YACnC,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC;YACnB,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC;YAEzC,MAAM,CAAC,GAAG,QAAQ,CAAC;YACnB,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YAEpC,CAAC,CAAC,GAAG,GAAG,gCAAgC,CAAC;YACzC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC;YACf,CAAC,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;SAClD;IACH,CAAC;IAED,OAAO,CAAC,EACN,KAAK,EACL,IAAI,GACE;QACN,IAAI,MAAM,IAAI,IAAI,CAAC,SAAS,KAAK,EAAE,EAAE;YACnC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC;YACnD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC;SAClD;IACH,CAAC;IAED,OAAO,CAAC,EACN,GAAG,EACH,KAAK,GACC;QACN,IAAI,MAAM,IAAI,IAAI,CAAC,SAAS,KAAK,EAAE,EAAE;YACnC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC/D;IACH,CAAC;CACF;AAED,kBAAe,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type $Config = {
2
+ websiteId: string;
3
+ };
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vroskus/library-crisp",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Crisp",
5
5
  "author": "Vilius Roškus <vilius@regattas.eu>",
6
6
  "license": "MIT",
@@ -9,9 +9,6 @@
9
9
  "url": "git+https://github.com/vroskus/library-crisp.git"
10
10
  },
11
11
  "main": "dist/index.js",
12
- "files": [
13
- "dist/index.js"
14
- ],
15
12
  "scripts": {
16
13
  "postinstall": "npm run build",
17
14
  "build": "tsc",
package/src/index.ts ADDED
@@ -0,0 +1,68 @@
1
+ // Types
2
+ import type {
3
+ $Config as Config,
4
+ } from './types';
5
+
6
+ declare global {
7
+ interface Window {
8
+ $crisp: Array<Array<unknown>>;
9
+ CRISP_WEBSITE_ID: string | void;
10
+ }
11
+ }
12
+
13
+ type $User = {
14
+ Name: string;
15
+ Email: string;
16
+ };
17
+
18
+ type $Attr = {
19
+ key: string;
20
+ value: string;
21
+ };
22
+
23
+ export type $Config = Config;
24
+
25
+ class CrispService<C extends Config> {
26
+ websiteId: string;
27
+
28
+ constructor({
29
+ websiteId,
30
+ }: C) {
31
+ this.websiteId = websiteId || '';
32
+ }
33
+
34
+ init(): void {
35
+ if (window && this.websiteId !== '') {
36
+ window.$crisp = [];
37
+ window.CRISP_WEBSITE_ID = this.websiteId;
38
+
39
+ const d = document;
40
+ const s = d.createElement('script');
41
+
42
+ s.src = 'https://client.crisp.chat/l.js';
43
+ s.async = true;
44
+ d.getElementsByTagName('head')[0].appendChild(s);
45
+ }
46
+ }
47
+
48
+ setUser({
49
+ Email,
50
+ Name,
51
+ }: $User): void {
52
+ if (window && this.websiteId !== '') {
53
+ window.$crisp.push(['set', 'user:nickname', Name]);
54
+ window.$crisp.push(['set', 'user:email', Email]);
55
+ }
56
+ }
57
+
58
+ setAttr({
59
+ key,
60
+ value,
61
+ }: $Attr): void {
62
+ if (window && this.websiteId !== '') {
63
+ window.$crisp.push(['set', 'session:data', [[[key, value]]]]);
64
+ }
65
+ }
66
+ }
67
+
68
+ export default CrispService;
package/src/types.ts ADDED
@@ -0,0 +1,3 @@
1
+ export type $Config = {
2
+ websiteId: string;
3
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./dist/",
4
+ "types": ["node", "jest"],
5
+ "module": "commonjs",
6
+ "esModuleInterop": true,
7
+ "declaration": true,
8
+ "noImplicitAny": false,
9
+ "removeComments": true,
10
+ "noLib": false,
11
+ "emitDecoratorMetadata": true,
12
+ "experimentalDecorators": true,
13
+ "target": "es6",
14
+ "sourceMap": true,
15
+ "lib": [
16
+ "dom",
17
+ "es6"
18
+ ]
19
+ },
20
+ "exclude": [
21
+ "node_modules",
22
+ "./dist/**/*"
23
+ ],
24
+ "include": [
25
+ "./src"
26
+ ]
27
+ }