poe-code 4.0.23 → 4.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-code",
3
- "version": "4.0.23",
3
+ "version": "4.0.24",
4
4
  "description": "CLI tool to configure Poe API for developer workflows.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -31,6 +31,7 @@ export interface HostedOAuthStorage<TCredential = unknown> {
31
31
  capabilities: HostedOAuthStorageCapabilities;
32
32
  signingKey(): Promise<OAuthAuthorizationServerSigningKey>;
33
33
  resolveSubject(providerName: string, accountId: string): Promise<string>;
34
+ healthCheck?(): Promise<void>;
34
35
  cleanup?(now?: number): Promise<void>;
35
36
  }
36
37
  export interface HostedOAuthCredentialAccess<TCredential = unknown> {
@@ -217,8 +217,21 @@ export async function prepareHostedOAuthRuntime(config) {
217
217
  const requestHandler = async (request, response) => {
218
218
  const url = new URL(request.url ?? "/", prepared.issuer);
219
219
  if (request.method === "GET" && url.pathname === "/healthz") {
220
- response.writeHead(200, { "content-type": "application/json", "cache-control": "no-store" });
221
- response.end('{"ok":true}');
220
+ try {
221
+ await config.storage.healthCheck?.();
222
+ response.writeHead(200, {
223
+ "content-type": "application/json",
224
+ "cache-control": "no-store"
225
+ });
226
+ response.end('{"ok":true}');
227
+ }
228
+ catch {
229
+ response.writeHead(503, {
230
+ "content-type": "application/json",
231
+ "cache-control": "no-store"
232
+ });
233
+ response.end('{"ok":false}');
234
+ }
222
235
  return true;
223
236
  }
224
237
  if (customInteraction?.paths.includes(url.pathname) === true) {
@@ -227,11 +240,11 @@ export async function prepareHostedOAuthRuntime(config) {
227
240
  request: toWebRequest(request, prepared.issuer, body),
228
241
  async complete({ transactionId, accountId, credential }) {
229
242
  const subject = await config.storage.resolveSubject(config.provider.name, accountId);
243
+ await config.storage.credentials.set(subject, credential);
230
244
  const completed = await authorizationServer.completeAuthorization({
231
245
  transactionId,
232
246
  subject
233
247
  });
234
- await config.storage.credentials.set(subject, credential);
235
248
  await config.storage.interactions.delete(transactionId);
236
249
  return new Response(null, {
237
250
  status: 303,
@@ -281,11 +294,11 @@ export async function prepareHostedOAuthRuntime(config) {
281
294
  if (connected.accountId.trim().length === 0)
282
295
  throw new Error("Provider returned an empty accountId.");
283
296
  const subject = await config.storage.resolveSubject(config.provider.name, connected.accountId);
297
+ await config.storage.credentials.set(subject, connected.credential);
284
298
  const completed = await authorizationServer.completeAuthorization({
285
299
  transactionId,
286
300
  subject
287
301
  });
288
- await config.storage.credentials.set(subject, connected.credential);
289
302
  await config.storage.interactions.delete(transactionId);
290
303
  response.writeHead(303, {
291
304
  location: completed.redirectUrl.href,