-
Notifications
You must be signed in to change notification settings - Fork 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
Handlers and Endpoints for Mojaloop/App/Firebase - Linking/Unlinking Flow #24
Merged
Merged
Changes from all commits
Commits
Show all changes
123 commits
Select commit
Hold shift + click to select a range
c6c2dfd
feat: Handler logic for put participants
akapur99 df32e0f
Merge remote-tracking branch 'origin/master' into consentRequest
akapur99 edccad0
feat: add outgoing postConsentRequests method in Client
akapur99 deacbbb
feat: create consents Handler
akapur99 0f17193
refactor: fix spelling error in getConsentByID
akapur99 4fb2e87
feat: Add consentHandlers as default export
akapur99 5dbc21c
feat: initialize consent handler in firestore
akapur99 ed87a49
feat: add method to updateConsentById
akapur99 fe77c44
feat: add updateConsentById method to interface
akapur99 667363f
feat: Add method to handle creation of consent
akapur99 a35716e
feat: implement handler for PUT consentRequests/{ID}
akapur99 858aec4
feat: implement postConsent handler
akapur99 c7f83a2
fix: status should not be taken from request body
akapur99 d51fbe8
feat: create ConsentStatus enum and add field to consent object
akapur99 67c8df5
feat: allow consent status to be undefined(on creation)
akapur99 c4cfd8d
Merge remote-tracking branch 'origin/master' into consentRequest
akapur99 b481c5f
feat: Add update consent method to consent repository
akapur99 0d389e6
feat: implement handler for PUT parties/{Type}/{ID}
akapur99 ff99ecb
feat: Implement handler for PATCH consents/{ID}
akapur99 6466f1e
feat: implement PUT consents/{ID}
akapur99 ea4fa3a
feat: add methods to consent Handler
akapur99 2cf4491
feat: Add/update ConsentStatus enum
akapur99 8447762
feat: implement all linking related firestore handlers
akapur99 bf7d3c8
feat: Use ConsentStatus enum instead of hardcoding value
akapur99 49812bb
fix: Correct ConsentStatus Enum used
akapur99 a20f0dc
feat: Add/Update handlers in index
akapur99 9a49e03
feat: Implement app-side handler for DELETE consents/{ID}
akapur99 ba3ed53
style: updating licence
akapur99 6c28ba5
feat: add consent validator for firestore handlers
akapur99 15e7a60
refactor: remove postConsentRequests method - implemented in separate PR
akapur99 1639024
fix: Corrected validator method descriptions and updated validator me…
akapur99 3946c48
chore: linting fix
akapur99 8920d44
feat: Create participant repository and implement replace method
akapur99 ad2a59a
feat: implement PUT participants Handler
akapur99 62c3735
fix: add non-null assertions
akapur99 d989d75
chore: bump sdk-standard-components to 11.3.1 + audit fix
akapur99 de20706
fix: add non-null assertions
akapur99 e7d481a
fix: Incorrect handler type + method names + unneeded import
akapur99 c4f54b5
fix: add casting to avoid typescript errors
akapur99 9a872e2
Merge remote-tracking branch 'origin/master' into consentRequest
akapur99 b7102ea
Merge remote-tracking branch 'origin/master' into consentRequest
akapur99 a12c673
feat: Following unlinking diagram update, implement unlinking using f…
akapur99 c72cf12
docs: Added patchConsentsById to yaml files
akapur99 617b344
fix: necessary casting
akapur99 3e1d334
fix: add checks to validator for fspId
akapur99 9d3517f
fix: misc small merge conflict issues
akapur99 7a0136d
fix: accessing from request instead of context
akapur99 6054299
test: Unit tests for PUT participants
akapur99 a084124
test: Unit Test for POST consents handler
akapur99 9b4fa2a
test: Unit tests for PUT/PATCH consents/{ID}
akapur99 742b057
fix: Necessary casting
akapur99 de99659
fix: Correct test description
akapur99 8e3bb4b
refactor: using variables instead of harcoding ID
akapur99 3442dc5
fix: Correct extraction of ID from request params
akapur99 2d267af
test: Unit test for PUT consentRequests/{ID} handler
akapur99 c6db888
docs: adding comment justifying design decision
akapur99 4e383a9
feat: add callbackUri to config
akapur99 5b901da
refactor: Replace callbackUri values with config callbackUri
akapur99 7cd1b37
chore: bumped sdk-standard-components + central-services shared
akapur99 2362262
fix: Correct capitalization in context.request.params.ID
akapur99 e0e837e
fix: Correct types used in participant repository
akapur99 b07ee42
fix: Use correct types within Participant repository methods
akapur99 5b145d9
feat: Add OPAQUE to PartyIdType enum
akapur99 3bdb3d4
style: remove unneeded TODO comment
akapur99 c56f7a1
refactor: Add needed imports + switch to using enum over strings
akapur99 d86d39f
test: Add unit tests for consents firestore handlers
akapur99 e638cab
test: Ignore testing for src/shared/ml-thirdparty-client/models/core/…
akapur99 cb78424
fix: Checks for fspId in party
akapur99 cc55900
test: refactor to improve test readability and add structure
akapur99 af6e3af
test: add unit tests for consent validators
akapur99 edaa067
test: Add unit tests for error cases + refactor mocking for clarity
akapur99 7e76707
chore: bump @mojaloop/sdk-standard-components version to 11.5.1
akapur99 253eebb
refactor: switch to sdk-standard-components logger for mojaloop client
akapur99 a51a5c4
chore: Remove unneeded TODOs and comments
akapur99 09e3377
fix: Add error handling + remove unneeded comments
akapur99 b31fce9
test: Add logger mocking and implement tests for client error
akapur99 e4ae20b
fix: linter warnings
akapur99 21d7cb2
feat: Add flags to ignore testing for repository and factory methods
akapur99 64b590a
refactor: Change ConsentStatus enum values according to linking diagrams
akapur99 52dfc39
test: Add unit tests for firestore consent handlers
akapur99 60113d4
Update src/repositories/consent.ts
akapur99 544d991
refactor: Remove disabling of any type and replace any with unknown i…
akapur99 0d1d3e4
feat: Updated ambient.d.ts
akapur99 64ce4b6
refactor: Use enums when referencing http codes + update responseTool…
akapur99 eae71de
Merge remote-tracking branch 'origin/master' into consentRequest
akapur99 a54c40e
feat: update ambient.d.ts
akapur99 c3e5940
feat: utilize new error classes
akapur99 d33bacc
fix: remove incorrect declaration
akapur99 944f0a5
fix: change any to unknown type
akapur99 c7992b1
refactor: undo previous changes
akapur99 1b7e717
fix: Remove unnecessary `await` usage
akapur99 bcea9d0
fix: Declaration and import issues in ambient.d.ts
akapur99 32bd566
feat: Create declarations.d.ts file and add to tsconfig
akapur99 34caefc
chore: bump sdk-standard-components to v 11.5.2 + audit fix
akapur99 a2e268c
Merge remote-tracking branch 'origin/master' into consentRequest
akapur99 363e0c7
refactor: firestore consent handlers - to follow new StateServer inte…
akapur99 165439e
refactor: tests and files to follow new ambient declaration of StateS…
akapur99 dd63e63
Revert "feat: Create declarations.d.ts file and add to tsconfig"
akapur99 5f037ed
refactor: Use optional chaining in validators and merge 2 identical m…
akapur99 a0b02f2
chore: bump sdk-standard-components to v11.5.3
akapur99 75bff6f
style: modify TODO comment
akapur99 42d38a0
refactor: Replace unneeded type casting with non-null assertion
akapur99 dda5baa
refactor: Change name of callbackUri in config to pispCallbackUri
akapur99 1753903
chore: Add flags to ignore BDD testing which is covered in separate t…
akapur99 f8217a9
feat: Throw InvalidConsentStatus Error if default case reached in fir…
akapur99 b4af4fb
refactor: removed unneeded extra variable
akapur99 6a58745
refactor: Remove request logging for handlers which have been impleme…
akapur99 4fd24e6
fix: REplace any type with unknown
akapur99 d14415b
fix: remove ts-ignore
akapur99 7072fc0
feat: Add consent ID to invalidConsentStatusError for clarity
akapur99 e36cdeb
style: Add comments explaining decision to not await async code
akapur99 69f4718
refactor: Change method names to more accurately reflect function
akapur99 501af91
refactor: awaiting batch commits in repositories
akapur99 a5a8874
chore: bump sdk standard components to v 11.8.0
akapur99 0e2a6f5
fix: Make id a required variable for InvalidConsentStatusError
akapur99 ca24cbe
refactor: Use try/catch instead of .then/.catch for promise handling …
akapur99 143777b
Merge remote-tracking branch 'origin/master' into consentRequest
akapur99 c52584d
style: remove redundant comment
akapur99 06a21b4
build: Bump sdk-standard-components to v11.9.0
akapur99 30f7fb7
feat: Implement getParties request in mojaloopClient
akapur99 a370b25
Merge remote-tracking branch 'origin/master' into consentRequest
akapur99 a201c95
style: modified TODO comment
akapur99 38de745
fix: removed unneeded comments
akapur99 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
|
||
- Steven Wijaya <[email protected]> | ||
- Abhimanyu Kapur <[email protected]> | ||
-------------- | ||
******/ | ||
|
||
|
@@ -40,22 +41,37 @@ export enum ConsentStatus { | |
* Waiting for the user to confirm payee information and provide more | ||
* details about the transaction. | ||
*/ | ||
PENDING_PAYEE_CONFIRMATION = 'PENDING_PAYEE_CONFIRMATION', | ||
PENDING_PARTY_CONFIRMATION = 'PENDING_PARTY_CONFIRMATION', | ||
eoln marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Waiting for the user to authorize the consent. | ||
*/ | ||
AUTHORIZATION_REQUIRED = 'AUTHORIZATION_REQUIRED', | ||
AUTHENTICATION_REQUIRED = 'AUTHENTICATION_REQUIRED', | ||
akapur99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* The consent is authorized and active. | ||
* The consent is granted and active. | ||
*/ | ||
CONSENT_GRANTED = 'CONSENT_GRANTED', | ||
|
||
/** | ||
* The consent is ACTIVE and challenge has been generated | ||
*/ | ||
CHALLENGE_GENERATED = 'CHALLENGE_GENERATED', | ||
|
||
/** | ||
* The consent is ACTIVE and challenge has been verified | ||
*/ | ||
ACTIVE = 'ACTIVE', | ||
|
||
/** | ||
* The consent is revoked and no longer valid. | ||
*/ | ||
REVOKED = 'REVOKED', | ||
|
||
/** | ||
* The consent is requested to be revoked for unlinking. | ||
*/ | ||
REVOKE_REQUESTED = 'REVOKE_REQUESTED', | ||
} | ||
|
||
export interface Consent { | ||
|
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 |
---|---|---|
|
@@ -19,27 +19,47 @@ | |
- Name Surname <[email protected]> | ||
|
||
- Steven Wijaya <stevenwjy@google.com> | ||
- Abhimanyu Kapur <abhi.kapur09@gmail.com> | ||
-------------- | ||
******/ | ||
|
||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* istanbul ignore file */ | ||
// TODO: BDD Testing will covered in separate ticket #1702 | ||
|
||
import firebase from '~/lib/firebase' | ||
import { Consent } from '~/models/consent' | ||
import { logger } from '~/shared/logger' | ||
|
||
export interface IConsentRepository { | ||
/** | ||
* Updates a consent document based on a unique identifier. | ||
* | ||
* @param id Id for the consent document that needs to be updated. | ||
* @param data Document fields that are about to be updated. | ||
*/ | ||
updateConsentById(id: string, data: Record<string, unknown>): Promise<void> | ||
akapur99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Retrieves a consent document based on its consent ID. | ||
* | ||
* @param id Consent ID of the document that needs to be retrieved. | ||
*/ | ||
getByConsentId(id: string): Promise<Consent> | ||
getConsentById(id: string): Promise<Consent> | ||
|
||
/** | ||
* Updates one or more consent documents based on the given conditions. | ||
* | ||
* @param conditions Conditions for the documents that need to be updated. | ||
* @param data Document fields that are about to be updated. | ||
*/ | ||
updateConsent( | ||
conditions: Record<string, unknown>, | ||
data: Record<string, unknown> | ||
eoln marked this conversation as resolved.
Show resolved
Hide resolved
|
||
): Promise<void> | ||
} | ||
|
||
export class FirebaseConsentRepository implements IConsentRepository { | ||
async getByConsentId(id: string): Promise<Consent> { | ||
async getConsentById(id: string): Promise<Consent> { | ||
return new Promise((resolve, reject) => { | ||
firebase | ||
.firestore() | ||
|
@@ -58,6 +78,51 @@ export class FirebaseConsentRepository implements IConsentRepository { | |
}) | ||
}) | ||
} | ||
|
||
async updateConsentById( | ||
id: string, | ||
data: Record<string, unknown> | ||
): Promise<void> { | ||
await firebase.firestore().collection('consents').doc(id).update(data) | ||
} | ||
|
||
async updateConsent( | ||
conditions: Record<string, unknown>, | ||
data: Record<string, unknown> | ||
): Promise<void> { | ||
try { | ||
let firestoreQuery: FirebaseFirestore.Query = firebase | ||
.firestore() | ||
.collection('consents') | ||
|
||
// Chain all of the given conditions to the query | ||
for (const key in conditions) { | ||
firestoreQuery = firestoreQuery.where(key, '==', conditions[key]) | ||
} | ||
|
||
// Find and update all matching documents in Firebase that match the given conditions. | ||
const response = await firestoreQuery.get() | ||
// Create a batch to perform all of the updates using a single request. | ||
// Firebase will also execute the updates atomically according to the | ||
// API specification. | ||
const batch = firebase.firestore().batch() | ||
|
||
// Iterate through all matching documents add them to the processing batch. | ||
response.docs.forEach((doc) => { | ||
batch.update( | ||
// Put a reference to the document. | ||
firebase.firestore().collection('consents').doc(doc.id), | ||
// Specify the updated fields and their new values. | ||
data | ||
) | ||
}) | ||
|
||
// Commit the updates. | ||
await batch.commit() | ||
} catch (error) { | ||
logger.error(error) | ||
} | ||
} | ||
} | ||
|
||
export const consentRepository: IConsentRepository = new FirebaseConsentRepository() |
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,78 @@ | ||
/***** | ||
License | ||
-------------- | ||
Copyright © 2020 Mojaloop Foundation | ||
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the 'License') and you may not use these files except in compliance with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
Contributors | ||
-------------- | ||
This is the official list of the Mojaloop project contributors for this file. | ||
Names of the original copyright holders (individuals or organizations) | ||
should be listed with a '*' in the first column. People who have | ||
contributed from an organization can be listed under the organization | ||
that actually holds the copyright for their contributions (see the | ||
Mojaloop Foundation organization for an example). Those individuals should have | ||
their names indented and be marked with a '-'. Email address can be added | ||
optionally within square brackets <email>. | ||
* Mojaloop Foundation | ||
- Name Surname <[email protected]> | ||
|
||
- Steven Wijaya <[email protected]> | ||
- Abhimanyu Kapur <[email protected]> | ||
-------------- | ||
******/ | ||
|
||
/* istanbul ignore file */ | ||
// TODO: BDD Testing will covered in separate ticket #1702 | ||
|
||
import firebase from '~/lib/firebase' | ||
import { logger } from '~/shared/logger' | ||
import { Participant } from '~/shared/ml-thirdparty-client/models/core' | ||
|
||
export interface IParticipantRepository { | ||
/** | ||
* Replace existing participants list with new list. | ||
* | ||
* @param data Documents that are about to be added. | ||
*/ | ||
replace(data: Participant[]): Promise<void> | ||
} | ||
|
||
export class FirebaseParticipantRepository implements IParticipantRepository { | ||
async replace(data: Participant[]): Promise<void> { | ||
try { | ||
const collectionRef: FirebaseFirestore.CollectionReference<FirebaseFirestore.DocumentData> = firebase | ||
.firestore() | ||
.collection('participants') | ||
|
||
const response = await collectionRef.get() | ||
// Create a batch to perform all of the updates using a single request. | ||
// Firebase will also execute the updates atomically according to the | ||
// API specification. | ||
const batch = firebase.firestore().batch() | ||
|
||
const batchSize = response.size | ||
if (batchSize > 0) { | ||
// If previous participants list exists, delete it | ||
|
||
// Iterate through all matching documents add them to the processing batch. | ||
response.docs.forEach((doc) => { | ||
batch.delete(doc.ref) | ||
}) | ||
} | ||
// Iterate through received participants list and add them to the processing batch. | ||
data.forEach((participant: Participant) => { | ||
batch.set(collectionRef.doc(), participant) | ||
}) | ||
|
||
// Commit the updates. | ||
await batch.commit() | ||
} catch (error) { | ||
logger.error(error) | ||
} | ||
} | ||
} | ||
|
||
export const participantRepository: IParticipantRepository = new FirebaseParticipantRepository() |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't it better to take this interface from api-snippets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I think it would be better that way! :-)
iirc, the current dependency still points to my forked repo (because it was set before the
api-snippets
was published), probably can fix that as wellThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sense - I'll make a separate ticket for that - separation of concerns