Skip to content

Commit

Permalink
Merge branch 'staging' into fix-activity-designs
Browse files Browse the repository at this point in the history
  • Loading branch information
0xemc authored Jan 5, 2024
2 parents 8b9bbbf + f584419 commit cd57d04
Show file tree
Hide file tree
Showing 57 changed files with 708 additions and 340 deletions.
2 changes: 1 addition & 1 deletion app/locale/de/messages.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2024-01-03 17:48+0000\n"
"POT-Creation-Date: 2024-01-05 08:59+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion app/locale/en-pseudo/messages.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2024-01-03 17:48+0000\n"
"POT-Creation-Date: 2024-01-05 08:59+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion app/locale/es/messages.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2024-01-03 17:48+0000\n"
"POT-Creation-Date: 2024-01-05 08:59+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion app/locale/fr/messages.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2024-01-03 17:48+0000\n"
"POT-Creation-Date: 2024-01-05 08:59+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion app/locale/hi/messages.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2024-01-03 17:48+0000\n"
"POT-Creation-Date: 2024-01-05 08:59+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion app/locale/ko/messages.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2024-01-03 17:48+0000\n"
"POT-Creation-Date: 2024-01-05 08:59+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion app/locale/ru/messages.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2024-01-03 17:48+0000\n"
"POT-Creation-Date: 2024-01-05 08:59+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion app/locale/zh-CN/messages.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2024-01-03 17:48+0000\n"
"POT-Creation-Date: 2024-01-05 08:59+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
24 changes: 24 additions & 0 deletions carbon-projects/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# Project Data CMS

Single source of truth for Methodologies and Projects

# Deployment

When changes have been made to the schema, first build locally from inside this folder after running `npm install` for the top-level workspace of this repo:

```
npm run build
```

Assuming the build is successful, deploy the changes to Sanity Studio:

```
npm run deploy
```

Finally, update the Sanity GraphQL deployment:

```
npm run deploy-graphql
```

If there are breaking changes, the codegen also needs to be re-run for the main repo workspace, and any breaking schema changes need to be consumed in our gql fragments and queries here:
- https://github.com/KlimaDAO/klimadao/blob/staging/carbonmark-api/src/graphql/cms.fragments.gql
- https://github.com/KlimaDAO/klimadao/blob/staging/carbonmark-api/src/graphql/cms.gql
3 changes: 2 additions & 1 deletion carbon-projects/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import methodology from "./methodology";
import externalFile from "./objects/externalFile";
import project from "./project";
import projectContent from "./projectContent";
export const schemaTypes = [project, methodology, projectContent];
export const schemaTypes = [project, methodology, projectContent, externalFile];
1 change: 1 addition & 0 deletions carbon-projects/schemas/methodology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const categories = [
{ title: "Industrial Processing", value: "Industrial Processing" },
{ title: "Renewable Energy", value: "Renewable Energy" },
{ title: "Blue Carbon", value: "Blue Carbon" },
{ title: "Agriculture", value: "Agriculture" },
{ title: "Other", value: "Other" },
];

Expand Down
30 changes: 30 additions & 0 deletions carbon-projects/schemas/objects/externalFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { defineType } from "sanity";

export default defineType({
name: "externalFile",
type: "object",
title: "External file",
fields: [
{
type: "string",
title: "File name",
name: "filename",
},
{
type: "url",
title: "URI",
name: "uri",
validation: (Rule) => [Rule.required()],
},
{
type: "string",
title: "Description or Caption",
name: "description",
},
{
type: "string",
title: "MIME Type",
name: "mimetype",
},
],
});
55 changes: 37 additions & 18 deletions carbon-projects/schemas/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ const ccbs = [
{ title: "CCB Community Gold", value: "CCB-Community Gold" },
];

const subcategories = [
{ title: "Solar Energy", value: "solar" },
{ title: "Wind Energy", value: "wind" },
{ title: "Hydroelectric Energy", value: "hydro" },
{ title: "Improved Forest Management (IFM)", value: "ifm" },
{ title: "Avoided Deforestation", value: "redd" },
{ title: "Afforestation", value: "afforestation" },
{ title: "Mangrove Restoration", value: "mangroves" },
];

export default defineType({
name: "project",
title: "Project",
Expand Down Expand Up @@ -83,6 +93,7 @@ export default defineType({
{ title: "Verra", value: "VCS" },
{ title: "Gold Standard", value: "GS" },
{ title: "EcoRegistry", value: "ECO" },
{ title: "International Carbon Registry", value: "ICR" },
],
},
validation: (r) => r.required(),
Expand Down Expand Up @@ -148,6 +159,14 @@ export default defineType({
},
],
}),
defineField({
name: "subcategory",
description: "From our predefined ontology of subcategories",
type: "string",
options: {
list: subcategories,
},
}),
{
name: "region",
description: "Region where the project was implemented",
Expand Down Expand Up @@ -214,30 +233,30 @@ export default defineType({
}),
defineField({
name: "url",
description: "Project website or resource url, if exists",
description:
"Project's website or resource url on the registry, if exists",
group: "media",
type: "url",
}),
defineField({
name: "projectWebsite",
description: "External project website, if exists",
group: "media",
type: "url",
}),
defineField({
name: "documents",
description: "Other PDF documents associated with this project",
name: "externalMedia",
description: "Arrays of external media URIs and associated captions",
group: "media",
type: "array",
of: [
{
type: "file",
options: {
accept: ".pdf",
},
fields: [
{
name: "description",
description: "Description of the file",
type: "string",
},
],
},
],
of: [{ type: "externalFile" }],
}),
defineField({
name: "externalDocuments",
description: "External PDF documents associated with this project",
group: "media",
type: "array",
of: [{ type: "externalFile" }],
}),
],
});
2 changes: 1 addition & 1 deletion carbon/locale/de/messages.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2024-01-03 17:49+0000\n"
"POT-Creation-Date: 2024-01-05 08:59+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion carbon/locale/en-pseudo/messages.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2024-01-03 17:49+0000\n"
"POT-Creation-Date: 2024-01-05 08:59+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion carbon/locale/es/messages.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2024-01-03 17:49+0000\n"
"POT-Creation-Date: 2024-01-05 08:59+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion carbon/locale/fr/messages.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2024-01-03 17:49+0000\n"
"POT-Creation-Date: 2024-01-05 08:59+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion carbon/locale/hi/messages.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2024-01-03 17:49+0000\n"
"POT-Creation-Date: 2024-01-05 08:59+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion carbon/locale/ko/messages.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2024-01-03 17:49+0000\n"
"POT-Creation-Date: 2024-01-05 08:59+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion carbon/locale/ru/messages.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2024-01-03 17:49+0000\n"
"POT-Creation-Date: 2024-01-05 08:59+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion carbon/locale/zh-CN/messages.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2024-01-03 17:49+0000\n"
"POT-Creation-Date: 2024-01-05 08:59+0000\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
2 changes: 1 addition & 1 deletion carbonmark-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@klimadao/carbonmark-api",
"version": "4.1.1",
"version": "4.1.3",
"description": "An API for exploring Carbonmark project data, prices and activity.",
"main": "app.ts",
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion carbonmark-api/src/app.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const GRAPH_API_ROOT_ID = "https://api.thegraph.com/subgraphs/id";
const POLYGON_URLS = {
marketplace: `${GRAPH_API_ROOT_ID}/QmTfM5TvokuyKXCGWL3wTLZ1z4TqRtQ7PdVfQRVU39ovUC`,
assets: `${GRAPH_API_ROOT}/cujowolf/klima-refi-current-holdings`,
offsets: `${GRAPH_API_ROOT}/klimadao/polygon-bridged-carbon`,
tokens: `${GRAPH_API_ROOT}/klimadao/klimadao-pairs`,
digitalCarbon: `${GRAPH_API_ROOT}/klimadao/polygon-digital-carbon`,
};
Expand Down
7 changes: 5 additions & 2 deletions carbonmark-api/src/plugins/caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import fp from "fastify-plugin";
* @see https://github.com/denbon05/fastify-lcache
*/
export default fp(async function (fastify) {
await fastify.register(fastifyCaching, { ttlInMinutes: 1 });
//We need to disable caching in testing to allow proper mocking
if (process.env.NODE_ENV !== "test") {
await fastify.register(fastifyCaching, { ttlInMinutes: 1 });
}
});

declare module "fastify" {
export interface FastifyInstance {
lcache: ILcacheStorage;
lcache: ILcacheStorage | null;
}
}

Expand Down
4 changes: 3 additions & 1 deletion carbonmark-api/src/plugins/rate-limit.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import rateLimiter from "@fastify/rate-limit";
import fp from "fastify-plugin";

export const LIMIT = 100;

/**
* This plugin adds rate limiting functionality to Fastify.
* @see https://github.com/fastify/rate-limit
*/
export default fp(async function (fastify) {
await fastify.register(rateLimiter, {
max: 100,
max: LIMIT,
timeWindow: "1 minute",
});
});
2 changes: 1 addition & 1 deletion carbonmark-api/src/routes/projects/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ const handler = (fastify: FastifyInstance) =>
marketplaceProjectData: project,
});
});

/** Compose all the data together to unique entries (unsorted) */
const entries = composeProjectEntries(ProjectMap, CMSDataMap, poolPrices);

const sortedEntries = sortBy(entries, (e) => Number(e.price));
// Send the transformed projects array as a JSON string in the response
return reply
Expand Down
4 changes: 2 additions & 2 deletions carbonmark-api/src/routes/projects/get.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ export const composeProjectEntries = (
/** If there are no prices hide this project */
const price = pickBestPrice(data, poolPrices);
if (!price) return;

// construct CarbonmarkProjectT and make typescript happy
const entry: Project = {
//Remove string padding on methodologies
Expand All @@ -276,7 +275,8 @@ export const composeProjectEntries = (
name: carbonProject?.name || poolBalances?.name || "",
location: toGeoJSON(carbonProject?.geolocation),
country: {
id: carbonProject?.country || poolBalances?.country || "",
id:
carbonProject?.country?.trim() || poolBalances?.country.trim() || "",
},
images: carbonProject?.content?.images?.map((img) => ({
url: img?.asset?.url ?? "",
Expand Down
6 changes: 3 additions & 3 deletions carbonmark-api/src/utils/CreditId.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { includes } from "lodash";
import { notNil } from "./functional.utils";

const standards = ["VCS", "PURO", "ICR"] as const;

Expand Down Expand Up @@ -101,11 +102,10 @@ export class CreditId {
private static isValidParams(params: unknown): params is UntypedParams {
if (!params || typeof params !== "object") return false;
const typedParams = params as Partial<UntypedParams>;
/* eslint-enable @typescript-eslint/consistent-type-assertions -- type guards */
return (
includes(standards, typedParams.standard?.toUpperCase()) &&
!!Number(typedParams.registryProjectId) &&
!!Number(typedParams.vintage)
notNil(Number(typedParams.registryProjectId)) &&
notNil(Number(typedParams.vintage))
);
}
}
Loading

0 comments on commit cd57d04

Please sign in to comment.