@koolbase/core 12.25.0 → 12.26.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.
@@ -1,5 +1,5 @@
1
1
  import { AuthStateListener, KoolbaseConfig, KoolbaseSession, KoolbaseUser, LinkPhoneParams, LoginParams, OtpSendResult, PhoneVerifyResult, RegisterParams, RestoreResult, KoolbaseAuditPage, KoolbaseSessionInfo, ResendVerificationResult, SendOtpParams, SignUpResult, SignInWithAppleParams, VerifyOtpParams } from './types.js';
2
- import type { SignInWithGoogleParams, SignOutReason } from './types.js';
2
+ import type { KoolbaseAvatarFile, SignInWithGoogleParams, SignOutReason } from './types.js';
3
3
  export declare class KoolbaseAuth {
4
4
  private config;
5
5
  private storage;
@@ -248,10 +248,16 @@ export declare class KoolbaseAuth {
248
248
  * Only the fields given are sent, so passing one leaves the other
249
249
  * untouched. The updated user is persisted, so `currentUser` reflects it
250
250
  * without a refetch.
251
+ *
252
+ * The photo is one of: `avatar`, one of the user's own files -- the bucket
253
+ * and path an upload returned; read it in a preset's size, and signed when
254
+ * the bucket is private -- `avatarUrl`, an address; or `avatar: null`,
255
+ * removed. A file someone else uploaded is refused.
251
256
  */
252
257
  updateProfile(params: {
253
258
  fullName?: string;
254
259
  avatarUrl?: string;
260
+ avatar?: KoolbaseAvatarFile | null;
255
261
  }): Promise<KoolbaseUser>;
256
262
  /**
257
263
  * Change the signed-in user's password.
package/dist/cjs/auth.js CHANGED
@@ -6,6 +6,15 @@ const types_js_1 = require("./types.js");
6
6
  const auth_errors_js_1 = require("./auth-errors.js");
7
7
  const platform_js_1 = require("./platform.js");
8
8
  const device_metadata_js_1 = require("./device-metadata.js");
9
+ /** The server's `{ bucket, path }`; undefined when it is not one. */
10
+ function avatarFileOf(raw) {
11
+ if (!raw || typeof raw !== 'object')
12
+ return undefined;
13
+ const { bucket, path } = raw;
14
+ if (typeof bucket !== 'string' || typeof path !== 'string' || !bucket || !path)
15
+ return undefined;
16
+ return { bucket, path };
17
+ }
9
18
  class KoolbaseAuth {
10
19
  constructor(config) {
11
20
  this.session = null;
@@ -760,13 +769,24 @@ class KoolbaseAuth {
760
769
  * Only the fields given are sent, so passing one leaves the other
761
770
  * untouched. The updated user is persisted, so `currentUser` reflects it
762
771
  * without a refetch.
772
+ *
773
+ * The photo is one of: `avatar`, one of the user's own files -- the bucket
774
+ * and path an upload returned; read it in a preset's size, and signed when
775
+ * the bucket is private -- `avatarUrl`, an address; or `avatar: null`,
776
+ * removed. A file someone else uploaded is refused.
763
777
  */
764
778
  async updateProfile(params) {
779
+ if (params.avatarUrl !== undefined && params.avatar !== undefined) {
780
+ throw new TypeError('updateProfile: give avatar or avatarUrl, not both');
781
+ }
765
782
  const body = {};
766
783
  if (params.fullName !== undefined)
767
784
  body.full_name = params.fullName;
768
785
  if (params.avatarUrl !== undefined)
769
786
  body.avatar_url = params.avatarUrl;
787
+ if (params.avatar !== undefined) {
788
+ body.avatar = params.avatar === null ? {} : { bucket: params.avatar.bucket, path: params.avatar.path };
789
+ }
770
790
  const res = await this.authRequest('/v1/sdk/auth/me', {
771
791
  method: 'PATCH',
772
792
  body,
@@ -1212,6 +1232,7 @@ class KoolbaseAuth {
1212
1232
  phoneVerified: raw.phone_verified ?? false,
1213
1233
  fullName: raw.full_name,
1214
1234
  avatarUrl: raw.avatar_url,
1235
+ ...(avatarFileOf(raw.avatar) ? { avatar: avatarFileOf(raw.avatar) } : {}),
1215
1236
  verified: raw.verified ?? false,
1216
1237
  createdAt: raw.created_at,
1217
1238
  // Only the claims readable by the user reach here (#155b).
@@ -28,13 +28,29 @@ export interface KoolbaseConfig {
28
28
  */
29
29
  fetch?: FetchLike;
30
30
  }
31
+ /**
32
+ * Where a user's profile photo is stored, when it is one of their files: a
33
+ * path in one of the project's buckets. Read it like any stored file -- in
34
+ * one of the project's image presets, and signed when the bucket is private:
35
+ * `storage.getDownloadUrl({ bucket, path, preset: 'thumb' })`.
36
+ */
37
+ export interface KoolbaseAvatarFile {
38
+ bucket: string;
39
+ path: string;
40
+ }
31
41
  export interface KoolbaseUser {
32
42
  id: string;
33
43
  email: string;
34
44
  phoneNumber?: string;
35
45
  phoneVerified?: boolean;
36
46
  fullName?: string;
47
+ /**
48
+ * The photo's address: set by updateProfile's avatarUrl, or following
49
+ * `avatar` -- a public bucket's permanent link, absent for a private one.
50
+ */
37
51
  avatarUrl?: string;
52
+ /** Where the photo is stored, when it is one of the user's files. */
53
+ avatar?: KoolbaseAvatarFile;
38
54
  verified: boolean;
39
55
  createdAt: string;
40
56
  /**
@@ -1,5 +1,5 @@
1
1
  import { AuthStateListener, KoolbaseConfig, KoolbaseSession, KoolbaseUser, LinkPhoneParams, LoginParams, OtpSendResult, PhoneVerifyResult, RegisterParams, RestoreResult, KoolbaseAuditPage, KoolbaseSessionInfo, ResendVerificationResult, SendOtpParams, SignUpResult, SignInWithAppleParams, VerifyOtpParams } from './types.js';
2
- import type { SignInWithGoogleParams, SignOutReason } from './types.js';
2
+ import type { KoolbaseAvatarFile, SignInWithGoogleParams, SignOutReason } from './types.js';
3
3
  export declare class KoolbaseAuth {
4
4
  private config;
5
5
  private storage;
@@ -248,10 +248,16 @@ export declare class KoolbaseAuth {
248
248
  * Only the fields given are sent, so passing one leaves the other
249
249
  * untouched. The updated user is persisted, so `currentUser` reflects it
250
250
  * without a refetch.
251
+ *
252
+ * The photo is one of: `avatar`, one of the user's own files -- the bucket
253
+ * and path an upload returned; read it in a preset's size, and signed when
254
+ * the bucket is private -- `avatarUrl`, an address; or `avatar: null`,
255
+ * removed. A file someone else uploaded is refused.
251
256
  */
252
257
  updateProfile(params: {
253
258
  fullName?: string;
254
259
  avatarUrl?: string;
260
+ avatar?: KoolbaseAvatarFile | null;
255
261
  }): Promise<KoolbaseUser>;
256
262
  /**
257
263
  * Change the signed-in user's password.
package/dist/esm/auth.js CHANGED
@@ -3,6 +3,15 @@ import { RestoreResult, } from './types.js';
3
3
  import { AccountLockedError, EmailAlreadyInUseError, InvalidCredentialsError, InvalidPhoneNumberError, KoolbaseAuthError, OtpExpiredError, OtpInvalidError, OtpMaxAttemptsError, OtpRateLimitError, PhoneAlreadyLinkedError, IdentityNotFoundError, InsufficientScopeError, MalformedSessionResponseError, ProviderIdentityAlreadyLinkedError, AccountExistsError, ContactNotVerifiedError, CurrentPasswordIncorrectError, HideRequiresVerificationError, InsufficientAuthorityError, LastCredentialError, OAuthOnlyAccountError, SessionRequiredError, SignupsDisabledError, TokenAlreadyUsedError, TokenExpiredError, UnsupportedOAuthProviderError, RateLimitError, VerificationResendCooldownError, VerificationResendDailyCapError, SessionExpiredError, SmsConfigMissingError, TokenRevokedError, UnlockTokenInvalidError, UserDisabledError, WeakPasswordError, AppleEmailRequiredError, AppleSignInNotConfiguredError, InvalidAppleTokenError, OAuthEmailConflictError, GoogleEmailRequiredError, GoogleSignInNotConfiguredError, InvalidGoogleTokenError, EmailCodeDisabledError, MfaRequiredError, RecentAuthRequiredError, RecentMfaRequiredError, MfaAlreadyEnabledError, MfaEnrollmentNotFoundError, MfaNotEnabledError, } from './auth-errors.js';
4
4
  import { getPlatform } from './platform.js';
5
5
  import { DeviceMetadata } from './device-metadata.js';
6
+ /** The server's `{ bucket, path }`; undefined when it is not one. */
7
+ function avatarFileOf(raw) {
8
+ if (!raw || typeof raw !== 'object')
9
+ return undefined;
10
+ const { bucket, path } = raw;
11
+ if (typeof bucket !== 'string' || typeof path !== 'string' || !bucket || !path)
12
+ return undefined;
13
+ return { bucket, path };
14
+ }
6
15
  export class KoolbaseAuth {
7
16
  constructor(config) {
8
17
  this.session = null;
@@ -757,13 +766,24 @@ export class KoolbaseAuth {
757
766
  * Only the fields given are sent, so passing one leaves the other
758
767
  * untouched. The updated user is persisted, so `currentUser` reflects it
759
768
  * without a refetch.
769
+ *
770
+ * The photo is one of: `avatar`, one of the user's own files -- the bucket
771
+ * and path an upload returned; read it in a preset's size, and signed when
772
+ * the bucket is private -- `avatarUrl`, an address; or `avatar: null`,
773
+ * removed. A file someone else uploaded is refused.
760
774
  */
761
775
  async updateProfile(params) {
776
+ if (params.avatarUrl !== undefined && params.avatar !== undefined) {
777
+ throw new TypeError('updateProfile: give avatar or avatarUrl, not both');
778
+ }
762
779
  const body = {};
763
780
  if (params.fullName !== undefined)
764
781
  body.full_name = params.fullName;
765
782
  if (params.avatarUrl !== undefined)
766
783
  body.avatar_url = params.avatarUrl;
784
+ if (params.avatar !== undefined) {
785
+ body.avatar = params.avatar === null ? {} : { bucket: params.avatar.bucket, path: params.avatar.path };
786
+ }
767
787
  const res = await this.authRequest('/v1/sdk/auth/me', {
768
788
  method: 'PATCH',
769
789
  body,
@@ -1209,6 +1229,7 @@ export class KoolbaseAuth {
1209
1229
  phoneVerified: raw.phone_verified ?? false,
1210
1230
  fullName: raw.full_name,
1211
1231
  avatarUrl: raw.avatar_url,
1232
+ ...(avatarFileOf(raw.avatar) ? { avatar: avatarFileOf(raw.avatar) } : {}),
1212
1233
  verified: raw.verified ?? false,
1213
1234
  createdAt: raw.created_at,
1214
1235
  // Only the claims readable by the user reach here (#155b).
@@ -28,13 +28,29 @@ export interface KoolbaseConfig {
28
28
  */
29
29
  fetch?: FetchLike;
30
30
  }
31
+ /**
32
+ * Where a user's profile photo is stored, when it is one of their files: a
33
+ * path in one of the project's buckets. Read it like any stored file -- in
34
+ * one of the project's image presets, and signed when the bucket is private:
35
+ * `storage.getDownloadUrl({ bucket, path, preset: 'thumb' })`.
36
+ */
37
+ export interface KoolbaseAvatarFile {
38
+ bucket: string;
39
+ path: string;
40
+ }
31
41
  export interface KoolbaseUser {
32
42
  id: string;
33
43
  email: string;
34
44
  phoneNumber?: string;
35
45
  phoneVerified?: boolean;
36
46
  fullName?: string;
47
+ /**
48
+ * The photo's address: set by updateProfile's avatarUrl, or following
49
+ * `avatar` -- a public bucket's permanent link, absent for a private one.
50
+ */
37
51
  avatarUrl?: string;
52
+ /** Where the photo is stored, when it is one of the user's files. */
53
+ avatar?: KoolbaseAvatarFile;
38
54
  verified: boolean;
39
55
  createdAt: string;
40
56
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koolbase/core",
3
- "version": "12.25.0",
3
+ "version": "12.26.0",
4
4
  "description": "Koolbase SDK core \u2014 shared behaviour behind @koolbase/react-native and @koolbase/js. Install one of those, not this.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "types": "./dist/esm/index.d.ts",