@ogcio/building-blocks-sdk 0.0.1

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 (106) hide show
  1. package/.husky/commit-msg +1 -0
  2. package/.husky/pre-push +1 -0
  3. package/.nvmrc +1 -0
  4. package/.vscode/settings.json +20 -0
  5. package/biome.jsonc +45 -0
  6. package/commitlint.config.js +6 -0
  7. package/dist/client/auth/index.d.ts +4 -0
  8. package/dist/client/auth/index.d.ts.map +1 -0
  9. package/dist/client/auth/index.js +83 -0
  10. package/dist/client/auth/index.js.map +1 -0
  11. package/dist/client/base-client.d.ts +18 -0
  12. package/dist/client/base-client.d.ts.map +1 -0
  13. package/dist/client/base-client.js +71 -0
  14. package/dist/client/base-client.js.map +1 -0
  15. package/dist/client/clients/messaging/index.d.ts +2407 -0
  16. package/dist/client/clients/messaging/index.d.ts.map +1 -0
  17. package/dist/client/clients/messaging/index.js +430 -0
  18. package/dist/client/clients/messaging/index.js.map +1 -0
  19. package/dist/client/clients/messaging/schema.d.ts +3823 -0
  20. package/dist/client/clients/messaging/schema.d.ts.map +1 -0
  21. package/dist/client/clients/messaging/schema.js +2 -0
  22. package/dist/client/clients/messaging/schema.js.map +1 -0
  23. package/dist/client/clients/payments/index.d.ts +2294 -0
  24. package/dist/client/clients/payments/index.d.ts.map +1 -0
  25. package/dist/client/clients/payments/index.js +217 -0
  26. package/dist/client/clients/payments/index.js.map +1 -0
  27. package/dist/client/clients/payments/schema.d.ts +2534 -0
  28. package/dist/client/clients/payments/schema.d.ts.map +1 -0
  29. package/dist/client/clients/payments/schema.js +2 -0
  30. package/dist/client/clients/payments/schema.js.map +1 -0
  31. package/dist/client/clients/profile/index.d.ts +1364 -0
  32. package/dist/client/clients/profile/index.d.ts.map +1 -0
  33. package/dist/client/clients/profile/index.js +102 -0
  34. package/dist/client/clients/profile/index.js.map +1 -0
  35. package/dist/client/clients/profile/schema.d.ts +1429 -0
  36. package/dist/client/clients/profile/schema.d.ts.map +1 -0
  37. package/dist/client/clients/profile/schema.js +2 -0
  38. package/dist/client/clients/profile/schema.js.map +1 -0
  39. package/dist/client/clients/scheduler/index.d.ts +14 -0
  40. package/dist/client/clients/scheduler/index.d.ts.map +1 -0
  41. package/dist/client/clients/scheduler/index.js +14 -0
  42. package/dist/client/clients/scheduler/index.js.map +1 -0
  43. package/dist/client/clients/scheduler/schema.d.ts +114 -0
  44. package/dist/client/clients/scheduler/schema.d.ts.map +1 -0
  45. package/dist/client/clients/scheduler/schema.js +2 -0
  46. package/dist/client/clients/scheduler/schema.js.map +1 -0
  47. package/dist/client/clients/upload/index.d.ts +390 -0
  48. package/dist/client/clients/upload/index.d.ts.map +1 -0
  49. package/dist/client/clients/upload/index.js +93 -0
  50. package/dist/client/clients/upload/index.js.map +1 -0
  51. package/dist/client/clients/upload/schema.d.ts +564 -0
  52. package/dist/client/clients/upload/schema.d.ts.map +1 -0
  53. package/dist/client/clients/upload/schema.js +2 -0
  54. package/dist/client/clients/upload/schema.js.map +1 -0
  55. package/dist/client/utils/client-utils.d.ts +15 -0
  56. package/dist/client/utils/client-utils.d.ts.map +1 -0
  57. package/dist/client/utils/client-utils.js +14 -0
  58. package/dist/client/utils/client-utils.js.map +1 -0
  59. package/dist/clients-configurations/clients-configuration.json +92 -0
  60. package/dist/clients-configurations/read-configuration-file.d.ts +22 -0
  61. package/dist/clients-configurations/read-configuration-file.d.ts.map +1 -0
  62. package/dist/clients-configurations/read-configuration-file.js +47 -0
  63. package/dist/clients-configurations/read-configuration-file.js.map +1 -0
  64. package/dist/index.d.ts +6 -0
  65. package/dist/index.d.ts.map +1 -0
  66. package/dist/index.js +33 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/types/index.d.ts +63 -0
  69. package/dist/types/index.d.ts.map +1 -0
  70. package/dist/types/index.js +6 -0
  71. package/dist/types/index.js.map +1 -0
  72. package/dist/utils/get-absolute-path.d.ts +3 -0
  73. package/dist/utils/get-absolute-path.d.ts.map +1 -0
  74. package/dist/utils/get-absolute-path.js +8 -0
  75. package/dist/utils/get-absolute-path.js.map +1 -0
  76. package/package.json +44 -0
  77. package/src/cli/cli-utils.ts +25 -0
  78. package/src/cli/index.ts +13 -0
  79. package/src/cli/outdated-clients-command.ts +148 -0
  80. package/src/cli/update-clients-command.ts +298 -0
  81. package/src/client/auth/index.ts +131 -0
  82. package/src/client/base-client.ts +97 -0
  83. package/src/client/clients/messaging/index.ts +683 -0
  84. package/src/client/clients/messaging/open-api-definition.json +8394 -0
  85. package/src/client/clients/messaging/schema.ts +3822 -0
  86. package/src/client/clients/payments/index.ts +349 -0
  87. package/src/client/clients/payments/open-api-definition.json +6094 -0
  88. package/src/client/clients/payments/schema.ts +2533 -0
  89. package/src/client/clients/profile/index.ts +182 -0
  90. package/src/client/clients/profile/open-api-definition.json +2876 -0
  91. package/src/client/clients/profile/schema.ts +1428 -0
  92. package/src/client/clients/scheduler/index.ts +28 -0
  93. package/src/client/clients/scheduler/open-api-definition.json +120 -0
  94. package/src/client/clients/scheduler/schema.ts +113 -0
  95. package/src/client/clients/upload/index.ts +129 -0
  96. package/src/client/clients/upload/open-api-definition.json +985 -0
  97. package/src/client/clients/upload/schema.ts +563 -0
  98. package/src/client/utils/client-utils.ts +50 -0
  99. package/src/clients-configurations/clients-configuration.json +92 -0
  100. package/src/clients-configurations/read-configuration-file.ts +68 -0
  101. package/src/index.ts +43 -0
  102. package/src/logto-node.d.ts +12 -0
  103. package/src/types/index.ts +82 -0
  104. package/src/utils/get-absolute-path.ts +10 -0
  105. package/tsconfig.json +18 -0
  106. package/tsconfig.prod.json +4 -0
@@ -0,0 +1,68 @@
1
+ import { type Static, Type } from "@sinclair/typebox";
2
+ import { Value } from "@sinclair/typebox/value";
3
+
4
+ export enum OpenAPIFileFormats {
5
+ JSON = "json",
6
+ YAML = "yaml",
7
+ }
8
+
9
+ const ConfigurationBuildingBlockSchema = Type.Object({
10
+ name: Type.String(),
11
+ openApiDefinitionUrl: Type.String(),
12
+ openApiDefinitionFormat: Type.Enum(OpenAPIFileFormats),
13
+ citizenPermissions: Type.Array(Type.String(), { default: [] }),
14
+ publicServantPermissions: Type.Array(Type.String(), { default: [] }),
15
+ updateDefinitions: Type.Boolean({ default: true }),
16
+ });
17
+
18
+ export type ConfigurationBuildingBlock = Static<
19
+ typeof ConfigurationBuildingBlockSchema
20
+ >;
21
+
22
+ const InputFileSchema = Type.Object({
23
+ buildingBlocks: Type.Array(ConfigurationBuildingBlockSchema),
24
+ });
25
+
26
+ type ConfigurationFile = {
27
+ buildingBlocks: { [x: string]: ConfigurationBuildingBlock };
28
+ };
29
+
30
+ function ensureBuildingBlockNameIsValid(bbName: string) {
31
+ // The building block name must only contain letters
32
+ // so its name can be used to get it using dot notation
33
+ // in code. E.g. sdkClient.messaging, where messaging
34
+ // is the name of the BB
35
+ const regex = /^[a-zA-Z]+$/g;
36
+ if (!regex.test(bbName))
37
+ throw new Error(
38
+ `A building block name can only contain letters, ${bbName} is not valid`,
39
+ );
40
+ }
41
+
42
+ export async function readConfigurationFile(
43
+ configurationFilePath: string,
44
+ ): Promise<ConfigurationFile> {
45
+ const { default: rawConfigurationFile } = await import(
46
+ configurationFilePath,
47
+ {
48
+ assert: {
49
+ type: "json",
50
+ },
51
+ }
52
+ );
53
+
54
+ const parsedFile = Value.Parse(InputFileSchema, rawConfigurationFile);
55
+
56
+ // Why do not directly create an object where the service name
57
+ // is the key in the configuration file instead of an array?
58
+ // To avoid having unexpected behaviours on naming
59
+ // e.g. Adding a "messaging-api" entry could return
60
+ // "messagingApi" when parsing
61
+ const outputFile: ConfigurationFile = { buildingBlocks: {} };
62
+ for (const parsedBlock of parsedFile.buildingBlocks) {
63
+ ensureBuildingBlockNameIsValid(parsedBlock.name);
64
+ outputFile.buildingBlocks[parsedBlock.name] = parsedBlock;
65
+ }
66
+
67
+ return outputFile;
68
+ }
package/src/index.ts ADDED
@@ -0,0 +1,43 @@
1
+ import Messaging from "./client/clients/messaging/index.js";
2
+ import Payments from "./client/clients/payments/index.js";
3
+ import Profile from "./client/clients/profile/index.js";
4
+ import Scheduler from "./client/clients/scheduler/index.js";
5
+ import Upload from "./client/clients/upload/index.js";
6
+
7
+ export type { BuildingBlocksSDK } from "./types/index.js";
8
+ export { default as getM2MTokenFn } from "./client/auth/index.js";
9
+
10
+ import type {
11
+ BuildingBlockSDKParams,
12
+ BuildingBlocksSDK,
13
+ } from "./types/index.js";
14
+
15
+ const getBuildingBlockSDK = (
16
+ params: BuildingBlockSDKParams,
17
+ ): BuildingBlocksSDK => {
18
+ const { services, getTokenFn } = params;
19
+ return {
20
+ messaging: new Messaging({
21
+ ...services.messaging,
22
+ getTokenFn,
23
+ }),
24
+ payments: new Payments({
25
+ ...services.payments,
26
+ getTokenFn,
27
+ }),
28
+ profile: new Profile({
29
+ ...services.payments,
30
+ getTokenFn,
31
+ }),
32
+ scheduler: new Scheduler({
33
+ ...services.scheduler,
34
+ getTokenFn,
35
+ }),
36
+ upload: new Upload({
37
+ ...services.upload,
38
+ getTokenFn,
39
+ }),
40
+ };
41
+ };
42
+
43
+ export default getBuildingBlockSDK;
@@ -0,0 +1,12 @@
1
+ declare module "@logto/node" {
2
+ export enum UserScope {
3
+ Profile = "profile",
4
+ Email = "email",
5
+ Phone = "phone",
6
+ CustomData = "custom_data",
7
+ Identities = "identities",
8
+ Roles = "roles",
9
+ Organizations = "urn:logto:scope:organizations",
10
+ OrganizationRoles = "urn:logto:scope:organization_roles",
11
+ }
12
+ }
@@ -0,0 +1,82 @@
1
+ import type Messaging from "../client/clients/messaging/index.js";
2
+ import type Payments from "../client/clients/payments/index.js";
3
+ import type Profile from "../client/clients/profile/index.js";
4
+ import type Scheduler from "../client/clients/scheduler/index.js";
5
+ import type Upload from "../client/clients/upload/index.js";
6
+
7
+ export const MESSAGING = "messaging" as const;
8
+ export const PAYMENTS = "payments" as const;
9
+ export const PROFILE = "profile" as const;
10
+ export const SCHEDULER = "scheduler" as const;
11
+ export const UPLOAD = "upload" as const;
12
+
13
+ export type SERVICE_NAME =
14
+ | typeof MESSAGING
15
+ | typeof PAYMENTS
16
+ | typeof PROFILE
17
+ | typeof SCHEDULER
18
+ | typeof UPLOAD;
19
+
20
+ export type TokenFunction = (
21
+ serviceName: SERVICE_NAME,
22
+ ) => Promise<string> | string;
23
+
24
+ export type M2MParams = {
25
+ getOrganizationTokenParams?: GetOrganizationTokenParams;
26
+ getAccessTokenParams?: GetAccessTokenParams;
27
+ };
28
+
29
+ export type M2MTokenFnConfig = {
30
+ services: {
31
+ [key in SERVICE_NAME]?: M2MParams;
32
+ };
33
+ };
34
+
35
+ export type SDKClientParams = {
36
+ baseUrl?: string;
37
+ };
38
+
39
+ export type ApiClientParams = SDKClientParams & {
40
+ getTokenFn?: TokenFunction;
41
+ };
42
+
43
+ type ServiceClients = {
44
+ messaging: Messaging;
45
+ payments: Payments;
46
+ profile: Profile;
47
+ scheduler: Scheduler;
48
+ upload: Upload;
49
+ };
50
+
51
+ export type BuildingBlocksSDK = {
52
+ [key in keyof ServiceClients]: ServiceClients[key];
53
+ };
54
+
55
+ export type BuildingBlockSDKParams = {
56
+ services: {
57
+ [key in keyof ServiceClients]?: SDKClientParams;
58
+ };
59
+ getTokenFn?: TokenFunction;
60
+ };
61
+
62
+ export interface TokenResponseBody {
63
+ access_token: string;
64
+ expires_in: number;
65
+ token_type: string;
66
+ scope: string;
67
+ }
68
+
69
+ interface GetTokenBaseParams {
70
+ logtoOidcEndpoint: string;
71
+ applicationId: string;
72
+ applicationSecret: string;
73
+ scopes?: string[];
74
+ }
75
+
76
+ export interface GetAccessTokenParams extends GetTokenBaseParams {
77
+ resource: string;
78
+ }
79
+
80
+ export interface GetOrganizationTokenParams extends GetTokenBaseParams {
81
+ organizationId: string;
82
+ }
@@ -0,0 +1,10 @@
1
+ import { dirname, resolve } from "path";
2
+ import { fileURLToPath } from "url";
3
+
4
+ const __dirname = dirname(fileURLToPath(import.meta.url));
5
+
6
+ function getAbsolutePath(...relativeInputPath: string[]): string {
7
+ return resolve(__dirname, "..", "..", ...relativeInputPath);
8
+ }
9
+
10
+ export default getAbsolutePath;
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "strict": true,
5
+ "esModuleInterop": true,
6
+ "skipLibCheck": true,
7
+ "forceConsistentCasingInFileNames": true,
8
+ "declaration": true,
9
+ "declarationMap": true,
10
+ "sourceMap": true,
11
+ "module": "NodeNext",
12
+ "moduleResolution": "NodeNext",
13
+ "outDir": "dist",
14
+ "rootDir": "src",
15
+ "resolveJsonModule": true
16
+ },
17
+ "include": ["./src"]
18
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": ["__tests__", "dist", "./src/cli"]
4
+ }