@@ -129,6 +129,57 @@ export function getReadTheDocsConfig(sendUrlParam) {
129
129
} ) ;
130
130
}
131
131
132
+ export async function getReadTheDocsConfigUsingAPIv3 ( sendUrlParam ) {
133
+ // TODO: get the project/version slug from the META tags
134
+ const projectResponse = fetch ( "/_/api/v3/projects/test-builds/" ) ;
135
+ const translationsResponse = fetch (
136
+ "/_/api/v3/projects/test-builds/translations/" ,
137
+ ) ;
138
+ const versionResponse = fetch (
139
+ "/_/api/v3/projects/test-builds/versions/full-feature/" ,
140
+ ) ;
141
+ const activeVersionsResponse = fetch (
142
+ "/_/api/v3/projects/test-builds/versions/?active=true" ,
143
+ ) ;
144
+ const buildResponse = fetch ( "/_/api/v3/projects/test-builds/builds/3111/" ) ;
145
+
146
+ const responses = await Promise . all ( [
147
+ projectResponse ,
148
+ translationsResponse ,
149
+ versionResponse ,
150
+ activeVersionsResponse ,
151
+ buildResponse ,
152
+ ] ) ;
153
+
154
+ const [ project , translations , version , activeVersions , build ] =
155
+ await Promise . all ( responses . map ( ( response ) => response . json ( ) ) ) ;
156
+
157
+ // TODO: we are missing the data from the `/_/addons/` endpoint that are not resources.
158
+ // We need to perform another request for that.
159
+ const dataEvent = {
160
+ builds : {
161
+ current : build ,
162
+ } ,
163
+ projects : {
164
+ current : project ,
165
+ translations : translations . results ,
166
+ } ,
167
+ versions : {
168
+ active : activeVersions . results ,
169
+ current : version ,
170
+ } ,
171
+ } ;
172
+
173
+ // Trigger the addons data ready CustomEvent to with the data the user is expecting.
174
+ dispatchEvent (
175
+ EVENT_READTHEDOCS_ADDONS_DATA_READY ,
176
+ document ,
177
+ new ReadTheDocsEventData ( dataEvent ) ,
178
+ ) ;
179
+
180
+ return dataEvent ;
181
+ }
182
+
132
183
function dispatchEvent ( eventName , element , data ) {
133
184
const event = new CustomEvent ( eventName , { detail : data } ) ;
134
185
element . dispatchEvent ( event ) ;
0 commit comments