@rustrak/client 0.14.1 → 0.14.3

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/index.cjs CHANGED
@@ -626,7 +626,21 @@ var userSchema = zod.z.object({
626
626
  id: zod.z.number().int().positive(),
627
627
  email: zod.z.string().email(),
628
628
  role: globalRoleSchema,
629
- is_admin: zod.z.boolean()
629
+ is_admin: zod.z.boolean(),
630
+ /**
631
+ * The dashboard language this user chose.
632
+ *
633
+ * `null` means they never chose one, which a consumer should treat as
634
+ * "infer it" rather than as English. Optional as well as nullable so a
635
+ * client stays compatible with a server predating the column.
636
+ */
637
+ language: zod.z.string().nullable().optional(),
638
+ /** The IANA timezone this user chose, `null` when they never chose one. */
639
+ timezone: zod.z.string().nullable().optional()
640
+ });
641
+ var updatePreferencesRequestSchema = zod.z.object({
642
+ language: zod.z.string().nullable().optional(),
643
+ timezone: zod.z.string().nullable().optional()
630
644
  });
631
645
  var authResponseSchema = zod.z.object({
632
646
  user: userSchema
@@ -719,6 +733,11 @@ function warnUnknownFieldErrorCode(code, field) {
719
733
  `[@rustrak/client] Dropped a field error with an unrecognised code "${code}" (field "${field}"). This client build does not know that code, so the affected inputs degrade to a form-level error. The server is most likely newer than @rustrak/client; upgrade the client to match the server version.`
720
734
  );
721
735
  }
736
+ function readIncidentId(error) {
737
+ const body = error.data;
738
+ const raw = body && typeof body === "object" ? body.error?.incident_id : void 0;
739
+ return typeof raw === "string" && raw.length > 0 ? raw : void 0;
740
+ }
722
741
  function readFieldErrors(error) {
723
742
  const body = error.data;
724
743
  const raw = body && typeof body === "object" ? body.error?.fields : void 0;
@@ -764,7 +783,13 @@ function transformHttpError(error) {
764
783
  const { response } = error;
765
784
  const status = response.status;
766
785
  if (status >= 500) {
767
- return { kind: "server_error", status, message: SERVER_ERROR_MESSAGE };
786
+ const base = {
787
+ kind: "server_error",
788
+ status,
789
+ message: SERVER_ERROR_MESSAGE
790
+ };
791
+ const incidentId = readIncidentId(error);
792
+ return incidentId === void 0 ? base : { ...base, incidentId };
768
793
  }
769
794
  const message = readErrorMessage(error, status);
770
795
  const fields = readFieldErrors(error);
@@ -1296,6 +1321,24 @@ var AuthResource = class extends BaseResource {
1296
1321
  async getCurrentUser() {
1297
1322
  return this.request(() => this.http.get("auth/me"), userSchema);
1298
1323
  }
1324
+ /**
1325
+ * Stores how this reader wants the dashboard presented to them.
1326
+ *
1327
+ * A key left out is left alone; a key sent as `null` is cleared. That is why
1328
+ * the request type is optional *and* nullable rather than one or the other:
1329
+ * "do not touch" and "forget my choice" are different instructions.
1330
+ */
1331
+ async updatePreferences(preferences) {
1332
+ const validatedInput = this.validateInput(
1333
+ preferences,
1334
+ updatePreferencesRequestSchema
1335
+ );
1336
+ if (!validatedInput.success) return validatedInput;
1337
+ return this.request(
1338
+ () => this.http.patch("auth/me", { json: validatedInput.data }),
1339
+ userSchema
1340
+ );
1341
+ }
1299
1342
  /**
1300
1343
  * Get the details of a pending invitation by its token (public endpoint)
1301
1344
  * Used by the accept-invitation page before the user has an account