@tearleads/client-sdk 0.1.13 → 0.1.15

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 (204) hide show
  1. package/README.md +32 -7
  2. package/client/containerContents.js +2 -1
  3. package/client/containerContents.js.map +1 -1
  4. package/data/documents/blob/shared/types.d.ts +4 -0
  5. package/data/documents/blob/shared/types.js.map +1 -1
  6. package/data/keyingProjectionVerification/accessManifestCheckpointEnforcement.js +2 -0
  7. package/data/keyingProjectionVerification/accessManifestCheckpointEnforcement.js.map +1 -1
  8. package/data/keyingProjectionVerification/checkpointContext.d.ts +2 -1
  9. package/data/keyingProjectionVerification/checkpointContext.js +22 -0
  10. package/data/keyingProjectionVerification/checkpointContext.js.map +1 -1
  11. package/data/keyingProjectionVerification/containerDestinationVerification.js +11 -1
  12. package/data/keyingProjectionVerification/containerDestinationVerification.js.map +1 -1
  13. package/data/keyingProjectionVerification/containerManifestVerification.js.map +1 -1
  14. package/data/keyingProjectionVerification/containerPathVerification.js.map +1 -1
  15. package/data/keyingProjectionVerification/containerProjectionVerification.d.ts +3 -2
  16. package/data/keyingProjectionVerification/containerProjectionVerification.js +10 -11
  17. package/data/keyingProjectionVerification/containerProjectionVerification.js.map +1 -1
  18. package/data/keyingProjectionVerification/documentManifestPolicies.js.map +1 -1
  19. package/data/keyingProjectionVerification/documentManifestVerification.js.map +1 -1
  20. package/data/keyingProjectionVerification/documentProjectionVerification.d.ts +2 -3
  21. package/data/keyingProjectionVerification/documentProjectionVerification.js +4 -0
  22. package/data/keyingProjectionVerification/documentProjectionVerification.js.map +1 -1
  23. package/data/keyingProjectionVerification/mergeProjectionPolicyEvidence.js +14 -12
  24. package/data/keyingProjectionVerification/mergeProjectionPolicyEvidence.js.map +1 -1
  25. package/data/keyingProjectionVerification/organizationFounderBinding.js.map +1 -1
  26. package/data/keyingProjectionVerification/projectionAuthorizationEvidence.js +33 -6
  27. package/data/keyingProjectionVerification/projectionAuthorizationEvidence.js.map +1 -1
  28. package/data/keyingProjectionVerification/projectionLifetimes.js +13 -0
  29. package/data/keyingProjectionVerification/projectionLifetimes.js.map +1 -0
  30. package/data/keyingProjectionVerification/projectionPolicyEvidence.js +19 -66
  31. package/data/keyingProjectionVerification/projectionPolicyEvidence.js.map +1 -1
  32. package/data/keyingProjectionVerification/types.d.ts +13 -2
  33. package/data/keyingProjectionVerification/types.js +15 -0
  34. package/data/keyingProjectionVerification/types.js.map +1 -1
  35. package/data/persistence/keyingCheckpointAdvancePersistence.js +4 -1
  36. package/data/persistence/keyingCheckpointAdvancePersistence.js.map +1 -1
  37. package/data/persistence/organizationFounderPersistence.js +2 -2
  38. package/data/persistence/organizationFounderPersistence.js.map +1 -1
  39. package/data/persistence/principalAuthorizationCheckpoints.js +29 -0
  40. package/data/persistence/principalAuthorizationCheckpoints.js.map +1 -0
  41. package/data/persistence/principalHistoryEvidencePersistence.d.ts +30 -0
  42. package/data/persistence/principalHistoryPrefixPersistence.d.ts +24 -0
  43. package/data/persistence/principalHistoryPrefixPersistence.js +6 -2
  44. package/data/persistence/principalHistoryPrefixPersistence.js.map +1 -1
  45. package/data/persistence/principalHistoryStagePersistence.d.ts +21 -0
  46. package/data/principals/principalHistoryRuntime.js +12 -0
  47. package/data/principals/principalHistoryRuntime.js.map +1 -0
  48. package/data/principals/principalHistoryStageProtection.js +2 -12
  49. package/data/principals/principalHistoryStageProtection.js.map +1 -1
  50. package/data/principals/principalPolicyEvidence.d.ts +2 -2
  51. package/data/principals/principalPolicyEvidence.js.map +1 -1
  52. package/data/sqlite/principalHistoryEvidenceSchema.d.ts +308 -0
  53. package/data/sqlite/principalHistoryStageSchema.d.ts +119 -0
  54. package/index.d.ts +2 -2
  55. package/index.js +1 -1
  56. package/index.js.map +1 -1
  57. package/internal/api-client/ApiCache.d.ts +54 -0
  58. package/internal/api-client/ApiClient.d.ts +255 -309
  59. package/internal/api-client/ApiClient.js +15 -6
  60. package/internal/api-client/ApiClient.js.map +1 -1
  61. package/internal/api-client/index.d.ts +1 -0
  62. package/internal/api-client/index.js.map +1 -1
  63. package/internal/api-client/principalHistoryDeadline.js +20 -0
  64. package/internal/api-client/principalHistoryDeadline.js.map +1 -0
  65. package/internal/api-client/principalHistoryRequest.js +59 -22
  66. package/internal/api-client/principalHistoryRequest.js.map +1 -1
  67. package/internal/api-client/principalHistoryRequestContext.js +18 -5
  68. package/internal/api-client/principalHistoryRequestContext.js.map +1 -1
  69. package/internal/api-client/principalPolicyRequests.d.ts +799 -0
  70. package/internal/api-client/principalPolicyRequests.js +9 -4
  71. package/internal/api-client/principalPolicyRequests.js.map +1 -1
  72. package/internal/api-client/projectionPolicyHistoryPages.d.ts +9 -0
  73. package/internal/api-client/projectionPolicyHistoryPages.js +88 -0
  74. package/internal/api-client/projectionPolicyHistoryPages.js.map +1 -0
  75. package/internal/api-client/writerProjectionRequests.js +26 -0
  76. package/internal/api-client/writerProjectionRequests.js.map +1 -0
  77. package/internal/crypto/keying/principalPolicyHistory.js +4 -0
  78. package/internal/crypto/keying/principalPolicyHistory.js.map +1 -1
  79. package/internal/crypto/keying/principalPolicyHistoryTypes.d.ts +2 -0
  80. package/internal/crypto/keying/principalPolicyHistoryTypes.js.map +1 -1
  81. package/internal/crypto/projectionHistorySlots.js +0 -4
  82. package/internal/crypto/projectionHistorySlots.js.map +1 -1
  83. package/internal/validators/operation/index.d.ts +1 -0
  84. package/internal/validators/operation/index.js +1 -0
  85. package/internal/validators/operation/index.js.map +1 -1
  86. package/internal/validators/operation/principals.d.ts +38 -16
  87. package/internal/validators/operation/principals.js +11 -5
  88. package/internal/validators/operation/principals.js.map +1 -1
  89. package/internal/validators/operation/projectionPolicyHistory.d.ts +512 -0
  90. package/internal/validators/operation/projectionPolicyHistory.js +37 -0
  91. package/internal/validators/operation/projectionPolicyHistory.js.map +1 -0
  92. package/internal/validators/operation/registry.d.ts +2 -0
  93. package/internal/validators/operation/registry.js +2 -0
  94. package/internal/validators/operation/registry.js.map +1 -1
  95. package/internal/validators/operation/writerProjections.d.ts +178 -1224
  96. package/internal/validators/operation/writerProjections.js +9 -2
  97. package/internal/validators/operation/writerProjections.js.map +1 -1
  98. package/internal/validators/response/container.d.ts +84 -612
  99. package/internal/validators/response/documentMutation.d.ts +84 -612
  100. package/internal/validators/response/index.d.ts +1 -0
  101. package/internal/validators/response/index.js +1 -0
  102. package/internal/validators/response/index.js.map +1 -1
  103. package/internal/validators/response/organizationBilling.d.ts +1 -0
  104. package/internal/validators/response/organizationBilling.js +1 -1
  105. package/internal/validators/response/organizationBilling.js.map +1 -1
  106. package/internal/validators/response/principalHistoryPreparation.js +28 -1
  107. package/internal/validators/response/principalHistoryPreparation.js.map +1 -1
  108. package/internal/validators/response/principalPolicySnapshotPage.d.ts +388 -0
  109. package/internal/validators/response/principalPolicySnapshotPage.js +24 -0
  110. package/internal/validators/response/principalPolicySnapshotPage.js.map +1 -0
  111. package/internal/validators/response/projectionPolicyEvidence.d.ts +85 -613
  112. package/internal/validators/response/projectionPolicyEvidence.js +10 -5
  113. package/internal/validators/response/projectionPolicyEvidence.js.map +1 -1
  114. package/package.json +4 -1
  115. package/sqlite/sqlite3-licenses.md +38 -0
  116. package/sqlite/sqlite3.wasm +0 -0
  117. package/sqlite/worker.js +4 -0
  118. package/stores/documents/documentStore/attachmentHydration.js +3 -0
  119. package/stores/documents/documentStore/attachmentHydration.js.map +1 -1
  120. package/stores/documents/documentStore/syncDetachedAttachments.js +3 -0
  121. package/stores/documents/documentStore/syncDetachedAttachments.js.map +1 -1
  122. package/workflows/blobs/decrypt.d.ts +1 -1
  123. package/workflows/blobs/decrypt.js +3 -1
  124. package/workflows/blobs/decrypt.js.map +1 -1
  125. package/workflows/blobs/detach.js +6 -1
  126. package/workflows/blobs/detach.js.map +1 -1
  127. package/workflows/blobs/hydrate.d.ts +3 -1
  128. package/workflows/blobs/hydrate.js +2 -0
  129. package/workflows/blobs/hydrate.js.map +1 -1
  130. package/workflows/blobs/retainedAttachmentVerification.js +2 -0
  131. package/workflows/blobs/retainedAttachmentVerification.js.map +1 -1
  132. package/workflows/container-contents/container-state/createAdoption.js +2 -0
  133. package/workflows/container-contents/container-state/createAdoption.js.map +1 -1
  134. package/workflows/container-contents/container-state/createWithMetadata.js +7 -39
  135. package/workflows/container-contents/container-state/createWithMetadata.js.map +1 -1
  136. package/workflows/container-contents/container-state/createWithMetadataPlan.js +68 -0
  137. package/workflows/container-contents/container-state/createWithMetadataPlan.js.map +1 -0
  138. package/workflows/container-contents/remoteContainerState.js +3 -1
  139. package/workflows/container-contents/remoteContainerState.js.map +1 -1
  140. package/workflows/container-contents/remoteHydration/verifiedDestination.js +3 -0
  141. package/workflows/container-contents/remoteHydration/verifiedDestination.js.map +1 -1
  142. package/workflows/container-contents/runtime.d.ts +3 -0
  143. package/workflows/container-contents/runtime.js +7 -6
  144. package/workflows/container-contents/runtime.js.map +1 -1
  145. package/workflows/documents/create.d.ts +2 -15
  146. package/workflows/documents/create.js +9 -64
  147. package/workflows/documents/create.js.map +1 -1
  148. package/workflows/documents/createProjection.d.ts +14 -0
  149. package/workflows/documents/createProjection.js +26 -0
  150. package/workflows/documents/createProjection.js.map +1 -0
  151. package/workflows/documents/createResponse.js +49 -0
  152. package/workflows/documents/createResponse.js.map +1 -0
  153. package/workflows/documents/linkSetBlobRewraps.js +2 -0
  154. package/workflows/documents/linkSetBlobRewraps.js.map +1 -1
  155. package/workflows/documents/runtime.d.ts +3 -0
  156. package/workflows/documents/runtime.js +3 -2
  157. package/workflows/documents/runtime.js.map +1 -1
  158. package/workflows/documents/syncFailureClassification.js +3 -1
  159. package/workflows/documents/syncFailureClassification.js.map +1 -1
  160. package/workflows/principals/index.d.ts +2 -0
  161. package/workflows/principals/index.js +1 -0
  162. package/workflows/principals/index.js.map +1 -1
  163. package/workflows/principals/policyVerification.js.map +1 -1
  164. package/workflows/principals/principalHistoryRecoveryAuthority.js +20 -0
  165. package/workflows/principals/principalHistoryRecoveryAuthority.js.map +1 -0
  166. package/workflows/principals/principalHistoryRecoveryStage.js +1 -1
  167. package/workflows/principals/principalHistoryRecoveryStage.js.map +1 -1
  168. package/workflows/principals/principalHistoryRecoveryTypes.d.ts +3 -3
  169. package/workflows/principals/principalHistoryRecoveryTypes.js.map +1 -1
  170. package/workflows/principals/principalHistoryRecoveryVerification.js +6 -1
  171. package/workflows/principals/principalHistoryRecoveryVerification.js.map +1 -1
  172. package/workflows/principals/principalRecoveryOutage.js +1 -1
  173. package/workflows/principals/principalRecoveryOutage.js.map +1 -1
  174. package/workflows/principals/publicPrincipalHistoryAuthority.js +60 -0
  175. package/workflows/principals/publicPrincipalHistoryAuthority.js.map +1 -0
  176. package/workflows/principals/publicPrincipalHistoryPage.js +87 -0
  177. package/workflows/principals/publicPrincipalHistoryPage.js.map +1 -0
  178. package/workflows/principals/publicPrincipalHistoryProgress.js +178 -0
  179. package/workflows/principals/publicPrincipalHistoryProgress.js.map +1 -0
  180. package/workflows/principals/publicPrincipalHistoryTypes.d.ts +39 -0
  181. package/workflows/principals/publicPrincipalHistoryTypes.js +2 -0
  182. package/workflows/principals/publicPrincipalHistoryTypes.js.map +1 -0
  183. package/workflows/principals/publicProjectionDirectory.js +40 -0
  184. package/workflows/principals/publicProjectionDirectory.js.map +1 -0
  185. package/workflows/principals/publicProjectionPrincipal.js +53 -0
  186. package/workflows/principals/publicProjectionPrincipal.js.map +1 -0
  187. package/workflows/principals/recoverPrincipalPolicyHistory.js +4 -1
  188. package/workflows/principals/recoverPrincipalPolicyHistory.js.map +1 -1
  189. package/workflows/principals/recoverProjectionPolicyHistory.d.ts +9 -0
  190. package/workflows/principals/recoverProjectionPolicyHistory.js +98 -0
  191. package/workflows/principals/recoverProjectionPolicyHistory.js.map +1 -0
  192. package/workflows/principals/recoverPublicPrincipalHistory.js +176 -0
  193. package/workflows/principals/recoverPublicPrincipalHistory.js.map +1 -0
  194. package/workflows/principals/recoverScopedPrincipalPolicyHistory.js +2 -5
  195. package/workflows/principals/recoverScopedPrincipalPolicyHistory.js.map +1 -1
  196. package/workflows/principals/runtimePolicyRecovery.js +2 -1
  197. package/workflows/principals/runtimePolicyRecovery.js.map +1 -1
  198. package/workflows/principals/runtimePolicyWarmer.js +2 -0
  199. package/workflows/principals/runtimePolicyWarmer.js.map +1 -1
  200. package/workflows/principals/runtimeProjectionPolicyRecovery.js +56 -0
  201. package/workflows/principals/runtimeProjectionPolicyRecovery.js.map +1 -0
  202. package/workflows/principals/selectPublicPrincipalHistory.js +90 -0
  203. package/workflows/principals/selectPublicPrincipalHistory.js.map +1 -0
  204. package/workflows/registration/provisioningBootstrapBuilders.d.ts +21 -153
@@ -1,4 +1,5 @@
1
1
  import { decodeJsonOperationResponse } from "./operationResponse.js";
2
+ import { principalHistoryDeadline } from "./principalHistoryDeadline.js";
2
3
  import { PrincipalHistoryRequestContext } from "./principalHistoryRequestContext.js";
3
4
  /** Retry only an explicit, validated response proving the operation rolled back. */
4
5
  export async function principalHistoryRequest(runtime, input) {
@@ -15,7 +16,7 @@ export async function principalHistoryRequest(runtime, input) {
15
16
  if (!decoded.ok && context.restartReadAfterRenewal())
16
17
  continue;
17
18
  if (!decoded.ok)
18
- return decoded;
19
+ return preserveCommitUncertainty(method, context, decoded);
19
20
  if (decoded.data.status === 202) {
20
21
  context.afterPreparation();
21
22
  const failure = await continuePreparation(decoded.data.data, progress);
@@ -30,38 +31,74 @@ export async function principalHistoryRequest(runtime, input) {
30
31
  });
31
32
  continue;
32
33
  }
33
- if (decoded.data.status !== 200 || !input.validator(decoded.data.data))
34
- return runtime.responseRequest.reportFailure({
34
+ if (decoded.data.status !== 200 || !input.validator(decoded.data.data)) {
35
+ const failure = runtime.responseRequest.reportFailure({
35
36
  kind: "shape",
36
37
  message: `Invalid principal policy response for ${path}`,
37
38
  method,
38
- options,
39
+ options: method === "GET" ? options : { ...options, reportErrors: false },
39
40
  path,
40
41
  status: decoded.data.status,
41
42
  statusText: decoded.data.statusText,
42
43
  });
44
+ return preserveCommitUncertainty(method, context, failure);
45
+ }
43
46
  return { ok: true, data: decoded.data.data };
44
47
  }
45
48
  }
49
+ function preserveCommitUncertainty(method, context, failure) {
50
+ if (method === "GET")
51
+ return failure;
52
+ // A network/decode failure or intermediary 5xx says nothing about commit.
53
+ // Inner write errors are silent until this final classification is known.
54
+ const ambiguous = failure.kind !== "http" ||
55
+ ((failure.status ?? 0) >= 500 &&
56
+ // The declared 503 schema requires the exact code and committed:false.
57
+ // Unvalidated codes never reach RequestFailure.code.
58
+ !(failure.status === 503 &&
59
+ failure.code === "principal_history_preparation_unavailable")) ||
60
+ failure.status === 408 ||
61
+ failure.status === 499;
62
+ const result = ambiguous && failure.kind !== "outcome-unknown"
63
+ ? context.failure()
64
+ : failure;
65
+ if (context.options.reportErrors !== false &&
66
+ (result.kind === "http" || !context.cancelled()))
67
+ result.report();
68
+ return result;
69
+ }
46
70
  async function readResponse(runtime, context, input) {
47
- const response = await runtime.responseRequest(input.path, input.method, input.body, context.options, [], input.operation);
48
- // Authentication rejection precedes the workflow, so renewal does not make
49
- // this write's outcome uncertain. Reads may restart after a known renewal.
50
- if (!response.ok && response.kind === "http" && response.status === 401)
51
- return response;
52
- if (context.cancelled())
53
- return context.failure(response.ok ? response.data : undefined);
54
- if (!response.ok)
55
- return response;
56
- const decoded = await decodeJsonOperationResponse(runtime.responseRequest, input.operation, response.data, input.path, context.options);
57
- if (context.cancelled())
58
- return context.failure(response.data);
59
- if (!decoded.ok)
60
- return decoded;
61
- return {
62
- ok: true,
63
- data: { ...decoded.data, statusText: response.data.statusText },
64
- };
71
+ const deadline = principalHistoryDeadline(context.options,
72
+ // Writes await acknowledgement unless the caller supplies a deadline.
73
+ // Aborting a committed write cannot be repaired by the continuation loop.
74
+ input.requestTimeoutMs ?? (input.method === "GET" ? undefined : null));
75
+ const options = input.method === "GET"
76
+ ? deadline.options
77
+ : { ...deadline.options, reportErrors: false };
78
+ try {
79
+ const response = await runtime.responseRequest(input.path, input.method, input.body, options, [], input.operation);
80
+ // Authentication rejection precedes the workflow, so renewal does not make
81
+ // this write's outcome uncertain. Reads may restart after a known renewal.
82
+ if (!response.ok && response.kind === "http" && response.status === 401)
83
+ return response;
84
+ // An expired write remains uncertain even if a failure status arrived.
85
+ if (context.cancelled() || deadline.expired())
86
+ return context.failure(response.ok ? response.data : undefined, deadline.expired() && !context.cancelled());
87
+ if (!response.ok)
88
+ return response;
89
+ const decoded = await decodeJsonOperationResponse(runtime.responseRequest, input.operation, response.data, input.path, options);
90
+ if (context.cancelled() || deadline.expired())
91
+ return context.failure(response.data, deadline.expired() && !context.cancelled());
92
+ if (!decoded.ok)
93
+ return decoded;
94
+ return {
95
+ ok: true,
96
+ data: { ...decoded.data, statusText: response.data.statusText },
97
+ };
98
+ }
99
+ finally {
100
+ deadline.dispose();
101
+ }
65
102
  }
66
103
  async function continuePreparation(data, progress) {
67
104
  const token = typeof data === "object" &&
@@ -1 +1 @@
1
- {"version":3,"file":"principalHistoryRequest.js","sourceRoot":"","sources":["principalHistoryRequest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAGlF,oFAAoF;AACpF,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAA0B,EAC1B,KAQC;IAED,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IAC/B,MAAM,OAAO,GACX,KAAK,CAAC,OAAO;QACb,IAAI,8BAA8B,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3E,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAChC,MAAM,QAAQ,GAAwB,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IAC5E,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,OAAO,CAAC,SAAS,EAAE;YAAE,OAAO,OAAO,CAAC,OA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AAK,QAAQ;QACxB,IAAI,KAAK,IAAI;QACb,eAAe,IAAI,IAAI;QACvB,OAAO,IAAI,CAAC,aAAa,KAAK,QAAQ;QACpC,CAAC,CAAC,IAAI,CAAC,aAAa;QACpB,CAAC,CAAC,SAAS,CAAC;IAChB,IAAI,KAAK,KAAK,SAAS;QACrB,OAAO;YACL,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,2CAA2C;SACrD,CAAC;IACJ,QAAQ,CAAC,SAAS,GAAG,KAAK,KAAK,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9E,QAAQ,CAAC,QAAQ,GAAG,KAAK,CAAC;IAC1B,IAAI,QAAQ,CAAC,SAAS,IAAI,CAAC;QACzB,OAAO;YACL,IAAI,EAAE,uCAAuC;YAC7C,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,4DAA4D;SACtE,CAAC;IACJ,4EAA4E;IAC5E,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAClC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CACnD,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { JsonOperation } from \"@tearleads/validators/operation\";\nimport type { ApiRequestRuntime } from \"./apiRequestRuntime\";\nimport { decodeJsonOperationResponse } from \"./operationResponse\";\nimport { PrincipalHistoryRequestContext } from \"./principalHistoryRequestContext\";\nimport type { HttpMethod, RequestResult, RequestResultOptions } from \"./types\";\n\n/** Retry only an explicit, validated response proving the operation rolled back. */\nexport async function principalHistoryRequest<T>(\n runtime: ApiRequestRuntime,\n input: {\n readonly path: string;\n readonly validator: (value: unknown) => value is T;\n readonly method: HttpMethod;\n readonly body?: string;\n readonly options?: RequestResultOptions;\n readonly operation: JsonOperation;\n readonly context?: PrincipalHistoryRequestContext;\n },\n): Promise<RequestResult<T>> {\n const { path, method } = input;\n const context =\n input.context ??\n new PrincipalHistoryRequestContext(runtime, method, path, input.options);\n const options = context.options;\n const progress: PreparationProgress = { previous: undefined, unchanged: 0 };\n while (true) {\n if (context.cancelled()) return context.failure();\n context.beforeRequest();\n const decoded = await readResponse(runtime, context, input);\n if (!decoded.ok && context.restartReadAfterRenewal()) continue;\n if (!decoded.ok) return decoded;\n if (decoded.data.status === 202) {\n context.afterPreparation();\n const failure = await continuePreparation(decoded.data.data, progress);\n if (failure)\n return runtime.responseRequest.reportFailure({\n ...failure,\n method,\n options,\n path,\n status: 202,\n statusText: decoded.data.statusText,\n });\n continue;\n }\n if (decoded.data.status !== 200 || !input.validator(decoded.data.data))\n return runtime.responseRequest.reportFailure({\n kind: \"shape\",\n message: `Invalid principal policy response for ${path}`,\n method,\n options,\n path,\n status: decoded.data.status,\n statusText: decoded.data.statusText,\n });\n return { ok: true, data: decoded.data.data };\n }\n}\n\nasync function readResponse(\n runtime: ApiRequestRuntime,\n context: PrincipalHistoryRequestContext,\n input: {\n readonly path: string;\n readonly method: HttpMethod;\n readonly body?: string;\n readonly operation: JsonOperation;\n },\n) {\n const response = await runtime.responseRequest(\n input.path,\n input.method,\n input.body,\n context.options,\n [],\n input.operation,\n );\n // Authentication rejection precedes the workflow, so renewal does not make\n // this write's outcome uncertain. Reads may restart after a known renewal.\n if (!response.ok && response.kind === \"http\" && response.status === 401)\n return response;\n if (context.cancelled())\n return context.failure(response.ok ? response.data : undefined);\n if (!response.ok) return response;\n const decoded = await decodeJsonOperationResponse(\n runtime.responseRequest,\n input.operation,\n response.data,\n input.path,\n context.options,\n );\n if (context.cancelled()) return context.failure(response.data);\n if (!decoded.ok) return decoded;\n return {\n ok: true as const,\n data: { ...decoded.data, statusText: response.data.statusText },\n };\n}\n\ninterface PreparationProgress {\n previous: string | undefined;\n unchanged: number;\n}\n\nasync function continuePreparation(\n data: unknown,\n progress: PreparationProgress,\n): Promise<{\n readonly kind: \"shape\" | \"http\";\n readonly message: string;\n readonly code?: string;\n} | null> {\n const token =\n typeof data === \"object\" &&\n data !== null &&\n \"progressToken\" in data &&\n typeof data.progressToken === \"string\"\n ? data.progressToken\n : undefined;\n if (token === undefined)\n return {\n kind: \"shape\",\n message: \"Principal preparation progress is missing\",\n };\n progress.unchanged = token === progress.previous ? progress.unchanged + 1 : 0;\n progress.previous = token;\n if (progress.unchanged >= 2)\n return {\n code: \"principal_history_preparation_stalled\",\n kind: \"http\",\n message: \"Principal history preparation did not advance; retry later\",\n };\n // The next round checks cancellation and identity again before any request.\n await new Promise<void>((resolve) =>\n setTimeout(resolve, progress.unchanged ? 250 : 25),\n );\n return null;\n}\n"]}
1
+ {"version":3,"file":"principalHistoryRequest.js","sourceRoot":"","sources":["principalHistoryRequest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAQlF,oFAAoF;AACpF,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAA0B,EAC1B,KASC;IAED,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IAC/B,MAAM,OAAO,GACX,KAAK,CAAC,OAAO;QACb,IAAI,8BAA8B,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3E,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAChC,MAAM,QAAQ,GAAwB,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IAC5E,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,OAAO,CAAC,SAAS,EAAE;YAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAClD,OAAO,CAAC,aAAa,EAAE,CAA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CAAC,CAAC,EAAE,CAAC,CACnD,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { JsonOperation } from \"@tearleads/validators/operation\";\nimport type { ApiRequestRuntime } from \"./apiRequestRuntime\";\nimport { decodeJsonOperationResponse } from \"./operationResponse\";\nimport { principalHistoryDeadline } from \"./principalHistoryDeadline\";\nimport { PrincipalHistoryRequestContext } from \"./principalHistoryRequestContext\";\nimport type {\n HttpMethod,\n RequestFailure,\n RequestResult,\n RequestResultOptions,\n} from \"./types\";\n\n/** Retry only an explicit, validated response proving the operation rolled back. */\nexport async function principalHistoryRequest<T>(\n runtime: ApiRequestRuntime,\n input: {\n readonly path: string;\n readonly validator: (value: unknown) => value is T;\n readonly method: HttpMethod;\n readonly body?: string;\n readonly options?: RequestResultOptions;\n readonly operation: JsonOperation;\n readonly context?: PrincipalHistoryRequestContext;\n readonly requestTimeoutMs?: number;\n },\n): Promise<RequestResult<T>> {\n const { path, method } = input;\n const context =\n input.context ??\n new PrincipalHistoryRequestContext(runtime, method, path, input.options);\n const options = context.options;\n const progress: PreparationProgress = { previous: undefined, unchanged: 0 };\n while (true) {\n if (context.cancelled()) return context.failure();\n context.beforeRequest();\n const decoded = await readResponse(runtime, context, input);\n if (!decoded.ok && context.restartReadAfterRenewal()) continue;\n if (!decoded.ok) return preserveCommitUncertainty(method, context, decoded);\n if (decoded.data.status === 202) {\n context.afterPreparation();\n const failure = await continuePreparation(decoded.data.data, progress);\n if (failure)\n return runtime.responseRequest.reportFailure({\n ...failure,\n method,\n options,\n path,\n status: 202,\n statusText: decoded.data.statusText,\n });\n continue;\n }\n if (decoded.data.status !== 200 || !input.validator(decoded.data.data)) {\n const failure = runtime.responseRequest.reportFailure({\n kind: \"shape\",\n message: `Invalid principal policy response for ${path}`,\n method,\n options:\n method === \"GET\" ? options : { ...options, reportErrors: false },\n path,\n status: decoded.data.status,\n statusText: decoded.data.statusText,\n });\n return preserveCommitUncertainty(method, context, failure);\n }\n return { ok: true, data: decoded.data.data };\n }\n}\n\nfunction preserveCommitUncertainty(\n method: HttpMethod,\n context: PrincipalHistoryRequestContext,\n failure: RequestFailure,\n): RequestFailure {\n if (method === \"GET\") return failure;\n // A network/decode failure or intermediary 5xx says nothing about commit.\n // Inner write errors are silent until this final classification is known.\n const ambiguous =\n failure.kind !== \"http\" ||\n ((failure.status ?? 0) >= 500 &&\n // The declared 503 schema requires the exact code and committed:false.\n // Unvalidated codes never reach RequestFailure.code.\n !(\n failure.status === 503 &&\n failure.code === \"principal_history_preparation_unavailable\"\n )) ||\n failure.status === 408 ||\n failure.status === 499;\n const result =\n ambiguous && failure.kind !== \"outcome-unknown\"\n ? context.failure()\n : failure;\n if (\n context.options.reportErrors !== false &&\n (result.kind === \"http\" || !context.cancelled())\n )\n result.report();\n return result;\n}\n\nasync function readResponse(\n runtime: ApiRequestRuntime,\n context: PrincipalHistoryRequestContext,\n input: {\n readonly path: string;\n readonly method: HttpMethod;\n readonly body?: string;\n readonly operation: JsonOperation;\n readonly requestTimeoutMs?: number;\n },\n) {\n const deadline = principalHistoryDeadline(\n context.options,\n // Writes await acknowledgement unless the caller supplies a deadline.\n // Aborting a committed write cannot be repaired by the continuation loop.\n input.requestTimeoutMs ?? (input.method === \"GET\" ? undefined : null),\n );\n const options =\n input.method === \"GET\"\n ? deadline.options\n : { ...deadline.options, reportErrors: false };\n try {\n const response = await runtime.responseRequest(\n input.path,\n input.method,\n input.body,\n options,\n [],\n input.operation,\n );\n // Authentication rejection precedes the workflow, so renewal does not make\n // this write's outcome uncertain. Reads may restart after a known renewal.\n if (!response.ok && response.kind === \"http\" && response.status === 401)\n return response;\n // An expired write remains uncertain even if a failure status arrived.\n if (context.cancelled() || deadline.expired())\n return context.failure(\n response.ok ? response.data : undefined,\n deadline.expired() && !context.cancelled(),\n );\n if (!response.ok) return response;\n const decoded = await decodeJsonOperationResponse(\n runtime.responseRequest,\n input.operation,\n response.data,\n input.path,\n options,\n );\n if (context.cancelled() || deadline.expired())\n return context.failure(\n response.data,\n deadline.expired() && !context.cancelled(),\n );\n if (!decoded.ok) return decoded;\n return {\n ok: true as const,\n data: { ...decoded.data, statusText: response.data.statusText },\n };\n } finally {\n deadline.dispose();\n }\n}\n\ninterface PreparationProgress {\n previous: string | undefined;\n unchanged: number;\n}\n\nasync function continuePreparation(\n data: unknown,\n progress: PreparationProgress,\n): Promise<{\n readonly kind: \"shape\" | \"http\";\n readonly message: string;\n readonly code?: string;\n} | null> {\n const token =\n typeof data === \"object\" &&\n data !== null &&\n \"progressToken\" in data &&\n typeof data.progressToken === \"string\"\n ? data.progressToken\n : undefined;\n if (token === undefined)\n return {\n kind: \"shape\",\n message: \"Principal preparation progress is missing\",\n };\n progress.unchanged = token === progress.previous ? progress.unchanged + 1 : 0;\n progress.previous = token;\n if (progress.unchanged >= 2)\n return {\n code: \"principal_history_preparation_stalled\",\n kind: \"http\",\n message: \"Principal history preparation did not advance; retry later\",\n };\n // The next round checks cancellation and identity again before any request.\n await new Promise<void>((resolve) =>\n setTimeout(resolve, progress.unchanged ? 250 : 25),\n );\n return null;\n}\n"]}
@@ -46,18 +46,31 @@ export class PrincipalHistoryRequestContext {
46
46
  this.restartedRead = true;
47
47
  return true;
48
48
  }
49
- failure(response) {
49
+ failure(response, timedOut = false) {
50
50
  void response?.body?.cancel().catch(() => { });
51
51
  return this.runtime.responseRequest.reportFailure({
52
52
  code: this.submitted
53
53
  ? "principal_history_outcome_unknown"
54
- : "principal_history_context_changed",
55
- kind: this.submitted ? "outcome-unknown" : "cancelled",
54
+ : timedOut
55
+ ? "principal_history_request_timed_out"
56
+ : "principal_history_context_changed",
57
+ kind: this.submitted
58
+ ? "outcome-unknown"
59
+ : timedOut
60
+ ? "network"
61
+ : "cancelled",
56
62
  message: this.submitted
57
63
  ? "Policy request may have committed; refresh before retrying"
58
- : "Principal history request was cancelled",
64
+ : timedOut
65
+ ? "Principal history request timed out"
66
+ : "Principal history request was cancelled",
59
67
  method: this.method,
60
- options: { ...this.options, reportErrors: false },
68
+ options: {
69
+ ...this.options,
70
+ reportErrors: timedOut &&
71
+ this.method === "GET" &&
72
+ this.options.reportErrors !== false,
73
+ },
61
74
  path: this.path,
62
75
  status: null,
63
76
  statusText: "",
@@ -1 +1 @@
1
- {"version":3,"file":"principalHistoryRequestContext.js","sourceRoot":"","sources":["principalHistoryRequestContext.ts"],"names":[],"mappings":"AAGA,gGAAgG;AAChG,MAAM,OAAO,8BAA8B;IAQtB;IACA;IACA;IATV,OAAO,CAAuB;IAC/B,KAAK,CAAgB;IACrB,SAAS,GAAG,KAAK,CAAC;IAClB,WAAW,GAAG,KAAK,CAAC;IACpB,aAAa,GAAG,KAAK,CAAC;IAE9B,YACmB,OAA0B,EAC1B,MAAkB,EAClB,IAAY,EAC7B,OAAyC;QAHxB,YAAO,GAAP,OAAO,CAAmB;QAC1B,WAAM,GAAN,MAAM,CAAY;QAClB,SAAI,GAAJ,IAAI,CAAQ;QAG7B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;QACpC,IAAI,CAAC,OAAO,GAAG;YACb,GAAG,OAAO;YACV,qBAAqB,EACnB,OAAO,EAAE,qBAAqB,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY;YACjE,gBAAgB,EAAE,GAAG,EAAE;gBACrB,IAAI,MAAM,KAAK,KAAK,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;oBAClD,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;oBACpC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;gBAC1B,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;IAED,SAAS;QACP,OAAO,CACL,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI;YACrC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,KAAK,IAAI,CAAC,KAAK,CAC3C,CAAC;IACJ,CAAC;I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import type { HttpMethod, RequestFailure, RequestResultOptions } from \"./types\";\n\n/** Keep continuations within their authentication context without hiding commit uncertainty. */\nexport class PrincipalHistoryRequestContext {\n readonly options: RequestResultOptions;\n private token: string | null;\n private submitted = false;\n private renewedRead = false;\n private restartedRead = false;\n\n constructor(\n private readonly runtime: ApiRequestRuntime,\n private readonly method: HttpMethod,\n private readonly path: string,\n options: RequestResultOptions | undefined,\n ) {\n this.token = runtime.getAuthToken();\n this.options = {\n ...options,\n retryOnSessionExpired:\n options?.retryOnSessionExpired === false ? false : \"renew-only\",\n onSessionRenewed: () => {\n if (method === \"GET\" && !options?.signal?.aborted) {\n this.token = runtime.getAuthToken();\n this.renewedRead = true;\n }\n },\n };\n }\n\n cancelled(): boolean {\n return (\n this.options.signal?.aborted === true ||\n this.runtime.getAuthToken() !== this.token\n );\n }\n\n beforeRequest(): void {\n this.submitted = this.method !== \"GET\";\n }\n\n afterPreparation(): void {\n this.submitted = false;\n }\n\n afterReadPage(): void {\n // A completed page is forward progress. A later page may renew again,\n // while repeated 401s within one page still cannot loop indefinitely.\n this.renewedRead = false;\n this.restartedRead = false;\n }\n\n restartReadAfterRenewal(): boolean {\n if (!this.renewedRead || this.restartedRead || this.cancelled())\n return false;\n this.restartedRead = true;\n return true;\n }\n\n failure(response?: Response): RequestFailure {\n void response?.body?.cancel().catch(() => {});\n return this.runtime.responseRequest.reportFailure({\n code: this.submitted\n ? \"principal_history_outcome_unknown\"\n : \"principal_history_context_changed\",\n kind: this.submitted ? \"outcome-unknown\" : \"cancelled\",\n message: this.submitted\n ? \"Policy request may have committed; refresh before retrying\"\n : \"Principal history request was cancelled\",\n method: this.method,\n options: { ...this.options, reportErrors: false },\n path: this.path,\n status: null,\n statusText: \"\",\n });\n }\n}\n"]}
1
+ {"version":3,"file":"principalHistoryRequestContext.js","sourceRoot":"","sources":["principalHistoryRequestContext.ts"],"names":[],"mappings":"AAGA,gGAAgG;AAChG,MAAM,OAAO,8BAA8B;IAQtB;IACA;IACA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estResultOptions } from \"./types\";\n\n/** Keep continuations within their authentication context without hiding commit uncertainty. */\nexport class PrincipalHistoryRequestContext {\n readonly options: RequestResultOptions;\n private token: string | null;\n private submitted = false;\n private renewedRead = false;\n private restartedRead = false;\n\n constructor(\n private readonly runtime: ApiRequestRuntime,\n private readonly method: HttpMethod,\n private readonly path: string,\n options: RequestResultOptions | undefined,\n ) {\n this.token = runtime.getAuthToken();\n this.options = {\n ...options,\n retryOnSessionExpired:\n options?.retryOnSessionExpired === false ? false : \"renew-only\",\n onSessionRenewed: () => {\n if (method === \"GET\" && !options?.signal?.aborted) {\n this.token = runtime.getAuthToken();\n this.renewedRead = true;\n }\n },\n };\n }\n\n cancelled(): boolean {\n return (\n this.options.signal?.aborted === true ||\n this.runtime.getAuthToken() !== this.token\n );\n }\n\n beforeRequest(): void {\n this.submitted = this.method !== \"GET\";\n }\n\n afterPreparation(): void {\n this.submitted = false;\n }\n\n afterReadPage(): void {\n // A completed page is forward progress. A later page may renew again,\n // while repeated 401s within one page still cannot loop indefinitely.\n this.renewedRead = false;\n this.restartedRead = false;\n }\n\n restartReadAfterRenewal(): boolean {\n if (!this.renewedRead || this.restartedRead || this.cancelled())\n return false;\n this.restartedRead = true;\n return true;\n }\n\n failure(response?: Response, timedOut = false): RequestFailure {\n void response?.body?.cancel().catch(() => {});\n return this.runtime.responseRequest.reportFailure({\n code: this.submitted\n ? \"principal_history_outcome_unknown\"\n : timedOut\n ? \"principal_history_request_timed_out\"\n : \"principal_history_context_changed\",\n kind: this.submitted\n ? \"outcome-unknown\"\n : timedOut\n ? \"network\"\n : \"cancelled\",\n message: this.submitted\n ? \"Policy request may have committed; refresh before retrying\"\n : timedOut\n ? \"Principal history request timed out\"\n : \"Principal history request was cancelled\",\n method: this.method,\n options: {\n ...this.options,\n reportErrors:\n timedOut &&\n this.method === \"GET\" &&\n this.options.reportErrors !== false,\n },\n path: this.path,\n status: null,\n statusText: \"\",\n });\n }\n}\n"]}