@ogcio/building-blocks-sdk 0.0.1 → 0.0.2

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/README.md ADDED
@@ -0,0 +1,142 @@
1
+ # Building Blocks SDK - README
2
+
3
+ ## Overview
4
+
5
+ The Building Blocks SDK is the `TypeScript` client for integrating with the various building blocks within the OGCIO ecosystem. It helps developers interact different modules in a streamlined way, providing a unified API for seamless integration.
6
+
7
+ ## Features
8
+
9
+ - Proxy Client: Acts as a middleware to interact with various services via the SDK.
10
+ - Modular Design: Allows integration of different components (building blocks) to extend functionality as needed.
11
+ - Enables both authenticated and non-authenticated usage
12
+
13
+ ### Usage
14
+
15
+ Install the package via:
16
+
17
+ ```bash
18
+ npm install @ogcio/building-blocks-sdk
19
+ ```
20
+
21
+ SDK initialization:
22
+
23
+ ```typescript
24
+ const sdk = getBuildingBlockSDK({
25
+ services: {
26
+ upload: {
27
+ baseUrl: "http://localhost:8008",
28
+ },
29
+ },
30
+ });
31
+ ```
32
+
33
+ This snippet creates the SDK with configuration for the upload API building block. The SDK accepts a configuration for each building block API.
34
+
35
+ At the present time available building blocks are:
36
+
37
+ - payments
38
+ - messaging
39
+ - upload
40
+ - profile
41
+ - scheduler
42
+
43
+ ### Authentication
44
+
45
+ Access to building-blocks api is granted through access token in the `Authorization` header.
46
+
47
+ Users can pass the `getTokenFn` function to the SDK. The SDK client will call this function when it needs an access token. The SDK will provide the service name of the service for which it is requesting the token:
48
+
49
+ ```typescript
50
+ const sdk = getBuildingBlockSDK({
51
+ services: {
52
+ upload: {
53
+ baseUrl: "http://localhost:8008",
54
+ },
55
+ },
56
+ getTokenFn: async (serviceName: SERVICE_NAME) => {
57
+ if (serviceName === UPLOAD) {
58
+ return "TOKEN_FOR_UPLOAD";
59
+ }
60
+ },
61
+ });
62
+ ```
63
+
64
+ This approach allows users of this library to plug-in their preferred authentication mechanism as long as a string is returned by the `getTokenFn`.
65
+
66
+ ### M2M Authentication
67
+
68
+ In order to use the library in your server applications you can install the peer dependency `@logto/node` via:
69
+
70
+ ```bash
71
+ npm i @logto/node
72
+ ```
73
+
74
+ and use the `getM2MTokenFn` utility function. This function accepts the M2M configuration parameters for each of the building-blocks api and returns a `getTokenFn` compliant function that will handle Logto m2m retrieval for you:
75
+
76
+ ```typescript
77
+ const sdk = getBuildingBlockSDK({
78
+ services: {
79
+ upload: {
80
+ baseUrl: "http://localhost:8008",
81
+ },
82
+ },
83
+ getTokenFn: await getM2MTokenFn({
84
+ services: {
85
+ upload: {
86
+ getOrganizationTokenParams: {
87
+ applicationId: "APPLICATION_ID",
88
+ applicationSecret: "APPLICATION_SECRET",
89
+ logtoOidcEndpoint: "http://localhost:3301/oidc",
90
+ organizationId: "ogcio",
91
+ },
92
+ },
93
+ },
94
+ }),
95
+ });
96
+ ```
97
+
98
+ Using the m2m utility function like this will cause the SDK to request all the scopes available for the building-block, scopes can be overridden when passed as parameter:
99
+
100
+ ```typescript
101
+ const sdk = getBuildingBlockSDK({
102
+ services: {
103
+ upload: {
104
+ baseUrl: "http://localhost:8008",
105
+ },
106
+ },
107
+ getTokenFn: await getM2MTokenFn({
108
+ services: {
109
+ upload: {
110
+ getOrganizationTokenParams: {
111
+ applicationId: "APPLICATION_ID",
112
+ applicationSecret: "APPLICATION_SECRET",
113
+ logtoOidcEndpoint: "http://localhost:3301/oidc",
114
+ organizationId: "ogcio",
115
+ scopes: ["custom:role:1", "custom:role:2"],
116
+ },
117
+ },
118
+ },
119
+ }),
120
+ });
121
+ ```
122
+
123
+ ## Development
124
+
125
+ This project is built with the latest Node LTS, clone this repository and install the dependencies with:
126
+
127
+ ```bash
128
+ npm install
129
+ ```
130
+
131
+ The code is formatted and linted with [biome](https://biomejs.dev/).
132
+
133
+ The clients schemas are auto generated using open `openapi-typescript`.
134
+
135
+ you can update the json configuration clients for each client under: `src/clients-configuration/clients-configuration.json`,
136
+ then run:
137
+
138
+ ```bash
139
+ npm run clients:update
140
+ ```
141
+
142
+ to update the schemas. At this point you are ready to modify clients files and use the newly generated schemas
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ogcio/building-blocks-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -30,7 +30,7 @@
30
30
  "typescript": "^5.6.3"
31
31
  },
32
32
  "peerDependencies": {
33
- "@logto/node": "^2.5.8"
33
+ "@logto/node": "2.5.5"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@logto/node": {
@@ -68,9 +68,9 @@ const getOrganizationToken = async (
68
68
  const tokenResponse = await fetchToken({
69
69
  ...params,
70
70
  scopes: [
71
- ...scopesToUse,
72
71
  UserScope.OrganizationRoles,
73
72
  UserScope.Organizations,
73
+ ...scopesToUse,
74
74
  ],
75
75
  specificBodyFields: {
76
76
  organization_id: params.organizationId,
@@ -11,8 +11,6 @@
11
11
  "messaging:citizen.self:write"
12
12
  ],
13
13
  "publicServantPermissions": [
14
- "urn:logto:scope:organizations",
15
- "urn:logto:scope:organization_roles",
16
14
  "messaging:message:*",
17
15
  "messaging:provider:*",
18
16
  "messaging:template:*",
@@ -26,12 +24,7 @@
26
24
  "openApiDefinitionUrl": "https://raw.githubusercontent.com/ogcio/life-events/refs/heads/dev/apps/upload-api/openapi-definition.yml",
27
25
  "openApiDefinitionFormat": "yaml",
28
26
  "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
- ],
27
+ "publicServantPermissions": ["upload:file:*", "profile:user:read"],
35
28
  "updateDefinitions": true
36
29
  },
37
30
  {
@@ -45,8 +38,6 @@
45
38
  "payments:provider.public:read"
46
39
  ],
47
40
  "publicServantPermissions": [
48
- "urn:logto:scope:organizations",
49
- "urn:logto:scope:organization_roles",
50
41
  "payments:provider:*",
51
42
  "payments:payment_request:*",
52
43
  "payments:payment_request.public:read",
@@ -59,11 +50,7 @@
59
50
  "openApiDefinitionUrl": "https://raw.githubusercontent.com/ogcio/life-events/refs/heads/dev/apps/scheduler-api/openapi-definition.yml",
60
51
  "openApiDefinitionFormat": "yaml",
61
52
  "citizenPermissions": ["scheduler:jobs:write"],
62
- "publicServantPermissions": [
63
- "urn:logto:scope:organizations",
64
- "urn:logto:scope:organization_roles",
65
- "scheduler:jobs:write"
66
- ],
53
+ "publicServantPermissions": ["scheduler:jobs:write"],
67
54
  "updateDefinitions": true
68
55
  },
69
56
  {
@@ -80,8 +67,6 @@
80
67
  "profile:user:read"
81
68
  ],
82
69
  "publicServantPermissions": [
83
- "urn:logto:scope:organizations",
84
- "urn:logto:scope:organization_roles",
85
70
  "profile:user:*",
86
71
  "profile:address:*",
87
72
  "profile:entitlement:*"