JS SDK debugging doodle

The most minimal boilerplate to debug issues with the JS SDK.

HTML

<script src="https://unpkg.com/@amityco/js-sdk"></script>
<pre></pre>

CSS

* {
  box-sizing: border-box;
}

html, body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  margin: 0;
  padding: 0;
  background: #222;
  color: #eee;
}

pre {
  width: 100%;
  height: 100%;
  overflow: auto;
  margin: 0;
  padding: 1rem;
  word-break: break-all;
  white-space: break-spaces;
}

JavaScript

/*
  Welcome to the JS SDK debugging doodle.

  Here you'll find:
  	1. The most minimal setup to reproduce your issue.
    2. A boilerplate with the latest version of the SDK ready to go.
		3. Some debug helper.
*/

/*****************************/
// debug helper

console.clear();

;['clear'].forEach(method => {
  const call = console[method]
  console[method] = () => {
    call()
    document.querySelector('pre').textContent = ''
  }
})

;['log', 'info', 'warn', 'error'].forEach(method => {
  const call = console[method]

  console[method] = (...mixed) => {
    const entries = mixed.map(entry => JSON.stringify(entry, null, 2))
    document.querySelector('pre').textContent += `[${method}](${new Date().toISOString()}) - ${entries.join(', ')}\n\n`  

    call(...mixed);
  }
});

/******************************/
// sdk starterkit
console.log('sdk version:', window.__asc__.sdk)

const amitySdk = window['@amityco/js-sdk']
const { default: AmityClient, ApiEndpoint, UserRepository } = amitySdk

const apiKey = 'b3bee858328ef4344a308e4a5a091688d05fdee2be353a2b'
const userId = 'this_RANDOM_user_ID1' // not exist

const userId2 = 'test' // exist
const targetUserId = 'Web-Test' // exist
const apiEndpoint = 'https://api.staging.ekomedia.technology'

const client = new AmityClient({ apiKey, apiEndpoint})


/******************************/
const onStatusChange = status => {
	const { currentUserId = 'not exist if disconnected (unregister session)', connectionStatus } = client; 
  console.log('connected:', { currentUserId, connectionStatus });
};

const main = async () => {
	client.registerSession({ userId })
  client.on('connectionStatusChanged', onStatusChange);
  
  console.log(`sending follow request from ${userId} to ${targetUserId}`)
  try {
  	await UserRepository.follow(targetUserId);
  } catch (err) {
  	console.log(err.message)
  }
  
  const followInfo = UserRepository.getFollowInfo(userId, targetUserId);
  followInfo.on('dataUpdated', console.log);
  
  setTimeout(()...