@ogcio/building-blocks-sdk 0.0.7 → 0.0.8

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.
@@ -0,0 +1,12 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "npm"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
7
+ time: "23:00" # UTC time
8
+ open-pull-requests-limit: 1
9
+ groups:
10
+ all-dependencies:
11
+ patterns:
12
+ - "*"
@@ -0,0 +1,2 @@
1
+ npm run check:formatting
2
+ npm run check:linting
package/README.md CHANGED
@@ -47,6 +47,8 @@ Access to building-blocks api is granted through access token in the `Authorizat
47
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
48
 
49
49
  ```typescript
50
+ import getBuildingBlockSDK from "@ogcio/building-blocks-sdk";
51
+
50
52
  const sdk = getBuildingBlockSDK({
51
53
  services: {
52
54
  upload: {
@@ -74,6 +76,8 @@ npm i @logto/node
74
76
  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
77
 
76
78
  ```typescript
79
+ import getBuildingBlockSDK, { getM2MTokenFn } from "@ogcio/building-blocks-sdk";
80
+
77
81
  const sdk = getBuildingBlockSDK({
78
82
  services: {
79
83
  upload: {
@@ -98,6 +102,8 @@ const sdk = getBuildingBlockSDK({
98
102
  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
103
 
100
104
  ```typescript
105
+ import getBuildingBlockSDK, { getM2MTokenFn } from "@ogcio/building-blocks-sdk";
106
+
101
107
  const sdk = getBuildingBlockSDK({
102
108
  services: {
103
109
  upload: {
@@ -128,8 +134,6 @@ This project is built with the latest Node LTS, clone this repository and instal
128
134
  npm install
129
135
  ```
130
136
 
131
- The code is formatted and linted with [biome](https://biomejs.dev/).
132
-
133
137
  The clients schemas are auto generated using open `openapi-typescript`.
134
138
 
135
139
  you can update the json configuration clients for each client under: `src/clients-configuration/clients-configuration.json`,
@@ -140,3 +144,21 @@ npm run clients:update
140
144
  ```
141
145
 
142
146
  to update the schemas. At this point you are ready to modify clients files and use the newly generated schemas
147
+
148
+ ### Formatting and linting
149
+
150
+ The code is formatted and linted with [biome](https://biomejs.dev/). If you use `VS Code` you can install the `biome` extension to get suggestions and auto-fix on save ( Ref: https://biomejs.dev/guides/editors/first-party-extensions/)
151
+
152
+ To check the formatting and linting errors run:
153
+
154
+ ```bash
155
+ npm run check:formatting
156
+ npm run check:linting
157
+ ```
158
+
159
+ To fix the formatting and linting errors run:
160
+
161
+ ```bash
162
+ npm run fix:formatting
163
+ npm run fix:linting
164
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ogcio/building-blocks-sdk",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -8,9 +8,15 @@
8
8
  "test": "echo \"Error: no test specified\" && exit 1",
9
9
  "build": "rm -rf dist && tsc -p tsconfig.prod.json",
10
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"
11
+ "clients:outdated": "node --import=tsx src/cli/index.ts clients:outdated -c src/clients-configurations/clients-configuration.json",
12
+ "check:formatting": "biome format",
13
+ "fix:formatting": "biome format --write",
14
+ "check:linting": "biome lint",
15
+ "fix:linting": "biome lint --write",
16
+ "prepare": "husky || true"
12
17
  },
13
18
  "dependencies": {
19
+ "@ogcio/analytics-sdk": "0.0.1-beta.1",
14
20
  "@sinclair/typebox": "^0.33.15",
15
21
  "commander": "^12.1.0",
16
22
  "http-errors": "^2.0.0",
@@ -89,7 +89,9 @@ const importUserScopes = async () => {
89
89
  }
90
90
  };
91
91
 
92
- const getM2MTokenFn = (m2mTokenConfig: M2MTokenFnConfig): TokenFunction => {
92
+ export const getM2MTokenFn = (
93
+ m2mTokenConfig: M2MTokenFnConfig,
94
+ ): TokenFunction => {
93
95
  const { services } = m2mTokenConfig;
94
96
 
95
97
  const tokenFn = (serviceName: SERVICE_NAME) => {
@@ -127,5 +129,3 @@ const getM2MTokenFn = (m2mTokenConfig: M2MTokenFnConfig): TokenFunction => {
127
129
  };
128
130
  return tokenFn;
129
131
  };
130
-
131
- export default getM2MTokenFn;
@@ -3,7 +3,7 @@ import createClient, {
3
3
  type FetchResponse,
4
4
  } from "openapi-fetch";
5
5
  import type {
6
- ApiClientParams,
6
+ BaseApiClientParams,
7
7
  SERVICE_NAME,
8
8
  TokenFunction,
9
9
  } from "../types/index.js";
@@ -19,7 +19,7 @@ abstract class BaseClient<T extends {}> {
19
19
 
20
20
  protected client: ReturnType<typeof createClient<T>>;
21
21
 
22
- constructor({ baseUrl, getTokenFn }: ApiClientParams) {
22
+ constructor({ baseUrl, getTokenFn }: BaseApiClientParams) {
23
23
  this.initialized = false;
24
24
  if (baseUrl) {
25
25
  this.baseUrl = baseUrl;
@@ -48,6 +48,10 @@ abstract class BaseClient<T extends {}> {
48
48
  this.client.use(authMiddleware);
49
49
  }
50
50
 
51
+ public deleteToken() {
52
+ this.token = undefined;
53
+ }
54
+
51
55
  protected async getToken() {
52
56
  if (this.getTokenFn) {
53
57
  const token = await this.getTokenFn(this.serviceName as SERVICE_NAME);
@@ -10,7 +10,7 @@ import {
10
10
  import type { paths } from "./schema.js";
11
11
 
12
12
  class Messaging extends BaseClient<paths> {
13
- declare client: ReturnType<typeof createClient<paths>>;
13
+ protected declare client: ReturnType<typeof createClient<paths>>;
14
14
  protected serviceName = MESSAGING;
15
15
 
16
16
  async getMessagesForUser(
@@ -4,7 +4,7 @@ import BaseClient from "../../base-client.js";
4
4
  import type { paths } from "./schema.js";
5
5
 
6
6
  class Payments extends BaseClient<paths> {
7
- declare client: ReturnType<typeof createClient<paths>>;
7
+ protected declare client: ReturnType<typeof createClient<paths>>;
8
8
  protected serviceName = PAYMENTS;
9
9
 
10
10
  /**
@@ -344,6 +344,23 @@ class Payments extends BaseClient<paths> {
344
344
  (reason) => this.formatError(reason),
345
345
  );
346
346
  }
347
+
348
+ async getRedirectToken(
349
+ transactionId: paths["/api/v1/transactions/{transactionId}/token"]["get"]["parameters"]["path"]["transactionId"],
350
+ ) {
351
+ return this.client
352
+ .GET("/api/v1/transactions/{transactionId}/token", {
353
+ params: {
354
+ path: {
355
+ transactionId,
356
+ },
357
+ },
358
+ })
359
+ .then(
360
+ (response) => this.formatResponse(response),
361
+ (reason) => this.formatError(reason),
362
+ );
363
+ }
347
364
  }
348
365
 
349
366
  export default Payments;
@@ -4,7 +4,7 @@ import BaseClient from "../../base-client.js";
4
4
  import type { paths } from "./schema.js";
5
5
 
6
6
  class Profile extends BaseClient<paths> {
7
- declare client: ReturnType<typeof createClient<paths>>;
7
+ protected declare client: ReturnType<typeof createClient<paths>>;
8
8
  protected serviceName = PROFILE;
9
9
 
10
10
  async getAddresses() {
@@ -4,7 +4,7 @@ import BaseClient from "../../base-client.js";
4
4
  import type { paths } from "./schema.js";
5
5
 
6
6
  class Scheduler extends BaseClient<paths> {
7
- declare client: ReturnType<typeof createClient<paths>>;
7
+ protected declare client: ReturnType<typeof createClient<paths>>;
8
8
  protected serviceName = SCHEDULER;
9
9
 
10
10
  async scheduleTasks(
@@ -4,15 +4,22 @@ import BaseClient from "../../base-client.js";
4
4
  import type { paths } from "./schema.js";
5
5
 
6
6
  class Upload extends BaseClient<paths> {
7
- declare client: ReturnType<typeof createClient<paths>>;
7
+ protected declare client: ReturnType<typeof createClient<paths>>;
8
8
  protected serviceName = UPLOAD;
9
9
 
10
- getFilesMetadata(organizationId: string) {
10
+ getFilesMetadata({
11
+ organizationId,
12
+ userId,
13
+ }: {
14
+ organizationId?: string;
15
+ userId?: string;
16
+ }) {
11
17
  return this.client
12
18
  .GET("/api/v1/metadata/", {
13
19
  params: {
14
20
  query: {
15
21
  organizationId,
22
+ userId,
16
23
  },
17
24
  },
18
25
  })
@@ -22,28 +29,6 @@ class Upload extends BaseClient<paths> {
22
29
  );
23
30
  }
24
31
 
25
- shareFile(fileId: string, userId: string) {
26
- return this.client
27
- .POST("/api/v1/permissions/", {
28
- body: { fileId, userId },
29
- })
30
- .then(
31
- (response) => this.formatResponse(response),
32
- (reason) => this.formatError(reason),
33
- );
34
- }
35
-
36
- removeFileSharing(fileId: string, userId: string) {
37
- return this.client
38
- .DELETE("/api/v1/permissions/", {
39
- body: { fileId, userId },
40
- })
41
- .then(
42
- (response) => this.formatResponse(response),
43
- (reason) => this.formatError(reason),
44
- );
45
- }
46
-
47
32
  async getFile(id: string) {
48
33
  try {
49
34
  const {
@@ -104,6 +89,43 @@ class Upload extends BaseClient<paths> {
104
89
  );
105
90
  }
106
91
 
92
+ getFileSharings(id: string) {
93
+ return this.client
94
+ .GET("/api/v1/permissions/", {
95
+ params: {
96
+ query: {
97
+ fileId: id,
98
+ },
99
+ },
100
+ })
101
+ .then(
102
+ (response) => this.formatResponse(response),
103
+ (reason) => this.formatError(reason),
104
+ );
105
+ }
106
+
107
+ shareFile(fileId: string, userId: string) {
108
+ return this.client
109
+ .POST("/api/v1/permissions/", {
110
+ body: { fileId, userId },
111
+ })
112
+ .then(
113
+ (response) => this.formatResponse(response),
114
+ (reason) => this.formatError(reason),
115
+ );
116
+ }
117
+
118
+ removeFileSharing(fileId: string, userId: string) {
119
+ return this.client
120
+ .DELETE("/api/v1/permissions/", {
121
+ body: { fileId, userId },
122
+ })
123
+ .then(
124
+ (response) => this.formatResponse(response),
125
+ (reason) => this.formatError(reason),
126
+ );
127
+ }
128
+
107
129
  async uploadFile(file: File, expirationDate?: string) {
108
130
  const { error } = await this.client.POST("/api/v1/files/", {
109
131
  body: {
@@ -1,5 +1,13 @@
1
1
  {
2
2
  "buildingBlocks": [
3
+ {
4
+ "name": "analytics",
5
+ "openApiDefinitionUrl": "",
6
+ "openApiDefinitionFormat": "yaml",
7
+ "updateDefinitions": false,
8
+ "citizenPermissions": [],
9
+ "publicServantPermissions": []
10
+ },
3
11
  {
4
12
  "name": "messaging",
5
13
  "openApiDefinitionUrl": "https://raw.githubusercontent.com/ogcio/life-events/refs/heads/dev/apps/messaging-api/openapi-definition.yml",
package/src/index.ts CHANGED
@@ -1,15 +1,17 @@
1
+ import { Analytics } from "@ogcio/analytics-sdk";
2
+
1
3
  import Messaging from "./client/clients/messaging/index.js";
2
4
  import Payments from "./client/clients/payments/index.js";
3
5
  import Profile from "./client/clients/profile/index.js";
4
6
  import Scheduler from "./client/clients/scheduler/index.js";
5
7
  import Upload from "./client/clients/upload/index.js";
6
-
7
8
  export type { BuildingBlocksSDK } from "./types/index.js";
8
- export { default as getM2MTokenFn } from "./client/auth/index.js";
9
+ export { getM2MTokenFn } from "./client/auth/index.js";
9
10
 
10
11
  import type {
11
12
  BuildingBlockSDKParams,
12
13
  BuildingBlocksSDK,
14
+ TokenFunction,
13
15
  } from "./types/index.js";
14
16
 
15
17
  const getBuildingBlockSDK = (
@@ -17,6 +19,10 @@ const getBuildingBlockSDK = (
17
19
  ): BuildingBlocksSDK => {
18
20
  const { services, getTokenFn } = params;
19
21
  return {
22
+ analytics: new Analytics({
23
+ ...services.analytics,
24
+ getTokenFn,
25
+ }),
20
26
  messaging: new Messaging({
21
27
  ...services.messaging,
22
28
  getTokenFn,
@@ -26,7 +32,7 @@ const getBuildingBlockSDK = (
26
32
  getTokenFn,
27
33
  }),
28
34
  profile: new Profile({
29
- ...services.payments,
35
+ ...services.profile,
30
36
  getTokenFn,
31
37
  }),
32
38
  scheduler: new Scheduler({
@@ -1,9 +1,11 @@
1
+ import type { Analytics } from "@ogcio/analytics-sdk";
1
2
  import type Messaging from "../client/clients/messaging/index.js";
2
3
  import type Payments from "../client/clients/payments/index.js";
3
4
  import type Profile from "../client/clients/profile/index.js";
4
5
  import type Scheduler from "../client/clients/scheduler/index.js";
5
6
  import type Upload from "../client/clients/upload/index.js";
6
7
 
8
+ export const ANALYTICS = "analytics" as const;
7
9
  export const MESSAGING = "messaging" as const;
8
10
  export const PAYMENTS = "payments" as const;
9
11
  export const PROFILE = "profile" as const;
@@ -11,6 +13,7 @@ export const SCHEDULER = "scheduler" as const;
11
13
  export const UPLOAD = "upload" as const;
12
14
 
13
15
  export type SERVICE_NAME =
16
+ | typeof ANALYTICS
14
17
  | typeof MESSAGING
15
18
  | typeof PAYMENTS
16
19
  | typeof PROFILE
@@ -36,25 +39,28 @@ export type SDKClientParams = {
36
39
  baseUrl?: string;
37
40
  };
38
41
 
39
- export type ApiClientParams = SDKClientParams & {
42
+ export type BaseApiClientParams = SDKClientParams & {
40
43
  getTokenFn?: TokenFunction;
41
44
  };
42
45
 
43
46
  type ServiceClients = {
44
- messaging: Messaging;
45
- payments: Payments;
46
- profile: Profile;
47
- scheduler: Scheduler;
48
- upload: Upload;
47
+ analytics: typeof Analytics;
48
+ messaging: typeof Messaging;
49
+ payments: typeof Payments;
50
+ profile: typeof Profile;
51
+ scheduler: typeof Scheduler;
52
+ upload: typeof Upload;
49
53
  };
50
54
 
51
55
  export type BuildingBlocksSDK = {
52
- [key in keyof ServiceClients]: ServiceClients[key];
56
+ [key in keyof ServiceClients]: InstanceType<ServiceClients[key]>;
53
57
  };
54
58
 
55
59
  export type BuildingBlockSDKParams = {
56
60
  services: {
57
- [key in keyof ServiceClients]?: SDKClientParams;
61
+ [key in keyof ServiceClients]?: ConstructorParameters<
62
+ ServiceClients[key]
63
+ >[0];
58
64
  };
59
65
  getTokenFn?: TokenFunction;
60
66
  };