spine-framework-portal 0.2.20 → 0.2.22

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/LICENSE.md ADDED
@@ -0,0 +1,193 @@
1
+ Spine Framework Internal Use License 1.0.0
2
+ Source-available. Free for internal use. Commercial rights reserved.
3
+
4
+ This license is based on the structure and intent of the PolyForm Internal Use License 1.0.0, but it has been modified for Spine Framework. This is not the unmodified PolyForm Internal Use License.
5
+
6
+ Required Notice
7
+ Required Notice: Copyright © 2026 Dahl Ventures Inc. All rights reserved.
8
+
9
+ 1. Acceptance
10
+ In order to receive any license under these terms, you must agree to these terms as both strict obligations and conditions to all licenses granted to you.
11
+
12
+ If you do not agree to these terms, you do not have permission to use, copy, modify, run, install, access, or create works based on Spine Framework.
13
+
14
+ 2. Definitions
15
+ Software means Spine Framework, including its source code, object code, packages, modules, templates, schemas, migrations, configuration files, documentation, examples, command-line tools, SDKs, application packs, and related materials provided by the licensor.
16
+
17
+ Licensor means the legal owner of Spine Framework.
18
+
19
+ You means the individual or legal entity receiving the Software.
20
+
21
+ Your Company means the legal entity on whose behalf you use the Software, including that entity's employees and authorized contractors.
22
+
23
+ Internal Business Use means use of the Software solely inside Your Company for Your Company's own internal business operations, internal workflows, internal applications, internal data, internal users, and internal customers or accounts.
24
+
25
+ Third Party means any person or legal entity other than You or Your Company.
26
+
27
+ Commercial License means a separate written agreement signed by the Licensor that grants rights beyond this license.
28
+
29
+ 3. Copyright License
30
+ The Licensor grants You a copyright license to do everything with the Software that would otherwise infringe the Licensor's copyright, but only for Internal Business Use and only as permitted by these terms.
31
+
32
+ You may install, run, access, evaluate, test, configure, and use the Software for Internal Business Use.
33
+
34
+ You may copy the Software only as reasonably necessary for Internal Business Use, including backup, deployment, development, testing, staging, disaster recovery, and internal security review.
35
+
36
+ You may not distribute the Software except as expressly allowed in these terms.
37
+
38
+ 4. Changes and New Works
39
+ The Licensor grants You a copyright license to modify the Software and create new works based on the Software, but only for Internal Business Use.
40
+
41
+ You may create internal applications, extensions, workflows, integrations, automations, schemas, roles, agents, triggers, pipelines, dashboards, reports, and other internal business systems using the Software.
42
+
43
+ You may not distribute, sell, sublicense, transfer, lease, rent, host for others, white-label, resell, or commercially exploit any modified version, derivative work, extension, application pack, template, or implementation of the Software except under a Commercial License.
44
+
45
+ 5. Internal Contractors
46
+ Your Company may allow employees and contractors to access and use the Software solely on behalf of Your Company and solely for Your Company's Internal Business Use.
47
+
48
+ Contractors do not receive any independent right to use the Software for themselves, their other clients, their own products, or any Third Party.
49
+
50
+ Your Company is responsible for all use of the Software by its employees, contractors, agents, and representatives.
51
+
52
+ 6. Your Data and Application-Specific Work
53
+ As between You and the Licensor, You own Your Company's data, records, content, prompts, business logic, customer records, internal workflows, and application-specific code that You independently create using the Software.
54
+
55
+ These terms do not give the Licensor ownership of Your Company's data or independently created application-specific business content.
56
+
57
+ However, ownership of Your Company's data or application-specific work does not give You the right to distribute, resell, white-label, host, or commercially exploit the Software or any portion of the Software except as allowed by these terms or a Commercial License.
58
+
59
+ 7. Prohibited Uses
60
+ You may not do any of the following without a Commercial License:
61
+
62
+ Sell, resell, sublicense, rent, lease, lend, transfer, assign, publish, or distribute the Software.
63
+ Offer the Software, or any modified version of the Software, to Third Parties as software, infrastructure, a framework, a platform, a service, or a hosted product.
64
+ Offer the Software as SaaS, PaaS, IaaS, framework-as-a-service, backend-as-a-service, workflow-as-a-service, automation-as-a-service, AI-agent platform, managed service, support service, or similar commercial service.
65
+ White-label, private-label, rebrand, or remove Spine Framework identity from the Software in order to provide it to Third Parties.
66
+ Embed, bundle, package, or include the Software in any product, service, appliance, marketplace offering, application pack, starter kit, template library, SDK, CLI, distribution, or managed implementation made available to Third Parties.
67
+ Use the Software to operate, power, support, or provide a product or service for Third Parties where those Third Parties receive access to the Software or to functionality substantially provided by the Software.
68
+ Use the Software to build, operate, or improve a competing framework, platform, marketplace, application generator, agentic software infrastructure product, or commercial development infrastructure product.
69
+ Provide implementation, consulting, hosting, support, customization, training, migration, or managed services for the Software to Third Parties as a paid or commercial offering, except as expressly authorized by the Licensor.
70
+ Remove, alter, obscure, or bypass copyright notices, license notices, attribution, trademarks, branding, license keys, license checks, usage limits, or technical protection measures included in the Software.
71
+ Use the Software in violation of law, regulation, third-party rights, or these terms.
72
+ 8. Examples of Permitted Use
73
+ The following are permitted under this license, provided they are solely for Internal Business Use:
74
+
75
+ A company installs Spine Framework to build its own internal CRM.
76
+ A company uses Spine Framework to operate an internal customer support portal for its own support team and its own customers.
77
+ A company modifies Spine Framework for its internal workflows, roles, permissions, automations, pipelines, and integrations.
78
+ A company lets its employees and authorized contractors configure, maintain, and support its internal Spine Framework installation.
79
+ A company creates internal dashboards, agents, knowledge bases, audit trails, and operational tools on top of Spine Framework.
80
+ 9. Examples Requiring a Commercial License
81
+ The following are not permitted under this license and require a Commercial License:
82
+
83
+ Selling Spine Framework or a modified version of Spine Framework.
84
+ Offering Spine Framework as a hosted SaaS product.
85
+ Offering a white-labeled application built on Spine Framework to customers.
86
+ Packaging Spine Framework into a commercial starter kit, template, marketplace app, agency offering, or developer platform.
87
+ Running Spine Framework for multiple clients as a managed service provider, agency, consultant, systems integrator, or outsourcing firm.
88
+ Embedding Spine Framework into a product sold to customers.
89
+ Forking Spine Framework to launch a competing framework, backend, app platform, AI-agent platform, or development infrastructure product.
90
+ Publishing modified Spine Framework source code to a public repository.
91
+ Giving a customer, client, partner, reseller, or affiliate a copy of Spine Framework.
92
+ 10. Distribution
93
+ You may not distribute the Software, modified versions of the Software, or works based on the Software to any Third Party except as expressly permitted by these terms or a Commercial License.
94
+
95
+ You may share copies of the Software with employees and contractors of Your Company only as necessary for Internal Business Use and only if they are bound by obligations consistent with these terms.
96
+
97
+ Any copy of the Software must include this license and all Required Notices.
98
+
99
+ 11. Trademarks
100
+ This license does not grant You any right to use the Licensor's names, trademarks, service marks, logos, product names, domain names, or branding except as necessary to identify the Software for Internal Business Use.
101
+
102
+ You may not use Spine Framework branding in a way that suggests sponsorship, endorsement, partnership, certification, resale authorization, or commercial authorization without written permission from the Licensor.
103
+
104
+ 12. Patent License
105
+ The Licensor grants You a patent license for the Software that covers patent claims the Licensor can license, or later becomes able to license, that You would infringe by using the Software as permitted by these terms.
106
+
107
+ 13. Patent Defense
108
+ If You make any written claim that the Software infringes or contributes to infringement of any patent, Your patent license for the Software ends immediately.
109
+
110
+ If Your Company makes such a claim, Your Company's patent license ends immediately.
111
+
112
+ 14. Fair Use and Other Legal Rights
113
+ You may have fair use, fair dealing, or other rights under applicable law. These terms do not limit rights that the law does not allow these terms to limit.
114
+
115
+ 15. No Other Rights
116
+ These terms do not allow You to sublicense, transfer, assign, or delegate any license granted under these terms except as expressly allowed here.
117
+
118
+ These terms do not prevent the Licensor from granting licenses to anyone else.
119
+
120
+ These terms do not imply any license other than the licenses expressly granted here.
121
+
122
+ All rights not expressly granted are reserved by the Licensor.
123
+
124
+ 16. Violations and Cure
125
+ The first time You are notified in writing that You have violated these terms, or done anything with the Software not covered by these terms, Your licenses can continue if You:
126
+
127
+ come into full compliance with these terms;
128
+ take practical steps to correct past violations; and
129
+ complete both within 32 days of receiving written notice.
130
+ If You do not satisfy those requirements, all licenses granted to You under these terms end immediately.
131
+
132
+ For any later violation, all licenses granted to You under these terms end immediately without any cure period.
133
+
134
+ 17. Termination
135
+ When Your licenses end, You must stop all use of the Software and destroy all copies of the Software in Your possession or control, except copies you are legally required to retain for archival, compliance, or legal purposes.
136
+
137
+ Sections concerning ownership, prohibited uses, trademarks, patent defense, no other rights, violations, termination, no warranty, limitation of liability, and general terms survive termination.
138
+
139
+ 18. No Warranty
140
+ As far as the law allows, the Software is provided as is and as available, without any warranty or condition, express or implied.
141
+
142
+ The Licensor disclaims all warranties and conditions, including warranties of merchantability, fitness for a particular purpose, title, non-infringement, availability, accuracy, security, and quiet enjoyment.
143
+
144
+ 19. Limitation of Liability
145
+ As far as the law allows, the Licensor will not be liable to You for any indirect, incidental, special, consequential, exemplary, punitive, or other damages arising out of these terms or the Software.
146
+
147
+ As far as the law allows, the Licensor will not be liable for lost profits, lost revenue, lost savings, lost data, business interruption, security incidents, procurement of substitute services, or loss of goodwill.
148
+
149
+ The Licensor's total liability arising out of these terms or the Software will not exceed the amount You paid the Licensor for the Software during the 12 months before the event giving rise to liability, or USD $100 if You paid nothing.
150
+
151
+ 20. Commercial Licensing
152
+ Rights not granted under this license may be available under a separate Commercial License from the Licensor.
153
+
154
+ A Commercial License is required for resale, redistribution, SaaS, managed services, white-label use, OEM use, marketplace distribution, partner use, commercial hosting, commercial support offerings, or any use outside Internal Business Use.
155
+
156
+ To request commercial rights, contact:
157
+
158
+ spine-framework.com
159
+ webmaster@spine-framework.com
160
+ 21. License Updates
161
+ The Licensor may publish updated versions of this license from time to time.
162
+
163
+ Each release, package, download, or copy of the Software is governed by the license terms included with that release, package, download, or copy, unless You and the Licensor have signed a separate written agreement.
164
+
165
+ Updated license terms apply only to future releases, downloads, packages, updates, upgrades, patches, hosted access, or other versions of the Software made available after the updated terms are published.
166
+
167
+ The Licensor may require acceptance of updated license terms as a condition of receiving or using future releases, updates, hosted services, commercial features, support, documentation, marketplace access, license keys, portals, application packs, or other Spine Framework services.
168
+
169
+ Nothing in this section gives You rights to continue using future versions of the Software under earlier license terms.
170
+
171
+ 22. General Terms
172
+ If any part of these terms is held unenforceable, the rest remains in effect as far as the law allows.
173
+
174
+ Failure by the Licensor to enforce any term is not a waiver.
175
+
176
+ Any waiver must be in writing and signed by the Licensor.
177
+
178
+ These terms are the entire license terms for the Software unless You and the Licensor have signed a separate written agreement.
179
+
180
+ 23. Plain-English Summary
181
+ This summary is not part of the legal license.
182
+
183
+ You may use Spine Framework inside your own company for your own internal business operations.
184
+
185
+ You may modify Spine Framework for your own internal use.
186
+
187
+ You may let your employees and contractors work on your internal Spine Framework installation.
188
+
189
+ You may not sell it, redistribute it, white-label it, host it for others, offer it as SaaS, package it into another product, use it as a managed service offering, or use it to build a competing framework without a separate commercial license.
190
+
191
+ Future versions, updates, services, support, portals, packs, license keys, and commercial features may require acceptance of updated terms.
192
+
193
+ Spine Framework is source-available. It is not open source.
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Spine Framework Portal
2
+
3
+ Portal is a customer-facing self-service app for [Spine Framework](https://spine-framework.com). It gives customers access to tickets, knowledge base, courses, community, and marketplace — all under your brand.
4
+
5
+ ## Features
6
+
7
+ - **Tickets** — Submit and track support tickets
8
+ - **Knowledge Base** — Browse and search help articles
9
+ - **Courses** — Access course catalog and track progress
10
+ - **Community** — Community discussions and Q&A
11
+ - **Marketplace** — App and integration marketplace
12
+
13
+ ## Requirements
14
+
15
+ - [Spine Framework](https://www.npmjs.com/package/spine-framework) `>=0.1.0`
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npx spine-framework install-app spine-framework-portal
21
+ ```
22
+
23
+ This will:
24
+ 1. Copy app files to `custom/apps/portal/`
25
+ 2. Run any pending migrations
26
+ 3. Seed roles, types, link-types, and triggers into the database
27
+ 4. Register the app in `spine.config.json`
28
+
29
+ ## Configuration
30
+
31
+ After installation, edit `custom/apps/portal/manifest.json` to configure:
32
+
33
+ - `route_prefix` — where the app is served (default: `/portal`)
34
+ - `registration` — self-registration behaviour and account strategy (`new` creates a new account per customer, `existing` assigns to a shared account)
35
+
36
+ To apply manifest changes to the database without reinstalling:
37
+
38
+ ```bash
39
+ npx spine-framework update-db-app portal
40
+ ```
41
+
42
+ ## License
43
+
44
+ See [LICENSE.md](./LICENSE.md)
@@ -1,5 +1,4 @@
1
1
  import { useState } from 'react'
2
- import { getTypeIdAsync } from '../hooks/useTypeRegistry'
3
2
  import { apiFetch } from '@core/lib/api'
4
3
  import { Card, CardContent, CardHeader } from '@core/components/ui/card'
5
4
  import { Button } from '@core/components/ui/button'
@@ -40,13 +39,12 @@ export function KBGenerator({ ticket, onGenerated, onCancel }: KBGeneratorProps)
40
39
  const handleSave = async () => {
41
40
  if (!generatedArticle) return
42
41
  try {
43
- const kbArticleTypeId = await getTypeIdAsync('kb_article')
44
42
  const res = await apiFetch('/.netlify/functions/admin-data', {
45
43
  method: 'POST',
46
44
  headers: { 'Content-Type': 'application/json' },
47
45
  body: JSON.stringify({
48
46
  entity: 'items',
49
- type_id: kbArticleTypeId,
47
+ type_slug: 'kb_article',
50
48
  title: generatedArticle.title,
51
49
  status: 'published',
52
50
  description: editedContent,
@@ -165,7 +165,7 @@ export const checkUnanswered = createHandler(async (ctx, _body) => {
165
165
  // Resolve type IDs dynamically
166
166
  const [supportTicketTypeId, threadTypeId] = await Promise.all([
167
167
  resolveTypeId('item', 'support_ticket'),
168
- resolveTypeId('thread', 'thread')
168
+ resolveTypeId('thread', 'support_thread')
169
169
  ])
170
170
 
171
171
  try {
@@ -1,12 +1,12 @@
1
1
  import { createHandler } from './_shared/middleware'
2
+ import { adminDb } from './_shared/db'
2
3
  import { resolveTypeId } from './_shared/resolve-ids'
3
- import { create } from './admin-data'
4
4
 
5
5
  export const handler = createHandler(async (ctx, body) => {
6
- const {
7
- action_type,
8
- action_value,
9
- action_description,
6
+ const {
7
+ action_type,
8
+ action_value,
9
+ action_description,
10
10
  session_id,
11
11
  url,
12
12
  path,
@@ -27,7 +27,14 @@ export const handler = createHandler(async (ctx, body) => {
27
27
  throw err
28
28
  }
29
29
 
30
- const typeId = await resolveTypeId('item', 'funnel_signal')
30
+ // Get the funnel_signal type_id
31
+ const { data: typeId } = await adminDb
32
+ .from('types')
33
+ .select('id')
34
+ .eq('kind', 'item')
35
+ .eq('slug', 'funnel_signal')
36
+ .single()
37
+
31
38
  if (!typeId) {
32
39
  const err: any = new Error('funnel_signal type not found')
33
40
  err.statusCode = 500
@@ -35,33 +42,36 @@ export const handler = createHandler(async (ctx, body) => {
35
42
  }
36
43
 
37
44
  const signalData = {
38
- identity_person_id: ctx.principal.id,
39
- identity_account_id: ctx.accountId,
40
- identity_session_id: session_id || `portal_${ctx.principal.id}_${Date.now()}`,
41
- identity_anonymous_id: anonymous_id || null,
42
- classification_stage: 'identified',
43
- classification_source: 'port',
45
+ account_id: ctx.accountId,
46
+ person_id: ctx.principal.id,
47
+ session_id: session_id || `portal_${ctx.principal.id}_${Date.now()}`,
48
+ anonymous_id: anonymous_id || null,
49
+ stage: 'identified',
50
+ source: 'port', // Portal-specific source for user engagement tracking
44
51
  action_type,
45
52
  action_value,
46
53
  ...(action_description && { action_description }),
47
- ...(url && { portal_url: url }),
48
- ...(path && { portal_path: path }),
49
- ...(referrer && { portal_referrer: referrer }),
50
- ...(user_agent && { portal_user_agent: user_agent }),
51
- processing_received_at: new Date().toISOString()
54
+ ...(url && { url }),
55
+ ...(path && { path }),
56
+ ...(referrer && { referrer }),
57
+ ...(user_agent && { user_agent }),
58
+ occurred_at: new Date().toISOString()
52
59
  }
53
60
 
54
- // Delegate to admin-data.create so design_schema, validation_schema,
55
- // scope resolution, and audit fields are all stamped correctly.
56
- const signal = await create(ctx, {
57
- entity: 'items',
58
- type_id: typeId,
59
- title: `${action_type} - ${action_value}`,
60
- data: signalData
61
- })
61
+ // Create the signal item directly using admin-data pattern
62
+ const { data: signal, error } = await adminDb
63
+ .from('items')
64
+ .insert({
65
+ type_id: typeId.id,
66
+ title: `${action_type} - ${action_value}`,
67
+ account_id: ctx.accountId,
68
+ data: signalData
69
+ })
70
+ .select('id')
71
+ .single()
62
72
 
63
- if (!signal?.id) {
64
- const err: any = new Error('Failed to create signal')
73
+ if (error || !signal) {
74
+ const err: any = new Error(`Failed to create signal: ${error?.message || 'Unknown error'}`)
65
75
  err.statusCode = 500
66
76
  throw err
67
77
  }
@@ -153,7 +153,7 @@ export const handler = createHandler(async (ctx, body) => {
153
153
 
154
154
  const [supportTicket, thread, triageAgentId, promptConfigId] = await Promise.all([
155
155
  resolveTypeId('item', 'support_ticket'),
156
- resolveTypeId('thread', 'thread'),
156
+ resolveTypeId('thread', 'support_thread'),
157
157
  resolveAgentId('Support Triage Agent'),
158
158
  resolvePromptConfigId('support_triage'),
159
159
  ])
@@ -1,6 +1,5 @@
1
1
  import { useState, useEffect, useCallback } from 'react'
2
2
  import { apiFetch } from '@core/lib/api'
3
- import { getTypeIdAsync } from './useTypeRegistry'
4
3
 
5
4
  export interface CommunityPost {
6
5
  id: string
@@ -59,12 +58,9 @@ export function useCreatePost() {
59
58
  setLoading(true)
60
59
  setError(null)
61
60
  try {
62
- const typeId = await getTypeIdAsync('community_post')
63
- if (!typeId) throw new Error('community_post type not found')
64
-
65
61
  return await fetchJSON('/.netlify/functions/admin-data', {
66
62
  method: 'POST',
67
- body: JSON.stringify({ entity: 'items', type_id: typeId, ...fields }),
63
+ body: JSON.stringify({ entity: 'items', type_slug: 'community_post', ...fields }),
68
64
  })
69
65
  } catch (e: any) {
70
66
  setError(e.message)
@@ -76,7 +76,7 @@ export function useUpsertProgress() {
76
76
  const upsert = useCallback(async (params: {
77
77
  personId: string
78
78
  itemId: string
79
- typeId: string
79
+ typeSlug: string
80
80
  accountId: string
81
81
  appId?: string
82
82
  status?: string
@@ -92,7 +92,7 @@ export function useUpsertProgress() {
92
92
  body: JSON.stringify({
93
93
  person_id: params.personId,
94
94
  item_id: params.itemId,
95
- type_id: params.typeId,
95
+ type_slug: params.typeSlug,
96
96
  account_id: params.accountId,
97
97
  app_id: params.appId,
98
98
  status: params.status,
@@ -1,6 +1,5 @@
1
1
  import { useState, useEffect, useCallback } from 'react'
2
2
  import { apiFetch } from '@core/lib/api'
3
- import { getTypeIdAsync } from './useTypeRegistry'
4
3
 
5
4
  export interface PortalMessage {
6
5
  id: string
@@ -35,19 +34,36 @@ async function fetchJSON(path: string, options?: RequestInit) {
35
34
  return json.data
36
35
  }
37
36
 
38
- export function usePortalThread(targetType: string, targetId: string | null) {
37
+ type ThreadDomain = 'support' | 'community' | 'generic'
38
+
39
+ function getThreadTypeSlug(domain: ThreadDomain) {
40
+ if (domain === 'support') return 'support_thread'
41
+ if (domain === 'community') return 'community_thread'
42
+ return 'thread'
43
+ }
44
+
45
+ function getMessageTypeSlug(domain: ThreadDomain) {
46
+ if (domain === 'support') return 'support_reply'
47
+ if (domain === 'community') return 'community_reply'
48
+ return 'message'
49
+ }
50
+
51
+ export function usePortalThread(targetType: string, targetId: string | null, domain: ThreadDomain = 'generic') {
39
52
  const [thread, setThread] = useState<PortalThread | null>(null)
40
53
  const [messages, setMessages] = useState<PortalMessage[]>([])
41
54
  const [loading, setLoading] = useState(false)
42
55
  const [error, setError] = useState<string | null>(null)
43
56
 
57
+ const threadTypeSlug = getThreadTypeSlug(domain)
58
+ const messageTypeSlug = getMessageTypeSlug(domain)
59
+
44
60
  const load = useCallback(async () => {
45
61
  if (!targetId) return
46
62
  setLoading(true)
47
63
  setError(null)
48
64
  try {
49
65
  const threads = await fetchJSON(
50
- `/.netlify/functions/admin-data?entity=threads&target_type=${targetType}&target_id=${targetId}`
66
+ `/.netlify/functions/admin-data?entity=threads&target_type=${targetType}&target_id=${targetId}&type_slug=${threadTypeSlug}`
51
67
  )
52
68
  const found: PortalThread | null = Array.isArray(threads) ? (threads[0] ?? null) : null
53
69
  setThread(found)
@@ -64,7 +80,7 @@ export function usePortalThread(targetType: string, targetId: string | null) {
64
80
  } finally {
65
81
  setLoading(false)
66
82
  }
67
- }, [targetType, targetId])
83
+ }, [targetType, targetId, threadTypeSlug])
68
84
 
69
85
  useEffect(() => { load() }, [load])
70
86
 
@@ -72,14 +88,11 @@ export function usePortalThread(targetType: string, targetId: string | null) {
72
88
  let activeThread = thread
73
89
 
74
90
  if (!activeThread?.id) {
75
- const threadTypeId = await getTypeIdAsync('thread')
76
- if (!threadTypeId) throw new Error('thread type not found')
77
-
78
91
  activeThread = await fetchJSON('/.netlify/functions/admin-data', {
79
92
  method: 'POST',
80
93
  body: JSON.stringify({
81
94
  entity: 'threads',
82
- type_id: threadTypeId,
95
+ type_slug: threadTypeSlug,
83
96
  target_type: targetType,
84
97
  target_id: targetId,
85
98
  status: 'open',
@@ -88,9 +101,6 @@ export function usePortalThread(targetType: string, targetId: string | null) {
88
101
  setThread(activeThread)
89
102
  }
90
103
 
91
- const messageTypeId = await getTypeIdAsync('message')
92
- if (!messageTypeId) throw new Error('message type not found')
93
-
94
104
  // Calculate next sequence based on current messages to avoid stale state
95
105
  const nextSequence = messages.reduce((max, m) => Math.max(max, m.sequence || 0), 0) + 1
96
106
 
@@ -98,7 +108,7 @@ export function usePortalThread(targetType: string, targetId: string | null) {
98
108
  method: 'POST',
99
109
  body: JSON.stringify({
100
110
  entity: 'messages',
101
- type_id: messageTypeId,
111
+ type_slug: messageTypeSlug,
102
112
  thread_id: activeThread!.id,
103
113
  content,
104
114
  direction: 'inbound',
@@ -107,7 +117,7 @@ export function usePortalThread(targetType: string, targetId: string | null) {
107
117
  })
108
118
  setMessages((prev) => [...prev, msg])
109
119
  return msg
110
- }, [thread, targetType, targetId, messages])
120
+ }, [thread, targetType, targetId, messages, threadTypeSlug, messageTypeSlug])
111
121
 
112
122
  return { thread, messages, loading, error, reply, refetch: load }
113
123
  }
@@ -1,6 +1,5 @@
1
1
  import { useState, useEffect, useCallback } from 'react'
2
2
  import { apiFetch } from '@core/lib/api'
3
- import { getTypeIdAsync } from './useTypeRegistry'
4
3
 
5
4
  export interface Ticket {
6
5
  id: string
@@ -77,12 +76,9 @@ export function useCreateTicket() {
77
76
  setLoading(true)
78
77
  setError(null)
79
78
  try {
80
- const typeId = await getTypeIdAsync('support_ticket')
81
- if (!typeId) throw new Error('support_ticket type not found')
82
-
83
79
  return await fetchJSON('/.netlify/functions/admin-data', {
84
80
  method: 'POST',
85
- body: JSON.stringify({ entity: 'items', type_id: typeId, ...fields }),
81
+ body: JSON.stringify({ entity: 'items', type_slug: 'support_ticket', ...fields }),
86
82
  })
87
83
  } catch (e: any) {
88
84
  setError(e.message)
package/manifest.json CHANGED
@@ -2,10 +2,9 @@
2
2
  "name": "Portal",
3
3
  "slug": "portal",
4
4
  "description": "Self-service portal for customers to access tickets, knowledge base, courses, and community",
5
- "version": "0.2.20",
5
+ "version": "0.2.22",
6
6
  "app_type": "full",
7
- "route_prefix": "/",
8
- "prod_domain": "portal.spine-framework.com",
7
+ "route_prefix": "/portal",
9
8
  "required_roles": ["member", "member_admin"],
10
9
  "routes": [
11
10
  "/",
@@ -42,7 +41,7 @@
42
41
  "registration": {
43
42
  "enabled": true,
44
43
  "default_role": "member",
45
- "redirect_path": "/",
44
+ "redirect_path": "/portal",
46
45
  "account_strategy": "new"
47
46
  }
48
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spine-framework-portal",
3
- "version": "0.2.20",
3
+ "version": "0.2.22",
4
4
  "private": false,
5
5
  "description": "Customer Portal — self-service portal app for Spine Framework",
6
6
  "type": "module",
@@ -22,7 +22,7 @@ const CHANNEL_LABELS: Record<string, string> = {
22
22
  }
23
23
 
24
24
  function ThreadPane({ post }: { post: CommunityPost }) {
25
- const { messages, loading, reply } = usePortalThread('items', post.id)
25
+ const { messages, loading, reply } = usePortalThread('items', post.id, 'community')
26
26
  const [replyText, setReplyText] = useState('')
27
27
  const [sending, setSending] = useState(false)
28
28
  const { sendSignal } = usePortalSignal()
@@ -1,10 +1,9 @@
1
- import { useState, useEffect, useRef } from 'react'
1
+ import { useState, useEffect } from 'react'
2
2
  import { CheckCircle, Circle, PlayCircle, GraduationCap, Send } from 'lucide-react'
3
3
  import { useCourseLessons, type CourseItem } from '../hooks/useCourses'
4
4
  import { usePortalSignal } from '../hooks/usePortalSignal'
5
5
  import { useItemProgress, useUpsertProgress } from '../hooks/useItemProgress'
6
6
  import { usePortalThread } from '../hooks/usePortalThreads'
7
- import { getTypeIdAsync } from '../hooks/useTypeRegistry'
8
7
  import { useAuth } from '@core/contexts/AuthContext'
9
8
  import { SearchFilterBar } from '../components/SearchFilterBar'
10
9
  import { Button } from '@core/components/ui/button'
@@ -42,7 +41,6 @@ export function CoursesPage() {
42
41
  const [selectedId, setSelectedId] = useState<string | null>(() => localStorage.getItem(LAST_LESSON_KEY))
43
42
  const [replyText, setReplyText] = useState('')
44
43
  const [replying, setReplying] = useState(false)
45
- const progressTypeIdRef = useRef<string | null>(null)
46
44
 
47
45
  const { lessons, loading, error } = useCourseLessons()
48
46
  const lessonIds = lessons.map((l) => l.id)
@@ -60,10 +58,6 @@ export function CoursesPage() {
60
58
  }
61
59
  }, [lessons, selectedId])
62
60
 
63
- useEffect(() => {
64
- getTypeIdAsync(PROGRESS_TYPE_SLUG).then((id) => { progressTypeIdRef.current = id })
65
- }, [])
66
-
67
61
  const courseMap = groupByCourse(lessons)
68
62
  const courseNames = Array.from(courseMap.keys())
69
63
  const filteredCourses = courseNames.filter((c) => c.toLowerCase().includes(search.toLowerCase()))
@@ -75,11 +69,10 @@ export function CoursesPage() {
75
69
  const handleSelectLesson = async (lessonId: string) => {
76
70
  setSelectedId(lessonId)
77
71
  localStorage.setItem(LAST_LESSON_KEY, lessonId)
78
- const typeId = progressTypeIdRef.current
79
- if (!typeId || !user?.id || !user?.account_id) return
72
+ if (!user?.id || !user?.account_id) return
80
73
  const existing = progressMap.get(lessonId)
81
74
  if (!existing || existing.status === 'not_started') {
82
- await upsert({ personId: user.id, itemId: lessonId, typeId, accountId: user.account_id, status: 'in_progress' })
75
+ await upsert({ personId: user.id, itemId: lessonId, typeSlug: PROGRESS_TYPE_SLUG, accountId: user.account_id, status: 'in_progress' })
83
76
  refetchProgress()
84
77
  sendSignal('lesson_start', 'Started a course lesson')
85
78
  }
@@ -87,9 +80,7 @@ export function CoursesPage() {
87
80
 
88
81
  const handleComplete = async () => {
89
82
  if (!selectedId || !user?.id || !user?.account_id) return
90
- const typeId = progressTypeIdRef.current
91
- if (!typeId) return
92
- await upsert({ personId: user.id, itemId: selectedId, typeId, accountId: user.account_id, status: 'completed' })
83
+ await upsert({ personId: user.id, itemId: selectedId, typeSlug: PROGRESS_TYPE_SLUG, accountId: user.account_id, status: 'completed' })
93
84
  refetchProgress()
94
85
  sendSignal('lesson_complete', 'Completed a course lesson')
95
86
  }
@@ -85,7 +85,7 @@ function AIResponseCard({ message, ticketId, messageId, onFeedback }: {
85
85
  }
86
86
 
87
87
  function TicketThread({ ticketId, ticketStatus, onStatusChange }: TicketThreadProps) {
88
- const { messages, loading, thread, refetch } = usePortalThread('items', ticketId)
88
+ const { messages, loading, thread, refetch } = usePortalThread('items', ticketId, 'support')
89
89
  const [replyText, setReplyText] = useState('')
90
90
  const [aiState, setAiState] = useState<'idle' | 'analyzing' | 'responded' | 'escalated'>('idle')
91
91
  const { sendReply, loading: replying } = useTriageReply()
package/seed/types.json CHANGED
@@ -1300,10 +1300,162 @@
1300
1300
  }
1301
1301
  },
1302
1302
  {
1303
- "kind": "item",
1303
+ "kind": "thread",
1304
+ "slug": "support_thread",
1305
+ "name": "Support Thread",
1306
+ "description": "Customer-visible conversation thread attached to a support ticket",
1307
+ "icon": "message-square",
1308
+ "color": "#EF4444",
1309
+ "ownership": "tenant",
1310
+ "is_active": true,
1311
+ "validation_schema": {},
1312
+ "design_schema": {
1313
+ "scope": "account",
1314
+ "views": {
1315
+ "default_list": {
1316
+ "type": "list",
1317
+ "label": "Support Threads",
1318
+ "fields": {
1319
+ "title": { "sortable": true, "display_type": "text" },
1320
+ "target_type": { "sortable": true, "display_type": "text" },
1321
+ "visibility": { "sortable": true, "display_type": "badge" },
1322
+ "status": { "sortable": true, "display_type": "badge" }
1323
+ },
1324
+ "display": "table"
1325
+ },
1326
+ "default_detail": {
1327
+ "type": "detail",
1328
+ "label": "Support Thread",
1329
+ "sections": [
1330
+ { "title": "Overview", "fields": ["title", "target_type", "target_id", "visibility", "status"] }
1331
+ ]
1332
+ }
1333
+ },
1334
+ "fields": {
1335
+ "title": { "data_type": "text", "label": "Title", "required": false, "system": true },
1336
+ "target_type": { "data_type": "text", "label": "Target Type", "required": true, "system": true },
1337
+ "target_id": { "data_type": "uuid", "label": "Target ID", "required": true, "system": true },
1338
+ "visibility": { "data_type": "text", "label": "Visibility", "required": true, "system": true },
1339
+ "status": { "data_type": "text", "label": "Status", "required": true, "system": true },
1340
+ "is_active": { "data_type": "boolean", "label": "Active", "required": true, "system": true },
1341
+ "created_at": { "data_type": "datetime", "label": "Created", "required": false, "system": true, "readonly": true },
1342
+ "updated_at": { "data_type": "datetime", "label": "Updated", "required": false, "system": true, "readonly": true }
1343
+ },
1344
+ "record_permissions": {
1345
+ "system_admin": ["create", "read", "update", "delete"],
1346
+ "support_admin": ["create", "read", "update"],
1347
+ "support": ["create", "read", "update"],
1348
+ "member_admin": ["create", "read", "update"],
1349
+ "member": ["create", "read", "update"]
1350
+ }
1351
+ }
1352
+ },
1353
+ {
1354
+ "kind": "message",
1355
+ "slug": "support_reply",
1356
+ "name": "Support Reply",
1357
+ "description": "Customer or agent message within a support thread",
1358
+ "icon": "message-circle",
1359
+ "color": "#EF4444",
1360
+ "ownership": "tenant",
1361
+ "is_active": true,
1362
+ "validation_schema": {},
1363
+ "design_schema": {
1364
+ "scope": "account",
1365
+ "views": {
1366
+ "default_list": {
1367
+ "type": "list",
1368
+ "label": "Support Replies",
1369
+ "fields": {
1370
+ "content": { "sortable": false, "display_type": "text" },
1371
+ "direction": { "sortable": true, "display_type": "badge" },
1372
+ "visibility": { "sortable": true, "display_type": "badge" },
1373
+ "created_at": { "sortable": true, "display_type": "datetime" }
1374
+ },
1375
+ "display": "table"
1376
+ },
1377
+ "default_detail": {
1378
+ "type": "detail",
1379
+ "label": "Support Reply",
1380
+ "sections": [
1381
+ { "title": "Content", "fields": ["content", "direction", "visibility"] }
1382
+ ]
1383
+ }
1384
+ },
1385
+ "fields": {
1386
+ "content": { "data_type": "textarea", "label": "Content", "required": true, "system": true },
1387
+ "direction": { "data_type": "text", "label": "Direction", "required": true, "system": true },
1388
+ "sequence": { "data_type": "number", "label": "Sequence", "required": true, "system": true },
1389
+ "visibility": { "data_type": "text", "label": "Visibility", "required": true, "system": true },
1390
+ "is_active": { "data_type": "boolean", "label": "Active", "required": true, "system": true },
1391
+ "created_at": { "data_type": "datetime", "label": "Created", "required": false, "system": true, "readonly": true },
1392
+ "updated_at": { "data_type": "datetime", "label": "Updated", "required": false, "system": true, "readonly": true }
1393
+ },
1394
+ "record_permissions": {
1395
+ "system_admin": ["create", "read", "update", "delete"],
1396
+ "support_admin": ["create", "read", "update"],
1397
+ "support": ["create", "read", "update"],
1398
+ "member_admin": ["create", "read", "update"],
1399
+ "member": ["create", "read", "update"]
1400
+ }
1401
+ }
1402
+ },
1403
+ {
1404
+ "kind": "thread",
1405
+ "slug": "community_thread",
1406
+ "name": "Community Thread",
1407
+ "description": "Public discussion thread attached to a community post",
1408
+ "icon": "users",
1409
+ "color": "#6366F1",
1410
+ "ownership": "tenant",
1411
+ "is_active": true,
1412
+ "validation_schema": {},
1413
+ "design_schema": {
1414
+ "scope": "platform",
1415
+ "views": {
1416
+ "default_list": {
1417
+ "type": "list",
1418
+ "label": "Community Threads",
1419
+ "fields": {
1420
+ "title": { "sortable": true, "display_type": "text" },
1421
+ "target_type": { "sortable": true, "display_type": "text" },
1422
+ "visibility": { "sortable": true, "display_type": "badge" },
1423
+ "status": { "sortable": true, "display_type": "badge" }
1424
+ },
1425
+ "display": "table"
1426
+ },
1427
+ "default_detail": {
1428
+ "type": "detail",
1429
+ "label": "Community Thread",
1430
+ "sections": [
1431
+ { "title": "Overview", "fields": ["title", "target_type", "target_id", "visibility", "status"] }
1432
+ ]
1433
+ }
1434
+ },
1435
+ "fields": {
1436
+ "title": { "data_type": "text", "label": "Title", "required": false, "system": true },
1437
+ "target_type": { "data_type": "text", "label": "Target Type", "required": true, "system": true },
1438
+ "target_id": { "data_type": "uuid", "label": "Target ID", "required": true, "system": true },
1439
+ "visibility": { "data_type": "text", "label": "Visibility", "required": true, "system": true },
1440
+ "status": { "data_type": "text", "label": "Status", "required": true, "system": true },
1441
+ "is_active": { "data_type": "boolean", "label": "Active", "required": true, "system": true },
1442
+ "created_at": { "data_type": "datetime", "label": "Created", "required": false, "system": true, "readonly": true },
1443
+ "updated_at": { "data_type": "datetime", "label": "Updated", "required": false, "system": true, "readonly": true }
1444
+ },
1445
+ "record_permissions": {
1446
+ "system_admin": ["create", "read", "update", "delete"],
1447
+ "support_admin": ["create", "read", "update"],
1448
+ "support": ["create", "read", "update"],
1449
+ "member_admin": ["create", "read", "update"],
1450
+ "member": ["create", "read", "update"]
1451
+ }
1452
+ }
1453
+ },
1454
+ {
1455
+ "kind": "message",
1304
1456
  "slug": "community_reply",
1305
1457
  "name": "Community Reply",
1306
- "description": "Reply to a community post or discussion",
1458
+ "description": "Public reply within a community thread",
1307
1459
  "icon": "message-circle",
1308
1460
  "color": "#22C55E",
1309
1461
  "ownership": "tenant",
@@ -1316,18 +1468,10 @@
1316
1468
  "type": "list",
1317
1469
  "label": "Community Replies",
1318
1470
  "fields": {
1319
- "title": {
1320
- "sortable": true,
1321
- "display_type": "text"
1322
- },
1323
- "parent_post_id": {
1324
- "sortable": true,
1325
- "display_type": "text"
1326
- },
1327
- "created_at": {
1328
- "sortable": true,
1329
- "display_type": "datetime"
1330
- }
1471
+ "content": { "sortable": false, "display_type": "text" },
1472
+ "direction": { "sortable": true, "display_type": "badge" },
1473
+ "visibility": { "sortable": true, "display_type": "badge" },
1474
+ "created_at": { "sortable": true, "display_type": "datetime" }
1331
1475
  },
1332
1476
  "display": "table"
1333
1477
  },
@@ -1335,73 +1479,26 @@
1335
1479
  "type": "detail",
1336
1480
  "label": "Community Reply",
1337
1481
  "sections": [
1338
- {
1339
- "title": "Content",
1340
- "fields": [
1341
- "title",
1342
- "content"
1343
- ]
1344
- },
1345
- {
1346
- "title": "Context",
1347
- "fields": [
1348
- "parent_post_id"
1349
- ]
1350
- }
1482
+ { "title": "Content", "fields": ["content", "direction", "visibility"] }
1351
1483
  ]
1352
1484
  }
1353
1485
  },
1354
1486
  "fields": {
1355
- "title": {
1356
- "label": "Title",
1357
- "required": true,
1358
- "data_type": "text"
1359
- },
1360
- "content": {
1361
- "label": "Content",
1362
- "required": true,
1363
- "data_type": "textarea"
1364
- },
1365
- "parent_post_id": {
1366
- "label": "Parent Post ID",
1367
- "required": true,
1368
- "data_type": "text"
1369
- },
1370
- "is_solution": {
1371
- "label": "Is Solution",
1372
- "data_type": "boolean",
1373
- "default": false
1374
- }
1487
+ "content": { "data_type": "textarea", "label": "Content", "required": true, "system": true },
1488
+ "direction": { "data_type": "text", "label": "Direction", "required": true, "system": true },
1489
+ "sequence": { "data_type": "number", "label": "Sequence", "required": true, "system": true },
1490
+ "visibility": { "data_type": "text", "label": "Visibility", "required": true, "system": true },
1491
+ "is_active": { "data_type": "boolean", "label": "Active", "required": true, "system": true },
1492
+ "created_at": { "data_type": "datetime", "label": "Created", "required": false, "system": true, "readonly": true },
1493
+ "updated_at": { "data_type": "datetime", "label": "Updated", "required": false, "system": true, "readonly": true }
1375
1494
  },
1376
1495
  "record_permissions": {
1377
- "system_admin": [
1378
- "create",
1379
- "read",
1380
- "update",
1381
- "delete"
1382
- ],
1383
- "support_admin": [
1384
- "create",
1385
- "read",
1386
- "update"
1387
- ],
1388
- "support": [
1389
- "create",
1390
- "read",
1391
- "update"
1392
- ],
1393
- "member_admin": [
1394
- "create",
1395
- "read",
1396
- "update"
1397
- ],
1398
- "member": [
1399
- "create",
1400
- "read",
1401
- "update"
1402
- ]
1403
- },
1404
- "functionality": null
1496
+ "system_admin": ["create", "read", "update", "delete"],
1497
+ "support_admin": ["create", "read", "update"],
1498
+ "support": ["create", "read", "update"],
1499
+ "member_admin": ["create", "read", "update"],
1500
+ "member": ["create", "read", "update"]
1501
+ }
1405
1502
  }
1406
1503
  }
1407
1504
  ]
@@ -1,74 +0,0 @@
1
- import { useState, useEffect } from 'react'
2
- import { supabase } from '@core/lib/supabase'
3
-
4
- interface TypeRecord {
5
- id: string
6
- slug: string
7
- name: string
8
- description?: string
9
- }
10
-
11
- // Module-level cache - persists across renders, shared across hooks
12
- let typeCache: Map<string, TypeRecord> | null = null
13
- let loadPromise: Promise<Map<string, TypeRecord>> | null = null
14
-
15
- async function fetchTypes(): Promise<Map<string, TypeRecord>> {
16
- if (typeCache) return typeCache
17
- if (loadPromise) return loadPromise
18
-
19
- loadPromise = (async () => {
20
- try {
21
- // Query Supabase directly - types is a config table, not exposed via admin-data
22
- const { data: types, error } = await supabase
23
- .from('types')
24
- .select('id, slug, name, description')
25
- .eq('is_active', true)
26
- .limit(100)
27
-
28
- if (error) throw error
29
-
30
- typeCache = new Map((types || []).map(t => [t.slug, t]))
31
- return typeCache
32
- } catch (e) {
33
- console.error('Failed to load types:', e)
34
- typeCache = new Map() // Empty cache on error
35
- return typeCache
36
- } finally {
37
- loadPromise = null
38
- }
39
- })()
40
-
41
- return loadPromise
42
- }
43
-
44
- export function useTypeRegistry() {
45
- const [types, setTypes] = useState<Map<string, TypeRecord>>(typeCache || new Map())
46
- const [loading, setLoading] = useState(!typeCache)
47
- const [error, setError] = useState<string | null>(null)
48
-
49
- useEffect(() => {
50
- if (typeCache) return
51
-
52
- fetchTypes()
53
- .then(cache => {
54
- setTypes(cache)
55
- setLoading(false)
56
- })
57
- .catch(e => {
58
- setError(e.message)
59
- setLoading(false)
60
- })
61
- }, [])
62
-
63
- const getTypeId = (slug: string): string | null => {
64
- return types.get(slug)?.id || null
65
- }
66
-
67
- return { types, loading, error, getTypeId }
68
- }
69
-
70
- // Synchronous version for use inside async functions
71
- export async function getTypeIdAsync(slug: string): Promise<string | null> {
72
- const cache = await fetchTypes()
73
- return cache.get(slug)?.id || null
74
- }