@kintone/customize-uploader
Version:
A kintone customize uploader
131 lines • 4.52 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthenticationError = void 0;
const rest_api_client_1 = require("@kintone/rest-api-client");
const util_1 = require("./util");
class KintoneApiClient {
constructor(username, password, oAuthToken, basicAuthUsername, basicAuthPassword, baseUrl, options) {
this.options = options;
let auth;
if (username && password) {
auth = {
username,
password,
};
}
if (oAuthToken) {
auth = {
oAuthToken,
};
}
let basicAuth;
if (basicAuthUsername && basicAuthPassword) {
basicAuth = {
username: basicAuthUsername,
password: basicAuthPassword,
};
}
let guestSpaceId;
if (options.guestSpaceId) {
guestSpaceId = options.guestSpaceId;
}
let proxy;
if (options.proxy) {
proxy = (0, util_1.parseProxy)(options.proxy);
}
this.restApiClient = new rest_api_client_1.KintoneRestAPIClient({
baseUrl,
auth,
basicAuth,
featureFlags: {
enableAbortSearchError: false,
},
guestSpaceId,
proxy,
});
}
uploadFile(filePath) {
return this.restApiClient.file.uploadFile({
file: {
path: filePath,
},
});
}
prepareCustomizeFile(fileOrUrl) {
return __awaiter(this, void 0, void 0, function* () {
const isUrl = (0, util_1.isUrlString)(fileOrUrl);
if (isUrl) {
return {
type: "URL",
url: fileOrUrl,
};
}
const { fileKey } = yield this.uploadFile(fileOrUrl);
return {
type: "FILE",
file: {
fileKey,
},
};
});
}
updateCustomizeSetting(params) {
return this.restApiClient.app.updateAppCustomize(params);
}
deploySetting(appId) {
return this.restApiClient.app.deployApp({
apps: [{ app: appId }],
});
}
waitFinishingDeploy(appId, callback) {
return __awaiter(this, void 0, void 0, function* () {
let deployed = false;
while (!deployed) {
const resp = yield this.restApiClient.app.getDeployStatus({
apps: [appId],
});
const successedApps = resp.apps;
const successedAppsLength = successedApps.filter((r) => {
return r.status === "SUCCESS";
}).length;
deployed = successedAppsLength === resp.apps.length;
if (!deployed) {
yield (0, util_1.wait)(1000);
callback();
}
}
deployed = true;
});
}
downloadFile(fileKey) {
return this.restApiClient.file.downloadFile({
fileKey,
});
}
getAppCustomize(appId) {
return this.restApiClient.app.getAppCustomize({
app: appId,
});
}
getBase64EncodedCredentials(username, password) {
const buffer = Buffer.from(username + ":" + password);
return buffer.toString("base64");
}
getBasicAuthorization(basicAuthUsername, basicAuthPassword) {
return `Basic ${this.getBase64EncodedCredentials(basicAuthUsername, basicAuthPassword)}`;
}
}
exports.default = KintoneApiClient;
class AuthenticationError extends Error {
}
exports.AuthenticationError = AuthenticationError;
//# sourceMappingURL=KintoneApiClient.js.map