@tearleads/client-sdk 0.1.24 → 0.1.25

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 (85) hide show
  1. package/data/persistence/container-contents/containerContentsPersistenceTypes.d.ts +2 -0
  2. package/data/persistence/container-contents/containerContentsPersistenceTypes.js.map +1 -1
  3. package/data/persistence/container-contents/containerDeletionPersistence.js +3 -0
  4. package/data/persistence/container-contents/containerDeletionPersistence.js.map +1 -1
  5. package/data/persistence/container-contents/documentPurgePlacement.js +15 -0
  6. package/data/persistence/container-contents/documentPurgePlacement.js.map +1 -0
  7. package/data/persistence/documents/internal/documentDeletionPersistence.js +7 -0
  8. package/data/persistence/documents/internal/documentDeletionPersistence.js.map +1 -1
  9. package/data/persistence/documents/types.d.ts +2 -1
  10. package/data/persistence/documents/types.js.map +1 -1
  11. package/data/persistence/principalCurrentAcknowledgementPersistence.d.ts +13 -2
  12. package/data/persistence/principalCurrentAcknowledgementPersistence.js +36 -20
  13. package/data/persistence/principalCurrentAcknowledgementPersistence.js.map +1 -1
  14. package/index.d.ts +2 -2
  15. package/index.js +1 -1
  16. package/index.js.map +1 -1
  17. package/internal/api-client/ApiClient.d.ts +6 -2
  18. package/internal/api-client/ApiClient.js +4 -5
  19. package/internal/api-client/ApiClient.js.map +1 -1
  20. package/internal/api-client/apiRequestRuntime.d.ts +1 -2
  21. package/internal/api-client/apiRequestRuntime.js +12 -15
  22. package/internal/api-client/apiRequestRuntime.js.map +1 -1
  23. package/internal/api-client/routes/containers/mutations.js +2 -2
  24. package/internal/api-client/routes/containers/mutations.js.map +1 -1
  25. package/internal/api-client/sessionRefresh.js +14 -6
  26. package/internal/api-client/sessionRefresh.js.map +1 -1
  27. package/internal/api-client/sessionRenewal.js +54 -0
  28. package/internal/api-client/sessionRenewal.js.map +1 -0
  29. package/internal/validators/operation/containerMutations.d.ts +3 -0
  30. package/internal/validators/operation/containerMutations.js +1 -0
  31. package/internal/validators/operation/containerMutations.js.map +1 -1
  32. package/package.json +1 -1
  33. package/workflows/container-contents/container-state/delete.js +2 -0
  34. package/workflows/container-contents/container-state/delete.js.map +1 -1
  35. package/workflows/container-contents/container-state/localPurgeScope.js +49 -0
  36. package/workflows/container-contents/container-state/localPurgeScope.js.map +1 -0
  37. package/workflows/container-contents/container-state/purgeTree.js +42 -7
  38. package/workflows/container-contents/container-state/purgeTree.js.map +1 -1
  39. package/workflows/container-contents/container-state/purgeTreeCollection.js +11 -0
  40. package/workflows/container-contents/container-state/purgeTreeCollection.js.map +1 -1
  41. package/workflows/container-contents/container-state/purgeTreeContainerDeletion.js +4 -1
  42. package/workflows/container-contents/container-state/purgeTreeContainerDeletion.js.map +1 -1
  43. package/workflows/container-contents/container-state/purgeTreeScope.js +158 -0
  44. package/workflows/container-contents/container-state/purgeTreeScope.js.map +1 -0
  45. package/workflows/container-contents/container-state/readLocalPurgeScope.js +18 -0
  46. package/workflows/container-contents/container-state/readLocalPurgeScope.js.map +1 -0
  47. package/workflows/container-contents/container-state/remote.js +1 -0
  48. package/workflows/container-contents/container-state/remote.js.map +1 -1
  49. package/workflows/container-contents/container-state/types.js.map +1 -1
  50. package/workflows/container-contents/documentLinks.d.ts +4 -0
  51. package/workflows/container-contents/documentLinks.js +2 -0
  52. package/workflows/container-contents/documentLinks.js.map +1 -1
  53. package/workflows/container-contents/documentPurge.d.ts +6 -1
  54. package/workflows/container-contents/documentPurge.js +8 -1
  55. package/workflows/container-contents/documentPurge.js.map +1 -1
  56. package/workflows/documents/linkSet.d.ts +1 -0
  57. package/workflows/documents/linkSet.js +2 -0
  58. package/workflows/documents/linkSet.js.map +1 -1
  59. package/workflows/documents/linkSetRemote.d.ts +2 -0
  60. package/workflows/documents/linkSetRemote.js +3 -0
  61. package/workflows/documents/linkSetRemote.js.map +1 -1
  62. package/workflows/documents/purge.d.ts +3 -0
  63. package/workflows/documents/purge.js +7 -0
  64. package/workflows/documents/purge.js.map +1 -1
  65. package/workflows/documents/subtreePurgeScope.js +11 -0
  66. package/workflows/documents/subtreePurgeScope.js.map +1 -0
  67. package/workflows/organizations/acknowledgedPrincipalPredecessor.d.ts +39 -0
  68. package/workflows/organizations/acknowledgedPrincipalPredecessor.js +87 -0
  69. package/workflows/organizations/acknowledgedPrincipalPredecessor.js.map +1 -0
  70. package/workflows/organizations/currentOrganizationMutationRetention.js +13 -2
  71. package/workflows/organizations/currentOrganizationMutationRetention.js.map +1 -1
  72. package/workflows/organizations/index.d.ts +1 -0
  73. package/workflows/organizations/index.js +1 -0
  74. package/workflows/organizations/index.js.map +1 -1
  75. package/workflows/organizations/initialPrincipalCurrentPublication.js +3 -2
  76. package/workflows/organizations/initialPrincipalCurrentPublication.js.map +1 -1
  77. package/workflows/organizations/reconcileAcknowledgedPrincipalCurrent.js +63 -0
  78. package/workflows/organizations/reconcileAcknowledgedPrincipalCurrent.js.map +1 -0
  79. package/workflows/organizations/retainAcknowledgedPrincipalCurrents.d.ts +3 -0
  80. package/workflows/organizations/retainAcknowledgedPrincipalCurrents.js +33 -55
  81. package/workflows/organizations/retainAcknowledgedPrincipalCurrents.js.map +1 -1
  82. package/workflows/organizations/runtimeCurrentGroupMutation.js +13 -2
  83. package/workflows/organizations/runtimeCurrentGroupMutation.js.map +1 -1
  84. package/workflows/organizations/runtimeCurrentOrganizationMutation.js +2 -2
  85. package/workflows/organizations/runtimeCurrentOrganizationMutation.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"apiRequestRuntime.js","sourceRoot":"","sources":["apiRequestRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,oBAAoB,EACpB,eAAe,GAChB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EAErB,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,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BACJ,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM;YACtC,OAAO,EAAE,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,QAAQ,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,GAAG,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE;YAC/H,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,YAAY,EAAE,CAAC,SAAS,IAAI,YAAY;YACxC,oBAAoB,EAAE,KAAK,CAAC,gBAAgB,CAAC,oBAAoB;YACjE,mBAAmB,EAAE,KAAK,CAAC,gBAAgB,CAAC,mBAAmB;YAC/D,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM;YAC7B,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,UAAU;SACtC,CAAC,CAAC;IACL,CAAC;IAEO,4BAA4B,CAClC,KAA4C;QAE5C,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC7B,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;QAC1B,CAAC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;YACzB,GAAG,KAAK;YACR,YAAY,EAAE,KAAK,CAAC,OAAO,EAAE,YAAY,IAAI,IAAI;YACjD,mBAAmB,EAAE,SAAS;SAC/B,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import {\n authChallengeSigningBytes,\n canonicalAuthOrigin,\n} from \"@tearleads/crypto\";\nimport {\n apiVersionHeaderName,\n parseApiVersion,\n} from \"@tearleads/validators/operation\";\nimport {\n bindPrototypeMethods,\n describeErrorResponse,\n type ErrorResponseDescription,\n errorMessage,\n hasHeader,\n isSuccessfulResponse,\n normalizeApiBaseUrl,\n requestFailureKey,\n} from \"./requestInternals\";\nimport { responseBodyFailure } from \"./responseBodyFailure\";\nimport { shouldRetryAfterSessionExpired } from \"./sessionRefresh\";\nimport type {\n HttpMethod,\n OperationRequestFn,\n OperationRequestResultFn,\n OperationResponseRequestFn,\n RequestBody,\n RequestFailure,\n RequestFailureKind,\n RequestResult,\n RequestResultOptions,\n ResponseRequestValidationFailureInput,\n} from \"./types\";\n\ntype ExpiredHandler = () => boolean | Promise<boolean>;\ntype PaymentRequiredHandler = (organizationId: string | null) => void;\n\nexport class ApiRequestRuntime {\n private authToken: string | null = null;\n private sessionRenewal: { from: string; to: string } | null = null;\n private readonly baseUrl: string;\n private onError: ((message: string) => void) | null = null;\n private onNetworkError: (() => void) | null = null;\n private onNetworkSuccess: (() => void) | null = null;\n private onApiVersion: ((version: number) => void) | null = null;\n private onSessionExpired: ExpiredHandler | null = null;\n private onPaymentRequired: PaymentRequiredHandler | null = null;\n private readonly requestFailuresByKey = new Map<string, RequestFailure>();\n readonly request: OperationRequestFn;\n readonly requestResult: OperationRequestResultFn;\n readonly responseRequest: OperationResponseRequestFn;\n\n constructor(baseUrl?: string | null) {\n this.baseUrl = normalizeApiBaseUrl(baseUrl);\n bindPrototypeMethods(this, ApiRequestRuntime.prototype);\n this.request = this.makeRequest;\n this.requestResult = this.makeRequestResult;\n this.responseRequest = Object.assign(this.makeResponseRequest, {\n reportFailure: this.reportResponseRequestFailure,\n });\n }\n\n /**\n * The bytes a login challenge is signed as, bound to the API this client\n * addresses. A relative base URL resolves against the page, as its requests\n * do; with neither, there is no API origin to sign for.\n */\n authChallengeBytes(challengeHex: string, fingerprint: string): Uint8Array {\n let apiOrigin: string;\n try {\n apiOrigin = canonicalAuthOrigin(\n new URL(this.baseUrl || \"/\", globalThis.location?.href).href,\n );\n } catch {\n throw new Error(\"The API origin is unavailable for authentication\");\n }\n return authChallengeSigningBytes({ apiOrigin, challengeHex, fingerprint });\n }\n\n setOnError(handler: ((message: string) => void) | null): void {\n this.onError = handler;\n }\n\n setOnNetworkError(handler: (() => void) | null): void {\n this.onNetworkError = handler;\n }\n\n setOnNetworkSuccess(handler: (() => void) | null): void {\n this.onNetworkSuccess = handler;\n }\n\n /** Receives the build named by each response that carries one. */\n setOnApiVersion(handler: ((version: number) => void) | null): void {\n this.onApiVersion = handler;\n }\n\n setOnSessionExpired(handler: ExpiredHandler | null): void {\n this.onSessionExpired = handler;\n }\n\n setOnPaymentRequired(handler: PaymentRequiredHandler | null): void {\n this.onPaymentRequired = handler;\n }\n\n setAuthToken(token: string | null): boolean {\n const changed = this.authToken !== token;\n if (changed) this.sessionRenewal = null;\n this.authToken = token;\n return changed;\n }\n\n getAuthToken(): string | null {\n return this.authToken;\n }\n\n private async renewSession(): Promise<boolean> {\n const from = this.authToken;\n const renewed = await (this.onSessionExpired?.() ?? false);\n const to = this.authToken;\n if (renewed && from && to && from !== to)\n this.sessionRenewal = { from, to };\n return renewed;\n }\n\n getRequestFailure(input: { method: HttpMethod; path: string }) {\n return this.requestFailuresByKey.get(requestFailureKey(input)) ?? null;\n }\n\n private buildHeaders(\n body: RequestBody | undefined,\n headers: Record<string, string> | undefined,\n authToken: string | null,\n ): Record<string, string> {\n return {\n ...(authToken ? { Authorization: `Bearer ${authToken}` } : {}),\n ...(typeof body === \"string\" && !hasHeader(headers, \"Content-Type\")\n ? { \"Content-Type\": \"application/json\" }\n : {}),\n ...headers,\n };\n }\n\n private async makeRequest<T>(\n path: string,\n validator: (value: unknown) => value is T,\n method: HttpMethod,\n body: RequestBody | undefined,\n options: RequestResultOptions | undefined,\n failureOperation: Parameters<OperationRequestFn>[5],\n ): Promise<T | null> {\n const result = await this.makeRequestResult(\n path,\n validator,\n method,\n body,\n options,\n failureOperation,\n );\n return result.ok ? result.data : null;\n }\n\n private requestFailure(input: {\n code?: string | undefined;\n kind: RequestFailureKind;\n message: string;\n method: HttpMethod;\n path: string;\n reportErrors: boolean;\n requiredContainerIds?: RequestFailure[\"requiredContainerIds\"];\n stalePrincipalHeads: RequestFailure[\"stalePrincipalHeads\"];\n status: number | null;\n statusText: string;\n }): RequestFailure {\n const failure: RequestFailure = {\n ...(input.code === undefined ? {} : { code: input.code }),\n kind: input.kind,\n message: input.message,\n method: input.method,\n ok: false,\n path: input.path,\n report: () => {\n if (input.kind !== \"cancelled\") this.onError?.(input.message);\n },\n status: input.status,\n statusText: input.statusText,\n ...(input.stalePrincipalHeads\n ? { stalePrincipalHeads: input.stalePrincipalHeads }\n : {}),\n ...(input.requiredContainerIds\n ? { requiredContainerIds: input.requiredContainerIds }\n : {}),\n };\n this.requestFailuresByKey.set(\n requestFailureKey({ method: input.method, path: input.path }),\n failure,\n );\n\n if (input.reportErrors) {\n failure.report();\n }\n\n return failure;\n }\n\n private async makeRequestResult<T>(\n path: string,\n validator: (value: unknown) => value is T,\n method: HttpMethod,\n body: RequestBody | undefined,\n options: RequestResultOptions = {},\n failureOperation: Parameters<OperationRequestFn>[5],\n ): Promise<RequestResult<T>> {\n const responseResult = await this.makeResponseRequest(\n path,\n method,\n body,\n options,\n [],\n failureOperation,\n );\n if (!responseResult.ok) {\n return responseResult;\n }\n\n const response = responseResult.data;\n const reportErrors = options.reportErrors ?? true;\n let data: unknown;\n try {\n data = await response.json();\n } catch (error) {\n const failure = responseBodyFailure(error, errorMessage(error));\n if (failure.kind === \"network\") {\n this.onNetworkError?.();\n }\n return this.requestFailure({\n kind: failure.kind,\n message: `${method} ${path}: ${failure.message}`,\n method,\n path,\n reportErrors,\n stalePrincipalHeads: undefined,\n status: response.status,\n statusText: response.statusText,\n });\n }\n\n if (!validator(data)) {\n return this.requestFailure({\n kind: \"shape\",\n message: `Invalid response shape for ${path}`,\n method,\n path,\n reportErrors,\n stalePrincipalHeads: undefined,\n status: response.status,\n statusText: response.statusText,\n });\n }\n\n return { data, ok: true };\n }\n\n private async makeResponseRequest(\n path: string,\n method: HttpMethod,\n body: RequestBody | undefined,\n options: RequestResultOptions = {},\n additionalSuccessStatuses: readonly number[],\n failureOperation: Parameters<OperationResponseRequestFn>[5],\n ): Promise<RequestResult<Response>> {\n const authToken = this.authToken;\n const responseResult = await this.fetchResponseRequest(\n path,\n method,\n body,\n options,\n authToken,\n );\n if (!responseResult.ok) {\n return responseResult;\n }\n const response = responseResult.data;\n if (isSuccessfulResponse(response, additionalSuccessStatuses)) {\n this.requestFailuresByKey.delete(requestFailureKey({ method, path }));\n return { data: response, ok: true };\n }\n\n const errorDescription = await describeErrorResponse(\n response,\n failureOperation,\n options.expectedPaymentRequiredOrganizationId,\n );\n if (\n await shouldRetryAfterSessionExpired({\n authToken,\n body,\n code: errorDescription.code,\n getCurrentAuthToken: () => this.authToken,\n isKnownSessionRenewal: (from, to) =>\n this.sessionRenewal?.from === from && this.sessionRenewal.to === to,\n options,\n refreshSession: () => this.renewSession(),\n reportError: (message) => this.onError?.(message),\n responseStatus: response.status,\n })\n ) {\n if (options.retryOnSessionExpired === \"renew-only\")\n return this.httpFailure({\n errorDescription,\n failureOperation,\n method,\n options: {\n ...options,\n reportErrors: method === \"GET\" ? false : options.reportErrors,\n },\n path,\n response,\n });\n const retryResult = await this.fetchResponseRequest(\n path,\n method,\n body,\n options,\n this.authToken,\n );\n if (!retryResult.ok) {\n return retryResult;\n }\n const retryResponse = retryResult.data;\n if (isSuccessfulResponse(retryResponse, additionalSuccessStatuses)) {\n this.requestFailuresByKey.delete(requestFailureKey({ method, path }));\n return { data: retryResponse, ok: true };\n }\n\n return this.httpFailure({\n errorDescription: await describeErrorResponse(\n retryResponse,\n failureOperation,\n options.expectedPaymentRequiredOrganizationId,\n ),\n failureOperation,\n method,\n options,\n path,\n response: retryResponse,\n });\n }\n\n return this.httpFailure({\n errorDescription,\n failureOperation,\n method,\n options,\n path,\n response,\n });\n }\n\n private async fetchResponseRequest(\n path: string,\n method: HttpMethod,\n body: RequestBody | undefined,\n options: RequestResultOptions,\n authToken: string | null,\n ): Promise<RequestResult<Response>> {\n const reportErrors = options.reportErrors ?? true;\n const init: RequestInit & { duplex?: \"half\" } = {\n method,\n headers: this.buildHeaders(body, options.headers, authToken),\n ...(options.signal ? { signal: options.signal } : {}),\n };\n if (body !== undefined) {\n init.body = body;\n if (body instanceof ReadableStream) {\n init.duplex = \"half\";\n }\n }\n\n let response: Response;\n try {\n response = await fetch(`${this.baseUrl}${path}`, init);\n } catch (error) {\n const cancelled = options.signal?.aborted === true;\n if (!cancelled) this.onNetworkError?.();\n return this.requestFailure({\n ...(cancelled ? { code: \"request_aborted\" } : {}),\n kind: cancelled ? \"cancelled\" : \"network\",\n message: `${method} ${path}: ${errorMessage(error)}`,\n method,\n path,\n reportErrors: cancelled ? false : reportErrors,\n stalePrincipalHeads: undefined,\n status: null,\n statusText: \"\",\n });\n }\n\n this.onNetworkSuccess?.();\n const apiVersion = parseApiVersion(\n response.headers.get(apiVersionHeaderName),\n );\n if (apiVersion !== null) this.onApiVersion?.(apiVersion);\n return { data: response, ok: true };\n }\n\n private httpFailure(input: {\n readonly errorDescription: ErrorResponseDescription;\n readonly failureOperation: Parameters<OperationResponseRequestFn>[5];\n readonly method: HttpMethod;\n readonly options: RequestResultOptions;\n readonly path: string;\n readonly response: Response;\n }): RequestFailure {\n const cancelled = input.options.signal?.aborted === true;\n const reportErrors = input.options.reportErrors ?? true;\n if (\n !cancelled &&\n input.response.status === 402 &&\n input.failureOperation.failureResponses?.[402] &&\n input.errorDescription.paymentRequiredOrganizationId !== undefined &&\n input.errorDescription.paymentRequiredOrganizationId ===\n input.options.expectedPaymentRequiredOrganizationId\n ) {\n this.onPaymentRequired?.(\n input.errorDescription.paymentRequiredOrganizationId,\n );\n }\n return this.requestFailure({\n ...(cancelled\n ? { code: \"request_aborted\" }\n : input.errorDescription.code === null\n ? {}\n : { code: input.errorDescription.code }),\n kind: cancelled ? \"cancelled\" : \"http\",\n message: `${input.method} ${input.path}: ${input.response.status} ${input.response.statusText}${input.errorDescription.detail}`,\n method: input.method,\n path: input.path,\n reportErrors: !cancelled && reportErrors,\n requiredContainerIds: input.errorDescription.requiredContainerIds,\n stalePrincipalHeads: input.errorDescription.stalePrincipalHeads,\n status: input.response.status,\n statusText: input.response.statusText,\n });\n }\n\n private reportResponseRequestFailure(\n input: ResponseRequestValidationFailureInput,\n ): RequestFailure {\n if (input.kind === \"network\") {\n this.onNetworkError?.();\n }\n return this.requestFailure({\n ...input,\n reportErrors: input.options?.reportErrors ?? true,\n stalePrincipalHeads: undefined,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"apiRequestRuntime.js","sourceRoot":"","sources":["apiRequestRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,oBAAoB,EACpB,eAAe,GAChB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EAErB,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAiBzD,MAAM,OAAO,iBAAiB;IACpB,SAAS,GAAkB,IAAI,CAAC;IACvB,eAAe,GAAG,IAAI,qBAAqB,CAC1D,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CACrB,CAAC;IACe,OAAO,CAAS;IACzB,OAAO,GAAuC,IAAI,CAAC;IACnD,cAAc,GAAwB,IAAI,CAAC;IAC3C,gBAAgB,GAAwB,IAAI,CAAC;IAC7C,YAAY,GAAuC,IAAI,CAAC;IACxD,gBAAgB,GAA0B,IAAI,CAAC;IAC/C,iBAAiB,GAAkC,IAAI,CAAC;IAC/C,oBAAoB,GAAG,IAAI,GAAG,EAA0B,CAAC;IACjE,OAAO,CAAqB;IAC5B,aAAa,CAA2B;IACxC,eAAe,CA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Q,CAAC,UAAU;SACtC,CAAC,CAAC;IACL,CAAC;IAEO,4BAA4B,CAClC,KAA4C;QAE5C,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC7B,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;QAC1B,CAAC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;YACzB,GAAG,KAAK;YACR,YAAY,EAAE,KAAK,CAAC,OAAO,EAAE,YAAY,IAAI,IAAI;YACjD,mBAAmB,EAAE,SAAS;SAC/B,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import {\n authChallengeSigningBytes,\n canonicalAuthOrigin,\n} from \"@tearleads/crypto\";\nimport {\n apiVersionHeaderName,\n parseApiVersion,\n} from \"@tearleads/validators/operation\";\nimport {\n bindPrototypeMethods,\n describeErrorResponse,\n type ErrorResponseDescription,\n errorMessage,\n hasHeader,\n isSuccessfulResponse,\n normalizeApiBaseUrl,\n requestFailureKey,\n} from \"./requestInternals\";\nimport { responseBodyFailure } from \"./responseBodyFailure\";\nimport { shouldRetryAfterSessionExpired } from \"./sessionRefresh\";\nimport { SessionRenewalTracker } from \"./sessionRenewal\";\nimport type {\n HttpMethod,\n OperationRequestFn,\n OperationRequestResultFn,\n OperationResponseRequestFn,\n RequestBody,\n RequestFailure,\n RequestFailureKind,\n RequestResult,\n RequestResultOptions,\n ResponseRequestValidationFailureInput,\n} from \"./types\";\n\ntype ExpiredHandler = () => boolean | Promise<boolean>;\ntype PaymentRequiredHandler = (organizationId: string | null) => void;\n\nexport class ApiRequestRuntime {\n private authToken: string | null = null;\n private readonly sessionRenewals = new SessionRenewalTracker(\n () => this.authToken,\n );\n private readonly baseUrl: string;\n private onError: ((message: string) => void) | null = null;\n private onNetworkError: (() => void) | null = null;\n private onNetworkSuccess: (() => void) | null = null;\n private onApiVersion: ((version: number) => void) | null = null;\n private onSessionExpired: ExpiredHandler | null = null;\n private onPaymentRequired: PaymentRequiredHandler | null = null;\n private readonly requestFailuresByKey = new Map<string, RequestFailure>();\n readonly request: OperationRequestFn;\n readonly requestResult: OperationRequestResultFn;\n readonly responseRequest: OperationResponseRequestFn;\n\n constructor(baseUrl?: string | null) {\n this.baseUrl = normalizeApiBaseUrl(baseUrl);\n bindPrototypeMethods(this, ApiRequestRuntime.prototype);\n this.request = this.makeRequest;\n this.requestResult = this.makeRequestResult;\n this.responseRequest = Object.assign(this.makeResponseRequest, {\n reportFailure: this.reportResponseRequestFailure,\n });\n }\n\n /**\n * The bytes a login challenge is signed as, bound to the API this client\n * addresses. A relative base URL resolves against the page, as its requests\n * do; with neither, there is no API origin to sign for.\n */\n authChallengeBytes(challengeHex: string, fingerprint: string): Uint8Array {\n let apiOrigin: string;\n try {\n apiOrigin = canonicalAuthOrigin(\n new URL(this.baseUrl || \"/\", globalThis.location?.href).href,\n );\n } catch {\n throw new Error(\"The API origin is unavailable for authentication\");\n }\n return authChallengeSigningBytes({ apiOrigin, challengeHex, fingerprint });\n }\n\n setOnError(handler: ((message: string) => void) | null): void {\n this.onError = handler;\n }\n\n setOnNetworkError(handler: (() => void) | null): void {\n this.onNetworkError = handler;\n }\n\n setOnNetworkSuccess(handler: (() => void) | null): void {\n this.onNetworkSuccess = handler;\n }\n\n /** Receives the build named by each response that carries one. */\n setOnApiVersion(handler: ((version: number) => void) | null): void {\n this.onApiVersion = handler;\n }\n\n setOnSessionExpired(handler: ExpiredHandler | null): void {\n this.onSessionExpired = handler;\n }\n\n setOnPaymentRequired(handler: PaymentRequiredHandler | null): void {\n this.onPaymentRequired = handler;\n }\n\n setAuthToken(token: string | null): boolean {\n const changed = this.authToken !== token;\n if (changed) this.sessionRenewals.tokenChanged();\n this.authToken = token;\n return changed;\n }\n\n getAuthToken(): string | null {\n return this.authToken;\n }\n\n getRequestFailure(input: { method: HttpMethod; path: string }) {\n return this.requestFailuresByKey.get(requestFailureKey(input)) ?? null;\n }\n\n private buildHeaders(\n body: RequestBody | undefined,\n headers: Record<string, string> | undefined,\n authToken: string | null,\n ): Record<string, string> {\n return {\n ...(authToken ? { Authorization: `Bearer ${authToken}` } : {}),\n ...(typeof body === \"string\" && !hasHeader(headers, \"Content-Type\")\n ? { \"Content-Type\": \"application/json\" }\n : {}),\n ...headers,\n };\n }\n\n private async makeRequest<T>(\n path: string,\n validator: (value: unknown) => value is T,\n method: HttpMethod,\n body: RequestBody | undefined,\n options: RequestResultOptions | undefined,\n failureOperation: Parameters<OperationRequestFn>[5],\n ): Promise<T | null> {\n const result = await this.makeRequestResult(\n path,\n validator,\n method,\n body,\n options,\n failureOperation,\n );\n return result.ok ? result.data : null;\n }\n\n private requestFailure(input: {\n code?: string | undefined;\n kind: RequestFailureKind;\n message: string;\n method: HttpMethod;\n path: string;\n reportErrors: boolean;\n requiredContainerIds?: RequestFailure[\"requiredContainerIds\"];\n stalePrincipalHeads: RequestFailure[\"stalePrincipalHeads\"];\n status: number | null;\n statusText: string;\n }): RequestFailure {\n const failure: RequestFailure = {\n ...(input.code === undefined ? {} : { code: input.code }),\n kind: input.kind,\n message: input.message,\n method: input.method,\n ok: false,\n path: input.path,\n report: () => {\n if (input.kind !== \"cancelled\") this.onError?.(input.message);\n },\n status: input.status,\n statusText: input.statusText,\n ...(input.stalePrincipalHeads\n ? { stalePrincipalHeads: input.stalePrincipalHeads }\n : {}),\n ...(input.requiredContainerIds\n ? { requiredContainerIds: input.requiredContainerIds }\n : {}),\n };\n this.requestFailuresByKey.set(\n requestFailureKey({ method: input.method, path: input.path }),\n failure,\n );\n\n if (input.reportErrors) {\n failure.report();\n }\n\n return failure;\n }\n\n private async makeRequestResult<T>(\n path: string,\n validator: (value: unknown) => value is T,\n method: HttpMethod,\n body: RequestBody | undefined,\n options: RequestResultOptions = {},\n failureOperation: Parameters<OperationRequestFn>[5],\n ): Promise<RequestResult<T>> {\n const responseResult = await this.makeResponseRequest(\n path,\n method,\n body,\n options,\n [],\n failureOperation,\n );\n if (!responseResult.ok) {\n return responseResult;\n }\n\n const response = responseResult.data;\n const reportErrors = options.reportErrors ?? true;\n let data: unknown;\n try {\n data = await response.json();\n } catch (error) {\n const failure = responseBodyFailure(error, errorMessage(error));\n if (failure.kind === \"network\") {\n this.onNetworkError?.();\n }\n return this.requestFailure({\n kind: failure.kind,\n message: `${method} ${path}: ${failure.message}`,\n method,\n path,\n reportErrors,\n stalePrincipalHeads: undefined,\n status: response.status,\n statusText: response.statusText,\n });\n }\n\n if (!validator(data)) {\n return this.requestFailure({\n kind: \"shape\",\n message: `Invalid response shape for ${path}`,\n method,\n path,\n reportErrors,\n stalePrincipalHeads: undefined,\n status: response.status,\n statusText: response.statusText,\n });\n }\n\n return { data, ok: true };\n }\n\n private async makeResponseRequest(\n path: string,\n method: HttpMethod,\n body: RequestBody | undefined,\n options: RequestResultOptions = {},\n additionalSuccessStatuses: readonly number[],\n failureOperation: Parameters<OperationResponseRequestFn>[5],\n ): Promise<RequestResult<Response>> {\n const authToken = this.authToken;\n const responseResult = await this.fetchResponseRequest(\n path,\n method,\n body,\n options,\n authToken,\n );\n if (!responseResult.ok) {\n return responseResult;\n }\n const response = responseResult.data;\n if (isSuccessfulResponse(response, additionalSuccessStatuses)) {\n this.requestFailuresByKey.delete(requestFailureKey({ method, path }));\n return { data: response, ok: true };\n }\n\n const errorDescription = await describeErrorResponse(\n response,\n failureOperation,\n options.expectedPaymentRequiredOrganizationId,\n );\n const shouldRetry = await shouldRetryAfterSessionExpired({\n authToken,\n body,\n code: errorDescription.code,\n getCurrentAuthToken: () => this.authToken,\n isKnownSessionRenewal: (from, to) =>\n this.sessionRenewals.isKnown(from, to),\n pendingSessionRenewal: (from) => this.sessionRenewals.pending(from),\n options,\n refreshSession: () => this.sessionRenewals.renew(this.onSessionExpired),\n reportError: (message) => this.onError?.(message),\n responseStatus: response.status,\n });\n const retryAuthToken = this.sessionRenewals.currentToken(authToken);\n // Recheck after the awaited helper and the host's renewal notification.\n if (shouldRetry && retryAuthToken) {\n if (options.retryOnSessionExpired === \"renew-only\")\n return this.httpFailure({\n errorDescription,\n failureOperation,\n method,\n options: {\n ...options,\n reportErrors: method === \"GET\" ? false : options.reportErrors,\n },\n path,\n response,\n });\n const retryResult = await this.fetchResponseRequest(\n path,\n method,\n body,\n options,\n retryAuthToken,\n );\n if (!retryResult.ok) {\n return retryResult;\n }\n const retryResponse = retryResult.data;\n if (isSuccessfulResponse(retryResponse, additionalSuccessStatuses)) {\n this.requestFailuresByKey.delete(requestFailureKey({ method, path }));\n return { data: retryResponse, ok: true };\n }\n\n return this.httpFailure({\n errorDescription: await describeErrorResponse(\n retryResponse,\n failureOperation,\n options.expectedPaymentRequiredOrganizationId,\n ),\n failureOperation,\n method,\n options,\n path,\n response: retryResponse,\n });\n }\n\n return this.httpFailure({\n errorDescription,\n failureOperation,\n method,\n options,\n path,\n response,\n });\n }\n\n private async fetchResponseRequest(\n path: string,\n method: HttpMethod,\n body: RequestBody | undefined,\n options: RequestResultOptions,\n authToken: string | null,\n ): Promise<RequestResult<Response>> {\n const reportErrors = options.reportErrors ?? true;\n const init: RequestInit & { duplex?: \"half\" } = {\n method,\n headers: this.buildHeaders(body, options.headers, authToken),\n ...(options.signal ? { signal: options.signal } : {}),\n };\n if (body !== undefined) {\n init.body = body;\n if (body instanceof ReadableStream) {\n init.duplex = \"half\";\n }\n }\n\n let response: Response;\n try {\n response = await fetch(`${this.baseUrl}${path}`, init);\n } catch (error) {\n const cancelled = options.signal?.aborted === true;\n if (!cancelled) this.onNetworkError?.();\n return this.requestFailure({\n ...(cancelled ? { code: \"request_aborted\" } : {}),\n kind: cancelled ? \"cancelled\" : \"network\",\n message: `${method} ${path}: ${errorMessage(error)}`,\n method,\n path,\n reportErrors: cancelled ? false : reportErrors,\n stalePrincipalHeads: undefined,\n status: null,\n statusText: \"\",\n });\n }\n\n this.onNetworkSuccess?.();\n const apiVersion = parseApiVersion(\n response.headers.get(apiVersionHeaderName),\n );\n if (apiVersion !== null) this.onApiVersion?.(apiVersion);\n return { data: response, ok: true };\n }\n\n private httpFailure(input: {\n readonly errorDescription: ErrorResponseDescription;\n readonly failureOperation: Parameters<OperationResponseRequestFn>[5];\n readonly method: HttpMethod;\n readonly options: RequestResultOptions;\n readonly path: string;\n readonly response: Response;\n }): RequestFailure {\n const cancelled = input.options.signal?.aborted === true;\n const reportErrors = input.options.reportErrors ?? true;\n if (\n !cancelled &&\n input.response.status === 402 &&\n input.failureOperation.failureResponses?.[402] &&\n input.errorDescription.paymentRequiredOrganizationId !== undefined &&\n input.errorDescription.paymentRequiredOrganizationId ===\n input.options.expectedPaymentRequiredOrganizationId\n ) {\n this.onPaymentRequired?.(\n input.errorDescription.paymentRequiredOrganizationId,\n );\n }\n return this.requestFailure({\n ...(cancelled\n ? { code: \"request_aborted\" }\n : input.errorDescription.code === null\n ? {}\n : { code: input.errorDescription.code }),\n kind: cancelled ? \"cancelled\" : \"http\",\n message: `${input.method} ${input.path}: ${input.response.status} ${input.response.statusText}${input.errorDescription.detail}`,\n method: input.method,\n path: input.path,\n reportErrors: !cancelled && reportErrors,\n requiredContainerIds: input.errorDescription.requiredContainerIds,\n stalePrincipalHeads: input.errorDescription.stalePrincipalHeads,\n status: input.response.status,\n statusText: input.response.statusText,\n });\n }\n\n private reportResponseRequestFailure(\n input: ResponseRequestValidationFailureInput,\n ): RequestFailure {\n if (input.kind === \"network\") {\n this.onNetworkError?.();\n }\n return this.requestFailure({\n ...input,\n reportErrors: input.options?.reportErrors ?? true,\n stalePrincipalHeads: undefined,\n });\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { createContainerOperation, createContainerWithMetadataDocumentOperation, deleteContainerOperation, isContainerMutationOperationRequest, isContainerMutationOperationResponse, isContainerRotationOperationRequest, isContainerRotationOperationResponse, isCreateContainerWithMetadataDocumentOperationRequest, isCreateContainerWithMetadataDocumentOperationResponse, isDeleteContainerOperationResponse, moveContainerOperation, operationRequestPath, reciteContainerOperation, rekeyContainerOperation, revokeContainerOperation, shareContainerOperation, } from "../../../validators/operation/index.js";
1
+ import { createContainerOperation, createContainerWithMetadataDocumentOperation, deleteContainerOperation, isContainerMutationOperationRequest, isContainerMutationOperationResponse, isContainerRotationOperationRequest, isContainerRotationOperationResponse, isCreateContainerWithMetadataDocumentOperationRequest, isCreateContainerWithMetadataDocumentOperationResponse, isDeleteContainerOperationResponse, moveContainerOperation, operationRequestPath, operationRequestPathWithQuery, reciteContainerOperation, rekeyContainerOperation, revokeContainerOperation, shareContainerOperation, } from "../../../validators/operation/index.js";
2
2
  import { isContainerReciteRequest } from "../../../validators/request/index.js";
3
3
  import { isContainerReciteResponse } from "../../../validators/response/index.js";
4
4
  export const containerRecite = {
@@ -49,6 +49,6 @@ export const containerMove = {
49
49
  export const containerDelete = {
50
50
  isResponse: isDeleteContainerOperationResponse,
51
51
  method: deleteContainerOperation.method,
52
- path: (containerId) => operationRequestPath(deleteContainerOperation, { containerId }),
52
+ path: (containerId, requiredAncestorId) => operationRequestPathWithQuery(deleteContainerOperation, { containerId }, { requiredAncestorId }),
53
53
  };
54
54
  //# sourceMappingURL=mutations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mutations.js","sourceRoot":"","sources":["mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,4CAA4C,EAC5C,wBAAwB,EACxB,mCAAmC,EACnC,oCAAoC,EACpC,mCAAmC,EACnC,oCAAoC,EACpC,qDAAqD,EACrD,sDAAsD,EACtD,kCAAkC,EAClC,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,SAAS,EAAE,wBAAwB;IACnC,UAAU,EAAE,yBAAyB;IACrC,MAAM,EAAE,wBAAwB,CAAC,MAAM;IACvC,IAAI,EAAE,CAAC,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,EAAE,CAAC,WAAmB,EAAE,EAAE,CAC5B,qBAAqB,CAAC,uBAAuB,EAAE,WAAW,CAAC;CACrD,CAAC;AAEX,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,SAAS,EAAE,mCAAmC;IAC9C,UAAU,EAAE,oCAAoC;IAChD,MAAM,EAAE,sBAAsB,CAAC,MAAM;IACrC,IAAI,EAAE,CAAC,WAAmB,EAAE,EAAE,CAC5B,qBAAqB,CAAC,sBAAsB,EAAE,WAAW,CAAC;CACpD,CAAC;AAEX,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,UAAU,EAAE,kCAAkC;IAC9C,MAAM,EAAE,wBAAwB,CAAC,MAAM;IACvC,IAAI,EAAE,CAAC,WAAmB,EAAE,EAAE,CAC5B,oBAAoB,CAAC,wBAAwB,EAAE,EAAE,WAAW,EAAE,CAAC;CACzD,CAAC","sourcesContent":["import {\n createContainerOperation,\n createContainerWithMetadataDocumentOperation,\n deleteContainerOperation,\n isContainerMutationOperationRequest,\n isContainerMutationOperationResponse,\n isContainerRotationOperationRequest,\n isContainerRotationOperationResponse,\n isCreateContainerWithMetadataDocumentOperationRequest,\n isCreateContainerWithMetadataDocumentOperationResponse,\n isDeleteContainerOperationResponse,\n moveContainerOperation,\n operationRequestPath,\n reciteContainerOperation,\n rekeyContainerOperation,\n revokeContainerOperation,\n shareContainerOperation,\n} from \"@tearleads/validators/operation\";\nimport { isContainerReciteRequest } from \"@tearleads/validators/request\";\nimport { isContainerReciteResponse } from \"@tearleads/validators/response\";\n\nexport const containerRecite = {\n isRequest: isContainerReciteRequest,\n isResponse: isContainerReciteResponse,\n method: reciteContainerOperation.method,\n path: (containerId: string) =>\n operationRequestPath(reciteContainerOperation, { containerId }),\n} as const;\n\nexport const containerCreate = {\n isRequest: isContainerMutationOperationRequest,\n isResponse: isContainerMutationOperationResponse,\n method: createContainerOperation.method,\n path: operationRequestPath(createContainerOperation, {}),\n} as const;\n\nexport const containerCreateWithMetadataDocument = {\n isRequest: isCreateContainerWithMetadataDocumentOperationRequest,\n isResponse: isCreateContainerWithMetadataDocumentOperationResponse,\n method: createContainerWithMetadataDocumentOperation.method,\n path: operationRequestPath(createContainerWithMetadataDocumentOperation, {}),\n} as const;\n\nfunction containerMutationPath(\n operation:\n | typeof moveContainerOperation\n | typeof rekeyContainerOperation\n | typeof revokeContainerOperation\n | typeof shareContainerOperation,\n containerId: string,\n) {\n return operationRequestPath(operation, { containerId });\n}\n\nexport const containerShare = {\n isRequest: isContainerMutationOperationRequest,\n isResponse: isContainerMutationOperationResponse,\n method: shareContainerOperation.method,\n path: (containerId: string) =>\n containerMutationPath(shareContainerOperation, containerId),\n} as const;\n\nexport const containerRevoke = {\n isRequest: isContainerRotationOperationRequest,\n isResponse: isContainerRotationOperationResponse,\n method: revokeContainerOperation.method,\n path: (containerId: string) =>\n containerMutationPath(revokeContainerOperation, containerId),\n} as const;\n\nexport const containerRekey = {\n isRequest: isContainerRotationOperationRequest,\n isResponse: isContainerRotationOperationResponse,\n method: rekeyContainerOperation.method,\n path: (containerId: string) =>\n containerMutationPath(rekeyContainerOperation, containerId),\n} as const;\n\nexport const containerMove = {\n isRequest: isContainerRotationOperationRequest,\n isResponse: isContainerRotationOperationResponse,\n method: moveContainerOperation.method,\n path: (containerId: string) =>\n containerMutationPath(moveContainerOperation, containerId),\n} as const;\n\nexport const containerDelete = {\n isResponse: isDeleteContainerOperationResponse,\n method: deleteContainerOperation.method,\n path: (containerId: string) =>\n operationRequestPath(deleteContainerOperation, { containerId }),\n} as const;\n"]}
1
+ {"version":3,"file":"mutations.js","sourceRoot":"","sources":["mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,4CAA4C,EAC5C,wBAAwB,EACxB,mCAAmC,EACnC,oCAAoC,EACpC,mCAAmC,EACnC,oCAAoC,EACpC,qDAAqD,EACrD,sDAAsD,EACtD,kCAAkC,EAClC,sBAAsB,EACtB,oBAAoB,EACpB,6BAA6B,EAC7B,wBAA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B,SAAS,EAAE,mCAAmC;IAC9C,UAAU,EAAE,oCAAoC;IAChD,MAAM,EAAE,wBAAwB,CAAC,MAAM;IACvC,IAAI,EAAE,CAAC,WAAmB,EAAE,EAAE,CAC5B,qBAAqB,CAAC,wBAAwB,EAAE,WAAW,CAAC;CACtD,CAAC;AAEX,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,SAAS,EAAE,mCAAmC;IAC9C,UAAU,EAAE,oCAAoC;IAChD,MAAM,EAAE,uBAAuB,CAAC,MAAM;IACtC,IAAI,EAAE,CAAC,WAAmB,EAAE,EAAE,CAC5B,qBAAqB,CAAC,uBAAuB,EAAE,WAAW,CAAC;CACrD,CAAC;AAEX,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,SAAS,EAAE,mCAAmC;IAC9C,UAAU,EAAE,oCAAoC;IAChD,MAAM,EAAE,sBAAsB,CAAC,MAAM;IACrC,IAAI,EAAE,CAAC,WAAmB,EAAE,EAAE,CAC5B,qBAAqB,CAAC,sBAAsB,EAAE,WAAW,CAAC;CACpD,CAAC;AAEX,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,UAAU,EAAE,kCAAkC;IAC9C,MAAM,EAAE,wBAAwB,CAAC,MAAM;IACvC,IAAI,EAAE,CAAC,WAAmB,EAAE,kBAA2B,EAAE,EAAE,CACzD,6BAA6B,CAC3B,wBAAwB,EACxB,EAAE,WAAW,EAAE,EACf,EAAE,kBAAkB,EAAE,CACvB;CACK,CAAC","sourcesContent":["import {\n createContainerOperation,\n createContainerWithMetadataDocumentOperation,\n deleteContainerOperation,\n isContainerMutationOperationRequest,\n isContainerMutationOperationResponse,\n isContainerRotationOperationRequest,\n isContainerRotationOperationResponse,\n isCreateContainerWithMetadataDocumentOperationRequest,\n isCreateContainerWithMetadataDocumentOperationResponse,\n isDeleteContainerOperationResponse,\n moveContainerOperation,\n operationRequestPath,\n operationRequestPathWithQuery,\n reciteContainerOperation,\n rekeyContainerOperation,\n revokeContainerOperation,\n shareContainerOperation,\n} from \"@tearleads/validators/operation\";\nimport { isContainerReciteRequest } from \"@tearleads/validators/request\";\nimport { isContainerReciteResponse } from \"@tearleads/validators/response\";\n\nexport const containerRecite = {\n isRequest: isContainerReciteRequest,\n isResponse: isContainerReciteResponse,\n method: reciteContainerOperation.method,\n path: (containerId: string) =>\n operationRequestPath(reciteContainerOperation, { containerId }),\n} as const;\n\nexport const containerCreate = {\n isRequest: isContainerMutationOperationRequest,\n isResponse: isContainerMutationOperationResponse,\n method: createContainerOperation.method,\n path: operationRequestPath(createContainerOperation, {}),\n} as const;\n\nexport const containerCreateWithMetadataDocument = {\n isRequest: isCreateContainerWithMetadataDocumentOperationRequest,\n isResponse: isCreateContainerWithMetadataDocumentOperationResponse,\n method: createContainerWithMetadataDocumentOperation.method,\n path: operationRequestPath(createContainerWithMetadataDocumentOperation, {}),\n} as const;\n\nfunction containerMutationPath(\n operation:\n | typeof moveContainerOperation\n | typeof rekeyContainerOperation\n | typeof revokeContainerOperation\n | typeof shareContainerOperation,\n containerId: string,\n) {\n return operationRequestPath(operation, { containerId });\n}\n\nexport const containerShare = {\n isRequest: isContainerMutationOperationRequest,\n isResponse: isContainerMutationOperationResponse,\n method: shareContainerOperation.method,\n path: (containerId: string) =>\n containerMutationPath(shareContainerOperation, containerId),\n} as const;\n\nexport const containerRevoke = {\n isRequest: isContainerRotationOperationRequest,\n isResponse: isContainerRotationOperationResponse,\n method: revokeContainerOperation.method,\n path: (containerId: string) =>\n containerMutationPath(revokeContainerOperation, containerId),\n} as const;\n\nexport const containerRekey = {\n isRequest: isContainerRotationOperationRequest,\n isResponse: isContainerRotationOperationResponse,\n method: rekeyContainerOperation.method,\n path: (containerId: string) =>\n containerMutationPath(rekeyContainerOperation, containerId),\n} as const;\n\nexport const containerMove = {\n isRequest: isContainerRotationOperationRequest,\n isResponse: isContainerRotationOperationResponse,\n method: moveContainerOperation.method,\n path: (containerId: string) =>\n containerMutationPath(moveContainerOperation, containerId),\n} as const;\n\nexport const containerDelete = {\n isResponse: isDeleteContainerOperationResponse,\n method: deleteContainerOperation.method,\n path: (containerId: string, requiredAncestorId?: string) =>\n operationRequestPathWithQuery(\n deleteContainerOperation,\n { containerId },\n { requiredAncestorId },\n ),\n} as const;\n"]}
@@ -12,14 +12,21 @@ export async function shouldRetryAfterSessionExpired(input) {
12
12
  return false;
13
13
  }
14
14
  const currentAuthToken = input.getCurrentAuthToken();
15
- if (currentAuthToken && currentAuthToken !== input.authToken) {
16
- if (input.isKnownSessionRenewal(input.authToken, currentAuthToken))
15
+ let pending = null;
16
+ if (currentAuthToken !== input.authToken) {
17
+ const renewed = currentAuthToken !== null &&
18
+ input.isKnownSessionRenewal(input.authToken, currentAuthToken);
19
+ if (renewed) {
17
20
  input.options.onSessionRenewed?.();
18
- return true;
21
+ return true;
22
+ }
23
+ pending = input.pendingSessionRenewal(input.authToken);
24
+ if (!currentAuthToken || !pending)
25
+ return false;
19
26
  }
20
27
  let refreshed = false;
21
28
  try {
22
- refreshed = await input.refreshSession();
29
+ refreshed = await (pending ?? input.refreshSession());
23
30
  }
24
31
  catch (error) {
25
32
  if (error instanceof KeyingVerificationError) {
@@ -29,9 +36,10 @@ export async function shouldRetryAfterSessionExpired(input) {
29
36
  input.reportError(`Session refresh failed: ${errorMessage(error)}`);
30
37
  }
31
38
  }
39
+ const refreshedToken = input.getCurrentAuthToken();
32
40
  const renewed = Boolean(refreshed &&
33
- input.getCurrentAuthToken() &&
34
- input.getCurrentAuthToken() !== input.authToken);
41
+ refreshedToken &&
42
+ input.isKnownSessionRenewal(input.authToken, refreshedToken));
35
43
  if (renewed)
36
44
  input.options.onSessionRenewed?.();
37
45
  return renewed;
@@ -1 +1 @@
1
- {"version":3,"file":"sessionRefresh.js","sourceRoot":"","sources":["sessionRefresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EACL,YAAY,EACZ,yBAAyB,EACzB,uBAAuB,GACxB,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gBAAgB,EAAE,EAAE,CAAC;IAChD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport {\n errorMessage,\n isRefreshableSessionError,\n isReplayableRequestBody,\n} from \"./requestInternals\";\nimport type { RequestBody, RequestResultOptions } from \"./types\";\n\ninterface SessionRefreshInput {\n readonly authToken: string | null;\n readonly body: RequestBody | undefined;\n readonly code: string | null;\n readonly getCurrentAuthToken: () => string | null;\n readonly isKnownSessionRenewal: (from: string, to: string) => boolean;\n readonly options: RequestResultOptions;\n readonly refreshSession: () => boolean | Promise<boolean>;\n readonly reportError: (message: string) => void;\n readonly responseStatus: number;\n}\n\n/**\n * Decides whether a failed request can be replayed after session renewal.\n * Identity-integrity failures are terminal and must retain their typed error.\n */\nexport async function shouldRetryAfterSessionExpired(\n input: SessionRefreshInput,\n): Promise<boolean> {\n if (\n input.options.retryOnSessionExpired === false ||\n !input.authToken ||\n !isReplayableRequestBody(input.body) ||\n !isRefreshableSessionError(input.responseStatus, input.code)\n ) {\n return false;\n }\n\n const currentAuthToken = input.getCurrentAuthToken();\n if (currentAuthToken && currentAuthToken !== input.authToken) {\n if (input.isKnownSessionRenewal(input.authToken, currentAuthToken))\n input.options.onSessionRenewed?.();\n return true;\n }\n\n let refreshed = false;\n try {\n refreshed = await input.refreshSession();\n } catch (error: unknown) {\n if (error instanceof KeyingVerificationError) {\n throw error;\n }\n if (input.options.reportErrors ?? true) {\n input.reportError(`Session refresh failed: ${errorMessage(error)}`);\n }\n }\n\n const renewed = Boolean(\n refreshed &&\n input.getCurrentAuthToken() &&\n input.getCurrentAuthToken() !== input.authToken,\n );\n if (renewed) input.options.onSessionRenewed?.();\n return renewed;\n}\n"]}
1
+ {"version":3,"file":"sessionRefresh.js","sourceRoot":"","sources":["sessionRefresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EACL,YAAY,EACZ,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AAE,CAAC;YACvC,KAAK,CAAC,WAAW,CAAC,2BAA2B,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAED,MAAM,cAAc,GAAG,KAAK,CAAC,mBAAmB,EAAE,CAAC;IACnD,MAAM,OAAO,GAAG,OAAO,CACrB,SAAS;QACP,cAAc;QACd,KAAK,CAAC,qBAAqB,CAAC,KAAK,CAAC,SAAS,EAAE,cAAc,CAAC,CAC/D,CAAC;IACF,IAAI,OAAO;QAAE,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC;IAChD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport {\n errorMessage,\n isRefreshableSessionError,\n isReplayableRequestBody,\n} from \"./requestInternals\";\nimport type { RequestBody, RequestResultOptions } from \"./types\";\n\ninterface SessionRefreshInput {\n readonly authToken: string | null;\n readonly body: RequestBody | undefined;\n readonly code: string | null;\n readonly getCurrentAuthToken: () => string | null;\n readonly isKnownSessionRenewal: (from: string, to: string) => boolean;\n readonly options: RequestResultOptions;\n readonly pendingSessionRenewal: (from: string) => Promise<boolean> | null;\n readonly refreshSession: () => boolean | Promise<boolean>;\n readonly reportError: (message: string) => void;\n readonly responseStatus: number;\n}\n\n/**\n * Decides whether a failed request can be replayed after session renewal.\n * Identity-integrity failures are terminal and must retain their typed error.\n */\nexport async function shouldRetryAfterSessionExpired(\n input: SessionRefreshInput,\n): Promise<boolean> {\n if (\n input.options.retryOnSessionExpired === false ||\n !input.authToken ||\n !isReplayableRequestBody(input.body) ||\n !isRefreshableSessionError(input.responseStatus, input.code)\n ) {\n return false;\n }\n\n const currentAuthToken = input.getCurrentAuthToken();\n let pending: Promise<boolean> | null = null;\n if (currentAuthToken !== input.authToken) {\n const renewed =\n currentAuthToken !== null &&\n input.isKnownSessionRenewal(input.authToken, currentAuthToken);\n if (renewed) {\n input.options.onSessionRenewed?.();\n return true;\n }\n pending = input.pendingSessionRenewal(input.authToken);\n if (!currentAuthToken || !pending) return false;\n }\n\n let refreshed = false;\n try {\n refreshed = await (pending ?? input.refreshSession());\n } catch (error: unknown) {\n if (error instanceof KeyingVerificationError) {\n throw error;\n }\n if (input.options.reportErrors ?? true) {\n input.reportError(`Session refresh failed: ${errorMessage(error)}`);\n }\n }\n\n const refreshedToken = input.getCurrentAuthToken();\n const renewed = Boolean(\n refreshed &&\n refreshedToken &&\n input.isKnownSessionRenewal(input.authToken, refreshedToken),\n );\n if (renewed) input.options.onSessionRenewed?.();\n return renewed;\n}\n"]}
@@ -0,0 +1,54 @@
1
+ /** An identity change invalidates renewal evidence, including an awaited callback. */
2
+ export class SessionRenewalTracker {
3
+ readToken;
4
+ revision = 0;
5
+ known = null;
6
+ inFlight = null;
7
+ constructor(readToken) {
8
+ this.readToken = readToken;
9
+ }
10
+ tokenChanged() {
11
+ this.revision += 1;
12
+ this.known = null;
13
+ }
14
+ isKnown(from, to) {
15
+ return this.known?.from === from && this.known.to === to;
16
+ }
17
+ currentToken(from) {
18
+ const token = this.readToken();
19
+ return from && token && this.isKnown(from, token) ? token : null;
20
+ }
21
+ pending(from) {
22
+ return this.inFlight?.from === from ? this.inFlight.promise : null;
23
+ }
24
+ async renew(handler) {
25
+ const from = this.readToken();
26
+ if (!from)
27
+ return false;
28
+ const existing = this.pending(from);
29
+ if (existing)
30
+ return existing;
31
+ const pending = {
32
+ from,
33
+ promise: this.complete(from, this.revision, handler),
34
+ };
35
+ this.inFlight = pending;
36
+ try {
37
+ return await pending.promise;
38
+ }
39
+ finally {
40
+ if (this.inFlight === pending)
41
+ this.inFlight = null;
42
+ }
43
+ }
44
+ async complete(from, revision, handler) {
45
+ const renewed = await (handler?.() ?? false);
46
+ const to = this.readToken();
47
+ // The trusted callback authenticates the same identity and installs one
48
+ // replacement token. A second transition cannot borrow that renewal.
49
+ if (renewed && to && from !== to && this.revision === revision + 1)
50
+ this.known = { from, to };
51
+ return renewed;
52
+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;YAAE,OAAO,QAAQ,CAAC;QAC9B,MAAM,OAAO,GAAG;YACd,IAAI;YACJ,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC;SACrD,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC;YACH,OAAO,MAAM,OAAO,CAAC,OAAO,CAAC;QAC/B,CAAC;gBAAS,CAAC;YACT,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO;gBAAE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACtD,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,QAAQ,CACpB,IAAY,EACZ,QAAgB,EAChB,OAAqB;QAErB,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,EAAE,IAAI,KAAK,CAAC,CAAC;QAC7C,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAC5B,wEAAwE;QACxE,qEAAqE;QACrE,IAAI,OAAO,IAAI,EAAE,IAAI,IAAI,KAAK,EAAE,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ,GAAG,CAAC;YAChE,IAAI,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;QAC5B,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["type RenewSession = (() => boolean | Promise<boolean>) | null;\n\n/** An identity change invalidates renewal evidence, including an awaited callback. */\nexport class SessionRenewalTracker {\n private revision = 0;\n private known: { from: string; to: string } | null = null;\n private inFlight: { from: string; promise: Promise<boolean> } | null = null;\n\n constructor(private readonly readToken: () => string | null) {}\n\n tokenChanged(): void {\n this.revision += 1;\n this.known = null;\n }\n\n isKnown(from: string, to: string): boolean {\n return this.known?.from === from && this.known.to === to;\n }\n\n currentToken(from: string | null): string | null {\n const token = this.readToken();\n return from && token && this.isKnown(from, token) ? token : null;\n }\n\n pending(from: string): Promise<boolean> | null {\n return this.inFlight?.from === from ? this.inFlight.promise : null;\n }\n\n async renew(handler: RenewSession): Promise<boolean> {\n const from = this.readToken();\n if (!from) return false;\n const existing = this.pending(from);\n if (existing) return existing;\n const pending = {\n from,\n promise: this.complete(from, this.revision, handler),\n };\n this.inFlight = pending;\n try {\n return await pending.promise;\n } finally {\n if (this.inFlight === pending) this.inFlight = null;\n }\n }\n\n private async complete(\n from: string,\n revision: number,\n handler: RenewSession,\n ): Promise<boolean> {\n const renewed = await (handler?.() ?? false);\n const to = this.readToken();\n // The trusted callback authenticates the same identity and installs one\n // replacement token. A second transition cannot borrow that renewal.\n if (renewed && to && from !== to && this.revision === revision + 1)\n this.known = { from, to };\n return renewed;\n }\n}\n"]}
@@ -6244,6 +6244,9 @@ export declare const deleteContainerOperation: Omit<{
6244
6244
  containerId: z.ZodString;
6245
6245
  }, z.core.$strict>;
6246
6246
  readonly path: "/containers/{containerId}";
6247
+ readonly query: z.ZodObject<{
6248
+ requiredAncestorId: z.ZodOptional<z.ZodString>;
6249
+ }, z.core.$strict>;
6247
6250
  readonly responses: {
6248
6251
  readonly 200: z.ZodType<{
6249
6252
  containerId: string;
@@ -119,6 +119,7 @@ export const deleteContainerOperation = defineJsonOperation({
119
119
  method: "DELETE",
120
120
  params: ContainerMutationPathParamsSchema,
121
121
  path: "/containers/{containerId}",
122
+ query: z.strictObject({ requiredAncestorId: z.string().min(1).optional() }),
122
123
  responses: { 200: ContainerDeleteResponseSchema },
123
124
  });
124
125
  export const isContainerMutationOperationRequest = isContainerMutationRequest;
@@ -1 +1 @@
1
- {"version":3,"file":"containerMutations.js","sourceRoot":"","sources":["containerMutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kDAAkD,EAAE,MAAM,wCAAwC,CAAC;AAC5G,OAAO,EACL,gDAAgD,EAChD,8BAA8B,EAC9B,4BAA4B,EAC5B,8BAA8B,EAC9B,4CAA4C,EAC5C,0B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AClD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mCAAmC,GAAG,0BAA0B,CAAC;AAC9E,MAAM,CAAC,MAAM,oCAAoC,GAAG,2BAA2B,CAAC;AAChF,MAAM,CAAC,MAAM,mCAAmC,GAAG,0BAA0B,CAAC;AAC9E,MAAM,CAAC,MAAM,oCAAoC,GAAG,2BAA2B,CAAC;AAChF,MAAM,CAAC,MAAM,qDAAqD,GAChE,4CAA4C,CAAC;AAC/C,MAAM,CAAC,MAAM,sDAAsD,GACjE,6CAA6C,CAAC;AAChD,MAAM,CAAC,MAAM,kCAAkC,GAAG,yBAAyB,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { organizationProvisioningContainerKeyringRefinement } from \"../organizationProvisioningRefinements\";\nimport {\n ContainerCreateWithMetadataDocumentRequestSchema,\n ContainerMutationRequestSchema,\n ContainerReciteRequestSchema,\n ContainerRotationRequestSchema,\n isContainerCreateWithMetadataDocumentRequest,\n isContainerMutationRequest,\n isContainerRotationRequest,\n} from \"../request\";\nimport {\n ContainerCreateWithMetadataDocumentResponseSchema,\n ContainerDeleteResponseSchema,\n ContainerMutationFailureResponseSchema,\n ContainerMutationResponseSchema,\n ContainerNotFoundErrorResponseSchema,\n ContainerReciteResponseSchema,\n ContainerRotationResponseSchema,\n ErrorResponseSchema,\n isContainerCreateWithMetadataDocumentResponse,\n isContainerDeleteResponse,\n isContainerMutationResponse,\n isContainerRotationResponse,\n PaymentRequiredErrorResponseSchema,\n SessionFailureResponseSchema,\n} from \"../response\";\nimport { defineJsonOperation } from \"./definition\";\n\nconst EmptyContainerMutationPathParamsSchema = z.strictObject({});\n\nexport const ContainerMutationPathParamsSchema = z.strictObject({\n containerId: z.string(),\n});\n\nexport type ContainerMutationPathParams = z.infer<\n typeof ContainerMutationPathParamsSchema\n>;\n\nconst containerMutationFailureResponses = {\n 400: ErrorResponseSchema,\n 401: SessionFailureResponseSchema,\n 402: PaymentRequiredErrorResponseSchema,\n 403: ErrorResponseSchema,\n 404: ErrorResponseSchema,\n 409: ContainerMutationFailureResponseSchema,\n 500: ErrorResponseSchema,\n} as const;\n\nconst containerMutationFailureStatuses = [\n 400, 401, 402, 403, 404, 409, 500,\n] as const;\n\nconst containerMutationRuntimeRefinements = [\n organizationProvisioningContainerKeyringRefinement,\n] as const;\n\nexport const createContainerOperation = defineJsonOperation({\n auth: \"session\",\n body: ContainerMutationRequestSchema,\n failureResponses: containerMutationFailureResponses,\n failureStatuses: containerMutationFailureStatuses,\n id: \"containers.create\",\n method: \"POST\",\n params: EmptyContainerMutationPathParamsSchema,\n path: \"/containers\",\n responses: { 200: ContainerMutationResponseSchema },\n runtimeRefinements: containerMutationRuntimeRefinements,\n});\n\nexport const createContainerWithMetadataDocumentOperation = defineJsonOperation(\n {\n auth: \"session\",\n body: ContainerCreateWithMetadataDocumentRequestSchema,\n failureResponses: {\n ...containerMutationFailureResponses,\n 503: ErrorResponseSchema,\n },\n failureStatuses: [...containerMutationFailureStatuses, 503],\n id: \"containers.withMetadataDocument.create\",\n method: \"POST\",\n params: EmptyContainerMutationPathParamsSchema,\n path: \"/containers/with-metadata-document\",\n responses: { 200: ContainerCreateWithMetadataDocumentResponseSchema },\n runtimeRefinements: containerMutationRuntimeRefinements,\n },\n);\n\nfunction defineContainerMutationOperation<\n const Id extends string,\n const Path extends `/${string}`,\n>(input: { readonly id: Id; readonly path: Path }) {\n return defineJsonOperation({\n auth: \"session\",\n body: ContainerMutationRequestSchema,\n failureResponses: containerMutationFailureResponses,\n failureStatuses: containerMutationFailureStatuses,\n id: input.id,\n method: \"POST\",\n params: ContainerMutationPathParamsSchema,\n path: input.path,\n responses: { 200: ContainerMutationResponseSchema },\n runtimeRefinements: containerMutationRuntimeRefinements,\n });\n}\n\n/**\n * Rekey, revoke, and move mint a new key epoch, so they alone may carry the\n * descendant rekeys that must commit with them.\n */\nfunction defineContainerRotationOperation<\n const Id extends string,\n const Path extends `/${string}`,\n>(input: { readonly id: Id; readonly path: Path }) {\n return defineJsonOperation({\n auth: \"session\",\n body: ContainerRotationRequestSchema,\n failureResponses: containerMutationFailureResponses,\n failureStatuses: containerMutationFailureStatuses,\n id: input.id,\n method: \"POST\",\n params: ContainerMutationPathParamsSchema,\n path: input.path,\n responses: { 200: ContainerRotationResponseSchema },\n runtimeRefinements: containerMutationRuntimeRefinements,\n });\n}\n\nexport const shareContainerOperation = defineContainerMutationOperation({\n id: \"containers.share\",\n path: \"/containers/{containerId}/share\",\n});\n\nexport const reciteContainerOperation = defineJsonOperation({\n auth: \"session\",\n body: ContainerReciteRequestSchema,\n failureResponses: containerMutationFailureResponses,\n failureStatuses: containerMutationFailureStatuses,\n id: \"containers.recite\",\n method: \"POST\",\n params: ContainerMutationPathParamsSchema,\n path: \"/containers/{containerId}/recite\",\n responses: { 200: ContainerReciteResponseSchema },\n});\n\nexport const revokeContainerOperation = defineContainerRotationOperation({\n id: \"containers.revoke\",\n path: \"/containers/{containerId}/revoke\",\n});\n\nexport const rekeyContainerOperation = defineContainerRotationOperation({\n id: \"containers.rekey\",\n path: \"/containers/{containerId}/rekey\",\n});\n\nexport const moveContainerOperation = defineContainerRotationOperation({\n id: \"containers.move\",\n path: \"/containers/{containerId}/move\",\n});\n\nexport const deleteContainerOperation = defineJsonOperation({\n auth: \"session\",\n failureResponses: {\n ...containerMutationFailureResponses,\n 404: ContainerNotFoundErrorResponseSchema,\n },\n failureStatuses: containerMutationFailureStatuses,\n id: \"containers.delete\",\n method: \"DELETE\",\n params: ContainerMutationPathParamsSchema,\n path: \"/containers/{containerId}\",\n responses: { 200: ContainerDeleteResponseSchema },\n});\n\nexport const isContainerMutationOperationRequest = isContainerMutationRequest;\nexport const isContainerMutationOperationResponse = isContainerMutationResponse;\nexport const isContainerRotationOperationRequest = isContainerRotationRequest;\nexport const isContainerRotationOperationResponse = isContainerRotationResponse;\nexport const isCreateContainerWithMetadataDocumentOperationRequest =\n isContainerCreateWithMetadataDocumentRequest;\nexport const isCreateContainerWithMetadataDocumentOperationResponse =\n isContainerCreateWithMetadataDocumentResponse;\nexport const isDeleteContainerOperationResponse = isContainerDeleteResponse;\n"]}
1
+ {"version":3,"file":"containerMutations.js","sourceRoot":"","sources":["containerMutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kDAAkD,EAAE,MAAM,wCAAwC,CAAC;AAC5G,OAAO,EACL,gDAAgD,EAChD,8BAA8B,EAC9B,4BAA4B,EAC5B,8BAA8B,EAC9B,4CAA4C,EAC5C,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,iDAAiD,EACjD,6BAA6B,EAC7B,sCAAsC,EACtC,+BAA+B,EAC/B,oCAAoC,EACpC,6BAA6B,EAC7B,+BAA+B,EAC/B,mBAAmB,EACnB,6CAA6C,EAC7C,yBAAyB,EACzB,2BAA2B,EAC3B,2BAA2B,EAC3B,kCAAkC,EAClC,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD,MAAM,sCAAsC,GAAG,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;AAElE,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,CAAC,YAAY,CAAC;IAC9D,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;CACxB,CAAC,CAAC;AAMH,MAAM,iCAAiC,GAAG;IACxC,GAAG,EAAE,mBAAmB;IACxB,GAAG,EAAE,4BAA4B;IACjC,GAAG,EAAE,kCAAkC;IACvC,GAAG,EAAE,mBAAmB;IACxB,GAAG,EAAE,mBAAmB;IACxB,GAAG,EAAE,sCAAsC;IAC3C,GAAG,EAAE,mBAAmB;CAChB,CAAC;AAEX,MAAM,gCAAgC,GAAG;IACvC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;CACzB,CAAC;AAEX,MAAM,m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AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,mBAAmB,CAAC;IAC1D,IAAI,EAAE,SAAS;IACf,gBAAgB,EAAE;QAChB,GAAG,iCAAiC;QACpC,GAAG,EAAE,oCAAoC;KAC1C;IACD,eAAe,EAAE,gCAAgC;IACjD,EAAE,EAAE,mBAAmB;IACvB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,iCAAiC;IACzC,IAAI,EAAE,2BAA2B;IACjC,KAAK,EAAE,CAAC,CAAC,YAAY,CAAC,EAAE,kBAAkB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC3E,SAAS,EAAE,EAAE,GAAG,EAAE,6BAA6B,EAAE;CAClD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mCAAmC,GAAG,0BAA0B,CAAC;AAC9E,MAAM,CAAC,MAAM,oCAAoC,GAAG,2BAA2B,CAAC;AAChF,MAAM,CAAC,MAAM,mCAAmC,GAAG,0BAA0B,CAAC;AAC9E,MAAM,CAAC,MAAM,oCAAoC,GAAG,2BAA2B,CAAC;AAChF,MAAM,CAAC,MAAM,qDAAqD,GAChE,4CAA4C,CAAC;AAC/C,MAAM,CAAC,MAAM,sDAAsD,GACjE,6CAA6C,CAAC;AAChD,MAAM,CAAC,MAAM,kCAAkC,GAAG,yBAAyB,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { organizationProvisioningContainerKeyringRefinement } from \"../organizationProvisioningRefinements\";\nimport {\n ContainerCreateWithMetadataDocumentRequestSchema,\n ContainerMutationRequestSchema,\n ContainerReciteRequestSchema,\n ContainerRotationRequestSchema,\n isContainerCreateWithMetadataDocumentRequest,\n isContainerMutationRequest,\n isContainerRotationRequest,\n} from \"../request\";\nimport {\n ContainerCreateWithMetadataDocumentResponseSchema,\n ContainerDeleteResponseSchema,\n ContainerMutationFailureResponseSchema,\n ContainerMutationResponseSchema,\n ContainerNotFoundErrorResponseSchema,\n ContainerReciteResponseSchema,\n ContainerRotationResponseSchema,\n ErrorResponseSchema,\n isContainerCreateWithMetadataDocumentResponse,\n isContainerDeleteResponse,\n isContainerMutationResponse,\n isContainerRotationResponse,\n PaymentRequiredErrorResponseSchema,\n SessionFailureResponseSchema,\n} from \"../response\";\nimport { defineJsonOperation } from \"./definition\";\n\nconst EmptyContainerMutationPathParamsSchema = z.strictObject({});\n\nexport const ContainerMutationPathParamsSchema = z.strictObject({\n containerId: z.string(),\n});\n\nexport type ContainerMutationPathParams = z.infer<\n typeof ContainerMutationPathParamsSchema\n>;\n\nconst containerMutationFailureResponses = {\n 400: ErrorResponseSchema,\n 401: SessionFailureResponseSchema,\n 402: PaymentRequiredErrorResponseSchema,\n 403: ErrorResponseSchema,\n 404: ErrorResponseSchema,\n 409: ContainerMutationFailureResponseSchema,\n 500: ErrorResponseSchema,\n} as const;\n\nconst containerMutationFailureStatuses = [\n 400, 401, 402, 403, 404, 409, 500,\n] as const;\n\nconst containerMutationRuntimeRefinements = [\n organizationProvisioningContainerKeyringRefinement,\n] as const;\n\nexport const createContainerOperation = defineJsonOperation({\n auth: \"session\",\n body: ContainerMutationRequestSchema,\n failureResponses: containerMutationFailureResponses,\n failureStatuses: containerMutationFailureStatuses,\n id: \"containers.create\",\n method: \"POST\",\n params: EmptyContainerMutationPathParamsSchema,\n path: \"/containers\",\n responses: { 200: ContainerMutationResponseSchema },\n runtimeRefinements: containerMutationRuntimeRefinements,\n});\n\nexport const createContainerWithMetadataDocumentOperation = defineJsonOperation(\n {\n auth: \"session\",\n body: ContainerCreateWithMetadataDocumentRequestSchema,\n failureResponses: {\n ...containerMutationFailureResponses,\n 503: ErrorResponseSchema,\n },\n failureStatuses: [...containerMutationFailureStatuses, 503],\n id: \"containers.withMetadataDocument.create\",\n method: \"POST\",\n params: EmptyContainerMutationPathParamsSchema,\n path: \"/containers/with-metadata-document\",\n responses: { 200: ContainerCreateWithMetadataDocumentResponseSchema },\n runtimeRefinements: containerMutationRuntimeRefinements,\n },\n);\n\nfunction defineContainerMutationOperation<\n const Id extends string,\n const Path extends `/${string}`,\n>(input: { readonly id: Id; readonly path: Path }) {\n return defineJsonOperation({\n auth: \"session\",\n body: ContainerMutationRequestSchema,\n failureResponses: containerMutationFailureResponses,\n failureStatuses: containerMutationFailureStatuses,\n id: input.id,\n method: \"POST\",\n params: ContainerMutationPathParamsSchema,\n path: input.path,\n responses: { 200: ContainerMutationResponseSchema },\n runtimeRefinements: containerMutationRuntimeRefinements,\n });\n}\n\n/**\n * Rekey, revoke, and move mint a new key epoch, so they alone may carry the\n * descendant rekeys that must commit with them.\n */\nfunction defineContainerRotationOperation<\n const Id extends string,\n const Path extends `/${string}`,\n>(input: { readonly id: Id; readonly path: Path }) {\n return defineJsonOperation({\n auth: \"session\",\n body: ContainerRotationRequestSchema,\n failureResponses: containerMutationFailureResponses,\n failureStatuses: containerMutationFailureStatuses,\n id: input.id,\n method: \"POST\",\n params: ContainerMutationPathParamsSchema,\n path: input.path,\n responses: { 200: ContainerRotationResponseSchema },\n runtimeRefinements: containerMutationRuntimeRefinements,\n });\n}\n\nexport const shareContainerOperation = defineContainerMutationOperation({\n id: \"containers.share\",\n path: \"/containers/{containerId}/share\",\n});\n\nexport const reciteContainerOperation = defineJsonOperation({\n auth: \"session\",\n body: ContainerReciteRequestSchema,\n failureResponses: containerMutationFailureResponses,\n failureStatuses: containerMutationFailureStatuses,\n id: \"containers.recite\",\n method: \"POST\",\n params: ContainerMutationPathParamsSchema,\n path: \"/containers/{containerId}/recite\",\n responses: { 200: ContainerReciteResponseSchema },\n});\n\nexport const revokeContainerOperation = defineContainerRotationOperation({\n id: \"containers.revoke\",\n path: \"/containers/{containerId}/revoke\",\n});\n\nexport const rekeyContainerOperation = defineContainerRotationOperation({\n id: \"containers.rekey\",\n path: \"/containers/{containerId}/rekey\",\n});\n\nexport const moveContainerOperation = defineContainerRotationOperation({\n id: \"containers.move\",\n path: \"/containers/{containerId}/move\",\n});\n\nexport const deleteContainerOperation = defineJsonOperation({\n auth: \"session\",\n failureResponses: {\n ...containerMutationFailureResponses,\n 404: ContainerNotFoundErrorResponseSchema,\n },\n failureStatuses: containerMutationFailureStatuses,\n id: \"containers.delete\",\n method: \"DELETE\",\n params: ContainerMutationPathParamsSchema,\n path: \"/containers/{containerId}\",\n query: z.strictObject({ requiredAncestorId: z.string().min(1).optional() }),\n responses: { 200: ContainerDeleteResponseSchema },\n});\n\nexport const isContainerMutationOperationRequest = isContainerMutationRequest;\nexport const isContainerMutationOperationResponse = isContainerMutationResponse;\nexport const isContainerRotationOperationRequest = isContainerRotationRequest;\nexport const isContainerRotationOperationResponse = isContainerRotationResponse;\nexport const isCreateContainerWithMetadataDocumentOperationRequest =\n isContainerCreateWithMetadataDocumentRequest;\nexport const isCreateContainerWithMetadataDocumentOperationResponse =\n isContainerCreateWithMetadataDocumentResponse;\nexport const isDeleteContainerOperationResponse = isContainerDeleteResponse;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tearleads/client-sdk",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "React-free Tearleads client runtime: local SQLite persistence, keys, sync, encrypted blobs, and domain workflows.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -5,6 +5,7 @@ export async function deleteContainerState(input) {
5
5
  if (isRemoteContainer) {
6
6
  const deletedRemoteContainer = await deleteRemoteContainer({
7
7
  containerId: input.containerState.container.id,
8
+ requiredAncestorId: input.requiredAncestorId,
8
9
  organizationId: input.containerState.container.organizationId,
9
10
  runtime: input.runtime,
10
11
  });
@@ -22,6 +23,7 @@ export async function deleteContainerState(input) {
22
23
  updatedAt: deletedAt ?? new Date().toISOString(),
23
24
  },
24
25
  ], {
26
+ beforeDeleteInTransaction: input.beforeDeleteInTransaction,
25
27
  expectedContainers: [
26
28
  { containerId, expectedContainer: input.containerState.container },
27
29
  ],
@@ -1 +1 @@
1
- {"version":3,"file":"delete.js","sourceRoot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AAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,gBAAgB,CAAC;AACjE,CAAC","sourcesContent":["import type { ContainerContentsPersistence } from \"../containerPersistence\";\nimport type { ContainerState } from \"../remoteHydration\";\nimport { deleteRemoteContainer } from \"./remote\";\nimport type { ContainerWorkflowRuntime } from \"./types\";\n\ntype DeleteContainerStateResult =\n | \"deleted\"\n | \"local-conflict\"\n | \"remote-deleted\"\n | \"remote-failed\";\n\nexport async function deleteContainerState(input: {\n containerState: ContainerState;\n persistence: ContainerContentsPersistence;\n runtime: ContainerWorkflowRuntime;\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<DeleteContainerStateResult> {\n const isRemoteContainer = Boolean(input.containerState.record.documentId);\n let deletedAt: string | undefined;\n\n if (isRemoteContainer) {\n const deletedRemoteContainer = await deleteRemoteContainer({\n containerId: input.containerState.container.id,\n organizationId: input.containerState.container.organizationId,\n runtime: input.runtime,\n });\n if (!deletedRemoteContainer) {\n return \"remote-failed\";\n }\n deletedAt = deletedRemoteContainer.deletedAt;\n }\n const execSql = input.runtime.infra.execSql;\n const containerId = input.containerState.container.id;\n const deletedContainerIds = await input.persistence.deleteContainers(\n execSql,\n [\n {\n containerId,\n reason: \"deleted\",\n updatedAt: deletedAt ?? new Date().toISOString(),\n },\n ],\n {\n expectedContainers: [\n { containerId, expectedContainer: input.containerState.container },\n ],\n stillCurrent: input.stillCurrent,\n },\n );\n if (deletedContainerIds.includes(containerId)) return \"deleted\";\n return isRemoteContainer ? \"remote-deleted\" : \"local-conflict\";\n}\n"]}
1
+ {"version":3,"file":"delete.js","sourceRoot":"","sources":["delete.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AASjD,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,KAS1C;IACC,MAAM,iBAAiB,GAAG,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC1E,IAAI,SAA6B,CAAC;IAElC,IAAI,iBAAiB,EAAE,CAAC;QACtB,MAAM,sBAAsB,GAAG,MAAM,qBAAqB,CAAC;YACzD,WAAW,EAAE,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE;YAC9C,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;YAC5C,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,cAAc;YAC7D,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB,CAAC,CAAC;QACH,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAC5B,OAAO,eAAe,CAAC;QACzB,CAAC;QACD,SAAS,GAAG,sBAAsB,CAAC,SAAS,CAAC;IAC/C,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;IAC5C,MAAM,WAAW,GAAG,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,CAAC;IACtD,MAAM,mBAAmB,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAClE,OAAO,EACP;QACE;YACE,WAAW;YACX,MAAM,EAAE,SAAS;YACjB,SAAS,EAAE,SAAS,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACjD;KACF,EACD;QACE,yBAAyB,EAAE,KAAK,CAAC,yBAAyB;QAC1D,kBAAkB,EAAE;YAClB,EAAE,WAAW,EAAE,iBAAiB,EAAE,KAAK,CAAC,cAAc,CAAC,SAAS,EAAE;SACnE;QACD,YAAY,EAAE,KAAK,CAAC,YAAY;KACjC,CACF,CAAC;IACF,IAAI,mBAAmB,CAAC,QAAQ,CAAC,WAAW,CAAC;QAAE,OAAO,SAAS,CAAC;IAChE,OAAO,iBAAiB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,gBAAgB,CAAC;AACjE,CAAC","sourcesContent":["import type { ContainerContentsPersistence } from \"../containerPersistence\";\nimport type { ContainerState } from \"../remoteHydration\";\nimport { deleteRemoteContainer } from \"./remote\";\nimport type { ContainerWorkflowRuntime } from \"./types\";\n\ntype DeleteContainerStateResult =\n | \"deleted\"\n | \"local-conflict\"\n | \"remote-deleted\"\n | \"remote-failed\";\n\nexport async function deleteContainerState(input: {\n beforeDeleteInTransaction?: NonNullable<\n Parameters<ContainerContentsPersistence[\"deleteContainers\"]>[2]\n >[\"beforeDeleteInTransaction\"];\n containerState: ContainerState;\n persistence: ContainerContentsPersistence;\n requiredAncestorId?: string | undefined;\n runtime: ContainerWorkflowRuntime;\n stillCurrent?: (() => boolean) | undefined;\n}): Promise<DeleteContainerStateResult> {\n const isRemoteContainer = Boolean(input.containerState.record.documentId);\n let deletedAt: string | undefined;\n\n if (isRemoteContainer) {\n const deletedRemoteContainer = await deleteRemoteContainer({\n containerId: input.containerState.container.id,\n requiredAncestorId: input.requiredAncestorId,\n organizationId: input.containerState.container.organizationId,\n runtime: input.runtime,\n });\n if (!deletedRemoteContainer) {\n return \"remote-failed\";\n }\n deletedAt = deletedRemoteContainer.deletedAt;\n }\n const execSql = input.runtime.infra.execSql;\n const containerId = input.containerState.container.id;\n const deletedContainerIds = await input.persistence.deleteContainers(\n execSql,\n [\n {\n containerId,\n reason: \"deleted\",\n updatedAt: deletedAt ?? new Date().toISOString(),\n },\n ],\n {\n beforeDeleteInTransaction: input.beforeDeleteInTransaction,\n expectedContainers: [\n { containerId, expectedContainer: input.containerState.container },\n ],\n stillCurrent: input.stillCurrent,\n },\n );\n if (deletedContainerIds.includes(containerId)) return \"deleted\";\n return isRemoteContainer ? \"remote-deleted\" : \"local-conflict\";\n}\n"]}
@@ -0,0 +1,49 @@
1
+ import { hasUnsettledDocumentPlacement } from "../../../data/persistence/container-contents/documentPurgePlacement.js";
2
+ function guardedContainerIds(input) {
3
+ const guardedIds = new Set();
4
+ const seen = new Set();
5
+ let currentId = input.containerId;
6
+ while (true) {
7
+ if (!currentId || seen.has(currentId))
8
+ throw changedScope();
9
+ seen.add(currentId);
10
+ guardedIds.add(currentId);
11
+ for (const id of input.verifiedAncestorsById.get(currentId) ?? [])
12
+ guardedIds.add(id);
13
+ const expected = input.containersById.get(currentId);
14
+ if (!expected)
15
+ throw changedScope();
16
+ if (currentId === input.rootContainerId)
17
+ break;
18
+ currentId = expected.container.parentId;
19
+ }
20
+ return guardedIds;
21
+ }
22
+ /** Called inside the document deletion transaction; performs no remote I/O. */
23
+ export async function assertLocalPurgeScope(input) {
24
+ if (input.localId !== undefined &&
25
+ (await hasUnsettledDocumentPlacement(input.execSql, input.localId)))
26
+ throw changedScope();
27
+ const guardedIds = guardedContainerIds(input);
28
+ // Include every known signed ancestor as well as the local selection chain.
29
+ // A dishonest listing can give these chains different intermediate nodes.
30
+ for (const id of guardedIds) {
31
+ const expected = input.containersById.get(id);
32
+ if (!expected)
33
+ continue;
34
+ const current = await input.persistence.loadContainerMetadataState(input.execSql, id);
35
+ if (!current?.record ||
36
+ current.container.parentId !== expected.container.parentId ||
37
+ current.container.organizationId !== expected.container.organizationId ||
38
+ current.record.documentId !== expected.record.documentId)
39
+ throw changedScope();
40
+ }
41
+ const pending = await input.persistence.listUnsyncedMoveIntents(input.execSql);
42
+ if (pending.some((intent) => guardedIds.has(intent.containerId)) ||
43
+ input.stillCurrent?.() === false)
44
+ throw changedScope();
45
+ }
46
+ function changedScope() {
47
+ return new Error("Local subtree purge scope changed before deletion committed");
48
+ }
49
+ //# sourceMappingURL=localPurgeScope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localPurgeScope.js","sourceRoot":"","sources":["localPurgeScope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,qEAAqE,CAAC;AAgBpH,SAAS,mBAAmB,CAAC,KAA2B;IACtD,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,IAAI,SAAS,GAAG,KAAK,CAAC,WAAW,CAAC;IAClC,OAAO,IAAI,EAAE,CAA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ACE,CAAC,OAAO,EAAE,MAAM;YAChB,OAAO,CAAC,SAAS,CAAC,QAAQ,KAAK,QAAQ,CAAC,SAAS,CAAC,QAAQ;YAC1D,OAAO,CAAC,SAAS,CAAC,cAAc,KAAK,QAAQ,CAAC,SAAS,CAAC,cAAc;YACtE,OAAO,CAAC,MAAM,CAAC,UAAU,KAAK,QAAQ,CAAC,MAAM,CAAC,UAAU;YAExD,MAAM,YAAY,EAAE,CAAC;IACzB,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,uBAAuB,CAC7D,KAAK,CAAC,OAAO,CACd,CAAC;IACF,IACE,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAC5D,KAAK,CAAC,YAAY,EAAE,EAAE,KAAK,KAAK;QAEhC,MAAM,YAAY,EAAE,CAAC;AACzB,CAAC;AAED,SAAS,YAAY;IACnB,OAAO,IAAI,KAAK,CACd,6DAA6D,CAC9D,CAAC;AACJ,CAAC","sourcesContent":["import { hasUnsettledDocumentPlacement } from \"../../../data/persistence/container-contents/documentPurgePlacement\";\nimport type { ExecSql } from \"../../../data/sqlite/sqlSchema\";\nimport type { ContainerContentsPersistence } from \"../containerPersistence\";\nimport type { ContainerState } from \"../remoteHydration\";\n\ninterface LocalPurgeScopeInput {\n containerId: string | null | undefined;\n containersById: ReadonlyMap<string, ContainerState>;\n execSql: ExecSql;\n localId?: string | undefined;\n persistence: ContainerContentsPersistence;\n rootContainerId: string;\n stillCurrent?: (() => boolean) | undefined;\n verifiedAncestorsById: ReadonlyMap<string, readonly string[]>;\n}\n\nfunction guardedContainerIds(input: LocalPurgeScopeInput): ReadonlySet<string> {\n const guardedIds = new Set<string>();\n const seen = new Set<string>();\n let currentId = input.containerId;\n while (true) {\n if (!currentId || seen.has(currentId)) throw changedScope();\n seen.add(currentId);\n guardedIds.add(currentId);\n for (const id of input.verifiedAncestorsById.get(currentId) ?? [])\n guardedIds.add(id);\n const expected = input.containersById.get(currentId);\n if (!expected) throw changedScope();\n if (currentId === input.rootContainerId) break;\n currentId = expected.container.parentId;\n }\n return guardedIds;\n}\n\n/** Called inside the document deletion transaction; performs no remote I/O. */\nexport async function assertLocalPurgeScope(\n input: LocalPurgeScopeInput,\n): Promise<void> {\n if (\n input.localId !== undefined &&\n (await hasUnsettledDocumentPlacement(input.execSql, input.localId))\n )\n throw changedScope();\n const guardedIds = guardedContainerIds(input);\n // Include every known signed ancestor as well as the local selection chain.\n // A dishonest listing can give these chains different intermediate nodes.\n for (const id of guardedIds) {\n const expected = input.containersById.get(id);\n if (!expected) continue;\n const current = await input.persistence.loadContainerMetadataState(\n input.execSql,\n id,\n );\n if (\n !current?.record ||\n current.container.parentId !== expected.container.parentId ||\n current.container.organizationId !== expected.container.organizationId ||\n current.record.documentId !== expected.record.documentId\n )\n throw changedScope();\n }\n const pending = await input.persistence.listUnsyncedMoveIntents(\n input.execSql,\n );\n if (\n pending.some((intent) => guardedIds.has(intent.containerId)) ||\n input.stillCurrent?.() === false\n )\n throw changedScope();\n}\n\nfunction changedScope(): Error {\n return new Error(\n \"Local subtree purge scope changed before deletion committed\",\n );\n}\n"]}
@@ -3,8 +3,9 @@ import { sqlDocumentContainerProjectionPersistence } from "../../../data/persist
3
3
  import { listDocumentsByContainerIdsOrDocumentIds } from "../../../data/persistence/documents/documentsPersistence.js";
4
4
  import { unlinkRemoteContainerDocument } from "../documentLinks.js";
5
5
  import { purgeLocalContainerDocument, purgeRemoteContainerDocument, } from "../documentPurge.js";
6
- import { collectSubtreeLeafFirst } from "./purgeTreeCollection.js";
6
+ import { collectSubtreeLeafFirst, snapshotContainerStates, } from "./purgeTreeCollection.js";
7
7
  import { deleteSubtreeContainers } from "./purgeTreeContainerDeletion.js";
8
+ import { createSubtreePurgeScope } from "./purgeTreeScope.js";
8
9
  export { collectSubtreeLeafFirst } from "./purgeTreeCollection.js";
9
10
  // Destroy local-only documents locally. Destroy synced documents only when all
10
11
  // links are in the subtree; preserve documents with an external link. The purge
@@ -84,7 +85,10 @@ async function unlinkSubtreeDocument(input) {
84
85
  }
85
86
  for (const containerId of input.containerIds) {
86
87
  const result = await unlinkRemoteContainerDocument({
88
+ beforeSubmit: input.beforeSubmit,
87
89
  documentId,
90
+ expectedSubtreeRootId: input.expectedSubtreeRootId,
91
+ isCurrent: input.stillCurrent,
88
92
  noteId: input.document.id,
89
93
  resolveProjectionUserKey: input.resolveProjectionUserKey,
90
94
  rotationSnapshot,
@@ -97,28 +101,51 @@ async function unlinkSubtreeDocument(input) {
97
101
  }
98
102
  return true;
99
103
  }
100
- function resolveSubtreeDocumentOperations(input) {
101
- return (input.documentOperations ?? {
104
+ function resolveSubtreeDocumentOperations(input, scope) {
105
+ const operations = input.documentOperations ?? {
102
106
  purgeLocal: async (document) => (await purgeLocalContainerDocument({
107
+ beforeDeleteInTransaction: (execSql) => scope.assertLocalScopeInTransaction(execSql, document.containerId, document.id),
103
108
  noteId: document.id,
109
+ expectedContainerId: document.containerId,
104
110
  runtime: input.runtime,
105
111
  })) !== null,
106
112
  purgeRemote: async (document) => Boolean(document.documentId &&
107
113
  (await purgeRemoteContainerDocument({
114
+ beforeSubmit: () => scope.allowsDocument(document),
108
115
  documentId: document.documentId,
116
+ expectedSubtreeRootId: input.rootContainerId,
117
+ stillCurrent: input.stillCurrent,
109
118
  documentKind: document.documentKind ?? DEFAULT_DOCUMENT_KIND,
110
119
  noteId: document.id,
111
120
  resolveProjectionUserKey: input.resolveProjectionUserKey,
112
121
  runtime: input.runtime,
113
122
  }))),
114
123
  unlink: (document, containerIds) => unlinkSubtreeDocument({
124
+ beforeSubmit: () => scope.allowsDocument(document),
115
125
  containerIds,
116
126
  document,
127
+ expectedSubtreeRootId: input.rootContainerId,
128
+ stillCurrent: input.stillCurrent,
117
129
  prepareDocumentRotationSnapshot: input.prepareDocumentRotationSnapshot,
118
130
  resolveProjectionUserKey: input.resolveProjectionUserKey,
119
131
  runtime: input.runtime,
120
132
  }),
121
- });
133
+ };
134
+ return {
135
+ purgeLocal: async (document) => (await scope.allowsDocument(document)) &&
136
+ (await operations.purgeLocal(document)),
137
+ purgeRemote: async (document) => (await scope.allowsDocument(document)) &&
138
+ (await operations.purgeRemote(document)),
139
+ unlink: async (document, containerIds) => {
140
+ if (!(await scope.allowsDocument(document)))
141
+ return false;
142
+ for (const containerId of containerIds) {
143
+ if (!(await scope.allowsContainer(containerId)))
144
+ return false;
145
+ }
146
+ return operations.unlink(document, containerIds);
147
+ },
148
+ };
122
149
  }
123
150
  function purgeWasCancelled(input) {
124
151
  return input.signal?.aborted === true || input.stillCurrent?.() === false;
@@ -169,10 +196,14 @@ async function teardownSubtreeDocuments(input) {
169
196
  // reports whatever prefix was actually destroyed alongside completed/failed
170
197
  // counts and whether a cancellation cut it short. Returns null only when the
171
198
  // target container is absent from the snapshot.
172
- export async function purgeContainerTree(input) {
173
- if (purgeWasCancelled(input)) {
199
+ export async function purgeContainerTree(request) {
200
+ if (purgeWasCancelled(request)) {
174
201
  return null;
175
202
  }
203
+ const input = {
204
+ ...request,
205
+ containersById: snapshotContainerStates(request.containersById),
206
+ };
176
207
  const subtreeStates = collectSubtreeLeafFirst(input.containersById, input.rootContainerId);
177
208
  if (subtreeStates.length === 0) {
178
209
  return null;
@@ -216,8 +247,9 @@ export async function purgeContainerTree(input) {
216
247
  // Emit the initial 0/total so a determinate bar renders immediately, before the
217
248
  // first (potentially slow) remote call.
218
249
  emitProgress();
250
+ const scope = createSubtreePurgeScope(input);
219
251
  const teardown = await teardownSubtreeDocuments({
220
- documentOperations: resolveSubtreeDocumentOperations(input),
252
+ documentOperations: resolveSubtreeDocumentOperations(input, scope),
221
253
  plan,
222
254
  reportStep,
223
255
  signal: input.signal,
@@ -228,6 +260,9 @@ export async function purgeContainerTree(input) {
228
260
  let aborted = teardown.aborted;
229
261
  if (!teardown.aborted) {
230
262
  const deletion = await deleteSubtreeContainers({
263
+ allowsContainer: scope.allowsContainer,
264
+ allowsLocalScopeInTransaction: scope.allowsLocalScopeInTransaction,
265
+ rootContainerId: input.rootContainerId,
231
266
  persistence: input.persistence,
232
267
  reportStep,
233
268
  runtime: input.runtime,