@sacms/sdk 1.1.0 → 1.1.1
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/dist/client.js +13 -2
- package/dist/types.d.ts +10 -1
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -22,7 +22,7 @@ class SaCMS {
|
|
|
22
22
|
constructor(config) {
|
|
23
23
|
this.baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
24
24
|
this.tenant = config.tenant;
|
|
25
|
-
this.token = config.token;
|
|
25
|
+
this.token = config.token ?? "";
|
|
26
26
|
this.defaultLocale = config.locale ?? "id";
|
|
27
27
|
this.auth = new auth_1.AuthClient(this);
|
|
28
28
|
}
|
|
@@ -45,8 +45,19 @@ class SaCMS {
|
|
|
45
45
|
async request(path, init, retries = 3) {
|
|
46
46
|
const url = `${this.baseUrl}${path}`;
|
|
47
47
|
const headers = {
|
|
48
|
-
Authorization: `Bearer ${this.token}`,
|
|
49
48
|
"Content-Type": "application/json",
|
|
49
|
+
// Fifth external audit: this used to send `Authorization: Bearer
|
|
50
|
+
// ${this.token}` unconditionally — with no token configured,
|
|
51
|
+
// `this.token` was `undefined` (TS's `token: string` only enforces
|
|
52
|
+
// this at compile time; a plain-JS caller omitting it entirely got
|
|
53
|
+
// a real `undefined` at runtime), producing the literal header
|
|
54
|
+
// "Bearer undefined". The server's own bearer-extraction only treats
|
|
55
|
+
// a MISSING Authorization header as anonymous/public access — a
|
|
56
|
+
// non-empty (but garbage) token value is treated as a real,
|
|
57
|
+
// invalid credential attempt and rejected with 401, even though the
|
|
58
|
+
// request would have succeeded perfectly well anonymously had this
|
|
59
|
+
// header been omitted entirely. Only send it when a real token exists.
|
|
60
|
+
...(this.token ? { Authorization: `Bearer ${this.token}` } : {}),
|
|
50
61
|
...init?.headers,
|
|
51
62
|
};
|
|
52
63
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
package/dist/types.d.ts
CHANGED
|
@@ -72,7 +72,16 @@ export interface GraphQLResponse<T = Record<string, unknown>> {
|
|
|
72
72
|
export interface SaCMSConfig {
|
|
73
73
|
baseUrl: string;
|
|
74
74
|
tenant: string;
|
|
75
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Optional — the public Content API works anonymously for published
|
|
77
|
+
* content (confirmed: `resolvePublicApiActor` falls back to a "public"
|
|
78
|
+
* role when no Authorization header is sent at all). Only needed for a
|
|
79
|
+
* full-access/read-only API token, or to read non-PUBLISHED content.
|
|
80
|
+
* Omit it rather than passing `""` as a workaround — both are now
|
|
81
|
+
* treated identically (see the client's own request() comment for why
|
|
82
|
+
* that distinction used to matter).
|
|
83
|
+
*/
|
|
84
|
+
token?: string;
|
|
76
85
|
locale?: string;
|
|
77
86
|
}
|
|
78
87
|
export interface MutateParams {
|