@rest-vir/define-service 1.2.6 → 1.3.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.
@@ -98,6 +98,8 @@ export declare const endpointInitShape: Shape<{
98
98
  * - Any other set value overrides the service's origin requirement (if it has any).
99
99
  */
100
100
  requiredClientOrigin: Shape<import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<(import("@sinclair/typebox").TUnsafe<{
101
+ allOrigins: boolean;
102
+ }> | import("@sinclair/typebox").TUnsafe<{
101
103
  anyOrigin: boolean;
102
104
  }> | import("@sinclair/typebox").TUnsafe<RegExp> | import("@sinclair/typebox").TString | import("@sinclair/typebox").TUndefined | import("@sinclair/typebox").TUnsafe<() => void> | import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<(import("@sinclair/typebox").TUnsafe<{
103
105
  anyOrigin: boolean;
@@ -1,7 +1,7 @@
1
1
  import { type MaybePromise } from '@augment-vir/common';
2
2
  /**
3
- * Explicity denotes that any origin is allowed. Use {@link isAnyOrigin} to check if something is
4
- * equal to this.
3
+ * Explicity denotes that any origin (`*`) is allowed. Use {@link isAnyOrigin} to check if something
4
+ * is equal to this.
5
5
  *
6
6
  * @category Internal
7
7
  * @category Package : @rest-vir/define-service
@@ -26,6 +26,34 @@ export declare function isAnyOrigin(input: unknown): input is AnyOrigin;
26
26
  * @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
27
27
  */
28
28
  export type AnyOrigin = typeof AnyOrigin;
29
+ /**
30
+ * Different from {@link AnyOrigin} in that it accepts _all origins_ as the accepted origin. In
31
+ * practice this is similar to {@link AnyOrigin} but allows credentials to be included in requests
32
+ * when the browser normally blocks them for {@link AnyOrigin} (`*`).
33
+ *
34
+ * @category Internal
35
+ * @category Package : @rest-vir/define-service
36
+ * @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
37
+ */
38
+ export declare const AllOrigins: {
39
+ allOrigins: boolean;
40
+ };
41
+ /**
42
+ * Checks if the input is equal to {@link AllOrigins}.
43
+ *
44
+ * @category Internal
45
+ * @category Package : @rest-vir/define-service
46
+ * @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
47
+ */
48
+ export declare function isAllOrigins(input: unknown): input is AllOrigins;
49
+ /**
50
+ * Type for {@link AllOrigins}.
51
+ *
52
+ * @category Internal
53
+ * @category Package : @rest-vir/define-service
54
+ * @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
55
+ */
56
+ export type AllOrigins = typeof AllOrigins;
29
57
  /**
30
58
  * Options explained:
31
59
  *
@@ -33,7 +61,9 @@ export type AnyOrigin = typeof AnyOrigin;
33
61
  * parent service's origin requirement. When on the service, `undefined` is not allowed.
34
62
  * - `string`: require all request origins to exactly match the given string.
35
63
  * - `RegExp`: all request origins must match the RegExp.
36
- * - {@link AnyOrigin}: allow any origin.
64
+ * - {@link AnyOrigin}: allow any origin with a `*`.
65
+ * - {@link AllOrigins}: accept whatever origin is received as the required origin (See
66
+ * {@link AllOrigins} for details on how this is different from {@link AnyOrigin}).
37
67
  * - A function: allow custom checking. If this function returns something truthy, the origin is
38
68
  * allowed.
39
69
  * - An array: a combination of `string` values, `RegExp` values, or functions to compare against. If
@@ -43,7 +73,7 @@ export type AnyOrigin = typeof AnyOrigin;
43
73
  * @category Package : @rest-vir/define-service
44
74
  * @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
45
75
  */
46
- export type OriginRequirement = undefined | string | RegExp | AnyOrigin | (((origin: string | undefined) => MaybePromise<boolean>) | string | RegExp)[] | ((origin: string | undefined) => MaybePromise<boolean>);
76
+ export type OriginRequirement = undefined | string | RegExp | AnyOrigin | AllOrigins | (((origin: string | undefined) => MaybePromise<boolean>) | string | RegExp)[] | ((origin: string | undefined) => MaybePromise<boolean>);
47
77
  /**
48
78
  * Shape definition for {@link OriginRequirement}.
49
79
  *
@@ -52,6 +82,8 @@ export type OriginRequirement = undefined | string | RegExp | AnyOrigin | (((ori
52
82
  * @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
53
83
  */
54
84
  export declare const originRequirementShape: import("object-shape-tester").Shape<import("object-shape-tester").Shape<import("@sinclair/typebox").TUnion<(import("@sinclair/typebox").TUnsafe<{
85
+ allOrigins: boolean;
86
+ }> | import("@sinclair/typebox").TUnsafe<{
55
87
  anyOrigin: boolean;
56
88
  }> | import("@sinclair/typebox").TUnsafe<RegExp> | import("@sinclair/typebox").TString | import("@sinclair/typebox").TUndefined | import("@sinclair/typebox").TUnsafe<() => void> | import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<(import("@sinclair/typebox").TUnsafe<{
57
89
  anyOrigin: boolean;
@@ -1,8 +1,8 @@
1
1
  import { check } from '@augment-vir/assert';
2
2
  import { classShape, defineShape, exactShape, unionShape } from 'object-shape-tester';
3
3
  /**
4
- * Explicity denotes that any origin is allowed. Use {@link isAnyOrigin} to check if something is
5
- * equal to this.
4
+ * Explicity denotes that any origin (`*`) is allowed. Use {@link isAnyOrigin} to check if something
5
+ * is equal to this.
6
6
  *
7
7
  * @category Internal
8
8
  * @category Package : @rest-vir/define-service
@@ -21,6 +21,28 @@ export const AnyOrigin = {
21
21
  export function isAnyOrigin(input) {
22
22
  return check.jsonEquals(input, AnyOrigin);
23
23
  }
24
+ /**
25
+ * Different from {@link AnyOrigin} in that it accepts _all origins_ as the accepted origin. In
26
+ * practice this is similar to {@link AnyOrigin} but allows credentials to be included in requests
27
+ * when the browser normally blocks them for {@link AnyOrigin} (`*`).
28
+ *
29
+ * @category Internal
30
+ * @category Package : @rest-vir/define-service
31
+ * @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
32
+ */
33
+ export const AllOrigins = {
34
+ allOrigins: true,
35
+ };
36
+ /**
37
+ * Checks if the input is equal to {@link AllOrigins}.
38
+ *
39
+ * @category Internal
40
+ * @category Package : @rest-vir/define-service
41
+ * @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
42
+ */
43
+ export function isAllOrigins(input) {
44
+ return check.jsonEquals(input, AllOrigins);
45
+ }
24
46
  /**
25
47
  * Shape definition for {@link OriginRequirement}.
26
48
  *
@@ -28,7 +50,7 @@ export function isAnyOrigin(input) {
28
50
  * @category Package : @rest-vir/define-service
29
51
  * @package [`@rest-vir/define-service`](https://www.npmjs.com/package/@rest-vir/define-service)
30
52
  */
31
- export const originRequirementShape = defineShape(unionShape(undefined, '', exactShape(AnyOrigin), classShape(RegExp), () => { }, [
53
+ export const originRequirementShape = defineShape(unionShape(undefined, '', exactShape(AllOrigins), exactShape(AnyOrigin), classShape(RegExp), () => { }, [
32
54
  unionShape('', exactShape(AnyOrigin), classShape(RegExp), () => { }),
33
55
  ]));
34
56
  /**
@@ -44,6 +66,9 @@ export async function checkOriginRequirement(origin, originRequirement) {
44
66
  /** Any origin has been explicitly allowed. */
45
67
  return AnyOrigin;
46
68
  }
69
+ else if (isAllOrigins(originRequirement)) {
70
+ return true;
71
+ }
47
72
  else if (originRequirement == undefined) {
48
73
  /** No checking occurred. */
49
74
  return undefined;
@@ -283,7 +283,7 @@ function toRegExp(tokens, keys) {
283
283
  result += `(${negate(DEFAULT_DELIMITER, isSafeSegmentParam ? '' : backtrack)}+)`;
284
284
  }
285
285
  else {
286
- result += `([\\s\\S]+)`;
286
+ result += String.raw `([\s\S]+)`;
287
287
  }
288
288
  keys.push(token);
289
289
  backtrack = '';
@@ -303,5 +303,5 @@ function negate(delimiter, backtrack) {
303
303
  if (delimiter.length < 2) {
304
304
  return `(?:(?!${escape(backtrack)})[^${escape(delimiter)}])`;
305
305
  }
306
- return `(?:(?!${escape(backtrack)}|${escape(delimiter)})[\\s\\S])`;
306
+ return String.raw `(?:(?!${escape(backtrack)}|${escape(delimiter)})[\s\S])`;
307
307
  }
@@ -137,6 +137,8 @@ export declare const webSocketInitShape: Shape<{
137
137
  * - Any other set value overrides the service's origin requirement (if it has any).
138
138
  */
139
139
  requiredClientOrigin: Shape<import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<(import("@sinclair/typebox").TUnsafe<{
140
+ allOrigins: boolean;
141
+ }> | import("@sinclair/typebox").TUnsafe<{
140
142
  anyOrigin: boolean;
141
143
  }> | import("@sinclair/typebox").TUnsafe<RegExp> | import("@sinclair/typebox").TString | import("@sinclair/typebox").TUndefined | import("@sinclair/typebox").TUnsafe<() => void> | import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<(import("@sinclair/typebox").TUnsafe<{
142
144
  anyOrigin: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rest-vir/define-service",
3
- "version": "1.2.6",
3
+ "version": "1.3.1",
4
4
  "description": "Define an connect to a declarative and type safe REST and WebSocket service.",
5
5
  "keywords": [
6
6
  "rest",
@@ -40,14 +40,14 @@
40
40
  "test:update": "npm test update"
41
41
  },
42
42
  "dependencies": {
43
- "@augment-vir/assert": "^31.46.1",
44
- "@augment-vir/common": "^31.46.1",
43
+ "@augment-vir/assert": "^31.48.0",
44
+ "@augment-vir/common": "^31.48.0",
45
45
  "date-vir": "^8.0.0",
46
- "type-fest": "^5.1.0",
46
+ "type-fest": "^5.2.0",
47
47
  "url-vir": "^2.1.6"
48
48
  },
49
49
  "devDependencies": {
50
- "@augment-vir/test": "^31.46.1",
50
+ "@augment-vir/test": "^31.48.0",
51
51
  "@web/dev-server-esbuild": "^1.0.4",
52
52
  "@web/test-runner": "^0.20.2",
53
53
  "@web/test-runner-commands": "^0.9.0",