@plitzi/sdk-auth 0.38.16 → 0.38.18

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 CHANGED
@@ -1,5 +1,120 @@
1
1
  # @plitzi/sdk-auth
2
2
 
3
+ ## 0.38.18
4
+
5
+ ### Patch Changes
6
+
7
+ - b3023c9: ## Security
8
+
9
+ - **A page of the same site on another origin is no longer this server's own** (`@plitzi/sdk-server`): the guard
10
+ against writes another page caused (`crossSiteWrites`, the sign-in's login-CSRF check and `createOriginGuardMiddleware`)
11
+ trusted `Sec-Fetch-Site: same-site` — and a site has no port and spans every sub-domain, so another port of the host
12
+ (where `createAuthoringHost` serves pages an agent wrote) or a sibling sub-domain (every space of a platform on one
13
+ domain) could write as if it were the server's own page. Now only `same-origin` (and `none`, a typed URL) is; `same-site`
14
+ is refused 403 `reason: 'foreign'` unless its origin is named (`crossSiteWrites.origins`, `identity.platformOrigins`),
15
+ and the `Origin` fallback compares host and port. In production an app and its spaces are already on different sites,
16
+ so a deployment that works there needs nothing; one that relied on a sibling sub-domain locally names it.
17
+ `createAuthoringHost`'s docs now say to serve on a host of its own — a cookie belongs to a host whatever its port.
18
+
19
+ ## Server
20
+ - **An open page takes a new version of its space where it stands** (`@plitzi/sdk-server`, `@plitzi/plitzi-sdk`):
21
+ `server.updatePages(documents, { draft? })` hands the pages showing that space — or that draft — its new documents,
22
+ and each swaps them in place, its state, scroll and focus kept (`replaceSpace` on what the SDK's `render` returns;
23
+ `false`, and the page loads again, for a page with elements the server draws). The development loop of a project uses
24
+ it: a save to the space no longer reloads the open page. `createAuthoringHost`'s `put` over an id that pages show
25
+ hands them the new version and answers how many took it (`updated`), so a page an agent keeps improving is seen to
26
+ grow instead of reloading — no second iframe needed.
27
+ - **`devReload` is `livePages`** (`@plitzi/sdk-server`): the channel the open pages listen on now carries the space,
28
+ not only "load again", and a host that is not developing uses it too. Its address is `/__plitzi/live`; a draft's page
29
+ listens for its own changes alone (`?__pt=`). A plugin swapped where it is drawn stays a development server's
30
+ (`devMode`). `plitzi upgrade migrations --write` renames the option in a project's code (`livePagesOption`).
31
+
32
+ ## Packages
33
+ - **`@plitzi/sdk-server` starts in half the time** (`@plitzi/sdk-shared`, `@plitzi/sdk-server`): importing it took
34
+ ~310 ms, ~200 of them `date-fns` — 108 modules nothing on the server uses, brought by `@plitzi/sdk-shared/helpers` —
35
+ and loaded the browser's hooks and contexts of every folder of `@plitzi/sdk-shared` it read, `@plitzi/nexus/react`
36
+ with them. Now ~150 ms (`@plitzi/sdk-shared` 139 → 113 modules, `@plitzi/nexus` 53 → 31). What moved, each
37
+ rewritten by `plitzi upgrade migrations --write` (`movedExports`):
38
+ - the dates — `formatDate`, `formatDateUTC`, `formatFromNow`, `formatUTCToLocal`, `getDurationMs`, `isDate`,
39
+ `isValidFormat`, `parseDate`, `toUnixSeconds`, `SupportedLocale` — from `@plitzi/sdk-shared/helpers` to
40
+ `@plitzi/sdk-shared/dates`;
41
+ - React's bindings to an entry of their own beside each area, as `@plitzi/nexus/react` is: `useDisplayMode`,
42
+ `useElementSize` → `@plitzi/sdk-shared/style/react`; `SchemaContext` → `schema/react`; `PluginsContext` →
43
+ `plugins/react`; `DevToolsContext` → `devTools/react`; `useFlagResolution` → `flags/react` (`flagUserFrom` stays
44
+ in `flags`);
45
+ - `PROJECT_DATA_PREFIX` from `@plitzi/sdk-shared/server` to `@plitzi/sdk-shared/project/paths` — the project's
46
+ layout names, an entry a browser imports too (`@plitzi/sdk-shared/project` stays Node only and re-exports them).
47
+ The theme cookie's helpers (`themeFromCookies`…) are also `@plitzi/sdk-shared/theme/cookie`, still exported by
48
+ `@plitzi/sdk-shared/theme`.
49
+
50
+ `yarn check:server-footprint` (in CI after the build) holds what the server's root loads, package by package — Plitzi's
51
+ and every other — to a budget: a heavy library or a folder of hooks coming back fails with what came in.
52
+
53
+ ## CLI
54
+ - **`plitzi upgrade migrations --write` writes a file import's new home when it has one** (`@plitzi/cli`): the
55
+ `folderImports` migration of 0.38.17 named every import of a package's FILE and wrote none. It now reads the installed
56
+ declarations with the project's own TypeScript and rewrites each `import` / `export … from` whose every name the folder
57
+ exports under one name — `import usePlitzi from '@plitzi/sdk-shared/hooks/usePlitzi'` →
58
+ `import { usePlitzi } from '@plitzi/sdk-shared/hooks'`, `type` modifiers and aliases kept. What has no one answer is
59
+ said with why (a namespace import, an `import()` or mock, a name the folder does not export, a project with no
60
+ TypeScript). The report says which places `--write` writes (`writable` in `--json`) instead of calling every one
61
+ "yours to change"; a migration now gives each place its own `edit` in place of a whole-file `rewrite`
62
+ (`docs/en/releases.md`).
63
+ - **`plitzi doctor` says an import of a path the installed package does not export** (`@plitzi/cli`):
64
+ `import-not-exported`, an error, at the importing file — what Node otherwise reports at start as an
65
+ `ERR_MODULE_NOT_FOUND` into the package's `dist`, which reads as a broken install rather than a changed API. For a
66
+ `@plitzi` package the fix names `plitzi upgrade migrations --write`; for any other, its `exports`. Asked only of a
67
+ package that is installed.
68
+
69
+ - Updated dependencies [b3023c9]
70
+ - @plitzi/sdk-navigation@0.38.18
71
+ - @plitzi/sdk-shared@0.38.18
72
+
73
+ ## 0.38.17
74
+
75
+ ### Patch Changes
76
+
77
+ - 4f8dc37: ## Packages
78
+
79
+ - **A library package is imported by its root and its folders, never by a file** (`@plitzi/sdk-shared`, `sdk-schema`,
80
+ `sdk-style`, `sdk-elements`, `sdk-interactions`, `sdk-auth`, `sdk-dev-tools`, `sdk-event-bridge`, `sdk-navigation`,
81
+ `sdk-plugins`, `sdk-variables`): each `exports` is now `"."` and `"./*"`, the latter a folder's `index`.
82
+ `@plitzi/sdk-shared/helpers/isRecord` becomes `import { isRecord } from '@plitzi/sdk-shared/helpers'`, and a default
83
+ export by the name its folder gives it — almost always its file's (`import usePlitzi from '…/hooks/usePlitzi'` →
84
+ `import { usePlitzi } from '@plitzi/sdk-shared/hooks'`). A file-level specifier now fails with `ERR_MODULE_NOT_FOUND`.
85
+ New entries where a folder barrel would have brought more than was asked for: `@plitzi/sdk-shared/project` and
86
+ `@plitzi/sdk-shared/plugins/bundle` (Node only), `@plitzi/sdk-interactions/declarations` (the global callbacks and
87
+ utility specs, without React), and `@plitzi/sdk-elements/elements/declarations`, which now also carries the
88
+ declarations' attribute types and the constants they are checked with. `RuleGroup` is exported by `@plitzi/sdk-shared`
89
+ with the document types that use it. `plitzi upgrade migrations` names every such import in a project, with the folder to
90
+ import it from instead.
91
+ - **`@plitzi/sdk-shared`'s root exports the document types, and only them** (`@plitzi/sdk-shared`): what the package
92
+ does is imported from its folder — `formatDate` from `@plitzi/sdk-shared/helpers`, `ThemeProvider` from
93
+ `@plitzi/sdk-shared/theme`, a GraphQL operation's types from `@plitzi/sdk-shared/network/graphql` — so a module that
94
+ imports a type from the root no longer loads every area of the package.
95
+ - **What one package alone used lives in that package** (`@plitzi/sdk-shared`, `@plitzi/sdk-elements`): the data
96
+ source hooks moved from `@plitzi/sdk-shared/dataSource/hooks` to `@plitzi/sdk-elements/dataSource`
97
+ (`useRegisterSource`, `useResolvedVariables`), and the Apollo links the builder's client is built with into the
98
+ builder.
99
+ - **The builder's panels are an entry of their own** (`@plitzi/sdk-style`, `@plitzi/sdk-variables`,
100
+ `@plitzi/sdk-elements`): the style inspector, the advanced style editor and `BuilderStyleContextProvider` are imported
101
+ from `@plitzi/sdk-style/builder`; the variables' lists and forms from `@plitzi/sdk-variables/builder`; the elements'
102
+ settings panels (`defaultElementsSettings`) from `@plitzi/sdk-elements/builder`. Each package's root keeps what a page
103
+ and a server use — `generateCache` no longer loads the inspector, on a server 227 modules down to 21.
104
+
105
+ ## CLI
106
+ - **`plitzi upgrade`'s `renames` part is now `migrations`** (`@plitzi/cli`): what a version changed that a project's
107
+ own source must follow, one file per change in the CLI's `src/migrations/changes/` with the version it shipped in —
108
+ rewritten with `--write` when it has one right answer, said otherwise. The `--json` report carries `migrations` (each
109
+ with its `migration`, `since`, `file`, `line`, `what` and whether it was `written`) in place of `renames` and
110
+ `changes`. The changes of 0.38.0 (`canTemplate` → `canSnippet`, the `*Template` authoring names), 0.38.9 (a
111
+ `formControl` without `required` is optional) and 0.38.12 (`usePlitziServiceContext` → `usePlitzi`) are no longer
112
+ looked for: a project still on one of those versions makes them by hand.
113
+
114
+ - Updated dependencies [4f8dc37]
115
+ - @plitzi/sdk-navigation@0.38.17
116
+ - @plitzi/sdk-shared@0.38.17
117
+
3
118
  ## 0.38.16
4
119
 
5
120
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { sharedContext as e } from "@plitzi/sdk-shared/helpers/sharedContext";
1
+ import { sharedContext as e } from "@plitzi/sdk-shared/helpers";
2
2
  var t = e("AuthContext", {});
3
3
  //#endregion
4
4
  export { t as AuthContext, t as default };
@@ -5,9 +5,9 @@ import r from "./hooks/useAuth/index.mjs";
5
5
  import i from "./hooks/useSessionQueryReset/index.mjs";
6
6
  import { QueryBuilderEvaluator as a } from "@plitzi/plitzi-ui/QueryBuilder";
7
7
  import { use as o, useMemo as s, useRef as c } from "react";
8
- import l from "@plitzi/sdk-navigation/hooks/useNavigation";
8
+ import { useNavigation as l } from "@plitzi/sdk-navigation";
9
9
  import { processTwig as u } from "@plitzi/sdk-shared/helpers/twigWrapper";
10
- import d from "@plitzi/sdk-shared/network/NetworkContext";
10
+ import { NetworkContext as d } from "@plitzi/sdk-shared/network";
11
11
  import { useCommonStore as f, useRenderSettings as p } from "@plitzi/sdk-shared/store";
12
12
  import { jsx as m } from "react/jsx-runtime";
13
13
  //#region src/AuthContextProvider.tsx
@@ -95,33 +95,12 @@ var s = 60, c = 300, l = 2147483647, u = class {
95
95
  user: r?.user,
96
96
  token: r?.token,
97
97
  validatedAt: r?.validatedAt ?? 0
98
- }, this.hintCookie && !i) {
99
- this.endSession(void 0, "hint-missing");
100
- return;
101
- }
102
- if (this.hasLiveToken() && this.session.user) {
98
+ }, this.hintCookie && !i) this.endSession(void 0, "hint-missing");
99
+ else if (this.hasLiveToken() && this.session.user) {
103
100
  this.setState("authenticated", "restored"), this.scheduleRenewal();
104
101
  let e = this.isFresh() && this.gate !== "strict" ? void 0 : this.revalidate(!0);
105
102
  this.gate === "strict" && await e;
106
- return;
107
- }
108
- if (!this.hasEvidence()) {
109
- this.endSession(void 0, "no-evidence");
110
- return;
111
- }
112
- if (this.setState("initLoading", "no-evidence"), this.hasLiveToken() && this.capabilities.identity) {
113
- await this.loadIdentity();
114
- return;
115
- }
116
- if (this.capabilities.renew) {
117
- await this.renew();
118
- return;
119
- }
120
- if (this.capabilities.identity) {
121
- await this.loadIdentity();
122
- return;
123
- }
124
- this.endSession();
103
+ } else this.hasEvidence() ? (this.setState("initLoading", "no-evidence"), this.hasLiveToken() && this.capabilities.identity ? await this.loadIdentity() : this.capabilities.renew ? await this.renew() : this.capabilities.identity ? await this.loadIdentity() : this.endSession()) : this.endSession(void 0, "no-evidence");
125
104
  }
126
105
  dispose() {
127
106
  clearTimeout(this.renewalTimer), this.renewalTimer = void 0, this.detachListeners?.(), this.detachListeners = void 0;
@@ -157,15 +136,9 @@ var s = 60, c = 300, l = 2147483647, u = class {
157
136
  async handOffToServer() {
158
137
  let e = await this.requestExchange();
159
138
  if (e) {
160
- if (e.ok) {
161
- this.adopt(e);
162
- return;
163
- }
164
- if (e.reason === "network") {
165
- this.offline = !0;
166
- return;
167
- }
168
- return this.endSession(e.reason), e.reason;
139
+ if (e.ok) this.adopt(e);
140
+ else if (e.reason === "network") this.offline = !0;
141
+ else return this.endSession(e.reason), e.reason;
169
142
  }
170
143
  }
171
144
  async refresh() {
@@ -211,11 +184,7 @@ var s = 60, c = 300, l = 2147483647, u = class {
211
184
  return e === this.epoch ? t.ok ? (this.adopt(t), this.state === "authenticated") : this.renewable(t.reason) && !this.renewal ? this.renew() : (this.handleFailure(t.reason), !1) : this.state === "authenticated";
212
185
  }
213
186
  handleFailure(e) {
214
- if (e === "network") {
215
- this.offline = !0;
216
- return;
217
- }
218
- this.endSession(e);
187
+ e === "network" ? this.offline = !0 : this.endSession(e);
219
188
  }
220
189
  adopt(e, t = !0, r = "granted") {
221
190
  this.session = {
@@ -259,18 +228,10 @@ var s = 60, c = 300, l = 2147483647, u = class {
259
228
  let e = this.expiresAt();
260
229
  if (e === void 0 || typeof window > "u" || this.state === "guest") return;
261
230
  let t = Math.min((e - s - n()) * 1e3, l);
262
- if (t <= 0) {
263
- this.onRenewalDue();
264
- return;
265
- }
266
- this.renewalTimer = setTimeout(() => this.onRenewalDue(), t);
231
+ t <= 0 ? this.onRenewalDue() : this.renewalTimer = setTimeout(() => this.onRenewalDue(), t);
267
232
  }
268
233
  onRenewalDue() {
269
- if (this.capabilities.renew) {
270
- this.renew();
271
- return;
272
- }
273
- this.endSession("expired");
234
+ this.capabilities.renew ? this.renew() : this.endSession("expired");
274
235
  }
275
236
  attach() {
276
237
  if (typeof window > "u" || this.detachListeners) return;
@@ -287,11 +248,7 @@ var s = 60, c = 300, l = 2147483647, u = class {
287
248
  };
288
249
  }
289
250
  adoptFromStorage(e) {
290
- if (this.epoch += 1, !e?.token && !e?.user) {
291
- clearTimeout(this.renewalTimer), this.renewalTimer = void 0, this.session = { validatedAt: n() }, this.setState("guest", "another-tab"), this.emit({ type: "logout" });
292
- return;
293
- }
294
- this.adopt({
251
+ this.epoch += 1, !e?.token && !e?.user ? (clearTimeout(this.renewalTimer), this.renewalTimer = void 0, this.session = { validatedAt: n() }, this.setState("guest", "another-tab"), this.emit({ type: "logout" })) : this.adopt({
295
252
  ok: !0,
296
253
  user: e.user,
297
254
  token: e.token
package/package.json CHANGED
@@ -1,89 +1,20 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-auth",
3
- "version": "0.38.16",
3
+ "version": "0.38.18",
4
4
  "license": "AGPL-3.0",
5
5
  "files": [
6
6
  "dist"
7
7
  ],
8
8
  "exports": {
9
9
  ".": {
10
+ "@plitzi/source": "./src/index.ts",
10
11
  "types": "./dist/index.d.ts",
11
12
  "import": "./dist/index.mjs"
12
13
  },
13
- "./AuthContext": {
14
- "types": "./dist/AuthContext.d.ts",
15
- "import": "./dist/AuthContext.mjs"
16
- },
17
- "./AuthContextProvider": {
18
- "types": "./dist/AuthContextProvider.d.ts",
19
- "import": "./dist/AuthContextProvider.mjs"
20
- },
21
- "./AuthManager": {
22
- "types": "./dist/AuthManager.d.ts",
23
- "import": "./dist/AuthManager.mjs"
24
- },
25
- "./AuthProvider": {
26
- "types": "./dist/AuthProvider.d.ts",
27
- "import": "./dist/AuthProvider.mjs"
28
- },
29
- "./helpers/SessionStore": {
30
- "types": "./dist/helpers/SessionStore.d.ts",
31
- "import": "./dist/helpers/SessionStore.mjs"
32
- },
33
- "./helpers/publishedSession": {
34
- "types": "./dist/helpers/publishedSession.d.ts",
35
- "import": "./dist/helpers/publishedSession.mjs"
36
- },
37
- "./helpers/resolveAuthSettings": {
38
- "types": "./dist/helpers/resolveAuthSettings.d.ts",
39
- "import": "./dist/helpers/resolveAuthSettings.mjs"
40
- },
41
- "./helpers/sessionHint": {
42
- "types": "./dist/helpers/sessionHint.d.ts",
43
- "import": "./dist/helpers/sessionHint.mjs"
44
- },
45
- "./helpers/tokenClaims": {
46
- "types": "./dist/helpers/tokenClaims.d.ts",
47
- "import": "./dist/helpers/tokenClaims.mjs"
48
- },
49
- "./hooks/useAuth": {
50
- "types": "./dist/hooks/useAuth/index.d.ts",
51
- "import": "./dist/hooks/useAuth/index.mjs"
52
- },
53
- "./hooks/useAuth/index": {
54
- "types": "./dist/hooks/useAuth/index.d.ts",
55
- "import": "./dist/hooks/useAuth/index.mjs"
56
- },
57
- "./hooks/useAuth/useAuth": {
58
- "types": "./dist/hooks/useAuth/useAuth.d.ts",
59
- "import": "./dist/hooks/useAuth/useAuth.mjs"
60
- },
61
- "./hooks/useSessionQueryReset": {
62
- "types": "./dist/hooks/useSessionQueryReset/index.d.ts",
63
- "import": "./dist/hooks/useSessionQueryReset/index.mjs"
64
- },
65
- "./hooks/useSessionQueryReset/index": {
66
- "types": "./dist/hooks/useSessionQueryReset/index.d.ts",
67
- "import": "./dist/hooks/useSessionQueryReset/index.mjs"
68
- },
69
- "./hooks/useSessionQueryReset/useSessionQueryReset": {
70
- "types": "./dist/hooks/useSessionQueryReset/useSessionQueryReset.d.ts",
71
- "import": "./dist/hooks/useSessionQueryReset/useSessionQueryReset.mjs"
72
- },
73
- "./index": {
74
- "types": "./dist/index.d.ts",
75
- "import": "./dist/index.mjs"
76
- },
77
- "./providers/BasicAuthProvider": {
78
- "types": "./dist/providers/BasicAuthProvider.d.ts",
79
- "import": "./dist/providers/BasicAuthProvider.mjs"
80
- },
81
- "./providers/ServerAuthProvider": {
82
- "types": "./dist/providers/ServerAuthProvider.d.ts",
83
- "import": "./dist/providers/ServerAuthProvider.mjs"
84
- },
85
- "./types": {
86
- "types": "./dist/types.d.ts"
14
+ "./*": {
15
+ "@plitzi/source": "./src/*/index.ts",
16
+ "types": "./dist/*/index.d.ts",
17
+ "import": "./dist/*/index.mjs"
87
18
  }
88
19
  },
89
20
  "type": "module",
@@ -94,22 +25,22 @@
94
25
  "test": "vitest run",
95
26
  "test:watch": "vitest",
96
27
  "test:ui": "vitest --ui",
97
- "build:dev": "vite build --mode development --minify false && node ../sdk-shared/scripts/generate-exports.mjs",
28
+ "build:dev": "vite build --mode development --minify false",
98
29
  "build:dev-watch": "vite build --mode development --watch --minify false",
99
- "build:prod": "vite build && node ../sdk-shared/scripts/generate-exports.mjs"
30
+ "build:prod": "vite build"
100
31
  },
101
32
  "dependencies": {
102
33
  "@plitzi/nexus": "^1.4.0",
103
34
  "@plitzi/plitzi-ui": "^1.6.33",
104
- "@plitzi/sdk-navigation": "0.38.16",
105
- "@plitzi/sdk-shared": "0.38.16"
35
+ "@plitzi/sdk-navigation": "0.38.18",
36
+ "@plitzi/sdk-shared": "0.38.18"
106
37
  },
107
38
  "devDependencies": {
108
39
  "eslint": "^9.39.5",
109
- "react": "^19.3.0",
40
+ "react": "^19.3.1",
110
41
  "typescript": "^6.0.3",
111
- "vite": "^8.3.2",
112
- "vitest": "^5.0.3"
42
+ "vite": "^8.3.4",
43
+ "vitest": "^5.0.5"
113
44
  },
114
45
  "peerDependencies": {
115
46
  "react": "^19"