-
Notifications
You must be signed in to change notification settings - Fork 0
feat: adds user identification functionality #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
94791f7
feat: adds user identification functions
pandeymangg 999a922
fix: apply dart format and update playground test for wired identity …
pandeymangg 384a654
fix(update-queue): clear pending buffer in finally so a throwing flus…
pandeymangg 2b40420
test(user): stub API client so debounced flushes stay hermetic
pandeymangg 57270ab
addresses feedback
pandeymangg a66ed53
fixes feedback
pandeymangg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,48 @@ | ||
| /// Contact attributes: `setAttributes` and `setLanguage`. | ||
| /// | ||
| /// Ports the RN `lib/user/attribute.ts`. The backend infers each attribute's | ||
| /// type from the JSON value type, so values cross the wire with their natural | ||
| /// type: `String` stays a string, `num` stays a number, and `DateTime` is | ||
| /// converted to an ISO-8601 string at this one boundary (plan §7 #4). | ||
| library; | ||
|
|
||
| import 'dart:async'; | ||
|
|
||
| import '../common/result.dart'; | ||
| import '../types/errors.dart'; | ||
| import 'update_queue.dart'; | ||
|
|
||
| /// Sets [attributes] on the current user/contact. | ||
| /// | ||
| /// `DateTime` values become UTC ISO-8601 strings; `num` and `String` values are | ||
| /// passed through unchanged. Queues the change through the debounced | ||
| /// [UpdateQueue] and returns `Ok` immediately (the network call, and any | ||
| /// no-userId error, surface from the queue's flush). | ||
| Future<Result<void, FormbricksError>> setAttributes( | ||
| Map<String, Object?> attributes, { | ||
| UpdateQueue? queue, | ||
| }) async { | ||
| final normalized = <String, Object?>{}; | ||
| attributes.forEach((key, value) { | ||
| normalized[key] = | ||
| value is DateTime ? value.toUtc().toIso8601String() : value; | ||
| }); | ||
|
|
||
| final q = queue ?? UpdateQueue.instance; | ||
| q.updateAttributes(normalized); | ||
| // Fire-and-forget: the flush already logs and recovers from failures (e.g. | ||
| // MissingFieldError), so swallow here to keep it off the host's unhandled- | ||
| // error path. Tests await processUpdates() directly and still see the error. | ||
| unawaited(q.processUpdates().catchError((_) {})); | ||
| return const Result.ok(null); | ||
| } | ||
|
|
||
| /// Sets the contact's preferred [language]. | ||
| /// | ||
| /// Routes through [setAttributes] exactly as RN does — this is what makes the | ||
| /// "language without a userId updates local config only" path reachable. | ||
| Future<Result<void, FormbricksError>> setLanguage( | ||
| String language, { | ||
| UpdateQueue? queue, | ||
| }) => | ||
| setAttributes({'language': language}, queue: queue); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.