-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(platform): set and get App Data
- Loading branch information
Showing
8 changed files
with
192 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { z } from 'zod' | ||
|
||
import { BadRequestError } from '@proofzero/errors' | ||
import { AccountURNSpace } from '@proofzero/urns/account' | ||
|
||
import { Context } from '../../context' | ||
import { initAccessNodeByName } from '../../nodes' | ||
import { AppData } from '@proofzero/types/application' | ||
import type { AppDataType } from '@proofzero/types/application' | ||
import type { AccountURN } from '@proofzero/urns/account' | ||
|
||
export const GetAppDataInput = z.object({ | ||
clientId: z.string(), | ||
}) | ||
|
||
export const GetAppDataOutput = AppData | ||
|
||
export const getAppDataMethod = async ({ | ||
input, | ||
ctx, | ||
}: { | ||
input: z.infer<typeof GetAppDataInput> | ||
ctx: Context | ||
}): Promise<z.infer<typeof GetAppDataOutput>> => { | ||
const accountUrn = ctx.accountURN as AccountURN | ||
const { clientId } = input | ||
|
||
if (!clientId) | ||
throw new BadRequestError({ | ||
message: 'missing client id', | ||
}) | ||
|
||
if (!AccountURNSpace.is(accountUrn)) | ||
throw new BadRequestError({ | ||
message: 'missing account', | ||
}) | ||
|
||
const name = `${AccountURNSpace.decode(accountUrn)}@${clientId}` | ||
const accessNode = await initAccessNodeByName(name, ctx.Access) | ||
|
||
const appData = | ||
(await accessNode.storage.get<AppDataType>('appData')) || | ||
({} as AppDataType) | ||
return appData | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { z } from 'zod' | ||
|
||
import { BadRequestError } from '@proofzero/errors' | ||
import { AccountURNSpace } from '@proofzero/urns/account' | ||
|
||
import { Context } from '../../context' | ||
import { initAccessNodeByName } from '../../nodes' | ||
import { AppData } from '@proofzero/types/application' | ||
import type { AppDataType } from '@proofzero/types/application' | ||
import type { AccountURN } from '@proofzero/urns/account' | ||
|
||
export const SetAppDataInput = z.object({ | ||
clientId: z.string(), | ||
appData: AppData, | ||
}) | ||
|
||
export const setAppDataMethod = async ({ | ||
input, | ||
ctx, | ||
}: { | ||
input: z.infer<typeof SetAppDataInput> | ||
ctx: Context | ||
}) => { | ||
const accountUrn = ctx.accountURN as AccountURN | ||
const { clientId } = input | ||
|
||
if (!clientId) | ||
throw new BadRequestError({ | ||
message: 'missing client id', | ||
}) | ||
|
||
if (!AccountURNSpace.is(accountUrn)) | ||
throw new BadRequestError({ | ||
message: 'missing account', | ||
}) | ||
|
||
const name = `${AccountURNSpace.decode(accountUrn)}@${clientId}` | ||
const accessNode = await initAccessNodeByName(name, ctx.Access) | ||
|
||
await accessNode.storage.put<AppDataType>({ appData: input.appData }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters