@ogcio/building-blocks-sdk 0.0.26 → 0.1.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 (39) hide show
  1. package/README.md +11 -10
  2. package/dist/__tests__/client/clients/featureFlags/index.test.js +1 -1
  3. package/dist/__tests__/client/clients/featureFlags/index.test.js.map +1 -1
  4. package/dist/__tests__/index.test.d.ts +2 -0
  5. package/dist/__tests__/index.test.d.ts.map +1 -0
  6. package/dist/__tests__/index.test.js +174 -0
  7. package/dist/__tests__/index.test.js.map +1 -0
  8. package/dist/client/base-client.d.ts +5 -2
  9. package/dist/client/base-client.d.ts.map +1 -1
  10. package/dist/client/base-client.js +1 -1
  11. package/dist/client/base-client.js.map +1 -1
  12. package/dist/client/clients/featureFlags/index.d.ts +4 -2
  13. package/dist/client/clients/featureFlags/index.d.ts.map +1 -1
  14. package/dist/client/clients/featureFlags/index.js +1 -1
  15. package/dist/client/clients/featureFlags/index.js.map +1 -1
  16. package/dist/client/clients/payments/index.d.ts +3 -109
  17. package/dist/client/clients/payments/index.d.ts.map +1 -1
  18. package/dist/client/clients/payments/index.js +5 -13
  19. package/dist/client/clients/payments/index.js.map +1 -1
  20. package/dist/client/clients/payments/schema.d.ts +3 -109
  21. package/dist/client/clients/payments/schema.d.ts.map +1 -1
  22. package/dist/index.d.ts +4 -2
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +15 -29
  25. package/dist/index.js.map +1 -1
  26. package/dist/types/index.d.ts +63 -47
  27. package/dist/types/index.d.ts.map +1 -1
  28. package/dist/types/index.js +8 -7
  29. package/dist/types/index.js.map +1 -1
  30. package/package.json +3 -2
  31. package/src/__tests__/client/clients/featureFlags/index.test.ts +1 -1
  32. package/src/__tests__/index.test.ts +213 -0
  33. package/src/client/base-client.ts +9 -11
  34. package/src/client/clients/featureFlags/index.ts +8 -2
  35. package/src/client/clients/payments/index.ts +8 -23
  36. package/src/client/clients/payments/open-api-definition.json +3 -345
  37. package/src/client/clients/payments/schema.ts +3 -109
  38. package/src/index.ts +42 -32
  39. package/src/types/index.ts +97 -53
@@ -4052,7 +4052,7 @@
4052
4052
  }
4053
4053
  }
4054
4054
  },
4055
- "/api/v1/transactions/by-external-id/{extPaymentId}": {
4055
+ "/api/v1/transactions/transactionId/{extPaymentId}": {
4056
4056
  "get": {
4057
4057
  "tags": [
4058
4058
  "Transactions"
@@ -4078,121 +4078,12 @@
4078
4078
  "data": {
4079
4079
  "type": "object",
4080
4080
  "properties": {
4081
- "transactionId": {
4082
- "type": "string"
4083
- },
4084
- "status": {
4085
- "anyOf": [
4086
- {
4087
- "type": "string",
4088
- "enum": [
4089
- "initiated"
4090
- ]
4091
- },
4092
- {
4093
- "type": "string",
4094
- "enum": [
4095
- "pending"
4096
- ]
4097
- },
4098
- {
4099
- "type": "string",
4100
- "enum": [
4101
- "succeeded"
4102
- ]
4103
- },
4104
- {
4105
- "type": "string",
4106
- "enum": [
4107
- "cancelled"
4108
- ]
4109
- },
4110
- {
4111
- "type": "string",
4112
- "enum": [
4113
- "failed"
4114
- ]
4115
- }
4116
- ]
4117
- },
4118
- "amount": {
4119
- "minimum": 1,
4120
- "maximum": 1000000,
4121
- "type": "number"
4122
- },
4123
- "extPaymentId": {
4124
- "allOf": [
4125
- {
4126
- "type": "string"
4127
- },
4128
- {
4129
- "type": "string"
4130
- }
4131
- ]
4132
- },
4133
- "paymentProviderId": {
4134
- "type": "string"
4135
- },
4136
- "updatedAt": {
4137
- "type": "string"
4138
- },
4139
- "title": {
4140
- "type": "string"
4141
- },
4142
- "userId": {
4143
- "type": "string"
4144
- },
4145
- "metadata": {
4146
- "type": "object",
4147
- "properties": {
4148
- "name": {
4149
- "type": "string"
4150
- },
4151
- "email": {
4152
- "type": "string"
4153
- },
4154
- "runId": {
4155
- "type": "string"
4156
- },
4157
- "journeyId": {
4158
- "type": "string"
4159
- },
4160
- "journeyTitle": {
4161
- "type": "string"
4162
- }
4163
- },
4164
- "required": [
4165
- "name",
4166
- "email"
4167
- ]
4168
- },
4169
- "description": {
4170
- "type": "string"
4171
- },
4172
- "providerName": {
4173
- "type": "string"
4174
- },
4175
- "providerType": {
4176
- "type": "string"
4177
- },
4178
- "paymentRequestId": {
4081
+ "id": {
4179
4082
  "type": "string"
4180
4083
  }
4181
4084
  },
4182
4085
  "required": [
4183
- "transactionId",
4184
- "status",
4185
- "amount",
4186
- "extPaymentId",
4187
- "paymentProviderId",
4188
- "updatedAt",
4189
- "title",
4190
- "userId",
4191
- "metadata",
4192
- "description",
4193
- "providerName",
4194
- "providerType",
4195
- "paymentRequestId"
4086
+ "id"
4196
4087
  ]
4197
4088
  },
4198
4089
  "metadata": {
@@ -4316,239 +4207,6 @@
4316
4207
  }
4317
4208
  }
4318
4209
  }
4319
- },
4320
- "patch": {
4321
- "tags": [
4322
- "Transactions"
4323
- ],
4324
- "requestBody": {
4325
- "content": {
4326
- "application/json": {
4327
- "schema": {
4328
- "type": "object",
4329
- "properties": {
4330
- "status": {
4331
- "anyOf": [
4332
- {
4333
- "type": "string",
4334
- "enum": [
4335
- "initiated"
4336
- ]
4337
- },
4338
- {
4339
- "type": "string",
4340
- "enum": [
4341
- "pending"
4342
- ]
4343
- },
4344
- {
4345
- "type": "string",
4346
- "enum": [
4347
- "succeeded"
4348
- ]
4349
- },
4350
- {
4351
- "type": "string",
4352
- "enum": [
4353
- "cancelled"
4354
- ]
4355
- },
4356
- {
4357
- "type": "string",
4358
- "enum": [
4359
- "failed"
4360
- ]
4361
- }
4362
- ]
4363
- }
4364
- },
4365
- "required": [
4366
- "status"
4367
- ]
4368
- }
4369
- }
4370
- },
4371
- "required": true
4372
- },
4373
- "parameters": [
4374
- {
4375
- "schema": {
4376
- "type": "string"
4377
- },
4378
- "in": "path",
4379
- "name": "extPaymentId",
4380
- "required": true
4381
- }
4382
- ],
4383
- "responses": {
4384
- "200": {
4385
- "description": "Default Response",
4386
- "content": {
4387
- "application/json": {
4388
- "schema": {
4389
- "type": "object",
4390
- "properties": {
4391
- "data": {
4392
- "type": "object",
4393
- "properties": {
4394
- "transactionId": {
4395
- "type": "string"
4396
- },
4397
- "paymentRequestId": {
4398
- "type": "string"
4399
- },
4400
- "metadata": {
4401
- "type": "object",
4402
- "properties": {
4403
- "name": {
4404
- "type": "string"
4405
- },
4406
- "email": {
4407
- "type": "string"
4408
- },
4409
- "runId": {
4410
- "type": "string"
4411
- },
4412
- "journeyId": {
4413
- "type": "string"
4414
- },
4415
- "journeyTitle": {
4416
- "type": "string"
4417
- }
4418
- },
4419
- "required": [
4420
- "name",
4421
- "email"
4422
- ]
4423
- }
4424
- },
4425
- "required": [
4426
- "transactionId",
4427
- "paymentRequestId",
4428
- "metadata"
4429
- ]
4430
- },
4431
- "metadata": {
4432
- "type": "object",
4433
- "properties": {
4434
- "links": {
4435
- "description": "Object containing the links to the related endpoints",
4436
- "type": "object",
4437
- "properties": {
4438
- "self": {
4439
- "type": "object",
4440
- "properties": {
4441
- "href": {
4442
- "description": "URL pointing to the request itself",
4443
- "type": "string"
4444
- }
4445
- }
4446
- },
4447
- "next": {
4448
- "type": "object",
4449
- "properties": {
4450
- "href": {
4451
- "description": "URL pointing to the next page of results in a paginated response. If there are no more results, this field may be omitted",
4452
- "type": "string"
4453
- }
4454
- }
4455
- },
4456
- "prev": {
4457
- "type": "object",
4458
- "properties": {
4459
- "href": {
4460
- "description": "URL pointing to the previous page of results in a paginated response. If there are no more results, this field may be omitted",
4461
- "type": "string"
4462
- }
4463
- }
4464
- },
4465
- "first": {
4466
- "type": "object",
4467
- "properties": {
4468
- "href": {
4469
- "description": "URL pointing to the first page of results in a paginated response",
4470
- "type": "string"
4471
- }
4472
- }
4473
- },
4474
- "last": {
4475
- "type": "object",
4476
- "properties": {
4477
- "href": {
4478
- "description": "URL pointing to the first page of results in a paginated response",
4479
- "type": "string"
4480
- }
4481
- }
4482
- },
4483
- "pages": {
4484
- "description": "It may contain a list of other useful URLs, e.g. one entry for page:'page 1', 'page 2'",
4485
- "type": "object",
4486
- "additionalProperties": {
4487
- "type": "object",
4488
- "properties": {
4489
- "href": {
4490
- "type": "string"
4491
- }
4492
- }
4493
- }
4494
- }
4495
- },
4496
- "required": [
4497
- "self",
4498
- "first",
4499
- "last",
4500
- "pages"
4501
- ]
4502
- },
4503
- "totalCount": {
4504
- "description": "Number representing the total number of available items",
4505
- "type": "number"
4506
- }
4507
- }
4508
- }
4509
- },
4510
- "required": [
4511
- "data"
4512
- ]
4513
- }
4514
- }
4515
- }
4516
- },
4517
- "500": {
4518
- "description": "Default Response",
4519
- "content": {
4520
- "application/json": {
4521
- "schema": {
4522
- "type": "object",
4523
- "properties": {
4524
- "code": {
4525
- "type": "string"
4526
- },
4527
- "detail": {
4528
- "type": "string"
4529
- },
4530
- "requestId": {
4531
- "type": "string"
4532
- },
4533
- "name": {
4534
- "type": "string"
4535
- },
4536
- "validation": {},
4537
- "validationContext": {
4538
- "type": "string"
4539
- }
4540
- },
4541
- "required": [
4542
- "code",
4543
- "detail",
4544
- "requestId",
4545
- "name"
4546
- ]
4547
- }
4548
- }
4549
- }
4550
- }
4551
- }
4552
4210
  }
4553
4211
  },
4554
4212
  "/api/v1/transactions/": {
@@ -1632,7 +1632,7 @@ export interface paths {
1632
1632
  };
1633
1633
  trace?: never;
1634
1634
  };
1635
- "/api/v1/transactions/by-external-id/{extPaymentId}": {
1635
+ "/api/v1/transactions/transactionId/{extPaymentId}": {
1636
1636
  parameters: {
1637
1637
  query?: never;
1638
1638
  header?: never;
@@ -1658,25 +1658,7 @@ export interface paths {
1658
1658
  content: {
1659
1659
  "application/json": {
1660
1660
  data: {
1661
- transactionId: string;
1662
- status: "initiated" | "pending" | "succeeded" | "cancelled" | "failed";
1663
- amount: number;
1664
- extPaymentId: string;
1665
- paymentProviderId: string;
1666
- updatedAt: string;
1667
- title: string;
1668
- userId: string;
1669
- metadata: {
1670
- name: string;
1671
- email: string;
1672
- runId?: string;
1673
- journeyId?: string;
1674
- journeyTitle?: string;
1675
- };
1676
- description: string;
1677
- providerName: string;
1678
- providerType: string;
1679
- paymentRequestId: string;
1661
+ id: string;
1680
1662
  };
1681
1663
  metadata?: {
1682
1664
  /** @description Object containing the links to the related endpoints */
@@ -1737,95 +1719,7 @@ export interface paths {
1737
1719
  delete?: never;
1738
1720
  options?: never;
1739
1721
  head?: never;
1740
- patch: {
1741
- parameters: {
1742
- query?: never;
1743
- header?: never;
1744
- path: {
1745
- extPaymentId: string;
1746
- };
1747
- cookie?: never;
1748
- };
1749
- requestBody: {
1750
- content: {
1751
- "application/json": {
1752
- status: "initiated" | "pending" | "succeeded" | "cancelled" | "failed";
1753
- };
1754
- };
1755
- };
1756
- responses: {
1757
- /** @description Default Response */
1758
- 200: {
1759
- headers: {
1760
- [name: string]: unknown;
1761
- };
1762
- content: {
1763
- "application/json": {
1764
- data: {
1765
- transactionId: string;
1766
- paymentRequestId: string;
1767
- metadata: {
1768
- name: string;
1769
- email: string;
1770
- runId?: string;
1771
- journeyId?: string;
1772
- journeyTitle?: string;
1773
- };
1774
- };
1775
- metadata?: {
1776
- /** @description Object containing the links to the related endpoints */
1777
- links?: {
1778
- self: {
1779
- /** @description URL pointing to the request itself */
1780
- href?: string;
1781
- };
1782
- next?: {
1783
- /** @description URL pointing to the next page of results in a paginated response. If there are no more results, this field may be omitted */
1784
- href?: string;
1785
- };
1786
- prev?: {
1787
- /** @description URL pointing to the previous page of results in a paginated response. If there are no more results, this field may be omitted */
1788
- href?: string;
1789
- };
1790
- first: {
1791
- /** @description URL pointing to the first page of results in a paginated response */
1792
- href?: string;
1793
- };
1794
- last: {
1795
- /** @description URL pointing to the first page of results in a paginated response */
1796
- href?: string;
1797
- };
1798
- /** @description It may contain a list of other useful URLs, e.g. one entry for page:'page 1', 'page 2' */
1799
- pages: {
1800
- [key: string]: {
1801
- href?: string;
1802
- };
1803
- };
1804
- };
1805
- /** @description Number representing the total number of available items */
1806
- totalCount?: number;
1807
- };
1808
- };
1809
- };
1810
- };
1811
- /** @description Default Response */
1812
- 500: {
1813
- headers: {
1814
- [name: string]: unknown;
1815
- };
1816
- content: {
1817
- "application/json": {
1818
- code: string;
1819
- detail: string;
1820
- requestId: string;
1821
- name: string;
1822
- validation?: unknown;
1823
- validationContext?: string;
1824
- };
1825
- };
1826
- };
1827
- };
1828
- };
1722
+ patch?: never;
1829
1723
  trace?: never;
1830
1724
  };
1831
1725
  "/api/v1/transactions/": {
package/src/index.ts CHANGED
@@ -6,46 +6,56 @@ import { Payments } from "./client/clients/payments/index.js";
6
6
  import { Profile } from "./client/clients/profile/index.js";
7
7
  import { Scheduler } from "./client/clients/scheduler/index.js";
8
8
  import { Upload } from "./client/clients/upload/index.js";
9
- export type { BuildingBlocksSDK } from "./types/index.js";
10
9
  export { getM2MTokenFn } from "./client/auth/index.js";
11
10
 
12
11
  import type {
13
12
  BuildingBlockSDKParams,
14
13
  BuildingBlocksSDK,
14
+ Services,
15
+ TokenFunction,
15
16
  } from "./types/index.js";
16
17
 
17
- export const getBuildingBlockSDK = (
18
- params: BuildingBlockSDKParams,
19
- ): BuildingBlocksSDK => {
18
+ // Create type that only includes services that are defined in params
19
+ type DefinedServices<T extends BuildingBlockSDKParams> = {
20
+ [K in keyof BuildingBlocksSDK as K extends keyof T["services"]
21
+ ? T["services"][K] extends undefined
22
+ ? never
23
+ : K
24
+ : never]: BuildingBlocksSDK[K];
25
+ };
26
+
27
+ const createService = <K extends keyof Services>(
28
+ ServiceClass: new (
29
+ config: Services[K] & { getTokenFn: TokenFunction },
30
+ ) => BuildingBlocksSDK[K],
31
+ config: Services[K] | undefined,
32
+ getTokenFn: TokenFunction,
33
+ ): BuildingBlocksSDK[K] | undefined => {
34
+ if (!config) return undefined;
35
+ return new ServiceClass({ ...config, getTokenFn });
36
+ };
37
+
38
+ export const getBuildingBlockSDK = <T extends BuildingBlockSDKParams>(
39
+ params: T,
40
+ ): DefinedServices<T> => {
20
41
  const { services, getTokenFn } = params;
21
- return {
22
- analytics: new Analytics({
23
- ...services.analytics,
24
- getTokenFn,
25
- }),
26
- messaging: new Messaging({
27
- ...services.messaging,
28
- getTokenFn,
29
- }),
30
- payments: new Payments({
31
- ...services.payments,
32
- getTokenFn,
33
- }),
34
- profile: new Profile({
35
- ...services.profile,
36
- getTokenFn,
37
- }),
38
- scheduler: new Scheduler({
39
- ...services.scheduler,
40
- getTokenFn,
41
- }),
42
- upload: new Upload({
43
- ...services.upload,
44
- getTokenFn,
45
- }),
46
- featureFlags: new FeatureFlags({
47
- ...services.featureFlags,
42
+
43
+ const sdk = {
44
+ analytics: createService(Analytics, services.analytics, getTokenFn),
45
+ messaging: createService(Messaging, services.messaging, getTokenFn),
46
+ payments: createService(Payments, services.payments, getTokenFn),
47
+ profile: createService(Profile, services.profile, getTokenFn),
48
+ scheduler: createService(Scheduler, services.scheduler, getTokenFn),
49
+ upload: createService(Upload, services.upload, getTokenFn),
50
+ featureFlags: createService(
51
+ FeatureFlags,
52
+ services.featureFlags,
48
53
  getTokenFn,
49
- }),
54
+ ),
50
55
  };
56
+
57
+ // Remove undefined services
58
+ return Object.fromEntries(
59
+ Object.entries(sdk).filter(([_, value]) => value !== undefined),
60
+ ) as DefinedServices<T>;
51
61
  };