@proveanything/smartlinks 1.14.10 → 1.14.12
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/dist/api/contact.d.ts +2 -1
- package/dist/api/contact.js +46 -0
- package/dist/docs/API_SUMMARY.md +63 -2
- package/dist/docs/contact-search.md +162 -0
- package/dist/docs/overview.md +3 -0
- package/dist/docs/portal-auth-broadcast.md +26 -8
- package/dist/docs/portal-back-button.md +128 -36
- package/dist/docs/portal-request-action.md +450 -0
- package/dist/docs/portal-request-login.md +236 -0
- package/dist/openapi.yaml +171 -0
- package/dist/types/contact.d.ts +26 -0
- package/docs/API_SUMMARY.md +63 -2
- package/docs/contact-search.md +162 -0
- package/docs/overview.md +3 -0
- package/docs/portal-auth-broadcast.md +26 -8
- package/docs/portal-back-button.md +128 -36
- package/docs/portal-request-action.md +450 -0
- package/docs/portal-request-login.md +236 -0
- package/openapi.yaml +171 -0
- package/package.json +1 -1
package/dist/api/contact.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContactResponse, ContactCreateRequest, ContactUpdateRequest, ContactListResponse, PublicContactUpsertRequest, PublicContactUpsertResponse, UserSearchResponse, ContactPatch, PublicGetMyContactResponse, PublicUpdateMyContactResponse, ContactSchemaResponse } from "../types";
|
|
1
|
+
import { ContactResponse, ContactCreateRequest, ContactUpdateRequest, ContactListResponse, ContactSearchParams, ContactSearchResponse, PublicContactUpsertRequest, PublicContactUpsertResponse, UserSearchResponse, ContactPatch, PublicGetMyContactResponse, PublicUpdateMyContactResponse, ContactSchemaResponse } from "../types";
|
|
2
2
|
export declare namespace contact {
|
|
3
3
|
function create(collectionId: string, data: ContactCreateRequest): Promise<ContactResponse>;
|
|
4
4
|
function list(collectionId: string, params?: {
|
|
@@ -6,6 +6,7 @@ export declare namespace contact {
|
|
|
6
6
|
offset?: number;
|
|
7
7
|
includeDeleted?: boolean;
|
|
8
8
|
}): Promise<ContactListResponse>;
|
|
9
|
+
function search({ collectionId, q, typeahead, email, phone, id, userId, tags, tagsAll, source, locale, createdFrom, createdTo, externalIdKey, externalIdValue, customFieldKey, customFieldValue, limit, offset, }: ContactSearchParams): Promise<ContactSearchResponse>;
|
|
9
10
|
function get(collectionId: string, contactId: string, params?: {
|
|
10
11
|
includeDeleted?: boolean;
|
|
11
12
|
}): Promise<ContactResponse>;
|
package/dist/api/contact.js
CHANGED
|
@@ -19,6 +19,52 @@ export var contact;
|
|
|
19
19
|
return request(path);
|
|
20
20
|
}
|
|
21
21
|
contact.list = list;
|
|
22
|
+
async function search({ collectionId, q, typeahead, email, phone, id, userId, tags, tagsAll, source, locale, createdFrom, createdTo, externalIdKey, externalIdValue, customFieldKey, customFieldValue, limit, offset, }) {
|
|
23
|
+
const query = new URLSearchParams();
|
|
24
|
+
if (q !== undefined)
|
|
25
|
+
query.set("q", q);
|
|
26
|
+
if (typeahead !== undefined)
|
|
27
|
+
query.set("typeahead", String(typeahead));
|
|
28
|
+
if (email !== undefined)
|
|
29
|
+
query.set("email", email);
|
|
30
|
+
if (phone !== undefined)
|
|
31
|
+
query.set("phone", phone);
|
|
32
|
+
if (id !== undefined)
|
|
33
|
+
query.set("id", id);
|
|
34
|
+
if (userId !== undefined)
|
|
35
|
+
query.set("userId", userId);
|
|
36
|
+
if (tags !== undefined) {
|
|
37
|
+
const arr = Array.isArray(tags) ? tags : tags.split(",").map(t => t.trim());
|
|
38
|
+
arr.forEach(t => query.append("tags", t));
|
|
39
|
+
}
|
|
40
|
+
if (tagsAll !== undefined) {
|
|
41
|
+
const arr = Array.isArray(tagsAll) ? tagsAll : tagsAll.split(",").map(t => t.trim());
|
|
42
|
+
arr.forEach(t => query.append("tagsAll", t));
|
|
43
|
+
}
|
|
44
|
+
if (source !== undefined)
|
|
45
|
+
query.set("source", source);
|
|
46
|
+
if (locale !== undefined)
|
|
47
|
+
query.set("locale", locale);
|
|
48
|
+
if (createdFrom !== undefined)
|
|
49
|
+
query.set("createdFrom", createdFrom);
|
|
50
|
+
if (createdTo !== undefined)
|
|
51
|
+
query.set("createdTo", createdTo);
|
|
52
|
+
if (externalIdKey !== undefined)
|
|
53
|
+
query.set("externalIdKey", externalIdKey);
|
|
54
|
+
if (externalIdValue !== undefined)
|
|
55
|
+
query.set("externalIdValue", externalIdValue);
|
|
56
|
+
if (customFieldKey !== undefined)
|
|
57
|
+
query.set("customFieldKey", customFieldKey);
|
|
58
|
+
if (customFieldValue !== undefined)
|
|
59
|
+
query.set("customFieldValue", customFieldValue);
|
|
60
|
+
if (limit !== undefined)
|
|
61
|
+
query.set("limit", String(limit));
|
|
62
|
+
if (offset !== undefined)
|
|
63
|
+
query.set("offset", String(offset));
|
|
64
|
+
const path = `/admin/collection/${encodeURIComponent(collectionId)}/contacts/search?${query.toString()}`;
|
|
65
|
+
return request(path);
|
|
66
|
+
}
|
|
67
|
+
contact.search = search;
|
|
22
68
|
async function get(collectionId, contactId, params) {
|
|
23
69
|
const query = new URLSearchParams();
|
|
24
70
|
if ((params === null || params === void 0 ? void 0 : params.includeDeleted) !== undefined)
|
package/dist/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 1.14.
|
|
3
|
+
Version: 1.14.12 | Generated: 2026-05-19T11:25:45.278Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -36,6 +36,11 @@ For detailed guides on specific features:
|
|
|
36
36
|
- **[Product Facets SDK](PRODUCT_FACETS_SDK.md)** - Admin and public product facet endpoints and TypeScript interfaces
|
|
37
37
|
- **[Attestations](attestations.md)** - Append-only fact log with cryptographic chain integrity, time-series analytics, and public/owner/admin visibility
|
|
38
38
|
- **[Auth Kit](auth-kit.md)** - End-user authentication flows (email/password, magic link, OTP, OAuth) for microapps
|
|
39
|
+
- **[Portal Request Login](portal-request-login.md)** - Sub-apps delegate user authentication to the portal; `useSafeAuth().requestLogin` hook and iframe postMessage contract, redirect-bounce handling
|
|
40
|
+
- **[Portal Auth Broadcast](portal-auth-broadcast.md)** - Publishing a custom-flow session to the portal so the header, sibling apps, and SDK all stay in sync
|
|
41
|
+
- **[Portal Request Action](portal-request-action.md)** - Invoking portal built-in actions (`__qrScanner`, `__share`, `__logout`, etc.) from containers, widgets, and iframes
|
|
42
|
+
- **[Portal Back Button](portal-back-button.md)** - `parentPath` contract for hierarchy-aware "up" navigation; `useDeepLinkSync` integration
|
|
43
|
+
- **[Contact Search](contact-search.md)** - Admin contact search: free-text, typeahead, identity/tag/JSONB filters, and pagination
|
|
39
44
|
- **[App Data Storage](app-data-storage.md)** - User-specific and collection-scoped app data storage
|
|
40
45
|
- **[Forms](forms.md)** - Platform-managed form definitions, submissions, and schema-driven React form UI
|
|
41
46
|
- **[App Objects: Cases, Threads & Records](app-objects.md)** - Generic app-scoped building blocks for support cases, discussions, bookings, registrations, and more
|
|
@@ -89,7 +94,7 @@ The Smartlinks SDK is organized into the following namespaces:
|
|
|
89
94
|
— Identity & Access —
|
|
90
95
|
- **auth** - Admin authentication and account ops: login/logout, tokens, account info.
|
|
91
96
|
- **authKit** - End‑user auth flows (email/password, OAuth, phone); profiles and verification.
|
|
92
|
-
- **contact** - Manage customer contacts; CRUD, lookup, upsert, erase.
|
|
97
|
+
- **contact** - Manage customer contacts; CRUD, lookup, upsert, erase, and admin search. → [Guide](contact-search.md)
|
|
93
98
|
|
|
94
99
|
— Messaging & Audience —
|
|
95
100
|
- **comms** - Send notifications (push, email, wallet); templating, severity, delivery status. → [Guide](comms.md)
|
|
@@ -4460,6 +4465,40 @@ interface ContactListResponse {
|
|
|
4460
4465
|
}
|
|
4461
4466
|
```
|
|
4462
4467
|
|
|
4468
|
+
**ContactSearchParams** (interface)
|
|
4469
|
+
```typescript
|
|
4470
|
+
interface ContactSearchParams {
|
|
4471
|
+
collectionId: string
|
|
4472
|
+
q?: string
|
|
4473
|
+
typeahead?: boolean
|
|
4474
|
+
email?: string
|
|
4475
|
+
phone?: string
|
|
4476
|
+
id?: string
|
|
4477
|
+
userId?: string
|
|
4478
|
+
tags?: string | string[]
|
|
4479
|
+
tagsAll?: string | string[]
|
|
4480
|
+
source?: string
|
|
4481
|
+
locale?: string
|
|
4482
|
+
createdFrom?: string
|
|
4483
|
+
createdTo?: string
|
|
4484
|
+
externalIdKey?: string
|
|
4485
|
+
externalIdValue?: string
|
|
4486
|
+
customFieldKey?: string
|
|
4487
|
+
customFieldValue?: string
|
|
4488
|
+
limit?: number
|
|
4489
|
+
offset?: number
|
|
4490
|
+
}
|
|
4491
|
+
```
|
|
4492
|
+
|
|
4493
|
+
**ContactSearchResponse** (interface)
|
|
4494
|
+
```typescript
|
|
4495
|
+
interface ContactSearchResponse {
|
|
4496
|
+
items: Contact[]
|
|
4497
|
+
limit: number
|
|
4498
|
+
offset: number
|
|
4499
|
+
}
|
|
4500
|
+
```
|
|
4501
|
+
|
|
4463
4502
|
**PublicContactUpsertResponse** (interface)
|
|
4464
4503
|
```typescript
|
|
4465
4504
|
interface PublicContactUpsertResponse {
|
|
@@ -8629,6 +8668,28 @@ Returns all proof type definitions. Proof types are templates that specify which
|
|
|
8629
8668
|
**list**(collectionId: string,
|
|
8630
8669
|
params?: { limit?: number; offset?: number; includeDeleted?: boolean }) → `Promise<ContactListResponse>`
|
|
8631
8670
|
|
|
8671
|
+
**search**({
|
|
8672
|
+
collectionId,
|
|
8673
|
+
q,
|
|
8674
|
+
typeahead,
|
|
8675
|
+
email,
|
|
8676
|
+
phone,
|
|
8677
|
+
id,
|
|
8678
|
+
userId,
|
|
8679
|
+
tags,
|
|
8680
|
+
tagsAll,
|
|
8681
|
+
source,
|
|
8682
|
+
locale,
|
|
8683
|
+
createdFrom,
|
|
8684
|
+
createdTo,
|
|
8685
|
+
externalIdKey,
|
|
8686
|
+
externalIdValue,
|
|
8687
|
+
customFieldKey,
|
|
8688
|
+
customFieldValue,
|
|
8689
|
+
limit,
|
|
8690
|
+
offset,
|
|
8691
|
+
}: ContactSearchParams) → `Promise<ContactSearchResponse>`
|
|
8692
|
+
|
|
8632
8693
|
**get**(collectionId: string,
|
|
8633
8694
|
contactId: string,
|
|
8634
8695
|
params?: { includeDeleted?: boolean }) → `Promise<ContactResponse>`
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Contact Search
|
|
2
|
+
|
|
3
|
+
Admin-scoped endpoint for querying contacts within a collection. Supports
|
|
4
|
+
free-text search, type-ahead, identity lookup, structured filters, and JSONB
|
|
5
|
+
field queries. All parameters are optional and composable.
|
|
6
|
+
|
|
7
|
+
**Base path:** `GET /api/admin/:collectionId/contacts/search`
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Quick examples
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// Type-ahead while user types "joh" into a search box
|
|
15
|
+
await contact.search({ collectionId, q: "joh", typeahead: true })
|
|
16
|
+
|
|
17
|
+
// Find contacts by partial email
|
|
18
|
+
await contact.search({ collectionId, email: "acme.com" })
|
|
19
|
+
|
|
20
|
+
// Exact contact by UUID
|
|
21
|
+
await contact.search({ collectionId, id: "uuid-here" })
|
|
22
|
+
|
|
23
|
+
// All contacts tagged "vip" created this year
|
|
24
|
+
await contact.search({
|
|
25
|
+
collectionId,
|
|
26
|
+
tags: ["vip"],
|
|
27
|
+
createdFrom: "2026-01-01",
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
// Find by external ID (e.g. Shopify customer ID)
|
|
31
|
+
await contact.search({
|
|
32
|
+
collectionId,
|
|
33
|
+
externalIdKey: "shopify_id",
|
|
34
|
+
externalIdValue: "123456",
|
|
35
|
+
})
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Parameters
|
|
41
|
+
|
|
42
|
+
### Free-text
|
|
43
|
+
|
|
44
|
+
| Param | Type | Description |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| `q` | `string` | General search term. Searches `first_name`, `last_name`, `display_name`, `company`, and all identity values (`email`, `phone`). When the value contains `@` only email identities are searched; when it matches a phone pattern only phone identities are searched. |
|
|
47
|
+
| `typeahead` | `boolean` | When `true`, uses prefix (`startsWith`) operators instead of substring (`contains`). Significantly cheaper per keystroke. Default limit becomes `10`; minimum `q` length is 2 characters. Use this for live search-as-you-type UIs. |
|
|
48
|
+
|
|
49
|
+
### Identity filters
|
|
50
|
+
|
|
51
|
+
| Param | Type | Description |
|
|
52
|
+
|---|---|---|
|
|
53
|
+
| `email` | `string` | Partial match against normalised email identity values. Case-insensitive. |
|
|
54
|
+
| `phone` | `string` | Partial match against normalised phone identity values. |
|
|
55
|
+
|
|
56
|
+
### Exact lookups
|
|
57
|
+
|
|
58
|
+
These short-circuit all text/filter logic and return at most one contact.
|
|
59
|
+
|
|
60
|
+
| Param | Type | Description |
|
|
61
|
+
|---|---|---|
|
|
62
|
+
| `id` | `string` (UUID) | Contact primary key. |
|
|
63
|
+
| `userId` | `string` | Firebase auth UID linked to the contact. |
|
|
64
|
+
|
|
65
|
+
### Structured filters
|
|
66
|
+
|
|
67
|
+
All filters are ANDed with each other and with any text search.
|
|
68
|
+
|
|
69
|
+
| Param | Type | Description |
|
|
70
|
+
|---|---|---|
|
|
71
|
+
| `tags` | `string \| string[]` | Comma-separated string or repeated param. Contacts must have **any** of these tags. |
|
|
72
|
+
| `tagsAll` | `string \| string[]` | Contacts must have **all** of these tags. |
|
|
73
|
+
| `source` | `string` | Exact match on the `source` field. |
|
|
74
|
+
| `locale` | `string` | Exact match on the `locale` field (e.g. `"en-US"`). |
|
|
75
|
+
| `createdFrom` | `string` (ISO-8601) | Lower bound on `created_at`. |
|
|
76
|
+
| `createdTo` | `string` (ISO-8601) | Upper bound on `created_at`. |
|
|
77
|
+
|
|
78
|
+
### JSONB field filters
|
|
79
|
+
|
|
80
|
+
Searches inside the `external_ids` or `custom_fields` JSONB columns by
|
|
81
|
+
key/value pair. Both params in a pair must be supplied together.
|
|
82
|
+
|
|
83
|
+
| Param | Type | Description |
|
|
84
|
+
|---|---|---|
|
|
85
|
+
| `externalIdKey` | `string` | Top-level key in `externalIds` (e.g. `"shopify_id"`). |
|
|
86
|
+
| `externalIdValue` | `string` | Expected value at that key. |
|
|
87
|
+
| `customFieldKey` | `string` | Top-level key in `customFields`. |
|
|
88
|
+
| `customFieldValue` | `string` | Expected value at that key. |
|
|
89
|
+
|
|
90
|
+
### Pagination
|
|
91
|
+
|
|
92
|
+
| Param | Type | Default | Max |
|
|
93
|
+
|---|---|---|---|
|
|
94
|
+
| `limit` | `number` | `20` (`10` in typeahead mode) | `100` (`10` in typeahead mode) |
|
|
95
|
+
| `offset` | `number` | `0` | — |
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Response
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
{
|
|
103
|
+
items: Contact[],
|
|
104
|
+
limit: number,
|
|
105
|
+
offset: number,
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Each `Contact` item follows the shape defined in `src/types/contact.ts`.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## SDK usage
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { contact } from '@proveanything/smartlinks'
|
|
117
|
+
|
|
118
|
+
const results = await contact.search({
|
|
119
|
+
collectionId: "my-collection",
|
|
120
|
+
q: "jane",
|
|
121
|
+
tags: ["vip"],
|
|
122
|
+
limit: 20,
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
for (const c of results.items) {
|
|
126
|
+
console.log(c.displayName, c.email)
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Performance notes
|
|
133
|
+
|
|
134
|
+
The search endpoint is backed by **PostgreSQL trigram GIN indexes** via the
|
|
135
|
+
`pg_trgm` extension (migration `20260519000001`). This makes `ILIKE '%query%'`
|
|
136
|
+
scans fast even with millions of contacts per org.
|
|
137
|
+
|
|
138
|
+
**What is a trigram?** PostgreSQL decomposes every string into overlapping
|
|
139
|
+
3-character windows ("trigrams") and stores them in an inverted index. A query
|
|
140
|
+
for `"acme"` is converted into trigrams `" ac", "acm", "cme", "me "` and the
|
|
141
|
+
index returns only rows containing those windows — so Postgres never scans rows
|
|
142
|
+
that can't match, regardless of whether the query is a prefix, suffix, or
|
|
143
|
+
middle-of-word substring.
|
|
144
|
+
|
|
145
|
+
**Type-ahead mode** (`typeahead: true`) is the recommended pattern for
|
|
146
|
+
keystroke-by-keystroke UI. It emits `LIKE 'query%'` (prefix) operators instead
|
|
147
|
+
of `LIKE '%query%'` (substring). Prefix scans are cheaper because they require
|
|
148
|
+
fewer trigram lookups, making them safe to call on every keypress. Minimum query
|
|
149
|
+
length is enforced at 2 characters server-side to prevent over-broad scans.
|
|
150
|
+
|
|
151
|
+
**Future scale path:** At very high volumes, routing `search` through
|
|
152
|
+
Elasticsearch would add typo-tolerance and relevance ranking. The API surface is
|
|
153
|
+
intentionally implementation-agnostic so the backing engine can be swapped
|
|
154
|
+
without client changes.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Error codes
|
|
159
|
+
|
|
160
|
+
| Code | HTTP | Meaning |
|
|
161
|
+
|---|---|---|
|
|
162
|
+
| `SEARCH_REQUIRED` | 400 | No searchable parameter was provided. |
|
package/dist/docs/overview.md
CHANGED
|
@@ -65,6 +65,7 @@ The SmartLinks SDK (`@proveanything/smartlinks`) includes comprehensive document
|
|
|
65
65
|
| **Executors** | `docs/executor.md` | Building executor bundles for SEO, LLM content, programmatic config |
|
|
66
66
|
| **Deep Linking** | `docs/deep-link-discovery.md` | URL state management, navigable states, portal menus, AI nav |
|
|
67
67
|
| **Portal Back Button** | `docs/portal-back-button.md` | Hierarchy-aware "up" navigation inside embedded apps |
|
|
68
|
+
| **Portal Request Action** | `docs/portal-request-action.md` | Triggering portal built-in actions (__qrScanner, __share, __logout, etc.) from sub-apps |
|
|
68
69
|
| **Interactions** | `docs/interactions.md` | Business events, outcomes, voting, competitions, and journey triggers |
|
|
69
70
|
| **AI-Native Manifests** | `docs/manifests.md` | `app.manifest.json`, `app.admin.json`, `ai-guide.md` structure |
|
|
70
71
|
| **App Config Files** | `docs/app-manifest.md` | Full field-by-field reference for both JSON config files |
|
|
@@ -74,7 +75,9 @@ The SmartLinks SDK (`@proveanything/smartlinks`) includes comprehensive document
|
|
|
74
75
|
| **AI Guide Template** | `docs/ai-guide-template.md` | Template for creating `public/ai-guide.md` — customise per app |
|
|
75
76
|
| **Forms** | `docs/forms.md` | Form definitions, schema-driven rendering, submission patterns |
|
|
76
77
|
| **Auth Kit** | `docs/auth-kit.md` | End-user sign-in: email/password, magic links, phone OTP, Google OAuth |
|
|
78
|
+
| **Portal Request Login** | `docs/portal-request-login.md` | How sub-apps ask the portal to authenticate the user; hook and iframe postMessage contracts |
|
|
77
79
|
| **Portal Auth Broadcast** | `docs/portal-auth-broadcast.md` | Publishing custom auth flows to the portal; syncing sessions across containers and iframes |
|
|
80
|
+
| **Contact Search** | `docs/contact-search.md` | Admin contact search: free-text, typeahead, identity/tag/JSONB filters, and pagination |
|
|
78
81
|
| **App Records Pattern** | `docs/app-records-pattern.md` | Standard pattern for per-product/facet/variant/batch admin + public widget UIs |
|
|
79
82
|
| **UI Utils** | `docs/ui-utils.md` | `@proveanything/smartlinks-utils-ui` — React shells, hooks, and primitives for records-based apps |
|
|
80
83
|
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# Publishing Auth State to the Portal
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> **⚠️ Read [`portal-request-login.md`](./portal-request-login.md) first.**
|
|
4
|
+
> The recommended pattern for "I need a logged-in user before I continue"
|
|
5
|
+
> is `requestLogin` — the sub-app asks the portal to run its standard
|
|
6
|
+
> AuthKit flow and awaits a result. This doc covers the *other* case:
|
|
7
|
+
> a sub-app that runs its **own** authentication flow and needs to
|
|
8
|
+
> publish the resulting session up to the portal so the header, account
|
|
9
|
+
> UI, and sibling apps stay in sync.
|
|
4
10
|
|
|
5
11
|
A SmartLinks micro-app may need to run its own custom authentication flow —
|
|
6
12
|
typical cases: an auction app that calls a bidder API, a competition app
|
|
@@ -11,6 +17,7 @@ app pick up the new session.
|
|
|
11
17
|
|
|
12
18
|
This doc describes the contract the portal framework already implements.
|
|
13
19
|
|
|
20
|
+
|
|
14
21
|
---
|
|
15
22
|
|
|
16
23
|
## Container / Widget Apps (Same React Tree)
|
|
@@ -52,18 +59,28 @@ function BidButton() {
|
|
|
52
59
|
|
|
53
60
|
## Iframe Apps (Cross-Origin)
|
|
54
61
|
|
|
55
|
-
Iframe apps don't share React context
|
|
56
|
-
|
|
62
|
+
Iframe apps don't share React context with the portal. They publish their
|
|
63
|
+
session by posting framework-recognised messages on `window.parent`. The
|
|
64
|
+
portal's `IframeResponder` listens for these and routes them into the same
|
|
65
|
+
`login` / `logout` calls the built-in `AuthModal` makes.
|
|
66
|
+
|
|
67
|
+
> **Note:** There is no `authKit.publishLogin` / `publishLogout` helper in
|
|
68
|
+
> the SmartLinks SDK today. Use the raw `postMessage` calls below. If a
|
|
69
|
+
> helper ships later it will wrap exactly these payloads.
|
|
57
70
|
|
|
58
71
|
```ts
|
|
59
|
-
// LOGIN
|
|
72
|
+
// LOGIN — after your custom auth flow returns a token + user
|
|
60
73
|
window.parent.postMessage({
|
|
61
74
|
_smartlinksIframeMessage: true,
|
|
62
75
|
type: 'smartlinks:authkit:login',
|
|
63
76
|
payload: {
|
|
64
77
|
token: '<bearer>',
|
|
65
|
-
user: {
|
|
66
|
-
|
|
78
|
+
user: {
|
|
79
|
+
uid: 'usr_123',
|
|
80
|
+
email: 'bidder@example.com',
|
|
81
|
+
displayName: 'Jane Bidder',
|
|
82
|
+
},
|
|
83
|
+
accountData: { tier: 'gold' }, // optional, free-form
|
|
67
84
|
},
|
|
68
85
|
}, '*');
|
|
69
86
|
|
|
@@ -114,8 +131,9 @@ through the standard portal UI.
|
|
|
114
131
|
wiped.
|
|
115
132
|
|
|
116
133
|
❌ Implementing logout by just clearing your own state. Always call
|
|
117
|
-
`useAuth().logout()` (container/widget) or post
|
|
118
|
-
(iframe) so the whole portal
|
|
134
|
+
`useAuth().logout()` (container/widget) or post the
|
|
135
|
+
`smartlinks:authkit:logout` message (iframe) so the whole portal
|
|
136
|
+
session ends cleanly.
|
|
119
137
|
|
|
120
138
|
---
|
|
121
139
|
|
|
@@ -1,20 +1,36 @@
|
|
|
1
|
-
# Portal Back Button
|
|
1
|
+
# Portal Back Button — "Up" Navigation Inside Sub-Apps
|
|
2
2
|
|
|
3
|
-
> **For sub-app authors.**
|
|
3
|
+
> **For sub-app authors.** Drop this file into the SmartLinks SDK docs (e.g.
|
|
4
|
+
> `docs/portal-back-button.md`) and link it from `routing.md` / `mpa.md` so
|
|
5
|
+
> microapp authors discover it.
|
|
4
6
|
|
|
5
|
-
When a
|
|
7
|
+
When a sub-app is embedded by a portal shell, the shell renders a top-level
|
|
8
|
+
back button. By default that button **exits the app entirely** when tapped —
|
|
9
|
+
which is wrong for any app with internal hierarchy (lists → detail, wizards,
|
|
10
|
+
etc.).
|
|
6
11
|
|
|
7
|
-
This document describes the contract for telling the portal where "up" goes
|
|
12
|
+
This document describes the contract for telling the portal where "up" goes
|
|
13
|
+
from the current screen, so the top back button performs **hierarchy-aware
|
|
14
|
+
"up" navigation** inside your app instead.
|
|
8
15
|
|
|
9
|
-
|
|
16
|
+
---
|
|
10
17
|
|
|
11
|
-
|
|
18
|
+
## Why "up", not "back"
|
|
12
19
|
|
|
13
|
-
|
|
20
|
+
Browser back replays history. If a user navigates **list → item A → list →
|
|
21
|
+
item B**, browser back yo-yos: `B → list → A → list → ...`. That is not what
|
|
22
|
+
users expect from an "up arrow" in app chrome.
|
|
14
23
|
|
|
15
|
-
|
|
24
|
+
"Up" navigates the **content hierarchy**: `B → list → exit app`. It is
|
|
25
|
+
single-direction and idempotent. Only your app's router knows the hierarchy,
|
|
26
|
+
so the portal can't infer it — your app must declare it.
|
|
16
27
|
|
|
17
|
-
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## The Contract
|
|
31
|
+
|
|
32
|
+
With every `smartlinks-route-change` your app already posts (via
|
|
33
|
+
`useDeepLinkSync` or directly), include a `parentPath` field inside `state`:
|
|
18
34
|
|
|
19
35
|
```ts
|
|
20
36
|
window.parent.postMessage({
|
|
@@ -22,7 +38,8 @@ window.parent.postMessage({
|
|
|
22
38
|
path: '/items/123',
|
|
23
39
|
context: { collectionId: 'auction-2026', appId: 'auction' },
|
|
24
40
|
state: {
|
|
25
|
-
parentPath: '/items',
|
|
41
|
+
parentPath: '/items', // ← where "up" goes from /items/123
|
|
42
|
+
// ... your other app state
|
|
26
43
|
},
|
|
27
44
|
appId: 'auction',
|
|
28
45
|
}, '*');
|
|
@@ -30,43 +47,68 @@ window.parent.postMessage({
|
|
|
30
47
|
|
|
31
48
|
| `state.parentPath` value | Portal back-button behaviour |
|
|
32
49
|
| --- | --- |
|
|
33
|
-
| `'/items'` (or any string) |
|
|
34
|
-
| `''
|
|
50
|
+
| `'/items'` (or any string) | Posts `smartlinks-navigate` to the iframe with that path. App stays mounted. |
|
|
51
|
+
| `''` / missing / omitted | Default: clears the active app and returns to the portal homepage. |
|
|
52
|
+
|
|
53
|
+
When the portal sends the up-navigation message, your app must respond by
|
|
54
|
+
navigating to that path. If you use `useDeepLinkSync` with an SDK release
|
|
55
|
+
that includes the inbound `smartlinks-navigate` listener, this is automatic —
|
|
56
|
+
otherwise add a listener (see "Receiving the up-message" below).
|
|
35
57
|
|
|
36
|
-
|
|
58
|
+
---
|
|
37
59
|
|
|
38
|
-
## Recommended pattern
|
|
60
|
+
## Recommended sub-app pattern (React Router)
|
|
39
61
|
|
|
40
|
-
Keep
|
|
62
|
+
Keep "what's above this route" co-located with your route definitions:
|
|
41
63
|
|
|
42
64
|
```ts
|
|
65
|
+
// routes.ts
|
|
43
66
|
const PARENTS: Record<string, (params: any) => string | null> = {
|
|
44
|
-
'/':
|
|
45
|
-
'/items':
|
|
46
|
-
'/items/:id':
|
|
47
|
-
'/items/:id/bid':
|
|
48
|
-
'/checkout':
|
|
67
|
+
'/': () => null, // home — back exits the app
|
|
68
|
+
'/items': () => null, // list — back exits the app
|
|
69
|
+
'/items/:id': () => '/items', // detail — back goes to list
|
|
70
|
+
'/items/:id/bid': ({ id }) => `/items/${id}`,
|
|
71
|
+
'/checkout': () => '/items',
|
|
49
72
|
};
|
|
50
73
|
|
|
51
74
|
export function getParentPath(pathname: string): string | null {
|
|
52
|
-
//
|
|
53
|
-
|
|
75
|
+
// matchPath against PARENTS keys — return parent or null
|
|
76
|
+
// (use react-router's matchPath in your real implementation)
|
|
54
77
|
}
|
|
55
78
|
```
|
|
56
79
|
|
|
57
|
-
|
|
80
|
+
```tsx
|
|
81
|
+
// App.tsx
|
|
82
|
+
import { useDeepLinkSync } from '@/hooks/useDeepLinkSync';
|
|
83
|
+
import { getParentPath } from './routes';
|
|
84
|
+
|
|
85
|
+
function App() {
|
|
86
|
+
useDeepLinkSync({
|
|
87
|
+
getParentPath: ({ pathname }) => getParentPath(pathname),
|
|
88
|
+
});
|
|
89
|
+
// ...
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
If your app does not use `useDeepLinkSync`, post the message yourself:
|
|
58
94
|
|
|
59
95
|
```ts
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
if (window.parent === window) return;
|
|
98
|
+
window.parent.postMessage({
|
|
99
|
+
type: 'smartlinks-route-change',
|
|
100
|
+
path: location.pathname,
|
|
101
|
+
context: { /* ... */ },
|
|
102
|
+
state: { parentPath: getParentPath(location.pathname) ?? '' },
|
|
103
|
+
}, '*');
|
|
104
|
+
}, [location.pathname]);
|
|
63
105
|
```
|
|
64
106
|
|
|
65
|
-
|
|
107
|
+
---
|
|
66
108
|
|
|
67
|
-
## Receiving the up-message
|
|
109
|
+
## Receiving the up-message (`smartlinks-navigate`)
|
|
68
110
|
|
|
69
|
-
When the portal consumes `parentPath`, it posts
|
|
111
|
+
When the portal back button consumes a `parentPath`, it posts:
|
|
70
112
|
|
|
71
113
|
```ts
|
|
72
114
|
{
|
|
@@ -78,18 +120,68 @@ When the portal consumes `parentPath`, it posts `smartlinks-navigate` back to th
|
|
|
78
120
|
}
|
|
79
121
|
```
|
|
80
122
|
|
|
81
|
-
Your app
|
|
123
|
+
Your app must listen for this and route accordingly. A minimal hook:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { useEffect } from 'react';
|
|
127
|
+
import { useNavigate } from 'react-router-dom';
|
|
128
|
+
|
|
129
|
+
export function useParentNavigation() {
|
|
130
|
+
const navigate = useNavigate();
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
const onMessage = (e: MessageEvent) => {
|
|
133
|
+
if (e.data?.type !== 'smartlinks-navigate') return;
|
|
134
|
+
if (typeof e.data.path !== 'string') return;
|
|
135
|
+
navigate(e.data.path);
|
|
136
|
+
};
|
|
137
|
+
window.addEventListener('message', onMessage);
|
|
138
|
+
return () => window.removeEventListener('message', onMessage);
|
|
139
|
+
}, [navigate]);
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Reference: Updated `RouteChangeMessage`
|
|
146
|
+
|
|
147
|
+
`state` is an open `Record<string, string>` — `parentPath` is a recognised
|
|
148
|
+
optional convention; everything else flows through unchanged.
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
interface RouteChangeMessage {
|
|
152
|
+
type: 'smartlinks-route-change';
|
|
153
|
+
path: string;
|
|
154
|
+
context: Record<string, string>;
|
|
155
|
+
state: Record<string, string> & {
|
|
156
|
+
/**
|
|
157
|
+
* Optional. The "up" target from the current screen. When present, the
|
|
158
|
+
* portal's top back button posts smartlinks-navigate with this path
|
|
159
|
+
* instead of exiting the app. Empty / missing → exits the app.
|
|
160
|
+
*/
|
|
161
|
+
parentPath?: string;
|
|
162
|
+
};
|
|
163
|
+
appId?: string;
|
|
164
|
+
}
|
|
165
|
+
```
|
|
82
166
|
|
|
83
|
-
|
|
167
|
+
No breaking change: existing apps that don't emit `parentPath` keep today's
|
|
168
|
+
behaviour (one tap of the portal back exits the app).
|
|
84
169
|
|
|
85
|
-
|
|
170
|
+
---
|
|
86
171
|
|
|
87
172
|
## FAQ
|
|
88
173
|
|
|
89
|
-
**Do I need to push every query-param change as a navigation step?**
|
|
174
|
+
**Q: Do I need to push every query-param change as a navigation step?**
|
|
175
|
+
No. `parentPath` is hierarchy, not history. A filter toggle, a tab switch,
|
|
176
|
+
or a modal open on the same screen should keep the same `parentPath`.
|
|
90
177
|
|
|
91
|
-
**What if my up
|
|
178
|
+
**Q: What if my "up" leaves the app?**
|
|
179
|
+
Set `parentPath` to `''` (or omit it). The portal will exit the app on back.
|
|
92
180
|
|
|
93
|
-
**Can I disable the portal back button on certain screens?**
|
|
181
|
+
**Q: Can I disable the portal back button on certain screens?**
|
|
182
|
+
Not directly via this protocol. Use the existing portal `homeScope: 'entry'`
|
|
183
|
+
mechanism if you need the entire portal back button suppressed.
|
|
94
184
|
|
|
95
|
-
**What about
|
|
185
|
+
**Q: What about the in-app back button I already render?**
|
|
186
|
+
Keep it if you want — they're not mutually exclusive. The portal back is
|
|
187
|
+
chrome; an in-content back is content. Many apps will only need one.
|