-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d86b1f
commit e479c8b
Showing
6 changed files
with
220 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'dart:js_interop'; | ||
|
||
import 'package:tekartik_firebase_auth/auth.dart'; | ||
import 'package:tekartik_firebase_auth_node/src/node/auth_node.dart' // ignore: implementation_imports | ||
as impl; | ||
import 'package:tekartik_firebase_functions/firebase_functions.dart'; | ||
import 'package:tekartik_firebase_functions_node/src/node/firebase_functions_https_node_js_interop.dart' | ||
as js; | ||
|
||
class CallRequestNode with CallRequestMixin implements CallRequest { | ||
final js.JSCallableRequest nativeInstance; | ||
|
||
@override | ||
late final Object? data = nativeInstance.data?.dartify(); | ||
|
||
@override | ||
late final CallContext context = CallContextNode(nativeInstance); | ||
|
||
CallRequestNode(this.nativeInstance); | ||
} | ||
|
||
class CallContextNode with CallContextMixin implements CallContext { | ||
final js.JSCallableRequest nativeInstance; | ||
|
||
CallContextNode(this.nativeInstance); | ||
|
||
@override | ||
late final CallContextAuth? auth = CallContextAuthNode(nativeInstance); | ||
} | ||
|
||
class CallContextAuthNode with CallContextAuthMixin implements CallContextAuth { | ||
final js.JSCallableRequest nativeInstance; | ||
|
||
CallContextAuthNode(this.nativeInstance); | ||
|
||
@override | ||
String? get uid => nativeInstance.auth.uid; | ||
|
||
@override | ||
DecodedIdToken? get token { | ||
return impl.DecodedIdTokenNode(nativeInstance.auth.token); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
functions_node/lib/src/node/firebase_functions_https_node.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import 'dart:async'; | ||
import 'dart:js_interop' as js; | ||
|
||
import 'package:tekartik_firebase_functions/firebase_functions.dart'; | ||
import 'package:tekartik_firebase_functions_node/src/node/firebase_functions_https_node_js_interop.dart' | ||
as node; | ||
|
||
import 'call_request_node.dart'; | ||
import 'express_http_request_node.dart'; | ||
import 'firebase_functions_node.dart'; | ||
|
||
class HttpsFunctionsNode | ||
with HttpsFunctionsDefaultMixin | ||
implements HttpsFunctions { | ||
final FirebaseFunctionsNode functions; | ||
final node.JSHttpsFunctions nativeInstance; | ||
|
||
HttpsFunctionsNode(this.functions, this.nativeInstance); | ||
|
||
@override | ||
HttpsFunction onRequest(RequestHandler handler, | ||
{HttpsOptions? httpsOptions}) { | ||
void handleRequest( | ||
node.JSHttpsRequest request, node.JSHttpsResponse response) { | ||
var expressRequest = ExpressHttpRequestNode(request, response); | ||
handler(expressRequest); | ||
} | ||
|
||
return HttpsFunctionNode( | ||
functions, | ||
nativeInstance.onRequest( | ||
options: toNodeHttpsOptionsOrNull(httpsOptions), | ||
handler: handleRequest)); | ||
} | ||
|
||
@override | ||
HttpsCallableFunction onCall(CallHandler handler, | ||
{HttpsCallableOptions? callableOptions}) { | ||
FutureOr<Object?> handleCall(node.JSCallableRequest request) { | ||
var requestNode = CallRequestNode(request); | ||
return handler(requestNode); | ||
} | ||
|
||
return HttpsCallableFunctionNode( | ||
functions, | ||
nativeInstance.onCall( | ||
options: toNodeCallableOptionsOrNull(callableOptions), | ||
handler: handleCall)); | ||
} | ||
} | ||
|
||
class HttpsFunctionNode extends FirebaseFunctionNode implements HttpsFunction { | ||
@override | ||
final node.JSHttpsFunction nativeInstance; | ||
|
||
HttpsFunctionNode(super.firebaseFunctionsNode, this.nativeInstance); | ||
} | ||
|
||
class HttpsCallableFunctionNode extends FirebaseFunctionNode | ||
implements HttpsCallableFunction { | ||
@override | ||
final node.JSCallableFunction nativeInstance; | ||
|
||
HttpsCallableFunctionNode(super.firebaseFunctionsNode, this.nativeInstance); | ||
} | ||
|
||
node.JSHttpsOptions? toNodeHttpsOptionsOrNull(HttpsOptions? httpsOptions) { | ||
if (httpsOptions == null) { | ||
return null; | ||
} | ||
return toNodeHttpsOptions(httpsOptions); | ||
} | ||
|
||
node.JSHttpsOptions toNodeHttpsOptions(HttpsOptions httpsOptions) { | ||
return node.JSHttpsOptions( | ||
region: httpsOptions.region, cors: httpsOptions.cors?.toJS); | ||
} | ||
|
||
node.JSCallableOptions? toNodeCallableOptionsOrNull( | ||
HttpsCallableOptions? callableOptions) { | ||
if (callableOptions == null) { | ||
return null; | ||
} | ||
return toNodeCallableOptions(callableOptions); | ||
} | ||
|
||
node.JSCallableOptions toNodeCallableOptions( | ||
HttpsCallableOptions callableOptions) { | ||
return node.JSCallableOptions( | ||
consumeAppCheckToken: callableOptions.consumeAppCheckToken, | ||
enforceAppCheck: callableOptions.enforceAppCheck, | ||
region: callableOptions.region, | ||
cors: callableOptions.cors?.toJS); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters