CloudFunction constructor
Creates a new CloudFunction client
Throws ArgumentError if projectId is empty or invalid
Implementation
CloudFunction(this.projectId, this._getToken) {
// Validate projectId
if (projectId.trim().isEmpty) {
throw ArgumentError(
'CloudFunction requires a valid projectId. Please provide projectId in CocobaseConfig.',
);
}
_dio = Dio(
BaseOptions(
baseUrl: CLOUD_BASEURL,
connectTimeout: const Duration(seconds: 30),
receiveTimeout: const Duration(seconds: 30),
headers: {'Content-Type': 'application/json'},
),
);
// Add auth interceptor
_dio.interceptors.add(
InterceptorsWrapper(
onRequest: (options, handler) {
final token = _getToken();
if (token.isNotEmpty) {
options.headers['Authorization'] = 'Bearer $token';
}
handler.next(options);
},
),
);
}