Skip to content

Commit a85d7bc

Browse files
committed
Update core, pass clientName to client
1 parent 30094b8 commit a85d7bc

File tree

8 files changed

+54
-21
lines changed

8 files changed

+54
-21
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 1.2.0
4+
5+
- Update core to fix body serialization bug.
6+
- Pass along `clientName` with form submission.
7+
38
## 1.1.0
49

510
- Accept `site` + `form` combo (in lieu of `id`) for identifying forms.

package-lock.json

Lines changed: 12 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
]
4646
},
4747
"dependencies": {
48-
"@statickit/core": "^1.4.0",
48+
"@statickit/core": "^1.5.0",
4949
"hyperscript": "^2.0.2"
5050
},
5151
"devDependencies": {
@@ -61,6 +61,7 @@
6161
"rollup": "1.17.0",
6262
"rollup-plugin-babel": "4.3.3",
6363
"rollup-plugin-commonjs": "10.0.1",
64+
"rollup-plugin-json": "4.0.0",
6465
"rollup-plugin-node-resolve": "5.2.0",
6566
"rollup-plugin-terser": "5.1.1",
6667
"sort-package-json": "1.22.1"

public/statickit.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -912,9 +912,11 @@ var statickit = (function () {
912912
return to;
913913
};
914914

915+
var version = "1.5.0";
916+
915917
var serializeBody = function serializeBody(data) {
916918
if (data instanceof FormData) return data;
917-
JSON.stringify(data);
919+
return JSON.stringify(data);
918920
};
919921

920922
var submissionUrl = function submissionUrl(props) {
@@ -929,6 +931,13 @@ var statickit = (function () {
929931
return "".concat(endpoint, "/j/forms/").concat(id, "/submissions");
930932
}
931933
};
934+
935+
var clientHeader = function clientHeader(_ref) {
936+
var clientName = _ref.clientName;
937+
var label = "@statickit/core@".concat(version);
938+
if (!clientName) return label;
939+
return "".concat(clientName, " ").concat(label);
940+
};
932941
/**
933942
* The client constructor.
934943
*/
@@ -991,13 +1000,14 @@ var statickit = (function () {
9911000
var request = {
9921001
method: 'POST',
9931002
mode: 'cors',
994-
body: serializeBody(data)
1003+
body: serializeBody(data),
1004+
headers: {
1005+
'StaticKit-Client': clientHeader(props)
1006+
}
9951007
};
9961008

9971009
if (!(data instanceof FormData)) {
998-
request.headers = {
999-
'Content-Type': 'application/json'
1000-
};
1010+
request.headers['Content-Type'] = 'application/json';
10011011
}
10021012

10031013
return fetchImpl(url, request).then(function (response) {
@@ -2459,12 +2469,6 @@ var statickit = (function () {
24592469
}
24602470
});
24612471

2462-
var toCamel = function toCamel(s) {
2463-
return s.replace(/([-_][a-z])/gi, function ($1) {
2464-
return $1.toUpperCase().replace('-', '').replace('_', '');
2465-
});
2466-
};
2467-
24682472
/*
24692473
object-assign
24702474
(c) Sindre Sorhus
@@ -2554,6 +2558,14 @@ var statickit = (function () {
25542558
return to;
25552559
};
25562560

2561+
var toCamel = function toCamel(s) {
2562+
return s.replace(/([-_][a-z])/gi, function ($1) {
2563+
return $1.toUpperCase().replace('-', '').replace('_', '');
2564+
});
2565+
};
2566+
2567+
var version$1 = "1.1.0";
2568+
25572569
var onSuccess = function onSuccess(config, _resp) {
25582570
var h = config.h,
25592571
form = config.form;
@@ -2637,6 +2649,7 @@ var statickit = (function () {
26372649
site: site,
26382650
form: key,
26392651
endpoint: endpoint,
2652+
clientName: "@statickit/html@".concat(version$1),
26402653
data: formData
26412654
}).then(function (result) {
26422655
if (result.response.status == 200) {

public/statickit.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup.config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import babel from 'rollup-plugin-babel';
22
import commonjs from 'rollup-plugin-commonjs';
33
import nodeResolve from 'rollup-plugin-node-resolve';
44
import { terser } from 'rollup-plugin-terser';
5+
import json from 'rollup-plugin-json';
56

67
const unbundledPlugins = [
78
nodeResolve({
@@ -10,15 +11,17 @@ const unbundledPlugins = [
1011
commonjs(),
1112
babel({
1213
exclude: 'node_modules/**'
13-
})
14+
}),
15+
json()
1416
];
1517

1618
const bundlePlugins = [
1719
nodeResolve(),
1820
commonjs(),
1921
babel({
2022
exclude: 'node_modules/**'
21-
})
23+
}),
24+
json()
2225
];
2326

2427
export default [
@@ -46,7 +49,6 @@ export default [
4649
plugins: unbundledPlugins,
4750
output: {
4851
format: 'cjs',
49-
name: 'statickit',
5052
file: __dirname + '/dist/statickit.cjs.js'
5153
}
5254
},
@@ -56,7 +58,6 @@ export default [
5658
plugins: unbundledPlugins,
5759
output: {
5860
format: 'esm',
59-
name: 'statickit',
6061
file: __dirname + '/dist/statickit.esm.js'
6162
}
6263
}

src/forms.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import h from 'hyperscript';
2-
import { toCamel } from './utils';
32
import objectAssign from 'object-assign';
3+
import { toCamel } from './utils';
4+
import { version } from '../package.json';
45

56
const onSuccess = (config, _resp) => {
67
const { h, form } = config;
@@ -94,6 +95,7 @@ const submit = config => {
9495
site: site,
9596
form: key,
9697
endpoint: endpoint,
98+
clientName: `@statickit/html@${version}`,
9799
data: formData
98100
})
99101
.then(result => {

test/forms.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sk from '../src';
2+
import { version } from '../package.json';
23

34
const successClient = (data, opts) => ({
45
submitForm: props => {
@@ -97,6 +98,7 @@ it('calls the success callback', () => {
9798
expect(props.id).toBe('xxx');
9899
expect(props.site).toBe('yyy');
99100
expect(props.form).toBe('zzz');
101+
expect(props.clientName).toBe(`@statickit/html@${version}`);
100102
}
101103
});
102104

0 commit comments

Comments
 (0)