Skip to content

Commit

Permalink
cryptedData: create :xt/id at backend
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesloetzsch committed Sep 12, 2023
1 parent 79b0536 commit 1152a1f
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 24 deletions.
2 changes: 1 addition & 1 deletion backend/project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject formswizard "0.2.1" #_"-SNAPSHOT"
(defproject formswizard "0.2.4" #_"-SNAPSHOT"
:description "FormsWizard backend based on clojure+reitit+xtdb"
:url "https://github.com/FormsWizard/formswizard"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
Expand Down
4 changes: 4 additions & 0 deletions backend/src/formswizard/lib/uuid.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(ns formswizard.lib.uuid)

(defn uuid []
(str (java.util.UUID/randomUUID)))
7 changes: 4 additions & 3 deletions backend/src/formswizard/model/project_state/cryptedData.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
(:require [clojure.spec.alpha :as s]))

(s/def ::data string?) ;; ArmoredPGPMessage
(s/def ::uuid string?) ;; UUID
(s/def ::keyId string?) ;; PGPID
(s/def ::armoredPublicKey string?) ;; ArmoredPubKey
(s/def ::id string?)

(s/def ::cryptedDatum (s/keys :req-un [::data ::uuid ::keyId ::armoredPublicKey]))
(s/def ::cryptedData (s/coll-of ::cryptedDatum))
(s/def ::cryptedDatum (s/keys :req-un [::data ::keyId ::armoredPublicKey]))
(s/def ::cryptedDatumWithId (s/keys :req-un [::data ::keyId ::armoredPublicKey ::id]))
(s/def ::cryptedData (s/coll-of ::cryptedDatumWithId))
2 changes: 1 addition & 1 deletion backend/src/formswizard/resolver/openapi/openapi.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{:get {:no-doc true
:openapi {:info {:title "FormsWizard OpenAPI"
:description "openapi3-docs of FormsWizard backend"
:version "0.2.0"}
:version "0.2.4"}
;; used in /secure APIs below
:components {:securitySchemes {"auth" {:type :apiKey
:in :header
Expand Down
2 changes: 1 addition & 1 deletion backend/src/formswizard/resolver/openapi/swagger.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{:get {:no-doc true
:swagger {:info {:title "FormsWizard SwaggerAPI"
:description "swagger-docs of FormsWizard backend"
:version "0.2.0"}
:version "0.2.4"}
;; used in /secure APIs below
:securityDefinitions {"auth" {:type :apiKey
:in :header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
[formswizard.state :as state]
[formswizard.lib.http :as http]))

(defn xt->id [m]
(-> (assoc m :id (:xt/id m))
(dissoc :xt/id)))

(def route
{:get {:summary "get project-state.cryptedData"
:parameters {:query (s/keys :req-un [::api/formId])}
:responses {200 {:body (s/keys :opt-un [::cryptedData/cryptedData])}}
:handler (fn [{{{:keys [formId]} :query} :parameters}]
{:status 200
:body (state/getCryptedData formId)})}
:body (-> (state/getCryptedData formId)
(update :cryptedData #(map xt->id %)))})}
:post {:summary "add project-state.cryptedData"
:parameters {:body (s/keys :req-un [::api/formId ::cryptedData/cryptedDatum])}
:responses http/ok-response
Expand Down
3 changes: 2 additions & 1 deletion backend/src/formswizard/state.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns formswizard.state
(:require [formswizard.db.state :refer [db_ctx]]
[formswizard.lib.uuid :refer [uuid]]
[formswizard.model.project-state.keys :as keys]
[formswizard.model.project-state.schema :as schema]
[formswizard.model.project-state.cryptedData :as cryptedData]
Expand Down Expand Up @@ -63,7 +64,7 @@
(defn addCryptedDatum! [formId cryptedDatum]
;(swap! state update-in [formId :cryptedData] conj cryptedDatum)
((:tx db_ctx) [[:xtdb.api/put (assoc cryptedDatum
:xt/id (str "cryptedDatum_" (:uuid cryptedDatum))
:xt/id (str "cryptedDatum_" (uuid))
:xt/spec ::cryptedData/cryptedDatum
:formId formId)]]))

Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"name": "@formswizard/app",
"version": "0.2.1",
"version": "0.2.4",
"scripts": {
"build": "turbo run build",
"dev": "turbo run dev --concurrency 50",
"lint": "turbo run lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"codegen": "npx openapi-typescript-codegen --input http://localhost:4000/openapi.json --output ./packages/api/codegen"
"format": "prettier --write \"**/*.{ts,tsx,md}\""
},
"devDependencies": {
"@turbo/gen": "^1.10.13",
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/api/codegen/core/OpenAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type OpenAPIConfig = {

export const OpenAPI: OpenAPIConfig = {
BASE: '',
VERSION: '0.2.0',
VERSION: '0.2.4',
WITH_CREDENTIALS: false,
CREDENTIALS: 'include',
TOKEN: undefined,
Expand Down
3 changes: 1 addition & 2 deletions frontend/packages/api/codegen/services/DefaultService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ export class DefaultService {
): CancelablePromise<{
cryptedData?: Array<{
data: string;
uuid: string;
keyId: string;
armoredPublicKey: string;
id: string;
}>;
}> {
return __request(OpenAPI, {
Expand All @@ -180,7 +180,6 @@ export class DefaultService {
formId: string;
cryptedDatum: {
data: string;
uuid: string;
keyId: string;
armoredPublicKey: string;
};
Expand Down
5 changes: 3 additions & 2 deletions frontend/packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@formswizard/api",
"version": "0.2.1",
"version": "0.2.4",
"description": "Typescript client for OpenAPI specification of FormsWizard-REST-API (using openapi-typescript-codegen)",
"keywords": ["openapi", "swagger", "rest", "api", "typescript", "codegen", "forms", "wizard", "json", "schema", "jsonschema", "uischema"],
"license": "MIT",
Expand All @@ -16,7 +16,8 @@
"scripts": {
"build": "tsup index.ts --format esm,cjs --dts --external react",
"dev": "npm run build --watch",
"lint": "eslint \"**/*.ts*\""
"lint": "eslint \"**/*.ts*\"",
"codegen": "npx openapi-typescript-codegen --input http://localhost:4000/openapi.json --output ./codegen"
},
"devDependencies": {
"eslint": "^8.48.0",
Expand Down
1 change: 0 additions & 1 deletion frontend/packages/submit/Submit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ function Form() {
if (encrypted && keyId && armoredPublicKey) {
const cryptedDatum = {
data: encrypted,
uuid: crypto.randomUUID(),
keyId, armoredPublicKey
};
api.postProjectStateCryptedData({formId, cryptedDatum})
Expand Down
2 changes: 1 addition & 1 deletion frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1152a1f

Please sign in to comment.