@sesamy/sesamy-js 1.19.6 → 1.19.7
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/README.md +148 -0
- package/dist/sesamy-js.cjs +5 -5
- package/dist/sesamy-js.d.ts +21 -5
- package/dist/sesamy-js.iife.js +5 -5
- package/dist/sesamy-js.mjs +1729 -1711
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -271,6 +271,154 @@ setToken(accessToken, expiresIn)
|
|
|
271
271
|
|
|
272
272
|
# Services
|
|
273
273
|
|
|
274
|
+
## `getProfile()`
|
|
275
|
+
|
|
276
|
+
Fetches the user's profile information from the Sesamy-hosted service. If the user is authenticated, the profile data will be retrieved.
|
|
277
|
+
|
|
278
|
+
### Returns
|
|
279
|
+
|
|
280
|
+
`Promise<Profile | null>`: A promise that resolves to the user's profile information if the user is authenticated, otherwise it resolves to `null`.
|
|
281
|
+
|
|
282
|
+
### Example
|
|
283
|
+
|
|
284
|
+
The following example demonstrates how to fetch the user's profile information:
|
|
285
|
+
|
|
286
|
+
```javascript
|
|
287
|
+
import { getProfile } from '@sesamy/sesamy-js';
|
|
288
|
+
|
|
289
|
+
// Fetch the user's profile information
|
|
290
|
+
getProfile()
|
|
291
|
+
.then(profile => {
|
|
292
|
+
if (profile) {
|
|
293
|
+
console.log('User profile:', profile);
|
|
294
|
+
} else {
|
|
295
|
+
console.log('User is not authenticated');
|
|
296
|
+
}
|
|
297
|
+
})
|
|
298
|
+
.catch(error => {
|
|
299
|
+
console.error('Error fetching profile:', error);
|
|
300
|
+
});
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### Profile Type
|
|
304
|
+
|
|
305
|
+
```typescript
|
|
306
|
+
export type Profile = {
|
|
307
|
+
userId: string;
|
|
308
|
+
firstName?: string;
|
|
309
|
+
lastName?: string;
|
|
310
|
+
emailVerified: boolean;
|
|
311
|
+
email: string;
|
|
312
|
+
name?: string;
|
|
313
|
+
locale?: string;
|
|
314
|
+
picture?: string;
|
|
315
|
+
createdAt: string;
|
|
316
|
+
updatedAt: string;
|
|
317
|
+
mobilePhone?: string;
|
|
318
|
+
tags: string[];
|
|
319
|
+
user_metadata?: { [id: string]: string | number };
|
|
320
|
+
billingAddress?: Address;
|
|
321
|
+
deliveryAddress?: Address;
|
|
322
|
+
// @deprecated
|
|
323
|
+
sub: string;
|
|
324
|
+
email_verified?: boolean;
|
|
325
|
+
given_name?: string;
|
|
326
|
+
family_name?: string;
|
|
327
|
+
phone_number?: string;
|
|
328
|
+
};
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### Address Type
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
export type Address = {
|
|
335
|
+
street: string;
|
|
336
|
+
co?: string;
|
|
337
|
+
city: string;
|
|
338
|
+
state: string;
|
|
339
|
+
postalCode: string;
|
|
340
|
+
country: string;
|
|
341
|
+
};
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
Here's the documentation for the `updateProfile` function in a similar structure to the `generateLink` and `getProfile` documentation:
|
|
345
|
+
|
|
346
|
+
## `updateProfile(profile: Partial<Profile>)`
|
|
347
|
+
|
|
348
|
+
Updates the user's profile information on the Sesamy-hosted service. After updating, the cache is cleared to ensure that the latest profile information is available.
|
|
349
|
+
|
|
350
|
+
### Parameters
|
|
351
|
+
|
|
352
|
+
- `profile` (Partial<Profile>): An object containing the profile fields to be updated. Only the provided fields will be updated.
|
|
353
|
+
|
|
354
|
+
### Returns
|
|
355
|
+
|
|
356
|
+
`Promise<boolean>`: A promise that resolves to `true` if the profile update is successful, otherwise `false`.
|
|
357
|
+
|
|
358
|
+
### Example
|
|
359
|
+
|
|
360
|
+
The following example demonstrates how to update the user's profile information:
|
|
361
|
+
|
|
362
|
+
```javascript
|
|
363
|
+
import { updateProfile } from '@sesamy/sesamy-js';
|
|
364
|
+
|
|
365
|
+
// Define the profile fields to be updated
|
|
366
|
+
const updatedProfile = {
|
|
367
|
+
firstName: 'John',
|
|
368
|
+
lastName: 'Doe',
|
|
369
|
+
locale: 'en-US',
|
|
370
|
+
mobilePhone: '+1234567890',
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
// Update the user's profile information
|
|
374
|
+
updateProfile(updatedProfile)
|
|
375
|
+
.then(success => {
|
|
376
|
+
if (success) {
|
|
377
|
+
console.log('Profile updated successfully');
|
|
378
|
+
} else {
|
|
379
|
+
console.log('Profile update failed');
|
|
380
|
+
}
|
|
381
|
+
})
|
|
382
|
+
.catch(error => {
|
|
383
|
+
console.error('Error updating profile:', error);
|
|
384
|
+
});
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
### Profile Type
|
|
388
|
+
|
|
389
|
+
```typescript
|
|
390
|
+
export type Profile = {
|
|
391
|
+
userId: string;
|
|
392
|
+
firstName?: string;
|
|
393
|
+
lastName?: string;
|
|
394
|
+
emailVerified: boolean;
|
|
395
|
+
email: string;
|
|
396
|
+
name?: string;
|
|
397
|
+
locale?: string;
|
|
398
|
+
picture?: string;
|
|
399
|
+
createdAt: string;
|
|
400
|
+
updatedAt: string;
|
|
401
|
+
mobilePhone?: string;
|
|
402
|
+
tags: string[];
|
|
403
|
+
user_metadata?: { [id: string]: string | number };
|
|
404
|
+
billingAddress?: Address;
|
|
405
|
+
deliveryAddress?: Address;
|
|
406
|
+
};
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Address Type
|
|
410
|
+
|
|
411
|
+
```typescript
|
|
412
|
+
export type Address = {
|
|
413
|
+
street: string;
|
|
414
|
+
co?: string;
|
|
415
|
+
city: string;
|
|
416
|
+
state: string;
|
|
417
|
+
postalCode: string;
|
|
418
|
+
country: string;
|
|
419
|
+
};
|
|
420
|
+
```
|
|
421
|
+
|
|
274
422
|
## `generateLink(params: GenerateAccountLink | GenerateConsumeLink)`
|
|
275
423
|
|
|
276
424
|
Generates a link to a Sesamy-hosted service such as account or consume. If the user is authenticated, the link will be signed so that the user can access the service without logging in again.
|