liferay-headless-sdk 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -51,7 +51,7 @@ const client = new LiferayHeadlessClient({
51
51
  await client.init();
52
52
 
53
53
  // Call generated methods
54
- const { data: sites } = await client.headlessDelivery.site.getSites();
54
+ const { data: sites } = await client.headlessAdminUser.site.getMyUserAccountSitesPage();
55
55
  console.log(sites.items);
56
56
  ```
57
57
 
@@ -143,7 +143,7 @@ After `init()`, service namespaces are accessible as properties of the client. T
143
143
  await client.init();
144
144
 
145
145
  // GET /v1.0/sites/{siteId}
146
- const { data } = await client.headlessDelivery.site.getSite({siteId: 12345});
146
+ const { data } = await client.headlessAdminUser.site.getSite({siteId: 12345});
147
147
 
148
148
  // GET /v1.0/structured-contents/{structuredContentId}
149
149
  const { data: contents } = await client.headlessDelivery.structuredContent.getStructuredContent({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "liferay-headless-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A production-ready JavaScript SDK dynamically generated from Liferay Headless API Swagger/OpenAPI specifications.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -30,8 +30,6 @@
30
30
  "README.md"
31
31
  ],
32
32
  "scripts": {
33
- "test": "node --experimental-vm-modules node_modules/.bin/jest",
34
- "lint": "eslint .",
35
33
  "build": "echo 'No build step required for ES modules'"
36
34
  },
37
35
  "keywords": [
@@ -48,26 +46,5 @@
48
46
  "license": "MIT",
49
47
  "engines": {
50
48
  "node": ">=18.0.0"
51
- },
52
- "devDependencies": {
53
- "eslint": "^8.57.0",
54
- "jest": "^29.7.0"
55
- },
56
- "eslintConfig": {
57
- "env": {
58
- "browser": true,
59
- "es2022": true,
60
- "node": true
61
- },
62
- "parserOptions": {
63
- "ecmaVersion": 2022,
64
- "sourceType": "module"
65
- },
66
- "rules": {
67
- "no-console": "warn",
68
- "no-unused-vars": "warn",
69
- "prefer-const": "error",
70
- "no-var": "error"
71
- }
72
49
  }
73
50
  }
package/src/auth.js CHANGED
@@ -14,6 +14,7 @@ export class AuthManager {
14
14
  constructor() {
15
15
  /** @type {AuthType | null} */
16
16
  this._authType = null;
17
+ this._authToken = null;
17
18
  this._credentials = null;
18
19
  }
19
20
 
@@ -40,6 +41,10 @@ export class AuthManager {
40
41
  this._credentials = `Bearer ${token}`;
41
42
  }
42
43
 
44
+ setAuthToken(authToken) {
45
+ this._authToken = authToken
46
+ }
47
+
43
48
  /**
44
49
  * Clear all authentication credentials.
45
50
  */
@@ -75,8 +80,8 @@ export class AuthManager {
75
80
  headers['Authorization'] = authHeader;
76
81
  }
77
82
 
78
- if(Liferay.authToken) {
79
- headers['x-csrf-token'] = Liferay.authToken;
83
+ if(this._authToken) {
84
+ headers['x-csrf-token'] = this._authToken;
80
85
  }
81
86
 
82
87
  return headers;
package/src/cli.js CHANGED
@@ -97,7 +97,6 @@ async function fetchSchema(url) {
97
97
  const authHeader = buildAuthHeader();
98
98
  const headers = { Accept: 'application/json' };
99
99
  if (authHeader) headers['Authorization'] = authHeader;
100
- if (Liferay.authToken) headers['x-csrf-token'] = Liferay.authToken;
101
100
 
102
101
  const response = await fetch(url, { headers });
103
102
  if (!response.ok) {
package/src/client.js CHANGED
@@ -46,6 +46,7 @@ export class LiferayHeadlessClient {
46
46
  username,
47
47
  password,
48
48
  oauthToken,
49
+ authToken,
49
50
  timeout = 30000,
50
51
  retries = 2,
51
52
  autoGenerate = true,
@@ -73,6 +74,8 @@ export class LiferayHeadlessClient {
73
74
  this._auth.setOAuthToken(oauthToken);
74
75
  } else if (username && password) {
75
76
  this._auth.setBasicAuth(username, password);
77
+ } else if (authToken) {
78
+ this._auth.setAuthToken(authToken);
76
79
  }
77
80
 
78
81
  // Auto-generate: return a Proxy that lazily triggers init on first service access
@@ -91,10 +94,8 @@ export class LiferayHeadlessClient {
91
94
  if (this._initialized) return this;
92
95
 
93
96
  const authHeaders = {};
94
- const authHeader = this._auth.getAuthHeader();
95
- if (authHeader) authHeaders['Authorization'] = authHeader;
96
- if (Liferay.authToken) authHeaders['x-csrf-token'] = Liferay.authToken;
97
-
97
+ this._auth.injectAuthHeaders(authHeaders);
98
+
98
99
  const schemas = await this._loader.loadAll(this._swaggerUrls, this.baseUrl, authHeaders);
99
100
 
100
101
  for (const { url, schema } of schemas) {
@@ -113,9 +114,7 @@ export class LiferayHeadlessClient {
113
114
  */
114
115
  async loadSchema(swaggerUrl) {
115
116
  const authHeaders = {};
116
- const authHeader = this._auth.getAuthHeader();
117
- if (authHeader) authHeaders['Authorization'] = authHeader;
118
- if (Liferay.authToken) authHeaders['x-csrf-token'] = Liferay.authToken;
117
+ this._auth.injectAuthHeaders(authHeaders);
119
118
 
120
119
  const schema = await this._loader.load(swaggerUrl, this.baseUrl, authHeaders);
121
120
  this._mergeServices(generateServicesFromSchema(schema, this._http), swaggerUrl);