Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

This is the Atomic Transact JavaScript SDK, a browser-based SDK that enables integration with Atomic's financial services through an iframe-based widget. The SDK provides a simple API to launch the Transact experience and handle callbacks for user interactions.

## Development Commands

- **Test**: `npm test` or `jest` - Runs Jest test suite
- **Build TypeScript definitions**: `npx tsc` - Generates TypeScript declaration files from JavaScript source
- **Publish**: `npm run publish-it` - Compiles TypeScript definitions and publishes to npm

## Architecture

### Core Structure
- **index.js**: Main SDK implementation - single file containing the complete SDK
- **index.d.ts**: TypeScript definitions (auto-generated from index.js via JSDoc comments)
- **test/index.spec.js**: Jest test suite with snapshots

### SDK Architecture
The SDK follows a simple pattern:
1. **atomicSDK.transact()**: Main entry point that creates an iframe and handles configuration
2. **_handleIFrameEvent()**: PostMessage event handler for iframe communication
3. **_removeTransact()**: Cleanup function for removing iframe and event listeners

### Key Components
- **iframe Management**: Creates and styles iframe elements, supports both modal and container modes
- **PostMessage Communication**: Bidirectional communication with Transact iframe using postMessage API
- **Event Callbacks**: onInteraction, onDataRequest, onFinish, onClose callbacks for different SDK events
- **Product Constants**: Predefined product types (DEPOSIT, VERIFY, IDENTIFY, WITHHOLD)

### Configuration
- **Origin Override**: `environmentOverride` parameter allows pointing to different Transact environments
- **Platform Metadata**: SDK automatically includes platform information (browser, SDK version, system details)
- **Container Support**: Can render as modal overlay or embedded in specific DOM container

## Code Style

- Uses Prettier with specific config: no semicolons, single quotes, 2-space tabs, no trailing commas
- TypeScript definitions generated from JSDoc comments in JavaScript source
- Jest for testing with snapshot testing for DOM elements

## SDK Version Management

The SDK version is hardcoded in index.js:52 and should be kept in sync with package.json version. This version is sent to Transact servers as part of platform metadata.
15 changes: 8 additions & 7 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export var Product: {
IDENTIFY: string;
WITHHOLD: string;
VERIFY: string;
DEPOSIT: string;
};
export namespace Atomic {
declare namespace atomicProduct {
const DEPOSIT: string;
const VERIFY: string;
const IDENTIFY: string;
const WITHHOLD: string;
}
declare namespace atomicSDK {
function transact({ config, container, environmentOverride, onInteraction, onDataRequest, onFinish, onClose }?: {
config: any;
container?: any;
Expand All @@ -17,4 +17,5 @@ export namespace Atomic {
close: () => void;
};
}
export { atomicProduct as Product, atomicSDK as Atomic };
//# sourceMappingURL=index.d.ts.map
2 changes: 1 addition & 1 deletion index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let atomicSDK = {
inSdk: true,
platform: {
name: 'browser',
sdkVersion: '3.0.4',
sdkVersion: '__VERSION__',
systemVersion: `${navigator.platform}-${
navigator.vendor ?? 'unknown'
}`
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"version": "3.0.7",
"version": "3.0.8",
"name": "@atomicfi/transact-javascript",
"description": "Atomic Transact Javascript SDK.",
"main": "index.js",
"scripts": {
"test": "jest",
"publish-it": "npx tsc && npm publish --access public"
"prepublishOnly": "node scripts/update-version.js && npx tsc"
},
"keywords": [
"Atomic",
Expand Down
21 changes: 21 additions & 0 deletions scripts/update-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node

const fs = require('fs')
const path = require('path')

// Read version from package.json
const packageJsonPath = path.join(__dirname, '..', 'package.json')
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
const version = packageJson.version

// Read index.js
const indexPath = path.join(__dirname, '..', 'index.js')
const indexContent = fs.readFileSync(indexPath, 'utf8')

// Replace version placeholder with actual version
const updatedContent = indexContent.replace(/'__VERSION__'/g, `'${version}'`)

// Write updated content back
fs.writeFileSync(indexPath, updatedContent, 'utf8')

console.log(`Updated SDK version to ${version}`)
2 changes: 1 addition & 1 deletion test/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ exports[`JavaScript SDK should initialize the sdk 1`] = `
exports[`JavaScript SDK should initialize the sdk 2`] = `
{
"id": "atomic-transact-iframe",
"src": "https://transact.atomicfi.com/initialize/eyJpblNkayI6dHJ1ZSwicGxhdGZvcm0iOnsibmFtZSI6ImJyb3dzZXIiLCJzZGtWZXJzaW9uIjoiMy4wLjQiLCJzeXN0ZW1WZXJzaW9uIjoiaW9zLW1hYyJ9LCJwdWJsaWNUb2tlbiI6IjZlOTM1NDllLTM1NzEtNGY1Ny1iMGY3LTc3YjdjYjBiNWU0OCIsInRhc2tzIjpbeyJwcm9kdWN0IjoiZGVwb3NpdCJ9XX0=",
"src": "https://transact.atomicfi.com/initialize/eyJpblNkayI6dHJ1ZSwicGxhdGZvcm0iOnsibmFtZSI6ImJyb3dzZXIiLCJzZGtWZXJzaW9uIjoiX19WRVJTSU9OX18iLCJzeXN0ZW1WZXJzaW9uIjoiaW9zLW1hYyJ9LCJwdWJsaWNUb2tlbiI6IjZlOTM1NDllLTM1NzEtNGY1Ny1iMGY3LTc3YjdjYjBiNWU0OCIsInRhc2tzIjpbeyJwcm9kdWN0IjoiZGVwb3NpdCJ9XX0=",
"style": {
"cssText": "width: 100%; height: 100%; z-index: 888888888; border-width: 0; overflow-x: hidden; overflow-y: auto; position: fixed; top: 0; left: 0; right: 0; bottom: 0;",
},
Expand Down