Skip to content

Commit b59f8b1

Browse files
committed
changes due tu to first implementation
1 parent b454178 commit b59f8b1

9 files changed

Lines changed: 61 additions & 30 deletions

File tree

docs/hds-lib.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/hds-lib.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/appTemplates/AppClientAccount.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class AppClientAccount extends Application {
2828
* @param {string} [incomingEventId] - Information for the recipient
2929
*/
3030
async handleIncomingRequest (apiEndpoint, incomingEventId) {
31+
// make sure that collectorClientsMap is initialized
32+
// await this.getCollectorClients();
33+
3134
const requesterConnection = new pryv.Connection(apiEndpoint);
3235
const accessInfo = await requesterConnection.accessInfo();
3336
// check if request is known

src/appTemplates/AppManagingAccount.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,26 @@ class AppManagingAccount extends Application {
3939
}
4040

4141
async getCollectors (forceRefresh) {
42-
if (!forceRefresh && this.cache.collectorsMap) return Object.values(this.cache.collectorsMap);
43-
// Collectors are materialized by streams
42+
await this.#updateCollectorsIfNeeded(forceRefresh);
43+
return Object.values(this.cache.collectorsMap);
44+
}
45+
46+
async getCollectorById (id) {
47+
await this.#updateCollectorsIfNeeded();
48+
return this.cache.collectorsMap[id];
49+
}
50+
51+
async #updateCollectorsIfNeeded (forceRefresh = false) {
52+
if (!forceRefresh && this.cache.collectorsMap) return;
4453
if (forceRefresh) await this.loadStreamData();
54+
// TODO do not replace the map, but update collectors if streamData has changed and add new collectors
4555
const streams = this.streamData.children || [];
4656
const collectorsMap = {};
4757
for (const stream of streams) {
4858
const collector = new Collector(this, stream);
49-
collectorsMap[collector.streamId] = collector;
59+
collectorsMap[collector.id] = collector;
5060
}
5161
this.cache.collectorsMap = collectorsMap;
52-
return Object.values(this.cache.collectorsMap);
5362
}
5463

5564
/**

src/appTemplates/Application.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async function createAppStreams (app) {
129129
const streamData = await app.loadStreamData();
130130
if (streamData) found = true;
131131
} catch (e) {
132-
if (e.innerObject?.id !== 'unknown-referenced-resource' || e.innerObject?.data?.id !== 'test-app-template-client') {
132+
if (e.innerObject?.id !== 'unknown-referenced-resource' || e.innerObject?.data?.id !== app.baseStreamId) {
133133
throw e;
134134
}
135135
}

src/appTemplates/Collector.js

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,26 @@ class Collector {
4848
}
4949

5050
/**
51-
* @property {string} one of 'draft', 'active', 'deactivated'
51+
* @property {string} id - shortcut for steamid
5252
*/
53-
get statusCode () {
54-
if (this.#cache.status == null) throw new Error('Init Collector first');
55-
return this.#cache.status.content.status;
53+
get id () {
54+
return this.streamId;
5655
}
5756

58-
/**
59-
* @typedef {RequestContent}
60-
* @property {number} version
61-
* @property {Localizable} description
62-
* @property {Localizable} consent
63-
* @property {Array<Permission>} permissions - Like Pryv permission request
64-
* @property {Object} app
65-
* @property {String} app.id
66-
* @property {String} app.url
67-
* @property {Object} app.data - to be finalized
68-
*/
69-
70-
/**
71-
* @typedef {StatusData}
72-
* @property {RequestContent} requestContent
73-
*/
74-
7557
/** @type {StatusData} */
7658
get statusData () {
7759
if (this.#cache.status == null) throw new Error('Init Collector first');
7860
return this.#cache.status.content.data;
7961
}
8062

63+
/**
64+
* @property {string} one of 'draft', 'active', 'deactivated'
65+
*/
66+
get statusCode () {
67+
if (this.#cache.status == null) throw new Error('Init Collector first');
68+
return this.#cache.status.content.status;
69+
}
70+
8171
/**
8272
* Fetch online data
8373
*/
@@ -159,6 +149,11 @@ class Collector {
159149
return this.#cache.invites[key];
160150
}
161151

152+
/**
153+
* Retreive all invites
154+
* @param {boolean} [forceRefresh]
155+
* @returns {Array<CollectorInvite>}
156+
*/
162157
async getInvites (forceRefresh = false) {
163158
while (this.#cache.invitesInitializing) (await new Promise((resolve) => { setTimeout(resolve, 100); }));
164159
this.#cache.invitesInitializing = true;
@@ -352,3 +347,20 @@ class Collector {
352347
}
353348

354349
module.exports = Collector;
350+
351+
/**
352+
* @typedef {RequestContent}
353+
* @property {number} version
354+
* @property {Localizable} description
355+
* @property {Localizable} consent
356+
* @property {Array<Permission>} permissions - Like Pryv permission request
357+
* @property {Object} app
358+
* @property {String} app.id
359+
* @property {String} app.url
360+
* @property {Object} app.data - to be finalized
361+
*/
362+
363+
/**
364+
* @typedef {StatusData}
365+
* @property {RequestContent} requestContent
366+
*/

src/appTemplates/CollectorInvite.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class CollectorInvite {
3535
return this.eventData.content.apiEndpoint;
3636
}
3737

38+
get dateCreation () {
39+
return new Date(this.eventData.created * 1000);
40+
}
41+
3842
get connection () {
3943
if (this.#connection == null) {
4044
this.#connection = new pryv.Connection(this.apiEndpoint);

src/appTemplates/appTemplates.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const AppManagingAccount = require('./AppManagingAccount');
2+
const AppClientAccount = require('./AppClientAccount');
23

34
module.exports = {
4-
AppManagingAccount
5+
AppManagingAccount,
6+
AppClientAccount
57
};

tests/apptemplates.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,12 @@ describe('[APTX] appTemplates', function () {
118118
const collectors2 = await appManaging2.getCollectors();
119119
const collector2 = collectors2.find(c => c.name === collectorName);
120120
if (!collector2) throw new Error('Should find collector with name: ' + collectorName);
121+
// init collector found;
122+
await collector2.init();
121123
// call of StreamStructure should be empty as already created
122124
const resultCheckStructure3 = await collector2.checkStreamStructure();
123125
assert.equal(resultCheckStructure3.created.length, 0, 'Should create 0 streams');
124126
// should return the same access access point
125-
await collector2.init();
126127
const sharingApiEndpoint3 = await collector2.sharingApiEndpoint();
127128
assert.equal(sharingApiEndpoint3, sharingApiEndpoint);
128129
});

0 commit comments

Comments
 (0)