Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Merge branch 'release/2.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
gallayl committed Aug 22, 2017
2 parents ee46ddc + cf0d3e6 commit 41d490d
Show file tree
Hide file tree
Showing 27 changed files with 801 additions and 394 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,26 @@ let repository = new Repository.SnRepository({
RepositoryUrl: 'https://my-sensenet-site.com',
ODataToken: 'OData.svc',
JwtTokenKeyTemplate: 'my-${tokenName}-token-for-${siteName}',
JwtTokenPersist: 'expiration'
JwtTokenPersist: 'expiration',
DefaultSelect: ['DisplayName', 'Icon'],
RequiredSelect: ['Id', 'Type', 'Path', 'Name'],
DefaultMetadata: 'no',
DefaultInlineCount: 'allpages',
DefaultExpand: [],
DefaultTop: 1000
});
```
- __RepositoryURL__: The component will communicate with your repositoy using the following url. This will fall back to your _window.location.href_, if not specified. To enable your external app to send request against your sensenet portal change your ```Portal.settings```. For further information about cross-origin resource sharing in sensenet check [this](community.sensenet.com/docs/cors/)
article.
- __ODataToken__: Check your Sense/Net portal's web.config and if the ```ODataServiceToken``` is set, you can configure it here for the client side.
- __JwtTokenKeyTemplate__ - This will be the template how your JWT tokens will be stored (in _local/session storage_ or as a _cookie_). _${tokenName}_ will be replaced with the token's name ('access' or 'refresh'), _${siteName}_ will be replaced with your site's name
- __JwtTokenPersist__ - You can change how JWT Tokens should be persisted on the client, you can use _'session'_, whitch means the token will be invalidated on browser close, or _'expiration'_, in that case the token expiration property will be used (See [JWT Token docs](http://community.sensenet.com/docs/web-token-authentication/) for further details)
- __DefaultSelect__ - These fields will be selected by default on each OData request. Can be a field, an array of fields or 'all'
- __RequiredSelect__ - These fields will always be included in the OData *$select* statement. Also can be a field, an array of fields or 'all'
- __DefaultMetadata__ - Default *metadata* value for OData requests. Can be 'full', 'minimal' or 'no'
- __DefaultInlineCount__ - Default *inlinecount* OData parameter. Can be 'allpages' or 'none'
- __DefaultExpand__ - Default fields to *$expand*, empty by default. Can be a field or an array of fields.
- __DefaultTop__ - Default value to the odata *$top* parameter

### Create, Save, Update

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sn-client-js",
"version": "2.2.0",
"version": "2.3.0",
"description": "A JavaScript client for Sense/Net ECM that makes it easy to use the REST API of the Content Repository.",
"main": "dist/src/SN.js",
"files": [
Expand Down
2 changes: 2 additions & 0 deletions src/Authentication/IAuthenticationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ export interface IAuthenticationService {
*/
Logout(): Observable<boolean>;

CurrentUser: string;

}
11 changes: 10 additions & 1 deletion src/Authentication/JwtService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@ import { ODataHelper } from '../SN';
* This service class manages the JWT authentication, the session and the current login state.
*/
export class JwtService implements IAuthenticationService {

private readonly visitorName: string = 'BuiltIn\\Visitor';

public get CurrentUser(): string {
if (this.TokenStore.AccessToken.IsValid() || this.TokenStore.RefreshToken.IsValid()){
return this.TokenStore.AccessToken.Username || this.TokenStore.RefreshToken.Username;
}
return this.visitorName;
};
/**
* This subject indicates the current state of the service
* @default LoginState.Pending
*/
public get State(): Observable<LoginState>{
return this.stateSubject.asObservable();
return this.stateSubject.distinctUntilChanged();
}

/**
Expand Down
26 changes: 11 additions & 15 deletions src/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
*/ /** */

import { Observable } from '@reactivex/rxjs';
import { CustomAction, IODataParams, ODataRequestOptions, ODataApi } from './ODataApi';
import { CustomAction, IODataParams, IODataRequestOptions, ODataApi } from './ODataApi';
import { ODataHelper } from './SN';
import { Content } from './Content';
import { BaseRepository } from './Repository/BaseRepository';
import { BaseHttpProvider } from './HttpProviders/BaseHttpProvider';

export class Collection<T extends Content> {
odata: ODataApi<BaseHttpProvider, Content>;
odata: ODataApi<BaseHttpProvider>;
Path: string = '';

/**
Expand Down Expand Up @@ -83,7 +83,7 @@ export class Collection<T extends Content> {
public Add(content: T['options']): Observable<T> {
const newcontent = this.odata.Post(this.Path, content, this.contentType)
.map(resp => {
return this.repository.HandleLoadedContent(resp, this.contentType);
return this.repository.HandleLoadedContent(resp as any, this.contentType);
});
newcontent
.subscribe({
Expand Down Expand Up @@ -177,19 +177,15 @@ export class Collection<T extends Content> {
* });
* ```
*/
public Read(path: string, options?: IODataParams): Observable<any> {
public Read(path: string, options?: IODataParams<T>): Observable<any> {
this.Path = path;
let o: any = {};
if (typeof options !== 'undefined') {
o['params'] = options;
}
o['path'] = path;
let optionList = new ODataRequestOptions(o as ODataRequestOptions);
const children = this.odata.Fetch<T>(optionList)
const children = this.odata.Fetch<T>({
params: options,
path: path
})
.map(items => {
return items.d.results.map(c => this.repository.HandleLoadedContent(c, this.contentType));
}
);
return items.d.results.map(c => this.repository.HandleLoadedContent(c as any, this.contentType));
});
return children;
}
/**
Expand Down Expand Up @@ -309,7 +305,7 @@ export class Collection<T extends Content> {
o['params'] = options;
}
o['path'] = ODataHelper.getContentURLbyPath(this.Path);
let optionList = new ODataRequestOptions(o as ODataRequestOptions);
let optionList = o as IODataRequestOptions<T>;
return this.odata.Get<T>(optionList);
}
/**
Expand Down
63 changes: 63 additions & 0 deletions src/Config/snconfigmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import { SnConfigBehavior } from './snconfigbehavior';
import { SnConfigField } from './snconfigfielddecorator';
import { ODataMetadataType, ODataFieldParameter } from '../ODataApi/ODataParams';
import { Content } from '../Content';

/**
* Class that represents a typed model for the Sense/Net related configuration for an NPM Package. The values can be populated from sn.config.js.
Expand Down Expand Up @@ -67,6 +69,67 @@ export class SnConfigModel {
})
public JwtTokenPersist: 'session' | 'expiration' = 'session';

/**
* This parameter describes what fields should be included in the OData $select statements by default
*/
@SnConfigField({
Behavior: SnConfigBehavior.AllowFromConfig,
FieldDescription: 'The default values to select when triggering an OData Action',
Question: ''
})
public DefaultSelect: ODataFieldParameter<Content> | 'all' = ['DisplayName', 'Description', 'Icon']


/**
* This parameter describes what fields should always be included in the OData $select statements
*/
@SnConfigField({
Behavior: SnConfigBehavior.AllowFromConfig,
FieldDescription: 'The values are required when triggering an OData Action and will be always included in Select statements',
Question: ''
})
public RequiredSelect: ODataFieldParameter<Content> = ['Id', 'Path', 'Name', 'Type']

/**
* This field sets the default OData $metadata value
*/
@SnConfigField({
Behavior: SnConfigBehavior.AllowFromConfig,
FieldDescription: 'The default OData metadata option',
Question: ''
})
public DefaultMetadata: ODataMetadataType = 'no';

/**
* This field sets the default OData inline count value
*/
@SnConfigField({
Behavior: SnConfigBehavior.AllowFromConfig,
FieldDescription: 'The default OData inline count option',
Question: ''
})
public DefaultInlineCount: 'allpages' | 'none' = 'allpages'

/**
* This field describes what fields should be expanded on every OData request by default
*/
@SnConfigField({
Behavior: SnConfigBehavior.AllowFromConfig,
FieldDescription: 'The default OData references to expand',
Question: ''
})
public DefaultExpand: ODataFieldParameter<Content> | undefined = undefined;

/**
* This field sets up a default OData $top parameter
*/
@SnConfigField({
Behavior: SnConfigBehavior.AllowFromConfig,
FieldDescription: 'The default OData $top parameter for querying / fetching content',
Question: ''
})
public DefaultTop: number = 1000;

/**
*
* @param {Partial<SnConfigMoel>} config Partial config values, the default values will be overwritten if provided
Expand Down
Loading

0 comments on commit 41d490d

Please sign in to comment.