Skip to content

Instantly share code, notes, and snippets.

@Aaronius
Created January 28, 2021 17:10
Show Gist options
  • Save Aaronius/91a0ec99379d1213ba04e22963628974 to your computer and use it in GitHub Desktop.
Save Aaronius/91a0ec99379d1213ba04e22963628974 to your computer and use it in GitHub Desktop.
Blackbird Mini SDK (WIP)
/*
Copyright 2021 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
import fetch from 'node-fetch';
const baseUrl = 'https://edge.adobe.io/configs/user/edge';
class Blackbird {
constructor(accessToken, imsOrgId) {
this._headers = {
'x-gw-ims-org-id': `${imsOrgId}`,
authorization: `Bearer ${accessToken}`,
'content-type': 'application/json',
'x-api-key': 'Activation-DTM'
};
}
async _request(url, method, body) {
const response = await fetch(url, {
method: 'POST',
headers: this._headers,
body: JSON.stringify(body)
});
if (!response.ok) {
let responseBody = '';
try {
responseBody = await response.text();
} catch (e) {}
console.log(response);
throw new Error(`${response.status} ${response.statusText}: ${responseBody}`);
}
return await response.json();
}
createConfig(data) {
return this._request(baseUrl, 'POST', data);
}
createEnvironment(configId, data) {
return this._request(`${baseUrl}/${configId}/environments/`, 'POST', data);
}
}
export default Blackbird;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment