@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.
- package/.husky/commit-msg +1 -0
- package/.husky/pre-push +1 -0
- package/.nvmrc +1 -0
- package/.vscode/settings.json +20 -0
- package/biome.jsonc +45 -0
- package/commitlint.config.js +6 -0
- package/dist/client/auth/index.d.ts +4 -0
- package/dist/client/auth/index.d.ts.map +1 -0
- package/dist/client/auth/index.js +83 -0
- package/dist/client/auth/index.js.map +1 -0
- package/dist/client/base-client.d.ts +18 -0
- package/dist/client/base-client.d.ts.map +1 -0
- package/dist/client/base-client.js +71 -0
- package/dist/client/base-client.js.map +1 -0
- package/dist/client/clients/messaging/index.d.ts +2407 -0
- package/dist/client/clients/messaging/index.d.ts.map +1 -0
- package/dist/client/clients/messaging/index.js +430 -0
- package/dist/client/clients/messaging/index.js.map +1 -0
- package/dist/client/clients/messaging/schema.d.ts +3823 -0
- package/dist/client/clients/messaging/schema.d.ts.map +1 -0
- package/dist/client/clients/messaging/schema.js +2 -0
- package/dist/client/clients/messaging/schema.js.map +1 -0
- package/dist/client/clients/payments/index.d.ts +2294 -0
- package/dist/client/clients/payments/index.d.ts.map +1 -0
- package/dist/client/clients/payments/index.js +217 -0
- package/dist/client/clients/payments/index.js.map +1 -0
- package/dist/client/clients/payments/schema.d.ts +2534 -0
- package/dist/client/clients/payments/schema.d.ts.map +1 -0
- package/dist/client/clients/payments/schema.js +2 -0
- package/dist/client/clients/payments/schema.js.map +1 -0
- package/dist/client/clients/profile/index.d.ts +1364 -0
- package/dist/client/clients/profile/index.d.ts.map +1 -0
- package/dist/client/clients/profile/index.js +102 -0
- package/dist/client/clients/profile/index.js.map +1 -0
- package/dist/client/clients/profile/schema.d.ts +1429 -0
- package/dist/client/clients/profile/schema.d.ts.map +1 -0
- package/dist/client/clients/profile/schema.js +2 -0
- package/dist/client/clients/profile/schema.js.map +1 -0
- package/dist/client/clients/scheduler/index.d.ts +14 -0
- package/dist/client/clients/scheduler/index.d.ts.map +1 -0
- package/dist/client/clients/scheduler/index.js +14 -0
- package/dist/client/clients/scheduler/index.js.map +1 -0
- package/dist/client/clients/scheduler/schema.d.ts +114 -0
- package/dist/client/clients/scheduler/schema.d.ts.map +1 -0
- package/dist/client/clients/scheduler/schema.js +2 -0
- package/dist/client/clients/scheduler/schema.js.map +1 -0
- package/dist/client/clients/upload/index.d.ts +390 -0
- package/dist/client/clients/upload/index.d.ts.map +1 -0
- package/dist/client/clients/upload/index.js +93 -0
- package/dist/client/clients/upload/index.js.map +1 -0
- package/dist/client/clients/upload/schema.d.ts +564 -0
- package/dist/client/clients/upload/schema.d.ts.map +1 -0
- package/dist/client/clients/upload/schema.js +2 -0
- package/dist/client/clients/upload/schema.js.map +1 -0
- package/dist/client/utils/client-utils.d.ts +15 -0
- package/dist/client/utils/client-utils.d.ts.map +1 -0
- package/dist/client/utils/client-utils.js +14 -0
- package/dist/client/utils/client-utils.js.map +1 -0
- package/dist/clients-configurations/clients-configuration.json +92 -0
- package/dist/clients-configurations/read-configuration-file.d.ts +22 -0
- package/dist/clients-configurations/read-configuration-file.d.ts.map +1 -0
- package/dist/clients-configurations/read-configuration-file.js +47 -0
- package/dist/clients-configurations/read-configuration-file.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +63 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/get-absolute-path.d.ts +3 -0
- package/dist/utils/get-absolute-path.d.ts.map +1 -0
- package/dist/utils/get-absolute-path.js +8 -0
- package/dist/utils/get-absolute-path.js.map +1 -0
- package/package.json +44 -0
- package/src/cli/cli-utils.ts +25 -0
- package/src/cli/index.ts +13 -0
- package/src/cli/outdated-clients-command.ts +148 -0
- package/src/cli/update-clients-command.ts +298 -0
- package/src/client/auth/index.ts +131 -0
- package/src/client/base-client.ts +97 -0
- package/src/client/clients/messaging/index.ts +683 -0
- package/src/client/clients/messaging/open-api-definition.json +8394 -0
- package/src/client/clients/messaging/schema.ts +3822 -0
- package/src/client/clients/payments/index.ts +349 -0
- package/src/client/clients/payments/open-api-definition.json +6094 -0
- package/src/client/clients/payments/schema.ts +2533 -0
- package/src/client/clients/profile/index.ts +182 -0
- package/src/client/clients/profile/open-api-definition.json +2876 -0
- package/src/client/clients/profile/schema.ts +1428 -0
- package/src/client/clients/scheduler/index.ts +28 -0
- package/src/client/clients/scheduler/open-api-definition.json +120 -0
- package/src/client/clients/scheduler/schema.ts +113 -0
- package/src/client/clients/upload/index.ts +129 -0
- package/src/client/clients/upload/open-api-definition.json +985 -0
- package/src/client/clients/upload/schema.ts +563 -0
- package/src/client/utils/client-utils.ts +50 -0
- package/src/clients-configurations/clients-configuration.json +92 -0
- package/src/clients-configurations/read-configuration-file.ts +68 -0
- package/src/index.ts +43 -0
- package/src/logto-node.d.ts +12 -0
- package/src/types/index.ts +82 -0
- package/src/utils/get-absolute-path.ts +10 -0
- package/tsconfig.json +18 -0
- 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
|
+
}
|