@veroxm/sdk 1.5.0 → 1.7.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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.7.0
4
+
5
+ - Database content models (public API 2.10): `app.content(slug)` reads them like any collection; their entries come
6
+ from a connected database, with related rows nested. `get(id)` takes a text key too, and `list`, `search`, `count`
7
+ and `get` take `userId` and `ctx` (sent as `?userId=` and `?ctx.<name>=`) for a model limited to the caller's rows,
8
+ from a project key on your server.
9
+
10
+ ## 1.6.0
11
+
12
+ - Forms in several languages (public API 2.8): `embedForm({ lang: "fr" })` (or `data-lang="fr"`) shows the form in that
13
+ language when it has a translation; otherwise the visitor's browser language decides, and the form has a language
14
+ switcher. Responses from `app.forms` carry `locale`, the language the person answered in.
15
+
3
16
  ## 1.5.0
4
17
 
5
18
  - Forms (public API 2.7). `embedForm({ baseUrl, form, mode })` shows a VeroXM form in a page: `inline` (in an element,
package/dist/content.d.ts CHANGED
@@ -28,6 +28,13 @@ export interface ListOptions {
28
28
  * explicit last resort.
29
29
  */
30
30
  locale?: string;
31
+ /**
32
+ * A database content model limited to the caller's rows: whose rows (project keys on your server; an end user's
33
+ * login is always themselves). Sent as `?userId=`.
34
+ */
35
+ userId?: string;
36
+ /** A database content model limited by a value your server passes: `{ tenant: 'acme' }` is sent as `?ctx.tenant=acme`. */
37
+ ctx?: Record<string, string>;
31
38
  }
32
39
  /**
33
40
  * Typed access to one content collection's entries. `T` is whatever
@@ -58,9 +65,9 @@ export declare class ContentResource<T = Record<string, unknown>> {
58
65
  * a specific locale's entry, filter list()/search() by whatever field
59
66
  * identifies the logical entry (e.g. `slug`) plus `locale`, not by id.
60
67
  */
61
- get(id: number, options?: {
68
+ get(id: number | string, options?: {
62
69
  timestamps?: boolean;
63
- }): Promise<T>;
70
+ } & Pick<ListOptions, 'userId' | 'ctx'>): Promise<T>;
64
71
  /** Fields are sent flat (no wrapper). Pass `draft: true` to create without publishing; omit it (or pass false) to publish immediately. */
65
72
  create(data: Record<string, unknown>): Promise<T>;
66
73
  /**
package/dist/content.js CHANGED
@@ -1,3 +1,7 @@
1
+ /** Who the rows are for (userId, ctx.<name>), as query parameters. */
2
+ function callerQuery(options) {
3
+ return { userId: options.userId, ...Object.fromEntries(Object.entries(options.ctx ?? {}).map(([k, v]) => [`ctx.${k}`, v])) };
4
+ }
1
5
  /**
2
6
  * Typed access to one content collection's entries. `T` is whatever
3
7
  * shape you expect back (the API's actual response is a plain object per
@@ -24,15 +28,18 @@ export class ContentResource {
24
28
  count: options.count ? '1' : undefined,
25
29
  timestamps: options.timestamps ? '1' : undefined,
26
30
  locale: options.locale,
31
+ ...callerQuery(options),
27
32
  },
28
33
  });
29
34
  }
30
35
  /** Same filters as list(), sent as a JSON body -- use this for `where`/`whereRelation`, which are awkward to express as query-string params. */
31
36
  async search(options) {
37
+ const { userId, ctx, ...body } = options;
32
38
  return this.app.request({
33
39
  method: 'POST',
34
40
  path: `${this.root()}/search`,
35
- json: options,
41
+ query: callerQuery({ userId, ctx }),
42
+ json: body,
36
43
  });
37
44
  }
38
45
  /** A typed shortcut for search({...options, count: true}) -- the API returns a bare number for a counting query, not a list. */
@@ -53,9 +60,10 @@ export class ContentResource {
53
60
  * identifies the logical entry (e.g. `slug`) plus `locale`, not by id.
54
61
  */
55
62
  async get(id, options = {}) {
63
+ // A database content model's key can be text.
56
64
  return this.app.request({
57
- path: `${this.root()}/${id}`,
58
- query: { timestamps: options.timestamps ? '1' : undefined },
65
+ path: `${this.root()}/${encodeURIComponent(String(id))}`,
66
+ query: { timestamps: options.timestamps ? '1' : undefined, ...callerQuery(options) },
59
67
  });
60
68
  }
61
69
  /** Fields are sent flat (no wrapper). Pass `draft: true` to create without publishing; omit it (or pass false) to publish immediately. */
package/dist/embed.d.ts CHANGED
@@ -16,6 +16,8 @@ export interface FormEmbedOptions {
16
16
  container?: HTMLElement | string;
17
17
  /** Hidden fields the form declares, e.g. `{ source: "pricing-page" }`. */
18
18
  hidden?: Record<string, string>;
19
+ /** The language to show, when the form has it ("fr", "ar"); otherwise the visitor's browser language decides. */
20
+ lang?: string;
19
21
  /** inline: the height in pixels (default 520). */
20
22
  height?: number;
21
23
  /** inline: grow and shrink with the form's content (good for the all-on-a-page layout). */
package/dist/embed.js CHANGED
@@ -82,6 +82,8 @@ export function embedForm(options) {
82
82
  const url = new URL(`/f/${options.form}`, formOrigin);
83
83
  for (const [k, v] of Object.entries(options.hidden ?? {}))
84
84
  url.searchParams.set(k, String(v));
85
+ if (options.lang)
86
+ url.searchParams.set('lang', options.lang);
85
87
  url.searchParams.set('vx_embed', mode);
86
88
  url.searchParams.set('vx_id', id);
87
89
  url.searchParams.set('vx_origin', window.location.origin);
@@ -306,6 +308,7 @@ export function embedFormsFromPage(baseUrl, root = document) {
306
308
  mode,
307
309
  container: mode === 'inline' || (mode === 'fullpage' && node.tagName !== 'SCRIPT') ? node : undefined,
308
310
  hidden,
311
+ lang: d.lang,
309
312
  height: num(d.height),
310
313
  autoHeight: d.autoHeight === 'true',
311
314
  size: d.size === 'small' || d.size === 'large' ? d.size : undefined,
@@ -540,7 +540,7 @@ export interface paths {
540
540
  };
541
541
  /**
542
542
  * A collection's entries
543
- * @description Flags are on when present (`?count`, `?timestamps`). With `count` the answer is a number.
543
+ * @description Flags are on when present (`?count`, `?timestamps`). With `count` the answer is a number. The slug can also name a database content model (entries read from a connected database): the key then also needs database:<db>:read, `filter.<field>[.<op>]=` filters, `userId=` or `ctx.<name>=` say whose rows for a model limited to the caller’s, and `state`, `locale` and `timestamps` don’t apply.
544
544
  */
545
545
  get: operations["listEntries"];
546
546
  put?: never;
@@ -760,6 +760,43 @@ export interface paths {
760
760
  patch?: never;
761
761
  trace?: never;
762
762
  };
763
+ "/projects/{uuid}/databases/{db}/{table}": {
764
+ parameters: {
765
+ query?: never;
766
+ header?: never;
767
+ path?: never;
768
+ cookie?: never;
769
+ };
770
+ /**
771
+ * A page of rows from an exposed table of a connected database
772
+ * @description Needs database:<db>:read. Filters are filter.<column>=value or filter.<column>.<op>=value (eq, ne, gt, gte, lt, lte, in (comma-separated), contains, null (true/false)), on columns the table lets you filter. A table limited to the caller’s rows takes userId= or ctx.<name>= from a project key; an end user’s login is always themselves.
773
+ */
774
+ get: operations["listDatabaseRows"];
775
+ put?: never;
776
+ post?: never;
777
+ delete?: never;
778
+ options?: never;
779
+ head?: never;
780
+ patch?: never;
781
+ trace?: never;
782
+ };
783
+ "/projects/{uuid}/databases/{db}/{table}/{key}": {
784
+ parameters: {
785
+ query?: never;
786
+ header?: never;
787
+ path?: never;
788
+ cookie?: never;
789
+ };
790
+ /** One row by its primary key */
791
+ get: operations["getDatabaseRow"];
792
+ put?: never;
793
+ post?: never;
794
+ delete?: never;
795
+ options?: never;
796
+ head?: never;
797
+ patch?: never;
798
+ trace?: never;
799
+ };
763
800
  "/projects/{uuid}/setup": {
764
801
  parameters: {
765
802
  query?: never;
@@ -1320,9 +1357,10 @@ export interface components {
1320
1357
  };
1321
1358
  SessionWithRecoveryCodes: components["schemas"]["Session"] & components["schemas"]["MaybeRecoveryCodes"];
1322
1359
  SessionWithPasskey: components["schemas"]["Session"] & components["schemas"]["PasskeyAdded"];
1323
- /** @description An entry: its id and the collection's fields, by field name. */
1360
+ /** @description An entry: its id and the collection's fields, by field name. A database content model's entry also has its relations: an object (or null) or a list. */
1324
1361
  Entry: {
1325
- id: number;
1362
+ /** @description A number; for a database content model, its key column as stored (a number or text). */
1363
+ id: number | string;
1326
1364
  locale?: string | null;
1327
1365
  /** Format: date-time */
1328
1366
  published_at?: string;
@@ -1504,6 +1542,19 @@ export interface components {
1504
1542
  [key: string]: unknown;
1505
1543
  };
1506
1544
  };
1545
+ DatabaseRows: {
1546
+ data: {
1547
+ [key: string]: unknown;
1548
+ }[];
1549
+ /** @description Pass as page_token for the next page; null on the last page. */
1550
+ next_page_token: string | null;
1551
+ };
1552
+ DatabaseRow: {
1553
+ /** @description The row: the columns the table exposes. */
1554
+ data: {
1555
+ [key: string]: unknown;
1556
+ };
1557
+ };
1507
1558
  StartedRun: {
1508
1559
  runId: number;
1509
1560
  };
@@ -1792,6 +1843,8 @@ export interface components {
1792
1843
  url?: string;
1793
1844
  referrer?: string | null;
1794
1845
  };
1846
+ /** @description The language the person saw: the definition's `locale` or one of its `translations`. Error messages come back in it. */
1847
+ locale?: string;
1795
1848
  };
1796
1849
  FormResponseResult: {
1797
1850
  /** @description The response id (r_...). */
@@ -1886,6 +1939,8 @@ export interface components {
1886
1939
  title: string;
1887
1940
  } | null;
1888
1941
  device: string | null;
1942
+ /** @description The language the person saw. */
1943
+ locale: string | null;
1889
1944
  /** @description Signed-in forms: the project account that answered. */
1890
1945
  endUserId: number | null;
1891
1946
  variables: {
@@ -1945,6 +2000,15 @@ export interface components {
1945
2000
  "application/json": components["schemas"]["Error"];
1946
2001
  };
1947
2002
  };
2003
+ /** @description Not allowed: a database content model is read only */
2004
+ E405: {
2005
+ headers: {
2006
+ [name: string]: unknown;
2007
+ };
2008
+ content: {
2009
+ "application/json": components["schemas"]["Error"];
2010
+ };
2011
+ };
1948
2012
  /** @description It conflicts with the current state */
1949
2013
  E409: {
1950
2014
  headers: {
@@ -1972,7 +2036,7 @@ export interface components {
1972
2036
  "application/json": components["schemas"]["Error"];
1973
2037
  };
1974
2038
  };
1975
- /** @description Too many requests; see Retry-After */
2039
+ /** @description Too many requests, or a plan limit reached; see Retry-After */
1976
2040
  E429: {
1977
2041
  headers: {
1978
2042
  [name: string]: unknown;
@@ -1981,6 +2045,33 @@ export interface components {
1981
2045
  "application/json": components["schemas"]["Error"];
1982
2046
  };
1983
2047
  };
2048
+ /** @description The system behind this answered with an error */
2049
+ E502: {
2050
+ headers: {
2051
+ [name: string]: unknown;
2052
+ };
2053
+ content: {
2054
+ "application/json": components["schemas"]["Error"];
2055
+ };
2056
+ };
2057
+ /** @description Not available right now; see Retry-After */
2058
+ E503: {
2059
+ headers: {
2060
+ [name: string]: unknown;
2061
+ };
2062
+ content: {
2063
+ "application/json": components["schemas"]["Error"];
2064
+ };
2065
+ };
2066
+ /** @description The system behind this did not answer in time */
2067
+ E504: {
2068
+ headers: {
2069
+ [name: string]: unknown;
2070
+ };
2071
+ content: {
2072
+ "application/json": components["schemas"]["Error"];
2073
+ };
2074
+ };
1984
2075
  };
1985
2076
  parameters: never;
1986
2077
  requestBodies: never;
@@ -3016,6 +3107,8 @@ export interface operations {
3016
3107
  count?: string;
3017
3108
  timestamps?: string;
3018
3109
  locale?: string;
3110
+ /** @description A database content model limited to the caller's rows: whose (project keys). */
3111
+ userId?: string;
3019
3112
  };
3020
3113
  header?: never;
3021
3114
  path: {
@@ -3042,6 +3135,9 @@ export interface operations {
3042
3135
  403: components["responses"]["E403"];
3043
3136
  404: components["responses"]["E404"];
3044
3137
  429: components["responses"]["E429"];
3138
+ 502: components["responses"]["E502"];
3139
+ 503: components["responses"]["E503"];
3140
+ 504: components["responses"]["E504"];
3045
3141
  };
3046
3142
  };
3047
3143
  createEntry: {
@@ -3074,13 +3170,17 @@ export interface operations {
3074
3170
  401: components["responses"]["E401"];
3075
3171
  403: components["responses"]["E403"];
3076
3172
  404: components["responses"]["E404"];
3173
+ 405: components["responses"]["E405"];
3077
3174
  409: components["responses"]["E409"];
3078
3175
  429: components["responses"]["E429"];
3079
3176
  };
3080
3177
  };
3081
3178
  searchEntries: {
3082
3179
  parameters: {
3083
- query?: never;
3180
+ query?: {
3181
+ /** @description A database content model limited to the caller's rows: whose (project keys). `ctx.<name>=` likewise. */
3182
+ userId?: string;
3183
+ };
3084
3184
  header?: never;
3085
3185
  path: {
3086
3186
  /** @description The project's UUID. */
@@ -3109,6 +3209,9 @@ export interface operations {
3109
3209
  403: components["responses"]["E403"];
3110
3210
  404: components["responses"]["E404"];
3111
3211
  429: components["responses"]["E429"];
3212
+ 502: components["responses"]["E502"];
3213
+ 503: components["responses"]["E503"];
3214
+ 504: components["responses"]["E504"];
3112
3215
  };
3113
3216
  };
3114
3217
  getEntry: {
@@ -3117,13 +3220,16 @@ export interface operations {
3117
3220
  timestamps?: string;
3118
3221
  /** @description Present: answer with the A/B test variant's entry, plus `experiment` and `variant`. */
3119
3222
  experiment?: string;
3223
+ /** @description A database content model limited to the caller's rows: whose (project keys). */
3224
+ userId?: string;
3120
3225
  };
3121
3226
  header?: never;
3122
3227
  path: {
3123
3228
  /** @description The project's UUID. */
3124
3229
  uuid: string;
3125
3230
  slug: string;
3126
- id: number;
3231
+ /** @description The entry's id: a number, or a database content model's key. */
3232
+ id: string;
3127
3233
  };
3128
3234
  cookie?: never;
3129
3235
  };
@@ -3143,6 +3249,9 @@ export interface operations {
3143
3249
  403: components["responses"]["E403"];
3144
3250
  404: components["responses"]["E404"];
3145
3251
  429: components["responses"]["E429"];
3252
+ 502: components["responses"]["E502"];
3253
+ 503: components["responses"]["E503"];
3254
+ 504: components["responses"]["E504"];
3146
3255
  };
3147
3256
  };
3148
3257
  deleteEntry: {
@@ -3172,6 +3281,7 @@ export interface operations {
3172
3281
  401: components["responses"]["E401"];
3173
3282
  403: components["responses"]["E403"];
3174
3283
  404: components["responses"]["E404"];
3284
+ 405: components["responses"]["E405"];
3175
3285
  429: components["responses"]["E429"];
3176
3286
  };
3177
3287
  };
@@ -3206,6 +3316,7 @@ export interface operations {
3206
3316
  401: components["responses"]["E401"];
3207
3317
  403: components["responses"]["E403"];
3208
3318
  404: components["responses"]["E404"];
3319
+ 405: components["responses"]["E405"];
3209
3320
  409: components["responses"]["E409"];
3210
3321
  429: components["responses"]["E429"];
3211
3322
  };
@@ -3650,6 +3761,88 @@ export interface operations {
3650
3761
  429: components["responses"]["E429"];
3651
3762
  };
3652
3763
  };
3764
+ listDatabaseRows: {
3765
+ parameters: {
3766
+ query?: {
3767
+ /** @description Up to 3 columns, like name,-created_at. */
3768
+ sort?: string;
3769
+ /** @description Rows per page: default 25, at most the connection's limit. */
3770
+ limit?: number;
3771
+ /** @description next_page_token from the previous page, with the same filters and sort. */
3772
+ page_token?: string;
3773
+ /** @description Whose rows, for a table limited to the caller's rows (project keys). */
3774
+ userId?: string;
3775
+ };
3776
+ header?: never;
3777
+ path: {
3778
+ /** @description The project's UUID. */
3779
+ uuid: string;
3780
+ /** @description The database's name in the project. */
3781
+ db: string;
3782
+ /** @description The table's URL name. */
3783
+ table: string;
3784
+ };
3785
+ cookie?: never;
3786
+ };
3787
+ requestBody?: never;
3788
+ responses: {
3789
+ /** @description OK */
3790
+ 200: {
3791
+ headers: {
3792
+ [name: string]: unknown;
3793
+ };
3794
+ content: {
3795
+ "application/json": components["schemas"]["DatabaseRows"];
3796
+ };
3797
+ };
3798
+ 400: components["responses"]["E400"];
3799
+ 401: components["responses"]["E401"];
3800
+ 403: components["responses"]["E403"];
3801
+ 404: components["responses"]["E404"];
3802
+ 429: components["responses"]["E429"];
3803
+ 502: components["responses"]["E502"];
3804
+ 503: components["responses"]["E503"];
3805
+ 504: components["responses"]["E504"];
3806
+ };
3807
+ };
3808
+ getDatabaseRow: {
3809
+ parameters: {
3810
+ query?: {
3811
+ /** @description Whose rows, for a table limited to the caller's rows (project keys). */
3812
+ userId?: string;
3813
+ };
3814
+ header?: never;
3815
+ path: {
3816
+ /** @description The project's UUID. */
3817
+ uuid: string;
3818
+ db: string;
3819
+ table: string;
3820
+ /** @description The row's primary key value. */
3821
+ key: string;
3822
+ };
3823
+ cookie?: never;
3824
+ };
3825
+ requestBody?: never;
3826
+ responses: {
3827
+ /** @description OK */
3828
+ 200: {
3829
+ headers: {
3830
+ [name: string]: unknown;
3831
+ };
3832
+ content: {
3833
+ "application/json": components["schemas"]["DatabaseRow"];
3834
+ };
3835
+ };
3836
+ 400: components["responses"]["E400"];
3837
+ 401: components["responses"]["E401"];
3838
+ 403: components["responses"]["E403"];
3839
+ 404: components["responses"]["E404"];
3840
+ 429: components["responses"]["E429"];
3841
+ 502: components["responses"]["E502"];
3842
+ 503: components["responses"]["E503"];
3843
+ 504: components["responses"]["E504"];
3844
+ };
3845
+ };
3653
3846
  exportSetup: {
3654
3847
  parameters: {
3655
3848
  query?: never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veroxm/sdk",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "description": "VeroXM client for JavaScript and TypeScript: content, media, experiences, events and the visitor tracker.",
5
5
  "keywords": [
6
6
  "veroxm",