@ichinese/open-js-sdk 1.0.0-rc.1 → 1.0.0-rc.2
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 +2 -0
- package/dist/gen/meta.d.ts +1 -1
- package/dist/ichinese-open.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# iChinese Open Platform JS SDK
|
|
2
2
|
|
|
3
|
+
> **Prerelease 1.0.0-rc.2.** 这是预发布版,开放平台还没有正式开放,SDK 的默认地址可能连不上。This is a prerelease: the open platform is not open to the public yet, so the SDK's default address may not answer.
|
|
4
|
+
|
|
3
5
|
爱中文开放平台的网页 JS SDK:应用的网页在桌面端、手机 App 和普通浏览器里用同一套代码登录,并调用容器的方法。
|
|
4
6
|
|
|
5
7
|
The web JS SDK of the iChinese open platform: one set of code for an app's web pages, whether they run in the
|
package/dist/gen/meta.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** The JS SDK's version (it follows the open API's). */
|
|
2
|
-
export declare const VERSION = "1.0.0-rc.
|
|
2
|
+
export declare const VERSION = "1.0.0-rc.2";
|
|
3
3
|
/** The single issuer (the plain-browser fallback signs in there); `config({ issuer })` overrides it. */
|
|
4
4
|
export declare const DEFAULT_ISSUER = "https://id.ichinese.cn";
|
|
5
5
|
/** Where each region's web serves the single-file build of this SDK. */
|
package/dist/ichinese-open.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ichinese=(()=>{var v=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var D=(e,r,n)=>r in e?v(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n;var $=(e,r)=>{for(var n in r)v(e,n,{get:r[n],enumerable:!0})},q=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of L(r))!V.call(e,i)&&i!==n&&v(e,i,{get:()=>r[i],enumerable:!(t=A(r,i))||t.enumerable});return e};var M=e=>q(v({},"__esModule",{value:!0}),e);var g=(e,r,n)=>D(e,typeof r!="symbol"?r+"":r,n);var re={};$(re,{BRIDGE_PROTOCOL:()=>_,BridgeError:()=>d,DEFAULT_ISSUER:()=>y,SCRIPT_URL:()=>P,VERSION:()=>h,_reset:()=>ee,close:()=>Y,config:()=>J,env:()=>B,inContainer:()=>K,on:()=>Z,openExternal:()=>z,ready:()=>f,requestAuthCode:()=>W,setTitle:()=>X,shareToChat:()=>Q});var h="1.0.0-rc.
|
|
1
|
+
"use strict";var ichinese=(()=>{var v=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var D=(e,r,n)=>r in e?v(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n;var $=(e,r)=>{for(var n in r)v(e,n,{get:r[n],enumerable:!0})},q=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of L(r))!V.call(e,i)&&i!==n&&v(e,i,{get:()=>r[i],enumerable:!(t=A(r,i))||t.enumerable});return e};var M=e=>q(v({},"__esModule",{value:!0}),e);var g=(e,r,n)=>D(e,typeof r!="symbol"?r+"":r,n);var re={};$(re,{BRIDGE_PROTOCOL:()=>_,BridgeError:()=>d,DEFAULT_ISSUER:()=>y,SCRIPT_URL:()=>P,VERSION:()=>h,_reset:()=>ee,close:()=>Y,config:()=>J,env:()=>B,inContainer:()=>K,on:()=>Z,openExternal:()=>z,ready:()=>f,requestAuthCode:()=>W,setTitle:()=>X,shareToChat:()=>Q});var h="1.0.0-rc.2",y="https://id.ichinese.cn",P="https://ichinese.cn/open-js-sdk/1/ichinese-open.js",_=1;var d=class extends Error{constructor(n,t){super(t||n);g(this,"code",n);g(this,"name","BridgeError")}},R=()=>typeof window=="undefined"?void 0:window;function b(){var r;let e=(r=R())==null?void 0:r.ichOpenBridge;return e&&typeof e.postMessage=="function"?e:void 0}var x=class{constructor(r){g(this,"bridge",r);g(this,"seq",0);g(this,"pending",new Map);g(this,"listeners",new Map);let n=R();if(!n)return;let t=n.__ichOpenBridgeReceive;n.__ichOpenBridgeReceive=i=>{this.receive(i),t&&t!==n.__ichOpenBridgeReceive&&t(i)}}call(r,n={},t=15e3){let i=`${Date.now().toString(36)}-${(++this.seq).toString(36)}`;return new Promise((c,s)=>{let o=t===null?null:setTimeout(()=>{this.pending.delete(i),s(new d("timeout",`${r}: no answer from the container`))},t);this.pending.set(i,{resolve:c,reject:s,timer:o});try{this.bridge.postMessage(JSON.stringify({v:1,id:i,method:r,params:n}))}catch(p){o&&clearTimeout(o),this.pending.delete(i),s(new d("internal",p.message))}})}on(r,n){let t=this.listeners.get(r);return t||(t=new Set,this.listeners.set(r,t)),t.add(n),()=>t.delete(n)}receive(r){var i,c,s,o,p;let n;try{n=typeof r=="string"?JSON.parse(r):r}catch{return}if(!n||typeof n!="object")return;if(typeof n.event=="string"){for(let w of(i=this.listeners.get(n.event))!=null?i:[])try{w(n.data)}catch{}return}let t=n.id?this.pending.get(n.id):void 0;t&&(this.pending.delete(n.id),t.timer&&clearTimeout(t.timer),n.ok?t.resolve((c=n.result)!=null?c:{}):t.reject(new d((o=(s=n.error)==null?void 0:s.code)!=null?o:"internal",(p=n.error)==null?void 0:p.message)))}};var I="ichopen:oidc:",N=10*6e4,j=new Set(["login_required","consent_required","interaction_required","account_selection_required"]),U=e=>btoa(String.fromCharCode(...e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),E=e=>U(crypto.getRandomValues(new Uint8Array(e)));async function H(e){let r=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(e));return U(new Uint8Array(r))}function O(){try{return window.sessionStorage}catch{return null}}function G(e){for(let r of["code","state","error","error_description","iss","session_state"])e.searchParams.delete(r);try{history.replaceState(history.state,"",e.toString())}catch{}}function T(){let e=new URL(window.location.href),r=e.searchParams.get("state"),n=e.searchParams.get("code"),t=e.searchParams.get("error");if(!r||!n&&!t)return null;let i=O(),c=i==null?void 0:i.getItem(I+r);if(!c)return null;i==null||i.removeItem(I+r),G(e);let s=JSON.parse(c);return Date.now()-s.at>N?{error:"expired"}:n?{ok:{code:n,state:r,redirectUri:s.redirectUri,codeVerifier:s.verifier}}:s.silent&&t&&j.has(t)?{retry:{...s,state:r}}:{error:t!=null?t:"unknown"}}async function S(e,r){let n=O();if(!n)throw new d("unsupported","sessionStorage is not available");let t=E(16),i=E(32);n.setItem(I+t,JSON.stringify({verifier:i,redirectUri:e.redirectUri,appId:e.appId,silent:r,at:Date.now()}));let c=new URLSearchParams({client_id:e.appId,redirect_uri:e.redirectUri,response_type:"code",scope:["openid",...e.scopes.filter(s=>s!=="openid")].join(" "),state:t,nonce:E(16),code_challenge:await H(i),code_challenge_method:"S256",...r?{prompt:"none"}:{},...e.locale?{ui_locales:e.locale}:{}});return window.location.assign(`${e.issuer.replace(/\/$/,"")}/auth?${c}`),new Promise(()=>{})}var u={},a,l,m;function J(e){u={...u,...e}}function k(){var r;let e=typeof matchMedia=="function"&&matchMedia("(prefers-color-scheme: dark)").matches;return{container:"browser",containerVersion:null,locale:typeof navigator!="undefined"&&navigator.language||"en",theme:e?"dark":"light",appId:(r=u.appId)!=null?r:null,sdkVersion:h}}function f(){return m||(m=(async()=>{var n,t,i,c,s;typeof document!="undefined"&&document.readyState==="loading"&&await new Promise(o=>document.addEventListener("DOMContentLoaded",()=>o(),{once:!0}));let e=b();for(let o=0;!e&&o<5&&F();o++)await new Promise(p=>setTimeout(p,60)),e=b();if(!e)return l=k(),l;a=new x(e);let r=await a.call("env",{},5e3);return l={container:r.container,containerVersion:(n=r.container_version)!=null?n:null,locale:(t=r.locale)!=null?t:k().locale,theme:(i=r.theme)!=null?i:"light",appId:(s=(c=r.app_id)!=null?c:u.appId)!=null?s:null,sdkVersion:h},a.on("themeChanged",o=>{l&&o&&typeof o=="object"&&(l.theme=o.theme)}),a.on("localeChanged",o=>{l&&o&&typeof o=="object"&&(l.locale=o.locale)}),l})(),m)}function F(){return typeof navigator!="undefined"&&/\bIchineseApp\//.test(navigator.userAgent)}function B(){return l!=null?l:k()}var K=()=>B().container!=="browser";async function W(e={}){var c,s,o,p,w;let r=await f();if(r.container!=="browser"&&a){let C=await a.call("requestAuthCode",(c=e.scopes)!=null&&c.length?{scopes:e.scopes}:{},null);return{code:C.code,via:"bridge",expiresIn:C.expires_in}}let n=T();if(n&&"ok"in n)return{...n.ok,via:"oidc"};let t=u.appId;if(!t)throw new d("invalid_params","config({ appId }) first: needed outside the containers");let i={issuer:(s=u.issuer)!=null?s:y,appId:t,redirectUri:(o=u.redirectUri)!=null?o:`${location.origin}${location.pathname}`,scopes:(w=(p=e.scopes)!=null?p:u.scopes)!=null?w:[],locale:r.locale};if(n&&"retry"in n)return S(i,!1);if(n&&"error"in n)throw new d(n.error==="access_denied"?"consent_denied":n.error,`the issuer answered ${n.error}`);return S(i,!0)}async function X(e){let r=await f(),n=String(e).slice(0,100);if(r.container==="browser"||!a){document.title=n;return}await a.call("setTitle",{title:n})}async function Y(){if((await f()).container==="browser"||!a){window.close();return}await a.call("close")}async function z(e){let r=new URL(e,location.href);if(r.protocol!=="https:"&&r.protocol!=="http:")throw new d("invalid_params","http(s) links only");if((await f()).container==="browser"||!a){window.open(r.toString(),"_blank","noopener,noreferrer");return}await a.call("openExternal",{url:r.toString()})}async function Q(e){if((await f()).container==="browser"||!a){if(typeof navigator!="undefined"&&typeof navigator.share=="function")try{return await navigator.share({title:e.title,text:e.description,url:e.url}),{shared:!0}}catch{return{shared:!1}}throw new d("unsupported_method","sharing to a conversation needs the desktop or mobile app")}return a.call("shareToChat",{title:e.title,description:e.description,url:e.url,image_url:e.imageUrl},null)}function Z(e,r){return a?a.on(e,r):()=>{}}function ee(){u={},a=void 0,l=void 0,m=void 0}return M(re);})();
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
|
|
5
5
|
// src/gen/meta.ts
|
|
6
|
-
var VERSION = "1.0.0-rc.
|
|
6
|
+
var VERSION = "1.0.0-rc.2";
|
|
7
7
|
var DEFAULT_ISSUER = "https://id.ichinese.cn";
|
|
8
8
|
var SCRIPT_URL = "https://ichinese.cn/open-js-sdk/1/ichinese-open.js";
|
|
9
9
|
var BRIDGE_PROTOCOL = 1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ichinese/open-js-sdk",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.2",
|
|
4
4
|
"description": "Web JS SDK for iChinese open platform web apps: the login bridge (requestAuthCode) in the desktop and mobile apps, falling back to OIDC in a plain browser, and the container's methods",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|