aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-10-18 19:19:20 +0200
committerFlorian Dold <florian@dold.me>2021-10-18 19:19:20 +0200
commit3a69f27412782872c1264e8a4dd1be13d57a8a80 (patch)
tree3cc3f8e4eb315b69c4e1919b229604adef4aef06 /packages
parentb1034801d124b53cbb683e4a430ac00c7979bca1 (diff)
move declarations into anastasis-core
Diffstat (limited to 'packages')
-rw-r--r--packages/anastasis-webui/package.json1
-rw-r--r--packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts173
-rw-r--r--packages/anastasis-webui/src/routes/home/index.tsx24
-rw-r--r--packages/anastasis-webui/tsconfig.json110
4 files changed, 104 insertions, 204 deletions
diff --git a/packages/anastasis-webui/package.json b/packages/anastasis-webui/package.json
index 5093ad2e9..78d8671ba 100644
--- a/packages/anastasis-webui/package.json
+++ b/packages/anastasis-webui/package.json
@@ -22,6 +22,7 @@
},
"dependencies": {
"@gnu-taler/taler-util": "workspace:^0.8.3",
+ "anastasis-core": "workspace:^0.0.1",
"preact": "^10.3.1",
"preact-render-to-string": "^5.1.4",
"preact-router": "^3.2.1"
diff --git a/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts b/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts
index 27eab0884..be68ba6eb 100644
--- a/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts
+++ b/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts
@@ -1,144 +1,16 @@
import { TalerErrorCode } from "@gnu-taler/taler-util";
+import { BackupStates, getBackupStartState, getRecoveryStartState, RecoveryStates, reduceAction, ReducerState } from "anastasis-core";
import { useState } from "preact/hooks";
-export type ReducerState =
- | ReducerStateBackup
- | ReducerStateRecovery
- | ReducerStateError;
-
-export interface ReducerStateBackup {
- recovery_state: undefined;
- backup_state: BackupStates;
- code: undefined;
- continents: any;
- countries: any;
- identity_attributes?: { [n: string]: string };
- authentication_providers: any;
- authentication_methods?: AuthMethod[];
- required_attributes: any;
- secret_name?: string;
- policies?: {
- methods: {
- authentication_method: number;
- provider: string;
- }[];
- }[];
- success_details: {
- [provider_url: string]: {
- policy_version: number;
- };
- };
- payments?: string[];
- policy_payment_requests?: {
- payto: string;
- provider: string;
- }[];
-
- core_secret?: {
- mime: string;
- value: string;
- };
-}
-
-export interface AuthMethod {
- type: string;
- instructions: string;
- challenge: string;
-}
-
-export interface ChallengeInfo {
- cost: string;
- instructions: string;
- type: string;
- uuid: string;
-}
-
-export interface ReducerStateRecovery {
- backup_state: undefined;
- recovery_state: RecoveryStates;
- code: undefined;
-
- identity_attributes?: { [n: string]: string };
-
- continents: any;
- countries: any;
- required_attributes: any;
-
- recovery_information?: {
- challenges: ChallengeInfo[];
- policies: {
- /**
- * UUID of the associated challenge.
- */
- uuid: string;
- }[][];
- };
-
- recovery_document?: {
- secret_name: string;
- provider_url: string;
- version: number;
- };
-
- selected_challenge_uuid?: string;
-
- challenge_feedback?: { [uuid: string]: ChallengeFeedback };
-
- core_secret?: {
- mime: string;
- value: string;
- };
-
- authentication_providers?: {
- [url: string]: {
- business_name: string;
- };
- };
-
- recovery_error: any;
-}
-
-export interface ChallengeFeedback {
- state: string;
-}
-
-export interface ReducerStateError {
- backup_state: undefined;
- recovery_state: undefined;
- code: number;
-}
+const reducerBaseUrl = "http://localhost:5000/";
+let remoteReducer = true;
interface AnastasisState {
reducerState: ReducerState | undefined;
currentError: any;
}
-export enum BackupStates {
- ContinentSelecting = "CONTINENT_SELECTING",
- CountrySelecting = "COUNTRY_SELECTING",
- UserAttributesCollecting = "USER_ATTRIBUTES_COLLECTING",
- AuthenticationsEditing = "AUTHENTICATIONS_EDITING",
- PoliciesReviewing = "POLICIES_REVIEWING",
- SecretEditing = "SECRET_EDITING",
- TruthsPaying = "TRUTHS_PAYING",
- PoliciesPaying = "POLICIES_PAYING",
- BackupFinished = "BACKUP_FINISHED",
-}
-
-export enum RecoveryStates {
- ContinentSelecting = "CONTINENT_SELECTING",
- CountrySelecting = "COUNTRY_SELECTING",
- UserAttributesCollecting = "USER_ATTRIBUTES_COLLECTING",
- SecretSelecting = "SECRET_SELECTING",
- ChallengeSelecting = "CHALLENGE_SELECTING",
- ChallengePaying = "CHALLENGE_PAYING",
- ChallengeSolving = "CHALLENGE_SOLVING",
- RecoveryFinished = "RECOVERY_FINISHED",
-}
-
-const reducerBaseUrl = "http://localhost:5000/";
-
-async function getBackupStartState(): Promise<ReducerState> {
+async function getBackupStartStateRemote(): Promise<ReducerState> {
let resp: Response;
try {
@@ -159,7 +31,7 @@ async function getBackupStartState(): Promise<ReducerState> {
}
}
-async function getRecoveryStartState(): Promise<ReducerState> {
+async function getRecoveryStartStateRemote(): Promise<ReducerState> {
let resp: Response;
try {
resp = await fetch(new URL("start-recovery", reducerBaseUrl).href);
@@ -179,7 +51,7 @@ async function getRecoveryStartState(): Promise<ReducerState> {
}
}
-async function reduceState(
+async function reduceStateRemote(
state: any,
action: string,
args: any,
@@ -286,7 +158,12 @@ export function useAnastasisReducer(): AnastasisReducerApi {
async function doTransition(action: string, args: any) {
console.log("reducing with", action, args);
- const s = await reduceState(anastasisState.reducerState, action, args);
+ let s: ReducerState;
+ if (remoteReducer) {
+ s = await reduceStateRemote(anastasisState.reducerState, action, args);
+ } else {
+ s = await reduceAction(anastasisState.reducerState!, action, args);
+ }
console.log("got new state from reducer", s);
if (s.code) {
setAnastasisState({ ...anastasisState, currentError: s });
@@ -303,7 +180,12 @@ export function useAnastasisReducer(): AnastasisReducerApi {
currentReducerState: anastasisState.reducerState,
currentError: anastasisState.currentError,
async startBackup() {
- const s = await getBackupStartState();
+ let s: ReducerState;
+ if (remoteReducer) {
+ s = await getBackupStartStateRemote();
+ } else {
+ s = await getBackupStartState();
+ }
if (s.code !== undefined) {
setAnastasisState({
...anastasisState,
@@ -318,7 +200,12 @@ export function useAnastasisReducer(): AnastasisReducerApi {
}
},
async startRecover() {
- const s = await getRecoveryStartState();
+ let s: ReducerState;
+ if (remoteReducer) {
+ s = await getRecoveryStartStateRemote();
+ } else {
+ s = await getRecoveryStartState();
+ }
if (s.code !== undefined) {
setAnastasisState({
...anastasisState,
@@ -394,12 +281,14 @@ export function useAnastasisReducer(): AnastasisReducerApi {
class ReducerTxImpl implements ReducerTransactionHandle {
constructor(public transactionState: ReducerState) {}
async transition(action: string, args: any): Promise<ReducerState> {
+ let s: ReducerState;
+ if (remoteReducer) {
+ s = await reduceStateRemote(this.transactionState, action, args);
+ } else {
+ s = await reduceAction(this.transactionState, action, args);
+ }
console.log("making transition in transaction", action);
- this.transactionState = await reduceState(
- this.transactionState,
- action,
- args,
- );
+ this.transactionState = s;
// Abort transaction as soon as we transition into an error state.
if (this.transactionState.code !== undefined) {
throw Error("transition resulted in error");
diff --git a/packages/anastasis-webui/src/routes/home/index.tsx b/packages/anastasis-webui/src/routes/home/index.tsx
index b1d017f30..1351775b5 100644
--- a/packages/anastasis-webui/src/routes/home/index.tsx
+++ b/packages/anastasis-webui/src/routes/home/index.tsx
@@ -6,6 +6,15 @@ import {
stringToBytes,
} from "@gnu-taler/taler-util";
import {
+ AuthMethod,
+ BackupStates,
+ ChallengeFeedback,
+ ChallengeInfo,
+ RecoveryStates,
+ ReducerStateBackup,
+ ReducerStateRecovery,
+} from "anastasis-core";
+import {
FunctionalComponent,
ComponentChildren,
h,
@@ -14,13 +23,6 @@ import {
import { useState, useContext, useRef, useLayoutEffect } from "preact/hooks";
import {
AnastasisReducerApi,
- AuthMethod,
- BackupStates,
- ChallengeFeedback,
- ChallengeInfo,
- RecoveryStates,
- ReducerStateBackup,
- ReducerStateRecovery,
useAnastasisReducer,
} from "../../hooks/use-anastasis-reducer";
import style from "./style.css";
@@ -511,8 +513,8 @@ const AnastasisClientImpl: FunctionalComponent = () => {
</p>
<p>The backup is stored by the following providers:</p>
<ul>
- {Object.keys(backupState.success_details).map((x, i) => {
- const sd = backupState.success_details[x];
+ {Object.keys(backupState.success_details!).map((x, i) => {
+ const sd = backupState.success_details![x];
return (
<li>
{x} (Policy version {sd.policy_version})
@@ -835,11 +837,11 @@ function AuthenticationEditor(props: AuthenticationEditorProps) {
undefined,
);
const { reducer, backupState } = props;
- const providers = backupState.authentication_providers;
+ const providers = backupState.authentication_providers!;
const authAvailableSet = new Set<string>();
for (const provKey of Object.keys(providers)) {
const p = providers[provKey];
- if (p.methods) {
+ if ("http_status" in p && (!("error_code" in p)) && p.methods) {
for (const meth of p.methods) {
authAvailableSet.add(meth.type);
}
diff --git a/packages/anastasis-webui/tsconfig.json b/packages/anastasis-webui/tsconfig.json
index 14d4d0470..e2491daa0 100644
--- a/packages/anastasis-webui/tsconfig.json
+++ b/packages/anastasis-webui/tsconfig.json
@@ -1,60 +1,68 @@
{
- "compilerOptions": {
- /* Basic Options */
- "target": "ES5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
- "module": "ESNext", /* Specify module code generation: 'none', commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
- // "lib": [], /* Specify library files to be included in the compilation: */
- "allowJs": true, /* Allow javascript files to be compiled. */
- // "checkJs": true, /* Report errors in .js files. */
- "jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
- "jsxFactory": "h", /* Specify the JSX factory function to use when targeting react JSX emit, e.g. React.createElement or h. */
- // "declaration": true, /* Generates corresponding '.d.ts' file. */
- // "sourceMap": true, /* Generates corresponding '.map' file. */
- // "outFile": "./", /* Concatenate and emit output to single file. */
- // "outDir": "./", /* Redirect output structure to the directory. */
- // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
- // "removeComments": true, /* Do not emit comments to output. */
- "noEmit": true, /* Do not emit outputs. */
- // "importHelpers": true, /* Import emit helpers from 'tslib'. */
- // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
- // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
+ "compilerOptions": {
+ /* Basic Options */
+ "target": "ES5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */,
+ "module": "ESNext" /* Specify module code generation: 'none', commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
+ // "lib": [], /* Specify library files to be included in the compilation: */
+ "allowJs": true /* Allow javascript files to be compiled. */,
+ // "checkJs": true, /* Report errors in .js files. */
+ "jsx": "react" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
+ "jsxFactory": "h" /* Specify the JSX factory function to use when targeting react JSX emit, e.g. React.createElement or h. */,
+ // "declaration": true, /* Generates corresponding '.d.ts' file. */
+ // "sourceMap": true, /* Generates corresponding '.map' file. */
+ // "outFile": "./", /* Concatenate and emit output to single file. */
+ // "outDir": "./", /* Redirect output structure to the directory. */
+ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
+ // "removeComments": true, /* Do not emit comments to output. */
+ "noEmit": true /* Do not emit outputs. */,
+ // "importHelpers": true, /* Import emit helpers from 'tslib'. */
+ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
+ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
- /* Strict Type-Checking Options */
- "strict": true, /* Enable all strict type-checking options. */
- // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
- // "strictNullChecks": true, /* Enable strict null checks. */
- // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
- // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
+ /* Strict Type-Checking Options */
+ "strict": true /* Enable all strict type-checking options. */,
+ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
+ // "strictNullChecks": true, /* Enable strict null checks. */
+ // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
+ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
- /* Additional Checks */
- // "noUnusedLocals": true, /* Report errors on unused locals. */
- // "noUnusedParameters": true, /* Report errors on unused parameters. */
- // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
- // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
+ /* Additional Checks */
+ // "noUnusedLocals": true, /* Report errors on unused locals. */
+ // "noUnusedParameters": true, /* Report errors on unused parameters. */
+ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
+ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
- /* Module Resolution Options */
- "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
- "esModuleInterop": true, /* */
- // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
- // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
- // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
- // "typeRoots": [], /* List of folders to include type definitions from. */
- // "types": [], /* Type declaration files to be included in compilation. */
- // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
- // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
+ /* Module Resolution Options */
+ "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
+ "esModuleInterop": true /* */,
+ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
+ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
+ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
+ // "typeRoots": [], /* List of folders to include type definitions from. */
+ // "types": [], /* Type declaration files to be included in compilation. */
+ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
+ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
- /* Source Map Options */
- // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
- // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
- // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
- // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
+ /* Source Map Options */
+ // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
+ // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
+ // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
+ // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
- /* Experimental Options */
- // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
- // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
+ /* Experimental Options */
+ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
+ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
- /* Advanced Options */
- "skipLibCheck": true /* Skip type checking of declaration files. */
+ /* Advanced Options */
+ "skipLibCheck": true /* Skip type checking of declaration files. */
+ },
+ "references": [
+ {
+ "path": "../taler-util/"
},
- "include": ["src/**/*", "tests/**/*"]
+ {
+ "path": "../anastasis-core/"
+ }
+ ],
+ "include": ["src/**/*", "tests/**/*"]
}