@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.
Files changed (83) hide show
  1. package/dist/base/base-client.d.ts +2 -7
  2. package/dist/base/base-client.d.ts.map +1 -1
  3. package/dist/base/base-client.js +3 -15
  4. package/dist/base/base-client.js.map +1 -0
  5. package/{types.d.ts → dist/browser-types.d.ts} +1 -1
  6. package/dist/index.d.ts +400 -597
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +332 -198
  9. package/dist/index.js.map +1 -0
  10. package/dist/matomo/helpers.d.ts +15 -0
  11. package/dist/matomo/helpers.d.ts.map +1 -1
  12. package/dist/matomo/helpers.js +80 -0
  13. package/dist/matomo/helpers.js.map +1 -0
  14. package/dist/matomo/types.d.ts +6 -2
  15. package/dist/matomo/types.d.ts.map +1 -1
  16. package/dist/matomo/types.js +1 -0
  17. package/dist/matomo/types.js.map +1 -0
  18. package/dist/schema.d.ts +223 -387
  19. package/dist/schema.d.ts.map +1 -1
  20. package/dist/schema.js +1 -0
  21. package/dist/schema.js.map +1 -0
  22. package/dist/support-files/auth/index.js +1 -0
  23. package/dist/support-files/auth/index.js.map +1 -0
  24. package/dist/support-files/auth/types.d.ts +1 -1
  25. package/dist/support-files/auth/types.d.ts.map +1 -1
  26. package/dist/support-files/auth/types.js +1 -0
  27. package/dist/support-files/auth/types.js.map +1 -0
  28. package/dist/support-files/building-blocks-sdk.d.ts +1 -1
  29. package/dist/support-files/building-blocks-sdk.d.ts.map +1 -1
  30. package/dist/support-files/building-blocks-sdk.js +1 -0
  31. package/dist/support-files/building-blocks-sdk.js.map +1 -0
  32. package/dist/utils/index.js +1 -0
  33. package/dist/utils/index.js.map +1 -0
  34. package/package.json +24 -16
  35. package/dist/ogcio-analytics-sdk-0.0.1.tgz +0 -0
  36. package/dist/package/dist/base/base-client.d.ts +0 -36
  37. package/dist/package/dist/base/base-client.d.ts.map +0 -1
  38. package/dist/package/dist/base/base-client.js +0 -96
  39. package/dist/package/dist/index.d.ts +0 -651
  40. package/dist/package/dist/index.d.ts.map +0 -1
  41. package/dist/package/dist/index.js +0 -321
  42. package/dist/package/dist/matomo/helpers.d.ts +0 -9
  43. package/dist/package/dist/matomo/helpers.d.ts.map +0 -1
  44. package/dist/package/dist/matomo/helpers.js +0 -10
  45. package/dist/package/dist/matomo/types.d.ts +0 -33
  46. package/dist/package/dist/matomo/types.d.ts.map +0 -1
  47. package/dist/package/dist/matomo/types.js +0 -1
  48. package/dist/package/dist/schema.d.ts +0 -1295
  49. package/dist/package/dist/schema.d.ts.map +0 -1
  50. package/dist/package/dist/schema.js +0 -5
  51. package/dist/package/dist/support-files/auth/index.d.ts +0 -3
  52. package/dist/package/dist/support-files/auth/index.d.ts.map +0 -1
  53. package/dist/package/dist/support-files/auth/index.js +0 -76
  54. package/dist/package/dist/support-files/auth/types.d.ts +0 -31
  55. package/dist/package/dist/support-files/auth/types.d.ts.map +0 -1
  56. package/dist/package/dist/support-files/auth/types.js +0 -1
  57. package/dist/package/dist/support-files/building-blocks-sdk.d.ts +0 -17
  58. package/dist/package/dist/support-files/building-blocks-sdk.d.ts.map +0 -1
  59. package/dist/package/dist/support-files/building-blocks-sdk.js +0 -11
  60. package/dist/package/dist/utils/index.d.ts +0 -7
  61. package/dist/package/dist/utils/index.d.ts.map +0 -1
  62. package/dist/package/dist/utils/index.js +0 -19
  63. package/dist/package/examples/environment.d.ts +0 -11
  64. package/dist/package/examples/index.ts +0 -201
  65. package/dist/package/examples/tsconfig.json +0 -15
  66. package/dist/package/package.json +0 -56
  67. package/dist/package/tsconfig.json +0 -18
  68. package/dist/package/types.d.ts +0 -19
  69. package/examples/environment.d.ts +0 -11
  70. package/examples/index.ts +0 -201
  71. package/examples/tsconfig.json +0 -15
  72. package/src/base/base-client.ts +0 -172
  73. package/src/index.test.ts +0 -92
  74. package/src/index.ts +0 -449
  75. package/src/matomo/helpers.ts +0 -14
  76. package/src/matomo/types.ts +0 -48
  77. package/src/schema.ts +0 -1295
  78. package/src/support-files/auth/index.ts +0 -116
  79. package/src/support-files/auth/types.ts +0 -38
  80. package/src/support-files/building-blocks-sdk.ts +0 -32
  81. package/src/utils/index.test.ts +0 -46
  82. package/src/utils/index.ts +0 -20
  83. 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;
@@ -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
- });
@@ -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
- }