@typexim/aics-embed-sdk 0.0.4-alpha.3

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/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # TypeX Embed SDK
2
+
3
+ ## 调用方式
4
+
5
+ ```javascript
6
+ import {
7
+ initialize,
8
+ isLogin,
9
+ subscribe,
10
+ sendMessage,
11
+ } from '@typexim/embed-sdk';
12
+
13
+ initialize();
14
+ isLogin();
15
+
16
+ const unsubscribe = subscribe(SubscribeType.feed, (args) => {
17
+ console.log('feed改变', args);
18
+ });
19
+ unsubscribe();
20
+ sendMessage({
21
+ type: 'text',
22
+ content: '你好22',
23
+ });
24
+ ```
25
+
26
+ ## API清单
27
+
28
+ ### 初始化
29
+
30
+ 1、initialize注意:所有的端内使用方法都必须在initialize之后调用
31
+
32
+ ### 登录状态判断
33
+
34
+ isLogin 1、返回值:boolean 2、说明:判断当前用户是否登录
35
+
36
+ ### 订阅
37
+
38
+ subscribe 1、参数:1.1 type:SubscribeType 1.2 callback:(args: any) => void 2、返回值:unsubscribe:() => void 3、说明:订阅端内事件,事件触发时会调用callback 4、注意:4.2 订阅时需要传入事件类型和回调函数,事件类型可以参考SubscribeType枚举4.3 订阅返回一个unsubscribe函数,调用该函数可以取消订阅
39
+
40
+ ### 发送消息
41
+
42
+ sendMessage 1、参数:1.1 message:Message 2、返回值:void 3、说明:发送一条消息到端内4、注意:4.1 发送消息前需要先调用initialize方法初始化4.2 消息类型可以参考Message枚举
@@ -0,0 +1 @@
1
+ import*as n from"comlink";let t=null;const r=async()=>{try{return t=n.wrap(n.windowEndpoint(window.parent)),!0}catch(n){return console.error("❌ iframe: 连接失败",n),!1}},e=()=>t,o=(t,r)=>{const o=e();if(!o)return()=>{};const i=n.proxy(n=>{r(n)}),s=`${Date.now().toString(36)}-${Math.random().toString(36).substring(2,8)}`;return o.subscribe(t,i,s),()=>{((n,t)=>{const r=e();r&&r.unsubscribe(n,t)})(t,s)}},i=async()=>{const n=e();if(!n)return!1;return await n.isLogin()},s=async n=>{const t=e();if(!t)return!1;return await t.sendMessage(n)};var a,c;!function(n){n.text="text"}(a||(a={})),function(n){n.feed="feed",n.login="login"}(c||(c={}));export{a as MessageType,c as SubscribeType,r as initialize,i as isLogin,s as sendMessage,o as subscribe};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";function e(e){var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,Object.freeze(r)}var r=e(require("comlink"));let t=null;const n=()=>t;var s;exports.MessageType=void 0,(exports.MessageType||(exports.MessageType={})).text="text",exports.SubscribeType=void 0,(s=exports.SubscribeType||(exports.SubscribeType={})).feed="feed",s.login="login",exports.initialize=async()=>{try{return t=r.wrap(r.windowEndpoint(window.parent)),!0}catch(e){return console.error("❌ iframe: 连接失败",e),!1}},exports.isLogin=async()=>{const e=n();if(!e)return!1;return await e.isLogin()},exports.sendMessage=async e=>{const r=n();if(!r)return!1;return await r.sendMessage(e)},exports.subscribe=(e,t)=>{const s=n();if(!s)return()=>{};const o=r.proxy(e=>{t(e)}),i=`${Date.now().toString(36)}-${Math.random().toString(36).substring(2,8)}`;return s.subscribe(e,o,i),()=>{((e,r)=>{const t=n();t&&t.unsubscribe(e,r)})(e,i)}};
@@ -0,0 +1,4 @@
1
+ export { initialize, subscribe } from './init';
2
+ export * from './login';
3
+ export * from './message';
4
+ export * from './types';
@@ -0,0 +1,17 @@
1
+ import * as comlink from 'comlink';
2
+ import { SubscribeType } from '../types';
3
+ /***
4
+ * 初始化连接
5
+ */
6
+ export declare const initialize: () => Promise<boolean>;
7
+ /***
8
+ * 获取连接对象
9
+ */
10
+ export declare const getApi: () => comlink.Remote<any> | null;
11
+ /**
12
+ * 订阅事件
13
+ * @param type
14
+ * @param callback
15
+ * @returns
16
+ */
17
+ export declare const subscribe: (type: SubscribeType, callback: (args?: any) => void) => () => void;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 判断是否在登录态
3
+ * @returns
4
+ */
5
+ export declare const isLogin: () => Promise<boolean>;
@@ -0,0 +1,10 @@
1
+ import { MessageType } from '../types';
2
+ /**
3
+ * 发送消息
4
+ * @param params
5
+ * @returns
6
+ */
7
+ export declare const sendMessage: (params: {
8
+ type: keyof typeof MessageType;
9
+ content: string;
10
+ }) => Promise<boolean>;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 发送消息类型
3
+ */
4
+ export declare enum MessageType {
5
+ text = "text"
6
+ }
7
+ /**
8
+ * 订阅类型
9
+ */
10
+ export declare enum SubscribeType {
11
+ feed = "feed",
12
+ login = "login"
13
+ }
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@typexim/aics-embed-sdk",
3
+ "version": "0.0.4-alpha.3",
4
+ "private": false,
5
+ "license": "UNLICENSED",
6
+ "type": "module",
7
+ "exports": {
8
+ "./package.json": "./package.json",
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/types/index.d.ts",
12
+ "default": "./dist/index.es.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/types/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ }
19
+ },
20
+ "main": "./dist/index.es.js",
21
+ "types": "./dist/types/index.d.ts",
22
+ "scripts": {
23
+ "build": "cross-env MODE=prod rollup -c",
24
+ "dev": "cross-env MODE=dev rollup -c -w",
25
+ "publish": "yarn run build && npm publish"
26
+ },
27
+ "dependencies": {
28
+ "comlink": "4.4.2"
29
+ },
30
+ "devDependencies": {
31
+ "@rollup/plugin-node-resolve": "^16.0.1",
32
+ "@rollup/plugin-terser": "0.4.4",
33
+ "@rollup/plugin-typescript": "12.1.4",
34
+ "@types/crypto-js": "4.2.2",
35
+ "@types/js-cookie": "3.0.6",
36
+ "cross-env": "10.0.0",
37
+ "rollup": "4.50.1",
38
+ "rollup-plugin-delete": "3.0.1"
39
+ },
40
+ "engines": {
41
+ "node": ">=20.0.0"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public",
45
+ "registry": "https://registry.npmjs.org/"
46
+ }
47
+ }
@@ -0,0 +1,39 @@
1
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
2
+ import terser from '@rollup/plugin-terser';
3
+ import typescript from '@rollup/plugin-typescript';
4
+ import { defineConfig } from 'rollup';
5
+ import del from 'rollup-plugin-delete';
6
+
7
+ const IS_BUILD = process.env.MODE === 'prod';
8
+ const IS_DEV = process.env.MODE === 'dev';
9
+
10
+ export default defineConfig({
11
+ input: 'src/index.ts',
12
+ output: [
13
+ {
14
+ format: 'es',
15
+ file: 'dist/index.es.js',
16
+ sourcemap: IS_DEV,
17
+ },
18
+ IS_BUILD && {
19
+ format: 'cjs',
20
+ file: 'dist/index.js',
21
+ sourcemap: IS_DEV,
22
+ },
23
+ ],
24
+ plugins: [
25
+ del({
26
+ targets: 'dist',
27
+ runOnce: true,
28
+ }),
29
+ typescript({
30
+ tsconfig: './tsconfig.json',
31
+ declarationDir: './dist/types',
32
+ sourceMap: IS_DEV,
33
+ declarationMap: IS_DEV,
34
+ }),
35
+ nodeResolve(),
36
+ IS_BUILD && terser(),
37
+ ].filter(Boolean),
38
+ external: [/node_modules/],
39
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["ESNext", "DOM"],
6
+ "module": "ESNext",
7
+ "skipLibCheck": true,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "bundler",
11
+ "isolatedModules": true,
12
+ "moduleDetection": "force",
13
+ "declaration": true,
14
+
15
+ /* Linting */
16
+ "strict": true,
17
+ "noUnusedLocals": true,
18
+ "noUnusedParameters": true,
19
+ "noFallthroughCasesInSwitch": true
20
+ },
21
+ "include": ["src"]
22
+ }