@msssystems/mss-link-sdk 0.1.8 → 0.1.9

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.
@@ -0,0 +1,64 @@
1
+ export type DrivePermissionRole = 'editor' | 'owner' | 'viewer';
2
+ export type DriveEditablePermissionRole = Exclude<DrivePermissionRole, 'owner'>;
3
+ export type DriveVisibility = 'private' | 'shared';
4
+ export type DriveItemType = 'file' | 'folder';
5
+ export type DriveShareTargetType = 'user';
6
+ export interface DriveShareTarget {
7
+ type: DriveShareTargetType;
8
+ userId?: string;
9
+ username?: string;
10
+ }
11
+ export interface DriveWrappedItemKey {
12
+ encryptedItemKey: string;
13
+ keyAlgorithm?: string;
14
+ keyNonce?: string;
15
+ keyRecipientId?: string;
16
+ }
17
+ export interface CreateDriveShareGrantInput {
18
+ role: DriveEditablePermissionRole;
19
+ target: DriveShareTarget;
20
+ wrappedItemKey: DriveWrappedItemKey;
21
+ }
22
+ export interface DriveShareGrantPayload {
23
+ encryptedItemKey: string;
24
+ keyAlgorithm?: string;
25
+ keyNonce?: string;
26
+ keyRecipientId?: string;
27
+ role: 'EDITOR' | 'VIEWER';
28
+ target: {
29
+ type: 'user';
30
+ userId?: string;
31
+ username?: string;
32
+ };
33
+ }
34
+ export interface DriveAccessPrincipal {
35
+ accountId: string;
36
+ avatarUrl: string | null;
37
+ displayName: string | null;
38
+ userId: string | null;
39
+ username: string | null;
40
+ }
41
+ export interface DriveAccessGrant {
42
+ createdAt: string;
43
+ encryptedItemKey: string;
44
+ fileId: string | null;
45
+ folderId: string | null;
46
+ grantee: DriveAccessPrincipal;
47
+ granteeAccountId: string;
48
+ id: string;
49
+ itemType: 'FILE' | 'FOLDER';
50
+ keyAlgorithm: string;
51
+ keyNonce: string | null;
52
+ keyRecipientId: string | null;
53
+ ownerAccountId: string;
54
+ role: 'EDITOR' | 'OWNER' | 'VIEWER';
55
+ updatedAt: string;
56
+ }
57
+ export interface DriveAccessResponse {
58
+ currentUserRole: 'EDITOR' | 'OWNER' | 'VIEWER';
59
+ grants: DriveAccessGrant[];
60
+ itemId: string;
61
+ itemType: 'FILE' | 'FOLDER';
62
+ owner: DriveAccessPrincipal;
63
+ visibility: 'PRIVATE' | 'SHARED';
64
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { CreateDriveShareGrantInput, DriveEditablePermissionRole, DriveShareGrantPayload, DriveShareTarget, DriveWrappedItemKey } from './drive-sharing.contracts';
2
+ export declare function createDriveShareGrantPayload(input: CreateDriveShareGrantInput): DriveShareGrantPayload;
3
+ export declare function normalizeDriveShareTarget(target: DriveShareTarget): DriveShareGrantPayload['target'];
4
+ export declare function normalizeWrappedItemKey(key: DriveWrappedItemKey): Omit<DriveShareGrantPayload, 'role' | 'target'>;
5
+ export declare function toApiDrivePermissionRole(role: DriveEditablePermissionRole): DriveShareGrantPayload['role'];
@@ -0,0 +1,51 @@
1
+ const DEFAULT_KEY_ALGORITHM = 'X25519-AES-256-GCM';
2
+ export function createDriveShareGrantPayload(input) {
3
+ return {
4
+ ...normalizeWrappedItemKey(input.wrappedItemKey),
5
+ role: toApiDrivePermissionRole(input.role),
6
+ target: normalizeDriveShareTarget(input.target),
7
+ };
8
+ }
9
+ export function normalizeDriveShareTarget(target) {
10
+ if (target.type !== 'user') {
11
+ throw new Error('Drive sharing supports only selected users in v1.');
12
+ }
13
+ const userId = target.userId?.trim();
14
+ const username = target.username?.trim().replace(/^@/, '').toLowerCase();
15
+ if (!userId && !username) {
16
+ throw new Error('Drive share target must include userId or username.');
17
+ }
18
+ return {
19
+ type: 'user',
20
+ ...(userId ? { userId } : {}),
21
+ ...(username ? { username } : {}),
22
+ };
23
+ }
24
+ export function normalizeWrappedItemKey(key) {
25
+ const encryptedItemKey = key.encryptedItemKey.trim();
26
+ const keyAlgorithm = (key.keyAlgorithm?.trim() || DEFAULT_KEY_ALGORITHM).trim();
27
+ const keyNonce = key.keyNonce?.trim();
28
+ const keyRecipientId = key.keyRecipientId?.trim();
29
+ if (!encryptedItemKey) {
30
+ throw new Error('Drive share requires encrypted wrapped item key.');
31
+ }
32
+ if (!keyAlgorithm) {
33
+ throw new Error('Drive share key algorithm is required.');
34
+ }
35
+ return {
36
+ encryptedItemKey,
37
+ keyAlgorithm,
38
+ ...(keyNonce ? { keyNonce } : {}),
39
+ ...(keyRecipientId ? { keyRecipientId } : {}),
40
+ };
41
+ }
42
+ export function toApiDrivePermissionRole(role) {
43
+ switch (role) {
44
+ case 'editor':
45
+ return 'EDITOR';
46
+ case 'viewer':
47
+ return 'VIEWER';
48
+ default:
49
+ throw new Error('Drive owner role cannot be granted through sharing.');
50
+ }
51
+ }
@@ -3,6 +3,8 @@ export * from './client-options';
3
3
  export * from './decryption-errors';
4
4
  export * from './drive-file-runtime';
5
5
  export * from './drive-file-runtime.contracts';
6
+ export * from './drive-sharing';
7
+ export * from './drive-sharing.contracts';
6
8
  export * from './local-crypto-health';
7
9
  export * from './local-crypto-health.contracts';
8
10
  export * from './media-crypto.contracts';
@@ -3,6 +3,8 @@ export * from './client-options';
3
3
  export * from './decryption-errors';
4
4
  export * from './drive-file-runtime';
5
5
  export * from './drive-file-runtime.contracts';
6
+ export * from './drive-sharing';
7
+ export * from './drive-sharing.contracts';
6
8
  export * from './local-crypto-health';
7
9
  export * from './local-crypto-health.contracts';
8
10
  export * from './media-crypto.contracts';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@msssystems/mss-link-sdk",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Official managed application SDK for MSS ecosystem",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",