itube-specs 0.0.399 → 0.0.401

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "itube-specs",
3
3
  "type": "module",
4
- "version": "0.0.399",
4
+ "version": "0.0.401",
5
5
  "main": "./nuxt.config.ts",
6
6
  "types": "./types/index.d.ts",
7
7
  "scripts": {
package/runtime/index.ts CHANGED
@@ -52,3 +52,5 @@ export * from './utils/converters/convert-string';
52
52
  export * from './utils/normalize-url';
53
53
  export * from './utils/is-mobile';
54
54
  export * from './utils/vtt-helper';
55
+ export * from './utils/server/age';
56
+ export * from './utils/server/geo';
@@ -0,0 +1,75 @@
1
+ import { getCookie } from 'h3';
2
+ import { getGeoHeaders } from './geo';
3
+
4
+ export async function isGeoMatch(event, config) {
5
+ const data = await getGeoHeaders(event, config);
6
+
7
+ const AGE_VERIFY_REGIONS = ['KS'];
8
+ const AGE_VERIFY_COUNTRIES = ['GB'];
9
+
10
+ const countryCode = data?.data[ 'X-Country-Code' ]?.[ 0 ];
11
+ const stateCode = data?.data[ 'X-Region-Code' ]?.[ 0 ];
12
+
13
+ // return AGE_VERIFY_COUNTRIES.includes(countryCode)
14
+ // || AGE_VERIFY_REGIONS.includes(stateCode);
15
+ return true;
16
+ }
17
+
18
+ export async function isAgeVerified(event, config) {
19
+ const apiUrl = config.public.apiDomain;
20
+ const sessionId = getCookie(event, 'session_id') || event?.context.sessionId;
21
+
22
+ const res: any = await $fetch(`${apiUrl}/v1/user/is-age-verified`, {
23
+ method: 'GET',
24
+ params: {
25
+ session_id: sessionId,
26
+ },
27
+ headers: {
28
+ 'x-domain': config.public.xDomain,
29
+ 'X-Cache-Time': 259200,
30
+ 'Content-Type': 'application/json',
31
+ },
32
+ parseResponse: JSON.parse
33
+ });
34
+
35
+ return res.data === true;
36
+ }
37
+
38
+ export async function getAgeValidationUrl(event, backPath: string, config) {
39
+ const sessionId = event.context?.sessionId || getCookie(event, 'session_id');
40
+ const apiUrl = config.public.apiDomain;
41
+
42
+ const data = await getGeoHeaders(event);
43
+
44
+ const countryCode = data?.data[ 'X-Country-Code' ]?.[ 0 ];
45
+ const stateCode = data?.data[ 'X-Region-Code' ]?.[ 0 ];
46
+ const remoteIP = data?.data[ 'X-Real-Ip' ]?.[ 0 ];
47
+ const userAgent = data?.data[ 'User-Agent' ]?.[ 0 ];
48
+
49
+ const siteUrl = `https://${config.public.xDomain}`;
50
+ const callbackURL = `${siteUrl}/bff/age/verify`;
51
+
52
+ const resRaw: any = await $fetch(`${apiUrl}/v1/user/age-validation-url`, {
53
+ method: 'POST',
54
+ body: {
55
+ backURL: `${siteUrl}${backPath}`,
56
+ callbackURL,
57
+ countryCode,
58
+ stateCode,
59
+ remoteIP,
60
+ sessionId,
61
+ userAgent,
62
+ },
63
+ headers: {
64
+ 'x-domain': config.public.xDomain,
65
+ 'X-Cache-Time': 259200,
66
+ 'Content-Type': 'application/json',
67
+ },
68
+ });
69
+
70
+ const res: any = typeof resRaw === 'string' ? JSON.parse(resRaw) : resRaw;
71
+
72
+ const url = typeof res?.data === 'string' ? res.data : '';
73
+
74
+ return { url, countryCode };
75
+ }
@@ -0,0 +1,20 @@
1
+ import { useRuntimeConfig } from '#imports';
2
+
3
+ export async function getGeoHeaders(event, config) {
4
+ if (event.context.geoHeaders) {
5
+ return event.context.geoHeaders;
6
+ }
7
+ const apiUrl = config.public.apiDomain;
8
+
9
+ const data = await $fetch(`${apiUrl}/v1/tools/headers`, {
10
+ method: 'GET',
11
+ headers: {
12
+ 'Content-Type': 'application/json',
13
+ 'x-domain': process.env.NUXT_PUBLIC_X_DOMAIN,
14
+ },
15
+ parseResponse: JSON.parse,
16
+ });
17
+
18
+ event.context.geoHeaders = data;
19
+ return data;
20
+ }