@financeable/aggregation 0.2.0 → 0.2.5

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 (97) hide show
  1. package/FUNCTIONS.md +1 -7
  2. package/README.md +938 -31
  3. package/docs/sdks/applications/README.md +2 -14
  4. package/jsr.json +1 -1
  5. package/lib/config.d.ts +3 -3
  6. package/lib/config.js +3 -3
  7. package/models/components/applicationresourcebulksubmission.d.ts +0 -6
  8. package/models/components/applicationresourcebulksubmission.d.ts.map +1 -1
  9. package/models/components/applicationresourcebulksubmission.js +0 -6
  10. package/models/components/applicationresourcebulksubmission.js.map +1 -1
  11. package/models/components/customerattributes.d.ts +5 -36
  12. package/models/components/customerattributes.d.ts.map +1 -1
  13. package/models/components/customerattributes.js +6 -41
  14. package/models/components/customerattributes.js.map +1 -1
  15. package/models/components/customeridtype.d.ts +28 -0
  16. package/models/components/customeridtype.d.ts.map +1 -0
  17. package/models/components/customeridtype.js +60 -0
  18. package/models/components/customeridtype.js.map +1 -0
  19. package/models/components/index.d.ts +1 -0
  20. package/models/components/index.d.ts.map +1 -1
  21. package/models/components/index.js +1 -0
  22. package/models/components/index.js.map +1 -1
  23. package/package.json +1 -1
  24. package/src/lib/config.ts +3 -3
  25. package/src/models/components/applicationresourcebulksubmission.ts +0 -12
  26. package/src/models/components/customerattributes.ts +13 -53
  27. package/src/models/components/customeridtype.ts +33 -0
  28. package/src/models/components/index.ts +1 -0
  29. package/financeable-typescript/.devcontainer/README.md +0 -30
  30. package/financeable-typescript/FUNCTIONS.md +0 -205
  31. package/financeable-typescript/README.md +0 -895
  32. package/financeable-typescript/RUNTIMES.md +0 -22
  33. package/financeable-typescript/docs/sdks/applications/README.md +0 -427
  34. package/financeable-typescript/docs/sdks/financeable/README.md +0 -5
  35. package/financeable-typescript/src/core.ts +0 -13
  36. package/financeable-typescript/src/funcs/applicationsCreate.ts +0 -124
  37. package/financeable-typescript/src/funcs/applicationsGet.ts +0 -128
  38. package/financeable-typescript/src/funcs/applicationsList.ts +0 -126
  39. package/financeable-typescript/src/hooks/hooks.ts +0 -129
  40. package/financeable-typescript/src/hooks/index.ts +0 -6
  41. package/financeable-typescript/src/hooks/types.ts +0 -109
  42. package/financeable-typescript/src/index.ts +0 -7
  43. package/financeable-typescript/src/lib/base64.ts +0 -37
  44. package/financeable-typescript/src/lib/config.ts +0 -59
  45. package/financeable-typescript/src/lib/dlv.ts +0 -53
  46. package/financeable-typescript/src/lib/encodings.ts +0 -449
  47. package/financeable-typescript/src/lib/env.ts +0 -37
  48. package/financeable-typescript/src/lib/files.ts +0 -40
  49. package/financeable-typescript/src/lib/http.ts +0 -323
  50. package/financeable-typescript/src/lib/is-plain-object.ts +0 -43
  51. package/financeable-typescript/src/lib/logger.ts +0 -9
  52. package/financeable-typescript/src/lib/matchers.ts +0 -322
  53. package/financeable-typescript/src/lib/primitives.ts +0 -122
  54. package/financeable-typescript/src/lib/retries.ts +0 -219
  55. package/financeable-typescript/src/lib/schemas.ts +0 -86
  56. package/financeable-typescript/src/lib/sdks.ts +0 -392
  57. package/financeable-typescript/src/lib/security.ts +0 -227
  58. package/financeable-typescript/src/lib/url.ts +0 -33
  59. package/financeable-typescript/src/models/components/addressattributes.ts +0 -148
  60. package/financeable-typescript/src/models/components/apierrorlinks.ts +0 -65
  61. package/financeable-typescript/src/models/components/applicationattributes.ts +0 -128
  62. package/financeable-typescript/src/models/components/applicationattributescreate.ts +0 -90
  63. package/financeable-typescript/src/models/components/applicationresourcebulksubmission.ts +0 -1000
  64. package/financeable-typescript/src/models/components/applicationstatus.ts +0 -39
  65. package/financeable-typescript/src/models/components/applicationtype.ts +0 -33
  66. package/financeable-typescript/src/models/components/assetattributes.ts +0 -400
  67. package/financeable-typescript/src/models/components/customerattributes.ts +0 -171
  68. package/financeable-typescript/src/models/components/customertitle.ts +0 -35
  69. package/financeable-typescript/src/models/components/errorsource.ts +0 -79
  70. package/financeable-typescript/src/models/components/forbiddenerror.ts +0 -207
  71. package/financeable-typescript/src/models/components/frequencytype.ts +0 -40
  72. package/financeable-typescript/src/models/components/index.ts +0 -20
  73. package/financeable-typescript/src/models/components/links.ts +0 -72
  74. package/financeable-typescript/src/models/components/loandetailsattributes.ts +0 -187
  75. package/financeable-typescript/src/models/components/repaymentstructure.ts +0 -40
  76. package/financeable-typescript/src/models/errors/apierror.ts +0 -27
  77. package/financeable-typescript/src/models/errors/createapplication.ts +0 -76
  78. package/financeable-typescript/src/models/errors/getapplication.ts +0 -76
  79. package/financeable-typescript/src/models/errors/getapplications.ts +0 -76
  80. package/financeable-typescript/src/models/errors/httpclienterrors.ts +0 -62
  81. package/financeable-typescript/src/models/errors/index.ts +0 -10
  82. package/financeable-typescript/src/models/errors/sdkvalidationerror.ts +0 -97
  83. package/financeable-typescript/src/models/operations/createapplication.ts +0 -1649
  84. package/financeable-typescript/src/models/operations/getapplication.ts +0 -1829
  85. package/financeable-typescript/src/models/operations/getapplications.ts +0 -1790
  86. package/financeable-typescript/src/models/operations/index.ts +0 -7
  87. package/financeable-typescript/src/sdk/applications.ts +0 -55
  88. package/financeable-typescript/src/sdk/index.ts +0 -5
  89. package/financeable-typescript/src/sdk/sdk.ts +0 -13
  90. package/financeable-typescript/src/types/blobs.ts +0 -31
  91. package/financeable-typescript/src/types/constdatetime.ts +0 -15
  92. package/financeable-typescript/src/types/enums.ts +0 -16
  93. package/financeable-typescript/src/types/fp.ts +0 -50
  94. package/financeable-typescript/src/types/index.ts +0 -11
  95. package/financeable-typescript/src/types/operations.ts +0 -105
  96. package/financeable-typescript/src/types/rfcdate.ts +0 -54
  97. package/financeable-typescript/src/types/streams.ts +0 -21
@@ -78,7 +78,6 @@ export type ApplicationResourceBulkSubmissionDataRelationshipsCustomersType =
78
78
  >;
79
79
 
80
80
  export type ApplicationResourceBulkSubmissionDataRelationshipsCustomersData = {
81
- id: string;
82
81
  type: ApplicationResourceBulkSubmissionDataRelationshipsCustomersType;
83
82
  attributes: AddressAttributes;
84
83
  };
@@ -92,7 +91,6 @@ export type ApplicationResourceBulkSubmissionRelationships = {
92
91
  };
93
92
 
94
93
  export type ApplicationResourceBulkSubmissionData = {
95
- id: string;
96
94
  type: ApplicationResourceBulkSubmissionDataType;
97
95
  /**
98
96
  * A customer of the proposed financing
@@ -113,7 +111,6 @@ export type ApplicationResourceBulkSubmissionDataRelationshipsType = ClosedEnum<
113
111
  >;
114
112
 
115
113
  export type ApplicationResourceBulkSubmissionDataData = {
116
- id: string;
117
114
  type: ApplicationResourceBulkSubmissionDataRelationshipsType;
118
115
  /**
119
116
  * The asset to be obtained by the customer, using the proposed loan financing.
@@ -370,7 +367,6 @@ export const ApplicationResourceBulkSubmissionDataRelationshipsCustomersData$inb
370
367
  z.ZodTypeDef,
371
368
  unknown
372
369
  > = z.object({
373
- id: z.string(),
374
370
  type:
375
371
  ApplicationResourceBulkSubmissionDataRelationshipsCustomersType$inboundSchema,
376
372
  attributes: AddressAttributes$inboundSchema,
@@ -379,7 +375,6 @@ export const ApplicationResourceBulkSubmissionDataRelationshipsCustomersData$inb
379
375
  /** @internal */
380
376
  export type ApplicationResourceBulkSubmissionDataRelationshipsCustomersData$Outbound =
381
377
  {
382
- id: string;
383
378
  type: string;
384
379
  attributes: AddressAttributes$Outbound;
385
380
  };
@@ -391,7 +386,6 @@ export const ApplicationResourceBulkSubmissionDataRelationshipsCustomersData$out
391
386
  z.ZodTypeDef,
392
387
  ApplicationResourceBulkSubmissionDataRelationshipsCustomersData
393
388
  > = z.object({
394
- id: z.string(),
395
389
  type:
396
390
  ApplicationResourceBulkSubmissionDataRelationshipsCustomersType$outboundSchema,
397
391
  attributes: AddressAttributes$outboundSchema,
@@ -572,7 +566,6 @@ export const ApplicationResourceBulkSubmissionData$inboundSchema: z.ZodType<
572
566
  z.ZodTypeDef,
573
567
  unknown
574
568
  > = z.object({
575
- id: z.string(),
576
569
  type: ApplicationResourceBulkSubmissionDataType$inboundSchema,
577
570
  attributes: CustomerAttributes$inboundSchema,
578
571
  relationships: z.lazy(() =>
@@ -582,7 +575,6 @@ export const ApplicationResourceBulkSubmissionData$inboundSchema: z.ZodType<
582
575
 
583
576
  /** @internal */
584
577
  export type ApplicationResourceBulkSubmissionData$Outbound = {
585
- id: string;
586
578
  type: string;
587
579
  attributes: CustomerAttributes$Outbound;
588
580
  relationships: ApplicationResourceBulkSubmissionRelationships$Outbound;
@@ -594,7 +586,6 @@ export const ApplicationResourceBulkSubmissionData$outboundSchema: z.ZodType<
594
586
  z.ZodTypeDef,
595
587
  ApplicationResourceBulkSubmissionData
596
588
  > = z.object({
597
- id: z.string(),
598
589
  type: ApplicationResourceBulkSubmissionDataType$outboundSchema,
599
590
  attributes: CustomerAttributes$outboundSchema,
600
591
  relationships: z.lazy(() =>
@@ -723,14 +714,12 @@ export const ApplicationResourceBulkSubmissionDataData$inboundSchema: z.ZodType<
723
714
  z.ZodTypeDef,
724
715
  unknown
725
716
  > = z.object({
726
- id: z.string(),
727
717
  type: ApplicationResourceBulkSubmissionDataRelationshipsType$inboundSchema,
728
718
  attributes: AssetAttributes$inboundSchema,
729
719
  });
730
720
 
731
721
  /** @internal */
732
722
  export type ApplicationResourceBulkSubmissionDataData$Outbound = {
733
- id: string;
734
723
  type: string;
735
724
  attributes: AssetAttributes$Outbound;
736
725
  };
@@ -742,7 +731,6 @@ export const ApplicationResourceBulkSubmissionDataData$outboundSchema:
742
731
  z.ZodTypeDef,
743
732
  ApplicationResourceBulkSubmissionDataData
744
733
  > = z.object({
745
- id: z.string(),
746
734
  type: ApplicationResourceBulkSubmissionDataRelationshipsType$outboundSchema,
747
735
  attributes: AssetAttributes$outboundSchema,
748
736
  });
@@ -3,29 +3,20 @@
3
3
  */
4
4
 
5
5
  import * as z from "zod";
6
- import { remap as remap$ } from "../../lib/primitives.js";
7
6
  import { safeParse } from "../../lib/schemas.js";
8
- import { ClosedEnum } from "../../types/enums.js";
9
7
  import { Result as SafeParseResult } from "../../types/fp.js";
10
8
  import { SDKValidationError } from "../errors/sdkvalidationerror.js";
9
+ import {
10
+ CustomerIDType,
11
+ CustomerIDType$inboundSchema,
12
+ CustomerIDType$outboundSchema,
13
+ } from "./customeridtype.js";
11
14
  import {
12
15
  CustomerTitle,
13
16
  CustomerTitle$inboundSchema,
14
17
  CustomerTitle$outboundSchema,
15
18
  } from "./customertitle.js";
16
19
 
17
- /**
18
- * Type of ID, either drivers' license or passport
19
- */
20
- export const IDType = {
21
- Licence: "licence",
22
- Passport: "passport",
23
- } as const;
24
- /**
25
- * Type of ID, either drivers' license or passport
26
- */
27
- export type IDType = ClosedEnum<typeof IDType>;
28
-
29
20
  /**
30
21
  * A customer of the proposed financing
31
22
  */
@@ -57,32 +48,13 @@ export type CustomerAttributes = {
57
48
  /**
58
49
  * Type of ID, either drivers' license or passport
59
50
  */
60
- idType?: IDType | undefined;
51
+ idType?: CustomerIDType | undefined;
61
52
  /**
62
53
  * Number of the ID
63
54
  */
64
55
  idNumber?: string | undefined;
65
56
  };
66
57
 
67
- /** @internal */
68
- export const IDType$inboundSchema: z.ZodNativeEnum<typeof IDType> = z
69
- .nativeEnum(IDType);
70
-
71
- /** @internal */
72
- export const IDType$outboundSchema: z.ZodNativeEnum<typeof IDType> =
73
- IDType$inboundSchema;
74
-
75
- /**
76
- * @internal
77
- * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
78
- */
79
- export namespace IDType$ {
80
- /** @deprecated use `IDType$inboundSchema` instead. */
81
- export const inboundSchema = IDType$inboundSchema;
82
- /** @deprecated use `IDType$outboundSchema` instead. */
83
- export const outboundSchema = IDType$outboundSchema;
84
- }
85
-
86
58
  /** @internal */
87
59
  export const CustomerAttributes$inboundSchema: z.ZodType<
88
60
  CustomerAttributes,
@@ -94,15 +66,9 @@ export const CustomerAttributes$inboundSchema: z.ZodType<
94
66
  middleNames: z.string().optional(),
95
67
  lastName: z.string(),
96
68
  dateOfBirth: z.string(),
97
- IDExpiryDate: z.string(),
98
- IDType: IDType$inboundSchema.optional(),
99
- IDNumber: z.string().optional(),
100
- }).transform((v) => {
101
- return remap$(v, {
102
- "IDExpiryDate": "idExpiryDate",
103
- "IDType": "idType",
104
- "IDNumber": "idNumber",
105
- });
69
+ idExpiryDate: z.string(),
70
+ idType: CustomerIDType$inboundSchema.optional(),
71
+ idNumber: z.string().optional(),
106
72
  });
107
73
 
108
74
  /** @internal */
@@ -112,9 +78,9 @@ export type CustomerAttributes$Outbound = {
112
78
  middleNames?: string | undefined;
113
79
  lastName: string;
114
80
  dateOfBirth: string;
115
- IDExpiryDate: string;
116
- IDType?: string | undefined;
117
- IDNumber?: string | undefined;
81
+ idExpiryDate: string;
82
+ idType?: string | undefined;
83
+ idNumber?: string | undefined;
118
84
  };
119
85
 
120
86
  /** @internal */
@@ -129,14 +95,8 @@ export const CustomerAttributes$outboundSchema: z.ZodType<
129
95
  lastName: z.string(),
130
96
  dateOfBirth: z.string(),
131
97
  idExpiryDate: z.string(),
132
- idType: IDType$outboundSchema.optional(),
98
+ idType: CustomerIDType$outboundSchema.optional(),
133
99
  idNumber: z.string().optional(),
134
- }).transform((v) => {
135
- return remap$(v, {
136
- idExpiryDate: "IDExpiryDate",
137
- idType: "IDType",
138
- idNumber: "IDNumber",
139
- });
140
100
  });
141
101
 
142
102
  /**
@@ -0,0 +1,33 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+
5
+ import * as z from "zod";
6
+ import { ClosedEnum } from "../../types/enums.js";
7
+
8
+ export const CustomerIDType = {
9
+ Passport: "passport",
10
+ Licence: "licence",
11
+ } as const;
12
+ export type CustomerIDType = ClosedEnum<typeof CustomerIDType>;
13
+
14
+ /** @internal */
15
+ export const CustomerIDType$inboundSchema: z.ZodNativeEnum<
16
+ typeof CustomerIDType
17
+ > = z.nativeEnum(CustomerIDType);
18
+
19
+ /** @internal */
20
+ export const CustomerIDType$outboundSchema: z.ZodNativeEnum<
21
+ typeof CustomerIDType
22
+ > = CustomerIDType$inboundSchema;
23
+
24
+ /**
25
+ * @internal
26
+ * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
27
+ */
28
+ export namespace CustomerIDType$ {
29
+ /** @deprecated use `CustomerIDType$inboundSchema` instead. */
30
+ export const inboundSchema = CustomerIDType$inboundSchema;
31
+ /** @deprecated use `CustomerIDType$outboundSchema` instead. */
32
+ export const outboundSchema = CustomerIDType$outboundSchema;
33
+ }
@@ -11,6 +11,7 @@ export * from "./applicationstatus.js";
11
11
  export * from "./applicationtype.js";
12
12
  export * from "./assetattributes.js";
13
13
  export * from "./customerattributes.js";
14
+ export * from "./customeridtype.js";
14
15
  export * from "./customertitle.js";
15
16
  export * from "./errorsource.js";
16
17
  export * from "./forbiddenerror.js";
@@ -1,30 +0,0 @@
1
-
2
- > **Remember to shutdown a GitHub Codespace when it is not in use!**
3
-
4
- # Dev Containers Quick Start
5
-
6
- The default location for usage snippets is the `samples` directory.
7
-
8
- ## Running a Usage Sample
9
-
10
- A sample usage example has been provided in a `root.ts` file. As you work with the SDK, it's expected that you will modify these samples to fit your needs. To execute this particular snippet, use the command below.
11
-
12
- ```
13
- ts-node root.ts
14
- ```
15
-
16
- ## Generating Additional Usage Samples
17
-
18
- The speakeasy CLI allows you to generate more usage snippets. Here's how:
19
-
20
- - To generate a sample for a specific operation by providing an operation ID, use:
21
-
22
- ```
23
- speakeasy generate usage -s ./spec.yaml -l typescript -i {INPUT_OPERATION_ID} -o ./samples
24
- ```
25
-
26
- - To generate samples for an entire namespace (like a tag or group name), use:
27
-
28
- ```
29
- speakeasy generate usage -s ./spec.yaml -l typescript -n {INPUT_TAG_NAME} -o ./samples
30
- ```
@@ -1,205 +0,0 @@
1
- # Standalone Functions
2
-
3
- > [!NOTE]
4
- > This section is useful if you are using a bundler and targetting browsers and
5
- > runtimes where the size of an application affects performance and load times.
6
-
7
- Every method in this SDK is also available as a standalone function. This
8
- alternative API is suitable when targetting the browser or serverless runtimes
9
- and using a bundler to build your application since all unused functionality
10
- will be tree-shaken away. This includes code for unused methods, Zod schemas,
11
- encoding helpers and response handlers. The result is dramatically smaller
12
- impact on the application's final bundle size which grows very slowly as you use
13
- more and more functionality from this SDK.
14
-
15
- Calling methods through the main SDK class remains a valid and generally more
16
- more ergonomic option. Standalone functions represent an optimisation for a
17
- specific category of applications.
18
-
19
- ## Example
20
-
21
- ```typescript
22
- import { FinanceableCore } from "@financeable/aggregation/core.js";
23
- import { applicationsCreate } from "@financeable/aggregation/funcs/applicationsCreate.js";
24
- import { SDKValidationError } from "@financeable/aggregation/models/errors/sdkvalidationerror.js";
25
-
26
- // Use `FinanceableCore` for best tree-shaking performance.
27
- // You can create one instance of it to use across an application.
28
- const financeable = new FinanceableCore();
29
-
30
- async function run() {
31
- const res = await applicationsCreate(financeable, {
32
- data: {
33
- type: "applications",
34
- attributes: {
35
- purpose: "Purchase of a motor vehicle",
36
- applicationType: "consumer",
37
- },
38
- relationships: {
39
- loanDetails: {
40
- data: {
41
- type: "loan-details",
42
- attributes: {
43
- repayments: 12,
44
- repaymentFrequency: "monthly",
45
- repaymentStructure: "group-payments",
46
- loanAmount: "10280.95",
47
- purpose: "Purchase of a motor vehicle",
48
- term: 48,
49
- balloon: 5,
50
- deposit: "2500",
51
- originationFee: 200,
52
- rate: "0.15",
53
- rateAdjustment: "-0.01",
54
- },
55
- },
56
- },
57
- customers: {
58
- data: [
59
- {
60
- id: "<id>",
61
- type: "customers",
62
- attributes: {
63
- title: "Mr",
64
- firstName: "John",
65
- lastName: "Smith",
66
- dateOfBirth: "01-01-1990",
67
- idExpiryDate: "01-01-2025",
68
- idType: "licence",
69
- idNumber: "12345678",
70
- },
71
- relationships: {
72
- addresses: {
73
- data: [
74
- {
75
- id: "<id>",
76
- type: "addresses",
77
- attributes: {
78
- addressType: "residential",
79
- fullAddress: "42 Wallaby Way, Sydney NSW 2000",
80
- city: "Sydney",
81
- postCode: "2000",
82
- streetAddress: "42 Wallaby Way",
83
- addressLine2: "",
84
- streetNumber: "42",
85
- streetType: "Way",
86
- street: "Wallaby",
87
- state: "NSW",
88
- country: "Australia",
89
- status: "current",
90
- monthsAt: 24,
91
- yearsAt: 2,
92
- },
93
- },
94
- ],
95
- },
96
- },
97
- },
98
- ],
99
- },
100
- asset: {
101
- data: {
102
- id: "<id>",
103
- type: "asset",
104
- attributes: {
105
- ageOfAsset: 3,
106
- ageOfAssetAtEnd: 8,
107
- condition: "USED",
108
- assetType: "MOTOR_VEHICLE_(<4.5_TONNES)",
109
- purpose: "VEHICLE",
110
- assetValue: "35000.00",
111
- make: "Toyota",
112
- assetModel: "Camry",
113
- registrationNumber: "ABC123",
114
- registrationState: "VIC",
115
- vin: "1HGCM82633A123456",
116
- supplierName: "Mr and Mrs Smith",
117
- supplierABN: "12345678901",
118
- supplierAddress: "123 Car Street, Melbourne VIC 3000",
119
- supplierPhone: "0412345678",
120
- supplierContactName: "John Smith",
121
- supplierEmail: "john.smith@mrandmrssmith.com.au",
122
- privateSale: false,
123
- typeOfSale: "DEALER",
124
- description: "2020 Toyota Camry Hybrid SL, Silver, 45,000km",
125
- netAssetValue: "32000.00",
126
- isLuxury: false,
127
- additionalFees: "995.00",
128
- additionalTaxes: "0.00",
129
- },
130
- },
131
- },
132
- },
133
- },
134
- });
135
-
136
- switch (true) {
137
- case res.ok:
138
- // The success case will be handled outside of the switch block
139
- break;
140
- case res.error instanceof SDKValidationError:
141
- // Pretty-print validation errors.
142
- return console.log(res.error.pretty());
143
- case res.error instanceof Error:
144
- return console.log(res.error);
145
- default:
146
- // TypeScript's type checking will fail on the following line if the above
147
- // cases were not exhaustive.
148
- res.error satisfies never;
149
- throw new Error("Assertion failed: expected error checks to be exhaustive: " + res.error);
150
- }
151
-
152
-
153
- const { value: result } = res;
154
-
155
- // Handle the result
156
- console.log(result);
157
- }
158
-
159
- run();
160
- ```
161
-
162
- ## Result types
163
-
164
- Standalone functions differ from SDK methods in that they return a
165
- `Result<Value, Error>` type to capture _known errors_ and document them using
166
- the type system. By avoiding throwing errors, application code maintains clear
167
- control flow and error-handling become part of the regular flow of application
168
- code.
169
-
170
- > We use the term "known errors" because standalone functions, and JavaScript
171
- > code in general, can still throw unexpected errors such as `TypeError`s,
172
- > `RangeError`s and `DOMException`s. Exhaustively catching all errors may be
173
- > something this SDK addresses in the future. Nevertheless, there is still a lot
174
- > of benefit from capturing most errors and turning them into values.
175
-
176
- The second reason for this style of programming is because these functions will
177
- typically be used in front-end applications where exception throwing is
178
- sometimes discouraged or considered unidiomatic. React and similar ecosystems
179
- and libraries tend to promote this style of programming so that components
180
- render useful content under all states (loading, success, error and so on).
181
-
182
- The general pattern when calling standalone functions looks like this:
183
-
184
- ```typescript
185
- import { Core } from "<sdk-package-name>";
186
- import { fetchSomething } from "<sdk-package-name>/funcs/fetchSomething.js";
187
-
188
- const client = new Core();
189
-
190
- async function run() {
191
- const result = await fetchSomething(client, { id: "123" });
192
- if (!result.ok) {
193
- // You can throw the error or handle it. It's your choice now.
194
- throw result.error;
195
- }
196
-
197
- console.log(result.value);
198
- }
199
-
200
- run();
201
- ```
202
-
203
- Notably, `result.error` above will have an explicit type compared to a try-catch
204
- variation where the error in the catch block can only be of type `unknown` (or
205
- `any` depending on your TypeScript settings).