@milaboratories/milaboratories.monetization-test.ui 1.0.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.
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta http-equiv="Content-Security-Policy" content="script-src 'self' blob:">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <script type="module" crossorigin src="./assets/index-drBI8LE5.js"></script>
8
+ <link rel="stylesheet" crossorigin href="./assets/index-CNZZQFPv.css">
9
+ </head>
10
+ <body>
11
+ <div id="app"></div>
12
+ </body>
13
+ </html>
package/index.html ADDED
@@ -0,0 +1,12 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta http-equiv="Content-Security-Policy" content="script-src 'self' blob:">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ </head>
8
+ <body>
9
+ <div id="app"></div>
10
+ <script type="module" src="/src/main.ts"></script>
11
+ </body>
12
+ </html>
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@milaboratories/milaboratories.monetization-test.ui",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "dependencies": {
6
+ "@platforma-sdk/ui-vue": "",
7
+ "vue": "^3.5.13",
8
+ "@milaboratories/milaboratories.monetization-test.model": "1.0.0",
9
+ "@platforma-sdk/model": "1.22.59"
10
+ },
11
+ "devDependencies": {
12
+ "@vitejs/plugin-vue": "^5.2.1",
13
+ "typescript": "~5.5.4",
14
+ "vite": "^5.4.11",
15
+ "vue-tsc": "^2.1.10"
16
+ },
17
+ "scripts": {
18
+ "dev": "vite",
19
+ "watch": "vue-tsc && vite build --watch",
20
+ "build": "vue-tsc -b && vite build",
21
+ "preview": "vite preview"
22
+ }
23
+ }
package/src/app.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { model } from "@milaboratories/milaboratories.monetization-test.model";
2
+ import { defineApp } from "@platforma-sdk/ui-vue";
3
+ import MainPage from "./pages/MainPage.vue";
4
+
5
+ export const sdkPlugin = defineApp(model, () => {
6
+ return {
7
+ routes: {
8
+ "/": () => MainPage,
9
+ },
10
+ };
11
+ });
12
+
13
+ export const useApp = sdkPlugin.useApp;
package/src/main.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { BlockLayout } from "@platforma-sdk/ui-vue";
2
+ import "@platforma-sdk/ui-vue/styles";
3
+ import { createApp } from "vue";
4
+ import { sdkPlugin } from "./app";
5
+
6
+ createApp(BlockLayout).use(sdkPlugin).mount("#app");
@@ -0,0 +1,142 @@
1
+ <script setup lang="ts">
2
+ import type { ImportFileHandle } from '@platforma-sdk/model';
3
+ import type { ImportedFiles, ListOption } from '@platforma-sdk/ui-vue';
4
+
5
+ import { PlAlert, PlBlockPage, PlContainer, PlRow, PlTextField, PlBtnPrimary, PlFileDialog, PlFileInput, PlDropdownMulti } from '@platforma-sdk/ui-vue';
6
+ import { useApp } from '../app';
7
+ import { computed, reactive, ref } from 'vue';
8
+
9
+ const app = useApp();
10
+
11
+ const dropdownOptions: ListOption<string>[] = [
12
+ {
13
+ text: 'sha256',
14
+ value: 'sha256'
15
+ },
16
+ {
17
+ text: 'lines (only in .zip files)',
18
+ value: 'lines',
19
+ },
20
+ {
21
+ text: 'size',
22
+ value: 'size'
23
+ }
24
+ ];
25
+
26
+ const files = reactive<{
27
+ isMultiDialogFileOpen: boolean;
28
+ }>({
29
+ isMultiDialogFileOpen: false,
30
+ })
31
+
32
+ const updateHandle = (v: ImportFileHandle | undefined, i: number) => {
33
+ if (v) {
34
+ app.model.args.inputHandles[i].handle = v;
35
+ } else {
36
+ app.model.args.inputHandles.splice(i, 1);
37
+ }
38
+ };
39
+
40
+ const onImport = (imported: ImportedFiles) => {
41
+ app.model.args.inputHandles = imported.files.map((h, i) => ({
42
+ handle: h,
43
+ fileName: `test${i}.txt`,
44
+ argName: `arg_${i}`,
45
+ options: ['size', 'sha256']
46
+ }));
47
+ };
48
+
49
+ const parsedToken = computed({
50
+ get: () => {
51
+ const splitted = app.model.outputs.token?.split('.') ?? [];
52
+ const data = splitted[1];
53
+ return JSON.parse(atob(data));
54
+ },
55
+ set: () => {}
56
+ })
57
+
58
+ const verificationResult = ref('');
59
+
60
+ const publicKey = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAECGShTw8Plag1uMuCg9OMYVHCF+wzjvXKr3cihyO77jEe9CrF6RP9tfnCd2XjM7XqQ0QH3i41rz5ohCB9fDDBbQ==';
61
+
62
+ async function verify(token: string) {
63
+ const cryptoPublicKey = await crypto.subtle.importKey(
64
+ 'spki',
65
+ Uint8Array.from(atob(publicKey), c => c.charCodeAt(0)).buffer,
66
+ { name: 'ECDSA', namedCurve: 'P-256' },
67
+ true,
68
+ ['verify']
69
+ );
70
+
71
+ const [base64Header, base64Payload, signature] = token.split('.');
72
+ if (!base64Header || typeof base64Payload !== 'string' || typeof signature !== 'string')
73
+ throw new Error('Invalid token body');
74
+
75
+ const signatureBinary = Uint8Array.from(
76
+ atob(signature.replace(/-/g, '+').replace(/_/g, '/')),
77
+ c => c.charCodeAt(0)
78
+ );
79
+
80
+ try {
81
+ const result = await crypto.subtle.verify(
82
+ { name: 'ECDSA', hash: { name: 'SHA-256' } },
83
+ cryptoPublicKey,
84
+ signatureBinary,
85
+ new TextEncoder().encode(`${base64Header}.${base64Payload}`)
86
+ );
87
+
88
+ if (result)
89
+ verificationResult.value = "Signature is correct";
90
+ else
91
+ verificationResult.value = "Signature is incorrect";
92
+ } catch (e: unknown) {
93
+ verificationResult.value = "Verification failed";
94
+ }
95
+ }
96
+
97
+
98
+ </script>
99
+
100
+ <template>
101
+ <PlBlockPage>
102
+
103
+ <PlTextField v-model="app.model.args.productKey"
104
+ label="Enter product key (keep MIFAKEMIFAKEMIFAKE for fake product)" clearable />
105
+
106
+ <PlContainer width="400px">
107
+ <PlBtnPrimary @click="files.isMultiDialogFileOpen = true">
108
+ Open multiple files to monetize
109
+ </PlBtnPrimary>
110
+ </PlContainer>
111
+ <template v-for="({ handle }, i) of app.model.args.inputHandles" :key="i">
112
+ <PlRow>
113
+ <PlTextField v-model="app.model.args.inputHandles[i].fileName" label="Type file name" />
114
+ <PlTextField v-model="app.model.args.inputHandles[i].argName" label="Type argument name" />
115
+ <PlFileInput :model-value="handle"
116
+ @update:model-value="(v: ImportFileHandle | undefined) => updateHandle(v, i)" />
117
+ <PlDropdownMulti label="Metrics to monetize" v-model="app.model.args.inputHandles[i].options"
118
+ :options="dropdownOptions" />
119
+ </PlRow>
120
+ </template>
121
+ <PlFileDialog v-model="files.isMultiDialogFileOpen" multi @import:files="onImport" />
122
+
123
+ <PlContainer />
124
+ <PlAlert label="pre-run info" v-if="app.model.outputs.info">
125
+ <pre> {{ JSON.stringify(app.model.outputs.info, undefined, 2) }} </pre>
126
+ </PlAlert>
127
+
128
+ <PlAlert label="token" v-if="app.model.outputs.token"> {{ app.model.outputs.token }}
129
+ </PlAlert>
130
+
131
+ <PlBtnPrimary v-if="app.model.outputs.token" @click="verify(app.model.outputs.token)">
132
+ Verify</PlBtnPrimary>
133
+
134
+ <PlAlert label="token verification" v-if="verificationResult"> {{ verificationResult }}
135
+ </PlAlert>
136
+
137
+ <PlAlert label="trying to parse a token" v-if="app.model.outputs.token">
138
+ <pre> {{ JSON.stringify(parsedToken, null, 2) }} </pre>
139
+ </PlAlert>
140
+
141
+ </PlBlockPage>
142
+ </template>
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
5
+ "target": "ES2020",
6
+ "useDefineForClassFields": true,
7
+ "module": "ESNext",
8
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
9
+ "skipLibCheck": true,
10
+
11
+ /* Bundler mode */
12
+ "moduleResolution": "bundler",
13
+ "allowImportingTsExtensions": true,
14
+ "resolveJsonModule": true,
15
+ "isolatedModules": true,
16
+ "moduleDetection": "force",
17
+ "noEmit": true,
18
+ "jsx": "preserve",
19
+
20
+ /* Linting */
21
+ "strict": true,
22
+ // "noUnusedLocals": true,
23
+ // "noUnusedParameters": true,
24
+ "noFallthroughCasesInSwitch": true
25
+ },
26
+ "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"]
27
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "files": [],
3
+ "references": [
4
+ {
5
+ "path": "./tsconfig.app.json"
6
+ },
7
+ {
8
+ "path": "./tsconfig.node.json"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
5
+ "skipLibCheck": true,
6
+ "module": "ESNext",
7
+ "moduleResolution": "bundler",
8
+ "allowSyntheticDefaultImports": true,
9
+ "strict": true,
10
+ "noEmit": true
11
+ },
12
+ "include": ["vite.config.ts"]
13
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from 'vite';
2
+ import vue from '@vitejs/plugin-vue';
3
+
4
+ // https://vitejs.dev/config/
5
+ export default defineConfig({
6
+ plugins: [vue()],
7
+ base: './',
8
+ build: {
9
+ sourcemap: true
10
+ }
11
+ });