@polyester/sdk 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/gen/auth/v1/api_keys_pb.d.ts +1 -1
- package/dist/gen/auth/v1/api_keys_pb.js.map +1 -1
- package/dist/gen/auth/v1/policies_pb.d.ts +47 -337
- package/dist/gen/auth/v1/policies_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/policies_pb.js +49 -73
- package/dist/gen/auth/v1/policies_pb.js.map +1 -1
- package/dist/gen/orders/v1/orders_pb.d.ts +32 -1
- package/dist/gen/orders/v1/orders_pb.d.ts.map +1 -1
- package/dist/gen/orders/v1/orders_pb.js +25 -1
- package/dist/gen/orders/v1/orders_pb.js.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.d.ts +22 -2
- 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/services/lifecycle/lifecycle.schemas.d.ts +42 -42
- package/dist/services/orders/order-errors.schemas.d.ts +1 -1
- package/dist/services/orders/orders-batch.schemas.d.ts +20 -20
- package/dist/services/orders/orders-input.schemas.d.ts +4 -4
- package/dist/services/orders/orders-modify.schemas.d.ts +3 -2
- package/dist/services/orders/orders-modify.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-modify.schemas.js +5 -3
- package/dist/services/orders/orders-modify.schemas.js.map +1 -1
- package/dist/services/orders/orders-output.schemas.d.ts +6 -6
- package/dist/services/orders/orders.d.ts +1 -1
- package/dist/services/orders/orders.js +1 -1
- package/dist/services/orders/orders.js.map +1 -1
- package/dist/services/policies/api-key-policies/api-key-policies.d.ts +2 -2
- package/dist/services/policies/api-key-policies/api-key-policies.js +2 -2
- package/dist/services/policies/api-key-policies/api-key-policies.js.map +1 -1
- package/dist/services/policies/api-key-policies/api-key-policies.schemas.d.ts +15 -140
- package/dist/services/policies/api-key-policies/api-key-policies.schemas.d.ts.map +1 -1
- package/dist/services/policies/api-key-policies/api-key-policies.schemas.js +5 -53
- package/dist/services/policies/api-key-policies/api-key-policies.schemas.js.map +1 -1
- package/dist/services/policies/shared.codecs.js +4 -12
- package/dist/services/policies/shared.codecs.js.map +1 -1
- package/dist/services/policies/shared.d.ts +1 -1
- package/dist/services/policies/shared.d.ts.map +1 -1
- package/dist/services/policies/shared.js +3 -11
- package/dist/services/policies/shared.js.map +1 -1
- package/dist/services/policies/subaccount-policies/subaccount-policies.d.ts +1 -1
- package/dist/services/policies/subaccount-policies/subaccount-policies.js +1 -1
- package/dist/services/policies/subaccount-policies/subaccount-policies.js.map +1 -1
- package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.d.ts +10 -206
- package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.d.ts.map +1 -1
- package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.js +9 -115
- package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.js.map +1 -1
- package/dist/services/subaccounts/subaccounts.schemas.d.ts +5 -5
- package/dist/services/triggers/trigger-input.schemas.d.ts +14 -7
- package/dist/services/triggers/trigger-input.schemas.d.ts.map +1 -1
- package/dist/services/triggers/trigger-input.schemas.js +13 -3
- package/dist/services/triggers/trigger-input.schemas.js.map +1 -1
- package/dist/services/triggers/triggers-output.schemas.d.ts +15 -15
- package/dist/services/triggers/triggers.codecs.js +6 -3
- package/dist/services/triggers/triggers.codecs.js.map +1 -1
- package/dist/services/triggers/triggers.d.ts +2 -2
- package/dist/services/triggers/triggers.js +2 -2
- package/dist/services/triggers/triggers.js.map +1 -1
- package/dist/services/triggers/triggers.types.d.ts +3 -3
- package/dist/shared/schemas.js +2 -2
- package/dist/shared/schemas.js.map +1 -1
- package/dist/shared/transports.js +6 -1
- package/dist/shared/transports.js.map +1 -1
- package/dist/shared/wire-bounds.js +3 -1
- package/dist/shared/wire-bounds.js.map +1 -1
- package/dist/utils/numbers.js +1 -10
- package/dist/utils/numbers.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { idToBigInt } from "../../../utils/base58-id.js";
|
|
2
|
-
import { toBigIntOrZero } from "../../../utils/numbers.js";
|
|
3
2
|
import { tsObjToMs, tsObjToNsString } from "../../../utils/time.js";
|
|
4
|
-
import { BigIntStringSchema,
|
|
5
|
-
import {
|
|
3
|
+
import { BigIntStringSchema, OptionalPublicIdSchema, PublicIdSchema, TimestampMsSchema, TimestampSchema, positiveBigintStringInputSchema } from "../../../shared/schemas.js";
|
|
4
|
+
import { PolicyActionEnumSchema, PolicyMarketScopeEnumSchema, ProtoPolicyActionEnumSchema, ProtoPolicyMarketScopeEnumSchema, SpotMarketRuleSchema } from "../shared.js";
|
|
6
5
|
import { PolicyActionCodec, PolicyMarketScopeCodec, policyActionLabelFor, policyMarketScopeLabelFor } from "../shared.codecs.js";
|
|
7
6
|
import { buildProtoPatch, defineProtoPatchFields } from "../../../utils/proto-patch.js";
|
|
8
7
|
import * as v from "valibot";
|
|
@@ -26,14 +25,9 @@ const ApiKeyPolicySchema = v.pipe(v.object({
|
|
|
26
25
|
description: v.string(),
|
|
27
26
|
spotMarkets: v.optional(v.array(SpotMarketRuleSchema), []),
|
|
28
27
|
spotMarketScope: v.pipe(ProtoPolicyMarketScopeEnumSchema, v.transform((v) => policyMarketScopeLabelFor(v))),
|
|
29
|
-
perpMarketScope: v.pipe(ProtoPolicyMarketScopeEnumSchema, v.transform((v) => policyMarketScopeLabelFor(v))),
|
|
30
|
-
perpMarkets: v.optional(v.array(PerpMarketRuleSchema), []),
|
|
31
28
|
actions: v.pipe(v.optional(v.array(ProtoPolicyActionEnumSchema), []), v.transform((v) => v.map((action) => policyActionLabelFor(action)))),
|
|
32
29
|
isTemplate: v.optional(v.boolean(), false),
|
|
33
30
|
sourceTemplateId: OptionalPublicIdSchema,
|
|
34
|
-
maxOrderNotional: v.pipe(v.optional(v.bigint()), v.transform((v) => v === void 0 ? void 0 : Number(v))),
|
|
35
|
-
dailyInternalTransferOutLimit: v.pipe(v.bigint(), v.transform((v) => Number(v))),
|
|
36
|
-
dailyWithdrawLimit: v.pipe(v.bigint(), v.transform((v) => Number(v))),
|
|
37
31
|
createdAt: TimestampMsSchema,
|
|
38
32
|
updatedAt: TimestampSchema,
|
|
39
33
|
revision: BigIntStringSchema
|
|
@@ -47,38 +41,21 @@ const ApiKeyPolicyInputBaseSchema = v.strictObject({
|
|
|
47
41
|
name: v.string(),
|
|
48
42
|
description: v.optional(v.string(), ""),
|
|
49
43
|
spotMarkets: v.optional(v.array(SpotMarketRuleSchema), []),
|
|
50
|
-
perpMarkets: v.optional(v.array(PerpMarketRuleSchema), []),
|
|
51
44
|
spotMarketScope: v.pipe(PolicyMarketScopeEnumSchema, v.transform((v) => PolicyMarketScopeCodec.inputToProto[v])),
|
|
52
|
-
perpMarketScope: v.pipe(PolicyMarketScopeEnumSchema, v.transform((v) => PolicyMarketScopeCodec.inputToProto[v])),
|
|
53
45
|
actions: v.pipe(v.optional(v.array(PolicyActionEnumSchema), []), v.transform((v) => (v ?? []).map((action) => PolicyActionCodec.inputToProto[action]))),
|
|
54
|
-
maxOrderNotional: OptionalNumberToBigIntOrZeroSchema,
|
|
55
|
-
dailyInternalTransferLimit: OptionalNumberToBigIntOrZeroSchema,
|
|
56
|
-
dailyWithdrawLimit: OptionalNumberToBigIntOrZeroSchema,
|
|
57
46
|
isTemplate: v.optional(v.boolean(), false),
|
|
58
47
|
assignToKeyId: v.optional(v.pipe(v.string(), v.trim()))
|
|
59
48
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
...rest,
|
|
64
|
-
dailyInternalTransferOutLimit: dailyInternalTransferLimit
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
const CreateApiKeyPolicyInputSchema = v.pipe(ApiKeyPolicyInputBaseSchema, v.transform((input) => ({
|
|
68
|
-
policy: createApiKeyPolicyBaseTransform(input),
|
|
69
|
-
assignToKeyId: input.assignToKeyId
|
|
49
|
+
const CreateApiKeyPolicyInputSchema = v.pipe(ApiKeyPolicyInputBaseSchema, v.transform(({ assignToKeyId, ...policy }) => ({
|
|
50
|
+
policy,
|
|
51
|
+
assignToKeyId
|
|
70
52
|
})));
|
|
71
53
|
const ApiKeyPolicyPatchSchema = v.strictObject({
|
|
72
54
|
name: v.optional(v.string()),
|
|
73
55
|
description: v.optional(v.string()),
|
|
74
56
|
spotMarkets: v.optional(v.array(SpotMarketRuleSchema)),
|
|
75
|
-
perpMarkets: v.optional(v.array(PerpMarketRuleSchema)),
|
|
76
57
|
spotMarketScope: v.optional(PolicyMarketScopeEnumSchema),
|
|
77
|
-
perpMarketScope: v.optional(PolicyMarketScopeEnumSchema),
|
|
78
58
|
actions: v.optional(v.array(PolicyActionEnumSchema)),
|
|
79
|
-
maxOrderNotional: v.optional(v.nullable(v.number())),
|
|
80
|
-
dailyInternalTransferLimit: v.optional(v.nullable(v.number())),
|
|
81
|
-
dailyWithdrawLimit: v.optional(v.nullable(v.number())),
|
|
82
59
|
isTemplate: v.optional(v.boolean())
|
|
83
60
|
});
|
|
84
61
|
const API_KEY_POLICY_PATCH_FIELDS = defineProtoPatchFields()({
|
|
@@ -94,34 +71,14 @@ const API_KEY_POLICY_PATCH_FIELDS = defineProtoPatchFields()({
|
|
|
94
71
|
path: "spot_markets",
|
|
95
72
|
encode: (spotMarkets) => ({ spotMarkets })
|
|
96
73
|
},
|
|
97
|
-
perpMarkets: {
|
|
98
|
-
path: "perp_markets",
|
|
99
|
-
encode: (perpMarkets) => ({ perpMarkets })
|
|
100
|
-
},
|
|
101
74
|
spotMarketScope: {
|
|
102
75
|
path: "spot_market_scope",
|
|
103
76
|
encode: (scope) => ({ spotMarketScope: PolicyMarketScopeCodec.inputToProto[scope] })
|
|
104
77
|
},
|
|
105
|
-
perpMarketScope: {
|
|
106
|
-
path: "perp_market_scope",
|
|
107
|
-
encode: (scope) => ({ perpMarketScope: PolicyMarketScopeCodec.inputToProto[scope] })
|
|
108
|
-
},
|
|
109
78
|
actions: {
|
|
110
79
|
path: "actions",
|
|
111
80
|
encode: (actions) => ({ actions: actions.map((action) => PolicyActionCodec.inputToProto[action]) })
|
|
112
81
|
},
|
|
113
|
-
maxOrderNotional: {
|
|
114
|
-
path: "max_order_notional",
|
|
115
|
-
encode: (value) => ({ maxOrderNotional: toBigIntOrZero(value) })
|
|
116
|
-
},
|
|
117
|
-
dailyInternalTransferLimit: {
|
|
118
|
-
path: "daily_internal_transfer_out_limit",
|
|
119
|
-
encode: (value) => ({ dailyInternalTransferOutLimit: toBigIntOrZero(value) })
|
|
120
|
-
},
|
|
121
|
-
dailyWithdrawLimit: {
|
|
122
|
-
path: "daily_withdraw_limit",
|
|
123
|
-
encode: (value) => ({ dailyWithdrawLimit: toBigIntOrZero(value) })
|
|
124
|
-
},
|
|
125
82
|
isTemplate: {
|
|
126
83
|
path: "is_template",
|
|
127
84
|
encode: (isTemplate) => ({ isTemplate })
|
|
@@ -150,12 +107,7 @@ const DEFAULT_API_KEY_POLICY = {
|
|
|
150
107
|
description: "Default API key policy with no permissions",
|
|
151
108
|
spotMarkets: [],
|
|
152
109
|
spotMarketScope: "all",
|
|
153
|
-
perpMarketScope: "all",
|
|
154
|
-
perpMarkets: [],
|
|
155
110
|
actions: [],
|
|
156
|
-
maxOrderNotional: 0,
|
|
157
|
-
dailyInternalTransferOutLimit: 0,
|
|
158
|
-
dailyWithdrawLimit: 0,
|
|
159
111
|
isTemplate: false,
|
|
160
112
|
sourceTemplateId: "",
|
|
161
113
|
createdAt: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-key-policies.schemas.js","names":[],"sources":["../../../../src/services/policies/api-key-policies/api-key-policies.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport {\n PerpMarketRuleSchema,\n PolicyActionEnumSchema,\n PolicyMarketScopeEnumSchema,\n ProtoPolicyActionEnumSchema,\n ProtoPolicyMarketScopeEnumSchema,\n SpotMarketRuleSchema,\n} from \"../shared.js\";\nimport {\n PolicyMarketScopeCodec,\n PolicyActionCodec,\n policyMarketScopeLabelFor,\n policyActionLabelFor,\n} from \"../shared.codecs.js\";\nimport { idToBigInt } from \"../../../utils/base58-id.js\";\nimport {\n OptionalNumberToBigIntOrZeroSchema,\n OptionalPublicIdSchema,\n BigIntStringSchema,\n PublicIdSchema,\n TimestampMsSchema,\n TimestampSchema,\n positiveBigintStringInputSchema,\n} from \"../../../shared/schemas.js\";\nimport { tsObjToMs, tsObjToNsString } from \"../../../utils/time.js\";\nimport { toBigIntOrZero } from \"../../../utils/numbers.js\";\nimport { buildProtoPatch, defineProtoPatchFields } from \"../../../utils/proto-patch.js\";\n\nconst OptionalApiKeyContextSchema = v.optional(\n v.pipe(v.string(), v.trim(), v.minLength(1, \"keyId is required\")),\n);\n\nexport const ListApiKeyPoliciesInputSchema = v.strictObject({\n keyId: OptionalApiKeyContextSchema,\n});\n\nexport type ListApiKeyPoliciesInput = v.InferInput<typeof ListApiKeyPoliciesInputSchema>;\n\nexport const GetApiKeyPolicyInputSchema = v.pipe(\n v.strictObject({\n policyId: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1))),\n keyId: OptionalApiKeyContextSchema,\n }),\n v.transform(({ policyId, keyId }) => ({\n policyId: policyId ? idToBigInt(policyId, \"policyId\") : undefined,\n keyId,\n })),\n);\n\nexport type GetApiKeyPolicyInput = v.InferInput<typeof GetApiKeyPolicyInputSchema>;\n\n/**\n * From the backend format to a usable frontend/UI format, so big ints to numbers, etc.\n * Shape matches auth.v1.ApiPolicyView.\n */\nexport const ApiKeyPolicySchema = v.pipe(\n v.object({\n id: PublicIdSchema,\n name: v.string(),\n description: v.string(),\n spotMarkets: v.optional(v.array(SpotMarketRuleSchema), []),\n spotMarketScope: v.pipe(\n ProtoPolicyMarketScopeEnumSchema,\n v.transform((v) => policyMarketScopeLabelFor(v)),\n ),\n perpMarketScope: v.pipe(\n ProtoPolicyMarketScopeEnumSchema,\n v.transform((v) => policyMarketScopeLabelFor(v)),\n ),\n perpMarkets: v.optional(v.array(PerpMarketRuleSchema), []),\n actions: v.pipe(\n v.optional(v.array(ProtoPolicyActionEnumSchema), []),\n v.transform((v) => v.map((action) => policyActionLabelFor(action))),\n ),\n isTemplate: v.optional(v.boolean(), false),\n sourceTemplateId: OptionalPublicIdSchema,\n maxOrderNotional: v.pipe(\n v.optional(v.bigint()),\n v.transform((v) => (v === undefined ? undefined : Number(v))),\n ),\n dailyInternalTransferOutLimit: v.pipe(\n v.bigint(),\n v.transform((v) => Number(v)),\n ),\n dailyWithdrawLimit: v.pipe(\n v.bigint(),\n v.transform((v) => Number(v)),\n ),\n createdAt: TimestampMsSchema,\n updatedAt: TimestampSchema,\n revision: BigIntStringSchema,\n }),\n v.transform(({ updatedAt, ...policy }) => ({\n ...policy,\n updatedAt: tsObjToMs(updatedAt),\n updatedAtNs: tsObjToNsString(updatedAt),\n })),\n);\n\nexport type ApiKeyPolicy = v.InferOutput<typeof ApiKeyPolicySchema>;\n\nexport const ListApiKeyPoliciesResponseSchema = v.pipe(\n v.object({\n policies: v.optional(v.array(ApiKeyPolicySchema), []),\n }),\n v.transform((value) => value.policies),\n);\n\nexport type ListApiKeyPoliciesResponse = v.InferOutput<typeof ListApiKeyPoliciesResponseSchema>;\n\nconst ApiKeyPolicyInputBaseSchema = v.strictObject({\n name: v.string(),\n description: v.optional(v.string(), \"\"),\n spotMarkets: v.optional(v.array(SpotMarketRuleSchema), []),\n perpMarkets: v.optional(v.array(PerpMarketRuleSchema), []),\n spotMarketScope: v.pipe(\n PolicyMarketScopeEnumSchema,\n v.transform((v) => PolicyMarketScopeCodec.inputToProto[v]),\n ),\n perpMarketScope: v.pipe(\n PolicyMarketScopeEnumSchema,\n v.transform((v) => PolicyMarketScopeCodec.inputToProto[v]),\n ),\n actions: v.pipe(\n v.optional(v.array(PolicyActionEnumSchema), []),\n v.transform((v) => (v ?? []).map((action) => PolicyActionCodec.inputToProto[action])),\n ),\n maxOrderNotional: OptionalNumberToBigIntOrZeroSchema,\n dailyInternalTransferLimit: OptionalNumberToBigIntOrZeroSchema,\n dailyWithdrawLimit: OptionalNumberToBigIntOrZeroSchema,\n isTemplate: v.optional(v.boolean(), false),\n assignToKeyId: v.optional(v.pipe(v.string(), v.trim())),\n});\n\nfunction createApiKeyPolicyBaseTransform(input: v.InferOutput<typeof ApiKeyPolicyInputBaseSchema>) {\n const { dailyInternalTransferLimit, assignToKeyId: _assignToKeyId, ...rest } = input;\n return {\n ...rest,\n dailyInternalTransferOutLimit: dailyInternalTransferLimit,\n };\n}\n\nexport const CreateApiKeyPolicyInputSchema = v.pipe(\n ApiKeyPolicyInputBaseSchema,\n v.transform((input) => ({\n policy: createApiKeyPolicyBaseTransform(input),\n assignToKeyId: input.assignToKeyId,\n })),\n);\n\nexport type ApiKeyPolicyCreateInput = v.InferInput<typeof CreateApiKeyPolicyInputSchema>;\n\nconst ApiKeyPolicyPatchSchema = v.strictObject({\n name: v.optional(v.string()),\n description: v.optional(v.string()),\n spotMarkets: v.optional(v.array(SpotMarketRuleSchema)),\n perpMarkets: v.optional(v.array(PerpMarketRuleSchema)),\n spotMarketScope: v.optional(PolicyMarketScopeEnumSchema),\n perpMarketScope: v.optional(PolicyMarketScopeEnumSchema),\n actions: v.optional(v.array(PolicyActionEnumSchema)),\n maxOrderNotional: v.optional(v.nullable(v.number())),\n dailyInternalTransferLimit: v.optional(v.nullable(v.number())),\n dailyWithdrawLimit: v.optional(v.nullable(v.number())),\n isTemplate: v.optional(v.boolean()),\n});\n\ntype ApiKeyPolicyPatch = v.InferOutput<typeof ApiKeyPolicyPatchSchema>;\n\nconst API_KEY_POLICY_PATCH_FIELDS = defineProtoPatchFields<ApiKeyPolicyPatch>()({\n name: { path: \"name\", encode: (name) => ({ name }) },\n description: { path: \"description\", encode: (description) => ({ description }) },\n spotMarkets: { path: \"spot_markets\", encode: (spotMarkets) => ({ spotMarkets }) },\n perpMarkets: { path: \"perp_markets\", encode: (perpMarkets) => ({ perpMarkets }) },\n spotMarketScope: {\n path: \"spot_market_scope\",\n encode: (scope) => ({ spotMarketScope: PolicyMarketScopeCodec.inputToProto[scope] }),\n },\n perpMarketScope: {\n path: \"perp_market_scope\",\n encode: (scope) => ({ perpMarketScope: PolicyMarketScopeCodec.inputToProto[scope] }),\n },\n actions: {\n path: \"actions\",\n encode: (actions) => ({\n actions: actions.map((action) => PolicyActionCodec.inputToProto[action]),\n }),\n },\n maxOrderNotional: {\n path: \"max_order_notional\",\n encode: (value) => ({ maxOrderNotional: toBigIntOrZero(value) }),\n },\n dailyInternalTransferLimit: {\n path: \"daily_internal_transfer_out_limit\",\n encode: (value) => ({ dailyInternalTransferOutLimit: toBigIntOrZero(value) }),\n },\n dailyWithdrawLimit: {\n path: \"daily_withdraw_limit\",\n encode: (value) => ({ dailyWithdrawLimit: toBigIntOrZero(value) }),\n },\n isTemplate: { path: \"is_template\", encode: (isTemplate) => ({ isTemplate }) },\n});\n\nexport const UpdateApiKeyPolicyInputSchema = v.pipe(\n v.strictObject({\n ...ApiKeyPolicyPatchSchema.entries,\n policyId: v.pipe(\n v.string(),\n v.transform((v) => idToBigInt(v, \"policyId\")),\n ),\n expectedRevision: positiveBigintStringInputSchema(\"expectedRevision\"),\n }),\n v.check(\n ({ policyId: _policyId, expectedRevision: _expectedRevision, ...patch }) =>\n Object.values(patch).some((value) => value !== undefined),\n \"At least one API key policy field must be provided\",\n ),\n v.transform(({ policyId, expectedRevision, ...patch }) => {\n const { patch: policy, updateMask } = buildProtoPatch(patch, API_KEY_POLICY_PATCH_FIELDS);\n return {\n policyId,\n policy,\n updateMask,\n expectedRevision,\n };\n }),\n);\n\nexport type ApiKeyPolicyUpdateInput = v.InferInput<typeof UpdateApiKeyPolicyInputSchema>;\n\nexport const ApplyApiKeyPolicyInputSchema = v.strictObject({\n keyId: v.pipe(v.string(), v.trim(), v.minLength(1)),\n policyId: v.pipe(\n v.nullable(v.pipe(v.string(), v.trim())),\n v.transform((value) => (value ? idToBigInt(value, \"policyId\") : undefined)),\n ),\n});\n\nexport type ApiKeyPolicyApplyInput = v.InferInput<typeof ApplyApiKeyPolicyInputSchema>;\n\nexport const DEFAULT_API_KEY_POLICY: ApiKeyPolicy = {\n id: \"\",\n name: \"API Key Policy\",\n description: \"Default API key policy with no permissions\",\n spotMarkets: [],\n spotMarketScope: \"all\",\n perpMarketScope: \"all\",\n perpMarkets: [],\n actions: [],\n maxOrderNotional: 0,\n dailyInternalTransferOutLimit: 0,\n dailyWithdrawLimit: 0,\n isTemplate: false,\n sourceTemplateId: \"\",\n createdAt: 0,\n updatedAt: 0,\n updatedAtNs: \"0\",\n revision: \"0\",\n};\n"],"mappings":";;;;;;;;;AA6BA,MAAM,8BAA8B,EAAE,SAClC,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,GAAG,mBAAmB,CAAC,CACpE;AAEA,MAAa,gCAAgC,EAAE,aAAa,EACxD,OAAO,4BACX,CAAC;AAID,MAAa,6BAA6B,EAAE,KACxC,EAAE,aAAa;CACX,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC;CACjE,OAAO;AACX,CAAC,GACD,EAAE,WAAW,EAAE,UAAU,aAAa;CAClC,UAAU,WAAW,WAAW,UAAU,UAAU,IAAI,KAAA;CACxD;AACJ,EAAE,CACN;;;;;AAQA,MAAa,qBAAqB,EAAE,KAChC,EAAE,OAAO;CACL,IAAI;CACJ,MAAM,EAAE,OAAO;CACf,aAAa,EAAE,OAAO;CACtB,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,GAAG,CAAC,CAAC;CACzD,iBAAiB,EAAE,KACf,kCACA,EAAE,WAAW,MAAM,0BAA0B,CAAC,CAAC,CACnD;CACA,iBAAiB,EAAE,KACf,kCACA,EAAE,WAAW,MAA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GAC5D,oDACJ,GACA,EAAE,WAAW,EAAE,UAAU,kBAAkB,GAAG,YAAY;CACtD,MAAM,EAAE,OAAO,QAAQ,eAAe,gBAAgB,OAAO,2BAA2B;CACxF,OAAO;EACH;EACA;EACA;EACA;CACJ;AACJ,CAAC,CACL;AAIA,MAAa,+BAA+B,EAAE,aAAa;CACvD,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,CAAC,CAAC;CAClD,UAAU,EAAE,KACR,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,CAAC,CAAC,GACvC,EAAE,WAAW,UAAW,QAAQ,WAAW,OAAO,UAAU,IAAI,KAAA,CAAU,CAC9E;AACJ,CAAC;AAID,MAAa,yBAAuC;CAChD,IAAI;CACJ,MAAM;CACN,aAAa;CACb,aAAa,CAAC;CACd,iBAAiB;CACjB,iBAAiB;CACjB,aAAa,CAAC;CACd,SAAS,CAAC;CACV,kBAAkB;CAClB,+BAA+B;CAC/B,oBAAoB;CACpB,YAAY;CACZ,kBAAkB;CAClB,WAAW;CACX,WAAW;CACX,aAAa;CACb,UAAU;AACd"}
|
|
1
|
+
{"version":3,"file":"api-key-policies.schemas.js","names":[],"sources":["../../../../src/services/policies/api-key-policies/api-key-policies.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport {\n PolicyActionEnumSchema,\n PolicyMarketScopeEnumSchema,\n ProtoPolicyActionEnumSchema,\n ProtoPolicyMarketScopeEnumSchema,\n SpotMarketRuleSchema,\n} from \"../shared.js\";\nimport {\n PolicyMarketScopeCodec,\n PolicyActionCodec,\n policyMarketScopeLabelFor,\n policyActionLabelFor,\n} from \"../shared.codecs.js\";\nimport { idToBigInt } from \"../../../utils/base58-id.js\";\nimport {\n OptionalPublicIdSchema,\n BigIntStringSchema,\n PublicIdSchema,\n TimestampMsSchema,\n TimestampSchema,\n positiveBigintStringInputSchema,\n} from \"../../../shared/schemas.js\";\nimport { tsObjToMs, tsObjToNsString } from \"../../../utils/time.js\";\nimport { buildProtoPatch, defineProtoPatchFields } from \"../../../utils/proto-patch.js\";\n\nconst OptionalApiKeyContextSchema = v.optional(\n v.pipe(v.string(), v.trim(), v.minLength(1, \"keyId is required\")),\n);\n\nexport const ListApiKeyPoliciesInputSchema = v.strictObject({\n keyId: OptionalApiKeyContextSchema,\n});\n\nexport type ListApiKeyPoliciesInput = v.InferInput<typeof ListApiKeyPoliciesInputSchema>;\n\nexport const GetApiKeyPolicyInputSchema = v.pipe(\n v.strictObject({\n policyId: v.optional(v.pipe(v.string(), v.trim(), v.minLength(1))),\n keyId: OptionalApiKeyContextSchema,\n }),\n v.transform(({ policyId, keyId }) => ({\n policyId: policyId ? idToBigInt(policyId, \"policyId\") : undefined,\n keyId,\n })),\n);\n\nexport type GetApiKeyPolicyInput = v.InferInput<typeof GetApiKeyPolicyInputSchema>;\n\n/**\n * From the backend format to a usable frontend/UI format, so big ints to numbers, etc.\n * Shape matches auth.v1.ApiPolicyView.\n */\nexport const ApiKeyPolicySchema = v.pipe(\n v.object({\n id: PublicIdSchema,\n name: v.string(),\n description: v.string(),\n spotMarkets: v.optional(v.array(SpotMarketRuleSchema), []),\n spotMarketScope: v.pipe(\n ProtoPolicyMarketScopeEnumSchema,\n v.transform((v) => policyMarketScopeLabelFor(v)),\n ),\n actions: v.pipe(\n v.optional(v.array(ProtoPolicyActionEnumSchema), []),\n v.transform((v) => v.map((action) => policyActionLabelFor(action))),\n ),\n isTemplate: v.optional(v.boolean(), false),\n sourceTemplateId: OptionalPublicIdSchema,\n createdAt: TimestampMsSchema,\n updatedAt: TimestampSchema,\n revision: BigIntStringSchema,\n }),\n v.transform(({ updatedAt, ...policy }) => ({\n ...policy,\n updatedAt: tsObjToMs(updatedAt),\n updatedAtNs: tsObjToNsString(updatedAt),\n })),\n);\n\nexport type ApiKeyPolicy = v.InferOutput<typeof ApiKeyPolicySchema>;\n\nexport const ListApiKeyPoliciesResponseSchema = v.pipe(\n v.object({\n policies: v.optional(v.array(ApiKeyPolicySchema), []),\n }),\n v.transform((value) => value.policies),\n);\n\nexport type ListApiKeyPoliciesResponse = v.InferOutput<typeof ListApiKeyPoliciesResponseSchema>;\n\nconst ApiKeyPolicyInputBaseSchema = v.strictObject({\n name: v.string(),\n description: v.optional(v.string(), \"\"),\n spotMarkets: v.optional(v.array(SpotMarketRuleSchema), []),\n spotMarketScope: v.pipe(\n PolicyMarketScopeEnumSchema,\n v.transform((v) => PolicyMarketScopeCodec.inputToProto[v]),\n ),\n actions: v.pipe(\n v.optional(v.array(PolicyActionEnumSchema), []),\n v.transform((v) => (v ?? []).map((action) => PolicyActionCodec.inputToProto[action])),\n ),\n isTemplate: v.optional(v.boolean(), false),\n assignToKeyId: v.optional(v.pipe(v.string(), v.trim())),\n});\n\nexport const CreateApiKeyPolicyInputSchema = v.pipe(\n ApiKeyPolicyInputBaseSchema,\n v.transform(({ assignToKeyId, ...policy }) => ({ policy, assignToKeyId })),\n);\n\nexport type ApiKeyPolicyCreateInput = v.InferInput<typeof CreateApiKeyPolicyInputSchema>;\n\nconst ApiKeyPolicyPatchSchema = v.strictObject({\n name: v.optional(v.string()),\n description: v.optional(v.string()),\n spotMarkets: v.optional(v.array(SpotMarketRuleSchema)),\n spotMarketScope: v.optional(PolicyMarketScopeEnumSchema),\n actions: v.optional(v.array(PolicyActionEnumSchema)),\n isTemplate: v.optional(v.boolean()),\n});\n\ntype ApiKeyPolicyPatch = v.InferOutput<typeof ApiKeyPolicyPatchSchema>;\n\nconst API_KEY_POLICY_PATCH_FIELDS = defineProtoPatchFields<ApiKeyPolicyPatch>()({\n name: { path: \"name\", encode: (name) => ({ name }) },\n description: { path: \"description\", encode: (description) => ({ description }) },\n spotMarkets: { path: \"spot_markets\", encode: (spotMarkets) => ({ spotMarkets }) },\n spotMarketScope: {\n path: \"spot_market_scope\",\n encode: (scope) => ({ spotMarketScope: PolicyMarketScopeCodec.inputToProto[scope] }),\n },\n actions: {\n path: \"actions\",\n encode: (actions) => ({\n actions: actions.map((action) => PolicyActionCodec.inputToProto[action]),\n }),\n },\n isTemplate: { path: \"is_template\", encode: (isTemplate) => ({ isTemplate }) },\n});\n\nexport const UpdateApiKeyPolicyInputSchema = v.pipe(\n v.strictObject({\n ...ApiKeyPolicyPatchSchema.entries,\n policyId: v.pipe(\n v.string(),\n v.transform((v) => idToBigInt(v, \"policyId\")),\n ),\n expectedRevision: positiveBigintStringInputSchema(\"expectedRevision\"),\n }),\n v.check(\n ({ policyId: _policyId, expectedRevision: _expectedRevision, ...patch }) =>\n Object.values(patch).some((value) => value !== undefined),\n \"At least one API key policy field must be provided\",\n ),\n v.transform(({ policyId, expectedRevision, ...patch }) => {\n const { patch: policy, updateMask } = buildProtoPatch(patch, API_KEY_POLICY_PATCH_FIELDS);\n return {\n policyId,\n policy,\n updateMask,\n expectedRevision,\n };\n }),\n);\n\nexport type ApiKeyPolicyUpdateInput = v.InferInput<typeof UpdateApiKeyPolicyInputSchema>;\n\nexport const ApplyApiKeyPolicyInputSchema = v.strictObject({\n keyId: v.pipe(v.string(), v.trim(), v.minLength(1)),\n policyId: v.pipe(\n v.nullable(v.pipe(v.string(), v.trim())),\n v.transform((value) => (value ? idToBigInt(value, \"policyId\") : undefined)),\n ),\n});\n\nexport type ApiKeyPolicyApplyInput = v.InferInput<typeof ApplyApiKeyPolicyInputSchema>;\n\nexport const DEFAULT_API_KEY_POLICY: ApiKeyPolicy = {\n id: \"\",\n name: \"API Key Policy\",\n description: \"Default API key policy with no permissions\",\n spotMarkets: [],\n spotMarketScope: \"all\",\n actions: [],\n isTemplate: false,\n sourceTemplateId: \"\",\n createdAt: 0,\n updatedAt: 0,\n updatedAtNs: \"0\",\n revision: \"0\",\n};\n"],"mappings":";;;;;;;;AA0BA,MAAM,8BAA8B,EAAE,SAClC,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,GAAG,mBAAmB,CAAC,CACpE;AAEA,MAAa,gCAAgC,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C3E;CACJ;CACA,YAAY;EAAE,MAAM;EAAe,SAAS,gBAAgB,EAAE,WAAW;CAAG;AAChF,CAAC;AAED,MAAa,gCAAgC,EAAE,KAC3C,EAAE,aAAa;CACX,GAAG,wBAAwB;CAC3B,UAAU,EAAE,KACR,EAAE,OAAO,GACT,EAAE,WAAW,MAAM,WAAW,GAAG,UAAU,CAAC,CAChD;CACA,kBAAkB,gCAAgC,kBAAkB;AACxE,CAAC,GACD,EAAE,OACG,EAAE,UAAU,WAAW,kBAAkB,mBAAmB,GAAG,YAC5D,OAAO,OAAO,KAAK,CAAC,CAAC,MAAM,UAAU,UAAU,KAAA,CAAS,GAC5D,oDACJ,GACA,EAAE,WAAW,EAAE,UAAU,kBAAkB,GAAG,YAAY;CACtD,MAAM,EAAE,OAAO,QAAQ,eAAe,gBAAgB,OAAO,2BAA2B;CACxF,OAAO;EACH;EACA;EACA;EACA;CACJ;AACJ,CAAC,CACL;AAIA,MAAa,+BAA+B,EAAE,aAAa;CACvD,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,CAAC,CAAC;CAClD,UAAU,EAAE,KACR,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,CAAC,CAAC,GACvC,EAAE,WAAW,UAAW,QAAQ,WAAW,OAAO,UAAU,IAAI,KAAA,CAAU,CAC9E;AACJ,CAAC;AAID,MAAa,yBAAuC;CAChD,IAAI;CACJ,MAAM;CACN,aAAa;CACb,aAAa,CAAC;CACd,iBAAiB;CACjB,SAAS,CAAC;CACV,YAAY;CACZ,kBAAkB;CAClB,WAAW;CACX,WAAW;CACX,aAAa;CACb,UAAU;AACd"}
|
|
@@ -16,31 +16,23 @@ const PolicyActionCodec = {
|
|
|
16
16
|
protoToOutput: {
|
|
17
17
|
[0]: "unspecified",
|
|
18
18
|
[1]: "trade-spot",
|
|
19
|
-
[2]: "trade-perp",
|
|
20
19
|
[3]: "internal-transfer",
|
|
21
20
|
[4]: "external-withdraw",
|
|
22
21
|
[5]: "read-balances",
|
|
23
22
|
[6]: "read-spot",
|
|
24
|
-
[7]: "read-perp",
|
|
25
23
|
[8]: "read-internal-transfers",
|
|
26
|
-
[
|
|
27
|
-
[
|
|
28
|
-
[12]: "manage-address-book",
|
|
29
|
-
[13]: "manage-transfer-whitelists"
|
|
24
|
+
[11]: "read-address-book",
|
|
25
|
+
[12]: "manage-address-book"
|
|
30
26
|
},
|
|
31
27
|
inputToProto: {
|
|
32
28
|
"trade-spot": 1,
|
|
33
|
-
"trade-perp": 2,
|
|
34
29
|
"internal-transfer": 3,
|
|
35
30
|
"external-withdraw": 4,
|
|
36
31
|
"read-balances": 5,
|
|
37
32
|
"read-spot": 6,
|
|
38
|
-
"read-perp": 7,
|
|
39
33
|
"read-internal-transfers": 8,
|
|
40
|
-
"read-
|
|
41
|
-
"
|
|
42
|
-
"manage-address-book": 12,
|
|
43
|
-
"manage-transfer-whitelists": 13
|
|
34
|
+
"read-address-book": 11,
|
|
35
|
+
"manage-address-book": 12
|
|
44
36
|
}
|
|
45
37
|
};
|
|
46
38
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.codecs.js","names":[],"sources":["../../../src/services/policies/shared.codecs.ts"],"sourcesContent":["import * as Proto from \"../../gen/auth/v1/policies_pb.js\";\nimport { requiredEnumLabel } from \"../../shared/proto-enum-codec.js\";\nimport type { DecodedEnum, ProtoToOutput } from \"../../utils/types.js\";\n\nexport const POLICY_ACTION_LABELS = [\n \"trade-spot\",\n \"
|
|
1
|
+
{"version":3,"file":"shared.codecs.js","names":[],"sources":["../../../src/services/policies/shared.codecs.ts"],"sourcesContent":["import * as Proto from \"../../gen/auth/v1/policies_pb.js\";\nimport { requiredEnumLabel } from \"../../shared/proto-enum-codec.js\";\nimport type { DecodedEnum, ProtoToOutput } from \"../../utils/types.js\";\n\nexport const POLICY_ACTION_LABELS = [\n \"trade-spot\",\n \"internal-transfer\",\n \"external-withdraw\",\n \"read-balances\",\n \"read-spot\",\n \"read-internal-transfers\",\n \"read-address-book\",\n \"manage-address-book\",\n] as const;\nexport type PolicyActionLabel = (typeof POLICY_ACTION_LABELS)[number];\n\nexport const POLICY_MARKET_SCOPE_LABELS = [\"all\", \"allowlist\"] as const;\nexport type PolicyMarketScopeLabel = (typeof POLICY_MARKET_SCOPE_LABELS)[number];\n\nexport const PolicyMarketScopeCodec = {\n inputToProto: {\n all: Proto.MarketScope_Value.ALL,\n allowlist: Proto.MarketScope_Value.ALLOWLIST,\n } satisfies Record<PolicyMarketScopeLabel, Proto.MarketScope_Value>,\n protoToOutput: {\n [Proto.MarketScope_Value.UNSPECIFIED]: \"unspecified\",\n [Proto.MarketScope_Value.ALL]: \"all\",\n [Proto.MarketScope_Value.ALLOWLIST]: \"allowlist\",\n } satisfies ProtoToOutput<Proto.MarketScope_Value, PolicyMarketScopeLabel>,\n} as const;\n\nexport const PolicyActionCodec = {\n protoToOutput: {\n [Proto.PolicyAction.UNSPECIFIED]: \"unspecified\",\n [Proto.PolicyAction.TRADE_SPOT]: \"trade-spot\",\n [Proto.PolicyAction.INTERNAL_TRANSFER]: \"internal-transfer\",\n [Proto.PolicyAction.EXTERNAL_WITHDRAW]: \"external-withdraw\",\n [Proto.PolicyAction.READ_BALANCES]: \"read-balances\",\n [Proto.PolicyAction.READ_SPOT]: \"read-spot\",\n [Proto.PolicyAction.READ_INTERNAL_TRANSFERS]: \"read-internal-transfers\",\n [Proto.PolicyAction.READ_ADDRESS_BOOK]: \"read-address-book\",\n [Proto.PolicyAction.MANAGE_ADDRESS_BOOK]: \"manage-address-book\",\n } satisfies ProtoToOutput<Proto.PolicyAction, PolicyActionLabel>,\n inputToProto: {\n \"trade-spot\": Proto.PolicyAction.TRADE_SPOT,\n \"internal-transfer\": Proto.PolicyAction.INTERNAL_TRANSFER,\n \"external-withdraw\": Proto.PolicyAction.EXTERNAL_WITHDRAW,\n \"read-balances\": Proto.PolicyAction.READ_BALANCES,\n \"read-spot\": Proto.PolicyAction.READ_SPOT,\n \"read-internal-transfers\": Proto.PolicyAction.READ_INTERNAL_TRANSFERS,\n \"read-address-book\": Proto.PolicyAction.READ_ADDRESS_BOOK,\n \"manage-address-book\": Proto.PolicyAction.MANAGE_ADDRESS_BOOK,\n } satisfies Record<PolicyActionLabel, Proto.PolicyAction>,\n} as const;\n\n/**\n * Returns the display label for a policy market scope.\n */\nexport function policyMarketScopeLabelFor(\n value: Proto.MarketScope_Value,\n): DecodedEnum<PolicyMarketScopeLabel> {\n return requiredEnumLabel(\n PolicyMarketScopeCodec.protoToOutput,\n value,\n \"PolicyMarketScopeCodec\",\n \"market scope\",\n );\n}\n\n/**\n * Returns the display label for a policy action.\n */\nexport function policyActionLabelFor(value: Proto.PolicyAction): DecodedEnum<PolicyActionLabel> {\n return requiredEnumLabel(\n PolicyActionCodec.protoToOutput,\n value,\n \"PolicyActionCodec\",\n \"policy action\",\n );\n}\n"],"mappings":";;;AAmBA,MAAa,yBAAyB;CAClC,cAAc;EACV,KAAA;EACA,WAAA;CACJ;CACA,eAAe;GAC4B,IAAA;GACR,IAAA;GACM,IAAA;CACzC;AACJ;AAEA,MAAa,oBAAoB;CAC7B,eAAe;GACuB,IAAA;GACD,IAAA;GACO,IAAA;GACA,IAAA;GACJ,IAAA;GACJ,IAAA;GACc,IAAA;GACN,KAAA;GACE,KAAA;CAC9C;CACA,cAAc;EACV,cAAA;EACA,qBAAA;EACA,qBAAA;EACA,iBAAA;EACA,aAAA;EACA,2BAAA;EACA,qBAAA;EACA,uBAAA;CACJ;AACJ;;;;AAKA,SAAgB,0BACZ,OACmC;CACnC,OAAO,kBACH,uBAAuB,eACvB,OACA,0BACA,cACJ;AACJ;;;;AAKA,SAAgB,qBAAqB,OAA2D;CAC5F,OAAO,kBACH,kBAAkB,eAClB,OACA,qBACA,eACJ;AACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "../../gen/auth/v1/policies_pb.js";
|
|
2
2
|
import * as v from "valibot";
|
|
3
3
|
//#region src/services/policies/shared.d.ts
|
|
4
|
-
declare const PolicyActionEnumSchema: v.PicklistSchema<readonly ["trade-spot", "
|
|
4
|
+
declare const PolicyActionEnumSchema: v.PicklistSchema<readonly ["trade-spot", "internal-transfer", "external-withdraw", "read-balances", "read-spot", "read-internal-transfers", "read-address-book", "manage-address-book"], undefined>;
|
|
5
5
|
declare const PolicyMarketScopeEnumSchema: v.PicklistSchema<readonly ["all", "allowlist"], undefined>;
|
|
6
6
|
type PolicyMarketScope = v.InferOutput<typeof PolicyMarketScopeEnumSchema>;
|
|
7
7
|
type PolicyAction = v.InferOutput<typeof PolicyActionEnumSchema>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","names":[],"sources":["../../../src/services/policies/shared.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"shared.d.ts","names":[],"sources":["../../../src/services/policies/shared.ts"],"mappings":";;;cAsBa,wBAAsB,EAAA;cAEtB,6BAA2B,EAAA;KAC5B,oBAAoB,EAAE,mBAAmB;KAEzC,eAAe,EAAE,mBAAmB"}
|
|
@@ -3,23 +3,15 @@ import { MarketScope_Value, PolicyAction } from "../../gen/auth/v1/policies_pb.j
|
|
|
3
3
|
import * as v from "valibot";
|
|
4
4
|
//#region src/services/policies/shared.ts
|
|
5
5
|
const SpotMarketRuleSchema = v.object({ symbol: v.string() });
|
|
6
|
-
const PerpMarketRuleSchema = v.object({
|
|
7
|
-
symbol: v.string(),
|
|
8
|
-
maxLeverageX: v.number()
|
|
9
|
-
});
|
|
10
6
|
const POLICY_ACTIONS = [
|
|
11
7
|
"trade-spot",
|
|
12
|
-
"trade-perp",
|
|
13
8
|
"internal-transfer",
|
|
14
9
|
"external-withdraw",
|
|
15
10
|
"read-balances",
|
|
16
11
|
"read-spot",
|
|
17
|
-
"read-perp",
|
|
18
12
|
"read-internal-transfers",
|
|
19
|
-
"read-
|
|
20
|
-
"
|
|
21
|
-
"manage-address-book",
|
|
22
|
-
"manage-transfer-whitelists"
|
|
13
|
+
"read-address-book",
|
|
14
|
+
"manage-address-book"
|
|
23
15
|
];
|
|
24
16
|
const POLICY_MARKET_SCOPES = ["all", "allowlist"];
|
|
25
17
|
const ProtoPolicyActionEnumSchema = v.enum(PolicyAction);
|
|
@@ -28,6 +20,6 @@ const ProtoPolicyMarketScopeEnumSchema = v.enum(MarketScope_Value);
|
|
|
28
20
|
const PolicyMarketScopeEnumSchema = v.picklist(POLICY_MARKET_SCOPES);
|
|
29
21
|
const PolicyIdSchema = v.pipe(v.string(), v.trim(), v.minLength(1), v.transform((v) => idToBigInt(v, "policyId")));
|
|
30
22
|
//#endregion
|
|
31
|
-
export { POLICY_ACTIONS, POLICY_MARKET_SCOPES,
|
|
23
|
+
export { POLICY_ACTIONS, POLICY_MARKET_SCOPES, PolicyActionEnumSchema, PolicyIdSchema, PolicyMarketScopeEnumSchema, ProtoPolicyActionEnumSchema, ProtoPolicyMarketScopeEnumSchema, SpotMarketRuleSchema };
|
|
32
24
|
|
|
33
25
|
//# sourceMappingURL=shared.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","names":["Proto.PolicyAction","Proto.MarketScope_Value"],"sources":["../../../src/services/policies/shared.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport * as Proto from \"../../gen/auth/v1/policies_pb.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\n\nexport const SpotMarketRuleSchema = v.object({\n symbol: v.string(),\n});\n\nexport const
|
|
1
|
+
{"version":3,"file":"shared.js","names":["Proto.PolicyAction","Proto.MarketScope_Value"],"sources":["../../../src/services/policies/shared.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport * as Proto from \"../../gen/auth/v1/policies_pb.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\n\nexport const SpotMarketRuleSchema = v.object({\n symbol: v.string(),\n});\n\nexport const POLICY_ACTIONS = [\n \"trade-spot\",\n \"internal-transfer\",\n \"external-withdraw\",\n \"read-balances\",\n \"read-spot\",\n \"read-internal-transfers\",\n \"read-address-book\",\n \"manage-address-book\",\n] as const;\n\nexport const POLICY_MARKET_SCOPES = [\"all\", \"allowlist\"] as const;\n\nexport const ProtoPolicyActionEnumSchema = v.enum(Proto.PolicyAction);\nexport const PolicyActionEnumSchema = v.picklist(POLICY_ACTIONS);\nexport const ProtoPolicyMarketScopeEnumSchema = v.enum(Proto.MarketScope_Value);\nexport const PolicyMarketScopeEnumSchema = v.picklist(POLICY_MARKET_SCOPES);\nexport type PolicyMarketScope = v.InferOutput<typeof PolicyMarketScopeEnumSchema>;\n\nexport type PolicyAction = v.InferOutput<typeof PolicyActionEnumSchema>;\n\nexport const PolicyIdSchema = v.pipe(\n v.string(),\n v.trim(),\n v.minLength(1),\n v.transform((v) => idToBigInt(v, \"policyId\")),\n);\n"],"mappings":";;;;AAIA,MAAa,uBAAuB,EAAE,OAAO,EACzC,QAAQ,EAAE,OAAO,EACrB,CAAC;AAED,MAAa,iBAAiB;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;AAEA,MAAa,uBAAuB,CAAC,OAAO,WAAW;AAEvD,MAAa,8BAA8B,EAAE,KAAKA,YAAkB;AACpE,MAAa,yBAAyB,EAAE,SAAS,cAAc;AAC/D,MAAa,mCAAmC,EAAE,KAAKC,iBAAuB;AAC9E,MAAa,8BAA8B,EAAE,SAAS,oBAAoB;AAK1E,MAAa,iBAAiB,EAAE,KAC5B,EAAE,OAAO,GACT,EAAE,KAAK,GACP,EAAE,UAAU,CAAC,GACb,EAAE,WAAW,MAAM,WAAW,GAAG,UAAU,CAAC,CAChD"}
|
|
@@ -37,7 +37,7 @@ declare class SubaccountPoliciesService {
|
|
|
37
37
|
*/
|
|
38
38
|
delete(policyId: string, options?: PolyesterMutationOptions): Promise<void>;
|
|
39
39
|
/**
|
|
40
|
-
* Attaches a policy to a subaccount
|
|
40
|
+
* Attaches a policy to a subaccount. Passing a null policyId clears the explicit binding and restores the system read-only policy.
|
|
41
41
|
*/
|
|
42
42
|
apply(input: v.InferInput<typeof ApplySubaccountPolicyInputSchema>, options?: PolyesterMutationOptions): Promise<void>;
|
|
43
43
|
/**
|
|
@@ -64,7 +64,7 @@ var SubaccountPoliciesService = class {
|
|
|
64
64
|
await this.#client.deleteSubaccountPolicy({ policyId: validatedPolicyId }, toConnectCallOptions(options));
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
* Attaches a policy to a subaccount
|
|
67
|
+
* Attaches a policy to a subaccount. Passing a null policyId clears the explicit binding and restores the system read-only policy.
|
|
68
68
|
*/
|
|
69
69
|
async apply(input, options) {
|
|
70
70
|
const validatedInput = parse(ApplySubaccountPolicyInputSchema, input);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subaccount-policies.js","names":["#client","Proto.PolicyService","#realtime","#resolver","Proto.SubaccountPolicyViewSchema"],"sources":["../../../../src/services/policies/subaccount-policies/subaccount-policies.ts"],"sourcesContent":["import * as Proto from \"../../../gen/auth/v1/policies_pb.js\";\nimport { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../../shared/validation.js\";\nimport { removeUndefined } from \"../../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../../shared/request-options.js\";\nimport type { BaseSubscribeInput } from \"../../../shared/types.js\";\nimport type { PolyesterRealtime } from \"../../../realtime/index.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../../subaccount-resolver.js\";\nimport {\n SubaccountPolicySchema,\n CreateSubaccountPolicyInputSchema,\n UpdateSubaccountPolicyInputSchema,\n PolicyIdSchema,\n ApplySubaccountPolicyInputSchema,\n type SubaccountPolicy,\n ListSubaccountPoliciesInputSchema,\n GetSubaccountPolicyInputSchema,\n} from \"./subaccount-policies.schemas.js\";\n\ninterface SubscribePoliciesInput extends BaseSubscribeInput<SubaccountPolicy> {\n accountId: string;\n}\n\n/**\n * Manages reusable subaccount policy templates, assignments, and realtime policy updates.\n */\nexport class SubaccountPoliciesService {\n #client: Client<typeof Proto.PolicyService>;\n #realtime: PolyesterRealtime;\n #resolver?: SubaccountResolver;\n\n constructor(transport: Transport, realtime: PolyesterRealtime, resolver?: SubaccountResolver) {\n this.#client = createClient(Proto.PolicyService, transport);\n this.#realtime = realtime;\n this.#resolver = resolver;\n }\n\n /**\n * Returns subaccount policy templates visible to the caller, sorted by ascending policy ID.\n */\n async list(\n input: v.InferInput<typeof ListSubaccountPoliciesInputSchema> = {},\n options?: PolyesterRequestOptions,\n ): Promise<SubaccountPolicy[]> {\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const request = parse(ListSubaccountPoliciesInputSchema, resolved);\n const result = await this.#client.listSubaccountPolicies(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(v.array(SubaccountPolicySchema), result.policies);\n }\n\n /**\n * Fetches one subaccount policy template by base58 policy ID and returns null when no policy is returned.\n */\n async get(\n input: v.InferInput<typeof GetSubaccountPolicyInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<SubaccountPolicy | null> {\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const request = parse(GetSubaccountPolicyInputSchema, resolved);\n const result = await this.#client.getSubaccountPolicy(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n if (!result.policy) return null;\n return parse(SubaccountPolicySchema, result.policy);\n }\n\n /**\n * Creates a subaccount policy template, optionally attaching it to a target subaccount in the same request.\n */\n async create(\n input: v.InferInput<typeof CreateSubaccountPolicyInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<SubaccountPolicy> {\n const validatedInput = parse(CreateSubaccountPolicyInputSchema, input);\n const result = await this.#client.createSubaccountPolicy(\n removeUndefined(validatedInput),\n toConnectCallOptions(options),\n );\n if (!result.policy) throw new Error(\"Failed to create subaccount policy\");\n return parse(SubaccountPolicySchema, result.policy);\n }\n\n /**\n * Updates selected subaccount policy fields using optimistic concurrency.\n */\n async update(\n input: v.InferInput<typeof UpdateSubaccountPolicyInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<SubaccountPolicy> {\n const validatedInput = parse(UpdateSubaccountPolicyInputSchema, input);\n const result = await this.#client.updateSubaccountPolicy(\n removeUndefined(validatedInput),\n toConnectCallOptions(options),\n );\n if (!result.policy) throw new Error(\"Failed to update subaccount policy\");\n return parse(SubaccountPolicySchema, result.policy);\n }\n\n /**\n * Deletes a subaccount policy template when it is not in use.\n */\n async delete(policyId: string, options?: PolyesterMutationOptions): Promise<void> {\n const validatedPolicyId = parse(PolicyIdSchema, policyId);\n await this.#client.deleteSubaccountPolicy(\n { policyId: validatedPolicyId },\n toConnectCallOptions(options),\n );\n }\n\n /**\n * Attaches a policy to a subaccount
|
|
1
|
+
{"version":3,"file":"subaccount-policies.js","names":["#client","Proto.PolicyService","#realtime","#resolver","Proto.SubaccountPolicyViewSchema"],"sources":["../../../../src/services/policies/subaccount-policies/subaccount-policies.ts"],"sourcesContent":["import * as Proto from \"../../../gen/auth/v1/policies_pb.js\";\nimport { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../../shared/validation.js\";\nimport { removeUndefined } from \"../../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../../shared/request-options.js\";\nimport type { BaseSubscribeInput } from \"../../../shared/types.js\";\nimport type { PolyesterRealtime } from \"../../../realtime/index.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../../subaccount-resolver.js\";\nimport {\n SubaccountPolicySchema,\n CreateSubaccountPolicyInputSchema,\n UpdateSubaccountPolicyInputSchema,\n PolicyIdSchema,\n ApplySubaccountPolicyInputSchema,\n type SubaccountPolicy,\n ListSubaccountPoliciesInputSchema,\n GetSubaccountPolicyInputSchema,\n} from \"./subaccount-policies.schemas.js\";\n\ninterface SubscribePoliciesInput extends BaseSubscribeInput<SubaccountPolicy> {\n accountId: string;\n}\n\n/**\n * Manages reusable subaccount policy templates, assignments, and realtime policy updates.\n */\nexport class SubaccountPoliciesService {\n #client: Client<typeof Proto.PolicyService>;\n #realtime: PolyesterRealtime;\n #resolver?: SubaccountResolver;\n\n constructor(transport: Transport, realtime: PolyesterRealtime, resolver?: SubaccountResolver) {\n this.#client = createClient(Proto.PolicyService, transport);\n this.#realtime = realtime;\n this.#resolver = resolver;\n }\n\n /**\n * Returns subaccount policy templates visible to the caller, sorted by ascending policy ID.\n */\n async list(\n input: v.InferInput<typeof ListSubaccountPoliciesInputSchema> = {},\n options?: PolyesterRequestOptions,\n ): Promise<SubaccountPolicy[]> {\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const request = parse(ListSubaccountPoliciesInputSchema, resolved);\n const result = await this.#client.listSubaccountPolicies(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(v.array(SubaccountPolicySchema), result.policies);\n }\n\n /**\n * Fetches one subaccount policy template by base58 policy ID and returns null when no policy is returned.\n */\n async get(\n input: v.InferInput<typeof GetSubaccountPolicyInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<SubaccountPolicy | null> {\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const request = parse(GetSubaccountPolicyInputSchema, resolved);\n const result = await this.#client.getSubaccountPolicy(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n if (!result.policy) return null;\n return parse(SubaccountPolicySchema, result.policy);\n }\n\n /**\n * Creates a subaccount policy template, optionally attaching it to a target subaccount in the same request.\n */\n async create(\n input: v.InferInput<typeof CreateSubaccountPolicyInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<SubaccountPolicy> {\n const validatedInput = parse(CreateSubaccountPolicyInputSchema, input);\n const result = await this.#client.createSubaccountPolicy(\n removeUndefined(validatedInput),\n toConnectCallOptions(options),\n );\n if (!result.policy) throw new Error(\"Failed to create subaccount policy\");\n return parse(SubaccountPolicySchema, result.policy);\n }\n\n /**\n * Updates selected subaccount policy fields using optimistic concurrency.\n */\n async update(\n input: v.InferInput<typeof UpdateSubaccountPolicyInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<SubaccountPolicy> {\n const validatedInput = parse(UpdateSubaccountPolicyInputSchema, input);\n const result = await this.#client.updateSubaccountPolicy(\n removeUndefined(validatedInput),\n toConnectCallOptions(options),\n );\n if (!result.policy) throw new Error(\"Failed to update subaccount policy\");\n return parse(SubaccountPolicySchema, result.policy);\n }\n\n /**\n * Deletes a subaccount policy template when it is not in use.\n */\n async delete(policyId: string, options?: PolyesterMutationOptions): Promise<void> {\n const validatedPolicyId = parse(PolicyIdSchema, policyId);\n await this.#client.deleteSubaccountPolicy(\n { policyId: validatedPolicyId },\n toConnectCallOptions(options),\n );\n }\n\n /**\n * Attaches a policy to a subaccount. Passing a null policyId clears the explicit binding and restores the system read-only policy.\n */\n async apply(\n input: v.InferInput<typeof ApplySubaccountPolicyInputSchema>,\n options?: PolyesterMutationOptions,\n ): Promise<void> {\n const validatedInput = parse(ApplySubaccountPolicyInputSchema, input);\n await this.#client.setSubaccountPolicy(\n removeUndefined(validatedInput),\n toConnectCallOptions(options),\n );\n }\n\n /**\n * Subscribes to private subaccount policy updates for an account and emits normalized policy views.\n */\n subscribePolicies(input: SubscribePoliciesInput) {\n const channel = `private:auth:subaccount-policies:${input.accountId}:proto`;\n\n return this.#realtime.connectProtoChannel({\n channel,\n schema: Proto.SubaccountPolicyViewSchema,\n onPublication: (data) => {\n const policy = parse(SubaccountPolicySchema, data);\n input.onEvent(policy);\n },\n onConnected: () => input.onOpen?.(),\n onDisconnected: () => input.onClose?.(),\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;AA+BA,IAAa,4BAAb,MAAuC;CACnC;CACA;CACA;CAEA,YAAY,WAAsB,UAA6B,UAA+B;EAC1F,KAAKA,UAAU,aAAaC,eAAqB,SAAS;EAC1D,KAAKC,YAAY;EACjB,KAAKC,YAAY;CACrB;;;;CA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