@secrecy/lib 1.86.2 → 1.86.4-fix-md5.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.
Files changed (47) hide show
  1. package/dist/lib/base-client.js +6 -5
  2. package/dist/lib/cache.js +14 -5
  3. package/dist/lib/client/SecrecyCloudClient.js +4 -2
  4. package/dist/lib/client/SecrecyMailClient.js +12 -5
  5. package/dist/lib/client/data-link.js +6 -12
  6. package/dist/lib/client/helpers.js +21 -1
  7. package/dist/lib/client/index.js +6 -8
  8. package/dist/lib/client/upload.js +12 -14
  9. package/dist/lib/client.js +6 -10
  10. package/dist/lib/crypto/data.js +146 -91
  11. package/dist/lib/crypto/domain.js +1 -3
  12. package/dist/lib/crypto/helpers.js +23 -1
  13. package/dist/lib/crypto/index.js +2 -2
  14. package/dist/lib/error/client.js +7 -1
  15. package/dist/lib/react/index.js +69 -0
  16. package/dist/lib/transformer.js +3 -2
  17. package/dist/lib/utils/popup-tools.js +31 -13
  18. package/dist/lib/versioning.js +1 -1
  19. package/dist/lib/worker/generated/md5.js +2 -0
  20. package/dist/lib/worker/generated/sodium.js +2 -0
  21. package/dist/lib/worker/md5.js +2 -2
  22. package/dist/lib/worker/sodium.js +17 -15
  23. package/dist/types/base-client.d.ts +2 -0
  24. package/dist/types/cache.d.ts +7 -6
  25. package/dist/types/client/SecrecyMailClient.d.ts +23 -1
  26. package/dist/types/client/data-link.d.ts +4 -4
  27. package/dist/types/client/helpers.d.ts +12 -0
  28. package/dist/types/client/index.d.ts +4 -2
  29. package/dist/types/client/types/data.d.ts +2 -1
  30. package/dist/types/client.d.ts +67 -74
  31. package/dist/types/crypto/data.d.ts +11 -1
  32. package/dist/types/crypto/domain.d.ts +0 -1
  33. package/dist/types/crypto/helpers.d.ts +7 -0
  34. package/dist/types/crypto/index.d.ts +3 -3
  35. package/dist/types/error/client.d.ts +8 -0
  36. package/dist/types/error/index.d.ts +4 -0
  37. package/dist/types/react/index.d.ts +20 -0
  38. package/dist/types/sodium.d.ts +5 -0
  39. package/dist/types/utils/popup-tools.d.ts +4 -2
  40. package/dist/types/versioning.d.ts +1 -1
  41. package/dist/types/worker/generated/md5.d.ts +1 -0
  42. package/dist/types/worker/generated/sodium.d.ts +1 -0
  43. package/package.json +37 -13
  44. package/dist/lib/client/SecrecyDbClient.js +0 -3
  45. package/dist/lib/worker/workerCodes.js +0 -254
  46. package/dist/types/client/SecrecyDbClient.d.ts +0 -4
  47. package/dist/types/worker/workerCodes.d.ts +0 -2
@@ -1,5 +1,4 @@
1
1
  import SparkMD5 from 'spark-md5';
2
- import { workerMd5Script } from './workerCodes.js';
3
2
  function* chunks(arr, n) {
4
3
  for (let i = 0; i < arr.length; i += n) {
5
4
  yield arr.slice(i, i + n);
@@ -8,8 +7,9 @@ function* chunks(arr, n) {
8
7
  const CHUNK_SIZE = 8192;
9
8
  export const md5 = process.env.NODE_ENV !== 'test'
10
9
  ? async (data) => {
10
+ const { workerMd5Script } = await import('./generated/md5.js');
11
+ const worker = new Worker(URL.createObjectURL(new Blob([workerMd5Script], { type: 'text/javascript' })));
11
12
  return await new Promise((resolve, reject) => {
12
- const worker = new Worker(URL.createObjectURL(new Blob([workerMd5Script], { type: 'text/javascript' })));
13
13
  worker.addEventListener('error', reject);
14
14
  worker.addEventListener('messageerror', reject);
15
15
  worker.addEventListener('message', ({ data }) => {
@@ -1,26 +1,18 @@
1
1
  import { decryptSecretStream, encryptSecretStream, } from '../crypto/data.js';
2
- import { workerSodiumScript } from './workerCodes.js';
3
- // const ensureNonDetachedUniqueBuffers = (
4
- // values: Transferable[]
5
- // ): Set<Transferable> =>
6
- // new Set(
7
- // values.filter(v => {
8
- // if (v instanceof ArrayBuffer) {
9
- // return v.byteLength === 0;
10
- // } else {
11
- // return true;
12
- // }
13
- // })
14
- // );
2
+ // Loaded lazily so the bundled libsodium only ships when a worker is needed.
3
+ const createSodiumWorker = async () => {
4
+ const { workerSodiumScript } = await import('./generated/sodium.js');
5
+ return new Worker(URL.createObjectURL(new Blob([workerSodiumScript], { type: 'text/javascript' })));
6
+ };
15
7
  export const encrypt = process.env.NODE_ENV !== 'test'
16
8
  ? async (key, dataToEncrypt, progress, signal) => {
9
+ const worker = await createSodiumWorker();
17
10
  return await new Promise((resolve, reject) => {
18
11
  void progress?.({
19
12
  current: 0,
20
13
  percent: 0,
21
14
  total: dataToEncrypt.byteLength,
22
15
  });
23
- const worker = new Worker(URL.createObjectURL(new Blob([workerSodiumScript], { type: 'text/javascript' })));
24
16
  worker.addEventListener('error', reject);
25
17
  worker.addEventListener('messageerror', reject);
26
18
  worker.addEventListener('message', ({ data }) => {
@@ -46,6 +38,11 @@ export const encrypt = process.env.NODE_ENV !== 'test'
46
38
  void progress?.(data.data);
47
39
  break;
48
40
  }
41
+ case 'error': {
42
+ worker.terminate();
43
+ reject(new Error(data.data));
44
+ break;
45
+ }
49
46
  case 'encrypt-result': {
50
47
  worker.terminate();
51
48
  resolve(data.data);
@@ -59,13 +56,13 @@ export const encrypt = process.env.NODE_ENV !== 'test'
59
56
  };
60
57
  export const decrypt = process.env.NODE_ENV !== 'test'
61
58
  ? async (key, dataToDecrypt, progress, signal) => {
59
+ const worker = await createSodiumWorker();
62
60
  return await new Promise((resolve, reject) => {
63
61
  void progress?.({
64
62
  current: 0,
65
63
  percent: 0,
66
64
  total: dataToDecrypt.byteLength,
67
65
  });
68
- const worker = new Worker(URL.createObjectURL(new Blob([workerSodiumScript], { type: 'text/javascript' })));
69
66
  worker.addEventListener('error', reject);
70
67
  worker.addEventListener('messageerror', reject);
71
68
  worker.addEventListener('message', ({ data }) => {
@@ -91,6 +88,11 @@ export const decrypt = process.env.NODE_ENV !== 'test'
91
88
  void progress?.(data.data);
92
89
  break;
93
90
  }
91
+ case 'error': {
92
+ worker.terminate();
93
+ reject(new Error(data.data));
94
+ break;
95
+ }
94
96
  case 'decrypt-result': {
95
97
  worker.terminate();
96
98
  resolve(data.data);
@@ -12,6 +12,8 @@ export type BaseClientOptions = {
12
12
  apiClient?: ApiClient;
13
13
  onAccessDenied?: () => void | Promise<void>;
14
14
  secrecyUrls?: Partial<SecrecyUrls>;
15
+ timeoutMs?: number;
16
+ reloadOnAccessDenied?: boolean;
15
17
  };
16
18
  export declare class BaseClient {
17
19
  #private;
@@ -1,17 +1,18 @@
1
1
  import type { InternalNode, InternalData, InternalNodeFull, LocalData, InternalMinimalNodeForEncryption } from './client/types/index.js';
2
2
  import { LRUCache } from 'lru-cache';
3
3
  type NodeForEncryptionCached = InternalNode | InternalNodeFull | InternalMinimalNodeForEncryption;
4
- export declare const dataCache: Map<string, InternalData>;
5
- export declare const nodesCache: Map<string, InternalNode | InternalNodeFull>;
6
- export declare const nodesEncryptionCache: Map<string, InternalMinimalNodeForEncryption>;
4
+ export declare const dataCache: LRUCache<string, InternalData, unknown>;
5
+ export declare const nodesCache: LRUCache<string, InternalNode | InternalNodeFull, unknown>;
6
+ export declare const nodesEncryptionCache: LRUCache<string, InternalMinimalNodeForEncryption, unknown>;
7
7
  export declare const getNodeForEncryptionFromCache: (id: string) => NodeForEncryptionCached | undefined;
8
- export declare const usersCache: Map<string, {
8
+ export declare const usersCache: LRUCache<string, {
9
9
  firstname: string;
10
10
  lastname: string;
11
11
  id: string;
12
12
  avatar: string | null;
13
13
  isSearchable: boolean;
14
- }>;
15
- export declare const publicKeysCache: Map<string, string>;
14
+ }, unknown>;
15
+ export declare const publicKeysCache: LRUCache<string, string, unknown>;
16
16
  export declare const dataContentCache: LRUCache<string, LocalData, unknown>;
17
+ export declare function clearAllCaches(): void;
17
18
  export {};
@@ -13,9 +13,23 @@ export declare class SecrecyMailClient {
13
13
  deletedMails({ mailType, }: {
14
14
  mailType: ApiMail['type'];
15
15
  }): Promise<Mail[]>;
16
+ create(data: NewMail & {
17
+ customMessage?: string | null | undefined;
18
+ }): Promise<SentMail>;
19
+ /**
20
+ * @deprecated Pass a single object instead:
21
+ * `create({ ...data, customMessage })`.
22
+ */
16
23
  create(data: NewMail, customMessage?: string | null | undefined): Promise<SentMail>;
17
24
  waitingReceivedMails(): Promise<WaitingReceivedMail[]>;
18
- updateDraft(draftId: string, { body, subject, senderFiles, recipients, replyToId }: Partial<NewMail>): Promise<DraftMail>;
25
+ updateDraft(input: {
26
+ draftId: string;
27
+ } & Partial<NewMail>): Promise<DraftMail>;
28
+ /**
29
+ * @deprecated Pass a single object instead:
30
+ * `updateDraft({ draftId, ...args })`.
31
+ */
32
+ updateDraft(draftId: string, args: Partial<NewMail>): Promise<DraftMail>;
19
33
  deleteDraft(draftId: string): Promise<boolean>;
20
34
  deleteTrash({ ids }: {
21
35
  ids: string[];
@@ -24,6 +38,14 @@ export declare class SecrecyMailClient {
24
38
  delete({ mailId }: {
25
39
  mailId: string;
26
40
  }): Promise<boolean>;
41
+ sendDraft(input: {
42
+ draftId: string;
43
+ customMessage?: string | null | undefined;
44
+ }): Promise<boolean>;
45
+ /**
46
+ * @deprecated Pass a single object instead:
47
+ * `sendDraft({ draftId, customMessage })`.
48
+ */
27
49
  sendDraft(draftId: string, customMessage?: string | null | undefined): Promise<boolean>;
28
50
  sendWaitingEmails(): Promise<void>;
29
51
  createDraft({ body, subject, senderFiles, recipients, replyToId, }: NewMail): Promise<DraftMail>;
@@ -3,7 +3,7 @@ import { type ProgressCallback } from '.';
3
3
  import { type Progress } from 'ky';
4
4
  export declare const downloadDataLinkSchema: z.ZodUnion<readonly [z.ZodObject<{
5
5
  name: z.ZodString;
6
- md5: z.ZodString;
6
+ md5: z.ZodNullable<z.ZodString>;
7
7
  md5Encrypted: z.ZodNullable<z.ZodString>;
8
8
  size: z.ZodCoercedBigInt<unknown>;
9
9
  parts: z.ZodArray<z.ZodObject<{
@@ -15,7 +15,7 @@ export declare const downloadDataLinkSchema: z.ZodUnion<readonly [z.ZodObject<{
15
15
  isEncrypted: z.ZodBoolean;
16
16
  }, z.core.$strip>, z.ZodObject<{
17
17
  name: z.ZodString;
18
- md5: z.ZodString;
18
+ md5: z.ZodNullable<z.ZodString>;
19
19
  md5Encrypted: z.ZodNullable<z.ZodString>;
20
20
  size: z.ZodCoercedBigInt<unknown>;
21
21
  bytes: z.ZodString;
@@ -34,7 +34,7 @@ export type DownloadDataFromLinkOptions = {
34
34
  };
35
35
  export declare function fetchDataLinkMetadata(dataLinkSlug: string, dataUrl?: string): Promise<{
36
36
  name: string;
37
- md5: string;
37
+ md5: string | null;
38
38
  md5Encrypted: string | null;
39
39
  size: bigint;
40
40
  parts: {
@@ -46,7 +46,7 @@ export declare function fetchDataLinkMetadata(dataLinkSlug: string, dataUrl?: st
46
46
  isEncrypted: boolean;
47
47
  } | {
48
48
  name: string;
49
- md5: string;
49
+ md5: string | null;
50
50
  md5Encrypted: string | null;
51
51
  size: bigint;
52
52
  bytes: string;
@@ -29,4 +29,16 @@ type LoginResponse<Params extends UseSecrecyParams> = Params extends {
29
29
  redirect: true;
30
30
  } ? SecrecyClient | null : SecrecyClient;
31
31
  export declare function login<Params extends UseSecrecyParams>({ appId, context, path, redirect, scopes, backPath, session, secrecyUrls, forceLogin, }: Params): Promise<LoginResponse<Params>>;
32
+ /**
33
+ * Single async entry point: runs `setup()`, reuses an existing session if
34
+ * one is found, and falls back to `login()` otherwise. Equivalent to
35
+ * `await setup()` + `getSecrecyClient()` + `login()`, without having to
36
+ * juggle the sync/async mismatch between them.
37
+ */
38
+ export declare function initSecrecy(opts: {
39
+ appId: string;
40
+ session?: boolean | undefined;
41
+ redirect?: boolean | undefined;
42
+ secrecyUrls?: Partial<SecrecyUrls>;
43
+ }): Promise<SecrecyClient | null>;
32
44
  export {};
@@ -3,7 +3,6 @@ import type { SecretStreamProgress } from '../crypto/data.js';
3
3
  import { SecrecyCloudClient } from './SecrecyCloudClient.js';
4
4
  import { SecrecyMailClient } from './SecrecyMailClient.js';
5
5
  import { SecrecyAppClient } from './SecrecyAppClient.js';
6
- import { SecrecyDbClient } from './SecrecyDbClient.js';
7
6
  import { SecrecyWalletClient } from './SecrecyWalletClient.js';
8
7
  import { SecrecyPayClient } from './SecrecyPayClient.js';
9
8
  import { type ApiClient, type RouterInputs } from '../client.js';
@@ -22,15 +21,18 @@ export interface SecrecyClientOptions {
22
21
  uaJwt: string;
23
22
  apiClient?: ApiClient;
24
23
  secrecyUrls?: Partial<SecrecyUrls>;
24
+ timeoutMs?: number;
25
+ reloadOnAccessDenied?: boolean;
25
26
  }
26
27
  export declare class SecrecyClient extends BaseClient {
27
28
  #private;
28
29
  cloud: SecrecyCloudClient;
29
30
  mail: SecrecyMailClient;
30
31
  app: SecrecyAppClient;
31
- db: SecrecyDbClient;
32
32
  organization: SecrecyOrganizationClient;
33
+ /** @experimental Susceptible de changer sans version majeure. */
33
34
  wallet: SecrecyWalletClient;
35
+ /** @experimental Susceptible de changer sans version majeure. */
34
36
  pay: SecrecyPayClient;
35
37
  user: SecrecyUserClient;
36
38
  pseudonym: SecrecyPseudonymClient;
@@ -7,7 +7,8 @@ export type LocalData = {
7
7
  storageType: DataStorageType;
8
8
  size: bigint;
9
9
  sizeEncrypted: bigint | null;
10
- md5: string;
10
+ /** md5 of the content: only for unencrypted and legacy encrypted data. */
11
+ md5: string | null;
11
12
  data: Uint8Array<ArrayBuffer>;
12
13
  mime?: string;
13
14
  ext?: string;