gdc-common-utils-ts 1.1.0 → 1.2.0

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.
@@ -29,6 +29,18 @@ export interface DataEntry {
29
29
  claims: any;
30
30
  };
31
31
  }
32
+ /**
33
+ * DIDComm attachment structure.
34
+ */
35
+ export interface DidCommAttachment {
36
+ id: string;
37
+ media_type: string;
38
+ data: {
39
+ links?: string[];
40
+ base64?: string;
41
+ json?: any;
42
+ };
43
+ }
32
44
  /**
33
45
  * The canonical, internal representation of a secure message, extending
34
46
  * the standard DIDComm payload with FHIR-specific, flattened metadata.
@@ -122,21 +122,6 @@ export interface ConfidentialStorageDoc {
122
122
  tag?: MetaTagCoding[];
123
123
  /** Policy-dependent research/analytics metadata, kept outside encrypted `content`. */
124
124
  research?: ResearchInfo;
125
- /**
126
- * @deprecated Use `created`, `contentType`, and `research` instead.
127
- * This legacy field is kept for backwards compatibility with older stored documents.
128
- */
129
- meta?: {
130
- created?: string;
131
- contentType?: string;
132
- chunks?: number;
133
- jurisdiction?: string;
134
- yearOfBirth?: string;
135
- gender?: string;
136
- sexAtBirth?: string;
137
- /** @deprecated Use `tag` instead. */
138
- tags?: string;
139
- };
140
125
  }
141
126
  /**
142
127
  * Represents a document whose sensitive content has been decrypted and is held
@@ -0,0 +1,40 @@
1
+ import { DidCommPayload, DidCommAttachment } from '../models/comm';
2
+ export { DidCommAttachment } from '../models/comm';
3
+ /**
4
+ * Creates a DIDComm message instance.
5
+ */
6
+ export declare class DidCommMessage implements DidCommPayload {
7
+ id: string;
8
+ type: string;
9
+ from?: string;
10
+ to?: string[];
11
+ thid?: string;
12
+ pthid?: string;
13
+ created_time?: number;
14
+ expires_time?: number;
15
+ body: {
16
+ [key: string]: any;
17
+ };
18
+ attachments?: DidCommAttachment[];
19
+ constructor();
20
+ }
21
+ /**
22
+ * Prepares a DIDComm request message.
23
+ */
24
+ export declare function prepareDidCommRequest(type: string, body?: any, attachments?: DidCommAttachment[]): DidCommMessage;
25
+ /**
26
+ * Includes VP token in DIDComm message body.
27
+ */
28
+ export declare function includeVpTokenInMessage(message: DidCommMessage, vpToken: string): void;
29
+ /**
30
+ * Includes file bytes as base64 attachment in DIDComm message.
31
+ */
32
+ export declare function includeFileInMessage(message: DidCommMessage, fileBytes: Uint8Array, mediaType: string, id: string): void;
33
+ /**
34
+ * Gets THID from DIDComm message.
35
+ */
36
+ export declare function getThidFromMessage(message: DidCommMessage): string;
37
+ /**
38
+ * Gets data results from polling response body.
39
+ */
40
+ export declare function getDataResults(response: DidCommMessage): any[];
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Generates a random ID for DIDComm messages.
3
+ */
4
+ function generateId() {
5
+ return Math.random().toString(36).substr(2, 9);
6
+ }
7
+ /**
8
+ * Creates a DIDComm message instance.
9
+ */
10
+ export class DidCommMessage {
11
+ id;
12
+ type;
13
+ from;
14
+ to;
15
+ thid;
16
+ pthid;
17
+ created_time;
18
+ expires_time;
19
+ body;
20
+ attachments;
21
+ constructor() {
22
+ this.id = generateId();
23
+ this.type = '';
24
+ this.body = {};
25
+ }
26
+ }
27
+ /**
28
+ * Prepares a DIDComm request message.
29
+ */
30
+ export function prepareDidCommRequest(type, body = {}, attachments = []) {
31
+ const message = new DidCommMessage();
32
+ message.type = type;
33
+ message.body = body;
34
+ message.attachments = attachments;
35
+ message.thid = message.id; // Set thid to id for new threads
36
+ return message;
37
+ }
38
+ /**
39
+ * Includes VP token in DIDComm message body.
40
+ */
41
+ export function includeVpTokenInMessage(message, vpToken) {
42
+ message.body.vp_token = vpToken;
43
+ }
44
+ /**
45
+ * Includes file bytes as base64 attachment in DIDComm message.
46
+ */
47
+ export function includeFileInMessage(message, fileBytes, mediaType, id) {
48
+ const base64 = Buffer.from(fileBytes).toString('base64');
49
+ if (!message.attachments)
50
+ message.attachments = [];
51
+ message.attachments.push({
52
+ id,
53
+ media_type: mediaType,
54
+ data: { base64 }
55
+ });
56
+ }
57
+ /**
58
+ * Gets THID from DIDComm message.
59
+ */
60
+ export function getThidFromMessage(message) {
61
+ return message.thid || message.id;
62
+ }
63
+ /**
64
+ * Gets data results from polling response body.
65
+ */
66
+ export function getDataResults(response) {
67
+ return response.body?.data || [];
68
+ }
@@ -4,6 +4,7 @@ export * from './baseN';
4
4
  export * from './bundle';
5
5
  export * from './content';
6
6
  export * from './did';
7
+ export * from './didcomm';
7
8
  export * from './format-converter';
8
9
  export * from './jwt';
9
10
  export * from './manager-error';
@@ -4,6 +4,7 @@ export * from './baseN.js';
4
4
  export * from './bundle.js';
5
5
  export * from './content.js';
6
6
  export * from './did.js';
7
+ export * from './didcomm.js';
7
8
  export * from './format-converter.js';
8
9
  export * from './jwt.js';
9
10
  export * from './manager-error.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gdc-common-utils-ts",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },