@polyester/sdk 0.29.0 → 0.29.2
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/CHANGELOG.md +20 -0
- package/dist/gen/auth/v1/auth_pb.d.ts +7 -1
- package/dist/gen/auth/v1/auth_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/auth_pb.js +7 -1
- package/dist/gen/auth/v1/auth_pb.js.map +1 -1
- package/dist/gen/auth/v1/social_verification_pb.d.ts +9 -0
- package/dist/gen/auth/v1/social_verification_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/social_verification_pb.js +6 -1
- package/dist/gen/auth/v1/social_verification_pb.js.map +1 -1
- package/dist/gen/claims/v1/claims_pb.d.ts +7 -1
- package/dist/gen/claims/v1/claims_pb.d.ts.map +1 -1
- package/dist/gen/claims/v1/claims_pb.js +7 -1
- package/dist/gen/claims/v1/claims_pb.js.map +1 -1
- package/dist/gen/orders/v1/orders_read_pb.d.ts +3 -1
- package/dist/gen/orders/v1/orders_read_pb.d.ts.map +1 -1
- package/dist/gen/orders/v1/orders_read_pb.js.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.d.ts +6 -0
- package/dist/gen/triggers/v1/triggers_pb.d.ts.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.js +7 -1
- package/dist/gen/triggers/v1/triggers_pb.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/services/candles/candles.schemas.d.ts +10 -10
- package/dist/services/heatmap/heatmap.schemas.d.ts +13 -13
- package/dist/services/market-overview/market-overview.schemas.d.ts +3 -3
- package/dist/services/orderbook/orderbook.schemas.d.ts +1 -1
- package/dist/services/social-verification/index.d.ts +2 -2
- package/dist/services/social-verification/social-verification.codecs.js +95 -1
- package/dist/services/social-verification/social-verification.codecs.js.map +1 -1
- package/dist/services/social-verification/social-verification.schemas.d.ts +10 -1
- package/dist/services/social-verification/social-verification.schemas.d.ts.map +1 -1
- package/dist/services/social-verification/social-verification.schemas.js +3 -1
- package/dist/services/social-verification/social-verification.schemas.js.map +1 -1
- package/dist/services/social-verification/social-verification.types.d.ts +2 -2
- package/dist/services/subaccounts/subaccounts.d.ts +2 -1
- package/dist/services/subaccounts/subaccounts.d.ts.map +1 -1
- package/dist/services/subaccounts/subaccounts.js +2 -1
- package/dist/services/subaccounts/subaccounts.js.map +1 -1
- package/dist/services/subaccounts/subaccounts.schemas.d.ts +2 -2
- package/dist/services/trades/trades.schemas.d.ts +15 -14
- package/dist/services/trades/trades.schemas.d.ts.map +1 -1
- package/dist/services/trades/trades.schemas.js +10 -3
- package/dist/services/trades/trades.schemas.js.map +1 -1
- package/dist/services/triggers/triggers-output.schemas.d.ts +4 -4
- package/dist/services/triggers/triggers.codecs.js +1 -0
- package/dist/services/triggers/triggers.codecs.js.map +1 -1
- package/dist/shared/connect-error-mapping.d.ts.map +1 -1
- package/dist/shared/connect-error-mapping.js +6 -2
- package/dist/shared/connect-error-mapping.js.map +1 -1
- package/dist/shared/errors.d.ts +13 -2
- package/dist/shared/errors.d.ts.map +1 -1
- package/dist/shared/errors.js +14 -1
- package/dist/shared/errors.js.map +1 -1
- package/dist/shared/transports.d.ts +5 -0
- package/dist/shared/transports.d.ts.map +1 -1
- package/dist/shared/transports.js +14 -2
- package/dist/shared/transports.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subaccounts.js","names":["#client","Proto.SubaccountService","#viewClient","Proto.SubaccountViewService","#publicRoleClient","Proto.SubaccountRoleService","#authRoleClient","#realtime","SubaccountSchema","ApiKeySchema","Proto.SubaccountSchema","ProtoApiKeys.ApiKeySchema"],"sources":["../../../src/services/subaccounts/subaccounts.ts"],"sourcesContent":["import * as Proto from \"../../gen/auth/v1/subaccounts_pb.js\";\nimport * as ProtoApiKeys from \"../../gen/auth/v1/api_keys_pb.js\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport { type ApiKey, ApiKeySchema } from \"../api-keys/index.js\";\nimport { formatId } from \"../../utils/base58-id.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\nimport {\n DEFAULT_SUBACCOUNT_POLICY,\n SubaccountPoliciesService,\n type SubaccountPolicy,\n SubaccountPolicySchema,\n} from \"../policies/subaccount-policies/index.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport type { AuthAndPublicApiTransports } from \"../../shared/transports.js\";\nimport type { SubaccountResolver } from \"../subaccount-resolver.js\";\nimport {\n CreateSubaccountChallengeInputSchema,\n CreateSubaccountInputSchema,\n CreateSubaccountResultSchema,\n SubaccountChallengeSchema,\n UpdateSubaccountInputSchema,\n InviteSubaccountMemberInputSchema,\n RemoveSubaccountMemberInputSchema,\n UpdateSubaccountMemberRoleInputSchema,\n ListSubaccountInvitesInputSchema,\n RespondSubaccountInviteInputSchema,\n SubaccountActivityInputSchema,\n SubaccountSchema,\n SubaccountMemberSchema,\n SubaccountInviteSchema,\n SubaccountActivityEventSchema,\n SetSubaccountMemberMfaRequirementInputSchema,\n SubaccountIdInputSchema,\n SubaccountMutationResultSchema,\n SubaccountRoleCatalogSchema,\n EffectiveSubaccountPermissionsSchema,\n type CreateSubaccountResult,\n type SubaccountChallenge,\n type Subaccount,\n type SubaccountMember,\n type SubaccountInvite,\n type SubaccountEvent,\n type SubaccountMutationResult,\n type SubaccountRoleCatalog,\n type EffectiveSubaccountPermissions,\n} from \"./subaccounts.schemas.js\";\n\ninterface SubscribeSubaccountsInput extends BaseSubscribeInput<Subaccount> {\n accountId: string;\n}\n\ninterface SubscribeApiKeysInput extends BaseSubscribeInput<ApiKey> {\n accountId: string;\n}\n\n/**\n * Reads the public role catalog and creates, manages, shares, audits, and subscribes to subaccounts visible to the authenticated caller.\n */\nexport class SubaccountsService {\n readonly policies: SubaccountPoliciesService;\n\n #client: Client<typeof Proto.SubaccountService>;\n #viewClient: Client<typeof Proto.SubaccountViewService>;\n #publicRoleClient: Client<typeof Proto.SubaccountRoleService>;\n #authRoleClient: Client<typeof Proto.SubaccountRoleService>;\n #realtime: PolyesterRealtime;\n\n constructor(\n transports: AuthAndPublicApiTransports,\n realtime: PolyesterRealtime,\n resolver?: SubaccountResolver,\n ) {\n this.policies = new SubaccountPoliciesService(transports, realtime, resolver);\n this.#client = createClient(Proto.SubaccountService, transports.authApi);\n this.#viewClient = createClient(Proto.SubaccountViewService, transports.authApi);\n this.#publicRoleClient = createClient(Proto.SubaccountRoleService, transports.publicApi);\n this.#authRoleClient = createClient(Proto.SubaccountRoleService, transports.authApi);\n this.#realtime = realtime;\n }\n\n /**\n * Returns subaccounts owned by or shared with the caller plus totalCreated, including soft-deleted ones. Use `createChallenge` for the canonical next smart-account address and salt.\n */\n async list(options?: PolyesterRequestOptions): Promise<{\n totalCreated: number;\n subaccounts: v.InferOutput<typeof SubaccountSchema>[];\n }> {\n const res = await this.#client.listSubaccounts({}, toConnectCallOptions(options));\n return {\n totalCreated: res.totalCreated,\n subaccounts: parse(v.array(SubaccountSchema), res.subaccounts),\n };\n }\n\n /**\n * Fetches an aggregated subaccount dashboard view with subaccount details, policy, API keys, balances, members, and outgoing invites; throws if the subaccount is missing.\n */\n async get(\n input: v.InferInput<typeof SubaccountIdInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<\n Subaccount & {\n apiKeys: ApiKey[];\n policy: SubaccountPolicy;\n members: SubaccountMember[];\n invites: SubaccountInvite[];\n }\n > {\n const validatedInput = parse(SubaccountIdInputSchema, input);\n const subaccountId = formatId(validatedInput.subaccountId);\n const res = await this.#viewClient.getSubaccount(\n {\n subaccountId: validatedInput.subaccountId,\n includeApiKeys: true,\n includeBalances: true,\n includeMembers: true,\n includeInvites: true,\n includePolicy: true,\n invitesDirection: Proto.SubaccountInviteDirection.OUTGOING,\n },\n toConnectCallOptions(options),\n );\n if (!res.subaccount) throw new Error(`Subaccount not found: ${subaccountId}`);\n\n return {\n ...parse(SubaccountSchema, res.subaccount),\n policy: res.policy\n ? parse(SubaccountPolicySchema, res.policy)\n : DEFAULT_SUBACCOUNT_POLICY,\n apiKeys: parse(v.optional(v.array(ApiKeySchema), []), res.apiKeys),\n members: parse(v.optional(v.array(SubaccountMemberSchema), []), res.members),\n invites: v\n .parse(v.optional(v.array(SubaccountInviteSchema), []), res.invites)\n .filter((invite) => invite.subaccountId === subaccountId),\n };\n }\n\n /**\n * Requests the canonical next smart account and a short-lived EIP-191 authorization message\n * bound to the authenticated root and the selected owner EOA. Sign the exact message through\n * the returned smart account, then pass it to `create`. A new challenge replaces the previous one.\n */\n async createChallenge(\n input: v.InferInput<typeof CreateSubaccountChallengeInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<SubaccountChallenge> {\n const validatedInput = parse(CreateSubaccountChallengeInputSchema, input);\n const res = await this.#client.createSubaccountChallenge(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(SubaccountChallengeSchema, res);\n }\n\n /**\n * Creates a new subaccount under the caller's root account using the smart-account address, message, and smart-account signature from `createChallenge`.\n */\n async create(\n input: v.InferInput<typeof CreateSubaccountInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<CreateSubaccountResult> {\n const validatedInput = parse(CreateSubaccountInputSchema, input);\n const res = await this.#client.createSubaccount(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(CreateSubaccountResultSchema, res);\n }\n\n /**\n * Updates mutable subaccount display/status fields such as label and active/disabled status.\n */\n async update(\n input: v.InferInput<typeof UpdateSubaccountInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<Subaccount> {\n const validatedInput = parse(UpdateSubaccountInputSchema, input);\n const res = await this.#client.updateSubaccount(\n validatedInput,\n toConnectCallOptions(options),\n );\n if (!res.subaccount) throw new Error(\"Failed to update subaccount\");\n return parse(SubaccountSchema, res.subaccount);\n }\n\n /**\n * Creates or refreshes a pending invitation granting a role on a subaccount to another root account.\n */\n async inviteMember(\n input: v.InferInput<typeof InviteSubaccountMemberInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<SubaccountInvite> {\n const validatedInput = parse(InviteSubaccountMemberInputSchema, input);\n const res = await this.#client.inviteSubaccountMember(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(SubaccountInviteSchema, res.invite);\n }\n\n /**\n * Removes delegated access for a subaccount member by grantee account ID.\n */\n async removeMember(\n input: v.InferInput<typeof RemoveSubaccountMemberInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<SubaccountMutationResult> {\n const validatedInput = parse(RemoveSubaccountMemberInputSchema, input);\n const res = await this.#client.removeSubaccountMember(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(SubaccountMutationResultSchema, res);\n }\n\n /**\n * Changes an existing delegated member's role without sending a new invitation.\n */\n async updateMemberRole(\n input: v.InferInput<typeof UpdateSubaccountMemberRoleInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<SubaccountMutationResult> {\n const validatedInput = parse(UpdateSubaccountMemberRoleInputSchema, input);\n const res = await this.#client.updateSubaccountMemberRole(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(SubaccountMutationResultSchema, res);\n }\n\n /**\n * Enables or disables the owner-controlled MFA requirement for delegated interactive member actions on a subaccount.\n */\n async setMemberMfaRequirement(\n input: v.InferInput<typeof SetSubaccountMemberMfaRequirementInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<SubaccountMutationResult> {\n const validatedInput = parse(SetSubaccountMemberMfaRequirementInputSchema, input);\n const res = await this.#client.setSubaccountMemberMFARequirement(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(SubaccountMutationResultSchema, res);\n }\n\n /**\n * Returns incoming, outgoing, or all subaccount invitations for the caller, newest first.\n */\n async listInvites(\n input: v.InferInput<typeof ListSubaccountInvitesInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<SubaccountInvite[]> {\n const validatedInput = parse(ListSubaccountInvitesInputSchema, input);\n const res = await this.#client.listSubaccountInvites(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(v.array(SubaccountInviteSchema), res.invites);\n }\n\n /**\n * Returns the public built-in role and permission catalog with display metadata and per-role permission sets.\n */\n async listRoles(options?: PolyesterRequestOptions): Promise<SubaccountRoleCatalog> {\n const res = await this.#publicRoleClient.listSubaccountRoles(\n {},\n toConnectCallOptions(options),\n );\n return parse(SubaccountRoleCatalogSchema, res);\n }\n\n /**\n * Returns the caller's current role, effective role-granted permissions, and attached policy ID for a subaccount.\n */\n async getEffectivePermissions(\n input: v.InferInput<typeof SubaccountIdInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<EffectiveSubaccountPermissions> {\n const validatedInput = parse(SubaccountIdInputSchema, input);\n const res = await this.#authRoleClient.getEffectiveSubaccountPermissions(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(EffectiveSubaccountPermissionsSchema, res);\n }\n\n /**\n * Returns the owner and delegated members for a subaccount, including role and MFA enrollment status.\n */\n async listMembers(\n input: v.InferInput<typeof SubaccountIdInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<SubaccountMember[]> {\n const validatedInput = parse(SubaccountIdInputSchema, input);\n const res = await this.#client.listSubaccountMembers(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(v.array(SubaccountMemberSchema), res.members);\n }\n\n /**\n * Accepts or rejects an incoming invite, or cancels an outgoing invite, returning the updated invitation.\n */\n async respondInvite(\n input: v.InferInput<typeof RespondSubaccountInviteInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<SubaccountInvite> {\n const validatedInput = parse(RespondSubaccountInviteInputSchema, input);\n const res = await this.#client.respondSubaccountInvite(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(SubaccountInviteSchema, res.invite);\n }\n\n /**\n * Returns paginated audit/activity events for a subaccount, newest first, with a non-negative integer limit from 0 through 200 and opaque cursor pagination.\n */\n async listEvents(\n input: v.InferInput<typeof SubaccountActivityInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<{ events: SubaccountEvent[]; nextPageToken: string }> {\n const validatedInput = parse(SubaccountActivityInputSchema, input);\n const res = await this.#viewClient.listSubaccountActivity(\n validatedInput,\n toConnectCallOptions(options),\n );\n return {\n events: parse(v.optional(v.array(SubaccountActivityEventSchema), []), res.events),\n nextPageToken: res.nextPageToken,\n };\n }\n\n /**\n * Subscribes to private subaccount updates for an account and emits normalized subaccount records.\n */\n subscribe(input: SubscribeSubaccountsInput) {\n const channel = `private:auth:subaccounts:${input.accountId}:proto`;\n\n return this.#realtime.connectProtoChannel({\n channel,\n schema: Proto.SubaccountSchema,\n onPublication: (data) => {\n const subaccount = parse(SubaccountSchema, data);\n input.onEvent(subaccount);\n },\n onConnected: () => input.onOpen?.(),\n onDisconnected: () => input.onClose?.(),\n onError: input.onError,\n });\n }\n\n /**\n * Subscribes to private API key updates for an account through the subaccount realtime channel helper.\n */\n subscribeApiKeys(input: SubscribeApiKeysInput) {\n const channel = `private:auth:api-keys:${input.accountId}:proto`;\n\n return this.#realtime.connectProtoChannel({\n channel,\n schema: ProtoApiKeys.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":";;;;;;;;;;;;;;;AAiEA,IAAa,qBAAb,MAAgC;CAC5B;CAEA;CACA;CACA;CACA;CACA;CAEA,YACI,YACA,UACA,UACF;EACE,KAAK,WAAW,IAAI,0BAA0B,YAAY,UAAU,QAAQ;EAC5E,KAAKA,UAAU,aAAaC,mBAAyB,WAAW,OAAO;EACvE,KAAKC,cAAc,aAAaC,uBAA6B,WAAW,OAAO;EAC/E,KAAKC,oBAAoB,aAAaC,uBAA6B,WAAW,SAAS;EACvF,KAAKC,kBAAkB,aAAaD,uBAA6B,WAAW,OAAO;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,QAAQG;GACR,gBAAgB,SAAS;IACrB,MAAM,aAAa,MAAMF,oBAAkB,IAAI;IAC/C,MAAM,QAAQ,UAAU;GAC5B;GACA,mBAAmB,MAAM,SAAS;GAClC,sBAAsB,MAAM,UAAU;GACtC,SAAS,MAAM;EACnB,CAAC;CACL;;;;CAKA,iBAAiB,OAA8B;EAC3C,MAAM,UAAU,yBAAyB,MAAM,UAAU;EAEzD,OAAO,KAAKD,UAAU,oBAAoB;GACtC;GACA,QAAQI;GACR,gBAAgB,SAAS;IACrB,MAAM,SAAS,MAAMF,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":"subaccounts.js","names":["#client","Proto.SubaccountService","#viewClient","Proto.SubaccountViewService","#publicRoleClient","Proto.SubaccountRoleService","#authRoleClient","#realtime","SubaccountSchema","ApiKeySchema","Proto.SubaccountSchema","ProtoApiKeys.ApiKeySchema"],"sources":["../../../src/services/subaccounts/subaccounts.ts"],"sourcesContent":["import * as Proto from \"../../gen/auth/v1/subaccounts_pb.js\";\nimport * as ProtoApiKeys from \"../../gen/auth/v1/api_keys_pb.js\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport { type ApiKey, ApiKeySchema } from \"../api-keys/index.js\";\nimport { formatId } from \"../../utils/base58-id.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\nimport {\n DEFAULT_SUBACCOUNT_POLICY,\n SubaccountPoliciesService,\n type SubaccountPolicy,\n SubaccountPolicySchema,\n} from \"../policies/subaccount-policies/index.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport type { AuthAndPublicApiTransports } from \"../../shared/transports.js\";\nimport type { SubaccountResolver } from \"../subaccount-resolver.js\";\nimport {\n CreateSubaccountChallengeInputSchema,\n CreateSubaccountInputSchema,\n CreateSubaccountResultSchema,\n SubaccountChallengeSchema,\n UpdateSubaccountInputSchema,\n InviteSubaccountMemberInputSchema,\n RemoveSubaccountMemberInputSchema,\n UpdateSubaccountMemberRoleInputSchema,\n ListSubaccountInvitesInputSchema,\n RespondSubaccountInviteInputSchema,\n SubaccountActivityInputSchema,\n SubaccountSchema,\n SubaccountMemberSchema,\n SubaccountInviteSchema,\n SubaccountActivityEventSchema,\n SetSubaccountMemberMfaRequirementInputSchema,\n SubaccountIdInputSchema,\n SubaccountMutationResultSchema,\n SubaccountRoleCatalogSchema,\n EffectiveSubaccountPermissionsSchema,\n type CreateSubaccountResult,\n type SubaccountChallenge,\n type Subaccount,\n type SubaccountMember,\n type SubaccountInvite,\n type SubaccountEvent,\n type SubaccountMutationResult,\n type SubaccountRoleCatalog,\n type EffectiveSubaccountPermissions,\n} from \"./subaccounts.schemas.js\";\n\ninterface SubscribeSubaccountsInput extends BaseSubscribeInput<Subaccount> {\n accountId: string;\n}\n\ninterface SubscribeApiKeysInput extends BaseSubscribeInput<ApiKey> {\n accountId: string;\n}\n\n/**\n * Reads the public role catalog and creates, manages, shares, audits, and subscribes to subaccounts visible to the authenticated caller.\n */\nexport class SubaccountsService {\n readonly policies: SubaccountPoliciesService;\n\n #client: Client<typeof Proto.SubaccountService>;\n #viewClient: Client<typeof Proto.SubaccountViewService>;\n #publicRoleClient: Client<typeof Proto.SubaccountRoleService>;\n #authRoleClient: Client<typeof Proto.SubaccountRoleService>;\n #realtime: PolyesterRealtime;\n\n constructor(\n transports: AuthAndPublicApiTransports,\n realtime: PolyesterRealtime,\n resolver?: SubaccountResolver,\n ) {\n this.policies = new SubaccountPoliciesService(transports, realtime, resolver);\n this.#client = createClient(Proto.SubaccountService, transports.authApi);\n this.#viewClient = createClient(Proto.SubaccountViewService, transports.authApi);\n this.#publicRoleClient = createClient(Proto.SubaccountRoleService, transports.publicApi);\n this.#authRoleClient = createClient(Proto.SubaccountRoleService, transports.authApi);\n this.#realtime = realtime;\n }\n\n /**\n * Returns subaccounts owned by or shared with the caller plus totalCreated, including soft-deleted ones. Use `createChallenge` for the canonical next smart-account address and salt.\n */\n async list(options?: PolyesterRequestOptions): Promise<{\n totalCreated: number;\n subaccounts: v.InferOutput<typeof SubaccountSchema>[];\n }> {\n const res = await this.#client.listSubaccounts({}, toConnectCallOptions(options));\n return {\n totalCreated: res.totalCreated,\n subaccounts: parse(v.array(SubaccountSchema), res.subaccounts),\n };\n }\n\n /**\n * Fetches an aggregated subaccount dashboard view with subaccount details, policy, API keys, balances, members, and outgoing invites; throws if the subaccount is missing.\n */\n async get(\n input: v.InferInput<typeof SubaccountIdInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<\n Subaccount & {\n apiKeys: ApiKey[];\n policy: SubaccountPolicy;\n members: SubaccountMember[];\n invites: SubaccountInvite[];\n }\n > {\n const validatedInput = parse(SubaccountIdInputSchema, input);\n const subaccountId = formatId(validatedInput.subaccountId);\n const res = await this.#viewClient.getSubaccount(\n {\n subaccountId: validatedInput.subaccountId,\n includeApiKeys: true,\n includeBalances: true,\n includeMembers: true,\n includeInvites: true,\n includePolicy: true,\n invitesDirection: Proto.SubaccountInviteDirection.OUTGOING,\n },\n toConnectCallOptions(options),\n );\n if (!res.subaccount) throw new Error(`Subaccount not found: ${subaccountId}`);\n\n return {\n ...parse(SubaccountSchema, res.subaccount),\n policy: res.policy\n ? parse(SubaccountPolicySchema, res.policy)\n : DEFAULT_SUBACCOUNT_POLICY,\n apiKeys: parse(v.optional(v.array(ApiKeySchema), []), res.apiKeys),\n members: parse(v.optional(v.array(SubaccountMemberSchema), []), res.members),\n invites: v\n .parse(v.optional(v.array(SubaccountInviteSchema), []), res.invites)\n .filter((invite) => invite.subaccountId === subaccountId),\n };\n }\n\n /**\n * Requests the canonical next smart account and a short-lived EIP-191 authorization message\n * bound to the authenticated root and the selected owner EOA. Sign the exact message through\n * the returned smart account, then pass it to `create`. A new challenge replaces the previous one.\n */\n async createChallenge(\n input: v.InferInput<typeof CreateSubaccountChallengeInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<SubaccountChallenge> {\n const validatedInput = parse(CreateSubaccountChallengeInputSchema, input);\n const res = await this.#client.createSubaccountChallenge(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(SubaccountChallengeSchema, res);\n }\n\n /**\n * Creates a new subaccount under the caller's root account using the smart-account address, message, and smart-account signature from `createChallenge`.\n */\n async create(\n input: v.InferInput<typeof CreateSubaccountInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<CreateSubaccountResult> {\n const validatedInput = parse(CreateSubaccountInputSchema, input);\n const res = await this.#client.createSubaccount(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(CreateSubaccountResultSchema, res);\n }\n\n /**\n * Updates mutable subaccount display/status fields such as label and active/disabled status.\n */\n async update(\n input: v.InferInput<typeof UpdateSubaccountInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<Subaccount> {\n const validatedInput = parse(UpdateSubaccountInputSchema, input);\n const res = await this.#client.updateSubaccount(\n validatedInput,\n toConnectCallOptions(options),\n );\n if (!res.subaccount) throw new Error(\"Failed to update subaccount\");\n return parse(SubaccountSchema, res.subaccount);\n }\n\n /**\n * Creates or refreshes a pending invitation granting a role on a subaccount to another root account.\n */\n async inviteMember(\n input: v.InferInput<typeof InviteSubaccountMemberInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<SubaccountInvite> {\n const validatedInput = parse(InviteSubaccountMemberInputSchema, input);\n const res = await this.#client.inviteSubaccountMember(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(SubaccountInviteSchema, res.invite);\n }\n\n /**\n * Removes delegated access for a subaccount member by grantee account ID.\n */\n async removeMember(\n input: v.InferInput<typeof RemoveSubaccountMemberInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<SubaccountMutationResult> {\n const validatedInput = parse(RemoveSubaccountMemberInputSchema, input);\n const res = await this.#client.removeSubaccountMember(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(SubaccountMutationResultSchema, res);\n }\n\n /**\n * Changes an existing delegated member's role without sending a new invitation.\n */\n async updateMemberRole(\n input: v.InferInput<typeof UpdateSubaccountMemberRoleInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<SubaccountMutationResult> {\n const validatedInput = parse(UpdateSubaccountMemberRoleInputSchema, input);\n const res = await this.#client.updateSubaccountMemberRole(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(SubaccountMutationResultSchema, res);\n }\n\n /**\n * Enables or disables the owner-controlled MFA requirement for delegated interactive member actions on a subaccount.\n */\n async setMemberMfaRequirement(\n input: v.InferInput<typeof SetSubaccountMemberMfaRequirementInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<SubaccountMutationResult> {\n const validatedInput = parse(SetSubaccountMemberMfaRequirementInputSchema, input);\n const res = await this.#client.setSubaccountMemberMFARequirement(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(SubaccountMutationResultSchema, res);\n }\n\n /**\n * Returns the caller's subaccount invitations, newest first. Omit `direction` to include both\n * incoming and outgoing invitations, or pass `\"incoming\"` or `\"outgoing\"` to filter.\n */\n async listInvites(\n input: v.InferInput<typeof ListSubaccountInvitesInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<SubaccountInvite[]> {\n const validatedInput = parse(ListSubaccountInvitesInputSchema, input);\n const res = await this.#client.listSubaccountInvites(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(v.array(SubaccountInviteSchema), res.invites);\n }\n\n /**\n * Returns the public built-in role and permission catalog with display metadata and per-role permission sets.\n */\n async listRoles(options?: PolyesterRequestOptions): Promise<SubaccountRoleCatalog> {\n const res = await this.#publicRoleClient.listSubaccountRoles(\n {},\n toConnectCallOptions(options),\n );\n return parse(SubaccountRoleCatalogSchema, res);\n }\n\n /**\n * Returns the caller's current role, effective role-granted permissions, and attached policy ID for a subaccount.\n */\n async getEffectivePermissions(\n input: v.InferInput<typeof SubaccountIdInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<EffectiveSubaccountPermissions> {\n const validatedInput = parse(SubaccountIdInputSchema, input);\n const res = await this.#authRoleClient.getEffectiveSubaccountPermissions(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(EffectiveSubaccountPermissionsSchema, res);\n }\n\n /**\n * Returns the owner and delegated members for a subaccount, including role and MFA enrollment status.\n */\n async listMembers(\n input: v.InferInput<typeof SubaccountIdInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<SubaccountMember[]> {\n const validatedInput = parse(SubaccountIdInputSchema, input);\n const res = await this.#client.listSubaccountMembers(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(v.array(SubaccountMemberSchema), res.members);\n }\n\n /**\n * Accepts or rejects an incoming invite, or cancels an outgoing invite, returning the updated invitation.\n */\n async respondInvite(\n input: v.InferInput<typeof RespondSubaccountInviteInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<SubaccountInvite> {\n const validatedInput = parse(RespondSubaccountInviteInputSchema, input);\n const res = await this.#client.respondSubaccountInvite(\n validatedInput,\n toConnectCallOptions(options),\n );\n return parse(SubaccountInviteSchema, res.invite);\n }\n\n /**\n * Returns paginated audit/activity events for a subaccount, newest first, with a non-negative integer limit from 0 through 200 and opaque cursor pagination.\n */\n async listEvents(\n input: v.InferInput<typeof SubaccountActivityInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<{ events: SubaccountEvent[]; nextPageToken: string }> {\n const validatedInput = parse(SubaccountActivityInputSchema, input);\n const res = await this.#viewClient.listSubaccountActivity(\n validatedInput,\n toConnectCallOptions(options),\n );\n return {\n events: parse(v.optional(v.array(SubaccountActivityEventSchema), []), res.events),\n nextPageToken: res.nextPageToken,\n };\n }\n\n /**\n * Subscribes to private subaccount updates for an account and emits normalized subaccount records.\n */\n subscribe(input: SubscribeSubaccountsInput) {\n const channel = `private:auth:subaccounts:${input.accountId}:proto`;\n\n return this.#realtime.connectProtoChannel({\n channel,\n schema: Proto.SubaccountSchema,\n onPublication: (data) => {\n const subaccount = parse(SubaccountSchema, data);\n input.onEvent(subaccount);\n },\n onConnected: () => input.onOpen?.(),\n onDisconnected: () => input.onClose?.(),\n onError: input.onError,\n });\n }\n\n /**\n * Subscribes to private API key updates for an account through the subaccount realtime channel helper.\n */\n subscribeApiKeys(input: SubscribeApiKeysInput) {\n const channel = `private:auth:api-keys:${input.accountId}:proto`;\n\n return this.#realtime.connectProtoChannel({\n channel,\n schema: ProtoApiKeys.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":";;;;;;;;;;;;;;;AAiEA,IAAa,qBAAb,MAAgC;CAC5B;CAEA;CACA;CACA;CACA;CACA;CAEA,YACI,YACA,UACA,UACF;EACE,KAAK,WAAW,IAAI,0BAA0B,YAAY,UAAU,QAAQ;EAC5E,KAAKA,UAAU,aAAaC,mBAAyB,WAAW,OAAO;EACvE,KAAKC,cAAc,aAAaC,uBAA6B,WAAW,OAAO;EAC/E,KAAKC,oBAAoB,aAAaC,uBAA6B,WAAW,SAAS;EACvF,KAAKC,kBAAkB,aAAaD,uBAA6B,WAAW,OAAO;EACnF,KAAKE,YAAY;CACrB;;;;CAKA,MAAM,KAAK,SAGR;EACC,MAAM,MAAM,MAAM,KAAKP,QAAQ,gBAAgB,CAAC,GAAG,qBAAqB,OAAO,CAAC;EAChF,OAAO;GACH,cAAc,IAAI;GAClB,aAAa,MAAM,EAAE,MAAMQ,kBAAgB,GAAG,IAAI,WAAW;EACjE;CACJ;;;;CAKA,MAAM,IACF,OACA,SAQF;EACE,MAAM,iBAAiB,MAAM,yBAAyB,KAAK;EAC3D,MAAM,eAAe,SAAS,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ACrB,MAAM,SAAS,MAAMF,gBAAc,IAAI;IACvC,MAAM,QAAQ,MAAM;GACxB;GACA,mBAAmB,MAAM,SAAS;GAClC,sBAAsB,MAAM,UAAU;GACtC,SAAS,MAAM;EACnB,CAAC;CACL;AACJ"}
|
|
@@ -295,8 +295,8 @@ declare const SubaccountActivityEventSchema: v.ObjectSchema<{
|
|
|
295
295
|
seconds: bigint;
|
|
296
296
|
nanos: number;
|
|
297
297
|
} | undefined, number | undefined>]>;
|
|
298
|
-
readonly entityKind: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "api_key" | "account" | "subaccount" | "destination" | "session" | "
|
|
299
|
-
readonly eventAction: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "enabled" | "disabled" | "
|
|
298
|
+
readonly entityKind: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "api_key" | "account" | "subaccount" | "destination" | "session" | "member" | "policy" | "invite" | "security">]>;
|
|
299
|
+
readonly eventAction: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "enabled" | "disabled" | "revoked" | "failed" | "created" | "updated" | "deleted" | "removed" | "role_set" | "received" | "replied" | "blocked" | "hold_placed" | "hold_released">]>;
|
|
300
300
|
readonly source: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "web" | "mobile" | "api">]>;
|
|
301
301
|
readonly ip: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
302
302
|
readonly userAgent: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
@@ -87,7 +87,7 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
|
|
|
87
87
|
} & {
|
|
88
88
|
readonly orderId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
89
89
|
readonly lineageId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
90
|
-
readonly throughGeneration: v.OptionalSchema<v.
|
|
90
|
+
readonly throughGeneration: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
91
91
|
}, undefined>, v.StrictObjectSchema<{
|
|
92
92
|
readonly symbolId: v.SchemaWithPipe<readonly [v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.TransformAction<string, number>]>, undefined>, v.TransformAction<number | undefined, number | undefined>]>;
|
|
93
93
|
readonly afterMatchId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
@@ -103,7 +103,7 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
|
|
|
103
103
|
} & {
|
|
104
104
|
readonly orderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>, v.CheckAction<bigint, `${string} must be greater than zero`>]>;
|
|
105
105
|
readonly lineageId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
106
|
-
readonly throughGeneration: v.OptionalSchema<v.
|
|
106
|
+
readonly throughGeneration: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
107
107
|
}, undefined>, v.StrictObjectSchema<{
|
|
108
108
|
readonly symbolId: v.SchemaWithPipe<readonly [v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.TransformAction<string, number>]>, undefined>, v.TransformAction<number | undefined, number | undefined>]>;
|
|
109
109
|
readonly afterMatchId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
@@ -135,7 +135,7 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
|
|
|
135
135
|
} & {
|
|
136
136
|
readonly orderId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
137
137
|
readonly lineageId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
138
|
-
readonly throughGeneration: v.OptionalSchema<v.
|
|
138
|
+
readonly throughGeneration: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
139
139
|
}, undefined>, v.StrictObjectSchema<{
|
|
140
140
|
readonly symbolId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.TransformAction<string, number>]>, v.CheckAction<number, "symbolId is required when afterMatchId is set">]>;
|
|
141
141
|
readonly afterMatchId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint | undefined>]>;
|
|
@@ -151,7 +151,7 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
|
|
|
151
151
|
} & {
|
|
152
152
|
readonly orderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>, v.CheckAction<bigint, `${string} must be greater than zero`>]>;
|
|
153
153
|
readonly lineageId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
154
|
-
readonly throughGeneration: v.OptionalSchema<v.
|
|
154
|
+
readonly throughGeneration: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
155
155
|
}, undefined>, v.StrictObjectSchema<{
|
|
156
156
|
readonly symbolId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.TransformAction<string, number>]>, v.CheckAction<number, "symbolId is required when afterMatchId is set">]>;
|
|
157
157
|
readonly afterMatchId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint | undefined>]>;
|
|
@@ -168,7 +168,7 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
|
|
|
168
168
|
readonly orderId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
169
169
|
readonly lineageId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>, v.CheckAction<bigint, `${string} must be greater than zero`>]>;
|
|
170
170
|
readonly throughGeneration: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>, undefined>;
|
|
171
|
-
}, undefined>], undefined>], ({ input }: v.UnionIssue<v.NumberIssue | v.StringIssue | v.PicklistIssue | v.StrictObjectIssue | v.MinLengthIssue<string, 1> | v.UnionIssue<v.StringIssue | v.PicklistIssue | v.StrictObjectIssue | v.MinLengthIssue<string, 1>> | v.IntegerIssue<number> | v.MaxValueIssue<number, 4294967295> | v.CheckIssue<bigint> | v.BooleanIssue | v.NeverIssue | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 1000> | v.UnionIssue<v.NumberIssue | v.StringIssue | v.PicklistIssue | v.StrictObjectIssue | v.MinLengthIssue<string, 1> | v.UnionIssue<v.StringIssue | v.PicklistIssue | v.StrictObjectIssue | v.MinLengthIssue<string, 1>> | v.IntegerIssue<number> | v.MaxValueIssue<number, 4294967295> | v.CheckIssue<bigint> | v.BooleanIssue | v.NeverIssue | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 1000>> | v.CheckIssue<number> | v.UnionIssue<v.NumberIssue | v.StringIssue | v.PicklistIssue | v.StrictObjectIssue | v.MinLengthIssue<string, 1> | v.UnionIssue<v.StringIssue | v.PicklistIssue | v.StrictObjectIssue | v.MinLengthIssue<string, 1>> | v.IntegerIssue<number> | v.MaxValueIssue<number, 4294967295> | v.CheckIssue<bigint> | v.BooleanIssue | v.NeverIssue | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 1000> | v.CheckIssue<number>>>) => "symbolId is required when afterMatchId is set" | "Provide at most one of orderId or lineageId">, v.TransformAction<{
|
|
171
|
+
}, undefined>], undefined>], ({ input }: v.UnionIssue<v.NumberIssue | v.StringIssue | v.PicklistIssue | v.StrictObjectIssue | v.MinLengthIssue<string, 1> | v.UnionIssue<v.StringIssue | v.PicklistIssue | v.StrictObjectIssue | v.MinLengthIssue<string, 1>> | v.IntegerIssue<number> | v.MaxValueIssue<number, 4294967295> | v.CheckIssue<bigint> | v.BooleanIssue | v.NeverIssue | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 1000> | v.UnionIssue<v.NumberIssue | v.StringIssue | v.PicklistIssue | v.StrictObjectIssue | v.MinLengthIssue<string, 1> | v.UnionIssue<v.StringIssue | v.PicklistIssue | v.StrictObjectIssue | v.MinLengthIssue<string, 1>> | v.IntegerIssue<number> | v.MaxValueIssue<number, 4294967295> | v.CheckIssue<bigint> | v.BooleanIssue | v.NeverIssue | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 1000>> | v.CheckIssue<number> | v.UnionIssue<v.NumberIssue | v.StringIssue | v.PicklistIssue | v.StrictObjectIssue | v.MinLengthIssue<string, 1> | v.UnionIssue<v.StringIssue | v.PicklistIssue | v.StrictObjectIssue | v.MinLengthIssue<string, 1>> | v.IntegerIssue<number> | v.MaxValueIssue<number, 4294967295> | v.CheckIssue<bigint> | v.BooleanIssue | v.NeverIssue | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 1000> | v.CheckIssue<number>>>) => "symbolId is required when afterMatchId is set" | "Provide at most one of orderId or lineageId" | "throughGeneration requires lineageId">, v.TransformAction<{
|
|
172
172
|
symbolId?: number | undefined;
|
|
173
173
|
afterMatchId?: undefined;
|
|
174
174
|
side?: Side.BUY | Side.SELL | undefined;
|
|
@@ -182,7 +182,7 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
|
|
|
182
182
|
} | undefined;
|
|
183
183
|
orderId?: undefined;
|
|
184
184
|
lineageId?: undefined;
|
|
185
|
-
throughGeneration?:
|
|
185
|
+
throughGeneration?: undefined;
|
|
186
186
|
} | {
|
|
187
187
|
symbolId?: number | undefined;
|
|
188
188
|
afterMatchId?: undefined;
|
|
@@ -197,7 +197,7 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
|
|
|
197
197
|
} | undefined;
|
|
198
198
|
orderId: bigint;
|
|
199
199
|
lineageId?: undefined;
|
|
200
|
-
throughGeneration?:
|
|
200
|
+
throughGeneration?: undefined;
|
|
201
201
|
} | {
|
|
202
202
|
symbolId?: number | undefined;
|
|
203
203
|
afterMatchId?: undefined;
|
|
@@ -227,7 +227,7 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
|
|
|
227
227
|
} | undefined;
|
|
228
228
|
orderId?: undefined;
|
|
229
229
|
lineageId?: undefined;
|
|
230
|
-
throughGeneration?:
|
|
230
|
+
throughGeneration?: undefined;
|
|
231
231
|
} | {
|
|
232
232
|
symbolId: number;
|
|
233
233
|
afterMatchId: bigint | undefined;
|
|
@@ -242,7 +242,7 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
|
|
|
242
242
|
} | undefined;
|
|
243
243
|
orderId: bigint;
|
|
244
244
|
lineageId?: undefined;
|
|
245
|
-
throughGeneration?:
|
|
245
|
+
throughGeneration?: undefined;
|
|
246
246
|
} | {
|
|
247
247
|
symbolId: number;
|
|
248
248
|
afterMatchId: bigint | undefined;
|
|
@@ -275,7 +275,7 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
|
|
|
275
275
|
limit?: number | undefined;
|
|
276
276
|
pageToken?: string | undefined;
|
|
277
277
|
includeTransfers?: boolean | undefined;
|
|
278
|
-
throughGeneration?:
|
|
278
|
+
throughGeneration?: undefined;
|
|
279
279
|
} | {
|
|
280
280
|
executionScope: {
|
|
281
281
|
readonly case: "orderId";
|
|
@@ -293,7 +293,7 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
|
|
|
293
293
|
limit?: number | undefined;
|
|
294
294
|
pageToken?: string | undefined;
|
|
295
295
|
includeTransfers?: boolean | undefined;
|
|
296
|
-
throughGeneration?:
|
|
296
|
+
throughGeneration?: undefined;
|
|
297
297
|
} | {
|
|
298
298
|
executionScope: {
|
|
299
299
|
readonly case: "orderId";
|
|
@@ -329,7 +329,7 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
|
|
|
329
329
|
limit?: number | undefined;
|
|
330
330
|
pageToken?: string | undefined;
|
|
331
331
|
includeTransfers?: boolean | undefined;
|
|
332
|
-
throughGeneration?:
|
|
332
|
+
throughGeneration?: undefined;
|
|
333
333
|
} | {
|
|
334
334
|
executionScope: {
|
|
335
335
|
readonly case: "orderId";
|
|
@@ -347,7 +347,7 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
|
|
|
347
347
|
limit?: number | undefined;
|
|
348
348
|
pageToken?: string | undefined;
|
|
349
349
|
includeTransfers?: boolean | undefined;
|
|
350
|
-
throughGeneration?:
|
|
350
|
+
throughGeneration?: undefined;
|
|
351
351
|
} | {
|
|
352
352
|
executionScope: {
|
|
353
353
|
readonly case: "orderId";
|
|
@@ -369,7 +369,8 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
|
|
|
369
369
|
}>]>;
|
|
370
370
|
/**
|
|
371
371
|
* Filters accepted by {@link TradesService.list}. Passing `afterMatchId` requires
|
|
372
|
-
* `symbolId`; the
|
|
372
|
+
* `symbolId`, and `throughGeneration` requires `lineageId`; the shapes form a discriminated
|
|
373
|
+
* union so both constraints are compile errors.
|
|
373
374
|
*/
|
|
374
375
|
type GetUserTradesInput = v.InferInput<typeof GetUserTradesInputSchema>;
|
|
375
376
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trades.schemas.d.ts","names":[],"sources":["../../../src/services/trades/trades.schemas.ts"],"mappings":";;;;;iBAoBgB,sBAAsB,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgD3C,QAAQ,EAAE,YAAY,kBAAkB;;
|
|
1
|
+
{"version":3,"file":"trades.schemas.d.ts","names":[],"sources":["../../../src/services/trades/trades.schemas.ts"],"mappings":";;;;;iBAoBgB,sBAAsB,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgD3C,QAAQ,EAAE,YAAY,kBAAkB;;cAoFvC,0BAAwB,EAAA,yBAAA,EAAA,aAAA,EAAA,sBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA+BzB,qBAAqB,EAAE,kBAAkB"}
|
|
@@ -53,6 +53,7 @@ function createUserTradeSchema(scales) {
|
|
|
53
53
|
}
|
|
54
54
|
const AFTER_MATCH_REQUIRES_SYMBOL = "symbolId is required when afterMatchId is set";
|
|
55
55
|
const EXECUTION_SCOPE_CONFLICT = "Provide at most one of orderId or lineageId";
|
|
56
|
+
const THROUGH_GENERATION_REQUIRES_LINEAGE = "throughGeneration requires lineageId";
|
|
56
57
|
const SymbolIdStringSchema = v.pipe(v.string(), v.trim(), v.transform((value) => Number(value)));
|
|
57
58
|
const GetUserTradesCommonEntries = {
|
|
58
59
|
...AccountScopeInputEntries,
|
|
@@ -70,13 +71,13 @@ function userTradesScopeSchemas(entries) {
|
|
|
70
71
|
...entries,
|
|
71
72
|
orderId: v.optional(v.never()),
|
|
72
73
|
lineageId: v.optional(v.never()),
|
|
73
|
-
throughGeneration:
|
|
74
|
+
throughGeneration: v.optional(v.never())
|
|
74
75
|
}),
|
|
75
76
|
v.strictObject({
|
|
76
77
|
...entries,
|
|
77
78
|
orderId: positiveOrderIdInputSchema("orderId"),
|
|
78
79
|
lineageId: v.optional(v.never()),
|
|
79
|
-
throughGeneration:
|
|
80
|
+
throughGeneration: v.optional(v.never())
|
|
80
81
|
}),
|
|
81
82
|
v.strictObject({
|
|
82
83
|
...entries,
|
|
@@ -99,7 +100,13 @@ const ReplayUserTradesInputSchema = v.union(userTradesScopeSchemas({
|
|
|
99
100
|
afterMatchId: v.pipe(v.string(), v.trim(), v.minLength(1), v.transform((value) => parseOptionalUint64DecimalStrict(value, "afterMatchId")))
|
|
100
101
|
}));
|
|
101
102
|
/** Validates filters accepted by {@link TradesService.list}. */
|
|
102
|
-
const GetUserTradesInputSchema = v.pipe(v.union([BrowseUserTradesInputSchema, ReplayUserTradesInputSchema], ({ input }) =>
|
|
103
|
+
const GetUserTradesInputSchema = v.pipe(v.union([BrowseUserTradesInputSchema, ReplayUserTradesInputSchema], ({ input }) => {
|
|
104
|
+
const filters = typeof input === "object" && input !== null ? input : {};
|
|
105
|
+
const has = (key) => key in filters && filters[key] !== void 0;
|
|
106
|
+
if (has("orderId") && has("lineageId")) return EXECUTION_SCOPE_CONFLICT;
|
|
107
|
+
if (has("throughGeneration") && !has("lineageId")) return THROUGH_GENERATION_REQUIRES_LINEAGE;
|
|
108
|
+
return AFTER_MATCH_REQUIRES_SYMBOL;
|
|
109
|
+
}), v.transform(({ account, orderId, lineageId, ...input }) => {
|
|
103
110
|
const executionScope = orderId !== void 0 ? {
|
|
104
111
|
case: "orderId",
|
|
105
112
|
value: orderId
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trades.schemas.js","names":[],"sources":["../../../src/services/trades/trades.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { tsNsToISO, tsNsToMs } from \"../../utils/time.js\";\nimport { SideSchema } from \"../shared.js\";\nimport { FeeAssetCodec, OrderSideCodec } from \"../orders/orders.codecs.js\";\nimport { formatId } from \"../../utils/base58-id.js\";\nimport { optionalUint64DecimalFilterSchema, U128Schema } from \"../../shared/schemas.js\";\nimport { parseOptionalUint64DecimalStrict } from \"../../utils/numbers.js\";\nimport { PROTOBUF_UINT32_MAX } from \"../../shared/wire-bounds.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { TradeSideCodec } from \"./trades.codecs.js\";\nimport { enumLabel } from \"../../shared/proto-enum-codec.js\";\nimport { E18_SCALE, scaledToDecimalOutput, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { fromU128 } from \"../../utils/u128.js\";\nimport { OrderLineageSchema } from \"../orders/order-lineage.schemas.js\";\nimport { positiveOrderIdInputSchema } from \"../orders/orders-identifiers.schemas.js\";\n\n/** Parses a generated user-trade fill into the SDK's JSON-safe public shape. */\nexport function createUserTradeSchema(scales: SdkScales) {\n return v.pipe(\n v.object({\n orderId: v.bigint(),\n symbolId: v.number(),\n side: v.number(),\n isMaker: v.boolean(),\n feeAsset: v.number(),\n qtyScaled: v.bigint(),\n priceTicks: v.bigint(),\n feeAmountE18: v.optional(U128Schema),\n referralShareAmountE18: v.optional(U128Schema),\n feeIsRebate: v.boolean(),\n tsNs: v.bigint(),\n matchId: v.bigint(),\n lineage: v.optional(OrderLineageSchema),\n }),\n v.transform((t) => {\n const feeAsset = enumLabel(FeeAssetCodec.protoToOutput, t.feeAsset);\n return {\n orderId: formatId(t.orderId),\n symbolId: t.symbolId,\n sideLabel: enumLabel(OrderSideCodec.protoToOutput, t.side),\n liquidityLabel: t.isMaker ? (\"maker\" as const) : (\"taker\" as const),\n feeAsset,\n qty: scaledToDecimalOutput(t.qtyScaled, scales.baseQty(t.symbolId)),\n price: scaledToDecimalOutput(t.priceTicks, scales.price()),\n fee: scaledToDecimalOutput(fromU128(t.feeAmountE18), E18_SCALE),\n ...(t.referralShareAmountE18 === undefined\n ? {}\n : {\n referralShare: scaledToDecimalOutput(\n fromU128(t.referralShareAmountE18),\n E18_SCALE,\n ),\n }),\n feeIsRebate: t.feeIsRebate,\n tsNs: t.tsNs.toString(),\n tsIso: tsNsToISO(t.tsNs),\n tsMs: tsNsToMs(t.tsNs),\n matchId: t.matchId.toString(),\n ...(t.lineage === undefined ? {} : { lineage: t.lineage }),\n };\n }),\n );\n}\n\n/** A JSON-safe authenticated trade fill returned by the SDK. */\nexport type Trade = v.InferOutput<ReturnType<typeof createUserTradeSchema>>;\n\nconst AFTER_MATCH_REQUIRES_SYMBOL = \"symbolId is required when afterMatchId is set\";\nconst EXECUTION_SCOPE_CONFLICT = \"Provide at most one of orderId or lineageId\";\n\nconst SymbolIdStringSchema = v.pipe(\n v.string(),\n v.trim(),\n v.transform((value) => Number(value)),\n);\n\nconst GetUserTradesCommonEntries = {\n ...AccountScopeInputEntries,\n side: v.pipe(\n v.optional(SideSchema),\n v.transform((v) => (v ? TradeSideCodec.inputToProto[v] : undefined)),\n ),\n startTsNs: optionalUint64DecimalFilterSchema(\"startTsNs\"),\n endTsNs: optionalUint64DecimalFilterSchema(\"endTsNs\"),\n limit: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1000))),\n pageToken: v.optional(v.pipe(v.string(), v.trim())),\n includeTransfers: v.optional(v.boolean()),\n};\n\nconst ThroughGenerationSchema = v.optional(\n v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(PROTOBUF_UINT32_MAX)),\n);\n\nfunction userTradesScopeSchemas<const TEntries extends v.ObjectEntries>(entries: TEntries) {\n return [\n v.strictObject({\n ...entries,\n orderId: v.optional(v.never()),\n lineageId: v.optional(v.never()),\n throughGeneration: ThroughGenerationSchema,\n }),\n v.strictObject({\n ...entries,\n orderId: positiveOrderIdInputSchema(\"orderId\"),\n lineageId: v.optional(v.never()),\n throughGeneration: ThroughGenerationSchema,\n }),\n v.strictObject({\n ...entries,\n orderId: v.optional(v.never()),\n lineageId: positiveOrderIdInputSchema(\"lineageId\"),\n throughGeneration: ThroughGenerationSchema,\n }),\n ] as const;\n}\n\n/** Browse mode: optional symbol filter, no replay cursor. */\nconst BrowseUserTradesInputSchema = v.union(\n userTradesScopeSchemas({\n ...GetUserTradesCommonEntries,\n symbolId: v.pipe(\n v.optional(SymbolIdStringSchema),\n v.transform((sid) =>\n sid !== undefined && Number.isFinite(sid) && sid > 0 ? sid : undefined,\n ),\n ),\n afterMatchId: v.optional(v.never()),\n }),\n);\n\n/** Replay mode: `afterMatchId` cursor, which the backend only accepts scoped to a symbol. */\nconst ReplayUserTradesInputSchema = v.union(\n userTradesScopeSchemas({\n ...GetUserTradesCommonEntries,\n symbolId: v.pipe(\n SymbolIdStringSchema,\n v.check((sid) => Number.isInteger(sid) && sid > 0, AFTER_MATCH_REQUIRES_SYMBOL),\n ),\n afterMatchId: v.pipe(\n v.string(),\n v.trim(),\n v.minLength(1),\n v.transform((value) => parseOptionalUint64DecimalStrict(value, \"afterMatchId\")),\n ),\n }),\n);\n\n/** Validates filters accepted by {@link TradesService.list}. */\nexport const GetUserTradesInputSchema = v.pipe(\n v.union([BrowseUserTradesInputSchema, ReplayUserTradesInputSchema], ({ input }) =>\n typeof input === \"object\" &&\n input !== null &&\n \"orderId\" in input &&\n input.orderId !== undefined &&\n \"lineageId\" in input &&\n input.lineageId !== undefined\n ? EXECUTION_SCOPE_CONFLICT\n : AFTER_MATCH_REQUIRES_SYMBOL,\n ),\n v.transform(({ account, orderId, lineageId, ...input }) => {\n const executionScope =\n orderId !== undefined\n ? ({ case: \"orderId\" as const, value: orderId } as const)\n : lineageId !== undefined\n ? ({ case: \"lineageId\" as const, value: lineageId } as const)\n : undefined;\n return {\n ...input,\n executionScope,\n subaccountId: accountScopeToSubaccountId(account),\n };\n }),\n);\n\n/**\n * Filters accepted by {@link TradesService.list}. Passing `afterMatchId` requires\n * `symbolId`; the two shapes form a discriminated union so the constraint is a compile error.\n */\nexport type GetUserTradesInput = v.InferInput<typeof GetUserTradesInputSchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,SAAgB,sBAAsB,QAAmB;CACrD,OAAO,EAAE,KACL,EAAE,OAAO;EACL,SAAS,EAAE,OAAO;EAClB,UAAU,EAAE,OAAO;EACnB,MAAM,EAAE,OAAO;EACf,SAAS,EAAE,QAAQ;EACnB,UAAU,EAAE,OAAO;EACnB,WAAW,EAAE,OAAO;EACpB,YAAY,EAAE,OAAO;EACrB,cAAc,EAAE,SAAS,UAAU;EACnC,wBAAwB,EAAE,SAAS,UAAU;EAC7C,aAAa,EAAE,QAAQ;EACvB,MAAM,EAAE,OAAO;EACf,SAAS,EAAE,OAAO;EAClB,SAAS,EAAE,SAAS,kBAAkB;CAC1C,CAAC,GACD,EAAE,WAAW,MAAM;EACf,MAAM,WAAW,UAAU,cAAc,eAAe,EAAE,QAAQ;EAClE,OAAO;GACH,SAAS,SAAS,EAAE,OAAO;GAC3B,UAAU,EAAE;GACZ,WAAW,UAAU,eAAe,eAAe,EAAE,IAAI;GACzD,gBAAgB,EAAE,UAAW,UAAqB;GAClD;GACA,KAAK,sBAAsB,EAAE,WAAW,OAAO,QAAQ,EAAE,QAAQ,CAAC;GAClE,OAAO,sBAAsB,EAAE,YAAY,OAAO,MAAM,CAAC;GACzD,KAAK,sBAAsB,SAAS,EAAE,YAAY,GAAA,EAAY;GAC9D,GAAI,EAAE,2BAA2B,KAAA,IAC3B,CAAC,IACD,EACI,eAAe,sBACX,SAAS,EAAE,sBAAsB,GAAA,EAErC,EACJ;GACN,aAAa,EAAE;GACf,MAAM,EAAE,KAAK,SAAS;GACtB,OAAO,UAAU,EAAE,IAAI;GACvB,MAAM,SAAS,EAAE,IAAI;GACrB,SAAS,EAAE,QAAQ,SAAS;GAC5B,GAA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AW;GACjD,mBAAmB;EACvB,CAAC;CACL;AACJ;;AAGA,MAAM,8BAA8B,EAAE,MAClC,uBAAuB;CACnB,GAAG;CACH,UAAU,EAAE,KACR,EAAE,SAAS,oBAAoB,GAC/B,EAAE,WAAW,QACT,QAAQ,KAAA,KAAa,OAAO,SAAS,GAAG,KAAK,MAAM,IAAI,MAAM,KAAA,CACjE,CACJ;CACA,cAAc,EAAE,SAAS,EAAE,MAAM,CAAC;AACtC,CAAC,CACL;;AAGA,MAAM,8BAA8B,EAAE,MAClC,uBAAuB;CACnB,GAAG;CACH,UAAU,EAAE,KACR,sBACA,EAAE,OAAO,QAAQ,OAAO,UAAU,GAAG,KAAK,MAAM,GAAG,2BAA2B,CAClF;CACA,cAAc,EAAE,KACZ,EAAE,OAAO,GACT,EAAE,KAAK,GACP,EAAE,UAAU,CAAC,GACb,EAAE,WAAW,UAAU,iCAAiC,OAAO,cAAc,CAAC,CAClF;AACJ,CAAC,CACL;;AAGA,MAAa,2BAA2B,EAAE,KACtC,EAAE,MAAM,CAAC,6BAA6B,2BAA2B,IAAI,EAAE,YACnE,OAAO,UAAU,YACjB,UAAU,QACV,aAAa,SACb,MAAM,YAAY,KAAA,KAClB,eAAe,SACf,MAAM,cAAc,KAAA,IACd,2BACA,2BACV,GACA,EAAE,WAAW,EAAE,SAAS,SAAS,WAAW,GAAG,YAAY;CACvD,MAAM,iBACF,YAAY,KAAA,IACL;EAAE,MAAM;EAAoB,OAAO;CAAQ,IAC5C,cAAc,KAAA,IACX;EAAE,MAAM;EAAsB,OAAO;CAAU,IAChD,KAAA;CACZ,OAAO;EACH,GAAG;EACH;EACA,cAAc,2BAA2B,OAAO;CACpD;AACJ,CAAC,CACL"}
|
|
1
|
+
{"version":3,"file":"trades.schemas.js","names":[],"sources":["../../../src/services/trades/trades.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { tsNsToISO, tsNsToMs } from \"../../utils/time.js\";\nimport { SideSchema } from \"../shared.js\";\nimport { FeeAssetCodec, OrderSideCodec } from \"../orders/orders.codecs.js\";\nimport { formatId } from \"../../utils/base58-id.js\";\nimport { optionalUint64DecimalFilterSchema, U128Schema } from \"../../shared/schemas.js\";\nimport { parseOptionalUint64DecimalStrict } from \"../../utils/numbers.js\";\nimport { PROTOBUF_UINT32_MAX } from \"../../shared/wire-bounds.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { TradeSideCodec } from \"./trades.codecs.js\";\nimport { enumLabel } from \"../../shared/proto-enum-codec.js\";\nimport { E18_SCALE, scaledToDecimalOutput, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { fromU128 } from \"../../utils/u128.js\";\nimport { OrderLineageSchema } from \"../orders/order-lineage.schemas.js\";\nimport { positiveOrderIdInputSchema } from \"../orders/orders-identifiers.schemas.js\";\n\n/** Parses a generated user-trade fill into the SDK's JSON-safe public shape. */\nexport function createUserTradeSchema(scales: SdkScales) {\n return v.pipe(\n v.object({\n orderId: v.bigint(),\n symbolId: v.number(),\n side: v.number(),\n isMaker: v.boolean(),\n feeAsset: v.number(),\n qtyScaled: v.bigint(),\n priceTicks: v.bigint(),\n feeAmountE18: v.optional(U128Schema),\n referralShareAmountE18: v.optional(U128Schema),\n feeIsRebate: v.boolean(),\n tsNs: v.bigint(),\n matchId: v.bigint(),\n lineage: v.optional(OrderLineageSchema),\n }),\n v.transform((t) => {\n const feeAsset = enumLabel(FeeAssetCodec.protoToOutput, t.feeAsset);\n return {\n orderId: formatId(t.orderId),\n symbolId: t.symbolId,\n sideLabel: enumLabel(OrderSideCodec.protoToOutput, t.side),\n liquidityLabel: t.isMaker ? (\"maker\" as const) : (\"taker\" as const),\n feeAsset,\n qty: scaledToDecimalOutput(t.qtyScaled, scales.baseQty(t.symbolId)),\n price: scaledToDecimalOutput(t.priceTicks, scales.price()),\n fee: scaledToDecimalOutput(fromU128(t.feeAmountE18), E18_SCALE),\n ...(t.referralShareAmountE18 === undefined\n ? {}\n : {\n referralShare: scaledToDecimalOutput(\n fromU128(t.referralShareAmountE18),\n E18_SCALE,\n ),\n }),\n feeIsRebate: t.feeIsRebate,\n tsNs: t.tsNs.toString(),\n tsIso: tsNsToISO(t.tsNs),\n tsMs: tsNsToMs(t.tsNs),\n matchId: t.matchId.toString(),\n ...(t.lineage === undefined ? {} : { lineage: t.lineage }),\n };\n }),\n );\n}\n\n/** A JSON-safe authenticated trade fill returned by the SDK. */\nexport type Trade = v.InferOutput<ReturnType<typeof createUserTradeSchema>>;\n\nconst AFTER_MATCH_REQUIRES_SYMBOL = \"symbolId is required when afterMatchId is set\";\nconst EXECUTION_SCOPE_CONFLICT = \"Provide at most one of orderId or lineageId\";\nconst THROUGH_GENERATION_REQUIRES_LINEAGE = \"throughGeneration requires lineageId\";\n\nconst SymbolIdStringSchema = v.pipe(\n v.string(),\n v.trim(),\n v.transform((value) => Number(value)),\n);\n\nconst GetUserTradesCommonEntries = {\n ...AccountScopeInputEntries,\n side: v.pipe(\n v.optional(SideSchema),\n v.transform((v) => (v ? TradeSideCodec.inputToProto[v] : undefined)),\n ),\n startTsNs: optionalUint64DecimalFilterSchema(\"startTsNs\"),\n endTsNs: optionalUint64DecimalFilterSchema(\"endTsNs\"),\n limit: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1000))),\n pageToken: v.optional(v.pipe(v.string(), v.trim())),\n includeTransfers: v.optional(v.boolean()),\n};\n\nconst ThroughGenerationSchema = v.optional(\n v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(PROTOBUF_UINT32_MAX)),\n);\n\nfunction userTradesScopeSchemas<const TEntries extends v.ObjectEntries>(entries: TEntries) {\n return [\n v.strictObject({\n ...entries,\n orderId: v.optional(v.never()),\n lineageId: v.optional(v.never()),\n throughGeneration: v.optional(v.never()),\n }),\n v.strictObject({\n ...entries,\n orderId: positiveOrderIdInputSchema(\"orderId\"),\n lineageId: v.optional(v.never()),\n throughGeneration: v.optional(v.never()),\n }),\n v.strictObject({\n ...entries,\n orderId: v.optional(v.never()),\n lineageId: positiveOrderIdInputSchema(\"lineageId\"),\n throughGeneration: ThroughGenerationSchema,\n }),\n ] as const;\n}\n\n/** Browse mode: optional symbol filter, no replay cursor. */\nconst BrowseUserTradesInputSchema = v.union(\n userTradesScopeSchemas({\n ...GetUserTradesCommonEntries,\n symbolId: v.pipe(\n v.optional(SymbolIdStringSchema),\n v.transform((sid) =>\n sid !== undefined && Number.isFinite(sid) && sid > 0 ? sid : undefined,\n ),\n ),\n afterMatchId: v.optional(v.never()),\n }),\n);\n\n/** Replay mode: `afterMatchId` cursor, which the backend only accepts scoped to a symbol. */\nconst ReplayUserTradesInputSchema = v.union(\n userTradesScopeSchemas({\n ...GetUserTradesCommonEntries,\n symbolId: v.pipe(\n SymbolIdStringSchema,\n v.check((sid) => Number.isInteger(sid) && sid > 0, AFTER_MATCH_REQUIRES_SYMBOL),\n ),\n afterMatchId: v.pipe(\n v.string(),\n v.trim(),\n v.minLength(1),\n v.transform((value) => parseOptionalUint64DecimalStrict(value, \"afterMatchId\")),\n ),\n }),\n);\n\n/** Validates filters accepted by {@link TradesService.list}. */\nexport const GetUserTradesInputSchema = v.pipe(\n v.union([BrowseUserTradesInputSchema, ReplayUserTradesInputSchema], ({ input }) => {\n const filters = typeof input === \"object\" && input !== null ? input : {};\n const has = (key: string) =>\n key in filters && (filters as Record<string, unknown>)[key] !== undefined;\n if (has(\"orderId\") && has(\"lineageId\")) return EXECUTION_SCOPE_CONFLICT;\n if (has(\"throughGeneration\") && !has(\"lineageId\")) {\n return THROUGH_GENERATION_REQUIRES_LINEAGE;\n }\n return AFTER_MATCH_REQUIRES_SYMBOL;\n }),\n v.transform(({ account, orderId, lineageId, ...input }) => {\n const executionScope =\n orderId !== undefined\n ? ({ case: \"orderId\" as const, value: orderId } as const)\n : lineageId !== undefined\n ? ({ case: \"lineageId\" as const, value: lineageId } as const)\n : undefined;\n return {\n ...input,\n executionScope,\n subaccountId: accountScopeToSubaccountId(account),\n };\n }),\n);\n\n/**\n * Filters accepted by {@link TradesService.list}. Passing `afterMatchId` requires\n * `symbolId`, and `throughGeneration` requires `lineageId`; the shapes form a discriminated\n * union so both constraints are compile errors.\n */\nexport type GetUserTradesInput = v.InferInput<typeof GetUserTradesInputSchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,SAAgB,sBAAsB,QAAmB;CACrD,OAAO,EAAE,KACL,EAAE,OAAO;EACL,SAAS,EAAE,OAAO;EAClB,UAAU,EAAE,OAAO;EACnB,MAAM,EAAE,OAAO;EACf,SAAS,EAAE,QAAQ;EACnB,UAAU,EAAE,OAAO;EACnB,WAAW,EAAE,OAAO;EACpB,YAAY,EAAE,OAAO;EACrB,cAAc,EAAE,SAAS,UAAU;EACnC,wBAAwB,EAAE,SAAS,UAAU;EAC7C,aAAa,EAAE,QAAQ;EACvB,MAAM,EAAE,OAAO;EACf,SAAS,EAAE,OAAO;EAClB,SAAS,EAAE,SAAS,kBAAkB;CAC1C,CAAC,GACD,EAAE,WAAW,MAAM;EACf,MAAM,WAAW,UAAU,cAAc,eAAe,EAAE,QAAQ;EAClE,OAAO;GACH,SAAS,SAAS,EAAE,OAAO;GAC3B,UAAU,EAAE;GACZ,WAAW,UAAU,eAAe,eAAe,EAAE,IAAI;GACzD,gBAAgB,EAAE,UAAW,UAAqB;GAClD;GACA,KAAK,sBAAsB,EAAE,WAAW,OAAO,QAAQ,EAAE,QAAQ,CAAC;GAClE,OAAO,sBAAsB,EAAE,YAAY,OAAO,MAAM,CAAC;GACzD,KAAK,sBAAsB,SAAS,EAAE,YAAY,GAAA,EAAY;GAC9D,GAAI,EAAE,2BAA2B,KAAA,IAC3B,CAAC,IACD,EACI,eAAe,sBACX,SAAS,EAAE,sBAAsB,GAAA,EAErC,EACJ;GACN,aAAa,EAAE;GACf,MAAM,EAAE,KAAK,SAAS;GACtB,OAAO,UAAU,EAAE,IAAI;GACvB,MAAM,SAAS,EAAE,IAAI;GACrB,SAAS,EAAE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KAAA;CACZ,OAAO;EACH,GAAG;EACH;EACA,cAAc,2BAA2B,OAAO;CACpD;AACJ,CAAC,CACL"}
|
|
@@ -555,7 +555,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
|
|
|
555
555
|
};
|
|
556
556
|
}, {
|
|
557
557
|
runtimeDetails: TriggerDetailsOutput;
|
|
558
|
-
cancelReason: "unspecified" | "
|
|
558
|
+
cancelReason: "unspecified" | "internal_error" | "oco" | "user_request" | "parent_canceled_no_fill" | "missing_reason_code";
|
|
559
559
|
failureReason: undefined;
|
|
560
560
|
triggerId: string;
|
|
561
561
|
subaccountId: string;
|
|
@@ -712,7 +712,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
|
|
|
712
712
|
} | {
|
|
713
713
|
runtimeDetails: TriggerDetailsOutput;
|
|
714
714
|
cancelReason: undefined;
|
|
715
|
-
failureReason: "unspecified" | "
|
|
715
|
+
failureReason: "unspecified" | "internal_error" | "missing_reason_code" | "unknown_symbol" | "pair_disabled" | "min_notional" | "tick_size" | "insufficient_funds" | "risk_limit" | "duplicate_client_id" | "market_halted" | "engine_busy" | "account_unknown" | "order_unknown" | "post_only_cross" | "reduce_only_blocked" | "price_band_violation" | "market_cap_violation" | "empty_book" | "fok_insufficient_liquidity" | "fee_asset_not_allowed" | "market_price_unavailable" | "stale_quote" | "min_quantity" | "step_size" | "invalid_sizing" | "max_quote_debit_too_small" | "fee_ceiling_exceeded" | "trigger_price_invalid" | "trigger_price_source_unsupported" | "trailing_distance_invalid" | "modification_requires_replace" | "order_already_terminal" | "conflict_idempotency_key_reuse" | "rate_limited" | "policy_spot_trade_deny" | "policy_market_deny" | "policy_max_notional" | "policy_max_open_orders" | "policy_trading_halted" | "max_slippage_invalid";
|
|
716
716
|
triggerId: string;
|
|
717
717
|
subaccountId: string;
|
|
718
718
|
symbolId: number;
|
|
@@ -1065,7 +1065,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
|
|
|
1065
1065
|
value?: undefined;
|
|
1066
1066
|
};
|
|
1067
1067
|
}, {
|
|
1068
|
-
cancelReason: "unspecified" | "
|
|
1068
|
+
cancelReason: "unspecified" | "internal_error" | "oco" | "user_request" | "parent_canceled_no_fill" | "missing_reason_code";
|
|
1069
1069
|
failureReason: undefined;
|
|
1070
1070
|
triggerId: string;
|
|
1071
1071
|
subaccountId: string;
|
|
@@ -1078,7 +1078,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
|
|
|
1078
1078
|
firePrice: string | undefined;
|
|
1079
1079
|
} | {
|
|
1080
1080
|
cancelReason: undefined;
|
|
1081
|
-
failureReason: "unspecified" | "
|
|
1081
|
+
failureReason: "unspecified" | "internal_error" | "missing_reason_code" | "unknown_symbol" | "pair_disabled" | "min_notional" | "tick_size" | "insufficient_funds" | "risk_limit" | "duplicate_client_id" | "market_halted" | "engine_busy" | "account_unknown" | "order_unknown" | "post_only_cross" | "reduce_only_blocked" | "price_band_violation" | "market_cap_violation" | "empty_book" | "fok_insufficient_liquidity" | "fee_asset_not_allowed" | "market_price_unavailable" | "stale_quote" | "min_quantity" | "step_size" | "invalid_sizing" | "max_quote_debit_too_small" | "fee_ceiling_exceeded" | "trigger_price_invalid" | "trigger_price_source_unsupported" | "trailing_distance_invalid" | "modification_requires_replace" | "order_already_terminal" | "conflict_idempotency_key_reuse" | "rate_limited" | "policy_spot_trade_deny" | "policy_market_deny" | "policy_max_notional" | "policy_max_open_orders" | "policy_trading_halted" | "max_slippage_invalid";
|
|
1082
1082
|
triggerId: string;
|
|
1083
1083
|
subaccountId: string;
|
|
1084
1084
|
symbolId: number;
|
|
@@ -127,6 +127,7 @@ const TriggerFailureReasonCodec = { protoToOutput: {
|
|
|
127
127
|
[49]: "policy_max_notional",
|
|
128
128
|
[50]: "policy_max_open_orders",
|
|
129
129
|
[51]: "policy_trading_halted",
|
|
130
|
+
[53]: "max_slippage_invalid",
|
|
130
131
|
[998]: "missing_reason_code",
|
|
131
132
|
[999]: "internal_error"
|
|
132
133
|
} };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"triggers.codecs.js","names":[],"sources":["../../../src/services/triggers/triggers.codecs.ts"],"sourcesContent":["import * as Proto from \"../../gen/triggers/v1/triggers_pb.js\";\nimport * as ProtoOrders from \"../../gen/orders/v1/orders_pb.js\";\nimport type { InputToProto, ProtoToOutput } from \"../../utils/types.js\";\nexport {\n FEE_ASSET_VALUES,\n FeeAssetCodec,\n type FeeAssetValue,\n ORDER_SIDE_VALUES as TRIGGER_SIDE_VALUES,\n ORDER_TYPE_VALUES,\n OrderSideCodec as TriggerSideCodec,\n type OrderSideValue as TriggerSideValue,\n OrderTypeCodec,\n type OrderTypeValue,\n SELF_TRADE_PREVENTION_MODE_VALUES,\n SelfTradePreventionModeCodec,\n type SelfTradePreventionModeValue,\n TIME_IN_FORCE_OUTPUT_VALUES,\n TIME_IN_FORCE_VALUES,\n TimeInForceCodec,\n type TimeInForceOutputValue,\n type TimeInForceValue,\n TRIGGER_PRICE_SOURCE_VALUES,\n TriggerPriceSourceCodec,\n type TriggerPriceSourceValue,\n} from \"../orders/order-enums.codecs.js\";\n\nexport const TRIGGER_TYPE_VALUES = [\n \"stop_loss\",\n \"take_profit\",\n \"trailing_stop\",\n \"twap\",\n \"ladder\",\n] as const;\nexport type TriggerTypeValue = (typeof TRIGGER_TYPE_VALUES)[number];\n\nexport const TRIGGER_TYPE_LABEL_VALUES = TRIGGER_TYPE_VALUES;\nexport type TriggerTypeLabelValue = (typeof TRIGGER_TYPE_LABEL_VALUES)[number];\n\nexport const TRIGGER_STATUS_FILTER_VALUES = [\n \"created\",\n \"armed\",\n \"running\",\n \"completed\",\n \"cancelled\",\n \"failed\",\n \"paused\",\n] as const;\nexport type TriggerStatusFilterValue = (typeof TRIGGER_STATUS_FILTER_VALUES)[number];\n\nexport const TRIGGER_STATUS_LABEL_VALUES = TRIGGER_STATUS_FILTER_VALUES;\nexport type TriggerStatusLabelValue = (typeof TRIGGER_STATUS_LABEL_VALUES)[number];\n\nexport const TRIGGER_EVENT_TYPE_VALUES = [\n \"fired\",\n \"canceled\",\n \"updated\",\n \"failed\",\n \"activated\",\n] as const;\nexport type TriggerEventTypeValue = (typeof TRIGGER_EVENT_TYPE_VALUES)[number];\n\nexport const TRIGGER_EVENT_TYPE_LABEL_VALUES = TRIGGER_EVENT_TYPE_VALUES;\nexport type TriggerEventTypeLabelValue = (typeof TRIGGER_EVENT_TYPE_LABEL_VALUES)[number];\n\nexport const TRIGGER_CANCEL_REASON_LABEL_VALUES = [\n \"user_request\",\n \"oco\",\n \"parent_canceled_no_fill\",\n \"missing_reason_code\",\n \"internal_error\",\n] as const;\nexport type TriggerCancelReasonLabelValue = (typeof TRIGGER_CANCEL_REASON_LABEL_VALUES)[number];\n\nexport const TRIGGER_FAILURE_REASON_LABEL_VALUES = [\n \"unknown_symbol\",\n \"pair_disabled\",\n \"min_notional\",\n \"tick_size\",\n \"insufficient_funds\",\n \"risk_limit\",\n \"duplicate_client_id\",\n \"market_halted\",\n \"engine_busy\",\n \"account_unknown\",\n \"order_unknown\",\n \"post_only_cross\",\n \"reduce_only_blocked\",\n \"price_band_violation\",\n \"market_cap_violation\",\n \"empty_book\",\n \"fok_insufficient_liquidity\",\n \"fee_asset_not_allowed\",\n \"market_price_unavailable\",\n \"stale_quote\",\n \"min_quantity\",\n \"step_size\",\n \"invalid_sizing\",\n \"max_quote_debit_too_small\",\n \"fee_ceiling_exceeded\",\n \"trigger_price_invalid\",\n \"trigger_price_source_unsupported\",\n \"trailing_distance_invalid\",\n \"modification_requires_replace\",\n \"order_already_terminal\",\n \"conflict_idempotency_key_reuse\",\n \"rate_limited\",\n \"policy_spot_trade_deny\",\n \"policy_market_deny\",\n \"policy_max_notional\",\n \"policy_max_open_orders\",\n \"policy_trading_halted\",\n \"missing_reason_code\",\n \"internal_error\",\n] as const;\nexport type TriggerFailureReasonLabelValue = (typeof TRIGGER_FAILURE_REASON_LABEL_VALUES)[number];\n\nexport const TRIGGER_DIRECTION_VALUES = [\"above\", \"below\"] as const;\nexport type TriggerDirectionValue = (typeof TRIGGER_DIRECTION_VALUES)[number];\n\nexport const LADDER_DISTRIBUTION_VALUES = [\"linear\"] as const;\nexport type LadderDistributionValue = (typeof LADDER_DISTRIBUTION_VALUES)[number];\n\nexport const LADDER_DISTRIBUTION_LABEL_VALUES = [\n \"linear\",\n \"geometric\",\n \"weighted_favorable\",\n] as const;\nexport type LadderDistributionLabelValue = (typeof LADDER_DISTRIBUTION_LABEL_VALUES)[number];\n\nexport const TriggerTypeCodec = {\n inputToProto: {\n stop_loss: Proto.TriggerType.STOP_LOSS,\n take_profit: Proto.TriggerType.TAKE_PROFIT,\n trailing_stop: Proto.TriggerType.TRAILING_STOP,\n twap: Proto.TriggerType.TWAP,\n ladder: Proto.TriggerType.LADDER,\n } satisfies InputToProto<TriggerTypeValue, Proto.TriggerType>,\n protoToOutput: {\n [Proto.TriggerType.TRIGGER_TYPE_UNSPECIFIED]: \"unspecified\",\n [Proto.TriggerType.STOP_LOSS]: \"stop_loss\",\n [Proto.TriggerType.TAKE_PROFIT]: \"take_profit\",\n [Proto.TriggerType.TRAILING_STOP]: \"trailing_stop\",\n [Proto.TriggerType.TWAP]: \"twap\",\n [Proto.TriggerType.LADDER]: \"ladder\",\n } satisfies ProtoToOutput<Proto.TriggerType, TriggerTypeLabelValue>,\n} as const;\n\nexport const TriggerStatusCodec = {\n inputToProto: {\n created: Proto.TriggerStatus.STATUS_CREATED,\n armed: Proto.TriggerStatus.STATUS_ARMED,\n running: Proto.TriggerStatus.STATUS_RUNNING,\n completed: Proto.TriggerStatus.STATUS_COMPLETED,\n cancelled: Proto.TriggerStatus.STATUS_CANCELED,\n failed: Proto.TriggerStatus.STATUS_FAILED,\n paused: Proto.TriggerStatus.STATUS_PAUSED,\n } satisfies InputToProto<TriggerStatusFilterValue, Proto.TriggerStatus>,\n protoToOutput: {\n [Proto.TriggerStatus.STATUS_UNSPECIFIED]: \"unspecified\",\n [Proto.TriggerStatus.STATUS_CREATED]: \"created\",\n [Proto.TriggerStatus.STATUS_ARMED]: \"armed\",\n [Proto.TriggerStatus.STATUS_RUNNING]: \"running\",\n [Proto.TriggerStatus.STATUS_COMPLETED]: \"completed\",\n [Proto.TriggerStatus.STATUS_CANCELED]: \"cancelled\",\n [Proto.TriggerStatus.STATUS_FAILED]: \"failed\",\n [Proto.TriggerStatus.STATUS_PAUSED]: \"paused\",\n } satisfies ProtoToOutput<Proto.TriggerStatus, TriggerStatusLabelValue>,\n} as const;\n\nexport const TriggerEventTypeCodec = {\n inputToProto: {\n fired: Proto.TriggerEventType.EVENT_FIRED,\n canceled: Proto.TriggerEventType.EVENT_CANCELED,\n updated: Proto.TriggerEventType.EVENT_UPDATED,\n failed: Proto.TriggerEventType.EVENT_FAILED,\n activated: Proto.TriggerEventType.EVENT_ACTIVATED,\n } satisfies InputToProto<TriggerEventTypeValue, Proto.TriggerEventType>,\n protoToOutput: {\n [Proto.TriggerEventType.EVENT_UNSPECIFIED]: \"unspecified\",\n [Proto.TriggerEventType.EVENT_FIRED]: \"fired\",\n [Proto.TriggerEventType.EVENT_CANCELED]: \"canceled\",\n [Proto.TriggerEventType.EVENT_UPDATED]: \"updated\",\n [Proto.TriggerEventType.EVENT_FAILED]: \"failed\",\n [Proto.TriggerEventType.EVENT_ACTIVATED]: \"activated\",\n } satisfies ProtoToOutput<Proto.TriggerEventType, TriggerEventTypeLabelValue>,\n} as const;\n\nexport const TriggerCancelReasonCodec = {\n protoToOutput: {\n [Proto.TriggerCancelReason.UNSPECIFIED]: \"unspecified\",\n [Proto.TriggerCancelReason.USER_REQUEST]: \"user_request\",\n [Proto.TriggerCancelReason.OCO]: \"oco\",\n [Proto.TriggerCancelReason.PARENT_CANCELED_NO_FILL]: \"parent_canceled_no_fill\",\n [Proto.TriggerCancelReason.MISSING_REASON_CODE]: \"missing_reason_code\",\n [Proto.TriggerCancelReason.INTERNAL_ERROR]: \"internal_error\",\n } satisfies ProtoToOutput<Proto.TriggerCancelReason, TriggerCancelReasonLabelValue>,\n} as const;\n\nexport const TriggerFailureReasonCodec = {\n protoToOutput: {\n [Proto.TriggerFailureReason.UNSPECIFIED]: \"unspecified\",\n [Proto.TriggerFailureReason.UNKNOWN_SYMBOL]: \"unknown_symbol\",\n [Proto.TriggerFailureReason.PAIR_DISABLED]: \"pair_disabled\",\n [Proto.TriggerFailureReason.MIN_NOTIONAL]: \"min_notional\",\n [Proto.TriggerFailureReason.TICK_SIZE]: \"tick_size\",\n [Proto.TriggerFailureReason.INSUFFICIENT_FUNDS]: \"insufficient_funds\",\n [Proto.TriggerFailureReason.RISK_LIMIT]: \"risk_limit\",\n [Proto.TriggerFailureReason.DUPLICATE_CLIENT_ID]: \"duplicate_client_id\",\n [Proto.TriggerFailureReason.MARKET_HALTED]: \"market_halted\",\n [Proto.TriggerFailureReason.ENGINE_BUSY]: \"engine_busy\",\n [Proto.TriggerFailureReason.ACCOUNT_UNKNOWN]: \"account_unknown\",\n [Proto.TriggerFailureReason.ORDER_UNKNOWN]: \"order_unknown\",\n [Proto.TriggerFailureReason.POST_ONLY_CROSS]: \"post_only_cross\",\n [Proto.TriggerFailureReason.REDUCE_ONLY_BLOCKED]: \"reduce_only_blocked\",\n [Proto.TriggerFailureReason.PRICE_BAND_VIOLATION]: \"price_band_violation\",\n [Proto.TriggerFailureReason.MARKET_CAP_VIOLATION]: \"market_cap_violation\",\n [Proto.TriggerFailureReason.EMPTY_BOOK]: \"empty_book\",\n [Proto.TriggerFailureReason.FOK_INSUFFICIENT_LIQUIDITY]: \"fok_insufficient_liquidity\",\n [Proto.TriggerFailureReason.FEE_ASSET_NOT_ALLOWED]: \"fee_asset_not_allowed\",\n [Proto.TriggerFailureReason.MARKET_PRICE_UNAVAILABLE]: \"market_price_unavailable\",\n [Proto.TriggerFailureReason.STALE_QUOTE]: \"stale_quote\",\n [Proto.TriggerFailureReason.MIN_QUANTITY]: \"min_quantity\",\n [Proto.TriggerFailureReason.STEP_SIZE]: \"step_size\",\n [Proto.TriggerFailureReason.INVALID_SIZING]: \"invalid_sizing\",\n [Proto.TriggerFailureReason.MAX_QUOTE_DEBIT_TOO_SMALL]: \"max_quote_debit_too_small\",\n [Proto.TriggerFailureReason.FEE_CEILING_EXCEEDED]: \"fee_ceiling_exceeded\",\n [Proto.TriggerFailureReason.TRIGGER_PRICE_INVALID]: \"trigger_price_invalid\",\n [Proto.TriggerFailureReason.TRIGGER_PRICE_SOURCE_UNSUPPORTED]:\n \"trigger_price_source_unsupported\",\n [Proto.TriggerFailureReason.TRAILING_DISTANCE_INVALID]: \"trailing_distance_invalid\",\n [Proto.TriggerFailureReason.MODIFICATION_REQUIRES_REPLACE]: \"modification_requires_replace\",\n [Proto.TriggerFailureReason.ORDER_ALREADY_TERMINAL]: \"order_already_terminal\",\n [Proto.TriggerFailureReason.CONFLICT_IDEMPOTENCY_KEY_REUSE]:\n \"conflict_idempotency_key_reuse\",\n [Proto.TriggerFailureReason.RATE_LIMITED]: \"rate_limited\",\n [Proto.TriggerFailureReason.POLICY_SPOT_TRADE_DENY]: \"policy_spot_trade_deny\",\n [Proto.TriggerFailureReason.POLICY_MARKET_DENY]: \"policy_market_deny\",\n [Proto.TriggerFailureReason.POLICY_MAX_NOTIONAL]: \"policy_max_notional\",\n [Proto.TriggerFailureReason.POLICY_MAX_OPEN_ORDERS]: \"policy_max_open_orders\",\n [Proto.TriggerFailureReason.POLICY_TRADING_HALTED]: \"policy_trading_halted\",\n [Proto.TriggerFailureReason.MISSING_REASON_CODE]: \"missing_reason_code\",\n [Proto.TriggerFailureReason.INTERNAL_ERROR]: \"internal_error\",\n } satisfies ProtoToOutput<Proto.TriggerFailureReason, TriggerFailureReasonLabelValue>,\n} as const;\n\nexport const TriggerDirectionCodec = {\n inputToProto: {\n above: ProtoOrders.TriggerDirection.ABOVE,\n below: ProtoOrders.TriggerDirection.BELOW,\n } satisfies InputToProto<TriggerDirectionValue, ProtoOrders.TriggerDirection>,\n protoToOutput: {\n [ProtoOrders.TriggerDirection.TRIGGER_DIRECTION_UNSPECIFIED]: \"unspecified\",\n [ProtoOrders.TriggerDirection.ABOVE]: \"above\",\n [ProtoOrders.TriggerDirection.BELOW]: \"below\",\n } satisfies ProtoToOutput<ProtoOrders.TriggerDirection, TriggerDirectionValue>,\n} as const;\n\nexport const LadderDistributionCodec = {\n inputToProto: {\n linear: Proto.LadderDistribution.LINEAR,\n } satisfies InputToProto<LadderDistributionValue, Proto.LadderDistribution>,\n protoToOutput: {\n [Proto.LadderDistribution.LADDER_DISTRIBUTION_UNSPECIFIED]: \"unspecified\",\n [Proto.LadderDistribution.LINEAR]: \"linear\",\n [Proto.LadderDistribution.GEOMETRIC]: \"geometric\",\n [Proto.LadderDistribution.WEIGHTED_FAVORABLE]: \"weighted_favorable\",\n } satisfies ProtoToOutput<Proto.LadderDistribution, LadderDistributionLabelValue>,\n} as const;\n"],"mappings":";;;;AA0BA,MAAa,sBAAsB;CAC/B;CACA;CACA;CACA;CACA;AACJ;AAMA,MAAa,+BAA+B;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;AAMA,MAAa,4BAA4B;CACrC;CACA;CACA;CACA;CACA;AACJ;AAuEA,MAAa,mBAAmB;CAC5B,cAAc;EACV,WAAA;EACA,aAAA;EACA,eAAA;EACA,MAAA;EACA,QAAA;CACJ;CACA,eAAe;GACmC,IAAA;GACf,IAAA;GACE,IAAA;GACE,IAAA;GACT,IAAA;GACE,IAAA;CAChC;AACJ;AAEA,MAAa,qBAAqB;CAC9B,cAAc;EACV,SAAA;EACA,OAAA;EACA,SAAA;EACA,WAAA;EACA,WAAA;EACA,QAAA;EACA,QAAA;CACJ;CACA,eAAe;GAC+B,IAAA;GACJ,IAAA;GACF,IAAA;GACE,IAAA;GACE,IAAA;GACD,IAAA;GACF,IAAA;GACA,IAAA;CACzC;AACJ;AAEA,MAAa,wBAAwB;CACjC,cAAc;EACV,OAAA;EACA,UAAA;EACA,SAAA;EACA,QAAA;EACA,WAAA;CACJ;CACA,eAAe;GACiC,IAAA;GACN,IAAA;GACG,IAAA;GACD,IAAA;GACD,IAAA;GACG,IAAA;CAC9C;AACJ;AAEA,MAAa,2BAA2B,EACpC,eAAe;EAC8B,IAAA;EACC,IAAA;EACT,IAAA;EACoB,IAAA;EACJ,MAAA;EACL,MAAA;AAChD,EACJ;AAEA,MAAa,4BAA4B,EACrC,eAAe;EAC+B,IAAA;EACG,IAAA;EACD,IAAA;EACD,IAAA;EACH,IAAA;EACS,IAAA;EACR,IAAA;EACS,IAAA;EACN,IAAA;EACF,IAAA;EACI,KAAA;EACF,KAAA;EACE,KAAA;EACI,KAAA;EACC,KAAA;EACA,KAAA;EACV,KAAA;EACgB,KAAA;EACL,KAAA;EACG,KAAA;EACb,KAAA;EACC,KAAA;EACH,KAAA;EACK,KAAA;EACW,KAAA;EACL,KAAA;EACC,KAAA;EAEhD,KAAA;EACoD,KAAA;EACI,KAAA;EACP,KAAA;EAEjD,KAAA;EACuC,KAAA;EACU,KAAA;EACJ,KAAA;EACC,KAAA;EACG,KAAA;EACD,KAAA;EACF,MAAA;EACL,MAAA;AACjD,EACJ;AAEA,MAAa,wBAAwB;CACjC,cAAc;EACV,OAAA;EACA,OAAA;CACJ;CACA,eAAe;GACmD,IAAA;GACxB,IAAA;GACA,IAAA;CAC1C;AACJ;AAEA,MAAa,0BAA0B;CACnC,cAAc,EACV,QAAA,EACJ;CACA,eAAe;GACiD,IAAA;GACzB,IAAA;GACG,IAAA;GACS,IAAA;CACnD;AACJ"}
|
|
1
|
+
{"version":3,"file":"triggers.codecs.js","names":[],"sources":["../../../src/services/triggers/triggers.codecs.ts"],"sourcesContent":["import * as Proto from \"../../gen/triggers/v1/triggers_pb.js\";\nimport * as ProtoOrders from \"../../gen/orders/v1/orders_pb.js\";\nimport type { InputToProto, ProtoToOutput } from \"../../utils/types.js\";\nexport {\n FEE_ASSET_VALUES,\n FeeAssetCodec,\n type FeeAssetValue,\n ORDER_SIDE_VALUES as TRIGGER_SIDE_VALUES,\n ORDER_TYPE_VALUES,\n OrderSideCodec as TriggerSideCodec,\n type OrderSideValue as TriggerSideValue,\n OrderTypeCodec,\n type OrderTypeValue,\n SELF_TRADE_PREVENTION_MODE_VALUES,\n SelfTradePreventionModeCodec,\n type SelfTradePreventionModeValue,\n TIME_IN_FORCE_OUTPUT_VALUES,\n TIME_IN_FORCE_VALUES,\n TimeInForceCodec,\n type TimeInForceOutputValue,\n type TimeInForceValue,\n TRIGGER_PRICE_SOURCE_VALUES,\n TriggerPriceSourceCodec,\n type TriggerPriceSourceValue,\n} from \"../orders/order-enums.codecs.js\";\n\nexport const TRIGGER_TYPE_VALUES = [\n \"stop_loss\",\n \"take_profit\",\n \"trailing_stop\",\n \"twap\",\n \"ladder\",\n] as const;\nexport type TriggerTypeValue = (typeof TRIGGER_TYPE_VALUES)[number];\n\nexport const TRIGGER_TYPE_LABEL_VALUES = TRIGGER_TYPE_VALUES;\nexport type TriggerTypeLabelValue = (typeof TRIGGER_TYPE_LABEL_VALUES)[number];\n\nexport const TRIGGER_STATUS_FILTER_VALUES = [\n \"created\",\n \"armed\",\n \"running\",\n \"completed\",\n \"cancelled\",\n \"failed\",\n \"paused\",\n] as const;\nexport type TriggerStatusFilterValue = (typeof TRIGGER_STATUS_FILTER_VALUES)[number];\n\nexport const TRIGGER_STATUS_LABEL_VALUES = TRIGGER_STATUS_FILTER_VALUES;\nexport type TriggerStatusLabelValue = (typeof TRIGGER_STATUS_LABEL_VALUES)[number];\n\nexport const TRIGGER_EVENT_TYPE_VALUES = [\n \"fired\",\n \"canceled\",\n \"updated\",\n \"failed\",\n \"activated\",\n] as const;\nexport type TriggerEventTypeValue = (typeof TRIGGER_EVENT_TYPE_VALUES)[number];\n\nexport const TRIGGER_EVENT_TYPE_LABEL_VALUES = TRIGGER_EVENT_TYPE_VALUES;\nexport type TriggerEventTypeLabelValue = (typeof TRIGGER_EVENT_TYPE_LABEL_VALUES)[number];\n\nexport const TRIGGER_CANCEL_REASON_LABEL_VALUES = [\n \"user_request\",\n \"oco\",\n \"parent_canceled_no_fill\",\n \"missing_reason_code\",\n \"internal_error\",\n] as const;\nexport type TriggerCancelReasonLabelValue = (typeof TRIGGER_CANCEL_REASON_LABEL_VALUES)[number];\n\nexport const TRIGGER_FAILURE_REASON_LABEL_VALUES = [\n \"unknown_symbol\",\n \"pair_disabled\",\n \"min_notional\",\n \"tick_size\",\n \"insufficient_funds\",\n \"risk_limit\",\n \"duplicate_client_id\",\n \"market_halted\",\n \"engine_busy\",\n \"account_unknown\",\n \"order_unknown\",\n \"post_only_cross\",\n \"reduce_only_blocked\",\n \"price_band_violation\",\n \"market_cap_violation\",\n \"empty_book\",\n \"fok_insufficient_liquidity\",\n \"fee_asset_not_allowed\",\n \"market_price_unavailable\",\n \"stale_quote\",\n \"min_quantity\",\n \"step_size\",\n \"invalid_sizing\",\n \"max_quote_debit_too_small\",\n \"fee_ceiling_exceeded\",\n \"trigger_price_invalid\",\n \"trigger_price_source_unsupported\",\n \"trailing_distance_invalid\",\n \"modification_requires_replace\",\n \"order_already_terminal\",\n \"conflict_idempotency_key_reuse\",\n \"rate_limited\",\n \"policy_spot_trade_deny\",\n \"policy_market_deny\",\n \"policy_max_notional\",\n \"policy_max_open_orders\",\n \"policy_trading_halted\",\n \"max_slippage_invalid\",\n \"missing_reason_code\",\n \"internal_error\",\n] as const;\nexport type TriggerFailureReasonLabelValue = (typeof TRIGGER_FAILURE_REASON_LABEL_VALUES)[number];\n\nexport const TRIGGER_DIRECTION_VALUES = [\"above\", \"below\"] as const;\nexport type TriggerDirectionValue = (typeof TRIGGER_DIRECTION_VALUES)[number];\n\nexport const LADDER_DISTRIBUTION_VALUES = [\"linear\"] as const;\nexport type LadderDistributionValue = (typeof LADDER_DISTRIBUTION_VALUES)[number];\n\nexport const LADDER_DISTRIBUTION_LABEL_VALUES = [\n \"linear\",\n \"geometric\",\n \"weighted_favorable\",\n] as const;\nexport type LadderDistributionLabelValue = (typeof LADDER_DISTRIBUTION_LABEL_VALUES)[number];\n\nexport const TriggerTypeCodec = {\n inputToProto: {\n stop_loss: Proto.TriggerType.STOP_LOSS,\n take_profit: Proto.TriggerType.TAKE_PROFIT,\n trailing_stop: Proto.TriggerType.TRAILING_STOP,\n twap: Proto.TriggerType.TWAP,\n ladder: Proto.TriggerType.LADDER,\n } satisfies InputToProto<TriggerTypeValue, Proto.TriggerType>,\n protoToOutput: {\n [Proto.TriggerType.TRIGGER_TYPE_UNSPECIFIED]: \"unspecified\",\n [Proto.TriggerType.STOP_LOSS]: \"stop_loss\",\n [Proto.TriggerType.TAKE_PROFIT]: \"take_profit\",\n [Proto.TriggerType.TRAILING_STOP]: \"trailing_stop\",\n [Proto.TriggerType.TWAP]: \"twap\",\n [Proto.TriggerType.LADDER]: \"ladder\",\n } satisfies ProtoToOutput<Proto.TriggerType, TriggerTypeLabelValue>,\n} as const;\n\nexport const TriggerStatusCodec = {\n inputToProto: {\n created: Proto.TriggerStatus.STATUS_CREATED,\n armed: Proto.TriggerStatus.STATUS_ARMED,\n running: Proto.TriggerStatus.STATUS_RUNNING,\n completed: Proto.TriggerStatus.STATUS_COMPLETED,\n cancelled: Proto.TriggerStatus.STATUS_CANCELED,\n failed: Proto.TriggerStatus.STATUS_FAILED,\n paused: Proto.TriggerStatus.STATUS_PAUSED,\n } satisfies InputToProto<TriggerStatusFilterValue, Proto.TriggerStatus>,\n protoToOutput: {\n [Proto.TriggerStatus.STATUS_UNSPECIFIED]: \"unspecified\",\n [Proto.TriggerStatus.STATUS_CREATED]: \"created\",\n [Proto.TriggerStatus.STATUS_ARMED]: \"armed\",\n [Proto.TriggerStatus.STATUS_RUNNING]: \"running\",\n [Proto.TriggerStatus.STATUS_COMPLETED]: \"completed\",\n [Proto.TriggerStatus.STATUS_CANCELED]: \"cancelled\",\n [Proto.TriggerStatus.STATUS_FAILED]: \"failed\",\n [Proto.TriggerStatus.STATUS_PAUSED]: \"paused\",\n } satisfies ProtoToOutput<Proto.TriggerStatus, TriggerStatusLabelValue>,\n} as const;\n\nexport const TriggerEventTypeCodec = {\n inputToProto: {\n fired: Proto.TriggerEventType.EVENT_FIRED,\n canceled: Proto.TriggerEventType.EVENT_CANCELED,\n updated: Proto.TriggerEventType.EVENT_UPDATED,\n failed: Proto.TriggerEventType.EVENT_FAILED,\n activated: Proto.TriggerEventType.EVENT_ACTIVATED,\n } satisfies InputToProto<TriggerEventTypeValue, Proto.TriggerEventType>,\n protoToOutput: {\n [Proto.TriggerEventType.EVENT_UNSPECIFIED]: \"unspecified\",\n [Proto.TriggerEventType.EVENT_FIRED]: \"fired\",\n [Proto.TriggerEventType.EVENT_CANCELED]: \"canceled\",\n [Proto.TriggerEventType.EVENT_UPDATED]: \"updated\",\n [Proto.TriggerEventType.EVENT_FAILED]: \"failed\",\n [Proto.TriggerEventType.EVENT_ACTIVATED]: \"activated\",\n } satisfies ProtoToOutput<Proto.TriggerEventType, TriggerEventTypeLabelValue>,\n} as const;\n\nexport const TriggerCancelReasonCodec = {\n protoToOutput: {\n [Proto.TriggerCancelReason.UNSPECIFIED]: \"unspecified\",\n [Proto.TriggerCancelReason.USER_REQUEST]: \"user_request\",\n [Proto.TriggerCancelReason.OCO]: \"oco\",\n [Proto.TriggerCancelReason.PARENT_CANCELED_NO_FILL]: \"parent_canceled_no_fill\",\n [Proto.TriggerCancelReason.MISSING_REASON_CODE]: \"missing_reason_code\",\n [Proto.TriggerCancelReason.INTERNAL_ERROR]: \"internal_error\",\n } satisfies ProtoToOutput<Proto.TriggerCancelReason, TriggerCancelReasonLabelValue>,\n} as const;\n\nexport const TriggerFailureReasonCodec = {\n protoToOutput: {\n [Proto.TriggerFailureReason.UNSPECIFIED]: \"unspecified\",\n [Proto.TriggerFailureReason.UNKNOWN_SYMBOL]: \"unknown_symbol\",\n [Proto.TriggerFailureReason.PAIR_DISABLED]: \"pair_disabled\",\n [Proto.TriggerFailureReason.MIN_NOTIONAL]: \"min_notional\",\n [Proto.TriggerFailureReason.TICK_SIZE]: \"tick_size\",\n [Proto.TriggerFailureReason.INSUFFICIENT_FUNDS]: \"insufficient_funds\",\n [Proto.TriggerFailureReason.RISK_LIMIT]: \"risk_limit\",\n [Proto.TriggerFailureReason.DUPLICATE_CLIENT_ID]: \"duplicate_client_id\",\n [Proto.TriggerFailureReason.MARKET_HALTED]: \"market_halted\",\n [Proto.TriggerFailureReason.ENGINE_BUSY]: \"engine_busy\",\n [Proto.TriggerFailureReason.ACCOUNT_UNKNOWN]: \"account_unknown\",\n [Proto.TriggerFailureReason.ORDER_UNKNOWN]: \"order_unknown\",\n [Proto.TriggerFailureReason.POST_ONLY_CROSS]: \"post_only_cross\",\n [Proto.TriggerFailureReason.REDUCE_ONLY_BLOCKED]: \"reduce_only_blocked\",\n [Proto.TriggerFailureReason.PRICE_BAND_VIOLATION]: \"price_band_violation\",\n [Proto.TriggerFailureReason.MARKET_CAP_VIOLATION]: \"market_cap_violation\",\n [Proto.TriggerFailureReason.EMPTY_BOOK]: \"empty_book\",\n [Proto.TriggerFailureReason.FOK_INSUFFICIENT_LIQUIDITY]: \"fok_insufficient_liquidity\",\n [Proto.TriggerFailureReason.FEE_ASSET_NOT_ALLOWED]: \"fee_asset_not_allowed\",\n [Proto.TriggerFailureReason.MARKET_PRICE_UNAVAILABLE]: \"market_price_unavailable\",\n [Proto.TriggerFailureReason.STALE_QUOTE]: \"stale_quote\",\n [Proto.TriggerFailureReason.MIN_QUANTITY]: \"min_quantity\",\n [Proto.TriggerFailureReason.STEP_SIZE]: \"step_size\",\n [Proto.TriggerFailureReason.INVALID_SIZING]: \"invalid_sizing\",\n [Proto.TriggerFailureReason.MAX_QUOTE_DEBIT_TOO_SMALL]: \"max_quote_debit_too_small\",\n [Proto.TriggerFailureReason.FEE_CEILING_EXCEEDED]: \"fee_ceiling_exceeded\",\n [Proto.TriggerFailureReason.TRIGGER_PRICE_INVALID]: \"trigger_price_invalid\",\n [Proto.TriggerFailureReason.TRIGGER_PRICE_SOURCE_UNSUPPORTED]:\n \"trigger_price_source_unsupported\",\n [Proto.TriggerFailureReason.TRAILING_DISTANCE_INVALID]: \"trailing_distance_invalid\",\n [Proto.TriggerFailureReason.MODIFICATION_REQUIRES_REPLACE]: \"modification_requires_replace\",\n [Proto.TriggerFailureReason.ORDER_ALREADY_TERMINAL]: \"order_already_terminal\",\n [Proto.TriggerFailureReason.CONFLICT_IDEMPOTENCY_KEY_REUSE]:\n \"conflict_idempotency_key_reuse\",\n [Proto.TriggerFailureReason.RATE_LIMITED]: \"rate_limited\",\n [Proto.TriggerFailureReason.POLICY_SPOT_TRADE_DENY]: \"policy_spot_trade_deny\",\n [Proto.TriggerFailureReason.POLICY_MARKET_DENY]: \"policy_market_deny\",\n [Proto.TriggerFailureReason.POLICY_MAX_NOTIONAL]: \"policy_max_notional\",\n [Proto.TriggerFailureReason.POLICY_MAX_OPEN_ORDERS]: \"policy_max_open_orders\",\n [Proto.TriggerFailureReason.POLICY_TRADING_HALTED]: \"policy_trading_halted\",\n [Proto.TriggerFailureReason.MAX_SLIPPAGE_INVALID]: \"max_slippage_invalid\",\n [Proto.TriggerFailureReason.MISSING_REASON_CODE]: \"missing_reason_code\",\n [Proto.TriggerFailureReason.INTERNAL_ERROR]: \"internal_error\",\n } satisfies ProtoToOutput<Proto.TriggerFailureReason, TriggerFailureReasonLabelValue>,\n} as const;\n\nexport const TriggerDirectionCodec = {\n inputToProto: {\n above: ProtoOrders.TriggerDirection.ABOVE,\n below: ProtoOrders.TriggerDirection.BELOW,\n } satisfies InputToProto<TriggerDirectionValue, ProtoOrders.TriggerDirection>,\n protoToOutput: {\n [ProtoOrders.TriggerDirection.TRIGGER_DIRECTION_UNSPECIFIED]: \"unspecified\",\n [ProtoOrders.TriggerDirection.ABOVE]: \"above\",\n [ProtoOrders.TriggerDirection.BELOW]: \"below\",\n } satisfies ProtoToOutput<ProtoOrders.TriggerDirection, TriggerDirectionValue>,\n} as const;\n\nexport const LadderDistributionCodec = {\n inputToProto: {\n linear: Proto.LadderDistribution.LINEAR,\n } satisfies InputToProto<LadderDistributionValue, Proto.LadderDistribution>,\n protoToOutput: {\n [Proto.LadderDistribution.LADDER_DISTRIBUTION_UNSPECIFIED]: \"unspecified\",\n [Proto.LadderDistribution.LINEAR]: \"linear\",\n [Proto.LadderDistribution.GEOMETRIC]: \"geometric\",\n [Proto.LadderDistribution.WEIGHTED_FAVORABLE]: \"weighted_favorable\",\n } satisfies ProtoToOutput<Proto.LadderDistribution, LadderDistributionLabelValue>,\n} as const;\n"],"mappings":";;;;AA0BA,MAAa,sBAAsB;CAC/B;CACA;CACA;CACA;CACA;AACJ;AAMA,MAAa,+BAA+B;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;AAMA,MAAa,4BAA4B;CACrC;CACA;CACA;CACA;CACA;AACJ;AAwEA,MAAa,mBAAmB;CAC5B,cAAc;EACV,WAAA;EACA,aAAA;EACA,eAAA;EACA,MAAA;EACA,QAAA;CACJ;CACA,eAAe;GACmC,IAAA;GACf,IAAA;GACE,IAAA;GACE,IAAA;GACT,IAAA;GACE,IAAA;CAChC;AACJ;AAEA,MAAa,qBAAqB;CAC9B,cAAc;EACV,SAAA;EACA,OAAA;EACA,SAAA;EACA,WAAA;EACA,WAAA;EACA,QAAA;EACA,QAAA;CACJ;CACA,eAAe;GAC+B,IAAA;GACJ,IAAA;GACF,IAAA;GACE,IAAA;GACE,IAAA;GACD,IAAA;GACF,IAAA;GACA,IAAA;CACzC;AACJ;AAEA,MAAa,wBAAwB;CACjC,cAAc;EACV,OAAA;EACA,UAAA;EACA,SAAA;EACA,QAAA;EACA,WAAA;CACJ;CACA,eAAe;GACiC,IAAA;GACN,IAAA;GACG,IAAA;GACD,IAAA;GACD,IAAA;GACG,IAAA;CAC9C;AACJ;AAEA,MAAa,2BAA2B,EACpC,eAAe;EAC8B,IAAA;EACC,IAAA;EACT,IAAA;EACoB,IAAA;EACJ,MAAA;EACL,MAAA;AAChD,EACJ;AAEA,MAAa,4BAA4B,EACrC,eAAe;EAC+B,IAAA;EACG,IAAA;EACD,IAAA;EACD,IAAA;EACH,IAAA;EACS,IAAA;EACR,IAAA;EACS,IAAA;EACN,IAAA;EACF,IAAA;EACI,KAAA;EACF,KAAA;EACE,KAAA;EACI,KAAA;EACC,KAAA;EACA,KAAA;EACV,KAAA;EACgB,KAAA;EACL,KAAA;EACG,KAAA;EACb,KAAA;EACC,KAAA;EACH,KAAA;EACK,KAAA;EACW,KAAA;EACL,KAAA;EACC,KAAA;EAEhD,KAAA;EACoD,KAAA;EACI,KAAA;EACP,KAAA;EAEjD,KAAA;EACuC,KAAA;EACU,KAAA;EACJ,KAAA;EACC,KAAA;EACG,KAAA;EACD,KAAA;EACD,KAAA;EACD,MAAA;EACL,MAAA;AACjD,EACJ;AAEA,MAAa,wBAAwB;CACjC,cAAc;EACV,OAAA;EACA,OAAA;CACJ;CACA,eAAe;GACmD,IAAA;GACxB,IAAA;GACA,IAAA;CAC1C;AACJ;AAEA,MAAa,0BAA0B;CACnC,cAAc,EACV,QAAA,EACJ;CACA,eAAe;GACiD,IAAA;GACzB,IAAA;GACG,IAAA;GACS,IAAA;CACnD;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect-error-mapping.d.ts","names":[],"sources":["../../src/shared/connect-error-mapping.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"connect-error-mapping.d.ts","names":[],"sources":["../../src/shared/connect-error-mapping.ts"],"mappings":";;;;;;;iBAyIgB,6BAA6B,IAAI,eAAe;;;;;;iBAuLhD,iBAAiB;;;;;;iBA0CjB,iCAAiC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { AlreadyExistsError, AuthenticationError, InternalServerError, MfaEnrollmentRequiredError, MfaLastFactorRequiredError, MfaVerificationError, NotImplementedError, PermissionError, PolicyInUseError, PolicyLockedError, PolicyScopeMismatchError, PolyesterError, PreconditionFailedError, RateLimitError, ResourceNotFoundError, RevisionConflictError, ServiceUnavailableError, SessionElevationRequiredError, StaleQuoteError, StepUpRequiredError, SubaccountChallengeInvalidError, TimeoutError, TransientError, ValidationError, errorFromHttpStatus, isAbortError, normalizeErrorMessage } from "./errors.js";
|
|
1
|
+
import { AlreadyExistsError, AuthenticationError, InternalServerError, MfaEnrollmentRequiredError, MfaLastFactorRequiredError, MfaVerificationError, NotImplementedError, PermissionError, PolicyInUseError, PolicyLockedError, PolicyScopeMismatchError, PolyesterError, PreconditionFailedError, RateLimitError, ResourceNotFoundError, RevisionConflictError, ServiceUnavailableError, SessionElevationRequiredError, StaleQuoteError, StepUpRequiredError, SubaccountChallengeInvalidError, TimeoutError, TimestampSkewError, TransientError, ValidationError, errorFromHttpStatus, isAbortError, normalizeErrorMessage } from "./errors.js";
|
|
2
2
|
import { parseConnectErrorDetail } from "./error-detail.js";
|
|
3
3
|
import { Code, ConnectError } from "@connectrpc/connect";
|
|
4
4
|
//#region src/shared/connect-error-mapping.ts
|
|
5
|
+
/** Backend code for API-key signatures whose timestamp is outside the skew window. */
|
|
6
|
+
const TIMESTAMP_SKEW_CODE = "TIMESTAMP_SKEW";
|
|
5
7
|
function hasTransientServiceError(detail) {
|
|
6
8
|
if (detail?.service === "withdraw") return [
|
|
7
9
|
"SERVICE_UNAVAILABLE",
|
|
@@ -76,6 +78,7 @@ function connectErrorToPolyesterError(ce) {
|
|
|
76
78
|
detail
|
|
77
79
|
};
|
|
78
80
|
const withFallback = (fallback) => message || fallback;
|
|
81
|
+
if (ce.rawMessage === "TIMESTAMP_SKEW") return new TimestampSkewError("API key timestamp is outside the allowed skew window.", options);
|
|
79
82
|
const httpStatus = /^HTTP (\d{3})$/u.exec(ce.rawMessage)?.[1];
|
|
80
83
|
if (!detail && httpStatus && httpStatus !== "404") return errorFromHttpStatus(Number(httpStatus), message, {
|
|
81
84
|
...options,
|
|
@@ -84,6 +87,7 @@ function connectErrorToPolyesterError(ce) {
|
|
|
84
87
|
if (detail?.service === "auth" && detail.code === "AUTH_RESOURCE_NOT_FOUND") return new ResourceNotFoundError(withFallback("Resource not found."), options);
|
|
85
88
|
if (detail?.service === "auth" && detail.code === "AUTH_REVISION_CONFLICT") return new RevisionConflictError(withFallback("Resource changed since it was last read."), options);
|
|
86
89
|
if (detail?.service === "auth" && detail.code === "AUTH_SUBACCOUNT_CHALLENGE_INVALID") return new SubaccountChallengeInvalidError(withFallback("Subaccount challenge is expired, replaced, or invalid."), options);
|
|
90
|
+
if (detail?.service === "auth" && detail.code === "AUTH_SOCIAL_ACCOUNT_ALREADY_LINKED") return new AlreadyExistsError(withFallback("Social account is already linked to another Polyester account."), options);
|
|
87
91
|
if (detail?.service === "auth" && detail.code === "AUTH_POLICY_IN_USE") return new PolicyInUseError(withFallback("Policy is still in use."), options);
|
|
88
92
|
if (detail?.service === "auth" && detail.code === "AUTH_POLICY_LOCKED") return new PolicyLockedError(withFallback("Policy is locked."), options);
|
|
89
93
|
if (detail?.service === "auth" && detail.code === "AUTH_POLICY_SCOPE_MISMATCH") return new PolicyScopeMismatchError(withFallback("Policy does not belong to the target account scope."), options);
|
|
@@ -217,6 +221,6 @@ function createErrorMappingTransport(transport) {
|
|
|
217
221
|
};
|
|
218
222
|
}
|
|
219
223
|
//#endregion
|
|
220
|
-
export { connectErrorToPolyesterError, createErrorMappingInterceptor, createErrorMappingTransport, getNormalizedConnectMessage, toPolyesterError };
|
|
224
|
+
export { TIMESTAMP_SKEW_CODE, connectErrorToPolyesterError, createErrorMappingInterceptor, createErrorMappingTransport, getNormalizedConnectMessage, toPolyesterError };
|
|
221
225
|
|
|
222
226
|
//# sourceMappingURL=connect-error-mapping.js.map
|