@veroxm/sdk 1.6.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,12 @@
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
+
3
10
  ## 1.6.0
4
11
 
5
12
  - Forms in several languages (public API 2.8): `embedForm({ lang: "fr" })` (or `data-lang="fr"`) shows the form in that
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. */
@@ -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
  };
@@ -1949,6 +2000,15 @@ export interface components {
1949
2000
  "application/json": components["schemas"]["Error"];
1950
2001
  };
1951
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
+ };
1952
2012
  /** @description It conflicts with the current state */
1953
2013
  E409: {
1954
2014
  headers: {
@@ -1976,7 +2036,7 @@ export interface components {
1976
2036
  "application/json": components["schemas"]["Error"];
1977
2037
  };
1978
2038
  };
1979
- /** @description Too many requests; see Retry-After */
2039
+ /** @description Too many requests, or a plan limit reached; see Retry-After */
1980
2040
  E429: {
1981
2041
  headers: {
1982
2042
  [name: string]: unknown;
@@ -1985,6 +2045,33 @@ export interface components {
1985
2045
  "application/json": components["schemas"]["Error"];
1986
2046
  };
1987
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
+ };
1988
2075
  };
1989
2076
  parameters: never;
1990
2077
  requestBodies: never;
@@ -3020,6 +3107,8 @@ export interface operations {
3020
3107
  count?: string;
3021
3108
  timestamps?: string;
3022
3109
  locale?: string;
3110
+ /** @description A database content model limited to the caller's rows: whose (project keys). */
3111
+ userId?: string;
3023
3112
  };
3024
3113
  header?: never;
3025
3114
  path: {
@@ -3046,6 +3135,9 @@ export interface operations {
3046
3135
  403: components["responses"]["E403"];
3047
3136
  404: components["responses"]["E404"];
3048
3137
  429: components["responses"]["E429"];
3138
+ 502: components["responses"]["E502"];
3139
+ 503: components["responses"]["E503"];
3140
+ 504: components["responses"]["E504"];
3049
3141
  };
3050
3142
  };
3051
3143
  createEntry: {
@@ -3078,13 +3170,17 @@ export interface operations {
3078
3170
  401: components["responses"]["E401"];
3079
3171
  403: components["responses"]["E403"];
3080
3172
  404: components["responses"]["E404"];
3173
+ 405: components["responses"]["E405"];
3081
3174
  409: components["responses"]["E409"];
3082
3175
  429: components["responses"]["E429"];
3083
3176
  };
3084
3177
  };
3085
3178
  searchEntries: {
3086
3179
  parameters: {
3087
- 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
+ };
3088
3184
  header?: never;
3089
3185
  path: {
3090
3186
  /** @description The project's UUID. */
@@ -3113,6 +3209,9 @@ export interface operations {
3113
3209
  403: components["responses"]["E403"];
3114
3210
  404: components["responses"]["E404"];
3115
3211
  429: components["responses"]["E429"];
3212
+ 502: components["responses"]["E502"];
3213
+ 503: components["responses"]["E503"];
3214
+ 504: components["responses"]["E504"];
3116
3215
  };
3117
3216
  };
3118
3217
  getEntry: {
@@ -3121,13 +3220,16 @@ export interface operations {
3121
3220
  timestamps?: string;
3122
3221
  /** @description Present: answer with the A/B test variant's entry, plus `experiment` and `variant`. */
3123
3222
  experiment?: string;
3223
+ /** @description A database content model limited to the caller's rows: whose (project keys). */
3224
+ userId?: string;
3124
3225
  };
3125
3226
  header?: never;
3126
3227
  path: {
3127
3228
  /** @description The project's UUID. */
3128
3229
  uuid: string;
3129
3230
  slug: string;
3130
- id: number;
3231
+ /** @description The entry's id: a number, or a database content model's key. */
3232
+ id: string;
3131
3233
  };
3132
3234
  cookie?: never;
3133
3235
  };
@@ -3147,6 +3249,9 @@ export interface operations {
3147
3249
  403: components["responses"]["E403"];
3148
3250
  404: components["responses"]["E404"];
3149
3251
  429: components["responses"]["E429"];
3252
+ 502: components["responses"]["E502"];
3253
+ 503: components["responses"]["E503"];
3254
+ 504: components["responses"]["E504"];
3150
3255
  };
3151
3256
  };
3152
3257
  deleteEntry: {
@@ -3176,6 +3281,7 @@ export interface operations {
3176
3281
  401: components["responses"]["E401"];
3177
3282
  403: components["responses"]["E403"];
3178
3283
  404: components["responses"]["E404"];
3284
+ 405: components["responses"]["E405"];
3179
3285
  429: components["responses"]["E429"];
3180
3286
  };
3181
3287
  };
@@ -3210,6 +3316,7 @@ export interface operations {
3210
3316
  401: components["responses"]["E401"];
3211
3317
  403: components["responses"]["E403"];
3212
3318
  404: components["responses"]["E404"];
3319
+ 405: components["responses"]["E405"];
3213
3320
  409: components["responses"]["E409"];
3214
3321
  429: components["responses"]["E429"];
3215
3322
  };
@@ -3654,6 +3761,88 @@ export interface operations {
3654
3761
  429: components["responses"]["E429"];
3655
3762
  };
3656
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
+ };
3657
3846
  exportSetup: {
3658
3847
  parameters: {
3659
3848
  query?: never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veroxm/sdk",
3
- "version": "1.6.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",