@telia-ace/alliance-internal-node-utilities 1.0.6 → 1.1.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.
- package/dist/chunk-26VIM55J.js +23 -0
- package/dist/chunk-JG7V63GM.js +1 -0
- package/dist/chunk-UNKGNXJ3.js +32 -0
- package/dist/compile-distribution.d.ts +1 -0
- package/dist/compile-distribution.js +301 -0
- package/dist/index.d.ts +18 -5
- package/dist/index.js +4 -737
- package/dist/main-FN5JZTIU.js +9 -0
- package/dist/prompt-YMONYGAG.js +45 -0
- package/package.json +12 -9
- package/CHANGELOG.md +0 -158
- package/dist/index.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,737 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { validate } from 'jsonschema';
|
|
5
|
-
import { existsSync, mkdirSync, writeFileSync, readFileSync, rmSync } from 'node:fs';
|
|
6
|
-
import { resolve } from 'node:path';
|
|
7
|
-
import _slugify from 'slugify';
|
|
8
|
-
import pino from 'pino';
|
|
9
|
-
|
|
10
|
-
// src/auth/tokens.ts
|
|
11
|
-
var zBooleanEnum = z.enum(["true", "false"]).transform((strBool) => strBool === "true");
|
|
12
|
-
var zNonEmptyString = z.string().min(1);
|
|
13
|
-
var zSharedConfig = z.object({
|
|
14
|
-
/**
|
|
15
|
-
* Name for the cookie storing the user session
|
|
16
|
-
*
|
|
17
|
-
* Optional, defaults to "alliance-auth"
|
|
18
|
-
*/
|
|
19
|
-
AUTH_COOKIE_NAME: zNonEmptyString.default("alliance-auth"),
|
|
20
|
-
/**
|
|
21
|
-
* Secret to use when signing the user session cookie
|
|
22
|
-
*
|
|
23
|
-
* Optional, defaults to "zlLZBlk7wt8lypP5lA4D"
|
|
24
|
-
*/
|
|
25
|
-
AUTH_COOKIE_SECRET: zNonEmptyString.default("zlLZBlk7wt8lypP5lA4D"),
|
|
26
|
-
/**
|
|
27
|
-
* Endpoint to use when communicating with the Data API
|
|
28
|
-
*/
|
|
29
|
-
DB_ENDPOINT: zNonEmptyString,
|
|
30
|
-
/**
|
|
31
|
-
* Private key to use when signing JWT tokens
|
|
32
|
-
*
|
|
33
|
-
* Optional, defaults to "MIIEogIBAAKCAQEAsGqOzjnfQtCYlDqhgGAnKuJOCiPt2WpCmL1Cs+SLBQlyoNn6LT8BJ6ZRj8t/vK8Sw0p51Uq/3k0tazh7bLGkWNMBLY3BqFiNRMMnCqHJfvGIUi/itNXNe2kbP7H3rbyQTu4O7yH/ZAMitdpF2KLucVRlFxrQ/ggZjxwEGso4JUnCwmAnoKct/uupKz9Y2PMTr00WWN79aPfD4LcKi570VJqBT3ISSucdwFLYNqnOkQnEa8O8xbthQhiI0k1GGJT+GCQcATUPeEbaCFXonOrJm+CyuMmQWYLFF3NbE5NllU1jz9PYHzp2hAgAx8WGeretTvpEA1dE2gvXNESGbQ8FxQIDAQABAoIBAAjTJmud1348eGAfLV8CRaij2MAxxenJ9/ozVXfcPIa2+fCelsuBSv8pwbYODvNoVT7xpcs2nwccGI6JgnBl09EhqlMWCT7w7GLT2aBy3A/T6JF76xJICQGzDfWPYygMtlyhv0YqZDUjjFlJHun+/ysqIUMY81AR0FLUAEc6yw41ChcdSvTgIqBM9f5PsBRK7zOgdW1vcVQiZbf2Vqr+7wTJ+6b9A4rWnnAqesGDXqYupx3UJEu3x0wRNQB8FeiG9iJrw4cyD9SmM95doTyKosQ2PWWnUO1NMgmWCR/mWcKZAUcfZUpnQ8rz75WAWept8ZIOOdha8UZ1B/kw3EsVdEECgYEA3iN0BRUqMN0J69bazvlNOWtI+Chc1lYMt/tZ4p78pIJpAZvc3rQ9lAp6JvOEno2IglULA4I+ZLUmpz+lfu7XxKMNOI3cnG7WdiGbiIlwOSwuxzeO1FJqhtnc0U6mNkIjptV8b2etj8U2/SXAC3CC8XgsawAj9A/I7awlCL3NXdECgYEAy07gun3rcd3Y0ISmd3+SbAn/MbGf8uRLcfSc2ls9B6m3p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AoGAUzUmcBiUAiODfjulrpYvWG0tCn5B//yk7g1Tm3Chrh9huA1qGEN3jDoqSsTd5k4Yi5foyAZt5ORgoiUVm4IsfS56aoxIco1CtFG3zeMQRy4uKzTsvUTOdsJ4RlQdjNwpngXR44VL0WelgCDqTqJwn5ubzPvuIHuTj3cBpmJCjOo="
|
|
37
|
-
),
|
|
38
|
-
/**
|
|
39
|
-
* Public key type used by old versions of .NET.
|
|
40
|
-
*
|
|
41
|
-
* Optional, defaults to "BgIAAACkAABSU0ExAAgAAAEAAQDFBQ9thkQ01wvaRFcDRPpOrbd6hsXHAAiEdjof2NPPY02VZZMTW3MXxYJZkMm4suCbyeqc6FUI2kZ4DzUBHCQY/pQYRk3SiBhCYbvFvMNrxAmRzqk22FLAHedKEnJPgZpU9J6LCrfgw/do/d5YFk2vE/PYWD8rqev+LaegJ2DCwkklOMoaBByPGQj+0BoXZVRx7qLYRdq1IgNk/yHvDu5OkLyt97E/G2l7zdW04i9SiPF+yaEKJ8NEjViowY0tAdNYpLFsezhrLU3ev0rVeUrDEq+8f8uPUaYnAT8t+tmgcgkFi+SzQr2YQmrZ7SMKTuIqJ2CAoTqUmNBC3znOjmqw"
|
|
42
|
-
*/
|
|
43
|
-
JWT_PUBLIC_CSP_KEY: z.string().min(1).default(
|
|
44
|
-
"BgIAAACkAABSU0ExAAgAAAEAAQDFBQ9thkQ01wvaRFcDRPpOrbd6hsXHAAiEdjof2NPPY02VZZMTW3MXxYJZkMm4suCbyeqc6FUI2kZ4DzUBHCQY/pQYRk3SiBhCYbvFvMNrxAmRzqk22FLAHedKEnJPgZpU9J6LCrfgw/do/d5YFk2vE/PYWD8rqev+LaegJ2DCwkklOMoaBByPGQj+0BoXZVRx7qLYRdq1IgNk/yHvDu5OkLyt97E/G2l7zdW04i9SiPF+yaEKJ8NEjViowY0tAdNYpLFsezhrLU3ev0rVeUrDEq+8f8uPUaYnAT8t+tmgcgkFi+SzQr2YQmrZ7SMKTuIqJ2CAoTqUmNBC3znOjmqw"
|
|
45
|
-
),
|
|
46
|
-
/**
|
|
47
|
-
* Log level to output
|
|
48
|
-
*
|
|
49
|
-
* Supports "silent" | "fatal" | "error" | "warn" | "info" | "debug" | "trace"
|
|
50
|
-
*
|
|
51
|
-
* Optional, defaults to "trace"
|
|
52
|
-
*/
|
|
53
|
-
SERVICE_LOG_LEVEL: z.enum(["silent", "fatal", "error", "warn", "info", "debug", "trace"]).default("trace"),
|
|
54
|
-
/**
|
|
55
|
-
* Port to run the service on.
|
|
56
|
-
*
|
|
57
|
-
* Optional, defaults to "3000"
|
|
58
|
-
*/
|
|
59
|
-
SERVICE_PORT: zNonEmptyString.transform(Number).default("3000"),
|
|
60
|
-
/**
|
|
61
|
-
* Url to redis server to use when storing / reading user session information.
|
|
62
|
-
*/
|
|
63
|
-
REDIS_HOST: zNonEmptyString,
|
|
64
|
-
/**
|
|
65
|
-
* Password to redis server to use when storing / reading user session information.
|
|
66
|
-
*
|
|
67
|
-
* Optional
|
|
68
|
-
*/
|
|
69
|
-
REDIS_PASSWORD: zNonEmptyString.optional()
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// src/constants/headers.ts
|
|
73
|
-
var AllianceHeaders = /* @__PURE__ */ ((AllianceHeaders2) => {
|
|
74
|
-
AllianceHeaders2["TargetUrl"] = "alliance-target-url";
|
|
75
|
-
AllianceHeaders2["TargetApp"] = "alliance-target-app";
|
|
76
|
-
AllianceHeaders2["TargetWorkspace"] = "alliance-target-workspace";
|
|
77
|
-
return AllianceHeaders2;
|
|
78
|
-
})(AllianceHeaders || {});
|
|
79
|
-
|
|
80
|
-
// src/auth/tokens.ts
|
|
81
|
-
zSharedConfig.pick({ JWT_PRIVATE_KEY: true, JWT_PUBLIC_CSP_KEY: true });
|
|
82
|
-
function createBearerToken({
|
|
83
|
-
privateKey,
|
|
84
|
-
aud,
|
|
85
|
-
sub,
|
|
86
|
-
name,
|
|
87
|
-
user,
|
|
88
|
-
workspace,
|
|
89
|
-
expiration = "1h"
|
|
90
|
-
}) {
|
|
91
|
-
const token = jwt.sign(
|
|
92
|
-
{
|
|
93
|
-
iss: "Alliance",
|
|
94
|
-
aud,
|
|
95
|
-
sub,
|
|
96
|
-
name,
|
|
97
|
-
"https://alliance.teliacompany.net/user_type": user.type,
|
|
98
|
-
"https://alliance.teliacompany.net/user_email": user.email,
|
|
99
|
-
"https://alliance.teliacompany.net/user_privileges": user.permissions,
|
|
100
|
-
"https://alliance.teliacompany.net/workspace": workspace.slug,
|
|
101
|
-
"https://alliance.teliacompany.net/workspace_name": workspace.name,
|
|
102
|
-
"https://alliance.teliacompany.net/tenant": workspace.slug,
|
|
103
|
-
"https://alliance.teliacompany.net/tenant_name": workspace.name
|
|
104
|
-
},
|
|
105
|
-
privateKey,
|
|
106
|
-
{
|
|
107
|
-
expiresIn: expiration,
|
|
108
|
-
algorithm: "RS256"
|
|
109
|
-
}
|
|
110
|
-
);
|
|
111
|
-
return `Bearer ${token}`;
|
|
112
|
-
}
|
|
113
|
-
function getPrivateKey(config) {
|
|
114
|
-
return "-----BEGIN RSA PRIVATE KEY-----\n" + config.JWT_PRIVATE_KEY + "\n-----END RSA PRIVATE KEY-----";
|
|
115
|
-
}
|
|
116
|
-
function createSystemUserToken(config) {
|
|
117
|
-
return createBearerToken({
|
|
118
|
-
aud: "system",
|
|
119
|
-
sub: "system",
|
|
120
|
-
name: "system",
|
|
121
|
-
workspace: {
|
|
122
|
-
slug: "system",
|
|
123
|
-
name: "system"
|
|
124
|
-
},
|
|
125
|
-
user: {
|
|
126
|
-
type: "system",
|
|
127
|
-
permissions: [],
|
|
128
|
-
email: "system"
|
|
129
|
-
},
|
|
130
|
-
privateKey: getPrivateKey(config)
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
function createPublicKeys(config) {
|
|
134
|
-
const priv = getPrivateKey(config);
|
|
135
|
-
const generatedKey = createPublicKey(priv);
|
|
136
|
-
return {
|
|
137
|
-
pkcs: generatedKey.export({ type: "pkcs1", format: "pem" }).toString().trim(),
|
|
138
|
-
spki: generatedKey.export({ type: "spki", format: "pem" }).toString().trim(),
|
|
139
|
-
csp: config.JWT_PUBLIC_CSP_KEY
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
function getCleanPublicKey(type, keys) {
|
|
143
|
-
return keys[type].replace("-----BEGIN RSA PUBLIC KEY-----", "").replace("-----END RSA PUBLIC KEY-----", "").replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").trim().replaceAll("\n", "");
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// src/distribution/cookie-policy.ts
|
|
147
|
-
function generateCookiePolicyHtml(appManifests) {
|
|
148
|
-
const cookiePolicyTableRows = [];
|
|
149
|
-
for (const appName in appManifests) {
|
|
150
|
-
const manifest = appManifests[appName];
|
|
151
|
-
if (!manifest.storage) {
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
for (const [key, value] of Object.entries(manifest.storage)) {
|
|
155
|
-
const tableRow = createCookiePolicyTableRow(key, value);
|
|
156
|
-
cookiePolicyTableRows.push(tableRow);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return cookiePolicyHtml.replace("{APP_COOKIES}", cookiePolicyTableRows.join(""));
|
|
160
|
-
}
|
|
161
|
-
function createCookiePolicyTableRow(key, claimEntry) {
|
|
162
|
-
const rows = ["<tr>"];
|
|
163
|
-
const { category, purpose, lifespan } = claimEntry;
|
|
164
|
-
rows.push(`<td>${key}</td>`);
|
|
165
|
-
rows.push(`<td>${category}</td>`);
|
|
166
|
-
rows.push(`<td>${purpose}</td>`);
|
|
167
|
-
rows.push(`<td>${lifespan}</td>`);
|
|
168
|
-
rows.push("</tr>");
|
|
169
|
-
return rows.join("");
|
|
170
|
-
}
|
|
171
|
-
var cookiePolicyHtml = `
|
|
172
|
-
<!DOCTYPE html>
|
|
173
|
-
<html lang="en">
|
|
174
|
-
<head>
|
|
175
|
-
<meta charset="UTF-8" />
|
|
176
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
177
|
-
<title>ACE Alliance - Cookie Policy</title>
|
|
178
|
-
<link
|
|
179
|
-
rel="icon"
|
|
180
|
-
href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAGcElEQVRYha2Xe4xUVx3HP7/fPTOzDLO7sw8RlzWlZEtp2dCy0qIVWltKU/UPDZH6ijXWEK2odPcPa2qbhpi2kSa7blSStsFUjNq0lWCMaVMx8rAm22IJMJRHCqFC6BJ22eEx+5p7z88/7sywC7uwgCe5mXsz5/y+j/M753eOcJ2tK5sDyBrME2gBmkBq43/tnMERgXdAjrbn518yXq4RNA3cB/J54HNiMhfEicm4oAYghmHexN4Dew5k01giUybQlc1h0CbI9zC+Imi9mCAIYhoHsnI4KcNjYoDhxWPxsxFY1Z5vHQVwVwSu3Qdid4E8rSb3i6mqKYwBjpWX1V/QZBiYYWIIiifCw8Mm/vS7L/W237FqJno58M5srgmxP4npjsAHDwTeaeAdagGBdwQWoBYgFqCmqGlMqvTE3+U+ipbeE+ngB42Lde6kDnRmcwisAHlBfdBYCYxStp3y7xjTJ51RA0XxgGCkasQFSfkW8NQlBDqzORVYK6ZPqAU6ThUyqd0TN7mQDRZ/CULzvVVeRO68xIGubE6BbjH9oVqA+thaQccpvjLwRDTit2RG/fxVGR3sLc4ELuRAV90+gJ/G4K4EHpRs1wr7qwW/uH36uaxPzwz0xNZhHUfAzJZgsjZWrqXEiTP9WlRP1Bb+pCacs2KaCwvmD/5+cLhCoCubU0G61QJXyWYkVv9/Av/UEzVh2+PVDmDPr875ob4oD6UcMLhfTdqU8dket+sDD6rwS7vrfMs30i4qRhzfMhwe3FhwQG+FgMDKytIyKe1o1zffZlB3swvve7mehgVJZ95zatdouG31gHpvoHYUwHVmc4AsqoCXYK9HtzhYsDoTLnqyRl1a1QxOvjMavrmyT4sFr6hhsA/AZUbqKKTy9ZfCXhuFpntS4WfWZWloTcTTa8bh14fCrY/2a3E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G3rA16vXXj529dVKMK2bVL2fkmhrmJ/9cPy91Z2ZGwhMqQx95TudC8gdCZx4obbMVAhqNGvaoCr99bKD1svGntK4647vg84J8X021PBXlK5gJGJWr11GDb3fkW7dPJfaUi3539iARxSUCz4AsERMVpHwDxMTyhq0HftGRbz071bhXfeooXVJvBR4EbgSGgR6Bt9qvArjc/gfZzPoCTDB+AgAAAABJRU5ErkJggg=="
|
|
181
|
-
/>
|
|
182
|
-
<style>
|
|
183
|
-
@charset "UTF-8";
|
|
184
|
-
@import 'https://cdn.voca.teliacompany.com/fonts/TeliaSansV10/TeliaSans.css';
|
|
185
|
-
@import 'https://fonts.googleapis.com/css?family=Reenie+Beanie';
|
|
186
|
-
|
|
187
|
-
body {
|
|
188
|
-
font-family: TeliaSans, Helvetica, Arial, Lucida Grande, sans-serif;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
body > div {
|
|
192
|
-
max-width: 1000px;
|
|
193
|
-
margin: 0 auto;
|
|
194
|
-
padding: 0 40px 40px;
|
|
195
|
-
}
|
|
196
|
-
</style>
|
|
197
|
-
</head>
|
|
198
|
-
|
|
199
|
-
<body>
|
|
200
|
-
<div>
|
|
201
|
-
<h1>Cookie Policy</h1>
|
|
202
|
-
<p>
|
|
203
|
-
On our websites, we use cookies and other similar technologies. You can choose
|
|
204
|
-
whether you want to allow our websites to store cookies on your computer or not. You
|
|
205
|
-
can change your choices at any time.
|
|
206
|
-
</p>
|
|
207
|
-
|
|
208
|
-
<h2>Your consent is required</h2>
|
|
209
|
-
<p>
|
|
210
|
-
You choose whether you want to accept cookies on your device or not. Your consent is
|
|
211
|
-
required for the use of cookies, but not for such cookies that are necessary to
|
|
212
|
-
enable the service that you as a user have requested. If you do not accept our use
|
|
213
|
-
of cookies, or if you have previously approved our use and have changed your mind,
|
|
214
|
-
you can return to your cookie settings at any time and change your choices. You do
|
|
215
|
-
this by clicking on the cookie button/link. You may also need to change the settings
|
|
216
|
-
in your browser and manually delete cookies to clear your device of previously
|
|
217
|
-
stored cookies.
|
|
218
|
-
</p>
|
|
219
|
-
|
|
220
|
-
<h2>What are cookies?</h2>
|
|
221
|
-
<p>
|
|
222
|
-
A cookie is a small text file that is stored on your computer by the web browser
|
|
223
|
-
while browsing a website. When we refer to cookies (\u201Ccookies\u201D) in this policy, other
|
|
224
|
-
similar technologies and tools that retrieve and store information in your browser,
|
|
225
|
-
and in some cases forward such information to third parties, in a manner similar to
|
|
226
|
-
cookies. Examples are pixels, local storage, session storage and fingerprinting.
|
|
227
|
-
</p>
|
|
228
|
-
<p>
|
|
229
|
-
The websites will \u201Cremember\u201D and \u201Crecognize\u201D you. This can be done by placing
|
|
230
|
-
cookies in three different ways;
|
|
231
|
-
</p>
|
|
232
|
-
<ul>
|
|
233
|
-
<li>The session ends, ie until you close the window in your browser.</li>
|
|
234
|
-
<li>
|
|
235
|
-
Time-limited, ie the cookie has a predetermined lifespan. The time may vary
|
|
236
|
-
between different cookies.
|
|
237
|
-
</li>
|
|
238
|
-
<li>
|
|
239
|
-
Until further notice, ie the information remains until you choose to delete it
|
|
240
|
-
yourself. This applies to local storage.
|
|
241
|
-
</li>
|
|
242
|
-
</ul>
|
|
243
|
-
<p>You can always go into your browser and delete already stored cookies yourself.</p>
|
|
244
|
-
|
|
245
|
-
<h3>Third Party Cookies</h3>
|
|
246
|
-
<p>
|
|
247
|
-
We use third-party cookies on our websites. Third-party cookies are stored by
|
|
248
|
-
someone other than the person responsible for the website, in this case by a company
|
|
249
|
-
other than Telia.
|
|
250
|
-
</p>
|
|
251
|
-
<p>
|
|
252
|
-
Telia uses external platforms to communicate digitally, these include the Google
|
|
253
|
-
Marketing Platform and others. The platforms use both first- and third-party cookies
|
|
254
|
-
as well as similar techniques to advertise and follow up the results of the
|
|
255
|
-
advertising.
|
|
256
|
-
</p>
|
|
257
|
-
<p>
|
|
258
|
-
A third-party cookie can be used by several websites to understand and track how you
|
|
259
|
-
browse between different websites. Telia receives information from these cookies,
|
|
260
|
-
but the information can also be used for other purposes determined by third parties.
|
|
261
|
-
Third-party cookies found on our website are covered by each third-party privacy
|
|
262
|
-
policy. Feel free to read these to understand what other purposes the information
|
|
263
|
-
can be used for. Links are in our Cookie Table.
|
|
264
|
-
</p>
|
|
265
|
-
<p>
|
|
266
|
-
For information about which third-party cookies are used on our websites, see our
|
|
267
|
-
Cookie Table. For more information on how Telia handles personal data in connection
|
|
268
|
-
with transfers to third parties, read our Privacy Policy.
|
|
269
|
-
</p>
|
|
270
|
-
|
|
271
|
-
<h2>Cookies on our websites</h2>
|
|
272
|
-
<p>
|
|
273
|
-
In order for you to have better control over which cookies are used on the websites,
|
|
274
|
-
and thus be able to more easily decide how cookies should be used when you visit our
|
|
275
|
-
websites, we have identified four different categories of cookies. These categories
|
|
276
|
-
are defined based on the purposes for the use of the cookies.
|
|
277
|
-
</p>
|
|
278
|
-
<p>
|
|
279
|
-
In our Cookie Table, you can also see which category each cookie belongs to, for
|
|
280
|
-
what purposes it is used and for how long it is active.
|
|
281
|
-
</p>
|
|
282
|
-
<p>
|
|
283
|
-
We have identified the following four categories of cookies. All categories contain
|
|
284
|
-
cookies which means that data is shared with third parties.
|
|
285
|
-
</p>
|
|
286
|
-
|
|
287
|
-
<h3>Necessary</h3>
|
|
288
|
-
<p>
|
|
289
|
-
These cookies are needed for our app to work in a secure and correct way. Necessary
|
|
290
|
-
cookies enable you to use our app and us to provide the service you request.
|
|
291
|
-
Necessary cookies make basic functions of the app possible, for example, identifying
|
|
292
|
-
you when you log into My Telia, detecting repeated failed login attempts,
|
|
293
|
-
identifying where you are in the buying process and remembering the items put into
|
|
294
|
-
your shopping basket.
|
|
295
|
-
</p>
|
|
296
|
-
|
|
297
|
-
<h3>Functionality</h3>
|
|
298
|
-
<p>
|
|
299
|
-
These cookies let us to enable some useful functionalities to make the user
|
|
300
|
-
experience better, for example, to remember your login details and settings.
|
|
301
|
-
</p>
|
|
302
|
-
|
|
303
|
-
<h3>Analytics</h3>
|
|
304
|
-
<p>
|
|
305
|
-
These cookies give us information about how you use our app and allow us to improve
|
|
306
|
-
the user experience.
|
|
307
|
-
</p>
|
|
308
|
-
|
|
309
|
-
<h3>Marketing</h3>
|
|
310
|
-
<p>
|
|
311
|
-
These cookies help us and our partners to display personalized and relevant ads
|
|
312
|
-
based on your browsing behavior on our website and in our app, even when you later
|
|
313
|
-
visit other (third parties\u2019) websites. These cookies are used to evaluate the
|
|
314
|
-
effectiveness of our marketingcampaigns, as well as for targeted marketing and
|
|
315
|
-
profiling, regardless of which device(s) you have used. Information collected for
|
|
316
|
-
this purpose may also be combined with other customer and traffic data we have about
|
|
317
|
-
you, if you have given your consent that we may use your traffic data for marketing
|
|
318
|
-
purpose and have not objected to the use of your customer data for marketing
|
|
319
|
-
purposes.
|
|
320
|
-
</p>
|
|
321
|
-
|
|
322
|
-
<h2>Manage settings</h2>
|
|
323
|
-
<p>
|
|
324
|
-
We save your cookie consent for 12 months. Then we will ask you again. Please note
|
|
325
|
-
that some cookies have a lifespan that exceeds these 12 months. You may therefore
|
|
326
|
-
need to change the settings in your browser and manually delete all cookies.
|
|
327
|
-
</p>
|
|
328
|
-
<p>
|
|
329
|
-
More information on how to turn off cookies can be found in the instructions for
|
|
330
|
-
your browser.
|
|
331
|
-
</p>
|
|
332
|
-
<ul>
|
|
333
|
-
<li>
|
|
334
|
-
<a
|
|
335
|
-
href="https://support.google.com/accounts/answer/61416?co=GENIE.Platform%3DDesktop&hl=en"
|
|
336
|
-
target="_blank"
|
|
337
|
-
rel="noopener noreferrer"
|
|
338
|
-
>Google Chrome</a
|
|
339
|
-
>
|
|
340
|
-
</li>
|
|
341
|
-
<li>
|
|
342
|
-
<a
|
|
343
|
-
href="https://privacy.microsoft.com/en-us/windows-10-microsoft-edge-and-privacy"
|
|
344
|
-
target="_blank"
|
|
345
|
-
rel="noopener noreferrer"
|
|
346
|
-
>Microsoft Edge</a
|
|
347
|
-
>
|
|
348
|
-
</li>
|
|
349
|
-
<li>
|
|
350
|
-
<a
|
|
351
|
-
href="https://support.mozilla.org/en-US/kb/enable-and-disable-cookies-website-preferences"
|
|
352
|
-
target="_blank"
|
|
353
|
-
rel="noopener noreferrer"
|
|
354
|
-
>Mozilla Firefox</a
|
|
355
|
-
>
|
|
356
|
-
</li>
|
|
357
|
-
<li>
|
|
358
|
-
<a
|
|
359
|
-
href="https://support.microsoft.com/en-gb/help/17442/windows-internet-explorer-delete-manage-cookies"
|
|
360
|
-
target="_blank"
|
|
361
|
-
rel="noopener noreferrer"
|
|
362
|
-
>Microsoft Internet Explorer</a
|
|
363
|
-
>
|
|
364
|
-
</li>
|
|
365
|
-
<li>
|
|
366
|
-
<a
|
|
367
|
-
href="https://www.opera.com/help/tutorials/security/privacy/"
|
|
368
|
-
target="_blank"
|
|
369
|
-
rel="noopener noreferrer"
|
|
370
|
-
>Opera</a
|
|
371
|
-
>
|
|
372
|
-
</li>
|
|
373
|
-
<li>
|
|
374
|
-
<a
|
|
375
|
-
href="https://support.apple.com/guide/safari/manage-cookies-and-website-data-sfri11471/mac"
|
|
376
|
-
target="_blank"
|
|
377
|
-
rel="noopener noreferrer"
|
|
378
|
-
>Apple Safari</a
|
|
379
|
-
>
|
|
380
|
-
</li>
|
|
381
|
-
</ul>
|
|
382
|
-
|
|
383
|
-
<h3>Do Not Track-signals</h3>
|
|
384
|
-
<p>
|
|
385
|
-
If you have chosen to turn on the Do Not Track function in your browser, we will not
|
|
386
|
-
automatically place cookies for marketing on your device. You make other choices in
|
|
387
|
-
your cookie settings.
|
|
388
|
-
</p>
|
|
389
|
-
|
|
390
|
-
<h3>If you block cookies</h3>
|
|
391
|
-
<p>
|
|
392
|
-
If you choose not to accept our use of cookies, the functionality and performance of
|
|
393
|
-
our websites may deteriorate as certain functions are dependent on cookies. A
|
|
394
|
-
blocking of cookies can therefore mean that the websites\u2019 services do not work as
|
|
395
|
-
they should.
|
|
396
|
-
</p>
|
|
397
|
-
|
|
398
|
-
<h3>Your security with us</h3>
|
|
399
|
-
<p>
|
|
400
|
-
If you want to read more about your rights and how we protect your privacy, go to
|
|
401
|
-
our privacy policy for
|
|
402
|
-
<a
|
|
403
|
-
href="https://www.telia.se/dam/jcr:df2eeb83-50ce-4383-89fc-0613f7615796/Integritetspolicy-privatkunder.pdf"
|
|
404
|
-
>private customers</a
|
|
405
|
-
>
|
|
406
|
-
(C2B) or
|
|
407
|
-
<a
|
|
408
|
-
href="https://www.telia.se/dam/jcr:95b2b4a5-82ca-436b-90e0-873e0a864118/Telia-integritetspolicy-foretag.pdf"
|
|
409
|
-
>corporate customers</a
|
|
410
|
-
>
|
|
411
|
-
(B2B). You are always welcome to contact us at
|
|
412
|
-
<a href="mailto:dpo-se@teliacompany.com">dpo-se@teliacompany.com</a> if you have any
|
|
413
|
-
questions.
|
|
414
|
-
</p>
|
|
415
|
-
<p>Our cookie policy may change in the future.</p>
|
|
416
|
-
<p>
|
|
417
|
-
More information about cookies can be found at the Swedish Post and Telecom
|
|
418
|
-
Authority (PTS).
|
|
419
|
-
</p>
|
|
420
|
-
|
|
421
|
-
<h2>Our Cookie Table</h2>
|
|
422
|
-
<p>
|
|
423
|
-
Below, you will find a list of the cookies and similar technologies that we use on
|
|
424
|
-
this website. These cookies are stored on your device by us.
|
|
425
|
-
</p>
|
|
426
|
-
<table>
|
|
427
|
-
<thead>
|
|
428
|
-
<tr>
|
|
429
|
-
<th>Cookie</th>
|
|
430
|
-
<th>Category</th>
|
|
431
|
-
<th>Purpose</th>
|
|
432
|
-
<th>Lifespan</th>
|
|
433
|
-
</tr>
|
|
434
|
-
</thead>
|
|
435
|
-
<tbody>
|
|
436
|
-
<tr>
|
|
437
|
-
<td>alliance-session-v1</td>
|
|
438
|
-
<td>necessary</td>
|
|
439
|
-
<td>Contains the authenticated user.</td>
|
|
440
|
-
<td>1 day</td>
|
|
441
|
-
</tr>
|
|
442
|
-
{APP_COOKIES}
|
|
443
|
-
</tbody>
|
|
444
|
-
</table>
|
|
445
|
-
<style>
|
|
446
|
-
table {
|
|
447
|
-
width: 100%;
|
|
448
|
-
border: 1px solid rgba(0, 0, 0, 0.15);
|
|
449
|
-
}
|
|
450
|
-
th, td {
|
|
451
|
-
text-align: left;
|
|
452
|
-
padding: 3px;
|
|
453
|
-
}
|
|
454
|
-
</style>
|
|
455
|
-
</div>
|
|
456
|
-
</body>
|
|
457
|
-
</html>
|
|
458
|
-
`;
|
|
459
|
-
function getJsonSchemas() {
|
|
460
|
-
const frameworkDistDirPath = resolve(
|
|
461
|
-
process.cwd(),
|
|
462
|
-
"node_modules",
|
|
463
|
-
"@telia-ace/alliance-framework",
|
|
464
|
-
"dist"
|
|
465
|
-
);
|
|
466
|
-
const appConfigSchemaPath = resolve(frameworkDistDirPath, "config.schema.json");
|
|
467
|
-
const appManifestSchemaPath = resolve(frameworkDistDirPath, "manifest.schema.json");
|
|
468
|
-
const appConfigSchemaFile = readFileSync(appConfigSchemaPath).toString();
|
|
469
|
-
const appManifestSchemaFile = readFileSync(appManifestSchemaPath).toString();
|
|
470
|
-
const appConfig = JSON.parse(appConfigSchemaFile);
|
|
471
|
-
const appManifest = JSON.parse(appManifestSchemaFile);
|
|
472
|
-
return {
|
|
473
|
-
appConfig,
|
|
474
|
-
appManifest
|
|
475
|
-
};
|
|
476
|
-
}
|
|
477
|
-
async function createTempModuleAndImport(moduleString, fileName) {
|
|
478
|
-
const file = resolve(process.cwd(), `${fileName}.mjs`);
|
|
479
|
-
writeFileSync(file, moduleString);
|
|
480
|
-
const importedModule = await import(`file:///${file}`);
|
|
481
|
-
rmSync(file, { force: true });
|
|
482
|
-
return importedModule;
|
|
483
|
-
}
|
|
484
|
-
async function getAppManifests(apps) {
|
|
485
|
-
const moduleStringParts = [];
|
|
486
|
-
const manifestImportVariables = [];
|
|
487
|
-
for (const packageName of apps) {
|
|
488
|
-
const manifestImportVariable = `app${apps.indexOf(packageName)}`;
|
|
489
|
-
manifestImportVariables.push(manifestImportVariable);
|
|
490
|
-
moduleStringParts.push(`import ${manifestImportVariable} from '${packageName}/manifest';`);
|
|
491
|
-
}
|
|
492
|
-
moduleStringParts.push(`export default [${manifestImportVariables.join(", ")}];`);
|
|
493
|
-
const result = await createTempModuleAndImport(
|
|
494
|
-
moduleStringParts.join("\n"),
|
|
495
|
-
"app-manifests"
|
|
496
|
-
);
|
|
497
|
-
return result.default;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// src/distribution/pkg-json.ts
|
|
501
|
-
function getPkgJson() {
|
|
502
|
-
const packageJson = resolve(process.cwd(), "package.json");
|
|
503
|
-
const pkgJsonFile = readFileSync(packageJson).toString();
|
|
504
|
-
return JSON.parse(pkgJsonFile);
|
|
505
|
-
}
|
|
506
|
-
async function getManifests(pkgJson) {
|
|
507
|
-
if (!pkgJson || !pkgJson.alliance || !pkgJson.alliance.apps) {
|
|
508
|
-
throw new Error("Alliance apps not defined in package.json.");
|
|
509
|
-
}
|
|
510
|
-
const manifestArray = await getAppManifests(pkgJson.alliance.apps);
|
|
511
|
-
return manifestArray.reduce((acc, curr) => {
|
|
512
|
-
acc[curr.name] = curr;
|
|
513
|
-
return acc;
|
|
514
|
-
}, {});
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
// src/distribution/create-public-files.ts
|
|
518
|
-
var PUBLIC_DIR_NAME = "public";
|
|
519
|
-
var MANIFESTS_FILE_NAME = "manifests.json";
|
|
520
|
-
var COOKIE_POLICY_FILE_NAME = "cookie-policy.html";
|
|
521
|
-
var APP_CONFIG_SCHEMA_FILE_NAME = "config.schema.json";
|
|
522
|
-
var APP_MANIFEST_SCHEMA_FILE_NAME = "manifest.schema.json";
|
|
523
|
-
async function createPublicDistributionFiles() {
|
|
524
|
-
const pkgJson = getPkgJson();
|
|
525
|
-
const manifests = await getManifests(pkgJson);
|
|
526
|
-
const schemas = getJsonSchemas();
|
|
527
|
-
for (const appName in manifests) {
|
|
528
|
-
const manifest = manifests[appName];
|
|
529
|
-
const validationResult = validate(manifest, schemas.appManifest);
|
|
530
|
-
if (validationResult.errors.length) {
|
|
531
|
-
const errors2 = validationResult.errors.map((e) => JSON.stringify(e, null, 2));
|
|
532
|
-
throw new Error(
|
|
533
|
-
`Validation of app manifest for app '${appName}' failed with the following errors:
|
|
534
|
-
${errors2.join(
|
|
535
|
-
"\n"
|
|
536
|
-
)}`
|
|
537
|
-
);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
const publicDirPath = resolve(process.cwd(), PUBLIC_DIR_NAME);
|
|
541
|
-
if (!existsSync(publicDirPath)) {
|
|
542
|
-
mkdirSync(publicDirPath);
|
|
543
|
-
}
|
|
544
|
-
const manifestsFilePath = resolve(publicDirPath, MANIFESTS_FILE_NAME);
|
|
545
|
-
writeFileSync(manifestsFilePath, JSON.stringify(manifests));
|
|
546
|
-
const cookiePolicyFilePath = resolve(publicDirPath, COOKIE_POLICY_FILE_NAME);
|
|
547
|
-
writeFileSync(cookiePolicyFilePath, generateCookiePolicyHtml(manifests));
|
|
548
|
-
const appConfigSchemaFilePath = resolve(publicDirPath, APP_CONFIG_SCHEMA_FILE_NAME);
|
|
549
|
-
const appManifestSchemaFilePath = resolve(publicDirPath, APP_MANIFEST_SCHEMA_FILE_NAME);
|
|
550
|
-
writeFileSync(appConfigSchemaFilePath, JSON.stringify(schemas.appConfig));
|
|
551
|
-
writeFileSync(appManifestSchemaFilePath, JSON.stringify(schemas.appManifest));
|
|
552
|
-
}
|
|
553
|
-
function slugify(value, replacement = "-") {
|
|
554
|
-
return _slugify(value, { strict: true, replacement, lower: true });
|
|
555
|
-
}
|
|
556
|
-
function logFn(instance) {
|
|
557
|
-
return (level) => {
|
|
558
|
-
return (msg, data) => instance[level]({ ...data, msg });
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
function createLogger(config) {
|
|
562
|
-
const instance = pino({
|
|
563
|
-
level: config.SERVICE_LOG_LEVEL,
|
|
564
|
-
redact: [
|
|
565
|
-
"authorization",
|
|
566
|
-
"headers.authorization",
|
|
567
|
-
"req.headers.authorization",
|
|
568
|
-
"res.headers.authorization",
|
|
569
|
-
"req.headers.cookie",
|
|
570
|
-
'res.headers["set-cookie"]'
|
|
571
|
-
]
|
|
572
|
-
});
|
|
573
|
-
return {
|
|
574
|
-
fatal: logFn(instance)("fatal"),
|
|
575
|
-
error: logFn(instance)("error"),
|
|
576
|
-
warn: logFn(instance)("warn"),
|
|
577
|
-
info: logFn(instance)("info"),
|
|
578
|
-
debug: logFn(instance)("debug"),
|
|
579
|
-
trace: logFn(instance)("trace"),
|
|
580
|
-
silent: logFn(instance)("silent"),
|
|
581
|
-
child: () => createLogger(config),
|
|
582
|
-
level: config.SERVICE_LOG_LEVEL
|
|
583
|
-
};
|
|
584
|
-
}
|
|
585
|
-
function requestLoggerHandler(logger) {
|
|
586
|
-
return (req, _, next) => {
|
|
587
|
-
logger.trace("received request", {
|
|
588
|
-
url: req.url,
|
|
589
|
-
params: req.params,
|
|
590
|
-
query: req.query,
|
|
591
|
-
body: req.body
|
|
592
|
-
});
|
|
593
|
-
return next();
|
|
594
|
-
};
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
// src/errors/codes.ts
|
|
598
|
-
var GatewayErrorCode = /* @__PURE__ */ ((GatewayErrorCode2) => {
|
|
599
|
-
GatewayErrorCode2[GatewayErrorCode2["NoObjectId"] = 10001] = "NoObjectId";
|
|
600
|
-
GatewayErrorCode2[GatewayErrorCode2["NoTargetAppHeader"] = 10002] = "NoTargetAppHeader";
|
|
601
|
-
GatewayErrorCode2[GatewayErrorCode2["NoTargetWorkspaceHeader"] = 10003] = "NoTargetWorkspaceHeader";
|
|
602
|
-
GatewayErrorCode2[GatewayErrorCode2["NoManifestsInCache"] = 10004] = "NoManifestsInCache";
|
|
603
|
-
GatewayErrorCode2[GatewayErrorCode2["NoDevSessionInCache"] = 10005] = "NoDevSessionInCache";
|
|
604
|
-
GatewayErrorCode2[GatewayErrorCode2["NoManifest"] = 10006] = "NoManifest";
|
|
605
|
-
GatewayErrorCode2[GatewayErrorCode2["NoRequestContext"] = 10007] = "NoRequestContext";
|
|
606
|
-
GatewayErrorCode2[GatewayErrorCode2["NoUserInRequestContext"] = 10008] = "NoUserInRequestContext";
|
|
607
|
-
GatewayErrorCode2[GatewayErrorCode2["NoAppInRequestContext"] = 10009] = "NoAppInRequestContext";
|
|
608
|
-
GatewayErrorCode2[GatewayErrorCode2["NoWorkspaceInRequestContext"] = 10010] = "NoWorkspaceInRequestContext";
|
|
609
|
-
GatewayErrorCode2[GatewayErrorCode2["NoUserPermissionsInRequestContext"] = 10012] = "NoUserPermissionsInRequestContext";
|
|
610
|
-
GatewayErrorCode2[GatewayErrorCode2["WorkspacePermissionDenied"] = 10013] = "WorkspacePermissionDenied";
|
|
611
|
-
GatewayErrorCode2[GatewayErrorCode2["NoTargetUrlHeader"] = 10014] = "NoTargetUrlHeader";
|
|
612
|
-
GatewayErrorCode2[GatewayErrorCode2["NoSessionInRedisCache"] = 10015] = "NoSessionInRedisCache";
|
|
613
|
-
return GatewayErrorCode2;
|
|
614
|
-
})(GatewayErrorCode || {});
|
|
615
|
-
var DataErrorCode = /* @__PURE__ */ ((DataErrorCode2) => {
|
|
616
|
-
DataErrorCode2[DataErrorCode2["NoPublicKey"] = 11e3] = "NoPublicKey";
|
|
617
|
-
DataErrorCode2[DataErrorCode2["NoAuthHeader"] = 11001] = "NoAuthHeader";
|
|
618
|
-
DataErrorCode2[DataErrorCode2["FailedFileUpload"] = 11002] = "FailedFileUpload";
|
|
619
|
-
DataErrorCode2[DataErrorCode2["FailedFileDownload"] = 11003] = "FailedFileDownload";
|
|
620
|
-
return DataErrorCode2;
|
|
621
|
-
})(DataErrorCode || {});
|
|
622
|
-
var errors = {
|
|
623
|
-
[10001 /* NoObjectId */]: {
|
|
624
|
-
statusCode: 401,
|
|
625
|
-
msg: "No object id available on authenticated user."
|
|
626
|
-
},
|
|
627
|
-
[10002 /* NoTargetAppHeader */]: {
|
|
628
|
-
statusCode: 400,
|
|
629
|
-
msg: `Request missing header '${"alliance-target-app" /* TargetApp */}'.`
|
|
630
|
-
},
|
|
631
|
-
[10003 /* NoTargetWorkspaceHeader */]: {
|
|
632
|
-
statusCode: 400,
|
|
633
|
-
msg: `Request missing header '${"alliance-target-workspace" /* TargetWorkspace */}'.`
|
|
634
|
-
},
|
|
635
|
-
[10014 /* NoTargetUrlHeader */]: {
|
|
636
|
-
statusCode: 400,
|
|
637
|
-
msg: `Request missing header '${"alliance-target-url" /* TargetUrl */}'.`
|
|
638
|
-
},
|
|
639
|
-
[10004 /* NoManifestsInCache */]: {
|
|
640
|
-
statusCode: 500,
|
|
641
|
-
msg: "App manifests missing in cache."
|
|
642
|
-
},
|
|
643
|
-
[10005 /* NoDevSessionInCache */]: {
|
|
644
|
-
statusCode: 500,
|
|
645
|
-
msg: "No dev session in memory cache."
|
|
646
|
-
},
|
|
647
|
-
[10015 /* NoSessionInRedisCache */]: {
|
|
648
|
-
statusCode: 401,
|
|
649
|
-
msg: "Could not find user session in Redis server."
|
|
650
|
-
},
|
|
651
|
-
[10006 /* NoManifest */]: {
|
|
652
|
-
statusCode: 500,
|
|
653
|
-
msg: "Could not find manifest for app '{{appSlug}}'."
|
|
654
|
-
},
|
|
655
|
-
[10007 /* NoRequestContext */]: {
|
|
656
|
-
statusCode: 500,
|
|
657
|
-
msg: "No request context."
|
|
658
|
-
},
|
|
659
|
-
[10008 /* NoUserInRequestContext */]: {
|
|
660
|
-
statusCode: 500,
|
|
661
|
-
msg: "No user in request context."
|
|
662
|
-
},
|
|
663
|
-
[10009 /* NoAppInRequestContext */]: {
|
|
664
|
-
statusCode: 500,
|
|
665
|
-
msg: "No app in request context."
|
|
666
|
-
},
|
|
667
|
-
[10010 /* NoWorkspaceInRequestContext */]: {
|
|
668
|
-
statusCode: 500,
|
|
669
|
-
msg: "No workspace in request context."
|
|
670
|
-
},
|
|
671
|
-
[10012 /* NoUserPermissionsInRequestContext */]: {
|
|
672
|
-
statusCode: 500,
|
|
673
|
-
msg: "No user permissions in request context."
|
|
674
|
-
},
|
|
675
|
-
[10013 /* WorkspacePermissionDenied */]: {
|
|
676
|
-
statusCode: 403,
|
|
677
|
-
msg: "User does not have access to the current workspace."
|
|
678
|
-
},
|
|
679
|
-
[11e3 /* NoPublicKey */]: {
|
|
680
|
-
statusCode: 401,
|
|
681
|
-
msg: "No public key available to decode JWT."
|
|
682
|
-
},
|
|
683
|
-
[11001 /* NoAuthHeader */]: {
|
|
684
|
-
statusCode: 401,
|
|
685
|
-
msg: "No authorization header found."
|
|
686
|
-
},
|
|
687
|
-
[11002 /* FailedFileUpload */]: {
|
|
688
|
-
statusCode: 500,
|
|
689
|
-
msg: "Something went wrong when trying to upload a file to the S3 storage."
|
|
690
|
-
},
|
|
691
|
-
[11003 /* FailedFileDownload */]: {
|
|
692
|
-
statusCode: 500,
|
|
693
|
-
msg: "Something went wrong when trying to download a file to the S3 storage."
|
|
694
|
-
},
|
|
695
|
-
[12e3 /* NoObjectId */]: {
|
|
696
|
-
statusCode: 401,
|
|
697
|
-
msg: "No object id found in user claims."
|
|
698
|
-
}
|
|
699
|
-
};
|
|
700
|
-
|
|
701
|
-
// src/errors/errors.ts
|
|
702
|
-
var AllianceError = class extends Error {
|
|
703
|
-
constructor(errorCode, variables = {}) {
|
|
704
|
-
const { msg, statusCode } = errors[errorCode];
|
|
705
|
-
const message = parseTemplates(msg, variables);
|
|
706
|
-
super(message);
|
|
707
|
-
this.errorCode = errorCode;
|
|
708
|
-
this.info = `https://github.com/telia-company/ace-alliance-sdk/wiki/error-codes#${this.errorCode}`;
|
|
709
|
-
this.message = message;
|
|
710
|
-
this.statusCode = statusCode;
|
|
711
|
-
}
|
|
712
|
-
};
|
|
713
|
-
function parseTemplates(message, variables) {
|
|
714
|
-
return Object.entries(variables).reduce((acc, [key, value]) => {
|
|
715
|
-
return acc.replaceAll(`{{${key}}}`, value);
|
|
716
|
-
}, message);
|
|
717
|
-
}
|
|
718
|
-
function requestErrorHandler(logger) {
|
|
719
|
-
return (err, req, res, _next) => {
|
|
720
|
-
const error = {
|
|
721
|
-
cause: err.cause,
|
|
722
|
-
message: err.message,
|
|
723
|
-
status: err.status || err.statusCode || err.code,
|
|
724
|
-
info: err.info
|
|
725
|
-
};
|
|
726
|
-
logger.error("error when processing request", {
|
|
727
|
-
url: req.url,
|
|
728
|
-
body: req.body,
|
|
729
|
-
error
|
|
730
|
-
});
|
|
731
|
-
return res.status(error.status).json(error);
|
|
732
|
-
};
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
export { AllianceError, AllianceHeaders, DataErrorCode, GatewayErrorCode, createBearerToken, createLogger, createPublicDistributionFiles, createPublicKeys, createSystemUserToken, getCleanPublicKey, getPrivateKey, requestErrorHandler, requestLoggerHandler, slugify, zBooleanEnum, zNonEmptyString, zSharedConfig };
|
|
736
|
-
//# sourceMappingURL=out.js.map
|
|
737
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import{a as E,b as ue,c as ce,d as le}from"./chunk-UNKGNXJ3.js";import"./chunk-26VIM55J.js";import"./chunk-JG7V63GM.js";import pe from"jsonwebtoken";import{createPublicKey as fe}from"node:crypto";var me=E.enum(["true","false"]).transform(e=>e==="true"),y=E.string().min(1),T=E.object({AUTH_COOKIE_NAME:y.default("alliance-auth"),AUTH_COOKIE_SECRET:y.default("zlLZBlk7wt8lypP5lA4D"),DB_ENDPOINT:y,JWT_PRIVATE_KEY:y.default("MIIEogIBAAKCAQEAsGqOzjnfQtCYlDqhgGAnKuJOCiPt2WpCmL1Cs+SLBQlyoNn6LT8BJ6ZRj8t/vK8Sw0p51Uq/3k0tazh7bLGkWNMBLY3BqFiNRMMnCqHJfvGIUi/itNXNe2kbP7H3rbyQTu4O7yH/ZAMitdpF2KLucVRlFxrQ/ggZjxwEGso4JUnCwmAnoKct/uupKz9Y2PMTr00WWN79aPfD4LcKi570VJqBT3ISSucdwFLYNqnOkQnEa8O8xbthQhiI0k1GGJT+GCQcATUPeEbaCFXonOrJm+CyuMmQWYLFF3NbE5NllU1jz9PYHzp2hAgAx8WGeretTvpEA1dE2gvXNESGbQ8F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UAiODfjulrpYvWG0tCn5B//yk7g1Tm3Chrh9huA1qGEN3jDoqSsTd5k4Yi5foyAZt5ORgoiUVm4IsfS56aoxIco1CtFG3zeMQRy4uKzTsvUTOdsJ4RlQdjNwpngXR44VL0WelgCDqTqJwn5ubzPvuIHuTj3cBpmJCjOo="),JWT_PUBLIC_CSP_KEY:E.string().min(1).default("BgIAAACkAABSU0ExAAgAAAEAAQDFBQ9thkQ01wvaRFcDRPpOrbd6hsXHAAiEdjof2NPPY02VZZMTW3MXxYJZkMm4suCbyeqc6FUI2kZ4DzUBHCQY/pQYRk3SiBhCYbvFvMNrxAmRzqk22FLAHedKEnJPgZpU9J6LCrfgw/do/d5YFk2vE/PYWD8rqev+LaegJ2DCwkklOMoaBByPGQj+0BoXZVRx7qLYRdq1IgNk/yHvDu5OkLyt97E/G2l7zdW04i9SiPF+yaEKJ8NEjViowY0tAdNYpLFsezhrLU3ev0rVeUrDEq+8f8uPUaYnAT8t+tmgcgkFi+SzQr2YQmrZ7SMKTuIqJ2CAoTqUmNBC3znOjmqw"),SERVICE_LOG_LEVEL:E.enum(["silent","fatal","error","warn","info","debug","trace"]).default("trace"),SERVICE_PORT:y.transform(Number).default("3000"),REDIS_HOST:y,REDIS_PASSWORD:y.optional()});var K=(u=>(u.TargetUrl="alliance-target-url",u.TargetApp="alliance-target-app",u.TargetWorkspace="alliance-target-workspace",u))(K||{});var Xe=T.pick({JWT_PRIVATE_KEY:!0,JWT_PUBLIC_CSP_KEY:!0});function j({privateKey:e,aud:t,sub:n,name:u,user:c,workspace:m,expiration:g="1h"}){return`Bearer ${pe.sign({iss:"Alliance",aud:t,sub:n,name:u,"https://alliance.teliacompany.net/user_type":c.type,"https://alliance.teliacompany.net/user_email":c.email,"https://alliance.teliacompany.net/user_privileges":c.permissions,"https://alliance.teliacompany.net/workspace":m.slug,"https://alliance.teliacompany.net/workspace_name":m.name,"https://alliance.teliacompany.net/tenant":m.slug,"https://alliance.teliacompany.net/tenant_name":m.name},e,{expiresIn:g,algorithm:"RS256"})}`}function L(e){return`-----BEGIN RSA PRIVATE KEY-----
|
|
2
|
+
`+e.JWT_PRIVATE_KEY+`
|
|
3
|
+
-----END RSA PRIVATE KEY-----`}function ge(e){return j({aud:"system",sub:"system",name:"system",workspace:{slug:"system",name:"system"},user:{type:"system",permissions:[],email:"system"},privateKey:L(e)})}function de(e){let t=L(e),n=fe(t);return{pkcs:n.export({type:"pkcs1",format:"pem"}).toString().trim(),spki:n.export({type:"spki",format:"pem"}).toString().trim(),csp:e.JWT_PUBLIC_CSP_KEY}}function ye(e,t){return t[e].replace("-----BEGIN RSA PUBLIC KEY-----","").replace("-----END RSA PUBLIC KEY-----","").replace("-----BEGIN PUBLIC KEY-----","").replace("-----END PUBLIC KEY-----","").trim().replaceAll(`
|
|
4
|
+
`,"")}import{homedir as Oe,tmpdir as ze}from"node:os";import{resolve as Fe}from"node:path";var he=/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,Ie=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,ve=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function we(e,t){if(e==="__proto__"||e==="constructor"&&t&&typeof t=="object"&&"prototype"in t){Ee(e);return}return t}function Ee(e){console.warn(`[destr] Dropping "${e}" key to prevent prototype pollution.`)}function C(e,t={}){if(typeof e!="string")return e;let n=e.trim();if(e[0]==='"'&&e.at(-1)==='"'&&!e.includes("\\"))return n.slice(1,-1);if(n.length<=9){let u=n.toLowerCase();if(u==="true")return!0;if(u==="false")return!1;if(u==="undefined")return;if(u==="null")return null;if(u==="nan")return Number.NaN;if(u==="infinity")return Number.POSITIVE_INFINITY;if(u==="-infinity")return Number.NEGATIVE_INFINITY}if(!ve.test(e)){if(t.strict)throw new SyntaxError("[destr] Invalid JSON");return e}try{if(he.test(e)||Ie.test(e)){if(t.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(e,we)}return JSON.parse(e)}catch(u){if(t.strict)throw u;return e}}function xe(e){return!e||typeof e.then!="function"?Promise.resolve(e):e}function p(e,...t){try{return xe(e(...t))}catch(n){return Promise.reject(n)}}function Ce(e){let t=typeof e;return e===null||t!=="object"&&t!=="function"}function Ae(e){let t=Object.getPrototypeOf(e);return!t||t.isPrototypeOf(Object)}function A(e){if(Ce(e))return String(e);if(Ae(e)||Array.isArray(e))return JSON.stringify(e);if(typeof e.toJSON=="function")return A(e.toJSON());throw new Error("[unstorage] Cannot stringify value!")}function M(){if(typeof Buffer===void 0)throw new TypeError("[unstorage] Buffer is not supported!")}var b="base64:";function V(e){if(typeof e=="string")return e;M();let t=Buffer.from(e).toString("base64");return b+t}function Y(e){return typeof e!="string"||!e.startsWith(b)?e:(M(),Buffer.from(e.slice(b.length),"base64"))}var Se=["hasItem","getItem","getItemRaw","setItem","setItemRaw","removeItem","getMeta","setMeta","removeMeta","getKeys","clear","mount","unmount"];function B(e,t){if(t=x(t),!t)return e;let n={...e};for(let u of Se)n[u]=(c="",...m)=>e[u](t+c,...m);return n.getKeys=(u="",...c)=>e.getKeys(t+u,...c).then(m=>m.map(g=>g.slice(t.length))),n}function f(e){return e?e.split("?")[0].replace(/[/\\]/g,":").replace(/:+/g,":").replace(/^:|:$/g,""):""}function D(...e){return f(e.join(":"))}function x(e){return e=f(e),e?e+":":""}var Re="memory",Ne=()=>{let e=new Map;return{name:Re,options:{},hasItem(t){return e.has(t)},getItem(t){return e.get(t)??null},getItemRaw(t){return e.get(t)??null},setItem(t,n){e.set(t,n)},setItemRaw(t,n){e.set(t,n)},removeItem(t){e.delete(t)},getKeys(){return Array.from(e.keys())},clear(){e.clear()},dispose(){e.clear()}}};function Q(e={}){let t={mounts:{"":e.driver||Ne()},mountpoints:[""],watching:!1,watchListeners:[],unwatch:{}},n=r=>{for(let o of t.mountpoints)if(r.startsWith(o))return{base:o,relativeKey:r.slice(o.length),driver:t.mounts[o]};return{base:"",relativeKey:r,driver:t.mounts[""]}},u=(r,o)=>t.mountpoints.filter(s=>s.startsWith(r)||o&&r.startsWith(s)).map(s=>({relativeBase:r.length>s.length?r.slice(s.length):void 0,mountpoint:s,driver:t.mounts[s]})),c=(r,o)=>{if(t.watching){o=f(o);for(let s of t.watchListeners)s(r,o)}},m=async()=>{if(!t.watching){t.watching=!0;for(let r in t.mounts)t.unwatch[r]=await J(t.mounts[r],c,r)}},g=async()=>{if(t.watching){for(let r in t.unwatch)await t.unwatch[r]();t.unwatch={},t.watching=!1}},h=(r,o,s)=>{let a=new Map,i=l=>{let d=a.get(l.base);return d||(d={driver:l.driver,base:l.base,items:[]},a.set(l.base,d)),d};for(let l of r){let d=typeof l=="string",R=f(d?l:l.key),I=d?void 0:l.value,P=d||!l.options?o:{...o,...l.options},W=n(R);i(W).items.push({key:R,value:I,relativeKey:W.relativeKey,options:P})}return Promise.all([...a.values()].map(l=>s(l))).then(l=>l.flat())},S={hasItem(r,o={}){r=f(r);let{relativeKey:s,driver:a}=n(r);return p(a.hasItem,s,o)},getItem(r,o={}){r=f(r);let{relativeKey:s,driver:a}=n(r);return p(a.getItem,s,o).then(i=>C(i))},getItems(r,o){return h(r,o,s=>s.driver.getItems?p(s.driver.getItems,s.items.map(a=>({key:a.relativeKey,options:a.options})),o).then(a=>a.map(i=>({key:D(s.base,i.key),value:C(i.value)}))):Promise.all(s.items.map(a=>p(s.driver.getItem,a.relativeKey,a.options).then(i=>({key:a.key,value:C(i)})))))},getItemRaw(r,o={}){r=f(r);let{relativeKey:s,driver:a}=n(r);return a.getItemRaw?p(a.getItemRaw,s,o):p(a.getItem,s,o).then(i=>Y(i))},async setItem(r,o,s={}){if(o===void 0)return S.removeItem(r);r=f(r);let{relativeKey:a,driver:i}=n(r);i.setItem&&(await p(i.setItem,a,A(o),s),i.watch||c("update",r))},async setItems(r,o){await h(r,o,async s=>{s.driver.setItems&&await p(s.driver.setItems,s.items.map(a=>({key:a.relativeKey,value:A(a.value),options:a.options})),o),s.driver.setItem&&await Promise.all(s.items.map(a=>p(s.driver.setItem,a.relativeKey,A(a.value),a.options)))})},async setItemRaw(r,o,s={}){if(o===void 0)return S.removeItem(r,s);r=f(r);let{relativeKey:a,driver:i}=n(r);if(i.setItemRaw)await p(i.setItemRaw,a,o,s);else if(i.setItem)await p(i.setItem,a,V(o),s);else return;i.watch||c("update",r)},async removeItem(r,o={}){typeof o=="boolean"&&(o={removeMeta:o}),r=f(r);let{relativeKey:s,driver:a}=n(r);a.removeItem&&(await p(a.removeItem,s,o),(o.removeMeta||o.removeMata)&&await p(a.removeItem,s+"$",o),a.watch||c("remove",r))},async getMeta(r,o={}){typeof o=="boolean"&&(o={nativeOnly:o}),r=f(r);let{relativeKey:s,driver:a}=n(r),i=Object.create(null);if(a.getMeta&&Object.assign(i,await p(a.getMeta,s,o)),!o.nativeOnly){let l=await p(a.getItem,s+"$",o).then(d=>C(d));l&&typeof l=="object"&&(typeof l.atime=="string"&&(l.atime=new Date(l.atime)),typeof l.mtime=="string"&&(l.mtime=new Date(l.mtime)),Object.assign(i,l))}return i},setMeta(r,o,s={}){return this.setItem(r+"$",o,s)},removeMeta(r,o={}){return this.removeItem(r+"$",o)},async getKeys(r,o={}){r=x(r);let s=u(r,!0),a=[],i=[];for(let l of s){let R=(await p(l.driver.getKeys,l.relativeBase,o)).map(I=>l.mountpoint+f(I)).filter(I=>!a.some(P=>I.startsWith(P)));i.push(...R),a=[l.mountpoint,...a.filter(I=>!I.startsWith(l.mountpoint))]}return r?i.filter(l=>l.startsWith(r)&&!l.endsWith("$")):i.filter(l=>!l.endsWith("$"))},async clear(r,o={}){r=x(r),await Promise.all(u(r,!1).map(async s=>{if(s.driver.clear)return p(s.driver.clear,s.relativeBase,o);if(s.driver.removeItem){let a=await s.driver.getKeys(s.relativeBase||"",o);return Promise.all(a.map(i=>s.driver.removeItem(i,o)))}}))},async dispose(){await Promise.all(Object.values(t.mounts).map(r=>H(r)))},async watch(r){return await m(),t.watchListeners.push(r),async()=>{t.watchListeners=t.watchListeners.filter(o=>o!==r),t.watchListeners.length===0&&await g()}},async unwatch(){t.watchListeners=[],await g()},mount(r,o){if(r=x(r),r&&t.mounts[r])throw new Error(`already mounted at ${r}`);return r&&(t.mountpoints.push(r),t.mountpoints.sort((s,a)=>a.length-s.length)),t.mounts[r]=o,t.watching&&Promise.resolve(J(o,c,r)).then(s=>{t.unwatch[r]=s}).catch(console.error),S},async unmount(r,o=!0){r=x(r),!(!r||!t.mounts[r])&&(t.watching&&r in t.unwatch&&(t.unwatch[r](),delete t.unwatch[r]),o&&await H(t.mounts[r]),t.mountpoints=t.mountpoints.filter(s=>s!==r),delete t.mounts[r])},getMount(r=""){r=f(r)+":";let o=n(r);return{driver:o.driver,base:o.base}},getMounts(r="",o={}){return r=f(r),u(r,o.parents).map(a=>({driver:a.driver,base:a.mountpoint}))}};return S}function J(e,t,n){return e.watch?e.watch((u,c)=>t(u,n+c)):()=>{}}async function H(e){typeof e.dispose=="function"&&await p(e.dispose)}import{existsSync as Te,promises as Ke}from"fs";import{resolve as Le,join as be}from"path";function N(e,t,n){return new Error(`[unstorage] [${e}] ${t}`,n)}function G(e,t){return Array.isArray(t)?N(e,`Missing some of the required options ${t.map(n=>"`"+n+"`").join(", ")}`):N(e,`Missing required option \`${t}\`.`)}import{existsSync as Pe,promises as v}from"fs";import{resolve as X,dirname as $}from"path";function O(e){return e.code==="ENOENT"||e.code==="EISDIR"?null:e}function Z(e){return e.code==="EEXIST"?null:e}async function z(e,t,n){return await re($(e)),v.writeFile(e,t,n)}function F(e,t){return v.readFile(e,t).catch(O)}function ee(e){return v.unlink(e).catch(O)}function te(e){return v.readdir(e,{withFileTypes:!0}).catch(O).then(t=>t||[])}async function re(e){Pe(e)||(await re($(e)).catch(Z),await v.mkdir(e).catch(Z))}async function q(e,t){if(t&&t(e))return[];let n=await te(e),u=[];return await Promise.all(n.map(async c=>{let m=X(e,c.name);if(c.isDirectory()){let g=await q(m,t);u.push(...g.map(h=>c.name+"/"+h))}else t&&t(c.name)||u.push(c.name)})),u}async function _(e){let t=await te(e);await Promise.all(t.map(n=>{let u=X(e,n.name);return n.isDirectory()?_(u).then(()=>v.rmdir(u)):v.unlink(u)}))}var Be=/\.\.\:|\.\.$/,k="fs-lite",ne=(e={})=>{if(!e.base)throw G(k,"base");e.base=Le(e.base);let t=n=>{if(Be.test(n))throw N(k,`Invalid key: ${JSON.stringify(n)}. It should not contain .. segments`);return be(e.base,n.replace(/:/g,"/"))};return{name:k,options:e,hasItem(n){return Te(t(n))},getItem(n){return F(t(n),"utf8")},getItemRaw(n){return F(t(n))},async getMeta(n){let{atime:u,mtime:c,size:m,birthtime:g,ctime:h}=await Ke.stat(t(n)).catch(()=>({}));return{atime:u,mtime:c,size:m,birthtime:g,ctime:h}},setItem(n,u){if(!e.readOnly)return z(t(n),u,"utf8")},setItemRaw(n,u){if(!e.readOnly)return z(t(n),u)},removeItem(n){if(!e.readOnly)return ee(t(n))},getKeys(){return q(t("."),e.ignore)},async clear(){e.readOnly||e.noClear||await _(t("."))}}};function qe({prefix:e,logger:t}){return B(Q({driver:ne({base:_e({logger:t})})}),e)}function _e({logger:e}){let t="";try{t=Oe()}catch(n){e.error("could not use homedir, trying tmpdir",{error:n?.message})}if(!t)try{t=ze()}catch(n){e.error("could not use tmpdir, trying process.cwd",{error:n?.message})}if(!t)try{t=process.cwd()}catch(n){e.error("could not use process.cwd, exiting",{error:n?.message}),process.exit(1)}return Fe(t,".alliance")}import ke from"pino";function w(e){return t=>(n,u)=>e[t]({...u,msg:n})}function oe(e){let t=ke({level:e.SERVICE_LOG_LEVEL,redact:["authorization","headers.authorization","req.headers.authorization","res.headers.authorization","req.headers.cookie",'res.headers["set-cookie"]']});return{fatal:w(t)("fatal"),error:w(t)("error"),warn:w(t)("warn"),info:w(t)("info"),debug:w(t)("debug"),trace:w(t)("trace"),silent:w(t)("silent"),child:()=>oe(e),level:e.SERVICE_LOG_LEVEL}}function Ue(e){return(t,n,u)=>(e.trace("received request",{url:t.url,params:t.params,query:t.query,body:t.body}),u())}var se=(i=>(i[i.NoObjectId=10001]="NoObjectId",i[i.NoTargetAppHeader=10002]="NoTargetAppHeader",i[i.NoTargetWorkspaceHeader=10003]="NoTargetWorkspaceHeader",i[i.NoManifest=10006]="NoManifest",i[i.NoRequestContext=10007]="NoRequestContext",i[i.NoUserInRequestContext=10008]="NoUserInRequestContext",i[i.NoAppInRequestContext=10009]="NoAppInRequestContext",i[i.NoWorkspaceInRequestContext=10010]="NoWorkspaceInRequestContext",i[i.NoUserPermissionsInRequestContext=10012]="NoUserPermissionsInRequestContext",i[i.WorkspacePermissionDenied=10013]="WorkspacePermissionDenied",i[i.NoTargetUrlHeader=10014]="NoTargetUrlHeader",i[i.NoSessionInRedisCache=10015]="NoSessionInRedisCache",i[i.ProhibitedTargetDomain=10016]="ProhibitedTargetDomain",i))(se||{}),ie=(c=>(c[c.NoPublicKey=11e3]="NoPublicKey",c[c.NoAuthHeader=11001]="NoAuthHeader",c[c.FailedFileUpload=11002]="FailedFileUpload",c[c.FailedFileDownload=11003]="FailedFileDownload",c))(ie||{});var ae={10001:{statusCode:401,msg:"No object id available on authenticated user."},10002:{statusCode:400,msg:"Request missing header 'alliance-target-app'."},10003:{statusCode:400,msg:"Request missing header 'alliance-target-workspace'."},10014:{statusCode:400,msg:"Request missing header 'alliance-target-url'."},10015:{statusCode:401,msg:"Could not find user session in Redis server."},10006:{statusCode:500,msg:"Could not find manifest for app '{{appSlug}}'."},10007:{statusCode:500,msg:"No request context."},10008:{statusCode:500,msg:"No user in request context."},10009:{statusCode:500,msg:"No app in request context."},10010:{statusCode:500,msg:"No workspace in request context."},10012:{statusCode:500,msg:"No user permissions in request context."},10013:{statusCode:403,msg:"User does not have access to the current workspace."},10016:{statusCode:403,msg:"Request prohibited - REQUEST_DOMAIN_WHITE_LIST does not contain '{{domain}}'."},11e3:{statusCode:401,msg:"No public key available to decode JWT."},11001:{statusCode:401,msg:"No authorization header found."},11002:{statusCode:500,msg:"Something went wrong when trying to upload a file to the S3 storage."},11003:{statusCode:500,msg:"Something went wrong when trying to download a file to the S3 storage."},12e3:{statusCode:401,msg:"No object id found in user claims."}};var U=class extends Error{constructor(n,u={}){let{msg:c,statusCode:m}=ae[n],g=We(c,u);super(g);this.errorCode=n;this.message=g,this.statusCode=m,this.info=`https://github.com/telia-company/ace-alliance-sdk/wiki/error-codes#${this.errorCode}`}info;statusCode};function We(e,t){return Object.entries(t).reduce((n,[u,c])=>n.replaceAll(`{{${u}}}`,c),e)}function je(e){return(t,n,u,c)=>{let m={cause:t.cause,message:t.message,status:t.status||t.statusCode||t.code,info:t.info};return e.error("error when processing request",{url:n.url,body:n.body,error:m}),u.status(m.status).json(m)}}export{U as AllianceError,K as AllianceHeaders,ie as DataErrorCode,se as GatewayErrorCode,j as createBearerToken,qe as createFileStorage,ce as createIndexHtml,oe as createLogger,de as createPublicKeys,ge as createSystemUserToken,le as getAppManifests,ye as getCleanPublicKey,L as getPrivateKey,je as requestErrorHandler,Ue as requestLoggerHandler,ue as slugify,me as zBooleanEnum,y as zNonEmptyString,T as zSharedConfig};
|