gemercheung пре 3 година
родитељ
комит
bc18da9cfe

+ 1 - 0
packages/core/package.json

@@ -21,6 +21,7 @@
     "@medici/foo": "workspace:~0.0.1",
     "@medici/types": "workspace:^0.0.1",
     "@medici/utils": "workspace:^0.0.1",
+    "rxjs": "^7.5.6",
     "uuidv4": "^6.2.13"
   },
   "devDependencies": {

+ 20 - 0
packages/core/src/collector.ts

@@ -0,0 +1,20 @@
+import { makeXHRRequest } from './xhr';
+
+export const collect = (type: string, payload: any) => {
+    makeXHRRequest({
+        url: 'xxx',
+        data: {
+            type,
+            payload,
+        },
+    });
+    // if (trackingDisabled()) return;
+    // post(
+    //     `${root}/api/collect`,
+    //     {
+    //         type,
+    //         payload,
+    //     },
+    //     res => (cache = res),
+    // );
+};

+ 19 - 0
packages/core/src/config.ts

@@ -0,0 +1,19 @@
+import { BehaviorSubject } from 'rxjs';
+import { version } from './package.json';
+
+export interface ProjectConfigType {
+    serverUrl: string;
+    appId?: string | number;
+    user?: string;
+    version?: string;
+}
+
+export const projectConfig = new BehaviorSubject<ProjectConfigType>({
+    serverUrl: '',
+    appId: '',
+    version: version,
+});
+
+export function getProjectConfig(): ProjectConfigType {
+    return projectConfig.value;
+}

+ 2 - 3
packages/core/src/event.ts

@@ -1,6 +1,5 @@
 import { GlobalEventType } from '@medici/types';
 
-export function TrackEvent() {
+export function TrackEvent() {}
 
-
-}
+export function trackView() {}

+ 1 - 0
packages/core/src/index.ts

@@ -1 +1,2 @@
+export { init } from './sdk';
 export { TrackEvent } from './event';

+ 4 - 2
packages/core/src/sdk.ts

@@ -1,6 +1,8 @@
 import { getGlobalObject } from '@medici/utils';
+import { projectConfig, ProjectConfigType } from './config';
 
-export function init() {
+export function init(config: ProjectConfigType) {
     const global = getGlobalObject<Window>();
+    console.log('global', global);
+    projectConfig.next(config);
 }
-

+ 11 - 11
packages/core/tsconfig.build.json

@@ -1,11 +1,11 @@
-{
-  "extends": "../../tsconfig.build.json",
-
-  "compilerOptions": {
-    "outDir": "./dist"
-  },
-
-  "include": [
-    "src/**/*"
-  ]
-}
+{
+  "extends": "../../tsconfig.build.json",
+
+  "compilerOptions": {
+    "outDir": "./dist"
+  },
+
+  "include": [
+    "src/**/*"
+  ]
+}

+ 12 - 0
pnpm-lock.yaml

@@ -32,12 +32,14 @@ importers:
       '@medici/types': workspace:^0.0.1
       '@medici/utils': workspace:^0.0.1
       rimraf: ~3.0.2
+      rxjs: ^7.5.6
       typescript: ~4.7.4
       uuidv4: ^6.2.13
     dependencies:
       '@medici/foo': link:../foo
       '@medici/types': link:../types
       '@medici/utils': link:../utils
+      rxjs: 7.5.6
       uuidv4: 6.2.13
     devDependencies:
       rimraf: 3.0.2
@@ -2537,6 +2539,12 @@ packages:
       queue-microtask: 1.2.3
     dev: true
 
+  /rxjs/7.5.6:
+    resolution: {integrity: sha512-dnyv2/YsXhnm461G+R/Pe5bWP41Nm6LBXEYWI6eiFP4fiwx6WRI/CD0zbdVAudd9xwLEF2IDcKXLHit0FYjUzw==}
+    dependencies:
+      tslib: 2.4.0
+    dev: false
+
   /safer-buffer/2.1.2:
     resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==}
     dev: true
@@ -2768,6 +2776,10 @@ packages:
     resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==}
     dev: true
 
+  /tslib/2.4.0:
+    resolution: {integrity: sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==}
+    dev: false
+
   /tsutils/3.21.0_typescript@4.7.4:
     resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==}
     engines: {node: '>= 6'}

+ 20 - 19
tsconfig.build.json

@@ -1,19 +1,20 @@
-{
-  "compilerOptions": {
-    "module": "commonjs",
-    "target": "ES6",
-    "sourceMap": true,
-    "declaration": true,
-    "declarationMap": true,
-    "noEmitOnError": true,
-    "skipLibCheck": true,
-    "esModuleInterop": true,
-    "types": [],
-    "jsx": "react",
-    "noEmit": false
-  },
-  "exclude": [
-    "node_modules",
-    "dist"
-  ]
-}
+{
+  "compilerOptions": {
+    "module": "commonjs",
+    "target": "ES6",
+    "sourceMap": true,
+    "declaration": true,
+    "declarationMap": true,
+    "noEmitOnError": true,
+    "skipLibCheck": true,
+    "esModuleInterop": true,
+    "resolveJsonModule": true,
+    "types": [],
+    "jsx": "react",
+    "noEmit": false
+  },
+  "exclude": [
+    "node_modules",
+    "dist"
+  ]
+}