studio-engine 0.137.0 → 0.139.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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -0
  3. data/README.md +86 -1
  4. data/app/assets/tailwind/studio_engine/engine.css +235 -0
  5. data/app/controllers/concerns/studio/connection_flow.rb +1 -1
  6. data/app/controllers/sessions_controller.rb +12 -3
  7. data/app/controllers/studio/integrations_controller.rb +43 -0
  8. data/app/controllers/studio/local_reviews_controller.rb +12 -0
  9. data/app/javascript/studio/carousel.js +109 -0
  10. data/app/javascript/studio/controllers/carousel_captions_controller.js +42 -0
  11. data/app/javascript/studio/controllers/carousel_controller.js +243 -1
  12. data/app/javascript/studio/stimulus.js +3 -1
  13. data/app/models/concerns/studio/account.rb +143 -0
  14. data/app/models/concerns/studio/omniauth_user.rb +9 -17
  15. data/app/models/error_log.rb +14 -5
  16. data/app/views/studio/_carousel.html.erb +74 -14
  17. data/app/views/studio/integrations/_card.html.erb +50 -0
  18. data/app/views/studio/integrations/index.html.erb +22 -0
  19. data/app/views/studio/integrations/show.html.erb +24 -0
  20. data/app/views/style/_tricks.html.erb +38 -0
  21. data/config/studio_tricks.yml +7 -0
  22. data/db/migrate/20261006120001_ensure_error_logs_table.rb +3 -1
  23. data/db/migrate/20261006120002_ensure_theme_settings_table.rb +3 -2
  24. data/db/migrate/20261108160000_require_slugs_on_engine_tables.rb +119 -0
  25. data/db/migrate/20261108160001_add_engine_state_checks.rb +94 -0
  26. data/db/migrate/20261108170000_add_users_role_known_check.rb +69 -0
  27. data/lib/generators/studio/connections/connections_generator.rb +10 -0
  28. data/lib/studio/connections.rb +53 -12
  29. data/lib/studio/integrations/egnyte.rb +69 -0
  30. data/lib/studio/integrations/microsoft_365.rb +63 -0
  31. data/lib/studio/integrations/quickbooks.rb +86 -0
  32. data/lib/studio/integrations.rb +265 -0
  33. data/lib/studio/node_tooling/README.md +9 -1
  34. data/lib/studio/node_tooling/e2e_helpers.js +93 -1
  35. data/lib/studio/node_tooling/playwright_base.js +51 -4
  36. data/lib/studio/roles.rb +17 -0
  37. data/lib/studio/version.rb +1 -1
  38. data/lib/studio.rb +59 -1
  39. metadata +16 -2
@@ -8,7 +8,15 @@ host gets it with the engine it already bundles: no npm registry, no token.
8
8
  exactly this version.
9
9
  - `playwright_base.js`: the browser lane's shared defaults (one chromium
10
10
  project, one worker, a Rails `webServer` on `/up`).
11
- - `e2e_helpers.js`: `watchPageErrors` and `blockOffsiteRequests`.
11
+ - `e2e_helpers.js`: `watchPageErrors` and `blockOffsiteRequests`; for a page
12
+ transition spec, the reveal waits (`watchReveal`, `revealed`, `settled`,
13
+ `arrivalSettled`, `frames`) and the log-on-red hook (`sessionLog`, `logOnRed`).
14
+ The waits read events the browser fires, never a clock.
15
+
16
+ A local run reuses a server already on the e2e port only when that server's
17
+ working directory is inside this tree (`mayReuseServer` in `playwright_base.js`,
18
+ read with `lsof`). Any other server there is refused, with a warning that names
19
+ its root: give the run its own port with `E2E_PORT=<free port>`.
12
20
  - `node_test/register.mjs` and `node_test/importmap_hooks.mjs`: let `node --test`
13
21
  import a module by the bare name the importmap pins it under.
14
22
 
@@ -71,4 +71,96 @@ async function blockOffsiteRequests(page, { pinned = {} } = {}) {
71
71
  });
72
72
  }
73
73
 
74
- module.exports = { isOffOrigin, watchPageErrors, blockOffsiteRequests };
74
+ // ---- Full-load page transitions (docs/PAGE_TRANSITIONS.md, "Full page loads") ----
75
+ //
76
+ // These wait on events the browser fires, never on a clock. Nothing here sleeps.
77
+
78
+ // Marks each document's pagereveal, for revealed(), settled() and arrivalSettled() below.
79
+ // Call it before the first navigation: it is an init script, so every new document gets it,
80
+ // and it must be bound before the first render to hear pagereveal at all.
81
+ //
82
+ // `window.__studioReveal` holds { revealed, transition, done }: `done` is true once the
83
+ // arrival's view transition has finished or been skipped, at once when there is none.
84
+ function watchReveal(target) {
85
+ return target.addInitScript(() => {
86
+ const state = { revealed: false, transition: false, done: false };
87
+ window.__studioReveal = state;
88
+ window.addEventListener("pagereveal", (event) => {
89
+ state.revealed = true;
90
+ const transition = event.viewTransition;
91
+ state.transition = !!transition;
92
+ if (!transition) { state.done = true; return; }
93
+ const done = () => { state.done = true; };
94
+ transition.finished.then(done, done);
95
+ });
96
+ });
97
+ }
98
+
99
+ // The new page has revealed. VISIBLE IS NOT REVEALED: its DOM parses, and Playwright sees it
100
+ // as visible, before its first render. A render-blocking sheet, or the reveal script's own
101
+ // hold to the end of parse, keeps pagereveal back, and until then no mark is set and no
102
+ // pseudo runs (engine CI run 42503970890 read an empty log at 312 ms).
103
+ async function revealed(page, selector) {
104
+ if (selector) await page.locator(selector).first().waitFor({ state: "visible" });
105
+ await page.waitForFunction(() => window.__studioReveal && window.__studioReveal.revealed === true);
106
+ }
107
+
108
+ // Past the whole motion: revealed, and the document's own marks and every
109
+ // ::view-transition animation are gone when this returns.
110
+ async function settled(page, selector) {
111
+ await revealed(page, selector);
112
+ await page.waitForFunction(() => document.documentElement.dataset.pageTransition === undefined
113
+ && !document.getAnimations().some((a) => ((a.effect && a.effect.pseudoElement) || "").startsWith("::view-transition")));
114
+ }
115
+
116
+ // Two rendered frames. A recorder that samples document.getAnimations() on every
117
+ // requestAnimationFrame has run at least once past anything that was live before this call.
118
+ function frames(page, count = 2) {
119
+ return page.evaluate((n) => new Promise((done) => {
120
+ const step = (left) => (left === 0 ? done() : requestAnimationFrame(() => step(left - 1)));
121
+ step(n);
122
+ }), count);
123
+ }
124
+
125
+ // For a spec that asserts NOTHING PLAYED: the arrival's view transition has finished or been
126
+ // skipped, and two frames have rendered since. A transition that wrongly plays keeps `done`
127
+ // false until its last frame, and every frame it draws comes before this returns, so a
128
+ // per-frame recorder has logged it. A fixed pause only hoped for that.
129
+ async function arrivalSettled(page, selector) {
130
+ await revealed(page, selector);
131
+ await page.waitForFunction(() => window.__studioReveal.done === true);
132
+ await frames(page);
133
+ }
134
+
135
+ // A log kept in sessionStorage, so it outlives each document of a full load.
136
+ function sessionLog(page, key = "pt-log") {
137
+ return page.evaluate((name) => JSON.parse(sessionStorage.getItem(name) || "[]"), key);
138
+ }
139
+
140
+ // A red carries its evidence: registers an afterEach that, on a failed test only, prints the
141
+ // log `read(page)` returns and attaches it to the report the CI uploads. A red with no log
142
+ // once left its cause unprovable. `test` is the host's own @playwright/test `test`, since
143
+ // this file cannot require Playwright (see README.md).
144
+ function logOnRed(test, read = (page) => sessionLog(page), { name = "pt-log" } = {}) {
145
+ test.afterEach(async ({ page }, testInfo) => {
146
+ if (testInfo.status === testInfo.expectedStatus) return;
147
+ const lines = await Promise.resolve()
148
+ .then(() => read(page))
149
+ .catch((error) => [`(the log could not be read: ${error.message})`]);
150
+ console.log(`${name} for "${testInfo.title}":\n${lines.join("\n")}`);
151
+ await testInfo.attach(name, { body: lines.join("\n"), contentType: "text/plain" });
152
+ });
153
+ }
154
+
155
+ module.exports = {
156
+ isOffOrigin,
157
+ watchPageErrors,
158
+ blockOffsiteRequests,
159
+ watchReveal,
160
+ revealed,
161
+ settled,
162
+ frames,
163
+ arrivalSettled,
164
+ sessionLog,
165
+ logOnRed,
166
+ };
@@ -14,6 +14,10 @@
14
14
  // Every key of `overrides` replaces the default of the same name; `use` merges
15
15
  // one level deep, so a host can add `reducedMotion` and keep `baseURL`.
16
16
 
17
+ const { execFileSync } = require("node:child_process");
18
+ const fs = require("node:fs");
19
+ const path = require("node:path");
20
+
17
21
  const DEFAULTS = Object.freeze({
18
22
  testDir: "./e2e",
19
23
  timeout: 30_000,
@@ -29,14 +33,57 @@ function studioBaseURL({ defaultPort, env = process.env } = {}) {
29
33
  return { port, external, baseURL: external || `http://127.0.0.1:${port}` };
30
34
  }
31
35
 
36
+ // The working directory of whatever listens on `port`, read with lsof: { root } for a
37
+ // listener, { root: null } for none, { unknown: true } when it cannot be told (no lsof, a
38
+ // process lsof may not read).
39
+ function listenerRoot(port) {
40
+ const run = (args) => execFileSync("lsof", args, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5000 });
41
+ let pids;
42
+ try {
43
+ pids = run(["-nP", `-iTCP:${port}`, "-sTCP:LISTEN", "-t"]).split("\n").filter(Boolean);
44
+ } catch (error) {
45
+ // lsof exits 1, printing nothing, when nothing listens.
46
+ if (error.status === 1 && !error.stdout) return { root: null };
47
+ return { unknown: true };
48
+ }
49
+ if (pids.length === 0) return { root: null };
50
+ try {
51
+ const line = run(["-a", "-p", pids[0], "-d", "cwd", "-Fn"]).split("\n").find((entry) => entry.startsWith("n"));
52
+ return line ? { root: line.slice(1) } : { unknown: true };
53
+ } catch (_error) {
54
+ return { unknown: true };
55
+ }
56
+ }
57
+
58
+ function realpath(path) {
59
+ try { return fs.realpathSync(path); } catch (_error) { return path; }
60
+ }
61
+
62
+ // May this run reuse the server already on `port`? Only one this tree started. Playwright's
63
+ // own check is "something answers /up", so on a shared default port one desk's run graded
64
+ // another desk's server, and its code. A server rooted outside `root`, or one whose root
65
+ // cannot be read, is refused: Playwright then stops with "is already used", and the warning
66
+ // names the server's root and the way out. Nothing listening reuses nothing either way.
67
+ function mayReuseServer({ port, root, lookup = listenerRoot, warn = console.warn }) {
68
+ const found = lookup(port);
69
+ if (found.root === null) return true;
70
+ const mine = realpath(root);
71
+ const theirs = found.unknown ? null : realpath(found.root);
72
+ if (theirs && (theirs === mine || theirs.startsWith(`${mine}${path.sep}`))) return true;
73
+ warn(`[studio playwright] port ${port} is held by a server ${theirs ? `rooted at ${theirs}` : "whose root cannot be read"}, ` +
74
+ `not by this tree (${mine}), so it is not reused. Stop it if it is yours, or give this run its own port: E2E_PORT=<free port>.`);
75
+ return false;
76
+ }
77
+
32
78
  // A Rails server Playwright boots and waits on. `/up` is the Rails health check
33
- // every app in the ecosystem keeps.
34
- function railsWebServer({ command, port, env = {}, timeout = 120_000, ci = !!process.env.CI }) {
79
+ // every app in the ecosystem keeps. Locally a running server is reused only when this
80
+ // tree started it (mayReuseServer); CI never reuses one.
81
+ function railsWebServer({ command, port, env = {}, timeout = 120_000, ci = !!process.env.CI, root = process.cwd(), lookup }) {
35
82
  if (!command) throw new Error("railsWebServer: a command is required");
36
83
  return {
37
84
  command,
38
85
  url: `http://127.0.0.1:${port}/up`,
39
- reuseExistingServer: !ci,
86
+ reuseExistingServer: !ci && mayReuseServer({ port, root, lookup }),
40
87
  timeout,
41
88
  stdout: "pipe",
42
89
  stderr: "pipe",
@@ -60,4 +107,4 @@ function studioPlaywrightConfig({ defaultPort, webServer, env = process.env, use
60
107
  return config;
61
108
  }
62
109
 
63
- module.exports = { DEFAULTS, studioBaseURL, railsWebServer, studioPlaywrightConfig };
110
+ module.exports = { DEFAULTS, studioBaseURL, listenerRoot, mayReuseServer, railsWebServer, studioPlaywrightConfig };
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Studio
4
+ # The one list of account roles every Studio app draws from (database audit
5
+ # 2026-11-07, section 3). `users.role` holds one of these, guarded twice: by
6
+ # Studio::Account's inclusion validation and by CHECK users_role_known, which
7
+ # db/migrate/20261108170000_add_users_role_known_check.rb installs.
8
+ #
9
+ # A host may NARROW the list (`studio_roles %w[viewer admin]` in its User),
10
+ # never widen it: a role the engine does not know means nothing to the
11
+ # engine's admin checks, and a new one is added here, for every app at once.
12
+ # Turf's old "user" spelling meant viewer and moved there.
13
+ Roles = %w[viewer member admin].freeze
14
+
15
+ # The role a new account takes when nothing says otherwise.
16
+ DEFAULT_ROLE = "viewer"
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Studio
2
- VERSION = "0.137.0"
2
+ VERSION = "0.139.0"
3
3
  end
data/lib/studio.rb CHANGED
@@ -12,6 +12,7 @@ require "active_support/core_ext/module/attribute_accessors"
12
12
  require "active_support/core_ext/numeric/time"
13
13
  require "active_support/core_ext/integer/time"
14
14
  require "studio/version"
15
+ require "studio/roles"
15
16
  require "studio/local_path"
16
17
  require "studio/public_file_version"
17
18
  require "studio/component_gallery"
@@ -77,6 +78,10 @@ require "studio/redis"
77
78
  require "studio/cable"
78
79
  require "studio/connections"
79
80
  require "studio/connections/stand_in"
81
+ require "studio/integrations"
82
+ require "studio/integrations/quickbooks"
83
+ require "studio/integrations/egnyte"
84
+ require "studio/integrations/microsoft_365"
80
85
  require "studio/survey"
81
86
  require "studio/survey/breakdown"
82
87
  require "studio/survey/export"
@@ -1203,7 +1208,8 @@ module Studio
1203
1208
 
1204
1209
  # ---- Connections (docs/CONNECTIONS.md) ------------------------------------
1205
1210
  #
1206
- # The generic OAuth 2.0 connection tooling. The engine names no provider: a
1211
+ # The generic OAuth 2.0 connection tooling. The tooling names no provider (the
1212
+ # engine's own definitions are Studio::Integrations, below): a
1207
1213
  # host declares each in an initializer and draws its routes.
1208
1214
  #
1209
1215
  # Studio.define_connection :files, label: "Acme Files", env: {...}, ...
@@ -1259,6 +1265,58 @@ module Studio
1259
1265
  end
1260
1266
  end
1261
1267
 
1268
+ # ---- Integrations (docs/INTEGRATIONS.md) -----------------------------------
1269
+ #
1270
+ # The engine's own connection definitions (Studio::Integrations): QuickBooks,
1271
+ # Egnyte and Microsoft 365. Connection only; a host writes its readers.
1272
+ #
1273
+ # # config/initializers/studio_integrations.rb
1274
+ # Studio.enable_integration :quickbooks,
1275
+ # env: { client_id: "INTUIT_CLIENT_ID", client_secret: "INTUIT_CLIENT_SECRET", environment: "INTUIT_ENVIRONMENT" },
1276
+ # panel: "admin/integrations/quickbooks_panel"
1277
+ # # config/routes.rb
1278
+ # Studio.draw_integrations_routes(self)
1279
+ #
1280
+ # env: names the host's env vars (never values); the integration stays off
1281
+ # until its client id and secret are set. panel: a host partial rendered on
1282
+ # the integration's page with locals integration: and connections:.
1283
+ def self.enable_integration(key, env:, panel: nil, label: nil, scopes: nil)
1284
+ Integrations.enable(key, env:, panel:, label:, scopes:)
1285
+ end
1286
+
1287
+ def self.integration(key)
1288
+ Integrations.fetch(key)
1289
+ end
1290
+
1291
+ def self.integrations
1292
+ Integrations.all
1293
+ end
1294
+
1295
+ # Draws the admin integrations page and, for every enabled integration, its
1296
+ # page and connection routes (Studio.draw_connection_routes), all served by
1297
+ # Studio::IntegrationsController unless the host names its own:
1298
+ #
1299
+ # GET /<path> <as> the list
1300
+ # GET /<path>/<key> <as>_<key> one integration's page
1301
+ # POST /<path>/<key>/connect <as>_<key>_connect (also GET when it takes no account at Connect)
1302
+ # GET /<path>/<key>/callback <as>_<key>_callback the redirect URI to register
1303
+ # DELETE /<path>/<key>/connections/:id <as>_<key>_disconnect
1304
+ #
1305
+ # path: defaults to admin/integrations, so QuickBooks's redirect URI is
1306
+ # /admin/integrations/quickbooks/callback. Call it after every
1307
+ # enable_integration (an initializer runs before the routes load).
1308
+ def self.draw_integrations_routes(router, path: "admin/integrations", controller: "studio/integrations", as: nil)
1309
+ path = path.to_s.delete_prefix("/").delete_suffix("/")
1310
+ controller = controller.to_s.delete_prefix("/")
1311
+ as = (as || path.tr("/-", "__")).to_s
1312
+ Integrations.mount_path = path
1313
+ router.instance_exec { get path, to: "#{controller}#index", as: as }
1314
+ Integrations.all.each do |integration|
1315
+ draw_connection_routes(router, integration.key, path: "#{path}/#{integration.key}", controller:, as: "#{as}_#{integration.key}",
1316
+ show: true, return_to: ["/#{path}/#{integration.key}", "/#{path}"])
1317
+ end
1318
+ end
1319
+
1262
1320
  # Define a survey in app code. See Studio::Survey for the DSL.
1263
1321
  def self.define_survey(slug, &block)
1264
1322
  Survey.define(slug, &block)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: studio-engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.137.0
4
+ version: 0.139.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex McRitchie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-08 00:00:00.000000000 Z
11
+ date: 2026-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -468,6 +468,7 @@ files:
468
468
  - app/controllers/studio/geo_settings_controller.rb
469
469
  - app/controllers/studio/google_setup_requests_controller.rb
470
470
  - app/controllers/studio/health_reports_controller.rb
471
+ - app/controllers/studio/integrations_controller.rb
471
472
  - app/controllers/studio/knowledge_docs_controller.rb
472
473
  - app/controllers/studio/links_controller.rb
473
474
  - app/controllers/studio/local_emails_controller.rb
@@ -515,6 +516,7 @@ files:
515
516
  - app/javascript/studio/controllers/agent_chat_voice_controller.js
516
517
  - app/javascript/studio/controllers/board_controller.js
517
518
  - app/javascript/studio/controllers/booking_controller.js
519
+ - app/javascript/studio/controllers/carousel_captions_controller.js
518
520
  - app/javascript/studio/controllers/carousel_controller.js
519
521
  - app/javascript/studio/controllers/copy_text_controller.js
520
522
  - app/javascript/studio/controllers/email_banner_scale_controller.js
@@ -596,6 +598,7 @@ files:
596
598
  - app/mailers/studio/profile_mailer.rb
597
599
  - app/mailers/user_mailer.rb
598
600
  - app/models/concerns/sluggable.rb
601
+ - app/models/concerns/studio/account.rb
599
602
  - app/models/concerns/studio/board/rankable.rb
600
603
  - app/models/concerns/studio/omniauth_user.rb
601
604
  - app/models/current.rb
@@ -716,6 +719,9 @@ files:
716
719
  - app/views/studio/google_sign_in/_setup_modal.html.erb
717
720
  - app/views/studio/health_report_mailer/daily.html.erb
718
721
  - app/views/studio/health_report_mailer/daily.text.erb
722
+ - app/views/studio/integrations/_card.html.erb
723
+ - app/views/studio/integrations/index.html.erb
724
+ - app/views/studio/integrations/show.html.erb
719
725
  - app/views/studio/knowledge_docs/_access_chips.html.erb
720
726
  - app/views/studio/knowledge_docs/_browser.html.erb
721
727
  - app/views/studio/knowledge_docs/_chip_styles.html.erb
@@ -882,6 +888,9 @@ files:
882
888
  - db/migrate/20261103120000_create_studio_user_sessions.rb
883
889
  - db/migrate/20261108120000_add_device_revocation_to_studio_user_sessions.rb
884
890
  - db/migrate/20261108130000_create_studio_connections.rb
891
+ - db/migrate/20261108160000_require_slugs_on_engine_tables.rb
892
+ - db/migrate/20261108160001_add_engine_state_checks.rb
893
+ - db/migrate/20261108170000_add_users_role_known_check.rb
885
894
  - docs/BOOKING.md
886
895
  - docs/SITE_FOOTER.md
887
896
  - lib/active_storage/service/studio_trash_s3_service.rb
@@ -932,6 +941,10 @@ files:
932
941
  - lib/studio/icons/lucide/rocket.svg
933
942
  - lib/studio/icons/lucide/user.svg
934
943
  - lib/studio/image_cache.rb
944
+ - lib/studio/integrations.rb
945
+ - lib/studio/integrations/egnyte.rb
946
+ - lib/studio/integrations/microsoft_365.rb
947
+ - lib/studio/integrations/quickbooks.rb
935
948
  - lib/studio/ip_locations.rb
936
949
  - lib/studio/js_identifier.rb
937
950
  - lib/studio/js_literal.rb
@@ -975,6 +988,7 @@ files:
975
988
  - lib/studio/public_file_version.rb
976
989
  - lib/studio/public_user.rb
977
990
  - lib/studio/redis.rb
991
+ - lib/studio/roles.rb
978
992
  - lib/studio/s3.rb
979
993
  - lib/studio/s3/multipart.rb
980
994
  - lib/studio/s3/trash.rb