Merge branch 'v3' into activity-definitions

This commit is contained in:
Gürkan Güran 2023-01-25 18:08:20 +01:00
commit 3426cd28b7
14 changed files with 84 additions and 51 deletions

View file

@ -2,4 +2,5 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=abcdefghijklmnopqrstuvwxyz/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Deconstructor/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Postgre/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=richtext/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Telnyx/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View file

@ -1,6 +1,6 @@
{
"name": "@elsa-workflows/elsa-workflows-designer",
"version": "3.0.2-preview.43",
"version": "3.0.2-preview.44",
"description": "A workflow designer for Elsa 3",
"main": "./dist/index.cjs.js",
"module": "./dist/index.js",

View file

@ -1,7 +1,6 @@
import {Component, h, State, Event, EventEmitter} from "@stencil/core";
import {LoginApi} from "../services";
import {Container} from "typedi";
import jwt_decode from "jwt-decode";
import {AuthContext} from "../../../services";
import {SignedInArgs} from "../models";
@ -43,7 +42,7 @@ export class LoginPage {
const accessToken = loginResponse.accessToken;
const refreshToken = loginResponse.refreshToken;
const authContext = Container.get(AuthContext);
await authContext.signinTokens(accessToken, refreshToken, rememberMe);
await authContext.signin(accessToken, refreshToken, rememberMe);
}
private renderError = () => {

View file

@ -6,7 +6,6 @@ import {Container, Service} from "typedi";
import {StudioService, AuthContext, EventBus, ElsaClient, ElsaClientProvider} from "../../services";
import descriptorsStore from '../../data/descriptors-store';
import {SignedInArgs} from "./models";
import {AxiosInstance} from "axios";
import {LoginApi} from "./services";
@Service()
@ -64,14 +63,16 @@ export class LoginPlugin implements Plugin {
},
async onResponseError(error) {
if (error.response.status !== 401 || error.response.config.hasRetriedRequest)
if (error.response.status !== 401 || error.response.config.hasRetriedRequest)
return;
const authContext = Container.get(AuthContext);
const loginResponse = await loginApi.refreshAccessToken(authContext.getRefreshToken());
if (loginResponse.isAuthenticated) {
await authContext.signinTokens(loginResponse.accessToken, loginResponse.refreshToken, true);
await authContext.updateTokens(loginResponse.accessToken, loginResponse.refreshToken, true);
const t = await service.http({
...error.config,
@ -85,7 +86,7 @@ export class LoginPlugin implements Plugin {
return t;
}
else {
authContext.signOut();
await authContext.signOut();
}
}
});

View file

@ -1,9 +1,8 @@
import 'reflect-metadata';
import {Container, Service} from "typedi";
import {ElsaClientProvider, EventBus, ServerSettings} from "../../services";
import {Service} from "typedi";
import {ElsaClientProvider, ServerSettings} from "../../services";
import {LoginResponse} from "./models";
import axios, {AxiosError, AxiosRequestConfig} from "axios";
import {EventTypes} from "../../models";
import axios, {AxiosRequestConfig} from "axios";
@Service()
export class LoginApi {
@ -32,4 +31,4 @@ export class LoginApi {
.then(response => response.data)
.catch(error => error.response)
}
}
}

View file

@ -29,14 +29,19 @@ export class AuthContext {
}
}
async signinTokens(accessToken: string, refreshToken: string, createPersistentCookie: boolean){
async signin(accessToken: string, refreshToken: string, createPersistentCookie: boolean){
await this.updateTokens(accessToken, refreshToken, createPersistentCookie);
await this.eventBus.emit(EventTypes.Auth.SignedIn)
}
async updateTokens(accessToken: string, refreshToken: string, createPersistentCookie: boolean){
const claims = jwt_decode<any>(accessToken);
const permissions = claims.permissions || [];
const name = claims.name || '';
await this.signIn(name, permissions, accessToken, refreshToken, createPersistentCookie);
await this.updateSession(name, permissions, accessToken, refreshToken, createPersistentCookie);
}
async signIn(name: string, permissions: Array<string>, accessToken: string, refreshToken: string, createPersistentCookie: boolean) {
updateSession(name: string, permissions: Array<string>, accessToken: string, refreshToken: string, createPersistentCookie: boolean) {
authStore.name = name;
authStore.permissions = permissions;
authStore.signedIn = true;
@ -49,8 +54,6 @@ export class AuthContext {
if (createPersistentCookie) {
cookies.set("dashboard-session", data);
}
await this.eventBus.emit(EventTypes.Auth.SignedIn)
}
async signOut() {

View file

@ -1,30 +1,53 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Elsa.Expressions.Models;
/// <summary>
/// Represents a literal JSON expression.
/// </summary>
public class JsonLiteral : MemoryBlockReference
{
/// <inheritdoc />
[JsonConstructor]
public JsonLiteral()
{
}
/// <inheritdoc />
public JsonLiteral(string? value)
{
Value = value;
}
/// <summary>
/// The literal JSON string value.
/// </summary>
public string? Value { get; }
/// <inheritdoc />
public override MemoryBlock Declare() => new();
/// <summary>
/// Serializes the value into a JSON string in the form of a <see cref="JsonLiteral{T}"/>
/// </summary>
/// <param name="value"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static JsonLiteral From<T>(T value) => new JsonLiteral<T>(value);
}
/// <summary>
/// Represents a JSON string for the specified type <code>T</code>
/// </summary>
public class JsonLiteral<T> : JsonLiteral
{
/// <inheritdoc />
public JsonLiteral()
{
}
/// <inheritdoc />
public JsonLiteral(T value) : base(JsonSerializer.Serialize(value!))
{
}

View file

@ -26,8 +26,8 @@ public class TypeDescriber : ITypeDescriber
{
DeclarationKeyword = GetDeclarationKeyword(type),
Name = type.Name,
Properties = GetPropertyDefinitions(type).ToList(),
Methods = GetMethodDefinitions(type).ToList()
Properties = GetPropertyDefinitions(type).DistinctBy(x => x.Name).ToList(),
Methods = GetMethodDefinitions(type).DistinctBy(x => x.Name).ToList()
};
return typeDefinition;

View file

@ -20,16 +20,21 @@ internal class VariableTypeDefinitionProvider : TypeDefinitionProvider
protected override IEnumerable<TypeDefinition> GetTypeDefinitions(TypeDefinitionContext context)
{
var excludedTypes = new[] { typeof(ExpandoObject), typeof(IDictionary<string, object>) };
var excludedTypes = new Func<Type, bool>[]
{
type => type == typeof(ExpandoObject),
type => typeof(IDictionary<string, object>).IsAssignableFrom(type),
type => type == typeof(object)
};
var variableTypeQuery =
from variable in context.Variables
let variableType = variable.GetVariableType()
where (variableType.IsClass || variableType.IsInterface) && !variableType.IsPrimitive && !excludedTypes.Any(x => x.IsAssignableFrom(variableType))
where (variableType.IsClass || variableType.IsInterface) && !variableType.IsPrimitive && !excludedTypes.Any(x => x(variableType))
select variableType;
var variableTypes = variableTypeQuery.Distinct();
foreach (var variableType in variableTypes)
{
yield return _typeDescriber.DescribeType(variableType);

View file

@ -6,8 +6,12 @@ using Elsa.Workflows.Core.Expressions;
namespace Elsa.Workflows.Core.Models;
/// <summary>
/// A base type for the <see cref="Input{T}"/> type.
/// </summary>
public abstract class Input : Argument
{
/// <inheritdoc />
protected Input(IExpression expression, MemoryBlockReference memoryBlockReference, Type type) : base(memoryBlockReference)
{
Expression = expression;
@ -19,60 +23,77 @@ public abstract class Input : Argument
[JsonPropertyName("typeName")] public Type Type { get; set; }
}
/// <summary>
/// Represents activity input that is evaluated at runtime.
/// </summary>
public class Input<T> : Input
{
/// <inheritdoc />
public Input(T literal, string? id = default) : this(new Literal<T>(literal) { Id = id! })
{
}
/// <inheritdoc />
public Input(Func<T> @delegate, string? id = default) : this(new DelegateBlockReference(() => @delegate()){ Id = id!})
{
}
/// <inheritdoc />
public Input(Func<ExpressionExecutionContext, ValueTask<T?>> @delegate) : this(new DelegateBlockReference<T>(@delegate))
{
}
/// <inheritdoc />
public Input(Func<ValueTask<T?>> @delegate) : this(new DelegateBlockReference<T>(@delegate))
{
}
/// <inheritdoc />
public Input(Func<ExpressionExecutionContext, T> @delegate) : this(new DelegateBlockReference<T>(@delegate))
{
}
/// <inheritdoc />
public Input(Variable variable) : base(new VariableExpression(variable), variable, typeof(T))
{
}
/// <inheritdoc />
public Input(Output output) : base(new OutputExpression(output), output.MemoryBlockReference(), typeof(T))
{
}
/// <inheritdoc />
public Input(Literal<T> literal) : base(new LiteralExpression(literal.Value), literal, typeof(T))
{
}
/// <inheritdoc />
public Input(Literal literal) : base(new LiteralExpression(literal.Value), literal, typeof(T))
{
}
/// <inheritdoc />
public Input(JsonLiteral<T> literal) : base(new JsonExpression(literal.Value), literal, typeof(T))
{
}
/// <inheritdoc />
public Input(JsonLiteral literal) : base(new JsonExpression(literal.Value), literal, typeof(T))
{
}
/// <inheritdoc />
public Input(DelegateBlockReference delegateBlockReference) : base(new DelegateExpression(delegateBlockReference), delegateBlockReference, typeof(T))
{
}
/// <inheritdoc />
public Input(ElsaExpression expression) : this(new ElsaExpressionBlockReference(expression))
{
}
/// <inheritdoc />
public Input(IExpression expression, MemoryBlockReference memoryBlockReference) : base(expression, memoryBlockReference, typeof(T))
{
}

View file

@ -1,19 +0,0 @@
using Elsa.Expressions.Models;
namespace Elsa.Workflows.Core.Models;
public class JsonObject : MemoryBlockReference
{
public JsonObject()
{
}
public JsonObject(string? defaultValue)
{
DefaultValue = defaultValue;
}
public string? Name { get; set; }
public string? DefaultValue { get; }
public override MemoryBlock Declare() => new(DefaultValue);
}

View file

@ -5,7 +5,7 @@
"packages": {
"": {
"devDependencies": {
"@elsa-workflows/elsa-workflows-designer": "^3.0.2-preview.43",
"@elsa-workflows/elsa-workflows-designer": "^3.0.2-preview.44",
"copy-webpack-plugin": "^11.0.0",
"cross-env": "^7.0.3",
"monaco-editor": "^0.34.1",
@ -115,9 +115,9 @@
}
},
"node_modules/@elsa-workflows/elsa-workflows-designer": {
"version": "3.0.2-preview.43",
"resolved": "https://registry.npmjs.org/@elsa-workflows/elsa-workflows-designer/-/elsa-workflows-designer-3.0.2-preview.43.tgz",
"integrity": "sha512-9W7trl8k3yf9HSXHyyO514YENp2K8YvqChZw8U6sq4nD3iEd0DPEQ90HnDiLi7Dum4oAJZ42LM/m6ekKi0Ob7Q==",
"version": "3.0.2-preview.44",
"resolved": "https://registry.npmjs.org/@elsa-workflows/elsa-workflows-designer/-/elsa-workflows-designer-3.0.2-preview.44.tgz",
"integrity": "sha512-+mygygHGoJzCX4jWPgXYGjQh8yhb4tOAGbKuxTOKQNNtn+diBRgwY+MG33zQXRIVlyBun8OQv0T16i3Nun5s5g==",
"dev": true,
"dependencies": {
"@antv/layout": "^0.3.11",
@ -2425,9 +2425,9 @@
"dev": true
},
"@elsa-workflows/elsa-workflows-designer": {
"version": "3.0.2-preview.43",
"resolved": "https://registry.npmjs.org/@elsa-workflows/elsa-workflows-designer/-/elsa-workflows-designer-3.0.2-preview.43.tgz",
"integrity": "sha512-9W7trl8k3yf9HSXHyyO514YENp2K8YvqChZw8U6sq4nD3iEd0DPEQ90HnDiLi7Dum4oAJZ42LM/m6ekKi0Ob7Q==",
"version": "3.0.2-preview.44",
"resolved": "https://registry.npmjs.org/@elsa-workflows/elsa-workflows-designer/-/elsa-workflows-designer-3.0.2-preview.44.tgz",
"integrity": "sha512-+mygygHGoJzCX4jWPgXYGjQh8yhb4tOAGbKuxTOKQNNtn+diBRgwY+MG33zQXRIVlyBun8OQv0T16i3Nun5s5g==",
"dev": true,
"requires": {
"@antv/layout": "^0.3.11",

View file

@ -6,7 +6,7 @@
"build:debug": "cross-env webpack --mode=development --env configuration=Debug"
},
"devDependencies": {
"@elsa-workflows/elsa-workflows-designer": "^3.0.2-preview.43",
"@elsa-workflows/elsa-workflows-designer": "^3.0.2-preview.44",
"copy-webpack-plugin": "^11.0.0",
"cross-env": "^7.0.3",
"monaco-editor": "^0.34.1",

View file

@ -34,7 +34,7 @@ public class DefaultExpressionSyntaxProvider : IExpressionSyntaxProvider
private ExpressionSyntaxDescriptor CreateJsonDescriptor() => CreateDescriptor<JsonExpression>(
"Json",
CreateJsonExpression,
context => new JsonObject(context.GetExpression<JsonExpression>().Value),
context => new JsonLiteral(context.GetExpression<JsonExpression>().Value),
expression => expression.Value);
private ExpressionSyntaxDescriptor CreateDelegateDescriptor() => CreateDescriptor<DelegateExpression>(