Skip to content

Commit

Permalink
Merge pull request #343 from desci-labs/develop
Browse files Browse the repository at this point in the history
promote main
  • Loading branch information
hubsmoke authored May 24, 2024
2 parents 727d044 + 684187c commit 7d875c6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 41 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/deploy-staging-services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env:
CONTAINER_IMAGE_REPO: desci-repo-server
CONTAINER_IMAGE_MEDIA: nodes-media-server
CONTAINER_IMAGE_ISOLATED: desci-media-isolated
CONTAINER_IMAGE_PROXY: "reverse-proxy"
DOCKER_BUILDKIT: 1

jobs:
Expand Down Expand Up @@ -294,23 +295,23 @@ jobs:
run: |
# Build and tag the image
docker build \
-t $CONTAINER_IMAGE-staging:latest \
-t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-staging \
./$CONTAINER_IMAGE
-t $CONTAINER_IMAGE_PROXY-staging:latest \
-t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE_PROXY-staging \
./$CONTAINER_IMAGE_PROXY
- name: Push (STAGING)
run: |
# Push image to AWS ECR
aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
docker tag $CONTAINER_IMAGE-staging:latest $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-staging:${{ github.sha }}
docker tag $CONTAINER_IMAGE-staging:latest $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-staging:latest
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-staging:${{ github.sha }}
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-staging:latest
docker tag $CONTAINER_IMAGE_PROXY-staging:latest $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE_PROXY-staging:${{ github.sha }}
docker tag $CONTAINER_IMAGE_PROXY-staging:latest $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE_PROXY-staging:latest
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE_PROXY-staging:${{ github.sha }}
docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE_PROXY-staging:latest
- name: Deploy to EKS (STAGING)
run: | # defaults to latest kubectl binary version
kubectl apply -f $CONTAINER_IMAGE/deployment.yaml
kubectl set image deployment/reverse-proxy-staging reverse-proxy-staging=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-staging:${{ github.sha }} --record
kubectl apply -f $CONTAINER_IMAGE_PROXY/deployment.yaml
kubectl set image deployment/reverse-proxy-staging reverse-proxy-staging=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE_PROXY-staging:${{ github.sha }} --record
- name: Verify EKS Deployment (STAGING)
run: |
Expand Down
64 changes: 52 additions & 12 deletions desci-server/src/services/orcid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,21 @@ class OrcidApiService {
userId: authToken.userId,
},
});
logger.info({ status: response.status, statusText: response.statusText, data }, 'REFRESH TOKEN RESPONSE');
logger.info(
{
status: response.status,
statusText: response.statusText,
data: {
name: data.name,
scope: data.scope,
token_type: data.token_type,
orcid: data.orcid,
refreshToken: !!data.refresh_token,
accessToken: !!data.access_token,
},
},
'REFRESH TOKEN RESPONSE',
);
} else {
logger.info(
{ status: response.status, statusText: response.statusText, BODY: await response.json() },
Expand Down Expand Up @@ -230,13 +244,15 @@ class OrcidApiService {

const latestVersion = researchObject.versions[researchObject.versions.length - 1];
const publicationDate = new Date(parseInt(latestVersion.time) * 1000).toLocaleDateString().replaceAll('/', '-');
const contributorsXml = generateContributors(latestManifest.authors ?? [], orcid);
const nodeRecordPromise = this.putNodeWorkRecord({
orcid,
authToken,
uuid: nodeUuid,
userId: user.id,
nodeVersion,
publicationDate,
contributorsXml,
userId: user.id,
manifest: latestManifest,
});
const claimRecordPromises = claims.map((claim) => {
Expand All @@ -250,6 +266,7 @@ class OrcidApiService {
publicationDate,
orcid,
authToken,
contributorsXml,
uuid: nodeUuid,
userId: user.id,
nodeVersion: claimedVersionNumber,
Expand Down Expand Up @@ -283,6 +300,7 @@ class OrcidApiService {
authToken,
orcid,
nodeVersion,
contributorsXml,
}: {
manifest: ResearchObjectV1;
publicationDate: string;
Expand All @@ -291,14 +309,15 @@ class OrcidApiService {
authToken: string;
orcid: string;
nodeVersion: number;
contributorsXml: string;
}) {
try {
const orcidPutCode = await prisma.orcidPutCodes.findUnique({
where: { orcid_uuid_reference: { orcid, uuid, reference: PutcodeReference.PREPRINT } },
});
const putCode = orcidPutCode?.putcode;

let data = generateNodeWorkRecord({ manifest, publicationDate, nodeVersion, putCode });
let data = generateNodeWorkRecord({ manifest, publicationDate, nodeVersion, putCode, contributorsXml });
data = data.replace(/\\"/g, '"');

const url = `${this.baseUrl}/${orcid}/work${putCode ? '/' + putCode : ''}`;
Expand Down Expand Up @@ -388,8 +407,10 @@ class OrcidApiService {
orcid,
claim,
nodeVersion,
contributorsXml,
}: {
claim: Claim;
contributorsXml: string;
manifest: ResearchObjectV1;
nodeVersion: number;
publicationDate: string;
Expand All @@ -410,7 +431,14 @@ class OrcidApiService {
});
const putCode = orcidPutCode?.putcode;

let data = generateClaimWorkRecord({ nodeVersion, manifest, publicationDate, claim, putCode });
let data = generateClaimWorkRecord({
nodeVersion,
manifest,
publicationDate,
claim,
putCode,
contributorsXml,
});
data = data.replace(/\\"/g, '"');

const url = `${this.baseUrl}/${orcid}/work${putCode ? '/' + putCode : ''}`;
Expand Down Expand Up @@ -500,9 +528,11 @@ const generateClaimWorkRecord = ({
claim,
nodeVersion,
publicationDate,
contributorsXml,
}: {
manifest: ResearchObjectV1;
claim: Claim;
contributorsXml: string;
putCode?: string;
nodeVersion: number;
publicationDate: string;
Expand All @@ -514,9 +544,9 @@ const generateClaimWorkRecord = ({
? 'data-set'
: 'preprint';

const description = `${claim.name} Attestation`;
const description = `${claim.name} availability verified`;
const [month, day, year] = publicationDate.split('-');
const externalUrl = `${DPID_URL_OVERRIDE}/${manifest.dpid.id}/attestation/${claim.id}`;
const externalUrl = `${DPID_URL_OVERRIDE}/${manifest.dpid.id}/v${nodeVersion}/attestation/${claim.id}`;
const dataRoot = `${DPID_URL_OVERRIDE}/${manifest.dpid.id}/v${nodeVersion}`;
logger.info({ codeAttr, workType, publicationDate, day, month, year, externalUrl }, 'CODE ATTR');
return (
Expand All @@ -525,7 +555,6 @@ const generateClaimWorkRecord = ({
'> ' +
'<work:title>' +
` <common:title>${manifest.title}</common:title>
<common:subtitle>${description}</common:subtitle>
</work:title>
<work:short-description>${description}</work:short-description>
<work:type>${workType}</work:type>
Expand All @@ -548,7 +577,8 @@ const generateClaimWorkRecord = ({
<common:external-id-relationship>part-of</common:external-id-relationship>
</common:external-id>
</common:external-ids>
${generateContributors(manifest.authors ?? [])}
<common:url>${externalUrl}</common:url>
${contributorsXml}
</work:work>
`
);
Expand All @@ -571,11 +601,13 @@ const generateNodeWorkRecord = ({
nodeVersion,
putCode,
publicationDate,
contributorsXml,
}: {
manifest: ResearchObjectV1;
nodeVersion: number;
putCode?: string;
publicationDate: string;
contributorsXml: string;
}): string => {
const codeAttr = putCode ? 'put-code="' + putCode + '"' : '';
const workType = 'preprint';
Expand All @@ -588,9 +620,7 @@ const generateNodeWorkRecord = ({
'> ' +
'<work:title>' +
` <common:title>${manifest.title}</common:title>
${manifest.description.trim() ? `<common:subtitle>${manifest.description.trim()}</common:subtitle>` : ``}
</work:title>
${manifest?.description?.trim() ? `<work:short-description>${manifest.description}</work:short-description>` : ``}
<work:type>${workType}</work:type>
<common:publication-date>
<common:year>${year}</common:year>
Expand All @@ -605,7 +635,8 @@ const generateNodeWorkRecord = ({
<common:external-id-relationship>self</common:external-id-relationship>
</common:external-id>
</common:external-ids>
${generateContributors(manifest.authors ?? [])}
<common:url>${dataRoot}</common:url>
${contributorsXml}
</work:work>
`
);
Expand All @@ -617,11 +648,20 @@ const generateNodeWorkRecord = ({
* @param authors[] - A list of ResearchObjectV1Author entries
* @returns {string} xml string of the constructed contributor data
*/
const generateContributors = (authors: ResearchObjectV1Author[]): string => {
const generateContributors = (authors: ResearchObjectV1Author[], ownerOrcid: string): string => {
authors.reverse();

const authorIndex = authors.findIndex((author) => author.orcid === ownerOrcid);
if (authorIndex !== -1 && authorIndex !== 0) {
const mainAuthor = authors.splice(authorIndex, 1);
authors.unshift(mainAuthor[0]);
}

const contributors =
authors?.length > 0
? `<work:contributors>
${authors
.filter((author) => !!author.name)
.map((author, idx) => {
return `<work:contributor>
${
Expand Down
4 changes: 1 addition & 3 deletions desci-server/src/templates/emails/BaseProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Tailwind } from '@react-email/components';
import React from 'react';

const BaseProvider = ({ children }: { children: JSX.Element }) => {
export const BaseProvider = ({ children }: { children: JSX.Element }) => {
return (
<Tailwind
config={{
Expand All @@ -19,5 +19,3 @@ const BaseProvider = ({ children }: { children: JSX.Element }) => {
</Tailwind>
);
};

export default BaseProvider;
6 changes: 1 addition & 5 deletions desci-server/src/templates/emails/MagicCode.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import {
Body,
Container,
Column,
Head,
Heading,
Html,
Preview,
Row,
Text,
Button,
Section,
render,
} from '@react-email/components';
import * as React from 'react';

Expand All @@ -29,7 +25,7 @@ export const MagicCodeEmail = ({ magicCode, ip }: MagicCodeEmailProps) => (
>
<Html>
<Head />
<Preview>Confirm your contribution</Preview>
<Preview>Confirm your identity</Preview>
<Body style={main}>
<Container style={container}>
<Heading style={h1} className="text-center !text-black">
Expand Down
20 changes: 8 additions & 12 deletions desci-server/src/templates/emails/MainLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
import { url } from 'inspector';

import {
Body,
Container,
Column,
Head,
Heading,
Html,
Img,
Link,
Preview,
Row,
Section,
Text,
Font,
} from '@react-email/components';
import React from 'react';
import { BaseProvider } from './BaseProvider.js';

import BaseProvider from './BaseProvider.js';

export const emailAssetsBaseUrl = 'https://ipfs.desci.com/ipfs';
const cubertBkg = 'bafkreih6yx7ywj7trvpp45vergrnytad7ezsku75tefyro4qrrcfrrmrt4';
const labsLogo = 'bafkreifvb7tleo5jaidjjf6lfjxb5bpjbs2nswp47bi7zh3hxbpc6fjyf4';
export const emailAssetsBaseUrl = 'https://pub.desci.com/ipfs';
// const cubertBkg = 'bafkreih6yx7ywj7trvpp45vergrnytad7ezsku75tefyro4qrrcfrrmrt4';
const labsLogo = 'bafkreie2jto3flk2r43yt545xrasftbsc2atp5eb7qcbsmhacm26k4wiz4';
const defaultFooterMsg = "If you didn't request this email, there's nothing to worry about, you can safely ignore it.";

const MainLayout = ({ children, footerMsg = defaultFooterMsg }: { children: JSX.Element; footerMsg?: string }) => {
Expand Down Expand Up @@ -55,11 +51,11 @@ const MainLayout = ({ children, footerMsg = defaultFooterMsg }: { children: JSX.
<Container className="backdrop-blur-2xl bg-opacity-50">
<Section className="h-full backdrop-blur-lg w-full" align="center">
<Img
src={`${emailAssetsBaseUrl}/${labsLogo}`}
src={ `${emailAssetsBaseUrl}/${labsLogo}` }
width="193"
height="60"
alt="Desci Labs"
className="m-auto invert"
className="m-auto invert mix-blend-difference"
/>
</Section>
<Section>{children}</Section>
Expand All @@ -70,11 +66,11 @@ const MainLayout = ({ children, footerMsg = defaultFooterMsg }: { children: JSX.
<Column className="">
<Link href="https://desci.com" target="_blank" rel="noopener noreferrer">
<Img
src={`${emailAssetsBaseUrl}/${labsLogo}`}
src={ `${emailAssetsBaseUrl}/${labsLogo}` }
width="135"
height="42"
alt="Desci Labs"
className="invert"
className="invert mix-blend-difference"
/>
</Link>
</Column>
Expand Down

0 comments on commit 7d875c6

Please sign in to comment.