casdoor-nodejs-sdk
Version:
Node.js client SDK for Casdoor
469 lines (468 loc) • 17 kB
JavaScript
"use strict";
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
//
// Licensed 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 CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.SDK = void 0;
const request_1 = require("./request");
const user_1 = require("./user");
const adapter_1 = require("./adapter");
const application_1 = require("./application");
const cert_1 = require("./cert");
const enforcer_1 = require("./enforcer");
const group_1 = require("./group");
const model_1 = require("./model");
const organization_1 = require("./organization");
const payment_1 = require("./payment");
const session_1 = require("./session");
const syncer_1 = require("./syncer");
const permission_1 = require("./permission");
const plan_1 = require("./plan");
const policy_1 = require("./policy");
const pricing_1 = require("./pricing");
const provider_1 = require("./provider");
const resource_1 = require("./resource");
const role_1 = require("./role");
const subscription_1 = require("./subscription");
const token_1 = require("./token");
const webhook_1 = require("./webhook");
const product_1 = require("./product");
const email_1 = require("./email");
const sms_1 = require("./sms");
const mfa_1 = require("./mfa");
const enforce_1 = require("./enforce");
const url_1 = require("./url");
class SDK {
constructor(config, axiosConfig) {
this.config = config;
this.request = new request_1.default(Object.assign({ url: config.endpoint + '/api', timeout: 60000, headers: {
Authorization: 'Basic ' +
Buffer.from(`${this.config.clientId}:${this.config.clientSecret}`).toString('base64'),
} }, axiosConfig));
this.userSDK = new user_1.UserSDK(this.config, this.request);
this.adapterSDK = new adapter_1.AdapterSDK(this.config, this.request);
this.applicationSDK = new application_1.ApplicationSDK(this.config, this.request);
this.certSDK = new cert_1.CertSDK(this.config, this.request);
this.enforcerSDK = new enforcer_1.EnforcerSDK(this.config, this.request);
this.groupSDK = new group_1.GroupSDK(this.config, this.request);
this.modelSDK = new model_1.ModelSDK(this.config, this.request);
this.organizationSDK = new organization_1.OrganizationSDK(this.config, this.request);
this.paymentSDK = new payment_1.PaymentSDK(this.config, this.request);
this.sessionSDK = new session_1.SessionSDK(this.config, this.request);
this.syncerSDK = new syncer_1.SyncerSDK(this.config, this.request);
this.permissionSDK = new permission_1.PermissionSDK(this.config, this.request);
this.planSDK = new plan_1.PlanSDK(this.config, this.request);
this.policySDK = new policy_1.PolicySDK(this.config, this.request);
this.pricingSDK = new pricing_1.PricingSDK(this.config, this.request);
this.providerSDK = new provider_1.ProviderSDK(this.config, this.request);
this.resourceSDK = new resource_1.ResourceSDK(this.config, this.request);
this.roleSDK = new role_1.RoleSDK(this.config, this.request);
this.subscriptionSDK = new subscription_1.SubscriptionSDK(this.config, this.request);
this.tokenSDK = new token_1.TokenSDK(this.config, this.request);
this.webhookSDK = new webhook_1.WebhookSDK(this.config, this.request);
this.productSDK = new product_1.ProductSDK(this.config, this.request);
this.emailSDK = new email_1.EmailSDK(this.config, this.request);
this.smsSDK = new sms_1.SmsSDK(this.config, this.request);
this.mfaSDK = new mfa_1.MfaSDK(this.config, this.request);
this.enforceSDK = new enforce_1.EnforceSDK(this.config, this.request);
this.urlSDK = new url_1.UrlSDK(this.config);
}
async getAuthToken(code) {
return await this.userSDK.getAuthToken(code);
}
async refreshToken(refreshToken) {
return await this.userSDK.refreshToken(refreshToken);
}
parseJwtToken(token) {
return this.userSDK.parseJwtToken(token);
}
async getUsers() {
return await this.userSDK.getUsers();
}
async getUser(id) {
return await this.userSDK.getUser(id);
}
async getUserCount(isOnline) {
return await this.userSDK.getUserCount(isOnline);
}
async addUser(user) {
return await this.userSDK.addUser(user);
}
async updateUser(user) {
return await this.userSDK.updateUser(user);
}
async deleteUser(user) {
return await this.userSDK.deleteUser(user);
}
async getAdapters() {
return await this.adapterSDK.getAdapters();
}
async getAdapter(id) {
return await this.adapterSDK.getAdapter(id);
}
async addAdapter(adapter) {
return await this.adapterSDK.addAdapter(adapter);
}
async updateAdapter(adapter) {
return await this.adapterSDK.updateAdapter(adapter);
}
async deleteAdapter(adapter) {
return await this.adapterSDK.deleteAdapter(adapter);
}
async getApplications() {
return await this.applicationSDK.getApplications();
}
async getApplication(name) {
return await this.applicationSDK.getApplication(name);
}
async addApplication(application) {
return await this.applicationSDK.addApplication(application);
}
async updateApplication(application) {
return await this.applicationSDK.updateApplication(application);
}
async deleteApplication(application) {
return await this.applicationSDK.deleteApplication(application);
}
async getCerts() {
return await this.certSDK.getCerts();
}
async getCert(id) {
return await this.certSDK.getCert(id);
}
async addCert(cert) {
return await this.certSDK.addCert(cert);
}
async updateCert(cert) {
return await this.certSDK.updateCert(cert);
}
async deleteCert(cert) {
return await this.certSDK.deleteCert(cert);
}
async getEnforcers() {
return await this.enforcerSDK.getEnforcers();
}
async getEnforcer(id) {
return await this.enforcerSDK.getEnforcer(id);
}
async addEnforcer(enforcer) {
return await this.enforcerSDK.addEnforcer(enforcer);
}
async updateEnforcer(enforcer) {
return await this.enforcerSDK.updateEnforcer(enforcer);
}
async deleteEnforcer(enforcer) {
return await this.enforcerSDK.deleteEnforcer(enforcer);
}
async getGroups() {
return await this.groupSDK.getGroups();
}
async getGroup(id) {
return await this.groupSDK.getGroup(id);
}
async addGroup(group) {
return await this.groupSDK.addGroup(group);
}
async updateGroup(group) {
return await this.groupSDK.updateGroup(group);
}
async deleteGroup(group) {
return await this.groupSDK.deleteGroup(group);
}
async getModels() {
return await this.modelSDK.getModels();
}
async getModel(id) {
return await this.modelSDK.getModel(id);
}
async addModel(model) {
return await this.modelSDK.addModel(model);
}
async updateModel(model) {
return await this.modelSDK.updateModel(model);
}
async deleteModel(model) {
return await this.modelSDK.deleteModel(model);
}
async getOrganizations() {
return await this.organizationSDK.getOrganizations();
}
async getOrganization(id) {
return await this.organizationSDK.getOrganization(id);
}
async addOrganization(organization) {
return await this.organizationSDK.addOrganization(organization);
}
async updateOrganization(organization) {
return await this.organizationSDK.updateOrganization(organization);
}
async deleteOrganization(organization) {
return await this.organizationSDK.deleteOrganization(organization);
}
async getPayments() {
return await this.paymentSDK.getPayments();
}
async getPayment(id) {
return await this.paymentSDK.getPayment(id);
}
async addPayment(payment) {
return await this.paymentSDK.addPayment(payment);
}
async updatePayment(payment) {
return await this.paymentSDK.updatePayment(payment);
}
async deletePayment(payment) {
return await this.paymentSDK.deletePayment(payment);
}
async getSessions() {
return await this.sessionSDK.getSessions();
}
async getSession(name, application) {
return await this.sessionSDK.getSession(name, application);
}
async addSession(session) {
return await this.sessionSDK.addSession(session);
}
async updateSession(session) {
return await this.sessionSDK.updateSession(session);
}
async deleteSession(session) {
return await this.sessionSDK.deleteSession(session);
}
async getSyncers() {
return await this.syncerSDK.getSyncers();
}
async getSyncer(id) {
return await this.syncerSDK.getSyncer(id);
}
async addSyncer(syncer) {
return await this.syncerSDK.addSyncer(syncer);
}
async updateSyncer(syncer) {
return await this.syncerSDK.updateSyncer(syncer);
}
async deleteSyncer(syncer) {
return await this.syncerSDK.deleteSyncer(syncer);
}
async getPermissions() {
return await this.permissionSDK.getPermissions();
}
async getPermission(id) {
return await this.permissionSDK.getPermission(id);
}
async addPermission(permission) {
return await this.permissionSDK.addPermission(permission);
}
async updatePermission(permission) {
return await this.permissionSDK.updatePermission(permission);
}
async deletePermission(permission) {
return await this.permissionSDK.deletePermission(permission);
}
async getPlans() {
return await this.planSDK.getPlans();
}
async getPlan(id) {
return await this.planSDK.getPlan(id);
}
async addPlan(plan) {
return await this.planSDK.addPlan(plan);
}
async updatePlan(plan) {
return await this.planSDK.updatePlan(plan);
}
async deletePlan(plan) {
return await this.planSDK.deletePlan(plan);
}
async getPolicies(enforcerName, adapterId) {
return await this.policySDK.getPolicies(enforcerName, adapterId);
}
async addPolicy(enforcer, policy) {
return await this.policySDK.addPolicy(enforcer, policy);
}
async updatePolicy(enforcer, oldPolicy, newPolicy) {
return await this.policySDK.updatePolicy(enforcer, oldPolicy, newPolicy);
}
async deletePolicy(enforcer, policy) {
return await this.policySDK.deletePolicy(enforcer, policy);
}
async getPricings() {
return await this.pricingSDK.getPricings();
}
async getPricing(id) {
return await this.pricingSDK.getPricing(id);
}
async addPricing(pricing) {
return await this.pricingSDK.addPricing(pricing);
}
async updatePricing(pricing) {
return await this.pricingSDK.updatePricing(pricing);
}
async deletePricing(pricing) {
return await this.pricingSDK.deletePricing(pricing);
}
async getProviders() {
return await this.providerSDK.getProviders();
}
async getProvider(id) {
return await this.providerSDK.getProvider(id);
}
async addProvider(provider) {
return await this.providerSDK.addProvider(provider);
}
async updateProvider(provider) {
return await this.providerSDK.updateProvider(provider);
}
async deleteProvider(provider) {
return await this.providerSDK.deleteProvider(provider);
}
async getResources(owner, user, field, value, sortField, sortOrder) {
return await this.resourceSDK.getResources(owner, user, field, value, sortField, sortOrder);
}
async getResource(id) {
return await this.resourceSDK.getResource(id);
}
async addResource(resource) {
return await this.resourceSDK.addResource(resource);
}
async updateResource(resource) {
return await this.resourceSDK.updateResource(resource);
}
async deleteResource(resource) {
return await this.resourceSDK.deleteResource(resource);
}
async uploadResource(resource, file) {
return await this.resourceSDK.uploadResource(resource, file);
}
async getRoles() {
return await this.roleSDK.getRoles();
}
async getRole(id) {
return await this.roleSDK.getRole(id);
}
async addRole(role) {
return await this.roleSDK.addRole(role);
}
async updateRole(role) {
return await this.roleSDK.updateRole(role);
}
async deleteRole(role) {
return await this.roleSDK.deleteRole(role);
}
async getSubscriptions() {
return await this.subscriptionSDK.getSubscriptions();
}
async getSubscription(id) {
return await this.subscriptionSDK.getSubscription(id);
}
async addSubscription(subscription) {
return await this.subscriptionSDK.addSubscription(subscription);
}
async updateSubscription(subscription) {
return await this.subscriptionSDK.updateSubscription(subscription);
}
async deleteSubscription(subscription) {
return await this.subscriptionSDK.deleteSubscription(subscription);
}
async getTokens(p, pageSize) {
return await this.tokenSDK.getTokens(p, pageSize);
}
async getToken(id) {
return await this.tokenSDK.getToken(id);
}
async addToken(token) {
return await this.tokenSDK.addToken(token);
}
async updateToken(token) {
return await this.tokenSDK.updateToken(token);
}
async deleteToken(token) {
return await this.tokenSDK.deleteToken(token);
}
async introspect(token, token_type_hint) {
return await this.tokenSDK.introspect(token, token_type_hint);
}
async getWebhooks() {
return await this.webhookSDK.getWebhooks();
}
async getWebhook(id) {
return await this.webhookSDK.getWebhook(id);
}
async addWebhook(webhook) {
return await this.webhookSDK.addWebhook(webhook);
}
async updateWebhook(webhook) {
return await this.webhookSDK.updateWebhook(webhook);
}
async deleteWebhook(webhook) {
return await this.webhookSDK.deleteWebhook(webhook);
}
async getProducts() {
return await this.productSDK.getProducts();
}
async getProduct(id) {
return await this.productSDK.getProduct(id);
}
async addProduct(product) {
return await this.productSDK.addProduct(product);
}
async updateProduct(product) {
return await this.productSDK.updateProduct(product);
}
async deleteProduct(product) {
return await this.productSDK.deleteProduct(product);
}
async sendEmail(email) {
return await this.emailSDK.sendEmail(email);
}
async sendSms(sms) {
return await this.smsSDK.sendSms(sms);
}
async setPassword(data) {
return await this.userSDK.setPassword(data);
}
async initiateMfa(data) {
return await this.mfaSDK.initiate(data);
}
async verifyMfa(data, passcode) {
return await this.mfaSDK.verify(data, passcode);
}
async enableMfa(data, cookie = null) {
return await this.mfaSDK.enable(data, cookie);
}
async setPreferredMfa(data) {
return await this.mfaSDK.setPreferred(data);
}
async deleteMfa(owner, name) {
return await this.mfaSDK.delete(owner, name);
}
async enforce(permissionId, modelId, resourceId, casbinRequest) {
return await this.enforceSDK.enforce(permissionId, modelId, resourceId, casbinRequest);
}
async batchEnforce(permissionId, modelId, resourceId, casbinRequest) {
return await this.enforceSDK.batchEnforce(permissionId, modelId, resourceId, casbinRequest);
}
getSignUpUrl(enablePassword, redirectUri) {
return this.urlSDK.getSignUpUrl(enablePassword, redirectUri);
}
getSignInUrl(redirectUri) {
return this.urlSDK.getSignInUrl(redirectUri);
}
getUserProfileUrl(userName, accessToken) {
return this.urlSDK.getUserProfileUrl(userName, accessToken);
}
getMyProfileUrl(accessToken) {
return this.urlSDK.getMyProfileUrl(accessToken);
}
}
exports.SDK = SDK;