@aptly-as/sdk-app-web 0.1.0 → 0.2.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/README.md +11 -11
- package/dist/AptlyWeb.d.ts +1 -1
- package/dist/AptlyWeb.js +35 -6
- package/dist/lib/AptlyWeb.d.ts +16 -0
- package/dist/lib/AptlyWeb.js +76 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +1 -0
- package/package.json +12 -13
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
# Aptly app web
|
|
2
|
-
|
|
3
|
-
Helper classes for building aptly webs apps.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
## Installation
|
|
7
|
-
Need types for typescript types and enums
|
|
8
|
-
```
|
|
9
|
-
yarn add @aptly-as/app-sdk @aptly-as/types
|
|
10
|
-
|
|
11
|
-
npm install @aptly-as/app-sdk @aptly-as/types
|
|
1
|
+
# Aptly app web
|
|
2
|
+
|
|
3
|
+
Helper classes for building aptly webs apps.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
Need types for typescript types and enums
|
|
8
|
+
```
|
|
9
|
+
yarn add @aptly-as/app-sdk @aptly-as/types
|
|
10
|
+
|
|
11
|
+
npm install @aptly-as/app-sdk @aptly-as/types
|
|
12
12
|
```
|
package/dist/AptlyWeb.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare class AptlyWeb<S extends object> {
|
|
|
6
6
|
readonly media: Media;
|
|
7
7
|
constructor(_apiUrl: string, _config: AptlyAppWebContext<S>);
|
|
8
8
|
get theme(): any;
|
|
9
|
-
get organization(): Pick<import("@aptly-as/types").AptlyOrganization, "_id" | "
|
|
9
|
+
get organization(): Pick<import("@aptly-as/types").AptlyOrganization, "_id" | "name" | "slug">;
|
|
10
10
|
get project(): string | undefined;
|
|
11
11
|
get unit(): string | undefined;
|
|
12
12
|
get app(): import("@aptly-as/types").AptlyApp;
|
package/dist/AptlyWeb.js
CHANGED
|
@@ -33,15 +33,44 @@ export class AptlyWeb {
|
|
|
33
33
|
].join('/');
|
|
34
34
|
}
|
|
35
35
|
static initFromParentMessage(apiUrl, fn) {
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
fn(new AptlyWeb(apiUrl, parsed));
|
|
36
|
+
function receive(context) {
|
|
37
|
+
if (isWebContext(context)) {
|
|
38
|
+
fn(new AptlyWeb(apiUrl, context));
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
|
-
|
|
41
|
+
parentListeners.add(receive);
|
|
42
|
+
if (parentContext) {
|
|
43
|
+
receive(parentContext);
|
|
44
|
+
}
|
|
43
45
|
return () => {
|
|
44
|
-
|
|
46
|
+
parentListeners.delete(receive);
|
|
45
47
|
};
|
|
46
48
|
}
|
|
47
49
|
}
|
|
50
|
+
let parentContext = null;
|
|
51
|
+
const parentListeners = new Set();
|
|
52
|
+
function isWebContext(value) {
|
|
53
|
+
return typeof value === 'object' && value !== null && 'organization' in value && Boolean(value.organization);
|
|
54
|
+
}
|
|
55
|
+
function parseParentMessage(e) {
|
|
56
|
+
if (typeof e.data !== 'string')
|
|
57
|
+
return null;
|
|
58
|
+
try {
|
|
59
|
+
const parsed = JSON.parse(e.data);
|
|
60
|
+
return isWebContext(parsed) ? parsed : null;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (typeof window !== 'undefined') {
|
|
67
|
+
window.addEventListener('message', (e) => {
|
|
68
|
+
if (e.source !== window.parent)
|
|
69
|
+
return;
|
|
70
|
+
const context = parseParentMessage(e);
|
|
71
|
+
if (!context)
|
|
72
|
+
return;
|
|
73
|
+
parentContext = context;
|
|
74
|
+
parentListeners.forEach((listener) => listener(context));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Media } from '@aptly-as/sdk-web';
|
|
2
|
+
import { AptlyAppWebContext } from '@aptly-as/types';
|
|
3
|
+
export declare class AptlyWeb<S extends object> {
|
|
4
|
+
private _apiUrl;
|
|
5
|
+
private _config;
|
|
6
|
+
readonly media: Media;
|
|
7
|
+
constructor(_apiUrl: string, _config: AptlyAppWebContext<S>);
|
|
8
|
+
get theme(): any;
|
|
9
|
+
get organization(): Pick<import("@aptly-as/types").AptlyOrganization, "_id" | "name" | "slug">;
|
|
10
|
+
get project(): string | undefined;
|
|
11
|
+
get unit(): string | undefined;
|
|
12
|
+
get app(): import("@aptly-as/types").AptlyApp;
|
|
13
|
+
get config(): import("@aptly-as/types").AptlyOrganizationAppConfig<S>;
|
|
14
|
+
getProxyUrl(path: string): string;
|
|
15
|
+
static initFromParentMessage<S extends object>(apiUrl: string, fn: (state: AptlyWeb<S>) => void): () => void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Media } from '@aptly-as/sdk-web';
|
|
2
|
+
export class AptlyWeb {
|
|
3
|
+
constructor(_apiUrl, _config) {
|
|
4
|
+
this._apiUrl = _apiUrl;
|
|
5
|
+
this._config = _config;
|
|
6
|
+
this.media = new Media(_config.media.cloudinaryKey);
|
|
7
|
+
}
|
|
8
|
+
get theme() {
|
|
9
|
+
return this._config.theme;
|
|
10
|
+
}
|
|
11
|
+
get organization() {
|
|
12
|
+
return this._config.organization;
|
|
13
|
+
}
|
|
14
|
+
get project() {
|
|
15
|
+
return this._config.project;
|
|
16
|
+
}
|
|
17
|
+
get unit() {
|
|
18
|
+
return this._config.unit;
|
|
19
|
+
}
|
|
20
|
+
get app() {
|
|
21
|
+
return this._config.app;
|
|
22
|
+
}
|
|
23
|
+
get config() {
|
|
24
|
+
return this._config.config;
|
|
25
|
+
}
|
|
26
|
+
getProxyUrl(path) {
|
|
27
|
+
return [
|
|
28
|
+
`${this._apiUrl}/api/v1`,
|
|
29
|
+
`organizations/${this._config.organization.slug}`,
|
|
30
|
+
`apps/${this._config.app.slug}`,
|
|
31
|
+
'proxy',
|
|
32
|
+
path
|
|
33
|
+
].join('/');
|
|
34
|
+
}
|
|
35
|
+
static initFromParentMessage(apiUrl, fn) {
|
|
36
|
+
function receive(context) {
|
|
37
|
+
if (isWebContext(context)) {
|
|
38
|
+
fn(new AptlyWeb(apiUrl, context));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
parentListeners.add(receive);
|
|
42
|
+
if (parentContext) {
|
|
43
|
+
receive(parentContext);
|
|
44
|
+
}
|
|
45
|
+
return () => {
|
|
46
|
+
parentListeners.delete(receive);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
let parentContext = null;
|
|
51
|
+
const parentListeners = new Set();
|
|
52
|
+
function isWebContext(value) {
|
|
53
|
+
return typeof value === 'object' && value !== null && 'organization' in value && Boolean(value.organization);
|
|
54
|
+
}
|
|
55
|
+
function parseParentMessage(e) {
|
|
56
|
+
if (typeof e.data !== 'string')
|
|
57
|
+
return null;
|
|
58
|
+
try {
|
|
59
|
+
const parsed = JSON.parse(e.data);
|
|
60
|
+
return isWebContext(parsed) ? parsed : null;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (typeof window !== 'undefined') {
|
|
67
|
+
window.addEventListener('message', (e) => {
|
|
68
|
+
if (e.source !== window.parent)
|
|
69
|
+
return;
|
|
70
|
+
const context = parseParentMessage(e);
|
|
71
|
+
if (!context)
|
|
72
|
+
return;
|
|
73
|
+
parentContext = context;
|
|
74
|
+
parentListeners.forEach((listener) => listener(context));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AptlyWeb.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AptlyWeb.js';
|
package/package.json
CHANGED
|
@@ -1,39 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aptly-as/sdk-app-web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Aptly app SDK library for frontend development",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
7
8
|
"files": [
|
|
8
9
|
"dist"
|
|
9
10
|
],
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": "24.22.3"
|
|
13
|
+
},
|
|
10
14
|
"author": "Emil Andreas Olsen <emil@webbod.no>",
|
|
11
15
|
"license": "ISC",
|
|
12
16
|
"devDependencies": {
|
|
13
|
-
"@aptly-as/types": "^2.
|
|
14
|
-
"@vitest/ui": "^
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"typescript": "^5.7.2",
|
|
19
|
-
"vitest": "^2.1.8"
|
|
17
|
+
"@aptly-as/types": "^4.2.0",
|
|
18
|
+
"@vitest/ui": "^5.1.0",
|
|
19
|
+
"prettier": "^3.10.1",
|
|
20
|
+
"typescript": "7.0.2",
|
|
21
|
+
"vitest": "^5.1.0"
|
|
20
22
|
},
|
|
21
23
|
"dependencies": {
|
|
22
|
-
"@aptly-as/sdk-web": "^0.0
|
|
24
|
+
"@aptly-as/sdk-web": "^0.1.0"
|
|
23
25
|
},
|
|
24
26
|
"peerDependencies": {
|
|
25
27
|
"@aptly-as/types": "*"
|
|
26
28
|
},
|
|
27
|
-
"lint-staged": {
|
|
28
|
-
"**/*": "prettier --write --ignore-unknown"
|
|
29
|
-
},
|
|
30
29
|
"scripts": {
|
|
31
30
|
"start": "tsc --incremental --watch",
|
|
32
31
|
"build": "tsc",
|
|
33
32
|
"test": "vitest",
|
|
34
33
|
"test:ui": "vitest --ui --api 9527",
|
|
35
34
|
"test:run": "vitest run",
|
|
36
|
-
"prepublish": "
|
|
35
|
+
"prepublish": "pnpm run build",
|
|
37
36
|
"postversion": "git push && git push --tags"
|
|
38
37
|
}
|
|
39
38
|
}
|