@ai-matrx/vault 0.1.11 → 0.1.12

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.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as react from 'react';
2
+ import { ReactNode } from 'react';
2
3
  import { Look } from '@ai-matrx/design-system';
3
4
  import { KnobClient } from '@ai-matrx/data/knobs';
4
5
  import * as account from '@ai-matrx/api/account';
@@ -137,6 +138,11 @@ declare const isHiddenItem: (item: {
137
138
  }) => boolean;
138
139
  /** An item's website as people read it: `github.com` (no scheme, no `www.`), or "" when it has none. */
139
140
  declare function loginSiteOf(item: Pick<VaultItem, "loginUrls">): string;
141
+ /**
142
+ * The site a host belongs to, its registrable domain: `accounts.google.com` → `google.com`,
143
+ * `shop.example.co.uk` → `example.co.uk`. An address or a one-label host is returned as it is.
144
+ */
145
+ declare function siteDomainOf(host: string): string;
140
146
  declare function sortItems(items: readonly VaultItem[], sort: VaultSort): VaultItem[];
141
147
  interface NewSecretField {
142
148
  key: string;
@@ -253,6 +259,12 @@ interface VaultIdentity {
253
259
  withEmailCode(code: string): Promise<void>;
254
260
  /** A host-only path with no human step (the playground's dev server). */
255
261
  dev?: () => Promise<void>;
262
+ /**
263
+ * Run once when the page loads. After a provider confirmation left the page and came back, it
264
+ * checks the SAME person is signed in. A different account is signed out of this device and the
265
+ * sentence to show is returned; otherwise null.
266
+ */
267
+ checkReturn?: () => Promise<string | null>;
256
268
  }
257
269
  /** The slice of supabase-js `auth` this needs, so the package never depends on supabase-js itself. */
258
270
  interface SupabaseAuthLike {
@@ -318,12 +330,38 @@ interface SupabaseAuthLike {
318
330
  message: string;
319
331
  } | null;
320
332
  }>;
333
+ /** Used only when the host gives no `onDifferentPerson`: ends THIS device's session, never others. */
334
+ signOut?(o: {
335
+ scope: "local";
336
+ }): Promise<{
337
+ error: unknown;
338
+ }>;
321
339
  }
322
- /** THE identity confirmation for every host: give it the host's `supabase.auth`. */
323
- declare function createSupabaseIdentity(auth: SupabaseAuthLike, options?: {
340
+ /** Where the person confirming is remembered while the page is away at the provider. */
341
+ interface ReturnStore {
342
+ getItem(key: string): string | null;
343
+ setItem(key: string, value: string): void;
344
+ removeItem(key: string): void;
345
+ }
346
+ interface SupabaseIdentityOptions {
347
+ /** The host's accepted OAuth return address carrying this page. */
324
348
  redirectTo?: () => string;
325
349
  dev?: () => Promise<void>;
326
- }): VaultIdentity;
350
+ /**
351
+ * A provider confirmation came back signed in as someone else. The host ends that session on THIS
352
+ * device only (its own device-scoped sign-out) and tells the person; `message` says what happened.
353
+ * Without it the package signs out locally through `auth.signOut({ scope: "local" })`.
354
+ */
355
+ onDifferentPerson?: (message: string) => Promise<void> | void;
356
+ /** Default: the tab's `sessionStorage`. */
357
+ store?: ReturnStore;
358
+ /** Default `Date.now`. */
359
+ now?: () => number;
360
+ }
361
+ /** The key the expected person is kept under across the provider's redirect. */
362
+ declare const CONFIRM_RETURN_KEY = "matrx-vault:confirming-as";
363
+ /** THE identity confirmation for every host: give it the host's `supabase.auth`. */
364
+ declare function createSupabaseIdentity(auth: SupabaseAuthLike, options?: SupabaseIdentityOptions): VaultIdentity;
327
365
  /** True when the server refused because the sign-in is not recent enough. */
328
366
  declare function needsRecentSignIn(e: unknown): boolean;
329
367
 
@@ -1131,6 +1169,8 @@ interface VaultHostCapabilities {
1131
1169
  /** Desktop: the native passkey importer (file chooser, parsing and keys stay native). */
1132
1170
  nativeImport?: NativeImportBridge;
1133
1171
  openUrl?: (url: string) => void;
1172
+ /** The host's own sign-in, offered when the session has ended (the web app: its login page, back here after). */
1173
+ signIn?: () => void;
1134
1174
  /** A lock the host holds (`lock.ts`): while locked the vault shows Unlock and refuses every port call. */
1135
1175
  lock?: VaultLock;
1136
1176
  /** The host's clipboard: every copy goes through it; a secret is the host's to clear (`lock.ts`). */
@@ -1249,6 +1289,20 @@ interface ApiVaultPortOptions {
1249
1289
  }
1250
1290
  declare function createApiVaultPort(api: Api, options?: ApiVaultPortOptions): VaultPort;
1251
1291
 
1292
+ /**
1293
+ * Wrap any call that shows, copies or exports a secret. When the server answers "sign in again",
1294
+ * the person confirms it is them (Google, password, or an emailed code) and the call runs again —
1295
+ * they never see a dead "Authentication required" in the row.
1296
+ */
1297
+ type Confirmed = <T>(run: () => Promise<T>) => Promise<T>;
1298
+ declare function useConfirmed(): Confirmed;
1299
+ declare function IdentityGate({ identity, children }: {
1300
+ identity: VaultIdentity | undefined;
1301
+ children: ReactNode;
1302
+ }): react.JSX.Element;
1303
+ /** True for the rejection a cancelled confirmation produces (callers stay quiet about it). */
1304
+ declare const wasCancelled: (e: unknown) => boolean;
1305
+
1252
1306
  /** Reads the organization's ceilings. Raw knob values are fine: they are validated here. */
1253
1307
  type GeneratorLimitsSource = () => Promise<{
1254
1308
  maxPasswordLength?: unknown;
@@ -1265,4 +1319,4 @@ declare function GenerateButton({ onUse, label, limits, disabled }: {
1265
1319
  disabled?: boolean;
1266
1320
  }): react.JSX.Element | null;
1267
1321
 
1268
- export { type ApiVaultPortOptions, CATEGORIES, type CategoryId, type CopyOptions, DEFAULT_LOCATION, type DefinitionField, type FieldHandling, type FieldKind, GenerateButton, HIDDEN_ITEM_TAG, type IdentityAccount, type IdentityMethod, type ItemDraft, LOCKED_MESSAGE, type NoticeKind, type Notify, type SaveResult, type SupabaseAuthLike, type TotpReading, type UriMatchMode, type UrlGuess, VaultApp, type VaultAppProps, type VaultAttachment, type VaultAuthenticator, type VaultClipboard, type VaultCustomField, type VaultDefinition, type VaultField, type VaultHostCapabilities, type VaultIdentity, type VaultItem, type VaultItemCapabilities, type VaultKnobs, type VaultLayout, type VaultLocation, type VaultLock, VaultLockedError, type VaultOrganizationRef, type VaultOwner, type VaultPort, type VaultSelection, type VaultSnapshot, type VaultSort, type VaultUserStateDoor, categoryOf, copyValue, createApiVaultPort, createSupabaseIdentity, createVaultKnobs, guardPort, inferFromUrl, isHiddenItem, locationFromParams, locationToParams, loginSiteOf, matchesQuery, needsRecentSignIn, parseDefinitions, sortItems };
1322
+ export { type ApiVaultPortOptions, CATEGORIES, CONFIRM_RETURN_KEY, type CategoryId, type Confirmed, type CopyOptions, DEFAULT_LOCATION, type DefinitionField, type FieldHandling, type FieldKind, GenerateButton, HIDDEN_ITEM_TAG, type IdentityAccount, IdentityGate, type IdentityMethod, type ItemDraft, LOCKED_MESSAGE, type NoticeKind, type Notify, type ReturnStore, type SaveResult, type SupabaseAuthLike, type SupabaseIdentityOptions, type TotpReading, type UriMatchMode, type UrlGuess, VaultApp, type VaultAppProps, type VaultAttachment, type VaultAuthenticator, type VaultClipboard, type VaultCustomField, type VaultDefinition, type VaultField, type VaultHostCapabilities, type VaultIdentity, type VaultItem, type VaultItemCapabilities, type VaultKnobs, type VaultLayout, type VaultLocation, type VaultLock, VaultLockedError, type VaultOrganizationRef, type VaultOwner, type VaultPort, type VaultSelection, type VaultSnapshot, type VaultSort, type VaultUserStateDoor, categoryOf, copyValue, createApiVaultPort, createSupabaseIdentity, createVaultKnobs, guardPort, inferFromUrl, isHiddenItem, locationFromParams, locationToParams, loginSiteOf, matchesQuery, needsRecentSignIn, parseDefinitions, siteDomainOf, sortItems, useConfirmed, wasCancelled };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as react from 'react';
2
+ import { ReactNode } from 'react';
2
3
  import { Look } from '@ai-matrx/design-system';
3
4
  import { KnobClient } from '@ai-matrx/data/knobs';
4
5
  import * as account from '@ai-matrx/api/account';
@@ -137,6 +138,11 @@ declare const isHiddenItem: (item: {
137
138
  }) => boolean;
138
139
  /** An item's website as people read it: `github.com` (no scheme, no `www.`), or "" when it has none. */
139
140
  declare function loginSiteOf(item: Pick<VaultItem, "loginUrls">): string;
141
+ /**
142
+ * The site a host belongs to, its registrable domain: `accounts.google.com` → `google.com`,
143
+ * `shop.example.co.uk` → `example.co.uk`. An address or a one-label host is returned as it is.
144
+ */
145
+ declare function siteDomainOf(host: string): string;
140
146
  declare function sortItems(items: readonly VaultItem[], sort: VaultSort): VaultItem[];
141
147
  interface NewSecretField {
142
148
  key: string;
@@ -253,6 +259,12 @@ interface VaultIdentity {
253
259
  withEmailCode(code: string): Promise<void>;
254
260
  /** A host-only path with no human step (the playground's dev server). */
255
261
  dev?: () => Promise<void>;
262
+ /**
263
+ * Run once when the page loads. After a provider confirmation left the page and came back, it
264
+ * checks the SAME person is signed in. A different account is signed out of this device and the
265
+ * sentence to show is returned; otherwise null.
266
+ */
267
+ checkReturn?: () => Promise<string | null>;
256
268
  }
257
269
  /** The slice of supabase-js `auth` this needs, so the package never depends on supabase-js itself. */
258
270
  interface SupabaseAuthLike {
@@ -318,12 +330,38 @@ interface SupabaseAuthLike {
318
330
  message: string;
319
331
  } | null;
320
332
  }>;
333
+ /** Used only when the host gives no `onDifferentPerson`: ends THIS device's session, never others. */
334
+ signOut?(o: {
335
+ scope: "local";
336
+ }): Promise<{
337
+ error: unknown;
338
+ }>;
321
339
  }
322
- /** THE identity confirmation for every host: give it the host's `supabase.auth`. */
323
- declare function createSupabaseIdentity(auth: SupabaseAuthLike, options?: {
340
+ /** Where the person confirming is remembered while the page is away at the provider. */
341
+ interface ReturnStore {
342
+ getItem(key: string): string | null;
343
+ setItem(key: string, value: string): void;
344
+ removeItem(key: string): void;
345
+ }
346
+ interface SupabaseIdentityOptions {
347
+ /** The host's accepted OAuth return address carrying this page. */
324
348
  redirectTo?: () => string;
325
349
  dev?: () => Promise<void>;
326
- }): VaultIdentity;
350
+ /**
351
+ * A provider confirmation came back signed in as someone else. The host ends that session on THIS
352
+ * device only (its own device-scoped sign-out) and tells the person; `message` says what happened.
353
+ * Without it the package signs out locally through `auth.signOut({ scope: "local" })`.
354
+ */
355
+ onDifferentPerson?: (message: string) => Promise<void> | void;
356
+ /** Default: the tab's `sessionStorage`. */
357
+ store?: ReturnStore;
358
+ /** Default `Date.now`. */
359
+ now?: () => number;
360
+ }
361
+ /** The key the expected person is kept under across the provider's redirect. */
362
+ declare const CONFIRM_RETURN_KEY = "matrx-vault:confirming-as";
363
+ /** THE identity confirmation for every host: give it the host's `supabase.auth`. */
364
+ declare function createSupabaseIdentity(auth: SupabaseAuthLike, options?: SupabaseIdentityOptions): VaultIdentity;
327
365
  /** True when the server refused because the sign-in is not recent enough. */
328
366
  declare function needsRecentSignIn(e: unknown): boolean;
329
367
 
@@ -1131,6 +1169,8 @@ interface VaultHostCapabilities {
1131
1169
  /** Desktop: the native passkey importer (file chooser, parsing and keys stay native). */
1132
1170
  nativeImport?: NativeImportBridge;
1133
1171
  openUrl?: (url: string) => void;
1172
+ /** The host's own sign-in, offered when the session has ended (the web app: its login page, back here after). */
1173
+ signIn?: () => void;
1134
1174
  /** A lock the host holds (`lock.ts`): while locked the vault shows Unlock and refuses every port call. */
1135
1175
  lock?: VaultLock;
1136
1176
  /** The host's clipboard: every copy goes through it; a secret is the host's to clear (`lock.ts`). */
@@ -1249,6 +1289,20 @@ interface ApiVaultPortOptions {
1249
1289
  }
1250
1290
  declare function createApiVaultPort(api: Api, options?: ApiVaultPortOptions): VaultPort;
1251
1291
 
1292
+ /**
1293
+ * Wrap any call that shows, copies or exports a secret. When the server answers "sign in again",
1294
+ * the person confirms it is them (Google, password, or an emailed code) and the call runs again —
1295
+ * they never see a dead "Authentication required" in the row.
1296
+ */
1297
+ type Confirmed = <T>(run: () => Promise<T>) => Promise<T>;
1298
+ declare function useConfirmed(): Confirmed;
1299
+ declare function IdentityGate({ identity, children }: {
1300
+ identity: VaultIdentity | undefined;
1301
+ children: ReactNode;
1302
+ }): react.JSX.Element;
1303
+ /** True for the rejection a cancelled confirmation produces (callers stay quiet about it). */
1304
+ declare const wasCancelled: (e: unknown) => boolean;
1305
+
1252
1306
  /** Reads the organization's ceilings. Raw knob values are fine: they are validated here. */
1253
1307
  type GeneratorLimitsSource = () => Promise<{
1254
1308
  maxPasswordLength?: unknown;
@@ -1265,4 +1319,4 @@ declare function GenerateButton({ onUse, label, limits, disabled }: {
1265
1319
  disabled?: boolean;
1266
1320
  }): react.JSX.Element | null;
1267
1321
 
1268
- export { type ApiVaultPortOptions, CATEGORIES, type CategoryId, type CopyOptions, DEFAULT_LOCATION, type DefinitionField, type FieldHandling, type FieldKind, GenerateButton, HIDDEN_ITEM_TAG, type IdentityAccount, type IdentityMethod, type ItemDraft, LOCKED_MESSAGE, type NoticeKind, type Notify, type SaveResult, type SupabaseAuthLike, type TotpReading, type UriMatchMode, type UrlGuess, VaultApp, type VaultAppProps, type VaultAttachment, type VaultAuthenticator, type VaultClipboard, type VaultCustomField, type VaultDefinition, type VaultField, type VaultHostCapabilities, type VaultIdentity, type VaultItem, type VaultItemCapabilities, type VaultKnobs, type VaultLayout, type VaultLocation, type VaultLock, VaultLockedError, type VaultOrganizationRef, type VaultOwner, type VaultPort, type VaultSelection, type VaultSnapshot, type VaultSort, type VaultUserStateDoor, categoryOf, copyValue, createApiVaultPort, createSupabaseIdentity, createVaultKnobs, guardPort, inferFromUrl, isHiddenItem, locationFromParams, locationToParams, loginSiteOf, matchesQuery, needsRecentSignIn, parseDefinitions, sortItems };
1322
+ export { type ApiVaultPortOptions, CATEGORIES, CONFIRM_RETURN_KEY, type CategoryId, type Confirmed, type CopyOptions, DEFAULT_LOCATION, type DefinitionField, type FieldHandling, type FieldKind, GenerateButton, HIDDEN_ITEM_TAG, type IdentityAccount, IdentityGate, type IdentityMethod, type ItemDraft, LOCKED_MESSAGE, type NoticeKind, type Notify, type ReturnStore, type SaveResult, type SupabaseAuthLike, type SupabaseIdentityOptions, type TotpReading, type UriMatchMode, type UrlGuess, VaultApp, type VaultAppProps, type VaultAttachment, type VaultAuthenticator, type VaultClipboard, type VaultCustomField, type VaultDefinition, type VaultField, type VaultHostCapabilities, type VaultIdentity, type VaultItem, type VaultItemCapabilities, type VaultKnobs, type VaultLayout, type VaultLocation, type VaultLock, VaultLockedError, type VaultOrganizationRef, type VaultOwner, type VaultPort, type VaultSelection, type VaultSnapshot, type VaultSort, type VaultUserStateDoor, categoryOf, copyValue, createApiVaultPort, createSupabaseIdentity, createVaultKnobs, guardPort, inferFromUrl, isHiddenItem, locationFromParams, locationToParams, loginSiteOf, matchesQuery, needsRecentSignIn, parseDefinitions, siteDomainOf, sortItems, useConfirmed, wasCancelled };