diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..fd9fe79 --- /dev/null +++ b/CLAUDE.md @@ -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. \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index e9938b8..24f1780 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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; @@ -17,4 +17,5 @@ export namespace Atomic { close: () => void; }; } +export { atomicProduct as Product, atomicSDK as Atomic }; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/index.d.ts.map b/index.d.ts.map index 7ab8135..d732837 100644 --- a/index.d.ts.map +++ b/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"oBAIU;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC;;IAmBnE;;;;;;;;;;MAuFT"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":";;;;;;;IAmBY;;;;;;;;;;MA8FT"} \ No newline at end of file diff --git a/index.js b/index.js index 4e5c4bd..f4f26a5 100644 --- a/index.js +++ b/index.js @@ -49,7 +49,7 @@ let atomicSDK = { inSdk: true, platform: { name: 'browser', - sdkVersion: '3.0.4', + sdkVersion: '__VERSION__', systemVersion: `${navigator.platform}-${ navigator.vendor ?? 'unknown' }` diff --git a/package-lock.json b/package-lock.json index 769fbaa..dac62d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@atomicfi/transact-javascript", - "version": "3.0.6", + "version": "3.0.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@atomicfi/transact-javascript", - "version": "3.0.6", + "version": "3.0.8", "license": "ISC", "devDependencies": { "jest": "^29.7.0", diff --git a/package.json b/package.json index b572f9e..8decf55 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/update-version.js b/scripts/update-version.js new file mode 100644 index 0000000..330acbd --- /dev/null +++ b/scripts/update-version.js @@ -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}`) \ No newline at end of file diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index 6711bed..725540c 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -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;", },