@stepzen/sdk 0.0.0-experimental-20221114-610843f6

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 (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -0
  3. package/lib/client-v2.d.ts +50 -0
  4. package/lib/client-v2.d.ts.map +1 -0
  5. package/lib/client-v2.js +91 -0
  6. package/lib/client-v2.js.map +1 -0
  7. package/lib/client.d.ts +33 -0
  8. package/lib/client.d.ts.map +1 -0
  9. package/lib/client.js +95 -0
  10. package/lib/client.js.map +1 -0
  11. package/lib/commands/account.d.ts +10 -0
  12. package/lib/commands/account.d.ts.map +1 -0
  13. package/lib/commands/account.js +39 -0
  14. package/lib/commands/account.js.map +1 -0
  15. package/lib/commands/authenticate.d.ts +4 -0
  16. package/lib/commands/authenticate.d.ts.map +1 -0
  17. package/lib/commands/authenticate.js +25 -0
  18. package/lib/commands/authenticate.js.map +1 -0
  19. package/lib/commands/deploy.d.ts +4 -0
  20. package/lib/commands/deploy.d.ts.map +1 -0
  21. package/lib/commands/deploy.js +46 -0
  22. package/lib/commands/deploy.js.map +1 -0
  23. package/lib/commands/getPublicAccount.d.ts +7 -0
  24. package/lib/commands/getPublicAccount.d.ts.map +1 -0
  25. package/lib/commands/getPublicAccount.js +59 -0
  26. package/lib/commands/getPublicAccount.js.map +1 -0
  27. package/lib/commands/list.d.ts +4 -0
  28. package/lib/commands/list.d.ts.map +1 -0
  29. package/lib/commands/list.js +29 -0
  30. package/lib/commands/list.js.map +1 -0
  31. package/lib/commands/upload.d.ts +4 -0
  32. package/lib/commands/upload.d.ts.map +1 -0
  33. package/lib/commands/upload.js +64 -0
  34. package/lib/commands/upload.js.map +1 -0
  35. package/lib/commands-v2/account.d.ts +9 -0
  36. package/lib/commands-v2/account.d.ts.map +1 -0
  37. package/lib/commands-v2/account.js +68 -0
  38. package/lib/commands-v2/account.js.map +1 -0
  39. package/lib/commands-v2/deploy.d.ts +15 -0
  40. package/lib/commands-v2/deploy.d.ts.map +1 -0
  41. package/lib/commands-v2/deploy.js +90 -0
  42. package/lib/commands-v2/deploy.js.map +1 -0
  43. package/lib/commands-v2/getPublicAccount.d.ts +8 -0
  44. package/lib/commands-v2/getPublicAccount.d.ts.map +1 -0
  45. package/lib/commands-v2/getPublicAccount.js +46 -0
  46. package/lib/commands-v2/getPublicAccount.js.map +1 -0
  47. package/lib/commands-v2/list.d.ts +12 -0
  48. package/lib/commands-v2/list.d.ts.map +1 -0
  49. package/lib/commands-v2/list.js +58 -0
  50. package/lib/commands-v2/list.js.map +1 -0
  51. package/lib/index.d.ts +12 -0
  52. package/lib/index.d.ts.map +1 -0
  53. package/lib/index.js +26 -0
  54. package/lib/index.js.map +1 -0
  55. package/lib/init-v2.d.ts +33 -0
  56. package/lib/init-v2.d.ts.map +1 -0
  57. package/lib/init-v2.js +33 -0
  58. package/lib/init-v2.js.map +1 -0
  59. package/lib/init.d.ts +33 -0
  60. package/lib/init.d.ts.map +1 -0
  61. package/lib/init.js +31 -0
  62. package/lib/init.js.map +1 -0
  63. package/lib/shared/constants.d.ts +7 -0
  64. package/lib/shared/constants.d.ts.map +1 -0
  65. package/lib/shared/constants.js +11 -0
  66. package/lib/shared/constants.js.map +1 -0
  67. package/lib/shared/graphql-client.d.ts +38 -0
  68. package/lib/shared/graphql-client.d.ts.map +1 -0
  69. package/lib/shared/graphql-client.js +80 -0
  70. package/lib/shared/graphql-client.js.map +1 -0
  71. package/lib/shared/payloads.d.ts +10 -0
  72. package/lib/shared/payloads.d.ts.map +1 -0
  73. package/lib/shared/payloads.js +123 -0
  74. package/lib/shared/payloads.js.map +1 -0
  75. package/lib/shared/request.d.ts +4 -0
  76. package/lib/shared/request.d.ts.map +1 -0
  77. package/lib/shared/request.js +25 -0
  78. package/lib/shared/request.js.map +1 -0
  79. package/lib/shared/transpiling.d.ts +15 -0
  80. package/lib/shared/transpiling.d.ts.map +1 -0
  81. package/lib/shared/transpiling.js +29 -0
  82. package/lib/shared/transpiling.js.map +1 -0
  83. package/lib/shared/types.d.ts +194 -0
  84. package/lib/shared/types.d.ts.map +1 -0
  85. package/lib/shared/types.js +4 -0
  86. package/lib/shared/types.js.map +1 -0
  87. package/lib/shared/validation.d.ts +3 -0
  88. package/lib/shared/validation.d.ts.map +1 -0
  89. package/lib/shared/validation.js +47 -0
  90. package/lib/shared/validation.js.map +1 -0
  91. package/package.json +52 -0
  92. package/src/client-v2.ts +120 -0
  93. package/src/client.ts +133 -0
  94. package/src/commands/account.ts +54 -0
  95. package/src/commands/authenticate.ts +30 -0
  96. package/src/commands/deploy.ts +72 -0
  97. package/src/commands/getPublicAccount.ts +77 -0
  98. package/src/commands/list.ts +50 -0
  99. package/src/commands/upload.ts +91 -0
  100. package/src/commands-v2/account.ts +98 -0
  101. package/src/commands-v2/deploy.ts +145 -0
  102. package/src/commands-v2/getPublicAccount.ts +67 -0
  103. package/src/commands-v2/list.ts +91 -0
  104. package/src/index.ts +27 -0
  105. package/src/init-v2.ts +44 -0
  106. package/src/init.ts +45 -0
  107. package/src/shared/constants.ts +9 -0
  108. package/src/shared/graphql-client.ts +136 -0
  109. package/src/shared/payloads.ts +153 -0
  110. package/src/shared/request.ts +28 -0
  111. package/src/shared/transpiling.ts +49 -0
  112. package/src/shared/types.ts +235 -0
  113. package/src/shared/validation.ts +52 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/shared/constants.ts"],"names":[],"mappings":";AAAA,8CAA8C;;;AAEjC,QAAA,iBAAiB,GAAG,oBAAoB,CAAA;AACxC,QAAA,gBAAgB,GAAG,mBAAmB,CAAA;AACtC,QAAA,cAAc,GAAG,iBAAiB,CAAA;AAClC,QAAA,gBAAgB,GAAG,mBAAmB,CAAA;AACtC,QAAA,gBAAgB,GAAG,mBAAmB,CAAA;AAEtC,QAAA,WAAW,GAAG,uBAAuB,CAAA"}
@@ -0,0 +1,38 @@
1
+ import { SDKConfigurationV2 } from './types';
2
+ export declare type GraphQLSuccessResponse<T> = {
3
+ data: T;
4
+ errors: undefined;
5
+ };
6
+ export declare type GraphQLErrorResponse<T> = {
7
+ data: T | null;
8
+ errors: Array<{
9
+ message: string;
10
+ locations?: Array<{
11
+ line: number;
12
+ column: number;
13
+ }>;
14
+ path?: Array<string | number>;
15
+ }>;
16
+ };
17
+ export declare type GraphQLResponse<T> = GraphQLSuccessResponse<T> | GraphQLErrorResponse<T>;
18
+ export declare const fetchGraphQLQuery: <T>({ url, query, variables, headers, }: {
19
+ url: URL | string;
20
+ query: string;
21
+ variables: Record<string, any>;
22
+ headers: Record<string, any>;
23
+ }) => Promise<GraphQLResponse<T>>;
24
+ export declare const fetchZenCtlGraphQLQuery: <T>({ account, adminKey, deploymentType, query, variables, sdkConfig, }: {
25
+ account: string;
26
+ adminKey: string;
27
+ deploymentType: string;
28
+ query: string;
29
+ variables: Record<string, any>;
30
+ sdkConfig: SDKConfigurationV2;
31
+ }) => Promise<GraphQLResponse<T>>;
32
+ export declare const fetchPublicAccountGraphQLQuery: <T>({ url, query, variables, sdkConfig, }: {
33
+ url: URL | string;
34
+ query: string;
35
+ variables: Record<string, any>;
36
+ sdkConfig: SDKConfigurationV2;
37
+ }) => Promise<GraphQLResponse<T>>;
38
+ //# sourceMappingURL=graphql-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql-client.d.ts","sourceRoot":"","sources":["../../src/shared/graphql-client.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAA;AAG1C,oBAAY,sBAAsB,CAAC,CAAC,IAAI;IACtC,IAAI,EAAE,CAAC,CAAA;IACP,MAAM,EAAE,SAAS,CAAA;CAClB,CAAA;AAED,oBAAY,oBAAoB,CAAC,CAAC,IAAI;IACpC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAA;IACd,MAAM,EAAE,KAAK,CAAC;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,SAAS,CAAC,EAAE,KAAK,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAC,CAAC,CAAA;QACjD,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;KAC9B,CAAC,CAAA;CACH,CAAA;AAED,oBAAY,eAAe,CAAC,CAAC,IACzB,sBAAsB,CAAC,CAAC,CAAC,GACzB,oBAAoB,CAAC,CAAC,CAAC,CAAA;AAE3B,eAAO,MAAM,iBAAiB;SAMvB,GAAG,GAAG,MAAM;WACV,MAAM;eACF,OAAO,MAAM,EAAE,GAAG,CAAC;aACrB,OAAO,MAAM,EAAE,GAAG,CAAC;iCA6C7B,CAAA;AAED,eAAO,MAAM,uBAAuB;aAQzB,MAAM;cACL,MAAM;oBACA,MAAM;WACf,MAAM;eACF,OAAO,MAAM,EAAE,GAAG,CAAC;eACnB,kBAAkB;iCAe9B,CAAA;AAED,eAAO,MAAM,8BAA8B;SAMpC,GAAG,GAAG,MAAM;WACV,MAAM;eACF,OAAO,MAAM,EAAE,GAAG,CAAC;eACnB,kBAAkB;iCAc9B,CAAA"}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ // Copyright (c) 2020,2021,2022, StepZen, Inc.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.fetchPublicAccountGraphQLQuery = exports.fetchZenCtlGraphQLQuery = exports.fetchGraphQLQuery = void 0;
5
+ const debug = require("debug");
6
+ const fetch_1 = require("@stepzen/fetch");
7
+ const request_1 = require("./request");
8
+ const fetchGraphQLQuery = async ({ url, query, variables = {}, headers = {}, }) => {
9
+ debug('stepzen:sdk:url')(url);
10
+ debug('stepzen:sdk:headers')(headers);
11
+ debug('stepzen:sdk:query')(query);
12
+ debug('stepzen:sdk:variables')(variables);
13
+ try {
14
+ const response = await (0, fetch_1.default)(url, {
15
+ method: 'POST',
16
+ headers: {
17
+ 'content-type': 'application/json',
18
+ ...headers,
19
+ },
20
+ body: JSON.stringify({
21
+ query,
22
+ variables,
23
+ }),
24
+ });
25
+ if (response.status !== 200) {
26
+ throw new Error(`Unexpected HTTP status ${response.status}` +
27
+ ` from the GraphQL endpoint '${url}' (expected 200)`);
28
+ }
29
+ const json = await response.json();
30
+ debug('stepzen:sdk:response')(json);
31
+ const { data, errors } = json;
32
+ if (errors) {
33
+ return { data, errors };
34
+ }
35
+ else if (data) {
36
+ return { data, errors: undefined };
37
+ }
38
+ throw new Error(`Unexpected response structure from the GraphQL endpoint '${url}'` +
39
+ ` (expected {data, errors}, recieved ${JSON.stringify(json)})`);
40
+ }
41
+ catch (error) {
42
+ debug('stepzen:sdk:response')(`Failed to fetch from a GraphQL API`, error);
43
+ throw error;
44
+ }
45
+ };
46
+ exports.fetchGraphQLQuery = fetchGraphQLQuery;
47
+ const fetchZenCtlGraphQLQuery = async ({ account, adminKey, deploymentType, query, variables = {}, sdkConfig, }) => {
48
+ try {
49
+ return await (0, exports.fetchGraphQLQuery)({
50
+ url: sdkConfig.zenctlApiUrl,
51
+ query,
52
+ variables,
53
+ headers: {
54
+ 'user-agent': (0, request_1.getUserAgent)(sdkConfig),
55
+ host: `stepzen.${deploymentType}.net`,
56
+ },
57
+ });
58
+ }
59
+ catch (error) {
60
+ throw new Error(`Failed to connect to ZenCtl API. ${error}`);
61
+ }
62
+ };
63
+ exports.fetchZenCtlGraphQLQuery = fetchZenCtlGraphQLQuery;
64
+ const fetchPublicAccountGraphQLQuery = async ({ url, query, variables = {}, sdkConfig, }) => {
65
+ try {
66
+ return await (0, exports.fetchGraphQLQuery)({
67
+ url,
68
+ query,
69
+ variables,
70
+ headers: {
71
+ 'user-agent': (0, request_1.getUserAgent)(sdkConfig),
72
+ },
73
+ });
74
+ }
75
+ catch (error) {
76
+ throw new Error(`Failed to connect to Public Account API. ${error}`);
77
+ }
78
+ };
79
+ exports.fetchPublicAccountGraphQLQuery = fetchPublicAccountGraphQLQuery;
80
+ //# sourceMappingURL=graphql-client.js.map
@@ -0,0 +1 @@
1
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AC,CAAA;AAvBY,QAAA,8BAA8B,kCAuB1C"}
@@ -0,0 +1,10 @@
1
+ import * as FormData from 'form-data';
2
+ import { Configuration, SchemaFiles } from './types';
3
+ declare type YamlPayload = FormData;
4
+ declare type ZipPayload = FormData;
5
+ export declare const generateYamlPayload: (file: string | undefined) => Promise<YamlPayload>;
6
+ export declare const generateZipPayload: (directory: string | undefined, data: object | undefined, filters: RegExp[]) => Promise<ZipPayload>;
7
+ export declare const generateSchemaFilesPayload: (workspaceFolderPath: string) => SchemaFiles;
8
+ export declare const generateConfigurationPayload: (configFilePath?: string) => Promise<Configuration | null>;
9
+ export {};
10
+ //# sourceMappingURL=payloads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payloads.d.ts","sourceRoot":"","sources":["../../src/shared/payloads.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,QAAQ,MAAM,WAAW,CAAA;AAQrC,OAAO,EAAC,aAAa,EAAE,WAAW,EAAC,MAAM,SAAS,CAAA;AAElD,aAAK,WAAW,GAAG,QAAQ,CAAA;AAC3B,aAAK,UAAU,GAAG,QAAQ,CAAA;AAI1B,eAAO,MAAM,mBAAmB,SACxB,MAAM,GAAG,SAAS,KACvB,QAAQ,WAAW,CAgBrB,CAAA;AAKD,eAAO,MAAM,kBAAkB,cAClB,MAAM,GAAG,SAAS,QACvB,MAAM,GAAG,SAAS,WACf,MAAM,EAAE,KAChB,QAAQ,UAAU,CA4DpB,CAAA;AAED,eAAO,MAAM,0BAA0B,wBAChB,MAAM,KAC1B,WA0BF,CAAA;AAED,eAAO,MAAM,4BAA4B,oBACtB,MAAM,KACtB,QAAQ,aAAa,GAAG,IAAI,CAU9B,CAAA"}
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ // Copyright (c) 2020,2021,2022, StepZen, Inc.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.generateConfigurationPayload = exports.generateSchemaFilesPayload = exports.generateZipPayload = exports.generateYamlPayload = void 0;
5
+ // This file contains helpers that zip a file or directory
6
+ const archiver = require("archiver");
7
+ const debug = require("debug");
8
+ const FormData = require("form-data");
9
+ const fs = require("fs");
10
+ const glob = require("glob");
11
+ const os = require("os");
12
+ const path = require("path");
13
+ const yaml = require("yaml");
14
+ const transpiling_1 = require("./transpiling");
15
+ const validation_1 = require("./validation");
16
+ // This function takes a (yaml) file path
17
+ // and creates a FormData payload, containing the yaml content as 'yaml'
18
+ const generateYamlPayload = async (file) => {
19
+ return new Promise((resolve, reject) => {
20
+ const payload = new FormData();
21
+ if (file) {
22
+ if (!fs.existsSync(file)) {
23
+ reject(new Error(`File does not exist: ${file}`));
24
+ }
25
+ const content = fs.readFileSync(file, 'utf8');
26
+ debug('stepzen:sdk:payload')(`adding YAML payload\n${content}`);
27
+ payload.append('yaml', fs.readFileSync(file));
28
+ resolve(payload);
29
+ }
30
+ else {
31
+ reject(new Error('File not specified'));
32
+ }
33
+ });
34
+ };
35
+ exports.generateYamlPayload = generateYamlPayload;
36
+ // This function takes a directory path, and optional data object,
37
+ // and creates a FormData payload, containing the directory contents as 'zip',
38
+ // and any other items in the data object.
39
+ const generateZipPayload = async (directory, data, filters) => {
40
+ return new Promise((resolve, reject) => {
41
+ const payload = new FormData();
42
+ if (data) {
43
+ for (const [key, value] of Object.entries(data)) {
44
+ payload.append(key, value);
45
+ }
46
+ }
47
+ // Store it in /tmp. Create a WriteStream
48
+ const filepath = path.join(os.tmpdir(), `stepzen-payload-${Date.now()}.zip`);
49
+ const output = fs.createWriteStream(filepath);
50
+ // We're making a zip file
51
+ const archive = archiver('zip', {
52
+ zlib: { level: 9 },
53
+ });
54
+ // We're piping it to the WriteStream
55
+ archive.pipe(output);
56
+ // If we've specified a directory, add it to the archive
57
+ if (directory) {
58
+ if (!fs.existsSync(directory)) {
59
+ reject(new Error(`Directory does not exist: ${directory}`));
60
+ }
61
+ // Get all the files in the directory (and all subdirectories).
62
+ const allFiles = glob.sync('**', { cwd: directory });
63
+ // Loop through each file, because we want to filter them
64
+ // We add them manually, because when we use glob, it embeds
65
+ // a full path, and we want everything to explicitly
66
+ // start at the root of the archive.
67
+ allFiles.forEach(file => {
68
+ const include = filters.some(filter => file.match(filter));
69
+ if (include) {
70
+ debug('stepzen:archive')(file);
71
+ archive.file(path.join(directory, file), { name: file });
72
+ }
73
+ });
74
+ }
75
+ // Once we're done, append a ReadStream to the tmp file
76
+ output.on('close', () => {
77
+ const stream = fs.createReadStream(filepath);
78
+ payload.append('zip', stream);
79
+ // Remove the temporary zip
80
+ stream.on('close', () => {
81
+ fs.unlinkSync(filepath);
82
+ });
83
+ // This is where we return the payload
84
+ resolve(payload);
85
+ });
86
+ // Archive the file or directory
87
+ archive.finalize();
88
+ });
89
+ };
90
+ exports.generateZipPayload = generateZipPayload;
91
+ const generateSchemaFilesPayload = (workspaceFolderPath) => {
92
+ if (!fs.existsSync(workspaceFolderPath)) {
93
+ throw new Error(`Failed to read folder ${workspaceFolderPath}. Does it exist?`);
94
+ }
95
+ const files = glob
96
+ .sync('**/*.graphql', { cwd: workspaceFolderPath })
97
+ .map(file => {
98
+ return {
99
+ name: file,
100
+ content: fs.readFileSync(`${workspaceFolderPath}/${file}`, 'utf8'),
101
+ };
102
+ });
103
+ if (files.length === 0) {
104
+ throw new Error(`Failed to find any .graphql files in ${workspaceFolderPath}`);
105
+ }
106
+ return {
107
+ files,
108
+ entryPoint: 'index.graphql',
109
+ };
110
+ };
111
+ exports.generateSchemaFilesPayload = generateSchemaFilesPayload;
112
+ const generateConfigurationPayload = async (configFilePath) => {
113
+ if (!configFilePath) {
114
+ return null;
115
+ }
116
+ await (0, validation_1.validateConfigurationset)(configFilePath);
117
+ const transpiled = await (0, transpiling_1.transpileConfigurationset)(configFilePath);
118
+ debug('stepzen:sdk')(`effective config written to ${transpiled}`);
119
+ const content = fs.readFileSync(transpiled, 'utf-8');
120
+ return yaml.parse(content, { schema: 'failsafe' }) || null;
121
+ };
122
+ exports.generateConfigurationPayload = generateConfigurationPayload;
123
+ //# source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SACnE,CAAA;IACH,CAAC,CAAC,CAAA;IAEJ,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QACtB,MAAM,IAAI,KAAK,CACb,wCAAwC,mBAAmB,EAAE,CAC9D,CAAA;KACF;IAED,OAAO;QACL,KAAK;QACL,UAAU,EAAE,eAAe;KAC5B,CAAA;AACH,CAAC,CAAA;AA5BY,QAAA,0BAA0B,8BA4BtC;AAEM,MAAM,4BAA4B,GAAG,KAAK,EAC/C,cAAuB,EACQ,EAAE;IACjC,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,IAAI,CAAA;KACZ;IAED,MAAM,IAAA,qCAAwB,EAAC,cAAc,CAAC,CAAA;IAC9C,MAAM,UAAU,GAAG,MAAM,IAAA,uCAAyB,EAAC,cAAc,CAAC,CAAA;IAClE,KAAK,CAAC,aAAa,CAAC,CAAC,+BAA+B,UAAU,EAAE,CAAC,CAAA;IACjE,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IACpD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAC,MAAM,EAAE,UAAU,EAAC,CAAC,IAAI,IAAI,CAAA;AAC1D,CAAC,CAAA;AAZY,QAAA,4BAA4B,gCAYxC"}
@@ -0,0 +1,4 @@
1
+ import { SDKConfiguration, StepZenAccount, ZenCtlRequestHeaders } from './types';
2
+ export declare const getUserAgent: (sdkConfig: SDKConfiguration) => string;
3
+ export declare const getRequestHeaders: (account: StepZenAccount, sdkConfig: SDKConfiguration) => ZenCtlRequestHeaders;
4
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/shared/request.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,gBAAgB,EAAE,cAAc,EAAE,oBAAoB,EAAC,MAAM,SAAS,CAAA;AAS9E,eAAO,MAAM,YAAY,cAAe,gBAAgB,KAAG,MAE1D,CAAA;AAED,eAAO,MAAM,iBAAiB,YACnB,cAAc,aACZ,gBAAgB,KAC1B,oBAOF,CAAA"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ // Copyright (c) 2020,2021,2022, StepZen, Inc.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getRequestHeaders = exports.getUserAgent = void 0;
5
+ const os = require("os");
6
+ const isWsl = require("is-wsl");
7
+ const { version } = require('../../package.json');
8
+ // mimics the logic from @oclif/config
9
+ // https://github.com/oclif/core/blob/d7067d13c7d80c9e0064455c27ac1ebb6ee53fd2/src/config/config.ts#L128
10
+ const arch = os.arch() === 'ia32' ? 'x86' : os.arch();
11
+ const platform = isWsl ? 'wsl' : os.platform();
12
+ const getUserAgent = (sdkConfig) => {
13
+ return `${sdkConfig.appName} stepzen-sdk/${version} (${platform}; ${arch}; node-${process.version})`;
14
+ };
15
+ exports.getUserAgent = getUserAgent;
16
+ const getRequestHeaders = (account, sdkConfig) => {
17
+ return {
18
+ authorization: `Apikey ${account.adminkey}`,
19
+ host: `${account.account}.${account.domain}`,
20
+ 'stepzen-cli-version': version,
21
+ 'user-agent': (0, exports.getUserAgent)(sdkConfig),
22
+ };
23
+ };
24
+ exports.getRequestHeaders = getRequestHeaders;
25
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/shared/request.ts"],"names":[],"mappings":";AAAA,8CAA8C;;;AAE9C,yBAAwB;AACxB,gCAA+B;AAG/B,MAAM,EAAC,OAAO,EAAC,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA;AAE/C,sCAAsC;AACtC,wGAAwG;AACxG,MAAM,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,EAAE,CAAC,IAAI,EAAU,CAAA;AAC9D,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,EAAE,CAAC,QAAQ,EAAU,CAAA;AAEhD,MAAM,YAAY,GAAG,CAAC,SAA2B,EAAU,EAAE;IAClE,OAAO,GAAG,SAAS,CAAC,OAAO,gBAAgB,OAAO,KAAK,QAAQ,KAAK,IAAI,UAAU,OAAO,CAAC,OAAO,GAAG,CAAA;AACtG,CAAC,CAAA;AAFY,QAAA,YAAY,gBAExB;AAEM,MAAM,iBAAiB,GAAG,CAC/B,OAAuB,EACvB,SAA2B,EACL,EAAE;IACxB,OAAO;QACL,aAAa,EAAE,UAAU,OAAO,CAAC,QAAQ,EAAE;QAC3C,IAAI,EAAE,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE;QAC5C,qBAAqB,EAAE,OAAO;QAC9B,YAAY,EAAE,IAAA,oBAAY,EAAC,SAAS,CAAC;KACtC,CAAA;AACH,CAAC,CAAA;AAVY,QAAA,iBAAiB,qBAU7B"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @returns `undefined` when called without arguments
3
+ */
4
+ export declare function transpileConfigurationset(): Promise<undefined>;
5
+ /**
6
+ * Strip off any unsupported properties and substitute any STEPZEN_*
7
+ * placeholders with matching environment variables (load a `.env` file
8
+ * if present next to the `config.yaml` file).
9
+ *
10
+ * @param file path to a `config.yaml` file
11
+ * @returns path to a temp copy of `config.yaml` file with all clean-up
12
+ * and substitutions made
13
+ */
14
+ export declare function transpileConfigurationset(file: string): Promise<string>;
15
+ //# sourceMappingURL=transpiling.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transpiling.d.ts","sourceRoot":"","sources":["../../src/shared/transpiling.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,SAAS,CAAC,CAAA;AAErE;;;;;;;;GAQG;AACH,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ // Copyright (c) 2020,2021,2022, StepZen, Inc.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.transpileConfigurationset = void 0;
5
+ const dotenv = require("dotenv");
6
+ const debug = require("debug");
7
+ const fs = require("fs-extra");
8
+ const os = require("os");
9
+ const path = require("path");
10
+ const transpiler_1 = require("@stepzen/transpiler");
11
+ async function transpileConfigurationset(file) {
12
+ if (!file) {
13
+ return;
14
+ }
15
+ const source = file.substring(0, file.lastIndexOf('/'));
16
+ debug('stepzen:dotenv')(`loading .env from ${path.resolve(source)}` +
17
+ `, at sdk/src/shared/transpiling.ts`);
18
+ dotenv.config({ path: path.resolve(source, '.env') });
19
+ const tmp = path.join(os.tmpdir(), `stepzen-transpiler-${Date.now()}`);
20
+ const configPath = path.join(tmp, 'config.yaml');
21
+ fs.ensureDirSync(tmp);
22
+ fs.copyFileSync(file, configPath);
23
+ const result = await (0, transpiler_1.transpile)(tmp);
24
+ fs.emptyDirSync(tmp);
25
+ fs.writeFileSync(configPath, result.config || '');
26
+ return configPath;
27
+ }
28
+ exports.transpileConfigurationset = transpileConfigurationset;
29
+ //# sourceMappingURL=transpiling.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transpiling.js","sourceRoot":"","sources":["../../src/shared/transpiling.ts"],"names":[],"mappings":";AAAA,8CAA8C;;;AAE9C,iCAAgC;AAChC,+BAA8B;AAC9B,+BAA8B;AAC9B,yBAAwB;AACxB,6BAA4B;AAC5B,oDAA6C;AAkBtC,KAAK,UAAU,yBAAyB,CAAC,IAAa;IAC3D,IAAI,CAAC,IAAI,EAAE;QACT,OAAM;KACP;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAA;IACvD,KAAK,CAAC,gBAAgB,CAAC,CACrB,qBAAqB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACzC,oCAAoC,CACvC,CAAA;IACD,MAAM,CAAC,MAAM,CAAC,EAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,EAAC,CAAC,CAAA;IAEnD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,sBAAsB,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;IACtE,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;IAEhD,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;IACrB,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;IAEjC,MAAM,MAAM,GAAG,MAAM,IAAA,sBAAS,EAAC,GAAG,CAAC,CAAA;IAEnC,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;IACpB,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAA;IACjD,OAAO,UAAU,CAAA;AACnB,CAAC;AAvBD,8DAuBC"}
@@ -0,0 +1,194 @@
1
+ export interface StepZenAccount {
2
+ account: string;
3
+ adminkey: string;
4
+ /**
5
+ * ZenCtl base URL, e.g. `https://fakefish.stepzen.io` for production,
6
+ * or `http://localhost` for local tests.
7
+ *
8
+ * Determined by taking the first option that is defined:
9
+ * - the `server` config property explicily passed into the `init()` function
10
+ * - the `STEPZEN_SERVER_URL` environment variable
11
+ * - the `https://{account}.stepzen.io` default value
12
+ *
13
+ * The `{account}` placeholder (if present) is replaced by the provided account
14
+ * name
15
+ */
16
+ server: string;
17
+ /**
18
+ * ZenCtl domain, e.g. `stepzen.io`. This is only relevant for local testing
19
+ * when ZenCtl is running on localhost. In that case an additional `Host` HTTP
20
+ * header is added to requests, using a non-localhost host name constructed
21
+ * from this property.
22
+ *
23
+ * Determined by taking the first option that is defined:
24
+ * - the `domain` config property explicily passed into the `init()` function
25
+ * - the `STEPZEN_DOMAIN` environment variable
26
+ * - the `stepzen.io` default value
27
+ */
28
+ domain: string;
29
+ }
30
+ export declare type StepZenCredentials = {
31
+ account: string;
32
+ adminkey: string;
33
+ apikey: string;
34
+ };
35
+ export declare type UserCredentialsClientOptions = Pick<StepZenAccount, 'account' | 'adminkey'> & Partial<StepZenAccount>;
36
+ export declare type AnonymousClientOptions = {
37
+ publicAccountToken: string;
38
+ server?: StepZenAccount['server'];
39
+ domain?: StepZenAccount['domain'];
40
+ };
41
+ export interface StepZenDeploy {
42
+ configurationsets?: string[];
43
+ destination: string;
44
+ schema: string;
45
+ }
46
+ export interface StepZenList {
47
+ type: 'deployments' | 'schemas' | 'configurationsets';
48
+ }
49
+ export interface StepZenUpload {
50
+ destination: string;
51
+ directory?: string;
52
+ file?: string;
53
+ type: string;
54
+ }
55
+ export interface ZenCtlRequestHeaders {
56
+ authorization: string;
57
+ host: string;
58
+ 'stepzen-cli-version': string;
59
+ 'user-agent': string;
60
+ }
61
+ export interface ZenCtlResponse {
62
+ errors?: Array<string>;
63
+ message?: string;
64
+ results?: Array<string>;
65
+ success: boolean;
66
+ }
67
+ export interface SDKConfiguration {
68
+ /**
69
+ * The name and version of that app that uses the SDK,
70
+ * e.g. `stepzen-cli/0.9.32`
71
+ *
72
+ * It is appended to the user-agent string in all requests made to StepZen
73
+ * through the SDK and becomes availabe in the log analytics.
74
+ */
75
+ appName: string;
76
+ }
77
+ export interface SDKConfigurationV2 extends SDKConfiguration {
78
+ /**
79
+ * The name and version of that app that uses the SDK,
80
+ * e.g. `stepzen-cli/0.9.32`
81
+ *
82
+ * It is appended to the user-agent string in all requests made to StepZen
83
+ * through the SDK and becomes availabe in the log analytics.
84
+ */
85
+ appName: string;
86
+ /**
87
+ * Version of ZenCtl API to use:
88
+ * - `undefined`, `v1`: implies the v1 REST API at /ctl/admin/
89
+ * - `v2`: implies the v2 GraphQL API
90
+ */
91
+ apiVersion: string;
92
+ /**
93
+ * URL of the ZenCtl GraphQL API,
94
+ * e.g. https://stepzen.stepzen.net/api/zenctl2/__graphql
95
+ */
96
+ zenctlApiUrl: string;
97
+ /**
98
+ * URL of the StepZen getPublicAccount GraphQL API,
99
+ * e.g. https://stepzen.stepzen.net/api/publicaccount/__graphql
100
+ */
101
+ publicAccountApiUrl: string;
102
+ }
103
+ export interface ZenCtlSuccessResponseV2<T> {
104
+ data: T;
105
+ error: undefined;
106
+ }
107
+ export interface ZenCtlErrorResponseV2 {
108
+ data: undefined;
109
+ error: {
110
+ message: string;
111
+ };
112
+ }
113
+ export declare type ZenCtlResponseV2<T> = ZenCtlSuccessResponseV2<T> | ZenCtlErrorResponseV2;
114
+ export interface StepZenCredentialsV2 {
115
+ account: string;
116
+ adminKey: string;
117
+ apiKeys: string[];
118
+ deploymentType: string;
119
+ }
120
+ export interface StepZenAccountV2 {
121
+ account: string;
122
+ ownerEmail: string;
123
+ adminKey: string;
124
+ apiKeys: string[];
125
+ deploymentType: string;
126
+ }
127
+ export interface StepZenEndpointV2 {
128
+ account: string;
129
+ deploymentType: string;
130
+ folderName: string;
131
+ endpointName: string;
132
+ public: boolean;
133
+ endpointType: string;
134
+ }
135
+ export interface SchemaFiles {
136
+ files: SchemaFile[];
137
+ entryPoint?: String;
138
+ }
139
+ export interface SchemaFile {
140
+ name: string;
141
+ content: string;
142
+ }
143
+ export interface Configuration {
144
+ configurationset?: ConfigurationSet[];
145
+ ruleset?: QueryRule[];
146
+ access?: Policies;
147
+ deployment?: DeploymentSettings;
148
+ }
149
+ export interface ConfigurationSet {
150
+ configuration?: Record<string, any>;
151
+ }
152
+ export interface QueryRule {
153
+ query: string;
154
+ disabled?: boolean;
155
+ rules?: Rule[];
156
+ }
157
+ export interface Rule {
158
+ predicate: string;
159
+ action: string;
160
+ }
161
+ export interface Policies {
162
+ policies?: Policy[];
163
+ }
164
+ export interface Policy {
165
+ type?: string;
166
+ rules?: FieldRule[];
167
+ policyDefault?: FieldCondition;
168
+ }
169
+ export interface FieldRule {
170
+ name?: string;
171
+ description?: string;
172
+ condition: string;
173
+ fields?: string[];
174
+ }
175
+ export interface FieldCondition {
176
+ condition: string;
177
+ }
178
+ export interface DeploymentSettings {
179
+ identity?: IdentitySettings;
180
+ }
181
+ export interface IdentitySettings {
182
+ keys?: JWTKey[];
183
+ issuer?: string;
184
+ subject?: string;
185
+ audience?: string;
186
+ claims?: string[];
187
+ jwksendpoint?: string;
188
+ }
189
+ export interface JWTKey {
190
+ algorithm?: string;
191
+ keyid?: string;
192
+ key?: string;
193
+ }
194
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAEhB;;;;;;;;;;;OAWG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;;;;;;;;;OAUG;IACH,MAAM,EAAE,MAAM,CAAA;CACf;AAED,oBAAY,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,oBAAY,4BAA4B,GAAG,IAAI,CAC7C,cAAc,EACd,SAAS,GAAG,UAAU,CACvB,GACC,OAAO,CAAC,cAAc,CAAC,CAAA;AAEzB,oBAAY,sBAAsB,GAAG;IACnC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,MAAM,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAA;IACjC,MAAM,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAA;CAClC,CAAA;AAED,MAAM,WAAW,aAAa;IAC5B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,aAAa,G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;IACvB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,SAAS,EAAE,CAAA;IACnB,aAAa,CAAC,EAAE,cAAc,CAAA;CAC/B;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,gBAAgB,CAAA;CAC5B;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,MAAM;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;CACb"}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // Copyright (c) 2020,2021,2022, StepZen, Inc.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":";AAAA,8CAA8C"}
@@ -0,0 +1,3 @@
1
+ export declare const validateConfigurationset: (file: string | undefined) => Promise<void>;
2
+ export declare const validateSchema: (directory: string | undefined) => Promise<void>;
3
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/shared/validation.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,wBAAwB,SAAgB,MAAM,GAAG,SAAS,kBA0BtE,CAAA;AAGD,eAAO,MAAM,cAAc,cAAqB,MAAM,GAAG,SAAS,kBAcjE,CAAA"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ // Copyright (c) 2020,2021,2022, StepZen, Inc.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.validateSchema = exports.validateConfigurationset = void 0;
5
+ const debug = require("debug");
6
+ const fs = require("fs");
7
+ const glob = require("glob");
8
+ const yaml = require("yaml");
9
+ // Validate the Configurationset file
10
+ const validateConfigurationset = async (file) => {
11
+ if (!file) {
12
+ debug('stepzen:sdk')(`validateConfigurationset() expected 'file' to be a` +
13
+ ` non-empty string but got ${file}`);
14
+ throw new Error('You must provide a file path');
15
+ }
16
+ if (!fs.existsSync(file)) {
17
+ debug('stepzen:sdk')(`validateConfigurationset() expected ${file} to exist`);
18
+ throw new Error('The file does not exist');
19
+ }
20
+ const content = fs.readFileSync(file, 'utf8');
21
+ // Ensure the file is valid YAML
22
+ try {
23
+ yaml.parse(content);
24
+ }
25
+ catch (error) {
26
+ debug('stepzen:sdk')(`validateConfigurationset() expected ${file} to parse as YAML,` +
27
+ ` but got an error ${error}`);
28
+ throw new Error('The file is not valid YAML');
29
+ }
30
+ };
31
+ exports.validateConfigurationset = validateConfigurationset;
32
+ // Validate the Schema directory
33
+ const validateSchema = async (directory) => {
34
+ if (!directory) {
35
+ throw new Error('You must provide a directory path');
36
+ }
37
+ if (!fs.existsSync(directory)) {
38
+ throw new Error('The directory does not exist');
39
+ }
40
+ // Ensure there's a root `index.graphql` file
41
+ const allSchemaFiles = glob.sync('index.graphql', { cwd: directory });
42
+ if (allSchemaFiles.length === 0) {
43
+ throw new Error('Schemas must include an `index.graphql` file');
44
+ }
45
+ };
46
+ exports.validateSchema = validateSchema;
47
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/shared/validation.ts"],"names":[],"mappings":";AAAA,8CAA8C;;;AAE9C,+BAA8B;AAC9B,yBAAwB;AACxB,6BAA4B;AAC5B,6BAA4B;AAE5B,qCAAqC;AAC9B,MAAM,wBAAwB,GAAG,KAAK,EAAE,IAAwB,EAAE,EAAE;IACzE,IAAI,CAAC,IAAI,EAAE;QACT,KAAK,CAAC,aAAa,CAAC,CAClB,oDAAoD;YAClD,6BAA6B,IAAI,EAAE,CACtC,CAAA;QACD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;KAChD;IAED,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACxB,KAAK,CAAC,aAAa,CAAC,CAAC,uCAAuC,IAAI,WAAW,CAAC,CAAA;QAC5E,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;KAC3C;IAED,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAE7C,gCAAgC;IAChC,IAAI;QACF,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;KACpB;IAAC,OAAO,KAAK,EAAE;QACd,KAAK,CAAC,aAAa,CAAC,CAClB,uCAAuC,IAAI,oBAAoB;YAC7D,qBAAqB,KAAK,EAAE,CAC/B,CAAA;QACD,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;KAC9C;AACH,CAAC,CAAA;AA1BY,QAAA,wBAAwB,4BA0BpC;AAED,gCAAgC;AACzB,MAAM,cAAc,GAAG,KAAK,EAAE,SAA6B,EAAE,EAAE;IACpE,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;KACrD;IAED,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,S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