coffrify 0.9.0
coffrify: ^0.9.0 copied to clipboard
Official Dart SDK for Coffrify, encrypted file transfer infrastructure: transfers, webhooks, API keys, audit, vaults and 30+ resources. Pure Dart, no Flutter dependency.
// Coffrify Dart SDK — minimal CLI example.
//
// Demonstrates:
// - Bootstrapping the Coffrify client
// - Creating a transfer
// - Verifying an inbound webhook signature with the test helper
import 'package:coffrify/coffrify.dart';
import 'package:coffrify/testing.dart';
Future<void> main() async {
const apiKey = String.fromEnvironment(
'COFFRIFY_API_KEY',
defaultValue: 'cof_test_replace_me',
);
final client = Coffrify(
apiKey: apiKey,
configuration: CoffrifyConfiguration(
apiKey: apiKey,
timeout: const Duration(seconds: 20),
retryPolicy: const ExponentialBackoff(maxAttempts: 3),
),
);
print('Creating transfer...');
try {
final result = await client.transfers.create(
const [
TransferFileInput(
name: 'hello.txt',
size: 11,
mimeType: 'text/plain',
),
],
options: const CreateTransferOptions(
expiresInHours: 24,
maxDownloads: 5,
transferTitle: 'SDK demo',
),
);
print('Transfer created: ${result.transfer.shortCode}');
print('Upload URL: ${result.uploadUrls.first.url}');
} on CoffrifyApiException catch (e) {
print('Coffrify error ${e.status}: ${e.message}');
}
print('\nVerifying a test webhook...');
const secret = 'whsec_1234567890abcdef';
final signed = signPayloadTest(
secret: secret,
body: {
'id': 'evt_demo',
'type': 'ping',
'created_at': DateTime.now().toUtc().toIso8601String(),
'workspace_id': 'ws_demo',
'data': {'source': 'manual'},
},
);
final verification = await verifyWebhook(
secret: secret,
body: signed.body,
headers: signed.headers,
);
if (verification.valid) {
print('Webhook OK - event type: ${verification.event!.type}');
} else {
print('Webhook rejected: ${verification.failure!.name}');
}
}