0.2.2 • Published 5 months ago
@flamedeck/upload v0.2.2
@flamedeck/upload
Client library for uploading traces to the Flamedeck API.
Installation
npm install @flamedeck/upload
# or
yarn add @flamedeck/uploadUsage
Import the uploadTraceToApi function and required types:
import { uploadTraceToApi, UploadError, type UploadOptions } from '@flamedeck/upload';
async function handleFileUpload(file: File) {
const apiKey = 'YOUR_FLAMEDECK_API_KEY'; // Get key from flamdeck settings
const options: UploadOptions = {
apiKey: apiKey,
traceData: file, // Pass a File or Blob object
fileName: file.name,
scenario: 'Javascript Upload Example',
// Add other optional metadata if needed
commitSha: 'abcdef1',
metadata: { client: 'web', userId: 'some_user_id' }
};
try {
const result = await uploadTraceToApi(options);
console.log('Upload successful! View URL:', result.viewUrl);
} catch (error) {
if (error instanceof UploadError) {
console.error(`Upload failed (${error.status}): ${error.message}`, error.details);
} else {
console.error('An unexpected error occurred:', error);
}
}
}Building
To build the library locally (e.g., after making changes), run:
yarn nx run @flamedeck/upload:build
# or
cd packages/client-uploader
yarn buildThis will generate the distributable files (CommonJS, ESM, Type Definitions) in the packages/client-uploader/dist directory.
Publishing to NPM (for Maintainers)
NOTE: Make sure that uploading works before incrementing the script version:
FLAMEDECK_API_KEY=<my-key> yarn nx run @flamedeck/upload:example:node-upload- Update Version: Increment the
versionnumber inpackages/client-uploader/package.jsonaccording to semantic versioning. - Login to NPM: Ensure you are logged into the correct NPM account that has publish access to the
@flamedeckorganization:npm login - Build the package
yarn nx run @flamedeck/upload:build - Run Publish Command: Use the Nx target to build and publish:
This command automatically builds the package and runsyarn nx run @flamedeck/upload:publishnpm publish --access publicfrom thedistdirectory.
(Note: Version 0.0.1 was published incorrectly without the built JS/TS files due to an incorrect files entry in package.json. This was corrected for subsequent versions.)
Related Packages
@flamedeck/flamechart-mcp- MCP server for analyzing performance traces