@looker/sdk-rtl 21.6.4 → 21.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [21.6.5](https://github.com/looker-open-source/sdk-codegen/compare/sdk-rtl-v21.6.4...sdk-rtl-v21.6.5) (2026-03-25)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **codegen:** implement type-driven form encoding across SDKs ([#1674](https://github.com/looker-open-source/sdk-codegen/issues/1674)) ([58aaf86](https://github.com/looker-open-source/sdk-codegen/commit/58aaf8603be2a10cdd641c84d8d46ff98ce6d269)), closes [#1673](https://github.com/looker-open-source/sdk-codegen/issues/1673)
14
+
8
15
  ## [21.6.4](https://github.com/looker-open-source/sdk-codegen/compare/sdk-rtl-v21.6.3...sdk-rtl-v21.6.4) (2025-03-11)
9
16
 
10
17
 
@@ -45,8 +45,33 @@ class BaseTransport {
45
45
  body = undefined;
46
46
  } else {
47
47
  if (typeof body !== 'string') {
48
- body = JSON.stringify(body);
49
- headers['Content-Type'] = 'application/json';
48
+ var isUrlEncoded = body instanceof URLSearchParams;
49
+ if (!isUrlEncoded) {
50
+ isUrlEncoded = Object.keys(headers).some(k => {
51
+ var _headers$k;
52
+ return k.toLowerCase() === 'content-type' && ((_headers$k = headers[k]) === null || _headers$k === void 0 ? void 0 : _headers$k.toString().includes('application/x-www-form-urlencoded'));
53
+ });
54
+ }
55
+ if (isUrlEncoded) {
56
+ if (body instanceof URLSearchParams) {
57
+ body = body.toString();
58
+ } else {
59
+ var params = new URLSearchParams();
60
+ Object.entries(body).forEach(_ref => {
61
+ var [k, v] = _ref;
62
+ if (v !== undefined && v !== null) {
63
+ params.append(k, v instanceof Date ? v.toISOString() : typeof v === 'object' ? JSON.stringify(v) : v.toString());
64
+ }
65
+ });
66
+ body = params.toString();
67
+ }
68
+ if (!headers['Content-Type']) {
69
+ headers['Content-Type'] = 'application/x-www-form-urlencoded';
70
+ }
71
+ } else {
72
+ body = JSON.stringify(body);
73
+ headers['Content-Type'] = 'application/json';
74
+ }
50
75
  }
51
76
  }
52
77
  var signaller;
@@ -1 +1 @@
1
- {"version":3,"file":"baseTransport.js","names":["_transport","require","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","asyncGeneratorStep","gen","resolve","reject","_next","_throw","key","arg","info","value","error","done","Promise","then","_asyncToGenerator","fn","self","args","err","undefined","obj","_toPropertyKey","configurable","writable","i","_toPrimitive","String","Symbol","toPrimitive","call","TypeError","Number","BaseTransport","constructor","options","ok","res","statusCode","StatusCode","OK","IMUsed","makeUrl","path","queryParams","base","base_url","match","concat","addQueryParams","initRequest","method","body","authenticator","_this","_options","_options2","_options$headers","agentTag","agentPrefix","agent","headers","LookerAppId","mergeOptions","JSON","stringify","signaller","AbortSignal","timeout","ms","sdkTimeout","signal","any","console","debug","props","credentials","url","exports"],"sources":["../src/baseTransport.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\n/* eslint-disable no-console */\n\nimport {\n StatusCode,\n addQueryParams,\n agentPrefix,\n mergeOptions,\n LookerAppId,\n sdkTimeout,\n} from './transport';\nimport type {\n Authenticator,\n HttpMethod,\n IRawRequest,\n IRawResponse,\n ITransport,\n ITransportSettings,\n RawObserver,\n SDKResponse,\n Values,\n IRequestProps,\n} from './transport';\n\nexport abstract class BaseTransport implements ITransport {\n protected constructor(protected readonly options: ITransportSettings) {\n this.options = options;\n }\n\n observer: RawObserver | undefined = undefined;\n\n abstract parseResponse<TSuccess, TError>(\n raw: IRawResponse\n ): Promise<SDKResponse<TSuccess, TError>>;\n\n ok(res: IRawResponse): boolean {\n return (\n res.statusCode >= StatusCode.OK && res.statusCode <= StatusCode.IMUsed\n );\n }\n\n /**\n * HTTP request function for atomic, fully downloaded raw HTTP responses\n *\n * NOTE: This method has no error handling. It simply returns the results of the HTTP request.\n *\n * @param method of HTTP request\n * @param path request path, either relative or fully specified\n * @param queryParams name/value pairs to pass as part of the URL\n * @param body data for the body of the request\n * @param authenticator authenticator callback, typically from `IAuthSession` implementation\n * @param options overrides of default transport settings\n * @returns typed response of `TSuccess`, or `TError` result\n */\n abstract rawRequest(\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<IRawResponse>;\n\n /**\n * Request a streaming response\n * @param method HTTP method\n * @param path Request path\n * @param queryParams query parameters for the request\n * @param body http body to include with request\n * @param authenticator callback to add authentication information to the request\n * @param options transport settings overrides\n */\n abstract request<TSuccess, TError>(\n method: HttpMethod,\n path: string,\n queryParams?: any,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>;\n\n /**\n * Request a streaming response\n * @param callback A function will be called with the created HTTP response object\n * @param method HTTP method\n * @param path Request path\n * @param queryParams parameters for the request\n * @param body http body to include with request\n * @param authenticator callback to add authentication information to the request\n * @param options transport settings overrides\n * @returns the streaming response\n */\n abstract stream<TSuccess>(\n callback: (response: Response) => Promise<TSuccess>,\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<TSuccess>;\n\n /**\n * Determine whether the url should be an API path, relative from base_url, or is already fully specified override\n * @param path Request path\n * @param options Transport settings\n * @param queryParams Collection of query Params\n * @returns the fully specified request path including any query string parameters\n */\n makeUrl(\n path: string,\n options: Partial<ITransportSettings>,\n queryParams?: Values\n ) {\n // is this an API-versioned call?\n const base = options.base_url;\n if (!path.match(/^(http:\\/\\/|https:\\/\\/)/gi)) {\n path = `${base}${path}`; // path was relative\n }\n path = addQueryParams(path, queryParams);\n return path;\n }\n\n abstract retry(wait: IRawRequest): Promise<IRawResponse>;\n\n protected async initRequest(\n method: HttpMethod,\n path: string,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ) {\n const agentTag = options?.agentTag || this.options.agentTag || agentPrefix;\n const agent = { headers: { [LookerAppId]: agentTag } };\n options = mergeOptions({ ...this.options, ...agent }, options ?? {});\n const headers = options.headers ?? {};\n\n // Make sure an empty body is undefined\n if (!body) {\n body = undefined;\n } else {\n if (typeof body !== 'string') {\n body = JSON.stringify(body);\n headers['Content-Type'] = 'application/json';\n }\n }\n\n let signaller;\n if (AbortSignal.timeout) {\n const ms = sdkTimeout(options) * 1000;\n let signaller = AbortSignal.timeout(ms);\n if ('signal' in options && options.signal) {\n // AbortSignal.any may not be available, tolerate its absence\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (AbortSignal.any) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n signaller = AbortSignal.any([options.signal, signaller]);\n } else {\n console.debug(\n 'Cannot combine cancel signal and timeout. AbortSignal.any is not available in this transport.'\n );\n console.debug({ AbortSignal });\n }\n } else {\n console.debug(\n 'AbortSignal.timeout is not defined. Timeout will use default behavior'\n );\n }\n }\n\n let props: IRequestProps = {\n body,\n credentials: 'same-origin',\n headers,\n method,\n url: path,\n signal: signaller,\n };\n\n if (authenticator) {\n // Add authentication information to the request\n props = await authenticator(props);\n }\n\n // Transform to HTTP request headers at the last second\n // props.headers = new Headers(props.headers) as any;\n\n return props;\n }\n}\n"],"mappings":";;;;;;AA4BA,IAAAA,UAAA,GAAAC,OAAA;AAOqB,SAAAC,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAAU,cAAAZ,CAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAY,SAAA,CAAAC,MAAA,EAAAb,CAAA,UAAAC,CAAA,WAAAW,SAAA,CAAAZ,CAAA,IAAAY,SAAA,CAAAZ,CAAA,QAAAA,CAAA,OAAAF,OAAA,CAAAI,MAAA,CAAAD,CAAA,OAAAa,OAAA,WAAAd,CAAA,IAAAe,eAAA,CAAAhB,CAAA,EAAAC,CAAA,EAAAC,CAAA,CAAAD,CAAA,SAAA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,OAAO,IAAIA,OAAO,CAACoC,MAAM,EAAE;UAIzC,IAAIJ,WAAW,CAACK,GAAG,EAAE;YAInBN,UAAS,GAAGC,WAAW,CAACK,GAAG,CAAC,CAACrC,OAAO,CAACoC,MAAM,EAAEL,UAAS,CAAC,CAAC;UAC1D,CAAC,MAAM;YACLO,OAAO,CAACC,KAAK,CACX,+FACF,CAAC;YACDD,OAAO,CAACC,KAAK,CAAC;cAAEP;YAAY,CAAC,CAAC;UAChC;QACF,CAAC,MAAM;UACLM,OAAO,CAACC,KAAK,CACX,uEACF,CAAC;QACH;MACF;MAEA,IAAIC,KAAoB,GAAG;QACzBvB,IAAI;QACJwB,WAAW,EAAE,aAAa;QAC1Bf,OAAO;QACPV,MAAM;QACN0B,GAAG,EAAElC,IAAI;QACT4B,MAAM,EAAEL;MACV,CAAC;MAED,IAAIb,aAAa,EAAE;QAEjBsB,KAAK,SAAStB,aAAa,CAACsB,KAAK,CAAC;MACpC;MAKA,OAAOA,KAAK;IAAC;EACf;AACF;AAACG,OAAA,CAAA7C,aAAA,GAAAA,aAAA"}
1
+ {"version":3,"file":"baseTransport.js","names":["_transport","require","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","asyncGeneratorStep","gen","resolve","reject","_next","_throw","key","arg","info","value","error","done","Promise","then","_asyncToGenerator","fn","self","args","err","undefined","obj","_toPropertyKey","configurable","writable","i","_toPrimitive","String","Symbol","toPrimitive","call","TypeError","Number","BaseTransport","constructor","options","ok","res","statusCode","StatusCode","OK","IMUsed","makeUrl","path","queryParams","base","base_url","match","concat","addQueryParams","initRequest","method","body","authenticator","_this","_options","_options2","_options$headers","agentTag","agentPrefix","agent","headers","LookerAppId","mergeOptions","isUrlEncoded","URLSearchParams","some","k","_headers$k","toLowerCase","toString","includes","params","entries","_ref","v","append","Date","toISOString","JSON","stringify","signaller","AbortSignal","timeout","ms","sdkTimeout","signal","any","console","debug","props","credentials","url","exports"],"sources":["../src/baseTransport.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\n/* eslint-disable no-console */\n\nimport {\n StatusCode,\n addQueryParams,\n agentPrefix,\n mergeOptions,\n LookerAppId,\n sdkTimeout,\n} from './transport';\nimport type {\n Authenticator,\n HttpMethod,\n IRawRequest,\n IRawResponse,\n ITransport,\n ITransportSettings,\n RawObserver,\n SDKResponse,\n Values,\n IRequestProps,\n} from './transport';\n\nexport abstract class BaseTransport implements ITransport {\n protected constructor(protected readonly options: ITransportSettings) {\n this.options = options;\n }\n\n observer: RawObserver | undefined = undefined;\n\n abstract parseResponse<TSuccess, TError>(\n raw: IRawResponse\n ): Promise<SDKResponse<TSuccess, TError>>;\n\n ok(res: IRawResponse): boolean {\n return (\n res.statusCode >= StatusCode.OK && res.statusCode <= StatusCode.IMUsed\n );\n }\n\n /**\n * HTTP request function for atomic, fully downloaded raw HTTP responses\n *\n * NOTE: This method has no error handling. It simply returns the results of the HTTP request.\n *\n * @param method of HTTP request\n * @param path request path, either relative or fully specified\n * @param queryParams name/value pairs to pass as part of the URL\n * @param body data for the body of the request\n * @param authenticator authenticator callback, typically from `IAuthSession` implementation\n * @param options overrides of default transport settings\n * @returns typed response of `TSuccess`, or `TError` result\n */\n abstract rawRequest(\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<IRawResponse>;\n\n /**\n * Request a streaming response\n * @param method HTTP method\n * @param path Request path\n * @param queryParams query parameters for the request\n * @param body http body to include with request\n * @param authenticator callback to add authentication information to the request\n * @param options transport settings overrides\n */\n abstract request<TSuccess, TError>(\n method: HttpMethod,\n path: string,\n queryParams?: any,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>;\n\n /**\n * Request a streaming response\n * @param callback A function will be called with the created HTTP response object\n * @param method HTTP method\n * @param path Request path\n * @param queryParams parameters for the request\n * @param body http body to include with request\n * @param authenticator callback to add authentication information to the request\n * @param options transport settings overrides\n * @returns the streaming response\n */\n abstract stream<TSuccess>(\n callback: (response: Response) => Promise<TSuccess>,\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<TSuccess>;\n\n /**\n * Determine whether the url should be an API path, relative from base_url, or is already fully specified override\n * @param path Request path\n * @param options Transport settings\n * @param queryParams Collection of query Params\n * @returns the fully specified request path including any query string parameters\n */\n makeUrl(\n path: string,\n options: Partial<ITransportSettings>,\n queryParams?: Values\n ) {\n // is this an API-versioned call?\n const base = options.base_url;\n if (!path.match(/^(http:\\/\\/|https:\\/\\/)/gi)) {\n path = `${base}${path}`; // path was relative\n }\n path = addQueryParams(path, queryParams);\n return path;\n }\n\n abstract retry(wait: IRawRequest): Promise<IRawResponse>;\n\n protected async initRequest(\n method: HttpMethod,\n path: string,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ) {\n const agentTag = options?.agentTag || this.options.agentTag || agentPrefix;\n const agent = { headers: { [LookerAppId]: agentTag } };\n options = mergeOptions({ ...this.options, ...agent }, options ?? {});\n const headers = options.headers ?? {};\n\n // Make sure an empty body is undefined\n if (!body) {\n body = undefined;\n } else {\n if (typeof body !== 'string') {\n let isUrlEncoded = body instanceof URLSearchParams;\n if (!isUrlEncoded) {\n isUrlEncoded = Object.keys(headers).some(\n k =>\n k.toLowerCase() === 'content-type' &&\n headers[k]\n ?.toString()\n .includes('application/x-www-form-urlencoded')\n );\n }\n\n if (isUrlEncoded) {\n if (body instanceof URLSearchParams) {\n body = body.toString();\n } else {\n const params = new URLSearchParams();\n Object.entries(body as any).forEach(([k, v]) => {\n if (v !== undefined && v !== null) {\n params.append(\n k,\n v instanceof Date\n ? v.toISOString()\n : typeof v === 'object'\n ? JSON.stringify(v)\n : v.toString()\n );\n }\n });\n body = params.toString();\n }\n if (!headers['Content-Type']) {\n headers['Content-Type'] = 'application/x-www-form-urlencoded';\n }\n } else {\n body = JSON.stringify(body);\n headers['Content-Type'] = 'application/json';\n }\n }\n }\n\n let signaller;\n if (AbortSignal.timeout) {\n const ms = sdkTimeout(options) * 1000;\n let signaller = AbortSignal.timeout(ms);\n if ('signal' in options && options.signal) {\n // AbortSignal.any may not be available, tolerate its absence\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (AbortSignal.any) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n signaller = AbortSignal.any([options.signal, signaller]);\n } else {\n console.debug(\n 'Cannot combine cancel signal and timeout. AbortSignal.any is not available in this transport.'\n );\n console.debug({ AbortSignal });\n }\n } else {\n console.debug(\n 'AbortSignal.timeout is not defined. Timeout will use default behavior'\n );\n }\n }\n\n let props: IRequestProps = {\n body,\n credentials: 'same-origin',\n headers,\n method,\n url: path,\n signal: signaller,\n };\n\n if (authenticator) {\n // Add authentication information to the request\n props = await authenticator(props);\n }\n\n // Transform to HTTP request headers at the last second\n // props.headers = new Headers(props.headers) as any;\n\n return props;\n }\n}\n"],"mappings":";;;;;;AA4BA,IAAAA,UAAA,GAAAC,OAAA;AAOqB,SAAAC,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAAU,cAAAZ,CAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAY,SAAA,CAAAC,MAAA,EAAAb,CAAA,UAAAC,CAAA,WAAAW,SAAA,CAAAZ,CAAA,IAAAY,SAAA,CAAAZ,CAAA,QAAAA,CAAA,OAAAF,OAAA,CAAAI,MAAA,CAAAD,CAAA,OAAAa,OAAA,WAAAd,CAAA,IAAAe,eAAA,CAAAhB,CAAA,EAAAC,CAAA,EAAAC,CAAA,CAAAD,CAAA,SAAAE,MAAA,CAAAc,yBAAA,GAAAd,MAAA,CAAAe,gBAAA,CAAAlB,CAAA,EAAAG,MAAA,CAAAc,yBAAA,CAAAf,CAAA,KAAAH,OAAA,CAAAI,MAAA,CAAAD,CAAA,GAAAa,OAAA,WAAAd,CAAA,IAAAE,MAAA,CAAAgB,cAAA,CAAAnB,CAAA,EAAAC,CAAA,EAAAE,MAAA,CAAAK,wBAAA,CAAAN,CAAA,EAAAD,CAAA,iBAAAD,CA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UACLM,OAAO,CAACC,KAAK,CACX,uEACF,CAAC;QACH;MACF;MAEA,IAAIC,KAAoB,GAAG;QACzBtC,IAAI;QACJuC,WAAW,EAAE,aAAa;QAC1B9B,OAAO;QACPV,MAAM;QACNyC,GAAG,EAAEjD,IAAI;QACT2C,MAAM,EAAEL;MACV,CAAC;MAED,IAAI5B,aAAa,EAAE;QAEjBqC,KAAK,SAASrC,aAAa,CAACqC,KAAK,CAAC;MACpC;MAKA,OAAOA,KAAK;IAAC;EACf;AACF;AAACG,OAAA,CAAA5D,aAAA,GAAAA,aAAA"}
@@ -39,8 +39,33 @@ export class BaseTransport {
39
39
  body = undefined;
40
40
  } else {
41
41
  if (typeof body !== 'string') {
42
- body = JSON.stringify(body);
43
- headers['Content-Type'] = 'application/json';
42
+ var isUrlEncoded = body instanceof URLSearchParams;
43
+ if (!isUrlEncoded) {
44
+ isUrlEncoded = Object.keys(headers).some(k => {
45
+ var _headers$k;
46
+ return k.toLowerCase() === 'content-type' && ((_headers$k = headers[k]) === null || _headers$k === void 0 ? void 0 : _headers$k.toString().includes('application/x-www-form-urlencoded'));
47
+ });
48
+ }
49
+ if (isUrlEncoded) {
50
+ if (body instanceof URLSearchParams) {
51
+ body = body.toString();
52
+ } else {
53
+ var params = new URLSearchParams();
54
+ Object.entries(body).forEach(_ref => {
55
+ var [k, v] = _ref;
56
+ if (v !== undefined && v !== null) {
57
+ params.append(k, v instanceof Date ? v.toISOString() : typeof v === 'object' ? JSON.stringify(v) : v.toString());
58
+ }
59
+ });
60
+ body = params.toString();
61
+ }
62
+ if (!headers['Content-Type']) {
63
+ headers['Content-Type'] = 'application/x-www-form-urlencoded';
64
+ }
65
+ } else {
66
+ body = JSON.stringify(body);
67
+ headers['Content-Type'] = 'application/json';
68
+ }
44
69
  }
45
70
  }
46
71
  var signaller;
@@ -1 +1 @@
1
- {"version":3,"file":"baseTransport.js","names":["StatusCode","addQueryParams","agentPrefix","mergeOptions","LookerAppId","sdkTimeout","BaseTransport","constructor","options","_defineProperty","undefined","ok","res","statusCode","OK","IMUsed","makeUrl","path","queryParams","base","base_url","match","concat","initRequest","method","body","authenticator","_this","_asyncToGenerator","_options","_options2","_options$headers","agentTag","agent","headers","_objectSpread","JSON","stringify","signaller","AbortSignal","timeout","ms","signal","any","console","debug","props","credentials","url"],"sources":["../../src/baseTransport.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\n/* eslint-disable no-console */\n\nimport {\n StatusCode,\n addQueryParams,\n agentPrefix,\n mergeOptions,\n LookerAppId,\n sdkTimeout,\n} from './transport';\nimport type {\n Authenticator,\n HttpMethod,\n IRawRequest,\n IRawResponse,\n ITransport,\n ITransportSettings,\n RawObserver,\n SDKResponse,\n Values,\n IRequestProps,\n} from './transport';\n\nexport abstract class BaseTransport implements ITransport {\n protected constructor(protected readonly options: ITransportSettings) {\n this.options = options;\n }\n\n observer: RawObserver | undefined = undefined;\n\n abstract parseResponse<TSuccess, TError>(\n raw: IRawResponse\n ): Promise<SDKResponse<TSuccess, TError>>;\n\n ok(res: IRawResponse): boolean {\n return (\n res.statusCode >= StatusCode.OK && res.statusCode <= StatusCode.IMUsed\n );\n }\n\n /**\n * HTTP request function for atomic, fully downloaded raw HTTP responses\n *\n * NOTE: This method has no error handling. It simply returns the results of the HTTP request.\n *\n * @param method of HTTP request\n * @param path request path, either relative or fully specified\n * @param queryParams name/value pairs to pass as part of the URL\n * @param body data for the body of the request\n * @param authenticator authenticator callback, typically from `IAuthSession` implementation\n * @param options overrides of default transport settings\n * @returns typed response of `TSuccess`, or `TError` result\n */\n abstract rawRequest(\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<IRawResponse>;\n\n /**\n * Request a streaming response\n * @param method HTTP method\n * @param path Request path\n * @param queryParams query parameters for the request\n * @param body http body to include with request\n * @param authenticator callback to add authentication information to the request\n * @param options transport settings overrides\n */\n abstract request<TSuccess, TError>(\n method: HttpMethod,\n path: string,\n queryParams?: any,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>;\n\n /**\n * Request a streaming response\n * @param callback A function will be called with the created HTTP response object\n * @param method HTTP method\n * @param path Request path\n * @param queryParams parameters for the request\n * @param body http body to include with request\n * @param authenticator callback to add authentication information to the request\n * @param options transport settings overrides\n * @returns the streaming response\n */\n abstract stream<TSuccess>(\n callback: (response: Response) => Promise<TSuccess>,\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<TSuccess>;\n\n /**\n * Determine whether the url should be an API path, relative from base_url, or is already fully specified override\n * @param path Request path\n * @param options Transport settings\n * @param queryParams Collection of query Params\n * @returns the fully specified request path including any query string parameters\n */\n makeUrl(\n path: string,\n options: Partial<ITransportSettings>,\n queryParams?: Values\n ) {\n // is this an API-versioned call?\n const base = options.base_url;\n if (!path.match(/^(http:\\/\\/|https:\\/\\/)/gi)) {\n path = `${base}${path}`; // path was relative\n }\n path = addQueryParams(path, queryParams);\n return path;\n }\n\n abstract retry(wait: IRawRequest): Promise<IRawResponse>;\n\n protected async initRequest(\n method: HttpMethod,\n path: string,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ) {\n const agentTag = options?.agentTag || this.options.agentTag || agentPrefix;\n const agent = { headers: { [LookerAppId]: agentTag } };\n options = mergeOptions({ ...this.options, ...agent }, options ?? {});\n const headers = options.headers ?? {};\n\n // Make sure an empty body is undefined\n if (!body) {\n body = undefined;\n } else {\n if (typeof body !== 'string') {\n body = JSON.stringify(body);\n headers['Content-Type'] = 'application/json';\n }\n }\n\n let signaller;\n if (AbortSignal.timeout) {\n const ms = sdkTimeout(options) * 1000;\n let signaller = AbortSignal.timeout(ms);\n if ('signal' in options && options.signal) {\n // AbortSignal.any may not be available, tolerate its absence\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (AbortSignal.any) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n signaller = AbortSignal.any([options.signal, signaller]);\n } else {\n console.debug(\n 'Cannot combine cancel signal and timeout. AbortSignal.any is not available in this transport.'\n );\n console.debug({ AbortSignal });\n }\n } else {\n console.debug(\n 'AbortSignal.timeout is not defined. Timeout will use default behavior'\n );\n }\n }\n\n let props: IRequestProps = {\n body,\n credentials: 'same-origin',\n headers,\n method,\n url: path,\n signal: signaller,\n };\n\n if (authenticator) {\n // Add authentication information to the request\n props = await authenticator(props);\n }\n\n // Transform to HTTP request headers at the last second\n // props.headers = new Headers(props.headers) as any;\n\n return props;\n }\n}\n"],"mappings":";;;;;;;AA4BA,SACEA,UAAU,EACVC,cAAc,EACdC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,UAAU,QACL,aAAa;AAcpB,OAAO,MAA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StatusCode","addQueryParams","agentPrefix","mergeOptions","LookerAppId","sdkTimeout","BaseTransport","constructor","options","_defineProperty","undefined","ok","res","statusCode","OK","IMUsed","makeUrl","path","queryParams","base","base_url","match","concat","initRequest","method","body","authenticator","_this","_asyncToGenerator","_options","_options2","_options$headers","agentTag","agent","headers","_objectSpread","isUrlEncoded","URLSearchParams","Object","keys","some","k","_headers$k","toLowerCase","toString","includes","params","entries","forEach","_ref","v","append","Date","toISOString","JSON","stringify","signaller","AbortSignal","timeout","ms","signal","any","console","debug","props","credentials","url"],"sources":["../../src/baseTransport.ts"],"sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\n/* eslint-disable no-console */\n\nimport {\n StatusCode,\n addQueryParams,\n agentPrefix,\n mergeOptions,\n LookerAppId,\n sdkTimeout,\n} from './transport';\nimport type {\n Authenticator,\n HttpMethod,\n IRawRequest,\n IRawResponse,\n ITransport,\n ITransportSettings,\n RawObserver,\n SDKResponse,\n Values,\n IRequestProps,\n} from './transport';\n\nexport abstract class BaseTransport implements ITransport {\n protected constructor(protected readonly options: ITransportSettings) {\n this.options = options;\n }\n\n observer: RawObserver | undefined = undefined;\n\n abstract parseResponse<TSuccess, TError>(\n raw: IRawResponse\n ): Promise<SDKResponse<TSuccess, TError>>;\n\n ok(res: IRawResponse): boolean {\n return (\n res.statusCode >= StatusCode.OK && res.statusCode <= StatusCode.IMUsed\n );\n }\n\n /**\n * HTTP request function for atomic, fully downloaded raw HTTP responses\n *\n * NOTE: This method has no error handling. It simply returns the results of the HTTP request.\n *\n * @param method of HTTP request\n * @param path request path, either relative or fully specified\n * @param queryParams name/value pairs to pass as part of the URL\n * @param body data for the body of the request\n * @param authenticator authenticator callback, typically from `IAuthSession` implementation\n * @param options overrides of default transport settings\n * @returns typed response of `TSuccess`, or `TError` result\n */\n abstract rawRequest(\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<IRawResponse>;\n\n /**\n * Request a streaming response\n * @param method HTTP method\n * @param path Request path\n * @param queryParams query parameters for the request\n * @param body http body to include with request\n * @param authenticator callback to add authentication information to the request\n * @param options transport settings overrides\n */\n abstract request<TSuccess, TError>(\n method: HttpMethod,\n path: string,\n queryParams?: any,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<SDKResponse<TSuccess, TError>>;\n\n /**\n * Request a streaming response\n * @param callback A function will be called with the created HTTP response object\n * @param method HTTP method\n * @param path Request path\n * @param queryParams parameters for the request\n * @param body http body to include with request\n * @param authenticator callback to add authentication information to the request\n * @param options transport settings overrides\n * @returns the streaming response\n */\n abstract stream<TSuccess>(\n callback: (response: Response) => Promise<TSuccess>,\n method: HttpMethod,\n path: string,\n queryParams?: Values,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ): Promise<TSuccess>;\n\n /**\n * Determine whether the url should be an API path, relative from base_url, or is already fully specified override\n * @param path Request path\n * @param options Transport settings\n * @param queryParams Collection of query Params\n * @returns the fully specified request path including any query string parameters\n */\n makeUrl(\n path: string,\n options: Partial<ITransportSettings>,\n queryParams?: Values\n ) {\n // is this an API-versioned call?\n const base = options.base_url;\n if (!path.match(/^(http:\\/\\/|https:\\/\\/)/gi)) {\n path = `${base}${path}`; // path was relative\n }\n path = addQueryParams(path, queryParams);\n return path;\n }\n\n abstract retry(wait: IRawRequest): Promise<IRawResponse>;\n\n protected async initRequest(\n method: HttpMethod,\n path: string,\n body?: any,\n authenticator?: Authenticator,\n options?: Partial<ITransportSettings>\n ) {\n const agentTag = options?.agentTag || this.options.agentTag || agentPrefix;\n const agent = { headers: { [LookerAppId]: agentTag } };\n options = mergeOptions({ ...this.options, ...agent }, options ?? {});\n const headers = options.headers ?? {};\n\n // Make sure an empty body is undefined\n if (!body) {\n body = undefined;\n } else {\n if (typeof body !== 'string') {\n let isUrlEncoded = body instanceof URLSearchParams;\n if (!isUrlEncoded) {\n isUrlEncoded = Object.keys(headers).some(\n k =>\n k.toLowerCase() === 'content-type' &&\n headers[k]\n ?.toString()\n .includes('application/x-www-form-urlencoded')\n );\n }\n\n if (isUrlEncoded) {\n if (body instanceof URLSearchParams) {\n body = body.toString();\n } else {\n const params = new URLSearchParams();\n Object.entries(body as any).forEach(([k, v]) => {\n if (v !== undefined && v !== null) {\n params.append(\n k,\n v instanceof Date\n ? v.toISOString()\n : typeof v === 'object'\n ? JSON.stringify(v)\n : v.toString()\n );\n }\n });\n body = params.toString();\n }\n if (!headers['Content-Type']) {\n headers['Content-Type'] = 'application/x-www-form-urlencoded';\n }\n } else {\n body = JSON.stringify(body);\n headers['Content-Type'] = 'application/json';\n }\n }\n }\n\n let signaller;\n if (AbortSignal.timeout) {\n const ms = sdkTimeout(options) * 1000;\n let signaller = AbortSignal.timeout(ms);\n if ('signal' in options && options.signal) {\n // AbortSignal.any may not be available, tolerate its absence\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n if (AbortSignal.any) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n signaller = AbortSignal.any([options.signal, signaller]);\n } else {\n console.debug(\n 'Cannot combine cancel signal and timeout. AbortSignal.any is not available in this transport.'\n );\n console.debug({ AbortSignal });\n }\n } else {\n console.debug(\n 'AbortSignal.timeout is not defined. Timeout will use default behavior'\n );\n }\n }\n\n let props: IRequestProps = {\n body,\n credentials: 'same-origin',\n headers,\n method,\n url: path,\n signal: signaller,\n };\n\n if (authenticator) {\n // Add authentication information to the request\n props = await authenticator(props);\n }\n\n // Transform to HTTP request headers at the last second\n // props.headers = new Headers(props.headers) as any;\n\n return props;\n }\n}\n"],"mappings":";;;;;;;AA4BA,SACEA,UAAU,EACVC,cAAc,EACdC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,UAAU,QACL,aAAa;AAcpB,OAAO,MAAeC,aAAa,CAAuB;EAC9CC,WAAWA,CAAoBC,OAA2B,EAAE;IAAA,KAA7BA,OAA2B,GAA3BA,OAA2B;IAAAC,eAAA,mBAIhCC,SAAS;IAH3C,IAAI,CAACF,OAAO,GAAGA,OAAO;EACxB;EAQAG,EAAEA,CAACC,GAAiB,EAAW;IAC7B,OACEA,GAAG,CAACC,UAAU,IAAIb,UAAU,CAACc,EAAE,IAAIF,GAAG,CAACC,UAAU,IAAIb,UAAU,CAACe,MAAM;EAE1E;EAsEAC,OAAOA,CACLC,IAAY,EACZT,OAAoC,EACpCU,WAAoB,EACpB;IAEA,IAAMC,IAAI,GAAGX,OAAO,CAACY,QAAQ;IAC7B,IAAI,CAACH,IAAI,CAACI,KAAK,CAAC,2BAA2B,CAAC,EAAE;MAC5CJ,IAAI,MAAAK,MAAA,CAAMH,IAAI,EAAAG,MAAA,CAAGL,IAAI,CAAE;IACzB;IACAA,IAAI,GAAGhB,cAAc,CAACgB,IAAI,EAAEC,WAAW,CAAC;IACxC,OAAOD,I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AACI,GAAG,CAAC,CAACrD,OAAO,CAACoD,MAAM,EAAEJ,UAAS,CAAC,CAAC;UAC1D,CAAC,MAAM;YACLM,OAAO,CAACC,KAAK,CACX,+FACF,CAAC;YACDD,OAAO,CAACC,KAAK,CAAC;cAAEN;YAAY,CAAC,CAAC;UAChC;QACF,CAAC,MAAM;UACLK,OAAO,CAACC,KAAK,CACX,uEACF,CAAC;QACH;MACF;MAEA,IAAIC,KAAoB,GAAG;QACzBvC,IAAI;QACJwC,WAAW,EAAE,aAAa;QAC1B/B,OAAO;QACPV,MAAM;QACN0C,GAAG,EAAEjD,IAAI;QACT2C,MAAM,EAAEJ;MACV,CAAC;MAED,IAAI9B,aAAa,EAAE;QAEjBsC,KAAK,SAAStC,aAAa,CAACsC,KAAK,CAAC;MACpC;MAKA,OAAOA,KAAK;IAAC;EACf;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@looker/sdk-rtl",
3
- "version": "21.6.4",
3
+ "version": "21.6.5",
4
4
  "description": "Looker SDK Runtime Library",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/esm/index.js",
@@ -43,5 +43,5 @@
43
43
  "SDK",
44
44
  "RTL"
45
45
  ],
46
- "gitHead": "4f7632b94e4b0e53380ba95aaebbe7ed789ac9ca"
46
+ "gitHead": "77fc3b4d67ce3c1f12a0a0670f3d04f4b07d9d63"
47
47
  }