Skip to content

Commit dec421b

Browse files
authored
feat(environmental_footprint): enable v1alpha1 (scaleway#2441)
1 parent de42af9 commit dec421b

File tree

12 files changed

+574
-0
lines changed

12 files changed

+574
-0
lines changed

packages/sdk/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@scaleway/sdk-dedibox": "workspace:*",
4646
"@scaleway/sdk-domain": "workspace:*",
4747
"@scaleway/sdk-edge-services": "workspace:*",
48+
"@scaleway/sdk-environmental-footprint": "workspace:*",
4849
"@scaleway/sdk-file": "workspace:*",
4950
"@scaleway/sdk-flexibleip": "workspace:*",
5051
"@scaleway/sdk-function": "workspace:*",

packages/sdk/src/index.gen.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Datawarehousev1beta1 } from '@scaleway/sdk-datawarehouse'
1515
import { Dediboxv1 } from '@scaleway/sdk-dedibox'
1616
import { Domainv2beta1 } from '@scaleway/sdk-domain'
1717
import { EdgeServicesv1beta1 } from '@scaleway/sdk-edge-services'
18+
import { EnvironmentalFootprintv1alpha1 } from '@scaleway/sdk-environmental-footprint'
1819
import { Filev1alpha1 } from '@scaleway/sdk-file'
1920
import { Flexibleipv1alpha1 } from '@scaleway/sdk-flexibleip'
2021
import { Functionv1beta1 } from '@scaleway/sdk-function'
@@ -153,6 +154,14 @@ export const EdgeServices = {
153154
v1beta1: EdgeServicesv1beta1,
154155
}
155156

157+
/**
158+
* @deprecated Direct version exports are deprecated. Use the 'EnvironmentalFootprint' namespace instead (e.g., EnvironmentalFootprint.v1).
159+
*/
160+
export { EnvironmentalFootprintv1alpha1 }
161+
export const EnvironmentalFootprint = {
162+
v1alpha1: EnvironmentalFootprintv1alpha1,
163+
}
164+
156165
/**
157166
* @deprecated Direct version exports are deprecated. Use the 'File' namespace instead (e.g., File.v1).
158167
*/
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "@scaleway/sdk-environmental-footprint",
3+
"version": "1.0.0",
4+
"description": "Scaleway SDK environmental-footprint",
5+
"license": "Apache-2.0",
6+
"files": [
7+
"dist"
8+
],
9+
"type": "module",
10+
"exports": {
11+
".": {
12+
"types": "./dist/index.gen.d.ts",
13+
"import": "./dist/index.gen.js",
14+
"require": "./dist/index.gen.cjs",
15+
"default": "./dist/index.gen.js"
16+
},
17+
"./*": {
18+
"types": "./dist/*/index.gen.d.ts",
19+
"import": "./dist/*/index.gen.js",
20+
"require": "./dist/*/index.gen.cjs",
21+
"default": "./dist/*/index.gen.js"
22+
}
23+
},
24+
"repository": {
25+
"type": "git",
26+
"directory": "packages_generated/environmental-footprint"
27+
},
28+
"engines": {
29+
"node": ">=20.18.3"
30+
},
31+
"scripts": {
32+
"package:check": "pnpm publint",
33+
"typecheck": "tsc --noEmit",
34+
"type:generate": "tsc --declaration -p tsconfig.build.json",
35+
"build": "vite build --config vite.config.ts && pnpm run type:generate",
36+
"build:profile": "npx vite-bundle-visualizer -c vite.config.ts"
37+
},
38+
"dependencies": {
39+
"@scaleway/sdk-std": "workspace:*",
40+
"@scaleway/random-name": "5.1.1"
41+
},
42+
"peerDependencies": {
43+
"@scaleway/sdk-client": "workspace:^"
44+
},
45+
"devDependencies": {
46+
"@scaleway/sdk-client": "workspace:^"
47+
}
48+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* This file is automatically generated
3+
* PLEASE DO NOT EDIT HERE
4+
*/
5+
6+
export * as EnvironmentalFootprintv1alpha1 from './v1alpha1/index.gen'
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
import { API as ParentAPI, urlParams } from '@scaleway/sdk-client'
4+
import {
5+
marshalUserApiDownloadImpactReportRequest,
6+
unmarshalImpactDataResponse,
7+
unmarshalImpactReportAvailability,
8+
} from './marshalling.gen'
9+
import type {
10+
ImpactDataResponse,
11+
ImpactReportAvailability,
12+
UserApiDownloadImpactReportRequest,
13+
UserApiGetImpactDataRequest,
14+
UserApiGetImpactReportAvailabilityRequest,
15+
} from './types.gen'
16+
17+
const jsonContentHeaders = {
18+
'Content-Type': 'application/json; charset=utf-8',
19+
}
20+
21+
/**
22+
* Environmental Footprint API.
23+
24+
Access and download impact reports and impact data for your Scaleway projects. Our API provides key metrics such as estimated carbon emissions and water usage to help monitor your environmental footprint.
25+
*/
26+
export class UserAPI extends ParentAPI {
27+
/**
28+
* Get available impact reports. Returns a list of dates of available impact reports.
29+
*
30+
* @param request - The request {@link UserApiGetImpactReportAvailabilityRequest}
31+
* @returns A Promise of ImpactReportAvailability
32+
*/
33+
getImpactReportAvailability = (
34+
request: Readonly<UserApiGetImpactReportAvailabilityRequest> = {},
35+
) =>
36+
this.client.fetch<ImpactReportAvailability>(
37+
{
38+
method: 'GET',
39+
path: `/environmental-footprint/v1alpha1/reports/availability`,
40+
urlParams: urlParams(
41+
['end_date', request.endDate],
42+
[
43+
'organization_id',
44+
request.organizationId ??
45+
this.client.settings.defaultOrganizationId,
46+
],
47+
['start_date', request.startDate],
48+
),
49+
},
50+
unmarshalImpactReportAvailability,
51+
)
52+
53+
/**
54+
* Download PDF impact report. Download a Scaleway impact PDF report with detailed impact data for your Scaleway projects.
55+
*
56+
* @param request - The request {@link UserApiDownloadImpactReportRequest}
57+
* @returns A Promise of Blob
58+
*/
59+
downloadImpactReport = (
60+
request: Readonly<UserApiDownloadImpactReportRequest> = {},
61+
) =>
62+
this.client.fetch<Blob>({
63+
body: JSON.stringify(
64+
marshalUserApiDownloadImpactReportRequest(
65+
request,
66+
this.client.settings,
67+
),
68+
),
69+
headers: jsonContentHeaders,
70+
method: 'POST',
71+
path: `/environmental-footprint/v1alpha1/reports/download`,
72+
urlParams: urlParams(
73+
['dl', 1],
74+
['date', request.date],
75+
[
76+
'organization_id',
77+
request.organizationId ?? this.client.settings.defaultOrganizationId,
78+
],
79+
['type', request.type],
80+
),
81+
responseType: 'blob',
82+
})
83+
84+
/**
85+
* Retrieve detailed impact data. Retrieve detailed impact data for your Scaleway projects within a specified date range. Filter by project ID, region, zone, service category, and/or product category.
86+
*
87+
* @param request - The request {@link UserApiGetImpactDataRequest}
88+
* @returns A Promise of ImpactDataResponse
89+
*/
90+
getImpactData = (request: Readonly<UserApiGetImpactDataRequest> = {}) =>
91+
this.client.fetch<ImpactDataResponse>(
92+
{
93+
method: 'GET',
94+
path: `/environmental-footprint/v1alpha1/data/query`,
95+
urlParams: urlParams(
96+
['end_date', request.endDate],
97+
[
98+
'organization_id',
99+
request.organizationId ??
100+
this.client.settings.defaultOrganizationId,
101+
],
102+
['product_categories', request.productCategories],
103+
['project_ids', request.projectIds],
104+
['regions', request.regions],
105+
['service_categories', request.serviceCategories],
106+
['start_date', request.startDate],
107+
['zones', request.zones],
108+
),
109+
},
110+
unmarshalImpactDataResponse,
111+
)
112+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
export { UserAPI } from './api.gen'
4+
export * from './marshalling.gen'
5+
export type {
6+
Impact,
7+
ImpactDataResponse,
8+
ImpactReportAvailability,
9+
ProductCategory,
10+
ProjectImpact,
11+
RegionImpact,
12+
ReportType,
13+
ServiceCategory,
14+
SkuImpact,
15+
UserApiDownloadImpactReportRequest,
16+
UserApiGetImpactDataRequest,
17+
UserApiGetImpactReportAvailabilityRequest,
18+
ZoneImpact,
19+
} from './types.gen'
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
4+
import type { DefaultValues } from '@scaleway/sdk-client'
5+
import {
6+
isJSONObject,
7+
unmarshalArrayOfObject,
8+
unmarshalDate,
9+
} from '@scaleway/sdk-client'
10+
import type {
11+
Impact,
12+
ImpactDataResponse,
13+
ImpactReportAvailability,
14+
ProjectImpact,
15+
RegionImpact,
16+
SkuImpact,
17+
UserApiDownloadImpactReportRequest,
18+
ZoneImpact,
19+
} from './types.gen'
20+
21+
const unmarshalImpact = (data: unknown): Impact => {
22+
if (!isJSONObject(data)) {
23+
throw new TypeError(
24+
`Unmarshalling the type 'Impact' failed as data isn't a dictionary.`,
25+
)
26+
}
27+
28+
return {
29+
kgCo2Equivalent: data.kg_co2_equivalent,
30+
m3WaterUsage: data.m3_water_usage,
31+
} as Impact
32+
}
33+
34+
const unmarshalSkuImpact = (data: unknown): SkuImpact => {
35+
if (!isJSONObject(data)) {
36+
throw new TypeError(
37+
`Unmarshalling the type 'SkuImpact' failed as data isn't a dictionary.`,
38+
)
39+
}
40+
41+
return {
42+
productCategory: data.product_category,
43+
serviceCategory: data.service_category,
44+
sku: data.sku,
45+
totalSkuImpact: data.total_sku_impact
46+
? unmarshalImpact(data.total_sku_impact)
47+
: undefined,
48+
} as SkuImpact
49+
}
50+
51+
const unmarshalZoneImpact = (data: unknown): ZoneImpact => {
52+
if (!isJSONObject(data)) {
53+
throw new TypeError(
54+
`Unmarshalling the type 'ZoneImpact' failed as data isn't a dictionary.`,
55+
)
56+
}
57+
58+
return {
59+
skus: unmarshalArrayOfObject(data.skus, unmarshalSkuImpact),
60+
totalZoneImpact: data.total_zone_impact
61+
? unmarshalImpact(data.total_zone_impact)
62+
: undefined,
63+
zone: data.zone,
64+
} as ZoneImpact
65+
}
66+
67+
const unmarshalRegionImpact = (data: unknown): RegionImpact => {
68+
if (!isJSONObject(data)) {
69+
throw new TypeError(
70+
`Unmarshalling the type 'RegionImpact' failed as data isn't a dictionary.`,
71+
)
72+
}
73+
74+
return {
75+
region: data.region,
76+
totalRegionImpact: data.total_region_impact
77+
? unmarshalImpact(data.total_region_impact)
78+
: undefined,
79+
zones: unmarshalArrayOfObject(data.zones, unmarshalZoneImpact),
80+
} as RegionImpact
81+
}
82+
83+
const unmarshalProjectImpact = (data: unknown): ProjectImpact => {
84+
if (!isJSONObject(data)) {
85+
throw new TypeError(
86+
`Unmarshalling the type 'ProjectImpact' failed as data isn't a dictionary.`,
87+
)
88+
}
89+
90+
return {
91+
projectId: data.project_id,
92+
regions: unmarshalArrayOfObject(data.regions, unmarshalRegionImpact),
93+
totalProjectImpact: data.total_project_impact
94+
? unmarshalImpact(data.total_project_impact)
95+
: undefined,
96+
} as ProjectImpact
97+
}
98+
99+
export const unmarshalImpactDataResponse = (
100+
data: unknown,
101+
): ImpactDataResponse => {
102+
if (!isJSONObject(data)) {
103+
throw new TypeError(
104+
`Unmarshalling the type 'ImpactDataResponse' failed as data isn't a dictionary.`,
105+
)
106+
}
107+
108+
return {
109+
endDate: unmarshalDate(data.end_date),
110+
projects: unmarshalArrayOfObject(data.projects, unmarshalProjectImpact),
111+
startDate: unmarshalDate(data.start_date),
112+
totalImpact: data.total_impact
113+
? unmarshalImpact(data.total_impact)
114+
: undefined,
115+
} as ImpactDataResponse
116+
}
117+
118+
export const unmarshalImpactReportAvailability = (
119+
data: unknown,
120+
): ImpactReportAvailability => {
121+
if (!isJSONObject(data)) {
122+
throw new TypeError(
123+
`Unmarshalling the type 'ImpactReportAvailability' failed as data isn't a dictionary.`,
124+
)
125+
}
126+
127+
return {
128+
monthSummaryReports: unmarshalArrayOfObject(
129+
data.month_summary_reports,
130+
unmarshalDate,
131+
),
132+
} as ImpactReportAvailability
133+
}
134+
135+
export const marshalUserApiDownloadImpactReportRequest = (
136+
request: UserApiDownloadImpactReportRequest,
137+
defaults: DefaultValues,
138+
): Record<string, unknown> => ({
139+
date: request.date,
140+
organization_id: request.organizationId ?? defaults.defaultOrganizationId,
141+
type: request.type,
142+
})

0 commit comments

Comments
 (0)