@polyester/sdk 0.35.0-devnet-20261111161451 → 0.35.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 (59) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/dist/services/accounts/accounts.d.ts +1 -1
  3. package/dist/services/accounts/accounts.js +1 -1
  4. package/dist/services/accounts/accounts.js.map +1 -1
  5. package/dist/services/api-keys/api-keys.d.ts +2 -2
  6. package/dist/services/api-keys/api-keys.js +2 -2
  7. package/dist/services/api-keys/api-keys.js.map +1 -1
  8. package/dist/services/assistant/assistant-events.schemas.d.ts +129 -101
  9. package/dist/services/assistant/assistant-events.schemas.d.ts.map +1 -1
  10. package/dist/services/auth/profile/profile.d.ts +2 -2
  11. package/dist/services/auth/profile/profile.js +2 -2
  12. package/dist/services/auth/profile/profile.js.map +1 -1
  13. package/dist/services/balances/balances.schemas.d.ts +3 -3
  14. package/dist/services/candles/candles.schemas.d.ts +10 -10
  15. package/dist/services/changelog/changelog.schemas.d.ts +17 -17
  16. package/dist/services/checkpoints/checkpoints.d.ts +2 -2
  17. package/dist/services/checkpoints/checkpoints.js +2 -2
  18. package/dist/services/checkpoints/checkpoints.js.map +1 -1
  19. package/dist/services/checkpoints/checkpoints.schemas.d.ts +1 -1
  20. package/dist/services/deposit/deposit.d.ts +2 -2
  21. package/dist/services/deposit/deposit.js +2 -2
  22. package/dist/services/deposit/deposit.js.map +1 -1
  23. package/dist/services/guard-signer/guard-signer.d.ts +1 -1
  24. package/dist/services/guard-signer/guard-signer.js +1 -1
  25. package/dist/services/guard-signer/guard-signer.js.map +1 -1
  26. package/dist/services/heatmap/heatmap.schemas.d.ts +13 -13
  27. package/dist/services/internal-transfers/internal-transfers.schemas.d.ts +3 -3
  28. package/dist/services/lifecycle/lifecycle.schemas.d.ts +148 -148
  29. package/dist/services/market-overview/market-overview.schemas.d.ts +3 -3
  30. package/dist/services/orderbook/orderbook.schemas.d.ts +1 -1
  31. package/dist/services/orders/orders-batch.schemas.d.ts +19 -19
  32. package/dist/services/orders/orders-input.schemas.d.ts +1 -1
  33. package/dist/services/orders/orders-output.schemas.d.ts +22 -22
  34. package/dist/services/policies/api-key-policies/api-key-policies.d.ts +2 -2
  35. package/dist/services/policies/api-key-policies/api-key-policies.js +2 -2
  36. package/dist/services/policies/api-key-policies/api-key-policies.js.map +1 -1
  37. package/dist/services/policies/subaccount-policies/subaccount-policies.d.ts +2 -2
  38. package/dist/services/policies/subaccount-policies/subaccount-policies.js +2 -2
  39. package/dist/services/policies/subaccount-policies/subaccount-policies.js.map +1 -1
  40. package/dist/services/rewards/rewards.schemas.d.ts +4 -4
  41. package/dist/services/social-verification/social-verification.d.ts +1 -1
  42. package/dist/services/social-verification/social-verification.js +1 -1
  43. package/dist/services/social-verification/social-verification.js.map +1 -1
  44. package/dist/services/subaccounts/subaccounts.d.ts +6 -6
  45. package/dist/services/subaccounts/subaccounts.js +6 -6
  46. package/dist/services/subaccounts/subaccounts.js.map +1 -1
  47. package/dist/services/subaccounts/subaccounts.schemas.d.ts +12 -12
  48. package/dist/services/trades/trades.schemas.d.ts +1 -1
  49. package/dist/services/trading-withdraws/trading-withdraws.d.ts +1 -1
  50. package/dist/services/trading-withdraws/trading-withdraws.js +1 -1
  51. package/dist/services/trading-withdraws/trading-withdraws.js.map +1 -1
  52. package/dist/services/transfers/transfers.schemas.d.ts +1 -1
  53. package/dist/services/triggers/trigger-input.schemas.d.ts +2 -2
  54. package/dist/services/triggers/triggers-output.schemas.d.ts +37 -37
  55. package/dist/services/vip/vip.d.ts +1 -1
  56. package/dist/services/vip/vip.js +1 -1
  57. package/dist/services/vip/vip.js.map +1 -1
  58. package/dist/services/vip/vip.schemas.d.ts +3 -3
  59. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @polyester/sdk
2
2
 
3
- ## 0.35.0-devnet-20261111161451
3
+ ## 0.35.0
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -18,6 +18,8 @@
18
18
 
19
19
  - `createApiKeyEd25519AuthHeaders` now builds the same canonical string as the server's API-key verifier, so requests with escaped or unusual URLs stop failing signature checks. It signs the upper-cased method and the percent-decoded path, sorts query pairs by their decoded bytes (key, then value), and escapes everything outside `A-Z a-z 0-9 - . _ ~`, keeping bytes that are not UTF-8. A URL with a `;` in its query or a malformed percent-escape now throws `ConfigurationError` before signing, because the server rejects those requests whatever the signature. The tests pin the signing vectors shared with the Go, Python and Rust SDKs. ([#238](https://github.com/Fabric-Labs/polyester-sdk-typescript/pull/238))
20
20
 
21
+ - `checkpoints.list` docs no longer say API keys are refused: an API key scoped to the main account whose policy grants `read-checkpoints` can call it. Each method that API keys can now call names the permission it needs in its docs: API keys, policies, profile, accounts, social verification, VIP status, deposit addresses, withdraw validation, Guard Signer status and the sub-account reads. ([#250](https://github.com/Fabric-Labs/polyester-sdk-typescript/pull/250))
22
+
21
23
  - API keys add `purpose`: `"standard"` for keys the account holder made, `"assistant"` for keys made for the Polyester AI assistant, whose policy can never move value out of the account, or `"unspecified"` from older servers. Assistant keys are listed, updated and revoked like any other key. ([#247](https://github.com/Fabric-Labs/polyester-sdk-typescript/pull/247))
22
24
 
23
25
  - The API-key `recvWindow` docs now give the backend default of 5000 ms, down from 10000. The backend also refuses timestamps more than 1000 ms ahead of its clock, so keep the client clock synchronized. Signing is unchanged: HTTP requests never sent `X-API-NONCE`. ([#247](https://github.com/Fabric-Labs/polyester-sdk-typescript/pull/247))
@@ -9,7 +9,7 @@ declare class AccountsService {
9
9
  #private;
10
10
  constructor(transports: AuthApiTransports);
11
11
  /**
12
- * Resolves a username, opaque account/subaccount ID, or smart-account address into matching destination accounts; set includeSubaccounts for internal-transfer flows that may target subaccounts.
12
+ * Resolves a username, opaque account/subaccount ID, or smart-account address into matching destination accounts; set includeSubaccounts for internal-transfer flows that may target subaccounts. API keys need `read-account-directory`.
13
13
  */
14
14
  resolve(input: ResolveAccountInput, options?: PolyesterRequestOptions): Promise<ResolvedAccount[]>;
15
15
  }
@@ -13,7 +13,7 @@ var AccountsService = class {
13
13
  this.#client = createClient(ResolveService, transports.authApi);
14
14
  }
15
15
  /**
16
- * Resolves a username, opaque account/subaccount ID, or smart-account address into matching destination accounts; set includeSubaccounts for internal-transfer flows that may target subaccounts.
16
+ * Resolves a username, opaque account/subaccount ID, or smart-account address into matching destination accounts; set includeSubaccounts for internal-transfer flows that may target subaccounts. API keys need `read-account-directory`.
17
17
  */
18
18
  async resolve(input, options) {
19
19
  const validatedInput = parse(ResolveAccountInputSchema, input);
@@ -1 +1 @@
1
- {"version":3,"file":"accounts.js","names":["#client","ProtoResolve.ResolveService"],"sources":["../../../src/services/accounts/accounts.ts"],"sourcesContent":["import { createClient, type Client } from \"@connectrpc/connect\";\nimport * as ProtoResolve from \"../../gen/auth/v1/resolve_pb.js\";\nimport type { AuthApiTransports } from \"../../shared/transports.js\";\nimport { parse } from \"../../shared/validation.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport {\n ResolveAccountInputSchema,\n ResolvedAccountArraySchema,\n type ResolveAccountInput,\n type ResolvedAccount,\n} from \"./accounts.schemas.js\";\n\n/**\n * Resolves user-entered account identifiers into transfer/shareable root or subaccount destinations.\n */\nexport class AccountsService {\n #client: Client<typeof ProtoResolve.ResolveService>;\n\n constructor(transports: AuthApiTransports) {\n this.#client = createClient(ProtoResolve.ResolveService, transports.authApi);\n }\n\n /**\n * Resolves a username, opaque account/subaccount ID, or smart-account address into matching destination accounts; set includeSubaccounts for internal-transfer flows that may target subaccounts.\n */\n async resolve(\n input: ResolveAccountInput,\n options?: PolyesterRequestOptions,\n ): Promise<ResolvedAccount[]> {\n const validatedInput = parse(ResolveAccountInputSchema, input);\n const res = await this.#client.resolveAccount(\n validatedInput,\n toConnectCallOptions(options),\n );\n\n return parse(ResolvedAccountArraySchema, res.matches);\n }\n}\n"],"mappings":";;;;;;;;;AAkBA,IAAa,kBAAb,MAA6B;CACzB;CAEA,YAAY,YAA+B;EACvC,KAAKA,UAAU,aAAaC,gBAA6B,WAAW,OAAO;CAC/E;;;;CAKA,MAAM,QACF,OACA,SAC0B;EAC1B,MAAM,iBAAiB,MAAM,2BAA2B,KAAK;EAC7D,MAAM,MAAM,MAAM,KAAKD,QAAQ,eAC3B,gBACA,qBAAqB,OAAO,CAChC;EAEA,OAAO,MAAM,4BAA4B,IAAI,OAAO;CACxD;AACJ"}
1
+ {"version":3,"file":"accounts.js","names":["#client","ProtoResolve.ResolveService"],"sources":["../../../src/services/accounts/accounts.ts"],"sourcesContent":["import { createClient, type Client } from \"@connectrpc/connect\";\nimport * as ProtoResolve from \"../../gen/auth/v1/resolve_pb.js\";\nimport type { AuthApiTransports } from \"../../shared/transports.js\";\nimport { parse } from \"../../shared/validation.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport {\n ResolveAccountInputSchema,\n ResolvedAccountArraySchema,\n type ResolveAccountInput,\n type ResolvedAccount,\n} from \"./accounts.schemas.js\";\n\n/**\n * Resolves user-entered account identifiers into transfer/shareable root or subaccount destinations.\n */\nexport class AccountsService {\n #client: Client<typeof ProtoResolve.ResolveService>;\n\n constructor(transports: AuthApiTransports) {\n this.#client = createClient(ProtoResolve.ResolveService, transports.authApi);\n }\n\n /**\n * Resolves a username, opaque account/subaccount ID, or smart-account address into matching destination accounts; set includeSubaccounts for internal-transfer flows that may target subaccounts. API keys need `read-account-directory`.\n */\n async resolve(\n input: ResolveAccountInput,\n options?: PolyesterRequestOptions,\n ): Promise<ResolvedAccount[]> {\n const validatedInput = parse(ResolveAccountInputSchema, input);\n const res = await this.#client.resolveAccount(\n validatedInput,\n toConnectCallOptions(options),\n );\n\n return parse(ResolvedAccountArraySchema, res.matches);\n }\n}\n"],"mappings":";;;;;;;;;AAkBA,IAAa,kBAAb,MAA6B;CACzB;CAEA,YAAY,YAA+B;EACvC,KAAKA,UAAU,aAAaC,gBAA6B,WAAW,OAAO;CAC/E;;;;CAKA,MAAM,QACF,OACA,SAC0B;EAC1B,MAAM,iBAAiB,MAAM,2BAA2B,KAAK;EAC7D,MAAM,MAAM,MAAM,KAAKD,QAAQ,eAC3B,gBACA,qBAAqB,OAAO,CAChC;EAEA,OAAO,MAAM,4BAA4B,IAAI,OAAO;CACxD;AACJ"}
@@ -20,11 +20,11 @@ declare class ApiKeysService {
20
20
  readonly policies: ApiKeyPoliciesService;
21
21
  constructor(transports: AuthApiTransports, realtime: PolyesterRealtime, resolver?: SubaccountResolver);
22
22
  /**
23
- * Returns non-revoked API keys owned by the caller, newest first, optionally scoped through an explicit or resolver-provided subaccount ID.
23
+ * Returns non-revoked API keys owned by the caller, newest first, optionally scoped through an explicit or resolver-provided subaccount ID. API keys need `read-api-keys`; a key scoped to a sub-account sees only that sub-account's keys.
24
24
  */
25
25
  list(params?: v.InferInput<typeof ApiKeysListInputSchema>, options?: PolyesterRequestOptions): Promise<ApiKey[]>;
26
26
  /**
27
- * Fetches one caller-owned API key by ak_... key ID and returns null when no matching key is returned.
27
+ * Fetches one caller-owned API key by ak_... key ID and returns null when no matching key is returned. API keys need `read-api-keys`.
28
28
  */
29
29
  get(input: v.InferInput<typeof ApiKeyIdInputSchema>, options?: PolyesterRequestOptions): Promise<ApiKey | null>;
30
30
  /**
@@ -24,7 +24,7 @@ var ApiKeysService = class {
24
24
  this.#resolver = resolver;
25
25
  }
26
26
  /**
27
- * Returns non-revoked API keys owned by the caller, newest first, optionally scoped through an explicit or resolver-provided subaccount ID.
27
+ * Returns non-revoked API keys owned by the caller, newest first, optionally scoped through an explicit or resolver-provided subaccount ID. API keys need `read-api-keys`; a key scoped to a sub-account sees only that sub-account's keys.
28
28
  */
29
29
  async list(params = {}, options) {
30
30
  const resolved = resolveAccountScopedInput(params, this.#resolver);
@@ -33,7 +33,7 @@ var ApiKeysService = class {
33
33
  return parse(ApiKeysSchema, res.apiKeys);
34
34
  }
35
35
  /**
36
- * Fetches one caller-owned API key by ak_... key ID and returns null when no matching key is returned.
36
+ * Fetches one caller-owned API key by ak_... key ID and returns null when no matching key is returned. API keys need `read-api-keys`.
37
37
  */
38
38
  async get(input, options) {
39
39
  const validatedInput = parse(ApiKeyIdInputSchema, input);
@@ -1 +1 @@
1
- {"version":3,"file":"api-keys.js","names":["#client","Proto.ApiKeyService","#realtime","#resolver","ApiKeySchema","Proto.ApiKeySchema"],"sources":["../../../src/services/api-keys/api-keys.ts"],"sourcesContent":["import { createClient, type Client } from \"@connectrpc/connect\";\nimport * as Proto from \"../../gen/auth/v1/api_keys_pb.js\";\nimport type { AuthApiTransports } from \"../../shared/transports.js\";\nimport type * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport { removeUndefined } from \"../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport { bytesToHex } from \"@noble/hashes/utils.js\";\nimport { keygenAsync } from \"@noble/ed25519\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport { ApiKeyPoliciesService } from \"../policies/api-key-policies/index.js\";\nimport {\n ApiKeyIdInputSchema,\n ApiKeysListInputSchema,\n ApiKeysCreateInputSchema,\n ApiKeysUpdateInputSchema,\n ApiKeySchema,\n ApiKeysSchema,\n SetAssistantKeysInputSchema,\n type ApiKey,\n type SetAssistantKeysInput,\n} from \"./api-keys.schemas.js\";\n\ninterface SubscribeApiKeysInput extends BaseSubscribeInput<ApiKey> {\n accountId: string;\n}\n\n/**\n * Manages API key metadata, client-generated Ed25519 keypairs, policies, and realtime API key updates.\n */\nexport class ApiKeysService {\n readonly policies: ApiKeyPoliciesService;\n\n #client: Client<typeof Proto.ApiKeyService>;\n #realtime: PolyesterRealtime;\n #resolver?: SubaccountResolver;\n\n constructor(\n transports: AuthApiTransports,\n realtime: PolyesterRealtime,\n resolver?: SubaccountResolver,\n ) {\n this.policies = new ApiKeyPoliciesService(transports);\n this.#client = createClient(Proto.ApiKeyService, transports.authApi);\n this.#realtime = realtime;\n this.#resolver = resolver;\n }\n\n /**\n * Returns non-revoked API keys owned by the caller, newest first, optionally scoped through an explicit or resolver-provided subaccount ID.\n */\n async list(\n params: v.InferInput<typeof ApiKeysListInputSchema> = {},\n options?: PolyesterRequestOptions,\n ): Promise<ApiKey[]> {\n const resolved = resolveAccountScopedInput(params, this.#resolver);\n const validatedParams = parse(ApiKeysListInputSchema, resolved);\n const res = await this.#client.listApiKeys(\n removeUndefined(validatedParams),\n toConnectCallOptions(options),\n );\n\n return parse(ApiKeysSchema, res.apiKeys);\n }\n\n /**\n * Fetches one caller-owned API key by ak_... key ID and returns null when no matching key is returned.\n */\n async get(\n input: v.InferInput<typeof ApiKeyIdInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<ApiKey | null> {\n const validatedInput = parse(ApiKeyIdInputSchema, input);\n const res = await this.#client.getApiKey(validatedInput, toConnectCallOptions(options));\n return res.apiKey ? parse(ApiKeySchema, res.apiKey) : null;\n }\n\n /**\n * Creates API key metadata using a client-generated Ed25519 public key; security settings may require MFA fresh step-up and retrying with stepUpToken.\n */\n async create(\n payload: v.InferInput<typeof ApiKeysCreateInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<ApiKey | null> {\n const resolved = resolveAccountScopedInput(payload, this.#resolver);\n const validatedPayload = parse(ApiKeysCreateInputSchema, resolved);\n const res = await this.#client.createApiKey(\n removeUndefined(validatedPayload),\n toConnectCallOptions(options),\n );\n return res.apiKey ? parse(ApiKeySchema, res.apiKey) : null;\n }\n\n /**\n * Permanently revokes the specified API key; revoked keys cannot authenticate again.\n */\n async delete(\n input: v.InferInput<typeof ApiKeyIdInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<void> {\n const validatedInput = parse(ApiKeyIdInputSchema, input);\n await this.#client.deleteApiKey(validatedInput, toConnectCallOptions(options));\n }\n\n /**\n * Updates mutable key metadata, ACTIVE/DISABLED status, IP whitelist replacement/clearing, and optional expiry; revocation must use delete.\n */\n async update(\n payload: v.InferInput<typeof ApiKeysUpdateInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<ApiKey | null> {\n const validatedPayload = parse(ApiKeysUpdateInputSchema, payload);\n const res = await this.#client.updateApiKey(\n removeUndefined(validatedPayload),\n toConnectCallOptions(options),\n );\n return res.apiKey ? parse(ApiKeySchema, res.apiKey) : null;\n }\n\n /**\n * Replaces the caller's Polyester AI assistant key set: one `assistant` key per account,\n * each bounded by its API policy, all or nothing. Register the keys `assistant.prepareKeys`\n * returned before their deadline, then call `assistant.completeKeys`. Needs a fresh\n * `stepUpToken` for the whole set. A policy that allows moving value out throws\n * `PreconditionFailedError` (`AUTH_ASSISTANT_KEY_ACTION_NOT_ALLOWED`).\n */\n async setAssistantKeys(\n input: SetAssistantKeysInput,\n options?: PolyesterMutationOptions,\n ): Promise<ApiKey[]> {\n const request = parse(SetAssistantKeysInputSchema, input);\n const res = await this.#client.setAssistantKeys(\n { keys: request.keys.map((key) => removeUndefined(key)) },\n toConnectCallOptions(options),\n );\n return parse(ApiKeysSchema, res.apiKeys);\n }\n\n /** Lists the caller's non-revoked assistant keys, newest first. */\n async listAssistantKeys(options?: PolyesterRequestOptions): Promise<ApiKey[]> {\n const res = await this.#client.listAssistantKeys({}, toConnectCallOptions(options));\n return parse(ApiKeysSchema, res.apiKeys);\n }\n\n /**\n * Permanently revokes the caller's whole assistant key set; needs no step-up. Returns the\n * revoked key IDs, empty when the set was already empty.\n */\n async deleteAssistantKeys(options?: PolyesterMutationOptions): Promise<string[]> {\n const res = await this.#client.deleteAssistantKeys({}, toConnectCallOptions(options));\n return res.revokedKeyIds;\n }\n\n /**\n * Generates an Ed25519 keypair locally and returns public and secret key material as both hex strings and byte arrays; only the public key should be sent to the API.\n */\n async generateKeypair(): Promise<{\n publicKey: { hex: string; bytes: Uint8Array };\n secretKey: { hex: string; bytes: Uint8Array };\n }> {\n const { secretKey, publicKey } = await keygenAsync();\n return {\n publicKey: {\n hex: bytesToHex(publicKey),\n bytes: publicKey,\n },\n secretKey: {\n hex: bytesToHex(secretKey),\n bytes: secretKey,\n },\n };\n }\n\n /**\n * Subscribes to private API key updates for an account and emits normalized API key metadata from realtime protobuf publications.\n */\n subscribe(input: SubscribeApiKeysInput) {\n const channel = `private:auth:api-keys:${input.accountId}:proto`;\n\n return this.#realtime.connectProtoChannel({\n channel,\n schema: Proto.ApiKeySchema,\n onPublication: (data) => {\n const apiKey = parse(ApiKeySchema, data);\n input.onEvent(apiKey);\n },\n onConnected: () => input.onOpen?.(),\n onDisconnected: () => input.onClose?.(),\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAoCA,IAAa,iBAAb,MAA4B;CACxB;CAEA;CACA;CACA;CAEA,YACI,YACA,UACA,UACF;EACE,KAAK,WAAW,IAAI,sBAAsB,UAAU;EACpD,KAAKA,UAAU,aAAaC,eAAqB,WAAW,OAAO;EACnE,KAAKC,YAAY;EACjB,KAAKC,YAAY;CACrB;;;;CAKA,MAAM,KACF,SAAsD,CAAC,GACvD,SACiB;EACjB,MAAM,WAAW,0BAA0B,QAAQ,KAAKA,SAAS;EACjE,MAAM,kBAAkB,MAAM,wBAAwB,QAAQ;EAC9D,MAAM,MAAM,MAAM,KAAKH,QAAQ,YAC3B,gBAAgB,eAAe,GAC/B,qBAAqB,OAAO,CAChC;EAEA,OAAO,MAAM,eAAe,IAAI,OAAO;CAC3C;;;;CAKA,MAAM,IACF,OACA,SACsB;EACtB,MAAM,iBAAiB,MAAM,qBAAqB,KAAK;EACvD,MAAM,MAAM,MAAM,KAAKA,QAAQ,UAAU,gBAAgB,qBAAqB,OAAO,CAAC;EACtF,OAAO,IAAI,SAAS,MAAMI,gBAAc,IAAI,MAAM,IAAI;CAC1D;;;;CAKA,MAAM,OACF,SACA,SACsB;EACtB,MAAM,WA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B,OAAO;GACX;GACA,WAAW;IACP,KAAK,WAAW,SAAS;IACzB,OAAO;GACX;EACJ;CACJ;;;;CAKA,UAAU,OAA8B;EACpC,MAAM,UAAU,yBAAyB,MAAM,UAAU;EAEzD,OAAO,KAAKE,UAAU,oBAAoB;GACtC;GACA,QAAQG;GACR,gBAAgB,SAAS;IACrB,MAAM,SAAS,MAAMD,gBAAc,IAAI;IACvC,MAAM,QAAQ,MAAM;GACxB;GACA,mBAAmB,MAAM,SAAS;GAClC,sBAAsB,MAAM,UAAU;GACtC,SAAS,MAAM;EACnB,CAAC;CACL;AACJ"}
1
+ {"version":3,"file":"api-keys.js","names":["#client","Proto.ApiKeyService","#realtime","#resolver","ApiKeySchema","Proto.ApiKeySchema"],"sources":["../../../src/services/api-keys/api-keys.ts"],"sourcesContent":["import { createClient, type Client } from \"@connectrpc/connect\";\nimport * as Proto from \"../../gen/auth/v1/api_keys_pb.js\";\nimport type { AuthApiTransports } from \"../../shared/transports.js\";\nimport type * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport { removeUndefined } from \"../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport { bytesToHex } from \"@noble/hashes/utils.js\";\nimport { keygenAsync } from \"@noble/ed25519\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport { ApiKeyPoliciesService } from \"../policies/api-key-policies/index.js\";\nimport {\n ApiKeyIdInputSchema,\n ApiKeysListInputSchema,\n ApiKeysCreateInputSchema,\n ApiKeysUpdateInputSchema,\n ApiKeySchema,\n ApiKeysSchema,\n SetAssistantKeysInputSchema,\n type ApiKey,\n type SetAssistantKeysInput,\n} from \"./api-keys.schemas.js\";\n\ninterface SubscribeApiKeysInput extends BaseSubscribeInput<ApiKey> {\n accountId: string;\n}\n\n/**\n * Manages API key metadata, client-generated Ed25519 keypairs, policies, and realtime API key updates.\n */\nexport class ApiKeysService {\n readonly policies: ApiKeyPoliciesService;\n\n #client: Client<typeof Proto.ApiKeyService>;\n #realtime: PolyesterRealtime;\n #resolver?: SubaccountResolver;\n\n constructor(\n transports: AuthApiTransports,\n realtime: PolyesterRealtime,\n resolver?: SubaccountResolver,\n ) {\n this.policies = new ApiKeyPoliciesService(transports);\n this.#client = createClient(Proto.ApiKeyService, transports.authApi);\n this.#realtime = realtime;\n this.#resolver = resolver;\n }\n\n /**\n * Returns non-revoked API keys owned by the caller, newest first, optionally scoped through an explicit or resolver-provided subaccount ID. API keys need `read-api-keys`; a key scoped to a sub-account sees only that sub-account's keys.\n */\n async list(\n params: v.InferInput<typeof ApiKeysListInputSchema> = {},\n options?: PolyesterRequestOptions,\n ): Promise<ApiKey[]> {\n const resolved = resolveAccountScopedInput(params, this.#resolver);\n const validatedParams = parse(ApiKeysListInputSchema, resolved);\n const res = await this.#client.listApiKeys(\n removeUndefined(validatedParams),\n toConnectCallOptions(options),\n );\n\n return parse(ApiKeysSchema, res.apiKeys);\n }\n\n /**\n * Fetches one caller-owned API key by ak_... key ID and returns null when no matching key is returned. API keys need `read-api-keys`.\n */\n async get(\n input: v.InferInput<typeof ApiKeyIdInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<ApiKey | null> {\n const validatedInput = parse(ApiKeyIdInputSchema, input);\n const res = await this.#client.getApiKey(validatedInput, toConnectCallOptions(options));\n return res.apiKey ? parse(ApiKeySchema, res.apiKey) : null;\n }\n\n /**\n * Creates API key metadata using a client-generated Ed25519 public key; security settings may require MFA fresh step-up and retrying with stepUpToken.\n */\n async create(\n payload: v.InferInput<typeof ApiKeysCreateInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<ApiKey | null> {\n const resolved = resolveAccountScopedInput(payload, this.#resolver);\n const validatedPayload = parse(ApiKeysCreateInputSchema, resolved);\n const res = await this.#client.createApiKey(\n removeUndefined(validatedPayload),\n toConnectCallOptions(options),\n );\n return res.apiKey ? parse(ApiKeySchema, res.apiKey) : null;\n }\n\n /**\n * Permanently revokes the specified API key; revoked keys cannot authenticate again.\n */\n async delete(\n input: v.InferInput<typeof ApiKeyIdInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<void> {\n const validatedInput = parse(ApiKeyIdInputSchema, input);\n await this.#client.deleteApiKey(validatedInput, toConnectCallOptions(options));\n }\n\n /**\n * Updates mutable key metadata, ACTIVE/DISABLED status, IP whitelist replacement/clearing, and optional expiry; revocation must use delete.\n */\n async update(\n payload: v.InferInput<typeof ApiKeysUpdateInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<ApiKey | null> {\n const validatedPayload = parse(ApiKeysUpdateInputSchema, payload);\n const res = await this.#client.updateApiKey(\n removeUndefined(validatedPayload),\n toConnectCallOptions(options),\n );\n return res.apiKey ? parse(ApiKeySchema, res.apiKey) : null;\n }\n\n /**\n * Replaces the caller's Polyester AI assistant key set: one `assistant` key per account,\n * each bounded by its API policy, all or nothing. Register the keys `assistant.prepareKeys`\n * returned before their deadline, then call `assistant.completeKeys`. Needs a fresh\n * `stepUpToken` for the whole set. A policy that allows moving value out throws\n * `PreconditionFailedError` (`AUTH_ASSISTANT_KEY_ACTION_NOT_ALLOWED`).\n */\n async setAssistantKeys(\n input: SetAssistantKeysInput,\n options?: PolyesterMutationOptions,\n ): Promise<ApiKey[]> {\n const request = parse(SetAssistantKeysInputSchema, input);\n const res = await this.#client.setAssistantKeys(\n { keys: request.keys.map((key) => removeUndefined(key)) },\n toConnectCallOptions(options),\n );\n return parse(ApiKeysSchema, res.apiKeys);\n }\n\n /** Lists the caller's non-revoked assistant keys, newest first. */\n async listAssistantKeys(options?: PolyesterRequestOptions): Promise<ApiKey[]> {\n const res = await this.#client.listAssistantKeys({}, toConnectCallOptions(options));\n return parse(ApiKeysSchema, res.apiKeys);\n }\n\n /**\n * Permanently revokes the caller's whole assistant key set; needs no step-up. Returns the\n * revoked key IDs, empty when the set was already empty.\n */\n async deleteAssistantKeys(options?: PolyesterMutationOptions): Promise<string[]> {\n const res = await this.#client.deleteAssistantKeys({}, toConnectCallOptions(options));\n return res.revokedKeyIds;\n }\n\n /**\n * Generates an Ed25519 keypair locally and returns public and secret key material as both hex strings and byte arrays; only the public key should be sent to the API.\n */\n async generateKeypair(): Promise<{\n publicKey: { hex: string; bytes: Uint8Array };\n secretKey: { hex: string; bytes: Uint8Array };\n }> {\n const { secretKey, publicKey } = await keygenAsync();\n return {\n publicKey: {\n hex: bytesToHex(publicKey),\n bytes: publicKey,\n },\n secretKey: {\n hex: bytesToHex(secretKey),\n bytes: secretKey,\n },\n };\n }\n\n /**\n * Subscribes to private API key updates for an account and emits normalized API key metadata from realtime protobuf publications.\n */\n subscribe(input: SubscribeApiKeysInput) {\n const channel = `private:auth:api-keys:${input.accountId}:proto`;\n\n return this.#realtime.connectProtoChannel({\n channel,\n schema: Proto.ApiKeySchema,\n onPublication: (data) => {\n const apiKey = parse(ApiKeySchema, data);\n input.onEvent(apiKey);\n },\n onConnected: () => input.onOpen?.(),\n onDisconnected: () => input.onClose?.(),\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAoCA,IAAa,iBAAb,MAA4B;CACxB;CAEA;CACA;CACA;CAEA,YACI,YACA,UACA,UACF;EACE,KAAK,WAAW,IAAI,sBAAsB,UAAU;EACpD,KAAKA,UAAU,aAAaC,eAAqB,WAAW,OAAO;EACnE,KAAKC,YAAY;EACjB,KAAKC,YAAY;CACrB;;;;CAKA,MAAM,KACF,SAAsD,CAAC,GACvD,SACiB;EACjB,MAAM,WAAW,0BAA0B,QAAQ,KAAKA,SAAS;EACjE,MAAM,kBAAkB,MAAM,wBAAwB,QAAQ;EAC9D,MAAM,MAAM,MAAM,KAAKH,QAAQ,YAC3B,gBAAgB,eAAe,GAC/B,qBAAqB,OAAO,CAChC;EAEA,OAAO,MAAM,eAAe,IAAI,OAA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