Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function initializeBucket() {
const api = new KintoClient(
config.server.remote,
{headers: getAuthenticationHeaders(uuid.v4())}
);
return api.createBucket(config.server.bucket, {
safe: true,
permissions: {
"collection:create": ["system.Authenticated",]
}
}).then(() => {
api.bucket(config.server.bucket).setPermissions({
"write": []
},
{patch: true}); // Do a PATCH request to prevent everyone to be an admin.
})
.catch(() => {
console.debug("Skipping bucket creation, it probably already exist.");
const form = getState().form;
const schema = form.schema;
const uiSchema = form.uiSchema;
// Remove the "required" property if it's empty.
if (schema.required && schema.required.length === 0) {
delete schema.required;
}
dispatch({type: FORM_PUBLICATION_PENDING});
const adminToken = uuid.v4().replace(/-/g, "");
const formID = getFormID(adminToken);
// Create a client authenticated as the admin.
const bucket = new KintoClient(
config.server.remote,
{headers: getAuthenticationHeaders(adminToken)}
).bucket(config.server.bucket);
// The name of the collection is the user token so the user deals with
// less different concepts.
bucket.createCollection(formID, {
data: {schema, uiSchema},
permissions: {
"record:create": ["system.Authenticated"]
}
})
.then(({data}) => {
dispatch({
type: FORM_PUBLICATION_DONE,
collection: data.id,
export function createClient(username, password) {
return new KintoClient("http://0.0.0.0:8888/v1", {
headers: {
Authorization: "Basic " + btoa(`${username}:${password}`),
},
});
}
export function setupClient(auth: AuthData): KintoClient {
const { server } = auth;
return setClient(
new KintoClient(server, {
headers: { Authorization: getAuthHeader(auth) },
timeout: 30000,
retry: 1,
})
);
}
return Promise.resolve().then(() => {
const headers = {};
if (userToken) {
headers.Authorization = `github+Bearer ${userToken}`;
}
const db = new KintoClient(
`${process.env.STORAGE_ENDPOINT_URL}/v1`,
{ headers }
);
const bucket = db.bucket('processeer');
collections.blocks = bucket.collection('blocks');
collections.reports = bucket.collection('reports');
});
}
constructor(remote, username, password) {
this.username = username;
this.password = password;
const defaultOptions = {
remote,
};
if (username && password) {
defaultOptions['headers'] = {
Authorization: "Basic " + btoa(`${username}:${password}`),
};
}
this.server = new KintoClient(remote, defaultOptions);
this.user = new User(this.server, username);
this.sentences = new Sentences(this.server, username);
this.cvSentences = new CVSentences(this.server, username);
}