@availity/native-form 4.0.6 → 4.0.10

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
@@ -3,6 +3,38 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 4.0.10 (2021-12-21)
7
+
8
+ **Note:** Version bump only for package @availity/native-form
9
+
10
+
11
+
12
+
13
+
14
+ ## [4.0.9](https://github.com/Availity/sdk-js/compare/@availity/native-form@4.0.8...@availity/native-form@4.0.9) (2021-10-29)
15
+
16
+ **Note:** Version bump only for package @availity/native-form
17
+
18
+
19
+
20
+
21
+
22
+ ## [4.0.8](https://github.com/Availity/sdk-js/compare/@availity/native-form@4.0.7...@availity/native-form@4.0.8) (2021-10-22)
23
+
24
+ **Note:** Version bump only for package @availity/native-form
25
+
26
+
27
+
28
+
29
+
30
+ ## 4.0.7 (2021-10-20)
31
+
32
+ **Note:** Version bump only for package @availity/native-form
33
+
34
+
35
+
36
+
37
+
6
38
  ## [4.0.6](https://github.com/Availity/sdk-js/compare/@availity/native-form@4.0.5...@availity/native-form@4.0.6) (2021-10-19)
7
39
 
8
40
  **Note:** Version bump only for package @availity/native-form
package/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # native form
1
+ # @availity/native-form
2
2
 
3
3
  > Submit JSON data via a native form, not AJAX. Useful when you need to open a new page with a POST action.
4
4
 
5
5
  [![Version](https://img.shields.io/npm/v/@availity/native-form.svg?style=for-the-badge)](https://www.npmjs.com/package/@availity/native-form)
6
+ [![NPM Downloads](https://img.shields.io/npm/dt/@availity/native-form.svg?style=for-the-badge)](https://www.npmjs.com/package/@availity/native-form)
7
+ [![Dependecy Status](https://img.shields.io/librariesio/release/npm/@availity/native-form?style=for-the-badge)](https://github.com/Availity/sdk-js/blob/master/packages/native-form/package.json)
6
8
 
7
9
  ## Install
8
10
 
@@ -18,4 +20,6 @@ npm install @availity/native-form
18
20
  yarn add @availity/native-form
19
21
  ```
20
22
 
21
- ## [Documentation](https://availity.github.io/sdk-js/features/native-form)
23
+ ## Documentation
24
+
25
+ Check out more documentation at [availity.github.io](https://availity.github.io/sdk-js/resources/native-form)
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
3
5
  require("core-js/modules/es.object.to-string");
4
6
 
5
7
  Object.defineProperty(exports, "__esModule", {
@@ -7,8 +9,16 @@ Object.defineProperty(exports, "__esModule", {
7
9
  });
8
10
  exports["default"] = void 0;
9
11
 
12
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
13
+
10
14
  require("core-js/modules/es.regexp.to-string.js");
11
15
 
16
+ require("core-js/modules/esnext.async-iterator.reduce.js");
17
+
18
+ require("core-js/modules/esnext.iterator.constructor.js");
19
+
20
+ require("core-js/modules/esnext.iterator.reduce.js");
21
+
12
22
  require("core-js/modules/es.object.keys.js");
13
23
 
14
24
  require("core-js/modules/web.url.to-json.js");
@@ -28,7 +38,7 @@ var flattenObject = function flattenObject(ob) {
28
38
  return Object.keys(ob).reduce(function (toReturn, k) {
29
39
  if (Object.prototype.toString.call(ob[k]) === '[object Date]') {
30
40
  toReturn[k] = ob[k].toJSON();
31
- } else if (ob[k] && typeof ob[k] === 'object') {
41
+ } else if (ob[k] && (0, _typeof2["default"])(ob[k]) === 'object') {
32
42
  var flatObject = flattenObject(ob[k]);
33
43
  var isArray = Array.isArray(ob[k]);
34
44
 
package/lib/index.js CHANGED
@@ -15,6 +15,10 @@ require("core-js/modules/es.array.join.js");
15
15
 
16
16
  require("core-js/modules/es.array.map.js");
17
17
 
18
+ require("core-js/modules/esnext.async-iterator.map.js");
19
+
20
+ require("core-js/modules/esnext.iterator.map.js");
21
+
18
22
  require("core-js/modules/es.regexp.exec.js");
19
23
 
20
24
  require("core-js/modules/es.string.replace.js");
package/package.json CHANGED
@@ -1,33 +1,44 @@
1
1
  {
2
2
  "name": "@availity/native-form",
3
- "version": "4.0.6",
3
+ "version": "4.0.10",
4
4
  "description": "Submit JSON data via a native form, not AJAX. Useful when you need to open a new page with a POST action.",
5
- "main": "lib/index.js",
6
- "module": "src/index.js",
7
- "types": "types/index.d.ts",
8
- "scripts": {
9
- "test": "test"
10
- },
11
5
  "keywords": [
12
6
  "availity",
13
7
  "form",
14
8
  "native",
15
9
  "submission"
16
10
  ],
17
- "author": "Evan Sharp <evan.sharp@availity.com>",
11
+ "homepage": "https://availity.github.io/sdk-js/resources/native-form",
12
+ "bugs": {
13
+ "url": "https://github.com/availity/sdk-js/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/availity/sdk-js.git",
18
+ "directory": "packages/native-form"
19
+ },
18
20
  "license": "MIT",
19
- "publishConfig": {
20
- "access": "public"
21
+ "author": "Evan Sharp <evan.sharp@availity.com>",
22
+ "main": "lib/index.js",
23
+ "module": "src/index.js",
24
+ "types": "src/index.d.ts",
25
+ "scripts": {
26
+ "build": "yarn clean && yarn transpile",
27
+ "clean": "rimraf ./lib",
28
+ "transpile": "babel --root-mode upward src -d lib --ignore **/*.test.js"
21
29
  },
22
30
  "dependencies": {
23
- "@babel/runtime": "^7.10.2",
31
+ "@babel/runtime": "^7.16.5",
24
32
  "core-js": "^3.12.1"
25
33
  },
26
34
  "devDependencies": {
27
- "@availity/api-axios": "^6.0.2"
35
+ "@availity/api-axios": "^6.0.6"
28
36
  },
29
37
  "peerDependencies": {
30
38
  "@availity/api-axios": "^6.0.0"
31
39
  },
32
- "gitHead": "a5531289347963c0b9cef5494271441b1e7240d6"
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "gitHead": "1c3e8c8045b16fc5111f941d863600f0a97cdbff"
33
44
  }
@@ -1,3 +1,5 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
1
3
  type SsoType = 'saml' | 'openid';
2
4
 
3
5
  declare function nativeForm(
package/src/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { avWebQLApi } from '@availity/api-axios';
2
+
2
3
  import flattenObject from './flattenObject';
3
4
 
4
5
  const ssoTypeQuery = `
@@ -1,34 +0,0 @@
1
- import flattenObject from '../src/flattenObject';
2
-
3
- describe('flattenObject', () => {
4
- test('should flatten', () => {
5
- const obj = {
6
- int: 123,
7
- obj: {
8
- string: 'string',
9
- },
10
- };
11
-
12
- const flatObj = flattenObject(obj);
13
- expect(flatObj.int).toBe('123');
14
- expect(flatObj['obj.string']).toBe('string');
15
- });
16
-
17
- test('handles undefined', () => {
18
- const obj = {
19
- int: 0,
20
- false: false,
21
- undefined,
22
- obj: {
23
- int: 123,
24
- string: 'string',
25
- },
26
- };
27
-
28
- const flatObj = flattenObject(obj);
29
- expect(flatObj.int).toBe('0');
30
- expect(flatObj.false).toBe('false');
31
- expect(flatObj['obj.string']).toBe('string');
32
- expect(flatObj.undefined).toBeUndefined();
33
- });
34
- });
@@ -1,243 +0,0 @@
1
- import { avWebQLApi } from '@availity/api-axios';
2
- import nativeForm from '../src';
3
- import flattenObject from '../src/flattenObject';
4
-
5
- jest.mock('@availity/api-axios');
6
-
7
- describe('nativeForm', () => {
8
- const complexObject = {
9
- a: { b: 'c', d: 1, e: ['f', 'g', 2, 3, { h: { i: 'j', k: [4, 'l'] } }] },
10
- };
11
-
12
- describe('flattenObject', () => {
13
- test('should return an object', () => {
14
- expect(Object.prototype.toString.call(flattenObject({ a: { b: 'c' } }))).toBe('[object Object]');
15
- });
16
- describe('returned object', () => {
17
- let result;
18
- beforeEach(() => {
19
- result = flattenObject(complexObject);
20
- });
21
- test('should be 1 level deep', () => {
22
- for (const key of Object.keys(result)) {
23
- expect(Object.prototype.toString.call(result[key])).toBe('[object String]');
24
- }
25
- });
26
- test('should correctly represent the keys as dot notation', () => {
27
- const expected = {
28
- 'a.b': 'c',
29
- 'a.d': '1',
30
- 'a.e[0]': 'f',
31
- 'a.e[1]': 'g',
32
- 'a.e[2]': '2',
33
- 'a.e[3]': '3',
34
- 'a.e[4].h.i': 'j',
35
- 'a.e[4].h.k[0]': '4',
36
- 'a.e[4].h.k[1]': 'l',
37
- };
38
- expect(result).toEqual(expected);
39
- });
40
- });
41
- });
42
-
43
- describe('default export', () => {
44
- beforeEach(() => {
45
- window.HTMLFormElement.prototype.submit = jest.fn();
46
- });
47
-
48
- afterEach(() => {
49
- const form = document.querySelector('form');
50
- if (form) form.remove();
51
- });
52
-
53
- test('spaceId is required', async () => {
54
- await expect(() => nativeForm()).rejects.toThrow('spaceId is required and was not provided');
55
- });
56
-
57
- test('create a form', async () => {
58
- await nativeForm('spaceId', {}, {}, 'saml');
59
- expect(document.querySelector('form')).not.toBeNull();
60
- });
61
-
62
- describe('the form', () => {
63
- test('should be added to the body (to be able to be submitted)', async () => {
64
- await nativeForm('spaceId', {}, {}, 'saml');
65
- expect(document.body.querySelector('form')).not.toBeNull();
66
- });
67
-
68
- test('action should have the space id in the URL by default', async () => {
69
- await nativeForm('spaceId123', {}, {}, 'saml');
70
- expect(document.querySelector('form').getAttribute('action')).toBe(
71
- '/ms/api/availity/internal/spc/magneto/sso/v1/saml/spaceId123'
72
- );
73
- });
74
-
75
- test('action should be overridable', async () => {
76
- await nativeForm('spaceId123', {}, { action: '/my/url/here' }, 'saml');
77
- expect(document.querySelector('form').getAttribute('action')).toBe('/my/url/here');
78
- });
79
-
80
- test('action magneto integration type should be overridable', async () => {
81
- await nativeForm('spaceId123', {}, {}, 'openid');
82
- expect(document.querySelector('form').getAttribute('action')).toBe(
83
- '/ms/api/availity/internal/spc/magneto/sso/v1/openid/spaceId123'
84
- );
85
- });
86
-
87
- test('method should be post by default', async () => {
88
- await nativeForm('spaceId', {}, {}, 'saml');
89
- expect(document.querySelector('form').getAttribute('method')).toBe('post');
90
- });
91
-
92
- test('method should be overridable', async () => {
93
- await nativeForm('spaceId123', {}, { method: 'get' }, 'saml');
94
- expect(document.querySelector('form').getAttribute('method')).toBe('get');
95
- });
96
-
97
- test('target should be _blank by default', async () => {
98
- await nativeForm('spaceId', {}, {}, 'saml');
99
- expect(document.querySelector('form').getAttribute('target')).toBe('_blank');
100
- });
101
-
102
- test('target should be overridable', async () => {
103
- await nativeForm('spaceId123', {}, { target: '_top' }, 'saml');
104
- expect(document.querySelector('form').getAttribute('target')).toBe('_top');
105
- });
106
-
107
- test('addtional attributes can be defined', async () => {
108
- await nativeForm('spaceId123', {}, { id: 'myForm', class: 'my-form' }, 'saml');
109
-
110
- expect(document.querySelector('form').getAttribute('id')).toBe('myForm');
111
-
112
- expect(document.querySelector('form').getAttribute('class')).toBe('my-form');
113
- });
114
-
115
- test('should have no field if no data was provided', async () => {
116
- await nativeForm('spaceId123', {}, {}, 'saml');
117
- expect(document.querySelector('input')).toBeNull();
118
- });
119
-
120
- test('should have fields if was provided', async () => {
121
- await nativeForm('spaceId123', { a: 'b' }, {}, 'saml');
122
- expect(document.querySelector('input')).not.toBeNull();
123
- });
124
-
125
- describe('the fields', () => {
126
- test('should have a field for each piece of data (no more, no less)', async () => {
127
- await nativeForm('spaceId123', complexObject, {}, 'saml');
128
- expect(document.querySelectorAll('input').length).toBe(Object.keys(flattenObject(complexObject)).length);
129
- });
130
-
131
- test('the names will match the flat object, but have the array index value removed (the way the back-end likes it)', async () => {
132
- // Note: this causes multiple fields to have the same name, so we have to account for that
133
- await nativeForm('spaceId123', complexObject, {}, 'saml');
134
- const flat = flattenObject(complexObject);
135
- const count = {};
136
- for (const key of Object.keys(flat)) {
137
- const name = key.replace(/\[\d+]/g, '[]');
138
- count[name] = count[name] || 0;
139
- expect(document.querySelectorAll(`[name="${name}"`)[count[name]]).not.toBeNull();
140
- count[name] += 1;
141
- }
142
- });
143
-
144
- test('data should match the values within the object', async () => {
145
- // Note: this causes multiple fields to have the same name, so we have to account for that
146
- await nativeForm('spaceId123', complexObject, {}, 'saml');
147
- const flat = flattenObject(complexObject);
148
- const count = {};
149
- for (const key of Object.keys(flat)) {
150
- const name = key.replace(/\[\d+]/g, '[]');
151
- count[name] = count[name] || 0;
152
- const value = flat[key];
153
- expect(document.querySelectorAll(`[name="${name}"`)[count[name]].value).toBe(value);
154
- count[name] += 1;
155
- }
156
- });
157
- });
158
- });
159
-
160
- test('submit the form', async () => {
161
- await nativeForm('spaceId', {}, {}, 'saml');
162
- expect(window.HTMLFormElement.prototype.submit).toHaveBeenCalled();
163
- });
164
-
165
- describe('fetch sso type behavior', () => {
166
- beforeEach(() => {
167
- jest.clearAllMocks();
168
- });
169
-
170
- test('skips call to webQL endpoint when type param is saml', async () => {
171
- avWebQLApi.create.mockResolvedValue({
172
- data: {
173
- data: {
174
- configurationFindOne: {
175
- type: null,
176
- },
177
- },
178
- },
179
- });
180
-
181
- await nativeForm('spaceId', {}, {}, 'saml');
182
- expect(avWebQLApi.create).toHaveBeenCalledTimes(0);
183
- expect(document.querySelector('form').getAttribute('action')).toBe(
184
- '/ms/api/availity/internal/spc/magneto/sso/v1/saml/spaceId'
185
- );
186
- });
187
-
188
- test('skips call to webQL endpoint when type param is openid', async () => {
189
- avWebQLApi.create.mockResolvedValue({
190
- data: {
191
- data: {
192
- configurationFindOne: {
193
- type: null,
194
- },
195
- },
196
- },
197
- });
198
-
199
- await nativeForm('spaceId', {}, {}, 'openid');
200
- expect(avWebQLApi.create).toHaveBeenCalledTimes(0);
201
- expect(document.querySelector('form').getAttribute('action')).toBe(
202
- '/ms/api/availity/internal/spc/magneto/sso/v1/openid/spaceId'
203
- );
204
- });
205
-
206
- test('calls webQL endpoint when type param is omitted', async () => {
207
- avWebQLApi.create.mockResolvedValue({
208
- data: {
209
- data: {
210
- configurationFindOne: {
211
- type: 'SAML',
212
- },
213
- },
214
- },
215
- });
216
-
217
- await nativeForm('spaceId', {}, {});
218
- expect(avWebQLApi.create).toHaveBeenCalledTimes(1);
219
- expect(document.querySelector('form').getAttribute('action')).toBe(
220
- '/ms/api/availity/internal/spc/magneto/sso/v1/saml/spaceId'
221
- );
222
- });
223
-
224
- test('calls webQL endpoint when type param is neither saml nor openid', async () => {
225
- avWebQLApi.create.mockResolvedValue({
226
- data: {
227
- data: {
228
- configurationFindOne: {
229
- type: 'OPENID',
230
- },
231
- },
232
- },
233
- });
234
-
235
- await nativeForm('spaceId', {}, {}, 'application');
236
- expect(avWebQLApi.create).toHaveBeenCalledTimes(1);
237
- expect(document.querySelector('form').getAttribute('action')).toBe(
238
- '/ms/api/availity/internal/spc/magneto/sso/v1/openid/spaceId'
239
- );
240
- });
241
- });
242
- });
243
- });