var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { Util } from '../../../util/util';
export class Node {
    constructor() {
        this.dataRelationships = {};
        this._headers = {
            'Accept': 'application/vnd.api+json',
            'Content-Type': 'application/vnd.api+json'
        };
        this._nodeTemplate = {
            data: {
                type: "node--page",
                attributes: {
                    "title": "new: node--page",
                    // "langcode": "en",
                    // "status": true,
                    // "promote": false,
                    // "sticky": false,
                    // "default_langcode": true,
                    "body": {
                        "value": "new: node--page: body",
                    }
                }
            }
        };
    }
    _createNode(nodeObject = this._nodeTemplate) {
        let node = Util.copy(this._nodeTemplate);
        node = Util.deepAssign(node, nodeObject);
        console.log(node);
        return node;
    }
    _json() {
        return JSON.stringify(this.data);
    }
    _fetchResource(url, params = undefined) {
        return __awaiter(this, void 0, void 0, function* () {
            if (params) {
                url += '?';
                Object.keys(params).forEach(key => url += key + '=' + params[key] + '&');
            }
            let resource = yield fetch(url, { headers: this._headers })
                .then((response) => {
                if (response.status >= 400) {
                    throw new Error('Bad response from server');
                }
                return response.json();
            })
                .then((data) => {
                return data;
            });
            return resource;
        });
    }
}
//# sourceMappingURL=node.js.map