@majikah/majik-file 0.0.12 → 0.0.13

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.
@@ -61,10 +61,10 @@ export declare class MajikFile {
61
61
  private _isShared;
62
62
  private _shareToken;
63
63
  private readonly _context;
64
- private readonly _chatMessageId;
65
- private readonly _threadMessageId;
66
- private readonly _threadId;
67
- private readonly _conversationId;
64
+ private _chatMessageId;
65
+ private _threadMessageId;
66
+ private _threadId;
67
+ private _conversationId;
68
68
  private _participants;
69
69
  private _expiresAt;
70
70
  private readonly _timestamp;
@@ -208,6 +208,18 @@ export declare class MajikFile {
208
208
  * via the recipients array). To check owner access use `userIsOwner()`.
209
209
  */
210
210
  hasParticipantAccess(publicKey: MajikMessagePublicKey): boolean;
211
+ /**
212
+ * Bind this file to a thread mail after initial creation.
213
+ * Can only be called once — throws if either ID is already set.
214
+ * Call toJSON() and persist to Supabase after binding.
215
+ */
216
+ bindToThreadMail(threadId: string, threadMessageId: string): void;
217
+ /**
218
+ * Bind this file to a chat conversation after initial creation.
219
+ * Can only be called once — throws if either ID is already set.
220
+ * Call toJSON() and persist to Supabase after binding.
221
+ */
222
+ bindToChatConversation(conversationID: string, chatMessageID: string): void;
211
223
  /**
212
224
  * Decrypt a .mjkb Blob, Uint8Array, or ArrayBuffer.
213
225
  *
@@ -526,6 +526,52 @@ export class MajikFile {
526
526
  return false;
527
527
  return this._participants.includes(publicKey);
528
528
  }
529
+ /**
530
+ * Bind this file to a thread mail after initial creation.
531
+ * Can only be called once — throws if either ID is already set.
532
+ * Call toJSON() and persist to Supabase after binding.
533
+ */
534
+ bindToThreadMail(threadId, threadMessageId) {
535
+ if (this._context !== "thread_attachment") {
536
+ throw MajikFileError.invalidInput("bindToThreadMail: only thread_attachment files can be bound to a mail");
537
+ }
538
+ if (this._threadId || this._threadMessageId) {
539
+ throw MajikFileError.invalidInput("bindToThreadMail: this file is already bound to a thread mail — " +
540
+ "IDs are immutable once set");
541
+ }
542
+ if (!threadId?.trim()) {
543
+ throw MajikFileError.invalidInput("bindToThreadMail: threadId is required");
544
+ }
545
+ if (!threadMessageId?.trim()) {
546
+ throw MajikFileError.invalidInput("bindToThreadMail: threadMessageId is required");
547
+ }
548
+ this._threadId = threadId;
549
+ this._threadMessageId = threadMessageId;
550
+ this._lastUpdate = new Date().toISOString();
551
+ }
552
+ /**
553
+ * Bind this file to a chat conversation after initial creation.
554
+ * Can only be called once — throws if either ID is already set.
555
+ * Call toJSON() and persist to Supabase after binding.
556
+ */
557
+ bindToChatConversation(conversationID, chatMessageID) {
558
+ if (this._context !== "chat_attachment") {
559
+ throw MajikFileError.invalidInput("bindToChatConversation: only chat_attachment files can be bound to a mail");
560
+ }
561
+ if (this._chatMessageId || this._conversationId) {
562
+ throw MajikFileError.invalidInput("bindToChatConversation: this file is already bound to a chat conversation — " +
563
+ "IDs are immutable once set");
564
+ }
565
+ if (!conversationID?.trim()) {
566
+ throw MajikFileError.invalidInput("bindToChatConversation: conversationID is required");
567
+ }
568
+ if (!chatMessageID?.trim()) {
569
+ throw MajikFileError.invalidInput("bindToChatConversation: chatMessageID is required");
570
+ }
571
+ this._conversationId = conversationID;
572
+ this._chatMessageId = chatMessageID;
573
+ this._lastUpdate = new Date().toISOString();
574
+ }
529
575
  // ── DECRYPT (static) ──────────────────────────────────────────────────────
530
576
  /**
531
577
  * Decrypt a .mjkb Blob, Uint8Array, or ArrayBuffer.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@majikah/majik-file",
3
3
  "type": "module",
4
4
  "description": "Majik File is the core cryptographic engine for secure file handling in the Majikah ecosystem. It provides a post-quantum secure \"MJKB\" format designed for file encryption, multi-recipient key encapsulation, and transparent compression using NIST-standardized algorithms.",
5
- "version": "0.0.12",
5
+ "version": "0.0.13",
6
6
  "license": "Apache-2.0",
7
7
  "author": "Zelijah",
8
8
  "main": "./dist/index.js",