Skip to content

Commit

Permalink
2.0.4 (#65)
Browse files Browse the repository at this point in the history
* # 2.0.3
@craftercms/classes
- Change SDKService.httpGet to use fetch instead of rxjs.ajax
- Fix fetch's mode (for cors)
- Extend support for other fetch modes
- Switch from using URLSearchParams to using query-string for the same purpose

* # 2.0.4
@craftercms/content
- Fix `flatten` argument to getDescriptor getting lost/ignored
@craftercms/models
- Move types from other files into models package
- Adding missing properties to NavigationItem interface
  • Loading branch information
rart authored Sep 2, 2022
1 parent ad75bd0 commit d5c853a
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@craftercms/sdk",
"version": "2.0.3",
"version": "2.0.4",
"private": true,
"workspaces": [
"packages/*"
Expand Down
22 changes: 16 additions & 6 deletions packages/content/src/ContentStoreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/

import { Observable } from 'rxjs';

import { crafterConf, SDKService } from '@craftercms/classes';
import { CrafterConfig, Descriptor, Item } from '@craftercms/models';
import { composeUrl } from '@craftercms/utils';
import { map } from 'rxjs/operators';

/**
* Returns an Item from the content store.
Expand All @@ -44,13 +44,23 @@ export interface GetDescriptorConfig {
export function getDescriptor(path: string): Observable<Descriptor>;
export function getDescriptor(path: string, config: Partial<CrafterConfig & GetDescriptorConfig>): Observable<Descriptor>;
export function getDescriptor(path: string, config?: Partial<CrafterConfig & GetDescriptorConfig>): Observable<Descriptor> {
config = crafterConf.mix(config);
const requestURL = composeUrl(config, config.endpoints.GET_DESCRIPTOR);
return SDKService.httpGet(requestURL, {
let cfg = crafterConf.mix(config);
return SDKService.httpGet(composeUrl(cfg, cfg.endpoints.GET_DESCRIPTOR), {
url: path,
crafterSite: config.site,
crafterSite: cfg.site,
flatten: Boolean(config.flatten)
}, config.headers);
}, cfg.headers).pipe(
// Manually introduce the path into the response as descriptor endpoint does not return it.
map((descriptor: Descriptor) => {
let prop = typeof descriptor.page === 'undefined' ? 'component' : 'page';
return {
[prop]: {
...descriptor[prop],
localId: path
}
};
})
);
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/content/src/UrlTransformationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { composeUrl } from '@craftercms/utils';
* @param {string} transformerName - Name of the transformer to apply
* @param {string} url - URL that will be transformed
*/
// TODO: transformerName: 'storeUrlToRenderUrl' | 'renderUrlToStoreUrl' | ???
export function urlTransform(transformerName: string, url: string): Observable<any>;
export function urlTransform(transformerName: string, url: string, config: CrafterConfig): Observable<any>;
export function urlTransform(transformerName: string, url: string, config?: CrafterConfig): Observable<any> {
Expand Down
19 changes: 1 addition & 18 deletions packages/content/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,7 @@
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

import { ContentInstance, Descriptor, Item } from '@craftercms/models';

interface GraphQLResponse {
[root: string]: {
// Repeating groups & node selectors collection root
item?:
object[] |
Array<{
key: string;
value: string;
component: unknown;
}>
// Other field types
[contentTypeField: string]: unknown
}
}

type DescriptorResponse = Descriptor | Item | GraphQLResponse;
import { ContentInstance, DescriptorResponse } from '@craftercms/models';

const systemPropMap = {
guid: 'id',
Expand Down
1 change: 1 addition & 0 deletions packages/models/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ export * from './src/ReduxStore';
export * from './src/message';
export * from './src/ContentInstance';
export * from './src/search';
export * from './src/GraphQLResponse';
30 changes: 30 additions & 0 deletions packages/models/src/GraphQLResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

export interface GraphQLResponse {
[root: string]: {
// Repeating groups & node selectors collection root
item?:
object[] |
Array<{
key: string;
value: string;
component: unknown;
}>
// Other field types
[contentTypeField: string]: unknown
}
}
2 changes: 2 additions & 0 deletions packages/models/src/NavigationItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

export interface NavigationItem {
url: string;
label: string;
active: boolean;
subItems: Array<NavigationItem>;
attributes: Record<string, string>;
[prop: string]: any;
}

Expand Down
5 changes: 5 additions & 0 deletions packages/models/src/descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

import { Item } from './item';
import { GraphQLResponse } from './GraphQLResponse';

export interface Descriptor {
page?: any;
component?: any;
[prop: string]: any;
}

export type DescriptorResponse = Descriptor | Item | GraphQLResponse;

0 comments on commit d5c853a

Please sign in to comment.