@ogcio/analytics-sdk 0.0.1-beta.1 → 0.0.1-beta.3
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/base/base-client.d.ts +2 -7
- package/dist/base/base-client.d.ts.map +1 -1
- package/dist/base/base-client.js +3 -15
- package/dist/base/base-client.js.map +1 -0
- package/{types.d.ts → dist/browser-types.d.ts} +1 -1
- package/dist/index.d.ts +400 -597
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +332 -198
- package/dist/index.js.map +1 -0
- package/dist/matomo/helpers.d.ts +15 -0
- package/dist/matomo/helpers.d.ts.map +1 -1
- package/dist/matomo/helpers.js +80 -0
- package/dist/matomo/helpers.js.map +1 -0
- package/dist/matomo/types.d.ts +6 -2
- package/dist/matomo/types.d.ts.map +1 -1
- package/dist/matomo/types.js +1 -0
- package/dist/matomo/types.js.map +1 -0
- package/dist/schema.d.ts +223 -387
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +1 -0
- package/dist/schema.js.map +1 -0
- package/dist/support-files/auth/index.js +1 -0
- package/dist/support-files/auth/index.js.map +1 -0
- package/dist/support-files/auth/types.d.ts +1 -1
- package/dist/support-files/auth/types.d.ts.map +1 -1
- package/dist/support-files/auth/types.js +1 -0
- package/dist/support-files/auth/types.js.map +1 -0
- package/dist/support-files/building-blocks-sdk.d.ts +1 -1
- package/dist/support-files/building-blocks-sdk.d.ts.map +1 -1
- package/dist/support-files/building-blocks-sdk.js +1 -0
- package/dist/support-files/building-blocks-sdk.js.map +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +24 -16
- package/dist/ogcio-analytics-sdk-0.0.1.tgz +0 -0
- package/dist/package/dist/base/base-client.d.ts +0 -36
- package/dist/package/dist/base/base-client.d.ts.map +0 -1
- package/dist/package/dist/base/base-client.js +0 -96
- package/dist/package/dist/index.d.ts +0 -651
- package/dist/package/dist/index.d.ts.map +0 -1
- package/dist/package/dist/index.js +0 -321
- package/dist/package/dist/matomo/helpers.d.ts +0 -9
- package/dist/package/dist/matomo/helpers.d.ts.map +0 -1
- package/dist/package/dist/matomo/helpers.js +0 -10
- package/dist/package/dist/matomo/types.d.ts +0 -33
- package/dist/package/dist/matomo/types.d.ts.map +0 -1
- package/dist/package/dist/matomo/types.js +0 -1
- package/dist/package/dist/schema.d.ts +0 -1295
- package/dist/package/dist/schema.d.ts.map +0 -1
- package/dist/package/dist/schema.js +0 -5
- package/dist/package/dist/support-files/auth/index.d.ts +0 -3
- package/dist/package/dist/support-files/auth/index.d.ts.map +0 -1
- package/dist/package/dist/support-files/auth/index.js +0 -76
- package/dist/package/dist/support-files/auth/types.d.ts +0 -31
- package/dist/package/dist/support-files/auth/types.d.ts.map +0 -1
- package/dist/package/dist/support-files/auth/types.js +0 -1
- package/dist/package/dist/support-files/building-blocks-sdk.d.ts +0 -17
- package/dist/package/dist/support-files/building-blocks-sdk.d.ts.map +0 -1
- package/dist/package/dist/support-files/building-blocks-sdk.js +0 -11
- package/dist/package/dist/utils/index.d.ts +0 -7
- package/dist/package/dist/utils/index.d.ts.map +0 -1
- package/dist/package/dist/utils/index.js +0 -19
- package/dist/package/examples/environment.d.ts +0 -11
- package/dist/package/examples/index.ts +0 -201
- package/dist/package/examples/tsconfig.json +0 -15
- package/dist/package/package.json +0 -56
- package/dist/package/tsconfig.json +0 -18
- package/dist/package/types.d.ts +0 -19
- package/examples/environment.d.ts +0 -11
- package/examples/index.ts +0 -201
- package/examples/tsconfig.json +0 -15
- package/src/base/base-client.ts +0 -172
- package/src/index.test.ts +0 -92
- package/src/index.ts +0 -449
- package/src/matomo/helpers.ts +0 -14
- package/src/matomo/types.ts +0 -48
- package/src/schema.ts +0 -1295
- package/src/support-files/auth/index.ts +0 -116
- package/src/support-files/auth/types.ts +0 -38
- package/src/support-files/building-blocks-sdk.ts +0 -32
- package/src/utils/index.test.ts +0 -46
- package/src/utils/index.ts +0 -20
- package/tsconfig.json +0 -18
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { SERVICE_NAME } from "../../base/base-client.js";
|
|
2
|
-
import type {
|
|
3
|
-
GetAccessTokenParams,
|
|
4
|
-
GetOrganizationTokenParams,
|
|
5
|
-
M2MTokenFnConfig,
|
|
6
|
-
TokenFunction,
|
|
7
|
-
TokenResponseBody,
|
|
8
|
-
} from "./types.js";
|
|
9
|
-
|
|
10
|
-
const fetchToken = async (params: {
|
|
11
|
-
logtoOidcEndpoint: string;
|
|
12
|
-
applicationId: string;
|
|
13
|
-
applicationSecret: string;
|
|
14
|
-
scopes: string[];
|
|
15
|
-
specificBodyFields: { [x: string]: string };
|
|
16
|
-
}) => {
|
|
17
|
-
const body = {
|
|
18
|
-
...params.specificBodyFields,
|
|
19
|
-
scope: params.scopes.join(" "),
|
|
20
|
-
grant_type: "client_credentials",
|
|
21
|
-
};
|
|
22
|
-
const logtoOidcEndpoint = params.logtoOidcEndpoint.endsWith("/")
|
|
23
|
-
? params.logtoOidcEndpoint
|
|
24
|
-
: `${params.logtoOidcEndpoint}/`;
|
|
25
|
-
const Authorization = `Basic ${Buffer.from(
|
|
26
|
-
`${params.applicationId}:${params.applicationSecret}`,
|
|
27
|
-
).toString("base64")}`;
|
|
28
|
-
|
|
29
|
-
const response = await fetch(`${logtoOidcEndpoint}token`, {
|
|
30
|
-
method: "POST",
|
|
31
|
-
headers: {
|
|
32
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
33
|
-
Authorization,
|
|
34
|
-
},
|
|
35
|
-
body: new URLSearchParams(body).toString(),
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
if (response.status !== 200) {
|
|
39
|
-
throw new Error("Unauthorized");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return response.json() as Promise<TokenResponseBody>;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const getAccessToken = async (
|
|
46
|
-
params: GetAccessTokenParams,
|
|
47
|
-
scopes: string[],
|
|
48
|
-
) => {
|
|
49
|
-
const scopesToUse = params.scopes || scopes;
|
|
50
|
-
|
|
51
|
-
const tokenResponse = await fetchToken({
|
|
52
|
-
...params,
|
|
53
|
-
scopes: scopesToUse,
|
|
54
|
-
specificBodyFields: { resource: params.resource },
|
|
55
|
-
});
|
|
56
|
-
return tokenResponse.access_token;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const getOrganizationToken = async (
|
|
60
|
-
params: GetOrganizationTokenParams,
|
|
61
|
-
scopes: string[],
|
|
62
|
-
) => {
|
|
63
|
-
const logtoUserScopes = await importUserScopes();
|
|
64
|
-
|
|
65
|
-
const { UserScope } = logtoUserScopes;
|
|
66
|
-
|
|
67
|
-
const scopesToUse = params.scopes || scopes;
|
|
68
|
-
|
|
69
|
-
const tokenResponse = await fetchToken({
|
|
70
|
-
...params,
|
|
71
|
-
scopes: [
|
|
72
|
-
UserScope.OrganizationRoles,
|
|
73
|
-
UserScope.Organizations,
|
|
74
|
-
...scopesToUse,
|
|
75
|
-
],
|
|
76
|
-
specificBodyFields: {
|
|
77
|
-
organization_id: params.organizationId,
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
return tokenResponse.access_token;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const importUserScopes = async () => {
|
|
84
|
-
try {
|
|
85
|
-
const { UserScope } = await import("@logto/node");
|
|
86
|
-
|
|
87
|
-
return { UserScope };
|
|
88
|
-
} catch {
|
|
89
|
-
throw new Error("@logto/node package is not installed!");
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export const getM2MTokenFn = (
|
|
94
|
-
m2mTokenConfig: M2MTokenFnConfig,
|
|
95
|
-
): TokenFunction => {
|
|
96
|
-
const { services } = m2mTokenConfig;
|
|
97
|
-
|
|
98
|
-
const tokenFn = (serviceName: SERVICE_NAME) => {
|
|
99
|
-
const serviceParams = services[serviceName];
|
|
100
|
-
|
|
101
|
-
if (!serviceParams) {
|
|
102
|
-
throw new Error(`Missing m2m config for ${serviceName}`);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const { getAccessTokenParams, getOrganizationTokenParams } = serviceParams;
|
|
106
|
-
if (getAccessTokenParams) {
|
|
107
|
-
return getAccessToken(getAccessTokenParams, []);
|
|
108
|
-
}
|
|
109
|
-
if (getOrganizationTokenParams) {
|
|
110
|
-
return getOrganizationToken(getOrganizationTokenParams, []);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
throw new Error(`wrong m2m config for ${serviceName}`);
|
|
114
|
-
};
|
|
115
|
-
return tokenFn;
|
|
116
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { SERVICE_NAME } from "../../base/base-client.js";
|
|
2
|
-
|
|
3
|
-
export type TokenFunction = (
|
|
4
|
-
serviceName: SERVICE_NAME,
|
|
5
|
-
) => Promise<string> | string;
|
|
6
|
-
|
|
7
|
-
export type M2MParams = {
|
|
8
|
-
getOrganizationTokenParams?: GetOrganizationTokenParams;
|
|
9
|
-
getAccessTokenParams?: GetAccessTokenParams;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type M2MTokenFnConfig = {
|
|
13
|
-
services: {
|
|
14
|
-
[key in SERVICE_NAME]?: M2MParams;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export interface TokenResponseBody {
|
|
19
|
-
access_token: string;
|
|
20
|
-
expires_in: number;
|
|
21
|
-
token_type: string;
|
|
22
|
-
scope: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface GetTokenBaseParams {
|
|
26
|
-
logtoOidcEndpoint: string;
|
|
27
|
-
applicationId: string;
|
|
28
|
-
applicationSecret: string;
|
|
29
|
-
scopes?: string[];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface GetAccessTokenParams extends GetTokenBaseParams {
|
|
33
|
-
resource: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface GetOrganizationTokenParams extends GetTokenBaseParams {
|
|
37
|
-
organizationId: string;
|
|
38
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Analytics } from "../index.js";
|
|
2
|
-
import { SERVICE_NAME } from "../base/base-client.js";
|
|
3
|
-
|
|
4
|
-
type ServiceClients = {
|
|
5
|
-
analytics: typeof Analytics;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type TokenFunction = (
|
|
9
|
-
serviceName: SERVICE_NAME,
|
|
10
|
-
) => Promise<string> | string;
|
|
11
|
-
|
|
12
|
-
export type BuildingBlockSDKParams = {
|
|
13
|
-
services: {
|
|
14
|
-
[key in keyof ServiceClients]?: ConstructorParameters<
|
|
15
|
-
ServiceClients[key]
|
|
16
|
-
>[0];
|
|
17
|
-
};
|
|
18
|
-
getTokenFn?: TokenFunction;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const getBuildingBlockSDK = (params: BuildingBlockSDKParams) => {
|
|
22
|
-
const { services, getTokenFn } = params;
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
analytics: new Analytics({
|
|
26
|
-
...services.analytics,
|
|
27
|
-
getTokenFn,
|
|
28
|
-
}),
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export default getBuildingBlockSDK;
|
package/src/utils/index.test.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import t from "tap";
|
|
2
|
-
import { ensureTrailingSlash } from "./index.js";
|
|
3
|
-
|
|
4
|
-
t.test("ensureTrailingSlash", (t) => {
|
|
5
|
-
t.test("should add a trailing slash if not present", (t) => {
|
|
6
|
-
const input = "https://example.com";
|
|
7
|
-
const expected = "https://example.com/";
|
|
8
|
-
|
|
9
|
-
const result = ensureTrailingSlash(input);
|
|
10
|
-
|
|
11
|
-
t.equal(result, expected, "Adds trailing slash");
|
|
12
|
-
t.end();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
t.test("should not add a trailing slash if already present", (t) => {
|
|
16
|
-
const input = "https://example.com/";
|
|
17
|
-
const expected = "https://example.com/";
|
|
18
|
-
|
|
19
|
-
const result = ensureTrailingSlash(input);
|
|
20
|
-
|
|
21
|
-
t.equal(result, expected, "Keeps existing trailing slash");
|
|
22
|
-
t.end();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
t.test("should handle empty string", (t) => {
|
|
26
|
-
const input = "";
|
|
27
|
-
const expected = "/";
|
|
28
|
-
|
|
29
|
-
const result = ensureTrailingSlash(input);
|
|
30
|
-
|
|
31
|
-
t.equal(result, expected, "Adds trailing slash to empty string");
|
|
32
|
-
t.end();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
t.test("should not add a trailing slash if already present", (t) => {
|
|
36
|
-
const input = "https://example.com/";
|
|
37
|
-
const expected = "https://example.com/";
|
|
38
|
-
|
|
39
|
-
const result = ensureTrailingSlash(input);
|
|
40
|
-
|
|
41
|
-
t.equal(result, expected, "Keeps existing trailing slash");
|
|
42
|
-
t.end();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
t.end();
|
|
46
|
-
});
|
package/src/utils/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export function ensureTrailingSlash(url: string) {
|
|
2
|
-
return url.endsWith("/") ? url : `${url}/`;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Get an environment variable using process.env, if in browser, return undefined
|
|
7
|
-
*/
|
|
8
|
-
export const getEnvVariable = (key: string): string | undefined => {
|
|
9
|
-
if (typeof process !== "undefined" && process.env) {
|
|
10
|
-
// Node.js environment
|
|
11
|
-
return process.env[key];
|
|
12
|
-
} else {
|
|
13
|
-
// Browser environment
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export function isBrowser(): boolean {
|
|
19
|
-
return typeof window !== "undefined" && window.document !== undefined;
|
|
20
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"preserveSymlinks": true,
|
|
4
|
-
"target": "ESNext",
|
|
5
|
-
"module": "NodeNext",
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
"moduleResolution": "NodeNext",
|
|
8
|
-
"esModuleInterop": true,
|
|
9
|
-
"forceConsistentCasingInFileNames": true,
|
|
10
|
-
"strict": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"declaration": true,
|
|
13
|
-
"declarationMap": true,
|
|
14
|
-
"experimentalDecorators": true
|
|
15
|
-
},
|
|
16
|
-
"include": ["src/**/*", "types.d.ts"],
|
|
17
|
-
"exclude": ["examples", "dist", "src/**/*.test.ts"]
|
|
18
|
-
}
|