Skip to content

Commit

Permalink
# 2.0.3 (#64)
Browse files Browse the repository at this point in the history
@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
  • Loading branch information
rart authored Sep 2, 2022
1 parent 7f501db commit ad75bd0
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 11 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"name": "@craftercms/sdk",
"version": "2.0.2",
"version": "2.0.3",
"private": true,
"workspaces": [
"packages/*"
],
"description": "Crafter CMS SDK for JavaScript",
"scripts": {},
"scripts": {
"build": "./build.sh"
},
"repository": {
"type": "git",
"url": "git+https://github.com/craftercms/craftercms-sdk-js.git"
Expand Down
1 change: 1 addition & 0 deletions packages/classes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"dependencies": {
"@craftercms/models": "0.0.0-PLACEHOLDER",
"@craftercms/utils": "0.0.0-PLACEHOLDER",
"query-string": "^7.1.0",
"url-search-params-polyfill": "^5.0.0"
},
"devDependencies": {
Expand Down
15 changes: 8 additions & 7 deletions packages/classes/src/SDKService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@
*/

import { Observable } from 'rxjs';
import { fromFetch } from 'rxjs/fetch';
import { pluck } from 'rxjs/operators';
import { ajax } from 'rxjs/ajax';
import 'url-search-params-polyfill';
import { LookupTable } from '@craftercms/models';
import { stringify } from 'query-string';
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({
url: `${requestURL}?${searchParams.toString()}`,
export function httpGet<T extends any = any>(requestURL: string, params: Record<string, any> = {}, headers?: LookupTable): Observable<T> {
const mode = crafterConf.getConfig().cors;
return fromFetch(`${requestURL}?${stringify(params)}`, {
method: 'GET',
headers: headers,
crossDomain: crafterConf.getConfig().cors
}).pipe(pluck('response'));
mode: typeof mode === 'boolean' ? mode ? 'cors' : 'no-cors' : mode,
selector: response => response.json()
});
}

export function httpPost<T extends any = any>(requestURL: string, body: Object = {}, headers?: LookupTable): Observable<T> {
Expand Down
4 changes: 3 additions & 1 deletion packages/classes/tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"paths": {
"@craftercms/classes": ["."],
"@craftercms/utils": ["../../dist/packages/utils"],
"@craftercms/models": ["../../dist/packages/models"]
"@craftercms/models": ["../../dist/packages/models"],
"rxjs": ["../../node_modules/rxjs"],
"rxjs/*": ["../../node_modules/rxjs/*"]
},
"outDir": "../../dist/packages/classes"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/CrafterConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { LookupTable } from '@craftercms/models';

export interface CrafterConfig {
site: string;
cors: boolean;
cors: boolean | RequestInit['mode'];
baseUrl: string;
searchId?: string;
endpoints?: Endpoints;
Expand Down
1 change: 1 addition & 0 deletions packages/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"noFallthroughCasesInSwitch": true,
"paths": {
"redux": ["../node_modules/redux"],
"rxjs": ["../node_modules/rxjs"],
"rxjs/*": ["../node_modules/rxjs/*"],
"@craftercms/*": ["./*"]
},
Expand Down
25 changes: 25 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ fill-range@^7.0.1:
dependencies:
to-regex-range "^5.0.1"

filter-obj@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/filter-obj/-/filter-obj-1.1.0.tgz#9b311112bc6c6127a16e016c6c5d7f19e0805c5b"
integrity sha1-mzERErxsYSehbgFsbF1/GeCAXFs=

[email protected], find-up@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-3.0.0.tgz#49169f1d7993430646da61ecc5ae355c21c97b73"
Expand Down Expand Up @@ -770,6 +775,16 @@ [email protected]:
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.3.2.tgz#9653a036fb7c1ee42342f2325cceefea3926c48d"
integrity sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0=

query-string@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/query-string/-/query-string-7.1.0.tgz#96b88f27b39794f97b8c8ccd060bc900495078ef"
integrity sha512-wnJ8covk+S9isYR5JIXPt93kFUmI2fQ4R/8130fuq+qwLiGVTurg7Klodgfw4NSz/oe7xnyi09y3lSrogUeM3g==
dependencies:
decode-uri-component "^0.2.0"
filter-obj "^1.1.0"
split-on-first "^1.0.0"
strict-uri-encode "^2.0.0"

[email protected]:
version "0.2.0"
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620"
Expand Down Expand Up @@ -897,11 +912,21 @@ sourcemap-codec@^1.4.4:
resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4"
integrity sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==

split-on-first@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/split-on-first/-/split-on-first-1.1.0.tgz#f610afeee3b12bce1d0c30425e76398b78249a5f"
integrity sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==

sprintf-js@~1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=

strict-uri-encode@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"
integrity sha1-ucczDHBChi9rFC3CdLvMWGbONUY=

"string-width@^1.0.2 || 2":
version "2.1.1"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e"
Expand Down

0 comments on commit ad75bd0

Please sign in to comment.