@veroxm/sdk 1.13.0 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/http.d.ts CHANGED
@@ -44,6 +44,8 @@ export interface WriteControl extends RequestControl {
44
44
  export declare function checkRetries(value: number | undefined): void;
45
45
  /** Throws a RangeError for a `timeoutMs` that isn't a positive number. */
46
46
  export declare function checkTimeout(value: number | undefined): void;
47
+ /** @internal Sets (or, with null, clears) the language of a project's error answers. */
48
+ export declare function setRequestLocale(apiBase: string, locale: string | null): void;
47
49
  /**
48
50
  * The one place an HTTP request actually goes out. Deliberately built on
49
51
  * the platform's own global `fetch`/`FormData` -- available in every
package/dist/http.js CHANGED
@@ -114,6 +114,18 @@ async function attempt(url, init, control, fetchImpl) {
114
114
  signal?.removeEventListener('abort', onAbort);
115
115
  }
116
116
  }
117
+ /** The language the API answers errors in (userMessage), per project address: VeroXMApp's `locale`. */
118
+ const LOCALES = new Map();
119
+ /** @internal Sets (or, with null, clears) the language of a project's error answers. */
120
+ export function setRequestLocale(apiBase, locale) {
121
+ const base = apiBase.endsWith('/') ? apiBase : `${apiBase}/`;
122
+ if (locale === null || locale === '')
123
+ LOCALES.delete(base);
124
+ else if (!/^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8}){0,3}$/.test(locale))
125
+ throw new RangeError('locale is a language tag, such as "ar" or "en-GB"');
126
+ else
127
+ LOCALES.set(base, locale);
128
+ }
117
129
  /**
118
130
  * The one place an HTTP request actually goes out. Deliberately built on
119
131
  * the platform's own global `fetch`/`FormData` -- available in every
@@ -127,6 +139,7 @@ export async function rawRequest(apiBase, opts, internal = {}) {
127
139
  checkTimeout(opts.timeoutMs);
128
140
  checkRetries(opts.retries);
129
141
  const base = apiBase.endsWith('/') ? apiBase : `${apiBase}/`;
142
+ const locale = LOCALES.get(base);
130
143
  const url = new URL(opts.path.replace(/^\//, ''), base);
131
144
  if (opts.query) {
132
145
  for (const [key, value] of Object.entries(opts.query)) {
@@ -137,7 +150,11 @@ export async function rawRequest(apiBase, opts, internal = {}) {
137
150
  if (opts.idempotencyKey !== undefined && !/^[\x21-\x7e]{1,255}$/.test(opts.idempotencyKey)) {
138
151
  throw new RangeError('idempotencyKey must be 1 to 255 visible characters (no spaces)');
139
152
  }
140
- const headers = { ...opts.headers, ...(opts.idempotencyKey !== undefined ? { 'Idempotency-Key': opts.idempotencyKey } : {}) };
153
+ const headers = {
154
+ ...(locale ? { 'X-VeroXM-Locale': locale } : {}),
155
+ ...opts.headers,
156
+ ...(opts.idempotencyKey !== undefined ? { 'Idempotency-Key': opts.idempotencyKey } : {}),
157
+ };
141
158
  let body;
142
159
  if (opts.form) {
143
160
  body = opts.form;
package/dist/index.d.ts CHANGED
@@ -19,6 +19,10 @@ export { ProcessesResource } from './processes.js';
19
19
  export type { ProcessRun, ProcessRunDetail, ProcessRunListOptions } from './processes.js';
20
20
  export { FormsResource } from './forms.js';
21
21
  export type { FormDetail, FormResponse, FormResponseListOptions, FormResponsePage, FormSummary } from './forms.js';
22
+ export { FilesResource, uploadWithGrant } from './files.js';
23
+ export type { FileFolderRule, FileGrant, FileGrantOptions, StoredFile, StoredFileEvent, StoredFileEventOptions, StoredFileEventPage, StoredFileLink, StoredFileListOptions, StoredFilePage } from './files.js';
24
+ export { PushResource } from './push.js';
25
+ export type { PushDevice, PushDeviceRegistered, PushMessageInput, PushStatus } from './push.js';
22
26
  export { TranslationsResource, fetchTranslations, fetchTranslationResource, fetchTranslationLocales, createTranslator, VeroxmI18nextBackend, } from './translations.js';
23
27
  export type { FetchTranslationsOptions, TranslationBundle, TranslationBundleOptions, TranslationLocale, TranslationLocales, TranslationTexts, TranslationValues, Translator, VeroxmI18nextBackendOptions, } from './translations.js';
24
28
  export { embedForm, embedFormsFromPage } from './embed.js';
package/dist/index.js CHANGED
@@ -10,6 +10,10 @@ export { FunctionsResource } from './functions.js';
10
10
  export { TasksResource } from './tasks.js';
11
11
  export { ProcessesResource } from './processes.js';
12
12
  export { FormsResource } from './forms.js';
13
+ // Private files: a server key's, and one-time upload links a browser uses.
14
+ export { FilesResource, uploadWithGrant } from './files.js';
15
+ // Push notifications: register a device, or send from a server.
16
+ export { PushResource } from './push.js';
13
17
  // App translations: a locale's bundle in one request, and a t() for its texts.
14
18
  export { TranslationsResource, fetchTranslations, fetchTranslationResource, fetchTranslationLocales, createTranslator, VeroxmI18nextBackend, } from './translations.js';
15
19
  // Showing forms in a page: inline, popup, full page or toast.
package/dist/push.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ import type { VeroXMApp } from './client.js';
2
+ import type { Schemas } from './schemas.js';
3
+ /** A device an app registers: its Firebase token and platform, and optionally its language, topics and marketing choice. */
4
+ export type PushDevice = Schemas['PushDevice'];
5
+ export type PushDeviceRegistered = Schemas['PushDeviceRegistered'];
6
+ /** A push: who it's for (`to`), title and body (text, or by language), data, link and the rest. */
7
+ export type PushMessageInput = Schemas['PushMessageInput'];
8
+ export type PushStatus = Schemas['PushStatus'];
9
+ /**
10
+ * Push notifications through the project's own Firebase project (Settings > Push notifications). An app registers its
11
+ * device (with any key of the project, or signed in: the device is then the person's); a server key with "Send push
12
+ * notifications" sends. Get the device's token from the Firebase SDK in the app (`getToken()`).
13
+ */
14
+ export declare class PushResource {
15
+ private readonly app;
16
+ constructor(app: VeroXMApp);
17
+ /** Call on every start of the app, and when the token, language, topics or marketing choice change. */
18
+ register(device: PushDevice): Promise<PushDeviceRegistered>;
19
+ /** When the person signs out or turns pushes off. */
20
+ unregister(token: string): Promise<{
21
+ removed: boolean;
22
+ }>;
23
+ /** Queues a push (server keys with "Send push notifications"); `idempotencyKey` queues the same push once. */
24
+ send(message: PushMessageInput, options?: {
25
+ idempotencyKey?: string;
26
+ }): Promise<{
27
+ pushId: string;
28
+ status: string;
29
+ }>;
30
+ /** What a push did (kept 30 days). */
31
+ status(pushId: string): Promise<PushStatus>;
32
+ }
package/dist/push.js ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Push notifications through the project's own Firebase project (Settings > Push notifications). An app registers its
3
+ * device (with any key of the project, or signed in: the device is then the person's); a server key with "Send push
4
+ * notifications" sends. Get the device's token from the Firebase SDK in the app (`getToken()`).
5
+ */
6
+ export class PushResource {
7
+ constructor(app) {
8
+ this.app = app;
9
+ }
10
+ /** Call on every start of the app, and when the token, language, topics or marketing choice change. */
11
+ async register(device) {
12
+ return (await this.app.request({ method: 'POST', path: '/push/devices', json: device }));
13
+ }
14
+ /** When the person signs out or turns pushes off. */
15
+ async unregister(token) {
16
+ return (await this.app.request({ method: 'POST', path: '/push/devices/unregister', json: { token } }));
17
+ }
18
+ /** Queues a push (server keys with "Send push notifications"); `idempotencyKey` queues the same push once. */
19
+ async send(message, options = {}) {
20
+ return (await this.app.request({ method: 'POST', path: '/push/messages', json: message, idempotencyKey: options.idempotencyKey }));
21
+ }
22
+ /** What a push did (kept 30 days). */
23
+ async status(pushId) {
24
+ return (await this.app.request({ path: `/push/messages/${encodeURIComponent(pushId)}` }));
25
+ }
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veroxm/sdk",
3
- "version": "1.13.0",
3
+ "version": "1.15.0",
4
4
  "description": "VeroXM client for JavaScript and TypeScript: content, media, experiences, events and the visitor tracker.",
5
5
  "keywords": [
6
6
  "veroxm",