@msssystems/mss-link-sdk 0.1.3 → 0.1.5

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.
@@ -3,6 +3,8 @@ export * from './client-options';
3
3
  export * from './decryption-errors';
4
4
  export * from './local-crypto-health';
5
5
  export * from './local-crypto-health.contracts';
6
+ export * from './media-message.contracts';
7
+ export * from './media-message-metadata';
6
8
  export * from './message.contracts';
7
9
  export * from './message-decryption.contracts';
8
10
  export * from './message-decryption-state';
@@ -3,6 +3,8 @@ export * from './client-options';
3
3
  export * from './decryption-errors';
4
4
  export * from './local-crypto-health';
5
5
  export * from './local-crypto-health.contracts';
6
+ export * from './media-message.contracts';
7
+ export * from './media-message-metadata';
6
8
  export * from './message.contracts';
7
9
  export * from './message-decryption.contracts';
8
10
  export * from './message-decryption-state';
@@ -0,0 +1,4 @@
1
+ import type { MediaMessageAttachmentInput, MediaMessageMetadataPayload } from './media-message.contracts';
2
+ export declare function buildMediaMessageMetadataPayload(attachments: MediaMessageAttachmentInput[], caption?: string): MediaMessageMetadataPayload;
3
+ export declare function serializeMediaMessageMetadata(payload: MediaMessageMetadataPayload): string;
4
+ export declare function extractMediaAssetIds(attachments: MediaMessageAttachmentInput[]): string[];
@@ -0,0 +1,56 @@
1
+ export function buildMediaMessageMetadataPayload(attachments, caption) {
2
+ if (attachments.length === 0) {
3
+ throw new Error('Media message must contain at least one attachment.');
4
+ }
5
+ const payload = {
6
+ schema: 'mss.link.media-message.v1',
7
+ attachments: attachments.map(normalizeAttachment),
8
+ };
9
+ if (caption && caption.trim().length > 0) {
10
+ payload.caption = caption.trim();
11
+ }
12
+ return payload;
13
+ }
14
+ export function serializeMediaMessageMetadata(payload) {
15
+ return JSON.stringify({
16
+ schema: payload.schema,
17
+ attachments: payload.attachments.map((attachment) => ({
18
+ assetId: attachment.assetId,
19
+ mimeType: attachment.mimeType,
20
+ size: attachment.size,
21
+ ...(attachment.originalName
22
+ ? { originalName: attachment.originalName }
23
+ : {}),
24
+ ...(attachment.uploadedAt ? { uploadedAt: attachment.uploadedAt } : {}),
25
+ })),
26
+ ...(payload.caption ? { caption: payload.caption } : {}),
27
+ });
28
+ }
29
+ export function extractMediaAssetIds(attachments) {
30
+ return attachments.map((attachment) => attachment.assetId);
31
+ }
32
+ function normalizeAttachment(attachment) {
33
+ const assetId = attachment.assetId.trim();
34
+ const mimeType = attachment.mimeType.trim();
35
+ const size = String(attachment.size);
36
+ if (!assetId) {
37
+ throw new Error('Media attachment assetId is required.');
38
+ }
39
+ if (!mimeType) {
40
+ throw new Error('Media attachment mimeType is required.');
41
+ }
42
+ if (!size || size === 'NaN') {
43
+ throw new Error('Media attachment size is required.');
44
+ }
45
+ return {
46
+ assetId,
47
+ mimeType,
48
+ size,
49
+ ...(attachment.originalName?.trim()
50
+ ? { originalName: attachment.originalName.trim() }
51
+ : {}),
52
+ ...(attachment.uploadedAt?.trim()
53
+ ? { uploadedAt: attachment.uploadedAt.trim() }
54
+ : {}),
55
+ };
56
+ }
@@ -0,0 +1,25 @@
1
+ export interface MediaMessageAttachmentInput {
2
+ assetId: string;
3
+ mimeType: string;
4
+ size: string | number;
5
+ originalName?: string;
6
+ uploadedAt?: string;
7
+ }
8
+ export interface SendMediaMessageParams {
9
+ chatId: string;
10
+ targetUserId: string;
11
+ attachments: MediaMessageAttachmentInput[];
12
+ caption?: string;
13
+ }
14
+ export interface MediaMessageAttachmentMetadata {
15
+ assetId: string;
16
+ mimeType: string;
17
+ size: string;
18
+ originalName?: string;
19
+ uploadedAt?: string;
20
+ }
21
+ export interface MediaMessageMetadataPayload {
22
+ schema: 'mss.link.media-message.v1';
23
+ attachments: MediaMessageAttachmentMetadata[];
24
+ caption?: string;
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,6 @@
1
1
  import type { MssLinkBrowserClientOptions } from './client-options';
2
2
  import type { LocalCryptoHealth } from './local-crypto-health.contracts';
3
+ import type { SendMediaMessageParams } from './media-message.contracts';
3
4
  import type { DecryptedMessage } from './message.contracts';
4
5
  export declare class MssLinkBrowserClient {
5
6
  private readonly userId;
@@ -24,6 +25,7 @@ export declare class MssLinkBrowserClient {
24
25
  text: string;
25
26
  kind?: string;
26
27
  }): Promise<string>;
28
+ sendMediaMessage(params: SendMediaMessageParams): Promise<string>;
27
29
  syncMessages(): Promise<void>;
28
30
  getLocalMessages(chatId: string): Promise<DecryptedMessage[]>;
29
31
  reset(): void;
@@ -1,6 +1,7 @@
1
1
  import { normalizeProductApiBaseUrl } from './api-base-url';
2
2
  import { normalizeLocalCryptoError } from './decryption-errors';
3
3
  import { checkLocalCryptoHealth } from './local-crypto-health';
4
+ import { buildMediaMessageMetadataPayload, extractMediaAssetIds, serializeMediaMessageMetadata, } from './media-message-metadata';
4
5
  import { mapLocalSdkMessage } from './message.mapper';
5
6
  import { WasmCallQueue } from './wasm-call-queue';
6
7
  const DEFAULT_DEVICE_ID = 1;
@@ -67,6 +68,18 @@ export class MssLinkBrowserClient {
67
68
  throw normalizeLocalCryptoError(error);
68
69
  }
69
70
  }
71
+ async sendMediaMessage(params) {
72
+ try {
73
+ await this.ensureReady();
74
+ const payload = buildMediaMessageMetadataPayload(params.attachments, params.caption);
75
+ const metadataJson = serializeMediaMessageMetadata(payload);
76
+ const mediaAssetIds = extractMediaAssetIds(params.attachments);
77
+ return this.runWithClient((client) => client.sendMediaMessage(params.chatId, params.targetUserId, metadataJson, mediaAssetIds));
78
+ }
79
+ catch (error) {
80
+ throw normalizeLocalCryptoError(error);
81
+ }
82
+ }
70
83
  async syncMessages() {
71
84
  try {
72
85
  await this.runWithClient((client) => client.syncMessages());
@@ -104,7 +117,7 @@ export class MssLinkBrowserClient {
104
117
  return this.wasmClient;
105
118
  }
106
119
  loadWasmModule() {
107
- this.wasmModulePromise ??= import('@msssystems/mss-crypto-wasm');
120
+ this.wasmModulePromise ??= import('@msssystems/mss-crypto-wasm').then((module) => module);
108
121
  return this.wasmModulePromise;
109
122
  }
110
123
  }
@@ -1,6 +1,9 @@
1
1
  import type { WasmMssClient } from '@msssystems/mss-crypto-wasm';
2
- export type WasmMssClientConstructor = new (userId: string, deviceId: number, apiBaseUrl: string) => WasmMssClient;
2
+ export interface MssLinkWasmClient extends WasmMssClient {
3
+ sendMediaMessage(chatId: string, targetUserId: string, metadataJson: string, mediaAssetIds: string[]): Promise<string>;
4
+ }
5
+ export type WasmMssClientConstructor = new (userId: string, deviceId: number, apiBaseUrl: string) => MssLinkWasmClient;
3
6
  export interface MssCryptoWasmModule {
4
7
  WasmMssClient: WasmMssClientConstructor;
5
8
  }
6
- export type WasmMssClientInstance = WasmMssClient;
9
+ export type WasmMssClientInstance = MssLinkWasmClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@msssystems/mss-link-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Official managed application SDK for MSS ecosystem",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -53,7 +53,7 @@
53
53
  "registry": "https://registry.npmjs.org/"
54
54
  },
55
55
  "peerDependencies": {
56
- "@msssystems/mss-crypto-wasm": "^0.1.16",
56
+ "@msssystems/mss-crypto-wasm": "^0.1.17",
57
57
  "@nestjs/common": "^10.0.0 || ^11.0.0",
58
58
  "@nestjs/core": "^10.0.0 || ^11.0.0",
59
59
  "express": "^4.0.0 || ^5.0.0",
@@ -77,7 +77,7 @@
77
77
  }
78
78
  },
79
79
  "devDependencies": {
80
- "@msssystems/mss-crypto-wasm": "^0.1.16",
80
+ "@msssystems/mss-crypto-wasm": "^0.1.17",
81
81
  "@nestjs/common": "^11.0.1",
82
82
  "@nestjs/core": "^11.0.1",
83
83
  "@types/express": "^5.0.0",