@amityco/ts-sdk 7.34.1-0b076f5c.0 → 7.34.1-aaca0bfd.0

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.
@@ -3,7 +3,8 @@ declare global {
3
3
  namespace Amity {
4
4
  /**
5
5
  * What every {@link WidgetRepository} call carries. `coreVersion` is the
6
- * caller's own; `etag` sends `If-None-Match`.
6
+ * caller's own; `cursor` is the paging token, sent as `options[token]`;
7
+ * `etag` sends `If-None-Match`.
7
8
  */
8
9
  type WidgetCall = {
9
10
  coreVersion: string;
@@ -1 +1 @@
1
- {"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../../../src/@types/domains/widget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC;AAEV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC;QACd;;;WAGG;QACH,KAAK,UAAU,GAAG;YAChB,WAAW,EAAE,MAAM,CAAC;YACpB,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB,EAAE,CAAC,EAAE,MAAM,CAAC;YACZ,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;SACtB,CAAC;QAEF,gEAAgE;QAChE,KAAK,UAAU,GAAG;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,CAAC;QAEtE,iDAAiD;QACjD,KAAK,iBAAiB,GAAG;YAAE,IAAI,EAAE,aAAa,CAAA;SAAE,CAAC;QAEjD,qDAAqD;QACrD,KAAK,eAAe,GAAG;YAAE,IAAI,EAAE,WAAW,CAAA;SAAE,CAAC;QAE7C,KAAK,YAAY,GAAG,UAAU,GAAG,iBAAiB,GAAG,eAAe,CAAC;KACtE;CACF"}
1
+ {"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../../../src/@types/domains/widget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC;AAEV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC;QACd;;;;WAIG;QACH,KAAK,UAAU,GAAG;YAChB,WAAW,EAAE,MAAM,CAAC;YACpB,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB,EAAE,CAAC,EAAE,MAAM,CAAC;YACZ,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;SACtB,CAAC;QAEF,gEAAgE;QAChE,KAAK,UAAU,GAAG;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,CAAC;QAEtE,iDAAiD;QACjD,KAAK,iBAAiB,GAAG;YAAE,IAAI,EAAE,aAAa,CAAA;SAAE,CAAC;QAEjD,qDAAqD;QACrD,KAAK,eAAe,GAAG;YAAE,IAAI,EAAE,WAAW,CAAA;SAAE,CAAC;QAE7C,KAAK,YAAY,GAAG,UAAU,GAAG,iBAAiB,GAAG,eAAe,CAAC;KACtE;CACF"}
package/dist/index.cjs.js CHANGED
@@ -38931,12 +38931,28 @@ const widgetTarget = (url, endpoint, allowed) => {
38931
38931
  * @hidden
38932
38932
  */
38933
38933
  const widgetHeaders = (apiKey, call, json = false) => (Object.assign(Object.assign(Object.assign(Object.assign({}, (apiKey ? { 'X-API-Key': apiKey } : {})), { 'X-Widget-Platform': WIDGET_PLATFORM, 'X-Widget-Core-Version': call.coreVersion }), (call.etag ? { 'If-None-Match': call.etag } : {})), (json ? { 'Content-Type': 'application/json' } : {})));
38934
- /** The query of a call: `locale`, `tz` and `cursor` where they are given, in that order. */
38934
+ /**
38935
+ * The query of a call: `locale`, `tz` and the paging token where they are given, in that order.
38936
+ * The token (`cursor`) goes as core's `options[token]`, unread.
38937
+ */
38935
38938
  const widgetQuery = (call, keys) => keys.reduce((query, key) => {
38936
38939
  const value = call[key];
38937
38940
  const given = key === 'cursor' ? !!value : value !== undefined && value !== null;
38938
- return given ? Object.assign(Object.assign({}, query), { [key]: value }) : query;
38941
+ return given
38942
+ ? Object.assign(Object.assign({}, query), { [key === 'cursor' ? 'options[token]' : key]: value }) : query;
38939
38943
  }, {});
38944
+ /**
38945
+ * Drops `traceparent` from a widget request. The widget service's CORS does not
38946
+ * allow it yet, so a browser refuses the request; `x-request-id` still goes.
38947
+ * Remove once the service allows `traceparent`.
38948
+ *
38949
+ * @hidden
38950
+ */
38951
+ const withoutTraceparent = (data, headers) => {
38952
+ headers.delete('traceparent');
38953
+ return data;
38954
+ };
38955
+ const defaultTransforms = () => { var _a; return [(_a = axios__default["default"].defaults.transformRequest) !== null && _a !== void 0 ? _a : []].flat(); };
38940
38956
  const bodyText = (data) => {
38941
38957
  if (typeof data === 'string')
38942
38958
  return data;
@@ -38954,7 +38970,9 @@ const sendWidgetRequest = async ({ method, url, call, params, data, json, timeou
38954
38970
  var _a;
38955
38971
  const client = await widgetSession();
38956
38972
  const target = widgetTarget(url, client.http.defaults.baseURL, allowed);
38957
- const config = Object.assign(Object.assign(Object.assign({}, (target.baseURL ? { baseURL: target.baseURL } : {})), (params && Object.keys(params).length ? { params } : {})), { headers: widgetHeaders(client.apiKey, call, json), timeout, adapter: WIDGET_ADAPTERS, fetchOptions: { cache: 'no-store' }, responseType: 'text',
38973
+ const config = Object.assign(Object.assign(Object.assign({}, (target.baseURL ? { baseURL: target.baseURL } : {})), (params && Object.keys(params).length ? { params } : {})), { headers: widgetHeaders(client.apiKey, call, json), timeout, adapter: WIDGET_ADAPTERS, fetchOptions: { cache: 'no-store' },
38974
+ // transforms run after the client's interceptor has set traceparent
38975
+ transformRequest: [withoutTraceparent, ...defaultTransforms()], responseType: 'text',
38958
38976
  // every status is read here, not by the client's error interceptor
38959
38977
  validateStatus: () => true });
38960
38978
  let response;
@@ -38987,7 +39005,7 @@ const sendWidgetRequest = async ({ method, url, call, params, data, json, timeou
38987
39005
  * Fetches a slot's widget from the widget service. Nothing is cached or parsed.
38988
39006
  *
38989
39007
  * @param slotId The slot to fetch
38990
- * @param call What the call carries: `coreVersion`, and `locale`, `tz`, `cursor`, `etag`
39008
+ * @param call What the call carries: `coreVersion`, and `locale`, `tz`, `cursor` (sent as `options[token]`), `etag`
38991
39009
  * @returns The body, `notModified` (304) or `noContent` (204)
38992
39010
  * @throws {AmityWidgetError}
38993
39011
  *
package/dist/index.esm.js CHANGED
@@ -38931,12 +38931,28 @@ const widgetTarget = (url, endpoint, allowed) => {
38931
38931
  * @hidden
38932
38932
  */
38933
38933
  const widgetHeaders = (apiKey, call, json = false) => (Object.assign(Object.assign(Object.assign(Object.assign({}, (apiKey ? { 'X-API-Key': apiKey } : {})), { 'X-Widget-Platform': WIDGET_PLATFORM, 'X-Widget-Core-Version': call.coreVersion }), (call.etag ? { 'If-None-Match': call.etag } : {})), (json ? { 'Content-Type': 'application/json' } : {})));
38934
- /** The query of a call: `locale`, `tz` and `cursor` where they are given, in that order. */
38934
+ /**
38935
+ * The query of a call: `locale`, `tz` and the paging token where they are given, in that order.
38936
+ * The token (`cursor`) goes as core's `options[token]`, unread.
38937
+ */
38935
38938
  const widgetQuery = (call, keys) => keys.reduce((query, key) => {
38936
38939
  const value = call[key];
38937
38940
  const given = key === 'cursor' ? !!value : value !== undefined && value !== null;
38938
- return given ? Object.assign(Object.assign({}, query), { [key]: value }) : query;
38941
+ return given
38942
+ ? Object.assign(Object.assign({}, query), { [key === 'cursor' ? 'options[token]' : key]: value }) : query;
38939
38943
  }, {});
38944
+ /**
38945
+ * Drops `traceparent` from a widget request. The widget service's CORS does not
38946
+ * allow it yet, so a browser refuses the request; `x-request-id` still goes.
38947
+ * Remove once the service allows `traceparent`.
38948
+ *
38949
+ * @hidden
38950
+ */
38951
+ const withoutTraceparent = (data, headers) => {
38952
+ headers.delete('traceparent');
38953
+ return data;
38954
+ };
38955
+ const defaultTransforms = () => { var _a; return [(_a = axios.defaults.transformRequest) !== null && _a !== void 0 ? _a : []].flat(); };
38940
38956
  const bodyText = (data) => {
38941
38957
  if (typeof data === 'string')
38942
38958
  return data;
@@ -38954,7 +38970,9 @@ const sendWidgetRequest = async ({ method, url, call, params, data, json, timeou
38954
38970
  var _a;
38955
38971
  const client = await widgetSession();
38956
38972
  const target = widgetTarget(url, client.http.defaults.baseURL, allowed);
38957
- const config = Object.assign(Object.assign(Object.assign({}, (target.baseURL ? { baseURL: target.baseURL } : {})), (params && Object.keys(params).length ? { params } : {})), { headers: widgetHeaders(client.apiKey, call, json), timeout, adapter: WIDGET_ADAPTERS, fetchOptions: { cache: 'no-store' }, responseType: 'text',
38973
+ const config = Object.assign(Object.assign(Object.assign({}, (target.baseURL ? { baseURL: target.baseURL } : {})), (params && Object.keys(params).length ? { params } : {})), { headers: widgetHeaders(client.apiKey, call, json), timeout, adapter: WIDGET_ADAPTERS, fetchOptions: { cache: 'no-store' },
38974
+ // transforms run after the client's interceptor has set traceparent
38975
+ transformRequest: [withoutTraceparent, ...defaultTransforms()], responseType: 'text',
38958
38976
  // every status is read here, not by the client's error interceptor
38959
38977
  validateStatus: () => true });
38960
38978
  let response;
@@ -38987,7 +39005,7 @@ const sendWidgetRequest = async ({ method, url, call, params, data, json, timeou
38987
39005
  * Fetches a slot's widget from the widget service. Nothing is cached or parsed.
38988
39006
  *
38989
39007
  * @param slotId The slot to fetch
38990
- * @param call What the call carries: `coreVersion`, and `locale`, `tz`, `cursor`, `etag`
39008
+ * @param call What the call carries: `coreVersion`, and `locale`, `tz`, `cursor` (sent as `options[token]`), `etag`
38991
39009
  * @returns The body, `notModified` (304) or `noContent` (204)
38992
39010
  * @throws {AmityWidgetError}
38993
39011
  *