@takeshape/schema 8.32.0 → 8.33.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 (68) hide show
  1. package/es/migration-utils.js +186 -0
  2. package/es/migration.js +105 -4
  3. package/es/mocks.js +1 -0
  4. package/es/project-schema/index.js +1 -0
  5. package/es/project-schema/v3.11.0.js +1 -0
  6. package/es/schemas/index.js +4 -3
  7. package/es/schemas/index.ts +4 -2
  8. package/es/schemas/project-schema/v3.11.0.json +2135 -0
  9. package/es/services.js +57 -255
  10. package/es/types/types.js +9 -0
  11. package/es/types/utils.js +19 -12
  12. package/examples/latest/blog-schema.json +2 -1
  13. package/examples/latest/brewery-schema.json +2 -1
  14. package/examples/latest/complex-project-schema.json +2 -1
  15. package/examples/latest/fabric-ecommerce.json +2 -2
  16. package/examples/latest/frank-and-fred-schema.json +2 -1
  17. package/examples/latest/massive-schema.json +2 -1
  18. package/examples/latest/mill-components-schema.json +2 -1
  19. package/examples/latest/pet-oneof-array.json +2 -1
  20. package/examples/latest/post-schema.json +2 -1
  21. package/examples/latest/pruned-shopify-product-schema.json +2 -2
  22. package/examples/latest/real-world-schema.json +2 -1
  23. package/examples/latest/recursive-repeater-schema.json +2 -1
  24. package/examples/latest/recursive-schema.json +2 -1
  25. package/examples/latest/rick-and-morty-ast.json +1 -1
  26. package/examples/latest/rick-and-morty-graphql.json +1 -1
  27. package/examples/latest/rick-and-morty-rest.json +1 -1
  28. package/examples/latest/schema-with-repeater-draftjs.json +2 -1
  29. package/examples/latest/shape-books-v3_2_0.json +2 -1
  30. package/examples/latest/shape-books.json +2 -1
  31. package/examples/latest/shopify-lookbook.json +1 -1
  32. package/examples/latest/shopify-store-with-widget.json +2 -2
  33. package/examples/latest/stripe-starter-resolved.json +2 -2
  34. package/examples/latest/user-schema-no-required.json +2 -1
  35. package/examples/latest/user-schema-with-defaults.json +2 -1
  36. package/lib/migration-utils.d.ts +18 -0
  37. package/lib/migration-utils.d.ts.map +1 -0
  38. package/lib/migration-utils.js +203 -0
  39. package/lib/migration.d.ts +3 -3
  40. package/lib/migration.d.ts.map +1 -1
  41. package/lib/migration.js +110 -5
  42. package/lib/mocks.d.ts.map +1 -1
  43. package/lib/mocks.js +1 -0
  44. package/lib/project-schema/index.d.ts +3 -1
  45. package/lib/project-schema/index.d.ts.map +1 -1
  46. package/lib/project-schema/index.js +26 -13
  47. package/lib/project-schema/latest.d.ts +26 -17
  48. package/lib/project-schema/latest.d.ts.map +1 -1
  49. package/lib/project-schema/v3.11.0.d.ts +1211 -0
  50. package/lib/project-schema/v3.11.0.d.ts.map +1 -0
  51. package/lib/project-schema/v3.11.0.js +5 -0
  52. package/lib/schemas/index.d.ts +2051 -2
  53. package/lib/schemas/index.d.ts.map +1 -1
  54. package/lib/schemas/index.js +17 -15
  55. package/lib/schemas/index.ts +4 -2
  56. package/lib/schemas/project-schema/v3.11.0.json +2135 -0
  57. package/lib/services.d.ts +11 -27
  58. package/lib/services.d.ts.map +1 -1
  59. package/lib/services.js +54 -261
  60. package/lib/types/types.d.ts +16 -5
  61. package/lib/types/types.d.ts.map +1 -1
  62. package/lib/types/types.js +9 -0
  63. package/lib/types/utils.d.ts +8 -5
  64. package/lib/types/utils.d.ts.map +1 -1
  65. package/lib/types/utils.js +25 -13
  66. package/lib/validate.d.ts +1 -1
  67. package/lib/validate.d.ts.map +1 -1
  68. package/package.json +4 -4
@@ -0,0 +1,186 @@
1
+ /**
2
+ * This file is a stop-gap for this story: https://app.shortcut.com/takeshape/story/7140/reorganize-schema-migration-ts-into-a-directory
3
+ */
4
+ import { isAnyServiceConfig } from './types/utils';
5
+ import { pascalCase } from '@takeshape/util';
6
+ import isObject from 'lodash/isObject';
7
+ import isString from 'lodash/isString';
8
+ import isUndefined from 'lodash/isUndefined';
9
+ /**
10
+ * `graphql:my-key` `my-key`
11
+ */
12
+
13
+ export function parseV3ServiceStr(service) {
14
+ const parts = service.split(':');
15
+ return {
16
+ provider: parts.length > 1 ? parts[0] : undefined,
17
+ id: parts.length > 1 ? parts[1] : parts[0]
18
+ };
19
+ }
20
+ /**
21
+ * Ensures a consistent service config, inluding updating the service
22
+ * authentication object.
23
+ */
24
+ // eslint-disable-next-line complexity
25
+
26
+ export function updateServiceConfigV3ToV3_1(serviceConfig, serviceKey) {
27
+ if (isAnyServiceConfig(serviceConfig)) {
28
+ if (isString(serviceConfig.authentication) || isUndefined(serviceConfig.authentication)) {
29
+ return serviceConfig;
30
+ }
31
+
32
+ return serviceConfig;
33
+ }
34
+
35
+ const {
36
+ auth
37
+ } = serviceConfig;
38
+ const serviceParams = serviceConfig.params || {};
39
+ let {
40
+ provider: serviceKeyProvider,
41
+ id: serviceKeyId
42
+ } = parseV3ServiceStr(serviceKey);
43
+ const authType = serviceParams.authType || undefined;
44
+ const title = serviceParams.name || serviceKeyId;
45
+
46
+ if (serviceKeyId === 'vercel') {
47
+ serviceKeyProvider = 'vercel';
48
+ } else if (serviceKeyId === 'netlify') {
49
+ serviceKeyProvider = 'netlify';
50
+ } // Example schemas had this in params, which are untyped, so adding here just in case
51
+
52
+
53
+ if (serviceParams.type === 'rest') {
54
+ serviceKeyProvider = 'rest';
55
+ } else if (serviceParams.type === 'graphql' && serviceKeyProvider !== 'shopify') {
56
+ serviceKeyProvider = 'graphql';
57
+ }
58
+
59
+ let provider;
60
+ let authenticationType;
61
+ let serviceType;
62
+ let namespace;
63
+
64
+ if (serviceKeyProvider === 'shopify') {
65
+ provider = 'shopify';
66
+ authenticationType = 'oauth2Bearer';
67
+ serviceType = 'graphql';
68
+ namespace = serviceParams.namespace ?? 'Shopify';
69
+ } else if (serviceKeyProvider === 'takeshape') {
70
+ provider = 'takeshape';
71
+ authenticationType = 'none';
72
+ serviceType = 'takeshape';
73
+ namespace = serviceParams.namespace ?? 'TakeShape';
74
+ } else if (serviceKeyProvider === 'bigcommerce') {
75
+ provider = 'bigcommerce';
76
+ authenticationType = 'bearer';
77
+ serviceType = 'graphql';
78
+ namespace = serviceParams.namespace ?? 'BigCommerce';
79
+ } else if (serviceKeyProvider === 'rest') {
80
+ provider = 'generic';
81
+ authenticationType = mapAuthType(authType, auth);
82
+ serviceType = 'rest';
83
+ namespace = serviceParams.namespace ?? pascalCase(title);
84
+ } else if (serviceKeyProvider === 'graphql') {
85
+ provider = 'generic';
86
+ authenticationType = mapAuthType(authType, auth);
87
+ serviceType = 'graphql';
88
+ namespace = serviceParams.namespace ?? pascalCase(title);
89
+ } else if (serviceKeyProvider === 'vercel') {
90
+ provider = 'vercel';
91
+ authenticationType = 'oauth2Bearer';
92
+ serviceType = 'deployment';
93
+ } else if (serviceKeyProvider === 'netlify') {
94
+ provider = 'netlify';
95
+ authenticationType = 'oauth2Bearer';
96
+ serviceType = 'deployment';
97
+ } else {
98
+ provider = 'generic';
99
+ authenticationType = mapAuthType(authType, auth);
100
+ serviceType = 'unknown';
101
+ namespace = serviceParams.namespace ?? pascalCase(title);
102
+ }
103
+
104
+ const updatedServiceConfig = {
105
+ title,
106
+ id: serviceKey,
107
+ provider,
108
+ namespace,
109
+ serviceType,
110
+ authenticationType,
111
+ options: { ...serviceParams
112
+ }
113
+ };
114
+
115
+ if (serviceConfig.auth && isObject(serviceConfig.auth)) {
116
+ const authentication = updateServiceAuthentication(updatedServiceConfig.authenticationType, serviceConfig.auth, serviceParams);
117
+ return { ...updatedServiceConfig,
118
+ authentication
119
+ };
120
+ }
121
+
122
+ return updatedServiceConfig;
123
+ }
124
+ /**
125
+ * V1/V3 unencrypted `auth` -> V3.1 `authentication
126
+ */
127
+
128
+ function updateServiceAuthentication(authenticationType, legacyAuth, legacyParams) {
129
+ if (authenticationType === 'oauth2Bearer') {
130
+ return {
131
+ token: legacyAuth.accessToken,
132
+ scope: legacyAuth.scope,
133
+ header: legacyParams.authHeader
134
+ };
135
+ }
136
+
137
+ if (authenticationType === 'searchParams' && legacyParams.authProp) {
138
+ return [{
139
+ name: legacyParams.authProp,
140
+ value: legacyAuth.accessToken
141
+ }];
142
+ }
143
+
144
+ if (authenticationType === 'basic') {
145
+ const [username, password] = Buffer.from(legacyAuth.accessToken, 'base64').toString('utf-8').split(':');
146
+ return {
147
+ username,
148
+ password
149
+ };
150
+ }
151
+
152
+ if (authenticationType === 'bearer') {
153
+ return {
154
+ token: legacyAuth.accessToken,
155
+ header: legacyParams.authHeader
156
+ };
157
+ }
158
+ }
159
+
160
+ function mapAuthType(authType, auth) {
161
+ if (authType === 'none') {
162
+ return 'none';
163
+ }
164
+
165
+ if (authType === 'searchParams') {
166
+ return 'searchParams';
167
+ }
168
+
169
+ if (authType === 'bearer') {
170
+ return 'bearer';
171
+ }
172
+
173
+ if (authType === 'bearer') {
174
+ return 'basic';
175
+ }
176
+
177
+ if (!auth) {
178
+ return 'none';
179
+ }
180
+
181
+ if (auth) {
182
+ return 'bearer';
183
+ }
184
+
185
+ return 'unknown';
186
+ }
package/es/migration.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import pReduce from 'p-reduce';
2
2
  import forEach from 'lodash/forEach';
3
3
  import pick from 'lodash/pick';
4
+ import mapValues from 'lodash/mapValues';
5
+ import isObject from 'lodash/isObject';
6
+ import fromPairs from 'lodash/fromPairs';
4
7
  import { pascalCase, deepClone, visit } from '@takeshape/util';
5
8
  import { arraySchemaKeys, getShapeQueriesAndMutations, multipleRelationshipSchemaKeys, objectSchemaKeys, scalarSchemaKeys, schemaMetadataKeys } from './schema-util';
6
- import { updateServiceConfigV3ToV3_1 } from './services';
7
- import { isServiceAuthentication, isProjectSchemaV1, isProjectSchemaV3, isLatestProjectSchema, isProjectSchemaV3_1, isProjectSchemaV3_2, isProjectSchemaV3_3, isProjectSchemaV3_4, isProjectSchemaV3_5, isProjectSchemaV3_5_1, isProjectSchemaV3_6, isProjectSchemaV3_7, isProjectSchemaV3_8, isProjectSchemaV3_9 } from './types/utils';
8
- import mapValues from 'lodash/mapValues';
9
+ import { updateServiceConfigV3ToV3_1 } from './migration-utils';
10
+ import { isProjectSchemaV1, isProjectSchemaV3, isLatestProjectSchema, isProjectSchemaV3_1, isProjectSchemaV3_2, isProjectSchemaV3_3, isProjectSchemaV3_4, isProjectSchemaV3_5, isProjectSchemaV3_5_1, isProjectSchemaV3_6, isProjectSchemaV3_7, isProjectSchemaV3_8, isProjectSchemaV3_9, isProjectSchemaV3_10 } from './types/utils';
9
11
  export const listTypePrefix = 'PaginatedList';
10
12
  const annotationMap = {
11
13
  l10n: '@l10n',
@@ -284,7 +286,7 @@ export async function migrateToV3_1(context, projectSchema) {
284
286
  }, serviceKey);
285
287
  const authentication = updatedServiceConfig === null || updatedServiceConfig === void 0 ? void 0 : updatedServiceConfig.authentication;
286
288
  serviceMap[serviceKey] = { ...updatedServiceConfig,
287
- authentication: isServiceAuthentication(authentication) ? encryptFn(authentication) : authentication
289
+ authentication: authentication && isObject(authentication) ? encryptFn(authentication) : authentication
288
290
  };
289
291
  return serviceMap;
290
292
  }, {});
@@ -497,6 +499,101 @@ export function migrateToV3_10(projectSchema) {
497
499
  schemaVersion: '3.10.0'
498
500
  };
499
501
  }
502
+ export function migrateToV3_11_0({
503
+ decryptFn,
504
+ encryptFn
505
+ }, projectSchema) {
506
+ const migratedServices = [];
507
+
508
+ for (const [serviceKey, serviceConfig] of Object.entries(projectSchema.services ?? {})) {
509
+ const {
510
+ authenticationType,
511
+ authentication
512
+ } = serviceConfig; // Migrate authentication, ensuring now required properties
513
+
514
+ if (authentication && authenticationType !== 'unknown' && authenticationType !== 'none') {
515
+ const decrypted = decryptFn(authentication);
516
+
517
+ if (!decrypted) {
518
+ throw new Error(`Service "${serviceKey}" authentication could not be decrypted. Please contact support.`);
519
+ }
520
+
521
+ let migrated;
522
+
523
+ if (authenticationType === 'searchParams') {
524
+ migrated = {
525
+ params: decrypted,
526
+ type: authenticationType
527
+ };
528
+ }
529
+
530
+ if (authenticationType === 'basic') {
531
+ migrated = {
532
+ username: '',
533
+ password: '',
534
+ ...decrypted,
535
+ type: authenticationType
536
+ };
537
+ }
538
+
539
+ if (authenticationType === 'bearer') {
540
+ migrated = {
541
+ token: '',
542
+ ...decrypted,
543
+ type: authenticationType
544
+ };
545
+ }
546
+
547
+ if (authenticationType === 'oauth2Bearer') {
548
+ migrated = {
549
+ token: '',
550
+ ...decrypted,
551
+ type: authenticationType
552
+ };
553
+ }
554
+
555
+ if (authenticationType === 'oauth2') {
556
+ migrated = {
557
+ grantType: 'clientCredentials',
558
+ clientId: '',
559
+ ...decrypted,
560
+ type: authenticationType
561
+ };
562
+ }
563
+
564
+ if (authenticationType === 'aws') {
565
+ migrated = {
566
+ awsAccessKeyId: '',
567
+ awsSecretAccessKey: '',
568
+ ...decrypted,
569
+ type: authenticationType
570
+ };
571
+ }
572
+
573
+ if (authenticationType === 'custom') {
574
+ migrated = { ...decrypted,
575
+ type: authenticationType
576
+ };
577
+ }
578
+
579
+ if (migrated) {
580
+ const migratedServiceConfig = { ...serviceConfig,
581
+ authentication: encryptFn(migrated)
582
+ };
583
+ migratedServices.push([serviceKey, migratedServiceConfig]);
584
+ } else {
585
+ migratedServices.push([serviceKey, serviceConfig]);
586
+ }
587
+ } else {
588
+ migratedServices.push([serviceKey, serviceConfig]);
589
+ }
590
+ }
591
+
592
+ return { ...projectSchema,
593
+ services: fromPairs(migratedServices),
594
+ schemaVersion: '3.11.0'
595
+ };
596
+ }
500
597
  export async function migrateToLatestProjectSchema(context, projectSchema) {
501
598
  if (projectSchema.schemaVersion === '4.0.0') {
502
599
  throw new Error('You are using an unreleased schema version. Migration is not possible');
@@ -550,6 +647,10 @@ export async function migrateToLatestProjectSchema(context, projectSchema) {
550
647
  projectSchema = migrateToV3_10(projectSchema);
551
648
  }
552
649
 
650
+ if (isProjectSchemaV3_10(projectSchema)) {
651
+ projectSchema = migrateToV3_11_0(context, projectSchema);
652
+ }
653
+
553
654
  return projectSchema;
554
655
  }
555
656
  export function normalizeSchemaVersion(version) {
package/es/mocks.js CHANGED
@@ -27,6 +27,7 @@ export function createMockServiceConfig(serviceKey, serviceConfig) {
27
27
  namespace: pascalCase(serviceKey),
28
28
  authenticationType: 'bearer',
29
29
  authentication: {
30
+ type: 'bearer',
30
31
  token: 'abc123'
31
32
  },
32
33
  options: {
@@ -1,6 +1,7 @@
1
1
  // This file is generated by "pnpm json2ts"
2
2
  export * from './latest';
3
3
  export * from './v4.0.0';
4
+ export * from './v3.11.0';
4
5
  export * from './v3.10.0';
5
6
  export * from './v3.9.0';
6
7
  export * from './v3.8.0';
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,9 @@
1
1
  // This file is generated by "pnpm json2ts"
2
- export const CURRENT_SCHEMA_VERSION = '3.10.0';
2
+ export const CURRENT_SCHEMA_VERSION = '3.11.0';
3
3
  export { default as anyProjectSchema } from './project-schema.json';
4
- export { default as latestSchemaJson } from './project-schema/v3.10.0.json';
4
+ export { default as latestSchemaJson } from './project-schema/v3.11.0.json';
5
5
  import projectSchemaV4_0_0 from './project-schema/v4.0.0.json';
6
+ import projectSchemaV3_11_0 from './project-schema/v3.11.0.json';
6
7
  import projectSchemaV3_10_0 from './project-schema/v3.10.0.json';
7
8
  import projectSchemaV3_9_0 from './project-schema/v3.9.0.json';
8
9
  import metaSchemaV3_9_0 from './project-schema/meta-schema-v3.9.0.json';
@@ -28,4 +29,4 @@ import projectSchemaV3_0_0 from './project-schema/v3.0.0.json';
28
29
  import metaSchemaV3_0_0 from './project-schema/meta-schema-v3.0.0.json';
29
30
  import projectSchemaV1_0_0 from './project-schema/v1.0.0.json';
30
31
  import metaSchemaV1_0_0 from './project-schema/meta-schema-v1.0.0.json';
31
- export const allProjectSchemas = [projectSchemaV4_0_0, projectSchemaV3_10_0, projectSchemaV3_9_0, metaSchemaV3_9_0, projectSchemaV3_8_0, metaSchemaV3_8_0, projectSchemaV3_7_0, metaSchemaV3_7_0, projectSchemaV3_6_0, metaSchemaV3_6_0, projectSchemaV3_5_1, metaSchemaV3_5_1, projectSchemaV3_5_0, metaSchemaV3_5_0, projectSchemaV3_4_0, metaSchemaV3_4_0, projectSchemaV3_3_0, metaSchemaV3_3_0, projectSchemaV3_2_0, metaSchemaV3_2_0, projectSchemaV3_1_0, metaSchemaV3_1_0, projectSchemaV3_0_0, metaSchemaV3_0_0, projectSchemaV1_0_0, metaSchemaV1_0_0];
32
+ export const allProjectSchemas = [projectSchemaV4_0_0, projectSchemaV3_11_0, projectSchemaV3_10_0, projectSchemaV3_9_0, metaSchemaV3_9_0, projectSchemaV3_8_0, metaSchemaV3_8_0, projectSchemaV3_7_0, metaSchemaV3_7_0, projectSchemaV3_6_0, metaSchemaV3_6_0, projectSchemaV3_5_1, metaSchemaV3_5_1, projectSchemaV3_5_0, metaSchemaV3_5_0, projectSchemaV3_4_0, metaSchemaV3_4_0, projectSchemaV3_3_0, metaSchemaV3_3_0, projectSchemaV3_2_0, metaSchemaV3_2_0, projectSchemaV3_1_0, metaSchemaV3_1_0, projectSchemaV3_0_0, metaSchemaV3_0_0, projectSchemaV1_0_0, metaSchemaV1_0_0];
@@ -1,8 +1,9 @@
1
1
  // This file is generated by "pnpm json2ts"
2
- export const CURRENT_SCHEMA_VERSION = '3.10.0';
2
+ export const CURRENT_SCHEMA_VERSION = '3.11.0';
3
3
  export {default as anyProjectSchema} from './project-schema.json';
4
- export {default as latestSchemaJson} from './project-schema/v3.10.0.json';
4
+ export {default as latestSchemaJson} from './project-schema/v3.11.0.json';
5
5
  import projectSchemaV4_0_0 from './project-schema/v4.0.0.json';
6
+ import projectSchemaV3_11_0 from './project-schema/v3.11.0.json';
6
7
  import projectSchemaV3_10_0 from './project-schema/v3.10.0.json';
7
8
  import projectSchemaV3_9_0 from './project-schema/v3.9.0.json';
8
9
  import metaSchemaV3_9_0 from './project-schema/meta-schema-v3.9.0.json';
@@ -30,6 +31,7 @@ import projectSchemaV1_0_0 from './project-schema/v1.0.0.json';
30
31
  import metaSchemaV1_0_0 from './project-schema/meta-schema-v1.0.0.json';
31
32
  export const allProjectSchemas = [
32
33
  projectSchemaV4_0_0,
34
+ projectSchemaV3_11_0,
33
35
  projectSchemaV3_10_0,
34
36
  projectSchemaV3_9_0,
35
37
  metaSchemaV3_9_0,