@pioneercompany/app-sdk 0.1.1 → 0.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/README.md +36 -0
- package/dist/client/index.d.ts +13 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +73 -2
- package/dist/client/index.js.map +1 -1
- package/dist-cjs/client/index.d.ts +13 -0
- package/dist-cjs/client/index.d.ts.map +1 -1
- package/dist-cjs/client/index.js +73 -2
- package/dist-cjs/client/index.js.map +1 -1
- package/docs/contract.md +41 -1
- package/docs/errors.md +4 -0
- package/fixtures/protocol.json +2 -1
- package/package.json +1 -1
- package/src/client/index.ts +81 -2
package/README.md
CHANGED
|
@@ -35,6 +35,38 @@ unsubscribe();
|
|
|
35
35
|
app.dispose();
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
Inside Pioneer Desktop, move the current application view without reloading it:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
await app.view.setPlacement('fullscreen');
|
|
42
|
+
await app.view.setPlacement('bottom');
|
|
43
|
+
await app.view.setPlacement('right');
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`fullscreen` fills Pioneer's application area using the expanded placement; it does not change OS window fullscreen. Opening from the Apps
|
|
47
|
+
page starts in this placement. The method works in installed and direct dev
|
|
48
|
+
views on a Desktop version supporting the presentation bridge. It requires no
|
|
49
|
+
backend credentials. Calls resolve after Desktop applies the placement; an
|
|
50
|
+
unavailable host times out after five seconds (`sdk.view_timeout`). At most 16
|
|
51
|
+
calls may be pending per client (`sdk.view_overloaded`); `dispose()` rejects
|
|
52
|
+
remaining calls with `sdk.closed`. Invalid placement rejects with
|
|
53
|
+
`sdk.invalid_placement`; a synchronous transport failure is `sdk.view_unavailable`.
|
|
54
|
+
|
|
55
|
+
To close this application view:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
app.view.close();
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
This closes the current presentation. The application stays installed and its
|
|
62
|
+
backend remains managed by Gateway, following the Desktop view
|
|
63
|
+
lifecycle. `close()` sends a request and returns `void`: it cannot acknowledge
|
|
64
|
+
completion to a JavaScript context being destroyed. Save state before calling
|
|
65
|
+
it. It throws `sdk.closed` after disposal or `sdk.view_unavailable` on a
|
|
66
|
+
synchronous transport failure. A browser or older Desktop without the bridge
|
|
67
|
+
may ignore the request. `app.dispose()` only releases the SDK client; it does
|
|
68
|
+
not close the view.
|
|
69
|
+
|
|
38
70
|
`connectApp` installs its listener synchronously before its promise is awaited.
|
|
39
71
|
Call it during browser module initialization, before iframe load or the dev
|
|
40
72
|
page's DOMContentLoaded. SSR imports are safe; connecting requires a browser.
|
|
@@ -44,6 +76,10 @@ immediately delivers an already known palette, then future updates. Connections
|
|
|
44
76
|
are independent and disposable. There is no handshake or resend request: a late
|
|
45
77
|
connection cannot recover a missed message. Theme grants no backend authority.
|
|
46
78
|
SDK does not mutate DOM/styles; applications apply data via their own state.
|
|
79
|
+
`theme.current` and subscriptions include the host's semantic `success`, `warning`,
|
|
80
|
+
`danger` and `info` colors when supplied. Use these for statuses rather than the
|
|
81
|
+
ordinary accent. They are optional for compatibility with older hosts; the SDK
|
|
82
|
+
validates present values but does not synthesize missing colors.
|
|
47
83
|
URL methods return strings, reject external/protocol-relative/traversal paths,
|
|
48
84
|
and interpret a leading slash relative to the configured view root. A base URL
|
|
49
85
|
is required (explicit option or HTML base element), including outside Pioneer.
|
package/dist/client/index.d.ts
CHANGED
|
@@ -7,12 +7,25 @@ export interface Theme {
|
|
|
7
7
|
readonly border: string;
|
|
8
8
|
readonly accent: string;
|
|
9
9
|
readonly "accent-foreground": string;
|
|
10
|
+
/** Semantic status colors; absent on older Pioneer hosts. */
|
|
11
|
+
readonly success?: string;
|
|
12
|
+
readonly warning?: string;
|
|
13
|
+
readonly danger?: string;
|
|
14
|
+
readonly info?: string;
|
|
10
15
|
}
|
|
11
16
|
export interface ConnectAppOptions {
|
|
12
17
|
/** Exact grant root, absolute or relative to document URL; must end in /. */
|
|
13
18
|
baseUrl?: string;
|
|
14
19
|
}
|
|
20
|
+
/** Fullscreen fills Pioneer's application area, not the operating system screen. */
|
|
21
|
+
export type AppPlacement = "fullscreen" | "bottom" | "right";
|
|
15
22
|
export interface AppClient {
|
|
23
|
+
readonly view: {
|
|
24
|
+
/** Moves this open view without navigating or restarting the application. */
|
|
25
|
+
setPlacement(placement: AppPlacement): Promise<void>;
|
|
26
|
+
/** Requests closing this application view. No acknowledgement. */
|
|
27
|
+
close(): void;
|
|
28
|
+
};
|
|
16
29
|
readonly theme: {
|
|
17
30
|
readonly current: Readonly<Theme> | null;
|
|
18
31
|
/** Delivers current synchronously if known, then future updates. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC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,CAwIpF"}
|
package/dist/client/index.js
CHANGED
|
@@ -23,6 +23,13 @@ export async function connectApp(options = {}) {
|
|
|
23
23
|
let disposed = false;
|
|
24
24
|
let current = null;
|
|
25
25
|
const listeners = new Set();
|
|
26
|
+
const pending = new Map();
|
|
27
|
+
// Available even in opaque sandbox origins (no secure-context requirement).
|
|
28
|
+
const requestId = () => Array.from(crypto.getRandomValues(new Uint8Array(16)), byte => byte.toString(16).padStart(2, "0")).join("");
|
|
29
|
+
const postViewRequest = (message) => {
|
|
30
|
+
const direct = window.parent === window;
|
|
31
|
+
window.parent.postMessage(message, direct ? window.location.origin : "*");
|
|
32
|
+
};
|
|
26
33
|
const receive = (event) => {
|
|
27
34
|
if (disposed)
|
|
28
35
|
return;
|
|
@@ -35,6 +42,15 @@ export async function connectApp(options = {}) {
|
|
|
35
42
|
// Embedded origin may be opaque; direct dev views use self + exact origin.
|
|
36
43
|
// A theme message never authenticates a user or a backend request.
|
|
37
44
|
const data = event.data;
|
|
45
|
+
if (data?.type === "pioneer.view.result" && typeof data.id === "string") {
|
|
46
|
+
const call = pending.get(data.id);
|
|
47
|
+
if (call && data.placement === call.placement) {
|
|
48
|
+
pending.delete(data.id);
|
|
49
|
+
clearTimeout(call.timer);
|
|
50
|
+
call.resolve();
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
38
54
|
if (!data || data.type !== "pioneer.theme" || !data.palette)
|
|
39
55
|
return;
|
|
40
56
|
const value = data.palette;
|
|
@@ -45,7 +61,17 @@ export async function connectApp(options = {}) {
|
|
|
45
61
|
if (typeof value[key] !== "string" || value[key].length > 128 || !CSS.supports("color", value[key]))
|
|
46
62
|
return;
|
|
47
63
|
}
|
|
48
|
-
|
|
64
|
+
const statusColors = ["success", "warning", "danger", "info"];
|
|
65
|
+
for (const key of statusColors) {
|
|
66
|
+
if (value[key] !== undefined &&
|
|
67
|
+
(typeof value[key] !== "string" || value[key].length > 128 || !CSS.supports("color", value[key])))
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
current = Object.freeze({
|
|
71
|
+
appearance: value.appearance,
|
|
72
|
+
...Object.fromEntries(colors.map(key => [key, value[key]])),
|
|
73
|
+
...Object.fromEntries(statusColors.filter(key => value[key] !== undefined).map(key => [key, value[key]])),
|
|
74
|
+
});
|
|
49
75
|
for (const listener of [...listeners]) {
|
|
50
76
|
if (disposed)
|
|
51
77
|
break;
|
|
@@ -74,6 +100,42 @@ export async function connectApp(options = {}) {
|
|
|
74
100
|
return target.href;
|
|
75
101
|
};
|
|
76
102
|
return Object.freeze({
|
|
103
|
+
view: Object.freeze({
|
|
104
|
+
setPlacement(placement) {
|
|
105
|
+
if (disposed)
|
|
106
|
+
return Promise.reject(failure("sdk.closed"));
|
|
107
|
+
if (!["fullscreen", "bottom", "right"].includes(placement))
|
|
108
|
+
return Promise.reject(failure("sdk.invalid_placement"));
|
|
109
|
+
if (pending.size >= 16)
|
|
110
|
+
return Promise.reject(failure("sdk.view_overloaded"));
|
|
111
|
+
const id = requestId();
|
|
112
|
+
return new Promise((resolve, reject) => {
|
|
113
|
+
const timer = setTimeout(() => {
|
|
114
|
+
pending.delete(id);
|
|
115
|
+
reject(failure("sdk.view_timeout"));
|
|
116
|
+
}, 5000);
|
|
117
|
+
pending.set(id, { placement, resolve, reject, timer });
|
|
118
|
+
try {
|
|
119
|
+
postViewRequest({ type: "pioneer.view.setPlacement", id, placement });
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
pending.delete(id);
|
|
123
|
+
clearTimeout(timer);
|
|
124
|
+
reject(failure("sdk.view_unavailable"));
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
close() {
|
|
129
|
+
if (disposed)
|
|
130
|
+
throw failure("sdk.closed");
|
|
131
|
+
try {
|
|
132
|
+
postViewRequest({ type: "pioneer.view.close", id: requestId() });
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
throw failure("sdk.view_unavailable");
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
}),
|
|
77
139
|
theme: Object.freeze({
|
|
78
140
|
get current() { return current; },
|
|
79
141
|
subscribe(listener) {
|
|
@@ -95,7 +157,16 @@ export async function connectApp(options = {}) {
|
|
|
95
157
|
target.protocol = target.protocol === "https:" ? "wss:" : "ws:";
|
|
96
158
|
return target.href;
|
|
97
159
|
},
|
|
98
|
-
dispose() {
|
|
160
|
+
dispose() {
|
|
161
|
+
disposed = true;
|
|
162
|
+
listeners.clear();
|
|
163
|
+
window.removeEventListener("message", receive);
|
|
164
|
+
for (const call of pending.values()) {
|
|
165
|
+
clearTimeout(call.timer);
|
|
166
|
+
call.reject(failure("sdk.closed"));
|
|
167
|
+
}
|
|
168
|
+
pending.clear();
|
|
169
|
+
},
|
|
99
170
|
});
|
|
100
171
|
}
|
|
101
172
|
//# sourceMappingURL=index.js.map
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAuC3C,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,UAA6B,EAAE;IAC9D,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,MAAM,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACzE,4EAA4E;IAC5E,+EAA+E;IAC/E,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,IAAI,QAAQ,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,C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MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;YAChE,OAAO,MAAM,CAAC,IAAI,CAAC;QACrB,CAAC;QACD,OAAO;YACL,QAAQ,GAAG,IAAI,CAAC;YAChB,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YAC/C,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;gBACpC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACzB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;YACrC,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -7,12 +7,25 @@ export interface Theme {
|
|
|
7
7
|
readonly border: string;
|
|
8
8
|
readonly accent: string;
|
|
9
9
|
readonly "accent-foreground": string;
|
|
10
|
+
/** Semantic status colors; absent on older Pioneer hosts. */
|
|
11
|
+
readonly success?: string;
|
|
12
|
+
readonly warning?: string;
|
|
13
|
+
readonly danger?: string;
|
|
14
|
+
readonly info?: string;
|
|
10
15
|
}
|
|
11
16
|
export interface ConnectAppOptions {
|
|
12
17
|
/** Exact grant root, absolute or relative to document URL; must end in /. */
|
|
13
18
|
baseUrl?: string;
|
|
14
19
|
}
|
|
20
|
+
/** Fullscreen fills Pioneer's application area, not the operating system screen. */
|
|
21
|
+
export type AppPlacement = "fullscreen" | "bottom" | "right";
|
|
15
22
|
export interface AppClient {
|
|
23
|
+
readonly view: {
|
|
24
|
+
/** Moves this open view without navigating or restarting the application. */
|
|
25
|
+
setPlacement(placement: AppPlacement): Promise<void>;
|
|
26
|
+
/** Requests closing this application view. No acknowledgement. */
|
|
27
|
+
close(): void;
|
|
28
|
+
};
|
|
16
29
|
readonly theme: {
|
|
17
30
|
readonly current: Readonly<Theme> | null;
|
|
18
31
|
/** Delivers current synchronously if known, then future updates. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,6DAA6D;IAC7D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AACD,MAAM,WAAW,iBAAiB;IAChC,6EAA6E;IAC7E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AACD,oFAAoF;AACpF,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,QAAQ,GAAG,OAAO,CAAC;AAC7D,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE;QACb,6EAA6E;QAC7E,YAAY,CAAC,SAAS,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QACrD,kEAAkE;QAClE,KAAK,IAAI,IAAI,CAAC;KACf,CAAC;IACF,QAAQ,CAAC,KAAK,EAAE;QACd,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;QACzC,oEAAoE;QACpE,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;KACnE,CAAC;IACF,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACnC,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,+EAA+E;AAC/E,wBAAsB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,SAAS,CAAC,CAwIpF"}
|
package/dist-cjs/client/index.js
CHANGED
|
@@ -28,6 +28,13 @@ async function connectApp(options = {}) {
|
|
|
28
28
|
let disposed = false;
|
|
29
29
|
let current = null;
|
|
30
30
|
const listeners = new Set();
|
|
31
|
+
const pending = new Map();
|
|
32
|
+
// Available even in opaque sandbox origins (no secure-context requirement).
|
|
33
|
+
const requestId = () => Array.from(crypto.getRandomValues(new Uint8Array(16)), byte => byte.toString(16).padStart(2, "0")).join("");
|
|
34
|
+
const postViewRequest = (message) => {
|
|
35
|
+
const direct = window.parent === window;
|
|
36
|
+
window.parent.postMessage(message, direct ? window.location.origin : "*");
|
|
37
|
+
};
|
|
31
38
|
const receive = (event) => {
|
|
32
39
|
if (disposed)
|
|
33
40
|
return;
|
|
@@ -40,6 +47,15 @@ async function connectApp(options = {}) {
|
|
|
40
47
|
// Embedded origin may be opaque; direct dev views use self + exact origin.
|
|
41
48
|
// A theme message never authenticates a user or a backend request.
|
|
42
49
|
const data = event.data;
|
|
50
|
+
if (data?.type === "pioneer.view.result" && typeof data.id === "string") {
|
|
51
|
+
const call = pending.get(data.id);
|
|
52
|
+
if (call && data.placement === call.placement) {
|
|
53
|
+
pending.delete(data.id);
|
|
54
|
+
clearTimeout(call.timer);
|
|
55
|
+
call.resolve();
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
43
59
|
if (!data || data.type !== "pioneer.theme" || !data.palette)
|
|
44
60
|
return;
|
|
45
61
|
const value = data.palette;
|
|
@@ -50,7 +66,17 @@ async function connectApp(options = {}) {
|
|
|
50
66
|
if (typeof value[key] !== "string" || value[key].length > 128 || !CSS.supports("color", value[key]))
|
|
51
67
|
return;
|
|
52
68
|
}
|
|
53
|
-
|
|
69
|
+
const statusColors = ["success", "warning", "danger", "info"];
|
|
70
|
+
for (const key of statusColors) {
|
|
71
|
+
if (value[key] !== undefined &&
|
|
72
|
+
(typeof value[key] !== "string" || value[key].length > 128 || !CSS.supports("color", value[key])))
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
current = Object.freeze({
|
|
76
|
+
appearance: value.appearance,
|
|
77
|
+
...Object.fromEntries(colors.map(key => [key, value[key]])),
|
|
78
|
+
...Object.fromEntries(statusColors.filter(key => value[key] !== undefined).map(key => [key, value[key]])),
|
|
79
|
+
});
|
|
54
80
|
for (const listener of [...listeners]) {
|
|
55
81
|
if (disposed)
|
|
56
82
|
break;
|
|
@@ -79,6 +105,42 @@ async function connectApp(options = {}) {
|
|
|
79
105
|
return target.href;
|
|
80
106
|
};
|
|
81
107
|
return Object.freeze({
|
|
108
|
+
view: Object.freeze({
|
|
109
|
+
setPlacement(placement) {
|
|
110
|
+
if (disposed)
|
|
111
|
+
return Promise.reject((0, error_js_1.failure)("sdk.closed"));
|
|
112
|
+
if (!["fullscreen", "bottom", "right"].includes(placement))
|
|
113
|
+
return Promise.reject((0, error_js_1.failure)("sdk.invalid_placement"));
|
|
114
|
+
if (pending.size >= 16)
|
|
115
|
+
return Promise.reject((0, error_js_1.failure)("sdk.view_overloaded"));
|
|
116
|
+
const id = requestId();
|
|
117
|
+
return new Promise((resolve, reject) => {
|
|
118
|
+
const timer = setTimeout(() => {
|
|
119
|
+
pending.delete(id);
|
|
120
|
+
reject((0, error_js_1.failure)("sdk.view_timeout"));
|
|
121
|
+
}, 5000);
|
|
122
|
+
pending.set(id, { placement, resolve, reject, timer });
|
|
123
|
+
try {
|
|
124
|
+
postViewRequest({ type: "pioneer.view.setPlacement", id, placement });
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
pending.delete(id);
|
|
128
|
+
clearTimeout(timer);
|
|
129
|
+
reject((0, error_js_1.failure)("sdk.view_unavailable"));
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
close() {
|
|
134
|
+
if (disposed)
|
|
135
|
+
throw (0, error_js_1.failure)("sdk.closed");
|
|
136
|
+
try {
|
|
137
|
+
postViewRequest({ type: "pioneer.view.close", id: requestId() });
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
throw (0, error_js_1.failure)("sdk.view_unavailable");
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
}),
|
|
82
144
|
theme: Object.freeze({
|
|
83
145
|
get current() { return current; },
|
|
84
146
|
subscribe(listener) {
|
|
@@ -100,7 +162,16 @@ async function connectApp(options = {}) {
|
|
|
100
162
|
target.protocol = target.protocol === "https:" ? "wss:" : "ws:";
|
|
101
163
|
return target.href;
|
|
102
164
|
},
|
|
103
|
-
dispose() {
|
|
165
|
+
dispose() {
|
|
166
|
+
disposed = true;
|
|
167
|
+
listeners.clear();
|
|
168
|
+
window.removeEventListener("message", receive);
|
|
169
|
+
for (const call of pending.values()) {
|
|
170
|
+
clearTimeout(call.timer);
|
|
171
|
+
call.reject((0, error_js_1.failure)("sdk.closed"));
|
|
172
|
+
}
|
|
173
|
+
pending.clear();
|
|
174
|
+
},
|
|
104
175
|
});
|
|
105
176
|
}
|
|
106
177
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;AAyCA,gCAwIC;AAjLD,0CAAsC;AACtC,wCAA2C;AAAlC,wGAAA,YAAY,OAAA;AAuCrB,+EAA+E;AACxE,KAAK,UAAU,UAAU,CAAC,UAA6B,EAAE;IAC9D,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,MAAM,IAAA,kBAAO,EAAC,sBAAsB,CAAC,CAAC;IACzE,4EAA4E;IAC5E,+EAA+E;IAC/E,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,IAAI,QAAQ,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;IACjG,IAAI,CAAC,UAAU;QAAE,MAAM,IAAA,kBAAO,EAAC,uBAAuB,CAAC,CAAC;IACxD,IAAI,IAAS,CAAC;IACd,IAAI,CAAC;QAAC,IAAI,GAAG,IAAI,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAAC,CAAC;IACzD,MAAM,CAAC;QAAC,MAAM,IAAA,kBAAO,EAAC,iBAAiB,CAAC,CAAC;IAAC,CAAC;IAC3C,IAAI,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,G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AAE,CAAC;gBACpC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACzB,IAAI,CAAC,MAAM,CAAC,IAAA,kBAAO,EAAC,YAAY,CAAC,CAAC,CAAC;YACrC,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/docs/contract.md
CHANGED
|
@@ -38,7 +38,11 @@ view URL, never execution credentials.
|
|
|
38
38
|
The iframe parent, or the direct dev page's own window, posts
|
|
39
39
|
{type:'pioneer.theme',palette:{appearance,background,foreground,
|
|
40
40
|
muted,border,accent,'accent-foreground'}}. appearance is light/dark; colors are
|
|
41
|
-
valid CSS colors of at most 128 characters.
|
|
41
|
+
valid CSS colors of at most 128 characters. Optional `success`, `warning`, `danger`
|
|
42
|
+
and `info` tokens carry the active desktop theme's semantic status colors. A
|
|
43
|
+
present status token must obey the same CSS color validation. Older palettes
|
|
44
|
+
without these fields remain valid; the SDK preserves absence instead of inventing
|
|
45
|
+
colors. Embedded pages check source===parent
|
|
42
46
|
without demanding a non-opaque origin. Top-level pages check source===window AND
|
|
43
47
|
origin===location.origin. Theme is public styling data, never an identity proof.
|
|
44
48
|
No environment variable, handshake or ready event is involved. Import is inert
|
|
@@ -52,6 +56,42 @@ state/listeners; disposing one leaves another active. Reconnecting after disposa
|
|
|
52
56
|
starts null. No palette is synthesized outside Pioneer. SDK never mutates DOM,
|
|
53
57
|
styles or hydration markup: the application owns state and rendering.
|
|
54
58
|
|
|
59
|
+
## View presentation
|
|
60
|
+
|
|
61
|
+
Desktop exposes a per-WebView presentation bridge, independent of backend Host
|
|
62
|
+
API authority. `view.setPlacement` sends a window message
|
|
63
|
+
`{type:'pioneer.view.setPlacement', id, placement}` to the parent (installed
|
|
64
|
+
iframe) or the same window with its exact origin (direct dev page). Placement
|
|
65
|
+
is exactly `fullscreen`, `bottom` or `right`. Fullscreen fills Pioneer's app area,
|
|
66
|
+
using its existing expanded placement, not OS fullscreen. Apps page opening
|
|
67
|
+
defaults to fullscreen. Changing placement retains the page and its state.
|
|
68
|
+
|
|
69
|
+
`view.close()` sends `{type:'pioneer.view.close', id}` through the same window
|
|
70
|
+
transport. It closes only the current presentation through the existing Desktop
|
|
71
|
+
view-close lifecycle, without uninstalling, deleting data, quitting Desktop
|
|
72
|
+
or explicitly stopping the backend. It returns void and has no acknowledgement,
|
|
73
|
+
because closing destroys the caller's JavaScript context. State should be saved
|
|
74
|
+
before requesting close. An unsupported host may ignore it; synchronous
|
|
75
|
+
transport errors throw `sdk.view_unavailable`, and disposal throws `sdk.closed`.
|
|
76
|
+
|
|
77
|
+
Desktop accepts messages only from its own App iframe or the direct dev page's
|
|
78
|
+
same-origin window. A private per-WebView 128-bit token authenticates the narrow
|
|
79
|
+
native IPC hop; it is not a backend credential and is not passed to the installed
|
|
80
|
+
App iframe. Only setPlacement and close are admitted. The native queue has 32 slots
|
|
81
|
+
and is drained by the existing view publication refresh; revocation drops the
|
|
82
|
+
queue with its WebView.
|
|
83
|
+
|
|
84
|
+
Desktop acknowledges an applied request with
|
|
85
|
+
`{type:'pioneer.view.result', id, placement}` through the parent/self message
|
|
86
|
+
source. The SDK checks that source and (for dev) origin, then matches both ID
|
|
87
|
+
and placement. IDs contain 128 random bits from getRandomValues, including in
|
|
88
|
+
opaque sandbox origins. Calls time out after five seconds, never implicitly
|
|
89
|
+
retry, and have a limit of 16 pending per connection. A timeout leaves the
|
|
90
|
+
outcome unconfirmed; it does not guarantee that Desktop did not move the view.
|
|
91
|
+
Disposal clears timers and rejects pending calls. Older Desktop versions and
|
|
92
|
+
ordinary browsers have no presentation bridge; their calls time out. This
|
|
93
|
+
addition does not change Gateway JSON-RPC or grant the page execution credentials.
|
|
94
|
+
|
|
55
95
|
## Host transport
|
|
56
96
|
|
|
57
97
|
Backend-only WebSocket at bootstrap host_api.endpoint. Authorization: Bearer
|
package/docs/errors.md
CHANGED
|
@@ -17,6 +17,10 @@ host.operation_failed. Applications must tolerate future codes.
|
|
|
17
17
|
| sdk.unauthorized | Missing/invalid proxy credential |
|
|
18
18
|
| sdk.user_missing | No valid trusted principal after authentication |
|
|
19
19
|
| sdk.capability_unavailable | Host API absent or host.pty not advertised |
|
|
20
|
+
| sdk.invalid_placement | Placement is not fullscreen, bottom or right |
|
|
21
|
+
| sdk.view_overloaded | Too many pending view placement requests |
|
|
22
|
+
| sdk.view_timeout | Host placement acknowledgement did not arrive; outcome unconfirmed |
|
|
23
|
+
| sdk.view_unavailable | View message could not be sent |
|
|
20
24
|
| sdk.closed | Handle/context/transport has closed |
|
|
21
25
|
| sdk.capacity | Bounded queue/window/request capacity exceeded |
|
|
22
26
|
| sdk.limit | Input/request/sequence size limit exceeded |
|
package/fixtures/protocol.json
CHANGED
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"type": "pioneer.theme",
|
|
16
16
|
"palette": {
|
|
17
17
|
"appearance": "dark", "background": "#111111", "foreground": "#eeeeee",
|
|
18
|
-
"muted": "#999999", "border": "#333333", "accent": "#4488ff", "accent-foreground": "#ffffff"
|
|
18
|
+
"muted": "#999999", "border": "#333333", "accent": "#4488ff", "accent-foreground": "#ffffff",
|
|
19
|
+
"success": "#22aa66", "warning": "#dd8800", "danger": "#dd3344", "info": "#3399dd"
|
|
19
20
|
}
|
|
20
21
|
},
|
|
21
22
|
"output": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneercompany/app-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Pioneer application client and Node.js backend SDK",
|
|
5
5
|
"repository": { "type": "git", "url": "git+https://github.com/pioneerdotai/pioneer-app-sdk-ts.git" },
|
|
6
6
|
"homepage": "https://github.com/pioneerdotai/pioneer-app-sdk-ts#readme",
|
package/src/client/index.ts
CHANGED
|
@@ -9,12 +9,25 @@ export interface Theme {
|
|
|
9
9
|
readonly border: string;
|
|
10
10
|
readonly accent: string;
|
|
11
11
|
readonly "accent-foreground": string;
|
|
12
|
+
/** Semantic status colors; absent on older Pioneer hosts. */
|
|
13
|
+
readonly success?: string;
|
|
14
|
+
readonly warning?: string;
|
|
15
|
+
readonly danger?: string;
|
|
16
|
+
readonly info?: string;
|
|
12
17
|
}
|
|
13
18
|
export interface ConnectAppOptions {
|
|
14
19
|
/** Exact grant root, absolute or relative to document URL; must end in /. */
|
|
15
20
|
baseUrl?: string;
|
|
16
21
|
}
|
|
22
|
+
/** Fullscreen fills Pioneer's application area, not the operating system screen. */
|
|
23
|
+
export type AppPlacement = "fullscreen" | "bottom" | "right";
|
|
17
24
|
export interface AppClient {
|
|
25
|
+
readonly view: {
|
|
26
|
+
/** Moves this open view without navigating or restarting the application. */
|
|
27
|
+
setPlacement(placement: AppPlacement): Promise<void>;
|
|
28
|
+
/** Requests closing this application view. No acknowledgement. */
|
|
29
|
+
close(): void;
|
|
30
|
+
};
|
|
18
31
|
readonly theme: {
|
|
19
32
|
readonly current: Readonly<Theme> | null;
|
|
20
33
|
/** Delivers current synchronously if known, then future updates. */
|
|
@@ -42,6 +55,18 @@ export async function connectApp(options: ConnectAppOptions = {}): Promise<AppCl
|
|
|
42
55
|
let disposed = false;
|
|
43
56
|
let current: Readonly<Theme> | null = null;
|
|
44
57
|
const listeners = new Set<(theme: Readonly<Theme>) => void>();
|
|
58
|
+
const pending = new Map<string, {
|
|
59
|
+
placement: AppPlacement;
|
|
60
|
+
resolve: () => void;
|
|
61
|
+
reject: (error: Error) => void;
|
|
62
|
+
timer: ReturnType<typeof setTimeout>;
|
|
63
|
+
}>();
|
|
64
|
+
// Available even in opaque sandbox origins (no secure-context requirement).
|
|
65
|
+
const requestId = () => Array.from(crypto.getRandomValues(new Uint8Array(16)), byte => byte.toString(16).padStart(2, "0")).join("");
|
|
66
|
+
const postViewRequest = (message: { type: string; id: string; placement?: AppPlacement }) => {
|
|
67
|
+
const direct = window.parent === window;
|
|
68
|
+
window.parent.postMessage(message, direct ? window.location.origin : "*");
|
|
69
|
+
};
|
|
45
70
|
const receive = (event: MessageEvent) => {
|
|
46
71
|
if (disposed) return;
|
|
47
72
|
if (window.parent === window) {
|
|
@@ -50,6 +75,15 @@ export async function connectApp(options: ConnectAppOptions = {}): Promise<AppCl
|
|
|
50
75
|
// Embedded origin may be opaque; direct dev views use self + exact origin.
|
|
51
76
|
// A theme message never authenticates a user or a backend request.
|
|
52
77
|
const data = event.data;
|
|
78
|
+
if (data?.type === "pioneer.view.result" && typeof data.id === "string") {
|
|
79
|
+
const call = pending.get(data.id);
|
|
80
|
+
if (call && data.placement === call.placement) {
|
|
81
|
+
pending.delete(data.id);
|
|
82
|
+
clearTimeout(call.timer);
|
|
83
|
+
call.resolve();
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
53
87
|
if (!data || data.type !== "pioneer.theme" || !data.palette) return;
|
|
54
88
|
const value = data.palette;
|
|
55
89
|
if (value.appearance !== "dark" && value.appearance !== "light") return;
|
|
@@ -57,7 +91,16 @@ export async function connectApp(options: ConnectAppOptions = {}): Promise<AppCl
|
|
|
57
91
|
for (const key of colors) {
|
|
58
92
|
if (typeof value[key] !== "string" || value[key].length > 128 || !CSS.supports("color", value[key])) return;
|
|
59
93
|
}
|
|
60
|
-
|
|
94
|
+
const statusColors = ["success", "warning", "danger", "info"] as const;
|
|
95
|
+
for (const key of statusColors) {
|
|
96
|
+
if (value[key] !== undefined &&
|
|
97
|
+
(typeof value[key] !== "string" || value[key].length > 128 || !CSS.supports("color", value[key]))) return;
|
|
98
|
+
}
|
|
99
|
+
current = Object.freeze({
|
|
100
|
+
appearance: value.appearance,
|
|
101
|
+
...Object.fromEntries(colors.map(key => [key, value[key]])),
|
|
102
|
+
...Object.fromEntries(statusColors.filter(key => value[key] !== undefined).map(key => [key, value[key]])),
|
|
103
|
+
}) as Readonly<Theme>;
|
|
61
104
|
for (const listener of [...listeners]) {
|
|
62
105
|
if (disposed) break;
|
|
63
106
|
if (!listeners.has(listener)) continue;
|
|
@@ -77,6 +120,33 @@ export async function connectApp(options: ConnectAppOptions = {}): Promise<AppCl
|
|
|
77
120
|
return target.href;
|
|
78
121
|
};
|
|
79
122
|
return Object.freeze({
|
|
123
|
+
view: Object.freeze({
|
|
124
|
+
setPlacement(placement: AppPlacement): Promise<void> {
|
|
125
|
+
if (disposed) return Promise.reject(failure("sdk.closed"));
|
|
126
|
+
if (!["fullscreen", "bottom", "right"].includes(placement)) return Promise.reject(failure("sdk.invalid_placement"));
|
|
127
|
+
if (pending.size >= 16) return Promise.reject(failure("sdk.view_overloaded"));
|
|
128
|
+
const id = requestId();
|
|
129
|
+
return new Promise<void>((resolve, reject) => {
|
|
130
|
+
const timer = setTimeout(() => {
|
|
131
|
+
pending.delete(id);
|
|
132
|
+
reject(failure("sdk.view_timeout"));
|
|
133
|
+
}, 5000);
|
|
134
|
+
pending.set(id, { placement, resolve, reject, timer });
|
|
135
|
+
try {
|
|
136
|
+
postViewRequest({ type: "pioneer.view.setPlacement", id, placement });
|
|
137
|
+
} catch {
|
|
138
|
+
pending.delete(id);
|
|
139
|
+
clearTimeout(timer);
|
|
140
|
+
reject(failure("sdk.view_unavailable"));
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
close(): void {
|
|
145
|
+
if (disposed) throw failure("sdk.closed");
|
|
146
|
+
try { postViewRequest({ type: "pioneer.view.close", id: requestId() }); }
|
|
147
|
+
catch { throw failure("sdk.view_unavailable"); }
|
|
148
|
+
},
|
|
149
|
+
}),
|
|
80
150
|
theme: Object.freeze({
|
|
81
151
|
get current() { return current; },
|
|
82
152
|
subscribe(listener: (theme: Readonly<Theme>) => void) {
|
|
@@ -94,6 +164,15 @@ export async function connectApp(options: ConnectAppOptions = {}): Promise<AppCl
|
|
|
94
164
|
target.protocol = target.protocol === "https:" ? "wss:" : "ws:";
|
|
95
165
|
return target.href;
|
|
96
166
|
},
|
|
97
|
-
dispose() {
|
|
167
|
+
dispose() {
|
|
168
|
+
disposed = true;
|
|
169
|
+
listeners.clear();
|
|
170
|
+
window.removeEventListener("message", receive);
|
|
171
|
+
for (const call of pending.values()) {
|
|
172
|
+
clearTimeout(call.timer);
|
|
173
|
+
call.reject(failure("sdk.closed"));
|
|
174
|
+
}
|
|
175
|
+
pending.clear();
|
|
176
|
+
},
|
|
98
177
|
});
|
|
99
178
|
}
|