edge.libx.js 0.0.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/LICENSE +21 -0
- package/README.md +49 -0
- package/bin/cli.sh +7 -0
- package/bin/set-secrets.ts +70 -0
- package/bin/test.ts +18 -0
- package/build/Main.d.ts +1 -0
- package/build/Main.js +6 -0
- package/build/Main.js.map +1 -0
- package/build/helpers/EdgeNetwork.d.ts +13 -0
- package/build/helpers/EdgeNetwork.js +100 -0
- package/build/helpers/EdgeNetwork.js.map +1 -0
- package/build/helpers/Exceptions.d.ts +37 -0
- package/build/helpers/Exceptions.js +100 -0
- package/build/helpers/Exceptions.js.map +1 -0
- package/build/helpers/getExpress.d.ts +4 -0
- package/build/helpers/getExpress.js +25 -0
- package/build/helpers/getExpress.js.map +1 -0
- package/build/helpers/index.d.ts +12 -0
- package/build/helpers/index.js +70 -0
- package/build/helpers/index.js.map +1 -0
- package/build/helpers/jwt.d.ts +57 -0
- package/build/helpers/jwt.js +227 -0
- package/build/helpers/jwt.js.map +1 -0
- package/build/helpers/localServer.d.ts +1 -0
- package/build/helpers/localServer.js +54 -0
- package/build/helpers/localServer.js.map +1 -0
- package/build/helpers/require.d.ts +1 -0
- package/build/helpers/require.js +219 -0
- package/build/helpers/require.js.map +1 -0
- package/build/modules/@module.d.ts +6 -0
- package/build/modules/@module.js +16 -0
- package/build/modules/@module.js.map +1 -0
- package/build/modules/RouterWrapper.d.ts +21 -0
- package/build/modules/RouterWrapper.js +62 -0
- package/build/modules/RouterWrapper.js.map +1 -0
- package/build/modules/cors.d.ts +15 -0
- package/build/modules/cors.js +117 -0
- package/build/modules/cors.js.map +1 -0
- package/jest.config.js +26 -0
- package/package.json +65 -0
- package/src/Main.ts +1 -0
- package/src/helpers/EdgeNetwork.ts +113 -0
- package/src/helpers/Exceptions.ts +102 -0
- package/src/helpers/getExpress.ts +25 -0
- package/src/helpers/index.ts +61 -0
- package/src/helpers/jwt.ts +287 -0
- package/src/helpers/localServer.ts +75 -0
- package/src/helpers/require.ts +331 -0
- package/src/modules/@module.ts +13 -0
- package/src/modules/RouterWrapper.ts +68 -0
- package/src/modules/cors.ts +153 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.JwtHelper = void 0;
|
|
13
|
+
const essentials_js_1 = require("libx.js/build/bundles/essentials.js");
|
|
14
|
+
const js_base64_1 = require("js-base64");
|
|
15
|
+
const EdgeNetwork_js_1 = require("./EdgeNetwork.js");
|
|
16
|
+
class JwtHelper {
|
|
17
|
+
static base64urlEncode(str) {
|
|
18
|
+
return str.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
19
|
+
}
|
|
20
|
+
static objectToBase64url(payload) {
|
|
21
|
+
return this.arrayBufferToBase64Url(new TextEncoder().encode(JSON.stringify(payload)));
|
|
22
|
+
}
|
|
23
|
+
static arrayBufferToBase64Url(buffer) {
|
|
24
|
+
return btoa(String.fromCharCode(...new Uint8Array(buffer)))
|
|
25
|
+
.replace(/=/g, '')
|
|
26
|
+
.replace(/\+/g, '-')
|
|
27
|
+
.replace(/\//g, '_');
|
|
28
|
+
}
|
|
29
|
+
static hexToBuffer(hex) {
|
|
30
|
+
var _a;
|
|
31
|
+
const matches = (_a = hex.match(/[\da-f]{2}/gi)) !== null && _a !== void 0 ? _a : [];
|
|
32
|
+
const { buffer } = new Uint8Array(matches.map((h) => parseInt(h, 16)));
|
|
33
|
+
return buffer;
|
|
34
|
+
}
|
|
35
|
+
static getGooglePublicKey(kid) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
if (this.cachedFirebasePublicKeys[kid])
|
|
38
|
+
return this.cachedFirebasePublicKeys[kid];
|
|
39
|
+
const result = yield (yield fetch("https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com")).json();
|
|
40
|
+
const res = result.keys.find((key) => key.kid === kid);
|
|
41
|
+
this.cachedFirebasePublicKeys[kid] = res;
|
|
42
|
+
return res;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
static generateSignedJWT(serviceAccount, scope, options) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
options = Object.assign(Object.assign({}, new Options()), options);
|
|
48
|
+
const pem = serviceAccount.private_key.replace(/\n/g, '');
|
|
49
|
+
const pemHeader = '-----BEGIN PRIVATE KEY-----';
|
|
50
|
+
const pemFooter = '-----END PRIVATE KEY-----';
|
|
51
|
+
if (!pem.startsWith(pemHeader) || !pem.endsWith(pemFooter)) {
|
|
52
|
+
throw new Error('Invalid service account private key');
|
|
53
|
+
}
|
|
54
|
+
const pemContents = pem.substring(pemHeader.length, pem.length - pemFooter.length);
|
|
55
|
+
const buffer = js_base64_1.Base64.toUint8Array(pemContents);
|
|
56
|
+
const algorithm = {
|
|
57
|
+
name: 'RSASSA-PKCS1-v1_5',
|
|
58
|
+
hash: {
|
|
59
|
+
name: 'SHA-256',
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
const extractable = false;
|
|
63
|
+
const privateKey = yield crypto.subtle.importKey('pkcs8', buffer, algorithm, extractable, ["sign"]);
|
|
64
|
+
const header = js_base64_1.Base64.encodeURI(JSON.stringify({
|
|
65
|
+
alg: 'RS256',
|
|
66
|
+
typ: 'JWT',
|
|
67
|
+
kid: serviceAccount.private_key_id,
|
|
68
|
+
}));
|
|
69
|
+
const iat = Math.floor(Date.now() / 1000);
|
|
70
|
+
const exp = iat + options.exp;
|
|
71
|
+
const payload = js_base64_1.Base64.encodeURI(JSON.stringify({
|
|
72
|
+
iss: serviceAccount.client_email,
|
|
73
|
+
sub: serviceAccount.client_email,
|
|
74
|
+
scope,
|
|
75
|
+
aud: options.aud,
|
|
76
|
+
exp,
|
|
77
|
+
iat,
|
|
78
|
+
}));
|
|
79
|
+
const textEncoder = new TextEncoder();
|
|
80
|
+
const inputArrayBuffer = textEncoder.encode(`${header}.${payload}`);
|
|
81
|
+
const outputArrayBuffer = yield crypto.subtle.sign({ name: 'RSASSA-PKCS1-v1_5' }, privateKey, inputArrayBuffer);
|
|
82
|
+
const signature = js_base64_1.Base64.fromUint8Array(new Uint8Array(outputArrayBuffer), true);
|
|
83
|
+
return {
|
|
84
|
+
header,
|
|
85
|
+
payload,
|
|
86
|
+
signature
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
static generateToken(serviceAccount, scope, options) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
const signed = yield this.generateSignedJWT(serviceAccount, scope, options);
|
|
93
|
+
const token = `${signed.header}.${signed.payload}.${signed.signature}`;
|
|
94
|
+
return token;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
static generateOAuth(serviceAccount, scope, options) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const token = yield this.generateToken(serviceAccount, scope, options);
|
|
100
|
+
return yield this.jwtToOAuth(token);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
static jwtToOAuth(signedJwt) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
const tokenRequest = {
|
|
106
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
|
107
|
+
assertion: signedJwt
|
|
108
|
+
};
|
|
109
|
+
try {
|
|
110
|
+
const response = yield EdgeNetwork_js_1.network.httpPostJson('https://oauth2.googleapis.com/token', tokenRequest);
|
|
111
|
+
const tmp = response;
|
|
112
|
+
if (tmp.error)
|
|
113
|
+
throw tmp;
|
|
114
|
+
return tmp.access_token;
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.error('Error fetching OAuth2 token:', error);
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
static makeRequest(url_1, serviceAccountObj_1, scope_1, payload_1) {
|
|
123
|
+
return __awaiter(this, arguments, void 0, function* (url, serviceAccountObj, scope, payload, options = {
|
|
124
|
+
method: "POST",
|
|
125
|
+
exHeaders: {}
|
|
126
|
+
}) {
|
|
127
|
+
const token = yield JwtHelper.generateOAuth(serviceAccountObj, scope);
|
|
128
|
+
essentials_js_1.libx.log.d('DBG: makeRequest: ', scope, token);
|
|
129
|
+
const bqResp = yield fetch(url, {
|
|
130
|
+
method: options.method,
|
|
131
|
+
body: payload ? JSON.stringify(payload) : null,
|
|
132
|
+
headers: Object.assign({ "content-type": "application/json;charset=UTF-8", "Authorization": "Bearer " + token }, options.exHeaders)
|
|
133
|
+
});
|
|
134
|
+
return bqResp;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
static verifyFirebaseToken(token, expectAud) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
const dur = essentials_js_1.libx.Measurement.start();
|
|
140
|
+
const expectIss = `https://securetoken.google.com/${expectAud}`;
|
|
141
|
+
const tokenParts = token.split('.');
|
|
142
|
+
const header = JSON.parse(atob(tokenParts[0]));
|
|
143
|
+
const key = yield this.getGooglePublicKey(header.kid);
|
|
144
|
+
const payload = yield this.verifyToken(key, token, expectAud, expectIss);
|
|
145
|
+
essentials_js_1.libx.log.d(`verifyFirebaseToken: dur: ${dur.peek()}ms`);
|
|
146
|
+
return payload;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
static verifyToken(publicKey_1, token_1, expectAud_1, expectIss_1) {
|
|
150
|
+
return __awaiter(this, arguments, void 0, function* (publicKey, token, expectAud, expectIss, checkExpiry = true) {
|
|
151
|
+
try {
|
|
152
|
+
const payload2 = this.decodeToken(token);
|
|
153
|
+
if (expectAud && payload2.payload.aud != expectAud) {
|
|
154
|
+
throw 'verifyToken: mismatched aud!';
|
|
155
|
+
}
|
|
156
|
+
if (expectIss && payload2.payload.iss != expectIss) {
|
|
157
|
+
throw 'verifyToken: mismatched iss!';
|
|
158
|
+
}
|
|
159
|
+
const tokenParts = token.split('.');
|
|
160
|
+
const alg = { name: 'RSASSA-PKCS1-v1_5', hash: { name: 'SHA-256' } };
|
|
161
|
+
const key = yield crypto.subtle.importKey('jwk', publicKey, alg, false, ['verify']);
|
|
162
|
+
const isVerified = yield crypto.subtle.verify(alg, key, this.parseBase64Url(tokenParts[2]), this.utf8ToUint8Array(`${tokenParts[0]}.${tokenParts[1]}`));
|
|
163
|
+
if (checkExpiry && payload2.payload.exp <= Math.floor(Date.now() / 1000)) {
|
|
164
|
+
throw 'verifyToken: expired!';
|
|
165
|
+
}
|
|
166
|
+
if (isVerified == false) {
|
|
167
|
+
throw 'verifyToken: invalid token!';
|
|
168
|
+
}
|
|
169
|
+
return payload2.payload;
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
essentials_js_1.libx.log.e('Error verifying token:', error);
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
static decodeToken(idToken) {
|
|
178
|
+
const [header, payload, signature] = idToken.split('.').map(part => this.base64UrlDecode(part));
|
|
179
|
+
return {
|
|
180
|
+
rawHeader: header,
|
|
181
|
+
header: JSON.parse(header),
|
|
182
|
+
payload: JSON.parse(payload),
|
|
183
|
+
rawPayload: payload,
|
|
184
|
+
signature: signature,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
;
|
|
188
|
+
static parseBase64Url(url) {
|
|
189
|
+
return new Uint8Array(Array.prototype.map.call(atob(url.replace(/-/g, '+').replace(/_/g, '/').replace(/\s/g, '')), c => c.charCodeAt(0)));
|
|
190
|
+
}
|
|
191
|
+
static utf8ToUint8Array(str) {
|
|
192
|
+
return this.parseBase64Url(btoa(unescape(encodeURIComponent(str))));
|
|
193
|
+
}
|
|
194
|
+
static decodeToken_2(token) {
|
|
195
|
+
let raw = token.split('.')[1].replace(/-/g, '+').replace(/_/g, '/');
|
|
196
|
+
switch (raw.length % 4) {
|
|
197
|
+
case 0:
|
|
198
|
+
break;
|
|
199
|
+
case 2:
|
|
200
|
+
raw += '==';
|
|
201
|
+
break;
|
|
202
|
+
case 3:
|
|
203
|
+
raw += '=';
|
|
204
|
+
break;
|
|
205
|
+
default:
|
|
206
|
+
throw new Error('Illegal base64url string!');
|
|
207
|
+
}
|
|
208
|
+
try {
|
|
209
|
+
return JSON.parse(decodeURIComponent(escape(atob(raw))));
|
|
210
|
+
}
|
|
211
|
+
catch (_a) {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
exports.JwtHelper = JwtHelper;
|
|
217
|
+
JwtHelper.cachedFirebasePublicKeys = {};
|
|
218
|
+
JwtHelper.base64UrlDecode = (str) => {
|
|
219
|
+
return essentials_js_1.libx.Buffer.from(str, 'base64').toString('utf-8');
|
|
220
|
+
};
|
|
221
|
+
class Options {
|
|
222
|
+
constructor() {
|
|
223
|
+
this.aud = 'https://oauth2.googleapis.com/token';
|
|
224
|
+
this.exp = 3600;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=jwt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.js","sourceRoot":"","sources":["../../src/helpers/jwt.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,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GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACpE,QAAQ,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,KAAK,CAAC;gBACL,MAAK;YACN,KAAK,CAAC;gBACL,GAAG,IAAI,IAAI,CAAA;gBACX,MAAK;YACN,KAAK,CAAC;gBACL,GAAG,IAAI,GAAG,CAAA;gBACV,MAAK;YACN;gBACC,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;QAC9C,CAAC;QAED,IAAI,CAAC;YACJ,OAAO,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;QACzD,CAAC;QAAC,WAAM,CAAC;YACR,OAAO,IAAI,CAAA;QACZ,CAAC;IACF,CAAC;;AA6BO,8BAAS;AAzRF,kCAAwB,GAAQ,EAAE,CAAC;AAuBnC,yBAAe,GAAG,CAAC,GAAG,EAAE,EAAE;IACxC,OAAO,oBAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC1D,CAAC,CAAC;AAsOH,MAAM,OAAO;IAAb;QACC,QAAG,GAAG,qCAAqC,CAAC;QAC5C,QAAG,GAAG,IAAI,CAAC;IACZ,CAAC;CAAA","sourcesContent":["import { libx } from 'libx.js/build/bundles/essentials.js';\nimport { Base64 } from 'js-base64'\nimport { network } from './EdgeNetwork.js';\n\nclass JwtHelper {\n\tprivate static cachedFirebasePublicKeys = <any>{};\n\n\tprivate static base64urlEncode(str): string {\n\t\treturn str.toString('base64').replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '');\n\t}\n\n\tprivate static objectToBase64url(payload) {\n\t\treturn this.arrayBufferToBase64Url(new TextEncoder().encode(JSON.stringify(payload)));\n\t}\n\n\tprivate static arrayBufferToBase64Url(buffer) {\n\t\treturn btoa(String.fromCharCode(...new Uint8Array(buffer)))\n\t\t\t.replace(/=/g, '')\n\t\t\t.replace(/\\+/g, '-')\n\t\t\t.replace(/\\//g, '_');\n\t}\n\n\tprivate static hexToBuffer(hex: string) {\n\t\tconst matches = hex.match(/[\\da-f]{2}/gi) ?? []; // grab hex pairs\n\t\tconst { buffer } = new Uint8Array(matches.map((h) => parseInt(h, 16)));\n\t\treturn buffer;\n\t}\n\n\tprivate static base64UrlDecode = (str) => {\n\t\treturn libx.Buffer.from(str, 'base64').toString('utf-8');\n\t};\n\n\tprivate static async getGooglePublicKey(kid) {\n\t\tif (this.cachedFirebasePublicKeys[kid]) return this.cachedFirebasePublicKeys[kid];\n\t\tconst result: any = await (\n\t\t\tawait fetch(\n\t\t\t\t\"https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com\"\n\t\t\t\t// 'https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com'\n\t\t\t)\n\t\t).json();\n\n\t\tconst res = result.keys.find((key) => key.kid === kid);\n\t\tthis.cachedFirebasePublicKeys[kid] = res;\n\t\treturn res;\n\t}\n\n\tpublic static async generateSignedJWT(serviceAccount: any, scope: string, options?: Partial<Options>) {\n\t\toptions = { ...new Options(), ...options };\n\t\tconst pem = serviceAccount.private_key.replace(/\\n/g, '');\n\n\t\tconst pemHeader = '-----BEGIN PRIVATE KEY-----';\n\t\tconst pemFooter = '-----END PRIVATE KEY-----';\n\n\t\tif (!pem.startsWith(pemHeader) || !pem.endsWith(pemFooter)) {\n\t\t\tthrow new Error('Invalid service account private key');\n\t\t}\n\n\t\tconst pemContents = pem.substring(pemHeader.length, pem.length - pemFooter.length);\n\t\tconst buffer = Base64.toUint8Array(pemContents);\n\t\tconst algorithm = {\n\t\t\tname: 'RSASSA-PKCS1-v1_5',\n\t\t\thash: {\n\t\t\t\tname: 'SHA-256',\n\t\t\t},\n\t\t};\n\t\tconst extractable = false;\n\t\tconst privateKey = await crypto.subtle.importKey('pkcs8', buffer, algorithm, extractable, [\"sign\"]);\n\n\t\tconst header = Base64.encodeURI(\n\t\t\tJSON.stringify({\n\t\t\t\talg: 'RS256',\n\t\t\t\ttyp: 'JWT',\n\t\t\t\tkid: serviceAccount.private_key_id,\n\t\t\t})\n\t\t);\n\n\t\tconst iat = Math.floor(Date.now() / 1000);\n\t\tconst exp = iat + options.exp;\n\t\tconst payload = Base64.encodeURI(\n\t\t\tJSON.stringify({\n\t\t\t\tiss: serviceAccount.client_email,\n\t\t\t\tsub: serviceAccount.client_email,\n\t\t\t\tscope,\n\t\t\t\taud: options.aud,\n\t\t\t\texp,\n\t\t\t\tiat,\n\t\t\t})\n\t\t);\n\n\t\tconst textEncoder = new TextEncoder();\n\t\tconst inputArrayBuffer = textEncoder.encode(`${header}.${payload}`);\n\t\tconst outputArrayBuffer = await crypto.subtle.sign({ name: 'RSASSA-PKCS1-v1_5' }, privateKey, inputArrayBuffer);\n\t\tconst signature = Base64.fromUint8Array(new Uint8Array(outputArrayBuffer), true);\n\n\t\treturn {\n\t\t\theader,\n\t\t\tpayload,\n\t\t\tsignature\n\t\t};\n\t}\n\n\tpublic static async generateToken(serviceAccount: any, scope: string, options?: Partial<Options>) {\n\t\tconst signed = await this.generateSignedJWT(serviceAccount, scope, options);\n\t\tconst token = `${signed.header}.${signed.payload}.${signed.signature}`;\n\t\treturn token;\n\t}\n\n\tpublic static async generateOAuth(serviceAccount: any, scope: string, options?: Partial<Options>) {\n\t\tconst token = await this.generateToken(serviceAccount, scope, options);\n\t\treturn await this.jwtToOAuth(token);\n\t}\n\n\tprivate static async jwtToOAuth(signedJwt: string) {\n\t\t// Prepare the request to get an OAuth2 token\n\t\tconst tokenRequest = {\n\t\t\tgrant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',\n\t\t\tassertion: signedJwt\n\t\t};\n\n\t\ttry {\n\t\t\t/*\n\t\t\t // Make the request to Google's OAuth2 server\n\t\t\t const response = await axios.post('https://oauth2.googleapis.com/token', new URLSearchParams(tokenRequest).toString(), {\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/x-www-form-urlencoded'\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\t// Extract and return the access token\n\t\t\treturn response.data.access_token;\n\t\t\t*/\n\n\t\t\t// Make the request to Google's OAuth2 server\n\t\t\tconst response = await network.httpPostJson('https://oauth2.googleapis.com/token', tokenRequest);\n\t\t\t// const response = await fetch('https://www.googleapis.com/oauth2/v4/token', {\n\t\t\t// \tmethod: 'POST',\n\t\t\t// \theaders: new Headers({\n\t\t\t// \t\t'Content-Type': 'application/json',\n\t\t\t// \t}),\n\t\t\t// \tbody: JSON.stringify(tokenRequest),\n\t\t\t// });\n\n\t\t\t// Extract and return the access token\n\t\t\tconst tmp = response as any;\n\t\t\t// const tmp = await response.json<any>();\n\t\t\tif (tmp.error) throw tmp;\n\t\t\treturn tmp.access_token;\n\t\t} catch (error) {\n\t\t\tconsole.error('Error fetching OAuth2 token:', error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tpublic static async makeRequest(url: string, serviceAccountObj: Object, scope: string, payload: any, options = {\n\t\tmethod: \"POST\",\n\t\texHeaders: {}\n\t}) {\n\t\tconst token = await JwtHelper.generateOAuth(serviceAccountObj, scope);\n\n\t\tlibx.log.d('DBG: makeRequest: ', scope, token);\n\t\tconst bqResp = await fetch(url, {\n\t\t\tmethod: options.method,\n\t\t\tbody: payload ? JSON.stringify(payload) : null,\n\t\t\theaders: {\n\t\t\t\t\"content-type\": \"application/json;charset=UTF-8\",\n\t\t\t\t\"Authorization\": \"Bearer \" + token,\n\t\t\t\t...options.exHeaders\n\t\t\t}\n\t\t});\n\n\t\t// libx.log.i('DONE!', JSON.stringify(await this.gatherResponse(bqResp)))\n\t\treturn bqResp;\n\t}\n\n\tpublic static async verifyFirebaseToken(token, expectAud): Promise<IFirebaseTokenPayload> {\n\t\tconst dur = libx.Measurement.start();\n\t\tconst expectIss = `https://securetoken.google.com/${expectAud}`;\n\t\tconst tokenParts = token.split('.');\n\t\tconst header = JSON.parse(atob(tokenParts[0]));\n\t\tconst key = await this.getGooglePublicKey(header.kid);\n\t\tconst payload = await this.verifyToken(key, token, expectAud, expectIss) as IFirebaseTokenPayload;\n\n\t\tlibx.log.d(`verifyFirebaseToken: dur: ${dur.peek()}ms`);\n\t\treturn payload;\n\t}\n\n\tpublic static async verifyToken(publicKey, token, expectAud, expectIss, checkExpiry = true): Promise<IJwtTokenPayload> {\n\t\ttry {\n\t\t\t// const payload = this.decodeToken(token);\n\t\t\tconst payload2 = this.decodeToken(token);\n\n\t\t\tif (expectAud && payload2.payload.aud != expectAud) {\n\t\t\t\tthrow 'verifyToken: mismatched aud!';\n\t\t\t}\n\t\t\tif (expectIss && payload2.payload.iss != expectIss) {\n\t\t\t\tthrow 'verifyToken: mismatched iss!';\n\t\t\t}\n\n\t\t\tconst tokenParts = token.split('.');\n\t\t\tconst alg = { name: 'RSASSA-PKCS1-v1_5', hash: { name: 'SHA-256' } };\n\t\t\tconst key = await crypto.subtle.importKey('jwk', publicKey, alg, false, ['verify']);\n\t\t\tconst isVerified = await crypto.subtle.verify(alg, key, this.parseBase64Url(tokenParts[2]), this.utf8ToUint8Array(`${tokenParts[0]}.${tokenParts[1]}`));\n\n\t\t\tif (checkExpiry && payload2.payload.exp <= Math.floor(Date.now() / 1000)) {\n\t\t\t\tthrow 'verifyToken: expired!';\n\t\t\t}\n\n\t\t\tif (isVerified == false) {\n\t\t\t\tthrow 'verifyToken: invalid token!';\n\t\t\t}\n\n\t\t\treturn payload2.payload;\n\t\t} catch (error) {\n\t\t\tlibx.log.e('Error verifying token:', error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tpublic static decodeToken(idToken) {\n\t\tconst [header, payload, signature] = idToken.split('.').map(part => this.base64UrlDecode(part));\n\t\treturn {\n\t\t\trawHeader: header,\n\t\t\theader: JSON.parse(header),\n\t\t\tpayload: JSON.parse(payload),\n\t\t\trawPayload: payload,\n\t\t\tsignature: signature,\n\t\t};\n\t};\n\n\tprivate static parseBase64Url(url) {\n\t\treturn new Uint8Array(Array.prototype.map.call(atob(url.replace(/-/g, '+').replace(/_/g, '/').replace(/\\s/g, '')), c => c.charCodeAt(0)))\n\t}\n\n\tprivate static utf8ToUint8Array(str) {\n\t\treturn this.parseBase64Url(btoa(unescape(encodeURIComponent(str))))\n\t}\n\n\tprivate static decodeToken_2(token) {\n\t\tlet raw = token.split('.')[1].replace(/-/g, '+').replace(/_/g, '/');\n\t\tswitch (raw.length % 4) {\n\t\t\tcase 0:\n\t\t\t\tbreak\n\t\t\tcase 2:\n\t\t\t\traw += '=='\n\t\t\t\tbreak\n\t\t\tcase 3:\n\t\t\t\traw += '='\n\t\t\t\tbreak\n\t\t\tdefault:\n\t\t\t\tthrow new Error('Illegal base64url string!')\n\t\t}\n\n\t\ttry {\n\t\t\treturn JSON.parse(decodeURIComponent(escape(atob(raw))))\n\t\t} catch {\n\t\t\treturn null\n\t\t}\n\t}\n}\n\nclass Options {\n\taud = 'https://oauth2.googleapis.com/token';\n\texp = 3600;\n}\n\ninterface IJwtTokenPayload {\n\tname: string;\n\tpicture: string;\n\tiss: string;\n\taud: string;\n\tauth_time: number,\n\tuser_id: string;\n\tsub: string;\n\tiat: number,\n\texp: number,\n\temail: string;\n\temail_verified: true,\n}\n\nexport interface IFirebaseTokenPayload extends IJwtTokenPayload {\n\tfirebase: {\n\t\tidentities: any,\n\t\tsign_in_provider: string;\n\t}\n}\n\nexport { JwtHelper };"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'isomorphic-fetch';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
var _a;
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const server_1 = require("@whatwg-node/server");
|
|
8
|
+
require("isomorphic-fetch");
|
|
9
|
+
const getExpress_1 = require("./getExpress");
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const log_1 = require("libx.js/build/modules/log");
|
|
12
|
+
const node_essentials_1 = require("libx.js/build/bundles/node.essentials");
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
log_1.log.isDebug = true;
|
|
15
|
+
log_1.log.filterLevel = log_1.LogLevel.All;
|
|
16
|
+
const envFile = '.env';
|
|
17
|
+
const entryPoints = node_essentials_1.libx.node.args._;
|
|
18
|
+
const { app } = (0, getExpress_1.getExpress)();
|
|
19
|
+
function getEnvVars() {
|
|
20
|
+
var _a;
|
|
21
|
+
const envFilePath = path_1.default.join(process.cwd(), envFile);
|
|
22
|
+
if (!fs_1.default.existsSync(envFilePath))
|
|
23
|
+
return null;
|
|
24
|
+
const content = (_a = fs_1.default.readFileSync(envFilePath)) === null || _a === void 0 ? void 0 : _a.toString();
|
|
25
|
+
const ret = {};
|
|
26
|
+
for (let line of content.split('\n')) {
|
|
27
|
+
const parts = line.split('=');
|
|
28
|
+
if (parts[0].trim().startsWith('#') || parts[1] == null)
|
|
29
|
+
continue;
|
|
30
|
+
ret[parts[0].trim()] = parts[1].replace(/\s*[\"\'](.+)[\"\']\s*/gi, '$1');
|
|
31
|
+
}
|
|
32
|
+
return ret;
|
|
33
|
+
}
|
|
34
|
+
node_essentials_1.libx.node.catchErrors((err) => {
|
|
35
|
+
console.error('!!!!!! ERROR: ', err);
|
|
36
|
+
}, false);
|
|
37
|
+
if (['debug', 'debug:watch'].indexOf(process.env.npm_lifecycle_event) !== -1) {
|
|
38
|
+
const env = (_a = getEnvVars()) !== null && _a !== void 0 ? _a : { a: 1 };
|
|
39
|
+
for (let entryPoint of entryPoints) {
|
|
40
|
+
const dir = process.cwd();
|
|
41
|
+
const { handler, prefix } = require(`${dir}/${entryPoint}`);
|
|
42
|
+
app.use(prefix !== null && prefix !== void 0 ? prefix : '/api', (0, server_1.createServerAdapter)((request, env) => handler(request, env)));
|
|
43
|
+
}
|
|
44
|
+
const port = 8080;
|
|
45
|
+
try {
|
|
46
|
+
app.listen(port, () => {
|
|
47
|
+
console.log(`Server listening on http://0.0.0.0:${port}`);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
console.warn(`LOCAL: Failed to start local server on port: ${port}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=localServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localServer.js","sourceRoot":"","sources":["../../src/helpers/localServer.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA0D;AAC1D,4BAA0B;AAG1B,6CAA0C;AAE1C,4CAAoB;AACpB,mDAA0D;AAC1D,2EAA6D;AAC7D,gDAAwB;AAExB,SAAG,CAAC,OAAO,GAAG,IAAI,CAAC;AACnB,SAAG,CAAC,WAAW,GAAG,cAAQ,CAAC,GAAG,CAAC;AAE/B,MAAM,OAAO,GAAG,MAAM,CAAC;AAEvB,MAAM,WAAW,GAAG,sBAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAErC,MAAM,EAAE,GAAG,EAAE,GAAG,IAAA,uBAAU,GAAE,CAAC;AAM7B,SAAS,UAAU;;IAClB,MAAM,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,CAAC;IACtD,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,WAAW,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7C,MAAM,OAAO,GAAG,MAAA,YAAE,CAAC,YAAY,CAAC,WAAW,CAAC,0CAAE,QAAQ,EAAE,CAAC;IACzD,MAAM,GAAG,GAAG,EAAE,CAAC;IACf,KAAK,IAAI,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACtC,MAAM,KAAK,GAAG,IAAI,CAAC,KAA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AAC,IAAI,EAAE,GAAG,EAAE;YACrB,OAAO,CAAC,GAAG,CAAC,sCAAsC,IAAI,EAAE,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,OAAO,CAAC,IAAI,CAAC,gDAAgD,IAAI,EAAE,CAAC,CAAC;IACtE,CAAC;AACF,CAAC","sourcesContent":["import { createServerAdapter } from '@whatwg-node/server';\nimport 'isomorphic-fetch';\nimport { IRequest, Router, error, json } from 'itty-router';\nimport express from 'express';\nimport { getExpress } from './getExpress';\n// import { router, server } from '../v5';\nimport fs from 'fs';\nimport { log, LogLevel } from 'libx.js/build/modules/log';\nimport { libx } from 'libx.js/build/bundles/node.essentials';\nimport path from 'path';\n\nlog.isDebug = true;\nlog.filterLevel = LogLevel.All;\n\nconst envFile = '.env'; //'.dev.vars'\n\nconst entryPoints = libx.node.args._;\n\nconst { app } = getExpress();\n\n// node-wrangler bridge:\n// global.crypto = require('crypto');\n// global.TransformStream = require('web-streams-polyfill').TransformStream;\n\nfunction getEnvVars() {\n\tconst envFilePath = path.join(process.cwd(), envFile);\n\tif (!fs.existsSync(envFilePath)) return null;\n\tconst content = fs.readFileSync(envFilePath)?.toString();\n\tconst ret = {};\n\tfor (let line of content.split('\\n')) {\n\t\tconst parts = line.split('=');\n\t\tif (parts[0].trim().startsWith('#') || parts[1] == null) continue;\n\t\tret[parts[0].trim()] = parts[1].replace(/\\s*[\\\"\\'](.+)[\\\"\\']\\s*/gi, '$1');\n\t}\n\treturn ret;\n}\n\nlibx.node.catchErrors((err) => {\n\tconsole.error('!!!!!! ERROR: ', err);\n}, false);\n\n\n\n// only lunch manual local server if using 'dev' command\nif (['debug', 'debug:watch'].indexOf(process.env.npm_lifecycle_event) !== -1) {\n\tconst env = getEnvVars() ?? { a: 1 };\n\n\tfor (let entryPoint of entryPoints) {\n\t\tconst dir = process.cwd(); // process.argv[1]\n\t\tconst { handler, prefix } = require(`${dir}/${entryPoint}`);\n\t\tapp.use(\n\t\t\tprefix ?? '/api',\n\t\t\tcreateServerAdapter((request, env) =>\n\t\t\t\thandler(<IRequest>request, env))\n\t\t);\n\t}\n\n\t// app.use(\n\t// \t'/v5-n',\n\t// \tcreateServerAdapter((request, env) =>\n\t// \t\thandler_node(<IRequest>request, env))\n\t// \t\t// handlerRedirect(<IRequest>request, env))\n\t// );\n\n\tconst port = 8080;\n\ttry {\n\t\tapp.listen(port, () => {\n\t\t\tconsole.log(`Server listening on http://0.0.0.0:${port}`);\n\t\t});\n\t} catch (err) {\n\t\tconsole.warn(`LOCAL: Failed to start local server on port: ${port}`);\n\t}\n}\n\n// export default server; //routes.fetch;"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const require: any;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.require = void 0;
|
|
13
|
+
const reqSetup = (function () {
|
|
14
|
+
var mod = {};
|
|
15
|
+
(function (load) {
|
|
16
|
+
'use strict';
|
|
17
|
+
var RequireError = function (message, fileName, lineNumber) {
|
|
18
|
+
this.name = 'RequireError';
|
|
19
|
+
this.message = message;
|
|
20
|
+
};
|
|
21
|
+
RequireError.prototype = Object.create(Error.prototype);
|
|
22
|
+
if (typeof new Error().fileName == 'string') {
|
|
23
|
+
self.addEventListener('error', function (evt) {
|
|
24
|
+
if (evt.error instanceof Error) {
|
|
25
|
+
if (pwd[0]) {
|
|
26
|
+
evt.preventDefault();
|
|
27
|
+
throw new evt.error.constructor(evt.error.message, pwd[0].uri, evt.error.lineNumber);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
var m = evt.error.stack.match(/^[^\n@]*@([^\n]+):\d+:\d+/);
|
|
31
|
+
if (m === null) {
|
|
32
|
+
console.warn('libx.browser.require: unable to read file name from stack');
|
|
33
|
+
}
|
|
34
|
+
else if (evt.error.fileName != m[1]) {
|
|
35
|
+
evt.preventDefault();
|
|
36
|
+
throw new evt.error.constructor(evt.error.message, m[1], evt.error.lineNumber);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}, false);
|
|
41
|
+
}
|
|
42
|
+
var pwd = Array();
|
|
43
|
+
var parser = URL ? new URL(location.href) : document.createElement('A');
|
|
44
|
+
try {
|
|
45
|
+
var cache = new Object();
|
|
46
|
+
Object.defineProperty(cache, 'foo', { value: 'bar', configurable: true });
|
|
47
|
+
delete cache.foo;
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
console.warn('Falling back to DOM workaround for defineProperty: ' + e);
|
|
51
|
+
cache = document.createElement('DIV');
|
|
52
|
+
}
|
|
53
|
+
var lock = new Object();
|
|
54
|
+
var requirePath = mod && mod.requirePath !== undefined ? mod.requirePath.slice(0) : ['./'];
|
|
55
|
+
var requireCompiler = mod && mod.requireCompiler !== undefined ? mod.requireCompiler : null;
|
|
56
|
+
var base = [location.origin, location.href.substr(0, location.href.lastIndexOf('/') + 1)];
|
|
57
|
+
for (var i = 0; i < requirePath.length; i++) {
|
|
58
|
+
parser.href = (requirePath[i][0] == '.' ? base[1] : base[0]) + requirePath[i];
|
|
59
|
+
requirePath[i] = parser.href;
|
|
60
|
+
}
|
|
61
|
+
for (var id in mod && mod.requirePreloaded)
|
|
62
|
+
cache['$' + resolve(id).id] = mod.requirePreloaded[id].toString();
|
|
63
|
+
for (var id in mod && mod.requireOverrides)
|
|
64
|
+
cache['$' + resolve(id).id] = mod.requireOverrides[id];
|
|
65
|
+
mod = function (identifier, callback, compiler) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
return new Promise((resolvePromise, rejectPromise) => {
|
|
68
|
+
if (identifier instanceof Array) {
|
|
69
|
+
var modules = new Array();
|
|
70
|
+
var modcount = identifier.length;
|
|
71
|
+
for (var index = 0; index < identifier.length; index++) {
|
|
72
|
+
(function (id, i) {
|
|
73
|
+
modules.push(mod(id, callback &&
|
|
74
|
+
function (mod) {
|
|
75
|
+
modules[i] = mod;
|
|
76
|
+
--modcount == 0 && callback(modules);
|
|
77
|
+
}, compiler));
|
|
78
|
+
})(identifier[index], index);
|
|
79
|
+
}
|
|
80
|
+
return modules;
|
|
81
|
+
}
|
|
82
|
+
compiler = compiler !== undefined ? compiler : requireCompiler;
|
|
83
|
+
var descriptor = resolve(identifier);
|
|
84
|
+
var cacheid = '$' + descriptor.id;
|
|
85
|
+
if (cache[cacheid]) {
|
|
86
|
+
if (typeof cache[cacheid] === 'string')
|
|
87
|
+
load(descriptor, cache, pwd, cache[cacheid]);
|
|
88
|
+
callback &&
|
|
89
|
+
setTimeout(function () {
|
|
90
|
+
callback(cache[cacheid]);
|
|
91
|
+
}, 0);
|
|
92
|
+
return resolvePromise(cache[cacheid]);
|
|
93
|
+
}
|
|
94
|
+
var request = new XMLHttpRequest();
|
|
95
|
+
callback && (request[request.onload === null ? 'onload' : 'onreadystatechange'] = onLoad);
|
|
96
|
+
request.addEventListener('load', onLoad);
|
|
97
|
+
request.open('GET', descriptor.uri, true);
|
|
98
|
+
try {
|
|
99
|
+
}
|
|
100
|
+
catch (ex) {
|
|
101
|
+
console.warn('libx.require: Error setting CORS headers. ', ex);
|
|
102
|
+
}
|
|
103
|
+
lock[cacheid] = lock[cacheid]++ || 1;
|
|
104
|
+
request.send();
|
|
105
|
+
!callback && onLoad();
|
|
106
|
+
function onLoad() {
|
|
107
|
+
try {
|
|
108
|
+
if (request.readyState != 4)
|
|
109
|
+
return;
|
|
110
|
+
if (request.status != 200)
|
|
111
|
+
new RequireError('unable to load ' + descriptor.id + ' (' + request.status + ' ' + request.statusText + ')');
|
|
112
|
+
if (request.status == 200)
|
|
113
|
+
lock[cacheid]--;
|
|
114
|
+
if (lock[cacheid]) {
|
|
115
|
+
console.warn('module locked: ' + descriptor.id);
|
|
116
|
+
if (lock[cacheid] <= 5)
|
|
117
|
+
return;
|
|
118
|
+
callback && setTimeout(onLoad, 0);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (!cache[cacheid]) {
|
|
122
|
+
var source = compiler ? compiler(request.responseText) : request.responseText;
|
|
123
|
+
load(descriptor, cache, pwd, source, typeof callback == 'boolean');
|
|
124
|
+
}
|
|
125
|
+
!callback && onLoad();
|
|
126
|
+
callback && callback(cache[cacheid]);
|
|
127
|
+
resolvePromise(cache[cacheid]);
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
rejectPromise(err);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
function fixSlash(url) {
|
|
137
|
+
var isDoubleSlash = url.startsWith('//');
|
|
138
|
+
var ret = url.replace(/[\/]+/g, '/').replace(':/', '://');
|
|
139
|
+
if (isDoubleSlash)
|
|
140
|
+
ret = ret.replace(/^\//, '//');
|
|
141
|
+
return ret;
|
|
142
|
+
}
|
|
143
|
+
function resolve(identifier) {
|
|
144
|
+
if (identifier.indexOf('http://') == 0 ||
|
|
145
|
+
identifier.indexOf('https://') == 0 ||
|
|
146
|
+
identifier.indexOf('//') == 0 ||
|
|
147
|
+
identifier.indexOf('://') != -1)
|
|
148
|
+
return { id: identifier, uri: fixSlash(identifier) };
|
|
149
|
+
if (identifier.indexOf('/') == 0) {
|
|
150
|
+
var root = requirePath[0].substr(0, requirePath[0].indexOf('/', requirePath[0].indexOf('://') + 3));
|
|
151
|
+
return { id: identifier, uri: fixSlash(root + '/' + identifier) };
|
|
152
|
+
}
|
|
153
|
+
return { id: identifier, uri: fixSlash(identifier) };
|
|
154
|
+
var m = identifier.match(/^(?:([^:\/]+):)?(\.\.?)?\/?((?:.*\/)?)([^\.]+)?(\..*)?$/);
|
|
155
|
+
var p = (pwd[0] ? pwd[0].id : '').match(/^(?:([^:\/]+):)?(.*\/|)[^\/]*$/);
|
|
156
|
+
var root = m[2] ? requirePath[p[1] ? parseInt(p[1]) : 0] : requirePath[m[1] ? parseInt(m[1]) : 0];
|
|
157
|
+
parser.href = (m[2] ? root + p[2] + m[2] + '/' : root) + m[3] + (m[4] ? m[4] : 'index');
|
|
158
|
+
var uri = parser.href + (m[5] ? m[5] : '.js');
|
|
159
|
+
if (uri.substr(0, root.length) != root)
|
|
160
|
+
throw new RequireError('Relative identifier outside of module root');
|
|
161
|
+
var id = (m[1] ? m[1] + ':' : '0:') + parser.href.substr(root.length);
|
|
162
|
+
return { id: id, uri: fixSlash(uri) };
|
|
163
|
+
}
|
|
164
|
+
if (mod !== undefined) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
Object.defineProperty('require', { value: mod });
|
|
169
|
+
Object.defineProperty(mod, 'resolve', { value: resolve });
|
|
170
|
+
Object.defineProperty(mod, 'path', {
|
|
171
|
+
get: function () {
|
|
172
|
+
return requirePath.slice(0);
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
mod.resolve = resolve;
|
|
178
|
+
mod.path = requirePath.slice(0);
|
|
179
|
+
}
|
|
180
|
+
})(function (module) {
|
|
181
|
+
var global = self;
|
|
182
|
+
var exports = new Object();
|
|
183
|
+
Object.defineProperty(module, 'exports', {
|
|
184
|
+
get: function () {
|
|
185
|
+
return exports;
|
|
186
|
+
},
|
|
187
|
+
set: function (e) {
|
|
188
|
+
exports = e;
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
arguments[2].unshift(module);
|
|
192
|
+
Object.defineProperty(arguments[1], '$' + module.id, {
|
|
193
|
+
get: function () {
|
|
194
|
+
return exports;
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
var content = arguments[3];
|
|
198
|
+
var isNotModule = arguments[4];
|
|
199
|
+
if (isNotModule === true) {
|
|
200
|
+
eval(content);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
var extra = 'var __moduleUri = "' + module.uri + '";\n';
|
|
204
|
+
if (!module.uri.endsWith('.js')) {
|
|
205
|
+
content = 'module.exports = ' + content;
|
|
206
|
+
}
|
|
207
|
+
var script = 'function(){\n' + extra + content + '\n}';
|
|
208
|
+
let wrapper = '(' + script + ')();\n//# sourceURL=' + module.uri;
|
|
209
|
+
eval(wrapper);
|
|
210
|
+
}
|
|
211
|
+
if (typeof module.id !== 'string')
|
|
212
|
+
for (id in module)
|
|
213
|
+
arguments[1]['$' + mod.resolve(id).id] = module[id].toString();
|
|
214
|
+
arguments[2].shift();
|
|
215
|
+
});
|
|
216
|
+
return mod;
|
|
217
|
+
})();
|
|
218
|
+
exports.require = reqSetup();
|
|
219
|
+
//# sourceMappingURL=require.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"require.js","sourceRoot":"","sources":["../../src/helpers/require.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,MAAM,QAAQ,GAAG,CAAC;IAGd,IAAI,GAAG,GAAG,EAAE,CAAC;IAEb,CAAC,UAAU,IAAI;QACX,YAAY,CAAC;QACb,IAAI,YAAY,GAAG,UAAU,OAAO,EAAE,QAAQ,EAAE,UAAU;YACtD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;YAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAC3B,CAAC,CAAC;QACF,YAAY,CAAC,SAAS,GAAG,MA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AAC,QAAQ,EAAE,CAAC;QACrH,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC,CACJ,CAAC;IAEF,OAAO,GAAG,CAAC;AACf,CAAC,CAAC,EAAE,CAAC;AAGQ,QAAA,OAAO,GAAG,QAAQ,EAAE,CAAC","sourcesContent":["// @ts-nocheck\n\nconst reqSetup = (function () {\n // var require = libx.browser.require;\n\t\n var mod = {};\n\n (function (load) {\n 'use strict';\n var RequireError = function (message, fileName, lineNumber) {\n this.name = 'RequireError';\n this.message = message;\n };\n RequireError.prototype = Object.create(Error.prototype);\n\n // NOTE Mozilla still sets the wrong fileName porperty for errors that occur\n // inside an eval call (even with sourceURL). However, the stack\n // contains the correct source, so it can be used to re-threw the error\n // with the correct fileName property.\n // NOTE Re-threwing a new error object will mess up the stack trace and the\n // column number.\n if (typeof new Error().fileName == 'string') {\n self.addEventListener(\n 'error',\n function (evt) {\n if (evt.error instanceof Error) {\n if (pwd[0]) {\n evt.preventDefault();\n throw new evt.error.constructor(evt.error.message, pwd[0].uri, evt.error.lineNumber);\n } else {\n var m = evt.error.stack.match(/^[^\\n@]*@([^\\n]+):\\d+:\\d+/);\n if (m === null) {\n console.warn('libx.browser.require: unable to read file name from stack');\n } else if (evt.error.fileName != m[1]) {\n evt.preventDefault();\n throw new evt.error.constructor(evt.error.message, m[1], evt.error.lineNumber);\n }\n }\n }\n },\n false\n );\n }\n\n // INFO Current module descriptors\n // pwd[0] contains the descriptor of the currently loaded module,\n // pwd[1] contains the descriptor its parent module and so on.\n\n var pwd = Array();\n\n // INFO Path parser\n // NOTE Older browsers don't support the URL interface, therefore we use an\n // anchor element as parser in that case. Thes breaks web worker support,\n // but we don't care since these browser also don't support web workers.\n\n var parser = URL ? new URL(location.href) : document.createElement('A');\n\n // INFO Module cache\n // NOTE Contains getter functions for the exports objects of all the loaded\n // modules. The getter for the module 'mymod' is name '$name' to prevent\n // collisions with predefined object properties (see note below).\n // As long as a module has not been loaded the getter is either undefined\n // or contains the module code as a function (in case the module has been\n // pre-loaded in a bundle).\n // NOTE IE8 supports defineProperty only for DOM objects, therfore we use a\n // HTMLDivElement as cache in that case. This breaks web worker support,\n // but we don't care since IE8 has no web workers at all.\n\n try {\n var cache = new Object();\n Object.defineProperty(cache, 'foo', { value: 'bar', configurable: true });\n delete cache.foo;\n } catch (e) {\n console.warn('Falling back to DOM workaround for defineProperty: ' + e);\n cache = document.createElement('DIV');\n }\n\n // INFO Send lock\n // NOTE Sending the request causes the event loop to continue. Therefore\n // pending AJAX load events for the same url might be executed before\n // the synchronous onLoad is called. This should be no problem, but in\n // Chrome the responseText of the sneaked in load events will be empty.\n // Therefore we have to lock the loading while executing send().\n\n var lock = new Object();\n\n var requirePath = mod && mod.requirePath !== undefined ? mod.requirePath.slice(0) : ['./'];\n var requireCompiler = mod && mod.requireCompiler !== undefined ? mod.requireCompiler : null;\n\n // NOTE Parse module root paths\n var base = [location.origin, location.href.substr(0, location.href.lastIndexOf('/') + 1)];\n for (var i = 0; i < requirePath.length; i++) {\n parser.href = (requirePath[i][0] == '.' ? base[1] : base[0]) + requirePath[i];\n requirePath[i] = parser.href;\n }\n\n // NOTE Add preloaded modules to cache\n for (var id in mod && mod.requirePreloaded) cache['$' + resolve(id).id] = mod.requirePreloaded[id].toString();\n\n // NOTE Add module overrides to cache\n for (var id in mod && mod.requireOverrides) cache['$' + resolve(id).id] = mod.requireOverrides[id];\n\n // INFO Module getter\n // Takes a module identifier, resolves it and gets the module code via an\n // AJAX request from the module URI. If this was successful the code and\n // some environment variables are passed to the load function. The return\n // value is the module's `exports` object. If the cache already\n // contains an object for the module id, this object is returned directly.\n // NOTE If a callback function has been passed, the AJAX request is asynchronous\n // and the module exports are passed to the callback function after the\n // module has been loaded.\n\n mod = async function (identifier, callback, compiler) {\n return new Promise((resolvePromise, rejectPromise) => {\n if (identifier instanceof Array) {\n var modules = new Array();\n var modcount = identifier.length;\n for (var index = 0; index < identifier.length; index++) {\n (function (id, i) {\n modules.push(\n mod(\n id,\n callback &&\n function (mod) {\n modules[i] = mod;\n --modcount == 0 && callback(modules);\n },\n compiler\n )\n );\n })(identifier[index], index);\n }\n return modules;\n }\n\n compiler = compiler !== undefined ? compiler : requireCompiler;\n var descriptor = resolve(identifier);\n var cacheid = '$' + descriptor.id;\n\n if (cache[cacheid]) {\n if (typeof cache[cacheid] === 'string') load(descriptor, cache, pwd, cache[cacheid]);\n // NOTE The callback should always be called asynchronously to ensure\n // that a cached call won't differ from an uncached one.\n callback &&\n setTimeout(function () {\n callback(cache[cacheid]);\n }, 0);\n return resolvePromise(cache[cacheid]);\n }\n\n var request = new XMLHttpRequest();\n\n // NOTE IE8 doesn't support the onload event, therefore we use\n // onreadystatechange as a fallback here. However, onreadystatechange\n // shouldn't be used for all browsers, since at least mobile Safari\n // seems to have an issue where onreadystatechange is called twice for\n // readyState 4.\n callback && (request[request.onload === null ? 'onload' : 'onreadystatechange'] = onLoad);\n request.addEventListener('load', onLoad);\n request.open('GET', descriptor.uri, true); //!!callback);\n\n try {\n // request.setRequestHeader('Origin', window.location.hostname);\n // request.setRequestHeader('Access-Control-Allow-Origin', '*');\n // request.setRequestHeader('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, DELETE, OPTIONS');\n // request.setRequestHeader('Access-Control-Allow-Headers', 'Origin, Content-Type, X-Auth-Token');\n } catch (ex) {\n console.warn('libx.require: Error setting CORS headers. ', ex);\n }\n\n lock[cacheid] = lock[cacheid]++ || 1;\n request.send();\n !callback && onLoad();\n\n function onLoad() {\n try {\n if (request.readyState != 4) return;\n if (request.status != 200)\n new RequireError('unable to load ' + descriptor.id + ' (' + request.status + ' ' + request.statusText + ')');\n if (request.status == 200) lock[cacheid]--;\n if (lock[cacheid]) {\n console.warn('module locked: ' + descriptor.id);\n if (lock[cacheid] <= 5) return;\n callback && setTimeout(onLoad, 0);\n return;\n }\n if (!cache[cacheid]) {\n var source = compiler ? compiler(request.responseText) : request.responseText;\n load(descriptor, cache, pwd, source, typeof callback == 'boolean');\n }\n\n !callback && onLoad();\n\n callback && callback(cache[cacheid]);\n resolvePromise(cache[cacheid]);\n } catch (err) {\n rejectPromise(err);\n }\n }\n });\n };\n\n // INFO Module resolver\n // Takes a module identifier and resolves it to a module id and URI. Both\n // values are returned as a module descriptor, which can be passed to\n // `fetch` to load a module.\n\n function fixSlash(url) {\n var isDoubleSlash = url.startsWith('//');\n var ret = url.replace(/[\\/]+/g, '/').replace(':/', '://'); //.replace(/\\/\\//g, '/').replace(':/', '://');\n if (isDoubleSlash) ret = ret.replace(/^\\//, '//');\n return ret;\n }\n\n function resolve(identifier) {\n if (\n identifier.indexOf('http://') == 0 ||\n identifier.indexOf('https://') == 0 ||\n identifier.indexOf('//') == 0 ||\n identifier.indexOf('://') != -1\n )\n return { id: identifier, uri: fixSlash(identifier) };\n\n if (identifier.indexOf('/') == 0) {\n var root = requirePath[0].substr(0, requirePath[0].indexOf('/', requirePath[0].indexOf('://') + 3));\n return { id: identifier, uri: fixSlash(root + '/' + identifier) };\n }\n\n return { id: identifier, uri: fixSlash(identifier) };\n\n // NOTE Matches [1]:[..]/[path/to/][file][.js]\n var m = identifier.match(/^(?:([^:\\/]+):)?(\\.\\.?)?\\/?((?:.*\\/)?)([^\\.]+)?(\\..*)?$/);\n // NOTE Matches [1]:[/path/to/]file.js\n var p = (pwd[0] ? pwd[0].id : '').match(/^(?:([^:\\/]+):)?(.*\\/|)[^\\/]*$/);\n var root = m[2] ? requirePath[p[1] ? parseInt(p[1]) : 0] : requirePath[m[1] ? parseInt(m[1]) : 0];\n parser.href = (m[2] ? root + p[2] + m[2] + '/' : root) + m[3] + (m[4] ? m[4] : 'index');\n var uri = parser.href + (m[5] ? m[5] : '.js');\n if (uri.substr(0, root.length) != root) throw new RequireError('Relative identifier outside of module root');\n var id = (m[1] ? m[1] + ':' : '0:') + parser.href.substr(root.length);\n\n return { id: id, uri: fixSlash(uri) };\n }\n\n // INFO Exporting require to global scope\n\n if (mod !== undefined) {\n //throw new RequireError('\\'require\\' already defined in global scope');\n //console.warn(\"'\\'require\\' already defined in global scope'\");\n return;\n }\n\n try {\n Object.defineProperty('require', { value: mod });\n Object.defineProperty(mod, 'resolve', { value: resolve });\n Object.defineProperty(mod, 'path', {\n get: function () {\n return requirePath.slice(0);\n },\n });\n } catch (e) {\n // NOTE IE8 can't use defineProperty on non-DOM objects, so we have to fall\n // back to unsave property assignments in this case.\n mod.resolve = resolve;\n mod.path = requirePath.slice(0);\n }\n })(\n // INFO Module loader\n // Takes the module descriptor, the global variables and the module code,\n // sets up the module envirinment, defines the module getter in the cache\n // and evaluates the module code. If module is a bundle the code of the\n // pre-loaded modules will be stored in the cache afterwards.\n // NOTE This functions is defined as an anonymous function, which is passed as\n // a parameter to the closure above to provide a clean environment (only\n // global variables, module and exports) for the loaded module. This is\n // also the reason why `source`, `pwd` & `cache` are not named parameters.\n // NOTE If we would strict use mode here, the evaluated code would be forced to be\n // in strict mode, too.\n\n function (/*load*/ module /*, cache, pwd, source, isNotModule*/) {\n var global = self;\n var exports = new Object();\n Object.defineProperty(module, 'exports', {\n get: function () {\n return exports;\n },\n set: function (e) {\n exports = e;\n },\n });\n arguments[2].unshift(module);\n Object.defineProperty(arguments[1], '$' + module.id, {\n get: function () {\n return exports;\n },\n });\n\n var content = arguments[3];\n var isNotModule = arguments[4];\n\n if (isNotModule === true) {\n eval(content);\n } else {\n var extra = 'var __moduleUri = \"' + module.uri + '\";\\n';\n if (!module.uri.endsWith('.js')) {\n content = 'module.exports = ' + content;\n }\n var script = 'function(){\\n' + extra + content + '\\n}';\n let wrapper = '(' + script + ')();\\n//# sourceURL=' + module.uri;\n\n eval(wrapper);\n }\n\n // var script = '(function(__moduleUri){\\n ('+arguments[3]+')}(); \\n'\n // arguments[3] = '(' + extra + script+')(\"' + module.uri + '\");\\nsourceURL=\"'+module.uri+'\"';\n\n // load(descriptor, cache, pwd, 'function(){\\n'+source+'\\n}');\n // arguments[3] = '('+arguments[3]+')();\\n//# sourceURL='+module.uri;\n\n // if (typeof Function != \"undefined\") new Function(arguments[3]);\n // else\n // NOTE Store module code in the cache if the loaded file is a bundle\n if (typeof module.id !== 'string') for (id in module) arguments[1]['$' + mod.resolve(id).id] = module[id].toString();\n arguments[2].shift();\n }\n );\n\n return mod;\n})();\n\n\nexport const require = reqSetup();"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModuleOptions = exports.Module = void 0;
|
|
4
|
+
const essentials_js_1 = require("libx.js/build/bundles/essentials.js");
|
|
5
|
+
class Module {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
this.options = Object.assign(Object.assign({}, new ModuleOptions()), options);
|
|
9
|
+
essentials_js_1.libx.log.v('Module:ctor');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.Module = Module;
|
|
13
|
+
class ModuleOptions {
|
|
14
|
+
}
|
|
15
|
+
exports.ModuleOptions = ModuleOptions;
|
|
16
|
+
//# sourceMappingURL=@module.js.map
|