@clearly-hub/node 0.1.0 → 0.1.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/README.md CHANGED
@@ -43,7 +43,8 @@ Hono, Bun or Deno. Mount it at `/clearly-hub/*`.
43
43
  **3. Add the script and a button:**
44
44
 
45
45
  ```html
46
- <script src="https://cdn.jsdelivr.net/npm/@clearly-hub/browser/dist/clearly-hub.js"></script>
46
+ <!-- @0.1: follows 0.1.x fixes, not a breaking 0.2 -->
47
+ <script src="https://cdn.jsdelivr.net/npm/@clearly-hub/browser@0.1/dist/clearly-hub.js"></script>
47
48
 
48
49
  <clearly-hub-button action="sign-in"></clearly-hub-button>
49
50
  <clearly-hub-button action="DATA_PICKER"></clearly-hub-button>
package/dist/index.cjs CHANGED
@@ -44,6 +44,17 @@ var SCREEN_ACTIONS = [
44
44
  function isScreenAction(value) {
45
45
  return SCREEN_ACTIONS.includes(value);
46
46
  }
47
+ function checkScreenData(action, data) {
48
+ if (action !== "REGISTER_RESOURCE") return void 0;
49
+ const { url, format } = data ?? {};
50
+ if (typeof url !== "string" || !url || typeof format !== "string" || !format) {
51
+ return 'REGISTER_RESOURCE needs data with a url and a format, for example { url, format: "geojson" }';
52
+ }
53
+ if (!url.startsWith("https://")) {
54
+ return "REGISTER_RESOURCE needs a public https url: Clearly.HUB refuses other addresses";
55
+ }
56
+ return void 0;
57
+ }
47
58
 
48
59
  // ../shared/src/protocol.ts
49
60
  var DEFAULT_BASE_PATH = "/clearly-hub";
@@ -291,6 +302,14 @@ function openScreen(url, session, { config, screens }) {
291
302
  if (!isScreenAction(action)) return errorPage(400, `Unknown screen: ${action}`);
292
303
  const display = url.searchParams.get("display") === "redirect" ? "redirect" : "popup";
293
304
  const dataParam = url.searchParams.get("data");
305
+ let data;
306
+ try {
307
+ data = dataParam ? JSON.parse(dataParam) : void 0;
308
+ } catch {
309
+ return errorPage(400, "The screen data is not valid JSON");
310
+ }
311
+ const dataProblem = checkScreenData(action, data);
312
+ if (dataProblem) return errorPage(400, dataProblem);
294
313
  const state = crypto.randomUUID();
295
314
  session.screens = pruneScreens(session.screens);
296
315
  session.screens[state] = {
@@ -300,14 +319,7 @@ function openScreen(url, session, { config, screens }) {
300
319
  returnTo: safeReturnTo(url, config),
301
320
  createdAt: Date.now()
302
321
  };
303
- return redirect(
304
- screens.screenUrl(
305
- action,
306
- state,
307
- session.user?.email,
308
- dataParam ? JSON.parse(dataParam) : void 0
309
- )
310
- );
322
+ return redirect(screens.screenUrl(action, state, session.user?.email, data));
311
323
  }
312
324
  async function receiveAnswer(url, session, { config, screens }) {
313
325
  const query = readRawQuery(url);
package/dist/index.d.cts CHANGED
@@ -10,6 +10,7 @@ interface ScreenData {
10
10
  format: string;
11
11
  };
12
12
  }
13
+ declare function checkScreenData(action: ScreenAction, data: unknown): string | undefined;
13
14
  interface HubRef {
14
15
  _id: string;
15
16
  name: string;
@@ -164,5 +165,5 @@ declare function clearlyHub(options: ClearlyHubOptions): {
164
165
  };
165
166
  type ClearlyHub = ReturnType<typeof clearlyHub>;
166
167
 
167
- export { ANSWER_CHANNEL, DEFAULT_AUTH_URL, DEFAULT_BASE_PATH, DEFAULT_HUB_URL, DEFAULT_ISSUER, ROUTES, SCREEN_ACTIONS, clearlyHub, isScreenAction };
168
+ export { ANSWER_CHANNEL, DEFAULT_AUTH_URL, DEFAULT_BASE_PATH, DEFAULT_HUB_URL, DEFAULT_ISSUER, ROUTES, SCREEN_ACTIONS, checkScreenData, clearlyHub, isScreenAction };
168
169
  export type { AnswerMessage, AppSubscription, ClearlyHub, ClearlyHubOptions, ClearlyHubUrls, CookieSource, HubRef, HubSubscription, PickedResource, ScreenAction, ScreenAnswers, ScreenData, ScreenDisplay, ScreenResult, Session, SessionUser, SignedInPerson };
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ interface ScreenData {
10
10
  format: string;
11
11
  };
12
12
  }
13
+ declare function checkScreenData(action: ScreenAction, data: unknown): string | undefined;
13
14
  interface HubRef {
14
15
  _id: string;
15
16
  name: string;
@@ -164,5 +165,5 @@ declare function clearlyHub(options: ClearlyHubOptions): {
164
165
  };
165
166
  type ClearlyHub = ReturnType<typeof clearlyHub>;
166
167
 
167
- export { ANSWER_CHANNEL, DEFAULT_AUTH_URL, DEFAULT_BASE_PATH, DEFAULT_HUB_URL, DEFAULT_ISSUER, ROUTES, SCREEN_ACTIONS, clearlyHub, isScreenAction };
168
+ export { ANSWER_CHANNEL, DEFAULT_AUTH_URL, DEFAULT_BASE_PATH, DEFAULT_HUB_URL, DEFAULT_ISSUER, ROUTES, SCREEN_ACTIONS, checkScreenData, clearlyHub, isScreenAction };
168
169
  export type { AnswerMessage, AppSubscription, ClearlyHub, ClearlyHubOptions, ClearlyHubUrls, CookieSource, HubRef, HubSubscription, PickedResource, ScreenAction, ScreenAnswers, ScreenData, ScreenDisplay, ScreenResult, Session, SessionUser, SignedInPerson };
package/dist/index.js CHANGED
@@ -8,6 +8,17 @@ var SCREEN_ACTIONS = [
8
8
  function isScreenAction(value) {
9
9
  return SCREEN_ACTIONS.includes(value);
10
10
  }
11
+ function checkScreenData(action, data) {
12
+ if (action !== "REGISTER_RESOURCE") return void 0;
13
+ const { url, format } = data ?? {};
14
+ if (typeof url !== "string" || !url || typeof format !== "string" || !format) {
15
+ return 'REGISTER_RESOURCE needs data with a url and a format, for example { url, format: "geojson" }';
16
+ }
17
+ if (!url.startsWith("https://")) {
18
+ return "REGISTER_RESOURCE needs a public https url: Clearly.HUB refuses other addresses";
19
+ }
20
+ return void 0;
21
+ }
11
22
 
12
23
  // ../shared/src/protocol.ts
13
24
  var DEFAULT_BASE_PATH = "/clearly-hub";
@@ -255,6 +266,14 @@ function openScreen(url, session, { config, screens }) {
255
266
  if (!isScreenAction(action)) return errorPage(400, `Unknown screen: ${action}`);
256
267
  const display = url.searchParams.get("display") === "redirect" ? "redirect" : "popup";
257
268
  const dataParam = url.searchParams.get("data");
269
+ let data;
270
+ try {
271
+ data = dataParam ? JSON.parse(dataParam) : void 0;
272
+ } catch {
273
+ return errorPage(400, "The screen data is not valid JSON");
274
+ }
275
+ const dataProblem = checkScreenData(action, data);
276
+ if (dataProblem) return errorPage(400, dataProblem);
258
277
  const state = crypto.randomUUID();
259
278
  session.screens = pruneScreens(session.screens);
260
279
  session.screens[state] = {
@@ -264,14 +283,7 @@ function openScreen(url, session, { config, screens }) {
264
283
  returnTo: safeReturnTo(url, config),
265
284
  createdAt: Date.now()
266
285
  };
267
- return redirect(
268
- screens.screenUrl(
269
- action,
270
- state,
271
- session.user?.email,
272
- dataParam ? JSON.parse(dataParam) : void 0
273
- )
274
- );
286
+ return redirect(screens.screenUrl(action, state, session.user?.email, data));
275
287
  }
276
288
  async function receiveAnswer(url, session, { config, screens }) {
277
289
  const query = readRawQuery(url);
package/package.json CHANGED
@@ -1,10 +1,16 @@
1
1
  {
2
2
  "name": "@clearly-hub/node",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Clearly.HUB for Node servers: sign-in, hosted screens, subscriptions and usage in one handler",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Future Insight Group BV",
7
- "keywords": ["clearly-hub", "oup", "open-urban-platform", "oidc", "sdk"],
7
+ "keywords": [
8
+ "clearly-hub",
9
+ "oup",
10
+ "open-urban-platform",
11
+ "oidc",
12
+ "sdk"
13
+ ],
8
14
  "type": "module",
9
15
  "main": "./dist/index.cjs",
10
16
  "module": "./dist/index.js",
@@ -33,7 +39,7 @@
33
39
  "openid-client": "^6.8.8"
34
40
  },
35
41
  "devDependencies": {
36
- "@clearly-hub/shared": "0.1.0"
42
+ "@clearly-hub/shared": "*"
37
43
  },
38
44
  "engines": {
39
45
  "node": ">=20"