@raytio/decrypt-helper 5.1.3 → 6.1.0

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 (88) hide show
  1. package/README.md +5 -1
  2. package/package.json +32 -23
  3. package/CHANGELOG.md +0 -221
  4. package/dist/api/authedFetch.d.ts +0 -1
  5. package/dist/api/authedFetch.js +0 -32
  6. package/dist/api/fetchAA.d.ts +0 -3
  7. package/dist/api/fetchAA.js +0 -19
  8. package/dist/api/fetchEnvConfig.d.ts +0 -6
  9. package/dist/api/fetchEnvConfig.js +0 -39
  10. package/dist/api/fetchInstanceData.d.ts +0 -3
  11. package/dist/api/fetchInstanceData.js +0 -21
  12. package/dist/api/getFiles.d.ts +0 -4
  13. package/dist/api/getFiles.js +0 -82
  14. package/dist/api/getLookupOption.d.ts +0 -2
  15. package/dist/api/getLookupOption.js +0 -32
  16. package/dist/api/getSchema.d.ts +0 -3
  17. package/dist/api/getSchema.js +0 -31
  18. package/dist/api/index.d.ts +0 -9
  19. package/dist/api/index.js +0 -25
  20. package/dist/api/resolveVerificationDetails.d.ts +0 -9
  21. package/dist/api/resolveVerificationDetails.js +0 -35
  22. package/dist/api/signIn.d.ts +0 -7
  23. package/dist/api/signIn.js +0 -56
  24. package/dist/api/updateInstanceData.d.ts +0 -2
  25. package/dist/api/updateInstanceData.js +0 -19
  26. package/dist/configureEnv.d.ts +0 -1
  27. package/dist/configureEnv.js +0 -16
  28. package/dist/constants.d.ts +0 -23
  29. package/dist/constants.js +0 -45
  30. package/dist/helpers/file.d.ts +0 -13
  31. package/dist/helpers/file.js +0 -17
  32. package/dist/helpers/formatOutput.d.ts +0 -28
  33. package/dist/helpers/formatOutput.js +0 -92
  34. package/dist/helpers/index.d.ts +0 -6
  35. package/dist/helpers/index.js +0 -22
  36. package/dist/helpers/json2csv.d.ts +0 -2
  37. package/dist/helpers/json2csv.js +0 -24
  38. package/dist/helpers/lookup.d.ts +0 -2
  39. package/dist/helpers/lookup.js +0 -22
  40. package/dist/helpers/setupMaxcryptor.d.ts +0 -4
  41. package/dist/helpers/setupMaxcryptor.js +0 -28
  42. package/dist/helpers/splitPOAndVers.d.ts +0 -2
  43. package/dist/helpers/splitPOAndVers.js +0 -11
  44. package/dist/helpers/types.d.ts +0 -1
  45. package/dist/helpers/types.js +0 -9
  46. package/dist/index.d.ts +0 -6
  47. package/dist/index.js +0 -16
  48. package/dist/locales/index.d.ts +0 -44
  49. package/dist/locales/index.js +0 -21
  50. package/dist/locales/translations/en.json +0 -33
  51. package/dist/pdf/components/FieldVerificationBadge.d.ts +0 -6
  52. package/dist/pdf/components/FieldVerificationBadge.js +0 -19
  53. package/dist/pdf/components/Images.d.ts +0 -6
  54. package/dist/pdf/components/Images.js +0 -19
  55. package/dist/pdf/components/InnerTableRows.d.ts +0 -11
  56. package/dist/pdf/components/InnerTableRows.js +0 -37
  57. package/dist/pdf/components/POVerificationBadge.d.ts +0 -8
  58. package/dist/pdf/components/POVerificationBadge.js +0 -41
  59. package/dist/pdf/components/Report.d.ts +0 -14
  60. package/dist/pdf/components/Report.js +0 -95
  61. package/dist/pdf/components/Subheader.d.ts +0 -2
  62. package/dist/pdf/components/Subheader.js +0 -28
  63. package/dist/pdf/components/Table.d.ts +0 -9
  64. package/dist/pdf/components/Table.js +0 -47
  65. package/dist/pdf/components/TableTitle.d.ts +0 -5
  66. package/dist/pdf/components/TableTitle.js +0 -17
  67. package/dist/pdf/components/ValidationDisplay.d.ts +0 -5
  68. package/dist/pdf/components/ValidationDisplay.js +0 -29
  69. package/dist/pdf/components/VerifyBox.d.ts +0 -9
  70. package/dist/pdf/components/VerifyBox.js +0 -16
  71. package/dist/pdf/components/pieChart.d.ts +0 -6
  72. package/dist/pdf/components/pieChart.js +0 -27
  73. package/dist/pdf/constants.d.ts +0 -2
  74. package/dist/pdf/constants.js +0 -11
  75. package/dist/pdf/helpers/general.d.ts +0 -8
  76. package/dist/pdf/helpers/general.js +0 -37
  77. package/dist/pdf/helpers/transform.d.ts +0 -4
  78. package/dist/pdf/helpers/transform.js +0 -39
  79. package/dist/pdf/style.d.ts +0 -10
  80. package/dist/pdf/style.js +0 -24
  81. package/dist/public-methods/generatePDF.d.ts +0 -4
  82. package/dist/public-methods/generatePDF.js +0 -62
  83. package/dist/public-methods/getAndValidateConfig.d.ts +0 -8
  84. package/dist/public-methods/getAndValidateConfig.js +0 -20
  85. package/dist/public-methods/processSubmission.d.ts +0 -48
  86. package/dist/public-methods/processSubmission.js +0 -124
  87. package/dist/public-methods/saveToS3Bucket.d.ts +0 -2
  88. package/dist/public-methods/saveToS3Bucket.js +0 -58
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  ## Intsall
9
9
 
10
- This SDK is designed to run on nodejs >=14.
10
+ This SDK is designed to run on nodejs >=18.
11
11
 
12
12
  ```sh
13
13
  npm install --save @raytio/decrypt-helper
@@ -87,3 +87,7 @@ We use jest for unit tests, snapshot tests of the PDF, and integration tests for
87
87
  To run tests, use `yarn test`. To run and update snapshots, use `yarn test -u`. You will need to configure the evironment variables in `.env` for integration tests.
88
88
 
89
89
  If jest apears to be stuck running the end-to-end tests, run `yarn jest --clearCache`.
90
+
91
+ ### Manual testing
92
+
93
+ You can also test changes to this code using serverless-offline, [see here for more info](https://gitlab.com/raytio/common/pdf-generate/-/tree/main/packages/pdf-generate#testing).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytio/decrypt-helper",
3
- "version": "5.1.3",
3
+ "version": "6.1.0",
4
4
  "author": "Raytio",
5
5
  "description": "A helper to decrypt data shared by Raytio users",
6
6
  "main": "dist",
@@ -22,47 +22,55 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@aws-amplify/auth": "3.4.25",
25
- "@peculiar/webcrypto": "^1.4.1",
26
- "@raytio/core": "^10.1.0",
25
+ "@raytio/core": "^11.1.0",
27
26
  "@raytio/maxcryptor": "^3.1.0",
28
- "@raytio/types": "^6.0.2",
27
+ "@raytio/types": "^7.1.0",
29
28
  "aws-sdk": "^2.754.0",
30
29
  "jsx-pdf": "^2.3.0",
31
30
  "localstorage-polyfill": "^1.0.1",
32
31
  "mime-types": "^2.1.35",
33
- "node-fetch": "^2.6.7",
34
- "pdfmake": "^0.2.6",
35
- "ramda": "^0.28.0"
32
+ "pdfmake": "^0.2.7",
33
+ "ramda": "^0.29.0"
36
34
  },
37
35
  "devDependencies": {
38
- "@raytio/react-intl-manager": "^6.3.0",
39
- "@types/jest": "^29.2.2",
40
- "@types/jest-image-snapshot": "^5.1.0",
36
+ "@raytio/react-intl-manager": "^6.3.1",
37
+ "@types/jest": "^29.5.1",
38
+ "@types/jest-image-snapshot": "^6.1.0",
41
39
  "@types/jsx-pdf": "^2.2.2",
42
40
  "@types/mime-types": "^2.1.1",
43
- "@types/node": "^18.11.9",
44
- "@types/node-fetch": "^2.5.12",
41
+ "@types/node": "^18.15.12",
45
42
  "@types/pdfmake": "^0.2.2",
46
- "@types/ramda": "^0.28.19",
43
+ "@types/ramda": "^0.29.0",
47
44
  "babel-preset-react-app": "^10.0.1",
48
45
  "dotenv": "^16.0.3",
49
- "eslint": "^8.27.0",
50
- "eslint-config-kyle": "^9.12.1",
51
- "jest": "^29.3.1",
52
- "jest-image-snapshot": "^6.0.0",
53
- "jest-junit": "^14.0.1",
54
- "pdf-to-img": "^2.0.0",
55
- "ts-jest": "^29.0.3",
46
+ "eslint": "^8.38.0",
47
+ "eslint-config-kyle": "^11.14.2",
48
+ "jest": "^29.5.0",
49
+ "jest-image-snapshot": "^6.1.0",
50
+ "jest-junit": "^16.0.0",
51
+ "pdf-to-img": "^2.1.1",
52
+ "ts-jest": "^29.1.0",
56
53
  "ts-node": "^10.9.1",
57
- "typescript": "^4.8.4"
54
+ "typescript": "^5.0.4"
58
55
  },
59
56
  "eslintConfig": {
60
57
  "extends": "kyle",
61
58
  "rules": {
59
+ "import/extensions": 0,
60
+ "react/jsx-key": 0,
62
61
  "react/react-in-jsx-scope": 0,
63
62
  "react/style-prop-object": 0,
64
63
  "react/no-unknown-property": 0,
65
- "@typescript-eslint/no-non-null-assertion": 0,
64
+ "unicorn/prevent-abbreviations": [
65
+ 1,
66
+ {
67
+ "replacements": {
68
+ "i": false,
69
+ "env": false,
70
+ "props": false
71
+ }
72
+ }
73
+ ],
66
74
  "@typescript-eslint/no-unused-vars": [
67
75
  2,
68
76
  {
@@ -73,6 +81,7 @@
73
81
  "camelcase": 0
74
82
  }
75
83
  },
84
+ "prettier": {},
76
85
  "jest": {
77
86
  "testMatch": [
78
87
  "**/__tests__/?(*.)+(spec|test).[jt]s?(x)"
@@ -114,7 +123,7 @@
114
123
  "outputDirectory": "tmp"
115
124
  },
116
125
  "engines": {
117
- "node": ">=14"
126
+ "node": ">=18"
118
127
  },
119
128
  "i18n": {
120
129
  "localeDir": "src/locales/translations",
package/CHANGELOG.md DELETED
@@ -1,221 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [Unreleased]
9
-
10
- ## 5.1.3 (2022-11-11)
11
-
12
- - !196 fix more issues caused by corrupted images
13
- - !192, !194 automated dependency updates
14
-
15
- ## 5.1.2 (2022-11-10)
16
-
17
- - !195 retry API requests that fail with a 504 error
18
- - !195 fix crash from corrupted binary files
19
-
20
- ## 5.1.1 (2022-08-15)
21
-
22
- - !189 load verifier details faster
23
- - !187 automated dependency updates
24
-
25
- ## 5.1.0 (2022-08-13)
26
-
27
- - !188 update raytio/core so that `repairDate` is used on dates
28
- - !186 automated dependency updates
29
-
30
- ## 5.0.0 (2022-07-12)
31
-
32
- - 💥 BREAKING CHANGE: !185 use `accessToken` instead of `idToken` when communicating with the Raytio API
33
- - 💥 BREAKING CHANGE: !185 Improve how quotes (`"`) are escaped in the csv format to be compliant with [RFC-4180](https://datatracker.ietf.org/doc/html/rfc4180#section-2)
34
- - !185 embed language into pdf
35
- - !184 automated dependency updates
36
-
37
- ## 4.0.0 (2022-07-08)
38
-
39
- - 💥 BREAKING CHANGE: !170 [json] [csv] changed the format of badges, the fields `$verified` and `$safeHarbour` have been replaced with `$badges`
40
- - !176 fix field values being unexpectedly transformed
41
- - !179 update dependencies
42
- - !182 save the calculated score to the instance
43
-
44
- ## 3.2.0 (2022-04-21)
45
-
46
- - !177 do not use `hashPassword` when logging in, and migrate old credentials
47
-
48
- ## 3.1.1 (2022-04-02)
49
-
50
- - !175 Fix import issue in v3.1
51
-
52
- ## 3.1.0 (2022-03-14)
53
-
54
- - !168 Support internationalizing the pdf
55
- - !167 Support while labelling the pdf
56
- - !166 List the person schema first in the PDF
57
- - !163, !165, !169, !171, !172 automated dependency updates
58
-
59
- ## 3.0.2 (2022-02-16)
60
-
61
- - !164 fix PDF bug for multiple POs from the same schema
62
- - !164 remove legacy internal property called `$source`
63
- - !164 fix field verification status being `undefined` instead of `NotVerified`/`60002`
64
- - 💥 BREAKING CHANGE: we no longer use `schema_group` to group schema in the json, csv, and pdf
65
-
66
- ## 3.0.1 (2022-02-15)
67
-
68
- - !162 fix bug with PDF generation
69
-
70
- ## 3.0.0 (2022-02-04)
71
-
72
- - 💥 BREAKING CHANGE: renamed the `USERNAME` & `PASSWORD` environment variables to `RAYTIO_USERNAME` & `RAYTIO_PASSWORD`
73
- - 💥 BREAKING CHANGE: removed the `READABLE_FIELD_NAMES` option
74
- - 💥 BREAKING CHANGE: [csv] added new columns, shifted other columns
75
- - 💥 BREAKING CHANGE: [json] removed some duplicate legacy fields, see #33
76
- - !156: various internal refactoring
77
-
78
- ## 2.2.1 (2022-02-09)
79
-
80
- - !158 include the submission score in the json and pdf
81
-
82
- ## 2.2.0 (2022-02-04)
83
-
84
- - !153 fix rendering of arrays of primitive values
85
- - !152 Update @raytio/core to v9 to fix a bug with `hashed_n_id`
86
- - !155, !154, !146, !147, !150, !151 automated dependency updates
87
-
88
- ## 2.1.3 (2021-10-08)
89
-
90
- - !134 Add more logging to `saveToS3Bucket`
91
- - !129, !131, !132, !133 automated dependency updates
92
-
93
- ## 2.1.2 (2021-09-24)
94
-
95
- - !129 Update @raytio/core to v8.1.2 to support the new API format for `hashed_n_id`
96
-
97
- ## 2.1.1 (2021-09-15)
98
-
99
- - !126 Update @raytio/core to v8.1.1 to fix a bug with `hashed_n_id`
100
-
101
- ## 2.1.0 (2021-09-03)
102
-
103
- - !117 Update @raytio/core to v8
104
- - !120 Render document validation score
105
-
106
- ## 2.0.0 (2021-06-28)
107
-
108
- - 💥 BREAKING CHANGE: requires nodejs v14 or newer
109
- - 💥 BREAKING CHANGE: dates in the PDF will now use the `DATE_FORMAT` and `TIMEZONE` environment variables, which were previously required, but not used due to a bug in node v12.
110
- - removed various polyfills for node12, which reduced the install size by 26MB
111
-
112
- ## 1.4.1 (2021-05-21)
113
-
114
- - !103 embed decrypt-helper version into PDF metadata
115
- - !101, !100, !99, !98, !97, !96, !94, !93, !87 automated dependency updates
116
-
117
- ## 1.4.0 (2021-04-27)
118
-
119
- - !95 release
120
- - !92 remove base64 of encrypted images from json output
121
- - !91 use schema lookups in the pdf report
122
- - !90 only show verification badges in the pdf report if the the data is verifiable
123
- - !89 automated dependency updates
124
-
125
- ## 1.3.4 (2021-04-15)
126
-
127
- - !86 Fix first row of table being simulating table header on page break when table header isn't specified.
128
- - !85 update maxcryptor
129
- - !75 refresh lockfile
130
-
131
- ## 1.3.3 (2021-04-14)
132
-
133
- - !84 minor refactoring
134
-
135
- ## 1.3.2 (2021-04-13)
136
-
137
- - !80 update raytio packages
138
- - !77, !78, !82 automated dependency updates
139
-
140
- ## 1.3.1 (2021-03-21)
141
-
142
- - !73 fixes a bug introduced in `1.3.0` where the content type of images from `urn:temp_object:` was wrong
143
-
144
- ## 1.3.0 (2021-03-21)
145
-
146
- - !72 handle images from `urn:temp_object:`
147
- - !71 automated dependency updates
148
-
149
- ## 1.2.1 (2021-03-17)
150
-
151
- - !70 improve fetchEnvConfig debugging
152
- - !68 tweak renovate config
153
- - !64, !69 automated dependency updates
154
-
155
- ## 1.2.0 (2021-03-10)
156
-
157
- - !67 support encrypted images
158
- - !60, !66 automated dependency updates
159
-
160
- # 1.1.1 (2021-03-03)
161
-
162
- - !63 upgrade raytio packages
163
- - !61, !62 automated dependency updates
164
-
165
- ## 1.1.0 (2021-02-26)
166
-
167
- - !57 release
168
- - !55 fix bug
169
- - !51 support arrays of objects in PDF
170
- - !32 add screenshot tests for PDF generation
171
- - !20, !21, !22, !23, !24, !25, !27, !28, !29, !30, !33, !36, !38, !39, !41, !43, !45, !46, !49, !50, !54 automated dependency updates
172
- - !19, !53 set up automated dependency updates
173
-
174
- ## 1.0.1 (2021-01-27)
175
-
176
- - !18 fix: fix bug in PDF generation
177
-
178
- ## 1.0.0 (2021-01-21)
179
-
180
- - versioning now follow semver. This update in itself is not a breaking change
181
- - !16 fix: handle corrupted submission data
182
-
183
- ## 0.0.10 (2021-01-21)
184
-
185
- - !15 chore: enable more logging if processing a submission fails
186
- - !15 chore: update raytio packages
187
-
188
- ## 0.0.9 (2021-01-09)
189
-
190
- - !14 fix: show a nicer error if an invalid clientUrl is supplied
191
-
192
- ## 0.0.8 (2021-01-08)
193
-
194
- - !12 feat(pdf): add Safe Harbour badge to pdf
195
- - !12 feat(json): add more details to json data (`$nId`, `$schemaName`, `$properties`)
196
-
197
- ## 0.0.7 (2021-01-07)
198
-
199
- - !13 feat: export the `fetchEnvConfig` function
200
-
201
- ## 0.0.6 (2020-12-16)
202
-
203
- - !11 fix: update @raytio/core to fix verification bugs
204
-
205
- ## 0.0.5 (2020-11-20)
206
-
207
- - !10 fix: update @raytio/core to fix bug
208
- - !9 feat: use schema groups
209
-
210
- ## 0.0.4 (2020-11-13)
211
-
212
- - !8 fix(pdf): change hard to read green text
213
- - !8 chore: update dependencies
214
-
215
- ## 0.0.3 (2020-10-16)
216
-
217
- - !7 feat(`saveToS3Bucket`): store data in folder based on `i_id`.
218
-
219
- ## 0.0.2 (2020-10-09)
220
-
221
- First stable release
@@ -1 +0,0 @@
1
- export declare function authedFetch<T>(apiToken: string, url: string, options?: RequestInit, retrying?: boolean): Promise<T>;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.authedFetch = void 0;
13
- function authedFetch(apiToken, url, options, retrying = false) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- console.log(`[API] ${retrying ? "Retry" : "Start"} ${url}`);
16
- const startTime = +new Date();
17
- const req = yield fetch(url, Object.assign(Object.assign({}, options), { headers: { Authorization: `Bearer ${apiToken}` } }));
18
- const apiResp = yield req.json();
19
- if (apiResp.message) {
20
- if (!retrying && req.status === 504) {
21
- console.log(`[API] Error ${req.status} (will retry) ${url}`);
22
- return authedFetch(apiToken, url, options, true);
23
- }
24
- console.log(`[API] Error ${req.status} (no retry) ${url}`);
25
- throw new Error(`Failed due to API Error from ${url}: "${apiResp.message}"`);
26
- }
27
- const totalTime = ((+new Date() - startTime) / 1000).toFixed(1);
28
- console.log(`[API] Finish${retrying ? " after retry" : ""} (${totalTime}s) ${url}`);
29
- return apiResp;
30
- });
31
- }
32
- exports.authedFetch = authedFetch;
@@ -1,3 +0,0 @@
1
- import type { AId, AA } from "@raytio/types";
2
- import { EnvConfig } from "./fetchEnvConfig";
3
- export declare function fetchAA(apiToken: string, envConfig: EnvConfig, aId: AId): Promise<AA>;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.fetchAA = void 0;
13
- const authedFetch_1 = require("./authedFetch");
14
- function fetchAA(apiToken, envConfig, aId) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- return (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/share/v2/access_application/${aId}`);
17
- });
18
- }
19
- exports.fetchAA = fetchAA;
@@ -1,6 +0,0 @@
1
- declare const PARAMS: readonly ["cognito_region", "cognito_user_pool_id", "cognito_web_client_id", "api_url", "app_name", "logo_url"];
2
- export declare type EnvConfig = Record<typeof PARAMS[number], string> & {
3
- clientUrl: string;
4
- };
5
- export declare function fetchEnvConfig(clientUrl: string): Promise<EnvConfig>;
6
- export {};
@@ -1,39 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.fetchEnvConfig = void 0;
13
- const PARAMS = [
14
- "cognito_region",
15
- "cognito_user_pool_id",
16
- "cognito_web_client_id",
17
- "api_url",
18
- "app_name",
19
- "logo_url", // must be a URL to a png file
20
- ];
21
- const DEFAULTS = {
22
- app_name: "Raytio",
23
- logo_url: undefined,
24
- };
25
- function fetchEnvConfig(clientUrl) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- try {
28
- const envConfig = Object.assign(Object.assign({}, DEFAULTS), (yield fetch(`${clientUrl}/client_config.json`).then((r) => r.json())));
29
- const missing = PARAMS.filter((p) => !(p in envConfig));
30
- if (missing.length)
31
- throw new Error(`Missing: ${missing.join(", ")}`);
32
- return Object.assign(Object.assign({}, envConfig), { clientUrl });
33
- }
34
- catch (ex) {
35
- throw new Error(`The CLIENT_URL you specified is not a valid Raytio client. Are you sure you used the client URL, not the API url? You supplied: "${clientUrl}" (${ex})`);
36
- }
37
- });
38
- }
39
- exports.fetchEnvConfig = fetchEnvConfig;
@@ -1,3 +0,0 @@
1
- import type { IId, Instance } from "@raytio/types";
2
- import { EnvConfig } from "./fetchEnvConfig";
3
- export declare function fetchInstanceData(apiToken: string, envConfig: EnvConfig, instanceId: IId): Promise<Instance>;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.fetchInstanceData = void 0;
13
- const core_1 = require("@raytio/core");
14
- const authedFetch_1 = require("./authedFetch");
15
- function fetchInstanceData(apiToken, envConfig, instanceId) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const instance = yield (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/share/v2/access_application/instance/${instanceId}`).then(core_1.cleanInstance);
18
- return instance;
19
- });
20
- }
21
- exports.fetchInstanceData = fetchInstanceData;
@@ -1,4 +0,0 @@
1
- import type { Instance, NId, ProfileObject } from "@raytio/types";
2
- import { ApplicationEncryptorLike } from "../types";
3
- import { EnvConfig } from "./fetchEnvConfig";
4
- export declare function getFiles(profileObjects: ProfileObject[], instance: Instance, apiToken: string, envConfig: EnvConfig, applicationDecryptor: ApplicationEncryptorLike): Promise<Record<NId, [dataUrl: string, fileExtension: string]>>;
@@ -1,82 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getFiles = void 0;
16
- const core_1 = require("@raytio/core");
17
- const node_fetch_1 = __importDefault(require("node-fetch"));
18
- const mime_types_1 = require("mime-types");
19
- const file_1 = require("../helpers/file");
20
- const authedFetch_1 = require("./authedFetch");
21
- const TEMP_OBJ_PREFIX = "urn:temp_object:";
22
- const getFileExtn = (b64) => { var _a; return (0, mime_types_1.extension)(((_a = b64.split(":")[1]) === null || _a === void 0 ? void 0 : _a.split(";base64,")[0]) || "text/plain") || "txt"; };
23
- const decryptFile = (encryptedData, encryptedObj, applicationDecryptor, wdek) => __awaiter(void 0, void 0, void 0, function* () {
24
- const clonedEncryptedObj = JSON.parse(JSON.stringify(encryptedObj));
25
- clonedEncryptedObj.encrypted_data.data = encryptedData;
26
- const decrypted = yield applicationDecryptor.decrypt(clonedEncryptedObj, wdek);
27
- return decrypted;
28
- });
29
- const cleanApiResponse = (responseBody) => {
30
- try {
31
- const realB64 = atob(responseBody);
32
- if (realB64.slice(0, 5) === "data:") {
33
- return realB64;
34
- }
35
- }
36
- catch (_a) {
37
- // for some reason we need to do this...
38
- }
39
- return responseBody;
40
- };
41
- function getFiles(profileObjects, instance, apiToken, envConfig, applicationDecryptor) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- // [nId: NId, fieldName: string, file: RaytFile][]
44
- const urnOrEncryptedList = profileObjects.flatMap((PO) => {
45
- return Object.entries(PO.properties)
46
- .filter((kv) => (0, file_1.isFieldValueFile)(kv[1]))
47
- .map(([k, v]) => {
48
- return [
49
- PO.n_id,
50
- v.n_id,
51
- k,
52
- "content" in v ? v.content : v.Content,
53
- ];
54
- });
55
- });
56
- const filesBase64 = yield Promise.all(urnOrEncryptedList.map(([PONId, fileNId, fieldName, urnOrEncrypted]) => __awaiter(this, void 0, void 0, function* () {
57
- var _a, _b;
58
- // handle urn:temp_object:
59
- if (typeof urnOrEncrypted === "string" &&
60
- urnOrEncrypted.startsWith(TEMP_OBJ_PREFIX)) {
61
- const url = atob(urnOrEncrypted.slice(TEMP_OBJ_PREFIX.length));
62
- const res = yield (0, node_fetch_1.default)(url);
63
- const b64 = (yield res.buffer()).toString("base64");
64
- const type = res.headers.get("content-type") || "text/plain";
65
- const dataUrl = `data:${type};base64,${b64}`;
66
- return [fileNId, [dataUrl, getFileExtn(dataUrl)]];
67
- }
68
- // TODO: should realB64 be renamed to "realDataUrl"?
69
- const realB64 = yield (0, authedFetch_1.authedFetch)(apiToken, `${envConfig.api_url}/share/v2/access_application/instance/${instance.i_id}/profile_object/${fileNId}/content`).then(cleanApiResponse);
70
- if ((0, core_1.isEncrypted)(urnOrEncrypted)) {
71
- const wdek = (_b = (_a = instance.keys[PONId]) === null || _a === void 0 ? void 0 : _a[fieldName]) === null || _b === void 0 ? void 0 : _b.data;
72
- if (!wdek)
73
- return [fileNId, undefined];
74
- const decryptedDataUrl = yield decryptFile(realB64, urnOrEncrypted, applicationDecryptor, wdek);
75
- return [fileNId, [decryptedDataUrl, getFileExtn(decryptedDataUrl)]];
76
- }
77
- return [fileNId, [realB64, getFileExtn(realB64)]];
78
- })));
79
- return Object.fromEntries(filesBase64.filter((file) => { var _a; return !!file[1] && ((_a = file[1][0]) === null || _a === void 0 ? void 0 : _a.includes(",")); }));
80
- });
81
- }
82
- exports.getFiles = getFiles;
@@ -1,2 +0,0 @@
1
- import { Lookup } from "@raytio/types";
2
- export declare function getLookupOption(apiToken: string, lookup: string): Promise<Lookup[]>;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getLookupOption = void 0;
13
- const authedFetch_1 = require("./authedFetch");
14
- /**
15
- * We cache the promise so that only one XHR request is ever sent
16
- */
17
- const cache = new Map();
18
- function getLookupOption(apiToken, lookup) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- const { origin } = new URL(lookup);
21
- const cached = cache.get(lookup);
22
- if (cached)
23
- return cached;
24
- // if it's a lookup to our own API, then include the IdentityToken
25
- const promise = origin.endsWith(".rayt.io")
26
- ? (0, authedFetch_1.authedFetch)(apiToken, lookup)
27
- : fetch(lookup).then((r) => r.json());
28
- cache.set(lookup, promise);
29
- return promise;
30
- });
31
- }
32
- exports.getLookupOption = getLookupOption;
@@ -1,3 +0,0 @@
1
- import type { Schema } from "@raytio/types";
2
- import { EnvConfig } from "./fetchEnvConfig";
3
- export declare function getSchema(envConfig: EnvConfig, name: string): Promise<Schema>;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getSchema = void 0;
13
- const authedFetch_1 = require("./authedFetch");
14
- const cache = new Map();
15
- function $getSchema(envConfig, name) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const [schemaHead, ...schemaTail] = name.split("_");
18
- const schema = yield (0, authedFetch_1.authedFetch)("", `${envConfig.api_url}/graph/v2/schema_public/${schemaHead}/${schemaTail.join("_")}?expand=true`);
19
- return Object.assign(Object.assign({}, schema), { name });
20
- });
21
- }
22
- function getSchema(envConfig, name) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- if (cache.has(name))
25
- return cache.get(name);
26
- const promise = $getSchema(envConfig, name);
27
- cache.set(name, promise);
28
- return promise;
29
- });
30
- }
31
- exports.getSchema = getSchema;
@@ -1,9 +0,0 @@
1
- export * from "./authedFetch";
2
- export * from "./fetchAA";
3
- export * from "./fetchEnvConfig";
4
- export * from "./fetchInstanceData";
5
- export * from "./getFiles";
6
- export * from "./getSchema";
7
- export * from "./resolveVerificationDetails";
8
- export * from "./signIn";
9
- export * from "./updateInstanceData";