@takeshape/schema 7.194.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/README.md +5 -0
- package/es/api-version.js +21 -0
- package/es/auth-schemas.js +0 -0
- package/es/builtin-schema.js +590 -0
- package/es/content-schema-transform.js +192 -0
- package/es/entitlements.js +0 -0
- package/es/enum.js +11 -0
- package/es/get-is-leaf.js +58 -0
- package/es/index.js +25 -0
- package/es/migration.js +413 -0
- package/es/mocks.js +47 -0
- package/es/patterns.js +0 -0
- package/es/project-schema/index.js +10 -0
- package/es/project-schema/v1.0.0.js +0 -0
- package/es/project-schema/v3.0.0.js +0 -0
- package/es/project-schema/v3.1.0.js +0 -0
- package/es/project-schema/v3.2.0.js +0 -0
- package/es/project-schema/v3.3.0.js +0 -0
- package/es/project-schema/v3.4.0.js +0 -0
- package/es/project-schema/v3.5.0.js +0 -0
- package/es/project-schema/v3.5.1.js +0 -0
- package/es/project-schema/v3.6.0.js +0 -0
- package/es/refs.js +301 -0
- package/es/resolvers.js +2 -0
- package/es/scalars.js +4 -0
- package/es/schema-util.js +1197 -0
- package/es/schemas/auth-schemas.json +313 -0
- package/es/schemas/project-schema/meta-schema-v1.0.0.json +209 -0
- package/es/schemas/project-schema/meta-schema-v3.0.0.json +609 -0
- package/es/schemas/project-schema/meta-schema-v3.1.0.json +609 -0
- package/es/schemas/project-schema/meta-schema-v3.2.0.json +613 -0
- package/es/schemas/project-schema/meta-schema-v3.3.0.json +613 -0
- package/es/schemas/project-schema/meta-schema-v3.4.0.json +613 -0
- package/es/schemas/project-schema/meta-schema-v3.5.0.json +627 -0
- package/es/schemas/project-schema/meta-schema-v3.5.1.json +630 -0
- package/es/schemas/project-schema/meta-schema-v3.6.0.json +633 -0
- package/es/schemas/project-schema/v1.0.0.json +321 -0
- package/es/schemas/project-schema/v3.0.0.json +411 -0
- package/es/schemas/project-schema/v3.1.0.json +569 -0
- package/es/schemas/project-schema/v3.2.0.json +577 -0
- package/es/schemas/project-schema/v3.3.0.json +578 -0
- package/es/schemas/project-schema/v3.4.0.json +568 -0
- package/es/schemas/project-schema/v3.5.0.json +568 -0
- package/es/schemas/project-schema/v3.5.1.json +568 -0
- package/es/schemas/project-schema/v3.6.0.json +584 -0
- package/es/schemas/project-schema.json +16 -0
- package/es/schemas/user-schema.json +58 -0
- package/es/services.js +379 -0
- package/es/taxonomies.js +55 -0
- package/es/template-shapes.js +79 -0
- package/es/types.js +202 -0
- package/es/unions.js +137 -0
- package/es/user-schema.js +0 -0
- package/es/util/detect-cycles.js +54 -0
- package/es/util/index.js +1 -0
- package/es/validate.js +764 -0
- package/es/versions.js +4 -0
- package/es/workflows.js +69 -0
- package/examples/.pnpm-debug.log +20 -0
- package/examples/v1_0_0/beer-schema.json +125 -0
- package/examples/v1_0_0/blog-schema.json +192 -0
- package/examples/v1_0_0/brewery-schema.json +232 -0
- package/examples/v1_0_0/complex-project-schema.json +3197 -0
- package/examples/v1_0_0/error-schema.json +275 -0
- package/examples/v1_0_0/frank-and-fred-schema.json +21387 -0
- package/examples/v1_0_0/massive-schema.json +6930 -0
- package/examples/v1_0_0/post-schema.json +83 -0
- package/examples/v1_0_0/real-world-schema.json +797 -0
- package/examples/v1_0_0/recursive-repeater-schema.json +69 -0
- package/examples/v1_0_0/recursive-schema.json +79 -0
- package/examples/v1_0_0/schema-with-repeater-draftjs.json +292 -0
- package/examples/v1_0_0/shape-books.json +797 -0
- package/examples/v1_0_0/user-schema-no-required.json +84 -0
- package/examples/v1_0_0/user-schema-with-defaults.json +105 -0
- package/examples/v1_0_0/user-schema-with-obj-prop.json +92 -0
- package/examples/v1_0_0/user-schema.json +87 -0
- package/examples/v3_0_0/rick-and-morty-rest.json +62 -0
- package/examples/v3_0_0/shopify-lookbook.json +1172 -0
- package/examples/v3_0_0/shopify-store-with-widget.json +11323 -0
- package/examples/v3_2_0/blog-schema.json +378 -0
- package/examples/v3_2_0/brewery-schema.json +385 -0
- package/examples/v3_2_0/complex-project-schema.json +3748 -0
- package/examples/v3_2_0/frank-and-fred-schema.json +19217 -0
- package/examples/v3_2_0/massive-schema.json +6676 -0
- package/examples/v3_2_0/pet-oneof-array.json +323 -0
- package/examples/v3_2_0/post-schema.json +265 -0
- package/examples/v3_2_0/real-world-schema.json +970 -0
- package/examples/v3_2_0/recursive-repeater-schema.json +144 -0
- package/examples/v3_2_0/recursive-schema.json +151 -0
- package/examples/v3_2_0/rick-and-morty-rest.json +65 -0
- package/examples/v3_2_0/schema-with-repeater-draftjs.json +381 -0
- package/examples/v3_2_0/shape-books.json +1044 -0
- package/examples/v3_2_0/shopify-store-with-widget.json +11016 -0
- package/examples/v3_2_0/user-schema-no-required.json +174 -0
- package/examples/v3_2_0/user-schema-with-defaults.json +187 -0
- package/examples/v3_3_0/blog-schema.json +405 -0
- package/examples/v3_3_0/brewery-schema.json +406 -0
- package/examples/v3_3_0/complex-project-schema.json +4076 -0
- package/examples/v3_3_0/frank-and-fred-schema.json +20913 -0
- package/examples/v3_3_0/massive-schema.json +7309 -0
- package/examples/v3_3_0/pet-oneof-array.json +380 -0
- package/examples/v3_3_0/post-schema.json +248 -0
- package/examples/v3_3_0/real-world-schema.json +1046 -0
- package/examples/v3_3_0/recursive-repeater-schema.json +154 -0
- package/examples/v3_3_0/recursive-schema.json +161 -0
- package/examples/v3_3_0/rick-and-morty-rest.json +101 -0
- package/examples/v3_3_0/schema-with-repeater-draftjs.json +393 -0
- package/examples/v3_3_0/shape-books.json +1121 -0
- package/examples/v3_3_0/shopify-lookbook.json +1196 -0
- package/examples/v3_3_0/shopify-store-with-widget.json +11320 -0
- package/examples/v3_3_0/user-schema-no-required.json +185 -0
- package/examples/v3_3_0/user-schema-with-defaults.json +210 -0
- package/examples/v3_4_0/blog-schema.json +405 -0
- package/examples/v3_4_0/brewery-schema.json +406 -0
- package/examples/v3_4_0/complex-project-schema.json +4076 -0
- package/examples/v3_4_0/frank-and-fred-schema.json +20913 -0
- package/examples/v3_4_0/massive-schema.json +7309 -0
- package/examples/v3_4_0/pet-oneof-array.json +420 -0
- package/examples/v3_4_0/post-schema.json +248 -0
- package/examples/v3_4_0/real-world-schema.json +1046 -0
- package/examples/v3_4_0/recursive-repeater-schema.json +154 -0
- package/examples/v3_4_0/recursive-schema.json +161 -0
- package/examples/v3_4_0/rick-and-morty-rest.json +101 -0
- package/examples/v3_4_0/schema-with-repeater-draftjs.json +393 -0
- package/examples/v3_4_0/shape-books.json +1121 -0
- package/examples/v3_4_0/shopify-lookbook.json +1196 -0
- package/examples/v3_4_0/shopify-store-with-widget.json +11323 -0
- package/examples/v3_4_0/user-schema-no-required.json +185 -0
- package/examples/v3_4_0/user-schema-with-defaults.json +210 -0
- package/examples/v3_5_0/blog-schema.json +405 -0
- package/examples/v3_5_0/brewery-schema.json +406 -0
- package/examples/v3_5_0/complex-project-schema.json +4076 -0
- package/examples/v3_5_0/frank-and-fred-schema.json +20913 -0
- package/examples/v3_5_0/massive-schema.json +7309 -0
- package/examples/v3_5_0/pet-oneof-array.json +420 -0
- package/examples/v3_5_0/post-schema.json +248 -0
- package/examples/v3_5_0/real-world-schema.json +1046 -0
- package/examples/v3_5_0/recursive-repeater-schema.json +154 -0
- package/examples/v3_5_0/recursive-schema.json +161 -0
- package/examples/v3_5_0/rick-and-morty-rest.json +101 -0
- package/examples/v3_5_0/schema-with-repeater-draftjs.json +393 -0
- package/examples/v3_5_0/shape-books.json +1121 -0
- package/examples/v3_5_0/shopify-lookbook.json +1196 -0
- package/examples/v3_5_0/shopify-store-with-widget.json +12271 -0
- package/examples/v3_5_0/user-schema-no-required.json +185 -0
- package/examples/v3_5_0/user-schema-with-defaults.json +210 -0
- package/examples/v3_5_1/blog-schema.json +405 -0
- package/examples/v3_5_1/brewery-schema.json +406 -0
- package/examples/v3_5_1/complex-project-schema.json +4076 -0
- package/examples/v3_5_1/frank-and-fred-schema.json +20913 -0
- package/examples/v3_5_1/massive-schema.json +7309 -0
- package/examples/v3_5_1/pet-oneof-array.json +420 -0
- package/examples/v3_5_1/post-schema.json +248 -0
- package/examples/v3_5_1/real-world-schema.json +1046 -0
- package/examples/v3_5_1/recursive-repeater-schema.json +154 -0
- package/examples/v3_5_1/recursive-schema.json +161 -0
- package/examples/v3_5_1/rick-and-morty-rest.json +101 -0
- package/examples/v3_5_1/schema-with-repeater-draftjs.json +393 -0
- package/examples/v3_5_1/shape-books.json +1121 -0
- package/examples/v3_5_1/shopify-lookbook.json +1196 -0
- package/examples/v3_5_1/shopify-store-with-widget.json +12271 -0
- package/examples/v3_5_1/stripe-starter-resolved.json +21419 -0
- package/examples/v3_5_1/user-schema-no-required.json +185 -0
- package/examples/v3_5_1/user-schema-with-defaults.json +210 -0
- package/examples/v3_6_0/blog-schema.json +405 -0
- package/examples/v3_6_0/brewery-schema.json +406 -0
- package/examples/v3_6_0/complex-project-schema.json +4076 -0
- package/examples/v3_6_0/frank-and-fred-schema.json +20913 -0
- package/examples/v3_6_0/massive-schema.json +7309 -0
- package/examples/v3_6_0/pet-oneof-array.json +420 -0
- package/examples/v3_6_0/post-schema.json +248 -0
- package/examples/v3_6_0/real-world-schema.json +1046 -0
- package/examples/v3_6_0/recursive-repeater-schema.json +154 -0
- package/examples/v3_6_0/recursive-schema.json +161 -0
- package/examples/v3_6_0/rick-and-morty-rest.json +101 -0
- package/examples/v3_6_0/schema-with-repeater-draftjs.json +393 -0
- package/examples/v3_6_0/shape-books.json +1121 -0
- package/examples/v3_6_0/shopify-lookbook.json +1196 -0
- package/examples/v3_6_0/shopify-store-with-widget.json +12271 -0
- package/examples/v3_6_0/stripe-starter-resolved.json +21419 -0
- package/examples/v3_6_0/user-schema-no-required.json +185 -0
- package/examples/v3_6_0/user-schema-with-defaults.json +210 -0
- package/lib/api-version.d.ts +6 -0
- package/lib/api-version.d.ts.map +1 -0
- package/lib/api-version.js +36 -0
- package/lib/auth-schemas.d.ts +105 -0
- package/lib/auth-schemas.d.ts.map +1 -0
- package/lib/auth-schemas.js +1 -0
- package/lib/builtin-schema.d.ts +8 -0
- package/lib/builtin-schema.d.ts.map +1 -0
- package/lib/builtin-schema.js +606 -0
- package/lib/content-schema-transform.d.ts +41 -0
- package/lib/content-schema-transform.d.ts.map +1 -0
- package/lib/content-schema-transform.js +217 -0
- package/lib/entitlements.d.ts +1 -0
- package/lib/entitlements.d.ts.map +1 -0
- package/lib/entitlements.js +1 -0
- package/lib/enum.d.ts +3 -0
- package/lib/enum.d.ts.map +1 -0
- package/lib/enum.js +18 -0
- package/lib/get-is-leaf.d.ts +4 -0
- package/lib/get-is-leaf.d.ts.map +1 -0
- package/lib/get-is-leaf.js +68 -0
- package/lib/index.d.ts +27 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +359 -0
- package/lib/migration.d.ts +55 -0
- package/lib/migration.d.ts.map +1 -0
- package/lib/migration.js +463 -0
- package/lib/mocks.d.ts +13 -0
- package/lib/mocks.d.ts.map +1 -0
- package/lib/mocks.js +61 -0
- package/lib/patterns.d.ts +13 -0
- package/lib/patterns.d.ts.map +1 -0
- package/lib/patterns.js +1 -0
- package/lib/project-schema/index.d.ts +21 -0
- package/lib/project-schema/index.d.ts.map +1 -0
- package/lib/project-schema/index.js +122 -0
- package/lib/project-schema/v1.0.0.d.ts +293 -0
- package/lib/project-schema/v1.0.0.d.ts.map +1 -0
- package/lib/project-schema/v1.0.0.js +1 -0
- package/lib/project-schema/v3.0.0.d.ts +480 -0
- package/lib/project-schema/v3.0.0.d.ts.map +1 -0
- package/lib/project-schema/v3.0.0.js +1 -0
- package/lib/project-schema/v3.1.0.d.ts +623 -0
- package/lib/project-schema/v3.1.0.d.ts.map +1 -0
- package/lib/project-schema/v3.1.0.js +1 -0
- package/lib/project-schema/v3.2.0.d.ts +634 -0
- package/lib/project-schema/v3.2.0.d.ts.map +1 -0
- package/lib/project-schema/v3.2.0.js +1 -0
- package/lib/project-schema/v3.3.0.d.ts +634 -0
- package/lib/project-schema/v3.3.0.d.ts.map +1 -0
- package/lib/project-schema/v3.3.0.js +1 -0
- package/lib/project-schema/v3.4.0.d.ts +626 -0
- package/lib/project-schema/v3.4.0.d.ts.map +1 -0
- package/lib/project-schema/v3.4.0.js +1 -0
- package/lib/project-schema/v3.5.0.d.ts +651 -0
- package/lib/project-schema/v3.5.0.d.ts.map +1 -0
- package/lib/project-schema/v3.5.0.js +1 -0
- package/lib/project-schema/v3.5.1.d.ts +651 -0
- package/lib/project-schema/v3.5.1.d.ts.map +1 -0
- package/lib/project-schema/v3.5.1.js +1 -0
- package/lib/project-schema/v3.6.0.d.ts +660 -0
- package/lib/project-schema/v3.6.0.d.ts.map +1 -0
- package/lib/project-schema/v3.6.0.js +1 -0
- package/lib/refs.d.ts +122 -0
- package/lib/refs.d.ts.map +1 -0
- package/lib/refs.js +359 -0
- package/lib/resolvers.d.ts +4 -0
- package/lib/resolvers.d.ts.map +1 -0
- package/lib/resolvers.js +10 -0
- package/lib/scalars.d.ts +3 -0
- package/lib/scalars.d.ts.map +1 -0
- package/lib/scalars.js +13 -0
- package/lib/schema-util.d.ts +201 -0
- package/lib/schema-util.d.ts.map +1 -0
- package/lib/schema-util.js +1353 -0
- package/lib/schemas/auth-schemas.json +313 -0
- package/lib/schemas/project-schema/meta-schema-v1.0.0.json +209 -0
- package/lib/schemas/project-schema/meta-schema-v3.0.0.json +609 -0
- package/lib/schemas/project-schema/meta-schema-v3.1.0.json +609 -0
- package/lib/schemas/project-schema/meta-schema-v3.2.0.json +613 -0
- package/lib/schemas/project-schema/meta-schema-v3.3.0.json +613 -0
- package/lib/schemas/project-schema/meta-schema-v3.4.0.json +613 -0
- package/lib/schemas/project-schema/meta-schema-v3.5.0.json +627 -0
- package/lib/schemas/project-schema/meta-schema-v3.5.1.json +630 -0
- package/lib/schemas/project-schema/meta-schema-v3.6.0.json +633 -0
- package/lib/schemas/project-schema/v1.0.0.json +321 -0
- package/lib/schemas/project-schema/v3.0.0.json +411 -0
- package/lib/schemas/project-schema/v3.1.0.json +569 -0
- package/lib/schemas/project-schema/v3.2.0.json +577 -0
- package/lib/schemas/project-schema/v3.3.0.json +578 -0
- package/lib/schemas/project-schema/v3.4.0.json +568 -0
- package/lib/schemas/project-schema/v3.5.0.json +568 -0
- package/lib/schemas/project-schema/v3.5.1.json +568 -0
- package/lib/schemas/project-schema/v3.6.0.json +584 -0
- package/lib/schemas/project-schema.json +16 -0
- package/lib/schemas/user-schema.json +58 -0
- package/lib/services.d.ts +71 -0
- package/lib/services.d.ts.map +1 -0
- package/lib/services.js +413 -0
- package/lib/taxonomies.d.ts +16 -0
- package/lib/taxonomies.d.ts.map +1 -0
- package/lib/taxonomies.js +69 -0
- package/lib/template-shapes.d.ts +32 -0
- package/lib/template-shapes.d.ts.map +1 -0
- package/lib/template-shapes.js +100 -0
- package/lib/types.d.ts +187 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +289 -0
- package/lib/unions.d.ts +29 -0
- package/lib/unions.d.ts.map +1 -0
- package/lib/unions.js +167 -0
- package/lib/user-schema.d.ts +39 -0
- package/lib/user-schema.d.ts.map +1 -0
- package/lib/user-schema.js +1 -0
- package/lib/util/detect-cycles.d.ts +6 -0
- package/lib/util/detect-cycles.d.ts.map +1 -0
- package/lib/util/detect-cycles.js +61 -0
- package/lib/util/index.d.ts +2 -0
- package/lib/util/index.d.ts.map +1 -0
- package/lib/util/index.js +18 -0
- package/lib/validate.d.ts +49 -0
- package/lib/validate.d.ts.map +1 -0
- package/lib/validate.js +823 -0
- package/lib/versions.d.ts +5 -0
- package/lib/versions.d.ts.map +1 -0
- package/lib/versions.js +14 -0
- package/lib/workflows.d.ts +15 -0
- package/lib/workflows.d.ts.map +1 -0
- package/lib/workflows.js +92 -0
- package/package.json +65 -0
package/es/services.js
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { upperCamel, deepClone } from '@takeshape/util';
|
|
2
|
+
import { mergeWithArrayMerge } from '@takeshape/util/lib/merge';
|
|
3
|
+
import { isEncryptedServiceConfig, isAnyServiceConfig } from './types';
|
|
4
|
+
import projectMetaSchema from './schemas/project-schema/v3.1.0.json';
|
|
5
|
+
import { createSchemaValidator } from '@takeshape/json-schema';
|
|
6
|
+
import isObject from 'lodash/isObject';
|
|
7
|
+
import isNull from 'lodash/isNull';
|
|
8
|
+
import isString from 'lodash/isString';
|
|
9
|
+
import isUndefined from 'lodash/isUndefined';
|
|
10
|
+
import { getServiceInfo, SERVICE_OBJECT_PATTERN_NAME } from './schema-util';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* `graphql:my-key` `my-key`
|
|
14
|
+
*/
|
|
15
|
+
export function parseV3ServiceStr(service) {
|
|
16
|
+
const parts = service.split(':');
|
|
17
|
+
return {
|
|
18
|
+
provider: parts.length > 1 ? parts[0] : undefined,
|
|
19
|
+
id: parts.length > 1 ? parts[1] : parts[0]
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Given a `StoredServiceConfig` returns a usable `ServiceConfig` with the
|
|
24
|
+
* authentication object decrypted.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
export function decryptServiceConfig(decryptFn, storedServiceConfig) {
|
|
28
|
+
let authentication;
|
|
29
|
+
|
|
30
|
+
if (isEncryptedServiceConfig(storedServiceConfig)) {
|
|
31
|
+
authentication = decryptFn(storedServiceConfig.authentication);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return { ...storedServiceConfig,
|
|
35
|
+
authentication
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Given a `StoredServiceMap` returns a usable `ServiceMap` with all the
|
|
40
|
+
* authentication objects decrypted.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
export async function decryptServiceMap(decryptFn, storedServiceMap) {
|
|
44
|
+
return Object.entries(storedServiceMap).reduce((result, [serviceKey, serviceConfig]) => {
|
|
45
|
+
return result.set(serviceKey, decryptServiceConfig(decryptFn, serviceConfig));
|
|
46
|
+
}, new Map());
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Provides a `ServiceConfig` validator based on the JSON-schema.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
function createServiceConfigValidator() {
|
|
53
|
+
const {
|
|
54
|
+
serviceConfig: schema,
|
|
55
|
+
...definitions
|
|
56
|
+
} = projectMetaSchema.definitions;
|
|
57
|
+
const validationSchema = {
|
|
58
|
+
$id: '#serviceConfig',
|
|
59
|
+
definitions,
|
|
60
|
+
...schema
|
|
61
|
+
};
|
|
62
|
+
return createSchemaValidator(validationSchema);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Provides a `ServiceAuthentication` validator. Due to a behavior of `oneOf` and
|
|
66
|
+
* the `removeAdditional` setting, where valid properties are being stripped,
|
|
67
|
+
* this is validated separate from the overall config. May have something to do with
|
|
68
|
+
* JSON Schema's lack of handling for discriminated unions?
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
function createServiceAuthenticationValidator() {
|
|
73
|
+
const {
|
|
74
|
+
serviceAuthentication: schema,
|
|
75
|
+
...definitions
|
|
76
|
+
} = projectMetaSchema.definitions;
|
|
77
|
+
const validationSchema = {
|
|
78
|
+
$id: '#serviceAuthentication',
|
|
79
|
+
definitions,
|
|
80
|
+
...schema
|
|
81
|
+
};
|
|
82
|
+
return createSchemaValidator(validationSchema, [], {
|
|
83
|
+
removeAdditional: false
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const serviceConfigValidator = createServiceConfigValidator();
|
|
88
|
+
const serviceAuthenticationValidator = createServiceAuthenticationValidator();
|
|
89
|
+
/**
|
|
90
|
+
* Prepare a `ServiceConfig` object update, validating the overall structure
|
|
91
|
+
* and encrypting the `ServiceAuthentication` object.
|
|
92
|
+
*/
|
|
93
|
+
// eslint-disable-next-line max-params
|
|
94
|
+
|
|
95
|
+
export function prepareServiceUpdate(encryptFn, decryptFn, projectSchema, partialServiceConfig, serviceKey) {
|
|
96
|
+
var _projectSchema$servic;
|
|
97
|
+
|
|
98
|
+
const storedServiceConfig = (_projectSchema$servic = projectSchema.services) === null || _projectSchema$servic === void 0 ? void 0 : _projectSchema$servic[serviceKey];
|
|
99
|
+
let newServiceConfig = partialServiceConfig;
|
|
100
|
+
|
|
101
|
+
if (storedServiceConfig) {
|
|
102
|
+
const existingServiceConfig = decryptServiceConfig(decryptFn, storedServiceConfig);
|
|
103
|
+
newServiceConfig = mergeWithArrayMerge(existingServiceConfig, partialServiceConfig);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (isNull(newServiceConfig.authentication)) {
|
|
107
|
+
delete newServiceConfig.authentication;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let authentication;
|
|
111
|
+
|
|
112
|
+
if (newServiceConfig.authentication) {
|
|
113
|
+
// Copy authentication, to ensure validation doesn't remove any properties
|
|
114
|
+
authentication = deepClone(newServiceConfig.authentication);
|
|
115
|
+
const {
|
|
116
|
+
errorsText: authenticationErrors
|
|
117
|
+
} = serviceAuthenticationValidator(authentication);
|
|
118
|
+
|
|
119
|
+
if (authenticationErrors) {
|
|
120
|
+
throw new Error(authenticationErrors);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const {
|
|
125
|
+
errorsText: configErrors
|
|
126
|
+
} = serviceConfigValidator(newServiceConfig);
|
|
127
|
+
|
|
128
|
+
if (configErrors) {
|
|
129
|
+
throw new Error(configErrors);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let serviceConfig;
|
|
133
|
+
|
|
134
|
+
if (authentication) {
|
|
135
|
+
serviceConfig = { ...newServiceConfig,
|
|
136
|
+
authentication: encryptFn(authentication)
|
|
137
|
+
};
|
|
138
|
+
} else {
|
|
139
|
+
serviceConfig = newServiceConfig;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return serviceConfig;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get a service config from a project schema.
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
export function getStoredServiceConfig(projectSchema, serviceKey) {
|
|
149
|
+
var _projectSchema$servic2;
|
|
150
|
+
|
|
151
|
+
return (_projectSchema$servic2 = projectSchema.services) === null || _projectSchema$servic2 === void 0 ? void 0 : _projectSchema$servic2[serviceKey];
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Migration-related Functions
|
|
155
|
+
*
|
|
156
|
+
* All the following code is used in the migration process. At some point
|
|
157
|
+
* migraton code should live outside the standard runtime code.
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Ensures a consistent service config, inluding updating the service
|
|
162
|
+
* authentication object.
|
|
163
|
+
*/
|
|
164
|
+
// eslint-disable-next-line complexity
|
|
165
|
+
|
|
166
|
+
export function updateServiceConfigV3ToV3_1(serviceConfig, serviceKey) {
|
|
167
|
+
if (isAnyServiceConfig(serviceConfig)) {
|
|
168
|
+
if (isString(serviceConfig.authentication) || isUndefined(serviceConfig.authentication)) {
|
|
169
|
+
return serviceConfig;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return serviceConfig;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const auth = serviceConfig.auth;
|
|
176
|
+
const serviceParams = serviceConfig.params || {};
|
|
177
|
+
let {
|
|
178
|
+
provider: serviceKeyProvider,
|
|
179
|
+
id: serviceKeyId
|
|
180
|
+
} = parseV3ServiceStr(serviceKey);
|
|
181
|
+
const authType = serviceParams.authType || undefined;
|
|
182
|
+
const title = serviceParams.name || serviceKeyId;
|
|
183
|
+
|
|
184
|
+
if (serviceKeyId === 'vercel') {
|
|
185
|
+
serviceKeyProvider = 'vercel';
|
|
186
|
+
} else if (serviceKeyId === 'netlify') {
|
|
187
|
+
serviceKeyProvider = 'netlify';
|
|
188
|
+
} // Example schemas had this in params, which are untyped, so adding here just in case
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
if (serviceParams.type === 'rest') {
|
|
192
|
+
serviceKeyProvider = 'rest';
|
|
193
|
+
} else if (serviceParams.type === 'graphql' && serviceKeyProvider !== 'shopify') {
|
|
194
|
+
serviceKeyProvider = 'graphql';
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
let provider;
|
|
198
|
+
let authenticationType;
|
|
199
|
+
let serviceType;
|
|
200
|
+
let namespace;
|
|
201
|
+
|
|
202
|
+
if (serviceKeyProvider === 'shopify') {
|
|
203
|
+
var _serviceParams$namesp;
|
|
204
|
+
|
|
205
|
+
provider = 'shopify';
|
|
206
|
+
authenticationType = 'oauth2Bearer';
|
|
207
|
+
serviceType = 'graphql';
|
|
208
|
+
namespace = (_serviceParams$namesp = serviceParams.namespace) !== null && _serviceParams$namesp !== void 0 ? _serviceParams$namesp : 'Shopify';
|
|
209
|
+
} else if (serviceKeyProvider === 'takeshape') {
|
|
210
|
+
var _serviceParams$namesp2;
|
|
211
|
+
|
|
212
|
+
provider = 'takeshape';
|
|
213
|
+
authenticationType = 'none';
|
|
214
|
+
serviceType = 'takeshape';
|
|
215
|
+
namespace = (_serviceParams$namesp2 = serviceParams.namespace) !== null && _serviceParams$namesp2 !== void 0 ? _serviceParams$namesp2 : 'TakeShape';
|
|
216
|
+
} else if (serviceKeyProvider === 'bigcommerce') {
|
|
217
|
+
var _serviceParams$namesp3;
|
|
218
|
+
|
|
219
|
+
provider = 'bigcommerce';
|
|
220
|
+
authenticationType = 'bearer';
|
|
221
|
+
serviceType = 'graphql';
|
|
222
|
+
namespace = (_serviceParams$namesp3 = serviceParams.namespace) !== null && _serviceParams$namesp3 !== void 0 ? _serviceParams$namesp3 : 'BigCommerce';
|
|
223
|
+
} else if (serviceKeyProvider === 'rest') {
|
|
224
|
+
var _serviceParams$namesp4;
|
|
225
|
+
|
|
226
|
+
provider = 'generic';
|
|
227
|
+
authenticationType = mapAuthType(authType, auth);
|
|
228
|
+
serviceType = 'rest';
|
|
229
|
+
namespace = (_serviceParams$namesp4 = serviceParams.namespace) !== null && _serviceParams$namesp4 !== void 0 ? _serviceParams$namesp4 : upperCamel(title);
|
|
230
|
+
} else if (serviceKeyProvider === 'graphql') {
|
|
231
|
+
var _serviceParams$namesp5;
|
|
232
|
+
|
|
233
|
+
provider = 'generic';
|
|
234
|
+
authenticationType = mapAuthType(authType, auth);
|
|
235
|
+
serviceType = 'graphql';
|
|
236
|
+
namespace = (_serviceParams$namesp5 = serviceParams.namespace) !== null && _serviceParams$namesp5 !== void 0 ? _serviceParams$namesp5 : upperCamel(title);
|
|
237
|
+
} else if (serviceKeyProvider === 'vercel') {
|
|
238
|
+
provider = 'vercel';
|
|
239
|
+
authenticationType = 'oauth2Bearer';
|
|
240
|
+
serviceType = 'deployment';
|
|
241
|
+
} else if (serviceKeyProvider === 'netlify') {
|
|
242
|
+
provider = 'netlify';
|
|
243
|
+
authenticationType = 'oauth2Bearer';
|
|
244
|
+
serviceType = 'deployment';
|
|
245
|
+
} else {
|
|
246
|
+
var _serviceParams$namesp6;
|
|
247
|
+
|
|
248
|
+
provider = 'generic';
|
|
249
|
+
authenticationType = mapAuthType(authType, auth);
|
|
250
|
+
serviceType = 'unknown';
|
|
251
|
+
namespace = (_serviceParams$namesp6 = serviceParams.namespace) !== null && _serviceParams$namesp6 !== void 0 ? _serviceParams$namesp6 : upperCamel(title);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const updatedServiceConfig = {
|
|
255
|
+
title,
|
|
256
|
+
id: serviceKey,
|
|
257
|
+
provider,
|
|
258
|
+
namespace,
|
|
259
|
+
serviceType,
|
|
260
|
+
authenticationType,
|
|
261
|
+
options: { ...serviceParams
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
if (serviceConfig.auth && isObject(serviceConfig.auth)) {
|
|
266
|
+
const authentication = updateServiceAuthentication(updatedServiceConfig.authenticationType, serviceConfig.auth, serviceParams);
|
|
267
|
+
return { ...updatedServiceConfig,
|
|
268
|
+
authentication
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return updatedServiceConfig;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* V1/V3 unencrypted `auth` -> V3.1 `authentication
|
|
276
|
+
*/
|
|
277
|
+
|
|
278
|
+
function updateServiceAuthentication(authenticationType, legacyAuth, legacyParams) {
|
|
279
|
+
if (authenticationType === 'oauth2Bearer') {
|
|
280
|
+
return {
|
|
281
|
+
token: legacyAuth.accessToken,
|
|
282
|
+
scope: legacyAuth.scope,
|
|
283
|
+
header: legacyParams.authHeader
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (authenticationType === 'searchParams' && legacyParams.authProp) {
|
|
288
|
+
return [{
|
|
289
|
+
name: legacyParams.authProp,
|
|
290
|
+
value: legacyAuth.accessToken
|
|
291
|
+
}];
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (authenticationType === 'basic') {
|
|
295
|
+
const [username, password] = Buffer.from(legacyAuth.accessToken, 'base64').toString('utf-8').split(':');
|
|
296
|
+
return {
|
|
297
|
+
username,
|
|
298
|
+
password
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (authenticationType === 'bearer') {
|
|
303
|
+
return {
|
|
304
|
+
token: legacyAuth.accessToken,
|
|
305
|
+
header: legacyParams.authHeader
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function mapAuthType(authType, auth) {
|
|
311
|
+
if (authType === 'none') {
|
|
312
|
+
return 'none';
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (authType === 'searchParams') {
|
|
316
|
+
return 'searchParams';
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (authType === 'bearer') {
|
|
320
|
+
return 'bearer';
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (authType === 'bearer') {
|
|
324
|
+
return 'basic';
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (!auth) {
|
|
328
|
+
return 'none';
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (auth) {
|
|
332
|
+
return 'bearer';
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return 'unknown';
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export function getServiceNamespace(serviceConfig) {
|
|
339
|
+
var _serviceConfig$params;
|
|
340
|
+
|
|
341
|
+
if ('namespace' in serviceConfig && serviceConfig.namespace) {
|
|
342
|
+
return serviceConfig.namespace;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if ('params' in serviceConfig && (_serviceConfig$params = serviceConfig.params) !== null && _serviceConfig$params !== void 0 && _serviceConfig$params.namespace) {
|
|
346
|
+
return serviceConfig.params.namespace;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Get a `Map` keyed with all the service namespaces.
|
|
351
|
+
*
|
|
352
|
+
* @param context A partial project schema
|
|
353
|
+
*
|
|
354
|
+
* @returns A `Map` with namespaces as keys, and service keys as values.
|
|
355
|
+
*/
|
|
356
|
+
|
|
357
|
+
export function getServiceNamespaces(context) {
|
|
358
|
+
let namespaces = new Map();
|
|
359
|
+
const {
|
|
360
|
+
services
|
|
361
|
+
} = context;
|
|
362
|
+
|
|
363
|
+
if (services) {
|
|
364
|
+
Object.keys(services).forEach(serviceKey => {
|
|
365
|
+
const namespace = getServiceNamespace(services[serviceKey]);
|
|
366
|
+
|
|
367
|
+
if (namespace) {
|
|
368
|
+
namespaces.set(namespace, serviceKey);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return namespaces;
|
|
374
|
+
}
|
|
375
|
+
export function getServiceObjectFields(projectSchema, shape, provider) {
|
|
376
|
+
var _getServiceInfo$provi;
|
|
377
|
+
|
|
378
|
+
return ((_getServiceInfo$provi = getServiceInfo(projectSchema, shape)[provider]) !== null && _getServiceInfo$provi !== void 0 ? _getServiceInfo$provi : []).filter(serviceInfo => serviceInfo.generators[SERVICE_OBJECT_PATTERN_NAME]);
|
|
379
|
+
}
|
package/es/taxonomies.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import memoize from 'lodash/memoize';
|
|
2
|
+
import { createSchemaPropertyAccessor } from './schema-util';
|
|
3
|
+
|
|
4
|
+
function weakMemoize(fn) {
|
|
5
|
+
const memoized = memoize(fn);
|
|
6
|
+
memoized.cache = new WeakMap();
|
|
7
|
+
return memoized;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function getFirstStringFieldV3(shape, projectSchema) {
|
|
11
|
+
var _projectSchema$forms;
|
|
12
|
+
|
|
13
|
+
const forms = (_projectSchema$forms = projectSchema.forms) === null || _projectSchema$forms === void 0 ? void 0 : _projectSchema$forms[shape.name];
|
|
14
|
+
|
|
15
|
+
if (!forms || !forms.default) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const schemaProperties = createSchemaPropertyAccessor(projectSchema, shape.schema);
|
|
20
|
+
const {
|
|
21
|
+
order
|
|
22
|
+
} = forms.default;
|
|
23
|
+
const name = order.find(name => {
|
|
24
|
+
var _schemaProperties$get;
|
|
25
|
+
|
|
26
|
+
return ((_schemaProperties$get = schemaProperties.getValue(name)) === null || _schemaProperties$get === void 0 ? void 0 : _schemaProperties$get.type) === 'string';
|
|
27
|
+
});
|
|
28
|
+
return name ? {
|
|
29
|
+
name,
|
|
30
|
+
key: schemaProperties.getKey(name)
|
|
31
|
+
} : null;
|
|
32
|
+
}
|
|
33
|
+
export const getTaxonomyField = weakMemoize((shape, projectSchema) => {
|
|
34
|
+
var _shape$model;
|
|
35
|
+
|
|
36
|
+
return ((_shape$model = shape.model) === null || _shape$model === void 0 ? void 0 : _shape$model.type) === 'taxonomy' ? getFirstStringFieldV3(shape, projectSchema) : null;
|
|
37
|
+
});
|
|
38
|
+
export const getTaxonomies = weakMemoize(projectSchema => {
|
|
39
|
+
const {
|
|
40
|
+
shapes
|
|
41
|
+
} = projectSchema;
|
|
42
|
+
return Object.keys(shapes).reduce((result, shapeName) => {
|
|
43
|
+
const shape = shapes[shapeName];
|
|
44
|
+
const field = getTaxonomyField(shape, projectSchema);
|
|
45
|
+
|
|
46
|
+
if (field) {
|
|
47
|
+
result.push({
|
|
48
|
+
shapeId: shape.id,
|
|
49
|
+
field
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return result;
|
|
54
|
+
}, []);
|
|
55
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { isRefSchema } from './types';
|
|
2
|
+
import { getRef, refExpressionToRefItem, refItemToShapeName } from './refs';
|
|
3
|
+
export const knownTemplateShapes = new Set(['TSGetArgs', 'TSGetSingletonArgs', 'PaginatedList', 'TSListArgs', 'CreateArgs', 'UpdateArgs', 'DuplicateArgs', 'DeleteArgs', 'CreateResult', 'UpdateResult', 'DuplicateResult', 'DeleteResult']);
|
|
4
|
+
/**
|
|
5
|
+
* Check if a string is a known template such as `PaginatedList`
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export function isValidTemplate(template) {
|
|
9
|
+
return knownTemplateShapes.has(template);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parse a template like `PaginatedList<Post>` and return both the template and the shape name.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export function parseTemplateShape(shape) {
|
|
16
|
+
const parts = shape.split('<');
|
|
17
|
+
|
|
18
|
+
if (parts.length > 1 && isValidTemplate(parts[0])) {
|
|
19
|
+
return {
|
|
20
|
+
shapeName: parts[1].replace(/(<|>)/, ''),
|
|
21
|
+
template: parts[0]
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
shapeName: parts[0],
|
|
27
|
+
template: undefined
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function parseReturnShape(projectSchema, shape) {
|
|
31
|
+
if (typeof shape === 'object') {
|
|
32
|
+
if (isRefSchema(shape.items)) {
|
|
33
|
+
const ref = getRef(projectSchema, shape.items);
|
|
34
|
+
|
|
35
|
+
if (!ref) {
|
|
36
|
+
throw new Error(`Could not parse ${JSON.stringify(shape.items)}: invalid ref`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
isArray: true,
|
|
41
|
+
ref,
|
|
42
|
+
shapeName: refItemToShapeName(ref)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (typeof shape.items.type !== 'string') {
|
|
47
|
+
throw new Error(`Could not parse ${JSON.stringify(shape.items)}: invalid type`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
isArray: true,
|
|
52
|
+
shapeName: shape.items.type
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const ref = refExpressionToRefItem(projectSchema, shape);
|
|
57
|
+
const shapeName = refItemToShapeName(ref);
|
|
58
|
+
return {
|
|
59
|
+
isArray: false,
|
|
60
|
+
shapeName,
|
|
61
|
+
ref,
|
|
62
|
+
template: ref.template
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a template string like `PaginatedList<Post>` from a template and shape name.
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
export function createTemplateShapeName(template, shapeName) {
|
|
70
|
+
return `${template}<${shapeName}>`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* If the string is a template like `PaginatedList<Post>`, return the shape name,
|
|
74
|
+
* in this case `Post`. Otherwise return the input.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
export const untemplate = input => {
|
|
78
|
+
return parseTemplateShape(input).shapeName;
|
|
79
|
+
};
|