Methods to set up and update a customer's account data.

Use to create a new customer account and attach it to the current session.

Returns the newly created account object.

Create an account
await swell.account.create({
  email: 'julia@example.com',
  first_name: 'Julia', // Optional
  last_name: 'Sanchez', // Optional
  email_optin: true, // Optional
  password: 'thepassword' // Optional
})

Use to update properties of the account that is currently logged in.

Returns the updated account object if successful. Otherwise, returns a validation error.

Update the account
await swell.account.updateAddress("5c15505200c7d14d851e510f", {
  address1: '06 Bennered Mare',
  city: 'Whiterun',
  state: 'NY',
  zip: '10005',
  country: 'US' // Two letter ISO country code
})

Use the metadata object to store arbitrary values on an account. As opposed to storing custom fields with the Backend API, the metadata object is publicly accessible, making it easy to add custom data throughout your customer flow. Note: the metadata object can also be queried and updated using the Backend API.

Returns the updated account object.

Update the account metadata
await swell.account.update({
  metadata: {
    any: 'value',
    even: {
      nested: true
    }
  }
})

When updating nested arrays in metadata, you may notice the default behavior is to merge instead of replacing values. To replace array values, use the $set operator to override the entire value.

Replace array values for account updates
await swell.account.update({
  $set: {
    metadata: {
      my_array: [ ... ]
    }
  }
})