@enbox/api 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,44 +0,0 @@
1
- import { getRecordAuthor } from '@enbox/agent';
2
- import type { DwnRecordSubscriptionHandler, PermissionsApi, Web5Agent } from '@enbox/agent';
3
-
4
- import { Record } from './record.js';
5
- import type { RecordsSubscribeRequest } from './dwn-api.js';
6
-
7
- /**
8
- * Utility class for dealing with subscriptions.
9
- */
10
- export class SubscriptionUtil {
11
- /**
12
- * Creates a record subscription handler that can be used to process incoming {Record} messages.
13
- */
14
- static recordSubscriptionHandler({ agent, connectedDid, request, delegateDid, protocolRole, permissionsApi }:{
15
- agent: Web5Agent;
16
- connectedDid: string;
17
- delegateDid?: string;
18
- protocolRole?: string;
19
- permissionsApi?: PermissionsApi;
20
- request: RecordsSubscribeRequest;
21
- }): DwnRecordSubscriptionHandler {
22
- const { subscriptionHandler, from: remoteOrigin } = request;
23
-
24
- return async (event) => {
25
- const { message, initialWrite } = event;
26
- const author = getRecordAuthor(message);
27
- const recordOptions = {
28
- author,
29
- connectedDid,
30
- remoteOrigin,
31
- initialWrite
32
- };
33
-
34
- const record = new Record(agent, {
35
- ...message,
36
- ...recordOptions,
37
- protocolRole,
38
- delegateDid: delegateDid,
39
- }, permissionsApi);
40
-
41
- subscriptionHandler(record);
42
- };
43
- }
44
- }