Skip to content

Commit

Permalink
## 2.0.2 (#60)
Browse files Browse the repository at this point in the history
* ## 2.0.2
- Allow CORs
  - Use `crafterConf.configure({ cors: true, ... })` to enable CORs mode.
- Fix `fetchIsAuthoring` and `addAuthoringSupport` not retrieving for baseUrl from `crafterConf`.

* Use relative path for same package import
  • Loading branch information
rart authored Jan 19, 2022
1 parent 61547bc commit 4e52ac1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# SDK Changelog

## 2.0.2
- Allow CORs
- Use `crafterConf.configure({ cors: true, ... })` to enable CORs mode.
- Fix `fetchIsAuthoring` and `addAuthoringSupport` not retrieving for baseUrl from `crafterConf`.

## 2.0.1

### @craftercms/redux
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": "@craftercms/sdk",
"version": "2.0.1",
"version": "2.0.2",
"private": true,
"workspaces": [
"packages/*"
Expand Down
12 changes: 8 additions & 4 deletions packages/classes/src/SDKService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@

import { Observable } from 'rxjs';
import { pluck } from 'rxjs/operators';
import { ajax, AjaxResponse } from 'rxjs/ajax';
import { ajax } from 'rxjs/ajax';
import 'url-search-params-polyfill';
import { LookupTable } from '@craftercms/models';
import { crafterConf } from './config';

export function httpGet<T extends any = any>(requestURL: string, params: Object = {}, headers?: LookupTable): Observable<T> {
const searchParams = new URLSearchParams(params as URLSearchParams);
return ajax.get(`${requestURL}?${searchParams.toString()}`, headers).pipe(
pluck('response')
);
return ajax({
url: `${requestURL}?${searchParams.toString()}`,
method: 'GET',
headers: headers,
crossDomain: crafterConf.getConfig().cors
}).pipe(pluck('response'));
}

export function httpPost<T extends any = any>(requestURL: string, body: Object = {}, headers?: LookupTable): Observable<T> {
Expand Down
1 change: 1 addition & 0 deletions packages/classes/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { CrafterConfig } from '@craftercms/models';

const DEFAULTS: CrafterConfig = {
site: '',
cors: false,
baseUrl: '',
searchId: null,
endpoints: {
Expand Down
18 changes: 9 additions & 9 deletions packages/ice/ice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

import { ContentInstance } from '@craftercms/models';
import { ContentInstance, CrafterConfig } from '@craftercms/models';
import { crafterConf } from '@craftercms/classes';

declare namespace window {
const crafterRequire: any;
}

interface BaseCrafterConfig {
baseUrl?: string;
export interface BaseCrafterConfig extends Pick<CrafterConfig, 'site' | 'baseUrl'> {
}

export interface ICEConfig {
Expand Down Expand Up @@ -60,13 +60,13 @@ const printedErrorCache = {
invalidPath: {}
};

export function addAuthoringSupport(config?: BaseCrafterConfig): Promise<any> {
config = { baseUrl: '', ...(config || {}) };
export function addAuthoringSupport(config?: Partial<BaseCrafterConfig>): Promise<any> {
config = crafterConf.mix(config);
return new Promise((resolve) => {
const script = document.createElement('script');
script.src = `${config.baseUrl}/studio/static-assets/libs/requirejs/require.js`;
script.addEventListener('load', () => {
window.crafterRequire?.([`${config.baseUrl}/studio/overlayhook?extensionless`], () => {
window.crafterRequire?.([`${config.baseUrl}/studio/overlayhook?.js`], () => {
window.crafterRequire(['guest'], (guest) => {
resolve(guest);
});
Expand Down Expand Up @@ -207,9 +207,9 @@ export const repaintPencils: (() => void) = (function () {
};
})();

export function fetchIsAuthoring(config?: BaseCrafterConfig): Promise<boolean> {
config = { baseUrl: '', ...(config || {}) };
return fetch(`${config.baseUrl}/api/1/config/preview.json`)
export function fetchIsAuthoring(config?: Partial<BaseCrafterConfig>): Promise<boolean> {
let cfg = crafterConf.mix(config);
return fetch(`${cfg.baseUrl}/api/1/config/preview.json?crafterSite=${cfg.site}`, cfg.cors ? { mode: 'cors' } : {})
.then((response) => response.json())
.then((response) => response.preview);
}
1 change: 1 addition & 0 deletions packages/models/src/CrafterConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { LookupTable } from '@craftercms/models';

export interface CrafterConfig {
site: string;
cors: boolean;
baseUrl: string;
searchId?: string;
endpoints?: Endpoints;
Expand Down

0 comments on commit 4e52ac1

Please sign in to comment.