@sidesuit/pkg-module-proxy 0.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/dist/ajaxParamsHijack.d.ts +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/injector.d.ts +7 -0
- package/dist/relayStoreFinder.d.ts +1 -0
- package/dist/types.d.ts +51 -0
- package/dist/utils.d.ts +3 -0
- package/package.json +33 -0
- package/src/global.d.ts +30 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(){"use strict";function e(e){return e.split("").reverse().map((e=>String.fromCharCode(e.charCodeAt(0)-1))).join("")}function n(n){const[t,r="default"]=e(n).split("|");return[t,r]}function t(e){const n=function(e){let n=e.slice(e.indexOf("{")+1,e.lastIndexOf("}"));return n||""}(e),t=function(e){let n=e.replace(r,""),t=n.slice(n.indexOf("(")+1,n.indexOf(")")).match(o);null===t&&(t=[]);return t}(e);return new Function(t,n)}let r=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,o=/([^\s,]+)/g;function i(e,n,t=!1){const r=n.split(/\.|\[(\d+)\]/).filter(Boolean);let o,i=e;for(let s=0;s<r.length;s++){if(o=i,i=i[r[s]],void 0===i)return t?o:void 0}return t?o:i}(r=>{if(window.GZUAwCFuFf)return;window.GZUAwCFuFf=!0;const o={},s={},c={},l={},d={};let u=window.__d;window.__d&&(~u.toString().indexOf("__d_stub")?delete window.__d:u=new Proxy(window.__d,{apply:(e,n,t)=>(t=a(t),e.apply(n,t))})),Object.defineProperty(window,"__d",{get:function(){return u},set:function(e){u=new Proxy(e,{apply:(e,n,t)=>(t=a(t),e.apply(n,t))})}});const f=[];function a(e){let[n,r,d]=e;return"string"!=typeof n||f.includes(n)||(f.push(n),e[2]=function(e,n){if(!c[n])return e;const r=c[n];r.sort(((e,n)=>e.options.order-n.options.order));const o=r.find((e=>e.options.skipOthers));if(o)return t(o.replacement(e.toString()));return t(r.reduce(((e,n)=>e=n.replacement(e)),e.toString()))}(e[2],n),e[2]=function(e,n){return s[n]?new Proxy(e,{apply(e,t,r){if(r[5]&&r[5].dependencies)for(let n=0;n<r[5].dependencies.length;n++)r.push(r[5].dependencies[n].exports);const o=e.apply(t,r);return s[n].map((e=>{e(r)})),o}}):e}(e[2],n),e[2]=function(e,n){if(!o[n]||0===o[n].length)return e;const t=o[n];t.sort(((e,n)=>e.options.order-n.options.order));const r=t.reduce(((e,n)=>{const t=n.options.definerPath;return e[t]=e[t]||[],e[t].push(n),e}),{});return new Proxy(e,{apply(e,o,s){const c=e.apply(o,s);if(s[5]&&s[5].dependencies)for(let n=0;n<s[5].dependencies.length;n++)s.push(s[5].dependencies[n].exports);const l=s[3],d=(0,s[2])("CometErrorBoundary.react"),u=e=>(console.error(e),"Error");for(let f in r){const e=i(s,f,!0),o=f.split(".").pop(),c=i(s,f);e[o]=function(...e){const o=c.apply(c,e),i=e[0],{useState:a,useEffect:g,jsx:w,Fragment:x}=l("react"),[b,h]=a(0),y=()=>{if(!r[f])return o;const c=r[f].find((e=>e.options.skipOthers));if(c&&c.component)return w(c.fallback?d:x,{fallback:c.fallback,children:w(c.component,{payload:i,SourceCmp:o,lastCmp:o,definedArgs:s,callingArgs:e,extraPayloadFromDefiner:c.options.extraPayload,proxyCount:0,removeThisModuleProxy(){const e=r[f].indexOf(c);~e&&r[f].splice(e,1)}})});let l=0;return r[f].reduce(((c,u)=>(u.component&&(c=w(u.fallback?d:x,{fallback:u.fallback,children:w(u.component,{payload:i,SourceCmp:o,lastCmp:c,extraPayloadFromDefiner:u.options.extraPayload,proxyCount:l,definedArgs:s,callingArgs:e,removeThisModuleProxy(){const e=r[f].indexOf(u);if(~e){const o=t.indexOf(u);r[f].splice(e,1),t.splice(o,1),m(n)}}})}),l++),c)),o)};return g((()=>{const e=p(n,(()=>{h(Math.random())}));return()=>e()}),[]),w(d,{fallback:u,children:y()})}}return c}})}(e[2],n),l[n]&&console.log(n,e)),e}function p(e,n){return d[e]=d[e]||[],d[e].push(n),()=>{const t=d[e].findIndex(n);d[e].splice(t,1)}}function m(e){if(d[e])for(let n of d[e])n()}r.zKjQYvgSmF=function(n){return window.require(e(n))},r.zKjQYvcSmF=(e,t,r)=>{const[i,s]=n(e);o[i]||console.error(`Undefined module ${i} from ${s} #1`);const c=o[i].find((e=>e.extensionId===s));if(!c)return console.error(`Undefined module ${i} from ${s} #2`);const{fallback:l}=r||{};c.component=t,c.fallback=l,m(i)},r.zKjQYVcSmF=(e,t)=>{const r=Object.assign({order:10,skipOthers:!1,beforeInject:()=>!0,afterInject:()=>{},extraPayload:void 0,definerPath:"[6].default"},t),[i,s]=n(e);o[i]=o[i]||[],o[i].push({extensionId:s,moduleName:i,options:r,component:void 0,fallback:void 0})},r.zKjQYwcSmF=n=>{l[e(n)]=!0},r.zKjQYvcSfF=(e,t,r)=>{const o=Object.assign({order:10,skipOthers:!1},r),[i,s]=n(e);c[i]=c[i]||[],c[i].push({moduleName:i,options:o,replacement:t})},r.zKGQYvcSmF=(n,t)=>{n=e(n),s[n]=s[n]||[],s[n].push(t)},r.zKjQYvcSfF("umvbgfe}spssf.cg",(e=>e.replace('debugjs.")','debugjs.");console.error(b.stackFrames.slice(0,10).map(e=>e.text).join("\\n"))'))),r.zKjQYvcSfF("umvbgfe}djttbmd/epsq.NPEudbfS",(e=>e.replace(/Error\(\w\(418\)\)/g,"void 0"))),r.zKjQYvcSfF("umvbgfe}fvfvRitjmcvQzbmfS0fsput0fnjuovs.zbmfs",(e=>e.replace(/,(\w)=new\(b\("relay-runtime\/mutations\/RelayRecordSourceProxy"/,',$1=window["RlbiULLGWt"]=new(b("relay-runtime/mutations/RelayRecordSourceProxy"')))})(window),(n=>{if(n.vTUNhjwVvX)return;n.vTUNhjwVvX=!0;n.zKjqYvcSmF=(t,r,o)=>{r=e(r);const i=n.RlbiULLGWt,s="string"==typeof t?i.get(t):t;if(void 0===s)return s;let c=(l=r.replace(/\[(\d+)\]/g,".$1"),l.replace(/\((.*?)\.(.*?)\)/g,"($1_*_*_*_*_$2)")).split(".");var l;c=c.map((e=>function(e){return e.replaceAll("_*_*_*_*_",".")}(e)));let d=s;for(let e=0;e<c.length;e++){const n=c[e];if("*"===n)return d;if(0===n.indexOf("^^")){const[e,t]=u(n.substring(2));if(d=d.getLinkedRecords(e,t),void 0===d)return f(n),d}else if(0===n.indexOf("^")){const[e,t]=u(n.substring(1));if(d=d.getLinkedRecord(e,t),null==d)return f(n),d}else if(n.match(/^\d+$/)){if(d=d[parseInt(n)],null==d)return f(n),d}else{const[e,t]=u(n);if(d=d.getValue(e,t),null==d)return f(n),d}}return d;function u(e){const[n,t]=e.split("{");if(!t)return[n,{}];if(!o)throw new Error("args undefined");return[n,o[t.substring(0,t.length-1)]||{}]}function f(e){~n.location.search.indexOf("debug")&&console.warn("undefined value",{id:t,path:r,args:o,currentPath:e})}}})(window),(n=>{if(window.xmxlgxMDjA)return;window.xmxlgxMDjA=!0;let t={};n.zKGQYvcSmF("sf{jmbjsfTbubEfmqnjTsiy",(e=>{const n=e[4].exports.default;e[4].exports.default=function(...e){const r=e[0].fb_api_req_friendly_name;return r&&t[r]&&(e[0]=t[r].reduce(((e,n)=>e=n(e)),e[0])),n.apply(n,e)}}));n.zkjQYvcSmF=(n,r)=>{n=e(n),t[n]=t[n]||[],t[n].push(r)}})(window)}();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ComponentType } from "react";
|
|
2
|
+
export type SourceComponentPayload = {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
};
|
|
5
|
+
export type ExtraPayloadFromDefiner = any;
|
|
6
|
+
export type ProxyPayload<P extends SourceComponentPayload, E extends ExtraPayloadFromDefiner> = {
|
|
7
|
+
payload: P;
|
|
8
|
+
SourceCmp: ComponentType<any>;
|
|
9
|
+
lastCmp: ComponentType<any>;
|
|
10
|
+
extraPayloadFromDefiner: E;
|
|
11
|
+
proxyCount: number;
|
|
12
|
+
definedArgs: any[];
|
|
13
|
+
callingArgs: any[];
|
|
14
|
+
removeThisModuleProxy(): void;
|
|
15
|
+
};
|
|
16
|
+
export type ReplaceComponentType<P extends SourceComponentPayload, E extends ExtraPayloadFromDefiner> = ComponentType<ProxyPayload<P, E>>;
|
|
17
|
+
export type ModuleProxyDefineOptionType<P extends SourceComponentPayload, E extends ExtraPayloadFromDefiner> = {
|
|
18
|
+
order: number;
|
|
19
|
+
skipOthers: boolean;
|
|
20
|
+
beforeInject: (payload: P, othersProxy: ProxyMap[keyof ProxyMap]) => boolean;
|
|
21
|
+
afterInject: () => void;
|
|
22
|
+
extraPayload: E;
|
|
23
|
+
definerPath: string;
|
|
24
|
+
};
|
|
25
|
+
export type ProxyMap = Record<string, Array<{
|
|
26
|
+
extensionId: string;
|
|
27
|
+
moduleName: string;
|
|
28
|
+
options: ModuleProxyDefineOptionType<any, any>;
|
|
29
|
+
component: ReplaceComponentType<any, any> | undefined;
|
|
30
|
+
fallback: (() => any) | undefined;
|
|
31
|
+
}>>;
|
|
32
|
+
export type ModuleCodeReplaceOptionType = {
|
|
33
|
+
order: number;
|
|
34
|
+
skipOthers: boolean;
|
|
35
|
+
};
|
|
36
|
+
export type ModuleCodeReplaceMap = Record<string, Array<{
|
|
37
|
+
moduleName: string;
|
|
38
|
+
options: ModuleCodeReplaceOptionType;
|
|
39
|
+
replacement: (code: string) => string;
|
|
40
|
+
}>>;
|
|
41
|
+
export type ModuleProxyImmediatelyFunction = (moduleName: string, cb: (argsArr: any[]) => void) => void;
|
|
42
|
+
export type DefineModuleFunction<P extends SourceComponentPayload, E extends ExtraPayloadFromDefiner> = (moduleName: string, component: ReplaceComponentType<P, E>, options?: Partial<{
|
|
43
|
+
fallback: (() => any) | undefined;
|
|
44
|
+
}>) => void;
|
|
45
|
+
export type ModuleProxyDefineFunction<P extends SourceComponentPayload, E extends ExtraPayloadFromDefiner> = (moduleName: string, options?: Partial<ModuleProxyDefineOptionType<P, E>>) => void;
|
|
46
|
+
export type ModuleDebugDefineFunction = (moduleName: string) => void;
|
|
47
|
+
export type ModuleCodeReplaceFunction = (moduleName: string, replaceFn: (code: string) => string, options?: Partial<ModuleCodeReplaceOptionType>) => void;
|
|
48
|
+
export type StoreFinderFunction = (id: string, path: string, args?: {
|
|
49
|
+
[key: string]: any;
|
|
50
|
+
}) => any;
|
|
51
|
+
export type AjaxHijackFunction = (fb_api_req_friendly_name: string, cb: (params: Record<string, string>) => Record<string, string>) => void;
|
package/dist/utils.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sidesuit/pkg-module-proxy",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.iife.js",
|
|
7
|
+
"module": "./dist/index.iife.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"src/global.d.ts"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"serve": "vite",
|
|
15
|
+
"build": "vite build && tsc -p ./tsconfig.dist.json -emitDeclarationOnly && tsc-alias -p ./tsconfig.dist.json",
|
|
16
|
+
"preview": "vite preview"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@rollup/plugin-replace": "^5.0.2",
|
|
20
|
+
"@rollup/plugin-terser": "^0.4.0",
|
|
21
|
+
"@sidesuit/pkg-vite-plugins": "*",
|
|
22
|
+
"@types/lodash-es": "^4.17.6",
|
|
23
|
+
"@types/node": "^18.11.17",
|
|
24
|
+
"@vitejs/plugin-react": "3.1.0",
|
|
25
|
+
"glob": "9.0.1",
|
|
26
|
+
"lodash-es": "^4.17.21",
|
|
27
|
+
"prettier": "^2.8.1",
|
|
28
|
+
"react": "^18.2.0",
|
|
29
|
+
"tsc-alias": "^1.8.2",
|
|
30
|
+
"typescript": "^4.9.3",
|
|
31
|
+
"vite": "^4.0.3"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/global.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AjaxHijackFunction,
|
|
3
|
+
DefineModuleFunction,
|
|
4
|
+
ModuleCodeReplaceFunction,
|
|
5
|
+
ModuleDebugDefineFunction,
|
|
6
|
+
ModuleProxyDefineFunction,
|
|
7
|
+
ModuleProxyImmediatelyFunction,
|
|
8
|
+
StoreFinderFunction,
|
|
9
|
+
} from "./types";
|
|
10
|
+
|
|
11
|
+
export declare global {
|
|
12
|
+
interface Window {
|
|
13
|
+
// window.require
|
|
14
|
+
rq(module: string): any;
|
|
15
|
+
// 定义需要代理的模块
|
|
16
|
+
defineModule: DefineModuleFunction;
|
|
17
|
+
// 模块代理
|
|
18
|
+
moduleProxyDefine: ModuleProxyDefineFunction;
|
|
19
|
+
// 模块 debug
|
|
20
|
+
moduleDebugDefine: ModuleDebugDefineFunction;
|
|
21
|
+
// 模块代码替换
|
|
22
|
+
moduleCodeReplace: ModuleCodeReplaceFunction;
|
|
23
|
+
// replay store 查找
|
|
24
|
+
storeFinder: StoreFinderFunction;
|
|
25
|
+
// 跟旧版本的立刻替换一样
|
|
26
|
+
moduleProxyImmediately: ModuleProxyImmediatelyFunction;
|
|
27
|
+
// ajax 参数拦截
|
|
28
|
+
ajaxHijack: AjaxHijackFunction;
|
|
29
|
+
}
|
|
30
|
+
}
|