|
| 1 | +This document is part of [Generic toolkit for server and web applications](README.md). |
| 2 | + |
| 3 | +# APPLICATION TEMPLATES |
| 4 | + |
| 5 | + |
| 6 | +App templates based on HDS Model, provide frameworks to build applications for HDS. |
| 7 | + |
| 8 | +- **AppManagingAccount**: App which manages Collectors. A "Collector" handles a "Request" and set of "Responses". => With access to some HDS data from other accounts. |
| 9 | +- **AppClientAccount**: Handles requests from `AppManagingAccount` and corresponding responses (agree, refuse, revoke). |
| 10 | + |
| 11 | +## Application class |
| 12 | +Both templates extend `Application` class |
| 13 | + |
| 14 | +An application is based on |
| 15 | +- one `connection`: an instance of `pryv.Connection` |
| 16 | +- one `baseStreamId`: the streamId where the application will store its own operation data (i.e. state management) - This stream should be a children of stream `applications`. |
| 17 | +- one `appName` |
| 18 | + |
| 19 | +### instantiating an Application |
| 20 | +Either use: |
| 21 | +- `App{ExtensionName}.newFromApiEndpoint(baseStreamId, apiEndpoint, appName)` |
| 22 | +- `App{ExtensionName}.newFromConnection(baseStreamId, connection, appName)` |
| 23 | + |
| 24 | +It will return an instance already initialized with eventual necessary streams created. |
| 25 | + |
| 26 | +### extending Application class |
| 27 | +Check the code for mode details. |
| 28 | + |
| 29 | +## AppManagingAccount |
| 30 | + |
| 31 | +### instantiating |
| 32 | +Either use: |
| 33 | +- `AppManagingAccount.newFromApiEndpoint(baseStreamId, apiEndpoint, appName)` |
| 34 | +- `AppManagingAccount.newFromConnection(baseStreamId, connection, appName)` |
| 35 | + |
| 36 | +Params: |
| 37 | +- **apiEndpoint or connection** must have `master` or `personnal` access rights. |
| 38 | + |
| 39 | +### appManagingAccount.getCollectors(); |
| 40 | +Get current `Collector` instances related to this app |
| 41 | + |
| 42 | +### appManagingAccount.getCollectorById(); |
| 43 | +Get one `Collector`from its id. |
| 44 | + |
| 45 | +### appManagingAccount.createCollector(name) |
| 46 | +Create new `Collector` |
| 47 | + |
| 48 | + |
| 49 | +### AppManagingAccount Collectors class |
| 50 | +A collector is holding |
| 51 | +- A single request for accessing a set of streams |
| 52 | +- A set of `CollectorInvite` which are to be submitted to **clients** |
| 53 | + |
| 54 | +It has 3 possible states `draft`=> `active` => `deactivated` |
| 55 | + |
| 56 | +Collector instances are created and managed by AppManagingAccount. |
| 57 | + |
| 58 | +#### collector.id |
| 59 | +You may use this as a reference to retrieve a specific collector from an app |
| 60 | + |
| 61 | +#### collector.statusCode |
| 62 | +One of 'draft', 'active', 'deactivated' |
| 63 | + |
| 64 | +#### collector.statusData |
| 65 | +Payload that can be modified |
| 66 | + |
| 67 | +#### async collector.save() |
| 68 | +After modifying `collector.statusData` you should save it. |
| 69 | + |
| 70 | +#### async collector.publish() |
| 71 | +Once the edition is done and saved, validate and publish. (Can be done just once); |
| 72 | + |
| 73 | +#### async collector.getInvites() |
| 74 | +List of current invites |
| 75 | + |
| 76 | +#### async collector.checkInbox () |
| 77 | +Check if new 'accept', 'refuse', 'revoke' messages have been received. |
| 78 | + |
| 79 | +#### AppManagingAccount - CollectorInvite class |
| 80 | +A collector invite represents the state of a 1 - 1 relationship between a Collector => A User |
| 81 | +It's materialized by an `event` in one of the streams of the Collector |
| 82 | + |
| 83 | +`collectorInvite` instances are created and retrieved by `Collector` instances. |
| 84 | + |
| 85 | +##### collectorInvite.displayName() |
| 86 | +Returns the display name set at creation |
| 87 | + |
| 88 | + |
| 89 | +##### collectorInvite.getSharingData() |
| 90 | +When `pending` this will return an `apiEndpoint` and an `eventId` to be shared with a 3rd party app using `ApplicationClient`. This data will be consumed by `appclient.handleIncomingRequest(apiEndpoint, eventId)` to initiate the relationship. |
| 91 | + |
| 92 | +##### collectorInvite.status() |
| 93 | +Returns one of `pending`, `active`, `error`. |
| 94 | + |
| 95 | +In case of error, (meaning, means not accessible) the call `collectorInvite.errorType()` will return `revoked` or `refused`. |
| 96 | + |
| 97 | +##### collectorInvite.connection and collectorInvite.apiEndpoint |
| 98 | +As an invite is a 1 - 1 relationship, when active, it holds a connection to the matching account. |
| 99 | + |
| 100 | +#### collectorInvite.dateCreation() |
| 101 | +Returns a `Date`object. |
| 102 | + |
| 103 | +##### async collectorInvite.checkAndGetAccessInfo() |
| 104 | +Check if connection is valid. (only if active) |
| 105 | +If the result is "forbidden" update and set as revoked. |
| 106 | + |
| 107 | +Returns the `accessInfo` on success, which can be useful to get the hds username or other infos and the account. |
| 108 | + |
| 109 | +## AppClientAccount |
| 110 | + |
| 111 | +The counterpart of `AppManagingAccount` for "client" applications. |
| 112 | + |
| 113 | +### instantiating |
| 114 | +Either use: |
| 115 | +- `AppClientAccount.newFromApiEndpoint(baseStreamId, apiEndpoint, appName)` |
| 116 | +- `AppClientAccount.newFromConnection(baseStreamId, connection, appName)` |
| 117 | +### appClientAccount.handleIncomingRequest(apiEndpoint, incomingEventId) |
| 118 | +To be called when the app receives a new request issued by `AppManagingAccount's collectorInvite.getSharingData()`. Returns a `CollectorClient` instance. |
| 119 | + |
| 120 | +### appClientAccount.getCollectorClients() |
| 121 | +Get current `CollectorClient` instances. |
| 122 | + |
| 123 | +### appClientAccount.getCollectorClientByKey(collectorKey) |
| 124 | +Get a specific `CollectorClient` instance. |
| 125 | + |
| 126 | +### CollectorClient class |
| 127 | + |
| 128 | +#### collectorClient.key |
| 129 | +Identifier to retrieve a collector from appClientAccount. |
| 130 | + |
| 131 | +#### collectorClient.status |
| 132 | +One of 'Incoming', 'Active', 'Deactivated', 'Refused' |
| 133 | + |
| 134 | +#### collectorClient.requestData |
| 135 | +The data holding the requestFrom the invite |
| 136 | + |
| 137 | +#### collectorClient.accept() |
| 138 | +Accept current request |
| 139 | + |
| 140 | +#### collectorClient.revoke() |
| 141 | +Revoke current request |
| 142 | + |
| 143 | +#### collectorClient.refuse() |
| 144 | +Refuse current request |
0 commit comments