@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,15 @@
1
+ import type { ParseAsResponse } from "openapi-fetch";
2
+ import type { ErrorStatus, FilterKeys, OkStatus, ResponseContent, ResponseObjectMap } from "openapi-typescript-helpers";
3
+ export interface PaginationParams {
4
+ offset?: string | number;
5
+ limit?: string | number;
6
+ }
7
+ export type DataResponseValue<T, O> = ParseAsResponse<FilterKeys<ResponseContent<FilterKeys<ResponseObjectMap<T>, OkStatus>>, "application/json">, O> & {
8
+ error: ParseAsResponse<FilterKeys<ResponseContent<FilterKeys<ResponseObjectMap<T>, ErrorStatus>>, "application/json">, O>;
9
+ };
10
+ export declare function toStringOrUndefined(variable: number | boolean | undefined): string | undefined;
11
+ export declare function preparePaginationParams(paginationParams?: PaginationParams): {
12
+ offset?: string;
13
+ limit?: string;
14
+ };
15
+ //# sourceMappingURL=client-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-utils.d.ts","sourceRoot":"","sources":["../../../src/client/utils/client-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,QAAQ,EACR,eAAe,EACf,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AAEpC,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,iBAAiB,CAAC,CAAC,EAAE,CAAC,IAAI,eAAe,CACnD,UAAU,CACR,eAAe,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,EAC3D,kBAAkB,CACnB,EACD,CAAC,CACF,GAAG;IACF,KAAK,EAAE,eAAe,CACpB,UAAU,CACR,eAAe,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,EAC9D,kBAAkB,CACnB,EACD,CAAC,CACF,CAAC;CACH,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,sBAEzE;AAED,wBAAgB,uBAAuB,CAAC,gBAAgB,CAAC,EAAE,gBAAgB,GAAG;IAC5E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAYA"}
@@ -0,0 +1,14 @@
1
+ export function toStringOrUndefined(variable) {
2
+ return variable === undefined ? undefined : String(variable);
3
+ }
4
+ export function preparePaginationParams(paginationParams) {
5
+ const output = {};
6
+ if (paginationParams?.offset) {
7
+ output.offset = String(paginationParams.offset);
8
+ }
9
+ if (paginationParams?.limit) {
10
+ output.limit = String(paginationParams.limit);
11
+ }
12
+ return output;
13
+ }
14
+ //# sourceMappingURL=client-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-utils.js","sourceRoot":"","sources":["../../../src/client/utils/client-utils.ts"],"names":[],"mappings":"AA8BA,MAAM,UAAU,mBAAmB,CAAC,QAAsC;IACxE,OAAO,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,gBAAmC;IAIzE,MAAM,MAAM,GAAwC,EAAE,CAAC;IAEvD,IAAI,gBAAgB,EAAE,MAAM,EAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;IAED,IAAI,gBAAgB,EAAE,KAAK,EAAE,CAAC;QAC5B,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,92 @@
1
+ {
2
+ "buildingBlocks": [
3
+ {
4
+ "name": "messaging",
5
+ "openApiDefinitionUrl": "https://raw.githubusercontent.com/ogcio/life-events/refs/heads/dev/apps/messaging-api/openapi-definition.yml",
6
+ "openApiDefinitionFormat": "yaml",
7
+ "citizenPermissions": [
8
+ "messaging:message.self:read",
9
+ "messaging:message.self:write",
10
+ "messaging:citizen.self:read",
11
+ "messaging:citizen.self:write"
12
+ ],
13
+ "publicServantPermissions": [
14
+ "urn:logto:scope:organizations",
15
+ "urn:logto:scope:organization_roles",
16
+ "messaging:message:*",
17
+ "messaging:provider:*",
18
+ "messaging:template:*",
19
+ "messaging:citizen:*",
20
+ "messaging:event:read"
21
+ ],
22
+ "updateDefinitions": false
23
+ },
24
+ {
25
+ "name": "upload",
26
+ "openApiDefinitionUrl": "https://raw.githubusercontent.com/ogcio/life-events/refs/heads/dev/apps/upload-api/openapi-definition.yml",
27
+ "openApiDefinitionFormat": "yaml",
28
+ "citizenPermissions": ["upload:file.self:write", "upload:file.self:read"],
29
+ "publicServantPermissions": [
30
+ "urn:logto:scope:organizations",
31
+ "urn:logto:scope:organization_roles",
32
+ "upload:file:*",
33
+ "profile:user:read"
34
+ ],
35
+ "updateDefinitions": false
36
+ },
37
+ {
38
+ "name": "payments",
39
+ "openApiDefinitionUrl": "https://raw.githubusercontent.com/ogcio/life-events/refs/heads/dev/apps/payments-api/openapi-definition.yml",
40
+ "openApiDefinitionFormat": "yaml",
41
+ "citizenPermissions": [
42
+ "payments:transaction.self:read",
43
+ "payments:payment_request.public:read",
44
+ "payments:transaction.self:write",
45
+ "payments:provider.public:read"
46
+ ],
47
+ "publicServantPermissions": [
48
+ "urn:logto:scope:organizations",
49
+ "urn:logto:scope:organization_roles",
50
+ "payments:provider:*",
51
+ "payments:payment_request:*",
52
+ "payments:payment_request.public:read",
53
+ "payments:transaction:*"
54
+ ],
55
+ "updateDefinitions": false
56
+ },
57
+ {
58
+ "name": "scheduler",
59
+ "openApiDefinitionUrl": "https://raw.githubusercontent.com/ogcio/life-events/refs/heads/dev/apps/scheduler-api/openapi-definition.yml",
60
+ "openApiDefinitionFormat": "yaml",
61
+ "citizenPermissions": ["scheduler:jobs:write"],
62
+ "publicServantPermissions": [
63
+ "urn:logto:scope:organizations",
64
+ "urn:logto:scope:organization_roles",
65
+ "scheduler:jobs:write"
66
+ ],
67
+ "updateDefinitions": false
68
+ },
69
+ {
70
+ "name": "profile",
71
+ "openApiDefinitionUrl": "http://localhost:8003/docs/json",
72
+ "openApiDefinitionFormat": "json",
73
+ "citizenPermissions": [
74
+ "profile:user.self:read",
75
+ "profile:user.self:write",
76
+ "profile:address.self:read",
77
+ "profile:address.self:write",
78
+ "profile:entitlement.self:read",
79
+ "profile:entitlement.self:write",
80
+ "profile:user:read"
81
+ ],
82
+ "publicServantPermissions": [
83
+ "urn:logto:scope:organizations",
84
+ "urn:logto:scope:organization_roles",
85
+ "profile:user:*",
86
+ "profile:address:*",
87
+ "profile:entitlement:*"
88
+ ],
89
+ "updateDefinitions": true
90
+ }
91
+ ]
92
+ }
@@ -0,0 +1,22 @@
1
+ import { type Static } from "@sinclair/typebox";
2
+ export declare enum OpenAPIFileFormats {
3
+ JSON = "json",
4
+ YAML = "yaml"
5
+ }
6
+ declare const ConfigurationBuildingBlockSchema: import("@sinclair/typebox").TObject<{
7
+ name: import("@sinclair/typebox").TString;
8
+ openApiDefinitionUrl: import("@sinclair/typebox").TString;
9
+ openApiDefinitionFormat: import("@sinclair/typebox").TEnum<typeof OpenAPIFileFormats>;
10
+ citizenPermissions: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
11
+ publicServantPermissions: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
12
+ updateDefinitions: import("@sinclair/typebox").TBoolean;
13
+ }>;
14
+ export type ConfigurationBuildingBlock = Static<typeof ConfigurationBuildingBlockSchema>;
15
+ type ConfigurationFile = {
16
+ buildingBlocks: {
17
+ [x: string]: ConfigurationBuildingBlock;
18
+ };
19
+ };
20
+ export declare function readConfigurationFile(configurationFilePath: string): Promise<ConfigurationFile>;
21
+ export {};
22
+ //# sourceMappingURL=read-configuration-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-configuration-file.d.ts","sourceRoot":"","sources":["../../src/clients-configurations/read-configuration-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,mBAAmB,CAAC;AAGtD,oBAAY,kBAAkB;IAC5B,IAAI,SAAS;IACb,IAAI,SAAS;CACd;AAED,QAAA,MAAM,gCAAgC;;;;;;;EAOpC,CAAC;AAEH,MAAM,MAAM,0BAA0B,GAAG,MAAM,CAC7C,OAAO,gCAAgC,CACxC,CAAC;AAMF,KAAK,iBAAiB,GAAG;IACvB,cAAc,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,0BAA0B,CAAA;KAAE,CAAC;CAC7D,CAAC;AAcF,wBAAsB,qBAAqB,CACzC,qBAAqB,EAAE,MAAM,GAC5B,OAAO,CAAC,iBAAiB,CAAC,CAwB5B"}
@@ -0,0 +1,47 @@
1
+ import { Type } from "@sinclair/typebox";
2
+ import { Value } from "@sinclair/typebox/value";
3
+ export var OpenAPIFileFormats;
4
+ (function (OpenAPIFileFormats) {
5
+ OpenAPIFileFormats["JSON"] = "json";
6
+ OpenAPIFileFormats["YAML"] = "yaml";
7
+ })(OpenAPIFileFormats || (OpenAPIFileFormats = {}));
8
+ const ConfigurationBuildingBlockSchema = Type.Object({
9
+ name: Type.String(),
10
+ openApiDefinitionUrl: Type.String(),
11
+ openApiDefinitionFormat: Type.Enum(OpenAPIFileFormats),
12
+ citizenPermissions: Type.Array(Type.String(), { default: [] }),
13
+ publicServantPermissions: Type.Array(Type.String(), { default: [] }),
14
+ updateDefinitions: Type.Boolean({ default: true }),
15
+ });
16
+ const InputFileSchema = Type.Object({
17
+ buildingBlocks: Type.Array(ConfigurationBuildingBlockSchema),
18
+ });
19
+ function ensureBuildingBlockNameIsValid(bbName) {
20
+ // The building block name must only contain letters
21
+ // so its name can be used to get it using dot notation
22
+ // in code. E.g. sdkClient.messaging, where messaging
23
+ // is the name of the BB
24
+ const regex = /^[a-zA-Z]+$/g;
25
+ if (!regex.test(bbName))
26
+ throw new Error(`A building block name can only contain letters, ${bbName} is not valid`);
27
+ }
28
+ export async function readConfigurationFile(configurationFilePath) {
29
+ const { default: rawConfigurationFile } = await import(configurationFilePath, {
30
+ assert: {
31
+ type: "json",
32
+ },
33
+ });
34
+ const parsedFile = Value.Parse(InputFileSchema, rawConfigurationFile);
35
+ // Why do not directly create an object where the service name
36
+ // is the key in the configuration file instead of an array?
37
+ // To avoid having unexpected behaviours on naming
38
+ // e.g. Adding a "messaging-api" entry could return
39
+ // "messagingApi" when parsing
40
+ const outputFile = { buildingBlocks: {} };
41
+ for (const parsedBlock of parsedFile.buildingBlocks) {
42
+ ensureBuildingBlockNameIsValid(parsedBlock.name);
43
+ outputFile.buildingBlocks[parsedBlock.name] = parsedBlock;
44
+ }
45
+ return outputFile;
46
+ }
47
+ //# sourceMappingURL=read-configuration-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-configuration-file.js","sourceRoot":"","sources":["../../src/clients-configurations/read-configuration-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,mCAAa,CAAA;IACb,mCAAa,CAAA;AACf,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B;AAED,MAAM,gCAAgC,GAAG,IAAI,CAAC,MAAM,CAAC;IACnD,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;IACnB,oBAAoB,EAAE,IAAI,CAAC,MAAM,EAAE;IACnC,uBAAuB,EAAE,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC;IACtD,kBAAkB,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAC9D,wBAAwB,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACpE,iBAAiB,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;CACnD,CAAC,CAAC;AAMH,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC;IAClC,cAAc,EAAE,IAAI,CAAC,KAAK,CAAC,gCAAgC,CAAC;CAC7D,CAAC,CAAC;AAMH,SAAS,8BAA8B,CAAC,MAAc;IACpD,oDAAoD;IACpD,uDAAuD;IACvD,qDAAqD;IACrD,wBAAwB;IACxB,MAAM,KAAK,GAAG,cAAc,CAAC;IAC7B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,mDAAmD,MAAM,eAAe,CACzE,CAAC;AACN,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,qBAA6B;IAE7B,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,MAAM,CACpD,qBAAqB,EACrB;QACE,MAAM,EAAE;YACN,IAAI,EAAE,MAAM;SACb;KACF,CACF,CAAC;IAEF,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,eAAe,EAAE,oBAAoB,CAAC,CAAC;IAEtE,8DAA8D;IAC9D,4DAA4D;IAC5D,kDAAkD;IAClD,mDAAmD;IACnD,8BAA8B;IAC9B,MAAM,UAAU,GAAsB,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC;IAC7D,KAAK,MAAM,WAAW,IAAI,UAAU,CAAC,cAAc,EAAE,CAAC;QACpD,8BAA8B,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACjD,UAAU,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC;IAC5D,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export type { BuildingBlocksSDK } from "./types/index.js";
2
+ export { default as getM2MTokenFn } from "./client/auth/index.js";
3
+ import type { BuildingBlockSDKParams, BuildingBlocksSDK } from "./types/index.js";
4
+ declare const getBuildingBlockSDK: (params: BuildingBlockSDKParams) => BuildingBlocksSDK;
5
+ export default getBuildingBlockSDK;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,KAAK,EACV,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;AAE1B,QAAA,MAAM,mBAAmB,WACf,sBAAsB,KAC7B,iBAwBF,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,33 @@
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
+ export { default as getM2MTokenFn } from "./client/auth/index.js";
7
+ const getBuildingBlockSDK = (params) => {
8
+ const { services, getTokenFn } = params;
9
+ return {
10
+ messaging: new Messaging({
11
+ ...services.messaging,
12
+ getTokenFn,
13
+ }),
14
+ payments: new Payments({
15
+ ...services.payments,
16
+ getTokenFn,
17
+ }),
18
+ profile: new Profile({
19
+ ...services.payments,
20
+ getTokenFn,
21
+ }),
22
+ scheduler: new Scheduler({
23
+ ...services.scheduler,
24
+ getTokenFn,
25
+ }),
26
+ upload: new Upload({
27
+ ...services.upload,
28
+ getTokenFn,
29
+ }),
30
+ };
31
+ };
32
+ export default getBuildingBlockSDK;
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,qCAAqC,CAAC;AAC5D,OAAO,QAAQ,MAAM,oCAAoC,CAAC;AAC1D,OAAO,OAAO,MAAM,mCAAmC,CAAC;AACxD,OAAO,SAAS,MAAM,qCAAqC,CAAC;AAC5D,OAAO,MAAM,MAAM,kCAAkC,CAAC;AAGtD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAOlE,MAAM,mBAAmB,GAAG,CAC1B,MAA8B,EACX,EAAE;IACrB,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IACxC,OAAO;QACL,SAAS,EAAE,IAAI,SAAS,CAAC;YACvB,GAAG,QAAQ,CAAC,SAAS;YACrB,UAAU;SACX,CAAC;QACF,QAAQ,EAAE,IAAI,QAAQ,CAAC;YACrB,GAAG,QAAQ,CAAC,QAAQ;YACpB,UAAU;SACX,CAAC;QACF,OAAO,EAAE,IAAI,OAAO,CAAC;YACnB,GAAG,QAAQ,CAAC,QAAQ;YACpB,UAAU;SACX,CAAC;QACF,SAAS,EAAE,IAAI,SAAS,CAAC;YACvB,GAAG,QAAQ,CAAC,SAAS;YACrB,UAAU;SACX,CAAC;QACF,MAAM,EAAE,IAAI,MAAM,CAAC;YACjB,GAAG,QAAQ,CAAC,MAAM;YAClB,UAAU;SACX,CAAC;KACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,63 @@
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
+ export declare const MESSAGING: "messaging";
7
+ export declare const PAYMENTS: "payments";
8
+ export declare const PROFILE: "profile";
9
+ export declare const SCHEDULER: "scheduler";
10
+ export declare const UPLOAD: "upload";
11
+ export type SERVICE_NAME = typeof MESSAGING | typeof PAYMENTS | typeof PROFILE | typeof SCHEDULER | typeof UPLOAD;
12
+ export type TokenFunction = (serviceName: SERVICE_NAME) => Promise<string> | string;
13
+ export type M2MParams = {
14
+ getOrganizationTokenParams?: GetOrganizationTokenParams;
15
+ getAccessTokenParams?: GetAccessTokenParams;
16
+ };
17
+ export type M2MTokenFnConfig = {
18
+ services: {
19
+ [key in SERVICE_NAME]?: M2MParams;
20
+ };
21
+ };
22
+ export type SDKClientParams = {
23
+ baseUrl?: string;
24
+ };
25
+ export type ApiClientParams = SDKClientParams & {
26
+ getTokenFn?: TokenFunction;
27
+ };
28
+ type ServiceClients = {
29
+ messaging: Messaging;
30
+ payments: Payments;
31
+ profile: Profile;
32
+ scheduler: Scheduler;
33
+ upload: Upload;
34
+ };
35
+ export type BuildingBlocksSDK = {
36
+ [key in keyof ServiceClients]: ServiceClients[key];
37
+ };
38
+ export type BuildingBlockSDKParams = {
39
+ services: {
40
+ [key in keyof ServiceClients]?: SDKClientParams;
41
+ };
42
+ getTokenFn?: TokenFunction;
43
+ };
44
+ export interface TokenResponseBody {
45
+ access_token: string;
46
+ expires_in: number;
47
+ token_type: string;
48
+ scope: string;
49
+ }
50
+ interface GetTokenBaseParams {
51
+ logtoOidcEndpoint: string;
52
+ applicationId: string;
53
+ applicationSecret: string;
54
+ scopes?: string[];
55
+ }
56
+ export interface GetAccessTokenParams extends GetTokenBaseParams {
57
+ resource: string;
58
+ }
59
+ export interface GetOrganizationTokenParams extends GetTokenBaseParams {
60
+ organizationId: string;
61
+ }
62
+ export {};
63
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,sCAAsC,CAAC;AAClE,OAAO,KAAK,QAAQ,MAAM,qCAAqC,CAAC;AAChE,OAAO,KAAK,OAAO,MAAM,oCAAoC,CAAC;AAC9D,OAAO,KAAK,SAAS,MAAM,sCAAsC,CAAC;AAClE,OAAO,KAAK,MAAM,MAAM,mCAAmC,CAAC;AAE5D,eAAO,MAAM,SAAS,aAAuB,CAAC;AAC9C,eAAO,MAAM,QAAQ,YAAsB,CAAC;AAC5C,eAAO,MAAM,OAAO,WAAqB,CAAC;AAC1C,eAAO,MAAM,SAAS,aAAuB,CAAC;AAC9C,eAAO,MAAM,MAAM,UAAoB,CAAC;AAExC,MAAM,MAAM,YAAY,GACpB,OAAO,SAAS,GAChB,OAAO,QAAQ,GACf,OAAO,OAAO,GACd,OAAO,SAAS,GAChB,OAAO,MAAM,CAAC;AAElB,MAAM,MAAM,aAAa,GAAG,CAC1B,WAAW,EAAE,YAAY,KACtB,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;AAE9B,MAAM,MAAM,SAAS,GAAG;IACtB,0BAA0B,CAAC,EAAE,0BAA0B,CAAC;IACxD,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE;SACP,GAAG,IAAI,YAAY,CAAC,CAAC,EAAE,SAAS;KAClC,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,eAAe,GAAG;IAC9C,UAAU,CAAC,EAAE,aAAa,CAAC;CAC5B,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;KAC7B,GAAG,IAAI,MAAM,cAAc,GAAG,cAAc,CAAC,GAAG,CAAC;CACnD,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,EAAE;SACP,GAAG,IAAI,MAAM,cAAc,CAAC,CAAC,EAAE,eAAe;KAChD,CAAC;IACF,UAAU,CAAC,EAAE,aAAa,CAAC;CAC5B,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,kBAAkB;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAC9D,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,0BAA2B,SAAQ,kBAAkB;IACpE,cAAc,EAAE,MAAM,CAAC;CACxB"}
@@ -0,0 +1,6 @@
1
+ export const MESSAGING = "messaging";
2
+ export const PAYMENTS = "payments";
3
+ export const PROFILE = "profile";
4
+ export const SCHEDULER = "scheduler";
5
+ export const UPLOAD = "upload";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,SAAS,GAAG,WAAoB,CAAC;AAC9C,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAmB,CAAC;AAC5C,MAAM,CAAC,MAAM,OAAO,GAAG,SAAkB,CAAC;AAC1C,MAAM,CAAC,MAAM,SAAS,GAAG,WAAoB,CAAC;AAC9C,MAAM,CAAC,MAAM,MAAM,GAAG,QAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare function getAbsolutePath(...relativeInputPath: string[]): string;
2
+ export default getAbsolutePath;
3
+ //# sourceMappingURL=get-absolute-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-absolute-path.d.ts","sourceRoot":"","sources":["../../src/utils/get-absolute-path.ts"],"names":[],"mappings":"AAKA,iBAAS,eAAe,CAAC,GAAG,iBAAiB,EAAE,MAAM,EAAE,GAAG,MAAM,CAE/D;AAED,eAAe,eAAe,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { dirname, resolve } from "path";
2
+ import { fileURLToPath } from "url";
3
+ const __dirname = dirname(fileURLToPath(import.meta.url));
4
+ function getAbsolutePath(...relativeInputPath) {
5
+ return resolve(__dirname, "..", "..", ...relativeInputPath);
6
+ }
7
+ export default getAbsolutePath;
8
+ //# sourceMappingURL=get-absolute-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-absolute-path.js","sourceRoot":"","sources":["../../src/utils/get-absolute-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1D,SAAS,eAAe,CAAC,GAAG,iBAA2B;IACrD,OAAO,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,iBAAiB,CAAC,CAAC;AAC9D,CAAC;AAED,eAAe,eAAe,CAAC"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@ogcio/building-blocks-sdk",
3
+ "version": "0.0.1",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "type": "module",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "build": "rm -rf dist && tsc -p tsconfig.prod.json",
10
+ "clients:update": "node --import=tsx src/cli/index.ts clients:update -c src/clients-configurations/clients-configuration.json",
11
+ "clients:outdated": "node --import=tsx src/cli/index.ts clients:outdated -c src/clients-configurations/clients-configuration.json"
12
+ },
13
+ "dependencies": {
14
+ "@sinclair/typebox": "^0.33.15",
15
+ "commander": "^12.1.0",
16
+ "http-errors": "^2.0.0",
17
+ "openapi-fetch": "^0.12.2",
18
+ "openapi-typescript": "^7.4.1",
19
+ "openapi-typescript-helpers": "^0.0.13",
20
+ "safe-stable-stringify": "^2.5.0",
21
+ "yaml": "^2.5.1"
22
+ },
23
+ "devDependencies": {
24
+ "@biomejs/biome": "1.9.3",
25
+ "@commitlint/config-conventional": "^19.5.0",
26
+ "@types/http-errors": "^2.0.4",
27
+ "commitlint": "^19.5.0",
28
+ "husky": "^9.1.6",
29
+ "tsx": "^4.19.1",
30
+ "typescript": "^5.6.3"
31
+ },
32
+ "peerDependencies": {
33
+ "@logto/node": "^2.5.8"
34
+ },
35
+ "peerDependenciesMeta": {
36
+ "@logto/node": {
37
+ "optional": true
38
+ }
39
+ },
40
+ "keywords": [],
41
+ "author": "",
42
+ "license": "ISC",
43
+ "description": ""
44
+ }
@@ -0,0 +1,25 @@
1
+ import fs from "node:fs";
2
+
3
+ export const CLIENTS_ROOT_FOLDER_PATH = "src/client/clients";
4
+ export const OPEN_API_DEFINITION_FILE_NAME = "open-api-definition.json";
5
+ export const OLD_OPEN_API_DEFINITION_FILE_NAME = "old-open-api-definition.json";
6
+ export const SCHEMA_FILE_NAME = "schema.ts";
7
+ export const OLD_SCHEMA_FILE_NAME = "old-schema.ts";
8
+
9
+ export async function getOpenApiDefinitionFileContent(
10
+ filePath: string,
11
+ ): Promise<string> {
12
+ if (fs.existsSync(filePath)) {
13
+ return fs.readFileSync(filePath, "utf-8");
14
+ }
15
+
16
+ try {
17
+ const url = new URL(filePath);
18
+ const response = await fetch(url);
19
+ return response.text();
20
+ } catch {}
21
+
22
+ throw new Error(
23
+ `The configuration-file-path is not a valid file path nor url, or it is not reachable: ${filePath}`,
24
+ );
25
+ }
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ import { program } from "commander";
3
+ import outdatedClientsCommand from "./outdated-clients-command.js";
4
+ import updateClientsCommand from "./update-clients-command.js";
5
+
6
+ program
7
+ .name("building-blocks-cli")
8
+ .description("CLI with tools for managing the building blocks SDK")
9
+ .version("0.0.1")
10
+ .addCommand(updateClientsCommand)
11
+ .addCommand(outdatedClientsCommand);
12
+
13
+ program.parseAsync(process.argv);
@@ -0,0 +1,148 @@
1
+ import fs from "node:fs";
2
+ import { Command } from "commander";
3
+ import { stringify as stableStringify } from "safe-stable-stringify";
4
+ import { parse } from "yaml";
5
+ import {
6
+ type ConfigurationBuildingBlock,
7
+ OpenAPIFileFormats,
8
+ readConfigurationFile,
9
+ } from "../clients-configurations/read-configuration-file.js";
10
+ import getAbsolutePath from "../utils/get-absolute-path.js";
11
+ import {
12
+ CLIENTS_ROOT_FOLDER_PATH,
13
+ OPEN_API_DEFINITION_FILE_NAME,
14
+ getOpenApiDefinitionFileContent,
15
+ } from "./cli-utils.js";
16
+
17
+ /**
18
+ * This command, starting from a json configuration file,
19
+ * downloads the open-API definition file,
20
+ * parse it and compare it with the already existent one
21
+ */
22
+
23
+ function stringify(input: unknown): string {
24
+ stableStringify.configure({ deterministic: true });
25
+
26
+ const stringified = stableStringify(input);
27
+ if (!stringified) {
28
+ throw new Error("Invalid item to stringify!");
29
+ }
30
+
31
+ return stringified;
32
+ }
33
+
34
+ async function getLatestDefinitionFileContent({
35
+ inputBuildingBlock,
36
+ }: {
37
+ inputBuildingBlock: ConfigurationBuildingBlock;
38
+ }): Promise<string> {
39
+ log(`${inputBuildingBlock.name} - Downloading Open API definition file`);
40
+ const downloadedFileContent = await getOpenApiDefinitionFileContent(
41
+ inputBuildingBlock.openApiDefinitionUrl,
42
+ );
43
+ log(`${inputBuildingBlock.name} - Open API definition file downloaded`);
44
+ const openApiParsed =
45
+ inputBuildingBlock.openApiDefinitionFormat === OpenAPIFileFormats.JSON
46
+ ? JSON.parse(downloadedFileContent)
47
+ : parse(downloadedFileContent);
48
+ log(`${inputBuildingBlock.name} - Open API definition file parsed`);
49
+ return stringify(openApiParsed);
50
+ }
51
+
52
+ async function isBuildingBlockOutdated({
53
+ inputBuildingBlock,
54
+ }: {
55
+ inputBuildingBlock: ConfigurationBuildingBlock;
56
+ }): Promise<{ name: string; isOutdated: boolean }> {
57
+ if (inputBuildingBlock.updateDefinitions === false) {
58
+ log(`${inputBuildingBlock.name} - Update definition is disabled, ignoring`);
59
+ return { name: inputBuildingBlock.name, isOutdated: false };
60
+ }
61
+ log(`${inputBuildingBlock.name} - Processing`);
62
+ try {
63
+ const latestDefinition = await getLatestDefinitionFileContent({
64
+ inputBuildingBlock,
65
+ });
66
+
67
+ const serviceFolderPath = getAbsolutePath(
68
+ CLIENTS_ROOT_FOLDER_PATH,
69
+ inputBuildingBlock.name,
70
+ );
71
+ const definitionFilePath = getAbsolutePath(
72
+ serviceFolderPath,
73
+ OPEN_API_DEFINITION_FILE_NAME,
74
+ );
75
+
76
+ if (
77
+ !fs.existsSync(serviceFolderPath) ||
78
+ !fs.existsSync(definitionFilePath)
79
+ ) {
80
+ return { name: inputBuildingBlock.name, isOutdated: true };
81
+ }
82
+
83
+ const storedFile = fs.readFileSync(definitionFilePath, {
84
+ encoding: "utf-8",
85
+ });
86
+
87
+ const stringifiedStored = stringify(JSON.parse(storedFile));
88
+
89
+ const isOutdated = stringifiedStored !== latestDefinition;
90
+ log(
91
+ `${inputBuildingBlock.name} - Processed. Building Block is ${isOutdated ? "OUTDATED!" : "not outdated"}`,
92
+ );
93
+
94
+ return { name: inputBuildingBlock.name, isOutdated };
95
+ } catch (e) {
96
+ log(`${inputBuildingBlock.name} - Error While Processing`);
97
+ throw e;
98
+ }
99
+ }
100
+
101
+ function log(message: string, ...params: unknown[]): void {
102
+ if (params.length === 0) {
103
+ console.log(`Outdated Clients: ${message}`);
104
+ return;
105
+ }
106
+ console.log(`Outdated Clients: ${message}`, params);
107
+ }
108
+ async function checkClients({
109
+ configurationFilePath,
110
+ }: { configurationFilePath: string }): Promise<void> {
111
+ const configurationFile = await readConfigurationFile(configurationFilePath);
112
+ log("Configuration file read");
113
+
114
+ const promises: Promise<{ name: string; isOutdated: boolean }>[] = [];
115
+ for (const inputBuilding of Object.values(configurationFile.buildingBlocks)) {
116
+ promises.push(
117
+ isBuildingBlockOutdated({ inputBuildingBlock: inputBuilding }),
118
+ );
119
+ }
120
+
121
+ const bbStatuses = await Promise.all(promises);
122
+ const outdated = bbStatuses
123
+ .filter((bb) => bb.isOutdated === true)
124
+ .map((bb) => bb.name);
125
+ if (outdated.length) {
126
+ throw new Error(
127
+ `The following building blocks are outdated: ${outdated.join(", ")}`,
128
+ );
129
+ }
130
+
131
+ log("All the building blocks are updated!");
132
+ }
133
+ const outdatedClientsCommand = new Command("clients:outdated");
134
+ outdatedClientsCommand
135
+ .description(
136
+ "Parse a configuration file to check if the clients need to be updated",
137
+ )
138
+ .requiredOption(
139
+ "-c, --configuration-file-path <configuration-path>",
140
+ "Path of the configuration file to parse",
141
+ (value: string) => getAbsolutePath(value),
142
+ )
143
+ .action(async (options: { configurationFilePath: string }) => {
144
+ log("Started!");
145
+ await checkClients(options);
146
+ });
147
+
148
+ export default outdatedClientsCommand;