@wise/dynamic-flow-client-internal 3.11.2-experimental-7d4fc19 → 3.11.2-experimental-26093dd

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.
@@ -49,34 +49,78 @@ import { jsx as _jsx } from "react/jsx-runtime";
49
49
  import { waitFor } from '@testing-library/react';
50
50
  import { renderWithProviders } from '../test-utils/rtl-utils';
51
51
  import { DynamicFlowLegacy, DynamicFlowRevamp, DynamicFragment } from './DynamicFlow';
52
+ import { makeCustomFetch } from '..';
52
53
  describe.each([
53
54
  { name: 'DynamicFlowLegacy', DFComponent: DynamicFlowLegacy },
54
55
  { name: 'DynamicFlowRevamp', DFComponent: DynamicFlowRevamp },
55
56
  { name: 'DynamicFragment', DFComponent: DynamicFragment },
56
57
  ])('Wise-Specific Headers', function (_a) {
57
58
  var name = _a.name, DFComponent = _a.DFComponent;
59
+ var originalFetch;
60
+ var spyFetch;
61
+ beforeEach(function () {
62
+ originalFetch = global.fetch;
63
+ spyFetch = jest.spyOn(global, 'fetch').mockImplementation();
64
+ });
65
+ afterEach(function () {
66
+ global.fetch = originalFetch;
67
+ jest.clearAllMocks();
68
+ });
58
69
  it("".concat(name, " - makes an initial request with additional RequestInit parameters, as specified in the wise-specific fetcher"), function () { return __awaiter(void 0, void 0, void 0, function () {
59
- var props, customFetch, requestInit, credentials;
70
+ var props, requestInit, credentials;
60
71
  return __generator(this, function (_a) {
61
72
  switch (_a.label) {
62
73
  case 0:
63
74
  props = {
64
75
  flowId: 'test',
65
- customFetch: jest.fn(),
66
76
  initialAction: { url: '/initial' },
67
77
  onCompletion: jest.fn(),
68
78
  onError: jest.fn(),
69
79
  };
70
- customFetch = jest.fn();
71
- renderWithProviders(_jsx(DFComponent, __assign({}, props, { customFetch: customFetch })));
80
+ renderWithProviders(_jsx(DFComponent, __assign({}, props)));
72
81
  return [4 /*yield*/, waitFor(function () {
73
- expect(customFetch).toHaveBeenCalledWith('/initial', expect.anything());
82
+ expect(spyFetch).toHaveBeenCalledWith('/initial', expect.anything());
74
83
  })];
75
84
  case 1:
76
85
  _a.sent();
77
- requestInit = customFetch.mock.calls[0][1];
86
+ requestInit = spyFetch.mock.calls[0][1];
78
87
  credentials = requestInit === null || requestInit === void 0 ? void 0 : requestInit.credentials;
79
88
  expect(credentials).toBe('include');
89
+ expect(requestInit === null || requestInit === void 0 ? void 0 : requestInit.headers).toEqual({
90
+ 'content-type': 'application/json',
91
+ 'accept-language': 'en-GB',
92
+ });
93
+ return [2 /*return*/];
94
+ }
95
+ });
96
+ }); });
97
+ it("".concat(name, " - makes an initial reques with the 'content-type': 'application/json' header, regardless of the additional headers from makeCustomFetch"), function () { return __awaiter(void 0, void 0, void 0, function () {
98
+ var props, requestInit;
99
+ return __generator(this, function (_a) {
100
+ switch (_a.label) {
101
+ case 0:
102
+ props = {
103
+ flowId: 'test',
104
+ initialAction: { url: '/initial' },
105
+ customFetch: makeCustomFetch('', {
106
+ 'content-type': 'WRONG-CONTENT-TYPE',
107
+ 'x-other': 'something else',
108
+ }),
109
+ onCompletion: jest.fn(),
110
+ onError: jest.fn(),
111
+ };
112
+ renderWithProviders(_jsx(DFComponent, __assign({}, props)));
113
+ return [4 /*yield*/, waitFor(function () {
114
+ expect(spyFetch).toHaveBeenCalledWith('/initial', expect.anything());
115
+ })];
116
+ case 1:
117
+ _a.sent();
118
+ requestInit = spyFetch.mock.calls[0][1];
119
+ expect(requestInit === null || requestInit === void 0 ? void 0 : requestInit.headers).toEqual({
120
+ 'content-type': 'application/json',
121
+ 'accept-language': 'en-GB',
122
+ 'x-other': 'something else',
123
+ });
80
124
  return [2 /*return*/];
81
125
  }
82
126
  });
@@ -9,7 +9,7 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- export var mergeRequestInit = function (init, additionalInit) { return (__assign(__assign(__assign({}, init), additionalInit), { headers: mergeHeaders(init === null || init === void 0 ? void 0 : init.headers, additionalInit === null || additionalInit === void 0 ? void 0 : additionalInit.headers) })); };
12
+ export var mergeRequestInit = function (lhs, rhs) { return (__assign(__assign(__assign({}, lhs), rhs), { headers: mergeHeaders(lhs === null || lhs === void 0 ? void 0 : lhs.headers, rhs === null || rhs === void 0 ? void 0 : rhs.headers) })); };
13
13
  var mergeHeaders = function () {
14
14
  var headersInits = [];
15
15
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -13,6 +13,36 @@ describe('mergeRequestInit', function () {
13
13
  });
14
14
  });
15
15
  });
16
+ it('merges the two objects and the headers, prioritising the additionalInit headers in case they match', function () {
17
+ var result = mergeRequestInit({ credentials: 'include', headers: { 'Content-Type': 'lhs-header' } }, { method: 'POST', headers: { 'Content-Type': 'rhs-header' } });
18
+ expect(result).toMatchObject({
19
+ credentials: 'include',
20
+ method: 'POST',
21
+ });
22
+ expect(result.headers).toMatchObject({
23
+ 'content-type': 'rhs-header',
24
+ });
25
+ });
26
+ describe('when called with RequestInits with Headers instances', function () {
27
+ it('merges the two objects and the headers, prioritising the init headers in case they match', function () {
28
+ var result = mergeRequestInit({ headers: new Headers([['Content-Type', 'lhs-header']]) }, {
29
+ headers: new Headers([['Content-Type', 'rhs-header']]),
30
+ });
31
+ expect(result.headers).toMatchObject({
32
+ 'content-type': 'rhs-header',
33
+ });
34
+ });
35
+ });
36
+ describe('when called with RequestInits with Array headers', function () {
37
+ it('merges the two objects and the headers, prioritising the init headers in case they match', function () {
38
+ var result = mergeRequestInit({ headers: [['Content-Type', 'lhs-header']] }, {
39
+ headers: [['Content-Type', 'rhs-header']],
40
+ });
41
+ expect(result.headers).toMatchObject({
42
+ 'content-type': 'rhs-header',
43
+ });
44
+ });
45
+ });
16
46
  describe('when called with undefined as a first argument', function () {
17
47
  it('returns the second argument and empty headers', function () {
18
48
  var result = mergeRequestInit(undefined, { method: 'POST' });
package/build/main.js CHANGED
@@ -56,8 +56,8 @@ var import_react_intl = require("react-intl");
56
56
  var import_dynamic_flow_client = require("@wise/dynamic-flow-client");
57
57
 
58
58
  // src/dynamicFlow/utils/mergeRequestInit.ts
59
- var mergeRequestInit = (init, additionalInit) => __spreadProps(__spreadValues(__spreadValues({}, init), additionalInit), {
60
- headers: mergeHeaders(init == null ? void 0 : init.headers, additionalInit == null ? void 0 : additionalInit.headers)
59
+ var mergeRequestInit = (lhs, rhs) => __spreadProps(__spreadValues(__spreadValues({}, lhs), rhs), {
60
+ headers: mergeHeaders(lhs == null ? void 0 : lhs.headers, rhs == null ? void 0 : rhs.headers)
61
61
  });
62
62
  var mergeHeaders = (...headersInits) => headersInits.reduce(
63
63
  (acc, headers) => __spreadValues(__spreadValues({}, acc), Object.fromEntries(new Headers(headers).entries())),
package/build/main.min.js CHANGED
@@ -1 +1 @@
1
- "use strict";var s=Object.defineProperty,d=Object.defineProperties,v=Object.getOwnPropertyDescriptor,I=Object.getOwnPropertyDescriptors,W=Object.getOwnPropertyNames,w=Object.getOwnPropertySymbols;var h=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable;var D=(t,e,o)=>e in t?s(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,n=(t,e)=>{for(var o in e||(e={}))h.call(e,o)&&D(t,o,e[o]);if(w)for(var o of w(e))x.call(e,o)&&D(t,o,e[o]);return t},r=(t,e)=>d(t,I(e));var L=(t,e)=>{for(var o in e)s(t,o,{get:e[o],enumerable:!0})},b=(t,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of W(e))!h.call(t,c)&&c!==o&&s(t,c,{get:()=>e[c],enumerable:!(a=v(e,c))||a.enumerable});return t};var S=t=>b(s({},"__esModule",{value:!0}),t);var H={};L(H,{DynamicFlow:()=>y,DynamicFlowLegacy:()=>y,DynamicFlowRevamp:()=>P,DynamicFragment:()=>u,JsonSchemaForm:()=>m.JsonSchemaForm,isValidSchema:()=>m.isValidSchema,makeCustomFetch:()=>A,translations:()=>m.translations});module.exports=S(H);var R=require("@wise/dynamic-flow-client"),m=require("@wise/dynamic-flow-client");var l=require("react"),f=require("react-intl"),i=require("@wise/dynamic-flow-client");var g=(t,e)=>r(n(n({},t),e),{headers:q(t==null?void 0:t.headers,e==null?void 0:e.headers)}),q=(...t)=>t.reduce((e,o)=>n(n({},e),Object.fromEntries(new Headers(o).entries())),{});var p=require("react/jsx-runtime");function y(t){let{customFetch:e=globalThis.fetch}=t,o=F(e),a=r(n({},t),{httpClient:o});return(0,p.jsx)(i.DynamicFlow,n({},a))}function P(t){let{customFetch:e=globalThis.fetch}=t,o=F(e),a=r(n({},t),{httpClient:o});return(0,p.jsx)(i.DynamicFlowRevamp,n({},a))}var u=(0,l.forwardRef)(function(e,o){let{customFetch:a=globalThis.fetch}=e,c=F(a),C=r(n({},e),{httpClient:c});return(0,p.jsx)(i.DynamicFragmentWise,r(n({},C),{ref:o}))}),F=t=>{let{locale:e}=(0,f.useIntl)();return(0,l.useCallback)(async(o,a)=>t(o,g(a,{credentials:"include",headers:{"accept-language":e}})),[t,e])};var A=R.makeHttpClient;
1
+ "use strict";var l=Object.defineProperty,C=Object.defineProperties,v=Object.getOwnPropertyDescriptor,I=Object.getOwnPropertyDescriptors,W=Object.getOwnPropertyNames,w=Object.getOwnPropertySymbols;var g=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable;var D=(t,e,o)=>e in t?l(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,i=(t,e)=>{for(var o in e||(e={}))g.call(e,o)&&D(t,o,e[o]);if(w)for(var o of w(e))x.call(e,o)&&D(t,o,e[o]);return t},c=(t,e)=>C(t,I(e));var L=(t,e)=>{for(var o in e)l(t,o,{get:e[o],enumerable:!0})},b=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of W(e))!g.call(t,a)&&a!==o&&l(t,a,{get:()=>e[a],enumerable:!(n=v(e,a))||n.enumerable});return t};var S=t=>b(l({},"__esModule",{value:!0}),t);var H={};L(H,{DynamicFlow:()=>y,DynamicFlowLegacy:()=>y,DynamicFlowRevamp:()=>P,DynamicFragment:()=>d,JsonSchemaForm:()=>m.JsonSchemaForm,isValidSchema:()=>m.isValidSchema,makeCustomFetch:()=>A,translations:()=>m.translations});module.exports=S(H);var u=require("@wise/dynamic-flow-client"),m=require("@wise/dynamic-flow-client");var p=require("react"),h=require("react-intl"),r=require("@wise/dynamic-flow-client");var f=(t,e)=>c(i(i({},t),e),{headers:q(t==null?void 0:t.headers,e==null?void 0:e.headers)}),q=(...t)=>t.reduce((e,o)=>i(i({},e),Object.fromEntries(new Headers(o).entries())),{});var s=require("react/jsx-runtime");function y(t){let{customFetch:e=globalThis.fetch}=t,o=F(e),n=c(i({},t),{httpClient:o});return(0,s.jsx)(r.DynamicFlow,i({},n))}function P(t){let{customFetch:e=globalThis.fetch}=t,o=F(e),n=c(i({},t),{httpClient:o});return(0,s.jsx)(r.DynamicFlowRevamp,i({},n))}var d=(0,p.forwardRef)(function(e,o){let{customFetch:n=globalThis.fetch}=e,a=F(n),R=c(i({},e),{httpClient:a});return(0,s.jsx)(r.DynamicFragmentWise,c(i({},R),{ref:o}))}),F=t=>{let{locale:e}=(0,h.useIntl)();return(0,p.useCallback)(async(o,n)=>t(o,f(n,{credentials:"include",headers:{"accept-language":e}})),[t,e])};var A=u.makeHttpClient;
package/build/main.mjs CHANGED
@@ -32,8 +32,8 @@ import {
32
32
  } from "@wise/dynamic-flow-client";
33
33
 
34
34
  // src/dynamicFlow/utils/mergeRequestInit.ts
35
- var mergeRequestInit = (init, additionalInit) => __spreadProps(__spreadValues(__spreadValues({}, init), additionalInit), {
36
- headers: mergeHeaders(init == null ? void 0 : init.headers, additionalInit == null ? void 0 : additionalInit.headers)
35
+ var mergeRequestInit = (lhs, rhs) => __spreadProps(__spreadValues(__spreadValues({}, lhs), rhs), {
36
+ headers: mergeHeaders(lhs == null ? void 0 : lhs.headers, rhs == null ? void 0 : rhs.headers)
37
37
  });
38
38
  var mergeHeaders = (...headersInits) => headersInits.reduce(
39
39
  (acc, headers) => __spreadValues(__spreadValues({}, acc), Object.fromEntries(new Headers(headers).entries())),
@@ -1 +1 @@
1
- export declare const mergeRequestInit: (init?: RequestInit, additionalInit?: RequestInit) => RequestInit;
1
+ export declare const mergeRequestInit: (lhs?: RequestInit, rhs?: RequestInit) => RequestInit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise/dynamic-flow-client-internal",
3
- "version": "3.11.2-experimental-7d4fc19",
3
+ "version": "3.11.2-experimental-26093dd",
4
4
  "description": "Dynamic Flow web client for Wise",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./build/main.min.js",
@@ -80,7 +80,7 @@
80
80
  "react-intl": "^6"
81
81
  },
82
82
  "dependencies": {
83
- "@wise/dynamic-flow-client": "3.11.2-experimental-7d4fc19"
83
+ "@wise/dynamic-flow-client": "3.11.2-experimental-26093dd"
84
84
  },
85
85
  "scripts": {
86
86
  "dev": "storybook dev -p 3005",