create-wirejs-app 2.0.5 → 2.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-wirejs-app",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "description": "Initializes a wirejs package.",
5
5
  "author": "Jon Wire",
6
6
  "license": "MIT",
@@ -19,4 +19,4 @@
19
19
  "package.json",
20
20
  "templates/*"
21
21
  ]
22
- }
22
+ }
@@ -0,0 +1,3 @@
1
+ // this file will be overwritten by your hosting provider during deployment.
2
+ const config = {};
3
+ export default config;
@@ -26,9 +26,24 @@ const apiCode = Object.keys(indexModule)
26
26
 
27
27
  const baseClient = dedent(1, /* js */ `
28
28
  async function wirejsCallApi(method, ...args) {
29
+ function isNode() {
30
+ return typeof args[0]?.cookies?.getAll === 'function'
31
+ // return typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
32
+ }
33
+
34
+ function apiUrl() {
35
+ if (isNode()) {
36
+ return "${API_URL}";
37
+ } else {
38
+ return "/api";
39
+ }
40
+ }
41
+
29
42
  let cookieHeader = {};
30
- if (typeof args[0]?.cookies?.getAll === 'function') {
31
- const cookies = args[0]?.cookies?.getAll();
43
+
44
+ if (isNode()) {
45
+ const context = args[0];
46
+ const cookies = context.cookies.getAll();
32
47
  cookieHeader = typeof cookies === 'object'
33
48
  ? {
34
49
  Cookie: Object.entries(cookies).map(kv => kv.join('=')).join('; ')
@@ -36,7 +51,7 @@ const baseClient = dedent(1, /* js */ `
36
51
  : {};
37
52
  }
38
53
 
39
- const response = await fetch("${API_URL}", {
54
+ const response = await fetch(apiUrl(), {
40
55
  method: 'POST',
41
56
  headers: {
42
57
  'Content-Type': 'application/json',
@@ -46,6 +61,25 @@ const baseClient = dedent(1, /* js */ `
46
61
  });
47
62
  const body = await response.json();
48
63
 
64
+ if (isNode()) {
65
+ const context = args[0];
66
+ for (const c of response.headers.getSetCookie()) {
67
+ const parts = c.split(';').map(p => p.trim());
68
+ const flags = parts.slice(1);
69
+ const [name, value] = parts[0].split('=').map(decodeURIComponent);
70
+ const httpOnly = flags.includes('HttpOnly');
71
+ const secure = flags.includes('Secure');
72
+ const maxAgePart = flags.find(f => f.startsWith('Max-Age='))?.split('=')[1];
73
+ context.cookies.set({
74
+ name,
75
+ value,
76
+ httpOnly,
77
+ secure,
78
+ maxAge: maxAgePart ? parseInt(maxAgePart) : undefined
79
+ });
80
+ }
81
+ }
82
+
49
83
  const error = body[0].error;
50
84
  if (error) {
51
85
  throw new Error(error);
@@ -9,12 +9,12 @@
9
9
  ],
10
10
  "dependencies": {
11
11
  "wirejs-dom": "^1.0.34",
12
- "wirejs-resources": "^0.1.5-alpha",
12
+ "wirejs-resources": "^0.1.6-alpha",
13
13
  "dompurify": "^3.2.3",
14
14
  "marked": "^15.0.6"
15
15
  },
16
16
  "devDependencies": {
17
- "wirejs-scripts": "^3.0.1"
17
+ "wirejs-scripts": "^3.0.2"
18
18
  },
19
19
  "scripts": {
20
20
  "prebuild": "npm run prebuild --workspaces --if-present",