Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async (auth, _, userAttributes, fiscalCode) => {
const errorOrMaybeProfile = await profileModel.findOneProfileByFiscalCode(
fiscalCode
);
if (isRight(errorOrMaybeProfile)) {
const maybeProfile = errorOrMaybeProfile.value;
if (isSome(maybeProfile)) {
const profile = maybeProfile.value;
if (auth.groups.has(UserGroup.ApiFullProfileRead)) {
// if the client is a trusted application we return the
// extended profile
return ResponseSuccessJson(toExtendedProfile(profile));
} else {
// or else, we return a limited profile
return ResponseSuccessJson(
toLimitedProfile(
profile,
isSenderAllowed(
profile.blockedInboxOrChannels,
userAttributes.service.serviceId
)
test('should match even if no server defined', () => {
const method = pickOneHttpMethod();
const path = randomPath();
return expect(
isRight(
route({
resources: [createResource(method, path, [])],
input: {
method,
url: {
baseUrl: '',
path,
},
},
})
)
).toBeTruthy();
});
async function getValidatedSettings() {
const currentSettings = await ExtensionSettings.get();
const settingsWithDefault = RBetterTweetDeckSettings.decode(currentSettings);
if (!isRight(settingsWithDefault)) {
console.error('Had to use default settings');
console.log(PathReporter.report(settingsWithDefault));
return defaultSettings;
}
return settingsWithDefault.right;
}
public async getBackup(id: string): Promise {
const config = await this.so.get('backup_configurations', id);
if (config.error) {
throw new Error(config.error.message);
}
if (!config.attributes) {
throw new Error(`No backup configuration found with ID of ${id}`);
}
if (isRight(RuntimeConfigurationFile.decode(config.attributes))) {
return config.attributes as BackupConfigurationFile;
} else {
throw new Error(`Invalid BackupConfigurationFile data. == ${config.attributes}`);
}
}
const storedPolicies = policies.saved_objects.map(policySO => {
const policy = {
id: policySO.id,
...policySO.attributes,
};
const decoded = RuntimeStoredPolicy.decode(policy);
if (isRight(decoded)) {
return decoded.right;
} else {
throw new Error(
`Invalid PolicyFile data. == ${JSON.stringify(policy)} -- ${PathReporter.report(
decoded
)}`
);
}
});
return {
const getBranches = (x: RepoAccess) => async () =>
(
await this.git.getRemoteInfo(repoUrl, client, x.user, x.password)
).branches.map(b => b.name)
const placeHolder = "select branch"
const replaceBranch = dependFieldReplacer("branch", x =>
quickPick(getBranches(x), { placeHolder })
)
const newAccess = await chainTaskTransformers(
fieldReplacer("user", inputUser),
fieldReplacer("password", inputPwd),
replaceBranch
)(access)()
if (isRight(newAccess)) return newAccess.right
} else access.branch = ri && ri.branches[0] && ri.branches[0].name
} catch (e) {
log(e.toString())
}
return access
}
return S.stream.chain((str as any) as StreamEither, ea =>
Ei.isRight(ea)
? S.stream.of>(ea)
: (f(ea.left) as any)
);
return configs.map(config => {
if (isRight(RuntimeConfigurationFile.decode(config.attributes))) {
return config.attributes;
} else {
throw new Error(`Invalid ConfigurationFile data. == ${config.attributes}`);
}
});
}
const mapToTimeUrlState = (value: any) => {
const result = MetricsTimeRT.decode(value);
if (isRight(result)) {
const resultValue = result.right;
const to = isNumber(resultValue.to) ? moment(resultValue.to).toISOString() : resultValue.to;
const from = isNumber(resultValue.from)
? moment(resultValue.from).toISOString()
: resultValue.from;
return { ...resultValue, from, to };
}
return undefined;
};
profileModelPayload: ExtendedProfile
): Promise | IResponseErrorQuery> {
const profile: Profile = {
acceptedTosVersion: profileModelPayload.accepted_tos_version,
blockedInboxOrChannels: profileModelPayload.blocked_inbox_or_channels,
email: profileModelPayload.email,
fiscalCode,
isInboxEnabled: profileModelPayload.is_inbox_enabled,
isWebhookEnabled: profileModelPayload.is_webhook_enabled,
preferredLanguages: profileModelPayload.preferred_languages
};
const errorOrProfile = await profileModel.create(profile, profile.fiscalCode);
const errorOrProfileAsPublicExtendedProfile = errorOrProfile.map(
toExtendedProfile
);
if (isRight(errorOrProfileAsPublicExtendedProfile)) {
return ResponseSuccessJson(errorOrProfileAsPublicExtendedProfile.value);
} else {
return ResponseErrorQuery(
"Error while creating a new profile",
errorOrProfileAsPublicExtendedProfile.value
);
}
}