-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add server sent events module (#176)
* feat: add option to get an auth token * feat: implement the sse module * feat: add config * feat: add the eventsource library * chore: simplify connection strings * chore: deprecation comment * chore: more precise comments * chore: more developer options * chore: add dev sse server * fix: correct routes * chore: move syncer init down * feat: enable sse for the connector * feat: update local backbone connection * chore: add script to establish a relationship * feat: run sync * chore: move listener * feat: add override for local development * chore: update lockfile * fix: close infrastructure in dev-mode if runtime was not able to start correctly * chore: rename variable * feat: restructure / resolve todos * chore: wording * chore: remove checked in stuff * chore: add task for clearing only connectors * refactor: move baseUrlOverride to config * chore: bump backbone * chore: downgrade * chore: rm TODO * chore: remove local sse impl --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
d957428
commit dab8bde
Showing
15 changed files
with
254 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
# required - the information below is used to connect to the backbone | ||
transportLibrary__baseUrl="http://localhost:8090" | ||
transportLibrary__baseUrl="http://host.docker.internal:8090" | ||
transportLibrary__platformClientId="test" | ||
transportLibrary__platformClientSecret="test" | ||
|
||
modules__sse__enabled=true | ||
modules__sse__baseUrlOverride="http://host.docker.internal:8092" |
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
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,67 @@ | ||
import { sleep } from "@js-soft/ts-utils"; | ||
import { ConnectorClient, ConnectorRelationshipStatus } from "@nmshd/connector-sdk"; | ||
|
||
async function run() { | ||
const connector1 = ConnectorClient.create({ | ||
baseUrl: "http://localhost:3000", | ||
apiKey: "xxx" | ||
}); | ||
|
||
const connector2 = ConnectorClient.create({ | ||
baseUrl: "http://localhost:3001", | ||
apiKey: "xxx" | ||
}); | ||
|
||
const { connector1Address, connector2Address } = await establishOrReturnRelationship(connector1, connector2); | ||
|
||
while (true) { | ||
await connector1.messages.sendMessage({ recipients: [connector2Address], content: {} }); | ||
await sleep(2000); | ||
|
||
await connector2.messages.sendMessage({ recipients: [connector1Address], content: {} }); | ||
await sleep(2000); | ||
} | ||
} | ||
|
||
async function establishOrReturnRelationship(connector1: ConnectorClient, connector2: ConnectorClient) { | ||
const identityInfo = (await connector1.account.getIdentityInfo()).result; | ||
|
||
const relationships = (await connector1.relationships.getRelationships()).result; | ||
|
||
if (relationships.length > 0) { | ||
if (relationships[0].status === ConnectorRelationshipStatus.PENDING) { | ||
await connector1.relationships.acceptRelationshipChange(relationships[0].id, relationships[0].changes[0].id); | ||
} | ||
|
||
return { | ||
connector1Address: identityInfo.address, | ||
connector2Address: relationships[0].peer | ||
}; | ||
} | ||
|
||
const template = (await connector1.relationshipTemplates.createOwnRelationshipTemplate({ expiresAt: "2099", maxNumberOfAllocations: 1, content: {} })).result; | ||
|
||
await connector2.relationshipTemplates.loadPeerRelationshipTemplate({ reference: template.truncatedReference }); | ||
|
||
const relationship = (await connector2.relationships.createRelationship({ templateId: template.id, content: {} })).result; | ||
|
||
await connector1.account.sync(); | ||
|
||
const accepted = (await connector1.relationships.acceptRelationshipChange(relationship.id, relationship.changes[0].id)).result; | ||
console.log(accepted); | ||
|
||
await connector2.account.sync(); | ||
|
||
return { | ||
connector1Address: identityInfo.address, | ||
connector2Address: accepted.peer | ||
}; | ||
} | ||
|
||
run() | ||
.then(() => { | ||
console.log("Script finished successfully"); | ||
}) | ||
.catch((error) => { | ||
console.error("Script failed with error", error); | ||
}); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Oops, something went wrong.