@proveanything/smartlinks 2.1.31 → 2.1.33

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.
@@ -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.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;
@@ -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,160 @@ 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.domain', required: [], description: 'The domain settings.' },
283
+ { name: 'settings.languages', required: [], description: 'The languages customers see.' },
284
+ { name: 'settings.translations', required: [], description: 'Everything translated for customers.' },
285
+ { name: 'settings.email', required: [], description: 'Email settings: the sending address and its look.' },
286
+ { name: 'settings.team', required: [], description: 'The people who run the business in Studio.' },
287
+ { name: 'settings.userGroups', required: [], description: 'User groups.' },
288
+ { name: 'settings.setupLists', required: [], optional: ['appId'], description: "Set-up lists (an app's lists the business keeps)." },
289
+ { name: 'settings.portal', required: [], description: 'The Portal: what people see when they scan.' },
290
+ { name: 'settings.hub', required: [], description: 'The Hub: the ready-made site.' },
291
+ { name: 'settings.signIn', required: [], description: 'Customer sign-in.' },
292
+ { name: 'media', required: [], description: 'Images and files (assets).' },
293
+ // Anything else
294
+ { name: 'app', required: ['appId'], optional: ['view', 'params'], description: "Another app at one of its screens (as `openApp`)." },
295
+ ];
296
+ const ANSWER_MS = 1500;
297
+ let available_ = null;
298
+ let listening = false;
299
+ const openWaiters = new Map();
300
+ const listWaiters = new Set();
301
+ function cleanAbout(a) {
302
+ if (!a || typeof a !== 'object')
303
+ return undefined;
304
+ const o = a;
305
+ if (typeof o.type !== 'string' || typeof o.id !== 'string' || !o.type || !o.id)
306
+ return undefined;
307
+ const out = { type: o.type, id: o.id };
308
+ if (typeof o.appId === 'string')
309
+ out.appId = o.appId;
310
+ if (typeof o.view === 'string')
311
+ out.view = o.view;
312
+ if (typeof o.label === 'string')
313
+ out.label = o.label;
314
+ if (o.params && typeof o.params === 'object')
315
+ out.params = stringsOnly(o.params);
316
+ return out;
317
+ }
318
+ function stringsOnly(o) {
319
+ const out = {};
320
+ if (o && typeof o === 'object')
321
+ for (const [k, v] of Object.entries(o))
322
+ if (typeof v === 'string' && v)
323
+ out[k] = v;
324
+ return out;
325
+ }
326
+ function listen() {
327
+ if (listening || typeof window === 'undefined' || !inIframe())
328
+ return;
329
+ listening = true;
330
+ window.addEventListener('message', (e) => {
331
+ if (e.source !== window.parent)
332
+ return;
333
+ const d = e.data;
334
+ if (!d || typeof d !== 'object')
335
+ return;
336
+ if (d.type === 'smartlinks:destinations' && Array.isArray(d.available)) {
337
+ available_ = d.available.filter((n) => typeof n === 'string');
338
+ for (const w of listWaiters)
339
+ w(available_);
340
+ listWaiters.clear();
341
+ }
342
+ else if (d.type === 'smartlinks:open-result' && typeof d.id === 'string') {
343
+ const w = openWaiters.get(d.id);
344
+ if (w) {
345
+ openWaiters.delete(d.id);
346
+ w(Object.assign({ ok: !!d.ok }, (typeof d.reason === 'string' ? { reason: d.reason } : {})));
347
+ }
348
+ }
349
+ });
350
+ }
351
+ /**
352
+ * The destinations this host can open here: `['contact', 'message.compose', 'settings.domain', …]`.
353
+ * Leaves out a screen whose app isn't on in this collection. `[]` with no host (the admin page opened
354
+ * on its own), after a short wait.
355
+ */
356
+ export function available() {
357
+ if (typeof window === 'undefined' || !inIframe())
358
+ return Promise.resolve([]);
359
+ listen();
360
+ if (available_)
361
+ return Promise.resolve(available_);
362
+ return new Promise((resolve) => {
363
+ const done = (list) => { clearTimeout(timer); resolve(list); };
364
+ const timer = setTimeout(() => { listWaiters.delete(done); resolve([]); }, ANSWER_MS);
365
+ listWaiters.add(done);
366
+ postParent('smartlinks:destinations-request', {});
367
+ });
368
+ }
369
+ /**
370
+ * Whether `open(name)` will open something here. Ask before showing a button: false when the screen's
371
+ * app isn't on (Messages not switched on) or there is no host. Then hide the button, or say what to
372
+ * switch on. Build your own only when the platform has nothing.
373
+ *
374
+ * @example
375
+ * const canMessage = await SL.adminViews.canOpen('message.compose')
376
+ */
377
+ export async function canOpen(name) {
378
+ return (await available()).includes(name);
379
+ }
380
+ /**
381
+ * Open one of the platform's screens by name: a contact, the Messages composer, a person's messages, a
382
+ * template, a product, a settings page. The host (Studio) decides which app or page that is today, so
383
+ * the app never hard-codes another app's address or builds its own copy. Resolves with whether it
384
+ * opened (`{ ok: false, reason: 'no-host' }` outside Studio).
385
+ *
386
+ * @example
387
+ * // Message this parent, tied to their booking (it is logged against the booking and links back)
388
+ * SL.adminViews.open('message.compose', {
389
+ * contactId,
390
+ * about: { type: 'booking', id: bookingId, view: 'booking', params: { bookingId }, label: 'Sat 3pm' },
391
+ * })
392
+ * SL.adminViews.open('contact', { contactId })
393
+ * SL.adminViews.open('settings.domain')
394
+ */
395
+ export function open(to, params = {}) {
396
+ if (typeof to !== 'string' || !to)
397
+ return Promise.resolve({ ok: false, reason: 'unknown' });
398
+ if (typeof window === 'undefined' || !inIframe())
399
+ return Promise.resolve({ ok: false, reason: 'no-host' });
400
+ listen();
401
+ const id = `o_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
402
+ const flat = {};
403
+ for (const [k, v] of Object.entries(params || {}))
404
+ if (k !== 'about' && k !== 'params' && typeof v === 'string' && v)
405
+ flat[k] = v;
406
+ const about = cleanAbout(params === null || params === void 0 ? void 0 : params.about);
407
+ const appParams = (params === null || params === void 0 ? void 0 : params.params) ? stringsOnly(params.params) : undefined;
408
+ return new Promise((resolve) => {
409
+ const timer = setTimeout(() => { openWaiters.delete(id); resolve({ ok: false, reason: 'no-host' }); }, ANSWER_MS);
410
+ openWaiters.set(id, (r) => { clearTimeout(timer); resolve(r); });
411
+ postParent('smartlinks:open', Object.assign(Object.assign({ id,
412
+ to, params: flat }, (about ? { about } : {})), (appParams ? { appParams } : {})));
413
+ });
414
+ }
259
415
  // -----------------------------------------------------------------------------
260
416
  // Host side
261
417
  // -----------------------------------------------------------------------------
@@ -273,3 +429,25 @@ export function postNavigate(target, req, targetOrigin = '*') {
273
429
  /* ignore */
274
430
  }
275
431
  }
432
+ /** Tell an embedded app which destinations it can open here (on load, on request, and when it changes). */
433
+ export function postDestinations(target, availableNames, targetOrigin = '*') {
434
+ if (!target)
435
+ return;
436
+ try {
437
+ target.postMessage({ type: 'smartlinks:destinations', available: availableNames }, targetOrigin);
438
+ }
439
+ catch (_a) {
440
+ /* ignore */
441
+ }
442
+ }
443
+ /** Answer an app's `smartlinks:open`. */
444
+ export function postOpenResult(target, result, targetOrigin = '*') {
445
+ if (!target)
446
+ return;
447
+ try {
448
+ target.postMessage(Object.assign({ type: 'smartlinks:open-result' }, result), targetOrigin);
449
+ }
450
+ catch (_a) {
451
+ /* ignore */
452
+ }
453
+ }
@@ -0,0 +1,39 @@
1
+ import type { AddressFront, AddressNameAvailability, AddressResponse } 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
+ /** Everything about the business's address: name, own domain, front page, websites that can take it, app pages. */
9
+ function get(collectionId: string): Promise<AddressResponse>;
10
+ /** Is this name free? (lower-case letters, numbers and hyphens) */
11
+ function checkName(collectionId: string, name: string): Promise<AddressNameAvailability>;
12
+ /**
13
+ * Choose (or change) the business's name: `<name>.smartlinks.host`. The previous name is released.
14
+ * @throws ErrorResponse 400 BAD_NAME, 409 NAME_TAKEN
15
+ */
16
+ function setName(collectionId: string, name: string): Promise<{
17
+ name: string;
18
+ host: string;
19
+ }>;
20
+ /**
21
+ * What the front page shows. Applies to the business's name, its automatic address and its own domain
22
+ * together. A website must be installed and live; a redirect must be https and not one of its own addresses.
23
+ * @throws ErrorResponse 400 BAD_FRONT | BAD_URL | REDIRECT_LOOP, 404 APP_NOT_INSTALLED, 409 PRODUCTION_ONLY | NOT_A_WEBSITE
24
+ */
25
+ function setFront(collectionId: string, front: AddressFront): Promise<{
26
+ front: AddressFront;
27
+ }>;
28
+ /**
29
+ * Rename an app's page (old names keep redirecting) and/or show it on the holding page.
30
+ * @throws ErrorResponse 400 PAGE_NAME_INVALID, 404 APP_NOT_INSTALLED, 409 PAGE_NAME_TAKEN
31
+ */
32
+ function setPage(collectionId: string, appId: string, change: {
33
+ name?: string;
34
+ listed?: boolean;
35
+ }): Promise<{
36
+ name?: string;
37
+ listed?: boolean;
38
+ }>;
39
+ }
@@ -0,0 +1,45 @@
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
+ /** Everything about the business's address: name, own domain, front page, websites that can take it, app pages. */
11
+ async function get(collectionId) {
12
+ return request(base(collectionId));
13
+ }
14
+ address.get = get;
15
+ /** Is this name free? (lower-case letters, numbers and hyphens) */
16
+ async function checkName(collectionId, name) {
17
+ return request(`${base(collectionId)}/available?${new URLSearchParams({ name })}`);
18
+ }
19
+ address.checkName = checkName;
20
+ /**
21
+ * Choose (or change) the business's name: `<name>.smartlinks.host`. The previous name is released.
22
+ * @throws ErrorResponse 400 BAD_NAME, 409 NAME_TAKEN
23
+ */
24
+ async function setName(collectionId, name) {
25
+ return post(`${base(collectionId)}/name`, { name });
26
+ }
27
+ address.setName = setName;
28
+ /**
29
+ * What the front page shows. Applies to the business's name, its automatic address and its own domain
30
+ * together. A website must be installed and live; a redirect must be https and not one of its own addresses.
31
+ * @throws ErrorResponse 400 BAD_FRONT | BAD_URL | REDIRECT_LOOP, 404 APP_NOT_INSTALLED, 409 PRODUCTION_ONLY | NOT_A_WEBSITE
32
+ */
33
+ async function setFront(collectionId, front) {
34
+ return post(`${base(collectionId)}/front`, front);
35
+ }
36
+ address.setFront = setFront;
37
+ /**
38
+ * Rename an app's page (old names keep redirecting) and/or show it on the holding page.
39
+ * @throws ErrorResponse 400 PAGE_NAME_INVALID, 404 APP_NOT_INSTALLED, 409 PAGE_NAME_TAKEN
40
+ */
41
+ async function setPage(collectionId, appId, change) {
42
+ return post(`${base(collectionId)}/pages/${encodeURIComponent(appId)}`, change);
43
+ }
44
+ address.setPage = setPage;
45
+ })(address || (address = {}));
@@ -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>;
@@ -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;
@@ -1,5 +1,5 @@
1
1
  import type { TranslationActivity } from '../translationActivity.js';
2
- import type { ResolvedTranslationResponse, TranslationHashOptions, TranslationListParams, TranslationListResponse, TranslationLookupRequest, TranslationLookupResponse, TranslationRecord, TranslationResolveOptions, TranslationUpdateRequest } from '../types/translations.js';
2
+ import type { ResolvedTranslationResponse, TranslationHashOptions, TranslationListParams, TranslationListResponse, TranslationLookupRequest, TranslationLookupResponse, TranslationRecord, TranslationResolveOptions, TranslationRules, TranslationUpdateRequest } from '../types/translations.js';
3
3
  /** @internal tests only */
4
4
  export declare function _resetRevisionChecks(): void;
5
5
  export declare namespace translations {
@@ -31,6 +31,7 @@ export declare namespace translations {
31
31
  language: string;
32
32
  total: number;
33
33
  edited: number;
34
+ issues?: number;
34
35
  }>;
35
36
  }>;
36
37
  /** Admin: where translated text appears for one language (context keys), with counts. */
@@ -43,5 +44,9 @@ export declare namespace translations {
43
44
  }>;
44
45
  /** Admin: undo a person's edit with a fresh machine translation. */
45
46
  function reset(collectionId: string, translationId: string): Promise<TranslationRecord>;
47
+ /** Admin: the site's translation rules (brief, notes per language, required terms). */
48
+ function rules(collectionId: string): Promise<TranslationRules>;
49
+ /** Admin: replace the site's translation rules. They apply to new translations from now on. */
50
+ function saveRules(collectionId: string, body: Pick<TranslationRules, 'guidance' | 'languages' | 'terms'>): Promise<TranslationRules>;
46
51
  function clearLocalCache(collectionId?: string): Promise<void>;
47
52
  }
@@ -1,4 +1,4 @@
1
- import { isProxyEnabled, patch, post, request } from '../http.js';
1
+ import { isProxyEnabled, patch, post, put, request } from '../http.js';
2
2
  import { clearCachedTranslations, deriveTranslationContextKey, getCachedTranslations, getDefaultTranslationCacheTtlMs, hashTranslationText, normalizeTranslationText, setCachedTranslations, } from '../translationCache.js';
3
3
  import { trackTranslation, onActivity as onTranslationActivity, activity as translationActivity, translatingMessage as translatingLine } from '../translationActivity.js';
4
4
  function normalizeLookupRequest(body) {
@@ -305,6 +305,16 @@ export var translations;
305
305
  return post(`/admin/collection/${encodeURIComponent(collectionId)}/translations/${encodeURIComponent(translationId)}/reset`, {});
306
306
  }
307
307
  translations.reset = reset;
308
+ /** Admin: the site's translation rules (brief, notes per language, required terms). */
309
+ async function rules(collectionId) {
310
+ return request(`/admin/collection/${encodeURIComponent(collectionId)}/translations/rules`);
311
+ }
312
+ translations.rules = rules;
313
+ /** Admin: replace the site's translation rules. They apply to new translations from now on. */
314
+ async function saveRules(collectionId, body) {
315
+ return put(`/admin/collection/${encodeURIComponent(collectionId)}/translations/rules`, body);
316
+ }
317
+ translations.saveRules = saveRules;
308
318
  async function clearLocalCache(collectionId) {
309
319
  await clearCachedTranslations(collectionId);
310
320
  }
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) {