diff options
author | Florian Dold <florian@dold.me> | 2021-11-04 21:47:51 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-11-04 21:47:51 +0100 |
commit | 5a72e4ae3e9ebd77547ac5aa95cd0b54b39a34cd (patch) | |
tree | 4ee5ac89a8302ceaa00cea9aa12dc2d86102a768 | |
parent | 09d01a4bf16c3fcbe6020d8efd38cae34db53514 (diff) | |
download | wallet-core-5a72e4ae3e9ebd77547ac5aa95cd0b54b39a34cd.tar.xz |
anastasis-core: implement update_policy transition
-rw-r--r-- | packages/anastasis-core/rollup.config.js | 28 | ||||
-rw-r--r-- | packages/anastasis-core/src/index.ts | 14 | ||||
-rw-r--r-- | packages/anastasis-core/src/reducer-types.ts | 5 |
3 files changed, 46 insertions, 1 deletions
diff --git a/packages/anastasis-core/rollup.config.js b/packages/anastasis-core/rollup.config.js index 59998c93b..a9af1d3b5 100644 --- a/packages/anastasis-core/rollup.config.js +++ b/packages/anastasis-core/rollup.config.js @@ -5,7 +5,7 @@ import json from "@rollup/plugin-json"; import builtins from "builtin-modules"; import sourcemaps from "rollup-plugin-sourcemaps"; -export default { +const cli = { input: "lib/index.node.js", output: { file: "dist/anastasis-cli.js", @@ -28,3 +28,29 @@ export default { json(), ], }; + +const standalone = { + input: "lib/cli-entry.js", + output: { + file: "dist/anastasis-cli-standalone.js", + format: "es", + sourcemap: true, + }, + external: [...builtins, "source-map-support"], + plugins: [ + nodeResolve({ + preferBuiltins: true, + }), + + sourcemaps(), + + commonjs({ + sourceMap: true, + transformMixedEsModules: true, + }), + + json(), + ], +}; + +export default [standalone, cli]; diff --git a/packages/anastasis-core/src/index.ts b/packages/anastasis-core/src/index.ts index 53364fc08..f2b8ff1d1 100644 --- a/packages/anastasis-core/src/index.ts +++ b/packages/anastasis-core/src/index.ts @@ -62,6 +62,7 @@ import { codecForActionArgsChangeVersion, ActionArgsChangeVersion, TruthMetaData, + ActionArgsUpdatePolicy, } from "./reducer-types.js"; import fetchPonyfill from "fetch-ponyfill"; import { @@ -1038,6 +1039,18 @@ async function deletePolicy( }; } +async function updatePolicy( + state: ReducerStateBackup, + args: ActionArgsUpdatePolicy, +): Promise<ReducerStateBackup> { + const policies = [...(state.policies ?? [])]; + policies[args.policy_index] = { methods: args.policy }; + return { + ...state, + policies, + }; +} + async function addPolicy( state: ReducerStateBackup, args: ActionArgsAddPolicy, @@ -1230,6 +1243,7 @@ const backupTransitions: Record< ...transitionBackupJump("next", BackupStates.SecretEditing), ...transition("add_policy", codecForActionArgsAddPolicy(), addPolicy), ...transition("delete_policy", codecForAny(), deletePolicy), + ...transition("update_policy", codecForAny(), updatePolicy), }, [BackupStates.SecretEditing]: { ...transitionBackupJump("back", BackupStates.PoliciesReviewing), diff --git a/packages/anastasis-core/src/reducer-types.ts b/packages/anastasis-core/src/reducer-types.ts index 56b27898e..e5b0c47a4 100644 --- a/packages/anastasis-core/src/reducer-types.ts +++ b/packages/anastasis-core/src/reducer-types.ts @@ -418,6 +418,11 @@ export interface ActionArgsChangeVersion { version: number; } +export interface ActionArgsUpdatePolicy { + policy_index: number; + policy: PolicyMember[]; +} + export const codecForActionArgsChangeVersion = () => buildCodecForObject<ActionArgsChangeVersion>() .property("provider_url", codecForString()) |