studio-engine 0.136.0 → 0.138.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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -0
  3. data/README.md +29 -0
  4. data/app/assets/tailwind/studio_engine/engine.css +228 -0
  5. data/app/controllers/concerns/studio/connection_flow.rb +215 -0
  6. data/app/controllers/sessions_controller.rb +12 -3
  7. data/app/controllers/studio/connections_controller.rb +13 -0
  8. data/app/controllers/studio/integrations_controller.rb +43 -0
  9. data/app/controllers/studio/local_reviews_controller.rb +12 -0
  10. data/app/javascript/studio/carousel.js +66 -0
  11. data/app/javascript/studio/controllers/carousel_controller.js +203 -1
  12. data/app/models/concerns/studio/account.rb +143 -0
  13. data/app/models/concerns/studio/omniauth_user.rb +9 -17
  14. data/app/models/error_log.rb +14 -5
  15. data/app/models/studio/connection.rb +137 -0
  16. data/app/views/studio/_carousel.html.erb +58 -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 +15 -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/20261108130000_create_studio_connections.rb +35 -0
  25. data/db/migrate/20261108160000_require_slugs_on_engine_tables.rb +119 -0
  26. data/db/migrate/20261108160001_add_engine_state_checks.rb +94 -0
  27. data/db/migrate/20261108170000_add_users_role_known_check.rb +69 -0
  28. data/lib/generators/studio/connections/connections_generator.rb +103 -0
  29. data/lib/studio/connections/stand_in.rb +89 -0
  30. data/lib/studio/connections.rb +524 -0
  31. data/lib/studio/engine.rb +8 -0
  32. data/lib/studio/integrations/egnyte.rb +69 -0
  33. data/lib/studio/integrations/microsoft_365.rb +63 -0
  34. data/lib/studio/integrations/quickbooks.rb +86 -0
  35. data/lib/studio/integrations.rb +265 -0
  36. data/lib/studio/node_tooling/README.md +9 -1
  37. data/lib/studio/node_tooling/e2e_helpers.js +93 -1
  38. data/lib/studio/node_tooling/playwright_base.js +51 -4
  39. data/lib/studio/roles.rb +17 -0
  40. data/lib/studio/version.rb +1 -1
  41. data/lib/studio.rb +118 -0
  42. metadata +22 -2
@@ -0,0 +1,137 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Studio
4
+ # One third-party account a host app has connected over OAuth 2.0, for a
5
+ # provider the host declared with Studio.define_connection
6
+ # (Studio::Connections::Provider). docs/CONNECTIONS.md.
7
+ #
8
+ # One row per provider and account (account_key, unique within a provider).
9
+ # Connecting the same account again replaces its tokens (.store!). No token,
10
+ # and no part of one, is ever shown: every token column is encrypted, filtered
11
+ # from inspect, and read only by the provider's access_token.
12
+ #
13
+ # THE ROW DEPENDS ON THE APP'S ENCRYPTION KEYS: without them a connect refuses
14
+ # before it asks the provider for anything
15
+ # (Studio::Connections.encryption_ready?); with them lost or changed, a stored
16
+ # row is unreadable (#readable? is false), counts as not connected, and
17
+ # connecting again replaces it.
18
+ #
19
+ # ROTATION. #rotate! is called by the provider inside #with_lock, which
20
+ # reloads the row first: a racing caller waits, then spends the NEWEST
21
+ # refresh token, and the answered token is stored before the access token it
22
+ # came with is used.
23
+ class Connection < ApplicationRecord
24
+ self.table_name = "studio_connections"
25
+
26
+ encrypts :access_token, :refresh_token, :account_secret
27
+ self.filter_attributes += %i[access_token refresh_token account_secret account_key]
28
+
29
+ validates :provider, :account_key, :connected_at, presence: true
30
+ validates :account_key, uniqueness: { scope: :provider }
31
+ validate :holds_what_its_policy_needs
32
+
33
+ scope :for_provider, ->(key) { where(provider: key.to_s) }
34
+
35
+ class << self
36
+ def encryption_ready? = Studio::Connections.encryption_ready?
37
+
38
+ def newest_first = order(connected_at: :desc, id: :desc)
39
+
40
+ # Every connection of a provider whose tokens this server can read, newest first.
41
+ def readable(provider) = for_provider(provider).newest_first.select(&:readable?)
42
+
43
+ # Stores the account a connect reached. `grant` is the token endpoint's
44
+ # JSON ({} for a client-credentials consent). Raises InvalidAccount for an
45
+ # account that fails the provider's format, and RecordInvalid when the
46
+ # answer lacks what the provider's policy keeps; the message names the
47
+ # field, never a value.
48
+ def store!(provider, grant, account:, by:, label: nil, metadata: {}, now: Time.current)
49
+ provider = Studio::Connections.fetch(provider) unless provider.is_a?(Studio::Connections::Provider)
50
+ account = provider.normalize_account(account) or raise Studio::Connections::InvalidAccount, "not a #{provider.label} account"
51
+ key = provider.account_key_for(account)
52
+
53
+ transaction(requires_new: true) do
54
+ connection = find_or_initialize_by(provider: provider.key, account_key: key)
55
+ # A row whose tokens can no longer be read is replaced, not updated.
56
+ unless connection.new_record? || connection.readable?
57
+ where(id: connection.id).delete_all
58
+ connection = new(provider: provider.key, account_key: key)
59
+ end
60
+ keep_access = provider.refresh == :cached
61
+ connection.assign_attributes(
62
+ account_secret: provider.private_account ? account : nil,
63
+ label: label.to_s.strip.presence || provider.label,
64
+ access_token: keep_access ? grant["access_token"].to_s.presence : nil,
65
+ refresh_token: provider.refresh == :memory ? nil : grant["refresh_token"].to_s.presence,
66
+ access_expires_at: keep_access ? Studio::Connections::Provider.expiry(grant, "expires_in", now) : nil,
67
+ refresh_expires_at: Studio::Connections::Provider.expiry(grant, provider.refresh_expires_in_key, now),
68
+ metadata: metadata.to_h.deep_stringify_keys, connected_by: by.to_s.presence, connected_at: now,
69
+ last_refreshed_at: nil
70
+ )
71
+ connection.save!
72
+ connection
73
+ end
74
+ end
75
+ end
76
+
77
+ def provider_definition = Studio::Connections.fetch(provider)
78
+
79
+ # The account as the provider names it: the decrypted id for a private
80
+ # account, else the key itself.
81
+ def account_id = account_secret.presence || account_key
82
+
83
+ # An access token, by the provider's refresh policy. `stale:` is a token the
84
+ # API just refused with a 401 (the :cached policy refreshes it).
85
+ def fresh_access_token(stale: nil) = provider_definition.access_token(self, stale:)
86
+
87
+ # Can the stored tokens be decrypted with this app's keys?
88
+ def readable?
89
+ access_token
90
+ refresh_token
91
+ account_secret
92
+ true
93
+ rescue ActiveRecord::Encryption::Errors::Base
94
+ false
95
+ end
96
+
97
+ # Is the stored access token good for longer than the provider's margin? A
98
+ # token with no expiry is, until the provider refuses it.
99
+ def access_fresh?(now = Time.current)
100
+ return false if access_token.blank?
101
+
102
+ access_expires_at.nil? || access_expires_at > now + provider_definition.refresh_margin
103
+ end
104
+
105
+ # Stores what a refresh just answered. Called inside #with_lock by the
106
+ # provider, before the access token is used. A provider whose rotation is
107
+ # :required refuses an answer without a refresh token (storing nothing would
108
+ # lose the account); otherwise a blank one keeps the stored one.
109
+ def rotate!(grant, now: Time.current)
110
+ definition = provider_definition
111
+ answered = grant["refresh_token"].to_s.presence
112
+ if answered.nil? && definition.rotation == :required
113
+ raise Studio::Connections::Error, "#{definition.label} answered a refresh with no refresh token; connect again"
114
+ end
115
+
116
+ changes = { refresh_token: answered || refresh_token, last_refreshed_at: now,
117
+ refresh_expires_at: Studio::Connections::Provider.expiry(grant, definition.refresh_expires_in_key, now) || refresh_expires_at }
118
+ if definition.refresh == :cached
119
+ raise Studio::Connections::Error, "#{definition.label} answered a refresh with no access token" if grant["access_token"].blank?
120
+
121
+ changes.merge!(access_token: grant["access_token"], access_expires_at: Studio::Connections::Provider.expiry(grant, "expires_in", now))
122
+ end
123
+ update!(changes)
124
+ end
125
+
126
+ private
127
+
128
+ def holds_what_its_policy_needs
129
+ definition = Studio::Connections.defined?(provider) ? Studio::Connections.fetch(provider) : nil
130
+ return errors.add(:provider, "is not a defined connection provider") unless definition
131
+
132
+ errors.add(:refresh_token, :blank) if definition.refresh == :rotating && refresh_token.blank?
133
+ errors.add(:access_token, :blank) if definition.refresh == :cached && access_token.blank?
134
+ errors.add(:account_secret, :blank) if definition.private_account && account_secret.blank?
135
+ end
136
+ end
137
+ end
@@ -1,4 +1,4 @@
1
- <%# locals: (label:, items:, per_view: 3, id: nil, slide_label: nil, data: {}, class_name: nil, style: :standard, caption: nil, start: nil, autoplay: nil, loop: false) %>
1
+ <%# locals: (label:, items:, per_view: 3, id: nil, slide_label: nil, data: {}, class_name: nil, style: :standard, caption: nil, start: nil, autoplay: nil, loop: false, visible: nil) %>
2
2
  <%# THE CAROUSEL: one sideways row of slides, the apps' standard for a set too
3
3
  long to grid. Render it as a layout, so each slide is your own block:
4
4
 
@@ -18,18 +18,25 @@
18
18
  slide is "2 of 6".
19
19
  data data attributes for the region, such as a test hook.
20
20
  class_name classes for the region, such as its width.
21
- style :standard (slides snap to the start) or :spotlight (the
21
+ style :standard (slides snap to the start), :spotlight (the
22
22
  centred slide is full size and colour, its neighbours smaller,
23
- faded and grey, and the arrows and keys move one slide).
23
+ faded and grey, and the arrows and keys move one slide), or
24
+ :cascade (a 3D stack: the open slide in front at full size,
25
+ the slides either side stepping back behind it, each step
26
+ smaller and dimmer; see THE CASCADE below).
27
+ visible a cascade's slides in view: 5 (the default: the open slide and
28
+ two each side) or 3. A region under 36rem wide shows 3 whatever
29
+ it asks. Only a cascade takes it.
24
30
  caption a callable that writes a line under a slide from its item. A
25
31
  standard row shows a small line under every slide; the
26
- spotlight shows it under the centred slide only.
32
+ spotlight and the cascade show it under the open slide only.
27
33
  start the slide the row opens on: an index from 0, or :middle (the
28
34
  slide at items.size / 2). Defaults to :middle for a spotlight
29
35
  that does not loop, so both halves of the row hold a slide at
30
36
  load, and to 0 for a standard row and for a looping spotlight
31
37
  (its wrap already shows the last slide left of the first, so it
32
- opens on the host's first item). An explicit start: wins. The browser sets it before the first paint where
38
+ opens on the host's first item). A cascade takes the spotlight's
39
+ defaults. An explicit start: wins. The browser sets it before the first paint where
33
40
  it has scroll-initial-target; elsewhere the controller sets it
34
41
  when it connects, with no glide and nothing announced. A link
35
42
  to an id inside the row (#fragment) wins over the start.
@@ -60,6 +67,18 @@
60
67
  transitions it. Under reduced motion nothing scales: the neighbours are only
61
68
  dimmed.
62
69
 
70
+ THE CASCADE (engine.css, carousel-cascade) does not scroll. Its slides share
71
+ one grid cell, and each wears data-cascade-step, its place from the open slide:
72
+ -2 to 2 in view, "before" and "after" past the window. The partial writes the
73
+ steps of the first paint and the controller rewrites them on a move, so CSS
74
+ lays the stack out (perspective, translateZ, a slight turn toward the centre)
75
+ and transitions it. An arrow, a dot, a key, a swipe or drag, autoplay, a click
76
+ on a side slide and keyboard focus in one bring that slide to the front; a
77
+ click on a side slide opens nothing. A looping cascade needs no clones: the
78
+ steps wrap round the set, so the window is never wider than the set. Under
79
+ reduced motion it lays flat, as a spotlight does, and swaps with no glide. If
80
+ its controller fails it falls back to a plain scrolling row.
81
+
63
82
  THE TRACK IS A NATIVE SCROLL-SNAP ROW (engine.css, carousel). A swipe, a
64
83
  trackpad, a wheel and a focused link move it with no script. The carousel
65
84
  controller (studio/controllers/carousel_controller) adds the edge fade, the
@@ -80,16 +99,25 @@
80
99
  per_view = per_view.to_i if per_view == per_view.floor
81
100
  items = items.to_a
82
101
  total = items.size
83
- spotlight = case style.to_s
84
- when "standard" then false
85
- when "spotlight" then true
86
- else raise ArgumentError, "studio/carousel style: #{style.inspect} is not :standard or :spotlight"
87
- end
102
+ style_name = style.to_s
103
+ unless %w[standard spotlight cascade].include?(style_name)
104
+ raise ArgumentError, "studio/carousel style: #{style.inspect} is not :standard, :spotlight or :cascade"
105
+ end
106
+ spotlight = style_name == "spotlight"
107
+ cascade = style_name == "cascade"
108
+ # The spotlight and the cascade both centre one slide: they share its defaults.
109
+ centred = spotlight || cascade
110
+ if cascade
111
+ visible = 5 if visible.nil?
112
+ raise ArgumentError, "studio/carousel visible: #{visible.inspect} is not 3 or 5" unless [3, 5].include?(visible)
113
+ elsif !visible.nil?
114
+ raise ArgumentError, "studio/carousel visible: only a style: :cascade row takes it"
115
+ end
88
116
  loop = loop ? true : false
89
117
  wraps = loop && total > 1
90
118
  # A looping spotlight has a left neighbour at its first slide (the clones), so it
91
119
  # opens there; one that does not loop opens mid-row so neither half is empty.
92
- start = spotlight && !wraps ? :middle : 0 if start.nil?
120
+ start = centred && !wraps ? :middle : 0 if start.nil?
93
121
  start_index = case start
94
122
  when :middle, "middle" then total / 2
95
123
  when Integer then start.clamp(0, [total - 1, 0].max)
@@ -100,20 +128,36 @@
100
128
  raise ArgumentError, "studio/carousel autoplay: #{autoplay.inspect} is not a number of seconds above 0 or nil"
101
129
  end
102
130
  autoplay = autoplay.to_i if autoplay && autoplay == autoplay.floor
103
- arrow_noun = spotlight ? "slide" : "slides"
131
+ arrow_noun = centred ? "slide" : "slides"
132
+ # A cascade slide's place from the open slide (studio/carousel's cascadeStep and
133
+ # cascadeSlot): signed, the short way round a looping set, the later side on a tie.
134
+ cascade_slot = lambda do |index|
135
+ step = index - start_index
136
+ if wraps
137
+ step %= total
138
+ step -= total if step > total / 2.0
139
+ end
140
+ step < -2 ? "before" : step > 2 ? "after" : step.to_s
141
+ end
104
142
  track_id = id.presence || "carousel-#{label.to_s.parameterize.presence || 'slides'}"
105
143
  %>
106
- <%= tag.section(class: ["carousel", ("carousel-spotlight" if spotlight), class_name].compact.join(" "),
144
+ <%= tag.section(class: ["carousel", ("carousel-spotlight" if spotlight), ("carousel-cascade" if cascade), class_name].compact.join(" "),
107
145
  role: "region",
108
146
  aria: { roledescription: "carousel", label: label },
109
147
  style: "--carousel-per-view: #{per_view}",
110
148
  data: { studio_controller: "carousel", studio_action: "keydown->carousel#key", carousel_start: (start_index.to_s if start_index.positive?),
111
- carousel_autoplay: (autoplay.to_s if autoplay), carousel_loop: ("" if loop) }.compact.merge(data)) do %>
149
+ carousel_autoplay: (autoplay.to_s if autoplay), carousel_loop: ("" if loop), carousel_visible: (visible.to_s if cascade) }.compact.merge(data)) do %>
112
150
  <%# The track takes focus for the keys, so it carries a name: a group, since a
113
151
  bare div may not be named. %>
114
152
  <div id="<%= track_id %>" class="carousel-track" tabindex="0" role="group"
115
153
  aria-label="<%= label %> slides" data-carousel-target="track">
116
154
  <% items.each_with_index do |item, index| %>
155
+ <% if cascade %>
156
+ <div class="carousel-slide" role="group" aria-roledescription="slide"
157
+ aria-label="<%= slide_label ? slide_label.call(item) : "#{index + 1} of #{total}" %>"
158
+ data-carousel-target="slide" data-cascade-step="<%= cascade_slot.call(index) %>"<%= ' data-current'.html_safe if index == start_index %>><div class="carousel-cascade-body"><%= yield(item) %></div><% if caption %><div class="carousel-caption"><%= caption.call(item) %></div><% end %></div>
159
+ <% next %>
160
+ <% end %>
117
161
  <div class="carousel-slide" role="group" aria-roledescription="slide"
118
162
  aria-label="<%= slide_label ? slide_label.call(item) : "#{index + 1} of #{total}" %>"
119
163
  data-carousel-target="slide"<%= ' data-carousel-start-slide'.html_safe if start_index.positive? && index == start_index %><%= ' data-current'.html_safe if spotlight && index == start_index %>><% if spotlight %><div class="carousel-spotlight-body"><%= yield(item) %></div><% else %><%= yield(item) %><% end %><% if caption %><div class="carousel-caption"><%= caption.call(item) %></div><% end %></div>
@@ -0,0 +1,50 @@
1
+ <%# locals: (integration:, connections:, return_to:, linked:) %>
2
+ <%# One integration's card: status, what keeps it off, Connect (a POST, with
3
+ the account field when the admin names the account at Connect), and its
4
+ connections with Disconnect. No token, and no part of one, is shown. %>
5
+ <% provider = integration.provider %>
6
+ <% status = integration.status %>
7
+ <section class="card p-4" data-studio-integration-card="<%= integration.key %>" data-status="<%= status %>">
8
+ <div class="flex flex-wrap items-center justify-between gap-2">
9
+ <h2 class="text-heading font-semibold">
10
+ <% if linked %><a href="<%= integration_path_for(integration) %>" class="hover:underline"><%= integration.label %></a><% else %><%= integration.label %><% end %>
11
+ </h2>
12
+ <span class="badge" data-studio-integration-status><%= integration.status_label %></span>
13
+ </div>
14
+ <p class="text-sm text-secondary mt-1"><%= integration.summary %></p>
15
+
16
+ <% integration.missing.each do |reason| %>
17
+ <p class="text-sm text-muted mt-2" data-studio-integration-missing><%= reason %></p>
18
+ <% end %>
19
+
20
+ <% if connections.any? %>
21
+ <ul class="mt-3 divide-y divide-subtle" data-studio-integration-connections>
22
+ <% connections.each do |connection| %>
23
+ <li class="py-2 flex flex-wrap items-center justify-between gap-2" data-studio-integration-connection="<%= connection.id %>">
24
+ <div>
25
+ <p class="text-sm text-heading font-medium"><%= connection.label %></p>
26
+ <p class="text-xs text-muted">
27
+ Connected <%= connection.connected_at.utc.strftime("%Y-%m-%d %H:%M UTC") %><% if connection.connected_by.present? %> by <%= connection.connected_by %><% end %><% if connection.metadata.to_h["environment"].present? %> · <%= connection.metadata["environment"] %><% end %>
28
+ </p>
29
+ </div>
30
+ <%= button_to "Disconnect", integration_disconnect_path(integration, connection), method: :delete,
31
+ params: { return_to: }, class: "btn btn-outline btn-sm",
32
+ form: { data: { turbo_confirm: "Disconnect #{connection.label}?" } } %>
33
+ </li>
34
+ <% end %>
35
+ </ul>
36
+ <% end %>
37
+
38
+ <%= form_with url: integration_connect_path(integration), method: :post, local: true,
39
+ class: "mt-3 flex flex-wrap items-end gap-2", data: { studio_integration_connect: integration.key, turbo: false } do |form| %>
40
+ <%= hidden_field_tag :return_to, return_to %>
41
+ <% if provider.account_source == :connect %>
42
+ <label class="text-sm text-secondary">
43
+ <span class="block mb-1"><%= integration.definition.account_label %></span>
44
+ <%= text_field_tag provider.account_param, nil, class: "input-field py-2", required: true, autocomplete: "off",
45
+ placeholder: integration.definition.account_hint %>
46
+ </label>
47
+ <% end %>
48
+ <%= form.submit(connections.any? ? "Connect another" : "Connect", class: "btn btn-primary btn-sm") %>
49
+ <% end %>
50
+ </section>
@@ -0,0 +1,22 @@
1
+ <%# /admin/integrations: every integration the host enabled
2
+ (Studio.enable_integration), with its status and Connect
3
+ (Studio::IntegrationsController#index). %>
4
+ <% content_for(:title, "Integrations") %>
5
+ <div class="max-w-4xl mx-auto px-4 py-6" data-studio-integrations>
6
+ <%= render "studio/page_header", title: "Integrations" %>
7
+ <p class="text-sm text-secondary mt-1 mb-6">Connect an account once. Each integration's page shows its connections and what this app reads.</p>
8
+
9
+ <% if @integrations.empty? %>
10
+ <div class="empty-state">
11
+ <p class="text-heading font-semibold mb-1">No integrations enabled</p>
12
+ <p class="text-sm text-muted">Enable one with <code>Studio.enable_integration</code>; see the engine's docs/INTEGRATIONS.md.</p>
13
+ </div>
14
+ <% else %>
15
+ <div class="grid gap-4">
16
+ <% @integrations.each do |integration| %>
17
+ <%= render "studio/integrations/card", integration:, connections: integration.connections,
18
+ return_to: integrations_index_path, linked: true %>
19
+ <% end %>
20
+ </div>
21
+ <% end %>
22
+ </div>
@@ -0,0 +1,24 @@
1
+ <%# /admin/integrations/<key>: one enabled integration, its connections and
2
+ Disconnect, the redirect URI to register, and the host's own panel
3
+ (Studio.enable_integration panel:), rendered with locals integration: and
4
+ connections: (Studio::IntegrationsController#show). %>
5
+ <% content_for(:title, @integration.label) %>
6
+ <div class="max-w-4xl mx-auto px-4 py-6" data-studio-integration="<%= @integration.key %>">
7
+ <%= render "studio/page_header", title: @integration.label %>
8
+ <p class="text-sm mt-1 mb-6"><a href="<%= integrations_index_path %>" class="text-secondary hover:underline">All integrations</a></p>
9
+
10
+ <%= render "studio/integrations/card", integration: @integration, connections: @connections,
11
+ return_to: integration_path_for(@integration), linked: false %>
12
+
13
+ <div class="card p-4 mt-4" data-studio-integration-redirect>
14
+ <p class="label-upper mb-1">Redirect URI</p>
15
+ <p class="text-sm text-secondary mb-2">Register this exact URL on the <%= @integration.label %> app as its redirect (callback) URI.</p>
16
+ <code class="text-sm break-all"><%= integration_callback_url(@integration) %></code>
17
+ </div>
18
+
19
+ <% if @integration.panel %>
20
+ <div class="mt-6" data-studio-integration-panel>
21
+ <%= render partial: @integration.panel, locals: { integration: @integration, connections: @connections } %>
22
+ </div>
23
+ <% end %>
24
+ </div>
@@ -267,6 +267,21 @@
267
267
  <% end %>
268
268
  </div>
269
269
  <% end %>
270
+
271
+ <%# The cascade: a 3D stack, five in view (visible: 3 shows one each side, and so
272
+ does a region under 36rem). Click a side card, drag, or use the arrow keys. %>
273
+ <%= render layout: "style/specimen", locals: { trick: "cascade" } do %>
274
+ <div class="w-full min-w-0" data-carousel-cascade-specimen>
275
+ <%= render layout: "studio/carousel",
276
+ locals: { label: "Cascade specimen", items: (1..7).to_a, style: :cascade, loop: true,
277
+ id: "style-carousel-cascade-specimen", caption: ->(n) { "Slide #{n}" } } do |n| %>
278
+ <div class="card h-full p-5 space-y-1 aspect-[4/3]" style="background-image: linear-gradient(150deg, rgb(var(--color-primary-rgb) / 0.35), transparent)">
279
+ <p class="label-upper">Slide <%= n %></p>
280
+ <p class="text-sm text-body">Any block content.</p>
281
+ </div>
282
+ <% end %>
283
+ </div>
284
+ <% end %>
270
285
  </section>
271
286
 
272
287
  <!-- Surfaces, text and form -->
@@ -160,6 +160,13 @@ spotlight:
160
160
  note: "Centres one slide with its caption; its neighbours shrink and fade."
161
161
  resolve: [partial:studio/carousel, css:carousel-spotlight]
162
162
 
163
+ cascade:
164
+ name: Cascade Carousel
165
+ group: Carousel
166
+ token: "render layout: \"studio/carousel\", style: :cascade"
167
+ note: "A 3D stack: the open slide in front, the others stepping back either side."
168
+ resolve: [partial:studio/carousel, css:carousel-cascade]
169
+
163
170
  card:
164
171
  name: Card
165
172
  group: "Surfaces, text & form"
@@ -14,7 +14,9 @@
14
14
  # fail on existing rows or lock a large table.
15
15
  #
16
16
  # On every consumer that existed when this shipped, the second branch adds
17
- # nothing. Studio::HostSchema checks the same columns at boot.
17
+ # nothing. Studio::HostSchema checks the same columns at boot. The slug
18
+ # standard (NOT NULL, unique) is the later RequireSlugsOnEngineTables
19
+ # (20261108160000), which tightens the column on every host.
18
20
  class EnsureErrorLogsTable < ActiveRecord::Migration[7.2]
19
21
  def up
20
22
  unless table_exists?(:error_logs)
@@ -5,8 +5,9 @@
5
5
  # Sluggable, whose before_save writes `slug` on every save, and the setup doc's
6
6
  # hand-copied migration omitted it, so a theme save raises on any host built
7
7
  # from that doc (cyvasse, mcritchie-industries and moms-app when this shipped).
8
- # The slug is "theme-<app_name>", derived on save; existing rows keep a NULL
9
- # slug until their next save, and nothing looks a theme up by slug.
8
+ # The slug is "theme-<app_name>", derived on save. Rows this left with a NULL
9
+ # slug are filled, and the column made NOT NULL and unique, by the later
10
+ # RequireSlugsOnEngineTables (20261108160000).
10
11
  #
11
12
  # A baseline, not a rebuild:
12
13
  #
@@ -0,0 +1,35 @@
1
+ # CONNECTIONS (docs/CONNECTIONS.md): one row per third-party account a host app
2
+ # has connected over OAuth 2.0, for any provider the host declares with
3
+ # Studio.define_connection. The engine names no provider; `provider` is the
4
+ # host's key for one.
5
+ #
6
+ # One row per provider and account (`account_key`, unique within a provider):
7
+ # the account itself (a domain, a company id), or a keyed digest of it when the
8
+ # provider declares the account private, in which case the id is kept only in
9
+ # `account_secret`, encrypted. Every token column is encrypted with the app's
10
+ # Active Record encryption keys; a host without them cannot store a row.
11
+ #
12
+ # Installing the table changes nothing on its own: no route is drawn and no
13
+ # provider exists until the host declares one.
14
+ class CreateStudioConnections < ActiveRecord::Migration[7.2]
15
+ def change
16
+ create_table :studio_connections do |t|
17
+ t.string :provider, null: false
18
+ t.string :account_key, null: false
19
+ t.text :account_secret
20
+ t.string :label
21
+ t.text :access_token
22
+ t.text :refresh_token
23
+ t.datetime :access_expires_at
24
+ t.datetime :refresh_expires_at
25
+ t.json :metadata, null: false, default: {}
26
+ t.string :connected_by
27
+ t.datetime :connected_at, null: false
28
+ t.datetime :last_refreshed_at
29
+
30
+ t.timestamps
31
+ end
32
+
33
+ add_index :studio_connections, [:provider, :account_key], unique: true
34
+ end
35
+ end
@@ -0,0 +1,119 @@
1
+ # The engine's own settings and log tables take the hub's slug standard:
2
+ # `slug` NOT NULL with a unique index, on error_logs, theme_settings,
3
+ # studio_geo_settings and studio_site_identities (database audit 2026-11-07,
4
+ # finding 6). Every host inherits the tables, so one migration reaches them all.
5
+ #
6
+ # Each table goes through three steps, and a table the host does not have is
7
+ # skipped (its own create migration runs first whenever it is installed, since
8
+ # install:migrations copies the engine's migrations in order):
9
+ #
10
+ # 1. Backfill. A NULL or blank slug gets the one its model would write
11
+ # (Sluggable's `name_slug`): `error-log-<id>`, `theme-<app_name>`,
12
+ # `geo-<app_name>`, `site-identity-<app_name>`, with the app name
13
+ # parameterized. A slug another row already holds takes `-<id>` after it.
14
+ # 2. Duplicates. A table without a unique slug index (turf-monster's
15
+ # error_logs) may hold a slug twice; every copy after the lowest id takes
16
+ # `-<id>` after it. No table here has slug children, so nothing else
17
+ # references the old value.
18
+ # 3. NOT NULL, then the unique index on `slug` unless one is there. A
19
+ # non-unique slug index is replaced by the unique one.
20
+ #
21
+ # Production on 2026-11-08 (every app with a database, read-only counts): no
22
+ # NULL or blank slug, no duplicate, so steps 1 and 2 change no row there. The
23
+ # largest table is the hub's error_logs at 606 rows, so the NOT NULL scan and
24
+ # the index build are short. On Postgres each ALTER waits at most LOCK_TIMEOUT
25
+ # for its lock; a migrate that cannot get it fails whole, changes nothing, and
26
+ # runs again on the next release.
27
+ class RequireSlugsOnEngineTables < ActiveRecord::Migration[7.2]
28
+ LOCK_TIMEOUT = "10s"
29
+
30
+ # table => the slug prefix its model's name_slug writes before the app name.
31
+ # error_logs has no app name: its slug is the id.
32
+ NAMED = {
33
+ "theme_settings" => "theme",
34
+ "studio_geo_settings" => "geo",
35
+ "studio_site_identities" => "site-identity"
36
+ }.freeze
37
+ TABLES = (["error_logs"] + NAMED.keys).freeze
38
+
39
+ def up
40
+ set_lock_timeout
41
+ TABLES.each do |table|
42
+ next unless table_exists?(table) && column_exists?(table, :slug)
43
+
44
+ backfill(table)
45
+ dedupe(table)
46
+ change_column_null table, :slug, false
47
+ unique_slug_index(table)
48
+ end
49
+ end
50
+
51
+ # Only the NOT NULL is undone. The unique index stays: most hosts had it before
52
+ # this migration, and a down cannot tell which index it added. Backfilled slugs
53
+ # stay too; a slug is a valid value either way.
54
+ def down
55
+ TABLES.each do |table|
56
+ next unless table_exists?(table) && column_exists?(table, :slug)
57
+
58
+ change_column_null table, :slug, true
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def set_lock_timeout
65
+ return unless connection.adapter_name.downcase.include?("postgres")
66
+
67
+ execute "SET LOCAL lock_timeout = '#{LOCK_TIMEOUT}'"
68
+ end
69
+
70
+ def quoted(table) = connection.quote_table_name(table)
71
+
72
+ def backfill(table)
73
+ rows = connection.select_rows(<<~SQL.squish)
74
+ SELECT id#{', app_name' if NAMED.key?(table)} FROM #{quoted(table)}
75
+ WHERE slug IS NULL OR slug = '' ORDER BY id
76
+ SQL
77
+ rows.each do |id, app_name|
78
+ derived = derived_slug(table, id, app_name)
79
+ derived = "#{derived}-#{id}" if taken?(table, derived, id)
80
+ write_slug(table, id, derived)
81
+ end
82
+ end
83
+
84
+ def derived_slug(table, id, app_name)
85
+ return "error-log-#{id}" unless NAMED.key?(table)
86
+
87
+ name = ActiveSupport::Inflector.parameterize(app_name.to_s)
88
+ name.empty? ? "#{NAMED.fetch(table)}-#{id}" : "#{NAMED.fetch(table)}-#{name}"
89
+ end
90
+
91
+ def dedupe(table)
92
+ duplicates = connection.select_rows(<<~SQL.squish)
93
+ SELECT id, slug FROM #{quoted(table)} later
94
+ WHERE EXISTS (SELECT 1 FROM #{quoted(table)} earlier WHERE earlier.slug = later.slug AND earlier.id < later.id)
95
+ ORDER BY id
96
+ SQL
97
+ duplicates.each { |id, slug| write_slug(table, id, "#{slug}-#{id}") }
98
+ end
99
+
100
+ def taken?(table, slug, id)
101
+ connection.select_value(<<~SQL.squish).present?
102
+ SELECT 1 FROM #{quoted(table)} WHERE slug = #{connection.quote(slug)} AND id <> #{Integer(id)} LIMIT 1
103
+ SQL
104
+ end
105
+
106
+ def write_slug(table, id, slug)
107
+ connection.update(<<~SQL.squish, "#{self.class.name} backfill")
108
+ UPDATE #{quoted(table)} SET slug = #{connection.quote(slug)} WHERE id = #{Integer(id)}
109
+ SQL
110
+ end
111
+
112
+ def unique_slug_index(table)
113
+ slug_indexes = connection.indexes(table).select { |index| Array(index.columns) == ["slug"] }
114
+ return if slug_indexes.any?(&:unique)
115
+
116
+ slug_indexes.each { |index| remove_index table, name: index.name }
117
+ add_index table, :slug, unique: true
118
+ end
119
+ end