UNPKG

@eclipse-ditto/ditto-javascript-client-node

Version:

Node.js(r) implementation of Eclipse Ditto JavaScript API.

346 lines 12.7 kB
"use strict"; /*! * Copyright (c) 2019 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0 * * SPDX-License-Identifier: EPL-2.0 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.DefaultPoliciesHandle = void 0; const policies_model_1 = require("../../model/policies.model"); const http_verb_1 = require("../constants/http-verb"); /** * Handle to send Policies requests. */ class DefaultPoliciesHandle { constructor(requestFactory) { this.requestFactory = requestFactory; } /** * returns an instance of PoliciesHandle using the provided RequestSender. * * @param builder - The builder for the RequestSender to work with. * @returns The PoliciesHandle */ static getInstance(builder) { return new DefaultPoliciesHandle(builder.buildInstance('policies')); } /** * Gets a Policy. * * @param policyId - The ID of the Policy to get. * @param options - Options to use for the request. * @returns A Promise for the Policy */ getPolicy(policyId, options) { return this.requestFactory.fetchJsonRequest({ verb: http_verb_1.HttpVerb.GET, parser: o => policies_model_1.Policy.fromObject(o, policyId), id: policyId, requestOptions: options }); } /** * Gets the Entries of a Policy. * * @param policyId - The ID of the Policy. * @param options - Options to use for the request. * @returns A Promise for the Entries */ getEntries(policyId, options) { return this.requestFactory.fetchJsonRequest({ verb: http_verb_1.HttpVerb.GET, parser: policies_model_1.Entries.fromObject, id: policyId, path: 'entries', requestOptions: options }); } /** * Gets an Entry of a Policy. * * @param policyId - The ID of the Policy. * @param label - The label of the Entry to get. * @param options - Options to use for the request. * @returns A Promise for the Entry */ getEntry(policyId, label, options) { return this.requestFactory.fetchJsonRequest({ verb: http_verb_1.HttpVerb.GET, parser: o => policies_model_1.Entry.fromObject(o, label), id: policyId, path: `entries/${label}`, requestOptions: options }); } /** * Gets the Subjects of an Entry. * * @param policyId - The ID of the Policy the Entry belongs to. * @param label - The label of the Entry. * @param options - Options to use for the request. * @returns A Promise for the Subjects */ getSubjects(policyId, label, options) { return this.requestFactory.fetchJsonRequest({ verb: http_verb_1.HttpVerb.GET, parser: policies_model_1.Subjects.fromObject, id: policyId, path: `entries/${label}/subjects`, requestOptions: options }); } /** * Gets a Subject of an Entry. * * @param policyId - The ID of the Policy the Entry belongs to. * @param label - The label of the Entry. * @param subjectId - The ID of the Subject to get. * @param options - Options to use for the request. * @returns A Promise for the Subject */ getSubject(policyId, label, subjectId, options) { return this.requestFactory.fetchJsonRequest({ verb: http_verb_1.HttpVerb.GET, parser: o => policies_model_1.Subject.fromObject(o, subjectId), id: policyId, path: `entries/${label}/subjects/${subjectId}`, requestOptions: options }); } /** * Gets the Resources of an Entry. * * @param policyId - The ID of the Policy the Entry belongs to. * @param label - The label of the Entry. * @param options - Options to use for the request. * @returns A Promise for the Resources */ getResources(policyId, label, options) { return this.requestFactory.fetchJsonRequest({ verb: http_verb_1.HttpVerb.GET, parser: policies_model_1.Resources.fromObject, id: policyId, path: `entries/${label}/resources`, requestOptions: options }); } /** * Gets a Resource of an Entry. * * @param policyId - The ID of the Policy the Entry belongs to. * @param label - The label of the Entry. * @param resourcePath - The path to the Resource. * @param options - Options to use for the request. * @returns A Promise for the Resource */ getResource(policyId, label, resourcePath, options) { return this.requestFactory.fetchJsonRequest({ verb: http_verb_1.HttpVerb.GET, parser: o => policies_model_1.Resource.fromObject(o, resourcePath), id: policyId, path: `entries/${label}/resources/${resourcePath}`, requestOptions: options }); } /** * Adds or updates a Policy. * * @param policy - The new Policy. * @param options - Options to use for the request. * @returns A Promise for a response containing the new Policy if provided by the response */ putPolicy(policy, options) { return this.requestFactory.fetchPutRequest({ verb: http_verb_1.HttpVerb.PUT, parser: o => policies_model_1.Policy.fromObject(o, policy.id), id: policy.id, requestOptions: options, payload: policy.toObject() }); } /** * Adds or updates the Entries of a Policy. * * @param policyId - The ID of the Policy. * @param entries - The new Entries. * @param options - Options to use for the request. * @returns A Promise a response containing the new Entries if provided by the response */ putEntries(policyId, entries, options) { return this.requestFactory.fetchPutRequest({ verb: http_verb_1.HttpVerb.PUT, parser: policies_model_1.Entries.fromObject, id: policyId, path: 'entries', requestOptions: options, payload: policies_model_1.Entries.toObject(entries) }); } /** * Adds or updates an Entry of a Policy. * * @param policyId - The ID of the Policy. * @param entry - The new Entry. * @param options - Options to use for the request. * @returns A Promise for a response containing the new Entry if provided by the response */ putEntry(policyId, entry, options) { return this.requestFactory.fetchPutRequest({ verb: http_verb_1.HttpVerb.PUT, parser: o => policies_model_1.Entry.fromObject(o, entry.id), id: policyId, path: `entries/${entry.id}`, requestOptions: options, payload: entry.toObject() }); } /** * Adds or updates the Subjects of an Entry. * * @param policyId - The ID of the Policy the Entry belongs to. * @param label - The label of the Entry. * @param subjects - The new Subjects. * @param options - Options to use for the request. * @returns A Promise for a response containing the new Subjects if provided by the response */ putSubjects(policyId, label, subjects, options) { return this.requestFactory.fetchPutRequest({ verb: http_verb_1.HttpVerb.PUT, parser: policies_model_1.Subjects.fromObject, id: policyId, path: `entries/${label}/subjects`, requestOptions: options, payload: policies_model_1.Subjects.toObject(subjects) }); } /** * Adds or updates a Subject of an Entry. * * @param policyId - The ID of the Policy the Entry belongs to. * @param label - The label of the Entry. * @param subject - The new Subject. * @param options - Options to use for the request. * @returns A Promise for a response containing the new Subject if provided by the response */ putSubject(policyId, label, subject, options) { return this.requestFactory.fetchPutRequest({ verb: http_verb_1.HttpVerb.PUT, parser: o => policies_model_1.Subject.fromObject(o, subject.id), id: policyId, path: `entries/${label}/subjects/${subject.id}`, requestOptions: options, payload: subject.toObject() }); } /** * Adds or updates the Resources of an Entry. * * @param policyId - The ID of the Policy the Entry belongs to. * @param label - The label of the Entry. * @param resources - The new Resources. * @param options - Options to use for the request. * @returns A Promise for a response containing the new Resources if provided by the response */ putResources(policyId, label, resources, options) { return this.requestFactory.fetchPutRequest({ verb: http_verb_1.HttpVerb.PUT, parser: policies_model_1.Resources.fromObject, id: policyId, path: `entries/${label}/resources`, requestOptions: options, payload: policies_model_1.Resources.toObject(resources) }); } /** * Adds or updates a Resource of an Entry. * * @param policyId - The ID of the Policy the Entry belongs to. * @param label - The label of the Entry. * @param resource - The new Resource. * @param options - Options to use for the request. * @returns A Promise for a response containing the new Resource if provided by the response */ putResource(policyId, label, resource, options) { return this.requestFactory.fetchPutRequest({ verb: http_verb_1.HttpVerb.PUT, parser: o => policies_model_1.Resource.fromObject(o, resource.id), id: policyId, path: `entries/${label}/resources/${resource.id}`, requestOptions: options, payload: resource.toObject() }); } /** * Deletes a Policy. * * @param policyId - The ID of the Policy to delete. * @param options - Options to use for the request. * @returns A Promise for the response */ deletePolicy(policyId, options) { return this.requestFactory.fetchRequest({ verb: http_verb_1.HttpVerb.DELETE, id: policyId, requestOptions: options }); } /** * Deletes an Entry of a Policy. * * @param policyId - The ID of the Policy. * @param label - The label of the Entry to delete. * @param options - Options to use for the request. * @returns A Promise for the response */ deleteEntry(policyId, label, options) { return this.requestFactory.fetchRequest({ verb: http_verb_1.HttpVerb.DELETE, id: policyId, path: `entries/${label}`, requestOptions: options }); } /** * Deletes a Subject of an Entry. * * @param policyId - The ID of the Policy the Entry belongs to. * @param label - The label of the Entry. * @param subjectId - The ID of the Subject to delete. * @param options - Options to use for the request. * @returns A Promise for the response */ deleteSubject(policyId, label, subjectId, options) { return this.requestFactory.fetchRequest({ verb: http_verb_1.HttpVerb.DELETE, id: policyId, path: `entries/${label}/subjects/${subjectId}`, requestOptions: options }); } /** * Deletes a Subject of an Entry. * * @param policyId - The ID of the Policy the Entry belongs to. * @param label - The label of the Entry. * @param resourcePath - The path to the Resource to delete. * @param options - Options to use for the request. * @returns A Promise for the response */ deleteResource(policyId, label, resourcePath, options) { return this.requestFactory.fetchRequest({ verb: http_verb_1.HttpVerb.DELETE, id: policyId, path: `entries/${label}/resources/${resourcePath}`, requestOptions: options }); } } exports.DefaultPoliciesHandle = DefaultPoliciesHandle; //# sourceMappingURL=policies.js.map