@bstage-sdk/bridge 0.0.0-stage → 0.9.0
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 +21 -0
- package/README.md +194 -2
- package/dist/chunk-6LV7HEN4.js +583 -0
- package/dist/chunk-KQMJY4ZH.js +266 -0
- package/dist/createSrcdoc-bOoxttPz.d.cts +52 -0
- package/dist/createSrcdoc-bOoxttPz.d.ts +52 -0
- package/dist/frame.cjs +306 -0
- package/dist/frame.d.cts +72 -0
- package/dist/frame.d.ts +72 -0
- package/dist/frame.js +21 -0
- package/dist/host.cjs +1399 -0
- package/dist/host.d.cts +262 -0
- package/dist/host.d.ts +262 -0
- package/dist/host.js +594 -0
- package/dist/index.cjs +673 -0
- package/dist/index.d.cts +32 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +63 -0
- package/dist/messages-9N0GFq5b.d.cts +186 -0
- package/dist/messages-9N0GFq5b.d.ts +186 -0
- package/package.json +68 -3
package/dist/frame.d.cts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { g as BridgeInit, j as BridgeRequestType, i as BridgeRequestMap, e as BridgeEventMap } from './messages-9N0GFq5b.cjs';
|
|
2
|
+
|
|
3
|
+
/** 프레임 런타임 설정 — srcdoc 부트스트랩이 상수로 넘긴다. */
|
|
4
|
+
interface BridgeClientConfig {
|
|
5
|
+
readonly session: string;
|
|
6
|
+
readonly hostOrigin: string;
|
|
7
|
+
}
|
|
8
|
+
/** 이벤트 구독 해제 함수. */
|
|
9
|
+
type Unsubscribe = () => void;
|
|
10
|
+
/**
|
|
11
|
+
* 프레임 안 브리지 클라이언트. `globalThis.__bstage_bridge__`에 설치된다.
|
|
12
|
+
* core·react 어댑터는 이 모양을 구조적으로 읽는다(패키지 의존 없음).
|
|
13
|
+
*/
|
|
14
|
+
interface BridgeClient {
|
|
15
|
+
readonly version: 1;
|
|
16
|
+
readonly hostOrigin: string;
|
|
17
|
+
/** init 수신 시 resolve. reject하지 않는다(호스트가 늦게 붙으면 ready를 계속 재전송한다). */
|
|
18
|
+
readonly ready: Promise<BridgeInit>;
|
|
19
|
+
/** 지금까지 받은 init(이후 locale·member·theme·slot.context 이벤트가 반영된 값). 수신 전이면 undefined. */
|
|
20
|
+
getInit(): BridgeInit | undefined;
|
|
21
|
+
request<T extends BridgeRequestType>(type: T, payload: BridgeRequestMap[T]['req']): Promise<BridgeRequestMap[T]['res']>;
|
|
22
|
+
on<E extends keyof BridgeEventMap>(type: E, fn: (payload: BridgeEventMap[E]) => void): Unsubscribe;
|
|
23
|
+
/** 브리지 경유 fetch(`createBridgeFetch(this)`). */
|
|
24
|
+
readonly fetch: typeof globalThis.fetch;
|
|
25
|
+
}
|
|
26
|
+
/** 프레임 런타임이 쓰는 전역의 최소 모양 — 테스트에서 가짜 창을 넘길 수 있게 한다. */
|
|
27
|
+
interface RuntimeGlobal {
|
|
28
|
+
parent: {
|
|
29
|
+
postMessage(message: unknown, targetOrigin: string): void;
|
|
30
|
+
} | null;
|
|
31
|
+
addEventListener(type: 'message', fn: (ev: {
|
|
32
|
+
source: unknown;
|
|
33
|
+
origin: string;
|
|
34
|
+
data: unknown;
|
|
35
|
+
}) => void): void;
|
|
36
|
+
crypto?: {
|
|
37
|
+
getRandomValues<T extends ArrayBufferView | null>(array: T): T;
|
|
38
|
+
};
|
|
39
|
+
__bstage_bridge__?: BridgeClient;
|
|
40
|
+
}
|
|
41
|
+
/** `createBridgeFetch`가 요구하는 클라이언트 부분. */
|
|
42
|
+
type BridgeRequester = Pick<BridgeClient, 'request'>;
|
|
43
|
+
|
|
44
|
+
interface CreateBridgeClientOptions extends Partial<BridgeClientConfig> {
|
|
45
|
+
/** 프레임 전역. 기본 `globalThis`(테스트용). */
|
|
46
|
+
readonly global?: RuntimeGlobal;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 프레임 브리지 클라이언트를 만들고 `globalThis.__bstage_bridge__`에 설치한다.
|
|
50
|
+
* 이미 설치돼 있으면 그 인스턴스를 돌려준다.
|
|
51
|
+
*
|
|
52
|
+
* 세션·hostOrigin을 생략하면 srcdoc 부트스트랩이 심은 `__bstage_bridge_config__`를 읽는다.
|
|
53
|
+
* 보통은 부트스트랩이 직접 호출하므로 템플릿 코드가 부를 일은 없다.
|
|
54
|
+
*/
|
|
55
|
+
declare function createBridgeClient(options?: CreateBridgeClientOptions): BridgeClient;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 브리지 경유 fetch를 만든다. 요청을 `fetch` 브리지 요청으로 바꾸고, 호스트가 돌려준
|
|
59
|
+
* `{ status, statusText, headers, bodyText }`로 `Response`를 다시 만든다.
|
|
60
|
+
*
|
|
61
|
+
* **자기완결 함수다** — `bridgeRuntime`과 함께 srcdoc에 `toString()`으로 심긴다(runtime.ts 주석 참고).
|
|
62
|
+
*
|
|
63
|
+
* 제약(호스트 fetch 정책과 프레임에서 할 수 있는 일의 경계):
|
|
64
|
+
* - body는 문자열·`URLSearchParams`·null만. FormData·Blob·스트림은 `TypeError`.
|
|
65
|
+
* - `Request` 입력은 url·method·headers만 읽는다(본문은 동기로 읽을 수 없어 `init.body`로 넘긴다).
|
|
66
|
+
* - `credentials`·`mode`·`cache` 등은 무시된다 — 호스트가 `credentials: "same-origin"`으로 보낸다.
|
|
67
|
+
* - `signal`은 프레임 쪽 대기만 끊는다(호스트 요청은 취소되지 않는다).
|
|
68
|
+
* - 응답 헤더는 content-type만 온다.
|
|
69
|
+
*/
|
|
70
|
+
declare function createBridgeFetch(client: BridgeRequester): typeof globalThis.fetch;
|
|
71
|
+
|
|
72
|
+
export { type BridgeClient, type BridgeClientConfig, type BridgeRequester, type CreateBridgeClientOptions, type Unsubscribe, createBridgeClient, createBridgeFetch };
|
package/dist/frame.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { g as BridgeInit, j as BridgeRequestType, i as BridgeRequestMap, e as BridgeEventMap } from './messages-9N0GFq5b.js';
|
|
2
|
+
|
|
3
|
+
/** 프레임 런타임 설정 — srcdoc 부트스트랩이 상수로 넘긴다. */
|
|
4
|
+
interface BridgeClientConfig {
|
|
5
|
+
readonly session: string;
|
|
6
|
+
readonly hostOrigin: string;
|
|
7
|
+
}
|
|
8
|
+
/** 이벤트 구독 해제 함수. */
|
|
9
|
+
type Unsubscribe = () => void;
|
|
10
|
+
/**
|
|
11
|
+
* 프레임 안 브리지 클라이언트. `globalThis.__bstage_bridge__`에 설치된다.
|
|
12
|
+
* core·react 어댑터는 이 모양을 구조적으로 읽는다(패키지 의존 없음).
|
|
13
|
+
*/
|
|
14
|
+
interface BridgeClient {
|
|
15
|
+
readonly version: 1;
|
|
16
|
+
readonly hostOrigin: string;
|
|
17
|
+
/** init 수신 시 resolve. reject하지 않는다(호스트가 늦게 붙으면 ready를 계속 재전송한다). */
|
|
18
|
+
readonly ready: Promise<BridgeInit>;
|
|
19
|
+
/** 지금까지 받은 init(이후 locale·member·theme·slot.context 이벤트가 반영된 값). 수신 전이면 undefined. */
|
|
20
|
+
getInit(): BridgeInit | undefined;
|
|
21
|
+
request<T extends BridgeRequestType>(type: T, payload: BridgeRequestMap[T]['req']): Promise<BridgeRequestMap[T]['res']>;
|
|
22
|
+
on<E extends keyof BridgeEventMap>(type: E, fn: (payload: BridgeEventMap[E]) => void): Unsubscribe;
|
|
23
|
+
/** 브리지 경유 fetch(`createBridgeFetch(this)`). */
|
|
24
|
+
readonly fetch: typeof globalThis.fetch;
|
|
25
|
+
}
|
|
26
|
+
/** 프레임 런타임이 쓰는 전역의 최소 모양 — 테스트에서 가짜 창을 넘길 수 있게 한다. */
|
|
27
|
+
interface RuntimeGlobal {
|
|
28
|
+
parent: {
|
|
29
|
+
postMessage(message: unknown, targetOrigin: string): void;
|
|
30
|
+
} | null;
|
|
31
|
+
addEventListener(type: 'message', fn: (ev: {
|
|
32
|
+
source: unknown;
|
|
33
|
+
origin: string;
|
|
34
|
+
data: unknown;
|
|
35
|
+
}) => void): void;
|
|
36
|
+
crypto?: {
|
|
37
|
+
getRandomValues<T extends ArrayBufferView | null>(array: T): T;
|
|
38
|
+
};
|
|
39
|
+
__bstage_bridge__?: BridgeClient;
|
|
40
|
+
}
|
|
41
|
+
/** `createBridgeFetch`가 요구하는 클라이언트 부분. */
|
|
42
|
+
type BridgeRequester = Pick<BridgeClient, 'request'>;
|
|
43
|
+
|
|
44
|
+
interface CreateBridgeClientOptions extends Partial<BridgeClientConfig> {
|
|
45
|
+
/** 프레임 전역. 기본 `globalThis`(테스트용). */
|
|
46
|
+
readonly global?: RuntimeGlobal;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 프레임 브리지 클라이언트를 만들고 `globalThis.__bstage_bridge__`에 설치한다.
|
|
50
|
+
* 이미 설치돼 있으면 그 인스턴스를 돌려준다.
|
|
51
|
+
*
|
|
52
|
+
* 세션·hostOrigin을 생략하면 srcdoc 부트스트랩이 심은 `__bstage_bridge_config__`를 읽는다.
|
|
53
|
+
* 보통은 부트스트랩이 직접 호출하므로 템플릿 코드가 부를 일은 없다.
|
|
54
|
+
*/
|
|
55
|
+
declare function createBridgeClient(options?: CreateBridgeClientOptions): BridgeClient;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 브리지 경유 fetch를 만든다. 요청을 `fetch` 브리지 요청으로 바꾸고, 호스트가 돌려준
|
|
59
|
+
* `{ status, statusText, headers, bodyText }`로 `Response`를 다시 만든다.
|
|
60
|
+
*
|
|
61
|
+
* **자기완결 함수다** — `bridgeRuntime`과 함께 srcdoc에 `toString()`으로 심긴다(runtime.ts 주석 참고).
|
|
62
|
+
*
|
|
63
|
+
* 제약(호스트 fetch 정책과 프레임에서 할 수 있는 일의 경계):
|
|
64
|
+
* - body는 문자열·`URLSearchParams`·null만. FormData·Blob·스트림은 `TypeError`.
|
|
65
|
+
* - `Request` 입력은 url·method·headers만 읽는다(본문은 동기로 읽을 수 없어 `init.body`로 넘긴다).
|
|
66
|
+
* - `credentials`·`mode`·`cache` 등은 무시된다 — 호스트가 `credentials: "same-origin"`으로 보낸다.
|
|
67
|
+
* - `signal`은 프레임 쪽 대기만 끊는다(호스트 요청은 취소되지 않는다).
|
|
68
|
+
* - 응답 헤더는 content-type만 온다.
|
|
69
|
+
*/
|
|
70
|
+
declare function createBridgeFetch(client: BridgeRequester): typeof globalThis.fetch;
|
|
71
|
+
|
|
72
|
+
export { type BridgeClient, type BridgeClientConfig, type BridgeRequester, type CreateBridgeClientOptions, type Unsubscribe, createBridgeClient, createBridgeFetch };
|
package/dist/frame.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bridgeRuntime,
|
|
3
|
+
createBridgeFetch
|
|
4
|
+
} from "./chunk-KQMJY4ZH.js";
|
|
5
|
+
|
|
6
|
+
// src/frame/createBridgeClient.ts
|
|
7
|
+
var BRIDGE_CONFIG_GLOBAL = "__bstage_bridge_config__";
|
|
8
|
+
function createBridgeClient(options = {}) {
|
|
9
|
+
const g = options.global ?? globalThis;
|
|
10
|
+
const installed = g[BRIDGE_CONFIG_GLOBAL] ?? {};
|
|
11
|
+
const session = options.session ?? installed.session;
|
|
12
|
+
const hostOrigin = options.hostOrigin ?? installed.hostOrigin;
|
|
13
|
+
if (typeof session !== "string" || typeof hostOrigin !== "string") {
|
|
14
|
+
throw new TypeError("[bstage-bridge] session\uACFC hostOrigin\uC774 \uD544\uC694\uD569\uB2C8\uB2E4");
|
|
15
|
+
}
|
|
16
|
+
return bridgeRuntime(g, createBridgeFetch, { session, hostOrigin });
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
createBridgeClient,
|
|
20
|
+
createBridgeFetch
|
|
21
|
+
};
|