Skip to content

layers/amba-functions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@layers/amba-functions

The SDK customer Cloudflare Workers import to build amba functions.

defineFunction wraps your handler with HMAC verification of the incoming dispatched request and constructs a typed ctx object exposing auth, collections, AI, events, storage, email, queue, fan-out, and secrets.

Install

npm install @layers/amba-functions
# or: pnpm add @layers/amba-functions
# or: yarn add @layers/amba-functions

Usage

import { defineFunction } from '@layers/amba-functions';

export default defineFunction(async (req, ctx) => {
  const userId = ctx.auth.assertUser();
  const letters = await ctx.collections.letters.asUser(userId).find();
  return Response.json({ letters });
});

The handler receives the Worker Request and a ctx:

  • ctx.authuserId / developerId, plus assertUser() / assertDeveloper().
  • ctx.collections.<name> — typed CRUD against your tenant database.
  • ctx.ai.anthropic / ctx.ai.openai / ctx.ai.embeddings — proxied AI calls.
  • ctx.events.track({ name, properties }) — record an engagement event.
  • ctx.storageupload, delete, presign against your project's R2.
  • ctx.email.send — templated or ad-hoc transactional email.
  • ctx.queue.send — enqueue a background job.
  • ctx.fanOut.forUsersInSegment — invoke a function for every user in a segment.
  • ctx.secrets.get('STRIPE_KEY') — read a Workers Secret bound to this script.

Errors thrown by the SDK are subclasses of AmbaError (AmbaAuthError, AmbaNotFoundError, AmbaValidationError, AmbaRateLimitError, AmbaTenantUnavailableError, AmbaInternalError).

License

MIT

About

amba functions SDK — defineFunction + ctx.* for customer Cloudflare Workers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors