nextemos 6.3.1 → 6.4.0
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.
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -25,7 +48,68 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
49
|
const __1 = require("../");
|
|
27
50
|
const getConfigs_1 = __importDefault(require("./getConfigs"));
|
|
28
|
-
const { FETCH_OPTIONS } = getConfigs_1.default;
|
|
51
|
+
const { FETCH_OPTIONS, ENVIRONMENT } = getConfigs_1.default;
|
|
52
|
+
// --- www-authenticate interceptor yardımcıları -------------------------------
|
|
53
|
+
// Backend, environment_token süresi dolduğunda yanıtta standart `www-authenticate`
|
|
54
|
+
// başlığını döndürür. Aşağıdaki yardımcılar böyle bir yanıtta token'ı yenileyip isteği bir
|
|
55
|
+
// kez tekrarlar. Eskiden tüketici projelerde Edge middleware'in (readEnvironment) yaptığı işi
|
|
56
|
+
// merkezîleştirir → tüm projeler yalnız nextemos versiyonunu yükselterek faydalanır.
|
|
57
|
+
// Interceptor logları nextemos LOG_LEVEL konvansiyonuna uyar (debug/info/trace).
|
|
58
|
+
const logEnvRefresh = (...args) => {
|
|
59
|
+
if (["debug", "info", "trace"].includes(FETCH_OPTIONS.LOG_LEVEL))
|
|
60
|
+
console.log("🔄 [nextemos:env-refresh]", ...args);
|
|
61
|
+
};
|
|
62
|
+
// Aynı süresi dolmuş token için eşzamanlı yenilemeleri tek isteğe indirir (race önleme).
|
|
63
|
+
const environmentRefreshInFlight = new Map();
|
|
64
|
+
const refreshExpiredEnvironment = (environment, ctx) => {
|
|
65
|
+
const inFlight = environmentRefreshInFlight.get(environment);
|
|
66
|
+
if (inFlight) {
|
|
67
|
+
logEnvRefresh("zaten devam eden yenilemeye katıldı (single-flight)");
|
|
68
|
+
return inFlight;
|
|
69
|
+
}
|
|
70
|
+
const task = (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
try {
|
|
72
|
+
logEnvRefresh("environment_token yenileniyor…");
|
|
73
|
+
// Dinamik import: services → fetchRequest dairesel bağımlılığını ve TDZ'yi önler.
|
|
74
|
+
const { EnvironmentService } = yield Promise.resolve().then(() => __importStar(require("../services/environment")));
|
|
75
|
+
const { data } = yield EnvironmentService.Refresh({
|
|
76
|
+
environment,
|
|
77
|
+
countryCode: ENVIRONMENT.COUNTRY_CODE,
|
|
78
|
+
platform: ENVIRONMENT.PLATFORM,
|
|
79
|
+
}, {
|
|
80
|
+
version: ctx.version,
|
|
81
|
+
__envRetried: true,
|
|
82
|
+
headers: ctx.authorization
|
|
83
|
+
? { Authorization: ctx.authorization }
|
|
84
|
+
: undefined,
|
|
85
|
+
});
|
|
86
|
+
const refreshed = (data === null || data === void 0 ? void 0 : data.environment) || null;
|
|
87
|
+
logEnvRefresh(refreshed
|
|
88
|
+
? "environment_token yenilendi ✅"
|
|
89
|
+
: "yenileme başarısız: yanıtta environment yok ⚠️");
|
|
90
|
+
return refreshed;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
logEnvRefresh("yenileme hatası ❌", error);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
environmentRefreshInFlight.delete(environment);
|
|
98
|
+
}
|
|
99
|
+
}))();
|
|
100
|
+
environmentRefreshInFlight.set(environment, task);
|
|
101
|
+
return task;
|
|
102
|
+
};
|
|
103
|
+
// Yenilenen token'ı, tüketicideki mevcut cookieHandler'ın (data.refreshEnvironment) sıfır
|
|
104
|
+
// değişiklikle yazabilmesi için yanıt gövdesine de enjekte eder.
|
|
105
|
+
const injectRefreshEnvironment = (data, environment) => {
|
|
106
|
+
if (data && typeof data === "object" && !Array.isArray(data)) {
|
|
107
|
+
const obj = data;
|
|
108
|
+
if (!obj.refreshEnvironment)
|
|
109
|
+
obj.refreshEnvironment = environment;
|
|
110
|
+
}
|
|
111
|
+
return data;
|
|
112
|
+
};
|
|
29
113
|
/**
|
|
30
114
|
* İstek yapmak için bir HTTP istemcisi oluşturur.
|
|
31
115
|
* @returns {object} İstek yapmak için yöntemlere sahip HTTP istemcisi.
|
|
@@ -39,7 +123,7 @@ const fetchRequest = () => {
|
|
|
39
123
|
*/
|
|
40
124
|
const request = (_a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
125
|
var _b;
|
|
42
|
-
var { url, method, params } = _a, options = __rest(_a, ["url", "method", "params"]);
|
|
126
|
+
var { url, method, params, __envRetried } = _a, options = __rest(_a, ["url", "method", "params", "__envRetried"]);
|
|
43
127
|
const apiURL = new URL(url);
|
|
44
128
|
if (params) {
|
|
45
129
|
Object.keys(params).forEach((key) => {
|
|
@@ -104,6 +188,27 @@ const fetchRequest = () => {
|
|
|
104
188
|
};
|
|
105
189
|
}
|
|
106
190
|
if (!response.ok) {
|
|
191
|
+
// www-authenticate interceptor: environment_token süresi dolmuş → yenile + bir kez retry
|
|
192
|
+
if (response.status === __1.HttpStatusCode.UNAUTHORIZED &&
|
|
193
|
+
headers["www-authenticate"] === "Environment" &&
|
|
194
|
+
!__envRetried) {
|
|
195
|
+
logEnvRefresh("www-authenticate: Environment yakalandı →", apiURL.toString());
|
|
196
|
+
const requestHeaders = options.headers;
|
|
197
|
+
const currentEnvironment = requestHeaders === null || requestHeaders === void 0 ? void 0 : requestHeaders["Environment"];
|
|
198
|
+
if (currentEnvironment) {
|
|
199
|
+
const refreshedEnvironment = yield refreshExpiredEnvironment(currentEnvironment, {
|
|
200
|
+
authorization: requestHeaders === null || requestHeaders === void 0 ? void 0 : requestHeaders["Authorization"],
|
|
201
|
+
version: options.version,
|
|
202
|
+
});
|
|
203
|
+
if (refreshedEnvironment) {
|
|
204
|
+
logEnvRefresh("istek yeni token ile tekrarlanıyor →", apiURL.toString());
|
|
205
|
+
const retried = yield request(Object.assign(Object.assign({ url,
|
|
206
|
+
method,
|
|
207
|
+
params }, options), { __envRetried: true, headers: Object.assign(Object.assign({}, requestHeaders), { Environment: refreshedEnvironment }) }));
|
|
208
|
+
return Object.assign(Object.assign({}, retried), { refreshedEnvironment, data: injectRefreshEnvironment(retried.data, refreshedEnvironment) });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
107
212
|
const errorDetail = yield response.text();
|
|
108
213
|
if (["debug", "info", "trace"].includes(FETCH_OPTIONS.LOG_LEVEL) &&
|
|
109
214
|
response.status !== __1.HttpStatusCode.NOT_FOUND)
|
|
@@ -39,6 +39,12 @@ exports.defaultConfig = {
|
|
|
39
39
|
LOG_LEVEL: "info",
|
|
40
40
|
CACHE: "",
|
|
41
41
|
},
|
|
42
|
+
// www-authenticate interceptor environment_token'ı yenilerken kullanılan varsayılanlar.
|
|
43
|
+
// Proje bazında nextemos-config.json ile override edilebilir.
|
|
44
|
+
ENVIRONMENT: {
|
|
45
|
+
COUNTRY_CODE: "TR",
|
|
46
|
+
PLATFORM: "desktop",
|
|
47
|
+
},
|
|
42
48
|
K8S_NAMESPACE: "emosv2service",
|
|
43
49
|
K8S_SERVICE_NAMES: {
|
|
44
50
|
ADDRESS: "address",
|
|
@@ -4,10 +4,14 @@ export interface IRequestOptions extends RequestInit {
|
|
|
4
4
|
url: string;
|
|
5
5
|
method: HTTPMethod;
|
|
6
6
|
params?: Record<string, any>;
|
|
7
|
+
/** internal: www-authenticate retry loop guard */
|
|
8
|
+
__envRetried?: boolean;
|
|
7
9
|
}
|
|
8
10
|
export interface IRequestInit extends RequestInit {
|
|
9
11
|
useClient?: boolean;
|
|
10
12
|
version?: string;
|
|
13
|
+
/** internal: www-authenticate retry loop guard */
|
|
14
|
+
__envRetried?: boolean;
|
|
11
15
|
}
|
|
12
16
|
export interface IApiResponse<T = any> {
|
|
13
17
|
data?: T;
|
|
@@ -17,6 +21,8 @@ export interface IApiResponse<T = any> {
|
|
|
17
21
|
headers?: {
|
|
18
22
|
[key: string]: string;
|
|
19
23
|
};
|
|
24
|
+
/** www-authenticate sonrası interceptor tarafından yenilenen environment_token */
|
|
25
|
+
refreshedEnvironment?: string;
|
|
20
26
|
}
|
|
21
27
|
export interface IRequestBase {
|
|
22
28
|
language?: string;
|
|
@@ -21,7 +21,7 @@ const createUrlEncodedBody = (plainBodyObject) => {
|
|
|
21
21
|
};
|
|
22
22
|
// Environment servisi
|
|
23
23
|
exports.KeycloakService = {
|
|
24
|
-
ServiceUrl: "
|
|
24
|
+
ServiceUrl: "",
|
|
25
25
|
Token: function (_a, options_1) {
|
|
26
26
|
return __awaiter(this, arguments, void 0, function* ({ realm, client_id, client_secret, grant_type }, options) {
|
|
27
27
|
// request
|