databag icon indicating copy to clipboard operation
databag copied to clipboard

Move to an sdk package

Open lil5 opened this issue 1 year ago • 9 comments

Instead of reimplementing common chat functionality on each client, create an sdk that is plugged into mobile and web apps.

This could handle;

  • Improve bot support 🤖
  • Move to redaxios

The sdk should not contain any react. Instead async and callbacks should be used

const sdk = new DatabagSdk()

sdk.onLogin(()=>{})

const room = sdk.selectRoom()
const g = () => appview(room.renderConversation())
room.onUpdate(g)

This is just an example of functionality not structure.

With an sdk the react could move to a more passive role of displaying data when the sdk says so.

lil5 avatar Apr 25 '24 21:04 lil5

Yes, I agree. Along those lines, I can see it allowing for other clients to participate in the network while maintaining interoperability. Just because clients speak the same protocol or api, doesn't mean they work well together.

It would be nice if there was just one SDK, but mobile generally requires storage for offline viewing. Supporting both modes within a single SDK may be messy.

There are a few new features, maybe bundled as separate apps, that I would like to include in an SDK. Perhaps it's over designing, but it goes to my hopes that the databag backend can be more general than a message service.

  • contact list with selective access to attributes (ie. phone number for friends, email for work colleagues)
  • photo albums with selective access (ie. family can see family photos, work colleagues can see conference photos)

Thank you for the suggestion!

balzack avatar Apr 25 '24 22:04 balzack

but mobile generally requires storage for offline viewing. Supporting both modes within a single SDK may be messy.

That would require an optional addOfflineSqliteStorage(db)

Interoperability with other sqlite libraries isn't necessary as a non react native library exists too. https://github.com/asnando/sqlite-storage

lil5 avatar Apr 26 '24 05:04 lil5

Thank you for this reference. I have a rough idea what the API should look like now, but am not yet sure how much the refactor effort will be.

I will likely start the SDK work in a month or two, after I complete several other commitments. Would you be willing to review the SDK API after I finish a draft?

balzack avatar Apr 26 '24 19:04 balzack

Definitely 👍

I'd suggest cut-pasting from frontend to sdk then altering from there, that way you never have a commit where everything is broken.

lil5 avatar Apr 27 '24 05:04 lil5

I need to move the typescript changes into a branch until I can fix it: https://github.com/balzack/databag/tree/typescript

Deploying the latest gives me: 'Uncaught ReferenceError: require is not defined'

I thought I had tested it, but I must have been using a stale build.

balzack avatar May 02 '24 22:05 balzack

I'll see if I can work on the docker development env, you seem to be using production builds instead of the local code.

I haven't yet got it working properly (on a Mac machine)

lil5 avatar May 03 '24 05:05 lil5

It might not be worth this effort. When I start the SDK refactor work, I will make sure to use typescript.

balzack avatar May 03 '24 19:05 balzack