@leancodepl/cyberware-contract 10.1.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/LICENSE +201 -0
- package/README.md +721 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +160 -0
- package/dist/index.umd.cjs +1 -0
- package/dist/lib/ConnectToHostProvider.d.ts +17 -0
- package/dist/lib/ConnectToHostProvider.d.ts.map +1 -0
- package/dist/lib/connect.d.ts +46 -0
- package/dist/lib/connect.d.ts.map +1 -0
- package/dist/lib/createContract.d.ts +43 -0
- package/dist/lib/createContract.d.ts.map +1 -0
- package/dist/lib/enums.d.ts +7 -0
- package/dist/lib/enums.d.ts.map +1 -0
- package/dist/lib/types.d.ts +10 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/urlParams.d.ts +12 -0
- package/dist/lib/urlParams.d.ts.map +1 -0
- package/dist/lib/useConnectToHost.d.ts +29 -0
- package/dist/lib/useConnectToHost.d.ts.map +1 -0
- package/dist/lib/useConnectToRemote.d.ts +47 -0
- package/dist/lib/useConnectToRemote.d.ts.map +1 -0
- package/dist/lib/zod.d.ts +81 -0
- package/dist/lib/zod.d.ts.map +1 -0
- package/package.json +65 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { connectToHost, type ConnectToHostOptions, connectToRemote, type ConnectToRemoteOptions } from './lib/connect';
|
|
2
|
+
export { useConnectToRemote, type UseConnectToRemoteOptions, type UseConnectToRemoteResult, } from './lib/useConnectToRemote';
|
|
3
|
+
export { type ConnectToHostState, useConnectToHost, type UseConnectToHostOptions, type UseConnectToHostResult, } from './lib/useConnectToHost';
|
|
4
|
+
export { createConnectToHostProvider } from './lib/ConnectToHostProvider';
|
|
5
|
+
export { buildRemoteUrl, getUrlParams } from './lib/urlParams';
|
|
6
|
+
export { createContract, type CreateContractOptions } from './lib/createContract';
|
|
7
|
+
export { ConnectStatus } from './lib/enums';
|
|
8
|
+
export type { HostProxy, RemoteProxy } from './lib/types';
|
|
9
|
+
export { ContractSchema, type ContractSchemaType, type HostMethodsSchemaBase, type InferMethodsFromSchema, type InferParamsFromSchema, methodDef, type MethodDefInferred, MethodDefInferredSchema, type MethodDefOutput, type MethodParamsType, type MethodReturnType, type MethodType, mkZodContractSchema, type RemoteMethodsSchemaBase, type RemoteParamsSchemaBase, } from './lib/zod';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACtH,OAAO,EACL,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,GAC9B,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,KAAK,kBAAkB,EACvB,gBAAgB,EAChB,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,GAC5B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAA;AACzE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9D,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,EACL,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,SAAS,EACT,KAAK,iBAAiB,EACtB,uBAAuB,EACvB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,mBAAmB,EACnB,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,GAC5B,MAAM,WAAW,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { WindowMessenger as T, connect as b } from "penpal";
|
|
2
|
+
import { jsx as E } from "react/jsx-runtime";
|
|
3
|
+
import { useRef as R, useState as v, useEffect as O, createContext as I, useContext as L } from "react";
|
|
4
|
+
import D from "semver";
|
|
5
|
+
import { z as e } from "zod";
|
|
6
|
+
function W(t, o) {
|
|
7
|
+
const { methods: n, allowedOrigins: s } = o, r = new URL(t.src).origin, i = t.contentWindow;
|
|
8
|
+
if (!i)
|
|
9
|
+
throw new Error("Iframe content window is not available");
|
|
10
|
+
const m = new T({
|
|
11
|
+
remoteWindow: i,
|
|
12
|
+
allowedOrigins: s ?? [r]
|
|
13
|
+
});
|
|
14
|
+
return b({
|
|
15
|
+
messenger: m,
|
|
16
|
+
methods: n
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function x(t) {
|
|
20
|
+
const { methods: o, allowedOrigins: n } = t, s = document.referrer && document.referrer !== "" ? new URL(document.referrer).origin : globalThis.location.origin, r = new T({
|
|
21
|
+
remoteWindow: globalThis.window.parent,
|
|
22
|
+
allowedOrigins: n ?? [s]
|
|
23
|
+
});
|
|
24
|
+
return b({
|
|
25
|
+
messenger: r,
|
|
26
|
+
methods: o
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
var a = /* @__PURE__ */ ((t) => (t.IDLE = "idle", t.CONNECTED = "connected", t.ERROR = "error", t.INCOMPATIBLE = "incompatible", t))(a || {});
|
|
30
|
+
function V(t, o) {
|
|
31
|
+
if (!o || Object.keys(o).length === 0)
|
|
32
|
+
return t;
|
|
33
|
+
const n = new URL(t, globalThis.location.origin);
|
|
34
|
+
for (const [s, r] of Object.entries(o))
|
|
35
|
+
r !== void 0 && r !== "" && n.searchParams.set(s, r);
|
|
36
|
+
return n.toString();
|
|
37
|
+
}
|
|
38
|
+
function j() {
|
|
39
|
+
const t = typeof globalThis.window < "u" ? globalThis.location.search : "";
|
|
40
|
+
return Object.fromEntries(new URLSearchParams(t).entries());
|
|
41
|
+
}
|
|
42
|
+
function M(t) {
|
|
43
|
+
const { remoteUrl: o, iframeProps: n, methods: s, allowedOrigins: r, params: i, contractVersion: m } = t, { title: c, ...l } = n, h = R(null), [f, u] = v({ status: a.IDLE }), H = {
|
|
44
|
+
...i,
|
|
45
|
+
contractVersion: m
|
|
46
|
+
}, p = V(o, H);
|
|
47
|
+
return O(() => {
|
|
48
|
+
const w = h.current;
|
|
49
|
+
if (!w) return;
|
|
50
|
+
const g = W(w, {
|
|
51
|
+
methods: s,
|
|
52
|
+
allowedOrigins: r
|
|
53
|
+
});
|
|
54
|
+
return g.promise.then((d) => u({ status: a.CONNECTED, remote: d })).catch(
|
|
55
|
+
(d) => u({
|
|
56
|
+
status: a.ERROR,
|
|
57
|
+
error: d instanceof Error ? d : new Error(String(d))
|
|
58
|
+
})
|
|
59
|
+
), () => {
|
|
60
|
+
u({ status: a.IDLE }), g.destroy();
|
|
61
|
+
};
|
|
62
|
+
}, [p, s, r]), {
|
|
63
|
+
iframe: /* @__PURE__ */ E("iframe", { ref: h, src: p, title: c, ...l }),
|
|
64
|
+
...f
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function P(t) {
|
|
68
|
+
const { methods: o, allowedOrigins: n, contractVersion: s, contractVersionRange: r } = t, i = R(j()), [m, c] = v({ status: a.IDLE });
|
|
69
|
+
return O(() => {
|
|
70
|
+
if (typeof globalThis.window.parent > "u" || globalThis.window.parent === globalThis.window)
|
|
71
|
+
return;
|
|
72
|
+
const l = i.current.contractVersion;
|
|
73
|
+
if (!D.satisfies(l, r)) {
|
|
74
|
+
c({ status: a.INCOMPATIBLE, hostVersion: l, remoteVersion: s });
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const f = x({
|
|
78
|
+
methods: o,
|
|
79
|
+
allowedOrigins: n
|
|
80
|
+
});
|
|
81
|
+
return f.promise.then((u) => c({ status: a.CONNECTED, host: u })).catch(
|
|
82
|
+
(u) => c({
|
|
83
|
+
status: a.ERROR,
|
|
84
|
+
error: u instanceof Error ? u : new Error(String(u))
|
|
85
|
+
})
|
|
86
|
+
), () => {
|
|
87
|
+
c({ status: a.IDLE }), f.destroy();
|
|
88
|
+
};
|
|
89
|
+
}, [o, n, s, r]), m;
|
|
90
|
+
}
|
|
91
|
+
function N(t, o) {
|
|
92
|
+
const n = I(null);
|
|
93
|
+
function s({ children: i, methods: m, allowedOrigins: c }) {
|
|
94
|
+
const l = P({
|
|
95
|
+
methods: m,
|
|
96
|
+
allowedOrigins: c,
|
|
97
|
+
contractVersion: t,
|
|
98
|
+
contractVersionRange: o
|
|
99
|
+
});
|
|
100
|
+
return /* @__PURE__ */ E(n.Provider, { value: l, children: i });
|
|
101
|
+
}
|
|
102
|
+
function r() {
|
|
103
|
+
const i = L(n);
|
|
104
|
+
if (i === null)
|
|
105
|
+
throw new Error("useConnectToHostContext must be used within ConnectToHostProvider");
|
|
106
|
+
return i;
|
|
107
|
+
}
|
|
108
|
+
return { ConnectToHostProvider: s, useConnectToHostContext: r };
|
|
109
|
+
}
|
|
110
|
+
function z(t) {
|
|
111
|
+
const { contractVersion: o, contractVersionRange: n } = t, { ConnectToHostProvider: s, useConnectToHostContext: r } = N(o, n);
|
|
112
|
+
return {
|
|
113
|
+
useConnectToRemote: (c) => M({
|
|
114
|
+
...c,
|
|
115
|
+
contractVersion: o
|
|
116
|
+
}),
|
|
117
|
+
useConnectToHost: (c) => P({
|
|
118
|
+
...c,
|
|
119
|
+
contractVersion: o,
|
|
120
|
+
contractVersionRange: n
|
|
121
|
+
}),
|
|
122
|
+
ConnectToHostProvider: s,
|
|
123
|
+
useConnectToHostContext: r,
|
|
124
|
+
getUrlParams: j
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function Z(t) {
|
|
128
|
+
return !t || t.params === void 0 && t.returns === void 0 ? e.object({}) : t.params === void 0 && t.returns !== void 0 ? e.object({ returns: t.returns }) : t.returns === void 0 && t.params !== void 0 ? e.object({ params: t.params }) : t.params !== void 0 && t.returns !== void 0 ? e.object({ params: t.params, returns: t.returns }) : e.object({});
|
|
129
|
+
}
|
|
130
|
+
const C = e.object({ params: e.unknown(), returns: e.unknown() }).partial(), q = e.object({
|
|
131
|
+
hostMethods: e.record(e.string(), C),
|
|
132
|
+
remoteMethods: e.record(e.string(), C),
|
|
133
|
+
remoteParams: e.record(e.string(), e.string())
|
|
134
|
+
});
|
|
135
|
+
function F({
|
|
136
|
+
hostMethods: t,
|
|
137
|
+
remoteMethods: o,
|
|
138
|
+
remoteParams: n
|
|
139
|
+
}) {
|
|
140
|
+
return e.object({
|
|
141
|
+
hostMethods: e.object(t),
|
|
142
|
+
remoteMethods: e.object(o),
|
|
143
|
+
remoteParams: e.object(n)
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
export {
|
|
147
|
+
a as ConnectStatus,
|
|
148
|
+
q as ContractSchema,
|
|
149
|
+
C as MethodDefInferredSchema,
|
|
150
|
+
V as buildRemoteUrl,
|
|
151
|
+
x as connectToHost,
|
|
152
|
+
W as connectToRemote,
|
|
153
|
+
N as createConnectToHostProvider,
|
|
154
|
+
z as createContract,
|
|
155
|
+
j as getUrlParams,
|
|
156
|
+
Z as methodDef,
|
|
157
|
+
F as mkZodContractSchema,
|
|
158
|
+
P as useConnectToHost,
|
|
159
|
+
M as useConnectToRemote
|
|
160
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(t,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("penpal"),require("react/jsx-runtime"),require("react"),require("semver"),require("zod")):typeof define=="function"&&define.amd?define(["exports","penpal","react/jsx-runtime","react","semver","zod"],f):(t=typeof globalThis<"u"?globalThis:t||self,f(t["@leancodepl/cyberware-contract"]={},t.penpal,t.jsxRuntime,t.react,t.semver,t.zod))})(this,(function(t,f,R,d,D,n){"use strict";function E(e,o){const{methods:r,allowedOrigins:c}=o,s=new URL(e.src).origin,i=e.contentWindow;if(!i)throw new Error("Iframe content window is not available");const l=new f.WindowMessenger({remoteWindow:i,allowedOrigins:c??[s]});return f.connect({messenger:l,methods:r})}function v(e){const{methods:o,allowedOrigins:r}=e,c=document.referrer&&document.referrer!==""?new URL(document.referrer).origin:globalThis.location.origin,s=new f.WindowMessenger({remoteWindow:globalThis.window.parent,allowedOrigins:r??[c]});return f.connect({messenger:s,methods:o})}var u=(e=>(e.IDLE="idle",e.CONNECTED="connected",e.ERROR="error",e.INCOMPATIBLE="incompatible",e))(u||{});function j(e,o){if(!o||Object.keys(o).length===0)return e;const r=new URL(e,globalThis.location.origin);for(const[c,s]of Object.entries(o))s!==void 0&&s!==""&&r.searchParams.set(c,s);return r.toString()}function T(){const e=typeof globalThis.window<"u"?globalThis.location.search:"";return Object.fromEntries(new URLSearchParams(e).entries())}function O(e){const{remoteUrl:o,iframeProps:r,methods:c,allowedOrigins:s,params:i,contractVersion:l}=e,{title:a,...h}=r,b=d.useRef(null),[C,m]=d.useState({status:u.IDLE}),V={...i,contractVersion:l},H=j(o,V);return d.useEffect(()=>{const S=b.current;if(!S)return;const I=E(S,{methods:c,allowedOrigins:s});return I.promise.then(w=>m({status:u.CONNECTED,remote:w})).catch(w=>m({status:u.ERROR,error:w instanceof Error?w:new Error(String(w))})),()=>{m({status:u.IDLE}),I.destroy()}},[H,c,s]),{iframe:R.jsx("iframe",{ref:b,src:H,title:a,...h}),...C}}function g(e){const{methods:o,allowedOrigins:r,contractVersion:c,contractVersionRange:s}=e,i=d.useRef(T()),[l,a]=d.useState({status:u.IDLE});return d.useEffect(()=>{if(typeof globalThis.window.parent>"u"||globalThis.window.parent===globalThis.window)return;const h=i.current.contractVersion;if(!D.satisfies(h,s)){a({status:u.INCOMPATIBLE,hostVersion:h,remoteVersion:c});return}const C=v({methods:o,allowedOrigins:r});return C.promise.then(m=>a({status:u.CONNECTED,host:m})).catch(m=>a({status:u.ERROR,error:m instanceof Error?m:new Error(String(m))})),()=>{a({status:u.IDLE}),C.destroy()}},[o,r,c,s]),l}function P(e,o){const r=d.createContext(null);function c({children:i,methods:l,allowedOrigins:a}){const h=g({methods:l,allowedOrigins:a,contractVersion:e,contractVersionRange:o});return R.jsx(r.Provider,{value:h,children:i})}function s(){const i=d.useContext(r);if(i===null)throw new Error("useConnectToHostContext must be used within ConnectToHostProvider");return i}return{ConnectToHostProvider:c,useConnectToHostContext:s}}function y(e){const{contractVersion:o,contractVersionRange:r}=e,{ConnectToHostProvider:c,useConnectToHostContext:s}=P(o,r);return{useConnectToRemote:a=>O({...a,contractVersion:o}),useConnectToHost:a=>g({...a,contractVersion:o,contractVersionRange:r}),ConnectToHostProvider:c,useConnectToHostContext:s,getUrlParams:T}}function L(e){return!e||e.params===void 0&&e.returns===void 0?n.z.object({}):e.params===void 0&&e.returns!==void 0?n.z.object({returns:e.returns}):e.returns===void 0&&e.params!==void 0?n.z.object({params:e.params}):e.params!==void 0&&e.returns!==void 0?n.z.object({params:e.params,returns:e.returns}):n.z.object({})}const p=n.z.object({params:n.z.unknown(),returns:n.z.unknown()}).partial(),M=n.z.object({hostMethods:n.z.record(n.z.string(),p),remoteMethods:n.z.record(n.z.string(),p),remoteParams:n.z.record(n.z.string(),n.z.string())});function W({hostMethods:e,remoteMethods:o,remoteParams:r}){return n.z.object({hostMethods:n.z.object(e),remoteMethods:n.z.object(o),remoteParams:n.z.object(r)})}t.ConnectStatus=u,t.ContractSchema=M,t.MethodDefInferredSchema=p,t.buildRemoteUrl=j,t.connectToHost=v,t.connectToRemote=E,t.createConnectToHostProvider=P,t.createContract=y,t.getUrlParams=T,t.methodDef=L,t.mkZodContractSchema=W,t.useConnectToHost=g,t.useConnectToRemote=O,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { HostMethodsBase, RemoteMethodsBase, RemoteParamsWithContractVersion } from './types';
|
|
3
|
+
import { UseConnectToHostResult } from './useConnectToHost';
|
|
4
|
+
/**
|
|
5
|
+
* Create a typed ConnectToHostProvider and useConnectToHostContext pair.
|
|
6
|
+
* Each contract should call this to get a provider and hook that share the same context.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createConnectToHostProvider<THost extends HostMethodsBase, TRemote extends RemoteMethodsBase, TParamsWithContractVersion extends RemoteParamsWithContractVersion>(contractVersion: string, contractVersionRange: string): {
|
|
9
|
+
ConnectToHostProvider: <T extends Omit<import('./connect').ConnectToHostOptions<TRemote> & {
|
|
10
|
+
contractVersion: string;
|
|
11
|
+
contractVersionRange: string;
|
|
12
|
+
} & {
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
}, "contractVersion" | "contractVersionRange">>({ children, methods, allowedOrigins }: T) => import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
useConnectToHostContext: () => UseConnectToHostResult<THost>;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=ConnectToHostProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectToHostProvider.d.ts","sourceRoot":"","sources":["../../src/lib/ConnectToHostProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,SAAS,EAAc,MAAM,OAAO,CAAA;AACjE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAA;AAC7F,OAAO,EAAkD,KAAK,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAEhH;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,SAAS,eAAe,EAC7B,OAAO,SAAS,iBAAiB,EACjC,0BAA0B,SAAS,+BAA+B,EAClE,eAAe,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM;4BAQnD,CAAC,SAAS,IAAI;;;;kBAJJ,SAAS;OAIwB,iBAAiB,GAAG,sBAAsB,CAAC,yCAC/C,CAAC;mCAWN,sBAAsB,CAAC,KAAK,CAAC;EASlE"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { HostMethodsBase, RemoteMethodsBase } from './types';
|
|
2
|
+
export type ConnectToRemoteOptions<THost extends HostMethodsBase> = {
|
|
3
|
+
/** Methods the host exposes to the remote */
|
|
4
|
+
methods: THost;
|
|
5
|
+
/** Allowed origins for the remote iframe (defaults to iframe src origin) */
|
|
6
|
+
allowedOrigins?: string[];
|
|
7
|
+
};
|
|
8
|
+
export type ConnectToHostOptions<TRemote extends RemoteMethodsBase> = {
|
|
9
|
+
/** Methods the remote exposes to the host */
|
|
10
|
+
methods: TRemote;
|
|
11
|
+
/** Allowed origins for the parent window (defaults to document.referrer origin) */
|
|
12
|
+
allowedOrigins?: string[];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Connect host (parent) to remote (child iframe).
|
|
16
|
+
* Call this from the host app with the iframe element.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const connection = connectToRemote<RemoteMethods, HostMethods>(iframeRef.current, {
|
|
20
|
+
* methods: {
|
|
21
|
+
* navigateTo: (path) => { router.navigate(path) },
|
|
22
|
+
* showNotification: (msg, type) => { messageApi[type](msg) },
|
|
23
|
+
* getCurrentUserId: () => Promise.resolve(userId),
|
|
24
|
+
* },
|
|
25
|
+
* })
|
|
26
|
+
* const remote = await connection.promise
|
|
27
|
+
* await remote.navigateTo("/settings")
|
|
28
|
+
*/
|
|
29
|
+
export declare function connectToRemote<TRemote extends RemoteMethodsBase, THost extends HostMethodsBase>(iframe: HTMLIFrameElement, options: ConnectToRemoteOptions<THost>): import('penpal').Connection<TRemote>;
|
|
30
|
+
/**
|
|
31
|
+
* Connect remote (child iframe) to host (parent window).
|
|
32
|
+
* Call this from the remote app.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const connection = connectToHost<HostMethods, RemoteMethods>({
|
|
36
|
+
* methods: {
|
|
37
|
+
* navigateTo: (path) => { navigate(path) },
|
|
38
|
+
* getCurrentPath: () => Promise.resolve(location.pathname),
|
|
39
|
+
* refresh: () => refetch(),
|
|
40
|
+
* },
|
|
41
|
+
* })
|
|
42
|
+
* const host = await connection.promise
|
|
43
|
+
* await host.showNotification("Settings saved", "success")
|
|
44
|
+
*/
|
|
45
|
+
export declare function connectToHost<THost extends HostMethodsBase, TRemote extends RemoteMethodsBase>(options: ConnectToHostOptions<TRemote>): import('penpal').Connection<THost>;
|
|
46
|
+
//# sourceMappingURL=connect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../src/lib/connect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAE5D,MAAM,MAAM,sBAAsB,CAAC,KAAK,SAAS,eAAe,IAAI;IAClE,6CAA6C;IAC7C,OAAO,EAAE,KAAK,CAAA;IACd,4EAA4E;IAC5E,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;CAC1B,CAAA;AAED,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,iBAAiB,IAAI;IACpE,6CAA6C;IAC7C,OAAO,EAAE,OAAO,CAAA;IAChB,mFAAmF;IACnF,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;CAC1B,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,iBAAiB,EAAE,KAAK,SAAS,eAAe,EAC9F,MAAM,EAAE,iBAAiB,EACzB,OAAO,EAAE,sBAAsB,CAAC,KAAK,CAAC,wCAmBvC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,KAAK,SAAS,eAAe,EAAE,OAAO,SAAS,iBAAiB,EAC5F,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,sCAevC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { HostMethodsBase, RemoteMethodsBase, RemoteParamsBase, RemoteParamsWithContractVersion } from './types';
|
|
2
|
+
import { getUrlParams } from './urlParams';
|
|
3
|
+
import { UseConnectToHostOptions } from './useConnectToHost';
|
|
4
|
+
import { UseConnectToRemoteOptions } from './useConnectToRemote';
|
|
5
|
+
export type CreateContractOptions = {
|
|
6
|
+
/** Semver version of the contract */
|
|
7
|
+
contractVersion: `${number}.${number}.${number}`;
|
|
8
|
+
/** Semver range the host contract version must satisfy (e.g. ">=1.0.0", "^2.0.0", "~2.1.0") */
|
|
9
|
+
contractVersionRange: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Create a type-safe contract shared between host and remote.
|
|
13
|
+
* Use the same contract type on both sides to ensure method signatures match.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Define contract in a shared package or file
|
|
17
|
+
* type HostMethods = { navigateTo: (path: string) => Promise<void>; ... }
|
|
18
|
+
* type RemoteMethods = { getCurrentPath: () => Promise<string>; ... }
|
|
19
|
+
* type RemoteParams = { userId?: string; tenantId?: string }
|
|
20
|
+
*
|
|
21
|
+
* export const contract = createContract<
|
|
22
|
+
* HostMethods,
|
|
23
|
+
* RemoteMethods,
|
|
24
|
+
* RemoteParams
|
|
25
|
+
* >({ contractVersion: '1.0.0', contractVersionRange: '>=1.0.0 <2.0.0' })
|
|
26
|
+
*
|
|
27
|
+
* // Host: contract.useConnectToRemote({ remoteUrl, params: { userId: '123' }, methods })
|
|
28
|
+
* // Remote: contract.useConnectToHost({ methods })
|
|
29
|
+
* // Remote: contract.getUrlParams() // { userId?: string; tenantId?: string }
|
|
30
|
+
*/
|
|
31
|
+
export declare function createContract<THost extends HostMethodsBase, TRemote extends RemoteMethodsBase, TParams extends RemoteParamsBase>(options: CreateContractOptions): {
|
|
32
|
+
useConnectToRemote: (options: Omit<UseConnectToRemoteOptions<THost, TParams>, "contractVersion">) => import('./useConnectToRemote').UseConnectToRemoteResult<TRemote>;
|
|
33
|
+
useConnectToHost: (options: Omit<UseConnectToHostOptions<TRemote>, "contractVersion" | "contractVersionRange">) => import('./useConnectToHost').UseConnectToHostResult<THost>;
|
|
34
|
+
ConnectToHostProvider: <T extends Omit<import('./connect').ConnectToHostOptions<TRemote> & {
|
|
35
|
+
contractVersion: string;
|
|
36
|
+
contractVersionRange: string;
|
|
37
|
+
} & {
|
|
38
|
+
children: import('react').ReactNode;
|
|
39
|
+
}, "contractVersion" | "contractVersionRange">>({ children, methods, allowedOrigins }: T) => import("react/jsx-runtime").JSX.Element;
|
|
40
|
+
useConnectToHostContext: () => import('./useConnectToHost').UseConnectToHostResult<THost>;
|
|
41
|
+
getUrlParams: typeof getUrlParams<RemoteParamsWithContractVersion<TParams>>;
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=createContract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createContract.d.ts","sourceRoot":"","sources":["../../src/lib/createContract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAA;AAC/G,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAoB,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AAC9E,OAAO,EAAsB,yBAAyB,EAAE,MAAM,sBAAsB,CAAA;AAEpF,MAAM,MAAM,qBAAqB,GAAG;IAClC,qCAAqC;IACrC,eAAe,EAAE,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAA;IAChD,+FAA+F;IAC/F,oBAAoB,EAAE,MAAM,CAAA;CAC7B,CAAA;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAC5B,KAAK,SAAS,eAAe,EAC7B,OAAO,SAAS,iBAAiB,EACjC,OAAO,SAAS,gBAAgB,EAChC,OAAO,EAAE,qBAAqB;kCAWc,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,iBAAiB,CAAC;gCAOnG,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,sBAAsB,CAAC;;;;;;;;kBAa7D,OAAO,YAAY,0CAA4B;EAEhF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../../src/lib/enums.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa;IACvB,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,KAAK,UAAU;IACf,YAAY,iBAAiB;CAC9B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Methods, RemoteProxy as PenpalRemoteProxy } from 'penpal';
|
|
2
|
+
export type HostMethodsBase = Methods;
|
|
3
|
+
export type RemoteMethodsBase = Methods;
|
|
4
|
+
export type RemoteParamsBase = Record<string, string>;
|
|
5
|
+
export type RemoteParamsWithContractVersion<TParams extends RemoteParamsBase = RemoteParamsBase> = TParams & {
|
|
6
|
+
contractVersion: string;
|
|
7
|
+
};
|
|
8
|
+
export type HostProxy<THost extends HostMethodsBase> = PenpalRemoteProxy<THost>;
|
|
9
|
+
export type RemoteProxy<TRemote extends RemoteMethodsBase> = PenpalRemoteProxy<TRemote>;
|
|
10
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,IAAI,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AAElE,MAAM,MAAM,eAAe,GAAG,OAAO,CAAA;AACrC,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAA;AACvC,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AACrD,MAAM,MAAM,+BAA+B,CAAC,OAAO,SAAS,gBAAgB,GAAG,gBAAgB,IAAI,OAAO,GAAG;IAC3G,eAAe,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,eAAe,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAA;AAC/E,MAAM,MAAM,WAAW,CAAC,OAAO,SAAS,iBAAiB,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RemoteParamsWithContractVersion } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Build remote URL with query parameters.
|
|
4
|
+
* Merges params into the URL, preserving existing search params.
|
|
5
|
+
*/
|
|
6
|
+
export declare function buildRemoteUrl(baseUrl: string, params?: RemoteParamsWithContractVersion): string;
|
|
7
|
+
/**
|
|
8
|
+
* Read URL search params as a typed object. No validation is performed.
|
|
9
|
+
* Call from the remote (iframe) to read params passed by the host.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getUrlParams<TParamsWithContractVersion extends RemoteParamsWithContractVersion>(): TParamsWithContractVersion;
|
|
12
|
+
//# sourceMappingURL=urlParams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlParams.d.ts","sourceRoot":"","sources":["../../src/lib/urlParams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAA;AAEzD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,+BAA+B,GAAG,MAAM,CAYhG;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,0BAA0B,SAAS,+BAA+B,KAC/D,0BAA0B,CAG9B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ConnectToHostOptions } from './connect';
|
|
2
|
+
import { ConnectStatus } from './enums';
|
|
3
|
+
import { HostMethodsBase, HostProxy, RemoteMethodsBase, RemoteParamsWithContractVersion } from './types';
|
|
4
|
+
export type UseConnectToHostOptions<TRemote extends RemoteMethodsBase> = ConnectToHostOptions<TRemote> & {
|
|
5
|
+
/** Remote's semver contract version */
|
|
6
|
+
contractVersion: string;
|
|
7
|
+
/** Semver range the host contract version must satisfy (e.g. ">=1.0.0", "^2.0.0", "~2.1.0") */
|
|
8
|
+
contractVersionRange: string;
|
|
9
|
+
};
|
|
10
|
+
export type ConnectToHostState<THost extends HostMethodsBase> = {
|
|
11
|
+
status: ConnectStatus.CONNECTED;
|
|
12
|
+
host: HostProxy<THost>;
|
|
13
|
+
} | {
|
|
14
|
+
status: ConnectStatus.ERROR;
|
|
15
|
+
error: Error;
|
|
16
|
+
} | {
|
|
17
|
+
status: ConnectStatus.IDLE;
|
|
18
|
+
} | {
|
|
19
|
+
status: ConnectStatus.INCOMPATIBLE;
|
|
20
|
+
hostVersion: string;
|
|
21
|
+
remoteVersion: string;
|
|
22
|
+
};
|
|
23
|
+
export type UseConnectToHostResult<THost extends HostMethodsBase> = ConnectToHostState<THost>;
|
|
24
|
+
/**
|
|
25
|
+
* Connect remote (child iframe) to host (parent window).
|
|
26
|
+
* Call this from the remote app. Does nothing when not embedded in an iframe.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useConnectToHost<THost extends HostMethodsBase, TRemote extends RemoteMethodsBase, TParamsWithContractVersion extends RemoteParamsWithContractVersion>(options: UseConnectToHostOptions<TRemote>): UseConnectToHostResult<THost>;
|
|
29
|
+
//# sourceMappingURL=useConnectToHost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConnectToHost.d.ts","sourceRoot":"","sources":["../../src/lib/useConnectToHost.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,iBAAiB,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAA;AAGxG,MAAM,MAAM,uBAAuB,CAAC,OAAO,SAAS,iBAAiB,IAAI,oBAAoB,CAAC,OAAO,CAAC,GAAG;IACvG,uCAAuC;IACvC,eAAe,EAAE,MAAM,CAAA;IACvB,+FAA+F;IAC/F,oBAAoB,EAAE,MAAM,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,kBAAkB,CAAC,KAAK,SAAS,eAAe,IACxD;IAAE,MAAM,EAAE,aAAa,CAAC,SAAS,CAAC;IAAC,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,CAAA;CAAE,GAC3D;IAAE,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC7C;IAAE,MAAM,EAAE,aAAa,CAAC,IAAI,CAAA;CAAE,GAC9B;IAAE,MAAM,EAAE,aAAa,CAAC,YAAY,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAA;AAEtF,MAAM,MAAM,sBAAsB,CAAC,KAAK,SAAS,eAAe,IAAI,kBAAkB,CAAC,KAAK,CAAC,CAAA;AAE7F;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,SAAS,eAAe,EAC7B,OAAO,SAAS,iBAAiB,EACjC,0BAA0B,SAAS,+BAA+B,EAClE,OAAO,EAAE,uBAAuB,CAAC,OAAO,CAAC,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAyC1E"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
import { ConnectToRemoteOptions } from './connect';
|
|
3
|
+
import { ConnectStatus } from './enums';
|
|
4
|
+
import { HostMethodsBase, RemoteMethodsBase, RemoteParamsBase, RemoteProxy } from './types';
|
|
5
|
+
export type ConnectToRemoteState<TRemote extends RemoteMethodsBase> = {
|
|
6
|
+
status: ConnectStatus.CONNECTED;
|
|
7
|
+
remote: RemoteProxy<TRemote>;
|
|
8
|
+
} | {
|
|
9
|
+
status: ConnectStatus.ERROR;
|
|
10
|
+
error: Error;
|
|
11
|
+
} | {
|
|
12
|
+
status: ConnectStatus.IDLE;
|
|
13
|
+
};
|
|
14
|
+
export type UseConnectToRemoteOptions<THost extends HostMethodsBase, TParams extends RemoteParamsBase> = ConnectToRemoteOptions<THost> & {
|
|
15
|
+
/** URL for the remote iframe src (base URL without params) */
|
|
16
|
+
remoteUrl: string;
|
|
17
|
+
/** Params to pass to the remote via URL query string */
|
|
18
|
+
params?: TParams;
|
|
19
|
+
/** Host's semver contract version */
|
|
20
|
+
contractVersion: string;
|
|
21
|
+
/** Props for the iframe element */
|
|
22
|
+
iframeProps: Omit<HTMLAttributes<HTMLIFrameElement>, "src" | "title"> & {
|
|
23
|
+
title: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export type UseConnectToRemoteResult<TRemote extends RemoteMethodsBase> = ConnectToRemoteState<TRemote> & {
|
|
27
|
+
/** The iframe element to render */
|
|
28
|
+
iframe: ReactNode;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Connects host (parent) to remote (child iframe) and renders the iframe.
|
|
32
|
+
* Call from the host app.
|
|
33
|
+
*
|
|
34
|
+
* @param options - Connection options including remote URL, host methods, and params
|
|
35
|
+
* @returns Object with `iframe` element, `remote` proxy, `isConnected` flag, and `error`
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* const { iframe, remote, isConnected } = useConnectToRemote({
|
|
39
|
+
* remoteUrl: "https://remote.example.com",
|
|
40
|
+
* methods: { navigateTo: (path) => router.navigate(path), ... },
|
|
41
|
+
* params: { userId: "123", theme: "dark" },
|
|
42
|
+
* })
|
|
43
|
+
* return <div>{iframe}</div>
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function useConnectToRemote<TRemote extends RemoteMethodsBase, THost extends HostMethodsBase, TParams extends RemoteParamsBase>(options: UseConnectToRemoteOptions<THost, TParams>): UseConnectToRemoteResult<TRemote>;
|
|
47
|
+
//# sourceMappingURL=useConnectToRemote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConnectToRemote.d.ts","sourceRoot":"","sources":["../../src/lib/useConnectToRemote.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAA;AAEvD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAEhB,WAAW,EACZ,MAAM,SAAS,CAAA;AAGhB,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,iBAAiB,IAC9D;IAAE,MAAM,EAAE,aAAa,CAAC,SAAS,CAAC;IAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;CAAE,GACjE;IAAE,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC7C;IAAE,MAAM,EAAE,aAAa,CAAC,IAAI,CAAA;CAAE,CAAA;AAElC,MAAM,MAAM,yBAAyB,CACnC,KAAK,SAAS,eAAe,EAC7B,OAAO,SAAS,gBAAgB,IAC9B,sBAAsB,CAAC,KAAK,CAAC,GAAG;IAClC,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAA;IACjB,wDAAwD;IACxD,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,qCAAqC;IACrC,eAAe,EAAE,MAAM,CAAA;IACvB,mCAAmC;IACnC,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CAC1F,CAAA;AAED,MAAM,MAAM,wBAAwB,CAAC,OAAO,SAAS,iBAAiB,IAAI,oBAAoB,CAAC,OAAO,CAAC,GAAG;IACxG,mCAAmC;IACnC,MAAM,EAAE,SAAS,CAAA;CAClB,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,SAAS,iBAAiB,EACjC,KAAK,SAAS,eAAe,EAC7B,OAAO,SAAS,gBAAgB,EAChC,OAAO,EAAE,yBAAyB,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,wBAAwB,CAAC,OAAO,CAAC,CA4CvF"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare function methodDef(): z.ZodObject<Record<string, never>>;
|
|
3
|
+
export declare function methodDef<R extends z.ZodTypeAny>(def: {
|
|
4
|
+
returns: R;
|
|
5
|
+
}): z.ZodObject<{
|
|
6
|
+
returns: R;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function methodDef<P extends z.ZodRawShape>(def: {
|
|
9
|
+
params: z.ZodObject<P>;
|
|
10
|
+
}): z.ZodObject<{
|
|
11
|
+
params: z.ZodObject<P>;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function methodDef<P extends z.ZodRawShape, R extends z.ZodTypeAny>(def: {
|
|
14
|
+
params: z.ZodObject<P>;
|
|
15
|
+
returns: R;
|
|
16
|
+
}): z.ZodObject<{
|
|
17
|
+
params: z.ZodObject<P>;
|
|
18
|
+
returns: R;
|
|
19
|
+
}>;
|
|
20
|
+
export declare const MethodDefInferredSchema: z.ZodObject<{
|
|
21
|
+
params: z.ZodOptional<z.ZodUnknown>;
|
|
22
|
+
returns: z.ZodOptional<z.ZodUnknown>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
export type MethodDefInferred = z.infer<typeof MethodDefInferredSchema>;
|
|
25
|
+
export type MethodDefOutput<S extends z.ZodTypeAny> = z.infer<S>;
|
|
26
|
+
export type MethodParamsType<S extends z.ZodTypeAny> = MethodDefOutput<S> extends {
|
|
27
|
+
params: infer P;
|
|
28
|
+
} ? P : never;
|
|
29
|
+
export type MethodReturnType<S extends z.ZodTypeAny> = MethodDefOutput<S> extends {
|
|
30
|
+
returns: infer R;
|
|
31
|
+
} ? Promise<R> : Promise<void>;
|
|
32
|
+
export type MethodType<S extends z.ZodTypeAny> = MethodParamsType<S> extends never ? () => MethodReturnType<S> : (params: MethodParamsType<S>) => MethodReturnType<S>;
|
|
33
|
+
export type InferMethodsFromSchema<T extends Record<string, z.ZodTypeAny>> = {
|
|
34
|
+
[K in keyof T]: MethodType<T[K]>;
|
|
35
|
+
};
|
|
36
|
+
export type InferParamsFromSchema<T extends Record<string, z.ZodType<string>>> = {
|
|
37
|
+
[K in keyof T]: z.infer<T[K]>;
|
|
38
|
+
};
|
|
39
|
+
export type HostMethodsSchemaBase = Record<string, z.ZodType<MethodDefInferred>>;
|
|
40
|
+
export type RemoteMethodsSchemaBase = Record<string, z.ZodType<MethodDefInferred>>;
|
|
41
|
+
export type RemoteParamsSchemaBase = Record<string, z.ZodType<string>>;
|
|
42
|
+
export declare const ContractSchema: z.ZodObject<{
|
|
43
|
+
hostMethods: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
44
|
+
params: z.ZodOptional<z.ZodUnknown>;
|
|
45
|
+
returns: z.ZodOptional<z.ZodUnknown>;
|
|
46
|
+
}, z.core.$strip>>;
|
|
47
|
+
remoteMethods: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
48
|
+
params: z.ZodOptional<z.ZodUnknown>;
|
|
49
|
+
returns: z.ZodOptional<z.ZodUnknown>;
|
|
50
|
+
}, z.core.$strip>>;
|
|
51
|
+
remoteParams: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
export type ContractSchemaType = z.infer<typeof ContractSchema>;
|
|
54
|
+
export declare function mkZodContractSchema({ hostMethods, remoteMethods, remoteParams, }: {
|
|
55
|
+
hostMethods: HostMethodsSchemaBase;
|
|
56
|
+
remoteMethods: RemoteMethodsSchemaBase;
|
|
57
|
+
remoteParams: RemoteParamsSchemaBase;
|
|
58
|
+
}): z.ZodObject<{
|
|
59
|
+
hostMethods: z.ZodObject<{
|
|
60
|
+
[x: string]: z.ZodType<{
|
|
61
|
+
params?: unknown;
|
|
62
|
+
returns?: unknown;
|
|
63
|
+
}, unknown, z.core.$ZodTypeInternals<{
|
|
64
|
+
params?: unknown;
|
|
65
|
+
returns?: unknown;
|
|
66
|
+
}, unknown>>;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
remoteMethods: z.ZodObject<{
|
|
69
|
+
[x: string]: z.ZodType<{
|
|
70
|
+
params?: unknown;
|
|
71
|
+
returns?: unknown;
|
|
72
|
+
}, unknown, z.core.$ZodTypeInternals<{
|
|
73
|
+
params?: unknown;
|
|
74
|
+
returns?: unknown;
|
|
75
|
+
}, unknown>>;
|
|
76
|
+
}, z.core.$strip>;
|
|
77
|
+
remoteParams: z.ZodObject<{
|
|
78
|
+
[x: string]: z.ZodType<string, unknown, z.core.$ZodTypeInternals<string, unknown>>;
|
|
79
|
+
}, z.core.$strip>;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
//# sourceMappingURL=zod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/lib/zod.ts"],"names":[],"mappings":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leancodepl/cyberware-contract",
|
|
3
|
+
"version": "10.1.3",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
"./package.json": "./package.json",
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public",
|
|
19
|
+
"registry": "https://registry.npmjs.org/"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=22.0.0"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"penpal": "^7.0.0",
|
|
26
|
+
"semver": "^7.0.0",
|
|
27
|
+
"zod": "^4.0.5"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@testing-library/react": "*",
|
|
31
|
+
"react": "*",
|
|
32
|
+
"react-dom": "*",
|
|
33
|
+
"vitest": "*"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/leancodepl/js_corelibrary.git",
|
|
38
|
+
"directory": "packages/cyberware/cyberware-contract"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/leancodepl/js_corelibrary",
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/leancodepl/js_corelibrary/issues"
|
|
43
|
+
},
|
|
44
|
+
"description": "Creates type-safe contracts between a host app and a remote iframe app (e.g., Replit embed). Uses `postMessage` via Penpal for secure cross-origin communication.",
|
|
45
|
+
"keywords": [
|
|
46
|
+
"iframe",
|
|
47
|
+
"contract",
|
|
48
|
+
"embed",
|
|
49
|
+
"penpal",
|
|
50
|
+
"typescript",
|
|
51
|
+
"javascript",
|
|
52
|
+
"leancode",
|
|
53
|
+
"react"
|
|
54
|
+
],
|
|
55
|
+
"author": {
|
|
56
|
+
"name": "LeanCode",
|
|
57
|
+
"url": "https://leancode.co"
|
|
58
|
+
},
|
|
59
|
+
"sideEffects": false,
|
|
60
|
+
"files": [
|
|
61
|
+
"dist",
|
|
62
|
+
"CHANGELOG.md",
|
|
63
|
+
"!**/*.tsbuildinfo"
|
|
64
|
+
]
|
|
65
|
+
}
|