@proveanything/smartlinks 2.1.32 → 2.1.34
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/adminViews.d.ts +86 -0
- package/dist/adminViews.js +179 -0
- package/dist/api/address.d.ts +50 -0
- package/dist/api/address.js +66 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/interactions.d.ts +3 -0
- package/dist/api/interactions.js +3 -0
- package/dist/context.d.ts +5 -0
- package/dist/context.js +4 -1
- package/dist/docs/API_SUMMARY.md +91 -9
- package/dist/docs/admin-views.md +94 -0
- package/dist/docs/app-manifest.md +19 -0
- package/dist/index.d.ts +1 -1
- package/dist/openapi.yaml +142 -0
- package/dist/site.d.ts +5 -0
- package/dist/types/address.d.ts +92 -0
- package/dist/types/address.js +5 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/docs/API_SUMMARY.md +91 -9
- package/docs/admin-views.md +94 -0
- package/docs/app-manifest.md +19 -0
- package/openapi.yaml +142 -0
- package/package.json +1 -1
package/dist/adminViews.d.ts
CHANGED
|
@@ -97,8 +97,94 @@ export interface OpenAppRequest {
|
|
|
97
97
|
* SL.adminViews.openApp({ appId: 'crm', view: 'contact', params: { contactId } })
|
|
98
98
|
*/
|
|
99
99
|
export declare function openApp(req: OpenAppRequest): void;
|
|
100
|
+
/** One destination: its name, the params it needs, and what it opens. */
|
|
101
|
+
export interface DestinationInfo {
|
|
102
|
+
name: string;
|
|
103
|
+
/** Params that must be given. */
|
|
104
|
+
required: string[];
|
|
105
|
+
/** Params that may be given. */
|
|
106
|
+
optional?: string[];
|
|
107
|
+
/** What it opens, in a few words. */
|
|
108
|
+
description: string;
|
|
109
|
+
}
|
|
110
|
+
/** The platform's screens any admin screen can open by name. */
|
|
111
|
+
export declare const DESTINATIONS: DestinationInfo[];
|
|
112
|
+
/** A destination name. Any string is accepted, so a newer host's names work on an older SDK. */
|
|
113
|
+
export type Destination = 'contacts' | 'contact' | 'contact.messages' | 'conversation' | 'segment' | 'message.compose' | 'message.log' | 'campaign.new' | 'campaign' | 'templates' | 'template' | 'product' | 'proof' | 'interaction.type' | 'settings' | 'settings.address' | 'settings.domain' | 'settings.languages' | 'settings.translations' | 'settings.email' | 'settings.team' | 'settings.userGroups' | 'settings.setupLists' | 'settings.portal' | 'settings.hub' | 'settings.signIn' | 'media' | 'app' | (string & {});
|
|
114
|
+
/** What a message is about (the same shape as `comms.sendTransactional`'s `about`). Ids only. */
|
|
115
|
+
export interface DestinationAbout {
|
|
116
|
+
appId?: string;
|
|
117
|
+
type: string;
|
|
118
|
+
id: string;
|
|
119
|
+
view?: string;
|
|
120
|
+
params?: Record<string, string>;
|
|
121
|
+
label?: string;
|
|
122
|
+
}
|
|
123
|
+
/** Params for `open`: ids as strings, plus `about` (messages) and `params` (`app`). */
|
|
124
|
+
export interface OpenParams {
|
|
125
|
+
contactId?: string;
|
|
126
|
+
conversationId?: string;
|
|
127
|
+
segmentId?: string;
|
|
128
|
+
campaignId?: string;
|
|
129
|
+
templateId?: string;
|
|
130
|
+
productId?: string;
|
|
131
|
+
proofId?: string;
|
|
132
|
+
interactionId?: string;
|
|
133
|
+
appId?: string;
|
|
134
|
+
view?: string;
|
|
135
|
+
/** `message.compose` / `message.log`: the record the message is about, so it is logged against it. */
|
|
136
|
+
about?: DestinationAbout;
|
|
137
|
+
/** `app`: that app's view params. */
|
|
138
|
+
params?: Record<string, string>;
|
|
139
|
+
[key: string]: string | DestinationAbout | Record<string, string> | undefined;
|
|
140
|
+
}
|
|
141
|
+
export interface OpenResult {
|
|
142
|
+
ok: boolean;
|
|
143
|
+
/** `no-host` (not inside Studio) · `unknown` · `not-here` (its app isn't on) · `missing-param` · `preview`. */
|
|
144
|
+
reason?: string;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The destinations this host can open here: `['contact', 'message.compose', 'settings.domain', …]`.
|
|
148
|
+
* Leaves out a screen whose app isn't on in this collection. `[]` with no host (the admin page opened
|
|
149
|
+
* on its own), after a short wait.
|
|
150
|
+
*/
|
|
151
|
+
export declare function available(): Promise<string[]>;
|
|
152
|
+
/**
|
|
153
|
+
* Whether `open(name)` will open something here. Ask before showing a button: false when the screen's
|
|
154
|
+
* app isn't on (Messages not switched on) or there is no host. Then hide the button, or say what to
|
|
155
|
+
* switch on. Build your own only when the platform has nothing.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* const canMessage = await SL.adminViews.canOpen('message.compose')
|
|
159
|
+
*/
|
|
160
|
+
export declare function canOpen(name: Destination): Promise<boolean>;
|
|
161
|
+
/**
|
|
162
|
+
* Open one of the platform's screens by name: a contact, the Messages composer, a person's messages, a
|
|
163
|
+
* template, a product, a settings page. The host (Studio) decides which app or page that is today, so
|
|
164
|
+
* the app never hard-codes another app's address or builds its own copy. Resolves with whether it
|
|
165
|
+
* opened (`{ ok: false, reason: 'no-host' }` outside Studio).
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* // Message this parent, tied to their booking (it is logged against the booking and links back)
|
|
169
|
+
* SL.adminViews.open('message.compose', {
|
|
170
|
+
* contactId,
|
|
171
|
+
* about: { type: 'booking', id: bookingId, view: 'booking', params: { bookingId }, label: 'Sat 3pm' },
|
|
172
|
+
* })
|
|
173
|
+
* SL.adminViews.open('contact', { contactId })
|
|
174
|
+
* SL.adminViews.open('settings.domain')
|
|
175
|
+
*/
|
|
176
|
+
export declare function open(to: Destination, params?: OpenParams): Promise<OpenResult>;
|
|
100
177
|
/**
|
|
101
178
|
* Ask an embedded app to open a screen. Post this only once the app has said it follows navigate
|
|
102
179
|
* (`smartlinks:navigable`); otherwise reload the frame at the new path as before.
|
|
103
180
|
*/
|
|
104
181
|
export declare function postNavigate(target: Window | null | undefined, req: NavigateRequest, targetOrigin?: string): void;
|
|
182
|
+
/** Tell an embedded app which destinations it can open here (on load, on request, and when it changes). */
|
|
183
|
+
export declare function postDestinations(target: Window | null | undefined, availableNames: string[], targetOrigin?: string): void;
|
|
184
|
+
/** Answer an app's `smartlinks:open`. */
|
|
185
|
+
export declare function postOpenResult(target: Window | null | undefined, result: {
|
|
186
|
+
id: string;
|
|
187
|
+
to: string;
|
|
188
|
+
ok: boolean;
|
|
189
|
+
reason?: string;
|
|
190
|
+
}, targetOrigin?: string): void;
|
package/dist/adminViews.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
// host → app { type: 'smartlinks:navigate', view?, path?, params?, highlight? } open a screen, no reload
|
|
5
5
|
// app → host 'smartlinks:navigable' (the app follows navigate) 'smartlinks:navigate-result'
|
|
6
6
|
// app → host 'smartlinks:open-app' { appId, view?, params?, path? } open ANOTHER app at a screen
|
|
7
|
+
// app → host 'smartlinks:open' { id, to, params?, about? } open a platform screen by NAME
|
|
8
|
+
// ('contact', 'message.compose', 'settings.domain'); the host picks the app or page
|
|
7
9
|
// plus `chrome=none`: the host carries the app's menu itself, so the app hides its own.
|
|
8
10
|
// One list drives the app's own side menu, Studio's workspace menu and the assistant. See
|
|
9
11
|
// docs/admin-views.md.
|
|
@@ -256,6 +258,161 @@ export function openApp(req) {
|
|
|
256
258
|
return;
|
|
257
259
|
postParent('smartlinks:open-app', Object.assign(Object.assign(Object.assign({ appId: req.appId }, (req.view ? { view: req.view } : {})), (req.params ? { params: req.params } : {})), (req.path ? { path: req.path } : {})));
|
|
258
260
|
}
|
|
261
|
+
/** The platform's screens any admin screen can open by name. */
|
|
262
|
+
export const DESTINATIONS = [
|
|
263
|
+
// People
|
|
264
|
+
{ name: 'contacts', required: [], description: 'The contacts list in Customers.' },
|
|
265
|
+
{ name: 'contact', required: ['contactId'], description: 'One contact in Customers.' },
|
|
266
|
+
{ name: 'contact.messages', required: ['contactId'], description: "A person's messages: the Message log for them." },
|
|
267
|
+
{ name: 'conversation', required: ['conversationId'], description: 'One conversation in Messages.' },
|
|
268
|
+
{ name: 'segment', required: ['segmentId'], description: 'One segment in Customers.' },
|
|
269
|
+
// Messages
|
|
270
|
+
{ name: 'message.compose', required: [], optional: ['contactId', 'about'], description: 'The Messages composer: write to one person (or choose who).' },
|
|
271
|
+
{ name: 'message.log', required: [], optional: ['contactId', 'about'], description: 'The Message log, filtered by person or by what the messages were about.' },
|
|
272
|
+
{ name: 'campaign.new', required: [], optional: ['segmentId'], description: 'A new campaign: one message to many people, with opt-in and unsubscribe.' },
|
|
273
|
+
{ name: 'campaign', required: ['campaignId'], description: 'One campaign in Messages.' },
|
|
274
|
+
{ name: 'templates', required: [], description: 'The email and message templates.' },
|
|
275
|
+
{ name: 'template', required: ['templateId'], description: 'One template, open in the template editor.' },
|
|
276
|
+
// Catalogue and records
|
|
277
|
+
{ name: 'product', required: ['productId'], description: 'One product in Items.' },
|
|
278
|
+
{ name: 'proof', required: ['productId', 'proofId'], description: 'One item (proof) of a product.' },
|
|
279
|
+
{ name: 'interaction.type', required: ['interactionId'], description: 'One interaction type in Customers.' },
|
|
280
|
+
// Settings
|
|
281
|
+
{ name: 'settings', required: [], description: 'The business settings in Studio.' },
|
|
282
|
+
{ name: 'settings.address', required: [], optional: ['appId'], description: "The business's address: its name, front page, app pages (appId: point at that app's page) and links domain." },
|
|
283
|
+
{ name: 'settings.domain', required: [], description: 'The links domain (QR codes, GS1 Digital Links), on the Your address page.' },
|
|
284
|
+
{ name: 'settings.languages', required: [], description: 'The languages customers see.' },
|
|
285
|
+
{ name: 'settings.translations', required: [], description: 'Everything translated for customers.' },
|
|
286
|
+
{ name: 'settings.email', required: [], description: 'Email settings: the sending address and its look.' },
|
|
287
|
+
{ name: 'settings.team', required: [], description: 'The people who run the business in Studio.' },
|
|
288
|
+
{ name: 'settings.userGroups', required: [], description: 'User groups.' },
|
|
289
|
+
{ name: 'settings.setupLists', required: [], optional: ['appId'], description: "Set-up lists (an app's lists the business keeps)." },
|
|
290
|
+
{ name: 'settings.portal', required: [], description: 'The Portal: what people see when they scan.' },
|
|
291
|
+
{ name: 'settings.hub', required: [], description: 'The Hub: the ready-made site.' },
|
|
292
|
+
{ name: 'settings.signIn', required: [], description: 'Customer sign-in.' },
|
|
293
|
+
{ name: 'media', required: [], description: 'Images and files (assets).' },
|
|
294
|
+
// Anything else
|
|
295
|
+
{ name: 'app', required: ['appId'], optional: ['view', 'params'], description: "Another app at one of its screens (as `openApp`)." },
|
|
296
|
+
];
|
|
297
|
+
const ANSWER_MS = 1500;
|
|
298
|
+
let available_ = null;
|
|
299
|
+
let listening = false;
|
|
300
|
+
const openWaiters = new Map();
|
|
301
|
+
const listWaiters = new Set();
|
|
302
|
+
function cleanAbout(a) {
|
|
303
|
+
if (!a || typeof a !== 'object')
|
|
304
|
+
return undefined;
|
|
305
|
+
const o = a;
|
|
306
|
+
if (typeof o.type !== 'string' || typeof o.id !== 'string' || !o.type || !o.id)
|
|
307
|
+
return undefined;
|
|
308
|
+
const out = { type: o.type, id: o.id };
|
|
309
|
+
if (typeof o.appId === 'string')
|
|
310
|
+
out.appId = o.appId;
|
|
311
|
+
if (typeof o.view === 'string')
|
|
312
|
+
out.view = o.view;
|
|
313
|
+
if (typeof o.label === 'string')
|
|
314
|
+
out.label = o.label;
|
|
315
|
+
if (o.params && typeof o.params === 'object')
|
|
316
|
+
out.params = stringsOnly(o.params);
|
|
317
|
+
return out;
|
|
318
|
+
}
|
|
319
|
+
function stringsOnly(o) {
|
|
320
|
+
const out = {};
|
|
321
|
+
if (o && typeof o === 'object')
|
|
322
|
+
for (const [k, v] of Object.entries(o))
|
|
323
|
+
if (typeof v === 'string' && v)
|
|
324
|
+
out[k] = v;
|
|
325
|
+
return out;
|
|
326
|
+
}
|
|
327
|
+
function listen() {
|
|
328
|
+
if (listening || typeof window === 'undefined' || !inIframe())
|
|
329
|
+
return;
|
|
330
|
+
listening = true;
|
|
331
|
+
window.addEventListener('message', (e) => {
|
|
332
|
+
if (e.source !== window.parent)
|
|
333
|
+
return;
|
|
334
|
+
const d = e.data;
|
|
335
|
+
if (!d || typeof d !== 'object')
|
|
336
|
+
return;
|
|
337
|
+
if (d.type === 'smartlinks:destinations' && Array.isArray(d.available)) {
|
|
338
|
+
available_ = d.available.filter((n) => typeof n === 'string');
|
|
339
|
+
for (const w of listWaiters)
|
|
340
|
+
w(available_);
|
|
341
|
+
listWaiters.clear();
|
|
342
|
+
}
|
|
343
|
+
else if (d.type === 'smartlinks:open-result' && typeof d.id === 'string') {
|
|
344
|
+
const w = openWaiters.get(d.id);
|
|
345
|
+
if (w) {
|
|
346
|
+
openWaiters.delete(d.id);
|
|
347
|
+
w(Object.assign({ ok: !!d.ok }, (typeof d.reason === 'string' ? { reason: d.reason } : {})));
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* The destinations this host can open here: `['contact', 'message.compose', 'settings.domain', …]`.
|
|
354
|
+
* Leaves out a screen whose app isn't on in this collection. `[]` with no host (the admin page opened
|
|
355
|
+
* on its own), after a short wait.
|
|
356
|
+
*/
|
|
357
|
+
export function available() {
|
|
358
|
+
if (typeof window === 'undefined' || !inIframe())
|
|
359
|
+
return Promise.resolve([]);
|
|
360
|
+
listen();
|
|
361
|
+
if (available_)
|
|
362
|
+
return Promise.resolve(available_);
|
|
363
|
+
return new Promise((resolve) => {
|
|
364
|
+
const done = (list) => { clearTimeout(timer); resolve(list); };
|
|
365
|
+
const timer = setTimeout(() => { listWaiters.delete(done); resolve([]); }, ANSWER_MS);
|
|
366
|
+
listWaiters.add(done);
|
|
367
|
+
postParent('smartlinks:destinations-request', {});
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Whether `open(name)` will open something here. Ask before showing a button: false when the screen's
|
|
372
|
+
* app isn't on (Messages not switched on) or there is no host. Then hide the button, or say what to
|
|
373
|
+
* switch on. Build your own only when the platform has nothing.
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* const canMessage = await SL.adminViews.canOpen('message.compose')
|
|
377
|
+
*/
|
|
378
|
+
export async function canOpen(name) {
|
|
379
|
+
return (await available()).includes(name);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Open one of the platform's screens by name: a contact, the Messages composer, a person's messages, a
|
|
383
|
+
* template, a product, a settings page. The host (Studio) decides which app or page that is today, so
|
|
384
|
+
* the app never hard-codes another app's address or builds its own copy. Resolves with whether it
|
|
385
|
+
* opened (`{ ok: false, reason: 'no-host' }` outside Studio).
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* // Message this parent, tied to their booking (it is logged against the booking and links back)
|
|
389
|
+
* SL.adminViews.open('message.compose', {
|
|
390
|
+
* contactId,
|
|
391
|
+
* about: { type: 'booking', id: bookingId, view: 'booking', params: { bookingId }, label: 'Sat 3pm' },
|
|
392
|
+
* })
|
|
393
|
+
* SL.adminViews.open('contact', { contactId })
|
|
394
|
+
* SL.adminViews.open('settings.domain')
|
|
395
|
+
*/
|
|
396
|
+
export function open(to, params = {}) {
|
|
397
|
+
if (typeof to !== 'string' || !to)
|
|
398
|
+
return Promise.resolve({ ok: false, reason: 'unknown' });
|
|
399
|
+
if (typeof window === 'undefined' || !inIframe())
|
|
400
|
+
return Promise.resolve({ ok: false, reason: 'no-host' });
|
|
401
|
+
listen();
|
|
402
|
+
const id = `o_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
|
403
|
+
const flat = {};
|
|
404
|
+
for (const [k, v] of Object.entries(params || {}))
|
|
405
|
+
if (k !== 'about' && k !== 'params' && typeof v === 'string' && v)
|
|
406
|
+
flat[k] = v;
|
|
407
|
+
const about = cleanAbout(params === null || params === void 0 ? void 0 : params.about);
|
|
408
|
+
const appParams = (params === null || params === void 0 ? void 0 : params.params) ? stringsOnly(params.params) : undefined;
|
|
409
|
+
return new Promise((resolve) => {
|
|
410
|
+
const timer = setTimeout(() => { openWaiters.delete(id); resolve({ ok: false, reason: 'no-host' }); }, ANSWER_MS);
|
|
411
|
+
openWaiters.set(id, (r) => { clearTimeout(timer); resolve(r); });
|
|
412
|
+
postParent('smartlinks:open', Object.assign(Object.assign({ id,
|
|
413
|
+
to, params: flat }, (about ? { about } : {})), (appParams ? { appParams } : {})));
|
|
414
|
+
});
|
|
415
|
+
}
|
|
259
416
|
// -----------------------------------------------------------------------------
|
|
260
417
|
// Host side
|
|
261
418
|
// -----------------------------------------------------------------------------
|
|
@@ -273,3 +430,25 @@ export function postNavigate(target, req, targetOrigin = '*') {
|
|
|
273
430
|
/* ignore */
|
|
274
431
|
}
|
|
275
432
|
}
|
|
433
|
+
/** Tell an embedded app which destinations it can open here (on load, on request, and when it changes). */
|
|
434
|
+
export function postDestinations(target, availableNames, targetOrigin = '*') {
|
|
435
|
+
if (!target)
|
|
436
|
+
return;
|
|
437
|
+
try {
|
|
438
|
+
target.postMessage({ type: 'smartlinks:destinations', available: availableNames }, targetOrigin);
|
|
439
|
+
}
|
|
440
|
+
catch (_a) {
|
|
441
|
+
/* ignore */
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
/** Answer an app's `smartlinks:open`. */
|
|
445
|
+
export function postOpenResult(target, result, targetOrigin = '*') {
|
|
446
|
+
if (!target)
|
|
447
|
+
return;
|
|
448
|
+
try {
|
|
449
|
+
target.postMessage(Object.assign({ type: 'smartlinks:open-result' }, result), targetOrigin);
|
|
450
|
+
}
|
|
451
|
+
catch (_a) {
|
|
452
|
+
/* ignore */
|
|
453
|
+
}
|
|
454
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { AddressFront, AddressNameAvailability, AddressResponse, AppPageLink } from "../types/address.js";
|
|
2
|
+
/**
|
|
3
|
+
* The business's address in one place (admin): its name, what its front page shows, and its apps' pages
|
|
4
|
+
* under `/_apps/<name>/` (prove docs/design/business-address.md, app-page-addresses.md). Changes reach
|
|
5
|
+
* visitors within about a minute.
|
|
6
|
+
*/
|
|
7
|
+
export declare namespace address {
|
|
8
|
+
/**
|
|
9
|
+
* Where an app's public page is, on the business's own address. Public: use it from the app's admin
|
|
10
|
+
* ("Open the game") and from share buttons, instead of building the CDN address by hand. Add the app's
|
|
11
|
+
* own route to it: `${link.url}#/play`. The page carries no collectionId or appId: the address says it.
|
|
12
|
+
* Resolves null when the app has no page on that collection (not installed, or a connector).
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const link = await SL.address.page(collectionId, appId)
|
|
16
|
+
* window.open(`${link?.url ?? fallback}#/play`, '_blank')
|
|
17
|
+
*/
|
|
18
|
+
function page(collectionId: string, appId: string): Promise<AppPageLink | null>;
|
|
19
|
+
/** Everything about the business's address: name, own domain, front page, websites that can take it, app pages. */
|
|
20
|
+
function get(collectionId: string): Promise<AddressResponse>;
|
|
21
|
+
/** Is this name free? (lower-case letters, numbers and hyphens) */
|
|
22
|
+
function checkName(collectionId: string, name: string): Promise<AddressNameAvailability>;
|
|
23
|
+
/**
|
|
24
|
+
* Choose (or change) the business's name: `<name>.smartlinks.host`. The previous name is released.
|
|
25
|
+
* @throws ErrorResponse 400 BAD_NAME, 409 NAME_TAKEN
|
|
26
|
+
*/
|
|
27
|
+
function setName(collectionId: string, name: string): Promise<{
|
|
28
|
+
name: string;
|
|
29
|
+
host: string;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* What the front page shows. Applies to the business's name, its automatic address and its own domain
|
|
33
|
+
* together. A website must be installed and live; a redirect must be https and not one of its own addresses.
|
|
34
|
+
* @throws ErrorResponse 400 BAD_FRONT | BAD_URL | REDIRECT_LOOP, 404 APP_NOT_INSTALLED, 409 PRODUCTION_ONLY | NOT_A_WEBSITE
|
|
35
|
+
*/
|
|
36
|
+
function setFront(collectionId: string, front: AddressFront): Promise<{
|
|
37
|
+
front: AddressFront;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Rename an app's page (old names keep redirecting) and/or show it on the holding page.
|
|
41
|
+
* @throws ErrorResponse 400 PAGE_NAME_INVALID, 404 APP_NOT_INSTALLED, 409 PAGE_NAME_TAKEN
|
|
42
|
+
*/
|
|
43
|
+
function setPage(collectionId: string, appId: string, change: {
|
|
44
|
+
name?: string;
|
|
45
|
+
listed?: boolean;
|
|
46
|
+
}): Promise<{
|
|
47
|
+
name?: string;
|
|
48
|
+
listed?: boolean;
|
|
49
|
+
}>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { request, post } from "../http.js";
|
|
2
|
+
/**
|
|
3
|
+
* The business's address in one place (admin): its name, what its front page shows, and its apps' pages
|
|
4
|
+
* under `/_apps/<name>/` (prove docs/design/business-address.md, app-page-addresses.md). Changes reach
|
|
5
|
+
* visitors within about a minute.
|
|
6
|
+
*/
|
|
7
|
+
export var address;
|
|
8
|
+
(function (address) {
|
|
9
|
+
const base = (collectionId) => `/admin/collection/${encodeURIComponent(collectionId)}/address`;
|
|
10
|
+
/**
|
|
11
|
+
* Where an app's public page is, on the business's own address. Public: use it from the app's admin
|
|
12
|
+
* ("Open the game") and from share buttons, instead of building the CDN address by hand. Add the app's
|
|
13
|
+
* own route to it: `${link.url}#/play`. The page carries no collectionId or appId: the address says it.
|
|
14
|
+
* Resolves null when the app has no page on that collection (not installed, or a connector).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const link = await SL.address.page(collectionId, appId)
|
|
18
|
+
* window.open(`${link?.url ?? fallback}#/play`, '_blank')
|
|
19
|
+
*/
|
|
20
|
+
async function page(collectionId, appId) {
|
|
21
|
+
try {
|
|
22
|
+
return await request(`/public/collection/${encodeURIComponent(collectionId)}/app/${encodeURIComponent(appId)}/page`);
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
if ((e === null || e === void 0 ? void 0 : e.statusCode) === 404)
|
|
26
|
+
return null;
|
|
27
|
+
throw e;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
address.page = page;
|
|
31
|
+
/** Everything about the business's address: name, own domain, front page, websites that can take it, app pages. */
|
|
32
|
+
async function get(collectionId) {
|
|
33
|
+
return request(base(collectionId));
|
|
34
|
+
}
|
|
35
|
+
address.get = get;
|
|
36
|
+
/** Is this name free? (lower-case letters, numbers and hyphens) */
|
|
37
|
+
async function checkName(collectionId, name) {
|
|
38
|
+
return request(`${base(collectionId)}/available?${new URLSearchParams({ name })}`);
|
|
39
|
+
}
|
|
40
|
+
address.checkName = checkName;
|
|
41
|
+
/**
|
|
42
|
+
* Choose (or change) the business's name: `<name>.smartlinks.host`. The previous name is released.
|
|
43
|
+
* @throws ErrorResponse 400 BAD_NAME, 409 NAME_TAKEN
|
|
44
|
+
*/
|
|
45
|
+
async function setName(collectionId, name) {
|
|
46
|
+
return post(`${base(collectionId)}/name`, { name });
|
|
47
|
+
}
|
|
48
|
+
address.setName = setName;
|
|
49
|
+
/**
|
|
50
|
+
* What the front page shows. Applies to the business's name, its automatic address and its own domain
|
|
51
|
+
* together. A website must be installed and live; a redirect must be https and not one of its own addresses.
|
|
52
|
+
* @throws ErrorResponse 400 BAD_FRONT | BAD_URL | REDIRECT_LOOP, 404 APP_NOT_INSTALLED, 409 PRODUCTION_ONLY | NOT_A_WEBSITE
|
|
53
|
+
*/
|
|
54
|
+
async function setFront(collectionId, front) {
|
|
55
|
+
return post(`${base(collectionId)}/front`, front);
|
|
56
|
+
}
|
|
57
|
+
address.setFront = setFront;
|
|
58
|
+
/**
|
|
59
|
+
* Rename an app's page (old names keep redirecting) and/or show it on the holding page.
|
|
60
|
+
* @throws ErrorResponse 400 PAGE_NAME_INVALID, 404 APP_NOT_INSTALLED, 409 PAGE_NAME_TAKEN
|
|
61
|
+
*/
|
|
62
|
+
async function setPage(collectionId, appId, change) {
|
|
63
|
+
return post(`${base(collectionId)}/pages/${encodeURIComponent(appId)}`, change);
|
|
64
|
+
}
|
|
65
|
+
address.setPage = setPage;
|
|
66
|
+
})(address || (address = {}));
|
package/dist/api/index.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export { functions } from "./functions.js";
|
|
|
39
39
|
export { location } from "./location.js";
|
|
40
40
|
export * as realtime from "./realtime.js";
|
|
41
41
|
export { adminCards } from "./adminCards.js";
|
|
42
|
+
export { address } from "./address.js";
|
|
42
43
|
export { tags } from "./tags.js";
|
|
43
44
|
export { order } from "./order.js";
|
|
44
45
|
export { app } from "./appObjects.js";
|
package/dist/api/index.js
CHANGED
|
@@ -42,6 +42,7 @@ export { location } from "./location.js";
|
|
|
42
42
|
import * as realtime_1 from "./realtime.js";
|
|
43
43
|
export { realtime_1 as realtime };
|
|
44
44
|
export { adminCards } from "./adminCards.js";
|
|
45
|
+
export { address } from "./address.js";
|
|
45
46
|
export { tags } from "./tags.js";
|
|
46
47
|
export { order } from "./order.js";
|
|
47
48
|
export { app } from "./appObjects.js";
|
|
@@ -54,8 +54,11 @@ export declare namespace interactions {
|
|
|
54
54
|
* @example
|
|
55
55
|
* const vote = await SL.interactions.ensureType(collectionId, {
|
|
56
56
|
* appId: 'my-app', key: 'vote', permissions: { allowPublicSubmit: true, uniquePerUser: true },
|
|
57
|
+
* display: { title: 'Cast a vote', description: 'Someone voted in the poll' },
|
|
57
58
|
* })
|
|
58
59
|
* // vote.id → '52bab6fa-…' — store it in config; never hardcode 'vote' as an interactionId
|
|
60
|
+
* // Always give display.title: it's the name staff see in the CRM, on activity and when choosing
|
|
61
|
+
* // "everyone who voted" for a segment. (Without one the platform names it from the key.)
|
|
59
62
|
*/
|
|
60
63
|
function ensureType(collectionId: string, input: EnsureInteractionTypeInput): Promise<InteractionTypeRecord>;
|
|
61
64
|
function get(collectionId: string, id: string): Promise<InteractionTypeRecord>;
|
package/dist/api/interactions.js
CHANGED
|
@@ -111,8 +111,11 @@ export var interactions;
|
|
|
111
111
|
* @example
|
|
112
112
|
* const vote = await SL.interactions.ensureType(collectionId, {
|
|
113
113
|
* appId: 'my-app', key: 'vote', permissions: { allowPublicSubmit: true, uniquePerUser: true },
|
|
114
|
+
* display: { title: 'Cast a vote', description: 'Someone voted in the poll' },
|
|
114
115
|
* })
|
|
115
116
|
* // vote.id → '52bab6fa-…' — store it in config; never hardcode 'vote' as an interactionId
|
|
117
|
+
* // Always give display.title: it's the name staff see in the CRM, on activity and when choosing
|
|
118
|
+
* // "everyone who voted" for a segment. (Without one the platform names it from the key.)
|
|
116
119
|
*/
|
|
117
120
|
async function ensureType(collectionId, input) {
|
|
118
121
|
const { appId, key, permissions, display, data } = input;
|
package/dist/context.d.ts
CHANGED
|
@@ -15,6 +15,11 @@ export interface SmartLinksContext {
|
|
|
15
15
|
* (`appChannel: 'preview'`) on this collection. Set by Forge; never present elsewhere.
|
|
16
16
|
*/
|
|
17
17
|
slPreview?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Where the app's page lives on the business's address when served as an app page
|
|
20
|
+
* (`/_apps/<name>`): build share links to the app from it. Absent elsewhere.
|
|
21
|
+
*/
|
|
22
|
+
basePath?: string;
|
|
18
23
|
/** Any other declared view params (e.g. pageId, voteId, orientation, tvMode). */
|
|
19
24
|
[key: string]: string | undefined;
|
|
20
25
|
}
|
package/dist/context.js
CHANGED
|
@@ -42,7 +42,7 @@ export function readContext(overrides) {
|
|
|
42
42
|
}
|
|
43
43
|
// 4. the SITE the page is served as (lowest precedence). When an app runs as a public website at
|
|
44
44
|
// its own hostname (an "app site"), the host page injects window.__SMARTLINKS_SITE__ =
|
|
45
|
-
// { collectionId, appId, channel, host } — so a site knows its collection with no URL params.
|
|
45
|
+
// { collectionId, appId, channel, host[, basePath] } — so a site knows its collection with no URL params.
|
|
46
46
|
const site = globalThis.__SMARTLINKS_SITE__;
|
|
47
47
|
if (site && typeof site === 'object') {
|
|
48
48
|
const fill = (key, value) => { if (out[key] == null && typeof value === 'string' && value)
|
|
@@ -55,6 +55,9 @@ export function readContext(overrides) {
|
|
|
55
55
|
fill('appChannelApp', site.appId);
|
|
56
56
|
}
|
|
57
57
|
fill('slPreview', site.previewPass);
|
|
58
|
+
// Served as an app page on the business's address (/_apps/<name>): where the page lives.
|
|
59
|
+
if (typeof site.basePath === 'string' && /^\/_apps\/[a-z0-9-]+$/.test(site.basePath))
|
|
60
|
+
fill('basePath', site.basePath);
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
catch (_a) {
|