-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #755 from digitalfabrik/pre-release
Prerelease
- Loading branch information
Showing
22 changed files
with
419 additions
and
271 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 was deleted.
Oops, something went wrong.
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,40 @@ | ||
import { DynamicActivationCode, StaticVerificationCode } from '../generated/card_pb' | ||
import { | ||
AddCardsDocument, | ||
AddCardsMutation, | ||
AddCardsMutationVariables, | ||
CardGenerationModelInput, | ||
CodeType, | ||
Region, | ||
} from '../generated/graphql' | ||
import hashCardInfo from './hashCardInfo' | ||
import { ApolloClient } from '@apollo/client' | ||
import { uint8ArrayToBase64 } from '../util/base64' | ||
|
||
type Codes = (DynamicActivationCode | StaticVerificationCode)[] | ||
|
||
export async function createCards(client: ApolloClient<object>, activationCodes: Codes, region: Region) { | ||
const cards: CardGenerationModelInput[] = await Promise.all( | ||
activationCodes.map(async code => { | ||
const codeType = code instanceof DynamicActivationCode ? CodeType.Dynamic : CodeType.Static | ||
const cardInfoHash = await hashCardInfo(code.info!, code.pepper) | ||
const expirationDay = code.info!.expirationDay | ||
const activationSecretBase64 = | ||
code instanceof DynamicActivationCode ? uint8ArrayToBase64(code.activationSecret) : null | ||
return { | ||
cardExpirationDay: expirationDay ?? null, // JS number can represent integers up to 2^53, so it can represent all values of an uint32 (protobuf) | ||
cardInfoHashBase64: uint8ArrayToBase64(cardInfoHash), | ||
activationSecretBase64: activationSecretBase64, | ||
regionId: region.id, | ||
codeType, | ||
} | ||
}) | ||
) | ||
const result = await client.mutate<AddCardsMutation, AddCardsMutationVariables>({ | ||
mutation: AddCardsDocument, | ||
variables: { cards }, | ||
}) | ||
if (!result.data?.success) { | ||
throw Error(JSON.stringify(result)) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
mutation addCard($card: CardGenerationModelInput!) { | ||
success: addCard(card: $card) | ||
mutation addCards($cards: [CardGenerationModelInput!]!) { | ||
success: addCards(cards: $cards) | ||
} |
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
Oops, something went wrong.