@learncard/helpers 1.3.12 → 1.4.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.
- package/dist/Utilities.d.ts +59 -0
- package/dist/Utilities.d.ts.map +1 -0
- package/dist/app-install/index.d.ts +62 -0
- package/dist/app-install/index.d.ts.map +1 -0
- package/dist/arrays/index.d.ts +3 -0
- package/dist/arrays/index.d.ts.map +1 -0
- package/dist/bitstring-status-list/index.d.ts +8 -0
- package/dist/bitstring-status-list/index.d.ts.map +1 -0
- package/dist/credential-format.d.ts +96 -0
- package/dist/credential-format.d.ts.map +1 -0
- package/dist/did.d.ts +3 -0
- package/dist/did.d.ts.map +1 -0
- package/dist/environment.d.ts +32 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/helpers.cjs.development.cjs +1648 -1540
- package/dist/helpers.cjs.development.cjs.map +4 -4
- package/dist/helpers.cjs.production.min.cjs +15 -11
- package/dist/helpers.cjs.production.min.cjs.map +4 -4
- package/dist/helpers.esm.js +172 -80
- package/dist/helpers.esm.js.map +4 -4
- package/dist/images/discord.helpers.d.ts +65 -0
- package/dist/images/discord.helpers.d.ts.map +1 -0
- package/dist/images/filestack.helpers.d.ts +92 -0
- package/dist/images/filestack.helpers.d.ts.map +1 -0
- package/dist/images/images.helpers.d.ts +32 -0
- package/dist/images/images.helpers.d.ts.map +1 -0
- package/dist/images/index.d.ts +2 -0
- package/dist/images/index.d.ts.map +1 -0
- package/dist/images/unsplash.helpers.d.ts +64 -0
- package/dist/images/unsplash.helpers.d.ts.map +1 -0
- package/dist/images/url.helpers.d.ts +14 -0
- package/dist/images/url.helpers.d.ts.map +1 -0
- package/dist/index.d.cts +43 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/numbers/index.d.ts +5 -0
- package/dist/numbers/index.d.ts.map +1 -0
- package/dist/state.d.ts +130 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/strings/index.d.ts +2 -0
- package/dist/strings/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +12 -17
- package/src/credential-format.ts +5 -4
- package/src/environment.ts +75 -0
- package/src/index.ts +11 -10
- package/dist/helpers.d.cts +0 -979
- package/dist/helpers.d.ts +0 -979
package/src/credential-format.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
StoredCredential,
|
|
6
6
|
StoredCredentialEnvelope,
|
|
7
7
|
VC,
|
|
8
|
+
VP,
|
|
8
9
|
} from '@learncard/types';
|
|
9
10
|
import { isStoredCredentialEnvelope } from '@learncard/types';
|
|
10
11
|
|
|
@@ -485,8 +486,8 @@ const projectJwtVcCompactToVc = (compact: string): VC | undefined => {
|
|
|
485
486
|
* `read.get` result without branching themselves).
|
|
486
487
|
*/
|
|
487
488
|
export const resolveStorageReadResult = (
|
|
488
|
-
value: VC | StoredCredentialEnvelope | undefined
|
|
489
|
-
): VC | StoredCredentialEnvelope | undefined => {
|
|
489
|
+
value: VC | VP | StoredCredentialEnvelope | undefined
|
|
490
|
+
): VC | VP | StoredCredentialEnvelope | undefined => {
|
|
490
491
|
if (!value) return value;
|
|
491
492
|
if (!isStoredCredentialEnvelope(value)) return value;
|
|
492
493
|
const projected = projectEnvelopeToDisplayVc(value);
|
|
@@ -499,8 +500,8 @@ const inferW3cVersionFromContext = (vc: unknown): 'w3c-vc-2.0' | 'w3c-vc-1.1' =>
|
|
|
499
500
|
const contexts = Array.isArray(contextRaw)
|
|
500
501
|
? contextRaw
|
|
501
502
|
: contextRaw !== undefined
|
|
502
|
-
|
|
503
|
-
|
|
503
|
+
? [contextRaw]
|
|
504
|
+
: [];
|
|
504
505
|
const isV2 = contexts.some(
|
|
505
506
|
c => typeof c === 'string' && c.includes('w3.org/ns/credentials/v2')
|
|
506
507
|
);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export type EnvironmentSource = {
|
|
4
|
+
project: string;
|
|
5
|
+
source: string;
|
|
6
|
+
examplePath: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export class EnvironmentConfigurationError extends Error {
|
|
10
|
+
constructor(message: string) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'EnvironmentConfigurationError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const requiredEnvironmentString = z.string().trim().min(1, 'Required but missing');
|
|
17
|
+
|
|
18
|
+
export const optionalEnvironmentString = z.preprocess(
|
|
19
|
+
value => (value === '' ? undefined : value),
|
|
20
|
+
requiredEnvironmentString.optional()
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export const optionalEnvironmentUrl = z.preprocess(
|
|
24
|
+
value => (value === '' ? undefined : value),
|
|
25
|
+
z.url('Expected a valid URL').optional()
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Deployment manifests historically use both true/false and 1/0. These are the complete
|
|
30
|
+
* accepted spellings; every other value fails validation.
|
|
31
|
+
*/
|
|
32
|
+
export const environmentBoolean = z
|
|
33
|
+
.enum(['true', 'false', '1', '0'])
|
|
34
|
+
.transform(value => value === 'true' || value === '1');
|
|
35
|
+
|
|
36
|
+
export const optionalEnvironmentBoolean = z.preprocess(
|
|
37
|
+
value => (value === '' || value === undefined ? undefined : value),
|
|
38
|
+
environmentBoolean.optional()
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export const environmentPort = z.coerce.number().int().min(1).max(65_535);
|
|
42
|
+
|
|
43
|
+
export const optionalEnvironmentPort = z.preprocess(
|
|
44
|
+
value => (value === '' || value === undefined ? undefined : value),
|
|
45
|
+
environmentPort.optional()
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
export const parseEnvironment = <Schema extends z.ZodType>(
|
|
49
|
+
schema: Schema,
|
|
50
|
+
raw: Record<string, unknown>,
|
|
51
|
+
context: EnvironmentSource
|
|
52
|
+
): z.output<Schema> => {
|
|
53
|
+
const result = schema.safeParse(raw);
|
|
54
|
+
|
|
55
|
+
if (result.success) return result.data;
|
|
56
|
+
|
|
57
|
+
const issues = result.error.issues
|
|
58
|
+
.map(issue => {
|
|
59
|
+
const key = issue.path.length ? issue.path.map(String).join('.') : '(environment)';
|
|
60
|
+
|
|
61
|
+
return `${key}\n ${issue.message}`;
|
|
62
|
+
})
|
|
63
|
+
.join('\n\n');
|
|
64
|
+
|
|
65
|
+
throw new EnvironmentConfigurationError(
|
|
66
|
+
[
|
|
67
|
+
`Invalid ${context.project} configuration`,
|
|
68
|
+
'',
|
|
69
|
+
issues,
|
|
70
|
+
'',
|
|
71
|
+
`Configuration source: ${context.source}`,
|
|
72
|
+
`Copy ${context.examplePath} to .env and correct the values above.`,
|
|
73
|
+
].join('\n')
|
|
74
|
+
);
|
|
75
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { DataTransformer } from '@trpc/server';
|
|
|
9
9
|
export const isHex = (str: string) => /^[0-9a-f]+$/i.test(str);
|
|
10
10
|
|
|
11
11
|
/** Determines whether or not an object is an encrypted JWE */
|
|
12
|
-
export const isEncrypted = (item:
|
|
12
|
+
export const isEncrypted = (item: unknown): item is JWE => {
|
|
13
13
|
return JWEValidator.safeParse(item).success;
|
|
14
14
|
};
|
|
15
15
|
|
|
@@ -17,7 +17,7 @@ export const isEncrypted = (item: Record<string, any>): item is JWE => {
|
|
|
17
17
|
* tRPC data transformer that handles RegExp serialization/deserialization
|
|
18
18
|
*/
|
|
19
19
|
export const RegExpTransformer: DataTransformer = {
|
|
20
|
-
serialize(object
|
|
20
|
+
serialize(object) {
|
|
21
21
|
return JSON.stringify(object, (_key, value) => {
|
|
22
22
|
if (value instanceof RegExp) return value.toString(); // Converts to format /pattern/flags
|
|
23
23
|
|
|
@@ -25,7 +25,7 @@ export const RegExpTransformer: DataTransformer = {
|
|
|
25
25
|
});
|
|
26
26
|
},
|
|
27
27
|
|
|
28
|
-
deserialize(object
|
|
28
|
+
deserialize(object) {
|
|
29
29
|
// Old clients will for some reason already be deserialized, so this checks for that to retain
|
|
30
30
|
// backwards compat
|
|
31
31
|
if (typeof object !== 'string') return object;
|
|
@@ -51,14 +51,14 @@ export const RegExpTransformer: DataTransformer = {
|
|
|
51
51
|
/**
|
|
52
52
|
* Determines if a credential uses VC 2.0 format by checking the context array
|
|
53
53
|
*/
|
|
54
|
-
export const isVC2Format = (credential:
|
|
55
|
-
if (!credential
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
export const isVC2Format = (credential: unknown): boolean => {
|
|
55
|
+
if (!credential || typeof credential !== 'object' || !('@context' in credential)) return false;
|
|
56
|
+
|
|
57
|
+
const context = credential['@context'];
|
|
58
58
|
|
|
59
|
-
return
|
|
60
|
-
context =>
|
|
61
|
-
|
|
59
|
+
return Array.isArray(context)
|
|
60
|
+
? context.some(value => value === 'https://www.w3.org/ns/credentials/v2')
|
|
61
|
+
: context === 'https://www.w3.org/ns/credentials/v2';
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
/** Unwraps a boost credential from a CertifiedBoostCredential, if it is one */
|
|
@@ -86,6 +86,7 @@ export * from './Utilities';
|
|
|
86
86
|
export * from './app-install';
|
|
87
87
|
export * from './credential-format';
|
|
88
88
|
export * from './did';
|
|
89
|
+
export * from './environment';
|
|
89
90
|
|
|
90
91
|
// ADR-0001 Phase 1: format-tagged credential storage projector
|
|
91
92
|
export * from './credential-format';
|