techne-sdk 0.10.0 → 0.12.0

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 (35) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +89 -6
  3. package/dist/auth/app-key.d.ts +2 -1
  4. package/dist/auth/app-key.js +2 -1
  5. package/dist/catalog/catalog.gen.js +320 -25
  6. package/dist/connect.d.ts +5 -2
  7. package/dist/generated/lexicons.d.ts +74 -20
  8. package/dist/generated/lexicons.js +42 -10
  9. package/dist/generated/nsid.d.ts +5 -0
  10. package/dist/generated/nsid.js +5 -0
  11. package/dist/generated/nsid.json +5 -0
  12. package/dist/generated/types/pub/techne/draft/identity/createCollective.d.ts +4 -1
  13. package/dist/generated/types/pub/techne/draft/identity/createCollective.js +7 -0
  14. package/dist/generated/types/pub/techne/draft/orgAtPlace.d.ts +2 -2
  15. package/dist/generated/types/pub/techne/draft/place.d.ts +4 -0
  16. package/dist/generated/types/pub/techne/draft/query/composeRecords.d.ts +2 -2
  17. package/dist/generated/types/pub/techne/draft/query/countRecords.d.ts +6 -0
  18. package/dist/generated/types/pub/techne/draft/query/countRecords.js +14 -0
  19. package/dist/generated/types/pub/techne/draft/query/listRecords.d.ts +7 -1
  20. package/dist/generated/types/pub/techne/draft/query/listRecords.js +14 -0
  21. package/dist/item.d.ts +3 -1
  22. package/dist/item.js +1 -1
  23. package/dist/query/hosts.d.ts +1 -1
  24. package/dist/query/hosts.js +5 -3
  25. package/dist/query/index.d.ts +32 -5
  26. package/dist/read/index.js +5 -4
  27. package/dist/session/own-session.d.ts +6 -6
  28. package/dist/session/own-session.js +45 -44
  29. package/dist/session/phone.d.ts +27 -8
  30. package/dist/session/phone.js +73 -14
  31. package/dist/session/relay.d.ts +23 -0
  32. package/dist/session/relay.js +44 -0
  33. package/dist/wasm/techne-wasm.gen.js +1 -1
  34. package/dist/wasm/techne-wasm2js.gen.js +21892 -21892
  35. package/package.json +1 -1
@@ -118,3 +118,47 @@ export async function withNonceRetry(nsid, nonce, send, retries = 1) {
118
118
  nonce = err.nonce;
119
119
  }
120
120
  }
121
+ /** How long the platform keeps an answer for the same request (a refresh's for the same token and key, an
122
+ * adopt's for the same device credential). */
123
+ export const PLATFORM_ANSWER_WINDOW_MS = 60_000;
124
+ /** How long after the first send a request that got no answer may be sent again. */
125
+ export const LOST_ANSWER_WINDOW_MS = 50_000;
126
+ /** Every send is given up this long before {@link PLATFORM_ANSWER_WINDOW_MS} ends (clock skew, transit). */
127
+ export const SEND_MARGIN_MS = 5_000;
128
+ /** The waits between those sends, and how long one send may take at most. */
129
+ const LOST_ANSWER_DELAYS_MS = [1_000, 2_000, 4_000, 8_000, 15_000];
130
+ const SEND_TIMEOUT_MS = 15_000;
131
+ /**
132
+ * One platform request whose answer the platform keeps for {@link PLATFORM_ANSWER_WINDOW_MS}, sent again
133
+ * while no answer comes: `send(timeoutMs)` makes it (afresh each time, e.g. with a new proof). A send that
134
+ * throws (no answer, or no answer in its time) or an answer `noAnswerYet` names counts as none. A send starts
135
+ * up to {@link LOST_ANSWER_WINDOW_MS} after `started`, and each is given up {@link SEND_MARGIN_MS} before
136
+ * the platform's window ends, so no resend reaches the platform after its kept answer is gone. Past that,
137
+ * the last answer, or `NetworkError`.
138
+ */
139
+ export async function resendUntilAnswered(o) {
140
+ const deadline = o.started + PLATFORM_ANSWER_WINDOW_MS - SEND_MARGIN_MS;
141
+ let failure;
142
+ for (let lost = 0;; lost++) {
143
+ let got;
144
+ const left = deadline - o.now();
145
+ if (left <= 0)
146
+ throw new OwnSessionError(NETWORK_ERROR, `techne-sdk/session: ${o.nsid} got no answer in the window`, { cause: failure });
147
+ try {
148
+ got = await o.send(Math.min(SEND_TIMEOUT_MS, left));
149
+ failure = undefined;
150
+ }
151
+ catch (e) {
152
+ failure = e;
153
+ }
154
+ if (got && !o.noAnswerYet(got.status))
155
+ return got;
156
+ const wait = Math.max(LOST_ANSWER_DELAYS_MS[Math.min(lost, LOST_ANSWER_DELAYS_MS.length - 1)], ((got ? retryAfterOf(got) : undefined) ?? 0) * 1000);
157
+ if (o.now() + wait - o.started > LOST_ANSWER_WINDOW_MS) {
158
+ if (got)
159
+ return got;
160
+ throw new OwnSessionError(NETWORK_ERROR, `techne-sdk/session: ${o.nsid} got no answer`, { cause: failure });
161
+ }
162
+ await o.sleep(wait);
163
+ }
164
+ }