@foir/sdk 0.15.0 → 0.16.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/CHANGELOG.md +19 -0
- package/dist/placement/index.d.ts +29 -0
- package/dist/placement.js +15 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -108,6 +108,25 @@ nobody asking for `@foir/sdk` gets it early. The push that carries the commit to
|
|
|
108
108
|
|
|
109
109
|
Changes on `dev` that have not been published to npm.
|
|
110
110
|
|
|
111
|
+
## [0.16.0] — 2026-10-02
|
|
112
|
+
|
|
113
|
+
Published under npm's `next` tag from `dev`, as 0.15.0 was; `latest` moves to
|
|
114
|
+
it at the next promotion.
|
|
115
|
+
|
|
116
|
+
### Added
|
|
117
|
+
|
|
118
|
+
- **An embedded page is told how the console looks** (`@foir/sdk/placement`).
|
|
119
|
+
The console's theme is the operator's own setting, which a framed page cannot
|
|
120
|
+
see, so a page that followed the system's preference could sit dark inside a
|
|
121
|
+
light console. `connectPlacement` takes `onAppearance`, called with
|
|
122
|
+
`{ theme: 'light' | 'dark' }` as soon as the console says (before the token
|
|
123
|
+
arrives) and again whenever the operator changes it; `session.appearance`
|
|
124
|
+
holds the current one. `PlacementAppearance` is the type, and
|
|
125
|
+
`PLACEMENT_MESSAGE.appearance` the message.
|
|
126
|
+
- A console older than this says nothing: `onAppearance` is not called and
|
|
127
|
+
`session.appearance` is `null`, so keep the system's preference as the
|
|
128
|
+
fallback.
|
|
129
|
+
|
|
111
130
|
## [0.15.0] — 2026-10-02
|
|
112
131
|
|
|
113
132
|
Published under npm's `next` tag from `dev`, because it calls parts of the
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
* const data = await session.request('{ preorders { items { id } } }');
|
|
20
20
|
* ```
|
|
21
21
|
*
|
|
22
|
+
* The console also tells the page how it looks, so the page can match it: pass
|
|
23
|
+
* `onAppearance` and apply the theme it names. The operator's console theme is
|
|
24
|
+
* their own setting and need not be their system's.
|
|
25
|
+
*
|
|
22
26
|
* The browser shows the page blank, however well it is authenticated, unless
|
|
23
27
|
* the page allows the console as a frame ancestor. Hydrogen and many other
|
|
24
28
|
* frameworks send `frame-ancestors 'none'` by default. `placementFrameAncestors`
|
|
@@ -37,6 +41,8 @@ export declare const PLACEMENT_MESSAGE: {
|
|
|
37
41
|
readonly refused: "foir:placement:refused";
|
|
38
42
|
/** Console to page: the operator signed out. */
|
|
39
43
|
readonly signedOut: "foir:placement:signed-out";
|
|
44
|
+
/** Console to page: how the console looks, now and whenever it changes. */
|
|
45
|
+
readonly appearance: "foir:placement:appearance";
|
|
40
46
|
};
|
|
41
47
|
/** What the console hands an embedded page. */
|
|
42
48
|
export interface PlacementGrant {
|
|
@@ -54,6 +60,14 @@ export interface PlacementGrant {
|
|
|
54
60
|
reason: string;
|
|
55
61
|
}[];
|
|
56
62
|
}
|
|
63
|
+
/** How the console looks, for an embedded page to match. */
|
|
64
|
+
export interface PlacementAppearance {
|
|
65
|
+
/**
|
|
66
|
+
* The console's theme as the operator sees it: their own choice, or their
|
|
67
|
+
* system's when they left it to the system.
|
|
68
|
+
*/
|
|
69
|
+
theme: 'light' | 'dark';
|
|
70
|
+
}
|
|
57
71
|
/** A message the console sends an embedded page. */
|
|
58
72
|
export type PlacementHostMessage = {
|
|
59
73
|
type: typeof PLACEMENT_MESSAGE.token;
|
|
@@ -63,6 +77,9 @@ export type PlacementHostMessage = {
|
|
|
63
77
|
reason: string;
|
|
64
78
|
} | {
|
|
65
79
|
type: typeof PLACEMENT_MESSAGE.signedOut;
|
|
80
|
+
} | {
|
|
81
|
+
type: typeof PLACEMENT_MESSAGE.appearance;
|
|
82
|
+
appearance: PlacementAppearance;
|
|
66
83
|
};
|
|
67
84
|
/** A message an embedded page sends the console. */
|
|
68
85
|
export type PlacementPageMessage = {
|
|
@@ -100,6 +117,13 @@ export interface ConnectPlacementOptions {
|
|
|
100
117
|
timeoutMs?: number;
|
|
101
118
|
/** How long before expiry to ask for a fresh token. Default 60 seconds. */
|
|
102
119
|
refreshBeforeMs?: number;
|
|
120
|
+
/**
|
|
121
|
+
* Called with how the console looks: once as soon as the console says, which
|
|
122
|
+
* is before the token arrives, and again whenever the operator changes it.
|
|
123
|
+
* Apply it instead of the system's preference, so the page matches the
|
|
124
|
+
* console it is shown in.
|
|
125
|
+
*/
|
|
126
|
+
onAppearance?: (appearance: PlacementAppearance) => void;
|
|
103
127
|
/** The page's window. Default the global one; tests pass their own. */
|
|
104
128
|
window?: Window;
|
|
105
129
|
/** The fetch the session's requests use. Default the global one. */
|
|
@@ -109,6 +133,11 @@ export interface ConnectPlacementOptions {
|
|
|
109
133
|
export interface PlacementSession {
|
|
110
134
|
/** The grant in force now. Replaced as the session refreshes. */
|
|
111
135
|
readonly grant: PlacementGrant;
|
|
136
|
+
/**
|
|
137
|
+
* How the console looks now, or null when the console has not said (a console
|
|
138
|
+
* older than this). Kept current as the operator changes it.
|
|
139
|
+
*/
|
|
140
|
+
readonly appearance: PlacementAppearance | null;
|
|
112
141
|
/** Whether the token carries this scope, to hide or grey out what the operator cannot do. */
|
|
113
142
|
can(scope: string): boolean;
|
|
114
143
|
/** A GraphQL request to Foir's API as the operator, through your app. */
|
package/dist/placement.js
CHANGED
|
@@ -9,7 +9,9 @@ var PLACEMENT_MESSAGE = {
|
|
|
9
9
|
/** Console to page: no token, and why. */
|
|
10
10
|
refused: "foir:placement:refused",
|
|
11
11
|
/** Console to page: the operator signed out. */
|
|
12
|
-
signedOut: "foir:placement:signed-out"
|
|
12
|
+
signedOut: "foir:placement:signed-out",
|
|
13
|
+
/** Console to page: how the console looks, now and whenever it changes. */
|
|
14
|
+
appearance: "foir:placement:appearance"
|
|
13
15
|
};
|
|
14
16
|
var FOIR_CONSOLE_ORIGINS = {
|
|
15
17
|
production: ["https://app.foir.io"],
|
|
@@ -41,6 +43,10 @@ var PlacementRefused = class extends Error {
|
|
|
41
43
|
function isHostMessage(data) {
|
|
42
44
|
if (typeof data !== "object" || data === null) return false;
|
|
43
45
|
const t = data.type;
|
|
46
|
+
if (t === PLACEMENT_MESSAGE.appearance) {
|
|
47
|
+
const theme = data.appearance?.theme;
|
|
48
|
+
return theme === "light" || theme === "dark";
|
|
49
|
+
}
|
|
44
50
|
return t === PLACEMENT_MESSAGE.token || t === PLACEMENT_MESSAGE.refused || t === PLACEMENT_MESSAGE.signedOut;
|
|
45
51
|
}
|
|
46
52
|
function connectPlacement(options) {
|
|
@@ -55,6 +61,7 @@ function connectPlacement(options) {
|
|
|
55
61
|
}
|
|
56
62
|
return new Promise((resolve, reject) => {
|
|
57
63
|
let grant = null;
|
|
64
|
+
let appearance = null;
|
|
58
65
|
let settled = false;
|
|
59
66
|
let refreshTimer;
|
|
60
67
|
const signedOut = /* @__PURE__ */ new Set();
|
|
@@ -77,6 +84,9 @@ function connectPlacement(options) {
|
|
|
77
84
|
if (!grant) throw new PlacementRefused("the operator has signed out");
|
|
78
85
|
return grant;
|
|
79
86
|
},
|
|
87
|
+
get appearance() {
|
|
88
|
+
return appearance;
|
|
89
|
+
},
|
|
80
90
|
can: (scope) => grant?.grantedScopes.includes(scope) ?? false,
|
|
81
91
|
async request(document, variables) {
|
|
82
92
|
if (!grant) throw new PlacementRefused("the operator has signed out");
|
|
@@ -123,6 +133,10 @@ function connectPlacement(options) {
|
|
|
123
133
|
close();
|
|
124
134
|
for (const l of signedOut) l();
|
|
125
135
|
return;
|
|
136
|
+
case PLACEMENT_MESSAGE.appearance:
|
|
137
|
+
appearance = { theme: msg.appearance.theme };
|
|
138
|
+
options.onAppearance?.(appearance);
|
|
139
|
+
return;
|
|
126
140
|
}
|
|
127
141
|
}
|
|
128
142
|
const timeout = setTimeout(() => {
|